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

feat(did-comm): add support for some of the AES based content and key encryption algorithms #1180

Merged
merged 11 commits into from
Aug 1, 2023
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
4 changes: 2 additions & 2 deletions __tests__/initial.migration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ describe('database initial migration tests', () => {
encoding: 'utf-8',
})
expect(signedMessage).toEqual(
'vzDocUViJh7ooOCZ-jBHKZddEsTa4yClHwhIL9SHJwjAv3bC6TZIcUnX36ZqNBWvLbnNAQvdtzqrVf3l0pv3QQ',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JWT signing for ES256K now uses canonical signatures, with a low S value (through the use of @noble/curves)
This eliminates signature malleability, just like what happens for ethereum signatures, but it also means tests will change.

'vzDocUViJh7ooOCZ-jBHKZddEsTa4yClHwhIL9SHJwg_QIk9Fsm3jrYoIFmVy-pPjPUP5aNq6QEUfGCm_ZpKAA',
)
})

Expand Down Expand Up @@ -203,7 +203,7 @@ describe('database initial migration tests', () => {
encoding: 'utf-8',
})
expect(signedMessage).toEqual(
'JDaZFSC4eWQdau4G9a8l8ml0rhwmzCY4oEDIr-cjWK2nVCOGZP94HV3EfbpO_X3bZKPITLg8FJgVVSyRRPcObQ',
'JDaZFSC4eWQdau4G9a8l8ml0rhwmzCY4oEDIr-cjWK1Yq9x5mwCH4qI7gkWxAoIjVgsUmfcMi6OqfTH7iz8y1A',
)
})

Expand Down
4 changes: 2 additions & 2 deletions __tests__/shared/verifiableDataJWT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default (testContext: {
},
proofFormat: 'jwt',
})
const verifyResult = await agent.verifyCredential({credential: verifiableCredential})
const verifyResult = await agent.verifyCredential({ credential: verifiableCredential })

expect(verifyResult.verified).toBe(true)
expect(verifiableCredential).toHaveProperty('proof.jwt')
Expand Down Expand Up @@ -403,7 +403,7 @@ export default (testContext: {
hello: 'world',
},
credentialStatus: {
id: 'override me',
id: 'override:me',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest @transmute libraries fail if the ID value doesn't look like an IRI

type: 'ThisMethodDoesNotExist2022',
},
},
Expand Down
13 changes: 8 additions & 5 deletions __tests__/shared/verifiableDataLD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export default (testContext: {
challenge = 'TEST_CHALLENGE_STRING'
didEthrIdentifier = await agent.didManagerCreate({ kms: 'local', provider: 'did:ethr' })
didKeyIdentifier = await agent.didManagerCreate({ kms: 'local', provider: 'did:key' })
pkhIdentifier = await agent.didManagerCreate({ kms: 'local', provider: "did:pkh", options: { chainId: "1"} })
pkhIdentifier = await agent.didManagerCreate({
kms: 'local',
provider: 'did:pkh',
options: { chainId: '1' },
})
})
afterAll(testContext.tearDown)

