@worldcoin/idkit-core 4.0.15 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,7 +16,10 @@ The RP signature authenticates your verification requests. Generate it server-si
16
16
  import { signRequest } from "@worldcoin/idkit-core/signing";
17
17
 
18
18
  // Never expose RP_SIGNING_KEY to clients
19
- const sig = signRequest("my-action", process.env.RP_SIGNING_KEY);
19
+ const sig = signRequest({
20
+ action: "my-action",
21
+ signingKeyHex: process.env.RP_SIGNING_KEY!,
22
+ });
20
23
 
21
24
  // Return to client
22
25
  res.json({
@@ -50,6 +53,7 @@ const request = await IDKit.request({
50
53
  signature: rpSig.sig,
51
54
  },
52
55
  allow_legacy_proofs: false,
56
+ return_to: "myapp://idkit/callback",
53
57
  }).preset(orbLegacy({ signal: "user-123" }));
54
58
 
55
59
  // Display QR code for World App
@@ -114,10 +118,10 @@ const { success } = await response.json();
114
118
 
115
119
  Pure JS subpath exports are available for server-side use without WASM initialization:
116
120
 
117
- | Subpath | Exports |
118
- | ---------- | ---------------------------------------------------------------- |
119
- | `/signing` | `signRequest`, `computeRpSignatureMessage`, `RpSignature` (type) |
120
- | `/hashing` | `hashSignal` |
121
+ | Subpath | Exports |
122
+ | ---------- | ----------------------------------------------------------------------------------------- |
123
+ | `/signing` | `signRequest`, `computeRpSignatureMessage`, `RpSignature` and `SignRequestParams` (types) |
124
+ | `/hashing` | `hashSignal` |
121
125
 
122
126
  ```typescript
123
127
  import { signRequest } from "@worldcoin/idkit-core/signing";
Binary file
package/dist/index.cjs CHANGED
@@ -6,9 +6,9 @@ var utils = require('@noble/hashes/utils');
6
6
 
7
7
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
8
8
  var __defProp = Object.defineProperty;
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
9
+ var __export = (target, all2) => {
10
+ for (var name in all2)
11
+ __defProp(target, name, { get: all2[name], enumerable: true });
12
12
  };
13
13
 
14
14
  // src/types/result.ts
@@ -422,10 +422,11 @@ var IDKitBuilder = class _IDKitBuilder {
422
422
  * @param {string | null} [action_description]
423
423
  * @param {string | null} [bridge_url]
424
424
  * @param {string | null} [override_connect_base_url]
425
+ * @param {string | null} [return_to]
425
426
  * @param {string | null} [environment]
426
427
  * @returns {IDKitBuilder}
427
428
  */
428
- static forCreateSession(app_id, rp_context, action_description, bridge_url, override_connect_base_url, environment) {
429
+ static forCreateSession(app_id, rp_context, action_description, bridge_url, override_connect_base_url, return_to, environment) {
429
430
  const ptr0 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
430
431
  const len0 = WASM_VECTOR_LEN;
431
432
  _assertClass(rp_context, RpContextWasm);
@@ -436,9 +437,11 @@ var IDKitBuilder = class _IDKitBuilder {
436
437
  var len3 = WASM_VECTOR_LEN;
437
438
  var ptr4 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
438
439
  var len4 = WASM_VECTOR_LEN;
439
- var ptr5 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
440
+ var ptr5 = isLikeNone(return_to) ? 0 : passStringToWasm0(return_to, wasm.__wbindgen_export, wasm.__wbindgen_export2);
440
441
  var len5 = WASM_VECTOR_LEN;
441
- const ret = wasm.idkitbuilder_forCreateSession(ptr0, len0, ptr1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
442
+ var ptr6 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
443
+ var len6 = WASM_VECTOR_LEN;
444
+ const ret = wasm.idkitbuilder_forCreateSession(ptr0, len0, ptr1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6);
442
445
  return _IDKitBuilder.__wrap(ret);
443
446
  }
444
447
  /**
@@ -449,10 +452,11 @@ var IDKitBuilder = class _IDKitBuilder {
449
452
  * @param {string | null} [action_description]
450
453
  * @param {string | null} [bridge_url]
451
454
  * @param {string | null} [override_connect_base_url]
455
+ * @param {string | null} [return_to]
452
456
  * @param {string | null} [environment]
453
457
  * @returns {IDKitBuilder}
454
458
  */
455
- static forProveSession(session_id, app_id, rp_context, action_description, bridge_url, override_connect_base_url, environment) {
459
+ static forProveSession(session_id, app_id, rp_context, action_description, bridge_url, override_connect_base_url, return_to, environment) {
456
460
  const ptr0 = passStringToWasm0(session_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
457
461
  const len0 = WASM_VECTOR_LEN;
458
462
  const ptr1 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
@@ -465,9 +469,11 @@ var IDKitBuilder = class _IDKitBuilder {
465
469
  var len4 = WASM_VECTOR_LEN;
466
470
  var ptr5 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
467
471
  var len5 = WASM_VECTOR_LEN;
468
- var ptr6 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
472
+ var ptr6 = isLikeNone(return_to) ? 0 : passStringToWasm0(return_to, wasm.__wbindgen_export, wasm.__wbindgen_export2);
469
473
  var len6 = WASM_VECTOR_LEN;
470
- const ret = wasm.idkitbuilder_forProveSession(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6);
474
+ var ptr7 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
475
+ var len7 = WASM_VECTOR_LEN;
476
+ const ret = wasm.idkitbuilder_forProveSession(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6, ptr7, len7);
471
477
  return _IDKitBuilder.__wrap(ret);
472
478
  }
473
479
  /**
@@ -530,8 +536,8 @@ var IDKitBuilder = class _IDKitBuilder {
530
536
  * Builds a v1 (legacy) native payload from a preset (synchronous, no bridge connection).
531
537
  *
532
538
  * Used by the native transport when the World App only supports verify v1.
533
- * Only legacy presets produce valid v1 payloads (constraints always have
534
- * `Deprecated` verification level and will fail).
539
+ * Only legacy presets produce valid v1 payloads (constraint-based requests
540
+ * default to `Device` level and may not carry the correct action).
535
541
  *
536
542
  * # Errors
537
543
  *
@@ -564,9 +570,10 @@ var IDKitBuilder = class _IDKitBuilder {
564
570
  * @param {string | null | undefined} bridge_url
565
571
  * @param {boolean} allow_legacy_proofs
566
572
  * @param {string | null} [override_connect_base_url]
573
+ * @param {string | null} [return_to]
567
574
  * @param {string | null} [environment]
568
575
  */
569
- constructor(app_id, action, rp_context, action_description, bridge_url, allow_legacy_proofs, override_connect_base_url, environment) {
576
+ constructor(app_id, action, rp_context, action_description, bridge_url, allow_legacy_proofs, override_connect_base_url, return_to, environment) {
570
577
  const ptr0 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
571
578
  const len0 = WASM_VECTOR_LEN;
572
579
  const ptr1 = passStringToWasm0(action, wasm.__wbindgen_export, wasm.__wbindgen_export2);
@@ -579,9 +586,11 @@ var IDKitBuilder = class _IDKitBuilder {
579
586
  var len4 = WASM_VECTOR_LEN;
580
587
  var ptr5 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
581
588
  var len5 = WASM_VECTOR_LEN;
582
- var ptr6 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
589
+ var ptr6 = isLikeNone(return_to) ? 0 : passStringToWasm0(return_to, wasm.__wbindgen_export, wasm.__wbindgen_export2);
583
590
  var len6 = WASM_VECTOR_LEN;
584
- const ret = wasm.idkitbuilder_new(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, allow_legacy_proofs, ptr5, len5, ptr6, len6);
591
+ var ptr7 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
592
+ var len7 = WASM_VECTOR_LEN;
593
+ const ret = wasm.idkitbuilder_new(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, allow_legacy_proofs, ptr5, len5, ptr6, len6, ptr7, len7);
585
594
  this.__wbg_ptr = ret >>> 0;
586
595
  IDKitBuilderFinalization.register(this, this.__wbg_ptr, this);
587
596
  return this;
@@ -966,12 +975,14 @@ function base64Encode(data) {
966
975
  wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
967
976
  }
968
977
  }
969
- function computeRpSignatureMessage(nonce, created_at, expires_at) {
978
+ function computeRpSignatureMessage(nonce, created_at, expires_at, action) {
970
979
  try {
971
980
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
972
981
  const ptr0 = passStringToWasm0(nonce, wasm.__wbindgen_export, wasm.__wbindgen_export2);
973
982
  const len0 = WASM_VECTOR_LEN;
974
- wasm.computeRpSignatureMessage(retptr, ptr0, len0, created_at, expires_at);
983
+ var ptr1 = isLikeNone(action) ? 0 : passStringToWasm0(action, wasm.__wbindgen_export, wasm.__wbindgen_export2);
984
+ var len1 = WASM_VECTOR_LEN;
985
+ wasm.computeRpSignatureMessage(retptr, ptr0, len0, created_at, expires_at, ptr1, len1);
975
986
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
976
987
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
977
988
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -979,14 +990,14 @@ function computeRpSignatureMessage(nonce, created_at, expires_at) {
979
990
  if (r3) {
980
991
  throw takeObject(r2);
981
992
  }
982
- var v2 = getArrayU8FromWasm0(r0, r1).slice();
993
+ var v3 = getArrayU8FromWasm0(r0, r1).slice();
983
994
  wasm.__wbindgen_export4(r0, r1 * 1, 1);
984
- return v2;
995
+ return v3;
985
996
  } finally {
986
997
  wasm.__wbindgen_add_to_stack_pointer(16);
987
998
  }
988
999
  }
989
- function createSession(app_id, rp_context, action_description, bridge_url, override_connect_base_url, environment) {
1000
+ function createSession(app_id, rp_context, action_description, bridge_url, override_connect_base_url, return_to, environment) {
990
1001
  const ptr0 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
991
1002
  const len0 = WASM_VECTOR_LEN;
992
1003
  _assertClass(rp_context, RpContextWasm);
@@ -997,9 +1008,11 @@ function createSession(app_id, rp_context, action_description, bridge_url, overr
997
1008
  var len3 = WASM_VECTOR_LEN;
998
1009
  var ptr4 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
999
1010
  var len4 = WASM_VECTOR_LEN;
1000
- var ptr5 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1011
+ var ptr5 = isLikeNone(return_to) ? 0 : passStringToWasm0(return_to, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1001
1012
  var len5 = WASM_VECTOR_LEN;
1002
- const ret = wasm.createSession(ptr0, len0, ptr1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
1013
+ var ptr6 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1014
+ var len6 = WASM_VECTOR_LEN;
1015
+ const ret = wasm.createSession(ptr0, len0, ptr1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6);
1003
1016
  return IDKitBuilder.__wrap(ret);
1004
1017
  }
1005
1018
  function hashSignal(signal) {
@@ -1030,7 +1043,7 @@ function hashSignal(signal) {
1030
1043
  function init_wasm() {
1031
1044
  wasm.init_wasm();
1032
1045
  }
1033
- function proveSession(session_id, app_id, rp_context, action_description, bridge_url, override_connect_base_url, environment) {
1046
+ function proveSession(session_id, app_id, rp_context, action_description, bridge_url, override_connect_base_url, return_to, environment) {
1034
1047
  const ptr0 = passStringToWasm0(session_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1035
1048
  const len0 = WASM_VECTOR_LEN;
1036
1049
  const ptr1 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
@@ -1043,12 +1056,14 @@ function proveSession(session_id, app_id, rp_context, action_description, bridge
1043
1056
  var len4 = WASM_VECTOR_LEN;
1044
1057
  var ptr5 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1045
1058
  var len5 = WASM_VECTOR_LEN;
1046
- var ptr6 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1059
+ var ptr6 = isLikeNone(return_to) ? 0 : passStringToWasm0(return_to, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1047
1060
  var len6 = WASM_VECTOR_LEN;
1048
- const ret = wasm.proveSession(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6);
1061
+ var ptr7 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1062
+ var len7 = WASM_VECTOR_LEN;
1063
+ const ret = wasm.proveSession(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6, ptr7, len7);
1049
1064
  return IDKitBuilder.__wrap(ret);
1050
1065
  }
1051
- function request(app_id, action, rp_context, action_description, bridge_url, allow_legacy_proofs, override_connect_base_url, environment) {
1066
+ function request(app_id, action, rp_context, action_description, bridge_url, allow_legacy_proofs, override_connect_base_url, return_to, environment) {
1052
1067
  const ptr0 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1053
1068
  const len0 = WASM_VECTOR_LEN;
1054
1069
  const ptr1 = passStringToWasm0(action, wasm.__wbindgen_export, wasm.__wbindgen_export2);
@@ -1061,17 +1076,21 @@ function request(app_id, action, rp_context, action_description, bridge_url, all
1061
1076
  var len4 = WASM_VECTOR_LEN;
1062
1077
  var ptr5 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1063
1078
  var len5 = WASM_VECTOR_LEN;
1064
- var ptr6 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1079
+ var ptr6 = isLikeNone(return_to) ? 0 : passStringToWasm0(return_to, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1065
1080
  var len6 = WASM_VECTOR_LEN;
1066
- const ret = wasm.request(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, allow_legacy_proofs, ptr5, len5, ptr6, len6);
1081
+ var ptr7 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1082
+ var len7 = WASM_VECTOR_LEN;
1083
+ const ret = wasm.request(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, allow_legacy_proofs, ptr5, len5, ptr6, len6, ptr7, len7);
1067
1084
  return IDKitBuilder.__wrap(ret);
1068
1085
  }
1069
- function signRequest(signing_key_hex, ttl_seconds) {
1086
+ function signRequest(signing_key_hex, ttl_seconds, action) {
1070
1087
  try {
1071
1088
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1072
1089
  const ptr0 = passStringToWasm0(signing_key_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1073
1090
  const len0 = WASM_VECTOR_LEN;
1074
- wasm.signRequest(retptr, ptr0, len0, !isLikeNone(ttl_seconds), isLikeNone(ttl_seconds) ? BigInt(0) : ttl_seconds);
1091
+ var ptr1 = isLikeNone(action) ? 0 : passStringToWasm0(action, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1092
+ var len1 = WASM_VECTOR_LEN;
1093
+ wasm.signRequest(retptr, ptr0, len0, !isLikeNone(ttl_seconds), isLikeNone(ttl_seconds) ? BigInt(0) : ttl_seconds, ptr1, len1);
1075
1094
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1076
1095
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1077
1096
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -1377,7 +1396,7 @@ function __wbg_get_imports() {
1377
1396
  const a = state0.a;
1378
1397
  state0.a = 0;
1379
1398
  try {
1380
- return __wasm_bindgen_func_elem_1382(a, state0.b, arg02, arg12);
1399
+ return __wasm_bindgen_func_elem_1423(a, state0.b, arg02, arg12);
1381
1400
  } finally {
1382
1401
  state0.a = a;
1383
1402
  }
@@ -1557,11 +1576,11 @@ function __wbg_get_imports() {
1557
1576
  return addHeapObject(ret);
1558
1577
  },
1559
1578
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
1560
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_632, __wasm_bindgen_func_elem_633);
1579
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_645, __wasm_bindgen_func_elem_646);
1561
1580
  return addHeapObject(ret);
1562
1581
  },
1563
1582
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
1564
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_962, __wasm_bindgen_func_elem_963);
1583
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_975, __wasm_bindgen_func_elem_976);
1565
1584
  return addHeapObject(ret);
1566
1585
  },
1567
1586
  __wbindgen_cast_0000000000000003: function(arg0) {
@@ -1597,13 +1616,13 @@ function __wbg_get_imports() {
1597
1616
  "./idkit_wasm_bg.js": import0
1598
1617
  };
1599
1618
  }
1600
- function __wasm_bindgen_func_elem_633(arg0, arg1) {
1601
- wasm.__wasm_bindgen_func_elem_633(arg0, arg1);
1619
+ function __wasm_bindgen_func_elem_646(arg0, arg1) {
1620
+ wasm.__wasm_bindgen_func_elem_646(arg0, arg1);
1602
1621
  }
1603
- function __wasm_bindgen_func_elem_963(arg0, arg1, arg2) {
1622
+ function __wasm_bindgen_func_elem_976(arg0, arg1, arg2) {
1604
1623
  try {
1605
1624
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1606
- wasm.__wasm_bindgen_func_elem_963(retptr, arg0, arg1, addHeapObject(arg2));
1625
+ wasm.__wasm_bindgen_func_elem_976(retptr, arg0, arg1, addHeapObject(arg2));
1607
1626
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1608
1627
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1609
1628
  if (r1) {
@@ -1613,8 +1632,8 @@ function __wasm_bindgen_func_elem_963(arg0, arg1, arg2) {
1613
1632
  wasm.__wbindgen_add_to_stack_pointer(16);
1614
1633
  }
1615
1634
  }
1616
- function __wasm_bindgen_func_elem_1382(arg0, arg1, arg2, arg3) {
1617
- wasm.__wasm_bindgen_func_elem_1382(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1635
+ function __wasm_bindgen_func_elem_1423(arg0, arg1, arg2, arg3) {
1636
+ wasm.__wasm_bindgen_func_elem_1423(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1618
1637
  }
1619
1638
  var __wbindgen_enum_RequestCache = ["default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached"];
1620
1639
  var __wbindgen_enum_RequestCredentials = ["omit", "same-origin", "include"];
@@ -1943,6 +1962,16 @@ async function initIDKit() {
1943
1962
  return wasmInitPromise;
1944
1963
  }
1945
1964
 
1965
+ // src/lib/debug.ts
1966
+ var _debug = false;
1967
+ function isDebug() {
1968
+ if (_debug) return true;
1969
+ return typeof window !== "undefined" && Boolean(window.IDKIT_DEBUG);
1970
+ }
1971
+ function setDebug(enabled) {
1972
+ _debug = enabled;
1973
+ }
1974
+
1946
1975
  // src/transports/native.ts
1947
1976
  var MINIAPP_VERIFY_ACTION = "miniapp-verify-action";
1948
1977
  function isInWorldApp() {
@@ -1958,9 +1987,10 @@ var _requestCounter = 0;
1958
1987
  var _activeNativeRequest = null;
1959
1988
  function createNativeRequest(wasmPayload, config, signalHashes = {}, legacySignalHash, version = 2) {
1960
1989
  if (_activeNativeRequest?.isPending()) {
1961
- console.warn(
1962
- "IDKit native request already in flight. Reusing active request."
1963
- );
1990
+ if (isDebug())
1991
+ console.warn(
1992
+ "[IDKit] Native: request already in flight, reusing active request"
1993
+ );
1964
1994
  return _activeNativeRequest;
1965
1995
  }
1966
1996
  const request2 = new NativeIDKitRequest(
@@ -1987,6 +2017,11 @@ var NativeIDKitRequest = class {
1987
2017
  const handleIncomingPayload = (responsePayload) => {
1988
2018
  if (this.completionResult) return;
1989
2019
  if (responsePayload?.status === "error") {
2020
+ if (isDebug())
2021
+ console.warn(
2022
+ "[IDKit] Native: received error response",
2023
+ responsePayload.error_code
2024
+ );
1990
2025
  this.complete({
1991
2026
  success: false,
1992
2027
  error: responsePayload.error_code ?? "generic_error" /* GenericError */
@@ -2020,7 +2055,9 @@ var NativeIDKitRequest = class {
2020
2055
  this.miniKitHandler = miniKitHandler;
2021
2056
  miniKit.subscribe(MINIAPP_VERIFY_ACTION, miniKitHandler);
2022
2057
  }
2023
- } catch {
2058
+ } catch (err) {
2059
+ if (isDebug())
2060
+ console.warn("[IDKit] Native: MiniKit subscribe failed", err);
2024
2061
  }
2025
2062
  const sendPayload = {
2026
2063
  command: "verify",
@@ -2030,16 +2067,29 @@ var NativeIDKitRequest = class {
2030
2067
  try {
2031
2068
  const w = window;
2032
2069
  if (w.webkit?.messageHandlers?.minikit) {
2070
+ if (isDebug())
2071
+ console.debug(
2072
+ `[IDKit] Native: sending verify command (version=${version}, platform=ios)`
2073
+ );
2033
2074
  w.webkit.messageHandlers.minikit.postMessage(sendPayload);
2034
2075
  } else if (w.Android) {
2076
+ if (isDebug())
2077
+ console.debug(
2078
+ `[IDKit] Native: sending verify command (version=${version}, platform=android)`
2079
+ );
2035
2080
  w.Android.postMessage(JSON.stringify(sendPayload));
2036
2081
  } else {
2082
+ if (isDebug())
2083
+ console.warn(
2084
+ "[IDKit] Native: no native bridge found (no webkit/Android)"
2085
+ );
2037
2086
  this.complete({
2038
2087
  success: false,
2039
2088
  error: "generic_error" /* GenericError */
2040
2089
  });
2041
2090
  }
2042
- } catch {
2091
+ } catch (err) {
2092
+ if (isDebug()) console.warn("[IDKit] Native: postMessage failed", err);
2043
2093
  this.complete({
2044
2094
  success: false,
2045
2095
  error: "generic_error" /* GenericError */
@@ -2050,6 +2100,11 @@ var NativeIDKitRequest = class {
2050
2100
  // Single entry point for finishing the request. Idempotent — first caller wins.
2051
2101
  complete(result) {
2052
2102
  if (this.completionResult) return;
2103
+ if (isDebug())
2104
+ console.debug(
2105
+ "[IDKit] Native: request completed",
2106
+ result.success ? "success" : `error=${result.error}`
2107
+ );
2053
2108
  this.completionResult = result;
2054
2109
  this.cleanup();
2055
2110
  this.resolveFn?.(result);
@@ -2069,7 +2124,9 @@ var NativeIDKitRequest = class {
2069
2124
  try {
2070
2125
  const miniKit = window.MiniKit;
2071
2126
  miniKit?.unsubscribe?.(MINIAPP_VERIFY_ACTION);
2072
- } catch {
2127
+ } catch (err) {
2128
+ if (isDebug())
2129
+ console.warn("[IDKit] Native: MiniKit unsubscribe failed", err);
2073
2130
  }
2074
2131
  this.miniKitHandler = null;
2075
2132
  }
@@ -2087,7 +2144,7 @@ var NativeIDKitRequest = class {
2087
2144
  return { type: "failed", error: this.completionResult.error };
2088
2145
  }
2089
2146
  async pollUntilCompletion(options) {
2090
- const timeout = options?.timeout ?? 3e5;
2147
+ const timeout = options?.timeout ?? 9e5;
2091
2148
  const timeoutId = setTimeout(() => {
2092
2149
  this.complete({ success: false, error: "timeout" /* Timeout */ });
2093
2150
  }, timeout);
@@ -2120,14 +2177,15 @@ var NativeIDKitRequest = class {
2120
2177
  function nativeResultToIDKitResult(payload, config, signalHashes, legacySignalHash) {
2121
2178
  const p = payload;
2122
2179
  const rpNonce = config.rp_context?.nonce ?? "";
2123
- if ("responses" in p && Array.isArray(p.responses)) {
2124
- const items = p.responses;
2125
- if (p.session_id) {
2180
+ if ("proof_response" in p && p.proof_response != null) {
2181
+ const proof_response = p.proof_response;
2182
+ const items = proof_response.responses ?? [];
2183
+ if (proof_response.session_id) {
2126
2184
  return {
2127
2185
  protocol_version: "4.0",
2128
- nonce: p.nonce ?? rpNonce,
2129
- action_description: p.action_description,
2130
- session_id: p.session_id,
2186
+ nonce: proof_response.nonce ?? rpNonce,
2187
+ action_description: proof_response.action_description,
2188
+ session_id: proof_response.session_id,
2131
2189
  responses: items.map((item) => ({
2132
2190
  identifier: item.identifier,
2133
2191
  signal_hash: signalHashes[item.identifier],
@@ -2141,9 +2199,9 @@ function nativeResultToIDKitResult(payload, config, signalHashes, legacySignalHa
2141
2199
  }
2142
2200
  return {
2143
2201
  protocol_version: "4.0",
2144
- nonce: p.nonce ?? rpNonce,
2145
- action: p.action ?? config.action ?? "",
2146
- action_description: p.action_description,
2202
+ nonce: proof_response.nonce ?? rpNonce,
2203
+ action: proof_response.action ?? config.action ?? "",
2204
+ action_description: proof_response.action_description,
2147
2205
  responses: items.map((item) => ({
2148
2206
  identifier: item.identifier,
2149
2207
  signal_hash: signalHashes[item.identifier],
@@ -2189,6 +2247,7 @@ function nativeResultToIDKitResult(payload, config, signalHashes, legacySignalHa
2189
2247
  }
2190
2248
 
2191
2249
  // src/request.ts
2250
+ var SESSION_ID_PATTERN = /^session_[0-9a-fA-F]{128}$/;
2192
2251
  var IDKitRequestImpl = class {
2193
2252
  constructor(wasmRequest) {
2194
2253
  this.wasmRequest = wasmRequest;
@@ -2206,7 +2265,7 @@ var IDKitRequestImpl = class {
2206
2265
  }
2207
2266
  async pollUntilCompletion(options) {
2208
2267
  const pollInterval = options?.pollInterval ?? 1e3;
2209
- const timeout = options?.timeout ?? 3e5;
2268
+ const timeout = options?.timeout ?? 9e5;
2210
2269
  const startTime = Date.now();
2211
2270
  while (true) {
2212
2271
  if (options?.signal?.aborted) {
@@ -2229,6 +2288,23 @@ var IDKitRequestImpl = class {
2229
2288
  }
2230
2289
  }
2231
2290
  };
2291
+ function CredentialRequest(credential_type, options) {
2292
+ return {
2293
+ type: credential_type,
2294
+ signal: options?.signal,
2295
+ genesis_issued_at_min: options?.genesis_issued_at_min,
2296
+ expires_at_min: options?.expires_at_min
2297
+ };
2298
+ }
2299
+ function any(...nodes) {
2300
+ return { any: nodes };
2301
+ }
2302
+ function all(...nodes) {
2303
+ return { all: nodes };
2304
+ }
2305
+ function enumerate(...nodes) {
2306
+ return { enumerate: nodes };
2307
+ }
2232
2308
  function orbLegacy(opts = {}) {
2233
2309
  return { type: "OrbLegacy", signal: opts.signal };
2234
2310
  }
@@ -2264,6 +2340,7 @@ function createWasmBuilderFromConfig(config) {
2264
2340
  config.bridge_url ?? null,
2265
2341
  config.allow_legacy_proofs ?? false,
2266
2342
  config.override_connect_base_url ?? null,
2343
+ config.return_to ?? null,
2267
2344
  config.environment ?? null
2268
2345
  );
2269
2346
  }
@@ -2275,6 +2352,7 @@ function createWasmBuilderFromConfig(config) {
2275
2352
  config.action_description ?? null,
2276
2353
  config.bridge_url ?? null,
2277
2354
  config.override_connect_base_url ?? null,
2355
+ config.return_to ?? null,
2278
2356
  config.environment ?? null
2279
2357
  );
2280
2358
  }
@@ -2284,6 +2362,7 @@ function createWasmBuilderFromConfig(config) {
2284
2362
  config.action_description ?? null,
2285
2363
  config.bridge_url ?? null,
2286
2364
  config.override_connect_base_url ?? null,
2365
+ config.return_to ?? null,
2287
2366
  config.environment ?? null
2288
2367
  );
2289
2368
  }
@@ -2318,7 +2397,7 @@ var IDKitBuilder2 = class {
2318
2397
  wasmResult.payload,
2319
2398
  this.config,
2320
2399
  wasmResult.signal_hashes ?? {},
2321
- wasmResult.legacy_signal_hash ?? void 0,
2400
+ wasmResult.legacy_signal_hash,
2322
2401
  2
2323
2402
  );
2324
2403
  }
@@ -2344,6 +2423,11 @@ var IDKitBuilder2 = class {
2344
2423
  * ```
2345
2424
  */
2346
2425
  async preset(preset) {
2426
+ if (this.config.type === "createSession" || this.config.type === "proveSession") {
2427
+ throw new Error(
2428
+ "Presets are not supported for session flows. Use .constraints() instead."
2429
+ );
2430
+ }
2347
2431
  await initIDKit();
2348
2432
  if (isInWorldApp()) {
2349
2433
  const verifyVersion = getWorldAppVerifyVersion();
@@ -2354,7 +2438,7 @@ var IDKitBuilder2 = class {
2354
2438
  wasmResult.payload,
2355
2439
  this.config,
2356
2440
  wasmResult.signal_hashes ?? {},
2357
- wasmResult.legacy_signal_hash ?? void 0,
2441
+ wasmResult.legacy_signal_hash,
2358
2442
  2
2359
2443
  );
2360
2444
  }
@@ -2365,7 +2449,7 @@ var IDKitBuilder2 = class {
2365
2449
  wasmResult.payload,
2366
2450
  this.config,
2367
2451
  wasmResult.signal_hashes ?? {},
2368
- wasmResult.legacy_signal_hash ?? void 0,
2452
+ wasmResult.legacy_signal_hash,
2369
2453
  1
2370
2454
  );
2371
2455
  } catch (err) {
@@ -2408,27 +2492,76 @@ function createRequest(config) {
2408
2492
  rp_context: config.rp_context,
2409
2493
  action_description: config.action_description,
2410
2494
  bridge_url: config.bridge_url,
2495
+ return_to: config.return_to,
2411
2496
  allow_legacy_proofs: config.allow_legacy_proofs,
2412
2497
  override_connect_base_url: config.override_connect_base_url,
2413
2498
  environment: config.environment
2414
2499
  });
2415
2500
  }
