sharenet/frontend/test_wasm.html
continuist dc050d5e34
Some checks failed
Podman Rootless Demo / test-backend (push) Has been skipped
Podman Rootless Demo / test-frontend (push) Has been skipped
Podman Rootless Demo / build-backend (push) Failing after 1s
Podman Rootless Demo / deploy-prod (push) Has been skipped
Podman Rootless Demo / build-frontend (push) Has been skipped
Add self-sovereign passports
2025-10-20 21:15:11 -04:00

46 lines
No EOL
1.7 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>WASM SPF Test</title>
</head>
<body>
<h1>WASM SPF File Test</h1>
<input type="file" id="spfFile" accept=".spf">
<div id="output"></div>
<script type="module">
import init, { parse_spf_file } from './wasm/pkg/sharenet_passport_wasm.js';
await init();
document.getElementById('spfFile').addEventListener('change', async (event) => {
const file = event.target.files[0];
if (!file) return;
const output = document.getElementById('output');
output.innerHTML = `<p>Loading file: ${file.name} (${file.size} bytes)</p>`;
try {
const arrayBuffer = await file.arrayBuffer();
const data = new Uint8Array(arrayBuffer);
output.innerHTML += `<p>File loaded: ${data.length} bytes</p>`;
output.innerHTML += `<p>First 16 bytes: ${Array.from(data.slice(0, 16)).map(b => b.toString(16).padStart(2, '0')).join(' ')}</p>`;
// Try to parse with password "test"
const password = prompt('Enter password:');
if (!password) return;
output.innerHTML += `<p>Attempting to parse with password...</p>`;
const result = await parse_spf_file(data, password);
output.innerHTML += `<p style="color: green;">Success! Parsed SPF file</p>`;
output.innerHTML += `<pre>${JSON.stringify(result, null, 2)}</pre>`;
} catch (error) {
output.innerHTML += `<p style="color: red;">Error: ${error.message}</p>`;
console.error('SPF parsing error:', error);
}
});
</script>
</body>
</html>