@reclaimprotocol/js-sdk 4.9.0 → 4.10.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
@@ -308,32 +308,33 @@ The Reclaim SDK offers several advanced options to customize your integration:
308
308
  ```
309
309
 
310
310
  3. **Custom Redirect URL**:
311
- Set a custom URL to redirect users after the verification process:
312
311
 
313
- ```javascript
314
- reclaimProofRequest.setRedirectUrl("https://example.com/redirect");
315
- ```
312
+ Set a custom URL to redirect users after the verification process:
316
313
 
317
- 4. **Custom Error Redirect URL**:
318
- Set a custom URL to redirect users on an error which aborts the verification process:
319
- ```javascript
320
- reclaimProofRequest.setErrorRedirectUrl("https://example.com/error-redirect");
321
- ```
314
+ ```javascript
315
+ reclaimProofRequest.setRedirectUrl("https://example.com/redirect");
316
+ ```
317
+
318
+ 4. **Custom Cancel Redirect URL**:
319
+ Set a custom URL to redirect users on a cancellation which aborts the verification process:
320
+
321
+ ```javascript
322
+ reclaimProofRequest.setCancelRedirectUrl("https://example.com/error-redirect");
323
+ ```
322
324
 
323
325
  5. **Custom Callback URL**:
324
326
  Set a custom callback URL for your app which allows you to receive proofs and status updates on your callback URL:
325
327
  Pass in `jsonProofResponse: true` to receive the proof in JSON format: By default, the proof is returned as a url encoded string.
326
328
 
327
- ```javascript
328
329
  reclaimProofRequest.setAppCallbackUrl("https://example.com/callback", true);
329
330
  ```
330
331
 
331
332
  6. **Custom Error Callback URL**:
332
- Set a custom error callback URL for your app which allows you to receive errors and status updates on your error callback URL:
333
+ Set a custom cancel callback URL for your app which allows you to receive user or provider initiated cancellation on your callback URL:
333
334
 
334
335
  ```javascript
335
- reclaimProofRequest.setErrorCallbackUrl("https://example.com/error-callback");
336
- ```
336
+ reclaimProofRequest.setCancelCallbackUrl("https://example.com/error-callback");
337
+
337
338
 
338
339
  7. **Modal Customization for Desktop Users**:
339
340
  Customize the appearance and behavior of the QR code modal shown to desktop users:
@@ -461,19 +462,19 @@ const proofRequest = await ReclaimProofRequest.init(APP_ID, APP_SECRET, PROVIDER
461
462
 
462
463
  ## Handling Proofs on Your Backend
463
464
 
464
- For production applications, it's recommended to handle proofs, and errors on your backend:
465
+ For production applications, it's recommended to handle proofs, and cancellations on your backend:
465
466
 
466
467
  1. Set a callback URL:
467
468
  ```javascript
468
469
  reclaimProofRequest.setAppCallbackUrl("https://your-backend.com/receive-proofs");
469
470
  ```
470
471
 
471
- 2. Set a error callback URL:
472
+ 2. Set a cancel callback URL:
472
473
  ```javascript
473
- reclaimProofRequest.setErrorCallbackUrl("https://your-backend.com/receive-errors");
474
+ reclaimProofRequest.setCancelCallbackUrl("https://your-backend.com/receive-cancel");
474
475
  ```
475
476
 
476
- These options allow you to securely process proofs and status updates on your server.
477
+ These options allow you to securely process proofs or cancellations on your server.
477
478
 
478
479
  ## Proof Verification
479
480
 
package/dist/index.d.ts CHANGED
@@ -95,8 +95,8 @@ type ProofRequestOptions = {
95
95
  */
96
96
  preferredLocale?: string;
97
97
  /**
98
- * Additional metadata to pass to the verification client.
99
- * This can be used to customize the client experience, such as customizing themes or UI by passing context-specific information.
98
+ * Additional metadata to pass to the verification client frontend.
99
+ * This can be used to customize the client UI experience, such as customizing themes or UI by passing context-specific information.
100
100
  * The keys and values must be strings. For most clients, this is not required and goes unused.
101
101
  *
102
102
  * This has no effect on the verification process.
@@ -158,8 +158,8 @@ type ProofPropertiesJSON = {
158
158
  timeStamp?: string;
159
159
  timestamp?: string;
160
160
  appCallbackUrl?: string;
161
- errorCallbackUrl?: TemplateData['errorCallbackUrl'];
162
- errorRedirectUrl?: TemplateData['errorRedirectUrl'];
161
+ cancelCallbackUrl?: TemplateData['cancelCallbackUrl'];
162
+ cancelRedirectUrl?: TemplateData['cancelRedirectUrl'];
163
163
  claimCreationType?: ClaimCreationType;
164
164
  options?: ProofRequestOptions;
165
165
  sdkVersion: string;
@@ -179,8 +179,8 @@ type TemplateData = {
179
179
  [key: string]: string;
180
180
  };
181
181
  redirectUrl: string;
182
- errorCallbackUrl?: string | null;
183
- errorRedirectUrl?: string | null;
182
+ cancelCallbackUrl?: string | null;
183
+ cancelRedirectUrl?: string | null;
184
184
  acceptAiProviders: boolean;
185
185
  sdkVersion: string;
186
186
  jsonProofResponse?: boolean;
@@ -237,8 +237,8 @@ declare class ReclaimProofRequest {
237
237
  private resolvedProviderVersion?;
238
238
  private parameters;
239
239
  private redirectUrl?;
240
- private errorCallbackUrl?;
241
- private errorRedirectUrl?;
240
+ private cancelCallbackUrl?;
241
+ private cancelRedirectUrl?;
242
242
  private intervals;
243
243
  private timeStamp;
244
244
  private sdkVersion;
@@ -338,13 +338,13 @@ declare class ReclaimProofRequest {
338
338
  *
339
339
  * @example
340
340
  * ```typescript
