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