Skip to content

Commit

Permalink
fix: Ed25519 2018 handling for verification
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Sep 27, 2023
1 parent 14125e5 commit b858710
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 53 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"ethr-did": "2.3.9",
"typeorm": "0.3.17",
"@mattrglobal/[email protected]>jsonld": "4.0.1",
"jsonld": "link:./node_modules/.pnpm/@digitalcredentials+jsonld@5.2.1/node_modules/@digitalcredentials/jsonld",
"jsonld": "link:./node_modules/.pnpm/@digitalcredentials+jsonld@6.0.0/node_modules/@digitalcredentials/jsonld",
"isomorphic-webcrypto": "link:./node_modules/@sphereon/isomorphic-webcrypto"
},
"patchedDependencies": {
Expand Down
11 changes: 6 additions & 5 deletions packages/vc-handler-ld-local/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
},
"dependencies": {
"@digitalcredentials/ed25519-signature-2020": "~3.0.2",
"@digitalcredentials/ed25519-verification-key-2020": "3.2.2",
"@digitalcredentials/ed25519-verification-key-2020": "^4.0.0",
"@veramo-community/lds-ecdsa-secp256k1-recovery2020": "uport-project/EcdsaSecp256k1RecoverySignature2020",
"@digitalcredentials/jsonld": "^5.2.1",
"@digitalcredentials/jsonld-signatures": "^9.3.1",
"@digitalcredentials/jsonld": "^6.0.0",
"@digitalcredentials/jsonld-signatures": "^9.3.2",
"@digitalcredentials/rdf-canonize": "^1.0.0",
"@digitalcredentials/vc": "^5.0.0",
"@digitalcredentials/vc": "^6.0.0",
"@digitalcredentials/x25519-key-agreement-2020-context": "^1.0.0",
"@mattrglobal/jsonld-signatures-bbs": "^1.1.2",
"@mattrglobal/jsonld-signatures-bbs": "^1.2.0",
"@noble/hashes": "^1.2.0",
"@sphereon/isomorphic-webcrypto": "^2.4.0-unstable.4",
"@sphereon/ssi-types": "workspace:*",
Expand All @@ -43,6 +43,7 @@
"@transmute/secp256k1-key-pair": "0.7.0-unstable.81",
"@transmute/security-context": "0.7.0-unstable.81",
"@transmute/vc-status-rl-2020": "0.7.0-unstable.81",
"@transmute/credentials-context": "^0.7.0-unstable.81",
"@transmute/web-crypto-key-pair": "0.7.0-unstable.81",
"@veramo/core": "4.2.0",
"@veramo/utils": "4.2.0",
Expand Down
6 changes: 4 additions & 2 deletions packages/vc-handler-ld-local/src/__tests__/diwala.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ describe('Diwala issued VC', () => {
valid: true,
},
verificationMethod: {
'@context': ['https://w3id.org/security/suites/ed25519-2018/v1'],
'@context': ["https://www.w3.org/ns/did/v1", 'https://w3id.org/security/suites/ed25519-2018/v1'],
controller: {
id: 'did:key:z6MkrzXCdarP1kaZcJb3pmNi295wfxerDrmTqPv5c6MkP2r9',
id: 'did:key:z6MkrzXCdarP1kaZcJb3pmNi295wfxerDrmTqPv5c6MkP2r9#z6MkrzXCdarP1kaZcJb3pmNi295wfxerDrmTqPv5c6MkP2r9',
// @fixme: The above is incorrect. Controller should be the DID not a VM, like below
//id: 'did:key:z6MkrzXCdarP1kaZcJb3pmNi295wfxerDrmTqPv5c6MkP2r9',
},
id: 'did:key:z6MkrzXCdarP1kaZcJb3pmNi295wfxerDrmTqPv5c6MkP2r9#z6MkrzXCdarP1kaZcJb3pmNi295wfxerDrmTqPv5c6MkP2r9',
publicKeyBase58: 'DYGA3LbwgD66VokM9CQsB3XwrPNzoyX79P19mpPjTp4m',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const customContext = new Map<string, ContextDoc>([
['https://sphereon-opensource.github.io/vc-contexts/myc/bedrijfsinformatie-v1.jsonld', bedrijfsInformatieV1],
])

describe.skip('credential-LD full flow', () => {
describe('credential-LD full flow', () => {
let didKeyIdentifier: IIdentifier
let agent: TAgent<IResolver & IKeyManager & IDIDManager & ICredentialPlugin & ICredentialIssuer & ICredentialHandlerLDLocal>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ describe('credential-LD full flow', () => {
valid: true,
},
verificationMethod: {
'@context': ['https://w3id.org/security/suites/ed25519-2018/v1'],
'@context': ['https://www.w3.org/ns/did/v1', 'https://w3id.org/security/suites/ed25519-2018/v1'],
type: 'Ed25519VerificationKey2018',
},
verified: true,
Expand Down Expand Up @@ -257,7 +257,7 @@ describe('credential-LD full flow', () => {
valid: true,
},
verificationMethod: {
'@context': ['https://w3id.org/security/suites/ed25519-2018/v1'],
'@context': ['https://www.w3.org/ns/did/v1', 'https://w3id.org/security/suites/ed25519-2018/v1'],
type: 'Ed25519VerificationKey2018',
},
verified: true,
Expand All @@ -281,7 +281,7 @@ describe('credential-LD full flow', () => {
valid: true,
},
verificationMethod: {
'@context': ['https://w3id.org/security/suites/ed25519-2018/v1'],
"@context": "https://www.w3.org/ns/did/v1",
type: 'Ed25519VerificationKey2018',
},
verified: true,
Expand Down Expand Up @@ -418,7 +418,7 @@ describe('credential-LD full flow', () => {
valid: true,
},
verificationMethod: {
'@context': ['https://w3id.org/security/suites/ed25519-2018/v1'],
'@context': ['https://www.w3.org/ns/did/v1'],
type: 'Ed25519VerificationKey2018',
},
verified: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export default (testContext: { setup: () => Promise<boolean>; tearDown: () => Pr
issuer: didKeyIdentifier.did,
name: 'Permanent Resident Card',
proof: {
// '@context': expect.any(String),
created: expect.any(String),
proofPurpose: 'assertionMethod',
proofValue: expect.any(String),
Expand Down
2 changes: 2 additions & 0 deletions packages/vc-handler-ld-local/src/ld-credential-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { LdSuiteLoader } from './ld-suite-loader'
import { RequiredAgentMethods } from './ld-suites'
import { events, IIssueCredentialStatusOpts } from './types'



// import jsigs from '@digitalcredentials/jsonld-signatures'
//Support for Typescript added in version 9.0.0
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down
11 changes: 6 additions & 5 deletions packages/vc-handler-ld-local/src/ld-document-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class LdDocumentLoader {
if (!url || url.trim().length === 0) {
throw Error('URL needs to be provided to load a context!')
}
const origUrl = url

if (url.startsWith('#') && verifiableData.issuer !== undefined) {
url = (typeof verifiableData.issuer === 'string' ? verifiableData.issuer : verifiableData.issuer.id) + url
debug(url)
Expand All @@ -69,7 +69,7 @@ export class LdDocumentLoader {
uniresolverResolution: this.uniresolverResolution,
}).resolve(url)
// context.agent.resolveDid({didUrl: url})
let didDoc: DIDDocument | null = resolutionResult.didDocument
const didDoc: DIDDocument | null = resolutionResult.didDocument
if (!didDoc) {
throw new Error(`Could not fetch DID document with url: ${url}. Did you enable the the driver?`)
}
Expand All @@ -90,7 +90,8 @@ export class LdDocumentLoader {
delete didDoc.publicKey
}

if (url.indexOf('#') > 0 && didDoc['@context']) {
// const origUrl = url
/*if (url.indexOf('#') > 0 && didDoc && typeof didDoc === 'object' && '@context' in didDoc!) {
if (origUrl !== url) {
// Make sure we replace the result URLs with the original URLs, so framing keeps working
didDoc = JSON.parse(JSON.stringify(didDoc).replace(url, origUrl)) as DIDDocument
Expand All @@ -109,7 +110,7 @@ export class LdDocumentLoader {
// We have to provide a context
const contexts = this.ldSuiteLoader
.getAllSignatureSuites()
.filter((x) => x.getSupportedVerificationType() === component.type /* || component.type === 'Ed25519VerificationKey2018'*/)
.filter((x) => x.getSupportedVerificationType() === component.type /!* || component.type === 'Ed25519VerificationKey2018'*!/)
.filter((value, index, self) => self.indexOf(value) === index)
.map((value) => value.getContext())
const fragment = { ...component, '@context': contexts }
Expand All @@ -121,7 +122,7 @@ export class LdDocumentLoader {
}
}
}

*/
return {
contextUrl: null,
documentUrl: url,
Expand Down
1 change: 0 additions & 1 deletion packages/vc-status-list/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
UpdateStatusListFromStatusListCredentialArgs,
} from './types'

//fixme: Remove fix-esm when we move to ESM For whatever reason it kept complaining to do a require even when changing module/target in tsconfig
import {StatusList, checkStatus} from '@sphereon/vc-status-list'

export async function fetchStatusListCredential(args: { statusListCredential: string }): Promise<OriginalVerifiableCredential> {
Expand Down
Loading

0 comments on commit b858710

Please sign in to comment.