From a7fa53e10908559ff1575928a2fa6ca6c2bc9cf9 Mon Sep 17 00:00:00 2001 From: Carlos Amaro Date: Fri, 23 Aug 2024 17:12:08 +0100 Subject: [PATCH] feat(satp-hermes): stage0, bug fixing and test e2e Co-authored-by: eduv09 Signed-off-by: Carlos Amaro fix(satp-hermes): error messages in stage0 Signed-off-by: Carlos Amaro feat(satp-hermes): service tests added stage0 and error handling Signed-off-by: Carlos Amaro feat(satp-hermes): test e2e Signed-off-by: Carlos Amaro fix(satp-hermes): fix bugs and test e2e working transfer Signed-off-by: Carlos Amaro fix(stap-hermes): bugs and 2 gateway test Signed-off-by: Carlos Amaro --- .../cactus-plugin-satp-hermes/package.json | 19 +- .../gateway-client/.openapi-generator/FILES | 4 + .../go/generated/gateway-client/README.md | 2 + .../generated/gateway-client/api/openapi.yaml | 105 +- .../go/generated/gateway-client/docs/Asset.md | 171 +++ .../gateway-client/docs/TransactRequest.md | 128 +- .../docs/TransactRequestSourceAsset.md | 171 +++ .../gateway-client/docs/TransactionApi.md | 2 +- .../generated/gateway-client/model_asset.go | 279 ++++ .../gateway-client/model_transact_request.go | 258 ++-- .../model_transact_request_source_asset.go | 279 ++++ .../src/main/json/openapi-blo-bundled.json | 189 ++- .../proto/cacti/satp/v02/common/message.proto | 39 + .../proto/cacti/satp/v02/common/session.proto | 50 +- .../main/proto/cacti/satp/v02/stage_0.proto | 79 +- .../src/main/typescript/blo/dispatcher.ts | 18 +- .../transaction/transact-handler-service.ts | 114 ++ .../src/main/typescript/core/constants.ts | 1 - .../core/errors/satp-handler-errors.ts | 23 +- .../core/errors/satp-service-errors.ts | 243 +++- .../src/main/typescript/core/satp-session.ts | 198 ++- .../src/main/typescript/core/session-utils.ts | 250 +++- .../core/stage-handlers/stage0-handler.ts | 250 +++- .../core/stage-handlers/stage1-handler.ts | 37 +- .../core/stage-handlers/stage2-handler.ts | 20 +- .../core/stage-handlers/stage3-handler.ts | 49 +- .../client/stage0-client-service.ts | 307 ++++- .../client/stage1-client-service.ts | 64 +- .../client/stage2-client-service.ts | 15 +- .../client/stage3-client-service.ts | 15 +- .../core/stage-services/data-verifier.ts | 8 +- .../stage-services/satp-bridge/besu-bridge.ts | 7 + .../satp-bridge/satp-bridge-manager.ts | 47 +- .../stage-services/satp-bridge/types/asset.ts | 10 + .../satp-bridge/types/besu-asset.ts | 1 - .../satp-bridge/types/fabric-asset.ts | 1 - .../server/stage0-server-service.ts | 391 +++++- .../server/stage1-server-service.ts | 24 +- .../server/stage3-server-service.ts | 31 +- .../core/stage-services/service-utils.ts | 70 ++ .../src/main/typescript/core/types.ts | 5 +- .../src/main/typescript/gateway-utils.ts | 2 + .../gateway-client/typescript-axios/api.ts | 110 +- .../cacti/satp/v02/common/health_connect.ts | 2 +- .../proto/cacti/satp/v02/common/message_pb.ts | 243 ++++ .../cacti/satp/v02/common/session_connect.ts | 2 +- .../proto/cacti/satp/v02/common/session_pb.ts | 261 +++- .../cacti/satp/v02/crash_recovery_connect.ts | 2 +- .../proto/cacti/satp/v02/stage_0_connect.ts | 40 +- .../proto/cacti/satp/v02/stage_0_pb.ts | 370 ++++-- .../proto/cacti/satp/v02/stage_1_connect.ts | 2 +- .../proto/cacti/satp/v02/stage_2_connect.ts | 2 +- .../proto/cacti/satp/v02/stage_3_connect.ts | 2 +- .../typescript/gol/gateway-orchestrator.ts | 130 +- .../typescript/gol/satp-bridges-manager.ts | 2 - .../src/main/typescript/gol/satp-manager.ts | 134 +- .../network-identification/resolve-gateway.ts | 66 +- .../typescript/plugin-satp-hermes-gateway.ts | 68 +- .../types/blockchain-interaction.ts | 4 + .../main/typescript/types/satp-protocol.ts | 10 + .../src/main/yml/bol/openapi-blo-bundled.yml | 132 +- .../src/main/yml/bol/schemas.yml | 41 +- ...satp-end-to-end-transfer-1-gateway.test.ts | 1084 ++++++++++++++++ ...atp-end-to-end-transfer-2-gateways.test.ts | 1117 +++++++++++++++++ .../src/test/typescript/unit/services.test.ts | 261 +++- yarn.lock | 93 +- 66 files changed, 7242 insertions(+), 912 deletions(-) create mode 100644 packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/docs/Asset.md create mode 100644 packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/docs/TransactRequestSourceAsset.md create mode 100644 packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/model_asset.go create mode 100644 packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/model_transact_request_source_asset.go create mode 100644 packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/service-utils.ts create mode 100644 packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-end-to-end-transfer-1-gateway.test.ts create mode 100644 packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-end-to-end-transfer-2-gateways.test.ts diff --git a/packages/cactus-plugin-satp-hermes/package.json b/packages/cactus-plugin-satp-hermes/package.json index 7a0c1a62a9..c0c1c73e56 100644 --- a/packages/cactus-plugin-satp-hermes/package.json +++ b/packages/cactus-plugin-satp-hermes/package.json @@ -55,7 +55,7 @@ ], "scripts": { "preinstall": "curl -L https://foundry.paradigm.xyz | bash && foundryup", - "start-gateway": "ts-node satp-gateway-cli.ts", + "start-gateway": "ts-node /src/main/typescript/plugin-satp-hermes-gateway-cli.ts", "build": "run-s codegen tsc", "build-proto": "buf build --path src/main/proto --verbose", "build:dev:backend:postbuild": "mkdir -p ./dist/lib/knex && cp -r ./src/knex/* ./dist/lib/knex", @@ -86,11 +86,12 @@ } }, "dependencies": { - "@connectrpc/connect": "1.3.0", - "@connectrpc/connect-express": "1.3.0", - "@connectrpc/connect-node": "1.3.0", - "@connectrpc/protoc-gen-connect-es": "1.3.0", + "@connectrpc/connect": "1.4.0", + "@connectrpc/connect-express": "1.4.0", + "@connectrpc/connect-node": "1.4.0", + "@connectrpc/protoc-gen-connect-es": "1.4.0", "@foundry-rs/hardhat-forge": "0.1.17", + "@grpc/grpc-js": "1.11.1", "@hyperledger/cactus-cmd-api-server": "2.0.0-rc.3", "@hyperledger/cactus-common": "2.0.0-rc.3", "@hyperledger/cactus-core": "2.0.0-rc.3", @@ -112,11 +113,13 @@ "express": "4.17.2", "fabric-network": "2.2.19", "fs-extra": "11.2.0", + "google-protobuf": "3.21.2", "hardhat": "2.22.5", "knex": "2.4.0", "kubo-rpc-client": "3.0.1", "npm-run-all": "4.1.5", "openzeppelin-solidity": "3.4.2", + "safe-stable-stringify": "^2.5.0", "secp256k1": "4.0.3", "socket.io": "4.6.2", "sqlite3": "5.1.5", @@ -131,11 +134,13 @@ "@bufbuild/buf": "1.29.0", "@bufbuild/protobuf": "1.7.2", "@bufbuild/protoc-gen-es": "1.7.2", + "@grpc/proto-loader": "0.7.8", "@quobix/vacuum": "0.9.10", "@types/body-parser": "1.19.4", "@types/crypto-js": "4.0.1", "@types/express": "4.17.21", "@types/fs-extra": "11.0.4", + "@types/google-protobuf": "3.15.5", "@types/node": "18.18.2", "@types/swagger-ui-express": "4.1.6", "@types/tape": "4.13.4", @@ -144,7 +149,11 @@ "ethereum-abi-types-generator": "1.3.4", "express": "4.19.2", "fabric-network": "2.2.20", + "grpc-tools": "1.12.4", + "grpc_tools_node_protoc_ts": "5.3.3", "kubo-rpc-client": "3.0.1", + "make-dir-cli": "3.1.0", + "protobufjs": "7.2.5", "swagger-cli": "4.0.4", "typescript": "5.5.2" }, diff --git a/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/.openapi-generator/FILES b/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/.openapi-generator/FILES index e101cc77cb..183ff7f779 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/.openapi-generator/FILES +++ b/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/.openapi-generator/FILES @@ -9,6 +9,7 @@ configuration.go docs/APIError.md docs/Action.md docs/AdminApi.md +docs/Asset.md docs/AuthzJwtClaim.md docs/AuthzScope.md docs/BridgeInfo.md @@ -59,6 +60,7 @@ docs/Transact200ResponseStatusResponseDestinationChain.md docs/Transact200ResponseStatusResponseOriginChain.md docs/TransactDefaultResponse.md docs/TransactRequest.md +docs/TransactRequestSourceAsset.md docs/TransactResponse.md docs/TransactionApi.md git_push.sh @@ -66,6 +68,7 @@ go.mod go.sum model_action.go model_api_error.go +model_asset.go model_authz_jwt_claim.go model_authz_scope.go model_bridge_info.go @@ -116,6 +119,7 @@ model_transact_200_response_status_response_destination_chain.go model_transact_200_response_status_response_origin_chain.go model_transact_default_response.go model_transact_request.go +model_transact_request_source_asset.go model_transact_response.go response.go utils.go diff --git a/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/README.md b/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/README.md index da330b7e19..5bc8df928c 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/README.md +++ b/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/README.md @@ -103,6 +103,7 @@ Class | Method | HTTP request | Description - [APIError](docs/APIError.md) - [Action](docs/Action.md) + - [Asset](docs/Asset.md) - [AuthzJwtClaim](docs/AuthzJwtClaim.md) - [AuthzScope](docs/AuthzScope.md) - [BridgeInfo](docs/BridgeInfo.md) @@ -153,6 +154,7 @@ Class | Method | HTTP request | Description - [Transact200ResponseStatusResponseOriginChain](docs/Transact200ResponseStatusResponseOriginChain.md) - [TransactDefaultResponse](docs/TransactDefaultResponse.md) - [TransactRequest](docs/TransactRequest.md) + - [TransactRequestSourceAsset](docs/TransactRequestSourceAsset.md) - [TransactResponse](docs/TransactResponse.md) diff --git a/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/api/openapi.yaml b/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/api/openapi.yaml index e16c9333cd..dc98f2438b 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/api/openapi.yaml +++ b/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/api/openapi.yaml @@ -592,20 +592,54 @@ components: - sessionID type: object x-category: request + Asset: + description: An asset + properties: + owner: + type: string + ontology: + type: string + contractName: + type: string + contractAddress: + type: string + mspId: + type: string + channelName: + type: string + required: + - contractName + - ontology + - owner + type: object TransactRequest: description: "Request schema for initiating a transaction. Includes details\ \ such as the transaction context, mode (data or transfer), payload, and information\ \ about the source and destination DLT networks." example: mode: transfer + beneficiaryPubkey: beneficiaryPubkey + destinyAsset: + owner: owner + mspId: mspId + contractAddress: contractAddress + contractName: contractName + channelName: channelName + ontology: ontology payload: "{\"data\":\"example payload\"}" fromAmount: "100" toAmount: "95" + sourceAsset: + owner: owner + mspId: mspId + contractAddress: contractAddress + contractName: contractName + channelName: channelName + ontology: ontology + originatorPubkey: originatorPubkey contextID: 123e4567-e89b-12d3-a456-426614174000 toDLTNetworkID: network2 fromDLTNetworkID: network1 - fromToken: TOKEN1 - toToken: TOKEN2 properties: contextID: example: 123e4567-e89b-12d3-a456-426614174000 @@ -629,18 +663,28 @@ components: fromAmount: example: "100" type: string - fromToken: - example: TOKEN1 - type: string toAmount: example: "95" type: string - toToken: - example: TOKEN2 + beneficiaryPubkey: + type: string + originatorPubkey: type: string + sourceAsset: + $ref: '#/components/schemas/Transact_request_sourceAsset' + destinyAsset: + $ref: '#/components/schemas/Transact_request_sourceAsset' required: + - beneficiaryPubkey - contextID + - destinyAsset + - fromAmount + - fromDLTNetworkID - mode + - originatorPubkey + - sourceAsset + - toAmount + - toDLTNetworkID type: object TransactResponse: description: Response schema for a transaction request. Includes the session @@ -1181,6 +1225,33 @@ components: token: $ref: '#/components/schemas/GetRoutes_200_response_routes_inner_fromToken' type: object + Transact_request_sourceAsset: + description: An asset + example: + owner: owner + mspId: mspId + contractAddress: contractAddress + contractName: contractName + channelName: channelName + ontology: ontology + properties: + owner: + type: string + ontology: + type: string + contractName: + type: string + contractAddress: + type: string + mspId: + type: string + channelName: + type: string + required: + - contractName + - ontology + - owner + type: object Transact_request: description: "Request schema for initiating a transaction. Includes details\ \ such as the transaction context, mode (data or transfer), payload, and information\ @@ -1208,18 +1279,28 @@ components: fromAmount: example: "100" type: string - fromToken: - example: TOKEN1 - type: string toAmount: example: "95" type: string - toToken: - example: TOKEN2 + beneficiaryPubkey: + type: string + originatorPubkey: type: string + sourceAsset: + $ref: '#/components/schemas/Transact_request_sourceAsset' + destinyAsset: + $ref: '#/components/schemas/Transact_request_sourceAsset' required: + - beneficiaryPubkey - contextID + - destinyAsset + - fromAmount + - fromDLTNetworkID - mode + - originatorPubkey + - sourceAsset + - toAmount + - toDLTNetworkID type: object Transact_200_response_statusResponse_originChain: example: diff --git a/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/docs/Asset.md b/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/docs/Asset.md new file mode 100644 index 0000000000..943cdc53a3 --- /dev/null +++ b/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/docs/Asset.md @@ -0,0 +1,171 @@ +# Asset + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Owner** | **string** | | +**Ontology** | **string** | | +**ContractName** | **string** | | +**ContractAddress** | Pointer to **string** | | [optional] +**MspId** | Pointer to **string** | | [optional] +**ChannelName** | Pointer to **string** | | [optional] + +## Methods + +### NewAsset + +`func NewAsset(owner string, ontology string, contractName string, ) *Asset` + +NewAsset instantiates a new Asset object +This constructor will assign default values to properties that have it defined, +and makes sure properties required by API are set, but the set of arguments +will change when the set of required properties is changed + +### NewAssetWithDefaults + +`func NewAssetWithDefaults() *Asset` + +NewAssetWithDefaults instantiates a new Asset object +This constructor will only assign default values to properties that have it defined, +but it doesn't guarantee that properties required by API are set + +### GetOwner + +`func (o *Asset) GetOwner() string` + +GetOwner returns the Owner field if non-nil, zero value otherwise. + +### GetOwnerOk + +`func (o *Asset) GetOwnerOk() (*string, bool)` + +GetOwnerOk returns a tuple with the Owner field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetOwner + +`func (o *Asset) SetOwner(v string)` + +SetOwner sets Owner field to given value. + + +### GetOntology + +`func (o *Asset) GetOntology() string` + +GetOntology returns the Ontology field if non-nil, zero value otherwise. + +### GetOntologyOk + +`func (o *Asset) GetOntologyOk() (*string, bool)` + +GetOntologyOk returns a tuple with the Ontology field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetOntology + +`func (o *Asset) SetOntology(v string)` + +SetOntology sets Ontology field to given value. + + +### GetContractName + +`func (o *Asset) GetContractName() string` + +GetContractName returns the ContractName field if non-nil, zero value otherwise. + +### GetContractNameOk + +`func (o *Asset) GetContractNameOk() (*string, bool)` + +GetContractNameOk returns a tuple with the ContractName field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetContractName + +`func (o *Asset) SetContractName(v string)` + +SetContractName sets ContractName field to given value. + + +### GetContractAddress + +`func (o *Asset) GetContractAddress() string` + +GetContractAddress returns the ContractAddress field if non-nil, zero value otherwise. + +### GetContractAddressOk + +`func (o *Asset) GetContractAddressOk() (*string, bool)` + +GetContractAddressOk returns a tuple with the ContractAddress field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetContractAddress + +`func (o *Asset) SetContractAddress(v string)` + +SetContractAddress sets ContractAddress field to given value. + +### HasContractAddress + +`func (o *Asset) HasContractAddress() bool` + +HasContractAddress returns a boolean if a field has been set. + +### GetMspId + +`func (o *Asset) GetMspId() string` + +GetMspId returns the MspId field if non-nil, zero value otherwise. + +### GetMspIdOk + +`func (o *Asset) GetMspIdOk() (*string, bool)` + +GetMspIdOk returns a tuple with the MspId field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetMspId + +`func (o *Asset) SetMspId(v string)` + +SetMspId sets MspId field to given value. + +### HasMspId + +`func (o *Asset) HasMspId() bool` + +HasMspId returns a boolean if a field has been set. + +### GetChannelName + +`func (o *Asset) GetChannelName() string` + +GetChannelName returns the ChannelName field if non-nil, zero value otherwise. + +### GetChannelNameOk + +`func (o *Asset) GetChannelNameOk() (*string, bool)` + +GetChannelNameOk returns a tuple with the ChannelName field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetChannelName + +`func (o *Asset) SetChannelName(v string)` + +SetChannelName sets ChannelName field to given value. + +### HasChannelName + +`func (o *Asset) HasChannelName() bool` + +HasChannelName returns a boolean if a field has been set. + + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/docs/TransactRequest.md b/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/docs/TransactRequest.md index 5e7c595240..983b991ac6 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/docs/TransactRequest.md +++ b/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/docs/TransactRequest.md @@ -7,18 +7,20 @@ Name | Type | Description | Notes **ContextID** | **string** | | **Mode** | **string** | | **Payload** | Pointer to **string** | | [optional] -**FromDLTNetworkID** | Pointer to **string** | | [optional] -**ToDLTNetworkID** | Pointer to **string** | | [optional] -**FromAmount** | Pointer to **string** | | [optional] -**FromToken** | Pointer to **string** | | [optional] -**ToAmount** | Pointer to **string** | | [optional] -**ToToken** | Pointer to **string** | | [optional] +**FromDLTNetworkID** | **string** | | +**ToDLTNetworkID** | **string** | | +**FromAmount** | **string** | | +**ToAmount** | **string** | | +**BeneficiaryPubkey** | **string** | | +**OriginatorPubkey** | **string** | | +**SourceAsset** | [**TransactRequestSourceAsset**](TransactRequestSourceAsset.md) | | +**DestinyAsset** | [**TransactRequestSourceAsset**](TransactRequestSourceAsset.md) | | ## Methods ### NewTransactRequest -`func NewTransactRequest(contextID string, mode string, ) *TransactRequest` +`func NewTransactRequest(contextID string, mode string, fromDLTNetworkID string, toDLTNetworkID string, fromAmount string, toAmount string, beneficiaryPubkey string, originatorPubkey string, sourceAsset TransactRequestSourceAsset, destinyAsset TransactRequestSourceAsset, ) *TransactRequest` NewTransactRequest instantiates a new TransactRequest object This constructor will assign default values to properties that have it defined, @@ -117,11 +119,6 @@ and a boolean to check if the value has been set. SetFromDLTNetworkID sets FromDLTNetworkID field to given value. -### HasFromDLTNetworkID - -`func (o *TransactRequest) HasFromDLTNetworkID() bool` - -HasFromDLTNetworkID returns a boolean if a field has been set. ### GetToDLTNetworkID @@ -142,11 +139,6 @@ and a boolean to check if the value has been set. SetToDLTNetworkID sets ToDLTNetworkID field to given value. -### HasToDLTNetworkID - -`func (o *TransactRequest) HasToDLTNetworkID() bool` - -HasToDLTNetworkID returns a boolean if a field has been set. ### GetFromAmount @@ -167,86 +159,106 @@ and a boolean to check if the value has been set. SetFromAmount sets FromAmount field to given value. -### HasFromAmount -`func (o *TransactRequest) HasFromAmount() bool` +### GetToAmount -HasFromAmount returns a boolean if a field has been set. +`func (o *TransactRequest) GetToAmount() string` -### GetFromToken +GetToAmount returns the ToAmount field if non-nil, zero value otherwise. -`func (o *TransactRequest) GetFromToken() string` +### GetToAmountOk -GetFromToken returns the FromToken field if non-nil, zero value otherwise. +`func (o *TransactRequest) GetToAmountOk() (*string, bool)` -### GetFromTokenOk +GetToAmountOk returns a tuple with the ToAmount field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. -`func (o *TransactRequest) GetFromTokenOk() (*string, bool)` +### SetToAmount -GetFromTokenOk returns a tuple with the FromToken field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. +`func (o *TransactRequest) SetToAmount(v string)` -### SetFromToken +SetToAmount sets ToAmount field to given value. -`func (o *TransactRequest) SetFromToken(v string)` -SetFromToken sets FromToken field to given value. +### GetBeneficiaryPubkey -### HasFromToken +`func (o *TransactRequest) GetBeneficiaryPubkey() string` -`func (o *TransactRequest) HasFromToken() bool` +GetBeneficiaryPubkey returns the BeneficiaryPubkey field if non-nil, zero value otherwise. -HasFromToken returns a boolean if a field has been set. +### GetBeneficiaryPubkeyOk -### GetToAmount +`func (o *TransactRequest) GetBeneficiaryPubkeyOk() (*string, bool)` -`func (o *TransactRequest) GetToAmount() string` +GetBeneficiaryPubkeyOk returns a tuple with the BeneficiaryPubkey field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. -GetToAmount returns the ToAmount field if non-nil, zero value otherwise. +### SetBeneficiaryPubkey -### GetToAmountOk +`func (o *TransactRequest) SetBeneficiaryPubkey(v string)` -`func (o *TransactRequest) GetToAmountOk() (*string, bool)` +SetBeneficiaryPubkey sets BeneficiaryPubkey field to given value. -GetToAmountOk returns a tuple with the ToAmount field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. -### SetToAmount +### GetOriginatorPubkey -`func (o *TransactRequest) SetToAmount(v string)` +`func (o *TransactRequest) GetOriginatorPubkey() string` -SetToAmount sets ToAmount field to given value. +GetOriginatorPubkey returns the OriginatorPubkey field if non-nil, zero value otherwise. + +### GetOriginatorPubkeyOk + +`func (o *TransactRequest) GetOriginatorPubkeyOk() (*string, bool)` + +GetOriginatorPubkeyOk returns a tuple with the OriginatorPubkey field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. -### HasToAmount +### SetOriginatorPubkey -`func (o *TransactRequest) HasToAmount() bool` +`func (o *TransactRequest) SetOriginatorPubkey(v string)` -HasToAmount returns a boolean if a field has been set. +SetOriginatorPubkey sets OriginatorPubkey field to given value. -### GetToToken -`func (o *TransactRequest) GetToToken() string` +### GetSourceAsset -GetToToken returns the ToToken field if non-nil, zero value otherwise. +`func (o *TransactRequest) GetSourceAsset() TransactRequestSourceAsset` -### GetToTokenOk +GetSourceAsset returns the SourceAsset field if non-nil, zero value otherwise. -`func (o *TransactRequest) GetToTokenOk() (*string, bool)` +### GetSourceAssetOk -GetToTokenOk returns a tuple with the ToToken field if it's non-nil, zero value otherwise +`func (o *TransactRequest) GetSourceAssetOk() (*TransactRequestSourceAsset, bool)` + +GetSourceAssetOk returns a tuple with the SourceAsset field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. -### SetToToken +### SetSourceAsset + +`func (o *TransactRequest) SetSourceAsset(v TransactRequestSourceAsset)` + +SetSourceAsset sets SourceAsset field to given value. + + +### GetDestinyAsset -`func (o *TransactRequest) SetToToken(v string)` +`func (o *TransactRequest) GetDestinyAsset() TransactRequestSourceAsset` + +GetDestinyAsset returns the DestinyAsset field if non-nil, zero value otherwise. + +### GetDestinyAssetOk + +`func (o *TransactRequest) GetDestinyAssetOk() (*TransactRequestSourceAsset, bool)` + +GetDestinyAssetOk returns a tuple with the DestinyAsset field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. -SetToToken sets ToToken field to given value. +### SetDestinyAsset -### HasToToken +`func (o *TransactRequest) SetDestinyAsset(v TransactRequestSourceAsset)` -`func (o *TransactRequest) HasToToken() bool` +SetDestinyAsset sets DestinyAsset field to given value. -HasToToken returns a boolean if a field has been set. [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/docs/TransactRequestSourceAsset.md b/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/docs/TransactRequestSourceAsset.md new file mode 100644 index 0000000000..2c1bf0579d --- /dev/null +++ b/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/docs/TransactRequestSourceAsset.md @@ -0,0 +1,171 @@ +# TransactRequestSourceAsset + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Owner** | **string** | | +**Ontology** | **string** | | +**ContractName** | **string** | | +**ContractAddress** | Pointer to **string** | | [optional] +**MspId** | Pointer to **string** | | [optional] +**ChannelName** | Pointer to **string** | | [optional] + +## Methods + +### NewTransactRequestSourceAsset + +`func NewTransactRequestSourceAsset(owner string, ontology string, contractName string, ) *TransactRequestSourceAsset` + +NewTransactRequestSourceAsset instantiates a new TransactRequestSourceAsset object +This constructor will assign default values to properties that have it defined, +and makes sure properties required by API are set, but the set of arguments +will change when the set of required properties is changed + +### NewTransactRequestSourceAssetWithDefaults + +`func NewTransactRequestSourceAssetWithDefaults() *TransactRequestSourceAsset` + +NewTransactRequestSourceAssetWithDefaults instantiates a new TransactRequestSourceAsset object +This constructor will only assign default values to properties that have it defined, +but it doesn't guarantee that properties required by API are set + +### GetOwner + +`func (o *TransactRequestSourceAsset) GetOwner() string` + +GetOwner returns the Owner field if non-nil, zero value otherwise. + +### GetOwnerOk + +`func (o *TransactRequestSourceAsset) GetOwnerOk() (*string, bool)` + +GetOwnerOk returns a tuple with the Owner field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetOwner + +`func (o *TransactRequestSourceAsset) SetOwner(v string)` + +SetOwner sets Owner field to given value. + + +### GetOntology + +`func (o *TransactRequestSourceAsset) GetOntology() string` + +GetOntology returns the Ontology field if non-nil, zero value otherwise. + +### GetOntologyOk + +`func (o *TransactRequestSourceAsset) GetOntologyOk() (*string, bool)` + +GetOntologyOk returns a tuple with the Ontology field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetOntology + +`func (o *TransactRequestSourceAsset) SetOntology(v string)` + +SetOntology sets Ontology field to given value. + + +### GetContractName + +`func (o *TransactRequestSourceAsset) GetContractName() string` + +GetContractName returns the ContractName field if non-nil, zero value otherwise. + +### GetContractNameOk + +`func (o *TransactRequestSourceAsset) GetContractNameOk() (*string, bool)` + +GetContractNameOk returns a tuple with the ContractName field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetContractName + +`func (o *TransactRequestSourceAsset) SetContractName(v string)` + +SetContractName sets ContractName field to given value. + + +### GetContractAddress + +`func (o *TransactRequestSourceAsset) GetContractAddress() string` + +GetContractAddress returns the ContractAddress field if non-nil, zero value otherwise. + +### GetContractAddressOk + +`func (o *TransactRequestSourceAsset) GetContractAddressOk() (*string, bool)` + +GetContractAddressOk returns a tuple with the ContractAddress field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetContractAddress + +`func (o *TransactRequestSourceAsset) SetContractAddress(v string)` + +SetContractAddress sets ContractAddress field to given value. + +### HasContractAddress + +`func (o *TransactRequestSourceAsset) HasContractAddress() bool` + +HasContractAddress returns a boolean if a field has been set. + +### GetMspId + +`func (o *TransactRequestSourceAsset) GetMspId() string` + +GetMspId returns the MspId field if non-nil, zero value otherwise. + +### GetMspIdOk + +`func (o *TransactRequestSourceAsset) GetMspIdOk() (*string, bool)` + +GetMspIdOk returns a tuple with the MspId field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetMspId + +`func (o *TransactRequestSourceAsset) SetMspId(v string)` + +SetMspId sets MspId field to given value. + +### HasMspId + +`func (o *TransactRequestSourceAsset) HasMspId() bool` + +HasMspId returns a boolean if a field has been set. + +### GetChannelName + +`func (o *TransactRequestSourceAsset) GetChannelName() string` + +GetChannelName returns the ChannelName field if non-nil, zero value otherwise. + +### GetChannelNameOk + +`func (o *TransactRequestSourceAsset) GetChannelNameOk() (*string, bool)` + +GetChannelNameOk returns a tuple with the ChannelName field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetChannelName + +`func (o *TransactRequestSourceAsset) SetChannelName(v string)` + +SetChannelName sets ChannelName field to given value. + +### HasChannelName + +`func (o *TransactRequestSourceAsset) HasChannelName() bool` + +HasChannelName returns a boolean if a field has been set. + + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/docs/TransactionApi.md b/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/docs/TransactionApi.md index 2321303ad9..1149778379 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/docs/TransactionApi.md +++ b/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/docs/TransactionApi.md @@ -237,7 +237,7 @@ import ( ) func main() { - transactRequest := *openapiclient.NewTransactRequest("123e4567-e89b-12d3-a456-426614174000", "transfer") // TransactRequest | + transactRequest := *openapiclient.NewTransactRequest("123e4567-e89b-12d3-a456-426614174000", "transfer", "network1", "network2", "100", "95", "BeneficiaryPubkey_example", "OriginatorPubkey_example", *openapiclient.NewTransactRequestSourceAsset("Owner_example", "Ontology_example", "ContractName_example"), *openapiclient.NewTransactRequestSourceAsset("Owner_example", "Ontology_example", "ContractName_example")) // TransactRequest | configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) diff --git a/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/model_asset.go b/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/model_asset.go new file mode 100644 index 0000000000..40c45a69fe --- /dev/null +++ b/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/model_asset.go @@ -0,0 +1,279 @@ +/* +SATP Gateway Client (Business Logic Orchestrator) + +SATP is a protocol operating between two gateways that conducts the transfer of a digital asset from one gateway to another. The protocol establishes a secure channel between the endpoints and implements a 2-phase commit to ensure the properties of transfer atomicity, consistency, isolation and durability. This API defines the gateway client facing API (business logic orchestrator, or BLO), which is named API-Type 1 in the SATP-Core specification. **Additional Resources**: - [Proposed SATP Charter](https://datatracker.ietf.org/doc/charter-ietf-satp/) - [SATP Core draft](https://datatracker.ietf.org/doc/draft-ietf-satp-core) - [SATP Crash Recovery draft](https://datatracker.ietf.org/doc/draft-belchior-satp-gateway-recovery/) - [SATP Architecture draft](https://datatracker.ietf.org/doc/draft-ietf-satp-architecture/) - [SATP Use-Cases draft](https://datatracker.ietf.org/doc/draft-ramakrishna-sat-use-cases/) - [SATP Data sharing draft](https://datatracker.ietf.org/doc/draft-ramakrishna-satp-data-sharing) - [SATP View Addresses draft](https://datatracker.ietf.org/doc/draft-ramakrishna-satp-views-addresses) + +API version: 0.0.2 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package generated + +import ( + "encoding/json" +) + +// checks if the Asset type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Asset{} + +// Asset An asset +type Asset struct { + Owner string `json:"owner"` + Ontology string `json:"ontology"` + ContractName string `json:"contractName"` + ContractAddress *string `json:"contractAddress,omitempty"` + MspId *string `json:"mspId,omitempty"` + ChannelName *string `json:"channelName,omitempty"` +} + +// NewAsset instantiates a new Asset object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewAsset(owner string, ontology string, contractName string) *Asset { + this := Asset{} + this.Owner = owner + this.Ontology = ontology + this.ContractName = contractName + return &this +} + +// NewAssetWithDefaults instantiates a new Asset object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewAssetWithDefaults() *Asset { + this := Asset{} + return &this +} + +// GetOwner returns the Owner field value +func (o *Asset) GetOwner() string { + if o == nil { + var ret string + return ret + } + + return o.Owner +} + +// GetOwnerOk returns a tuple with the Owner field value +// and a boolean to check if the value has been set. +func (o *Asset) GetOwnerOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Owner, true +} + +// SetOwner sets field value +func (o *Asset) SetOwner(v string) { + o.Owner = v +} + +// GetOntology returns the Ontology field value +func (o *Asset) GetOntology() string { + if o == nil { + var ret string + return ret + } + + return o.Ontology +} + +// GetOntologyOk returns a tuple with the Ontology field value +// and a boolean to check if the value has been set. +func (o *Asset) GetOntologyOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Ontology, true +} + +// SetOntology sets field value +func (o *Asset) SetOntology(v string) { + o.Ontology = v +} + +// GetContractName returns the ContractName field value +func (o *Asset) GetContractName() string { + if o == nil { + var ret string + return ret + } + + return o.ContractName +} + +// GetContractNameOk returns a tuple with the ContractName field value +// and a boolean to check if the value has been set. +func (o *Asset) GetContractNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ContractName, true +} + +// SetContractName sets field value +func (o *Asset) SetContractName(v string) { + o.ContractName = v +} + +// GetContractAddress returns the ContractAddress field value if set, zero value otherwise. +func (o *Asset) GetContractAddress() string { + if o == nil || IsNil(o.ContractAddress) { + var ret string + return ret + } + return *o.ContractAddress +} + +// GetContractAddressOk returns a tuple with the ContractAddress field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Asset) GetContractAddressOk() (*string, bool) { + if o == nil || IsNil(o.ContractAddress) { + return nil, false + } + return o.ContractAddress, true +} + +// HasContractAddress returns a boolean if a field has been set. +func (o *Asset) HasContractAddress() bool { + if o != nil && !IsNil(o.ContractAddress) { + return true + } + + return false +} + +// SetContractAddress gets a reference to the given string and assigns it to the ContractAddress field. +func (o *Asset) SetContractAddress(v string) { + o.ContractAddress = &v +} + +// GetMspId returns the MspId field value if set, zero value otherwise. +func (o *Asset) GetMspId() string { + if o == nil || IsNil(o.MspId) { + var ret string + return ret + } + return *o.MspId +} + +// GetMspIdOk returns a tuple with the MspId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Asset) GetMspIdOk() (*string, bool) { + if o == nil || IsNil(o.MspId) { + return nil, false + } + return o.MspId, true +} + +// HasMspId returns a boolean if a field has been set. +func (o *Asset) HasMspId() bool { + if o != nil && !IsNil(o.MspId) { + return true + } + + return false +} + +// SetMspId gets a reference to the given string and assigns it to the MspId field. +func (o *Asset) SetMspId(v string) { + o.MspId = &v +} + +// GetChannelName returns the ChannelName field value if set, zero value otherwise. +func (o *Asset) GetChannelName() string { + if o == nil || IsNil(o.ChannelName) { + var ret string + return ret + } + return *o.ChannelName +} + +// GetChannelNameOk returns a tuple with the ChannelName field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Asset) GetChannelNameOk() (*string, bool) { + if o == nil || IsNil(o.ChannelName) { + return nil, false + } + return o.ChannelName, true +} + +// HasChannelName returns a boolean if a field has been set. +func (o *Asset) HasChannelName() bool { + if o != nil && !IsNil(o.ChannelName) { + return true + } + + return false +} + +// SetChannelName gets a reference to the given string and assigns it to the ChannelName field. +func (o *Asset) SetChannelName(v string) { + o.ChannelName = &v +} + +func (o Asset) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Asset) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["owner"] = o.Owner + toSerialize["ontology"] = o.Ontology + toSerialize["contractName"] = o.ContractName + if !IsNil(o.ContractAddress) { + toSerialize["contractAddress"] = o.ContractAddress + } + if !IsNil(o.MspId) { + toSerialize["mspId"] = o.MspId + } + if !IsNil(o.ChannelName) { + toSerialize["channelName"] = o.ChannelName + } + return toSerialize, nil +} + +type NullableAsset struct { + value *Asset + isSet bool +} + +func (v NullableAsset) Get() *Asset { + return v.value +} + +func (v *NullableAsset) Set(val *Asset) { + v.value = val + v.isSet = true +} + +func (v NullableAsset) IsSet() bool { + return v.isSet +} + +func (v *NullableAsset) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableAsset(val *Asset) *NullableAsset { + return &NullableAsset{value: val, isSet: true} +} + +func (v NullableAsset) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableAsset) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/model_transact_request.go b/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/model_transact_request.go index a3bb88bc87..2669a7cb74 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/model_transact_request.go +++ b/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/model_transact_request.go @@ -22,22 +22,32 @@ type TransactRequest struct { ContextID string `json:"contextID"` Mode string `json:"mode"` Payload *string `json:"payload,omitempty"` - FromDLTNetworkID *string `json:"fromDLTNetworkID,omitempty"` - ToDLTNetworkID *string `json:"toDLTNetworkID,omitempty"` - FromAmount *string `json:"fromAmount,omitempty"` - FromToken *string `json:"fromToken,omitempty"` - ToAmount *string `json:"toAmount,omitempty"` - ToToken *string `json:"toToken,omitempty"` + FromDLTNetworkID string `json:"fromDLTNetworkID"` + ToDLTNetworkID string `json:"toDLTNetworkID"` + FromAmount string `json:"fromAmount"` + ToAmount string `json:"toAmount"` + BeneficiaryPubkey string `json:"beneficiaryPubkey"` + OriginatorPubkey string `json:"originatorPubkey"` + SourceAsset TransactRequestSourceAsset `json:"sourceAsset"` + DestinyAsset TransactRequestSourceAsset `json:"destinyAsset"` } // NewTransactRequest instantiates a new TransactRequest object // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func NewTransactRequest(contextID string, mode string) *TransactRequest { +func NewTransactRequest(contextID string, mode string, fromDLTNetworkID string, toDLTNetworkID string, fromAmount string, toAmount string, beneficiaryPubkey string, originatorPubkey string, sourceAsset TransactRequestSourceAsset, destinyAsset TransactRequestSourceAsset) *TransactRequest { this := TransactRequest{} this.ContextID = contextID this.Mode = mode + this.FromDLTNetworkID = fromDLTNetworkID + this.ToDLTNetworkID = toDLTNetworkID + this.FromAmount = fromAmount + this.ToAmount = toAmount + this.BeneficiaryPubkey = beneficiaryPubkey + this.OriginatorPubkey = originatorPubkey + this.SourceAsset = sourceAsset + this.DestinyAsset = destinyAsset return &this } @@ -129,196 +139,196 @@ func (o *TransactRequest) SetPayload(v string) { o.Payload = &v } -// GetFromDLTNetworkID returns the FromDLTNetworkID field value if set, zero value otherwise. +// GetFromDLTNetworkID returns the FromDLTNetworkID field value func (o *TransactRequest) GetFromDLTNetworkID() string { - if o == nil || IsNil(o.FromDLTNetworkID) { + if o == nil { var ret string return ret } - return *o.FromDLTNetworkID + + return o.FromDLTNetworkID } -// GetFromDLTNetworkIDOk returns a tuple with the FromDLTNetworkID field value if set, nil otherwise +// GetFromDLTNetworkIDOk returns a tuple with the FromDLTNetworkID field value // and a boolean to check if the value has been set. func (o *TransactRequest) GetFromDLTNetworkIDOk() (*string, bool) { - if o == nil || IsNil(o.FromDLTNetworkID) { + if o == nil { return nil, false } - return o.FromDLTNetworkID, true -} - -// HasFromDLTNetworkID returns a boolean if a field has been set. -func (o *TransactRequest) HasFromDLTNetworkID() bool { - if o != nil && !IsNil(o.FromDLTNetworkID) { - return true - } - - return false + return &o.FromDLTNetworkID, true } -// SetFromDLTNetworkID gets a reference to the given string and assigns it to the FromDLTNetworkID field. +// SetFromDLTNetworkID sets field value func (o *TransactRequest) SetFromDLTNetworkID(v string) { - o.FromDLTNetworkID = &v + o.FromDLTNetworkID = v } -// GetToDLTNetworkID returns the ToDLTNetworkID field value if set, zero value otherwise. +// GetToDLTNetworkID returns the ToDLTNetworkID field value func (o *TransactRequest) GetToDLTNetworkID() string { - if o == nil || IsNil(o.ToDLTNetworkID) { + if o == nil { var ret string return ret } - return *o.ToDLTNetworkID + + return o.ToDLTNetworkID } -// GetToDLTNetworkIDOk returns a tuple with the ToDLTNetworkID field value if set, nil otherwise +// GetToDLTNetworkIDOk returns a tuple with the ToDLTNetworkID field value // and a boolean to check if the value has been set. func (o *TransactRequest) GetToDLTNetworkIDOk() (*string, bool) { - if o == nil || IsNil(o.ToDLTNetworkID) { + if o == nil { return nil, false } - return o.ToDLTNetworkID, true -} - -// HasToDLTNetworkID returns a boolean if a field has been set. -func (o *TransactRequest) HasToDLTNetworkID() bool { - if o != nil && !IsNil(o.ToDLTNetworkID) { - return true - } - - return false + return &o.ToDLTNetworkID, true } -// SetToDLTNetworkID gets a reference to the given string and assigns it to the ToDLTNetworkID field. +// SetToDLTNetworkID sets field value func (o *TransactRequest) SetToDLTNetworkID(v string) { - o.ToDLTNetworkID = &v + o.ToDLTNetworkID = v } -// GetFromAmount returns the FromAmount field value if set, zero value otherwise. +// GetFromAmount returns the FromAmount field value func (o *TransactRequest) GetFromAmount() string { - if o == nil || IsNil(o.FromAmount) { + if o == nil { var ret string return ret } - return *o.FromAmount + + return o.FromAmount } -// GetFromAmountOk returns a tuple with the FromAmount field value if set, nil otherwise +// GetFromAmountOk returns a tuple with the FromAmount field value // and a boolean to check if the value has been set. func (o *TransactRequest) GetFromAmountOk() (*string, bool) { - if o == nil || IsNil(o.FromAmount) { + if o == nil { return nil, false } - return o.FromAmount, true -} - -// HasFromAmount returns a boolean if a field has been set. -func (o *TransactRequest) HasFromAmount() bool { - if o != nil && !IsNil(o.FromAmount) { - return true - } - - return false + return &o.FromAmount, true } -// SetFromAmount gets a reference to the given string and assigns it to the FromAmount field. +// SetFromAmount sets field value func (o *TransactRequest) SetFromAmount(v string) { - o.FromAmount = &v + o.FromAmount = v } -// GetFromToken returns the FromToken field value if set, zero value otherwise. -func (o *TransactRequest) GetFromToken() string { - if o == nil || IsNil(o.FromToken) { +// GetToAmount returns the ToAmount field value +func (o *TransactRequest) GetToAmount() string { + if o == nil { var ret string return ret } - return *o.FromToken + + return o.ToAmount } -// GetFromTokenOk returns a tuple with the FromToken field value if set, nil otherwise +// GetToAmountOk returns a tuple with the ToAmount field value // and a boolean to check if the value has been set. -func (o *TransactRequest) GetFromTokenOk() (*string, bool) { - if o == nil || IsNil(o.FromToken) { +func (o *TransactRequest) GetToAmountOk() (*string, bool) { + if o == nil { return nil, false } - return o.FromToken, true -} - -// HasFromToken returns a boolean if a field has been set. -func (o *TransactRequest) HasFromToken() bool { - if o != nil && !IsNil(o.FromToken) { - return true - } - - return false + return &o.ToAmount, true } -// SetFromToken gets a reference to the given string and assigns it to the FromToken field. -func (o *TransactRequest) SetFromToken(v string) { - o.FromToken = &v +// SetToAmount sets field value +func (o *TransactRequest) SetToAmount(v string) { + o.ToAmount = v } -// GetToAmount returns the ToAmount field value if set, zero value otherwise. -func (o *TransactRequest) GetToAmount() string { - if o == nil || IsNil(o.ToAmount) { +// GetBeneficiaryPubkey returns the BeneficiaryPubkey field value +func (o *TransactRequest) GetBeneficiaryPubkey() string { + if o == nil { var ret string return ret } - return *o.ToAmount + + return o.BeneficiaryPubkey } -// GetToAmountOk returns a tuple with the ToAmount field value if set, nil otherwise +// GetBeneficiaryPubkeyOk returns a tuple with the BeneficiaryPubkey field value // and a boolean to check if the value has been set. -func (o *TransactRequest) GetToAmountOk() (*string, bool) { - if o == nil || IsNil(o.ToAmount) { +func (o *TransactRequest) GetBeneficiaryPubkeyOk() (*string, bool) { + if o == nil { return nil, false } - return o.ToAmount, true + return &o.BeneficiaryPubkey, true } -// HasToAmount returns a boolean if a field has been set. -func (o *TransactRequest) HasToAmount() bool { - if o != nil && !IsNil(o.ToAmount) { - return true +// SetBeneficiaryPubkey sets field value +func (o *TransactRequest) SetBeneficiaryPubkey(v string) { + o.BeneficiaryPubkey = v +} + +// GetOriginatorPubkey returns the OriginatorPubkey field value +func (o *TransactRequest) GetOriginatorPubkey() string { + if o == nil { + var ret string + return ret } - return false + return o.OriginatorPubkey } -// SetToAmount gets a reference to the given string and assigns it to the ToAmount field. -func (o *TransactRequest) SetToAmount(v string) { - o.ToAmount = &v +// GetOriginatorPubkeyOk returns a tuple with the OriginatorPubkey field value +// and a boolean to check if the value has been set. +func (o *TransactRequest) GetOriginatorPubkeyOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.OriginatorPubkey, true } -// GetToToken returns the ToToken field value if set, zero value otherwise. -func (o *TransactRequest) GetToToken() string { - if o == nil || IsNil(o.ToToken) { - var ret string +// SetOriginatorPubkey sets field value +func (o *TransactRequest) SetOriginatorPubkey(v string) { + o.OriginatorPubkey = v +} + +// GetSourceAsset returns the SourceAsset field value +func (o *TransactRequest) GetSourceAsset() TransactRequestSourceAsset { + if o == nil { + var ret TransactRequestSourceAsset return ret } - return *o.ToToken + + return o.SourceAsset } -// GetToTokenOk returns a tuple with the ToToken field value if set, nil otherwise +// GetSourceAssetOk returns a tuple with the SourceAsset field value // and a boolean to check if the value has been set. -func (o *TransactRequest) GetToTokenOk() (*string, bool) { - if o == nil || IsNil(o.ToToken) { +func (o *TransactRequest) GetSourceAssetOk() (*TransactRequestSourceAsset, bool) { + if o == nil { return nil, false } - return o.ToToken, true + return &o.SourceAsset, true } -// HasToToken returns a boolean if a field has been set. -func (o *TransactRequest) HasToToken() bool { - if o != nil && !IsNil(o.ToToken) { - return true +// SetSourceAsset sets field value +func (o *TransactRequest) SetSourceAsset(v TransactRequestSourceAsset) { + o.SourceAsset = v +} + +// GetDestinyAsset returns the DestinyAsset field value +func (o *TransactRequest) GetDestinyAsset() TransactRequestSourceAsset { + if o == nil { + var ret TransactRequestSourceAsset + return ret } - return false + return o.DestinyAsset +} + +// GetDestinyAssetOk returns a tuple with the DestinyAsset field value +// and a boolean to check if the value has been set. +func (o *TransactRequest) GetDestinyAssetOk() (*TransactRequestSourceAsset, bool) { + if o == nil { + return nil, false + } + return &o.DestinyAsset, true } -// SetToToken gets a reference to the given string and assigns it to the ToToken field. -func (o *TransactRequest) SetToToken(v string) { - o.ToToken = &v +// SetDestinyAsset sets field value +func (o *TransactRequest) SetDestinyAsset(v TransactRequestSourceAsset) { + o.DestinyAsset = v } func (o TransactRequest) MarshalJSON() ([]byte, error) { @@ -336,24 +346,14 @@ func (o TransactRequest) ToMap() (map[string]interface{}, error) { if !IsNil(o.Payload) { toSerialize["payload"] = o.Payload } - if !IsNil(o.FromDLTNetworkID) { - toSerialize["fromDLTNetworkID"] = o.FromDLTNetworkID - } - if !IsNil(o.ToDLTNetworkID) { - toSerialize["toDLTNetworkID"] = o.ToDLTNetworkID - } - if !IsNil(o.FromAmount) { - toSerialize["fromAmount"] = o.FromAmount - } - if !IsNil(o.FromToken) { - toSerialize["fromToken"] = o.FromToken - } - if !IsNil(o.ToAmount) { - toSerialize["toAmount"] = o.ToAmount - } - if !IsNil(o.ToToken) { - toSerialize["toToken"] = o.ToToken - } + toSerialize["fromDLTNetworkID"] = o.FromDLTNetworkID + toSerialize["toDLTNetworkID"] = o.ToDLTNetworkID + toSerialize["fromAmount"] = o.FromAmount + toSerialize["toAmount"] = o.ToAmount + toSerialize["beneficiaryPubkey"] = o.BeneficiaryPubkey + toSerialize["originatorPubkey"] = o.OriginatorPubkey + toSerialize["sourceAsset"] = o.SourceAsset + toSerialize["destinyAsset"] = o.DestinyAsset return toSerialize, nil } diff --git a/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/model_transact_request_source_asset.go b/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/model_transact_request_source_asset.go new file mode 100644 index 0000000000..efa04419c1 --- /dev/null +++ b/packages/cactus-plugin-satp-hermes/src/main/go/generated/gateway-client/model_transact_request_source_asset.go @@ -0,0 +1,279 @@ +/* +SATP Gateway Client (Business Logic Orchestrator) + +SATP is a protocol operating between two gateways that conducts the transfer of a digital asset from one gateway to another. The protocol establishes a secure channel between the endpoints and implements a 2-phase commit to ensure the properties of transfer atomicity, consistency, isolation and durability. This API defines the gateway client facing API (business logic orchestrator, or BLO), which is named API-Type 1 in the SATP-Core specification. **Additional Resources**: - [Proposed SATP Charter](https://datatracker.ietf.org/doc/charter-ietf-satp/) - [SATP Core draft](https://datatracker.ietf.org/doc/draft-ietf-satp-core) - [SATP Crash Recovery draft](https://datatracker.ietf.org/doc/draft-belchior-satp-gateway-recovery/) - [SATP Architecture draft](https://datatracker.ietf.org/doc/draft-ietf-satp-architecture/) - [SATP Use-Cases draft](https://datatracker.ietf.org/doc/draft-ramakrishna-sat-use-cases/) - [SATP Data sharing draft](https://datatracker.ietf.org/doc/draft-ramakrishna-satp-data-sharing) - [SATP View Addresses draft](https://datatracker.ietf.org/doc/draft-ramakrishna-satp-views-addresses) + +API version: 0.0.2 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package generated + +import ( + "encoding/json" +) + +// checks if the TransactRequestSourceAsset type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &TransactRequestSourceAsset{} + +// TransactRequestSourceAsset An asset +type TransactRequestSourceAsset struct { + Owner string `json:"owner"` + Ontology string `json:"ontology"` + ContractName string `json:"contractName"` + ContractAddress *string `json:"contractAddress,omitempty"` + MspId *string `json:"mspId,omitempty"` + ChannelName *string `json:"channelName,omitempty"` +} + +// NewTransactRequestSourceAsset instantiates a new TransactRequestSourceAsset object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewTransactRequestSourceAsset(owner string, ontology string, contractName string) *TransactRequestSourceAsset { + this := TransactRequestSourceAsset{} + this.Owner = owner + this.Ontology = ontology + this.ContractName = contractName + return &this +} + +// NewTransactRequestSourceAssetWithDefaults instantiates a new TransactRequestSourceAsset object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewTransactRequestSourceAssetWithDefaults() *TransactRequestSourceAsset { + this := TransactRequestSourceAsset{} + return &this +} + +// GetOwner returns the Owner field value +func (o *TransactRequestSourceAsset) GetOwner() string { + if o == nil { + var ret string + return ret + } + + return o.Owner +} + +// GetOwnerOk returns a tuple with the Owner field value +// and a boolean to check if the value has been set. +func (o *TransactRequestSourceAsset) GetOwnerOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Owner, true +} + +// SetOwner sets field value +func (o *TransactRequestSourceAsset) SetOwner(v string) { + o.Owner = v +} + +// GetOntology returns the Ontology field value +func (o *TransactRequestSourceAsset) GetOntology() string { + if o == nil { + var ret string + return ret + } + + return o.Ontology +} + +// GetOntologyOk returns a tuple with the Ontology field value +// and a boolean to check if the value has been set. +func (o *TransactRequestSourceAsset) GetOntologyOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Ontology, true +} + +// SetOntology sets field value +func (o *TransactRequestSourceAsset) SetOntology(v string) { + o.Ontology = v +} + +// GetContractName returns the ContractName field value +func (o *TransactRequestSourceAsset) GetContractName() string { + if o == nil { + var ret string + return ret + } + + return o.ContractName +} + +// GetContractNameOk returns a tuple with the ContractName field value +// and a boolean to check if the value has been set. +func (o *TransactRequestSourceAsset) GetContractNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ContractName, true +} + +// SetContractName sets field value +func (o *TransactRequestSourceAsset) SetContractName(v string) { + o.ContractName = v +} + +// GetContractAddress returns the ContractAddress field value if set, zero value otherwise. +func (o *TransactRequestSourceAsset) GetContractAddress() string { + if o == nil || IsNil(o.ContractAddress) { + var ret string + return ret + } + return *o.ContractAddress +} + +// GetContractAddressOk returns a tuple with the ContractAddress field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *TransactRequestSourceAsset) GetContractAddressOk() (*string, bool) { + if o == nil || IsNil(o.ContractAddress) { + return nil, false + } + return o.ContractAddress, true +} + +// HasContractAddress returns a boolean if a field has been set. +func (o *TransactRequestSourceAsset) HasContractAddress() bool { + if o != nil && !IsNil(o.ContractAddress) { + return true + } + + return false +} + +// SetContractAddress gets a reference to the given string and assigns it to the ContractAddress field. +func (o *TransactRequestSourceAsset) SetContractAddress(v string) { + o.ContractAddress = &v +} + +// GetMspId returns the MspId field value if set, zero value otherwise. +func (o *TransactRequestSourceAsset) GetMspId() string { + if o == nil || IsNil(o.MspId) { + var ret string + return ret + } + return *o.MspId +} + +// GetMspIdOk returns a tuple with the MspId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *TransactRequestSourceAsset) GetMspIdOk() (*string, bool) { + if o == nil || IsNil(o.MspId) { + return nil, false + } + return o.MspId, true +} + +// HasMspId returns a boolean if a field has been set. +func (o *TransactRequestSourceAsset) HasMspId() bool { + if o != nil && !IsNil(o.MspId) { + return true + } + + return false +} + +// SetMspId gets a reference to the given string and assigns it to the MspId field. +func (o *TransactRequestSourceAsset) SetMspId(v string) { + o.MspId = &v +} + +// GetChannelName returns the ChannelName field value if set, zero value otherwise. +func (o *TransactRequestSourceAsset) GetChannelName() string { + if o == nil || IsNil(o.ChannelName) { + var ret string + return ret + } + return *o.ChannelName +} + +// GetChannelNameOk returns a tuple with the ChannelName field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *TransactRequestSourceAsset) GetChannelNameOk() (*string, bool) { + if o == nil || IsNil(o.ChannelName) { + return nil, false + } + return o.ChannelName, true +} + +// HasChannelName returns a boolean if a field has been set. +func (o *TransactRequestSourceAsset) HasChannelName() bool { + if o != nil && !IsNil(o.ChannelName) { + return true + } + + return false +} + +// SetChannelName gets a reference to the given string and assigns it to the ChannelName field. +func (o *TransactRequestSourceAsset) SetChannelName(v string) { + o.ChannelName = &v +} + +func (o TransactRequestSourceAsset) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o TransactRequestSourceAsset) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["owner"] = o.Owner + toSerialize["ontology"] = o.Ontology + toSerialize["contractName"] = o.ContractName + if !IsNil(o.ContractAddress) { + toSerialize["contractAddress"] = o.ContractAddress + } + if !IsNil(o.MspId) { + toSerialize["mspId"] = o.MspId + } + if !IsNil(o.ChannelName) { + toSerialize["channelName"] = o.ChannelName + } + return toSerialize, nil +} + +type NullableTransactRequestSourceAsset struct { + value *TransactRequestSourceAsset + isSet bool +} + +func (v NullableTransactRequestSourceAsset) Get() *TransactRequestSourceAsset { + return v.value +} + +func (v *NullableTransactRequestSourceAsset) Set(val *TransactRequestSourceAsset) { + v.value = val + v.isSet = true +} + +func (v NullableTransactRequestSourceAsset) IsSet() bool { + return v.isSet +} + +func (v *NullableTransactRequestSourceAsset) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableTransactRequestSourceAsset(val *TransactRequestSourceAsset) *NullableTransactRequestSourceAsset { + return &NullableTransactRequestSourceAsset{value: val, isSet: true} +} + +func (v NullableTransactRequestSourceAsset) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableTransactRequestSourceAsset) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/packages/cactus-plugin-satp-hermes/src/main/json/openapi-blo-bundled.json b/packages/cactus-plugin-satp-hermes/src/main/json/openapi-blo-bundled.json index 3d121dfd3f..2b42e56f90 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/json/openapi-blo-bundled.json +++ b/packages/cactus-plugin-satp-hermes/src/main/json/openapi-blo-bundled.json @@ -58,7 +58,15 @@ "type": "object", "required": [ "contextID", - "mode" + "mode", + "fromDLTNetworkID", + "toDLTNetworkID", + "fromAmount", + "toAmount", + "beneficiaryPubkey", + "originatorPubkey", + "sourceAsset", + "destinyAsset" ], "properties": { "contextID": { @@ -90,17 +98,73 @@ "type": "string", "example": "100" }, - "fromToken": { - "type": "string", - "example": "TOKEN1" - }, "toAmount": { "type": "string", "example": "95" }, - "toToken": { - "type": "string", - "example": "TOKEN2" + "beneficiaryPubkey": { + "type": "string" + }, + "originatorPubkey": { + "type": "string" + }, + "sourceAsset": { + "description": "An asset", + "type": "object", + "required": [ + "owner", + "ontology", + "contractName" + ], + "properties": { + "owner": { + "type": "string" + }, + "ontology": { + "type": "string" + }, + "contractName": { + "type": "string" + }, + "contractAddress": { + "type": "string" + }, + "mspId": { + "type": "string" + }, + "channelName": { + "type": "string" + } + } + }, + "destinyAsset": { + "description": "An asset", + "type": "object", + "required": [ + "owner", + "ontology", + "contractName" + ], + "properties": { + "owner": { + "type": "string" + }, + "ontology": { + "type": "string" + }, + "contractName": { + "type": "string" + }, + "contractAddress": { + "type": "string" + }, + "mspId": { + "type": "string" + }, + "channelName": { + "type": "string" + } + } } } } @@ -2659,12 +2723,49 @@ }, "example": "123e4567-e89b-12d3-a456-426614174000" }, + "Asset": { + "description": "An asset", + "type": "object", + "required": [ + "owner", + "ontology", + "contractName" + ], + "properties": { + "owner": { + "type": "string" + }, + "ontology": { + "type": "string" + }, + "contractName": { + "type": "string" + }, + "contractAddress": { + "type": "string" + }, + "mspId": { + "type": "string" + }, + "channelName": { + "type": "string" + } + } + }, "TransactRequest": { "description": "Request schema for initiating a transaction. Includes details such as the transaction context, mode (data or transfer), payload, and information about the source and destination DLT networks.", "type": "object", "required": [ "contextID", - "mode" + "mode", + "fromDLTNetworkID", + "toDLTNetworkID", + "fromAmount", + "toAmount", + "beneficiaryPubkey", + "originatorPubkey", + "sourceAsset", + "destinyAsset" ], "properties": { "contextID": { @@ -2696,17 +2797,73 @@ "type": "string", "example": "100" }, - "fromToken": { - "type": "string", - "example": "TOKEN1" - }, "toAmount": { "type": "string", "example": "95" }, - "toToken": { - "type": "string", - "example": "TOKEN2" + "beneficiaryPubkey": { + "type": "string" + }, + "originatorPubkey": { + "type": "string" + }, + "sourceAsset": { + "description": "An asset", + "type": "object", + "required": [ + "owner", + "ontology", + "contractName" + ], + "properties": { + "owner": { + "type": "string" + }, + "ontology": { + "type": "string" + }, + "contractName": { + "type": "string" + }, + "contractAddress": { + "type": "string" + }, + "mspId": { + "type": "string" + }, + "channelName": { + "type": "string" + } + } + }, + "destinyAsset": { + "description": "An asset", + "type": "object", + "required": [ + "owner", + "ontology", + "contractName" + ], + "properties": { + "owner": { + "type": "string" + }, + "ontology": { + "type": "string" + }, + "contractName": { + "type": "string" + }, + "contractAddress": { + "type": "string" + }, + "mspId": { + "type": "string" + }, + "channelName": { + "type": "string" + } + } } } }, 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 88f464488c..912f5a216a 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 @@ -38,12 +38,19 @@ message TransferClaims { uint64 max_timeout = 14; string amount_from_originator = 15; string amount_to_beneficiary = 16; + repeated PrivacyPolicy processPolicies = 17; + repeated PrivacyPolicy mergePolicies = 18; } message TransferClaimsFormat { } +message PrivacyPolicy { + string name = 1; + repeated string arguments = 2; + } + message Permissions { } @@ -109,6 +116,10 @@ enum MessageType { MESSAGE_TYPE_COMMIT_FINAL = 15; MESSAGE_TYPE_ACK_COMMIT_FINAL = 16; MESSAGE_TYPE_COMMIT_TRANSFER_COMPLETE = 17; + MESSAGE_TYPE_NEW_SESSION_REQUEST = 18; + MESSAGE_TYPE_NEW_SESSION_RESPONSE = 19; + MESSAGE_TYPE_PRE_SATP_TRANSFER_REQUEST = 20; + MESSAGE_TYPE_PRE_SATP_TRANSFER_RESPONSE = 21; } message CommonSatp { @@ -235,3 +246,31 @@ message AssignmentAssertionClaim { string signature = 2; } +message WrapAssertionClaim { + string receipt = 1; + string signature = 2; +} + +enum TokenType { + TOKEN_TYPE_ERC20 = 0; + TOKEN_TYPE_ERC721 = 1; + TOKEN_TYPE_ERC1155 = 2; + TOKEN_TYPE_NONSTANDARD = 3; +} + +message Asset { + string token_id = 1; + TokenType token_type = 2; + string owner = 3; + uint64 amount = 4; + string ontology = 5; + string contract_name = 7; + //besu + string contract_address = 6; + //fabric + string msp_id = 8; + string channel_name = 9; + + +} + 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 ec33400858..a4f0de9bc9 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 @@ -68,14 +68,28 @@ message SessionData { string server_transfer_number = 58; uint64 lock_assertion_expiration = 59; cacti.satp.v02.common.AssetProfile asset_profile = 60; - string resource_url = 61; + string sender_contract_ontology = 61; + string receiver_contract_ontology = 62; + string resource_url = 63; + cacti.satp.v02.common.WrapAssertionClaim sender_wrap_assertion_claim = 64; + cacti.satp.v02.common.WrapAssertionClaim receiver_wrap_assertion_claim = 65; + cacti.satp.v02.common.Asset sender_asset = 66; + cacti.satp.v02.common.Asset receiver_asset = 67; } message MessageStagesHashes { - Stage1Hashes stage1 = 1; - Stage2Hashes stage2 = 2; - Stage3Hashes stage3 = 3; + Stage0Hashes stage0 = 1; + Stage1Hashes stage1 = 2; + Stage2Hashes stage2 = 3; + Stage3Hashes stage3 = 4; +} + +message Stage0Hashes { + string new_session_request_message_hash = 1; + string new_session_response_message_hash = 2; + string pre_satp_transfer_request_message_hash = 3; + string pre_satp_transfer_response_message_hash = 4; } message Stage1Hashes { @@ -100,9 +114,17 @@ message Stage3Hashes { } message MessageStagesSignatures { - Stage1Signatures stage1 = 1; - Stage2Signatures stage2 = 2; - Stage3Signatures stage3 = 3; + Stage0Signatures stage0 = 1; + Stage1Signatures stage1 = 2; + Stage2Signatures stage2 = 3; + Stage3Signatures stage3 = 4; +} + +message Stage0Signatures { + string new_session_request_message_signature = 1; + string new_session_response_message_signature = 2; + string pre_satp_transfer_request_message_signature = 3; + string pre_satp_transfer_response_message_signature = 4; } message Stage1Signatures { @@ -127,9 +149,17 @@ message Stage3Signatures { } message MessageStagesTimestamps { - Stage1Timestamps stage1 = 1; - Stage2Timestamps stage2 = 2; - Stage3Timestamps stage3 = 3; + Stage0Timestamps stage0 = 1; + Stage1Timestamps stage1 = 2; + Stage2Timestamps stage2 = 3; + Stage3Timestamps stage3 = 4; +} + +message Stage0Timestamps { + string new_session_request_message_timestamp = 1; + string new_session_response_message_timestamp = 2; + string pre_satp_transfer_request_message_timestamp = 3; + string pre_satp_transfer_response_message_timestamp = 4; } message Stage1Timestamps { diff --git a/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/stage_0.proto b/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/stage_0.proto index 7172208c82..fb551c9902 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/stage_0.proto +++ b/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/stage_0.proto @@ -5,43 +5,64 @@ package cacti.satp.v02; import "cacti/satp/v02/common/message.proto"; import "google/protobuf/empty.proto"; -message PrivacyPolicy { - string name = 1; - repeated string arguments = 2; +enum STATUS { + STATUS_UNSPECIFIED = 0; + STATUS_ACCEPTED = 1; + STATUS_REJECTED = 2; } -message PreTransferVerificationAndContextEstablishmentRequest { - cacti.satp.v02.common.CommonSatp context = 1; - cacti.satp.v02.common.TransferClaims transfer_claims = 2; // needed ? - repeated PrivacyPolicy processPolicies = 3; - repeated PrivacyPolicy mergePolicies = 4; + +message NewSessionRequest { + string session_id = 1; + string context_id = 2; + string client_transfer_number = 3; + string sender_gateway_network_id = 4; + string recipient_gateway_network_id = 5; + string gateway_id = 6; //TODO FIX this change so it gets the gateway ID from channel + string client_signature = 7; } -// TODO -message PreTransferVerificationAndContextEstablishmentResponse { - cacti.satp.v02.common.CommonSatp context = 1; - repeated PrivacyPolicy processPolicies_counter_proposal = 2; - repeated PrivacyPolicy mergePolicies_counter_proposal = 3; - string hash_pre_transfer_verification_and_context = 4; - string timestamp = 5; +message NewSessionResponse { + string session_id = 1; + string context_id = 2; + STATUS status = 3; + string hash_previous_message = 4; + string sender_gateway_network_id = 5; + string recipient_gateway_network_id = 6; + string server_signature = 7; } -message PreTransferCommenceRequestMessage { - cacti.satp.v02.common.CommonSatp common = 1; - string hash_pre_transfer_verification_and_context = 2; + +message PreSATPTransferRequest { + string session_id = 1; + string context_id = 2; string client_transfer_number = 3; + string sender_gateway_network_id = 4; + string recipient_gateway_network_id = 5; + cacti.satp.v02.common.Asset sender_asset = 6; + cacti.satp.v02.common.Asset receiver_asset = 7; + cacti.satp.v02.common.WrapAssertionClaim wrap_assertion_claim = 8; + string hash_previous_message = 9; + string client_signature = 10; +} + +message PreSATPTransferResponse { + string session_id = 1; + string context_id = 2; + cacti.satp.v02.common.WrapAssertionClaim wrap_assertion_claim = 3; + string hash_previous_message = 4; + string recipient_token_id = 5; + string server_signature = 6; } -message PreTransferCommenceResponseMessage { - cacti.satp.v02.common.CommonSatp common = 1; + +message CheckRequest { + string check = 1; } -message PublicKey { - string public_key = 1; +message CheckResponse { + string check = 1; } -service SatpStage0Service { - // util RPCs - rpc GetPublicKey(google.protobuf.Empty) returns (PublicKey) {}; - // step RPCs - rpc PreTransferProposalClaims(PreTransferVerificationAndContextEstablishmentRequest) returns (PreTransferVerificationAndContextEstablishmentResponse) {}; - rpc PreTransferCommence(PreTransferCommenceRequestMessage) returns (PreTransferCommenceResponseMessage) {} - // todo other rpcs +service SatpStage0Service { + rpc NewSession(NewSessionRequest) returns (NewSessionResponse) {} + rpc PreSATPTransfer(PreSATPTransferRequest) returns (PreSATPTransferResponse) {} + rpc Check(CheckRequest) returns (CheckResponse) {} } \ No newline at end of file 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 966de6ef1c..8b4441f2df 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 @@ -16,11 +16,14 @@ import { GetStatusEndpointV1 } from "../web-services/status-endpoint"; import { StatusRequest, StatusResponse, + TransactRequest, + TransactResponse, } from "../generated/gateway-client/typescript-axios/api"; 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"; +import { ExecuteTransact } from "./transaction/transact-handler-service"; export interface BLODispatcherOptions { logger: Logger; @@ -29,6 +32,7 @@ export interface BLODispatcherOptions { orchestrator: GatewayOrchestrator; signer: JsObjectSigner; bridgesManager: SATPBridgesManager; + pubKey: string; } export class BLODispatcher { @@ -61,7 +65,8 @@ export class BLODispatcher { signer: signer, supportedDLTs: this.orchestrator.supportedDLTs, bridgeManager: this.bridgeManager, - orquestrator: this.orchestrator, + orchestrator: this.orchestrator, + pubKey: options.pubKey, }; this.manager = new SATPManager(SATPManagerOpts); @@ -111,8 +116,15 @@ export class BLODispatcher { return ExecuteGetStatus(this.logger, req); } - public async Transact(req: StatusRequest): Promise { - return ExecuteGetStatus(this.logger, req); + public async Transact(req: TransactRequest): Promise { + //TODO pre-verify verify input + const res = await ExecuteTransact( + this.logger, + req, + this.manager, + this.orchestrator, + ); + return res; } // get channel by caller; give needed client from orchestrator to handler to call // for all channels, find session id on request diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/blo/transaction/transact-handler-service.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/blo/transaction/transact-handler-service.ts index 65b3dba385..5b6e7b74d4 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/blo/transaction/transact-handler-service.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/blo/transaction/transact-handler-service.ts @@ -1 +1,115 @@ +import { Logger } from "@hyperledger/cactus-common"; +import { + TransactRequest, + TransactResponse, + Transact200ResponseStatusResponseOriginChain, + StatusResponse, +} from "../../public-api"; +import { SATPManager } from "../../gol/satp-manager"; +import { populateClientSessionData } from "../../core/session-utils"; +import { + CredentialProfile, + LockType, + SignatureAlgorithm, +} from "../../generated/proto/cacti/satp/v02/common/message_pb"; +import { GatewayOrchestrator } from "../../gol/gateway-orchestrator"; +import { GatewayIdentity } from "../../core/types"; +import { SATP_VERSION } from "../../core/constants"; + // todo +export async function ExecuteTransact( + logger: Logger, + req: TransactRequest, + manager: SATPManager, + gol: GatewayOrchestrator, +): Promise { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const fn = "BLO#transact-handler-service#ExecuteTransact"; + + //TODO check input for valid strings... + const ourGateway: GatewayIdentity = gol.ourGateway; + const senderGatewayOwnerId: string = ourGateway.id; + + //This data is set in satpManager GOL + const serverGatewayPubkey: string = ""; + const receiverGatewayOwnerId: string = ""; + + //Default, make it configurable by injecting sign function + const signatureAlgorithm: SignatureAlgorithm = SignatureAlgorithm.ECDSA; + + //Default, TODO + const lockType: LockType = LockType.DESTROYBURN; + //In milliseconds (5min) + const lockExpirationTime: bigint = BigInt(1000 * 60 * 5); + + const credentialProfile: CredentialProfile = CredentialProfile.UNSPECIFIED; + const loggingProfile: string = "MOCK_LOGGING_PROFILE"; + const accessControlProfile: string = "MOCK_ACCESS_CONTROL_PROFILE"; + + //todo verify ontologies signatures, validation, etc. + + let session = manager.getOrCreateSession(undefined, req.contextID); + session = populateClientSessionData( + session, + SATP_VERSION, + req.sourceAsset.contractAddress, + req.destinyAsset.contractAddress, + req.originatorPubkey, + req.beneficiaryPubkey, + req.fromDLTNetworkID, + req.toDLTNetworkID, + manager.pubKey, + serverGatewayPubkey, + receiverGatewayOwnerId, + senderGatewayOwnerId, + signatureAlgorithm, + lockType, + lockExpirationTime, + credentialProfile, + loggingProfile ? loggingProfile : "", + accessControlProfile, + req.sourceAsset.ontology, + req.destinyAsset.ontology, + req.fromAmount, + req.toAmount, + req.sourceAsset.mspId ? req.sourceAsset.mspId : "", + req.sourceAsset.channelName ? req.sourceAsset.channelName : "", + req.destinyAsset.mspId ? req.destinyAsset.mspId : "", + req.destinyAsset.channelName ? req.destinyAsset.channelName : "", + req.sourceAsset.contractName, + req.destinyAsset.contractName, + req.sourceAsset.owner, + req.destinyAsset.owner, + ); + await manager.initiateTransfer(session); + + //mock + const originChain: Transact200ResponseStatusResponseOriginChain = { + dltProtocol: "besu", + dltSubnetworkID: "v24.4.0-RC1", + }; + + const destinationChain: Transact200ResponseStatusResponseOriginChain = { + dltProtocol: "besu", + dltSubnetworkID: "v24.4.0-RC1", + }; + + const mock: StatusResponse = { + status: "DONE", + substatus: "COMPLETED", + stage: "STAGE3", + step: "transfer-complete-message", + startTime: "2023-03-14T16:50:06.662Z", + originChain: originChain, + destinationChain: destinationChain, + }; + + logger.info(req); + // logger.error("GetStatusService not implemented"); + // throw new GetStatusError(req.sessionID, "GetStatusService not implemented"); + + return { + sessionID: session.getSessionId(), + statusResponse: mock, + }; +} diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/constants.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/constants.ts index 9d3773228e..bf18c70f4c 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/constants.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/constants.ts @@ -1,5 +1,4 @@ export const DEFAULT_PORT_GATEWAY_SERVER = 3010; export const DEFAULT_PORT_GATEWAY_CLIENT = DEFAULT_PORT_GATEWAY_SERVER + 1; export const DEFAULT_PORT_GATEWAY_UI = DEFAULT_PORT_GATEWAY_SERVER + 2; -export const DEFAULT_PORT_GATEWAY_GRPC = 4010; export const SATP_VERSION = "v02"; diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/errors/satp-handler-errors.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/errors/satp-handler-errors.ts index 04e2ad1a01..fe37880ffe 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/errors/satp-handler-errors.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/errors/satp-handler-errors.ts @@ -13,13 +13,28 @@ export class SessionIdNotFoundError extends SATPInternalError { } export class FailedToCreateMessageError extends SATPInternalError { - constructor(tag: string, message: string) { - super(`${tag}, failed to create message: ${message}`, 500); + constructor(tag: string, message: string, cause?: Error) { + super( + `${tag}, failed to create message: ${message} \n stack: ${cause}`, + 500, + ); } } export class FailedToProcessError extends SATPInternalError { - constructor(tag: string, message: string) { - super(`${tag}, failed to process: ${message}`, 500); + constructor(tag: string, message: string, cause?: Error) { + super(`${tag}, failed to process: ${message} \n stack: ${cause}`, 500); + } +} + +export class SenderGatewayNetworkIdError extends SATPInternalError { + constructor(tag: string) { + super(`${tag}, senderGatewayNetworkId is empty`, 500); + } +} + +export class PubKeyError extends SATPInternalError { + constructor(tag: string) { + super(`${tag}, pubKey not found`, 500); } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/errors/satp-service-errors.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/errors/satp-service-errors.ts index c5962c983f..548f59f6d7 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/errors/satp-service-errors.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/errors/satp-service-errors.ts @@ -1,168 +1,299 @@ import { SATPInternalError } from "./satp-errors"; export class SatpCommonBodyError extends SATPInternalError { - constructor(fnTag: string, data: string) { + constructor(tag: string, data: string) { super( - `${fnTag}, message satp common body is missing or is missing required fields \n ${data}`, + `${tag}, message satp common body is missing or is missing required fields \n ${data}`, 400, ); } } export class SessionError extends SATPInternalError { - constructor(fnTag: string) { - super(`${fnTag}, session undefined`, 500); + constructor(tag: string) { + super(`${tag}, session undefined`, 500); + } +} + +export class SessionIdError extends SATPInternalError { + constructor(tag: string) { + super(`${tag}, session id undefined`, 500); + } +} + +export class SessionMissMatchError extends SATPInternalError { + constructor(tag: string) { + super(`${tag}, session missmatch`, 500); } } export class SessionDataNotLoadedCorrectlyError extends SATPInternalError { - constructor(fnTag: string, data: string) { - super(`${fnTag}, session data was not loaded correctly \n ${data}`, 500); + constructor(tag: string, data: string, stack?: Error) { + super( + `${tag}, session data was not loaded correctly \n ${data} \n stack: ${stack} `, + 500, + ); + } +} + +export class SessionDataNotAvailableError extends SATPInternalError { + constructor(tag: string, type: string) { + super(`${tag}, ${type} session data not available`, 500); } } export class SessionCompletedError extends SATPInternalError { - constructor(fnTag: string) { - super(`${fnTag}, session data already completed`, 500); + constructor(tag: string) { + super(`${tag}, session data already completed`, 500); } } export class SATPVersionError extends SATPInternalError { - constructor(fnTag: string, unsupported: string, supported: string) { - super( - `${fnTag}, unsupported SATP version \n received: ${unsupported}, supported: ${supported}`, - 400, - ); + constructor(tag: string, unsupported?: string, supported?: string) { + if (!supported) { + super(`${tag}, SATP version is missing`, 400); + } else { + super( + `${tag}, unsupported SATP version \n received: ${unsupported}, supported: ${supported}`, + 400, + ); + } + } +} + +export class SignatureAlgorithmError extends SATPInternalError { + constructor(tag: string) { + super(`${tag}, signature algorithm is missing`, 400); } } export class SignatureVerificationError extends SATPInternalError { - constructor(fnTag: string) { - super(`${fnTag}, message signature verification failed`, 400); + constructor(tag: string) { + super(`${tag}, message signature verification failed`, 400); } } export class SignatureMissingError extends SATPInternalError { - constructor(fnTag: string) { - super(`${fnTag}, message signature missing`, 400); + constructor(tag: string) { + super(`${tag}, message signature missing`, 400); + } +} + +export class LockTypeError extends SATPInternalError { + constructor(tag: string) { + super(`${tag}, lock type missing`, 400); + } +} + +export class lockExpirationTimeError extends SATPInternalError { + constructor(tag: string) { + super(`${tag}, lock expiration time missing`, 400); + } +} + +export class CredentialProfileError extends SATPInternalError { + constructor(tag: string) { + super(`${tag}, credential profile missing`, 400); + } +} + +export class LoggingProfileError extends SATPInternalError { + constructor(tag: string) { + super(`${tag}, logging profile missing`, 400); + } +} + +export class AccessControlProfileError extends SATPInternalError { + constructor(tag: string) { + super(`${tag}, access control profile missing`, 400); } } export class MessageTypeError extends SATPInternalError { - constructor(fnTag: string, received: string, expected: string) { + constructor(tag: string, received: string, expected: string) { super( - `${fnTag}, message type miss match \n received: ${received} \n expected: ${expected}`, + `${tag}, message type miss match \n received: ${received} \n expected: ${expected}`, 400, ); } } export class TransferInitClaimsError extends SATPInternalError { - constructor(fnTag: string) { - super(`${fnTag}, transferInitClaims missing or faulty`, 400); + constructor(tag: string) { + super(`${tag}, transferInitClaims missing or faulty`, 400); } } export class TransferInitClaimsHashError extends SATPInternalError { - constructor(fnTag: string) { - super(`${fnTag}, transferInitClaims hash missing or missmatch`, 400); + constructor(tag: string) { + super(`${tag}, transferInitClaims hash missing or missmatch`, 400); } } export class NetworkCapabilitiesError extends SATPInternalError { - constructor(fnTag: string) { - super(`${fnTag}, NetworkCapabilitiesError missing or faulty`, 400); + constructor(tag: string) { + super(`${tag}, NetworkCapabilitiesError missing or faulty`, 400); } } export class DLTNotSupportedError extends SATPInternalError { - constructor(fnTag: string, dlt: string) { - super(`${fnTag}, DLT not supported \n received: ${dlt}`, 400); + constructor(tag: string, dlt: string) { + super(`${tag}, DLT not supported \n received: ${dlt}`, 400); } } export class ServerGatewayPubkeyError extends SATPInternalError { - constructor(fnTag: string) { - super(`${fnTag}, serverGatewayPubkey missing or missmatch`, 400); + constructor(tag: string) { + super(`${tag}, serverGatewayPubkey missing or missmatch`, 400); } } export class ClientGatewayPubkeyError extends SATPInternalError { - constructor(fnTag: string) { - super(`${fnTag}, clientGatewayPubkey missing or missmatch`, 400); + constructor(tag: string) { + super(`${tag}, clientGatewayPubkey missing or missmatch`, 400); } } export class SequenceNumberError extends SATPInternalError { - constructor(fnTag: string, received: bigint, expected: bigint) { + constructor(tag: string, received: bigint, expected: bigint) { super( - `${fnTag}, sequence number missmatch \n received: ${received} \n expected: ${expected}`, + `${tag}, sequence number missmatch \n received: ${received} \n expected: ${expected}`, 400, ); } } export class HashError extends SATPInternalError { - constructor(fnTag: string, received: string, expected: string) { + constructor(tag: string, received: string, expected: string) { super( - `${fnTag}, hash missmatch \n received: ${received} \n expected: ${expected}`, + `${tag}, hash missmatch \n received: ${received} \n expected: ${expected}`, 400, ); } } export class TransferContextIdError extends SATPInternalError { - constructor(fnTag: string, received: string, expected: string) { - super( - `${fnTag}, transferContextId missing or missmatch \n received: ${received} \n expected: ${expected}`, - 400, - ); + constructor(tag: string, received?: string, expected?: string) { + if (!received || !expected) { + super(`${tag}, transferContextId missing or missmatch`, 400); + } else { + super( + `${tag}, transferContextId missing or missmatch \n received: ${received} \n expected: ${expected}`, + 400, + ); + } } } export class MissingBridgeManagerError extends SATPInternalError { - constructor(fnTag: string) { - super(`${fnTag}, bridge manager missing`, 400); + constructor(tag: string) { + super(`${tag}, bridge manager missing`, 400); } } export class LockAssertionClaimError extends SATPInternalError { - constructor(fnTag: string) { - super(`${fnTag}, lockAssertionClaim missing or faulty`, 400); + constructor(tag: string) { + super(`${tag}, lockAssertionClaim missing or faulty`, 400); } } export class LockAssertionClaimFormatError extends SATPInternalError { - constructor(fnTag: string) { - super(`${fnTag}, lockAssertionClaimFormat missing`, 400); + constructor(tag: string) { + super(`${tag}, lockAssertionClaimFormat missing`, 400); } } export class LockAssertionExpirationError extends SATPInternalError { - constructor(fnTag: string) { - super(`${fnTag}, lockAssertionExpiration missing or faulty`, 400); + constructor(tag: string) { + super(`${tag}, lockAssertionExpiration missing or faulty`, 400); } } export class BurnAssertionClaimError extends SATPInternalError { - constructor(fnTag: string) { - super(`${fnTag}, burnAssertionClaim missing or faulty`, 400); + constructor(tag: string) { + super(`${tag}, burnAssertionClaim missing or faulty`, 400); } } export class MintAssertionClaimError extends SATPInternalError { - constructor(fnTag: string) { - super(`${fnTag}, mintAssertionClaim missing or faulty`, 400); + constructor(tag: string) { + super(`${tag}, mintAssertionClaim missing or faulty`, 400); } } export class AssignmentAssertionClaimError extends SATPInternalError { - constructor(fnTag: string) { - super(`${fnTag}, assignmentAssertionClaim missing or faulty`, 400); + constructor(tag: string) { + super(`${tag}, assignmentAssertionClaim missing or faulty`, 400); } } export class ResourceUrlError extends SATPInternalError { - constructor(fnTag: string) { - super(`${fnTag}, resourceUrl missing or missmatch`, 400); + constructor(tag: string) { + super(`${tag}, resourceUrl missing or missmatch`, 400); + } +} + +export class GatewayNetworkIdError extends SATPInternalError { + constructor(tag: string) { + super(`${tag}, gatewayNetworkId missing or missmatch`, 400); + } +} + +export class OntologyContractError extends SATPInternalError { + constructor(tag: string) { + super(`${tag}, ontologyContract missing or has problems`, 400); + } +} + +export class LedgerAssetIdError extends SATPInternalError { + constructor(tag: string) { + super(`${tag}, ledgerAssetId missing`, 400); + } +} + +export class LedgerAssetError extends SATPInternalError { + constructor(tag: string) { + super(`${tag}, ledgerAsset missing`, 400); + } +} + +export class NetworkIdError extends SATPInternalError { + constructor(tag: string, type: string) { + super(`${tag}, ${type} networkId missing or missmatch`, 400); + } +} + +export class AssetMissing extends SATPInternalError { + constructor(tag: string) { + super(`${tag}, asset missing`, 400); + } +} + +export class WrapAssertionClaimError extends SATPInternalError { + constructor(tag: string) { + super(`${tag}, Wrap Assertion Claim missing or faulty`, 400); + } +} + +export class TokenIdMissingError extends SATPInternalError { + constructor(tag: string) { + super(`${tag}, tokenId missing`, 400); + } +} + +export class MissingRecipientError extends SATPInternalError { + constructor(tag: string) { + super(`${tag}, Recipient is missing`, 400); + } +} + +export class DigitalAssetIdError extends SATPInternalError { + constructor(tag: string) { + super(`${tag}, DigitalAssetId is missing`, 400); + } +} + +export class PubKeyError extends SATPInternalError { + constructor(tag: string) { + super(`${tag}, PubKey is missing`, 400); } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/satp-session.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/satp-session.ts index 432f3c6cdf..0080cd8d67 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/satp-session.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/satp-session.ts @@ -4,6 +4,9 @@ import { MessageStagesSignatures, MessageStagesTimestamps, SessionData, + Stage0Hashes, + Stage0Signatures, + Stage0Timestamps, Stage1Hashes, Stage1Signatures, Stage1Timestamps, @@ -15,12 +18,28 @@ import { Stage3Timestamps, } from "../generated/proto/cacti/satp/v02/common/session_pb"; import { + AccessControlProfileError, + ClientGatewayPubkeyError, + CredentialProfileError, + DigitalAssetIdError, + GatewayNetworkIdError, + lockExpirationTimeError, + LockTypeError, + LoggingProfileError, + PubKeyError, SATPVersionError, + ServerGatewayPubkeyError, SessionCompletedError, SessionDataNotLoadedCorrectlyError, + SessionIdError, + SignatureAlgorithmError, + TransferContextIdError, } from "./errors/satp-service-errors"; import { SATP_VERSION } from "./constants"; -import { LockType } from "../generated/proto/cacti/satp/v02/common/message_pb"; +import { + LockType, + SignatureAlgorithm, +} from "../generated/proto/cacti/satp/v02/common/message_pb"; import { SessionType } from "./session-utils"; // Define interface on protos @@ -44,14 +63,16 @@ export class SATPSession { if (ops.server) { this.serverSessionData = new SessionData(); this.serverSessionData.transferContextId = ops.contextID; - this.serverSessionData.id = this.generateSessionID(ops.contextID); + this.serverSessionData.id = + ops.sessionID || this.generateSessionID(ops.contextID); this.initialize(this.serverSessionData); } if (ops.client) { this.clientSessionData = new SessionData(); this.clientSessionData.transferContextId = ops.contextID; - this.clientSessionData.id = this.generateSessionID(ops.contextID); + this.clientSessionData.id = + ops.sessionID || this.generateSessionID(ops.contextID); this.initialize(this.clientSessionData); } } @@ -66,18 +87,22 @@ export class SATPSession { sessionData.processedTimestamps = new MessageStagesTimestamps(); sessionData.receivedTimestamps = new MessageStagesTimestamps(); + sessionData.processedTimestamps.stage0 = new Stage0Timestamps(); sessionData.processedTimestamps.stage1 = new Stage1Timestamps(); sessionData.processedTimestamps.stage2 = new Stage2Timestamps(); sessionData.processedTimestamps.stage3 = new Stage3Timestamps(); + sessionData.receivedTimestamps.stage0 = new Stage0Timestamps(); sessionData.receivedTimestamps.stage1 = new Stage1Timestamps(); sessionData.receivedTimestamps.stage2 = new Stage2Timestamps(); sessionData.receivedTimestamps.stage3 = new Stage3Timestamps(); + sessionData.hashes.stage0 = new Stage0Hashes(); sessionData.hashes.stage1 = new Stage1Hashes(); sessionData.hashes.stage2 = new Stage2Hashes(); sessionData.hashes.stage3 = new Stage3Hashes(); + sessionData.signatures.stage0 = new Stage0Signatures(); sessionData.signatures.stage1 = new Stage1Signatures(); sessionData.signatures.stage2 = new Stage2Signatures(); sessionData.signatures.stage3 = new Stage3Signatures(); @@ -101,6 +126,44 @@ export class SATPSession { return this.clientSessionData; } + public createSessionData( + type: SessionType, + sessionId: string, + contextId: string, + ): void { + if (type == SessionType.SERVER) { + if (this.serverSessionData !== undefined) { + throw new Error( + `${SATPSession.CLASS_NAME}#createSessionData(), serverSessionData already defined`, + ); + } + } else if (type == SessionType.CLIENT) { + if (this.clientSessionData !== undefined) { + throw new Error( + `${SATPSession.CLASS_NAME}#createSessionData(), clientSessionData already defined`, + ); + } + } else { + throw new Error( + `${SATPSession.CLASS_NAME}#createSessionData(), sessionData type is not valid`, + ); + } + + const sessionData = new SessionData(); + sessionData.transferContextId = contextId; + sessionData.id = sessionId; + this.initialize(sessionData); + + switch (type) { + case SessionType.SERVER: + this.serverSessionData = sessionData; + break; + case SessionType.CLIENT: + this.clientSessionData = sessionData; + break; + } + } + public hasServerSessionData(): boolean { return this.serverSessionData !== undefined; } @@ -110,60 +173,103 @@ export class SATPSession { } public getSessionId(): string { + console.log("serverSessionId: ", this.serverSessionData?.id); + console.log("clientSessionId: ", this.clientSessionData?.id); return this.serverSessionData?.id || this.clientSessionData?.id || ""; } public verify(tag: string, type: SessionType): void { let sessionData: SessionData | undefined; - if (type == SessionType.SERVER) { - sessionData = this.getServerSessionData(); - } else if (type == SessionType.CLIENT) { - sessionData = this.getClientSessionData(); - } else { - throw new Error( - `${SATPSession.CLASS_NAME}#verify(), sessionData type is not valid`, - ); - } + try { + if (type == SessionType.SERVER) { + sessionData = this.getServerSessionData(); + } else if (type == SessionType.CLIENT) { + sessionData = this.getClientSessionData(); + } else { + throw new Error( + `${SATPSession.CLASS_NAME}#verify(), sessionData type is not valid`, + ); + } - if (sessionData == undefined) { - throw new SessionDataNotLoadedCorrectlyError(tag, "undefined"); - } + if (sessionData == undefined) { + throw new SessionDataNotLoadedCorrectlyError(tag, "undefined"); + } - if (sessionData.completed) { - throw new SessionCompletedError("Session already completed"); - } - - if ( - sessionData.version == "" || - sessionData.id == "" || - sessionData.digitalAssetId == "" || - sessionData.originatorPubkey == "" || - sessionData.beneficiaryPubkey == "" || - sessionData.senderGatewayNetworkId == "" || - sessionData.recipientGatewayNetworkId == "" || - sessionData.clientGatewayPubkey == "" || - sessionData.serverGatewayPubkey == "" || - sessionData.senderGatewayOwnerId == "" || - sessionData.receiverGatewayOwnerId == "" || - // sessionData.maxRetries == undefined || - // sessionData.maxTimeout == undefined || - sessionData.senderGatewayNetworkId == "" || - sessionData.signatureAlgorithm == undefined || - sessionData.lockType == LockType.UNSPECIFIED || - sessionData.lockExpirationTime == BigInt(0) || - sessionData.credentialProfile == undefined || - sessionData.loggingProfile == "" || - sessionData.accessControlProfile == "" || - // sessionData.lastSequenceNumber == BigInt(0) || - sessionData.transferContextId == "" - ) { + if (sessionData.completed) { + throw new SessionCompletedError("Session already completed"); + } + if (sessionData.id == "") { + throw new SessionIdError(tag); + } + if (sessionData.digitalAssetId == "") { + throw new DigitalAssetIdError(tag); + } + if (sessionData.originatorPubkey == "") { + throw new PubKeyError(tag); + } + if (sessionData.beneficiaryPubkey == "") { + throw new PubKeyError(tag); + } + if (sessionData.senderGatewayNetworkId == "") { + throw new GatewayNetworkIdError(tag); + } + if (sessionData.recipientGatewayNetworkId == "") { + throw new GatewayNetworkIdError(tag); + } + if (sessionData.clientGatewayPubkey == "") { + throw new ClientGatewayPubkeyError(tag); + } + if (sessionData.serverGatewayPubkey == "") { + throw new ServerGatewayPubkeyError(tag); + } + if (sessionData.senderGatewayOwnerId == "") { + throw new GatewayNetworkIdError(tag); + } + if (sessionData.receiverGatewayOwnerId == "") { + throw new GatewayNetworkIdError(tag); + } + if (sessionData.signatureAlgorithm == SignatureAlgorithm.UNSPECIFIED) { + throw new SignatureAlgorithmError(tag); + } + if (sessionData.lockType == LockType.UNSPECIFIED) { + throw new LockTypeError(tag); + } + if (sessionData.lockExpirationTime == BigInt(0)) { + throw new lockExpirationTimeError(tag); + } + if (sessionData.credentialProfile == undefined) { + throw new CredentialProfileError(tag); + } + if (sessionData.loggingProfile == "") { + throw new LoggingProfileError(tag); + } + if (sessionData.accessControlProfile == "") { + throw new AccessControlProfileError(tag); + } + if (sessionData.transferContextId == "") { + throw new TransferContextIdError(tag); + } + if ( + // sessionData.maxRetries == undefined || + // sessionData.maxTimeout == undefined || + // sessionData.lastSequenceNumber == BigInt(0) || + false + ) { + throw new SessionDataNotLoadedCorrectlyError( + tag, + JSON.stringify(sessionData), + ); + } + if (sessionData.version != SATP_VERSION) { + throw new SATPVersionError(tag, sessionData.version, SATP_VERSION); + } + } catch (error) { + console.error(`${tag}, error: ${error}`); throw new SessionDataNotLoadedCorrectlyError( tag, JSON.stringify(sessionData), + error, ); } - if (sessionData.version != SATP_VERSION) { - throw new SATPVersionError(tag, sessionData.version, SATP_VERSION); - } } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/session-utils.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/session-utils.ts index c0065f88c6..a799f9e730 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/session-utils.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/session-utils.ts @@ -1,25 +1,17 @@ import { + Asset, CredentialProfile, LockType, MessageType, SignatureAlgorithm, } from "../generated/proto/cacti/satp/v02/common/message_pb"; import { - MessageStagesHashes, - MessageStagesSignatures, MessageStagesTimestamps, SessionData, - Stage1Hashes, - Stage1Signatures, - Stage1Timestamps, - Stage2Hashes, - Stage2Signatures, - Stage2Timestamps, - Stage3Hashes, - Stage3Signatures, - Stage3Timestamps, } from "../generated/proto/cacti/satp/v02/common/session_pb"; +import { SATPSession } from "./satp-session"; +import { v4 as uuidv4 } from "uuid"; export enum TimestampType { PROCESSED = "PROCESSED", RECEIVED = "RECEIVED", @@ -30,10 +22,11 @@ export enum SessionType { CLIENT = "CLIENT", } -export function createSessionData( - id: string, +export function populateClientSessionData( + session: SATPSession, version: string, - digitalAssetId: string, + sourceContractAddress: string | undefined, + destinyContractAddress: string | undefined, originatorPubkey: string, beneficiaryPubkey: string, senderGatewayNetworkId: string, @@ -48,32 +41,26 @@ export function createSessionData( credentialProfile: CredentialProfile, loggingProfile: string, accessControlProfile: string, -): SessionData { - const sessionData = new SessionData(); - sessionData.processedTimestamps = new MessageStagesTimestamps(); - sessionData.receivedTimestamps = new MessageStagesTimestamps(); - sessionData.hashes = new MessageStagesHashes(); - sessionData.signatures = new MessageStagesSignatures(); - - sessionData.processedTimestamps.stage1 = new Stage1Timestamps(); - sessionData.processedTimestamps.stage2 = new Stage2Timestamps(); - sessionData.processedTimestamps.stage3 = new Stage3Timestamps(); - - sessionData.receivedTimestamps.stage1 = new Stage1Timestamps(); - sessionData.receivedTimestamps.stage2 = new Stage2Timestamps(); - sessionData.receivedTimestamps.stage3 = new Stage3Timestamps(); - - sessionData.hashes.stage1 = new Stage1Hashes(); - sessionData.hashes.stage2 = new Stage2Hashes(); - sessionData.hashes.stage3 = new Stage3Hashes(); - - sessionData.signatures.stage1 = new Stage1Signatures(); - sessionData.signatures.stage2 = new Stage2Signatures(); - sessionData.signatures.stage3 = new Stage3Signatures(); - - sessionData.id = id; + senderContractOntology: string, + receiverContractOntology: string, + fromAmount: string, + toAmount: string, + sourceMspId: string, + sourceChannelName: string, + destinyMspId: string, + destinyChannelName: string, + sourceContractName: string, + destinyContractName: string, + sourceOwner: string, + destinyOwner: string, +): SATPSession { + const fn = "session_utils#populateClientSessionData"; + const sessionData = session.getClientSessionData(); + if (!sessionData) { + throw new Error(fn + ":Session Data is undefined"); + } sessionData.version = version; - sessionData.digitalAssetId = digitalAssetId; + sessionData.digitalAssetId = uuidv4(); sessionData.originatorPubkey = originatorPubkey; sessionData.beneficiaryPubkey = beneficiaryPubkey; sessionData.senderGatewayNetworkId = senderGatewayNetworkId; @@ -88,9 +75,135 @@ export function createSessionData( sessionData.credentialProfile = credentialProfile; sessionData.loggingProfile = loggingProfile; sessionData.accessControlProfile = accessControlProfile; + sessionData.senderContractOntology = senderContractOntology; + sessionData.receiverContractOntology = receiverContractOntology; + const senderAsset: Asset = new Asset(); + senderAsset.tokenId = uuidv4() + "-" + sessionData.transferContextId; + senderAsset.owner = sourceOwner; + senderAsset.ontology = senderContractOntology; + senderAsset.contractName = sourceContractName; + senderAsset.contractAddress = sourceContractAddress || ""; + senderAsset.amount = BigInt(fromAmount); + + senderAsset.mspId = sourceMspId; + senderAsset.channelName = sourceChannelName; + sessionData.senderAsset = senderAsset; + + const receiverAsset: Asset = new Asset(); + receiverAsset.tokenId = ""; + receiverAsset.owner = destinyOwner; + receiverAsset.ontology = receiverContractOntology; + receiverAsset.contractName = destinyContractName; + receiverAsset.contractAddress = destinyContractAddress || ""; + receiverAsset.amount = BigInt(toAmount); + + receiverAsset.mspId = destinyMspId; + receiverAsset.channelName = destinyChannelName; + sessionData.receiverAsset = receiverAsset; + + //todo check THis + + sessionData.resourceUrl = "MOCK_RESOURCE_URL"; + + return session; +} - return sessionData; +export function copySessionDataAttributes( + srcSessionData: SessionData, + destSessionData: SessionData, + sessionId?: string, + contextId?: string, +): void { + destSessionData.id = sessionId || srcSessionData.id; + destSessionData.version = srcSessionData.version; + destSessionData.transferContextId = + contextId || srcSessionData.transferContextId; + destSessionData.hashes = srcSessionData.hashes; + destSessionData.payloadProfile = srcSessionData.payloadProfile; + destSessionData.signatures = srcSessionData.signatures; + destSessionData.maxRetries = srcSessionData.maxRetries; + destSessionData.maxTimeout = srcSessionData.maxTimeout; + destSessionData.loggingProfile = srcSessionData.loggingProfile; + destSessionData.recipientBasePath = srcSessionData.recipientBasePath; + destSessionData.sourceBasePath = srcSessionData.sourceBasePath; + destSessionData.accessControlProfile = srcSessionData.accessControlProfile; + destSessionData.applicationProfile = srcSessionData.applicationProfile; + destSessionData.lastSequenceNumber = srcSessionData.lastSequenceNumber; + destSessionData.senderGatewayNetworkId = + srcSessionData.senderGatewayNetworkId; + destSessionData.recipientGatewayNetworkId = + srcSessionData.recipientGatewayNetworkId; + destSessionData.sourceLedgerAssetId = srcSessionData.sourceLedgerAssetId; + destSessionData.recipientLedgerAssetId = + srcSessionData.recipientLedgerAssetId; + destSessionData.serverGatewayPubkey = srcSessionData.serverGatewayPubkey; + destSessionData.clientGatewayPubkey = srcSessionData.clientGatewayPubkey; + destSessionData.verifiedOriginatorEntityId = + srcSessionData.verifiedOriginatorEntityId; + destSessionData.verifiedBeneficiaryEntityId = + srcSessionData.verifiedBeneficiaryEntityId; + destSessionData.assetProfileId = srcSessionData.assetProfileId; + destSessionData.digitalAssetId = srcSessionData.digitalAssetId; + destSessionData.originatorPubkey = srcSessionData.originatorPubkey; + destSessionData.beneficiaryPubkey = srcSessionData.beneficiaryPubkey; + destSessionData.senderGatewayOwnerId = srcSessionData.senderGatewayOwnerId; + destSessionData.receiverGatewayOwnerId = + srcSessionData.receiverGatewayOwnerId; + destSessionData.hashTransferInitClaims = + srcSessionData.hashTransferInitClaims; + destSessionData.transferInitClaims = srcSessionData.transferInitClaims; + destSessionData.proposedTransferInitClaims = + srcSessionData.proposedTransferInitClaims; + destSessionData.signatureAlgorithm = srcSessionData.signatureAlgorithm; + destSessionData.lockType = srcSessionData.lockType; + destSessionData.lockExpirationTime = srcSessionData.lockExpirationTime; + destSessionData.permissions = srcSessionData.permissions; + destSessionData.developerUrn = srcSessionData.developerUrn; + destSessionData.credentialProfile = srcSessionData.credentialProfile; + destSessionData.subsequentCalls = srcSessionData.subsequentCalls; + destSessionData.history = srcSessionData.history; + destSessionData.multipleClaimsAllowed = srcSessionData.multipleClaimsAllowed; + destSessionData.multipleCancelsAllowed = + srcSessionData.multipleCancelsAllowed; + destSessionData.lastMessageReceivedTimestamp = + srcSessionData.lastMessageReceivedTimestamp; + destSessionData.processedTimestamps = srcSessionData.processedTimestamps; + destSessionData.receivedTimestamps = srcSessionData.receivedTimestamps; + destSessionData.lockAssertionClaim = srcSessionData.lockAssertionClaim; + destSessionData.lockAssertionClaimFormat = + srcSessionData.lockAssertionClaimFormat; + destSessionData.mintAssertionClaim = srcSessionData.mintAssertionClaim; + destSessionData.mintAssertionClaimFormat = + srcSessionData.mintAssertionClaimFormat; + destSessionData.burnAssertionClaim = srcSessionData.burnAssertionClaim; + destSessionData.burnAssertionClaimFormat = + srcSessionData.burnAssertionClaimFormat; + destSessionData.assignmentAssertionClaim = + srcSessionData.assignmentAssertionClaim; + destSessionData.assignmentAssertionClaimFormat = + srcSessionData.assignmentAssertionClaimFormat; + destSessionData.completed = srcSessionData.completed; + destSessionData.acceptance = srcSessionData.acceptance; + destSessionData.lastMessageHash = srcSessionData.lastMessageHash; + destSessionData.transferClaimsFormat = srcSessionData.transferClaimsFormat; + destSessionData.clientTransferNumber = srcSessionData.clientTransferNumber; + destSessionData.serverTransferNumber = srcSessionData.serverTransferNumber; + destSessionData.lockAssertionExpiration = + srcSessionData.lockAssertionExpiration; + destSessionData.assetProfile = srcSessionData.assetProfile; + destSessionData.senderContractOntology = + srcSessionData.senderContractOntology; + destSessionData.receiverContractOntology = + srcSessionData.receiverContractOntology; + destSessionData.resourceUrl = srcSessionData.resourceUrl; + destSessionData.senderWrapAssertionClaim = + srcSessionData.senderWrapAssertionClaim; + destSessionData.receiverWrapAssertionClaim = + srcSessionData.receiverWrapAssertionClaim; + destSessionData.senderAsset = srcSessionData.senderAsset; + destSessionData.receiverAsset = srcSessionData.receiverAsset; } + export function saveTimestamp( session: SessionData | undefined, stageMessage: MessageType, @@ -123,6 +236,7 @@ export function saveTimestamp( if ( timestamps == undefined || + timestamps.stage0 == undefined || timestamps.stage1 == undefined || timestamps.stage2 == undefined || timestamps.stage3 == undefined @@ -131,6 +245,18 @@ export function saveTimestamp( } switch (stageMessage) { + case MessageType.NEW_SESSION_REQUEST: + timestamps.stage0.newSessionRequestMessageTimestamp = timestamp; + break; + case MessageType.NEW_SESSION_RESPONSE: + timestamps.stage0.newSessionResponseMessageTimestamp = timestamp; + break; + case MessageType.PRE_SATP_TRANSFER_REQUEST: + timestamps.stage0.preSatpTransferRequestMessageTimestamp = timestamp; + break; + case MessageType.PRE_SATP_TRANSFER_RESPONSE: + timestamps.stage0.preSatpTransferResponseMessageTimestamp = timestamp; + break; case MessageType.INIT_PROPOSAL: timestamps.stage1.transferProposalRequestMessageTimestamp = timestamp; break; @@ -184,6 +310,7 @@ export function saveHash( if ( hashes == undefined || + hashes.stage0 == undefined || hashes.stage1 == undefined || hashes.stage2 == undefined || hashes.stage3 == undefined @@ -192,6 +319,18 @@ export function saveHash( } switch (stageMessage) { + case MessageType.NEW_SESSION_REQUEST: + hashes.stage0.newSessionRequestMessageHash = hash; + break; + case MessageType.NEW_SESSION_RESPONSE: + hashes.stage0.newSessionResponseMessageHash = hash; + break; + case MessageType.PRE_SATP_TRANSFER_REQUEST: + hashes.stage0.preSatpTransferRequestMessageHash = hash; + break; + case MessageType.PRE_SATP_TRANSFER_RESPONSE: + hashes.stage0.preSatpTransferResponseMessageHash = hash; + break; case MessageType.INIT_PROPOSAL: hashes.stage1.transferProposalRequestMessageHash = hash; break; @@ -244,6 +383,7 @@ export function saveSignature( if ( signatures == undefined || + signatures.stage0 == undefined || signatures.stage1 == undefined || signatures.stage2 == undefined || signatures.stage3 == undefined @@ -252,6 +392,18 @@ export function saveSignature( } switch (stageMessage) { + case MessageType.NEW_SESSION_REQUEST: + signatures.stage0.newSessionRequestMessageSignature = signature; + break; + case MessageType.NEW_SESSION_RESPONSE: + signatures.stage0.newSessionResponseMessageSignature = signature; + break; + case MessageType.PRE_SATP_TRANSFER_REQUEST: + signatures.stage0.preSatpTransferRequestMessageSignature = signature; + break; + case MessageType.PRE_SATP_TRANSFER_RESPONSE: + signatures.stage0.preSatpTransferResponseMessageSignature = signature; + break; case MessageType.INIT_PROPOSAL: signatures.stage1.transferProposalRequestMessageSignature = signature; break; @@ -343,6 +495,7 @@ export function getMessageHash( if ( sessionData.hashes == undefined || + sessionData.hashes.stage0 == undefined || sessionData.hashes.stage1 == undefined || sessionData.hashes.stage2 == undefined || sessionData.hashes.stage3 == undefined @@ -351,6 +504,14 @@ export function getMessageHash( } switch (messageType) { + case MessageType.NEW_SESSION_REQUEST: + return sessionData.hashes.stage0.newSessionRequestMessageHash; + case MessageType.NEW_SESSION_RESPONSE: + return sessionData.hashes.stage0.newSessionResponseMessageHash; + case MessageType.PRE_SATP_TRANSFER_REQUEST: + return sessionData.hashes.stage0.preSatpTransferRequestMessageHash; + case MessageType.PRE_SATP_TRANSFER_RESPONSE: + return sessionData.hashes.stage0.preSatpTransferResponseMessageHash; case MessageType.INIT_PROPOSAL: return sessionData.hashes.stage1.transferProposalRequestMessageHash; case MessageType.INIT_RECEIPT: @@ -403,6 +564,7 @@ export function getMessageTimestamp( if ( timestamps == undefined || + timestamps.stage0 == undefined || timestamps.stage1 == undefined || timestamps.stage2 == undefined || timestamps.stage3 == undefined @@ -411,6 +573,14 @@ export function getMessageTimestamp( } switch (stageMessage) { + case MessageType.NEW_SESSION_REQUEST: + return timestamps.stage0.newSessionRequestMessageTimestamp; + case MessageType.NEW_SESSION_RESPONSE: + return timestamps.stage0.newSessionResponseMessageTimestamp; + case MessageType.PRE_SATP_TRANSFER_REQUEST: + return timestamps.stage0.preSatpTransferRequestMessageTimestamp; + case MessageType.PRE_SATP_TRANSFER_RESPONSE: + return timestamps.stage0.preSatpTransferResponseMessageTimestamp; case MessageType.INIT_PROPOSAL: return timestamps.stage1.transferProposalRequestMessageTimestamp; case MessageType.INIT_RECEIPT: diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage0-handler.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage0-handler.ts index 93f29c04bc..4e024836e9 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage0-handler.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage0-handler.ts @@ -5,29 +5,42 @@ import { SATPHandler, SATPHandlerOptions, SATPHandlerType, + Stage, } from "../../types/satp-protocol"; -import { ConnectRouter } from "@connectrpc/connect"; +import { ConnectRouter, HandlerContext } from "@connectrpc/connect"; import { SatpStage0Service } from "../../generated/proto/cacti/satp/v02/stage_0_connect"; import { - PreTransferCommenceRequestMessage, - PreTransferCommenceResponseMessage, - PreTransferVerificationAndContextEstablishmentRequest, - PreTransferVerificationAndContextEstablishmentResponse, + CheckRequest, + CheckResponse, + NewSessionRequest, + NewSessionResponse, + PreSATPTransferRequest, + PreSATPTransferResponse, } from "../../generated/proto/cacti/satp/v02/stage_0_pb"; import { Stage0ClientService } from "../stage-services/client/stage0-client-service"; - +import { + FailedToCreateMessageError, + FailedToProcessError, + PubKeyError, + SenderGatewayNetworkIdError, + SessionNotFoundError, +} from "../errors/satp-handler-errors"; export class Stage0SATPHandler implements SATPHandler { public static readonly CLASS_NAME = SATPHandlerType.STAGE0; private sessions: Map; private serverService: Stage0ServerService; private clientService: Stage0ClientService; private logger: Logger; + private pubKeys: Map; + private gatewayId: string; constructor(ops: SATPHandlerOptions) { this.sessions = ops.sessions; this.serverService = ops.serverService as Stage0ServerService; this.clientService = ops.clientService as Stage0ClientService; this.logger = LoggerProvider.getOrCreate(ops.loggerOptions); this.logger.trace(`Initialized ${Stage0SATPHandler.CLASS_NAME}`); + this.pubKeys = ops.pubkeys; + this.gatewayId = ops.gatewayId; } getHandlerSessions(): string[] { return Array.from(this.sessions.keys()); @@ -37,58 +50,179 @@ export class Stage0SATPHandler implements SATPHandler { return Stage0SATPHandler.CLASS_NAME; } - // async PreTransferProposalImplementation( - // req: PreTransferVerificationAndContextEstablishmentRequest, - // ): Promise { - // try { - // console.log("Received TransferProposalRequest", req); - // const sessionData = - // await this.serverService.checkPreTransferProposalRequestMessage( - // req, - // this.session, - // ); - // const message = await this.serverService.preTransferProposalResponse( - // req, - // this.session, - // ); - // console.log("message", message); - // console.log("Returning response", sessionData); - // const response = - // new PreTransferVerificationAndContextEstablishmentResponse(); - // return response; - // } catch (error) { - // console.error("Error handling TransferProposalRequest:", error); - // throw new Error("Failed to process TransferProposalRequest"); - // } - // } - - // async PreTransferCommenceImplementation( - // req: PreTransferCommenceRequestMessage, - // ): Promise { - // try { - // console.log("Received TransferCommenceRequest", req); - // const sessionData = - // await this.serverService.checkTransferCommenceRequestMessage( - // req, - // this.session, - // ); - // const message = await this.serverService.transferCommenceResponse( - // req, - // this.session, - // ); - // console.log("Returning response", message); - // console.log("Returning response", sessionData); - // const response = new PreTransferCommenceResponseMessage(); - // return response; - // } catch (error) { - // console.error("Error handling TransferCommenceRequest:", error); - // throw new Error("Failed to process TransferCommenceRequest"); - // } - // } + getStage(): string { + return Stage.STAGE0; + } + + public get Log(): Logger { + return this.logger; + } + + private async NewSessionImplementation( + req: NewSessionRequest, + context: HandlerContext, + ): Promise { + const stepTag = `NewSessionImplementation()`; + const fnTag = `${this.getHandlerIdentifier()}#${stepTag}`; + try { + this.Log.debug(`${fnTag}, New Session...`); + this.Log.debug(`${fnTag}, Request: ${req}, Context: ${context}`); + + let session = this.sessions.get(req.sessionId); + + if (req.gatewayId == "") { + throw new SenderGatewayNetworkIdError(fnTag); + } + + if (!this.pubKeys.has(req.gatewayId)) { + throw new PubKeyError(fnTag); + } + + session = await this.serverService.checkNewSessionRequest( + req, + session, + this.pubKeys.get(req.gatewayId)!, + ); + + this.sessions.set(session.getSessionId(), session); + + const message = await this.serverService.newSessionResponse(req, session); + + if (!message) { + throw new FailedToCreateMessageError(fnTag, "NewSessionResponse"); + } + + this.Log.debug(`${fnTag}, Returning response: ${message}`); + + return message; + } catch (error) { + throw new FailedToCreateMessageError(fnTag, "NewSessionResponse", error); + } + } + + private async PreSATPTransferImplementation( + req: PreSATPTransferRequest, + context: HandlerContext, + ): Promise { + const stepTag = `PreSATPTransferImplementation()`; + const fnTag = `${this.getHandlerIdentifier()}#${stepTag}`; + try { + this.Log.debug(`${fnTag}, PreSATPTransfer...`); + this.Log.debug(`${fnTag}, Request: ${req}, Context: ${context}`); + + const session = this.sessions.get(req.sessionId); + + if (!session) { + throw new SessionNotFoundError(fnTag); + } + + await this.serverService.checkPreSATPTransferRequest(req, session); + + await this.serverService.wrapToken(session); + + const message = await this.serverService.preSATPTransferResponse( + req, + session, + ); + + if (!message) { + throw new FailedToCreateMessageError(fnTag, "PreSATPTransferResponse"); + } + + this.Log.debug(`${fnTag}, Returning response: ${message}`); + + return message; + } catch (error) { + throw new FailedToCreateMessageError(fnTag, "NewSessionResponse", error); + } + } + setupRouter(router: ConnectRouter): void { - // router.service(SatpStage0Service, { - // preTransferProposalClaims: this.PreTransferProposalImplementation, - // preTransferCommence: this.PreTransferCommenceImplementation, - // }); + // eslint-disable-next-line @typescript-eslint/no-this-alias + const that = this; + router.service(SatpStage0Service, { + async check(req: CheckRequest): Promise { + return new CheckResponse({ check: req.check }); + }, + async newSession(req, context): Promise { + return await that.NewSessionImplementation(req, context); + }, + async preSATPTransfer(req, context): Promise { + return await that.PreSATPTransferImplementation(req, context); + }, + // newSession: this.NewSessionImplementation, + //preSATPTransfer: this.PreSATPTransferImplementation, + }); + } + + //client side + + public async NewSessionRequest( + sessionId: string, + ): Promise { + const stepTag = `NewSessionRequest()`; + const fnTag = `${this.getHandlerIdentifier()}#${stepTag}`; + try { + this.Log.debug(`${fnTag}, New Session Request...`); + + const session = this.sessions.get(sessionId); + + if (!session) { + throw new SessionNotFoundError(fnTag); + } + + const message = await this.clientService.newSessionRequest( + session, + this.gatewayId, + ); + + if (!message) { + throw new FailedToCreateMessageError(fnTag, "NewSessionRequest"); + } + + return message; + } catch (error) { + throw new FailedToProcessError(fnTag, "NewSessionRequest", error); + } + } + + public async PreSATPTransferRequest( + response: NewSessionResponse, + sessionId: string, + ): Promise { + const stepTag = `PreSATPTransferRequest()`; + const fnTag = `${this.getHandlerIdentifier()}#${stepTag}`; + try { + this.Log.debug(`${fnTag}, Pre SATP Transfer Request...`); + + const session = this.sessions.get(sessionId); + + if (!session) { + throw new SessionNotFoundError(fnTag); + } + + const newSession = await this.clientService.checkNewSessionResponse( + response, + session, + Array.from(this.sessions.keys()), + ); + + if (newSession.getSessionId() != session.getSessionId()) { + this.sessions.set(newSession.getSessionId(), newSession); + this.sessions.delete(session.getSessionId()); + } + + await this.clientService.wrapToken(session); + + const message = await this.clientService.preSATPTransferRequest(session); + + if (!message) { + throw new FailedToCreateMessageError(fnTag, "PreSATPTransferRequest"); + } + + return message; + } catch (error) { + throw new FailedToProcessError(fnTag, "PreSATPTransferRequest", error); + } } } 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 fe3529803f..6dec68a438 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 @@ -14,6 +14,7 @@ import { SATPHandler, SATPHandlerOptions, SATPHandlerType, + Stage, } from "../../types/satp-protocol"; import { Logger, LoggerProvider } from "@hyperledger/cactus-common"; import { @@ -22,6 +23,7 @@ import { SessionNotFoundError, } from "../errors/satp-handler-errors"; import { getSessionId } from "./handler-utils"; +import { PreSATPTransferResponse } from "../../generated/proto/cacti/satp/v02/stage_0_pb"; export class Stage1SATPHandler implements SATPHandler { public static readonly CLASS_NAME = SATPHandlerType.STAGE1; @@ -47,6 +49,9 @@ export class Stage1SATPHandler implements SATPHandler { getHandlerSessions(): string[] { return Array.from(this.sessions.keys()); } + getStage(): string { + return Stage.STAGE1; + } public get Log(): Logger { return this.logger; @@ -78,14 +83,16 @@ export class Stage1SATPHandler implements SATPHandler { session, ); - this.Log.debug(`${fnTag}, Returning response: ${message}`); + this.Log.debug( + `${fnTag}, Returning response: ${JSON.stringify(message)}`, + ); if (!message) { throw new FailedToCreateMessageError(fnTag, "TransferProposalReceipt"); } return message; } catch (error) { - throw new FailedToProcessError(fnTag, "TransferProposalRequest"); + throw new FailedToProcessError(fnTag, "TransferProposalRequest", error); } } @@ -112,27 +119,39 @@ export class Stage1SATPHandler implements SATPHandler { req, session, ); - this.Log.debug(`${fnTag}, Returning response: ${message}`); + + this.Log.debug( + `${fnTag}, Returning response: ${JSON.stringify(message)}`, + ); if (!message) { throw new FailedToCreateMessageError(fnTag, "TransferCommenceResponse"); } return message; } catch (error) { - throw new FailedToProcessError(fnTag, "TransferCommenceResponse"); + throw new FailedToProcessError(fnTag, "TransferCommenceResponse", error); } } setupRouter(router: ConnectRouter): void { + // eslint-disable-next-line @typescript-eslint/no-this-alias + const that = this; router.service(SatpStage1Service, { - transferProposal: this.TransferProposalImplementation, - transferCommence: this.TransferCommenceImplementation, + async transferProposal(req, context) { + return await that.TransferProposalImplementation(req, context)!; + }, + async transferCommence(req, context) { + return that.TransferCommenceImplementation(req, context); + }, + // transferProposal: this.TransferProposalImplementation, + // transferCommence: this.TransferCommenceImplementation, }); } //client side public async TransferProposalRequest( sessionId: string, + response: PreSATPTransferResponse, ): Promise { const stepTag = `TransferProposalRequest()`; const fnTag = `${this.getHandlerIdentifier()}#${stepTag}`; @@ -144,6 +163,8 @@ export class Stage1SATPHandler implements SATPHandler { throw new Error(`${fnTag}, Session not found`); } + await this.clientService.checkPreSATPTransferResponse(response, session); + const requestTransferProposal = await this.clientService.transferProposalRequest( session, @@ -155,7 +176,7 @@ export class Stage1SATPHandler implements SATPHandler { } return requestTransferProposal; } catch (error) { - throw new FailedToProcessError(fnTag, "TransferProposalRequest"); + throw new FailedToProcessError(fnTag, "TransferProposalRequest", error); } } @@ -192,7 +213,7 @@ export class Stage1SATPHandler implements SATPHandler { return requestTransferCommence; } catch (error) { - throw new FailedToProcessError(fnTag, "TransferCommenceRequest"); + throw new FailedToProcessError(fnTag, "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 aa5cd93b49..cdff4b874f 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 @@ -7,6 +7,7 @@ import { SATPHandler, SATPHandlerOptions, SATPHandlerType, + Stage, } from "../../types/satp-protocol"; import { Logger, LoggerProvider } from "@hyperledger/cactus-common"; import { @@ -50,6 +51,10 @@ export class Stage2SATPHandler implements SATPHandler { return Array.from(this.sessions.keys()); } + getStage(): string { + return Stage.STAGE2; + } + async LockAssertionImplementation( req: LockAssertionRequestMessage, context: HandlerContext, @@ -82,13 +87,22 @@ export class Stage2SATPHandler implements SATPHandler { } return message; } catch (error) { - throw new FailedToProcessError(fnTag, "LockAssertionImplementation"); + throw new FailedToProcessError( + fnTag, + "LockAssertionImplementation", + error, + ); } } setupRouter(router: ConnectRouter): void { + // eslint-disable-next-line @typescript-eslint/no-this-alias + const that = this; router.service(SatpStage2Service, { - lockAssertion: this.LockAssertionImplementation, + async lockAssertion(req, context) { + return await that.LockAssertionImplementation(req, context); + }, + //lockAssertion: this.LockAssertionImplementation, }); } @@ -124,7 +138,7 @@ export class Stage2SATPHandler implements SATPHandler { } return request; } catch (error) { - throw new FailedToProcessError(fnTag, "LockAssertionRequest"); + throw new FailedToProcessError(fnTag, "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 1290d632b6..571f3a403c 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 @@ -14,6 +14,7 @@ import { SATPHandler, SATPHandlerOptions, SATPHandlerType, + Stage, } from "../../types/satp-protocol"; import { Logger, LoggerProvider } from "@hyperledger/cactus-common"; import { Empty } from "@bufbuild/protobuf"; @@ -24,6 +25,7 @@ import { FailedToProcessError, SessionNotFoundError, } from "../errors/satp-handler-errors"; +import { LockAssertionReceiptMessage } from "../../generated/proto/cacti/satp/v02/stage_2_pb"; export class Stage3SATPHandler implements SATPHandler { public static readonly CLASS_NAME = SATPHandlerType.STAGE3; @@ -54,6 +56,10 @@ export class Stage3SATPHandler implements SATPHandler { return this.logger; } + getStage(): string { + return Stage.STAGE3; + } + async CommitPreparationImplementation( req: CommitPreparationRequestMessage, context: HandlerContext, @@ -86,7 +92,7 @@ export class Stage3SATPHandler implements SATPHandler { return message; } catch (error) { - throw new FailedToProcessError(fnTag, "CommitPreparationRequest"); + throw new FailedToProcessError(fnTag, "CommitPreparationRequest", error); } } @@ -129,7 +135,11 @@ export class Stage3SATPHandler implements SATPHandler { return message; } catch (error) { - throw new FailedToProcessError(fnTag, "CommitFinalAssertionRequest"); + throw new FailedToProcessError( + fnTag, + "CommitFinalAssertionRequest", + error, + ); } } @@ -155,22 +165,33 @@ export class Stage3SATPHandler implements SATPHandler { return new Empty({}); } catch (error) { - throw new FailedToProcessError(fnTag, "TransferCompleteRequest"); + throw new FailedToProcessError(fnTag, "TransferCompleteRequest", error); } } setupRouter(router: ConnectRouter): void { + // eslint-disable-next-line @typescript-eslint/no-this-alias + const that = this; router.service(SatpStage3Service, { - commitPreparation: this.CommitPreparationImplementation, - commitFinalAssertion: this.CommitFinalAssertionImplementation, - transferComplete: this.TransferCompleteImplementation, + async commitPreparation(req, context) { + return await that.CommitPreparationImplementation(req, context); + }, + async commitFinalAssertion(req, context) { + return await that.CommitFinalAssertionImplementation(req, context); + }, + async transferComplete(req, context) { + return await that.TransferCompleteImplementation(req, context); + }, + // commitPreparation: this.CommitPreparationImplementation, + // commitFinalAssertion: this.CommitFinalAssertionImplementation, + // transferComplete: this.TransferCompleteImplementation, }); } //client side async CommitPreparationRequest( - response: CommitReadyResponseMessage, + response: LockAssertionReceiptMessage, ): Promise { const stepTag = `CommitPreparationRequest()`; const fnTag = `${this.getHandlerIdentifier()}#${stepTag}`; @@ -183,7 +204,7 @@ export class Stage3SATPHandler implements SATPHandler { throw new SessionNotFoundError(fnTag); } - await this.clientService.checkCommitReadyResponseMessage( + await this.clientService.checkLockAssertionReceiptMessage( response, session, ); @@ -194,11 +215,11 @@ export class Stage3SATPHandler implements SATPHandler { ); if (!request) { - throw new FailedToCreateMessageError(fnTag, "TransferProposalRequest"); + throw new FailedToCreateMessageError(fnTag, "CommitPreparationRequest"); } return request; } catch (error) { - throw new FailedToProcessError(fnTag, "TransferProposalRequest"); + throw new FailedToProcessError(fnTag, "CommitPreparationRequest", error); } } @@ -236,7 +257,11 @@ export class Stage3SATPHandler implements SATPHandler { } return request; } catch (error) { - throw new FailedToProcessError(fnTag, "CommitFinalAssertionRequest"); + throw new FailedToProcessError( + fnTag, + "CommitFinalAssertionRequest", + error, + ); } } @@ -269,7 +294,7 @@ export class Stage3SATPHandler implements SATPHandler { } return request; } catch (error) { - throw new FailedToProcessError(fnTag, "TransferCompleteRequest"); + throw new FailedToProcessError(fnTag, "TransferCompleteRequest", error); } } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage0-client-service.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage0-client-service.ts index 9bd9a8b6de..7c79cc541f 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage0-client-service.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage0-client-service.ts @@ -1,18 +1,55 @@ +import { bufArray2HexStr, getHash, sign } from "../../../gateway-utils"; +import { + MessageType, + WrapAssertionClaim, +} from "../../../generated/proto/cacti/satp/v02/common/message_pb"; +import { + NewSessionRequest, + NewSessionResponse, + PreSATPTransferRequest, +} from "../../../generated/proto/cacti/satp/v02/stage_0_pb"; +import { SATPBridgesManager } from "../../../gol/satp-bridges-manager"; +import { FailedToProcessError } from "../../errors/satp-handler-errors"; +import { + GatewayNetworkIdError, + HashError, + LedgerAssetError, + LedgerAssetIdError, + MissingBridgeManagerError, + OntologyContractError, + SessionError, + SessionIdError, + SessionMissMatchError, + SignatureVerificationError, + TransferContextIdError, +} from "../../errors/satp-service-errors"; +import { SATPSession } from "../../satp-session"; +import { + copySessionDataAttributes, + getMessageHash, + saveHash, + saveSignature, + SessionType, +} from "../../session-utils"; +import { SupportedChain } from "../../types"; +import { signatureVerifier } from "../data-verifier"; +import { Asset } from "../satp-bridge/types/asset"; import { SATPService, SATPServiceType, ISATPClientServiceOptions, ISATPServiceOptions, } from "../satp-service"; +import { protoToAsset } from "../service-utils"; export class Stage0ClientService extends SATPService { public static readonly SATP_STAGE = "0"; public static readonly SERVICE_TYPE = SATPServiceType.Client; public static readonly SATP_SERVICE_INTERNAL_NAME = `stage-${this.SATP_STAGE}-${SATPServiceType[this.SERVICE_TYPE].toLowerCase()}`; - constructor(ops: ISATPClientServiceOptions) { - // for now stage1serverservice does not have any different options than the SATPService class + private bridgeManager: SATPBridgesManager; + constructor(ops: ISATPClientServiceOptions) { const commonOptions: ISATPServiceOptions = { stage: Stage0ClientService.SATP_STAGE, loggerOptions: ops.loggerOptions, @@ -21,5 +58,271 @@ export class Stage0ClientService extends SATPService { serviceType: Stage0ClientService.SERVICE_TYPE, }; super(commonOptions); + if (ops.bridgeManager == undefined) { + throw new MissingBridgeManagerError( + `${this.getServiceIdentifier()}#constructor`, + ); + } + this.bridgeManager = ops.bridgeManager; + } + + public async newSessionRequest( + session: SATPSession, + thisGatewayId: string, + ): Promise { + const stepTag = `newSessionRequest()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + + if (session == undefined) { + throw new SessionError(fnTag); + } + + session.verify(fnTag, SessionType.CLIENT); + + const sessionData = session.getClientSessionData(); + + const newSessionRequestMessage = new NewSessionRequest(); + newSessionRequestMessage.sessionId = sessionData.id; + newSessionRequestMessage.contextId = sessionData.transferContextId; + newSessionRequestMessage.recipientGatewayNetworkId = + sessionData.recipientGatewayNetworkId; + newSessionRequestMessage.senderGatewayNetworkId = + sessionData.senderGatewayNetworkId; + newSessionRequestMessage.gatewayId = thisGatewayId; + const messageSignature = bufArray2HexStr( + sign(this.Signer, JSON.stringify(newSessionRequestMessage)), + ); + + newSessionRequestMessage.clientSignature = messageSignature; + + saveSignature( + sessionData, + MessageType.NEW_SESSION_REQUEST, + messageSignature, + ); + + saveHash( + sessionData, + MessageType.NEW_SESSION_REQUEST, + getHash(newSessionRequestMessage), + ); + + this.Log.info(`${fnTag}, sending NewSessionRequest...`); + + return newSessionRequestMessage; + } + + public async checkNewSessionResponse( + response: NewSessionResponse, + session: SATPSession, + sessionIds: string[], + ): Promise { + const stepTag = `checkNewSessionResponse()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + + if (session == undefined) { + throw new SessionError(fnTag); + } + + session.verify(fnTag, SessionType.CLIENT); + + const sessionData = session.getClientSessionData(); + + if (response.sessionId == "") { + throw new SessionIdError(fnTag); + } + + if ( + response.contextId == "" || + response.contextId != sessionData.transferContextId + ) { + throw new TransferContextIdError( + fnTag, + response.contextId, + sessionData.transferContextId, + ); + } + + if (response.serverSignature == "") { + throw new SignatureVerificationError(fnTag); + } + + if ( + response.recipientGatewayNetworkId == "" || + response.recipientGatewayNetworkId != + sessionData.recipientGatewayNetworkId + ) { + throw new GatewayNetworkIdError(fnTag); + } + + if ( + response.senderGatewayNetworkId == "" || + response.senderGatewayNetworkId != sessionData.senderGatewayNetworkId + ) { + throw new GatewayNetworkIdError(fnTag); + } + + if ( + response.hashPreviousMessage != + getMessageHash(sessionData, MessageType.NEW_SESSION_REQUEST) + ) { + throw new HashError( + fnTag, + response.hashPreviousMessage, + getMessageHash(sessionData, MessageType.NEW_SESSION_REQUEST), + ); + } + + signatureVerifier(fnTag, this.Signer, response, sessionData); + + if (sessionData.id != response.sessionId) { + if (sessionIds.includes(response.sessionId)) { + throw new SessionMissMatchError(fnTag); + } + + session = new SATPSession({ + contextID: response.contextId, + sessionID: response.sessionId, + server: false, + client: true, + }); + + copySessionDataAttributes( + sessionData, + session.getClientSessionData(), + response.sessionId, + response.contextId, + ); + } + return session; + } + + public async preSATPTransferRequest( + session: SATPSession, + ): Promise { + const stepTag = `preSATPTransferRequest()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + + if (session == undefined) { + throw new SessionError(fnTag); + } + + session.verify(fnTag, SessionType.CLIENT); + + const sessionData = session.getClientSessionData(); + + if (sessionData.receiverContractOntology == "") { + //TODO check ontology + throw new OntologyContractError(fnTag); + } + + if (sessionData.senderAsset?.tokenId == "") { + throw new LedgerAssetIdError(fnTag); + } + + if (sessionData.senderGatewayNetworkId == "") { + throw new GatewayNetworkIdError(fnTag); + } + + if (sessionData.senderAsset == undefined) { + throw new LedgerAssetError(fnTag); + } + + if (sessionData.receiverAsset == undefined) { + throw new LedgerAssetError(fnTag); + } + + const preSATPTransferRequest = new PreSATPTransferRequest(); + preSATPTransferRequest.sessionId = sessionData.id; + preSATPTransferRequest.contextId = sessionData.transferContextId; + preSATPTransferRequest.clientTransferNumber = + sessionData.clientTransferNumber; + preSATPTransferRequest.senderGatewayNetworkId = + sessionData.senderGatewayNetworkId; + preSATPTransferRequest.recipientGatewayNetworkId = + sessionData.recipientGatewayNetworkId; + preSATPTransferRequest.senderAsset = sessionData.senderAsset; + preSATPTransferRequest.receiverAsset = sessionData.receiverAsset; + preSATPTransferRequest.wrapAssertionClaim = + sessionData.senderWrapAssertionClaim; + preSATPTransferRequest.hashPreviousMessage = getMessageHash( + sessionData, + MessageType.NEW_SESSION_RESPONSE, + ); + + const messageSignature = bufArray2HexStr( + sign(this.Signer, JSON.stringify(preSATPTransferRequest)), + ); + + preSATPTransferRequest.clientSignature = messageSignature; + + saveSignature( + sessionData, + MessageType.PRE_SATP_TRANSFER_REQUEST, + messageSignature, + ); + + saveHash( + sessionData, + MessageType.PRE_SATP_TRANSFER_REQUEST, + getHash(preSATPTransferRequest), + ); + + this.Log.info(`${fnTag}, sending PreSATPTransferRequest...`); + + return preSATPTransferRequest; + } + + public async wrapToken(session: SATPSession): Promise { + const stepTag = `wrapToken()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + try { + this.Log.info(`${fnTag}, Wrapping Asset...`); + + if (session == undefined) { + throw new SessionError(fnTag); + } + + session.verify(fnTag, SessionType.CLIENT); + + const sessionData = session.getClientSessionData(); + + if (sessionData.senderGatewayNetworkId == "") { + throw new GatewayNetworkIdError(fnTag); + } + + if (sessionData.senderAsset == undefined) { + throw new LedgerAssetError(fnTag); + } + + const token: Asset = protoToAsset( + sessionData.senderAsset, + sessionData.senderGatewayNetworkId as SupportedChain, + ); + + const assetId = token.tokenId; + const amount = token.amount.toString(); + + this.Log.debug(`${fnTag}, Wrap: ${JSON.stringify(token)}`); + + this.Log.debug(`${fnTag}, Wrap Asset ID: ${assetId} amount: ${amount}`); + if (assetId == undefined) { + throw new LedgerAssetIdError(fnTag); + } + + const bridge = this.bridgeManager.getBridge( + sessionData.senderGatewayNetworkId, + ); + + sessionData.senderWrapAssertionClaim = new WrapAssertionClaim(); + sessionData.senderWrapAssertionClaim.receipt = + await bridge.wrapAsset(token); + + sessionData.senderWrapAssertionClaim.signature = bufArray2HexStr( + sign(this.Signer, sessionData.senderWrapAssertionClaim.receipt), + ); + } catch (error) { + throw new FailedToProcessError(fnTag, "WrapToken"); + } } } 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 c371aecaaf..7c7e693861 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 @@ -26,7 +26,14 @@ import { } from "../satp-service"; import { commonBodyVerifier, signatureVerifier } from "../data-verifier"; import { ACCEPTANCE } from "../../../generated/proto/cacti/satp/v02/common/session_pb"; -import { SessionError } from "../../errors/satp-service-errors"; +import { + HashError, + SessionError, + TokenIdMissingError, + TransferContextIdError, + WrapAssertionClaimError, +} from "../../errors/satp-service-errors"; +import { PreSATPTransferResponse } from "../../../generated/proto/cacti/satp/v02/stage_0_pb"; export class Stage1ClientService extends SATPService { public static readonly SATP_STAGE = "1"; @@ -271,6 +278,61 @@ export class Stage1ClientService extends SATPService { return transferCommenceRequestMessage; } + async checkPreSATPTransferResponse( + response: PreSATPTransferResponse, + session: SATPSession, + ): Promise { + const stepTag = `checkPreSATPTransferResponse()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + this.Log.debug(`${fnTag}, checkPreSATPTransferResponse...`); + + if (session == undefined) { + throw new SessionError(fnTag); + } + + session.verify(fnTag, SessionType.CLIENT); + + const sessionData = session.getClientSessionData(); + + if ( + response.contextId == "" || + response.contextId != sessionData.transferContextId + ) { + throw new TransferContextIdError( + fnTag, + response.contextId, + sessionData.transferContextId, + ); + } + + if (response.wrapAssertionClaim == undefined) { + throw new WrapAssertionClaimError(fnTag); + } + + if (response.recipientTokenId == "") { + throw new TokenIdMissingError(fnTag); + } + + if ( + response.hashPreviousMessage != + getMessageHash(sessionData, MessageType.PRE_SATP_TRANSFER_REQUEST) + ) { + throw new HashError( + fnTag, + response.hashPreviousMessage, + getMessageHash(sessionData, MessageType.PRE_SATP_TRANSFER_REQUEST), + ); + } + + signatureVerifier(fnTag, this.Signer, response, sessionData); + + sessionData.receiverAsset!.tokenId = response.recipientTokenId; + + saveHash(sessionData, MessageType.PRE_SATP_TRANSFER_RESPONSE, fnTag); + + this.Log.info(`${fnTag}, PreSATPTransferResponse passed all checks.`); + } + async checkTransferProposalReceiptMessage( response: TransferProposalReceiptMessage, session: SATPSession, 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 7a5a96a137..d63dbb1879 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 @@ -28,7 +28,9 @@ import { LockAssertionClaimError, LockAssertionClaimFormatError, SessionError, + TokenIdMissingError, } from "../../errors/satp-service-errors"; +import { FailedToProcessError } from "../../errors/satp-handler-errors"; export class Stage2ClientService extends SATPService { public static readonly SATP_STAGE = "2"; @@ -204,12 +206,17 @@ export class Stage2ClientService extends SATPService { const sessionData = session.getClientSessionData(); - const assetId = sessionData?.transferInitClaims?.digitalAssetId; - const amount = sessionData?.transferInitClaims?.amountFromOriginator; + const assetId = sessionData.senderAsset?.tokenId; + const amount = sessionData.senderAsset?.amount; this.Log.debug(`${fnTag}, Lock Asset ID: ${assetId} amount: ${amount}`); + if (assetId == undefined) { - throw new Error(`${fnTag}, Asset ID is missing`); + throw new TokenIdMissingError(fnTag); + } + + if (amount == undefined) { + throw new Error(`${fnTag}, Amount is missing`); } const bridge = this.bridgeManager.getBridge( @@ -230,7 +237,7 @@ export class Stage2ClientService extends SATPService { sign(this.Signer, sessionData.lockAssertionClaim.receipt), ); } catch (error) { - throw new Error(`${fnTag}, Failed to process Lock Asset ${error}`); + throw new FailedToProcessError(fnTag, "LockAsset"); } } } 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 e7674a09b3..682f4dcf0f 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 @@ -34,7 +34,9 @@ import { MintAssertionClaimError, MissingBridgeManagerError, SessionError, + TokenIdMissingError, } from "../../errors/satp-service-errors"; +import { FailedToProcessError } from "../../errors/satp-handler-errors"; export class Stage3ClientService extends SATPService { public static readonly SATP_STAGE = "3"; @@ -466,12 +468,17 @@ export class Stage3ClientService extends SATPService { const sessionData = session.getClientSessionData(); - const assetId = sessionData.transferInitClaims?.digitalAssetId; - const amount = sessionData.transferInitClaims?.amountFromOriginator; + const assetId = sessionData.senderAsset?.tokenId; + const amount = sessionData.senderAsset?.amount; this.Log.debug(`${fnTag}, Burn Asset ID: ${assetId} amount: ${amount}`); + if (assetId == undefined) { - throw new Error(`${fnTag}, Asset ID is missing`); + throw new TokenIdMissingError(fnTag); + } + + if (amount == undefined) { + throw new Error(`${fnTag}, Amount is missing`); } const bridge = this.bridgeManager.getBridge( @@ -487,7 +494,7 @@ export class Stage3ClientService extends SATPService { sign(this.Signer, sessionData.burnAssertionClaim.receipt), ); } catch (error) { - throw new Error(`${fnTag}, Failed to process Burn Asset ${error}`); + throw new FailedToProcessError(fnTag, "BurnAsset"); } } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/data-verifier.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/data-verifier.ts index c82bfe7438..33ce5295af 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/data-verifier.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/data-verifier.ts @@ -48,6 +48,7 @@ export function commonBodyVerifier( (common.hashPreviousMessage == "" && messageStage != MessageType.INIT_PROPOSAL) ) { + console.error("errorcommon", JSON.stringify(common)); throw new SatpCommonBodyError(tag, JSON.stringify(common)); } @@ -122,13 +123,16 @@ export function signatureVerifier( throw new SessionDataNotLoadedCorrectlyError(tag, "undefined"); } - if (message.serverSignature != "") { + if (message.serverSignature != undefined && message.serverSignature != "") { if ( !verifySignature(signer, message, sessionData?.serverGatewayPubkey || "") ) { throw new SignatureVerificationError(tag); } - } else if (message.clientSignature != "") { + } else if ( + message.clientSignature != undefined && + message.clientSignature != "" + ) { if ( !verifySignature(signer, message, sessionData?.clientGatewayPubkey || "") ) { diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-bridge/besu-bridge.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-bridge/besu-bridge.ts index a6bb0b2902..702e619f7a 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-bridge/besu-bridge.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-bridge/besu-bridge.ts @@ -52,6 +52,13 @@ export class BesuBridge implements NetworkBridge { this.connector = new PluginLedgerConnectorBesu(besuConfig.options); this.bungee = new PluginBungeeHermes(besuConfig.bungeeOptions); this.bungee.addStrategy(this.network, new StrategyBesu(level)); + + //TODO is this needed? + if (besuConfig.besuAssets) { + besuConfig.besuAssets.forEach(async (asset) => { + await this.wrapAsset(asset); + }); + } } public async wrapAsset(asset: BesuAsset): Promise { 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 index c582714c88..cf75f0449d 100644 --- 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 @@ -7,7 +7,7 @@ import { Asset } from "./types/asset"; import { TransactionIdUndefinedError } from "../../errors/bridge-erros"; export class SATPBridgeManager implements BridgeManager { - public static readonly CLASS_NAME = "FabricBridgeManager"; + public static readonly CLASS_NAME = "SATPBridgeManager"; private _log: Logger; @@ -29,10 +29,11 @@ export class SATPBridgeManager implements BridgeManager { throw new TransactionIdUndefinedError(fnTag); } - const receipt = this.config.network.getReceipt( - asset.tokenId, - response.transactionId, - ); + const receipt = ""; + // this.config.network.getReceipt( + // asset.tokenId, + // response.transactionId, + // ); this.log.info(`${fnTag}, proof of the asset wrapping: ${receipt}`); @@ -70,10 +71,11 @@ export class SATPBridgeManager implements BridgeManager { throw new TransactionIdUndefinedError(fnTag); } - const receipt = await this.config.network.getReceipt( - assetId, - response.transactionId, - ); + const receipt = ""; + // this.config.network.getReceipt( + // asset.tokenId, + // response.transactionId, + // ); this.log.info(`${fnTag}, proof of the asset lock: ${receipt}`); @@ -108,10 +110,11 @@ export class SATPBridgeManager implements BridgeManager { throw new TransactionIdUndefinedError(fnTag); } - const receipt = await this.config.network.getReceipt( - assetId, - transaction.transactionId, - ); + const receipt = ""; + // this.config.network.getReceipt( + // asset.tokenId, + // response.transactionId, + // ); this.log.info(`${fnTag}, proof of the asset creation: ${receipt}`); @@ -127,10 +130,11 @@ export class SATPBridgeManager implements BridgeManager { throw new TransactionIdUndefinedError(fnTag); } - const receipt = await this.config.network.getReceipt( - assetId, - transaction.transactionId, - ); + const receipt = ""; + // this.config.network.getReceipt( + // asset.tokenId, + // response.transactionId, + // ); this.log.info(`${fnTag}, proof of the asset deletion: ${receipt}`); @@ -154,10 +158,11 @@ export class SATPBridgeManager implements BridgeManager { throw new TransactionIdUndefinedError(fnTag); } - const receipt = await this.config.network.getReceipt( - assetId, - response.transactionId, - ); + const receipt = ""; + // this.config.network.getReceipt( + // asset.tokenId, + // response.transactionId, + // ); this.log.info(`${fnTag}, proof of the asset assignment: ${receipt}`); diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-bridge/types/asset.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-bridge/types/asset.ts index 2c743e415f..4f613e8020 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-bridge/types/asset.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-bridge/types/asset.ts @@ -1,9 +1,11 @@ +import { v4 as uuidv4 } from "uuid"; export interface Asset { tokenId: string; tokenType: TokenType; owner: string; amount: number; ontology: string; + contractName: string; } //When there is new token type, add it here or it will break the code @@ -32,3 +34,11 @@ export function getInteractionType(stringType: string) { stringType.toUpperCase() as keyof typeof InteractionType ]; } + +export function createAssetId( + contextId: string, + tokenType: TokenType, + networkId: string, +): string { + return `${uuidv4()}-${contextId}-${tokenType}-${networkId}`; +} diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-bridge/types/besu-asset.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-bridge/types/besu-asset.ts index af5847b08b..f3ddfadee7 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-bridge/types/besu-asset.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-bridge/types/besu-asset.ts @@ -1,7 +1,6 @@ import { Asset } from "./asset"; export interface BesuAsset extends Asset { - contractName: string; contractAddress: string; } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-bridge/types/fabric-asset.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-bridge/types/fabric-asset.ts index 6b0fc4e368..d8f8c0481a 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-bridge/types/fabric-asset.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/satp-bridge/types/fabric-asset.ts @@ -2,7 +2,6 @@ import { Asset, InteractionType } from "./asset"; export interface FabricAsset extends Asset { mspId: string; - contractName: string; channelName: string; } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage0-server-service.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage0-server-service.ts index a1304df153..c741382e2b 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage0-server-service.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage0-server-service.ts @@ -1,18 +1,57 @@ -import { Token } from "../../../public-api"; +import { + bufArray2HexStr, + getHash, + sign, + verifySignature, +} from "../../../gateway-utils"; +import { + MessageType, + WrapAssertionClaim, +} from "../../../generated/proto/cacti/satp/v02/common/message_pb"; +import { + NewSessionRequest, + NewSessionResponse, + PreSATPTransferRequest, + PreSATPTransferResponse, + STATUS, +} from "../../../generated/proto/cacti/satp/v02/stage_0_pb"; +import { SATPBridgesManager } from "../../../gol/satp-bridges-manager"; +import { + AssetMissing, + GatewayNetworkIdError, + LedgerAssetError, + MissingBridgeManagerError, + NetworkIdError, + SessionDataNotAvailableError, + SessionError, + SessionIdError, + SignatureMissingError, + SignatureVerificationError, +} from "../../errors/satp-service-errors"; +import { SATPSession } from "../../satp-session"; +import { + getMessageHash, + saveHash, + saveSignature, + SessionType, +} from "../../session-utils"; +import { Asset, createAssetId } from "../satp-bridge/types/asset"; import { SATPService, SATPServiceType, ISATPServerServiceOptions, ISATPServiceOptions, } from "../satp-service"; - +import { protoToAsset } from "../service-utils"; export class Stage0ServerService extends SATPService { public static readonly SATP_STAGE = "0"; public static readonly SERVICE_TYPE = SATPServiceType.Server; public static readonly SATP_SERVICE_INTERNAL_NAME = `stage-${this.SATP_STAGE}-${SATPServiceType[this.SERVICE_TYPE].toLowerCase()}`; + private bridgeManager: SATPBridgesManager; + constructor(ops: ISATPServerServiceOptions) { - // for now stage0serverservice does not have any different options than the SATPService class + // for now stage1serverservice does not have any different options than the SATPService class const commonOptions: ISATPServiceOptions = { stage: Stage0ServerService.SATP_STAGE, @@ -22,14 +61,350 @@ export class Stage0ServerService extends SATPService { serviceType: Stage0ServerService.SERVICE_TYPE, }; super(commonOptions); + if (ops.bridgeManager == undefined) { + throw new MissingBridgeManagerError( + `${this.getServiceIdentifier()}#constructor`, + ); + } + this.bridgeManager = ops.bridgeManager; + } + + public async checkNewSessionRequest( + request: NewSessionRequest, + session: SATPSession | undefined, + clientPubKey: string, + ): Promise { + const stepTag = `checkNewSessionRequest()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + + if (request == undefined) { + throw new Error(`${fnTag}, Request is undefined`); + } + + if (request.clientSignature == "") { + throw new SignatureMissingError(fnTag); + } + + if (request.sessionId == "") { + throw new SessionIdError(fnTag); + } + + if (request.senderGatewayNetworkId == "") { + throw new NetworkIdError(fnTag, "Sender"); + } + + if (request.recipientGatewayNetworkId == "") { + throw new NetworkIdError(fnTag, "Recipient"); + } + + if (!verifySignature(this.Signer, request, clientPubKey)) { + throw new SignatureVerificationError(fnTag); + } + + if (session == undefined) { + this.Log.debug(`${fnTag}, Session is undefined needs to be created`); + session = new SATPSession({ + contextID: request.contextId, + sessionID: request.sessionId, + server: true, + client: false, + }); + } else if (!session.hasServerSessionData()) { + this.Log.debug(`${fnTag}, Session does not have server session data`); + session.createSessionData( + SessionType.SERVER, + request.sessionId, + request.contextId, + ); + } else { + this.Log.debug(`${fnTag}, Session is already has a server session`); + session = new SATPSession({ + contextID: request.contextId, + server: true, + client: false, + }); + this.Log.debug( + `${fnTag}, Session created with new sessionID ${session.getSessionId()}`, + ); + } + + const newSessionData = session.getServerSessionData(); + + newSessionData.clientGatewayPubkey = clientPubKey; + newSessionData.senderGatewayNetworkId = request.senderGatewayNetworkId; + newSessionData.recipientGatewayNetworkId = + request.recipientGatewayNetworkId; + + saveSignature( + newSessionData, + MessageType.NEW_SESSION_REQUEST, + request.clientSignature, + ); + + saveHash(newSessionData, MessageType.NEW_SESSION_REQUEST, getHash(request)); + + this.Log.info(`${fnTag}, NewSessionRequest passed all checks.`); + return session; + } + + public async checkPreSATPTransferRequest( + request: PreSATPTransferRequest, + session: SATPSession, + ): Promise { + const stepTag = `checkPreSATPTransferRequest()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + + if (session == undefined) { + throw new SessionError(fnTag); + } + + if (!session.hasServerSessionData()) { + throw new Error(`${fnTag}, Session Data is missing`); + } + + const sessionData = session.getServerSessionData(); + + if (request.sessionId != sessionData.id) { + throw new Error(`${fnTag}, Session ID does not match`); + } + + if (request.senderGatewayNetworkId != sessionData.senderGatewayNetworkId) { + throw new Error(`${fnTag}, Sender Gateway Network ID does not match`); + } + + if ( + request.recipientGatewayNetworkId != sessionData.recipientGatewayNetworkId + ) { + throw new Error(`${fnTag}, Recipient Gateway Network ID does not match`); + } + + if (request.senderAsset == undefined) { + throw new Error(`${fnTag}, Sender Asset is missing`); + } + + if (request.receiverAsset == undefined) { + throw new Error(`${fnTag}, Receiver Asset is missing`); + } + + if ( + request.hashPreviousMessage != + getMessageHash(sessionData, MessageType.NEW_SESSION_RESPONSE) + ) { + throw new Error(`${fnTag}, Hash of previous message does not match`); + } + + if (request.clientSignature == "") { + throw new Error(`${fnTag}, Client Signature is missing`); + } + + if ( + !verifySignature(this.Signer, request, sessionData.clientGatewayPubkey) + ) { + throw new Error(`${fnTag}, Client Signature is invalid`); + } + + if (request.senderAsset == undefined) { + throw new Error(`${fnTag}, Sender Asset is missing`); + } + + sessionData.senderAsset = request.senderAsset; + + if (request.receiverAsset == undefined) { + throw new Error(`${fnTag}, Receiver Asset is missing`); + } + + if (request.wrapAssertionClaim == undefined) { + throw new Error(`${fnTag}, Wrap Assertion Claim is missing`); + } + + if (request.clientTransferNumber != "") { + this.Log.info( + `${fnTag}, Optional variable loaded: clientTransferNumber...`, + ); + sessionData.clientTransferNumber = request.clientTransferNumber; + } + + saveSignature( + sessionData, + MessageType.PRE_SATP_TRANSFER_REQUEST, + request.clientSignature, + ); + + saveHash( + sessionData, + MessageType.PRE_SATP_TRANSFER_REQUEST, + getHash(request), + ); + + //TODO maybe do a hard copy, reason: after the hash because this changes the req object + sessionData.receiverAsset = request.receiverAsset; + + sessionData.receiverAsset.tokenId = createAssetId( + request.contextId, + request.receiverAsset.tokenType, + sessionData.recipientGatewayNetworkId, + ); + + this.Log.info(`${fnTag}, PreSATPTransferRequest passed all checks.`); } - public async getPubKey(): Promise { - //todo + public async newSessionResponse( + request: NewSessionRequest, + session: SATPSession, + ): Promise { + const stepTag = `newSessionResponse()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + + if (session == undefined) { + throw new SessionError(fnTag); + } + + if (!session.hasServerSessionData()) { + throw new SessionDataNotAvailableError("server", fnTag); + } + const sessionData = session.getServerSessionData(); + + const newSessionResponse = new NewSessionResponse(); + + if (sessionData.id != request.sessionId) { + newSessionResponse.status = STATUS.STATUS_REJECTED; + } else { + newSessionResponse.status = STATUS.STATUS_ACCEPTED; + } + newSessionResponse.sessionId = sessionData.id; + newSessionResponse.contextId = sessionData.transferContextId; + newSessionResponse.recipientGatewayNetworkId = + sessionData.recipientGatewayNetworkId; + newSessionResponse.senderGatewayNetworkId = + sessionData.senderGatewayNetworkId; + + newSessionResponse.hashPreviousMessage = getMessageHash( + sessionData, + MessageType.NEW_SESSION_REQUEST, + ); + + const messageSignature = bufArray2HexStr( + sign(this.Signer, JSON.stringify(newSessionResponse)), + ); + + newSessionResponse.serverSignature = messageSignature; + + saveSignature( + sessionData, + MessageType.NEW_SESSION_REQUEST, + messageSignature, + ); + + saveHash(sessionData, MessageType.NEW_SESSION_REQUEST, fnTag); + + this.Log.info(`${fnTag}, sending NewSessionRequest...`); + + return newSessionResponse; } - public async wrapToken(token: Token) { - //todo - return token; + public async preSATPTransferResponse( + request: PreSATPTransferRequest, + session: SATPSession, + ): Promise { + const stepTag = `preSATPTransferResponse()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + + if (session == undefined) { + throw new SessionError(fnTag); + } + + if (!session.hasServerSessionData()) { + throw new SessionDataNotAvailableError("server", fnTag); + } + + const sessionData = session.getServerSessionData(); + + const preSATPTransferResponse = new PreSATPTransferResponse(); + + preSATPTransferResponse.sessionId = sessionData.id; + preSATPTransferResponse.contextId = sessionData.transferContextId; + + preSATPTransferResponse.hashPreviousMessage = getMessageHash( + sessionData, + MessageType.PRE_SATP_TRANSFER_REQUEST, + ); + + if (request.receiverAsset == undefined) { + throw new AssetMissing(fnTag); + } + + preSATPTransferResponse.wrapAssertionClaim = + sessionData.receiverWrapAssertionClaim; + preSATPTransferResponse.recipientTokenId = + sessionData.receiverAsset!.tokenId; + + const messageSignature = bufArray2HexStr( + sign(this.Signer, JSON.stringify(preSATPTransferResponse)), + ); + + preSATPTransferResponse.serverSignature = messageSignature; + + saveSignature( + sessionData, + MessageType.PRE_SATP_TRANSFER_REQUEST, + messageSignature, + ); + + saveHash(sessionData, MessageType.PRE_SATP_TRANSFER_REQUEST, fnTag); + + this.Log.info(`${fnTag}, sending PreSATPTransferResponse...`); + + return preSATPTransferResponse; + } + + public async wrapToken(session: SATPSession): Promise { + const stepTag = `wrapToken()`; + const fnTag = `${this.getServiceIdentifier()}#${stepTag}`; + try { + this.Log.info(`${fnTag}, Wrapping Asset...`); + + if (session == undefined) { + throw new SessionError(fnTag); + } + + //TODO: check if is necessary to verify more things + + const sessionData = session.getServerSessionData(); + + if (sessionData.recipientGatewayNetworkId == "") { + throw new GatewayNetworkIdError(fnTag); + } + + if (sessionData.receiverAsset == undefined) { + throw new LedgerAssetError(fnTag); + } + + const token: Asset = protoToAsset( + sessionData.receiverAsset, + sessionData.recipientGatewayNetworkId, + ); + + const assetId = token.tokenId; + const amount = token.amount.toString(); + + this.Log.debug(`${fnTag}, Wrap Asset ID: ${assetId} amount: ${amount}`); + if (assetId == undefined) { + throw new Error(`${fnTag}, Asset ID is missing`); + } + + const bridge = this.bridgeManager.getBridge( + sessionData.recipientGatewayNetworkId, + ); + + sessionData.receiverWrapAssertionClaim = new WrapAssertionClaim(); + sessionData.receiverWrapAssertionClaim.receipt = + await bridge.wrapAsset(token); + + sessionData.receiverWrapAssertionClaim.signature = bufArray2HexStr( + sign(this.Signer, sessionData.receiverWrapAssertionClaim.receipt), + ); + } catch (error) { + throw new Error(`${fnTag}, Failed to process Wrap Asset ${error}`); + } } } 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 f5fd51fb1b..fdf658d724 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 @@ -71,7 +71,12 @@ export class Stage1ServerService extends SATPService { throw new SessionError(fnTag); } - session.verify(fnTag, SessionType.SERVER); + if ( + session.getServerSessionData().acceptance == + ACCEPTANCE.ACCEPTANCE_ACCEPTED + ) { + session.verify(fnTag, SessionType.SERVER); + } const sessionData = session.getServerSessionData(); @@ -236,6 +241,7 @@ export class Stage1ServerService extends SATPService { this.checkNetworkCapabilities(request.networkCapabilities, fnTag); if (this.checkTransferClaims(request.transferInitClaims, fnTag)) { + this.Log.info(`${fnTag}, TransferProposalRequest was accepted...`); sessionData.acceptance = ACCEPTANCE.ACCEPTANCE_ACCEPTED; } else { this.Log.info(`${fnTag}, TransferProposalRequest was rejected...`); @@ -243,11 +249,11 @@ export class Stage1ServerService extends SATPService { return; } - const senderId = request.transferInitClaims! - .senderGatewayNetworkId as SupportedChain; + const receiverId = request.transferInitClaims! + .recipientGatewayNetworkId as SupportedChain; - if (!supportedDLTs.includes(senderId)) { - throw new DLTNotSupportedError(fnTag, senderId); //todo change this to the transferClaims check + if (!supportedDLTs.includes(receiverId)) { + throw new DLTNotSupportedError(fnTag, receiverId); //todo change this to the transferClaims check } sessionData.version = request.common!.version; @@ -330,7 +336,7 @@ export class Stage1ServerService extends SATPService { throw new TransferInitClaimsHashError(fnTag); } - if (request.clientTransferNumber != undefined) { + if (request.clientTransferNumber != "") { this.Log.info( `${fnTag}, Optional variable loaded: clientTransferNumber...`, ); @@ -358,18 +364,18 @@ export class Stage1ServerService extends SATPService { } if (transferClaims.assetProfileId == "") { this.Log.error(`${tag}, assetProfileId is missing`); - return false; + //return false; } if (transferClaims.verifiedOriginatorEntityId == "") { this.Log.error(`${tag}, verifiedOriginatorEntityId is missing`); - return false; + //return false; } if (transferClaims.verifiedBeneficiaryEntityId == "") { this.Log.error(`${tag}, verifiedBeneficiaryEntityId is missing`); } if (transferClaims.originatorPubkey == "") { this.Log.error(`${tag}, originatorPubkey is missing`); - return false; + //return false; } if (transferClaims.beneficiaryPubkey == "") { this.Log.error(`${tag}, beneficiaryPubkey is missing`); 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 0831f815d7..408f068377 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 @@ -33,8 +33,11 @@ import { BurnAssertionClaimError, MintAssertionClaimError, MissingBridgeManagerError, + MissingRecipientError, SessionError, + TokenIdMissingError, } from "../../errors/satp-service-errors"; +import { FailedToProcessError } from "../../errors/satp-handler-errors"; export class Stage3ServerService extends SATPService { public static readonly SATP_STAGE = "3"; @@ -397,14 +400,18 @@ export class Stage3ServerService extends SATPService { const sessionData = session.getServerSessionData(); - const assetId = sessionData.transferInitClaims?.digitalAssetId; - const amount = sessionData.transferInitClaims?.amountToBeneficiary; + const assetId = sessionData.receiverAsset?.tokenId; + const amount = sessionData.receiverAsset?.amount; this.logger.debug( `${fnTag}, Mint Asset ID: ${assetId} amount: ${amount}`, ); if (assetId == undefined) { - throw new Error(`${fnTag}, Asset ID is missing`); + throw new TokenIdMissingError(fnTag); + } + + if (amount == undefined) { + throw new Error(`${fnTag}, Amount is missing`); } const bridge = this.bridgeManager.getBridge( @@ -420,7 +427,7 @@ export class Stage3ServerService extends SATPService { sign(this.Signer, sessionData.mintAssertionClaim.receipt), ); } catch (error) { - throw new Error(`${fnTag}, Failed to process Mint Asset ${error}`); + throw new FailedToProcessError(fnTag, "MintAsset"); } } @@ -438,18 +445,22 @@ export class Stage3ServerService extends SATPService { const sessionData = session.getServerSessionData(); - const assetId = sessionData.transferInitClaims?.digitalAssetId; - const amount = sessionData.transferInitClaims?.amountToBeneficiary; - const recipient = sessionData.transferInitClaims?.beneficiaryPubkey; + const assetId = sessionData.receiverAsset?.tokenId; + const amount = sessionData.receiverAsset?.amount; + const recipient = sessionData.receiverAsset?.owner; if (recipient == undefined) { - throw new Error(`${fnTag}, Recipient is missing`); + throw new MissingRecipientError(fnTag); } this.logger.debug( `${fnTag}, Assign Asset ID: ${assetId} amount: ${amount} recipient: ${recipient}`, ); if (assetId == undefined) { - throw new Error(`${fnTag}, Asset ID is missing`); + throw new TokenIdMissingError(fnTag); + } + + if (amount == undefined) { + throw new Error(`${fnTag}, Amount is missing`); } const bridge = this.bridgeManager.getBridge( @@ -466,7 +477,7 @@ export class Stage3ServerService extends SATPService { sign(this.Signer, sessionData.assignmentAssertionClaim.receipt), ); } catch (error) { - throw new Error(`${fnTag}, Failed to process Assign Asset ${error}`); + throw new FailedToProcessError(fnTag, "AssignAsset"); } } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/service-utils.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/service-utils.ts new file mode 100644 index 0000000000..dd1be75994 --- /dev/null +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/service-utils.ts @@ -0,0 +1,70 @@ +import { Asset as ProtoAsset } from "../../generated/proto/cacti/satp/v02/common/message_pb"; +import { SupportedChain } from "../types"; +import { Asset } from "./satp-bridge/types/asset"; +import { BesuAsset } from "./satp-bridge/types/besu-asset"; +import { FabricAsset } from "./satp-bridge/types/fabric-asset"; + +export function assetToProto( + asset: Asset, + networkId: SupportedChain, +): ProtoAsset { + const protoAsset = new ProtoAsset(); + protoAsset.tokenId = asset.tokenId; + protoAsset.tokenType = asset.tokenType; + protoAsset.owner = asset.owner; + protoAsset.amount = BigInt(asset.amount); + + switch (networkId) { + case SupportedChain.BESU: + protoAsset.contractAddress = (asset as BesuAsset).contractAddress; + break; + case SupportedChain.FABRIC: + protoAsset.mspId = (asset as FabricAsset).mspId; + protoAsset.channelName = (asset as FabricAsset).channelName; + break; + default: + throw new Error(`Unsupported networkId: ${networkId}`); + } + return protoAsset; +} + +export function protoToAsset(asset: ProtoAsset, networkId: string): Asset { + const assetObj: Asset = { + tokenId: asset.tokenId, + tokenType: asset.tokenType.valueOf(), + owner: asset.owner, + amount: Number(asset.amount), + ontology: asset.ontology, + contractName: asset.contractName, + }; + + switch (networkId) { + case SupportedChain.BESU: + (assetObj as BesuAsset).contractAddress = asset.contractAddress; + break; + case SupportedChain.FABRIC: + (assetObj as FabricAsset).mspId = asset.mspId; + (assetObj as FabricAsset).channelName = asset.channelName; + break; + default: + throw new Error(`Unsupported networkId: ${networkId}`); + } + return assetObj; +} + +export function compareProtoAsset( + asset1: ProtoAsset, + asset2: ProtoAsset, +): boolean { + return ( + asset1.tokenId === asset2.tokenId && + asset1.tokenType === asset2.tokenType && + asset1.owner === asset2.owner && + asset1.amount === asset2.amount && + asset1.ontology === asset2.ontology && + asset1.contractName === asset2.contractName && + asset1.mspId === asset2.mspId && + asset1.channelName === asset2.channelName && + asset1.contractAddress === asset2.contractAddress + ); +} 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 80b9b70d8e..d17ce0d53b 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 @@ -11,6 +11,7 @@ import { IPrivacyPolicyValue } from "@hyperledger/cactus-plugin-bungee-hermes/di import { IMergePolicyValue } from "@hyperledger/cactus-plugin-bungee-hermes/dist/lib/main/typescript/view-merging/merge-policies"; import { NetworkBridge } from "./stage-services/satp-bridge/network-bridge"; import { SATPServiceInstance } from "./stage-services/satp-service"; +import { NetworkConfig } from "../types/blockchain-interaction"; export type SATPConnectHandler = ( gateway: SATPGateway, @@ -52,10 +53,11 @@ export type GatewayChannel = { export type Address = | `http://${string}` | `https://${string}` - | `${number}.${number}.${number}.${number}.`; + | `${number}.${number}.${number}.${number}`; export type GatewayIdentity = { id: string; + pubKey?: string; name?: string; version: DraftVersions[]; supportedDLTs: SupportedChain[]; @@ -76,6 +78,7 @@ export interface SATPGatewayConfig { validationOptions?: ValidatorOptions; privacyPolicies?: IPrivacyPolicyValue[]; mergePolicies?: IMergePolicyValue[]; + bridgesConfig?: NetworkConfig[]; } // export interface SATPBridgeConfig { diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/gateway-utils.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/gateway-utils.ts index d5de011eb6..50ed95ab34 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/gateway-utils.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/gateway-utils.ts @@ -23,6 +23,7 @@ export function verifySignature( const sourceSignature = new Uint8Array( Buffer.from(copy.clientSignature, "hex"), ); + const sourcePubkey = new Uint8Array(Buffer.from(pubKey, "hex")); copy.clientSignature = ""; @@ -36,6 +37,7 @@ export function verifySignature( const sourceSignature = new Uint8Array( Buffer.from(copy.serverSignature, "hex"), ); + const sourcePubkey = new Uint8Array(Buffer.from(pubKey, "hex")); copy.serverSignature = ""; diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/gateway-client/typescript-axios/api.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/gateway-client/typescript-axios/api.ts index 5009672823..91f69c4e4a 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/gateway-client/typescript-axios/api.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/gateway-client/typescript-axios/api.ts @@ -103,6 +103,49 @@ export interface Action { */ 'toAddress'?: string; } +/** + * An asset + * @export + * @interface Asset + */ +export interface Asset { + /** + * + * @type {string} + * @memberof Asset + */ + 'owner': string; + /** + * + * @type {string} + * @memberof Asset + */ + 'ontology': string; + /** + * + * @type {string} + * @memberof Asset + */ + 'contractName': string; + /** + * + * @type {string} + * @memberof Asset + */ + 'contractAddress'?: string; + /** + * + * @type {string} + * @memberof Asset + */ + 'mspId'?: string; + /** + * + * @type {string} + * @memberof Asset + */ + 'channelName'?: string; +} /** * Stores global constants related to the authorization of the application. Specifically enumerates the claims to validate for as per RFC 7519, section 4.1. See: https://tools.ietf.org/html/rfc7519#section-4.1 * @export @@ -1856,37 +1899,49 @@ export interface TransactRequest { * @type {string} * @memberof TransactRequest */ - 'fromDLTNetworkID'?: string; + 'fromDLTNetworkID': string; /** * * @type {string} * @memberof TransactRequest */ - 'toDLTNetworkID'?: string; + 'toDLTNetworkID': string; /** * * @type {string} * @memberof TransactRequest */ - 'fromAmount'?: string; + 'fromAmount': string; /** * * @type {string} * @memberof TransactRequest */ - 'fromToken'?: string; + 'toAmount': string; /** * * @type {string} * @memberof TransactRequest */ - 'toAmount'?: string; + 'beneficiaryPubkey': string; /** * * @type {string} * @memberof TransactRequest */ - 'toToken'?: string; + 'originatorPubkey': string; + /** + * + * @type {TransactRequestSourceAsset} + * @memberof TransactRequest + */ + 'sourceAsset': TransactRequestSourceAsset; + /** + * + * @type {TransactRequestSourceAsset} + * @memberof TransactRequest + */ + 'destinyAsset': TransactRequestSourceAsset; } export const TransactRequestModeEnum = { @@ -1896,6 +1951,49 @@ export const TransactRequestModeEnum = { export type TransactRequestModeEnum = typeof TransactRequestModeEnum[keyof typeof TransactRequestModeEnum]; +/** + * An asset + * @export + * @interface TransactRequestSourceAsset + */ +export interface TransactRequestSourceAsset { + /** + * + * @type {string} + * @memberof TransactRequestSourceAsset + */ + 'owner': string; + /** + * + * @type {string} + * @memberof TransactRequestSourceAsset + */ + 'ontology': string; + /** + * + * @type {string} + * @memberof TransactRequestSourceAsset + */ + 'contractName': string; + /** + * + * @type {string} + * @memberof TransactRequestSourceAsset + */ + 'contractAddress'?: string; + /** + * + * @type {string} + * @memberof TransactRequestSourceAsset + */ + 'mspId'?: string; + /** + * + * @type {string} + * @memberof TransactRequestSourceAsset + */ + 'channelName'?: string; +} /** * Response schema for a transaction request. Includes the session ID and the current status of the transaction. * @export diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/common/health_connect.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/common/health_connect.ts index 6868d89652..74a983f613 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/common/health_connect.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/common/health_connect.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-connect-es v1.3.0 with parameter "target=ts,js_import_style=module" +// @generated by protoc-gen-connect-es v1.4.0 with parameter "target=ts,js_import_style=module" // @generated from file cacti/satp/v02/common/health.proto (package cacti.satp.v02.common, syntax proto3) /* eslint-disable */ // @ts-nocheck 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 ac13a62b54..36d20c534e 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 @@ -125,6 +125,26 @@ export enum MessageType { * @generated from enum value: MESSAGE_TYPE_COMMIT_TRANSFER_COMPLETE = 17; */ COMMIT_TRANSFER_COMPLETE = 17, + + /** + * @generated from enum value: MESSAGE_TYPE_NEW_SESSION_REQUEST = 18; + */ + NEW_SESSION_REQUEST = 18, + + /** + * @generated from enum value: MESSAGE_TYPE_NEW_SESSION_RESPONSE = 19; + */ + NEW_SESSION_RESPONSE = 19, + + /** + * @generated from enum value: MESSAGE_TYPE_PRE_SATP_TRANSFER_REQUEST = 20; + */ + PRE_SATP_TRANSFER_REQUEST = 20, + + /** + * @generated from enum value: MESSAGE_TYPE_PRE_SATP_TRANSFER_RESPONSE = 21; + */ + PRE_SATP_TRANSFER_RESPONSE = 21, } // Retrieve enum metadata with: proto3.getEnumType(MessageType) proto3.util.setEnumType(MessageType, "cacti.satp.v02.common.MessageType", [ @@ -146,6 +166,10 @@ proto3.util.setEnumType(MessageType, "cacti.satp.v02.common.MessageType", [ { no: 15, name: "MESSAGE_TYPE_COMMIT_FINAL" }, { no: 16, name: "MESSAGE_TYPE_ACK_COMMIT_FINAL" }, { no: 17, name: "MESSAGE_TYPE_COMMIT_TRANSFER_COMPLETE" }, + { no: 18, name: "MESSAGE_TYPE_NEW_SESSION_REQUEST" }, + { no: 19, name: "MESSAGE_TYPE_NEW_SESSION_RESPONSE" }, + { no: 20, name: "MESSAGE_TYPE_PRE_SATP_TRANSFER_REQUEST" }, + { no: 21, name: "MESSAGE_TYPE_PRE_SATP_TRANSFER_RESPONSE" }, ]); /** @@ -360,6 +384,38 @@ proto3.util.setEnumType(Error, "cacti.satp.v02.common.Error", [ { no: 11, name: "ERROR_MESSAGE_OUT_OF_SEQUENCE" }, ]); +/** + * @generated from enum cacti.satp.v02.common.TokenType + */ +export enum TokenType { + /** + * @generated from enum value: TOKEN_TYPE_ERC20 = 0; + */ + ERC20 = 0, + + /** + * @generated from enum value: TOKEN_TYPE_ERC721 = 1; + */ + ERC721 = 1, + + /** + * @generated from enum value: TOKEN_TYPE_ERC1155 = 2; + */ + ERC1155 = 2, + + /** + * @generated from enum value: TOKEN_TYPE_NONSTANDARD = 3; + */ + NONSTANDARD = 3, +} +// Retrieve enum metadata with: proto3.getEnumType(TokenType) +proto3.util.setEnumType(TokenType, "cacti.satp.v02.common.TokenType", [ + { no: 0, name: "TOKEN_TYPE_ERC20" }, + { no: 1, name: "TOKEN_TYPE_ERC721" }, + { no: 2, name: "TOKEN_TYPE_ERC1155" }, + { no: 3, name: "TOKEN_TYPE_NONSTANDARD" }, +]); + /** * TODO: define the common parameters to every protocol message * @@ -559,6 +615,16 @@ export class TransferClaims extends Message { */ amountToBeneficiary = ""; + /** + * @generated from field: repeated cacti.satp.v02.common.PrivacyPolicy processPolicies = 17; + */ + processPolicies: PrivacyPolicy[] = []; + + /** + * @generated from field: repeated cacti.satp.v02.common.PrivacyPolicy mergePolicies = 18; + */ + mergePolicies: PrivacyPolicy[] = []; + constructor(data?: PartialMessage) { super(); proto3.util.initPartial(data, this); @@ -583,6 +649,8 @@ export class TransferClaims extends Message { { 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 */ }, + { no: 17, name: "processPolicies", kind: "message", T: PrivacyPolicy, repeated: true }, + { no: 18, name: "mergePolicies", kind: "message", T: PrivacyPolicy, repeated: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TransferClaims { @@ -633,6 +701,49 @@ export class TransferClaimsFormat extends Message { } } +/** + * @generated from message cacti.satp.v02.common.PrivacyPolicy + */ +export class PrivacyPolicy extends Message { + /** + * @generated from field: string name = 1; + */ + name = ""; + + /** + * @generated from field: repeated string arguments = 2; + */ + arguments: string[] = []; + + constructor(data?: PartialMessage) { + super(); + proto3.util.initPartial(data, this); + } + + static readonly runtime: typeof proto3 = proto3; + static readonly typeName = "cacti.satp.v02.common.PrivacyPolicy"; + static readonly fields: FieldList = proto3.util.newFieldList(() => [ + { no: 1, name: "name", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "arguments", kind: "scalar", T: 9 /* ScalarType.STRING */, repeated: true }, + ]); + + static fromBinary(bytes: Uint8Array, options?: Partial): PrivacyPolicy { + return new PrivacyPolicy().fromBinary(bytes, options); + } + + static fromJson(jsonValue: JsonValue, options?: Partial): PrivacyPolicy { + return new PrivacyPolicy().fromJson(jsonValue, options); + } + + static fromJsonString(jsonString: string, options?: Partial): PrivacyPolicy { + return new PrivacyPolicy().fromJsonString(jsonString, options); + } + + static equals(a: PrivacyPolicy | PlainMessage | undefined, b: PrivacyPolicy | PlainMessage | undefined): boolean { + return proto3.util.equals(PrivacyPolicy, a, b); + } +} + /** * @generated from message cacti.satp.v02.common.Permissions */ @@ -1589,3 +1700,135 @@ export class AssignmentAssertionClaim extends Message } } +/** + * @generated from message cacti.satp.v02.common.WrapAssertionClaim + */ +export class WrapAssertionClaim 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.WrapAssertionClaim"; + 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): WrapAssertionClaim { + return new WrapAssertionClaim().fromBinary(bytes, options); + } + + static fromJson(jsonValue: JsonValue, options?: Partial): WrapAssertionClaim { + return new WrapAssertionClaim().fromJson(jsonValue, options); + } + + static fromJsonString(jsonString: string, options?: Partial): WrapAssertionClaim { + return new WrapAssertionClaim().fromJsonString(jsonString, options); + } + + static equals(a: WrapAssertionClaim | PlainMessage | undefined, b: WrapAssertionClaim | PlainMessage | undefined): boolean { + return proto3.util.equals(WrapAssertionClaim, a, b); + } +} + +/** + * @generated from message cacti.satp.v02.common.Asset + */ +export class Asset extends Message { + /** + * @generated from field: string token_id = 1; + */ + tokenId = ""; + + /** + * @generated from field: cacti.satp.v02.common.TokenType token_type = 2; + */ + tokenType = TokenType.ERC20; + + /** + * @generated from field: string owner = 3; + */ + owner = ""; + + /** + * @generated from field: uint64 amount = 4; + */ + amount = protoInt64.zero; + + /** + * @generated from field: string ontology = 5; + */ + ontology = ""; + + /** + * @generated from field: string contract_name = 7; + */ + contractName = ""; + + /** + * besu + * + * @generated from field: string contract_address = 6; + */ + contractAddress = ""; + + /** + * fabric + * + * @generated from field: string msp_id = 8; + */ + mspId = ""; + + /** + * @generated from field: string channel_name = 9; + */ + channelName = ""; + + constructor(data?: PartialMessage) { + super(); + proto3.util.initPartial(data, this); + } + + static readonly runtime: typeof proto3 = proto3; + static readonly typeName = "cacti.satp.v02.common.Asset"; + static readonly fields: FieldList = proto3.util.newFieldList(() => [ + { no: 1, name: "token_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "token_type", kind: "enum", T: proto3.getEnumType(TokenType) }, + { no: 3, name: "owner", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 4, name: "amount", kind: "scalar", T: 4 /* ScalarType.UINT64 */ }, + { no: 5, name: "ontology", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 7, name: "contract_name", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 6, name: "contract_address", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 8, name: "msp_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 9, name: "channel_name", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + ]); + + static fromBinary(bytes: Uint8Array, options?: Partial): Asset { + return new Asset().fromBinary(bytes, options); + } + + static fromJson(jsonValue: JsonValue, options?: Partial): Asset { + return new Asset().fromJson(jsonValue, options); + } + + static fromJsonString(jsonString: string, options?: Partial): Asset { + return new Asset().fromJsonString(jsonString, options); + } + + static equals(a: Asset | PlainMessage | undefined, b: Asset | PlainMessage | undefined): boolean { + return proto3.util.equals(Asset, a, b); + } +} + diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/common/session_connect.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/common/session_connect.ts index cd60e5eb81..1368f0bc01 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/common/session_connect.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/common/session_connect.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-connect-es v1.3.0 with parameter "target=ts,js_import_style=module" +// @generated by protoc-gen-connect-es v1.4.0 with parameter "target=ts,js_import_style=module" // @generated from file cacti/satp/v02/common/session.proto (package cacti.satp.v02.common, syntax proto3) /* eslint-disable */ // @ts-nocheck 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 39ea829e99..29c9d725f3 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 { AssetProfile, AssignmentAssertionClaim, AssignmentAssertionClaimFormat, BurnAssertionClaim, BurnAssertionClaimFormat, CredentialProfile, History, LockAssertionClaim, LockAssertionClaimFormat, LockType, MintAssertionClaim, MintAssertionClaimFormat, PayloadProfile, Permissions, SignatureAlgorithm, SubsequentCalls, TransferClaims, TransferClaimsFormat } from "./message_pb.js"; +import { Asset, AssetProfile, AssignmentAssertionClaim, AssignmentAssertionClaimFormat, BurnAssertionClaim, BurnAssertionClaimFormat, CredentialProfile, History, LockAssertionClaim, LockAssertionClaimFormat, LockType, MintAssertionClaim, MintAssertionClaimFormat, PayloadProfile, Permissions, SignatureAlgorithm, SubsequentCalls, TransferClaims, TransferClaimsFormat, WrapAssertionClaim } from "./message_pb.js"; /** * @generated from enum cacti.satp.v02.common.ACCEPTANCE @@ -338,10 +338,40 @@ export class SessionData extends Message { assetProfile?: AssetProfile; /** - * @generated from field: string resource_url = 61; + * @generated from field: string sender_contract_ontology = 61; + */ + senderContractOntology = ""; + + /** + * @generated from field: string receiver_contract_ontology = 62; + */ + receiverContractOntology = ""; + + /** + * @generated from field: string resource_url = 63; */ resourceUrl = ""; + /** + * @generated from field: cacti.satp.v02.common.WrapAssertionClaim sender_wrap_assertion_claim = 64; + */ + senderWrapAssertionClaim?: WrapAssertionClaim; + + /** + * @generated from field: cacti.satp.v02.common.WrapAssertionClaim receiver_wrap_assertion_claim = 65; + */ + receiverWrapAssertionClaim?: WrapAssertionClaim; + + /** + * @generated from field: cacti.satp.v02.common.Asset sender_asset = 66; + */ + senderAsset?: Asset; + + /** + * @generated from field: cacti.satp.v02.common.Asset receiver_asset = 67; + */ + receiverAsset?: Asset; + constructor(data?: PartialMessage) { super(); proto3.util.initPartial(data, this); @@ -410,7 +440,13 @@ export class SessionData extends Message { { no: 58, name: "server_transfer_number", kind: "scalar", T: 9 /* ScalarType.STRING */ }, { no: 59, name: "lock_assertion_expiration", kind: "scalar", T: 4 /* ScalarType.UINT64 */ }, { no: 60, name: "asset_profile", kind: "message", T: AssetProfile }, - { no: 61, name: "resource_url", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 61, name: "sender_contract_ontology", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 62, name: "receiver_contract_ontology", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 63, name: "resource_url", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 64, name: "sender_wrap_assertion_claim", kind: "message", T: WrapAssertionClaim }, + { no: 65, name: "receiver_wrap_assertion_claim", kind: "message", T: WrapAssertionClaim }, + { no: 66, name: "sender_asset", kind: "message", T: Asset }, + { no: 67, name: "receiver_asset", kind: "message", T: Asset }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): SessionData { @@ -435,17 +471,22 @@ export class SessionData extends Message { */ export class MessageStagesHashes extends Message { /** - * @generated from field: cacti.satp.v02.common.Stage1Hashes stage1 = 1; + * @generated from field: cacti.satp.v02.common.Stage0Hashes stage0 = 1; + */ + stage0?: Stage0Hashes; + + /** + * @generated from field: cacti.satp.v02.common.Stage1Hashes stage1 = 2; */ stage1?: Stage1Hashes; /** - * @generated from field: cacti.satp.v02.common.Stage2Hashes stage2 = 2; + * @generated from field: cacti.satp.v02.common.Stage2Hashes stage2 = 3; */ stage2?: Stage2Hashes; /** - * @generated from field: cacti.satp.v02.common.Stage3Hashes stage3 = 3; + * @generated from field: cacti.satp.v02.common.Stage3Hashes stage3 = 4; */ stage3?: Stage3Hashes; @@ -457,9 +498,10 @@ export class MessageStagesHashes extends Message { static readonly runtime: typeof proto3 = proto3; static readonly typeName = "cacti.satp.v02.common.MessageStagesHashes"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "stage1", kind: "message", T: Stage1Hashes }, - { no: 2, name: "stage2", kind: "message", T: Stage2Hashes }, - { no: 3, name: "stage3", kind: "message", T: Stage3Hashes }, + { no: 1, name: "stage0", kind: "message", T: Stage0Hashes }, + { no: 2, name: "stage1", kind: "message", T: Stage1Hashes }, + { no: 3, name: "stage2", kind: "message", T: Stage2Hashes }, + { no: 4, name: "stage3", kind: "message", T: Stage3Hashes }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): MessageStagesHashes { @@ -479,6 +521,61 @@ export class MessageStagesHashes extends Message { } } +/** + * @generated from message cacti.satp.v02.common.Stage0Hashes + */ +export class Stage0Hashes extends Message { + /** + * @generated from field: string new_session_request_message_hash = 1; + */ + newSessionRequestMessageHash = ""; + + /** + * @generated from field: string new_session_response_message_hash = 2; + */ + newSessionResponseMessageHash = ""; + + /** + * @generated from field: string pre_satp_transfer_request_message_hash = 3; + */ + preSatpTransferRequestMessageHash = ""; + + /** + * @generated from field: string pre_satp_transfer_response_message_hash = 4; + */ + preSatpTransferResponseMessageHash = ""; + + constructor(data?: PartialMessage) { + super(); + proto3.util.initPartial(data, this); + } + + static readonly runtime: typeof proto3 = proto3; + static readonly typeName = "cacti.satp.v02.common.Stage0Hashes"; + static readonly fields: FieldList = proto3.util.newFieldList(() => [ + { no: 1, name: "new_session_request_message_hash", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "new_session_response_message_hash", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 3, name: "pre_satp_transfer_request_message_hash", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 4, name: "pre_satp_transfer_response_message_hash", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + ]); + + static fromBinary(bytes: Uint8Array, options?: Partial): Stage0Hashes { + return new Stage0Hashes().fromBinary(bytes, options); + } + + static fromJson(jsonValue: JsonValue, options?: Partial): Stage0Hashes { + return new Stage0Hashes().fromJson(jsonValue, options); + } + + static fromJsonString(jsonString: string, options?: Partial): Stage0Hashes { + return new Stage0Hashes().fromJsonString(jsonString, options); + } + + static equals(a: Stage0Hashes | PlainMessage | undefined, b: Stage0Hashes | PlainMessage | undefined): boolean { + return proto3.util.equals(Stage0Hashes, a, b); + } +} + /** * @generated from message cacti.satp.v02.common.Stage1Hashes */ @@ -649,17 +746,22 @@ export class Stage3Hashes extends Message { */ export class MessageStagesSignatures extends Message { /** - * @generated from field: cacti.satp.v02.common.Stage1Signatures stage1 = 1; + * @generated from field: cacti.satp.v02.common.Stage0Signatures stage0 = 1; + */ + stage0?: Stage0Signatures; + + /** + * @generated from field: cacti.satp.v02.common.Stage1Signatures stage1 = 2; */ stage1?: Stage1Signatures; /** - * @generated from field: cacti.satp.v02.common.Stage2Signatures stage2 = 2; + * @generated from field: cacti.satp.v02.common.Stage2Signatures stage2 = 3; */ stage2?: Stage2Signatures; /** - * @generated from field: cacti.satp.v02.common.Stage3Signatures stage3 = 3; + * @generated from field: cacti.satp.v02.common.Stage3Signatures stage3 = 4; */ stage3?: Stage3Signatures; @@ -671,9 +773,10 @@ export class MessageStagesSignatures extends Message { static readonly runtime: typeof proto3 = proto3; static readonly typeName = "cacti.satp.v02.common.MessageStagesSignatures"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "stage1", kind: "message", T: Stage1Signatures }, - { no: 2, name: "stage2", kind: "message", T: Stage2Signatures }, - { no: 3, name: "stage3", kind: "message", T: Stage3Signatures }, + { no: 1, name: "stage0", kind: "message", T: Stage0Signatures }, + { no: 2, name: "stage1", kind: "message", T: Stage1Signatures }, + { no: 3, name: "stage2", kind: "message", T: Stage2Signatures }, + { no: 4, name: "stage3", kind: "message", T: Stage3Signatures }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): MessageStagesSignatures { @@ -693,6 +796,61 @@ export class MessageStagesSignatures extends Message { } } +/** + * @generated from message cacti.satp.v02.common.Stage0Signatures + */ +export class Stage0Signatures extends Message { + /** + * @generated from field: string new_session_request_message_signature = 1; + */ + newSessionRequestMessageSignature = ""; + + /** + * @generated from field: string new_session_response_message_signature = 2; + */ + newSessionResponseMessageSignature = ""; + + /** + * @generated from field: string pre_satp_transfer_request_message_signature = 3; + */ + preSatpTransferRequestMessageSignature = ""; + + /** + * @generated from field: string pre_satp_transfer_response_message_signature = 4; + */ + preSatpTransferResponseMessageSignature = ""; + + constructor(data?: PartialMessage) { + super(); + proto3.util.initPartial(data, this); + } + + static readonly runtime: typeof proto3 = proto3; + static readonly typeName = "cacti.satp.v02.common.Stage0Signatures"; + static readonly fields: FieldList = proto3.util.newFieldList(() => [ + { no: 1, name: "new_session_request_message_signature", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "new_session_response_message_signature", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 3, name: "pre_satp_transfer_request_message_signature", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 4, name: "pre_satp_transfer_response_message_signature", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + ]); + + static fromBinary(bytes: Uint8Array, options?: Partial): Stage0Signatures { + return new Stage0Signatures().fromBinary(bytes, options); + } + + static fromJson(jsonValue: JsonValue, options?: Partial): Stage0Signatures { + return new Stage0Signatures().fromJson(jsonValue, options); + } + + static fromJsonString(jsonString: string, options?: Partial): Stage0Signatures { + return new Stage0Signatures().fromJsonString(jsonString, options); + } + + static equals(a: Stage0Signatures | PlainMessage | undefined, b: Stage0Signatures | PlainMessage | undefined): boolean { + return proto3.util.equals(Stage0Signatures, a, b); + } +} + /** * @generated from message cacti.satp.v02.common.Stage1Signatures */ @@ -863,17 +1021,22 @@ export class Stage3Signatures extends Message { */ export class MessageStagesTimestamps extends Message { /** - * @generated from field: cacti.satp.v02.common.Stage1Timestamps stage1 = 1; + * @generated from field: cacti.satp.v02.common.Stage0Timestamps stage0 = 1; + */ + stage0?: Stage0Timestamps; + + /** + * @generated from field: cacti.satp.v02.common.Stage1Timestamps stage1 = 2; */ stage1?: Stage1Timestamps; /** - * @generated from field: cacti.satp.v02.common.Stage2Timestamps stage2 = 2; + * @generated from field: cacti.satp.v02.common.Stage2Timestamps stage2 = 3; */ stage2?: Stage2Timestamps; /** - * @generated from field: cacti.satp.v02.common.Stage3Timestamps stage3 = 3; + * @generated from field: cacti.satp.v02.common.Stage3Timestamps stage3 = 4; */ stage3?: Stage3Timestamps; @@ -885,9 +1048,10 @@ export class MessageStagesTimestamps extends Message { static readonly runtime: typeof proto3 = proto3; static readonly typeName = "cacti.satp.v02.common.MessageStagesTimestamps"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "stage1", kind: "message", T: Stage1Timestamps }, - { no: 2, name: "stage2", kind: "message", T: Stage2Timestamps }, - { no: 3, name: "stage3", kind: "message", T: Stage3Timestamps }, + { no: 1, name: "stage0", kind: "message", T: Stage0Timestamps }, + { no: 2, name: "stage1", kind: "message", T: Stage1Timestamps }, + { no: 3, name: "stage2", kind: "message", T: Stage2Timestamps }, + { no: 4, name: "stage3", kind: "message", T: Stage3Timestamps }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): MessageStagesTimestamps { @@ -907,6 +1071,61 @@ export class MessageStagesTimestamps extends Message { } } +/** + * @generated from message cacti.satp.v02.common.Stage0Timestamps + */ +export class Stage0Timestamps extends Message { + /** + * @generated from field: string new_session_request_message_timestamp = 1; + */ + newSessionRequestMessageTimestamp = ""; + + /** + * @generated from field: string new_session_response_message_timestamp = 2; + */ + newSessionResponseMessageTimestamp = ""; + + /** + * @generated from field: string pre_satp_transfer_request_message_timestamp = 3; + */ + preSatpTransferRequestMessageTimestamp = ""; + + /** + * @generated from field: string pre_satp_transfer_response_message_timestamp = 4; + */ + preSatpTransferResponseMessageTimestamp = ""; + + constructor(data?: PartialMessage) { + super(); + proto3.util.initPartial(data, this); + } + + static readonly runtime: typeof proto3 = proto3; + static readonly typeName = "cacti.satp.v02.common.Stage0Timestamps"; + static readonly fields: FieldList = proto3.util.newFieldList(() => [ + { no: 1, name: "new_session_request_message_timestamp", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "new_session_response_message_timestamp", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 3, name: "pre_satp_transfer_request_message_timestamp", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 4, name: "pre_satp_transfer_response_message_timestamp", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + ]); + + static fromBinary(bytes: Uint8Array, options?: Partial): Stage0Timestamps { + return new Stage0Timestamps().fromBinary(bytes, options); + } + + static fromJson(jsonValue: JsonValue, options?: Partial): Stage0Timestamps { + return new Stage0Timestamps().fromJson(jsonValue, options); + } + + static fromJsonString(jsonString: string, options?: Partial): Stage0Timestamps { + return new Stage0Timestamps().fromJsonString(jsonString, options); + } + + static equals(a: Stage0Timestamps | PlainMessage | undefined, b: Stage0Timestamps | PlainMessage | undefined): boolean { + return proto3.util.equals(Stage0Timestamps, a, b); + } +} + /** * @generated from message cacti.satp.v02.common.Stage1Timestamps */ diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/crash_recovery_connect.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/crash_recovery_connect.ts index 5989c0b6ba..de4bca5b35 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/crash_recovery_connect.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/crash_recovery_connect.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-connect-es v1.3.0 with parameter "target=ts,js_import_style=module" +// @generated by protoc-gen-connect-es v1.4.0 with parameter "target=ts,js_import_style=module" // @generated from file cacti/satp/v02/crash_recovery.proto (package cacti.satp.v02.crash, syntax proto3) /* eslint-disable */ // @ts-nocheck diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_0_connect.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_0_connect.ts index fe85c7ea67..b9619c447a 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_0_connect.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_0_connect.ts @@ -1,10 +1,10 @@ -// @generated by protoc-gen-connect-es v1.3.0 with parameter "target=ts,js_import_style=module" +// @generated by protoc-gen-connect-es v1.4.0 with parameter "target=ts,js_import_style=module" // @generated from file cacti/satp/v02/stage_0.proto (package cacti.satp.v02, syntax proto3) /* eslint-disable */ // @ts-nocheck -import { Empty, MethodKind } from "@bufbuild/protobuf"; -import { PreTransferCommenceRequestMessage, PreTransferCommenceResponseMessage, PreTransferVerificationAndContextEstablishmentRequest, PreTransferVerificationAndContextEstablishmentResponse, PublicKey } from "./stage_0_pb.js"; +import { CheckRequest, CheckResponse, NewSessionRequest, NewSessionResponse, PreSATPTransferRequest, PreSATPTransferResponse } from "./stage_0_pb.js"; +import { MethodKind } from "@bufbuild/protobuf"; /** * @generated from service cacti.satp.v02.SatpStage0Service @@ -13,34 +13,30 @@ export const SatpStage0Service = { typeName: "cacti.satp.v02.SatpStage0Service", methods: { /** - * util RPCs - * - * @generated from rpc cacti.satp.v02.SatpStage0Service.GetPublicKey + * @generated from rpc cacti.satp.v02.SatpStage0Service.NewSession */ - getPublicKey: { - name: "GetPublicKey", - I: Empty, - O: PublicKey, + newSession: { + name: "NewSession", + I: NewSessionRequest, + O: NewSessionResponse, kind: MethodKind.Unary, }, /** - * step RPCs - * - * @generated from rpc cacti.satp.v02.SatpStage0Service.PreTransferProposalClaims + * @generated from rpc cacti.satp.v02.SatpStage0Service.PreSATPTransfer */ - preTransferProposalClaims: { - name: "PreTransferProposalClaims", - I: PreTransferVerificationAndContextEstablishmentRequest, - O: PreTransferVerificationAndContextEstablishmentResponse, + preSATPTransfer: { + name: "PreSATPTransfer", + I: PreSATPTransferRequest, + O: PreSATPTransferResponse, kind: MethodKind.Unary, }, /** - * @generated from rpc cacti.satp.v02.SatpStage0Service.PreTransferCommence + * @generated from rpc cacti.satp.v02.SatpStage0Service.Check */ - preTransferCommence: { - name: "PreTransferCommence", - I: PreTransferCommenceRequestMessage, - O: PreTransferCommenceResponseMessage, + check: { + name: "Check", + I: CheckRequest, + O: CheckResponse, kind: MethodKind.Unary, }, } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_0_pb.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_0_pb.ts index 5a7a7b0b48..cacc514805 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_0_pb.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_0_pb.ts @@ -5,291 +5,411 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; import { Message, proto3 } from "@bufbuild/protobuf"; -import { CommonSatp, TransferClaims } from "./common/message_pb.js"; +import { Asset, WrapAssertionClaim } from "./common/message_pb.js"; /** - * @generated from message cacti.satp.v02.PrivacyPolicy + * @generated from enum cacti.satp.v02.STATUS */ -export class PrivacyPolicy extends Message { +export enum STATUS { /** - * @generated from field: string name = 1; + * @generated from enum value: STATUS_UNSPECIFIED = 0; */ - name = ""; + STATUS_UNSPECIFIED = 0, /** - * @generated from field: repeated string arguments = 2; + * @generated from enum value: STATUS_ACCEPTED = 1; */ - arguments: string[] = []; + STATUS_ACCEPTED = 1, - constructor(data?: PartialMessage) { + /** + * @generated from enum value: STATUS_REJECTED = 2; + */ + STATUS_REJECTED = 2, +} +// Retrieve enum metadata with: proto3.getEnumType(STATUS) +proto3.util.setEnumType(STATUS, "cacti.satp.v02.STATUS", [ + { no: 0, name: "STATUS_UNSPECIFIED" }, + { no: 1, name: "STATUS_ACCEPTED" }, + { no: 2, name: "STATUS_REJECTED" }, +]); + +/** + * @generated from message cacti.satp.v02.NewSessionRequest + */ +export class NewSessionRequest extends Message { + /** + * @generated from field: string session_id = 1; + */ + sessionId = ""; + + /** + * @generated from field: string context_id = 2; + */ + contextId = ""; + + /** + * @generated from field: string client_transfer_number = 3; + */ + clientTransferNumber = ""; + + /** + * @generated from field: string sender_gateway_network_id = 4; + */ + senderGatewayNetworkId = ""; + + /** + * @generated from field: string recipient_gateway_network_id = 5; + */ + recipientGatewayNetworkId = ""; + + /** + * TODO FIX this change so it gets the gateway ID from channel + * + * @generated from field: string gateway_id = 6; + */ + gatewayId = ""; + + /** + * @generated from field: string client_signature = 7; + */ + clientSignature = ""; + + constructor(data?: PartialMessage) { super(); proto3.util.initPartial(data, this); } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "cacti.satp.v02.PrivacyPolicy"; + static readonly typeName = "cacti.satp.v02.NewSessionRequest"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "name", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 2, name: "arguments", kind: "scalar", T: 9 /* ScalarType.STRING */, repeated: true }, + { no: 1, name: "session_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "context_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 3, name: "client_transfer_number", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 4, name: "sender_gateway_network_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 5, name: "recipient_gateway_network_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 6, name: "gateway_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 7, name: "client_signature", kind: "scalar", T: 9 /* ScalarType.STRING */ }, ]); - static fromBinary(bytes: Uint8Array, options?: Partial): PrivacyPolicy { - return new PrivacyPolicy().fromBinary(bytes, options); + static fromBinary(bytes: Uint8Array, options?: Partial): NewSessionRequest { + return new NewSessionRequest().fromBinary(bytes, options); } - static fromJson(jsonValue: JsonValue, options?: Partial): PrivacyPolicy { - return new PrivacyPolicy().fromJson(jsonValue, options); + static fromJson(jsonValue: JsonValue, options?: Partial): NewSessionRequest { + return new NewSessionRequest().fromJson(jsonValue, options); } - static fromJsonString(jsonString: string, options?: Partial): PrivacyPolicy { - return new PrivacyPolicy().fromJsonString(jsonString, options); + static fromJsonString(jsonString: string, options?: Partial): NewSessionRequest { + return new NewSessionRequest().fromJsonString(jsonString, options); } - static equals(a: PrivacyPolicy | PlainMessage | undefined, b: PrivacyPolicy | PlainMessage | undefined): boolean { - return proto3.util.equals(PrivacyPolicy, a, b); + static equals(a: NewSessionRequest | PlainMessage | undefined, b: NewSessionRequest | PlainMessage | undefined): boolean { + return proto3.util.equals(NewSessionRequest, a, b); } } /** - * @generated from message cacti.satp.v02.PreTransferVerificationAndContextEstablishmentRequest + * @generated from message cacti.satp.v02.NewSessionResponse */ -export class PreTransferVerificationAndContextEstablishmentRequest extends Message { +export class NewSessionResponse extends Message { /** - * @generated from field: cacti.satp.v02.common.CommonSatp context = 1; + * @generated from field: string session_id = 1; */ - context?: CommonSatp; + sessionId = ""; /** - * needed ? - * - * @generated from field: cacti.satp.v02.common.TransferClaims transfer_claims = 2; + * @generated from field: string context_id = 2; */ - transferClaims?: TransferClaims; + contextId = ""; /** - * @generated from field: repeated cacti.satp.v02.PrivacyPolicy processPolicies = 3; + * @generated from field: cacti.satp.v02.STATUS status = 3; */ - processPolicies: PrivacyPolicy[] = []; + status = STATUS.STATUS_UNSPECIFIED; /** - * @generated from field: repeated cacti.satp.v02.PrivacyPolicy mergePolicies = 4; + * @generated from field: string hash_previous_message = 4; */ - mergePolicies: PrivacyPolicy[] = []; + hashPreviousMessage = ""; - constructor(data?: PartialMessage) { + /** + * @generated from field: string sender_gateway_network_id = 5; + */ + senderGatewayNetworkId = ""; + + /** + * @generated from field: string recipient_gateway_network_id = 6; + */ + recipientGatewayNetworkId = ""; + + /** + * @generated from field: string server_signature = 7; + */ + serverSignature = ""; + + constructor(data?: PartialMessage) { super(); proto3.util.initPartial(data, this); } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "cacti.satp.v02.PreTransferVerificationAndContextEstablishmentRequest"; + static readonly typeName = "cacti.satp.v02.NewSessionResponse"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "context", kind: "message", T: CommonSatp }, - { no: 2, name: "transfer_claims", kind: "message", T: TransferClaims }, - { no: 3, name: "processPolicies", kind: "message", T: PrivacyPolicy, repeated: true }, - { no: 4, name: "mergePolicies", kind: "message", T: PrivacyPolicy, repeated: true }, + { no: 1, name: "session_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "context_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 3, name: "status", kind: "enum", T: proto3.getEnumType(STATUS) }, + { no: 4, name: "hash_previous_message", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 5, name: "sender_gateway_network_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 6, name: "recipient_gateway_network_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 7, name: "server_signature", kind: "scalar", T: 9 /* ScalarType.STRING */ }, ]); - static fromBinary(bytes: Uint8Array, options?: Partial): PreTransferVerificationAndContextEstablishmentRequest { - return new PreTransferVerificationAndContextEstablishmentRequest().fromBinary(bytes, options); + static fromBinary(bytes: Uint8Array, options?: Partial): NewSessionResponse { + return new NewSessionResponse().fromBinary(bytes, options); } - static fromJson(jsonValue: JsonValue, options?: Partial): PreTransferVerificationAndContextEstablishmentRequest { - return new PreTransferVerificationAndContextEstablishmentRequest().fromJson(jsonValue, options); + static fromJson(jsonValue: JsonValue, options?: Partial): NewSessionResponse { + return new NewSessionResponse().fromJson(jsonValue, options); } - static fromJsonString(jsonString: string, options?: Partial): PreTransferVerificationAndContextEstablishmentRequest { - return new PreTransferVerificationAndContextEstablishmentRequest().fromJsonString(jsonString, options); + static fromJsonString(jsonString: string, options?: Partial): NewSessionResponse { + return new NewSessionResponse().fromJsonString(jsonString, options); } - static equals(a: PreTransferVerificationAndContextEstablishmentRequest | PlainMessage | undefined, b: PreTransferVerificationAndContextEstablishmentRequest | PlainMessage | undefined): boolean { - return proto3.util.equals(PreTransferVerificationAndContextEstablishmentRequest, a, b); + static equals(a: NewSessionResponse | PlainMessage | undefined, b: NewSessionResponse | PlainMessage | undefined): boolean { + return proto3.util.equals(NewSessionResponse, a, b); } } /** - * TODO - * - * @generated from message cacti.satp.v02.PreTransferVerificationAndContextEstablishmentResponse + * @generated from message cacti.satp.v02.PreSATPTransferRequest */ -export class PreTransferVerificationAndContextEstablishmentResponse extends Message { +export class PreSATPTransferRequest extends Message { + /** + * @generated from field: string session_id = 1; + */ + sessionId = ""; + + /** + * @generated from field: string context_id = 2; + */ + contextId = ""; + /** - * @generated from field: cacti.satp.v02.common.CommonSatp context = 1; + * @generated from field: string client_transfer_number = 3; */ - context?: CommonSatp; + clientTransferNumber = ""; /** - * @generated from field: repeated cacti.satp.v02.PrivacyPolicy processPolicies_counter_proposal = 2; + * @generated from field: string sender_gateway_network_id = 4; */ - processPoliciesCounterProposal: PrivacyPolicy[] = []; + senderGatewayNetworkId = ""; /** - * @generated from field: repeated cacti.satp.v02.PrivacyPolicy mergePolicies_counter_proposal = 3; + * @generated from field: string recipient_gateway_network_id = 5; */ - mergePoliciesCounterProposal: PrivacyPolicy[] = []; + recipientGatewayNetworkId = ""; /** - * @generated from field: string hash_pre_transfer_verification_and_context = 4; + * @generated from field: cacti.satp.v02.common.Asset sender_asset = 6; */ - hashPreTransferVerificationAndContext = ""; + senderAsset?: Asset; /** - * @generated from field: string timestamp = 5; + * @generated from field: cacti.satp.v02.common.Asset receiver_asset = 7; */ - timestamp = ""; + receiverAsset?: Asset; - constructor(data?: PartialMessage) { + /** + * @generated from field: cacti.satp.v02.common.WrapAssertionClaim wrap_assertion_claim = 8; + */ + wrapAssertionClaim?: WrapAssertionClaim; + + /** + * @generated from field: string hash_previous_message = 9; + */ + hashPreviousMessage = ""; + + /** + * @generated from field: string client_signature = 10; + */ + clientSignature = ""; + + constructor(data?: PartialMessage) { super(); proto3.util.initPartial(data, this); } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "cacti.satp.v02.PreTransferVerificationAndContextEstablishmentResponse"; + static readonly typeName = "cacti.satp.v02.PreSATPTransferRequest"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "context", kind: "message", T: CommonSatp }, - { no: 2, name: "processPolicies_counter_proposal", kind: "message", T: PrivacyPolicy, repeated: true }, - { no: 3, name: "mergePolicies_counter_proposal", kind: "message", T: PrivacyPolicy, repeated: true }, - { no: 4, name: "hash_pre_transfer_verification_and_context", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 5, name: "timestamp", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 1, name: "session_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "context_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 3, name: "client_transfer_number", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 4, name: "sender_gateway_network_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 5, name: "recipient_gateway_network_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 6, name: "sender_asset", kind: "message", T: Asset }, + { no: 7, name: "receiver_asset", kind: "message", T: Asset }, + { no: 8, name: "wrap_assertion_claim", kind: "message", T: WrapAssertionClaim }, + { no: 9, name: "hash_previous_message", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 10, name: "client_signature", kind: "scalar", T: 9 /* ScalarType.STRING */ }, ]); - static fromBinary(bytes: Uint8Array, options?: Partial): PreTransferVerificationAndContextEstablishmentResponse { - return new PreTransferVerificationAndContextEstablishmentResponse().fromBinary(bytes, options); + static fromBinary(bytes: Uint8Array, options?: Partial): PreSATPTransferRequest { + return new PreSATPTransferRequest().fromBinary(bytes, options); } - static fromJson(jsonValue: JsonValue, options?: Partial): PreTransferVerificationAndContextEstablishmentResponse { - return new PreTransferVerificationAndContextEstablishmentResponse().fromJson(jsonValue, options); + static fromJson(jsonValue: JsonValue, options?: Partial): PreSATPTransferRequest { + return new PreSATPTransferRequest().fromJson(jsonValue, options); } - static fromJsonString(jsonString: string, options?: Partial): PreTransferVerificationAndContextEstablishmentResponse { - return new PreTransferVerificationAndContextEstablishmentResponse().fromJsonString(jsonString, options); + static fromJsonString(jsonString: string, options?: Partial): PreSATPTransferRequest { + return new PreSATPTransferRequest().fromJsonString(jsonString, options); } - static equals(a: PreTransferVerificationAndContextEstablishmentResponse | PlainMessage | undefined, b: PreTransferVerificationAndContextEstablishmentResponse | PlainMessage | undefined): boolean { - return proto3.util.equals(PreTransferVerificationAndContextEstablishmentResponse, a, b); + static equals(a: PreSATPTransferRequest | PlainMessage | undefined, b: PreSATPTransferRequest | PlainMessage | undefined): boolean { + return proto3.util.equals(PreSATPTransferRequest, a, b); } } /** - * @generated from message cacti.satp.v02.PreTransferCommenceRequestMessage + * @generated from message cacti.satp.v02.PreSATPTransferResponse */ -export class PreTransferCommenceRequestMessage extends Message { +export class PreSATPTransferResponse extends Message { /** - * @generated from field: cacti.satp.v02.common.CommonSatp common = 1; + * @generated from field: string session_id = 1; */ - common?: CommonSatp; + sessionId = ""; /** - * @generated from field: string hash_pre_transfer_verification_and_context = 2; + * @generated from field: string context_id = 2; */ - hashPreTransferVerificationAndContext = ""; + contextId = ""; /** - * @generated from field: string client_transfer_number = 3; + * @generated from field: cacti.satp.v02.common.WrapAssertionClaim wrap_assertion_claim = 3; */ - clientTransferNumber = ""; + wrapAssertionClaim?: WrapAssertionClaim; - constructor(data?: PartialMessage) { + /** + * @generated from field: string hash_previous_message = 4; + */ + hashPreviousMessage = ""; + + /** + * @generated from field: string recipient_token_id = 5; + */ + recipientTokenId = ""; + + /** + * @generated from field: string server_signature = 6; + */ + serverSignature = ""; + + constructor(data?: PartialMessage) { super(); proto3.util.initPartial(data, this); } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "cacti.satp.v02.PreTransferCommenceRequestMessage"; + static readonly typeName = "cacti.satp.v02.PreSATPTransferResponse"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "common", kind: "message", T: CommonSatp }, - { no: 2, name: "hash_pre_transfer_verification_and_context", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 3, name: "client_transfer_number", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 1, name: "session_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "context_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 3, name: "wrap_assertion_claim", kind: "message", T: WrapAssertionClaim }, + { no: 4, name: "hash_previous_message", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 5, name: "recipient_token_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 6, name: "server_signature", kind: "scalar", T: 9 /* ScalarType.STRING */ }, ]); - static fromBinary(bytes: Uint8Array, options?: Partial): PreTransferCommenceRequestMessage { - return new PreTransferCommenceRequestMessage().fromBinary(bytes, options); + static fromBinary(bytes: Uint8Array, options?: Partial): PreSATPTransferResponse { + return new PreSATPTransferResponse().fromBinary(bytes, options); } - static fromJson(jsonValue: JsonValue, options?: Partial): PreTransferCommenceRequestMessage { - return new PreTransferCommenceRequestMessage().fromJson(jsonValue, options); + static fromJson(jsonValue: JsonValue, options?: Partial): PreSATPTransferResponse { + return new PreSATPTransferResponse().fromJson(jsonValue, options); } - static fromJsonString(jsonString: string, options?: Partial): PreTransferCommenceRequestMessage { - return new PreTransferCommenceRequestMessage().fromJsonString(jsonString, options); + static fromJsonString(jsonString: string, options?: Partial): PreSATPTransferResponse { + return new PreSATPTransferResponse().fromJsonString(jsonString, options); } - static equals(a: PreTransferCommenceRequestMessage | PlainMessage | undefined, b: PreTransferCommenceRequestMessage | PlainMessage | undefined): boolean { - return proto3.util.equals(PreTransferCommenceRequestMessage, a, b); + static equals(a: PreSATPTransferResponse | PlainMessage | undefined, b: PreSATPTransferResponse | PlainMessage | undefined): boolean { + return proto3.util.equals(PreSATPTransferResponse, a, b); } } /** - * @generated from message cacti.satp.v02.PreTransferCommenceResponseMessage + * @generated from message cacti.satp.v02.CheckRequest */ -export class PreTransferCommenceResponseMessage extends Message { +export class CheckRequest extends Message { /** - * @generated from field: cacti.satp.v02.common.CommonSatp common = 1; + * @generated from field: string check = 1; */ - common?: CommonSatp; + check = ""; - constructor(data?: PartialMessage) { + constructor(data?: PartialMessage) { super(); proto3.util.initPartial(data, this); } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "cacti.satp.v02.PreTransferCommenceResponseMessage"; + static readonly typeName = "cacti.satp.v02.CheckRequest"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "common", kind: "message", T: CommonSatp }, + { no: 1, name: "check", kind: "scalar", T: 9 /* ScalarType.STRING */ }, ]); - static fromBinary(bytes: Uint8Array, options?: Partial): PreTransferCommenceResponseMessage { - return new PreTransferCommenceResponseMessage().fromBinary(bytes, options); + static fromBinary(bytes: Uint8Array, options?: Partial): CheckRequest { + return new CheckRequest().fromBinary(bytes, options); } - static fromJson(jsonValue: JsonValue, options?: Partial): PreTransferCommenceResponseMessage { - return new PreTransferCommenceResponseMessage().fromJson(jsonValue, options); + static fromJson(jsonValue: JsonValue, options?: Partial): CheckRequest { + return new CheckRequest().fromJson(jsonValue, options); } - static fromJsonString(jsonString: string, options?: Partial): PreTransferCommenceResponseMessage { - return new PreTransferCommenceResponseMessage().fromJsonString(jsonString, options); + static fromJsonString(jsonString: string, options?: Partial): CheckRequest { + return new CheckRequest().fromJsonString(jsonString, options); } - static equals(a: PreTransferCommenceResponseMessage | PlainMessage | undefined, b: PreTransferCommenceResponseMessage | PlainMessage | undefined): boolean { - return proto3.util.equals(PreTransferCommenceResponseMessage, a, b); + static equals(a: CheckRequest | PlainMessage | undefined, b: CheckRequest | PlainMessage | undefined): boolean { + return proto3.util.equals(CheckRequest, a, b); } } /** - * @generated from message cacti.satp.v02.PublicKey + * @generated from message cacti.satp.v02.CheckResponse */ -export class PublicKey extends Message { +export class CheckResponse extends Message { /** - * @generated from field: string public_key = 1; + * @generated from field: string check = 1; */ - publicKey = ""; + check = ""; - constructor(data?: PartialMessage) { + constructor(data?: PartialMessage) { super(); proto3.util.initPartial(data, this); } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "cacti.satp.v02.PublicKey"; + static readonly typeName = "cacti.satp.v02.CheckResponse"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "public_key", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 1, name: "check", kind: "scalar", T: 9 /* ScalarType.STRING */ }, ]); - static fromBinary(bytes: Uint8Array, options?: Partial): PublicKey { - return new PublicKey().fromBinary(bytes, options); + static fromBinary(bytes: Uint8Array, options?: Partial): CheckResponse { + return new CheckResponse().fromBinary(bytes, options); } - static fromJson(jsonValue: JsonValue, options?: Partial): PublicKey { - return new PublicKey().fromJson(jsonValue, options); + static fromJson(jsonValue: JsonValue, options?: Partial): CheckResponse { + return new CheckResponse().fromJson(jsonValue, options); } - static fromJsonString(jsonString: string, options?: Partial): PublicKey { - return new PublicKey().fromJsonString(jsonString, options); + static fromJsonString(jsonString: string, options?: Partial): CheckResponse { + return new CheckResponse().fromJsonString(jsonString, options); } - static equals(a: PublicKey | PlainMessage | undefined, b: PublicKey | PlainMessage | undefined): boolean { - return proto3.util.equals(PublicKey, a, b); + static equals(a: CheckResponse | PlainMessage | undefined, b: CheckResponse | PlainMessage | undefined): boolean { + return proto3.util.equals(CheckResponse, a, b); } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_1_connect.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_1_connect.ts index 342989c8be..0efa818289 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_1_connect.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_1_connect.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-connect-es v1.3.0 with parameter "target=ts,js_import_style=module" +// @generated by protoc-gen-connect-es v1.4.0 with parameter "target=ts,js_import_style=module" // @generated from file cacti/satp/v02/stage_1.proto (package cacti.satp.v02, syntax proto3) /* eslint-disable */ // @ts-nocheck diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_2_connect.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_2_connect.ts index 1acc5ea289..b21c863cea 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_2_connect.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_2_connect.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-connect-es v1.3.0 with parameter "target=ts,js_import_style=module" +// @generated by protoc-gen-connect-es v1.4.0 with parameter "target=ts,js_import_style=module" // @generated from file cacti/satp/v02/stage_2.proto (package cacti.satp.v02, syntax proto3) /* eslint-disable */ // @ts-nocheck diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_3_connect.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_3_connect.ts index d7e1779400..533133fd22 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_3_connect.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/stage_3_connect.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-connect-es v1.3.0 with parameter "target=ts,js_import_style=module" +// @generated by protoc-gen-connect-es v1.4.0 with parameter "target=ts,js_import_style=module" // @generated from file cacti/satp/v02/stage_3.proto (package cacti.satp.v02, syntax proto3) /* eslint-disable */ // @ts-nocheck diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/gol/gateway-orchestrator.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/gol/gateway-orchestrator.ts index 18d59d24fa..468846b0cb 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/gol/gateway-orchestrator.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/gol/gateway-orchestrator.ts @@ -17,6 +17,10 @@ import { Transport as ConnectTransport, } from "@connectrpc/connect"; +import { Express } from "express"; + +import { expressConnectMiddleware } from "@connectrpc/connect-express"; + import { SatpStage0Service } from "../generated/proto/cacti/satp/v02/stage_0_connect"; import { SatpStage1Service } from "../generated/proto/cacti/satp/v02/stage_1_connect"; import { SatpStage2Service } from "../generated/proto/cacti/satp/v02/stage_2_connect"; @@ -25,22 +29,25 @@ import { SatpStage3Service } from "../generated/proto/cacti/satp/v02/stage_3_con export interface IGatewayOrchestratorOptions { logLevel?: LogLevelDesc; localGateway: GatewayIdentity; - counterPartyGateways: GatewayIdentity[] | undefined; + counterPartyGateways?: GatewayIdentity[]; signer: JsObjectSigner; } //import { COREDispatcher, COREDispatcherOptions } from "../core/dispatcher"; import { createPromiseClient } from "@connectrpc/connect"; -import { createConnectTransport } from "@connectrpc/connect-node"; +import { createGrpcWebTransport } from "@connectrpc/connect-node"; import { getGatewaySeeds, resolveGatewayID, } from "../network-identification/resolve-gateway"; +import { SATPHandler, Stage } from "../types/satp-protocol"; export class GatewayOrchestrator { public readonly label = "GatewayOrchestrator"; + private expressServer: Express | undefined; protected localGateway: GatewayIdentity; private counterPartyGateways: Map = new Map(); + private handlers: Map = new Map(); // TODO!: add logic to manage sessions (parallelization, user input, freeze, unfreeze, rollback, recovery) private channels: Map = new Map(); @@ -62,9 +69,11 @@ export class GatewayOrchestrator { this.logger.info( `Initializing gateway connection manager with ${seedGateways} seed gateways`, ); + const allCounterPartyGateways = seedGateways.concat( options.counterPartyGateways ?? [], ); + // populate counterPartyGateways this.counterPartyGateways = new Map( allCounterPartyGateways.map((gateway) => [gateway.id, gateway]), @@ -74,6 +83,11 @@ export class GatewayOrchestrator { `Gateway Connection Manager bootstrapped with ${allCounterPartyGateways.length} gateways`, ); + this.channels.set( + this.localGateway.id, + this.createChannel(this.localGateway), + ); + this.addGateways(allCounterPartyGateways); const numberGatewayChannels = this.connectToCounterPartyGateways(); if (numberGatewayChannels > 0) { @@ -88,6 +102,30 @@ export class GatewayOrchestrator { return this.localGateway; } + public addGOLServer(server: Express): void { + this.expressServer = server; + } + + public startServices(): void { + for (const stage of this.handlers.keys()) { + this.logger.info( + `Setting up routes for stage ${`/${this.handlers.get(stage)!.getStage()}`}`, + ); + this.expressServer!.use( + `/${this.handlers.get(stage)!.getStage()}`, + expressConnectMiddleware({ + routes: this.handlers + .get(stage)! + .setupRouter.bind(this.handlers.get(stage)!), + }), + ); + } + } + + public addHandlers(handlers: Map): void { + this.handlers = handlers; + } + async startupGatewayOrchestrator(): Promise { if (this.counterPartyGateways.values.length === 0) { this.logger.info("No gateways to connect to"); @@ -97,13 +135,27 @@ export class GatewayOrchestrator { } } + public getGatewayIdentity(id: string): GatewayIdentity | undefined { + if (this.localGateway.id === id) { + return this.localGateway; + } else { + return this.counterPartyGateways.get(id); + } + } + + public getCounterPartyGateway(id: string): GatewayIdentity | undefined { + return this.counterPartyGateways.get(id); + } + public getChannel(dlt: SupportedChain): GatewayChannel { const channels = Array.from(this.channels.values()); const channel = channels.find((channel) => { return channel.supportedDLTs.includes(dlt); }); if (!channel) { - throw new Error(`No channel found for DLT ${dlt}`); + throw new Error( + `No channel found for DLT ${dlt} \n available channels: ${JSON.stringify(channels)}`, + ); } return channel; } @@ -114,11 +166,18 @@ export class GatewayOrchestrator { isSelfId(id: string): boolean { return id === this.localGateway.id; } + getSelfId(): string { + return this.localGateway.id; + } isInCounterPartyGateways(id: string): boolean { return this.counterPartyGateways.has(id); } + getCounterPartyGateways(): Map { + return this.counterPartyGateways; + } + isInChannels(id: string): boolean { return this.channels.has(id); } @@ -134,9 +193,8 @@ export class GatewayOrchestrator { filterNewIds(ids: string[]): string[] { return ids.filter((id) => { return ( - !this.isInCounterPartyGateways(id) && - !this.isInChannels(id) && - !this.isSelfId(id) + // !this.isInCounterPartyGateways(id) && + !this.isInChannels(id) && !this.isSelfId(id) ); }); } @@ -156,7 +214,7 @@ export class GatewayOrchestrator { return 0; } - // get gateway identtiies from counterPartyGateways + // get gateway identities from counterPartyGateways const gatewaysToAdd = idsToAdd.map( (id) => this.counterPartyGateways.get(id)!, ); @@ -189,7 +247,9 @@ export class GatewayOrchestrator { clients: clients, supportedDLTs: identity.supportedDLTs, }; - + this.logger.info( + `Created channel to gateway ${identity.id} \n supported DLTs: ${identity.supportedDLTs}`, + ); return channel; } @@ -206,8 +266,50 @@ export class GatewayOrchestrator { identity: GatewayIdentity, ): Map> { // one function for each client type; aggregate in array - const transport = createConnectTransport({ - baseUrl: identity.address + ":" + identity.gatewayGrpcPort, + this.logger.debug( + `Creating clients for gateway ${JSON.stringify(identity)}`, + ); + const transport0 = createGrpcWebTransport({ + baseUrl: + identity.address + + ":" + + identity.gatewayServerPort + + `/${Stage.STAGE0}`, + httpVersion: "1.1", + }); + + this.logger.debug( + "Transport:" + + identity.address + + ":" + + identity.gatewayServerPort + + `/${Stage.STAGE0}`, + ); + + const transport1 = createGrpcWebTransport({ + baseUrl: + identity.address + + ":" + + identity.gatewayServerPort + + `/${Stage.STAGE1}`, + httpVersion: "1.1", + }); + + const transport2 = createGrpcWebTransport({ + baseUrl: + identity.address + + ":" + + identity.gatewayServerPort + + `/${Stage.STAGE2}`, + httpVersion: "1.1", + }); + + const transport3 = createGrpcWebTransport({ + baseUrl: + identity.address + + ":" + + identity.gatewayServerPort + + `/${Stage.STAGE3}`, httpVersion: "1.1", }); @@ -216,10 +318,10 @@ export class GatewayOrchestrator { PromiseConnectClient > = new Map(); - clients.set("0", this.createStage0ServiceClient(transport)); - clients.set("1", this.createStage1ServiceClient(transport)); - clients.set("2", this.createStage2ServiceClient(transport)); - clients.set("3", this.createStage3ServiceClient(transport)); + clients.set("0", this.createStage0ServiceClient(transport0)); + clients.set("1", this.createStage1ServiceClient(transport1)); + clients.set("2", this.createStage2ServiceClient(transport2)); + clients.set("3", this.createStage3ServiceClient(transport3)); // todo perform healthcheck on startup; should be in stage 0 return clients; 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 index 9ca79aafd9..d4221ccb96 100644 --- 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 @@ -57,8 +57,6 @@ export class SATPBridgesManager { throw new Error(`Unsupported network: ${bridgeConfig.network}`); } - this.log.debug(`Creating 2 ${SATPBridgesManager.CLASS_NAME}...`); - const config: SATPBridgeConfig = { network: bridge, logLevel: this.level, 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 02ea361a6f..4b96bebbb5 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 @@ -13,7 +13,7 @@ import { Stage1ServerService } from "../core/stage-services/server/stage1-server 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 { GatewayIdentity, SupportedChain } from "../core/types"; import { Stage0ClientService } from "../core/stage-services/client/stage0-client-service"; import { Stage1ClientService } from "../core/stage-services/client/stage1-client-service"; import { Stage2ClientService } from "../core/stage-services/client/stage2-client-service"; @@ -24,7 +24,6 @@ import { SATPServiceType, SATPHandlerOptions, SATPHandlerType, - ISATPHandler, SATPHandlerInstance, } from "../types/satp-protocol"; import { @@ -43,16 +42,16 @@ import { SatpStage2Service } from "../generated/proto/cacti/satp/v02/stage_2_con import { SatpStage3Service } from "../generated/proto/cacti/satp/v02/stage_3_connect"; import { PromiseClient as PromiseConnectClient } from "@connectrpc/connect"; import { SatpStage0Service } from "../generated/proto/cacti/satp/v02/stage_0_connect"; -import { Empty } from "@bufbuild/protobuf"; export interface ISATPManagerOptions { logLevel?: LogLevelDesc; instanceId: string; sessions?: Map; signer: JsObjectSigner; + pubKey: string; supportedDLTs: SupportedChain[]; bridgeManager: SATPBridgesManager; - orquestrator: GatewayOrchestrator; + orchestrator: GatewayOrchestrator; } export class SATPManager { @@ -69,10 +68,13 @@ export class SATPManager { Map > = new Map(); private readonly satpHandlers: Map = new Map(); + private _pubKey: string; private readonly bridgesManager: SATPBridgesManager; - private readonly orquestrator: GatewayOrchestrator; + private readonly orchestrator: GatewayOrchestrator; + + private gatewaysPubKeys: Map = new Map(); constructor(public readonly options: ISATPManagerOptions) { const fnTag = `${SATPManager.CLASS_NAME}#constructor()`; @@ -86,7 +88,9 @@ export class SATPManager { this.supportedDLTs = options.supportedDLTs; this.signer = options.signer; this.bridgesManager = options.bridgeManager; - this.orquestrator = options.orquestrator; + this.orchestrator = options.orchestrator; + this._pubKey = options.pubKey; + this.loadPubKeys(this.orchestrator.getCounterPartyGateways()); this.sessions = options.sessions || new Map(); const handlersClasses = [ @@ -125,6 +129,12 @@ export class SATPManager { ); this.initializeHandlers(handlersClasses, handlersOptions); + + this.orchestrator.addHandlers(this.satpHandlers); + } + + public get pubKey(): string { + return this._pubKey; } public getServiceByStage( @@ -177,10 +187,12 @@ export class SATPManager { sessionId?: string, contextID?: string, ): SATPSession { - let session: SATPSession; if (!sessionId) { + //TODO maybe compare to "" + if (!contextID) { + throw new Error("ContextID missing"); + } return this.createNewSession(contextID || "MOCK_CONTEXT_ID"); - return session; } else { const existingSession = this.sessions.get(sessionId); return existingSession || this.createNewSession("MOCK_CONTEXT_ID"); @@ -190,7 +202,7 @@ export class SATPManager { private createNewSession(contextID: string): SATPSession { const session = new SATPSession({ contextID: contextID, - server: true, //todo implement the separation of server and client + server: false, client: true, }); this.sessions?.set(session.getSessionId(), session); @@ -285,6 +297,8 @@ export class SATPManager { serverService: serverService, clientService: clientService, supportedDLTs: this.supportedDLTs, + pubkeys: this.gatewaysPubKeys, + gatewayId: this.orchestrator.ourGateway.id, stage: serviceIndex, loggerOptions: { level: level, @@ -332,7 +346,7 @@ export class SATPManager { } public async initiateTransfer(session: SATPSession): Promise { - const fnTag = `${SATPManager.CLASS_NAME}#initializeHandlers()`; + const fnTag = `${SATPManager.CLASS_NAME}#initiateTransfer()`; this.logger.info(`${fnTag}, Initiating Transfer`); this.logger.debug( `SessionData: ${JSON.stringify(session.getClientSessionData())}`, @@ -341,8 +355,8 @@ export class SATPManager { if (!session.getClientSessionData()) { throw new Error(`${fnTag}, Session not found`); } - - const channel = this.orquestrator.getChannel( + //maybe get a suitable gateway first. + const channel = this.orchestrator.getChannel( session.getClientSessionData() ?.recipientGatewayNetworkId as SupportedChain, ); @@ -350,29 +364,66 @@ export class SATPManager { if (!channel) { throw new Error(`${fnTag}, Channel not found`); } - + const counterGatewayID = this.orchestrator.getGatewayIdentity( + channel.toGatewayID, + ); + if (!counterGatewayID) { + throw new Error(`${fnTag}, counterparty gateway ID not found`); + } const sessionData: SessionData = session.getClientSessionData() as SessionData; + sessionData.receiverGatewayOwnerId = channel.toGatewayID; + const clientSatpStage0: PromiseConnectClient = channel.clients.get("0") as PromiseConnectClient< typeof SatpStage0Service >; + + if (!clientSatpStage0) { + throw new Error(`${fnTag}, Failed to get clientSatpStage0`); + } + const clientSatpStage1: PromiseConnectClient = channel.clients.get("1") as PromiseConnectClient< typeof SatpStage1Service >; + + if (!clientSatpStage1) { + throw new Error(`${fnTag}, Failed to get clientSatpStage1`); + } + const clientSatpStage2: PromiseConnectClient = channel.clients.get("2") as PromiseConnectClient< typeof SatpStage2Service >; + + if (!clientSatpStage2) { + throw new Error(`${fnTag}, Failed to get clientSatpStage2`); + } const clientSatpStage3: PromiseConnectClient = channel.clients.get("3") as PromiseConnectClient< typeof SatpStage3Service >; - const serverGatewayPubkey = (await clientSatpStage0.getPublicKey(Empty)) - .publicKey; + if (!clientSatpStage3) { + throw new Error(`${fnTag}, Failed to get clientSatpStage3`); + } + + const check = await clientSatpStage0.check({ check: "check" }); + + this.logger.info(`${fnTag}, check: ${JSON.stringify(check)}`); + + if (!check) { + throw new Error(`${fnTag}, Failed to check`); + } + + if (check.check !== "check") { + throw new Error(`${fnTag}, check failed`); + } + + //TODO: implement GetPubKey service + const serverGatewayPubkey = counterGatewayID.pubKey; if (!serverGatewayPubkey) { throw new Error(`${fnTag}, Failed to get serverGatewayPubkey`); @@ -380,11 +431,46 @@ export class SATPManager { sessionData.serverGatewayPubkey = serverGatewayPubkey; - this.logger.info(`${fnTag}, Stage 0`); + const newSessionRequest = await ( + this.getSATPHandler(SATPHandlerType.STAGE0) as Stage0SATPHandler + ).NewSessionRequest(session.getSessionId()); + + if (!newSessionRequest) { + throw new Error(`${fnTag}, Failed to create NewSessionRequest`); + } + + const responseNewSession = + await clientSatpStage0.newSession(newSessionRequest); + + this.logger.info( + `${fnTag}, responseNewSession: ${JSON.stringify(responseNewSession)}`, + ); + + if (!responseNewSession) { + throw new Error(`${fnTag}, Failed to create NewSessionRequest`); + } + + const requestPreSATPTransfer = await ( + this.getSATPHandler(SATPHandlerType.STAGE0) as Stage0SATPHandler + ).PreSATPTransferRequest(responseNewSession, session.getSessionId()); + + if (!requestPreSATPTransfer) { + throw new Error(`${fnTag}, Failed to create PreSATPTransferRequest`); + } + + const responsePreSATPTransfer = await clientSatpStage0.preSATPTransfer( + requestPreSATPTransfer, + ); + + this.logger.info( + `${fnTag}, responsePreSATPTransfer: ${JSON.stringify(responsePreSATPTransfer)}`, + ); + + this.logger.info(`${fnTag}, Stage 0 completed`); const requestTransferProposal = await ( this.getSATPHandler(SATPHandlerType.STAGE1) as Stage1SATPHandler - ).TransferProposalRequest(session.getSessionId()); + ).TransferProposalRequest(session.getSessionId(), responsePreSATPTransfer); if (!requestTransferProposal) { throw new Error(`${fnTag}, Failed to create TransferProposalRequest`); @@ -450,7 +536,7 @@ export class SATPManager { const requestCommitFinalAssertion = await ( this.getSATPHandler(SATPHandlerType.STAGE3) as Stage3SATPHandler - ).CommitFinalAssertionRequest(responseLockAssertion); + ).CommitFinalAssertionRequest(responseCommitPreparation); if (!requestCommitFinalAssertion) { throw new Error(`${fnTag}, Failed to create CommitFinalAssertionRequest`); @@ -479,4 +565,16 @@ export class SATPManager { this.logger.info(`${fnTag}, Stage 3 completed`); } + + private loadPubKeys(gateways: Map): void { + gateways.forEach((gateway) => { + if (gateway.pubKey) { + this.gatewaysPubKeys.set(gateway.id, gateway.pubKey); + } + }); + this.gatewaysPubKeys.set( + this.orchestrator.getSelfId(), + this.orchestrator.ourGateway.pubKey!, + ); + } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/network-identification/resolve-gateway.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/network-identification/resolve-gateway.ts index f7df2e1659..72ecfcdc08 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/network-identification/resolve-gateway.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/network-identification/resolve-gateway.ts @@ -50,37 +50,37 @@ export function getGatewaySeeds(logger: Logger): GatewayIdentity[] { const fnTag = `#getGatewaySeeds()`; logger.trace(`Entering ${fnTag}`); - const mockGatewayIdentity: GatewayIdentity[] = [ - { - id: "1", - name: "Gateway1", - version: [ - { - Core: "1.0", - Architecture: "1.0", - Crash: "1.0", - }, - ], - supportedDLTs: [SupportedChain.FABRIC, SupportedChain.BESU], - proofID: "mockProofID1", - gatewayServerPort: 3011, - address: "http://localhost", - }, - { - id: "2", - name: "Gateway2", - version: [ - { - Core: "1.0", - Architecture: "1.0", - Crash: "1.0", - }, - ], - supportedDLTs: [SupportedChain.FABRIC, SupportedChain.BESU], - proofID: "mockProofID1", - gatewayServerPort: 3014, - address: "http://localhost", - }, - ]; - return mockGatewayIdentity; + // const mockGatewayIdentity: GatewayIdentity[] = [ + // { + // id: "1", + // name: "Gateway1", + // version: [ + // { + // Core: "1.0", + // Architecture: "1.0", + // Crash: "1.0", + // }, + // ], + // supportedDLTs: [SupportedChain.FABRIC, SupportedChain.BESU], + // proofID: "mockProofID1", + // gatewayServerPort: 3011, + // address: "http://localhost", + // }, + // { + // id: "2", + // name: "Gateway2", + // version: [ + // { + // Core: "1.0", + // Architecture: "1.0", + // Crash: "1.0", + // }, + // ], + // supportedDLTs: [SupportedChain.FABRIC, SupportedChain.BESU], + // proofID: "mockProofID1", + // gatewayServerPort: 3014, + // address: "http://localhost", + // }, + // ]; + return []; } 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 c0b71257dd..f3a608d1f7 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 @@ -79,6 +79,8 @@ export class SATPGateway implements IPluginWebService, ICactusPlugin { private BLOApplication?: Express; private BLOServer?: http.Server; private BLODispatcher?: BLODispatcher; + private GOLApplication?: Express; + private GOLServer?: http.Server; private readonly OAS: JsonObject; public OAPIServerEnabled: boolean = false; @@ -126,9 +128,15 @@ export class SATPGateway implements IPluginWebService, ICactusPlugin { const bridgesManagerOptions: ISATPBridgesOptions = { logLevel: this.config.logLevel, supportedDLTs: this.config.gid!.supportedDLTs, - networks: [], //todo add networks + networks: options.bridgesConfig ? options.bridgesConfig : [], }; + this.bridgesManager = new SATPBridgesManager(bridgesManagerOptions); + + if (!this.bridgesManager) { + throw new Error("BridgesManager is not defined"); + } + if (this.config.gid) { this.logger.info( "Initializing gateway connection manager with seed gateways", @@ -140,12 +148,6 @@ 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, @@ -154,6 +156,7 @@ export class SATPGateway implements IPluginWebService, ICactusPlugin { orchestrator: this.gatewayOrchestrator, signer: this.signer, bridgesManager: this.bridgesManager, + pubKey: this.pubKey, }; this.supportedDltIDs = this.config.gid!.supportedDLTs; @@ -182,6 +185,11 @@ export class SATPGateway implements IPluginWebService, ICactusPlugin { return `@hyperledger/cactus-plugin-satp-hermes`; } + //for testing + public getBLODispatcher(): BLODispatcher | undefined { + return this.BLODispatcher; + } + public async onPluginInit(): Promise { const fnTag = `${this.className}#onPluginInit()`; this.logger.trace(`Entering ${fnTag}`); @@ -252,6 +260,7 @@ export class SATPGateway implements IPluginWebService, ICactusPlugin { if (!pluginOptions.gid) { pluginOptions.gid = { id: id, + pubKey: bufArray2HexStr(pluginOptions.keyPair.publicKey), name: id, version: [ { @@ -275,6 +284,12 @@ export class SATPGateway implements IPluginWebService, ICactusPlugin { pluginOptions.gid.name = id; } + if (!pluginOptions.gid.pubKey) { + pluginOptions.gid.pubKey = bufArray2HexStr( + pluginOptions.keyPair.publicKey, + ); + } + if (!pluginOptions.gid.version) { pluginOptions.gid.version = [ { @@ -326,7 +341,7 @@ export class SATPGateway implements IPluginWebService, ICactusPlugin { /** * Startup Methods * ---------------- - * This section includes methods responsible for starting up the server and its associated services independently of the existance of a Hyperledger Cacti Node. + * This section includes methods responsible for starting up the server and its associated services independently of the existence of a Hyperledger Cacti Node. * It ensures that both the GatewayServer and BLOServer are initiated concurrently for efficient launch. */ public async startup(): Promise { @@ -334,6 +349,8 @@ export class SATPGateway implements IPluginWebService, ICactusPlugin { this.logger.trace(`Entering ${fnTag}`); await Promise.all([this.startupBLOServer(), this.setupOpenAPIServer()]); + + await Promise.all([this.startupGOLServer()]); } protected async startupBLOServer(): Promise { @@ -378,6 +395,40 @@ export class SATPGateway implements IPluginWebService, ICactusPlugin { }); } + protected async startupGOLServer(): Promise { + // starts GOL + const fnTag = `${this.className}#startupGOLServer()`; + this.logger.trace(`Entering ${fnTag}`); + this.logger.info("Starting GOL server"); + + const port = + this.options.gid?.gatewayServerPort ?? DEFAULT_PORT_GATEWAY_SERVER; + + return new Promise(async (resolve, reject) => { + if (!this.GOLServer) { + this.GOLApplication = express(); + + this.gatewayOrchestrator.addGOLServer(this.GOLApplication!); + this.gatewayOrchestrator.startServices(); + + this.GOLServer = http.createServer(this.GOLApplication); + + this.GOLServer.listen(port, () => { + this.logger.info(`GOL server started and listening on port ${port}`); + resolve(); + }); + + this.GOLServer.on("error", (error) => { + this.logger.error(`GOL server failed to start: ${error}`); + reject(error); + }); + } else { + this.logger.warn("GOL Server already running."); + resolve(); + } + }); + } + public setupOpenAPIServer(): void { if (!this.OAPIServerEnabled) { this.logger.debug("OpenAPI server is disabled"); @@ -401,6 +452,7 @@ export class SATPGateway implements IPluginWebService, ICactusPlugin { swaggerUi.setup(this.OAS) as express.RequestHandler, ); } + /** * Gateway Connection Methods * -------------------------- 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 index 948da87f4a..283f7b23c3 100644 --- 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 @@ -9,6 +9,8 @@ import { Web3SigningCredential, } from "@hyperledger/cactus-plugin-ledger-connector-besu"; import { IPluginBungeeHermesOptions } from "@hyperledger/cactus-plugin-bungee-hermes"; +import { BesuAsset } from "../core/stage-services/satp-bridge/types/besu-asset"; +import { FabricAsset } from "../core/stage-services/satp-bridge/types/fabric-asset"; // inject gateway, get connectors export type SATPLedgerConnector = string; @@ -24,6 +26,7 @@ export interface FabricConfig extends NetworkConfig { contractName: string; options: IPluginLedgerConnectorFabricOptions; bungeeOptions: IPluginBungeeHermesOptions; + fabricAssets?: FabricAsset[]; } export interface BesuConfig extends NetworkConfig { keychainId: string; @@ -33,6 +36,7 @@ export interface BesuConfig extends NetworkConfig { gas: number; options: IPluginLedgerConnectorBesuOptions; bungeeOptions: IPluginBungeeHermesOptions; + besuAssets?: BesuAsset[]; } export interface TransactionResponse { 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 86b4cd45d9..624a7326c1 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 @@ -26,6 +26,13 @@ export enum SATPHandlerType { STAGE3 = "stage-3-handler", } +export enum Stage { + STAGE0 = "stage-0", + STAGE1 = "stage-1", + STAGE2 = "stage-2", + STAGE3 = "stage-3", +} + export interface SATPServiceStatic { new (options: ISATPServiceOptions): SATPService; readonly SERVICE_TYPE: SATPServiceType; @@ -51,6 +58,7 @@ export interface SATPHandler { setupRouter(router: ConnectRouter): void; getHandlerIdentifier(): SATPHandlerType; getHandlerSessions(): string[]; + getStage(): string; } export interface SATPHandlerOptions { @@ -58,6 +66,8 @@ export interface SATPHandlerOptions { serverService: SATPService; clientService: SATPService; supportedDLTs: SupportedChain[]; + pubkeys: Map; + gatewayId: string; loggerOptions: ILoggerOptions; stage: string; } diff --git a/packages/cactus-plugin-satp-hermes/src/main/yml/bol/openapi-blo-bundled.yml b/packages/cactus-plugin-satp-hermes/src/main/yml/bol/openapi-blo-bundled.yml index ae3f997a2d..6b67993f6e 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/yml/bol/openapi-blo-bundled.yml +++ b/packages/cactus-plugin-satp-hermes/src/main/yml/bol/openapi-blo-bundled.yml @@ -54,6 +54,14 @@ paths: required: - contextID - mode + - fromDLTNetworkID + - toDLTNetworkID + - fromAmount + - toAmount + - beneficiaryPubkey + - originatorPubkey + - sourceAsset + - destinyAsset properties: contextID: type: string @@ -77,15 +85,53 @@ paths: fromAmount: type: string example: '100' - fromToken: - type: string - example: TOKEN1 toAmount: type: string example: '95' - toToken: + beneficiaryPubkey: + type: string + originatorPubkey: type: string - example: TOKEN2 + sourceAsset: + description: An asset + type: object + required: + - owner + - ontology + - contractName + properties: + owner: + type: string + ontology: + type: string + contractName: + type: string + contractAddress: + type: string + mspId: + type: string + channelName: + type: string + destinyAsset: + description: An asset + type: object + required: + - owner + - ontology + - contractName + properties: + owner: + type: string + ontology: + type: string + contractName: + type: string + contractAddress: + type: string + mspId: + type: string + channelName: + type: string required: true responses: '200': @@ -2037,12 +2083,40 @@ components: type: string description: The ID of the session for which the status is being requested. example: 123e4567-e89b-12d3-a456-426614174000 + Asset: + description: An asset + type: object + required: + - owner + - ontology + - contractName + properties: + owner: + type: string + ontology: + type: string + contractName: + type: string + contractAddress: + type: string + mspId: + type: string + channelName: + type: string TransactRequest: description: 'Request schema for initiating a transaction. Includes details such as the transaction context, mode (data or transfer), payload, and information about the source and destination DLT networks.' type: object required: - contextID - mode + - fromDLTNetworkID + - toDLTNetworkID + - fromAmount + - toAmount + - beneficiaryPubkey + - originatorPubkey + - sourceAsset + - destinyAsset properties: contextID: type: string @@ -2066,15 +2140,53 @@ components: fromAmount: type: string example: '100' - fromToken: - type: string - example: TOKEN1 toAmount: type: string example: '95' - toToken: + beneficiaryPubkey: + type: string + originatorPubkey: type: string - example: TOKEN2 + sourceAsset: + description: An asset + type: object + required: + - owner + - ontology + - contractName + properties: + owner: + type: string + ontology: + type: string + contractName: + type: string + contractAddress: + type: string + mspId: + type: string + channelName: + type: string + destinyAsset: + description: An asset + type: object + required: + - owner + - ontology + - contractName + properties: + owner: + type: string + ontology: + type: string + contractName: + type: string + contractAddress: + type: string + mspId: + type: string + channelName: + type: string TransactResponse: description: Response schema for a transaction request. Includes the session ID and the current status of the transaction. type: object diff --git a/packages/cactus-plugin-satp-hermes/src/main/yml/bol/schemas.yml b/packages/cactus-plugin-satp-hermes/src/main/yml/bol/schemas.yml index ab79555139..029b95f124 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/yml/bol/schemas.yml +++ b/packages/cactus-plugin-satp-hermes/src/main/yml/bol/schemas.yml @@ -193,12 +193,40 @@ StatusRequest: type: string description: The ID of the session for which the status is being requested. example: "123e4567-e89b-12d3-a456-426614174000" +Asset: + description: "An asset" + type: object + required: + - owner + - ontology + - contractName + properties: + owner: + type: string + ontology: + type: string + contractName: + type: string + contractAddress: + type: string + mspId: + type: string + channelName: + type: string TransactRequest: description: "Request schema for initiating a transaction. Includes details such as the transaction context, mode (data or transfer), payload, and information about the source and destination DLT networks." type: object required: - contextID - mode + - fromDLTNetworkID + - toDLTNetworkID + - fromAmount + - toAmount + - beneficiaryPubkey + - originatorPubkey + - sourceAsset + - destinyAsset properties: contextID: type: string @@ -222,15 +250,18 @@ TransactRequest: fromAmount: type: string example: "100" - fromToken: - type: string - example: "TOKEN1" toAmount: type: string example: "95" - toToken: + beneficiaryPubkey: + type: string + originatorPubkey: type: string - example: "TOKEN2" + sourceAsset: + $ref: ./schemas.yml#/Asset + destinyAsset: + $ref: ./schemas.yml#/Asset + TransactResponse: description: "Response schema for a transaction request. Includes the session ID and the current status of the transaction." diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-end-to-end-transfer-1-gateway.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-end-to-end-transfer-1-gateway.test.ts new file mode 100644 index 0000000000..75ae8423f3 --- /dev/null +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-end-to-end-transfer-1-gateway.test.ts @@ -0,0 +1,1084 @@ +import "jest-extended"; + +import { + IListenOptions, + LogLevelDesc, + LoggerProvider, + Secp256k1Keys, + Servers, +} from "@hyperledger/cactus-common"; +import { v4 as uuidv4 } from "uuid"; + +import { PluginRegistry } from "@hyperledger/cactus-core"; +import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; +import { + ChainCodeProgrammingLanguage, + Configuration, + DefaultEventHandlerStrategy, + FabricSigningCredential, + FileBase64, + IPluginLedgerConnectorFabricOptions, + PluginLedgerConnectorFabric, + DefaultApi as FabricApi, + FabricContractInvocationType, +} from "@hyperledger/cactus-plugin-ledger-connector-fabric"; +import http, { Server } from "http"; +import fs from "fs-extra"; + +import { + pruneDockerAllIfGithubAction, + Containers, + FabricTestLedgerV1, + BesuTestLedger, + FABRIC_25_LTS_AIO_FABRIC_VERSION, + FABRIC_25_LTS_AIO_IMAGE_VERSION, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, +} from "@hyperledger/cactus-test-tooling"; +import bodyParser from "body-parser"; +import express from "express"; +import { DiscoveryOptions, X509Identity } from "fabric-network"; +import { AddressInfo } from "net"; +import path from "path"; +import { + BesuConfig, + FabricConfig, +} from "../../../main/typescript/types/blockchain-interaction"; +import { IPluginBungeeHermesOptions } from "@hyperledger/cactus-plugin-bungee-hermes"; +import { Account } from "web3-core"; +import { + EthContractInvocationType, + IPluginLedgerConnectorBesuOptions, + PluginLedgerConnectorBesu, + ReceiptType, + Web3SigningCredentialType, +} from "@hyperledger/cactus-plugin-ledger-connector-besu"; +import Web3 from "web3"; +import SATPContract from "../../solidity/generated/satp-erc20.sol/SATPContract.json"; +import SATPWrapperContract from "../../../solidity/generated/satp-wrapper.sol/SATPWrapperContract.json"; +import { + SATPGatewayConfig, + SATPGateway, + PluginFactorySATPGateway, + TransactRequest, + Asset, +} from "../../../main/typescript"; +import { + Address, + GatewayIdentity, + SupportedChain, +} from "../../../main/typescript/core/types"; +import { + IPluginFactoryOptions, + PluginImportType, +} from "@hyperledger/cactus-core-api"; +import FabricSATPInteraction from "../../../test/typescript/fabric/satp-erc20-interact.json"; +import BesuSATPInteraction from "../../solidity/satp-erc20-interact.json"; + +const logLevel: LogLevelDesc = "DEBUG"; +const log = LoggerProvider.getOrCreate({ + level: logLevel, + label: "BUNGEE - Hermes", +}); + +let fabricServer: Server; + +let besuLedger: BesuTestLedger; + +let fabricLedger: FabricTestLedgerV1; +let fabricSigningCredential: FabricSigningCredential; +let bridgeFabricSigningCredential: FabricSigningCredential; +let configFabric: Configuration; +let fabricChannelName: string; + +const FABRIC_ASSET_ID = uuidv4(); + +const BRIDGE_ID = + "x509::/OU=org2/OU=client/OU=department1/CN=bridge::/C=UK/ST=Hampshire/L=Hursley/O=org2.example.com/CN=ca.org2.example.com"; + +let clientId: string; +let fabricConfig: FabricConfig; +let pluginBungeeFabricOptions: IPluginBungeeHermesOptions; + +let erc20TokenContract: string; +let contractNameWrapper: string; + +let rpcApiHttpHost: string; +let rpcApiWsHost: string; +let web3: Web3; +let firstHighNetWorthAccount: string; +let testing_connector: PluginLedgerConnectorBesu; +let besuKeyPair: { privateKey: string }; +let bridgeEthAccount: Account; +let assigneeEthAccount: Account; +const BESU_ASSET_ID = uuidv4(); +let assetContractAddress: string; +let wrapperContractAddress: string; +let satpContractName: string; + +let pluginBungeeBesuOptions: IPluginBungeeHermesOptions; + +let besuConfig: BesuConfig; +let besuOptions: IPluginLedgerConnectorBesuOptions; + +let keychainPlugin1: PluginKeychainMemory; +let keychainPlugin2: PluginKeychainMemory; +let fabricUser: X509Identity; + +let apiClient: FabricApi; + +afterAll(async () => { + await besuLedger.stop(); + await besuLedger.destroy(); + await fabricLedger.stop(); + await fabricLedger.destroy(); + await Servers.shutdown(fabricServer); + + await pruneDockerAllIfGithubAction({ logLevel }) + .then(() => { + log.info("Pruning throw OK"); + }) + .catch(async () => { + await Containers.logDiagnostics({ logLevel }); + fail("Pruning didn't throw OK"); + }); +}); + +beforeAll(async () => { + pruneDockerAllIfGithubAction({ logLevel }) + .then(() => { + log.info("Pruning throw OK"); + }) + .catch(async () => { + await Containers.logDiagnostics({ logLevel }); + fail("Pruning didn't throw OK"); + }); + { + besuLedger = new BesuTestLedger({ + logLevel, + emitContainerLogs: true, + envVars: ["BESU_NETWORK=dev"], + }); + await besuLedger.start(); + + // Fabric ledger connection + const channelId = "mychannel"; + fabricChannelName = channelId; + + fabricLedger = new FabricTestLedgerV1({ + emitContainerLogs: true, + publishAllPorts: true, + imageName: "ghcr.io/hyperledger/cactus-fabric2-all-in-one", + imageVersion: FABRIC_25_LTS_AIO_IMAGE_VERSION, + envVars: new Map([["FABRIC_VERSION", FABRIC_25_LTS_AIO_FABRIC_VERSION]]), + logLevel, + }); + + await fabricLedger.start(); + + log.info("Both Ledgers started successfully"); + } + + { + // setup fabric ledger + const connectionProfile = await fabricLedger.getConnectionProfileOrg1(); + expect(connectionProfile).not.toBeUndefined(); + + const bridgeProfile = await fabricLedger.getConnectionProfileOrgX("org2"); + expect(bridgeProfile).not.toBeUndefined(); + + const enrollAdminOut = await fabricLedger.enrollAdmin(); + const adminWallet = enrollAdminOut[1]; + + const enrollAdminBridgeOut = await fabricLedger.enrollAdminV2({ + organization: "org2", + }); + const bridgeWallet = enrollAdminBridgeOut[1]; + + const [userIdentity] = await fabricLedger.enrollUser(adminWallet); + fabricUser = userIdentity; + const opts = { + enrollmentID: "bridge", + organization: "org2", + wallet: bridgeWallet, + }; + + const [bridgeIdentity] = await fabricLedger.enrollUserV2(opts); + + const sshConfig = await fabricLedger.getSshConfig(); + + log.info("enrolled admin"); + + const keychainInstanceId = uuidv4(); + const keychainId = uuidv4(); + const keychainEntryKey = "user1"; + const keychainEntryValue = JSON.stringify(userIdentity); + + console.log("keychainEntryValue: ", keychainEntryValue); + + const keychainInstanceIdBridge = uuidv4(); + const keychainIdBridge = uuidv4(); + const keychainEntryKeyBridge = "bridge1"; + const keychainEntryValueBridge = JSON.stringify(bridgeIdentity); + + console.log("keychainEntryValue: ", keychainEntryValueBridge); + + const keychainPlugin = new PluginKeychainMemory({ + instanceId: keychainInstanceId, + keychainId, + logLevel, + backend: new Map([ + [keychainEntryKey, keychainEntryValue], + ["some-other-entry-key", "some-other-entry-value"], + ]), + }); + + const keychainPluginBridge = new PluginKeychainMemory({ + instanceId: keychainInstanceIdBridge, + keychainId: keychainIdBridge, + logLevel, + backend: new Map([ + [keychainEntryKeyBridge, keychainEntryValueBridge], + ["some-other-entry-key", "some-other-entry-value"], + ]), + }); + + const pluginRegistry = new PluginRegistry({ plugins: [keychainPlugin] }); + + const pluginRegistryBridge = new PluginRegistry({ + plugins: [keychainPluginBridge], + }); + + const discoveryOptions: DiscoveryOptions = { + enabled: true, + asLocalhost: true, + }; + + const pluginOptions: IPluginLedgerConnectorFabricOptions = { + instanceId: uuidv4(), + dockerBinary: "/usr/local/bin/docker", + peerBinary: "/fabric-samples/bin/peer", + goBinary: "/usr/local/go/bin/go", + pluginRegistry, + cliContainerEnv: FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + sshConfig, + logLevel: "DEBUG", + connectionProfile, + discoveryOptions, + eventHandlerOptions: { + strategy: DefaultEventHandlerStrategy.NetworkScopeAllfortx, + commitTimeout: 300, + }, + }; + + const fabricConnector = new PluginLedgerConnectorFabric(pluginOptions); + + const expressApp = express(); + expressApp.use(bodyParser.json({ limit: "250mb" })); + fabricServer = http.createServer(expressApp); + const listenOptions: IListenOptions = { + hostname: "127.0.0.1", + port: 3000, + server: fabricServer, + }; + const addressInfo = (await Servers.listen(listenOptions)) as AddressInfo; + const { address, port } = addressInfo; + + await fabricConnector.getOrCreateWebServices(); + await fabricConnector.registerWebServices(expressApp); + + log.info("Fabric Ledger connector check"); + + const apiUrl = `http://${address}:${port}`; + + configFabric = new Configuration({ basePath: apiUrl }); + + apiClient = new FabricApi(configFabric); + + // deploy contracts ... + satpContractName = "satp-contract"; + const satpWrapperContractName = "satp-wrapper-contract"; + const satpContractRelPath = + "../../../test/typescript/fabric/contracts/satp-contract/chaincode-typescript"; + const wrapperSatpContractRelPath = + "../../../main/typescript/fabric-contracts/satp-wrapper/chaincode-typescript"; + const satpContractDir = path.join(__dirname, satpContractRelPath); + + // ├── package.json + // ├── src + // │ ├── index.ts + // │ ├── ITraceableContract.ts + // │ ├── satp-contract-interface.ts + // │ ├── satp-contract.ts + // ├── tsconfig.json + // ├── lib + // │ └── tokenERC20.js + // -------- + const satpSourceFiles: FileBase64[] = []; + { + const filename = "./tsconfig.json"; + const relativePath = "./"; + const filePath = path.join(satpContractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + satpSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./package.json"; + const relativePath = "./"; + const filePath = path.join(satpContractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + satpSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./index.ts"; + const relativePath = "./src/"; + const filePath = path.join(satpContractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + satpSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./ITraceableContract.ts"; + const relativePath = "./src/"; + const filePath = path.join(satpContractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + satpSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./satp-contract-interface.ts"; + const relativePath = "./src/"; + const filePath = path.join(satpContractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + satpSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./satp-contract.ts"; + const relativePath = "./src/"; + const filePath = path.join(satpContractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + satpSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./tokenERC20.ts"; + const relativePath = "./src/"; + const filePath = path.join(satpContractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + satpSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + + const wrapperSatpContractDir = path.join( + __dirname, + wrapperSatpContractRelPath, + ); + + // ├── package.json + // ├── src + // │ ├── index.ts + // │ ├── interaction-signature.ts + // │ ├── ITraceableContract.ts + // │ ├── satp-wrapper.ts + // │ └── token.ts + // ├── tsconfig.json + // -------- + const wrapperSourceFiles: FileBase64[] = []; + { + const filename = "./tsconfig.json"; + const relativePath = "./"; + const filePath = path.join( + wrapperSatpContractDir, + relativePath, + filename, + ); + const buffer = await fs.readFile(filePath); + wrapperSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./package.json"; + const relativePath = "./"; + const filePath = path.join( + wrapperSatpContractDir, + relativePath, + filename, + ); + const buffer = await fs.readFile(filePath); + wrapperSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./index.ts"; + const relativePath = "./src/"; + const filePath = path.join( + wrapperSatpContractDir, + relativePath, + filename, + ); + const buffer = await fs.readFile(filePath); + wrapperSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./interaction-signature.ts"; + const relativePath = "./src/"; + const filePath = path.join( + wrapperSatpContractDir, + relativePath, + filename, + ); + const buffer = await fs.readFile(filePath); + wrapperSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./ITraceableContract.ts"; + const relativePath = "./src/"; + const filePath = path.join( + wrapperSatpContractDir, + relativePath, + filename, + ); + const buffer = await fs.readFile(filePath); + wrapperSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./satp-wrapper.ts"; + const relativePath = "./src/"; + const filePath = path.join( + wrapperSatpContractDir, + relativePath, + filename, + ); + const buffer = await fs.readFile(filePath); + wrapperSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./token.ts"; + const relativePath = "./src/"; + const filePath = path.join( + wrapperSatpContractDir, + relativePath, + filename, + ); + const buffer = await fs.readFile(filePath); + wrapperSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + + const res = await apiClient.deployContractV1({ + channelId: fabricChannelName, + ccVersion: "1.0.0", + sourceFiles: satpSourceFiles, + ccName: satpContractName, + targetOrganizations: [ + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, + ], + caFile: + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1.ORDERER_TLS_ROOTCERT_FILE, + ccLabel: "satp-contract", + ccLang: ChainCodeProgrammingLanguage.Typescript, + ccSequence: 1, + orderer: "orderer.example.com:7050", + ordererTLSHostnameOverride: "orderer.example.com", + connTimeout: 60, + }); + + const { packageIds, lifecycle, success } = res.data; + expect(res.status).toBe(200); + expect(success).toBe(true); + expect(lifecycle).not.toBeUndefined(); + + const { + approveForMyOrgList, + installList, + queryInstalledList, + commit, + packaging, + queryCommitted, + } = lifecycle; + + expect(packageIds).toBeTruthy(); + expect(packageIds).toBeArray(); + + expect(approveForMyOrgList).toBeTruthy(); + expect(approveForMyOrgList).toBeArray(); + + expect(installList).toBeTruthy(); + expect(installList).toBeArray(); + expect(queryInstalledList).toBeTruthy(); + expect(queryInstalledList).toBeArray(); + + expect(commit).toBeTruthy(); + expect(packaging).toBeTruthy(); + expect(queryCommitted).toBeTruthy(); + log.info("SATP Contract deployed"); + + const res2 = await apiClient.deployContractV1({ + channelId: fabricChannelName, + ccVersion: "1.0.0", + sourceFiles: wrapperSourceFiles, + ccName: satpWrapperContractName, + targetOrganizations: [ + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, + ], + caFile: + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2.ORDERER_TLS_ROOTCERT_FILE, + ccLabel: "satp-wrapper-contract", + ccLang: ChainCodeProgrammingLanguage.Typescript, + ccSequence: 1, + orderer: "orderer.example.com:7050", + ordererTLSHostnameOverride: "orderer.example.com", + connTimeout: 60, + }); + + const { + packageIds: packageIds2, + lifecycle: lifecycle2, + success: success2, + } = res2.data; + expect(res2.status).toBe(200); + expect(success2).toBe(true); + + const { + approveForMyOrgList: approveForMyOrgList2, + installList: installList2, + queryInstalledList: queryInstalledList2, + commit: commit2, + packaging: packaging2, + queryCommitted: queryCommitted2, + } = lifecycle2; + + expect(packageIds2).toBeTruthy(); + expect(packageIds2).toBeArray(); + + expect(approveForMyOrgList2).toBeTruthy(); + expect(approveForMyOrgList2).toBeArray(); + + expect(installList2).toBeTruthy(); + expect(installList2).toBeArray(); + expect(queryInstalledList2).toBeTruthy(); + expect(queryInstalledList2).toBeArray(); + + expect(commit2).toBeTruthy(); + expect(packaging2).toBeTruthy(); + expect(queryCommitted2).toBeTruthy(); + + log.info("SATP Wrapper Contract deployed"); + + fabricSigningCredential = { + keychainId, + keychainRef: keychainEntryKey, + }; + + bridgeFabricSigningCredential = { + keychainId: keychainIdBridge, + keychainRef: keychainEntryKeyBridge, + }; + const mspId: string = userIdentity.mspId; + + const initializeResponse = await apiClient.runTransactionV1({ + contractName: satpContractName, + channelName: fabricChannelName, + params: [mspId, FABRIC_ASSET_ID], + methodName: "InitToken", + invocationType: FabricContractInvocationType.Send, + signingCredential: fabricSigningCredential, + }); + + expect(initializeResponse).not.toBeUndefined(); + expect(initializeResponse.status).toBeGreaterThan(199); + expect(initializeResponse.status).toBeLessThan(300); + + log.info( + `SATPContract.InitToken(): ${JSON.stringify(initializeResponse.data)}`, + ); + + const initializeResponse2 = await apiClient.runTransactionV1({ + contractName: satpWrapperContractName, + channelName: fabricChannelName, + params: [mspId], + methodName: "Initialize", + invocationType: FabricContractInvocationType.Send, + signingCredential: fabricSigningCredential, + }); + + expect(initializeResponse2).not.toBeUndefined(); + expect(initializeResponse2.status).toBeGreaterThan(199); + expect(initializeResponse2.status).toBeLessThan(300); + + log.info( + `SATPWrapper.Initialize(): ${JSON.stringify(initializeResponse2.data)}`, + ); + + const setBridgeResponse = await apiClient.runTransactionV1({ + contractName: satpContractName, + channelName: fabricChannelName, + params: ["Org2MSP"], + methodName: "setBridge", + invocationType: FabricContractInvocationType.Send, + signingCredential: fabricSigningCredential, + }); + + const setBridgeResponse2 = await apiClient.runTransactionV1({ + contractName: satpWrapperContractName, + channelName: fabricChannelName, + params: ["Org2MSP", BRIDGE_ID], + methodName: "setBridge", + invocationType: FabricContractInvocationType.Send, + signingCredential: fabricSigningCredential, + }); + + expect(setBridgeResponse2).not.toBeUndefined(); + expect(setBridgeResponse2.status).toBeGreaterThan(199); + expect(setBridgeResponse2.status).toBeLessThan(300); + + log.info( + `SATPWrapper.setBridge(): ${JSON.stringify(setBridgeResponse.data)}`, + ); + + const responseClientId = await apiClient.runTransactionV1({ + contractName: satpWrapperContractName, + channelName: fabricChannelName, + params: [], + methodName: "ClientAccountID", + invocationType: FabricContractInvocationType.Send, + signingCredential: fabricSigningCredential, + }); + + clientId = responseClientId.data.functionOutput.toString(); + + pluginBungeeFabricOptions = { + keyPair: Secp256k1Keys.generateKeyPairsBuffer(), + instanceId: uuidv4(), + pluginRegistry: new PluginRegistry(), + logLevel, + }; + + const pluginOptionsFabricBridge: IPluginLedgerConnectorFabricOptions = { + instanceId: uuidv4(), + dockerBinary: "/usr/local/bin/docker", + peerBinary: "/fabric-samples/bin/peer", + goBinary: "/usr/local/go/bin/go", + pluginRegistry: pluginRegistryBridge, + cliContainerEnv: FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, + sshConfig, + logLevel: "DEBUG", + connectionProfile: bridgeProfile, + discoveryOptions, + eventHandlerOptions: { + strategy: DefaultEventHandlerStrategy.NetworkScopeAllfortx, + commitTimeout: 300, + }, + }; + + fabricConfig = { + network: SupportedChain.FABRIC, + signingCredential: bridgeFabricSigningCredential, + channelName: fabricChannelName, + contractName: satpWrapperContractName, + options: pluginOptionsFabricBridge, + bungeeOptions: pluginBungeeFabricOptions, + } as FabricConfig; + + // networkDetails = { + // connectorApiPath: fabricPath, + // signingCredential: fabricSigningCredential, + // channelName: fabricChannelName, + // contractName: satpContractName, + // participant: "Org1MSP", + // }; + } + + { + //setup besu ledger + rpcApiHttpHost = await besuLedger.getRpcApiHttpHost(); + rpcApiWsHost = await besuLedger.getRpcApiWsHost(); + web3 = new Web3(rpcApiHttpHost); + firstHighNetWorthAccount = besuLedger.getGenesisAccountPubKey(); + + bridgeEthAccount = await besuLedger.createEthTestAccount(); + + assigneeEthAccount = await besuLedger.createEthTestAccount(); + + besuKeyPair = { + privateKey: besuLedger.getGenesisAccountPrivKey(), + }; + + erc20TokenContract = "SATPContract"; + contractNameWrapper = "SATPWrapperContract"; + + const keychainEntryValue = besuKeyPair.privateKey; + const keychainEntryKey = uuidv4(); + keychainPlugin1 = new PluginKeychainMemory({ + instanceId: uuidv4(), + keychainId: uuidv4(), + + backend: new Map([[keychainEntryKey, keychainEntryValue]]), + logLevel, + }); + + keychainPlugin2 = new PluginKeychainMemory({ + instanceId: uuidv4(), + keychainId: uuidv4(), + + backend: new Map([[keychainEntryKey, keychainEntryValue]]), + logLevel, + }); + + keychainPlugin1.set(erc20TokenContract, JSON.stringify(SATPContract)); + keychainPlugin2.set( + contractNameWrapper, + JSON.stringify(SATPWrapperContract), + ); + + const pluginRegistry = new PluginRegistry({ + plugins: [keychainPlugin1, keychainPlugin2], + }); + + besuOptions = { + instanceId: uuidv4(), + rpcApiHttpHost, + rpcApiWsHost, + pluginRegistry, + logLevel, + }; + testing_connector = new PluginLedgerConnectorBesu(besuOptions); + pluginRegistry.add(testing_connector); + + await testing_connector.transact({ + web3SigningCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + consistencyStrategy: { + blockConfirmations: 0, + receiptType: ReceiptType.NodeTxPoolAck, + }, + transactionConfig: { + from: firstHighNetWorthAccount, + to: bridgeEthAccount.address, + value: 10e9, + gas: 1000000, + }, + }); + + const balance = await web3.eth.getBalance(bridgeEthAccount.address); + expect(balance).toBeTruthy(); + expect(parseInt(balance, 10)).toBeGreaterThan(10e9); + log.info("Connector initialized"); + + const deployOutSATPContract = await testing_connector.deployContract({ + keychainId: keychainPlugin1.getKeychainId(), + contractName: erc20TokenContract, + contractAbi: SATPContract.abi, + constructorArgs: [firstHighNetWorthAccount, BESU_ASSET_ID], + web3SigningCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + bytecode: SATPContract.bytecode.object, + gas: 999999999999999, + }); + expect(deployOutSATPContract).toBeTruthy(); + expect(deployOutSATPContract.transactionReceipt).toBeTruthy(); + expect( + deployOutSATPContract.transactionReceipt.contractAddress, + ).toBeTruthy(); + + assetContractAddress = + deployOutSATPContract.transactionReceipt.contractAddress ?? ""; + + log.info("SATPContract Deployed successfully"); + + const deployOutWrapperContract = await testing_connector.deployContract({ + keychainId: keychainPlugin2.getKeychainId(), + contractName: contractNameWrapper, + contractAbi: SATPWrapperContract.abi, + constructorArgs: [bridgeEthAccount.address], + web3SigningCredential: { + ethAccount: bridgeEthAccount.address, + secret: bridgeEthAccount.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + bytecode: SATPWrapperContract.bytecode.object, + gas: 999999999999999, + }); + expect(deployOutWrapperContract).toBeTruthy(); + expect(deployOutWrapperContract.transactionReceipt).toBeTruthy(); + expect( + deployOutWrapperContract.transactionReceipt.contractAddress, + ).toBeTruthy(); + log.info("SATPWrapperContract Deployed successfully"); + + wrapperContractAddress = + deployOutWrapperContract.transactionReceipt.contractAddress ?? ""; + + pluginBungeeBesuOptions = { + keyPair: Secp256k1Keys.generateKeyPairsBuffer(), + instanceId: uuidv4(), + pluginRegistry: new PluginRegistry(), + logLevel, + }; + + besuConfig = { + network: SupportedChain.BESU, + keychainId: keychainPlugin2.getKeychainId(), + signingCredential: { + ethAccount: bridgeEthAccount.address, + secret: bridgeEthAccount.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + contractName: contractNameWrapper, + contractAddress: wrapperContractAddress, + options: besuOptions, + bungeeOptions: pluginBungeeBesuOptions, + gas: 999999999999999, + }; + + const giveRoleRes = await testing_connector.invokeContract({ + contractName: erc20TokenContract, + keychainId: keychainPlugin1.getKeychainId(), + invocationType: EthContractInvocationType.Send, + methodName: "giveRole", + params: [wrapperContractAddress], + signingCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + gas: 1000000, + }); + + expect(giveRoleRes).toBeTruthy(); + expect(giveRoleRes.success).toBeTruthy(); + log.info("BRIDGE_ROLE given to SATPWrapperContract successfully"); + } + + const responseMint = await testing_connector.invokeContract({ + contractName: erc20TokenContract, + keychainId: keychainPlugin1.getKeychainId(), + invocationType: EthContractInvocationType.Send, + methodName: "mint", + params: [firstHighNetWorthAccount, "100"], + signingCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + gas: 999999999, + }); + expect(responseMint).toBeTruthy(); + expect(responseMint.success).toBeTruthy(); + log.info("Minted 100 tokens to firstHighNetWorthAccount"); + + const responseApprove = await testing_connector.invokeContract({ + contractName: erc20TokenContract, + keychainId: keychainPlugin1.getKeychainId(), + invocationType: EthContractInvocationType.Send, + methodName: "approve", + params: [wrapperContractAddress, "100"], + signingCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + gas: 999999999, + }); + expect(responseApprove).toBeTruthy(); + expect(responseApprove.success).toBeTruthy(); + log.info("Approved 100 tokens to SATPWrapperContract"); +}); +describe("SATPGateway sending a token from Besu to Fabric", () => { + it("should realize a transfer", async () => { + //setup satp gateway + const factoryOptions: IPluginFactoryOptions = { + pluginImportType: PluginImportType.Local, + }; + const factory = new PluginFactorySATPGateway(factoryOptions); + + const gatewayIdentity = { + id: "mockID", + name: "CustomGateway", + version: [ + { + Core: "v02", + Architecture: "v02", + Crash: "v02", + }, + ], + supportedDLTs: [SupportedChain.FABRIC, SupportedChain.BESU], + proofID: "mockProofID10", + address: "http://localhost" as Address, + } as GatewayIdentity; + + const options: SATPGatewayConfig = { + logLevel: "DEBUG", + gid: gatewayIdentity, + counterPartyGateways: [], //only knows itself + bridgesConfig: [besuConfig, fabricConfig], + }; + const gateway = await factory.create(options); + expect(gateway).toBeInstanceOf(SATPGateway); + + const identity = gateway.Identity; + // default servers + expect(identity.gatewayServerPort).toBe(3010); + expect(identity.gatewayClientPort).toBe(3011); + expect(identity.address).toBe("http://localhost"); + await gateway.startup(); + + const dispatcher = gateway.getBLODispatcher(); + + expect(dispatcher).toBeTruthy(); + const sourceAsset: Asset = { + owner: firstHighNetWorthAccount, + ontology: JSON.stringify(BesuSATPInteraction), + contractName: erc20TokenContract, + contractAddress: assetContractAddress, + }; + const destinyAsset: Asset = { + owner: clientId, + ontology: JSON.stringify(FabricSATPInteraction), + contractName: satpContractName, + mspId: fabricUser.mspId, + channelName: fabricChannelName, + }; + const req: TransactRequest = { + contextID: "mockContext", + fromDLTNetworkID: SupportedChain.BESU, + toDLTNetworkID: SupportedChain.FABRIC, + fromAmount: "100", + toAmount: "1", + mode: "transfer", + originatorPubkey: assigneeEthAccount.address, + beneficiaryPubkey: fabricUser.credentials.certificate, + sourceAsset, + destinyAsset, + }; + + const res = await dispatcher?.Transact(req); + log.info(res?.statusResponse); + + const responseBalanceOwner = await testing_connector.invokeContract({ + contractName: erc20TokenContract, + keychainId: keychainPlugin1.getKeychainId(), + invocationType: EthContractInvocationType.Call, + methodName: "checkBalance", + params: [firstHighNetWorthAccount], + signingCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + gas: 999999999, + }); + expect(responseBalanceOwner).toBeTruthy(); + expect(responseBalanceOwner.success).toBeTruthy(); + expect(responseBalanceOwner.callOutput).toBe("0"); + log.info("Amount was transfer correctly from the Owner account"); + + const responseBalanceBridge = await testing_connector.invokeContract({ + contractName: erc20TokenContract, + keychainId: keychainPlugin1.getKeychainId(), + invocationType: EthContractInvocationType.Call, + methodName: "checkBalance", + params: [wrapperContractAddress], + signingCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + gas: 999999999, + }); + expect(responseBalanceBridge).toBeTruthy(); + expect(responseBalanceBridge.success).toBeTruthy(); + expect(responseBalanceBridge.callOutput).toBe("0"); + log.info("Amount was transfer correctly to the Wrapper account"); + + const responseBalance1 = await apiClient.runTransactionV1({ + contractName: satpContractName, + channelName: fabricChannelName, + params: [BRIDGE_ID], + methodName: "ClientIDAccountBalance", + invocationType: FabricContractInvocationType.Send, + signingCredential: fabricSigningCredential, + }); + + expect(responseBalance1).not.toBeUndefined(); + expect(responseBalance1.status).toBeGreaterThan(199); + expect(responseBalance1.status).toBeLessThan(300); + expect(responseBalance1.data).not.toBeUndefined(); + expect(responseBalance1.data.functionOutput).toBe("0"); + log.info("Amount was transfer correctly from the Bridge account"); + + const responseBalance2 = await apiClient.runTransactionV1({ + contractName: satpContractName, + channelName: fabricChannelName, + params: [clientId], + methodName: "ClientIDAccountBalance", + invocationType: FabricContractInvocationType.Send, + signingCredential: fabricSigningCredential, + }); + expect(responseBalance2).not.toBeUndefined(); + expect(responseBalance2.status).toBeGreaterThan(199); + expect(responseBalance2.status).toBeLessThan(300); + expect(responseBalance2.data).not.toBeUndefined(); + expect(responseBalance2.data.functionOutput).toBe("1"); + log.info("Amount was transfer correctly to the Owner account"); + + await gateway.shutdown(); + }); +}); diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-end-to-end-transfer-2-gateways.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-end-to-end-transfer-2-gateways.test.ts new file mode 100644 index 0000000000..3105d085bf --- /dev/null +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-end-to-end-transfer-2-gateways.test.ts @@ -0,0 +1,1117 @@ +import "jest-extended"; + +import { + IListenOptions, + LogLevelDesc, + LoggerProvider, + Secp256k1Keys, + Servers, +} from "@hyperledger/cactus-common"; +import { v4 as uuidv4 } from "uuid"; + +import { PluginRegistry } from "@hyperledger/cactus-core"; +import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; +import { + ChainCodeProgrammingLanguage, + Configuration, + DefaultEventHandlerStrategy, + FabricSigningCredential, + FileBase64, + IPluginLedgerConnectorFabricOptions, + PluginLedgerConnectorFabric, + DefaultApi as FabricApi, + FabricContractInvocationType, +} from "@hyperledger/cactus-plugin-ledger-connector-fabric"; +import http, { Server } from "http"; +import fs from "fs-extra"; + +import { + pruneDockerAllIfGithubAction, + Containers, + FabricTestLedgerV1, + BesuTestLedger, + FABRIC_25_LTS_AIO_FABRIC_VERSION, + FABRIC_25_LTS_AIO_IMAGE_VERSION, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, +} from "@hyperledger/cactus-test-tooling"; +import bodyParser from "body-parser"; +import express from "express"; +import { DiscoveryOptions, X509Identity } from "fabric-network"; +import { AddressInfo } from "net"; +import path from "path"; +import { + BesuConfig, + FabricConfig, +} from "../../../main/typescript/types/blockchain-interaction"; +import { IPluginBungeeHermesOptions } from "@hyperledger/cactus-plugin-bungee-hermes"; +import { Account } from "web3-core"; +import { + EthContractInvocationType, + IPluginLedgerConnectorBesuOptions, + PluginLedgerConnectorBesu, + ReceiptType, + Web3SigningCredentialType, +} from "@hyperledger/cactus-plugin-ledger-connector-besu"; +import Web3 from "web3"; +import SATPContract from "../../solidity/generated/satp-erc20.sol/SATPContract.json"; +import SATPWrapperContract from "../../../solidity/generated/satp-wrapper.sol/SATPWrapperContract.json"; +import { + SATPGatewayConfig, + SATPGateway, + PluginFactorySATPGateway, + TransactRequest, + Asset, +} from "../../../main/typescript"; +import { + Address, + GatewayIdentity, + SupportedChain, +} from "../../../main/typescript/core/types"; +import { + IPluginFactoryOptions, + PluginImportType, +} from "@hyperledger/cactus-core-api"; +import FabricSATPInteraction from "../../../test/typescript/fabric/satp-erc20-interact.json"; +import BesuSATPInteraction from "../../solidity/satp-erc20-interact.json"; + +const logLevel: LogLevelDesc = "DEBUG"; +const log = LoggerProvider.getOrCreate({ + level: logLevel, + label: "BUNGEE - Hermes", +}); +let fabricServer: Server; + +let besuLedger: BesuTestLedger; + +let fabricLedger: FabricTestLedgerV1; +let fabricSigningCredential: FabricSigningCredential; +let bridgeFabricSigningCredential: FabricSigningCredential; +let configFabric: Configuration; +let fabricChannelName: string; + +const FABRIC_ASSET_ID = uuidv4(); + +const BRIDGE_ID = + "x509::/OU=org2/OU=client/OU=department1/CN=bridge::/C=UK/ST=Hampshire/L=Hursley/O=org2.example.com/CN=ca.org2.example.com"; + +let clientId: string; +let fabricConfig: FabricConfig; +let pluginBungeeFabricOptions: IPluginBungeeHermesOptions; + +let erc20TokenContract: string; +let contractNameWrapper: string; + +let rpcApiHttpHost: string; +let rpcApiWsHost: string; +let web3: Web3; +let firstHighNetWorthAccount: string; +let testing_connector: PluginLedgerConnectorBesu; +let besuKeyPair: { privateKey: string }; +let bridgeEthAccount: Account; +let assigneeEthAccount: Account; +const BESU_ASSET_ID = uuidv4(); +let assetContractAddress: string; +let wrapperContractAddress: string; +let satpContractName: string; + +let pluginBungeeBesuOptions: IPluginBungeeHermesOptions; + +let besuConfig: BesuConfig; +let besuOptions: IPluginLedgerConnectorBesuOptions; + +let keychainPlugin1: PluginKeychainMemory; +let keychainPlugin2: PluginKeychainMemory; +let fabricUser: X509Identity; + +let apiClient: FabricApi; + +afterAll(async () => { + await besuLedger.stop(); + await besuLedger.destroy(); + await fabricLedger.stop(); + await fabricLedger.destroy(); + await Servers.shutdown(fabricServer); + await pruneDockerAllIfGithubAction({ logLevel }) + .then(() => { + log.info("Pruning throw OK"); + }) + .catch(async () => { + await Containers.logDiagnostics({ logLevel }); + fail("Pruning didn't throw OK"); + }); +}); + +beforeAll(async () => { + pruneDockerAllIfGithubAction({ logLevel }) + .then(() => { + log.info("Pruning throw OK"); + }) + .catch(async () => { + await Containers.logDiagnostics({ logLevel }); + fail("Pruning didn't throw OK"); + }); + { + besuLedger = new BesuTestLedger({ + logLevel, + emitContainerLogs: true, + envVars: ["BESU_NETWORK=dev"], + }); + await besuLedger.start(); + + // Fabric ledger connection + const channelId = "mychannel"; + fabricChannelName = channelId; + + fabricLedger = new FabricTestLedgerV1({ + emitContainerLogs: true, + publishAllPorts: true, + imageName: "ghcr.io/hyperledger/cactus-fabric2-all-in-one", + imageVersion: FABRIC_25_LTS_AIO_IMAGE_VERSION, + envVars: new Map([["FABRIC_VERSION", FABRIC_25_LTS_AIO_FABRIC_VERSION]]), + logLevel, + }); + + await fabricLedger.start(); + + log.info("Both Ledgers started successfully"); + } + + { + // setup fabric ledger + const connectionProfile = await fabricLedger.getConnectionProfileOrg1(); + expect(connectionProfile).not.toBeUndefined(); + + const bridgeProfile = await fabricLedger.getConnectionProfileOrgX("org2"); + expect(bridgeProfile).not.toBeUndefined(); + + const enrollAdminOut = await fabricLedger.enrollAdmin(); + const adminWallet = enrollAdminOut[1]; + + const enrollAdminBridgeOut = await fabricLedger.enrollAdminV2({ + organization: "org2", + }); + const bridgeWallet = enrollAdminBridgeOut[1]; + + const [userIdentity] = await fabricLedger.enrollUser(adminWallet); + fabricUser = userIdentity; + const opts = { + enrollmentID: "bridge", + organization: "org2", + wallet: bridgeWallet, + }; + + const [bridgeIdentity] = await fabricLedger.enrollUserV2(opts); + + const sshConfig = await fabricLedger.getSshConfig(); + + log.info("enrolled admin"); + + const keychainInstanceId = uuidv4(); + const keychainId = uuidv4(); + const keychainEntryKey = "user1"; + const keychainEntryValue = JSON.stringify(userIdentity); + + console.log("keychainEntryValue: ", keychainEntryValue); + + const keychainInstanceIdBridge = uuidv4(); + const keychainIdBridge = uuidv4(); + const keychainEntryKeyBridge = "bridge1"; + const keychainEntryValueBridge = JSON.stringify(bridgeIdentity); + + console.log("keychainEntryValue: ", keychainEntryValueBridge); + + const keychainPlugin = new PluginKeychainMemory({ + instanceId: keychainInstanceId, + keychainId, + logLevel, + backend: new Map([ + [keychainEntryKey, keychainEntryValue], + ["some-other-entry-key", "some-other-entry-value"], + ]), + }); + + const keychainPluginBridge = new PluginKeychainMemory({ + instanceId: keychainInstanceIdBridge, + keychainId: keychainIdBridge, + logLevel, + backend: new Map([ + [keychainEntryKeyBridge, keychainEntryValueBridge], + ["some-other-entry-key", "some-other-entry-value"], + ]), + }); + + const pluginRegistry = new PluginRegistry({ plugins: [keychainPlugin] }); + + const pluginRegistryBridge = new PluginRegistry({ + plugins: [keychainPluginBridge], + }); + + const discoveryOptions: DiscoveryOptions = { + enabled: true, + asLocalhost: true, + }; + + const pluginOptions: IPluginLedgerConnectorFabricOptions = { + instanceId: uuidv4(), + dockerBinary: "/usr/local/bin/docker", + peerBinary: "/fabric-samples/bin/peer", + goBinary: "/usr/local/go/bin/go", + pluginRegistry, + cliContainerEnv: FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + sshConfig, + logLevel: "DEBUG", + connectionProfile, + discoveryOptions, + eventHandlerOptions: { + strategy: DefaultEventHandlerStrategy.NetworkScopeAllfortx, + commitTimeout: 300, + }, + }; + + const fabricConnector = new PluginLedgerConnectorFabric(pluginOptions); + + const expressApp = express(); + expressApp.use(bodyParser.json({ limit: "250mb" })); + fabricServer = http.createServer(expressApp); + const listenOptions: IListenOptions = { + hostname: "127.0.0.1", + port: 3000, + server: fabricServer, + }; + const addressInfo = (await Servers.listen(listenOptions)) as AddressInfo; + const { address, port } = addressInfo; + + await fabricConnector.getOrCreateWebServices(); + await fabricConnector.registerWebServices(expressApp); + + log.info("Fabric Ledger connector check"); + + const apiUrl = `http://${address}:${port}`; + + configFabric = new Configuration({ basePath: apiUrl }); + + apiClient = new FabricApi(configFabric); + + // deploy contracts ... + satpContractName = "satp-contract"; + const satpWrapperContractName = "satp-wrapper-contract"; + const satpContractRelPath = + "../../../test/typescript/fabric/contracts/satp-contract/chaincode-typescript"; + const wrapperSatpContractRelPath = + "../../../main/typescript/fabric-contracts/satp-wrapper/chaincode-typescript"; + const satpContractDir = path.join(__dirname, satpContractRelPath); + + // ├── package.json + // ├── src + // │ ├── index.ts + // │ ├── ITraceableContract.ts + // │ ├── satp-contract-interface.ts + // │ ├── satp-contract.ts + // ├── tsconfig.json + // ├── lib + // │ └── tokenERC20.js + // -------- + const satpSourceFiles: FileBase64[] = []; + { + const filename = "./tsconfig.json"; + const relativePath = "./"; + const filePath = path.join(satpContractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + satpSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./package.json"; + const relativePath = "./"; + const filePath = path.join(satpContractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + satpSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./index.ts"; + const relativePath = "./src/"; + const filePath = path.join(satpContractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + satpSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./ITraceableContract.ts"; + const relativePath = "./src/"; + const filePath = path.join(satpContractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + satpSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./satp-contract-interface.ts"; + const relativePath = "./src/"; + const filePath = path.join(satpContractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + satpSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./satp-contract.ts"; + const relativePath = "./src/"; + const filePath = path.join(satpContractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + satpSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./tokenERC20.ts"; + const relativePath = "./src/"; + const filePath = path.join(satpContractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + satpSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + + const wrapperSatpContractDir = path.join( + __dirname, + wrapperSatpContractRelPath, + ); + + // ├── package.json + // ├── src + // │ ├── index.ts + // │ ├── interaction-signature.ts + // │ ├── ITraceableContract.ts + // │ ├── satp-wrapper.ts + // │ └── token.ts + // ├── tsconfig.json + // -------- + const wrapperSourceFiles: FileBase64[] = []; + { + const filename = "./tsconfig.json"; + const relativePath = "./"; + const filePath = path.join( + wrapperSatpContractDir, + relativePath, + filename, + ); + const buffer = await fs.readFile(filePath); + wrapperSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./package.json"; + const relativePath = "./"; + const filePath = path.join( + wrapperSatpContractDir, + relativePath, + filename, + ); + const buffer = await fs.readFile(filePath); + wrapperSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./index.ts"; + const relativePath = "./src/"; + const filePath = path.join( + wrapperSatpContractDir, + relativePath, + filename, + ); + const buffer = await fs.readFile(filePath); + wrapperSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./interaction-signature.ts"; + const relativePath = "./src/"; + const filePath = path.join( + wrapperSatpContractDir, + relativePath, + filename, + ); + const buffer = await fs.readFile(filePath); + wrapperSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./ITraceableContract.ts"; + const relativePath = "./src/"; + const filePath = path.join( + wrapperSatpContractDir, + relativePath, + filename, + ); + const buffer = await fs.readFile(filePath); + wrapperSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./satp-wrapper.ts"; + const relativePath = "./src/"; + const filePath = path.join( + wrapperSatpContractDir, + relativePath, + filename, + ); + const buffer = await fs.readFile(filePath); + wrapperSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./token.ts"; + const relativePath = "./src/"; + const filePath = path.join( + wrapperSatpContractDir, + relativePath, + filename, + ); + const buffer = await fs.readFile(filePath); + wrapperSourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + + const res = await apiClient.deployContractV1({ + channelId: fabricChannelName, + ccVersion: "1.0.0", + sourceFiles: satpSourceFiles, + ccName: satpContractName, + targetOrganizations: [ + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, + ], + caFile: + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1.ORDERER_TLS_ROOTCERT_FILE, + ccLabel: "satp-contract", + ccLang: ChainCodeProgrammingLanguage.Typescript, + ccSequence: 1, + orderer: "orderer.example.com:7050", + ordererTLSHostnameOverride: "orderer.example.com", + connTimeout: 60, + }); + + const { packageIds, lifecycle, success } = res.data; + expect(res.status).toBe(200); + expect(success).toBe(true); + expect(lifecycle).not.toBeUndefined(); + + const { + approveForMyOrgList, + installList, + queryInstalledList, + commit, + packaging, + queryCommitted, + } = lifecycle; + + expect(packageIds).toBeTruthy(); + expect(packageIds).toBeArray(); + + expect(approveForMyOrgList).toBeTruthy(); + expect(approveForMyOrgList).toBeArray(); + + expect(installList).toBeTruthy(); + expect(installList).toBeArray(); + expect(queryInstalledList).toBeTruthy(); + expect(queryInstalledList).toBeArray(); + + expect(commit).toBeTruthy(); + expect(packaging).toBeTruthy(); + expect(queryCommitted).toBeTruthy(); + log.info("SATP Contract deployed"); + + const res2 = await apiClient.deployContractV1({ + channelId: fabricChannelName, + ccVersion: "1.0.0", + sourceFiles: wrapperSourceFiles, + ccName: satpWrapperContractName, + targetOrganizations: [ + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, + ], + caFile: + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2.ORDERER_TLS_ROOTCERT_FILE, + ccLabel: "satp-wrapper-contract", + ccLang: ChainCodeProgrammingLanguage.Typescript, + ccSequence: 1, + orderer: "orderer.example.com:7050", + ordererTLSHostnameOverride: "orderer.example.com", + connTimeout: 60, + }); + + const { + packageIds: packageIds2, + lifecycle: lifecycle2, + success: success2, + } = res2.data; + expect(res2.status).toBe(200); + expect(success2).toBe(true); + + const { + approveForMyOrgList: approveForMyOrgList2, + installList: installList2, + queryInstalledList: queryInstalledList2, + commit: commit2, + packaging: packaging2, + queryCommitted: queryCommitted2, + } = lifecycle2; + + expect(packageIds2).toBeTruthy(); + expect(packageIds2).toBeArray(); + + expect(approveForMyOrgList2).toBeTruthy(); + expect(approveForMyOrgList2).toBeArray(); + + expect(installList2).toBeTruthy(); + expect(installList2).toBeArray(); + expect(queryInstalledList2).toBeTruthy(); + expect(queryInstalledList2).toBeArray(); + + expect(commit2).toBeTruthy(); + expect(packaging2).toBeTruthy(); + expect(queryCommitted2).toBeTruthy(); + + log.info("SATP Wrapper Contract deployed"); + + fabricSigningCredential = { + keychainId, + keychainRef: keychainEntryKey, + }; + + bridgeFabricSigningCredential = { + keychainId: keychainIdBridge, + keychainRef: keychainEntryKeyBridge, + }; + const mspId: string = userIdentity.mspId; + + const initializeResponse = await apiClient.runTransactionV1({ + contractName: satpContractName, + channelName: fabricChannelName, + params: [mspId, FABRIC_ASSET_ID], + methodName: "InitToken", + invocationType: FabricContractInvocationType.Send, + signingCredential: fabricSigningCredential, + }); + + expect(initializeResponse).not.toBeUndefined(); + expect(initializeResponse.status).toBeGreaterThan(199); + expect(initializeResponse.status).toBeLessThan(300); + + log.info( + `SATPContract.InitToken(): ${JSON.stringify(initializeResponse.data)}`, + ); + + const initializeResponse2 = await apiClient.runTransactionV1({ + contractName: satpWrapperContractName, + channelName: fabricChannelName, + params: [mspId], + methodName: "Initialize", + invocationType: FabricContractInvocationType.Send, + signingCredential: fabricSigningCredential, + }); + + expect(initializeResponse2).not.toBeUndefined(); + expect(initializeResponse2.status).toBeGreaterThan(199); + expect(initializeResponse2.status).toBeLessThan(300); + + log.info( + `SATPWrapper.Initialize(): ${JSON.stringify(initializeResponse2.data)}`, + ); + + const setBridgeResponse = await apiClient.runTransactionV1({ + contractName: satpContractName, + channelName: fabricChannelName, + params: ["Org2MSP"], + methodName: "setBridge", + invocationType: FabricContractInvocationType.Send, + signingCredential: fabricSigningCredential, + }); + + const setBridgeResponse2 = await apiClient.runTransactionV1({ + contractName: satpWrapperContractName, + channelName: fabricChannelName, + params: ["Org2MSP", BRIDGE_ID], + methodName: "setBridge", + invocationType: FabricContractInvocationType.Send, + signingCredential: fabricSigningCredential, + }); + + expect(setBridgeResponse2).not.toBeUndefined(); + expect(setBridgeResponse2.status).toBeGreaterThan(199); + expect(setBridgeResponse2.status).toBeLessThan(300); + + log.info( + `SATPWrapper.setBridge(): ${JSON.stringify(setBridgeResponse.data)}`, + ); + + const responseClientId = await apiClient.runTransactionV1({ + contractName: satpWrapperContractName, + channelName: fabricChannelName, + params: [], + methodName: "ClientAccountID", + invocationType: FabricContractInvocationType.Send, + signingCredential: fabricSigningCredential, + }); + + clientId = responseClientId.data.functionOutput.toString(); + + pluginBungeeFabricOptions = { + keyPair: Secp256k1Keys.generateKeyPairsBuffer(), + instanceId: uuidv4(), + pluginRegistry: new PluginRegistry(), + logLevel, + }; + + const pluginOptionsFabricBridge: IPluginLedgerConnectorFabricOptions = { + instanceId: uuidv4(), + dockerBinary: "/usr/local/bin/docker", + peerBinary: "/fabric-samples/bin/peer", + goBinary: "/usr/local/go/bin/go", + pluginRegistry: pluginRegistryBridge, + cliContainerEnv: FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, + sshConfig, + logLevel: "DEBUG", + connectionProfile: bridgeProfile, + discoveryOptions, + eventHandlerOptions: { + strategy: DefaultEventHandlerStrategy.NetworkScopeAllfortx, + commitTimeout: 300, + }, + }; + + fabricConfig = { + network: SupportedChain.FABRIC, + signingCredential: bridgeFabricSigningCredential, + channelName: fabricChannelName, + contractName: satpWrapperContractName, + options: pluginOptionsFabricBridge, + bungeeOptions: pluginBungeeFabricOptions, + } as FabricConfig; + + // networkDetails = { + // connectorApiPath: fabricPath, + // signingCredential: fabricSigningCredential, + // channelName: fabricChannelName, + // contractName: satpContractName, + // participant: "Org1MSP", + // }; + } + + { + //setup besu ledger + rpcApiHttpHost = await besuLedger.getRpcApiHttpHost(); + rpcApiWsHost = await besuLedger.getRpcApiWsHost(); + web3 = new Web3(rpcApiHttpHost); + firstHighNetWorthAccount = besuLedger.getGenesisAccountPubKey(); + + bridgeEthAccount = await besuLedger.createEthTestAccount(); + + assigneeEthAccount = await besuLedger.createEthTestAccount(); + + besuKeyPair = { + privateKey: besuLedger.getGenesisAccountPrivKey(), + }; + + erc20TokenContract = "SATPContract"; + contractNameWrapper = "SATPWrapperContract"; + + const keychainEntryValue = besuKeyPair.privateKey; + const keychainEntryKey = uuidv4(); + keychainPlugin1 = new PluginKeychainMemory({ + instanceId: uuidv4(), + keychainId: uuidv4(), + + backend: new Map([[keychainEntryKey, keychainEntryValue]]), + logLevel, + }); + + keychainPlugin2 = new PluginKeychainMemory({ + instanceId: uuidv4(), + keychainId: uuidv4(), + + backend: new Map([[keychainEntryKey, keychainEntryValue]]), + logLevel, + }); + + keychainPlugin1.set(erc20TokenContract, JSON.stringify(SATPContract)); + keychainPlugin2.set( + contractNameWrapper, + JSON.stringify(SATPWrapperContract), + ); + + const pluginRegistry = new PluginRegistry({ + plugins: [keychainPlugin1, keychainPlugin2], + }); + + besuOptions = { + instanceId: uuidv4(), + rpcApiHttpHost, + rpcApiWsHost, + pluginRegistry, + logLevel, + }; + testing_connector = new PluginLedgerConnectorBesu(besuOptions); + pluginRegistry.add(testing_connector); + + await testing_connector.transact({ + web3SigningCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + consistencyStrategy: { + blockConfirmations: 0, + receiptType: ReceiptType.NodeTxPoolAck, + }, + transactionConfig: { + from: firstHighNetWorthAccount, + to: bridgeEthAccount.address, + value: 10e9, + gas: 1000000, + }, + }); + + const balance = await web3.eth.getBalance(bridgeEthAccount.address); + expect(balance).toBeTruthy(); + expect(parseInt(balance, 10)).toBeGreaterThan(10e9); + log.info("Connector initialized"); + + const deployOutSATPContract = await testing_connector.deployContract({ + keychainId: keychainPlugin1.getKeychainId(), + contractName: erc20TokenContract, + contractAbi: SATPContract.abi, + constructorArgs: [firstHighNetWorthAccount, BESU_ASSET_ID], + web3SigningCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + bytecode: SATPContract.bytecode.object, + gas: 999999999999999, + }); + expect(deployOutSATPContract).toBeTruthy(); + expect(deployOutSATPContract.transactionReceipt).toBeTruthy(); + expect( + deployOutSATPContract.transactionReceipt.contractAddress, + ).toBeTruthy(); + + assetContractAddress = + deployOutSATPContract.transactionReceipt.contractAddress ?? ""; + + log.info("SATPContract Deployed successfully"); + + const deployOutWrapperContract = await testing_connector.deployContract({ + keychainId: keychainPlugin2.getKeychainId(), + contractName: contractNameWrapper, + contractAbi: SATPWrapperContract.abi, + constructorArgs: [bridgeEthAccount.address], + web3SigningCredential: { + ethAccount: bridgeEthAccount.address, + secret: bridgeEthAccount.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + bytecode: SATPWrapperContract.bytecode.object, + gas: 999999999999999, + }); + expect(deployOutWrapperContract).toBeTruthy(); + expect(deployOutWrapperContract.transactionReceipt).toBeTruthy(); + expect( + deployOutWrapperContract.transactionReceipt.contractAddress, + ).toBeTruthy(); + log.info("SATPWrapperContract Deployed successfully"); + + wrapperContractAddress = + deployOutWrapperContract.transactionReceipt.contractAddress ?? ""; + + pluginBungeeBesuOptions = { + keyPair: Secp256k1Keys.generateKeyPairsBuffer(), + instanceId: uuidv4(), + pluginRegistry: new PluginRegistry(), + logLevel, + }; + + besuConfig = { + network: SupportedChain.BESU, + keychainId: keychainPlugin2.getKeychainId(), + signingCredential: { + ethAccount: bridgeEthAccount.address, + secret: bridgeEthAccount.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + contractName: contractNameWrapper, + contractAddress: wrapperContractAddress, + options: besuOptions, + bungeeOptions: pluginBungeeBesuOptions, + gas: 999999999999999, + }; + + const giveRoleRes = await testing_connector.invokeContract({ + contractName: erc20TokenContract, + keychainId: keychainPlugin1.getKeychainId(), + invocationType: EthContractInvocationType.Send, + methodName: "giveRole", + params: [wrapperContractAddress], + signingCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + gas: 1000000, + }); + + expect(giveRoleRes).toBeTruthy(); + expect(giveRoleRes.success).toBeTruthy(); + log.info("BRIDGE_ROLE given to SATPWrapperContract successfully"); + } + + const responseMint = await testing_connector.invokeContract({ + contractName: erc20TokenContract, + keychainId: keychainPlugin1.getKeychainId(), + invocationType: EthContractInvocationType.Send, + methodName: "mint", + params: [firstHighNetWorthAccount, "100"], + signingCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + gas: 999999999, + }); + expect(responseMint).toBeTruthy(); + expect(responseMint.success).toBeTruthy(); + log.info("Minted 100 tokens to firstHighNetWorthAccount"); + + const responseApprove = await testing_connector.invokeContract({ + contractName: erc20TokenContract, + keychainId: keychainPlugin1.getKeychainId(), + invocationType: EthContractInvocationType.Send, + methodName: "approve", + params: [wrapperContractAddress, "100"], + signingCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + gas: 999999999, + }); + expect(responseApprove).toBeTruthy(); + expect(responseApprove.success).toBeTruthy(); + log.info("Approved 100 tokens to SATPWrapperContract"); +}); +describe("2 SATPGateway sending a token from Besu to Fabric", () => { + it("should realize a transfer", async () => { + //setup satp gateway + const factoryOptions: IPluginFactoryOptions = { + pluginImportType: PluginImportType.Local, + }; + const factory = new PluginFactorySATPGateway(factoryOptions); + + const gatewayIdentity1 = { + id: "mockID-1", + name: "CustomGateway", + version: [ + { + Core: "v02", + Architecture: "v02", + Crash: "v02", + }, + ], + supportedDLTs: [SupportedChain.BESU], + proofID: "mockProofID10", + address: "http://localhost" as Address, + } as GatewayIdentity; + + const gatewayIdentity2 = { + id: "mockID-2", + name: "CustomGateway", + version: [ + { + Core: "v02", + Architecture: "v02", + Crash: "v02", + }, + ], + supportedDLTs: [SupportedChain.FABRIC], + proofID: "mockProofID11", + address: "http://localhost" as Address, + gatewayServerPort: 3110, + gatewayClientPort: 3111, + } as GatewayIdentity; + + const options1: SATPGatewayConfig = { + logLevel: "DEBUG", + gid: gatewayIdentity1, + counterPartyGateways: [gatewayIdentity2], //only knows itself + bridgesConfig: [besuConfig], + }; + + const options2: SATPGatewayConfig = { + logLevel: "DEBUG", + gid: gatewayIdentity2, + counterPartyGateways: [gatewayIdentity1], //only knows itself + bridgesConfig: [fabricConfig], + }; + const gateway1 = await factory.create(options1); + expect(gateway1).toBeInstanceOf(SATPGateway); + + const identity1 = gateway1.Identity; + // default servers + expect(identity1.gatewayServerPort).toBe(3010); + expect(identity1.gatewayClientPort).toBe(3011); + expect(identity1.address).toBe("http://localhost"); + await gateway1.startup(); + + const gateway2 = await factory.create(options2); + expect(gateway2).toBeInstanceOf(SATPGateway); + + const identity2 = gateway2.Identity; + // default servers + expect(identity2.gatewayServerPort).toBe(3110); + expect(identity2.gatewayClientPort).toBe(3111); + expect(identity2.address).toBe("http://localhost"); + await gateway2.startup(); + + const dispatcher = gateway1.getBLODispatcher(); + + expect(dispatcher).toBeTruthy(); + const sourceAsset: Asset = { + owner: firstHighNetWorthAccount, + ontology: JSON.stringify(BesuSATPInteraction), + contractName: erc20TokenContract, + contractAddress: assetContractAddress, + }; + const destinyAsset: Asset = { + owner: clientId, + ontology: JSON.stringify(FabricSATPInteraction), + contractName: satpContractName, + mspId: fabricUser.mspId, + channelName: fabricChannelName, + }; + const req: TransactRequest = { + contextID: "mockContext", + fromDLTNetworkID: SupportedChain.BESU, + toDLTNetworkID: SupportedChain.FABRIC, + fromAmount: "100", + toAmount: "1", + mode: "transfer", + originatorPubkey: assigneeEthAccount.address, + beneficiaryPubkey: fabricUser.credentials.certificate, + sourceAsset, + destinyAsset, + }; + + const res = await dispatcher?.Transact(req); + log.info(res?.statusResponse); + + const responseBalanceOwner = await testing_connector.invokeContract({ + contractName: erc20TokenContract, + keychainId: keychainPlugin1.getKeychainId(), + invocationType: EthContractInvocationType.Call, + methodName: "checkBalance", + params: [firstHighNetWorthAccount], + signingCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + gas: 999999999, + }); + expect(responseBalanceOwner).toBeTruthy(); + expect(responseBalanceOwner.success).toBeTruthy(); + expect(responseBalanceOwner.callOutput).toBe("0"); + log.info("Amount was transfer correctly from the Owner account"); + + const responseBalanceBridge = await testing_connector.invokeContract({ + contractName: erc20TokenContract, + keychainId: keychainPlugin1.getKeychainId(), + invocationType: EthContractInvocationType.Call, + methodName: "checkBalance", + params: [wrapperContractAddress], + signingCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + gas: 999999999, + }); + expect(responseBalanceBridge).toBeTruthy(); + expect(responseBalanceBridge.success).toBeTruthy(); + expect(responseBalanceBridge.callOutput).toBe("0"); + log.info("Amount was transfer correctly to the Wrapper account"); + + const responseBalance1 = await apiClient.runTransactionV1({ + contractName: satpContractName, + channelName: fabricChannelName, + params: [BRIDGE_ID], + methodName: "ClientIDAccountBalance", + invocationType: FabricContractInvocationType.Send, + signingCredential: fabricSigningCredential, + }); + + expect(responseBalance1).not.toBeUndefined(); + expect(responseBalance1.status).toBeGreaterThan(199); + expect(responseBalance1.status).toBeLessThan(300); + expect(responseBalance1.data).not.toBeUndefined(); + expect(responseBalance1.data.functionOutput).toBe("0"); + log.info("Amount was transfer correctly from the Bridge account"); + + const responseBalance2 = await apiClient.runTransactionV1({ + contractName: satpContractName, + channelName: fabricChannelName, + params: [clientId], + methodName: "ClientIDAccountBalance", + invocationType: FabricContractInvocationType.Send, + signingCredential: fabricSigningCredential, + }); + expect(responseBalance2).not.toBeUndefined(); + expect(responseBalance2.status).toBeGreaterThan(199); + expect(responseBalance2.status).toBeLessThan(300); + expect(responseBalance2.data).not.toBeUndefined(); + expect(responseBalance2.data.functionOutput).toBe("1"); + log.info("Amount was transfer correctly to the Owner account"); + + await gateway1.shutdown(); + await gateway2.shutdown(); + }); +}); diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/services.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/services.test.ts index 4782c1d440..40fa1fc8a8 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/services.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/services.test.ts @@ -20,6 +20,7 @@ import { Stage3ServerService } from "../../../main/typescript/core/stage-service import { SATPSession } from "../../../main/typescript/core/satp-session"; import { SATP_VERSION } from "../../../main/typescript/core/constants"; import { + Asset, AssignmentAssertionClaim, BurnAssertionClaim, CredentialProfile, @@ -49,10 +50,22 @@ import { } from "../../../main/typescript/generated/proto/cacti/satp/v02/stage_3_pb"; import { getMessageHash } from "../../../main/typescript/core/session-utils"; +import { Stage0ClientService } from "../../../main/typescript/core/stage-services/client/stage0-client-service"; +import { Stage0ServerService } from "../../../main/typescript/core/stage-services/server/stage0-server-service"; +import { + NewSessionRequest, + NewSessionResponse, + PreSATPTransferRequest, + PreSATPTransferResponse, + STATUS, +} from "../../../main/typescript/generated/proto/cacti/satp/v02/stage_0_pb"; +import { TokenType } from "../../../main/typescript/core/stage-services/satp-bridge/types/asset"; const logLevel: LogLevelDesc = "DEBUG"; const serviceClasses = [ + Stage0ClientService, + Stage0ServerService, Stage1ServerService, Stage1ClientService, Stage2ServerService, @@ -73,6 +86,8 @@ let bridgeManager: SATPBridgesManager; let mockSession: SATPSession; +let satpClientService0: Stage0ClientService; +let satpServerService0: Stage0ServerService; let satpClientService1: Stage1ClientService; let satpClientService2: Stage2ClientService; let satpClientService3: Stage3ClientService; @@ -80,6 +95,10 @@ let satpServerService1: Stage1ServerService; let satpServerService2: Stage2ServerService; let satpServerService3: Stage3ServerService; +let newSessionRequestMessage: NewSessionRequest; +let newSessionResponseMessage: NewSessionResponse; +let preSATPTransferRequestMessage: PreSATPTransferRequest; +let preSATPTransferResponseMessage: PreSATPTransferResponse; let transferProposalRequestMessage: TransferProposalRequestMessage; let transferProposalResponseMessage: TransferProposalReceiptMessage; let transferCommenceRequestMessage: TransferCommenceRequestMessage; @@ -92,6 +111,8 @@ let commitFinalAssertionRequestMessage: CommitFinalAssertionRequestMessage; let commitFinalAcknowledgementReceiptResponseMessage: CommitFinalAcknowledgementReceiptResponseMessage; let transferCompleteRequestMessage: TransferCompleteRequestMessage; +const sessionIDs: string[] = []; + beforeAll(async () => { bridgeManager = new SATPBridgesManager({ supportedDLTs: supportedDLTs, @@ -101,10 +122,12 @@ beforeAll(async () => { mockSession = new SATPSession({ contextID: "MOCK_CONTEXT_ID", - server: true, + server: false, client: true, }); + sessionIDs.push(mockSession.getSessionId()); + const serviceOptions = initializeServiceOptions( serviceClasses, logLevel, @@ -113,6 +136,12 @@ beforeAll(async () => { for (const service of initializeServices(serviceClasses, serviceOptions)) { switch (service.constructor) { + case Stage0ClientService: + satpClientService0 = service as Stage0ClientService; + break; + case Stage0ServerService: + satpServerService0 = service as Stage0ServerService; + break; case Stage1ServerService: satpServerService1 = service as Stage1ServerService; break; @@ -137,12 +166,7 @@ beforeAll(async () => { } }); describe("SATP Services Testing", () => { - it("Service1Client transferProposalRequest", async () => { - expect(satpClientService1).toBeDefined(); - expect(satpClientService1.getServiceIdentifier()).toBe( - `${SATPServiceType.Client}#1`, - ); - + it("Service0Client newSessionRequest", async () => { const sessionData = mockSession.getClientSessionData(); if (!sessionData) { throw new Error("Session data not found"); @@ -162,8 +186,8 @@ describe("SATP Services Testing", () => { sessionData.verifiedBeneficiaryEntityId = "MOCK_VERIFIED_BENEFICIARY_ENTITY_ID"; sessionData.receiverGatewayOwnerId = "MOCK_RECEIVER_GATEWAY_OWNER_ID"; - sessionData.recipientGatewayNetworkId = "MOCK_RECIPIENT_GATEWAY_NETWORK_ID"; - sessionData.senderGatewayOwnerId = SupportedChain.FABRIC; + sessionData.recipientGatewayNetworkId = SupportedChain.FABRIC; + sessionData.senderGatewayOwnerId = "MOCK_SENDER_GATEWAY_OWNER_ID"; sessionData.senderGatewayNetworkId = SupportedChain.BESU; sessionData.signatureAlgorithm = SignatureAlgorithm.RSA; sessionData.lockType = LockType.FAUCET; @@ -173,6 +197,209 @@ describe("SATP Services Testing", () => { sessionData.accessControlProfile = "MOCK_ACCESS_CONTROL_PROFILE"; sessionData.resourceUrl = "MOCK_RESOURCE_URL"; sessionData.lockAssertionExpiration = BigInt(99999); + sessionData.receiverContractOntology = "MOCK_RECEIVER_CONTRACT_ONTOLOGY"; //TODO when implemented verification of Contract Ontology change this + sessionData.senderContractOntology = "MOCK_SENDER_CONTRACT_ONTOLOGY"; + sessionData.sourceLedgerAssetId = "MOCK_SOURCE_LEDGER_ASSET_ID"; + sessionData.senderAsset = new Asset(); + sessionData.senderAsset.tokenId = "MOCK_TOKEN_ID"; + sessionData.senderAsset.tokenType = TokenType.ERC20; + sessionData.senderAsset.amount = BigInt(0); + sessionData.senderAsset.owner = "MOCK_SENDER_ASSET_OWNER"; + sessionData.senderAsset.ontology = "MOCK_SENDER_ASSET_ONTOLOGY"; + sessionData.senderAsset.contractName = "MOCK_SENDER_ASSET_CONTRACT_NAME"; + sessionData.senderAsset.contractAddress = + "MOCK_SENDER_ASSET_CONTRACT_ADDRESS"; + sessionData.receiverAsset = new Asset(); + + sessionData.receiverAsset.tokenType = TokenType.ERC20; + sessionData.receiverAsset.amount = BigInt(0); + sessionData.receiverAsset.owner = "MOCK_RECEIVER_ASSET_OWNER"; + sessionData.receiverAsset.ontology = "MOCK_RECEIVER_ASSET_ONTOLOGY"; + sessionData.receiverAsset.contractName = + "MOCK_RECEIVER_ASSET_CONTRACT_NAME"; + sessionData.receiverAsset.mspId = "MOCK_RECEIVER_ASSET_MSP_ID"; + sessionData.receiverAsset.channelName = "MOCK_CHANNEL_ID"; + expect(satpClientService1).toBeDefined(); + expect(satpClientService1.getServiceIdentifier()).toBe( + `${SATPServiceType.Client}#1`, + ); + + newSessionRequestMessage = await satpClientService0.newSessionRequest( + mockSession, + SupportedChain.BESU, + ); + + expect(newSessionRequestMessage).toBeDefined(); + expect(newSessionRequestMessage.contextId).toBe( + mockSession.getClientSessionData()?.transferContextId, + ); + expect(newSessionRequestMessage.senderGatewayNetworkId).toBe( + mockSession.getClientSessionData().senderGatewayNetworkId, + ); + expect(newSessionRequestMessage.recipientGatewayNetworkId).toBe( + mockSession.getClientSessionData().recipientGatewayNetworkId, + ); + expect(newSessionRequestMessage.clientSignature).not.toBe(""); + }); + it("Service0Server checkNewSessionRequest", async () => { + expect(satpServerService0).toBeDefined(); + expect(satpServerService0.getServiceIdentifier()).toBe( + `${SATPServiceType.Server}#0`, + ); + + await satpServerService0.checkNewSessionRequest( + newSessionRequestMessage, + mockSession, + Buffer.from(keyPairs.publicKey).toString("hex"), + ); + + expect(mockSession.getServerSessionData()).toBeDefined(); + expect(mockSession.getServerSessionData()?.transferContextId).toBe( + newSessionRequestMessage.contextId, + ); + expect(mockSession.getServerSessionData()?.senderGatewayNetworkId).toBe( + newSessionRequestMessage.senderGatewayNetworkId, + ); + expect(mockSession.getServerSessionData()?.recipientGatewayNetworkId).toBe( + newSessionRequestMessage.recipientGatewayNetworkId, + ); + }); + it("Service0Server newSessionResponse", async () => { + newSessionResponseMessage = await satpServerService0.newSessionResponse( + newSessionRequestMessage, + mockSession, + ); + + expect(newSessionResponseMessage).toBeDefined(); + expect(newSessionResponseMessage.contextId).toBe( + mockSession.getClientSessionData()?.transferContextId, + ); + expect(newSessionResponseMessage.senderGatewayNetworkId).toBe( + mockSession.getClientSessionData().senderGatewayNetworkId, + ); + expect(newSessionResponseMessage.recipientGatewayNetworkId).toBe( + mockSession.getClientSessionData().recipientGatewayNetworkId, + ); + expect(newSessionResponseMessage.status).toBe(STATUS.STATUS_ACCEPTED); + expect(newSessionResponseMessage.hashPreviousMessage).not.toBe(""); + expect(newSessionResponseMessage.serverSignature).not.toBe(""); + }); + it("Service0Client checkNewSessionResponse", async () => { + expect(satpClientService0).toBeDefined(); + expect(satpClientService0.getServiceIdentifier()).toBe( + `${SATPServiceType.Client}#0`, + ); + + await satpClientService0.checkNewSessionResponse( + newSessionResponseMessage, + mockSession, + sessionIDs, + ); + }); + it("Service0Client preSATPTransferRequest", async () => { + expect(satpClientService0).toBeDefined(); + expect(satpClientService0.getServiceIdentifier()).toBe( + `${SATPServiceType.Client}#0`, + ); + + const sessionData = mockSession.getClientSessionData(); + if (!sessionData) { + throw new Error("Session data not found"); + } + + sessionData.senderWrapAssertionClaim = new AssignmentAssertionClaim(); + + preSATPTransferRequestMessage = + await satpClientService0.preSATPTransferRequest(mockSession); + + expect(preSATPTransferRequestMessage).toBeDefined(); + expect(preSATPTransferRequestMessage.sessionId).toBe(sessionData.id); + expect(preSATPTransferRequestMessage.contextId).toBe( + sessionData.transferContextId, + ); + expect(preSATPTransferRequestMessage.senderGatewayNetworkId).toBe( + sessionData.senderGatewayNetworkId, + ); + expect(preSATPTransferRequestMessage.recipientGatewayNetworkId).toBe( + sessionData.recipientGatewayNetworkId, + ); + expect(preSATPTransferRequestMessage.senderAsset).toBeDefined(); + expect(preSATPTransferRequestMessage.receiverAsset).toBeDefined(); + expect(preSATPTransferRequestMessage.wrapAssertionClaim).toBeDefined(); + expect(preSATPTransferRequestMessage.hashPreviousMessage).toBeDefined(); + expect(preSATPTransferRequestMessage.clientSignature).toBeDefined(); + }); + it("Service0Server checkPreSATPTransferRequest", async () => { + expect(satpServerService0).toBeDefined(); + expect(satpServerService0.getServiceIdentifier()).toBe( + `${SATPServiceType.Server}#0`, + ); + + await satpServerService0.checkPreSATPTransferRequest( + preSATPTransferRequestMessage, + mockSession, + ); + + expect(mockSession.getServerSessionData()).toBeDefined(); + expect(mockSession.getServerSessionData()?.senderAsset).toBe( + preSATPTransferRequestMessage.senderAsset, + ); + expect(mockSession.getServerSessionData()?.receiverAsset).toBe( + preSATPTransferRequestMessage.receiverAsset, + ); + }); + it("Service0Server preSATPTransferResponse", async () => { + const sessionData = mockSession.getServerSessionData(); + if (!sessionData) { + throw new Error("Session data not found"); + } + + sessionData.receiverWrapAssertionClaim = new AssignmentAssertionClaim(); + + preSATPTransferResponseMessage = + await satpServerService0.preSATPTransferResponse( + preSATPTransferRequestMessage, + mockSession, + ); + + expect(preSATPTransferResponseMessage).toBeDefined(); + expect(preSATPTransferResponseMessage.sessionId).toBe( + preSATPTransferRequestMessage.sessionId, + ); + expect(preSATPTransferResponseMessage.contextId).toBe( + newSessionResponseMessage.contextId, + ); + expect(preSATPTransferResponseMessage.wrapAssertionClaim).toBeDefined(); + expect(preSATPTransferResponseMessage.hashPreviousMessage).toBeDefined(); + expect(preSATPTransferResponseMessage.serverSignature).toBeDefined(); + expect(preSATPTransferResponseMessage.recipientTokenId).toBeDefined(); + }); + it("Service1Client checkPreSATPTransferResponse", async () => { + expect(satpClientService1).toBeDefined(); + expect(satpClientService1.getServiceIdentifier()).toBe( + `${SATPServiceType.Client}#1`, + ); + + await satpClientService1.checkPreSATPTransferResponse( + preSATPTransferResponseMessage, + mockSession, + ); + + expect(mockSession.getClientSessionData()).toBeDefined(); + expect(mockSession.getClientSessionData()?.receiverAsset?.tokenId).toBe( + preSATPTransferResponseMessage.recipientTokenId, + ); + }); + it("Service1Client transferProposalRequest", async () => { + expect(satpClientService1).toBeDefined(); + expect(satpClientService1.getServiceIdentifier()).toBe( + `${SATPServiceType.Client}#1`, + ); + + const sessionData = mockSession.getClientSessionData(); + if (!sessionData) { + throw new Error("Session data not found"); + } transferProposalRequestMessage = (await satpClientService1.transferProposalRequest( @@ -219,10 +446,14 @@ describe("SATP Services Testing", () => { ).toBe("MOCK_RECEIVER_GATEWAY_OWNER_ID"); expect( transferProposalRequestMessage.transferInitClaims?.senderGatewayOwnerId, - ).toBe(SupportedChain.FABRIC); + ).toBe("MOCK_SENDER_GATEWAY_OWNER_ID"); expect( transferProposalRequestMessage.transferInitClaims?.senderGatewayNetworkId, ).toBe(SupportedChain.BESU); + expect( + transferProposalRequestMessage.transferInitClaims + ?.recipientGatewayNetworkId, + ).toBe(SupportedChain.FABRIC); expect( transferProposalRequestMessage.networkCapabilities?.signatureAlgorithm, ).toBe(SignatureAlgorithm.RSA); @@ -364,15 +595,13 @@ describe("SATP Services Testing", () => { it("Service2Client lockAssertionRequest", async () => { //mock claims - (mockSession.getClientSessionData() as SessionData).lockAssertionClaim = + mockSession.getClientSessionData().lockAssertionClaim = new LockAssertionClaim(); - ( - mockSession.getClientSessionData() as SessionData - ).lockAssertionClaimFormat = new LockAssertionClaim(); + mockSession.getClientSessionData().lockAssertionClaimFormat = + new LockAssertionClaim(); - (mockSession.getClientSessionData() as SessionData).lockExpirationTime = - BigInt(1000); + mockSession.getClientSessionData().lockExpirationTime = BigInt(1000); lockAssertionRequestMessage = (await satpClientService2.lockAssertionRequest( diff --git a/yarn.lock b/yarn.lock index a7c63bdb6e..11a8959a0b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5879,7 +5879,7 @@ __metadata: languageName: node linkType: hard -"@bufbuild/protobuf@npm:1.10.0, @bufbuild/protobuf@npm:^1.6.0": +"@bufbuild/protobuf@npm:1.10.0": version: 1.10.0 resolution: "@bufbuild/protobuf@npm:1.10.0" checksum: 10/1f120f72bbb40dd3d0f8c73f1474b001cfb9be09c38b7b0292e35fec98c5184a3db380a6feff7626fb3fff108c8a8aa7fc8cfea14904dc0a1174a01c8e637cc6 @@ -5956,17 +5956,6 @@ __metadata: languageName: node linkType: hard -"@bufbuild/protoplugin@npm:^1.6.0": - version: 1.10.0 - resolution: "@bufbuild/protoplugin@npm:1.10.0" - dependencies: - "@bufbuild/protobuf": "npm:1.10.0" - "@typescript/vfs": "npm:^1.4.0" - typescript: "npm:4.5.2" - checksum: 10/829a6d64076a16d7a89e732be39f1988b52b8babee215d91a5f692e0e6ac3e2b58ea4012bd7707c3cef4b6952cfcc36076b646aa09ed68888aedb2fb004d659f - languageName: node - linkType: hard - "@chainsafe/as-sha256@npm:^0.3.1": version: 0.3.1 resolution: "@chainsafe/as-sha256@npm:0.3.1" @@ -6233,19 +6222,6 @@ __metadata: languageName: node linkType: hard -"@connectrpc/connect-express@npm:1.3.0": - version: 1.3.0 - resolution: "@connectrpc/connect-express@npm:1.3.0" - dependencies: - "@types/express": "npm:^4.17.18" - peerDependencies: - "@bufbuild/protobuf": ^1.4.2 - "@connectrpc/connect": 1.3.0 - "@connectrpc/connect-node": 1.3.0 - checksum: 10/581495391477e2b8a2738bdc34dbf45a245d26cb4943a5b3d1813d80ae4f11d85e0d0f01d95e408e7b1cb7812a873218428d6b0cde9fc643747f06e8b7205627 - languageName: node - linkType: hard - "@connectrpc/connect-express@npm:1.4.0": version: 1.4.0 resolution: "@connectrpc/connect-express@npm:1.4.0" @@ -6271,18 +6247,6 @@ __metadata: languageName: node linkType: hard -"@connectrpc/connect-node@npm:1.3.0": - version: 1.3.0 - resolution: "@connectrpc/connect-node@npm:1.3.0" - dependencies: - undici: "npm:^5.28.2" - peerDependencies: - "@bufbuild/protobuf": ^1.4.2 - "@connectrpc/connect": 1.3.0 - checksum: 10/34b4903220881b39128bc31c79a0a006cb44c7cb9074fd0d77e853ff016f51c2a131811421c971c01210d4329068026c278cf64d349f2eb38126d0604710816a - languageName: node - linkType: hard - "@connectrpc/connect-node@npm:1.4.0": version: 1.4.0 resolution: "@connectrpc/connect-node@npm:1.4.0" @@ -6305,15 +6269,6 @@ __metadata: languageName: node linkType: hard -"@connectrpc/connect@npm:1.3.0": - version: 1.3.0 - resolution: "@connectrpc/connect@npm:1.3.0" - peerDependencies: - "@bufbuild/protobuf": ^1.4.2 - checksum: 10/7707d97ee6e4a83cc03371b1da1709c103f0338e85b2fbf49813053d96114818d34831b1c11715cc9badcc3ce5d4c9fbc423af4b6a8efa953bf0ef76cdc6e50d - languageName: node - linkType: hard - "@connectrpc/connect@npm:1.4.0": version: 1.4.0 resolution: "@connectrpc/connect@npm:1.4.0" @@ -6323,26 +6278,6 @@ __metadata: languageName: node linkType: hard -"@connectrpc/protoc-gen-connect-es@npm:1.3.0": - version: 1.3.0 - resolution: "@connectrpc/protoc-gen-connect-es@npm:1.3.0" - dependencies: - "@bufbuild/protobuf": "npm:^1.6.0" - "@bufbuild/protoplugin": "npm:^1.6.0" - peerDependencies: - "@bufbuild/protoc-gen-es": ^1.6.0 - "@connectrpc/connect": 1.3.0 - peerDependenciesMeta: - "@bufbuild/protoc-gen-es": - optional: true - "@connectrpc/connect": - optional: true - bin: - protoc-gen-connect-es: bin/protoc-gen-connect-es - checksum: 10/23a17bef378ac2fa414fb35fe50a7630134946a086f75f9201c5d0c3631f32e61445628b0420eac7353e88193e170059969bc83bad96a9f43cb98db30243aa1c - languageName: node - linkType: hard - "@connectrpc/protoc-gen-connect-es@npm:1.4.0": version: 1.4.0 resolution: "@connectrpc/protoc-gen-connect-es@npm:1.4.0" @@ -10854,11 +10789,13 @@ __metadata: "@bufbuild/buf": "npm:1.29.0" "@bufbuild/protobuf": "npm:1.7.2" "@bufbuild/protoc-gen-es": "npm:1.7.2" - "@connectrpc/connect": "npm:1.3.0" - "@connectrpc/connect-express": "npm:1.3.0" - "@connectrpc/connect-node": "npm:1.3.0" - "@connectrpc/protoc-gen-connect-es": "npm:1.3.0" + "@connectrpc/connect": "npm:1.4.0" + "@connectrpc/connect-express": "npm:1.4.0" + "@connectrpc/connect-node": "npm:1.4.0" + "@connectrpc/protoc-gen-connect-es": "npm:1.4.0" "@foundry-rs/hardhat-forge": "npm:0.1.17" + "@grpc/grpc-js": "npm:1.11.1" + "@grpc/proto-loader": "npm:0.7.8" "@hyperledger/cactus-cmd-api-server": "npm:2.0.0-rc.3" "@hyperledger/cactus-common": "npm:2.0.0-rc.3" "@hyperledger/cactus-core": "npm:2.0.0-rc.3" @@ -10875,6 +10812,7 @@ __metadata: "@types/crypto-js": "npm:4.0.1" "@types/express": "npm:4.17.21" "@types/fs-extra": "npm:11.0.4" + "@types/google-protobuf": "npm:3.15.5" "@types/node": "npm:18.18.2" "@types/swagger-ui-express": "npm:4.1.6" "@types/tape": "npm:4.13.4" @@ -10890,11 +10828,17 @@ __metadata: express: "npm:4.19.2" fabric-network: "npm:2.2.20" fs-extra: "npm:11.2.0" + google-protobuf: "npm:3.21.2" + grpc-tools: "npm:1.12.4" + grpc_tools_node_protoc_ts: "npm:5.3.3" hardhat: "npm:2.22.5" knex: "npm:2.4.0" kubo-rpc-client: "npm:3.0.1" + make-dir-cli: "npm:3.1.0" npm-run-all: "npm:4.1.5" openzeppelin-solidity: "npm:3.4.2" + protobufjs: "npm:7.2.5" + safe-stable-stringify: "npm:^2.5.0" secp256k1: "npm:4.0.3" socket.io: "npm:4.6.2" sqlite3: "npm:5.1.5" @@ -46386,6 +46330,13 @@ __metadata: languageName: node linkType: hard +"safe-stable-stringify@npm:^2.5.0": + version: 2.5.0 + resolution: "safe-stable-stringify@npm:2.5.0" + checksum: 10/2697fa186c17c38c3ca5309637b4ac6de2f1c3d282da27cd5e1e3c88eca0fb1f9aea568a6aabdf284111592c8782b94ee07176f17126031be72ab1313ed46c5c + languageName: node + linkType: hard + "safer-buffer@npm:>= 2.1.2 < 3, safer-buffer@npm:>= 2.1.2 < 3.0.0, safer-buffer@npm:^2.0.2, safer-buffer@npm:^2.1.0, safer-buffer@npm:~2.1.0": version: 2.1.2 resolution: "safer-buffer@npm:2.1.2" @@ -50941,7 +50892,7 @@ __metadata: languageName: node linkType: hard -"undici@npm:^5.28.2, undici@npm:^5.28.3": +"undici@npm:^5.28.3": version: 5.28.4 resolution: "undici@npm:5.28.4" dependencies: