@reclaimprotocol/js-sdk 4.5.1 → 4.6.0

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