@worldcoin/idkit-core 4.0.15 → 4.1.0

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,4 +1,4 @@
1
- export { RpSignature, signRequest } from '@worldcoin/idkit-server';
1
+ export { RpSignature, SignRequestParams, signRequest } from '@worldcoin/idkit-server';
2
2
  export { hashSignal } from './hashing.cjs';
3
3
 
4
4
  /**
@@ -47,6 +47,8 @@ type IDKitRequestConfig = {
47
47
  action_description?: string;
48
48
  /** URL to a third-party bridge to use when connecting to the World App. Optional. */
49
49
  bridge_url?: string;
50
+ /** Optional deep-link callback URL appended as `return_to` on the connector URL. */
51
+ return_to?: string;
50
52
  /**
51
53
  * Whether to accept legacy (v3) World ID proofs as fallback.
52
54
  *
@@ -77,6 +79,8 @@ type IDKitSessionConfig = {
77
79
  action_description?: string;
78
80
  /** URL to a third-party bridge to use when connecting to the World App. Optional. */
79
81
  bridge_url?: string;
82
+ /** Optional deep-link callback URL appended as `return_to` on the connector URL. */
83
+ return_to?: string;
80
84
  /** Optional override for the connect base URL (e.g., for staging environments) */
81
85
  override_connect_base_url?: string;
82
86
  /** Optional environment override. Defaults to "production". */
