Skip to content

Commit

Permalink
update js-sdk to 1.26.0 and verify response typ
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-basiuk committed Jan 14, 2025
1 parent a197115 commit 3f6ba95
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
14 changes: 10 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"url": "https://github.com/iden3/js-iden3-auth"
},
"dependencies": {
"@0xpolygonid/js-sdk": "1.23.0",
"@0xpolygonid/js-sdk": "1.26.0",
"@iden3/js-crypto": "1.1.0",
"@iden3/js-iden3-core": "1.4.1",
"@iden3/js-jsonld-merklization": "1.4.1",
Expand Down
17 changes: 6 additions & 11 deletions src/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,11 @@ export class Verifier {
opts?: VerifyOpts
): Promise<AuthorizationResponseMessage> {
const msg = await this.packageManager.unpack(byteEncoder.encode(tokenStr));

if (request.body.accept?.length && !request.body.accept.includes(msg.unpackedMediaType)) {
throw new Error('response media type is not accepted by request');
}

const response = msg.unpackedMessage as AuthorizationResponseMessage;
await this.verifyAuthResponse(response, request, opts);
return response;
Expand All @@ -438,17 +443,7 @@ export class Verifier {
}
const supportedMediaTypes: PROTOCOL_CONSTANTS.MediaType[] = [];
for (const acceptProfile of profile) {
// 1. check protocol version
const { protocolVersion, env } = parseAcceptProfile(acceptProfile);
const messageTypeVersion = Number(messageType.split('/').at(-2));
if (
protocolVersion !== PROTOCOL_CONSTANTS.ProtocolVersion.V1 ||
(protocolVersion === PROTOCOL_CONSTANTS.ProtocolVersion.V1 &&
(messageTypeVersion < 1 || messageTypeVersion >= 2))
) {
continue;
}
// 2. check packer support
const { env } = parseAcceptProfile(acceptProfile);
if (this.packageManager.isProfileSupported(env, acceptProfile)) {
supportedMediaTypes.push(env);
}
Expand Down

0 comments on commit 3f6ba95

Please sign in to comment.