@worldcoin/idkit-core 4.0.1 → 4.0.2-dev.6541a3e

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.cts CHANGED
@@ -1,3 +1,6 @@
1
+ export { RpSignature, signRequest } from './signing.cjs';
2
+ export { hashSignal } from './hashing.cjs';
3
+
1
4
  /**
2
5
  * Configuration types for IDKit
3
6
  *
@@ -80,20 +83,22 @@ type IDKitSessionConfig = {
80
83
  environment?: "production" | "staging";
81
84
  };
82
85
 
83
- type CredentialType = "orb" | "face" | "secure_document" | "document" | "device";
86
+ interface OrbLegacyPreset {
87
+ type: "OrbLegacy";
88
+ signal?: string;
89
+ }
84
90
 
85
- interface CredentialRequestType {
86
- type: CredentialType;
87
- /** Signal can be a string or raw bytes (Uint8Array) */
88
- signal?: string | Uint8Array;
89
- genesis_issued_at_min?: number;
90
- expires_at_min?: number;
91
+ interface SecureDocumentLegacyPreset {
92
+ type: "SecureDocumentLegacy";
93
+ signal?: string;
91
94
  }
92
95
 
93
- type ConstraintNode =
94
- | CredentialRequestType
95
- | { any: ConstraintNode[] }
96
- | { all: ConstraintNode[] };
96
+ interface DocumentLegacyPreset {
97
+ type: "DocumentLegacy";
98
+ signal?: string;
99
+ }
100
+
101
+ type Preset = OrbLegacyPreset | SecureDocumentLegacyPreset | DocumentLegacyPreset;
97
102
 
98
103
 
99
104
 
@@ -223,131 +228,21 @@ type Status$1 =
223
228
 
224
229
 
225
230
 
226
- interface OrbLegacyPreset {
227
- type: "OrbLegacy";
228
- signal?: string;
229
- }
230
-
231
- interface SecureDocumentLegacyPreset {
232
- type: "SecureDocumentLegacy";
233
- signal?: string;
234
- }
235
-
236
- interface DocumentLegacyPreset {
237
- type: "DocumentLegacy";
238
- signal?: string;
239
- }
240
-
241
- type Preset = OrbLegacyPreset | SecureDocumentLegacyPreset | DocumentLegacyPreset;
242
- /**
243
- * Unified builder for creating `IDKit` requests and sessions (WASM)
244
- */
245
- declare class IDKitBuilder$1 {
246
- free(): void;
247
- [Symbol.dispose](): void;
248
- /**
249
- * Creates a `BridgeConnection` with the given constraints
250
- */
251
- constraints(constraints_json: any): Promise<any>;
252
- /**
253
- * Creates a new builder for proving an existing session
254
- */
255
- static forProveSession(session_id: string, app_id: string, rp_context: RpContextWasm, action_description?: string | null, bridge_url?: string | null, override_connect_base_url?: string | null, environment?: string | null): IDKitBuilder$1;
256
- /**
257
- * Creates a new builder for creating a new session
258
- */
259
- static forCreateSession(app_id: string, rp_context: RpContextWasm, action_description?: string | null, bridge_url?: string | null, override_connect_base_url?: string | null, environment?: string | null): IDKitBuilder$1;
260
- /**
261
- * Creates a new builder for uniqueness requests
262
- */
263
- constructor(app_id: string, action: string, rp_context: RpContextWasm, action_description: string | null | undefined, bridge_url: string | null | undefined, allow_legacy_proofs: boolean, override_connect_base_url?: string | null, environment?: string | null);
264
- /**
265
- * Creates a `BridgeConnection` from a preset (works for all request types)
266
- */
267
- preset(preset_json: any): Promise<any>;
268
- }
269
- /**
270
- * RP Context for protocol-level proof requests (WASM binding)
271
- *
272
- * Contains RP-specific data needed to construct a `ProofRequest`.
273
- */
274
- declare class RpContextWasm {
275
- free(): void;
276
- [Symbol.dispose](): void;
277
- /**
278
- * Creates a new RP context
279
- *
280
- * # Arguments
281
- * * `rp_id` - The registered RP ID (e.g., `"rp_123456789abcdef0"`)
282
- * * `nonce` - Unique nonce for this proof request
283
- * * `created_at` - Unix timestamp (seconds since epoch) when created
284
- * * `expires_at` - Unix timestamp (seconds since epoch) when expires
285
- * * `signature` - The RP's ECDSA signature of the `nonce` and `created_at` timestamp
286
- *
287
- * # Errors
288
- *
289
- * Returns an error if `rp_id` is not a valid RP ID (must start with `rp_`)
290
- */
291
- constructor(rp_id: string, nonce: string, created_at: bigint, expires_at: bigint, signature: string);
292
- }
293
-
294
-
231
+ type CredentialType = "orb" | "face" | "secure_document" | "document" | "device";
295
232
 
