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 1 commit
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 package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 @@ -485,7 +509,8 @@ export class ReclaimProofRequest {
timeStamp: this.timeStamp,
options: this.options,
sdkVersion: this.sdkVersion,
jsonProofResponse: this.jsonProofResponse
jsonProofResponse: this.jsonProofResponse,
resolvedProviderVersion: this.resolvedProviderVersion ?? ''
})
}

Expand All @@ -501,6 +526,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 @@ -511,6 +538,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 @@ -555,6 +583,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
6 changes: 6 additions & 0 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ export type OnError = (error: Error) => void;

export type ProofRequestOptions = {
log?: boolean;
versionNumber?: string;
acceptAiProviders?: boolean;
useAppClip?: boolean;
device?: string;
envUrl?: string;
useBrowserExtension?: boolean;
extensionID?: string;
providerVersion?: string;
};

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

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

export type TemplateData = {
Expand All @@ -116,6 +120,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