@worldcoin/idkit-core 4.0.16 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
package/dist/index.cjs CHANGED
@@ -6,9 +6,9 @@ var utils = require('@noble/hashes/utils');
6
6
 
7
7
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
8
8
  var __defProp = Object.defineProperty;
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
9
+ var __export = (target, all2) => {
10
+ for (var name in all2)
11
+ __defProp(target, name, { get: all2[name], enumerable: true });
12
12
  };
13
13
 
14
14
  // src/types/result.ts
@@ -536,8 +536,8 @@ var IDKitBuilder = class _IDKitBuilder {
536
536
  * Builds a v1 (legacy) native payload from a preset (synchronous, no bridge connection).
537
537
  *
538
538
  * Used by the native transport when the World App only supports verify v1.
539
- * Only legacy presets produce valid v1 payloads (constraints always have
540
- * `Deprecated` verification level and will fail).
539
+ * Only legacy presets produce valid v1 payloads (constraint-based requests
540
+ * default to `Device` level and may not carry the correct action).
541
541
  *
542
542
  * # Errors
543
543
  *
@@ -1396,7 +1396,7 @@ function __wbg_get_imports() {
1396
1396
  const a = state0.a;
1397
1397
  state0.a = 0;
1398
1398
  try {
1399
- return __wasm_bindgen_func_elem_1421(a, state0.b, arg02, arg12);
1399
+ return __wasm_bindgen_func_elem_1423(a, state0.b, arg02, arg12);
1400
1400
  } finally {
1401
1401
  state0.a = a;
1402
1402
  }
@@ -1576,11 +1576,11 @@ function __wbg_get_imports() {
1576
1576
  return addHeapObject(ret);
1577
1577
  },
1578
1578
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
1579
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_643, __wasm_bindgen_func_elem_644);
1579
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_645, __wasm_bindgen_func_elem_646);
1580
1580
  return addHeapObject(ret);
1581
1581
  },
1582
1582
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
1583
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_973, __wasm_bindgen_func_elem_974);
1583
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_975, __wasm_bindgen_func_elem_976);
1584
1584
  return addHeapObject(ret);
1585
1585
  },
1586
1586
  __wbindgen_cast_0000000000000003: function(arg0) {
@@ -1616,13 +1616,13 @@ function __wbg_get_imports() {
1616
1616
  "./idkit_wasm_bg.js": import0
1617
1617
  };
1618
1618
  }
