Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions js/examples/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,6 @@ <h3>Error</h3>
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", {
Expand Down
4 changes: 1 addition & 3 deletions js/packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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";
Expand Down
16 changes: 0 additions & 16 deletions js/packages/core/src/__tests__/smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion js/packages/core/src/hashing.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { hashSignal, hashToField } from "./lib/hashing";
export { hashSignal } from "./lib/hashing";
59 changes: 0 additions & 59 deletions js/packages/core/src/lib/wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ import initWasm, * as WasmModule from "../../wasm/idkit_wasm.js";
let wasmInitialized = false;
let wasmInitPromise: Promise<void> | null = null;

async function importNodeModule(specifier: string): Promise<unknown> {
// Avoid static analysis of node-only imports in browser bundles.
const dynamicImport = Function("moduleName", "return import(moduleName)") as (
moduleName: string,
) => Promise<unknown>;

return dynamicImport(specifier);
}

/**
* Initializes the WASM module for browser environments
* Uses fetch-based loading (works with http/https URLs)
Expand Down Expand Up @@ -44,56 +35,6 @@ export async function initIDKit(): Promise<void> {
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<void> {
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
*/
Expand Down
6 changes: 1 addition & 5 deletions js/packages/core/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) */
Expand Down
5 changes: 1 addition & 4 deletions js/packages/react/src/__tests__/hooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ 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(),
}));

vi.mock("@worldcoin/idkit-core", () => ({
IDKit: {
init: initMock,
request: requestMock,
createSession: createSessionMock,
proveSession: proveSessionMock,
Expand Down Expand Up @@ -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" });
Expand Down
9 changes: 1 addition & 8 deletions js/packages/react/src/hooks/useIDKitFlow.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -76,9 +72,6 @@ export function useIDKitFlow<TResult>(

void (async () => {
try {
await IDKit.init();
ensureNotAborted(controller.signal);

const request = await createFlowHandleRef.current();
ensureNotAborted(controller.signal);

Expand Down
Loading