@worldcoin/idkit-core 4.1.4 → 4.1.6
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 +384 -79
- package/dist/index.d.cts +133 -4
- package/dist/index.d.ts +133 -4
- package/dist/index.js +383 -80
- 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";
|
|
@@ -30,6 +32,7 @@ var IDKitErrorCodes = /* @__PURE__ */ ((IDKitErrorCodes2) => {
|
|
|
30
32
|
IDKitErrorCodes2["TimestampTooFarInFuture"] = "timestamp_too_far_in_future";
|
|
31
33
|
IDKitErrorCodes2["InvalidTimestamp"] = "invalid_timestamp";
|
|
32
34
|
IDKitErrorCodes2["RpSignatureExpired"] = "rp_signature_expired";
|
|
35
|
+
IDKitErrorCodes2["IdentityAttributesNotMatched"] = "identity_attributes_not_matched";
|
|
33
36
|
IDKitErrorCodes2["GenericError"] = "generic_error";
|
|
34
37
|
IDKitErrorCodes2["InvalidRpIdFormat"] = "invalid_rp_id_format";
|
|
35
38
|
IDKitErrorCodes2["Timeout"] = "timeout";
|
|
@@ -43,6 +46,7 @@ __export(idkit_wasm_exports, {
|
|
|
43
46
|
BridgeEncryption: () => BridgeEncryption,
|
|
44
47
|
CredentialRequestWasm: () => CredentialRequestWasm,
|
|
45
48
|
IDKitBuilder: () => IDKitBuilder,
|
|
49
|
+
IDKitInviteCodeRequest: () => IDKitInviteCodeRequest,
|
|
46
50
|
IDKitProof: () => IDKitProof,
|
|
47
51
|
IDKitRequest: () => IDKitRequest,
|
|
48
52
|
RpContextWasm: () => RpContextWasm,
|
|
@@ -55,6 +59,7 @@ __export(idkit_wasm_exports, {
|
|
|
55
59
|
hashSignal: () => hashSignal,
|
|
56
60
|
initSync: () => initSync,
|
|
57
61
|
init_wasm: () => init_wasm,
|
|
62
|
+
proofResponseToIDKitResult: () => proofResponseToIDKitResult,
|
|
58
63
|
proveSession: () => proveSession,
|
|
59
64
|
request: () => request,
|
|
60
65
|
signRequest: () => signRequest
|
|
@@ -422,6 +427,16 @@ var IDKitBuilder = class _IDKitBuilder {
|
|
|
422
427
|
const ret = wasm.idkitbuilder_constraints(ptr, addHeapObject(constraints_json));
|
|
423
428
|
return takeObject(ret);
|
|
424
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
|
+
}
|
|
425
440
|
/**
|
|
426
441
|
* Creates a new builder for creating a new session
|
|
427
442
|
* @param {string} app_id
|
|
@@ -612,8 +627,147 @@ var IDKitBuilder = class _IDKitBuilder {
|
|
|
612
627
|
const ret = wasm.idkitbuilder_preset(ptr, addHeapObject(preset_json));
|
|
613
628
|
return takeObject(ret);
|
|
614
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
|
+
}
|
|
615
640
|
};
|
|
616
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;
|
|
617
771
|
var IDKitProof = class {
|
|
618
772
|
__destroy_into_raw() {
|
|
619
773
|
const ptr = this.__wbg_ptr;
|
|
@@ -1050,6 +1204,21 @@ function hashSignal(signal) {
|
|
|
1050
1204
|
function init_wasm() {
|
|
1051
1205
|
wasm.init_wasm();
|
|
1052
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
|
+
}
|
|
1053
1222
|
function proveSession(session_id, app_id, rp_context, action_description, bridge_url, override_connect_base_url, return_to, environment) {
|
|
1054
1223
|
const ptr0 = passStringToWasm0(session_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1055
1224
|
const len0 = WASM_VECTOR_LEN;
|
|
@@ -1116,6 +1285,10 @@ function __wbg_get_imports() {
|
|
|
1116
1285
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
1117
1286
|
return addHeapObject(ret);
|
|
1118
1287
|
},
|
|
1288
|
+
__wbg_Number_a5a435bd7bbec835: function(arg0) {
|
|
1289
|
+
const ret = Number(getObject(arg0));
|
|
1290
|
+
return ret;
|
|
1291
|
+
},
|
|
1119
1292
|
__wbg_String_8564e559799eccda: function(arg0, arg1) {
|
|
1120
1293
|
const ret = String(getObject(arg1));
|
|
1121
1294
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
@@ -1282,6 +1455,10 @@ function __wbg_get_imports() {
|
|
|
1282
1455
|
const ret = getObject(arg0)[arg1 >>> 0];
|
|
1283
1456
|
return addHeapObject(ret);
|
|
1284
1457
|
},
|
|
1458
|
+
__wbg_get_with_ref_key_6412cf3094599694: function(arg0, arg1) {
|
|
1459
|
+
const ret = getObject(arg0)[getObject(arg1)];
|
|
1460
|
+
return addHeapObject(ret);
|
|
1461
|
+
},
|
|
1285
1462
|
__wbg_has_926ef2ff40b308cf: function() {
|
|
1286
1463
|
return handleError(function(arg0, arg1) {
|
|
1287
1464
|
const ret = Reflect.has(getObject(arg0), getObject(arg1));
|
|
@@ -1292,6 +1469,10 @@ function __wbg_get_imports() {
|
|
|
1292
1469
|
const ret = getObject(arg0).headers;
|
|
1293
1470
|
return addHeapObject(ret);
|
|
1294
1471
|
},
|
|
1472
|
+
__wbg_idkitinvitecoderequest_new: function(arg0) {
|
|
1473
|
+
const ret = IDKitInviteCodeRequest.__wrap(arg0);
|
|
1474
|
+
return addHeapObject(ret);
|
|
1475
|
+
},
|
|
1295
1476
|
__wbg_idkitrequest_new: function(arg0) {
|
|
1296
1477
|
const ret = IDKitRequest.__wrap(arg0);
|
|
1297
1478
|
return addHeapObject(ret);
|
|
@@ -1403,7 +1584,7 @@ function __wbg_get_imports() {
|
|
|
1403
1584
|
const a = state0.a;
|
|
1404
1585
|
state0.a = 0;
|
|
1405
1586
|
try {
|
|
1406
|
-
return
|
|
1587
|
+
return __wasm_bindgen_func_elem_1556(a, state0.b, arg02, arg12);
|
|
1407
1588
|
} finally {
|
|
1408
1589
|
state0.a = a;
|
|
1409
1590
|
}
|
|
@@ -1583,11 +1764,11 @@ function __wbg_get_imports() {
|
|
|
1583
1764
|
return addHeapObject(ret);
|
|
1584
1765
|
},
|
|
1585
1766
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
1586
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
1767
|
+
const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_763, __wasm_bindgen_func_elem_764);
|
|
1587
1768
|
return addHeapObject(ret);
|
|
1588
1769
|
},
|
|
1589
1770
|
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
1590
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
1771
|
+
const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_1091, __wasm_bindgen_func_elem_1092);
|
|
1591
1772
|
return addHeapObject(ret);
|
|
1592
1773
|
},
|
|
1593
1774
|
__wbindgen_cast_0000000000000003: function(arg0) {
|
|
@@ -1623,13 +1804,13 @@ function __wbg_get_imports() {
|
|
|
1623
1804
|
"./idkit_wasm_bg.js": import0
|
|
1624
1805
|
};
|
|
1625
1806
|
}
|
|
1626
|
-
function
|
|
1627
|
-
wasm.
|
|
1807
|
+
function __wasm_bindgen_func_elem_764(arg0, arg1) {
|
|
1808
|
+
wasm.__wasm_bindgen_func_elem_764(arg0, arg1);
|
|
1628
1809
|
}
|
|
1629
|
-
function
|
|
1810
|
+
function __wasm_bindgen_func_elem_1092(arg0, arg1, arg2) {
|
|
1630
1811
|
try {
|
|
1631
1812
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1632
|
-
wasm.
|
|
1813
|
+
wasm.__wasm_bindgen_func_elem_1092(retptr, arg0, arg1, addHeapObject(arg2));
|
|
1633
1814
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1634
1815
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1635
1816
|
if (r1) {
|
|
@@ -1639,8 +1820,8 @@ function __wasm_bindgen_func_elem_1028(arg0, arg1, arg2) {
|
|
|
1639
1820
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1640
1821
|
}
|
|
1641
1822
|
}
|
|
1642
|
-
function
|
|
1643
|
-
wasm.
|
|
1823
|
+
function __wasm_bindgen_func_elem_1556(arg0, arg1, arg2, arg3) {
|
|
1824
|
+
wasm.__wasm_bindgen_func_elem_1556(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
|
|
1644
1825
|
}
|
|
1645
1826
|
var __wbindgen_enum_RequestCache = ["default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached"];
|
|
1646
1827
|
var __wbindgen_enum_RequestCredentials = ["omit", "same-origin", "include"];
|
|
@@ -1654,6 +1835,9 @@ var CredentialRequestWasmFinalization = typeof FinalizationRegistry === "undefin
|
|
|
1654
1835
|
var IDKitBuilderFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
1655
1836
|
}, unregister: () => {
|
|
1656
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));
|
|
1657
1841
|
var IDKitProofFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
1658
1842
|
}, unregister: () => {
|
|
1659
1843
|
} } : new FinalizationRegistry((ptr) => wasm.__wbg_idkitproof_free(ptr >>> 0, 1));
|
|
@@ -1981,6 +2165,10 @@ function setDebug(enabled) {
|
|
|
1981
2165
|
|
|
1982
2166
|
// src/transports/native.ts
|
|
1983
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
|
+
}
|
|
1984
2172
|
function isInWorldApp() {
|
|
1985
2173
|
return typeof window !== "undefined" && Boolean(window.WorldApp);
|
|
1986
2174
|
}
|
|
@@ -2023,6 +2211,8 @@ var NativeIDKitRequest = class {
|
|
|
2023
2211
|
this.resolveFn = resolve;
|
|
2024
2212
|
const handleIncomingPayload = (responsePayload) => {
|
|
2025
2213
|
if (this.completionResult) return;
|
|
2214
|
+
if (isDebug())
|
|
2215
|
+
console.debug("[IDKit] Native: received response", responsePayload);
|
|
2026
2216
|
if (responsePayload?.status === "error") {
|
|
2027
2217
|
if (isDebug())
|
|
2028
2218
|
console.warn(
|
|
@@ -2035,15 +2225,27 @@ var NativeIDKitRequest = class {
|
|
|
2035
2225
|
});
|
|
2036
2226
|
return;
|
|
2037
2227
|
}
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
result: nativeResultToIDKitResult(
|
|
2228
|
+
try {
|
|
2229
|
+
const result = nativeResultToIDKitResult(
|
|
2041
2230
|
responsePayload,
|
|
2042
2231
|
config,
|
|
2043
2232
|
signalHashes,
|
|
2044
2233
|
legacySignalHash
|
|
2045
|
-
)
|
|
2046
|
-
|
|
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
|
+
}
|
|
2047
2249
|
};
|
|
2048
2250
|
const handler = (event) => {
|
|
2049
2251
|
const data = event.data;
|
|
@@ -2076,13 +2278,15 @@ var NativeIDKitRequest = class {
|
|
|
2076
2278
|
if (w.webkit?.messageHandlers?.minikit) {
|
|
2077
2279
|
if (isDebug())
|
|
2078
2280
|
console.debug(
|
|
2079
|
-
`[IDKit] Native: sending verify command (version=${version}, platform=ios)
|
|
2281
|
+
`[IDKit] Native: sending verify command (version=${version}, platform=ios)`,
|
|
2282
|
+
sendPayload
|
|
2080
2283
|
);
|
|
2081
2284
|
w.webkit.messageHandlers.minikit.postMessage(sendPayload);
|
|
2082
2285
|
} else if (w.Android) {
|
|
2083
2286
|
if (isDebug())
|
|
2084
2287
|
console.debug(
|
|
2085
|
-
`[IDKit] Native: sending verify command (version=${version}, platform=android)
|
|
2288
|
+
`[IDKit] Native: sending verify command (version=${version}, platform=android)`,
|
|
2289
|
+
sendPayload
|
|
2086
2290
|
);
|
|
2087
2291
|
w.Android.postMessage(JSON.stringify(sendPayload));
|
|
2088
2292
|
} else {
|
|
@@ -2110,7 +2314,7 @@ var NativeIDKitRequest = class {
|
|
|
2110
2314
|
if (isDebug())
|
|
2111
2315
|
console.debug(
|
|
2112
2316
|
"[IDKit] Native: request completed",
|
|
2113
|
-
result.success ? "success" : `error=${result.error}`
|
|
2317
|
+
result.success === true ? "success" : `error=${result.error}`
|
|
2114
2318
|
);
|
|
2115
2319
|
this.completionResult = result;
|
|
2116
2320
|
this.cleanup();
|
|
@@ -2142,13 +2346,14 @@ var NativeIDKitRequest = class {
|
|
|
2142
2346
|
return this.completionResult === null;
|
|
2143
2347
|
}
|
|
2144
2348
|
async pollOnce() {
|
|
2145
|
-
|
|
2349
|
+
const completionResult = this.completionResult;
|
|
2350
|
+
if (!completionResult) {
|
|
2146
2351
|
return { type: "awaiting_confirmation" };
|
|
2147
2352
|
}
|
|
2148
|
-
if (
|
|
2149
|
-
return { type: "confirmed", result:
|
|
2353
|
+
if (completionResult.success === true) {
|
|
2354
|
+
return { type: "confirmed", result: completionResult.result };
|
|
2150
2355
|
}
|
|
2151
|
-
return { type: "failed", error:
|
|
2356
|
+
return { type: "failed", error: completionResult.error };
|
|
2152
2357
|
}
|
|
2153
2358
|
async pollUntilCompletion(options) {
|
|
2154
2359
|
const timeout = options?.timeout ?? 9e5;
|
|
@@ -2186,39 +2391,24 @@ function nativeResultToIDKitResult(payload, config, signalHashes, legacySignalHa
|
|
|
2186
2391
|
const rpNonce = config.rp_context?.nonce ?? "";
|
|
2187
2392
|
if ("proof_response" in p && p.proof_response != null) {
|
|
2188
2393
|
const proof_response = p.proof_response;
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
return {
|
|
2208
|
-
protocol_version: "4.0",
|
|
2209
|
-
nonce: proof_response.nonce ?? rpNonce,
|
|
2210
|
-
action: proof_response.action ?? config.action ?? "",
|
|
2211
|
-
action_description: proof_response.action_description,
|
|
2212
|
-
responses: items.map((item) => ({
|
|
2213
|
-
identifier: item.identifier,
|
|
2214
|
-
signal_hash: signalHashes[item.identifier],
|
|
2215
|
-
proof: item.proof,
|
|
2216
|
-
nullifier: item.nullifier,
|
|
2217
|
-
issuer_schema_id: item.issuer_schema_id,
|
|
2218
|
-
expires_at_min: item.expires_at_min
|
|
2219
|
-
})),
|
|
2220
|
-
environment: config.environment ?? "production"
|
|
2221
|
-
};
|
|
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 */);
|
|
2222
2412
|
}
|
|
2223
2413
|
if ("verifications" in p && Array.isArray(p.verifications)) {
|
|
2224
2414
|
const verifications = p.verifications;
|
|
@@ -2255,6 +2445,30 @@ function nativeResultToIDKitResult(payload, config, signalHashes, legacySignalHa
|
|
|
2255
2445
|
|
|
2256
2446
|
// src/request.ts
|
|
2257
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
|
+
}
|
|
2258
2472
|
var IDKitRequestImpl = class {
|
|
2259
2473
|
constructor(wasmRequest) {
|
|
2260
2474
|
this.wasmRequest = wasmRequest;
|
|
@@ -2270,29 +2484,31 @@ var IDKitRequestImpl = class {
|
|
|
2270
2484
|
async pollOnce() {
|
|
2271
2485
|
return await this.wasmRequest.pollForStatus();
|
|
2272
2486
|
}
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
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);
|
|
2296
2512
|
}
|
|
2297
2513
|
};
|
|
2298
2514
|
function CredentialRequest(credential_type, options) {
|
|
@@ -2327,6 +2543,12 @@ function deviceLegacy(opts = {}) {
|
|
|
2327
2543
|
function selfieCheckLegacy(opts = {}) {
|
|
2328
2544
|
return { type: "SelfieCheckLegacy", signal: opts.signal };
|
|
2329
2545
|
}
|
|
2546
|
+
function proofOfHuman(opts = {}) {
|
|
2547
|
+
return { type: "ProofOfHuman", signal: opts.signal };
|
|
2548
|
+
}
|
|
2549
|
+
function passport(opts = {}) {
|
|
2550
|
+
return { type: "Passport", signal: opts.signal };
|
|
2551
|
+
}
|
|
2330
2552
|
function createWasmBuilderFromConfig(config) {
|
|
2331
2553
|
if (!config.rp_context) {
|
|
2332
2554
|
throw new Error("rp_context is required for WASM bridge transport");
|
|
@@ -2420,7 +2642,7 @@ var IDKitBuilder2 = class {
|
|
|
2420
2642
|
* Presets provide a simplified way to create requests with predefined
|
|
2421
2643
|
* credential configurations.
|
|
2422
2644
|
*
|
|
2423
|
-
* @param preset - A preset object from orbLegacy(), secureDocumentLegacy(), documentLegacy(), selfieCheckLegacy(), or
|
|
2645
|
+
* @param preset - A preset object from orbLegacy(), secureDocumentLegacy(), documentLegacy(), selfieCheckLegacy(), deviceLegacy(), proofOfHuman(), or passport()
|
|
2424
2646
|
* @returns A new IDKitRequest instance
|
|
2425
2647
|
*
|
|
2426
2648
|
* @example
|
|
@@ -2475,6 +2697,51 @@ var IDKitBuilder2 = class {
|
|
|
2475
2697
|
return new IDKitRequestImpl(wasmRequest);
|
|
2476
2698
|
}
|
|
2477
2699
|
};
|
|
2700
|
+
var IDKitInviteCodeBuilder = class {
|
|
2701
|
+
constructor(config) {
|
|
2702
|
+
this.config = config;
|
|
2703
|
+
}
|
|
2704
|
+
/**
|
|
2705
|
+
* Creates an invite-code mode IDKit request with the given constraints.
|
|
2706
|
+
*
|
|
2707
|
+
* @param constraints - Constraint tree (CredentialRequest or any/all/enumerate combinators)
|
|
2708
|
+
* @returns A new IDKitInviteCodeRequest instance
|
|
2709
|
+
*
|
|
2710
|
+
* @example
|
|
2711
|
+
* ```typescript
|
|
2712
|
+
* const request = await IDKit.requestWithInviteCode({ app_id, action, rp_context, allow_legacy_proofs: false })
|
|
2713
|
+
* .constraints(any(CredentialRequest('proof_of_human'), CredentialRequest('face')));
|
|
2714
|
+
* displayLink(request.connectorURI);
|
|
2715
|
+
* ```
|
|
2716
|
+
*/
|
|
2717
|
+
async constraints(constraints) {
|
|
2718
|
+
await initIDKit();
|
|
2719
|
+
const wasmBuilder = createWasmBuilderFromConfig(this.config);
|
|
2720
|
+
const wasmRequest = await wasmBuilder.constraintsWithInviteCode(
|
|
2721
|
+
constraints
|
|
2722
|
+
);
|
|
2723
|
+
return new IDKitInviteCodeRequestImpl(wasmRequest);
|
|
2724
|
+
}
|
|
2725
|
+
/**
|
|
2726
|
+
* Creates an invite-code mode IDKit request from a preset.
|
|
2727
|
+
*
|
|
2728
|
+
* @param preset - A preset object from orbLegacy(), secureDocumentLegacy(), documentLegacy(), selfieCheckLegacy(), deviceLegacy(), proofOfHuman(), or passport()
|
|
2729
|
+
* @returns A new IDKitInviteCodeRequest instance
|
|
2730
|
+
*/
|
|
2731
|
+
async preset(preset) {
|
|
2732
|
+
if (this.config.type === "createSession" || this.config.type === "proveSession") {
|
|
2733
|
+
throw new Error(
|
|
2734
|
+
"Presets are not supported for session flows. Use .constraints() instead."
|
|
2735
|
+
);
|
|
2736
|
+
}
|
|
2737
|
+
await initIDKit();
|
|
2738
|
+
const wasmBuilder = createWasmBuilderFromConfig(this.config);
|
|
2739
|
+
const wasmRequest = await wasmBuilder.presetWithInviteCode(
|
|
2740
|
+
preset
|
|
2741
|
+
);
|
|
2742
|
+
return new IDKitInviteCodeRequestImpl(wasmRequest);
|
|
2743
|
+
}
|
|
2744
|
+
};
|
|
2478
2745
|
function createRequest(config) {
|
|
2479
2746
|
if (!config.app_id) {
|
|
2480
2747
|
throw new Error("app_id is required");
|
|
@@ -2505,6 +2772,36 @@ function createRequest(config) {
|
|
|
2505
2772
|
environment: config.environment
|
|
2506
2773
|
});
|
|
2507
2774
|
}
|
|
2775
|
+
function createRequestWithInviteCode(config) {
|
|
2776
|
+
if (!config.app_id) {
|
|
2777
|
+
throw new Error("app_id is required");
|
|
2778
|
+
}
|
|
2779
|
+
if (!config.action) {
|
|
2780
|
+
throw new Error("action is required");
|
|
2781
|
+
}
|
|
2782
|
+
if (!config.rp_context) {
|
|
2783
|
+
throw new Error(
|
|
2784
|
+
"rp_context is required. Generate it on your backend using signRequest()."
|
|
2785
|
+
);
|
|
2786
|
+
}
|
|
2787
|
+
if (typeof config.allow_legacy_proofs !== "boolean") {
|
|
2788
|
+
throw new Error(
|
|
2789
|
+
"allow_legacy_proofs is required. Set to true to accept v3 proofs during migration, or false to only accept v4 proofs."
|
|
2790
|
+
);
|
|
2791
|
+
}
|
|
2792
|
+
return new IDKitInviteCodeBuilder({
|
|
2793
|
+
type: "request",
|
|
2794
|
+
app_id: config.app_id,
|
|
2795
|
+
action: String(config.action),
|
|
2796
|
+
rp_context: config.rp_context,
|
|
2797
|
+
action_description: config.action_description,
|
|
2798
|
+
bridge_url: config.bridge_url,
|
|
2799
|
+
return_to: config.return_to,
|
|
2800
|
+
allow_legacy_proofs: config.allow_legacy_proofs,
|
|
2801
|
+
override_connect_base_url: config.override_connect_base_url,
|
|
2802
|
+
environment: config.environment
|
|
2803
|
+
});
|
|
2804
|
+
}
|
|
2508
2805
|
function createSession2(config) {
|
|
2509
2806
|
if (!config.app_id) {
|
|
2510
2807
|
throw new Error("app_id is required");
|
|
@@ -2557,6 +2854,8 @@ function proveSession2(sessionId, config) {
|
|
|
2557
2854
|
var IDKit = {
|
|
2558
2855
|
/** Create a new verification request */
|
|
2559
2856
|
request: createRequest,
|
|
2857
|
+
/** Create a new invite-code mode verification request (WDP-73) */
|
|
2858
|
+
requestWithInviteCode: createRequestWithInviteCode,
|
|
2560
2859
|
/** Create a new session (no action, no existing session_id) */
|
|
2561
2860
|
createSession: createSession2,
|
|
2562
2861
|
/** Prove an existing session (no action, has session_id) */
|
|
@@ -2578,7 +2877,11 @@ var IDKit = {
|
|
|
2578
2877
|
/** Create a DeviceLegacy preset for World ID 3.0 legacy support */
|
|
2579
2878
|
deviceLegacy,
|
|
2580
2879
|
/** Create a SelfieCheckLegacy preset for face verification */
|
|
2581
|
-
selfieCheckLegacy
|
|
2880
|
+
selfieCheckLegacy,
|
|
2881
|
+
/** Create a ProofOfHuman preset for World ID 4.0 with legacy Orb fallback */
|
|
2882
|
+
proofOfHuman,
|
|
2883
|
+
/** Create a Passport preset for World ID 4.0 with legacy document fallback */
|
|
2884
|
+
passport
|
|
2582
2885
|
};
|
|
2583
2886
|
|
|
2584
2887
|
// src/lib/platform.ts
|
|
@@ -2612,4 +2915,4 @@ function isValidHex(s) {
|
|
|
2612
2915
|
return /^[0-9a-fA-F]+$/.test(s);
|
|
2613
2916
|
}
|
|
2614
2917
|
|
|
2615
|
-
export { CredentialRequest, IDKit, IDKitErrorCodes, all, any, deviceLegacy, documentLegacy, enumerate, hashSignal2 as hashSignal, isDebug, isInWorldApp, isNode, isReactNative, isWeb, orbLegacy, secureDocumentLegacy, selfieCheckLegacy, setDebug };
|
|
2918
|
+
export { CredentialRequest, IDKit, IDKitErrorCodes, all, any, deviceLegacy, documentLegacy, enumerate, hashSignal2 as hashSignal, isDebug, isInWorldApp, isNode, isReactNative, isWeb, orbLegacy, passport, proofOfHuman, secureDocumentLegacy, selfieCheckLegacy, setDebug };
|