@reclaimprotocol/js-sdk 4.10.0 → 4.10.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/README.md CHANGED
@@ -80,15 +80,17 @@ function App() {
80
80
 
81
81
  await reclaimProofRequest.startSession({
82
82
  onSuccess: (proofs) => {
83
- if (proofs && typeof proofs === "string") {
84
- // When using a custom callback url, the proof is returned to the callback url and we get a message instead of a proof
85
- console.log("SDK Message:", proofs);
86
- setProofs(proofs);
87
- } else if (proofs && typeof proofs !== "string") {
83
+ if (proofs && typeof proofs !== "string") {
88
84
  // When using the default callback url, we get a proof
89
85
  if (Array.isArray(proofs)) {
90
- // when using the cascading providers, providers having more than one proof will return an array of proofs
91
- console.log(JSON.stringify(proofs.map((p) => p.claimData.context)));
86
+ if (proofs.length == 0) {
87
+ // From version 4.10.1, this is the case when using a custom callback url
88
+ // Proofs are sent to the callback url.
89
+ console.log("No proofs received. This is expected when using a custom callback url.");
90
+ } else {
91
+ // when using the cascading providers, providers having more than one proof will return an array of proofs
92
+ console.log(JSON.stringify(proofs.map((p) => p.claimData.context)));
93
+ }
92
94
  } else {
93
95
  console.log("Proof received:", proofs?.claimData.context);
94
96
  }
@@ -164,12 +166,13 @@ async function handleCreateClaim() {
164
166
  // Listen for the verification results
165
167
  await reclaimProofRequest.startSession({
166
168
  onSuccess: (proofs) => {
167
- if (proofs && typeof proofs === "string") {
168
- console.log("SDK Message:", proofs);
169
- setProofs(proofs);
170
- } else if (proofs && typeof proofs !== "string") {
169
+ if (proofs && typeof proofs !== "string") {
171
170
  if (Array.isArray(proofs)) {
172
- console.log(JSON.stringify(proofs.map((p) => p.claimData.context)));
171
+ if (proofs.length == 0) {
172
+ // proofs sent to callback url
173
+ } else {
174
+ console.log(JSON.stringify(proofs.map((p) => p.claimData.context)));
175
+ }
173
176
  } else {
174
177
  console.log("Proof received:", proofs?.claimData.context);
175
178
  }
@@ -282,7 +285,7 @@ Your Reclaim SDK demo should now be running. Click the "Create Claim" button to
282
285
 
283
286
  3. **Status URL**: This URL (logged to the console) can be used to check the status of the claim process. It's useful for tracking the progress of verification.
284
287
 
285
- 4. **Verification**: The `onSuccess` is called when verification is successful, providing the proof data. When using a custom callback url, the proof is returned to the callback url and we get a message instead of a proof.
288
+ 4. **Verification**: The `onSuccess` is called when verification is successful, providing the proof data. When using a custom callback url, the proof is returned to the callback url and we get an empty array instead of a proof.
286
289
 
287
290
  5. **Handling Failures**: The `onFailure` is called if verification fails, allowing you to handle errors gracefully.
288
291
 
@@ -324,7 +327,10 @@ reclaimProofRequest.setCancelRedirectUrl("https://example.com/error-redirect");
324
327
 
325
328
  5. **Custom Callback URL**:
326
329
  Set a custom callback URL for your app which allows you to receive proofs and status updates on your callback URL:
327
- Pass in `jsonProofResponse: true` to receive the proof in JSON format: By default, the proof is returned as a url encoded string.
330
+
331
+ **Note**: When a custom callback URL is set, proofs are sent to the custom URL *instead* of the Reclaim backend. Consequently, the `onSuccess` callback will be invoked with an empty array (`[]`) instead of the proof data.
332
+
333
+ By default, proofs are sent as HTTP `POST` with `Content-Type` as `application/x-www-form-urlencoded`. Pass function argument `jsonProofResponse` as `true` to send proofs with `Content-Type` as `application/json`.
328
334
 
329
335
  reclaimProofRequest.setAppCallbackUrl("https://example.com/callback", true);
330
336
  ```
@@ -476,6 +482,9 @@ For production applications, it's recommended to handle proofs, and cancellation
476
482
 
477
483
  These options allow you to securely process proofs or cancellations on your server.
478
484
 
485
+ > [!TIP]
486
+ > **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.
487
+
479
488
  ## Proof Verification
480
489
 
481
490
  The SDK provides a `verifyProof` function to manually verify proofs. This is useful when you need to validate proofs outside of the normal flow:
@@ -518,8 +527,9 @@ try {
518
527
  const proofRequest = await ReclaimProofRequest.init(APP_ID, APP_SECRET, PROVIDER_ID);
519
528
 
520
529
  await proofRequest.startSession({
521
- onSuccess: (proof) => {
522
- console.log("Proof received:", proof);
530
+ onSuccess: (proofs) => {
531
+ // proofs can be empty if callback url set
532
+ console.log("Proof received:", proofs);
523
533
  },
524
534
  onError: (error) => {
525
535
  // Handle different error types
package/dist/index.d.ts CHANGED
@@ -53,7 +53,7 @@ type StartSessionParams = {
53
53
  onSuccess: OnSuccess;
54
54
  onError: OnError;
55
55
  };
56
- type OnSuccess = (proof?: Proof | Proof[] | string) => void;
56
+ type OnSuccess = (proof?: Proof | Proof[]) => void;
57
57
  type OnError = (error: Error) => void;
58
58
  type ProofRequestOptions = {
59
59
  /**
@@ -292,16 +292,18 @@ declare class ReclaimProofRequest {
292
292
  */
293
293
  static fromJsonString(jsonString: string): Promise<ReclaimProofRequest>;
294
294
  /**
295
- * Sets a custom callback URL where proofs will be submitted via HTTP POST
295
+ * Sets a custom callback URL where proofs will be submitted via HTTP `POST`
296
296
  *
297
- * By default, proofs are posted as `application/x-www-form-urlencoded`.
298
- * When a custom callback URL is set, Reclaim will no longer receive proofs upon submission,
299
- * and listeners on the startSession method will not be triggered. Your application must
300
- * coordinate with your backend to receive and verify proofs using verifyProof().
297
+ * By default, proofs are sent as HTTP POST with `Content-Type` as `application/x-www-form-urlencoded`.
298
+ * Pass function argument `jsonProofResponse` as `true` to send proofs with `Content-Type` as `application/json`.
299
+ *
300
+ * When a custom callback URL is set, proofs are sent to the custom URL *instead* of the Reclaim backend.
301
+ * Consequently, the startSession `onSuccess` callback will be invoked with an empty array (`[]`)
302
+ * instead of the proof data, as the proof is not available to the SDK in this flow.
301
303
  *
302
304
  * Note: InApp SDKs are unaffected by this property as they do not handle proof submission.
303
305
  *
304
- * @param url - The URL where proofs should be submitted via HTTP POST
306
+ * @param url - The URL where proofs should be submitted via HTTP `POST`
305
307
  * @param jsonProofResponse - Optional. Set to true to submit proofs as `application/json`. Defaults to false
306
308
  * @throws {InvalidParamError} When URL is invalid
307
309
  *
@@ -390,11 +392,13 @@ declare class ReclaimProofRequest {
390
392
  /**
391
393
  * Sets additional context data to be stored with the claim
392
394
  *
393
- * This allows you to associate custom data (address and message) with the proof claim.
395
+ * This allows you to associate custom JSON serializable data with the proof claim.
394
396
  * The context can be retrieved and validated when verifying the proof.
395
397
  *
396
398
  * Also see [setContext] which is an alternate way to set context that has an address & message.
397
399
  *
400
+ * [setContext] and [setJsonContext] overwrite each other. Each call replaces the existing context.
401
+ *
398
402
  * @param context - Any additional data you want to store with the claim. Should be serializable to a JSON string.
399
403
  * @throws {SetContextError} When context parameters are invalid
400
404
  *
@@ -410,6 +414,10 @@ declare class ReclaimProofRequest {
410
414
  * This allows you to associate custom data (address and message) with the proof claim.
411
415
  * The context can be retrieved and validated when verifying the proof.
412
416
  *
417
+ * Also see [setJsonContext] which is an alternate way to set context that allows for custom JSON serializable data.
418
+ *
419
+ * [setContext] and [setJsonContext] overwrite each other. Each call replaces the existing context.
420
+ *
413
421
  * @param address - Context address identifier
414
422
  * @param message - Additional data to associate with the address
415
423
  * @throws {SetContextError} When context parameters are invalid
@@ -606,7 +614,16 @@ declare class ReclaimProofRequest {
606
614
  * and custom callback URLs.
607
615
  *
608
616
  * For default callbacks: Verifies proofs automatically and passes them to onSuccess
609
- * For custom callbacks: Monitors submission status and notifies via onSuccess when complete
617
+ * For custom callbacks: Monitors submission status and notifies via onSuccess when complete.
618
+ * In the custom-callback flow (where the SDK submits a proof to a provided callback URL),
619
+ * onSuccess may be invoked with an empty array (onSuccess([])) when no proof is available
620
+ * (this happens when a callback is set using setAppCallbackUrl where proof is sent to callback instead of reclaim backend).
621
+ *
622
+ * Please refer to the OnSuccess type signature ((proof?: Proof | Proof[]) => void)
623
+ * and the startSession function source for more details.
624
+ *
625
+ * > [!TIP]
626
+ * > **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.
610
627
  *
611
628
  * @param onSuccess - Callback function invoked when proof is successfully submitted
612
629
  * @param onError - Callback function invoked when an error occurs during the session
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.10.1",
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",
@@ -2214,16 +2214,18 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2214
2214
  });
2215
2215
  }
2216
2216
  /**
2217
- * Sets a custom callback URL where proofs will be submitted via HTTP POST
2218
- *
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().
2217
+ * Sets a custom callback URL where proofs will be submitted via HTTP `POST`
2223
2218
  *
2219
+ * By default, proofs are sent as HTTP POST with `Content-Type` as `application/x-www-form-urlencoded`.
2220
+ * Pass function argument `jsonProofResponse` as `true` to send proofs with `Content-Type` as `application/json`.
2221
+ *
2222
+ * When a custom callback URL is set, proofs are sent to the custom URL *instead* of the Reclaim backend.
2223
+ * Consequently, the startSession `onSuccess` callback will be invoked with an empty array (`[]`)
2224
+ * instead of the proof data, as the proof is not available to the SDK in this flow.
2225
+ *
2224
2226
  * Note: InApp SDKs are unaffected by this property as they do not handle proof submission.
2225
2227
  *
2226
- * @param url - The URL where proofs should be submitted via HTTP POST
2228
+ * @param url - The URL where proofs should be submitted via HTTP `POST`
2227
2229
  * @param jsonProofResponse - Optional. Set to true to submit proofs as `application/json`. Defaults to false
2228
2230
  * @throws {InvalidParamError} When URL is invalid
2229
2231
  *
@@ -2336,11 +2338,13 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2336
2338
  /**
2337
2339
  * Sets additional context data to be stored with the claim
2338
2340
  *
2339
- * This allows you to associate custom data (address and message) with the proof claim.
2341
+ * This allows you to associate custom JSON serializable data with the proof claim.
2340
2342
  * The context can be retrieved and validated when verifying the proof.
2341
2343
  *
2342
2344
  * Also see [setContext] which is an alternate way to set context that has an address & message.
2343
2345
  *
2346
+ * [setContext] and [setJsonContext] overwrite each other. Each call replaces the existing context.
2347
+ *
2344
2348
  * @param context - Any additional data you want to store with the claim. Should be serializable to a JSON string.
2345
2349
  * @throws {SetContextError} When context parameters are invalid
2346
2350
  *
@@ -2366,6 +2370,10 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2366
2370
  * This allows you to associate custom data (address and message) with the proof claim.
2367
2371
  * The context can be retrieved and validated when verifying the proof.
2368
2372
  *
2373
+ * Also see [setJsonContext] which is an alternate way to set context that allows for custom JSON serializable data.
2374
+ *
2375
+ * [setContext] and [setJsonContext] overwrite each other. Each call replaces the existing context.
2376
+ *
2369
2377
  * @param address - Context address identifier
2370
2378
  * @param message - Additional data to associate with the address
2371
2379
  * @throws {SetContextError} When context parameters are invalid
@@ -2879,7 +2887,16 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2879
2887
  * and custom callback URLs.
2880
2888
  *
2881
2889
  * For default callbacks: Verifies proofs automatically and passes them to onSuccess
2882
- * For custom callbacks: Monitors submission status and notifies via onSuccess when complete
2890
+ * For custom callbacks: Monitors submission status and notifies via onSuccess when complete.
2891
+ * In the custom-callback flow (where the SDK submits a proof to a provided callback URL),
2892
+ * onSuccess may be invoked with an empty array (onSuccess([])) when no proof is available
2893
+ * (this happens when a callback is set using setAppCallbackUrl where proof is sent to callback instead of reclaim backend).
2894
+ *
2895
+ * Please refer to the OnSuccess type signature ((proof?: Proof | Proof[]) => void)
2896
+ * and the startSession function source for more details.
2897
+ *
2898
+ * > [!TIP]
2899
+ * > **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
2900
  *
2884
2901
  * @param onSuccess - Callback function invoked when proof is successfully submitted
2885
2902
  * @param onError - Callback function invoked when an error occurs during the session
@@ -2955,7 +2972,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2955
2972
  }
2956
2973
  if (statusUrlResponse.session.statusV2 === "PROOF_SUBMITTED" /* PROOF_SUBMITTED */ || statusUrlResponse.session.statusV2 === "AI_PROOF_SUBMITTED" /* AI_PROOF_SUBMITTED */) {
2957
2974
  if (onSuccess) {
2958
- onSuccess("Proof submitted successfully to the custom callback url");
2975
+ onSuccess([]);
2959
2976
  }
2960
2977
  this.clearInterval();
2961
2978
  (_c = this.modal) == null ? void 0 : _c.close();