From 7da3f2730265b40d04252f81b5b235f12622427d Mon Sep 17 00:00:00 2001 From: Rafael Belchior Date: Wed, 14 Aug 2024 12:38:52 +0100 Subject: [PATCH] fix(satp-hermes): fix handler and service intialization Signed-off-by: Rafael Belchior --- .../src/main/typescript/core/errors.ts | 27 +++--- .../client/stage0-client-service.ts | 1 + .../client/stage1-client-service.ts | 1 + .../client/stage2-client-service.ts | 1 + .../client/stage3-client-service.ts | 1 + .../core/stage-services/satp-service.ts | 23 ++++- .../server/stage0-server-service.ts | 5 +- .../server/stage1-server-service.ts | 6 +- .../server/stage2-server-service.ts | 1 + .../server/stage3-server-service.ts | 1 + .../src/main/typescript/core/types.ts | 16 +--- .../typescript/gol/gateway-orchestrator.ts | 6 +- .../src/main/typescript/gol/satp-manager.ts | 93 ++++++++++++------- .../main/typescript/types/satp-protocol.ts | 36 ++++++- 14 files changed, 148 insertions(+), 70 deletions(-) diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/errors.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/errors.ts index 0eb24f198b..9a3f4ebe54 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/errors.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/errors.ts @@ -1,8 +1,9 @@ -export class SATPError extends Error { +export class SATPInternalError extends Error { constructor( - message: string, + public message: string, + // TODO internal error codes public code: number = 500, - public internalErrorId?: string, + public traceID?: string, public trace?: string, ) { super(message); @@ -12,35 +13,37 @@ export class SATPError extends Error { } } -export class BootstrapError extends SATPError { - constructor(internalErrorId?: string, trace?: string) { +export class BootstrapError extends SATPInternalError { + constructor(traceID?: string, trace?: string) { super( "Bootstrap already called in this Gateway Manager", 409, - internalErrorId, + traceID, trace, ); } } -export class NonExistantGatewayIdentity extends SATPError { - constructor(id: string, internalErrorId?: string, trace?: string) { - super(`Gateway with id ${id} does not exist`, 404, internalErrorId, trace); +export class NonExistantGatewayIdentity extends SATPInternalError { + constructor(id: string, traceID?: string, trace?: string) { + super(`Gateway with id ${id} does not exist`, 404, traceID, trace); } } -export class GetStatusError extends SATPError { +export class GetStatusError extends SATPInternalError { constructor( sessionID: string, message: string, - internalErrorId?: string, + traceID?: string, trace?: string, ) { super( `Could not GetStatus at Session: with id ${sessionID}. Reason: ${message}`, 400, - internalErrorId, + traceID, trace, ); } } +// TODO client-facing error logic, maps SATPInternalErrors to user friendly errors +export class SATPError extends Error {} diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage0-client-service.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage0-client-service.ts index aa09838890..786c693aa7 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage0-client-service.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage0-client-service.ts @@ -34,6 +34,7 @@ import { export class Stage0ClientService extends SATPService { public static readonly SATP_STAGE = "0"; public static readonly SERVICE_TYPE = SATPServiceType.Client; + public static readonly SATP_SERVICE_INTERNAL_NAME = `stage-${this.SATP_STAGE}-${SATPServiceType[this.SERVICE_TYPE].toLowerCase()}`; constructor(ops: ISATPClientServiceOptions) { // for now stage1serverservice does not have any different options than the SATPService class diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage1-client-service.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage1-client-service.ts index a73e11a828..2d6caeaa19 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage1-client-service.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage1-client-service.ts @@ -34,6 +34,7 @@ import { export class Stage1ClientService extends SATPService { public static readonly SATP_STAGE = "1"; public static readonly SERVICE_TYPE = SATPServiceType.Client; + public static readonly SATP_SERVICE_INTERNAL_NAME = `stage-${this.SATP_STAGE}-${SATPServiceType[this.SERVICE_TYPE].toLowerCase()}`; constructor(ops: ISATPClientServiceOptions) { // for now stage1serverservice does not have any different options than the SATPService class diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage2-client-service.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage2-client-service.ts index 63a743acc6..33e7122a9f 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage2-client-service.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage2-client-service.ts @@ -43,6 +43,7 @@ import { export class Stage2ClientService extends SATPService { public static readonly SATP_STAGE = "2"; public static readonly SERVICE_TYPE = SATPServiceType.Client; + public static readonly SATP_SERVICE_INTERNAL_NAME = `stage-${this.SATP_STAGE}-${SATPServiceType[this.SERVICE_TYPE].toLowerCase()}`; private bridgeManager: SATPBridgesManager; diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage3-client-service.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage3-client-service.ts index cbd1bd0777..f19cb6877f 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage3-client-service.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage3-client-service.ts @@ -48,6 +48,7 @@ import { export class Stage3ClientService extends SATPService { public static readonly SATP_STAGE = "3"; public static readonly SERVICE_TYPE = SATPServiceType.Client; + public static readonly SATP_SERVICE_INTERNAL_NAME = `stage-${this.SATP_STAGE}-${SATPServiceType[this.SERVICE_TYPE].toLowerCase()}`; private bridgeManager: SATPBridgesManager; diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-service.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-service.ts index 089e049a32..dc666b1f3c 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-service.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-service.ts @@ -5,21 +5,42 @@ import { ILoggerOptions, } from "@hyperledger/cactus-common"; import { SATPBridgesManager } from "../../gol/satp-bridges-manager"; +import { SatpStage0Service } from "../../generated/proto/cacti/satp/v02/stage_0_connect"; +import { SatpStage1Service } from "../../generated/proto/cacti/satp/v02/stage_1_connect"; +import { SatpStage2Service } from "../../generated/proto/cacti/satp/v02/stage_2_connect"; +import { SatpStage3Service } from "../../generated/proto/cacti/satp/v02/stage_3_connect"; export enum SATPServiceType { Server = "Server", Client = "Client", } +export type SATPStagesV02 = "0" | "1" | "2" | "3"; + export type ISATPServiceOptions = { serviceName: string; - stage: "0" | "1" | "2" | "3"; + stage: SATPStagesV02; loggerOptions: ILoggerOptions; signer: JsObjectSigner; serviceType: SATPServiceType; bridgeManager?: SATPBridgesManager; }; +export interface SATPServiceStatic { + new (options: ISATPServiceOptions): SATPService; + readonly SERVICE_TYPE: SATPServiceType; + readonly SATP_STAGE: string; + // service name serves as an internal, hardcoded service name. One can assign a more user-friendly service name via the SATPService constructor + readonly SATP_SERVICE_INTERNAL_NAME: string; + get ServiceType(): SATPServiceType; +} + +export type SATPServiceInstance = + | (typeof SatpStage0Service & SATPServiceStatic) + | (typeof SatpStage1Service & SATPServiceStatic) + | (typeof SatpStage2Service & SATPServiceStatic) + | (typeof SatpStage3Service & SATPServiceStatic); + export type ISATPServerServiceOptions = ISATPServiceOptions; export type ISATPClientServiceOptions = ISATPServiceOptions; diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage0-server-service.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage0-server-service.ts index c099221770..747d10760c 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage0-server-service.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage0-server-service.ts @@ -24,7 +24,6 @@ import { saveHash, saveSignature, } from "../../session-utils"; -import { SupportedChain } from "../../types"; import { SATPSession } from "../../../core/satp-session"; import { SATPService, @@ -36,6 +35,7 @@ import { export class Stage0ServerService extends SATPService { public static readonly SATP_STAGE = "0"; public static readonly SERVICE_TYPE = SATPServiceType.Server; + public static readonly SATP_SERVICE_INTERNAL_NAME = `stage-${this.SATP_STAGE}-${SATPServiceType[this.SERVICE_TYPE].toLowerCase()}`; constructor(ops: ISATPServerServiceOptions) { // for now stage0serverservice does not have any different options than the SATPService class @@ -234,6 +234,9 @@ export class Stage0ServerService extends SATPService { const stepTag = `checkTransferProposalRequestMessage()`; const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + // todo use session; + session; + if ( request.context == undefined || request.context.version == undefined || diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage1-server-service.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage1-server-service.ts index 44401e0faa..f6ac52e937 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage1-server-service.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage1-server-service.ts @@ -9,7 +9,10 @@ import { CommonSatp, } from "../../../generated/proto/cacti/satp/v02/common/message_pb"; // eslint-disable-next-line prettier/prettier -import { ACCEPTANCE, SessionData } from "../../../generated/proto/cacti/satp/v02/common/session_pb"; +import { + ACCEPTANCE, + SessionData, +} from "../../../generated/proto/cacti/satp/v02/common/session_pb"; import { SATP_VERSION } from "../../constants"; import { bufArray2HexStr, @@ -52,6 +55,7 @@ import { export class Stage1ServerService extends SATPService { public static readonly SATP_STAGE = "1"; public static readonly SERVICE_TYPE = SATPServiceType.Server; + public static readonly SATP_SERVICE_INTERNAL_NAME = `stage-${this.SATP_STAGE}-${SATPServiceType[this.SERVICE_TYPE].toLowerCase()}`; constructor(ops: ISATPServerServiceOptions) { // for now stage1serverservice does not have any different options than the SATPService class diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage2-server-service.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage2-server-service.ts index 1551c131d1..1c01eb4b78 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage2-server-service.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage2-server-service.ts @@ -41,6 +41,7 @@ import { export class Stage2ServerService extends SATPService { public static readonly SATP_STAGE = "2"; public static readonly SERVICE_TYPE = SATPServiceType.Server; + public static readonly SATP_SERVICE_INTERNAL_NAME = `stage-${this.SATP_STAGE}-${SATPServiceType[this.SERVICE_TYPE].toLowerCase()}`; constructor(ops: ISATPServerServiceOptions) { const commonOptions: ISATPServiceOptions = { diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage3-server-service.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage3-server-service.ts index 114f19b61d..7634d9416f 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage3-server-service.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage3-server-service.ts @@ -49,6 +49,7 @@ import { export class Stage3ServerService extends SATPService { public static readonly SATP_STAGE = "3"; public static readonly SERVICE_TYPE = SATPServiceType.Server; + public static readonly SATP_SERVICE_INTERNAL_NAME = `stage-${this.SATP_STAGE}-${SATPServiceType[this.SERVICE_TYPE].toLowerCase()}`; private bridgeManager: SATPBridgesManager; diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/types.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/types.ts index 162d2181e6..80b9b70d8e 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/types.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/types.ts @@ -3,29 +3,20 @@ import { ValidatorOptions } from "class-validator"; import { BLODispatcher } from "../blo/dispatcher"; import { ISignerKeyPairs } from "@hyperledger/cactus-common/dist/lib/main/typescript/signer-key-pairs"; import { SATPSession } from "./satp-session"; -import { SatpStage0Service } from "../generated/proto/cacti/satp/v02/stage_0_connect"; -import { SatpStage1Service } from "../generated/proto/cacti/satp/v02/stage_1_connect"; -import { SatpStage2Service } from "../generated/proto/cacti/satp/v02/stage_2_connect"; -import { SatpStage3Service } from "../generated/proto/cacti/satp/v02/stage_3_connect"; import { ConnectRouter } from "@connectrpc/connect"; import { SATPGateway } from "../plugin-satp-hermes-gateway"; import { SATPService } from "../types/satp-protocol"; import { PromiseClient as PromiseConnectClient } from "@connectrpc/connect"; import { IPrivacyPolicyValue } from "@hyperledger/cactus-plugin-bungee-hermes/dist/lib/main/typescript/view-creation/privacy-policies"; import { IMergePolicyValue } from "@hyperledger/cactus-plugin-bungee-hermes/dist/lib/main/typescript/view-merging/merge-policies"; +import { NetworkBridge } from "./stage-services/satp-bridge/network-bridge"; +import { SATPServiceInstance } from "./stage-services/satp-service"; export type SATPConnectHandler = ( gateway: SATPGateway, service: SATPService, ) => (router: ConnectRouter) => void; -export type SATPServiceClient = - | typeof SatpStage0Service - | typeof SatpStage1Service - | typeof SatpStage2Service - | typeof SatpStage3Service; -import { NetworkBridge } from "./stage-services/satp-bridge/network-bridge"; - export enum CurrentDrafts { Core = "Core", Architecture = "Architecture", @@ -55,7 +46,7 @@ export type GatewayChannel = { toGatewayID: string; sessions: Map; supportedDLTs: SupportedChain[]; - clients: Map>; + clients: Map>; }; export type Address = @@ -126,3 +117,4 @@ export interface SATPBridgeConfig { network: NetworkBridge; logLevel?: LogLevelDesc; } +export { SATPServiceInstance }; diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/gol/gateway-orchestrator.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/gol/gateway-orchestrator.ts index 63338744ba..18d59d24fa 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/gol/gateway-orchestrator.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/gol/gateway-orchestrator.ts @@ -10,7 +10,7 @@ import { GatewayIdentity, GatewayChannel, SupportedChain, - SATPServiceClient, + SATPServiceInstance, } from "../core/types"; import { PromiseClient as PromiseConnectClient, @@ -204,7 +204,7 @@ export class GatewayOrchestrator { private createConnectClients( identity: GatewayIdentity, - ): Map> { + ): Map> { // one function for each client type; aggregate in array const transport = createConnectTransport({ baseUrl: identity.address + ":" + identity.gatewayGrpcPort, @@ -213,7 +213,7 @@ export class GatewayOrchestrator { const clients: Map< string, - PromiseConnectClient + PromiseConnectClient > = new Map(); clients.set("0", this.createStage0ServiceClient(transport)); diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/gol/satp-manager.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/gol/satp-manager.ts index 7400950d22..dfa48a7152 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/gol/satp-manager.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/gol/satp-manager.ts @@ -24,8 +24,14 @@ import { SATPServiceType, SATPHandlerOptions, SATPHandlerType, + ISATPHandler, + SATPHandlerInstance, } from "../types/satp-protocol"; -import { ISATPServiceOptions } from "../core/stage-services/satp-service"; +import { + ISATPServiceOptions, + SATPServiceInstance, + SATPStagesV02, +} from "../core/stage-services/satp-service"; import { Stage2SATPHandler } from "../core/stage-handlers/stage2-handler"; import { Stage3SATPHandler } from "../core/stage-handlers/stage3-handler"; import { SATPBridgesManager } from "./satp-bridges-manager"; @@ -57,6 +63,7 @@ export class SATPManager { private signer: JsObjectSigner; public supportedDLTs: SupportedChain[] = []; private sessions: Map; + // maps stage to client/service and service class private readonly satpServices: Map< string, Map @@ -83,21 +90,21 @@ export class SATPManager { this.sessions = options.sessions || new Map(); const handlersClasses = [ - Stage0SATPHandler, - Stage1SATPHandler, - Stage2SATPHandler, - Stage3SATPHandler, + Stage0SATPHandler as unknown as SATPHandlerInstance, + Stage1SATPHandler as unknown as SATPHandlerInstance, + Stage2SATPHandler as unknown as SATPHandlerInstance, + Stage3SATPHandler as unknown as SATPHandlerInstance, ]; const serviceClasses = [ - Stage0ServerService, - Stage0ClientService, - Stage1ServerService, - Stage1ClientService, - Stage2ServerService, - Stage2ClientService, - Stage3ServerService, - Stage3ClientService, + Stage0ServerService as unknown as SATPServiceInstance, + Stage0ClientService as unknown as SATPServiceInstance, + Stage1ServerService as unknown as SATPServiceInstance, + Stage1ClientService as unknown as SATPServiceInstance, + Stage2ServerService as unknown as SATPServiceInstance, + Stage2ClientService as unknown as SATPServiceInstance, + Stage3ServerService as unknown as SATPServiceInstance, + Stage3ClientService as unknown as SATPServiceInstance, ]; const serviceOptions = this.initializeServiceOptions( @@ -122,17 +129,22 @@ export class SATPManager { public getServiceByStage( serviceType: SATPServiceType, - stageId: string, + stageID: string, ): SATPService { - if (isNaN(Number(stageId))) { + // we assume stages are numbers + if (isNaN(Number(stageID))) { throw new Error("Invalid stageId"); } - const service = this.satpServices.get(stageId)?.get(serviceType); + if (!this.satpServices) { + throw new Error("No satp services defined"); + } + + const service = this.satpServices.get(stageID)?.get(serviceType); if (service == undefined) { throw new Error( - `Service not found for stageId=${stageId} and serviceType=${serviceType}`, + `Service not found for stageId=${stageID} and serviceType=${serviceType}`, ); } return service; @@ -190,25 +202,27 @@ export class SATPManager { } private initializeServiceOptions( - serviceClasses: (new (options: ISATPServiceOptions) => SATPService)[], + serviceClasses: SATPServiceInstance[], logLevel: LogLevelDesc, label: string, ): ISATPServiceOptions[] { const fnTag = `${SATPManager.CLASS_NAME}#initializeServiceOptions()`; this.logger.info(`${fnTag}, Initializing services options...`); - return serviceClasses.map((_, index) => ({ + this.logger.info( + `Initializing ${serviceClasses.length} services options...`, + ); + return serviceClasses.map((serviceClass) => ({ signer: this.signer, - stage: index.toString() as "0" | "1" | "2" | "3", + stage: serviceClass.SATP_STAGE as SATPStagesV02, loggerOptions: { level: logLevel, label }, - serviceName: `Service-${index}`, - serviceType: - index % 2 === 0 ? SATPServiceType.Server : SATPServiceType.Client, + // we can pass whatever name we wish; in this case we are using the internal service name + serviceType: serviceClass.SERVICE_TYPE, + serviceName: serviceClass.SATP_SERVICE_INTERNAL_NAME, bridgeManager: this.bridgesManager, })); } - private initializeServices( - serviceClasses: (new (options: ISATPServiceOptions) => SATPService)[], + serviceClasses: SATPServiceInstance[], serviceOptions: ISATPServiceOptions[], ): void { const fnTag = `${SATPManager.CLASS_NAME}#initializeServices()`; @@ -232,33 +246,37 @@ export class SATPManager { serviceClasses.forEach((ServiceClass, index) => { const service = new ServiceClass(serviceOptions[index]); if (!this.satpServices.has(service.stage)) { + // initialize map this.satpServices.set(service.stage, new Map()); } - this.satpServices - .get(service.serviceType) - ?.set(service.serviceType, service); + this.satpServices.get(service.stage)?.set(service.serviceType, service); }); } private initializeHandlerOptions( - serviceClasses: (new (options: ISATPServiceOptions) => SATPService)[], + serviceClasses: SATPServiceInstance[], level: LogLevelDesc = "DEBUG", ): SATPHandlerOptions[] { const fnTag = `${SATPManager.CLASS_NAME}#initializeHandlerOptions()`; this.logger.info(`${fnTag}, Initializing handlers options...`); const handlersOptions: SATPHandlerOptions[] = []; - + if (serviceClasses.length % 2 != 0) { + throw new Error( + "Error intializing handler options - a pair number of services are expected", + ); + } try { - for (let i = 1; i <= serviceClasses.length / 2; i++) { + for (let i = 0; i <= serviceClasses.length / 2 - 1; i++) { + const serviceIndex = i.toString() as SATPStagesV02; const serverService = this.getServiceByStage( SATPServiceType.Server, - i.toString(), + serviceIndex, ); const clientService = this.getServiceByStage( SATPServiceType.Client, - i.toString(), + serviceIndex, ); const handlerOptions: SATPHandlerOptions = { @@ -266,8 +284,11 @@ export class SATPManager { serverService: serverService, clientService: clientService, supportedDLTs: this.supportedDLTs, - stage: i.toString() as "0" | "1" | "2" | "3", - loggerOptions: { level: level, label: `SATPHandler-Stage${i}` }, + stage: serviceIndex, + loggerOptions: { + level: level, + label: `SATPHandler-Stage${serviceIndex}`, + }, }; handlersOptions.push(handlerOptions); } @@ -279,7 +300,7 @@ export class SATPManager { } private initializeHandlers( - handlersClasses: (new (options: SATPHandlerOptions) => SATPHandler)[], + handlersClasses: SATPHandlerInstance[], handlersOptions: SATPHandlerOptions[], ): void { const fnTag = `${SATPManager.CLASS_NAME}#initializeHandlers()`; diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/types/satp-protocol.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/types/satp-protocol.ts index 653c274231..86b4cd45d9 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/types/satp-protocol.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/types/satp-protocol.ts @@ -3,10 +3,16 @@ import { SupportedChain } from "../core/types"; import { ConnectRouter } from "@connectrpc/connect"; import { SATPSession } from "../core/satp-session"; import { + ISATPServiceOptions, SATPService, SATPServiceType, } from "../core/stage-services/satp-service"; +import { Stage0SATPHandler } from "../core/stage-handlers/stage0-handler"; +import { Stage1SATPHandler } from "../core/stage-handlers/stage1-handler"; +import { Stage2SATPHandler } from "../core/stage-handlers/stage2-handler"; +import { Stage3SATPHandler } from "../core/stage-handlers/stage3-handler"; + /** * Represents a handler for various stages of the SATP (Secure Asset Transfer Protocol). * Handlers implementing this interface must provide mechanisms to setup routes and handle @@ -14,11 +20,33 @@ import { */ export enum SATPHandlerType { - STAGE0 = "Stage0SATPHandler", - STAGE1 = "Stage1SATPHandler", - STAGE2 = "Stage2SATPHandler", - STAGE3 = "Stage3SATPHandler", + STAGE0 = "stage-0-handler", + STAGE1 = "stage-1-handler", + STAGE2 = "stage-2-handler", + STAGE3 = "stage-3-handler", +} + +export interface SATPServiceStatic { + new (options: ISATPServiceOptions): SATPService; + readonly SERVICE_TYPE: SATPServiceType; + readonly SATP_STAGE: string; + // service name serves as an internal, hardcoded service name. One can assign a more user-friendly service name via the SATPService constructor + readonly SATP_SERVICE_INTERNAL_NAME: string; + get ServiceType(): SATPServiceType; } +export interface ISATPHandler { + new (options: SATPHandlerOptions): SATPHandler; + getHandlerSessions(): string[]; + getHandlerIdentifier(): SATPHandlerType; + setupRouter(router: ConnectRouter): void; +} + +export type SATPHandlerInstance = + | (typeof Stage0SATPHandler & ISATPHandler) + | (typeof Stage1SATPHandler & ISATPHandler) + | (typeof Stage2SATPHandler & ISATPHandler) + | (typeof Stage3SATPHandler & ISATPHandler); + export interface SATPHandler { setupRouter(router: ConnectRouter): void; getHandlerIdentifier(): SATPHandlerType;