Skip to content

Commit 0356f19

Browse files
authored
Add verificationConfig parameter to startSession for customizing verification (#100)
1 parent d9b5bdc commit 0356f19

6 files changed

Lines changed: 85 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [5.1.0]
9+
10+
### Added
11+
12+
- Add `verificationConfig` parameter to `startSession` method.
13+
814
## [5.0.1]
915

1016
### Added

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Let's break down what's happening in this code:
138138
139139
- Generate a request URL using `getRequestUrl()`. This URL is used to create the QR code.
140140
- Get the status URL using `getStatusUrl()`. This URL can be used to check the status of the claim process.
141-
- Start a session with `startSession()`, which sets up callbacks for successful and failed verifications.
141+
- Start a session with `startSession()`, which sets up callbacks for successful and failed verifications, and allows you to pass an optional `verificationConfig` to customize proof verification.
142142
143143
3. We display a QR code using the request URL. When a user scans this code, it starts the verification process.
144144

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@reclaimprotocol/js-sdk",
3-
"version": "5.0.1",
3+
"version": "5.1.0",
44
"description": "Designed to request proofs from the Reclaim protocol and manage the flow of claims and witness interactions.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/Reclaim.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,7 @@ export class ReclaimProofRequest {
16711671
*
16721672
* @param onSuccess - Callback function invoked when proof is successfully submitted
16731673
* @param onError - Callback function invoked when an error occurs during the session
1674+
* @param verificationConfig - Optional configuration to customize proof verification
16741675
* @returns Promise<void>
16751676
* @throws {SessionNotStartedError} When session ID is not defined
16761677
* @throws {ProofNotVerifiedError} When proof verification fails (default callback only)
@@ -1689,7 +1690,7 @@ export class ReclaimProofRequest {
16891690
* });
16901691
* ```
16911692
*/
1692-
async startSession({ onSuccess, onError }: StartSessionParams): Promise<void> {
1693+
async startSession({ onSuccess, onError, verificationConfig }: StartSessionParams): Promise<void> {
16931694
if (!this.sessionId) {
16941695
const message = "Session can't be started due to undefined value of sessionId";
16951696
logger.info(message);
@@ -1732,10 +1733,10 @@ export class ReclaimProofRequest {
17321733
if (statusUrlResponse.session.proofs && statusUrlResponse.session.proofs.length > 0) {
17331734
const proofs = statusUrlResponse.session.proofs;
17341735
if (this.claimCreationType === ClaimCreationType.STANDALONE) {
1735-
const { isVerified: verified } = await verifyProof(proofs, this.getProviderVersion());
1736-
if (!verified) {
1736+
const result = await verifyProof(proofs, verificationConfig ?? this.getProviderVersion());
1737+
if (!result.isVerified) {
17371738
logger.info(`Proofs not verified: count=${proofs?.length}`);
1738-
throw new ProofNotVerifiedError();
1739+
throw new ProofNotVerifiedError(`Proofs not verified: count=${proofs?.length}`, result.error);
17391740
}
17401741
}
17411742
// check if the proofs array has only one proof then send the proofs in onSuccess

src/utils/__tests__/request.test.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,4 +563,74 @@ describe('Request', () => {
563563
expect(output.options.launchOptions.verificationMode).toEqual('app');
564564
});
565565
});
566+
567+
describe('startSession', () => {
568+
let originalSetInterval: typeof setInterval;
569+
let originalClearInterval: typeof clearInterval;
570+
571+
beforeEach(() => {
572+
originalSetInterval = global.setInterval;
573+
originalClearInterval = global.clearInterval;
574+
});
575+
576+
afterEach(() => {
577+
global.setInterval = originalSetInterval;
578+
global.clearInterval = originalClearInterval;
579+
});
580+
581+
it('should accept and use verificationConfig in startSession without breaking the api', async () => {
582+
let intervalCb: any;
583+
(global as any).setInterval = (cb: any, time: number) => {
584+
intervalCb = cb;
585+
return 123 as any;
586+
};
587+
(global as any).clearInterval = () => {};
588+
589+
globalThis.fetch = mockFetchBy((url) => {
590+
if (url.includes('session/')) {
591+
return {
592+
session: {
593+
statusV2: 'PROOF_GENERATION_SUCCESS',
594+
proofs: [{
595+
identifier: '0x123',
596+
claimData: {
597+
provider: 'http',
598+
parameters: '{}',
599+
owner: '0x0',
600+
timestampS: 1234567890,
601+
context: 'some-context',
602+
identifier: '0x123',
603+
epoch: 1
604+
},
605+
signatures: ['0xinvalid'],
606+
witnesses: []
607+
}]
608+
},
609+
sessionId: '123',
610+
resolvedProviderVersion: '1.0.0'
611+
};
612+
}
613+
return { success: true };
614+
});
615+
616+
const request = await ReclaimProofRequest.init(testAppId, testAppSecret, 'example');
617+
618+
const mockSuccess = jest.fn();
619+
const mockError = jest.fn();
620+
621+
await request.startSession({
622+
onSuccess: mockSuccess,
623+
onError: mockError,
624+
verificationConfig: { dangerouslyDisableContentValidation: true }
625+
});
626+
627+
// Trigger the interval callback manually
628+
await intervalCb();
629+
630+
expect(mockError).toHaveBeenCalled();
631+
const err = mockError.mock.calls[0][0];
632+
expect(err.message).toContain('Proofs not verified');
633+
expect(mockSuccess).not.toHaveBeenCalled();
634+
});
635+
});
566636
});

src/utils/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Context, Proof, ProviderClaimData, TeeAttestation } from './interfaces';
2+
import { VerificationConfig } from './proofValidationUtils';
23
import { InjectedRequestSpec, InterceptorRequestSpec, ProviderHashRequirementsConfig, ReclaimProviderConfigWithRequestSpec, RequestSpec, ResponseMatchSpec, ResponseRedactionSpec } from './providerUtils';
34

45
// Claim-related types
@@ -39,6 +40,7 @@ export type CreateVerificationRequest = {
3940
export type StartSessionParams = {
4041
onSuccess: OnSuccess;
4142
onError: OnError;
43+
verificationConfig?: VerificationConfig;
4244
};
4345

4446
export type OnSuccess = (proof?: Proof | Proof[]) => void;

0 commit comments

Comments
 (0)