Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-basiuk committed Nov 19, 2024
1 parent de2915d commit d20b82d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 44 deletions.
14 changes: 7 additions & 7 deletions src/iden3comm/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@ export const SUPPORTED_PUBLIC_KEY_TYPES = {
};

export enum ProtocolVersion {
v1 = 'iden3comm/v1'
V1 = 'iden3comm/v1'
}

export enum AcceptAuthCircuits {
authV2 = 'authV2',
authV3 = 'authV3'
AuthV2 = 'authV2',
AuthV3 = 'authV3'
}

export enum AcceptJwzAlgorithms {
groth16 = 'groth16'
Groth16 = 'groth16'
}

export enum AcceptJwsAlgorithms {
Expand All @@ -100,10 +100,10 @@ export enum AcceptJwsAlgorithms {
}

export const defaultAcceptProfile: AcceptProfile = {
protocolVersion: ProtocolVersion.v1,
protocolVersion: ProtocolVersion.V1,
env: MediaType.ZKPMessage,
circuits: [AcceptAuthCircuits.authV2],
alg: [AcceptJwzAlgorithms.groth16]
circuits: [AcceptAuthCircuits.AuthV2],
alg: [AcceptJwzAlgorithms.Groth16]
};

export const DEFAULT_PROOF_VERIFY_DELAY = 1 * 60 * 60 * 1000; // 1 hour
Expand Down
4 changes: 2 additions & 2 deletions src/iden3comm/handlers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ export class AuthHandler
const { protocolVersion, env } = parseAcceptProfile(acceptProfile);
const responseTypeVersion = Number(responseType.split('/').at(-2));
if (
protocolVersion !== ProtocolVersion.v1 ||
(protocolVersion === ProtocolVersion.v1 &&
protocolVersion !== ProtocolVersion.V1 ||
(protocolVersion === ProtocolVersion.V1 &&
(responseTypeVersion < 1 || responseTypeVersion >= 2))
) {
continue;
Expand Down
11 changes: 3 additions & 8 deletions src/iden3comm/packers/jws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,10 @@ export class JWSPacker implements IPacker {
throw new Error(`Circuits are not supported for ${env} media type`);
}

let algSupported = !alg?.length;
const supportedAlgArr = this.getSupportedAlgorithms();
for (const a of alg || []) {
if (supportedAlgArr.includes(a as AcceptJwsAlgorithms)) {
algSupported = true;
break;
}
}

const algSupported = (alg || []).some((a) =>
supportedAlgArr.includes(a as AcceptJwsAlgorithms)
);
return algSupported;
}

Expand Down
23 changes: 6 additions & 17 deletions src/iden3comm/packers/zkp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,33 +192,22 @@ export class ZKPPacker implements IPacker {
return false;
}

let circuitIdSupported = !circuits?.length;
const supportedCircuitIds = this.getSupportedCircuitIds();
for (const c of circuits || []) {
if (supportedCircuitIds.includes(c)) {
circuitIdSupported = true;
break;
}
}
const circuitIdSupported = (circuits || []).some((c) => supportedCircuitIds.includes(c));

let algSupported = !alg?.length;
const supportedAlgArr = this.getSupportedAlgorithms();
for (const a of alg || []) {
if (supportedAlgArr.includes(a as AcceptJwzAlgorithms)) {
algSupported = true;
break;
}
}

const algSupported = (alg || []).some((a) =>
supportedAlgArr.includes(a as AcceptJwzAlgorithms)
);
return algSupported && circuitIdSupported;
}

private getSupportedAlgorithms(): AcceptJwzAlgorithms[] {
return [AcceptJwzAlgorithms.groth16];
return [AcceptJwzAlgorithms.Groth16];
}

private getSupportedCircuitIds(): AcceptAuthCircuits[] {
return [AcceptAuthCircuits.authV2];
return [AcceptAuthCircuits.AuthV2];
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/iden3comm/utils/accept-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ export const parseAcceptProfile = (profile: string): AcceptProfile => {
alg = params[algIndex]
.split('=')[1]
.split(',')
.map((i) => i.trim())
.map((i) => {
i = i.trim();
if (!isAcceptJwzAlgorithms(i)) {
throw new Error(`Algorithm '${i}' not supported for '${env}'`);
}
Expand All @@ -100,8 +100,8 @@ export const parseAcceptProfile = (profile: string): AcceptProfile => {
alg = params[algIndex]
.split('=')[1]
.split(',')
.map((i) => i.trim())
.map((i) => {
i = i.trim();
if (!isAcceptJwsAlgorithms(i)) {
throw new Error(`Algorithm '${i}' not supported for '${env}'`);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/handlers/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ describe('auth', () => {
};

const profile: AcceptProfile = {
protocolVersion: ProtocolVersion.v1,
protocolVersion: ProtocolVersion.V1,
env: MediaType.ZKPMessage,
circuits: [AcceptAuthCircuits.authV2]
circuits: [AcceptAuthCircuits.AuthV2]
};

const authReqBody: AuthorizationRequestMessageBody = {
Expand Down Expand Up @@ -2417,9 +2417,9 @@ describe('auth', () => {
};

const authV3NotSupportedProfile: AcceptProfile = {
protocolVersion: ProtocolVersion.v1,
protocolVersion: ProtocolVersion.V1,
env: MediaType.ZKPMessage,
circuits: [AcceptAuthCircuits.authV3]
circuits: [AcceptAuthCircuits.AuthV3]
};
const authReqBody: AuthorizationRequestMessageBody = {
callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123',
Expand Down
8 changes: 4 additions & 4 deletions tests/iden3comm/accept-profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ describe('accept profile utils test', () => {

const accept = buildAccept([
{
protocolVersion: ProtocolVersion.v1,
protocolVersion: ProtocolVersion.V1,
env: MediaType.ZKPMessage,
circuits: [AcceptAuthCircuits.authV2, AcceptAuthCircuits.authV3],
alg: [AcceptJwzAlgorithms.groth16]
circuits: [AcceptAuthCircuits.AuthV2, AcceptAuthCircuits.AuthV3],
alg: [AcceptJwzAlgorithms.Groth16]
},
{
protocolVersion: ProtocolVersion.v1,
protocolVersion: ProtocolVersion.V1,
env: MediaType.SignedMessage,
alg: [AcceptJwsAlgorithms.ES256KR]
}
Expand Down

0 comments on commit d20b82d

Please sign in to comment.