@reclaimprotocol/js-sdk 4.9.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 +44 -33
- package/dist/index.d.ts +46 -29
- package/dist/index.js +76 -46
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
|
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
|
-
|
|
91
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
|
@@ -308,32 +311,36 @@ The Reclaim SDK offers several advanced options to customize your integration:
|
|
|
308
311
|
```
|
|
309
312
|
|
|
310
313
|
3. **Custom Redirect URL**:
|
|
311
|
-
Set a custom URL to redirect users after the verification process:
|
|
312
314
|
|
|
313
|
-
|
|
314
|
-
reclaimProofRequest.setRedirectUrl("https://example.com/redirect");
|
|
315
|
-
```
|
|
315
|
+
Set a custom URL to redirect users after the verification process:
|
|
316
316
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
317
|
+
```javascript
|
|
318
|
+
reclaimProofRequest.setRedirectUrl("https://example.com/redirect");
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
4. **Custom Cancel Redirect URL**:
|
|
322
|
+
Set a custom URL to redirect users on a cancellation which aborts the verification process:
|
|
323
|
+
|
|
324
|
+
```javascript
|
|
325
|
+
reclaimProofRequest.setCancelRedirectUrl("https://example.com/error-redirect");
|
|
326
|
+
```
|
|
322
327
|
|
|
323
328
|
5. **Custom Callback URL**:
|
|
324
329
|
Set a custom callback URL for your app which allows you to receive proofs and status updates on your callback URL:
|
|
325
|
-
|
|
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`.
|
|
326
334
|
|
|
327
|
-
```javascript
|
|
328
335
|
reclaimProofRequest.setAppCallbackUrl("https://example.com/callback", true);
|
|
329
336
|
```
|
|
330
337
|
|
|
331
338
|
6. **Custom Error Callback URL**:
|
|
332
|
-
Set a custom
|
|
339
|
+
Set a custom cancel callback URL for your app which allows you to receive user or provider initiated cancellation on your callback URL:
|
|
333
340
|
|
|
334
341
|
```javascript
|
|
335
|
-
reclaimProofRequest.
|
|
336
|
-
|
|
342
|
+
reclaimProofRequest.setCancelCallbackUrl("https://example.com/error-callback");
|
|
343
|
+
|
|
337
344
|
|
|
338
345
|
7. **Modal Customization for Desktop Users**:
|
|
339
346
|
Customize the appearance and behavior of the QR code modal shown to desktop users:
|
|
@@ -461,19 +468,22 @@ const proofRequest = await ReclaimProofRequest.init(APP_ID, APP_SECRET, PROVIDER
|
|
|
461
468
|
|
|
462
469
|
## Handling Proofs on Your Backend
|
|
463
470
|
|
|
464
|
-
For production applications, it's recommended to handle proofs, and
|
|
471
|
+
For production applications, it's recommended to handle proofs, and cancellations on your backend:
|
|
465
472
|
|
|
466
473
|
1. Set a callback URL:
|
|
467
474
|
```javascript
|
|
468
475
|
reclaimProofRequest.setAppCallbackUrl("https://your-backend.com/receive-proofs");
|
|
469
476
|
```
|
|
470
477
|
|
|
471
|
-
2. Set a
|
|
478
|
+
2. Set a cancel callback URL:
|
|
472
479
|
```javascript
|
|
473
|
-
reclaimProofRequest.
|
|
480
|
+
reclaimProofRequest.setCancelCallbackUrl("https://your-backend.com/receive-cancel");
|
|
474
481
|
```
|
|
475
482
|
|
|
476
|
-
These options allow you to securely process proofs
|
|
483
|
+
These options allow you to securely process proofs or cancellations on your server.
|
|
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.
|
|
477
487
|
|
|
478
488
|
## Proof Verification
|
|
479
489
|
|
|
@@ -517,8 +527,9 @@ try {
|
|
|
517
527
|
const proofRequest = await ReclaimProofRequest.init(APP_ID, APP_SECRET, PROVIDER_ID);
|
|
518
528
|
|
|
519
529
|
await proofRequest.startSession({
|
|
520
|
-
onSuccess: (
|
|
521
|
-
|
|
530
|
+
onSuccess: (proofs) => {
|
|
531
|
+
// proofs can be empty if callback url set
|
|
532
|
+
console.log("Proof received:", proofs);
|
|
522
533
|
},
|
|
523
534
|
onError: (error) => {
|
|
524
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[]
|
|
56
|
+
type OnSuccess = (proof?: Proof | Proof[]) => void;
|
|
57
57
|
type OnError = (error: Error) => void;
|
|
58
58
|
type ProofRequestOptions = {
|
|
59
59
|
/**
|
|
@@ -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
|
-
|
|
162
|
-
|
|
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
|
-
|
|
183
|
-
|
|
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
|
|
241
|
-
private
|
|
240
|
+
private cancelCallbackUrl?;
|
|
241
|
+
private cancelRedirectUrl?;
|
|
242
242
|
private intervals;
|
|
243
243
|
private timeStamp;
|
|
244
244
|
private sdkVersion;
|
|
@@ -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
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
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
|
*
|
|
@@ -338,13 +340,13 @@ declare class ReclaimProofRequest {
|
|
|
338
340
|
*
|
|
339
341
|
* @example
|
|
340
342
|
* ```typescript
|
|
341
|
-
* proofRequest.
|
|
343
|
+
* proofRequest.setCancelCallbackUrl('https://your-backend.com/error-callback');
|
|
342
344
|
* ```
|
|
343
345
|
*
|
|
344
346
|
* @since 4.8.1
|
|
345
347
|
*
|
|
346
348
|
*/
|
|
347
|
-
|
|
349
|
+
setCancelCallbackUrl(url: string): void;
|
|
348
350
|
/**
|
|
349
351
|
* Sets an error redirect URL where users will be redirected after an error which aborts the verification process
|
|
350
352
|
*
|
|
@@ -353,13 +355,13 @@ declare class ReclaimProofRequest {
|
|
|
353
355
|
*
|
|
354
356
|
* @example
|
|
355
357
|
* ```typescript
|
|
356
|
-
* proofRequest.
|
|
358
|
+
* proofRequest.setCancelRedirectUrl('https://your-app.com/error');
|
|
357
359
|
* ```
|
|
358
360
|
*
|
|
359
|
-
* @since 4.
|
|
361
|
+
* @since 4.10.0
|
|
360
362
|
*
|
|
361
363
|
*/
|
|
362
|
-
|
|
364
|
+
setCancelRedirectUrl(url: string): void;
|
|
363
365
|
/**
|
|
364
366
|
* Sets the claim creation type for the proof request
|
|
365
367
|
*
|
|
@@ -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
|
|
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
|
|
@@ -464,21 +472,21 @@ declare class ReclaimProofRequest {
|
|
|
464
472
|
*/
|
|
465
473
|
getAppCallbackUrl(): string;
|
|
466
474
|
/**
|
|
467
|
-
* Returns the currently configured
|
|
475
|
+
* Returns the currently configured cancel callback URL
|
|
468
476
|
*
|
|
469
|
-
* If no custom
|
|
470
|
-
* Reclaim service
|
|
477
|
+
* If no custom cancel callback URL was set via setCancelCallbackUrl(), this returns the default
|
|
478
|
+
* Reclaim service cancel callback URL with the current session ID.
|
|
471
479
|
*
|
|
472
|
-
* @returns The
|
|
473
|
-
* @throws {GetAppCallbackUrlError} When unable to retrieve the
|
|
480
|
+
* @returns The cancel callback URL where proofs will be submitted
|
|
481
|
+
* @throws {GetAppCallbackUrlError} When unable to retrieve the cancel callback URL
|
|
474
482
|
*
|
|
475
483
|
* @example
|
|
476
484
|
* ```typescript
|
|
477
|
-
* const callbackUrl = proofRequest.
|
|
485
|
+
* const callbackUrl = proofRequest.getCancelCallbackUrl();
|
|
478
486
|
* console.log('Errors will be sent to:', callbackUrl);
|
|
479
487
|
* ```
|
|
480
488
|
*/
|
|
481
|
-
|
|
489
|
+
getCancelCallbackUrl(): string;
|
|
482
490
|
/**
|
|
483
491
|
* Returns the status URL for monitoring the current session
|
|
484
492
|
*
|
|
@@ -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.
|
|
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",
|
|
@@ -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
|
|
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
|
-
|
|
1877
|
-
|
|
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
|
-
|
|
1917
|
-
|
|
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
|
-
|
|
2103
|
-
|
|
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 (
|
|
2133
|
-
validateURL(
|
|
2145
|
+
if (cancelRedirectUrl) {
|
|
2146
|
+
validateURL(cancelRedirectUrl, "fromJsonString");
|
|
2134
2147
|
}
|
|
2135
|
-
if (
|
|
2136
|
-
validateURL(
|
|
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.
|
|
2195
|
-
proofRequestInstance.
|
|
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);
|
|
@@ -2201,16 +2214,18 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
2201
2214
|
});
|
|
2202
2215
|
}
|
|
2203
2216
|
/**
|
|
2204
|
-
* Sets a custom callback URL where proofs will be submitted via HTTP POST
|
|
2205
|
-
*
|
|
2206
|
-
* By default, proofs are posted as `application/x-www-form-urlencoded`.
|
|
2207
|
-
* When a custom callback URL is set, Reclaim will no longer receive proofs upon submission,
|
|
2208
|
-
* and listeners on the startSession method will not be triggered. Your application must
|
|
2209
|
-
* 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`
|
|
2210
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
|
+
*
|
|
2211
2226
|
* Note: InApp SDKs are unaffected by this property as they do not handle proof submission.
|
|
2212
2227
|
*
|
|
2213
|
-
* @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`
|
|
2214
2229
|
* @param jsonProofResponse - Optional. Set to true to submit proofs as `application/json`. Defaults to false
|
|
2215
2230
|
* @throws {InvalidParamError} When URL is invalid
|
|
2216
2231
|
*
|
|
@@ -2254,15 +2269,15 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
2254
2269
|
*
|
|
2255
2270
|
* @example
|
|
2256
2271
|
* ```typescript
|
|
2257
|
-
* proofRequest.
|
|
2272
|
+
* proofRequest.setCancelCallbackUrl('https://your-backend.com/error-callback');
|
|
2258
2273
|
* ```
|
|
2259
2274
|
*
|
|
2260
2275
|
* @since 4.8.1
|
|
2261
2276
|
*
|
|
2262
2277
|
*/
|
|
2263
|
-
|
|
2264
|
-
validateURL(url, "
|
|
2265
|
-
this.
|
|
2278
|
+
setCancelCallbackUrl(url) {
|
|
2279
|
+
validateURL(url, "setCancelCallbackUrl");
|
|
2280
|
+
this.cancelCallbackUrl = url;
|
|
2266
2281
|
}
|
|
2267
2282
|
/**
|
|
2268
2283
|
* Sets an error redirect URL where users will be redirected after an error which aborts the verification process
|
|
@@ -2272,15 +2287,15 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
2272
2287
|
*
|
|
2273
2288
|
* @example
|
|
2274
2289
|
* ```typescript
|
|
2275
|
-
* proofRequest.
|
|
2290
|
+
* proofRequest.setCancelRedirectUrl('https://your-app.com/error');
|
|
2276
2291
|
* ```
|
|
2277
2292
|
*
|
|
2278
|
-
* @since 4.
|
|
2293
|
+
* @since 4.10.0
|
|
2279
2294
|
*
|
|
2280
2295
|
*/
|
|
2281
|
-
|
|
2282
|
-
validateURL(url, "
|
|
2283
|
-
this.
|
|
2296
|
+
setCancelRedirectUrl(url) {
|
|
2297
|
+
validateURL(url, "setCancelRedirectUrl");
|
|
2298
|
+
this.cancelRedirectUrl = url;
|
|
2284
2299
|
}
|
|
2285
2300
|
/**
|
|
2286
2301
|
* Sets the claim creation type for the proof request
|
|
@@ -2323,11 +2338,13 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
2323
2338
|
/**
|
|
2324
2339
|
* Sets additional context data to be stored with the claim
|
|
2325
2340
|
*
|
|
2326
|
-
* This allows you to associate custom
|
|
2341
|
+
* This allows you to associate custom JSON serializable data with the proof claim.
|
|
2327
2342
|
* The context can be retrieved and validated when verifying the proof.
|
|
2328
2343
|
*
|
|
2329
2344
|
* Also see [setContext] which is an alternate way to set context that has an address & message.
|
|
2330
2345
|
*
|
|
2346
|
+
* [setContext] and [setJsonContext] overwrite each other. Each call replaces the existing context.
|
|
2347
|
+
*
|
|
2331
2348
|
* @param context - Any additional data you want to store with the claim. Should be serializable to a JSON string.
|
|
2332
2349
|
* @throws {SetContextError} When context parameters are invalid
|
|
2333
2350
|
*
|
|
@@ -2353,6 +2370,10 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
2353
2370
|
* This allows you to associate custom data (address and message) with the proof claim.
|
|
2354
2371
|
* The context can be retrieved and validated when verifying the proof.
|
|
2355
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
|
+
*
|
|
2356
2377
|
* @param address - Context address identifier
|
|
2357
2378
|
* @param message - Additional data to associate with the address
|
|
2358
2379
|
* @throws {SetContextError} When context parameters are invalid
|
|
@@ -2434,27 +2455,27 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
2434
2455
|
}
|
|
2435
2456
|
}
|
|
2436
2457
|
/**
|
|
2437
|
-
* Returns the currently configured
|
|
2458
|
+
* Returns the currently configured cancel callback URL
|
|
2438
2459
|
*
|
|
2439
|
-
* If no custom
|
|
2440
|
-
* Reclaim service
|
|
2460
|
+
* If no custom cancel callback URL was set via setCancelCallbackUrl(), this returns the default
|
|
2461
|
+
* Reclaim service cancel callback URL with the current session ID.
|
|
2441
2462
|
*
|
|
2442
|
-
* @returns The
|
|
2443
|
-
* @throws {GetAppCallbackUrlError} When unable to retrieve the
|
|
2463
|
+
* @returns The cancel callback URL where proofs will be submitted
|
|
2464
|
+
* @throws {GetAppCallbackUrlError} When unable to retrieve the cancel callback URL
|
|
2444
2465
|
*
|
|
2445
2466
|
* @example
|
|
2446
2467
|
* ```typescript
|
|
2447
|
-
* const callbackUrl = proofRequest.
|
|
2468
|
+
* const callbackUrl = proofRequest.getCancelCallbackUrl();
|
|
2448
2469
|
* console.log('Errors will be sent to:', callbackUrl);
|
|
2449
2470
|
* ```
|
|
2450
2471
|
*/
|
|
2451
|
-
|
|
2472
|
+
getCancelCallbackUrl() {
|
|
2452
2473
|
try {
|
|
2453
|
-
validateFunctionParams([{ input: this.sessionId, paramName: "sessionId", isString: true }], "
|
|
2454
|
-
return this.
|
|
2474
|
+
validateFunctionParams([{ input: this.sessionId, paramName: "sessionId", isString: true }], "getCancelCallbackUrl");
|
|
2475
|
+
return this.cancelCallbackUrl || `${constants.DEFAULT_RECLAIM_CANCEL_CALLBACK_URL}${this.sessionId}`;
|
|
2455
2476
|
} catch (error) {
|
|
2456
|
-
logger7.info("Error getting
|
|
2457
|
-
throw new GetAppCallbackUrlError("Error getting
|
|
2477
|
+
logger7.info("Error getting cancel callback url", error);
|
|
2478
|
+
throw new GetAppCallbackUrlError("Error getting cancel callback url", error);
|
|
2458
2479
|
}
|
|
2459
2480
|
}
|
|
2460
2481
|
/**
|
|
@@ -2569,8 +2590,8 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
2569
2590
|
parameters: this.parameters,
|
|
2570
2591
|
signature: this.signature,
|
|
2571
2592
|
redirectUrl: this.redirectUrl,
|
|
2572
|
-
|
|
2573
|
-
|
|
2593
|
+
cancelCallbackUrl: this.cancelCallbackUrl,
|
|
2594
|
+
cancelRedirectUrl: this.cancelRedirectUrl,
|
|
2574
2595
|
timestamp: this.timeStamp,
|
|
2575
2596
|
// New field with correct spelling
|
|
2576
2597
|
timeStamp: this.timeStamp,
|
|
@@ -2866,7 +2887,16 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
2866
2887
|
* and custom callback URLs.
|
|
2867
2888
|
*
|
|
2868
2889
|
* For default callbacks: Verifies proofs automatically and passes them to onSuccess
|
|
2869
|
-
* 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.
|
|
2870
2900
|
*
|
|
2871
2901
|
* @param onSuccess - Callback function invoked when proof is successfully submitted
|
|
2872
2902
|
* @param onError - Callback function invoked when an error occurs during the session
|
|
@@ -2942,7 +2972,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
2942
2972
|
}
|
|
2943
2973
|
if (statusUrlResponse.session.statusV2 === "PROOF_SUBMITTED" /* PROOF_SUBMITTED */ || statusUrlResponse.session.statusV2 === "AI_PROOF_SUBMITTED" /* AI_PROOF_SUBMITTED */) {
|
|
2944
2974
|
if (onSuccess) {
|
|
2945
|
-
onSuccess(
|
|
2975
|
+
onSuccess([]);
|
|
2946
2976
|
}
|
|
2947
2977
|
this.clearInterval();
|
|
2948
2978
|
(_c = this.modal) == null ? void 0 : _c.close();
|