@reclaimprotocol/js-sdk 4.10.0 → 4.11.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.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.10.0",
75
+ version: "4.11.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",
@@ -179,6 +179,7 @@ __export(index_exports, {
179
179
  DeviceType: () => DeviceType,
180
180
  RECLAIM_EXTENSION_ACTIONS: () => RECLAIM_EXTENSION_ACTIONS,
181
181
  ReclaimProofRequest: () => ReclaimProofRequest,
182
+ SessionStatus: () => SessionStatus,
182
183
  clearDeviceCache: () => clearDeviceCache,
183
184
  getDeviceType: () => getDeviceType,
184
185
  getMobileDeviceType: () => getMobileDeviceType,
@@ -280,6 +281,22 @@ var DeviceType = /* @__PURE__ */ ((DeviceType2) => {
280
281
  DeviceType2["MOBILE"] = "mobile";
281
282
  return DeviceType2;
282
283
  })(DeviceType || {});
284
+ var SessionStatus = /* @__PURE__ */ ((SessionStatus2) => {
285
+ SessionStatus2["SESSION_INIT"] = "SESSION_INIT";
286
+ SessionStatus2["SESSION_STARTED"] = "SESSION_STARTED";
287
+ SessionStatus2["USER_INIT_VERIFICATION"] = "USER_INIT_VERIFICATION";
288
+ SessionStatus2["USER_STARTED_VERIFICATION"] = "USER_STARTED_VERIFICATION";
289
+ SessionStatus2["PROOF_GENERATION_STARTED"] = "PROOF_GENERATION_STARTED";
290
+ SessionStatus2["PROOF_GENERATION_SUCCESS"] = "PROOF_GENERATION_SUCCESS";
291
+ SessionStatus2["PROOF_GENERATION_FAILED"] = "PROOF_GENERATION_FAILED";
292
+ SessionStatus2["PROOF_SUBMITTED"] = "PROOF_SUBMITTED";
293
+ SessionStatus2["AI_PROOF_SUBMITTED"] = "AI_PROOF_SUBMITTED";
294
+ SessionStatus2["PROOF_SUBMISSION_FAILED"] = "PROOF_SUBMISSION_FAILED";
295
+ SessionStatus2["ERROR_SUBMITTED"] = "ERROR_SUBMITTED";
296
+ SessionStatus2["ERROR_SUBMISSION_FAILED"] = "ERROR_SUBMISSION_FAILED";
297
+ SessionStatus2["PROOF_MANUAL_VERIFICATION_SUBMITED"] = "PROOF_MANUAL_VERIFICATION_SUBMITED";
298
+ return SessionStatus2;
299
+ })(SessionStatus || {});
283
300
 
284
301
  // src/Reclaim.ts
285
302
  var import_ethers6 = require("ethers");
@@ -474,6 +491,41 @@ function validateURL(url, functionName) {
474
491
  throw new InvalidParamError(`Invalid URL format ${url} passed to ${functionName}.`, e);
475
492
  }
476
493
  }
494
+ function validateRedirectionMethod(method, functionName) {
495
+ try {
496
+ if (method === null || method === void 0) {
497
+ return;
498
+ }
499
+ if (method !== "GET" && method !== "POST") {
500
+ throw new Error(`Invalid redirection method ${method} passed to ${functionName}.`);
501
+ }
502
+ } catch (e) {
503
+ logger3.info(`Redirection method validation failed for ${method} in ${functionName}: ${e.message}`);
504
+ throw new InvalidParamError(`Invalid redirection method ${method} passed to ${functionName}.`, e);
505
+ }
506
+ }
507
+ function validateRedirectionBody(records, functionName) {
508
+ try {
509
+ if (records === null || records === void 0) {
510
+ return;
511
+ }
512
+ if (Array.isArray(records)) {
513
+ for (const record of records) {
514
+ if ("name" in record && record.name && typeof record.name === "string") {
515
+ if ("value" in record && typeof record.value === "string") {
516
+ continue;
517
+ }
518
+ }
519
+ throw new Error("Record in form entries do not have a valid name and/or value");
520
+ }
521
+ } else {
522
+ throw new Error("Redirection body must be an array of objects with name, and value");
523
+ }
524
+ } catch (e) {
525
+ logger3.info(`Redirection body validation failed for ${records} in ${functionName}: ${e.message}`);
526
+ throw new InvalidParamError(`Invalid redirection body ${records} passed to ${functionName}.`, e);
527
+ }
528
+ }
477
529
  function validateSignature(providerId, signature, applicationId, timestamp) {
478
530
  try {
479
531
  logger3.info(`Starting signature validation for providerId: ${providerId}, applicationId: ${applicationId}, timestamp: ${timestamp}`);
@@ -1885,8 +1937,10 @@ var emptyTemplateData = {
1885
1937
  context: "",
1886
1938
  parameters: {},
1887
1939
  redirectUrl: "",
1940
+ redirectUrlOptions: { method: "GET" },
1888
1941
  cancelCallbackUrl: "",
1889
1942
  cancelRedirectUrl: "",
1943
+ cancelRedirectUrlOptions: { method: "GET" },
1890
1944
  acceptAiProviders: false,
1891
1945
  sdkVersion: "",
1892
1946
  providerVersion: "",
@@ -1925,8 +1979,10 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1925
1979
  resolvedProviderVersion: (_c = this.resolvedProviderVersion) != null ? _c : "",
1926
1980
  parameters: this.parameters,
1927
1981
  redirectUrl: (_d = this.redirectUrl) != null ? _d : "",
1982
+ redirectUrlOptions: this.redirectUrlOptions,
1928
1983
  cancelCallbackUrl: this.getCancelCallbackUrl(),
1929
1984
  cancelRedirectUrl: this.cancelRedirectUrl,
1985
+ cancelRedirectUrlOptions: this.cancelRedirectUrlOptions,
1930
1986
  acceptAiProviders: (_f = (_e = this.options) == null ? void 0 : _e.acceptAiProviders) != null ? _f : false,
1931
1987
  sdkVersion: this.sdkVersion,
1932
1988
  jsonProofResponse: this.jsonProofResponse,
@@ -2112,8 +2168,10 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2112
2168
  parameters,
2113
2169
  signature,
2114
2170
  redirectUrl,
2171
+ redirectUrlOptions,
2115
2172
  cancelCallbackUrl,
2116
2173
  cancelRedirectUrl,
2174
+ cancelRedirectUrlOptions,
2117
2175
  timeStamp,
2118
2176
  timestamp,
2119
2177
  appCallbackUrl,
@@ -2139,12 +2197,20 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2139
2197
  if (redirectUrl) {
2140
2198
  validateURL(redirectUrl, "fromJsonString");
2141
2199
  }
2200
+ if (redirectUrlOptions) {
2201
+ validateRedirectionMethod(redirectUrlOptions.method, "fromJsonString");
2202
+ validateRedirectionBody(redirectUrlOptions.body, "fromJsonString");
2203
+ }
2142
2204
  if (appCallbackUrl) {
2143
2205
  validateURL(appCallbackUrl, "fromJsonString");
2144
2206
  }
2145
2207
  if (cancelRedirectUrl) {
2146
2208
  validateURL(cancelRedirectUrl, "fromJsonString");
2147
2209
  }
2210
+ if (cancelRedirectUrlOptions) {
2211
+ validateRedirectionMethod(cancelRedirectUrlOptions.method, "fromJsonString");
2212
+ validateRedirectionBody(cancelRedirectUrlOptions.body, "fromJsonString");
2213
+ }
2148
2214
  if (cancelCallbackUrl) {
2149
2215
  validateURL(cancelCallbackUrl, "fromJsonString");
2150
2216
  }
@@ -2198,6 +2264,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2198
2264
  proofRequestInstance.parameters = parameters;
2199
2265
  proofRequestInstance.appCallbackUrl = appCallbackUrl;
2200
2266
  proofRequestInstance.redirectUrl = redirectUrl;
2267
+ proofRequestInstance.redirectUrlOptions = redirectUrlOptions;
2201
2268
  proofRequestInstance.timeStamp = resolvedTimestamp;
2202
2269
  proofRequestInstance.signature = signature;
2203
2270
  proofRequestInstance.sdkVersion = sdkVersion2;
@@ -2206,6 +2273,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2206
2273
  proofRequestInstance.jsonProofResponse = jsonProofResponse != null ? jsonProofResponse : false;
2207
2274
  proofRequestInstance.cancelCallbackUrl = cancelCallbackUrl;
2208
2275
  proofRequestInstance.cancelRedirectUrl = cancelRedirectUrl;
2276
+ proofRequestInstance.cancelRedirectUrlOptions = cancelRedirectUrlOptions;
2209
2277
  return proofRequestInstance;
2210
2278
  } catch (error) {
2211
2279
  logger7.info("Failed to parse JSON string in fromJsonString:", error);
@@ -2214,16 +2282,21 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2214
2282
  });
2215
2283
  }
2216
2284
  /**
2217
- * Sets a custom callback URL where proofs will be submitted via HTTP POST
2285
+ * Sets a custom callback URL where proofs will be submitted via HTTP `POST`
2218
2286
  *
2219
- * By default, proofs are posted as `application/x-www-form-urlencoded`.
2220
- * When a custom callback URL is set, Reclaim will no longer receive proofs upon submission,
2221
- * and listeners on the startSession method will not be triggered. Your application must
2222
- * coordinate with your backend to receive and verify proofs using verifyProof().
2287
+ * By default, proofs are sent as HTTP POST with `Content-Type` as `application/x-www-form-urlencoded`.
2288
+ * Pass function argument `jsonProofResponse` as `true` to send proofs with `Content-Type` as `application/json`.
2289
+ *
2290
+ * When a custom callback URL is set, proofs are sent to the custom URL *instead* of the Reclaim backend.
2291
+ * Consequently, the startSession `onSuccess` callback will be invoked with an empty array (`[]`)
2292
+ * instead of the proof data, as the proof is not available to the SDK in this flow.
2293
+ *
2294
+ * This verification session's id will be present in `X-Reclaim-Session-Id` header of the request.
2295
+ * The request URL will contain query param `allowAiWitness` with value `true` when AI Witness should be allowed by handler of the request.
2223
2296
  *
2224
2297
  * Note: InApp SDKs are unaffected by this property as they do not handle proof submission.
2225
2298
  *
2226
- * @param url - The URL where proofs should be submitted via HTTP POST
2299
+ * @param url - The URL where proofs should be submitted via HTTP `POST`
2227
2300
  * @param jsonProofResponse - Optional. Set to true to submit proofs as `application/json`. Defaults to false
2228
2301
  * @throws {InvalidParamError} When URL is invalid
2229
2302
  *
@@ -2243,6 +2316,13 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2243
2316
  * Sets a redirect URL where users will be redirected after successfully acquiring and submitting proof
2244
2317
  *
2245
2318
  * @param url - The URL where users should be redirected after successful proof generation
2319
+ * @param method - The redirection method that should be used for redirection. Allowed options: `GET`, and `POST`.
2320
+ * `POST` form redirection is only supported in In-Browser SDK.
2321
+ * @param body - List of name-value pairs to be sent as the body of the form request.
2322
+ * `When `method` is set to `POST`, `body` will be sent with 'application/x-www-form-urlencoded' content type.
2323
+ * When `method` is set to `GET`, if `body` is set then `body` will be sent as query parameters.
2324
+ * Sending `body` on redirection is only supported in In-Browser SDK.
2325
+ *
2246
2326
  * @throws {InvalidParamError} When URL is invalid
2247
2327
  *
2248
2328
  * @example
@@ -2250,29 +2330,50 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2250
2330
  * proofRequest.setRedirectUrl('https://your-app.com/success');
2251
2331
  * ```
2252
2332
  */
2253
- setRedirectUrl(url) {
2333
+ setRedirectUrl(url, method = "GET", body) {
2254
2334
  validateURL(url, "setRedirectUrl");
2335
+ validateRedirectionMethod(method, "setRedirectUrl");
2336
+ validateRedirectionBody(body, "setRedirectUrl");
2255
2337
  this.redirectUrl = url;
2338
+ this.redirectUrlOptions = { method: method || "GET", body };
2256
2339
  }
2257
2340
  /**
2258
- * Sets a custom callback URL where errors that abort the verification process will be submitted via HTTP POST
2259
- *
2260
- * Errors will be HTTP POSTed with `header 'Content-Type': 'application/json'`.
2261
- * When a custom error callback URL is set, Reclaim will no longer receive errors upon submission,
2262
- * and listeners on the startSession method will not be triggered. Your application must
2263
- * coordinate with your backend to receive errors.
2264
- *
2265
- * @param url - The URL where errors should be submitted via HTTP POST
2266
- * @throws {InvalidParamError} When URL is invalid
2267
- *
2268
- * @example
2269
- * ```typescript
2270
- * proofRequest.setCancelCallbackUrl('https://your-backend.com/error-callback');
2271
- * ```
2272
- *
2273
- * @since 4.8.1
2274
- *
2275
- */
2341
+ * Sets a custom callback URL where errors that abort the verification process will be submitted via HTTP POST
2342
+ *
2343
+ * Errors will be HTTP POSTed with `header 'Content-Type': 'application/json'`.
2344
+ * When a custom error callback URL is set, Reclaim will no longer receive errors upon submission,
2345
+ * and listeners on the startSession method will not be triggered. Your application must
2346
+ * coordinate with your backend to receive errors.
2347
+ *
2348
+ * This verification session's id will be present in `X-Reclaim-Session-Id` header of the request.
2349
+ *
2350
+ * Following is the data format which is sent as an HTTP POST request to the url with `Content-Type: application/json`:
2351
+
2352
+ * ```json
2353
+ * {
2354
+ * "type": "string", // Name of the exception
2355
+ * "message": "string",
2356
+ * "sessionId": "string",
2357
+ * // context as canonicalized json string
2358
+ * "context": "string",
2359
+ * // Other fields with more details about error may be present
2360
+ * // [key: any]: any
2361
+ * }
2362
+ * ```
2363
+ *
2364
+ * For more details about response format, check out [official documentation of Error Callback URL](https://docs.reclaimprotocol.org/js-sdk/preparing-request#cancel-callback).
2365
+ *
2366
+ * @param url - The URL where errors should be submitted via HTTP POST
2367
+ * @throws {InvalidParamError} When URL is invalid
2368
+ *
2369
+ * @example
2370
+ * ```typescript
2371
+ * proofRequest.setCancelCallbackUrl('https://your-backend.com/error-callback');
2372
+ * ```
2373
+ *
2374
+ * @since 4.8.1
2375
+ *
2376
+ */
2276
2377
  setCancelCallbackUrl(url) {
2277
2378
  validateURL(url, "setCancelCallbackUrl");
2278
2379
  this.cancelCallbackUrl = url;
@@ -2281,6 +2382,12 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2281
2382
  * Sets an error redirect URL where users will be redirected after an error which aborts the verification process
2282
2383
  *
2283
2384
  * @param url - The URL where users should be redirected after an error which aborts the verification process
2385
+ * @param method - The redirection method that should be used for redirection. Allowed options: `GET`, and `POST`.
2386
+ * `POST` form redirection is only supported in In-Browser SDK.
2387
+ * @param body - List of name-value pairs to be sent as the body of the form request.
2388
+ * When `method` is set to `POST`, `body` will be sent with 'application/x-www-form-urlencoded' content type.
2389
+ * When `method` is set to `GET`, if `body` is set then `body` will be sent as query parameters.
2390
+ * Sending `body` on redirection is only supported in In-Browser SDK.
2284
2391
  * @throws {InvalidParamError} When URL is invalid
2285
2392
  *
2286
2393
  * @example
@@ -2291,9 +2398,12 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2291
2398
  * @since 4.10.0
2292
2399
  *
2293
2400
  */
2294
- setCancelRedirectUrl(url) {
2401
+ setCancelRedirectUrl(url, method = "GET", body) {
2295
2402
  validateURL(url, "setCancelRedirectUrl");
2403
+ validateRedirectionMethod(method, "setCancelRedirectUrl");
2404
+ validateRedirectionBody(body, "setCancelRedirectUrl");
2296
2405
  this.cancelRedirectUrl = url;
2406
+ this.cancelRedirectUrlOptions = { method: method || "GET", body };
2297
2407
  }
2298
2408
  /**
2299
2409
  * Sets the claim creation type for the proof request
@@ -2336,11 +2446,13 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2336
2446
  /**
2337
2447
  * Sets additional context data to be stored with the claim
2338
2448
  *
2339
- * This allows you to associate custom data (address and message) with the proof claim.
2449
+ * This allows you to associate custom JSON serializable data with the proof claim.
2340
2450
  * The context can be retrieved and validated when verifying the proof.
2341
2451
  *
2342
2452
  * Also see [setContext] which is an alternate way to set context that has an address & message.
2343
2453
  *
2454
+ * [setContext] and [setJsonContext] overwrite each other. Each call replaces the existing context.
2455
+ *
2344
2456
  * @param context - Any additional data you want to store with the claim. Should be serializable to a JSON string.
2345
2457
  * @throws {SetContextError} When context parameters are invalid
2346
2458
  *
@@ -2366,6 +2478,10 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2366
2478
  * This allows you to associate custom data (address and message) with the proof claim.
2367
2479
  * The context can be retrieved and validated when verifying the proof.
2368
2480
  *
2481
+ * Also see [setJsonContext] which is an alternate way to set context that allows for custom JSON serializable data.
2482
+ *
2483
+ * [setContext] and [setJsonContext] overwrite each other. Each call replaces the existing context.
2484
+ *
2369
2485
  * @param address - Context address identifier
2370
2486
  * @param message - Additional data to associate with the address
2371
2487
  * @throws {SetContextError} When context parameters are invalid
@@ -2582,8 +2698,10 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2582
2698
  parameters: this.parameters,
2583
2699
  signature: this.signature,
2584
2700
  redirectUrl: this.redirectUrl,
2701
+ redirectUrlOptions: this.redirectUrlOptions,
2585
2702
  cancelCallbackUrl: this.cancelCallbackUrl,
2586
2703
  cancelRedirectUrl: this.cancelRedirectUrl,
2704
+ cancelRedirectUrlOptions: this.cancelRedirectUrlOptions,
2587
2705
  timestamp: this.timeStamp,
2588
2706
  // New field with correct spelling
2589
2707
  timeStamp: this.timeStamp,
@@ -2879,7 +2997,16 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2879
2997
  * and custom callback URLs.
2880
2998
  *
2881
2999
  * For default callbacks: Verifies proofs automatically and passes them to onSuccess
2882
- * For custom callbacks: Monitors submission status and notifies via onSuccess when complete
3000
+ * For custom callbacks: Monitors submission status and notifies via onSuccess when complete.
3001
+ * In the custom-callback flow (where the SDK submits a proof to a provided callback URL),
3002
+ * onSuccess may be invoked with an empty array (onSuccess([])) when no proof is available
3003
+ * (this happens when a callback is set using setAppCallbackUrl where proof is sent to callback instead of reclaim backend).
3004
+ *
3005
+ * Please refer to the OnSuccess type signature ((proof?: Proof | Proof[]) => void)
3006
+ * and the startSession function source for more details.
3007
+ *
3008
+ * > [!TIP]
3009
+ * > **Best Practice:** When using `setAppCallbackUrl` and/or `setCancelCallbackUrl`, your backend receives the proof or cancellation details directly. We recommend your backend notifies the frontend (e.g. via WebSockets, SSE, or polling) to stop the verification process and handle the appropriate success/failure action. Do not rely completely on `startSession` callbacks on the frontend when using these backend callbacks.
2883
3010
  *
2884
3011
  * @param onSuccess - Callback function invoked when proof is successfully submitted
2885
3012
  * @param onError - Callback function invoked when an error occurs during the session
@@ -2955,7 +3082,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2955
3082
  }
2956
3083
  if (statusUrlResponse.session.statusV2 === "PROOF_SUBMITTED" /* PROOF_SUBMITTED */ || statusUrlResponse.session.statusV2 === "AI_PROOF_SUBMITTED" /* AI_PROOF_SUBMITTED */) {
2957
3084
  if (onSuccess) {
2958
- onSuccess("Proof submitted successfully to the custom callback url");
3085
+ onSuccess([]);
2959
3086
  }
2960
3087
  this.clearInterval();
2961
3088
  (_c = this.modal) == null ? void 0 : _c.close();
@@ -3012,6 +3139,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
3012
3139
  DeviceType,
3013
3140
  RECLAIM_EXTENSION_ACTIONS,
3014
3141
  ReclaimProofRequest,
3142
+ SessionStatus,
3015
3143
  clearDeviceCache,
3016
3144
  getDeviceType,
3017
3145
  getMobileDeviceType,