Expand Down Expand Up @@ -295,7 +299,7 @@ export default (testContext: {
issuer: { id: pkhIdentifier.did },
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://veramo.io/contexts/discord-kudos/v1'
'https://veramo.io/contexts/discord-kudos/v1',
],
type: ['VerifiableCredential', 'DiscordKudos'],
issuanceDate: new Date().toISOString(),
Expand All @@ -315,10 +319,9 @@ export default (testContext: {

const result = await agent.verifyCredential({
credential,
fetchRemoteContexts: true
fetchRemoteContexts: true,
})
expect(result.verified).toBe(true)

})

describe('credential verification policies', () => {
Expand Down Expand Up @@ -363,7 +366,7 @@ export default (testContext: {
name: 'hello',
},
credentialStatus: {
id: 'override me',
id: 'override:me',
type: 'ThisMethodDoesNotExist2022',
},
},
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,27 @@
"docs": "pnpm docs:copy && pnpm docs:build",
"docs:copy": "ts-node ./scripts/docs-copy.ts",
"docs:build": "ts-node ./scripts/docs-build.ts && pnpm docs:pretty",
"docs:pretty": "pretty-quick"
"docs:pretty": "prettier --write docs/**/*.md"
},
"devDependencies": {
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@ethersproject/transactions": "^5.7.0",
"@ethersproject/wallet": "^5.7.0",
"@jest/globals": "^29.5.0",
"@jest/globals": "29.5.0",
"@metamask/eth-sig-util": "6.0.0",
"@microsoft/api-documenter": "7.22.16",
"@microsoft/api-extractor": "7.35.2",
"@microsoft/api-extractor-model": "7.27.2",
"@microsoft/tsdoc": "0.14.2",
"@noble/hashes": "1.3.1",
"@stablelib/ed25519": "1.0.3",
"@transmute/credentials-context": "0.7.0-unstable.81",
"@types/express": "4.17.17",
"@types/fs-extra": "11.0.1",
"@types/jest": "29.5.2",
"@types/node": "20.3.0",
"@types/uuid": "9.0.1",
"blakejs": "1.2.1",
"@types/uuid": "9.0.2",
"caip": "1.1.0",
"credential-status": "2.0.5",
"cross-env": "7.0.3",
Expand All @@ -63,15 +64,14 @@
"oas-resolver": "2.5.6",
"openapi-types": "12.1.3",
"prettier": "3.0.0",
"pretty-quick": "3.1.3",
"rimraf": "5.0.1",
"semantic-release": "21.0.5",
"ts-jest": "29.1.0",
"ts-json-schema-generator": "1.2.0",
"ts-node": "10.9.1",
"typeorm": "0.3.16",
"typescript": "5.1.3",
"uint8arrays": "4.0.3",
"uint8arrays": "4.0.4",
"uuid": "9.0.0",
"web-did-resolver": "2.0.27"
},
Expand Down
48 changes: 24 additions & 24 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
"update-veramo-latest": "pnpm add @veramo/core@latest @veramo/discovery@latest @veramo/remote-client@latest @veramo/remote-server@latest @veramo/did-provider-key@latest @veramo/did-resolver@latest @veramo/did-jwt@latest @veramo/credential-w3c@latest @veramo/did-provider-ethr@latest @veramo/did-provider-web@latest @veramo/did-comm@latest @veramo/kms-local@latest @veramo/selective-disclosure@latest @veramo/data-store@latest @veramo/key-manager@latest @veramo/message-handler@latest @veramo/did-manager@latest @veramo/url-handler@latest @veramo/credential-eip712@latest @veramo/utils@latest"
},
"dependencies": {
"@microsoft/api-extractor": "^7.35.1",
"@microsoft/api-extractor-model": "^7.27.1",
"@transmute/credentials-context": "^0.7.0-unstable.79",
"@types/blessed": "^0.1.19",
"@microsoft/api-extractor": "^7.35.2",
"@microsoft/api-extractor-model": "^7.27.2",
"@transmute/credentials-context": "^0.7.0-unstable.81",
"@types/blessed": "^0.1.22",
"@types/swagger-ui-express": "^4.1.3",
"@veramo/core": "workspace:^",
"@veramo/core-types": "workspace:^",
Expand Down Expand Up @@ -64,37 +64,37 @@
"@veramo/utils": "workspace:^",
"blessed": "^0.1.81",
"commander": "^11.0.0",
"console-table-printer": "^2.10.0",
"console-table-printer": "^2.11.1",
"cors": "^2.8.5",
"cross-fetch": "^3.1.6",
"date-fns": "^2.28.0",
"debug": "^4.3.3",
"did-resolver": "^4.0.1",
"dotenv": "^16.0.0",
"date-fns": "^2.30.0",
"debug": "^4.3.4",
"did-resolver": "^4.1.0",
"dotenv": "^16.1.4",
"ethr-did-resolver": "^8.0.0",
"express": "^4.18.2",
"express-handlebars": "^7.0.0",
"express-handlebars": "^7.0.7",
"fuzzy": "^0.1.3",
"handlebars": "^4.7.6",
"inquirer": "^9.1.4",
"handlebars": "^4.7.7",
"inquirer": "^9.2.7",
"inquirer-autocomplete-prompt": "^3.0.0",
"json-schema": "^0.4.0",
"json5": "^2.2.0",
"jsonpointer": "^5.0.0",
"oas-resolver": "^2.5.3",
"openapi-types": "^12.0.2",
"json5": "^2.2.3",
"jsonpointer": "^5.0.1",
"oas-resolver": "^2.5.6",
"openapi-types": "^12.1.3",
"passport": "^0.6.0",
"passport-http-bearer": "^1.0.1",
"pg": "^8.7.1",
"pg": "^8.11.0",
"qrcode-terminal": "^0.12.0",
"sqlite3": "^5.0.8",
"swagger-ui-express": "^4.6.0",
"sqlite3": "^5.1.6",
"swagger-ui-express": "^4.6.3",
"ts-json-schema-generator": "^1.2.0",
"typeorm": "^0.3.10",
"url-parse": "^1.5.4",
"web-did-resolver": "^2.0.21",
"ws": "^8.11.0",
"yaml": "^2.1.3"
"url-parse": "^1.5.10",
"web-did-resolver": "^2.0.24",
"ws": "^8.13.0",
"yaml": "^2.3.1"
},
"devDependencies": {
"@types/debug": "4.1.8",
Expand All @@ -105,7 +105,7 @@
"@types/passport-http-bearer": "1.0.37",
"@types/qrcode-terminal": "0.12.0",
"@types/url-parse": "1.4.8",
"@types/ws": "8.5.4",
"@types/ws": "8.5.5",
"typescript": "5.1.3"
},
"files": [
Expand Down
4 changes: 2 additions & 2 deletions packages/core-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"dependencies": {
"credential-status": "^2.0.5",
"debug": "^4.3.3",
"did-jwt-vc": "^3.1.0",
"did-resolver": "^4.0.1"
"did-jwt-vc": "^3.2.3",
"did-resolver": "^4.1.0"
},
"devDependencies": {
"@types/debug": "4.1.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@veramo/core-types": "workspace:^",
"debug": "^4.3.4",
"events": "^3.2.0",
"z-schema": "^6.0.0"
"z-schema": "^6.0.1"
},
"devDependencies": {
"@types/debug": "4.1.8",
Expand Down
9 changes: 4 additions & 5 deletions packages/credential-ld/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@
"@digitalcredentials/jsonld": "^5.2.1",
"@digitalcredentials/jsonld-signatures": "^9.3.1",
"@digitalcredentials/vc": "^5.0.0",
"@transmute/credentials-context": "^0.7.0-unstable.79",
"@transmute/ed25519-signature-2018": "^0.7.0-unstable.79",
"@transmute/json-web-signature": "^0.7.0-unstable.79",
"@transmute/credentials-context": "^0.7.0-unstable.81",
"@transmute/ed25519-signature-2018": "^0.7.0-unstable.81",
"@transmute/json-web-signature": "^0.7.0-unstable.81",
"@veramo-community/lds-ecdsa-secp256k1-recovery2020": "uport-project/EcdsaSecp256k1RecoverySignature2020",
"@veramo/core-types": "workspace:^",
"@veramo/utils": "workspace:^",
"cross-fetch": "^3.1.6",
"debug": "^4.3.3",
"did-resolver": "^4.0.1",
"uint8arrays": "^4.0.3"
"did-resolver": "^4.1.0"
},
"resolutions": {
"@types/react": "18.0.26",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { RequiredAgentMethods, VeramoLdSignature } from '../ld-suites.js'
import { CredentialPayload, DIDDocument, IAgentContext, IKey, TKeyType } from '@veramo/core-types'
import ldsEcdsa from '@veramo-community/lds-ecdsa-secp256k1-recovery2020'
import * as u8a from 'uint8arrays'
import { asArray, encodeJoseBlob } from '@veramo/utils'
import { asArray, bytesToBase64, concat, encodeJoseBlob, stringToUtf8Bytes } from '@veramo/utils'

const { EcdsaSecp256k1RecoveryMethod2020, EcdsaSecp256k1RecoverySignature2020 } = ldsEcdsa

Expand Down Expand Up @@ -36,8 +35,8 @@ export class VeramoEcdsaSecp256k1RecoverySignature2020 extends VeramoLdSignature
crit: ['b64'],
}
const headerString = encodeJoseBlob(header)
const messageBuffer = u8a.concat([u8a.fromString(`${headerString}.`, 'utf-8'), args.data])
const messageString = u8a.toString(messageBuffer, 'base64')
const messageBuffer = concat([stringToUtf8Bytes(`${headerString}.`), args.data])
const messageString = bytesToBase64(messageBuffer)
const signature = await context.agent.keyManagerSign({
keyRef: key.kid,
algorithm: 'ES256K-R',
Expand All @@ -59,7 +58,7 @@ export class VeramoEcdsaSecp256k1RecoverySignature2020 extends VeramoLdSignature
}),
})

