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

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