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

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
@@ -1,5 +1,11 @@
1
1
  'use strict';
2
2
 
3
+ var sha3 = require('@noble/hashes/sha3');
4
+ var utils = require('@noble/hashes/utils');
5
+ var hmac = require('@noble/hashes/hmac');
6
+ var sha2 = require('@noble/hashes/sha2');
7
+ var secp256k1 = require('@noble/secp256k1');
8
+
3
9
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
4
10
  var __defProp = Object.defineProperty;
5
11
  var __export = (target, all2) => {
@@ -7,54 +13,43 @@ var __export = (target, all2) => {
7
13
  __defProp(target, name, { get: all2[name], enumerable: true });
8
14
  };
9
15
 
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 || {});
16
+ // src/types/result.ts
17
+ var IDKitErrorCodes = /* @__PURE__ */ ((IDKitErrorCodes2) => {
18
+ IDKitErrorCodes2["UserRejected"] = "user_rejected";
19
+ IDKitErrorCodes2["VerificationRejected"] = "verification_rejected";
20
+ IDKitErrorCodes2["CredentialUnavailable"] = "credential_unavailable";
21
+ IDKitErrorCodes2["MalformedRequest"] = "malformed_request";
22
+ IDKitErrorCodes2["InvalidNetwork"] = "invalid_network";
23
+ IDKitErrorCodes2["InclusionProofPending"] = "inclusion_proof_pending";
24
+ IDKitErrorCodes2["InclusionProofFailed"] = "inclusion_proof_failed";
25
+ IDKitErrorCodes2["UnexpectedResponse"] = "unexpected_response";
26
+ IDKitErrorCodes2["ConnectionFailed"] = "connection_failed";
27
+ IDKitErrorCodes2["MaxVerificationsReached"] = "max_verifications_reached";
28
+ IDKitErrorCodes2["FailedByHostApp"] = "failed_by_host_app";
29
+ IDKitErrorCodes2["GenericError"] = "generic_error";
30
+ IDKitErrorCodes2["Timeout"] = "timeout";
31
+ IDKitErrorCodes2["Cancelled"] = "cancelled";
32
+ return IDKitErrorCodes2;
33
+ })(IDKitErrorCodes || {});
39
34
 
40
35
  // wasm/idkit_wasm.js
41
36
  var idkit_wasm_exports = {};
42
37
  __export(idkit_wasm_exports, {
43
38
  BridgeEncryption: () => BridgeEncryption,
44
39
  CredentialRequestWasm: () => CredentialRequestWasm,
40
+ IDKitBuilder: () => IDKitBuilder,
45
41
  IDKitProof: () => IDKitProof,
46
42
  IDKitRequest: () => IDKitRequest,
47
- IDKitRequestBuilderWasm: () => IDKitRequestBuilderWasm,
48
43
  RpContextWasm: () => RpContextWasm,
49
44
  RpSignature: () => RpSignature,
50
45
  base64Decode: () => base64Decode,
51
46
  base64Encode: () => base64Encode,
47
+ createSession: () => createSession,
52
48
  default: () => idkit_wasm_default,
53
49
  hashSignal: () => hashSignal,
54
- hashSignalBytes: () => hashSignalBytes,
55
50
  initSync: () => initSync,
56
51
  init_wasm: () => init_wasm,
57
- orbLegacy: () => orbLegacy,
52
+ proveSession: () => proveSession,
58
53
  request: () => request,
59
54
  signRequest: () => signRequest
60
55
  });
@@ -251,54 +246,28 @@ function makeMutClosure(arg0, arg1, dtor, f) {
251
246
  CLOSURE_DTORS.register(real, state, state);
252
247
  return real;
253
248
  }
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
249
  function _assertClass(instance, klass) {
297
250
  if (!(instance instanceof klass)) {
298
251
  throw new Error(`expected instance of ${klass.name}`);
299
252
  }
300
253
  }
