@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 CHANGED
@@ -1,123 +1,205 @@
1
- # Reclaim SDK v2
1
+ # Reclaim js-sdk
2
2
 
3
- Designed to request proofs from the Reclaim protocol and manage the flow of claims and witness interactions.
3
+ This README provides a step-by-step guide on integrating the Reclaim Protocol JavaScript SDK into application
4
4
 
5
- ## Interfaces:
5
+ ## Pre-requisites
6
6
 
7
- - ### Reclaim Interface
7
+ - An application ID from Reclaim Protocol. You can get one from the [Reclaim Developer Protocol](https://dev.reclaimprotocol.org/)
8
8
 
9
- - #### `requestProof(request: ReclaimRequest, AppCallbackUrl: string): TemplateWithLink`
9
+ ## Create a new React application
10
10
 
11
- Requests proof using the provided proof request.
12
-
13
- **Parameters:**
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
- - **title:** `string` - Title of the request
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
- - ### RequestedProof interface
18
+ ```bash
19
+ npm install @reclaimprotocol/js-sdk
20
+ ```
31
21
 
32
- - **name:** `string` - Title of the request
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
- - ### TemplateWithLink Interface:
24
+ ```bash
25
+ npm i react-qr-code
26
+ ```
37
27
 
38
- - **template**: `Template`
39
- - **link**: `string`
28
+ ## Import dependencies
40
29
 
41
- - ### Template Interface:
30
+ In your `src/App.js` file, import the Reclaim SDK and the QR code generator
42
31
 
43
- - **id:** `string`
44
- - **name:** `string`
45
- - **callbackUrl:** `string`
46
- - **claims:** `RequestedProof[]`
47
- - **context:** `string`
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
- - ### ProviderV2 Interface:
38
+ ## Initialize the Reclaim SDK
51
39
 
52
- - **headers?:** `Map<string, string>` _(Any additional headers to be sent with the request)_
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
- - ### ResponseRedaction Interface:
42
+ File: `src/App.js`
61
43
 
62
- - **xPath?:** `string` _(XPath for HTML response)_
63
- - **jsonPath?:** `string` _(JSONPath for JSON response)_
64
- - **regex?:** `string` _(Regex for response matching)_
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
- - ### ResponseMatch Interface:
50
+ function App() {
51
+ const APP_ID = 'YOUR_APPLICATION_ID_HERE'
52
+ const reclaimProofRequest = new Reclaim.ProofRequest(APP_ID)
67
53
 
68
- - **type:** `'regex' | 'contains'` _("regex" or "contains" indicating the matching type)_
69
- - **value:** `string` _(The string/regex to match against)_
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
- ## Usage Flow
63
+ export default App
64
+ ```
72
65
 
73
- <img src='./readme/usage-flow-3.svg' width='900' />
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
- ## Dependency Diagram
154
+ export default App
155
+ ```
76
156
 
77
- <img src='./readme/depemdency-diagram.svg' width='600' />
157
+ ### Production Mode
78
158
 
79
- ## Error Codes
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
- - `Malformed proof request`: The proof request is structurally incorrect or missing required elements.
161
+ Similar to the prototype mode but ensure to fetch and set the signature securely
82
162
 
83
- - `Invalid AppCallbackUrl format`: The provided AppCallbackUrl is not in the expected format.
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
- ## Create ProofRequest Example
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
- ```typescript
88
- const privateKey = 'YOUR_PRIVATE_KEY'
175
+ const { requestUrl, statusUrl } =
176
+ await reclaimProofRequest.createVerificationRequest()
89
177
 
90
- const proofRequest: ProofRequest = {
91
- title: 'Example Proof Request',
92
- requestedProofs: [
93
- {
94
- url: 'https://api.example.com/data',
95
- method: 'GET',
96
- responseRedactions: [
97
- { start: 10, end: 20 },
98
- { start: 30, end: 40 }
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
- contextMessage: 'Please provide the necessary proofs for verification.',
108
- contextAddress: '0x0'
188
+ })
189
+
190
+ setRequestUrl(requestUrl)
109
191
  }
192
+ ```
110
193
 
111
- const dataToSign = JSON.stringify(proofRequest)
194
+ ## Run the application
112
195
 
113
- const signature = signData(dataToSign, privateKey)
196
+ ```bash
197
+ npm start
198
+ ```
114
199
 
115
- const proofRequestWithSignature: ProofRequest = {
116
- ...proofRequestWithoutSensitiveHeaders,
117
- requestorSignature: signature
118
- }
200
+ ## Advanced Configuration
119
201
 
120
- // Send the proof request to the AppClip/InstantApp
121
- // Verify the signature on the AppClip side
122
- const isSignatureValid = verifySignature(dataToSign, signature)
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
- declare class ReclaimClient {
140
- applicationId: string;
141
- signature?: string;
142
- appCallbackUrl?: string;
143
- statusUrl?: string;
144
- sessionId: string;
145
- requestedProofs?: RequestedProofs;
146
- context: Context;
147
- verificationRequest?: ReclaimVerificationRequest;
148
- myProvidersList: ProviderV2[];
149
- constructor(applicationId: string, sessionId?: string);
150
- createVerificationRequest(providers: string[]): Promise<ReclaimVerificationRequest>;
151
- createLinkRequest(providers: string[]): Promise<string>;
152
- setAppCallbackUrl(url: string): void;
153
- getAppCallbackUrl(): string;
154
- setStatusUrl(url: string): void;
155
- getStatusUrl(): string;
156
- setSignature(signature: string): void;
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
- getMyProvidersList(): Promise<ProviderV2[]>;
163
- }
164
- declare class ReclaimVerificationRequest {
165
- onSuccessCallback?: (data: Proof | Error | unknown) => void | unknown;
166
- onFailureCallback?: (data: Proof | Error | unknown) => void | unknown;
167
- sessionId: string;
168
- template: string;
169
- statusUrl: string;
170
- intervals: Map<string, NodeJS.Timer>;
171
- constructor(sessionId: string, statusUrl: string, template: string);
172
- on(event: string, callback: (data: Proof | Error | unknown) => void | unknown): this;
173
- start(): Promise<string | undefined>;
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, ReclaimClient, ReclaimVerificationRequest, type RequestedClaim, type RequestedProofs, type ResponseSelection, type WitnessData };
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 };