Skip to content

Commit

Permalink
fix: Do not retrieve AS metadata from store in case an external AS is…
Browse files Browse the repository at this point in the history
… used. Fetch from remote
  • Loading branch information
nklomp committed Jan 10, 2025
1 parent 6abab53 commit 99c3f8e
Show file tree
Hide file tree
Showing 40 changed files with 544 additions and 518 deletions.
4 changes: 2 additions & 2 deletions packages/contact-manager-rest-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
},
"dependencies": {
"@sphereon/ssi-express-support": "workspace:*",
"@sphereon/ssi-sdk-ext.key-manager": "0.27.0",
"@sphereon/ssi-sdk-ext.key-utils": "0.27.0",
"@sphereon/ssi-sdk-ext.key-manager": "0.27.1-next.6",
"@sphereon/ssi-sdk-ext.key-utils": "0.27.1-next.6",
"@sphereon/ssi-sdk.contact-manager": "workspace:*",
"@sphereon/ssi-sdk.core": "workspace:*",
"@sphereon/ssi-sdk.data-store": "workspace:*",
Expand Down
59 changes: 30 additions & 29 deletions packages/credential-validation/src/agent/CredentialValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ import {
ICredentialSchemaType,
IVerifyResult,
OriginalVerifiableCredential,
WrappedVerifiableCredential
WrappedVerifiableCredential,
} from '@sphereon/ssi-types'
import {
IAgentPlugin,
IVerifyCredentialArgs,
W3CVerifiableCredential as VeramoW3CVerifiableCredential
} from '@veramo/core'
import { IAgentPlugin, IVerifyCredentialArgs, W3CVerifiableCredential as VeramoW3CVerifiableCredential } from '@veramo/core'
import addFormats from 'ajv-formats'
import Ajv2020 from 'ajv/dist/2020'
import fetch from 'cross-fetch'
Expand All @@ -27,7 +23,7 @@ import {
VerificationSubResult,
VerifyCredentialArgs,
VerifyMdocCredentialArgs,
VerifySDJWTCredentialArgs
VerifySDJWTCredentialArgs,
} from '../index'
import IVerifySignatureResult = com.sphereon.crypto.generic.IVerifySignatureResult
import decodeFrom = com.sphereon.kmp.decodeFrom
Expand All @@ -39,7 +35,7 @@ export const credentialValidationMethods: Array<string> = [
'cvVerifySchema',
'cvVerifyMdoc',
'cvVerifySDJWTCredential',
'cvVerifyW3CCredential'
'cvVerifyW3CCredential',
]

/**
Expand All @@ -52,7 +48,7 @@ export class CredentialValidation implements IAgentPlugin {
cvVerifySchema: this.cvVerifySchema.bind(this),
cvVerifyMdoc: this.cvVerifyMdoc.bind(this),
cvVerifySDJWTCredential: this.cvVerifySDJWTCredential.bind(this),
cvVerifyW3CCredential: this.cvVerifyW3CCredential.bind(this)
cvVerifyW3CCredential: this.cvVerifyW3CCredential.bind(this),
}

private detectSchemas(wrappedVC: WrappedVerifiableCredential): ICredentialSchemaType[] | undefined {
Expand All @@ -79,7 +75,7 @@ export class CredentialValidation implements IAgentPlugin {
const schemaResult = await this.cvVerifySchema({
credential,
validationPolicy: policies?.schemaValidation ?? SchemaValidation.WHEN_PRESENT,
hasher
hasher,
})
if (!schemaResult.result) {
return schemaResult
Expand All @@ -89,10 +85,13 @@ export class CredentialValidation implements IAgentPlugin {
} else if (CredentialMapper.isSdJwtEncoded(credential)) {
return await this.cvVerifySDJWTCredential({ credential, hasher }, context)
} else {
return await this.cvVerifyW3CCredential({
...args,
credential: credential as VeramoW3CVerifiableCredential
}, context)
return await this.cvVerifyW3CCredential(
{
...args,
credential: credential as VeramoW3CVerifiableCredential,
},
context,
)
}
}

Expand All @@ -103,7 +102,7 @@ export class CredentialValidation implements IAgentPlugin {
return {
result: true,
source: wrappedCredential,
subResults: []
subResults: [],
}
}
return this.validateSchema(wrappedCredential, validationPolicy)
Expand All @@ -113,17 +112,19 @@ export class CredentialValidation implements IAgentPlugin {
const schemas: ICredentialSchemaType[] | undefined = this.detectSchemas(wrappedVC)
if (!schemas) {
if (validationPolicy === SchemaValidation.ALWAYS) {
console.error(`No schema found for credential, but validation policy is set to ALWAYS. Returning false. Credential: ${JSON.stringify(wrappedVC.credential, null, 2)}`)
console.error(
`No schema found for credential, but validation policy is set to ALWAYS. Returning false. Credential: ${JSON.stringify(wrappedVC.credential, null, 2)}`,
)
return {
result: false,
source: wrappedVC,
subResults: []
subResults: [],
}
} else {
return {
result: true,
source: wrappedVC,
subResults: []
subResults: [],
}
}
}
Expand All @@ -133,7 +134,7 @@ export class CredentialValidation implements IAgentPlugin {
return {
result: subResults.every((subResult) => subResult.result),
source: wrappedVC,
subResults
subResults,
}
}

Expand All @@ -154,7 +155,7 @@ export class CredentialValidation implements IAgentPlugin {
console.error(error)
return {
result: false,
error: error
error: error,
}
}

Expand All @@ -167,7 +168,7 @@ export class CredentialValidation implements IAgentPlugin {
console.error(`Schema validation failed for `, wrappedVC.credential)
}
return {
result: valid
result: valid,
}
}

Expand All @@ -182,7 +183,7 @@ export class CredentialValidation implements IAgentPlugin {
name: 'mdoc',
critical: true,
error: true,
message: error.message ?? 'Mdoc Issuer Signed VC could not be verified'
message: error.message ?? 'Mdoc Issuer Signed VC could not be verified',
} satisfies IVerifySignatureResult<ICoseKeyJson>
})

Expand All @@ -191,8 +192,8 @@ export class CredentialValidation implements IAgentPlugin {
result: !verification.error,
subResults: [],
...(verification.error && {
error: verification.message ?? `Could not verify mdoc from issuer`
})
error: verification.message ?? `Could not verify mdoc from issuer`,
}),
}
}

Expand All @@ -209,9 +210,9 @@ export class CredentialValidation implements IAgentPlugin {
result,
...(!result && {
error: 'Invalid JWT VC',
errorDetails: `JWT VC was not valid with policies: ${JSON.stringify(policies)}`
errorDetails: `JWT VC was not valid with policies: ${JSON.stringify(policies)}`,
}),
subResults: []
subResults: [],
}
} else {
// TODO look at what this is doing and make it simple and readable
Expand All @@ -236,7 +237,7 @@ export class CredentialValidation implements IAgentPlugin {
result: result.verified,
subResults,
error,
errorDetails
errorDetails,
}
}
}
Expand All @@ -250,7 +251,7 @@ export class CredentialValidation implements IAgentPlugin {
console.error(error)
return {
error: 'Invalid SD-JWT VC',
errorDetails: error.message ?? 'SD-JWT VC could not be verified'
errorDetails: error.message ?? 'SD-JWT VC could not be verified',
}
})

Expand All @@ -259,7 +260,7 @@ export class CredentialValidation implements IAgentPlugin {
source: CredentialMapper.toWrappedVerifiableCredential(credential as OriginalVerifiableCredential, { hasher }),
result,
subResults: [],
...(!result && { ...verification })
...(!result && { ...verification }),
}
}
}
4 changes: 2 additions & 2 deletions packages/data-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"dependencies": {
"@sphereon/kmp-mdoc-core": "0.2.0-SNAPSHOT.26",
"@sphereon/pex": "5.0.0-unstable.28",
"@sphereon/ssi-sdk-ext.did-utils": "0.27.0",
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.27.0",
"@sphereon/ssi-sdk-ext.did-utils": "0.27.1-next.6",
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.27.1-next.6",
"@sphereon/ssi-sdk.agent-config": "workspace:*",
"@sphereon/ssi-sdk.core": "workspace:*",
"@sphereon/ssi-types": "workspace:*",
Expand Down
14 changes: 7 additions & 7 deletions packages/ebsi-support/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
"@sphereon/did-auth-siop-adapter": "0.16.1-feature.MWALL.715.258",
"@sphereon/pex": "5.0.0-unstable.28",
"@sphereon/pex-models": "^2.3.2",
"@sphereon/ssi-sdk-ext.did-resolver-ebsi": "0.27.0",
"@sphereon/ssi-sdk-ext.did-utils": "0.27.0",
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.27.0",
"@sphereon/ssi-sdk-ext.jwt-service": "0.27.0",
"@sphereon/ssi-sdk-ext.key-utils": "0.27.0",
"@sphereon/ssi-sdk-ext.did-resolver-ebsi": "0.27.1-next.6",
"@sphereon/ssi-sdk-ext.did-utils": "0.27.1-next.6",
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.27.1-next.6",
"@sphereon/ssi-sdk-ext.jwt-service": "0.27.1-next.6",
"@sphereon/ssi-sdk-ext.key-utils": "0.27.1-next.6",
"@sphereon/ssi-sdk.contact-manager": "workspace:*",
"@sphereon/ssi-sdk.core": "workspace:*",
"@sphereon/ssi-sdk.oid4vci-holder": "workspace:*",
Expand All @@ -47,8 +47,8 @@
"@sphereon/oid4vci-client": "0.16.1-feature.MWALL.715.258",
"@sphereon/oid4vci-common": "0.16.1-feature.MWALL.715.258",
"@sphereon/ssi-express-support": "workspace:*",
"@sphereon/ssi-sdk-ext.key-manager": "0.27.0",
"@sphereon/ssi-sdk-ext.kms-local": "0.27.0",
"@sphereon/ssi-sdk-ext.key-manager": "0.27.1-next.6",
"@sphereon/ssi-sdk-ext.kms-local": "0.27.1-next.6",
"@sphereon/ssi-sdk.agent-config": "workspace:*",
"@sphereon/ssi-sdk.data-store": "workspace:*",
"@sphereon/ssi-sdk.public-key-hosting": "workspace:*",
Expand Down
10 changes: 5 additions & 5 deletions packages/mdl-mdoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"@sphereon/kmp-mdoc-core": "0.2.0-SNAPSHOT.26",
"@sphereon/pex": "5.0.0-unstable.28",
"@sphereon/pex-models": "^2.3.2",
"@sphereon/ssi-sdk-ext.did-utils": "0.27.0",
"@sphereon/ssi-sdk-ext.key-utils": "0.27.0",
"@sphereon/ssi-sdk-ext.x509-utils": "0.27.0",
"@sphereon/ssi-sdk-ext.did-utils": "0.27.1-next.6",
"@sphereon/ssi-sdk-ext.key-utils": "0.27.1-next.6",
"@sphereon/ssi-sdk-ext.x509-utils": "0.27.1-next.6",
"@sphereon/ssi-sdk.core": "workspace:*",
"@sphereon/ssi-types": "workspace:*",
"@veramo/core": "4.2.0",
Expand All @@ -38,8 +38,8 @@
"@sphereon/oid4vci-client": "0.16.1-feature.MWALL.715.258",
"@sphereon/oid4vci-common": "0.16.1-feature.MWALL.715.258",
"@sphereon/ssi-express-support": "workspace:*",
"@sphereon/ssi-sdk-ext.key-manager": "0.27.0",
"@sphereon/ssi-sdk-ext.kms-local": "0.27.0",
"@sphereon/ssi-sdk-ext.key-manager": "0.27.1-next.6",
"@sphereon/ssi-sdk-ext.kms-local": "0.27.1-next.6",
"@sphereon/ssi-sdk.agent-config": "workspace:*",
"@sphereon/ssi-sdk.data-store": "workspace:*",
"@sphereon/ssi-sdk.public-key-hosting": "workspace:*",
Expand Down
Loading

0 comments on commit 99c3f8e

Please sign in to comment.