@worldcoin/idkit-core 2.1.0 → 4.0.1-dev.eebacb1

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,456 @@
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
+ export interface OrbLegacyPreset {
94
+ type: "OrbLegacy";
95
+ data: { signal?: string };
96
+ }
97
+
98
+ export type Preset = OrbLegacyPreset;
99
+
100
+ export function orbLegacy(signal?: string): Preset;
101
+
102
+
103
+
104
+ export type CredentialType = "orb" | "face" | "secure_document" | "document" | "device";
105
+
106
+ export interface CredentialRequestType {
107
+ type: CredentialType;
108
+ signal?: string;
109
+ genesis_issued_at_min?: number;
110
+ }
111
+
112
+ export type ConstraintNode =
113
+ | CredentialRequestType
114
+ | { any: ConstraintNode[] }
115
+ | { all: ConstraintNode[] };
116
+
117
+
118
+
119
+ export interface RpSignature {
120
+ sig: string;
121
+ nonce: string;
122
+ createdAt: number;
123
+ expiresAt: number;
124
+ toJSON(): { sig: string; nonce: string; createdAt: number; expiresAt: number };
125
+ }
126
+
127
+ export function signRequest(action: string, signingKeyHex: string, ttlSeconds?: number): RpSignature;
128
+
129
+
130
+ /**
131
+ * Bridge encryption for secure communication between client and bridge
132
+ */
133
+ export class BridgeEncryption {
134
+ free(): void;
135
+ [Symbol.dispose](): void;
136
+ /**
137
+ * Returns the key as a base64-encoded string
138
+ */
139
+ keyBase64(): string;
140
+ /**
141
+ * Returns the nonce as a base64-encoded string
142
+ */
143
+ nonceBase64(): string;
144
+ /**
145
+ * Creates a new `BridgeEncryption` instance with randomly generated key and nonce
146
+ *
147
+ * # Errors
148
+ *
149
+ * Returns an error if key generation fails
150
+ */
151
+ constructor();
152
+ /**
153
+ * Decrypts a base64-encoded ciphertext using AES-256-GCM
154
+ *
155
+ * # Errors
156
+ *
157
+ * Returns an error if decryption fails or the output is not valid UTF-8
158
+ */
159
+ decrypt(ciphertext_base64: string): string;
160
+ /**
161
+ * Encrypts a plaintext string using AES-256-GCM and returns base64
162
+ *
163
+ * # Errors
164
+ *
165
+ * Returns an error if encryption fails
166
+ */
167
+ encrypt(plaintext: string): string;
168
+ }
169
+ /**
170
+ * WASM wrapper for `CredentialRequest`
171
+ */
172
+ export class CredentialRequestWasm {
173
+ free(): void;
174
+ [Symbol.dispose](): void;
175
+ /**
176
+ * Creates a new request item with ABI-encoded bytes for the signal
177
+ *
178
+ * # Errors
179
+ *
180
+ * Returns an error if the credential type is invalid
181
+ */
182
+ static withBytes(credential_type: any, signal_bytes: Uint8Array): CredentialRequestWasm;
183
+ /**
184
+ * Gets the credential type
185
+ */
186
+ credentialType(): any;
187
+ /**
188
+ * Gets the signal as raw bytes
189
+ */
190
+ getSignalBytes(): Uint8Array | undefined;
191
+ /**
192
+ * Creates a new request item with genesis minimum timestamp
193
+ *
194
+ * # Errors
195
+ *
196
+ * Returns an error if the credential type is invalid
197
+ */
198
+ static withGenesisMin(credential_type: any, signal: string | null | undefined, genesis_min: bigint): CredentialRequestWasm;
199
+ /**
200
+ * Creates a new request item
201
+ *
202
+ * # Arguments
203
+ * * `credential_type` - The type of credential to request (e.g., "orb", "face")
204
+ * * `signal` - Optional signal string
205
+ *
206
+ * # Errors
207
+ *
208
+ * Returns an error if the credential type is invalid
209
+ */
210
+ constructor(credential_type: any, signal?: string | null);
211
+ /**
212
+ * Converts the request item to JSON
213
+ *
214
+ * # Errors
215
+ *
216
+ * Returns an error if serialization fails
217
+ */
218
+ toJSON(): any;
219
+ }
220
+ export class IDKitProof {
221
+ free(): void;
222
+ [Symbol.dispose](): void;
223
+ /**
224
+ * Creates a new proof
225
+ *
226
+ * # Errors
227
+ *
228
+ * Returns an error if the verification level cannot be deserialized
229
+ */
230
+ constructor(proof: string, merkle_root: string, nullifier_hash: string, verification_level: any);
231
+ /**
232
+ * Converts the proof to JSON
233
+ *
234
+ * # Errors
235
+ *
236
+ * Returns an error if serialization fails
237
+ */
238
+ toJSON(): any;
239
+ }
240
+ /**
241
+ * World ID verification request
242
+ *
243
+ * Manages the verification flow with World App via the bridge.
244
+ */
245
+ export class IDKitRequest {
246
+ private constructor();
247
+ free(): void;
248
+ [Symbol.dispose](): void;
249
+ /**
250
+ * Returns the request ID for this request
251
+ *
252
+ * # Errors
253
+ *
254
+ * Returns an error if the request has been closed
255
+ */
256
+ requestId(): string;
257
+ /**
258
+ * Returns the connect URL for World App
259
+ *
260
+ * This URL should be displayed as a QR code for users to scan with World App.
261
+ *
262
+ * # Errors
263
+ *
264
+ * Returns an error if the request has been closed
265
+ */
266
+ connectUrl(): string;
267
+ /**
268
+ * Polls the bridge for the current status (non-blocking)
269
+ *
270
+ * Returns a status object with type:
271
+ * - `"waiting_for_connection"` - Waiting for World App to retrieve the request
272
+ * - `"awaiting_confirmation"` - World App has retrieved the request, waiting for user
273
+ * - `"confirmed"` - User confirmed and provided a proof
274
+ * - `"failed"` - Request has failed
275
+ *
276
+ * # Errors
277
+ *
278
+ * Returns an error if the request fails or the response is invalid
279
+ */
280
+ pollForStatus(): Promise<any>;
281
+ }
282
+ /**
283
+ * Builder for creating `IDKit` requests (WASM)
284
+ */
285
+ export class IDKitRequestBuilderWasm {
286
+ free(): void;
287
+ [Symbol.dispose](): void;
288
+ /**
289
+ * Creates an `IDKit` request with the given constraints
290
+ *
291
+ * # Arguments
292
+ * * `constraints_json` - Constraint tree as JSON (`CredentialRequest` or `{any: []}` or `{all: []}`)
293
+ *
294
+ * # Errors
295
+ *
296
+ * Returns an error if the request cannot be created
297
+ */
298
+ constraints(constraints_json: any): Promise<any>;
299
+ /**
300
+ * Creates a new `IDKitRequestBuilder`
301
+ *
302
+ * # Arguments
303
+ * * `app_id` - Application ID from the Developer Portal
304
+ * * `action` - Action identifier
305
+ * * `rp_context` - RP context for building protocol-level `ProofRequest`
306
+ * * `action_description` - Optional action description shown to users
307
+ * * `bridge_url` - Optional bridge URL (defaults to production)
308
+ */
309
+ constructor(app_id: string, action: string, rp_context: RpContextWasm, action_description?: string | null, bridge_url?: string | null);
310
+ /**
311
+ * Creates an `IDKit` request from a preset
312
+ *
313
+ * Presets provide a simplified way to create requests with predefined
314
+ * credential configurations. The preset is converted to both World ID 4.0
315
+ * constraints and World ID 3.0 legacy fields for backward compatibility.
316
+ *
317
+ * # Arguments
318
+ * * `preset_json` - Preset object from `orbLegacy()`
319
+ *
320
+ * # Errors
321
+ *
322
+ * Returns an error if the request cannot be created
323
+ */
324
+ preset(preset_json: any): Promise<any>;
325
+ }
326
+ /**
327
+ * RP Context for protocol-level proof requests (WASM binding)
328
+ *
329
+ * Contains RP-specific data needed to construct a `ProofRequest`.
330
+ */
331
+ export class RpContextWasm {
332
+ free(): void;
333
+ [Symbol.dispose](): void;
334
+ /**
335
+ * Creates a new RP context
336
+ *
337
+ * # Arguments
338
+ * * `rp_id` - The registered RP ID (e.g., `"rp_123456789abcdef0"`)
339
+ * * `nonce` - Unique nonce for this proof request
340
+ * * `created_at` - Unix timestamp (seconds since epoch) when created
341
+ * * `expires_at` - Unix timestamp (seconds since epoch) when expires
342
+ * * `signature` - The RP's ECDSA signature of the `nonce` and `created_at` timestamp
343
+ *
344
+ * # Errors
345
+ *
346
+ * Returns an error if `rp_id` is not a valid RP ID (must start with `rp_`)
347
+ */
348
+ constructor(rp_id: string, nonce: string, created_at: bigint, expires_at: bigint, signature: string);
349
+ }
350
+ export class RpSignature {
351
+ private constructor();
352
+ free(): void;
353
+ [Symbol.dispose](): void;
354
+ /**
355
+ * Converts to JSON
356
+ *
357
+ * # Errors
358
+ *
359
+ * Returns an error if setting object properties fails
360
+ */
361
+ toJSON(): any;
362
+ /**
363
+ * Gets the creation timestamp
364
+ */
365
+ readonly createdAt: bigint;
366
+ /**
367
+ * Gets the expiration timestamp
368
+ */
369
+ readonly expiresAt: bigint;
370
+ /**
371
+ * Gets the signature as hex string (0x-prefixed, 65 bytes)
372
+ */
373
+ readonly sig: string;
374
+ /**
375
+ * Gets the nonce as hex string (0x-prefixed field element)
376
+ */
377
+ readonly nonce: string;
378
+ }
379
+
380
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
381
+
382
+ export interface InitOutput {
383
+ readonly memory: WebAssembly.Memory;
384
+ readonly __wbg_bridgeencryption_free: (a: number, b: number) => void;
385
+ readonly __wbg_credentialrequestwasm_free: (a: number, b: number) => void;
386
+ readonly __wbg_idkitproof_free: (a: number, b: number) => void;
387
+ readonly __wbg_idkitrequest_free: (a: number, b: number) => void;
388
+ readonly __wbg_idkitrequestbuilderwasm_free: (a: number, b: number) => void;
389
+ readonly __wbg_rpcontextwasm_free: (a: number, b: number) => void;
390
+ readonly __wbg_rpsignature_free: (a: number, b: number) => void;
391
+ readonly base64Decode: (a: number, b: number, c: number) => void;
392
+ readonly base64Encode: (a: number, b: number, c: number) => void;
393
+ readonly bridgeencryption_decrypt: (a: number, b: number, c: number, d: number) => void;
394
+ readonly bridgeencryption_encrypt: (a: number, b: number, c: number, d: number) => void;
395
+ readonly bridgeencryption_keyBase64: (a: number, b: number) => void;
396
+ readonly bridgeencryption_new: (a: number) => void;
397
+ readonly bridgeencryption_nonceBase64: (a: number, b: number) => void;
398
+ readonly credentialrequestwasm_credentialType: (a: number) => number;
399
+ readonly credentialrequestwasm_getSignalBytes: (a: number, b: number) => void;
400
+ readonly credentialrequestwasm_new: (a: number, b: number, c: number, d: number) => void;
401
+ readonly credentialrequestwasm_toJSON: (a: number, b: number) => void;
402
+ readonly credentialrequestwasm_withBytes: (a: number, b: number, c: number, d: number) => void;
403
+ readonly credentialrequestwasm_withGenesisMin: (a: number, b: number, c: number, d: number, e: bigint) => void;
404
+ readonly hashSignal: (a: number, b: number, c: number) => void;
405
+ readonly idkitproof_new: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
406
+ readonly idkitproof_toJSON: (a: number, b: number) => void;
407
+ readonly idkitrequest_connectUrl: (a: number, b: number) => void;
408
+ readonly idkitrequest_pollForStatus: (a: number) => number;
409
+ readonly idkitrequest_requestId: (a: number, b: number) => void;
410
+ readonly idkitrequestbuilderwasm_constraints: (a: number, b: number) => number;
411
+ readonly idkitrequestbuilderwasm_new: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => number;
412
+ readonly idkitrequestbuilderwasm_preset: (a: number, b: number) => number;
413
+ readonly orbLegacy: (a: number, b: number, c: number) => void;
414
+ readonly rpcontextwasm_new: (a: number, b: number, c: number, d: number, e: number, f: bigint, g: bigint, h: number, i: number) => void;
415
+ readonly rpsignature_createdAt: (a: number) => bigint;
416
+ readonly rpsignature_expiresAt: (a: number) => bigint;
417
+ readonly rpsignature_nonce: (a: number, b: number) => void;
418
+ readonly rpsignature_sig: (a: number, b: number) => void;
419
+ readonly rpsignature_toJSON: (a: number, b: number) => void;
420
+ readonly signRequest: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint) => void;
421
+ readonly init_wasm: () => void;
422
+ readonly hashSignalBytes: (a: number, b: number, c: number) => void;
423
+ readonly request: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => number;
424
+ readonly __wasm_bindgen_func_elem_510: (a: number, b: number) => void;
425
+ readonly __wasm_bindgen_func_elem_509: (a: number, b: number) => void;
426
+ readonly __wasm_bindgen_func_elem_873: (a: number, b: number, c: number) => void;
427
+ readonly __wasm_bindgen_func_elem_872: (a: number, b: number) => void;
428
+ readonly __wasm_bindgen_func_elem_1238: (a: number, b: number, c: number, d: number) => void;
429
+ readonly __wbindgen_export: (a: number, b: number) => number;
430
+ readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
431
+ readonly __wbindgen_export3: (a: number) => void;
432
+ readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
433
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
434
+ readonly __wbindgen_start: () => void;
435
+ }
436
+
437
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
438
+ /**
439
+ * Instantiates the given `module`, which can either be bytes or
440
+ * a precompiled `WebAssembly.Module`.
441
+ *
442
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
443
+ *
444
+ * @returns {InitOutput}
445
+ */
446
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
447
+
448
+ /**
449
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
450
+ * for everything else, calls `WebAssembly.instantiate` directly.
451
+ *
452
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
453
+ *
454
+ * @returns {Promise<InitOutput>}
455
+ */
456
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;