@worldcoin/idkit-core 4.0.1-dev.123c6a8 → 4.0.1-dev.2039000

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.
package/dist/index.cjs CHANGED
@@ -7,54 +7,43 @@ var __export = (target, all2) => {
7
7
  __defProp(target, name, { get: all2[name], enumerable: true });
8
8
  };
9
9
 
10
- // src/types/bridge.ts
11
- var AppErrorCodes = /* @__PURE__ */ ((AppErrorCodes2) => {
12
- AppErrorCodes2["ConnectionFailed"] = "connection_failed";
13
- AppErrorCodes2["VerificationRejected"] = "verification_rejected";
14
- AppErrorCodes2["MaxVerificationsReached"] = "max_verifications_reached";
15
- AppErrorCodes2["CredentialUnavailable"] = "credential_unavailable";
16
- AppErrorCodes2["MalformedRequest"] = "malformed_request";
17
- AppErrorCodes2["InvalidNetwork"] = "invalid_network";
18
- AppErrorCodes2["InclusionProofFailed"] = "inclusion_proof_failed";
19
- AppErrorCodes2["InclusionProofPending"] = "inclusion_proof_pending";
20
- AppErrorCodes2["UnexpectedResponse"] = "unexpected_response";
21
- AppErrorCodes2["FailedByHostApp"] = "failed_by_host_app";
22
- AppErrorCodes2["GenericError"] = "generic_error";
23
- return AppErrorCodes2;
24
- })(AppErrorCodes || {});
25
- var VerificationState = /* @__PURE__ */ ((VerificationState2) => {
26
- VerificationState2["PreparingClient"] = "loading_widget";
27
- VerificationState2["WaitingForConnection"] = "awaiting_connection";
28
- VerificationState2["WaitingForApp"] = "awaiting_app";
29
- VerificationState2["Confirmed"] = "confirmed";
30
- VerificationState2["Failed"] = "failed";
31
- return VerificationState2;
32
- })(VerificationState || {});
33
- var ResponseStatus = /* @__PURE__ */ ((ResponseStatus2) => {
34
- ResponseStatus2["Retrieved"] = "retrieved";
35
- ResponseStatus2["Completed"] = "completed";
36
- ResponseStatus2["Initialized"] = "initialized";
37
- return ResponseStatus2;
38
- })(ResponseStatus || {});
10
+ // src/types/result.ts
11
+ var IDKitErrorCodes = /* @__PURE__ */ ((IDKitErrorCodes2) => {
12
+ IDKitErrorCodes2["UserRejected"] = "user_rejected";
13
+ IDKitErrorCodes2["VerificationRejected"] = "verification_rejected";
14
+ IDKitErrorCodes2["CredentialUnavailable"] = "credential_unavailable";
15
+ IDKitErrorCodes2["MalformedRequest"] = "malformed_request";
16
+ IDKitErrorCodes2["InvalidNetwork"] = "invalid_network";
17
+ IDKitErrorCodes2["InclusionProofPending"] = "inclusion_proof_pending";
18
+ IDKitErrorCodes2["InclusionProofFailed"] = "inclusion_proof_failed";
19
+ IDKitErrorCodes2["UnexpectedResponse"] = "unexpected_response";
20
+ IDKitErrorCodes2["ConnectionFailed"] = "connection_failed";
21
+ IDKitErrorCodes2["MaxVerificationsReached"] = "max_verifications_reached";
22
+ IDKitErrorCodes2["FailedByHostApp"] = "failed_by_host_app";
23
+ IDKitErrorCodes2["GenericError"] = "generic_error";
24
+ IDKitErrorCodes2["Timeout"] = "timeout";
25
+ IDKitErrorCodes2["Cancelled"] = "cancelled";
26
+ return IDKitErrorCodes2;
27
+ })(IDKitErrorCodes || {});
39
28
 
40
29
  // wasm/idkit_wasm.js
41
30
  var idkit_wasm_exports = {};
42
31
  __export(idkit_wasm_exports, {
43
32
  BridgeEncryption: () => BridgeEncryption,
44
33
  CredentialRequestWasm: () => CredentialRequestWasm,
34
+ IDKitBuilder: () => IDKitBuilder,
45
35
  IDKitProof: () => IDKitProof,
46
36
  IDKitRequest: () => IDKitRequest,
47
- IDKitRequestBuilderWasm: () => IDKitRequestBuilderWasm,
48
37
  RpContextWasm: () => RpContextWasm,
49
38
  RpSignature: () => RpSignature,
50
39
  base64Decode: () => base64Decode,
51
40
  base64Encode: () => base64Encode,
41
+ createSession: () => createSession,
52
42
  default: () => idkit_wasm_default,
53
43
  hashSignal: () => hashSignal,
54
- hashSignalBytes: () => hashSignalBytes,
55
44
  initSync: () => initSync,
56
45
  init_wasm: () => init_wasm,
57
- orbLegacy: () => orbLegacy,
46
+ proveSession: () => proveSession,
58
47
  request: () => request,
59
48
  signRequest: () => signRequest
60
49
  });
@@ -251,54 +240,28 @@ function makeMutClosure(arg0, arg1, dtor, f) {
251
240
  CLOSURE_DTORS.register(real, state, state);
252
241
  return real;
253
242
  }
254
- function hashSignal(signal) {
255
- let deferred2_0;
256
- let deferred2_1;
257
- try {
258
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
259
- const ptr0 = passStringToWasm0(signal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
260
- const len0 = WASM_VECTOR_LEN;
261
- wasm.hashSignal(retptr, ptr0, len0);
262
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
263
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
264
- deferred2_0 = r0;
265
- deferred2_1 = r1;
266
- return getStringFromWasm0(r0, r1);
267
- } finally {
268
- wasm.__wbindgen_add_to_stack_pointer(16);
269
- wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
270
- }
271
- }
272
- function passArray8ToWasm0(arg, malloc) {
273
- const ptr = malloc(arg.length * 1, 1) >>> 0;
274
- getUint8ArrayMemory0().set(arg, ptr / 1);
275
- WASM_VECTOR_LEN = arg.length;
276
- return ptr;
277
- }
278
- function hashSignalBytes(bytes) {
279
- let deferred2_0;
280
- let deferred2_1;
281
- try {
282
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
283
- const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_export);
284
- const len0 = WASM_VECTOR_LEN;
285
- wasm.hashSignal(retptr, ptr0, len0);
286
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
287
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
288
- deferred2_0 = r0;
289
- deferred2_1 = r1;
290
- return getStringFromWasm0(r0, r1);
291
- } finally {
292
- wasm.__wbindgen_add_to_stack_pointer(16);
293
- wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
294
- }
295
- }
296
243
  function _assertClass(instance, klass) {
297
244
  if (!(instance instanceof klass)) {
298
245
  throw new Error(`expected instance of ${klass.name}`);
299
246
  }
300
247
  }
