@reclaimprotocol/js-sdk 4.10.1 → 4.12.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/README.md CHANGED
@@ -8,6 +8,8 @@
8
8
 
9
9
  This guide will walk you through integrating the Reclaim Protocol JavaScript SDK into your application. We'll create a simple React application that demonstrates how to use the SDK to generate proofs and verify claims.
10
10
 
11
+ [Official documentation](https://docs.reclaimprotocol.org/js-sdk/installation)
12
+
11
13
  ## Prerequisites
12
14
 
13
15
  Before we begin, make sure you have:
@@ -312,19 +314,56 @@ The Reclaim SDK offers several advanced options to customize your integration:
312
314
 
313
315
  3. **Custom Redirect URL**:
314
316
 
315
- Set a custom URL to redirect users after the verification process:
317
+ Set a custom URL to redirect users after the verification process.
316
318
 
317
319
  ```javascript
318
320
  reclaimProofRequest.setRedirectUrl("https://example.com/redirect");
319
321
  ```
320
322
 
323
+ Redirection with body:
324
+
325
+ - **url**: The URL where users should be redirected after successful proof generation.
326
+ - **method** (optional): The redirection method to use. Allowed options: `GET` (default) and `POST`.
327
+ *Note: `POST` form redirection is only supported in In-Browser SDK.*
328
+ - **body** (optional): List of name-value pairs to be sent as the body of the form request.
329
+ - When `method` is `POST`, `body` is sent with `application/x-www-form-urlencoded` content type.
330
+ - When `method` is `GET`, if `body` is set, it is sent as query parameters.
331
+ *Note: Sending `body` on redirection is only supported in In-Browser SDK.*
332
+
333
+ ```javascript
334
+ reclaimProofRequest.setRedirectUrl(
335
+ "https://example.com/redirect",
336
+ "POST", // In-Browser SDK only
337
+ [{ name: "foo", value: "bar" }] // In-Browser SDK only
338
+ );
339
+ ```
340
+
321
341
  4. **Custom Cancel Redirect URL**:
322
- Set a custom URL to redirect users on a cancellation which aborts the verification process:
342
+ Set a custom URL to redirect users on a cancellation which aborts the verification process.
343
+
323
344
 
324
345
  ```javascript
325
346
  reclaimProofRequest.setCancelRedirectUrl("https://example.com/error-redirect");
326
347
  ```
327
348
 
349
+ Redirection with body:
350
+
351
+ - **url**: The URL where users should be redirected after an error which aborts the verification process.
352
+ - **method** (optional): The redirection method to use. Allowed options: `GET` (default) and `POST`.
353
+ *Note: `POST` form redirection is only supported in In-Browser SDK.*
354
+ - **body** (optional): List of name-value pairs to be sent as the body of the form request.
355
+ - When `method` is `POST`, `body` is sent with `application/x-www-form-urlencoded` content type.
356
+ - When `method` is `GET`, if `body` is set, it is sent as query parameters.
357
+ *Note: Sending `body` on redirection is only supported in In-Browser SDK.*
358
+
359
+ ```javascript
360
+ reclaimProofRequest.setCancelRedirectUrl(
361
+ "https://example.com/error-redirect",
362
+ "POST", // In-Browser SDK only
363
+ [{ name: "error_code", value: "1001" }] // In-Browser SDK only
364
+ );
365
+ ```
366
+
328
367
  5. **Custom Callback URL**:
329
368
  Set a custom callback URL for your app which allows you to receive proofs and status updates on your callback URL:
330
369
 
@@ -335,12 +374,36 @@ reclaimProofRequest.setCancelRedirectUrl("https://example.com/error-redirect");
335
374
  reclaimProofRequest.setAppCallbackUrl("https://example.com/callback", true);
336
375
  ```
337
376
 
377
+ This verification session's id will also be present in `X-Reclaim-Session-Id` header of the request.
378
+
379
+ The request URL will contain query param `allowAiWitness` with value `true` when AI Witness should be allowed by handler of the request.
380
+
338
381
  6. **Custom Error Callback URL**:
339
- Set a custom cancel callback URL for your app which allows you to receive user or provider initiated cancellation on your callback URL:
340
382
 
341
- ```javascript
342
- reclaimProofRequest.setCancelCallbackUrl("https://example.com/error-callback");
343
-
383
+ Set a custom cancel callback URL for your app which allows you to receive user- or provider-initiated cancellation on your callback URL:
384
+
385
+ ```javascript
386
+ reclaimProofRequest.setCancelCallbackUrl("https://example.com/error-callback");
387
+ ```
388
+
389
+ When verificaiton is cancelled by user (or upon error when auto-submit is enabled), following data is sent as an HTTP POST request to the url with `Content-Type: application/json`:
390
+
391
+ ```json
392
+ {
393
+ "type": "string", // Name of the exception
394
+ "message": "string",
395
+ "sessionId": "string",
396
+ // context as canonicalized json string
397
+ "context": "string",
398
+ // Other fields with more details about error may be present
399
+ // [key: any]: any
400
+ }
401
+ ```
402
+
403
+ This verification session's id will also be present in `X-Reclaim-Session-Id` header of the request.
404
+
405
+ For more details about response format, check out [official documentation of Error Callback URL](https://docs.reclaimprotocol.org/js-sdk/preparing-request#cancel-callback).
406
+
344
407
 
345
408
  7. **Modal Customization for Desktop Users**:
346
409
  Customize the appearance and behavior of the QR code modal shown to desktop users:
package/dist/index.d.ts CHANGED
@@ -49,6 +49,20 @@ type BeaconState = {
49
49
  nextEpochTimestampS: number;
50
50
  };
51
51
 
52
+ type ClaimID = ProviderClaimData['identifier'];
53
+ type ClaimInfo = Pick<ProviderClaimData, 'context' | 'provider' | 'parameters'>;
54
+ type AnyClaimInfo = ClaimInfo | {
55
+ identifier: ClaimID;
56
+ };
57
+ type CompleteClaimData = Pick<ProviderClaimData, 'owner' | 'timestampS' | 'epoch'> & AnyClaimInfo;
58
+ type SignedClaim = {
59
+ claim: CompleteClaimData;
60
+ signatures: Uint8Array[];
61
+ };
62
+ type CreateVerificationRequest = {
63
+ providerIds: string[];
64
+ applicationSecret?: string;
65
+ };
52
66
  type StartSessionParams = {
53
67
  onSuccess: OnSuccess;
54
68
  onError: OnError;
@@ -142,6 +156,29 @@ declare enum DeviceType {
142
156
  DESKTOP = "desktop",
143
157
  MOBILE = "mobile"
144
158
  }
159
+ type InitSessionResponse = {
160
+ sessionId: string;
161
+ resolvedProviderVersion: string;
162
+ };
163
+ interface UpdateSessionResponse {
164
+ success: boolean;
165
+ message?: string;
166
+ }
167
+ declare enum SessionStatus {
168
+ SESSION_INIT = "SESSION_INIT",
169
+ SESSION_STARTED = "SESSION_STARTED",
170
+ USER_INIT_VERIFICATION = "USER_INIT_VERIFICATION",
171
+ USER_STARTED_VERIFICATION = "USER_STARTED_VERIFICATION",
172
+ PROOF_GENERATION_STARTED = "PROOF_GENERATION_STARTED",
173
+ PROOF_GENERATION_SUCCESS = "PROOF_GENERATION_SUCCESS",
174
+ PROOF_GENERATION_FAILED = "PROOF_GENERATION_FAILED",
175
+ PROOF_SUBMITTED = "PROOF_SUBMITTED",
176
+ AI_PROOF_SUBMITTED = "AI_PROOF_SUBMITTED",
177
+ PROOF_SUBMISSION_FAILED = "PROOF_SUBMISSION_FAILED",
178
+ ERROR_SUBMITTED = "ERROR_SUBMITTED",
179
+ ERROR_SUBMISSION_FAILED = "ERROR_SUBMISSION_FAILED",
180
+ PROOF_MANUAL_VERIFICATION_SUBMITED = "PROOF_MANUAL_VERIFICATION_SUBMITED"
181
+ }
145
182
  type ProofPropertiesJSON = {
146
183
  applicationId: string;
147
184
  providerId: string;
@@ -149,6 +186,7 @@ type ProofPropertiesJSON = {
149
186
  context: Context;
150
187
  signature: string;
151
188
  redirectUrl?: string;
189
+ redirectUrlOptions?: TemplateData['redirectUrlOptions'];
152
190
  parameters: {
153
191
  [key: string]: string;
154
192
  };
@@ -160,6 +198,7 @@ type ProofPropertiesJSON = {
160
198
  appCallbackUrl?: string;
161
199
  cancelCallbackUrl?: TemplateData['cancelCallbackUrl'];
162
200
  cancelRedirectUrl?: TemplateData['cancelRedirectUrl'];
201
+ cancelRedirectUrlOptions?: TemplateData['cancelRedirectUrlOptions'];
163
202
  claimCreationType?: ClaimCreationType;
164
203
  options?: ProofRequestOptions;
165
204
  sdkVersion: string;
@@ -167,6 +206,41 @@ type ProofPropertiesJSON = {
167
206
  resolvedProviderVersion: string;
168
207
  modalOptions?: SerializableModalOptions;
169
208
  };
209
+ type HttpFormEntry = {
210
+ name: string;
211
+ value: string;
212
+ };
213
+ type HttpRedirectionMethod = 'GET' | 'POST';
214
+ /**
215
+ * Options for HTTP redirection.
216
+ *
217
+ * Only supported by In-Browser SDK.
218
+ * On other SDKs, this will be ignored and a GET redirection will be performed with the URL.
219
+ *
220
+ * @since 4.11.0
221
+ * @default "{ method: 'GET' }"
222
+ */
223
+ type HttpRedirectionOptions = {
224
+ /**
225
+ * List of name-value pairs to be sent as the body of the form request.
226
+ * When `method` is set to `POST`, `body` will be sent with 'application/x-www-form-urlencoded' content type.
227
+ * When `method` is set to `GET`, `body` will be sent as query parameters.
228
+ *
229
+ * @default undefined
230
+ */
231
+ body?: HttpFormEntry[] | null | undefined;
232
+ /**
233
+ * HTTP method to use for the redirection.
234
+ *
235
+ * POST will result in `body` being sent with 'application/x-www-form-urlencoded' content type.
236
+ * GET will result in `body`, if present, being sent as query parameters.
237
+ *
238
+ * With `method` set to `GET` and no `body`, this will result in a simple GET redirection using `window.location.href`.
239
+ *
240
+ * @default 'GET'
241
+ */
242
+ method?: HttpRedirectionMethod;
243
+ };
170
244
  type TemplateData = {
171
245
  sessionId: string;
172
246
  providerId: string;
@@ -179,8 +253,10 @@ type TemplateData = {
179
253
  [key: string]: string;
180
254
  };
181
255
  redirectUrl: string;
256
+ redirectUrlOptions?: HttpRedirectionOptions;
182
257
  cancelCallbackUrl?: string | null;
183
258
  cancelRedirectUrl?: string | null;
259
+ cancelRedirectUrlOptions?: HttpRedirectionOptions;
184
260
  acceptAiProviders: boolean;
185
261
  sdkVersion: string;
186
262
  jsonProofResponse?: boolean;
@@ -191,6 +267,18 @@ type TemplateData = {
191
267
  metadata?: Record<string, string>;
192
268
  preferredLocale?: ProofRequestOptions['preferredLocale'];
193
269
  };
270
+ type StatusUrlResponse = {
271
+ message: string;
272
+ session?: {
273
+ id: string;
274
+ appId: string;
275
+ httpProviderId: string[];
276
+ sessionId: string;
277
+ proofs?: Proof[];
278
+ statusV2: string;
279
+ };
280
+ providerId?: string;
281
+ };
194
282
 
195
283
  /**
196
284
  * Verifies one or more Reclaim proofs by validating signatures and witness information
@@ -209,6 +297,7 @@ type TemplateData = {
209
297
  * ```
210
298
  */
211
299
  declare function verifyProof(proofOrProofs: Proof | Proof[], allowAiWitness?: boolean): Promise<boolean>;
300
+ declare function assertValidProof(proofOrProofs: Proof | Proof[], allowAiWitness?: boolean): Promise<void>;
212
301
  /**
213
302
  * Transforms a Reclaim proof into a format suitable for on-chain verification
214
303
  *
@@ -237,8 +326,10 @@ declare class ReclaimProofRequest {
237
326
  private resolvedProviderVersion?;
238
327
  private parameters;
239
328
  private redirectUrl?;
329
+ private redirectUrlOptions?;
240
330
  private cancelCallbackUrl?;
241
331
  private cancelRedirectUrl?;
332
+ private cancelRedirectUrlOptions?;
242
333
  private intervals;
243
334
  private timeStamp;
244
335
  private sdkVersion;
@@ -301,6 +392,9 @@ declare class ReclaimProofRequest {
301
392
  * Consequently, the startSession `onSuccess` callback will be invoked with an empty array (`[]`)
302
393
  * instead of the proof data, as the proof is not available to the SDK in this flow.
303
394
  *
395
+ * This verification session's id will be present in `X-Reclaim-Session-Id` header of the request.
396
+ * The request URL will contain query param `allowAiWitness` with value `true` when AI Witness should be allowed by handler of the request.
397
+ *
304
398
  * Note: InApp SDKs are unaffected by this property as they do not handle proof submission.
305
399
  *
306
400
  * @param url - The URL where proofs should be submitted via HTTP `POST`
@@ -319,6 +413,13 @@ declare class ReclaimProofRequest {
319
413
  * Sets a redirect URL where users will be redirected after successfully acquiring and submitting proof
320
414
  *
321
415
  * @param url - The URL where users should be redirected after successful proof generation
416
+ * @param method - The redirection method that should be used for redirection. Allowed options: `GET`, and `POST`.
417
+ * `POST` form redirection is only supported in In-Browser SDK.
418
+ * @param body - List of name-value pairs to be sent as the body of the form request.
419
+ * `When `method` is set to `POST`, `body` will be sent with 'application/x-www-form-urlencoded' content type.
420
+ * When `method` is set to `GET`, if `body` is set then `body` will be sent as query parameters.
421
+ * Sending `body` on redirection is only supported in In-Browser SDK.
422
+ *
322
423
  * @throws {InvalidParamError} When URL is invalid
323
424
  *
324
425
  * @example
@@ -326,7 +427,7 @@ declare class ReclaimProofRequest {
326
427
  * proofRequest.setRedirectUrl('https://your-app.com/success');
327
428
  * ```
328
429
  */
329
- setRedirectUrl(url: string): void;
430
+ setRedirectUrl(url: string, method?: HttpRedirectionMethod, body?: HttpFormEntry[] | undefined): void;
330
431
  /**
331
432
  * Sets a custom callback URL where errors that abort the verification process will be submitted via HTTP POST
332
433
  *
@@ -335,6 +436,24 @@ declare class ReclaimProofRequest {
335
436
  * and listeners on the startSession method will not be triggered. Your application must
336
437
  * coordinate with your backend to receive errors.
337
438
  *
439
+ * This verification session's id will be present in `X-Reclaim-Session-Id` header of the request.
440
+ *
441
+ * Following is the data format which is sent as an HTTP POST request to the url with `Content-Type: application/json`:
442
+
443
+ * ```json
444
+ * {
445
+ * "type": "string", // Name of the exception
446
+ * "message": "string",
447
+ * "sessionId": "string",
448
+ * // context as canonicalized json string
449
+ * "context": "string",
450
+ * // Other fields with more details about error may be present
451
+ * // [key: any]: any
452
+ * }
453
+ * ```
454
+ *
455
+ * For more details about response format, check out [official documentation of Error Callback URL](https://docs.reclaimprotocol.org/js-sdk/preparing-request#cancel-callback).
456
+ *
338
457
  * @param url - The URL where errors should be submitted via HTTP POST
339
458
  * @throws {InvalidParamError} When URL is invalid
340
459
  *
@@ -351,6 +470,12 @@ declare class ReclaimProofRequest {
351
470
  * Sets an error redirect URL where users will be redirected after an error which aborts the verification process
352
471
  *
353
472
  * @param url - The URL where users should be redirected after an error which aborts the verification process
473
+ * @param method - The redirection method that should be used for redirection. Allowed options: `GET`, and `POST`.
474
+ * `POST` form redirection is only supported in In-Browser SDK.
475
+ * @param body - List of name-value pairs to be sent as the body of the form request.
476
+ * When `method` is set to `POST`, `body` will be sent with 'application/x-www-form-urlencoded' content type.
477
+ * When `method` is set to `GET`, if `body` is set then `body` will be sent as query parameters.
478
+ * Sending `body` on redirection is only supported in In-Browser SDK.
354
479
  * @throws {InvalidParamError} When URL is invalid
355
480
  *
356
481
  * @example
@@ -361,7 +486,7 @@ declare class ReclaimProofRequest {
361
486
  * @since 4.10.0
362
487
  *
363
488
  */
364
- setCancelRedirectUrl(url: string): void;
489
+ setCancelRedirectUrl(url: string, method?: HttpRedirectionMethod, body?: HttpFormEntry[] | undefined): void;
365
490
  /**
366
491
  * Sets the claim creation type for the proof request
367
492
  *
@@ -700,4 +825,4 @@ declare function isDesktopDevice(): boolean;
700
825
  */
701
826
  declare function clearDeviceCache(): void;
702
827
 
703
- export { type Beacon, type BeaconState, ClaimCreationType, type Context, DeviceType, type ExtensionMessage, type ModalOptions, type Proof, type ProofPropertiesJSON, type ProviderClaimData, RECLAIM_EXTENSION_ACTIONS, ReclaimProofRequest, type WitnessData, clearDeviceCache, getDeviceType, getMobileDeviceType, isDesktopDevice, isMobileDevice, transformForOnchain, verifyProof };
828
+ export { type AnyClaimInfo, type Beacon, type BeaconState, ClaimCreationType, type ClaimID, type ClaimInfo, type CompleteClaimData, type Context, type CreateVerificationRequest, DeviceType, type ExtensionMessage, type HttpFormEntry, type HttpRedirectionMethod, type HttpRedirectionOptions, type InitSessionResponse, type ModalOptions, type OnError, type OnSuccess, type Proof, type ProofPropertiesJSON, type ProofRequestOptions, type ProviderClaimData, RECLAIM_EXTENSION_ACTIONS, type ReclaimFlowLaunchOptions, ReclaimProofRequest, type SerializableModalOptions, SessionStatus, type SignedClaim, type StartSessionParams, type StatusUrlResponse, type TemplateData, type UpdateSessionResponse, type WitnessData, assertValidProof, clearDeviceCache, getDeviceType, getMobileDeviceType, isDesktopDevice, isMobileDevice, transformForOnchain, verifyProof };