301
- function request(app_id, action, rp_context, action_description, bridge_url) {
254
+ function createSession(app_id, rp_context, action_description, bridge_url, override_connect_base_url, environment) {
255
+ const ptr0 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
256
+ const len0 = WASM_VECTOR_LEN;
257
+ _assertClass(rp_context, RpContextWasm);
258
+ var ptr1 = rp_context.__destroy_into_raw();
259
+ var ptr2 = isLikeNone(action_description) ? 0 : passStringToWasm0(action_description, wasm.__wbindgen_export, wasm.__wbindgen_export2);
260
+ var len2 = WASM_VECTOR_LEN;
261
+ var ptr3 = isLikeNone(bridge_url) ? 0 : passStringToWasm0(bridge_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
262
+ var len3 = WASM_VECTOR_LEN;
263
+ var ptr4 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
264
+ var len4 = WASM_VECTOR_LEN;
265
+ var ptr5 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
266
+ var len5 = WASM_VECTOR_LEN;
267
+ const ret = wasm.createSession(ptr0, len0, ptr1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
268
+ return IDKitBuilder.__wrap(ret);
269
+ }
270
+ function request(app_id, action, rp_context, action_description, bridge_url, allow_legacy_proofs, override_connect_base_url, environment) {
302
271
  const ptr0 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
303
272
  const len0 = WASM_VECTOR_LEN;
304
273
  const ptr1 = passStringToWasm0(action, wasm.__wbindgen_export, wasm.__wbindgen_export2);
@@ -309,28 +278,56 @@ function request(app_id, action, rp_context, action_description, bridge_url) {
309
278
  var len3 = WASM_VECTOR_LEN;
310
279
  var ptr4 = isLikeNone(bridge_url) ? 0 : passStringToWasm0(bridge_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
311
280
  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);
281
+ var ptr5 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
282
+ var len5 = WASM_VECTOR_LEN;
283
+ var ptr6 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
284
+ var len6 = WASM_VECTOR_LEN;
285
+ const ret = wasm.idkitbuilder_new(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, allow_legacy_proofs, ptr5, len5, ptr6, len6);
286
+ return IDKitBuilder.__wrap(ret);
314
287
  }
315
- function orbLegacy(signal) {
288
+ function base64Decode(data) {
316
289
  try {
317
290
  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);
291
+ const ptr0 = passStringToWasm0(data, wasm.__wbindgen_export, wasm.__wbindgen_export2);
292
+ const len0 = WASM_VECTOR_LEN;
293
+ wasm.base64Decode(retptr, ptr0, len0);
321
294
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
322
295
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
323
296
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
324
- if (r2) {
325
- throw takeObject(r1);
297
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
298
+ if (r3) {
299
+ throw takeObject(r2);
326
300
  }
327
- return takeObject(r0);
301
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
302
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
303
+ return v2;
328
304
  } finally {
329
305
  wasm.__wbindgen_add_to_stack_pointer(16);
330
306
  }
331
307
  }
332
- function init_wasm() {
333
- wasm.init_wasm();
308
+ function proveSession(session_id, app_id, rp_context, action_description, bridge_url, override_connect_base_url, environment) {
309
+ const ptr0 = passStringToWasm0(session_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
310
+ const len0 = WASM_VECTOR_LEN;
311
+ const ptr1 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
312
+ const len1 = WASM_VECTOR_LEN;
313
+ _assertClass(rp_context, RpContextWasm);
314
+ var ptr2 = rp_context.__destroy_into_raw();
315
+ var ptr3 = isLikeNone(action_description) ? 0 : passStringToWasm0(action_description, wasm.__wbindgen_export, wasm.__wbindgen_export2);
316
+ var len3 = WASM_VECTOR_LEN;
317
+ var ptr4 = isLikeNone(bridge_url) ? 0 : passStringToWasm0(bridge_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
318
+ var len4 = WASM_VECTOR_LEN;
319
+ var ptr5 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
320
+ var len5 = WASM_VECTOR_LEN;
321
+ var ptr6 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
322
+ var len6 = WASM_VECTOR_LEN;
323
+ const ret = wasm.idkitbuilder_forProveSession(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6);
324
+ return IDKitBuilder.__wrap(ret);
325
+ }
326
+ function passArray8ToWasm0(arg, malloc) {
327
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
328
+ getUint8ArrayMemory0().set(arg, ptr / 1);
329
+ WASM_VECTOR_LEN = arg.length;
330
+ return ptr;
334
331
  }
335
332
  function base64Encode(data) {
336
333
  let deferred2_0;
@@ -350,53 +347,61 @@ function base64Encode(data) {
350
347
  wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
351
348
  }
352
349
  }
353
- function base64Decode(data) {
350
+ function init_wasm() {
351
+ wasm.init_wasm();
352
+ }
353
+ function signRequest(action, signing_key_hex, ttl_seconds) {
354
354
  try {
355
355
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
356
- const ptr0 = passStringToWasm0(data, wasm.__wbindgen_export, wasm.__wbindgen_export2);
356
+ const ptr0 = passStringToWasm0(action, wasm.__wbindgen_export, wasm.__wbindgen_export2);
357
357
  const len0 = WASM_VECTOR_LEN;
358
- wasm.base64Decode(retptr, ptr0, len0);
358
+ const ptr1 = passStringToWasm0(signing_key_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
359
+ const len1 = WASM_VECTOR_LEN;
360
+ wasm.signRequest(retptr, ptr0, len0, ptr1, len1, !isLikeNone(ttl_seconds), isLikeNone(ttl_seconds) ? BigInt(0) : ttl_seconds);
359
361
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
360
362
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
361
363
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
362
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
363
- if (r3) {
364
- throw takeObject(r2);
364
+ if (r2) {
365
+ throw takeObject(r1);
365
366
  }
366
- var v2 = getArrayU8FromWasm0(r0, r1).slice();
367
- wasm.__wbindgen_export4(r0, r1 * 1, 1);
368
- return v2;
367
+ return RpSignature.__wrap(r0);
369
368
  } finally {
370
369
  wasm.__wbindgen_add_to_stack_pointer(16);
371
370
  }
372
371
  }
373
- function signRequest(action, signing_key_hex, ttl_seconds) {
372
+ function hashSignal(signal) {
373
+ let deferred2_0;
374
+ let deferred2_1;
374
375
  try {
375
376
  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);
377
+ wasm.hashSignal(retptr, addHeapObject(signal));
381
378
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
382
379
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
383
380
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
384
- if (r2) {
385
- throw takeObject(r1);
381
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
382
+ var ptr1 = r0;
383
+ var len1 = r1;
384
+ if (r3) {
385
+ ptr1 = 0;
386
+ len1 = 0;
387
+ throw takeObject(r2);
386
388
  }
387
- return RpSignature.__wrap(r0);
389
+ deferred2_0 = ptr1;
390
+ deferred2_1 = len1;
391
+ return getStringFromWasm0(ptr1, len1);
388
392
  } finally {
389
393
  wasm.__wbindgen_add_to_stack_pointer(16);
394
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
390
395
  }
391
396
  }
392
- function __wasm_bindgen_func_elem_551(arg0, arg1) {
393
- wasm.__wasm_bindgen_func_elem_551(arg0, arg1);
397
+ function __wasm_bindgen_func_elem_597(arg0, arg1) {
398
+ wasm.__wasm_bindgen_func_elem_597(arg0, arg1);
394
399
  }
395
- function __wasm_bindgen_func_elem_914(arg0, arg1, arg2) {
396
- wasm.__wasm_bindgen_func_elem_914(arg0, arg1, addHeapObject(arg2));
400
+ function __wasm_bindgen_func_elem_960(arg0, arg1, arg2) {
401
+ wasm.__wasm_bindgen_func_elem_960(arg0, arg1, addHeapObject(arg2));
397
402
  }
398
- function __wasm_bindgen_func_elem_1281(arg0, arg1, arg2, arg3) {
399
- wasm.__wasm_bindgen_func_elem_1281(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
403
+ function __wasm_bindgen_func_elem_1345(arg0, arg1, arg2, arg3) {
404
+ wasm.__wasm_bindgen_func_elem_1345(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
400
405
  }
401
406
  var __wbindgen_enum_RequestCache = ["default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached"];
402
407
  var __wbindgen_enum_RequestCredentials = ["omit", "same-origin", "include"];
@@ -575,7 +580,7 @@ var CredentialRequestWasm = class _CredentialRequestWasm {
575
580
  wasm.__wbg_credentialrequestwasm_free(ptr, 0);
576
581
  }
577
582
  /**
578
- * Creates a new request item with ABI-encoded bytes for the signal
583
+ * Creates a new request item with raw bytes for the signal
579
584
  *
580
585
  * # Errors
581
586
  *
@@ -657,6 +662,34 @@ var CredentialRequestWasm = class _CredentialRequestWasm {
657
662
  wasm.__wbindgen_add_to_stack_pointer(16);
658
663
  }
659
664
  }
665
+ /**
666
+ * Creates a new request item with expiration minimum timestamp
667
+ *
668
+ * # Errors
669
+ *
670
+ * Returns an error if the credential type is invalid
671
+ * @param {any} credential_type
672
+ * @param {string | null | undefined} signal
673
+ * @param {bigint} expires_at_min
674
+ * @returns {CredentialRequestWasm}
675
+ */
676
+ static withExpiresAtMin(credential_type, signal, expires_at_min) {
677
+ try {
678
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
679
+ var ptr0 = isLikeNone(signal) ? 0 : passStringToWasm0(signal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
680
+ var len0 = WASM_VECTOR_LEN;
681
+ wasm.credentialrequestwasm_withExpiresAtMin(retptr, addHeapObject(credential_type), ptr0, len0, expires_at_min);
682
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
683
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
684
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
685
+ if (r2) {
686
+ throw takeObject(r1);
687
+ }
688
+ return _CredentialRequestWasm.__wrap(r0);
689
+ } finally {
690
+ wasm.__wbindgen_add_to_stack_pointer(16);
691
+ }
692
+ }
660
693
  /**
661
694
  * Creates a new request item
662
695
  *
@@ -714,6 +747,191 @@ var CredentialRequestWasm = class _CredentialRequestWasm {
714
747
  }
715
748
  };
716
749
  if (Symbol.dispose) CredentialRequestWasm.prototype[Symbol.dispose] = CredentialRequestWasm.prototype.free;
750
+ var IDKitBuilderFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
751
+ }, unregister: () => {
752
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_idkitbuilder_free(ptr >>> 0, 1));
753
+ var IDKitBuilder = class _IDKitBuilder {
754
+ static __wrap(ptr) {
755
+ ptr = ptr >>> 0;
756
+ const obj = Object.create(_IDKitBuilder.prototype);
757
+ obj.__wbg_ptr = ptr;
758
+ IDKitBuilderFinalization.register(obj, obj.__wbg_ptr, obj);
759
+ return obj;
760
+ }
761
+ __destroy_into_raw() {
762
+ const ptr = this.__wbg_ptr;
763
+ this.__wbg_ptr = 0;
764
+ IDKitBuilderFinalization.unregister(this);
765
+ return ptr;
766
+ }
767
+ free() {
768
+ const ptr = this.__destroy_into_raw();
769
+ wasm.__wbg_idkitbuilder_free(ptr, 0);
770
+ }
771
+ /**
772
+ * Creates a `BridgeConnection` with the given constraints
773
+ * @param {any} constraints_json
774
+ * @returns {Promise<any>}
775
+ */
776
+ constraints(constraints_json) {
777
+ const ptr = this.__destroy_into_raw();
778
+ const ret = wasm.idkitbuilder_constraints(ptr, addHeapObject(constraints_json));
779
+ return takeObject(ret);
780
+ }
781
+ /**
782
+ * Builds the native payload for constraints (synchronous, no bridge connection).
783
+ *
784
+ * Used by the native transport to get the same payload format as the bridge
785
+ * without creating a network connection.
786
+ *
787
+ * # Errors
788
+ *
789
+ * Returns an error if constraints are invalid or payload construction fails.
790
+ * @param {any} constraints_json
791
+ * @returns {any}
792
+ */
793
+ nativePayload(constraints_json) {
794
+ try {
795
+ const ptr = this.__destroy_into_raw();
796
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
797
+ wasm.idkitbuilder_nativePayload(retptr, ptr, addHeapObject(constraints_json));
798
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
799
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
800
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
801
+ if (r2) {
802
+ throw takeObject(r1);
803
+ }
804
+ return takeObject(r0);
805
+ } finally {
806
+ wasm.__wbindgen_add_to_stack_pointer(16);
807
+ }
808
+ }
809
+ /**
810
+ * Creates a new builder for proving an existing session
811
+ * @param {string} session_id
812
+ * @param {string} app_id
813
+ * @param {RpContextWasm} rp_context
814
+ * @param {string | null} [action_description]
815
+ * @param {string | null} [bridge_url]
816
+ * @param {string | null} [override_connect_base_url]
817
+ * @param {string | null} [environment]
818
+ * @returns {IDKitBuilder}
819
+ */
820
+ static forProveSession(session_id, app_id, rp_context, action_description, bridge_url, override_connect_base_url, environment) {
821
+ const ptr0 = passStringToWasm0(session_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
822
+ const len0 = WASM_VECTOR_LEN;
823
+ const ptr1 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
824
+ const len1 = WASM_VECTOR_LEN;
825
+ _assertClass(rp_context, RpContextWasm);
826
+ var ptr2 = rp_context.__destroy_into_raw();
827
+ var ptr3 = isLikeNone(action_description) ? 0 : passStringToWasm0(action_description, wasm.__wbindgen_export, wasm.__wbindgen_export2);
828
+ var len3 = WASM_VECTOR_LEN;
829
+ var ptr4 = isLikeNone(bridge_url) ? 0 : passStringToWasm0(bridge_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
830
+ var len4 = WASM_VECTOR_LEN;
831
+ var ptr5 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
832
+ var len5 = WASM_VECTOR_LEN;
833
+ var ptr6 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
834
+ var len6 = WASM_VECTOR_LEN;
835
+ const ret = wasm.idkitbuilder_forProveSession(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6);
836
+ return _IDKitBuilder.__wrap(ret);
837
+ }
838
+ /**
839
+ * Creates a new builder for creating a new session
840
+ * @param {string} app_id
841
+ * @param {RpContextWasm} rp_context
842
+ * @param {string | null} [action_description]
843
+ * @param {string | null} [bridge_url]
844
+ * @param {string | null} [override_connect_base_url]
845
+ * @param {string | null} [environment]
846
+ * @returns {IDKitBuilder}
847
+ */
848
+ static forCreateSession(app_id, rp_context, action_description, bridge_url, override_connect_base_url, environment) {
849
+ const ptr0 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
850
+ const len0 = WASM_VECTOR_LEN;
851
+ _assertClass(rp_context, RpContextWasm);
852
+ var ptr1 = rp_context.__destroy_into_raw();
853
+ var ptr2 = isLikeNone(action_description) ? 0 : passStringToWasm0(action_description, wasm.__wbindgen_export, wasm.__wbindgen_export2);
854
+ var len2 = WASM_VECTOR_LEN;
855
+ var ptr3 = isLikeNone(bridge_url) ? 0 : passStringToWasm0(bridge_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
856
+ var len3 = WASM_VECTOR_LEN;
857
+ var ptr4 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
858
+ var len4 = WASM_VECTOR_LEN;
859
+ var ptr5 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
860
+ var len5 = WASM_VECTOR_LEN;
861
+ const ret = wasm.createSession(ptr0, len0, ptr1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
862
+ return _IDKitBuilder.__wrap(ret);
863
+ }
864
+ /**
865
+ * Builds the native payload from a preset (synchronous, no bridge connection).
866
+ *
867
+ * Used by the native transport to get the same payload format as the bridge
868
+ * without creating a network connection.
869
+ *
870
+ * # Errors
871
+ *
872
+ * Returns an error if the preset is invalid or payload construction fails.
873
+ * @param {any} preset_json
874
+ * @returns {any}
875
+ */
876
+ nativePayloadFromPreset(preset_json) {
877
+ try {
878
+ const ptr = this.__destroy_into_raw();
879
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
880
+ wasm.idkitbuilder_nativePayloadFromPreset(retptr, ptr, addHeapObject(preset_json));
881
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
882
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
883
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
884
+ if (r2) {
885
+ throw takeObject(r1);
886
+ }
887
+ return takeObject(r0);
888
+ } finally {
889
+ wasm.__wbindgen_add_to_stack_pointer(16);
890
+ }
891
+ }
892
+ /**
893
+ * Creates a new builder for uniqueness requests
894
+ * @param {string} app_id
895
+ * @param {string} action
896
+ * @param {RpContextWasm} rp_context
897
+ * @param {string | null | undefined} action_description
898
+ * @param {string | null | undefined} bridge_url
899
+ * @param {boolean} allow_legacy_proofs
900
+ * @param {string | null} [override_connect_base_url]
901
+ * @param {string | null} [environment]
902
+ */
903
+ constructor(app_id, action, rp_context, action_description, bridge_url, allow_legacy_proofs, override_connect_base_url, environment) {
904
+ const ptr0 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
905
+ const len0 = WASM_VECTOR_LEN;
906
+ const ptr1 = passStringToWasm0(action, wasm.__wbindgen_export, wasm.__wbindgen_export2);
907
+ const len1 = WASM_VECTOR_LEN;
908
+ _assertClass(rp_context, RpContextWasm);
909
+ var ptr2 = rp_context.__destroy_into_raw();
910
+ var ptr3 = isLikeNone(action_description) ? 0 : passStringToWasm0(action_description, wasm.__wbindgen_export, wasm.__wbindgen_export2);
911
+ var len3 = WASM_VECTOR_LEN;
912
+ var ptr4 = isLikeNone(bridge_url) ? 0 : passStringToWasm0(bridge_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
913
+ var len4 = WASM_VECTOR_LEN;
914
+ var ptr5 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
915
+ var len5 = WASM_VECTOR_LEN;
916
+ var ptr6 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
917
+ var len6 = WASM_VECTOR_LEN;
918
+ const ret = wasm.idkitbuilder_new(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, allow_legacy_proofs, ptr5, len5, ptr6, len6);
919
+ this.__wbg_ptr = ret >>> 0;
920
+ IDKitBuilderFinalization.register(this, this.__wbg_ptr, this);
921
+ return this;
922
+ }
923
+ /**
924
+ * Creates a `BridgeConnection` from a preset (works for all request types)
925
+ * @param {any} preset_json
926
+ * @returns {Promise<any>}
927
+ */
928
+ preset(preset_json) {
929
+ const ptr = this.__destroy_into_raw();
930
+ const ret = wasm.idkitbuilder_preset(ptr, addHeapObject(preset_json));
931
+ return takeObject(ret);
932
+ }
933
+ };
934
+ if (Symbol.dispose) IDKitBuilder.prototype[Symbol.dispose] = IDKitBuilder.prototype.free;
717
935
  var IDKitProofFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
718
936
  }, unregister: () => {
719
937
  } } : new FinalizationRegistry((ptr) => wasm.__wbg_idkitproof_free(ptr >>> 0, 1));
@@ -896,98 +1114,6 @@ var IDKitRequest = class _IDKitRequest {
896
1114
  }
897
1115
  };
898
1116
  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
1117
  var RpContextWasmFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
992
1118
  }, unregister: () => {
993
1119
  } } : new FinalizationRegistry((ptr) => wasm.__wbg_rpcontextwasm_free(ptr >>> 0, 1));
@@ -1343,10 +1469,6 @@ function __wbg_get_imports() {
1343
1469
  return addHeapObject(ret);
1344
1470
  }, arguments);
1345
1471
  };
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
1472
  imports.wbg.__wbg_has_787fafc980c3ccdb = function() {
1351
1473
  return handleError(function(arg0, arg1) {
1352
1474
  const ret = Reflect.has(getObject(arg0), getObject(arg1));
@@ -1442,7 +1564,7 @@ function __wbg_get_imports() {
1442
1564
  const a = state0.a;
1443
1565
  state0.a = 0;
1444
1566
  try {
1445
- return __wasm_bindgen_func_elem_1281(a, state0.b, arg02, arg12);
1567
+ return __wasm_bindgen_func_elem_1345(a, state0.b, arg02, arg12);
1446
1568
  } finally {
1447
1569
  state0.a = a;
1448
1570
  }
@@ -1660,7 +1782,7 @@ function __wbg_get_imports() {
1660
1782
  return addHeapObject(ret);
1661
1783
  };
1662
1784
  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);
1785
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_596, __wasm_bindgen_func_elem_597);
1664
1786
  return addHeapObject(ret);
1665
1787
  };
1666
1788
  imports.wbg.__wbindgen_cast_9ae0607507abb057 = function(arg0) {
@@ -1668,7 +1790,7 @@ function __wbg_get_imports() {
1668
1790
  return addHeapObject(ret);
1669
1791
  };
1670
1792
  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);
1793
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_959, __wasm_bindgen_func_elem_960);
1672
1794
  return addHeapObject(ret);
1673
1795
  };
1674
1796
  imports.wbg.__wbindgen_cast_cb9088102bce6b30 = function(arg0, arg1) {
@@ -1754,27 +1876,178 @@ async function initIDKit() {
1754
1876
  })();
1755
1877
  return wasmInitPromise;
1756
1878
  }
1757
- async function initIDKitServer() {
1758
- if (wasmInitialized) {
1759
- return;
1879
+
1880
+ // src/transports/native.ts
1881
+ function isInWorldApp() {
1882
+ return typeof window !== "undefined" && Boolean(window.WorldApp);
1883
+ }
1884
+ var _requestCounter = 0;
1885
+ var _activeNativeRequest = null;
1886
+ function createNativeRequest(wasmPayload, config) {
1887
+ if (_activeNativeRequest) {
1888
+ _activeNativeRequest.cancel();
1889
+ }
1890
+ const request2 = new NativeIDKitRequest(wasmPayload, config);
1891
+ _activeNativeRequest = request2;
1892
+ return request2;
1893
+ }
1894
+ var NativeIDKitRequest = class {
1895
+ constructor(wasmPayload, config) {
1896
+ this.connectorURI = "";
1897
+ this.resolved = false;
1898
+ this.cancelled = false;
1899
+ this.resolvedResult = null;
1900
+ this.messageHandler = null;
1901
+ this.rejectFn = null;
1902
+ this.requestId = crypto.randomUUID?.() ?? `native-${Date.now()}-${++_requestCounter}`;
1903
+ this.resultPromise = new Promise((resolve, reject) => {
1904
+ this.rejectFn = reject;
1905
+ const handler = (event) => {
1906
+ if (this.cancelled) return;
1907
+ const data = event.data;
1908
+ if (data?.type === "miniapp-verify-action" || data?.command === "miniapp-verify-action") {
1909
+ this.cleanup();
1910
+ const responsePayload = data.payload ?? data;
1911
+ if (responsePayload.status === "error") {
1912
+ reject(
1913
+ new NativeVerifyError(
1914
+ responsePayload.error_code ?? "generic_error" /* GenericError */
1915
+ )
1916
+ );
1917
+ } else {
1918
+ this.resolved = true;
1919
+ const result = nativeResultToIDKitResult(responsePayload, config);
1920
+ this.resolvedResult = result;
1921
+ resolve(result);
1922
+ }
1923
+ }
1924
+ };
1925
+ this.messageHandler = handler;
1926
+ window.addEventListener("message", handler);
1927
+ const sendPayload = {
1928
+ command: "verify",
1929
+ version: 2,
1930
+ payload: wasmPayload
1931
+ };
1932
+ const w = window;
1933
+ if (w.webkit?.messageHandlers?.minikit) {
1934
+ w.webkit.messageHandlers.minikit.postMessage(sendPayload);
1935
+ } else if (w.Android) {
1936
+ w.Android.postMessage(JSON.stringify(sendPayload));
1937
+ } else {
1938
+ this.cleanup();
1939
+ reject(new Error("No WebView bridge available"));
1940
+ }
1941
+ });
1942
+ this.resultPromise.catch(() => {
1943
+ }).finally(() => {
1944
+ this.cleanup();
1945
+ if (_activeNativeRequest === this) {
1946
+ _activeNativeRequest = null;
1947
+ }
1948
+ });
1760
1949
  }
1761
- if (wasmInitPromise) {
1762
- return wasmInitPromise;
1950
+ /**
1951
+ * Cancel this request. Removes the message listener so it cannot consume
1952
+ * a response meant for a later request, and rejects the pending promise.
1953
+ */
1954
+ cancel() {
1955
+ if (this.resolved || this.cancelled) return;
1956
+ this.cancelled = true;
1957
+ this.cleanup();
1958
+ this.rejectFn?.(new NativeVerifyError("cancelled" /* Cancelled */));
1959
+ if (_activeNativeRequest === this) {
1960
+ _activeNativeRequest = null;
1961
+ }
1763
1962
  }
1764
- wasmInitPromise = (async () => {
1963
+ cleanup() {
1964
+ if (this.messageHandler) {
1965
+ window.removeEventListener("message", this.messageHandler);
1966
+ this.messageHandler = null;
1967
+ }
1968
+ }
1969
+ async pollOnce() {
1970
+ if (this.resolved && this.resolvedResult) {
1971
+ return { type: "confirmed", result: this.resolvedResult };
1972
+ }
1973
+ return { type: "awaiting_confirmation" };
1974
+ }
1975
+ async pollUntilCompletion(options) {
1976
+ const timeout = options?.timeout ?? 3e5;
1765
1977
  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));
1770
- await idkit_wasm_default({ module_or_path: wasmBuffer });
1771
- wasmInitialized = true;
1978
+ const result = await Promise.race([
1979
+ this.resultPromise,
1980
+ new Promise((_, reject) => {
1981
+ if (options?.signal) {
1982
+ options.signal.addEventListener(
1983
+ "abort",
1984
+ () => reject(new NativeVerifyError("cancelled" /* Cancelled */))
1985
+ );
1986
+ }
1987
+ setTimeout(
1988
+ () => reject(new NativeVerifyError("timeout" /* Timeout */)),
1989
+ timeout
1990
+ );
1991
+ })
1992
+ ]);
1993
+ return { success: true, result };
1772
1994
  } catch (error) {
1773
- wasmInitPromise = null;
1774
- throw new Error(`Failed to initialize IDKit WASM for server: ${error}`);
1995
+ if (error instanceof NativeVerifyError) {
1996
+ return { success: false, error: error.code };
1997
+ }
1998
+ return { success: false, error: "generic_error" /* GenericError */ };
1775
1999
  }
1776
- })();
1777
- return wasmInitPromise;
2000
+ }
2001
+ };
2002
+ var NativeVerifyError = class extends Error {
2003
+ constructor(code) {
2004
+ super(code);
2005
+ this.code = code;
2006
+ }
2007
+ };
2008
+ function nativeResultToIDKitResult(payload, config) {
2009
+ const rpNonce = config.rp_context?.nonce ?? "";
2010
+ if ("responses" in payload && Array.isArray(payload.responses)) {
2011
+ return {
2012
+ protocol_version: payload.protocol_version ?? "4.0",
2013
+ nonce: payload.nonce ?? rpNonce,
2014
+ action: payload.action ?? config.action ?? "",
2015
+ action_description: payload.action_description,
2016
+ session_id: payload.session_id,
2017
+ responses: payload.responses,
2018
+ environment: payload.environment ?? config.environment ?? "production"
2019
+ };
2020
+ }
2021
+ if ("verifications" in payload) {
2022
+ return {
2023
+ protocol_version: "4.0",
2024
+ nonce: rpNonce,
2025
+ action: config.action ?? "",
2026
+ responses: payload.verifications.map((v) => ({
2027
+ identifier: v.verification_level,
2028
+ proof: [v.proof],
2029
+ nullifier: v.nullifier_hash,
2030
+ merkle_root: v.merkle_root,
2031
+ issuer_schema_id: 0,
2032
+ expires_at_min: 0
2033
+ })),
2034
+ environment: "production"
2035
+ };
2036
+ }
2037
+ return {
2038
+ protocol_version: "3.0",
2039
+ nonce: rpNonce,
2040
+ action: config.action ?? "",
2041
+ responses: [
2042
+ {
2043
+ identifier: payload.verification_level,
2044
+ proof: payload.proof,
2045
+ merkle_root: payload.merkle_root,
2046
+ nullifier: payload.nullifier_hash
2047
+ }
2048
+ ],
2049
+ environment: "production"
2050
+ };
1778
2051
  }
1779
2052
 
1780
2053
  // src/request.ts
@@ -1793,24 +2066,26 @@ var IDKitRequestImpl = class {
1793
2066
  async pollOnce() {
1794
2067
  return await this.wasmRequest.pollForStatus();
1795
2068
  }
1796
- async pollForUpdates(options) {
2069
+ async pollUntilCompletion(options) {
1797
2070
  const pollInterval = options?.pollInterval ?? 1e3;
1798
2071
  const timeout = options?.timeout ?? 3e5;
1799
2072
  const startTime = Date.now();
1800
2073
  while (true) {
1801
2074
  if (options?.signal?.aborted) {
1802
- throw new Error("Verification cancelled");
2075
+ return { success: false, error: "cancelled" /* Cancelled */ };
1803
2076
  }
1804
2077
  if (Date.now() - startTime > timeout) {
1805
- throw new Error(`Timeout waiting for proof after ${timeout}ms`);
2078
+ return { success: false, error: "timeout" /* Timeout */ };
1806
2079
  }
1807
2080
  const status = await this.pollOnce();
1808
2081
  if (status.type === "confirmed" && status.result) {
1809
- return status.result;
2082
+ return { success: true, result: status.result };
1810
2083
  }
1811
2084
  if (status.type === "failed") {
1812
- const errorCode = status.error ?? "generic_error" /* GenericError */;
1813
- throw new Error(`Verification failed: ${errorCode}`);
2085
+ return {
2086
+ success: false,
2087
+ error: status.error ?? "generic_error" /* GenericError */
2088
+ };
1814
2089
  }
1815
2090
  await new Promise((resolve) => setTimeout(resolve, pollInterval));
1816
2091
  }
@@ -1820,7 +2095,8 @@ function CredentialRequest(credential_type, options) {
1820
2095
  return {
1821
2096
  type: credential_type,
1822
2097
  signal: options?.signal,
1823
- genesis_issued_at_min: options?.genesis_issued_at_min
2098
+ genesis_issued_at_min: options?.genesis_issued_at_min,
2099
+ expires_at_min: options?.expires_at_min
1824
2100
  };
1825
2101
  }
1826
2102
  function any(...nodes) {
@@ -1829,10 +2105,59 @@ function any(...nodes) {
1829
2105
  function all(...nodes) {
1830
2106
  return { all: nodes };
1831
2107
  }
1832
- function orbLegacy2(opts = {}) {
1833
- return { type: "OrbLegacy", data: { signal: opts.signal } };
2108
+ function orbLegacy(opts = {}) {
2109
+ return { type: "OrbLegacy", signal: opts.signal };
2110
+ }
2111
+ function secureDocumentLegacy(opts = {}) {
2112
+ return { type: "SecureDocumentLegacy", signal: opts.signal };
1834
2113
  }
1835
- var IDKitRequestBuilder = class {
2114
+ function documentLegacy(opts = {}) {
2115
+ return { type: "DocumentLegacy", signal: opts.signal };
2116
+ }
2117
+ function createWasmBuilderFromConfig(config) {
2118
+ if (!config.rp_context) {
2119
+ throw new Error("rp_context is required for WASM bridge transport");
2120
+ }
2121
+ const rpContext = new idkit_wasm_exports.RpContextWasm(
2122
+ config.rp_context.rp_id,
2123
+ config.rp_context.nonce,
2124
+ BigInt(config.rp_context.created_at),
2125
+ BigInt(config.rp_context.expires_at),
2126
+ config.rp_context.signature
2127
+ );
2128
+ if (config.type === "request") {
2129
+ return idkit_wasm_exports.request(
2130
+ config.app_id,
2131
+ String(config.action ?? ""),
2132
+ rpContext,
2133
+ config.action_description ?? null,
2134
+ config.bridge_url ?? null,
2135
+ config.allow_legacy_proofs ?? false,
2136
+ config.override_connect_base_url ?? null,
2137
+ config.environment ?? null
2138
+ );
2139
+ }
2140
+ if (config.type === "proveSession") {
2141
+ return idkit_wasm_exports.proveSession(
2142
+ config.session_id,
2143
+ config.app_id,
2144
+ rpContext,
2145
+ config.action_description ?? null,
2146
+ config.bridge_url ?? null,
2147
+ config.override_connect_base_url ?? null,
2148
+ config.environment ?? null
2149
+ );
2150
+ }
2151
+ return idkit_wasm_exports.createSession(
2152
+ config.app_id,
2153
+ rpContext,
2154
+ config.action_description ?? null,
2155
+ config.bridge_url ?? null,
2156
+ config.override_connect_base_url ?? null,
2157
+ config.environment ?? null
2158
+ );
2159
+ }
2160
+ var IDKitBuilder2 = class {
1836
2161
  constructor(config) {
1837
2162
  this.config = config;
1838
2163
  }
@@ -1844,63 +2169,44 @@ var IDKitRequestBuilder = class {
1844
2169
  *
1845
2170
  * @example
1846
2171
  * ```typescript
1847
- * const request = await IDKit.request({ app_id, action, rp_context })
1848
- * .constraints(any(CredentialRequest('orb'), CredentialRequest('face')))
2172
+ * const request = await IDKit.request({ app_id, action, rp_context, allow_legacy_proofs: false })
2173
+ * .constraints(any(CredentialRequest('orb'), CredentialRequest('face')));
1849
2174
  * ```
1850
2175
  */
1851
2176
  async constraints(constraints) {
1852
2177
  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
- );
2178
+ const wasmBuilder = createWasmBuilderFromConfig(this.config);
2179
+ if (isInWorldApp()) {
2180
+ const payload = wasmBuilder.nativePayload(constraints);
2181
+ return createNativeRequest(payload, this.config);
2182
+ }
1867
2183
  const wasmRequest = await wasmBuilder.constraints(
1868
2184
  constraints
1869
2185
  );
1870
2186
  return new IDKitRequestImpl(wasmRequest);
1871
2187
  }
1872
2188
  /**
1873
- * Creates an IDKit request from a preset
2189
+ * Creates an IDKit request from a preset (works for all request types)
1874
2190
  *
1875
2191
  * 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.
2192
+ * credential configurations.
1878
2193
  *
1879
- * @param preset - A preset object from orbLegacy()
2194
+ * @param preset - A preset object from orbLegacy(), secureDocumentLegacy(), or documentLegacy()
1880
2195
  * @returns A new IDKitRequest instance
1881
2196
  *
1882
2197
  * @example
1883
2198
  * ```typescript
1884
- * const request = await IDKit.request({ app_id, action, rp_context })
1885
- * .preset(orbLegacy({ signal: 'user-123' }))
2199
+ * const request = await IDKit.request({ app_id, action, rp_context, allow_legacy_proofs: true })
2200
+ * .preset(orbLegacy({ signal: 'user-123' }));
1886
2201
  * ```
1887
2202
  */
1888
2203
  async preset(preset) {
1889
2204
  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
- );
2205
+ const wasmBuilder = createWasmBuilderFromConfig(this.config);
2206
+ if (isInWorldApp()) {
2207
+ const payload = wasmBuilder.nativePayloadFromPreset(preset);
2208
+ return createNativeRequest(payload, this.config);
2209
+ }
1904
2210
  const wasmRequest = await wasmBuilder.preset(
1905
2211
  preset
1906
2212
  );
@@ -1915,17 +2221,76 @@ function createRequest(config) {
1915
2221
  throw new Error("action is required");
1916
2222
  }
1917
2223
  if (!config.rp_context) {
1918
- throw new Error("rp_context is required");
2224
+ throw new Error(
2225
+ "rp_context is required. Generate it on your backend using signRequest()."
2226
+ );
1919
2227
  }
1920
- return new IDKitRequestBuilder(config);
2228
+ if (typeof config.allow_legacy_proofs !== "boolean") {
2229
+ throw new Error(
2230
+ "allow_legacy_proofs is required. Set to true to accept v3 proofs during migration, or false to only accept v4 proofs."
2231
+ );
2232
+ }
2233
+ return new IDKitBuilder2({
2234
+ type: "request",
2235
+ app_id: config.app_id,
2236
+ action: String(config.action),
2237
+ rp_context: config.rp_context,
2238
+ action_description: config.action_description,
2239
+ bridge_url: config.bridge_url,
2240
+ allow_legacy_proofs: config.allow_legacy_proofs,
2241
+ override_connect_base_url: config.override_connect_base_url,
2242
+ environment: config.environment
2243
+ });
2244
+ }
2245
+ function createSession2(config) {
2246
+ if (!config.app_id) {
2247
+ throw new Error("app_id is required");
2248
+ }
2249
+ if (!config.rp_context) {
2250
+ throw new Error(
2251
+ "rp_context is required. Generate it on your backend using signRequest()."
2252
+ );
2253
+ }
2254
+ return new IDKitBuilder2({
2255
+ type: "session",
2256
+ app_id: config.app_id,
2257
+ rp_context: config.rp_context,
2258
+ action_description: config.action_description,
2259
+ bridge_url: config.bridge_url,
2260
+ override_connect_base_url: config.override_connect_base_url,
2261
+ environment: config.environment
2262
+ });
2263
+ }
2264
+ function proveSession2(sessionId, config) {
2265
+ if (!sessionId) {
2266
+ throw new Error("session_id is required");
2267
+ }
2268
+ if (!config.app_id) {
2269
+ throw new Error("app_id is required");
2270
+ }
2271
+ if (!config.rp_context) {
2272
+ throw new Error(
2273
+ "rp_context is required. Generate it on your backend using signRequest()."
2274
+ );
2275
+ }
2276
+ return new IDKitBuilder2({
2277
+ type: "proveSession",
2278
+ session_id: sessionId,
2279
+ app_id: config.app_id,
2280
+ rp_context: config.rp_context,
2281
+ action_description: config.action_description,
2282
+ bridge_url: config.bridge_url,
2283
+ override_connect_base_url: config.override_connect_base_url,
2284
+ environment: config.environment
2285
+ });
1921
2286
  }
1922
2287
  var IDKit = {
1923
- /** Initialize WASM for browser environments */
1924
- init: initIDKit,
1925
- /** Initialize WASM for Node.js/server environments */
1926
- initServer: initIDKitServer,
1927
2288
  /** Create a new verification request */
1928
2289
  request: createRequest,
2290
+ /** Create a new session (no action, no existing session_id) */
2291
+ createSession: createSession2,
2292
+ /** Prove an existing session (no action, has session_id) */
2293
+ proveSession: proveSession2,
1929
2294
  /** Create a CredentialRequest for a credential type */
1930
2295
  CredentialRequest,
1931
2296
  /** Create an OR constraint - at least one child must be satisfied */
@@ -1933,7 +2298,11 @@ var IDKit = {
1933
2298
  /** Create an AND constraint - all children must be satisfied */
1934
2299
  all,
1935
2300
  /** Create an OrbLegacy preset for World ID 3.0 legacy support */
1936
- orbLegacy: orbLegacy2
2301
+ orbLegacy,
2302
+ /** Create a SecureDocumentLegacy preset for World ID 3.0 legacy support */
2303
+ secureDocumentLegacy,
2304
+ /** Create a DocumentLegacy preset for World ID 3.0 legacy support */
2305
+ documentLegacy
1937
2306
  };
1938
2307
 
1939
2308
  // src/lib/platform.ts
@@ -1958,29 +2327,83 @@ var isServerEnvironment = () => {
1958
2327
  }
1959
2328
  return false;
1960
2329
  };
2330
+ function hashToField(input) {
2331
+ const hash = BigInt("0x" + utils.bytesToHex(sha3.keccak_256(input))) >> 8n;
2332
+ return utils.hexToBytes(hash.toString(16).padStart(64, "0"));
2333
+ }
2334
+ function hashSignal2(signal) {
2335
+ let input;
2336
+ if (signal instanceof Uint8Array) {
2337
+ input = signal;
2338
+ } else if (signal.startsWith("0x") && isValidHex(signal.slice(2))) {
2339
+ input = utils.hexToBytes(signal.slice(2));
2340
+ } else {
2341
+ input = new TextEncoder().encode(signal);
2342
+ }
2343
+ return "0x" + utils.bytesToHex(hashToField(input));
2344
+ }
2345
+ function isValidHex(s) {
2346
+ if (s.length === 0) return false;
2347
+ if (s.length % 2 !== 0) return false;
2348
+ return /^[0-9a-fA-F]+$/.test(s);
2349
+ }
1961
2350
 
1962
- // src/lib/rp-signature.ts
1963
- function signRequest2(action, signingKeyHex, ttlSeconds) {
2351
+ // src/lib/signing.ts
2352
+ secp256k1.etc.hmacSha256Sync = (key, ...msgs) => hmac.hmac(sha2.sha256, key, secp256k1.etc.concatBytes(...msgs));
2353
+ var DEFAULT_TTL_SEC = 300;
2354
+ function computeRpSignatureMessage(nonceBytes, createdAt, expiresAt) {
2355
+ const message = new Uint8Array(48);
2356
+ message.set(nonceBytes, 0);
2357
+ const view = new DataView(message.buffer);
2358
+ view.setBigUint64(32, BigInt(createdAt), false);
2359
+ view.setBigUint64(40, BigInt(expiresAt), false);
2360
+ return message;
2361
+ }
2362
+ function signRequest2(_action, signingKeyHex, ttl = DEFAULT_TTL_SEC) {
1964
2363
  if (!isServerEnvironment()) {
1965
2364
  throw new Error(
1966
2365
  "signRequest can only be used in Node.js environments. This function requires access to signing keys and should never be called from browser/client-side code."
1967
2366
  );
1968
2367
  }
1969
- const ttlBigInt = ttlSeconds !== void 0 ? BigInt(ttlSeconds) : void 0;
1970
- return idkit_wasm_exports.signRequest(action, signingKeyHex, ttlBigInt);
2368
+ const keyHex = signingKeyHex.startsWith("0x") ? signingKeyHex.slice(2) : signingKeyHex;
2369
+ if (!/^[0-9a-fA-F]+$/.test(keyHex)) {
2370
+ throw new Error("Invalid signing key: contains non-hex characters");
2371
+ }
2372
+ if (keyHex.length !== 64) {
2373
+ throw new Error(
2374
+ `Invalid signing key: expected 32 bytes (64 hex chars), got ${keyHex.length / 2} bytes`
2375
+ );
2376
+ }
2377
+ const privKey = secp256k1.etc.hexToBytes(keyHex);
2378
+ const randomBytes = crypto.getRandomValues(new Uint8Array(32));
2379
+ const nonceBytes = hashToField(randomBytes);
2380
+ const createdAt = Math.floor(Date.now() / 1e3);
2381
+ const expiresAt = createdAt + ttl;
2382
+ const message = computeRpSignatureMessage(nonceBytes, createdAt, expiresAt);
2383
+ const msgHash = sha3.keccak_256(message);
2384
+ const recSig = secp256k1.sign(msgHash, privKey);
2385
+ const compact = recSig.toCompactRawBytes();
2386
+ const sig65 = new Uint8Array(65);
2387
+ sig65.set(compact, 0);
2388
+ sig65[64] = recSig.recovery + 27;
2389
+ return {
2390
+ sig: "0x" + utils.bytesToHex(sig65),
2391
+ nonce: "0x" + utils.bytesToHex(nonceBytes),
2392
+ createdAt,
2393
+ expiresAt
2394
+ };
1971
2395
  }
1972
2396
 
1973
- exports.AppErrorCodes = AppErrorCodes;
1974
2397
  exports.CredentialRequest = CredentialRequest;
1975
2398
  exports.IDKit = IDKit;
1976
- exports.ResponseStatus = ResponseStatus;
1977
- exports.VerificationState = VerificationState;
2399
+ exports.IDKitErrorCodes = IDKitErrorCodes;
1978
2400
  exports.all = all;
1979
2401
  exports.any = any;
2402
+ exports.documentLegacy = documentLegacy;
2403
+ exports.hashSignal = hashSignal2;
1980
2404
  exports.isNode = isNode;
1981
2405
  exports.isReactNative = isReactNative;
1982
2406
  exports.isWeb = isWeb;
1983
- exports.orbLegacy = orbLegacy2;
2407
+ exports.orbLegacy = orbLegacy;
2408
+ exports.secureDocumentLegacy = secureDocumentLegacy;
1984
2409
  exports.signRequest = signRequest2;
1985
- //# sourceMappingURL=index.cjs.map
1986
- //# sourceMappingURL=index.cjs.map