@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/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { RpSignature, signRequest } from '
|
|
1
|
+
export { RpSignature, signRequest } from '@worldcoin/idkit-server';
|
|
2
2
|
export { hashSignal } from './hashing.js';
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
+
export { signRequest } from '@worldcoin/idkit-server';
|
|
1
2
|
import { keccak_256 } from '@noble/hashes/sha3';
|
|
2
3
|
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
4
|
|
|
7
5
|
var __defProp = Object.defineProperty;
|
|
8
|
-
var __export = (target,
|
|
9
|
-
for (var name in
|
|
10
|
-
__defProp(target, name, { get:
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
9
|
};
|
|
12
10
|
|
|
13
11
|
// src/types/result.ts
|
|
@@ -391,14 +389,14 @@ function hashSignal(signal) {
|
|
|
391
389
|
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
392
390
|
}
|
|
393
391
|
}
|
|
394
|
-
function
|
|
395
|
-
wasm.
|
|
392
|
+
function __wasm_bindgen_func_elem_599(arg0, arg1) {
|
|
393
|
+
wasm.__wasm_bindgen_func_elem_599(arg0, arg1);
|
|
396
394
|
}
|
|
397
|
-
function
|
|
398
|
-
wasm.
|
|
395
|
+
function __wasm_bindgen_func_elem_962(arg0, arg1, arg2) {
|
|
396
|
+
wasm.__wasm_bindgen_func_elem_962(arg0, arg1, addHeapObject(arg2));
|
|
399
397
|
}
|
|
400
|
-
function
|
|
401
|
-
wasm.
|
|
398
|
+
function __wasm_bindgen_func_elem_1347(arg0, arg1, arg2, arg3) {
|
|
399
|
+
wasm.__wasm_bindgen_func_elem_1347(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
|
|
402
400
|
}
|
|
403
401
|
var __wbindgen_enum_RequestCache = ["default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached"];
|
|
404
402
|
var __wbindgen_enum_RequestCredentials = ["omit", "same-origin", "include"];
|
|
@@ -1561,7 +1559,7 @@ function __wbg_get_imports() {
|
|
|
1561
1559
|
const a = state0.a;
|
|
1562
1560
|
state0.a = 0;
|
|
1563
1561
|
try {
|
|
1564
|
-
return
|
|
1562
|
+
return __wasm_bindgen_func_elem_1347(a, state0.b, arg02, arg12);
|
|
1565
1563
|
} finally {
|
|
1566
1564
|
state0.a = a;
|
|
1567
1565
|
}
|
|
@@ -1774,20 +1772,20 @@ function __wbg_get_imports() {
|
|
|
1774
1772
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
1775
1773
|
return addHeapObject(ret);
|
|
1776
1774
|
};
|
|
1777
|
-
imports.wbg.
|
|
1778
|
-
const ret =
|
|
1775
|
+
imports.wbg.__wbindgen_cast_2d12912bac8cf5ca = function(arg0, arg1) {
|
|
1776
|
+
const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_961, __wasm_bindgen_func_elem_962);
|
|
1779
1777
|
return addHeapObject(ret);
|
|
1780
1778
|
};
|
|
1781
|
-
imports.wbg.
|
|
1782
|
-
const ret =
|
|
1779
|
+
imports.wbg.__wbindgen_cast_4625c577ab2ec9ee = function(arg0) {
|
|
1780
|
+
const ret = BigInt.asUintN(64, arg0);
|
|
1783
1781
|
return addHeapObject(ret);
|
|
1784
1782
|
};
|
|
1785
1783
|
imports.wbg.__wbindgen_cast_9ae0607507abb057 = function(arg0) {
|
|
1786
1784
|
const ret = arg0;
|
|
1787
1785
|
return addHeapObject(ret);
|
|
1788
1786
|
};
|
|
1789
|
-
imports.wbg.
|
|
1790
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
1787
|
+
imports.wbg.__wbindgen_cast_b8b1061c2d0ea705 = function(arg0, arg1) {
|
|
1788
|
+
const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_598, __wasm_bindgen_func_elem_599);
|
|
1791
1789
|
return addHeapObject(ret);
|
|
1792
1790
|
};
|
|
1793
1791
|
imports.wbg.__wbindgen_cast_cb9088102bce6b30 = function(arg0, arg1) {
|
|
@@ -1875,56 +1873,76 @@ async function initIDKit() {
|
|
|
1875
1873
|
}
|
|
1876
1874
|
|
|
1877
1875
|
// src/transports/native.ts
|
|
1876
|
+
var MINIAPP_VERIFY_ACTION = "miniapp-verify-action";
|
|
1878
1877
|
function isInWorldApp() {
|
|
1879
1878
|
return typeof window !== "undefined" && Boolean(window.WorldApp);
|
|
1880
1879
|
}
|
|
1881
1880
|
var _requestCounter = 0;
|
|
1882
1881
|
var _activeNativeRequest = null;
|
|
1883
|
-
function createNativeRequest(wasmPayload, config) {
|
|
1882
|
+
function createNativeRequest(wasmPayload, config, signalHashes = {}) {
|
|
1884
1883
|
if (_activeNativeRequest?.isPending()) {
|
|
1885
1884
|
console.warn(
|
|
1886
1885
|
"IDKit native request already in flight. Reusing active request."
|
|
1887
1886
|
);
|
|
1888
1887
|
return _activeNativeRequest;
|
|
1889
1888
|
}
|
|
1890
|
-
const request2 = new NativeIDKitRequest(wasmPayload, config);
|
|
1889
|
+
const request2 = new NativeIDKitRequest(wasmPayload, config, signalHashes);
|
|
1891
1890
|
_activeNativeRequest = request2;
|
|
1892
1891
|
return request2;
|
|
1893
1892
|
}
|
|
1894
1893
|
var NativeIDKitRequest = class {
|
|
1895
|
-
constructor(wasmPayload, config) {
|
|
1894
|
+
constructor(wasmPayload, config, signalHashes = {}) {
|
|
1896
1895
|
this.connectorURI = "";
|
|
1897
1896
|
this.resolved = false;
|
|
1898
1897
|
this.cancelled = false;
|
|
1899
1898
|
this.settled = false;
|
|
1900
1899
|
this.resolvedResult = null;
|
|
1901
1900
|
this.messageHandler = null;
|
|
1901
|
+
this.miniKitHandler = null;
|
|
1902
1902
|
this.rejectFn = null;
|
|
1903
1903
|
this.requestId = crypto.randomUUID?.() ?? `native-${Date.now()}-${++_requestCounter}`;
|
|
1904
1904
|
this.resultPromise = new Promise((resolve, reject) => {
|
|
1905
1905
|
this.rejectFn = reject;
|
|
1906
|
+
const handleIncomingPayload = (responsePayload) => {
|
|
1907
|
+
if (this.cancelled || this.resolved || this.settled) return;
|
|
1908
|
+
if (responsePayload?.status === "error") {
|
|
1909
|
+
this.cleanup();
|
|
1910
|
+
reject(
|
|
1911
|
+
new NativeVerifyError(
|
|
1912
|
+
responsePayload.error_code ?? "generic_error" /* GenericError */
|
|
1913
|
+
)
|
|
1914
|
+
);
|
|
1915
|
+
return;
|
|
1916
|
+
}
|
|
1917
|
+
this.resolved = true;
|
|
1918
|
+
const result = nativeResultToIDKitResult(
|
|
1919
|
+
responsePayload,
|
|
1920
|
+
config,
|
|
1921
|
+
signalHashes
|
|
1922
|
+
);
|
|
1923
|
+
this.resolvedResult = result;
|
|
1924
|
+
this.cleanup();
|
|
1925
|
+
resolve(result);
|
|
1926
|
+
};
|
|
1906
1927
|
const handler = (event) => {
|
|
1907
|
-
if (this.cancelled) return;
|
|
1908
1928
|
const data = event.data;
|
|
1909
|
-
if (data?.type ===
|
|
1910
|
-
|
|
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
|
-
}
|
|
1929
|
+
if (data?.type === MINIAPP_VERIFY_ACTION || data?.command === MINIAPP_VERIFY_ACTION) {
|
|
1930
|
+
handleIncomingPayload(data.payload ?? data);
|
|
1924
1931
|
}
|
|
1925
1932
|
};
|
|
1926
1933
|
this.messageHandler = handler;
|
|
1927
1934
|
window.addEventListener("message", handler);
|
|
1935
|
+
try {
|
|
1936
|
+
const miniKit = window.MiniKit;
|
|
1937
|
+
if (typeof miniKit?.subscribe === "function") {
|
|
1938
|
+
const miniKitHandler = (payload) => {
|
|
1939
|
+
handleIncomingPayload(payload?.payload ?? payload);
|
|
1940
|
+
};
|
|
1941
|
+
this.miniKitHandler = miniKitHandler;
|
|
1942
|
+
miniKit.subscribe(MINIAPP_VERIFY_ACTION, miniKitHandler);
|
|
1943
|
+
}
|
|
1944
|
+
} catch {
|
|
1945
|
+
}
|
|
1928
1946
|
const sendPayload = {
|
|
1929
1947
|
command: "verify",
|
|
1930
1948
|
version: 2,
|
|
@@ -1967,6 +1985,14 @@ var NativeIDKitRequest = class {
|
|
|
1967
1985
|
window.removeEventListener("message", this.messageHandler);
|
|
1968
1986
|
this.messageHandler = null;
|
|
1969
1987
|
}
|
|
1988
|
+
if (this.miniKitHandler) {
|
|
1989
|
+
try {
|
|
1990
|
+
const miniKit = window.MiniKit;
|
|
1991
|
+
miniKit?.unsubscribe?.(MINIAPP_VERIFY_ACTION);
|
|
1992
|
+
} catch {
|
|
1993
|
+
}
|
|
1994
|
+
this.miniKitHandler = null;
|
|
1995
|
+
}
|
|
1970
1996
|
}
|
|
1971
1997
|
isPending() {
|
|
1972
1998
|
return !this.settled && !this.cancelled;
|
|
@@ -2030,26 +2056,32 @@ var NativeVerifyError = class extends Error {
|
|
|
2030
2056
|
this.code = code;
|
|
2031
2057
|
}
|
|
2032
2058
|
};
|
|
2033
|
-
function nativeResultToIDKitResult(payload, config) {
|
|
2059
|
+
function nativeResultToIDKitResult(payload, config, signalHashes) {
|
|
2034
2060
|
const rpNonce = config.rp_context?.nonce ?? "";
|
|
2035
|
-
if ("responses" in payload
|
|
2061
|
+
if ("responses" in payload) {
|
|
2062
|
+
const v4 = payload;
|
|
2036
2063
|
return {
|
|
2037
|
-
protocol_version:
|
|
2038
|
-
nonce:
|
|
2039
|
-
action:
|
|
2040
|
-
action_description:
|
|
2041
|
-
session_id:
|
|
2042
|
-
responses:
|
|
2043
|
-
|
|
2064
|
+
protocol_version: v4.protocol_version ?? "4.0",
|
|
2065
|
+
nonce: v4.nonce ?? rpNonce,
|
|
2066
|
+
action: v4.action ?? config.action ?? "",
|
|
2067
|
+
action_description: v4.action_description,
|
|
2068
|
+
session_id: v4.session_id,
|
|
2069
|
+
responses: v4.responses.map((item) => ({
|
|
2070
|
+
...item,
|
|
2071
|
+
signal_hash: signalHashes[item.identifier]
|
|
2072
|
+
})),
|
|
2073
|
+
environment: v4.environment ?? config.environment ?? "production"
|
|
2044
2074
|
};
|
|
2045
2075
|
}
|
|
2046
2076
|
if ("verifications" in payload) {
|
|
2077
|
+
const multi = payload;
|
|
2047
2078
|
return {
|
|
2048
2079
|
protocol_version: "4.0",
|
|
2049
2080
|
nonce: rpNonce,
|
|
2050
2081
|
action: config.action ?? "",
|
|
2051
|
-
responses:
|
|
2082
|
+
responses: multi.verifications.map((v) => ({
|
|
2052
2083
|
identifier: v.verification_level,
|
|
2084
|
+
signal_hash: v.signal_hash ?? signalHashes[v.verification_level],
|
|
2053
2085
|
proof: [v.proof],
|
|
2054
2086
|
nullifier: v.nullifier_hash,
|
|
2055
2087
|
merkle_root: v.merkle_root,
|
|
@@ -2059,16 +2091,18 @@ function nativeResultToIDKitResult(payload, config) {
|
|
|
2059
2091
|
environment: "production"
|
|
2060
2092
|
};
|
|
2061
2093
|
}
|
|
2094
|
+
const single = payload;
|
|
2062
2095
|
return {
|
|
2063
2096
|
protocol_version: "3.0",
|
|
2064
2097
|
nonce: rpNonce,
|
|
2065
2098
|
action: config.action ?? "",
|
|
2066
2099
|
responses: [
|
|
2067
2100
|
{
|
|
2068
|
-
identifier:
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2101
|
+
identifier: single.verification_level,
|
|
2102
|
+
signal_hash: single.signal_hash ?? signalHashes[single.verification_level],
|
|
2103
|
+
proof: single.proof,
|
|
2104
|
+
merkle_root: single.merkle_root,
|
|
2105
|
+
nullifier: single.nullifier_hash
|
|
2072
2106
|
}
|
|
2073
2107
|
],
|
|
2074
2108
|
environment: "production"
|
|
@@ -2116,20 +2150,6 @@ var IDKitRequestImpl = class {
|
|
|
2116
2150
|
}
|
|
2117
2151
|
}
|
|
2118
2152
|
};
|
|
2119
|
-
function CredentialRequest(credential_type, options) {
|
|
2120
|
-
return {
|
|
2121
|
-
type: credential_type,
|
|
2122
|
-
signal: options?.signal,
|
|
2123
|
-
genesis_issued_at_min: options?.genesis_issued_at_min,
|
|
2124
|
-
expires_at_min: options?.expires_at_min
|
|
2125
|
-
};
|
|
2126
|
-
}
|
|
2127
|
-
function any(...nodes) {
|
|
2128
|
-
return { any: nodes };
|
|
2129
|
-
}
|
|
2130
|
-
function all(...nodes) {
|
|
2131
|
-
return { all: nodes };
|
|
2132
|
-
}
|
|
2133
2153
|
function orbLegacy(opts = {}) {
|
|
2134
2154
|
return { type: "OrbLegacy", signal: opts.signal };
|
|
2135
2155
|
}
|
|
@@ -2189,7 +2209,7 @@ var IDKitBuilder2 = class {
|
|
|
2189
2209
|
/**
|
|
2190
2210
|
* Creates an IDKit request with the given constraints
|
|
2191
2211
|
*
|
|
2192
|
-
* @param constraints - Constraint tree (CredentialRequest or any/all combinators)
|
|
2212
|
+
* @param constraints - Constraint tree (CredentialRequest or any/all/enumerate combinators)
|
|
2193
2213
|
* @returns A new IDKitRequest instance
|
|
2194
2214
|
*
|
|
2195
2215
|
* @example
|
|
@@ -2202,8 +2222,12 @@ var IDKitBuilder2 = class {
|
|
|
2202
2222
|
await initIDKit();
|
|
2203
2223
|
const wasmBuilder = createWasmBuilderFromConfig(this.config);
|
|
2204
2224
|
if (isInWorldApp()) {
|
|
2205
|
-
const
|
|
2206
|
-
return createNativeRequest(
|
|
2225
|
+
const wasmResult = wasmBuilder.nativePayload(constraints);
|
|
2226
|
+
return createNativeRequest(
|
|
2227
|
+
wasmResult.payload,
|
|
2228
|
+
this.config,
|
|
2229
|
+
wasmResult.signal_hashes ?? {}
|
|
2230
|
+
);
|
|
2207
2231
|
}
|
|
2208
2232
|
const wasmRequest = await wasmBuilder.constraints(
|
|
2209
2233
|
constraints
|
|
@@ -2229,8 +2253,12 @@ var IDKitBuilder2 = class {
|
|
|
2229
2253
|
await initIDKit();
|
|
2230
2254
|
const wasmBuilder = createWasmBuilderFromConfig(this.config);
|
|
2231
2255
|
if (isInWorldApp()) {
|
|
2232
|
-
const
|
|
2233
|
-
return createNativeRequest(
|
|
2256
|
+
const wasmResult = wasmBuilder.nativePayloadFromPreset(preset);
|
|
2257
|
+
return createNativeRequest(
|
|
2258
|
+
wasmResult.payload,
|
|
2259
|
+
this.config,
|
|
2260
|
+
wasmResult.signal_hashes ?? {}
|
|
2261
|
+
);
|
|
2234
2262
|
}
|
|
2235
2263
|
const wasmRequest = await wasmBuilder.preset(
|
|
2236
2264
|
preset
|
|
@@ -2267,61 +2295,22 @@ function createRequest(config) {
|
|
|
2267
2295
|
environment: config.environment
|
|
2268
2296
|
});
|
|
2269
2297
|
}
|
|
2270
|
-
function createSession2(config) {
|
|
2271
|
-
if (!config.app_id) {
|
|
2272
|
-
throw new Error("app_id is required");
|
|
2273
|
-
}
|
|
2274
|
-
if (!config.rp_context) {
|
|
2275
|
-
throw new Error(
|
|
2276
|
-
"rp_context is required. Generate it on your backend using signRequest()."
|
|
2277
|
-
);
|
|
2278
|
-
}
|
|
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
|
-
});
|
|
2288
|
-
}
|
|
2289
|
-
function proveSession2(sessionId, config) {
|
|
2290
|
-
if (!sessionId) {
|
|
2291
|
-
throw new Error("session_id is required");
|
|
2292
|
-
}
|
|
2293
|
-
if (!config.app_id) {
|
|
2294
|
-
throw new Error("app_id is required");
|
|
2295
|
-
}
|
|
2296
|
-
if (!config.rp_context) {
|
|
2297
|
-
throw new Error(
|
|
2298
|
-
"rp_context is required. Generate it on your backend using signRequest()."
|
|
2299
|
-
);
|
|
2300
|
-
}
|
|
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
|
-
});
|
|
2311
|
-
}
|
|
2312
2298
|
var IDKit = {
|
|
2313
2299
|
/** Create a new verification request */
|
|
2314
2300
|
request: createRequest,
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
CredentialRequest
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
all
|
|
2301
|
+
// TODO: Re-enable when World ID 4.0 is live
|
|
2302
|
+
// /** Create a new session (no action, no existing session_id) */
|
|
2303
|
+
// createSession,
|
|
2304
|
+
// /** Prove an existing session (no action, has session_id) */
|
|
2305
|
+
// proveSession,
|
|
2306
|
+
// /** Create a CredentialRequest for a credential type */
|
|
2307
|
+
// CredentialRequest,
|
|
2308
|
+
// /** Create an OR constraint - at least one child must be satisfied */
|
|
2309
|
+
// any,
|
|
2310
|
+
// /** Create an AND constraint - all children must be satisfied */
|
|
2311
|
+
// all,
|
|
2312
|
+
// /** Create an enumerate constraint - all satisfiable children should be selected */
|
|
2313
|
+
// enumerate,
|
|
2325
2314
|
/** Create an OrbLegacy preset for World ID 3.0 legacy support */
|
|
2326
2315
|
orbLegacy,
|
|
2327
2316
|
/** Create a SecureDocumentLegacy preset for World ID 3.0 legacy support */
|
|
@@ -2340,18 +2329,6 @@ var isWeb = () => {
|
|
|
2340
2329
|
var isNode = () => {
|
|
2341
2330
|
return typeof process !== "undefined" && typeof process.versions !== "undefined" && typeof process.versions.node !== "undefined";
|
|
2342
2331
|
};
|
|
2343
|
-
var isServerEnvironment = () => {
|
|
2344
|
-
if (typeof process !== "undefined" && process.versions?.node) {
|
|
2345
|
-
return true;
|
|
2346
|
-
}
|
|
2347
|
-
if (typeof globalThis.Deno !== "undefined") {
|
|
2348
|
-
return true;
|
|
2349
|
-
}
|
|
2350
|
-
if (typeof globalThis.Bun !== "undefined") {
|
|
2351
|
-
return true;
|
|
2352
|
-
}
|
|
2353
|
-
return false;
|
|
2354
|
-
};
|
|
2355
2332
|
function hashToField(input) {
|
|
2356
2333
|
const hash = BigInt("0x" + bytesToHex(keccak_256(input))) >> 8n;
|
|
2357
2334
|
return hexToBytes(hash.toString(16).padStart(64, "0"));
|
|
@@ -2373,50 +2350,4 @@ function isValidHex(s) {
|
|
|
2373
2350
|
return /^[0-9a-fA-F]+$/.test(s);
|
|
2374
2351
|
}
|
|
2375
2352
|
|
|
2376
|
-
|
|
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) {
|
|
2388
|
-
if (!isServerEnvironment()) {
|
|
2389
|
-
throw new Error(
|
|
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."
|
|
2391
|
-
);
|
|
2392
|
-
}
|
|
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
|
-
};
|
|
2420
|
-
}
|
|
2421
|
-
|
|
2422
|
-
export { CredentialRequest, IDKit, IDKitErrorCodes, all, any, documentLegacy, hashSignal2 as hashSignal, isNode, isReactNative, isWeb, orbLegacy, secureDocumentLegacy, signRequest2 as signRequest };
|
|
2353
|
+
export { IDKit, IDKitErrorCodes, documentLegacy, hashSignal2 as hashSignal, isNode, isReactNative, isWeb, orbLegacy, secureDocumentLegacy };
|