296
- interface RpSignature {
297
- sig: string;
298
- nonce: string;
299
- createdAt: number;
300
- expiresAt: number;
301
- toJSON(): { sig: string; nonce: string; createdAt: number; expiresAt: number };
302
- }
303
- declare class RpSignature {
304
- private constructor();
305
- free(): void;
306
- [Symbol.dispose](): void;
307
- /**
308
- * Converts to JSON
309
- *
310
- * # Errors
311
- *
312
- * Returns an error if setting object properties fails
313
- */
314
- toJSON(): any;
315
- /**
316
- * Gets the creation timestamp
317
- */
318
- readonly createdAt: bigint;
319
- /**
320
- * Gets the expiration timestamp
321
- */
322
- readonly expiresAt: bigint;
323
- /**
324
- * Gets the signature as hex string (0x-prefixed, 65 bytes)
325
- */
326
- readonly sig: string;
327
- /**
328
- * Gets the nonce as hex string (0x-prefixed field element)
329
- */
330
- readonly nonce: string;
233
+ interface CredentialRequestType {
234
+ type: CredentialType;
235
+ /** Signal can be a string or raw bytes (Uint8Array) */
236
+ signal?: string | Uint8Array;
237
+ genesis_issued_at_min?: number;
238
+ expires_at_min?: number;
331
239
  }
332
240
 
333
- /**
334
- * WASM initialization and management
335
- */
336
-
337
- /**
338
- * Initializes the WASM module for browser environments
339
- * Uses fetch-based loading (works with http/https URLs)
340
- * This must be called before using any WASM-powered functions
341
- * Safe to call multiple times - initialization only happens once
342
- */
343
- declare function initIDKit(): Promise<void>;
344
- /**
345
- * Initializes the WASM module for Node.js/server environments
346
- * Uses fs-based loading since Node.js fetch doesn't support file:// URLs
347
- * This must be called before using any WASM-powered functions
348
- * Safe to call multiple times - initialization only happens once
349
- */
350
- declare function initIDKitServer(): Promise<void>;
241
+ type ConstraintNode =
242
+ | CredentialRequestType
243
+ | { any: ConstraintNode[] }
244
+ | { all: ConstraintNode[] }
245
+ | { enumerate: ConstraintNode[] };
351
246
 
352
247
  /**
353
248
  * Result types - re-exported from WASM bindings
@@ -377,6 +272,19 @@ declare enum IDKitErrorCodes {
377
272
  Cancelled = "cancelled"
378
273
  }
379
274
 
275
+ interface BuilderConfig {
276
+ type: "request" | "session" | "proveSession";
277
+ app_id: string;
278
+ action?: string;
279
+ session_id?: string;
280
+ rp_context?: RpContext;
281
+ action_description?: string;
282
+ bridge_url?: string;
283
+ allow_legacy_proofs?: boolean;
284
+ override_connect_base_url?: string;
285
+ environment?: string;
286
+ }
287
+
380
288
  /**
381
289
  * IDKit Request
382
290
  * Pure functional API for World ID verification - no dependencies
@@ -422,55 +330,6 @@ interface IDKitRequest {
422
330
  /** Poll continuously until completion or timeout */
423
331
  pollUntilCompletion(options?: WaitOptions): Promise<IDKitCompletionResult>;
424
332
  }
