Skip to content

Commit

Permalink
WIP did:web support
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartf committed Nov 3, 2023
1 parent 0f790ea commit 6cbdab9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
mocha: true
},
parserOptions: {
ecmaVersion: 12,
ecmaVersion: 2022,
sourceType: "module"
}
}
Expand Down
36 changes: 5 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 16 additions & 5 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand All @@ -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) =>
Expand All @@ -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}`]
}
}
}

Expand Down
24 changes: 17 additions & 7 deletions src/issue.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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 })
Expand All @@ -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]
}
Expand Down

0 comments on commit 6cbdab9

Please sign in to comment.