-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(credential-ld): fix Ed25519Signature2020 verification (#1166)
* fix(utils): allow x25519-pub multicodec when converting publicKeyMultibase to bytes, rename util function * fix(credential-ld): pre-process DID doc for Ed25519Signature2020 * fix(credential-ld): return correct signature bytes for Ed25519-2020 suite * feat(credential-ld): add schema.org and X25519_2020 context * fix(remote-server): improve LD @context compliance in web-did-doc-router * fix(credential-ld): fix document loader for Ed25519-2020 suite --------- Co-authored-by: nickreynolds <nicholas.s.reynolds@gmail.com>
- Loading branch information
1 parent
ad79a22
commit c965fd5
Showing
51 changed files
with
19,554 additions
and
5,990 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,6 @@ | |
"Keypair", | ||
"arrayify", | ||
"ethersproject" | ||
] | ||
], | ||
"jest.autoRun": "off" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
packages/credential-ld/src/__tests__/issue-verify-ed25519-2020.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import { | ||
createAgent, | ||
CredentialPayload, | ||
ICredentialPlugin, | ||
IDIDManager, | ||
IIdentifier, | ||
IKeyManager, | ||
IResolver, | ||
TAgent, | ||
} from '../../../core/src' | ||
import { CredentialPlugin } from '../../../credential-w3c/src' | ||
import { DIDManager, MemoryDIDStore } from '../../../did-manager/src' | ||
import { KeyManager, MemoryKeyStore, MemoryPrivateKeyStore } from '../../../key-manager/src' | ||
import { KeyManagementSystem } from '../../../kms-local/src' | ||
import { DIDResolverPlugin } from '../../../did-resolver/src' | ||
import { ContextDoc } from '../types' | ||
import { CredentialIssuerLD } from '../action-handler' | ||
import { LdDefaultContexts } from '../ld-default-contexts' | ||
import { VeramoEd25519Signature2020 } from '../suites/Ed25519Signature2020' | ||
import { Resolver } from 'did-resolver' | ||
import { FakeDidProvider, FakeDidResolver } from '../../../test-utils/src/fake-did' | ||
import { jest } from '@jest/globals' | ||
|
||
jest.setTimeout(300000) | ||
|
||
const customContext: Record<string, ContextDoc> = { | ||
'custom:example.context': { | ||
'@context': { | ||
nothing: 'custom:example.context#blank', | ||
}, | ||
}, | ||
} | ||
|
||
describe('credential-LD full flow', () => { | ||
let didFakeIdentifier: IIdentifier | ||
let agent: TAgent<IResolver & IKeyManager & IDIDManager & ICredentialPlugin> | ||
|
||
beforeAll(async () => { | ||
agent = createAgent({ | ||
plugins: [ | ||
new KeyManager({ | ||
store: new MemoryKeyStore(), | ||
kms: { | ||
local: new KeyManagementSystem(new MemoryPrivateKeyStore()), | ||
}, | ||
}), | ||
new DIDManager({ | ||
providers: { | ||
'did:fake': new FakeDidProvider(), | ||
}, | ||
store: new MemoryDIDStore(), | ||
defaultProvider: 'did:fake', | ||
}), | ||
new DIDResolverPlugin({ | ||
resolver: new Resolver({ | ||
...new FakeDidResolver(() => agent, true).getDidFakeResolver(), | ||
}), | ||
}), | ||
new CredentialPlugin(), | ||
new CredentialIssuerLD({ | ||
contextMaps: [LdDefaultContexts, customContext], | ||
suites: [new VeramoEd25519Signature2020()], | ||
}), | ||
], | ||
}) | ||
didFakeIdentifier = await agent.didManagerImport({ | ||
did: 'did:fake:z6MkgbqNU4uF9NKSz5BqJQ4XKVHuQZYcUZP8pXGsJC8nTHwo', | ||
keys: [ | ||
{ | ||
type: 'Ed25519', | ||
kid: 'didcomm-senderKey-1', | ||
publicKeyHex: '1fe9b397c196ab33549041b29cf93be29b9f2bdd27322f05844112fad97ff92a', | ||
privateKeyHex: | ||
'b57103882f7c66512dc96777cbafbeb2d48eca1e7a867f5a17a84e9a6740f7dc1fe9b397c196ab33549041b29cf93be29b9f2bdd27322f05844112fad97ff92a', | ||
kms: 'local', | ||
}, | ||
], | ||
services: [ | ||
{ | ||
id: 'msg1', | ||
type: 'DIDCommMessaging', | ||
serviceEndpoint: 'http://localhost:3002/messaging', | ||
}, | ||
], | ||
provider: 'did:fake', | ||
alias: 'sender', | ||
}) | ||
}) | ||
|
||
it('works with Ed25519Signature2020 credential', async () => { | ||
const credential: CredentialPayload = { | ||
issuer: didFakeIdentifier.did, | ||
'@context': ['custom:example.context'], | ||
credentialSubject: { | ||
nothing: 'else matters', | ||
}, | ||
} | ||
const verifiableCredential = await agent.createVerifiableCredential({ | ||
credential, | ||
proofFormat: 'lds', | ||
}) | ||
|
||
expect(verifiableCredential).toBeDefined() | ||
|
||
const result = await agent.verifyCredential({ | ||
credential: verifiableCredential, | ||
}) | ||
|
||
expect(result.verified).toBe(true) | ||
}) | ||
|
||
it('works with Ed25519Signature2020 credential and presentation', async () => { | ||
const credential: CredentialPayload = { | ||
issuer: didFakeIdentifier.did, | ||
'@context': ['custom:example.context'], | ||
credentialSubject: { | ||
nothing: 'else matters', | ||
}, | ||
} | ||
const verifiableCredential1 = await agent.createVerifiableCredential({ | ||
credential, | ||
proofFormat: 'lds', | ||
}) | ||
|
||
const verifiablePresentation = await agent.createVerifiablePresentation({ | ||
presentation: { | ||
verifiableCredential: [verifiableCredential1], | ||
holder: didFakeIdentifier.did, | ||
}, | ||
challenge: 'VERAMO', | ||
proofFormat: 'lds', | ||
}) | ||
|
||
expect(verifiablePresentation).toBeDefined() | ||
|
||
const result = await agent.verifyPresentation({ | ||
presentation: verifiablePresentation, | ||
challenge: 'VERAMO', | ||
}) | ||
|
||
expect(result.verified).toBe(true) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.