@worldcoin/idkit-core 4.0.0-dev.777cdbe → 4.0.1-dev.8abccc4
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 +1 -0
- package/dist/idkit_wasm_bg.wasm +0 -0
- package/dist/index.cjs +394 -116
- package/dist/index.d.cts +79 -117
- package/dist/index.d.ts +79 -117
- package/dist/index.js +394 -116
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -242,6 +242,22 @@ function _assertClass(instance, klass) {
|
|
|
242
242
|
throw new Error(`expected instance of ${klass.name}`);
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
|
+
function createSession(app_id, rp_context, action_description, bridge_url, override_connect_base_url, environment) {
|
|
246
|
+
const ptr0 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
247
|
+
const len0 = WASM_VECTOR_LEN;
|
|
248
|
+
_assertClass(rp_context, RpContextWasm);
|
|
249
|
+
var ptr1 = rp_context.__destroy_into_raw();
|
|
250
|
+
var ptr2 = isLikeNone(action_description) ? 0 : passStringToWasm0(action_description, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
251
|
+
var len2 = WASM_VECTOR_LEN;
|
|
252
|
+
var ptr3 = isLikeNone(bridge_url) ? 0 : passStringToWasm0(bridge_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
253
|
+
var len3 = WASM_VECTOR_LEN;
|
|
254
|
+
var ptr4 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
255
|
+
var len4 = WASM_VECTOR_LEN;
|
|
256
|
+
var ptr5 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
257
|
+
var len5 = WASM_VECTOR_LEN;
|
|
258
|
+
const ret = wasm.createSession(ptr0, len0, ptr1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
|
|
259
|
+
return IDKitBuilder.__wrap(ret);
|
|
260
|
+
}
|
|
245
261
|
function request(app_id, action, rp_context, action_description, bridge_url, allow_legacy_proofs, override_connect_base_url, environment) {
|
|
246
262
|
const ptr0 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
247
263
|
const len0 = WASM_VECTOR_LEN;
|
|
@@ -260,9 +276,6 @@ function request(app_id, action, rp_context, action_description, bridge_url, all
|
|
|
260
276
|
const ret = wasm.idkitbuilder_new(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, allow_legacy_proofs, ptr5, len5, ptr6, len6);
|
|
261
277
|
return IDKitBuilder.__wrap(ret);
|
|
262
278
|
}
|
|
263
|
-
function init_wasm() {
|
|
264
|
-
wasm.init_wasm();
|
|
265
|
-
}
|
|
266
279
|
function base64Decode(data) {
|
|
267
280
|
try {
|
|
268
281
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
@@ -301,22 +314,6 @@ function proveSession(session_id, app_id, rp_context, action_description, bridge
|
|
|
301
314
|
const ret = wasm.idkitbuilder_forProveSession(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6);
|
|
302
315
|
return IDKitBuilder.__wrap(ret);
|
|
303
316
|
}
|
|
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
317
|
function passArray8ToWasm0(arg, malloc) {
|
|
321
318
|
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
322
319
|
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
@@ -341,6 +338,28 @@ function base64Encode(data) {
|
|
|
341
338
|
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
342
339
|
}
|
|
343
340
|
}
|
|
341
|
+
function init_wasm() {
|
|
342
|
+
wasm.init_wasm();
|
|
343
|
+
}
|
|
344
|
+
function signRequest(action, signing_key_hex, ttl_seconds) {
|
|
345
|
+
try {
|
|
346
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
347
|
+
const ptr0 = passStringToWasm0(action, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
348
|
+
const len0 = WASM_VECTOR_LEN;
|
|
349
|
+
const ptr1 = passStringToWasm0(signing_key_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
350
|
+
const len1 = WASM_VECTOR_LEN;
|
|
351
|
+
wasm.signRequest(retptr, ptr0, len0, ptr1, len1, !isLikeNone(ttl_seconds), isLikeNone(ttl_seconds) ? BigInt(0) : ttl_seconds);
|
|
352
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
353
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
354
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
355
|
+
if (r2) {
|
|
356
|
+
throw takeObject(r1);
|
|
357
|
+
}
|
|
358
|
+
return RpSignature.__wrap(r0);
|
|
359
|
+
} finally {
|
|
360
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
344
363
|
function hashSignal(signal) {
|
|
345
364
|
let deferred2_0;
|
|
346
365
|
let deferred2_1;
|
|
@@ -366,33 +385,14 @@ function hashSignal(signal) {
|
|
|
366
385
|
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
367
386
|
}
|
|
368
387
|
}
|
|
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
388
|
function __wasm_bindgen_func_elem_960(arg0, arg1, arg2) {
|
|
389
389
|
wasm.__wasm_bindgen_func_elem_960(arg0, arg1, addHeapObject(arg2));
|
|
390
390
|
}
|
|
391
391
|
function __wasm_bindgen_func_elem_597(arg0, arg1) {
|
|
392
392
|
wasm.__wasm_bindgen_func_elem_597(arg0, arg1);
|
|
393
393
|
}
|
|
394
|
-
function
|
|
395
|
-
wasm.
|
|
394
|
+
function __wasm_bindgen_func_elem_1345(arg0, arg1, arg2, arg3) {
|
|
395
|
+
wasm.__wasm_bindgen_func_elem_1345(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
|
|
396
396
|
}
|
|
397
397
|
var __wbindgen_enum_RequestCache = ["default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached"];
|
|
398
398
|
var __wbindgen_enum_RequestCredentials = ["omit", "same-origin", "include"];
|
|
@@ -769,6 +769,34 @@ var IDKitBuilder = class _IDKitBuilder {
|
|
|
769
769
|
const ret = wasm.idkitbuilder_constraints(ptr, addHeapObject(constraints_json));
|
|
770
770
|
return takeObject(ret);
|
|
771
771
|
}
|
|
772
|
+
/**
|
|
773
|
+
* Builds the native payload for constraints (synchronous, no bridge connection).
|
|
774
|
+
*
|
|
775
|
+
* Used by the native transport to get the same payload format as the bridge
|
|
776
|
+
* without creating a network connection.
|
|
777
|
+
*
|
|
778
|
+
* # Errors
|
|
779
|
+
*
|
|
780
|
+
* Returns an error if constraints are invalid or payload construction fails.
|
|
781
|
+
* @param {any} constraints_json
|
|
782
|
+
* @returns {any}
|
|
783
|
+
*/
|
|
784
|
+
nativePayload(constraints_json) {
|
|
785
|
+
try {
|
|
786
|
+
const ptr = this.__destroy_into_raw();
|
|
787
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
788
|
+
wasm.idkitbuilder_nativePayload(retptr, ptr, addHeapObject(constraints_json));
|
|
789
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
790
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
791
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
792
|
+
if (r2) {
|
|
793
|
+
throw takeObject(r1);
|
|
794
|
+
}
|
|
795
|
+
return takeObject(r0);
|
|
796
|
+
} finally {
|
|
797
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
772
800
|
/**
|
|
773
801
|
* Creates a new builder for proving an existing session
|
|
774
802
|
* @param {string} session_id
|
|
@@ -824,6 +852,34 @@ var IDKitBuilder = class _IDKitBuilder {
|
|
|
824
852
|
const ret = wasm.createSession(ptr0, len0, ptr1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
|
|
825
853
|
return _IDKitBuilder.__wrap(ret);
|
|
826
854
|
}
|
|
855
|
+
/**
|
|
856
|
+
* Builds the native payload from a preset (synchronous, no bridge connection).
|
|
857
|
+
*
|
|
858
|
+
* Used by the native transport to get the same payload format as the bridge
|
|
859
|
+
* without creating a network connection.
|
|
860
|
+
*
|
|
861
|
+
* # Errors
|
|
862
|
+
*
|
|
863
|
+
* Returns an error if the preset is invalid or payload construction fails.
|
|
864
|
+
* @param {any} preset_json
|
|
865
|
+
* @returns {any}
|
|
866
|
+
*/
|
|
867
|
+
nativePayloadFromPreset(preset_json) {
|
|
868
|
+
try {
|
|
869
|
+
const ptr = this.__destroy_into_raw();
|
|
870
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
871
|
+
wasm.idkitbuilder_nativePayloadFromPreset(retptr, ptr, addHeapObject(preset_json));
|
|
872
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
873
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
874
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
875
|
+
if (r2) {
|
|
876
|
+
throw takeObject(r1);
|
|
877
|
+
}
|
|
878
|
+
return takeObject(r0);
|
|
879
|
+
} finally {
|
|
880
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
827
883
|
/**
|
|
828
884
|
* Creates a new builder for uniqueness requests
|
|
829
885
|
* @param {string} app_id
|
|
@@ -1499,7 +1555,7 @@ function __wbg_get_imports() {
|
|
|
1499
1555
|
const a = state0.a;
|
|
1500
1556
|
state0.a = 0;
|
|
1501
1557
|
try {
|
|
1502
|
-
return
|
|
1558
|
+
return __wasm_bindgen_func_elem_1345(a, state0.b, arg02, arg12);
|
|
1503
1559
|
} finally {
|
|
1504
1560
|
state0.a = a;
|
|
1505
1561
|
}
|
|
@@ -1793,6 +1849,10 @@ var idkit_wasm_default = __wbg_init;
|
|
|
1793
1849
|
// src/lib/wasm.ts
|
|
1794
1850
|
var wasmInitialized = false;
|
|
1795
1851
|
var wasmInitPromise = null;
|
|
1852
|
+
async function importNodeModule(specifier) {
|
|
1853
|
+
const dynamicImport = Function("moduleName", "return import(moduleName)");
|
|
1854
|
+
return dynamicImport(specifier);
|
|
1855
|
+
}
|
|
1796
1856
|
async function initIDKit() {
|
|
1797
1857
|
if (wasmInitialized) {
|
|
1798
1858
|
return;
|
|
@@ -1820,10 +1880,18 @@ async function initIDKitServer() {
|
|
|
1820
1880
|
}
|
|
1821
1881
|
wasmInitPromise = (async () => {
|
|
1822
1882
|
try {
|
|
1823
|
-
const { readFile } = await
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
const
|
|
1883
|
+
const { readFile } = await importNodeModule(
|
|
1884
|
+
"node:fs/promises"
|
|
1885
|
+
);
|
|
1886
|
+
const { fileURLToPath } = await importNodeModule(
|
|
1887
|
+
"node:url"
|
|
1888
|
+
);
|
|
1889
|
+
const { dirname, join } = await importNodeModule(
|
|
1890
|
+
"node:path"
|
|
1891
|
+
);
|
|
1892
|
+
const modulePath = fileURLToPath(import.meta.url);
|
|
1893
|
+
const wasmPath = join(dirname(modulePath), "idkit_wasm_bg.wasm");
|
|
1894
|
+
const wasmBuffer = await readFile(wasmPath);
|
|
1827
1895
|
await idkit_wasm_default({ module_or_path: wasmBuffer });
|
|
1828
1896
|
wasmInitialized = true;
|
|
1829
1897
|
} catch (error) {
|
|
@@ -1834,6 +1902,179 @@ async function initIDKitServer() {
|
|
|
1834
1902
|
return wasmInitPromise;
|
|
1835
1903
|
}
|
|
1836
1904
|
|
|
1905
|
+
// src/transports/native.ts
|
|
1906
|
+
function isInWorldApp() {
|
|
1907
|
+
return typeof window !== "undefined" && Boolean(window.WorldApp);
|
|
1908
|
+
}
|
|
1909
|
+
var _requestCounter = 0;
|
|
1910
|
+
var _activeNativeRequest = null;
|
|
1911
|
+
function createNativeRequest(wasmPayload, config) {
|
|
1912
|
+
if (_activeNativeRequest) {
|
|
1913
|
+
_activeNativeRequest.cancel();
|
|
1914
|
+
}
|
|
1915
|
+
const request2 = new NativeIDKitRequest(wasmPayload, config);
|
|
1916
|
+
_activeNativeRequest = request2;
|
|
1917
|
+
return request2;
|
|
1918
|
+
}
|
|
1919
|
+
var NativeIDKitRequest = class {
|
|
1920
|
+
constructor(wasmPayload, config) {
|
|
1921
|
+
this.connectorURI = "";
|
|
1922
|
+
this.resolved = false;
|
|
1923
|
+
this.cancelled = false;
|
|
1924
|
+
this.resolvedResult = null;
|
|
1925
|
+
this.messageHandler = null;
|
|
1926
|
+
this.rejectFn = null;
|
|
1927
|
+
this.requestId = crypto.randomUUID?.() ?? `native-${Date.now()}-${++_requestCounter}`;
|
|
1928
|
+
this.resultPromise = new Promise((resolve, reject) => {
|
|
1929
|
+
this.rejectFn = reject;
|
|
1930
|
+
const handler = (event) => {
|
|
1931
|
+
if (this.cancelled) return;
|
|
1932
|
+
const data = event.data;
|
|
1933
|
+
if (data?.type === "miniapp-verify-action" || data?.command === "miniapp-verify-action") {
|
|
1934
|
+
this.cleanup();
|
|
1935
|
+
const responsePayload = data.payload ?? data;
|
|
1936
|
+
if (responsePayload.status === "error") {
|
|
1937
|
+
reject(
|
|
1938
|
+
new NativeVerifyError(
|
|
1939
|
+
responsePayload.error_code ?? "generic_error" /* GenericError */
|
|
1940
|
+
)
|
|
1941
|
+
);
|
|
1942
|
+
} else {
|
|
1943
|
+
this.resolved = true;
|
|
1944
|
+
const result = nativeResultToIDKitResult(responsePayload, config);
|
|
1945
|
+
this.resolvedResult = result;
|
|
1946
|
+
resolve(result);
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
};
|
|
1950
|
+
this.messageHandler = handler;
|
|
1951
|
+
window.addEventListener("message", handler);
|
|
1952
|
+
const sendPayload = {
|
|
1953
|
+
command: "verify",
|
|
1954
|
+
version: 2,
|
|
1955
|
+
payload: wasmPayload
|
|
1956
|
+
};
|
|
1957
|
+
const w = window;
|
|
1958
|
+
if (w.webkit?.messageHandlers?.minikit) {
|
|
1959
|
+
w.webkit.messageHandlers.minikit.postMessage(sendPayload);
|
|
1960
|
+
} else if (w.Android) {
|
|
1961
|
+
w.Android.postMessage(JSON.stringify(sendPayload));
|
|
1962
|
+
} else {
|
|
1963
|
+
this.cleanup();
|
|
1964
|
+
reject(new Error("No WebView bridge available"));
|
|
1965
|
+
}
|
|
1966
|
+
});
|
|
1967
|
+
this.resultPromise.catch(() => {
|
|
1968
|
+
}).finally(() => {
|
|
1969
|
+
this.cleanup();
|
|
1970
|
+
if (_activeNativeRequest === this) {
|
|
1971
|
+
_activeNativeRequest = null;
|
|
1972
|
+
}
|
|
1973
|
+
});
|
|
1974
|
+
}
|
|
1975
|
+
/**
|
|
1976
|
+
* Cancel this request. Removes the message listener so it cannot consume
|
|
1977
|
+
* a response meant for a later request, and rejects the pending promise.
|
|
1978
|
+
*/
|
|
1979
|
+
cancel() {
|
|
1980
|
+
if (this.resolved || this.cancelled) return;
|
|
1981
|
+
this.cancelled = true;
|
|
1982
|
+
this.cleanup();
|
|
1983
|
+
this.rejectFn?.(new NativeVerifyError("cancelled" /* Cancelled */));
|
|
1984
|
+
if (_activeNativeRequest === this) {
|
|
1985
|
+
_activeNativeRequest = null;
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
cleanup() {
|
|
1989
|
+
if (this.messageHandler) {
|
|
1990
|
+
window.removeEventListener("message", this.messageHandler);
|
|
1991
|
+
this.messageHandler = null;
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
async pollOnce() {
|
|
1995
|
+
if (this.resolved && this.resolvedResult) {
|
|
1996
|
+
return { type: "confirmed", result: this.resolvedResult };
|
|
1997
|
+
}
|
|
1998
|
+
return { type: "awaiting_confirmation" };
|
|
1999
|
+
}
|
|
2000
|
+
async pollUntilCompletion(options) {
|
|
2001
|
+
const timeout = options?.timeout ?? 3e5;
|
|
2002
|
+
try {
|
|
2003
|
+
const result = await Promise.race([
|
|
2004
|
+
this.resultPromise,
|
|
2005
|
+
new Promise((_, reject) => {
|
|
2006
|
+
if (options?.signal) {
|
|
2007
|
+
options.signal.addEventListener(
|
|
2008
|
+
"abort",
|
|
2009
|
+
() => reject(new NativeVerifyError("cancelled" /* Cancelled */))
|
|
2010
|
+
);
|
|
2011
|
+
}
|
|
2012
|
+
setTimeout(
|
|
2013
|
+
() => reject(new NativeVerifyError("timeout" /* Timeout */)),
|
|
2014
|
+
timeout
|
|
2015
|
+
);
|
|
2016
|
+
})
|
|
2017
|
+
]);
|
|
2018
|
+
return { success: true, result };
|
|
2019
|
+
} catch (error) {
|
|
2020
|
+
if (error instanceof NativeVerifyError) {
|
|
2021
|
+
return { success: false, error: error.code };
|
|
2022
|
+
}
|
|
2023
|
+
return { success: false, error: "generic_error" /* GenericError */ };
|
|
2024
|
+
}
|
|
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
|
+
};
|
|
2076
|
+
}
|
|
2077
|
+
|
|
1837
2078
|
// src/request.ts
|
|
1838
2079
|
var IDKitRequestImpl = class {
|
|
1839
2080
|
constructor(wasmRequest) {
|
|
@@ -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,28 +2294,23 @@ 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 */
|
|
2313
|
+
/** Initialize WASM for browser environments (not needed in World App) */
|
|
2036
2314
|
init: initIDKit,
|
|
2037
2315
|
/** Initialize WASM for Node.js/server environments */
|
|
2038
2316
|
initServer: initIDKitServer,
|