Skip to content

Commit

Permalink
fix: format
Browse files Browse the repository at this point in the history
  • Loading branch information
auer-martin committed Sep 26, 2024
1 parent 7b54fae commit 688fb6d
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 41 deletions.
2 changes: 1 addition & 1 deletion packages/client/lib/AccessTokenClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class AccessTokenClient {

return request as AccessTokenRequest;
}

throw new Error('Credential offer request follows neither pre-authorized code nor authorization code flow requirements.');
}

Expand Down
2 changes: 1 addition & 1 deletion packages/oid4vci-common/lib/types/Authorization.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export interface AuthorizationRequestOpts {
redirectUri?: string;
scope?: string;
requestObjectOpts?: RequestObjectOpts;
holderPreferredAuthzFlowTypeOrder?: AuthzFlowType[]
holderPreferredAuthzFlowTypeOrder?: AuthzFlowType[];
}

export interface AuthorizationResponse {
Expand Down
2 changes: 1 addition & 1 deletion packages/siop-oid4vp/lib/__tests__/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import crypto, { createHash } from 'crypto'

import { JwtPayload, parseJWT, SigningAlgo, uuidv4 } from '@sphereon/oid4vc-common'
import { PartialSdJwtDecodedVerifiableCredential } from '@sphereon/pex/dist/main/lib'
import { IProofType } from '@sphereon/ssi-types'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand Down Expand Up @@ -39,7 +40,6 @@ import {
VERIFIERZ_PURPOSE_TO_VERIFY,
VERIFIERZ_PURPOSE_TO_VERIFY_NL,
} from './data/mockedData'
import { PartialSdJwtDecodedVerifiableCredential } from '@sphereon/pex/dist/main/lib'

export interface TESTKEY {
key: JWK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('OID4VCI-Client using Mattr issuer should', () => {

const correlationId = 'test'

const authorizationRequest = await AuthorizationRequest.fromUriOrJwt(offer.authorizeRequestUri);
const authorizationRequest = await AuthorizationRequest.fromUriOrJwt(offer.authorizeRequestUri)
const verifiedAuthRequest = await authorizationRequest.verify({
correlationId,
verifyJwtCallback: getVerifyJwtCallback(getResolver()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ describe('Language tag util should', () => {
it('return empty if list is given but not effective', async () => {
expect.assertions(1)
const result = await LanguageTagUtils.getLanguageTaggedProperties({}, [])
expect(result).toEqual(new Map<string, string>)
expect(result).toEqual(new Map<string, string>())
})

it('throw error if list is given but no proper field names', async () => {
Expand All @@ -227,7 +227,7 @@ describe('Language tag util should', () => {
it('return empty map if mapping is given but not effective', async () => {
expect.assertions(1)
const result = await LanguageTagUtils.getLanguageTaggedPropertiesMapped({}, new Map<string, string>())
expect(result).toEqual(new Map<string, string>)
expect(result).toEqual(new Map<string, string>())
})

it('throw error if mapping is given but no proper names', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Status,
Validated,
VerifiablePresentationFromOpts,
VerifiablePresentationResult
VerifiablePresentationResult,
} from '@sphereon/pex'
import { PresentationEvaluationResults } from '@sphereon/pex/dist/main/lib/evaluation'
import { Format, PresentationDefinitionV1, PresentationDefinitionV2, PresentationSubmission } from '@sphereon/pex-models'
Expand Down Expand Up @@ -117,9 +117,11 @@ export class PresentationExchange {
}

public static assertValidPresentationSubmission(presentationSubmission: PresentationSubmission) {
const validationResult:Validated = PEX.validateSubmission(presentationSubmission)
if (Array.isArray(validationResult) && validationResult[0].message != 'ok'
|| !Array.isArray(validationResult) && validationResult.message != 'ok') {
const validationResult: Validated = PEX.validateSubmission(presentationSubmission)
if (
(Array.isArray(validationResult) && validationResult[0].message != 'ok') ||
(!Array.isArray(validationResult) && validationResult.message != 'ok')
) {
throw new Error(`${SIOPErrors.RESPONSE_OPTS_PRESENTATIONS_SUBMISSION_IS_NOT_VALID}, details ${JSON.stringify(validationResult)}`)
}
}
Expand Down Expand Up @@ -244,8 +246,10 @@ export class PresentationExchange {

private static assertValidPresentationDefinition(presentationDefinition: IPresentationDefinition) {
const validationResult = PEX.validateDefinition(presentationDefinition)
if (Array.isArray(validationResult) && validationResult[0].message != 'ok'
|| !Array.isArray(validationResult) && validationResult.message != 'ok') {
if (
(Array.isArray(validationResult) && validationResult[0].message != 'ok') ||
(!Array.isArray(validationResult) && validationResult.message != 'ok')
) {
throw new Error(`${SIOPErrors.REQUEST_CLAIMS_PRESENTATION_DEFINITION_NOT_VALID}`)
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/siop-oid4vp/lib/helpers/Encodings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export function decodeUriAsJson(uri: string) {
}
const parts = parse(queryString, { plainObjects: true, depth: 10, parameterLimit: 5000, ignoreQueryPrefix: true })

const vpToken = (parts?.claims as { [key: string]: any })?.['vp_token'];
const descriptors = vpToken?.presentation_definition?.['input_descriptors']; // FIXME?
const vpToken = (parts?.claims as { [key: string]: any })?.['vp_token']
const descriptors = vpToken?.presentation_definition?.['input_descriptors'] // FIXME?
if (descriptors && Array.isArray(descriptors)) {
// Whenever we have a [{'uri': 'str1'}, 'uri': 'str2'] qs changes this to {uri: ['str1','str2']} which means schema validation fails. So we have to fix that
vpToken.presentation_definition['input_descriptors'] = descriptors.map((descriptor: InputDescriptorV1) => {
Expand All @@ -33,7 +33,7 @@ export function decodeUriAsJson(uri: string) {
})
}

const json:Record<string, any> = {}
const json: Record<string, any> = {}
for (const key in parts) {
const value = parts[key]
if (!value) {
Expand Down
2 changes: 1 addition & 1 deletion packages/siop-oid4vp/lib/helpers/HttpUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const siopFetch = async <T>(
if (!url || url.toLowerCase().startsWith('did:')) {
throw Error(`Invalid URL supplied. Expected a http(s) URL. Recieved: ${url}`)
}
const headers:Record<string, any> = opts?.customHeaders ? opts.customHeaders : {}
const headers: Record<string, any> = opts?.customHeaders ? opts.customHeaders : {}
if (opts?.bearerToken) {
headers['Authorization'] = `Bearer ${opts.bearerToken}`
}
Expand Down
2 changes: 1 addition & 1 deletion packages/siop-oid4vp/lib/helpers/LanguageTagUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class LanguageTagUtils {
* @param source is the object from which the language enabled fields and their values will be extracted.
*/
static getAllLanguageTaggedProperties(source: object): Map<string, string> {
return this.getLanguageTaggedPropertiesMapped(source, new Map() )
return this.getLanguageTaggedPropertiesMapped(source, new Map())
}

/**
Expand Down
7 changes: 5 additions & 2 deletions packages/siop-oid4vp/lib/helpers/Metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export function assertValidMetadata(opMetadata: DiscoveryMetadataPayload, rpMeta
const credentials = supportedCredentialsFormats(rpMetadata.vp_formats, opMetadata.vp_formats)
const isValidSubjectSyntax = verifySubjectSyntaxes(rpMetadata.subject_syntax_types_supported)
if (isValidSubjectSyntax && rpMetadata.subject_syntax_types_supported) {
subjectSyntaxTypesSupported = supportedSubjectSyntaxTypes(rpMetadata.subject_syntax_types_supported, opMetadata.subject_syntax_types_supported as string[])
subjectSyntaxTypesSupported = supportedSubjectSyntaxTypes(
rpMetadata.subject_syntax_types_supported,
opMetadata.subject_syntax_types_supported as string[],
)
} else if (isValidSubjectSyntax && (!rpMetadata.subject_syntax_types_supported || !rpMetadata.subject_syntax_types_supported.length)) {
if (opMetadata.subject_syntax_types_supported) {
subjectSyntaxTypesSupported = [...opMetadata.subject_syntax_types_supported]
Expand Down Expand Up @@ -107,7 +110,7 @@ function getFormatIntersection(rpFormat: Format, opFormat: Format): Format {
throw new Error(SIOPErrors.CREDENTIAL_FORMATS_NOT_SUPPORTED)
}
intersectionFormat[crFormat] = {}
if(methodKeyOP !== undefined) {
if (methodKeyOP !== undefined) {
intersectionFormat[crFormat][methodKeyOP] = algs
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/siop-oid4vp/lib/helpers/ObjectUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function isStringNullOrEmpty(key: string) {
return !key || !key.length
}

export function removeNullUndefined<T>(data: T) : T {
export function removeNullUndefined<T>(data: T): T {
if (!data) {
return data
}
Expand Down
8 changes: 5 additions & 3 deletions packages/siop-oid4vp/lib/helpers/Revocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ export const verifyRevocation = async (
throw new Error(`Revocation callback not provided`)
}

const vcs = (CredentialMapper.isWrappedSdJwtVerifiablePresentation(vpToken) || CredentialMapper.isWrappedMdocPresentation(vpToken))
? [vpToken.vcs[0]] : vpToken.presentation.verifiableCredential
const vcs =
CredentialMapper.isWrappedSdJwtVerifiablePresentation(vpToken) || CredentialMapper.isWrappedMdocPresentation(vpToken)
? [vpToken.vcs[0]]
: vpToken.presentation.verifiableCredential
for (const vc of vcs) {
if (
revocationVerification === RevocationVerification.ALWAYS ||
Expand All @@ -39,7 +41,7 @@ function originalTypeToVerifiableCredentialTypeFormat(original: WrappedVerifiabl
jwt_vc: VerifiableCredentialTypeFormat.JWT_VC,
ldp: VerifiableCredentialTypeFormat.LDP_VC,
ldp_vc: VerifiableCredentialTypeFormat.LDP_VC,
mso_mdoc: VerifiableCredentialTypeFormat.MSO_MDOC
mso_mdoc: VerifiableCredentialTypeFormat.MSO_MDOC,
}

return mapping[original]
Expand Down
7 changes: 5 additions & 2 deletions packages/siop-oid4vp/lib/request-object/RequestObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ export class RequestObject {
return requestObjectJwt ? new RequestObject(undefined, undefined, requestObjectJwt) : undefined
}

public static async fromPayload(requestObjectPayload: RequestObjectPayload, authorizationRequestOpts: CreateAuthorizationRequestOpts): Promise<RequestObject> {
public static async fromPayload(
requestObjectPayload: RequestObjectPayload,
authorizationRequestOpts: CreateAuthorizationRequestOpts,
): Promise<RequestObject> {
return new RequestObject(authorizationRequestOpts, requestObjectPayload)
}

public static async fromAuthorizationRequestPayload(payload: AuthorizationRequestPayload): Promise<RequestObject | undefined> {
const requestObjectJwt =
payload.request ?? payload.request_uri ? await fetchByReferenceOrUseByValue(payload.request_uri as string, payload.request, true) : undefined
(payload.request ?? payload.request_uri) ? await fetchByReferenceOrUseByValue(payload.request_uri as string, payload.request, true) : undefined
return requestObjectJwt ? await RequestObject.fromJwt(requestObjectJwt) : undefined
}

Expand Down
5 changes: 4 additions & 1 deletion packages/siop-oid4vp/lib/rp/Opts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ export const createRequestOptsFromBuilderOrExistingOpts = (opts: { builder?: RPB
return createRequestOpts
}

export const createVerifyResponseOptsFromBuilderOrExistingOpts = (opts: { builder?: RPBuilder; verifyOpts?: VerifyAuthorizationResponseOpts }): Partial<VerifyAuthorizationResponseOpts> => {
export const createVerifyResponseOptsFromBuilderOrExistingOpts = (opts: {
builder?: RPBuilder
verifyOpts?: VerifyAuthorizationResponseOpts
}): Partial<VerifyAuthorizationResponseOpts> => {
return opts.builder
? {
hasher: opts.builder.hasher ?? defaultHasher,
Expand Down
4 changes: 2 additions & 2 deletions packages/siop-oid4vp/lib/types/VpJwtVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ export const getRequestObjectJwtVerifier = async (
typeof attestationPayload.exp !== 'number' ||
typeof attestationPayload.cnf !== 'object' ||
!attestationPayload.cnf ||
(!('jwk' in attestationPayload.cnf)
|| typeof attestationPayload.cnf['jwk'] !== 'object')
!('jwk' in attestationPayload.cnf) ||
typeof attestationPayload.cnf['jwk'] !== 'object'
) {
throw new Error(SIOPErrors.BAD_VERIFIER_ATTESTATION)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/siop-oid4vp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
},
"dependencies": {
"@astronautlabs/jsonpath": "^1.1.2",
"@protokoll/jarm": "^0.2.10",
"@protokoll/core": "^0.2.10",
"@protokoll/jarm": "^0.2.11",
"@protokoll/core": "^0.2.11",
"@sphereon/did-uni-client": "^0.6.2",
"@sphereon/oid4vc-common": "workspace:*",
"@sphereon/pex": "5.0.0-unstable.2",
Expand Down
34 changes: 23 additions & 11 deletions pnpm-lock.yaml

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

0 comments on commit 688fb6d

Please sign in to comment.