@reclaimprotocol/js-sdk 4.5.2 → 4.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -66,6 +66,22 @@ type ProofRequestOptions = {
66
66
  providerVersion?: string;
67
67
  customSharePageUrl?: string;
68
68
  customAppClipUrl?: string;
69
+ launchOptions?: ReclaimFlowLaunchOptions;
70
+ };
71
+ type ReclaimFlowLaunchOptions = {
72
+ /**
73
+ * Enables deferred deep links for the Reclaim verification flow.
74
+ *
75
+ * When enabled, users without the verifier app installed will receive a deferred deep link
76
+ * that automatically launches the verification flow after they install the app, ensuring
77
+ * a seamless continuation of the verification process.
78
+ *
79
+ * **Platform Support:** Currently Android only
80
+ *
81
+ * **Default Behavior:** Opt-in during rollout phase. Will default to `true` for all apps
82
+ * once fully released. See: https://blog.reclaimprotocol.org/posts/moving-beyond-google-play-instant
83
+ */
84
+ canUseDeferredDeepLinksFlow?: boolean;
69
85
  };
70
86
  type ModalOptions = {
71
87
  title?: string;
@@ -87,7 +103,35 @@ declare enum DeviceType {
87
103
  MOBILE = "mobile"
88
104
  }
89
105
 
106
+ /**
107
+ * Verifies one or more Reclaim proofs by validating signatures and witness information
108
+ *
109
+ * @param proofOrProofs - A single proof object or an array of proof objects to verify
110
+ * @param allowAiWitness - Optional flag to allow AI witness verification. Defaults to false
111
+ * @returns Promise<boolean> - Returns true if all proofs are valid, false otherwise
112
+ * @throws {SignatureNotFoundError} When proof has no signatures
113
+ * @throws {ProofNotVerifiedError} When identifier mismatch occurs
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * const isValid = await verifyProof(proof);
118
+ * const areAllValid = await verifyProof([proof1, proof2, proof3]);
119
+ * const isValidWithAI = await verifyProof(proof, true);
120
+ * ```
121
+ */
90
122
  declare function verifyProof(proofOrProofs: Proof | Proof[], allowAiWitness?: boolean): Promise<boolean>;
123
+ /**
124
+ * Transforms a Reclaim proof into a format suitable for on-chain verification
125
+ *
126
+ * @param proof - The proof object to transform
127
+ * @returns Object containing claimInfo and signedClaim formatted for blockchain contracts
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * const { claimInfo, signedClaim } = transformForOnchain(proof);
132
+ * // Use claimInfo and signedClaim with smart contract verification
133
+ * ```
134
+ */
91
135
  declare function transformForOnchain(proof: Proof): {
92
136
  claimInfo: any;
93
137
  signedClaim: any;
@@ -117,33 +161,344 @@ declare class ReclaimProofRequest {
117
161
  private modal?;
118
162
  private readonly FAILURE_TIMEOUT;
119
163
  private constructor();
164
+ /**
165
+ * Initializes a new Reclaim proof request instance with automatic signature generation and session creation
166
+ *
167
+ * @param applicationId - Your Reclaim application ID
168
+ * @param appSecret - Your application secret key for signing requests
169
+ * @param providerId - The ID of the provider to use for proof generation
170
+ * @param options - Optional configuration options for the proof request
171
+ * @returns Promise<ReclaimProofRequest> - A fully initialized proof request instance
172
+ * @throws {InitError} When initialization fails due to invalid parameters or session creation errors
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * const proofRequest = await ReclaimProofRequest.init(
177
+ * 'your-app-id',
178
+ * 'your-app-secret',
179
+ * 'provider-id',
180
+ * { log: true, acceptAiProviders: true }
181
+ * );
182
+ * ```
183
+ */
120
184
  static init(applicationId: string, appSecret: string, providerId: string, options?: ProofRequestOptions): Promise<ReclaimProofRequest>;
185
+ /**
186
+ * Creates a ReclaimProofRequest instance from a JSON string representation
187
+ *
188
+ * This method deserializes a previously exported proof request (via toJsonString) and reconstructs
189
+ * the instance with all its properties. Useful for recreating requests on the frontend or across different contexts.
190
+ *
191
+ * @param jsonString - JSON string containing the serialized proof request data
192
+ * @returns {Promise<ReclaimProofRequest>} - Reconstructed proof request instance
193
+ * @throws {InvalidParamError} When JSON string is invalid or contains invalid parameters
194
+ *
195
+ * @example
196
+ * ```typescript
197
+ * const jsonString = proofRequest.toJsonString();
198
+ * const reconstructed = await ReclaimProofRequest.fromJsonString(jsonString);
199
+ * // Can also be used with InApp SDK's startVerificationFromJson method
200
+ * ```
201
+ */
121
202
  static fromJsonString(jsonString: string): Promise<ReclaimProofRequest>;
203
+ /**
204
+ * Sets a custom callback URL where proofs will be submitted via HTTP POST
205
+ *
206
+ * By default, proofs are posted as `application/x-www-form-urlencoded`.
207
+ * When a custom callback URL is set, Reclaim will no longer receive proofs upon submission,
208
+ * and listeners on the startSession method will not be triggered. Your application must
209
+ * coordinate with your backend to receive and verify proofs using verifyProof().
210
+ *
211
+ * Note: InApp SDKs are unaffected by this property as they do not handle proof submission.
212
+ *
213
+ * @param url - The URL where proofs should be submitted via HTTP POST
214
+ * @param jsonProofResponse - Optional. Set to true to submit proofs as `application/json`. Defaults to false
215
+ * @throws {InvalidParamError} When URL is invalid
216
+ *
217
+ * @example
218
+ * ```typescript
219
+ * proofRequest.setAppCallbackUrl('https://your-backend.com/callback');
220
+ * // Or with JSON format
221
+ * proofRequest.setAppCallbackUrl('https://your-backend.com/callback', true);
222
+ * ```
223
+ */
122
224
  setAppCallbackUrl(url: string, jsonProofResponse?: boolean): void;
225
+ /**
226
+ * Sets a redirect URL where users will be redirected after successfully acquiring and submitting proof
227
+ *
228
+ * @param url - The URL where users should be redirected after successful proof generation
229
+ * @throws {InvalidParamError} When URL is invalid
230
+ *
231
+ * @example
232
+ * ```typescript
233
+ * proofRequest.setRedirectUrl('https://your-app.com/success');
234
+ * ```
235
+ */
123
236
  setRedirectUrl(url: string): void;
237
+ /**
238
+ * Sets the claim creation type for the proof request
239
+ *
240
+ * @param claimCreationType - The type of claim creation (e.g., STANDALONE)
241
+ *
242
+ * @example
243
+ * ```typescript
244
+ * proofRequest.setClaimCreationType(ClaimCreationType.STANDALONE);
245
+ * ```
246
+ */
124
247
  setClaimCreationType(claimCreationType: ClaimCreationType): void;
248
+ /**
249
+ * Sets custom options for the QR code modal display
250
+ *
251
+ * @param options - Modal configuration options including title, description, theme, etc.
252
+ * @throws {SetParamsError} When modal options are invalid
253
+ *
254
+ * @example
255
+ * ```typescript
256
+ * proofRequest.setModalOptions({
257
+ * title: 'Scan QR Code',
258
+ * description: 'Scan with your mobile device',
259
+ * darkTheme: true
260
+ * });
261
+ * ```
262
+ */
125
263
  setModalOptions(options: ModalOptions): void;
264
+ /**
265
+ * Sets additional context data to be stored with the claim
266
+ *
267
+ * This allows you to associate custom data (address and message) with the proof claim.
268
+ * The context can be retrieved and validated when verifying the proof.
269
+ *
270
+ * Also see [setContext] which is an alternate way to set context that has an address & message.
271
+ *
272
+ * @param context - Any additional data you want to store with the claim. Should be serializable to a JSON string.
273
+ * @throws {SetContextError} When context parameters are invalid
274
+ *
275
+ * @example
276
+ * ```typescript
277
+ * proofRequest.setJsonContext({foo: 'bar'});
278
+ * ```
279
+ */
280
+ setJsonContext(context: Record<string, any>): void;
281
+ /**
282
+ * Sets additional context data to be stored with the claim
283
+ *
284
+ * This allows you to associate custom data (address and message) with the proof claim.
285
+ * The context can be retrieved and validated when verifying the proof.
286
+ *
287
+ * @param address - Context address identifier
288
+ * @param message - Additional data to associate with the address
289
+ * @throws {SetContextError} When context parameters are invalid
290
+ *
291
+ * @example
292
+ * ```typescript
293
+ * proofRequest.setContext('0x1234...', 'User verification for premium access');
294
+ * ```
295
+ */
126
296
  setContext(address: string, message: string): void;
297
+ /**
298
+ * @deprecated use setContext instead
299
+ *
300
+ * @param address
301
+ * @param message additional data you want associated with the [address]
302
+ */
127
303
  addContext(address: string, message: string): void;
304
+ /**
305
+ * Sets provider-specific parameters for the proof request
306
+ *
307
+ * These parameters are passed to the provider and may include configuration options,
308
+ * filters, or other provider-specific settings required for proof generation.
309
+ *
310
+ * @param params - Key-value pairs of parameters to set
311
+ * @throws {SetParamsError} When parameters are invalid
312
+ *
313
+ * @example
314
+ * ```typescript
315
+ * proofRequest.setParams({
316
+ * minFollowers: '1000',
317
+ * platform: 'twitter'
318
+ * });
319
+ * ```
320
+ */
128
321
  setParams(params: {
129
322
  [key: string]: string;
130
323
  }): void;
324
+ /**
325
+ * Returns the currently configured app callback URL
326
+ *
327
+ * If no custom callback URL was set via setAppCallbackUrl(), this returns the default
328
+ * Reclaim service callback URL with the current session ID.
329
+ *
330
+ * @returns The callback URL where proofs will be submitted
331
+ * @throws {GetAppCallbackUrlError} When unable to retrieve the callback URL
332
+ *
333
+ * @example
334
+ * ```typescript
335
+ * const callbackUrl = proofRequest.getAppCallbackUrl();
336
+ * console.log('Proofs will be sent to:', callbackUrl);
337
+ * ```
338
+ */
131
339
  getAppCallbackUrl(): string;
340
+ /**
341
+ * Returns the status URL for monitoring the current session
342
+ *
343
+ * This URL can be used to check the status of the proof request session.
344
+ *
345
+ * @returns The status monitoring URL for the current session
346
+ * @throws {GetStatusUrlError} When unable to retrieve the status URL
347
+ *
348
+ * @example
349
+ * ```typescript
350
+ * const statusUrl = proofRequest.getStatusUrl();
351
+ * // Use this URL to poll for session status updates
352
+ * ```
353
+ */
132
354
  getStatusUrl(): string;
355
+ /**
356
+ * Returns the session ID associated with this proof request
357
+ *
358
+ * The session ID is automatically generated during initialization and uniquely
359
+ * identifies this proof request session.
360
+ *
361
+ * @returns The session ID string
362
+ * @throws {SessionNotStartedError} When session ID is not set
363
+ *
364
+ * @example
365
+ * ```typescript
366
+ * const sessionId = proofRequest.getSessionId();
367
+ * console.log('Session ID:', sessionId);
368
+ * ```
369
+ */
133
370
  getSessionId(): string;
134
371
  private setSignature;
135
372
  private generateSignature;
136
373
  private clearInterval;
137
374
  private buildSharePageUrl;
375
+ /**
376
+ * Exports the Reclaim proof verification request as a JSON string
377
+ *
378
+ * This serialized format can be sent to the frontend to recreate this request using
379
+ * ReclaimProofRequest.fromJsonString() or any InApp SDK's startVerificationFromJson()
380
+ * method to initiate the verification journey.
381
+ *
382
+ * @returns JSON string representation of the proof request
383
+ *
384
+ * @example
385
+ * ```typescript
386
+ * const jsonString = proofRequest.toJsonString();
387
+ * // Send to frontend or store for later use
388
+ * // Can be reconstructed with: ReclaimProofRequest.fromJsonString(jsonString)
389
+ * ```
390
+ */
138
391
  toJsonString(): string;
139
- getRequestUrl(): Promise<string>;
140
- triggerReclaimFlow(): Promise<void>;
392
+ /**
393
+ * Validates signature and returns template data
394
+ * @returns
395
+ */
396
+ private getTemplateData;
397
+ /**
398
+ * Generates and returns the request URL for proof verification
399
+ *
400
+ * This URL can be shared with users to initiate the proof generation process.
401
+ * The URL format varies based on device type:
402
+ * - Mobile iOS: Returns App Clip URL (if useAppClip is enabled)
403
+ * - Mobile Android: Returns Instant App URL (if useAppClip is enabled)
404
+ * - Desktop/Other: Returns standard verification URL
405
+ *
406
+ * @param launchOptions - Optional launch configuration to override default behavior
407
+ * @returns Promise<string> - The generated request URL
408
+ * @throws {SignatureNotFoundError} When signature is not set
409
+ *
410
+ * @example
411
+ * ```typescript
412
+ * const requestUrl = await proofRequest.getRequestUrl();
413
+ * // Share this URL with users or display as QR code
414
+ * ```
415
+ */
416
+ getRequestUrl(launchOptions?: ReclaimFlowLaunchOptions): Promise<string>;
417
+ /**
418
+ * Triggers the appropriate Reclaim verification flow based on device type and configuration
419
+ *
420
+ * This method automatically detects the device type and initiates the optimal verification flow:
421
+ * - Desktop with browser extension: Triggers extension flow
422
+ * - Desktop without extension: Shows QR code modal
423
+ * - Mobile Android: Redirects to Instant App
424
+ * - Mobile iOS: Redirects to App Clip
425
+ *
426
+ * @param launchOptions - Optional launch configuration to override default behavior
427
+ * @returns Promise<void>
428
+ * @throws {SignatureNotFoundError} When signature is not set
429
+ *
430
+ * @example
431
+ * ```typescript
432
+ * await proofRequest.triggerReclaimFlow();
433
+ * // The appropriate verification method will be triggered automatically
434
+ * ```
435
+ */
436
+ triggerReclaimFlow(launchOptions?: ReclaimFlowLaunchOptions): Promise<void>;
437
+ /**
438
+ * Checks if the Reclaim browser extension is installed and available
439
+ *
440
+ * This method attempts to communicate with the browser extension to verify its availability.
441
+ * It uses a timeout mechanism to quickly determine if the extension responds.
442
+ *
443
+ * @param timeout - Timeout in milliseconds to wait for extension response. Defaults to 200ms
444
+ * @returns Promise<boolean> - True if extension is available, false otherwise
445
+ *
446
+ * @example
447
+ * ```typescript
448
+ * const hasExtension = await proofRequest.isBrowserExtensionAvailable();
449
+ * if (hasExtension) {
450
+ * console.log('Browser extension is installed');
451
+ * }
452
+ * ```
453
+ */
141
454
  isBrowserExtensionAvailable(timeout?: number): Promise<boolean>;
142
455
  private triggerBrowserExtensionFlow;
143
456
  private showQRCodeModal;
144
457
  private redirectToInstantApp;
145
458
  private redirectToAppClip;
459
+ /**
460
+ * Starts the proof request session and monitors for proof submission
461
+ *
462
+ * This method begins polling the session status to detect when
463
+ * a proof has been generated and submitted. It handles both default Reclaim callbacks
464
+ * and custom callback URLs.
465
+ *
466
+ * For default callbacks: Verifies proofs automatically and passes them to onSuccess
467
+ * For custom callbacks: Monitors submission status and notifies via onSuccess when complete
468
+ *
469
+ * @param onSuccess - Callback function invoked when proof is successfully submitted
470
+ * @param onError - Callback function invoked when an error occurs during the session
471
+ * @returns Promise<void>
472
+ * @throws {SessionNotStartedError} When session ID is not defined
473
+ * @throws {ProofNotVerifiedError} When proof verification fails (default callback only)
474
+ * @throws {ProofSubmissionFailedError} When proof submission fails (custom callback only)
475
+ * @throws {ProviderFailedError} When proof generation fails with timeout
476
+ *
477
+ * @example
478
+ * ```typescript
479
+ * await proofRequest.startSession({
480
+ * onSuccess: (proof) => {
481
+ * console.log('Proof received:', proof);
482
+ * },
483
+ * onError: (error) => {
484
+ * console.error('Error:', error);
485
+ * }
486
+ * });
487
+ * ```
488
+ */
146
489
  startSession({ onSuccess, onError }: StartSessionParams): Promise<void>;
490
+ /**
491
+ * Closes the QR code modal if it is currently open
492
+ *
493
+ * This method can be called to programmatically close the modal, for example,
494
+ * when implementing custom UI behavior or cleanup logic.
495
+ *
496
+ * @example
497
+ * ```typescript
498
+ * // Close modal after some condition
499
+ * proofRequest.closeModal();
500
+ * ```
501
+ */
147
502
  closeModal(): void;
148
503
  }
149
504