@worldcoin/idkit-core 4.1.4 → 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 +370 -77
- package/dist/index.d.cts +84 -1
- package/dist/index.d.ts +84 -1
- package/dist/index.js +370 -77
- package/package.json +1 -1
package/dist/idkit_wasm_bg.wasm
CHANGED
|
Binary file
|
package/dist/index.cjs
CHANGED
|
@@ -16,6 +16,8 @@ var IDKitErrorCodes = /* @__PURE__ */ ((IDKitErrorCodes2) => {
|
|
|
16
16
|
IDKitErrorCodes2["UserRejected"] = "user_rejected";
|
|
17
17
|
IDKitErrorCodes2["VerificationRejected"] = "verification_rejected";
|
|
18
18
|
IDKitErrorCodes2["CredentialUnavailable"] = "credential_unavailable";
|
|
19
|
+
IDKitErrorCodes2["WorldId4NotAvailable"] = "world_id_4_not_available";
|
|
20
|
+
IDKitErrorCodes2["WorldId3NotAvailable"] = "world_id_3_not_available";
|
|
19
21
|
IDKitErrorCodes2["MalformedRequest"] = "malformed_request";
|
|
20
22
|
IDKitErrorCodes2["InvalidNetwork"] = "invalid_network";
|
|
21
23
|
IDKitErrorCodes2["InclusionProofPending"] = "inclusion_proof_pending";
|
|
@@ -33,6 +35,7 @@ var IDKitErrorCodes = /* @__PURE__ */ ((IDKitErrorCodes2) => {
|
|
|
33
35
|
IDKitErrorCodes2["TimestampTooFarInFuture"] = "timestamp_too_far_in_future";
|
|
34
36
|
IDKitErrorCodes2["InvalidTimestamp"] = "invalid_timestamp";
|
|
35
37
|
IDKitErrorCodes2["RpSignatureExpired"] = "rp_signature_expired";
|
|
38
|
+
IDKitErrorCodes2["IdentityAttributesNotMatched"] = "identity_attributes_not_matched";
|
|
36
39
|
IDKitErrorCodes2["GenericError"] = "generic_error";
|
|
37
40
|
IDKitErrorCodes2["InvalidRpIdFormat"] = "invalid_rp_id_format";
|
|
38
41
|
IDKitErrorCodes2["Timeout"] = "timeout";
|
|
@@ -46,6 +49,7 @@ __export(idkit_wasm_exports, {
|
|
|
46
49
|
BridgeEncryption: () => BridgeEncryption,
|
|
47
50
|
CredentialRequestWasm: () => CredentialRequestWasm,
|
|
48
51
|
IDKitBuilder: () => IDKitBuilder,
|
|
52
|
+
IDKitInviteCodeRequest: () => IDKitInviteCodeRequest,
|
|
49
53
|
IDKitProof: () => IDKitProof,
|
|
50
54
|
IDKitRequest: () => IDKitRequest,
|
|
51
55
|
RpContextWasm: () => RpContextWasm,
|
|
@@ -58,6 +62,7 @@ __export(idkit_wasm_exports, {
|
|
|
58
62
|
hashSignal: () => hashSignal,
|
|
59
63
|
initSync: () => initSync,
|
|
60
64
|
init_wasm: () => init_wasm,
|
|
65
|
+
proofResponseToIDKitResult: () => proofResponseToIDKitResult,
|
|
61
66
|
proveSession: () => proveSession,
|
|
62
67
|
request: () => request,
|
|
63
68
|
signRequest: () => signRequest
|
|
@@ -425,6 +430,16 @@ var IDKitBuilder = class _IDKitBuilder {
|
|
|
425
430
|
const ret = wasm.idkitbuilder_constraints(ptr, addHeapObject(constraints_json));
|
|
426
431
|
return takeObject(ret);
|
|
427
432
|
}
|
|
433
|
+
/**
|
|
434
|
+
* Creates an invite-code mode `BridgeConnection` with the given constraints (WDP-73).
|
|
435
|
+
* @param {any} constraints_json
|
|
436
|
+
* @returns {Promise<any>}
|
|
437
|
+
*/
|
|
438
|
+
constraintsWithInviteCode(constraints_json) {
|
|
439
|
+
const ptr = this.__destroy_into_raw();
|
|
440
|
+
const ret = wasm.idkitbuilder_constraintsWithInviteCode(ptr, addHeapObject(constraints_json));
|
|
441
|
+
return takeObject(ret);
|
|
442
|
+
}
|
|
428
443
|
/**
|
|
429
444
|
* Creates a new builder for creating a new session
|
|
430
445
|
* @param {string} app_id
|
|
@@ -615,8 +630,147 @@ var IDKitBuilder = class _IDKitBuilder {
|
|
|
615
630
|
const ret = wasm.idkitbuilder_preset(ptr, addHeapObject(preset_json));
|
|
616
631
|
return takeObject(ret);
|
|
617
632
|
}
|
|
633
|
+
/**
|
|
634
|
+
* Creates an invite-code mode `BridgeConnection` from a preset (WDP-73).
|
|
635
|
+
* @param {any} preset_json
|
|
636
|
+
* @returns {Promise<any>}
|
|
637
|
+
*/
|
|
638
|
+
presetWithInviteCode(preset_json) {
|
|
639
|
+
const ptr = this.__destroy_into_raw();
|
|
640
|
+
const ret = wasm.idkitbuilder_presetWithInviteCode(ptr, addHeapObject(preset_json));
|
|
641
|
+
return takeObject(ret);
|
|
642
|
+
}
|
|
618
643
|
};
|
|
619
644
|
if (Symbol.dispose) IDKitBuilder.prototype[Symbol.dispose] = IDKitBuilder.prototype.free;
|
|
645
|
+
var IDKitInviteCodeRequest = class _IDKitInviteCodeRequest {
|
|
646
|
+
static __wrap(ptr) {
|
|
647
|
+
ptr = ptr >>> 0;
|
|
648
|
+
const obj = Object.create(_IDKitInviteCodeRequest.prototype);
|
|
649
|
+
obj.__wbg_ptr = ptr;
|
|
650
|
+
IDKitInviteCodeRequestFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
651
|
+
return obj;
|
|
652
|
+
}
|
|
653
|
+
__destroy_into_raw() {
|
|
654
|
+
const ptr = this.__wbg_ptr;
|
|
655
|
+
this.__wbg_ptr = 0;
|
|
656
|
+
IDKitInviteCodeRequestFinalization.unregister(this);
|
|
657
|
+
return ptr;
|
|
658
|
+
}
|
|
659
|
+
free() {
|
|
660
|
+
const ptr = this.__destroy_into_raw();
|
|
661
|
+
wasm.__wbg_idkitinvitecoderequest_free(ptr, 0);
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Returns the connector URL the RP should display to the user.
|
|
665
|
+
*
|
|
666
|
+
* This is the same URL shape the URL/QR mode produces, with two extra
|
|
667
|
+
* query params (`c=<canonical_code>`, `a=<app_id>`) the `world.org/verify`
|
|
668
|
+
* landing page uses to render an invite-code-aware view.
|
|
669
|
+
*
|
|
670
|
+
* # Errors
|
|
671
|
+
*
|
|
672
|
+
* Returns an error if the request has been closed.
|
|
673
|
+
* @returns {string}
|
|
674
|
+
*/
|
|
675
|
+
connectUrl() {
|
|
676
|
+
let deferred2_0;
|
|
677
|
+
let deferred2_1;
|
|
678
|
+
try {
|
|
679
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
680
|
+
wasm.idkitinvitecoderequest_connectUrl(retptr, this.__wbg_ptr);
|
|
681
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
682
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
683
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
684
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
685
|
+
var ptr1 = r0;
|
|
686
|
+
var len1 = r1;
|
|
687
|
+
if (r3) {
|
|
688
|
+
ptr1 = 0;
|
|
689
|
+
len1 = 0;
|
|
690
|
+
throw takeObject(r2);
|
|
691
|
+
}
|
|
692
|
+
deferred2_0 = ptr1;
|
|
693
|
+
deferred2_1 = len1;
|
|
694
|
+
return getStringFromWasm0(ptr1, len1);
|
|
695
|
+
} finally {
|
|
696
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
697
|
+
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Unix-seconds expiry of the unredeemed code.
|
|
702
|
+
*
|
|
703
|
+
* # Errors
|
|
704
|
+
*
|
|
705
|
+
* Returns an error if the request has been closed.
|
|
706
|
+
* @returns {number}
|
|
707
|
+
*/
|
|
708
|
+
expiresAt() {
|
|
709
|
+
try {
|
|
710
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
711
|
+
wasm.idkitinvitecoderequest_expiresAt(retptr, this.__wbg_ptr);
|
|
712
|
+
var r0 = getDataViewMemory0().getFloat64(retptr + 8 * 0, true);
|
|
713
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
714
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
715
|
+
if (r3) {
|
|
716
|
+
throw takeObject(r2);
|
|
717
|
+
}
|
|
718
|
+
return r0;
|
|
719
|
+
} finally {
|
|
720
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Polls the bridge for the current status (non-blocking).
|
|
725
|
+
*
|
|
726
|
+
* Mirrors `IDKitRequest::pollForStatus` exactly — same status shape,
|
|
727
|
+
* same close semantics. Adopters use the same poll loop they wrote for
|
|
728
|
+
* URL mode.
|
|
729
|
+
*
|
|
730
|
+
* # Errors
|
|
731
|
+
*
|
|
732
|
+
* Returns an error if the request has been closed or the poll fails.
|
|
733
|
+
* @returns {Promise<any>}
|
|
734
|
+
*/
|
|
735
|
+
pollForStatus() {
|
|
736
|
+
const ret = wasm.idkitinvitecoderequest_pollForStatus(this.__wbg_ptr);
|
|
737
|
+
return takeObject(ret);
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Returns the request ID for this request.
|
|
741
|
+
*
|
|
742
|
+
* # Errors
|
|
743
|
+
*
|
|
744
|
+
* Returns an error if the request has been closed.
|
|
745
|
+
* @returns {string}
|
|
746
|
+
*/
|
|
747
|
+
requestId() {
|
|
748
|
+
let deferred2_0;
|
|
749
|
+
let deferred2_1;
|
|
750
|
+
try {
|
|
751
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
752
|
+
wasm.idkitinvitecoderequest_requestId(retptr, this.__wbg_ptr);
|
|
753
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
754
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
755
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
756
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
757
|
+
var ptr1 = r0;
|
|
758
|
+
var len1 = r1;
|
|
759
|
+
if (r3) {
|
|
760
|
+
ptr1 = 0;
|
|
761
|
+
len1 = 0;
|
|
762
|
+
throw takeObject(r2);
|
|
763
|
+
}
|
|
764
|
+
deferred2_0 = ptr1;
|
|
765
|
+
deferred2_1 = len1;
|
|
766
|
+
return getStringFromWasm0(ptr1, len1);
|
|
767
|
+
} finally {
|
|
768
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
769
|
+
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
if (Symbol.dispose) IDKitInviteCodeRequest.prototype[Symbol.dispose] = IDKitInviteCodeRequest.prototype.free;
|
|
620
774
|
var IDKitProof = class {
|
|
621
775
|
__destroy_into_raw() {
|
|
622
776
|
const ptr = this.__wbg_ptr;
|
|
@@ -1053,6 +1207,21 @@ function hashSignal(signal) {
|
|
|
1053
1207
|
function init_wasm() {
|
|
1054
1208
|
wasm.init_wasm();
|
|
1055
1209
|
}
|
|
1210
|
+
function proofResponseToIDKitResult(proof_response, options) {
|
|
1211
|
+
try {
|
|
1212
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1213
|
+
wasm.proofResponseToIDKitResult(retptr, addHeapObject(proof_response), addHeapObject(options));
|
|
1214
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1215
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1216
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1217
|
+
if (r2) {
|
|
1218
|
+
throw takeObject(r1);
|
|
1219
|
+
}
|
|
1220
|
+
return takeObject(r0);
|
|
1221
|
+
} finally {
|
|
1222
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1056
1225
|
function proveSession(session_id, app_id, rp_context, action_description, bridge_url, override_connect_base_url, return_to, environment) {
|
|
1057
1226
|
const ptr0 = passStringToWasm0(session_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1058
1227
|
const len0 = WASM_VECTOR_LEN;
|
|
@@ -1119,6 +1288,10 @@ function __wbg_get_imports() {
|
|
|
1119
1288
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
1120
1289
|
return addHeapObject(ret);
|
|
1121
1290
|
},
|
|
1291
|
+
__wbg_Number_a5a435bd7bbec835: function(arg0) {
|
|
1292
|
+
const ret = Number(getObject(arg0));
|
|
1293
|
+
return ret;
|
|
1294
|
+
},
|
|
1122
1295
|
__wbg_String_8564e559799eccda: function(arg0, arg1) {
|
|
1123
1296
|
const ret = String(getObject(arg1));
|
|
1124
1297
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
@@ -1285,6 +1458,10 @@ function __wbg_get_imports() {
|
|
|
1285
1458
|
const ret = getObject(arg0)[arg1 >>> 0];
|
|
1286
1459
|
return addHeapObject(ret);
|
|
1287
1460
|
},
|
|
1461
|
+
__wbg_get_with_ref_key_6412cf3094599694: function(arg0, arg1) {
|
|
1462
|
+
const ret = getObject(arg0)[getObject(arg1)];
|
|
1463
|
+
return addHeapObject(ret);
|
|
1464
|
+
},
|
|
1288
1465
|
__wbg_has_926ef2ff40b308cf: function() {
|
|
1289
1466
|
return handleError(function(arg0, arg1) {
|
|
1290
1467
|
const ret = Reflect.has(getObject(arg0), getObject(arg1));
|
|
@@ -1295,6 +1472,10 @@ function __wbg_get_imports() {
|
|
|
1295
1472
|
const ret = getObject(arg0).headers;
|
|
1296
1473
|
return addHeapObject(ret);
|
|
1297
1474
|
},
|
|
1475
|
+
__wbg_idkitinvitecoderequest_new: function(arg0) {
|
|
1476
|
+
const ret = IDKitInviteCodeRequest.__wrap(arg0);
|
|
1477
|
+
return addHeapObject(ret);
|
|
1478
|
+
},
|
|
1298
1479
|
__wbg_idkitrequest_new: function(arg0) {
|
|
1299
1480
|
const ret = IDKitRequest.__wrap(arg0);
|
|
1300
1481
|
return addHeapObject(ret);
|
|
@@ -1406,7 +1587,7 @@ function __wbg_get_imports() {
|
|
|
1406
1587
|
const a = state0.a;
|
|
1407
1588
|
state0.a = 0;
|
|
1408
1589
|
try {
|
|
1409
|
-
return
|
|
1590
|
+
return __wasm_bindgen_func_elem_1544(a, state0.b, arg02, arg12);
|
|
1410
1591
|
} finally {
|
|
1411
1592
|
state0.a = a;
|
|
1412
1593
|
}
|
|
@@ -1586,11 +1767,11 @@ function __wbg_get_imports() {
|
|
|
1586
1767
|
return addHeapObject(ret);
|
|
1587
1768
|
},
|
|
1588
1769
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
1589
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
1770
|
+
const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_751, __wasm_bindgen_func_elem_752);
|
|
1590
1771
|
return addHeapObject(ret);
|
|
1591
1772
|
},
|
|
1592
1773
|
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
1593
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
1774
|
+
const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_1079, __wasm_bindgen_func_elem_1080);
|
|
1594
1775
|
return addHeapObject(ret);
|
|
1595
1776
|
},
|
|
1596
1777
|
__wbindgen_cast_0000000000000003: function(arg0) {
|
|
@@ -1626,13 +1807,13 @@ function __wbg_get_imports() {
|
|
|
1626
1807
|
"./idkit_wasm_bg.js": import0
|
|
1627
1808
|
};
|
|
1628
1809
|
}
|
|
1629
|
-
function
|
|
1630
|
-
wasm.
|
|
1810
|
+
function __wasm_bindgen_func_elem_752(arg0, arg1) {
|
|
1811
|
+
wasm.__wasm_bindgen_func_elem_752(arg0, arg1);
|
|
1631
1812
|
}
|
|
1632
|
-
function
|
|
1813
|
+
function __wasm_bindgen_func_elem_1080(arg0, arg1, arg2) {
|
|
1633
1814
|
try {
|
|
1634
1815
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1635
|
-
wasm.
|
|
1816
|
+
wasm.__wasm_bindgen_func_elem_1080(retptr, arg0, arg1, addHeapObject(arg2));
|
|
1636
1817
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1637
1818
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1638
1819
|
if (r1) {
|
|
@@ -1642,8 +1823,8 @@ function __wasm_bindgen_func_elem_1028(arg0, arg1, arg2) {
|
|
|
1642
1823
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1643
1824
|
}
|
|
1644
1825
|
}
|
|
1645
|
-
function
|
|
1646
|
-
wasm.
|
|
1826
|
+
function __wasm_bindgen_func_elem_1544(arg0, arg1, arg2, arg3) {
|
|
1827
|
+
wasm.__wasm_bindgen_func_elem_1544(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
|
|
1647
1828
|
}
|
|
1648
1829
|
var __wbindgen_enum_RequestCache = ["default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached"];
|
|
1649
1830
|
var __wbindgen_enum_RequestCredentials = ["omit", "same-origin", "include"];
|
|
@@ -1657,6 +1838,9 @@ var CredentialRequestWasmFinalization = typeof FinalizationRegistry === "undefin
|
|
|
1657
1838
|
var IDKitBuilderFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
1658
1839
|
}, unregister: () => {
|
|
1659
1840
|
} } : new FinalizationRegistry((ptr) => wasm.__wbg_idkitbuilder_free(ptr >>> 0, 1));
|
|
1841
|
+
var IDKitInviteCodeRequestFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
1842
|
+
}, unregister: () => {
|
|
1843
|
+
} } : new FinalizationRegistry((ptr) => wasm.__wbg_idkitinvitecoderequest_free(ptr >>> 0, 1));
|
|
1660
1844
|
var IDKitProofFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
1661
1845
|
}, unregister: () => {
|
|
1662
1846
|
} } : new FinalizationRegistry((ptr) => wasm.__wbg_idkitproof_free(ptr >>> 0, 1));
|
|
@@ -1984,6 +2168,10 @@ function setDebug(enabled) {
|
|
|
1984
2168
|
|
|
1985
2169
|
// src/transports/native.ts
|
|
1986
2170
|
var MINIAPP_VERIFY_ACTION = "miniapp-verify-action";
|
|
2171
|
+
function toNativeErrorCode(error) {
|
|
2172
|
+
const code = error instanceof Error ? error.message : String(error);
|
|
2173
|
+
return Object.values(IDKitErrorCodes).includes(code) ? code : "generic_error" /* GenericError */;
|
|
2174
|
+
}
|
|
1987
2175
|
function isInWorldApp() {
|
|
1988
2176
|
return typeof window !== "undefined" && Boolean(window.WorldApp);
|
|
1989
2177
|
}
|
|
@@ -2026,6 +2214,8 @@ var NativeIDKitRequest = class {
|
|
|
2026
2214
|
this.resolveFn = resolve;
|
|
2027
2215
|
const handleIncomingPayload = (responsePayload) => {
|
|
2028
2216
|
if (this.completionResult) return;
|
|
2217
|
+
if (isDebug())
|
|
2218
|
+
console.debug("[IDKit] Native: received response", responsePayload);
|
|
2029
2219
|
if (responsePayload?.status === "error") {
|
|
2030
2220
|
if (isDebug())
|
|
2031
2221
|
console.warn(
|
|
@@ -2038,15 +2228,27 @@ var NativeIDKitRequest = class {
|
|
|
2038
2228
|
});
|
|
2039
2229
|
return;
|
|
2040
2230
|
}
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
result: nativeResultToIDKitResult(
|
|
2231
|
+
try {
|
|
2232
|
+
const result = nativeResultToIDKitResult(
|
|
2044
2233
|
responsePayload,
|
|
2045
2234
|
config,
|
|
2046
2235
|
signalHashes,
|
|
2047
2236
|
legacySignalHash
|
|
2048
|
-
)
|
|
2049
|
-
|
|
2237
|
+
);
|
|
2238
|
+
if (isDebug())
|
|
2239
|
+
console.debug(
|
|
2240
|
+
"[IDKit] Native: mapped response",
|
|
2241
|
+
result.protocol_version
|
|
2242
|
+
);
|
|
2243
|
+
this.complete({ success: true, result });
|
|
2244
|
+
} catch (error) {
|
|
2245
|
+
if (isDebug())
|
|
2246
|
+
console.warn("[IDKit] Native: failed to map response", error);
|
|
2247
|
+
this.complete({
|
|
2248
|
+
success: false,
|
|
2249
|
+
error: toNativeErrorCode(error)
|
|
2250
|
+
});
|
|
2251
|
+
}
|
|
2050
2252
|
};
|
|
2051
2253
|
const handler = (event) => {
|
|
2052
2254
|
const data = event.data;
|
|
@@ -2079,13 +2281,15 @@ var NativeIDKitRequest = class {
|
|
|
2079
2281
|
if (w.webkit?.messageHandlers?.minikit) {
|
|
2080
2282
|
if (isDebug())
|
|
2081
2283
|
console.debug(
|
|
2082
|
-
`[IDKit] Native: sending verify command (version=${version}, platform=ios)
|
|
2284
|
+
`[IDKit] Native: sending verify command (version=${version}, platform=ios)`,
|
|
2285
|
+
sendPayload
|
|
2083
2286
|
);
|
|
2084
2287
|
w.webkit.messageHandlers.minikit.postMessage(sendPayload);
|
|
2085
2288
|
} else if (w.Android) {
|
|
2086
2289
|
if (isDebug())
|
|
2087
2290
|
console.debug(
|
|
2088
|
-
`[IDKit] Native: sending verify command (version=${version}, platform=android)
|
|
2291
|
+
`[IDKit] Native: sending verify command (version=${version}, platform=android)`,
|
|
2292
|
+
sendPayload
|
|
2089
2293
|
);
|
|
2090
2294
|
w.Android.postMessage(JSON.stringify(sendPayload));
|
|
2091
2295
|
} else {
|
|
@@ -2113,7 +2317,7 @@ var NativeIDKitRequest = class {
|
|
|
2113
2317
|
if (isDebug())
|
|
2114
2318
|
console.debug(
|
|
2115
2319
|
"[IDKit] Native: request completed",
|
|
2116
|
-
result.success ? "success" : `error=${result.error}`
|
|
2320
|
+
result.success === true ? "success" : `error=${result.error}`
|
|
2117
2321
|
);
|
|
2118
2322
|
this.completionResult = result;
|
|
2119
2323
|
this.cleanup();
|
|
@@ -2145,13 +2349,14 @@ var NativeIDKitRequest = class {
|
|
|
2145
2349
|
return this.completionResult === null;
|
|
2146
2350
|
}
|
|
2147
2351
|
async pollOnce() {
|
|
2148
|
-
|
|
2352
|
+
const completionResult = this.completionResult;
|
|
2353
|
+
if (!completionResult) {
|
|
2149
2354
|
return { type: "awaiting_confirmation" };
|
|
2150
2355
|
}
|
|
2151
|
-
if (
|
|
2152
|
-
return { type: "confirmed", result:
|
|
2356
|
+
if (completionResult.success === true) {
|
|
2357
|
+
return { type: "confirmed", result: completionResult.result };
|
|
2153
2358
|
}
|
|
2154
|
-
return { type: "failed", error:
|
|
2359
|
+
return { type: "failed", error: completionResult.error };
|
|
2155
2360
|
}
|
|
2156
2361
|
async pollUntilCompletion(options) {
|
|
2157
2362
|
const timeout = options?.timeout ?? 9e5;
|
|
@@ -2189,39 +2394,24 @@ function nativeResultToIDKitResult(payload, config, signalHashes, legacySignalHa
|
|
|
2189
2394
|
const rpNonce = config.rp_context?.nonce ?? "";
|
|
2190
2395
|
if ("proof_response" in p && p.proof_response != null) {
|
|
2191
2396
|
const proof_response = p.proof_response;
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
return {
|
|
2211
|
-
protocol_version: "4.0",
|
|
2212
|
-
nonce: proof_response.nonce ?? rpNonce,
|
|
2213
|
-
action: proof_response.action ?? config.action ?? "",
|
|
2214
|
-
action_description: proof_response.action_description,
|
|
2215
|
-
responses: items.map((item) => ({
|
|
2216
|
-
identifier: item.identifier,
|
|
2217
|
-
signal_hash: signalHashes[item.identifier],
|
|
2218
|
-
proof: item.proof,
|
|
2219
|
-
nullifier: item.nullifier,
|
|
2220
|
-
issuer_schema_id: item.issuer_schema_id,
|
|
2221
|
-
expires_at_min: item.expires_at_min
|
|
2222
|
-
})),
|
|
2223
|
-
environment: config.environment ?? "production"
|
|
2224
|
-
};
|
|
2397
|
+
if (isDebug())
|
|
2398
|
+
console.debug("[IDKit] Native: mapping wrapped v4 proof_response", {
|
|
2399
|
+
responseCount: proof_response.responses?.length,
|
|
2400
|
+
responseIdentifiers: proof_response.responses?.map(
|
|
2401
|
+
(item) => item.identifier
|
|
2402
|
+
)
|
|
2403
|
+
});
|
|
2404
|
+
return idkit_wasm_exports.proofResponseToIDKitResult(proof_response, {
|
|
2405
|
+
nonce: rpNonce,
|
|
2406
|
+
action: config.action,
|
|
2407
|
+
action_description: config.action_description,
|
|
2408
|
+
environment: config.environment ?? "production",
|
|
2409
|
+
signal_hashes: signalHashes,
|
|
2410
|
+
identity_attested: p.identity_attested
|
|
2411
|
+
});
|
|
2412
|
+
}
|
|
2413
|
+
if (Array.isArray(p.responses) && ("id" in p || "version" in p || "error" in p)) {
|
|
2414
|
+
throw new Error("unexpected_response" /* UnexpectedResponse */);
|
|
2225
2415
|
}
|
|
2226
2416
|
if ("verifications" in p && Array.isArray(p.verifications)) {
|
|
2227
2417
|
const verifications = p.verifications;
|
|
@@ -2258,6 +2448,30 @@ function nativeResultToIDKitResult(payload, config, signalHashes, legacySignalHa
|
|
|
2258
2448
|
|
|
2259
2449
|
// src/request.ts
|
|
2260
2450
|
var SESSION_ID_PATTERN = /^session_[0-9a-fA-F]{128}$/;
|
|
2451
|
+
async function pollUntilCompletionLoop(pollOnce, options) {
|
|
2452
|
+
const pollInterval = options?.pollInterval ?? 1e3;
|
|
2453
|
+
const timeout = options?.timeout ?? 9e5;
|
|
2454
|
+
const startTime = Date.now();
|
|
2455
|
+
while (true) {
|
|
2456
|
+
if (options?.signal?.aborted) {
|
|
2457
|
+
return { success: false, error: "cancelled" /* Cancelled */ };
|
|
2458
|
+
}
|
|
2459
|
+
if (Date.now() - startTime > timeout) {
|
|
2460
|
+
return { success: false, error: "timeout" /* Timeout */ };
|
|
2461
|
+
}
|
|
2462
|
+
const status = await pollOnce();
|
|
2463
|
+
if (status.type === "confirmed" && status.result) {
|
|
2464
|
+
return { success: true, result: status.result };
|
|
2465
|
+
}
|
|
2466
|
+
if (status.type === "failed") {
|
|
2467
|
+
return {
|
|
2468
|
+
success: false,
|
|
2469
|
+
error: status.error ?? "generic_error" /* GenericError */
|
|
2470
|
+
};
|
|
2471
|
+
}
|
|
2472
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2261
2475
|
var IDKitRequestImpl = class {
|
|
2262
2476
|
constructor(wasmRequest) {
|
|
2263
2477
|
this.wasmRequest = wasmRequest;
|
|
@@ -2273,29 +2487,31 @@ var IDKitRequestImpl = class {
|
|
|
2273
2487
|
async pollOnce() {
|
|
2274
2488
|
return await this.wasmRequest.pollForStatus();
|
|
2275
2489
|
}
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2490
|
+
pollUntilCompletion(options) {
|
|
2491
|
+
return pollUntilCompletionLoop(() => this.pollOnce(), options);
|
|
2492
|
+
}
|
|
2493
|
+
};
|
|
2494
|
+
var IDKitInviteCodeRequestImpl = class {
|
|
2495
|
+
constructor(wasmRequest) {
|
|
2496
|
+
this.wasmRequest = wasmRequest;
|
|
2497
|
+
this._connectorURI = wasmRequest.connectUrl();
|
|
2498
|
+
this._expiresAt = wasmRequest.expiresAt();
|
|
2499
|
+
this._requestId = wasmRequest.requestId();
|
|
2500
|
+
}
|
|
2501
|
+
get connectorURI() {
|
|
2502
|
+
return this._connectorURI;
|
|
2503
|
+
}
|
|
2504
|
+
get expiresAt() {
|
|
2505
|
+
return this._expiresAt;
|
|
2506
|
+
}
|
|
2507
|
+
get requestId() {
|
|
2508
|
+
return this._requestId;
|
|
2509
|
+
}
|
|
2510
|
+
async pollOnce() {
|
|
2511
|
+
return await this.wasmRequest.pollForStatus();
|
|
2512
|
+
}
|
|
2513
|
+
pollUntilCompletion(options) {
|
|
2514
|
+
return pollUntilCompletionLoop(() => this.pollOnce(), options);
|
|
2299
2515
|
}
|
|
2300
2516
|
};
|
|
2301
2517
|
function CredentialRequest(credential_type, options) {
|
|
@@ -2478,6 +2694,51 @@ var IDKitBuilder2 = class {
|
|
|
2478
2694
|
return new IDKitRequestImpl(wasmRequest);
|
|
2479
2695
|
}
|
|
2480
2696
|
};
|
|
2697
|
+
var IDKitInviteCodeBuilder = class {
|
|
2698
|
+
constructor(config) {
|
|
2699
|
+
this.config = config;
|
|
2700
|
+
}
|
|
2701
|
+
/**
|
|
2702
|
+
* Creates an invite-code mode IDKit request with the given constraints.
|
|
2703
|
+
*
|
|
2704
|
+
* @param constraints - Constraint tree (CredentialRequest or any/all/enumerate combinators)
|
|
2705
|
+
* @returns A new IDKitInviteCodeRequest instance
|
|
2706
|
+
*
|
|
2707
|
+
* @example
|
|
2708
|
+
* ```typescript
|
|
2709
|
+
* const request = await IDKit.requestWithInviteCode({ app_id, action, rp_context, allow_legacy_proofs: false })
|
|
2710
|
+
* .constraints(any(CredentialRequest('proof_of_human'), CredentialRequest('face')));
|
|
2711
|
+
* displayLink(request.connectorURI);
|
|
2712
|
+
* ```
|
|
2713
|
+
*/
|
|
2714
|
+
async constraints(constraints) {
|
|
2715
|
+
await initIDKit();
|
|
2716
|
+
const wasmBuilder = createWasmBuilderFromConfig(this.config);
|
|
2717
|
+
const wasmRequest = await wasmBuilder.constraintsWithInviteCode(
|
|
2718
|
+
constraints
|
|
2719
|
+
);
|
|
2720
|
+
return new IDKitInviteCodeRequestImpl(wasmRequest);
|
|
2721
|
+
}
|
|
2722
|
+
/**
|
|
2723
|
+
* Creates an invite-code mode IDKit request from a preset.
|
|
2724
|
+
*
|
|
2725
|
+
* @param preset - A preset object from orbLegacy(), secureDocumentLegacy(), documentLegacy(), selfieCheckLegacy(), or deviceLegacy()
|
|
2726
|
+
* @returns A new IDKitInviteCodeRequest instance
|
|
2727
|
+
*/
|
|
2728
|
+
async preset(preset) {
|
|
2729
|
+
if (this.config.type === "createSession" || this.config.type === "proveSession") {
|
|
2730
|
+
throw new Error(
|
|
2731
|
+
"Presets are not supported for session flows. Use .constraints() instead."
|
|
2732
|
+
);
|
|
2733
|
+
}
|
|
2734
|
+
await initIDKit();
|
|
2735
|
+
const wasmBuilder = createWasmBuilderFromConfig(this.config);
|
|
2736
|
+
const wasmRequest = await wasmBuilder.presetWithInviteCode(
|
|
2737
|
+
preset
|
|
2738
|
+
);
|
|
2739
|
+
return new IDKitInviteCodeRequestImpl(wasmRequest);
|
|
2740
|
+
}
|
|
2741
|
+
};
|
|
2481
2742
|
function createRequest(config) {
|
|
2482
2743
|
if (!config.app_id) {
|
|
2483
2744
|
throw new Error("app_id is required");
|
|
@@ -2508,6 +2769,36 @@ function createRequest(config) {
|
|
|
2508
2769
|
environment: config.environment
|
|
2509
2770
|
});
|
|
2510
2771
|
}
|
|
2772
|
+
function createRequestWithInviteCode(config) {
|
|
2773
|
+
if (!config.app_id) {
|
|
2774
|
+
throw new Error("app_id is required");
|
|
2775
|
+
}
|
|
2776
|
+
if (!config.action) {
|
|
2777
|
+
throw new Error("action is required");
|
|
2778
|
+
}
|
|
2779
|
+
if (!config.rp_context) {
|
|
2780
|
+
throw new Error(
|
|
2781
|
+
"rp_context is required. Generate it on your backend using signRequest()."
|
|
2782
|
+
);
|
|
2783
|
+
}
|
|
2784
|
+
if (typeof config.allow_legacy_proofs !== "boolean") {
|
|
2785
|
+
throw new Error(
|
|
2786
|
+
"allow_legacy_proofs is required. Set to true to accept v3 proofs during migration, or false to only accept v4 proofs."
|
|
2787
|
+
);
|
|
2788
|
+
}
|
|
2789
|
+
return new IDKitInviteCodeBuilder({
|
|
2790
|
+
type: "request",
|
|
2791
|
+
app_id: config.app_id,
|
|
2792
|
+
action: String(config.action),
|
|
2793
|
+
rp_context: config.rp_context,
|
|
2794
|
+
action_description: config.action_description,
|
|
2795
|
+
bridge_url: config.bridge_url,
|
|
2796
|
+
return_to: config.return_to,
|
|
2797
|
+
allow_legacy_proofs: config.allow_legacy_proofs,
|
|
2798
|
+
override_connect_base_url: config.override_connect_base_url,
|
|
2799
|
+
environment: config.environment
|
|
2800
|
+
});
|
|
2801
|
+
}
|
|
2511
2802
|
function createSession2(config) {
|
|
2512
2803
|
if (!config.app_id) {
|
|
2513
2804
|
throw new Error("app_id is required");
|
|
@@ -2560,6 +2851,8 @@ function proveSession2(sessionId, config) {
|
|
|
2560
2851
|
var IDKit = {
|
|
2561
2852
|
/** Create a new verification request */
|
|
2562
2853
|
request: createRequest,
|
|
2854
|
+
/** Create a new invite-code mode verification request (WDP-73) */
|
|
2855
|
+
requestWithInviteCode: createRequestWithInviteCode,
|
|
2563
2856
|
/** Create a new session (no action, no existing session_id) */
|
|
2564
2857
|
createSession: createSession2,
|
|
2565
2858
|
/** Prove an existing session (no action, has session_id) */
|