Skip to content

Commit

Permalink
feat: Add default DID resolver support
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Feb 25, 2022
1 parent f1e08f7 commit eebce18
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/did-auth-siop-op-authenticator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 13 additions & 4 deletions packages/did-auth-siop-op-authenticator/src/session/OpSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import {
IAuthRequestDetails,
IMatchedPresentationDefinition,
IRequiredContext,
ProvidedDidResolver,
PerDidResolver,
} from '../types/IDidAuthSiopOpAuthenticator'
import { Resolvable } from 'did-resolver'

const fetch = require('cross-fetch')

Expand All @@ -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'*/
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -230,13 +235,17 @@ 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)
.response(SIOP.ResponseMode.POST)
if (supportedDidMethods) {
supportedDidMethods.forEach((method) => builder.addDidMethod(method))
}
if (resolver) {
builder.defaultResolver(resolver)
}
if (providedDidResolvers) {
providedDidResolvers.forEach((providedResolver) => builder.addResolver(providedResolver.didMethod, providedResolver.resolver))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface IDidAuthSiopOpAuthenticator extends IPluginMethodMap {
registerCustomApprovalForSiop(args: IRegisterCustomApprovalForSiopArgs, context: IRequiredContext): Promise<void>
removeCustomApprovalForSiop(args: IRemoveCustomApprovalForSiopArgs, context: IRequiredContext): Promise<boolean>
}
export interface ProvidedDidResolver {
export interface PerDidResolver {
didMethod: string
resolver: Resolvable
}
Expand All @@ -32,7 +32,8 @@ export interface IOpSessionArgs {
identifier: IIdentifier
context: IRequiredContext
supportedDidMethods?: string[]
providedDidResolvers?: ProvidedDidResolver[]
resolver?: Resolvable
perDidResolvers?: PerDidResolver[]
expiresIn?: number
verificationMethodSection?: DIDDocumentSection
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit eebce18

Please sign in to comment.