Skip to content

Commit 3a3cbb0

Browse files
authored
Merge pull request #19 from reclaimprotocol/json-proof-response
Added a field in setAppCallbackUrl to specify the return type for proof
2 parents 08af3f2 + 58dc564 commit 3a3cbb0

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ The Reclaim SDK offers several advanced options to customize your integration:
184184
185185
4. **Custom Callback URL**:
186186
Set a custom callback URL for your app which allows you to receive proofs and status updates on your callback URL:
187+
Pass in `jsonProofResponse: true` to receive the proof in JSON format: By default, the proof is returned as a url encoded string.
187188
```javascript
188-
reclaimProofRequest.setAppCallbackUrl('https://example.com/callback')
189+
reclaimProofRequest.setAppCallbackUrl('https://example.com/callback', true)
189190
```
190191
191192
5. **Exporting and Importing SDK Configuration**:

src/Reclaim.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export class ReclaimProofRequest {
125125
private intervals: Map<string, NodeJS.Timer> = new Map();
126126
private timeStamp: string;
127127
private sdkVersion: string;
128+
private jsonProofResponse: boolean = false;
128129

129130
// Private constructor
130131
private constructor(applicationId: string, providerId: string, options?: ProofRequestOptions) {
@@ -197,7 +198,8 @@ export class ReclaimProofRequest {
197198
timeStamp,
198199
appCallbackUrl,
199200
options,
200-
sdkVersion
201+
sdkVersion,
202+
jsonProofResponse
201203
}: ProofPropertiesJSON = JSON.parse(jsonString)
202204

203205
validateFunctionParams([
@@ -223,6 +225,12 @@ export class ReclaimProofRequest {
223225
validateContext(context);
224226
}
225227

228+
if (jsonProofResponse !== undefined) {
229+
validateFunctionParams([
230+
{ input: jsonProofResponse, paramName: 'jsonProofResponse' }
231+
], 'fromJsonString');
232+
}
233+
226234
const proofRequestInstance = new ReclaimProofRequest(applicationId, providerId, options);
227235
proofRequestInstance.sessionId = sessionId;
228236
proofRequestInstance.context = context;
@@ -240,9 +248,10 @@ export class ReclaimProofRequest {
240248
}
241249

242250
// Setter methods
243-
setAppCallbackUrl(url: string): void {
251+
setAppCallbackUrl(url: string, jsonProofResponse?: boolean): void {
244252
validateURL(url, 'setAppCallbackUrl')
245253
this.appCallbackUrl = url
254+
this.jsonProofResponse = jsonProofResponse ?? false
246255
}
247256

248257
setRedirectUrl(url: string): void {
@@ -395,7 +404,8 @@ export class ReclaimProofRequest {
395404
redirectUrl: this.redirectUrl,
396405
timeStamp: this.timeStamp,
397406
options: this.options,
398-
sdkVersion: this.sdkVersion
407+
sdkVersion: this.sdkVersion,
408+
jsonProofResponse: this.jsonProofResponse
399409
})
400410
}
401411

@@ -420,7 +430,8 @@ export class ReclaimProofRequest {
420430
parameters: getFilledParameters(requestedProof),
421431
redirectUrl: this.redirectUrl ?? '',
422432
acceptAiProviders: this.options?.acceptAiProviders ?? false,
423-
sdkVersion: this.sdkVersion
433+
sdkVersion: this.sdkVersion,
434+
jsonProofResponse: this.jsonProofResponse
424435
}
425436

426437
const link = await createLinkWithTemplateData(templateData)

src/utils/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export type ProofPropertiesJSON = {
7171
appCallbackUrl?: string;
7272
options?: ProofRequestOptions;
7373
sdkVersion: string;
74+
jsonProofResponse?: boolean;
7475
};
7576

7677
export type TemplateData = {
@@ -85,6 +86,7 @@ export type TemplateData = {
8586
redirectUrl: string;
8687
acceptAiProviders: boolean;
8788
sdkVersion: string;
89+
jsonProofResponse?: boolean;
8890
};
8991

9092
// Add the new StatusUrlResponse type

0 commit comments

Comments
 (0)