341
- * proofRequest.setErrorCallbackUrl('https://your-backend.com/error-callback');
341
+ * proofRequest.setCancelCallbackUrl('https://your-backend.com/error-callback');
342
342
  * ```
343
343
  *
344
344
  * @since 4.8.1
345
345
  *
346
346
  */
347
- setErrorCallbackUrl(url: string): void;
347
+ setCancelCallbackUrl(url: string): void;
348
348
  /**
349
349
  * Sets an error redirect URL where users will be redirected after an error which aborts the verification process
350
350
  *
@@ -353,13 +353,13 @@ declare class ReclaimProofRequest {
353
353
  *
354
354
  * @example
355
355
  * ```typescript
356
- * proofRequest.setErrorRedirectUrl('https://your-app.com/error');
356
+ * proofRequest.setCancelRedirectUrl('https://your-app.com/error');
357
357
  * ```
358
358
  *
359
- * @since 4.8.1
359
+ * @since 4.10.0
360
360
  *
361
361
  */
362
- setErrorRedirectUrl(url: string): void;
362
+ setCancelRedirectUrl(url: string): void;
363
363
  /**
364
364
  * Sets the claim creation type for the proof request
365
365
  *
@@ -464,21 +464,21 @@ declare class ReclaimProofRequest {
464
464
  */
465
465
  getAppCallbackUrl(): string;
466
466
  /**
467
- * Returns the currently configured error callback URL
467
+ * Returns the currently configured cancel callback URL
468
468
  *
469
- * If no custom error callback URL was set via setErrorCallbackUrl(), this returns the default
470
- * Reclaim service error callback URL with the current session ID.
469
+ * If no custom cancel callback URL was set via setCancelCallbackUrl(), this returns the default
470
+ * Reclaim service cancel callback URL with the current session ID.
471
471
  *
472
- * @returns The error callback URL where proofs will be submitted
473
- * @throws {GetAppCallbackUrlError} When unable to retrieve the error callback URL
472
+ * @returns The cancel callback URL where proofs will be submitted
473
+ * @throws {GetAppCallbackUrlError} When unable to retrieve the cancel callback URL
474
474
  *
475
475
  * @example
476
476
  * ```typescript
477
- * const callbackUrl = proofRequest.getErrorCallbackUrl();
477
+ * const callbackUrl = proofRequest.getCancelCallbackUrl();
478
478
  * console.log('Errors will be sent to:', callbackUrl);
