Skip to content

Commit

Permalink
chore: refactor DidAuthSiopOpAuthenticator to use an object as options
Browse files Browse the repository at this point in the history
  • Loading branch information
Brummos committed Jan 21, 2025
1 parent 7fa6278 commit 8f989fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,25 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
private readonly sessions: Map<string, OpSession>
private readonly customApprovals: Record<string, (verifiedAuthorizationRequest: VerifiedAuthorizationRequest, sessionId: string) => Promise<void>>
private readonly presentationSignCallback?: PresentationSignCallback

private readonly onContactIdentityCreated?: (args: OnContactIdentityCreatedArgs) => Promise<void>
private readonly onIdentifierCreated?: (args: OnIdentifierCreatedArgs) => Promise<void>
private readonly eventEmitter?: EventEmitter

constructor(
presentationSignCallback?: PresentationSignCallback,
customApprovals?: Record<string, (verifiedAuthorizationRequest: VerifiedAuthorizationRequest, sessionId: string) => Promise<void>>,
options?: DidAuthSiopOpAuthenticatorOptions,
) {
const { onContactIdentityCreated, onIdentifierCreated, hasher } = { ...options }
constructor(options?: DidAuthSiopOpAuthenticatorOptions) {
const {
onContactIdentityCreated,
onIdentifierCreated,
hasher,
customApprovals = {},
presentationSignCallback
} = { ...options }

this.hasher = hasher
this.onContactIdentityCreated = onContactIdentityCreated
this.onIdentifierCreated = onIdentifierCreated

this.sessions = new Map<string, OpSession>()
this.customApprovals = customApprovals || {}
this.presentationSignCallback = presentationSignCallback
this.hasher = hasher
this.sessions = new Map<string, OpSession>()
this.customApprovals = customApprovals
}

public async onEvent(event: any, context: RequiredContext): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { PresentationDefinitionWithLocation, RPRegistrationMetadataPayload } from '@sphereon/did-auth-siop'
import {
PresentationDefinitionWithLocation,
PresentationSignCallback,
RPRegistrationMetadataPayload, VerifiedAuthorizationRequest
} from '@sphereon/did-auth-siop'
import { IIdentifierResolution, ManagedIdentifierOptsOrResult } from '@sphereon/ssi-sdk-ext.identifier-resolution'
import { IContactManager } from '@sphereon/ssi-sdk.contact-manager'
import { ICredentialStore, UniqueDigitalCredential } from '@sphereon/ssi-sdk.credential-store'
Expand All @@ -10,6 +14,8 @@ import { Siopv2MachineContext, Siopv2MachineInterpreter, Siopv2MachineState } fr
import { Hasher } from '@sphereon/ssi-types'

export type DidAuthSiopOpAuthenticatorOptions = {
presentationSignCallback?: PresentationSignCallback
customApprovals?: Record<string, (verifiedAuthorizationRequest: VerifiedAuthorizationRequest, sessionId: string) => Promise<void>>
onContactIdentityCreated?: (args: OnContactIdentityCreatedArgs) => Promise<void>
onIdentifierCreated?: (args: OnIdentifierCreatedArgs) => Promise<void>
hasher?: Hasher
Expand Down

0 comments on commit 8f989fe

Please sign in to comment.