@worldcoin/idkit-core 4.0.2 → 4.0.3
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 +116 -185
- package/dist/index.d.cts +8 -119
- package/dist/index.d.ts +8 -119
- package/dist/index.js +113 -182
- package/dist/signing.cjs +9 -71
- package/dist/signing.d.cts +1 -36
- package/dist/signing.d.ts +1 -36
- package/dist/signing.js +1 -73
- package/package.json +2 -2
package/dist/idkit_wasm_bg.wasm
CHANGED
|
Binary file
|
package/dist/index.cjs
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var idkitServer = require('@worldcoin/idkit-server');
|
|
3
4
|
var sha3 = require('@noble/hashes/sha3');
|
|
4
5
|
var utils = require('@noble/hashes/utils');
|
|
5
|
-
var hmac = require('@noble/hashes/hmac');
|
|
6
|
-
var sha2 = require('@noble/hashes/sha2');
|
|
7
|
-
var secp256k1 = require('@noble/secp256k1');
|
|
8
6
|
|
|
9
7
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
10
8
|
var __defProp = Object.defineProperty;
|
|
11
|
-
var __export = (target,
|
|
12
|
-
for (var name in
|
|
13
|
-
__defProp(target, name, { get:
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
12
|
};
|
|
15
13
|
|
|
16
14
|
// src/types/result.ts
|
|
@@ -394,14 +392,14 @@ function hashSignal(signal) {
|
|
|
394
392
|
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
395
393
|
}
|
|
396
394
|
}
|
|
397
|
-
function
|
|
398
|
-
wasm.
|
|
395
|
+
function __wasm_bindgen_func_elem_599(arg0, arg1) {
|
|
396
|
+
wasm.__wasm_bindgen_func_elem_599(arg0, arg1);
|
|
399
397
|
}
|
|
400
|
-
function
|
|
401
|
-
wasm.
|
|
398
|
+
function __wasm_bindgen_func_elem_962(arg0, arg1, arg2) {
|
|
399
|
+
wasm.__wasm_bindgen_func_elem_962(arg0, arg1, addHeapObject(arg2));
|
|
402
400
|
}
|
|
403
|
-
function
|
|
404
|
-
wasm.
|
|
401
|
+
function __wasm_bindgen_func_elem_1347(arg0, arg1, arg2, arg3) {
|
|
402
|
+
wasm.__wasm_bindgen_func_elem_1347(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
|
|
405
403
|
}
|
|
406
404
|
var __wbindgen_enum_RequestCache = ["default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached"];
|
|
407
405
|
var __wbindgen_enum_RequestCredentials = ["omit", "same-origin", "include"];
|
|
@@ -1564,7 +1562,7 @@ function __wbg_get_imports() {
|
|
|
1564
1562
|
const a = state0.a;
|
|
1565
1563
|
state0.a = 0;
|
|
1566
1564
|
try {
|
|
1567
|
-
return
|
|
1565
|
+
return __wasm_bindgen_func_elem_1347(a, state0.b, arg02, arg12);
|
|
1568
1566
|
} finally {
|
|
1569
1567
|
state0.a = a;
|
|
1570
1568
|
}
|
|
@@ -1777,20 +1775,20 @@ function __wbg_get_imports() {
|
|
|
1777
1775
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
1778
1776
|
return addHeapObject(ret);
|
|
1779
1777
|
};
|
|
1780
|
-
imports.wbg.
|
|
1781
|
-
const ret =
|
|
1778
|
+
imports.wbg.__wbindgen_cast_2d12912bac8cf5ca = function(arg0, arg1) {
|
|
1779
|
+
const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_961, __wasm_bindgen_func_elem_962);
|
|
1782
1780
|
return addHeapObject(ret);
|
|
1783
1781
|
};
|
|
1784
|
-
imports.wbg.
|
|
1785
|
-
const ret =
|
|
1782
|
+
imports.wbg.__wbindgen_cast_4625c577ab2ec9ee = function(arg0) {
|
|
1783
|
+
const ret = BigInt.asUintN(64, arg0);
|
|
1786
1784
|
return addHeapObject(ret);
|
|
1787
1785
|
};
|
|
1788
1786
|
imports.wbg.__wbindgen_cast_9ae0607507abb057 = function(arg0) {
|
|
1789
1787
|
const ret = arg0;
|
|
1790
1788
|
return addHeapObject(ret);
|
|
1791
1789
|
};
|
|
1792
|
-
imports.wbg.
|
|
1793
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
1790
|
+
imports.wbg.__wbindgen_cast_b8b1061c2d0ea705 = function(arg0, arg1) {
|
|
1791
|
+
const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_598, __wasm_bindgen_func_elem_599);
|
|
1794
1792
|
return addHeapObject(ret);
|
|
1795
1793
|
};
|
|
1796
1794
|
imports.wbg.__wbindgen_cast_cb9088102bce6b30 = function(arg0, arg1) {
|
|
@@ -1878,56 +1876,76 @@ async function initIDKit() {
|
|
|
1878
1876
|
}
|
|
1879
1877
|
|
|
1880
1878
|
// src/transports/native.ts
|
|
1879
|
+
var MINIAPP_VERIFY_ACTION = "miniapp-verify-action";
|
|
1881
1880
|
function isInWorldApp() {
|
|
1882
1881
|
return typeof window !== "undefined" && Boolean(window.WorldApp);
|
|
1883
1882
|
}
|
|
1884
1883
|
var _requestCounter = 0;
|
|
1885
1884
|
var _activeNativeRequest = null;
|
|
1886
|
-
function createNativeRequest(wasmPayload, config) {
|
|
1885
|
+
function createNativeRequest(wasmPayload, config, signalHashes = {}) {
|
|
1887
1886
|
if (_activeNativeRequest?.isPending()) {
|
|
1888
1887
|
console.warn(
|
|
1889
1888
|
"IDKit native request already in flight. Reusing active request."
|
|
1890
1889
|
);
|
|
1891
1890
|
return _activeNativeRequest;
|
|
1892
1891
|
}
|
|
1893
|
-
const request2 = new NativeIDKitRequest(wasmPayload, config);
|
|
1892
|
+
const request2 = new NativeIDKitRequest(wasmPayload, config, signalHashes);
|
|
1894
1893
|
_activeNativeRequest = request2;
|
|
1895
1894
|
return request2;
|
|
1896
1895
|
}
|
|
1897
1896
|
var NativeIDKitRequest = class {
|
|
1898
|
-
constructor(wasmPayload, config) {
|
|
1897
|
+
constructor(wasmPayload, config, signalHashes = {}) {
|
|
1899
1898
|
this.connectorURI = "";
|
|
1900
1899
|
this.resolved = false;
|
|
1901
1900
|
this.cancelled = false;
|
|
1902
1901
|
this.settled = false;
|
|
1903
1902
|
this.resolvedResult = null;
|
|
1904
1903
|
this.messageHandler = null;
|
|
1904
|
+
this.miniKitHandler = null;
|
|
1905
1905
|
this.rejectFn = null;
|
|
1906
1906
|
this.requestId = crypto.randomUUID?.() ?? `native-${Date.now()}-${++_requestCounter}`;
|
|
1907
1907
|
this.resultPromise = new Promise((resolve, reject) => {
|
|
1908
1908
|
this.rejectFn = reject;
|
|
1909
|
+
const handleIncomingPayload = (responsePayload) => {
|
|
1910
|
+
if (this.cancelled || this.resolved || this.settled) return;
|
|
1911
|
+
if (responsePayload?.status === "error") {
|
|
1912
|
+
this.cleanup();
|
|
1913
|
+
reject(
|
|
1914
|
+
new NativeVerifyError(
|
|
1915
|
+
responsePayload.error_code ?? "generic_error" /* GenericError */
|
|
1916
|
+
)
|
|
1917
|
+
);
|
|
1918
|
+
return;
|
|
1919
|
+
}
|
|
1920
|
+
this.resolved = true;
|
|
1921
|
+
const result = nativeResultToIDKitResult(
|
|
1922
|
+
responsePayload,
|
|
1923
|
+
config,
|
|
1924
|
+
signalHashes
|
|
1925
|
+
);
|
|
1926
|
+
this.resolvedResult = result;
|
|
1927
|
+
this.cleanup();
|
|
1928
|
+
resolve(result);
|
|
1929
|
+
};
|
|
1909
1930
|
const handler = (event) => {
|
|
1910
|
-
if (this.cancelled) return;
|
|
1911
1931
|
const data = event.data;
|
|
1912
|
-
if (data?.type ===
|
|
1913
|
-
|
|
1914
|
-
const responsePayload = data.payload ?? data;
|
|
1915
|
-
if (responsePayload.status === "error") {
|
|
1916
|
-
reject(
|
|
1917
|
-
new NativeVerifyError(
|
|
1918
|
-
responsePayload.error_code ?? "generic_error" /* GenericError */
|
|
1919
|
-
)
|
|
1920
|
-
);
|
|
1921
|
-
} else {
|
|
1922
|
-
this.resolved = true;
|
|
1923
|
-
const result = nativeResultToIDKitResult(responsePayload, config);
|
|
1924
|
-
this.resolvedResult = result;
|
|
1925
|
-
resolve(result);
|
|
1926
|
-
}
|
|
1932
|
+
if (data?.type === MINIAPP_VERIFY_ACTION || data?.command === MINIAPP_VERIFY_ACTION) {
|
|
1933
|
+
handleIncomingPayload(data.payload ?? data);
|
|
1927
1934
|
}
|
|
1928
1935
|
};
|
|
1929
1936
|
this.messageHandler = handler;
|
|
1930
1937
|
window.addEventListener("message", handler);
|
|
1938
|
+
try {
|
|
1939
|
+
const miniKit = window.MiniKit;
|
|
1940
|
+
if (typeof miniKit?.subscribe === "function") {
|
|
1941
|
+
const miniKitHandler = (payload) => {
|
|
1942
|
+
handleIncomingPayload(payload?.payload ?? payload);
|
|
1943
|
+
};
|
|
1944
|
+
this.miniKitHandler = miniKitHandler;
|
|
1945
|
+
miniKit.subscribe(MINIAPP_VERIFY_ACTION, miniKitHandler);
|
|
1946
|
+
}
|
|
1947
|
+
} catch {
|
|
1948
|
+
}
|
|
1931
1949
|
const sendPayload = {
|
|
1932
1950
|
command: "verify",
|
|
1933
1951
|
version: 2,
|
|
@@ -1970,6 +1988,14 @@ var NativeIDKitRequest = class {
|
|
|
1970
1988
|
window.removeEventListener("message", this.messageHandler);
|
|
1971
1989
|
this.messageHandler = null;
|
|
1972
1990
|
}
|
|
1991
|
+
if (this.miniKitHandler) {
|
|
1992
|
+
try {
|
|
1993
|
+
const miniKit = window.MiniKit;
|
|
1994
|
+
miniKit?.unsubscribe?.(MINIAPP_VERIFY_ACTION);
|
|
1995
|
+
} catch {
|
|
1996
|
+
}
|
|
1997
|
+
this.miniKitHandler = null;
|
|
1998
|
+
}
|
|
1973
1999
|
}
|
|
1974
2000
|
isPending() {
|
|
1975
2001
|
return !this.settled && !this.cancelled;
|
|
@@ -2033,26 +2059,32 @@ var NativeVerifyError = class extends Error {
|
|
|
2033
2059
|
this.code = code;
|
|
2034
2060
|
}
|
|
2035
2061
|
};
|
|
2036
|
-
function nativeResultToIDKitResult(payload, config) {
|
|
2062
|
+
function nativeResultToIDKitResult(payload, config, signalHashes) {
|
|
2037
2063
|
const rpNonce = config.rp_context?.nonce ?? "";
|
|
2038
|
-
if ("responses" in payload
|
|
2064
|
+
if ("responses" in payload) {
|
|
2065
|
+
const v4 = payload;
|
|
2039
2066
|
return {
|
|
2040
|
-
protocol_version:
|
|
2041
|
-
nonce:
|
|
2042
|
-
action:
|
|
2043
|
-
action_description:
|
|
2044
|
-
session_id:
|
|
2045
|
-
responses:
|
|
2046
|
-
|
|
2067
|
+
protocol_version: v4.protocol_version ?? "4.0",
|
|
2068
|
+
nonce: v4.nonce ?? rpNonce,
|
|
2069
|
+
action: v4.action ?? config.action ?? "",
|
|
2070
|
+
action_description: v4.action_description,
|
|
2071
|
+
session_id: v4.session_id,
|
|
2072
|
+
responses: v4.responses.map((item) => ({
|
|
2073
|
+
...item,
|
|
2074
|
+
signal_hash: signalHashes[item.identifier]
|
|
2075
|
+
})),
|
|
2076
|
+
environment: v4.environment ?? config.environment ?? "production"
|
|
2047
2077
|
};
|
|
2048
2078
|
}
|
|
2049
2079
|
if ("verifications" in payload) {
|
|
2080
|
+
const multi = payload;
|
|
2050
2081
|
return {
|
|
2051
2082
|
protocol_version: "4.0",
|
|
2052
2083
|
nonce: rpNonce,
|
|
2053
2084
|
action: config.action ?? "",
|
|
2054
|
-
responses:
|
|
2085
|
+
responses: multi.verifications.map((v) => ({
|
|
2055
2086
|
identifier: v.verification_level,
|
|
2087
|
+
signal_hash: v.signal_hash ?? signalHashes[v.verification_level],
|
|
2056
2088
|
proof: [v.proof],
|
|
2057
2089
|
nullifier: v.nullifier_hash,
|
|
2058
2090
|
merkle_root: v.merkle_root,
|
|
@@ -2062,16 +2094,18 @@ function nativeResultToIDKitResult(payload, config) {
|
|
|
2062
2094
|
environment: "production"
|
|
2063
2095
|
};
|
|
2064
2096
|
}
|
|
2097
|
+
const single = payload;
|
|
2065
2098
|
return {
|
|
2066
2099
|
protocol_version: "3.0",
|
|
2067
2100
|
nonce: rpNonce,
|
|
2068
2101
|
action: config.action ?? "",
|
|
2069
2102
|
responses: [
|
|
2070
2103
|
{
|
|
2071
|
-
identifier:
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2104
|
+
identifier: single.verification_level,
|
|
2105
|
+
signal_hash: single.signal_hash ?? signalHashes[single.verification_level],
|
|
2106
|
+
proof: single.proof,
|
|
2107
|
+
merkle_root: single.merkle_root,
|
|
2108
|
+
nullifier: single.nullifier_hash
|
|
2075
2109
|
}
|
|
2076
2110
|
],
|
|
2077
2111
|
environment: "production"
|
|
@@ -2119,20 +2153,6 @@ var IDKitRequestImpl = class {
|
|
|
2119
2153
|
}
|
|
2120
2154
|
}
|
|
2121
2155
|
};
|
|
2122
|
-
function CredentialRequest(credential_type, options) {
|
|
2123
|
-
return {
|
|
2124
|
-
type: credential_type,
|
|
2125
|
-
signal: options?.signal,
|
|
2126
|
-
genesis_issued_at_min: options?.genesis_issued_at_min,
|
|
2127
|
-
expires_at_min: options?.expires_at_min
|
|
2128
|
-
};
|
|
2129
|
-
}
|
|
2130
|
-
function any(...nodes) {
|
|
2131
|
-
return { any: nodes };
|
|
2132
|
-
}
|
|
2133
|
-
function all(...nodes) {
|
|
2134
|
-
return { all: nodes };
|
|
2135
|
-
}
|
|
2136
2156
|
function orbLegacy(opts = {}) {
|
|
2137
2157
|
return { type: "OrbLegacy", signal: opts.signal };
|
|
2138
2158
|
}
|
|
@@ -2192,7 +2212,7 @@ var IDKitBuilder2 = class {
|
|
|
2192
2212
|
/**
|
|
2193
2213
|
* Creates an IDKit request with the given constraints
|
|
2194
2214
|
*
|
|
2195
|
-
* @param constraints - Constraint tree (CredentialRequest or any/all combinators)
|
|
2215
|
+
* @param constraints - Constraint tree (CredentialRequest or any/all/enumerate combinators)
|
|
2196
2216
|
* @returns A new IDKitRequest instance
|
|
2197
2217
|
*
|
|
2198
2218
|
* @example
|
|
@@ -2205,8 +2225,12 @@ var IDKitBuilder2 = class {
|
|
|
2205
2225
|
await initIDKit();
|
|
2206
2226
|
const wasmBuilder = createWasmBuilderFromConfig(this.config);
|
|
2207
2227
|
if (isInWorldApp()) {
|
|
2208
|
-
const
|
|
2209
|
-
return createNativeRequest(
|
|
2228
|
+
const wasmResult = wasmBuilder.nativePayload(constraints);
|
|
2229
|
+
return createNativeRequest(
|
|
2230
|
+
wasmResult.payload,
|
|
2231
|
+
this.config,
|
|
2232
|
+
wasmResult.signal_hashes ?? {}
|
|
2233
|
+
);
|
|
2210
2234
|
}
|
|
2211
2235
|
const wasmRequest = await wasmBuilder.constraints(
|
|
2212
2236
|
constraints
|
|
@@ -2232,8 +2256,12 @@ var IDKitBuilder2 = class {
|
|
|
2232
2256
|
await initIDKit();
|
|
2233
2257
|
const wasmBuilder = createWasmBuilderFromConfig(this.config);
|
|
2234
2258
|
if (isInWorldApp()) {
|
|
2235
|
-
const
|
|
2236
|
-
return createNativeRequest(
|
|
2259
|
+
const wasmResult = wasmBuilder.nativePayloadFromPreset(preset);
|
|
2260
|
+
return createNativeRequest(
|
|
2261
|
+
wasmResult.payload,
|
|
2262
|
+
this.config,
|
|
2263
|
+
wasmResult.signal_hashes ?? {}
|
|
2264
|
+
);
|
|
2237
2265
|
}
|
|
2238
2266
|
const wasmRequest = await wasmBuilder.preset(
|
|
2239
2267
|
preset
|
|
@@ -2270,61 +2298,22 @@ function createRequest(config) {
|
|
|
2270
2298
|
environment: config.environment
|
|
2271
2299
|
});
|
|
2272
2300
|
}
|
|
2273
|
-
function createSession2(config) {
|
|
2274
|
-
if (!config.app_id) {
|
|
2275
|
-
throw new Error("app_id is required");
|
|
2276
|
-
}
|
|
2277
|
-
if (!config.rp_context) {
|
|
2278
|
-
throw new Error(
|
|
2279
|
-
"rp_context is required. Generate it on your backend using signRequest()."
|
|
2280
|
-
);
|
|
2281
|
-
}
|
|
2282
|
-
return new IDKitBuilder2({
|
|
2283
|
-
type: "session",
|
|
2284
|
-
app_id: config.app_id,
|
|
2285
|
-
rp_context: config.rp_context,
|
|
2286
|
-
action_description: config.action_description,
|
|
2287
|
-
bridge_url: config.bridge_url,
|
|
2288
|
-
override_connect_base_url: config.override_connect_base_url,
|
|
2289
|
-
environment: config.environment
|
|
2290
|
-
});
|
|
2291
|
-
}
|
|
2292
|
-
function proveSession2(sessionId, config) {
|
|
2293
|
-
if (!sessionId) {
|
|
2294
|
-
throw new Error("session_id is required");
|
|
2295
|
-
}
|
|
2296
|
-
if (!config.app_id) {
|
|
2297
|
-
throw new Error("app_id is required");
|
|
2298
|
-
}
|
|
2299
|
-
if (!config.rp_context) {
|
|
2300
|
-
throw new Error(
|
|
2301
|
-
"rp_context is required. Generate it on your backend using signRequest()."
|
|
2302
|
-
);
|
|
2303
|
-
}
|
|
2304
|
-
return new IDKitBuilder2({
|
|
2305
|
-
type: "proveSession",
|
|
2306
|
-
session_id: sessionId,
|
|
2307
|
-
app_id: config.app_id,
|
|
2308
|
-
rp_context: config.rp_context,
|
|
2309
|
-
action_description: config.action_description,
|
|
2310
|
-
bridge_url: config.bridge_url,
|
|
2311
|
-
override_connect_base_url: config.override_connect_base_url,
|
|
2312
|
-
environment: config.environment
|
|
2313
|
-
});
|
|
2314
|
-
}
|
|
2315
2301
|
var IDKit = {
|
|
2316
2302
|
/** Create a new verification request */
|
|
2317
2303
|
request: createRequest,
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
CredentialRequest
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
all
|
|
2304
|
+
// TODO: Re-enable when World ID 4.0 is live
|
|
2305
|
+
// /** Create a new session (no action, no existing session_id) */
|
|
2306
|
+
// createSession,
|
|
2307
|
+
// /** Prove an existing session (no action, has session_id) */
|
|
2308
|
+
// proveSession,
|
|
2309
|
+
// /** Create a CredentialRequest for a credential type */
|
|
2310
|
+
// CredentialRequest,
|
|
2311
|
+
// /** Create an OR constraint - at least one child must be satisfied */
|
|
2312
|
+
// any,
|
|
2313
|
+
// /** Create an AND constraint - all children must be satisfied */
|
|
2314
|
+
// all,
|
|
2315
|
+
// /** Create an enumerate constraint - all satisfiable children should be selected */
|
|
2316
|
+
// enumerate,
|
|
2328
2317
|
/** Create an OrbLegacy preset for World ID 3.0 legacy support */
|
|
2329
2318
|
orbLegacy,
|
|
2330
2319
|
/** Create a SecureDocumentLegacy preset for World ID 3.0 legacy support */
|
|
@@ -2343,18 +2332,6 @@ var isWeb = () => {
|
|
|
2343
2332
|
var isNode = () => {
|
|
2344
2333
|
return typeof process !== "undefined" && typeof process.versions !== "undefined" && typeof process.versions.node !== "undefined";
|
|
2345
2334
|
};
|
|
2346
|
-
var isServerEnvironment = () => {
|
|
2347
|
-
if (typeof process !== "undefined" && process.versions?.node) {
|
|
2348
|
-
return true;
|
|
2349
|
-
}
|
|
2350
|
-
if (typeof globalThis.Deno !== "undefined") {
|
|
2351
|
-
return true;
|
|
2352
|
-
}
|
|
2353
|
-
if (typeof globalThis.Bun !== "undefined") {
|
|
2354
|
-
return true;
|
|
2355
|
-
}
|
|
2356
|
-
return false;
|
|
2357
|
-
};
|
|
2358
2335
|
function hashToField(input) {
|
|
2359
2336
|
const hash = BigInt("0x" + utils.bytesToHex(sha3.keccak_256(input))) >> 8n;
|
|
2360
2337
|
return utils.hexToBytes(hash.toString(16).padStart(64, "0"));
|
|
@@ -2376,57 +2353,12 @@ function isValidHex(s) {
|
|
|
2376
2353
|
return /^[0-9a-fA-F]+$/.test(s);
|
|
2377
2354
|
}
|
|
2378
2355
|
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
const message = new Uint8Array(48);
|
|
2384
|
-
message.set(nonceBytes, 0);
|
|
2385
|
-
const view = new DataView(message.buffer);
|
|
2386
|
-
view.setBigUint64(32, BigInt(createdAt), false);
|
|
2387
|
-
view.setBigUint64(40, BigInt(expiresAt), false);
|
|
2388
|
-
return message;
|
|
2389
|
-
}
|
|
2390
|
-
function signRequest2(_action, signingKeyHex, ttl = DEFAULT_TTL_SEC) {
|
|
2391
|
-
if (!isServerEnvironment()) {
|
|
2392
|
-
throw new Error(
|
|
2393
|
-
"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."
|
|
2394
|
-
);
|
|
2395
|
-
}
|
|
2396
|
-
const keyHex = signingKeyHex.startsWith("0x") ? signingKeyHex.slice(2) : signingKeyHex;
|
|
2397
|
-
if (!/^[0-9a-fA-F]+$/.test(keyHex)) {
|
|
2398
|
-
throw new Error("Invalid signing key: contains non-hex characters");
|
|
2399
|
-
}
|
|
2400
|
-
if (keyHex.length !== 64) {
|
|
2401
|
-
throw new Error(
|
|
2402
|
-
`Invalid signing key: expected 32 bytes (64 hex chars), got ${keyHex.length / 2} bytes`
|
|
2403
|
-
);
|
|
2404
|
-
}
|
|
2405
|
-
const privKey = secp256k1.etc.hexToBytes(keyHex);
|
|
2406
|
-
const randomBytes = crypto.getRandomValues(new Uint8Array(32));
|
|
2407
|
-
const nonceBytes = hashToField(randomBytes);
|
|
2408
|
-
const createdAt = Math.floor(Date.now() / 1e3);
|
|
2409
|
-
const expiresAt = createdAt + ttl;
|
|
2410
|
-
const message = computeRpSignatureMessage(nonceBytes, createdAt, expiresAt);
|
|
2411
|
-
const msgHash = sha3.keccak_256(message);
|
|
2412
|
-
const recSig = secp256k1.sign(msgHash, privKey);
|
|
2413
|
-
const compact = recSig.toCompactRawBytes();
|
|
2414
|
-
const sig65 = new Uint8Array(65);
|
|
2415
|
-
sig65.set(compact, 0);
|
|
2416
|
-
sig65[64] = recSig.recovery + 27;
|
|
2417
|
-
return {
|
|
2418
|
-
sig: "0x" + utils.bytesToHex(sig65),
|
|
2419
|
-
nonce: "0x" + utils.bytesToHex(nonceBytes),
|
|
2420
|
-
createdAt,
|
|
2421
|
-
expiresAt
|
|
2422
|
-
};
|
|
2423
|
-
}
|
|
2424
|
-
|
|
2425
|
-
exports.CredentialRequest = CredentialRequest;
|
|
2356
|
+
Object.defineProperty(exports, "signRequest", {
|
|
2357
|
+
enumerable: true,
|
|
2358
|
+
get: function () { return idkitServer.signRequest; }
|
|
2359
|
+
});
|
|
2426
2360
|
exports.IDKit = IDKit;
|
|
2427
2361
|
exports.IDKitErrorCodes = IDKitErrorCodes;
|
|
2428
|
-
exports.all = all;
|
|
2429
|
-
exports.any = any;
|
|
2430
2362
|
exports.documentLegacy = documentLegacy;
|
|
2431
2363
|
exports.hashSignal = hashSignal2;
|
|
2432
2364
|
exports.isNode = isNode;
|
|
@@ -2434,4 +2366,3 @@ exports.isReactNative = isReactNative;
|
|
|
2434
2366
|
exports.isWeb = isWeb;
|
|
2435
2367
|
exports.orbLegacy = orbLegacy;
|
|
2436
2368
|
exports.secureDocumentLegacy = secureDocumentLegacy;
|
|
2437
|
-
exports.signRequest = signRequest2;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { RpSignature, signRequest } from '
|
|
1
|
+
export { RpSignature, signRequest } from '@worldcoin/idkit-server';
|
|
2
2
|
export { hashSignal } from './hashing.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -241,7 +241,8 @@ interface CredentialRequestType {
|
|
|
241
241
|
type ConstraintNode =
|
|
242
242
|
| CredentialRequestType
|
|
243
243
|
| { any: ConstraintNode[] }
|
|
244
|
-
| { all: ConstraintNode[] }
|
|
244
|
+
| { all: ConstraintNode[] }
|
|
245
|
+
| { enumerate: ConstraintNode[] };
|
|
245
246
|
|
|
246
247
|
/**
|
|
247
248
|
* Result types - re-exported from WASM bindings
|
|
@@ -329,55 +330,6 @@ interface IDKitRequest {
|
|
|
329
330
|
/** Poll continuously until completion or timeout */
|
|
330
331
|
pollUntilCompletion(options?: WaitOptions): Promise<IDKitCompletionResult>;
|
|
331
332
|
}
|
|
332
|
-
/**
|
|
333
|
-
* Creates a CredentialRequest for a credential type
|
|
334
|
-
*
|
|
335
|
-
* @param credential_type - The type of credential to request (e.g., 'orb', 'face')
|
|
336
|
-
* @param options - Optional signal, genesis_issued_at_min, and expires_at_min
|
|
337
|
-
* @returns A CredentialRequest object
|
|
338
|
-
*
|
|
339
|
-
* @example
|
|
340
|
-
* ```typescript
|
|
341
|
-
* const orb = CredentialRequest('orb', { signal: 'user-123' })
|
|
342
|
-
* const face = CredentialRequest('face')
|
|
343
|
-
* // Require credential to be valid for at least one year
|
|
344
|
-
* const withExpiry = CredentialRequest('orb', { expires_at_min: Date.now() / 1000 + 60 * 60 * 60 * 24 * 365 })
|
|
345
|
-
* ```
|
|
346
|
-
*/
|
|
347
|
-
declare function CredentialRequest(credential_type: CredentialType, options?: {
|
|
348
|
-
signal?: string;
|
|
349
|
-
genesis_issued_at_min?: number;
|
|
350
|
-
expires_at_min?: number;
|
|
351
|
-
}): CredentialRequestType;
|
|
352
|
-
/**
|
|
353
|
-
* Creates an OR constraint - at least one child must be satisfied
|
|
354
|
-
*
|
|
355
|
-
* @param nodes - Constraint nodes (CredentialRequests or nested constraints)
|
|
356
|
-
* @returns An "any" constraint node
|
|
357
|
-
*
|
|
358
|
-
* @example
|
|
359
|
-
* ```typescript
|
|
360
|
-
* const constraint = any(CredentialRequest('orb'), CredentialRequest('face'))
|
|
361
|
-
* ```
|
|
362
|
-
*/
|
|
363
|
-
declare function any(...nodes: ConstraintNode[]): {
|
|
364
|
-
any: ConstraintNode[];
|
|
365
|
-
};
|
|
366
|
-
/**
|
|
367
|
-
* Creates an AND constraint - all children must be satisfied
|
|
368
|
-
*
|
|
369
|
-
* @param nodes - Constraint nodes (CredentialRequests or nested constraints)
|
|
370
|
-
* @returns An "all" constraint node
|
|
371
|
-
*
|
|
372
|
-
* @example
|
|
373
|
-
* ```typescript
|
|
374
|
-
* const constraint = all(CredentialRequest('orb'), any(CredentialRequest('document'), CredentialRequest('secure_document')))
|
|
375
|
-
* ```
|
|
376
|
-
*/
|
|
377
|
-
declare function all(...nodes: ConstraintNode[]): {
|
|
378
|
-
all: ConstraintNode[];
|
|
379
|
-
};
|
|
380
|
-
|
|
381
333
|
/**
|
|
382
334
|
* Creates an OrbLegacy preset for World ID 3.0 legacy support
|
|
383
335
|
*
|
|
@@ -445,7 +397,7 @@ declare class IDKitBuilder {
|
|
|
445
397
|
/**
|
|
446
398
|
* Creates an IDKit request with the given constraints
|
|
447
399
|
*
|
|
448
|
-
* @param constraints - Constraint tree (CredentialRequest or any/all combinators)
|
|
400
|
+
* @param constraints - Constraint tree (CredentialRequest or any/all/enumerate combinators)
|
|
449
401
|
* @returns A new IDKitRequest instance
|
|
450
402
|
*
|
|
451
403
|
* @example
|
|
@@ -484,7 +436,7 @@ declare class IDKitBuilder {
|
|
|
484
436
|
*
|
|
485
437
|
* @example
|
|
486
438
|
* ```typescript
|
|
487
|
-
* import { IDKit, CredentialRequest, any, orbLegacy } from '@worldcoin/idkit-core'
|
|
439
|
+
* import { IDKit, CredentialRequest, any, enumerate, orbLegacy } from '@worldcoin/idkit-core'
|
|
488
440
|
*
|
|
489
441
|
* // With preset (legacy support)
|
|
490
442
|
* const request = await IDKit.request({
|
|
@@ -500,7 +452,7 @@ declare class IDKitBuilder {
|
|
|
500
452
|
* action: 'my-action',
|
|
501
453
|
* rp_context: { ... },
|
|
502
454
|
* allow_legacy_proofs: false,
|
|
503
|
-
* }).constraints(
|
|
455
|
+
* }).constraints(enumerate(CredentialRequest('orb'), CredentialRequest('face')));
|
|
504
456
|
*
|
|
505
457
|
* // In World App: connectorURI is empty, result comes via postMessage
|
|
506
458
|
* // On web: connectorURI is the QR URL to display
|
|
@@ -511,65 +463,12 @@ declare class IDKitBuilder {
|
|
|
511
463
|
* ```
|
|
512
464
|
*/
|
|
513
465
|
declare function createRequest(config: IDKitRequestConfig): IDKitBuilder;
|
|
514
|
-
/**
|
|
515
|
-
* Creates a new session builder (no action, no existing session_id)
|
|
516
|
-
*
|
|
517
|
-
* Use this when creating a new session for a user who doesn't have one yet.
|
|
518
|
-
* The response will include a `session_id` that should be saved for future
|
|
519
|
-
* session proofs with `proveSession()`.
|
|
520
|
-
*
|
|
521
|
-
* @param config - Session configuration (no action field)
|
|
522
|
-
* @returns IDKitBuilder - A builder instance
|
|
523
|
-
*
|
|
524
|
-
* @example
|
|
525
|
-
* ```typescript
|
|
526
|
-
* import { IDKit, CredentialRequest, any } from '@worldcoin/idkit-core'
|
|
527
|
-
*
|
|
528
|
-
* // Create a new session (user doesn't have session_id yet)
|
|
529
|
-
* const request = await IDKit.createSession({
|
|
530
|
-
* app_id: 'app_staging_xxxxx',
|
|
531
|
-
* rp_context: { ... },
|
|
532
|
-
* }).constraints(any(CredentialRequest('orb'), CredentialRequest('face')));
|
|
533
|
-
*
|
|
534
|
-
* // Display QR, wait for proof
|
|
535
|
-
* const result = await request.pollUntilCompletion();
|
|
536
|
-
* // result.session_id -> save this for future sessions
|
|
537
|
-
* // result.responses[0].session_nullifier -> for session tracking
|
|
538
|
-
* ```
|
|
539
|
-
*/
|
|
540
|
-
declare function createSession(config: IDKitSessionConfig): IDKitBuilder;
|
|
541
|
-
/**
|
|
542
|
-
* Creates a builder for proving an existing session (no action, has session_id)
|
|
543
|
-
*
|
|
544
|
-
* Use this when a returning user needs to prove they own an existing session.
|
|
545
|
-
* The `sessionId` should be a value previously returned from `createSession()`.
|
|
546
|
-
*
|
|
547
|
-
* @param sessionId - The session ID from a previous session creation
|
|
548
|
-
* @param config - Session configuration (no action field)
|
|
549
|
-
* @returns IDKitBuilder - A builder instance
|
|
550
|
-
*
|
|
551
|
-
* @example
|
|
552
|
-
* ```typescript
|
|
553
|
-
* import { IDKit, CredentialRequest, any } from '@worldcoin/idkit-core'
|
|
554
|
-
*
|
|
555
|
-
* // Prove an existing session (user returns)
|
|
556
|
-
* const request = await IDKit.proveSession(savedSessionId, {
|
|
557
|
-
* app_id: 'app_staging_xxxxx',
|
|
558
|
-
* rp_context: { ... },
|
|
559
|
-
* }).constraints(any(CredentialRequest('orb'), CredentialRequest('face')));
|
|
560
|
-
*
|
|
561
|
-
* const result = await request.pollUntilCompletion();
|
|
562
|
-
* // result.session_id -> same session
|
|
563
|
-
* // result.responses[0].session_nullifier -> should match for same user
|
|
564
|
-
* ```
|
|
565
|
-
*/
|
|
566
|
-
declare function proveSession(sessionId: string, config: IDKitSessionConfig): IDKitBuilder;
|
|
567
466
|
/**
|
|
568
467
|
* IDKit namespace providing the main API entry points
|
|
569
468
|
*
|
|
570
469
|
* @example
|
|
571
470
|
* ```typescript
|
|
572
|
-
* import { IDKit, CredentialRequest, any, orbLegacy } from '@worldcoin/idkit-core'
|
|
471
|
+
* import { IDKit, CredentialRequest, any, enumerate, orbLegacy } from '@worldcoin/idkit-core'
|
|
573
472
|
*
|
|
574
473
|
* // Create a verification request
|
|
575
474
|
* const request = await IDKit.request({
|
|
@@ -588,16 +487,6 @@ declare function proveSession(sessionId: string, config: IDKitSessionConfig): ID
|
|
|
588
487
|
declare const IDKit: {
|
|
589
488
|
/** Create a new verification request */
|
|
590
489
|
request: typeof createRequest;
|
|
591
|
-
/** Create a new session (no action, no existing session_id) */
|
|
592
|
-
createSession: typeof createSession;
|
|
593
|
-
/** Prove an existing session (no action, has session_id) */
|
|
594
|
-
proveSession: typeof proveSession;
|
|
595
|
-
/** Create a CredentialRequest for a credential type */
|
|
596
|
-
CredentialRequest: typeof CredentialRequest;
|
|
597
|
-
/** Create an OR constraint - at least one child must be satisfied */
|
|
598
|
-
any: typeof any;
|
|
599
|
-
/** Create an AND constraint - all children must be satisfied */
|
|
600
|
-
all: typeof all;
|
|
601
490
|
/** Create an OrbLegacy preset for World ID 3.0 legacy support */
|
|
602
491
|
orbLegacy: typeof orbLegacy;
|
|
603
492
|
/** Create a SecureDocumentLegacy preset for World ID 3.0 legacy support */
|
|
@@ -628,4 +517,4 @@ declare const isWeb: () => boolean;
|
|
|
628
517
|
*/
|
|
629
518
|
declare const isNode: () => boolean;
|
|
630
519
|
|
|
631
|
-
export { type AbiEncodedValue, type ConstraintNode,
|
|
520
|
+
export { type AbiEncodedValue, type ConstraintNode, type CredentialRequestType, type CredentialType, type DocumentLegacyPreset, IDKit, type IDKitCompletionResult, type IDKitErrorCode, IDKitErrorCodes, type IDKitRequest, type IDKitRequestConfig, type IDKitResult, type IDKitResultSession, type IDKitSessionConfig, type OrbLegacyPreset, type Preset, type ResponseItemSession, type ResponseItemV3, type ResponseItemV4, type RpContext, type SecureDocumentLegacyPreset, type Status$1 as Status, type WaitOptions, documentLegacy, isNode, isReactNative, isWeb, orbLegacy, secureDocumentLegacy };
|