479
479
  * ```
480
480
  */
481
- getErrorCallbackUrl(): string;
481
+ getCancelCallbackUrl(): string;
482
482
  /**
483
483
  * Returns the status URL for monitoring the current session
484
484
  *
package/dist/index.js CHANGED
@@ -72,7 +72,7 @@ var require_package = __commonJS({
72
72
  "package.json"(exports2, module2) {
73
73
  module2.exports = {
74
74
  name: "@reclaimprotocol/js-sdk",
75
- version: "4.9.0",
75
+ version: "4.10.0",
76
76
  description: "Designed to request proofs from the Reclaim protocol and manage the flow of claims and witness interactions.",
77
77
  main: "dist/index.js",
78
78
  types: "dist/index.d.ts",
@@ -408,7 +408,7 @@ var constants = {
408
408
  return `${BACKEND_BASE_URL}/api/sdk/callback?callbackId=`;
409
409
  },
410
410
  // Default error callback URL for Reclaim protocol
411
- get DEFAULT_RECLAIM_ERROR_CALLBACK_URL() {
411
+ get DEFAULT_RECLAIM_CANCEL_CALLBACK_URL() {
412
412
  return `${BACKEND_BASE_URL}/api/sdk/error-callback?callbackId=`;
413
413
  },
414
414
  // Default status URL for Reclaim sessions
@@ -501,6 +501,18 @@ function validateSignature(providerId, signature, applicationId, timestamp) {
501
501
  }
502
502
  }
503
503
  function validateContext(context) {
504
+ if (context && !("contextAddress" in context)) {
505
+ try {
506
+ validateFunctionParams([
507
+ { input: context, paramName: "context", isString: false }
508
+ ], "validateContext");
509
+ JSON.parse(canonicalStringify(context));
510
+ return;
511
+ } catch (e) {
512
+ logger3.info(`Context validation failed: Provided JSON serializable context is not valid`);
513
+ throw new InvalidParamError(`The provided context is not valid`);
514
+ }
515
+ }
504
516
  if (!context.contextAddress) {
505
517
  logger3.info(`Context validation failed: Provided context address in context is not valid`);
506
518
  throw new InvalidParamError(`The provided context address in context is not valid`);
@@ -1873,8 +1885,8 @@ var emptyTemplateData = {
1873
1885
  context: "",
1874
1886
  parameters: {},
1875
1887
  redirectUrl: "",
1876
- errorCallbackUrl: "",
1877
- errorRedirectUrl: "",
1888
+ cancelCallbackUrl: "",
1889
+ cancelRedirectUrl: "",
1878
1890
  acceptAiProviders: false,
1879
1891
  sdkVersion: "",
1880
1892
  providerVersion: "",
@@ -1913,8 +1925,8 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1913
1925
  resolvedProviderVersion: (_c = this.resolvedProviderVersion) != null ? _c : "",
1914
1926
  parameters: this.parameters,
1915
1927
  redirectUrl: (_d = this.redirectUrl) != null ? _d : "",
1916
- errorCallbackUrl: this.getErrorCallbackUrl(),
1917
- errorRedirectUrl: this.errorRedirectUrl,
1928
+ cancelCallbackUrl: this.getCancelCallbackUrl(),
1929
+ cancelRedirectUrl: this.cancelRedirectUrl,
1918
1930
  acceptAiProviders: (_f = (_e = this.options) == null ? void 0 : _e.acceptAiProviders) != null ? _f : false,
1919
1931
  sdkVersion: this.sdkVersion,
1920
1932
  jsonProofResponse: this.jsonProofResponse,
@@ -2066,6 +2078,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2066
2078
  proofRequestInstance.resolvedProviderVersion = data.resolvedProviderVersion;
2067
2079
  return proofRequestInstance;
2068
2080
  } catch (error) {
2081
+ console.error(error);
2069
2082
  logger7.info("Failed to initialize ReclaimProofRequest", error);
2070
2083
  throw new InitError("Failed to initialize ReclaimProofRequest", error);
2071
2084
  }
@@ -2099,8 +2112,8 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2099
2112
  parameters,
2100
2113
  signature,
2101
2114
  redirectUrl,
2102
- errorCallbackUrl,
2103
- errorRedirectUrl,
2115
+ cancelCallbackUrl,
2116
+ cancelRedirectUrl,
2104
2117
  timeStamp,
2105
2118
  timestamp,
2106
2119
  appCallbackUrl,
@@ -2129,11 +2142,11 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2129
2142
  if (appCallbackUrl) {
2130
2143
  validateURL(appCallbackUrl, "fromJsonString");
2131
2144
  }
2132
- if (errorRedirectUrl) {
2133
- validateURL(errorRedirectUrl, "fromJsonString");
2145
+ if (cancelRedirectUrl) {
2146
+ validateURL(cancelRedirectUrl, "fromJsonString");
2134
2147
  }
2135
- if (errorCallbackUrl) {
2136
- validateURL(errorCallbackUrl, "fromJsonString");
2148
+ if (cancelCallbackUrl) {
2149
+ validateURL(cancelCallbackUrl, "fromJsonString");
2137
2150
  }
2138
2151
  if (context) {
2139
2152
  validateContext(context);
@@ -2191,8 +2204,8 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2191
2204
  proofRequestInstance.resolvedProviderVersion = resolvedProviderVersion;
2192
2205
  proofRequestInstance.modalOptions = modalOptions;
2193
2206
  proofRequestInstance.jsonProofResponse = jsonProofResponse != null ? jsonProofResponse : false;
2194
- proofRequestInstance.errorCallbackUrl = errorCallbackUrl;
2195
- proofRequestInstance.errorRedirectUrl = errorRedirectUrl;
2207
+ proofRequestInstance.cancelCallbackUrl = cancelCallbackUrl;
2208
+ proofRequestInstance.cancelRedirectUrl = cancelRedirectUrl;
2196
2209
  return proofRequestInstance;
2197
2210
  } catch (error) {
2198
2211
  logger7.info("Failed to parse JSON string in fromJsonString:", error);
@@ -2254,15 +2267,15 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2254
2267
  *
2255
2268
  * @example
2256
2269
  * ```typescript
