diff --git a/packages/cactus-plugin-satp-hermes/package.json b/packages/cactus-plugin-satp-hermes/package.json index f42731298a..89397a2be0 100644 --- a/packages/cactus-plugin-satp-hermes/package.json +++ b/packages/cactus-plugin-satp-hermes/package.json @@ -84,11 +84,13 @@ "@hyperledger/cactus-common": "2.0.0-rc.2", "@hyperledger/cactus-core": "2.0.0-rc.2", "@hyperledger/cactus-core-api": "2.0.0-rc.2", + "@hyperledger/cactus-plugin-bungee-hermes": "2.0.0-rc.1", "@hyperledger/cactus-plugin-keychain-memory": "2.0.0-rc.2", "@hyperledger/cactus-plugin-ledger-connector-besu": "2.0.0-rc.2", "@hyperledger/cactus-plugin-ledger-connector-fabric": "2.0.0-rc.2", "@hyperledger/cactus-plugin-object-store-ipfs": "2.0.0-rc.2", "@hyperledger/cactus-test-tooling": "2.0.0-rc.2", + "@openzeppelin/contracts": "4.4.0", "axios": "1.6.0", "body-parser": "1.20.2", "class-transformer": "0.5.1", diff --git a/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/common/message.proto b/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/common/message.proto index 14c27a18a3..b73dcc0c77 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/common/message.proto +++ b/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/common/message.proto @@ -36,6 +36,8 @@ message TransferClaims { string receiver_gateway_owner_id = 12; uint32 max_retries = 13; uint64 max_timeout = 14; + string amount_from_originator = 15; + string amount_to_beneficiary = 16; } message TransferClaimsFormat { @@ -192,35 +194,40 @@ enum Error { ERROR_MESSAGE_OUT_OF_SEQUENCE = 11; } -message LockAssertionClaim { - -} -message LockAssertionFormat { +message LockAssertionClaimFormat { } -message MintAssertionClaims { +message MintAssertionClaimFormat { } -message MintAssertionClaimsFormat { +message BurnAssertionClaimFormat { } -message BurnAssertionClaim { +message AssignmentAssertionClaimFormat { } -message BurnAssertionClaimFormat { - +message LockAssertionClaim { + string receipt = 1; + string signature = 2; } -message AssignmentAssertionClaim { - +message MintAssertionClaim { + string receipt = 1; + string signature = 2; } -message AssignmentAssertionClaimFormat { +message BurnAssertionClaim { + string receipt = 1; + string signature = 2; +} +message AssignmentAssertionClaim { + string receipt = 1; + string signature = 2; } diff --git a/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/common/session.proto b/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/common/session.proto index 6ca77ac19d..9bfa59cc09 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/common/session.proto +++ b/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/common/session.proto @@ -37,36 +37,40 @@ message SessionData { string sender_gateway_owner_id = 27; string receiver_gateway_owner_id = 28; string hash_transfer_init_claims = 29; - string proposed_transfer_init_claims = 30; - cacti.satp.v02.common.SignatureAlgorithm signature_algorithm = 31; - cacti.satp.v02.common.LockType lock_type = 32; - uint64 lock_expiration_time = 33; - cacti.satp.v02.common.Permissions permissions = 34; - string developer_urn = 35; - cacti.satp.v02.common.CredentialProfile credential_profile = 36; - cacti.satp.v02.common.SubsequentCalls subsequent_calls = 37; - repeated cacti.satp.v02.common.History history = 38; - bool multiple_claims_allowed = 39; - bool multiple_cancels_allowed = 40; - string last_message_received_timestamp = 41; - MessageStagesTimestamps processed_timestamps = 42; - MessageStagesTimestamps received_timestamps = 43; - cacti.satp.v02.common.LockAssertionClaim lock_assertion_claim = 44; - cacti.satp.v02.common.LockAssertionFormat lock_assertion_format = 45; - cacti.satp.v02.common.MintAssertionClaims mint_assertion_claims = 46; - cacti.satp.v02.common.MintAssertionClaimsFormat mint_assertion_claims_format = 47; - cacti.satp.v02.common.BurnAssertionClaim burn_assertion_claim = 48; - cacti.satp.v02.common.BurnAssertionClaimFormat burn_assertion_claim_format = 49; - cacti.satp.v02.common.AssignmentAssertionClaim assignment_assertion_claim = 50; - cacti.satp.v02.common.AssignmentAssertionClaimFormat assignment_assertion_claim_format = 51; - bool completed = 52; - ACCEPTANCE acceptance = 53; - string last_message_hash = 54; - cacti.satp.v02.common.TransferClaimsFormat transfer_claims_format = 55; + cacti.satp.v02.common.TransferClaims transfer_init_claims = 30; + string proposed_transfer_init_claims = 31; + cacti.satp.v02.common.SignatureAlgorithm signature_algorithm = 32; + cacti.satp.v02.common.LockType lock_type = 33; + uint64 lock_expiration_time = 34; + cacti.satp.v02.common.Permissions permissions = 35; + string developer_urn = 36; + cacti.satp.v02.common.CredentialProfile credential_profile = 37; + cacti.satp.v02.common.SubsequentCalls subsequent_calls = 38; + repeated cacti.satp.v02.common.History history = 39; + bool multiple_claims_allowed = 40; + bool multiple_cancels_allowed = 41; + string last_message_received_timestamp = 42; + MessageStagesTimestamps processed_timestamps = 43; + MessageStagesTimestamps received_timestamps = 44; + cacti.satp.v02.common.LockAssertionClaim lock_assertion_claim = 45; + cacti.satp.v02.common.LockAssertionClaimFormat lock_assertion_claim_format = 46; + cacti.satp.v02.common.MintAssertionClaim mint_assertion_claim = 47; + cacti.satp.v02.common.MintAssertionClaimFormat mint_assertion_claim_format = 48; + cacti.satp.v02.common.BurnAssertionClaim burn_assertion_claim = 49; + cacti.satp.v02.common.BurnAssertionClaimFormat burn_assertion_claim_format = 50; + cacti.satp.v02.common.AssignmentAssertionClaim assignment_assertion_claim = 51; + cacti.satp.v02.common.AssignmentAssertionClaimFormat assignment_assertion_claim_format = 52; + bool completed = 53; + ACCEPTANCE acceptance = 54; + string last_message_hash = 55; + cacti.satp.v02.common.TransferClaimsFormat transfer_claims_format = 56; + string client_transfer_number = 57; + string server_transfer_number = 58; + string lock_assertion_expiration = 59; + cacti.satp.v02.common.AssetProfile asset_profile = 60; } - message MessageStagesHashes { Stage1Hashes stage1 = 1; Stage2Hashes stage2 = 2; diff --git a/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/stage_1.proto b/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/stage_1.proto index 5b7aa8493e..1423e41242 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/stage_1.proto +++ b/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/stage_1.proto @@ -28,6 +28,7 @@ message TransferCommenceRequestMessage { message TransferCommenceResponseMessage { cacti.satp.v02.common.CommonSatp common = 1; + string server_transfer_number = 2; } service SatpStage1Service { diff --git a/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/stage_2.proto b/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/stage_2.proto index 27863c71c1..8e946b4b91 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/stage_2.proto +++ b/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/stage_2.proto @@ -9,7 +9,7 @@ import "cacti/satp/v02/common/message.proto"; message LockAssertionRequestMessage { cacti.satp.v02.common.CommonSatp common = 1; cacti.satp.v02.common.LockAssertionClaim lock_assertion_claim = 2; - cacti.satp.v02.common.LockAssertionFormat lock_assertion_format = 3; + cacti.satp.v02.common.LockAssertionClaimFormat lock_assertion_claim_format = 3; string lock_assertion_expiration = 4; string client_transfer_number = 5; string client_signature = 6; diff --git a/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/stage_3.proto b/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/stage_3.proto index 78edd2f1b3..11ff12313a 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/stage_3.proto +++ b/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/stage_3.proto @@ -13,8 +13,8 @@ message CommitPreparationRequestMessage { message CommitReadyResponseMessage { cacti.satp.v02.common.CommonSatp common = 1; - cacti.satp.v02.common.MintAssertionClaims mint_assertion_claims = 2; - cacti.satp.v02.common.MintAssertionClaimsFormat mint_assertion_claims_format = 3; + cacti.satp.v02.common.MintAssertionClaim mint_assertion_claim = 2; + cacti.satp.v02.common.MintAssertionClaimFormat mint_assertion_claim_format = 3; string server_transfer_number = 4; string server_signature = 5; } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/blo/dispatcher.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/blo/dispatcher.ts index 7a146527d2..5299cb2b9d 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/blo/dispatcher.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/blo/dispatcher.ts @@ -20,6 +20,7 @@ import { import { ExecuteGetStatus } from "./admin/get-status-handler-service"; import { ISATPManagerOptions, SATPManager } from "../gol/satp-manager"; import { GatewayOrchestrator } from "../gol/gateway-orchestrator"; +import { SATPBridgesManager } from "../gol/satp-bridges-manager"; export interface BLODispatcherOptions { logger: Logger; @@ -27,6 +28,7 @@ export interface BLODispatcherOptions { instanceId: string; orchestrator: GatewayOrchestrator; signer: JsObjectSigner; + bridgesManager: SATPBridgesManager; } export class BLODispatcher { @@ -36,6 +38,7 @@ export class BLODispatcher { private readonly instanceId: string; private manager: SATPManager; private orchestrator: GatewayOrchestrator; + private bridgeManager: SATPBridgesManager; constructor(public readonly options: BLODispatcherOptions) { const fnTag = `${BLODispatcher.CLASS_NAME}#constructor()`; @@ -50,11 +53,14 @@ export class BLODispatcher { const signer = options.signer; const ourGateway = this.orchestrator.ourGateway; + this.bridgeManager = options.bridgesManager; + const SATPManagerOpts: ISATPManagerOptions = { logLevel: "DEBUG", instanceId: ourGateway!.id, signer: signer, supportedDLTs: this.orchestrator.supportedDLTs, + bridgeManager: this.bridgeManager, }; this.manager = new SATPManager(SATPManagerOpts); diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/sender-satp-protocol.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/sender-satp-protocol.ts new file mode 100644 index 0000000000..62b6f2fb2b --- /dev/null +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/sender-satp-protocol.ts @@ -0,0 +1,169 @@ +import { createPromiseClient } from "@connectrpc/connect"; +import { + LogLevelDesc, + Logger, + LoggerProvider, +} from "@hyperledger/cactus-common"; +import { SatpStage1Service } from "../generated/proto/cacti/satp/v02/stage_1_connect"; +import { createConnectTransport } from "@connectrpc/connect-node"; +import { SatpStage2Service } from "../generated/proto/cacti/satp/v02/stage_2_connect"; +import { SatpStage3Service } from "../generated/proto/cacti/satp/v02/stage_3_connect"; +import { SATPManager } from "../gol/satp-manager"; +import { SATPSession } from "./satp-session"; +import { SATPHandler } from "../types/satp-protocol"; +import { Stage1SATPHandler } from "./stage-handlers/stage1-handler"; +import { Stage2SATPHandler } from "./stage-handlers/stage2-handler"; +import { Stage3SATPHandler } from "./stage-handlers/stage3-handler"; + +export interface ISenderSATPProtocolOptions { + logLevel?: LogLevelDesc; + serverPath: string; + sessionId: string; + satpManager: SATPManager; +} + +export interface SATPTransferRequest { + sessionId: string; +} + +export class SenderSATPProtocol { + public static readonly CLASS_NAME = "SenderSATPProtocol"; + + private satpManager: SATPManager; + + readonly log: Logger; + constructor(private config: ISenderSATPProtocolOptions) { + this.log = LoggerProvider.getOrCreate({ + label: SenderSATPProtocol.CLASS_NAME, + level: config.logLevel || "INFO", + }); + this.satpManager = config.satpManager; + } + + public async initiateTransfer(session: SATPSession): Promise { + this.log.info(`Initiating Transfer`); + this.log.info(`Session: ${JSON.stringify(session)}`); + + if (!session) { + throw new Error(`Session with id ${this.config.sessionId} not found`); + } + + const transport = createConnectTransport({ + baseUrl: this.config.serverPath, + httpVersion: "1.1", + }); + + const handlers = this.satpManager.getSATPHandlers( + session.getSessionData().id, + ); + + if (!handlers) { + throw new Error( + `No handlers found for session ${session.getSessionData().id}`, + ); + } + + const satpHandlers: Map = handlers; + + const clientSatpStage1 = createPromiseClient(SatpStage1Service, transport); + const clientSatpStage2 = createPromiseClient(SatpStage2Service, transport); + const clientSatpStage3 = createPromiseClient(SatpStage3Service, transport); + + const requestTransferProposal = await ( + satpHandlers.get("Stage1SATPHandler") as Stage1SATPHandler + ).TransferProposalRequest(); + + if (!requestTransferProposal) { + throw new Error(`Failed to create TransferProposalRequest`); + } + + const responseTransferProposal = await clientSatpStage1.transferProposal( + requestTransferProposal, + ); + + this.log.info( + `responseTransferProposal: ${JSON.stringify(responseTransferProposal)}`, + ); + + const requestTransferCommence = await ( + satpHandlers.get("Stage1SATPHandler") as Stage1SATPHandler + ).TransferCommenceRequest(responseTransferProposal); + + if (!requestTransferCommence) { + throw new Error(`Failed to create TransferCommenceRequest`); + } + + const responseTransferCommence = await clientSatpStage1.transferCommence( + requestTransferCommence, + ); + + this.log.info( + `responseTransferCommence: ${JSON.stringify(responseTransferCommence)}`, + ); + + this.log.info(`Stage 1 completed`); + + const requestLockAssertion = await ( + satpHandlers.get("Stage2SATPHandler") as Stage2SATPHandler + ).LockAssertionRequest(responseTransferCommence); + + if (!requestLockAssertion) { + throw new Error(`Failed to create LockAssertionRequest`); + } + + const responseLockAssertion = + await clientSatpStage2.lockAssertion(requestLockAssertion); + + this.log.info( + `responseLockAssertion: ${JSON.stringify(responseLockAssertion)}`, + ); + + this.log.info(`Stage 2 completed`); + + const requestCommitPreparation = await ( + satpHandlers.get("Stage3SATPHandler") as Stage3SATPHandler + ).CommitPreparationRequest(responseLockAssertion); + + if (!requestCommitPreparation) { + throw new Error(`Failed to create CommitPreparationRequest`); + } + + const responseCommitPreparation = await clientSatpStage3.commitPreparation( + requestCommitPreparation, + ); + this.log.info( + `responseCommitPreparation: ${JSON.stringify(responseCommitPreparation)}`, + ); + + const requestCommitFinalAssertion = await ( + satpHandlers.get("Stage3SATPHandler") as Stage3SATPHandler + ).CommitFinalAssertionRequest(responseLockAssertion); + + if (!requestCommitFinalAssertion) { + throw new Error(`Failed to create CommitFinalAssertionRequest`); + } + + const responseCommitFinalAssertion = + await clientSatpStage3.commitFinalAssertion(requestCommitFinalAssertion); + this.log.info( + `responseCommitFinalAssertion: ${JSON.stringify(responseCommitFinalAssertion)}`, + ); + + const RequestTransferComplete = await ( + satpHandlers.get("Stage3SATPHandler") as Stage3SATPHandler + ).TransferCompleteRequest(responseCommitFinalAssertion); + + if (!RequestTransferComplete) { + throw new Error(`Failed to create TransferCompleteRequest`); + } + + const responseTransferComplete = await clientSatpStage3.transferComplete( + RequestTransferComplete, + ); + this.log.info( + `responseTransferComplete: ${JSON.stringify(responseTransferComplete)}`, + ); + + this.log.info(`Stage 3 completed`); + } +} diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage1-handler.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage1-handler.ts index 942acd3ff9..884b514f36 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage1-handler.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage1-handler.ts @@ -34,11 +34,23 @@ export class Stage1SATPHandler implements SATPHandler { return Stage1SATPHandler.CLASS_NAME; } - async TransferProposalImplementation( + getSessionId(): string { + return this.session.getSessionData().id; + } + + public get Log(): Logger { + return this.logger; + } + + private async TransferProposalImplementation( req: TransferProposalRequestMessage, + context: HandlerContext, ): Promise { + const stepTag = `TransferProposalImplementation()`; + const fnTag = `${this.getHandlerIdentifier()}#${stepTag}`; try { - console.log("Received TransferProposalRequest", req); + this.Log.debug(`${fnTag}, Transfer Proposal...`); + this.Log.debug(`${fnTag}, Request: ${req}, Context: ${context}`); const sessionData = await this.serverService.checkTransferProposalRequestMessage( req, @@ -49,21 +61,27 @@ export class Stage1SATPHandler implements SATPHandler { req, this.session, ); - console.log("message", message); - console.log("Returning response", sessionData); - const response = new TransferProposalReceiptMessage(); - return response; + this.Log.debug(`${fnTag}, Returning response: ${message}`); + this.Log.debug(`${fnTag}, Session Data: ${sessionData}`); + + if (!message) { + throw new Error(`${fnTag}, Failed to create TransferProposalReceipt`); + } + return message; } catch (error) { - console.error("Error handling TransferProposalRequest:", error); - throw new Error("Failed to process TransferProposalRequest"); + throw new Error(`${fnTag}, Failed to process TransferProposal ${error}`); } } - async TransferCommenceImplementation( + private async TransferCommenceImplementation( req: TransferCommenceRequestMessage, + context: HandlerContext, ): Promise { + const stepTag = `TransferProposalImplementation()`; + const fnTag = `${this.getHandlerIdentifier()}#${stepTag}`; try { - console.log("Received TransferCommenceRequest", req); + this.Log.debug(`${fnTag}, Transfer Commence...`); + this.Log.debug(`${fnTag}, Request: ${req}, Context: ${context}`); const sessionData = await this.serverService.checkTransferCommenceRequestMessage( req, @@ -73,13 +91,17 @@ export class Stage1SATPHandler implements SATPHandler { req, this.session, ); - console.log("Returning response", message); - console.log("Returning response", sessionData); - const response = new TransferProposalReceiptMessage(); - return response; + this.Log.debug(`${fnTag}, Returning response: ${message}`); + this.Log.debug(`${fnTag}, Session Data: ${sessionData}`); + + if (!message) { + throw new Error(`${fnTag}, Failed to create TransferCommenceResponse`); + } + return message; } catch (error) { - console.error("Error handling TransferCommenceRequest:", error); - throw new Error("Failed to process TransferCommenceRequest"); + throw new Error( + `${fnTag}, Failed to process TransferCommenceRequest ${error}`, + ); } } @@ -89,4 +111,60 @@ export class Stage1SATPHandler implements SATPHandler { transferCommence: this.TransferCommenceImplementation, }); } + + //client side + public async TransferProposalRequest(): Promise { + const stepTag = `TransferProposalRequest()`; + const fnTag = `${this.getHandlerIdentifier()}#${stepTag}`; + try { + this.Log.debug(`${fnTag}, Transfer Proposal Request...`); + const requestTransferProposal = + await this.clientService.transferProposalRequest( + this.session, + this.supportedDLTs, + ); + + if (!requestTransferProposal) { + throw new Error(`${fnTag}, Failed to create TransferProposalRequest`); + } + return requestTransferProposal; + } catch (error) { + throw new Error( + `${fnTag}, Failed to process TransferProposalRequest ${error}`, + ); + } + } + + //client side + public async TransferCommenceRequest( + response: TransferProposalReceiptMessage, + ): Promise { + const stepTag = `TransferProposalRequest()`; + const fnTag = `${this.getHandlerIdentifier()}#${stepTag}`; + try { + this.Log.debug(`${fnTag}, Transfer Commence Request...`); + this.Log.debug(`${fnTag}, Response: ${response}`); + + await this.clientService.checkTransferProposalReceiptMessage( + response, + this.session, + ); + + const requestTransferCommence = + await this.clientService.transferCommenceRequest( + response, + this.session, + ); + + if (!requestTransferCommence) { + throw new Error(`${fnTag}, Failed to create TransferCommenceRequest`); + } + + return requestTransferCommence; + } catch (error) { + throw new Error( + `${fnTag}, Failed to process TransferCommenceRequest ${error}`, + ); + } + } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage2-handler.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage2-handler.ts index 9159b4eef2..dcccccdd74 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage2-handler.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage2-handler.ts @@ -1,58 +1,110 @@ -/* import { ConnectRouter, HandlerContext } from "@connectrpc/connect"; import { SatpStage2Service } from "../../generated/proto/cacti/satp/v02/stage_2_connect"; -import { LockAssertionRequestMessage } from "../../generated/proto/cacti/satp/v02/stage_2_pb"; -import { SATPGateway } from "../../plugin-satp-hermes-gateway"; import { Stage2ServerService } from "../stage-services/server/stage2-server-service"; -import { TimestampType, saveTimestamp } from "../session-utils"; -import { MessageType } from "../../generated/proto/cacti/satp/v02/common/message_pb"; import { SATPSession } from "../satp-session"; -import { ServiceType } from "@bufbuild/protobuf"; import { SupportedChain } from "../types"; +import { SATPHandler, SATPHandlerOptions } from "../../types/satp-protocol"; +import { Logger, LoggerProvider } from "@hyperledger/cactus-common"; +import { + LockAssertionReceiptMessage, + LockAssertionRequestMessage, +} from "../../generated/proto/cacti/satp/v02/stage_2_pb"; +import { Stage2ClientService } from "../stage-services/client/stage2-client-service"; +import { TransferCommenceResponseMessage } from "../../generated/proto/cacti/satp/v02/stage_1_pb"; +export class Stage2SATPHandler implements SATPHandler { + public static readonly CLASS_NAME = "Stage2SATPHandler"; + private session: SATPSession; + private serverService: Stage2ServerService; + private clientService: Stage2ClientService; + private supportedDLTs: SupportedChain[]; + private logger: Logger; -export const Stage2Handler = - ( - session: SATPSession, - service: Stage2ServerService, - connectClients: ServiceType[], - supportedDLTs: SupportedChain[], - ) => - (router: ConnectRouter) => - router.service(SatpStage2Service, { - async lockAssertion( - req: LockAssertionRequestMessage, - context: HandlerContext, - ) { - console.log("Received LockAssertionRequest", req, context); - const recvTimestamp: string = Date.now().toString(); - - const sessionData = await service.checkLockAssertionRequestMessage( - req, - session, - ); + constructor(ops: SATPHandlerOptions) { + this.session = ops.session; + this.serverService = ops.serverService as Stage2ServerService; + this.clientService = ops.clientService as Stage2ClientService; + this.supportedDLTs = ops.supportedDLTs; + this.logger = LoggerProvider.getOrCreate(ops.loggerOptions); + this.logger.trace(`Initialized ${Stage2SATPHandler.CLASS_NAME}`); + } - saveTimestamp( - sessionData, - MessageType.LOCK_ASSERT, - TimestampType.RECEIVED, - recvTimestamp, - ); + public get Log(): Logger { + return this.logger; + } - const message = await service.lockAssertionResponse(req, session); + getHandlerIdentifier(): string { + return Stage2SATPHandler.CLASS_NAME; + } - if (!message) { - throw new Error("No message returned from lockAssertionResponse"); - } + getSessionId(): string { + return this.session.getSessionData().id; + } - saveTimestamp( - sessionData, - MessageType.ASSERTION_RECEIPT, - TimestampType.PROCESSED, + async LockAssertionImplementation( + req: LockAssertionRequestMessage, + context: HandlerContext, + ): Promise { + const stepTag = `LockAssertionImplementation()`; + const fnTag = `${this.getHandlerIdentifier()}#${stepTag}`; + try { + this.Log.debug(`${fnTag}, Lock Assertion...`); + this.Log.debug(`${fnTag}, Request: ${req}, Context: ${context}`); + const sessionData = + await this.serverService.checkLockAssertionRequestMessage( + req, + this.session, ); + const message = await this.serverService.lockAssertionResponse( + req, + this.session, + ); + this.Log.debug(`${fnTag}, Returning response: ${message}`); + this.Log.debug(`${fnTag}, Session Data: ${sessionData}`); - console.log("Returning response", message); + if (!message) { + throw new Error(`${fnTag}, Failed to create LockAssertionReceipt`); + } + return message; + } catch (error) { + throw new Error(`${fnTag}, Failed to process LockAssertion ${error}`); + } + } - return message; - }, + setupRouter(router: ConnectRouter): void { + router.service(SatpStage2Service, { + lockAssertion: this.LockAssertionImplementation, }); -*/ + } + + //client side + async LockAssertionRequest( + response: TransferCommenceResponseMessage, + ): Promise { + const stepTag = `LockAssertionRequest()`; + const fnTag = `${this.getHandlerIdentifier()}#${stepTag}`; + try { + this.Log.debug(`${fnTag}, Lock Assertion Request Message...`); + this.Log.debug(`${fnTag}, Response: ${response}`); + await this.clientService.checkTransferCommenceResponseMessage( + response, + this.session, + ); + + await this.clientService.lockAsset(this.session); + + const request = await this.clientService.lockAssertionRequest( + response, + this.session, + ); + + if (!request) { + throw new Error(`${fnTag}, Failed to create LockAssertionRequest`); + } + return request; + } catch (error) { + throw new Error( + `${fnTag}, Failed to process LockAssertionRequest ${error}`, + ); + } + } +} diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage3-handler.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage3-handler.ts index d967e99a33..c53f2b1941 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage3-handler.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage3-handler.ts @@ -1,118 +1,237 @@ -/* import { ConnectRouter, HandlerContext } from "@connectrpc/connect"; import { SatpStage3Service } from "../../generated/proto/cacti/satp/v02/stage_3_connect"; import { + CommitFinalAcknowledgementReceiptResponseMessage, CommitFinalAssertionRequestMessage, CommitPreparationRequestMessage, + CommitReadyResponseMessage, TransferCompleteRequestMessage, } from "../../generated/proto/cacti/satp/v02/stage_3_pb"; -import { Empty, ServiceType } from "@bufbuild/protobuf"; import { Stage3ServerService } from "../stage-services/server/stage3-server-service"; -import { SATPGateway } from "../../plugin-satp-hermes-gateway"; -import { TimestampType, saveTimestamp } from "../session-utils"; -import { MessageType } from "../../generated/proto/cacti/satp/v02/common/message_pb"; import { SATPSession } from "../satp-session"; import { SupportedChain } from "../types"; - -export const Stage3Handler = - ( - session: SATPSession, - service: Stage3ServerService, - connectClients: ServiceType[], - supportedDLTs: SupportedChain[], - ) => - (router: ConnectRouter) => - router.service(SatpStage3Service, { - async commitPreparation( - req: CommitPreparationRequestMessage, - context: HandlerContext, - ) { - console.log("Received CommitPreparationRequest", req, context); - const recvTimestamp: string = Date.now().toString(); - - const sessionData = await service.checkCommitPreparationRequestMessage( +import { SATPHandler, SATPHandlerOptions } from "../../types/satp-protocol"; +import { Logger, LoggerProvider } from "@hyperledger/cactus-common"; +import { Empty } from "@bufbuild/protobuf"; +import { Stage3ClientService } from "../stage-services/client/stage3-client-service"; + +export class Stage3SATPHandler implements SATPHandler { + public static readonly CLASS_NAME = "Stage3SATPHandler"; + private session: SATPSession; + private clientService: Stage3ClientService; + private serverService: Stage3ServerService; + private supportedDLTs: SupportedChain[]; + private logger: Logger; + + constructor(ops: SATPHandlerOptions) { + this.session = ops.session; + this.serverService = ops.serverService as Stage3ServerService; + this.clientService = ops.clientService as Stage3ClientService; + this.supportedDLTs = ops.supportedDLTs; + this.logger = LoggerProvider.getOrCreate(ops.loggerOptions); + this.logger.trace(`Initialized ${Stage3SATPHandler.CLASS_NAME}`); + } + + getHandlerIdentifier(): string { + return Stage3SATPHandler.CLASS_NAME; + } + + getSessionId(): string { + return this.session.getSessionData().id; + } + + public get Log(): Logger { + return this.logger; + } + + async CommitPreparationImplementation( + req: CommitPreparationRequestMessage, + context: HandlerContext, + ): Promise { + const stepTag = `CommitPreparationImplementation()`; + const fnTag = `${this.getHandlerIdentifier()}#${stepTag}`; + try { + this.Log.debug(`${fnTag}, Commit Preparation...`); + this.Log.debug(`${fnTag}, Request: ${req}, Context: ${context}`); + const sessionData = + await this.serverService.checkCommitPreparationRequestMessage( req, - session, + this.session, ); - saveTimestamp( - sessionData, - MessageType.COMMIT_PREPARE, - TimestampType.RECEIVED, - recvTimestamp, - ); - - const message = await service.commitReady(req, session); - - if (!message) { - throw new Error("No message returned from commitPreparation"); - } - - saveTimestamp( - sessionData, - MessageType.COMMIT_READY, - TimestampType.PROCESSED, - ); - - console.log("Returning response", message); - - return message; - }, - async commitFinalAssertion( - req: CommitFinalAssertionRequestMessage, - context: HandlerContext, - ) { - console.log("Received CommitFinalAssertionRequest", req, context); - const recvTimestamp: string = Date.now().toString(); - - const sessionData = - await service.checkCommitFinalAssertionRequestMessage(req, session); - - saveTimestamp( - sessionData, - MessageType.COMMIT_FINAL, - TimestampType.RECEIVED, - recvTimestamp, - ); - - const message = await service.commitFinalAcknowledgementReceiptResponse( + await this.serverService.mintAsset(this.session); + + const message = await this.serverService.commitReady(req, this.session); + + this.Log.debug(`${fnTag}, Returning response: ${message}`); + this.Log.debug(`${fnTag}, Session Data: ${sessionData}`); + + const response = new CommitReadyResponseMessage(); + return response; + } catch (error) { + throw new Error( + `${fnTag}, Failed to process CommitPreparationRequest ${error}`, + ); + } + } + + async CommitFinalAssertionImplementation( + req: CommitFinalAssertionRequestMessage, + context: HandlerContext, + ): Promise { + const stepTag = `CommitFinalAssertionImplementation()`; + const fnTag = `${this.getHandlerIdentifier()}#${stepTag}`; + try { + this.Log.debug(`${fnTag}, Commit Final Assertion...`); + this.Log.debug(`${fnTag}, Request: ${req}, Context: ${context}`); + const sessionData = + await this.serverService.checkCommitFinalAssertionRequestMessage( req, - session, + this.session, ); - if (!message) { - throw new Error("No message returned from commitFinalAssertion"); - } + await this.serverService.assignAsset(this.session); - saveTimestamp( - sessionData, - MessageType.ACK_COMMIT_FINAL, - TimestampType.PROCESSED, + const message = + await this.serverService.commitFinalAcknowledgementReceiptResponse( + req, + this.session, ); - - return message; - }, - async transferComplete( - req: TransferCompleteRequestMessage, - context: HandlerContext, - ) { - console.log("Received TransferCompleteRequest", req, context); - const recvTimestamp: string = Date.now().toString(); - - const sessionData = await service.checkTransferCompleteRequestMessage( + this.Log.debug(`${fnTag}, Returning response: ${message}`); + this.Log.debug(`${fnTag}, Session Data: ${sessionData}`); + + const response = new CommitFinalAcknowledgementReceiptResponseMessage(); + return response; + } catch (error) { + throw new Error( + `${fnTag}, Failed to process CommitFinalAssertionRequest ${error}`, + ); + } + } + + async TransferCompleteImplementation( + req: TransferCompleteRequestMessage, + context: HandlerContext, + ): Promise { + const stepTag = `CommitFinalAssertionImplementation()`; + const fnTag = `${this.getHandlerIdentifier()}#${stepTag}`; + try { + this.Log.debug(`${fnTag}, Transfer Complete...`); + this.Log.debug(`${fnTag}, Request: ${req}, Context: ${context}`); + const sessionData = + await this.serverService.checkTransferCompleteRequestMessage( req, - session, + this.session, ); - saveTimestamp( - sessionData, - MessageType.COMMIT_TRANSFER_COMPLETE, - TimestampType.RECEIVED, - recvTimestamp, - ); + this.Log.debug(`${fnTag}, Session Data: ${sessionData}`); + + return new Empty({}); + } catch (error) { + throw new Error( + `${fnTag}, Failed to process TransferCompleteRequest ${error}`, + ); + } + } - console.log("Returning empty response"); - return new Empty({}); - }, + setupRouter(router: ConnectRouter): void { + router.service(SatpStage3Service, { + commitPreparation: this.CommitPreparationImplementation, + commitFinalAssertion: this.CommitFinalAssertionImplementation, + transferComplete: this.TransferCompleteImplementation, }); -*/ + } + + //client side + + async CommitPreparationRequest( + response: CommitReadyResponseMessage, + ): Promise { + const stepTag = `CommitPreparationRequest()`; + const fnTag = `${this.getHandlerIdentifier()}#${stepTag}`; + try { + this.Log.debug(`${fnTag}, Commit Preparation Request...`); + this.Log.debug(`${fnTag}, Response: ${response}`); + await this.clientService.checkCommitReadyResponseMessage( + response, + this.session, + ); + + const request = await this.clientService.commitPreparation( + response, + this.session, + ); + + if (!request) { + throw new Error(`${fnTag}, Failed to create TransferProposalRequest`); + } + return request; + } catch (error) { + throw new Error( + `${fnTag}, Failed to process commitPreparationRequest ${error}`, + ); + } + } + + async CommitFinalAssertionRequest( + response: CommitReadyResponseMessage, + ): Promise { + const stepTag = `CommitFinalAssertionRequest()`; + const fnTag = `${this.getHandlerIdentifier()}#${stepTag}`; + try { + this.Log.debug(`${fnTag}, Commit Preparation Request...`); + this.Log.debug(`${fnTag}, Response: ${response}`); + await this.clientService.checkCommitReadyResponseMessage( + response, + this.session, + ); + + await this.clientService.burnAsset(this.session); + + const request = await this.clientService.commitFinalAssertion( + response, + this.session, + ); + + if (!request) { + throw new Error( + `${fnTag}, Failed to create CommitFinalAssertionRequest`, + ); + } + return request; + } catch (error) { + throw new Error( + `${fnTag}, Failed to process CommitFinalAssertionRequest ${error}`, + ); + } + } + + async TransferCompleteRequest( + response: CommitFinalAcknowledgementReceiptResponseMessage, + ): Promise { + const stepTag = `TransferCompleteRequest()`; + const fnTag = `${this.getHandlerIdentifier()}#${stepTag}`; + try { + this.Log.debug(`${fnTag}, Transfer Complete Request...`); + this.Log.debug(`${fnTag}, Response: ${response}`); + await this.clientService.checkCommitFinalAcknowledgementReceiptResponseMessage( + response, + this.session, + ); + + const request = await this.clientService.transferComplete( + response, + this.session, + ); + + if (!request) { + throw new Error(`${fnTag}, Failed to create TransferCompleteRequest`); + } + return request; + } catch (error) { + throw new Error( + `${fnTag}, Failed to process TransferCompleteRequest ${error}`, + ); + } + } +} 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 1d8b10cf26..239b92132b 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 @@ -49,12 +49,12 @@ export class Stage1ClientService extends SATPService { } async transferProposalRequest( - sessionID: string, session: SATPSession, supportedDLTs: SupportedChain[], ): Promise { const stepTag = `transferProposalRequest()`; const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, transferProposalRequest...`); const sessionData = session.getSessionData(); @@ -209,6 +209,7 @@ export class Stage1ClientService extends SATPService { ): Promise { const stepTag = `transferCommenceRequest()`; const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, transferCommenceRequest...`); if (!response || !response.common) { throw new Error("Response or response.common is undefined"); @@ -281,6 +282,7 @@ export class Stage1ClientService extends SATPService { ): Promise { const stepTag = `checkTransferProposalReceiptMessage()`; const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, checkTransferProposalReceiptMessage...`); if (response.common == undefined) { throw new Error(`${fnTag}, message has no satp common body`); } @@ -386,13 +388,13 @@ export class Stage1ClientService extends SATPService { return true; } else { this.Log.info( - `TransferProposalReceipt proposedTransferClaims were rejected`, + `${fnTag}, TransferProposalReceipt proposedTransferClaims were rejected`, ); sessionData.completed = true; return false; } } - this.Log.info(`TransferProposalReceipt passed all checks.`); + this.Log.info(`${fnTag}, TransferProposalReceipt passed all checks.`); return true; } 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 9cbdce756e..9a9887506d 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 @@ -1,233 +1,278 @@ -// import { -// JsObjectSigner, -// Logger, -// LoggerProvider, -// } from "@hyperledger/cactus-common"; -// import { TransferCommenceResponseMessage } from "../../../generated/proto/cacti/satp/v02/stage_1_pb"; -// import { SATPGateway } from "../../../plugin-satp-hermes-gateway"; -// import { SATP_VERSION } from "../../constants"; -// import { -// CommonSatp, -// MessageType, -// } from "../../../generated/proto/cacti/satp/v02/common/message_pb"; -// import { LockAssertionRequestMessage } from "../../../generated/proto/cacti/satp/v02/stage_2_pb"; -// import { -// bufArray2HexStr, -// getHash, -// sign, -// storeLog, -// verifySignature, -// } from "../../../gateway-utils"; -// import { getMessageHash, saveHash, saveSignature } from "../../session-utils"; -// import { SATPSession } from "../../../core/satp-session"; -// import { -// SATPService, -// ISATPClientServiceOptions, -// SATPServiceType, -// } from "../../../types/satp-protocol"; - -// export class Stage2ClientService implements SATPService { -// public static readonly CLASS_NAME = "client-service"; -// public static readonly SATP_STAGE = "stage-2"; -// public static readonly SATP_SERVICE_TYPE = SATPServiceType.Client; - -// private _log: Logger; -// private signer: JsObjectSigner; - -// constructor(ops: ISATPClientServiceOptions) { -// const level = ops.logLevel || "INFO"; -// const label = this.getServiceIdentifier(); -// this._log = LoggerProvider.getOrCreate({ level, label }); -// this.signer = ops.signer; -// } - -// public get className(): string { -// return Stage2ClientService.CLASS_NAME; -// } - -// public get stage(): string { -// return Stage2ClientService.SATP_STAGE; -// } - -// public get log(): Logger { -// return this._log; -// } - -// public get serviceType(): SATPServiceType { -// return SATPServiceType.Client; -// } - -// public getServiceIdentifier(): string { -// return `${this.className}#${this.serviceType}`; -// } - -// async lockAssertionRequest( -// response: TransferCommenceResponseMessage, -// session: SATPSession, -// ): Promise { -// const fnTag = `${this.className}#lockAssertionRequest()`; -// if (response.common == undefined) { -// throw new Error(`${fnTag}, message common body is missing`); -// } - -// const sessionData = session.getSessionData(); - -// if (sessionData == undefined) { -// throw new Error( -// `${fnTag}, session data not found for session id ${response.common.sessionId}`, -// ); -// } - -// saveHash(sessionData, MessageType.COMMIT_READY, getHash(response)); - -// const commonBody = new CommonSatp(); -// commonBody.version = sessionData.version; -// commonBody.messageType = MessageType.LOCK_ASSERT; -// commonBody.sequenceNumber = sessionData.lastSequenceNumber + BigInt(1); - -// commonBody.hashPreviousMessage = getMessageHash( -// sessionData, -// MessageType.TRANSFER_COMMENCE_RESPONSE, -// ); - -// commonBody.sessionId = response.common.sessionId; -// commonBody.clientGatewayPubkey = sessionData.clientGatewayPubkey; -// commonBody.serverGatewayPubkey = sessionData.serverGatewayPubkey; - -// sessionData.lastSequenceNumber = commonBody.sequenceNumber; - -// const lockAssertionRequestMessage = new LockAssertionRequestMessage(); -// lockAssertionRequestMessage.common = commonBody; - -// lockAssertionRequestMessage.lockAssertionClaim = -// sessionData.lockAssertionClaim; -// lockAssertionRequestMessage.lockAssertionFormat = -// sessionData.lockAssertionFormat; - -// const messageSignature = bufArray2HexStr( -// sign(this.signer, JSON.stringify(lockAssertionRequestMessage)), -// ); - -// lockAssertionRequestMessage.common.signature = messageSignature; - -// saveSignature(sessionData, MessageType.LOCK_ASSERT, messageSignature); - -// saveHash( -// sessionData, -// MessageType.LOCK_ASSERT, -// getHash(lockAssertionRequestMessage), -// ); - -// /* -// await storeLog(gateway, { -// sessionID: sessionData.id, -// type: "lockAssertionRequest", -// operation: "lock", -// data: JSON.stringify(sessionData), -// }); -// */ -// this.log.info(`${fnTag}, sending LockAssertionMessage...`); - -// return lockAssertionRequestMessage; -// } - -// checkTransferCommenceResponseMessage( -// response: TransferCommenceResponseMessage, -// session: SATPSession, -// ): void { -// const fnTag = `${this.className}#lockAssertionRequestMessage()`; - -// if ( -// response.common == undefined || -// response.common.version == undefined || -// response.common.messageType == undefined || -// response.common.sessionId == undefined || -// // request.common.transferContextId == undefined || -// response.common.sequenceNumber == undefined || -// response.common.resourceUrl == undefined || -// // request.common.actionResponse == undefined || -// // request.common.payloadProfile == undefined || -// // request.common.applicationProfile == undefined || -// response.common.signature == undefined || -// response.common.clientGatewayPubkey == undefined || -// response.common.serverGatewayPubkey == undefined -// ) { -// throw new Error( -// `${fnTag}, message satp common body is missing or is missing required fields`, -// ); -// } - -// if (response.common.version != SATP_VERSION) { -// throw new Error(`${fnTag}, unsupported SATP version`); -// } - -// const sessionData = session.getSessionData(); - -// if (sessionData == undefined) { -// throw new Error( -// `${fnTag}, session data not found for session id ${response.common.sessionId}`, -// ); -// } - -// if ( -// sessionData.serverGatewayPubkey == undefined || -// sessionData.lastSequenceNumber == undefined -// ) { -// throw new Error(`${fnTag}, session data was not load correctly`); -// } - -// if ( -// response.common.serverGatewayPubkey != sessionData.serverGatewayPubkey -// ) { -// throw new Error( -// `${fnTag}, TransferCommenceResponse serverIdentity public key does not match the one that was sent`, -// ); -// } - -// if ( -// response.common.clientGatewayPubkey != sessionData.clientGatewayPubkey -// ) { -// throw new Error( -// `${fnTag}, TransferCommenceResponse clientIdentity public key does not match the one that was sent`, -// ); -// } - -// if ( -// !verifySignature( -// this.signer, -// response.common, -// response.common.serverGatewayPubkey, -// ) -// ) { -// throw new Error( -// `${fnTag}, TransferCommenceResponse message signature verification failed`, -// ); -// } - -// if (response.common.messageType != MessageType.TRANSFER_COMMENCE_RESPONSE) { -// throw new Error( -// `${fnTag}, wrong message type for TransferCommenceResponse `, -// ); -// } - -// if ( -// response.common.sequenceNumber != -// sessionData.lastSequenceNumber + BigInt(1) -// ) { -// throw new Error( -// `${fnTag}, TransferCommenceResponse sequence number is wrong`, -// ); -// } - -// if ( -// response.common.hashPreviousMessage != -// getMessageHash(sessionData, MessageType.TRANSFER_COMMENCE_RESPONSE) -// ) { -// throw new Error( -// `${fnTag}, TransferCommenceResponse previous message hash does not match the one that was sent`, -// ); -// } - -// this.log.info(`TransferCommenceResponse passed all checks.`); -// } -// } +import { TransferCommenceResponseMessage } from "../../../generated/proto/cacti/satp/v02/stage_1_pb"; +import { SATP_VERSION } from "../../constants"; +import { + CommonSatp, + LockAssertionClaim, + MessageType, +} from "../../../generated/proto/cacti/satp/v02/common/message_pb"; +import { LockAssertionRequestMessage } from "../../../generated/proto/cacti/satp/v02/stage_2_pb"; +import { + bufArray2HexStr, + getHash, + sign, + verifySignature, +} from "../../../gateway-utils"; +import { getMessageHash, saveHash, saveSignature } from "../../session-utils"; +import { SATPSession } from "../../../core/satp-session"; +import { + SATPService, + ISATPClientServiceOptions, + SATPServiceType, +} from "../satp-service"; +import { ISATPServiceOptions } from "../satp-service"; +import { SATPBridgesManager } from "../../../gol/satp-bridges-manager"; + +export class Stage2ClientService extends SATPService { + public static readonly SATP_STAGE = "2"; + public static readonly SERVICE_TYPE = SATPServiceType.Client; + + private bridgeManager: SATPBridgesManager; + + constructor(ops: ISATPClientServiceOptions) { + const commonOptions: ISATPServiceOptions = { + stage: Stage2ClientService.SATP_STAGE, + loggerOptions: ops.loggerOptions, + serviceName: ops.serviceName, + signer: ops.signer, + serviceType: Stage2ClientService.SERVICE_TYPE, + bridgeManager: ops.bridgeManager, + }; + super(commonOptions); + + if (ops.bridgeManager == undefined) { + throw new Error( + `${this.getServiceIdentifier()}#constructor(), bridgeManager is missing`, + ); + } + this.bridgeManager = ops.bridgeManager; + } + + async lockAssertionRequest( + response: TransferCommenceResponseMessage, + session: SATPSession, + ): Promise { + const stepTag = `lockAssertionRequest()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, lockAssertionRequest...`); + + if (response.common == undefined) { + throw new Error(`${fnTag}, message common body is missing`); + } + + const sessionData = session.getSessionData(); + + if (sessionData == undefined) { + throw new Error( + `${fnTag}, session data not found for session id ${response.common.sessionId}`, + ); + } + + saveHash(sessionData, MessageType.COMMIT_READY, getHash(response)); + + const commonBody = new CommonSatp(); + commonBody.version = sessionData.version; + commonBody.messageType = MessageType.LOCK_ASSERT; + commonBody.sequenceNumber = sessionData.lastSequenceNumber + BigInt(1); + + commonBody.hashPreviousMessage = getMessageHash( + sessionData, + MessageType.TRANSFER_COMMENCE_RESPONSE, + ); + + commonBody.sessionId = response.common.sessionId; + commonBody.clientGatewayPubkey = sessionData.clientGatewayPubkey; + commonBody.serverGatewayPubkey = sessionData.serverGatewayPubkey; + + sessionData.lastSequenceNumber = commonBody.sequenceNumber; + + const lockAssertionRequestMessage = new LockAssertionRequestMessage(); + lockAssertionRequestMessage.common = commonBody; + + lockAssertionRequestMessage.lockAssertionClaim = + sessionData.lockAssertionClaim; + lockAssertionRequestMessage.lockAssertionClaimFormat = + sessionData.lockAssertionClaimFormat; + + if (sessionData.transferContextId != undefined) { + lockAssertionRequestMessage.common.transferContextId = + sessionData.transferContextId; + } + if (sessionData.clientTransferNumber != undefined) { + lockAssertionRequestMessage.clientTransferNumber = + sessionData.clientTransferNumber; + } + + const messageSignature = bufArray2HexStr( + sign(this.Signer, JSON.stringify(lockAssertionRequestMessage)), + ); + + lockAssertionRequestMessage.common.signature = messageSignature; + + saveSignature(sessionData, MessageType.LOCK_ASSERT, messageSignature); + + saveHash( + sessionData, + MessageType.LOCK_ASSERT, + getHash(lockAssertionRequestMessage), + ); + + /* + await storeLog(gateway, { + sessionID: sessionData.id, + type: "lockAssertionRequest", + operation: "lock", + data: JSON.stringify(sessionData), + }); + */ + this.Log.info(`${fnTag}, sending LockAssertionMessage...`); + + return lockAssertionRequestMessage; + } + + checkTransferCommenceResponseMessage( + response: TransferCommenceResponseMessage, + session: SATPSession, + ): void { + const stepTag = `checkTransferCommenceResponseMessage()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, checkTransferCommenceResponseMessage...`); + + if ( + response.common == undefined || + response.common.version == undefined || + response.common.messageType == undefined || + response.common.sessionId == undefined || + response.common.sequenceNumber == undefined || + response.common.resourceUrl == undefined || + response.common.signature == undefined || + response.common.clientGatewayPubkey == undefined || + response.common.serverGatewayPubkey == undefined || + response.common.hashPreviousMessage == undefined + ) { + throw new Error( + `${fnTag}, message satp common body is missing or is missing required fields`, + ); + } + + if (response.common.version != SATP_VERSION) { + throw new Error(`${fnTag}, unsupported SATP version`); + } + + const sessionData = session.getSessionData(); + + if (sessionData == undefined) { + throw new Error( + `${fnTag}, session data not found for session id ${response.common.sessionId}`, + ); + } + + if ( + sessionData.serverGatewayPubkey == undefined || + sessionData.lastSequenceNumber == undefined + ) { + throw new Error(`${fnTag}, session data was not load correctly`); + } + + if ( + response.common.serverGatewayPubkey != sessionData.serverGatewayPubkey + ) { + throw new Error( + `${fnTag}, TransferCommenceResponse serverIdentity public key does not match the one that was sent`, + ); + } + + if ( + response.common.clientGatewayPubkey != sessionData.clientGatewayPubkey + ) { + throw new Error( + `${fnTag}, TransferCommenceResponse clientIdentity public key does not match the one that was sent`, + ); + } + + if ( + !verifySignature( + this.Signer, + response.common, + response.common.serverGatewayPubkey, + ) + ) { + throw new Error( + `${fnTag}, TransferCommenceResponse message signature verification failed`, + ); + } + + if (response.common.messageType != MessageType.TRANSFER_COMMENCE_RESPONSE) { + throw new Error( + `${fnTag}, wrong message type for TransferCommenceResponse `, + ); + } + + if ( + response.common.sequenceNumber != + sessionData.lastSequenceNumber + BigInt(1) + ) { + throw new Error( + `${fnTag}, TransferCommenceResponse sequence number is wrong`, + ); + } + + if ( + response.common.hashPreviousMessage != + getMessageHash(sessionData, MessageType.TRANSFER_COMMENCE_RESPONSE) + ) { + throw new Error( + `${fnTag}, TransferCommenceResponse previous message hash does not match the one that was sent`, + ); + } + + if ( + sessionData.transferContextId != undefined && + response.common.transferContextId != sessionData.transferContextId + ) { + throw new Error( + `${fnTag}, transferContextId does not match the one that was sent`, + ); + } + + if (response.serverTransferNumber != undefined) { + this.Log.info( + `${fnTag}, Optional variable loaded: serverTransferNumber...`, + ); + sessionData.serverTransferNumber = response.serverTransferNumber; + } + + this.Log.info(`${fnTag}, TransferCommenceResponse passed all checks.`); + } + + async lockAsset(session: SATPSession): Promise { + const stepTag = `lockAsset()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + try { + this.Log.info(`${fnTag}, Locking Asset...`); + const sessionData = session.getSessionData(); + const assetId = sessionData.transferInitClaims?.digitalAssetId; + const amount = sessionData.transferInitClaims?.amountFromOriginator; + + this.Log.debug(`${fnTag}, Lock Asset ID: ${assetId} amount: ${amount}`); + if (assetId == undefined) { + throw new Error(`${fnTag}, Asset ID is missing`); + } + + // const bridge = this.bridgeManager.getBridge( + // sessionData.senderGatewayNetworkId, + // ); + + // sessionData.lockAssertionClaim = new LockAssertionClaim(); + // sessionData.lockAssertionClaim.receipt = await bridge.lockAsset( + // assetId, + // Number(amount), + // ); + + // sessionData.lockAssertionClaim.signature = bufArray2HexStr( + // sign(this.Signer, sessionData.lockAssertionClaim.receipt), + // ); + } catch (error) { + throw new Error(`${fnTag}, Failed to process Lock Asset ${error}`); + } + } +} 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 e407e98d5e..8f07ceffa7 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 @@ -1,516 +1,666 @@ -// import { -// JsObjectSigner, -// Logger, -// LoggerProvider, -// } from "@hyperledger/cactus-common"; -// import { SATPGateway } from "../../../plugin-satp-hermes-gateway"; -// import { -// CommonSatp, -// MessageType, -// } from "../../../generated/proto/cacti/satp/v02/common/message_pb"; -// import { SATP_VERSION } from "../../constants"; -// import { -// CommitFinalAcknowledgementReceiptResponseMessage, -// CommitFinalAssertionRequestMessage, -// CommitPreparationRequestMessage, -// CommitReadyResponseMessage, -// TransferCompleteRequestMessage, -// } from "../../../generated/proto/cacti/satp/v02/stage_3_pb"; -// import { -// bufArray2HexStr, -// getHash, -// sign, -// storeLog, -// verifySignature, -// } from "../../../gateway-utils"; -// import { getMessageHash, saveHash, saveSignature } from "../../session-utils"; -// import { -// SATPService, -// ISATPClientServiceOptions, -// SATPServiceType, -// } from "../../../types/satp-protocol"; -// import { SATPSession } from "../../satp-session"; -// import { LockAssertionReceiptMessage } from "../../../generated/proto/cacti/satp/v02/stage_2_pb"; - -// export class Stage3ClientService implements SATPService { -// public static readonly CLASS_NAME = "client-service"; -// public static readonly SATP_STAGE = "stage-3"; -// public static readonly SATP_SERVICE_TYPE = SATPServiceType.Client; - -// private _log: Logger; -// private signer: JsObjectSigner; - -// constructor(ops: ISATPClientServiceOptions) { -// const level = ops.logLevel || "INFO"; -// const label = this.getServiceIdentifier(); -// this._log = LoggerProvider.getOrCreate({ level, label }); -// this.signer = ops.signer; -// } - -// public get className(): string { -// return Stage3ClientService.CLASS_NAME; -// } - -// public get stage(): string { -// return Stage3ClientService.SATP_STAGE; -// } - -// public get log(): Logger { -// return this._log; -// } - -// public get serviceType(): SATPServiceType { -// return SATPServiceType.Client; -// } - -// public getServiceIdentifier(): string { -// return `${this.className}#${this.serviceType}`; -// } - -// async commitPreparation( -// response: LockAssertionReceiptMessage, -// session: SATPSession, -// ): Promise { -// const fnTag = `${this.className}#commitPreparation()`; - -// if (response.common == undefined) { -// throw new Error(`${fnTag}, message common body is missing`); -// } - -// const sessionData = session.getSessionData(); - -// if (sessionData == undefined) { -// throw new Error( -// `${fnTag}, session data not found for session id ${response.common.sessionId}`, -// ); -// } - -// saveHash(sessionData, MessageType.ASSERTION_RECEIPT, getHash(response)); - -// const commonBody = new CommonSatp(); -// commonBody.version = SATP_VERSION; -// commonBody.messageType = MessageType.COMMIT_PREPARE; -// commonBody.sequenceNumber = sessionData.lastSequenceNumber + BigInt(1); -// commonBody.hashPreviousMessage = getMessageHash( -// sessionData, -// MessageType.ASSERTION_RECEIPT, -// ); -// commonBody.sessionId = response.common.sessionId; -// commonBody.clientGatewayPubkey = sessionData.clientGatewayPubkey; -// commonBody.serverGatewayPubkey = sessionData.serverGatewayPubkey; - -// sessionData.lastSequenceNumber = commonBody.sequenceNumber; - -// const commitPreparationRequestMessage = -// new CommitPreparationRequestMessage(); -// commitPreparationRequestMessage.common = commonBody; - -// const messageSignature = bufArray2HexStr( -// sign(this.signer, JSON.stringify(commitPreparationRequestMessage)), -// ); - -// commitPreparationRequestMessage.common.signature = messageSignature; - -// saveSignature(sessionData, MessageType.COMMIT_PREPARE, messageSignature); - -// saveHash( -// sessionData, -// MessageType.COMMIT_PREPARE, -// getHash(commitPreparationRequestMessage), -// ); - -// /* -// await storeLog(gateway, { -// sessionID: sessionData.id, -// type: "commitPreparation", -// operation: "lock", -// data: JSON.stringify(sessionData), -// }); -// */ - -// this.log.info(`${fnTag}, sending CommitPreparationMessage...`); - -// return commitPreparationRequestMessage; -// } - -// async commitFinalAssertion( -// response: CommitReadyResponseMessage, -// session: SATPSession, -// ): Promise { -// const fnTag = `${this.className}#commitPreparation()`; - -// if (response.common == undefined) { -// throw new Error(`${fnTag}, message common body is missing`); -// } - -// const sessionData = session.getSessionData(); - -// if (sessionData == undefined) { -// throw new Error( -// `${fnTag}, session data not found for session id ${response.common.sessionId}`, -// ); -// } - -// saveHash(sessionData, MessageType.COMMIT_READY, getHash(response)); - -// const commonBody = new CommonSatp(); -// commonBody.version = SATP_VERSION; -// commonBody.messageType = MessageType.COMMIT_FINAL; -// commonBody.sequenceNumber = sessionData.lastSequenceNumber + BigInt(1); - -// commonBody.hashPreviousMessage = getMessageHash( -// sessionData, -// MessageType.COMMIT_READY, -// ); - -// commonBody.sessionId = response.common.sessionId; -// commonBody.clientGatewayPubkey = sessionData.clientGatewayPubkey; -// commonBody.serverGatewayPubkey = sessionData.serverGatewayPubkey; - -// sessionData.lastSequenceNumber = commonBody.sequenceNumber; - -// const commitFinalAssertionRequestMessage = -// new CommitFinalAssertionRequestMessage(); -// commitFinalAssertionRequestMessage.common = commonBody; - -// commitFinalAssertionRequestMessage.burnAssertionClaim = -// sessionData.burnAssertionClaim; -// commitFinalAssertionRequestMessage.burnAssertionClaimFormat = -// sessionData.burnAssertionClaimFormat; - -// const messageSignature = bufArray2HexStr( -// sign(this.signer, JSON.stringify(commitFinalAssertionRequestMessage)), -// ); - -// commitFinalAssertionRequestMessage.common.signature = messageSignature; - -// saveSignature(sessionData, MessageType.COMMIT_FINAL, messageSignature); - -// saveHash( -// sessionData, -// MessageType.COMMIT_FINAL, -// getHash(commitFinalAssertionRequestMessage), -// ); - -// /* -// await storeLog(gateway, { -// sessionID: sessionData.id, -// type: "commitFinalAssertion", -// operation: "lock", -// data: JSON.stringify(sessionData), -// }); -// */ -// this.log.info(`${fnTag}, sending CommitFinalAssertionMessage...`); - -// return commitFinalAssertionRequestMessage; -// } - -// async transferComplete( -// response: CommitFinalAcknowledgementReceiptResponseMessage, -// session: SATPSession, -// ): Promise { -// const fnTag = `${this.className}#transferComplete()`; - -// if (response.common == undefined) { -// throw new Error(`${fnTag}, message common body is missing`); -// } - -// const sessionData = session.getSessionData(); - -// if (sessionData == undefined) { -// throw new Error( -// `${fnTag}, session data not loaded correctly ${response.common.sessionId}`, -// ); -// } - -// saveHash(sessionData, MessageType.ACK_COMMIT_FINAL, getHash(response)); - -// const commonBody = new CommonSatp(); -// commonBody.version = SATP_VERSION; -// commonBody.messageType = MessageType.COMMIT_TRANSFER_COMPLETE; -// commonBody.sequenceNumber = sessionData.lastSequenceNumber + BigInt(1); - -// commonBody.hashPreviousMessage = getMessageHash( -// sessionData, -// MessageType.ACK_COMMIT_FINAL, -// ); - -// commonBody.sessionId = response.common.sessionId; -// commonBody.clientGatewayPubkey = sessionData.clientGatewayPubkey; -// commonBody.serverGatewayPubkey = sessionData.serverGatewayPubkey; - -// sessionData.lastSequenceNumber = commonBody.sequenceNumber; - -// const transferCompleteRequestMessage = new TransferCompleteRequestMessage(); -// transferCompleteRequestMessage.common = commonBody; - -// transferCompleteRequestMessage.hashTransferCommence = getMessageHash( -// sessionData, -// MessageType.TRANSFER_COMMENCE_REQUEST, -// ); - -// const messageSignature = bufArray2HexStr( -// sign(this.signer, JSON.stringify(transferCompleteRequestMessage)), -// ); - -// transferCompleteRequestMessage.common.signature = messageSignature; - -// saveSignature( -// sessionData, -// MessageType.COMMIT_TRANSFER_COMPLETE, -// messageSignature, -// ); - -// saveHash( -// sessionData, -// MessageType.COMMIT_TRANSFER_COMPLETE, -// getHash(transferCompleteRequestMessage), -// ); - -// /* -// await storeLog(gateway, { -// sessionID: sessionData.id, -// type: "transferComplete", -// operation: "lock", -// data: JSON.stringify(sessionData), -// }); -// */ - -// this.log.info(`${fnTag}, sending TransferCompleteMessage...`); - -// return transferCompleteRequestMessage; -// } - -// checkLockAssertionReceiptMessage( -// response: LockAssertionReceiptMessage, -// session: SATPSession, -// ): void { -// const fnTag = `${this.className}#checkLockAssertionReceiptMessage()`; - -// if (response.common == undefined) { -// throw new Error(`${fnTag}, message common body is missing`); -// } - -// if (response.common.version != SATP_VERSION) { -// throw new Error(`${fnTag}, message version is not ${SATP_VERSION}`); -// } - -// if (response.common.messageType != MessageType.ASSERTION_RECEIPT) { -// throw new Error(`${fnTag}, message type is not ASSERTION_RECEIPT`); -// } - -// const sessionData = session.getSessionData(); - -// if (sessionData == undefined) { -// throw new Error( -// `${fnTag}, session data not found for session id ${response.common.sessionId}`, -// ); -// } - -// if ( -// sessionData.lastSequenceNumber == undefined || -// sessionData.version == undefined -// ) { -// throw new Error( -// `${fnTag}, session data not loaded correctly ${response.common.sessionId}`, -// ); -// } - -// if ( -// sessionData.lastSequenceNumber + BigInt(1) != -// response.common.sequenceNumber -// ) { -// throw new Error(`${fnTag}, sequenceNumber does not match`); -// } - -// if ( -// response.common.hashPreviousMessage != -// getMessageHash(sessionData, MessageType.LOCK_ASSERT) -// ) { -// throw new Error(`${fnTag}, hashPreviousMessage does not match`); -// } - -// if ( -// sessionData.clientGatewayPubkey != response.common.clientGatewayPubkey -// ) { -// throw new Error(`${fnTag}, clientGatewayPubkey does not match`); -// } - -// if ( -// sessionData.serverGatewayPubkey != response.common.serverGatewayPubkey -// ) { -// throw new Error(`${fnTag}, serverGatewayPubkey does not match`); -// } - -// if ( -// !verifySignature( -// this.signer, -// response.common, -// response.common.serverGatewayPubkey, -// ) -// ) { -// throw new Error(`${fnTag}, message signature verification failed`); -// } - -// this.log.info(`LockAssertionReceiptMessage passed all checks.`); -// } - -// checkCommitReadyResponseMessage( -// response: CommitReadyResponseMessage, -// session: SATPSession, -// ): void { -// const fnTag = `${this.className}#checkCommitReadyResponseMessage()`; - -// if (response.common == undefined) { -// throw new Error(`${fnTag}, message common body is missing`); -// } - -// if (response.common.version != SATP_VERSION) { -// throw new Error(`${fnTag}, message version is not ${SATP_VERSION}`); -// } - -// if (response.common.messageType != MessageType.COMMIT_READY) { -// throw new Error(`${fnTag}, message type is not COMMIT_READY`); -// } - -// const sessionData = session.getSessionData(); - -// if (sessionData == undefined) { -// throw new Error( -// `${fnTag}, session data not found for session id ${response.common.sessionId}`, -// ); -// } - -// if ( -// sessionData.lastSequenceNumber == undefined || -// sessionData.version == undefined -// ) { -// throw new Error( -// `${fnTag}, session data not loaded correctly ${response.common.sessionId}`, -// ); -// } - -// if ( -// sessionData.lastSequenceNumber + BigInt(1) != -// response.common.sequenceNumber -// ) { -// throw new Error(`${fnTag}, sequenceNumber does not match`); -// } - -// if ( -// response.common.hashPreviousMessage != -// getMessageHash(sessionData, MessageType.COMMIT_PREPARE) -// ) { -// throw new Error(`${fnTag}, hashPreviousMessage does not match`); -// } - -// if ( -// sessionData.clientGatewayPubkey != response.common.clientGatewayPubkey -// ) { -// throw new Error(`${fnTag}, clientGatewayPubkey does not match`); -// } - -// if ( -// sessionData.serverGatewayPubkey != response.common.serverGatewayPubkey -// ) { -// throw new Error(`${fnTag}, serverGatewayPubkey does not match`); -// } - -// if ( -// !verifySignature( -// this.signer, -// response.common, -// response.common.serverGatewayPubkey, -// ) -// ) { -// throw new Error(`${fnTag}, message signature verification failed`); -// } - -// if (response.mintAssertionClaims == undefined) { -// //todo -// throw new Error(`${fnTag}, mintAssertionClaims is missing`); -// } - -// this.log.info(`CommitReadyResponseMessage passed all checks.`); -// } - -// checkCommitFinalAcknowledgementReceiptResponseMessage( -// response: CommitFinalAcknowledgementReceiptResponseMessage, -// session: SATPSession, -// ): void { -// const fnTag = `${this.className}#checkCommitFinalAcknowledgementReceiptResponseMessage()`; - -// if (response.common == undefined) { -// throw new Error(`${fnTag}, message common body is missing`); -// } - -// if (response.common.version != SATP_VERSION) { -// throw new Error(`${fnTag}, message version is not ${SATP_VERSION}`); -// } - -// if (response.common.messageType != MessageType.ACK_COMMIT_FINAL) { -// throw new Error(`${fnTag}, message type is not ACK_COMMIT_FINAL`); -// } - -// const sessionData = session.getSessionData(); - -// if (sessionData == undefined) { -// throw new Error( -// `${fnTag}, session data not found for session id ${response.common.sessionId}`, -// ); -// } - -// if ( -// sessionData.lastSequenceNumber == undefined || -// sessionData.version == undefined -// ) { -// throw new Error( -// `${fnTag}, session data not loaded correctly ${response.common.sessionId}`, -// ); -// } - -// if ( -// sessionData.lastSequenceNumber + BigInt(1) != -// response.common.sequenceNumber -// ) { -// throw new Error(`${fnTag}, sequenceNumber does not match`); -// } - -// if ( -// response.common.hashPreviousMessage != -// getMessageHash(sessionData, MessageType.COMMIT_FINAL) -// ) { -// throw new Error(`${fnTag}, hashPreviousMessage does not match`); -// } - -// if ( -// sessionData.clientGatewayPubkey != response.common.clientGatewayPubkey -// ) { -// throw new Error(`${fnTag}, clientGatewayPubkey does not match`); -// } - -// if ( -// sessionData.serverGatewayPubkey != response.common.serverGatewayPubkey -// ) { -// throw new Error(`${fnTag}, serverGatewayPubkey does not match`); -// } - -// if ( -// !verifySignature( -// this.signer, -// response.common, -// response.common.serverGatewayPubkey, -// ) -// ) { -// throw new Error(`${fnTag}, message signature verification failed`); -// } - -// if (response.assignmentAssertionClaim == undefined) { -// throw new Error(`${fnTag}, assignmentAssertionClaim is missing`); -// } - -// this.log.info( -// `CommitFinalAcknowledgementReceiptResponseMessage passed all checks.`, -// ); -// } -// } +import { + BurnAssertionClaim, + CommonSatp, + MessageType, +} from "../../../generated/proto/cacti/satp/v02/common/message_pb"; +import { SATP_VERSION } from "../../constants"; +import { + CommitFinalAcknowledgementReceiptResponseMessage, + CommitFinalAssertionRequestMessage, + CommitPreparationRequestMessage, + CommitReadyResponseMessage, + TransferCompleteRequestMessage, +} from "../../../generated/proto/cacti/satp/v02/stage_3_pb"; +import { + bufArray2HexStr, + getHash, + sign, + verifySignature, +} from "../../../gateway-utils"; +import { getMessageHash, saveHash, saveSignature } from "../../session-utils"; +import { + SATPService, + ISATPClientServiceOptions, + ISATPServiceOptions, + SATPServiceType, +} from "../satp-service"; +import { SATPSession } from "../../satp-session"; +import { LockAssertionReceiptMessage } from "../../../generated/proto/cacti/satp/v02/stage_2_pb"; +import { SATPBridgesManager } from "../../../gol/satp-bridges-manager"; + +export class Stage3ClientService extends SATPService { + public static readonly SATP_STAGE = "3"; + public static readonly SERVICE_TYPE = SATPServiceType.Client; + + private bridgeManager: SATPBridgesManager; + + constructor(ops: ISATPClientServiceOptions) { + const commonOptions: ISATPServiceOptions = { + stage: Stage3ClientService.SATP_STAGE, + loggerOptions: ops.loggerOptions, + serviceName: ops.serviceName, + signer: ops.signer, + serviceType: Stage3ClientService.SERVICE_TYPE, + bridgeManager: ops.bridgeManager, + }; + super(commonOptions); + + if (ops.bridgeManager == undefined) { + throw new Error( + `${this.getServiceIdentifier()}#constructor(), bridgeManager is missing`, + ); + } + this.bridgeManager = ops.bridgeManager; + } + + async commitPreparation( + response: LockAssertionReceiptMessage, + session: SATPSession, + ): Promise { + const stepTag = `commitPreparation()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, CommitPreparation...`); + + if (response.common == undefined) { + throw new Error(`${fnTag}, message common body is missing`); + } + + const sessionData = session.getSessionData(); + + if (sessionData == undefined) { + throw new Error( + `${fnTag}, session data not found for session id ${response.common.sessionId}`, + ); + } + + saveHash(sessionData, MessageType.ASSERTION_RECEIPT, getHash(response)); + + const commonBody = new CommonSatp(); + commonBody.version = SATP_VERSION; + commonBody.messageType = MessageType.COMMIT_PREPARE; + commonBody.sequenceNumber = sessionData.lastSequenceNumber + BigInt(1); + commonBody.hashPreviousMessage = getMessageHash( + sessionData, + MessageType.ASSERTION_RECEIPT, + ); + commonBody.sessionId = response.common.sessionId; + commonBody.clientGatewayPubkey = sessionData.clientGatewayPubkey; + commonBody.serverGatewayPubkey = sessionData.serverGatewayPubkey; + + sessionData.lastSequenceNumber = commonBody.sequenceNumber; + + const commitPreparationRequestMessage = + new CommitPreparationRequestMessage(); + commitPreparationRequestMessage.common = commonBody; + + if (sessionData.transferContextId != undefined) { + commitPreparationRequestMessage.common.transferContextId = + sessionData.transferContextId; + } + + if (sessionData.clientTransferNumber != undefined) { + commitPreparationRequestMessage.clientTransferNumber = + sessionData.clientTransferNumber; + } + + const messageSignature = bufArray2HexStr( + sign(this.Signer, JSON.stringify(commitPreparationRequestMessage)), + ); + + commitPreparationRequestMessage.common.signature = messageSignature; + + saveSignature(sessionData, MessageType.COMMIT_PREPARE, messageSignature); + + saveHash( + sessionData, + MessageType.COMMIT_PREPARE, + getHash(commitPreparationRequestMessage), + ); + + /* + await storeLog(gateway, { + sessionID: sessionData.id, + type: "commitPreparation", + operation: "lock", + data: JSON.stringify(sessionData), + }); + */ + + this.Log.info(`${fnTag}, sending CommitPreparationMessage...`); + + return commitPreparationRequestMessage; + } + + async commitFinalAssertion( + response: CommitReadyResponseMessage, + session: SATPSession, + ): Promise { + const stepTag = `commitFinalAssertion()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, CommitFinalAssertion...`); + + if (response.common == undefined) { + throw new Error(`${fnTag}, message common body is missing`); + } + + const sessionData = session.getSessionData(); + + if (sessionData == undefined) { + throw new Error( + `${fnTag}, session data not found for session id ${response.common.sessionId}`, + ); + } + + saveHash(sessionData, MessageType.COMMIT_READY, getHash(response)); + + const commonBody = new CommonSatp(); + commonBody.version = SATP_VERSION; + commonBody.messageType = MessageType.COMMIT_FINAL; + commonBody.sequenceNumber = sessionData.lastSequenceNumber + BigInt(1); + + commonBody.hashPreviousMessage = getMessageHash( + sessionData, + MessageType.COMMIT_READY, + ); + + commonBody.sessionId = response.common.sessionId; + commonBody.clientGatewayPubkey = sessionData.clientGatewayPubkey; + commonBody.serverGatewayPubkey = sessionData.serverGatewayPubkey; + + sessionData.lastSequenceNumber = commonBody.sequenceNumber; + + const commitFinalAssertionRequestMessage = + new CommitFinalAssertionRequestMessage(); + commitFinalAssertionRequestMessage.common = commonBody; + + commitFinalAssertionRequestMessage.burnAssertionClaim = + sessionData.burnAssertionClaim; + + if (sessionData.burnAssertionClaimFormat != undefined) { + commitFinalAssertionRequestMessage.burnAssertionClaimFormat = + sessionData.burnAssertionClaimFormat; + } + + if (sessionData.transferContextId != undefined) { + commitFinalAssertionRequestMessage.common.transferContextId = + sessionData.transferContextId; + } + + if (sessionData.clientTransferNumber != undefined) { + commitFinalAssertionRequestMessage.clientTransferNumber = + sessionData.clientTransferNumber; + } + + const messageSignature = bufArray2HexStr( + sign(this.Signer, JSON.stringify(commitFinalAssertionRequestMessage)), + ); + + commitFinalAssertionRequestMessage.common.signature = messageSignature; + + saveSignature(sessionData, MessageType.COMMIT_FINAL, messageSignature); + + saveHash( + sessionData, + MessageType.COMMIT_FINAL, + getHash(commitFinalAssertionRequestMessage), + ); + + /* + await storeLog(gateway, { + sessionID: sessionData.id, + type: "commitFinalAssertion", + operation: "lock", + data: JSON.stringify(sessionData), + }); + */ + this.Log.info(`${fnTag}, sending CommitFinalAssertionMessage...`); + + return commitFinalAssertionRequestMessage; + } + + async transferComplete( + response: CommitFinalAcknowledgementReceiptResponseMessage, + session: SATPSession, + ): Promise { + const stepTag = `transferComplete()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, TransferComplete...`); + + if (response.common == undefined) { + throw new Error(`${fnTag}, message common body is missing`); + } + + const sessionData = session.getSessionData(); + + if (sessionData == undefined) { + throw new Error( + `${fnTag}, session data not loaded correctly ${response.common.sessionId}`, + ); + } + + saveHash(sessionData, MessageType.ACK_COMMIT_FINAL, getHash(response)); + + const commonBody = new CommonSatp(); + commonBody.version = SATP_VERSION; + commonBody.messageType = MessageType.COMMIT_TRANSFER_COMPLETE; + commonBody.sequenceNumber = sessionData.lastSequenceNumber + BigInt(1); + + commonBody.hashPreviousMessage = getMessageHash( + sessionData, + MessageType.ACK_COMMIT_FINAL, + ); + + commonBody.sessionId = response.common.sessionId; + commonBody.clientGatewayPubkey = sessionData.clientGatewayPubkey; + commonBody.serverGatewayPubkey = sessionData.serverGatewayPubkey; + + sessionData.lastSequenceNumber = commonBody.sequenceNumber; + + const transferCompleteRequestMessage = new TransferCompleteRequestMessage(); + transferCompleteRequestMessage.common = commonBody; + + if (sessionData.transferContextId != undefined) { + transferCompleteRequestMessage.common.transferContextId = + sessionData.transferContextId; + } + + if (sessionData.clientTransferNumber != undefined) { + transferCompleteRequestMessage.clientTransferNumber = + sessionData.clientTransferNumber; + } + + transferCompleteRequestMessage.hashTransferCommence = getMessageHash( + sessionData, + MessageType.TRANSFER_COMMENCE_REQUEST, + ); + + const messageSignature = bufArray2HexStr( + sign(this.Signer, JSON.stringify(transferCompleteRequestMessage)), + ); + + transferCompleteRequestMessage.common.signature = messageSignature; + + saveSignature( + sessionData, + MessageType.COMMIT_TRANSFER_COMPLETE, + messageSignature, + ); + + saveHash( + sessionData, + MessageType.COMMIT_TRANSFER_COMPLETE, + getHash(transferCompleteRequestMessage), + ); + + /* + await storeLog(gateway, { + sessionID: sessionData.id, + type: "transferComplete", + operation: "lock", + data: JSON.stringify(sessionData), + }); + */ + + this.Log.info(`${fnTag}, sending TransferCompleteMessage...`); + + return transferCompleteRequestMessage; + } + + checkLockAssertionReceiptMessage( + response: LockAssertionReceiptMessage, + session: SATPSession, + ): void { + const stepTag = `checkLockAssertionReceiptMessage()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, CheckLockAssertionReceiptMessage...`); + + if (response.common == undefined) { + throw new Error(`${fnTag}, message common body is missing`); + } + + if (response.common.version != SATP_VERSION) { + throw new Error(`${fnTag}, message version is not ${SATP_VERSION}`); + } + + if (response.common.messageType != MessageType.ASSERTION_RECEIPT) { + throw new Error(`${fnTag}, message type is not ASSERTION_RECEIPT`); + } + + const sessionData = session.getSessionData(); + + if (sessionData == undefined) { + throw new Error( + `${fnTag}, session data not found for session id ${response.common.sessionId}`, + ); + } + + if ( + sessionData.lastSequenceNumber == undefined || + sessionData.version == undefined + ) { + throw new Error( + `${fnTag}, session data not loaded correctly ${response.common.sessionId}`, + ); + } + + if ( + sessionData.lastSequenceNumber + BigInt(1) != + response.common.sequenceNumber + ) { + throw new Error(`${fnTag}, sequenceNumber does not match`); + } + + if ( + response.common.hashPreviousMessage != + getMessageHash(sessionData, MessageType.LOCK_ASSERT) + ) { + throw new Error(`${fnTag}, hashPreviousMessage does not match`); + } + + if ( + sessionData.clientGatewayPubkey != response.common.clientGatewayPubkey + ) { + throw new Error(`${fnTag}, clientGatewayPubkey does not match`); + } + + if ( + sessionData.serverGatewayPubkey != response.common.serverGatewayPubkey + ) { + throw new Error(`${fnTag}, serverGatewayPubkey does not match`); + } + + if ( + !verifySignature( + this.Signer, + response.common, + response.common.serverGatewayPubkey, + ) + ) { + throw new Error(`${fnTag}, message signature verification failed`); + } + + if ( + sessionData.transferContextId != undefined && + response.common.transferContextId != sessionData.transferContextId + ) { + throw new Error(`${fnTag}, transferContextId does not match`); + } + + if ( + sessionData.serverTransferNumber != undefined && + response.serverTransferNumber != sessionData.serverTransferNumber + ) { + // This does not throw an error because the serverTransferNumber is only meaningful to the server. + this.Log.info( + `${fnTag}, serverTransferNumber does not match the one that was sent`, + ); + } + + if ( + sessionData.transferContextId != undefined && + response.common.transferContextId != sessionData.transferContextId + ) { + throw new Error(`${fnTag}, transferContextId does not match`); + } + + if ( + sessionData.serverTransferNumber != undefined && + response.serverTransferNumber != sessionData.serverTransferNumber + ) { + // This does not throw an error because the serverTransferNumber is only meaningful to the server. + this.Log.info( + `${fnTag}, serverTransferNumber does not match the one that was sent`, + ); + } + + this.Log.info(`${fnTag}, LockAssertionReceiptMessage passed all checks.`); + } + + checkCommitReadyResponseMessage( + response: CommitReadyResponseMessage, + session: SATPSession, + ): void { + const stepTag = `checkCommitReadyResponseMessage()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, CommitReadyResponse...`); + + if (response.common == undefined) { + throw new Error(`${fnTag}, message common body is missing`); + } + + if (response.common.version != SATP_VERSION) { + throw new Error(`${fnTag}, message version is not ${SATP_VERSION}`); + } + + if (response.common.messageType != MessageType.COMMIT_READY) { + throw new Error(`${fnTag}, message type is not COMMIT_READY`); + } + + const sessionData = session.getSessionData(); + + if (sessionData == undefined) { + throw new Error( + `${fnTag}, session data not found for session id ${response.common.sessionId}`, + ); + } + + if ( + sessionData.lastSequenceNumber == undefined || + sessionData.version == undefined + ) { + throw new Error( + `${fnTag}, session data not loaded correctly ${response.common.sessionId}`, + ); + } + + if ( + sessionData.lastSequenceNumber + BigInt(1) != + response.common.sequenceNumber + ) { + throw new Error(`${fnTag}, sequenceNumber does not match`); + } + + if ( + response.common.hashPreviousMessage != + getMessageHash(sessionData, MessageType.COMMIT_PREPARE) + ) { + throw new Error(`${fnTag}, hashPreviousMessage does not match`); + } + + if ( + sessionData.clientGatewayPubkey != response.common.clientGatewayPubkey + ) { + throw new Error(`${fnTag}, clientGatewayPubkey does not match`); + } + + if ( + sessionData.serverGatewayPubkey != response.common.serverGatewayPubkey + ) { + throw new Error(`${fnTag}, serverGatewayPubkey does not match`); + } + + if ( + !verifySignature( + this.Signer, + response.common, + response.common.serverGatewayPubkey, + ) + ) { + throw new Error(`${fnTag}, message signature verification failed`); + } + + if (response.mintAssertionClaimFormat != undefined) { + //todo + this.Log.info( + `${fnTag}, Optional variable loaded: mintAssertionClaimsFormat `, + ); + sessionData.mintAssertionClaimFormat = response.mintAssertionClaimFormat; + } + + if (response.mintAssertionClaim == undefined) { + //todo + throw new Error(`${fnTag}, mintAssertionClaims is missing`); + } + + sessionData.mintAssertionClaim = response.mintAssertionClaim; + + if ( + sessionData.transferContextId != undefined && + response.common.transferContextId != sessionData.transferContextId + ) { + throw new Error(`${fnTag}, transferContextId does not match`); + } + + if ( + sessionData.serverTransferNumber != undefined && + response.serverTransferNumber != sessionData.serverTransferNumber + ) { + // This does not throw an error because the serverTransferNumber is only meaningful to the server. + this.Log.info( + `${fnTag}, serverTransferNumber does not match the one that was sent`, + ); + } + + this.Log.info(`${fnTag}, CommitReadyResponseMessage passed all checks.`); + } + + checkCommitFinalAcknowledgementReceiptResponseMessage( + response: CommitFinalAcknowledgementReceiptResponseMessage, + session: SATPSession, + ): void { + const stepTag = `checkCommitFinalAcknowledgementReceiptResponseMessage()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, CommitFinalAcknowledgementReceipt...`); + + if (response.common == undefined) { + throw new Error(`${fnTag}, message common body is missing`); + } + + if (response.common.version != SATP_VERSION) { + throw new Error(`${fnTag}, message version is not ${SATP_VERSION}`); + } + + if (response.common.messageType != MessageType.ACK_COMMIT_FINAL) { + throw new Error(`${fnTag}, message type is not ACK_COMMIT_FINAL`); + } + + const sessionData = session.getSessionData(); + + if (sessionData == undefined) { + throw new Error( + `${fnTag}, session data not found for session id ${response.common.sessionId}`, + ); + } + + if ( + sessionData.lastSequenceNumber == undefined || + sessionData.version == undefined + ) { + throw new Error( + `${fnTag}, session data not loaded correctly ${response.common.sessionId}`, + ); + } + + if ( + sessionData.lastSequenceNumber + BigInt(1) != + response.common.sequenceNumber + ) { + throw new Error(`${fnTag}, sequenceNumber does not match`); + } + + if ( + response.common.hashPreviousMessage != + getMessageHash(sessionData, MessageType.COMMIT_FINAL) + ) { + throw new Error(`${fnTag}, hashPreviousMessage does not match`); + } + + if ( + sessionData.clientGatewayPubkey != response.common.clientGatewayPubkey + ) { + throw new Error(`${fnTag}, clientGatewayPubkey does not match`); + } + + if ( + sessionData.serverGatewayPubkey != response.common.serverGatewayPubkey + ) { + throw new Error(`${fnTag}, serverGatewayPubkey does not match`); + } + + if ( + !verifySignature( + this.Signer, + response.common, + response.common.serverGatewayPubkey, + ) + ) { + throw new Error(`${fnTag}, message signature verification failed`); + } + + if ( + sessionData.transferContextId != undefined && + response.common.transferContextId != sessionData.transferContextId + ) { + throw new Error(`${fnTag}, transferContextId does not match`); + } + + if (response.assignmentAssertionClaim == undefined) { + throw new Error(`${fnTag}, assignmentAssertionClaim is missing`); + } + + sessionData.assignmentAssertionClaim = response.assignmentAssertionClaim; + + if (response.assignmentAssertionClaimFormat != undefined) { + this.Log.info( + `${fnTag}, Optional variable loaded: assignmentAssertionClaimFormat `, + ); + sessionData.assignmentAssertionClaimFormat = + response.assignmentAssertionClaimFormat; + } + + if ( + sessionData.serverTransferNumber != undefined && + response.serverTransferNumber != sessionData.serverTransferNumber + ) { + // This does not throw an error because the serverTransferNumber is only meaningful to the server. + this.Log.info( + `${fnTag}, serverTransferNumber does not match the one that was sent`, + ); + } + + this.Log.info( + `${fnTag}, CommitFinalAcknowledgementReceiptResponseMessage passed all checks.`, + ); + } + + async burnAsset(session: SATPSession): Promise { + const stepTag = `lockAsset()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + try { + this.Log.debug(`${fnTag}, Burning Asset...`); + const sessionData = session.getSessionData(); + const assetId = sessionData.transferInitClaims?.digitalAssetId; + const amount = sessionData.transferInitClaims?.amountFromOriginator; + + this.Log.debug(`${fnTag}, Burn Asset ID: ${assetId} amount: ${amount}`); + if (assetId == undefined) { + throw new Error(`${fnTag}, Asset ID is missing`); + } + + // const bridge = this.bridgeManager.getBridge( + // sessionData.senderGatewayNetworkId, + // ); + + // sessionData.burnAssertionClaim = new BurnAssertionClaim(); + // sessionData.burnAssertionClaim.receipt = await bridge.burnAsset( + // assetId, + // Number(amount), + // ); + // sessionData.burnAssertionClaim.signature = bufArray2HexStr( + // sign(this.Signer, sessionData.burnAssertionClaim.receipt), + // ); + } catch (error) { + throw new Error(`${fnTag}, Failed to process Burn Asset ${error}`); + } + } +} diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-bridge/satp-bridge-manager.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-bridge/satp-bridge-manager.ts deleted file mode 100644 index 16d6ca7673..0000000000 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-bridge/satp-bridge-manager.ts +++ /dev/null @@ -1,26 +0,0 @@ -// this file contains a class that encapsulates the logic for managing the SATP bridge (lock, unlock, etc). -// should inject satp gateway session data (having parameters/chains for transactions), and processes smart contract output - -import { SATPLedgerConnector } from "../../../types/blockchain-interaction"; - -export abstract class SATPBridgeManager { - // Instantiate connectors based on supported implementations, at bridge level - private connectors: SATPLedgerConnector[] = []; - - public abstract lockAsset( - sessionId: string, - assetId: string, - ): Promise; - public abstract unlockAsset( - sessionId: string, - assetId: string, - ): Promise; - public abstract mintAsset( - sessionId: string, - assetId: string, - ): Promise; - public abstract burnAsset( - sessionId: string, - assetId: string, - ): Promise; -} 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 b20d70fdac..75812e5f11 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 @@ -4,6 +4,7 @@ import { LoggerProvider, ILoggerOptions, } from "@hyperledger/cactus-common"; +import { SATPBridgesManager } from "../../gol/satp-bridges-manager"; export enum SATPServiceType { Server, @@ -16,6 +17,7 @@ export type ISATPServiceOptions = { loggerOptions: ILoggerOptions; signer: JsObjectSigner; serviceType: SATPServiceType; + bridgeManager?: SATPBridgesManager; }; export type ISATPServerServiceOptions = ISATPServiceOptions; 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 e1237ed33b..a2886b15bd 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 @@ -19,7 +19,6 @@ import { import { TransferClaims } from "../../../generated/proto/cacti/satp/v02/common/message_pb"; import { TimestampType, - createSessionData, getMessageHash, getMessageTimestamp, saveHash, @@ -57,6 +56,7 @@ export class Stage1ServerService extends SATPService { ): Promise { const stepTag = `transferProposalResponse()`; const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, transferProposalResponse...`); if ( request.common == undefined || @@ -174,6 +174,7 @@ export class Stage1ServerService extends SATPService { ): Promise { const stepTag = `transferCommenceResponse()`; const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, transferCommenceResponse...`); if (request.common == undefined) { throw new Error( @@ -256,6 +257,24 @@ export class Stage1ServerService extends SATPService { ): Promise { const stepTag = `checkTransferProposalRequestMessage()`; const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, checkTransferProposalRequestMessage...`); + + if (session == undefined) { + throw new Error(`${fnTag}, session is undefined`); + } + const sessionData = session.getSessionData(); + + if (request.common == undefined) { + throw new Error( + `${fnTag}, message satp common body is missing or is missing required fields`, + ); + } + + if (sessionData == undefined) { + throw new Error( + `${fnTag}, session data not found for session id ${request.common.sessionId}`, + ); + } if ( request.common == undefined || @@ -321,25 +340,33 @@ export class Stage1ServerService extends SATPService { this.Log.info(`TransferProposalRequest passed all checks.`); - const sessionData = createSessionData( - request.common.sessionId, - request.common.version, - request.transferInitClaims.digitalAssetId, - request.transferInitClaims.senderGatewayNetworkId, - request.transferInitClaims.recipientGatewayNetworkId, - request.transferInitClaims.originatorPubkey, - request.transferInitClaims.beneficiaryPubkey, - request.transferInitClaims.senderGatewayOwnerId, - request.transferInitClaims.receiverGatewayOwnerId, - request.transferInitClaims.clientGatewayPubkey, - request.transferInitClaims.serverGatewayPubkey, - request.networkCapabilities.signatureAlgorithm, - request.networkCapabilities.lockType, - request.networkCapabilities.lockExpirationTime, - request.networkCapabilities.credentialProfile, - request.networkCapabilities.loggingProfile, - request.networkCapabilities.accessControlProfile, - ); + sessionData.version = request.common.version; + sessionData.digitalAssetId = request.transferInitClaims.digitalAssetId; + sessionData.originatorPubkey = request.transferInitClaims.originatorPubkey; + sessionData.beneficiaryPubkey = + request.transferInitClaims.beneficiaryPubkey; + sessionData.senderGatewayNetworkId = + request.transferInitClaims.senderGatewayNetworkId; + sessionData.recipientGatewayNetworkId = + request.transferInitClaims.recipientGatewayNetworkId; + sessionData.clientGatewayPubkey = + request.transferInitClaims.clientGatewayPubkey; + sessionData.serverGatewayPubkey = + request.transferInitClaims.serverGatewayPubkey; + sessionData.receiverGatewayOwnerId = + request.transferInitClaims.receiverGatewayOwnerId; + sessionData.senderGatewayOwnerId = + request.transferInitClaims.senderGatewayOwnerId; + sessionData.signatureAlgorithm = + request.networkCapabilities.signatureAlgorithm; + sessionData.lockType = request.networkCapabilities.lockType; + sessionData.lockExpirationTime = + request.networkCapabilities.lockExpirationTime; + sessionData.credentialProfile = + request.networkCapabilities.credentialProfile; + sessionData.loggingProfile = request.networkCapabilities.loggingProfile; + sessionData.accessControlProfile = + request.networkCapabilities.accessControlProfile; this.Log.info(`Session data created for session id ${sessionData.id}`); if (!this.checkTransferClaims(request.transferInitClaims)) { @@ -466,7 +493,23 @@ export class Stage1ServerService extends SATPService { ); } - this.Log.info(`TransferCommenceRequest passed all checks.`); + if ( + sessionData.transferContextId != undefined && + request.common.transferContextId != sessionData.transferContextId + ) { + throw new Error( + `${fnTag}, TransferCommenceRequest message transfer context id does not match the one that was sent`, + ); + } + + if (request.clientTransferNumber != undefined) { + this.Log.info( + `${fnTag}, Optional variable loaded: clientTransferNumber...`, + ); + sessionData.clientTransferNumber = request.clientTransferNumber; + } + + this.Log.info(`${fnTag}, TransferCommenceRequest passed all checks.`); return sessionData; } 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 702abebcdb..5cdd9d06b5 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 @@ -1,234 +1,253 @@ -// import { -// JsObjectSigner, -// Logger, -// LoggerProvider, -// } from "@hyperledger/cactus-common"; -// import { -// LockAssertionReceiptMessage, -// LockAssertionRequestMessage, -// } from "../../../generated/proto/cacti/satp/v02/stage_2_pb"; -// import { SATPGateway } from "../../../plugin-satp-hermes-gateway"; -// import { SATP_VERSION } from "../../constants"; -// import { -// CommonSatp, -// MessageType, -// } from "../../../generated/proto/cacti/satp/v02/common/message_pb"; -// import { SessionData } from "../../../generated/proto/cacti/satp/v02/common/session_pb"; -// import { -// bufArray2HexStr, -// getHash, -// sign, -// storeLog, -// verifySignature, -// } from "../../../gateway-utils"; -// import { getMessageHash, saveHash, saveSignature } from "../../session-utils"; -// import { -// SATPService, -// ISATPServerServiceOptions, -// SATPServiceType, -// } from "../../../types/satp-protocol"; -// import { SATPSession } from "../../../core/satp-session"; -// export class Stage2ServerService implements SATPService { -// public static readonly CLASS_NAME = "server-service"; -// public static readonly SATP_STAGE = "stage-2"; -// public static readonly SERVICE_TYPE = SATPServiceType.Server; - -// private _log: Logger; -// private signer: JsObjectSigner; - -// constructor(ops: ISATPServerServiceOptions) { -// const level = ops.logLevel || "INFO"; -// const label = this.getServiceIdentifier(); -// this._log = LoggerProvider.getOrCreate({ level, label }); -// this.signer = ops.signer; -// } - -// public get className(): string { -// return Stage2ServerService.CLASS_NAME; -// } - -// public get stage(): string { -// return Stage2ServerService.SATP_STAGE; -// } - -// public get log(): Logger { -// return this._log; -// } - -// public get serviceType(): SATPServiceType { -// return SATPServiceType.Server; -// } - -// public getServiceIdentifier(): string { -// return `${this.className}#${this.serviceType}`; -// } - -// async lockAssertionResponse( -// request: LockAssertionRequestMessage, -// session: SATPSession, -// ): Promise { -// const fnTag = `${this.className}#lockAssertionResponse()`; - -// if (request.common == undefined) { -// throw new Error(`${fnTag}, message common body is missing`); -// } - -// const sessionData = session.getSessionData(); - -// if (sessionData == undefined) { -// throw new Error( -// `${fnTag}, session data not found for session id ${request.common.sessionId}`, -// ); -// } - -// saveHash(sessionData, MessageType.LOCK_ASSERT, getHash(request)); - -// const commonBody = new CommonSatp(); -// commonBody.version = SATP_VERSION; -// commonBody.messageType = MessageType.ASSERTION_RECEIPT; -// commonBody.sequenceNumber = request.common.sequenceNumber + BigInt(1); -// commonBody.hashPreviousMessage = getMessageHash( -// sessionData, -// MessageType.LOCK_ASSERT, -// ); -// commonBody.sessionId = request.common.sessionId; -// commonBody.clientGatewayPubkey = sessionData.clientGatewayPubkey; -// commonBody.serverGatewayPubkey = sessionData.serverGatewayPubkey; - -// sessionData.lastSequenceNumber = commonBody.sequenceNumber; - -// const lockAssertionReceiptMessage = new LockAssertionReceiptMessage(); -// lockAssertionReceiptMessage.common = commonBody; - -// const messageSignature = bufArray2HexStr( -// sign(this.signer, JSON.stringify(lockAssertionReceiptMessage)), -// ); - -// lockAssertionReceiptMessage.common.signature = messageSignature; - -// saveSignature(sessionData, MessageType.ASSERTION_RECEIPT, messageSignature); - -// saveHash( -// sessionData, -// MessageType.ASSERTION_RECEIPT, -// getHash(lockAssertionReceiptMessage), -// ); - -// /* -// await storeLog(gateway, { -// sessionID: sessionData.id, -// type: "lockAssertionResponse", -// operation: "lock", -// data: JSON.stringify(sessionData), -// }); -// */ - -// this.log.info(`${fnTag}, sending LockAssertionResponseMessage...`); - -// return lockAssertionReceiptMessage; -// } - -// async checkLockAssertionRequestMessage( -// request: LockAssertionRequestMessage, -// session: SATPSession, -// ): Promise { -// const fnTag = `${this.className}#checkLockAssertionRequestMessage()`; - -// if ( -// request.common == undefined || -// request.common.version == undefined || -// request.common.messageType == undefined || -// request.common.sessionId == undefined || -// // request.common.transferContextId == undefined || -// request.common.sequenceNumber == undefined || -// request.common.resourceUrl == undefined || -// // request.common.actionrequest == undefined || -// // request.common.payloadProfile == undefined || -// // request.common.applicationProfile == undefined || -// request.common.signature == undefined || -// request.common.clientGatewayPubkey == undefined || -// request.common.serverGatewayPubkey == undefined -// ) { -// throw new Error( -// `${fnTag}, message satp common body is missing or is missing required fields`, -// ); -// } - -// if (request.common.version != SATP_VERSION) { -// throw new Error(`${fnTag}, unsupported SATP version`); -// } - -// const sessionData = session.getSessionData(); - -// if (sessionData == undefined) { -// throw new Error( -// `${fnTag}, session data not found for session id ${request.common.sessionId}`, -// ); -// } - -// if ( -// sessionData.serverGatewayPubkey == undefined || -// sessionData.lastSequenceNumber == undefined -// ) { -// throw new Error(`${fnTag}, session data was not load correctly`); -// } - -// if (request.common.serverGatewayPubkey != sessionData.serverGatewayPubkey) { -// throw new Error( -// `${fnTag}, LockAssertionRequest serverIdentity public key does not match the one that was sent`, -// ); -// } - -// if (request.common.clientGatewayPubkey != sessionData.clientGatewayPubkey) { -// throw new Error( -// `${fnTag}, LockAssertionRequest clientIdentity public key does not match the one that was sent`, -// ); -// } - -// if ( -// !verifySignature( -// this.signer, -// request.common, -// request.common.serverGatewayPubkey, -// ) -// ) { -// throw new Error( -// `${fnTag}, LockAssertionRequest message signature verification failed`, -// ); -// } - -// if (request.common.messageType != MessageType.LOCK_ASSERT) { -// throw new Error(`${fnTag}, wrong message type for LockAssertionRequest`); -// } - -// if ( -// request.common.sequenceNumber != -// sessionData.lastSequenceNumber + BigInt(1) -// ) { -// throw new Error( -// `${fnTag}, LockAssertionRequest Message sequence number is wrong`, -// ); -// } - -// if ( -// request.common.hashPreviousMessage != -// getMessageHash(sessionData, MessageType.TRANSFER_COMMENCE_RESPONSE) -// ) { -// throw new Error( -// `${fnTag}, LockAssertionRequest previous message hash does not match the one that was sent`, -// ); -// } - -// if ( -// request.lockAssertionFormat == undefined || -// request.lockAssertionClaim == undefined -// ) { -// throw new Error( -// `${fnTag}, LockAssertionRequest lockAssertionFormat or lockAssertionClaim is missing`, -// ); -// } - -// this.log.info(`LockAssertionRequest passed all checks.`); -// return sessionData; -// } -// } +import { + LockAssertionReceiptMessage, + LockAssertionRequestMessage, +} from "../../../generated/proto/cacti/satp/v02/stage_2_pb"; +import { SATP_VERSION } from "../../constants"; +import { + CommonSatp, + MessageType, +} from "../../../generated/proto/cacti/satp/v02/common/message_pb"; +import { SessionData } from "../../../generated/proto/cacti/satp/v02/common/session_pb"; +import { + bufArray2HexStr, + getHash, + sign, + verifySignature, +} from "../../../gateway-utils"; +import { getMessageHash, saveHash, saveSignature } from "../../session-utils"; +import { + SATPService, + SATPServiceType, + ISATPServerServiceOptions, + ISATPServiceOptions, +} from "../satp-service"; +import { SATPSession } from "../../../core/satp-session"; +export class Stage2ServerService extends SATPService { + public static readonly SATP_STAGE = "2"; + public static readonly SERVICE_TYPE = SATPServiceType.Server; + + constructor(ops: ISATPServerServiceOptions) { + const commonOptions: ISATPServiceOptions = { + stage: Stage2ServerService.SATP_STAGE, + loggerOptions: ops.loggerOptions, + serviceName: ops.serviceName, + signer: ops.signer, + serviceType: Stage2ServerService.SERVICE_TYPE, + }; + super(commonOptions); + } + + async lockAssertionResponse( + request: LockAssertionRequestMessage, + session: SATPSession, + ): Promise { + const stepTag = `lockAssertionResponse()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, lockAssertionResponse...`); + + if (request.common == undefined) { + throw new Error(`${fnTag}, message common body is missing`); + } + + const sessionData = session.getSessionData(); + + if (sessionData == undefined) { + throw new Error( + `${fnTag}, session data not found for session id ${request.common.sessionId}`, + ); + } + + saveHash(sessionData, MessageType.LOCK_ASSERT, getHash(request)); + + const commonBody = new CommonSatp(); + commonBody.version = SATP_VERSION; + commonBody.messageType = MessageType.ASSERTION_RECEIPT; + commonBody.sequenceNumber = request.common.sequenceNumber + BigInt(1); + commonBody.hashPreviousMessage = getMessageHash( + sessionData, + MessageType.LOCK_ASSERT, + ); + commonBody.sessionId = request.common.sessionId; + commonBody.clientGatewayPubkey = sessionData.clientGatewayPubkey; + commonBody.serverGatewayPubkey = sessionData.serverGatewayPubkey; + + sessionData.lastSequenceNumber = commonBody.sequenceNumber; + + const lockAssertionReceiptMessage = new LockAssertionReceiptMessage(); + lockAssertionReceiptMessage.common = commonBody; + + if (sessionData.transferContextId != undefined) { + lockAssertionReceiptMessage.common.transferContextId = + sessionData.transferContextId; + } + + if (sessionData.serverTransferNumber != undefined) { + lockAssertionReceiptMessage.serverTransferNumber = + sessionData.serverTransferNumber; + } + + const messageSignature = bufArray2HexStr( + sign(this.Signer, JSON.stringify(lockAssertionReceiptMessage)), + ); + + lockAssertionReceiptMessage.common.signature = messageSignature; + + saveSignature(sessionData, MessageType.ASSERTION_RECEIPT, messageSignature); + + saveHash( + sessionData, + MessageType.ASSERTION_RECEIPT, + getHash(lockAssertionReceiptMessage), + ); + + /* + await storeLog(gateway, { + sessionID: sessionData.id, + type: "lockAssertionResponse", + operation: "lock", + data: JSON.stringify(sessionData), + }); + */ + + this.Log.info(`${fnTag}, sending LockAssertionResponseMessage...`); + + return lockAssertionReceiptMessage; + } + + async checkLockAssertionRequestMessage( + request: LockAssertionRequestMessage, + session: SATPSession, + ): Promise { + const stepTag = `checkLockAssertionRequestMessage()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, checkLockAssertionRequestMessage...`); + + if ( + request.common == undefined || + request.common.version == undefined || + request.common.messageType == undefined || + request.common.sessionId == undefined || + request.common.sequenceNumber == undefined || + request.common.resourceUrl == undefined || + request.common.signature == undefined || + request.common.clientGatewayPubkey == undefined || + request.common.serverGatewayPubkey == undefined || + request.common.hashPreviousMessage == undefined + ) { + throw new Error( + `${fnTag}, message satp common body is missing or is missing required fields`, + ); + } + + if (request.common.version != SATP_VERSION) { + throw new Error(`${fnTag}, unsupported SATP version`); + } + + const sessionData = session.getSessionData(); + + if (sessionData == undefined) { + throw new Error( + `${fnTag}, session data not found for session id ${request.common.sessionId}`, + ); + } + + if ( + sessionData.serverGatewayPubkey == undefined || + sessionData.lastSequenceNumber == undefined + ) { + throw new Error(`${fnTag}, session data was not load correctly`); + } + + if (request.common.serverGatewayPubkey != sessionData.serverGatewayPubkey) { + throw new Error( + `${fnTag}, LockAssertionRequest serverIdentity public key does not match the one that was sent`, + ); + } + + if (request.common.clientGatewayPubkey != sessionData.clientGatewayPubkey) { + throw new Error( + `${fnTag}, LockAssertionRequest clientIdentity public key does not match the one that was sent`, + ); + } + + if ( + !verifySignature( + this.Signer, + request.common, + request.common.serverGatewayPubkey, + ) + ) { + throw new Error( + `${fnTag}, LockAssertionRequest message signature verification failed`, + ); + } + + if (request.common.messageType != MessageType.LOCK_ASSERT) { + throw new Error(`${fnTag}, wrong message type for LockAssertionRequest`); + } + + if ( + request.common.sequenceNumber != + sessionData.lastSequenceNumber + BigInt(1) + ) { + throw new Error( + `${fnTag}, LockAssertionRequest Message sequence number is wrong`, + ); + } + + if ( + request.common.hashPreviousMessage != + getMessageHash(sessionData, MessageType.TRANSFER_COMMENCE_RESPONSE) + ) { + throw new Error( + `${fnTag}, LockAssertionRequest previous message hash does not match the one that was sent`, + ); + } + + if (request.lockAssertionClaim == undefined) { + throw new Error( + `${fnTag}, LockAssertionRequest lockAssertionClaim is missing`, + ); + } + + sessionData.lockAssertionClaim = request.lockAssertionClaim; + + if (request.lockAssertionClaimFormat == undefined) { + throw new Error( + `${fnTag}, LockAssertionRequest lockAssertionFormat is missing`, + ); + } + + sessionData.lockAssertionClaimFormat = request.lockAssertionClaimFormat; + + if (request.lockAssertionExpiration == undefined) { + throw new Error( + `${fnTag}, LockAssertionRequest lockAssertionExpiration is missing`, + ); + } + + sessionData.lockAssertionExpiration = request.lockAssertionExpiration; //todo check if expired + + if ( + sessionData.transferContextId != undefined && + request.common.transferContextId != sessionData.transferContextId + ) { + throw new Error( + `${fnTag}, LockAssertionRequest transferContextId does not match the one that was sent`, + ); + } + + if ( + sessionData.clientTransferNumber != undefined && + request.clientTransferNumber != sessionData.clientTransferNumber + ) { + // This does not throw an error because the clientTransferNumber is only meaningful to the client. + this.Log.info( + `${fnTag}, LockAssertionRequest clientTransferNumber does not match the one that was sent`, + ); + } + + this.Log.info(`${fnTag}, LockAssertionRequest passed all checks.`); + return sessionData; + } +} 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 24bedb08db..4d75c0b865 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 @@ -1,433 +1,596 @@ -// import { -// JsObjectSigner, -// Logger, -// LoggerProvider, -// } from "@hyperledger/cactus-common"; -// import { SATPGateway } from "../../../plugin-satp-hermes-gateway"; -// import { -// CommitFinalAcknowledgementReceiptResponseMessage, -// CommitFinalAssertionRequestMessage, -// CommitPreparationRequestMessage, -// CommitReadyResponseMessage, -// } from "../../../generated/proto/cacti/satp/v02/stage_3_pb"; -// import { SATP_VERSION } from "../../constants"; -// import { -// CommonSatp, -// MessageType, -// } from "../../../generated/proto/cacti/satp/v02/common/message_pb"; -// import { SessionData } from "../../../generated/proto/cacti/satp/v02/common/session_pb"; -// import { -// bufArray2HexStr, -// getHash, -// sign, -// storeLog, -// verifySignature, -// } from "../../../gateway-utils"; -// import { getMessageHash, saveHash, saveSignature } from "../../session-utils"; -// import { -// SATPService, -// ISATPServerServiceOptions, -// SATPServiceType, -// } from "../../../types/satp-protocol"; -// import { SATPSession } from "../../../core/satp-session"; - -// export class Stage3ServerService implements SATPService { -// public static readonly CLASS_NAME = "server-service"; -// public static readonly SATP_STAGE = "stage-3"; -// public static readonly SERVICE_TYPE = SATPServiceType.Server; -// private _log: Logger; -// private signer: JsObjectSigner; - -// constructor(ops: ISATPServerServiceOptions) { -// const level = ops.logLevel || "INFO"; -// const label = this.getServiceIdentifier(); -// this._log = LoggerProvider.getOrCreate({ level, label }); -// this.signer = ops.signer; -// } - -// public get className(): string { -// return Stage3ServerService.CLASS_NAME; -// } - -// public get stage(): string { -// return Stage3ServerService.SATP_STAGE; -// } - -// public get log(): Logger { -// return this._log; -// } - -// public get serviceType(): SATPServiceType { -// return SATPServiceType.Server; -// } - -// public getServiceIdentifier(): string { -// return `${this.className}#${this.serviceType}`; -// } - -// async commitReady( -// request: CommitPreparationRequestMessage, -// session: SATPSession, -// ): Promise { -// const fnTag = `${this.className}#commitReady()`; - -// if (request.common == undefined) { -// throw new Error(`${fnTag}, message common body is missing`); -// } - -// const sessionData = session.getSessionData(); - -// if (sessionData == undefined) { -// throw new Error( -// `${fnTag}, session data not found for session id ${request.common.sessionId}`, -// ); -// } - -// saveHash(sessionData, MessageType.COMMIT_PREPARE, getHash(request)); - -// const commonBody = new CommonSatp(); -// commonBody.version = SATP_VERSION; -// commonBody.messageType = MessageType.COMMIT_READY; -// commonBody.sequenceNumber = request.common.sequenceNumber + BigInt(1); -// commonBody.hashPreviousMessage = getMessageHash( -// sessionData, -// MessageType.COMMIT_PREPARE, -// ); -// commonBody.sessionId = request.common.sessionId; -// commonBody.clientGatewayPubkey = sessionData.clientGatewayPubkey; -// commonBody.serverGatewayPubkey = sessionData.serverGatewayPubkey; - -// sessionData.lastSequenceNumber = commonBody.sequenceNumber; - -// const commitReadyMessage = new CommitReadyResponseMessage(); -// commitReadyMessage.common = commonBody; - -// commitReadyMessage.mintAssertionClaims = sessionData.mintAssertionClaims; -// commitReadyMessage.mintAssertionClaimsFormat = -// sessionData.mintAssertionClaimsFormat; - -// const messageSignature = bufArray2HexStr( -// sign(this.signer, JSON.stringify(commitReadyMessage)), -// ); - -// saveSignature(sessionData, MessageType.COMMIT_READY, messageSignature); - -// saveHash( -// sessionData, -// MessageType.COMMIT_READY, -// getHash(commitReadyMessage), -// ); - -// /* -// await storeLog(gateway, { -// sessionID: sessionData.id, -// type: "commitReady", -// operation: "lock", -// data: JSON.stringify(sessionData), -// }); -// */ -// this.log.info(`${fnTag}, sending commitReadyMessage...`); - -// return commitReadyMessage; -// } - -// async commitFinalAcknowledgementReceiptResponse( -// request: CommitFinalAssertionRequestMessage, -// session: SATPSession, -// ): Promise { -// const fnTag = `${this.className}#commitFinalAcknowledgementReceiptResponse()`; - -// if (request.common == undefined) { -// throw new Error(`${fnTag}, message common body is missing`); -// } - -// const sessionData = session.getSessionData(); - -// if (sessionData == undefined) { -// throw new Error( -// `${fnTag}, session data not loaded correctly ${request.common.sessionId}`, -// ); -// } - -// saveHash(sessionData, MessageType.COMMIT_FINAL, getHash(request)); - -// const commonBody = new CommonSatp(); -// commonBody.version = SATP_VERSION; -// commonBody.messageType = MessageType.ACK_COMMIT_FINAL; -// commonBody.sequenceNumber = request.common.sequenceNumber + BigInt(1); -// commonBody.hashPreviousMessage = getMessageHash( -// sessionData, -// MessageType.COMMIT_FINAL, -// ); -// commonBody.sessionId = request.common.sessionId; -// commonBody.clientGatewayPubkey = sessionData.clientGatewayPubkey; -// commonBody.serverGatewayPubkey = sessionData.serverGatewayPubkey; - -// sessionData.lastSequenceNumber = commonBody.sequenceNumber; - -// const commitFinalAcknowledgementReceiptResponseMessage = -// new CommitFinalAcknowledgementReceiptResponseMessage(); -// commitFinalAcknowledgementReceiptResponseMessage.common = commonBody; - -// commitFinalAcknowledgementReceiptResponseMessage.assignmentAssertionClaim = -// sessionData.assignmentAssertionClaim; -// commitFinalAcknowledgementReceiptResponseMessage.assignmentAssertionClaimFormat = -// sessionData.assignmentAssertionClaimFormat; - -// const messageSignature = bufArray2HexStr( -// sign( -// this.signer, -// JSON.stringify(commitFinalAcknowledgementReceiptResponseMessage), -// ), -// ); - -// saveSignature(sessionData, MessageType.ACK_COMMIT_FINAL, messageSignature); - -// saveHash(sessionData, MessageType.ACK_COMMIT_FINAL, getHash(request)); - -// /* -// await storeLog(gateway, { -// sessionID: sessionData.id, -// type: "commitFinalAcknowledgementReceiptResponse", -// operation: "lock", -// data: JSON.stringify(sessionData), -// }); -// */ -// this.log.info( -// `${fnTag}, sending commitFinalAcknowledgementReceiptResponseMessage...`, -// ); - -// return commitFinalAcknowledgementReceiptResponseMessage; -// } - -// async checkCommitPreparationRequestMessage( -// request: CommitPreparationRequestMessage, -// session: SATPSession, -// ): Promise { -// const fnTag = `${this.className}#checkCommitPreparationRequestMessage()`; - -// if (request.common == undefined) { -// throw new Error(`${fnTag}, message common body is missing`); -// } - -// if (request.common.version != SATP_VERSION) { -// throw new Error(`${fnTag}, message version is not ${SATP_VERSION}`); -// } - -// if (request.common.messageType != MessageType.COMMIT_PREPARE) { -// throw new Error(`${fnTag}, message type is not COMMIT_PREPARE`); -// } - -// const sessionData = session.getSessionData(); - -// if (sessionData == undefined) { -// throw new Error( -// `${fnTag}, session data not found for session id ${request.common.sessionId}`, -// ); -// } - -// if ( -// sessionData.lastSequenceNumber == undefined || -// sessionData.version == undefined || -// sessionData.signatures == undefined -// ) { -// throw new Error( -// `${fnTag}, session data not loaded correctly ${request.common.sessionId}`, -// ); -// } - -// if ( -// sessionData.lastSequenceNumber + BigInt(1) != -// request.common.sequenceNumber -// ) { -// throw new Error(`${fnTag}, sequenceNumber does not match`); -// } - -// if ( -// getMessageHash(sessionData, MessageType.ASSERTION_RECEIPT) != -// request.common.hashPreviousMessage -// ) { -// throw new Error(`${fnTag}, hashPreviousMessage does not match`); -// } - -// if (sessionData.clientGatewayPubkey != request.common.clientGatewayPubkey) { -// throw new Error(`${fnTag}, clientGatewayPubkey does not match`); -// } - -// if (sessionData.serverGatewayPubkey != request.common.serverGatewayPubkey) { -// throw new Error(`${fnTag}, serverGatewayPubkey does not match`); -// } - -// if ( -// !verifySignature( -// this.signer, -// request.common, -// request.common.clientGatewayPubkey, -// ) -// ) { -// throw new Error(`${fnTag}, message signature verification failed`); -// } - -// this.log.info(`CommitPreparationRequestMessage passed all checks.`); - -// return sessionData; -// } - -// async checkCommitFinalAssertionRequestMessage( -// request: CommitFinalAssertionRequestMessage, -// session: SATPSession, -// ): Promise { -// const fnTag = `${this.className}#checkCommitFinalAssertionRequestMessage()`; - -// if (request.common == undefined) { -// throw new Error(`${fnTag}, message common body is missing`); -// } - -// if (request.common.version != SATP_VERSION) { -// throw new Error(`${fnTag}, message version is not ${SATP_VERSION}`); -// } - -// if (request.common.messageType != MessageType.COMMIT_FINAL) { -// throw new Error(`${fnTag}, message type is not COMMIT_FINAL`); -// } - -// const sessionData = session.getSessionData(); - -// if (sessionData == undefined) { -// throw new Error( -// `${fnTag}, session data not found for session id ${request.common.sessionId}`, -// ); -// } - -// if ( -// sessionData.lastSequenceNumber == undefined || -// sessionData.version == undefined || -// sessionData.signatures == undefined -// ) { -// throw new Error( -// `${fnTag}, session data not loaded correctly ${request.common.sessionId}`, -// ); -// } - -// if ( -// sessionData.lastSequenceNumber + BigInt(1) != -// request.common.sequenceNumber -// ) { -// throw new Error(`${fnTag}, sequenceNumber does not match`); -// } - -// if ( -// getMessageHash(sessionData, MessageType.COMMIT_READY) != -// request.common.hashPreviousMessage -// ) { -// throw new Error(`${fnTag}, hashPreviousMessage does not match`); -// } - -// if (sessionData.clientGatewayPubkey != request.common.clientGatewayPubkey) { -// throw new Error(`${fnTag}, clientGatewayPubkey does not match`); -// } - -// if (sessionData.serverGatewayPubkey != request.common.serverGatewayPubkey) { -// throw new Error(`${fnTag}, serverGatewayPubkey does not match`); -// } - -// if ( -// !verifySignature( -// this.signer, -// request.common, -// request.common.clientGatewayPubkey, -// ) -// ) { -// throw new Error(`${fnTag}, message signature verification failed`); -// } - -// if (request.burnAssertionClaim == undefined) { -// throw new Error(`${fnTag}, mintAssertionClaims is missing`); -// } - -// //todo check burn - -// this.log.info(`CommitFinalAssertionRequestMessage passed all checks.`); - -// return sessionData; -// } - -// async checkTransferCompleteRequestMessage( -// request: CommitFinalAssertionRequestMessage, -// session: SATPSession, -// ): Promise { -// const fnTag = `${this.className}#checkTransferCompleteRequestMessage()`; - -// if (request.common == undefined) { -// throw new Error(`${fnTag}, message common body is missing`); -// } - -// if (request.common.version != SATP_VERSION) { -// throw new Error(`${fnTag}, message version is not ${SATP_VERSION}`); -// } - -// if (request.common.messageType != MessageType.COMMIT_TRANSFER_COMPLETE) { -// throw new Error(`${fnTag}, message type is not COMMIT_TRANSFER_COMPLETE`); -// } - -// this.log.info( -// `${fnTag}, TransferCompleteRequestMessage passed all checks.`, -// ); - -// const sessionData = session.getSessionData(); - -// if (sessionData == undefined) { -// throw new Error( -// `${fnTag}, session data not found for session id ${request.common.sessionId}`, -// ); -// } - -// if ( -// sessionData.lastSequenceNumber == undefined || -// sessionData.version == undefined || -// sessionData.signatures == undefined -// ) { -// throw new Error( -// `${fnTag}, session data not loaded correctly ${request.common.sessionId}`, -// ); -// } - -// if ( -// sessionData.lastSequenceNumber + BigInt(1) != -// request.common.sequenceNumber -// ) { -// throw new Error(`${fnTag}, sequenceNumber does not match`); -// } - -// if ( -// getMessageHash(sessionData, MessageType.COMMIT_FINAL) != -// request.common.hashPreviousMessage -// ) { -// throw new Error(`${fnTag}, hashPreviousMessage does not match`); -// } - -// if (sessionData.clientGatewayPubkey != request.common.clientGatewayPubkey) { -// throw new Error(`${fnTag}, clientGatewayPubkey does not match`); -// } - -// if (sessionData.serverGatewayPubkey != request.common.serverGatewayPubkey) { -// throw new Error(`${fnTag}, serverGatewayPubkey does not match`); -// } - -// if ( -// !verifySignature( -// this.signer, -// request.common, -// request.common.clientGatewayPubkey, -// ) -// ) { -// throw new Error(`${fnTag}, message signature verification failed`); -// } - -// this.log.info( -// `${fnTag}, TransferCompleteRequestMessage passed all checks.`, -// ); - -// return sessionData; -// } -// } +import { + CommitFinalAcknowledgementReceiptResponseMessage, + CommitFinalAssertionRequestMessage, + CommitPreparationRequestMessage, + CommitReadyResponseMessage, + TransferCompleteRequestMessage, +} from "../../../generated/proto/cacti/satp/v02/stage_3_pb"; +import { SATP_VERSION } from "../../constants"; +import { + AssignmentAssertionClaim, + CommonSatp, + MessageType, + MintAssertionClaim, +} from "../../../generated/proto/cacti/satp/v02/common/message_pb"; +import { SessionData } from "../../../generated/proto/cacti/satp/v02/common/session_pb"; +import { + bufArray2HexStr, + getHash, + sign, + verifySignature, +} from "../../../gateway-utils"; +import { getMessageHash, saveHash, saveSignature } from "../../session-utils"; +import { + SATPService, + SATPServiceType, + ISATPServerServiceOptions, + ISATPServiceOptions, +} from "../satp-service"; +import { SATPSession } from "../../../core/satp-session"; +import { SATPBridgesManager } from "../../../gol/satp-bridges-manager"; + +export class Stage3ServerService extends SATPService { + public static readonly SATP_STAGE = "3"; + public static readonly SERVICE_TYPE = SATPServiceType.Server; + + private bridgeManager: SATPBridgesManager; + + constructor(ops: ISATPServerServiceOptions) { + const commonOptions: ISATPServiceOptions = { + stage: Stage3ServerService.SATP_STAGE, + loggerOptions: ops.loggerOptions, + serviceName: ops.serviceName, + signer: ops.signer, + serviceType: Stage3ServerService.SERVICE_TYPE, + bridgeManager: ops.bridgeManager, + }; + super(commonOptions); + if (ops.bridgeManager == undefined) { + throw new Error( + `${this.getServiceIdentifier()}#constructor() bridgeManager is required`, + ); + } + this.bridgeManager = ops.bridgeManager; + } + + async commitReady( + request: CommitPreparationRequestMessage, + session: SATPSession, + ): Promise { + const stepTag = `commitReady()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, commitReady...`); + + if (request.common == undefined) { + throw new Error(`${fnTag}, message common body is missing`); + } + + const sessionData = session.getSessionData(); + + if (sessionData == undefined) { + throw new Error( + `${fnTag}, session data not found for session id ${request.common.sessionId}`, + ); + } + + saveHash(sessionData, MessageType.COMMIT_PREPARE, getHash(request)); + + const commonBody = new CommonSatp(); + commonBody.version = SATP_VERSION; + commonBody.messageType = MessageType.COMMIT_READY; + commonBody.sequenceNumber = request.common.sequenceNumber + BigInt(1); + commonBody.hashPreviousMessage = getMessageHash( + sessionData, + MessageType.COMMIT_PREPARE, + ); + commonBody.sessionId = request.common.sessionId; + commonBody.clientGatewayPubkey = sessionData.clientGatewayPubkey; + commonBody.serverGatewayPubkey = sessionData.serverGatewayPubkey; + + sessionData.lastSequenceNumber = commonBody.sequenceNumber; + + const commitReadyMessage = new CommitReadyResponseMessage(); + commitReadyMessage.common = commonBody; + + commitReadyMessage.mintAssertionClaim = sessionData.mintAssertionClaim; + commitReadyMessage.mintAssertionClaimFormat = + sessionData.mintAssertionClaimFormat; + + if (sessionData.transferContextId != undefined) { + commitReadyMessage.common.transferContextId = + sessionData.transferContextId; + } + + if (sessionData.serverTransferNumber != undefined) { + commitReadyMessage.serverTransferNumber = + sessionData.serverTransferNumber; + } + + const messageSignature = bufArray2HexStr( + sign(this.Signer, JSON.stringify(commitReadyMessage)), + ); + + saveSignature(sessionData, MessageType.COMMIT_READY, messageSignature); + + saveHash( + sessionData, + MessageType.COMMIT_READY, + getHash(commitReadyMessage), + ); + + /* + await storeLog(gateway, { + sessionID: sessionData.id, + type: "commitReady", + operation: "lock", + data: JSON.stringify(sessionData), + }); + */ + this.Log.info(`${fnTag}, sending commitReadyMessage...`); + + return commitReadyMessage; + } + + async commitFinalAcknowledgementReceiptResponse( + request: CommitFinalAssertionRequestMessage, + session: SATPSession, + ): Promise { + const stepTag = `commitFinalAcknowledgementReceiptResponse()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, commitFinalAcknowledgementReceiptResponse...`); + + if (request.common == undefined) { + throw new Error(`${fnTag}, message common body is missing`); + } + + const sessionData = session.getSessionData(); + + if (sessionData == undefined) { + throw new Error( + `${fnTag}, session data not loaded correctly ${request.common.sessionId}`, + ); + } + + saveHash(sessionData, MessageType.COMMIT_FINAL, getHash(request)); + + const commonBody = new CommonSatp(); + commonBody.version = SATP_VERSION; + commonBody.messageType = MessageType.ACK_COMMIT_FINAL; + commonBody.sequenceNumber = request.common.sequenceNumber + BigInt(1); + commonBody.hashPreviousMessage = getMessageHash( + sessionData, + MessageType.COMMIT_FINAL, + ); + commonBody.sessionId = request.common.sessionId; + commonBody.clientGatewayPubkey = sessionData.clientGatewayPubkey; + commonBody.serverGatewayPubkey = sessionData.serverGatewayPubkey; + + sessionData.lastSequenceNumber = commonBody.sequenceNumber; + + const commitFinalAcknowledgementReceiptResponseMessage = + new CommitFinalAcknowledgementReceiptResponseMessage(); + commitFinalAcknowledgementReceiptResponseMessage.common = commonBody; + + commitFinalAcknowledgementReceiptResponseMessage.assignmentAssertionClaim = + sessionData.assignmentAssertionClaim; + + if (sessionData.assignmentAssertionClaimFormat != undefined) { + commitFinalAcknowledgementReceiptResponseMessage.assignmentAssertionClaimFormat = + sessionData.assignmentAssertionClaimFormat; + } + + if (sessionData.transferContextId != undefined) { + commitFinalAcknowledgementReceiptResponseMessage.common.transferContextId = + sessionData.transferContextId; + } + + if (sessionData.serverTransferNumber != undefined) { + commitFinalAcknowledgementReceiptResponseMessage.serverTransferNumber = + sessionData.serverTransferNumber; + } + + const messageSignature = bufArray2HexStr( + sign( + this.Signer, + JSON.stringify(commitFinalAcknowledgementReceiptResponseMessage), + ), + ); + + saveSignature(sessionData, MessageType.ACK_COMMIT_FINAL, messageSignature); + + saveHash(sessionData, MessageType.ACK_COMMIT_FINAL, getHash(request)); + + /* + await storeLog(gateway, { + sessionID: sessionData.id, + type: "commitFinalAcknowledgementReceiptResponse", + operation: "lock", + data: JSON.stringify(sessionData), + }); + */ + this.Log.info( + `${fnTag}, sending commitFinalAcknowledgementReceiptResponseMessage...`, + ); + + return commitFinalAcknowledgementReceiptResponseMessage; + } + + async checkCommitPreparationRequestMessage( + request: CommitPreparationRequestMessage, + session: SATPSession, + ): Promise { + const stepTag = `checkCommitPreparationRequestMessage()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, checkCommitPreparationRequestMessage...`); + + if (request.common == undefined) { + throw new Error(`${fnTag}, message common body is missing`); + } + + if (request.common.version != SATP_VERSION) { + throw new Error(`${fnTag}, message version is not ${SATP_VERSION}`); + } + + if (request.common.messageType != MessageType.COMMIT_PREPARE) { + throw new Error(`${fnTag}, message type is not COMMIT_PREPARE`); + } + + const sessionData = session.getSessionData(); + + if (sessionData == undefined) { + throw new Error( + `${fnTag}, session data not found for session id ${request.common.sessionId}`, + ); + } + + if ( + sessionData.lastSequenceNumber == undefined || + sessionData.version == undefined || + sessionData.signatures == undefined + ) { + throw new Error( + `${fnTag}, session data not loaded correctly ${request.common.sessionId}`, + ); + } + + if ( + sessionData.lastSequenceNumber + BigInt(1) != + request.common.sequenceNumber + ) { + throw new Error(`${fnTag}, sequenceNumber does not match`); + } + + if ( + getMessageHash(sessionData, MessageType.ASSERTION_RECEIPT) != + request.common.hashPreviousMessage + ) { + throw new Error(`${fnTag}, hashPreviousMessage does not match`); + } + + if (sessionData.clientGatewayPubkey != request.common.clientGatewayPubkey) { + throw new Error(`${fnTag}, clientGatewayPubkey does not match`); + } + + if (sessionData.serverGatewayPubkey != request.common.serverGatewayPubkey) { + throw new Error(`${fnTag}, serverGatewayPubkey does not match`); + } + + if ( + !verifySignature( + this.Signer, + request.common, + request.common.clientGatewayPubkey, + ) + ) { + throw new Error(`${fnTag}, message signature verification failed`); + } + + if ( + sessionData.transferContextId != undefined && + request.common.transferContextId != sessionData.transferContextId + ) { + throw new Error(`${fnTag}, transferContextId does not match`); + } + + if ( + sessionData.clientTransferNumber != undefined && + request.clientTransferNumber != sessionData.clientTransferNumber + ) { + // This does not throw an error because the clientTransferNumber is only meaningful to the client. + this.Log.info( + `${fnTag}, LockAssertionRequest clientTransferNumber does not match the one that was sent`, + ); + } + + this.Log.info( + `${fnTag}, CommitPreparationRequestMessage passed all checks.`, + ); + + return sessionData; + } + + async checkCommitFinalAssertionRequestMessage( + request: CommitFinalAssertionRequestMessage, + session: SATPSession, + ): Promise { + const stepTag = `checkCommitFinalAssertionRequestMessage()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, checkCommitFinalAssertionRequestMessage...`); + + if (request.common == undefined) { + throw new Error(`${fnTag}, message common body is missing`); + } + + if (request.common.version != SATP_VERSION) { + throw new Error(`${fnTag}, message version is not ${SATP_VERSION}`); + } + + if (request.common.messageType != MessageType.COMMIT_FINAL) { + throw new Error(`${fnTag}, message type is not COMMIT_FINAL`); + } + + const sessionData = session.getSessionData(); + + if (sessionData == undefined) { + throw new Error( + `${fnTag}, session data not found for session id ${request.common.sessionId}`, + ); + } + + if ( + sessionData.lastSequenceNumber == undefined || + sessionData.version == undefined || + sessionData.signatures == undefined + ) { + throw new Error( + `${fnTag}, session data not loaded correctly ${request.common.sessionId}`, + ); + } + + if ( + sessionData.lastSequenceNumber + BigInt(1) != + request.common.sequenceNumber + ) { + throw new Error(`${fnTag}, sequenceNumber does not match`); + } + + if ( + getMessageHash(sessionData, MessageType.COMMIT_READY) != + request.common.hashPreviousMessage + ) { + throw new Error(`${fnTag}, hashPreviousMessage does not match`); + } + + if (sessionData.clientGatewayPubkey != request.common.clientGatewayPubkey) { + throw new Error(`${fnTag}, clientGatewayPubkey does not match`); + } + + if (sessionData.serverGatewayPubkey != request.common.serverGatewayPubkey) { + throw new Error(`${fnTag}, serverGatewayPubkey does not match`); + } + + if ( + !verifySignature( + this.Signer, + request.common, + request.common.clientGatewayPubkey, + ) + ) { + throw new Error(`${fnTag}, message signature verification failed`); + } + + if ( + sessionData.transferContextId != undefined && + request.common.transferContextId != sessionData.transferContextId + ) { + throw new Error(`${fnTag}, transferContextId does not match`); + } + //todo check burn + if (request.burnAssertionClaim == undefined) { + throw new Error(`${fnTag}, mintAssertionClaims is missing`); + } + + sessionData.burnAssertionClaim = request.burnAssertionClaim; + + if (request.burnAssertionClaimFormat != undefined) { + this.Log.info( + `${fnTag}, optional variable loaded: burnAssertionClaimFormat`, + ); + sessionData.burnAssertionClaimFormat = request.burnAssertionClaimFormat; + } + + if ( + sessionData.clientTransferNumber != undefined && + request.clientTransferNumber != sessionData.clientTransferNumber + ) { + // This does not throw an error because the clientTransferNumber is only meaningful to the client. + this.Log.info( + `${fnTag}, CommitFinalAssertionRequest clientTransferNumber does not match the one that was sent`, + ); + } + + this.Log.info( + `${fnTag}, CommitFinalAssertionRequestMessage passed all checks.`, + ); + + return sessionData; + } + + async checkTransferCompleteRequestMessage( + request: TransferCompleteRequestMessage, + session: SATPSession, + ): Promise { + const stepTag = `checkTransferCompleteRequestMessage()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, checkTransferCompleteRequestMessage...`); + + if (request.common == undefined) { + throw new Error(`${fnTag}, message common body is missing`); + } + + if (request.common.version != SATP_VERSION) { + throw new Error(`${fnTag}, message version is not ${SATP_VERSION}`); + } + + if (request.common.messageType != MessageType.COMMIT_TRANSFER_COMPLETE) { + throw new Error(`${fnTag}, message type is not COMMIT_TRANSFER_COMPLETE`); + } + + this.Log.info( + `${fnTag}, TransferCompleteRequestMessage passed all checks.`, + ); + + const sessionData = session.getSessionData(); + + if (sessionData == undefined) { + throw new Error( + `${fnTag}, session data not found for session id ${request.common.sessionId}`, + ); + } + + if ( + sessionData.lastSequenceNumber == undefined || + sessionData.version == undefined || + sessionData.signatures == undefined + ) { + throw new Error( + `${fnTag}, session data not loaded correctly ${request.common.sessionId}`, + ); + } + + if ( + sessionData.lastSequenceNumber + BigInt(1) != + request.common.sequenceNumber + ) { + throw new Error(`${fnTag}, sequenceNumber does not match`); + } + + if ( + getMessageHash(sessionData, MessageType.COMMIT_FINAL) != + request.common.hashPreviousMessage + ) { + throw new Error(`${fnTag}, hashPreviousMessage does not match`); + } + + if ( + getMessageHash(sessionData, MessageType.TRANSFER_COMMENCE_REQUEST) != + request.hashTransferCommence + ) { + throw new Error(`${fnTag}, hashTransferCommence does not match`); + } + + if (sessionData.clientGatewayPubkey != request.common.clientGatewayPubkey) { + throw new Error(`${fnTag}, clientGatewayPubkey does not match`); + } + + if (sessionData.serverGatewayPubkey != request.common.serverGatewayPubkey) { + throw new Error(`${fnTag}, serverGatewayPubkey does not match`); + } + + if ( + !verifySignature( + this.Signer, + request.common, + request.common.clientGatewayPubkey, + ) + ) { + throw new Error(`${fnTag}, message signature verification failed`); + } + + this.Log.info( + `${fnTag}, TransferCompleteRequestMessage passed all checks.`, + ); + + if ( + sessionData.transferContextId != undefined && + request.common.transferContextId != sessionData.transferContextId + ) { + throw new Error(`${fnTag}, transferContextId does not match`); + } + + if ( + sessionData.clientTransferNumber != undefined && + request.clientTransferNumber != sessionData.clientTransferNumber + ) { + // This does not throw an error because the clientTransferNumber is only meaningful to the client. + this.Log.info( + `${fnTag}, TransferCompleteRequest clientTransferNumber does not match the one that was sent`, + ); + } + this.Log.info( + `${fnTag}, TransferCompleteRequestMessage passed all checks.`, + ); + + return sessionData; + } + async mintAsset(session: SATPSession): Promise { + const stepTag = `mintAsset()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + try { + this.Log.info(`${fnTag}, Minting Asset...`); + const sessionData = session.getSessionData(); + const assetId = sessionData.transferInitClaims?.digitalAssetId; + const amount = sessionData.transferInitClaims?.amountToBeneficiary; + + this.logger.debug( + `${fnTag}, Mint Asset ID: ${assetId} amount: ${amount}`, + ); + if (assetId == undefined) { + throw new Error(`${fnTag}, Asset ID is missing`); + } + + // const bridge = this.bridgeManager.getBridge( + // sessionData.recipientGatewayNetworkId, + // ); + + // sessionData.mintAssertionClaim = new MintAssertionClaim(); + // sessionData.mintAssertionClaim.receipt = await bridge.mintAsset( + // assetId, + // Number(amount), + // ); + // sessionData.mintAssertionClaim.signature = bufArray2HexStr( + // sign(this.Signer, sessionData.mintAssertionClaim.receipt), + // ); + } catch (error) { + throw new Error(`${fnTag}, Failed to process Mint Asset ${error}`); + } + } + + async assignAsset(session: SATPSession): Promise { + const stepTag = `assignAsset()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + try { + this.Log.info(`${fnTag}, Assigning Asset...`); + const sessionData = session.getSessionData(); + const assetId = sessionData.transferInitClaims?.digitalAssetId; + const amount = sessionData.transferInitClaims?.amountToBeneficiary; + const recipient = sessionData.transferInitClaims?.beneficiaryPubkey; + + if (recipient == undefined) { + throw new Error(`${fnTag}, Recipient is missing`); + } + this.logger.debug( + `${fnTag}, Assign Asset ID: ${assetId} amount: ${amount} recipient: ${recipient}`, + ); + if (assetId == undefined) { + throw new Error(`${fnTag}, Asset ID is missing`); + } + + // const bridge = this.bridgeManager.getBridge( + // sessionData.recipientGatewayNetworkId, + // ); + + // sessionData.assignmentAssertionClaim = new AssignmentAssertionClaim(); + // sessionData.assignmentAssertionClaim.receipt = await bridge.assignAsset( + // assetId, + // recipient, + // Number(amount), + // ); + // sessionData.assignmentAssertionClaim.signature = bufArray2HexStr( + // sign(this.Signer, sessionData.assignmentAssertionClaim.receipt), + // ); + } catch (error) { + throw new Error(`${fnTag}, Failed to process Assign Asset ${error}`); + } + } +} 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 91f6a20937..5278e09809 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 @@ -1,9 +1,7 @@ -import { JsObjectSigner, LogLevelDesc } from "@hyperledger/cactus-common"; +import { LogLevelDesc } from "@hyperledger/cactus-common"; import { ValidatorOptions } from "class-validator"; import { BLODispatcher } from "../blo/dispatcher"; import { ISignerKeyPairs } from "@hyperledger/cactus-common/src/main/typescript/signer-key-pairs"; -import { createConnectTransport } from "@connectrpc/connect-node"; -import { SATPManager } from "../gol/satp-manager"; 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"; @@ -83,6 +81,12 @@ export interface SATPGatewayConfig { enableOpenAPI?: boolean; validationOptions?: ValidatorOptions; } + +// export interface SATPBridgeConfig { +// logLevel?: LogLevelDesc; +// network: NetworkBridge; +// } + export type Immutable = { readonly [K in keyof T]: Immutable; }; diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/factory/plugin-factory-satp-hermes-bridge-manager.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/factory/plugin-factory-satp-hermes-bridge-manager.ts index 70b786d12e..9fd5edb890 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/factory/plugin-factory-satp-hermes-bridge-manager.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/factory/plugin-factory-satp-hermes-bridge-manager.ts @@ -1 +1,30 @@ -// TODO +import { validateOrReject } from "class-validator"; +import { + IPluginFactoryOptions, + PluginFactory, +} from "@hyperledger/cactus-core-api"; +import { + SATPBridgesManager, + ISATPBridgesOptions, +} from "../gol/satp-bridges-manager"; + +export class PluginFactorySATPBridge extends PluginFactory< + SATPBridgesManager, + ISATPBridgesOptions, + IPluginFactoryOptions +> { + async create( + pluginOptions: ISATPBridgesOptions, + ): Promise { + const manager = new SATPBridgesManager(pluginOptions); + try { + const validationOptions = pluginOptions.validationOptions; + await validateOrReject(manager, validationOptions); + return manager; + } catch (errors) { + throw new Error( + `Caught promise rejection (validation failed). Errors: ${errors}`, + ); + } + } +} diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/common/message_pb.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/common/message_pb.ts index 9d7fd15f6d..e6d0eb22c8 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/common/message_pb.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/common/message_pb.ts @@ -519,6 +519,16 @@ export class TransferClaims extends Message { */ maxTimeout = protoInt64.zero; + /** + * @generated from field: string amount_from_originator = 15; + */ + amountFromOriginator = ""; + + /** + * @generated from field: string amount_to_beneficiary = 16; + */ + amountToBeneficiary = ""; + constructor(data?: PartialMessage) { super(); proto3.util.initPartial(data, this); @@ -541,6 +551,8 @@ export class TransferClaims extends Message { { no: 12, name: "receiver_gateway_owner_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, { no: 13, name: "max_retries", kind: "scalar", T: 13 /* ScalarType.UINT32 */ }, { no: 14, name: "max_timeout", kind: "scalar", T: 4 /* ScalarType.UINT64 */ }, + { no: 15, name: "amount_from_originator", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 16, name: "amount_to_beneficiary", kind: "scalar", T: 9 /* ScalarType.STRING */ }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TransferClaims { @@ -1258,250 +1270,298 @@ export class Payload extends Message { } /** - * @generated from message cacti.satp.v02.common.LockAssertionClaim + * @generated from message cacti.satp.v02.common.LockAssertionClaimFormat */ -export class LockAssertionClaim extends Message { - constructor(data?: PartialMessage) { +export class LockAssertionClaimFormat extends Message { + constructor(data?: PartialMessage) { super(); proto3.util.initPartial(data, this); } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "cacti.satp.v02.common.LockAssertionClaim"; + static readonly typeName = "cacti.satp.v02.common.LockAssertionClaimFormat"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ ]); - static fromBinary(bytes: Uint8Array, options?: Partial): LockAssertionClaim { - return new LockAssertionClaim().fromBinary(bytes, options); + static fromBinary(bytes: Uint8Array, options?: Partial): LockAssertionClaimFormat { + return new LockAssertionClaimFormat().fromBinary(bytes, options); } - static fromJson(jsonValue: JsonValue, options?: Partial): LockAssertionClaim { - return new LockAssertionClaim().fromJson(jsonValue, options); + static fromJson(jsonValue: JsonValue, options?: Partial): LockAssertionClaimFormat { + return new LockAssertionClaimFormat().fromJson(jsonValue, options); } - static fromJsonString(jsonString: string, options?: Partial): LockAssertionClaim { - return new LockAssertionClaim().fromJsonString(jsonString, options); + static fromJsonString(jsonString: string, options?: Partial): LockAssertionClaimFormat { + return new LockAssertionClaimFormat().fromJsonString(jsonString, options); } - static equals(a: LockAssertionClaim | PlainMessage | undefined, b: LockAssertionClaim | PlainMessage | undefined): boolean { - return proto3.util.equals(LockAssertionClaim, a, b); + static equals(a: LockAssertionClaimFormat | PlainMessage | undefined, b: LockAssertionClaimFormat | PlainMessage | undefined): boolean { + return proto3.util.equals(LockAssertionClaimFormat, a, b); } } /** - * @generated from message cacti.satp.v02.common.LockAssertionFormat + * @generated from message cacti.satp.v02.common.MintAssertionClaimFormat */ -export class LockAssertionFormat extends Message { - constructor(data?: PartialMessage) { +export class MintAssertionClaimFormat extends Message { + constructor(data?: PartialMessage) { super(); proto3.util.initPartial(data, this); } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "cacti.satp.v02.common.LockAssertionFormat"; + static readonly typeName = "cacti.satp.v02.common.MintAssertionClaimFormat"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ ]); - static fromBinary(bytes: Uint8Array, options?: Partial): LockAssertionFormat { - return new LockAssertionFormat().fromBinary(bytes, options); + static fromBinary(bytes: Uint8Array, options?: Partial): MintAssertionClaimFormat { + return new MintAssertionClaimFormat().fromBinary(bytes, options); } - static fromJson(jsonValue: JsonValue, options?: Partial): LockAssertionFormat { - return new LockAssertionFormat().fromJson(jsonValue, options); + static fromJson(jsonValue: JsonValue, options?: Partial): MintAssertionClaimFormat { + return new MintAssertionClaimFormat().fromJson(jsonValue, options); } - static fromJsonString(jsonString: string, options?: Partial): LockAssertionFormat { - return new LockAssertionFormat().fromJsonString(jsonString, options); + static fromJsonString(jsonString: string, options?: Partial): MintAssertionClaimFormat { + return new MintAssertionClaimFormat().fromJsonString(jsonString, options); } - static equals(a: LockAssertionFormat | PlainMessage | undefined, b: LockAssertionFormat | PlainMessage | undefined): boolean { - return proto3.util.equals(LockAssertionFormat, a, b); + static equals(a: MintAssertionClaimFormat | PlainMessage | undefined, b: MintAssertionClaimFormat | PlainMessage | undefined): boolean { + return proto3.util.equals(MintAssertionClaimFormat, a, b); } } /** - * @generated from message cacti.satp.v02.common.MintAssertionClaims + * @generated from message cacti.satp.v02.common.BurnAssertionClaimFormat */ -export class MintAssertionClaims extends Message { - constructor(data?: PartialMessage) { +export class BurnAssertionClaimFormat extends Message { + constructor(data?: PartialMessage) { super(); proto3.util.initPartial(data, this); } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "cacti.satp.v02.common.MintAssertionClaims"; + static readonly typeName = "cacti.satp.v02.common.BurnAssertionClaimFormat"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ ]); - static fromBinary(bytes: Uint8Array, options?: Partial): MintAssertionClaims { - return new MintAssertionClaims().fromBinary(bytes, options); + static fromBinary(bytes: Uint8Array, options?: Partial): BurnAssertionClaimFormat { + return new BurnAssertionClaimFormat().fromBinary(bytes, options); } - static fromJson(jsonValue: JsonValue, options?: Partial): MintAssertionClaims { - return new MintAssertionClaims().fromJson(jsonValue, options); + static fromJson(jsonValue: JsonValue, options?: Partial): BurnAssertionClaimFormat { + return new BurnAssertionClaimFormat().fromJson(jsonValue, options); } - static fromJsonString(jsonString: string, options?: Partial): MintAssertionClaims { - return new MintAssertionClaims().fromJsonString(jsonString, options); + static fromJsonString(jsonString: string, options?: Partial): BurnAssertionClaimFormat { + return new BurnAssertionClaimFormat().fromJsonString(jsonString, options); } - static equals(a: MintAssertionClaims | PlainMessage | undefined, b: MintAssertionClaims | PlainMessage | undefined): boolean { - return proto3.util.equals(MintAssertionClaims, a, b); + static equals(a: BurnAssertionClaimFormat | PlainMessage | undefined, b: BurnAssertionClaimFormat | PlainMessage | undefined): boolean { + return proto3.util.equals(BurnAssertionClaimFormat, a, b); } } /** - * @generated from message cacti.satp.v02.common.MintAssertionClaimsFormat + * @generated from message cacti.satp.v02.common.AssignmentAssertionClaimFormat */ -export class MintAssertionClaimsFormat extends Message { - constructor(data?: PartialMessage) { +export class AssignmentAssertionClaimFormat extends Message { + constructor(data?: PartialMessage) { super(); proto3.util.initPartial(data, this); } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "cacti.satp.v02.common.MintAssertionClaimsFormat"; + static readonly typeName = "cacti.satp.v02.common.AssignmentAssertionClaimFormat"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ ]); - static fromBinary(bytes: Uint8Array, options?: Partial): MintAssertionClaimsFormat { - return new MintAssertionClaimsFormat().fromBinary(bytes, options); + static fromBinary(bytes: Uint8Array, options?: Partial): AssignmentAssertionClaimFormat { + return new AssignmentAssertionClaimFormat().fromBinary(bytes, options); } - static fromJson(jsonValue: JsonValue, options?: Partial): MintAssertionClaimsFormat { - return new MintAssertionClaimsFormat().fromJson(jsonValue, options); + static fromJson(jsonValue: JsonValue, options?: Partial): AssignmentAssertionClaimFormat { + return new AssignmentAssertionClaimFormat().fromJson(jsonValue, options); } - static fromJsonString(jsonString: string, options?: Partial): MintAssertionClaimsFormat { - return new MintAssertionClaimsFormat().fromJsonString(jsonString, options); + static fromJsonString(jsonString: string, options?: Partial): AssignmentAssertionClaimFormat { + return new AssignmentAssertionClaimFormat().fromJsonString(jsonString, options); } - static equals(a: MintAssertionClaimsFormat | PlainMessage | undefined, b: MintAssertionClaimsFormat | PlainMessage | undefined): boolean { - return proto3.util.equals(MintAssertionClaimsFormat, a, b); + static equals(a: AssignmentAssertionClaimFormat | PlainMessage | undefined, b: AssignmentAssertionClaimFormat | PlainMessage | undefined): boolean { + return proto3.util.equals(AssignmentAssertionClaimFormat, a, b); } } /** - * @generated from message cacti.satp.v02.common.BurnAssertionClaim + * @generated from message cacti.satp.v02.common.LockAssertionClaim */ -export class BurnAssertionClaim extends Message { - constructor(data?: PartialMessage) { +export class LockAssertionClaim extends Message { + /** + * @generated from field: string receipt = 1; + */ + receipt = ""; + + /** + * @generated from field: string signature = 2; + */ + signature = ""; + + constructor(data?: PartialMessage) { super(); proto3.util.initPartial(data, this); } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "cacti.satp.v02.common.BurnAssertionClaim"; + static readonly typeName = "cacti.satp.v02.common.LockAssertionClaim"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ + { no: 1, name: "receipt", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "signature", kind: "scalar", T: 9 /* ScalarType.STRING */ }, ]); - static fromBinary(bytes: Uint8Array, options?: Partial): BurnAssertionClaim { - return new BurnAssertionClaim().fromBinary(bytes, options); + static fromBinary(bytes: Uint8Array, options?: Partial): LockAssertionClaim { + return new LockAssertionClaim().fromBinary(bytes, options); } - static fromJson(jsonValue: JsonValue, options?: Partial): BurnAssertionClaim { - return new BurnAssertionClaim().fromJson(jsonValue, options); + static fromJson(jsonValue: JsonValue, options?: Partial): LockAssertionClaim { + return new LockAssertionClaim().fromJson(jsonValue, options); } - static fromJsonString(jsonString: string, options?: Partial): BurnAssertionClaim { - return new BurnAssertionClaim().fromJsonString(jsonString, options); + static fromJsonString(jsonString: string, options?: Partial): LockAssertionClaim { + return new LockAssertionClaim().fromJsonString(jsonString, options); } - static equals(a: BurnAssertionClaim | PlainMessage | undefined, b: BurnAssertionClaim | PlainMessage | undefined): boolean { - return proto3.util.equals(BurnAssertionClaim, a, b); + static equals(a: LockAssertionClaim | PlainMessage | undefined, b: LockAssertionClaim | PlainMessage | undefined): boolean { + return proto3.util.equals(LockAssertionClaim, a, b); } } /** - * @generated from message cacti.satp.v02.common.BurnAssertionClaimFormat + * @generated from message cacti.satp.v02.common.MintAssertionClaim */ -export class BurnAssertionClaimFormat extends Message { - constructor(data?: PartialMessage) { +export class MintAssertionClaim extends Message { + /** + * @generated from field: string receipt = 1; + */ + receipt = ""; + + /** + * @generated from field: string signature = 2; + */ + signature = ""; + + constructor(data?: PartialMessage) { super(); proto3.util.initPartial(data, this); } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "cacti.satp.v02.common.BurnAssertionClaimFormat"; + static readonly typeName = "cacti.satp.v02.common.MintAssertionClaim"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ + { no: 1, name: "receipt", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "signature", kind: "scalar", T: 9 /* ScalarType.STRING */ }, ]); - static fromBinary(bytes: Uint8Array, options?: Partial): BurnAssertionClaimFormat { - return new BurnAssertionClaimFormat().fromBinary(bytes, options); + static fromBinary(bytes: Uint8Array, options?: Partial): MintAssertionClaim { + return new MintAssertionClaim().fromBinary(bytes, options); } - static fromJson(jsonValue: JsonValue, options?: Partial): BurnAssertionClaimFormat { - return new BurnAssertionClaimFormat().fromJson(jsonValue, options); + static fromJson(jsonValue: JsonValue, options?: Partial): MintAssertionClaim { + return new MintAssertionClaim().fromJson(jsonValue, options); } - static fromJsonString(jsonString: string, options?: Partial): BurnAssertionClaimFormat { - return new BurnAssertionClaimFormat().fromJsonString(jsonString, options); + static fromJsonString(jsonString: string, options?: Partial): MintAssertionClaim { + return new MintAssertionClaim().fromJsonString(jsonString, options); } - static equals(a: BurnAssertionClaimFormat | PlainMessage | undefined, b: BurnAssertionClaimFormat | PlainMessage | undefined): boolean { - return proto3.util.equals(BurnAssertionClaimFormat, a, b); + static equals(a: MintAssertionClaim | PlainMessage | undefined, b: MintAssertionClaim | PlainMessage | undefined): boolean { + return proto3.util.equals(MintAssertionClaim, a, b); } } /** - * @generated from message cacti.satp.v02.common.AssignmentAssertionClaim + * @generated from message cacti.satp.v02.common.BurnAssertionClaim */ -export class AssignmentAssertionClaim extends Message { - constructor(data?: PartialMessage) { +export class BurnAssertionClaim extends Message { + /** + * @generated from field: string receipt = 1; + */ + receipt = ""; + + /** + * @generated from field: string signature = 2; + */ + signature = ""; + + constructor(data?: PartialMessage) { super(); proto3.util.initPartial(data, this); } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "cacti.satp.v02.common.AssignmentAssertionClaim"; + static readonly typeName = "cacti.satp.v02.common.BurnAssertionClaim"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ + { no: 1, name: "receipt", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "signature", kind: "scalar", T: 9 /* ScalarType.STRING */ }, ]); - static fromBinary(bytes: Uint8Array, options?: Partial): AssignmentAssertionClaim { - return new AssignmentAssertionClaim().fromBinary(bytes, options); + static fromBinary(bytes: Uint8Array, options?: Partial): BurnAssertionClaim { + return new BurnAssertionClaim().fromBinary(bytes, options); } - static fromJson(jsonValue: JsonValue, options?: Partial): AssignmentAssertionClaim { - return new AssignmentAssertionClaim().fromJson(jsonValue, options); + static fromJson(jsonValue: JsonValue, options?: Partial): BurnAssertionClaim { + return new BurnAssertionClaim().fromJson(jsonValue, options); } - static fromJsonString(jsonString: string, options?: Partial): AssignmentAssertionClaim { - return new AssignmentAssertionClaim().fromJsonString(jsonString, options); + static fromJsonString(jsonString: string, options?: Partial): BurnAssertionClaim { + return new BurnAssertionClaim().fromJsonString(jsonString, options); } - static equals(a: AssignmentAssertionClaim | PlainMessage | undefined, b: AssignmentAssertionClaim | PlainMessage | undefined): boolean { - return proto3.util.equals(AssignmentAssertionClaim, a, b); + static equals(a: BurnAssertionClaim | PlainMessage | undefined, b: BurnAssertionClaim | PlainMessage | undefined): boolean { + return proto3.util.equals(BurnAssertionClaim, a, b); } } /** - * @generated from message cacti.satp.v02.common.AssignmentAssertionClaimFormat + * @generated from message cacti.satp.v02.common.AssignmentAssertionClaim */ -export class AssignmentAssertionClaimFormat extends Message { - constructor(data?: PartialMessage) { +export class AssignmentAssertionClaim extends Message { + /** + * @generated from field: string receipt = 1; + */ + receipt = ""; + + /** + * @generated from field: string signature = 2; + */ + signature = ""; + + constructor(data?: PartialMessage) { super(); proto3.util.initPartial(data, this); } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "cacti.satp.v02.common.AssignmentAssertionClaimFormat"; + static readonly typeName = "cacti.satp.v02.common.AssignmentAssertionClaim"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ + { no: 1, name: "receipt", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "signature", kind: "scalar", T: 9 /* ScalarType.STRING */ }, ]); - static fromBinary(bytes: Uint8Array, options?: Partial): AssignmentAssertionClaimFormat { - return new AssignmentAssertionClaimFormat().fromBinary(bytes, options); + static fromBinary(bytes: Uint8Array, options?: Partial): AssignmentAssertionClaim { + return new AssignmentAssertionClaim().fromBinary(bytes, options); } - static fromJson(jsonValue: JsonValue, options?: Partial): AssignmentAssertionClaimFormat { - return new AssignmentAssertionClaimFormat().fromJson(jsonValue, options); + static fromJson(jsonValue: JsonValue, options?: Partial): AssignmentAssertionClaim { + return new AssignmentAssertionClaim().fromJson(jsonValue, options); } - static fromJsonString(jsonString: string, options?: Partial): AssignmentAssertionClaimFormat { - return new AssignmentAssertionClaimFormat().fromJsonString(jsonString, options); + static fromJsonString(jsonString: string, options?: Partial): AssignmentAssertionClaim { + return new AssignmentAssertionClaim().fromJsonString(jsonString, options); } - static equals(a: AssignmentAssertionClaimFormat | PlainMessage | undefined, b: AssignmentAssertionClaimFormat | PlainMessage | undefined): boolean { - return proto3.util.equals(AssignmentAssertionClaimFormat, a, b); + static equals(a: AssignmentAssertionClaim | PlainMessage | undefined, b: AssignmentAssertionClaim | PlainMessage | undefined): boolean { + return proto3.util.equals(AssignmentAssertionClaim, a, b); } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/common/session_pb.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/common/session_pb.ts index f715a7cf52..a66127f94a 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/common/session_pb.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/common/session_pb.ts @@ -5,7 +5,7 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; import { Message, proto3, protoInt64 } from "@bufbuild/protobuf"; -import { AssignmentAssertionClaim, AssignmentAssertionClaimFormat, BurnAssertionClaim, BurnAssertionClaimFormat, CredentialProfile, History, LockAssertionClaim, LockAssertionFormat, LockType, MintAssertionClaims, MintAssertionClaimsFormat, PayloadProfile, Permissions, SignatureAlgorithm, SubsequentCalls, TransferClaimsFormat } from "./message_pb.js"; +import { AssetProfile, AssignmentAssertionClaim, AssignmentAssertionClaimFormat, BurnAssertionClaim, BurnAssertionClaimFormat, CredentialProfile, History, LockAssertionClaim, LockAssertionClaimFormat, LockType, MintAssertionClaim, MintAssertionClaimFormat, PayloadProfile, Permissions, SignatureAlgorithm, SubsequentCalls, TransferClaims, TransferClaimsFormat } from "./message_pb.js"; /** * @generated from enum cacti.satp.v02.common.ACCEPTANCE @@ -183,135 +183,160 @@ export class SessionData extends Message { hashTransferInitClaims = ""; /** - * @generated from field: string proposed_transfer_init_claims = 30; + * @generated from field: cacti.satp.v02.common.TransferClaims transfer_init_claims = 30; + */ + transferInitClaims?: TransferClaims; + + /** + * @generated from field: string proposed_transfer_init_claims = 31; */ proposedTransferInitClaims = ""; /** - * @generated from field: cacti.satp.v02.common.SignatureAlgorithm signature_algorithm = 31; + * @generated from field: cacti.satp.v02.common.SignatureAlgorithm signature_algorithm = 32; */ signatureAlgorithm = SignatureAlgorithm.UNSPECIFIED; /** - * @generated from field: cacti.satp.v02.common.LockType lock_type = 32; + * @generated from field: cacti.satp.v02.common.LockType lock_type = 33; */ lockType = LockType.UNSPECIFIED; /** - * @generated from field: uint64 lock_expiration_time = 33; + * @generated from field: uint64 lock_expiration_time = 34; */ lockExpirationTime = protoInt64.zero; /** - * @generated from field: cacti.satp.v02.common.Permissions permissions = 34; + * @generated from field: cacti.satp.v02.common.Permissions permissions = 35; */ permissions?: Permissions; /** - * @generated from field: string developer_urn = 35; + * @generated from field: string developer_urn = 36; */ developerUrn = ""; /** - * @generated from field: cacti.satp.v02.common.CredentialProfile credential_profile = 36; + * @generated from field: cacti.satp.v02.common.CredentialProfile credential_profile = 37; */ credentialProfile = CredentialProfile.UNSPECIFIED; /** - * @generated from field: cacti.satp.v02.common.SubsequentCalls subsequent_calls = 37; + * @generated from field: cacti.satp.v02.common.SubsequentCalls subsequent_calls = 38; */ subsequentCalls?: SubsequentCalls; /** - * @generated from field: repeated cacti.satp.v02.common.History history = 38; + * @generated from field: repeated cacti.satp.v02.common.History history = 39; */ history: History[] = []; /** - * @generated from field: bool multiple_claims_allowed = 39; + * @generated from field: bool multiple_claims_allowed = 40; */ multipleClaimsAllowed = false; /** - * @generated from field: bool multiple_cancels_allowed = 40; + * @generated from field: bool multiple_cancels_allowed = 41; */ multipleCancelsAllowed = false; /** - * @generated from field: string last_message_received_timestamp = 41; + * @generated from field: string last_message_received_timestamp = 42; */ lastMessageReceivedTimestamp = ""; /** - * @generated from field: cacti.satp.v02.common.MessageStagesTimestamps processed_timestamps = 42; + * @generated from field: cacti.satp.v02.common.MessageStagesTimestamps processed_timestamps = 43; */ processedTimestamps?: MessageStagesTimestamps; /** - * @generated from field: cacti.satp.v02.common.MessageStagesTimestamps received_timestamps = 43; + * @generated from field: cacti.satp.v02.common.MessageStagesTimestamps received_timestamps = 44; */ receivedTimestamps?: MessageStagesTimestamps; /** - * @generated from field: cacti.satp.v02.common.LockAssertionClaim lock_assertion_claim = 44; + * @generated from field: cacti.satp.v02.common.LockAssertionClaim lock_assertion_claim = 45; */ lockAssertionClaim?: LockAssertionClaim; /** - * @generated from field: cacti.satp.v02.common.LockAssertionFormat lock_assertion_format = 45; + * @generated from field: cacti.satp.v02.common.LockAssertionClaimFormat lock_assertion_claim_format = 46; */ - lockAssertionFormat?: LockAssertionFormat; + lockAssertionClaimFormat?: LockAssertionClaimFormat; /** - * @generated from field: cacti.satp.v02.common.MintAssertionClaims mint_assertion_claims = 46; + * @generated from field: cacti.satp.v02.common.MintAssertionClaim mint_assertion_claim = 47; */ - mintAssertionClaims?: MintAssertionClaims; + mintAssertionClaim?: MintAssertionClaim; /** - * @generated from field: cacti.satp.v02.common.MintAssertionClaimsFormat mint_assertion_claims_format = 47; + * @generated from field: cacti.satp.v02.common.MintAssertionClaimFormat mint_assertion_claim_format = 48; */ - mintAssertionClaimsFormat?: MintAssertionClaimsFormat; + mintAssertionClaimFormat?: MintAssertionClaimFormat; /** - * @generated from field: cacti.satp.v02.common.BurnAssertionClaim burn_assertion_claim = 48; + * @generated from field: cacti.satp.v02.common.BurnAssertionClaim burn_assertion_claim = 49; */ burnAssertionClaim?: BurnAssertionClaim; /** - * @generated from field: cacti.satp.v02.common.BurnAssertionClaimFormat burn_assertion_claim_format = 49; + * @generated from field: cacti.satp.v02.common.BurnAssertionClaimFormat burn_assertion_claim_format = 50; */ burnAssertionClaimFormat?: BurnAssertionClaimFormat; /** - * @generated from field: cacti.satp.v02.common.AssignmentAssertionClaim assignment_assertion_claim = 50; + * @generated from field: cacti.satp.v02.common.AssignmentAssertionClaim assignment_assertion_claim = 51; */ assignmentAssertionClaim?: AssignmentAssertionClaim; /** - * @generated from field: cacti.satp.v02.common.AssignmentAssertionClaimFormat assignment_assertion_claim_format = 51; + * @generated from field: cacti.satp.v02.common.AssignmentAssertionClaimFormat assignment_assertion_claim_format = 52; */ assignmentAssertionClaimFormat?: AssignmentAssertionClaimFormat; /** - * @generated from field: bool completed = 52; + * @generated from field: bool completed = 53; */ completed = false; /** - * @generated from field: cacti.satp.v02.common.ACCEPTANCE acceptance = 53; + * @generated from field: cacti.satp.v02.common.ACCEPTANCE acceptance = 54; */ acceptance = ACCEPTANCE.ACCEPTANCE_REJECTED; /** - * @generated from field: string last_message_hash = 54; + * @generated from field: string last_message_hash = 55; */ lastMessageHash = ""; /** - * @generated from field: cacti.satp.v02.common.TransferClaimsFormat transfer_claims_format = 55; + * @generated from field: cacti.satp.v02.common.TransferClaimsFormat transfer_claims_format = 56; */ transferClaimsFormat?: TransferClaimsFormat; + /** + * @generated from field: string client_transfer_number = 57; + */ + clientTransferNumber = ""; + + /** + * @generated from field: string server_transfer_number = 58; + */ + serverTransferNumber = ""; + + /** + * @generated from field: string lock_assertion_expiration = 59; + */ + lockAssertionExpiration = ""; + + /** + * @generated from field: cacti.satp.v02.common.AssetProfile asset_profile = 60; + */ + assetProfile?: AssetProfile; + constructor(data?: PartialMessage) { super(); proto3.util.initPartial(data, this); @@ -349,32 +374,37 @@ export class SessionData extends Message { { no: 27, name: "sender_gateway_owner_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, { no: 28, name: "receiver_gateway_owner_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, { no: 29, name: "hash_transfer_init_claims", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 30, name: "proposed_transfer_init_claims", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 31, name: "signature_algorithm", kind: "enum", T: proto3.getEnumType(SignatureAlgorithm) }, - { no: 32, name: "lock_type", kind: "enum", T: proto3.getEnumType(LockType) }, - { no: 33, name: "lock_expiration_time", kind: "scalar", T: 4 /* ScalarType.UINT64 */ }, - { no: 34, name: "permissions", kind: "message", T: Permissions }, - { no: 35, name: "developer_urn", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 36, name: "credential_profile", kind: "enum", T: proto3.getEnumType(CredentialProfile) }, - { no: 37, name: "subsequent_calls", kind: "message", T: SubsequentCalls }, - { no: 38, name: "history", kind: "message", T: History, repeated: true }, - { no: 39, name: "multiple_claims_allowed", kind: "scalar", T: 8 /* ScalarType.BOOL */ }, - { no: 40, name: "multiple_cancels_allowed", kind: "scalar", T: 8 /* ScalarType.BOOL */ }, - { no: 41, name: "last_message_received_timestamp", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 42, name: "processed_timestamps", kind: "message", T: MessageStagesTimestamps }, - { no: 43, name: "received_timestamps", kind: "message", T: MessageStagesTimestamps }, - { no: 44, name: "lock_assertion_claim", kind: "message", T: LockAssertionClaim }, - { no: 45, name: "lock_assertion_format", kind: "message", T: LockAssertionFormat }, - { no: 46, name: "mint_assertion_claims", kind: "message", T: MintAssertionClaims }, - { no: 47, name: "mint_assertion_claims_format", kind: "message", T: MintAssertionClaimsFormat }, - { no: 48, name: "burn_assertion_claim", kind: "message", T: BurnAssertionClaim }, - { no: 49, name: "burn_assertion_claim_format", kind: "message", T: BurnAssertionClaimFormat }, - { no: 50, name: "assignment_assertion_claim", kind: "message", T: AssignmentAssertionClaim }, - { no: 51, name: "assignment_assertion_claim_format", kind: "message", T: AssignmentAssertionClaimFormat }, - { no: 52, name: "completed", kind: "scalar", T: 8 /* ScalarType.BOOL */ }, - { no: 53, name: "acceptance", kind: "enum", T: proto3.getEnumType(ACCEPTANCE) }, - { no: 54, name: "last_message_hash", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 55, name: "transfer_claims_format", kind: "message", T: TransferClaimsFormat }, + { no: 30, name: "transfer_init_claims", kind: "message", T: TransferClaims }, + { no: 31, name: "proposed_transfer_init_claims", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 32, name: "signature_algorithm", kind: "enum", T: proto3.getEnumType(SignatureAlgorithm) }, + { no: 33, name: "lock_type", kind: "enum", T: proto3.getEnumType(LockType) }, + { no: 34, name: "lock_expiration_time", kind: "scalar", T: 4 /* ScalarType.UINT64 */ }, + { no: 35, name: "permissions", kind: "message", T: Permissions }, + { no: 36, name: "developer_urn", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 37, name: "credential_profile", kind: "enum", T: proto3.getEnumType(CredentialProfile) }, + { no: 38, name: "subsequent_calls", kind: "message", T: SubsequentCalls }, + { no: 39, name: "history", kind: "message", T: History, repeated: true }, + { no: 40, name: "multiple_claims_allowed", kind: "scalar", T: 8 /* ScalarType.BOOL */ }, + { no: 41, name: "multiple_cancels_allowed", kind: "scalar", T: 8 /* ScalarType.BOOL */ }, + { no: 42, name: "last_message_received_timestamp", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 43, name: "processed_timestamps", kind: "message", T: MessageStagesTimestamps }, + { no: 44, name: "received_timestamps", kind: "message", T: MessageStagesTimestamps }, + { no: 45, name: "lock_assertion_claim", kind: "message", T: LockAssertionClaim }, + { no: 46, name: "lock_assertion_claim_format", kind: "message", T: LockAssertionClaimFormat }, + { no: 47, name: "mint_assertion_claim", kind: "message", T: MintAssertionClaim }, + { no: 48, name: "mint_assertion_claim_format", kind: "message", T: MintAssertionClaimFormat }, + { no: 49, name: "burn_assertion_claim", kind: "message", T: BurnAssertionClaim }, + { no: 50, name: "burn_assertion_claim_format", kind: "message", T: BurnAssertionClaimFormat }, + { no: 51, name: "assignment_assertion_claim", kind: "message", T: AssignmentAssertionClaim }, + { no: 52, name: "assignment_assertion_claim_format", kind: "message", T: AssignmentAssertionClaimFormat }, + { no: 53, name: "completed", kind: "scalar", T: 8 /* ScalarType.BOOL */ }, + { no: 54, name: "acceptance", kind: "enum", T: proto3.getEnumType(ACCEPTANCE) }, + { no: 55, name: "last_message_hash", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 56, name: "transfer_claims_format", kind: "message", T: TransferClaimsFormat }, + { no: 57, name: "client_transfer_number", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 58, name: "server_transfer_number", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 59, name: "lock_assertion_expiration", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 60, name: "asset_profile", kind: "message", T: AssetProfile }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): SessionData { diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_1_pb.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_1_pb.ts index fac231eed5..4a6e7dc4cd 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_1_pb.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_1_pb.ts @@ -187,6 +187,11 @@ export class TransferCommenceResponseMessage extends Message) { super(); proto3.util.initPartial(data, this); @@ -196,6 +201,7 @@ export class TransferCommenceResponseMessage extends Message [ { no: 1, name: "common", kind: "message", T: CommonSatp }, + { no: 2, name: "server_transfer_number", kind: "scalar", T: 9 /* ScalarType.STRING */ }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TransferCommenceResponseMessage { diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_2_pb.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_2_pb.ts index a7e91edc78..2fb9380d15 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_2_pb.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_2_pb.ts @@ -5,7 +5,7 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; import { Message, proto3 } from "@bufbuild/protobuf"; -import { CommonSatp, LockAssertionClaim, LockAssertionFormat } from "./common/message_pb.js"; +import { CommonSatp, LockAssertionClaim, LockAssertionClaimFormat } from "./common/message_pb.js"; /** * @generated from message cacti.satp.v02.LockAssertionRequestMessage @@ -22,9 +22,9 @@ export class LockAssertionRequestMessage extends Message [ { no: 1, name: "common", kind: "message", T: CommonSatp }, { no: 2, name: "lock_assertion_claim", kind: "message", T: LockAssertionClaim }, - { no: 3, name: "lock_assertion_format", kind: "message", T: LockAssertionFormat }, + { no: 3, name: "lock_assertion_claim_format", kind: "message", T: LockAssertionClaimFormat }, { no: 4, name: "lock_assertion_expiration", kind: "scalar", T: 9 /* ScalarType.STRING */ }, { no: 5, name: "client_transfer_number", kind: "scalar", T: 9 /* ScalarType.STRING */ }, { no: 6, name: "client_signature", kind: "scalar", T: 9 /* ScalarType.STRING */ }, diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_3_pb.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_3_pb.ts index 7c4c0246fe..5e64da5a95 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_3_pb.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_3_pb.ts @@ -5,7 +5,7 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; import { Message, proto3 } from "@bufbuild/protobuf"; -import { AssignmentAssertionClaim, AssignmentAssertionClaimFormat, BurnAssertionClaim, BurnAssertionClaimFormat, CommonSatp, MintAssertionClaims, MintAssertionClaimsFormat } from "./common/message_pb.js"; +import { AssignmentAssertionClaim, AssignmentAssertionClaimFormat, BurnAssertionClaim, BurnAssertionClaimFormat, CommonSatp, MintAssertionClaim, MintAssertionClaimFormat } from "./common/message_pb.js"; /** * @generated from message cacti.satp.v02.CommitPreparationRequestMessage @@ -66,14 +66,14 @@ export class CommitReadyResponseMessage extends Message [ { no: 1, name: "common", kind: "message", T: CommonSatp }, - { no: 2, name: "mint_assertion_claims", kind: "message", T: MintAssertionClaims }, - { no: 3, name: "mint_assertion_claims_format", kind: "message", T: MintAssertionClaimsFormat }, + { no: 2, name: "mint_assertion_claim", kind: "message", T: MintAssertionClaim }, + { no: 3, name: "mint_assertion_claim_format", kind: "message", T: MintAssertionClaimFormat }, { no: 4, name: "server_transfer_number", kind: "scalar", T: 9 /* ScalarType.STRING */ }, { no: 5, name: "server_signature", kind: "scalar", T: 9 /* ScalarType.STRING */ }, ]); diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/gol/satp-bridges-manager.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/gol/satp-bridges-manager.ts new file mode 100644 index 0000000000..22f63d434f --- /dev/null +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/gol/satp-bridges-manager.ts @@ -0,0 +1,92 @@ +import { + LogLevelDesc, + Logger, + LoggerProvider, +} from "@hyperledger/cactus-common"; +// import { BesuBridge } from "../core/stage-services/satp-bridge/besu-bridge"; +// import { FabricBridge } from "../core/stage-services/satp-bridge/fabric-bridge"; +// import { NetworkBridge } from "../core/stage-services/satp-bridge/network-bridge-interface"; +// import { SATPBridge } from "../core/stage-services/satp-bridge/satp-bridge"; +import { SupportedChain } from "../core/types"; +// import { +// FabricConfig, +// BesuConfig, +// BridgeConfig, +// } from "../types/blockchain-interaction"; +import { ValidatorOptions } from "class-validator"; + +export interface ISATPBridgesOptions { + logLevel?: LogLevelDesc; + //networks: BridgeConfig[]; + validationOptions?: ValidatorOptions; + supportedDLTs: SupportedChain[]; +} + +export class SATPBridgesManager { + static CLASS_NAME: string = "SATPBridgesManager"; + + // bridges: Map = new Map(); + log: Logger; + + constructor(private config: ISATPBridgesOptions) { + this.log = LoggerProvider.getOrCreate({ + level: config.logLevel, + label: SATPBridgesManager.CLASS_NAME, + }); + + // config.networks.map((bridgeConfig) => { + // let bridge: NetworkBridge; + // switch (bridgeConfig.network) { + // case SupportedChain.FABRIC: + // bridge = new FabricBridge(bridgeConfig as FabricConfig); + // break; + // case SupportedChain.BESU: + // bridge = new BesuBridge(bridgeConfig as BesuConfig); + // break; + // default: + // throw new Error(`Unsupported network: ${bridgeConfig.network}`); + // } + // const config: SATPBridgeConfig = { + // network: bridge, + // logLevel: bridgeConfig.logLevel, + // }; + // const satp = new SATPBridge(config); + // this.bridges.set(bridgeConfig.network, satp); + // }); + } + + // public getBridge(network: string): SATPBridge { + // if (!this.bridges.has(network)) { + // throw new Error(`Bridge for network ${network} not found`); + // } + // return this.bridges.get(network) as SATPBridge; + // } + + // public getBridgesList(): string[] { + // return Array.from(this.bridges.keys()); + // } + + // public addBridgeFromConfig(bridgeConfig: BridgeConfig) { + // let bridge: NetworkBridge; + // switch (bridgeConfig.network) { + // case SupportedChain.FABRIC: + // bridge = new FabricBridge(bridgeConfig as FabricConfig); + // break; + // case SupportedChain.BESU: + // bridge = new BesuBridge(bridgeConfig as BesuConfig); + // break; + // default: + // throw new Error(`Unsupported network: ${bridgeConfig.network}`); + // } + // const config: SATPBridgeConfig = { + // network: bridge, + // logLevel: bridgeConfig.logLevel, + // }; + // const satp = new SATPBridge(config); + // this.bridges.set(bridgeConfig.network, satp); + // } + + // public addBridge(network: string, bridge: SATPBridge): void { + // this.bridges.set(network, bridge); + // } +} 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 543c4a2291..5a0a645d7a 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 @@ -8,13 +8,13 @@ import { import { Stage1SATPHandler } from "../core/stage-handlers/stage1-handler"; import { Stage1ServerService } from "../core/stage-services/server/stage1-server-service"; -// import { Stage2ServerService } from "../core/stage-services/server/stage2-server-service"; -// import { Stage3ServerService } from "../core/stage-services/server/stage3-server-service"; +import { Stage2ServerService } from "../core/stage-services/server/stage2-server-service"; +import { Stage3ServerService } from "../core/stage-services/server/stage3-server-service"; import { SATPSession } from "../core/satp-session"; import { SupportedChain } from "../core/types"; import { Stage1ClientService } from "../core/stage-services/client/stage1-client-service"; -// import { Stage2ClientService } from "../core/stage-services/client/stage2-client-service"; -// import { Stage3ClientService } from "../core/stage-services/client/stage3-client-service"; +import { Stage2ClientService } from "../core/stage-services/client/stage2-client-service"; +import { Stage3ClientService } from "../core/stage-services/client/stage3-client-service"; import { SATPService, SATPHandler, @@ -22,6 +22,9 @@ import { SATPHandlerOptions, } from "../types/satp-protocol"; import { ISATPServiceOptions } 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"; export interface ISATPManagerOptions { logLevel?: LogLevelDesc; @@ -29,6 +32,7 @@ export interface ISATPManagerOptions { sessions?: Map; signer: JsObjectSigner; supportedDLTs: SupportedChain[]; + bridgeManager: SATPBridgesManager; } export class SATPManager { @@ -39,9 +43,13 @@ export class SATPManager { private signer: JsObjectSigner; public supportedDLTs: SupportedChain[] = []; private sessions: Map; + private handlers: SATPHandler[] = []; + + private readonly bridgeManager: SATPBridgesManager; private readonly satpServices: SATPService[] = []; - private readonly satpHandlers: SATPHandler[] = []; + private readonly satpHandlers: Map> = + new Map(); constructor(public readonly options: ISATPManagerOptions) { const fnTag = `${SATPManager.CLASS_NAME}#constructor()`; @@ -54,15 +62,23 @@ export class SATPManager { this.logger.info(`Instantiated ${this.className} OK`); this.supportedDLTs = options.supportedDLTs; this.signer = options.signer; + this.bridgeManager = options.bridgeManager; this.sessions = options.sessions || new Map(); const handlersClasses = [ Stage1SATPHandler, - // Stage2SATPHandler, - // Stage3SATPHandler, + Stage2SATPHandler, + Stage3SATPHandler, ]; - const serviceClasses = [Stage1ServerService, Stage1ClientService]; + const serviceClasses = [ + Stage1ServerService, + Stage1ClientService, + Stage2ServerService, + Stage2ClientService, + Stage3ServerService, + Stage3ClientService, + ]; const serviceOptions = this.initializeServiceOptions( serviceClasses, @@ -83,8 +99,18 @@ export class SATPManager { level, ); - const handlers = this.initializeHandlers(handlersClasses, handlersOptions); - this.satpHandlers = handlers; + this.handlers = this.initializeHandlers(handlersClasses, handlersOptions); + + for (const handler of this.handlers) { + const sessionId = mockSession.getSessionData().id; + const handlerMap = this.satpHandlers.get(sessionId); + if (handlerMap == undefined) { + this.satpHandlers.set(sessionId, new Map()); + } + this.satpHandlers + .get(sessionId) + ?.set(handler.getHandlerIdentifier(), handler); + } } public getServiceByStage( @@ -126,6 +152,12 @@ export class SATPManager { return this.supportedDLTs; } + public getSATPHandlers( + sessionId: string, + ): Map | undefined { + return this.satpHandlers.get(sessionId); + } + public getOrCreateSession( sessionId?: string, contextID?: string, @@ -155,7 +187,7 @@ export class SATPManager { return this.endpoints; } - this.endpoints = this.satpHandlers; + this.endpoints = this.handlers; return this.endpoints; } @@ -175,6 +207,7 @@ export class SATPManager { serviceName: `Service-${index}`, serviceType: index % 2 === 0 ? SATPServiceType.Server : SATPServiceType.Client, + bridgeManager: this.bridgeManager, })); } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/plugin-satp-hermes-gateway.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/plugin-satp-hermes-gateway.ts index d271213457..55bee1be83 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/plugin-satp-hermes-gateway.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/plugin-satp-hermes-gateway.ts @@ -41,16 +41,18 @@ import { ILocalLogRepository, IRemoteLogRepository, } from "./repository/interfaces/repository"; -import { SATPLedgerConnector } from "./types/blockchain-interaction"; import { BLODispatcher, BLODispatcherOptions } from "./blo/dispatcher"; import fs from "fs"; import swaggerUi, { JsonObject } from "swagger-ui-express"; -import { SATPSession } from "./core/satp-session"; import { IPluginWebService, ICactusPlugin, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; +import { + ISATPBridgesOptions, + SATPBridgesManager, +} from "./gol/satp-bridges-manager"; export class SATPGateway implements IPluginWebService, ICactusPlugin { // todo more checks; example port from config is between 3000 and 9000 @@ -72,6 +74,7 @@ export class SATPGateway implements IPluginWebService, ICactusPlugin { public readonly instanceId: string; private supportedDltIDs: SupportedChain[]; private gatewayOrchestrator: GatewayOrchestrator; + private bridgesManager: SATPBridgesManager; private BLOApplication?: Express; private BLOServer?: http.Server; @@ -120,6 +123,12 @@ export class SATPGateway implements IPluginWebService, ICactusPlugin { signer: this.signer!, }; + const bridgesManagerOptions: ISATPBridgesOptions = { + logLevel: this.config.logLevel, + supportedDLTs: this.config.gid!.supportedDLTs, + // networks: [], //todo add networks + }; + if (this.config.gid) { this.logger.info( "Initializing gateway connection manager with seed gateways", @@ -131,6 +140,12 @@ export class SATPGateway implements IPluginWebService, ICactusPlugin { throw new Error("GatewayIdentity is not defined"); } + this.bridgesManager = new SATPBridgesManager(bridgesManagerOptions); + + if (!this.bridgesManager) { + throw new Error("BridgesManager is not defined"); + } + this.instanceId = uuidv4(); const dispatcherOps: BLODispatcherOptions = { logger: this.logger, @@ -138,6 +153,7 @@ export class SATPGateway implements IPluginWebService, ICactusPlugin { instanceId: this.config.gid!.id, orchestrator: this.gatewayOrchestrator, signer: this.signer, + bridgesManager: this.bridgesManager, }; this.supportedDltIDs = this.config.gid!.supportedDLTs; diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/types/blockchain-interaction.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/types/blockchain-interaction.ts deleted file mode 100644 index dc5fe3181d..0000000000 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/types/blockchain-interaction.ts +++ /dev/null @@ -1,5 +0,0 @@ -// TODO: define alias types for SATPLedgerConnector, which encapsulates IPluginLedgerConnector -// inject gateway, get connectors -export type SATPLedgerConnector = string; - -// TODO Define lock interfaces and strategy pattern for locking (as function of locking blockchain) (see what smart contract implementations return) 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 cab98da467..9fbe9a40dc 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 @@ -1,9 +1,4 @@ -import { - ILoggerOptions, - JsObjectSigner, - LogLevelDesc, - Logger, -} from "@hyperledger/cactus-common"; +import { ILoggerOptions } from "@hyperledger/cactus-common"; import { SupportedChain } from "../core/types"; import { ConnectRouter } from "@connectrpc/connect"; import { SATPSession } from "../core/satp-session"; @@ -20,6 +15,7 @@ import { export interface SATPHandler { setupRouter(router: ConnectRouter): void; getHandlerIdentifier(): string; + getSessionId(): string; } export interface SATPHandlerOptions { diff --git a/yarn.lock b/yarn.lock index 98ab5bdfa3..6268538d8e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4980,12 +4980,10 @@ __metadata: languageName: node linkType: hard -"@cspell/cspell-resolver@npm:8.10.4": - version: 8.10.4 - resolution: "@cspell/cspell-resolver@npm:8.10.4" - dependencies: - global-directory: "npm:^4.0.1" - checksum: 10/80ec4da36bc58f48b5ef9453cf9a2b42169869f8c63b9b253af1bd62138d3130c8a13f040f4fd97564bd51a9555a5aa0ee723ed63c371d177a26f0befa614910 +"@cspell/dict-ada@npm:^2.0.0": + version: 2.0.1 + resolution: "@cspell/dict-ada@npm:2.0.1" + checksum: 10/3e29199a5c65cdc2e9e5bb812b4d11a65034d15e74485dd644eef5525e1ad839af3df583aac1097b8571740db5107a21697d46e5c49e4064c8988e537a849793 languageName: node linkType: hard @@ -5031,17 +5029,17 @@ __metadata: languageName: node linkType: hard -"@cspell/dict-cpp@npm:^5.1.10": - version: 5.1.10 - resolution: "@cspell/dict-cpp@npm:5.1.10" - checksum: 10/ba8727af8ab3ac18f0ba030f043378bb6c951d819b7fba0114ca9377271752d04c1b3b6dfe4f9384fc35069ab7ff671313bc681a06345ef6625be7ca7fc37132 +"@cspell/dict-css@npm:^2.0.0": + version: 2.1.0 + resolution: "@cspell/dict-css@npm:2.1.0" + checksum: 10/7cf5ada8e72c3bfa12192b1d5d34d23eb3711b5d374cd8653007af157640cd0610f3760821f6a4f29cec82197450563303c5829c2b38400eb0373b87a2dbda7b languageName: node linkType: hard -"@cspell/dict-cryptocurrencies@npm:^5.0.0": - version: 5.0.0 - resolution: "@cspell/dict-cryptocurrencies@npm:5.0.0" - checksum: 10/116e7f117b59ea4c9fa7ae1c3b47fc963e050448d43e059fb93731a256881ee262420edd5b9701ffe88af3d5e95b0337fc99b4dde1b0283ee0aaed45b23e281e +"@cspell/dict-dart@npm:^1.1.0": + version: 1.1.1 + resolution: "@cspell/dict-dart@npm:1.1.1" + checksum: 10/94594c6605225b516d325b9b13459344f1c95281d539e11fe9b002af04750b6d2f7c191caffa396cb6d3b9dd97954f1d17efcc2b8d4dd2163f9f26d50cb89b73 languageName: node linkType: hard @@ -5122,17 +5120,17 @@ __metadata: languageName: node linkType: hard -"@cspell/dict-filetypes@npm:^3.0.4": - version: 3.0.4 - resolution: "@cspell/dict-filetypes@npm:3.0.4" - checksum: 10/d5e8e46f9caf40c895326c7557f42c0648458717f79d9f41f145170dbe36ec9e21dea322117a92a6a904385dfb3efd0dd63a349edf705c6cc4255861f8b97cce +"@cspell/dict-filetypes@npm:^2.0.1": + version: 2.1.1 + resolution: "@cspell/dict-filetypes@npm:2.1.1" + checksum: 10/37f03c40f4c2472c73ea734741303d3914ec4234eee08136b86b9224bb91234778d49a068c00303ed8f221dc042a9245e6d80adebd0ce8d173e256fa8484b935 languageName: node linkType: hard -"@cspell/dict-fonts@npm:^4.0.0": - version: 4.0.0 - resolution: "@cspell/dict-fonts@npm:4.0.0" - checksum: 10/894a31f3df8e3a43a3dcf13e1706eb94cb5e83bd6d2aa26b0e9fc79c2de304eb5e9118eec4dff6a673e2a3243c842ca694c8e0f3c0ad78301004f983acf53832 +"@cspell/dict-fonts@npm:^2.0.0": + version: 2.1.0 + resolution: "@cspell/dict-fonts@npm:2.1.0" + checksum: 10/121eaab7406af7aa07de6052d0dbc277279e35da6720a14979009af71d9de393cc5c3f7359f7288c73eced8caef6fdd06e5bad9bbf650d107a21746fb6dd1591 languageName: node linkType: hard @@ -5185,10 +5183,10 @@ __metadata: languageName: node linkType: hard -"@cspell/dict-html-symbol-entities@npm:^4.0.0": - version: 4.0.0 - resolution: "@cspell/dict-html-symbol-entities@npm:4.0.0" - checksum: 10/79f05f9080f39dbde703980eb587ed6624b8fc2f5cedc297327bc1b9b7e6022a7c382e6013149b1afe00609b96003ab5c8d18d378979f76f336ab626317183f4 +"@cspell/dict-haskell@npm:^2.0.0": + version: 2.0.1 + resolution: "@cspell/dict-haskell@npm:2.0.1" + checksum: 10/7f960b16822804a4ab2be6482083a6dc2ecfc8ff32f3be630aa57cdf979c884f005a97fe8042c02f5b8ec90a89e7b80c3508535d8f5558e6b6fc435e95f0b957 languageName: node linkType: hard @@ -5220,10 +5218,10 @@ __metadata: languageName: node linkType: hard -"@cspell/dict-latex@npm:^4.0.0": - version: 4.0.0 - resolution: "@cspell/dict-latex@npm:4.0.0" - checksum: 10/7e7a520196d143d0a3185689d09d84bf1e23b5328dfc78187c4e4ab264bd49c3dd695eb92f8d582583e5bc26bcab4ed0976b310b56a000af81d88a7acdea7f8c +"@cspell/dict-lorem-ipsum@npm:^2.0.0": + version: 2.0.1 + resolution: "@cspell/dict-lorem-ipsum@npm:2.0.1" + checksum: 10/7f50518a48b809f7c2b70c2bcd01d2a3cb2d89288497dbe9df3c7fc91ee8d8ec62ec3ac8adfa8191d8a4f8a0e7a51bc40333f40b8dcc1661c09c5d320b38b2ed languageName: node linkType: hard @@ -5327,10 +5325,10 @@ __metadata: languageName: node linkType: hard -"@cspell/dict-software-terms@npm:^3.4.9": - version: 3.4.9 - resolution: "@cspell/dict-software-terms@npm:3.4.9" - checksum: 10/2fc21d7fefbd0269b760d2f634b22d6e54bd71dd3c03d96b59931fd1ef0c7380b6596e578621f907823eb8423bbdd297f56d8eaa150f2bbb23ed0559656c7523 +"@cspell/dict-public-licenses@npm:^1.0.4": + version: 1.0.6 + resolution: "@cspell/dict-public-licenses@npm:1.0.6" + checksum: 10/e679c6151623b174cc88c855a9bff3b5d5fff7956d919b72a0a3f7c71aed2a90fbea06d0afd3b79ab78ca308b3ef33051a640dab77891c27a36665fc441bd73e languageName: node linkType: hard @@ -5341,10 +5339,10 @@ __metadata: languageName: node linkType: hard -"@cspell/dict-svelte@npm:^1.0.2": - version: 1.0.2 - resolution: "@cspell/dict-svelte@npm:1.0.2" - checksum: 10/5b42989bc6743a26ca5172cc23ebc1449d930695b10c908376048ce1835bf57fef7a0004f02ec5e43219f24a97f154e125041df470441199a045ed0be9e654fc +"@cspell/dict-r@npm:^1.0.2": + version: 1.0.3 + resolution: "@cspell/dict-r@npm:1.0.3" + checksum: 10/47fe5d64ba36328c580ada9f2f8e5b34f3ee6ca03065da8b355b7aa7a6a364e276f39ea2103eae3f22bf95335490181e4425b42e2d8f51b3224a80b48f36feb1 languageName: node linkType: hard @@ -5355,10 +5353,10 @@ __metadata: languageName: node linkType: hard -"@cspell/dict-terraform@npm:^1.0.0": - version: 1.0.0 - resolution: "@cspell/dict-terraform@npm:1.0.0" - checksum: 10/132b8f0532aa5a6a08fa57487313722bc10ad37a4b94a5d76b072922eb4eb56d204a3e33c1569613af5b337bd125b8e2d30cae6bf5400a07fa58c551c7fe3b37 +"@cspell/dict-rust@npm:^2.0.0": + version: 2.0.1 + resolution: "@cspell/dict-rust@npm:2.0.1" + checksum: 10/b1b866869a4ba950e688d8676308acd49b469e648a9bd7804f7932a1bf666556ddc814b661826369a79305719e21e37e9902c4100c427abf91cd98006ec6da03 languageName: node linkType: hard @@ -5376,19 +5374,17 @@ __metadata: languageName: node linkType: hard -"@cspell/dynamic-import@npm:8.10.4": - version: 8.10.4 - resolution: "@cspell/dynamic-import@npm:8.10.4" - dependencies: - import-meta-resolve: "npm:^4.1.0" - checksum: 10/d07b83c990a0ff4a645df5ea45a7aa9eb6a948a16132382a2b3aafe470094892b90d53bb81cad336d5df27cd7f6a30c0c4289327825e05fcb26556a59ae91b15 +"@cspell/dict-swift@npm:^1.0.2": + version: 1.0.3 + resolution: "@cspell/dict-swift@npm:1.0.3" + checksum: 10/030e91f3315bc834a968fe0a5a7007e4229535fa541689661917698c18c7e76b35d3a247a8ef6467b012666bdddd19e40dc325664bf29891eabf7cad7636f0bc languageName: node linkType: hard -"@cspell/strong-weak-map@npm:8.10.4": - version: 8.10.4 - resolution: "@cspell/strong-weak-map@npm:8.10.4" - checksum: 10/3249a3584b38c0079ac3b245c419b99ba65dfede461c81b3a14747107d20760c1b2b7f912e5cba220bdd7c9d5f2756b8bb977f05e33f3674f91d98fc604d12c5 +"@cspell/dict-typescript@npm:^2.0.0": + version: 2.0.2 + resolution: "@cspell/dict-typescript@npm:2.0.2" + checksum: 10/68575d5ea31563109d7c3d121bdd31367e9b982b7c68f378fb3d1364a0a435f175bba217b4e3dcd51413b8bfb2ff2b1e950dc5c2a63889406f3a3fdffff8882b languageName: node linkType: hard @@ -7705,6 +7701,16 @@ __metadata: languageName: node linkType: hard +"@grpc/grpc-js@npm:1.10.3": + version: 1.10.3 + resolution: "@grpc/grpc-js@npm:1.10.3" + dependencies: + "@grpc/proto-loader": "npm:^0.7.10" + "@js-sdsl/ordered-map": "npm:^4.4.2" + checksum: 10/8217ba9ae6bbc3b25fe6e1fd4494864c75180a408bf33ece88078ab849027483dac480ebc509d2f0838ff77b99e4a0958bd0909fce1a58c380d620c23aeba9f7 + languageName: node + linkType: hard + "@grpc/grpc-js@npm:1.10.9": version: 1.10.9 resolution: "@grpc/grpc-js@npm:1.10.9" @@ -7775,7 +7781,7 @@ __metadata: languageName: node linkType: hard -"@grpc/proto-loader@npm:^0.7.13": +"@grpc/proto-loader@npm:^0.7.10, @grpc/proto-loader@npm:^0.7.13": version: 0.7.13 resolution: "@grpc/proto-loader@npm:0.7.13" dependencies: @@ -8223,6 +8229,53 @@ __metadata: languageName: unknown linkType: soft +"@hyperledger/cactus-cmd-api-server@npm:2.0.0-rc.1": + version: 2.0.0-rc.1 + resolution: "@hyperledger/cactus-cmd-api-server@npm:2.0.0-rc.1" + dependencies: + "@connectrpc/connect": "npm:1.4.0" + "@connectrpc/connect-express": "npm:1.4.0" + "@connectrpc/connect-fastify": "npm:1.4.0" + "@connectrpc/connect-node": "npm:1.4.0" + "@grpc/grpc-js": "npm:1.10.3" + "@grpc/proto-loader": "npm:0.7.8" + "@hyperledger/cactus-common": "npm:2.0.0-rc.1" + "@hyperledger/cactus-core": "npm:2.0.0-rc.1" + "@hyperledger/cactus-core-api": "npm:2.0.0-rc.1" + "@thream/socketio-jwt": "npm:2.1.1" + async-exit-hook: "npm:2.0.1" + axios: "npm:1.6.0" + bluebird: "npm:3.7.2" + body-parser: "npm:1.20.2" + compression: "npm:1.7.4" + convict: "npm:6.2.4" + convict-format-with-validator: "npm:6.2.0" + cors: "npm:2.8.5" + express: "npm:4.19.2" + express-http-proxy: "npm:1.6.2" + express-jwt: "npm:8.4.1" + express-openapi-validator: "npm:5.0.4" + express-rate-limit: "npm:6.7.0" + fastify: "npm:4.26.2" + fs-extra: "npm:10.1.0" + google-protobuf: "npm:3.18.0-rc.2" + jose: "npm:4.15.5" + json-stable-stringify: "npm:1.0.2" + lmify: "npm:0.3.0" + node-forge: "npm:1.3.0" + prom-client: "npm:13.2.0" + run-time-error-cjs: "npm:1.4.0" + rxjs: "npm:7.8.1" + safe-stable-stringify: "npm:2.4.3" + semver: "npm:7.5.2" + socket.io: "npm:4.5.4" + socket.io-client-fixed-types: "npm:4.5.4" + typescript-optional: "npm:2.0.1" + uuid: "npm:9.0.1" + checksum: 10/7c2bc22d2466e2159986ef70bd8398b485a538a2b1c54ad9dc6404275091332b6aae80563981cba0b42ab08ef2db3446869487333a281d5ab9d1bc7daef88344 + languageName: node + linkType: hard + "@hyperledger/cactus-cmd-api-server@npm:2.0.0-rc.2, @hyperledger/cactus-cmd-api-server@workspace:packages/cactus-cmd-api-server": version: 0.0.0-use.local resolution: "@hyperledger/cactus-cmd-api-server@workspace:packages/cactus-cmd-api-server" @@ -8360,6 +8413,23 @@ __metadata: languageName: node linkType: hard +"@hyperledger/cactus-common@npm:2.0.0-rc.1": + version: 2.0.0-rc.1 + resolution: "@hyperledger/cactus-common@npm:2.0.0-rc.1" + dependencies: + fast-safe-stringify: "npm:2.1.1" + json-stable-stringify: "npm:1.0.1" + key-encoder: "npm:2.0.3" + loglevel: "npm:1.7.1" + loglevel-plugin-prefix: "npm:0.8.4" + run-time-error-cjs: "npm:1.4.0" + sanitize-html: "npm:2.12.1" + secp256k1: "npm:4.0.3" + sha3: "npm:2.1.4" + checksum: 10/a1a7563ee73b39295961d6ea19980726904ac9532606ec0a5b68135e7b0442d0c2e603996138d8e807514b7ec5fe63dd2407bccd77cf839c8678a16714fa4e62 + languageName: node + linkType: hard + "@hyperledger/cactus-common@npm:2.0.0-rc.2, @hyperledger/cactus-common@workspace:packages/cactus-common": version: 0.0.0-use.local resolution: "@hyperledger/cactus-common@workspace:packages/cactus-common" @@ -8382,6 +8452,16 @@ __metadata: languageName: unknown linkType: soft +"@hyperledger/cactus-core-api@npm:2.0.0-rc.1": + version: 2.0.0-rc.1 + resolution: "@hyperledger/cactus-core-api@npm:2.0.0-rc.1" + dependencies: + "@hyperledger/cactus-common": "npm:2.0.0-rc.1" + axios: "npm:1.6.0" + checksum: 10/0415d658fe3a02d8574deba1ab60b7c520128444487608d54faa37bb196604dbafa69031551f9127bebfed1bd5bd140771e2d4a55fa0d37f1da7badec0da7340 + languageName: node + linkType: hard + "@hyperledger/cactus-core-api@npm:2.0.0-rc.2, @hyperledger/cactus-core-api@workspace:packages/cactus-core-api": version: 0.0.0-use.local resolution: "@hyperledger/cactus-core-api@workspace:packages/cactus-core-api" @@ -8405,6 +8485,25 @@ __metadata: languageName: unknown linkType: soft +"@hyperledger/cactus-core@npm:2.0.0-rc.1": + version: 2.0.0-rc.1 + resolution: "@hyperledger/cactus-core@npm:2.0.0-rc.1" + dependencies: + "@hyperledger/cactus-common": "npm:2.0.0-rc.1" + "@hyperledger/cactus-core-api": "npm:2.0.0-rc.1" + body-parser: "npm:1.20.2" + express: "npm:4.19.2" + express-jwt-authz: "npm:2.4.1" + express-openapi-validator: "npm:5.0.4" + http-errors: "npm:2.0.0" + http-errors-enhanced-cjs: "npm:2.0.1" + run-time-error-cjs: "npm:1.4.0" + safe-stable-stringify: "npm:2.4.3" + typescript-optional: "npm:2.0.1" + checksum: 10/ae111d1f5969ffe4765acf6e21b1af2ad1217dc7e31a63cce15689c8a025b0184dd5811ff6582c20eb21d1e197df67884034b2bbd390d3287028c9d2a6cefcae + languageName: node + linkType: hard + "@hyperledger/cactus-core@npm:2.0.0-rc.2, @hyperledger/cactus-core@workspace:packages/cactus-core": version: 0.0.0-use.local resolution: "@hyperledger/cactus-core@workspace:packages/cactus-core" @@ -8742,6 +8841,31 @@ __metadata: languageName: unknown linkType: soft +"@hyperledger/cactus-plugin-bungee-hermes@npm:2.0.0-rc.1": + version: 2.0.0-rc.1 + resolution: "@hyperledger/cactus-plugin-bungee-hermes@npm:2.0.0-rc.1" + dependencies: + "@hyperledger/cactus-cmd-api-server": "npm:2.0.0-rc.1" + "@hyperledger/cactus-common": "npm:2.0.0-rc.1" + "@hyperledger/cactus-core": "npm:2.0.0-rc.1" + "@hyperledger/cactus-core-api": "npm:2.0.0-rc.1" + "@hyperledger/cactus-plugin-keychain-memory": "npm:2.0.0-rc.1" + "@hyperledger/cactus-plugin-ledger-connector-besu": "npm:2.0.0-rc.1" + "@hyperledger/cactus-plugin-ledger-connector-ethereum": "npm:2.0.0-rc.1" + "@hyperledger/cactus-plugin-ledger-connector-fabric": "npm:2.0.0-rc.1" + axios: "npm:1.6.0" + body-parser: "npm:1.20.2" + fs-extra: "npm:10.1.0" + key-encoder: "npm:2.0.3" + merkletreejs: "npm:0.3.11" + typescript-optional: "npm:2.0.1" + uuid: "npm:9.0.1" + web3: "npm:1.6.1" + web3-core: "npm:1.6.1" + checksum: 10/175acb7b4661bac589ab40451fb8c58465acb2025ddd47787e2b28565b5322937841288d3d1ba41c42102b630fdedee9e7c68d35a3e29ba4095e13281c7afb6c + languageName: node + linkType: hard + "@hyperledger/cactus-plugin-bungee-hermes@workspace:packages/cactus-plugin-bungee-hermes": version: 0.0.0-use.local resolution: "@hyperledger/cactus-plugin-bungee-hermes@workspace:packages/cactus-plugin-bungee-hermes" @@ -8965,6 +9089,22 @@ __metadata: languageName: unknown linkType: soft +"@hyperledger/cactus-plugin-keychain-memory@npm:2.0.0-rc.1": + version: 2.0.0-rc.1 + resolution: "@hyperledger/cactus-plugin-keychain-memory@npm:2.0.0-rc.1" + dependencies: + "@hyperledger/cactus-common": "npm:2.0.0-rc.1" + "@hyperledger/cactus-core": "npm:2.0.0-rc.1" + "@hyperledger/cactus-core-api": "npm:2.0.0-rc.1" + axios: "npm:1.6.0" + express: "npm:4.19.2" + prom-client: "npm:13.2.0" + rxjs: "npm:7.8.1" + uuid: "npm:9.0.1" + checksum: 10/d39c44899e34a54f56cc36722fecaf95ca998f80a696747e1caf40891876d816a7fcc0086887b79b8b0c69083fcff11e4f74b98fdf596ecc814a902308cc3e63 + languageName: node + linkType: hard + "@hyperledger/cactus-plugin-keychain-memory@npm:2.0.0-rc.2, @hyperledger/cactus-plugin-keychain-memory@workspace:packages/cactus-plugin-keychain-memory": version: 0.0.0-use.local resolution: "@hyperledger/cactus-plugin-keychain-memory@workspace:packages/cactus-plugin-keychain-memory" @@ -9048,6 +9188,36 @@ __metadata: languageName: unknown linkType: soft +"@hyperledger/cactus-plugin-ledger-connector-besu@npm:2.0.0-rc.1": + version: 2.0.0-rc.1 + resolution: "@hyperledger/cactus-plugin-ledger-connector-besu@npm:2.0.0-rc.1" + dependencies: + "@grpc/grpc-js": "npm:1.10.3" + "@hyperledger/cactus-common": "npm:2.0.0-rc.1" + "@hyperledger/cactus-core": "npm:2.0.0-rc.1" + "@hyperledger/cactus-core-api": "npm:2.0.0-rc.1" + axios: "npm:1.6.0" + express: "npm:4.19.2" + google-protobuf: "npm:3.21.2" + http-errors: "npm:2.0.0" + http-errors-enhanced-cjs: "npm:2.0.1" + joi: "npm:17.9.1" + openapi-types: "npm:12.1.3" + prom-client: "npm:13.2.0" + run-time-error-cjs: "npm:1.4.0" + rxjs: "npm:7.8.1" + socket.io-client-fixed-types: "npm:4.5.4" + typescript-optional: "npm:2.0.1" + web3: "npm:1.6.1" + web3-core: "npm:1.6.1" + web3-eth: "npm:1.6.1" + web3-eth-contract: "npm:1.6.1" + web3-utils: "npm:1.6.1" + web3js-quorum: "npm:22.4.0" + checksum: 10/88ed7821bce53a340cacbf0c2b43da2e8c3fb0ec572f73bc1f6e8a410f020d2e6ce4d8484928feb7feb9d8d159c50dff5709d0271455aaa679d6f8716cc5d6f0 + languageName: node + linkType: hard + "@hyperledger/cactus-plugin-ledger-connector-besu@npm:2.0.0-rc.2, @hyperledger/cactus-plugin-ledger-connector-besu@workspace:packages/cactus-plugin-ledger-connector-besu": version: 0.0.0-use.local resolution: "@hyperledger/cactus-plugin-ledger-connector-besu@workspace:packages/cactus-plugin-ledger-connector-besu" @@ -9145,6 +9315,34 @@ __metadata: languageName: unknown linkType: soft +"@hyperledger/cactus-plugin-ledger-connector-ethereum@npm:2.0.0-rc.1": + version: 2.0.0-rc.1 + resolution: "@hyperledger/cactus-plugin-ledger-connector-ethereum@npm:2.0.0-rc.1" + dependencies: + "@ethereumjs/common": "npm:4.0.0" + "@ethereumjs/tx": "npm:5.0.0" + "@hyperledger/cactus-common": "npm:2.0.0-rc.1" + "@hyperledger/cactus-core": "npm:2.0.0-rc.1" + "@hyperledger/cactus-core-api": "npm:2.0.0-rc.1" + axios: "npm:1.6.0" + express: "npm:4.19.2" + http-proxy-middleware: "npm:2.0.6" + minimist: "npm:1.2.8" + prom-client: "npm:13.2.0" + run-time-error-cjs: "npm:1.4.0" + rxjs: "npm:7.8.1" + sanitize-html: "npm:2.12.1" + socket.io-client-fixed-types: "npm:4.5.4" + typescript-optional: "npm:2.0.1" + web3: "npm:4.4.0" + web3-eth: "npm:4.4.0" + web3-eth-contract: "npm:4.2.0" + bin: + cacti-ethereum-connector-status: dist/lib/scripts/get-ethereum-connector-status.js + checksum: 10/b92d50e3114867c13279280dc16c01127cdfe573d1a1f28cba0ff701827d715a6d5b110acb162b85ebe793c33c30527b160c94123c7efc557655370a81316258 + languageName: node + linkType: hard + "@hyperledger/cactus-plugin-ledger-connector-ethereum@npm:2.0.0-rc.2, @hyperledger/cactus-plugin-ledger-connector-ethereum@workspace:packages/cactus-plugin-ledger-connector-ethereum": version: 0.0.0-use.local resolution: "@hyperledger/cactus-plugin-ledger-connector-ethereum@workspace:packages/cactus-plugin-ledger-connector-ethereum" @@ -9188,6 +9386,47 @@ __metadata: languageName: unknown linkType: soft +"@hyperledger/cactus-plugin-ledger-connector-fabric@npm:2.0.0-rc.1": + version: 2.0.0-rc.1 + resolution: "@hyperledger/cactus-plugin-ledger-connector-fabric@npm:2.0.0-rc.1" + dependencies: + "@fidm/x509": "npm:1.2.1" + "@hyperledger/cactus-common": "npm:2.0.0-rc.1" + "@hyperledger/cactus-core": "npm:2.0.0-rc.1" + "@hyperledger/cactus-core-api": "npm:2.0.0-rc.1" + axios: "npm:1.6.0" + bl: "npm:5.0.0" + bn.js: "npm:4.12.0" + elliptic: "npm:6.5.4" + express: "npm:4.19.2" + fabric-ca-client: "npm:2.5.0-snapshot.23" + fabric-common: "npm:2.5.0-snapshot.23" + fabric-network: "npm:2.5.0-snapshot.23" + fabric-protos: "npm:2.5.0-snapshot.23" + fast-safe-stringify: "npm:2.1.1" + form-data: "npm:4.0.0" + http-status-codes: "npm:2.1.4" + jsrsasign: "npm:11.0.0" + multer: "npm:1.4.5-lts.1" + ngo: "npm:2.7.0" + node-ssh: "npm:13.1.0" + node-vault: "npm:0.9.22" + openapi-types: "npm:12.1.3" + prom-client: "npm:13.2.0" + run-time-error-cjs: "npm:1.4.0" + rxjs: "npm:7.8.1" + sanitize-filename: "npm:1.6.3" + sanitize-html: "npm:2.12.1" + secp256k1: "npm:4.0.3" + socket.io-client-fixed-types: "npm:4.5.4" + temp: "npm:0.9.4" + typescript-optional: "npm:2.0.1" + uuid: "npm:9.0.1" + ws-identity-client: "npm:1.0.2" + checksum: 10/e244d59b9d05d6818c9755b22c936d71c14d9ee05ae36cecd0047af269da89eb73df22831d4d60768a1048586501256e7681e4ba7a1d36b4270baabdfa22f237 + languageName: node + linkType: hard + "@hyperledger/cactus-plugin-ledger-connector-fabric@npm:2.0.0-rc.2, @hyperledger/cactus-plugin-ledger-connector-fabric@workspace:packages/cactus-plugin-ledger-connector-fabric": version: 0.0.0-use.local resolution: "@hyperledger/cactus-plugin-ledger-connector-fabric@workspace:packages/cactus-plugin-ledger-connector-fabric" @@ -9534,11 +9773,13 @@ __metadata: "@hyperledger/cactus-common": "npm:2.0.0-rc.2" "@hyperledger/cactus-core": "npm:2.0.0-rc.2" "@hyperledger/cactus-core-api": "npm:2.0.0-rc.2" + "@hyperledger/cactus-plugin-bungee-hermes": "npm:2.0.0-rc.1" "@hyperledger/cactus-plugin-keychain-memory": "npm:2.0.0-rc.2" "@hyperledger/cactus-plugin-ledger-connector-besu": "npm:2.0.0-rc.2" "@hyperledger/cactus-plugin-ledger-connector-fabric": "npm:2.0.0-rc.2" "@hyperledger/cactus-plugin-object-store-ipfs": "npm:2.0.0-rc.2" "@hyperledger/cactus-test-tooling": "npm:2.0.0-rc.2" + "@openzeppelin/contracts": "npm:4.4.0" "@quobix/vacuum": "npm:^0.9.10" "@types/body-parser": "npm:1.19.4" "@types/crypto-js": "npm:4.0.1" @@ -12315,9 +12556,9 @@ __metadata: languageName: node linkType: hard -"@npmcli/arborist@npm:^7.5.3": - version: 7.5.3 - resolution: "@npmcli/arborist@npm:7.5.3" +"@npmcli/arborist@npm:^7.2.2": + version: 7.5.4 + resolution: "@npmcli/arborist@npm:7.5.4" dependencies: "@isaacs/string-locale-compare": "npm:^1.1.0" "@npmcli/fs": "npm:^3.1.1" @@ -12356,7 +12597,7 @@ __metadata: walk-up-path: "npm:^3.0.1" bin: arborist: bin/index.js - checksum: 10/e149df712a2396f59e348ff32d763f62bbdf576f3976110f47b10cd912a91cce76c83f859bb0f97f4ca5273f15a270df54a702190753772f3539a3f10307b6ed + checksum: 10/b77170754f419171e5ca2abfb679a9c811443e2b67036916a62eda81fd069f12c98186941cd73a0d36c2ec76cda638b43ceeb4c5fae39de1bb9df825432f3ef7 languageName: node linkType: hard @@ -12528,7 +12769,7 @@ __metadata: languageName: node linkType: hard -"@npmcli/package-json@npm:^5.1.0, @npmcli/package-json@npm:^5.2.0": +"@npmcli/package-json@npm:^5.1.0": version: 5.2.0 resolution: "@npmcli/package-json@npm:5.2.0" dependencies: @@ -12570,6 +12811,13 @@ __metadata: languageName: node linkType: hard +"@npmcli/redact@npm:^1.1.0": + version: 1.1.0 + resolution: "@npmcli/redact@npm:1.1.0" + checksum: 10/c6c81c2d1463bc9f30d40f983a3dbb3144503030ff455e5a8904ff82ca39b95e46e9830fa4413f17f9a77604cdbb1f2370c53dd0ba4841cf24b79843e1fcf825 + languageName: node + linkType: hard + "@npmcli/redact@npm:^2.0.0": version: 2.0.1 resolution: "@npmcli/redact@npm:2.0.1" @@ -12590,6 +12838,19 @@ __metadata: languageName: node linkType: hard +"@npmcli/run-script@npm:^7.0.0, @npmcli/run-script@npm:^7.0.2": + version: 7.0.4 + resolution: "@npmcli/run-script@npm:7.0.4" + dependencies: + "@npmcli/node-gyp": "npm:^3.0.0" + "@npmcli/package-json": "npm:^5.0.0" + "@npmcli/promise-spawn": "npm:^7.0.0" + node-gyp: "npm:^10.0.0" + which: "npm:^4.0.0" + checksum: 10/f09268051f74af7d7be46e9911a23126d531160c338d3c05d53e6cd7994b88271fb4ec524139fe7f2d826525f15a281eafef3be02831adc1f68556a8a668621a + languageName: node + linkType: hard + "@npmcli/run-script@npm:^8.0.0, @npmcli/run-script@npm:^8.1.0": version: 8.1.0 resolution: "@npmcli/run-script@npm:8.1.0" @@ -12624,39 +12885,39 @@ __metadata: languageName: node linkType: hard -"@octokit/core@npm:^6.1.2": - version: 6.1.2 - resolution: "@octokit/core@npm:6.1.2" +"@octokit/core@npm:^5.0.2": + version: 5.2.0 + resolution: "@octokit/core@npm:5.2.0" dependencies: - "@octokit/auth-token": "npm:^5.0.0" - "@octokit/graphql": "npm:^8.0.0" - "@octokit/request": "npm:^9.0.0" - "@octokit/request-error": "npm:^6.0.1" + "@octokit/auth-token": "npm:^4.0.0" + "@octokit/graphql": "npm:^7.1.0" + "@octokit/request": "npm:^8.3.1" + "@octokit/request-error": "npm:^5.1.0" "@octokit/types": "npm:^13.0.0" - before-after-hook: "npm:^3.0.2" - universal-user-agent: "npm:^7.0.0" - checksum: 10/ef8cc502790142d892b97b92a6e398323f1e4be777e5675681d5985d4681855f4e6f02a7b16466984af702ecdffed0ab923610d59c07c540c3e243160818eaec + before-after-hook: "npm:^2.2.0" + universal-user-agent: "npm:^6.0.0" + checksum: 10/2e40baf0b5c6949922436a653c213be43befd9690c43dd89872f669f3ac23117ae8ae5e5d6c18094813756c71c3f4fbedd575a891f0b89e12f58b2c38b7f3c13 languageName: node linkType: hard -"@octokit/endpoint@npm:^10.0.0": - version: 10.1.1 - resolution: "@octokit/endpoint@npm:10.1.1" +"@octokit/endpoint@npm:^9.0.1": + version: 9.0.5 + resolution: "@octokit/endpoint@npm:9.0.5" dependencies: - "@octokit/types": "npm:^13.0.0" - universal-user-agent: "npm:^7.0.2" - checksum: 10/6b8991b278ba7e63ddf95e7396f54e5f1347237f11fb845322ec25101764336ed0994ccb197c449b4fd4bc00ec5b78780ccbc3a0b48ba0620dcc115027a3add1 + "@octokit/types": "npm:^13.1.0" + universal-user-agent: "npm:^6.0.0" + checksum: 10/212122f653bf076ec37dd7de44bd54db74aa3cd16be4c395c91444488331becd83351e26b30248168e2cc28fc07b1a96e8f74adbbab02826f76de92e069f391f languageName: node linkType: hard -"@octokit/graphql@npm:^8.0.0": - version: 8.1.1 - resolution: "@octokit/graphql@npm:8.1.1" +"@octokit/graphql@npm:^7.1.0": + version: 7.1.0 + resolution: "@octokit/graphql@npm:7.1.0" dependencies: - "@octokit/request": "npm:^9.0.0" + "@octokit/request": "npm:^8.3.0" "@octokit/types": "npm:^13.0.0" - universal-user-agent: "npm:^7.0.0" - checksum: 10/d8b3941e6afa724fba0cff79c71c839971aed6f87777833e1f6facc816c5fcd9a5b637dad779462cd723aa7490151f69fc6634758ca5bfe76f2cce298df934a1 + universal-user-agent: "npm:^6.0.0" + checksum: 10/da6857a69dc93cd20a11d3a905db4214d269d246a6aaee1d8734f922024b08ffdef0b3cba2ac79917633043b4f50464242b0bd92a265c960083dfff5b833dbbe languageName: node linkType: hard @@ -12674,67 +12935,69 @@ __metadata: languageName: node linkType: hard -"@octokit/plugin-paginate-rest@npm:^11.0.0": - version: 11.3.3 - resolution: "@octokit/plugin-paginate-rest@npm:11.3.3" +"@octokit/plugin-paginate-rest@npm:11.3.1": + version: 11.3.1 + resolution: "@octokit/plugin-paginate-rest@npm:11.3.1" dependencies: "@octokit/types": "npm:^13.5.0" peerDependencies: - "@octokit/core": ">=6" - checksum: 10/87eeb4dd68a8207e669989cdbf9de3717b74038d630c2b803cbc7a9c44c3ff74771ce1cf45fa056b7172aaaa80fd9a0e4bf5eca06aabc19f30e7e29898f1f69e + "@octokit/core": 5 + checksum: 10/82f5bcc3a536a44bed0a205c8301176c0d210b7a1c6d035a79b31a102e2e02f46234a38629cc984a21be544194ac69151814e9a909416aa7389cdffd1297bcd9 languageName: node linkType: hard -"@octokit/plugin-request-log@npm:^5.1.0": - version: 5.3.0 - resolution: "@octokit/plugin-request-log@npm:5.3.0" +"@octokit/plugin-request-log@npm:^4.0.0": + version: 4.0.1 + resolution: "@octokit/plugin-request-log@npm:4.0.1" peerDependencies: - "@octokit/core": ">=6" - checksum: 10/8c918b14f0687e8a3d9c7c81ef1092a49de07681940cc1aee0aeb7e3dd8ac64f69af5d65932eec32f6db4af3dca80541ad3bb13ac0fa44af3e2340ed91909272 + "@octokit/core": 5 + checksum: 10/fd8c0a201490cba00084689a0d1d54fc7b5ab5b6bdb7e447056b947b1754f78526e9685400eab10d3522bfa7b5bc49c555f41ec412c788610b96500b168f3789 languageName: node linkType: hard -"@octokit/plugin-rest-endpoint-methods@npm:^13.0.0": - version: 13.2.4 - resolution: "@octokit/plugin-rest-endpoint-methods@npm:13.2.4" +"@octokit/plugin-rest-endpoint-methods@npm:13.2.2": + version: 13.2.2 + resolution: "@octokit/plugin-rest-endpoint-methods@npm:13.2.2" dependencies: "@octokit/types": "npm:^13.5.0" peerDependencies: - "@octokit/core": ">=6" - checksum: 10/5d90adb9b5ab52a7ce260fcd2acc48a6723fc888e4f5711f958694c4bfb53fa146ad6791ce651060566d1bd513b3d9287c44a25b1da866d9611c3e1e739b5981 + "@octokit/core": ^5 + checksum: 10/9eccc1a22aa0b65f3f9378f26a74c386683db420c33202998918df1eef492e93212e1849e1d85530f425602663cfc2bfbf385a30991b8a04470334c74ba2386b languageName: node linkType: hard -"@octokit/request-error@npm:^6.0.1": - version: 6.1.1 - resolution: "@octokit/request-error@npm:6.1.1" +"@octokit/request-error@npm:^5.1.0": + version: 5.1.0 + resolution: "@octokit/request-error@npm:5.1.0" dependencies: - "@octokit/types": "npm:^13.0.0" - checksum: 10/cae7bc4078629a02edcf35977f496a4b943e730165f6d7828795073f99a1d884ac67343b02eff69e553a5057765e466d70ddd9d266787f505aa29018858ab06d + "@octokit/types": "npm:^13.1.0" + deprecation: "npm:^2.0.0" + once: "npm:^1.4.0" + checksum: 10/d03f9f7a408af673cd991eeb450b6f4a5cee6c368f6349eb0211dfc0404fddfcff8b5225ef186020a2a1829adba0aa8c9174155b49ab2ed00a94fb9a886a1dd3 languageName: node linkType: hard -"@octokit/request@npm:^9.0.0": - version: 9.1.1 - resolution: "@octokit/request@npm:9.1.1" +"@octokit/request@npm:^8.3.0, @octokit/request@npm:^8.3.1": + version: 8.4.0 + resolution: "@octokit/request@npm:8.4.0" dependencies: - "@octokit/endpoint": "npm:^10.0.0" - "@octokit/request-error": "npm:^6.0.1" + "@octokit/endpoint": "npm:^9.0.1" + "@octokit/request-error": "npm:^5.1.0" "@octokit/types": "npm:^13.1.0" - universal-user-agent: "npm:^7.0.2" - checksum: 10/aef47d85751c387c6ef29e70b3b86c9033fc7940361092c80728f7e99cc0ba54ddd00bbecb4422e50df78744600cfb8a1a2bc6916c5b6440677aa8ebd6b9b291 + universal-user-agent: "npm:^6.0.0" + checksum: 10/176cd83c68bde87111a01d50e2d21cf12ec362c1a30b33649eb8771d37397f6d6dd0b0844aab8d59b16d74c825252e39cadd52e37a4b1669d6facd1cb2cdc995 languageName: node linkType: hard -"@octokit/rest@npm:^21.0.0": - version: 21.0.0 - resolution: "@octokit/rest@npm:21.0.0" +"@octokit/rest@npm:^20.0.2": + version: 20.1.1 + resolution: "@octokit/rest@npm:20.1.1" dependencies: - "@octokit/core": "npm:^6.1.2" - "@octokit/plugin-paginate-rest": "npm:^11.0.0" - "@octokit/plugin-request-log": "npm:^5.1.0" - "@octokit/plugin-rest-endpoint-methods": "npm:^13.0.0" - checksum: 10/7da1c97866af04038fe4e384ce0a90cc4750bb951085c10053ceb73a4818cfe460336d7794ab3c65648cf5e195dba8e90940e36aec1e7ed22b6606cda38c88e0 + "@octokit/core": "npm:^5.0.2" + "@octokit/plugin-paginate-rest": "npm:11.3.1" + "@octokit/plugin-request-log": "npm:^4.0.0" + "@octokit/plugin-rest-endpoint-methods": "npm:13.2.2" + checksum: 10/a5d557323f3ebcf813bf0965f04084dc52e71525315f865646e084713099a2baa340752caebafb17595b31c5011df0f42a15359e145046d85b5051af37a516f9 languageName: node linkType: hard @@ -12794,6 +13057,13 @@ __metadata: languageName: node linkType: hard +"@openzeppelin/contracts@npm:4.4.0": + version: 4.4.0 + resolution: "@openzeppelin/contracts@npm:4.4.0" + checksum: 10/1c830b5ec2a9df32d94ec14bfaead2feb4f67db2ed0e0085cf074d64b4240f9cf0760858c6f0b5a19e57e81f22f9daa892b9993bd83fdc25db2fdc48ea37b7a2 + languageName: node + linkType: hard + "@openzeppelin/contracts@npm:4.9.6": version: 4.9.6 resolution: "@openzeppelin/contracts@npm:4.9.6" @@ -18374,6 +18644,13 @@ __metadata: languageName: node linkType: hard +"are-we-there-yet@npm:^4.0.0": + version: 4.0.2 + resolution: "are-we-there-yet@npm:4.0.2" + checksum: 10/86feb4e8384b0820adaf7693bd02f602d001b0e5f051744dc2d05b30b74f9bd3e1e6f1a0c70fdadeddd837b8e5f8f77569a1a286078fb39b32a0a8f3724660d7 + languageName: node + linkType: hard + "arg@npm:^4.1.0": version: 4.1.3 resolution: "arg@npm:4.1.3" @@ -19521,10 +19798,10 @@ __metadata: languageName: node linkType: hard -"before-after-hook@npm:^3.0.2": - version: 3.0.2 - resolution: "before-after-hook@npm:3.0.2" - checksum: 10/57dfee78930276a740559552460a83f31c605e0164f02f170f71352aa1f4f5fb2c1632ac3bcba06ba711c32bd88b7e3c82431428e0c4984fbd2336faa78cf08c +"before-after-hook@npm:^2.2.0": + version: 2.2.3 + resolution: "before-after-hook@npm:2.2.3" + checksum: 10/e676f769dbc4abcf4b3317db2fd2badb4a92c0710e0a7da12cf14b59c3482d4febf835ad7de7874499060fd4e13adf0191628e504728b3c5bb4ec7a878c09940 languageName: node linkType: hard @@ -19648,6 +19925,17 @@ __metadata: languageName: node linkType: hard +"bl@npm:5.0.0": + version: 5.0.0 + resolution: "bl@npm:5.0.0" + dependencies: + buffer: "npm:^6.0.3" + inherits: "npm:^2.0.4" + readable-stream: "npm:^3.4.0" + checksum: 10/fe2af4bf39e1ba94767a9084bb7406ff65f1ef2faa4e292ccadc360ce9e9421d5685a598db02358e4fda838de8242be23a3c4f6d64f749ce0b8aa49298dd1015 + languageName: node + linkType: hard + "bl@npm:5.1.0": version: 5.1.0 resolution: "bl@npm:5.1.0" @@ -21803,7 +22091,7 @@ __metadata: languageName: node linkType: hard -"comment-json@npm:^4.2.4": +"comment-json@npm:^4.2.2": version: 4.2.4 resolution: "comment-json@npm:4.2.4" dependencies: @@ -23587,7 +23875,7 @@ __metadata: languageName: node linkType: hard -"dedent@npm:^1.5.3": +"dedent@npm:^1.5.1": version: 1.5.3 resolution: "dedent@npm:1.5.3" peerDependencies: @@ -23880,6 +24168,22 @@ __metadata: languageName: node linkType: hard +"del@npm:^6.0.0": + version: 6.1.1 + resolution: "del@npm:6.1.1" + dependencies: + globby: "npm:^11.0.1" + graceful-fs: "npm:^4.2.4" + is-glob: "npm:^4.0.1" + is-path-cwd: "npm:^2.2.0" + is-path-inside: "npm:^3.0.2" + p-map: "npm:^4.0.0" + rimraf: "npm:^3.0.2" + slash: "npm:^3.0.0" + checksum: 10/563288b73b8b19a7261c47fd21a330eeab6e2acd7c6208c49790dfd369127120dd7836cdf0c1eca216b77c94782a81507eac6b4734252d3bef2795cb366996b6 + languageName: node + linkType: hard + "delay@npm:^5.0.0": version: 5.0.0 resolution: "delay@npm:5.0.0" @@ -24445,7 +24749,7 @@ __metadata: languageName: node linkType: hard -"dotenv@npm:^16.4.5": +"dotenv@npm:^16.3.1": version: 16.4.5 resolution: "dotenv@npm:16.4.5" checksum: 10/55a3134601115194ae0f924e54473459ed0d9fc340ae610b676e248cca45aa7c680d86365318ea964e6da4e2ea80c4514c1adab5adb43d6867fb57ff068f95c8 @@ -28559,6 +28863,22 @@ __metadata: languageName: node linkType: hard +"gauge@npm:^5.0.0": + version: 5.0.2 + resolution: "gauge@npm:5.0.2" + dependencies: + aproba: "npm:^1.0.3 || ^2.0.0" + color-support: "npm:^1.1.3" + console-control-strings: "npm:^1.1.0" + has-unicode: "npm:^2.0.1" + signal-exit: "npm:^4.0.1" + string-width: "npm:^4.2.3" + strip-ansi: "npm:^6.0.1" + wide-align: "npm:^1.1.5" + checksum: 10/7ed6930e03622e3651182d9312ea763e208e7e71bf126505a59a4424820af2715fdbc4f0655f92a092f3f1015c425094421c9d1a898dbe33cf6779d3e7e91e5c + languageName: node + linkType: hard + "gaxios@npm:^6.0.0": version: 6.1.1 resolution: "gaxios@npm:6.1.1" @@ -28840,7 +29160,7 @@ __metadata: languageName: node linkType: hard -"get-tsconfig@npm:^4.7.5": +"get-tsconfig@npm:^4.7.2": version: 4.7.5 resolution: "get-tsconfig@npm:4.7.5" dependencies: @@ -29277,7 +29597,7 @@ __metadata: languageName: node linkType: hard -"globby@npm:^14.0.2": +"globby@npm:^14.0.0": version: 14.0.2 resolution: "globby@npm:14.0.2" dependencies: @@ -30934,9 +31254,9 @@ __metadata: languageName: node linkType: hard -"inquirer@npm:^9.3.4": - version: 9.3.4 - resolution: "inquirer@npm:9.3.4" +"inquirer@npm:^9.2.12": + version: 9.3.5 + resolution: "inquirer@npm:9.3.5" dependencies: "@inquirer/figures": "npm:^1.0.3" ansi-escapes: "npm:^4.3.2" @@ -30950,7 +31270,7 @@ __metadata: strip-ansi: "npm:^6.0.1" wrap-ansi: "npm:^6.2.0" yoctocolors-cjs: "npm:^2.1.2" - checksum: 10/f9d20820ad07bfaa98ad1b0e1bb65da9cb020edafda25f781a28e7fe0fc98eb15b3fe95687258140a24a6bc9d209740d38ab17cc265c12fa6738db530c71b17e + checksum: 10/77084423a2ff54f200b5b25900a212a92f496b7206df49c0031f17360f9a51ecfd7993e9e155b609631e636fa0fccfefcc03d01016e55ed32d5ec18f5644f288 languageName: node linkType: hard @@ -34954,7 +35274,7 @@ __metadata: languageName: node linkType: hard -"libnpmaccess@npm:^8.0.6": +"libnpmaccess@npm:^8.0.2": version: 8.0.6 resolution: "libnpmaccess@npm:8.0.6" dependencies: @@ -34964,7 +35284,7 @@ __metadata: languageName: node linkType: hard -"libnpmpublish@npm:^9.0.9": +"libnpmpublish@npm:^9.0.3": version: 9.0.9 resolution: "libnpmpublish@npm:9.0.9" dependencies: @@ -35722,7 +36042,7 @@ __metadata: languageName: node linkType: hard -"lru-cache@npm:^10.2.0, lru-cache@npm:^10.2.2": +"lru-cache@npm:^10.2.2": version: 10.3.0 resolution: "lru-cache@npm:10.3.0" checksum: 10/37e921aedbd1f4062475d9fa6760391fa7adfaaee3a5a6cbedd1d6d0b46705c14012312c1edb2b13f119eae6584a48f73c158d118828d42475b44a7abf7d05ab @@ -36270,7 +36590,7 @@ __metadata: languageName: node linkType: hard -"meow@npm:^10.1.3": +"meow@npm:^10.1.0": version: 10.1.5 resolution: "meow@npm:10.1.5" dependencies: @@ -38292,7 +38612,7 @@ __metadata: languageName: node linkType: hard -"npm-package-arg@npm:^11.0.2": +"npm-package-arg@npm:^11.0.1, npm-package-arg@npm:^11.0.2": version: 11.0.2 resolution: "npm-package-arg@npm:11.0.2" dependencies: @@ -38322,7 +38642,7 @@ __metadata: languageName: node linkType: hard -"npm-packlist@npm:^8.0.2": +"npm-packlist@npm:^8.0.1": version: 8.0.2 resolution: "npm-packlist@npm:8.0.2" dependencies: @@ -38382,7 +38702,22 @@ __metadata: languageName: node linkType: hard -"npm-registry-fetch@npm:^17.0.0, npm-registry-fetch@npm:^17.0.1, npm-registry-fetch@npm:^17.1.0": +"npm-registry-fetch@npm:^16.0.0, npm-registry-fetch@npm:^16.1.0": + version: 16.2.1 + resolution: "npm-registry-fetch@npm:16.2.1" + dependencies: + "@npmcli/redact": "npm:^1.1.0" + make-fetch-happen: "npm:^13.0.0" + minipass: "npm:^7.0.2" + minipass-fetch: "npm:^3.0.0" + minizlib: "npm:^2.1.2" + npm-package-arg: "npm:^11.0.0" + proc-log: "npm:^4.0.0" + checksum: 10/eb5a939f8f1c187b8d739e41bbc37f5d376480e2479f61a4f55af5aa00262a9a55e0053a0cd673d2945716863aaef6afbf97ebbb33fb194259573151c4dff37b + languageName: node + linkType: hard + +"npm-registry-fetch@npm:^17.0.0, npm-registry-fetch@npm:^17.0.1": version: 17.1.0 resolution: "npm-registry-fetch@npm:17.1.0" dependencies: @@ -39393,7 +39728,7 @@ __metadata: languageName: node linkType: hard -"p-map@npm:^7.0.2": +"p-map@npm:^7.0.0": version: 7.0.2 resolution: "p-map@npm:7.0.2" checksum: 10/b4a590038b991c17b9c1484aa8c24cb9d3aa8a6167d02b9f9459c9200c7d392202a860c95b6dcd190d51f5f083ed256b32f9cb5976785022b0111bab853ec58b @@ -39407,7 +39742,7 @@ __metadata: languageName: node linkType: hard -"p-queue@npm:^8.0.1": +"p-queue@npm:^8.0.0": version: 8.0.1 resolution: "p-queue@npm:8.0.1" dependencies: @@ -39558,6 +39893,35 @@ __metadata: languageName: node linkType: hard +"pacote@npm:^17.0.5": + version: 17.0.7 + resolution: "pacote@npm:17.0.7" + dependencies: + "@npmcli/git": "npm:^5.0.0" + "@npmcli/installed-package-contents": "npm:^2.0.1" + "@npmcli/package-json": "npm:^5.1.0" + "@npmcli/promise-spawn": "npm:^7.0.0" + "@npmcli/run-script": "npm:^8.0.0" + cacache: "npm:^18.0.0" + fs-minipass: "npm:^3.0.0" + minipass: "npm:^7.0.2" + npm-package-arg: "npm:^11.0.0" + npm-packlist: "npm:^8.0.0" + npm-pick-manifest: "npm:^9.0.0" + npm-registry-fetch: "npm:^16.0.0" + proc-log: "npm:^4.0.0" + promise-retry: "npm:^2.0.1" + read-package-json: "npm:^7.0.0" + read-package-json-fast: "npm:^3.0.0" + sigstore: "npm:^2.2.0" + ssri: "npm:^10.0.0" + tar: "npm:^6.1.11" + bin: + pacote: lib/bin.js + checksum: 10/6aa223428e0c8273d48d2e49d7bf3fbe03ea3f6b418a56f7c6d52f3f628d71608a4b4a4cb04f3de0b67fface556df34e47ca1f840c771e24b5e4f57cdbc3f4d4 + languageName: node + linkType: hard + "pacote@npm:^18.0.0, pacote@npm:^18.0.6": version: 18.0.6 resolution: "pacote@npm:18.0.6" @@ -42585,6 +42949,18 @@ __metadata: languageName: node linkType: hard +"read-package-json@npm:^7.0.0": + version: 7.0.1 + resolution: "read-package-json@npm:7.0.1" + dependencies: + glob: "npm:^10.2.2" + json-parse-even-better-errors: "npm:^3.0.0" + normalize-package-data: "npm:^6.0.0" + npm-normalize-package-bin: "npm:^3.0.0" + checksum: 10/4b5684f4ee96ff29d0ec62452d2b1ed2b3fb7e452cd1a1f40869d896082816a231a1e157fa3e72137e140ca961cbe7eeabc952658fc38235c85b202c91f2e584 + languageName: node + linkType: hard + "read-pkg-up@npm:^1.0.1": version: 1.0.1 resolution: "read-pkg-up@npm:1.0.1" @@ -45108,6 +45484,13 @@ __metadata: languageName: node linkType: hard +"socket.io-adapter@npm:~2.4.0": + version: 2.4.0 + resolution: "socket.io-adapter@npm:2.4.0" + checksum: 10/e10c8c36a1b0744432d9fb7266c69268fb11cacb548e95f5feb7708c1438c4c1e034abf3eee56dc3fd4d5524aba4e5a306a402f0c15efb1334be364a05bfad04 + languageName: node + linkType: hard + "socket.io-adapter@npm:~2.5.2": version: 2.5.5 resolution: "socket.io-adapter@npm:2.5.5" @@ -45140,6 +45523,20 @@ __metadata: languageName: node linkType: hard +"socket.io@npm:4.5.4": + version: 4.5.4 + resolution: "socket.io@npm:4.5.4" + dependencies: + accepts: "npm:~1.3.4" + base64id: "npm:~2.0.0" + debug: "npm:~4.3.2" + engine.io: "npm:~6.2.1" + socket.io-adapter: "npm:~2.4.0" + socket.io-parser: "npm:~4.2.1" + checksum: 10/5e599eb7cab24124ad7ef7718ef09e16f2587a0891588cc11b77d3ff7572de82d9d07bf7feb870c38f36c8a1a90b8ff4b8d5ce224a3390d45b085e400e92b9cf + languageName: node + linkType: hard + "socket.io@npm:4.6.2": version: 4.6.2 resolution: "socket.io@npm:4.6.2" @@ -45718,7 +46115,7 @@ __metadata: languageName: node linkType: hard -"ssri@npm:^10.0.6": +"ssri@npm:^10.0.5, ssri@npm:^10.0.6": version: 10.0.6 resolution: "ssri@npm:10.0.6" dependencies: @@ -47044,7 +47441,7 @@ __metadata: languageName: node linkType: hard -"tar@npm:^6.2.1": +"tar@npm:^6.2.0": version: 6.2.1 resolution: "tar@npm:6.2.1" dependencies: @@ -48728,10 +49125,10 @@ __metadata: languageName: node linkType: hard -"universal-user-agent@npm:^7.0.0, universal-user-agent@npm:^7.0.2": - version: 7.0.2 - resolution: "universal-user-agent@npm:7.0.2" - checksum: 10/3f02cb6de0bb9fbaf379566bd0320d8e46af6e4358a2e88fce7e70687ed7b48b37f479d728bb22f4204a518e363f3038ac4841c033af1ee2253f6428a6c67e53 +"universal-user-agent@npm:^6.0.0": + version: 6.0.1 + resolution: "universal-user-agent@npm:6.0.1" + checksum: 10/fdc8e1ae48a05decfc7ded09b62071f571c7fe0bd793d700704c80cea316101d4eac15cc27ed2bb64f4ce166d2684777c3198b9ab16034f547abea0d3aa1c93c languageName: node linkType: hard @@ -49358,14 +49755,14 @@ __metadata: languageName: node linkType: hard -"vscode-languageserver-textdocument@npm:^1.0.11": +"vscode-languageserver-textdocument@npm:^1.0.4": version: 1.0.11 resolution: "vscode-languageserver-textdocument@npm:1.0.11" checksum: 10/6096d2a85570e819e01ff406de7c88c48211e6874c6fc71df92193aa8b5aadf40591e44f033d634a95d04975d7aad29049d3eccab617ca41c189ae325aadb913 languageName: node linkType: hard -"vscode-uri@npm:^3.0.8": +"vscode-uri@npm:^3.0.3": version: 3.0.8 resolution: "vscode-uri@npm:3.0.8" checksum: 10/e882d6b679e0d053cbc042893c0951a135d899a192b62cd07f0a8924f11ae722067a8d6b1b5b147034becf57faf9fff9fb543b17b749fd0f17db1f54f783f07c @@ -53068,13 +53465,6 @@ __metadata: languageName: node linkType: hard -"yocto-queue@npm:^1.1.1": - version: 1.1.1 - resolution: "yocto-queue@npm:1.1.1" - checksum: 10/f2e05b767ed3141e6372a80af9caa4715d60969227f38b1a4370d60bffe153c9c5b33a862905609afc9b375ec57cd40999810d20e5e10229a204e8bde7ef255c - languageName: node - linkType: hard - "yoctocolors-cjs@npm:^2.1.2": version: 2.1.2 resolution: "yoctocolors-cjs@npm:2.1.2"