Skip to content

feat: support versioned providers #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ export default function Home() {
return (
<main className='flex min-h-screen flex-col items-center p-8 bg-gray-50'>
<div className='max-w-4xl w-full mx-auto'>
<h1 className='text-3xl font-bold mb-8 text-center'>Reclaim BrowserSDK</h1>
<h1 className='text-3xl font-bold mb-8 text-center'>Reclaim SDK</h1>

{!proofData && !isLoading && (
<div className="text-center">
<p className="mb-6 text-gray-700">
Click the button below to start the claim process using your browser extension.
Click the button below to start the claim process.
</p>
<button
onClick={startClaimProcess}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reclaimprotocol/js-sdk",
"version": "4.1.0",
"version": "4.2.0",
"description": "Designed to request proofs from the Reclaim protocol and manage the flow of claims and witness interactions.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
36 changes: 33 additions & 3 deletions src/Reclaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ const emptyTemplateData: TemplateData = {
redirectUrl: '',
acceptAiProviders: false,
sdkVersion: '',
providerVersion: '',
resolvedProviderVersion: '',
jsonProofResponse: false
}
export class ReclaimProofRequest {
Expand All @@ -151,6 +153,7 @@ export class ReclaimProofRequest {
private context: Context = { contextAddress: '0x0', contextMessage: 'sample context' };
private claimCreationType?: ClaimCreationType = ClaimCreationType.STANDALONE;
private providerId: string;
private resolvedProviderVersion?: string;
private parameters: { [key: string]: string };
private redirectUrl?: string;
private intervals: Map<string, NodeJS.Timer> = new Map();
Expand Down Expand Up @@ -219,6 +222,11 @@ export class ReclaimProofRequest {
{ paramName: 'acceptAiProviders', input: options.acceptAiProviders }
], 'the constructor')
}
if (options.providerVersion) {
validateFunctionParams([
{ paramName: 'providerVersion', input: options.providerVersion, isString: true }
], 'the constructor')
}
if (options.log) {
validateFunctionParams([
{ paramName: 'log', input: options.log }
Expand Down Expand Up @@ -257,8 +265,9 @@ export class ReclaimProofRequest {
const signature = await proofRequestInstance.generateSignature(appSecret)
proofRequestInstance.setSignature(signature)

const data: InitSessionResponse = await initSession(providerId, applicationId, proofRequestInstance.timeStamp, signature);
const data: InitSessionResponse = await initSession(providerId, applicationId, proofRequestInstance.timeStamp, signature, options?.providerVersion);
proofRequestInstance.sessionId = data.sessionId
proofRequestInstance.resolvedProviderVersion = data.resolvedProviderVersion

return proofRequestInstance
} catch (error) {
Expand All @@ -282,7 +291,8 @@ export class ReclaimProofRequest {
claimCreationType,
options,
sdkVersion,
jsonProofResponse
jsonProofResponse,
resolvedProviderVersion
}: ProofPropertiesJSON = JSON.parse(jsonString)

validateFunctionParams([
Expand Down Expand Up @@ -323,6 +333,19 @@ export class ReclaimProofRequest {
], 'fromJsonString');
}


if (options?.providerVersion) {
validateFunctionParams([
{ input: options.providerVersion, paramName: 'providerVersion', isString: true }
], 'fromJsonString');
}

if (resolvedProviderVersion) {
validateFunctionParams([
{ input: resolvedProviderVersion, paramName: 'resolvedProviderVersion', isString: true }
], 'fromJsonString');
}
Comment on lines +337 to +347
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider making resolvedProviderVersion validation mandatory.

The validation only occurs if resolvedProviderVersion exists, but according to the type definition in ProofPropertiesJSON, it's a required field.

-  if (resolvedProviderVersion) {
-    validateFunctionParams([
-      { input: resolvedProviderVersion, paramName: 'resolvedProviderVersion', isString: true }
-    ], 'fromJsonString');
-  }
+  validateFunctionParams([
+    { input: resolvedProviderVersion, paramName: 'resolvedProviderVersion', isString: true }
+  ], 'fromJsonString');
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (options?.providerVersion) {
validateFunctionParams([
{ input: options.providerVersion, paramName: 'providerVersion', isString: true }
], 'fromJsonString');
}
if (resolvedProviderVersion) {
validateFunctionParams([
{ input: resolvedProviderVersion, paramName: 'resolvedProviderVersion', isString: true }
], 'fromJsonString');
}
if (options?.providerVersion) {
validateFunctionParams([
{ input: options.providerVersion, paramName: 'providerVersion', isString: true }
], 'fromJsonString');
}
validateFunctionParams([
{ input: resolvedProviderVersion, paramName: 'resolvedProviderVersion', isString: true }
], 'fromJsonString');
🤖 Prompt for AI Agents
In src/Reclaim.ts around lines 337 to 347, the validation for
resolvedProviderVersion is conditional but it should be mandatory since the type
definition requires it. Remove the conditional check so that
validateFunctionParams is always called for resolvedProviderVersion, ensuring it
is validated regardless of its presence check.


const proofRequestInstance = new ReclaimProofRequest(applicationId, providerId, options);
proofRequestInstance.sessionId = sessionId;
proofRequestInstance.context = context;
Expand All @@ -332,6 +355,7 @@ export class ReclaimProofRequest {
proofRequestInstance.timeStamp = timeStamp
proofRequestInstance.signature = signature
proofRequestInstance.sdkVersion = sdkVersion;
proofRequestInstance.resolvedProviderVersion = resolvedProviderVersion;
return proofRequestInstance
} catch (error) {
logger.info('Failed to parse JSON string in fromJsonString:', error);
Expand Down Expand Up @@ -493,7 +517,8 @@ export class ReclaimProofRequest {
timeStamp: this.timeStamp,
options: this.options,
sdkVersion: this.sdkVersion,
jsonProofResponse: this.jsonProofResponse
jsonProofResponse: this.jsonProofResponse,
resolvedProviderVersion: this.resolvedProviderVersion ?? ''
})
}

Expand All @@ -509,6 +534,8 @@ export class ReclaimProofRequest {
const templateData: TemplateData = {
sessionId: this.sessionId,
providerId: this.providerId,
providerVersion: this.options?.providerVersion ?? '',
resolvedProviderVersion: this.resolvedProviderVersion ?? '',
applicationId: this.applicationId,
signature: this.signature,
timestamp: this.timeStamp,
Expand All @@ -519,6 +546,7 @@ export class ReclaimProofRequest {
acceptAiProviders: this.options?.acceptAiProviders ?? false,
sdkVersion: this.sdkVersion,
jsonProofResponse: this.jsonProofResponse

}
await updateSession(this.sessionId, SessionStatus.SESSION_STARTED)
if (this.options?.useAppClip) {
Expand Down Expand Up @@ -563,6 +591,8 @@ export class ReclaimProofRequest {
timestamp: this.timeStamp,
callbackUrl: this.getAppCallbackUrl(),
context: JSON.stringify(this.context),
providerVersion: this.options?.providerVersion ?? '',
resolvedProviderVersion: this.resolvedProviderVersion ?? '',
parameters: this.parameters,
redirectUrl: this.redirectUrl ?? '',
acceptAiProviders: this.options?.acceptAiProviders ?? false,
Expand Down
5 changes: 3 additions & 2 deletions src/utils/sessionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ export async function initSession(
providerId: string,
appId: string,
timestamp: string,
signature: string
signature: string,
versionNumber?: string
): Promise<InitSessionResponse> {
logger.info(`Initializing session for providerId: ${providerId}, appId: ${appId}`);
try {
const response = await fetch(`${BACKEND_BASE_URL}/api/sdk/init/session/`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ providerId, appId, timestamp, signature })
body: JSON.stringify({ providerId, appId, timestamp, signature, versionNumber })
});

const res = await response.json();
Expand Down
5 changes: 5 additions & 0 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type ProofRequestOptions = {
envUrl?: string;
useBrowserExtension?: boolean;
extensionID?: string;
providerVersion?: string;
};

// Modal customization options
Expand Down Expand Up @@ -66,6 +67,7 @@ export enum DeviceType {
// Session and response types
export type InitSessionResponse = {
sessionId: string;
resolvedProviderVersion: string;
};

export interface UpdateSessionResponse {
Expand Down Expand Up @@ -101,6 +103,7 @@ export type ProofPropertiesJSON = {
options?: ProofRequestOptions;
sdkVersion: string;
jsonProofResponse?: boolean;
resolvedProviderVersion: string;
};

export type TemplateData = {
Expand All @@ -116,6 +119,8 @@ export type TemplateData = {
acceptAiProviders: boolean;
sdkVersion: string;
jsonProofResponse?: boolean;
providerVersion?: string;
resolvedProviderVersion: string;
};

// Add the new StatusUrlResponse type
Expand Down
5 changes: 5 additions & 0 deletions src/utils/validationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ export function validateOptions(options: ProofRequestOptions): void {
logger.info(`Options validation failed: Provided log in options is not valid`);
throw new InvalidParamError(`The provided log in options is not valid`);
}

if (options.providerVersion && typeof options.providerVersion !== 'string') {
logger.info(`Options validation failed: Provided providerVersion in options is not valid`);
throw new InvalidParamError(`The provided providerVersion in options is not valid`);
}
}


Expand Down