@worldcoin/idkit-core 4.0.2-dev.a907be3 → 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/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { RpSignature, signRequest } from './signing.js';
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(any(CredentialRequest('orb'), CredentialRequest('face')));
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, CredentialRequest, 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, all, any, documentLegacy, isNode, isReactNative, isWeb, orbLegacy, secureDocumentLegacy };
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, all2) => {
9
- for (var name in all2)
10
- __defProp(target, name, { get: all2[name], enumerable: true });
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 __wasm_bindgen_func_elem_960(arg0, arg1, arg2) {
395
- wasm.__wasm_bindgen_func_elem_960(arg0, arg1, addHeapObject(arg2));
392
+ function __wasm_bindgen_func_elem_599(arg0, arg1) {
393
+ wasm.__wasm_bindgen_func_elem_599(arg0, arg1);
396
394
  }
397
- function __wasm_bindgen_func_elem_597(arg0, arg1) {
398
- wasm.__wasm_bindgen_func_elem_597(arg0, arg1);
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 __wasm_bindgen_func_elem_1345(arg0, arg1, arg2, arg3) {
401
- wasm.__wasm_bindgen_func_elem_1345(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
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 __wasm_bindgen_func_elem_1345(a, state0.b, arg02, arg12);
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.__wbindgen_cast_4625c577ab2ec9ee = function(arg0) {
1778
- const ret = BigInt.asUintN(64, arg0);
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.__wbindgen_cast_91c43ecf1f8dafb8 = function(arg0, arg1) {
1782
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_596, __wasm_bindgen_func_elem_597);
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.__wbindgen_cast_ab10518eebecf9a3 = function(arg0, arg1) {
1790
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_959, __wasm_bindgen_func_elem_960);
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) {
@@ -1881,19 +1879,19 @@ function isInWorldApp() {
1881
1879
  }
1882
1880
  var _requestCounter = 0;
1883
1881
  var _activeNativeRequest = null;
1884
- function createNativeRequest(wasmPayload, config) {
1882
+ function createNativeRequest(wasmPayload, config, signalHashes = {}) {
1885
1883
  if (_activeNativeRequest?.isPending()) {
1886
1884
  console.warn(
1887
1885
  "IDKit native request already in flight. Reusing active request."
1888
1886
  );
1889
1887
  return _activeNativeRequest;
1890
1888
  }
1891
- const request2 = new NativeIDKitRequest(wasmPayload, config);
1889
+ const request2 = new NativeIDKitRequest(wasmPayload, config, signalHashes);
1892
1890
  _activeNativeRequest = request2;
1893
1891
  return request2;
1894
1892
  }
1895
1893
  var NativeIDKitRequest = class {
1896
- constructor(wasmPayload, config) {
1894
+ constructor(wasmPayload, config, signalHashes = {}) {
1897
1895
  this.connectorURI = "";
1898
1896
  this.resolved = false;
1899
1897
  this.cancelled = false;
@@ -1917,7 +1915,11 @@ var NativeIDKitRequest = class {
1917
1915
  return;
1918
1916
  }
1919
1917
  this.resolved = true;
1920
- const result = nativeResultToIDKitResult(responsePayload, config);
1918
+ const result = nativeResultToIDKitResult(
1919
+ responsePayload,
1920
+ config,
1921
+ signalHashes
1922
+ );
1921
1923
  this.resolvedResult = result;
1922
1924
  this.cleanup();
1923
1925
  resolve(result);
@@ -2054,26 +2056,32 @@ var NativeVerifyError = class extends Error {
2054
2056
  this.code = code;
2055
2057
  }
2056
2058
  };
2057
- function nativeResultToIDKitResult(payload, config) {
2059
+ function nativeResultToIDKitResult(payload, config, signalHashes) {
2058
2060
  const rpNonce = config.rp_context?.nonce ?? "";
2059
- if ("responses" in payload && Array.isArray(payload.responses)) {
2061
+ if ("responses" in payload) {
2062
+ const v4 = payload;
2060
2063
  return {
2061
- protocol_version: payload.protocol_version ?? "4.0",
2062
- nonce: payload.nonce ?? rpNonce,
2063
- action: payload.action ?? config.action ?? "",
2064
- action_description: payload.action_description,
2065
- session_id: payload.session_id,
2066
- responses: payload.responses,
2067
- environment: payload.environment ?? config.environment ?? "production"
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"
2068
2074
  };
2069
2075
  }
2070
2076
  if ("verifications" in payload) {
2077
+ const multi = payload;
2071
2078
  return {
2072
2079
  protocol_version: "4.0",
2073
2080
  nonce: rpNonce,
2074
2081
  action: config.action ?? "",
2075
- responses: payload.verifications.map((v) => ({
2082
+ responses: multi.verifications.map((v) => ({
2076
2083
  identifier: v.verification_level,
2084
+ signal_hash: v.signal_hash ?? signalHashes[v.verification_level],
2077
2085
  proof: [v.proof],
2078
2086
  nullifier: v.nullifier_hash,
2079
2087
  merkle_root: v.merkle_root,
@@ -2083,16 +2091,18 @@ function nativeResultToIDKitResult(payload, config) {
2083
2091
  environment: "production"
2084
2092
  };
2085
2093
  }
2094
+ const single = payload;
2086
2095
  return {
2087
2096
  protocol_version: "3.0",
2088
2097
  nonce: rpNonce,
2089
2098
  action: config.action ?? "",
2090
2099
  responses: [
2091
2100
  {
2092
- identifier: payload.verification_level,
2093
- proof: payload.proof,
2094
- merkle_root: payload.merkle_root,
2095
- nullifier: payload.nullifier_hash
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
2096
2106
  }
2097
2107
  ],
2098
2108
  environment: "production"
@@ -2140,20 +2150,6 @@ var IDKitRequestImpl = class {
2140
2150
  }
2141
2151
  }
2142
2152
  };
2143
- function CredentialRequest(credential_type, options) {
2144
- return {
2145
- type: credential_type,
2146
- signal: options?.signal,
2147
- genesis_issued_at_min: options?.genesis_issued_at_min,
2148
- expires_at_min: options?.expires_at_min
2149
- };
2150
- }
2151
- function any(...nodes) {
2152
- return { any: nodes };
2153
- }
2154
- function all(...nodes) {
2155
- return { all: nodes };
2156
- }
2157
2153
  function orbLegacy(opts = {}) {
2158
2154
  return { type: "OrbLegacy", signal: opts.signal };
2159
2155
  }
@@ -2213,7 +2209,7 @@ var IDKitBuilder2 = class {
2213
2209
  /**
2214
2210
  * Creates an IDKit request with the given constraints
2215
2211
  *
2216
- * @param constraints - Constraint tree (CredentialRequest or any/all combinators)
2212
+ * @param constraints - Constraint tree (CredentialRequest or any/all/enumerate combinators)
2217
2213
  * @returns A new IDKitRequest instance
2218
2214
  *
2219
2215
  * @example
@@ -2226,8 +2222,12 @@ var IDKitBuilder2 = class {
2226
2222
  await initIDKit();
2227
2223
  const wasmBuilder = createWasmBuilderFromConfig(this.config);
2228
2224
  if (isInWorldApp()) {
2229
- const payload = wasmBuilder.nativePayload(constraints);
2230
- return createNativeRequest(payload, this.config);
2225
+ const wasmResult = wasmBuilder.nativePayload(constraints);
2226
+ return createNativeRequest(
2227
+ wasmResult.payload,
2228
+ this.config,
2229
+ wasmResult.signal_hashes ?? {}
2230
+ );
2231
2231
  }
2232
2232
  const wasmRequest = await wasmBuilder.constraints(
2233
2233
  constraints
@@ -2253,8 +2253,12 @@ var IDKitBuilder2 = class {
2253
2253
  await initIDKit();
2254
2254
  const wasmBuilder = createWasmBuilderFromConfig(this.config);
2255
2255
  if (isInWorldApp()) {
2256
- const payload = wasmBuilder.nativePayloadFromPreset(preset);
2257
- return createNativeRequest(payload, this.config);
2256
+ const wasmResult = wasmBuilder.nativePayloadFromPreset(preset);
2257
+ return createNativeRequest(
2258
+ wasmResult.payload,
2259
+ this.config,
2260
+ wasmResult.signal_hashes ?? {}
2261
+ );
2258
2262
  }
2259
2263
  const wasmRequest = await wasmBuilder.preset(
2260
2264
  preset
@@ -2291,61 +2295,22 @@ function createRequest(config) {
2291
2295
  environment: config.environment
2292
2296
  });
2293
2297
  }
2294
- function createSession2(config) {
2295
- if (!config.app_id) {
2296
- throw new Error("app_id is required");
2297
- }
2298
- if (!config.rp_context) {
2299
- throw new Error(
2300
- "rp_context is required. Generate it on your backend using signRequest()."
2301
- );
2302
- }
2303
- return new IDKitBuilder2({
2304
- type: "session",
2305
- app_id: config.app_id,
2306
- rp_context: config.rp_context,
2307
- action_description: config.action_description,
2308
- bridge_url: config.bridge_url,
2309
- override_connect_base_url: config.override_connect_base_url,
2310
- environment: config.environment
2311
- });
2312
- }
2313
- function proveSession2(sessionId, config) {
2314
- if (!sessionId) {
2315
- throw new Error("session_id is required");
2316
- }
2317
- if (!config.app_id) {
2318
- throw new Error("app_id is required");
2319
- }
2320
- if (!config.rp_context) {
2321
- throw new Error(
2322
- "rp_context is required. Generate it on your backend using signRequest()."
2323
- );
2324
- }
2325
- return new IDKitBuilder2({
2326
- type: "proveSession",
2327
- session_id: sessionId,
2328
- app_id: config.app_id,
2329
- rp_context: config.rp_context,
2330
- action_description: config.action_description,
2331
- bridge_url: config.bridge_url,
2332
- override_connect_base_url: config.override_connect_base_url,
2333
- environment: config.environment
2334
- });
2335
- }
2336
2298
  var IDKit = {
2337
2299
  /** Create a new verification request */
2338
2300
  request: createRequest,
2339
- /** Create a new session (no action, no existing session_id) */
2340
- createSession: createSession2,
2341
- /** Prove an existing session (no action, has session_id) */
2342
- proveSession: proveSession2,
2343
- /** Create a CredentialRequest for a credential type */
2344
- CredentialRequest,
2345
- /** Create an OR constraint - at least one child must be satisfied */
2346
- any,
2347
- /** Create an AND constraint - all children must be satisfied */
2348
- 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,
2349
2314
  /** Create an OrbLegacy preset for World ID 3.0 legacy support */
2350
2315
  orbLegacy,
2351
2316
  /** Create a SecureDocumentLegacy preset for World ID 3.0 legacy support */
@@ -2364,18 +2329,6 @@ var isWeb = () => {
2364
2329
  var isNode = () => {
2365
2330
  return typeof process !== "undefined" && typeof process.versions !== "undefined" && typeof process.versions.node !== "undefined";
2366
2331
  };
2367
- var isServerEnvironment = () => {
2368
- if (typeof process !== "undefined" && process.versions?.node) {
2369
- return true;
2370
- }
2371
- if (typeof globalThis.Deno !== "undefined") {
2372
- return true;
2373
- }
2374
- if (typeof globalThis.Bun !== "undefined") {
2375
- return true;
2376
- }
2377
- return false;
2378
- };
2379
2332
  function hashToField(input) {
2380
2333
  const hash = BigInt("0x" + bytesToHex(keccak_256(input))) >> 8n;
2381
2334
  return hexToBytes(hash.toString(16).padStart(64, "0"));
@@ -2397,50 +2350,4 @@ function isValidHex(s) {
2397
2350
  return /^[0-9a-fA-F]+$/.test(s);
2398
2351
  }
2399
2352
 
2400
- // src/lib/signing.ts
2401
- etc.hmacSha256Sync = (key, ...msgs) => hmac(sha256, key, etc.concatBytes(...msgs));
2402
- var DEFAULT_TTL_SEC = 300;
2403
- function computeRpSignatureMessage(nonceBytes, createdAt, expiresAt) {
2404
- const message = new Uint8Array(48);
2405
- message.set(nonceBytes, 0);
2406
- const view = new DataView(message.buffer);
2407
- view.setBigUint64(32, BigInt(createdAt), false);
2408
- view.setBigUint64(40, BigInt(expiresAt), false);
2409
- return message;
2410
- }
2411
- function signRequest2(_action, signingKeyHex, ttl = DEFAULT_TTL_SEC) {
2412
- if (!isServerEnvironment()) {
2413
- throw new Error(
2414
- "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."
2415
- );
2416
- }
2417
- const keyHex = signingKeyHex.startsWith("0x") ? signingKeyHex.slice(2) : signingKeyHex;
2418
- if (!/^[0-9a-fA-F]+$/.test(keyHex)) {
2419
- throw new Error("Invalid signing key: contains non-hex characters");
2420
- }
2421
- if (keyHex.length !== 64) {
2422
- throw new Error(
2423
- `Invalid signing key: expected 32 bytes (64 hex chars), got ${keyHex.length / 2} bytes`
2424
- );
2425
- }
2426
- const privKey = etc.hexToBytes(keyHex);
2427
- const randomBytes = crypto.getRandomValues(new Uint8Array(32));
2428
- const nonceBytes = hashToField(randomBytes);
2429
- const createdAt = Math.floor(Date.now() / 1e3);
2430
- const expiresAt = createdAt + ttl;
2431
- const message = computeRpSignatureMessage(nonceBytes, createdAt, expiresAt);
2432
- const msgHash = keccak_256(message);
2433
- const recSig = sign(msgHash, privKey);
2434
- const compact = recSig.toCompactRawBytes();
2435
- const sig65 = new Uint8Array(65);
2436
- sig65.set(compact, 0);
2437
- sig65[64] = recSig.recovery + 27;
2438
- return {
2439
- sig: "0x" + bytesToHex(sig65),
2440
- nonce: "0x" + bytesToHex(nonceBytes),
2441
- createdAt,
2442
- expiresAt
2443
- };
2444
- }
2445
-
2446
- 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 };
package/dist/signing.cjs CHANGED
@@ -1,76 +1,14 @@
1
1
  'use strict';
2
2
 
3
- var sha3 = require('@noble/hashes/sha3');
4
- 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');
3
+ var idkitServer = require('@worldcoin/idkit-server');
8
4
 
9
- // src/lib/signing.ts
10
5
 
11
- // src/lib/platform.ts
12
- var isServerEnvironment = () => {
13
- if (typeof process !== "undefined" && process.versions?.node) {
14
- return true;
15
- }
16
- if (typeof globalThis.Deno !== "undefined") {
17
- return true;
18
- }
19
- if (typeof globalThis.Bun !== "undefined") {
20
- return true;
21
- }
22
- return false;
23
- };
24
- function hashToField(input) {
25
- const hash = BigInt("0x" + utils.bytesToHex(sha3.keccak_256(input))) >> 8n;
26
- return utils.hexToBytes(hash.toString(16).padStart(64, "0"));
27
- }
28
6
 
29
- // src/lib/signing.ts
30
- secp256k1.etc.hmacSha256Sync = (key, ...msgs) => hmac.hmac(sha2.sha256, key, secp256k1.etc.concatBytes(...msgs));
31
- var DEFAULT_TTL_SEC = 300;
32
- function computeRpSignatureMessage(nonceBytes, createdAt, expiresAt) {
33
- const message = new Uint8Array(48);
34
- message.set(nonceBytes, 0);
35
- const view = new DataView(message.buffer);
36
- view.setBigUint64(32, BigInt(createdAt), false);
37
- view.setBigUint64(40, BigInt(expiresAt), false);
38
- return message;
39
- }
40
- function signRequest(_action, signingKeyHex, ttl = DEFAULT_TTL_SEC) {
41
- if (!isServerEnvironment()) {
42
- throw new Error(
43
- "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."
44
- );
45
- }
46
- const keyHex = signingKeyHex.startsWith("0x") ? signingKeyHex.slice(2) : signingKeyHex;
47
- if (!/^[0-9a-fA-F]+$/.test(keyHex)) {
48
- throw new Error("Invalid signing key: contains non-hex characters");
49
- }
50
- if (keyHex.length !== 64) {
51
- throw new Error(
52
- `Invalid signing key: expected 32 bytes (64 hex chars), got ${keyHex.length / 2} bytes`
53
- );
54
- }
55
- const privKey = secp256k1.etc.hexToBytes(keyHex);
56
- const randomBytes = crypto.getRandomValues(new Uint8Array(32));
57
- const nonceBytes = hashToField(randomBytes);
58
- const createdAt = Math.floor(Date.now() / 1e3);
59
- const expiresAt = createdAt + ttl;
60
- const message = computeRpSignatureMessage(nonceBytes, createdAt, expiresAt);
61
- const msgHash = sha3.keccak_256(message);
62
- const recSig = secp256k1.sign(msgHash, privKey);
63
- const compact = recSig.toCompactRawBytes();
64
- const sig65 = new Uint8Array(65);
65
- sig65.set(compact, 0);
66
- sig65[64] = recSig.recovery + 27;
67
- return {
68
- sig: "0x" + utils.bytesToHex(sig65),
69
- nonce: "0x" + utils.bytesToHex(nonceBytes),
70
- createdAt,
71
- expiresAt
72
- };
73
- }
74
-
75
- exports.computeRpSignatureMessage = computeRpSignatureMessage;
76
- exports.signRequest = signRequest;
7
+ Object.defineProperty(exports, "computeRpSignatureMessage", {
8
+ enumerable: true,
9
+ get: function () { return idkitServer.computeRpSignatureMessage; }
10
+ });
11
+ Object.defineProperty(exports, "signRequest", {
12
+ enumerable: true,
13
+ get: function () { return idkitServer.signRequest; }
14
+ });