@@ -169,8 +173,8 @@ interface IDKitResultSession {
169
173
  nonce: string;
170
174
  /** Action description (only if provided in input) */
171
175
  action_description?: string;
172
- /** Session ID returned by the World App */
173
- session_id: string;
176
+ /** Opaque session identifier returned by the World App in `session_<hex>` format */
177
+ session_id: `session_${string}`;
174
178
  /** Array of session credential responses */
175
179
  responses: ResponseItemSession[];
176
180
  /** The environment used for this request ("production" or "staging") */
@@ -293,13 +297,14 @@ declare enum IDKitErrorCodes {
293
297
  */
294
298
  declare function isInWorldApp(): boolean;
295
299
  interface BuilderConfig {
296
- type: "request" | "session" | "proveSession";
300
+ type: "request" | "createSession" | "proveSession";
297
301
  app_id: string;
298
302
  action?: string;
299
- session_id?: string;
303
+ session_id?: `session_${string}`;
300
304
  rp_context?: RpContext;
301
305
  action_description?: string;
302
306
  bridge_url?: string;
307
+ return_to?: string;
303
308
  allow_legacy_proofs?: boolean;
304
309
  override_connect_base_url?: string;
305
310
  environment?: string;
@@ -314,7 +319,7 @@ interface BuilderConfig {
314
319
  interface WaitOptions {
315
320
  /** Milliseconds between polls (default: 1000) */
316
321
  pollInterval?: number;
317
- /** Total timeout in milliseconds (default: 300000 = 5 minutes) */
322
+ /** Total timeout in milliseconds (default: 900000 = 15 minutes) */
318
323
  timeout?: number;
319
324
  /** AbortSignal for cancellation */
320
325
  signal?: AbortSignal;
@@ -350,6 +355,74 @@ interface IDKitRequest {
350
355
  /** Poll continuously until completion or timeout */
351
356
  pollUntilCompletion(options?: WaitOptions): Promise<IDKitCompletionResult>;
352
357
  }
358
+ /**
359
+ * Creates a CredentialRequest for a credential type
360
+ *
361
+ * @param credential_type - The type of credential to request (e.g., 'proof_of_human', 'face')
362
+ * @param options - Optional signal, genesis_issued_at_min, and expires_at_min
363
+ * @returns A CredentialRequest object
364
+ *
365
+ * @example
366
+ * ```typescript
367
+ * const orb = CredentialRequest('proof_of_human', { signal: 'user-123' })
368
+ * const face = CredentialRequest('face')
369
+ * // Require credential to be valid for at least one year
370
+ * const withExpiry = CredentialRequest('proof_of_human', { expires_at_min: Date.now() / 1000 + 60 * 60 * 60 * 24 * 365 })
371
+ * ```
372
+ */
373
+ declare function CredentialRequest(credential_type: CredentialType, options?: {
374
+ signal?: string;
375
+ genesis_issued_at_min?: number;
376
+ expires_at_min?: number;
377
+ }): CredentialRequestType;
378
+ /**
379
+ * Creates an OR constraint - at least one child must be satisfied
380
+ *
381
+ * @param nodes - Constraint nodes (CredentialRequests or nested constraints)
382
+ * @returns An "any" constraint node
383
+ *
384
+ * @example
385
+ * ```typescript
386
+ * const constraint = any(CredentialRequest('proof_of_human'), CredentialRequest('face'))
387
+ * ```
388
+ */
389
+ declare function any(...nodes: ConstraintNode[]): {
390
+ any: ConstraintNode[];
391
+ };
392
+ /**
393
+ * Creates an AND constraint - all children must be satisfied
394
+ *
395
+ * @param nodes - Constraint nodes (CredentialRequests or nested constraints)
396
+ * @returns An "all" constraint node
397
+ *
398
+ * @example
399
+ * ```typescript
400
+ * const constraint = all(CredentialRequest('proof_of_human'), any(CredentialRequest('passport'), CredentialRequest('mnc')))
401
+ * ```
402
+ */
403
+ declare function all(...nodes: ConstraintNode[]): {
404
+ all: ConstraintNode[];
405
+ };
406
+ /**
407
+ * Creates an enumerate constraint - all satisfiable children should be selected
408
+ *
409
+ * `enumerate` is satisfied when at least one child is satisfied.
410
+ *
411
+ * @param nodes - Constraint nodes (CredentialRequests or nested constraints)
412
+ * @returns An "enumerate" constraint node
413
+ *
414
+ * @example
415
+ * ```typescript
416
+ * const constraint = enumerate(
417
+ * CredentialRequest('passport'),
418
+ * CredentialRequest('mnc'),
419
+ * )
420
+ * ```
421
+ */
422
+ declare function enumerate(...nodes: ConstraintNode[]): {
423
+ enumerate: ConstraintNode[];
424
+ };
425
+
353
426
  /**
354
427
  * Creates an OrbLegacy preset for World ID 3.0 legacy support
355
428
  *
@@ -517,6 +590,60 @@ declare class IDKitBuilder {
517
590
  * ```
518
591
  */
519
592
  declare function createRequest(config: IDKitRequestConfig): IDKitBuilder;
593
+ /**
594
+ * Creates a new session builder (no action, no existing session_id)
595
+ *
596
+ * Use this when creating a new session for a user who doesn't have one yet.
597
+ * The response will include a `session_id` that should be saved for future
598
+ * session proofs with `proveSession()`.
599
+ *
600
+ * @param config - Session configuration (no action field)
601
+ * @returns IDKitBuilder - A builder instance
602
+ *
603
+ * @example
604
+ * ```typescript
605
+ * import { IDKit, CredentialRequest, any } from '@worldcoin/idkit-core'
606
+ *
607
+ * // Create a new session (user doesn't have session_id yet)
608
+ * const request = await IDKit.createSession({
609
+ * app_id: 'app_staging_xxxxx',
610
+ * rp_context: { ... },
611
+ * }).constraints(any(CredentialRequest('proof_of_human'), CredentialRequest('face')));
612
+ *
613
+ * // Display QR, wait for proof
614
+ * const result = await request.pollUntilCompletion();
615
+ * // result.session_id -> save this for future sessions
616
+ * // result.responses[0].session_nullifier -> for session tracking
617
+ * ```
618
+ */
619
+ declare function createSession(config: IDKitSessionConfig): IDKitBuilder;
620
+ /**
621
+ * Creates a builder for proving an existing session (no action, has session_id)
622
+ *
623
+ * Use this when a returning user needs to prove they own an existing session.
624
+ * The `sessionId` should be the opaque `session_<hex>` value previously returned
625
+ * from `createSession()`.
626
+ *
627
+ * @param sessionId - The protocol session ID from a previous session creation
628
+ * @param config - Session configuration (no action field)
629
+ * @returns IDKitBuilder - A builder instance
630
+ *
631
+ * @example
632
+ * ```typescript
633
+ * import { IDKit, CredentialRequest, any } from '@worldcoin/idkit-core'
634
+ *
635
+ * // Prove an existing session (user returns)
636
+ * const request = await IDKit.proveSession(savedSessionId, {
637
+ * app_id: 'app_staging_xxxxx',
638
+ * rp_context: { ... },
639
+ * }).constraints(any(CredentialRequest('proof_of_human'), CredentialRequest('face')));
640
+ *
641
+ * const result = await request.pollUntilCompletion();
642
+ * // result.session_id -> same session
643
+ * // result.responses[0].session_nullifier -> should match for same user
644
+ * ```
645
+ */
646
+ declare function proveSession(sessionId: `session_${string}`, config: IDKitSessionConfig): IDKitBuilder;
520
647
  /**
521
648
  * IDKit namespace providing the main API entry points
522
649
  *
@@ -541,6 +668,18 @@ declare function createRequest(config: IDKitRequestConfig): IDKitBuilder;
541
668
  declare const IDKit: {
542
669
  /** Create a new verification request */
543
670
  request: typeof createRequest;
671
+ /** Create a new session (no action, no existing session_id) */
672
+ createSession: typeof createSession;
673
+ /** Prove an existing session (no action, has session_id) */
674
+ proveSession: typeof proveSession;
675
+ /** Create a CredentialRequest for a credential type */
676
+ CredentialRequest: typeof CredentialRequest;
677
+ /** Create an OR constraint - at least one child must be satisfied */
678
+ any: typeof any;
679
+ /** Create an AND constraint - all children must be satisfied */
680
+ all: typeof all;
681
+ /** Create an enumerate constraint - all satisfiable children should be selected */
682
+ enumerate: typeof enumerate;
544
683
  /** Create an OrbLegacy preset for World ID 3.0 legacy support */
545
684
  orbLegacy: typeof orbLegacy;
546
685
  /** Create a SecureDocumentLegacy preset for World ID 3.0 legacy support */
@@ -575,4 +714,7 @@ declare const isWeb: () => boolean;
575
714
  */
576
715
  declare const isNode: () => boolean;
577
716
 
578
- export { type AbiEncodedValue, type ConstraintNode, type CredentialRequestType, type CredentialType, type DeviceLegacyPreset, 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 SelfieCheckLegacyPreset, type Status$1 as Status, type WaitOptions, deviceLegacy, documentLegacy, isInWorldApp, isNode, isReactNative, isWeb, orbLegacy, secureDocumentLegacy, selfieCheckLegacy };
717
+ declare function isDebug(): boolean;
718
+ declare function setDebug(enabled: boolean): void;
719
+
720
+ export { type AbiEncodedValue, type ConstraintNode, CredentialRequest, type CredentialRequestType, type CredentialType, type DeviceLegacyPreset, 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 SelfieCheckLegacyPreset, type Status$1 as Status, type WaitOptions, all, any, deviceLegacy, documentLegacy, enumerate, isDebug, isInWorldApp, isNode, isReactNative, isWeb, orbLegacy, secureDocumentLegacy, selfieCheckLegacy, setDebug };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { RpSignature, signRequest } from '@worldcoin/idkit-server';
1
+ export { RpSignature, SignRequestParams, signRequest } from '@worldcoin/idkit-server';
2
2
  export { hashSignal } from './hashing.js';
3
3
 
4
4
  /**
@@ -47,6 +47,8 @@ type IDKitRequestConfig = {
47
47
  action_description?: string;
48
48
  /** URL to a third-party bridge to use when connecting to the World App. Optional. */
49
49
  bridge_url?: string;
50
+ /** Optional deep-link callback URL appended as `return_to` on the connector URL. */
51
+ return_to?: string;
50
52
  /**
51
53
  * Whether to accept legacy (v3) World ID proofs as fallback.
52
54
  *
@@ -77,6 +79,8 @@ type IDKitSessionConfig = {
77
79
  action_description?: string;
78
80
  /** URL to a third-party bridge to use when connecting to the World App. Optional. */
79
81
  bridge_url?: string;
82
+ /** Optional deep-link callback URL appended as `return_to` on the connector URL. */
83
+ return_to?: string;
80
84
  /** Optional override for the connect base URL (e.g., for staging environments) */
81
85
  override_connect_base_url?: string;
82
86
  /** Optional environment override. Defaults to "production". */
@@ -169,8 +173,8 @@ interface IDKitResultSession {
169
173
  nonce: string;
170
174
  /** Action description (only if provided in input) */
171
175
  action_description?: string;
172
- /** Session ID returned by the World App */
173
- session_id: string;
176
+ /** Opaque session identifier returned by the World App in `session_<hex>` format */
177
+ session_id: `session_${string}`;
174
178
  /** Array of session credential responses */
175
179
  responses: ResponseItemSession[];
176
180
  /** The environment used for this request ("production" or "staging") */
@@ -293,13 +297,14 @@ declare enum IDKitErrorCodes {
293
297
  */
294
298
  declare function isInWorldApp(): boolean;
295
299
  interface BuilderConfig {
296
- type: "request" | "session" | "proveSession";
300
+ type: "request" | "createSession" | "proveSession";
297
301
  app_id: string;
298
302
  action?: string;
299
- session_id?: string;
303
+ session_id?: `session_${string}`;
300
304
  rp_context?: RpContext;
301
305
  action_description?: string;
302
306
  bridge_url?: string;
307
+ return_to?: string;
303
308
  allow_legacy_proofs?: boolean;
304
309
  override_connect_base_url?: string;
305
310
  environment?: string;
@@ -314,7 +319,7 @@ interface BuilderConfig {
314
319
  interface WaitOptions {
315
320
  /** Milliseconds between polls (default: 1000) */
316
321
  pollInterval?: number;
317
- /** Total timeout in milliseconds (default: 300000 = 5 minutes) */
322
+ /** Total timeout in milliseconds (default: 900000 = 15 minutes) */
318
323
  timeout?: number;
319
324
  /** AbortSignal for cancellation */
320
325
  signal?: AbortSignal;
@@ -350,6 +355,74 @@ interface IDKitRequest {
350
355
  /** Poll continuously until completion or timeout */
351
356
  pollUntilCompletion(options?: WaitOptions): Promise<IDKitCompletionResult>;
352
357
  }
358
+ /**
359
+ * Creates a CredentialRequest for a credential type
360
+ *
361
+ * @param credential_type - The type of credential to request (e.g., 'proof_of_human', 'face')
362
+ * @param options - Optional signal, genesis_issued_at_min, and expires_at_min
363
+ * @returns A CredentialRequest object
364
+ *
365
+ * @example
366
+ * ```typescript
367
+ * const orb = CredentialRequest('proof_of_human', { signal: 'user-123' })
368
+ * const face = CredentialRequest('face')
369
+ * // Require credential to be valid for at least one year
370
+ * const withExpiry = CredentialRequest('proof_of_human', { expires_at_min: Date.now() / 1000 + 60 * 60 * 60 * 24 * 365 })
371
+ * ```
372
+ */
373
+ declare function CredentialRequest(credential_type: CredentialType, options?: {
374
+ signal?: string;
375
+ genesis_issued_at_min?: number;
376
+ expires_at_min?: number;
377
+ }): CredentialRequestType;
378
+ /**
379
+ * Creates an OR constraint - at least one child must be satisfied
380
+ *
381
+ * @param nodes - Constraint nodes (CredentialRequests or nested constraints)
382
+ * @returns An "any" constraint node
383
+ *
384
+ * @example
385
+ * ```typescript
386
+ * const constraint = any(CredentialRequest('proof_of_human'), CredentialRequest('face'))
387
+ * ```
388
+ */
389
+ declare function any(...nodes: ConstraintNode[]): {
390
+ any: ConstraintNode[];
391
+ };
392
+ /**
393
+ * Creates an AND constraint - all children must be satisfied
394
+ *
395
+ * @param nodes - Constraint nodes (CredentialRequests or nested constraints)
396
+ * @returns An "all" constraint node
397
+ *
398
+ * @example
399
+ * ```typescript
400
+ * const constraint = all(CredentialRequest('proof_of_human'), any(CredentialRequest('passport'), CredentialRequest('mnc')))
401
+ * ```
402
+ */
403
+ declare function all(...nodes: ConstraintNode[]): {
404
+ all: ConstraintNode[];
405
+ };
406
+ /**
407
+ * Creates an enumerate constraint - all satisfiable children should be selected
408
+ *
409
+ * `enumerate` is satisfied when at least one child is satisfied.
410
+ *
411
+ * @param nodes - Constraint nodes (CredentialRequests or nested constraints)
412
+ * @returns An "enumerate" constraint node
413
+ *
414
+ * @example
415
+ * ```typescript
416
+ * const constraint = enumerate(
417
+ * CredentialRequest('passport'),
418
+ * CredentialRequest('mnc'),
419
+ * )
420
+ * ```
421
+ */
422
+ declare function enumerate(...nodes: ConstraintNode[]): {
423
+ enumerate: ConstraintNode[];
424
+ };
425
+
353
426
  /**
354
427
  * Creates an OrbLegacy preset for World ID 3.0 legacy support
355
428
  *
@@ -517,6 +590,60 @@ declare class IDKitBuilder {
517
590
  * ```
518
591
  */
519
592
  declare function createRequest(config: IDKitRequestConfig): IDKitBuilder;
593
+ /**
594
+ * Creates a new session builder (no action, no existing session_id)
595
+ *
596
+ * Use this when creating a new session for a user who doesn't have one yet.
597
+ * The response will include a `session_id` that should be saved for future
598
+ * session proofs with `proveSession()`.
599
+ *
600
+ * @param config - Session configuration (no action field)
601
+ * @returns IDKitBuilder - A builder instance
602
+ *
603
+ * @example
604
+ * ```typescript
605
+ * import { IDKit, CredentialRequest, any } from '@worldcoin/idkit-core'
606
+ *
607
+ * // Create a new session (user doesn't have session_id yet)
608
+ * const request = await IDKit.createSession({
609
+ * app_id: 'app_staging_xxxxx',
610
+ * rp_context: { ... },
611
+ * }).constraints(any(CredentialRequest('proof_of_human'), CredentialRequest('face')));
612
+ *
613
+ * // Display QR, wait for proof
614
+ * const result = await request.pollUntilCompletion();
615
+ * // result.session_id -> save this for future sessions
616
+ * // result.responses[0].session_nullifier -> for session tracking
617
+ * ```
618
+ */
619
+ declare function createSession(config: IDKitSessionConfig): IDKitBuilder;
620
+ /**
621
+ * Creates a builder for proving an existing session (no action, has session_id)
622
+ *
623
+ * Use this when a returning user needs to prove they own an existing session.
624
+ * The `sessionId` should be the opaque `session_<hex>` value previously returned
625
+ * from `createSession()`.
626
+ *
627
+ * @param sessionId - The protocol session ID from a previous session creation
628
+ * @param config - Session configuration (no action field)
629
+ * @returns IDKitBuilder - A builder instance
630
+ *
631
+ * @example
632
+ * ```typescript
633
+ * import { IDKit, CredentialRequest, any } from '@worldcoin/idkit-core'
634
+ *
635
+ * // Prove an existing session (user returns)
636
+ * const request = await IDKit.proveSession(savedSessionId, {
637
+ * app_id: 'app_staging_xxxxx',
638
+ * rp_context: { ... },
639
+ * }).constraints(any(CredentialRequest('proof_of_human'), CredentialRequest('face')));
640
+ *
641
+ * const result = await request.pollUntilCompletion();
642
+ * // result.session_id -> same session
643
+ * // result.responses[0].session_nullifier -> should match for same user
644
+ * ```
645
+ */
646
+ declare function proveSession(sessionId: `session_${string}`, config: IDKitSessionConfig): IDKitBuilder;
520
647
  /**
521
648
  * IDKit namespace providing the main API entry points
522
649
  *
@@ -541,6 +668,18 @@ declare function createRequest(config: IDKitRequestConfig): IDKitBuilder;
541
668
  declare const IDKit: {
542
669
  /** Create a new verification request */
543
670
  request: typeof createRequest;
671
+ /** Create a new session (no action, no existing session_id) */
672
+ createSession: typeof createSession;
673
+ /** Prove an existing session (no action, has session_id) */
674
+ proveSession: typeof proveSession;
675
+ /** Create a CredentialRequest for a credential type */
676
+ CredentialRequest: typeof CredentialRequest;
677
+ /** Create an OR constraint - at least one child must be satisfied */
678
+ any: typeof any;
679
+ /** Create an AND constraint - all children must be satisfied */
680
+ all: typeof all;
681
+ /** Create an enumerate constraint - all satisfiable children should be selected */
682
+ enumerate: typeof enumerate;
544
683
  /** Create an OrbLegacy preset for World ID 3.0 legacy support */
545
684
  orbLegacy: typeof orbLegacy;
546
685
  /** Create a SecureDocumentLegacy preset for World ID 3.0 legacy support */
@@ -575,4 +714,7 @@ declare const isWeb: () => boolean;
575
714
  */
576
715
  declare const isNode: () => boolean;
577
716
 
578
- export { type AbiEncodedValue, type ConstraintNode, type CredentialRequestType, type CredentialType, type DeviceLegacyPreset, 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 SelfieCheckLegacyPreset, type Status$1 as Status, type WaitOptions, deviceLegacy, documentLegacy, isInWorldApp, isNode, isReactNative, isWeb, orbLegacy, secureDocumentLegacy, selfieCheckLegacy };
717
+ declare function isDebug(): boolean;
718
+ declare function setDebug(enabled: boolean): void;
719
+
720
+ export { type AbiEncodedValue, type ConstraintNode, CredentialRequest, type CredentialRequestType, type CredentialType, type DeviceLegacyPreset, 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 SelfieCheckLegacyPreset, type Status$1 as Status, type WaitOptions, all, any, deviceLegacy, documentLegacy, enumerate, isDebug, isInWorldApp, isNode, isReactNative, isWeb, orbLegacy, secureDocumentLegacy, selfieCheckLegacy, setDebug };