Skip to content

Commit

Permalink
fix: fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Feb 10, 2022
1 parent 211dc0e commit 738f4ca
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TAgent } from '@veramo/core'
import { OP, PresentationExchange } from '@sphereon/did-auth-siop/dist/main'
import { OP, PresentationExchange } from '@sphereon/did-auth-siop'
import { IDidAuthSiopOpAuthenticator } from '../../src/types/IDidAuthSiopOpAuthenticator'
import {
ResponseContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
ISendSiopAuthenticationResponseArgs,
IVerifySiopAuthenticationRequestUriArgs,
} from '../types/IDidAuthSiopOpAuthenticator'
import { ParsedAuthenticationRequestURI, VerifiedAuthenticationRequestWithJWT } from '@sphereon/did-auth-siop/dist/main/types/SIOP.types'
import { SIOP } from '@sphereon/did-auth-siop'

/**
* {@inheritDoc IDidAuthSiopOpAuthenticator}
Expand All @@ -40,9 +40,9 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
}

private readonly sessions: Record<string, OpSession>
private readonly customApprovals: Record<string, (verifiedAuthenticationRequest: VerifiedAuthenticationRequestWithJWT) => Promise<void>>
private readonly customApprovals: Record<string, (verifiedAuthenticationRequest: SIOP.VerifiedAuthenticationRequestWithJWT) => Promise<void>>

constructor(customApprovals?: Record<string, (verifiedAuthenticationRequest: VerifiedAuthenticationRequestWithJWT) => Promise<void>>) {
constructor(customApprovals?: Record<string, (verifiedAuthenticationRequest: SIOP.VerifiedAuthenticationRequestWithJWT) => Promise<void>>) {
this.sessions = {}
this.customApprovals = customApprovals || {}
}
Expand Down Expand Up @@ -105,7 +105,7 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
private async getSiopAuthenticationRequestFromRP(
args: IGetSiopAuthenticationRequestFromRpArgs,
context: IRequiredContext
): Promise<ParsedAuthenticationRequestURI> {
): Promise<SIOP.ParsedAuthenticationRequestURI> {
return this.getSessionForSiop({ sessionId: args.sessionId }, context).then((session) => session.getSiopAuthenticationRequestFromRP(args))
}

Expand All @@ -121,7 +121,7 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
private async verifySiopAuthenticationRequestURI(
args: IVerifySiopAuthenticationRequestUriArgs,
context: IRequiredContext
): Promise<VerifiedAuthenticationRequestWithJWT> {
): Promise<SIOP.VerifiedAuthenticationRequestWithJWT> {
return this.getSessionForSiop({ sessionId: args.sessionId }, context).then((session) => session.verifySiopAuthenticationRequestURI(args))
}

Expand Down
45 changes: 19 additions & 26 deletions packages/did-auth-siop-op-authenticator/src/session/OpSession.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
import { DIDDocumentSection, IIdentifier, IKey, TKeyType } from '@veramo/core'
import { _ExtendedIKey, mapIdentifierKeysToDoc } from '@veramo/utils'
import { OP, PresentationExchange } from '@sphereon/did-auth-siop/dist/main'
import { OP, PresentationExchange, SIOP } from '@sphereon/did-auth-siop'
import { SubmissionRequirementMatch, IVerifiableCredential } from '@sphereon/pex'
import { parseDid } from '@sphereon/ssi-sdk-core'
import { SuppliedSigner } from '@sphereon/ssi-sdk-core'
import {
PassBy,
ResponseMode,
ParsedAuthenticationRequestURI,
PresentationDefinitionWithLocation,
VerifiedAuthenticationRequestWithJWT,
VerifyAuthenticationRequestOpts,
VerifiablePresentationTypeFormat,
VerificationMode,
KeyAlgo,
} from '@sphereon/did-auth-siop/dist/main/types/SIOP.types'
import {
IOpSessionArgs,
IOpsAuthenticateWithSiopArgs,
Expand Down Expand Up @@ -57,8 +46,10 @@ export class OpSession {

public async authenticateWithSiop(args: IOpsAuthenticateWithSiopArgs): Promise<Response> {
return this.getSiopAuthenticationRequestFromRP({ stateId: args.stateId, redirectUrl: args.redirectUrl })
.then((authenticationRequest: ParsedAuthenticationRequestURI) => this.verifySiopAuthenticationRequestURI({ requestURI: authenticationRequest }))
.then((verifiedAuthenticationRequest: VerifiedAuthenticationRequestWithJWT) => {
.then((authenticationRequest: SIOP.ParsedAuthenticationRequestURI) =>
this.verifySiopAuthenticationRequestURI({ requestURI: authenticationRequest })
)
.then((verifiedAuthenticationRequest: SIOP.VerifiedAuthenticationRequestWithJWT) => {
if (args.customApproval !== undefined) {
if (typeof args.customApproval === 'string') {
if (args.customApprovals !== undefined && args.customApprovals[args.customApproval] !== undefined) {
Expand All @@ -79,7 +70,7 @@ export class OpSession {
.catch((error: unknown) => Promise.reject(error))
}

public async getSiopAuthenticationRequestFromRP(args: IOpsGetSiopAuthenticationRequestFromRpArgs): Promise<ParsedAuthenticationRequestURI> {
public async getSiopAuthenticationRequestFromRP(args: IOpsGetSiopAuthenticationRequestFromRpArgs): Promise<SIOP.ParsedAuthenticationRequestURI> {
return fetch(`${args.redirectUrl}?stateId=${args.stateId}`)
.then(async (response: Response) =>
response.status >= 400 ? Promise.reject(new Error(await response.text())) : this.op!.parseAuthenticationRequestURI(await response.text())
Expand All @@ -101,7 +92,9 @@ export class OpSession {
}
}

public async verifySiopAuthenticationRequestURI(args: IOpsVerifySiopAuthenticationRequestUriArgs): Promise<VerifiedAuthenticationRequestWithJWT> {
public async verifySiopAuthenticationRequestURI(
args: IOpsVerifySiopAuthenticationRequestUriArgs
): Promise<SIOP.VerifiedAuthenticationRequestWithJWT> {
// TODO fix supported dids structure https://sphereon.atlassian.net/browse/MYC-141
const didMethodsSupported = args.requestURI.registration?.did_methods_supported as string[]
let didMethods: string[] = []
Expand All @@ -112,9 +105,9 @@ export class OpSession {
didMethods = [parseDid(this.identifier.did).method]
}

const options: VerifyAuthenticationRequestOpts = {
const options: SIOP.VerifyAuthenticationRequestOpts = {
verification: {
mode: VerificationMode.INTERNAL,
mode: SIOP.VerificationMode.INTERNAL,
resolveOpts: {
didMethods,
},
Expand All @@ -139,12 +132,12 @@ export class OpSession {
}

private async matchPresentationDefinitions(
presentationDefs: PresentationDefinitionWithLocation[],
presentationDefs: SIOP.PresentationDefinitionWithLocation[],
verifiableCredentials: IVerifiableCredential[]
): Promise<IMatchedPresentationDefinition[]> {
const presentationExchange = this.getPresentationExchange(verifiableCredentials)
return await Promise.all(
presentationDefs.map(async (presentationDef: PresentationDefinitionWithLocation) => {
presentationDefs.map(async (presentationDef: SIOP.PresentationDefinitionWithLocation) => {
const checked = await presentationExchange.selectVerifiableCredentialsForSubmission(presentationDef.definition)
if (checked.errors && checked.errors.length > 0) {
return Promise.reject(new Error(JSON.stringify(checked.errors)))
Expand All @@ -158,7 +151,7 @@ export class OpSession {
const verifiablePresentation = await presentationExchange.submissionFrom(presentationDef.definition, verifiableCredentials)
return {
location: presentationDef.location,
format: VerifiablePresentationTypeFormat.LDP_VP,
format: SIOP.VerifiablePresentationTypeFormat.LDP_VP,
presentation: verifiablePresentation,
}
})
Expand Down Expand Up @@ -191,12 +184,12 @@ export class OpSession {
return identifierKey
}

private getKeyAlgorithm(type: TKeyType): KeyAlgo {
private getKeyAlgorithm(type: TKeyType): SIOP.KeyAlgo {
switch (type) {
case 'Ed25519':
return KeyAlgo.EDDSA
return SIOP.KeyAlgo.EDDSA
case 'Secp256k1':
return KeyAlgo.ES256K
return SIOP.KeyAlgo.ES256K
default:
throw Error('Key type not yet supported')
}
Expand All @@ -219,8 +212,8 @@ export class OpSession {
.withExpiresIn(expiresIn)
.addDidMethod(didMethod)
.suppliedSignature(SuppliedSigner(keyRef, context, this.getKeyAlgorithm(keyRef.type)), identifier.did, identifier.controllerKeyId)
.registrationBy(PassBy.VALUE)
.response(ResponseMode.POST)
.registrationBy(SIOP.PassBy.VALUE)
.response(SIOP.ResponseMode.POST)
.build()
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { DIDDocumentSection, IAgentContext, IIdentifier, IPluginMethodMap, IResolver, IKeyManager } from '@veramo/core'
import { IVerifiableCredential, IVerifiablePresentation } from '@sphereon/pex'
import {
ParsedAuthenticationRequestURI,
VerifiedAuthenticationRequestWithJWT,
VerifiablePresentationResponseOpts,
VerifiablePresentationTypeFormat,
PresentationLocation,
} from '@sphereon/did-auth-siop/dist/main/types/SIOP.types'
import { OpSession } from '../session/OpSession'
import { SIOP } from '@sphereon/did-auth-siop'

export interface IDidAuthSiopOpAuthenticator extends IPluginMethodMap {
getSessionForSiop(args: IGetSiopSessionArgs, context: IRequiredContext): Promise<OpSession>
Expand All @@ -17,12 +11,12 @@ export interface IDidAuthSiopOpAuthenticator extends IPluginMethodMap {
getSiopAuthenticationRequestFromRP(
args: IGetSiopAuthenticationRequestFromRpArgs,
context: IRequiredContext
): Promise<ParsedAuthenticationRequestURI>
): Promise<SIOP.ParsedAuthenticationRequestURI>
getSiopAuthenticationRequestDetails(args: IGetSiopAuthenticationRequestDetailsArgs, context: IRequiredContext): Promise<IAuthRequestDetails>
verifySiopAuthenticationRequestURI(
args: IVerifySiopAuthenticationRequestUriArgs,
context: IRequiredContext
): Promise<VerifiedAuthenticationRequestWithJWT>
): Promise<SIOP.VerifiedAuthenticationRequestWithJWT>
sendSiopAuthenticationResponse(args: ISendSiopAuthenticationResponseArgs, context: IRequiredContext): Promise<IResponse>
registerCustomApprovalForSiop(args: IRegisterCustomApprovalForSiopArgs, context: IRequiredContext): Promise<void>
removeCustomApprovalForSiop(args: IRemoveCustomApprovalForSiopArgs, context: IRequiredContext): Promise<boolean>
Expand All @@ -40,7 +34,7 @@ export interface IAuthenticateWithSiopArgs {
sessionId: string
stateId: string
redirectUrl: string
customApproval?: ((verifiedAuthenticationRequest: VerifiedAuthenticationRequestWithJWT) => Promise<void>) | string
customApproval?: ((verifiedAuthenticationRequest: SIOP.VerifiedAuthenticationRequestWithJWT) => Promise<void>) | string
}

export interface IGetSiopAuthenticationRequestFromRpArgs {
Expand All @@ -51,32 +45,32 @@ export interface IGetSiopAuthenticationRequestFromRpArgs {

export interface IGetSiopAuthenticationRequestDetailsArgs {
sessionId: string
verifiedAuthenticationRequest: VerifiedAuthenticationRequestWithJWT
verifiedAuthenticationRequest: SIOP.VerifiedAuthenticationRequestWithJWT
verifiableCredentials: IVerifiableCredential[]
}

export interface IVerifySiopAuthenticationRequestUriArgs {
sessionId: string
requestURI: ParsedAuthenticationRequestURI
requestURI: SIOP.ParsedAuthenticationRequestURI
}

export interface ISendSiopAuthenticationResponseArgs {
sessionId: string
verifiedAuthenticationRequest: VerifiedAuthenticationRequestWithJWT
verifiablePresentationResponse?: VerifiablePresentationResponseOpts[]
verifiedAuthenticationRequest: SIOP.VerifiedAuthenticationRequestWithJWT
verifiablePresentationResponse?: SIOP.VerifiablePresentationResponseOpts[]
}

export interface IAuthRequestDetails {
id: string
vpResponseOpts: VerifiablePresentationResponseOpts[]
vpResponseOpts: SIOP.VerifiablePresentationResponseOpts[]
alsoKnownAs?: string[]
}

export interface IResponse extends Response {}

export interface IMatchedPresentationDefinition {
location: PresentationLocation
format: VerifiablePresentationTypeFormat
location: SIOP.PresentationLocation
format: SIOP.VerifiablePresentationTypeFormat
presentation: IVerifiablePresentation
}

Expand All @@ -96,7 +90,7 @@ export interface IRemoveSiopSessionArgs {

export interface IRegisterCustomApprovalForSiopArgs {
key: string
customApproval: (verifiedAuthenticationRequest: VerifiedAuthenticationRequestWithJWT) => Promise<void>
customApproval: (verifiedAuthenticationRequest: SIOP.VerifiedAuthenticationRequestWithJWT) => Promise<void>
}

export interface IRemoveCustomApprovalForSiopArgs {
Expand All @@ -106,8 +100,8 @@ export interface IRemoveCustomApprovalForSiopArgs {
export interface IOpsAuthenticateWithSiopArgs {
stateId: string
redirectUrl: string
customApprovals: Record<string, (verifiedAuthenticationRequest: VerifiedAuthenticationRequestWithJWT) => Promise<void>>
customApproval?: ((verifiedAuthenticationRequest: VerifiedAuthenticationRequestWithJWT) => Promise<void>) | string
customApprovals: Record<string, (verifiedAuthenticationRequest: SIOP.VerifiedAuthenticationRequestWithJWT) => Promise<void>>
customApproval?: ((verifiedAuthenticationRequest: SIOP.VerifiedAuthenticationRequestWithJWT) => Promise<void>) | string
}

export interface IOpsGetSiopAuthenticationRequestFromRpArgs {
Expand All @@ -116,17 +110,17 @@ export interface IOpsGetSiopAuthenticationRequestFromRpArgs {
}

export interface IOpsGetSiopAuthenticationRequestDetailsArgs {
verifiedAuthenticationRequest: VerifiedAuthenticationRequestWithJWT
verifiedAuthenticationRequest: SIOP.VerifiedAuthenticationRequestWithJWT
verifiableCredentials: IVerifiableCredential[]
}

export interface IOpsVerifySiopAuthenticationRequestUriArgs {
requestURI: ParsedAuthenticationRequestURI
requestURI: SIOP.ParsedAuthenticationRequestURI
}

export interface IOpsSendSiopAuthenticationResponseArgs {
verifiedAuthenticationRequest: VerifiedAuthenticationRequestWithJWT
verifiablePresentationResponse?: VerifiablePresentationResponseOpts[]
verifiedAuthenticationRequest: SIOP.VerifiedAuthenticationRequestWithJWT
verifiablePresentationResponse?: SIOP.VerifiablePresentationResponseOpts[]
}

export enum events {
Expand Down

0 comments on commit 738f4ca

Please sign in to comment.