Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(credential-ld): fix EcdsaSecp256k1RecoverySignature2020 suite context #909

Merged
merged 1 commit into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"version": "0.2.0",
"configurations": [

{
"type": "node",
"request": "launch",
Expand Down Expand Up @@ -134,9 +135,9 @@
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"--runInBand",
"--coverage=false",
"--config=jest.json"
"--config=jest.config.json"
],
"runtimeArgs": ["--preserve-symlinks"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
Expand All @@ -158,9 +159,10 @@
"${relativeFile}",
"--detectOpenHandles",
"--runInBand",
"--coverage=false",
"--config=jest.json"
"--config=jest.config.json"
],
"enableContentValidation": false,
"runtimeArgs": ["--preserve-symlinks"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"windows": {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/shared/verifiableDataLD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default (testContext: {
expect(verifiableCredential['@context']).toEqual([
'https://www.w3.org/2018/credentials/v1',
'https://veramo.io/contexts/profile/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
'https://w3id.org/security/suites/secp256k1recovery-2020/v2',
])
expect(verifiableCredential['type']).toEqual(['VerifiableCredential', 'Profile'])

Expand Down
4 changes: 2 additions & 2 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"moduleFileExtensions": ["ts", "tsx", "js", "jsx"],
"collectCoverage": true,
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "jsonld"],
"collectCoverage": false,
"collectCoverageFrom": [
"packages/**/src/**/*.ts",
"!**/examples/**",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"test:integration-prepare": "ts-node --project packages/tsconfig.settings.json ./scripts/prepare-integration-tests.ts",
"test:integration-pretty": "prettier --write __tests__/shared/documentationExamples.ts",
"test:integration": "yarn test:integration-build && yarn test:ci",
"test:ci": "jest --config=jest.config.json",
"test": "jest --config=jest.config.json --coverage=false",
"test:ci": "jest --config=jest.config.json --runInBand --coverage=true",
"test": "jest --config=jest.config.json",
"test:watch": "yarn test --watch --verbose",
"test:browser": "bash scripts/prepare-react-test.sh && cd ./__browser_tests__/react-sample && yarn install && yarn test:browser-integration",
"veramo": "./packages/cli/bin/veramo.js",
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions packages/credential-ld/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"@transmute/credentials-context": "^0.7.0-unstable.34",
"@transmute/ed25519-signature-2018": "^0.7.0-unstable.34",
"@transmute/lds-ecdsa-secp256k1-recovery2020": "^0.0.7",
"@transmute/lds-ecdsa-secp256k1-recovery2020": "decentralized-identity/EcdsaSecp256k1RecoverySignature2020",
"@veramo/core": "^3.1.0",
"@veramo/did-resolver": "^3.1.0",
"@veramo/utils": "^3.1.0",
Expand All @@ -25,7 +25,7 @@
"jsonld": "^5.2.0",
"jsonld-signatures": "^9.3.1",
"uint8arrays": "^3.0.0",
"vc-js": "^0.6.4"
"@digitalbazaar/vc": "^2.1.0"
},
"devDependencies": {
"@types/debug": "4.1.7",
Expand Down
109 changes: 106 additions & 3 deletions packages/credential-ld/src/__tests__/issue-verify-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ import { KeyManager, MemoryKeyStore, MemoryPrivateKeyStore } from '../../../key-
import { KeyManagementSystem } from '../../../kms-local/src'
import { getDidKeyResolver, KeyDIDProvider } from '../../../did-provider-key/src'
import { DIDResolverPlugin } from '../../../did-resolver/src'
import { EthrDIDProvider } from "../../../did-provider-ethr/src";
import { ContextDoc } from '../types'
import { CredentialIssuerLD } from '../action-handler'
import { LdDefaultContexts } from '../ld-default-contexts'
import { VeramoEd25519Signature2018 } from '../suites/Ed25519Signature2018'
import { Resolver } from 'did-resolver'
import { getResolver as ethrDidResolver } from 'ethr-did-resolver'
import { VeramoEcdsaSecp256k1RecoverySignature2020 } from "../suites/EcdsaSecp256k1RecoverySignature2020";

jest.setTimeout(300000)

const customContext: Record<string, ContextDoc> = {
'custom:example.context': {
Expand All @@ -27,8 +32,11 @@ const customContext: Record<string, ContextDoc> = {
},
}

const infuraProjectId = '3586660d179141e3801c3895de1c2eba'

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

beforeAll(async () => {
Expand All @@ -43,24 +51,32 @@ describe('credential-LD full flow', () => {
new DIDManager({
providers: {
'did:key': new KeyDIDProvider({ defaultKms: 'local' }),
'did:ethr:goerli': new EthrDIDProvider({
defaultKms: 'local',
network: 'goerli',
}),
},
store: new MemoryDIDStore(),
defaultProvider: 'did:key',
}),
new DIDResolverPlugin({
resolver: new Resolver({ ...getDidKeyResolver() }),
resolver: new Resolver({
...getDidKeyResolver(),
...ethrDidResolver({ infuraProjectId, }),
}),
}),
new CredentialIssuer(),
new CredentialIssuerLD({
contextMaps: [LdDefaultContexts, customContext],
suites: [new VeramoEd25519Signature2018()],
suites: [new VeramoEd25519Signature2018(), new VeramoEcdsaSecp256k1RecoverySignature2020()],
}),
],
})
didKeyIdentifier = await agent.didManagerCreate()
didEthrIdentifier = await agent.didManagerCreate({ provider: "did:ethr:goerli" })
})

it('works with Ed25519Signature2018', async () => {
it('works with Ed25519Signature2018 credential', async () => {
const credential: CredentialPayload = {
issuer: didKeyIdentifier.did,
'@context': ['custom:example.context'],
Expand All @@ -81,4 +97,91 @@ describe('credential-LD full flow', () => {

expect(verified).toBe(true)
})

it.only('works with EcdsaSecp256k1RecoveryMethod2020 credentials', async () => {
const credential: CredentialPayload = {
issuer: didEthrIdentifier.did,
'@context': ['custom:example.context'],
credentialSubject: {
nothing: 'else matters',
},
}
const verifiableCredential = await agent.createVerifiableCredential({
credential,
proofFormat: 'lds',
})

expect(verifiableCredential).toBeDefined()

const verified = await agent.verifyCredential({
credential: verifiableCredential,
})

expect(verified).toBe(true)
})

it('works with Ed25519Signature2018 credential and presentation', async () => {
const credential: CredentialPayload = {
issuer: didKeyIdentifier.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: didKeyIdentifier.did
},
proofFormat: 'lds',
})

expect(verifiablePresentation).toBeDefined()

const verified = await agent.verifyPresentation({
presentation: verifiablePresentation,
challenge: "VERAMO",
})

expect(verified).toBe(true)
})

it('works with EcdsaSecp256k1RecoveryMethod2020 credential and presentation', async () => {
const credential: CredentialPayload = {
issuer: { id: didEthrIdentifier.did },
'@context': ['https://www.w3.org/2018/credentials/v1', 'https://veramo.io/contexts/profile/v1'],
type: ['VerifiableCredential', 'Profile'],
issuanceDate: new Date().toISOString(),
credentialSubject: {
id: didKeyIdentifier.did,
name: 'Martin, the great',
},
}
const verifiableCredential1 = await agent.createVerifiableCredential({
credential,
proofFormat: 'lds',
})

const verifiablePresentation = await agent.createVerifiablePresentation({
presentation: {
verifiableCredential: [verifiableCredential1],
holder: didEthrIdentifier.did
},
proofFormat: 'lds',
})

expect(verifiablePresentation).toBeDefined()

const verified = await agent.verifyPresentation({
presentation: verifiablePresentation,
challenge: "VERAMO",
})

expect(verified).toBe(true)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"@context": {
"@version": 1.1,
"id": "@id",
"type": "@type",
"esrs2020": "https://identity.foundation/EcdsaSecp256k1RecoverySignature2020#",
"EcdsaSecp256k1RecoverySignature2020": "esrs2020:EcdsaSecp256k1RecoverySignature2020",
"EcdsaSecp256k1RecoveryMethod2020": "esrs2020:EcdsaSecp256k1RecoveryMethod2020",
"publicKeyJwk": {
"@id": "esrs2020:publicKeyJwk",
"@type": "@json"
},
"privateKeyJwk": {
"@id": "esrs2020:privateKeyJwk",
"@type": "@json"
},
"publicKeyHex": "esrs2020:publicKeyHex",
"privateKeyHex": "esrs2020:privateKeyHex",
"ethereumAddress": "esrs2020:ethereumAddress"
}
}
Loading