@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/README.md +95 -22
- package/dist/index.d.ts +153 -12
- package/dist/index.js +158 -30
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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:
|
|
@@ -80,15 +82,17 @@ function App() {
|
|
|
80
82
|
|
|
81
83
|
await reclaimProofRequest.startSession({
|
|
82
84
|
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") {
|
|
85
|
+
if (proofs && typeof proofs !== "string") {
|
|
88
86
|
// When using the default callback url, we get a proof
|
|
89
87
|
if (Array.isArray(proofs)) {
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
if (proofs.length == 0) {
|
|
89
|
+
// From version 4.10.1, this is the case when using a custom callback url
|
|
90
|
+
// Proofs are sent to the callback url.
|
|
91
|
+
console.log("No proofs received. This is expected when using a custom callback url.");
|
|
92
|
+
} else {
|
|
93
|
+
// when using the cascading providers, providers having more than one proof will return an array of proofs
|
|
94
|
+
console.log(JSON.stringify(proofs.map((p) => p.claimData.context)));
|
|
95
|
+
}
|
|
92
96
|
} else {
|
|
93
97
|
console.log("Proof received:", proofs?.claimData.context);
|
|
94
98
|
}
|
|
@@ -164,12 +168,13 @@ async function handleCreateClaim() {
|
|
|
164
168
|
// Listen for the verification results
|
|
165
169
|
await reclaimProofRequest.startSession({
|
|
166
170
|
onSuccess: (proofs) => {
|
|
167
|
-
if (proofs && typeof proofs
|
|
168
|
-
console.log("SDK Message:", proofs);
|
|
169
|
-
setProofs(proofs);
|
|
170
|
-
} else if (proofs && typeof proofs !== "string") {
|
|
171
|
+
if (proofs && typeof proofs !== "string") {
|
|
171
172
|
if (Array.isArray(proofs)) {
|
|
172
|
-
|
|
173
|
+
if (proofs.length == 0) {
|
|
174
|
+
// proofs sent to callback url
|
|
175
|
+
} else {
|
|
176
|
+
console.log(JSON.stringify(proofs.map((p) => p.claimData.context)));
|
|
177
|
+
}
|
|
173
178
|
} else {
|
|
174
179
|
console.log("Proof received:", proofs?.claimData.context);
|
|
175
180
|
}
|
|
@@ -282,7 +287,7 @@ Your Reclaim SDK demo should now be running. Click the "Create Claim" button to
|
|
|
282
287
|
|
|
283
288
|
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
289
|
|
|
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
|
|
290
|
+
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
291
|
|
|
287
292
|
5. **Handling Failures**: The `onFailure` is called if verification fails, allowing you to handle errors gracefully.
|
|
288
293
|
|
|
@@ -309,32 +314,96 @@ The Reclaim SDK offers several advanced options to customize your integration:
|
|
|
309
314
|
|
|
310
315
|
3. **Custom Redirect URL**:
|
|
311
316
|
|
|
312
|
-
Set a custom URL to redirect users after the verification process
|
|
317
|
+
Set a custom URL to redirect users after the verification process.
|
|
313
318
|
|
|
314
319
|
```javascript
|
|
315
320
|
reclaimProofRequest.setRedirectUrl("https://example.com/redirect");
|
|
316
321
|
```
|
|
317
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
|
+
|
|
318
341
|
4. **Custom Cancel Redirect URL**:
|
|
319
|
-
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
|
+
|
|
320
344
|
|
|
321
345
|
```javascript
|
|
322
346
|
reclaimProofRequest.setCancelRedirectUrl("https://example.com/error-redirect");
|
|
323
347
|
```
|
|
324
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
|
+
|
|
325
367
|
5. **Custom Callback URL**:
|
|
326
368
|
Set a custom callback URL for your app which allows you to receive proofs and status updates on your callback URL:
|
|
327
|
-
|
|
369
|
+
|
|
370
|
+
**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.
|
|
371
|
+
|
|
372
|
+
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
373
|
|
|
329
374
|
reclaimProofRequest.setAppCallbackUrl("https://example.com/callback", true);
|
|
330
375
|
```
|
|
331
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
|
+
|
|
332
381
|
6. **Custom 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:
|
|
334
382
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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
|
+
|
|
338
407
|
|
|
339
408
|
7. **Modal Customization for Desktop Users**:
|
|
340
409
|
Customize the appearance and behavior of the QR code modal shown to desktop users:
|
|
@@ -476,6 +545,9 @@ For production applications, it's recommended to handle proofs, and cancellation
|
|
|
476
545
|
|
|
477
546
|
These options allow you to securely process proofs or cancellations on your server.
|
|
478
547
|
|
|
548
|
+
> [!TIP]
|
|
549
|
+
> **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.
|
|
550
|
+
|
|
479
551
|
## Proof Verification
|
|
480
552
|
|
|
481
553
|
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 +590,9 @@ try {
|
|
|
518
590
|
const proofRequest = await ReclaimProofRequest.init(APP_ID, APP_SECRET, PROVIDER_ID);
|
|
519
591
|
|
|
520
592
|
await proofRequest.startSession({
|
|
521
|
-
onSuccess: (
|
|
522
|
-
|
|
593
|
+
onSuccess: (proofs) => {
|
|
594
|
+
// proofs can be empty if callback url set
|
|
595
|
+
console.log("Proof received:", proofs);
|
|
523
596
|
},
|
|
524
597
|
onError: (error) => {
|
|
525
598
|
// Handle different error types
|
package/dist/index.d.ts
CHANGED
|
@@ -49,11 +49,25 @@ 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;
|
|
55
69
|
};
|
|
56
|
-
type OnSuccess = (proof?: Proof | Proof[]
|
|
70
|
+
type OnSuccess = (proof?: Proof | Proof[]) => void;
|
|
57
71
|
type OnError = (error: Error) => void;
|
|
58
72
|
type ProofRequestOptions = {
|
|
59
73
|
/**
|
|
@@ -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
|
|
@@ -237,8 +325,10 @@ declare class ReclaimProofRequest {
|
|
|
237
325
|
private resolvedProviderVersion?;
|
|
238
326
|
private parameters;
|
|
239
327
|
private redirectUrl?;
|
|
328
|
+
private redirectUrlOptions?;
|
|
240
329
|
private cancelCallbackUrl?;
|
|
241
330
|
private cancelRedirectUrl?;
|
|
331
|
+
private cancelRedirectUrlOptions?;
|
|
242
332
|
private intervals;
|
|
243
333
|
private timeStamp;
|
|
244
334
|
private sdkVersion;
|
|
@@ -292,16 +382,21 @@ declare class ReclaimProofRequest {
|
|
|
292
382
|
*/
|
|
293
383
|
static fromJsonString(jsonString: string): Promise<ReclaimProofRequest>;
|
|
294
384
|
/**
|
|
295
|
-
* Sets a custom callback URL where proofs will be submitted via HTTP POST
|
|
385
|
+
* Sets a custom callback URL where proofs will be submitted via HTTP `POST`
|
|
296
386
|
*
|
|
297
|
-
* By default, proofs are
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
387
|
+
* By default, proofs are sent as HTTP POST with `Content-Type` as `application/x-www-form-urlencoded`.
|
|
388
|
+
* Pass function argument `jsonProofResponse` as `true` to send proofs with `Content-Type` as `application/json`.
|
|
389
|
+
*
|
|
390
|
+
* When a custom callback URL is set, proofs are sent to the custom URL *instead* of the Reclaim backend.
|
|
391
|
+
* Consequently, the startSession `onSuccess` callback will be invoked with an empty array (`[]`)
|
|
392
|
+
* instead of the proof data, as the proof is not available to the SDK in this flow.
|
|
393
|
+
*
|
|
394
|
+
* This verification session's id will be present in `X-Reclaim-Session-Id` header of the request.
|
|
395
|
+
* The request URL will contain query param `allowAiWitness` with value `true` when AI Witness should be allowed by handler of the request.
|
|
301
396
|
*
|
|
302
397
|
* Note: InApp SDKs are unaffected by this property as they do not handle proof submission.
|
|
303
398
|
*
|
|
304
|
-
* @param url - The URL where proofs should be submitted via HTTP POST
|
|
399
|
+
* @param url - The URL where proofs should be submitted via HTTP `POST`
|
|
305
400
|
* @param jsonProofResponse - Optional. Set to true to submit proofs as `application/json`. Defaults to false
|
|
306
401
|
* @throws {InvalidParamError} When URL is invalid
|
|
307
402
|
*
|
|
@@ -317,6 +412,13 @@ declare class ReclaimProofRequest {
|
|
|
317
412
|
* Sets a redirect URL where users will be redirected after successfully acquiring and submitting proof
|
|
318
413
|
*
|
|
319
414
|
* @param url - The URL where users should be redirected after successful proof generation
|
|
415
|
+
* @param method - The redirection method that should be used for redirection. Allowed options: `GET`, and `POST`.
|
|
416
|
+
* `POST` form redirection is only supported in In-Browser SDK.
|
|
417
|
+
* @param body - List of name-value pairs to be sent as the body of the form request.
|
|
418
|
+
* `When `method` is set to `POST`, `body` will be sent with 'application/x-www-form-urlencoded' content type.
|
|
419
|
+
* When `method` is set to `GET`, if `body` is set then `body` will be sent as query parameters.
|
|
420
|
+
* Sending `body` on redirection is only supported in In-Browser SDK.
|
|
421
|
+
*
|
|
320
422
|
* @throws {InvalidParamError} When URL is invalid
|
|
321
423
|
*
|
|
322
424
|
* @example
|
|
@@ -324,7 +426,7 @@ declare class ReclaimProofRequest {
|
|
|
324
426
|
* proofRequest.setRedirectUrl('https://your-app.com/success');
|
|
325
427
|
* ```
|
|
326
428
|
*/
|
|
327
|
-
setRedirectUrl(url: string): void;
|
|
429
|
+
setRedirectUrl(url: string, method?: HttpRedirectionMethod, body?: HttpFormEntry[] | undefined): void;
|
|
328
430
|
/**
|
|
329
431
|
* Sets a custom callback URL where errors that abort the verification process will be submitted via HTTP POST
|
|
330
432
|
*
|
|
@@ -333,6 +435,24 @@ declare class ReclaimProofRequest {
|
|
|
333
435
|
* and listeners on the startSession method will not be triggered. Your application must
|
|
334
436
|
* coordinate with your backend to receive errors.
|
|
335
437
|
*
|
|
438
|
+
* This verification session's id will be present in `X-Reclaim-Session-Id` header of the request.
|
|
439
|
+
*
|
|
440
|
+
* Following is the data format which is sent as an HTTP POST request to the url with `Content-Type: application/json`:
|
|
441
|
+
|
|
442
|
+
* ```json
|
|
443
|
+
* {
|
|
444
|
+
* "type": "string", // Name of the exception
|
|
445
|
+
* "message": "string",
|
|
446
|
+
* "sessionId": "string",
|
|
447
|
+
* // context as canonicalized json string
|
|
448
|
+
* "context": "string",
|
|
449
|
+
* // Other fields with more details about error may be present
|
|
450
|
+
* // [key: any]: any
|
|
451
|
+
* }
|
|
452
|
+
* ```
|
|
453
|
+
*
|
|
454
|
+
* For more details about response format, check out [official documentation of Error Callback URL](https://docs.reclaimprotocol.org/js-sdk/preparing-request#cancel-callback).
|
|
455
|
+
*
|
|
336
456
|
* @param url - The URL where errors should be submitted via HTTP POST
|
|
337
457
|
* @throws {InvalidParamError} When URL is invalid
|
|
338
458
|
*
|
|
@@ -349,6 +469,12 @@ declare class ReclaimProofRequest {
|
|
|
349
469
|
* Sets an error redirect URL where users will be redirected after an error which aborts the verification process
|
|
350
470
|
*
|
|
351
471
|
* @param url - The URL where users should be redirected after an error which aborts the verification process
|
|
472
|
+
* @param method - The redirection method that should be used for redirection. Allowed options: `GET`, and `POST`.
|
|
473
|
+
* `POST` form redirection is only supported in In-Browser SDK.
|
|
474
|
+
* @param body - List of name-value pairs to be sent as the body of the form request.
|
|
475
|
+
* When `method` is set to `POST`, `body` will be sent with 'application/x-www-form-urlencoded' content type.
|
|
476
|
+
* When `method` is set to `GET`, if `body` is set then `body` will be sent as query parameters.
|
|
477
|
+
* Sending `body` on redirection is only supported in In-Browser SDK.
|
|
352
478
|
* @throws {InvalidParamError} When URL is invalid
|
|
353
479
|
*
|
|
354
480
|
* @example
|
|
@@ -359,7 +485,7 @@ declare class ReclaimProofRequest {
|
|
|
359
485
|
* @since 4.10.0
|
|
360
486
|
*
|
|
361
487
|
*/
|
|
362
|
-
setCancelRedirectUrl(url: string): void;
|
|
488
|
+
setCancelRedirectUrl(url: string, method?: HttpRedirectionMethod, body?: HttpFormEntry[] | undefined): void;
|
|
363
489
|
/**
|
|
364
490
|
* Sets the claim creation type for the proof request
|
|
365
491
|
*
|
|
@@ -390,11 +516,13 @@ declare class ReclaimProofRequest {
|
|
|
390
516
|
/**
|
|
391
517
|
* Sets additional context data to be stored with the claim
|
|
392
518
|
*
|
|
393
|
-
* This allows you to associate custom
|
|
519
|
+
* This allows you to associate custom JSON serializable data with the proof claim.
|
|
394
520
|
* The context can be retrieved and validated when verifying the proof.
|
|
395
521
|
*
|
|
396
522
|
* Also see [setContext] which is an alternate way to set context that has an address & message.
|
|
397
523
|
*
|
|
524
|
+
* [setContext] and [setJsonContext] overwrite each other. Each call replaces the existing context.
|
|
525
|
+
*
|
|
398
526
|
* @param context - Any additional data you want to store with the claim. Should be serializable to a JSON string.
|
|
399
527
|
* @throws {SetContextError} When context parameters are invalid
|
|
400
528
|
*
|
|
@@ -410,6 +538,10 @@ declare class ReclaimProofRequest {
|
|
|
410
538
|
* This allows you to associate custom data (address and message) with the proof claim.
|
|
411
539
|
* The context can be retrieved and validated when verifying the proof.
|
|
412
540
|
*
|
|
541
|
+
* Also see [setJsonContext] which is an alternate way to set context that allows for custom JSON serializable data.
|
|
542
|
+
*
|
|
543
|
+
* [setContext] and [setJsonContext] overwrite each other. Each call replaces the existing context.
|
|
544
|
+
*
|
|
413
545
|
* @param address - Context address identifier
|
|
414
546
|
* @param message - Additional data to associate with the address
|
|
415
547
|
* @throws {SetContextError} When context parameters are invalid
|
|
@@ -606,7 +738,16 @@ declare class ReclaimProofRequest {
|
|
|
606
738
|
* and custom callback URLs.
|
|
607
739
|
*
|
|
608
740
|
* For default callbacks: Verifies proofs automatically and passes them to onSuccess
|
|
609
|
-
* For custom callbacks: Monitors submission status and notifies via onSuccess when complete
|
|
741
|
+
* For custom callbacks: Monitors submission status and notifies via onSuccess when complete.
|
|
742
|
+
* In the custom-callback flow (where the SDK submits a proof to a provided callback URL),
|
|
743
|
+
* onSuccess may be invoked with an empty array (onSuccess([])) when no proof is available
|
|
744
|
+
* (this happens when a callback is set using setAppCallbackUrl where proof is sent to callback instead of reclaim backend).
|
|
745
|
+
*
|
|
746
|
+
* Please refer to the OnSuccess type signature ((proof?: Proof | Proof[]) => void)
|
|
747
|
+
* and the startSession function source for more details.
|
|
748
|
+
*
|
|
749
|
+
* > [!TIP]
|
|
750
|
+
* > **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
751
|
*
|
|
611
752
|
* @param onSuccess - Callback function invoked when proof is successfully submitted
|
|
612
753
|
* @param onError - Callback function invoked when an error occurs during the session
|
|
@@ -683,4 +824,4 @@ declare function isDesktopDevice(): boolean;
|
|
|
683
824
|
*/
|
|
684
825
|
declare function clearDeviceCache(): void;
|
|
685
826
|
|
|
686
|
-
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 };
|
|
827
|
+
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, clearDeviceCache, getDeviceType, getMobileDeviceType, isDesktopDevice, isMobileDevice, transformForOnchain, verifyProof };
|