1619
- function __wasm_bindgen_func_elem_644(arg0, arg1) {
1620
- wasm.__wasm_bindgen_func_elem_644(arg0, arg1);
1619
+ function __wasm_bindgen_func_elem_646(arg0, arg1) {
1620
+ wasm.__wasm_bindgen_func_elem_646(arg0, arg1);
1621
1621
  }
1622
- function __wasm_bindgen_func_elem_974(arg0, arg1, arg2) {
1622
+ function __wasm_bindgen_func_elem_976(arg0, arg1, arg2) {
1623
1623
  try {
1624
1624
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1625
- wasm.__wasm_bindgen_func_elem_974(retptr, arg0, arg1, addHeapObject(arg2));
1625
+ wasm.__wasm_bindgen_func_elem_976(retptr, arg0, arg1, addHeapObject(arg2));
1626
1626
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1627
1627
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1628
1628
  if (r1) {
@@ -1632,8 +1632,8 @@ function __wasm_bindgen_func_elem_974(arg0, arg1, arg2) {
1632
1632
  wasm.__wbindgen_add_to_stack_pointer(16);
1633
1633
  }
1634
1634
  }
1635
- function __wasm_bindgen_func_elem_1421(arg0, arg1, arg2, arg3) {
1636
- wasm.__wasm_bindgen_func_elem_1421(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1635
+ function __wasm_bindgen_func_elem_1423(arg0, arg1, arg2, arg3) {
1636
+ wasm.__wasm_bindgen_func_elem_1423(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1637
1637
  }
1638
1638
  var __wbindgen_enum_RequestCache = ["default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached"];
1639
1639
  var __wbindgen_enum_RequestCredentials = ["omit", "same-origin", "include"];
@@ -1962,6 +1962,16 @@ async function initIDKit() {
1962
1962
  return wasmInitPromise;
1963
1963
  }
1964
1964
 
1965
+ // src/lib/debug.ts
1966
+ var _debug = false;
1967
+ function isDebug() {
1968
+ if (_debug) return true;
1969
+ return typeof window !== "undefined" && Boolean(window.IDKIT_DEBUG);
1970
+ }
1971
+ function setDebug(enabled) {
1972
+ _debug = enabled;
1973
+ }
1974
+
1965
1975
  // src/transports/native.ts
1966
1976
  var MINIAPP_VERIFY_ACTION = "miniapp-verify-action";
1967
1977
  function isInWorldApp() {
@@ -1977,9 +1987,10 @@ var _requestCounter = 0;
1977
1987
  var _activeNativeRequest = null;
1978
1988
  function createNativeRequest(wasmPayload, config, signalHashes = {}, legacySignalHash, version = 2) {
1979
1989
  if (_activeNativeRequest?.isPending()) {
1980
- console.warn(
1981
- "IDKit native request already in flight. Reusing active request."
1982
- );
1990
+ if (isDebug())
1991
+ console.warn(
1992
+ "[IDKit] Native: request already in flight, reusing active request"
1993
+ );
1983
1994
  return _activeNativeRequest;
1984
1995
  }
1985
1996
  const request2 = new NativeIDKitRequest(
@@ -2006,6 +2017,11 @@ var NativeIDKitRequest = class {
2006
2017
  const handleIncomingPayload = (responsePayload) => {
2007
2018
  if (this.completionResult) return;
2008
2019
  if (responsePayload?.status === "error") {
2020
+ if (isDebug())
2021
+ console.warn(
2022
+ "[IDKit] Native: received error response",
2023
+ responsePayload.error_code
2024
+ );
2009
2025
  this.complete({
2010
2026
  success: false,
2011
2027
  error: responsePayload.error_code ?? "generic_error" /* GenericError */
@@ -2039,7 +2055,9 @@ var NativeIDKitRequest = class {
2039
2055
  this.miniKitHandler = miniKitHandler;
2040
2056
  miniKit.subscribe(MINIAPP_VERIFY_ACTION, miniKitHandler);
2041
2057
  }
2042
- } catch {
2058
+ } catch (err) {
2059
+ if (isDebug())
2060
+ console.warn("[IDKit] Native: MiniKit subscribe failed", err);
2043
2061
  }
2044
2062
  const sendPayload = {
2045
2063
  command: "verify",
@@ -2049,16 +2067,29 @@ var NativeIDKitRequest = class {
2049
2067
  try {
2050
2068
  const w = window;
2051
2069
  if (w.webkit?.messageHandlers?.minikit) {
2070
+ if (isDebug())
2071
+ console.debug(
2072
+ `[IDKit] Native: sending verify command (version=${version}, platform=ios)`
2073
+ );
2052
2074
  w.webkit.messageHandlers.minikit.postMessage(sendPayload);
2053
2075
  } else if (w.Android) {
2076
+ if (isDebug())
2077
+ console.debug(
2078
+ `[IDKit] Native: sending verify command (version=${version}, platform=android)`
2079
+ );
2054
2080
  w.Android.postMessage(JSON.stringify(sendPayload));
2055
2081
  } else {
2082
+ if (isDebug())
2083
+ console.warn(
2084
+ "[IDKit] Native: no native bridge found (no webkit/Android)"
2085
+ );
2056
2086
  this.complete({
2057
2087
  success: false,
2058
2088
  error: "generic_error" /* GenericError */
2059
2089
  });
2060
2090
  }
2061
- } catch {
2091
+ } catch (err) {
2092
+ if (isDebug()) console.warn("[IDKit] Native: postMessage failed", err);
2062
2093
  this.complete({
2063
2094
  success: false,
2064
2095
  error: "generic_error" /* GenericError */
@@ -2069,6 +2100,11 @@ var NativeIDKitRequest = class {
2069
2100
  // Single entry point for finishing the request. Idempotent — first caller wins.
2070
2101
  complete(result) {
2071
2102
  if (this.completionResult) return;
2103
+ if (isDebug())
2104
+ console.debug(
2105
+ "[IDKit] Native: request completed",
2106
+ result.success ? "success" : `error=${result.error}`
2107
+ );
2072
2108
  this.completionResult = result;
2073
2109
  this.cleanup();
2074
2110
  this.resolveFn?.(result);
@@ -2088,7 +2124,9 @@ var NativeIDKitRequest = class {
2088
2124
  try {
2089
2125
  const miniKit = window.MiniKit;
2090
2126
  miniKit?.unsubscribe?.(MINIAPP_VERIFY_ACTION);
2091
- } catch {
2127
+ } catch (err) {
2128
+ if (isDebug())
2129
+ console.warn("[IDKit] Native: MiniKit unsubscribe failed", err);
2092
2130
  }
2093
2131
  this.miniKitHandler = null;
2094
2132
  }
@@ -2139,14 +2177,15 @@ var NativeIDKitRequest = class {
2139
2177
  function nativeResultToIDKitResult(payload, config, signalHashes, legacySignalHash) {
2140
2178
  const p = payload;
2141
2179
  const rpNonce = config.rp_context?.nonce ?? "";
2142
- if ("responses" in p && Array.isArray(p.responses)) {
2143
- const items = p.responses;
2144
- if (p.session_id) {
2180
+ if ("proof_response" in p && p.proof_response != null) {
2181
+ const proof_response = p.proof_response;
2182
+ const items = proof_response.responses ?? [];
2183
+ if (proof_response.session_id) {
2145
2184
  return {
2146
2185
  protocol_version: "4.0",
2147
- nonce: p.nonce ?? rpNonce,
2148
- action_description: p.action_description,
2149
- session_id: p.session_id,
2186
+ nonce: proof_response.nonce ?? rpNonce,
2187
+ action_description: proof_response.action_description,
2188
+ session_id: proof_response.session_id,
2150
2189
  responses: items.map((item) => ({
2151
2190
  identifier: item.identifier,
2152
2191
  signal_hash: signalHashes[item.identifier],
@@ -2160,9 +2199,9 @@ function nativeResultToIDKitResult(payload, config, signalHashes, legacySignalHa
2160
2199
  }
2161
2200
  return {
2162
2201
  protocol_version: "4.0",
2163
- nonce: p.nonce ?? rpNonce,
2164
- action: p.action ?? config.action ?? "",
2165
- action_description: p.action_description,
2202
+ nonce: proof_response.nonce ?? rpNonce,
2203
+ action: proof_response.action ?? config.action ?? "",
2204
+ action_description: proof_response.action_description,
2166
2205
  responses: items.map((item) => ({
2167
2206
  identifier: item.identifier,
2168
2207
  signal_hash: signalHashes[item.identifier],
@@ -2208,6 +2247,7 @@ function nativeResultToIDKitResult(payload, config, signalHashes, legacySignalHa
2208
2247
  }
2209
2248
 
2210
2249
  // src/request.ts
2250
+ var SESSION_ID_PATTERN = /^session_[0-9a-fA-F]{128}$/;
2211
2251
  var IDKitRequestImpl = class {
2212
2252
  constructor(wasmRequest) {
2213
2253
  this.wasmRequest = wasmRequest;
@@ -2248,6 +2288,23 @@ var IDKitRequestImpl = class {
2248
2288
  }
2249
2289
  }
2250
2290
  };
2291
+ function CredentialRequest(credential_type, options) {
2292
+ return {
2293
+ type: credential_type,
2294
+ signal: options?.signal,
2295
+ genesis_issued_at_min: options?.genesis_issued_at_min,
2296
+ expires_at_min: options?.expires_at_min
2297
+ };
2298
+ }
2299
+ function any(...nodes) {
2300
+ return { any: nodes };
2301
+ }
2302
+ function all(...nodes) {
2303
+ return { all: nodes };
2304
+ }
2305
+ function enumerate(...nodes) {
2306
+ return { enumerate: nodes };
2307
+ }
2251
2308
  function orbLegacy(opts = {}) {
2252
2309
  return { type: "OrbLegacy", signal: opts.signal };
2253
2310
  }
@@ -2340,7 +2397,7 @@ var IDKitBuilder2 = class {
2340
2397
  wasmResult.payload,
2341
2398
  this.config,
2342
2399
  wasmResult.signal_hashes ?? {},
2343
- wasmResult.legacy_signal_hash ?? void 0,
2400
+ wasmResult.legacy_signal_hash,
2344
2401
  2
2345
2402
  );
2346
2403
  }
@@ -2366,6 +2423,11 @@ var IDKitBuilder2 = class {
2366
2423
  * ```
2367
2424
  */
2368
2425
  async preset(preset) {
2426
+ if (this.config.type === "createSession" || this.config.type === "proveSession") {
2427
+ throw new Error(
2428
+ "Presets are not supported for session flows. Use .constraints() instead."
2429
+ );
2430
+ }
2369
2431
  await initIDKit();
2370
2432
  if (isInWorldApp()) {
2371
2433
  const verifyVersion = getWorldAppVerifyVersion();
@@ -2376,7 +2438,7 @@ var IDKitBuilder2 = class {
2376
2438
  wasmResult.payload,
2377
2439
  this.config,
2378
2440
  wasmResult.signal_hashes ?? {},
2379
- wasmResult.legacy_signal_hash ?? void 0,
2441
+ wasmResult.legacy_signal_hash,
2380
2442
  2
2381
2443
  );
2382
2444
  }
@@ -2387,7 +2449,7 @@ var IDKitBuilder2 = class {
2387
2449
  wasmResult.payload,
2388
2450
  this.config,
2389
2451
  wasmResult.signal_hashes ?? {},
2390
- wasmResult.legacy_signal_hash ?? void 0,
2452
+ wasmResult.legacy_signal_hash,
2391
2453
  1
2392
2454
  );
2393
2455
  } catch (err) {
@@ -2436,22 +2498,70 @@ function createRequest(config) {
2436
2498
  environment: config.environment
2437
2499
  });
2438
2500
  }
2501
+ function createSession2(config) {
2502
+ if (!config.app_id) {
2503
+ throw new Error("app_id is required");
2504
+ }
2505
+ if (!config.rp_context) {
2506
+ throw new Error(
2507
+ "rp_context is required. Generate it on your backend using signRequest()."
2508
+ );
2509
+ }
2510
+ return new IDKitBuilder2({
2511
+ type: "createSession",
2512
+ app_id: config.app_id,
2513
+ rp_context: config.rp_context,
2514
+ action_description: config.action_description,
2515
+ bridge_url: config.bridge_url,
2516
+ return_to: config.return_to,
2517
+ override_connect_base_url: config.override_connect_base_url,
2518
+ environment: config.environment
2519
+ });
2520
+ }
2521
+ function proveSession2(sessionId, config) {
2522
+ if (!sessionId) {
2523
+ throw new Error("session_id is required");
2524
+ }
2525
+ if (!SESSION_ID_PATTERN.test(sessionId)) {
2526
+ throw new Error(
2527
+ "session_id must be in the format session_<128 hex characters>"
2528
+ );
2529
+ }
2530
+ if (!config.app_id) {
2531
+ throw new Error("app_id is required");
2532
+ }
2533
+ if (!config.rp_context) {
2534
+ throw new Error(
2535
+ "rp_context is required. Generate it on your backend using signRequest()."
2536
+ );
2537
+ }
2538
+ return new IDKitBuilder2({
2539
+ type: "proveSession",
2540
+ session_id: sessionId,
2541
+ app_id: config.app_id,
2542
+ rp_context: config.rp_context,
2543
+ action_description: config.action_description,
2544
+ bridge_url: config.bridge_url,
2545
+ return_to: config.return_to,
2546
+ override_connect_base_url: config.override_connect_base_url,
2547
+ environment: config.environment
2548
+ });
2549
+ }
2439
2550
  var IDKit = {
2440
2551
  /** Create a new verification request */
2441
2552
  request: createRequest,
2442
- // TODO: Re-enable when World ID 4.0 is live
2443
- // /** Create a new session (no action, no existing session_id) */
2444
- // createSession,
2445
- // /** Prove an existing session (no action, has session_id) */
2446
- // proveSession,
2447
- // /** Create a CredentialRequest for a credential type */
2448
- // CredentialRequest,
2449
- // /** Create an OR constraint - at least one child must be satisfied */
2450
- // any,
2451
- // /** Create an AND constraint - all children must be satisfied */
2452
- // all,
2453
- // /** Create an enumerate constraint - all satisfiable children should be selected */
2454
- // enumerate,
2553
+ /** Create a new session (no action, no existing session_id) */
2554
+ createSession: createSession2,
2555
+ /** Prove an existing session (no action, has session_id) */
2556
+ proveSession: proveSession2,
2557
+ /** Create a CredentialRequest for a credential type */
2558
+ CredentialRequest,
2559
+ /** Create an OR constraint - at least one child must be satisfied */
2560
+ any,
2561
+ /** Create an AND constraint - all children must be satisfied */
2562
+ all,
2563
+ /** Create an enumerate constraint - all satisfiable children should be selected */
2564
+ enumerate,
2455
2565
  /** Create an OrbLegacy preset for World ID 3.0 legacy support */
2456
2566
  orbLegacy,
2457
2567
  /** Create a SecureDocumentLegacy preset for World ID 3.0 legacy support */
@@ -2499,11 +2609,16 @@ Object.defineProperty(exports, "signRequest", {
2499
2609
  enumerable: true,
2500
2610
  get: function () { return idkitServer.signRequest; }
2501
2611
  });
2612
+ exports.CredentialRequest = CredentialRequest;
2502
2613
  exports.IDKit = IDKit;
2503
2614
  exports.IDKitErrorCodes = IDKitErrorCodes;
2615
+ exports.all = all;
2616
+ exports.any = any;
2504
2617
  exports.deviceLegacy = deviceLegacy;
2505
2618
  exports.documentLegacy = documentLegacy;
2619
+ exports.enumerate = enumerate;
2506
2620
  exports.hashSignal = hashSignal2;
2621
+ exports.isDebug = isDebug;
2507
2622
  exports.isInWorldApp = isInWorldApp;
2508
2623
  exports.isNode = isNode;
2509
2624
  exports.isReactNative = isReactNative;
@@ -2511,3 +2626,4 @@ exports.isWeb = isWeb;
2511
2626
  exports.orbLegacy = orbLegacy;
2512
2627
  exports.secureDocumentLegacy = secureDocumentLegacy;
2513
2628
  exports.selfieCheckLegacy = selfieCheckLegacy;
2629
+ exports.setDebug = setDebug;
package/dist/index.d.cts CHANGED
@@ -173,8 +173,8 @@ interface IDKitResultSession {
173
173
  nonce: string;
174
174
  /** Action description (only if provided in input) */
175
175
  action_description?: string;
176
- /** Session ID returned by the World App */
177
- session_id: string;
176
+ /** Opaque session identifier returned by the World App in `session_<hex>` format */
177
+ session_id: `session_${string}`;
178
178
  /** Array of session credential responses */
179
179
  responses: ResponseItemSession[];
180
180
  /** The environment used for this request ("production" or "staging") */
@@ -297,10 +297,10 @@ declare enum IDKitErrorCodes {
297
297
  */
298
298
  declare function isInWorldApp(): boolean;
299
299
  interface BuilderConfig {
300
- type: "request" | "session" | "proveSession";
300
+ type: "request" | "createSession" | "proveSession";
301
301
  app_id: string;
302
302
  action?: string;
303
- session_id?: string;
303
+ session_id?: `session_${string}`;
304
304
  rp_context?: RpContext;
305
305
  action_description?: string;
306
306
  bridge_url?: string;
@@ -355,6 +355,74 @@ interface IDKitRequest {
355
355
  /** Poll continuously until completion or timeout */
356
356
  pollUntilCompletion(options?: WaitOptions): Promise<IDKitCompletionResult>;
357
357
  }
358
+ /**
359
+ * Creates a CredentialRequest for a credential type
360
+ *
361
+ * @param credential_type - The type of credential to request (e.g., 'proof_of_human', 'face')
362
+ * @param options - Optional signal, genesis_issued_at_min, and expires_at_min
363
+ * @returns A CredentialRequest object
364
+ *
365
+ * @example
366
+ * ```typescript
367
+ * const orb = CredentialRequest('proof_of_human', { signal: 'user-123' })
368
+ * const face = CredentialRequest('face')
369
+ * // Require credential to be valid for at least one year
370
+ * const withExpiry = CredentialRequest('proof_of_human', { expires_at_min: Date.now() / 1000 + 60 * 60 * 60 * 24 * 365 })
371
+ * ```
372
+ */
373
+ declare function CredentialRequest(credential_type: CredentialType, options?: {
374
+ signal?: string;
375
+ genesis_issued_at_min?: number;
376
+ expires_at_min?: number;
377
+ }): CredentialRequestType;
378
+ /**
379
+ * Creates an OR constraint - at least one child must be satisfied
380
+ *
381
+ * @param nodes - Constraint nodes (CredentialRequests or nested constraints)
382
+ * @returns An "any" constraint node
383
+ *
384
+ * @example
385
+ * ```typescript
386
+ * const constraint = any(CredentialRequest('proof_of_human'), CredentialRequest('face'))
387
+ * ```
388
+ */
389
+ declare function any(...nodes: ConstraintNode[]): {
390
+ any: ConstraintNode[];
391
+ };
392
+ /**
393
+ * Creates an AND constraint - all children must be satisfied
394
+ *
395
+ * @param nodes - Constraint nodes (CredentialRequests or nested constraints)
396
+ * @returns An "all" constraint node
397
+ *
398
+ * @example
399
+ * ```typescript
400
+ * const constraint = all(CredentialRequest('proof_of_human'), any(CredentialRequest('passport'), CredentialRequest('mnc')))
401
+ * ```
402
+ */
403
+ declare function all(...nodes: ConstraintNode[]): {
404
+ all: ConstraintNode[];
405
+ };
406
+ /**
407
+ * Creates an enumerate constraint - all satisfiable children should be selected
408
+ *
409
+ * `enumerate` is satisfied when at least one child is satisfied.
410
+ *
411
+ * @param nodes - Constraint nodes (CredentialRequests or nested constraints)
412
+ * @returns An "enumerate" constraint node
413
+ *
414
+ * @example
415
+ * ```typescript
416
+ * const constraint = enumerate(
417
+ * CredentialRequest('passport'),
418
+ * CredentialRequest('mnc'),
419
+ * )
420
+ * ```
421
+ */
422
+ declare function enumerate(...nodes: ConstraintNode[]): {
423
+ enumerate: ConstraintNode[];
424
+ };
425
+
358
426
  /**
359
427
  * Creates an OrbLegacy preset for World ID 3.0 legacy support
360
428
  *
@@ -522,6 +590,60 @@ declare class IDKitBuilder {
522
590
  * ```
523
591
  */
524
592
  declare function createRequest(config: IDKitRequestConfig): IDKitBuilder;
593
+ /**
594
+ * Creates a new session builder (no action, no existing session_id)
595
+ *
596
+ * Use this when creating a new session for a user who doesn't have one yet.
597
+ * The response will include a `session_id` that should be saved for future
598
+ * session proofs with `proveSession()`.
599
+ *
600
+ * @param config - Session configuration (no action field)
601
+ * @returns IDKitBuilder - A builder instance
602
+ *
603
+ * @example
604
+ * ```typescript
605
+ * import { IDKit, CredentialRequest, any } from '@worldcoin/idkit-core'
606
+ *
607
+ * // Create a new session (user doesn't have session_id yet)
608
+ * const request = await IDKit.createSession({
609
+ * app_id: 'app_staging_xxxxx',
610
+ * rp_context: { ... },
611
+ * }).constraints(any(CredentialRequest('proof_of_human'), CredentialRequest('face')));
612
+ *
613
+ * // Display QR, wait for proof
614
+ * const result = await request.pollUntilCompletion();
615
+ * // result.session_id -> save this for future sessions
616
+ * // result.responses[0].session_nullifier -> for session tracking
617
+ * ```
618
+ */
619
+ declare function createSession(config: IDKitSessionConfig): IDKitBuilder;
620
+ /**
621
+ * Creates a builder for proving an existing session (no action, has session_id)
622
+ *
623
+ * Use this when a returning user needs to prove they own an existing session.
624
+ * The `sessionId` should be the opaque `session_<hex>` value previously returned
625
+ * from `createSession()`.
626
+ *
627
+ * @param sessionId - The protocol session ID from a previous session creation
628
+ * @param config - Session configuration (no action field)
629
+ * @returns IDKitBuilder - A builder instance
630
+ *
631
+ * @example
632
+ * ```typescript
633
+ * import { IDKit, CredentialRequest, any } from '@worldcoin/idkit-core'
634
+ *
635
+ * // Prove an existing session (user returns)
636
+ * const request = await IDKit.proveSession(savedSessionId, {
637
+ * app_id: 'app_staging_xxxxx',
638
+ * rp_context: { ... },
639
+ * }).constraints(any(CredentialRequest('proof_of_human'), CredentialRequest('face')));
640
+ *
641
+ * const result = await request.pollUntilCompletion();
642
+ * // result.session_id -> same session
643
+ * // result.responses[0].session_nullifier -> should match for same user
644
+ * ```
645
+ */
646
+ declare function proveSession(sessionId: `session_${string}`, config: IDKitSessionConfig): IDKitBuilder;
525
647
  /**
526
648
  * IDKit namespace providing the main API entry points
527
649
  *
@@ -546,6 +668,18 @@ declare function createRequest(config: IDKitRequestConfig): IDKitBuilder;
546
668
  declare const IDKit: {
547
669
  /** Create a new verification request */
548
670
  request: typeof createRequest;
671
+ /** Create a new session (no action, no existing session_id) */
672
+ createSession: typeof createSession;
673
+ /** Prove an existing session (no action, has session_id) */
674
+ proveSession: typeof proveSession;
675
+ /** Create a CredentialRequest for a credential type */
676
+ CredentialRequest: typeof CredentialRequest;
677
+ /** Create an OR constraint - at least one child must be satisfied */
678
+ any: typeof any;
679
+ /** Create an AND constraint - all children must be satisfied */
680
+ all: typeof all;
681
+ /** Create an enumerate constraint - all satisfiable children should be selected */
682
+ enumerate: typeof enumerate;
549
683
  /** Create an OrbLegacy preset for World ID 3.0 legacy support */
550
684
  orbLegacy: typeof orbLegacy;
551
685
  /** Create a SecureDocumentLegacy preset for World ID 3.0 legacy support */
@@ -580,4 +714,7 @@ declare const isWeb: () => boolean;
580
714
  */
581
715
  declare const isNode: () => boolean;
582
716
 
583
- export { type AbiEncodedValue, type ConstraintNode, type CredentialRequestType, type CredentialType, type DeviceLegacyPreset, type DocumentLegacyPreset, IDKit, type IDKitCompletionResult, type IDKitErrorCode, IDKitErrorCodes, type IDKitRequest, type IDKitRequestConfig, type IDKitResult, type IDKitResultSession, type IDKitSessionConfig, type OrbLegacyPreset, type Preset, type ResponseItemSession, type ResponseItemV3, type ResponseItemV4, type RpContext, type SecureDocumentLegacyPreset, type SelfieCheckLegacyPreset, type Status$1 as Status, type WaitOptions, deviceLegacy, documentLegacy, isInWorldApp, isNode, isReactNative, isWeb, orbLegacy, secureDocumentLegacy, selfieCheckLegacy };
717
+ declare function isDebug(): boolean;
718
+ declare function setDebug(enabled: boolean): void;
719
+
720
+ export { type AbiEncodedValue, type ConstraintNode, CredentialRequest, type CredentialRequestType, type CredentialType, type DeviceLegacyPreset, type DocumentLegacyPreset, IDKit, type IDKitCompletionResult, type IDKitErrorCode, IDKitErrorCodes, type IDKitRequest, type IDKitRequestConfig, type IDKitResult, type IDKitResultSession, type IDKitSessionConfig, type OrbLegacyPreset, type Preset, type ResponseItemSession, type ResponseItemV3, type ResponseItemV4, type RpContext, type SecureDocumentLegacyPreset, type SelfieCheckLegacyPreset, type Status$1 as Status, type WaitOptions, all, any, deviceLegacy, documentLegacy, enumerate, isDebug, isInWorldApp, isNode, isReactNative, isWeb, orbLegacy, secureDocumentLegacy, selfieCheckLegacy, setDebug };
package/dist/index.d.ts CHANGED
@@ -173,8 +173,8 @@ interface IDKitResultSession {
173
173
  nonce: string;
174
174
  /** Action description (only if provided in input) */
175
175
  action_description?: string;
176
- /** Session ID returned by the World App */
177
- session_id: string;
176
+ /** Opaque session identifier returned by the World App in `session_<hex>` format */
177
+ session_id: `session_${string}`;
178
178
  /** Array of session credential responses */
179
179
  responses: ResponseItemSession[];
180
180
  /** The environment used for this request ("production" or "staging") */
@@ -297,10 +297,10 @@ declare enum IDKitErrorCodes {
297
297
  */
298
298
  declare function isInWorldApp(): boolean;
299
299
  interface BuilderConfig {
300
- type: "request" | "session" | "proveSession";
300
+ type: "request" | "createSession" | "proveSession";
301
301
  app_id: string;
302
302
  action?: string;
303
- session_id?: string;
303
+ session_id?: `session_${string}`;
304
304
  rp_context?: RpContext;
305
305
  action_description?: string;
306
306
  bridge_url?: string;
@@ -355,6 +355,74 @@ interface IDKitRequest {
355
355
  /** Poll continuously until completion or timeout */
356
356
  pollUntilCompletion(options?: WaitOptions): Promise<IDKitCompletionResult>;
357
357
  }
358
+ /**
359
+ * Creates a CredentialRequest for a credential type
360
+ *
361
+ * @param credential_type - The type of credential to request (e.g., 'proof_of_human', 'face')
362
+ * @param options - Optional signal, genesis_issued_at_min, and expires_at_min
363
+ * @returns A CredentialRequest object
364
+ *
365
+ * @example
366
+ * ```typescript
367
+ * const orb = CredentialRequest('proof_of_human', { signal: 'user-123' })
368
+ * const face = CredentialRequest('face')
369
+ * // Require credential to be valid for at least one year
370
+ * const withExpiry = CredentialRequest('proof_of_human', { expires_at_min: Date.now() / 1000 + 60 * 60 * 60 * 24 * 365 })
371
+ * ```
372
+ */
373
+ declare function CredentialRequest(credential_type: CredentialType, options?: {
374
+ signal?: string;
375
+ genesis_issued_at_min?: number;
376
+ expires_at_min?: number;
377
+ }): CredentialRequestType;
378
+ /**
379
+ * Creates an OR constraint - at least one child must be satisfied
380
+ *
381
+ * @param nodes - Constraint nodes (CredentialRequests or nested constraints)
382
+ * @returns An "any" constraint node
383
+ *
384
+ * @example
385
+ * ```typescript
386
+ * const constraint = any(CredentialRequest('proof_of_human'), CredentialRequest('face'))
387
+ * ```
388
+ */
389
+ declare function any(...nodes: ConstraintNode[]): {
390
+ any: ConstraintNode[];
391
+ };
392
+ /**
393
+ * Creates an AND constraint - all children must be satisfied
394
+ *
395
+ * @param nodes - Constraint nodes (CredentialRequests or nested constraints)
396
+ * @returns An "all" constraint node
397
+ *
398
+ * @example
399
+ * ```typescript
400
+ * const constraint = all(CredentialRequest('proof_of_human'), any(CredentialRequest('passport'), CredentialRequest('mnc')))
401
+ * ```
402
+ */
403
+ declare function all(...nodes: ConstraintNode[]): {
404
+ all: ConstraintNode[];
405
+ };
406
+ /**
407
+ * Creates an enumerate constraint - all satisfiable children should be selected
408
+ *
409
+ * `enumerate` is satisfied when at least one child is satisfied.
410
+ *
411
+ * @param nodes - Constraint nodes (CredentialRequests or nested constraints)
412
+ * @returns An "enumerate" constraint node
413
+ *
414
+ * @example
415
+ * ```typescript
416
+ * const constraint = enumerate(
417
+ * CredentialRequest('passport'),
418
+ * CredentialRequest('mnc'),
419
+ * )
420
+ * ```
421
+ */
422
+ declare function enumerate(...nodes: ConstraintNode[]): {
423
+ enumerate: ConstraintNode[];
424
+ };
425
+
358
426
  /**
359
427
  * Creates an OrbLegacy preset for World ID 3.0 legacy support
360
428
  *
@@ -522,6 +590,60 @@ declare class IDKitBuilder {
522
590
  * ```
523
591
  */
524
592
  declare function createRequest(config: IDKitRequestConfig): IDKitBuilder;
593
+ /**
594
+ * Creates a new session builder (no action, no existing session_id)
595
+ *
596
+ * Use this when creating a new session for a user who doesn't have one yet.
597
+ * The response will include a `session_id` that should be saved for future
598
+ * session proofs with `proveSession()`.
599
+ *
600
+ * @param config - Session configuration (no action field)
601
+ * @returns IDKitBuilder - A builder instance
602
+ *
603
+ * @example
604
+ * ```typescript
605
+ * import { IDKit, CredentialRequest, any } from '@worldcoin/idkit-core'
606
+ *
607
+ * // Create a new session (user doesn't have session_id yet)
608
+ * const request = await IDKit.createSession({
609
+ * app_id: 'app_staging_xxxxx',
610
+ * rp_context: { ... },
611
+ * }).constraints(any(CredentialRequest('proof_of_human'), CredentialRequest('face')));
612
+ *
613
+ * // Display QR, wait for proof
614
+ * const result = await request.pollUntilCompletion();
615
+ * // result.session_id -> save this for future sessions
616
+ * // result.responses[0].session_nullifier -> for session tracking
617
+ * ```
618
+ */
619
+ declare function createSession(config: IDKitSessionConfig): IDKitBuilder;
620
+ /**
621
+ * Creates a builder for proving an existing session (no action, has session_id)
622
+ *
623
+ * Use this when a returning user needs to prove they own an existing session.
624
+ * The `sessionId` should be the opaque `session_<hex>` value previously returned
625
+ * from `createSession()`.
626
+ *
627
+ * @param sessionId - The protocol session ID from a previous session creation
628
+ * @param config - Session configuration (no action field)
629
+ * @returns IDKitBuilder - A builder instance
630
+ *
631
+ * @example
632
+ * ```typescript
633
+ * import { IDKit, CredentialRequest, any } from '@worldcoin/idkit-core'
634
+ *
635
+ * // Prove an existing session (user returns)
636
+ * const request = await IDKit.proveSession(savedSessionId, {
637
+ * app_id: 'app_staging_xxxxx',
638
+ * rp_context: { ... },
639
+ * }).constraints(any(CredentialRequest('proof_of_human'), CredentialRequest('face')));
640
+ *
641
+ * const result = await request.pollUntilCompletion();
642
+ * // result.session_id -> same session
643
+ * // result.responses[0].session_nullifier -> should match for same user
644
+ * ```
645
+ */
646
+ declare function proveSession(sessionId: `session_${string}`, config: IDKitSessionConfig): IDKitBuilder;
525
647
  /**
526
648
  * IDKit namespace providing the main API entry points
527
649
  *
@@ -546,6 +668,18 @@ declare function createRequest(config: IDKitRequestConfig): IDKitBuilder;
546
668
  declare const IDKit: {
547
669
  /** Create a new verification request */
548
670
  request: typeof createRequest;
671
+ /** Create a new session (no action, no existing session_id) */
672
+ createSession: typeof createSession;
673
+ /** Prove an existing session (no action, has session_id) */
674
+ proveSession: typeof proveSession;
675
+ /** Create a CredentialRequest for a credential type */
676
+ CredentialRequest: typeof CredentialRequest;
677
+ /** Create an OR constraint - at least one child must be satisfied */
678
+ any: typeof any;
679
+ /** Create an AND constraint - all children must be satisfied */
680
+ all: typeof all;
681
+ /** Create an enumerate constraint - all satisfiable children should be selected */
682
+ enumerate: typeof enumerate;
549
683
  /** Create an OrbLegacy preset for World ID 3.0 legacy support */
550
684
  orbLegacy: typeof orbLegacy;
551
685
  /** Create a SecureDocumentLegacy preset for World ID 3.0 legacy support */
@@ -580,4 +714,7 @@ declare const isWeb: () => boolean;
580
714
  */
581
715
  declare const isNode: () => boolean;
582
716
 
583
- export { type AbiEncodedValue, type ConstraintNode, type CredentialRequestType, type CredentialType, type DeviceLegacyPreset, type DocumentLegacyPreset, IDKit, type IDKitCompletionResult, type IDKitErrorCode, IDKitErrorCodes, type IDKitRequest, type IDKitRequestConfig, type IDKitResult, type IDKitResultSession, type IDKitSessionConfig, type OrbLegacyPreset, type Preset, type ResponseItemSession, type ResponseItemV3, type ResponseItemV4, type RpContext, type SecureDocumentLegacyPreset, type SelfieCheckLegacyPreset, type Status$1 as Status, type WaitOptions, deviceLegacy, documentLegacy, isInWorldApp, isNode, isReactNative, isWeb, orbLegacy, secureDocumentLegacy, selfieCheckLegacy };
717
+ declare function isDebug(): boolean;
718
+ declare function setDebug(enabled: boolean): void;
719
+
720
+ export { type AbiEncodedValue, type ConstraintNode, CredentialRequest, type CredentialRequestType, type CredentialType, type DeviceLegacyPreset, type DocumentLegacyPreset, IDKit, type IDKitCompletionResult, type IDKitErrorCode, IDKitErrorCodes, type IDKitRequest, type IDKitRequestConfig, type IDKitResult, type IDKitResultSession, type IDKitSessionConfig, type OrbLegacyPreset, type Preset, type ResponseItemSession, type ResponseItemV3, type ResponseItemV4, type RpContext, type SecureDocumentLegacyPreset, type SelfieCheckLegacyPreset, type Status$1 as Status, type WaitOptions, all, any, deviceLegacy, documentLegacy, enumerate, isDebug, isInWorldApp, isNode, isReactNative, isWeb, orbLegacy, secureDocumentLegacy, selfieCheckLegacy, setDebug };
package/dist/index.js CHANGED
@@ -3,9 +3,9 @@ import { keccak_256 } from '@noble/hashes/sha3';
3
3
  import { hexToBytes, bytesToHex } from '@noble/hashes/utils';
4
4
 
5
5
  var __defProp = Object.defineProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
6
+ var __export = (target, all2) => {
7
+ for (var name in all2)
8
+ __defProp(target, name, { get: all2[name], enumerable: true });
9
9
  };
10
10
 
11
11
  // src/types/result.ts
@@ -533,8 +533,8 @@ var IDKitBuilder = class _IDKitBuilder {
533
533
  * Builds a v1 (legacy) native payload from a preset (synchronous, no bridge connection).
534
534
  *
535
535
  * Used by the native transport when the World App only supports verify v1.
536
- * Only legacy presets produce valid v1 payloads (constraints always have
537
- * `Deprecated` verification level and will fail).
536
+ * Only legacy presets produce valid v1 payloads (constraint-based requests
537
+ * default to `Device` level and may not carry the correct action).
538
538
  *
539
539
  * # Errors
540
540
  *
@@ -1393,7 +1393,7 @@ function __wbg_get_imports() {
1393
1393
  const a = state0.a;
1394
1394
  state0.a = 0;
1395
1395
  try {
1396
- return __wasm_bindgen_func_elem_1421(a, state0.b, arg02, arg12);
1396
+ return __wasm_bindgen_func_elem_1423(a, state0.b, arg02, arg12);
1397
1397
  } finally {
1398
1398
  state0.a = a;
1399
1399
  }
@@ -1573,11 +1573,11 @@ function __wbg_get_imports() {
1573
1573
  return addHeapObject(ret);
1574
1574
  },
1575
1575
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
1576
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_643, __wasm_bindgen_func_elem_644);
1576
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_645, __wasm_bindgen_func_elem_646);
1577
1577
  return addHeapObject(ret);
1578
1578
  },
1579
1579
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
1580
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_973, __wasm_bindgen_func_elem_974);
1580
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_975, __wasm_bindgen_func_elem_976);
1581
1581
  return addHeapObject(ret);
1582
1582
  },
1583
1583
  __wbindgen_cast_0000000000000003: function(arg0) {
@@ -1613,13 +1613,13 @@ function __wbg_get_imports() {
1613
1613
  "./idkit_wasm_bg.js": import0
1614
1614
  };
1615
1615
  }
1616
- function __wasm_bindgen_func_elem_644(arg0, arg1) {
1617
- wasm.__wasm_bindgen_func_elem_644(arg0, arg1);
1616
+ function __wasm_bindgen_func_elem_646(arg0, arg1) {
1617
+ wasm.__wasm_bindgen_func_elem_646(arg0, arg1);
1618
1618
  }
1619
- function __wasm_bindgen_func_elem_974(arg0, arg1, arg2) {
1619
+ function __wasm_bindgen_func_elem_976(arg0, arg1, arg2) {
1620
1620
  try {
1621
1621
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1622
- wasm.__wasm_bindgen_func_elem_974(retptr, arg0, arg1, addHeapObject(arg2));
1622
+ wasm.__wasm_bindgen_func_elem_976(retptr, arg0, arg1, addHeapObject(arg2));
1623
1623
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1624
1624
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1625
1625
  if (r1) {
@@ -1629,8 +1629,8 @@ function __wasm_bindgen_func_elem_974(arg0, arg1, arg2) {
1629
1629
  wasm.__wbindgen_add_to_stack_pointer(16);
1630
1630
  }
1631
1631
  }
1632
- function __wasm_bindgen_func_elem_1421(arg0, arg1, arg2, arg3) {
1633
- wasm.__wasm_bindgen_func_elem_1421(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1632
+ function __wasm_bindgen_func_elem_1423(arg0, arg1, arg2, arg3) {
1633
+ wasm.__wasm_bindgen_func_elem_1423(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1634
1634
  }
1635
1635
  var __wbindgen_enum_RequestCache = ["default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached"];
1636
1636
  var __wbindgen_enum_RequestCredentials = ["omit", "same-origin", "include"];
@@ -1959,6 +1959,16 @@ async function initIDKit() {
1959
1959
  return wasmInitPromise;
1960
1960
  }
1961
1961
 
1962
+ // src/lib/debug.ts
1963
+ var _debug = false;
1964
+ function isDebug() {
1965
+ if (_debug) return true;
1966
+ return typeof window !== "undefined" && Boolean(window.IDKIT_DEBUG);
1967
+ }
1968
+ function setDebug(enabled) {
1969
+ _debug = enabled;
1970
+ }
1971
+
1962
1972
  // src/transports/native.ts
1963
1973
  var MINIAPP_VERIFY_ACTION = "miniapp-verify-action";
1964
1974
  function isInWorldApp() {
@@ -1974,9 +1984,10 @@ var _requestCounter = 0;
1974
1984
  var _activeNativeRequest = null;
1975
1985
  function createNativeRequest(wasmPayload, config, signalHashes = {}, legacySignalHash, version = 2) {
1976
1986
  if (_activeNativeRequest?.isPending()) {
1977
- console.warn(
1978
- "IDKit native request already in flight. Reusing active request."
1979
- );
1987
+ if (isDebug())
1988
+ console.warn(
1989
+ "[IDKit] Native: request already in flight, reusing active request"
1990
+ );
1980
1991
  return _activeNativeRequest;
1981
1992
  }
1982
1993
  const request2 = new NativeIDKitRequest(
@@ -2003,6 +2014,11 @@ var NativeIDKitRequest = class {
2003
2014
  const handleIncomingPayload = (responsePayload) => {
2004
2015
  if (this.completionResult) return;
2005
2016
  if (responsePayload?.status === "error") {
2017
+ if (isDebug())
2018
+ console.warn(
2019
+ "[IDKit] Native: received error response",
2020
+ responsePayload.error_code
2021
+ );
2006
2022
  this.complete({
2007
2023
  success: false,
2008
2024
  error: responsePayload.error_code ?? "generic_error" /* GenericError */
@@ -2036,7 +2052,9 @@ var NativeIDKitRequest = class {
2036
2052
  this.miniKitHandler = miniKitHandler;
2037
2053
  miniKit.subscribe(MINIAPP_VERIFY_ACTION, miniKitHandler);
2038
2054
  }
2039
- } catch {
2055
+ } catch (err) {
2056
+ if (isDebug())
2057
+ console.warn("[IDKit] Native: MiniKit subscribe failed", err);
2040
2058
  }
2041
2059
  const sendPayload = {
2042
2060
  command: "verify",
@@ -2046,16 +2064,29 @@ var NativeIDKitRequest = class {
2046
2064
  try {
2047
2065
  const w = window;
2048
2066
  if (w.webkit?.messageHandlers?.minikit) {
2067
+ if (isDebug())
2068
+ console.debug(
2069
+ `[IDKit] Native: sending verify command (version=${version}, platform=ios)`
2070
+ );
2049
2071
  w.webkit.messageHandlers.minikit.postMessage(sendPayload);
2050
2072
  } else if (w.Android) {
2073
+ if (isDebug())
2074
+ console.debug(
2075
+ `[IDKit] Native: sending verify command (version=${version}, platform=android)`
2076
+ );
2051
2077
  w.Android.postMessage(JSON.stringify(sendPayload));
2052
2078
  } else {
2079
+ if (isDebug())
2080
+ console.warn(
2081
+ "[IDKit] Native: no native bridge found (no webkit/Android)"
2082
+ );
2053
2083
  this.complete({
2054
2084
  success: false,
2055
2085
  error: "generic_error" /* GenericError */
2056
2086
  });
2057
2087
  }
2058
- } catch {
2088
+ } catch (err) {
2089
+ if (isDebug()) console.warn("[IDKit] Native: postMessage failed", err);
2059
2090
  this.complete({
2060
2091
  success: false,
2061
2092
  error: "generic_error" /* GenericError */
@@ -2066,6 +2097,11 @@ var NativeIDKitRequest = class {
2066
2097
  // Single entry point for finishing the request. Idempotent — first caller wins.
2067
2098
  complete(result) {
2068
2099
  if (this.completionResult) return;
2100
+ if (isDebug())
2101
+ console.debug(
2102
+ "[IDKit] Native: request completed",
2103
+ result.success ? "success" : `error=${result.error}`
2104
+ );
2069
2105
  this.completionResult = result;
2070
2106
  this.cleanup();
2071
2107
  this.resolveFn?.(result);
@@ -2085,7 +2121,9 @@ var NativeIDKitRequest = class {
2085
2121
  try {
2086
2122
  const miniKit = window.MiniKit;
2087
2123
  miniKit?.unsubscribe?.(MINIAPP_VERIFY_ACTION);
2088
- } catch {
2124
+ } catch (err) {
2125
+ if (isDebug())
2126
+ console.warn("[IDKit] Native: MiniKit unsubscribe failed", err);
2089
2127
  }
2090
2128
  this.miniKitHandler = null;
2091
2129
  }
@@ -2136,14 +2174,15 @@ var NativeIDKitRequest = class {
2136
2174
  function nativeResultToIDKitResult(payload, config, signalHashes, legacySignalHash) {
2137
2175
  const p = payload;
2138
2176
  const rpNonce = config.rp_context?.nonce ?? "";
2139
- if ("responses" in p && Array.isArray(p.responses)) {
2140
- const items = p.responses;
2141
- if (p.session_id) {
2177
+ if ("proof_response" in p && p.proof_response != null) {
2178
+ const proof_response = p.proof_response;
2179
+ const items = proof_response.responses ?? [];
2180
+ if (proof_response.session_id) {
2142
2181
  return {
2143
2182
  protocol_version: "4.0",
2144
- nonce: p.nonce ?? rpNonce,
2145
- action_description: p.action_description,
2146
- session_id: p.session_id,
2183
+ nonce: proof_response.nonce ?? rpNonce,
2184
+ action_description: proof_response.action_description,
2185
+ session_id: proof_response.session_id,
2147
2186
  responses: items.map((item) => ({
2148
2187
  identifier: item.identifier,
2149
2188
  signal_hash: signalHashes[item.identifier],
@@ -2157,9 +2196,9 @@ function nativeResultToIDKitResult(payload, config, signalHashes, legacySignalHa
2157
2196
  }
2158
2197
  return {
2159
2198
  protocol_version: "4.0",
2160
- nonce: p.nonce ?? rpNonce,
2161
- action: p.action ?? config.action ?? "",
2162
- action_description: p.action_description,
2199
+ nonce: proof_response.nonce ?? rpNonce,
2200
+ action: proof_response.action ?? config.action ?? "",
2201
+ action_description: proof_response.action_description,
2163
2202
  responses: items.map((item) => ({
2164
2203
  identifier: item.identifier,
2165
2204
  signal_hash: signalHashes[item.identifier],
@@ -2205,6 +2244,7 @@ function nativeResultToIDKitResult(payload, config, signalHashes, legacySignalHa
2205
2244
  }
2206
2245
 
2207
2246
  // src/request.ts
2247
+ var SESSION_ID_PATTERN = /^session_[0-9a-fA-F]{128}$/;
2208
2248
  var IDKitRequestImpl = class {
2209
2249
  constructor(wasmRequest) {
2210
2250
  this.wasmRequest = wasmRequest;
@@ -2245,6 +2285,23 @@ var IDKitRequestImpl = class {
2245
2285
  }
2246
2286
  }
2247
2287
  };
2288
+ function CredentialRequest(credential_type, options) {
2289
+ return {
2290
+ type: credential_type,
2291
+ signal: options?.signal,
2292
+ genesis_issued_at_min: options?.genesis_issued_at_min,
2293
+ expires_at_min: options?.expires_at_min
2294
+ };
2295
+ }
2296
+ function any(...nodes) {
2297
+ return { any: nodes };
2298
+ }
2299
+ function all(...nodes) {
2300
+ return { all: nodes };
2301
+ }
2302
+ function enumerate(...nodes) {
2303
+ return { enumerate: nodes };
2304
+ }
2248
2305
  function orbLegacy(opts = {}) {
2249
2306
  return { type: "OrbLegacy", signal: opts.signal };
2250
2307
  }
@@ -2337,7 +2394,7 @@ var IDKitBuilder2 = class {
2337
2394
  wasmResult.payload,
2338
2395
  this.config,
2339
2396
  wasmResult.signal_hashes ?? {},
2340
- wasmResult.legacy_signal_hash ?? void 0,
2397
+ wasmResult.legacy_signal_hash,
2341
2398
  2
2342
2399
  );
2343
2400
  }
@@ -2363,6 +2420,11 @@ var IDKitBuilder2 = class {
2363
2420
  * ```
2364
2421
  */
2365
2422
  async preset(preset) {
2423
+ if (this.config.type === "createSession" || this.config.type === "proveSession") {
2424
+ throw new Error(
2425
+ "Presets are not supported for session flows. Use .constraints() instead."
2426
+ );
2427
+ }
2366
2428
  await initIDKit();
2367
2429
  if (isInWorldApp()) {
2368
2430
  const verifyVersion = getWorldAppVerifyVersion();
@@ -2373,7 +2435,7 @@ var IDKitBuilder2 = class {
2373
2435
  wasmResult.payload,
2374
2436
  this.config,
2375
2437
  wasmResult.signal_hashes ?? {},
2376
- wasmResult.legacy_signal_hash ?? void 0,
2438
+ wasmResult.legacy_signal_hash,
2377
2439
  2
2378
2440
  );
2379
2441
  }
@@ -2384,7 +2446,7 @@ var IDKitBuilder2 = class {
2384
2446
  wasmResult.payload,
2385
2447
  this.config,
2386
2448
  wasmResult.signal_hashes ?? {},
2387
- wasmResult.legacy_signal_hash ?? void 0,
2449
+ wasmResult.legacy_signal_hash,
2388
2450
  1
2389
2451
  );
2390
2452
  } catch (err) {
@@ -2433,22 +2495,70 @@ function createRequest(config) {
2433
2495
  environment: config.environment
2434
2496
  });
2435
2497
  }
2498
+ function createSession2(config) {
2499
+ if (!config.app_id) {
2500
+ throw new Error("app_id is required");
2501
+ }
2502
+ if (!config.rp_context) {
2503
+ throw new Error(
2504
+ "rp_context is required. Generate it on your backend using signRequest()."
2505
+ );
2506
+ }
2507
+ return new IDKitBuilder2({
2508
+ type: "createSession",
2509
+ app_id: config.app_id,
2510
+ rp_context: config.rp_context,
2511
+ action_description: config.action_description,
2512
+ bridge_url: config.bridge_url,
2513
+ return_to: config.return_to,
2514
+ override_connect_base_url: config.override_connect_base_url,
2515
+ environment: config.environment
2516
+ });
2517
+ }
2518
+ function proveSession2(sessionId, config) {
2519
+ if (!sessionId) {
2520
+ throw new Error("session_id is required");
2521
+ }
2522
+ if (!SESSION_ID_PATTERN.test(sessionId)) {
2523
+ throw new Error(
2524
+ "session_id must be in the format session_<128 hex characters>"
2525
+ );
2526
+ }
2527
+ if (!config.app_id) {
2528
+ throw new Error("app_id is required");
2529
+ }
2530
+ if (!config.rp_context) {
2531
+ throw new Error(
2532
+ "rp_context is required. Generate it on your backend using signRequest()."
2533
+ );
2534
+ }
2535
+ return new IDKitBuilder2({
2536
+ type: "proveSession",
2537
+ session_id: sessionId,
2538
+ app_id: config.app_id,
2539
+ rp_context: config.rp_context,
2540
+ action_description: config.action_description,
2541
+ bridge_url: config.bridge_url,
2542
+ return_to: config.return_to,
2543
+ override_connect_base_url: config.override_connect_base_url,
2544
+ environment: config.environment
2545
+ });
2546
+ }
2436
2547
  var IDKit = {
2437
2548
  /** Create a new verification request */
2438
2549
  request: createRequest,
2439
- // TODO: Re-enable when World ID 4.0 is live
2440
- // /** Create a new session (no action, no existing session_id) */
2441
- // createSession,
2442
- // /** Prove an existing session (no action, has session_id) */
2443
- // proveSession,
2444
- // /** Create a CredentialRequest for a credential type */
2445
- // CredentialRequest,
2446
- // /** Create an OR constraint - at least one child must be satisfied */
2447
- // any,
2448
- // /** Create an AND constraint - all children must be satisfied */
2449
- // all,
2450
- // /** Create an enumerate constraint - all satisfiable children should be selected */
2451
- // enumerate,
2550
+ /** Create a new session (no action, no existing session_id) */
2551
+ createSession: createSession2,
2552
+ /** Prove an existing session (no action, has session_id) */
2553
+ proveSession: proveSession2,
2554
+ /** Create a CredentialRequest for a credential type */
2555
+ CredentialRequest,
2556
+ /** Create an OR constraint - at least one child must be satisfied */
2557
+ any,
2558
+ /** Create an AND constraint - all children must be satisfied */
2559
+ all,
2560
+ /** Create an enumerate constraint - all satisfiable children should be selected */
2561
+ enumerate,
2452
2562
  /** Create an OrbLegacy preset for World ID 3.0 legacy support */
2453
2563
  orbLegacy,
2454
2564
  /** Create a SecureDocumentLegacy preset for World ID 3.0 legacy support */
@@ -2492,4 +2602,4 @@ function isValidHex(s) {
2492
2602
  return /^[0-9a-fA-F]+$/.test(s);
2493
2603
  }
2494
2604
 
2495
- export { IDKit, IDKitErrorCodes, deviceLegacy, documentLegacy, hashSignal2 as hashSignal, isInWorldApp, isNode, isReactNative, isWeb, orbLegacy, secureDocumentLegacy, selfieCheckLegacy };
2605
+ export { CredentialRequest, IDKit, IDKitErrorCodes, all, any, deviceLegacy, documentLegacy, enumerate, hashSignal2 as hashSignal, isDebug, isInWorldApp, isNode, isReactNative, isWeb, orbLegacy, secureDocumentLegacy, selfieCheckLegacy, setDebug };
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ var idkitServer = require('@worldcoin/idkit-server');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, "getSessionCommitment", {
8
+ enumerable: true,
9
+ get: function () { return idkitServer.getSessionCommitment; }
10
+ });
@@ -0,0 +1 @@
1
+ export { getSessionCommitment } from '@worldcoin/idkit-server';
@@ -0,0 +1 @@
1
+ export { getSessionCommitment } from '@worldcoin/idkit-server';
@@ -0,0 +1 @@
1
+ export { getSessionCommitment } from '@worldcoin/idkit-server';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@worldcoin/idkit-core",
3
- "version": "4.0.16",
3
+ "version": "4.1.0",
4
4
  "description": "Core IDKit SDK for World ID - Pure TypeScript, no dependencies",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -21,6 +21,11 @@
21
21
  "types": "./dist/hashing.d.ts",
22
22
  "import": "./dist/hashing.js",
23
23
  "require": "./dist/hashing.cjs"
24
+ },
25
+ "./session": {
26
+ "types": "./dist/session.d.ts",
27
+ "import": "./dist/session.js",
28
+ "require": "./dist/session.cjs"
24
29
  }
25
30
  },
26
31
  "files": [
@@ -52,7 +57,7 @@
52
57
  },
53
58
  "dependencies": {
54
59
  "@noble/hashes": "^1.7.2",
55
- "@worldcoin/idkit-server": "1.0.0"
60
+ "@worldcoin/idkit-server": "1.1.0"
56
61
  },
57
62
  "devDependencies": {
58
63
  "@types/node": "^20.19.30",