diff --git a/packages/did-auth-siop-op-authenticator/__tests__/shared/didAuthSiopOpAuthenticatorAgentLogic.ts b/packages/did-auth-siop-op-authenticator/__tests__/shared/didAuthSiopOpAuthenticatorAgentLogic.ts index a3790f6af..a62136fe0 100644 --- a/packages/did-auth-siop-op-authenticator/__tests__/shared/didAuthSiopOpAuthenticatorAgentLogic.ts +++ b/packages/did-auth-siop-op-authenticator/__tests__/shared/didAuthSiopOpAuthenticatorAgentLogic.ts @@ -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, diff --git a/packages/did-auth-siop-op-authenticator/src/agent/DidAuthSiopOpAuthenticator.ts b/packages/did-auth-siop-op-authenticator/src/agent/DidAuthSiopOpAuthenticator.ts index d283200be..ea8d124ef 100644 --- a/packages/did-auth-siop-op-authenticator/src/agent/DidAuthSiopOpAuthenticator.ts +++ b/packages/did-auth-siop-op-authenticator/src/agent/DidAuthSiopOpAuthenticator.ts @@ -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} @@ -40,9 +40,9 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin { } private readonly sessions: Record - private readonly customApprovals: Record Promise> + private readonly customApprovals: Record Promise> - constructor(customApprovals?: Record Promise>) { + constructor(customApprovals?: Record Promise>) { this.sessions = {} this.customApprovals = customApprovals || {} } @@ -105,7 +105,7 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin { private async getSiopAuthenticationRequestFromRP( args: IGetSiopAuthenticationRequestFromRpArgs, context: IRequiredContext - ): Promise { + ): Promise { return this.getSessionForSiop({ sessionId: args.sessionId }, context).then((session) => session.getSiopAuthenticationRequestFromRP(args)) } @@ -121,7 +121,7 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin { private async verifySiopAuthenticationRequestURI( args: IVerifySiopAuthenticationRequestUriArgs, context: IRequiredContext - ): Promise { + ): Promise { return this.getSessionForSiop({ sessionId: args.sessionId }, context).then((session) => session.verifySiopAuthenticationRequestURI(args)) } 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 70ac56b1d..425d6ab33 100644 --- a/packages/did-auth-siop-op-authenticator/src/session/OpSession.ts +++ b/packages/did-auth-siop-op-authenticator/src/session/OpSession.ts @@ -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, @@ -57,8 +46,10 @@ export class OpSession { public async authenticateWithSiop(args: IOpsAuthenticateWithSiopArgs): Promise { 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) { @@ -79,7 +70,7 @@ export class OpSession { .catch((error: unknown) => Promise.reject(error)) } - public async getSiopAuthenticationRequestFromRP(args: IOpsGetSiopAuthenticationRequestFromRpArgs): Promise { + public async getSiopAuthenticationRequestFromRP(args: IOpsGetSiopAuthenticationRequestFromRpArgs): Promise { 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()) @@ -101,7 +92,9 @@ export class OpSession { } } - public async verifySiopAuthenticationRequestURI(args: IOpsVerifySiopAuthenticationRequestUriArgs): Promise { + public async verifySiopAuthenticationRequestURI( + args: IOpsVerifySiopAuthenticationRequestUriArgs + ): Promise { // 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[] = [] @@ -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, }, @@ -139,12 +132,12 @@ export class OpSession { } private async matchPresentationDefinitions( - presentationDefs: PresentationDefinitionWithLocation[], + presentationDefs: SIOP.PresentationDefinitionWithLocation[], verifiableCredentials: IVerifiableCredential[] ): Promise { 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))) @@ -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, } }) @@ -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') } @@ -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() } } 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 f267ef453..e19211bc0 100644 --- a/packages/did-auth-siop-op-authenticator/src/types/IDidAuthSiopOpAuthenticator.ts +++ b/packages/did-auth-siop-op-authenticator/src/types/IDidAuthSiopOpAuthenticator.ts @@ -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 @@ -17,12 +11,12 @@ export interface IDidAuthSiopOpAuthenticator extends IPluginMethodMap { getSiopAuthenticationRequestFromRP( args: IGetSiopAuthenticationRequestFromRpArgs, context: IRequiredContext - ): Promise + ): Promise getSiopAuthenticationRequestDetails(args: IGetSiopAuthenticationRequestDetailsArgs, context: IRequiredContext): Promise verifySiopAuthenticationRequestURI( args: IVerifySiopAuthenticationRequestUriArgs, context: IRequiredContext - ): Promise + ): Promise sendSiopAuthenticationResponse(args: ISendSiopAuthenticationResponseArgs, context: IRequiredContext): Promise registerCustomApprovalForSiop(args: IRegisterCustomApprovalForSiopArgs, context: IRequiredContext): Promise removeCustomApprovalForSiop(args: IRemoveCustomApprovalForSiopArgs, context: IRequiredContext): Promise @@ -40,7 +34,7 @@ export interface IAuthenticateWithSiopArgs { sessionId: string stateId: string redirectUrl: string - customApproval?: ((verifiedAuthenticationRequest: VerifiedAuthenticationRequestWithJWT) => Promise) | string + customApproval?: ((verifiedAuthenticationRequest: SIOP.VerifiedAuthenticationRequestWithJWT) => Promise) | string } export interface IGetSiopAuthenticationRequestFromRpArgs { @@ -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 } @@ -96,7 +90,7 @@ export interface IRemoveSiopSessionArgs { export interface IRegisterCustomApprovalForSiopArgs { key: string - customApproval: (verifiedAuthenticationRequest: VerifiedAuthenticationRequestWithJWT) => Promise + customApproval: (verifiedAuthenticationRequest: SIOP.VerifiedAuthenticationRequestWithJWT) => Promise } export interface IRemoveCustomApprovalForSiopArgs { @@ -106,8 +100,8 @@ export interface IRemoveCustomApprovalForSiopArgs { export interface IOpsAuthenticateWithSiopArgs { stateId: string redirectUrl: string - customApprovals: Record Promise> - customApproval?: ((verifiedAuthenticationRequest: VerifiedAuthenticationRequestWithJWT) => Promise) | string + customApprovals: Record Promise> + customApproval?: ((verifiedAuthenticationRequest: SIOP.VerifiedAuthenticationRequestWithJWT) => Promise) | string } export interface IOpsGetSiopAuthenticationRequestFromRpArgs { @@ -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 {