2501
+ function createSession2(config) {
2502
+ if (!config.app_id) {
2503
+ throw new Error("app_id is required");
2504
+ }
2505
+ if (!config.rp_context) {
2506
+ throw new Error(
2507
+ "rp_context is required. Generate it on your backend using signRequest()."
2508
+ );
2509
+ }
2510
+ return new IDKitBuilder2({
2511
+ type: "createSession",
2512
+ app_id: config.app_id,
2513
+ rp_context: config.rp_context,
2514
+ action_description: config.action_description,
2515
+ bridge_url: config.bridge_url,
2516
+ return_to: config.return_to,
2517
+ override_connect_base_url: config.override_connect_base_url,
2518
+ environment: config.environment
2519
+ });
2520
+ }
2521
+ function proveSession2(sessionId, config) {
2522
+ if (!sessionId) {
2523
+ throw new Error("session_id is required");
2524
+ }
2525
+ if (!SESSION_ID_PATTERN.test(sessionId)) {
2526
+ throw new Error(
2527
+ "session_id must be in the format session_<128 hex characters>"
2528
+ );
2529
+ }
2530
+ if (!config.app_id) {
2531
+ throw new Error("app_id is required");
2532
+ }
2533
+ if (!config.rp_context) {
2534
+ throw new Error(
2535
+ "rp_context is required. Generate it on your backend using signRequest()."
2536
+ );
2537
+ }
2538
+ return new IDKitBuilder2({
2539
+ type: "proveSession",
2540
+ session_id: sessionId,
2541
+ app_id: config.app_id,
2542
+ rp_context: config.rp_context,
2543
+ action_description: config.action_description,
2544
+ bridge_url: config.bridge_url,
2545
+ return_to: config.return_to,
2546
+ override_connect_base_url: config.override_connect_base_url,
2547
+ environment: config.environment
2548
+ });
2549
+ }
2416
2550
  var IDKit = {
2417
2551
  /** Create a new verification request */
2418
2552
  request: createRequest,
2419
- // TODO: Re-enable when World ID 4.0 is live
2420
- // /** Create a new session (no action, no existing session_id) */
2421
- // createSession,
2422
- // /** Prove an existing session (no action, has session_id) */
2423
- // proveSession,
2424
- // /** Create a CredentialRequest for a credential type */
2425
- // CredentialRequest,
2426
- // /** Create an OR constraint - at least one child must be satisfied */
2427
- // any,
2428
- // /** Create an AND constraint - all children must be satisfied */
2429
- // all,
2430
- // /** Create an enumerate constraint - all satisfiable children should be selected */
2431
- // enumerate,
2553
+ /** Create a new session (no action, no existing session_id) */
2554
+ createSession: createSession2,
2555
+ /** Prove an existing session (no action, has session_id) */
2556
+ proveSession: proveSession2,
2557
+ /** Create a CredentialRequest for a credential type */
2558
+ CredentialRequest,
2559
+ /** Create an OR constraint - at least one child must be satisfied */
2560
+ any,
2561
+ /** Create an AND constraint - all children must be satisfied */
2562
+ all,
2563
+ /** Create an enumerate constraint - all satisfiable children should be selected */
2564
+ enumerate,
2432
2565
  /** Create an OrbLegacy preset for World ID 3.0 legacy support */
2433
2566
  orbLegacy,
2434
2567
  /** Create a SecureDocumentLegacy preset for World ID 3.0 legacy support */
@@ -2476,11 +2609,16 @@ Object.defineProperty(exports, "signRequest", {
2476
2609
  enumerable: true,
2477
2610
  get: function () { return idkitServer.signRequest; }
2478
2611
  });
2612
+ exports.CredentialRequest = CredentialRequest;
2479
2613
  exports.IDKit = IDKit;
2480
2614
  exports.IDKitErrorCodes = IDKitErrorCodes;
2615
+ exports.all = all;
2616
+ exports.any = any;
2481
2617
  exports.deviceLegacy = deviceLegacy;
2482
2618
  exports.documentLegacy = documentLegacy;
2619
+ exports.enumerate = enumerate;
2483
2620
  exports.hashSignal = hashSignal2;
2621
+ exports.isDebug = isDebug;
2484
2622
  exports.isInWorldApp = isInWorldApp;
2485
2623
  exports.isNode = isNode;
2486
2624
  exports.isReactNative = isReactNative;
@@ -2488,3 +2626,4 @@ exports.isWeb = isWeb;
2488
2626
  exports.orbLegacy = orbLegacy;
2489
2627
  exports.secureDocumentLegacy = secureDocumentLegacy;
2490
2628
  exports.selfieCheckLegacy = selfieCheckLegacy;
2629
+ exports.setDebug = setDebug;