From 45cea1182693b698611b062a9d664ad92e8dcd6a Mon Sep 17 00:00:00 2001 From: nklomp Date: Fri, 25 Feb 2022 03:50:10 +0100 Subject: [PATCH] feat: Add custom DID resolver support --- .../src/session/OpSession.ts | 11 ++++++++++- .../src/types/IDidAuthSiopOpAuthenticator.ts | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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 293d565d0..1bed2fe5a 100644 --- a/packages/did-auth-siop-op-authenticator/src/session/OpSession.ts +++ b/packages/did-auth-siop-op-authenticator/src/session/OpSession.ts @@ -13,11 +13,13 @@ import { IOpsVerifySiopAuthenticationRequestUriArgs, IAuthRequestDetails, IMatchedPresentationDefinition, - IRequiredContext, + IRequiredContext, ProvidedDidResolver, } from '../types/IDidAuthSiopOpAuthenticator' +import { Resolvable } from 'did-resolver' const fetch = require('cross-fetch') + export class OpSession { public readonly id: string public readonly identifier: IIdentifier @@ -26,10 +28,12 @@ export class OpSession { public readonly context: IRequiredContext public op: OP | undefined private readonly supportedDidMethods: string[] + private providedDidResolvers: ProvidedDidResolver[] constructor(options: IOpSessionArgs) { this.id = options.sessionId this.identifier = options.identifier + this.providedDidResolvers = options.providedDidResolvers || [] this.supportedDidMethods = options.supportedDidMethods || [] this.expiresIn = options.expiresIn this.verificationMethodSection = options.verificationMethodSection /*|| 'authentication'*/ @@ -41,6 +45,7 @@ export class OpSession { this.identifier, this.verificationMethodSection, parseDid(this.identifier.did).method, + this.providedDidResolvers, this.supportedDidMethods || [], this.expiresIn || 6000, this.context @@ -213,6 +218,7 @@ export class OpSession { identifier: IIdentifier, verificationMethodSection: DIDDocumentSection | undefined, didMethod: string, + providedDidResolvers: ProvidedDidResolver[], supportedDidMethods: string[], expiresIn: number, context: IRequiredContext @@ -232,6 +238,9 @@ export class OpSession { if (supportedDidMethods) { supportedDidMethods.forEach(method => builder.addDidMethod(method)) } + if (providedDidResolvers) { + providedDidResolvers.forEach(providedResolver => builder.addResolver(providedResolver.didMethod, providedResolver.resolver)) + } return builder.build() } 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 6e30e00d7..59d94a69c 100644 --- a/packages/did-auth-siop-op-authenticator/src/types/IDidAuthSiopOpAuthenticator.ts +++ b/packages/did-auth-siop-op-authenticator/src/types/IDidAuthSiopOpAuthenticator.ts @@ -2,6 +2,7 @@ import { DIDDocumentSection, IAgentContext, IIdentifier, IPluginMethodMap, IReso import { IVerifiableCredential, IVerifiablePresentation } from '@sphereon/pex' import { OpSession } from '../session/OpSession' import { SIOP } from '@sphereon/did-auth-siop' +import { Resolvable } from 'did-resolver' export interface IDidAuthSiopOpAuthenticator extends IPluginMethodMap { getSessionForSiop(args: IGetSiopSessionArgs, context: IRequiredContext): Promise @@ -21,12 +22,17 @@ export interface IDidAuthSiopOpAuthenticator extends IPluginMethodMap { registerCustomApprovalForSiop(args: IRegisterCustomApprovalForSiopArgs, context: IRequiredContext): Promise removeCustomApprovalForSiop(args: IRemoveCustomApprovalForSiopArgs, context: IRequiredContext): Promise } +export interface ProvidedDidResolver { + didMethod: string, + resolver: Resolvable +} export interface IOpSessionArgs { sessionId: string identifier: IIdentifier context: IRequiredContext supportedDidMethods?: string[] + providedDidResolvers?: ProvidedDidResolver[] expiresIn?: number verificationMethodSection?: DIDDocumentSection }