Skip to content

Commit

Permalink
fix: VCI did resolution from agent
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Jul 7, 2023
1 parent c4a4684 commit 2c913db
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/oid4vci-issuer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"@sphereon/oid4vci-common": "0.6.0",
"@sphereon/oid4vci-issuer": "0.6.0",
"@sphereon/ssi-sdk-ext.did-utils": "0.12.1-next.9",
"@sphereon/ssi-sdk-ext.did-utils": "0.12.2-next.3",
"@sphereon/ssi-sdk.core": "workspace:*",
"@sphereon/ssi-sdk.kv-store-temp": "workspace:*",
"@sphereon/ssi-sdk.oid4vci-issuer-store": "workspace:*",
Expand Down
13 changes: 10 additions & 3 deletions packages/oid4vci-issuer/src/functions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CredentialIssuerMetadata, Jwt, JwtVerifyResult, OID4VCICredentialFormat, UniformCredentialRequest } from '@sphereon/oid4vci-common'
import { CredentialDataSupplier, CredentialSignerCallback, VcIssuer, VcIssuerBuilder } from '@sphereon/oid4vci-issuer'
import { getAgentResolver } from '@sphereon/ssi-sdk-ext.did-utils'
import { getDID, getFirstKeyWithRelation, getIdentifier, getKey, IDIDOptions, toDID } from '@sphereon/ssi-sdk-ext.did-utils'
import { ICredential, W3CVerifiableCredential } from '@sphereon/ssi-types'
import { DIDDocument, IIdentifier, IKey, ProofFormat } from '@veramo/core'
Expand All @@ -11,6 +12,11 @@ import { IIssuerOptions, IRequiredContext } from './types/IOID4VCIIssuer'

export function getJwtVerifyCallback({ verifyOpts }: { verifyOpts?: JWTVerifyOptions }, _context: IRequiredContext) {
return async (args: { jwt: string; kid?: string }): Promise<JwtVerifyResult<DIDDocument>> => {
const resolver = getAgentResolver(_context, {uniresolverFallback: true})
verifyOpts = {...verifyOpts}
if (!verifyOpts?.resolver) {
verifyOpts.resolver = resolver
}
const result = await verifyJWT(args.jwt, verifyOpts)
if (!result.verified) {
console.log(`JWT invalid: ${args.jwt}`)
Expand All @@ -22,10 +28,11 @@ export function getJwtVerifyCallback({ verifyOpts }: { verifyOpts?: JWTVerifyOpt
throw Error('No kid value found')
}
const did = kid.split('#')[0]
const didDocument = await _context.agent.resolveDid({ didUrl: did }).then((result) => result.didDocument)
if (!didDocument) {
throw Error(`Could not resolve did: ${did}`)
const didResolution = await resolver.resolve(did)
if (!didResolution || !didResolution.didDocument) {
throw Error(`Could not resolve did: ${did}, metadata: ${didResolution?.didResolutionMetadata}`)
}
const didDocument = didResolution.didDocument
const alg = jwt.header.alg
return {
alg,
Expand Down
53 changes: 44 additions & 9 deletions pnpm-lock.yaml

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

0 comments on commit 2c913db

Please sign in to comment.