@worldcoin/idkit-core 4.1.3 → 4.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
package/dist/index.cjs CHANGED
@@ -16,6 +16,8 @@ var IDKitErrorCodes = /* @__PURE__ */ ((IDKitErrorCodes2) => {
16
16
  IDKitErrorCodes2["UserRejected"] = "user_rejected";
17
17
  IDKitErrorCodes2["VerificationRejected"] = "verification_rejected";
18
18
  IDKitErrorCodes2["CredentialUnavailable"] = "credential_unavailable";
19
+ IDKitErrorCodes2["WorldId4NotAvailable"] = "world_id_4_not_available";
20
+ IDKitErrorCodes2["WorldId3NotAvailable"] = "world_id_3_not_available";
19
21
  IDKitErrorCodes2["MalformedRequest"] = "malformed_request";
20
22
  IDKitErrorCodes2["InvalidNetwork"] = "invalid_network";
21
23
  IDKitErrorCodes2["InclusionProofPending"] = "inclusion_proof_pending";
@@ -24,7 +26,18 @@ var IDKitErrorCodes = /* @__PURE__ */ ((IDKitErrorCodes2) => {
24
26
  IDKitErrorCodes2["ConnectionFailed"] = "connection_failed";
25
27
  IDKitErrorCodes2["MaxVerificationsReached"] = "max_verifications_reached";
26
28
  IDKitErrorCodes2["FailedByHostApp"] = "failed_by_host_app";
29
+ IDKitErrorCodes2["InvalidRpSignature"] = "invalid_rp_signature";
30
+ IDKitErrorCodes2["NullifierReplayed"] = "nullifier_replayed";
31
+ IDKitErrorCodes2["DuplicateNonce"] = "duplicate_nonce";
32
+ IDKitErrorCodes2["UnknownRp"] = "unknown_rp";
33
+ IDKitErrorCodes2["InactiveRp"] = "inactive_rp";
34
+ IDKitErrorCodes2["TimestampTooOld"] = "timestamp_too_old";
35
+ IDKitErrorCodes2["TimestampTooFarInFuture"] = "timestamp_too_far_in_future";
36
+ IDKitErrorCodes2["InvalidTimestamp"] = "invalid_timestamp";
37
+ IDKitErrorCodes2["RpSignatureExpired"] = "rp_signature_expired";
38
+ IDKitErrorCodes2["IdentityAttributesNotMatched"] = "identity_attributes_not_matched";
27
39
  IDKitErrorCodes2["GenericError"] = "generic_error";
40
+ IDKitErrorCodes2["InvalidRpIdFormat"] = "invalid_rp_id_format";
28
41
  IDKitErrorCodes2["Timeout"] = "timeout";
29
42
  IDKitErrorCodes2["Cancelled"] = "cancelled";
30
43
  return IDKitErrorCodes2;
@@ -36,6 +49,7 @@ __export(idkit_wasm_exports, {
36
49
  BridgeEncryption: () => BridgeEncryption,
37
50
  CredentialRequestWasm: () => CredentialRequestWasm,
38
51
  IDKitBuilder: () => IDKitBuilder,
52
+ IDKitInviteCodeRequest: () => IDKitInviteCodeRequest,
39
53
  IDKitProof: () => IDKitProof,
40
54
  IDKitRequest: () => IDKitRequest,
41
55
  RpContextWasm: () => RpContextWasm,
@@ -48,6 +62,7 @@ __export(idkit_wasm_exports, {
48
62
  hashSignal: () => hashSignal,
49
63
  initSync: () => initSync,
50
64
  init_wasm: () => init_wasm,
65
+ proofResponseToIDKitResult: () => proofResponseToIDKitResult,
51
66
  proveSession: () => proveSession,
52
67
  request: () => request,
53
68
  signRequest: () => signRequest
@@ -415,6 +430,16 @@ var IDKitBuilder = class _IDKitBuilder {
415
430
  const ret = wasm.idkitbuilder_constraints(ptr, addHeapObject(constraints_json));
416
431
  return takeObject(ret);
417
432
  }
433
+ /**
434
+ * Creates an invite-code mode `BridgeConnection` with the given constraints (WDP-73).
435
+ * @param {any} constraints_json
436
+ * @returns {Promise<any>}
437
+ */
438
+ constraintsWithInviteCode(constraints_json) {
439
+ const ptr = this.__destroy_into_raw();
440
+ const ret = wasm.idkitbuilder_constraintsWithInviteCode(ptr, addHeapObject(constraints_json));
441
+ return takeObject(ret);
442
+ }
418
443
  /**
419
444
  * Creates a new builder for creating a new session
420
445
  * @param {string} app_id
@@ -605,8 +630,147 @@ var IDKitBuilder = class _IDKitBuilder {
605
630
  const ret = wasm.idkitbuilder_preset(ptr, addHeapObject(preset_json));
606
631
  return takeObject(ret);
607
632
  }
633
+ /**
634
+ * Creates an invite-code mode `BridgeConnection` from a preset (WDP-73).
635
+ * @param {any} preset_json
636
+ * @returns {Promise<any>}
637
+ */
638
+ presetWithInviteCode(preset_json) {
639
+ const ptr = this.__destroy_into_raw();
640
+ const ret = wasm.idkitbuilder_presetWithInviteCode(ptr, addHeapObject(preset_json));
641
+ return takeObject(ret);
642
+ }
608
643
  };
609
644
  if (Symbol.dispose) IDKitBuilder.prototype[Symbol.dispose] = IDKitBuilder.prototype.free;
645
+ var IDKitInviteCodeRequest = class _IDKitInviteCodeRequest {
646
+ static __wrap(ptr) {
647
+ ptr = ptr >>> 0;
648
+ const obj = Object.create(_IDKitInviteCodeRequest.prototype);
649
+ obj.__wbg_ptr = ptr;
650
+ IDKitInviteCodeRequestFinalization.register(obj, obj.__wbg_ptr, obj);
651
+ return obj;
652
+ }
653
+ __destroy_into_raw() {
654
+ const ptr = this.__wbg_ptr;
655
+ this.__wbg_ptr = 0;
656
+ IDKitInviteCodeRequestFinalization.unregister(this);
657
+ return ptr;
658
+ }
659
+ free() {
660
+ const ptr = this.__destroy_into_raw();
661
+ wasm.__wbg_idkitinvitecoderequest_free(ptr, 0);
662
+ }
663
+ /**
664
+ * Returns the connector URL the RP should display to the user.
665
+ *
666
+ * This is the same URL shape the URL/QR mode produces, with two extra
667
+ * query params (`c=<canonical_code>`, `a=<app_id>`) the `world.org/verify`
668
+ * landing page uses to render an invite-code-aware view.
669
+ *
670
+ * # Errors
671
+ *
672
+ * Returns an error if the request has been closed.
673
+ * @returns {string}
674
+ */
675
+ connectUrl() {
676
+ let deferred2_0;
677
+ let deferred2_1;
678
+ try {
679
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
680
+ wasm.idkitinvitecoderequest_connectUrl(retptr, this.__wbg_ptr);
681
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
682
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
683
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
684
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
685
+ var ptr1 = r0;
686
+ var len1 = r1;
687
+ if (r3) {
688
+ ptr1 = 0;
689
+ len1 = 0;
690
+ throw takeObject(r2);
691
+ }
692
+ deferred2_0 = ptr1;
693
+ deferred2_1 = len1;
694
+ return getStringFromWasm0(ptr1, len1);
695
+ } finally {
696
+ wasm.__wbindgen_add_to_stack_pointer(16);
697
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
698
+ }
699
+ }
700
+ /**
701
+ * Unix-seconds expiry of the unredeemed code.
702
+ *
703
+ * # Errors
704
+ *
705
+ * Returns an error if the request has been closed.
706
+ * @returns {number}
707
+ */
708
+ expiresAt() {
709
+ try {
710
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
711
+ wasm.idkitinvitecoderequest_expiresAt(retptr, this.__wbg_ptr);
712
+ var r0 = getDataViewMemory0().getFloat64(retptr + 8 * 0, true);
713
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
714
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
715
+ if (r3) {
716
+ throw takeObject(r2);
717
+ }
718
+ return r0;
719
+ } finally {
720
+ wasm.__wbindgen_add_to_stack_pointer(16);
721
+ }
722
+ }
723
+ /**
724
+ * Polls the bridge for the current status (non-blocking).
725
+ *
726
+ * Mirrors `IDKitRequest::pollForStatus` exactly — same status shape,
727
+ * same close semantics. Adopters use the same poll loop they wrote for
728
+ * URL mode.
729
+ *
730
+ * # Errors
731
+ *
732
+ * Returns an error if the request has been closed or the poll fails.
733
+ * @returns {Promise<any>}
734
+ */
735
+ pollForStatus() {
736
+ const ret = wasm.idkitinvitecoderequest_pollForStatus(this.__wbg_ptr);
737
+ return takeObject(ret);
738
+ }
739
+ /**
740
+ * Returns the request ID for this request.
741
+ *
742
+ * # Errors
743
+ *
744
+ * Returns an error if the request has been closed.
745
+ * @returns {string}
746
+ */
747
+ requestId() {
748
+ let deferred2_0;
749
+ let deferred2_1;
750
+ try {
751
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
752
+ wasm.idkitinvitecoderequest_requestId(retptr, this.__wbg_ptr);
753
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
754
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
755
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
756
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
757
+ var ptr1 = r0;
758
+ var len1 = r1;
759
+ if (r3) {
760
+ ptr1 = 0;
761
+ len1 = 0;
762
+ throw takeObject(r2);
763
+ }
764
+ deferred2_0 = ptr1;
765
+ deferred2_1 = len1;
766
+ return getStringFromWasm0(ptr1, len1);
767
+ } finally {
768
+ wasm.__wbindgen_add_to_stack_pointer(16);
769
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
770
+ }
771
+ }
772
+ };
773
+ if (Symbol.dispose) IDKitInviteCodeRequest.prototype[Symbol.dispose] = IDKitInviteCodeRequest.prototype.free;
610
774
  var IDKitProof = class {
611
775
  __destroy_into_raw() {
612
776
  const ptr = this.__wbg_ptr;
@@ -1043,6 +1207,21 @@ function hashSignal(signal) {
1043
1207
  function init_wasm() {
1044
1208
  wasm.init_wasm();
1045
1209
  }
1210
+ function proofResponseToIDKitResult(proof_response, options) {
1211
+ try {
1212
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1213
+ wasm.proofResponseToIDKitResult(retptr, addHeapObject(proof_response), addHeapObject(options));
1214
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1215
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1216
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1217
+ if (r2) {
1218
+ throw takeObject(r1);
1219
+ }
1220
+ return takeObject(r0);
1221
+ } finally {
1222
+ wasm.__wbindgen_add_to_stack_pointer(16);
1223
+ }
1224
+ }
1046
1225
  function proveSession(session_id, app_id, rp_context, action_description, bridge_url, override_connect_base_url, return_to, environment) {
1047
1226
  const ptr0 = passStringToWasm0(session_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1048
1227
  const len0 = WASM_VECTOR_LEN;
@@ -1109,6 +1288,10 @@ function __wbg_get_imports() {
1109
1288
  const ret = Error(getStringFromWasm0(arg0, arg1));
1110
1289
  return addHeapObject(ret);
1111
1290
  },
1291
+ __wbg_Number_a5a435bd7bbec835: function(arg0) {
1292
+ const ret = Number(getObject(arg0));
1293
+ return ret;
1294
+ },
1112
1295
  __wbg_String_8564e559799eccda: function(arg0, arg1) {
1113
1296
  const ret = String(getObject(arg1));
1114
1297
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
@@ -1275,6 +1458,10 @@ function __wbg_get_imports() {
1275
1458
  const ret = getObject(arg0)[arg1 >>> 0];
1276
1459
  return addHeapObject(ret);
1277
1460
  },
1461
+ __wbg_get_with_ref_key_6412cf3094599694: function(arg0, arg1) {
1462
+ const ret = getObject(arg0)[getObject(arg1)];
1463
+ return addHeapObject(ret);
1464
+ },
1278
1465
  __wbg_has_926ef2ff40b308cf: function() {
1279
1466
  return handleError(function(arg0, arg1) {
1280
1467
  const ret = Reflect.has(getObject(arg0), getObject(arg1));
@@ -1285,6 +1472,10 @@ function __wbg_get_imports() {
1285
1472
  const ret = getObject(arg0).headers;
1286
1473
  return addHeapObject(ret);
1287
1474
  },
1475
+ __wbg_idkitinvitecoderequest_new: function(arg0) {
1476
+ const ret = IDKitInviteCodeRequest.__wrap(arg0);
1477
+ return addHeapObject(ret);
1478
+ },
1288
1479
  __wbg_idkitrequest_new: function(arg0) {
1289
1480
  const ret = IDKitRequest.__wrap(arg0);
1290
1481
  return addHeapObject(ret);
@@ -1396,7 +1587,7 @@ function __wbg_get_imports() {
1396
1587
  const a = state0.a;
1397
1588
  state0.a = 0;
1398
1589
  try {
1399
- return __wasm_bindgen_func_elem_1443(a, state0.b, arg02, arg12);
1590
+ return __wasm_bindgen_func_elem_1544(a, state0.b, arg02, arg12);
1400
1591
  } finally {
1401
1592
  state0.a = a;
1402
1593
  }
@@ -1576,11 +1767,11 @@ function __wbg_get_imports() {
1576
1767
  return addHeapObject(ret);
1577
1768
  },
1578
1769
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
1579
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_661, __wasm_bindgen_func_elem_662);
1770
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_751, __wasm_bindgen_func_elem_752);
1580
1771
  return addHeapObject(ret);
1581
1772
  },
1582
1773
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
1583
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_989, __wasm_bindgen_func_elem_990);
1774
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_1079, __wasm_bindgen_func_elem_1080);
1584
1775
  return addHeapObject(ret);
1585
1776
  },
1586
1777
  __wbindgen_cast_0000000000000003: function(arg0) {
@@ -1616,13 +1807,13 @@ function __wbg_get_imports() {
1616
1807
  "./idkit_wasm_bg.js": import0
1617
1808
  };
1618
1809
  }
1619
- function __wasm_bindgen_func_elem_662(arg0, arg1) {
1620
- wasm.__wasm_bindgen_func_elem_662(arg0, arg1);
1810
+ function __wasm_bindgen_func_elem_752(arg0, arg1) {
1811
+ wasm.__wasm_bindgen_func_elem_752(arg0, arg1);
1621
1812
  }
1622
- function __wasm_bindgen_func_elem_990(arg0, arg1, arg2) {
1813
+ function __wasm_bindgen_func_elem_1080(arg0, arg1, arg2) {
1623
1814
  try {
1624
1815
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1625
- wasm.__wasm_bindgen_func_elem_990(retptr, arg0, arg1, addHeapObject(arg2));
1816
+ wasm.__wasm_bindgen_func_elem_1080(retptr, arg0, arg1, addHeapObject(arg2));
1626
1817
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1627
1818
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1628
1819
  if (r1) {
@@ -1632,8 +1823,8 @@ function __wasm_bindgen_func_elem_990(arg0, arg1, arg2) {
1632
1823
  wasm.__wbindgen_add_to_stack_pointer(16);
1633
1824
  }
1634
1825
  }
1635
- function __wasm_bindgen_func_elem_1443(arg0, arg1, arg2, arg3) {
1636
- wasm.__wasm_bindgen_func_elem_1443(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1826
+ function __wasm_bindgen_func_elem_1544(arg0, arg1, arg2, arg3) {
1827
+ wasm.__wasm_bindgen_func_elem_1544(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1637
1828
  }
1638
1829
  var __wbindgen_enum_RequestCache = ["default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached"];
1639
1830
  var __wbindgen_enum_RequestCredentials = ["omit", "same-origin", "include"];
@@ -1647,6 +1838,9 @@ var CredentialRequestWasmFinalization = typeof FinalizationRegistry === "undefin
1647
1838
  var IDKitBuilderFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
1648
1839
  }, unregister: () => {
1649
1840
  } } : new FinalizationRegistry((ptr) => wasm.__wbg_idkitbuilder_free(ptr >>> 0, 1));
1841
+ var IDKitInviteCodeRequestFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
1842
+ }, unregister: () => {
1843
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_idkitinvitecoderequest_free(ptr >>> 0, 1));
1650
1844
  var IDKitProofFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
1651
1845
  }, unregister: () => {
1652
1846
  } } : new FinalizationRegistry((ptr) => wasm.__wbg_idkitproof_free(ptr >>> 0, 1));
@@ -1974,6 +2168,10 @@ function setDebug(enabled) {
1974
2168
 
1975
2169
  // src/transports/native.ts
1976
2170
  var MINIAPP_VERIFY_ACTION = "miniapp-verify-action";
2171
+ function toNativeErrorCode(error) {
2172
+ const code = error instanceof Error ? error.message : String(error);
2173
+ return Object.values(IDKitErrorCodes).includes(code) ? code : "generic_error" /* GenericError */;
2174
+ }
1977
2175
  function isInWorldApp() {
1978
2176
  return typeof window !== "undefined" && Boolean(window.WorldApp);
1979
2177
  }
@@ -2016,6 +2214,8 @@ var NativeIDKitRequest = class {
2016
2214
  this.resolveFn = resolve;
2017
2215
  const handleIncomingPayload = (responsePayload) => {
2018
2216
  if (this.completionResult) return;
2217
+ if (isDebug())
2218
+ console.debug("[IDKit] Native: received response", responsePayload);
2019
2219
  if (responsePayload?.status === "error") {
2020
2220
  if (isDebug())
2021
2221
  console.warn(
@@ -2028,15 +2228,27 @@ var NativeIDKitRequest = class {
2028
2228
  });
2029
2229
  return;
2030
2230
  }
2031
- this.complete({
2032
- success: true,
2033
- result: nativeResultToIDKitResult(
2231
+ try {
2232
+ const result = nativeResultToIDKitResult(
2034
2233
  responsePayload,
2035
2234
  config,
2036
2235
  signalHashes,
2037
2236
  legacySignalHash
2038
- )
2039
- });
2237
+ );
2238
+ if (isDebug())
2239
+ console.debug(
2240
+ "[IDKit] Native: mapped response",
2241
+ result.protocol_version
2242
+ );
2243
+ this.complete({ success: true, result });
2244
+ } catch (error) {
2245
+ if (isDebug())
2246
+ console.warn("[IDKit] Native: failed to map response", error);
2247
+ this.complete({
2248
+ success: false,
2249
+ error: toNativeErrorCode(error)
2250
+ });
2251
+ }
2040
2252
  };
2041
2253
  const handler = (event) => {
2042
2254
  const data = event.data;
@@ -2069,13 +2281,15 @@ var NativeIDKitRequest = class {
2069
2281
  if (w.webkit?.messageHandlers?.minikit) {
2070
2282
  if (isDebug())
2071
2283
  console.debug(
2072
- `[IDKit] Native: sending verify command (version=${version}, platform=ios)`
2284
+ `[IDKit] Native: sending verify command (version=${version}, platform=ios)`,
2285
+ sendPayload
2073
2286
  );
2074
2287
  w.webkit.messageHandlers.minikit.postMessage(sendPayload);
2075
2288
  } else if (w.Android) {
2076
2289
  if (isDebug())
2077
2290
  console.debug(
2078
- `[IDKit] Native: sending verify command (version=${version}, platform=android)`
2291
+ `[IDKit] Native: sending verify command (version=${version}, platform=android)`,
2292
+ sendPayload
2079
2293
  );
2080
2294
  w.Android.postMessage(JSON.stringify(sendPayload));
2081
2295
  } else {
@@ -2103,7 +2317,7 @@ var NativeIDKitRequest = class {
2103
2317
  if (isDebug())
2104
2318
  console.debug(
2105
2319
  "[IDKit] Native: request completed",
2106
- result.success ? "success" : `error=${result.error}`
2320
+ result.success === true ? "success" : `error=${result.error}`
2107
2321
  );
2108
2322
  this.completionResult = result;
2109
2323
  this.cleanup();
@@ -2135,13 +2349,14 @@ var NativeIDKitRequest = class {
2135
2349
  return this.completionResult === null;
2136
2350
  }
2137
2351
  async pollOnce() {
2138
- if (!this.completionResult) {
2352
+ const completionResult = this.completionResult;
2353
+ if (!completionResult) {
2139
2354
  return { type: "awaiting_confirmation" };
2140
2355
  }
2141
- if (this.completionResult.success) {
2142
- return { type: "confirmed", result: this.completionResult.result };
2356
+ if (completionResult.success === true) {
2357
+ return { type: "confirmed", result: completionResult.result };
2143
2358
  }
2144
- return { type: "failed", error: this.completionResult.error };
2359
+ return { type: "failed", error: completionResult.error };
2145
2360
  }
2146
2361
  async pollUntilCompletion(options) {
2147
2362
  const timeout = options?.timeout ?? 9e5;
@@ -2179,39 +2394,24 @@ function nativeResultToIDKitResult(payload, config, signalHashes, legacySignalHa
2179
2394
  const rpNonce = config.rp_context?.nonce ?? "";
2180
2395
  if ("proof_response" in p && p.proof_response != null) {
2181
2396
  const proof_response = p.proof_response;
2182
- const items = proof_response.responses ?? [];
2183
- if (proof_response.session_id) {
2184
- return {
2185
- protocol_version: "4.0",
2186
- nonce: proof_response.nonce ?? rpNonce,
2187
- action_description: proof_response.action_description,
2188
- session_id: proof_response.session_id,
2189
- responses: items.map((item) => ({
2190
- identifier: item.identifier,
2191
- signal_hash: signalHashes[item.identifier],
2192
- proof: item.proof,
2193
- session_nullifier: item.session_nullifier,
2194
- issuer_schema_id: item.issuer_schema_id,
2195
- expires_at_min: item.expires_at_min
2196
- })),
2197
- environment: config.environment ?? "production"
2198
- };
2199
- }
2200
- return {
2201
- protocol_version: "4.0",
2202
- nonce: proof_response.nonce ?? rpNonce,
2203
- action: proof_response.action ?? config.action ?? "",
2204
- action_description: proof_response.action_description,
2205
- responses: items.map((item) => ({
2206
- identifier: item.identifier,
2207
- signal_hash: signalHashes[item.identifier],
2208
- proof: item.proof,
2209
- nullifier: item.nullifier,
2210
- issuer_schema_id: item.issuer_schema_id,
2211
- expires_at_min: item.expires_at_min
2212
- })),
2213
- environment: config.environment ?? "production"
2214
- };
2397
+ if (isDebug())
2398
+ console.debug("[IDKit] Native: mapping wrapped v4 proof_response", {
2399
+ responseCount: proof_response.responses?.length,
2400
+ responseIdentifiers: proof_response.responses?.map(
2401
+ (item) => item.identifier
2402
+ )
2403
+ });
2404
+ return idkit_wasm_exports.proofResponseToIDKitResult(proof_response, {
2405
+ nonce: rpNonce,
2406
+ action: config.action,
2407
+ action_description: config.action_description,
2408
+ environment: config.environment ?? "production",
2409
+ signal_hashes: signalHashes,
2410
+ identity_attested: p.identity_attested
2411
+ });
2412
+ }
2413
+ if (Array.isArray(p.responses) && ("id" in p || "version" in p || "error" in p)) {
2414
+ throw new Error("unexpected_response" /* UnexpectedResponse */);
2215
2415
  }
2216
2416
  if ("verifications" in p && Array.isArray(p.verifications)) {
2217
2417
  const verifications = p.verifications;
@@ -2248,6 +2448,30 @@ function nativeResultToIDKitResult(payload, config, signalHashes, legacySignalHa
2248
2448
 
2249
2449
  // src/request.ts
2250
2450
  var SESSION_ID_PATTERN = /^session_[0-9a-fA-F]{128}$/;
2451
+ async function pollUntilCompletionLoop(pollOnce, options) {
2452
+ const pollInterval = options?.pollInterval ?? 1e3;
2453
+ const timeout = options?.timeout ?? 9e5;
2454
+ const startTime = Date.now();
2455
+ while (true) {
2456
+ if (options?.signal?.aborted) {
2457
+ return { success: false, error: "cancelled" /* Cancelled */ };
2458
+ }
2459
+ if (Date.now() - startTime > timeout) {
2460
+ return { success: false, error: "timeout" /* Timeout */ };
2461
+ }
2462
+ const status = await pollOnce();
2463
+ if (status.type === "confirmed" && status.result) {
2464
+ return { success: true, result: status.result };
2465
+ }
2466
+ if (status.type === "failed") {
2467
+ return {
2468
+ success: false,
2469
+ error: status.error ?? "generic_error" /* GenericError */
2470
+ };
2471
+ }
2472
+ await new Promise((resolve) => setTimeout(resolve, pollInterval));
2473
+ }
2474
+ }
2251
2475
  var IDKitRequestImpl = class {
2252
2476
  constructor(wasmRequest) {
2253
2477
  this.wasmRequest = wasmRequest;
@@ -2263,29 +2487,31 @@ var IDKitRequestImpl = class {
2263
2487
  async pollOnce() {
2264
2488
  return await this.wasmRequest.pollForStatus();
2265
2489
  }
2266
- async pollUntilCompletion(options) {
2267
- const pollInterval = options?.pollInterval ?? 1e3;
2268
- const timeout = options?.timeout ?? 9e5;
2269
- const startTime = Date.now();
2270
- while (true) {
2271
- if (options?.signal?.aborted) {
2272
- return { success: false, error: "cancelled" /* Cancelled */ };
2273
- }
2274
- if (Date.now() - startTime > timeout) {
2275
- return { success: false, error: "timeout" /* Timeout */ };
2276
- }
2277
- const status = await this.pollOnce();
2278
- if (status.type === "confirmed" && status.result) {
2279
- return { success: true, result: status.result };
2280
- }
2281
- if (status.type === "failed") {
2282
- return {
2283
- success: false,
2284
- error: status.error ?? "generic_error" /* GenericError */
2285
- };
2286
- }
2287
- await new Promise((resolve) => setTimeout(resolve, pollInterval));
2288
- }
2490
+ pollUntilCompletion(options) {
2491
+ return pollUntilCompletionLoop(() => this.pollOnce(), options);
2492
+ }
2493
+ };
2494
+ var IDKitInviteCodeRequestImpl = class {
2495
+ constructor(wasmRequest) {
2496
+ this.wasmRequest = wasmRequest;
2497
+ this._connectorURI = wasmRequest.connectUrl();
2498
+ this._expiresAt = wasmRequest.expiresAt();
2499
+ this._requestId = wasmRequest.requestId();
2500
+ }
2501
+ get connectorURI() {
2502
+ return this._connectorURI;
2503
+ }
2504
+ get expiresAt() {
2505
+ return this._expiresAt;
2506
+ }
2507
+ get requestId() {
2508
+ return this._requestId;
2509
+ }
2510
+ async pollOnce() {
2511
+ return await this.wasmRequest.pollForStatus();
2512
+ }
2513
+ pollUntilCompletion(options) {
2514
+ return pollUntilCompletionLoop(() => this.pollOnce(), options);
2289
2515
  }
2290
2516
  };
2291
2517
  function CredentialRequest(credential_type, options) {
@@ -2468,6 +2694,51 @@ var IDKitBuilder2 = class {
2468
2694
  return new IDKitRequestImpl(wasmRequest);
2469
2695
  }
2470
2696
  };
2697
+ var IDKitInviteCodeBuilder = class {
2698
+ constructor(config) {
2699
+ this.config = config;
2700
+ }
2701
+ /**
2702
+ * Creates an invite-code mode IDKit request with the given constraints.
2703
+ *
2704
+ * @param constraints - Constraint tree (CredentialRequest or any/all/enumerate combinators)
2705
+ * @returns A new IDKitInviteCodeRequest instance
2706
+ *
2707
+ * @example
2708
+ * ```typescript
2709
+ * const request = await IDKit.requestWithInviteCode({ app_id, action, rp_context, allow_legacy_proofs: false })
2710
+ * .constraints(any(CredentialRequest('proof_of_human'), CredentialRequest('face')));
2711
+ * displayLink(request.connectorURI);
2712
+ * ```
2713
+ */
2714
+ async constraints(constraints) {
2715
+ await initIDKit();
2716
+ const wasmBuilder = createWasmBuilderFromConfig(this.config);
2717
+ const wasmRequest = await wasmBuilder.constraintsWithInviteCode(
2718
+ constraints
2719
+ );
2720
+ return new IDKitInviteCodeRequestImpl(wasmRequest);
2721
+ }
2722
+ /**
2723
+ * Creates an invite-code mode IDKit request from a preset.
2724
+ *
2725
+ * @param preset - A preset object from orbLegacy(), secureDocumentLegacy(), documentLegacy(), selfieCheckLegacy(), or deviceLegacy()
2726
+ * @returns A new IDKitInviteCodeRequest instance
2727
+ */
2728
+ async preset(preset) {
2729
+ if (this.config.type === "createSession" || this.config.type === "proveSession") {
2730
+ throw new Error(
2731
+ "Presets are not supported for session flows. Use .constraints() instead."
2732
+ );
2733
+ }
2734
+ await initIDKit();
2735
+ const wasmBuilder = createWasmBuilderFromConfig(this.config);
2736
+ const wasmRequest = await wasmBuilder.presetWithInviteCode(
2737
+ preset
2738
+ );
2739
+ return new IDKitInviteCodeRequestImpl(wasmRequest);
2740
+ }
2741
+ };
2471
2742
  function createRequest(config) {
2472
2743
  if (!config.app_id) {
2473
2744
  throw new Error("app_id is required");
@@ -2498,6 +2769,36 @@ function createRequest(config) {
2498
2769
  environment: config.environment
2499
2770
  });
2500
2771
  }
2772
+ function createRequestWithInviteCode(config) {
2773
+ if (!config.app_id) {
2774
+ throw new Error("app_id is required");
2775
+ }
2776
+ if (!config.action) {
2777
+ throw new Error("action is required");
2778
+ }
2779
+ if (!config.rp_context) {
2780
+ throw new Error(
2781
+ "rp_context is required. Generate it on your backend using signRequest()."
2782
+ );
2783
+ }
2784
+ if (typeof config.allow_legacy_proofs !== "boolean") {
2785
+ throw new Error(
2786
+ "allow_legacy_proofs is required. Set to true to accept v3 proofs during migration, or false to only accept v4 proofs."
2787
+ );
2788
+ }
2789
+ return new IDKitInviteCodeBuilder({
2790
+ type: "request",
2791
+ app_id: config.app_id,
2792
+ action: String(config.action),
2793
+ rp_context: config.rp_context,
2794
+ action_description: config.action_description,
2795
+ bridge_url: config.bridge_url,
2796
+ return_to: config.return_to,
2797
+ allow_legacy_proofs: config.allow_legacy_proofs,
2798
+ override_connect_base_url: config.override_connect_base_url,
2799
+ environment: config.environment
2800
+ });
2801
+ }
2501
2802
  function createSession2(config) {
2502
2803
  if (!config.app_id) {
2503
2804
  throw new Error("app_id is required");
@@ -2550,6 +2851,8 @@ function proveSession2(sessionId, config) {
2550
2851
  var IDKit = {
2551
2852
  /** Create a new verification request */
2552
2853
  request: createRequest,
2854
+ /** Create a new invite-code mode verification request (WDP-73) */
2855
+ requestWithInviteCode: createRequestWithInviteCode,
2553
2856
  /** Create a new session (no action, no existing session_id) */
2554
2857
  createSession: createSession2,
2555
2858
  /** Prove an existing session (no action, has session_id) */