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