2257
- * proofRequest.setErrorCallbackUrl('https://your-backend.com/error-callback');
2270
+ * proofRequest.setCancelCallbackUrl('https://your-backend.com/error-callback');
2258
2271
  * ```
2259
2272
  *
2260
2273
  * @since 4.8.1
2261
2274
  *
2262
2275
  */
2263
- setErrorCallbackUrl(url) {
2264
- validateURL(url, "setErrorCallbackUrl");
2265
- this.errorCallbackUrl = url;
2276
+ setCancelCallbackUrl(url) {
2277
+ validateURL(url, "setCancelCallbackUrl");
2278
+ this.cancelCallbackUrl = url;
2266
2279
  }
2267
2280
  /**
2268
2281
  * Sets an error redirect URL where users will be redirected after an error which aborts the verification process
@@ -2272,15 +2285,15 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2272
2285
  *
2273
2286
  * @example
2274
2287
  * ```typescript
2275
- * proofRequest.setErrorRedirectUrl('https://your-app.com/error');
2288
+ * proofRequest.setCancelRedirectUrl('https://your-app.com/error');
2276
2289
  * ```
2277
2290
  *
2278
- * @since 4.8.1
2291
+ * @since 4.10.0
2279
2292
  *
2280
2293
  */
2281
- setErrorRedirectUrl(url) {
2282
- validateURL(url, "setErrorRedirectUrl");
2283
- this.errorRedirectUrl = url;
2294
+ setCancelRedirectUrl(url) {
2295
+ validateURL(url, "setCancelRedirectUrl");
2296
+ this.cancelRedirectUrl = url;
2284
2297
  }
2285
2298
  /**
2286
2299
  * Sets the claim creation type for the proof request
@@ -2434,27 +2447,27 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2434
2447
  }
2435
2448
  }
2436
2449
  /**
2437
- * Returns the currently configured error callback URL
2450
+ * Returns the currently configured cancel callback URL
2438
2451
  *
2439
- * If no custom error callback URL was set via setErrorCallbackUrl(), this returns the default
2440
- * Reclaim service error callback URL with the current session ID.
2452
+ * If no custom cancel callback URL was set via setCancelCallbackUrl(), this returns the default
2453
+ * Reclaim service cancel callback URL with the current session ID.
2441
2454
  *
2442
- * @returns The error callback URL where proofs will be submitted
2443
- * @throws {GetAppCallbackUrlError} When unable to retrieve the error callback URL
2455
+ * @returns The cancel callback URL where proofs will be submitted
2456
+ * @throws {GetAppCallbackUrlError} When unable to retrieve the cancel callback URL
2444
2457
  *
2445
2458
  * @example
2446
2459
  * ```typescript
2447
- * const callbackUrl = proofRequest.getErrorCallbackUrl();
2460
+ * const callbackUrl = proofRequest.getCancelCallbackUrl();
2448
2461
  * console.log('Errors will be sent to:', callbackUrl);
2449
2462
  * ```
2450
2463
  */
2451
- getErrorCallbackUrl() {
2464
+ getCancelCallbackUrl() {
2452
2465
  try {
2453
- validateFunctionParams([{ input: this.sessionId, paramName: "sessionId", isString: true }], "getErrorCallbackUrl");
2454
- return this.errorCallbackUrl || `${constants.DEFAULT_RECLAIM_ERROR_CALLBACK_URL}${this.sessionId}`;
2466
+ validateFunctionParams([{ input: this.sessionId, paramName: "sessionId", isString: true }], "getCancelCallbackUrl");
2467
+ return this.cancelCallbackUrl || `${constants.DEFAULT_RECLAIM_CANCEL_CALLBACK_URL}${this.sessionId}`;
2455
2468
  } catch (error) {
2456
- logger7.info("Error getting error callback url", error);
2457
- throw new GetAppCallbackUrlError("Error getting error callback url", error);
2469
+ logger7.info("Error getting cancel callback url", error);
2470
+ throw new GetAppCallbackUrlError("Error getting cancel callback url", error);
2458
2471
  }
2459
2472
  }
2460
2473
  /**
@@ -2569,8 +2582,8 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2569
2582
  parameters: this.parameters,
2570
2583
  signature: this.signature,
2571
2584
  redirectUrl: this.redirectUrl,
2572
- errorCallbackUrl: this.errorCallbackUrl,
2573
- errorRedirectUrl: this.errorRedirectUrl,
2585
+ cancelCallbackUrl: this.cancelCallbackUrl,
2586
+ cancelRedirectUrl: this.cancelRedirectUrl,
2574
2587
  timestamp: this.timeStamp,
2575
2588
  // New field with correct spelling
2576
2589
  timeStamp: this.timeStamp,