From 6cbdab93422be8f2b66f5c949b0137716e5617ad Mon Sep 17 00:00:00 2001 From: "D. Stuart Freeman" Date: Fri, 3 Nov 2023 15:45:30 -0400 Subject: [PATCH] WIP did:web support --- .eslintrc.cjs | 2 +- package-lock.json | 36 +++++------------------------------- package.json | 3 +-- src/config.js | 21 ++++++++++++++++----- src/issue.js | 24 +++++++++++++++++------- 5 files changed, 40 insertions(+), 46 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 428cc4f..d214498 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -11,7 +11,7 @@ module.exports = { mocha: true }, parserOptions: { - ecmaVersion: 12, + ecmaVersion: 2022, sourceType: "module" } } diff --git a/package-lock.json b/package-lock.json index ead95e8..ad679a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,10 +16,9 @@ "@digitalcredentials/security-document-loader": "^3.1.0", "@digitalcredentials/status-list-manager-git": "github:digitalcredentials/status-list-manager-git", "@digitalcredentials/vc": "^5.0.0", + "@interop/did-web-resolver": "^3.0.1", "base32-encode": "^2.0.0", - "cookie-parser": "~1.4.4", "cors": "^2.8.5", - "debug": "~2.6.9", "dotenv": "^16.0.3", "express": "~4.16.1", "morgan": "~1.9.1", @@ -4025,7 +4024,8 @@ }, "node_modules/@interop/did-web-resolver": { "version": "3.0.1", - "license": "MIT", + "resolved": "https://registry.npmjs.org/@interop/did-web-resolver/-/did-web-resolver-3.0.1.tgz", + "integrity": "sha512-OuwYvbFaRf3qFoa5aL6rx123bXxndLawmbY770k6zIYGPjEdbq2nEkrL7Vl0WovdSeU1lcwL04CgBqOpjoZPGQ==", "dependencies": { "@digitalcredentials/bnid": "^2.1.1", "@digitalcredentials/did-io": "^1.0.2", @@ -6920,24 +6920,6 @@ "license": "MIT", "peer": true }, - "node_modules/cookie": { - "version": "0.4.1", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/cookie-parser": { - "version": "1.4.6", - "license": "MIT", - "dependencies": { - "cookie": "0.4.1", - "cookie-signature": "1.0.6" - }, - "engines": { - "node": ">= 0.8.0" - } - }, "node_modules/cookie-signature": { "version": "1.0.6", "license": "MIT" @@ -18884,6 +18866,8 @@ }, "@interop/did-web-resolver": { "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@interop/did-web-resolver/-/did-web-resolver-3.0.1.tgz", + "integrity": "sha512-OuwYvbFaRf3qFoa5aL6rx123bXxndLawmbY770k6zIYGPjEdbq2nEkrL7Vl0WovdSeU1lcwL04CgBqOpjoZPGQ==", "requires": { "@digitalcredentials/bnid": "^2.1.1", "@digitalcredentials/did-io": "^1.0.2", @@ -20863,16 +20847,6 @@ "version": "1.9.0", "peer": true }, - "cookie": { - "version": "0.4.1" - }, - "cookie-parser": { - "version": "1.4.6", - "requires": { - "cookie": "0.4.1", - "cookie-signature": "1.0.6" - } - }, "cookie-signature": { "version": "1.0.6" }, diff --git a/package.json b/package.json index f30f795..ff35598 100644 --- a/package.json +++ b/package.json @@ -18,10 +18,9 @@ "@digitalcredentials/security-document-loader": "^3.1.0", "@digitalcredentials/status-list-manager-git": "github:digitalcredentials/status-list-manager-git", "@digitalcredentials/vc": "^5.0.0", + "@interop/did-web-resolver": "^3.0.1", "base32-encode": "^2.0.0", - "cookie-parser": "~1.4.4", "cors": "^2.8.5", - "debug": "~2.6.9", "dotenv": "^16.0.3", "express": "~4.16.1", "morgan": "~1.9.1", diff --git a/src/config.js b/src/config.js index 8abbeea..5176876 100644 --- a/src/config.js +++ b/src/config.js @@ -8,7 +8,7 @@ const defaultPort = 4006 const defaultConsoleLogLevel = 'silly' const defaultLogLevel = 'silly' const testSeed = 'z1AeiPT496wWmo9BG2QYXeTusgFSZPNG3T9wNeTtjrQ3rCB' -const testTenantName = 'test' +const testTenantName = 'testing' const randomTenantName = 'random' const DID_SEEDS = {} @@ -18,9 +18,12 @@ export function setConfig() { async function parseTenantSeeds() { // add in the default test key now, so it can be overridden by env - DID_SEEDS[testTenantName] = await decodeSeed(testSeed) + DID_SEEDS[testTenantName] = { + didSeed: await decodeSeed(testSeed), + didMethod: 'key' + } // also add in the random test key - const randomSeed = await generateSecretKeySeed() + const randomSeed = { didSeed: await generateSecretKeySeed() } DID_SEEDS[randomTenantName] = await decodeSeed(randomSeed) const allEnvVars = process.env const didSeedKeys = Object.getOwnPropertyNames(allEnvVars).filter((key) => @@ -31,8 +34,16 @@ async function parseTenantSeeds() { if (value === 'generate') { value = await generateSecretKeySeed() } - const tenantName = key.slice(12).toLowerCase() - DID_SEEDS[tenantName] = await decodeSeed(value) + const tenant = key.slice(12) + const tenantName = tenant.toLowerCase() + DID_SEEDS[tenantName] = { + didSeed: await decodeSeed(value), + didMethod: + process.env[`TENANT_DIDMETHOD_${tenant}`].toLowerCase === 'web' + ? 'web' + : 'key', + didUrl: process.env[`TENANT_DID_URL_${tenant}`] + } } } diff --git a/src/issue.js b/src/issue.js index 0a9c072..06beb51 100644 --- a/src/issue.js +++ b/src/issue.js @@ -1,5 +1,6 @@ import { Ed25519Signature2020 } from '@digitalcredentials/ed25519-signature-2020' -import { driver } from '@digitalcredentials/did-method-key' +import { driver as keyDriver } from '@digitalcredentials/did-method-key' +import { driver as webDriver } from '@interop/did-web-resolver' import { securityLoader } from '@digitalcredentials/security-document-loader' import { IssuerInstance } from '@digitalcredentials/issuer-core' import { getTenantSeed } from './config.js' @@ -8,9 +9,12 @@ import SigningException from './SigningException.js' const ISSUER_INSTANCES = {} const documentLoader = securityLoader().build() -const buildIssuerInstance = async (seed) => { - const didKeyDriver = driver() - const { didDocument, methodFor } = await didKeyDriver.generate({ seed }) +const buildIssuerInstance = async (seed, method, url) => { + const didDriver = method === 'web' ? webDriver() : keyDriver() + const { didDocument, methodFor } = await didDriver.generate({ + seed, + ...(url ? { url } : null) + }) // const issuerDid = didDocument.id const signingKeyPair = methodFor({ purpose: 'assertionMethod' }) const signingSuite = new Ed25519Signature2020({ key: signingKeyPair }) @@ -20,9 +24,15 @@ const buildIssuerInstance = async (seed) => { const getIssuerInstance = async (instanceId) => { if (!ISSUER_INSTANCES[instanceId]) { - const didSeed = await getTenantSeed(instanceId) - if (!didSeed) throw new SigningException(404, "Tenant doesn't exist.") - ISSUER_INSTANCES[instanceId] = await buildIssuerInstance(didSeed) + const config = await getTenantSeed(instanceId) + if (!config?.didSeed) + throw new SigningException(404, "Tenant doesn't exist.") + const { didSeed, didMethod, didUrl } = config + ISSUER_INSTANCES[instanceId] = await buildIssuerInstance( + didSeed, + didMethod, + didUrl + ) } return ISSUER_INSTANCES[instanceId] }