diff --git a/js/examples/browser/index.html b/js/examples/browser/index.html index 7eeea30..4afc154 100644 --- a/js/examples/browser/index.html +++ b/js/examples/browser/index.html @@ -251,9 +251,6 @@

Error

errorDiv.hidden = true; }; - // Initialize WASM on page load - await IDKit.init(); - // Fetch RP signature from the backend async function fetchRpSignature(action) { const res = await fetch("/api/rp-signature", { diff --git a/js/packages/core/README.md b/js/packages/core/README.md index 9114102..5730671 100644 --- a/js/packages/core/README.md +++ b/js/packages/core/README.md @@ -36,8 +36,6 @@ For common verification scenarios with World ID 3.0 backward compatibility: ```typescript import { IDKit, orbLegacy } from "@worldcoin/idkit-core"; -await IDKit.init(); - // Fetch signature from your backend const rpSig = await fetch("/api/rp-signature").then((r) => r.json()); @@ -106,7 +104,7 @@ Pure JS subpath exports are available for server-side use without WASM initializ | Subpath | Exports | | ---------- | ---------------------------------------------------------------- | | `/signing` | `signRequest`, `computeRpSignatureMessage`, `RpSignature` (type) | -| `/hashing` | `hashSignal`, `hashToField` | +| `/hashing` | `hashSignal` | ```typescript import { signRequest } from "@worldcoin/idkit-core/signing"; diff --git a/js/packages/core/src/__tests__/smoke.test.ts b/js/packages/core/src/__tests__/smoke.test.ts index 4df0ddf..c5ab75f 100644 --- a/js/packages/core/src/__tests__/smoke.test.ts +++ b/js/packages/core/src/__tests__/smoke.test.ts @@ -14,22 +14,6 @@ import { signRequest, } from "../index"; -describe("WASM Initialization", () => { - it("should initialize WASM via IDKit.init", async () => { - // Call IDKit.init to initialize WASM - await IDKit.init(); - // If we get here without throwing, WASM is initialized - expect(true).toBe(true); - }); - - it("should be safe to call IDKit.init multiple times", async () => { - await IDKit.init(); - await IDKit.init(); - // If we get here without throwing, multiple init calls are safe - expect(true).toBe(true); - }); -}); - describe("Platform Detection", () => { it("should detect Node.js environment", () => { expect(isNode()).toBe(true); diff --git a/js/packages/core/src/hashing.ts b/js/packages/core/src/hashing.ts index cc01ead..3e0a3fa 100644 --- a/js/packages/core/src/hashing.ts +++ b/js/packages/core/src/hashing.ts @@ -1 +1 @@ -export { hashSignal, hashToField } from "./lib/hashing"; +export { hashSignal } from "./lib/hashing"; diff --git a/js/packages/core/src/lib/wasm.ts b/js/packages/core/src/lib/wasm.ts index aaf94a9..fb0c667 100644 --- a/js/packages/core/src/lib/wasm.ts +++ b/js/packages/core/src/lib/wasm.ts @@ -7,15 +7,6 @@ import initWasm, * as WasmModule from "../../wasm/idkit_wasm.js"; let wasmInitialized = false; let wasmInitPromise: Promise | null = null; -async function importNodeModule(specifier: string): Promise { - // Avoid static analysis of node-only imports in browser bundles. - const dynamicImport = Function("moduleName", "return import(moduleName)") as ( - moduleName: string, - ) => Promise; - - return dynamicImport(specifier); -} - /** * Initializes the WASM module for browser environments * Uses fetch-based loading (works with http/https URLs) @@ -44,56 +35,6 @@ export async function initIDKit(): Promise { return wasmInitPromise; } -/** - * Initializes the WASM module for Node.js/server environments - * Uses fs-based loading since Node.js fetch doesn't support file:// URLs - * This must be called before using any WASM-powered functions - * Safe to call multiple times - initialization only happens once - */ -export async function initIDKitServer(): Promise { - if (wasmInitialized) { - return; - } - - if (wasmInitPromise) { - return wasmInitPromise; - } - - wasmInitPromise = (async () => { - try { - const { readFile } = (await importNodeModule( - "node:fs/promises", - )) as typeof import("node:fs/promises"); - const { fileURLToPath } = (await importNodeModule( - "node:url", - )) as typeof import("node:url"); - const { dirname, join } = (await importNodeModule( - "node:path", - )) as typeof import("node:path"); - // WASM file is copied to dist/ by tsup, same directory as the bundled JS. - // Avoid `new URL(..., import.meta.url)` because some server bundlers rewrite - // it into runtime-invalid URLs. - const modulePath = fileURLToPath(import.meta.url); - const wasmPath = join(dirname(modulePath), "idkit_wasm_bg.wasm"); - const wasmBuffer = await readFile(wasmPath); - await initWasm({ module_or_path: wasmBuffer }); - wasmInitialized = true; - } catch (error) { - wasmInitPromise = null; - throw new Error(`Failed to initialize IDKit WASM for server: ${error}`); - } - })(); - - return wasmInitPromise; -} - -/** - * Checks if WASM has been initialized - */ -export function isInitialized(): boolean { - return wasmInitialized; -} - /** * Re-exports WASM module for direct access */ diff --git a/js/packages/core/src/request.ts b/js/packages/core/src/request.ts index f510a13..b99a6ac 100644 --- a/js/packages/core/src/request.ts +++ b/js/packages/core/src/request.ts @@ -15,7 +15,7 @@ import type { CredentialRequestType, } from "./types/result"; import { IDKitErrorCodes } from "./types/result"; -import { WasmModule, initIDKit, initIDKitServer } from "./lib/wasm"; +import { WasmModule, initIDKit } from "./lib/wasm"; import { isInWorldApp, createNativeRequest, @@ -607,10 +607,6 @@ function proveSession( * ``` */ export const IDKit = { - /** Initialize WASM for browser environments (not needed in World App) */ - init: initIDKit, - /** Initialize WASM for Node.js/server environments */ - initServer: initIDKitServer, /** Create a new verification request */ request: createRequest, /** Create a new session (no action, no existing session_id) */ diff --git a/js/packages/react/src/__tests__/hooks.test.tsx b/js/packages/react/src/__tests__/hooks.test.tsx index 25902fd..49d48de 100644 --- a/js/packages/react/src/__tests__/hooks.test.tsx +++ b/js/packages/react/src/__tests__/hooks.test.tsx @@ -4,9 +4,8 @@ import { IDKitErrorCodes } from "@worldcoin/idkit-core"; import { useIDKitRequest } from "../hooks/useIDKitRequest"; import { useIDKitSession } from "../hooks/useIDKitSession"; -const { initMock, requestMock, createSessionMock, proveSessionMock } = +const { requestMock, createSessionMock, proveSessionMock } = vi.hoisted(() => ({ - initMock: vi.fn(async () => undefined), requestMock: vi.fn(), createSessionMock: vi.fn(), proveSessionMock: vi.fn(), @@ -14,7 +13,6 @@ const { initMock, requestMock, createSessionMock, proveSessionMock } = vi.mock("@worldcoin/idkit-core", () => ({ IDKit: { - init: initMock, request: requestMock, createSession: createSessionMock, proveSession: proveSessionMock, @@ -120,7 +118,6 @@ describe("request/session hooks", () => { expect(result.current.isAwaitingUserConfirmation).toBe(false); }); - expect(initMock).toHaveBeenCalledTimes(1); expect(requestMock).toHaveBeenCalledTimes(1); expect(result.current.connectorURI).toBe("wc://request"); expect(result.current.result).toEqual({ proof: "ok" }); diff --git a/js/packages/react/src/hooks/useIDKitFlow.ts b/js/packages/react/src/hooks/useIDKitFlow.ts index d2fc6a7..14d5417 100644 --- a/js/packages/react/src/hooks/useIDKitFlow.ts +++ b/js/packages/react/src/hooks/useIDKitFlow.ts @@ -1,9 +1,5 @@ import { useCallback, useEffect, useRef, useState } from "react"; -import { - IDKit, - IDKitErrorCodes, - type IDKitRequest, -} from "@worldcoin/idkit-core"; +import { IDKitErrorCodes, type IDKitRequest } from "@worldcoin/idkit-core"; import type { FlowConfig, IDKitHookResult } from "../types"; import { createInitialHookState, @@ -76,9 +72,6 @@ export function useIDKitFlow( void (async () => { try { - await IDKit.init(); - ensureNotAborted(controller.signal); - const request = await createFlowHandleRef.current(); ensureNotAborted(controller.signal);