@worldcoin/idkit-core 4.0.1 → 4.0.2
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/README.md +19 -8
- package/dist/hashing.cjs +28 -0
- package/dist/hashing.d.cts +9 -0
- package/dist/hashing.d.ts +9 -0
- package/dist/hashing.js +26 -0
- package/dist/idkit_wasm_bg.wasm +0 -0
- package/dist/index.cjs +464 -140
- package/dist/index.d.cts +82 -214
- package/dist/index.d.ts +82 -214
- package/dist/index.js +464 -140
- package/dist/signing.cjs +76 -0
- package/dist/signing.d.cts +36 -0
- package/dist/signing.d.ts +36 -0
- package/dist/signing.js +73 -0
- package/package.json +15 -1
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
|
-
|
|
86
|
+
interface OrbLegacyPreset {
|
|
87
|
+
type: "OrbLegacy";
|
|
88
|
+
signal?: string;
|
|
89
|
+
}
|
|
84
90
|
|
|
85
|
-
interface
|
|
86
|
-
type:
|
|
87
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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,20 @@ type Status$1 =
|
|
|
223
228
|
|
|
224
229
|
|
|
225
230
|
|
|
226
|
-
|
|
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
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
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
|
-
|
|
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[] };
|
|
351
245
|
|
|
352
246
|
/**
|
|
353
247
|
* Result types - re-exported from WASM bindings
|
|
@@ -377,6 +271,19 @@ declare enum IDKitErrorCodes {
|
|
|
377
271
|
Cancelled = "cancelled"
|
|
378
272
|
}
|
|
379
273
|
|
|
274
|
+
interface BuilderConfig {
|
|
275
|
+
type: "request" | "session" | "proveSession";
|
|
276
|
+
app_id: string;
|
|
277
|
+
action?: string;
|
|
278
|
+
session_id?: string;
|
|
279
|
+
rp_context?: RpContext;
|
|
280
|
+
action_description?: string;
|
|
281
|
+
bridge_url?: string;
|
|
282
|
+
allow_legacy_proofs?: boolean;
|
|
283
|
+
override_connect_base_url?: string;
|
|
284
|
+
environment?: string;
|
|
285
|
+
}
|
|
286
|
+
|
|
380
287
|
/**
|
|
381
288
|
* IDKit Request
|
|
382
289
|
* Pure functional API for World ID verification - no dependencies
|
|
@@ -482,7 +389,7 @@ declare function all(...nodes: ConstraintNode[]): {
|
|
|
482
389
|
*
|
|
483
390
|
* @example
|
|
484
391
|
* ```typescript
|
|
485
|
-
* const request = await IDKit.request({ app_id, action, rp_context })
|
|
392
|
+
* const request = await IDKit.request({ app_id, action, rp_context, allow_legacy_proofs: true })
|
|
486
393
|
* .preset(orbLegacy({ signal: 'user-123' }))
|
|
487
394
|
* ```
|
|
488
395
|
*/
|
|
@@ -500,7 +407,7 @@ declare function orbLegacy(opts?: {
|
|
|
500
407
|
*
|
|
501
408
|
* @example
|
|
502
409
|
* ```typescript
|
|
503
|
-
* const request = await IDKit.request({ app_id, action, rp_context })
|
|
410
|
+
* const request = await IDKit.request({ app_id, action, rp_context, allow_legacy_proofs: true })
|
|
504
411
|
* .preset(secureDocumentLegacy({ signal: 'user-123' }))
|
|
505
412
|
* ```
|
|
506
413
|
*/
|
|
@@ -518,7 +425,7 @@ declare function secureDocumentLegacy(opts?: {
|
|
|
518
425
|
*
|
|
519
426
|
* @example
|
|
520
427
|
* ```typescript
|
|
521
|
-
* const request = await IDKit.request({ app_id, action, rp_context })
|
|
428
|
+
* const request = await IDKit.request({ app_id, action, rp_context, allow_legacy_proofs: true })
|
|
522
429
|
* .preset(documentLegacy({ signal: 'user-123' }))
|
|
523
430
|
* ```
|
|
524
431
|
*/
|
|
@@ -526,11 +433,15 @@ declare function documentLegacy(opts?: {
|
|
|
526
433
|
signal?: string;
|
|
527
434
|
}): DocumentLegacyPreset;
|
|
528
435
|
/**
|
|
529
|
-
*
|
|
436
|
+
* Builder for IDKit requests
|
|
437
|
+
*
|
|
438
|
+
* Stores configuration and defers transport selection to `.preset()` / `.constraints()`.
|
|
439
|
+
* In World App: uses native postMessage transport (no WASM needed).
|
|
440
|
+
* On web: uses WASM bridge transport (QR code + polling).
|
|
530
441
|
*/
|
|
531
442
|
declare class IDKitBuilder {
|
|
532
|
-
private
|
|
533
|
-
constructor(
|
|
443
|
+
private config;
|
|
444
|
+
constructor(config: BuilderConfig);
|
|
534
445
|
/**
|
|
535
446
|
* Creates an IDKit request with the given constraints
|
|
536
447
|
*
|
|
@@ -539,67 +450,64 @@ declare class IDKitBuilder {
|
|
|
539
450
|
*
|
|
540
451
|
* @example
|
|
541
452
|
* ```typescript
|
|
542
|
-
* const
|
|
543
|
-
*
|
|
453
|
+
* const request = await IDKit.request({ app_id, action, rp_context, allow_legacy_proofs: false })
|
|
454
|
+
* .constraints(any(CredentialRequest('orb'), CredentialRequest('face')));
|
|
544
455
|
* ```
|
|
545
456
|
*/
|
|
457
|
+
constraints(constraints: ConstraintNode): Promise<IDKitRequest>;
|
|
546
458
|
/**
|
|
547
459
|
* Creates an IDKit request from a preset (works for all request types)
|
|
548
460
|
*
|
|
549
461
|
* Presets provide a simplified way to create requests with predefined
|
|
550
462
|
* credential configurations.
|
|
551
463
|
*
|
|
552
|
-
* @param preset - A preset object from orbLegacy()
|
|
464
|
+
* @param preset - A preset object from orbLegacy(), secureDocumentLegacy(), or documentLegacy()
|
|
553
465
|
* @returns A new IDKitRequest instance
|
|
554
466
|
*
|
|
555
467
|
* @example
|
|
556
468
|
* ```typescript
|
|
557
|
-
* const
|
|
558
|
-
*
|
|
469
|
+
* const request = await IDKit.request({ app_id, action, rp_context, allow_legacy_proofs: true })
|
|
470
|
+
* .preset(orbLegacy({ signal: 'user-123' }));
|
|
559
471
|
* ```
|
|
560
472
|
*/
|
|
561
473
|
preset(preset: Preset): Promise<IDKitRequest>;
|
|
562
474
|
}
|
|
563
475
|
/**
|
|
564
|
-
* Creates an IDKit request builder
|
|
476
|
+
* Creates an IDKit verification request builder
|
|
565
477
|
*
|
|
566
478
|
* This is the main entry point for creating World ID verification requests.
|
|
567
|
-
* Use the builder pattern with constraints to specify
|
|
479
|
+
* Use the builder pattern with `.preset()` or `.constraints()` to specify
|
|
480
|
+
* which credentials to accept.
|
|
568
481
|
*
|
|
569
482
|
* @param config - Request configuration
|
|
570
483
|
* @returns IDKitBuilder - A builder instance
|
|
571
484
|
*
|
|
572
485
|
* @example
|
|
573
486
|
* ```typescript
|
|
574
|
-
* import { IDKit, CredentialRequest, any } from '@worldcoin/idkit-core'
|
|
575
|
-
*
|
|
576
|
-
* // Initialize WASM (only needed once)
|
|
577
|
-
* await IDKit.init()
|
|
487
|
+
* import { IDKit, CredentialRequest, any, orbLegacy } from '@worldcoin/idkit-core'
|
|
578
488
|
*
|
|
579
|
-
* //
|
|
580
|
-
* const
|
|
581
|
-
*
|
|
489
|
+
* // With preset (legacy support)
|
|
490
|
+
* const request = await IDKit.request({
|
|
491
|
+
* app_id: 'app_staging_xxxxx',
|
|
492
|
+
* action: 'my-action',
|
|
493
|
+
* rp_context: { ... },
|
|
494
|
+
* allow_legacy_proofs: true,
|
|
495
|
+
* }).preset(orbLegacy({ signal: 'user-123' }));
|
|
582
496
|
*
|
|
583
|
-
* //
|
|
497
|
+
* // With constraints (v4 only)
|
|
584
498
|
* const request = await IDKit.request({
|
|
585
499
|
* app_id: 'app_staging_xxxxx',
|
|
586
500
|
* 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
|
-
* },
|
|
501
|
+
* rp_context: { ... },
|
|
594
502
|
* allow_legacy_proofs: false,
|
|
595
|
-
* }).constraints(any(orb, face));
|
|
503
|
+
* }).constraints(any(CredentialRequest('orb'), CredentialRequest('face')));
|
|
596
504
|
*
|
|
597
|
-
* //
|
|
598
|
-
*
|
|
505
|
+
* // In World App: connectorURI is empty, result comes via postMessage
|
|
506
|
+
* // On web: connectorURI is the QR URL to display
|
|
507
|
+
* console.log(request.connectorURI);
|
|
599
508
|
*
|
|
600
|
-
* // Wait for
|
|
601
|
-
* const proof = await request.pollUntilCompletion()
|
|
602
|
-
* console.log('Success:', proof)
|
|
509
|
+
* // Wait for result — same interface in both environments
|
|
510
|
+
* const proof = await request.pollUntilCompletion();
|
|
603
511
|
* ```
|
|
604
512
|
*/
|
|
605
513
|
declare function createRequest(config: IDKitRequestConfig): IDKitBuilder;
|
|
@@ -661,28 +569,23 @@ declare function proveSession(sessionId: string, config: IDKitSessionConfig): ID
|
|
|
661
569
|
*
|
|
662
570
|
* @example
|
|
663
571
|
* ```typescript
|
|
664
|
-
* import { IDKit, CredentialRequest, any } from '@worldcoin/idkit-core'
|
|
572
|
+
* import { IDKit, CredentialRequest, any, orbLegacy } from '@worldcoin/idkit-core'
|
|
665
573
|
*
|
|
666
|
-
* //
|
|
667
|
-
* await IDKit.init()
|
|
668
|
-
*
|
|
669
|
-
* // Create a request
|
|
574
|
+
* // Create a verification request
|
|
670
575
|
* const request = await IDKit.request({
|
|
671
576
|
* app_id: 'app_staging_xxxxx',
|
|
672
577
|
* action: 'my-action',
|
|
673
578
|
* rp_context: { ... },
|
|
674
|
-
*
|
|
579
|
+
* allow_legacy_proofs: true,
|
|
580
|
+
* }).preset(orbLegacy({ signal: 'user-123' }))
|
|
675
581
|
*
|
|
676
|
-
* //
|
|
582
|
+
* // In World App: result comes via postMessage (no QR needed)
|
|
583
|
+
* // On web: display QR code and wait for proof
|
|
677
584
|
* console.log(request.connectorURI)
|
|
678
585
|
* const proof = await request.pollUntilCompletion()
|
|
679
586
|
* ```
|
|
680
587
|
*/
|
|
681
588
|
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
589
|
/** Create a new verification request */
|
|
687
590
|
request: typeof createRequest;
|
|
688
591
|
/** Create a new session (no action, no existing session_id) */
|
|
@@ -725,39 +628,4 @@ declare const isWeb: () => boolean;
|
|
|
725
628
|
*/
|
|
726
629
|
declare const isNode: () => boolean;
|
|
727
630
|
|
|
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 };
|
|
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 };
|