301
- function request(app_id, action, rp_context, action_description, bridge_url) {
248
+ function createSession(app_id, rp_context, action_description, bridge_url, override_connect_base_url, environment) {
249
+ const ptr0 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
250
+ const len0 = WASM_VECTOR_LEN;
251
+ _assertClass(rp_context, RpContextWasm);
252
+ var ptr1 = rp_context.__destroy_into_raw();
253
+ var ptr2 = isLikeNone(action_description) ? 0 : passStringToWasm0(action_description, wasm.__wbindgen_export, wasm.__wbindgen_export2);
254
+ var len2 = WASM_VECTOR_LEN;
255
+ var ptr3 = isLikeNone(bridge_url) ? 0 : passStringToWasm0(bridge_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
256
+ var len3 = WASM_VECTOR_LEN;
257
+ var ptr4 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
258
+ var len4 = WASM_VECTOR_LEN;
259
+ var ptr5 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
260
+ var len5 = WASM_VECTOR_LEN;
261
+ const ret = wasm.createSession(ptr0, len0, ptr1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
262
+ return IDKitBuilder.__wrap(ret);
263
+ }
264
+ function request(app_id, action, rp_context, action_description, bridge_url, allow_legacy_proofs, override_connect_base_url, environment) {
302
265
  const ptr0 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
303
266
  const len0 = WASM_VECTOR_LEN;
304
267
  const ptr1 = passStringToWasm0(action, wasm.__wbindgen_export, wasm.__wbindgen_export2);
@@ -309,28 +272,56 @@ function request(app_id, action, rp_context, action_description, bridge_url) {
309
272
  var len3 = WASM_VECTOR_LEN;
310
273
  var ptr4 = isLikeNone(bridge_url) ? 0 : passStringToWasm0(bridge_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
311
274
  var len4 = WASM_VECTOR_LEN;
312
- const ret = wasm.idkitrequestbuilderwasm_new(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4);
313
- return IDKitRequestBuilderWasm.__wrap(ret);
275
+ var ptr5 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
276
+ var len5 = WASM_VECTOR_LEN;
277
+ var ptr6 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
278
+ var len6 = WASM_VECTOR_LEN;
279
+ const ret = wasm.idkitbuilder_new(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, allow_legacy_proofs, ptr5, len5, ptr6, len6);
280
+ return IDKitBuilder.__wrap(ret);
314
281
  }
315
- function orbLegacy(signal) {
282
+ function base64Decode(data) {
316
283
  try {
317
284
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
318
- var ptr0 = isLikeNone(signal) ? 0 : passStringToWasm0(signal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
319
- var len0 = WASM_VECTOR_LEN;
320
- wasm.orbLegacy(retptr, ptr0, len0);
285
+ const ptr0 = passStringToWasm0(data, wasm.__wbindgen_export, wasm.__wbindgen_export2);
286
+ const len0 = WASM_VECTOR_LEN;
287
+ wasm.base64Decode(retptr, ptr0, len0);
321
288
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
322
289
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
323
290
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
324
- if (r2) {
325
- throw takeObject(r1);
291
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
292
+ if (r3) {
293
+ throw takeObject(r2);
326
294
  }
327
- return takeObject(r0);
295
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
296
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
297
+ return v2;
328
298
  } finally {
329
299
  wasm.__wbindgen_add_to_stack_pointer(16);
330
300
  }
331
301
  }
332
- function init_wasm() {
333
- wasm.init_wasm();
302
+ function proveSession(session_id, app_id, rp_context, action_description, bridge_url, override_connect_base_url, environment) {
303
+ const ptr0 = passStringToWasm0(session_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
304
+ const len0 = WASM_VECTOR_LEN;
305
+ const ptr1 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
306
+ const len1 = WASM_VECTOR_LEN;
307
+ _assertClass(rp_context, RpContextWasm);
308
+ var ptr2 = rp_context.__destroy_into_raw();
309
+ var ptr3 = isLikeNone(action_description) ? 0 : passStringToWasm0(action_description, wasm.__wbindgen_export, wasm.__wbindgen_export2);
310
+ var len3 = WASM_VECTOR_LEN;
311
+ var ptr4 = isLikeNone(bridge_url) ? 0 : passStringToWasm0(bridge_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
312
+ var len4 = WASM_VECTOR_LEN;
313
+ var ptr5 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
314
+ var len5 = WASM_VECTOR_LEN;
315
+ var ptr6 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
316
+ var len6 = WASM_VECTOR_LEN;
317
+ const ret = wasm.idkitbuilder_forProveSession(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6);
318
+ return IDKitBuilder.__wrap(ret);
319
+ }
320
+ function passArray8ToWasm0(arg, malloc) {
321
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
322
+ getUint8ArrayMemory0().set(arg, ptr / 1);
323
+ WASM_VECTOR_LEN = arg.length;
324
+ return ptr;
334
325
  }
335
326
  function base64Encode(data) {
336
327
  let deferred2_0;
@@ -350,53 +341,61 @@ function base64Encode(data) {
350
341
  wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
351
342
  }
352
343
  }
353
- function base64Decode(data) {
344
+ function init_wasm() {
345
+ wasm.init_wasm();
346
+ }
347
+ function signRequest(action, signing_key_hex, ttl_seconds) {
354
348
  try {
355
349
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
356
- const ptr0 = passStringToWasm0(data, wasm.__wbindgen_export, wasm.__wbindgen_export2);
350
+ const ptr0 = passStringToWasm0(action, wasm.__wbindgen_export, wasm.__wbindgen_export2);
357
351
  const len0 = WASM_VECTOR_LEN;
358
- wasm.base64Decode(retptr, ptr0, len0);
352
+ const ptr1 = passStringToWasm0(signing_key_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
353
+ const len1 = WASM_VECTOR_LEN;
354
+ wasm.signRequest(retptr, ptr0, len0, ptr1, len1, !isLikeNone(ttl_seconds), isLikeNone(ttl_seconds) ? BigInt(0) : ttl_seconds);
359
355
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
360
356
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
361
357
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
362
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
363
- if (r3) {
364
- throw takeObject(r2);
358
+ if (r2) {
359
+ throw takeObject(r1);
365
360
  }
366
- var v2 = getArrayU8FromWasm0(r0, r1).slice();
367
- wasm.__wbindgen_export4(r0, r1 * 1, 1);
368
- return v2;
361
+ return RpSignature.__wrap(r0);
369
362
  } finally {
370
363
  wasm.__wbindgen_add_to_stack_pointer(16);
371
364
  }
372
365
  }
373
- function signRequest(action, signing_key_hex, ttl_seconds) {
366
+ function hashSignal(signal) {
367
+ let deferred2_0;
368
+ let deferred2_1;
374
369
  try {
375
370
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
376
- const ptr0 = passStringToWasm0(action, wasm.__wbindgen_export, wasm.__wbindgen_export2);
377
- const len0 = WASM_VECTOR_LEN;
378
- const ptr1 = passStringToWasm0(signing_key_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
379
- const len1 = WASM_VECTOR_LEN;
380
- wasm.signRequest(retptr, ptr0, len0, ptr1, len1, !isLikeNone(ttl_seconds), isLikeNone(ttl_seconds) ? BigInt(0) : ttl_seconds);
371
+ wasm.hashSignal(retptr, addHeapObject(signal));
381
372
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
382
373
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
383
374
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
384
- if (r2) {
385
- throw takeObject(r1);
375
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
376
+ var ptr1 = r0;
377
+ var len1 = r1;
378
+ if (r3) {
379
+ ptr1 = 0;
380
+ len1 = 0;
381
+ throw takeObject(r2);
386
382
  }
387
- return RpSignature.__wrap(r0);
383
+ deferred2_0 = ptr1;
384
+ deferred2_1 = len1;
385
+ return getStringFromWasm0(ptr1, len1);
388
386
  } finally {
389
387
  wasm.__wbindgen_add_to_stack_pointer(16);
388
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
390
389
  }
391
390
  }
392
- function __wasm_bindgen_func_elem_551(arg0, arg1) {
393
- wasm.__wasm_bindgen_func_elem_551(arg0, arg1);
391
+ function __wasm_bindgen_func_elem_960(arg0, arg1, arg2) {
392
+ wasm.__wasm_bindgen_func_elem_960(arg0, arg1, addHeapObject(arg2));
394
393
  }
395
- function __wasm_bindgen_func_elem_914(arg0, arg1, arg2) {
396
- wasm.__wasm_bindgen_func_elem_914(arg0, arg1, addHeapObject(arg2));
394
+ function __wasm_bindgen_func_elem_597(arg0, arg1) {
395
+ wasm.__wasm_bindgen_func_elem_597(arg0, arg1);
397
396
  }
398
- function __wasm_bindgen_func_elem_1281(arg0, arg1, arg2, arg3) {
399
- wasm.__wasm_bindgen_func_elem_1281(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
397
+ function __wasm_bindgen_func_elem_1345(arg0, arg1, arg2, arg3) {
398
+ wasm.__wasm_bindgen_func_elem_1345(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
400
399
  }
401
400
  var __wbindgen_enum_RequestCache = ["default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached"];
402
401
  var __wbindgen_enum_RequestCredentials = ["omit", "same-origin", "include"];
@@ -575,7 +574,7 @@ var CredentialRequestWasm = class _CredentialRequestWasm {
575
574
  wasm.__wbg_credentialrequestwasm_free(ptr, 0);
576
575
  }
577
576
  /**
578
- * Creates a new request item with ABI-encoded bytes for the signal
577
+ * Creates a new request item with raw bytes for the signal
579
578
  *
580
579
  * # Errors
581
580
  *
@@ -657,6 +656,34 @@ var CredentialRequestWasm = class _CredentialRequestWasm {
657
656
  wasm.__wbindgen_add_to_stack_pointer(16);
658
657
  }
659
658
  }
659
+ /**
660
+ * Creates a new request item with expiration minimum timestamp
661
+ *
662
+ * # Errors
663
+ *
664
+ * Returns an error if the credential type is invalid
665
+ * @param {any} credential_type
666
+ * @param {string | null | undefined} signal
667
+ * @param {bigint} expires_at_min
668
+ * @returns {CredentialRequestWasm}
669
+ */
670
+ static withExpiresAtMin(credential_type, signal, expires_at_min) {
671
+ try {
672
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
673
+ var ptr0 = isLikeNone(signal) ? 0 : passStringToWasm0(signal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
674
+ var len0 = WASM_VECTOR_LEN;
675
+ wasm.credentialrequestwasm_withExpiresAtMin(retptr, addHeapObject(credential_type), ptr0, len0, expires_at_min);
676
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
677
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
678
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
679
+ if (r2) {
680
+ throw takeObject(r1);
681
+ }
682
+ return _CredentialRequestWasm.__wrap(r0);
683
+ } finally {
684
+ wasm.__wbindgen_add_to_stack_pointer(16);
685
+ }
686
+ }
660
687
  /**
661
688
  * Creates a new request item
662
689
  *
@@ -714,6 +741,191 @@ var CredentialRequestWasm = class _CredentialRequestWasm {
714
741
  }
715
742
  };
716
743
  if (Symbol.dispose) CredentialRequestWasm.prototype[Symbol.dispose] = CredentialRequestWasm.prototype.free;
744
+ var IDKitBuilderFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
745
+ }, unregister: () => {
746
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_idkitbuilder_free(ptr >>> 0, 1));
747
+ var IDKitBuilder = class _IDKitBuilder {
748
+ static __wrap(ptr) {
749
+ ptr = ptr >>> 0;
750
+ const obj = Object.create(_IDKitBuilder.prototype);
751
+ obj.__wbg_ptr = ptr;
752
+ IDKitBuilderFinalization.register(obj, obj.__wbg_ptr, obj);
753
+ return obj;
754
+ }
755
+ __destroy_into_raw() {
756
+ const ptr = this.__wbg_ptr;
757
+ this.__wbg_ptr = 0;
758
+ IDKitBuilderFinalization.unregister(this);
759
+ return ptr;
760
+ }
761
+ free() {
762
+ const ptr = this.__destroy_into_raw();
763
+ wasm.__wbg_idkitbuilder_free(ptr, 0);
764
+ }
765
+ /**
766
+ * Creates a `BridgeConnection` with the given constraints
767
+ * @param {any} constraints_json
768
+ * @returns {Promise<any>}
769
+ */
770
+ constraints(constraints_json) {
771
+ const ptr = this.__destroy_into_raw();
772
+ const ret = wasm.idkitbuilder_constraints(ptr, addHeapObject(constraints_json));
773
+ return takeObject(ret);
774
+ }
775
+ /**
776
+ * Builds the native payload for constraints (synchronous, no bridge connection).
777
+ *
778
+ * Used by the native transport to get the same payload format as the bridge
779
+ * without creating a network connection.
780
+ *
781
+ * # Errors
782
+ *
783
+ * Returns an error if constraints are invalid or payload construction fails.
784
+ * @param {any} constraints_json
785
+ * @returns {any}
786
+ */
787
+ nativePayload(constraints_json) {
788
+ try {
789
+ const ptr = this.__destroy_into_raw();
790
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
791
+ wasm.idkitbuilder_nativePayload(retptr, ptr, addHeapObject(constraints_json));
792
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
793
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
794
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
795
+ if (r2) {
796
+ throw takeObject(r1);
797
+ }
798
+ return takeObject(r0);
799
+ } finally {
800
+ wasm.__wbindgen_add_to_stack_pointer(16);
801
+ }
802
+ }
803
+ /**
804
+ * Creates a new builder for proving an existing session
805
+ * @param {string} session_id
806
+ * @param {string} app_id
807
+ * @param {RpContextWasm} rp_context
808
+ * @param {string | null} [action_description]
809
+ * @param {string | null} [bridge_url]
810
+ * @param {string | null} [override_connect_base_url]
811
+ * @param {string | null} [environment]
812
+ * @returns {IDKitBuilder}
813
+ */
814
+ static forProveSession(session_id, app_id, rp_context, action_description, bridge_url, override_connect_base_url, environment) {
815
+ const ptr0 = passStringToWasm0(session_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
816
+ const len0 = WASM_VECTOR_LEN;
817
+ const ptr1 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
818
+ const len1 = WASM_VECTOR_LEN;
819
+ _assertClass(rp_context, RpContextWasm);
820
+ var ptr2 = rp_context.__destroy_into_raw();
821
+ var ptr3 = isLikeNone(action_description) ? 0 : passStringToWasm0(action_description, wasm.__wbindgen_export, wasm.__wbindgen_export2);
822
+ var len3 = WASM_VECTOR_LEN;
823
+ var ptr4 = isLikeNone(bridge_url) ? 0 : passStringToWasm0(bridge_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
824
+ var len4 = WASM_VECTOR_LEN;
825
+ var ptr5 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
826
+ var len5 = WASM_VECTOR_LEN;
827
+ var ptr6 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
828
+ var len6 = WASM_VECTOR_LEN;
829
+ const ret = wasm.idkitbuilder_forProveSession(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6);
830
+ return _IDKitBuilder.__wrap(ret);
831
+ }
832
+ /**
833
+ * Creates a new builder for creating a new session
834
+ * @param {string} app_id
835
+ * @param {RpContextWasm} rp_context
836
+ * @param {string | null} [action_description]
837
+ * @param {string | null} [bridge_url]
838
+ * @param {string | null} [override_connect_base_url]
839
+ * @param {string | null} [environment]
840
+ * @returns {IDKitBuilder}
841
+ */
842
+ static forCreateSession(app_id, rp_context, action_description, bridge_url, override_connect_base_url, environment) {
843
+ const ptr0 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
844
+ const len0 = WASM_VECTOR_LEN;
845
+ _assertClass(rp_context, RpContextWasm);
846
+ var ptr1 = rp_context.__destroy_into_raw();
847
+ var ptr2 = isLikeNone(action_description) ? 0 : passStringToWasm0(action_description, wasm.__wbindgen_export, wasm.__wbindgen_export2);
848
+ var len2 = WASM_VECTOR_LEN;
849
+ var ptr3 = isLikeNone(bridge_url) ? 0 : passStringToWasm0(bridge_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
850
+ var len3 = WASM_VECTOR_LEN;
851
+ var ptr4 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
852
+ var len4 = WASM_VECTOR_LEN;
853
+ var ptr5 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
854
+ var len5 = WASM_VECTOR_LEN;
855
+ const ret = wasm.createSession(ptr0, len0, ptr1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
856
+ return _IDKitBuilder.__wrap(ret);
857
+ }
858
+ /**
859
+ * Builds the native payload from a preset (synchronous, no bridge connection).
860
+ *
861
+ * Used by the native transport to get the same payload format as the bridge
862
+ * without creating a network connection.
863
+ *
864
+ * # Errors
865
+ *
866
+ * Returns an error if the preset is invalid or payload construction fails.
867
+ * @param {any} preset_json
868
+ * @returns {any}
869
+ */
870
+ nativePayloadFromPreset(preset_json) {
871
+ try {
872
+ const ptr = this.__destroy_into_raw();
873
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
874
+ wasm.idkitbuilder_nativePayloadFromPreset(retptr, ptr, addHeapObject(preset_json));
875
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
876
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
877
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
878
+ if (r2) {
879
+ throw takeObject(r1);
880
+ }
881
+ return takeObject(r0);
882
+ } finally {
883
+ wasm.__wbindgen_add_to_stack_pointer(16);
884
+ }
885
+ }
886
+ /**
887
+ * Creates a new builder for uniqueness requests
888
+ * @param {string} app_id
889
+ * @param {string} action
890
+ * @param {RpContextWasm} rp_context
891
+ * @param {string | null | undefined} action_description
892
+ * @param {string | null | undefined} bridge_url
893
+ * @param {boolean} allow_legacy_proofs
894
+ * @param {string | null} [override_connect_base_url]
895
+ * @param {string | null} [environment]
896
+ */
897
+ constructor(app_id, action, rp_context, action_description, bridge_url, allow_legacy_proofs, override_connect_base_url, environment) {
898
+ const ptr0 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
899
+ const len0 = WASM_VECTOR_LEN;
900
+ const ptr1 = passStringToWasm0(action, wasm.__wbindgen_export, wasm.__wbindgen_export2);
901
+ const len1 = WASM_VECTOR_LEN;
902
+ _assertClass(rp_context, RpContextWasm);
903
+ var ptr2 = rp_context.__destroy_into_raw();
904
+ var ptr3 = isLikeNone(action_description) ? 0 : passStringToWasm0(action_description, wasm.__wbindgen_export, wasm.__wbindgen_export2);
905
+ var len3 = WASM_VECTOR_LEN;
906
+ var ptr4 = isLikeNone(bridge_url) ? 0 : passStringToWasm0(bridge_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
907
+ var len4 = WASM_VECTOR_LEN;
908
+ var ptr5 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
909
+ var len5 = WASM_VECTOR_LEN;
910
+ var ptr6 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
911
+ var len6 = WASM_VECTOR_LEN;
912
+ const ret = wasm.idkitbuilder_new(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, allow_legacy_proofs, ptr5, len5, ptr6, len6);
913
+ this.__wbg_ptr = ret >>> 0;
914
+ IDKitBuilderFinalization.register(this, this.__wbg_ptr, this);
915
+ return this;
916
+ }
917
+ /**
918
+ * Creates a `BridgeConnection` from a preset (works for all request types)
919
+ * @param {any} preset_json
920
+ * @returns {Promise<any>}
921
+ */
922
+ preset(preset_json) {
923
+ const ptr = this.__destroy_into_raw();
924
+ const ret = wasm.idkitbuilder_preset(ptr, addHeapObject(preset_json));
925
+ return takeObject(ret);
926
+ }
927
+ };
928
+ if (Symbol.dispose) IDKitBuilder.prototype[Symbol.dispose] = IDKitBuilder.prototype.free;
717
929
  var IDKitProofFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
718
930
  }, unregister: () => {
719
931
  } } : new FinalizationRegistry((ptr) => wasm.__wbg_idkitproof_free(ptr >>> 0, 1));
@@ -896,98 +1108,6 @@ var IDKitRequest = class _IDKitRequest {
896
1108
  }
897
1109
  };
898
1110
  if (Symbol.dispose) IDKitRequest.prototype[Symbol.dispose] = IDKitRequest.prototype.free;
899
- var IDKitRequestBuilderWasmFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
900
- }, unregister: () => {
901
- } } : new FinalizationRegistry((ptr) => wasm.__wbg_idkitrequestbuilderwasm_free(ptr >>> 0, 1));
902
- var IDKitRequestBuilderWasm = class _IDKitRequestBuilderWasm {
903
- static __wrap(ptr) {
904
- ptr = ptr >>> 0;
905
- const obj = Object.create(_IDKitRequestBuilderWasm.prototype);
906
- obj.__wbg_ptr = ptr;
907
- IDKitRequestBuilderWasmFinalization.register(obj, obj.__wbg_ptr, obj);
908
- return obj;
909
- }
910
- __destroy_into_raw() {
911
- const ptr = this.__wbg_ptr;
912
- this.__wbg_ptr = 0;
913
- IDKitRequestBuilderWasmFinalization.unregister(this);
914
- return ptr;
915
- }
916
- free() {
917
- const ptr = this.__destroy_into_raw();
918
- wasm.__wbg_idkitrequestbuilderwasm_free(ptr, 0);
919
- }
920
- /**
921
- * Creates an `IDKit` request with the given constraints
922
- *
923
- * # Arguments
924
- * * `constraints_json` - Constraint tree as JSON (`CredentialRequest` or `{any: []}` or `{all: []}`)
925
- *
926
- * # Errors
927
- *
928
- * Returns an error if the request cannot be created
929
- * @param {any} constraints_json
930
- * @returns {Promise<any>}
931
- */
932
- constraints(constraints_json) {
933
- const ptr = this.__destroy_into_raw();
934
- const ret = wasm.idkitrequestbuilderwasm_constraints(ptr, addHeapObject(constraints_json));
935
- return takeObject(ret);
936
- }
937
- /**
938
- * Creates a new `IDKitRequestBuilder`
939
- *
940
- * # Arguments
941
- * * `app_id` - Application ID from the Developer Portal
942
- * * `action` - Action identifier
943
- * * `rp_context` - RP context for building protocol-level `ProofRequest`
944
- * * `action_description` - Optional action description shown to users
945
- * * `bridge_url` - Optional bridge URL (defaults to production)
946
- * @param {string} app_id
947
- * @param {string} action
948
- * @param {RpContextWasm} rp_context
949
- * @param {string | null} [action_description]
950
- * @param {string | null} [bridge_url]
951
- */
952
- constructor(app_id, action, rp_context, action_description, bridge_url) {
953
- const ptr0 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
954
- const len0 = WASM_VECTOR_LEN;
955
- const ptr1 = passStringToWasm0(action, wasm.__wbindgen_export, wasm.__wbindgen_export2);
956
- const len1 = WASM_VECTOR_LEN;
957
- _assertClass(rp_context, RpContextWasm);
958
- var ptr2 = rp_context.__destroy_into_raw();
959
- var ptr3 = isLikeNone(action_description) ? 0 : passStringToWasm0(action_description, wasm.__wbindgen_export, wasm.__wbindgen_export2);
960
- var len3 = WASM_VECTOR_LEN;
961
- var ptr4 = isLikeNone(bridge_url) ? 0 : passStringToWasm0(bridge_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
962
- var len4 = WASM_VECTOR_LEN;
963
- const ret = wasm.idkitrequestbuilderwasm_new(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4);
964
- this.__wbg_ptr = ret >>> 0;
965
- IDKitRequestBuilderWasmFinalization.register(this, this.__wbg_ptr, this);
966
- return this;
967
- }
968
- /**
969
- * Creates an `IDKit` request from a preset
970
- *
971
- * Presets provide a simplified way to create requests with predefined
972
- * credential configurations. The preset is converted to both World ID 4.0
973
- * constraints and World ID 3.0 legacy fields for backward compatibility.
974
- *
975
- * # Arguments
976
- * * `preset_json` - Preset object from `orbLegacy()`
977
- *
978
- * # Errors
979
- *
980
- * Returns an error if the request cannot be created
981
- * @param {any} preset_json
982
- * @returns {Promise<any>}
983
- */
984
- preset(preset_json) {
985
- const ptr = this.__destroy_into_raw();
986
- const ret = wasm.idkitrequestbuilderwasm_preset(ptr, addHeapObject(preset_json));
987
- return takeObject(ret);
988
- }
989
- };
990
- if (Symbol.dispose) IDKitRequestBuilderWasm.prototype[Symbol.dispose] = IDKitRequestBuilderWasm.prototype.free;
991
1111
  var RpContextWasmFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
992
1112
  }, unregister: () => {
993
1113
  } } : new FinalizationRegistry((ptr) => wasm.__wbg_rpcontextwasm_free(ptr >>> 0, 1));
@@ -1343,10 +1463,6 @@ function __wbg_get_imports() {
1343
1463
  return addHeapObject(ret);
1344
1464
  }, arguments);
1345
1465
  };
1346
- imports.wbg.__wbg_get_with_ref_key_1dc361bd10053bfe = function(arg0, arg1) {
1347
- const ret = getObject(arg0)[getObject(arg1)];
1348
- return addHeapObject(ret);
1349
- };
1350
1466
  imports.wbg.__wbg_has_787fafc980c3ccdb = function() {
1351
1467
  return handleError(function(arg0, arg1) {
1352
1468
  const ret = Reflect.has(getObject(arg0), getObject(arg1));
@@ -1442,7 +1558,7 @@ function __wbg_get_imports() {
1442
1558
  const a = state0.a;
1443
1559
  state0.a = 0;
1444
1560
  try {
1445
- return __wasm_bindgen_func_elem_1281(a, state0.b, arg02, arg12);
1561
+ return __wasm_bindgen_func_elem_1345(a, state0.b, arg02, arg12);
1446
1562
  } finally {
1447
1563
  state0.a = a;
1448
1564
  }
@@ -1660,7 +1776,7 @@ function __wbg_get_imports() {
1660
1776
  return addHeapObject(ret);
1661
1777
  };
1662
1778
  imports.wbg.__wbindgen_cast_91c43ecf1f8dafb8 = function(arg0, arg1) {
1663
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_550, __wasm_bindgen_func_elem_551);
1779
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_596, __wasm_bindgen_func_elem_597);
1664
1780
  return addHeapObject(ret);
1665
1781
  };
1666
1782
  imports.wbg.__wbindgen_cast_9ae0607507abb057 = function(arg0) {
@@ -1668,7 +1784,7 @@ function __wbg_get_imports() {
1668
1784
  return addHeapObject(ret);
1669
1785
  };
1670
1786
  imports.wbg.__wbindgen_cast_ab10518eebecf9a3 = function(arg0, arg1) {
1671
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_913, __wasm_bindgen_func_elem_914);
1787
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_959, __wasm_bindgen_func_elem_960);
1672
1788
  return addHeapObject(ret);
1673
1789
  };
1674
1790
  imports.wbg.__wbindgen_cast_cb9088102bce6b30 = function(arg0, arg1) {
@@ -1736,6 +1852,10 @@ var idkit_wasm_default = __wbg_init;
1736
1852
  // src/lib/wasm.ts
1737
1853
  var wasmInitialized = false;
1738
1854
  var wasmInitPromise = null;
1855
+ async function importNodeModule(specifier) {
1856
+ const dynamicImport = Function("moduleName", "return import(moduleName)");
1857
+ return dynamicImport(specifier);
1858
+ }
1739
1859
  async function initIDKit() {
1740
1860
  if (wasmInitialized) {
1741
1861
  return;
@@ -1763,10 +1883,18 @@ async function initIDKitServer() {
1763
1883
  }
1764
1884
  wasmInitPromise = (async () => {
1765
1885
  try {
1766
- const { readFile } = await import('fs/promises');
1767
- const { fileURLToPath } = await import('url');
1768
- const wasmUrl = new URL("idkit_wasm_bg.wasm", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
1769
- const wasmBuffer = await readFile(fileURLToPath(wasmUrl));
1886
+ const { readFile } = await importNodeModule(
1887
+ "node:fs/promises"
1888
+ );
1889
+ const { fileURLToPath } = await importNodeModule(
1890
+ "node:url"
1891
+ );
1892
+ const { dirname, join } = await importNodeModule(
1893
+ "node:path"
1894
+ );
1895
+ const modulePath = fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
1896
+ const wasmPath = join(dirname(modulePath), "idkit_wasm_bg.wasm");
1897
+ const wasmBuffer = await readFile(wasmPath);
1770
1898
  await idkit_wasm_default({ module_or_path: wasmBuffer });
1771
1899
  wasmInitialized = true;
1772
1900
  } catch (error) {
@@ -1777,6 +1905,179 @@ async function initIDKitServer() {
1777
1905
  return wasmInitPromise;
1778
1906
  }
1779
1907
 
1908
+ // src/transports/native.ts
1909
+ function isInWorldApp() {
1910
+ return typeof window !== "undefined" && Boolean(window.WorldApp);
1911
+ }
1912
+ var _requestCounter = 0;
1913
+ var _activeNativeRequest = null;
1914
+ function createNativeRequest(wasmPayload, config) {
1915
+ if (_activeNativeRequest) {
1916
+ _activeNativeRequest.cancel();
1917
+ }
1918
+ const request2 = new NativeIDKitRequest(wasmPayload, config);
1919
+ _activeNativeRequest = request2;
1920
+ return request2;
1921
+ }
1922
+ var NativeIDKitRequest = class {
1923
+ constructor(wasmPayload, config) {
1924
+ this.connectorURI = "";
1925
+ this.resolved = false;
1926
+ this.cancelled = false;
1927
+ this.resolvedResult = null;
1928
+ this.messageHandler = null;
1929
+ this.rejectFn = null;
1930
+ this.requestId = crypto.randomUUID?.() ?? `native-${Date.now()}-${++_requestCounter}`;
1931
+ this.resultPromise = new Promise((resolve, reject) => {
1932
+ this.rejectFn = reject;
1933
+ const handler = (event) => {
1934
+ if (this.cancelled) return;
1935
+ const data = event.data;
1936
+ if (data?.type === "miniapp-verify-action" || data?.command === "miniapp-verify-action") {
1937
+ this.cleanup();
1938
+ const responsePayload = data.payload ?? data;
1939
+ if (responsePayload.status === "error") {
1940
+ reject(
1941
+ new NativeVerifyError(
1942
+ responsePayload.error_code ?? "generic_error" /* GenericError */
1943
+ )
1944
+ );
1945
+ } else {
1946
+ this.resolved = true;
1947
+ const result = nativeResultToIDKitResult(responsePayload, config);
1948
+ this.resolvedResult = result;
1949
+ resolve(result);
1950
+ }
1951
+ }
1952
+ };
1953
+ this.messageHandler = handler;
1954
+ window.addEventListener("message", handler);
1955
+ const sendPayload = {
1956
+ command: "verify",
1957
+ version: 2,
1958
+ payload: wasmPayload
1959
+ };
1960
+ const w = window;
1961
+ if (w.webkit?.messageHandlers?.minikit) {
1962
+ w.webkit.messageHandlers.minikit.postMessage(sendPayload);
1963
+ } else if (w.Android) {
1964
+ w.Android.postMessage(JSON.stringify(sendPayload));
1965
+ } else {
1966
+ this.cleanup();
1967
+ reject(new Error("No WebView bridge available"));
1968
+ }
1969
+ });
1970
+ this.resultPromise.catch(() => {
1971
+ }).finally(() => {
1972
+ this.cleanup();
1973
+ if (_activeNativeRequest === this) {
1974
+ _activeNativeRequest = null;
1975
+ }
1976
+ });
1977
+ }
1978
+ /**
1979
+ * Cancel this request. Removes the message listener so it cannot consume
1980
+ * a response meant for a later request, and rejects the pending promise.
1981
+ */
1982
+ cancel() {
1983
+ if (this.resolved || this.cancelled) return;
1984
+ this.cancelled = true;
1985
+ this.cleanup();
1986
+ this.rejectFn?.(new NativeVerifyError("cancelled" /* Cancelled */));
1987
+ if (_activeNativeRequest === this) {
1988
+ _activeNativeRequest = null;
1989
+ }
1990
+ }
1991
+ cleanup() {
1992
+ if (this.messageHandler) {
1993
+ window.removeEventListener("message", this.messageHandler);
1994
+ this.messageHandler = null;
1995
+ }
1996
+ }
1997
+ async pollOnce() {
1998
+ if (this.resolved && this.resolvedResult) {
1999
+ return { type: "confirmed", result: this.resolvedResult };
2000
+ }
2001
+ return { type: "awaiting_confirmation" };
2002
+ }
2003
+ async pollUntilCompletion(options) {
2004
+ const timeout = options?.timeout ?? 3e5;
2005
+ try {
2006
+ const result = await Promise.race([
2007
+ this.resultPromise,
2008
+ new Promise((_, reject) => {
2009
+ if (options?.signal) {
2010
+ options.signal.addEventListener(
2011
+ "abort",
2012
+ () => reject(new NativeVerifyError("cancelled" /* Cancelled */))
2013
+ );
2014
+ }
2015
+ setTimeout(
2016
+ () => reject(new NativeVerifyError("timeout" /* Timeout */)),
2017
+ timeout
2018
+ );
2019
+ })
2020
+ ]);
2021
+ return { success: true, result };
2022
+ } catch (error) {
2023
+ if (error instanceof NativeVerifyError) {
2024
+ return { success: false, error: error.code };
2025
+ }
2026
+ return { success: false, error: "generic_error" /* GenericError */ };
2027
+ }
2028
+ }
2029
+ };
2030
+ var NativeVerifyError = class extends Error {
2031
+ constructor(code) {
2032
+ super(code);
2033
+ this.code = code;
2034
+ }
2035
+ };
2036
+ function nativeResultToIDKitResult(payload, config) {
2037
+ const rpNonce = config.rp_context?.nonce ?? "";
2038
+ if ("responses" in payload && Array.isArray(payload.responses)) {
2039
+ return {
2040
+ protocol_version: payload.protocol_version ?? "4.0",
2041
+ nonce: payload.nonce ?? rpNonce,
2042
+ action: payload.action ?? config.action ?? "",
2043
+ action_description: payload.action_description,
2044
+ session_id: payload.session_id,
2045
+ responses: payload.responses,
2046
+ environment: payload.environment ?? config.environment ?? "production"
2047
+ };
2048
+ }
2049
+ if ("verifications" in payload) {
2050
+ return {
2051
+ protocol_version: "4.0",
2052
+ nonce: rpNonce,
2053
+ action: config.action ?? "",
2054
+ responses: payload.verifications.map((v) => ({
2055
+ identifier: v.verification_level,
2056
+ proof: [v.proof],
2057
+ nullifier: v.nullifier_hash,
2058
+ merkle_root: v.merkle_root,
2059
+ issuer_schema_id: 0,
2060
+ expires_at_min: 0
2061
+ })),
2062
+ environment: "production"
2063
+ };
2064
+ }
2065
+ return {
2066
+ protocol_version: "3.0",
2067
+ nonce: rpNonce,
2068
+ action: config.action ?? "",
2069
+ responses: [
2070
+ {
2071
+ identifier: payload.verification_level,
2072
+ proof: payload.proof,
2073
+ merkle_root: payload.merkle_root,
2074
+ nullifier: payload.nullifier_hash
2075
+ }
2076
+ ],
2077
+ environment: "production"
2078
+ };
2079
+ }
2080
+
1780
2081
  // src/request.ts
1781
2082
  var IDKitRequestImpl = class {
1782
2083
  constructor(wasmRequest) {
@@ -1793,24 +2094,26 @@ var IDKitRequestImpl = class {
1793
2094
  async pollOnce() {
1794
2095
  return await this.wasmRequest.pollForStatus();
1795
2096
  }
1796
- async pollForUpdates(options) {
2097
+ async pollUntilCompletion(options) {
1797
2098
  const pollInterval = options?.pollInterval ?? 1e3;
1798
2099
  const timeout = options?.timeout ?? 3e5;
1799
2100
  const startTime = Date.now();
1800
2101
  while (true) {
1801
2102
  if (options?.signal?.aborted) {
1802
- throw new Error("Verification cancelled");
2103
+ return { success: false, error: "cancelled" /* Cancelled */ };
1803
2104
  }
1804
2105
  if (Date.now() - startTime > timeout) {
1805
- throw new Error(`Timeout waiting for proof after ${timeout}ms`);
2106
+ return { success: false, error: "timeout" /* Timeout */ };
1806
2107
  }
1807
2108
  const status = await this.pollOnce();
1808
2109
  if (status.type === "confirmed" && status.result) {
1809
- return status.result;
2110
+ return { success: true, result: status.result };
1810
2111
  }
1811
2112
  if (status.type === "failed") {
1812
- const errorCode = status.error ?? "generic_error" /* GenericError */;
1813
- throw new Error(`Verification failed: ${errorCode}`);
2113
+ return {
2114
+ success: false,
2115
+ error: status.error ?? "generic_error" /* GenericError */
2116
+ };
1814
2117
  }
1815
2118
  await new Promise((resolve) => setTimeout(resolve, pollInterval));
1816
2119
  }
@@ -1820,7 +2123,8 @@ function CredentialRequest(credential_type, options) {
1820
2123
  return {
1821
2124
  type: credential_type,
1822
2125
  signal: options?.signal,
1823
- genesis_issued_at_min: options?.genesis_issued_at_min
2126
+ genesis_issued_at_min: options?.genesis_issued_at_min,
2127
+ expires_at_min: options?.expires_at_min
1824
2128
  };
1825
2129
  }
1826
2130
  function any(...nodes) {
@@ -1829,10 +2133,59 @@ function any(...nodes) {
1829
2133
  function all(...nodes) {
1830
2134
  return { all: nodes };
1831
2135
  }
1832
- function orbLegacy2(opts = {}) {
1833
- return { type: "OrbLegacy", data: { signal: opts.signal } };
2136
+ function orbLegacy(opts = {}) {
2137
+ return { type: "OrbLegacy", signal: opts.signal };
1834
2138
  }
1835
- var IDKitRequestBuilder = class {
2139
+ function secureDocumentLegacy(opts = {}) {
2140
+ return { type: "SecureDocumentLegacy", signal: opts.signal };
2141
+ }
2142
+ function documentLegacy(opts = {}) {
2143
+ return { type: "DocumentLegacy", signal: opts.signal };
2144
+ }
2145
+ function createWasmBuilderFromConfig(config) {
2146
+ if (!config.rp_context) {
2147
+ throw new Error("rp_context is required for WASM bridge transport");
2148
+ }
2149
+ const rpContext = new idkit_wasm_exports.RpContextWasm(
2150
+ config.rp_context.rp_id,
2151
+ config.rp_context.nonce,
2152
+ BigInt(config.rp_context.created_at),
2153
+ BigInt(config.rp_context.expires_at),
2154
+ config.rp_context.signature
2155
+ );
2156
+ if (config.type === "request") {
2157
+ return idkit_wasm_exports.request(
2158
+ config.app_id,
2159
+ String(config.action ?? ""),
2160
+ rpContext,
2161
+ config.action_description ?? null,
2162
+ config.bridge_url ?? null,
2163
+ config.allow_legacy_proofs ?? false,
2164
+ config.override_connect_base_url ?? null,
2165
+ config.environment ?? null
2166
+ );
2167
+ }
2168
+ if (config.type === "proveSession") {
2169
+ return idkit_wasm_exports.proveSession(
2170
+ config.session_id,
2171
+ config.app_id,
2172
+ rpContext,
2173
+ config.action_description ?? null,
2174
+ config.bridge_url ?? null,
2175
+ config.override_connect_base_url ?? null,
2176
+ config.environment ?? null
2177
+ );
2178
+ }
2179
+ return idkit_wasm_exports.createSession(
2180
+ config.app_id,
2181
+ rpContext,
2182
+ config.action_description ?? null,
2183
+ config.bridge_url ?? null,
2184
+ config.override_connect_base_url ?? null,
2185
+ config.environment ?? null
2186
+ );
2187
+ }
2188
+ var IDKitBuilder2 = class {
1836
2189
  constructor(config) {
1837
2190
  this.config = config;
1838
2191
  }
@@ -1844,63 +2197,44 @@ var IDKitRequestBuilder = class {
1844
2197
  *
1845
2198
  * @example
1846
2199
  * ```typescript
1847
- * const request = await IDKit.request({ app_id, action, rp_context })
1848
- * .constraints(any(CredentialRequest('orb'), CredentialRequest('face')))
2200
+ * const request = await IDKit.request({ app_id, action, rp_context, allow_legacy_proofs: false })
2201
+ * .constraints(any(CredentialRequest('orb'), CredentialRequest('face')));
1849
2202
  * ```
1850
2203
  */
1851
2204
  async constraints(constraints) {
1852
2205
  await initIDKit();
1853
- const rpContext = new idkit_wasm_exports.RpContextWasm(
1854
- this.config.rp_context.rp_id,
1855
- this.config.rp_context.nonce,
1856
- BigInt(this.config.rp_context.created_at),
1857
- BigInt(this.config.rp_context.expires_at),
1858
- this.config.rp_context.signature
1859
- );
1860
- const wasmBuilder = idkit_wasm_exports.request(
1861
- this.config.app_id,
1862
- String(this.config.action),
1863
- rpContext,
1864
- this.config.action_description ?? null,
1865
- this.config.bridge_url ?? null
1866
- );
2206
+ const wasmBuilder = createWasmBuilderFromConfig(this.config);
2207
+ if (isInWorldApp()) {
2208
+ const payload = wasmBuilder.nativePayload(constraints);
2209
+ return createNativeRequest(payload, this.config);
2210
+ }
1867
2211
  const wasmRequest = await wasmBuilder.constraints(
1868
2212
  constraints
1869
2213
  );
1870
2214
  return new IDKitRequestImpl(wasmRequest);
1871
2215
  }
1872
2216
  /**
1873
- * Creates an IDKit request from a preset
2217
+ * Creates an IDKit request from a preset (works for all request types)
1874
2218
  *
1875
2219
  * Presets provide a simplified way to create requests with predefined
1876
- * credential configurations. The preset is converted to both World ID 4.0
1877
- * constraints and World ID 3.0 legacy fields for backward compatibility.
2220
+ * credential configurations.
1878
2221
  *
1879
- * @param preset - A preset object from orbLegacy()
2222
+ * @param preset - A preset object from orbLegacy(), secureDocumentLegacy(), or documentLegacy()
1880
2223
  * @returns A new IDKitRequest instance
1881
2224
  *
1882
2225
  * @example
1883
2226
  * ```typescript
1884
- * const request = await IDKit.request({ app_id, action, rp_context })
1885
- * .preset(orbLegacy({ signal: 'user-123' }))
2227
+ * const request = await IDKit.request({ app_id, action, rp_context, allow_legacy_proofs: true })
2228
+ * .preset(orbLegacy({ signal: 'user-123' }));
1886
2229
  * ```
1887
2230
  */
1888
2231
  async preset(preset) {
1889
2232
  await initIDKit();
1890
- const rpContext = new idkit_wasm_exports.RpContextWasm(
1891
- this.config.rp_context.rp_id,
1892
- this.config.rp_context.nonce,
1893
- BigInt(this.config.rp_context.created_at),
1894
- BigInt(this.config.rp_context.expires_at),
1895
- this.config.rp_context.signature
1896
- );
1897
- const wasmBuilder = idkit_wasm_exports.request(
1898
- this.config.app_id,
1899
- String(this.config.action),
1900
- rpContext,
1901
- this.config.action_description ?? null,
1902
- this.config.bridge_url ?? null
1903
- );
2233
+ const wasmBuilder = createWasmBuilderFromConfig(this.config);
2234
+ if (isInWorldApp()) {
2235
+ const payload = wasmBuilder.nativePayloadFromPreset(preset);
2236
+ return createNativeRequest(payload, this.config);
2237
+ }
1904
2238
  const wasmRequest = await wasmBuilder.preset(
1905
2239
  preset
1906
2240
  );
@@ -1915,17 +2249,80 @@ function createRequest(config) {
1915
2249
  throw new Error("action is required");
1916
2250
  }
1917
2251
  if (!config.rp_context) {
1918
- throw new Error("rp_context is required");
2252
+ throw new Error(
2253
+ "rp_context is required. Generate it on your backend using signRequest()."
2254
+ );
2255
+ }
2256
+ if (typeof config.allow_legacy_proofs !== "boolean") {
2257
+ throw new Error(
2258
+ "allow_legacy_proofs is required. Set to true to accept v3 proofs during migration, or false to only accept v4 proofs."
2259
+ );
2260
+ }
2261
+ return new IDKitBuilder2({
2262
+ type: "request",
2263
+ app_id: config.app_id,
2264
+ action: String(config.action),
2265
+ rp_context: config.rp_context,
2266
+ action_description: config.action_description,
2267
+ bridge_url: config.bridge_url,
2268
+ allow_legacy_proofs: config.allow_legacy_proofs,
2269
+ override_connect_base_url: config.override_connect_base_url,
2270
+ environment: config.environment
2271
+ });
2272
+ }
2273
+ function createSession2(config) {
2274
+ if (!config.app_id) {
2275
+ throw new Error("app_id is required");
2276
+ }
2277
+ if (!config.rp_context) {
2278
+ throw new Error(
2279
+ "rp_context is required. Generate it on your backend using signRequest()."
2280
+ );
2281
+ }
2282
+ return new IDKitBuilder2({
2283
+ type: "session",
2284
+ app_id: config.app_id,
2285
+ rp_context: config.rp_context,
2286
+ action_description: config.action_description,
2287
+ bridge_url: config.bridge_url,
2288
+ override_connect_base_url: config.override_connect_base_url,
2289
+ environment: config.environment
2290
+ });
2291
+ }
2292
+ function proveSession2(sessionId, config) {
2293
+ if (!sessionId) {
2294
+ throw new Error("session_id is required");
2295
+ }
2296
+ if (!config.app_id) {
2297
+ throw new Error("app_id is required");
1919
2298
  }
1920
- return new IDKitRequestBuilder(config);
2299
+ if (!config.rp_context) {
2300
+ throw new Error(
2301
+ "rp_context is required. Generate it on your backend using signRequest()."
2302
+ );
2303
+ }
2304
+ return new IDKitBuilder2({
2305
+ type: "proveSession",
2306
+ session_id: sessionId,
2307
+ app_id: config.app_id,
2308
+ rp_context: config.rp_context,
2309
+ action_description: config.action_description,
2310
+ bridge_url: config.bridge_url,
2311
+ override_connect_base_url: config.override_connect_base_url,
2312
+ environment: config.environment
2313
+ });
1921
2314
  }
1922
2315
  var IDKit = {
1923
- /** Initialize WASM for browser environments */
2316
+ /** Initialize WASM for browser environments (not needed in World App) */
1924
2317
  init: initIDKit,
1925
2318
  /** Initialize WASM for Node.js/server environments */
1926
2319
  initServer: initIDKitServer,
1927
2320
  /** Create a new verification request */
1928
2321
  request: createRequest,
2322
+ /** Create a new session (no action, no existing session_id) */
2323
+ createSession: createSession2,
2324
+ /** Prove an existing session (no action, has session_id) */
2325
+ proveSession: proveSession2,
1929
2326
  /** Create a CredentialRequest for a credential type */
1930
2327
  CredentialRequest,
1931
2328
  /** Create an OR constraint - at least one child must be satisfied */
@@ -1933,7 +2330,11 @@ var IDKit = {
1933
2330
  /** Create an AND constraint - all children must be satisfied */
1934
2331
  all,
1935
2332
  /** Create an OrbLegacy preset for World ID 3.0 legacy support */
1936
- orbLegacy: orbLegacy2
2333
+ orbLegacy,
2334
+ /** Create a SecureDocumentLegacy preset for World ID 3.0 legacy support */
2335
+ secureDocumentLegacy,
2336
+ /** Create a DocumentLegacy preset for World ID 3.0 legacy support */
2337
+ documentLegacy
1937
2338
  };
1938
2339
 
1939
2340
  // src/lib/platform.ts
@@ -1970,17 +2371,21 @@ function signRequest2(action, signingKeyHex, ttlSeconds) {
1970
2371
  return idkit_wasm_exports.signRequest(action, signingKeyHex, ttlBigInt);
1971
2372
  }
1972
2373
 
1973
- exports.AppErrorCodes = AppErrorCodes;
2374
+ // src/lib/hashing.ts
2375
+ function hashSignal2(signal) {
2376
+ return idkit_wasm_exports.hashSignal(signal);
2377
+ }
2378
+
1974
2379
  exports.CredentialRequest = CredentialRequest;
1975
2380
  exports.IDKit = IDKit;
1976
- exports.ResponseStatus = ResponseStatus;
1977
- exports.VerificationState = VerificationState;
2381
+ exports.IDKitErrorCodes = IDKitErrorCodes;
1978
2382
  exports.all = all;
1979
2383
  exports.any = any;
2384
+ exports.documentLegacy = documentLegacy;
2385
+ exports.hashSignal = hashSignal2;
1980
2386
  exports.isNode = isNode;
1981
2387
  exports.isReactNative = isReactNative;
1982
2388
  exports.isWeb = isWeb;
1983
- exports.orbLegacy = orbLegacy2;
2389
+ exports.orbLegacy = orbLegacy;
2390
+ exports.secureDocumentLegacy = secureDocumentLegacy;
1984
2391
  exports.signRequest = signRequest2;
1985
- //# sourceMappingURL=index.cjs.map
1986
- //# sourceMappingURL=index.cjs.map