diff --git a/src/herumi/context.ts b/src/herumi/context.ts index 5a56065..b23997c 100644 --- a/src/herumi/context.ts +++ b/src/herumi/context.ts @@ -6,15 +6,21 @@ type Bls = typeof bls; let blsGlobal: Bls | null = null; let blsGlobalPromise: Promise | null = null; +// Patch to fix multiVerify() calls on a browser with polyfilled NodeJS crypto +declare global { + interface Window { + msCrypto: typeof window["crypto"]; + } +} + export async function setupBls(): Promise { if (!blsGlobal) { await bls.init(bls.BLS12_381); // Patch to fix multiVerify() calls on a browser with polyfilled NodeJS crypto - // @ts-ignore if (typeof window === "object") { - // @ts-ignore const crypto = window.crypto || window.msCrypto; + // getRandomValues is not typed in `bls-eth-wasm` because it's not meant to be exposed // @ts-ignore bls.getRandomValues = (x) => crypto.getRandomValues(x); } diff --git a/tsconfig.json b/tsconfig.json index a15932d..5b70769 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,7 @@ "target": "esnext", "module": "commonjs", "pretty": true, - "lib": ["esnext.bigint"], + "lib": ["esnext.bigint", "DOM"], "typeRoots": ["./node_modules/@types"], "declaration": true, "strict": true,