@worldcoin/idkit-core 2.0.2 → 4.0.1-dev.123c6a8

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.
@@ -0,0 +1,523 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * Hashes a signal string using Keccak256
5
+ */
6
+ export function hashSignal(signal: string): string;
7
+ /**
8
+ * Hashes raw bytes using Keccak256
9
+ */
10
+ export function hashSignalBytes(bytes: Uint8Array): string;
11
+ /**
12
+ * Entry point for creating `IDKit` requests (WASM)
13
+ *
14
+ * # Arguments
15
+ * * `app_id` - Application ID from the Developer Portal
16
+ * * `action` - Action identifier
17
+ * * `rp_context` - RP context for building protocol-level `ProofRequest`
18
+ * * `action_description` - Optional action description shown to users
19
+ * * `bridge_url` - Optional bridge URL (defaults to production)
20
+ */
21
+ export function request(app_id: string, action: string, rp_context: RpContextWasm, action_description?: string | null, bridge_url?: string | null): IDKitRequestBuilderWasm;
22
+ /**
23
+ * Creates an `OrbLegacy` preset for World ID 3.0 legacy support
24
+ *
25
+ * Returns a preset object that can be passed to `request().preset()`.
26
+ *
27
+ * # Arguments
28
+ * * `signal` - Optional signal string
29
+ *
30
+ * # Errors
31
+ *
32
+ * Returns an error if serialization fails
33
+ */
34
+ export function orbLegacy(signal?: string | null): any;
35
+ /**
36
+ * Initialize the WASM module.
37
+ * This sets up panic hooks for better error messages in the browser console.
38
+ * Safe to call multiple times - initialization only happens once.
39
+ */
40
+ export function init_wasm(): void;
41
+ /**
42
+ * Encodes data to base64
43
+ */
44
+ export function base64Encode(data: Uint8Array): string;
45
+ /**
46
+ * Decodes base64 data
47
+ *
48
+ * # Errors
49
+ *
50
+ * Returns an error if decoding fails
51
+ */
52
+ export function base64Decode(data: string): Uint8Array;
53
+ /**
54
+ * Signs an RP request for World ID proof verification
55
+ *
56
+ * **Backend-only**: This function should only be used in server-side environments.
57
+ * Never expose your signing key to client-side code.
58
+ *
59
+ * This function generates a cryptographic signature that RPs use to authenticate
60
+ * proof requests. It:
61
+ * 1. Generates a random nonce
62
+ * 2. Gets the current timestamp
63
+ * 3. Computes: keccak256(nonce || action || timestamp || `expires_at`)
64
+ * 4. Signs the hash with ECDSA secp256k1
65
+ *
66
+ * # Arguments
67
+ * * `action` - The action identifier string (e.g., "verify-human")
68
+ * * `signing_key_hex` - The ECDSA private key as hex (0x-prefixed or not, 32 bytes)
69
+ * * `ttl_seconds` - Optional time-to-live in seconds (defaults to 300 = 5 minutes)
70
+ *
71
+ * # Returns
72
+ * An `RpSignature` object containing the signature, nonce, and timestamps
73
+ * to be passed as `rp_context` in the proof request
74
+ *
75
+ * # Errors
76
+ * Returns an error if:
77
+ * - The signing key is invalid hex or wrong length
78
+ * - Random generation fails
79
+ * - Signing fails
80
+ *
81
+ * # Example
82
+ * ```javascript
83
+ * import { signRequest } from '@worldcoin/idkit-core'
84
+ *
85
+ * const signingKey = process.env.RP_SIGNING_KEY // Load from secure env var
86
+ * const signature = signRequest('my-action', signingKey) // default 5 min TTL
87
+ * const customTtl = signRequest('my-action', signingKey, 600) // 10 min TTL
88
+ * console.log(signature.sig, signature.nonce, signature.createdAt, signature.expiresAt)
89
+ * ```
90
+ */
91
+ export function signRequest(action: string, signing_key_hex: string, ttl_seconds?: bigint | null): RpSignature;
92
+
93
+ /** V4 response item (protocol version 4.0 / World ID v4) */
94
+ export interface ResponseItemV4 {
95
+ /** Credential identifier */
96
+ identifier: CredentialType;
97
+ /** Compressed Groth16 proof (hex) */
98
+ proof: string;
99
+ /** RP-scoped nullifier (hex) */
100
+ nullifier: string;
101
+ /** Authenticator merkle root (hex) */
102
+ merkle_root: string;
103
+ /** Unix timestamp when proof was generated */
104
+ proof_timestamp: number;
105
+ /** Credential issuer schema ID (hex) */
106
+ issuer_schema_id: string;
107
+ }
108
+
109
+ /** V3 response item (protocol version 3.0 / World ID v3 - legacy format) */
110
+ export interface ResponseItemV3 {
111
+ /** Credential identifier */
112
+ identifier: CredentialType;
113
+ /** ABI-encoded proof (hex) */
114
+ proof: string;
115
+ /** Merkle root (hex) */
116
+ merkle_root: string;
117
+ /** Nullifier hash (hex) */
118
+ nullifier_hash: string;
119
+ }
120
+
121
+ /**
122
+ * A single credential response item - unified type for both bridge and SDK.
123
+ * Type narrowing: use 'proof_timestamp' in item for V4, 'nullifier_hash' in item for V3.
124
+ */
125
+ export type ResponseItem = ResponseItemV4 | ResponseItemV3;
126
+
127
+ /** V3 result (legacy format - no session support) */
128
+ export interface IDKitResultV3 {
129
+ /** Protocol version 3.0 */
130
+ protocol_version: "3.0";
131
+ /** Array of V3 credential responses */
132
+ responses: ResponseItemV3[];
133
+ }
134
+
135
+ /** V4 result (current format - supports sessions) */
136
+ export interface IDKitResultV4 {
137
+ /** Protocol version 4.0 */
138
+ protocol_version: "4.0";
139
+ /** Session ID (for session proofs) */
140
+ session_id?: string;
141
+ /** Array of V4 credential responses */
142
+ responses: ResponseItemV4[];
143
+ }
144
+
145
+ /** The unified response structure - discriminated union by protocol_version */
146
+ export type IDKitResult = IDKitResultV3 | IDKitResultV4;
147
+
148
+ /** Status returned from pollForStatus() */
149
+ export type Status =
150
+ | { type: "waiting_for_connection" }
151
+ | { type: "awaiting_confirmation" }
152
+ | { type: "confirmed"; result: IDKitResult }
153
+ | { type: "failed"; error: string };
154
+
155
+
156
+
157
+ export type CredentialType = "orb" | "face" | "secure_document" | "document" | "device";
158
+
159
+ export interface CredentialRequestType {
160
+ type: CredentialType;
161
+ signal?: string;
162
+ genesis_issued_at_min?: number;
163
+ }
164
+
165
+ export type ConstraintNode =
166
+ | CredentialRequestType
167
+ | { any: ConstraintNode[] }
168
+ | { all: ConstraintNode[] };
169
+
170
+
171
+
172
+ export interface OrbLegacyPreset {
173
+ type: "OrbLegacy";
174
+ data: { signal?: string };
175
+ }
176
+
177
+ export type Preset = OrbLegacyPreset;
178
+
179
+ export function orbLegacy(signal?: string): Preset;
180
+
181
+
182
+
183
+ export interface RpSignature {
184
+ sig: string;
185
+ nonce: string;
186
+ createdAt: number;
187
+ expiresAt: number;
188
+ toJSON(): { sig: string; nonce: string; createdAt: number; expiresAt: number };
189
+ }
190
+
191
+ export function signRequest(action: string, signingKeyHex: string, ttlSeconds?: number): RpSignature;
192
+
193
+
194
+ /**
195
+ * Bridge encryption for secure communication between client and bridge
196
+ */
197
+ export class BridgeEncryption {
198
+ free(): void;
199
+ [Symbol.dispose](): void;
200
+ /**
201
+ * Returns the key as a base64-encoded string
202
+ */
203
+ keyBase64(): string;
204
+ /**
205
+ * Returns the nonce as a base64-encoded string
206
+ */
207
+ nonceBase64(): string;
208
+ /**
209
+ * Creates a new `BridgeEncryption` instance with randomly generated key and nonce
210
+ *
211
+ * # Errors
212
+ *
213
+ * Returns an error if key generation fails
214
+ */
215
+ constructor();
216
+ /**
217
+ * Decrypts a base64-encoded ciphertext using AES-256-GCM
218
+ *
219
+ * # Errors
220
+ *
221
+ * Returns an error if decryption fails or the output is not valid UTF-8
222
+ */
223
+ decrypt(ciphertext_base64: string): string;
224
+ /**
225
+ * Encrypts a plaintext string using AES-256-GCM and returns base64
226
+ *
227
+ * # Errors
228
+ *
229
+ * Returns an error if encryption fails
230
+ */
231
+ encrypt(plaintext: string): string;
232
+ }
233
+ /**
234
+ * WASM wrapper for `CredentialRequest`
235
+ */
236
+ export class CredentialRequestWasm {
237
+ free(): void;
238
+ [Symbol.dispose](): void;
239
+ /**
240
+ * Creates a new request item with ABI-encoded bytes for the signal
241
+ *
242
+ * # Errors
243
+ *
244
+ * Returns an error if the credential type is invalid
245
+ */
246
+ static withBytes(credential_type: any, signal_bytes: Uint8Array): CredentialRequestWasm;
247
+ /**
248
+ * Gets the credential type
249
+ */
250
+ credentialType(): any;
251
+ /**
252
+ * Gets the signal as raw bytes
253
+ */
254
+ getSignalBytes(): Uint8Array | undefined;
255
+ /**
256
+ * Creates a new request item with genesis minimum timestamp
257
+ *
258
+ * # Errors
259
+ *
260
+ * Returns an error if the credential type is invalid
261
+ */
262
+ static withGenesisMin(credential_type: any, signal: string | null | undefined, genesis_min: bigint): CredentialRequestWasm;
263
+ /**
264
+ * Creates a new request item
265
+ *
266
+ * # Arguments
267
+ * * `credential_type` - The type of credential to request (e.g., "orb", "face")
268
+ * * `signal` - Optional signal string
269
+ *
270
+ * # Errors
271
+ *
272
+ * Returns an error if the credential type is invalid
273
+ */
274
+ constructor(credential_type: any, signal?: string | null);
275
+ /**
276
+ * Converts the request item to JSON
277
+ *
278
+ * # Errors
279
+ *
280
+ * Returns an error if serialization fails
281
+ */
282
+ toJSON(): any;
283
+ }
284
+ /**
285
+ * WASM wrapper for `BridgeResponseV1` (legacy proof format)
286
+ */
287
+ export class IDKitProof {
288
+ free(): void;
289
+ [Symbol.dispose](): void;
290
+ /**
291
+ * Creates a new legacy proof (protocol v1 / World ID v3)
292
+ *
293
+ * # Errors
294
+ *
295
+ * Returns an error if the verification level cannot be deserialized
296
+ */
297
+ constructor(proof: string, merkle_root: string, nullifier_hash: string, verification_level: any);
298
+ /**
299
+ * Converts the proof to JSON
300
+ *
301
+ * # Errors
302
+ *
303
+ * Returns an error if serialization fails
304
+ */
305
+ toJSON(): any;
306
+ }
307
+ /**
308
+ * World ID verification request
309
+ *
310
+ * Manages the verification flow with World App via the bridge.
311
+ */
312
+ export class IDKitRequest {
313
+ private constructor();
314
+ free(): void;
315
+ [Symbol.dispose](): void;
316
+ /**
317
+ * Returns the request ID for this request
318
+ *
319
+ * # Errors
320
+ *
321
+ * Returns an error if the request has been closed
322
+ */
323
+ requestId(): string;
324
+ /**
325
+ * Returns the connect URL for World App
326
+ *
327
+ * This URL should be displayed as a QR code for users to scan with World App.
328
+ *
329
+ * # Errors
330
+ *
331
+ * Returns an error if the request has been closed
332
+ */
333
+ connectUrl(): string;
334
+ /**
335
+ * Polls the bridge for the current status (non-blocking)
336
+ *
337
+ * Returns a status object with type:
338
+ * - `"waiting_for_connection"` - Waiting for World App to retrieve the request
339
+ * - `"awaiting_confirmation"` - World App has retrieved the request, waiting for user
340
+ * - `"confirmed"` - User confirmed and provided a proof
341
+ * - `"failed"` - Request has failed
342
+ *
343
+ * # Errors
344
+ *
345
+ * Returns an error if the request fails or the response is invalid
346
+ */
347
+ pollForStatus(): Promise<any>;
348
+ }
349
+ /**
350
+ * Builder for creating `IDKit` requests (WASM)
351
+ */
352
+ export class IDKitRequestBuilderWasm {
353
+ free(): void;
354
+ [Symbol.dispose](): void;
355
+ /**
356
+ * Creates an `IDKit` request with the given constraints
357
+ *
358
+ * # Arguments
359
+ * * `constraints_json` - Constraint tree as JSON (`CredentialRequest` or `{any: []}` or `{all: []}`)
360
+ *
361
+ * # Errors
362
+ *
363
+ * Returns an error if the request cannot be created
364
+ */
365
+ constraints(constraints_json: any): Promise<any>;
366
+ /**
367
+ * Creates a new `IDKitRequestBuilder`
368
+ *
369
+ * # Arguments
370
+ * * `app_id` - Application ID from the Developer Portal
371
+ * * `action` - Action identifier
372
+ * * `rp_context` - RP context for building protocol-level `ProofRequest`
373
+ * * `action_description` - Optional action description shown to users
374
+ * * `bridge_url` - Optional bridge URL (defaults to production)
375
+ */
376
+ constructor(app_id: string, action: string, rp_context: RpContextWasm, action_description?: string | null, bridge_url?: string | null);
377
+ /**
378
+ * Creates an `IDKit` request from a preset
379
+ *
380
+ * Presets provide a simplified way to create requests with predefined
381
+ * credential configurations. The preset is converted to both World ID 4.0
382
+ * constraints and World ID 3.0 legacy fields for backward compatibility.
383
+ *
384
+ * # Arguments
385
+ * * `preset_json` - Preset object from `orbLegacy()`
386
+ *
387
+ * # Errors
388
+ *
389
+ * Returns an error if the request cannot be created
390
+ */
391
+ preset(preset_json: any): Promise<any>;
392
+ }
393
+ /**
394
+ * RP Context for protocol-level proof requests (WASM binding)
395
+ *
396
+ * Contains RP-specific data needed to construct a `ProofRequest`.
397
+ */
398
+ export class RpContextWasm {
399
+ free(): void;
400
+ [Symbol.dispose](): void;
401
+ /**
402
+ * Creates a new RP context
403
+ *
404
+ * # Arguments
405
+ * * `rp_id` - The registered RP ID (e.g., `"rp_123456789abcdef0"`)
406
+ * * `nonce` - Unique nonce for this proof request
407
+ * * `created_at` - Unix timestamp (seconds since epoch) when created
408
+ * * `expires_at` - Unix timestamp (seconds since epoch) when expires
409
+ * * `signature` - The RP's ECDSA signature of the `nonce` and `created_at` timestamp
410
+ *
411
+ * # Errors
412
+ *
413
+ * Returns an error if `rp_id` is not a valid RP ID (must start with `rp_`)
414
+ */
415
+ constructor(rp_id: string, nonce: string, created_at: bigint, expires_at: bigint, signature: string);
416
+ }
417
+ export class RpSignature {
418
+ private constructor();
419
+ free(): void;
420
+ [Symbol.dispose](): void;
421
+ /**
422
+ * Converts to JSON
423
+ *
424
+ * # Errors
425
+ *
426
+ * Returns an error if setting object properties fails
427
+ */
428
+ toJSON(): any;
429
+ /**
430
+ * Gets the creation timestamp
431
+ */
432
+ readonly createdAt: bigint;
433
+ /**
434
+ * Gets the expiration timestamp
435
+ */
436
+ readonly expiresAt: bigint;
437
+ /**
438
+ * Gets the signature as hex string (0x-prefixed, 65 bytes)
439
+ */
440
+ readonly sig: string;
441
+ /**
442
+ * Gets the nonce as hex string (0x-prefixed field element)
443
+ */
444
+ readonly nonce: string;
445
+ }
446
+
447
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
448
+
449
+ export interface InitOutput {
450
+ readonly memory: WebAssembly.Memory;
451
+ readonly __wbg_bridgeencryption_free: (a: number, b: number) => void;
452
+ readonly __wbg_credentialrequestwasm_free: (a: number, b: number) => void;
453
+ readonly __wbg_idkitproof_free: (a: number, b: number) => void;
454
+ readonly __wbg_idkitrequest_free: (a: number, b: number) => void;
455
+ readonly __wbg_idkitrequestbuilderwasm_free: (a: number, b: number) => void;
456
+ readonly __wbg_rpcontextwasm_free: (a: number, b: number) => void;
457
+ readonly __wbg_rpsignature_free: (a: number, b: number) => void;
458
+ readonly base64Decode: (a: number, b: number, c: number) => void;
459
+ readonly base64Encode: (a: number, b: number, c: number) => void;
460
+ readonly bridgeencryption_decrypt: (a: number, b: number, c: number, d: number) => void;
461
+ readonly bridgeencryption_encrypt: (a: number, b: number, c: number, d: number) => void;
462
+ readonly bridgeencryption_keyBase64: (a: number, b: number) => void;
463
+ readonly bridgeencryption_new: (a: number) => void;
464
+ readonly bridgeencryption_nonceBase64: (a: number, b: number) => void;
465
+ readonly credentialrequestwasm_credentialType: (a: number) => number;
466
+ readonly credentialrequestwasm_getSignalBytes: (a: number, b: number) => void;
467
+ readonly credentialrequestwasm_new: (a: number, b: number, c: number, d: number) => void;
468
+ readonly credentialrequestwasm_toJSON: (a: number, b: number) => void;
469
+ readonly credentialrequestwasm_withBytes: (a: number, b: number, c: number, d: number) => void;
470
+ readonly credentialrequestwasm_withGenesisMin: (a: number, b: number, c: number, d: number, e: bigint) => void;
471
+ readonly hashSignal: (a: number, b: number, c: number) => void;
472
+ readonly idkitproof_new: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
473
+ readonly idkitproof_toJSON: (a: number, b: number) => void;
474
+ readonly idkitrequest_connectUrl: (a: number, b: number) => void;
475
+ readonly idkitrequest_pollForStatus: (a: number) => number;
476
+ readonly idkitrequest_requestId: (a: number, b: number) => void;
477
+ readonly idkitrequestbuilderwasm_constraints: (a: number, b: number) => number;
478
+ readonly idkitrequestbuilderwasm_new: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => number;
479
+ readonly idkitrequestbuilderwasm_preset: (a: number, b: number) => number;
480
+ readonly orbLegacy: (a: number, b: number, c: number) => void;
481
+ readonly rpcontextwasm_new: (a: number, b: number, c: number, d: number, e: number, f: bigint, g: bigint, h: number, i: number) => void;
482
+ readonly rpsignature_createdAt: (a: number) => bigint;
483
+ readonly rpsignature_expiresAt: (a: number) => bigint;
484
+ readonly rpsignature_nonce: (a: number, b: number) => void;
485
+ readonly rpsignature_sig: (a: number, b: number) => void;
486
+ readonly rpsignature_toJSON: (a: number, b: number) => void;
487
+ readonly signRequest: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint) => void;
488
+ readonly init_wasm: () => void;
489
+ readonly hashSignalBytes: (a: number, b: number, c: number) => void;
490
+ readonly request: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => number;
491
+ readonly __wasm_bindgen_func_elem_551: (a: number, b: number) => void;
492
+ readonly __wasm_bindgen_func_elem_550: (a: number, b: number) => void;
493
+ readonly __wasm_bindgen_func_elem_914: (a: number, b: number, c: number) => void;
494
+ readonly __wasm_bindgen_func_elem_913: (a: number, b: number) => void;
495
+ readonly __wasm_bindgen_func_elem_1281: (a: number, b: number, c: number, d: number) => void;
496
+ readonly __wbindgen_export: (a: number, b: number) => number;
497
+ readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
498
+ readonly __wbindgen_export3: (a: number) => void;
499
+ readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
500
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
501
+ readonly __wbindgen_start: () => void;
502
+ }
503
+
504
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
505
+ /**
506
+ * Instantiates the given `module`, which can either be bytes or
507
+ * a precompiled `WebAssembly.Module`.
508
+ *
509
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
510
+ *
511
+ * @returns {InitOutput}
512
+ */
513
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
514
+
515
+ /**
516
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
517
+ * for everything else, calls `WebAssembly.instantiate` directly.
518
+ *
519
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
520
+ *
521
+ * @returns {Promise<InitOutput>}
522
+ */
523
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;