@reclaimprotocol/js-sdk 4.5.1 → 4.5.2
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 +156 -161
- package/dist/index.d.ts +1 -0
- package/dist/index.js +13 -6
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -42,67 +42,63 @@ npm install @reclaimprotocol/js-sdk react-qr-code
|
|
|
42
42
|
Replace the contents of `src/App.js` with the following code:
|
|
43
43
|
|
|
44
44
|
```javascript
|
|
45
|
-
import React, { useState, useEffect } from
|
|
46
|
-
import { ReclaimProofRequest, verifyProof, ClaimCreationType } from
|
|
47
|
-
import QRCode from
|
|
45
|
+
import React, { useState, useEffect } from "react";
|
|
46
|
+
import { ReclaimProofRequest, verifyProof, ClaimCreationType } from "@reclaimprotocol/js-sdk";
|
|
47
|
+
import QRCode from "react-qr-code";
|
|
48
48
|
|
|
49
49
|
function App() {
|
|
50
|
-
const [reclaimProofRequest, setReclaimProofRequest] = useState(null)
|
|
51
|
-
const [requestUrl, setRequestUrl] = useState(
|
|
52
|
-
const [statusUrl, setStatusUrl] = useState(
|
|
53
|
-
const [proofs, setProofs] = useState(null)
|
|
50
|
+
const [reclaimProofRequest, setReclaimProofRequest] = useState(null);
|
|
51
|
+
const [requestUrl, setRequestUrl] = useState("");
|
|
52
|
+
const [statusUrl, setStatusUrl] = useState("");
|
|
53
|
+
const [proofs, setProofs] = useState(null);
|
|
54
54
|
|
|
55
55
|
useEffect(() => {
|
|
56
56
|
async function initializeReclaim() {
|
|
57
|
-
const APP_ID =
|
|
58
|
-
const APP_SECRET =
|
|
59
|
-
const PROVIDER_ID =
|
|
60
|
-
|
|
61
|
-
const proofRequest = await ReclaimProofRequest.init(
|
|
62
|
-
|
|
63
|
-
APP_SECRET,
|
|
64
|
-
PROVIDER_ID
|
|
65
|
-
)
|
|
66
|
-
setReclaimProofRequest(proofRequest)
|
|
57
|
+
const APP_ID = "YOUR_APPLICATION_ID_HERE";
|
|
58
|
+
const APP_SECRET = "YOUR_APPLICATION_SECRET_HERE";
|
|
59
|
+
const PROVIDER_ID = "YOUR_PROVIDER_ID_HERE";
|
|
60
|
+
|
|
61
|
+
const proofRequest = await ReclaimProofRequest.init(APP_ID, APP_SECRET, PROVIDER_ID);
|
|
62
|
+
setReclaimProofRequest(proofRequest);
|
|
67
63
|
}
|
|
68
64
|
|
|
69
|
-
initializeReclaim()
|
|
70
|
-
}, [])
|
|
65
|
+
initializeReclaim();
|
|
66
|
+
}, []);
|
|
71
67
|
|
|
72
68
|
async function handleCreateClaim() {
|
|
73
69
|
if (!reclaimProofRequest) {
|
|
74
|
-
console.error(
|
|
75
|
-
return
|
|
70
|
+
console.error("Reclaim Proof Request not initialized");
|
|
71
|
+
return;
|
|
76
72
|
}
|
|
77
73
|
|
|
78
|
-
const url = await reclaimProofRequest.getRequestUrl()
|
|
79
|
-
setRequestUrl(url)
|
|
74
|
+
const url = await reclaimProofRequest.getRequestUrl();
|
|
75
|
+
setRequestUrl(url);
|
|
80
76
|
|
|
81
|
-
const status = reclaimProofRequest.getStatusUrl()
|
|
82
|
-
setStatusUrl(status)
|
|
83
|
-
console.log(
|
|
77
|
+
const status = reclaimProofRequest.getStatusUrl();
|
|
78
|
+
setStatusUrl(status);
|
|
79
|
+
console.log("Status URL:", status);
|
|
84
80
|
|
|
85
81
|
await reclaimProofRequest.startSession({
|
|
86
82
|
onSuccess: (proofs) => {
|
|
87
|
-
if (proofs && typeof proofs
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
setProofs(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") {
|
|
88
|
+
// When using the default callback url, we get a proof
|
|
89
|
+
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)));
|
|
92
|
+
} else {
|
|
93
|
+
console.log("Proof received:", proofs?.claimData.context);
|
|
100
94
|
}
|
|
95
|
+
setProofs(proofs);
|
|
96
|
+
}
|
|
101
97
|
},
|
|
102
98
|
onFailure: (error) => {
|
|
103
|
-
console.error(
|
|
104
|
-
}
|
|
105
|
-
})
|
|
99
|
+
console.error("Verification failed", error);
|
|
100
|
+
},
|
|
101
|
+
});
|
|
106
102
|
}
|
|
107
103
|
|
|
108
104
|
return (
|
|
@@ -122,10 +118,10 @@ function App() {
|
|
|
122
118
|
</div>
|
|
123
119
|
)}
|
|
124
120
|
</div>
|
|
125
|
-
)
|
|
121
|
+
);
|
|
126
122
|
}
|
|
127
123
|
|
|
128
|
-
export default App
|
|
124
|
+
export default App;
|
|
129
125
|
```
|
|
130
126
|
|
|
131
127
|
## Step 4: Understanding the code
|
|
@@ -135,6 +131,7 @@ Let's break down what's happening in this code:
|
|
|
135
131
|
1. We initialize the Reclaim SDK with your application ID, secret, and provider ID. This happens once when the component mounts.
|
|
136
132
|
|
|
137
133
|
2. When the user clicks the "Create Claim" button, we:
|
|
134
|
+
|
|
138
135
|
- Generate a request URL using `getRequestUrl()`. This URL is used to create the QR code.
|
|
139
136
|
- Get the status URL using `getStatusUrl()`. This URL can be used to check the status of the claim process.
|
|
140
137
|
- Start a session with `startSession()`, which sets up callbacks for successful and failed verifications.
|
|
@@ -156,35 +153,35 @@ Replace the `handleCreateClaim` function in your React component with this simpl
|
|
|
156
153
|
```javascript
|
|
157
154
|
async function handleCreateClaim() {
|
|
158
155
|
if (!reclaimProofRequest) {
|
|
159
|
-
console.error(
|
|
160
|
-
return
|
|
156
|
+
console.error("Reclaim Proof Request not initialized");
|
|
157
|
+
return;
|
|
161
158
|
}
|
|
162
159
|
|
|
163
160
|
try {
|
|
164
161
|
// Start the verification process automatically
|
|
165
|
-
await reclaimProofRequest.triggerReclaimFlow()
|
|
166
|
-
|
|
162
|
+
await reclaimProofRequest.triggerReclaimFlow();
|
|
163
|
+
|
|
167
164
|
// Listen for the verification results
|
|
168
165
|
await reclaimProofRequest.startSession({
|
|
169
166
|
onSuccess: (proofs) => {
|
|
170
|
-
if (proofs && typeof proofs ===
|
|
171
|
-
console.log(
|
|
172
|
-
setProofs(proofs)
|
|
173
|
-
} else if (proofs && typeof proofs !==
|
|
167
|
+
if (proofs && typeof proofs === "string") {
|
|
168
|
+
console.log("SDK Message:", proofs);
|
|
169
|
+
setProofs(proofs);
|
|
170
|
+
} else if (proofs && typeof proofs !== "string") {
|
|
174
171
|
if (Array.isArray(proofs)) {
|
|
175
|
-
console.log(JSON.stringify(proofs.map(p => p.claimData.context)))
|
|
172
|
+
console.log(JSON.stringify(proofs.map((p) => p.claimData.context)));
|
|
176
173
|
} else {
|
|
177
|
-
console.log(
|
|
174
|
+
console.log("Proof received:", proofs?.claimData.context);
|
|
178
175
|
}
|
|
179
|
-
setProofs(proofs)
|
|
176
|
+
setProofs(proofs);
|
|
180
177
|
}
|
|
181
178
|
},
|
|
182
179
|
onFailure: (error) => {
|
|
183
|
-
console.error(
|
|
184
|
-
}
|
|
185
|
-
})
|
|
180
|
+
console.error("Verification failed", error);
|
|
181
|
+
},
|
|
182
|
+
});
|
|
186
183
|
} catch (error) {
|
|
187
|
-
console.error(
|
|
184
|
+
console.error("Error triggering Reclaim flow:", error);
|
|
188
185
|
}
|
|
189
186
|
}
|
|
190
187
|
```
|
|
@@ -194,10 +191,12 @@ async function handleCreateClaim() {
|
|
|
194
191
|
The `triggerReclaimFlow()` method automatically detects the user's environment and chooses the optimal verification method:
|
|
195
192
|
|
|
196
193
|
#### On Desktop Browsers:
|
|
194
|
+
|
|
197
195
|
1. **Browser Extension First**: If the Reclaim browser extension is installed, it will use the extension for a seamless in-browser verification experience.
|
|
198
196
|
2. **QR Code Fallback**: If the extension is not available, it automatically displays a QR code modal for mobile scanning.
|
|
199
197
|
|
|
200
198
|
#### On Mobile Devices:
|
|
199
|
+
|
|
201
200
|
1. **iOS Devices**: Automatically redirects to the Reclaim App Clip for native iOS verification.
|
|
202
201
|
2. **Android Devices**: Automatically redirects to the Reclaim Instant App for native Android verification.
|
|
203
202
|
|
|
@@ -206,6 +205,7 @@ The `triggerReclaimFlow()` method automatically detects the user's environment a
|
|
|
206
205
|
The SDK now includes built-in support for the Reclaim browser extension, providing users with a seamless verification experience without leaving their current browser tab.
|
|
207
206
|
|
|
208
207
|
#### Features:
|
|
208
|
+
|
|
209
209
|
- **Automatic Detection**: The SDK automatically detects if the Reclaim browser extension is installed
|
|
210
210
|
- **Seamless Integration**: No additional setup required - the extension integration works out of the box
|
|
211
211
|
- **Fallback Support**: If the extension is not available, the SDK gracefully falls back to QR code or mobile app flows
|
|
@@ -215,11 +215,11 @@ The SDK now includes built-in support for the Reclaim browser extension, providi
|
|
|
215
215
|
You can also manually check if the browser extension is available:
|
|
216
216
|
|
|
217
217
|
```javascript
|
|
218
|
-
const isExtensionAvailable = await reclaimProofRequest.isBrowserExtensionAvailable()
|
|
218
|
+
const isExtensionAvailable = await reclaimProofRequest.isBrowserExtensionAvailable();
|
|
219
219
|
if (isExtensionAvailable) {
|
|
220
|
-
console.log(
|
|
220
|
+
console.log("Reclaim browser extension is installed");
|
|
221
221
|
} else {
|
|
222
|
-
console.log(
|
|
222
|
+
console.log("Browser extension not available, will use alternative flow");
|
|
223
223
|
}
|
|
224
224
|
```
|
|
225
225
|
|
|
@@ -228,16 +228,11 @@ if (isExtensionAvailable) {
|
|
|
228
228
|
You can customize the browser extension behavior during SDK initialization:
|
|
229
229
|
|
|
230
230
|
```javascript
|
|
231
|
-
const proofRequest = await ReclaimProofRequest.init(
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
useBrowserExtension: true, // Enable/disable browser extension (default: true)
|
|
237
|
-
extensionID: 'custom-extension-id', // Use custom extension ID if needed
|
|
238
|
-
// ... other options
|
|
239
|
-
}
|
|
240
|
-
)
|
|
231
|
+
const proofRequest = await ReclaimProofRequest.init(APP_ID, APP_SECRET, PROVIDER_ID, {
|
|
232
|
+
useBrowserExtension: true, // Enable/disable browser extension (default: true)
|
|
233
|
+
extensionID: "custom-extension-id", // Use custom extension ID if needed
|
|
234
|
+
// ... other options
|
|
235
|
+
});
|
|
241
236
|
```
|
|
242
237
|
|
|
243
238
|
### Modal Customization
|
|
@@ -247,18 +242,18 @@ When the QR code modal is displayed (fallback on desktop), you can customize its
|
|
|
247
242
|
```javascript
|
|
248
243
|
// Set modal options before triggering the flow
|
|
249
244
|
reclaimProofRequest.setModalOptions({
|
|
250
|
-
title:
|
|
251
|
-
description:
|
|
245
|
+
title: "Custom Verification Title",
|
|
246
|
+
description: "Scan this QR code with your mobile device to verify your account",
|
|
252
247
|
darkTheme: true, // Enable dark theme (default: false)
|
|
253
248
|
modalPopupTimer: 5, // Auto-close modal after 5 minutes (default: 1 minute)
|
|
254
249
|
showExtensionInstallButton: true, // Show extension install button (default: false)
|
|
255
|
-
extensionUrl:
|
|
250
|
+
extensionUrl: "https://custom-extension-url.com", // Custom extension download URL
|
|
256
251
|
onClose: () => {
|
|
257
|
-
console.log(
|
|
258
|
-
} // Callback when modal is closed
|
|
259
|
-
})
|
|
252
|
+
console.log("Modal was closed");
|
|
253
|
+
}, // Callback when modal is closed
|
|
254
|
+
});
|
|
260
255
|
|
|
261
|
-
await reclaimProofRequest.triggerReclaimFlow()
|
|
256
|
+
await reclaimProofRequest.triggerReclaimFlow();
|
|
262
257
|
```
|
|
263
258
|
|
|
264
259
|
### Benefits of the New Flow:
|
|
@@ -297,114 +292,116 @@ The Reclaim SDK offers several advanced options to customize your integration:
|
|
|
297
292
|
|
|
298
293
|
1. **Adding Context**:
|
|
299
294
|
You can add context to your proof request, which can be useful for providing additional information:
|
|
295
|
+
|
|
300
296
|
```javascript
|
|
301
|
-
reclaimProofRequest.
|
|
297
|
+
reclaimProofRequest.setContext("0x00000000000", "Example context message");
|
|
298
|
+
|
|
299
|
+
// deprecated method: use setContext instead
|
|
300
|
+
reclaimProofRequest.addContext("0x00000000000", "Example context message");
|
|
302
301
|
```
|
|
303
302
|
|
|
304
303
|
2. **Setting Parameters**:
|
|
305
304
|
If your provider requires specific parameters, you can set them like this:
|
|
305
|
+
|
|
306
306
|
```javascript
|
|
307
|
-
reclaimProofRequest.setParams({ email: "test@example.com", userName: "testUser" })
|
|
307
|
+
reclaimProofRequest.setParams({ email: "test@example.com", userName: "testUser" });
|
|
308
308
|
```
|
|
309
309
|
|
|
310
310
|
3. **Custom Redirect URL**:
|
|
311
311
|
Set a custom URL to redirect users after the verification process:
|
|
312
|
+
|
|
312
313
|
```javascript
|
|
313
|
-
reclaimProofRequest.setRedirectUrl(
|
|
314
|
+
reclaimProofRequest.setRedirectUrl("https://example.com/redirect");
|
|
314
315
|
```
|
|
315
316
|
|
|
316
317
|
4. **Custom Callback URL**:
|
|
317
318
|
Set a custom callback URL for your app which allows you to receive proofs and status updates on your callback URL:
|
|
318
319
|
Pass in `jsonProofResponse: true` to receive the proof in JSON format: By default, the proof is returned as a url encoded string.
|
|
320
|
+
|
|
319
321
|
```javascript
|
|
320
|
-
reclaimProofRequest.setAppCallbackUrl(
|
|
322
|
+
reclaimProofRequest.setAppCallbackUrl("https://example.com/callback", true);
|
|
321
323
|
```
|
|
322
324
|
|
|
323
325
|
5. **Modal Customization for Desktop Users**:
|
|
324
326
|
Customize the appearance and behavior of the QR code modal shown to desktop users:
|
|
327
|
+
|
|
325
328
|
```javascript
|
|
326
329
|
reclaimProofRequest.setModalOptions({
|
|
327
|
-
title:
|
|
328
|
-
description:
|
|
330
|
+
title: "Verify Your Account",
|
|
331
|
+
description: "Scan the QR code with your mobile device or install our browser extension",
|
|
329
332
|
darkTheme: false, // Enable dark theme (default: false)
|
|
330
|
-
extensionUrl:
|
|
331
|
-
})
|
|
333
|
+
extensionUrl: "https://chrome.google.com/webstore/detail/reclaim", // Custom extension URL
|
|
334
|
+
});
|
|
332
335
|
```
|
|
333
336
|
|
|
334
337
|
6. **Browser Extension Configuration**:
|
|
335
338
|
Configure browser extension behavior and detection:
|
|
339
|
+
|
|
336
340
|
```javascript
|
|
337
341
|
// Check if browser extension is available
|
|
338
|
-
const isExtensionAvailable = await reclaimProofRequest.isBrowserExtensionAvailable()
|
|
339
|
-
|
|
342
|
+
const isExtensionAvailable = await reclaimProofRequest.isBrowserExtensionAvailable();
|
|
343
|
+
|
|
340
344
|
// Trigger the verification flow with automatic platform detection
|
|
341
|
-
await reclaimProofRequest.triggerReclaimFlow()
|
|
342
|
-
|
|
345
|
+
await reclaimProofRequest.triggerReclaimFlow();
|
|
346
|
+
|
|
343
347
|
// Initialize with browser extension options
|
|
344
|
-
const proofRequest = await ReclaimProofRequest.init(
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
extensionID: 'custom-extension-id', // Custom extension identifier
|
|
351
|
-
useAppClip: true, // Enable mobile app clips (default: true)
|
|
352
|
-
log: true // Enable logging for debugging
|
|
353
|
-
}
|
|
354
|
-
)
|
|
348
|
+
const proofRequest = await ReclaimProofRequest.init(APP_ID, APP_SECRET, PROVIDER_ID, {
|
|
349
|
+
useBrowserExtension: true, // Enable browser extension support (default: true)
|
|
350
|
+
extensionID: "custom-extension-id", // Custom extension identifier
|
|
351
|
+
useAppClip: true, // Enable mobile app clips (default: true)
|
|
352
|
+
log: true, // Enable logging for debugging
|
|
353
|
+
});
|
|
355
354
|
```
|
|
356
355
|
|
|
357
356
|
7. **Custom Share Page and App Clip URLs**:
|
|
358
|
-
You can customize the share page and app clip URLs for your app:
|
|
359
|
-
|
|
360
|
-
```javascript
|
|
361
|
-
const proofRequest = await ReclaimProofRequest.init(
|
|
362
|
-
APP_ID,
|
|
363
|
-
APP_SECRET,
|
|
364
|
-
PROVIDER_ID,
|
|
365
|
-
{
|
|
366
|
-
customSharePageUrl: 'https://your-custom-domain.com/verify', // Custom share page URL
|
|
367
|
-
customAppClipUrl: 'https://appclip.apple.com/id?p=your.custom.app.clip', // Custom iOS App Clip URL
|
|
368
|
-
// ... other options
|
|
369
|
-
}
|
|
370
|
-
)
|
|
371
|
-
```
|
|
357
|
+
You can customize the share page and app clip URLs for your app:
|
|
372
358
|
|
|
359
|
+
```javascript
|
|
360
|
+
const proofRequest = await ReclaimProofRequest.init(APP_ID, APP_SECRET, PROVIDER_ID, {
|
|
361
|
+
customSharePageUrl: "https://your-custom-domain.com/verify", // Custom share page URL
|
|
362
|
+
customAppClipUrl: "https://appclip.apple.com/id?p=your.custom.app.clip", // Custom iOS App Clip URL
|
|
363
|
+
// ... other options
|
|
364
|
+
});
|
|
365
|
+
```
|
|
373
366
|
|
|
374
367
|
8. **Platform-Specific Flow Control**:
|
|
375
368
|
The `triggerReclaimFlow()` method provides intelligent platform detection, but you can still use traditional methods for custom flows:
|
|
369
|
+
|
|
376
370
|
```javascript
|
|
377
371
|
// Traditional approach with manual QR code handling
|
|
378
|
-
const requestUrl = await reclaimProofRequest.getRequestUrl()
|
|
372
|
+
const requestUrl = await reclaimProofRequest.getRequestUrl();
|
|
379
373
|
// Display your own QR code implementation
|
|
380
|
-
|
|
374
|
+
|
|
381
375
|
// Or use the new streamlined approach
|
|
382
|
-
await reclaimProofRequest.triggerReclaimFlow()
|
|
376
|
+
await reclaimProofRequest.triggerReclaimFlow();
|
|
383
377
|
// Automatically handles platform detection and optimal user experience
|
|
384
378
|
```
|
|
385
379
|
|
|
386
380
|
9. **Exporting and Importing SDK Configuration**:
|
|
387
381
|
You can export the entire Reclaim SDK configuration as a JSON string and use it to initialize the SDK with the same configuration on a different service or backend:
|
|
382
|
+
|
|
388
383
|
```javascript
|
|
389
384
|
// On the client-side or initial service
|
|
390
|
-
const configJson = reclaimProofRequest.toJsonString()
|
|
391
|
-
console.log(
|
|
392
|
-
|
|
385
|
+
const configJson = reclaimProofRequest.toJsonString();
|
|
386
|
+
console.log("Exportable config:", configJson);
|
|
387
|
+
|
|
393
388
|
// Send this configJson to your backend or another service
|
|
394
|
-
|
|
389
|
+
|
|
395
390
|
// On the backend or different service
|
|
396
|
-
const importedRequest = ReclaimProofRequest.fromJsonString(configJson)
|
|
397
|
-
const requestUrl = await importedRequest.getRequestUrl()
|
|
391
|
+
const importedRequest = ReclaimProofRequest.fromJsonString(configJson);
|
|
392
|
+
const requestUrl = await importedRequest.getRequestUrl();
|
|
398
393
|
```
|
|
394
|
+
|
|
399
395
|
This allows you to generate request URLs and other details from your backend or a different service while maintaining the same configuration.
|
|
400
396
|
|
|
401
397
|
10. **Utility Methods**:
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
398
|
+
Additional utility methods for managing your proof requests:
|
|
399
|
+
|
|
400
|
+
```javascript
|
|
401
|
+
// Get the current session ID
|
|
402
|
+
const sessionId = reclaimProofRequest.getSessionId();
|
|
403
|
+
console.log("Current session ID:", sessionId);
|
|
404
|
+
```
|
|
408
405
|
|
|
409
406
|
## Handling Proofs on Your Backend
|
|
410
407
|
|
|
@@ -412,7 +409,7 @@ For production applications, it's recommended to handle proofs on your backend:
|
|
|
412
409
|
|
|
413
410
|
1. Set a callback URL:
|
|
414
411
|
```javascript
|
|
415
|
-
reclaimProofRequest.setCallbackUrl(
|
|
412
|
+
reclaimProofRequest.setCallbackUrl("https://your-backend.com/receive-proofs");
|
|
416
413
|
```
|
|
417
414
|
|
|
418
415
|
These options allow you to securely process proofs and status updates on your server.
|
|
@@ -422,26 +419,27 @@ These options allow you to securely process proofs and status updates on your se
|
|
|
422
419
|
The SDK provides a `verifyProof` function to manually verify proofs. This is useful when you need to validate proofs outside of the normal flow:
|
|
423
420
|
|
|
424
421
|
```javascript
|
|
425
|
-
import { verifyProof } from
|
|
422
|
+
import { verifyProof } from "@reclaimprotocol/js-sdk";
|
|
426
423
|
|
|
427
424
|
// Verify a single proof
|
|
428
|
-
const isValid = await verifyProof(proof)
|
|
425
|
+
const isValid = await verifyProof(proof);
|
|
429
426
|
if (isValid) {
|
|
430
|
-
console.log(
|
|
427
|
+
console.log("Proof is valid");
|
|
431
428
|
} else {
|
|
432
|
-
console.log(
|
|
429
|
+
console.log("Proof is invalid");
|
|
433
430
|
}
|
|
434
431
|
|
|
435
432
|
// Verify multiple proofs
|
|
436
|
-
const areValid = await verifyProof([proof1, proof2, proof3])
|
|
433
|
+
const areValid = await verifyProof([proof1, proof2, proof3]);
|
|
437
434
|
if (areValid) {
|
|
438
|
-
console.log(
|
|
435
|
+
console.log("All proofs are valid");
|
|
439
436
|
} else {
|
|
440
|
-
console.log(
|
|
437
|
+
console.log("One or more proofs are invalid");
|
|
441
438
|
}
|
|
442
439
|
```
|
|
443
440
|
|
|
444
441
|
The `verifyProof` function:
|
|
442
|
+
|
|
445
443
|
- Accepts either a single proof or an array of proofs
|
|
446
444
|
- Returns a boolean indicating if the proof(s) are valid
|
|
447
445
|
- Verifies signatures, witness integrity, and claim data
|
|
@@ -452,43 +450,40 @@ The `verifyProof` function:
|
|
|
452
450
|
The SDK provides specific error types for different failure scenarios. Here's how to handle them:
|
|
453
451
|
|
|
454
452
|
```javascript
|
|
455
|
-
import { ReclaimProofRequest } from
|
|
453
|
+
import { ReclaimProofRequest } from "@reclaimprotocol/js-sdk";
|
|
456
454
|
|
|
457
455
|
try {
|
|
458
|
-
const proofRequest = await ReclaimProofRequest.init(
|
|
459
|
-
|
|
460
|
-
APP_SECRET,
|
|
461
|
-
PROVIDER_ID
|
|
462
|
-
)
|
|
463
|
-
|
|
456
|
+
const proofRequest = await ReclaimProofRequest.init(APP_ID, APP_SECRET, PROVIDER_ID);
|
|
457
|
+
|
|
464
458
|
await proofRequest.startSession({
|
|
465
459
|
onSuccess: (proof) => {
|
|
466
|
-
console.log(
|
|
460
|
+
console.log("Proof received:", proof);
|
|
467
461
|
},
|
|
468
462
|
onError: (error) => {
|
|
469
463
|
// Handle different error types
|
|
470
|
-
if (error.name ===
|
|
471
|
-
console.error(
|
|
472
|
-
} else if (error.name ===
|
|
473
|
-
console.error(
|
|
474
|
-
} else if (error.name ===
|
|
475
|
-
console.error(
|
|
464
|
+
if (error.name === "ProofNotVerifiedError") {
|
|
465
|
+
console.error("Proof verification failed");
|
|
466
|
+
} else if (error.name === "ProviderFailedError") {
|
|
467
|
+
console.error("Provider failed to generate proof");
|
|
468
|
+
} else if (error.name === "SessionNotStartedError") {
|
|
469
|
+
console.error("Session could not be started");
|
|
476
470
|
} else {
|
|
477
|
-
console.error(
|
|
471
|
+
console.error("Unknown error:", error.message);
|
|
478
472
|
}
|
|
479
|
-
}
|
|
480
|
-
})
|
|
473
|
+
},
|
|
474
|
+
});
|
|
481
475
|
} catch (error) {
|
|
482
476
|
// Handle initialization errors
|
|
483
|
-
if (error.name ===
|
|
484
|
-
console.error(
|
|
485
|
-
} else if (error.name ===
|
|
486
|
-
console.error(
|
|
477
|
+
if (error.name === "InitError") {
|
|
478
|
+
console.error("Failed to initialize SDK:", error.message);
|
|
479
|
+
} else if (error.name === "InvalidParamError") {
|
|
480
|
+
console.error("Invalid parameters provided:", error.message);
|
|
487
481
|
}
|
|
488
482
|
}
|
|
489
483
|
```
|
|
490
484
|
|
|
491
485
|
**Common Error Types:**
|
|
486
|
+
|
|
492
487
|
- `InitError`: SDK initialization failed
|
|
493
488
|
- `InvalidParamError`: Invalid parameters provided
|
|
494
489
|
- `SignatureNotFoundError`: Missing or invalid signature
|
|
@@ -531,4 +526,4 @@ For Indie Hackers: [Check out our guidelines and potential grant opportunities](
|
|
|
531
526
|
|
|
532
527
|
This project is licensed under a [custom license](https://github.com/reclaimprotocol/.github/blob/main/LICENSE). By contributing to this project, you agree that your contributions will be licensed under its terms.
|
|
533
528
|
|
|
534
|
-
Thank you for your contributions!
|
|
529
|
+
Thank you for your contributions!
|
package/dist/index.d.ts
CHANGED
|
@@ -123,6 +123,7 @@ declare class ReclaimProofRequest {
|
|
|
123
123
|
setRedirectUrl(url: string): void;
|
|
124
124
|
setClaimCreationType(claimCreationType: ClaimCreationType): void;
|
|
125
125
|
setModalOptions(options: ModalOptions): void;
|
|
126
|
+
setContext(address: string, message: string): void;
|
|
126
127
|
addContext(address: string, message: string): void;
|
|
127
128
|
setParams(params: {
|
|
128
129
|
[key: string]: string;
|
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.5.
|
|
75
|
+
version: "4.5.2",
|
|
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",
|
|
@@ -163,6 +163,9 @@ var require_package = __commonJS({
|
|
|
163
163
|
"release-it": "^19.0.4",
|
|
164
164
|
"url-parse": "^1.5.10",
|
|
165
165
|
uuid: "^9.0.1"
|
|
166
|
+
},
|
|
167
|
+
overrides: {
|
|
168
|
+
"@conventional-changelog/git-client": "^2.0.0"
|
|
166
169
|
}
|
|
167
170
|
};
|
|
168
171
|
}
|
|
@@ -293,7 +296,7 @@ var BackendServerError = createErrorClass("BackendServerError");
|
|
|
293
296
|
var GetStatusUrlError = createErrorClass("GetStatusUrlError");
|
|
294
297
|
var NoProviderParamsError = createErrorClass("NoProviderParamsError");
|
|
295
298
|
var SetParamsError = createErrorClass("SetParamsError");
|
|
296
|
-
var
|
|
299
|
+
var SetContextError = createErrorClass("SetContextError");
|
|
297
300
|
var SetSignatureError = createErrorClass("SetSignatureError");
|
|
298
301
|
var GetAppCallbackUrlError = createErrorClass("GetAppCallbackUrlError");
|
|
299
302
|
var StatusUrlError = createErrorClass("StatusUrlError");
|
|
@@ -2067,18 +2070,22 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
2067
2070
|
throw new SetParamsError("Error setting modal options", error);
|
|
2068
2071
|
}
|
|
2069
2072
|
}
|
|
2070
|
-
|
|
2073
|
+
setContext(address, message) {
|
|
2071
2074
|
try {
|
|
2072
2075
|
validateFunctionParams([
|
|
2073
2076
|
{ input: address, paramName: "address", isString: true },
|
|
2074
2077
|
{ input: message, paramName: "message", isString: true }
|
|
2075
|
-
], "
|
|
2078
|
+
], "setContext");
|
|
2076
2079
|
this.context = { contextAddress: address, contextMessage: message };
|
|
2077
2080
|
} catch (error) {
|
|
2078
|
-
logger7.info("Error
|
|
2079
|
-
throw new
|
|
2081
|
+
logger7.info("Error setting context", error);
|
|
2082
|
+
throw new SetContextError("Error setting context", error);
|
|
2080
2083
|
}
|
|
2081
2084
|
}
|
|
2085
|
+
// deprecated method: use setContext instead
|
|
2086
|
+
addContext(address, message) {
|
|
2087
|
+
this.setContext(address, message);
|
|
2088
|
+
}
|
|
2082
2089
|
setParams(params) {
|
|
2083
2090
|
try {
|
|
2084
2091
|
validateParameters(params);
|