Skip to content

Commit

Permalink
add test for did:web and fix the issue it uncovered
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartf committed Jan 23, 2024
1 parent b74d413 commit 41c11a7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { driver } from '@digitalcredentials/did-method-key'
import { decodeSecretKeySeed } from '@digitalcredentials/bnid'
import { expect } from 'chai'
import request from 'supertest'
import { resetConfig } from './config.js'
import {
ed25519_2020suiteContext,
getCredentialStatus,
Expand Down Expand Up @@ -138,4 +139,32 @@ describe('api', () => {
expect(response.body.credentialStatus).to.eql(statusBeforeSigning)
})
})
describe('DID:web', () => {
const tenantName = 'apptest'

before(() => {
resetConfig()
process.env[`TENANT_SEED_${tenantName}`] =
'z1AeiPT496wWmo9BG2QYXeTusgFSZPNG3T9wNeTtjrQ3rCB'
process.env[`TENANT_DIDMETHOD_${tenantName}`] = 'web'
process.env[`TENANT_DID_URL_${tenantName}`] = 'https://example.com'
})

after(() => {
delete process.env[`TENANT_SEED_${tenantName}`]
delete process.env[`TENANT_DIDMETHOD_${tenantName}`]
delete process.env[`TENANT_DID_URL_${tenantName}`]
})

it('signs with a did:web', async () => {
await request(app)
.post(`/instance/${tenantName}/credentials/sign`)
.send(getUnsignedVCWithStatus())
.expect('Content-Type', /json/)
.expect((res) =>
expect(res.body.issuer.id).to.eql('did:web:example.com')
)
.expect(200)
})
})
})
7 changes: 6 additions & 1 deletion src/issue.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Ed25519Signature2020 } from '@digitalcredentials/ed25519-signature-2020'
import { Ed25519VerificationKey2020 } from '@digitalcredentials/ed25519-verification-key-2020'
import { CryptoLD } from 'crypto-ld'
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'
Expand All @@ -9,8 +11,11 @@ import SigningException from './SigningException.js'
const ISSUER_INSTANCES = {}
const documentLoader = securityLoader().build()

const cryptoLd = new CryptoLD()
cryptoLd.use(Ed25519VerificationKey2020)

const buildIssuerInstance = async (seed, method, url) => {
const didDriver = method === 'web' ? webDriver() : keyDriver()
const didDriver = method === 'web' ? webDriver({ cryptoLd }) : keyDriver()
const { didDocument, methodFor } = await didDriver.generate({
seed,
...(url ? { url } : null)
Expand Down

0 comments on commit 41c11a7

Please sign in to comment.