From eebce18bf9cc9d28a8bcdd6886100b7a8921bb2f Mon Sep 17 00:00:00 2001 From: nklomp Date: Fri, 25 Feb 2022 04:22:06 +0100 Subject: [PATCH] feat: Add default DID resolver support --- .../did-auth-siop-op-authenticator/package.json | 2 +- .../src/session/OpSession.ts | 17 +++++++++++++---- .../src/types/IDidAuthSiopOpAuthenticator.ts | 5 +++-- yarn.lock | 8 ++++---- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/did-auth-siop-op-authenticator/package.json b/packages/did-auth-siop-op-authenticator/package.json index cdc2ea3a8..70592260a 100644 --- a/packages/did-auth-siop-op-authenticator/package.json +++ b/packages/did-auth-siop-op-authenticator/package.json @@ -13,7 +13,7 @@ "build": "tsc --build" }, "dependencies": { - "@sphereon/did-auth-siop": "0.2.9", + "@sphereon/did-auth-siop": "0.2.10", "@sphereon/pex": "^1.0.2", "@sphereon/ssi-sdk-core": "^0.5.0", "@veramo/core": "3.1.1-next.26", diff --git a/packages/did-auth-siop-op-authenticator/src/session/OpSession.ts b/packages/did-auth-siop-op-authenticator/src/session/OpSession.ts index fdfa0a6af..01362070f 100644 --- a/packages/did-auth-siop-op-authenticator/src/session/OpSession.ts +++ b/packages/did-auth-siop-op-authenticator/src/session/OpSession.ts @@ -14,8 +14,9 @@ import { IAuthRequestDetails, IMatchedPresentationDefinition, IRequiredContext, - ProvidedDidResolver, + PerDidResolver, } from '../types/IDidAuthSiopOpAuthenticator' +import { Resolvable } from 'did-resolver' const fetch = require('cross-fetch') @@ -27,12 +28,14 @@ export class OpSession { public readonly context: IRequiredContext public op: OP | undefined private readonly supportedDidMethods: string[] - private providedDidResolvers: ProvidedDidResolver[] + private readonly providedDidResolvers: PerDidResolver[] + private readonly resolver: Resolvable | undefined constructor(options: IOpSessionArgs) { this.id = options.sessionId this.identifier = options.identifier - this.providedDidResolvers = options.providedDidResolvers || [] + this.resolver = options.resolver + this.providedDidResolvers = options.perDidResolvers || [] this.supportedDidMethods = options.supportedDidMethods || [] this.expiresIn = options.expiresIn this.verificationMethodSection = options.verificationMethodSection /*|| 'authentication'*/ @@ -44,6 +47,7 @@ export class OpSession { this.identifier, this.verificationMethodSection, parseDid(this.identifier.did).method, + this.resolver, this.providedDidResolvers, this.supportedDidMethods || [], this.expiresIn || 6000, @@ -217,7 +221,8 @@ export class OpSession { identifier: IIdentifier, verificationMethodSection: DIDDocumentSection | undefined, didMethod: string, - providedDidResolvers: ProvidedDidResolver[], + resolver: Resolvable | undefined, + providedDidResolvers: PerDidResolver[], supportedDidMethods: string[], expiresIn: number, context: IRequiredContext @@ -230,6 +235,7 @@ export class OpSession { const builder = OP.builder() .withExpiresIn(expiresIn) + .addDidMethod(didMethod) .suppliedSignature(SuppliedSigner(keyRef, context, this.getKeyAlgorithm(keyRef.type)), identifier.did, identifier.controllerKeyId) .registrationBy(SIOP.PassBy.VALUE) @@ -237,6 +243,9 @@ export class OpSession { if (supportedDidMethods) { supportedDidMethods.forEach((method) => builder.addDidMethod(method)) } + if (resolver) { + builder.defaultResolver(resolver) + } if (providedDidResolvers) { providedDidResolvers.forEach((providedResolver) => builder.addResolver(providedResolver.didMethod, providedResolver.resolver)) } diff --git a/packages/did-auth-siop-op-authenticator/src/types/IDidAuthSiopOpAuthenticator.ts b/packages/did-auth-siop-op-authenticator/src/types/IDidAuthSiopOpAuthenticator.ts index 4e78c0e6a..d22e7e385 100644 --- a/packages/did-auth-siop-op-authenticator/src/types/IDidAuthSiopOpAuthenticator.ts +++ b/packages/did-auth-siop-op-authenticator/src/types/IDidAuthSiopOpAuthenticator.ts @@ -22,7 +22,7 @@ export interface IDidAuthSiopOpAuthenticator extends IPluginMethodMap { registerCustomApprovalForSiop(args: IRegisterCustomApprovalForSiopArgs, context: IRequiredContext): Promise removeCustomApprovalForSiop(args: IRemoveCustomApprovalForSiopArgs, context: IRequiredContext): Promise } -export interface ProvidedDidResolver { +export interface PerDidResolver { didMethod: string resolver: Resolvable } @@ -32,7 +32,8 @@ export interface IOpSessionArgs { identifier: IIdentifier context: IRequiredContext supportedDidMethods?: string[] - providedDidResolvers?: ProvidedDidResolver[] + resolver?: Resolvable + perDidResolvers?: PerDidResolver[] expiresIn?: number verificationMethodSection?: DIDDocumentSection } diff --git a/yarn.lock b/yarn.lock index 424d3b55d..d4bc69cb1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2612,10 +2612,10 @@ dependencies: "@sinonjs/commons" "^1.7.0" -"@sphereon/did-auth-siop@0.2.9": - version "0.2.9" - resolved "https://registry.yarnpkg.com/@sphereon/did-auth-siop/-/did-auth-siop-0.2.9.tgz#9108c18fa67c7ed2817c6768c880e7c71d652508" - integrity sha512-5oGy4v7jBg9SAK1ouoqybAyOZGq0T9Oe4l5HzEWJeYm2X7dyAl+T9WB6cC2+cIfu0r+D6jOVg5cJdOK9gW+h8w== +"@sphereon/did-auth-siop@0.2.10": + version "0.2.10" + resolved "https://registry.yarnpkg.com/@sphereon/did-auth-siop/-/did-auth-siop-0.2.10.tgz#dbd37ae6d2b5183cbc54686d9ce156ff625a48bb" + integrity sha512-YwNYd9HX9qlRIzowcrIpFsfj8Lt+rC4QJFzHK+ryhcXG499Z/Xqzjxyk9pCOn9O3Wr69oBud0EF5JCKmipqcGA== dependencies: "@sphereon/did-uni-client" "^0.4.0" "@sphereon/pex" "^1.0.2"