@worldcoin/idkit-core 2.0.2 → 4.0.0-dev.777cdbe
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 +101 -0
- package/dist/idkit_wasm_bg.wasm +0 -0
- package/dist/index.cjs +2113 -0
- package/dist/index.d.cts +763 -0
- package/dist/index.d.ts +763 -0
- package/dist/index.js +2098 -0
- package/package.json +34 -62
- package/LICENSE +0 -7
- package/build/chunk-HZ2SQA5V.js +0 -50
- package/build/config-fuwC_Hia.d.cts +0 -41
- package/build/config-fuwC_Hia.d.ts +0 -41
- package/build/index.cjs +0 -331
- package/build/index.d.cts +0 -30
- package/build/index.d.ts +0 -30
- package/build/index.js +0 -266
- package/build/lib/backend.cjs +0 -70
- package/build/lib/backend.d.cts +0 -12
- package/build/lib/backend.d.ts +0 -12
- package/build/lib/backend.js +0 -30
- package/build/lib/hashing.cjs +0 -78
- package/build/lib/hashing.d.cts +0 -21
- package/build/lib/hashing.d.ts +0 -21
- package/build/lib/hashing.js +0 -14
- package/build/result-BZ4QXOc2.d.cts +0 -35
- package/build/result-CqgtArQe.d.ts +0 -35
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,763 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration types for IDKit
|
|
3
|
+
*
|
|
4
|
+
* Note: CredentialType, CredentialRequestType, and ConstraintNode are now
|
|
5
|
+
* re-exported from WASM (source of truth: rust/core/src/wasm_bindings.rs)
|
|
6
|
+
*/
|
|
7
|
+
declare const brand: unique symbol;
|
|
8
|
+
type Brand<T, TBrand extends string> = T & {
|
|
9
|
+
[brand]: TBrand;
|
|
10
|
+
};
|
|
11
|
+
type AbiEncodedValue = Brand<{
|
|
12
|
+
types: string[];
|
|
13
|
+
values: unknown[];
|
|
14
|
+
}, "AbiEncodedValue">;
|
|
15
|
+
/**
|
|
16
|
+
* Relying Party context for IDKit requests
|
|
17
|
+
*
|
|
18
|
+
* Contains RP-specific data needed to construct a ProofRequest.
|
|
19
|
+
* This should be generated and signed by your backend.
|
|
20
|
+
*/
|
|
21
|
+
type RpContext = {
|
|
22
|
+
/** The registered RP ID (e.g., "rp_123456789abcdef0") */
|
|
23
|
+
rp_id: string;
|
|
24
|
+
/** Unique nonce for this proof request */
|
|
25
|
+
nonce: string;
|
|
26
|
+
/** Unix timestamp (seconds since epoch) when created */
|
|
27
|
+
created_at: number;
|
|
28
|
+
/** Unix timestamp (seconds since epoch) when expires */
|
|
29
|
+
expires_at: number;
|
|
30
|
+
/** The RP's ECDSA signature of the nonce and created_at timestamp */
|
|
31
|
+
signature: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Configuration for IDKit.request()
|
|
35
|
+
*/
|
|
36
|
+
type IDKitRequestConfig = {
|
|
37
|
+
/** Unique identifier for the app verifying the action. This should be the app ID obtained from the Developer Portal. */
|
|
38
|
+
app_id: `app_${string}`;
|
|
39
|
+
/** Identifier for the action the user is performing. Should be left blank for [Sign in with Worldcoin](https://docs.world.org/id/sign-in). */
|
|
40
|
+
action: AbiEncodedValue | string;
|
|
41
|
+
/** RP context for protocol-level proof requests (required) */
|
|
42
|
+
rp_context: RpContext;
|
|
43
|
+
/** The description of the specific action (shown to users in World App). Only recommended for actions created on-the-fly. */
|
|
44
|
+
action_description?: string;
|
|
45
|
+
/** URL to a third-party bridge to use when connecting to the World App. Optional. */
|
|
46
|
+
bridge_url?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Whether to accept legacy (v3) World ID proofs as fallback.
|
|
49
|
+
*
|
|
50
|
+
* - `true`: Accept both v3 and v4 proofs. Use during migration.
|
|
51
|
+
* You must track both v3 and v4 nullifiers to prevent double-claims.
|
|
52
|
+
* - `false`: Only accept v4 proofs. Use after migration cutoff or for new apps.
|
|
53
|
+
*/
|
|
54
|
+
allow_legacy_proofs: boolean;
|
|
55
|
+
/** Optional override for the connect base URL (e.g., for staging environments) */
|
|
56
|
+
override_connect_base_url?: string;
|
|
57
|
+
/** Optional environment override. Defaults to "production". */
|
|
58
|
+
environment?: "production" | "staging";
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Configuration for IDKit.createSession() and IDKit.proveSession()
|
|
62
|
+
*
|
|
63
|
+
* Session requests don't have an action field - they're used for session-based
|
|
64
|
+
* authentication where the user proves they're the same person across visits.
|
|
65
|
+
*
|
|
66
|
+
* Sessions are always World ID v4 - there is no legacy (v3) session support.
|
|
67
|
+
*/
|
|
68
|
+
type IDKitSessionConfig = {
|
|
69
|
+
/** Unique identifier for the app verifying the session. This should be the app ID obtained from the Developer Portal. */
|
|
70
|
+
app_id: `app_${string}`;
|
|
71
|
+
/** RP context for protocol-level proof requests (required) */
|
|
72
|
+
rp_context: RpContext;
|
|
73
|
+
/** The description of the action (shown to users in World App). Optional. */
|
|
74
|
+
action_description?: string;
|
|
75
|
+
/** URL to a third-party bridge to use when connecting to the World App. Optional. */
|
|
76
|
+
bridge_url?: string;
|
|
77
|
+
/** Optional override for the connect base URL (e.g., for staging environments) */
|
|
78
|
+
override_connect_base_url?: string;
|
|
79
|
+
/** Optional environment override. Defaults to "production". */
|
|
80
|
+
environment?: "production" | "staging";
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
type CredentialType = "orb" | "face" | "secure_document" | "document" | "device";
|
|
84
|
+
|
|
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
|
+
}
|
|
92
|
+
|
|
93
|
+
type ConstraintNode =
|
|
94
|
+
| CredentialRequestType
|
|
95
|
+
| { any: ConstraintNode[] }
|
|
96
|
+
| { all: ConstraintNode[] };
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
/** V4 response item for World ID v4 uniqueness proofs */
|
|
101
|
+
interface ResponseItemV4 {
|
|
102
|
+
/** Credential identifier (e.g., "orb", "face", "document") */
|
|
103
|
+
identifier: string;
|
|
104
|
+
/** Signal hash (optional, included if signal was provided in request) */
|
|
105
|
+
signal_hash?: string;
|
|
106
|
+
/** Encoded World ID proof: first 4 elements are compressed Groth16 proof, 5th is Merkle root (hex strings). Compatible with WorldIDVerifier.sol */
|
|
107
|
+
proof: string[];
|
|
108
|
+
/** RP-scoped nullifier (hex) */
|
|
109
|
+
nullifier: string;
|
|
110
|
+
/** Credential issuer schema ID (1=orb, 2=face, 3=secure_document, 4=document, 5=device) */
|
|
111
|
+
issuer_schema_id: number;
|
|
112
|
+
/** Minimum expiration timestamp (unix seconds) */
|
|
113
|
+
expires_at_min: number;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** V3 response item for World ID v3 (legacy format) */
|
|
117
|
+
interface ResponseItemV3 {
|
|
118
|
+
/** Credential identifier (e.g., "orb", "face") */
|
|
119
|
+
identifier: string;
|
|
120
|
+
/** Signal hash (optional, included if signal was provided in request) */
|
|
121
|
+
signal_hash?: string;
|
|
122
|
+
/** ABI-encoded proof (hex) */
|
|
123
|
+
proof: string;
|
|
124
|
+
/** Merkle root (hex) */
|
|
125
|
+
merkle_root: string;
|
|
126
|
+
/** Nullifier (hex) */
|
|
127
|
+
nullifier: string;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Session response item for World ID v4 session proofs */
|
|
131
|
+
interface ResponseItemSession {
|
|
132
|
+
/** Credential identifier (e.g., "orb", "face", "document") */
|
|
133
|
+
identifier: string;
|
|
134
|
+
/** Signal hash (optional, included if signal was provided in request) */
|
|
135
|
+
signal_hash?: string;
|
|
136
|
+
/** Encoded World ID proof: first 4 elements are compressed Groth16 proof, 5th is Merkle root (hex strings). Compatible with WorldIDVerifier.sol */
|
|
137
|
+
proof: string[];
|
|
138
|
+
/** Session nullifier: 1st element is the session nullifier, 2nd is the generated action (hex strings) */
|
|
139
|
+
session_nullifier: string[];
|
|
140
|
+
/** Credential issuer schema ID (1=orb, 2=face, 3=secure_document, 4=document, 5=device) */
|
|
141
|
+
issuer_schema_id: number;
|
|
142
|
+
/** Minimum expiration timestamp (unix seconds) */
|
|
143
|
+
expires_at_min: number;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** V3 result (legacy format - no session support) */
|
|
147
|
+
interface IDKitResultV3 {
|
|
148
|
+
/** Protocol version 3.0 */
|
|
149
|
+
protocol_version: "3.0";
|
|
150
|
+
/** Nonce used in the request */
|
|
151
|
+
nonce: string;
|
|
152
|
+
/** Action identifier (only for uniqueness proofs) */
|
|
153
|
+
action?: string;
|
|
154
|
+
/** Action description (only if provided in input) */
|
|
155
|
+
action_description?: string;
|
|
156
|
+
/** Array of V3 credential responses */
|
|
157
|
+
responses: ResponseItemV3[];
|
|
158
|
+
/** The environment used for this request ("production" or "staging") */
|
|
159
|
+
environment: string;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** V4 result for uniqueness proofs */
|
|
163
|
+
interface IDKitResultV4 {
|
|
164
|
+
/** Protocol version 4.0 */
|
|
165
|
+
protocol_version: "4.0";
|
|
166
|
+
/** Nonce used in the request */
|
|
167
|
+
nonce: string;
|
|
168
|
+
/** Action identifier (required for uniqueness proofs) */
|
|
169
|
+
action: string;
|
|
170
|
+
/** Action description (only if provided in input) */
|
|
171
|
+
action_description?: string;
|
|
172
|
+
/** Array of V4 credential responses */
|
|
173
|
+
responses: ResponseItemV4[];
|
|
174
|
+
/** The environment used for this request ("production" or "staging") */
|
|
175
|
+
environment: string;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** V4 result for session proofs */
|
|
179
|
+
interface IDKitResultSession {
|
|
180
|
+
/** Protocol version 4.0 */
|
|
181
|
+
protocol_version: "4.0";
|
|
182
|
+
/** Nonce used in the request */
|
|
183
|
+
nonce: string;
|
|
184
|
+
/** Action description (only if provided in input) */
|
|
185
|
+
action_description?: string;
|
|
186
|
+
/** Session ID returned by the World App */
|
|
187
|
+
session_id: string;
|
|
188
|
+
/** Array of session credential responses */
|
|
189
|
+
responses: ResponseItemSession[];
|
|
190
|
+
/** The environment used for this request ("production" or "staging") */
|
|
191
|
+
environment: string;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* The unified result structure for all proof types.
|
|
196
|
+
* Check `session_id` to determine if this is a session proof:
|
|
197
|
+
* - session_id !== undefined → session proof
|
|
198
|
+
* - session_id === undefined → uniqueness proof
|
|
199
|
+
*/
|
|
200
|
+
type IDKitResult = IDKitResultV3 | IDKitResultV4 | IDKitResultSession;
|
|
201
|
+
|
|
202
|
+
/** Error codes from World App (mirrors Rust AppError) */
|
|
203
|
+
type IDKitErrorCode =
|
|
204
|
+
| "user_rejected"
|
|
205
|
+
| "verification_rejected"
|
|
206
|
+
| "credential_unavailable"
|
|
207
|
+
| "malformed_request"
|
|
208
|
+
| "invalid_network"
|
|
209
|
+
| "inclusion_proof_pending"
|
|
210
|
+
| "inclusion_proof_failed"
|
|
211
|
+
| "unexpected_response"
|
|
212
|
+
| "connection_failed"
|
|
213
|
+
| "max_verifications_reached"
|
|
214
|
+
| "failed_by_host_app"
|
|
215
|
+
| "generic_error";
|
|
216
|
+
|
|
217
|
+
/** Status returned from pollForStatus() */
|
|
218
|
+
type Status$1 =
|
|
219
|
+
| { type: "waiting_for_connection" }
|
|
220
|
+
| { type: "awaiting_confirmation" }
|
|
221
|
+
| { type: "confirmed"; result: IDKitResult }
|
|
222
|
+
| { type: "failed"; error: IDKitErrorCode };
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
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
|
+
|
|
295
|
+
|
|
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;
|
|
331
|
+
}
|
|
332
|
+
|
|
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>;
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Result types - re-exported from WASM bindings
|
|
354
|
+
*
|
|
355
|
+
* Source of truth: rust/core/src/wasm_bindings.rs (typescript_custom_section)
|
|
356
|
+
*/
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* IDKit error codes enum — runtime values for matching against errors.
|
|
360
|
+
* Values mirror Rust's AppError enum (snake_case via serde rename_all).
|
|
361
|
+
* Includes client-side codes (timeout, cancelled) not from World App.
|
|
362
|
+
*/
|
|
363
|
+
declare enum IDKitErrorCodes {
|
|
364
|
+
UserRejected = "user_rejected",
|
|
365
|
+
VerificationRejected = "verification_rejected",
|
|
366
|
+
CredentialUnavailable = "credential_unavailable",
|
|
367
|
+
MalformedRequest = "malformed_request",
|
|
368
|
+
InvalidNetwork = "invalid_network",
|
|
369
|
+
InclusionProofPending = "inclusion_proof_pending",
|
|
370
|
+
InclusionProofFailed = "inclusion_proof_failed",
|
|
371
|
+
UnexpectedResponse = "unexpected_response",
|
|
372
|
+
ConnectionFailed = "connection_failed",
|
|
373
|
+
MaxVerificationsReached = "max_verifications_reached",
|
|
374
|
+
FailedByHostApp = "failed_by_host_app",
|
|
375
|
+
GenericError = "generic_error",
|
|
376
|
+
Timeout = "timeout",
|
|
377
|
+
Cancelled = "cancelled"
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* IDKit Request
|
|
382
|
+
* Pure functional API for World ID verification - no dependencies
|
|
383
|
+
*/
|
|
384
|
+
|
|
385
|
+
/** Options for pollUntilCompletion() */
|
|
386
|
+
interface WaitOptions {
|
|
387
|
+
/** Milliseconds between polls (default: 1000) */
|
|
388
|
+
pollInterval?: number;
|
|
389
|
+
/** Total timeout in milliseconds (default: 300000 = 5 minutes) */
|
|
390
|
+
timeout?: number;
|
|
391
|
+
/** AbortSignal for cancellation */
|
|
392
|
+
signal?: AbortSignal;
|
|
393
|
+
}
|
|
394
|
+
/** Status returned from pollOnce() */
|
|
395
|
+
interface Status {
|
|
396
|
+
type: "waiting_for_connection" | "awaiting_confirmation" | "confirmed" | "failed";
|
|
397
|
+
result?: IDKitResult;
|
|
398
|
+
error?: IDKitErrorCodes;
|
|
399
|
+
}
|
|
400
|
+
/** Result from pollUntilCompletion() — discriminated union, never throws */
|
|
401
|
+
type IDKitCompletionResult = {
|
|
402
|
+
success: true;
|
|
403
|
+
result: IDKitResult;
|
|
404
|
+
} | {
|
|
405
|
+
success: false;
|
|
406
|
+
error: IDKitErrorCodes;
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* A World ID verification request
|
|
411
|
+
*
|
|
412
|
+
* Provides a clean, promise-based API for World ID verification flows.
|
|
413
|
+
* Each request represents a single verification attempt.
|
|
414
|
+
*/
|
|
415
|
+
interface IDKitRequest {
|
|
416
|
+
/** QR code URL for World App - display this as a QR code for users to scan */
|
|
417
|
+
readonly connectorURI: string;
|
|
418
|
+
/** Unique request ID for this verification */
|
|
419
|
+
readonly requestId: string;
|
|
420
|
+
/** Poll once for current status (for manual polling) */
|
|
421
|
+
pollOnce(): Promise<Status>;
|
|
422
|
+
/** Poll continuously until completion or timeout */
|
|
423
|
+
pollUntilCompletion(options?: WaitOptions): Promise<IDKitCompletionResult>;
|
|
424
|
+
}
|
|
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
|
+
/**
|
|
475
|
+
* Creates an OrbLegacy preset for World ID 3.0 legacy support
|
|
476
|
+
*
|
|
477
|
+
* This preset creates an IDKit request compatible with both World ID 4.0 and 3.0 protocols.
|
|
478
|
+
* Use this when you need backward compatibility with older World App versions.
|
|
479
|
+
*
|
|
480
|
+
* @param opts - Optional configuration with signal
|
|
481
|
+
* @returns An OrbLegacy preset
|
|
482
|
+
*
|
|
483
|
+
* @example
|
|
484
|
+
* ```typescript
|
|
485
|
+
* const request = await IDKit.request({ app_id, action, rp_context })
|
|
486
|
+
* .preset(orbLegacy({ signal: 'user-123' }))
|
|
487
|
+
* ```
|
|
488
|
+
*/
|
|
489
|
+
declare function orbLegacy(opts?: {
|
|
490
|
+
signal?: string;
|
|
491
|
+
}): OrbLegacyPreset;
|
|
492
|
+
/**
|
|
493
|
+
* Creates a SecureDocumentLegacy preset for World ID 3.0 legacy support
|
|
494
|
+
*
|
|
495
|
+
* This preset creates an IDKit request compatible with both World ID 4.0 and 3.0 protocols.
|
|
496
|
+
* Use this when you need backward compatibility with older World App versions.
|
|
497
|
+
*
|
|
498
|
+
* @param opts - Optional configuration with signal
|
|
499
|
+
* @returns A SecureDocumentLegacy preset
|
|
500
|
+
*
|
|
501
|
+
* @example
|
|
502
|
+
* ```typescript
|
|
503
|
+
* const request = await IDKit.request({ app_id, action, rp_context })
|
|
504
|
+
* .preset(secureDocumentLegacy({ signal: 'user-123' }))
|
|
505
|
+
* ```
|
|
506
|
+
*/
|
|
507
|
+
declare function secureDocumentLegacy(opts?: {
|
|
508
|
+
signal?: string;
|
|
509
|
+
}): SecureDocumentLegacyPreset;
|
|
510
|
+
/**
|
|
511
|
+
* Creates a DocumentLegacy preset for World ID 3.0 legacy support
|
|
512
|
+
*
|
|
513
|
+
* This preset creates an IDKit request compatible with both World ID 4.0 and 3.0 protocols.
|
|
514
|
+
* Use this when you need backward compatibility with older World App versions.
|
|
515
|
+
*
|
|
516
|
+
* @param opts - Optional configuration with signal
|
|
517
|
+
* @returns A DocumentLegacy preset
|
|
518
|
+
*
|
|
519
|
+
* @example
|
|
520
|
+
* ```typescript
|
|
521
|
+
* const request = await IDKit.request({ app_id, action, rp_context })
|
|
522
|
+
* .preset(documentLegacy({ signal: 'user-123' }))
|
|
523
|
+
* ```
|
|
524
|
+
*/
|
|
525
|
+
declare function documentLegacy(opts?: {
|
|
526
|
+
signal?: string;
|
|
527
|
+
}): DocumentLegacyPreset;
|
|
528
|
+
/**
|
|
529
|
+
* Merged builder for IDKit requests
|
|
530
|
+
*/
|
|
531
|
+
declare class IDKitBuilder {
|
|
532
|
+
private wasmBuilder;
|
|
533
|
+
constructor(wasmBuilder: IDKitBuilder$1);
|
|
534
|
+
/**
|
|
535
|
+
* Creates an IDKit request with the given constraints
|
|
536
|
+
*
|
|
537
|
+
* @param constraints - Constraint tree (CredentialRequest or any/all combinators)
|
|
538
|
+
* @returns A new IDKitRequest instance
|
|
539
|
+
*
|
|
540
|
+
* @example
|
|
541
|
+
* ```typescript
|
|
542
|
+
* const builder = await IDKit.request({ app_id, action, rp_context });
|
|
543
|
+
* const request = await builder.constraints(any(CredentialRequest('orb'), CredentialRequest('face')));
|
|
544
|
+
* ```
|
|
545
|
+
*/
|
|
546
|
+
/**
|
|
547
|
+
* Creates an IDKit request from a preset (works for all request types)
|
|
548
|
+
*
|
|
549
|
+
* Presets provide a simplified way to create requests with predefined
|
|
550
|
+
* credential configurations.
|
|
551
|
+
*
|
|
552
|
+
* @param preset - A preset object from orbLegacy()
|
|
553
|
+
* @returns A new IDKitRequest instance
|
|
554
|
+
*
|
|
555
|
+
* @example
|
|
556
|
+
* ```typescript
|
|
557
|
+
* const builder = await IDKit.request({ app_id, action, rp_context });
|
|
558
|
+
* const request = await builder.preset(orbLegacy({ signal: 'user-123' }));
|
|
559
|
+
* ```
|
|
560
|
+
*/
|
|
561
|
+
preset(preset: Preset): Promise<IDKitRequest>;
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Creates an IDKit request builder
|
|
565
|
+
*
|
|
566
|
+
* 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.
|
|
568
|
+
*
|
|
569
|
+
* @param config - Request configuration
|
|
570
|
+
* @returns IDKitBuilder - A builder instance
|
|
571
|
+
*
|
|
572
|
+
* @example
|
|
573
|
+
* ```typescript
|
|
574
|
+
* import { IDKit, CredentialRequest, any } from '@worldcoin/idkit-core'
|
|
575
|
+
*
|
|
576
|
+
* // Initialize WASM (only needed once)
|
|
577
|
+
* await IDKit.init()
|
|
578
|
+
*
|
|
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
|
|
584
|
+
* const request = await IDKit.request({
|
|
585
|
+
* app_id: 'app_staging_xxxxx',
|
|
586
|
+
* 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
|
+
* 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)
|
|
635
|
+
*
|
|
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, {
|
|
649
|
+
* app_id: 'app_staging_xxxxx',
|
|
650
|
+
* rp_context: { ... },
|
|
651
|
+
* }).constraints(any(CredentialRequest('orb'), CredentialRequest('face')));
|
|
652
|
+
*
|
|
653
|
+
* const result = await request.pollUntilCompletion();
|
|
654
|
+
* // result.session_id -> same session
|
|
655
|
+
* // result.responses[0].session_nullifier -> should match for same user
|
|
656
|
+
* ```
|
|
657
|
+
*/
|
|
658
|
+
declare function proveSession(sessionId: string, config: IDKitSessionConfig): IDKitBuilder;
|
|
659
|
+
/**
|
|
660
|
+
* IDKit namespace providing the main API entry points
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
663
|
+
* ```typescript
|
|
664
|
+
* import { IDKit, CredentialRequest, any } from '@worldcoin/idkit-core'
|
|
665
|
+
*
|
|
666
|
+
* // Initialize (only needed once)
|
|
667
|
+
* await IDKit.init()
|
|
668
|
+
*
|
|
669
|
+
* // Create a request
|
|
670
|
+
* const request = await IDKit.request({
|
|
671
|
+
* app_id: 'app_staging_xxxxx',
|
|
672
|
+
* action: 'my-action',
|
|
673
|
+
* rp_context: { ... },
|
|
674
|
+
* }).constraints(any(CredentialRequest('orb'), CredentialRequest('face')))
|
|
675
|
+
*
|
|
676
|
+
* // Display QR and wait for proof
|
|
677
|
+
* console.log(request.connectorURI)
|
|
678
|
+
* const proof = await request.pollUntilCompletion()
|
|
679
|
+
* ```
|
|
680
|
+
*/
|
|
681
|
+
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
|
+
/** Create a new verification request */
|
|
687
|
+
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
|
+
/** Create an OrbLegacy preset for World ID 3.0 legacy support */
|
|
699
|
+
orbLegacy: typeof orbLegacy;
|
|
700
|
+
/** Create a SecureDocumentLegacy preset for World ID 3.0 legacy support */
|
|
701
|
+
secureDocumentLegacy: typeof secureDocumentLegacy;
|
|
702
|
+
/** Create a DocumentLegacy preset for World ID 3.0 legacy support */
|
|
703
|
+
documentLegacy: typeof documentLegacy;
|
|
704
|
+
};
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* Platform detection utilities
|
|
708
|
+
*
|
|
709
|
+
* These functions help detect the runtime environment (React Native, Web, Node.js)
|
|
710
|
+
* to enable platform-specific behavior or warnings.
|
|
711
|
+
*/
|
|
712
|
+
/**
|
|
713
|
+
* Checks if the code is running in React Native environment
|
|
714
|
+
* @returns true if running in React Native, false otherwise
|
|
715
|
+
*/
|
|
716
|
+
declare const isReactNative: () => boolean;
|
|
717
|
+
/**
|
|
718
|
+
* Checks if the code is running in a web browser environment
|
|
719
|
+
* @returns true if running in a browser, false otherwise
|
|
720
|
+
*/
|
|
721
|
+
declare const isWeb: () => boolean;
|
|
722
|
+
/**
|
|
723
|
+
* Checks if the code is running in Node.js environment
|
|
724
|
+
* @returns true if running in Node.js, false otherwise
|
|
725
|
+
*/
|
|
726
|
+
declare const isNode: () => boolean;
|
|
727
|
+
|
|
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 };
|