@reclaimprotocol/js-sdk 3.0.4 → 4.0.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 +167 -3
- package/dist/index.d.ts +32 -1
- package/dist/index.js +621 -41
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -143,7 +143,126 @@ Let's break down what's happening in this code:
|
|
|
143
143
|
|
|
144
144
|
5. When the verification is successful, we display the proof data on the page.
|
|
145
145
|
|
|
146
|
-
## Step 5:
|
|
146
|
+
## Step 5: New Streamlined Flow with Browser Extension Support
|
|
147
|
+
|
|
148
|
+
The Reclaim SDK now provides a simplified `triggerReclaimFlow()` method that automatically handles the verification process across different platforms and devices. This method intelligently chooses the best verification method based on the user's environment.
|
|
149
|
+
|
|
150
|
+
### Using triggerReclaimFlow()
|
|
151
|
+
|
|
152
|
+
Replace the `handleCreateClaim` function in your React component with this simpler approach:
|
|
153
|
+
|
|
154
|
+
```javascript
|
|
155
|
+
async function handleCreateClaim() {
|
|
156
|
+
if (!reclaimProofRequest) {
|
|
157
|
+
console.error('Reclaim Proof Request not initialized')
|
|
158
|
+
return
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
// Start the verification process automatically
|
|
163
|
+
await reclaimProofRequest.triggerReclaimFlow()
|
|
164
|
+
|
|
165
|
+
// Listen for the verification results
|
|
166
|
+
await reclaimProofRequest.startSession({
|
|
167
|
+
onSuccess: (proofs) => {
|
|
168
|
+
if (proofs && typeof proofs === 'string') {
|
|
169
|
+
console.log('SDK Message:', proofs)
|
|
170
|
+
setProofs(proofs)
|
|
171
|
+
} else if (proofs && typeof proofs !== 'string') {
|
|
172
|
+
if (Array.isArray(proofs)) {
|
|
173
|
+
console.log(JSON.stringify(proofs.map(p => p.claimData.context)))
|
|
174
|
+
} else {
|
|
175
|
+
console.log('Proof received:', proofs?.claimData.context)
|
|
176
|
+
}
|
|
177
|
+
setProofs(proofs)
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
onFailure: (error) => {
|
|
181
|
+
console.error('Verification failed', error)
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
} catch (error) {
|
|
185
|
+
console.error('Error triggering Reclaim flow:', error)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### How triggerReclaimFlow() Works
|
|
191
|
+
|
|
192
|
+
The `triggerReclaimFlow()` method automatically detects the user's environment and chooses the optimal verification method:
|
|
193
|
+
|
|
194
|
+
#### On Desktop Browsers:
|
|
195
|
+
1. **Browser Extension First**: If the Reclaim browser extension is installed, it will use the extension for a seamless in-browser verification experience.
|
|
196
|
+
2. **QR Code Fallback**: If the extension is not available, it automatically displays a QR code modal for mobile scanning.
|
|
197
|
+
|
|
198
|
+
#### On Mobile Devices:
|
|
199
|
+
1. **iOS Devices**: Automatically redirects to the Reclaim App Clip for native iOS verification.
|
|
200
|
+
2. **Android Devices**: Automatically redirects to the Reclaim Instant App for native Android verification.
|
|
201
|
+
|
|
202
|
+
### Browser Extension Support
|
|
203
|
+
|
|
204
|
+
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.
|
|
205
|
+
|
|
206
|
+
#### Features:
|
|
207
|
+
- **Automatic Detection**: The SDK automatically detects if the Reclaim browser extension is installed
|
|
208
|
+
- **Seamless Integration**: No additional setup required - the extension integration works out of the box
|
|
209
|
+
- **Fallback Support**: If the extension is not available, the SDK gracefully falls back to QR code or mobile app flows
|
|
210
|
+
|
|
211
|
+
#### Manual Extension Detection:
|
|
212
|
+
|
|
213
|
+
You can also manually check if the browser extension is available:
|
|
214
|
+
|
|
215
|
+
```javascript
|
|
216
|
+
const isExtensionAvailable = await reclaimProofRequest.isBrowserExtensionAvailable()
|
|
217
|
+
if (isExtensionAvailable) {
|
|
218
|
+
console.log('Reclaim browser extension is installed')
|
|
219
|
+
} else {
|
|
220
|
+
console.log('Browser extension not available, will use alternative flow')
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
#### Configuring Browser Extension Options:
|
|
225
|
+
|
|
226
|
+
You can customize the browser extension behavior during SDK initialization:
|
|
227
|
+
|
|
228
|
+
```javascript
|
|
229
|
+
const proofRequest = await ReclaimProofRequest.init(
|
|
230
|
+
APP_ID,
|
|
231
|
+
APP_SECRET,
|
|
232
|
+
PROVIDER_ID,
|
|
233
|
+
{
|
|
234
|
+
useBrowserExtension: true, // Enable/disable browser extension (default: true)
|
|
235
|
+
extensionID: 'custom-extension-id', // Use custom extension ID if needed
|
|
236
|
+
// ... other options
|
|
237
|
+
}
|
|
238
|
+
)
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Modal Customization
|
|
242
|
+
|
|
243
|
+
When the QR code modal is displayed (fallback on desktop), you can customize its appearance:
|
|
244
|
+
|
|
245
|
+
```javascript
|
|
246
|
+
// Set modal options before triggering the flow
|
|
247
|
+
reclaimProofRequest.setModalOptions({
|
|
248
|
+
title: 'Custom Verification Title',
|
|
249
|
+
description: 'Scan this QR code with your mobile device to verify your account',
|
|
250
|
+
darkTheme: true, // Enable dark theme
|
|
251
|
+
extensionUrl: 'https://custom-extension-url.com' // Custom extension download URL
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
await reclaimProofRequest.triggerReclaimFlow()
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Benefits of the New Flow:
|
|
258
|
+
|
|
259
|
+
1. **Platform Adaptive**: Automatically chooses the best verification method for each platform
|
|
260
|
+
2. **User-Friendly**: Provides the most seamless experience possible for each user
|
|
261
|
+
3. **Simplified Integration**: Single method call handles all verification scenarios
|
|
262
|
+
4. **Extension Support**: Leverages browser extension for desktop users when available
|
|
263
|
+
5. **Mobile Optimized**: Native app experiences on mobile devices
|
|
264
|
+
|
|
265
|
+
## Step 6: Run your application
|
|
147
266
|
|
|
148
267
|
Start your development server:
|
|
149
268
|
|
|
@@ -194,7 +313,53 @@ The Reclaim SDK offers several advanced options to customize your integration:
|
|
|
194
313
|
reclaimProofRequest.setAppCallbackUrl('https://example.com/callback', true)
|
|
195
314
|
```
|
|
196
315
|
|
|
197
|
-
5. **
|
|
316
|
+
5. **Modal Customization for Desktop Users**:
|
|
317
|
+
Customize the appearance and behavior of the QR code modal shown to desktop users:
|
|
318
|
+
```javascript
|
|
319
|
+
reclaimProofRequest.setModalOptions({
|
|
320
|
+
title: 'Verify Your Account',
|
|
321
|
+
description: 'Scan the QR code with your mobile device or install our browser extension',
|
|
322
|
+
darkTheme: false, // Enable dark theme (default: false)
|
|
323
|
+
extensionUrl: 'https://chrome.google.com/webstore/detail/reclaim' // Custom extension URL
|
|
324
|
+
})
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
6. **Browser Extension Configuration**:
|
|
328
|
+
Configure browser extension behavior and detection:
|
|
329
|
+
```javascript
|
|
330
|
+
// Check if browser extension is available
|
|
331
|
+
const isExtensionAvailable = await reclaimProofRequest.isBrowserExtensionAvailable()
|
|
332
|
+
|
|
333
|
+
// Trigger the verification flow with automatic platform detection
|
|
334
|
+
await reclaimProofRequest.triggerReclaimFlow()
|
|
335
|
+
|
|
336
|
+
// Initialize with browser extension options
|
|
337
|
+
const proofRequest = await ReclaimProofRequest.init(
|
|
338
|
+
APP_ID,
|
|
339
|
+
APP_SECRET,
|
|
340
|
+
PROVIDER_ID,
|
|
341
|
+
{
|
|
342
|
+
useBrowserExtension: true, // Enable browser extension support (default: true)
|
|
343
|
+
extensionID: 'custom-extension-id', // Custom extension identifier
|
|
344
|
+
useAppClip: true, // Enable mobile app clips (default: true)
|
|
345
|
+
log: true // Enable logging for debugging
|
|
346
|
+
}
|
|
347
|
+
)
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
7. **Platform-Specific Flow Control**:
|
|
351
|
+
The `triggerReclaimFlow()` method provides intelligent platform detection, but you can still use traditional methods for custom flows:
|
|
352
|
+
```javascript
|
|
353
|
+
// Traditional approach with manual QR code handling
|
|
354
|
+
const requestUrl = await reclaimProofRequest.getRequestUrl()
|
|
355
|
+
// Display your own QR code implementation
|
|
356
|
+
|
|
357
|
+
// Or use the new streamlined approach
|
|
358
|
+
await reclaimProofRequest.triggerReclaimFlow()
|
|
359
|
+
// Automatically handles platform detection and optimal user experience
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
8. **Exporting and Importing SDK Configuration**:
|
|
198
363
|
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:
|
|
199
364
|
```javascript
|
|
200
365
|
// On the client-side or initial service
|
|
@@ -218,7 +383,6 @@ For production applications, it's recommended to handle proofs on your backend:
|
|
|
218
383
|
reclaimProofRequest.setCallbackUrl('https://your-backend.com/receive-proofs')
|
|
219
384
|
```
|
|
220
385
|
|
|
221
|
-
|
|
222
386
|
These options allow you to securely process proofs and status updates on your server.
|
|
223
387
|
|
|
224
388
|
## Next Steps
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,18 @@ interface Proof {
|
|
|
9
9
|
};
|
|
10
10
|
taskId?: number;
|
|
11
11
|
}
|
|
12
|
+
declare const RECLAIM_EXTENSION_ACTIONS: {
|
|
13
|
+
CHECK_EXTENSION: string;
|
|
14
|
+
EXTENSION_RESPONSE: string;
|
|
15
|
+
START_VERIFICATION: string;
|
|
16
|
+
STATUS_UPDATE: string;
|
|
17
|
+
};
|
|
18
|
+
interface ExtensionMessage {
|
|
19
|
+
action: string;
|
|
20
|
+
messageId: string;
|
|
21
|
+
data?: any;
|
|
22
|
+
extensionID?: string;
|
|
23
|
+
}
|
|
12
24
|
interface WitnessData {
|
|
13
25
|
id: string;
|
|
14
26
|
url: string;
|
|
@@ -49,6 +61,15 @@ type ProofRequestOptions = {
|
|
|
49
61
|
useAppClip?: boolean;
|
|
50
62
|
device?: string;
|
|
51
63
|
envUrl?: string;
|
|
64
|
+
useBrowserExtension?: boolean;
|
|
65
|
+
extensionID?: string;
|
|
66
|
+
};
|
|
67
|
+
type ModalOptions = {
|
|
68
|
+
title?: string;
|
|
69
|
+
description?: string;
|
|
70
|
+
extensionUrl?: string;
|
|
71
|
+
darkTheme?: boolean;
|
|
72
|
+
onClose?: () => void;
|
|
52
73
|
};
|
|
53
74
|
declare enum ClaimCreationType {
|
|
54
75
|
STANDALONE = "createClaim",
|
|
@@ -76,6 +97,9 @@ declare class ReclaimProofRequest {
|
|
|
76
97
|
private sdkVersion;
|
|
77
98
|
private jsonProofResponse;
|
|
78
99
|
private lastFailureTime?;
|
|
100
|
+
private templateData;
|
|
101
|
+
private extensionID;
|
|
102
|
+
private modalOptions?;
|
|
79
103
|
private readonly FAILURE_TIMEOUT;
|
|
80
104
|
private constructor();
|
|
81
105
|
static init(applicationId: string, appSecret: string, providerId: string, options?: ProofRequestOptions): Promise<ReclaimProofRequest>;
|
|
@@ -83,6 +107,7 @@ declare class ReclaimProofRequest {
|
|
|
83
107
|
setAppCallbackUrl(url: string, jsonProofResponse?: boolean): void;
|
|
84
108
|
setRedirectUrl(url: string): void;
|
|
85
109
|
setClaimCreationType(claimCreationType: ClaimCreationType): void;
|
|
110
|
+
setModalOptions(options: ModalOptions): void;
|
|
86
111
|
addContext(address: string, message: string): void;
|
|
87
112
|
setParams(params: {
|
|
88
113
|
[key: string]: string;
|
|
@@ -94,7 +119,13 @@ declare class ReclaimProofRequest {
|
|
|
94
119
|
private clearInterval;
|
|
95
120
|
toJsonString(options?: ProofRequestOptions): string;
|
|
96
121
|
getRequestUrl(): Promise<string>;
|
|
122
|
+
triggerReclaimFlow(): Promise<void>;
|
|
123
|
+
isBrowserExtensionAvailable(timeout?: number): Promise<boolean>;
|
|
124
|
+
private triggerBrowserExtensionFlow;
|
|
125
|
+
private showQRCodeModal;
|
|
126
|
+
private redirectToInstantApp;
|
|
127
|
+
private redirectToAppClip;
|
|
97
128
|
startSession({ onSuccess, onError }: StartSessionParams): Promise<void>;
|
|
98
129
|
}
|
|
99
130
|
|
|
100
|
-
export { type Beacon, type BeaconState, ClaimCreationType, type Context, type Proof, type ProviderClaimData, ReclaimProofRequest, type WitnessData, transformForOnchain, verifyProof };
|
|
131
|
+
export { type Beacon, type BeaconState, ClaimCreationType, type Context, type ExtensionMessage, type ModalOptions, type Proof, type ProviderClaimData, RECLAIM_EXTENSION_ACTIONS, ReclaimProofRequest, type WitnessData, transformForOnchain, verifyProof };
|