diff --git a/src/iden3comm/constants.ts b/src/iden3comm/constants.ts index 2c8a1bc9..398767f1 100644 --- a/src/iden3comm/constants.ts +++ b/src/iden3comm/constants.ts @@ -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 { @@ -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 diff --git a/src/iden3comm/handlers/auth.ts b/src/iden3comm/handlers/auth.ts index b26bcd9a..bee9522a 100644 --- a/src/iden3comm/handlers/auth.ts +++ b/src/iden3comm/handlers/auth.ts @@ -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; diff --git a/src/iden3comm/packers/jws.ts b/src/iden3comm/packers/jws.ts index 5f05fab8..ab4ece8f 100644 --- a/src/iden3comm/packers/jws.ts +++ b/src/iden3comm/packers/jws.ts @@ -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; } diff --git a/src/iden3comm/packers/zkp.ts b/src/iden3comm/packers/zkp.ts index 3f403901..fd7f5425 100644 --- a/src/iden3comm/packers/zkp.ts +++ b/src/iden3comm/packers/zkp.ts @@ -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]; } } diff --git a/src/iden3comm/utils/accept-profile.ts b/src/iden3comm/utils/accept-profile.ts index 81d1ec2e..7c86a36d 100644 --- a/src/iden3comm/utils/accept-profile.ts +++ b/src/iden3comm/utils/accept-profile.ts @@ -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}'`); } @@ -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}'`); } diff --git a/tests/handlers/auth.test.ts b/tests/handlers/auth.test.ts index 42c06573..34ff1df4 100644 --- a/tests/handlers/auth.test.ts +++ b/tests/handlers/auth.test.ts @@ -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 = { @@ -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', diff --git a/tests/iden3comm/accept-profile.test.ts b/tests/iden3comm/accept-profile.test.ts index 65215008..b856b8cb 100644 --- a/tests/iden3comm/accept-profile.test.ts +++ b/tests/iden3comm/accept-profile.test.ts @@ -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] }