425
- /**
426
- * Creates a CredentialRequest for a credential type
427
- *
428
- * @param credential_type - The type of credential to request (e.g., 'orb', 'face')
429
- * @param options - Optional signal, genesis_issued_at_min, and expires_at_min
430
- * @returns A CredentialRequest object
431
- *
432
- * @example
433
- * ```typescript
434
- * const orb = CredentialRequest('orb', { signal: 'user-123' })
435
- * const face = CredentialRequest('face')
436
- * // Require credential to be valid for at least one year
437
- * const withExpiry = CredentialRequest('orb', { expires_at_min: Date.now() / 1000 + 60 * 60 * 60 * 24 * 365 })
438
- * ```
439
- */
440
- declare function CredentialRequest(credential_type: CredentialType, options?: {
441
- signal?: string;
442
- genesis_issued_at_min?: number;
443
- expires_at_min?: number;
444
- }): CredentialRequestType;
445
- /**
446
- * Creates an OR constraint - at least one child must be satisfied
447
- *
448
- * @param nodes - Constraint nodes (CredentialRequests or nested constraints)
449
- * @returns An "any" constraint node
450
- *
451
- * @example
452
- * ```typescript
453
- * const constraint = any(CredentialRequest('orb'), CredentialRequest('face'))
454
- * ```
455
- */
456
- declare function any(...nodes: ConstraintNode[]): {
457
- any: ConstraintNode[];
458
- };
459
- /**
460
- * Creates an AND constraint - all children must be satisfied
461
- *
462
- * @param nodes - Constraint nodes (CredentialRequests or nested constraints)
463
- * @returns An "all" constraint node
464
- *
465
- * @example
466
- * ```typescript
467
- * const constraint = all(CredentialRequest('orb'), any(CredentialRequest('document'), CredentialRequest('secure_document')))
468
- * ```
469
- */
470
- declare function all(...nodes: ConstraintNode[]): {
471
- all: ConstraintNode[];
472
- };
473
-
474
333
  /**
475
334
  * Creates an OrbLegacy preset for World ID 3.0 legacy support
476
335
  *
@@ -482,7 +341,7 @@ declare function all(...nodes: ConstraintNode[]): {
482
341
  *
483
342
  * @example
484
343
  * ```typescript
485
- * const request = await IDKit.request({ app_id, action, rp_context })
344
+ * const request = await IDKit.request({ app_id, action, rp_context, allow_legacy_proofs: true })
486
345
  * .preset(orbLegacy({ signal: 'user-123' }))
487
346
  * ```
488
347
  */
