@worldcoin/idkit-core 4.0.1 → 4.0.2
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/README.md +19 -8
- package/dist/hashing.cjs +28 -0
- package/dist/hashing.d.cts +9 -0
- package/dist/hashing.d.ts +9 -0
- package/dist/hashing.js +26 -0
- package/dist/idkit_wasm_bg.wasm +0 -0
- package/dist/index.cjs +464 -140
- package/dist/index.d.cts +82 -214
- package/dist/index.d.ts +82 -214
- package/dist/index.js +464 -140
- package/dist/signing.cjs +76 -0
- package/dist/signing.d.cts +36 -0
- package/dist/signing.d.ts +36 -0
- package/dist/signing.js +73 -0
- package/package.json +15 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { keccak_256 } from '@noble/hashes/sha3';
|
|
2
|
+
import { hexToBytes, bytesToHex } from '@noble/hashes/utils';
|
|
3
|
+
import { hmac } from '@noble/hashes/hmac';
|
|
4
|
+
import { sha256 } from '@noble/hashes/sha2';
|
|
5
|
+
import { etc, sign } from '@noble/secp256k1';
|
|
6
|
+
|
|
1
7
|
var __defProp = Object.defineProperty;
|
|
2
8
|
var __export = (target, all2) => {
|
|
3
9
|
for (var name in all2)
|
|
@@ -242,6 +248,22 @@ function _assertClass(instance, klass) {
|
|
|
242
248
|
throw new Error(`expected instance of ${klass.name}`);
|
|
243
249
|
}
|
|
244
250
|
}
|
|
251
|
+
function createSession(app_id, rp_context, action_description, bridge_url, override_connect_base_url, environment) {
|
|
252
|
+
const ptr0 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
253
|
+
const len0 = WASM_VECTOR_LEN;
|
|
254
|
+
_assertClass(rp_context, RpContextWasm);
|
|
255
|
+
var ptr1 = rp_context.__destroy_into_raw();
|
|
256
|
+
var ptr2 = isLikeNone(action_description) ? 0 : passStringToWasm0(action_description, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
257
|
+
var len2 = WASM_VECTOR_LEN;
|
|
258
|
+
var ptr3 = isLikeNone(bridge_url) ? 0 : passStringToWasm0(bridge_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
259
|
+
var len3 = WASM_VECTOR_LEN;
|
|
260
|
+
var ptr4 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
261
|
+
var len4 = WASM_VECTOR_LEN;
|
|
262
|
+
var ptr5 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
263
|
+
var len5 = WASM_VECTOR_LEN;
|
|
264
|
+
const ret = wasm.createSession(ptr0, len0, ptr1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
|
|
265
|
+
return IDKitBuilder.__wrap(ret);
|
|
266
|
+
}
|
|
245
267
|
function request(app_id, action, rp_context, action_description, bridge_url, allow_legacy_proofs, override_connect_base_url, environment) {
|
|
246
268
|
const ptr0 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
247
269
|
const len0 = WASM_VECTOR_LEN;
|
|
@@ -260,9 +282,6 @@ function request(app_id, action, rp_context, action_description, bridge_url, all
|
|
|
260
282
|
const ret = wasm.idkitbuilder_new(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, allow_legacy_proofs, ptr5, len5, ptr6, len6);
|
|
261
283
|
return IDKitBuilder.__wrap(ret);
|
|
262
284
|
}
|
|
263
|
-
function init_wasm() {
|
|
264
|
-
wasm.init_wasm();
|
|
265
|
-
}
|
|
266
285
|
function base64Decode(data) {
|
|
267
286
|
try {
|
|
268
287
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
@@ -301,22 +320,6 @@ function proveSession(session_id, app_id, rp_context, action_description, bridge
|
|
|
301
320
|
const ret = wasm.idkitbuilder_forProveSession(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6);
|
|
302
321
|
return IDKitBuilder.__wrap(ret);
|
|
303
322
|
}
|
|
304
|
-
function createSession(app_id, rp_context, action_description, bridge_url, override_connect_base_url, environment) {
|
|
305
|
-
const ptr0 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
306
|
-
const len0 = WASM_VECTOR_LEN;
|
|
307
|
-
_assertClass(rp_context, RpContextWasm);
|
|
308
|
-
var ptr1 = rp_context.__destroy_into_raw();
|
|
309
|
-
var ptr2 = isLikeNone(action_description) ? 0 : passStringToWasm0(action_description, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
310
|
-
var len2 = WASM_VECTOR_LEN;
|
|
311
|
-
var ptr3 = isLikeNone(bridge_url) ? 0 : passStringToWasm0(bridge_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
312
|
-
var len3 = WASM_VECTOR_LEN;
|
|
313
|
-
var ptr4 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
314
|
-
var len4 = WASM_VECTOR_LEN;
|
|
315
|
-
var ptr5 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
316
|
-
var len5 = WASM_VECTOR_LEN;
|
|
317
|
-
const ret = wasm.createSession(ptr0, len0, ptr1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
|
|
318
|
-
return IDKitBuilder.__wrap(ret);
|
|
319
|
-
}
|
|
320
323
|
function passArray8ToWasm0(arg, malloc) {
|
|
321
324
|
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
322
325
|
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
@@ -341,6 +344,28 @@ function base64Encode(data) {
|
|
|
341
344
|
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
342
345
|
}
|
|
343
346
|
}
|
|
347
|
+
function init_wasm() {
|
|
348
|
+
wasm.init_wasm();
|
|
349
|
+
}
|
|
350
|
+
function signRequest(action, signing_key_hex, ttl_seconds) {
|
|
351
|
+
try {
|
|
352
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
353
|
+
const ptr0 = passStringToWasm0(action, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
354
|
+
const len0 = WASM_VECTOR_LEN;
|
|
355
|
+
const ptr1 = passStringToWasm0(signing_key_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
356
|
+
const len1 = WASM_VECTOR_LEN;
|
|
357
|
+
wasm.signRequest(retptr, ptr0, len0, ptr1, len1, !isLikeNone(ttl_seconds), isLikeNone(ttl_seconds) ? BigInt(0) : ttl_seconds);
|
|
358
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
359
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
360
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
361
|
+
if (r2) {
|
|
362
|
+
throw takeObject(r1);
|
|
363
|
+
}
|
|
364
|
+
return RpSignature.__wrap(r0);
|
|
365
|
+
} finally {
|
|
366
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
344
369
|
function hashSignal(signal) {
|
|
345
370
|
let deferred2_0;
|
|
346
371
|
let deferred2_1;
|
|
@@ -366,33 +391,14 @@ function hashSignal(signal) {
|
|
|
366
391
|
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
367
392
|
}
|
|
368
393
|
}
|
|
369
|
-
function signRequest(action, signing_key_hex, ttl_seconds) {
|
|
370
|
-
try {
|
|
371
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
372
|
-
const ptr0 = passStringToWasm0(action, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
373
|
-
const len0 = WASM_VECTOR_LEN;
|
|
374
|
-
const ptr1 = passStringToWasm0(signing_key_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
375
|
-
const len1 = WASM_VECTOR_LEN;
|
|
376
|
-
wasm.signRequest(retptr, ptr0, len0, ptr1, len1, !isLikeNone(ttl_seconds), isLikeNone(ttl_seconds) ? BigInt(0) : ttl_seconds);
|
|
377
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
378
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
379
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
380
|
-
if (r2) {
|
|
381
|
-
throw takeObject(r1);
|
|
382
|
-
}
|
|
383
|
-
return RpSignature.__wrap(r0);
|
|
384
|
-
} finally {
|
|
385
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
394
|
function __wasm_bindgen_func_elem_960(arg0, arg1, arg2) {
|
|
389
395
|
wasm.__wasm_bindgen_func_elem_960(arg0, arg1, addHeapObject(arg2));
|
|
390
396
|
}
|
|
391
397
|
function __wasm_bindgen_func_elem_597(arg0, arg1) {
|
|
392
398
|
wasm.__wasm_bindgen_func_elem_597(arg0, arg1);
|
|
393
399
|
}
|
|
394
|
-
function
|
|
395
|
-
wasm.
|
|
400
|
+
function __wasm_bindgen_func_elem_1345(arg0, arg1, arg2, arg3) {
|
|
401
|
+
wasm.__wasm_bindgen_func_elem_1345(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
|
|
396
402
|
}
|
|
397
403
|
var __wbindgen_enum_RequestCache = ["default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached"];
|
|
398
404
|
var __wbindgen_enum_RequestCredentials = ["omit", "same-origin", "include"];
|
|
@@ -769,6 +775,34 @@ var IDKitBuilder = class _IDKitBuilder {
|
|
|
769
775
|
const ret = wasm.idkitbuilder_constraints(ptr, addHeapObject(constraints_json));
|
|
770
776
|
return takeObject(ret);
|
|
771
777
|
}
|
|
778
|
+
/**
|
|
779
|
+
* Builds the native payload for constraints (synchronous, no bridge connection).
|
|
780
|
+
*
|
|
781
|
+
* Used by the native transport to get the same payload format as the bridge
|
|
782
|
+
* without creating a network connection.
|
|
783
|
+
*
|
|
784
|
+
* # Errors
|
|
785
|
+
*
|
|
786
|
+
* Returns an error if constraints are invalid or payload construction fails.
|
|
787
|
+
* @param {any} constraints_json
|
|
788
|
+
* @returns {any}
|
|
789
|
+
*/
|
|
790
|
+
nativePayload(constraints_json) {
|
|
791
|
+
try {
|
|
792
|
+
const ptr = this.__destroy_into_raw();
|
|
793
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
794
|
+
wasm.idkitbuilder_nativePayload(retptr, ptr, addHeapObject(constraints_json));
|
|
795
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
796
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
797
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
798
|
+
if (r2) {
|
|
799
|
+
throw takeObject(r1);
|
|
800
|
+
}
|
|
801
|
+
return takeObject(r0);
|
|
802
|
+
} finally {
|
|
803
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
772
806
|
/**
|
|
773
807
|
* Creates a new builder for proving an existing session
|
|
774
808
|
* @param {string} session_id
|
|
@@ -824,6 +858,34 @@ var IDKitBuilder = class _IDKitBuilder {
|
|
|
824
858
|
const ret = wasm.createSession(ptr0, len0, ptr1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
|
|
825
859
|
return _IDKitBuilder.__wrap(ret);
|
|
826
860
|
}
|
|
861
|
+
/**
|
|
862
|
+
* Builds the native payload from a preset (synchronous, no bridge connection).
|
|
863
|
+
*
|
|
864
|
+
* Used by the native transport to get the same payload format as the bridge
|
|
865
|
+
* without creating a network connection.
|
|
866
|
+
*
|
|
867
|
+
* # Errors
|
|
868
|
+
*
|
|
869
|
+
* Returns an error if the preset is invalid or payload construction fails.
|
|
870
|
+
* @param {any} preset_json
|
|
871
|
+
* @returns {any}
|
|
872
|
+
*/
|
|
873
|
+
nativePayloadFromPreset(preset_json) {
|
|
874
|
+
try {
|
|
875
|
+
const ptr = this.__destroy_into_raw();
|
|
876
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
877
|
+
wasm.idkitbuilder_nativePayloadFromPreset(retptr, ptr, addHeapObject(preset_json));
|
|
878
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
879
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
880
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
881
|
+
if (r2) {
|
|
882
|
+
throw takeObject(r1);
|
|
883
|
+
}
|
|
884
|
+
return takeObject(r0);
|
|
885
|
+
} finally {
|
|
886
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
827
889
|
/**
|
|
828
890
|
* Creates a new builder for uniqueness requests
|
|
829
891
|
* @param {string} app_id
|
|
@@ -1499,7 +1561,7 @@ function __wbg_get_imports() {
|
|
|
1499
1561
|
const a = state0.a;
|
|
1500
1562
|
state0.a = 0;
|
|
1501
1563
|
try {
|
|
1502
|
-
return
|
|
1564
|
+
return __wasm_bindgen_func_elem_1345(a, state0.b, arg02, arg12);
|
|
1503
1565
|
} finally {
|
|
1504
1566
|
state0.a = a;
|
|
1505
1567
|
}
|
|
@@ -1811,27 +1873,206 @@ async function initIDKit() {
|
|
|
1811
1873
|
})();
|
|
1812
1874
|
return wasmInitPromise;
|
|
1813
1875
|
}
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1876
|
+
|
|
1877
|
+
// src/transports/native.ts
|
|
1878
|
+
function isInWorldApp() {
|
|
1879
|
+
return typeof window !== "undefined" && Boolean(window.WorldApp);
|
|
1880
|
+
}
|
|
1881
|
+
var _requestCounter = 0;
|
|
1882
|
+
var _activeNativeRequest = null;
|
|
1883
|
+
function createNativeRequest(wasmPayload, config) {
|
|
1884
|
+
if (_activeNativeRequest?.isPending()) {
|
|
1885
|
+
console.warn(
|
|
1886
|
+
"IDKit native request already in flight. Reusing active request."
|
|
1887
|
+
);
|
|
1888
|
+
return _activeNativeRequest;
|
|
1817
1889
|
}
|
|
1818
|
-
|
|
1819
|
-
|
|
1890
|
+
const request2 = new NativeIDKitRequest(wasmPayload, config);
|
|
1891
|
+
_activeNativeRequest = request2;
|
|
1892
|
+
return request2;
|
|
1893
|
+
}
|
|
1894
|
+
var NativeIDKitRequest = class {
|
|
1895
|
+
constructor(wasmPayload, config) {
|
|
1896
|
+
this.connectorURI = "";
|
|
1897
|
+
this.resolved = false;
|
|
1898
|
+
this.cancelled = false;
|
|
1899
|
+
this.settled = false;
|
|
1900
|
+
this.resolvedResult = null;
|
|
1901
|
+
this.messageHandler = null;
|
|
1902
|
+
this.rejectFn = null;
|
|
1903
|
+
this.requestId = crypto.randomUUID?.() ?? `native-${Date.now()}-${++_requestCounter}`;
|
|
1904
|
+
this.resultPromise = new Promise((resolve, reject) => {
|
|
1905
|
+
this.rejectFn = reject;
|
|
1906
|
+
const handler = (event) => {
|
|
1907
|
+
if (this.cancelled) return;
|
|
1908
|
+
const data = event.data;
|
|
1909
|
+
if (data?.type === "miniapp-verify-action" || data?.command === "miniapp-verify-action") {
|
|
1910
|
+
this.cleanup();
|
|
1911
|
+
const responsePayload = data.payload ?? data;
|
|
1912
|
+
if (responsePayload.status === "error") {
|
|
1913
|
+
reject(
|
|
1914
|
+
new NativeVerifyError(
|
|
1915
|
+
responsePayload.error_code ?? "generic_error" /* GenericError */
|
|
1916
|
+
)
|
|
1917
|
+
);
|
|
1918
|
+
} else {
|
|
1919
|
+
this.resolved = true;
|
|
1920
|
+
const result = nativeResultToIDKitResult(responsePayload, config);
|
|
1921
|
+
this.resolvedResult = result;
|
|
1922
|
+
resolve(result);
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
};
|
|
1926
|
+
this.messageHandler = handler;
|
|
1927
|
+
window.addEventListener("message", handler);
|
|
1928
|
+
const sendPayload = {
|
|
1929
|
+
command: "verify",
|
|
1930
|
+
version: 2,
|
|
1931
|
+
payload: wasmPayload
|
|
1932
|
+
};
|
|
1933
|
+
const w = window;
|
|
1934
|
+
if (w.webkit?.messageHandlers?.minikit) {
|
|
1935
|
+
w.webkit.messageHandlers.minikit.postMessage(sendPayload);
|
|
1936
|
+
} else if (w.Android) {
|
|
1937
|
+
w.Android.postMessage(JSON.stringify(sendPayload));
|
|
1938
|
+
} else {
|
|
1939
|
+
this.cleanup();
|
|
1940
|
+
reject(new Error("No WebView bridge available"));
|
|
1941
|
+
}
|
|
1942
|
+
});
|
|
1943
|
+
this.resultPromise.catch(() => {
|
|
1944
|
+
}).finally(() => {
|
|
1945
|
+
this.settled = true;
|
|
1946
|
+
this.cleanup();
|
|
1947
|
+
if (_activeNativeRequest === this) {
|
|
1948
|
+
_activeNativeRequest = null;
|
|
1949
|
+
}
|
|
1950
|
+
});
|
|
1820
1951
|
}
|
|
1821
|
-
|
|
1952
|
+
/**
|
|
1953
|
+
* Cancel this request. Removes the message listener so it cannot consume
|
|
1954
|
+
* a response meant for a later request, and rejects the pending promise.
|
|
1955
|
+
*/
|
|
1956
|
+
cancel() {
|
|
1957
|
+
if (this.resolved || this.cancelled) return;
|
|
1958
|
+
this.cancelled = true;
|
|
1959
|
+
this.cleanup();
|
|
1960
|
+
this.rejectFn?.(new NativeVerifyError("cancelled" /* Cancelled */));
|
|
1961
|
+
if (_activeNativeRequest === this) {
|
|
1962
|
+
_activeNativeRequest = null;
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
cleanup() {
|
|
1966
|
+
if (this.messageHandler) {
|
|
1967
|
+
window.removeEventListener("message", this.messageHandler);
|
|
1968
|
+
this.messageHandler = null;
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
isPending() {
|
|
1972
|
+
return !this.settled && !this.cancelled;
|
|
1973
|
+
}
|
|
1974
|
+
async pollOnce() {
|
|
1975
|
+
if (this.resolved && this.resolvedResult) {
|
|
1976
|
+
return { type: "confirmed", result: this.resolvedResult };
|
|
1977
|
+
}
|
|
1978
|
+
return { type: "awaiting_confirmation" };
|
|
1979
|
+
}
|
|
1980
|
+
async pollUntilCompletion(options) {
|
|
1981
|
+
const timeout = options?.timeout ?? 3e5;
|
|
1982
|
+
let timeoutId;
|
|
1983
|
+
let abortHandler = null;
|
|
1984
|
+
let waiterTerminationCode = null;
|
|
1822
1985
|
try {
|
|
1823
|
-
const
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1986
|
+
const result = await Promise.race([
|
|
1987
|
+
this.resultPromise,
|
|
1988
|
+
new Promise((_, reject) => {
|
|
1989
|
+
if (options?.signal) {
|
|
1990
|
+
abortHandler = () => {
|
|
1991
|
+
waiterTerminationCode = "cancelled" /* Cancelled */;
|
|
1992
|
+
reject(new NativeVerifyError("cancelled" /* Cancelled */));
|
|
1993
|
+
};
|
|
1994
|
+
if (options.signal.aborted) {
|
|
1995
|
+
abortHandler();
|
|
1996
|
+
return;
|
|
1997
|
+
}
|
|
1998
|
+
options.signal.addEventListener("abort", abortHandler, {
|
|
1999
|
+
once: true
|
|
2000
|
+
});
|
|
2001
|
+
}
|
|
2002
|
+
timeoutId = setTimeout(() => {
|
|
2003
|
+
waiterTerminationCode = "timeout" /* Timeout */;
|
|
2004
|
+
reject(new NativeVerifyError("timeout" /* Timeout */));
|
|
2005
|
+
}, timeout);
|
|
2006
|
+
})
|
|
2007
|
+
]);
|
|
2008
|
+
return { success: true, result };
|
|
1829
2009
|
} catch (error) {
|
|
1830
|
-
|
|
1831
|
-
|
|
2010
|
+
if (error instanceof NativeVerifyError) {
|
|
2011
|
+
if (waiterTerminationCode === error.code && this.isPending()) {
|
|
2012
|
+
this.cancel();
|
|
2013
|
+
}
|
|
2014
|
+
return { success: false, error: error.code };
|
|
2015
|
+
}
|
|
2016
|
+
return { success: false, error: "generic_error" /* GenericError */ };
|
|
2017
|
+
} finally {
|
|
2018
|
+
if (timeoutId) {
|
|
2019
|
+
clearTimeout(timeoutId);
|
|
2020
|
+
}
|
|
2021
|
+
if (options?.signal && abortHandler) {
|
|
2022
|
+
options.signal.removeEventListener("abort", abortHandler);
|
|
2023
|
+
}
|
|
1832
2024
|
}
|
|
1833
|
-
}
|
|
1834
|
-
|
|
2025
|
+
}
|
|
2026
|
+
};
|
|
2027
|
+
var NativeVerifyError = class extends Error {
|
|
2028
|
+
constructor(code) {
|
|
2029
|
+
super(code);
|
|
2030
|
+
this.code = code;
|
|
2031
|
+
}
|
|
2032
|
+
};
|
|
2033
|
+
function nativeResultToIDKitResult(payload, config) {
|
|
2034
|
+
const rpNonce = config.rp_context?.nonce ?? "";
|
|
2035
|
+
if ("responses" in payload && Array.isArray(payload.responses)) {
|
|
2036
|
+
return {
|
|
2037
|
+
protocol_version: payload.protocol_version ?? "4.0",
|
|
2038
|
+
nonce: payload.nonce ?? rpNonce,
|
|
2039
|
+
action: payload.action ?? config.action ?? "",
|
|
2040
|
+
action_description: payload.action_description,
|
|
2041
|
+
session_id: payload.session_id,
|
|
2042
|
+
responses: payload.responses,
|
|
2043
|
+
environment: payload.environment ?? config.environment ?? "production"
|
|
2044
|
+
};
|
|
2045
|
+
}
|
|
2046
|
+
if ("verifications" in payload) {
|
|
2047
|
+
return {
|
|
2048
|
+
protocol_version: "4.0",
|
|
2049
|
+
nonce: rpNonce,
|
|
2050
|
+
action: config.action ?? "",
|
|
2051
|
+
responses: payload.verifications.map((v) => ({
|
|
2052
|
+
identifier: v.verification_level,
|
|
2053
|
+
proof: [v.proof],
|
|
2054
|
+
nullifier: v.nullifier_hash,
|
|
2055
|
+
merkle_root: v.merkle_root,
|
|
2056
|
+
issuer_schema_id: 0,
|
|
2057
|
+
expires_at_min: 0
|
|
2058
|
+
})),
|
|
2059
|
+
environment: "production"
|
|
2060
|
+
};
|
|
2061
|
+
}
|
|
2062
|
+
return {
|
|
2063
|
+
protocol_version: "3.0",
|
|
2064
|
+
nonce: rpNonce,
|
|
2065
|
+
action: config.action ?? "",
|
|
2066
|
+
responses: [
|
|
2067
|
+
{
|
|
2068
|
+
identifier: payload.verification_level,
|
|
2069
|
+
proof: payload.proof,
|
|
2070
|
+
merkle_root: payload.merkle_root,
|
|
2071
|
+
nullifier: payload.nullifier_hash
|
|
2072
|
+
}
|
|
2073
|
+
],
|
|
2074
|
+
environment: "production"
|
|
2075
|
+
};
|
|
1835
2076
|
}
|
|
1836
2077
|
|
|
1837
2078
|
// src/request.ts
|
|
@@ -1898,9 +2139,52 @@ function secureDocumentLegacy(opts = {}) {
|
|
|
1898
2139
|
function documentLegacy(opts = {}) {
|
|
1899
2140
|
return { type: "DocumentLegacy", signal: opts.signal };
|
|
1900
2141
|
}
|
|
2142
|
+
function createWasmBuilderFromConfig(config) {
|
|
2143
|
+
if (!config.rp_context) {
|
|
2144
|
+
throw new Error("rp_context is required for WASM bridge transport");
|
|
2145
|
+
}
|
|
2146
|
+
const rpContext = new idkit_wasm_exports.RpContextWasm(
|
|
2147
|
+
config.rp_context.rp_id,
|
|
2148
|
+
config.rp_context.nonce,
|
|
2149
|
+
BigInt(config.rp_context.created_at),
|
|
2150
|
+
BigInt(config.rp_context.expires_at),
|
|
2151
|
+
config.rp_context.signature
|
|
2152
|
+
);
|
|
2153
|
+
if (config.type === "request") {
|
|
2154
|
+
return idkit_wasm_exports.request(
|
|
2155
|
+
config.app_id,
|
|
2156
|
+
String(config.action ?? ""),
|
|
2157
|
+
rpContext,
|
|
2158
|
+
config.action_description ?? null,
|
|
2159
|
+
config.bridge_url ?? null,
|
|
2160
|
+
config.allow_legacy_proofs ?? false,
|
|
2161
|
+
config.override_connect_base_url ?? null,
|
|
2162
|
+
config.environment ?? null
|
|
2163
|
+
);
|
|
2164
|
+
}
|
|
2165
|
+
if (config.type === "proveSession") {
|
|
2166
|
+
return idkit_wasm_exports.proveSession(
|
|
2167
|
+
config.session_id,
|
|
2168
|
+
config.app_id,
|
|
2169
|
+
rpContext,
|
|
2170
|
+
config.action_description ?? null,
|
|
2171
|
+
config.bridge_url ?? null,
|
|
2172
|
+
config.override_connect_base_url ?? null,
|
|
2173
|
+
config.environment ?? null
|
|
2174
|
+
);
|
|
2175
|
+
}
|
|
2176
|
+
return idkit_wasm_exports.createSession(
|
|
2177
|
+
config.app_id,
|
|
2178
|
+
rpContext,
|
|
2179
|
+
config.action_description ?? null,
|
|
2180
|
+
config.bridge_url ?? null,
|
|
2181
|
+
config.override_connect_base_url ?? null,
|
|
2182
|
+
config.environment ?? null
|
|
2183
|
+
);
|
|
2184
|
+
}
|
|
1901
2185
|
var IDKitBuilder2 = class {
|
|
1902
|
-
constructor(
|
|
1903
|
-
this.
|
|
2186
|
+
constructor(config) {
|
|
2187
|
+
this.config = config;
|
|
1904
2188
|
}
|
|
1905
2189
|
/**
|
|
1906
2190
|
* Creates an IDKit request with the given constraints
|
|
@@ -1910,36 +2194,45 @@ var IDKitBuilder2 = class {
|
|
|
1910
2194
|
*
|
|
1911
2195
|
* @example
|
|
1912
2196
|
* ```typescript
|
|
1913
|
-
* const
|
|
1914
|
-
*
|
|
2197
|
+
* const request = await IDKit.request({ app_id, action, rp_context, allow_legacy_proofs: false })
|
|
2198
|
+
* .constraints(any(CredentialRequest('orb'), CredentialRequest('face')));
|
|
1915
2199
|
* ```
|
|
1916
2200
|
*/
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
2201
|
+
async constraints(constraints) {
|
|
2202
|
+
await initIDKit();
|
|
2203
|
+
const wasmBuilder = createWasmBuilderFromConfig(this.config);
|
|
2204
|
+
if (isInWorldApp()) {
|
|
2205
|
+
const payload = wasmBuilder.nativePayload(constraints);
|
|
2206
|
+
return createNativeRequest(payload, this.config);
|
|
2207
|
+
}
|
|
2208
|
+
const wasmRequest = await wasmBuilder.constraints(
|
|
2209
|
+
constraints
|
|
2210
|
+
);
|
|
2211
|
+
return new IDKitRequestImpl(wasmRequest);
|
|
2212
|
+
}
|
|
1925
2213
|
/**
|
|
1926
2214
|
* Creates an IDKit request from a preset (works for all request types)
|
|
1927
2215
|
*
|
|
1928
2216
|
* Presets provide a simplified way to create requests with predefined
|
|
1929
2217
|
* credential configurations.
|
|
1930
2218
|
*
|
|
1931
|
-
* @param preset - A preset object from orbLegacy()
|
|
2219
|
+
* @param preset - A preset object from orbLegacy(), secureDocumentLegacy(), or documentLegacy()
|
|
1932
2220
|
* @returns A new IDKitRequest instance
|
|
1933
2221
|
*
|
|
1934
2222
|
* @example
|
|
1935
2223
|
* ```typescript
|
|
1936
|
-
* const
|
|
1937
|
-
*
|
|
2224
|
+
* const request = await IDKit.request({ app_id, action, rp_context, allow_legacy_proofs: true })
|
|
2225
|
+
* .preset(orbLegacy({ signal: 'user-123' }));
|
|
1938
2226
|
* ```
|
|
1939
2227
|
*/
|
|
1940
2228
|
async preset(preset) {
|
|
1941
2229
|
await initIDKit();
|
|
1942
|
-
const
|
|
2230
|
+
const wasmBuilder = createWasmBuilderFromConfig(this.config);
|
|
2231
|
+
if (isInWorldApp()) {
|
|
2232
|
+
const payload = wasmBuilder.nativePayloadFromPreset(preset);
|
|
2233
|
+
return createNativeRequest(payload, this.config);
|
|
2234
|
+
}
|
|
2235
|
+
const wasmRequest = await wasmBuilder.preset(
|
|
1943
2236
|
preset
|
|
1944
2237
|
);
|
|
1945
2238
|
return new IDKitRequestImpl(wasmRequest);
|
|
@@ -1953,55 +2246,45 @@ function createRequest(config) {
|
|
|
1953
2246
|
throw new Error("action is required");
|
|
1954
2247
|
}
|
|
1955
2248
|
if (!config.rp_context) {
|
|
1956
|
-
throw new Error(
|
|
2249
|
+
throw new Error(
|
|
2250
|
+
"rp_context is required. Generate it on your backend using signRequest()."
|
|
2251
|
+
);
|
|
1957
2252
|
}
|
|
1958
2253
|
if (typeof config.allow_legacy_proofs !== "boolean") {
|
|
1959
2254
|
throw new Error(
|
|
1960
2255
|
"allow_legacy_proofs is required. Set to true to accept v3 proofs during migration, or false to only accept v4 proofs."
|
|
1961
2256
|
);
|
|
1962
2257
|
}
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
config.
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
config.
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
config.
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
config.action_description ?? null,
|
|
1975
|
-
config.bridge_url ?? null,
|
|
1976
|
-
config.allow_legacy_proofs,
|
|
1977
|
-
config.override_connect_base_url ?? null,
|
|
1978
|
-
config.environment ?? null
|
|
1979
|
-
);
|
|
1980
|
-
return new IDKitBuilder2(wasmBuilder);
|
|
2258
|
+
return new IDKitBuilder2({
|
|
2259
|
+
type: "request",
|
|
2260
|
+
app_id: config.app_id,
|
|
2261
|
+
action: String(config.action),
|
|
2262
|
+
rp_context: config.rp_context,
|
|
2263
|
+
action_description: config.action_description,
|
|
2264
|
+
bridge_url: config.bridge_url,
|
|
2265
|
+
allow_legacy_proofs: config.allow_legacy_proofs,
|
|
2266
|
+
override_connect_base_url: config.override_connect_base_url,
|
|
2267
|
+
environment: config.environment
|
|
2268
|
+
});
|
|
1981
2269
|
}
|
|
1982
2270
|
function createSession2(config) {
|
|
1983
2271
|
if (!config.app_id) {
|
|
1984
2272
|
throw new Error("app_id is required");
|
|
1985
2273
|
}
|
|
1986
2274
|
if (!config.rp_context) {
|
|
1987
|
-
throw new Error(
|
|
2275
|
+
throw new Error(
|
|
2276
|
+
"rp_context is required. Generate it on your backend using signRequest()."
|
|
2277
|
+
);
|
|
1988
2278
|
}
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
config.
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
config.
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
rpContext,
|
|
1999
|
-
config.action_description ?? null,
|
|
2000
|
-
config.bridge_url ?? null,
|
|
2001
|
-
config.override_connect_base_url ?? null,
|
|
2002
|
-
config.environment ?? null
|
|
2003
|
-
);
|
|
2004
|
-
return new IDKitBuilder2(wasmBuilder);
|
|
2279
|
+
return new IDKitBuilder2({
|
|
2280
|
+
type: "session",
|
|
2281
|
+
app_id: config.app_id,
|
|
2282
|
+
rp_context: config.rp_context,
|
|
2283
|
+
action_description: config.action_description,
|
|
2284
|
+
bridge_url: config.bridge_url,
|
|
2285
|
+
override_connect_base_url: config.override_connect_base_url,
|
|
2286
|
+
environment: config.environment
|
|
2287
|
+
});
|
|
2005
2288
|
}
|
|
2006
2289
|
function proveSession2(sessionId, config) {
|
|
2007
2290
|
if (!sessionId) {
|
|
@@ -2011,31 +2294,22 @@ function proveSession2(sessionId, config) {
|
|
|
2011
2294
|
throw new Error("app_id is required");
|
|
2012
2295
|
}
|
|
2013
2296
|
if (!config.rp_context) {
|
|
2014
|
-
throw new Error(
|
|
2297
|
+
throw new Error(
|
|
2298
|
+
"rp_context is required. Generate it on your backend using signRequest()."
|
|
2299
|
+
);
|
|
2015
2300
|
}
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
config.
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
rpContext,
|
|
2027
|
-
config.action_description ?? null,
|
|
2028
|
-
config.bridge_url ?? null,
|
|
2029
|
-
config.override_connect_base_url ?? null,
|
|
2030
|
-
config.environment ?? null
|
|
2031
|
-
);
|
|
2032
|
-
return new IDKitBuilder2(wasmBuilder);
|
|
2301
|
+
return new IDKitBuilder2({
|
|
2302
|
+
type: "proveSession",
|
|
2303
|
+
session_id: sessionId,
|
|
2304
|
+
app_id: config.app_id,
|
|
2305
|
+
rp_context: config.rp_context,
|
|
2306
|
+
action_description: config.action_description,
|
|
2307
|
+
bridge_url: config.bridge_url,
|
|
2308
|
+
override_connect_base_url: config.override_connect_base_url,
|
|
2309
|
+
environment: config.environment
|
|
2310
|
+
});
|
|
2033
2311
|
}
|
|
2034
2312
|
var IDKit = {
|
|
2035
|
-
/** Initialize WASM for browser environments */
|
|
2036
|
-
init: initIDKit,
|
|
2037
|
-
/** Initialize WASM for Node.js/server environments */
|
|
2038
|
-
initServer: initIDKitServer,
|
|
2039
2313
|
/** Create a new verification request */
|
|
2040
2314
|
request: createRequest,
|
|
2041
2315
|
/** Create a new session (no action, no existing session_id) */
|
|
@@ -2078,21 +2352,71 @@ var isServerEnvironment = () => {
|
|
|
2078
2352
|
}
|
|
2079
2353
|
return false;
|
|
2080
2354
|
};
|
|
2355
|
+
function hashToField(input) {
|
|
2356
|
+
const hash = BigInt("0x" + bytesToHex(keccak_256(input))) >> 8n;
|
|
2357
|
+
return hexToBytes(hash.toString(16).padStart(64, "0"));
|
|
2358
|
+
}
|
|
2359
|
+
function hashSignal2(signal) {
|
|
2360
|
+
let input;
|
|
2361
|
+
if (signal instanceof Uint8Array) {
|
|
2362
|
+
input = signal;
|
|
2363
|
+
} else if (signal.startsWith("0x") && isValidHex(signal.slice(2))) {
|
|
2364
|
+
input = hexToBytes(signal.slice(2));
|
|
2365
|
+
} else {
|
|
2366
|
+
input = new TextEncoder().encode(signal);
|
|
2367
|
+
}
|
|
2368
|
+
return "0x" + bytesToHex(hashToField(input));
|
|
2369
|
+
}
|
|
2370
|
+
function isValidHex(s) {
|
|
2371
|
+
if (s.length === 0) return false;
|
|
2372
|
+
if (s.length % 2 !== 0) return false;
|
|
2373
|
+
return /^[0-9a-fA-F]+$/.test(s);
|
|
2374
|
+
}
|
|
2081
2375
|
|
|
2082
|
-
// src/lib/
|
|
2083
|
-
|
|
2376
|
+
// src/lib/signing.ts
|
|
2377
|
+
etc.hmacSha256Sync = (key, ...msgs) => hmac(sha256, key, etc.concatBytes(...msgs));
|
|
2378
|
+
var DEFAULT_TTL_SEC = 300;
|
|
2379
|
+
function computeRpSignatureMessage(nonceBytes, createdAt, expiresAt) {
|
|
2380
|
+
const message = new Uint8Array(48);
|
|
2381
|
+
message.set(nonceBytes, 0);
|
|
2382
|
+
const view = new DataView(message.buffer);
|
|
2383
|
+
view.setBigUint64(32, BigInt(createdAt), false);
|
|
2384
|
+
view.setBigUint64(40, BigInt(expiresAt), false);
|
|
2385
|
+
return message;
|
|
2386
|
+
}
|
|
2387
|
+
function signRequest2(_action, signingKeyHex, ttl = DEFAULT_TTL_SEC) {
|
|
2084
2388
|
if (!isServerEnvironment()) {
|
|
2085
2389
|
throw new Error(
|
|
2086
2390
|
"signRequest can only be used in Node.js environments. This function requires access to signing keys and should never be called from browser/client-side code."
|
|
2087
2391
|
);
|
|
2088
2392
|
}
|
|
2089
|
-
const
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2393
|
+
const keyHex = signingKeyHex.startsWith("0x") ? signingKeyHex.slice(2) : signingKeyHex;
|
|
2394
|
+
if (!/^[0-9a-fA-F]+$/.test(keyHex)) {
|
|
2395
|
+
throw new Error("Invalid signing key: contains non-hex characters");
|
|
2396
|
+
}
|
|
2397
|
+
if (keyHex.length !== 64) {
|
|
2398
|
+
throw new Error(
|
|
2399
|
+
`Invalid signing key: expected 32 bytes (64 hex chars), got ${keyHex.length / 2} bytes`
|
|
2400
|
+
);
|
|
2401
|
+
}
|
|
2402
|
+
const privKey = etc.hexToBytes(keyHex);
|
|
2403
|
+
const randomBytes = crypto.getRandomValues(new Uint8Array(32));
|
|
2404
|
+
const nonceBytes = hashToField(randomBytes);
|
|
2405
|
+
const createdAt = Math.floor(Date.now() / 1e3);
|
|
2406
|
+
const expiresAt = createdAt + ttl;
|
|
2407
|
+
const message = computeRpSignatureMessage(nonceBytes, createdAt, expiresAt);
|
|
2408
|
+
const msgHash = keccak_256(message);
|
|
2409
|
+
const recSig = sign(msgHash, privKey);
|
|
2410
|
+
const compact = recSig.toCompactRawBytes();
|
|
2411
|
+
const sig65 = new Uint8Array(65);
|
|
2412
|
+
sig65.set(compact, 0);
|
|
2413
|
+
sig65[64] = recSig.recovery + 27;
|
|
2414
|
+
return {
|
|
2415
|
+
sig: "0x" + bytesToHex(sig65),
|
|
2416
|
+
nonce: "0x" + bytesToHex(nonceBytes),
|
|
2417
|
+
createdAt,
|
|
2418
|
+
expiresAt
|
|
2419
|
+
};
|
|
2096
2420
|
}
|
|
2097
2421
|
|
|
2098
2422
|
export { CredentialRequest, IDKit, IDKitErrorCodes, all, any, documentLegacy, hashSignal2 as hashSignal, isNode, isReactNative, isWeb, orbLegacy, secureDocumentLegacy, signRequest2 as signRequest };
|