@reclaimprotocol/js-sdk 0.0.23 → 0.1.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 +171 -89
- package/dist/index.d.ts +46 -35
- package/dist/index.js +286 -231
- package/dist/index.js.map +1 -1
- package/package.json +7 -5
- package/readme/depemdency-diagram.svg +4 -0
- package/readme/usage-flow-2.svg +1 -0
- package/readme/usage-flow-3.svg +1 -0
- package/readme/usage-flow.svg +1 -0
package/README.md
CHANGED
|
@@ -1,123 +1,205 @@
|
|
|
1
|
-
# Reclaim
|
|
1
|
+
# Reclaim js-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This README provides a step-by-step guide on integrating the Reclaim Protocol JavaScript SDK into application
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Pre-requisites
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- An application ID from Reclaim Protocol. You can get one from the [Reclaim Developer Protocol](https://dev.reclaimprotocol.org/)
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## Create a new React application
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
- `request`: ReclaimRequest (The proof request object)
|
|
16
|
-
- `AppCallbackUrl`: callback url which will receive the proof from AppClip/InstantApp
|
|
17
|
-
|
|
18
|
-
**Returns:**
|
|
19
|
-
|
|
20
|
-
- `TemplateWithLink`: A link to AppClip/AppInstant with Template Data
|
|
21
|
-
|
|
22
|
-
- ### ReclaimRequest Interface
|
|
11
|
+
```bash
|
|
12
|
+
npx create-react-app reclaim-app
|
|
13
|
+
cd reclaim-app
|
|
14
|
+
```
|
|
23
15
|
|
|
24
|
-
|
|
25
|
-
- **requestedProofs:** `RequestedProof[]` - Proofs requested by the application
|
|
26
|
-
- **contextMessage?:** `string` - Context message for the proof request
|
|
27
|
-
- **contextAddress?:** `string` - Context address for the proof request
|
|
28
|
-
- **requestorSignature?:** `string` - Signature of the requestor
|
|
16
|
+
## Install the Reclaim Protocol JS-SDK
|
|
29
17
|
|
|
30
|
-
|
|
18
|
+
```bash
|
|
19
|
+
npm install @reclaimprotocol/js-sdk
|
|
20
|
+
```
|
|
31
21
|
|
|
32
|
-
|
|
33
|
-
- **provider:** `ProviderV2` - Proof requested by the application
|
|
34
|
-
- **metadata**: {logoUri?: string, description?: string} - Metadata of the proof provider
|
|
22
|
+
## Install other dependencies
|
|
35
23
|
|
|
36
|
-
|
|
24
|
+
```bash
|
|
25
|
+
npm i react-qr-code
|
|
26
|
+
```
|
|
37
27
|
|
|
38
|
-
|
|
39
|
-
- **link**: `string`
|
|
28
|
+
## Import dependencies
|
|
40
29
|
|
|
41
|
-
|
|
30
|
+
In your `src/App.js` file, import the Reclaim SDK and the QR code generator
|
|
42
31
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
- **requestorSignature?:** `string`
|
|
32
|
+
```javascript
|
|
33
|
+
import { useState, useEffect } from 'react'
|
|
34
|
+
import { Reclaim } from '@reclaimprotocol/js-sdk'
|
|
35
|
+
import QRCode from 'react-qr-code'
|
|
36
|
+
```
|
|
49
37
|
|
|
50
|
-
|
|
38
|
+
## Initialize the Reclaim SDK
|
|
51
39
|
|
|
52
|
-
|
|
53
|
-
- **url:** `string` _(URL to make the request to, e.g., "https://amazon.in/orders?q=abcd")_
|
|
54
|
-
- **method:** `'GET' | 'POST'` _(HTTP method)_
|
|
55
|
-
- **body?:** `string | Uint8Array` _(Body of the request, used only if the method is POST)_
|
|
56
|
-
- **responseRedactions:** `ResponseRedaction[]` _(Portions to select from a response for redaction)_
|
|
57
|
-
- **responseMatches:** `ResponseMatch[]` _(List to check that the redacted response matches provided strings/regexes)_
|
|
58
|
-
- **geoLocation?:** `string` \_(Geographical location from where to proxy the request)
|
|
40
|
+
Declare your `application ID` and initialize the Reclaim Protocol client. Replace `YOUR_APPLICATION_ID_HERE` with the actual application ID provided by Reclaim Protocol.
|
|
59
41
|
|
|
60
|
-
|
|
42
|
+
File: `src/App.js`
|
|
61
43
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
44
|
+
```javascript
|
|
45
|
+
import './App.css'
|
|
46
|
+
import { useState, useEffect } from 'react'
|
|
47
|
+
import { Reclaim } from '@reclaimprotocol/js-sdk'
|
|
48
|
+
import QRCode from 'react-qr-code'
|
|
65
49
|
|
|
66
|
-
|
|
50
|
+
function App() {
|
|
51
|
+
const APP_ID = 'YOUR_APPLICATION_ID_HERE'
|
|
52
|
+
const reclaimProofRequest = new Reclaim.ProofRequest(APP_ID)
|
|
67
53
|
|
|
68
|
-
|
|
69
|
-
|
|
54
|
+
return (
|
|
55
|
+
<div className='App'>
|
|
56
|
+
<header className='App-header'>
|
|
57
|
+
<p>Reclaim App</p>
|
|
58
|
+
</header>
|
|
59
|
+
</div>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
70
62
|
|
|
71
|
-
|
|
63
|
+
export default App
|
|
64
|
+
```
|
|
72
65
|
|
|
73
|
-
|
|
66
|
+
## Implement Verification Request Function
|
|
67
|
+
|
|
68
|
+
Create functions to handle the verification request. You'll need separate functions for prototype and production modes due to the different handling of the application secret and signature.
|
|
69
|
+
|
|
70
|
+
### Prototype Mode
|
|
71
|
+
|
|
72
|
+
For testing purposes, use the prototype mode. Note that in production, you should handle the application secret securely on your server.
|
|
73
|
+
|
|
74
|
+
File: `src/App.js`
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
import './App.css'
|
|
78
|
+
import { useState, useEffect } from 'react'
|
|
79
|
+
import { Reclaim } from '@reclaimprotocol/js-sdk'
|
|
80
|
+
import QRCode from 'react-qr-code'
|
|
81
|
+
|
|
82
|
+
function App() {
|
|
83
|
+
const [requestUrl, setRequestUrl] = useState('')
|
|
84
|
+
const [proofs, setProofs] = useState([])
|
|
85
|
+
|
|
86
|
+
const APP_ID = 'YOUR_APPLICATION_ID_HERE'
|
|
87
|
+
|
|
88
|
+
const reclaimProofRequest = new Reclaim.ProofRequest(APP_ID)
|
|
89
|
+
|
|
90
|
+
async function createVerificationRequest() {
|
|
91
|
+
// id of the provider you want to generate the proof for
|
|
92
|
+
await reclaimProofRequest.buildProofRequest('PROVIDER_ID')
|
|
93
|
+
|
|
94
|
+
reclaimProofRequest.setSignature(
|
|
95
|
+
await reclaimProofRequest.generateSignature(
|
|
96
|
+
'YOUR_APPLICATION_SECRET' // Handle securely for production
|
|
97
|
+
)
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
const { requestUrl, statusUrl } =
|
|
101
|
+
await reclaimProofRequest.createVerificationRequest()
|
|
102
|
+
|
|
103
|
+
await reclaimProofRequest.startSession({
|
|
104
|
+
onSuccessCallback: proofs => {
|
|
105
|
+
console.log('Verification success', proofs)
|
|
106
|
+
setProofs(proofs)
|
|
107
|
+
// Your business logic here
|
|
108
|
+
},
|
|
109
|
+
onFailureCallback: error => {
|
|
110
|
+
console.error('Verification failed', error)
|
|
111
|
+
// Your business logic here to handle the error
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
setRequestUrl(requestUrl)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<div className='App'>
|
|
120
|
+
<header className='App-header'>
|
|
121
|
+
<p>Reclaim App</p>
|
|
122
|
+
<button
|
|
123
|
+
onClick={createVerificationRequest}
|
|
124
|
+
style={{ marginBottom: '20px', padding: '10px', cursor: 'pointer' }}
|
|
125
|
+
>
|
|
126
|
+
Create Verification Request
|
|
127
|
+
</button>
|
|
128
|
+
<div style={{ backgroundColor: 'white', padding: '10px' }}>
|
|
129
|
+
{requestUrl && (
|
|
130
|
+
<div style={{ backgroundColor: 'white', padding: '10px' }}>
|
|
131
|
+
<QRCode value={requestUrl} />
|
|
132
|
+
</div>
|
|
133
|
+
)}
|
|
134
|
+
{proofs.length > 0 && (
|
|
135
|
+
<div>
|
|
136
|
+
<h3>Proofs</h3>
|
|
137
|
+
<ul>
|
|
138
|
+
{proofs.map((proof, index) => {
|
|
139
|
+
return (
|
|
140
|
+
<p key={index}>
|
|
141
|
+
{JSON.stringify(proof.extractedParameterValues)}
|
|
142
|
+
</p>
|
|
143
|
+
)
|
|
144
|
+
})}
|
|
145
|
+
</ul>
|
|
146
|
+
</div>
|
|
147
|
+
)}
|
|
148
|
+
</div>
|
|
149
|
+
</header>
|
|
150
|
+
</div>
|
|
151
|
+
)
|
|
152
|
+
}
|
|
74
153
|
|
|
75
|
-
|
|
154
|
+
export default App
|
|
155
|
+
```
|
|
76
156
|
|
|
77
|
-
|
|
157
|
+
### Production Mode
|
|
78
158
|
|
|
79
|
-
|
|
159
|
+
In production mode, securely fetch and set the signature from your backend instead of using the application secret directly in the client.
|
|
80
160
|
|
|
81
|
-
|
|
161
|
+
Similar to the prototype mode but ensure to fetch and set the signature securely
|
|
82
162
|
|
|
83
|
-
|
|
163
|
+
```javascript
|
|
164
|
+
async function createVerificationRequestProductionMode() {
|
|
165
|
+
// id of the provider you want to generate the proof for
|
|
166
|
+
await reclaimProofRequest.buildProofRequest('PROVIDER_ID')
|
|
84
167
|
|
|
85
|
-
|
|
168
|
+
reclaim
|
|
169
|
+
.setSignature
|
|
170
|
+
// TODO: fetch signature from your backend
|
|
171
|
+
// On the backend, generate signature using:
|
|
172
|
+
// await Reclaim.getSignature(requestedProofs, APP_SECRET)
|
|
173
|
+
()
|
|
86
174
|
|
|
87
|
-
|
|
88
|
-
|
|
175
|
+
const { requestUrl, statusUrl } =
|
|
176
|
+
await reclaimProofRequest.createVerificationRequest()
|
|
89
177
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
],
|
|
100
|
-
responseMatches: [
|
|
101
|
-
{ type: 'string', value: 'important-data' },
|
|
102
|
-
{ type: 'regex', pattern: '\\d{3}-\\d{2}-\\d{4}' }
|
|
103
|
-
],
|
|
104
|
-
geoLocation: '37.7749,-122.4194'
|
|
178
|
+
await reclaimProofRequest.startSession({
|
|
179
|
+
onSuccessCallback: proofs => {
|
|
180
|
+
console.log('Verification success', proofs)
|
|
181
|
+
setProofs(proofs)
|
|
182
|
+
// Your business logic here
|
|
183
|
+
},
|
|
184
|
+
onFailureCallback: error => {
|
|
185
|
+
console.error('Verification failed', error)
|
|
186
|
+
// Your business logic here to handle the error
|
|
105
187
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
setRequestUrl(requestUrl)
|
|
109
191
|
}
|
|
192
|
+
```
|
|
110
193
|
|
|
111
|
-
|
|
194
|
+
## Run the application
|
|
112
195
|
|
|
113
|
-
|
|
196
|
+
```bash
|
|
197
|
+
npm start
|
|
198
|
+
```
|
|
114
199
|
|
|
115
|
-
|
|
116
|
-
...proofRequestWithoutSensitiveHeaders,
|
|
117
|
-
requestorSignature: signature
|
|
118
|
-
}
|
|
200
|
+
## Advanced Configuration
|
|
119
201
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
202
|
+
You can configure Reclaim SDK to receive proofs in your preferref backend by setting up a callback URL. This is useful if you want to handle the proofs in your backend.
|
|
203
|
+
|
|
204
|
+
- **Set Callback Url** - `reclaim.setCallbackUrl('https://your-backend.com/receive-proofs')`
|
|
205
|
+
- **Set Status URL** - `reclaim.setStatusUrl('https://your-backend.com/receive-status')`
|
package/dist/index.d.ts
CHANGED
|
@@ -136,41 +136,52 @@ type BeaconState = {
|
|
|
136
136
|
nextEpochTimestampS: number;
|
|
137
137
|
};
|
|
138
138
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
getSignature(requestedProofs: RequestedProofs, applicationSecret: string): Promise<string>;
|
|
158
|
-
buildHttpProviderV2ByID(providerIds: string[]): Promise<ProviderV2[]>;
|
|
159
|
-
buildRequestedProofs(providers: ProviderV2[], callbackUrl: string, statusUrl?: string): RequestedProofs;
|
|
160
|
-
addContext(address: string, message: string): Context;
|
|
139
|
+
type StartSessionParams = {
|
|
140
|
+
onSuccessCallback: OnSuccessCallback;
|
|
141
|
+
onFailureCallback: OnFailureCallback;
|
|
142
|
+
};
|
|
143
|
+
type OnSuccessCallback = (proofs: Proof[]) => void;
|
|
144
|
+
type OnFailureCallback = (error: Error) => void;
|
|
145
|
+
type ProofRequestOptions = {
|
|
146
|
+
log?: boolean;
|
|
147
|
+
sessionId?: string;
|
|
148
|
+
};
|
|
149
|
+
type ApplicationId = string;
|
|
150
|
+
type Signature = string;
|
|
151
|
+
type AppCallbackUrl = string;
|
|
152
|
+
type SessionId = string;
|
|
153
|
+
type StatusUrl = string;
|
|
154
|
+
type NoReturn = void;
|
|
155
|
+
|
|
156
|
+
declare class Reclaim {
|
|
161
157
|
static verifySignedProof(proof: Proof): Promise<boolean>;
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
158
|
+
static ProofRequest: {
|
|
159
|
+
new (applicationId: string, options?: ProofRequestOptions): {
|
|
160
|
+
applicationId: ApplicationId;
|
|
161
|
+
signature?: string | undefined;
|
|
162
|
+
appCallbackUrl?: string | undefined;
|
|
163
|
+
sessionId: SessionId;
|
|
164
|
+
statusUrl?: string | undefined;
|
|
165
|
+
context: Context;
|
|
166
|
+
requestedProofs?: RequestedProofs | undefined;
|
|
167
|
+
intervals: Map<string, NodeJS.Timer>;
|
|
168
|
+
addContext(address: string, message: string): NoReturn;
|
|
169
|
+
setAppCallbackUrl(url: string): NoReturn;
|
|
170
|
+
setStatusUrl(url: string): NoReturn;
|
|
171
|
+
setSignature(signature: Signature): NoReturn;
|
|
172
|
+
getAppCallbackUrl(): AppCallbackUrl;
|
|
173
|
+
getStatusUrl(): StatusUrl;
|
|
174
|
+
getRequestedProofs(): Promise<RequestedProofs>;
|
|
175
|
+
generateSignature(applicationSecret: string): Promise<Signature>;
|
|
176
|
+
buildProofRequest(providerId: string): Promise<RequestedProofs>;
|
|
177
|
+
createVerificationRequest(): Promise<{
|
|
178
|
+
statusUrl: StatusUrl;
|
|
179
|
+
requestUrl: string;
|
|
180
|
+
}>;
|
|
181
|
+
startSession({ onSuccessCallback, onFailureCallback }: StartSessionParams): Promise<void>;
|
|
182
|
+
scheduleIntervalEndingTask(onFailureCallback: OnFailureCallback): void;
|
|
183
|
+
};
|
|
184
|
+
};
|
|
174
185
|
}
|
|
175
186
|
|
|
176
|
-
export { type Beacon, type BeaconState, type BodySniff, type Context, type Payload, type Proof, type ProviderClaimData, type ProviderV2,
|
|
187
|
+
export { type Beacon, type BeaconState, type BodySniff, type Context, type Payload, type Proof, type ProviderClaimData, type ProviderV2, Reclaim, type RequestedClaim, type RequestedProofs, type ResponseSelection, type WitnessData };
|