Skip to content

Commit

Permalink
feat: allow signing credential with local resolved DID. Especially ha…
Browse files Browse the repository at this point in the history
…ndy for did:web that is not yet published/exposed
  • Loading branch information
nklomp committed Aug 8, 2023
1 parent 3392837 commit 34793e9
Show file tree
Hide file tree
Showing 18 changed files with 215 additions and 218 deletions.
8 changes: 4 additions & 4 deletions packages/oid4vci-issuer-rest-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
"@sphereon/did-uni-client": "^0.6.0",
"@sphereon/pex": "2.1.0",
"@sphereon/pex-models": "^2.0.3",
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.13.0",
"@sphereon/ssi-sdk-ext.key-manager": "0.13.0",
"@sphereon/ssi-sdk-ext.key-utils": "0.13.0",
"@sphereon/ssi-sdk-ext.kms-local": "0.13.0",
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.13.1-next.7",
"@sphereon/ssi-sdk-ext.key-manager": "0.13.1-next.7",
"@sphereon/ssi-sdk-ext.key-utils": "0.13.1-next.7",
"@sphereon/ssi-sdk-ext.kms-local": "0.13.1-next.7",
"@sphereon/ssi-sdk.data-store": "workspace:*",
"@sphereon/ssi-sdk.vc-handler-ld-local": "workspace:*",
"@types/body-parser": "^1.19.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/oid4vci-issuer-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"@sphereon/oid4vci-common": "0.6.0",
"@sphereon/ssi-sdk-ext.did-utils": "0.13.0",
"@sphereon/ssi-sdk-ext.did-utils": "0.13.1-next.7",
"@sphereon/ssi-sdk.kv-store-temp": "workspace:*",
"@types/uuid": "^9.0.1",
"@veramo/core": "4.2.0",
Expand Down
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.13.0",
"@sphereon/ssi-sdk-ext.did-utils": "0.13.1-next.7",
"@sphereon/ssi-sdk.core": "workspace:*",
"@sphereon/ssi-sdk.kv-store-temp": "workspace:*",
"@sphereon/ssi-sdk.oid4vci-issuer-store": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/oid4vci-issuer/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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 })
const resolver = getAgentResolver(_context, { resolverResolution: true, uniresolverResolution: true, localResolution: true })
verifyOpts = { ...verifyOpts, resolver: verifyOpts?.resolver } // Resolver seperately as that is a function
if (!verifyOpts?.resolver || typeof verifyOpts?.resolver?.resolve !== 'function') {
verifyOpts.resolver = resolver
Expand Down
2 changes: 1 addition & 1 deletion packages/presentation-exchange/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"@sphereon/pex": "2.1.0",
"@sphereon/pex-models": "^2.0.3",
"@sphereon/ssi-sdk-ext.did-utils": "0.13.0",
"@sphereon/ssi-sdk-ext.did-utils": "0.13.1-next.7",
"@sphereon/ssi-sdk.kv-store-temp": "workspace:*",
"@sphereon/ssi-types": "workspace:*",
"@veramo/core": "4.2.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/siopv2-oid4vp-op-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@sphereon/did-auth-siop": "0.3.2-unstable.8",
"@sphereon/pex": "2.1.0",
"@sphereon/pex-models": "2.0.2",
"@sphereon/ssi-sdk-ext.did-utils": "0.13.0",
"@sphereon/ssi-sdk-ext.did-utils": "0.13.1-next.7",
"@sphereon/ssi-sdk.core": "workspace:*",
"@sphereon/ssi-sdk.presentation-exchange": "workspace:*",
"@sphereon/ssi-types": "workspace:*",
Expand Down
4 changes: 3 additions & 1 deletion packages/siopv2-oid4vp-op-auth/src/session/OpSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ export class OpSession {
return await (await this.getAuthorizationRequest()).authorizationRequest.mergedPayloads()
}
public async sendAuthorizationResponse(args: IOpsSendSiopAuthorizationResponseArgs): Promise<Response> {
const resolveOpts: ResolveOpts = this.options.resolveOpts ?? { resolver: new AgentDIDResolver(this.context, true) }
const resolveOpts: ResolveOpts = this.options.resolveOpts ?? {
resolver: new AgentDIDResolver(this.context, { uniresolverResolution: true, localResolution: true, resolverResolution: true }),
}
if (!resolveOpts.subjectSyntaxTypesSupported || resolveOpts.subjectSyntaxTypesSupported.length === 0) {
resolveOpts.subjectSyntaxTypesSupported = await this.getSupportedDIDMethods(true)
}
Expand Down
7 changes: 6 additions & 1 deletion packages/siopv2-oid4vp-op-auth/src/session/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ export async function createOPBuilder({
.withExpiresIn(opOptions.expiresIn ?? 300)
.withCheckLinkedDomain(opOptions.checkLinkedDomains ?? CheckLinkedDomain.IF_PRESENT)
.withCustomResolver(
opOptions.resolveOpts?.resolver ?? new AgentDIDResolver(context, opOptions.resolveOpts?.noUniversalResolverFallback !== false)
opOptions.resolveOpts?.resolver ??
new AgentDIDResolver(context, {
uniresolverResolution: opOptions.resolveOpts?.noUniversalResolverFallback !== true,
localResolution: true,
resolverResolution: true,
})
)
.withEventEmitter(eventEmitter)
.withRegistration({
Expand Down
2 changes: 1 addition & 1 deletion packages/siopv2-oid4vp-rp-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"@sphereon/did-auth-siop": "0.3.2-unstable.8",
"@sphereon/pex": "2.1.0",
"@sphereon/ssi-sdk-ext.did-utils": "0.13.0",
"@sphereon/ssi-sdk-ext.did-utils": "0.13.1-next.7",
"@sphereon/ssi-sdk.core": "workspace:*",
"@sphereon/ssi-sdk.kv-store-temp": "workspace:*",
"@sphereon/ssi-sdk.presentation-exchange": "workspace:*",
Expand Down
12 changes: 9 additions & 3 deletions packages/siopv2-oid4vp-rp-auth/src/agent/SIOPv2RP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class SIOPv2RP implements IAgentPlugin {
if (!this.opts.defaultOpts.didOpts.resolveOpts?.resolver || typeof this.opts.defaultOpts.didOpts.resolveOpts.resolver.resolve !== 'function') {
this.opts.defaultOpts.didOpts.resolveOpts = {
...this.opts.defaultOpts.didOpts.resolveOpts,
resolver: getAgentResolver(context, { uniresolverFallback: true }),
resolver: getAgentResolver(context, { uniresolverResolution: true, resolverResolution: true, localResolution: true }),
}
}
}
Expand Down Expand Up @@ -184,7 +184,11 @@ export class SIOPv2RP implements IAgentPlugin {
rpOpts.didOpts = { ...rpOpts.didOpts }
rpOpts.didOpts.resolveOpts = { ...rpOpts.didOpts.resolveOpts }
console.log('Using agent DID resolver for RP instance with definition id ' + args.definitionId)
rpOpts.didOpts.resolveOpts.resolver = getAgentResolver(context, { uniresolverFallback: true })
rpOpts.didOpts.resolveOpts.resolver = getAgentResolver(context, {
uniresolverResolution: true,
localResolution: true,
resolverResolution: true,
})
}

/*const definition = args.definition ?? (definitionId ? await context.agent.pexStoreGetDefinition({
Expand Down Expand Up @@ -229,7 +233,9 @@ export class SIOPv2RP implements IAgentPlugin {
if (!options.didOpts.resolveOpts || typeof options.didOpts.resolveOpts.resolver?.resolve !== 'function') {
options.didOpts.resolveOpts = {
...this.opts.defaultOpts.didOpts.resolveOpts,
resolver: this.opts.defaultOpts.didOpts?.resolveOpts?.resolver ?? getAgentResolver(context, { uniresolverFallback: true }),
resolver:
this.opts.defaultOpts.didOpts?.resolveOpts?.resolver ??
getAgentResolver(context, { localResolution: true, resolverResolution: true, uniresolverResolution: true }),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/siopv2-oid4vp-rp-auth/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ export async function createRPBuilder(args: {
.withResponseMode(rpOpts.responseMode ?? ResponseMode.POST)
.withResponseType(ResponseType.ID_TOKEN, PropertyTarget.REQUEST_OBJECT)
.withCustomResolver(
rpOpts.didOpts.resolveOpts?.resolver ?? new AgentDIDResolver(context, rpOpts.didOpts.resolveOpts?.noUniversalResolverFallback !== false)
rpOpts.didOpts.resolveOpts?.resolver ??
new AgentDIDResolver(context, { uniresolverResolution: rpOpts.didOpts.resolveOpts?.noUniversalResolverFallback !== true })
)
.withClientId(did, PropertyTarget.REQUEST_OBJECT)
// todo: move to options fill/correct method
Expand Down
2 changes: 1 addition & 1 deletion packages/siopv2-oid4vp-rp-rest-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@sphereon/did-uni-client": "^0.6.0",
"@sphereon/pex": "2.1.0",
"@sphereon/pex-models": "^2.0.3",
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.13.0",
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.13.1-next.7",
"@sphereon/ssi-sdk.data-store": "workspace:*",
"@sphereon/ssi-sdk.vc-handler-ld-local": "workspace:*",
"@types/body-parser": "^1.19.2",
Expand Down
10 changes: 5 additions & 5 deletions packages/uni-resolver-registrar-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"start:dev": "ts-node __tests__/agent.ts"
},
"dependencies": {
"@sphereon/ssi-sdk-ext.did-utils": "0.13.0",
"@sphereon/ssi-sdk-ext.key-manager": "0.13.0",
"@sphereon/ssi-sdk-ext.key-utils": "0.13.0",
"@sphereon/ssi-sdk-ext.did-utils": "0.13.1-next.7",
"@sphereon/ssi-sdk-ext.key-manager": "0.13.1-next.7",
"@sphereon/ssi-sdk-ext.key-utils": "0.13.1-next.7",
"@sphereon/ssi-sdk.core": "workspace:*",
"@sphereon/ssi-express-support": "workspace:*",
"@sphereon/ssi-types": "workspace:*",
Expand All @@ -30,8 +30,8 @@
},
"devDependencies": {
"@sphereon/did-uni-client": "^0.6.0",
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.13.0",
"@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.13.0",
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.13.1-next.7",
"@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.13.1-next.7",
"@sphereon/ssi-sdk.data-store": "workspace:*",
"@sphereon/ssi-sdk.vc-handler-ld-local": "workspace:*",
"@types/body-parser": "^1.19.2",
Expand Down
30 changes: 15 additions & 15 deletions packages/vc-handler-ld-local/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@
"@mattrglobal/jsonld-signatures-bbs": "^1.1.1",
"@sphereon/ed25519-signature-2018": "0.7.0-unstable.6",
"@sphereon/isomorphic-webcrypto": "^2.4.0-unstable.4",
"@sphereon/ssi-sdk-ext.did-utils": "0.13.0",
"@sphereon/ssi-sdk-ext.key-utils": "0.13.0",
"@sphereon/ssi-sdk-ext.did-utils": "0.13.1-next.7",
"@sphereon/ssi-sdk-ext.key-utils": "0.13.1-next.7",
"@sphereon/ssi-sdk.core": "workspace:*",
"@sphereon/ssi-types": "workspace:*",
"@transmute/ed25519-key-pair": "0.7.0-unstable.80",
"@transmute/jose-ld": "0.7.0-unstable.80",
"@transmute/json-web-signature": "0.7.0-unstable.80",
"@transmute/jsonld": "^0.0.4",
"@transmute/jsonld-document-loader": "^0.7.0-unstable.80",
"@transmute/secp256k1-key-pair": "0.7.0-unstable.80",
"@transmute/security-context": "0.7.0-unstable.80",
"@transmute/vc-status-rl-2020": "0.7.0-unstable.80",
"@transmute/web-crypto-key-pair": "0.7.0-unstable.80",
"@transmute/ed25519-key-pair": "0.7.0-unstable.81",
"@transmute/jose-ld": "0.7.0-unstable.81",
"@transmute/json-web-signature": "0.7.0-unstable.81",
"@transmute/jsonld": "^0.1.0",
"@transmute/jsonld-document-loader": "^0.7.0-unstable.81",
"@transmute/secp256k1-key-pair": "0.7.0-unstable.81",
"@transmute/security-context": "0.7.0-unstable.81",
"@transmute/vc-status-rl-2020": "0.7.0-unstable.81",
"@transmute/web-crypto-key-pair": "0.7.0-unstable.81",
"@veramo/core": "4.2.0",
"@veramo/utils": "4.2.0",
"credentials-context": "^2.0.0",
Expand All @@ -51,10 +51,10 @@
},
"devDependencies": {
"@sphereon/did-uni-client": "^0.6.0",
"@sphereon/ssi-sdk-ext.did-provider-key": "0.13.0",
"@sphereon/ssi-sdk-ext.did-provider-lto": "0.13.0",
"@sphereon/ssi-sdk-ext.key-manager": "0.13.0",
"@sphereon/ssi-sdk-ext.kms-local": "0.13.0",
"@sphereon/ssi-sdk-ext.did-provider-key": "0.13.1-next.7",
"@sphereon/ssi-sdk-ext.did-provider-lto": "0.13.1-next.7",
"@sphereon/ssi-sdk-ext.key-manager": "0.13.1-next.7",
"@sphereon/ssi-sdk-ext.kms-local": "0.13.1-next.7",
"@sphereon/ssi-sdk.agent-config": "workspace:*",
"@transmute/lds-ecdsa-secp256k1-recovery2020": "^0.0.7",
"@types/nock": "^11.1.0",
Expand Down
36 changes: 27 additions & 9 deletions packages/vc-handler-ld-local/src/agent/CredentialHandlerLDLocal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import { getAgentResolver, mapIdentifierKeysToDocWithJwkSupport } from '@sphereon/ssi-sdk-ext.did-utils'
import { VerifiableCredentialSP, VerifiablePresentationSP } from '@sphereon/ssi-sdk.core'
import { CredentialPayload, IAgentContext, IAgentPlugin, IIdentifier, IKey, IResolver, PresentationPayload } from '@veramo/core'
import { IVerifyResult } from '@sphereon/ssi-types'
import {
CredentialPayload,
DIDDocument,
IAgentContext,
IAgentPlugin,
IDIDManager,
IIdentifier,
IKey,
IResolver,
PresentationPayload,
} from '@veramo/core'
import { AbstractPrivateKeyStore } from '@veramo/key-manager'
import { _ExtendedIKey, extractIssuer, isDefined, MANDATORY_CREDENTIAL_CONTEXT, OrPromise, processEntryToArray, RecordLike } from '@veramo/utils'
import Debug from 'debug'
Expand All @@ -17,8 +29,6 @@ import {
IVerifyCredentialLDArgs,
IVerifyPresentationLDArgs,
} from '../types'
import { mapIdentifierKeysToDocWithJwkSupport } from '@sphereon/ssi-sdk-ext.did-utils'
import { IVerifyResult } from '@sphereon/ssi-types'

const debug = Debug('sphereon:ssi-sdk:ld-credential-module-local')

Expand Down Expand Up @@ -104,7 +114,7 @@ export class CredentialHandlerLDLocal implements IAgentPlugin {
}
try {
const { managedKey, verificationMethod } = await this.getSigningKey(identifier, args.keyRef)
const { signingKey, verificationMethodId } = await this.findSigningKeyWithId(context, identifier, args.keyRef)
const { signingKey, verificationMethodId } = await this.findSigningKeyWithId(context, identifier, { keyRef: args.keyRef })
return await this.ldCredentialModule.issueLDVerifiableCredential(
credential,
identifier.did,
Expand Down Expand Up @@ -180,7 +190,7 @@ export class CredentialHandlerLDLocal implements IAgentPlugin {
}
try {
const { managedKey, verificationMethod } = await this.getSigningKey(identifier, args.keyRef)
const { signingKey, verificationMethodId } = await this.findSigningKeyWithId(context, identifier, args.keyRef)
const { signingKey, verificationMethodId } = await this.findSigningKeyWithId(context, identifier, { keyRef: args.keyRef })

return await this.ldCredentialModule.signLDVerifiablePresentation(
presentation,
Expand Down Expand Up @@ -219,13 +229,21 @@ export class CredentialHandlerLDLocal implements IAgentPlugin {
}

private async findSigningKeyWithId(
context: IAgentContext<IResolver>,
context: IAgentContext<IResolver & IDIDManager>,
identifier: IIdentifier,
keyRef?: string
opts?: {
keyRef?: string
didDocument?: DIDDocument
}
): Promise<{ signingKey: IKey; verificationMethodId: string }> {
const keyRef = opts?.keyRef
debug(`Retrieving signing key for id ${identifier.did} keyref ${keyRef}...`)
// @ts-ignore
const extendedKeys: _ExtendedIKey[] = await mapIdentifierKeysToDocWithJwkSupport(identifier, 'verificationMethod', context)
const didDocument =
opts?.didDocument ??
(await getAgentResolver(context)
.resolve(identifier.did)
.then((result) => result.didDocument ?? undefined))
const extendedKeys: _ExtendedIKey[] = await mapIdentifierKeysToDocWithJwkSupport(identifier, 'verificationMethod', context, didDocument)
const supportedTypes = this.ldCredentialModule.ldSuiteLoader.getAllSignatureSuiteTypes()
let signingKey: _ExtendedIKey | undefined
if (keyRef) {
Expand Down
2 changes: 1 addition & 1 deletion packages/vc-handler-ld-local/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export interface IVerifyPresentationLDArgs {
*
* @beta This API is likely to change without a BREAKING CHANGE notice
*/
export type IRequiredContext = IAgentContext<IResolver & Pick<IDIDManager, 'didManagerGet'> & Pick<IKeyManager, 'keyManagerGet' | 'keyManagerSign'>>
export type IRequiredContext = IAgentContext<IResolver & IDIDManager & Pick<IKeyManager, 'keyManagerGet' | 'keyManagerSign'>>

export type ContextDoc = {
'@context': string | Record<string, any>
Expand Down
4 changes: 2 additions & 2 deletions packages/w3c-vc-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
},
"devDependencies": {
"@sphereon/did-uni-client": "^0.6.0",
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.13.0",
"@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.13.0",
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.13.1-next.7",
"@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.13.1-next.7",
"@sphereon/ssi-sdk.data-store": "workspace:*",
"@sphereon/ssi-sdk.vc-handler-ld-local": "workspace:*",
"@types/body-parser": "^1.19.2",
Expand Down
Loading

0 comments on commit 34793e9

Please sign in to comment.