suite.ensureSuiteContext = ({ document }: { document: any, addSuiteContext: boolean }) => {
suite.ensureSuiteContext = ({ document }: { document: any; addSuiteContext: boolean }) => {
document['@context'] = [...asArray(document['@context'] || []), this.getContext()]
}

Expand All @@ -70,12 +69,14 @@ export class VeramoEcdsaSecp256k1RecoverySignature2020 extends VeramoLdSignature
return new EcdsaSecp256k1RecoverySignature2020()
}

preSigningCredModification(credential: CredentialPayload): void {
}
preSigningCredModification(credential: CredentialPayload): void {}

async preDidResolutionModification(didUrl: string, didDoc: DIDDocument): Promise<DIDDocument> {
// did:ethr
const idx = didDoc['@context']?.indexOf('https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld') || -1
// did:ethr
const idx =
didDoc['@context']?.indexOf(
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
) || -1
if (Array.isArray(didDoc['@context']) && idx !== -1) {
didDoc['@context'][idx] = this.getContext()
}
Expand All @@ -85,7 +86,7 @@ export class VeramoEcdsaSecp256k1RecoverySignature2020 extends VeramoLdSignature
didDoc.verificationMethod?.forEach((x) => {
if (x.blockchainAccountId) {
if (x.blockchainAccountId.lastIndexOf('@eip155:') !== -1) {
const [ address, chain ] = x.blockchainAccountId.split("@eip155:")
const [address, chain] = x.blockchainAccountId.split('@eip155:')
x.blockchainAccountId = `eip155:${chain}:${address}`
}
}
Expand Down
9 changes: 4 additions & 5 deletions packages/credential-ld/src/suites/Ed25519Signature2018.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { encodeJoseBlob } from '@veramo/utils'
import { bytesToBase64, concat, encodeJoseBlob, hexToBytes, stringToUtf8Bytes } from '@veramo/utils'
import { RequiredAgentMethods, VeramoLdSignature } from '../ld-suites.js'
import { CredentialPayload, DIDDocument, IAgentContext, IKey, TKeyType } from '@veramo/core-types'
import * as u8a from 'uint8arrays'
import { Ed25519Signature2018, Ed25519VerificationKey2018 } from '@transmute/ed25519-signature-2018'

/**
Expand Down Expand Up @@ -38,8 +37,8 @@ export class VeramoEd25519Signature2018 extends VeramoLdSignature {
crit: ['b64'],
}
const headerString = encodeJoseBlob(header)
const messageBuffer = u8a.concat([u8a.fromString(`${headerString}.`, 'utf-8'), args.data])
const messageString = u8a.toString(messageBuffer, 'base64')
const messageBuffer = concat([stringToUtf8Bytes(`${headerString}.`), args.data])
const messageString = bytesToBase64(messageBuffer)
const signature = await context.agent.keyManagerSign({
keyRef: key.kid,
algorithm: 'EdDSA',
Expand All @@ -53,7 +52,7 @@ export class VeramoEd25519Signature2018 extends VeramoLdSignature {
const verificationKey = new Ed25519VerificationKey2018({
id,
controller,
publicKey: u8a.fromString(key.publicKeyHex, 'base16'),
publicKey: hexToBytes(key.publicKeyHex),
signer: () => signer,
type: this.getSupportedVerificationType(),
})
Expand Down
12 changes: 9 additions & 3 deletions packages/credential-ld/src/suites/Ed25519Signature2020.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ import {
IResolver,
TKeyType,
} from '@veramo/core-types'
import * as u8a from 'uint8arrays'
import { Ed25519Signature2020 } from '@digitalcredentials/ed25519-signature-2020'
import { Ed25519VerificationKey2020 } from '@digitalcredentials/ed25519-verification-key-2020'
import { asArray, base64ToBytes, bytesToMultibase, extractPublicKeyHex, hexToBytes } from '@veramo/utils'
import {
asArray,
base64ToBytes,
bytesToBase64,
bytesToMultibase,
extractPublicKeyHex,
hexToBytes,
} from '@veramo/utils'
import { VerificationMethod } from 'did-resolver'

import Debug from 'debug'
Expand Down Expand Up @@ -46,7 +52,7 @@ export class VeramoEd25519Signature2020 extends VeramoLdSignature {
const signer = {
// returns signatureBytes
sign: async (args: { data: Uint8Array }): Promise<Uint8Array> => {
const messageString = u8a.toString(args.data, 'base64')
const messageString = bytesToBase64(args.data)
const signature = await context.agent.keyManagerSign({
keyRef: key.kid,
data: messageString,
Expand Down
Loading