@@ -500,7 +359,7 @@ declare function orbLegacy(opts?: {
500
359
  *
501
360
  * @example
502
361
  * ```typescript
503
- * const request = await IDKit.request({ app_id, action, rp_context })
362
+ * const request = await IDKit.request({ app_id, action, rp_context, allow_legacy_proofs: true })
504
363
  * .preset(secureDocumentLegacy({ signal: 'user-123' }))
505
364
  * ```
506
365
  */
@@ -518,7 +377,7 @@ declare function secureDocumentLegacy(opts?: {
518
377
  *
519
378
  * @example
520
379
  * ```typescript
521
- * const request = await IDKit.request({ app_id, action, rp_context })
380
+ * const request = await IDKit.request({ app_id, action, rp_context, allow_legacy_proofs: true })
522
381
  * .preset(documentLegacy({ signal: 'user-123' }))
523
382
  * ```
524
383
  */
@@ -526,175 +385,108 @@ declare function documentLegacy(opts?: {
526
385
  signal?: string;
527
386
  }): DocumentLegacyPreset;
528
387
  /**
529
- * Merged builder for IDKit requests
388
+ * Builder for IDKit requests
389
+ *
390
+ * Stores configuration and defers transport selection to `.preset()` / `.constraints()`.
391
+ * In World App: uses native postMessage transport (no WASM needed).
392
+ * On web: uses WASM bridge transport (QR code + polling).
530
393
  */
531
394
  declare class IDKitBuilder {
532
- private wasmBuilder;
533
- constructor(wasmBuilder: IDKitBuilder$1);
395
+ private config;
396
+ constructor(config: BuilderConfig);
534
397
  /**
535
398
  * Creates an IDKit request with the given constraints
536
399
  *
537
- * @param constraints - Constraint tree (CredentialRequest or any/all combinators)
400
+ * @param constraints - Constraint tree (CredentialRequest or any/all/enumerate combinators)
538
401
  * @returns A new IDKitRequest instance
539
402
  *
540
403
  * @example
541
404
  * ```typescript
542
- * const builder = await IDKit.request({ app_id, action, rp_context });
543
- * const request = await builder.constraints(any(CredentialRequest('orb'), CredentialRequest('face')));
405
+ * const request = await IDKit.request({ app_id, action, rp_context, allow_legacy_proofs: false })
406
+ * .constraints(any(CredentialRequest('orb'), CredentialRequest('face')));
544
407
  * ```
545
408
  */
409
+ constraints(constraints: ConstraintNode): Promise<IDKitRequest>;
546
410
  /**
547
411
  * Creates an IDKit request from a preset (works for all request types)
548
412
  *
549
413
  * Presets provide a simplified way to create requests with predefined
550
414
  * credential configurations.
551
415
  *
552
- * @param preset - A preset object from orbLegacy()
416
+ * @param preset - A preset object from orbLegacy(), secureDocumentLegacy(), or documentLegacy()
553
417
  * @returns A new IDKitRequest instance
554
418
  *
555
419
  * @example
556
420
  * ```typescript
557
- * const builder = await IDKit.request({ app_id, action, rp_context });
558
- * const request = await builder.preset(orbLegacy({ signal: 'user-123' }));
421
+ * const request = await IDKit.request({ app_id, action, rp_context, allow_legacy_proofs: true })
422
+ * .preset(orbLegacy({ signal: 'user-123' }));
559
423
  * ```
560
424
  */
561
425
  preset(preset: Preset): Promise<IDKitRequest>;
562
426
  }
563
427
  /**
564
- * Creates an IDKit request builder
428
+ * Creates an IDKit verification request builder
565
429
  *
566
430
  * This is the main entry point for creating World ID verification requests.
567
- * Use the builder pattern with constraints to specify which credentials to accept.
431
+ * Use the builder pattern with `.preset()` or `.constraints()` to specify
432
+ * which credentials to accept.
568
433
  *
569
434
  * @param config - Request configuration
570
435
  * @returns IDKitBuilder - A builder instance
571
436
  *
572
437
  * @example
573
438
  * ```typescript
574
- * import { IDKit, CredentialRequest, any } from '@worldcoin/idkit-core'
575
- *
576
- * // Initialize WASM (only needed once)
577
- * await IDKit.init()
439
+ * import { IDKit, CredentialRequest, any, enumerate, orbLegacy } from '@worldcoin/idkit-core'
578
440
  *
579
- * // Create request items
580
- * const orb = CredentialRequest('orb', { signal: 'user-123' })
581
- * const face = CredentialRequest('face')
582
- *
583
- * // Create a verification request with constraints
441
+ * // With preset (legacy support)
584
442
  * const request = await IDKit.request({
585
443
  * app_id: 'app_staging_xxxxx',
586
444
  * action: 'my-action',
587
- * rp_context: {
588
- * rp_id: 'rp_123456789abcdef0',
589
- * nonce: 'unique-nonce',
590
- * created_at: Math.floor(Date.now() / 1000),
591
- * expires_at: Math.floor(Date.now() / 1000) + 3600,
592
- * signature: 'ecdsa-signature-from-backend',
593
- * },
594
- * allow_legacy_proofs: false,
595
- * }).constraints(any(orb, face));
596
- *
597
- * // Display QR code
598
- * console.log('Scan this:', request.connectorURI)
599
- *
600
- * // Wait for proof
601
- * const proof = await request.pollUntilCompletion()
602
- * console.log('Success:', proof)
603
- * ```
604
- */
605
- declare function createRequest(config: IDKitRequestConfig): IDKitBuilder;
606
- /**
607
- * Creates a new session builder (no action, no existing session_id)
608
- *
609
- * Use this when creating a new session for a user who doesn't have one yet.
610
- * The response will include a `session_id` that should be saved for future
611
- * session proofs with `proveSession()`.
612
- *
613
- * @param config - Session configuration (no action field)
614
- * @returns IDKitBuilder - A builder instance
615
- *
616
- * @example
617
- * ```typescript
618
- * import { IDKit, CredentialRequest, any } from '@worldcoin/idkit-core'
619
- *
620
- * // Create a new session (user doesn't have session_id yet)
621
- * const request = await IDKit.createSession({
622
- * app_id: 'app_staging_xxxxx',
623
445
  * rp_context: { ... },
624
- * }).constraints(any(CredentialRequest('orb'), CredentialRequest('face')));
625
- *
626
- * // Display QR, wait for proof
627
- * const result = await request.pollUntilCompletion();
628
- * // result.session_id -> save this for future sessions
629
- * // result.responses[0].session_nullifier -> for session tracking
630
- * ```
631
- */
632
- declare function createSession(config: IDKitSessionConfig): IDKitBuilder;
633
- /**
634
- * Creates a builder for proving an existing session (no action, has session_id)
446
+ * allow_legacy_proofs: true,
447
+ * }).preset(orbLegacy({ signal: 'user-123' }));
635
448
  *
636
- * Use this when a returning user needs to prove they own an existing session.
637
- * The `sessionId` should be a value previously returned from `createSession()`.
638
- *
639
- * @param sessionId - The session ID from a previous session creation
640
- * @param config - Session configuration (no action field)
641
- * @returns IDKitBuilder - A builder instance
642
- *
643
- * @example
644
- * ```typescript
645
- * import { IDKit, CredentialRequest, any } from '@worldcoin/idkit-core'
646
- *
647
- * // Prove an existing session (user returns)
648
- * const request = await IDKit.proveSession(savedSessionId, {
449
+ * // With constraints (v4 only)
450
+ * const request = await IDKit.request({
649
451
  * app_id: 'app_staging_xxxxx',
452
+ * action: 'my-action',
650
453
  * rp_context: { ... },
651
- * }).constraints(any(CredentialRequest('orb'), CredentialRequest('face')));
454
+ * allow_legacy_proofs: false,
455
+ * }).constraints(enumerate(CredentialRequest('orb'), CredentialRequest('face')));
652
456
  *
653
- * const result = await request.pollUntilCompletion();
654
- * // result.session_id -> same session
655
- * // result.responses[0].session_nullifier -> should match for same user
457
+ * // In World App: connectorURI is empty, result comes via postMessage
458
+ * // On web: connectorURI is the QR URL to display
459
+ * console.log(request.connectorURI);
460
+ *
461
+ * // Wait for result — same interface in both environments
462
+ * const proof = await request.pollUntilCompletion();
656
463
  * ```
657
464
  */
658
- declare function proveSession(sessionId: string, config: IDKitSessionConfig): IDKitBuilder;
465
+ declare function createRequest(config: IDKitRequestConfig): IDKitBuilder;
659
466
  /**
660
467
  * IDKit namespace providing the main API entry points
661
468
  *
662
469
  * @example
663
470
  * ```typescript
664
- * import { IDKit, CredentialRequest, any } from '@worldcoin/idkit-core'
665
- *
666
- * // Initialize (only needed once)
667
- * await IDKit.init()
471
+ * import { IDKit, CredentialRequest, any, enumerate, orbLegacy } from '@worldcoin/idkit-core'
668
472
  *
669
- * // Create a request
473
+ * // Create a verification request
670
474
  * const request = await IDKit.request({
671
475
  * app_id: 'app_staging_xxxxx',
672
476
  * action: 'my-action',
673
477
  * rp_context: { ... },
674
- * }).constraints(any(CredentialRequest('orb'), CredentialRequest('face')))
478
+ * allow_legacy_proofs: true,
479
+ * }).preset(orbLegacy({ signal: 'user-123' }))
675
480
  *
676
- * // Display QR and wait for proof
481
+ * // In World App: result comes via postMessage (no QR needed)
482
+ * // On web: display QR code and wait for proof
677
483
  * console.log(request.connectorURI)
678
484
  * const proof = await request.pollUntilCompletion()
679
485
  * ```
680
486
  */
681
487
  declare const IDKit: {
682
- /** Initialize WASM for browser environments */
683
- init: typeof initIDKit;
684
- /** Initialize WASM for Node.js/server environments */
685
- initServer: typeof initIDKitServer;
686
488
  /** Create a new verification request */
687
489
  request: typeof createRequest;
688
- /** Create a new session (no action, no existing session_id) */
689
- createSession: typeof createSession;
690
- /** Prove an existing session (no action, has session_id) */
691
- proveSession: typeof proveSession;
692
- /** Create a CredentialRequest for a credential type */
693
- CredentialRequest: typeof CredentialRequest;
694
- /** Create an OR constraint - at least one child must be satisfied */
695
- any: typeof any;
696
- /** Create an AND constraint - all children must be satisfied */
697
- all: typeof all;
698
490
  /** Create an OrbLegacy preset for World ID 3.0 legacy support */
699
491
  orbLegacy: typeof orbLegacy;
700
492
  /** Create a SecureDocumentLegacy preset for World ID 3.0 legacy support */
@@ -725,39 +517,4 @@ declare const isWeb: () => boolean;
725
517
  */
726
518
  declare const isNode: () => boolean;
727
519
 
728
- /**
729
- * Signs an RP request for World ID proof verification
730
- *
731
- * **Backend-only**: This function should ONLY be used in Node.js/server environments.
732
- * Never use this in browser/client-side code as it requires access to your signing key.
733
- *
734
- * This function generates a cryptographic signature that authenticates your proof request.
735
- * The returned signature, nonce, and timestamps should be passed as `rp_context` to the client.
736
- *
737
- * @param action - The action tied to the proof request
738
- * @param signingKeyHex - The ECDSA private key as hex (0x-prefixed or not, 32 bytes)
739
- * @param ttlSeconds - Optional time-to-live in seconds (defaults to 300 = 5 minutes)
740
- * @returns RpSignature object with sig, nonce, createdAt, expiresAt to use as rp_context
741
- * @throws Error if called in non-Node.js environment or if parameters are invalid
742
- *
743
- * @example
744
- * ```typescript
745
- * import { signRequest } from '@worldcoin/idkit-core'
746
- *
747
- * const signingKey = process.env.RP_SIGNING_KEY // Load from secure env var
748
- * const signature = signRequest('my-action', signingKey)
749
- * console.log(signature.sig, signature.nonce, signature.createdAt, signature.expiresAt)
750
- * ```
751
- */
752
- declare function signRequest(action: string, signingKeyHex: string, ttlSeconds?: number): RpSignature;
753
-
754
- /**
755
- * Hashes a Signal (string or Uint8Array) to its hash representation.
756
- * This is the same hashing used internally when constructing proof requests.
757
- *
758
- * @param signal - The signal to hash (string or Uint8Array)
759
- * @returns 0x-prefixed hex string representing the signal hash
760
- */
761
- declare function hashSignal(signal: string | Uint8Array): string;
762
-
763
- 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, RpSignature, type SecureDocumentLegacyPreset, type Status$1 as Status, type WaitOptions, all, any, documentLegacy, hashSignal, isNode, isReactNative, isWeb, orbLegacy, secureDocumentLegacy, signRequest };
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 };