Add WASM verifier loading and asset verification functions

- Introduced loadVerifier function to load the WASM verifier from the server.
- Added verifyAsset function to validate asset data against an expected SHA256 hash using the loaded verifier.
- Ensured compatibility with server-side rendering by checking for the window object.
This commit is contained in:
2025-12-27 15:32:54 -06:00
parent e2c53de3c3
commit d710ad6b4f

View File

@@ -0,0 +1,19 @@
export async function loadVerifier() {
if (typeof window === 'undefined') return null;
if ((window as any).verifySHA256) return (window as any).verifySHA256;
const go = new (window as any).Go();
const result = await WebAssembly.instantiateStreaming(
fetch('/verifier/verifier.wasm'),
go.importObject
);
go.run(result.instance);
return (window as any).verifySHA256;
}
export async function verifyAsset(data: ArrayBuffer, expectedHash: string): Promise<true | string> {
const verify = await loadVerifier();
if (!verify) return 'WASM verifier not available';
return verify(new Uint8Array(data), expectedHash);
}