Skip to content

Commit

Permalink
feat: Add custom DID resolver support
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Feb 25, 2022
1 parent df74ccd commit 45cea11
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/did-auth-siop-op-authenticator/src/session/OpSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'*/
Expand All @@ -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
Expand Down Expand Up @@ -213,6 +218,7 @@ export class OpSession {
identifier: IIdentifier,
verificationMethodSection: DIDDocumentSection | undefined,
didMethod: string,
providedDidResolvers: ProvidedDidResolver[],
supportedDidMethods: string[],
expiresIn: number,
context: IRequiredContext
Expand All @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<OpSession>
Expand All @@ -21,12 +22,17 @@ export interface IDidAuthSiopOpAuthenticator extends IPluginMethodMap {
registerCustomApprovalForSiop(args: IRegisterCustomApprovalForSiopArgs, context: IRequiredContext): Promise<void>
removeCustomApprovalForSiop(args: IRemoveCustomApprovalForSiopArgs, context: IRequiredContext): Promise<boolean>
}
export interface ProvidedDidResolver {
didMethod: string,
resolver: Resolvable
}

export interface IOpSessionArgs {
sessionId: string
identifier: IIdentifier
context: IRequiredContext
supportedDidMethods?: string[]
providedDidResolvers?: ProvidedDidResolver[]
expiresIn?: number
verificationMethodSection?: DIDDocumentSection
}
Expand Down

0 comments on commit 45cea11

Please sign in to comment.