diff --git a/package.json b/package.json index 9b1ea8e..f27581a 100644 --- a/package.json +++ b/package.json @@ -10,20 +10,15 @@ "test": "NODE_OPTIONS=--experimental-vm-modules npx mocha --timeout 10000 -r dotenv/config dotenv_config_path=src/test-fixtures/.env.testing src/app.test.js " }, "dependencies": { - "@digitalbazaar/did-io": "^2.0.0", - "@digitalbazaar/did-method-key": "^5.1.0", - "@digitalbazaar/ed25519-signature-2020": "^5.2.0", + "@digitalbazaar/ed25519-signature-2020": "^5.4.0", "@digitalbazaar/ed25519-verification-key-2020": "^4.1.0", - "@digitalbazaar/vc": "^6.0.1", + "@digitalbazaar/vc": "^7.0.0", + "@digitalcredentials/security-document-loader": "^6.0.0", "axios": "^1.4.0", "cors": "^2.8.5", - "credentials-context": "^2.0.0", "debug": "~2.6.9", - "did-context": "^3.1.1", "dotenv": "^16.0.3", - "ed25519-signature-2020-context": "^1.1.0", "express": "~4.16.1", - "jsonld-document-loader": "^2.0.0", "morgan": "~1.9.1", "winston": "^3.9.0" }, @@ -38,7 +33,7 @@ "dcc" ], "engines": { - "node": ">=16.0" + "node": ">=20.0" }, "author": { "name": "Digital Credentials Consortium", diff --git a/src/app.js b/src/app.js index 40389c2..491ad05 100644 --- a/src/app.js +++ b/src/app.js @@ -10,7 +10,6 @@ import verifyAuthHeader from './verifyAuthHeader.js' import { getConfig } from './config.js' import testVC from './testVC.js'; import CoordinatorException from './CoordinatorException.js'; -import { getSignedDIDAuth, verifyDIDAuth } from './didAuth.js'; async function callService(endpoint, body) { diff --git a/src/didAuth.js b/src/didAuth.js index 2ae17eb..761107f 100644 --- a/src/didAuth.js +++ b/src/didAuth.js @@ -1,11 +1,12 @@ -import {signPresentation, createPresentation, verify} from '@digitalbazaar/vc'; +import {signPresentation, createPresentation} from '@digitalbazaar/vc'; import {Ed25519VerificationKey2020} from '@digitalbazaar/ed25519-verification-key-2020'; import {Ed25519Signature2020} from '@digitalbazaar/ed25519-signature-2020'; -import { securityLoader } from './securityLoader.js'; + +import { securityLoader } from '@digitalcredentials/security-document-loader' const documentLoader = securityLoader().build() -const signingKeyPairForTesting = await Ed25519VerificationKey2020.generate( +const key = await Ed25519VerificationKey2020.generate( { seed: new Uint8Array ([ 217, 87, 166, 30, 75, 106, 132, 55, @@ -16,18 +17,12 @@ const signingKeyPairForTesting = await Ed25519VerificationKey2020.generate( controller: "did:key:z6MkvL5yVCgPhYvQwSoSRQou6k6ZGfD5mNM57HKxufEXwfnP" } ) -const suiteForSigning = new Ed25519Signature2020({key: signingKeyPairForTesting}); -const suiteForVerification = new Ed25519Signature2020(); +const suite = new Ed25519Signature2020({key}); export const getSignedDIDAuth = async (holder = 'did:ex:12345', challenge) => { const presentation = createPresentation({holder}); return await signPresentation({ - presentation, suite: suiteForSigning, challenge, documentLoader + presentation, suite, challenge, documentLoader }); } -export const verifyDIDAuth = async (presentation, challenge) => { - const result = await verify({presentation, challenge, suite: suiteForVerification, documentLoader}); - return result.verified -} - diff --git a/src/generate.js b/src/generate.js deleted file mode 100644 index 5eed1cd..0000000 --- a/src/generate.js +++ /dev/null @@ -1,24 +0,0 @@ -import { generateSecretKeySeed, decodeSecretKeySeed } from '@digitalcredentials/bnid'; -import { driver } from '@digitalcredentials/did-method-key'; - -export default async function generateSeed() { - const seed = await generateSecretKeySeed(); - const decodedSeed = await decodeSeed(seed) - const didKeyDriver = driver(); - const { didDocument } = await didKeyDriver.generate({ seed: decodedSeed }); - const did = didDocument.id - return {seed, did, didDocument} -} - -const decodeSeed = async (secretKeySeed) => { - let secretKeySeedBytes // Uint8Array; - if (secretKeySeed.startsWith('z')) { - // This is a multibase-decoded key seed, like those generated by @digitalcredentials/did-cli - secretKeySeedBytes = decodeSecretKeySeed({ secretKeySeed }); - } else if (secretKeySeed.length >= 32) { - secretKeySeedBytes = (new TextEncoder()).encode(secretKeySeed).slice(0, 32); - } else { - throw TypeError('"secretKeySeed" must be at least 32 bytes, preferably multibase-encoded.'); - } - return secretKeySeedBytes; -} \ No newline at end of file diff --git a/src/securityLoader.js b/src/securityLoader.js deleted file mode 100644 index 8dca752..0000000 --- a/src/securityLoader.js +++ /dev/null @@ -1,35 +0,0 @@ -import * as didKey from '@digitalbazaar/did-method-key'; -import didContext from 'did-context'; -import ed25519 from 'ed25519-signature-2020-context'; -import credentialsContext from 'credentials-context'; -import { JsonLdDocumentLoader } from 'jsonld-document-loader'; -import { Ed25519VerificationKey2020 } from '@digitalbazaar/ed25519-verification-key-2020' -import { CachedResolver } from '@digitalbazaar/did-io'; - -const didKeyDriver = didKey.driver(); -didKeyDriver.use({ - multibaseMultikeyHeader: 'z6Mk', - fromMultibase: Ed25519VerificationKey2020.from -}); - -const resolver = new CachedResolver(); -resolver.use(didKeyDriver); - -export function securityLoader() { - - const staticLoader = new JsonLdDocumentLoader(); - - staticLoader.addStatic(ed25519.constants.CONTEXT_URL, - ed25519.contexts.get(ed25519.constants.CONTEXT_URL)); - - staticLoader.addStatic(didContext.constants.DID_CONTEXT_URL, - didContext.contexts.get(didContext.constants.DID_CONTEXT_URL)); - - staticLoader.addStatic(credentialsContext.constants.CREDENTIALS_CONTEXT_V1_URL, - credentialsContext.contexts.get(credentialsContext.constants.CREDENTIALS_CONTEXT_V1_URL)); - - staticLoader.setDidResolver(resolver); - - return staticLoader - -} diff --git a/src/test-fixtures/nocks/directTest.js b/src/test-fixtures/nocks/directTest.js index 5b366e3..ca7a280 100644 --- a/src/test-fixtures/nocks/directTest.js +++ b/src/test-fixtures/nocks/directTest.js @@ -95,7 +95,7 @@ const signedVcWithId = { const signedVp = { "@context": [ - "https://www.w3.org/2018/credentials/v1", + "https://www.w3.org/ns/credentials/v2", "https://w3id.org/security/suites/ed25519-2020/v1" ], "type": [ diff --git a/src/test-fixtures/nocks/vprTest.js b/src/test-fixtures/nocks/vprTest.js index 39969ae..88aa036 100644 --- a/src/test-fixtures/nocks/vprTest.js +++ b/src/test-fixtures/nocks/vprTest.js @@ -50,7 +50,7 @@ nock('http://localhost:4004', {"encodedQueryParams":true}) // that we generate as part of the test nock('http://localhost:4004', {"encodedQueryParams":true}) - .post('/exchange/34913bac-b4d7-4c98-a598-c259e8d2925e/199ea83d-3b8d-44f0-8509-d10ce02f5c7c', {"@context":["https://www.w3.org/2018/credentials/v1","https://w3id.org/security/suites/ed25519-2020/v1"],"type":["VerifiablePresentation"],"holder":/.+/i,"proof":{"type":"Ed25519Signature2020","created":/.+/i,"verificationMethod":"did:key:z6MkvL5yVCgPhYvQwSoSRQou6k6ZGfD5mNM57HKxufEXwfnP#z6MkvL5yVCgPhYvQwSoSRQou6k6ZGfD5mNM57HKxufEXwfnP","proofPurpose":"authentication","challenge":"199ea83d-3b8d-44f0-8509-d10ce02f5c7c","proofValue":/.+/i}}) + .post('/exchange/34913bac-b4d7-4c98-a598-c259e8d2925e/199ea83d-3b8d-44f0-8509-d10ce02f5c7c', {"@context":["https://www.w3.org/ns/credentials/v2","https://w3id.org/security/suites/ed25519-2020/v1"],"type":["VerifiablePresentation"],"holder":/.+/i,"proof":{"type":"Ed25519Signature2020","created":/.+/i,"verificationMethod":"did:key:z6MkvL5yVCgPhYvQwSoSRQou6k6ZGfD5mNM57HKxufEXwfnP#z6MkvL5yVCgPhYvQwSoSRQou6k6ZGfD5mNM57HKxufEXwfnP","proofPurpose":"authentication","challenge":"199ea83d-3b8d-44f0-8509-d10ce02f5c7c","proofValue":/.+/i}}) .reply(200, {"vc":{"@context":["https://www.w3.org/2018/credentials/v1","https://purl.imsglobal.org/spec/ob/v3p0/context.json","https://w3id.org/vc/status-list/2021/v1"],"id":"urn:uuid:951b475e-b795-43bc-ba8f-a2d01efd2eb1","type":["VerifiableCredential","OpenBadgeCredential"],"issuer":{"id":"did:key:z6MkhVTX9BF3NGYX6cc7jWpbNnR7cAjH8LUffabZP8Qu4ysC","type":"Profile","name":"University of Wonderful","description":"The most wonderful university","url":"https://wonderful.edu/","image":{"id":"https://user-images.githubusercontent.com/947005/133544904-29d6139d-2e7b-4fe2-b6e9-7d1022bb6a45.png","type":"Image"}},"issuanceDate":"2020-01-01T00:00:00Z","name":"A Simply Wonderful Course","credentialSubject":{"type":"AchievementSubject","achievement":{"id":"http://wonderful.wonderful","type":"Achievement","criteria":{"narrative":"Completion of the Wonderful Course - well done you!"},"description":"Wonderful.","name":"Introduction to Wonderfullness"}}},"retrievalId":"someId","tenantName":"UN_PROTECTED_TEST","exchangeHost":"http://localhost:4005","transactionId":"199ea83d-3b8d-44f0-8509-d10ce02f5c7c","exchangeId":"34913bac-b4d7-4c98-a598-c259e8d2925e"}, [ 'X-Powered-By', 'Express',