diff --git a/.cspell.json b/.cspell.json index 183af22e39..2b299b1fd5 100644 --- a/.cspell.json +++ b/.cspell.json @@ -99,6 +99,7 @@ "Hursley", "HyperLedger", "immalleable", + "imodule", "ipaddress", "ipfs", "IPFSHTTP", diff --git a/.eslintignore b/.eslintignore index 90af78ce16..7d838527cc 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,6 +1,7 @@ **/node_modules/** **/dist/** - +**/build/** +docs/* examples/cactus-example-carbon-accounting-frontend/www/ examples/cactus-example-supply-chain-frontend/www/ weaver/core/identity-management/iin-agent/out/ @@ -32,6 +33,8 @@ weaver/common/policy-dsl/parser/PolicyParser.js weaver/common/policy-dsl/test/MyErrorListener.js weaver/common/policy-dsl/test/MyParseTreeVisitor.js weaver/common/protos-js/driver/driver_grpc_pb.js +weaver/common/protos-sol/solidity-protos/soltest/test/TestFixture.js +weaver/common/protos-sol/solidity-protos/soltest/migrations/1_deploy_contract.js weaver/core/drivers/fabric-driver/server/dbConnector.ts weaver/core/drivers/fabric-driver/server/events.ts weaver/core/drivers/fabric-driver/server/fabric-code.ts @@ -106,3 +109,4 @@ weaver/sdks/fabric/interoperation-node-sdk/src/helpers.ts weaver/sdks/fabric/interoperation-node-sdk/test/AssetManager.js weaver/sdks/fabric/interoperation-node-sdk/test/InteroperableHelper.js weaver/sdks/fabric/interoperation-node-sdk/test/Relay.js +weaver/sdks/fabric/interoperation-node-sdk/protos-js/driver/driver_grpc_pb.js diff --git a/.github/actions/copm_test/action.yaml b/.github/actions/copm_test/action.yaml index f02a3a2e16..9df29a8571 100644 --- a/.github/actions/copm_test/action.yaml +++ b/.github/actions/copm_test/action.yaml @@ -1,8 +1,22 @@ name: 'Copm Test' description: "common setup steps for the weaver network needed to run copm tests" +inputs: + github-actor: + description: the github actor variable + required: true + github-token: + description: the github secret token variable + required: true runs: using: "composite" steps: + - name: free github runner disk space + shell: bash + run: | + sudo rm -rf /usr/share/dotnet + sudo rm -rf /opt/ghc + sudo rm -rf "/usr/local/share/boost" + sudo rm -rf "$AGENT_TOOLSDIRECTORY" - name: Use Node.js ${{ env.NODEJS_VERSION }} uses: actions/setup-node@v4.0.2 with: @@ -22,6 +36,9 @@ runs: cargo update -p nom cargo update -p lexical-core working-directory: weaver/core/relay + - uses: actions/setup-go@v4 + with: + go-version: '1.20.2' - name: Use Protoc 3.15 shell: bash run: | @@ -29,8 +46,25 @@ runs: unzip protoc-3.15.6-linux-x86_64.zip -d protoc go install google.golang.org/protobuf/cmd/protoc-gen-go@latest go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.4.0 - # PROTOS - - name: Build local weaver dependencies - run: make setup --trace + - name: Set up JDK 17 + uses: actions/setup-java@v3.11.0 + with: + java-version: '17' + distribution: 'adopt' + - name: Generate github.properties shell: bash - working-directory: packages/cacti-plugin-copm-fabric + run: | + echo "Using ${{ inputs.github-actor }} user." + { + echo "username=${{ inputs.github-actor }}" + echo "password=${{ inputs.github-token }}" + echo "url=https://maven.pkg.github.com/hyperledger/cacti" + } >> github.properties + { + echo "username=${{ inputs.github-actor }}" + echo "password=${{ inputs.github-token }}" + echo "url=https://maven.pkg.github.com/hyperledger/cacti" + } >> github.main.properties + working-directory: weaver/tests/network-setups/corda + + diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5f3c1e4eff..d32c50cc8b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -64,7 +64,7 @@ jobs: plugin-htlc-coordinator-besu-changed: ${{ steps.changes.outputs.plugin-htlc-coordinator-besu-changed }} test-tooling-changed: ${{ steps.changes.outputs.test-tooling-changed }} ghcr-dev-container-vscode-changed: ${{ steps.changes.outputs.ghcr-dev-container-vscode-changed }} - plugin-copm-fabric-changed: ${{ steps.changes.outputs.plugin-copm-fabric-changed }} + copm-changed: ${{ steps.changes.outputs.copm-changed }} runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4.1.7 @@ -175,9 +175,15 @@ jobs: - './packages/cactus-plugin-keychain-memory/**' # - './.github/workflows/ci.yaml' - plugin-copm-fabric-changed: + copm-changed: + - './packages/cactus-common/**' + - './packages/cactus-core/**' + - './packages/cactus-core-api/**' - './packages/cacti-copm-common/**' + - './packages/cacti-copm-test/**' - './packages/cacti-plugin-copm-fabric/**' + - './packages/cacti-plugin-copm-corda/**' + - './weaver/**' build-dev: needs: check-ci-skip @@ -1471,7 +1477,7 @@ jobs: needs: - build-dev - compute_changed_packages - if: needs.compute_changed_packages.outputs.plugin-copm-fabric-changed == 'true' + if: needs.compute_changed_packages.outputs.copm-changed == 'true' uses: ./.github/workflows/test_copm.yaml diff --git a/.github/workflows/test_copm.yaml b/.github/workflows/test_copm.yaml index c1e18fe6c3..d2d06ea417 100644 --- a/.github/workflows/test_copm.yaml +++ b/.github/workflows/test_copm.yaml @@ -8,62 +8,84 @@ env: RUN_CODE_COVERAGE: true jobs: - copm-fabric-fabric-pledge-and-provestate: - continue-on-error: false - env: - CACTI_NPM_PACKAGE_NAME: "@hyperledger-cacti/cacti-plugin-copm-fabric" - HFC_LOGGING: '{"debug":"console","info":"console","warn": "console","error":"console"}' - FULL_BUILD_DISABLED: true - FREE_UP_GITHUB_RUNNER_DISK_SPACE_DISABLED: false - JEST_TEST_PATTERN: packages/cacti-plugin-copm-fabric/src/test/typescript/integration/test-copm-pledge-claim.test.ts packages/cacti-plugin-copm-fabric/src/test/typescript/integration/test-copm-getverifiedview.test.ts - JEST_TEST_RUNNER_DISABLED: false - JEST_TEST_COVERAGE_PATH: ./code-coverage-ts/plc-copm-fabric-fabric-pledge - JEST_TEST_CODE_COVERAGE_ENABLED: true - TAPE_TEST_PATTERN: "" - TAPE_TEST_RUNNER_DISABLED: true - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v4.1.1 - - uses: ./.github/actions/copm_test/ - - name: Make the fabric network - run: make pledge-network --trace - working-directory: packages/cacti-plugin-copm-fabric - - name: show the running network - run: docker container ls - - run: ./tools/ci.sh - - name: Upload coverage reports as artifacts - if: ${{ env.RUN_CODE_COVERAGE == 'true' }} - uses: actions/upload-artifact@v4.3.3 - with: - name: coverage-reports-copm-fabric - path: ./code-coverage-ts/**/ + matrix-pledge-and-getview: + name: pledge-getview-${{ matrix.net1 }}-${{ matrix.net2 }} + strategy: + fail-fast: false + matrix: + net1: ["fabric", "corda"] + net2: ["fabric", "corda"] + env: + FULL_BUILD_DISABLED: true + FREE_UP_GITHUB_RUNNER_DISK_SPACE_DISABLED: false + JEST_TEST_PATTERN: packages/cacti-copm-test/src/test/typescript/integration/test-copm-getverifiedview.test.ts packages/cacti-copm-test/src/test/typescript/integration/test-copm-pledge-claim.test.ts + JEST_TEST_RUNNER_DISABLED: false + JEST_TEST_COVERAGE_PATH: ./code-coverage-ts/copm-pledge-${{ matrix.net1 }}-${{ matrix.net2}} + JEST_TEST_CODE_COVERAGE_ENABLED: true + TAPE_TEST_PATTERN: '' + TAPE_TEST_RUNNER_DISABLED: true + COPM_NET_1: ${{ matrix.net1 }} + COPM_NET_2: ${{ matrix.net2 }} + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4.1.1 + - uses: ./.github/actions/copm_test/ + with: + github-actor: ${GITHUB_ACTOR} + github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Make the ${{matrix.net1}} network + run: | + make -f Makefile_${{matrix.net1}} setup pledge-network + working-directory: packages/cacti-copm-test + - name: Make the ${{matrix.net2}} network + run: | + make -f Makefile_${{matrix.net2}} setup pledge-network + working-directory: packages/cacti-copm-test + if: ${{ matrix.net1 != matrix.net2 }} + - name: show the running network + run: docker container ls + - run: ./tools/ci.sh + - name: Upload coverage reports as artifacts + if: ${{ env.RUN_CODE_COVERAGE == 'true' }} + uses: actions/upload-artifact@v4.3.3 + with: + name: copm-pledge-${{ matrix.net1 }}-${{ matrix.net2}} + path: ./code-coverage-ts/**/ - copm-fabric-fabric-lock: - continue-on-error: false - env: - CACTI_NPM_PACKAGE_NAME: "@hyperledger-cacti/cacti-plugin-copm-fabric" - HFC_LOGGING: '{"debug":"console","info":"console","warn": "console","error":"console"}' - FULL_BUILD_DISABLED: true - FREE_UP_GITHUB_RUNNER_DISK_SPACE_DISABLED: false - JEST_TEST_PATTERN: packages/cacti-plugin-copm-fabric/src/test/typescript/integration/test-copm-lock-claim.test.ts - JEST_TEST_RUNNER_DISABLED: false - JEST_TEST_COVERAGE_PATH: ./code-coverage-ts/plc-copm-fabric-fabric-lock - JEST_TEST_CODE_COVERAGE_ENABLED: true - TAPE_TEST_PATTERN: "" - TAPE_TEST_RUNNER_DISABLED: true - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v4.1.1 - - uses: ./.github/actions/copm_test/ - - name: Make the fabric network - run: make lock-network --trace - working-directory: packages/cacti-plugin-copm-fabric - - name: show the running network - run: docker container ls - - run: ./tools/ci.sh - - name: Upload coverage reports as artifacts - if: ${{ env.RUN_CODE_COVERAGE == 'true' }} - uses: actions/upload-artifact@v4.3.3 - with: - name: coverage-reports-copm-fabric-lock - path: ./code-coverage-ts/**/ + matrix-lock: + name: lock-${{ matrix.net1 }} + strategy: + fail-fast: false + matrix: + net1: ["fabric", "corda"] + env: + FULL_BUILD_DISABLED: true + FREE_UP_GITHUB_RUNNER_DISK_SPACE_DISABLED: false + TAPE_TEST_PATTERN: '' + TAPE_TEST_RUNNER_DISABLED: true + JEST_TEST_PATTERN: packages/cacti-copm-test/src/test/typescript/integration/test-copm-lock-claim.test.ts + JEST_TEST_RUNNER_DISABLED: false + JEST_TEST_COVERAGE_PATH: ./code-coverage-ts/copm-lock-${{ matrix.net1 }} + JEST_TEST_CODE_COVERAGE_ENABLED: true + COPM_NET_1: ${{ matrix.net1 }} + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4.1.1 + - uses: ./.github/actions/copm_test/ + with: + github-actor: ${GITHUB_ACTOR} + github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Make the ${{matrix.net1}} network + run: | + make -f Makefile_${{matrix.net1}} setup lock-network + working-directory: packages/cacti-copm-test + - name: show the running network + run: docker container ls + - run: ./tools/ci.sh + - name: Upload coverage reports as artifacts + if: ${{ env.RUN_CODE_COVERAGE == 'true' }} + uses: actions/upload-artifact@v4.3.3 + with: + name: copm-lock-${{ matrix.net1 }} + path: ./code-coverage-ts/**/ + diff --git a/jest.config.js b/jest.config.js index 1887b60017..e858658b36 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,6 +6,7 @@ module.exports = { moduleNameMapper: { "^(\\.\\.?\\/.+)\\.jsx?$": "$1", }, + modulePathIgnorePatterns: ["./weaver/core"], maxWorkers: 1, maxConcurrency: 1, setupFilesAfterEnv: ["jest-extended/all", "./jest.setup.console.logs.js"], diff --git a/packages/cacti-copm-core/package.json b/packages/cacti-copm-core/package.json index 98e83126f1..e9f9470f0b 100644 --- a/packages/cacti-copm-core/package.json +++ b/packages/cacti-copm-core/package.json @@ -24,7 +24,7 @@ "codegen:proto": "yarn run proto:openapi; yarn run proto:connectrpc", "dev:redo": "yarn run bundleopenapi; yarn run codegen:proto", "proto:connectrpc": "yarn run buf generate --template=./buf.gen.yaml ./src/main/proto/generated/openapi", - "proto:openapi": "yarn run --top-level openapi-generator-cli generate -i ./src/main/json/openapi.json -g protobuf-schema --model-name-suffix=PB --language-specific-primitives=google.protobuf.Any --type-mappings=AnyType=google.protobuf.Any --type-mappings=object=google.protobuf.Any --additional-properties=packageName=org.hyperledger.cacti.plugin.cacti.plugin.copm.core -o ./src/main/proto/generated/openapi/ -t=./src/main/mustache/openapi-generator/templates/protobuf-schema/ --ignore-file-override ../../openapi-generator-ignore" + "proto:openapi": "yarn run --top-level openapi-generator-cli generate -i ./src/main/json/openapi.json -g protobuf-schema --model-name-suffix=PB --language-specific-primitives=google.protobuf.Any --type-mappings=AnyType=google.protobuf.Any --type-mappings=object=google.protobuf.Any --additional-properties=packageName=org.hyperledger.cacti.plugin.copm.core -o ./src/main/proto/generated/openapi/ -t=./src/main/mustache/openapi-generator/templates/protobuf-schema/ --ignore-file-override ../../openapi-generator-ignore" }, "dependencies": { "@bufbuild/buf": "1.30.0", diff --git a/packages/cacti-copm-core/src/main/json/openapi.json b/packages/cacti-copm-core/src/main/json/openapi.json index 4fc4e21e48..1e01d532e9 100644 --- a/packages/cacti-copm-core/src/main/json/openapi.json +++ b/packages/cacti-copm-core/src/main/json/openapi.json @@ -3,7 +3,7 @@ "info": { "title": "Hyperledger Cacti Plugin - Common Operator Primitives", "description": "Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/.", - "version": "2.0.0-rc.2", + "version": "2.0.0", "license": { "name": "Apache-2.0", "url": "https://www.apache.org/licenses/LICENSE-2.0.html" @@ -132,26 +132,31 @@ "asset_id": "ref203" } }, - "owner": { + "source": { "type": "object", "$ref": "#/components/schemas/AssetAccountV1", "x-protobuf-index": 2 }, + "dest": { + "type": "object", + "$ref": "#/components/schemas/AssetAccountV1", + "x-protobuf-index": 3 + }, "hash_info": { "type": "object", "$ref": "#/components/schemas/HashInfoV1", - "x-protobuf-index": 3 + "x-protobuf-index": 4 }, "destination_certificate": { - "x-protobuf-index": 4, + "x-protobuf-index": 5, "type": "string" }, "source_certificate": { - "x-protobuf-index": 5, + "x-protobuf-index": 6, "type": "string" }, "expiry_secs": { - "x-protobuf-index": 6, + "x-protobuf-index": 7, "type": "integer", "format": "int64", "default": 3600 @@ -160,28 +165,16 @@ }, "AssetLockClaimV1": { "description": "Claim a previously locked asset on the same network.\n\"lock_id\" is required for fungible assets, \"asset\" is required for non-fungible assets.\nhttps://github.com/hyperledger-cacti/cacti/blob/main/weaver/rfcs/protocols/asset-exchange/generic-htlc.md", - "required": [ - "lock_id", - "source", - "destination", - "asset", - "source_certificate", - "hash_info" - ], + "required": ["lock_id", "destination", "asset", "hash_info"], "properties": { "lock_id": { "x-protobuf-index": 1, "type": "string" }, - "source": { - "type": "object", - "$ref": "#/components/schemas/AssetAccountV1", - "x-protobuf-index": 2 - }, "destination": { "type": "object", "$ref": "#/components/schemas/AssetAccountV1", - "x-protobuf-index": 3, + "x-protobuf-index": 2, "example": { "network": "network2.org", "user_id": "Bob" @@ -190,7 +183,7 @@ "asset": { "type": "object", "$ref": "#/components/schemas/TransferrableAssetV1", - "x-protobuf-index": 4, + "x-protobuf-index": 3, "example": { "type": "bond", "asset_id": "ref203" @@ -199,15 +192,7 @@ "hash_info": { "type": "object", "$ref": "#/components/schemas/HashInfoV1", - "x-protobuf-index": 5 - }, - "source_certificate": { - "x-protobuf-index": 6, - "type": "string" - }, - "dest_certificate": { - "x-protobuf-index": 7, - "type": "string" + "x-protobuf-index": 4 } } }, @@ -301,11 +286,29 @@ } }, "paths": { - "/api/v1/plugins/@hyperledger/cacti-plugin-copm/pledge-asset": { + "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/no-op": { + "post": { + "x-hyperledger-cacti": { + "http": { + "path": "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/no-op", + "verbLowerCase": "post" + } + }, + "operationId": "noopV1", + "summary": "A no-op operation. May be used as a health check.", + "parameters": [], + "responses": { + "200": { + "description": "OK" + } + } + } + }, + "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/pledge-asset": { "post": { "x-hyperledger-cacti": { "http": { - "path": "/api/v1/plugins/@hyperledger/cacti-plugin-copm/pledge-asset", + "path": "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/pledge-asset", "verbLowerCase": "post" } }, @@ -344,11 +347,11 @@ } } }, - "/api/v1/plugins/@hyperledger/cacti-plugin-copm/lock-asset": { + "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/lock-asset": { "post": { "x-hyperledger-cacti": { "http": { - "path": "/api/v1/plugins/@hyperledger/cacti-plugin-copm/lock-asset", + "path": "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/lock-asset", "verbLowerCase": "post" } }, @@ -387,11 +390,11 @@ } } }, - "/api/v1/plugins/@hyperledger/cacti-plugin-copm/claim-pledged-asset": { + "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/claim-pledged-asset": { "post": { "x-hyperledger-cacti": { "http": { - "path": "/api/v1/plugins/@hyperledger/cacti-plugin-copm/claim-pledged-asset", + "path": "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/claim-pledged-asset", "verbLowerCase": "post" } }, @@ -430,11 +433,11 @@ } } }, - "/api/v1/plugins/@hyperledger/cacti-plugin-copm/claim-locked-asset": { + "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/claim-locked-asset": { "post": { "x-hyperledger-cacti": { "http": { - "path": "/api/v1/plugins/@hyperledger/cacti-plugin-copm/claim-locked-asset", + "path": "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/claim-locked-asset", "verbLowerCase": "post" } }, @@ -473,11 +476,11 @@ } } }, - "/api/v1/plugins/@hyperledger/cacti-plugin-copm/get-verified-view": { + "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/get-verified-view": { "post": { "x-hyperledger-cacti": { "http": { - "path": "/api/v1/plugins/@hyperledger/cacti-plugin-copm/get-verified-view", + "path": "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/get-verified-view", "verbLowerCase": "post" } }, diff --git a/packages/cacti-copm-core/src/main/json/openapi.tpl.json b/packages/cacti-copm-core/src/main/json/openapi.tpl.json index 7fe70bfe3b..e034ff9476 100644 --- a/packages/cacti-copm-core/src/main/json/openapi.tpl.json +++ b/packages/cacti-copm-core/src/main/json/openapi.tpl.json @@ -3,7 +3,7 @@ "info": { "title": "Hyperledger Cacti Plugin - Common Operator Primitives", "description": "Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/.", - "version": "2.0.0-rc.2", + "version": "2.0.0", "license": { "name": "Apache-2.0", "url": "https://www.apache.org/licenses/LICENSE-2.0.html" @@ -27,7 +27,6 @@ "x-protobuf-index": 1, "type": "string", "example": "bond" - }, "asset_id": { "x-protobuf-index": 2, @@ -69,12 +68,12 @@ ], "properties": { "source": { - "type" : "object", + "type": "object", "$ref": "#/components/schemas/AssetAccountV1", "x-protobuf-index": 1 }, "destination": { - "type" : "object", + "type": "object", "$ref": "#/components/schemas/AssetAccountV1", "example": { "network": "network2.org", @@ -83,7 +82,7 @@ "x-protobuf-index": 2 }, "asset": { - "type" : "object", + "type": "object", "$ref": "#/components/schemas/TransferrableAssetV1", "example": { "type": "bond", @@ -133,26 +132,31 @@ "asset_id": "ref203" } }, - "owner": { + "source": { "type": "object", "$ref": "#/components/schemas/AssetAccountV1", "x-protobuf-index": 2 }, + "dest": { + "type": "object", + "$ref": "#/components/schemas/AssetAccountV1", + "x-protobuf-index": 3 + }, "hash_info": { "type": "object", "$ref": "#/components/schemas/HashInfoV1", - "x-protobuf-index": 3 + "x-protobuf-index": 4 }, "destination_certificate": { - "x-protobuf-index": 4, + "x-protobuf-index": 5, "type": "string" }, "source_certificate": { - "x-protobuf-index": 5, + "x-protobuf-index": 6, "type": "string" }, "expiry_secs": { - "x-protobuf-index": 6, + "x-protobuf-index": 7, "type": "integer", "format": "int64", "default": 3600 @@ -163,10 +167,8 @@ "description": "Claim a previously locked asset on the same network.\n\"lock_id\" is required for fungible assets, \"asset\" is required for non-fungible assets.\nhttps://github.com/hyperledger-cacti/cacti/blob/main/weaver/rfcs/protocols/asset-exchange/generic-htlc.md", "required": [ "lock_id", - "source", "destination", "asset", - "source_certificate", "hash_info" ], "properties": { @@ -174,15 +176,10 @@ "x-protobuf-index": 1, "type": "string" }, - "source": { - "type": "object", - "$ref": "#/components/schemas/AssetAccountV1", - "x-protobuf-index": 2 - }, "destination": { "type": "object", "$ref": "#/components/schemas/AssetAccountV1", - "x-protobuf-index": 3, + "x-protobuf-index": 2, "example": { "network": "network2.org", "user_id": "Bob" @@ -191,7 +188,7 @@ "asset": { "type": "object", "$ref": "#/components/schemas/TransferrableAssetV1", - "x-protobuf-index": 4, + "x-protobuf-index": 3, "example": { "type": "bond", "asset_id": "ref203" @@ -200,15 +197,7 @@ "hash_info": { "type": "object", "$ref": "#/components/schemas/HashInfoV1", - "x-protobuf-index": 5 - }, - "source_certificate": { - "x-protobuf-index": 6, - "type": "string" - }, - "dest_certificate": { - "x-protobuf-index": 7, - "type": "string" + "x-protobuf-index": 4 } } }, @@ -302,11 +291,29 @@ } }, "paths": { - "/api/v1/plugins/@hyperledger/cacti-plugin-copm/pledge-asset": { + "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/no-op": { + "post": { + "x-hyperledger-cacti": { + "http": { + "path": "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/no-op", + "verbLowerCase": "post" + } + }, + "operationId": "noopV1", + "summary": "A no-op operation. May be used as a health check.", + "parameters": [], + "responses": { + "200": { + "description": "OK" + } + } + } + }, + "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/pledge-asset": { "post": { "x-hyperledger-cacti": { "http": { - "path": "/api/v1/plugins/@hyperledger/cacti-plugin-copm/pledge-asset", + "path": "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/pledge-asset", "verbLowerCase": "post" } }, @@ -345,11 +352,11 @@ } } }, - "/api/v1/plugins/@hyperledger/cacti-plugin-copm/lock-asset": { + "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/lock-asset": { "post": { "x-hyperledger-cacti": { "http": { - "path": "/api/v1/plugins/@hyperledger/cacti-plugin-copm/lock-asset", + "path": "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/lock-asset", "verbLowerCase": "post" } }, @@ -388,11 +395,11 @@ } } }, - "/api/v1/plugins/@hyperledger/cacti-plugin-copm/claim-pledged-asset": { + "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/claim-pledged-asset": { "post": { "x-hyperledger-cacti": { "http": { - "path": "/api/v1/plugins/@hyperledger/cacti-plugin-copm/claim-pledged-asset", + "path": "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/claim-pledged-asset", "verbLowerCase": "post" } }, @@ -431,11 +438,11 @@ } } }, - "/api/v1/plugins/@hyperledger/cacti-plugin-copm/claim-locked-asset": { + "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/claim-locked-asset": { "post": { "x-hyperledger-cacti": { "http": { - "path": "/api/v1/plugins/@hyperledger/cacti-plugin-copm/claim-locked-asset", + "path": "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/claim-locked-asset", "verbLowerCase": "post" } }, @@ -474,11 +481,11 @@ } } }, - "/api/v1/plugins/@hyperledger/cacti-plugin-copm/get-verified-view": { + "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/get-verified-view": { "post": { "x-hyperledger-cacti": { "http": { - "path": "/api/v1/plugins/@hyperledger/cacti-plugin-copm/get-verified-view", + "path": "/api/v1/plugins/@hyperledger-cacti/cacti-plugin-copm/get-verified-view", "verbLowerCase": "post" } }, diff --git a/packages/cacti-copm-core/src/main/proto/generated/openapi/README.md b/packages/cacti-copm-core/src/main/proto/generated/openapi/README.md index d6302ca7f1..b18f83e9d1 100644 --- a/packages/cacti-copm-core/src/main/proto/generated/openapi/README.md +++ b/packages/cacti-copm-core/src/main/proto/generated/openapi/README.md @@ -1,11 +1,11 @@ -# gPRC for org.hyperledger.cacti.plugin.cacti.plugin.copm.core +# gPRC for org.hyperledger.cacti.plugin.copm.core Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. ## Overview These files were generated by the [OpenAPI Generator](https://openapi-generator.tech) project. -- API version: 2.0.0-rc.2 +- API version: 2.0.0 - Package version: - Build package: org.openapitools.codegen.languages.ProtobufSchemaCodegen @@ -16,15 +16,15 @@ Below are some usage examples for Go and Ruby. For other languages, please refer ### Go ``` # assuming `protoc-gen-go` has been installed with `go get -u github.com/golang/protobuf/protoc-gen-go` -mkdir /var/tmp/go/org.hyperledger.cacti.plugin.cacti.plugin.copm.core -protoc --go_out=/var/tmp/go/org.hyperledger.cacti.plugin.cacti.plugin.copm.core services/* -protoc --go_out=/var/tmp/go/org.hyperledger.cacti.plugin.cacti.plugin.copm.core models/* +mkdir /var/tmp/go/org.hyperledger.cacti.plugin.copm.core +protoc --go_out=/var/tmp/go/org.hyperledger.cacti.plugin.copm.core services/* +protoc --go_out=/var/tmp/go/org.hyperledger.cacti.plugin.copm.core models/* ``` ### Ruby ``` # assuming `grpc_tools_ruby_protoc` has been installed via `gem install grpc-tools` -RUBY_OUTPUT_DIR="/var/tmp/ruby/org.hyperledger.cacti.plugin.cacti.plugin.copm.core" +RUBY_OUTPUT_DIR="/var/tmp/ruby/org.hyperledger.cacti.plugin.copm.core" mkdir $RUBY_OUTPUT_DIR grpc_tools_ruby_protoc --ruby_out=$RUBY_OUTPUT_DIR --grpc_out=$RUBY_OUTPUT_DIR/lib services/* grpc_tools_ruby_protoc --ruby_out=$RUBY_OUTPUT_DIR --grpc_out=$RUBY_OUTPUT_DIR/lib models/* diff --git a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/asset_account_v1_pb.proto b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/asset_account_v1_pb.proto index f8923c1fa7..c10656e79d 100644 --- a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/asset_account_v1_pb.proto +++ b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/asset_account_v1_pb.proto @@ -3,14 +3,14 @@ Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. - The version of the OpenAPI document: 2.0.0-rc.2 + The version of the OpenAPI document: 2.0.0 Generated by OpenAPI Generator: https://openapi-generator.tech */ syntax = "proto3"; -package org.hyperledger.cacti.plugin.cacti.plugin.copm.core; +package org.hyperledger.cacti.plugin.copm.core; import "google/protobuf/any.proto"; diff --git a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/asset_lock_claim_v1_pb.proto b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/asset_lock_claim_v1_pb.proto index f571fdeb35..a98b6156a8 100644 --- a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/asset_lock_claim_v1_pb.proto +++ b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/asset_lock_claim_v1_pb.proto @@ -3,14 +3,14 @@ Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. - The version of the OpenAPI document: 2.0.0-rc.2 + The version of the OpenAPI document: 2.0.0 Generated by OpenAPI Generator: https://openapi-generator.tech */ syntax = "proto3"; -package org.hyperledger.cacti.plugin.cacti.plugin.copm.core; +package org.hyperledger.cacti.plugin.copm.core; import "google/protobuf/any.proto"; @@ -22,16 +22,10 @@ message AssetLockClaimV1PB { string lock_id = 1; - AssetAccountV1PB source = 359634918; - AssetAccountV1PB destination = 356105204; TransferrableAssetV1PB asset = 93121264; HashInfoV1PB hash_info = 309318975; - string source_certificate = 6; - - string dest_certificate = 7; - } diff --git a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/asset_lock_v1_pb.proto b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/asset_lock_v1_pb.proto index dbd9eb5867..97c1467680 100644 --- a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/asset_lock_v1_pb.proto +++ b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/asset_lock_v1_pb.proto @@ -3,14 +3,14 @@ Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. - The version of the OpenAPI document: 2.0.0-rc.2 + The version of the OpenAPI document: 2.0.0 Generated by OpenAPI Generator: https://openapi-generator.tech */ syntax = "proto3"; -package org.hyperledger.cacti.plugin.cacti.plugin.copm.core; +package org.hyperledger.cacti.plugin.copm.core; import "google/protobuf/any.proto"; @@ -22,14 +22,16 @@ message AssetLockV1PB { TransferrableAssetV1PB asset = 93121264; - AssetAccountV1PB owner = 106164915; + AssetAccountV1PB source = 359634918; + + AssetAccountV1PB dest = 3079842; HashInfoV1PB hash_info = 309318975; - string destination_certificate = 4; + string destination_certificate = 5; - string source_certificate = 5; + string source_certificate = 6; - int64 expiry_secs = 6; + int64 expiry_secs = 7; } diff --git a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/asset_pledge_claim_v1_pb.proto b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/asset_pledge_claim_v1_pb.proto index 69dfbcd111..a7da84bce2 100644 --- a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/asset_pledge_claim_v1_pb.proto +++ b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/asset_pledge_claim_v1_pb.proto @@ -3,14 +3,14 @@ Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. - The version of the OpenAPI document: 2.0.0-rc.2 + The version of the OpenAPI document: 2.0.0 Generated by OpenAPI Generator: https://openapi-generator.tech */ syntax = "proto3"; -package org.hyperledger.cacti.plugin.cacti.plugin.copm.core; +package org.hyperledger.cacti.plugin.copm.core; import "google/protobuf/any.proto"; diff --git a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/asset_pledge_v1_pb.proto b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/asset_pledge_v1_pb.proto index aac5eb8fec..7bb607fa3d 100644 --- a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/asset_pledge_v1_pb.proto +++ b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/asset_pledge_v1_pb.proto @@ -3,14 +3,14 @@ Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. - The version of the OpenAPI document: 2.0.0-rc.2 + The version of the OpenAPI document: 2.0.0 Generated by OpenAPI Generator: https://openapi-generator.tech */ syntax = "proto3"; -package org.hyperledger.cacti.plugin.cacti.plugin.copm.core; +package org.hyperledger.cacti.plugin.copm.core; import "google/protobuf/any.proto"; diff --git a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/claim_pledged_asset_v1200_response_pb.proto b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/claim_pledged_asset_v1200_response_pb.proto index 1e8d5aca8f..2c6af9a737 100644 --- a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/claim_pledged_asset_v1200_response_pb.proto +++ b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/claim_pledged_asset_v1200_response_pb.proto @@ -3,14 +3,14 @@ Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. - The version of the OpenAPI document: 2.0.0-rc.2 + The version of the OpenAPI document: 2.0.0 Generated by OpenAPI Generator: https://openapi-generator.tech */ syntax = "proto3"; -package org.hyperledger.cacti.plugin.cacti.plugin.copm.core; +package org.hyperledger.cacti.plugin.copm.core; import "google/protobuf/any.proto"; diff --git a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/get_verified_view_v1200_response_pb.proto b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/get_verified_view_v1200_response_pb.proto index ad9ae9e9b1..cca03b7778 100644 --- a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/get_verified_view_v1200_response_pb.proto +++ b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/get_verified_view_v1200_response_pb.proto @@ -3,14 +3,14 @@ Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. - The version of the OpenAPI document: 2.0.0-rc.2 + The version of the OpenAPI document: 2.0.0 Generated by OpenAPI Generator: https://openapi-generator.tech */ syntax = "proto3"; -package org.hyperledger.cacti.plugin.cacti.plugin.copm.core; +package org.hyperledger.cacti.plugin.copm.core; import "google/protobuf/any.proto"; diff --git a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/get_verified_view_v1_request_pb.proto b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/get_verified_view_v1_request_pb.proto index 6aec0bdf6c..c0fcc29107 100644 --- a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/get_verified_view_v1_request_pb.proto +++ b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/get_verified_view_v1_request_pb.proto @@ -3,14 +3,14 @@ Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. - The version of the OpenAPI document: 2.0.0-rc.2 + The version of the OpenAPI document: 2.0.0 Generated by OpenAPI Generator: https://openapi-generator.tech */ syntax = "proto3"; -package org.hyperledger.cacti.plugin.cacti.plugin.copm.core; +package org.hyperledger.cacti.plugin.copm.core; import "google/protobuf/any.proto"; diff --git a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/hash_info_v1_pb.proto b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/hash_info_v1_pb.proto index a76f5d53c5..d67cbc14ef 100644 --- a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/hash_info_v1_pb.proto +++ b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/hash_info_v1_pb.proto @@ -3,14 +3,14 @@ Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. - The version of the OpenAPI document: 2.0.0-rc.2 + The version of the OpenAPI document: 2.0.0 Generated by OpenAPI Generator: https://openapi-generator.tech */ syntax = "proto3"; -package org.hyperledger.cacti.plugin.cacti.plugin.copm.core; +package org.hyperledger.cacti.plugin.copm.core; import "google/protobuf/any.proto"; diff --git a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/lock_asset_v1200_response_pb.proto b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/lock_asset_v1200_response_pb.proto index 77420c3bdb..c132ebfca7 100644 --- a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/lock_asset_v1200_response_pb.proto +++ b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/lock_asset_v1200_response_pb.proto @@ -3,14 +3,14 @@ Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. - The version of the OpenAPI document: 2.0.0-rc.2 + The version of the OpenAPI document: 2.0.0 Generated by OpenAPI Generator: https://openapi-generator.tech */ syntax = "proto3"; -package org.hyperledger.cacti.plugin.cacti.plugin.copm.core; +package org.hyperledger.cacti.plugin.copm.core; import "google/protobuf/any.proto"; diff --git a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/pledge_asset_v1200_response_pb.proto b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/pledge_asset_v1200_response_pb.proto index de449c89da..4904f40ab7 100644 --- a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/pledge_asset_v1200_response_pb.proto +++ b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/pledge_asset_v1200_response_pb.proto @@ -3,14 +3,14 @@ Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. - The version of the OpenAPI document: 2.0.0-rc.2 + The version of the OpenAPI document: 2.0.0 Generated by OpenAPI Generator: https://openapi-generator.tech */ syntax = "proto3"; -package org.hyperledger.cacti.plugin.cacti.plugin.copm.core; +package org.hyperledger.cacti.plugin.copm.core; import "google/protobuf/any.proto"; diff --git a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/transferrable_asset_v1_pb.proto b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/transferrable_asset_v1_pb.proto index 9987f715ac..56f361ddb3 100644 --- a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/transferrable_asset_v1_pb.proto +++ b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/transferrable_asset_v1_pb.proto @@ -3,14 +3,14 @@ Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. - The version of the OpenAPI document: 2.0.0-rc.2 + The version of the OpenAPI document: 2.0.0 Generated by OpenAPI Generator: https://openapi-generator.tech */ syntax = "proto3"; -package org.hyperledger.cacti.plugin.cacti.plugin.copm.core; +package org.hyperledger.cacti.plugin.copm.core; import "google/protobuf/any.proto"; diff --git a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/view_address_v1_pb.proto b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/view_address_v1_pb.proto index 3cde095cd1..b2844ca7c7 100644 --- a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/view_address_v1_pb.proto +++ b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/view_address_v1_pb.proto @@ -3,14 +3,14 @@ Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. - The version of the OpenAPI document: 2.0.0-rc.2 + The version of the OpenAPI document: 2.0.0 Generated by OpenAPI Generator: https://openapi-generator.tech */ syntax = "proto3"; -package org.hyperledger.cacti.plugin.cacti.plugin.copm.core; +package org.hyperledger.cacti.plugin.copm.core; import "google/protobuf/any.proto"; diff --git a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/view_v1_pb.proto b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/view_v1_pb.proto index ba1c1cac33..2d484d18bb 100644 --- a/packages/cacti-copm-core/src/main/proto/generated/openapi/models/view_v1_pb.proto +++ b/packages/cacti-copm-core/src/main/proto/generated/openapi/models/view_v1_pb.proto @@ -3,14 +3,14 @@ Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. - The version of the OpenAPI document: 2.0.0-rc.2 + The version of the OpenAPI document: 2.0.0 Generated by OpenAPI Generator: https://openapi-generator.tech */ syntax = "proto3"; -package org.hyperledger.cacti.plugin.cacti.plugin.copm.core; +package org.hyperledger.cacti.plugin.copm.core; import "google/protobuf/any.proto"; diff --git a/packages/cacti-copm-core/src/main/proto/generated/openapi/services/default_service.proto b/packages/cacti-copm-core/src/main/proto/generated/openapi/services/default_service.proto index 6a0e88c8ad..39dafc5d6f 100644 --- a/packages/cacti-copm-core/src/main/proto/generated/openapi/services/default_service.proto +++ b/packages/cacti-copm-core/src/main/proto/generated/openapi/services/default_service.proto @@ -3,14 +3,14 @@ Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. - The version of the OpenAPI document: 2.0.0-rc.2 + The version of the OpenAPI document: 2.0.0 Generated by OpenAPI Generator: https://openapi-generator.tech */ syntax = "proto3"; -package org.hyperledger.cacti.plugin.cacti.plugin.copm.core.services.defaultservice; +package org.hyperledger.cacti.plugin.copm.core.services.defaultservice; import "google/protobuf/empty.proto"; import "models/asset_lock_claim_v1_pb.proto"; @@ -32,6 +32,8 @@ service DefaultService { rpc LockAssetV1 (LockAssetV1Request) returns (LockAssetV1200ResponsePB); + rpc NoopV1 (google.protobuf.Empty) returns (google.protobuf.Empty); + rpc PledgeAssetV1 (PledgeAssetV1Request) returns (PledgeAssetV1200ResponsePB); } diff --git a/packages/cacti-copm-core/src/main/protos-kt/build.gradle b/packages/cacti-copm-core/src/main/protos-kt/build.gradle new file mode 100644 index 0000000000..8b7ff531a0 --- /dev/null +++ b/packages/cacti-copm-core/src/main/protos-kt/build.gradle @@ -0,0 +1,88 @@ + +buildscript { + repositories { + mavenCentral() + } +} + +plugins { +// id 'com.github.johnrengelman.shadow' version '5.0.0' + id "java" + id "idea" + id 'com.google.protobuf' version "$protobuf_plugin_version" + id "application" + id 'org.jetbrains.kotlin.jvm' version "$kotlin_version" + id "org.jetbrains.kotlin.plugin.jpa" version "$kotlin_version" +} + +sourceSets { + main { + proto { + srcDir "./../proto/generated/openapi/" + } + } +} + +Properties constants = new Properties() + +repositories { + google() + mavenCentral() + mavenLocal() +} + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" + implementation 'com.google.code.gson:gson:2.8.6' + + // gRPC and protobuf dependencies + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" + implementation "io.grpc:grpc-kotlin-stub:$grpc_kotlin_version" + implementation "io.grpc:grpc-netty-shaded:$grpc_version" + implementation "io.grpc:grpc-stub:$grpc_version" + implementation "io.grpc:grpc-okhttp:$grpc_version" + implementation "io.grpc:grpc-protobuf:$grpc_version" + implementation group: 'org.json', name: 'json', version: '20190722' +} + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + +compileJava { + options.compilerArgs << '-parameters' +} + +jar { + // This makes the JAR's SHA-256 hash repeatable. + preserveFileTimestamps = false + reproducibleFileOrder = true +} + +protobuf { + protoc { artifact = "com.google.protobuf:protoc:3.21.12" } + plugins { + // Specify protoc to generate using kotlin protobuf plugin + grpc { + artifact = "io.grpc:protoc-gen-grpc-java:$grpc_version" + } + // Specify protoc to generate using our grpc kotlin plugin + grpckt { + artifact = "io.grpc:protoc-gen-grpc-kotlin:$grpc_kotlin_version:jdk8@jar" + } + } + generateProtoTasks { + all().each { task -> + task.plugins { + // Generate Java gRPC classes + grpc { } + // Generate Kotlin gRPC using the custom plugin from library + grpckt { } + } + } + } +} + + diff --git a/packages/cacti-copm-core/src/main/protos-kt/gradle.properties b/packages/cacti-copm-core/src/main/protos-kt/gradle.properties new file mode 100644 index 0000000000..ad80b3a92a --- /dev/null +++ b/packages/cacti-copm-core/src/main/protos-kt/gradle.properties @@ -0,0 +1,25 @@ +name=Test +group=com.cordaCopmClient +version=2.0.0 +kotlin.incremental=false +corda_release_group=net.corda +corda_core_release_group=net.corda +corda_release_version=4.12 +corda_core_release_version=4.12 +corda_core_version=4.12 +gradle_plugin_version=5.1.1 +protobuf_version=3.21.12 +protobuf_plugin_version=0.9.3 +kotlin_version=1.9.23 +junitVersion=4.12 +log4jVersion=2.23.1 +platformVersion=140 +slf4jVersion=2.0.12 +nettyVersion=4.1.77.Final +cordaTokenSDKGroup=com.r3.corda.lib.tokens +cordaTokenSDKVersion=1.3-RC02 +arrow_version=0.10.4 +grpc_version=1.65.0 +grpc_kotlin_version=1.4.1 +coroutines_version=1.8.1 + diff --git a/packages/cacti-copm-core/src/main/protos-kt/gradle/libs.versions.toml b/packages/cacti-copm-core/src/main/protos-kt/gradle/libs.versions.toml new file mode 100644 index 0000000000..8bb21088bb --- /dev/null +++ b/packages/cacti-copm-core/src/main/protos-kt/gradle/libs.versions.toml @@ -0,0 +1,28 @@ +# This file was generated by the Gradle 'init' task. +# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format + +[versions] +com-fasterxml-jackson-dataformat-jackson-dataformat-xml = "2.15.2" +com-fasterxml-jackson-dataformat-jackson-dataformat-yaml = "2.15.2" +com-fasterxml-jackson-datatype-jackson-datatype-jsr310 = "2.15.2" +com-fasterxml-jackson-module-jackson-module-kotlin = "2.15.2" +com-google-code-findbugs-jsr305 = "3.0.2" +jakarta-annotation-jakarta-annotation-api = "2.1.0" +jakarta-validation-jakarta-validation-api = "3.0.2" +org-jetbrains-kotlin-kotlin-reflect = "1.7.10" +org-jetbrains-kotlin-kotlin-stdlib-jdk8 = "1.7.10" +org-jetbrains-kotlin-kotlin-test-junit5 = "1.7.10" +org-springframework-boot-spring-boot-starter-web = "3.1.3" + +[libraries] +com-fasterxml-jackson-dataformat-jackson-dataformat-xml = { module = "com.fasterxml.jackson.dataformat:jackson-dataformat-xml", version.ref = "com-fasterxml-jackson-dataformat-jackson-dataformat-xml" } +com-fasterxml-jackson-dataformat-jackson-dataformat-yaml = { module = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml", version.ref = "com-fasterxml-jackson-dataformat-jackson-dataformat-yaml" } +com-fasterxml-jackson-datatype-jackson-datatype-jsr310 = { module = "com.fasterxml.jackson.datatype:jackson-datatype-jsr310", version.ref = "com-fasterxml-jackson-datatype-jackson-datatype-jsr310" } +com-fasterxml-jackson-module-jackson-module-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "com-fasterxml-jackson-module-jackson-module-kotlin" } +com-google-code-findbugs-jsr305 = { module = "com.google.code.findbugs:jsr305", version.ref = "com-google-code-findbugs-jsr305" } +jakarta-annotation-jakarta-annotation-api = { module = "jakarta.annotation:jakarta.annotation-api", version.ref = "jakarta-annotation-jakarta-annotation-api" } +jakarta-validation-jakarta-validation-api = { module = "jakarta.validation:jakarta.validation-api", version.ref = "jakarta-validation-jakarta-validation-api" } +org-jetbrains-kotlin-kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "org-jetbrains-kotlin-kotlin-reflect" } +org-jetbrains-kotlin-kotlin-stdlib-jdk8 = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "org-jetbrains-kotlin-kotlin-stdlib-jdk8" } +org-jetbrains-kotlin-kotlin-test-junit5 = { module = "org.jetbrains.kotlin:kotlin-test-junit5", version.ref = "org-jetbrains-kotlin-kotlin-test-junit5" } +org-springframework-boot-spring-boot-starter-web = { module = "org.springframework.boot:spring-boot-starter-web", version.ref = "org-springframework-boot-spring-boot-starter-web" } diff --git a/packages/cacti-copm-core/src/main/protos-kt/gradle/wrapper/gradle-wrapper.jar b/packages/cacti-copm-core/src/main/protos-kt/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..e6441136f3 Binary files /dev/null and b/packages/cacti-copm-core/src/main/protos-kt/gradle/wrapper/gradle-wrapper.jar differ diff --git a/packages/cacti-copm-core/src/main/protos-kt/gradle/wrapper/gradle-wrapper.properties b/packages/cacti-copm-core/src/main/protos-kt/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..a4413138c9 --- /dev/null +++ b/packages/cacti-copm-core/src/main/protos-kt/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/packages/cacti-copm-core/src/main/protos-kt/gradlew b/packages/cacti-copm-core/src/main/protos-kt/gradlew new file mode 100755 index 0000000000..b740cf1339 --- /dev/null +++ b/packages/cacti-copm-core/src/main/protos-kt/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/packages/cacti-copm-core/src/main/protos-kt/repositories.gradle b/packages/cacti-copm-core/src/main/protos-kt/repositories.gradle new file mode 100644 index 0000000000..ee4e0ee0da --- /dev/null +++ b/packages/cacti-copm-core/src/main/protos-kt/repositories.gradle @@ -0,0 +1,8 @@ +repositories { + mavenLocal() + mavenCentral() + maven { url 'https://jitpack.io' } + maven { url 'https://download.corda.net/maven/corda-dependencies' } + maven { url 'https://download.corda.net/maven/corda-releases' } + maven { url 'https://repo.gradle.org/gradle/libs-releases' } +} diff --git a/packages/cacti-copm-core/src/main/protos-kt/settings.gradle b/packages/cacti-copm-core/src/main/protos-kt/settings.gradle new file mode 100644 index 0000000000..1ec17e37c1 --- /dev/null +++ b/packages/cacti-copm-core/src/main/protos-kt/settings.gradle @@ -0,0 +1,7 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * This project uses @Incubating APIs which are subject to change. + */ + +rootProject.name = 'copm-corda' diff --git a/packages/cacti-copm-core/src/main/typescript/generated/models/asset_account_v1_pb_pb.ts b/packages/cacti-copm-core/src/main/typescript/generated/models/asset_account_v1_pb_pb.ts index b28c069f3d..929d02a26d 100644 --- a/packages/cacti-copm-core/src/main/typescript/generated/models/asset_account_v1_pb_pb.ts +++ b/packages/cacti-copm-core/src/main/typescript/generated/models/asset_account_v1_pb_pb.ts @@ -3,12 +3,12 @@ // //Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. // -//The version of the OpenAPI document: 2.0.0-rc.2 +//The version of the OpenAPI document: 2.0.0 // //Generated by OpenAPI Generator: https://openapi-generator.tech // @generated by protoc-gen-es v1.8.0 with parameter "target=ts" -// @generated from file models/asset_account_v1_pb.proto (package org.hyperledger.cacti.plugin.cacti.plugin.copm.core, syntax proto3) +// @generated from file models/asset_account_v1_pb.proto (package org.hyperledger.cacti.plugin.copm.core, syntax proto3) /* eslint-disable */ // @ts-nocheck @@ -16,7 +16,7 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialM import { Message, proto3 } from "@bufbuild/protobuf"; /** - * @generated from message org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetAccountV1PB + * @generated from message org.hyperledger.cacti.plugin.copm.core.AssetAccountV1PB */ export class AssetAccountV1PB extends Message { /** @@ -35,7 +35,7 @@ export class AssetAccountV1PB extends Message { } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetAccountV1PB"; + static readonly typeName = "org.hyperledger.cacti.plugin.copm.core.AssetAccountV1PB"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ { no: 1, name: "network", kind: "scalar", T: 9 /* ScalarType.STRING */ }, { no: 2, name: "user_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, diff --git a/packages/cacti-copm-core/src/main/typescript/generated/models/asset_lock_claim_v1_pb_pb.ts b/packages/cacti-copm-core/src/main/typescript/generated/models/asset_lock_claim_v1_pb_pb.ts index 03e7546010..73340a78ca 100644 --- a/packages/cacti-copm-core/src/main/typescript/generated/models/asset_lock_claim_v1_pb_pb.ts +++ b/packages/cacti-copm-core/src/main/typescript/generated/models/asset_lock_claim_v1_pb_pb.ts @@ -3,12 +3,12 @@ // //Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. // -//The version of the OpenAPI document: 2.0.0-rc.2 +//The version of the OpenAPI document: 2.0.0 // //Generated by OpenAPI Generator: https://openapi-generator.tech // @generated by protoc-gen-es v1.8.0 with parameter "target=ts" -// @generated from file models/asset_lock_claim_v1_pb.proto (package org.hyperledger.cacti.plugin.cacti.plugin.copm.core, syntax proto3) +// @generated from file models/asset_lock_claim_v1_pb.proto (package org.hyperledger.cacti.plugin.copm.core, syntax proto3) /* eslint-disable */ // @ts-nocheck @@ -19,7 +19,7 @@ import { TransferrableAssetV1PB } from "./transferrable_asset_v1_pb_pb.js"; import { HashInfoV1PB } from "./hash_info_v1_pb_pb.js"; /** - * @generated from message org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetLockClaimV1PB + * @generated from message org.hyperledger.cacti.plugin.copm.core.AssetLockClaimV1PB */ export class AssetLockClaimV1PB extends Message { /** @@ -28,50 +28,32 @@ export class AssetLockClaimV1PB extends Message { lockId = ""; /** - * @generated from field: org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetAccountV1PB source = 359634918; - */ - source?: AssetAccountV1PB; - - /** - * @generated from field: org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetAccountV1PB destination = 356105204; + * @generated from field: org.hyperledger.cacti.plugin.copm.core.AssetAccountV1PB destination = 356105204; */ destination?: AssetAccountV1PB; /** - * @generated from field: org.hyperledger.cacti.plugin.cacti.plugin.copm.core.TransferrableAssetV1PB asset = 93121264; + * @generated from field: org.hyperledger.cacti.plugin.copm.core.TransferrableAssetV1PB asset = 93121264; */ asset?: TransferrableAssetV1PB; /** - * @generated from field: org.hyperledger.cacti.plugin.cacti.plugin.copm.core.HashInfoV1PB hash_info = 309318975; + * @generated from field: org.hyperledger.cacti.plugin.copm.core.HashInfoV1PB hash_info = 309318975; */ hashInfo?: HashInfoV1PB; - /** - * @generated from field: string source_certificate = 6; - */ - sourceCertificate = ""; - - /** - * @generated from field: string dest_certificate = 7; - */ - destCertificate = ""; - constructor(data?: PartialMessage) { super(); proto3.util.initPartial(data, this); } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetLockClaimV1PB"; + static readonly typeName = "org.hyperledger.cacti.plugin.copm.core.AssetLockClaimV1PB"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ { no: 1, name: "lock_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 359634918, name: "source", kind: "message", T: AssetAccountV1PB }, { no: 356105204, name: "destination", kind: "message", T: AssetAccountV1PB }, { no: 93121264, name: "asset", kind: "message", T: TransferrableAssetV1PB }, { no: 309318975, name: "hash_info", kind: "message", T: HashInfoV1PB }, - { no: 6, name: "source_certificate", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 7, name: "dest_certificate", kind: "scalar", T: 9 /* ScalarType.STRING */ }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): AssetLockClaimV1PB { diff --git a/packages/cacti-copm-core/src/main/typescript/generated/models/asset_lock_v1_pb_pb.ts b/packages/cacti-copm-core/src/main/typescript/generated/models/asset_lock_v1_pb_pb.ts index 53f4287921..425067c624 100644 --- a/packages/cacti-copm-core/src/main/typescript/generated/models/asset_lock_v1_pb_pb.ts +++ b/packages/cacti-copm-core/src/main/typescript/generated/models/asset_lock_v1_pb_pb.ts @@ -3,12 +3,12 @@ // //Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. // -//The version of the OpenAPI document: 2.0.0-rc.2 +//The version of the OpenAPI document: 2.0.0 // //Generated by OpenAPI Generator: https://openapi-generator.tech // @generated by protoc-gen-es v1.8.0 with parameter "target=ts" -// @generated from file models/asset_lock_v1_pb.proto (package org.hyperledger.cacti.plugin.cacti.plugin.copm.core, syntax proto3) +// @generated from file models/asset_lock_v1_pb.proto (package org.hyperledger.cacti.plugin.copm.core, syntax proto3) /* eslint-disable */ // @ts-nocheck @@ -19,36 +19,41 @@ import { AssetAccountV1PB } from "./asset_account_v1_pb_pb.js"; import { HashInfoV1PB } from "./hash_info_v1_pb_pb.js"; /** - * @generated from message org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetLockV1PB + * @generated from message org.hyperledger.cacti.plugin.copm.core.AssetLockV1PB */ export class AssetLockV1PB extends Message { /** - * @generated from field: org.hyperledger.cacti.plugin.cacti.plugin.copm.core.TransferrableAssetV1PB asset = 93121264; + * @generated from field: org.hyperledger.cacti.plugin.copm.core.TransferrableAssetV1PB asset = 93121264; */ asset?: TransferrableAssetV1PB; /** - * @generated from field: org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetAccountV1PB owner = 106164915; + * @generated from field: org.hyperledger.cacti.plugin.copm.core.AssetAccountV1PB source = 359634918; */ - owner?: AssetAccountV1PB; + source?: AssetAccountV1PB; /** - * @generated from field: org.hyperledger.cacti.plugin.cacti.plugin.copm.core.HashInfoV1PB hash_info = 309318975; + * @generated from field: org.hyperledger.cacti.plugin.copm.core.AssetAccountV1PB dest = 3079842; + */ + dest?: AssetAccountV1PB; + + /** + * @generated from field: org.hyperledger.cacti.plugin.copm.core.HashInfoV1PB hash_info = 309318975; */ hashInfo?: HashInfoV1PB; /** - * @generated from field: string destination_certificate = 4; + * @generated from field: string destination_certificate = 5; */ destinationCertificate = ""; /** - * @generated from field: string source_certificate = 5; + * @generated from field: string source_certificate = 6; */ sourceCertificate = ""; /** - * @generated from field: int64 expiry_secs = 6; + * @generated from field: int64 expiry_secs = 7; */ expirySecs = protoInt64.zero; @@ -58,14 +63,15 @@ export class AssetLockV1PB extends Message { } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetLockV1PB"; + static readonly typeName = "org.hyperledger.cacti.plugin.copm.core.AssetLockV1PB"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ { no: 93121264, name: "asset", kind: "message", T: TransferrableAssetV1PB }, - { no: 106164915, name: "owner", kind: "message", T: AssetAccountV1PB }, + { no: 359634918, name: "source", kind: "message", T: AssetAccountV1PB }, + { no: 3079842, name: "dest", kind: "message", T: AssetAccountV1PB }, { no: 309318975, name: "hash_info", kind: "message", T: HashInfoV1PB }, - { no: 4, name: "destination_certificate", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 5, name: "source_certificate", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 6, name: "expiry_secs", kind: "scalar", T: 3 /* ScalarType.INT64 */ }, + { no: 5, name: "destination_certificate", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 6, name: "source_certificate", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 7, name: "expiry_secs", kind: "scalar", T: 3 /* ScalarType.INT64 */ }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): AssetLockV1PB { diff --git a/packages/cacti-copm-core/src/main/typescript/generated/models/asset_pledge_claim_v1_pb_pb.ts b/packages/cacti-copm-core/src/main/typescript/generated/models/asset_pledge_claim_v1_pb_pb.ts index c6dd7078e6..fdd22be61c 100644 --- a/packages/cacti-copm-core/src/main/typescript/generated/models/asset_pledge_claim_v1_pb_pb.ts +++ b/packages/cacti-copm-core/src/main/typescript/generated/models/asset_pledge_claim_v1_pb_pb.ts @@ -3,12 +3,12 @@ // //Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. // -//The version of the OpenAPI document: 2.0.0-rc.2 +//The version of the OpenAPI document: 2.0.0 // //Generated by OpenAPI Generator: https://openapi-generator.tech // @generated by protoc-gen-es v1.8.0 with parameter "target=ts" -// @generated from file models/asset_pledge_claim_v1_pb.proto (package org.hyperledger.cacti.plugin.cacti.plugin.copm.core, syntax proto3) +// @generated from file models/asset_pledge_claim_v1_pb.proto (package org.hyperledger.cacti.plugin.copm.core, syntax proto3) /* eslint-disable */ // @ts-nocheck @@ -18,7 +18,7 @@ import { AssetAccountV1PB } from "./asset_account_v1_pb_pb.js"; import { TransferrableAssetV1PB } from "./transferrable_asset_v1_pb_pb.js"; /** - * @generated from message org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetPledgeClaimV1PB + * @generated from message org.hyperledger.cacti.plugin.copm.core.AssetPledgeClaimV1PB */ export class AssetPledgeClaimV1PB extends Message { /** @@ -27,17 +27,17 @@ export class AssetPledgeClaimV1PB extends Message { pledgeId = ""; /** - * @generated from field: org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetAccountV1PB source = 359634918; + * @generated from field: org.hyperledger.cacti.plugin.copm.core.AssetAccountV1PB source = 359634918; */ source?: AssetAccountV1PB; /** - * @generated from field: org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetAccountV1PB destination = 356105204; + * @generated from field: org.hyperledger.cacti.plugin.copm.core.AssetAccountV1PB destination = 356105204; */ destination?: AssetAccountV1PB; /** - * @generated from field: org.hyperledger.cacti.plugin.cacti.plugin.copm.core.TransferrableAssetV1PB asset = 93121264; + * @generated from field: org.hyperledger.cacti.plugin.copm.core.TransferrableAssetV1PB asset = 93121264; */ asset?: TransferrableAssetV1PB; @@ -57,7 +57,7 @@ export class AssetPledgeClaimV1PB extends Message { } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetPledgeClaimV1PB"; + static readonly typeName = "org.hyperledger.cacti.plugin.copm.core.AssetPledgeClaimV1PB"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ { no: 1, name: "pledge_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, { no: 359634918, name: "source", kind: "message", T: AssetAccountV1PB }, diff --git a/packages/cacti-copm-core/src/main/typescript/generated/models/asset_pledge_v1_pb_pb.ts b/packages/cacti-copm-core/src/main/typescript/generated/models/asset_pledge_v1_pb_pb.ts index 7a4112f1ac..61850d99fa 100644 --- a/packages/cacti-copm-core/src/main/typescript/generated/models/asset_pledge_v1_pb_pb.ts +++ b/packages/cacti-copm-core/src/main/typescript/generated/models/asset_pledge_v1_pb_pb.ts @@ -3,12 +3,12 @@ // //Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. // -//The version of the OpenAPI document: 2.0.0-rc.2 +//The version of the OpenAPI document: 2.0.0 // //Generated by OpenAPI Generator: https://openapi-generator.tech // @generated by protoc-gen-es v1.8.0 with parameter "target=ts" -// @generated from file models/asset_pledge_v1_pb.proto (package org.hyperledger.cacti.plugin.cacti.plugin.copm.core, syntax proto3) +// @generated from file models/asset_pledge_v1_pb.proto (package org.hyperledger.cacti.plugin.copm.core, syntax proto3) /* eslint-disable */ // @ts-nocheck @@ -18,21 +18,21 @@ import { AssetAccountV1PB } from "./asset_account_v1_pb_pb.js"; import { TransferrableAssetV1PB } from "./transferrable_asset_v1_pb_pb.js"; /** - * @generated from message org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetPledgeV1PB + * @generated from message org.hyperledger.cacti.plugin.copm.core.AssetPledgeV1PB */ export class AssetPledgeV1PB extends Message { /** - * @generated from field: org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetAccountV1PB source = 359634918; + * @generated from field: org.hyperledger.cacti.plugin.copm.core.AssetAccountV1PB source = 359634918; */ source?: AssetAccountV1PB; /** - * @generated from field: org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetAccountV1PB destination = 356105204; + * @generated from field: org.hyperledger.cacti.plugin.copm.core.AssetAccountV1PB destination = 356105204; */ destination?: AssetAccountV1PB; /** - * @generated from field: org.hyperledger.cacti.plugin.cacti.plugin.copm.core.TransferrableAssetV1PB asset = 93121264; + * @generated from field: org.hyperledger.cacti.plugin.copm.core.TransferrableAssetV1PB asset = 93121264; */ asset?: TransferrableAssetV1PB; @@ -52,7 +52,7 @@ export class AssetPledgeV1PB extends Message { } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetPledgeV1PB"; + static readonly typeName = "org.hyperledger.cacti.plugin.copm.core.AssetPledgeV1PB"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ { no: 359634918, name: "source", kind: "message", T: AssetAccountV1PB }, { no: 356105204, name: "destination", kind: "message", T: AssetAccountV1PB }, diff --git a/packages/cacti-copm-core/src/main/typescript/generated/models/claim_pledged_asset_v1200_response_pb_pb.ts b/packages/cacti-copm-core/src/main/typescript/generated/models/claim_pledged_asset_v1200_response_pb_pb.ts index 7fc5a76763..104c29d86d 100644 --- a/packages/cacti-copm-core/src/main/typescript/generated/models/claim_pledged_asset_v1200_response_pb_pb.ts +++ b/packages/cacti-copm-core/src/main/typescript/generated/models/claim_pledged_asset_v1200_response_pb_pb.ts @@ -3,12 +3,12 @@ // //Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. // -//The version of the OpenAPI document: 2.0.0-rc.2 +//The version of the OpenAPI document: 2.0.0 // //Generated by OpenAPI Generator: https://openapi-generator.tech // @generated by protoc-gen-es v1.8.0 with parameter "target=ts" -// @generated from file models/claim_pledged_asset_v1200_response_pb.proto (package org.hyperledger.cacti.plugin.cacti.plugin.copm.core, syntax proto3) +// @generated from file models/claim_pledged_asset_v1200_response_pb.proto (package org.hyperledger.cacti.plugin.copm.core, syntax proto3) /* eslint-disable */ // @ts-nocheck @@ -16,7 +16,7 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialM import { Message, proto3 } from "@bufbuild/protobuf"; /** - * @generated from message org.hyperledger.cacti.plugin.cacti.plugin.copm.core.ClaimPledgedAssetV1200ResponsePB + * @generated from message org.hyperledger.cacti.plugin.copm.core.ClaimPledgedAssetV1200ResponsePB */ export class ClaimPledgedAssetV1200ResponsePB extends Message { /** @@ -30,7 +30,7 @@ export class ClaimPledgedAssetV1200ResponsePB extends Message [ { no: 1, name: "claim_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, ]); diff --git a/packages/cacti-copm-core/src/main/typescript/generated/models/get_verified_view_v1200_response_pb_pb.ts b/packages/cacti-copm-core/src/main/typescript/generated/models/get_verified_view_v1200_response_pb_pb.ts index 52d21e5df8..7fcf34bd96 100644 --- a/packages/cacti-copm-core/src/main/typescript/generated/models/get_verified_view_v1200_response_pb_pb.ts +++ b/packages/cacti-copm-core/src/main/typescript/generated/models/get_verified_view_v1200_response_pb_pb.ts @@ -3,12 +3,12 @@ // //Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. // -//The version of the OpenAPI document: 2.0.0-rc.2 +//The version of the OpenAPI document: 2.0.0 // //Generated by OpenAPI Generator: https://openapi-generator.tech // @generated by protoc-gen-es v1.8.0 with parameter "target=ts" -// @generated from file models/get_verified_view_v1200_response_pb.proto (package org.hyperledger.cacti.plugin.cacti.plugin.copm.core, syntax proto3) +// @generated from file models/get_verified_view_v1200_response_pb.proto (package org.hyperledger.cacti.plugin.copm.core, syntax proto3) /* eslint-disable */ // @ts-nocheck @@ -16,7 +16,7 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialM import { Message, proto3 } from "@bufbuild/protobuf"; /** - * @generated from message org.hyperledger.cacti.plugin.cacti.plugin.copm.core.GetVerifiedViewV1200ResponsePB + * @generated from message org.hyperledger.cacti.plugin.copm.core.GetVerifiedViewV1200ResponsePB */ export class GetVerifiedViewV1200ResponsePB extends Message { /** @@ -30,7 +30,7 @@ export class GetVerifiedViewV1200ResponsePB extends Message [ { no: 1, name: "data", kind: "scalar", T: 9 /* ScalarType.STRING */ }, ]); diff --git a/packages/cacti-copm-core/src/main/typescript/generated/models/get_verified_view_v1_request_pb_pb.ts b/packages/cacti-copm-core/src/main/typescript/generated/models/get_verified_view_v1_request_pb_pb.ts index 766a57fb7d..0ccf8b1233 100644 --- a/packages/cacti-copm-core/src/main/typescript/generated/models/get_verified_view_v1_request_pb_pb.ts +++ b/packages/cacti-copm-core/src/main/typescript/generated/models/get_verified_view_v1_request_pb_pb.ts @@ -3,12 +3,12 @@ // //Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. // -//The version of the OpenAPI document: 2.0.0-rc.2 +//The version of the OpenAPI document: 2.0.0 // //Generated by OpenAPI Generator: https://openapi-generator.tech // @generated by protoc-gen-es v1.8.0 with parameter "target=ts" -// @generated from file models/get_verified_view_v1_request_pb.proto (package org.hyperledger.cacti.plugin.cacti.plugin.copm.core, syntax proto3) +// @generated from file models/get_verified_view_v1_request_pb.proto (package org.hyperledger.cacti.plugin.copm.core, syntax proto3) /* eslint-disable */ // @ts-nocheck @@ -18,16 +18,16 @@ import { AssetAccountV1PB } from "./asset_account_v1_pb_pb.js"; import { ViewV1PB } from "./view_v1_pb_pb.js"; /** - * @generated from message org.hyperledger.cacti.plugin.cacti.plugin.copm.core.GetVerifiedViewV1RequestPB + * @generated from message org.hyperledger.cacti.plugin.copm.core.GetVerifiedViewV1RequestPB */ export class GetVerifiedViewV1RequestPB extends Message { /** - * @generated from field: org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetAccountV1PB account = 103577045; + * @generated from field: org.hyperledger.cacti.plugin.copm.core.AssetAccountV1PB account = 103577045; */ account?: AssetAccountV1PB; /** - * @generated from field: org.hyperledger.cacti.plugin.cacti.plugin.copm.core.ViewV1PB view = 3619493; + * @generated from field: org.hyperledger.cacti.plugin.copm.core.ViewV1PB view = 3619493; */ view?: ViewV1PB; @@ -37,7 +37,7 @@ export class GetVerifiedViewV1RequestPB extends Message [ { no: 103577045, name: "account", kind: "message", T: AssetAccountV1PB }, { no: 3619493, name: "view", kind: "message", T: ViewV1PB }, diff --git a/packages/cacti-copm-core/src/main/typescript/generated/models/hash_info_v1_pb_pb.ts b/packages/cacti-copm-core/src/main/typescript/generated/models/hash_info_v1_pb_pb.ts index b62ab840ac..5fa2a2b377 100644 --- a/packages/cacti-copm-core/src/main/typescript/generated/models/hash_info_v1_pb_pb.ts +++ b/packages/cacti-copm-core/src/main/typescript/generated/models/hash_info_v1_pb_pb.ts @@ -3,12 +3,12 @@ // //Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. // -//The version of the OpenAPI document: 2.0.0-rc.2 +//The version of the OpenAPI document: 2.0.0 // //Generated by OpenAPI Generator: https://openapi-generator.tech // @generated by protoc-gen-es v1.8.0 with parameter "target=ts" -// @generated from file models/hash_info_v1_pb.proto (package org.hyperledger.cacti.plugin.cacti.plugin.copm.core, syntax proto3) +// @generated from file models/hash_info_v1_pb.proto (package org.hyperledger.cacti.plugin.copm.core, syntax proto3) /* eslint-disable */ // @ts-nocheck @@ -16,7 +16,7 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialM import { Message, proto3 } from "@bufbuild/protobuf"; /** - * @generated from message org.hyperledger.cacti.plugin.cacti.plugin.copm.core.HashInfoV1PB + * @generated from message org.hyperledger.cacti.plugin.copm.core.HashInfoV1PB */ export class HashInfoV1PB extends Message { /** @@ -35,7 +35,7 @@ export class HashInfoV1PB extends Message { } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "org.hyperledger.cacti.plugin.cacti.plugin.copm.core.HashInfoV1PB"; + static readonly typeName = "org.hyperledger.cacti.plugin.copm.core.HashInfoV1PB"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ { no: 1, name: "hash_fcn", kind: "scalar", T: 9 /* ScalarType.STRING */ }, { no: 2, name: "secret", kind: "scalar", T: 9 /* ScalarType.STRING */ }, diff --git a/packages/cacti-copm-core/src/main/typescript/generated/models/lock_asset_v1200_response_pb_pb.ts b/packages/cacti-copm-core/src/main/typescript/generated/models/lock_asset_v1200_response_pb_pb.ts index 960b565eb3..b2dbea9ece 100644 --- a/packages/cacti-copm-core/src/main/typescript/generated/models/lock_asset_v1200_response_pb_pb.ts +++ b/packages/cacti-copm-core/src/main/typescript/generated/models/lock_asset_v1200_response_pb_pb.ts @@ -3,12 +3,12 @@ // //Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. // -//The version of the OpenAPI document: 2.0.0-rc.2 +//The version of the OpenAPI document: 2.0.0 // //Generated by OpenAPI Generator: https://openapi-generator.tech // @generated by protoc-gen-es v1.8.0 with parameter "target=ts" -// @generated from file models/lock_asset_v1200_response_pb.proto (package org.hyperledger.cacti.plugin.cacti.plugin.copm.core, syntax proto3) +// @generated from file models/lock_asset_v1200_response_pb.proto (package org.hyperledger.cacti.plugin.copm.core, syntax proto3) /* eslint-disable */ // @ts-nocheck @@ -16,7 +16,7 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialM import { Message, proto3 } from "@bufbuild/protobuf"; /** - * @generated from message org.hyperledger.cacti.plugin.cacti.plugin.copm.core.LockAssetV1200ResponsePB + * @generated from message org.hyperledger.cacti.plugin.copm.core.LockAssetV1200ResponsePB */ export class LockAssetV1200ResponsePB extends Message { /** @@ -30,7 +30,7 @@ export class LockAssetV1200ResponsePB extends Message } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "org.hyperledger.cacti.plugin.cacti.plugin.copm.core.LockAssetV1200ResponsePB"; + static readonly typeName = "org.hyperledger.cacti.plugin.copm.core.LockAssetV1200ResponsePB"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ { no: 1, name: "lock_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, ]); diff --git a/packages/cacti-copm-core/src/main/typescript/generated/models/pledge_asset_v1200_response_pb_pb.ts b/packages/cacti-copm-core/src/main/typescript/generated/models/pledge_asset_v1200_response_pb_pb.ts index 3f5ba88b9b..28327fe261 100644 --- a/packages/cacti-copm-core/src/main/typescript/generated/models/pledge_asset_v1200_response_pb_pb.ts +++ b/packages/cacti-copm-core/src/main/typescript/generated/models/pledge_asset_v1200_response_pb_pb.ts @@ -3,12 +3,12 @@ // //Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. // -//The version of the OpenAPI document: 2.0.0-rc.2 +//The version of the OpenAPI document: 2.0.0 // //Generated by OpenAPI Generator: https://openapi-generator.tech // @generated by protoc-gen-es v1.8.0 with parameter "target=ts" -// @generated from file models/pledge_asset_v1200_response_pb.proto (package org.hyperledger.cacti.plugin.cacti.plugin.copm.core, syntax proto3) +// @generated from file models/pledge_asset_v1200_response_pb.proto (package org.hyperledger.cacti.plugin.copm.core, syntax proto3) /* eslint-disable */ // @ts-nocheck @@ -16,7 +16,7 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialM import { Message, proto3 } from "@bufbuild/protobuf"; /** - * @generated from message org.hyperledger.cacti.plugin.cacti.plugin.copm.core.PledgeAssetV1200ResponsePB + * @generated from message org.hyperledger.cacti.plugin.copm.core.PledgeAssetV1200ResponsePB */ export class PledgeAssetV1200ResponsePB extends Message { /** @@ -30,7 +30,7 @@ export class PledgeAssetV1200ResponsePB extends Message [ { no: 1, name: "pledge_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, ]); diff --git a/packages/cacti-copm-core/src/main/typescript/generated/models/transferrable_asset_v1_pb_pb.ts b/packages/cacti-copm-core/src/main/typescript/generated/models/transferrable_asset_v1_pb_pb.ts index e0229c17d9..43bfb9381b 100644 --- a/packages/cacti-copm-core/src/main/typescript/generated/models/transferrable_asset_v1_pb_pb.ts +++ b/packages/cacti-copm-core/src/main/typescript/generated/models/transferrable_asset_v1_pb_pb.ts @@ -3,12 +3,12 @@ // //Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. // -//The version of the OpenAPI document: 2.0.0-rc.2 +//The version of the OpenAPI document: 2.0.0 // //Generated by OpenAPI Generator: https://openapi-generator.tech // @generated by protoc-gen-es v1.8.0 with parameter "target=ts" -// @generated from file models/transferrable_asset_v1_pb.proto (package org.hyperledger.cacti.plugin.cacti.plugin.copm.core, syntax proto3) +// @generated from file models/transferrable_asset_v1_pb.proto (package org.hyperledger.cacti.plugin.copm.core, syntax proto3) /* eslint-disable */ // @ts-nocheck @@ -16,7 +16,7 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialM import { Message, proto3 } from "@bufbuild/protobuf"; /** - * @generated from message org.hyperledger.cacti.plugin.cacti.plugin.copm.core.TransferrableAssetV1PB + * @generated from message org.hyperledger.cacti.plugin.copm.core.TransferrableAssetV1PB */ export class TransferrableAssetV1PB extends Message { /** @@ -42,7 +42,7 @@ export class TransferrableAssetV1PB extends Message { } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "org.hyperledger.cacti.plugin.cacti.plugin.copm.core.TransferrableAssetV1PB"; + static readonly typeName = "org.hyperledger.cacti.plugin.copm.core.TransferrableAssetV1PB"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ { no: 1, name: "asset_type", kind: "scalar", T: 9 /* ScalarType.STRING */ }, { no: 2, name: "asset_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, diff --git a/packages/cacti-copm-core/src/main/typescript/generated/models/view_address_v1_pb_pb.ts b/packages/cacti-copm-core/src/main/typescript/generated/models/view_address_v1_pb_pb.ts index d77298551c..6e3ba7d876 100644 --- a/packages/cacti-copm-core/src/main/typescript/generated/models/view_address_v1_pb_pb.ts +++ b/packages/cacti-copm-core/src/main/typescript/generated/models/view_address_v1_pb_pb.ts @@ -3,12 +3,12 @@ // //Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. // -//The version of the OpenAPI document: 2.0.0-rc.2 +//The version of the OpenAPI document: 2.0.0 // //Generated by OpenAPI Generator: https://openapi-generator.tech // @generated by protoc-gen-es v1.8.0 with parameter "target=ts" -// @generated from file models/view_address_v1_pb.proto (package org.hyperledger.cacti.plugin.cacti.plugin.copm.core, syntax proto3) +// @generated from file models/view_address_v1_pb.proto (package org.hyperledger.cacti.plugin.copm.core, syntax proto3) /* eslint-disable */ // @ts-nocheck @@ -16,7 +16,7 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialM import { Message, proto3 } from "@bufbuild/protobuf"; /** - * @generated from message org.hyperledger.cacti.plugin.cacti.plugin.copm.core.ViewAddressV1PB + * @generated from message org.hyperledger.cacti.plugin.copm.core.ViewAddressV1PB */ export class ViewAddressV1PB extends Message { /** @@ -40,7 +40,7 @@ export class ViewAddressV1PB extends Message { } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "org.hyperledger.cacti.plugin.cacti.plugin.copm.core.ViewAddressV1PB"; + static readonly typeName = "org.hyperledger.cacti.plugin.copm.core.ViewAddressV1PB"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ { no: 1, name: "contract_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, { no: 2, name: "function", kind: "scalar", T: 9 /* ScalarType.STRING */ }, diff --git a/packages/cacti-copm-core/src/main/typescript/generated/models/view_v1_pb_pb.ts b/packages/cacti-copm-core/src/main/typescript/generated/models/view_v1_pb_pb.ts index 5174c3a1a6..e16bc7901d 100644 --- a/packages/cacti-copm-core/src/main/typescript/generated/models/view_v1_pb_pb.ts +++ b/packages/cacti-copm-core/src/main/typescript/generated/models/view_v1_pb_pb.ts @@ -3,12 +3,12 @@ // //Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. // -//The version of the OpenAPI document: 2.0.0-rc.2 +//The version of the OpenAPI document: 2.0.0 // //Generated by OpenAPI Generator: https://openapi-generator.tech // @generated by protoc-gen-es v1.8.0 with parameter "target=ts" -// @generated from file models/view_v1_pb.proto (package org.hyperledger.cacti.plugin.cacti.plugin.copm.core, syntax proto3) +// @generated from file models/view_v1_pb.proto (package org.hyperledger.cacti.plugin.copm.core, syntax proto3) /* eslint-disable */ // @ts-nocheck @@ -17,7 +17,7 @@ import { Message, proto3 } from "@bufbuild/protobuf"; import { ViewAddressV1PB } from "./view_address_v1_pb_pb.js"; /** - * @generated from message org.hyperledger.cacti.plugin.cacti.plugin.copm.core.ViewV1PB + * @generated from message org.hyperledger.cacti.plugin.copm.core.ViewV1PB */ export class ViewV1PB extends Message { /** @@ -26,7 +26,7 @@ export class ViewV1PB extends Message { network = ""; /** - * @generated from field: org.hyperledger.cacti.plugin.cacti.plugin.copm.core.ViewAddressV1PB view_address = 312477787; + * @generated from field: org.hyperledger.cacti.plugin.copm.core.ViewAddressV1PB view_address = 312477787; */ viewAddress?: ViewAddressV1PB; @@ -36,7 +36,7 @@ export class ViewV1PB extends Message { } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "org.hyperledger.cacti.plugin.cacti.plugin.copm.core.ViewV1PB"; + static readonly typeName = "org.hyperledger.cacti.plugin.copm.core.ViewV1PB"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ { no: 1, name: "network", kind: "scalar", T: 9 /* ScalarType.STRING */ }, { no: 312477787, name: "view_address", kind: "message", T: ViewAddressV1PB }, diff --git a/packages/cacti-copm-core/src/main/typescript/generated/services/default_service_connect.ts b/packages/cacti-copm-core/src/main/typescript/generated/services/default_service_connect.ts index 822da62084..39a3a8c1a6 100644 --- a/packages/cacti-copm-core/src/main/typescript/generated/services/default_service_connect.ts +++ b/packages/cacti-copm-core/src/main/typescript/generated/services/default_service_connect.ts @@ -3,30 +3,30 @@ // //Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. // -//The version of the OpenAPI document: 2.0.0-rc.2 +//The version of the OpenAPI document: 2.0.0 // //Generated by OpenAPI Generator: https://openapi-generator.tech // @generated by protoc-gen-connect-es v1.4.0 with parameter "target=ts" -// @generated from file services/default_service.proto (package org.hyperledger.cacti.plugin.cacti.plugin.copm.core.services.defaultservice, syntax proto3) +// @generated from file services/default_service.proto (package org.hyperledger.cacti.plugin.copm.core.services.defaultservice, syntax proto3) /* eslint-disable */ // @ts-nocheck import { ClaimLockedAssetV1Request, ClaimPledgedAssetV1Request, GetVerifiedViewV1Request, LockAssetV1Request, PledgeAssetV1Request } from "./default_service_pb.js"; import { ClaimPledgedAssetV1200ResponsePB } from "../models/claim_pledged_asset_v1200_response_pb_pb.js"; -import { MethodKind } from "@bufbuild/protobuf"; +import { Empty, MethodKind } from "@bufbuild/protobuf"; import { GetVerifiedViewV1200ResponsePB } from "../models/get_verified_view_v1200_response_pb_pb.js"; import { LockAssetV1200ResponsePB } from "../models/lock_asset_v1200_response_pb_pb.js"; import { PledgeAssetV1200ResponsePB } from "../models/pledge_asset_v1200_response_pb_pb.js"; /** - * @generated from service org.hyperledger.cacti.plugin.cacti.plugin.copm.core.services.defaultservice.DefaultService + * @generated from service org.hyperledger.cacti.plugin.copm.core.services.defaultservice.DefaultService */ export const DefaultService = { - typeName: "org.hyperledger.cacti.plugin.cacti.plugin.copm.core.services.defaultservice.DefaultService", + typeName: "org.hyperledger.cacti.plugin.copm.core.services.defaultservice.DefaultService", methods: { /** - * @generated from rpc org.hyperledger.cacti.plugin.cacti.plugin.copm.core.services.defaultservice.DefaultService.ClaimLockedAssetV1 + * @generated from rpc org.hyperledger.cacti.plugin.copm.core.services.defaultservice.DefaultService.ClaimLockedAssetV1 */ claimLockedAssetV1: { name: "ClaimLockedAssetV1", @@ -35,7 +35,7 @@ export const DefaultService = { kind: MethodKind.Unary, }, /** - * @generated from rpc org.hyperledger.cacti.plugin.cacti.plugin.copm.core.services.defaultservice.DefaultService.ClaimPledgedAssetV1 + * @generated from rpc org.hyperledger.cacti.plugin.copm.core.services.defaultservice.DefaultService.ClaimPledgedAssetV1 */ claimPledgedAssetV1: { name: "ClaimPledgedAssetV1", @@ -44,7 +44,7 @@ export const DefaultService = { kind: MethodKind.Unary, }, /** - * @generated from rpc org.hyperledger.cacti.plugin.cacti.plugin.copm.core.services.defaultservice.DefaultService.GetVerifiedViewV1 + * @generated from rpc org.hyperledger.cacti.plugin.copm.core.services.defaultservice.DefaultService.GetVerifiedViewV1 */ getVerifiedViewV1: { name: "GetVerifiedViewV1", @@ -53,7 +53,7 @@ export const DefaultService = { kind: MethodKind.Unary, }, /** - * @generated from rpc org.hyperledger.cacti.plugin.cacti.plugin.copm.core.services.defaultservice.DefaultService.LockAssetV1 + * @generated from rpc org.hyperledger.cacti.plugin.copm.core.services.defaultservice.DefaultService.LockAssetV1 */ lockAssetV1: { name: "LockAssetV1", @@ -62,7 +62,16 @@ export const DefaultService = { kind: MethodKind.Unary, }, /** - * @generated from rpc org.hyperledger.cacti.plugin.cacti.plugin.copm.core.services.defaultservice.DefaultService.PledgeAssetV1 + * @generated from rpc org.hyperledger.cacti.plugin.copm.core.services.defaultservice.DefaultService.NoopV1 + */ + noopV1: { + name: "NoopV1", + I: Empty, + O: Empty, + kind: MethodKind.Unary, + }, + /** + * @generated from rpc org.hyperledger.cacti.plugin.copm.core.services.defaultservice.DefaultService.PledgeAssetV1 */ pledgeAssetV1: { name: "PledgeAssetV1", diff --git a/packages/cacti-copm-core/src/main/typescript/generated/services/default_service_pb.ts b/packages/cacti-copm-core/src/main/typescript/generated/services/default_service_pb.ts index 6211af85bd..58bdbae298 100644 --- a/packages/cacti-copm-core/src/main/typescript/generated/services/default_service_pb.ts +++ b/packages/cacti-copm-core/src/main/typescript/generated/services/default_service_pb.ts @@ -3,12 +3,12 @@ // //Contains/describes the Hyperledger Cacti Common Operator Primitives plugin. These primitives require specific chaincode and weaver relays to be deployed on the network as described at https://hyperledger-cacti.github.io/cacti/weaver/introduction/. // -//The version of the OpenAPI document: 2.0.0-rc.2 +//The version of the OpenAPI document: 2.0.0 // //Generated by OpenAPI Generator: https://openapi-generator.tech // @generated by protoc-gen-es v1.8.0 with parameter "target=ts" -// @generated from file services/default_service.proto (package org.hyperledger.cacti.plugin.cacti.plugin.copm.core.services.defaultservice, syntax proto3) +// @generated from file services/default_service.proto (package org.hyperledger.cacti.plugin.copm.core.services.defaultservice, syntax proto3) /* eslint-disable */ // @ts-nocheck @@ -21,13 +21,13 @@ import { AssetLockV1PB } from "../models/asset_lock_v1_pb_pb.js"; import { AssetPledgeV1PB } from "../models/asset_pledge_v1_pb_pb.js"; /** - * @generated from message org.hyperledger.cacti.plugin.cacti.plugin.copm.core.services.defaultservice.ClaimLockedAssetV1Request + * @generated from message org.hyperledger.cacti.plugin.copm.core.services.defaultservice.ClaimLockedAssetV1Request */ export class ClaimLockedAssetV1Request extends Message { /** * * - * @generated from field: org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetLockClaimV1PB assetLockClaimV1PB = 1; + * @generated from field: org.hyperledger.cacti.plugin.copm.core.AssetLockClaimV1PB assetLockClaimV1PB = 1; */ assetLockClaimV1PB?: AssetLockClaimV1PB; @@ -37,7 +37,7 @@ export class ClaimLockedAssetV1Request extends Message [ { no: 1, name: "assetLockClaimV1PB", kind: "message", T: AssetLockClaimV1PB }, ]); @@ -60,13 +60,13 @@ export class ClaimLockedAssetV1Request extends Message { /** * * - * @generated from field: org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetPledgeClaimV1PB assetPledgeClaimV1PB = 1; + * @generated from field: org.hyperledger.cacti.plugin.copm.core.AssetPledgeClaimV1PB assetPledgeClaimV1PB = 1; */ assetPledgeClaimV1PB?: AssetPledgeClaimV1PB; @@ -76,7 +76,7 @@ export class ClaimPledgedAssetV1Request extends Message [ { no: 1, name: "assetPledgeClaimV1PB", kind: "message", T: AssetPledgeClaimV1PB }, ]); @@ -99,13 +99,13 @@ export class ClaimPledgedAssetV1Request extends Message { /** * * - * @generated from field: org.hyperledger.cacti.plugin.cacti.plugin.copm.core.GetVerifiedViewV1RequestPB getVerifiedViewV1RequestPB = 1; + * @generated from field: org.hyperledger.cacti.plugin.copm.core.GetVerifiedViewV1RequestPB getVerifiedViewV1RequestPB = 1; */ getVerifiedViewV1RequestPB?: GetVerifiedViewV1RequestPB; @@ -115,7 +115,7 @@ export class GetVerifiedViewV1Request extends Message } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "org.hyperledger.cacti.plugin.cacti.plugin.copm.core.services.defaultservice.GetVerifiedViewV1Request"; + static readonly typeName = "org.hyperledger.cacti.plugin.copm.core.services.defaultservice.GetVerifiedViewV1Request"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ { no: 1, name: "getVerifiedViewV1RequestPB", kind: "message", T: GetVerifiedViewV1RequestPB }, ]); @@ -138,13 +138,13 @@ export class GetVerifiedViewV1Request extends Message } /** - * @generated from message org.hyperledger.cacti.plugin.cacti.plugin.copm.core.services.defaultservice.LockAssetV1Request + * @generated from message org.hyperledger.cacti.plugin.copm.core.services.defaultservice.LockAssetV1Request */ export class LockAssetV1Request extends Message { /** * * - * @generated from field: org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetLockV1PB assetLockV1PB = 1; + * @generated from field: org.hyperledger.cacti.plugin.copm.core.AssetLockV1PB assetLockV1PB = 1; */ assetLockV1PB?: AssetLockV1PB; @@ -154,7 +154,7 @@ export class LockAssetV1Request extends Message { } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "org.hyperledger.cacti.plugin.cacti.plugin.copm.core.services.defaultservice.LockAssetV1Request"; + static readonly typeName = "org.hyperledger.cacti.plugin.copm.core.services.defaultservice.LockAssetV1Request"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ { no: 1, name: "assetLockV1PB", kind: "message", T: AssetLockV1PB }, ]); @@ -177,13 +177,13 @@ export class LockAssetV1Request extends Message { } /** - * @generated from message org.hyperledger.cacti.plugin.cacti.plugin.copm.core.services.defaultservice.PledgeAssetV1Request + * @generated from message org.hyperledger.cacti.plugin.copm.core.services.defaultservice.PledgeAssetV1Request */ export class PledgeAssetV1Request extends Message { /** * * - * @generated from field: org.hyperledger.cacti.plugin.cacti.plugin.copm.core.AssetPledgeV1PB assetPledgeV1PB = 1; + * @generated from field: org.hyperledger.cacti.plugin.copm.core.AssetPledgeV1PB assetPledgeV1PB = 1; */ assetPledgeV1PB?: AssetPledgeV1PB; @@ -193,7 +193,7 @@ export class PledgeAssetV1Request extends Message { } static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "org.hyperledger.cacti.plugin.cacti.plugin.copm.core.services.defaultservice.PledgeAssetV1Request"; + static readonly typeName = "org.hyperledger.cacti.plugin.copm.core.services.defaultservice.PledgeAssetV1Request"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ { no: 1, name: "assetPledgeV1PB", kind: "message", T: AssetPledgeV1PB }, ]); diff --git a/packages/cacti-copm-core/src/main/typescript/interfaces/interop-configuration.ts b/packages/cacti-copm-core/src/main/typescript/interfaces/interop-configuration.ts index 55aa2ffcbc..355b38f12f 100644 --- a/packages/cacti-copm-core/src/main/typescript/interfaces/interop-configuration.ts +++ b/packages/cacti-copm-core/src/main/typescript/interfaces/interop-configuration.ts @@ -1,7 +1,16 @@ -import { LocalRelayConfig, RemoteNetworkConfig } from "../lib/types"; +import { + LocalRelayConfig, + RemoteNetworkConfig, + DLTransactionParams, +} from "../lib/types"; export interface InteropConfiguration { getLocalRelayConfig(orgKey: string): LocalRelayConfig; getRemoteNetworkConfig(remoteOrgKey: string): RemoteNetworkConfig; + getRemotePledgeStatusCmd( + remoteOrgKey: string, + ValidatedClaimPledgedAssetRequest, + ): DLTransactionParams; + interopContractName: string; } diff --git a/packages/cacti-copm-core/src/main/typescript/lib/transferrable-asset.ts b/packages/cacti-copm-core/src/main/typescript/lib/transferrable-asset.ts index b1edca0b21..78cbdf721f 100644 --- a/packages/cacti-copm-core/src/main/typescript/lib/transferrable-asset.ts +++ b/packages/cacti-copm-core/src/main/typescript/lib/transferrable-asset.ts @@ -23,4 +23,8 @@ export class TransferrableAsset { return this.asset.assetId || ""; } } + + public quantity(): number { + return this.asset.assetQuantity || 0; + } } diff --git a/packages/cacti-copm-core/src/main/typescript/lib/types.ts b/packages/cacti-copm-core/src/main/typescript/lib/types.ts index 0f5ad835af..b00fda226d 100644 --- a/packages/cacti-copm-core/src/main/typescript/lib/types.ts +++ b/packages/cacti-copm-core/src/main/typescript/lib/types.ts @@ -1,7 +1,8 @@ export type DLTransactionParams = { contract: string; method: string; - args: string[]; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + args: any[]; }; export type DLAccount = { @@ -15,12 +16,11 @@ export type CopmContractNames = { }; export type RemoteNetworkConfig = { - channelName: string; + channelName: string; // fabric-specific network: string; relayAddr: string; e2eConfidentiality: boolean; partyEndPoint: string; // corda-specific - flowPackage: string; // corda-specific networkType: string; }; diff --git a/packages/cacti-copm-core/src/main/typescript/lib/view-address.ts b/packages/cacti-copm-core/src/main/typescript/lib/view-address.ts index 281bf8e622..78cbf0a7e4 100644 --- a/packages/cacti-copm-core/src/main/typescript/lib/view-address.ts +++ b/packages/cacti-copm-core/src/main/typescript/lib/view-address.ts @@ -32,7 +32,7 @@ export class ViewAddress { "/" + this.remoteNetConfig.partyEndPoint + "#" + - this.remoteNetConfig.flowPackage + + this.transactionParams.contract + "." + this.transactionParams.method + ":" + diff --git a/packages/cacti-copm-core/src/main/typescript/public-api.ts b/packages/cacti-copm-core/src/main/typescript/public-api.ts index da97af5f13..f771dd30fc 100755 --- a/packages/cacti-copm-core/src/main/typescript/public-api.ts +++ b/packages/cacti-copm-core/src/main/typescript/public-api.ts @@ -21,5 +21,6 @@ export { DLTransactionParams, } from "./lib/types"; export { ViewAddress } from "./lib/view-address"; +export { TransferrableAsset } from "./lib/transferrable-asset"; export * as Interfaces from "./interfaces"; export * as Validators from "./validators"; diff --git a/packages/cacti-copm-core/src/main/typescript/validators.ts b/packages/cacti-copm-core/src/main/typescript/validators.ts index 5af7b64ab2..6949921df3 100644 --- a/packages/cacti-copm-core/src/main/typescript/validators.ts +++ b/packages/cacti-copm-core/src/main/typescript/validators.ts @@ -1,5 +1,5 @@ export { validateClaimLockedAssetRequest } from "./validators/validate_claim_locked_asset_request"; -export { validateClaimPledgedAssetRequest } from "./validators/validate_claim_pledged_asset_request"; +export { ValidatedClaimPledgedAssetRequest } from "./validators/validated_claim_pledged_asset_request"; export { validateLockAssetRequest } from "./validators/validate_lock_asset_request"; export { validatePledgeAssetRequest } from "./validators/validate_pledge_asset_request"; export { validateGetVerifiedViewRequest } from "./validators/validate_get_verified_view_request"; diff --git a/packages/cacti-copm-core/src/main/typescript/validators/common.ts b/packages/cacti-copm-core/src/main/typescript/validators/common.ts index 74307cd676..fb11ddca5a 100644 --- a/packages/cacti-copm-core/src/main/typescript/validators/common.ts +++ b/packages/cacti-copm-core/src/main/typescript/validators/common.ts @@ -78,3 +78,13 @@ export function validateHashInfo( hash.setPreimage(hashInfo.secret); return hash; } + +export function validateRequiredString( + value: string | undefined, + object_prefix: string, +): string { + if (!value) { + throw new ConnectError(`${object_prefix} required`, Code.InvalidArgument); + } + return value; +} diff --git a/packages/cacti-copm-core/src/main/typescript/validators/validate_claim_locked_asset_request.ts b/packages/cacti-copm-core/src/main/typescript/validators/validate_claim_locked_asset_request.ts index bb2ed4b5be..a0e53e3378 100644 --- a/packages/cacti-copm-core/src/main/typescript/validators/validate_claim_locked_asset_request.ts +++ b/packages/cacti-copm-core/src/main/typescript/validators/validate_claim_locked_asset_request.ts @@ -6,6 +6,7 @@ import { validateTransferrableAsset, validateHashInfo, validateAssetAccount, + validateRequiredString, } from "./common"; import { ClaimLockedAssetV1Request } from "../generated/services/default_service_pb"; @@ -16,43 +17,10 @@ export function validateClaimLockedAssetRequest( destination: DLAccount; hashInfo: HashFunctions.Hash; lockId: string; - sourceCertificate: string; - destCertificate: string; } { if (!req.assetLockClaimV1PB) { throw new ConnectError(`request data is required`, Code.InvalidArgument); } - if ( - !req.assetLockClaimV1PB?.asset?.assetId && - !req.assetLockClaimV1PB?.lockId - ) { - throw new ConnectError( - "either lockId or asset.assetId is required", - Code.InvalidArgument, - ); - } - - if (req.assetLockClaimV1PB?.asset.assetId) { - if (!req.assetLockClaimV1PB?.destCertificate) { - throw new ConnectError( - "destinationCertificate required for NFT claim", - Code.InvalidArgument, - ); - } - if (!req.assetLockClaimV1PB?.sourceCertificate) { - throw new ConnectError( - "sourceCertificate required for NFT claim", - Code.InvalidArgument, - ); - } - } else { - if (!req.assetLockClaimV1PB.lockId) { - throw new ConnectError( - "lockId must be supplied for fungible assets", - Code.InvalidArgument, - ); - } - } return { asset: validateTransferrableAsset(req.assetLockClaimV1PB.asset, "asset"), @@ -61,8 +29,6 @@ export function validateClaimLockedAssetRequest( req.assetLockClaimV1PB.destination, "destination", ), - sourceCertificate: req.assetLockClaimV1PB.sourceCertificate || "", - destCertificate: req.assetLockClaimV1PB.destCertificate || "", - lockId: req.assetLockClaimV1PB.lockId || "", + lockId: validateRequiredString(req.assetLockClaimV1PB.lockId, "lockId"), }; } diff --git a/packages/cacti-copm-core/src/main/typescript/validators/validate_claim_pledged_asset_request.ts b/packages/cacti-copm-core/src/main/typescript/validators/validate_claim_pledged_asset_request.ts deleted file mode 100644 index f8181c5656..0000000000 --- a/packages/cacti-copm-core/src/main/typescript/validators/validate_claim_pledged_asset_request.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { TransferrableAsset } from "../lib/transferrable-asset"; -import { DLAccount } from "../lib/types"; -import { ConnectError, Code } from "@connectrpc/connect"; -import { validateTransferrableAsset, validateAssetAccount } from "./common"; -import { ClaimPledgedAssetV1Request } from "../generated/services/default_service_pb"; - -export function validateClaimPledgedAssetRequest( - req: ClaimPledgedAssetV1Request, -): { - asset: TransferrableAsset; - sourceCert: string; - destCert: string; - destAccount: DLAccount; - sourceNetwork: string; - pledgeId: string; -} { - if (!req.assetPledgeClaimV1PB) { - throw new ConnectError("request data required", Code.InvalidArgument); - } - if (!req.assetPledgeClaimV1PB.destCertificate) { - throw new ConnectError("destCertificate required", Code.InvalidArgument); - } - if (!req.assetPledgeClaimV1PB.sourceCertificate) { - throw new ConnectError("sourceCertificate required", Code.InvalidArgument); - } - if (!req.assetPledgeClaimV1PB.source?.network) { - throw new ConnectError("source.network required", Code.InvalidArgument); - } - if (!req.assetPledgeClaimV1PB.pledgeId) { - throw new ConnectError("pledgeId required", Code.InvalidArgument); - } - return { - destAccount: validateAssetAccount( - req.assetPledgeClaimV1PB.destination, - "destination", - ), - asset: validateTransferrableAsset(req.assetPledgeClaimV1PB.asset, "asset"), - pledgeId: req.assetPledgeClaimV1PB.pledgeId, - sourceNetwork: req.assetPledgeClaimV1PB.source.network, - sourceCert: req.assetPledgeClaimV1PB.sourceCertificate, - destCert: req.assetPledgeClaimV1PB.destCertificate, - }; -} diff --git a/packages/cacti-copm-core/src/main/typescript/validators/validate_lock_asset_request.ts b/packages/cacti-copm-core/src/main/typescript/validators/validate_lock_asset_request.ts index ea8e690c21..f89d2e98d4 100644 --- a/packages/cacti-copm-core/src/main/typescript/validators/validate_lock_asset_request.ts +++ b/packages/cacti-copm-core/src/main/typescript/validators/validate_lock_asset_request.ts @@ -10,7 +10,7 @@ import { LockAssetV1Request } from "../generated/services/default_service_pb"; import { HashFunctions } from "@hyperledger/cacti-weaver-sdk-fabric"; export function validateLockAssetRequest(request: LockAssetV1Request): { - owner: DLAccount; + sourceAccount: DLAccount; hashInfo: HashFunctions.Hash; sourceCertificate: string; destinationCertificate: string; @@ -29,8 +29,10 @@ export function validateLockAssetRequest(request: LockAssetV1Request): { if (!request.assetLockV1PB.sourceCertificate) { throw new ConnectError("sourceCertificate required", Code.InvalidArgument); } + + // destination account is required only in CORDA implementation return { - owner: validateAssetAccount(request.assetLockV1PB.owner, "owner"), + sourceAccount: validateAssetAccount(request.assetLockV1PB.source, "source"), hashInfo: validateHashInfo(request.assetLockV1PB.hashInfo, "hashInfo"), asset: validateTransferrableAsset(request.assetLockV1PB.asset, "asset"), sourceCertificate: request.assetLockV1PB.sourceCertificate, diff --git a/packages/cacti-copm-core/src/main/typescript/validators/validated_claim_pledged_asset_request.ts b/packages/cacti-copm-core/src/main/typescript/validators/validated_claim_pledged_asset_request.ts new file mode 100644 index 0000000000..dfa3867b3a --- /dev/null +++ b/packages/cacti-copm-core/src/main/typescript/validators/validated_claim_pledged_asset_request.ts @@ -0,0 +1,50 @@ +import { TransferrableAsset } from "../lib/transferrable-asset"; +import { DLAccount } from "../lib/types"; +import { ConnectError, Code } from "@connectrpc/connect"; +import { + validateTransferrableAsset, + validateAssetAccount, + validateRequiredString, +} from "./common"; +import { ClaimPledgedAssetV1Request } from "../generated/services/default_service_pb"; + +export class ValidatedClaimPledgedAssetRequest { + public asset: TransferrableAsset; + public sourceCert: string; + public destCert: string; + public destAccount: DLAccount; + public sourceNetwork: string; + public pledgeId: string; + + constructor(req: ClaimPledgedAssetV1Request) { + if (!req.assetPledgeClaimV1PB) { + throw new ConnectError("request data required", Code.InvalidArgument); + } + + this.destCert = validateRequiredString( + req.assetPledgeClaimV1PB.destCertificate, + "destCertificate", + ); + this.sourceCert = validateRequiredString( + req.assetPledgeClaimV1PB.sourceCertificate, + "sourceCertificate", + ); + this.pledgeId = validateRequiredString( + req.assetPledgeClaimV1PB.pledgeId, + "pledgeId", + ); + + this.sourceNetwork = validateRequiredString( + req.assetPledgeClaimV1PB.source?.network, + "source.network", + ); + (this.destAccount = validateAssetAccount( + req.assetPledgeClaimV1PB.destination, + "destination", + )), + (this.asset = validateTransferrableAsset( + req.assetPledgeClaimV1PB.asset, + "asset", + )); + } +} diff --git a/packages/cacti-copm-test/Makefile b/packages/cacti-copm-test/Makefile new file mode 100644 index 0000000000..2bef3e8fe5 --- /dev/null +++ b/packages/cacti-copm-test/Makefile @@ -0,0 +1,37 @@ +WORKSPACE ?= $(shell realpath `pwd`/../../) +DOCKER_IMAGES=hyperledger/fabric-orderer hyperledger/fabric-peer hyperledger/fabric-ca ghcr.io/hyperledger/cacti-weaver-iin-agent ghcr.io/hyperledger/cacti-weaver-relay-server ghcr.io/hyperledger/cacti-weaver-driver-fabric corda/community:4.12-zulu-openjdk ghcr.io/hyperledger/cacti-weaver-driver-corda copm-corda + +common-relay-config: + cd $(WORKSPACE)/weaver/core/relay && \ + make convert-compose-method2 + +%-setup: + make -f Makefile_$* setup + +%-lock-network: + make -f Makefile_$* lock-network + +%-pledge-network: + make -f Makefile_$* pledge-network + +define stop_docker +echo "removing $(1)" +docker stop `docker container ls -a -q -f ancestor=$(1) | xargs` || true +docker rm `docker container ls -a -q -f ancestor=$(1) | xargs` || true +endef + +clean-network: + $(foreach image,$(DOCKER_IMAGES),$(call stop_docker,$(image))) + cd $(WORKSPACE)/weaver/tests/network-setups/fabric/dev && make clean || true + docker volume prune -f + docker volume rm network2_peer0.org2.network2.com || true + docker volume rm network1_peer0.org2.network1.com || true + docker network rm corda_default || true + docker network rm corda_network2_default || true + docker network rm relay || true + if [ "$(shell id -un )" != "root" ]; then \ + sudo chown -R $(shell id -un ) $(WORKSPACE)/weaver/tests/network-setups/fabric/shared; \ + sudo rm -Rf $(WORKSPACE)/weaver/tests/network-setups/corda/dev/*/build || true; \ + fi + docker volume rm `docker volume ls | grep -v NAME | sed -e 's/local //g' | grep -v vscode | xargs` || true + cd $(WORKSPACE)/weaver/tests/network-setups/corda && make clean || true diff --git a/packages/cacti-copm-test/Makefile_corda b/packages/cacti-copm-test/Makefile_corda new file mode 100644 index 0000000000..ed6e39daba --- /dev/null +++ b/packages/cacti-copm-test/Makefile_corda @@ -0,0 +1,81 @@ +WORKSPACE ?= $(shell realpath `pwd`/../../) + +# DL-NETWORK --------------------------------------------------- + +corda-pledge-dl: + cd $(WORKSPACE)/weaver/tests/network-setups/corda && \ + ./scripts/get-cordapps.sh simple local && \ + make start-local + +corda-lock-dl: + cd $(WORKSPACE)/weaver/tests/network-setups/corda && \ + ./scripts/get-cordapps.sh simple local && \ + make start-network1-local PROFILE=3-nodes + +# DRIVERS ----------------------------------------------------- + +corda1-driver: + echo "starting corda driver 1" + cd $(WORKSPACE)/weaver/core/drivers/corda-driver && \ + make deploy COMPOSE_ARG='--env-file docker-testnet-envs/.env.corda' + +corda2-driver: + echo "starting corda driver 2" + cd $(WORKSPACE)/weaver/core/drivers/corda-driver && \ + make deploy COMPOSE_ARG='--env-file docker-testnet-envs/.env.corda2' + + +# RELAYS --------------------------------------------------------- + +common-relay-config: + make common-relay-config + +corda-relay-config: + cd $(WORKSPACE)/weaver/core/relay &&\ + make protos-local &&\ + cargo update -p nom &&\ + cargo update -p lexical-core + +corda1-relay: + echo "starting corda relay 1" + cd $(WORKSPACE)/weaver/core/relay &&\ + make start-server COMPOSE_ARG='--env-file docker/testnet-envs/.env.corda' + +corda2-relay: + echo "starting corda relay 2" + cd $(WORKSPACE)/weaver/core/relay &&\ + make start-server COMPOSE_ARG='--env-file docker/testnet-envs/.env.corda2' + + +# CLI -------------------------------------------------------------------------------------- + +corda-cli: + echo "preparing corda cli" + cd $(WORKSPACE)/weaver/samples/corda/corda-simple-application/clients/src/main/resources/config && \ + cp remote-network-config.json.template remote-network-config.json && \ + sed -i "s#localhost:9080#relay-network1:9080#g" remote-network-config.json && \ + sed -i "s#localhost:9081#relay-corda:9081#g" remote-network-config.json && \ + sed -i "s#localhost:9082#relay-corda2:9082#g" remote-network-config.json && \ + sed -i "s#localhost:9083#relay-network2:9083#g" remote-network-config.json && \ + sed -i "s#localhost:10006#corda_partya_1:10003#g" remote-network-config.json && \ + sed -i "s#localhost:30006#corda_network2_partya_1:10003#g" remote-network-config.json + + +corda-pledge-cli-setup: + cd $(WORKSPACE)/weaver/samples/corda/corda-simple-application &&\ + make initialise-vault-asset-transfer-docker + +# MAIN TARGETS + +PATH := $(PATH):$(WORKSPACE)/protoc/bin + +# SETUP - run once + +setup: + cd $(WORKSPACE)/packages/cacti-plugin-copm-corda/src/test/kotlin && make build-image-local + +pledge-network: corda-pledge-dl corda1-driver corda2-driver common-relay-config corda-relay-config corda1-relay corda2-relay corda-cli corda-pledge-cli-setup + +lock-network: corda-lock-dl corda-cli + + diff --git a/packages/cacti-plugin-copm-fabric/Makefile b/packages/cacti-copm-test/Makefile_fabric similarity index 81% rename from packages/cacti-plugin-copm-fabric/Makefile rename to packages/cacti-copm-test/Makefile_fabric index 9d2d12aa64..087107c4e6 100644 --- a/packages/cacti-plugin-copm-fabric/Makefile +++ b/packages/cacti-copm-test/Makefile_fabric @@ -1,27 +1,44 @@ WORKSPACE ?= $(shell realpath `pwd`/../../) -DOCKER_IMAGES=hyperledger/fabric-orderer hyperledger/fabric-peer hyperledger/fabric-ca ghcr.io/hyperledger/cacti-weaver-iin-agent ghcr.io/hyperledger/cacti-weaver-relay-server ghcr.io/hyperledger/cacti-weaver-driver-fabric pledge%: chaincode = simpleassettransfer lock%: chaincode = simpleasset -.fabric-network: +# DL-NETWORK --------------------------------------------------- + +fabric-dl: export GO111MODULE=auto + echo "making fabric DL network" cd $(WORKSPACE)/weaver/tests/network-setups/fabric/dev && \ make start-interop-local CHAINCODE_NAME=$(chaincode) PROFILE='2-nodes' -drivers: +# DRIVERS ----------------------------------------------------- + +fabric1-driver: cd $(WORKSPACE)/weaver/core/drivers/fabric-driver && \ sed -i "s##$(WORKSPACE)/weaver#g" docker-testnet-envs/.env.n1 &&\ + make deploy COMPOSE_ARG='--env-file docker-testnet-envs/.env.n1' NETWORK_NAME=network1 + +fabric2-driver: + cd $(WORKSPACE)/weaver/core/drivers/fabric-driver && \ sed -i "s##$(WORKSPACE)/weaver#g" docker-testnet-envs/.env.n2 && \ - make deploy COMPOSE_ARG='--env-file docker-testnet-envs/.env.n1' NETWORK_NAME=network1 && \ make deploy COMPOSE_ARG='--env-file docker-testnet-envs/.env.n2' NETWORK_NAME=network2 -relays: +# RELAYS --------------------------------------------------------- + +common-relay-config: + make common-relay-config + +fabric1-relay: + cd $(WORKSPACE)/weaver/core/relay && \ + make start-server COMPOSE_ARG='--env-file docker/testnet-envs/.env.n1' + +fabric2-relay: cd $(WORKSPACE)/weaver/core/relay && \ make convert-compose-method2 && \ - make start-server COMPOSE_ARG='--env-file docker/testnet-envs/.env.n1' && \ make start-server COMPOSE_ARG='--env-file docker/testnet-envs/.env.n2' +# IIN -------------------------------------------------------------------------------------- + iin: cd $(WORKSPACE)/weaver/core/identity-management/iin-agent && \ sed -i "s##$(WORKSPACE)/weaver#g" docker-testnet/envs/.env.n1.org1 && \ @@ -36,14 +53,14 @@ iin: sed -i "s##$(WORKSPACE)/weaver#g" docker-testnet/envs/.env.n2.org2 && \ sed -i "s#^AUTO_SYNC=true#AUTO_SYNC=false#g" docker-testnet/envs/.env.n2.org2 && \ sed -i "s#^DNS_CONFIG_PATH=.*#DNS_CONFIG_PATH=./docker-testnet/configs/dnsconfig-2-nodes.json#g" docker-testnet/envs/.env.n2.org2 && \ - make build-image-local && \ make deploy COMPOSE_ARG='--env-file docker-testnet/envs/.env.n1.org1' DLT_SPECIFIC_DIR=$(WORKSPACE)/weaver/tests/network-setups/fabric/shared/network1/peerOrganizations/org1.network1.com && \ make deploy COMPOSE_ARG='--env-file docker-testnet/envs/.env.n1.org2' DLT_SPECIFIC_DIR=$(WORKSPACE)/weaver/tests/network-setups/fabric/shared/network1/peerOrganizations/org2.network1.com && \ make deploy COMPOSE_ARG='--env-file docker-testnet/envs/.env.n2.org1' DLT_SPECIFIC_DIR=$(WORKSPACE)/weaver/tests/network-setups/fabric/shared/network2/peerOrganizations/org1.network2.com && \ make deploy COMPOSE_ARG='--env-file docker-testnet/envs/.env.n2.org2' DLT_SPECIFIC_DIR=$(WORKSPACE)/weaver/tests/network-setups/fabric/shared/network2/peerOrganizations/org2.network2.com +# CLI -------------------------------------------------------------------------------------- -.fabric-config: +fabric-cli: cd $(WORKSPACE)/weaver/samples/fabric/fabric-cli && \ ./bin/fabric-cli env set MEMBER_CREDENTIAL_FOLDER $(WORKSPACE)/weaver/samples/fabric/fabric-cli/src/data/credentials_docker && \ ./bin/fabric-cli env set CONFIG_PATH $(WORKSPACE)/weaver/samples/fabric/fabric-cli/config.json && \ @@ -77,34 +94,22 @@ iin: docker logs iin-agent-Org1MSP-network1 && \ docker logs iin-agent-Org1MSP-network2 + +# MAIN TARGETS + PATH := $(PATH):$(WORKSPACE)/protoc/bin -setup: +# SETUP - run once + +setup: cd $(WORKSPACE)/weaver/common/protos-js && make build - cd $(WORKSPACE)/weaver/core/network/fabric-interop-cc && make build rm -Rf $(WORKSPACE)/weaver/sdks/fabric/interoperation-node-sdk/build cd $(WORKSPACE)/weaver/sdks/fabric/interoperation-node-sdk && make build-local - cd $(WORKSPACE)/weaver/core/identity-management/iin-agent && make build-local - cd $(WORKSPACE)/weaver/samples/fabric/fabric-cli && npm install --global yarn && make build-local - -.test-network: .fabric-network relays drivers iin .fabric-config - -pledge-network: .test-network - -lock-network: .test-network - -define stop_docker -echo "removing $(1)" -docker stop `docker container ls -a -q -f ancestor=$(1) | xargs` || true -docker rm `docker container ls -a -q -f ancestor=$(1) | xargs` || true -endef - -clean-network: - $(foreach image,$(DOCKER_IMAGES),$(call stop_docker,$(image))) - docker volume prune -f - docker volume rm network2_peer0.org2.network2.com || true - docker volume rm network1_peer0.org2.network1.com || true - if [ "$(shell id -un )" != "root" ]; then \ - sudo chown -R $(shell id -un ) $(WORKSPACE)/weaver/tests/network-setups/fabric/shared; \ - fi - cd $(WORKSPACE)/weaver/tests/network-setups/fabric/dev && make clean + cd $(WORKSPACE)/weaver/core/identity-management/iin-agent && make build-local build-image-local + cd $(WORKSPACE)/weaver/samples/fabric/fabric-cli && make build-local + + +pledge-network: fabric-dl fabric1-driver fabric2-driver common-relay-config fabric1-relay fabric2-relay iin fabric-cli + +lock-network: fabric-dl iin fabric-cli + diff --git a/packages/cacti-copm-test/README.md b/packages/cacti-copm-test/README.md new file mode 100644 index 0000000000..ee91d9d58a --- /dev/null +++ b/packages/cacti-copm-test/README.md @@ -0,0 +1,38 @@ +# @hyperledger-cacti/cacti-copm-test + +Test framework for testing the COPM distributed ledger-specific plugins. + +## Development + +To add testing for a new distributed ledger, implement the interfaces defined in src/main/typescript/interfaces + + - TestAssets: + - provides methods for + - issueing bonds and tokens + - checking the owner of a bond + - checking the token balance + - CopmTester: + - manages instantiating the ledger-specific plugin + - defines the parties in a test network (partyA and partyB) + - for a party in a network: + - returns the test-assets implementation + - returns the gprc client + +The CopmTester for a new network type should be returned by the copm-tester-factory function. + +## Test Components and Networks + +The Makefile in this directory provides targets for building test network components. Some setup is shared between networks. + +Makefile_\ will build a docker weaver network of the given network type with the following commands: + +- make setup + - build all weaver components +- make pledge-network + - makes a network for running pledge/claim (asset transfer) +- make lock-network + - makes a network for running lock/claim (asset exchange) + +The asset exchanges and asset transfer network modes are currently mutually exclusive. + + diff --git a/packages/cacti-copm-test/package.json b/packages/cacti-copm-test/package.json new file mode 100644 index 0000000000..e2d9079883 --- /dev/null +++ b/packages/cacti-copm-test/package.json @@ -0,0 +1,74 @@ +{ + "name": "@hyperledger-cacti/cacti-copm-test", + "version": "2.0.0", + "description": "COPM testing.", + "keywords": [ + "Hyperledger", + "Cacti", + "Integration", + "Blockchain", + "Distributed Ledger Technology" + ], + "homepage": "https://github.com/hyperledger-cacti/cactus#readme", + "bugs": { + "url": "https://github.com/hyperledger-cacti/cactus/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/hyperledger-cacti/cactus.git" + }, + "license": "Apache-2.0", + "author": { + "name": "Hyperledger Cacti Contributors", + "email": "cactus@lists.hyperledger.org", + "url": "https://www.lfdecentralizedtrust.org/projects/cacti" + }, + "contributors": [ + { + "name": "Jennifer Bell", + "email": "jenniferlianne@gmail.com" + } + ], + "main": "dist/lib/main/typescript/index.js", + "module": "dist/lib/main/typescript/index.js", + "types": "dist/lib/main/typescript/index.d.ts", + "files": [ + "dist/*" + ], + "scripts": { + "test": "yarn run --top-level test:jest:all ./src/test/typescript/*/*.test.ts", + "test:lock": "yarn run --top-level test:jest:all ./src/test/typescript/integration/test-copm-lock-claim.test.ts", + "test:pledge": "yarn run --top-level test:jest:all ./src/test/typescript/integration/test-copm-pledge-claim.test.ts", + "test:view": "yarn run --top-level test:jest:all ./src/test/typescript/integration/test-copm-getverifiedview.test.ts" + }, + "dependencies": { + "@connectrpc/connect": "1.4.0", + "@connectrpc/connect-node": "1.4.0", + "@hyperledger-cacti/cacti-copm-core": "2.0.0", + "@hyperledger-cacti/cacti-plugin-copm-corda": "2.0.0", + "@hyperledger-cacti/cacti-plugin-copm-fabric": "2.0.0", + "@hyperledger/cacti-weaver-protos-js": "2.0.0", + "@hyperledger/cacti-weaver-sdk-fabric": "2.0.0", + "@hyperledger/cactus-cmd-api-server": "2.0.0", + "@hyperledger/cactus-common": "2.0.0", + "@hyperledger/cactus-core": "2.0.0", + "@hyperledger/cactus-core-api": "2.0.0", + "@hyperledger/cactus-plugin-ledger-connector-corda": "2.0.0", + "@hyperledger/cactus-test-tooling": "2.0.0", + "@types/dockerode": "3.2.7", + "dockerode": "3.3.0", + "fabric-ca-client": "2.2.20", + "fabric-common": "2.2.20", + "fabric-network": "2.2.20", + "fs-extra": "11.2.0", + "uuid": "10.0.0" + }, + "engines": { + "node": ">=18", + "npm": ">=8" + }, + "publishConfig": { + "access": "public" + }, + "watch": {} +} diff --git a/packages/cacti-copm-test/src/main/typescript/corda/copm-corda-container.ts b/packages/cacti-copm-test/src/main/typescript/corda/copm-corda-container.ts new file mode 100644 index 0000000000..bd01961a57 --- /dev/null +++ b/packages/cacti-copm-test/src/main/typescript/corda/copm-corda-container.ts @@ -0,0 +1,195 @@ +import { EventEmitter } from "events"; +import Docker, { Container, ContainerInfo } from "dockerode"; + +import { + LogLevelDesc, + Logger, + LoggerProvider, + Checks, +} from "@hyperledger/cactus-common"; + +/* + * Provides default options for Corda connector server + */ +const DEFAULTS = Object.freeze({ + imageVersion: "latest", + imageName: "copm-corda", + apiPort: 9199, + envVars: [], +}); +export const COPM_CORDA_CONTAINER_DEFAULT_OPTIONS = DEFAULTS; + +/* + * Contains options for COPM Corda container + */ + +export interface ICopmCordaContainerOptions { + imageVersion?: string; + imageName?: string; + apiPort?: number; + logLevel?: LogLevelDesc; + rpcConfigJson: string; + relayConfigJson: string; + remoteNetworkConfigJson: string; + envVars?: string[]; +} + +/** + * Class responsible for programmatically managing a container that is running + * the image made for hosting a the Corda COPM implementation, written in + * Kotlin + **/ +export class CopmCordaContainer { + public static readonly CLASS_NAME = "CopmCordaContainer"; + + private readonly log: Logger; + private readonly envVars: string[]; + public readonly imageVersion: string; + public readonly imageName: string; + public readonly apiPort: number; + private container: Container | undefined; + private containerId: string | undefined; + + public get className(): string { + return CopmCordaContainer.CLASS_NAME; + } + + constructor(public readonly opts: ICopmCordaContainerOptions) { + const fnTag = `${this.className}#constructor()`; + Checks.truthy(opts, `${fnTag} arg options`); + + this.imageVersion = opts.imageVersion || DEFAULTS.imageVersion; + this.imageName = opts.imageName || DEFAULTS.imageName; + + this.apiPort = opts.apiPort || DEFAULTS.apiPort; + this.envVars = opts.envVars ? opts.envVars : DEFAULTS.envVars; + + const springAppConfig = { + logging: { + level: { + root: "INFO", + "com.copmCorda": "DEBUG", + }, + }, + }; + this.envVars.push( + `SPRING_APPLICATION_JSON=${JSON.stringify(springAppConfig)}`, + ); + + this.envVars.push(`COPM_RELAY_CONFIG=${opts.relayConfigJson}`); + this.envVars.push(`COPM_REMOTE_CONFIG=${opts.remoteNetworkConfigJson}`); + this.envVars.push(`COPM_CORDA_RPC=${opts.rpcConfigJson}`); + + Checks.truthy(Array.isArray(this.envVars), `${fnTag}:envVars not an array`); + + const level = this.opts.logLevel || "INFO"; + const label = this.className; + this.log = LoggerProvider.getOrCreate({ level, label }); + } + + public getContainerId(): string { + const fnTag = `${this.className}.getContainerId()`; + Checks.nonBlankString(this.containerId, `${fnTag}::containerId`); + return this.containerId as string; + } + + public async start(): Promise { + const imageFqn = this.getContainerImageName(); + + if (this.container) { + await this.container.stop(); + await this.container.remove(); + } + const docker = new Docker(); + this.log.info(`Starting container from image: ${imageFqn}`); + return new Promise((resolve, reject) => { + const eventEmitter: EventEmitter = docker.run( + imageFqn, + [], + [], + { + ExposedPorts: { + [`9090/tcp`]: {}, + }, + Healthcheck: { + Test: [ + "CMD-SHELL", + // a way to use curl to test if grpc svr is up -- will return an error with http + `curl -vv -i -X POST http://127.0.0.1:${this.apiPort}/ 2>&1 | grep "when not allowed"`, + ], + Interval: 5000000000, // 5 seconds + Timeout: 3000000000, // 3 seconds + Retries: 50, + StartPeriod: 1000000000, // 5 second + }, + Env: this.envVars, + HostConfig: { + PortBindings: { + "9090/tcp": [{ HostPort: this.apiPort.toString() }], + }, + }, + }, + {}, + (err: unknown) => { + if (err) { + reject(err); + } + }, + ); + + eventEmitter.once("start", async (container: Container) => { + this.container = container; + this.containerId = container.id; + try { + resolve(container); + } catch (ex) { + this.log.error(`Waiting for healthcheck to pass failed:`, ex); + reject(ex); + } + }); + }); + } + + public stop(): Promise { + return this.getContainer().stop(); + } + + public destroy(): Promise { + const fnTag = `${this.className}.destroy()`; + if (this.container) { + return this.container.remove(); + } else { + return Promise.reject( + new Error(`${fnTag} Container was never created, nothing to destroy.`), + ); + } + } + + protected async getContainerInfo(): Promise { + const fnTag = `${this.className}.getContainerInfo()`; + const docker = new Docker(); + const containerInfos = await docker.listContainers({}); + const id = this.getContainerId(); + + const aContainerInfo = containerInfos.find((ci) => ci.Id === id); + + if (aContainerInfo) { + return aContainerInfo; + } else { + throw new Error(`${fnTag} no container with ID "${id}"`); + } + } + + public getContainer(): Container { + const fnTag = `${this.className}.getContainer()`; + if (!this.container) { + throw new Error(`${fnTag} container not set on this instance yet.`); + } else { + return this.container; + } + } + + public getContainerImageName(): string { + return `${this.imageName}:${this.imageVersion}`; + } +} diff --git a/packages/cacti-copm-test/src/main/typescript/corda/copm-tester-corda.ts b/packages/cacti-copm-test/src/main/typescript/corda/copm-tester-corda.ts new file mode 100644 index 0000000000..e71a3696d3 --- /dev/null +++ b/packages/cacti-copm-test/src/main/typescript/corda/copm-tester-corda.ts @@ -0,0 +1,230 @@ +import { + DLAccount, + CopmContractNames, + DefaultService, +} from "@hyperledger-cacti/cacti-copm-core"; +import { LogLevelDesc, Logger } from "@hyperledger/cactus-common"; +import * as fs from "fs"; +import * as path from "path"; +import { createPromiseClient, PromiseClient } from "@connectrpc/connect"; +import { createConnectTransport } from "@connectrpc/connect-node"; + +import { CopmTester } from "../interfaces/copm-tester"; +import { TestAssets } from "../interfaces/test-assets"; +import { CopmNetworkMode } from "../lib/types"; +import { TestAssetsCordaCli } from "./test-assets-corda-cli"; +import { PluginRegistry } from "@hyperledger/cactus-core"; +import { ConfigService } from "@hyperledger/cactus-cmd-api-server"; +import { AuthorizationProtocol } from "@hyperledger/cactus-cmd-api-server"; +import { v4 as uuidV4 } from "uuid"; +import { PluginCopmCorda } from "@hyperledger-cacti/cacti-plugin-copm-corda"; +import { AddressInfo } from "node:net"; +import { Servers } from "@hyperledger/cactus-common"; +import http from "node:http"; +import { ApiServer } from "@hyperledger/cactus-cmd-api-server"; +import { CopmCordaContainer } from "./copm-corda-container"; +import { CordaRPCConfig } from "./corda-rpc-config"; + +export class CopmTesterCorda implements CopmTester { + logLevel: LogLevelDesc = "INFO"; + log: Logger; + contractNames: CopmContractNames; + private weaverRelativePath = "../../../../../../weaver/"; + private packageRelativePath = "../../../../"; + private networkMode: CopmNetworkMode; + private testAssetMap = new Map(); + private httpServer: http.Server | null; + private apiServer: ApiServer | null; + private serverAddress: string; + private copmCordaContainer: CopmCordaContainer; + + constructor(log: Logger, networkMode: CopmNetworkMode) { + this.log = log; + this.networkMode = networkMode; + this.apiServer = null; + this.httpServer = null; + this.serverAddress = ""; + this.contractNames = { + pledgeContract: "org.hyperledger.cacti.weaver.imodule.corda.flows", + lockContract: "org.hyperledger.cacti.weaver.imodule.corda.flows", + }; + this.copmCordaContainer = new CopmCordaContainer({ + logLevel: this.logLevel, + rpcConfigJson: this.getRPCConfig(), + relayConfigJson: this.getRelayConfig(), + remoteNetworkConfigJson: this.getRemoteNetworkConfig(), + }); + } + + public async assetsFor(account: DLAccount): Promise { + const accountKey = account.userId + "@" + account.organization; + if (!this.testAssetMap.has(accountKey)) { + this.testAssetMap.set(accountKey, await this.createTestAssets(account)); + } + const assets = this.testAssetMap.get(accountKey); + if (!assets) { + throw Error(`no assets found for account ${accountKey}`); + } + return assets; + } + + private async createTestAssets( + account: DLAccount, + ): Promise { + return new TestAssetsCordaCli(account, this.log); + } + + public networkNames(): string[] { + return ["Corda_Network", "Corda_Network2"]; + } + + async startServer() { + if (this.apiServer) { + return; + } + this.log.info("corda tester startServer - starting copmCordaContainer"); + await this.copmCordaContainer.start(); + this.log.info("corda tester startServer - started copmCordaContainer"); + + this.httpServer = await Servers.startOnPreferredPort(4050); + const addressInfoHttp = this.httpServer.address() as AddressInfo; + this.serverAddress = `http://${addressInfoHttp.address}:${addressInfoHttp.port}`; + this.log.debug("HTTP API host: %s", this.serverAddress); + + const pluginRegistry = new PluginRegistry({ plugins: [] }); + + const cfgSrv = new ConfigService(); + const apiSrvOpts = await cfgSrv.newExampleConfig(); + apiSrvOpts.authorizationProtocol = AuthorizationProtocol.NONE; + apiSrvOpts.logLevel = this.logLevel; + apiSrvOpts.configFile = ""; + apiSrvOpts.apiCorsDomainCsv = "*"; + apiSrvOpts.apiPort = addressInfoHttp.port; + apiSrvOpts.cockpitPort = 0; + apiSrvOpts.grpcPort = 0; + apiSrvOpts.grpcMtlsEnabled = false; + apiSrvOpts.apiTlsEnabled = false; + apiSrvOpts.crpcPort = 0; + const cfg = await cfgSrv.newExampleConfigConvict(apiSrvOpts); + this.log.debug("creating corda plugin"); + const copmPlugin = new PluginCopmCorda({ + instanceId: uuidV4(), + logLevel: this.logLevel, + copmKotlinServerBaseUrl: `http://127.0.0.1:${this.copmCordaContainer.apiPort}`, + }); + + pluginRegistry.add(copmPlugin); + + this.apiServer = new ApiServer({ + httpServerApi: this.httpServer, + config: cfg.getProperties(), + pluginRegistry, + }); + + this.log.info("typescript api wrapper - starting"); + await this.apiServer.start(); + this.log.info("typescript api wrapper - started"); + } + + async stopServer() { + if (this.apiServer) { + await this.apiServer.shutdown(); + } + if (this.httpServer) { + await this.httpServer.close(); + } + await this.copmCordaContainer.stop(); + } + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public getPartyA(_assetType: string): DLAccount { + return { + organization: "Corda_Network", + userId: "O=PartyA, L=London, C=GB", + }; + } + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public getPartyB(_assetType: string): DLAccount { + switch (this.networkMode) { + case CopmNetworkMode.Pledge: + return { + organization: "Corda_Network2", + userId: "O=PartyA, L=London, C=GB", + }; + case CopmNetworkMode.Lock: + return { + organization: "Corda_Network", + userId: "O=PartyB, L=London, C=GB", + }; + default: + throw Error("network mode not implemented"); + } + } + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public clientFor(account: DLAccount): PromiseClient { + const transport = createConnectTransport({ + baseUrl: this.serverAddress, + httpVersion: "1.1", + }); + return createPromiseClient(DefaultService, transport); + } + + public getVerifiedViewExpectedResult(): string { + return "UniqueIdentifier"; + } + + public async getVerifyViewCmd( + pledgeId: string, + src_crt: string, + dest_cert: string, + organization: string, + ): Promise<{ + contractId: string; + function: string; + input: string[]; + }> { + return { + contractId: "com.cordaSimpleApplication.flow", + function: "GetAssetPledgeStatusByPledgeId", + input: [pledgeId, organization], + }; + } + + public getCertificateString(account: DLAccount): Promise { + const certsFile = path.join( + __dirname, + this.weaverRelativePath, + `samples/corda/corda-simple-application/clients/src/main/resources/config/remoteNetworkUsers/${account.organization}_UsersAndCerts.json`, + ); + const configJSON = JSON.parse(fs.readFileSync(certsFile).toString()); + if (!configJSON[account.userId]) { + throw Error(`${account.userId} not found in json at ${certsFile}`); + } + return configJSON[account.userId]; + } + + private getRelayConfig(): string { + const relayConfigPath = path.resolve( + __dirname, + this.packageRelativePath, + "src/test/json/resources/corda-relay-config.json", + ); + const relayConfigContent = fs.readFileSync(relayConfigPath, "utf-8"); + return relayConfigContent.replace(/127.0.0.1/g, "172.17.0.1"); + } + + private getRPCConfig(): string { + return CordaRPCConfig.rpcJSON().replace(/127.0.0.1/g, "172.17.0.1"); + } + + private getRemoteNetworkConfig(): string { + const configPath = path.resolve( + __dirname, + this.weaverRelativePath, + "samples/corda/corda-simple-application/clients/src/main/resources/config/remote-network-config.json", + ); + return fs.readFileSync(configPath, "utf-8"); + } +} diff --git a/packages/cacti-copm-test/src/main/typescript/corda/corda-rpc-config.ts b/packages/cacti-copm-test/src/main/typescript/corda/corda-rpc-config.ts new file mode 100644 index 0000000000..5f9904c813 --- /dev/null +++ b/packages/cacti-copm-test/src/main/typescript/corda/corda-rpc-config.ts @@ -0,0 +1,28 @@ +import { DLAccount } from "@hyperledger-cacti/cacti-copm-core"; +import * as fs from "fs"; +import * as path from "path"; + +export class CordaRPCConfig { + private static readonly cordaRpcFile = path.join( + __dirname, + "../../../../src/test/json/resources/corda_rpc.json", + ); + + public static rpcJSON(): string { + return fs.readFileSync(this.cordaRpcFile).toString(); + } + + public static getRPCData(account: DLAccount): { + host: string; + port: number; + username: string; + password: string; + } { + const accountKey = account.userId + "@" + account.organization; + const config = JSON.parse(this.rpcJSON()); + if (!config[accountKey]) { + throw Error(`account ${accountKey} not found in ${this.cordaRpcFile}`); + } + return config[accountKey]; + } +} diff --git a/packages/cacti-copm-test/src/main/typescript/corda/test-assets-corda-cli.ts b/packages/cacti-copm-test/src/main/typescript/corda/test-assets-corda-cli.ts new file mode 100644 index 0000000000..b0e031a6d4 --- /dev/null +++ b/packages/cacti-copm-test/src/main/typescript/corda/test-assets-corda-cli.ts @@ -0,0 +1,90 @@ +import { DLAccount } from "@hyperledger-cacti/cacti-copm-core"; +import { TestAssets } from "../interfaces/test-assets"; +import { CordaRPCConfig } from "./corda-rpc-config"; +import { Logger } from "@hyperledger/cactus-common"; +import { exec } from "child_process"; + +const path = require("path"); + +export class TestAssetsCordaCli implements TestAssets { + account: DLAccount; + log: Logger; + private cli: string; + + constructor(owner: DLAccount, log: Logger) { + this.account = owner; + this.log = log; + this.cli = path.resolve( + path.dirname(__filename), + "../../../../../../weaver/samples/corda/corda-simple-application/clients/build/install/clients/bin/clients", + ); + this.log.info(this.cli); + } + + public async start() {} + + public async stop() {} + + public async userOwnsNonFungibleAsset( + assetType: string, + assetId: string, + ): Promise { + const port = this.getRPCPort(); + // CORDA_PORT=10006 ./clients/build/install/clients/bin/clients bond get-assets-by-type 'bond01'`) + const res = await this.runCliCommand( + `CORDA_PORT=${port} ${this.cli} bond get-assets-by-type ${assetType}`, + ); + this.log.info(`Response: ${res}`); + const matchStr = `id=${assetId}, owner=${this.account.userId}`; + return res.includes(matchStr); + } + + public async addToken(assetType: string, assetQuantity: number) { + const cmd = `NETWORK_NAME='${this.account.organization}' CORDA_PORT=${this.getRPCPort()} ${this.cli} issue-asset-state ${assetQuantity} ${assetType}`; + await this.runCliCommand(cmd); + } + + public async addNonFungibleAsset(assetType: string, assetId: string) { + const cmd = `NETWORK_NAME=${this.account.organization} CORDA_PORT=${this.getRPCPort()} ${this.cli} bond issue-asset '${assetId}' '${assetType}'`; + await this.runCliCommand(cmd); + } + + public async tokenBalance(tokenType: string): Promise { + const port = this.getRPCPort(); + const res = await this.runCliCommand( + `CORDA_PORT=${port} ${this.cli} get-asset-states-by-type ${tokenType}`, + ); + if (res.includes("[]")) { + return 0; + } + const assetStates = res.split("AssetState("); + let total = 0; + for (const assetState of assetStates) { + const matches = assetState.match(/quantity=(\d+)/); + if (matches) { + total += +matches[1]; + } + } + return total; + } + + private runCliCommand(command: string): Promise { + this.log.info(`Running command: ${command}`); + return new Promise((resolve, reject) => { + exec(command, (error, stdout, stderr) => { + if (error) { + reject(error); + } else { + this.log.info(`stderr: ${stderr}`); + this.log.info(`stdout: ${stdout}`); + resolve(stdout); + } + }); + }); + } + + private getRPCPort(): number { + const rpcData = CordaRPCConfig.getRPCData(this.account); + return rpcData.port; + } +} diff --git a/packages/cacti-copm-test/src/main/typescript/fabric/copm-tester-fabric.ts b/packages/cacti-copm-test/src/main/typescript/fabric/copm-tester-fabric.ts new file mode 100644 index 0000000000..85b9fb3e28 --- /dev/null +++ b/packages/cacti-copm-test/src/main/typescript/fabric/copm-tester-fabric.ts @@ -0,0 +1,233 @@ +import { Identity } from "fabric-network"; +import { ApiServer } from "@hyperledger/cactus-cmd-api-server"; +import { + DLAccount, + CopmContractNames, + DefaultService, +} from "@hyperledger-cacti/cacti-copm-core"; +import { LogLevelDesc, Logger } from "@hyperledger/cactus-common"; +import { TestAssets } from "../interfaces/test-assets"; +import { TestAssetsFabric } from "./test-assets-fabric"; +import { TestFabricConfiguration } from "./test-fabric-configuration"; +import { WeaverInteropConfiguration } from "../lib/weaver-interop-configuration"; +import { CopmTester } from "../interfaces/copm-tester"; +import { createPromiseClient, PromiseClient } from "@connectrpc/connect"; +import { createConnectTransport } from "@connectrpc/connect-node"; +import http from "node:http"; +import { PluginRegistry } from "@hyperledger/cactus-core"; +import { ConfigService } from "@hyperledger/cactus-cmd-api-server"; +import { AuthorizationProtocol } from "@hyperledger/cactus-cmd-api-server"; +import { v4 as uuidV4 } from "uuid"; +import { AddressInfo } from "node:net"; +import { Servers } from "@hyperledger/cactus-common"; +import { + PluginCopmFabric, + FabricTransactionContextFactory, +} from "@hyperledger-cacti/cacti-plugin-copm-fabric"; +import { CopmNetworkMode } from "../lib/types"; + +type FabricIdentity = Identity & { + credentials: { + certificate: string; + privateKey: string; + }; +}; + +export class CopmTesterFabric implements CopmTester { + logLevel: LogLevelDesc = "INFO"; + log: Logger; + fabricConfig: TestFabricConfiguration; + interopConfig: WeaverInteropConfiguration; + contractNames: CopmContractNames; + + private assetContractName: string; + private networkAdminName: string; + private networkMode: CopmNetworkMode; + private serverAddress: string; + private httpServer: http.Server | null; + private apiServer: ApiServer | null; + + constructor(log: Logger, mode: CopmNetworkMode) { + this.log = log; + this.networkAdminName = "networkadmin"; + this.fabricConfig = new TestFabricConfiguration(log); + this.interopConfig = new WeaverInteropConfiguration("interop", this.log); + this.contractNames = { + pledgeContract: "simpleassettransfer", + lockContract: "simpleasset", + }; + this.networkMode = mode; + this.assetContractName = + mode == CopmNetworkMode.Lock ? "simpleasset" : "simpleassettransfer"; + this.serverAddress = ""; + this.httpServer = null; + this.apiServer = null; + } + + public async assetsFor(account: DLAccount): Promise { + // eslint-disable-next-line @typescript-eslint/no-this-alias + const testnet = this; + + return new TestAssetsFabric( + account, + this.assetContractName, + this.networkAdminName, + new FabricTransactionContextFactory( + this.fabricConfig, + this.interopConfig, + this.log, + ), + async function (account: DLAccount): Promise { + return await testnet.getCertificateString(account); + }, + this.log, + ); + } + + public async startServer() { + if (this.apiServer) { + return; + } + this.log.info("fabric startServer"); + this.httpServer = await Servers.startOnPreferredPort(4050); + const addressInfoHttp = this.httpServer.address() as AddressInfo; + this.serverAddress = `http://${addressInfoHttp.address}:${addressInfoHttp.port}`; + this.log.debug("HTTP API host: %s", this.serverAddress); + + const pluginRegistry = new PluginRegistry({ plugins: [] }); + + const cfgSrv = new ConfigService(); + const apiSrvOpts = await cfgSrv.newExampleConfig(); + apiSrvOpts.authorizationProtocol = AuthorizationProtocol.NONE; + apiSrvOpts.logLevel = this.logLevel; + apiSrvOpts.configFile = ""; + apiSrvOpts.apiCorsDomainCsv = "*"; + apiSrvOpts.apiPort = addressInfoHttp.port; + apiSrvOpts.cockpitPort = 0; + apiSrvOpts.grpcPort = 0; + apiSrvOpts.grpcMtlsEnabled = false; + apiSrvOpts.apiTlsEnabled = false; + apiSrvOpts.crpcPort = 0; + const cfg = await cfgSrv.newExampleConfigConvict(apiSrvOpts); + const compFabricPlugin = new PluginCopmFabric({ + instanceId: uuidV4(), + logLevel: this.logLevel, + fabricConfig: this.fabricConfig, + interopConfig: this.interopConfig, + contractNames: this.contractNames, + }); + + pluginRegistry.add(compFabricPlugin); + + this.apiServer = new ApiServer({ + httpServerApi: this.httpServer, + config: cfg.getProperties(), + pluginRegistry, + }); + + this.log.info("api server - starting"); + const { addressInfoGrpc, addressInfoCrpc } = await this.apiServer.start(); + this.log.info("api server - started"); + const grpcPort = addressInfoGrpc.port; + const grpcHost = addressInfoGrpc.address; + const grpcFamily = addressInfoHttp.family; + this.log.info( + "gRPC family=%s host=%s port=%s", + grpcFamily, + grpcHost, + grpcPort, + ); + this.log.info("CRPC AddressInfo=%o", addressInfoCrpc); + } + + public async stopServer() { + if (this.apiServer) { + await this.apiServer.shutdown(); + } + if (this.httpServer) { + await this.httpServer.close(); + } + } + + public getPartyA(assetType: string): DLAccount { + const usernames = this.userNames(); + const networks = this.networkNames(); + + if (this.networkMode == CopmNetworkMode.Pledge) { + return { organization: networks[0], userId: usernames[0] }; + } else { + if (assetType.startsWith("bond")) { + // bonds are on network 0, tokens on network 1 + return { organization: networks[0], userId: usernames[0] }; + } else { + return { organization: networks[1], userId: usernames[0] }; + } + } + } + + public getPartyB(assetType: string): DLAccount { + const usernames = this.userNames(); + const networks = this.networkNames(); + + if (this.networkMode == CopmNetworkMode.Pledge) { + return { organization: networks[1], userId: usernames[1] }; + } else { + if (assetType.startsWith("bond")) { + // bonds are on network 0, tokens on network 1 + return { organization: networks[0], userId: usernames[1] }; + } else { + return { organization: networks[1], userId: usernames[1] }; + } + } + } + + getVerifiedViewExpectedResult(): string { + return "replace"; + } + + async getVerifyViewCmd( + pledgeId: string, + src_crt: string, + dest_cert: string, + organization: string, + ): Promise<{ + contractId: string; + function: string; + input: string[]; + }> { + return { + contractId: "simpleassettransfer", + function: "GetAssetPledgeStatus", + input: [pledgeId, src_crt, organization, dest_cert], + }; + } + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public clientFor(account: DLAccount): PromiseClient { + const transport = createConnectTransport({ + baseUrl: this.serverAddress, + httpVersion: "1.1", + }); + return createPromiseClient(DefaultService, transport); + } + + public networkNames(): string[] { + return ["network1", "network2"]; + } + + public userNames(): string[] { + return ["alice", "bob"]; + } + + public async getCertificateString(account: DLAccount): Promise { + const wallet = await this.fabricConfig.getOrgWallet(account.organization); + const identity = (await wallet.get(account.userId)) as FabricIdentity; + if (!identity?.credentials?.certificate) { + throw new Error(`no credentials for user ${account.userId}`); + } + const userCert = Buffer.from(identity.credentials.certificate).toString( + "base64", + ); + return userCert; + } +} diff --git a/packages/cacti-plugin-copm-fabric/src/test/typescript/lib/test-asset-manager.ts b/packages/cacti-copm-test/src/main/typescript/fabric/test-assets-fabric.ts similarity index 58% rename from packages/cacti-plugin-copm-fabric/src/test/typescript/lib/test-asset-manager.ts rename to packages/cacti-copm-test/src/main/typescript/fabric/test-assets-fabric.ts index a3cce667aa..526eeaa31f 100644 --- a/packages/cacti-plugin-copm-fabric/src/test/typescript/lib/test-asset-manager.ts +++ b/packages/cacti-copm-test/src/main/typescript/fabric/test-assets-fabric.ts @@ -2,20 +2,23 @@ import { Interfaces as CopmIF, DLAccount, } from "@hyperledger-cacti/cacti-copm-core"; +import { TestAssets } from "../interfaces/test-assets"; import { Logger } from "@hyperledger/cactus-common"; export interface CertificateFactoryFunc { (account: DLAccount): Promise; } -export class TestAssetManager { +export class TestAssetsFabric implements TestAssets { contractName: string; networkAdminName: string; log: Logger; + owner: DLAccount; contextFactory: CopmIF.DLTransactionContextFactory; certificateFactory: CertificateFactoryFunc; constructor( + account: DLAccount, contractName: string, networkAdminName: string, contextFactory: CopmIF.DLTransactionContextFactory, @@ -27,14 +30,16 @@ export class TestAssetManager { this.contractName = contractName; this.networkAdminName = networkAdminName; this.log = log; + this.owner = account; } public async userOwnsNonFungibleAsset( assetType: string, assetId: string, - account: DLAccount, ): Promise { - const netContext = await this.contextFactory.getTransactionContext(account); + const netContext = await this.contextFactory.getTransactionContext( + this.owner, + ); try { const readResult = await netContext.invoke({ @@ -47,18 +52,19 @@ export class TestAssetManager { if (ex.message.includes("does not exist")) { return false; } + if (ex.message.includes(`cannot access Bond Asset ${assetId}`)) { + return false; + } // unexpected error case throw ex; } return false; } - public async addToken( - assetType: string, - assetQuantity: number, - owner: DLAccount, - ) { - const transaction = await this.contextFactory.getTransactionContext(owner); + public async addToken(assetType: string, assetQuantity: number) { + const transaction = await this.contextFactory.getTransactionContext( + this.owner, + ); await transaction.invoke({ contract: this.contractName, @@ -66,27 +72,24 @@ export class TestAssetManager { args: [ assetType, assetQuantity.toString(), - await this.certificateFactory(owner), + await this.certificateFactory(this.owner), ], }); } - public async addNonFungibleAsset( - assetType: string, - assetId: string, - account: DLAccount, - ) { + public async addNonFungibleAsset(assetType: string, assetId: string) { const item = { assetType: assetType, id: assetId, - owner: account.userId, + owner: this.owner.userId, issuer: "treasury", facevalue: "500", maturitydate: "01 Jan 45 00:00 MST", }; - const transaction = - await this.contextFactory.getTransactionContext(account); - const userCert = await this.certificateFactory(account); + const transaction = await this.contextFactory.getTransactionContext( + this.owner, + ); + const userCert = await this.certificateFactory(this.owner); await transaction.invoke({ contract: this.contractName, @@ -102,21 +105,32 @@ export class TestAssetManager { }); } - public async tokenBalance( - tokenType: string, - account: DLAccount, - ): Promise { - const transaction = - await this.contextFactory.getTransactionContext(account); + public async tokenBalance(tokenType: string): Promise { + const transaction = await this.contextFactory.getTransactionContext( + this.owner, + ); - const walletBalance = await transaction.invoke({ - contract: this.contractName, - method: "GetMyWallet", - args: [], - }); + try { + const walletBalance = await transaction.invoke({ + contract: this.contractName, + method: "GetMyWallet", + args: [], + }); - this.log.info(walletBalance); - const walletParts = walletBalance.split("="); - return +walletParts[1]; + for (const asset of walletBalance.split(",")) { + if (asset.includes(tokenType)) { + const matches = walletBalance.match(/="(\d+)"/); + if (matches) { + return +matches[1]; + } + } + } + throw new Error(`Could not find ${tokenType} in ${walletBalance}`); + } catch (ex) { + if (ex.message.includes("does not have a wallet")) { + return 0; + } + throw ex; + } } } diff --git a/packages/cacti-plugin-copm-fabric/src/test/typescript/lib/test-fabric-configuration.ts b/packages/cacti-copm-test/src/main/typescript/fabric/test-fabric-configuration.ts similarity index 93% rename from packages/cacti-plugin-copm-fabric/src/test/typescript/lib/test-fabric-configuration.ts rename to packages/cacti-copm-test/src/main/typescript/fabric/test-fabric-configuration.ts index eea7dc5ff7..1ce83c0da2 100644 --- a/packages/cacti-plugin-copm-fabric/src/test/typescript/lib/test-fabric-configuration.ts +++ b/packages/cacti-copm-test/src/main/typescript/fabric/test-fabric-configuration.ts @@ -1,5 +1,7 @@ -import { FabricConfiguration } from "../../../main/typescript/lib/fabric-configuration"; -import { FabricContractContext } from "../../../main/typescript/lib/fabric-types"; +import { + FabricConfiguration, + FabricContractContext, +} from "@hyperledger-cacti/cacti-plugin-copm-fabric"; import { Wallet, DiscoveryOptions, Wallets } from "fabric-network"; import { Logger } from "@hyperledger/cactus-common"; import path from "path"; diff --git a/packages/cacti-copm-test/src/main/typescript/index.ts b/packages/cacti-copm-test/src/main/typescript/index.ts new file mode 100755 index 0000000000..0d16081168 --- /dev/null +++ b/packages/cacti-copm-test/src/main/typescript/index.ts @@ -0,0 +1,3 @@ +export { WeaverInteropConfiguration } from "./lib/weaver-interop-configuration"; +export { TestAssets } from "./interfaces/test-assets"; +export { CopmTester } from "./interfaces/copm-tester"; diff --git a/packages/cacti-copm-test/src/main/typescript/interfaces/copm-tester.ts b/packages/cacti-copm-test/src/main/typescript/interfaces/copm-tester.ts new file mode 100644 index 0000000000..fd751816d3 --- /dev/null +++ b/packages/cacti-copm-test/src/main/typescript/interfaces/copm-tester.ts @@ -0,0 +1,34 @@ +import { PromiseClient } from "@connectrpc/connect"; +import { DefaultService, DLAccount } from "@hyperledger-cacti/cacti-copm-core"; +import { TestAssets } from "./test-assets"; + +// Supplies the data needed to test COPM plugins on different networks +export interface CopmTester { + networkNames(): string[]; + + startServer(); + stopServer(); + + // on the fabric test networks, user roles differ by asset type + getPartyA(assetType: string): DLAccount; + getPartyB(assetType: string): DLAccount; + + clientFor(account: DLAccount): PromiseClient; + assetsFor(account: DLAccount): Promise; + + getCertificateString(account: DLAccount): Promise; + + getVerifiedViewExpectedResult(): string; + + // remote commands differ by the type of remote network + getVerifyViewCmd( + pledgeId: string, + src_crt: string, + dest_cert: string, + organization: string, + ): Promise<{ + contractId: string; + function: string; + input: string[]; + }>; +} diff --git a/packages/cacti-copm-test/src/main/typescript/interfaces/test-assets.ts b/packages/cacti-copm-test/src/main/typescript/interfaces/test-assets.ts new file mode 100644 index 0000000000..0ae25cebe9 --- /dev/null +++ b/packages/cacti-copm-test/src/main/typescript/interfaces/test-assets.ts @@ -0,0 +1,12 @@ +export interface TestAssets { + addToken(assetType: string, assetQuantity: number): Promise; + + addNonFungibleAsset(assetType: string, assetId: string): Promise; + + tokenBalance(tokenType: string): Promise; + + userOwnsNonFungibleAsset( + assetType: string, + assetId: string, + ): Promise; +} diff --git a/packages/cacti-copm-test/src/main/typescript/lib/copm-tester-factory.ts b/packages/cacti-copm-test/src/main/typescript/lib/copm-tester-factory.ts new file mode 100644 index 0000000000..f6f9848195 --- /dev/null +++ b/packages/cacti-copm-test/src/main/typescript/lib/copm-tester-factory.ts @@ -0,0 +1,19 @@ +import { CopmTester } from "../interfaces/copm-tester"; +import { CopmTesterFabric } from "../fabric/copm-tester-fabric"; +import { CopmNetworkMode } from "../lib/types"; +import { Logger } from "@hyperledger/cactus-common"; +import { CopmTesterCorda } from "../corda/copm-tester-corda"; + +export function copmTesterFactory( + log: Logger, + netType: string, + networkMode: CopmNetworkMode, +): CopmTester { + if (netType === "fabric") { + return new CopmTesterFabric(log, networkMode); + } + if (netType == "corda") { + return new CopmTesterCorda(log, networkMode); + } + throw new Error("Unsupported network type: " + netType); +} diff --git a/packages/cacti-copm-test/src/main/typescript/lib/copm-tester-multi-network.ts b/packages/cacti-copm-test/src/main/typescript/lib/copm-tester-multi-network.ts new file mode 100644 index 0000000000..98a9ae4527 --- /dev/null +++ b/packages/cacti-copm-test/src/main/typescript/lib/copm-tester-multi-network.ts @@ -0,0 +1,135 @@ +import { PromiseClient } from "@connectrpc/connect"; +import { DLAccount, DefaultService } from "@hyperledger-cacti/cacti-copm-core"; +import { CopmTester } from "../interfaces/copm-tester"; +import { copmTesterFactory } from "./copm-tester-factory"; +import { TestAssets } from "../interfaces/test-assets"; +import { Logger } from "@hyperledger/cactus-common"; +import { CopmNetworkMode } from "./types"; + +export class CopmTestertMultiNetwork implements CopmTester { + net1: CopmTester | null; + net2: CopmTester | null; + log: Logger; + networkMode: CopmNetworkMode; + net1Type: string | null; + net2Type: string | null; + netMap: Map = new Map(); + + constructor(log: Logger, mode: CopmNetworkMode) { + this.networkMode = mode; + this.log = log; + this.net1 = null; + this.net2 = null; + this.net1Type = null; + this.net2Type = null; + } + + async setNetworks(net1Type: string, net2Type: string) { + this.net1Type = net1Type; + this.net2Type = net2Type; + this.net1 = await this.getTesterForNetworkType(net1Type); + this.net2 = await this.getTesterForNetworkType(net2Type); + } + + networkNames(): string[] { + return this.getNet1().networkNames(); + } + + async startServer() {} + + async stopServer() { + for (const net of this.netMap.values()) { + await net.stopServer(); + } + } + + getPartyA(assetType: string): DLAccount { + return this.getNet1().getPartyA(assetType); + } + + getPartyB(assetType: string): DLAccount { + if ( + this.net1Type != this.net2Type && + this.networkMode == CopmNetworkMode.Pledge + ) { + // for different network types, + // cross network perms have only been set up for + // the primary user on each network. + return this.getNet2().getPartyA(assetType); + } else { + return this.getNet2().getPartyB(assetType); + } + } + + async assetsFor(account: DLAccount): Promise { + return this.getNetworkFor(account).assetsFor(account); + } + + clientFor(account: DLAccount): PromiseClient { + return this.getNetworkFor(account).clientFor(account); + } + + async getCertificateString(account: DLAccount): Promise { + return await this.getNetworkFor(account).getCertificateString(account); + } + + getVerifiedViewExpectedResult(): string { + return this.getNet1().getVerifiedViewExpectedResult(); + } + + async getVerifyViewCmd( + pledgeId: string, + src_crt: string, + dest_cert: string, + organization: string, + ): Promise<{ + contractId: string; + function: string; + input: string[]; + }> { + return await this.getNet1().getVerifyViewCmd( + pledgeId, + src_crt, + dest_cert, + organization, + ); + } + + private getNetworkFor(account: DLAccount): CopmTester { + if (this.getNet1().networkNames().includes(account.organization)) { + return this.getNet1(); + } + if (this.getNet2().networkNames().includes(account.organization)) { + return this.getNet2(); + } + throw new Error("Unknown organization: " + account.organization); + } + + private async getTesterForNetworkType(netType: string): Promise { + if (!this.netMap.has(netType)) { + const tester = copmTesterFactory(this.log, netType, this.networkMode); + this.netMap.set(netType, tester); + await tester.startServer(); + } + + const tester = this.netMap.get(netType); + if (tester == null) { + throw new Error("Tester not found for " + netType); + } + return tester; + } + + private getNet1(): CopmTester { + if (this.net1 == null) { + throw new Error("Network 1 not set"); + } + return this.net1; + } + + private getNet2(): CopmTester { + if (this.net2 == null) { + throw new Error("Network 2 not set"); + } + return this.net2; + } +} diff --git a/packages/cacti-copm-test/src/main/typescript/lib/types.ts b/packages/cacti-copm-test/src/main/typescript/lib/types.ts new file mode 100644 index 0000000000..8c15dc3553 --- /dev/null +++ b/packages/cacti-copm-test/src/main/typescript/lib/types.ts @@ -0,0 +1,4 @@ +export enum CopmNetworkMode { + Lock = 1, + Pledge, +} diff --git a/packages/cacti-plugin-copm-fabric/src/test/typescript/lib/test-interop-configuration.ts b/packages/cacti-copm-test/src/main/typescript/lib/weaver-interop-configuration.ts similarity index 53% rename from packages/cacti-plugin-copm-fabric/src/test/typescript/lib/test-interop-configuration.ts rename to packages/cacti-copm-test/src/main/typescript/lib/weaver-interop-configuration.ts index 0cc788fe39..5e0bc129c1 100644 --- a/packages/cacti-plugin-copm-fabric/src/test/typescript/lib/test-interop-configuration.ts +++ b/packages/cacti-copm-test/src/main/typescript/lib/weaver-interop-configuration.ts @@ -3,11 +3,13 @@ import { LocalRelayConfig, RemoteNetworkConfig, Interfaces as CopmIF, + DLTransactionParams, + Validators, } from "@hyperledger-cacti/cacti-copm-core"; import path from "path"; import fs from "fs-extra"; -export class TestInteropConfiguration implements CopmIF.InteropConfiguration { +export class WeaverInteropConfiguration implements CopmIF.InteropConfiguration { private log: Logger; private weaverRelativePath = "../../../../../../weaver/"; private weaverNetConfigPath = path.join( @@ -47,22 +49,66 @@ export class TestInteropConfiguration implements CopmIF.InteropConfiguration { ); } const netConfig = configJSON[orgName]; - if (!netConfig.channelName) { - throw Error(`no channel name defined for ${orgName}`); - } if (!netConfig.relayEndpoint) { throw Error(`no relay endpoint defined for ${orgName}`); } - return { - channelName: netConfig.channelName, - network: orgName, - relayAddr: netConfig.relayEndpoint, - e2eConfidentiality: false, - partyEndPoint: "", // corda-specific - flowPackage: "", // corda-specific - networkType: "fabric", - }; + if (netConfig.type === "fabric") { + if (!netConfig.channelName) { + throw Error(`no channel name defined for ${orgName}`); + } + return { + channelName: netConfig.channelName, + network: orgName, + relayAddr: netConfig.relayEndpoint, + e2eConfidentiality: false, + partyEndPoint: "", // corda-specific + networkType: netConfig.type, + }; + } else { + if (!netConfig.partyEndPoint) { + throw Error(`no partyEndpoint defined for ${orgName}`); + } + + return { + channelName: "", // fabric-specific + network: orgName, + relayAddr: netConfig.relayEndpoint, + e2eConfidentiality: false, + partyEndPoint: netConfig.partyEndPoint, + networkType: netConfig.type, + }; + } + } + + public getRemotePledgeStatusCmd( + remoteOrgKey: string, + claimRequest: Validators.ValidatedClaimPledgedAssetRequest, + ): DLTransactionParams { + const remoteNetConfig = this.getRemoteNetworkConfig(remoteOrgKey); + if (remoteNetConfig.networkType === "corda") { + return { + contract: + "com.cordaSimpleApplication.flow.GetBondAssetPledgeStatusByPledgeId", + method: claimRequest.asset.isNFT() + ? "GetBondAssetPledgeStatusByPledgeId" + : "GetAssetPledgeStatusByPledgeId", + args: [claimRequest.pledgeId, claimRequest.destAccount.organization], + }; + } else { + return { + contract: "simpleassettransfer", + method: claimRequest.asset.isNFT() + ? "GetAssetPledgeStatus" + : "GetTokenAssetPledgeStatus", + args: [ + claimRequest.pledgeId, + claimRequest.sourceCert, + claimRequest.destAccount.organization, + claimRequest.destCert, + ], + }; + } } private getWeaverNetworkConfig(networkId: string): { diff --git a/packages/cacti-copm-test/src/test/json/resources/corda-relay-config.json b/packages/cacti-copm-test/src/test/json/resources/corda-relay-config.json new file mode 100644 index 0000000000..d705529b90 --- /dev/null +++ b/packages/cacti-copm-test/src/test/json/resources/corda-relay-config.json @@ -0,0 +1,8 @@ +{ + "Corda_Network": { + "relayEndpoint": "127.0.0.1:9081" + }, + "Corda_Network2": { + "relayEndpoint": "127.0.0.1:9082" + } +} diff --git a/packages/cacti-copm-test/src/test/json/resources/corda_rpc.json b/packages/cacti-copm-test/src/test/json/resources/corda_rpc.json new file mode 100644 index 0000000000..8797957c20 --- /dev/null +++ b/packages/cacti-copm-test/src/test/json/resources/corda_rpc.json @@ -0,0 +1,26 @@ +{ + "O=PartyA, L=London, C=GB@Corda_Network": { + "host": "127.0.0.1", + "username": "clientUser1", + "password": "test", + "port": 10006 + }, + "O=PartyB, L=London, C=GB@Corda_Network": { + "host": "127.0.0.1", + "username": "clientUser1", + "password": "test", + "port": 10009 + }, + "O=PartyA, L=London, C=GB@Corda_Network2": { + "host": "127.0.0.1", + "username": "clientUser1", + "password": "test", + "port": 30006 + }, + "O=PartyB, L=London, C=GB@Corda_Network2": { + "host": "127.0.0.1", + "username": "clientUser1", + "password": "test", + "port": 30009 + } +} diff --git a/packages/cacti-copm-test/src/test/typescript/integration/test-copm-getverifiedview.test.ts b/packages/cacti-copm-test/src/test/typescript/integration/test-copm-getverifiedview.test.ts new file mode 100644 index 0000000000..597905d8ef --- /dev/null +++ b/packages/cacti-copm-test/src/test/typescript/integration/test-copm-getverifiedview.test.ts @@ -0,0 +1,110 @@ +import "jest-extended"; +import { + LogLevelDesc, + Logger, + LoggerProvider, +} from "@hyperledger/cactus-common"; +import { + PledgeAssetV1Request, + GetVerifiedViewV1Request, + DLAccount, +} from "@hyperledger-cacti/cacti-copm-core"; +import * as path from "path"; +import * as dotenv from "dotenv"; +import { CopmTestertMultiNetwork } from "../../../main/typescript/lib/copm-tester-multi-network"; +import { CopmNetworkMode } from "../../../main/typescript/lib/types"; +dotenv.config({ path: path.resolve(__dirname, "../../.env") }); + +const logLevel: LogLevelDesc = "DEBUG"; +const log: Logger = LoggerProvider.getOrCreate({ + label: "plugin-copm-crpc-server-test", + level: logLevel, +}); +let dest_cert: string; +const net1Type = process.env["COPM_NET_1"] || "fabric"; +const net2Type = process.env["COPM_NET_2"] || "fabric"; + +describe(`COPM get verified view ${net1Type}-${net2Type}`, () => { + let copmTester: CopmTestertMultiNetwork; + let partyA: DLAccount, partyB: DLAccount; + + beforeAll(async () => { + log.info("setting up fabric test network"); + + copmTester = new CopmTestertMultiNetwork(log, CopmNetworkMode.Pledge); + await copmTester.setNetworks(net1Type, net2Type); + await copmTester.startServer(); + + partyA = copmTester.getPartyA("bond"); + partyB = copmTester.getPartyB("bond"); + + dest_cert = await copmTester.getCertificateString(partyB); + + log.info("test setup complete"); + }); + + afterAll(async () => { + if (copmTester) { + await copmTester.stopServer(); + } + }); + + test(`${net1Type}-${net2Type} get verified view1`, async () => { + const assetType = "token1"; + const assetQuantity = 2; + await ( + await copmTester.assetsFor(partyA) + ).addToken(assetType, assetQuantity); + + log.info(`party a ${partyA.organization} ${partyA.userId}`); + log.info(`party b ${partyB.organization} ${partyB.userId}`); + + const pledgeResult = await copmTester.clientFor(partyA).pledgeAssetV1( + new PledgeAssetV1Request({ + assetPledgeV1PB: { + asset: { + assetType: assetType, + assetQuantity: assetQuantity, + }, + source: { + network: partyA.organization, + userId: partyA.userId, + }, + destination: { + network: partyB.organization, + userId: partyB.userId, + }, + expirySecs: BigInt(45), + destinationCertificate: dest_cert, + }, + }), + ); + + expect(pledgeResult).toBeTruthy(); + expect(pledgeResult.pledgeId).toBeString(); + const readPledge = await copmTester.getVerifyViewCmd( + pledgeResult.pledgeId, + await copmTester.getCertificateString(partyA), + dest_cert, + partyB.organization, + ); + const res = await copmTester.clientFor(partyB).getVerifiedViewV1( + new GetVerifiedViewV1Request({ + getVerifiedViewV1RequestPB: { + account: { + network: partyB.organization, + userId: partyB.userId, + }, + view: { + network: partyA.organization, + viewAddress: readPledge, + }, + }, + }), + ); + + expect(res).toBeTruthy(); + expect(res.data).toBeString(); + log.info(res.data); + }); +}); diff --git a/packages/cacti-copm-test/src/test/typescript/integration/test-copm-lock-claim.test.ts b/packages/cacti-copm-test/src/test/typescript/integration/test-copm-lock-claim.test.ts new file mode 100644 index 0000000000..64ce0a8dbd --- /dev/null +++ b/packages/cacti-copm-test/src/test/typescript/integration/test-copm-lock-claim.test.ts @@ -0,0 +1,186 @@ +import "jest-extended"; +import { + LogLevelDesc, + Logger, + LoggerProvider, +} from "@hyperledger/cactus-common"; +import { + ClaimLockedAssetV1Request, + LockAssetV1Request, +} from "@hyperledger-cacti/cacti-copm-core"; +import { copmTesterFactory } from "../../../main/typescript/lib/copm-tester-factory"; +import { CopmTester } from "../../../main/typescript/interfaces/copm-tester"; +import * as path from "path"; +import * as dotenv from "dotenv"; +import { CopmNetworkMode } from "../../../main/typescript/lib/types"; +dotenv.config({ path: path.resolve(__dirname, "../../.env") }); + +const logLevel: LogLevelDesc = "DEBUG"; +const log: Logger = LoggerProvider.getOrCreate({ + label: "plugin-copm-crpc-server-test", + level: logLevel, +}); + +const netType = process.env["COPM_NET_1"] || "fabric"; + +describe("Copm Lock and Claim", () => { + let copmTester: CopmTester; + const hashSecret: string = "my_secret_123"; + const lockAssetName: string = "lockasset" + new Date().getTime().toString(); + + beforeAll(async () => { + log.info("setting up copm test network"); + copmTester = copmTesterFactory(log, netType, CopmNetworkMode.Lock); + await copmTester.startServer(); + }); + + afterAll(async () => { + if (copmTester) { + await copmTester.stopServer(); + } + }); + + test(`${netType} can lock/claim nft on same network`, async () => { + const assetType = "bond"; + const partyA = copmTester.getPartyA(assetType); + const partyB = copmTester.getPartyB(assetType); + + // parties are different but on the same network + expect(partyA.organization).toEqual(partyB.organization); + expect(partyA.userId).not.toEqual(partyB.userId); + + const sourceCert = await copmTester.getCertificateString(partyA); + const destCert = await copmTester.getCertificateString(partyB); + + const assetsPartyA = await copmTester.assetsFor(partyA); + const assetsPartyB = await copmTester.assetsFor(partyB); + + await assetsPartyA.addNonFungibleAsset(assetType, lockAssetName); + + const lockResult = await copmTester.clientFor(partyA).lockAssetV1( + new LockAssetV1Request({ + assetLockV1PB: { + asset: { + assetType: assetType, + assetId: lockAssetName, + }, + source: { + network: partyA.organization, + userId: partyA.userId, + }, + dest: { + network: partyB.organization, + userId: partyB.userId, + }, + hashInfo: { + secret: hashSecret, + }, + expirySecs: BigInt(45), + sourceCertificate: sourceCert, + destinationCertificate: destCert, + }, + }), + ); + + expect(lockResult).toBeTruthy(); + + const claimResult = await copmTester.clientFor(partyB).claimLockedAssetV1( + new ClaimLockedAssetV1Request({ + assetLockClaimV1PB: { + lockId: lockResult.lockId, + asset: { + assetType: assetType, + assetId: lockAssetName, + }, + destination: { + network: partyB.organization, + userId: partyB.userId, + }, + hashInfo: { + secret: hashSecret, + }, + }, + }), + ); + expect(claimResult).toBeTruthy(); + + expect( + await assetsPartyA.userOwnsNonFungibleAsset(assetType, lockAssetName), + ).toBeFalse(); + expect( + await assetsPartyB.userOwnsNonFungibleAsset(assetType, lockAssetName), + ).toBeTrue(); + }); + + test(`${netType} can lock/claim tokens on same network`, async () => { + const assetType = "token1"; + const assetQuantity = 10; + const partyA = copmTester.getPartyA(assetType); + const partyB = copmTester.getPartyB(assetType); + + // parties are different but on the same network + expect(partyA.organization).toEqual(partyB.organization); + expect(partyA.userId).not.toEqual(partyB.userId); + + const assetsPartyA = await copmTester.assetsFor(partyA); + const assetsPartyB = await copmTester.assetsFor(partyB); + + await assetsPartyA.addToken(assetType, assetQuantity); + + const partyAStartBalance = await assetsPartyA.tokenBalance(assetType); + const partyBStartBalance = await assetsPartyB.tokenBalance(assetType); + + const srcCert = await copmTester.getCertificateString(partyA); + const destCert = await copmTester.getCertificateString(partyB); + + const lockResult = await copmTester.clientFor(partyA).lockAssetV1( + new LockAssetV1Request({ + assetLockV1PB: { + asset: { + assetType: assetType, + assetQuantity: assetQuantity, + }, + source: { network: partyA.organization, userId: partyA.userId }, + dest: { network: partyB.organization, userId: partyB.userId }, + hashInfo: { + secret: hashSecret, + }, + expirySecs: BigInt(45), + sourceCertificate: srcCert, + destinationCertificate: destCert, + }, + }), + ); + + expect(lockResult).toBeTruthy(); + expect(lockResult.lockId).toBeString(); + log.debug(lockResult.lockId); + + const claimResult = await copmTester.clientFor(partyB).claimLockedAssetV1( + new ClaimLockedAssetV1Request({ + assetLockClaimV1PB: { + lockId: lockResult.lockId, + asset: { + assetType: assetType, + assetQuantity: assetQuantity, + }, + destination: { + network: partyB.organization, + userId: partyB.userId, + }, + hashInfo: { + secret: hashSecret, + }, + }, + }), + ); + expect(claimResult).toBeTruthy(); + expect(await assetsPartyA.tokenBalance(assetType)).toEqual( + partyAStartBalance - assetQuantity, + ); + + expect(await assetsPartyB.tokenBalance(assetType)).toEqual( + partyBStartBalance + assetQuantity, + ); + }); +}); diff --git a/packages/cacti-copm-test/src/test/typescript/integration/test-copm-pledge-claim.test.ts b/packages/cacti-copm-test/src/test/typescript/integration/test-copm-pledge-claim.test.ts new file mode 100644 index 0000000000..95f6c16c34 --- /dev/null +++ b/packages/cacti-copm-test/src/test/typescript/integration/test-copm-pledge-claim.test.ts @@ -0,0 +1,227 @@ +import "jest-extended"; +import { + LogLevelDesc, + Logger, + LoggerProvider, +} from "@hyperledger/cactus-common"; +import { + ClaimPledgedAssetV1Request, + PledgeAssetV1Request, +} from "@hyperledger-cacti/cacti-copm-core"; +import { CopmNetworkMode } from "../../../main/typescript/lib/types"; +import { CopmTestertMultiNetwork } from "../../../main/typescript/lib/copm-tester-multi-network"; +import * as path from "path"; +import * as dotenv from "dotenv"; + +dotenv.config({ path: path.resolve(__dirname, "../../.env") }); + +const logLevel: LogLevelDesc = "DEBUG"; +const log: Logger = LoggerProvider.getOrCreate({ + label: "plugin-copm-crpc-server-test", + level: logLevel, +}); + +function makeMatrix(supportedNetworks: string[]): string[][] { + const supportedCombos = []; + for (const val1 of supportedNetworks) { + for (const val2 of supportedNetworks) { + supportedCombos.push([val1, val2]); + } + } + return supportedCombos; +} + +describe("Copm Pledge and Claim", () => { + let copmTester: CopmTestertMultiNetwork; + + const pledgeAssetName: string = + "pledgeasset" + new Date().getTime().toString(); + + const supportedNetworks = ["fabric", "corda"]; + let networksToTest: string[][]; + if (process.env["COPM_NET_1"] && process.env["COPM_NET_2"]) { + networksToTest = [[process.env["COPM_NET_1"], process.env["COPM_NET_2"]]]; + } else { + networksToTest = makeMatrix(supportedNetworks); + } + + log.info(`Supported network combos: ${JSON.stringify(networksToTest)}`); + + beforeAll(async () => { + copmTester = new CopmTestertMultiNetwork(log, CopmNetworkMode.Pledge); + await copmTester.startServer(); + log.info("test setup complete"); + }); + + afterAll(async () => { + if (copmTester) { + await copmTester.stopServer(); + } + }); + + test.each(networksToTest)( + "%s-%s nft pledge and claim", + async (net1Type, net2Type) => { + if (net1Type == "corda" && net2Type == "fabric") { + // can not transfer nft from corda to fabric due to + // maturity date issue + //https://github.com/hyperledger-cacti/cacti/issues/3610 + return; + } + await copmTester.setNetworks(net1Type, net2Type); + + const assetType = "bond01"; + const partyA = copmTester.getPartyA(assetType); + const partyB = copmTester.getPartyB(assetType); + const certA = await copmTester.getCertificateString(partyA); + const certB = await copmTester.getCertificateString(partyB); + const assetsPartyA = await copmTester.assetsFor(partyA); + const assetsPartyB = await copmTester.assetsFor(partyB); + + await assetsPartyA.addNonFungibleAsset(assetType, pledgeAssetName); + + const pledgeNFTResult = await copmTester.clientFor(partyA).pledgeAssetV1( + new PledgeAssetV1Request({ + assetPledgeV1PB: { + asset: { + assetType: assetType, + assetId: pledgeAssetName, + }, + source: { network: partyA.organization, userId: partyA.userId }, + destination: { + network: partyB.organization, + userId: partyB.userId, + }, + expirySecs: BigInt(45), + destinationCertificate: certB, + }, + }), + ); + + expect(pledgeNFTResult).toBeTruthy(); + expect(pledgeNFTResult.pledgeId).toBeString(); + + const claimNFTResult = await copmTester + .clientFor(partyB) + .claimPledgedAssetV1( + new ClaimPledgedAssetV1Request({ + assetPledgeClaimV1PB: { + pledgeId: pledgeNFTResult.pledgeId, + asset: { + assetType: assetType, + assetId: pledgeAssetName, + }, + source: { network: partyA.organization, userId: partyA.userId }, + destination: { + network: partyB.organization, + userId: partyB.userId, + }, + sourceCertificate: certA, + destCertificate: certB, + }, + }), + ); + expect(claimNFTResult).toBeTruthy(); + + expect( + await assetsPartyA.userOwnsNonFungibleAsset(assetType, pledgeAssetName), + ).toBeFalse(); + expect( + await assetsPartyB.userOwnsNonFungibleAsset(assetType, pledgeAssetName), + ).toBeTrue(); + }, + ); + + test.each(networksToTest)( + "%s-%s fungible pledge and claim", + async (net1Type, net2Type) => { + await copmTester.setNetworks(net1Type, net2Type); + log.info("starting tests"); + const assetType = "token1"; + const exchangeQuantity = 10; + const partyA = copmTester.getPartyA(assetType); + const partyB = copmTester.getPartyB(assetType); + const certA = await copmTester.getCertificateString(partyA); + const certB = await copmTester.getCertificateString(partyB); + + const assetsPartyA = await copmTester.assetsFor(partyA); + const assetsPartyB = await copmTester.assetsFor(partyB); + + await assetsPartyA.addToken(assetType, exchangeQuantity); + await assetsPartyB.addToken(assetType, 1); + + const partyAStartBalance = await assetsPartyA.tokenBalance(assetType); + const partyBStartBalance = await assetsPartyB.tokenBalance(assetType); + + log.info( + "party a %s@%s start balance %d", + partyA.userId, + partyA.organization, + partyAStartBalance, + ); + log.info( + "party b %s@%s start balance %d", + partyB.userId, + partyB.organization, + partyBStartBalance, + ); + + const pledgeResult = await copmTester.clientFor(partyA).pledgeAssetV1( + new PledgeAssetV1Request({ + assetPledgeV1PB: { + asset: { + assetType: assetType, + assetQuantity: exchangeQuantity, + }, + source: { + network: partyA.organization, + userId: partyA.userId, + }, + destination: { + network: partyB.organization, + userId: partyB.userId, + }, + expirySecs: BigInt(45), + destinationCertificate: certB, + }, + }), + ); + + expect(pledgeResult).toBeTruthy(); + expect(pledgeResult.pledgeId).toBeString(); + + const claimResult = await copmTester + .clientFor(partyB) + .claimPledgedAssetV1( + new ClaimPledgedAssetV1Request({ + assetPledgeClaimV1PB: { + pledgeId: pledgeResult.pledgeId, + asset: { + assetType: assetType, + assetQuantity: exchangeQuantity, + }, + source: { + network: partyA.organization, + userId: partyA.userId, + }, + destination: { + network: partyB.organization, + userId: partyB.userId, + }, + sourceCertificate: certA, + destCertificate: certB, + }, + }), + ); + expect(claimResult).toBeTruthy(); + + expect(await assetsPartyA.tokenBalance(assetType)).toEqual( + partyAStartBalance - exchangeQuantity, + ); + + expect(await assetsPartyB.tokenBalance(assetType)).toEqual( + partyBStartBalance + exchangeQuantity, + ); + }, + ); +}); diff --git a/packages/cacti-copm-test/tsconfig.json b/packages/cacti-copm-test/tsconfig.json new file mode 100644 index 0000000000..cbbad32611 --- /dev/null +++ b/packages/cacti-copm-test/tsconfig.json @@ -0,0 +1,30 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "composite": true, + "outDir": "./dist/lib/", + "declarationDir": "dist/lib", + "rootDir": "./src", + "tsBuildInfoFile": "../../.build-cache/cacti-copm-test.tsbuildinfo", + "strict": false, + "noImplicitAny": false + }, + "include": [ + "./src" + ], + "references": [ + { + "path": "../cactus-common/tsconfig.json" + }, + { + "path": "../cacti-copm-core/tsconfig.json" + }, + { + "path": "../cacti-plugin-copm-fabric/tsconfig.json" + }, + { + "path": "../cacti-plugin-copm-corda/tsconfig.json" + } + + ] +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/.gitignore b/packages/cacti-plugin-copm-corda/.gitignore new file mode 100644 index 0000000000..34b4d183a8 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/.gitignore @@ -0,0 +1 @@ +localdeps diff --git a/packages/cacti-plugin-copm-corda/README.md b/packages/cacti-plugin-copm-corda/README.md new file mode 100644 index 0000000000..0fe5d0cd08 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/README.md @@ -0,0 +1,42 @@ +# @hyperledger-cacti/cacti-plugin-copm-corda + +Implements COPM primitives for Corda as a cacti plugin. The implementation follows the model of the Corda ledger connector plugin, where a typescript pass-through implementation is registered on the plugin server, and commands are implemented on a separate grpc server in the Kotlin Spring framework. + +Command documentation as OpenAPI: +https://hyperledger-cacti.github.io/cacti/references/openapi/cacti-copm-core_openapi/ + +The kotlin implementation is divided into a base package, org.hyperledger.cacti.plugin.copm, and a sample implementation, +com.copmCorda. The com.copmCorda package specifies the application-specific implementation using the weaver +sample code. + +These endpoints require the following: + +- weaver relays and drivers to be deployed on the network +- chaincode contracts supporting 'asset exchange' and 'asset transfer' to be deployed on the corda network + +Please see https://hyperledger-cacti.github.io/cacti/weaver/introduction/. + +# Usage + +## Installation + +Yarn: + + yarn add --exact @hyperledger-cacti/cacti-plugin-copm-corda + +In a production scenario the kotlin server should be deployed and reachable from the cacti server plugin. Please see +the Dockerfile in src/test as an example. + +## Configuration + +The following application-specific interfaces must be implemented: + + - CordaConfiguration - provides information on how local asset contracts and user accounts are configured + - InteropConfiguration - provides information on how remote networks are configured + +These implementations should be marked as Spring components, as shown in the example implementation in src/test. + +## Development + +Please see [the cacti-cop-test README](./../cacti-copm-test/README.md) for details on building a +corda test network. diff --git a/packages/cacti-plugin-copm-corda/package.json b/packages/cacti-plugin-copm-corda/package.json new file mode 100644 index 0000000000..1417edc498 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/package.json @@ -0,0 +1,44 @@ +{ + "name": "@hyperledger-cacti/cacti-plugin-copm-corda", + "version": "2.0.0", + "description": "Cacti Common Operators - Corda", + "homepage": "https://github.com/hyperledger-cacti/cacti#readme", + "bugs": { + "url": "https://github.com/hyperledger-cacti/cacti/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/hyperledger-cacti/cacti.git" + }, + "license": "Apache-2.0", + "author": "Jennifer Bell", + "main": "dist/lib/main/typescript/index.js", + "module": "dist/lib/main/typescript/index.js", + "types": "dist/lib/main/typescript/index.d.ts", + "files": [ + "dist/*" + ], + "scripts": { + "build": "./gradlew build", + "bundleopenapi": "yarn run --top-level tools:bundle-open-api-tpl-files" + }, + "dependencies": { + "@bufbuild/buf": "1.30.0", + "@bufbuild/protobuf": "1.10.0", + "@connectrpc/connect": "1.4.0", + "@connectrpc/connect-node": "1.4.0", + "@connectrpc/connect-web": "1.4.0", + "@hyperledger-cacti/cacti-copm-core": "2.0.0", + "@hyperledger-cacti/cacti-copm-test": "2.0.0", + "@hyperledger/cacti-weaver-protos-js": "2.0.0", + "@hyperledger/cacti-weaver-sdk-fabric": "2.0.0", + "@hyperledger/cactus-common": "2.0.0", + "@hyperledger/cactus-core": "2.0.0", + "@hyperledger/cactus-core-api": "2.0.0" + }, + "devDependencies": { + "@connectrpc/connect-node": "1.4.0", + "@types/convict": "6.1.1", + "convict": "6.2.4" + } +} diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/ApiCopmCordaServiceImpl.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/ApiCopmCordaServiceImpl.kt new file mode 100644 index 0000000000..c2cb1a6aff --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/ApiCopmCordaServiceImpl.kt @@ -0,0 +1,101 @@ +package org.hyperledger.cacti.plugin.copm + +import org.hyperledger.cacti.plugin.copm.interfaces.InteropConfig +import org.hyperledger.cacti.plugin.copm.interfaces.CordaConfiguration +import org.hyperledger.cacti.plugin.copm.endpoints.* +import org.hyperledger.cacti.plugin.copm.validators.* +import io.grpc.Status +import net.corda.core.CordaRuntimeException +import net.corda.core.utilities.loggerFor +import com.google.protobuf.Empty +import net.devh.boot.grpc.server.advice.GrpcAdvice +import net.devh.boot.grpc.server.advice.GrpcExceptionHandler +import net.devh.boot.grpc.server.service.GrpcService +import org.hyperledger.cacti.plugin.copm.core.ClaimPledgedAssetV1200ResponsePb +import org.hyperledger.cacti.plugin.copm.core.GetVerifiedViewV1200ResponsePb +import org.hyperledger.cacti.plugin.copm.core.LockAssetV1200ResponsePb +import org.hyperledger.cacti.plugin.copm.core.PledgeAssetV1200ResponsePb +import org.hyperledger.cacti.plugin.copm.core.services.defaultservice.DefaultServiceGrpcKt +import org.hyperledger.cacti.plugin.copm.core.services.defaultservice.DefaultServiceOuterClass +import org.springframework.beans.factory.annotation.Autowired + + +@GrpcService +class ApiCopmCordaServiceImpl : DefaultServiceGrpcKt.DefaultServiceCoroutineImplBase() { + + lateinit var transactionContextFactory: DLTransactionContextFactory + lateinit var cordaConfig: CordaConfiguration + lateinit var interopConfig: InteropConfig + + @Autowired + fun setupCordaConfig(config: CordaConfiguration) { + this.cordaConfig = config + } + + @Autowired + fun setupInteropConfig(config: InteropConfig) { + this.interopConfig = config + } + + @Autowired + fun setupContextFactory(factory: DLTransactionContextFactory) { + this.transactionContextFactory = factory + } + + companion object { + val logger = loggerFor() + } + + override suspend fun noopV1(request: Empty): Empty { + return Empty.getDefaultInstance(); + } + + override suspend fun claimLockedAssetV1(request: DefaultServiceOuterClass.ClaimLockedAssetV1Request): ClaimPledgedAssetV1200ResponsePb.ClaimPledgedAssetV1200ResponsePB { + return claimLockedAssetV1Impl(request, this.transactionContextFactory, this.cordaConfig) + } + + override suspend fun claimPledgedAssetV1(request: DefaultServiceOuterClass.ClaimPledgedAssetV1Request): ClaimPledgedAssetV1200ResponsePb.ClaimPledgedAssetV1200ResponsePB { + return claimPledgedAssetV1Impl(request, this.transactionContextFactory, this.cordaConfig, this.interopConfig) + } + + override suspend fun getVerifiedViewV1(request: DefaultServiceOuterClass.GetVerifiedViewV1Request): GetVerifiedViewV1200ResponsePb.GetVerifiedViewV1200ResponsePB { + return getVerifiedViewV1Impl(request, this.transactionContextFactory) + } + + override suspend fun lockAssetV1(request: DefaultServiceOuterClass.LockAssetV1Request): LockAssetV1200ResponsePb.LockAssetV1200ResponsePB + { + return lockAssetV1Impl(request, this.transactionContextFactory, this.cordaConfig) + } + + override suspend fun pledgeAssetV1(request: DefaultServiceOuterClass.PledgeAssetV1Request): PledgeAssetV1200ResponsePb.PledgeAssetV1200ResponsePB { + // Obtain the recipient certificate from the name of the recipient + return pledgeAssetV1Impl(request, this.transactionContextFactory, this.cordaConfig) + } + +} + + +@GrpcAdvice +class GlobalExceptionHandler { + companion object { + val logger = loggerFor() + } + + @GrpcExceptionHandler(IllegalArgumentException::class) + fun handleMyCustomException(e: IllegalArgumentException): Status { + logger.error(e.message) + return Status.INVALID_ARGUMENT.withDescription(e.message) + } + + @GrpcExceptionHandler(IllegalStateException::class) + fun handleMyCustomException(e: IllegalStateException): Status { + logger.error(e.message) + return Status.INTERNAL.withDescription(e.message) + } + + @GrpcExceptionHandler(CordaRuntimeException::class) + fun handleMyCustomException(e: CordaRuntimeException): Status { + logger.error(e.message) + return Status.INTERNAL.withDescription(e.message) + } +} diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/DLTransactionContextFactory.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/DLTransactionContextFactory.kt new file mode 100644 index 0000000000..1a2a734da1 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/DLTransactionContextFactory.kt @@ -0,0 +1,42 @@ +package org.hyperledger.cacti.plugin.copm + +import org.hyperledger.cacti.plugin.copm.interfaces.CordaConfiguration +import org.hyperledger.cacti.plugin.copm.corda.LocalTransactionContext +import org.hyperledger.cacti.plugin.copm.interfaces.InteropConfig +import org.hyperledger.cacti.plugin.copm.types.DLAccount +import org.hyperledger.cacti.plugin.copm.types.DLTransactionContext +import org.hyperledger.cacti.plugin.copm.interop.RemoteTransactionContext +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.stereotype.Component + +@Component +class DLTransactionContextFactory { + + lateinit var cordaConfig: CordaConfiguration + lateinit var interopConfig: InteropConfig + + + @Autowired + fun setupCordaConfig(config: CordaConfiguration) { + this.cordaConfig = config + } + + @Autowired + fun setupInteropConfig(config: InteropConfig) { + this.interopConfig = config + } + + fun getLocalTransactionContext(account: DLAccount) : DLTransactionContext { + return LocalTransactionContext(account, this.cordaConfig.getRPC(account)); + } + + fun getRemoteTransactionContext(account: DLAccount, remoteNetwork: String): DLTransactionContext { + return RemoteTransactionContext( + account.organization, + this.interopConfig.getRelayConfig(account.organization), + this.interopConfig.getViewAddressFormat(remoteNetwork), + this.cordaConfig.getRPC(account), + this.cordaConfig.getObservers(account) + ); + } +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/GrpcConfig.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/GrpcConfig.kt new file mode 100644 index 0000000000..c7f2e67deb --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/GrpcConfig.kt @@ -0,0 +1,61 @@ +package org.hyperledger.cacti.plugin.copm + +import net.devh.boot.grpc.client.autoconfigure.GrpcClientAutoConfiguration +import net.devh.boot.grpc.client.autoconfigure.GrpcClientHealthAutoConfiguration +import net.devh.boot.grpc.client.autoconfigure.GrpcClientMetricAutoConfiguration +import net.devh.boot.grpc.client.autoconfigure.GrpcClientSecurityAutoConfiguration +import net.devh.boot.grpc.client.autoconfigure.GrpcClientTraceAutoConfiguration +import net.devh.boot.grpc.client.autoconfigure.GrpcDiscoveryClientAutoConfiguration +import net.devh.boot.grpc.common.autoconfigure.GrpcCommonCodecAutoConfiguration +import net.devh.boot.grpc.common.autoconfigure.GrpcCommonTraceAutoConfiguration +import net.devh.boot.grpc.server.autoconfigure.GrpcAdviceAutoConfiguration +import net.devh.boot.grpc.server.autoconfigure.GrpcHealthServiceAutoConfiguration +import net.devh.boot.grpc.server.autoconfigure.GrpcMetadataConsulConfiguration +import net.devh.boot.grpc.server.autoconfigure.GrpcMetadataEurekaConfiguration +import net.devh.boot.grpc.server.autoconfigure.GrpcMetadataNacosConfiguration +import net.devh.boot.grpc.server.autoconfigure.GrpcMetadataZookeeperConfiguration +import net.devh.boot.grpc.server.autoconfigure.GrpcReflectionServiceAutoConfiguration +import net.devh.boot.grpc.server.autoconfigure.GrpcServerAutoConfiguration +import net.devh.boot.grpc.server.autoconfigure.GrpcServerFactoryAutoConfiguration +import net.devh.boot.grpc.server.autoconfigure.GrpcServerMetricAutoConfiguration +import net.devh.boot.grpc.server.autoconfigure.GrpcServerSecurityAutoConfiguration +import net.devh.boot.grpc.server.autoconfigure.GrpcServerTraceAutoConfiguration +import net.devh.boot.grpc.server.event.GrpcServerStartedEvent +import org.slf4j.LoggerFactory +import org.springframework.boot.autoconfigure.ImportAutoConfiguration +import org.springframework.context.annotation.Configuration +import org.springframework.context.event.EventListener + +@Configuration +@ImportAutoConfiguration( + GrpcClientAutoConfiguration::class, + GrpcClientMetricAutoConfiguration::class, + GrpcClientHealthAutoConfiguration::class, + GrpcClientSecurityAutoConfiguration::class, + GrpcClientTraceAutoConfiguration::class, + GrpcDiscoveryClientAutoConfiguration::class, + GrpcCommonCodecAutoConfiguration::class, + GrpcCommonTraceAutoConfiguration::class, + GrpcAdviceAutoConfiguration::class, + GrpcHealthServiceAutoConfiguration::class, + GrpcMetadataConsulConfiguration::class, + GrpcMetadataEurekaConfiguration::class, + GrpcMetadataNacosConfiguration::class, + GrpcMetadataZookeeperConfiguration::class, + GrpcReflectionServiceAutoConfiguration::class, + GrpcServerAutoConfiguration::class, + GrpcServerFactoryAutoConfiguration::class, + GrpcServerMetricAutoConfiguration::class, + GrpcServerSecurityAutoConfiguration::class, + GrpcServerTraceAutoConfiguration::class +) +private class GrpcServerConfig { + @EventListener + fun onServerStarted(event: GrpcServerStartedEvent) { + log.info("gRPC Server started, services: ${event.server.services[0].methods}") + } + + companion object { + private val log = LoggerFactory.getLogger(GrpcServerConfig::class.java) + } +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/corda/CordaAssetClaim.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/corda/CordaAssetClaim.kt new file mode 100644 index 0000000000..577c3c0c21 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/corda/CordaAssetClaim.kt @@ -0,0 +1,26 @@ +package org.hyperledger.cacti.plugin.copm.corda +import org.hyperledger.cacti.plugin.copm.validators.ValidatedClaimPledgedAssetV1Request +import net.corda.core.contracts.CommandData +import org.hyperledger.cacti.weaver.imodule.corda.states.AssetClaimParameters + +class CordaAssetClaim(private var data: ValidatedClaimPledgedAssetV1Request, + private var pledgeStatusLinearId: String, + private var issueCmd : CommandData, + private var getStateAndContract: String, + private var issuer: CordaParty, + private var observers: List< CordaParty >) : CordaType { + + override fun toCordaParam(rpc: NodeRPCConnection): Any { + return AssetClaimParameters(data.pledgeId, + this.issueCmd, + this.pledgeStatusLinearId, + this.getStateAndContract, + data.asset.assetType, + data.asset.assetIdOrQuantity(), + data.sourceCert, + data.destCert, + this.issuer.toCordaParam(rpc), + this.observers.map { it.toCordaParam(rpc) } + ) + } +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/corda/CordaAssetContract.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/corda/CordaAssetContract.kt new file mode 100644 index 0000000000..b4e80a1e8c --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/corda/CordaAssetContract.kt @@ -0,0 +1,11 @@ +package org.hyperledger.cacti.plugin.copm.corda +import net.corda.core.contracts.CommandData + +class CordaAssetContract( + val getStateAndRefCmdStr: String, + val getStateAndContractIdCmdStr: String, + val updateAssetOwnerCmdStr: String, + val issueAssetCmd: CommandData, + val burnAssetCmd: CommandData) { +} + diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/corda/CordaAssetPledge.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/corda/CordaAssetPledge.kt new file mode 100644 index 0000000000..0fca8861b8 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/corda/CordaAssetPledge.kt @@ -0,0 +1,27 @@ +package org.hyperledger.cacti.plugin.copm.corda +import org.hyperledger.cacti.plugin.copm.validators.ValidatedPledgeAssetV1Request +import net.corda.core.contracts.CommandData +import org.hyperledger.cacti.weaver.imodule.corda.states.AssetPledgeParameters + +class CordaAssetPledge(private val data: ValidatedPledgeAssetV1Request, + private val getStateAndRef: String, + private val assetBurn : CommandData, + private val issuer: CordaParty, + private val observers: List) + : CordaType { + + override fun toCordaParam(rpc: NodeRPCConnection): Any { + return AssetPledgeParameters( + data.asset.assetType, // @property assetType + data.asset.assetIdOrQuantity(), + data.sourceAccount.organization, // @property localNetworkId + data.destinationAccount.organization, // @property remoteNetworkId + data.destinationCertificate, // @property recipientCert + data.timeout, // @property expiryTimeSecs + this.getStateAndRef, + this.assetBurn, + this.issuer.toCordaParam(rpc), + this.observers.map { it.toCordaParam(rpc) } + ) + } +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/corda/CordaParty.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/corda/CordaParty.kt new file mode 100644 index 0000000000..42295810c4 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/corda/CordaParty.kt @@ -0,0 +1,10 @@ +package org.hyperledger.cacti.plugin.copm.corda + +import net.corda.core.identity.CordaX500Name +import net.corda.core.identity.Party + +class CordaParty(private val name: String) : CordaType { + override fun toCordaParam(rpc: NodeRPCConnection) : Party { + return rpc.proxy.wellKnownPartyFromX500Name(CordaX500Name.parse(name))!! + } +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/corda/CordaType.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/corda/CordaType.kt new file mode 100644 index 0000000000..a78d54e6cd --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/corda/CordaType.kt @@ -0,0 +1,14 @@ +package org.hyperledger.cacti.plugin.copm.corda + +/*** + Encapsulates a parameter from the corda library that requires a corda node + connection to resolve. + + Parameter values are resolved when a corda transaction is invoked. + + see: CordaParty + + ***/ +interface CordaType { + fun toCordaParam(rpc: NodeRPCConnection) : Any +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/corda/LocalTransactionContext.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/corda/LocalTransactionContext.kt new file mode 100644 index 0000000000..7aa2c38eaf --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/corda/LocalTransactionContext.kt @@ -0,0 +1,49 @@ +package org.hyperledger.cacti.plugin.copm.corda +import arrow.core.Either +import org.hyperledger.cacti.plugin.copm.types.DLAccount +import org.hyperledger.cacti.plugin.copm.types.DLTransactionParams +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +import net.corda.core.CordaRuntimeException +import net.corda.core.flows.FlowLogic +import org.hyperledger.cacti.plugin.copm.types.DLTransactionContext + + +class LocalTransactionContext(private val account: DLAccount, private val rpc: NodeRPCConnection) : DLTransactionContext { + + override suspend fun invoke(cmd: DLTransactionParams) : Any? { + val cordaParams = this.cordaParams(cmd.args).toTypedArray() + @Suppress("UNCHECKED_CAST") + val cordaFlow = Class.forName("${cmd.contract}.${cmd.method}") as Class> + try { + val result = withContext(Dispatchers.IO) { + rpc.proxy.startFlowDynamic( + cordaFlow, + *cordaParams + ).returnValue.get() + } + when (result) { + is Either.Left<*> -> { + throw IllegalStateException("Corda Error: ${result.a.toString()}\n") + } + is Either.Right<*> -> { + return result.b.toString() + } + } + throw IllegalStateException("Corda did not return an EITHER\n") + } catch (e: CordaRuntimeException) { + throw IllegalStateException("Corda Runtime Exception:" + e.message) + } + } + + private fun cordaParams(params: List) : List { + return params.map { + when (it) { + is CordaType -> it.toCordaParam(this.rpc) + is List<*> -> this.cordaParams(it.map { it as Any}) + else -> it + } + } + } + +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/corda/NodeRPCConnection.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/corda/NodeRPCConnection.kt new file mode 100644 index 0000000000..69d3b865b0 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/corda/NodeRPCConnection.kt @@ -0,0 +1,41 @@ +/* + * Copyright IBM Corp. All Rights Reserved. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.hyperledger.cacti.plugin.copm.corda + +import javax.annotation.PreDestroy +import net.corda.client.rpc.CordaRPCClient +import net.corda.core.utilities.NetworkHostAndPort + +/** + * Wraps a Corda node RPC proxy. + * + * @property host The host of the node we are connecting to. + * @property rpcPort The RPC port of the node we are connecting to. + * @property username The username for logging into the RPC client. + * @property password The password for logging into the RPC client. + * @property proxy The RPC proxy. + * @property rpcAddress The address of the node to connect to + * @property rpcClient The client for sending RPC calls to the node + * @property rpcConnection The connection with the node + */ +open class NodeRPCConnection( + private val host: String, + private val username: String, + private val password: String, + private val rpcPort: Int +) { + + private val rpcAddress = NetworkHostAndPort(host, rpcPort) + private val rpcClient = CordaRPCClient(rpcAddress) + private val rpcConnection = rpcClient.start(username, password) + val proxy = rpcConnection.proxy + + @PreDestroy + fun close() { + rpcConnection.notifyServerAndClose() + } +} diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/endpoints/ClaimLockedAssetV1Impl.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/endpoints/ClaimLockedAssetV1Impl.kt new file mode 100644 index 0000000000..5bc1a5ba66 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/endpoints/ClaimLockedAssetV1Impl.kt @@ -0,0 +1,35 @@ +package org.hyperledger.cacti.plugin.copm.endpoints + +import org.hyperledger.cacti.plugin.copm.ApiCopmCordaServiceImpl.Companion.logger +import org.hyperledger.cacti.plugin.copm.DLTransactionContextFactory +import org.hyperledger.cacti.plugin.copm.interfaces.CordaConfiguration +import org.hyperledger.cacti.plugin.copm.types.DLTransactionParams +import org.hyperledger.cacti.plugin.copm.validators.ValidatedClaimLockedAssetV1Request +import org.hyperledger.cacti.plugin.copm.core.ClaimPledgedAssetV1200ResponsePb +import org.hyperledger.cacti.plugin.copm.core.services.defaultservice.DefaultServiceOuterClass +import org.hyperledger.cacti.weaver.sdk.corda.AssetManager + +suspend fun claimLockedAssetV1Impl(request: DefaultServiceOuterClass.ClaimLockedAssetV1Request, + transactionContextFactory: DLTransactionContextFactory, + cordaConfig: CordaConfiguration +): ClaimPledgedAssetV1200ResponsePb.ClaimPledgedAssetV1200ResponsePB { + logger.debug("start claimLockedAssetV1") + val data = ValidatedClaimLockedAssetV1Request(request) + val assetContract = cordaConfig.assetContract(data.asset) + val transactionContext = transactionContextFactory.getLocalTransactionContext(data.recipient) + val claimId = transactionContext.invoke( + DLTransactionParams( + cordaConfig.copmContract, + "ClaimAsset", + listOf(data.contractId, + AssetManager.createAssetClaimInfo(data.hash), + assetContract.issueAssetCmd, + assetContract.updateAssetOwnerCmdStr, + cordaConfig.getIssuer(data.asset), + cordaConfig.getObservers(data.recipient)) + ) + ) + return ClaimPledgedAssetV1200ResponsePb.ClaimPledgedAssetV1200ResponsePB.newBuilder() + .setClaimId(claimId.toString()) + .build() +} diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/endpoints/ClaimPledgedAssetV1Impl.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/endpoints/ClaimPledgedAssetV1Impl.kt new file mode 100644 index 0000000000..5e3a36b405 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/endpoints/ClaimPledgedAssetV1Impl.kt @@ -0,0 +1,47 @@ +package org.hyperledger.cacti.plugin.copm.endpoints + +import org.hyperledger.cacti.plugin.copm.ApiCopmCordaServiceImpl.Companion.logger +import org.hyperledger.cacti.plugin.copm.DLTransactionContextFactory +import org.hyperledger.cacti.plugin.copm.corda.CordaAssetClaim +import org.hyperledger.cacti.plugin.copm.interfaces.CordaConfiguration +import org.hyperledger.cacti.plugin.copm.interfaces.InteropConfig +import org.hyperledger.cacti.plugin.copm.types.DLTransactionParams +import org.hyperledger.cacti.plugin.copm.validators.ValidatedClaimPledgedAssetV1Request +import net.corda.core.contracts.UniqueIdentifier +import org.hyperledger.cacti.plugin.copm.core.ClaimPledgedAssetV1200ResponsePb +import org.hyperledger.cacti.plugin.copm.core.services.defaultservice.DefaultServiceOuterClass + +suspend fun claimPledgedAssetV1Impl(request: DefaultServiceOuterClass.ClaimPledgedAssetV1Request, + contextFactory: DLTransactionContextFactory, + cordaConfig: CordaConfiguration, + interopConfig: InteropConfig +): ClaimPledgedAssetV1200ResponsePb.ClaimPledgedAssetV1200ResponsePB { + logger.debug("start claimPledgedAssetV1") + val data = ValidatedClaimPledgedAssetV1Request(request) + val assetContract = cordaConfig.assetContract(data.asset) + val remoteContext = contextFactory.getRemoteTransactionContext(data.destinationAccount, data.sourceAccount.organization) + val remoteCmd = interopConfig.getRemoteCopmContract(data.sourceAccount.organization, data.asset).getPledgeInfoCmd(data) + logger.debug("getting remote pledge id") + @Suppress("Unchecked_cast") + val pledgeStatusLinearId = (remoteContext.invoke(remoteCmd) as Array)[0].toString() + logger.debug("claiming pledge $pledgeStatusLinearId") + val params = CordaAssetClaim( + data, + pledgeStatusLinearId, + assetContract.issueAssetCmd, + assetContract.getStateAndContractIdCmdStr, + cordaConfig.getIssuer(data.asset), + cordaConfig.getObservers(data.destinationAccount) + ) + val transaction = contextFactory.getLocalTransactionContext(data.destinationAccount) + val res = transaction.invoke( + DLTransactionParams( + cordaConfig.copmContract, + "AssetTransferClaim", + listOf(params) + ) + ) + logger.debug("done claiming pledge ${res.toString()}") + return ClaimPledgedAssetV1200ResponsePb.ClaimPledgedAssetV1200ResponsePB.newBuilder().setClaimId(res.toString()) + .build() +} diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/endpoints/GetVerifiedViewV1Impl.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/endpoints/GetVerifiedViewV1Impl.kt new file mode 100644 index 0000000000..7d56e03fc9 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/endpoints/GetVerifiedViewV1Impl.kt @@ -0,0 +1,19 @@ +package org.hyperledger.cacti.plugin.copm.endpoints + +import org.hyperledger.cacti.plugin.copm.ApiCopmCordaServiceImpl.Companion.logger +import org.hyperledger.cacti.plugin.copm.DLTransactionContextFactory +import org.hyperledger.cacti.plugin.copm.validators.ValidatedGetVerifiedViewV1Request +import org.hyperledger.cacti.plugin.copm.core.GetVerifiedViewV1200ResponsePb +import org.hyperledger.cacti.plugin.copm.core.services.defaultservice.DefaultServiceOuterClass + +suspend fun getVerifiedViewV1Impl(request: DefaultServiceOuterClass.GetVerifiedViewV1Request, + transactionContextFactory: DLTransactionContextFactory): GetVerifiedViewV1200ResponsePb.GetVerifiedViewV1200ResponsePB { + logger.debug("start verified view") + val data = ValidatedGetVerifiedViewV1Request(request) + val remoteTransaction = transactionContextFactory.getRemoteTransactionContext(data.account, + data.remoteNetwork) + val res = remoteTransaction.invoke(data.cmd) + return GetVerifiedViewV1200ResponsePb.GetVerifiedViewV1200ResponsePB.newBuilder() + .setData(res.toString()) + .build() +} diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/endpoints/LockAssetV1Impl.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/endpoints/LockAssetV1Impl.kt new file mode 100644 index 0000000000..183af0e500 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/endpoints/LockAssetV1Impl.kt @@ -0,0 +1,41 @@ +package org.hyperledger.cacti.plugin.copm.endpoints + +import org.hyperledger.cacti.plugin.copm.ApiCopmCordaServiceImpl.Companion.logger +import org.hyperledger.cacti.plugin.copm.DLTransactionContextFactory +import org.hyperledger.cacti.plugin.copm.interfaces.CordaConfiguration +import org.hyperledger.cacti.plugin.copm.types.DLTransactionParams +import org.hyperledger.cacti.plugin.copm.validators.ValidatedLockAssetV1Request +import org.hyperledger.cacti.plugin.copm.core.LockAssetV1200ResponsePb +import org.hyperledger.cacti.plugin.copm.core.services.defaultservice.DefaultServiceOuterClass +import org.hyperledger.cacti.weaver.sdk.corda.AssetManager + + +suspend fun lockAssetV1Impl(request: DefaultServiceOuterClass.LockAssetV1Request, + transactionContextFactory: DLTransactionContextFactory, + cordaConfig: CordaConfiguration +): LockAssetV1200ResponsePb.LockAssetV1200ResponsePB { + logger.debug("start lockAssetV1") + val data = ValidatedLockAssetV1Request(request) + val contract = cordaConfig.assetContract(data.asset) + val lockInfo = AssetManager.createAssetLockInfo(data.hash,data.expiryTimeFmt, data.expiryTime) + val flow = if (data.asset.isNFT) "LockAsset" else "LockFungibleAsset" + val agreement = if (data.asset.isNFT) AssetManager.createAssetExchangeAgreement(data.asset.assetType,data.asset.assetId, data.destAccount.accountId,"") + else AssetManager.createFungibleAssetExchangeAgreement(data.asset.assetType,data.asset.assetQuantity,data.destAccount.accountId, "") + val transaction = transactionContextFactory.getLocalTransactionContext(data.sourceAccount) + val result = transaction.invoke( + DLTransactionParams( + cordaConfig.copmContract, + flow, + listOf(lockInfo, + agreement, + contract.getStateAndRefCmdStr, + contract.burnAssetCmd, + cordaConfig.getIssuer(data.asset), + cordaConfig.getObservers(data.sourceAccount)) + ) + ) + return LockAssetV1200ResponsePb.LockAssetV1200ResponsePB + .newBuilder() + .setLockId(result.toString()) + .build() +} diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/endpoints/PledgeAssetV1Impl.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/endpoints/PledgeAssetV1Impl.kt new file mode 100644 index 0000000000..b2920220ab --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/endpoints/PledgeAssetV1Impl.kt @@ -0,0 +1,34 @@ +package org.hyperledger.cacti.plugin.copm.endpoints + +import org.hyperledger.cacti.plugin.copm.ApiCopmCordaServiceImpl.Companion.logger +import org.hyperledger.cacti.plugin.copm.DLTransactionContextFactory +import org.hyperledger.cacti.plugin.copm.corda.CordaAssetPledge +import org.hyperledger.cacti.plugin.copm.interfaces.CordaConfiguration +import org.hyperledger.cacti.plugin.copm.types.DLTransactionParams +import org.hyperledger.cacti.plugin.copm.validators.ValidatedPledgeAssetV1Request +import org.hyperledger.cacti.plugin.copm.core.PledgeAssetV1200ResponsePb +import org.hyperledger.cacti.plugin.copm.core.services.defaultservice.DefaultServiceOuterClass + +suspend fun pledgeAssetV1Impl(request: DefaultServiceOuterClass.PledgeAssetV1Request, + contextFactory: DLTransactionContextFactory, + cordaConfig: CordaConfiguration +): PledgeAssetV1200ResponsePb.PledgeAssetV1200ResponsePB { + logger.debug("starting pledge asset") + val data = ValidatedPledgeAssetV1Request(request) + val assetContract = cordaConfig.assetContract(data.asset) + val transaction = contextFactory.getLocalTransactionContext(data.sourceAccount) + val params = CordaAssetPledge(data, + assetContract.getStateAndRefCmdStr, + assetContract.burnAssetCmd, + cordaConfig.getIssuer(data.asset), + cordaConfig.getObservers(data.destinationAccount)) + val result = transaction.invoke( + DLTransactionParams(cordaConfig.copmContract, + "AssetTransferPledge", + listOf( params )) + ) + return PledgeAssetV1200ResponsePb.PledgeAssetV1200ResponsePB + .newBuilder() + .setPledgeId(result?.toString()) + .build() +} diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interfaces/CordaConfiguration.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interfaces/CordaConfiguration.kt new file mode 100644 index 0000000000..2511795425 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interfaces/CordaConfiguration.kt @@ -0,0 +1,33 @@ +package org.hyperledger.cacti.plugin.copm.interfaces +import org.hyperledger.cacti.plugin.copm.corda.CordaAssetContract +import org.hyperledger.cacti.plugin.copm.corda.CordaParty +import org.hyperledger.cacti.plugin.copm.corda.NodeRPCConnection +import org.hyperledger.cacti.plugin.copm.types.DLAccount +import org.hyperledger.cacti.plugin.copm.types.DLAsset + +interface CordaConfiguration { + /** + * The local chaincode containing the COPM functions + */ + val copmContract: String + + /** + * Given an asset, return the Corda contract information for the asset + */ + fun assetContract(asset: DLAsset) : CordaAssetContract + + /** + * Return the RPC connection for a given account + */ + fun getRPC(account: DLAccount) : NodeRPCConnection + + /** + * Given an asset, return the issuer + */ + fun getIssuer(asset: DLAsset) : CordaParty + + /** + * return a list of observer parties who may be interested + */ + fun getObservers(account: DLAccount) : List +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interfaces/InteropConfig.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interfaces/InteropConfig.kt new file mode 100644 index 0000000000..fe7adfc87e --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interfaces/InteropConfig.kt @@ -0,0 +1,13 @@ +package org.hyperledger.cacti.plugin.copm.interfaces +import org.hyperledger.cacti.plugin.copm.interop.RelayConfig +import org.hyperledger.cacti.plugin.copm.interop.RemoteCopmContract +import org.hyperledger.cacti.plugin.copm.interop.RemoteNetworkConfig +import org.hyperledger.cacti.plugin.copm.interop.ViewAddressFormat +import org.hyperledger.cacti.plugin.copm.types.DLAsset + +interface InteropConfig { + fun getRelayConfig(localNetwork: String): RelayConfig; + fun getViewAddressFormat(remoteNetwork: String) : ViewAddressFormat; + fun getRemoteCopmContract(remoteNetwork: String, asset: DLAsset) : RemoteCopmContract; + fun getRemoteNetworkConfig(remoteNetwork: String): RemoteNetworkConfig; +} diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interop/RelayConfig.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interop/RelayConfig.kt new file mode 100644 index 0000000000..1fd68d0b8e --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interop/RelayConfig.kt @@ -0,0 +1,6 @@ +package org.hyperledger.cacti.plugin.copm.interop + +import org.hyperledger.cacti.weaver.sdk.corda.RelayOptions + +class RelayConfig(val endpoint: String, val options: RelayOptions) { +} diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interop/RemoteCopmContract.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interop/RemoteCopmContract.kt new file mode 100644 index 0000000000..1599225f8c --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interop/RemoteCopmContract.kt @@ -0,0 +1,10 @@ +package org.hyperledger.cacti.plugin.copm.interop + +import org.hyperledger.cacti.plugin.copm.types.DLAsset +import org.hyperledger.cacti.plugin.copm.types.DLTransactionParams +import org.hyperledger.cacti.plugin.copm.validators.ValidatedClaimPledgedAssetV1Request + +interface RemoteCopmContract { + fun matchesNetworkTypeAndAsset(networkType: String, asset: DLAsset): Boolean + fun getPledgeInfoCmd(claim: ValidatedClaimPledgedAssetV1Request) : DLTransactionParams +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interop/RemoteNetworkConfig.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interop/RemoteNetworkConfig.kt new file mode 100644 index 0000000000..51d9cce30a --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interop/RemoteNetworkConfig.kt @@ -0,0 +1,11 @@ +package org.hyperledger.cacti.plugin.copm.interop + +class RemoteNetworkConfig(val networkId: String, + val networkType: String, + val relayEndpoint: String, + val channelName: String, // fabric-specific + val partyEndpoints: List // corda-specific + ) +{ +} + diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interop/RemoteTransactionContext.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interop/RemoteTransactionContext.kt new file mode 100644 index 0000000000..7fbf73e9c3 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interop/RemoteTransactionContext.kt @@ -0,0 +1,44 @@ +package org.hyperledger.cacti.plugin.copm.interop + +import arrow.core.Either +import org.hyperledger.cacti.plugin.copm.corda.CordaParty +import org.hyperledger.cacti.plugin.copm.corda.NodeRPCConnection +import org.hyperledger.cacti.plugin.copm.interfaces.InteropConfig +import org.hyperledger.cacti.plugin.copm.types.DLTransactionContext +import org.hyperledger.cacti.plugin.copm.types.DLTransactionParams +import org.hyperledger.cacti.weaver.sdk.corda.InteroperableHelper +import net.corda.core.utilities.loggerFor + +class RemoteTransactionContext( + private val localOrgKey: String, + private val relayConfig: RelayConfig, + private val viewAddressFormat: ViewAddressFormat, + private val rpc: NodeRPCConnection, + private val participants: List +) : DLTransactionContext { + + companion object { + val logger = loggerFor() + } + + override suspend fun invoke(cmd: DLTransactionParams): Any? { + val address = this.viewAddressFormat.address(cmd) + logger.info("invoking flow: $address at relay ${relayConfig.endpoint}") + val result = InteroperableHelper.interopFlow( + this.rpc.proxy, + arrayOf(address), + relayConfig.endpoint, + localOrgKey, + externalStateParticipants = this.participants.map { it.toCordaParam(rpc) }, + relayOptions = relayConfig.options + ) + when (result) { + is Either.Left<*> -> { + throw IllegalStateException("Corda Error: ${result.a.toString()}\n") + } + is Either.Right<*> -> { + return result.b + } + } + } +} diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interop/ViewAddressFormat.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interop/ViewAddressFormat.kt new file mode 100644 index 0000000000..3208404c10 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interop/ViewAddressFormat.kt @@ -0,0 +1,7 @@ +package org.hyperledger.cacti.plugin.copm.interop + +import org.hyperledger.cacti.plugin.copm.types.DLTransactionParams + +interface ViewAddressFormat { + fun address(cmd: DLTransactionParams) : String +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interop/corda/ViewAddressCorda.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interop/corda/ViewAddressCorda.kt new file mode 100644 index 0000000000..09d430df29 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interop/corda/ViewAddressCorda.kt @@ -0,0 +1,18 @@ +package org.hyperledger.cacti.plugin.copm.interop.corda + +import org.hyperledger.cacti.plugin.copm.types.DLTransactionParams +import org.hyperledger.cacti.plugin.copm.interop.RemoteNetworkConfig +import org.hyperledger.cacti.plugin.copm.interop.ViewAddressFormat +import org.hyperledger.cacti.weaver.sdk.corda.InteroperableHelper + +class ViewAddressCorda(private val remoteNetworkConfig: RemoteNetworkConfig): ViewAddressFormat { + override fun address(cmd: DLTransactionParams): String { + return InteroperableHelper.createCordaViewAddress( + this.remoteNetworkConfig.networkId, + this.remoteNetworkConfig.relayEndpoint, + this.remoteNetworkConfig.partyEndpoints, + cmd.contract + "." + cmd.method, + cmd.args.joinToString(separator=":") { it.toString() }) + } + +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interop/fabric/ViewAddressFabric.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interop/fabric/ViewAddressFabric.kt new file mode 100644 index 0000000000..ab176021e9 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/interop/fabric/ViewAddressFabric.kt @@ -0,0 +1,18 @@ +package org.hyperledger.cacti.plugin.copm.interop.fabric + +import org.hyperledger.cacti.plugin.copm.types.DLTransactionParams +import org.hyperledger.cacti.plugin.copm.interop.RemoteNetworkConfig +import org.hyperledger.cacti.plugin.copm.interop.ViewAddressFormat +import org.hyperledger.cacti.weaver.sdk.corda.InteroperableHelper + +class ViewAddressFabric(private val remoteNetworkConfig: RemoteNetworkConfig): ViewAddressFormat { + override fun address(cmd: DLTransactionParams): String { + return InteroperableHelper.createFabricViewAddress( + this.remoteNetworkConfig.networkId, + this.remoteNetworkConfig.relayEndpoint, + this.remoteNetworkConfig.channelName, + cmd.contract, + cmd.method, + cmd.args.joinToString(separator=":") { it.toString() }) + } +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/types/DLAccount.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/types/DLAccount.kt new file mode 100644 index 0000000000..25fded78f6 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/types/DLAccount.kt @@ -0,0 +1,4 @@ +package org.hyperledger.cacti.plugin.copm.types + +class DLAccount(val organization: String, val accountId: String) { +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/types/DLAsset.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/types/DLAsset.kt new file mode 100644 index 0000000000..e60df048b0 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/types/DLAsset.kt @@ -0,0 +1,14 @@ +package org.hyperledger.cacti.plugin.copm.types + +import org.hyperledger.cacti.plugin.copm.core.TransferrableAssetV1Pb.TransferrableAssetV1PB + +class DLAsset public constructor(asset: TransferrableAssetV1PB) { + val assetType: String = asset.getAssetType() + val assetId: String = asset.getAssetId(); + val assetQuantity: Long = asset.getAssetQuantity().toLong(); + val isNFT: Boolean = asset.getAssetQuantity() == 0; + + fun assetIdOrQuantity() : Any { + return if (this.isNFT) this.assetId else this.assetQuantity + } +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/types/DLTransactionContext.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/types/DLTransactionContext.kt new file mode 100644 index 0000000000..bf862f954a --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/types/DLTransactionContext.kt @@ -0,0 +1,5 @@ +package org.hyperledger.cacti.plugin.copm.types + +interface DLTransactionContext { + suspend fun invoke(cmd: DLTransactionParams) : Any? +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/types/DLTransactionParams.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/types/DLTransactionParams.kt new file mode 100644 index 0000000000..cc4d7ec60b --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/types/DLTransactionParams.kt @@ -0,0 +1,4 @@ +package org.hyperledger.cacti.plugin.copm.types + +class DLTransactionParams( val contract: String, val method: String, val args: List) { + } \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/validators/ValidatedClaimLockedAssetV1Request.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/validators/ValidatedClaimLockedAssetV1Request.kt new file mode 100644 index 0000000000..c218433707 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/validators/ValidatedClaimLockedAssetV1Request.kt @@ -0,0 +1,24 @@ +package org.hyperledger.cacti.plugin.copm.validators + +import org.hyperledger.cacti.plugin.copm.types.DLAccount +import org.hyperledger.cacti.plugin.copm.types.DLAsset +import org.hyperledger.cacti.plugin.copm.server.validators.validateAccount +import org.hyperledger.cacti.plugin.copm.server.validators.validateAsset +import org.hyperledger.cacti.plugin.copm.server.validators.validateHash +import org.hyperledger.cacti.plugin.copm.server.validators.validateRequiredString +import org.hyperledger.cacti.plugin.copm.core.services.defaultservice.DefaultServiceOuterClass.ClaimLockedAssetV1Request +import org.hyperledger.cacti.weaver.sdk.corda.HashFunctions + +class ValidatedClaimLockedAssetV1Request(val asset: DLAsset, + val contractId: String, + val recipient: DLAccount, + val hash: HashFunctions.Hash ) { + + constructor(request: ClaimLockedAssetV1Request) : this( + validateAsset(request.assetLockClaimV1PB.asset, "asset"), + validateRequiredString(request.assetLockClaimV1PB.lockId, "lockId"), + validateAccount(request.assetLockClaimV1PB.destination, "destination"), + validateHash(request.assetLockClaimV1PB.hashInfo, "hashInfo") + ) { + } +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/validators/ValidatedClaimPledgedAssetV1Request.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/validators/ValidatedClaimPledgedAssetV1Request.kt new file mode 100644 index 0000000000..81f8c3d286 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/validators/ValidatedClaimPledgedAssetV1Request.kt @@ -0,0 +1,26 @@ +package org.hyperledger.cacti.plugin.copm.validators + +import org.hyperledger.cacti.plugin.copm.types.DLAccount +import org.hyperledger.cacti.plugin.copm.types.DLAsset +import org.hyperledger.cacti.plugin.copm.server.validators.validateAccount +import org.hyperledger.cacti.plugin.copm.server.validators.validateAsset +import org.hyperledger.cacti.plugin.copm.server.validators.validateRequiredString +import org.hyperledger.cacti.plugin.copm.core.services.defaultservice.DefaultServiceOuterClass.ClaimPledgedAssetV1Request + +class ValidatedClaimPledgedAssetV1Request(val asset: DLAsset, + val sourceAccount: DLAccount, + val destinationAccount: DLAccount, + val sourceCert: String, + val destCert: String, + val pledgeId: String) { + + constructor(request: ClaimPledgedAssetV1Request) : this( + validateAsset(request.assetPledgeClaimV1PB.asset,"asset"), + validateAccount(request.assetPledgeClaimV1PB.source, "source"), + validateAccount(request.assetPledgeClaimV1PB.destination, "destination"), + request.assetPledgeClaimV1PB.sourceCertificate ?: "", + request.assetPledgeClaimV1PB.destCertificate ?: "", + validateRequiredString( request.assetPledgeClaimV1PB.pledgeId, "pledgeId") + ) + +} diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/validators/ValidatedGetVerifiedViewV1Request.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/validators/ValidatedGetVerifiedViewV1Request.kt new file mode 100644 index 0000000000..0eb92ddc0d --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/validators/ValidatedGetVerifiedViewV1Request.kt @@ -0,0 +1,17 @@ +package org.hyperledger.cacti.plugin.copm.validators + +import org.hyperledger.cacti.plugin.copm.types.DLAccount +import org.hyperledger.cacti.plugin.copm.types.DLTransactionParams +import org.hyperledger.cacti.plugin.copm.server.validators.validateAccount +import org.hyperledger.cacti.plugin.copm.server.validators.validateRequiredString +import org.hyperledger.cacti.plugin.copm.server.validators.validateViewRequest +import org.hyperledger.cacti.plugin.copm.core.services.defaultservice.DefaultServiceOuterClass + +class ValidatedGetVerifiedViewV1Request(val account : DLAccount, val cmd : DLTransactionParams, val remoteNetwork: String) { + constructor(request: DefaultServiceOuterClass.GetVerifiedViewV1Request) : this ( + validateAccount(request.getVerifiedViewV1RequestPB.account, "account"), + validateViewRequest(request.getVerifiedViewV1RequestPB.view?.viewAddress, "view.viewAddress"), + validateRequiredString(request.getVerifiedViewV1RequestPB.view.network, "view.network")) + { + } +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/validators/ValidatedLockAssetV1Request.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/validators/ValidatedLockAssetV1Request.kt new file mode 100644 index 0000000000..fceb3182d8 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/validators/ValidatedLockAssetV1Request.kt @@ -0,0 +1,28 @@ +package org.hyperledger.cacti.plugin.copm.validators +import org.hyperledger.cacti.plugin.copm.types.DLAccount +import org.hyperledger.cacti.plugin.copm.types.DLAsset +import org.hyperledger.cacti.plugin.copm.server.validators.validateAccount +import org.hyperledger.cacti.plugin.copm.server.validators.validateAsset +import org.hyperledger.cacti.plugin.copm.server.validators.validateHash +import org.hyperledger.cacti.plugin.copm.core.services.defaultservice.DefaultServiceOuterClass.LockAssetV1Request +import org.hyperledger.cacti.weaver.sdk.corda.HashFunctions + +class ValidatedLockAssetV1Request(val asset: DLAsset, + val sourceAccount: DLAccount, + val destAccount: DLAccount, + val hash: HashFunctions.Hash, + val sourceCert: String, + val destCert: String, + val expiryTimeFmt: Int, + val expiryTime: Long) { + constructor(req: LockAssetV1Request) : this( + validateAsset(req.assetLockV1PB.asset, "asset"), + validateAccount(req.assetLockV1PB.source, "source"), + validateAccount(req.assetLockV1PB.dest, "dest"), + validateHash(req.assetLockV1PB.hashInfo, "hashInfo"), + req.assetLockV1PB.sourceCertificate ?: "", + req.assetLockV1PB.destinationCertificate ?: "", + 1, + req.assetLockV1PB.expirySecs) + +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/validators/ValidatedPledgeAssetV1Request.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/validators/ValidatedPledgeAssetV1Request.kt new file mode 100644 index 0000000000..e2e609bb6a --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/validators/ValidatedPledgeAssetV1Request.kt @@ -0,0 +1,25 @@ +package org.hyperledger.cacti.plugin.copm.validators + +import org.hyperledger.cacti.plugin.copm.types.DLAccount +import org.hyperledger.cacti.plugin.copm.types.DLAsset +import org.hyperledger.cacti.plugin.copm.server.validators.validateAccount +import org.hyperledger.cacti.plugin.copm.server.validators.validateAsset +import org.hyperledger.cacti.plugin.copm.core.services.defaultservice.DefaultServiceOuterClass.PledgeAssetV1Request +import java.util.Calendar + +class ValidatedPledgeAssetV1Request(val asset: DLAsset, + val sourceAccount: DLAccount, + val destinationAccount: DLAccount, + val destinationCertificate: String, + val timeout: Long) { + + constructor(request: PledgeAssetV1Request) : this( + validateAsset(request.assetPledgeV1PB.asset,"asset"), + validateAccount(request.assetPledgeV1PB.source, "source"), + validateAccount(request.assetPledgeV1PB.destination, "destination"), + request.assetPledgeV1PB.destinationCertificate ?: "", + (Calendar.getInstance().timeInMillis / 1000) + (request.assetPledgeV1PB.expirySecs) + ) + +} + diff --git a/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/validators/common.kt b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/validators/common.kt new file mode 100644 index 0000000000..2e58a5e2df --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/kotlin/org/hyperledger/cacti/plugin/copm/validators/common.kt @@ -0,0 +1,54 @@ +package org.hyperledger.cacti.plugin.copm.server.validators + +import org.hyperledger.cacti.plugin.copm.core.HashInfoV1Pb.HashInfoV1PB +import org.hyperledger.cacti.plugin.copm.core.TransferrableAssetV1Pb.TransferrableAssetV1PB +import org.hyperledger.cacti.plugin.copm.core.AssetAccountV1Pb.AssetAccountV1PB +import org.hyperledger.cacti.plugin.copm.core.ViewAddressV1Pb.ViewAddressV1PB + +import org.hyperledger.cacti.plugin.copm.types.DLAsset; +import org.hyperledger.cacti.plugin.copm.types.DLAccount; +import org.hyperledger.cacti.plugin.copm.types.DLTransactionParams +import org.hyperledger.cacti.weaver.sdk.corda.HashFunctions + +fun validateRequiredString(str: String?, label: String) : String { + if ( str.isNullOrBlank() ) throw Exception("$label is required") + return str +} + +fun validateHash(hashInfo: HashInfoV1PB?, label: String) : HashFunctions.Hash { + if (hashInfo == null) { + throw Exception("$label is required") + } + val hash : HashFunctions.Hash = if( hashInfo.hashFcn == "SHA512") + HashFunctions.SHA512() + else + HashFunctions.SHA256() + + validateRequiredString(hashInfo.secret, "$label.secret") + hash.setPreimage(hashInfo.secret); + return hash; +} + +fun validateAccount(account: AssetAccountV1PB?, label: String) : DLAccount { + if (account == null) { throw Exception("$label is required") } + validateRequiredString(account.network, "$label.network") + validateRequiredString(account.userId, "$label.userId") + return DLAccount(account.network, account.userId); +} + +fun validateAsset(asset: TransferrableAssetV1PB?, label: String) : DLAsset { + if(asset == null) throw Exception("$label is required") + + if ( asset.assetId.isNullOrBlank() && asset.assetQuantity == 0) { + throw Exception("Either ${label}.assetId or ${label}.assetQuantity must be set"); + } + return DLAsset(asset); +} + +fun validateViewRequest(viewAddress: ViewAddressV1PB?, label: String) : DLTransactionParams { + if( viewAddress == null) throw Exception("$label is required"); + validateRequiredString(viewAddress.contractId, "$label.contractId") + validateRequiredString(viewAddress.function, "$label.function") + if( viewAddress.inputList == null) throw Exception("$label.input is required"); + return DLTransactionParams(viewAddress.contractId, viewAddress.function, viewAddress.inputList) +} diff --git a/packages/cacti-plugin-copm-corda/src/main/typescript/index.ts b/packages/cacti-plugin-copm-corda/src/main/typescript/index.ts new file mode 100644 index 0000000000..87cb558397 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/typescript/index.ts @@ -0,0 +1 @@ +export * from "./public-api"; diff --git a/packages/cacti-plugin-copm-corda/src/main/typescript/plugin-copm-corda.ts b/packages/cacti-plugin-copm-corda/src/main/typescript/plugin-copm-corda.ts new file mode 100644 index 0000000000..c3c3db6846 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/typescript/plugin-copm-corda.ts @@ -0,0 +1,78 @@ +import { + IPluginCrpcService, + ICactusPluginOptions, + ICactusPlugin, +} from "@hyperledger/cactus-core-api"; +import { + Logger, + LoggerProvider, + LogLevelDesc, +} from "@hyperledger/cactus-common"; +import { ICrpcSvcRegistration } from "@hyperledger/cactus-core-api"; +import { ServiceType } from "@bufbuild/protobuf"; +import { DefaultService } from "@hyperledger-cacti/cacti-copm-core"; +import { CopmCordaImpl, DefaultApi } from "./service-implementation"; +import { createGrpcTransport } from "@connectrpc/connect-node"; +import { createPromiseClient } from "@connectrpc/connect"; + +export interface IPluginCopmCordaOptions extends ICactusPluginOptions { + logLevel?: LogLevelDesc; + copmKotlinServerBaseUrl: string; +} + +export class PluginCopmCorda implements IPluginCrpcService, ICactusPlugin { + public static readonly CLASS_NAME = "PluginCopmCorda"; + private readonly instanceId: string; + private readonly logLevel: LogLevelDesc; + private readonly log: Logger; + private readonly options: IPluginCopmCordaOptions; + + constructor(public readonly opts: IPluginCopmCordaOptions) { + this.logLevel = opts.logLevel || "INFO"; + this.log = LoggerProvider.getOrCreate({ + level: this.logLevel, + label: "CopmCordaImpl", + }); + this.options = opts; + this.instanceId = this.opts.instanceId; + } + + public async createCrpcSvcRegistrations(): Promise< + ICrpcSvcRegistration[] + > { + const out: ICrpcSvcRegistration[] = []; + //await this.copmCordaContainer.start(); + + const transport = createGrpcTransport({ + // Requests will be made to /./method + baseUrl: this.opts.copmKotlinServerBaseUrl, + httpVersion: "2", + }); + const containerApi = createPromiseClient(DefaultService, transport); + + const implementation = new CopmCordaImpl( + this.log, + containerApi as DefaultApi, + ); + + const crpcSvcRegistration: ICrpcSvcRegistration = { + definition: DefaultService, + serviceName: DefaultService.typeName, + implementation, + }; + out.push(crpcSvcRegistration); + return out; + } + + public getInstanceId(): string { + return this.instanceId; + } + + public getPackageName(): string { + return `@hyperledger-cacti/cacti-plugin-copm-corda`; + } + + public async onPluginInit(): Promise { + return; + } +} diff --git a/packages/cacti-plugin-copm-corda/src/main/typescript/plugin-factory-copm-corda.ts b/packages/cacti-plugin-copm-corda/src/main/typescript/plugin-factory-copm-corda.ts new file mode 100644 index 0000000000..2cb7266a1c --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/typescript/plugin-factory-copm-corda.ts @@ -0,0 +1,16 @@ +import { + IPluginFactoryOptions, + PluginFactory, +} from "@hyperledger/cactus-core-api"; + +import { IPluginCopmCordaOptions, PluginCopmCorda } from "./plugin-copm-corda"; + +export class PluginFactoryCopmCorda extends PluginFactory< + PluginCopmCorda, + IPluginCopmCordaOptions, + IPluginFactoryOptions +> { + async create(options: IPluginCopmCordaOptions): Promise { + return new PluginCopmCorda(options); + } +} diff --git a/packages/cacti-plugin-copm-corda/src/main/typescript/public-api.ts b/packages/cacti-plugin-copm-corda/src/main/typescript/public-api.ts new file mode 100644 index 0000000000..1db836fa49 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/typescript/public-api.ts @@ -0,0 +1,10 @@ +export { PluginCopmCorda, IPluginCopmCordaOptions } from "./plugin-copm-corda"; + +import { IPluginFactoryOptions } from "@hyperledger/cactus-core-api"; +import { PluginFactoryCopmCorda } from "./plugin-factory-copm-corda"; + +export async function createPluginFactory( + pluginFactoryOptions: IPluginFactoryOptions, +): Promise { + return new PluginFactoryCopmCorda(pluginFactoryOptions); +} diff --git a/packages/cacti-plugin-copm-corda/src/main/typescript/service-implementation.ts b/packages/cacti-plugin-copm-corda/src/main/typescript/service-implementation.ts new file mode 100644 index 0000000000..799376f4b2 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/main/typescript/service-implementation.ts @@ -0,0 +1,75 @@ +import { Logger } from "@hyperledger/cactus-common"; +import { ServiceImpl, PromiseClient } from "@connectrpc/connect"; + +import type { ServiceType } from "@bufbuild/protobuf"; +import { + DefaultService, + PledgeAssetV1Request, + PledgeAssetV1200ResponsePB, + ClaimPledgedAssetV1Request, + LockAssetV1Request, + GetVerifiedViewV1Request, + GetVerifiedViewV1200ResponsePB, + LockAssetV1200ResponsePB, + ClaimLockedAssetV1Request, + ClaimPledgedAssetV1200ResponsePB, +} from "@hyperledger-cacti/cacti-copm-core"; + +type DefaultServiceMethodDefinitions = typeof DefaultService.methods; +type DefaultServiceMethodNames = keyof DefaultServiceMethodDefinitions; +export type DefaultApi = PromiseClient; + +type ICopmCordaApi = { + [key in DefaultServiceMethodNames]: (...args: never[]) => unknown; +}; + +export class CopmCordaImpl + implements ICopmCordaApi, Partial> +{ + // We cannot avoid this due to how the types of the upstream library are + // structured/designed hence we just disable the linter on this particular line. + // eslint-disable-next-line @typescript-eslint/no-explicit-any + [k: string]: any; + + private readonly log: Logger; + private readonly containerApi: DefaultApi; + + constructor(log: Logger, containerApi: DefaultApi) { + this.log = log; + this.containerApi = containerApi; + } + + public async noopV1(): Promise { + return; + } + + public async pledgeAssetV1( + req: PledgeAssetV1Request, + ): Promise { + return this.containerApi.pledgeAssetV1(req); + } + + public async claimLockedAssetV1( + req: ClaimLockedAssetV1Request, + ): Promise { + return this.containerApi.claimLockedAssetV1(req); + } + + public async claimPledgedAssetV1( + req: ClaimPledgedAssetV1Request, + ): Promise { + return this.containerApi.claimPledgedAssetV1(req); + } + + public async lockAssetV1( + req: LockAssetV1Request, + ): Promise { + return this.containerApi.lockAssetV1(req); + } + + public async getVerifiedViewV1( + req: GetVerifiedViewV1Request, + ): Promise { + return this.containerApi.getVerifiedViewV1(req); + } +} diff --git a/packages/cacti-plugin-copm-corda/src/test/kotlin/Dockerfile b/packages/cacti-plugin-copm-corda/src/test/kotlin/Dockerfile new file mode 100644 index 0000000000..40ed946f2a --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/test/kotlin/Dockerfile @@ -0,0 +1,43 @@ +FROM gradle:8.1.1-jdk17-jammy AS builder + +WORKDIR / +COPY src/test/kotlin/com /kotlin-spring/src/test/kotlin/com +COPY src/main/kotlin/org /kotlin-spring/src/main/kotlin/org +COPY src/test/kotlin/localdeps /kotlin-spring/src/test/kotlin/localdeps +COPY src/test/kotlin/build.gradle /kotlin-spring/src/test/kotlin +COPY src/test/kotlin/settings.gradle /kotlin-spring/src/test/kotlin +COPY src/test/kotlin/gradle.properties /kotlin-spring/src/test/kotlin +WORKDIR /kotlin-spring/src/test/kotlin + +RUN gradle clean build +WORKDIR / + +FROM openjdk:24-slim-bookworm + +ARG APP=/usr/src/app +ENV APP=/usr/src/app + +RUN apt update +RUN apt install -y ca-certificates tzdata curl tini iputils-ping netcat-openbsd +RUN rm -rf /var/lib/apt/lists/* + +ENV TZ=Etc/UTC \ + APP_USER=appuser + +RUN groupadd $APP_USER \ + && useradd -g $APP_USER $APP_USER \ + && mkdir -p ${APP} + +COPY --from=builder /kotlin-spring/src/test/kotlin/build/libs/ ${APP}/kotlin-spring/build/libs/ + +RUN chown -R $APP_USER:$APP_USER ${APP} + +USER $APP_USER +WORKDIR ${APP} + +COPY src/test/kotlin/start-app.sh / + +EXPOSE 9090 + +ENTRYPOINT ["/usr/bin/tini", "--"] +CMD ["/start-app.sh"] diff --git a/packages/cacti-plugin-copm-corda/src/test/kotlin/Makefile b/packages/cacti-plugin-copm-corda/src/test/kotlin/Makefile new file mode 100644 index 0000000000..6d34bec5d0 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/test/kotlin/Makefile @@ -0,0 +1,23 @@ +WORKSPACE ?= $(shell realpath `pwd`/../../../../../) + + +build-corda-copm-server-deps: + # also need to build the fabric interop helper as it is used in the copm impl + rm -Rf $(WORKSPACE)/weaver/sdks/fabric/interoperation-node-sdk/build + cd $(WORKSPACE)/weaver/sdks/fabric/interoperation-node-sdk && make build-local + cd $(WORKSPACE)/weaver/common/protos-java-kt && make build + cd $(WORKSPACE)/weaver/core/network/corda-interop-app && make build-local + cd $(WORKSPACE)/weaver/sdks/corda && make build + cd $(WORKSPACE)/weaver/samples/corda/corda-simple-application && make build-local + cd $(WORKSPACE)/packages/cacti-copm-core/src/main/protos-kt && ./gradlew build + mkdir -p localdeps && \ + cp $(WORKSPACE)/packages/cacti-copm-core/src/main/protos-kt/build/libs/copm-corda-*jar localdeps && \ + cp $(WORKSPACE)/weaver/common/protos-java-kt/build/libs/protos-java-kt-*.jar localdeps && \ + cp $(WORKSPACE)/weaver/sdks/corda/build/libs/weaver-sdk-corda-*.jar localdeps && \ + cp $(WORKSPACE)/weaver/core/network/corda-interop-app/interop-workflows/build/libs/interop-workflows-*.jar localdeps && \ + cp $(WORKSPACE)/weaver/core/network/corda-interop-app/interop-contracts/build/libs/interop-contracts-*.jar localdeps && \ + cp $(WORKSPACE)/weaver/samples/corda/corda-simple-application/contracts-kotlin/build/libs/contracts-kotlin-*.jar localdeps && \ + cp $(WORKSPACE)/weaver/samples/corda/corda-simple-application/workflows-kotlin/build/libs/workflows-kotlin-*.jar localdeps + +build-image-local: build-corda-copm-server-deps + cd $(WORKSPACE)/packages/cacti-plugin-copm-corda && DOCKER_BUILDKIT=1 docker build . -f src/test/kotlin/Dockerfile --tag copm-corda diff --git a/packages/cacti-plugin-copm-corda/src/test/kotlin/build.gradle b/packages/cacti-plugin-copm-corda/src/test/kotlin/build.gradle new file mode 100644 index 0000000000..54df4704b9 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/test/kotlin/build.gradle @@ -0,0 +1,112 @@ + +buildscript { + repositories { + mavenCentral() + } +} + +plugins { +// id 'com.github.johnrengelman.shadow' version '5.0.0' + id "java" + id "idea" + id "application" + id 'org.jetbrains.kotlin.jvm' version "$kotlin_version" + id "org.jetbrains.kotlin.plugin.jpa" version "$kotlin_version" + id "org.jetbrains.kotlin.plugin.spring" version "$kotlin_version" + id "org.springframework.boot" version "3.0.2" + id "io.spring.dependency-management" version "1.0.14.RELEASE" + +} + +sourceSets { + main { + resources { + srcDir rootProject.file("config/dev") + } + kotlin.srcDirs += ['../../main/kotlin', '.' ] + } +} + +Properties constants = new Properties() + +repositories { + google() + mavenCentral() + mavenLocal() + maven { url "https://download.corda.net/maven/corda-dependencies" } // access to the patched Quasar and Caffeine version +} + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" + implementation 'com.google.code.gson:gson:2.8.6' + + // Corda dependencies. + implementation "$corda_core_release_group:corda-core:$corda_core_release_version" + implementation "$corda_release_group:corda-node-api:$corda_release_version" + implementation "$corda_release_group:corda:$corda_release_version" + implementation "$corda_release_group:corda-rpc:$corda_release_version" + + implementation "io.arrow-kt:arrow-core:$arrow_version" + implementation "io.arrow-kt:arrow-fx:$arrow_version" + implementation "io.arrow-kt:arrow-syntax:$arrow_version" + + // gRPC and protobuf dependencies + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" + implementation "io.grpc:grpc-kotlin-stub:$grpc_kotlin_version" + implementation "io.grpc:grpc-netty-shaded:$grpc_version" + implementation "io.grpc:grpc-stub:$grpc_version" + implementation "io.grpc:grpc-okhttp:$grpc_version" + implementation "io.grpc:grpc-protobuf:$grpc_version" + implementation group: 'org.json', name: 'json', version: '20190722' + + implementation "org.springframework.boot:spring-boot-starter-parent:3.0.4" + implementation "org.springframework.boot:spring-boot-maven-plugin:3.0.4" + implementation "org.springframework.boot:spring-boot-starter" + implementation "org.springframework.boot:spring-boot-starter-web" + annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" + implementation "net.devh:grpc-spring-boot-starter:2.14.0.RELEASE" + implementation "jakarta.validation:jakarta.validation-api" + implementation "jakarta.annotation:jakarta.annotation-api:2.1.0" + + + //// Logger dependencies + implementation "org.slf4j:slf4j-simple:1.6.1" + +} + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + +compileJava { + options.compilerArgs << '-parameters' +} + +jar { + // This makes the JAR's SHA-256 hash repeatable. + preserveFileTimestamps = false + reproducibleFileOrder = true + + dependencies { + implementation files("./localdeps/copm-corda-" + version + ".jar") + implementation files("./localdeps/protos-java-kt-" + version + ".jar") + implementation files("./localdeps/weaver-sdk-corda-" + version + ".jar") + implementation files("./localdeps/interop-workflows-" + version + ".jar") + implementation files("./localdeps/interop-contracts-" + version + ".jar") + implementation files("./localdeps/contracts-kotlin-" + weaver_sample_contracts_version + ".jar") + implementation files("./localdeps/workflows-kotlin-" + weaver_sample_contracts_version + ".jar") + } + + manifest { + attributes( + 'Main-Class': "com.copmCorda.MainClassKt" + ) + } +} + +application { + mainClass = 'com.copmCorda.MainClassKt' +} + diff --git a/packages/cacti-plugin-copm-corda/src/test/kotlin/com/copmCorda/MainClass.kt b/packages/cacti-plugin-copm-corda/src/test/kotlin/com/copmCorda/MainClass.kt new file mode 100755 index 0000000000..47be742bdf --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/test/kotlin/com/copmCorda/MainClass.kt @@ -0,0 +1,14 @@ +package com.copmCorda +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.context.properties.ConfigurationPropertiesScan +import org.springframework.boot.runApplication + +@SpringBootApplication(scanBasePackages = ["com.copmCorda", "org.hyperledger.cacti.plugin.copm"]) +@ConfigurationPropertiesScan +class CopmCordaApplication + + +fun main(args: Array) { + runApplication(*args) +} + diff --git a/packages/cacti-plugin-copm-corda/src/test/kotlin/com/copmCorda/SampleCordaConfiguration.kt b/packages/cacti-plugin-copm-corda/src/test/kotlin/com/copmCorda/SampleCordaConfiguration.kt new file mode 100644 index 0000000000..6117483f0d --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/test/kotlin/com/copmCorda/SampleCordaConfiguration.kt @@ -0,0 +1,71 @@ +package com.copmCorda + +import org.json.JSONObject +import net.corda.core.utilities.loggerFor +import org.springframework.stereotype.Component +import com.cordaSimpleApplication.contract.AssetContract +import com.cordaSimpleApplication.contract.BondAssetContract +import org.hyperledger.cacti.plugin.copm.types.DLAccount +import org.hyperledger.cacti.plugin.copm.types.DLAsset +import org.hyperledger.cacti.plugin.copm.corda.CordaAssetContract +import org.hyperledger.cacti.plugin.copm.corda.CordaParty +import org.hyperledger.cacti.plugin.copm.interfaces.CordaConfiguration +import org.hyperledger.cacti.plugin.copm.corda.NodeRPCConnection + +@Component +class SampleCordaConfiguration : CordaConfiguration { + override val copmContract = "org.hyperledger.cacti.weaver.imodule.corda.flows" + + companion object { + + val logger = loggerFor() + private val exampleNFTAssetInfo = CordaAssetContract( + "com.cordaSimpleApplication.flow.RetrieveBondAssetStateAndRef", + "com.cordaSimpleApplication.flow.GetSimpleBondAssetStateAndContractId", + "com.cordaSimpleApplication.flow.UpdateBondAssetOwnerFromPointer", + BondAssetContract.Commands.Issue(), + BondAssetContract.Commands.Delete() + ) + private val exampleFungibleAssetInfo = CordaAssetContract( + "com.cordaSimpleApplication.flow.RetrieveStateAndRef", + "com.cordaSimpleApplication.flow.GetSimpleAssetStateAndContractId", + "com.cordaSimpleApplication.flow.UpdateAssetOwnerFromPointer", + AssetContract.Commands.Issue(), + AssetContract.Commands.Delete() + ) + } + + override fun assetContract(asset: DLAsset) : CordaAssetContract { + return if (asset.isNFT) exampleNFTAssetInfo else exampleFungibleAssetInfo; + } + + + override fun getIssuer(asset: DLAsset) : CordaParty { + return CordaParty("O=PartyA,L=London,C=GB") + } + + override fun getRPC(account: DLAccount) : NodeRPCConnection { + val accountKey = "${account.accountId}@${account.organization}" + logger.debug("connecting $accountKey") + val networksConfigJSON: JSONObject + val rpcStr = System.getenv("COPM_CORDA_RPC") ?: "{}" + networksConfigJSON = JSONObject(rpcStr) + + if (!networksConfigJSON.has(accountKey)) { + throw IllegalStateException("ENV VAR COPM_CORDA_RPC configuration of networkID $accountKey.") + } + + val accountJson = networksConfigJSON.getJSONObject(accountKey) + val host = accountJson.getString("host") + val port = accountJson.getInt("port") + val username = accountJson.getString("username") + val password = accountJson.getString("password") + logger.debug("connecting to $host:${port.toString()}") + return NodeRPCConnection(host, username, password, port) + } + + override fun getObservers(account: DLAccount) : List { + return emptyList(); + } + +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/test/kotlin/com/copmCorda/SampleInteropConfig.kt b/packages/cacti-plugin-copm-corda/src/test/kotlin/com/copmCorda/SampleInteropConfig.kt new file mode 100644 index 0000000000..ea5718b76b --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/test/kotlin/com/copmCorda/SampleInteropConfig.kt @@ -0,0 +1,119 @@ +package com.copmCorda + +import org.hyperledger.cacti.plugin.copm.interfaces.InteropConfig +import org.hyperledger.cacti.plugin.copm.interop.RelayConfig +import org.hyperledger.cacti.plugin.copm.interop.RemoteCopmContract +import org.hyperledger.cacti.plugin.copm.interop.RemoteNetworkConfig +import org.hyperledger.cacti.plugin.copm.interop.ViewAddressFormat +import org.hyperledger.cacti.plugin.copm.interop.fabric.ViewAddressFabric +import org.hyperledger.cacti.plugin.copm.interop.corda.ViewAddressCorda +import org.hyperledger.cacti.plugin.copm.types.DLAsset +import com.copmCorda.interop.corda.RemoteCopmContractCordaFungible +import com.copmCorda.interop.corda.RemoteCopmContractCordaNFT +import com.copmCorda.interop.fabric.RemoteCopmContractFabricFungible +import com.copmCorda.interop.fabric.RemoteCopmContractFabricNFT +import org.hyperledger.cacti.weaver.sdk.corda.RelayOptions +import org.json.JSONObject +import org.springframework.stereotype.Component +import net.corda.core.utilities.loggerFor +import kotlin.reflect.KClass + +@Component +class SampleInteropConfig : InteropConfig { + + companion object { + val logger = loggerFor() + val remoteCopmContracts = listOf( + RemoteCopmContractFabricNFT(), + RemoteCopmContractFabricFungible(), + RemoteCopmContractCordaNFT(), + RemoteCopmContractCordaFungible() + ) + val viewAddressFormats: Map> = mapOf( + "corda" to ViewAddressCorda::class, + "fabric" to ViewAddressFabric::class + ) + } + + override fun getRelayConfig(localNetwork: String): RelayConfig { + val relayConfigJSON = JSONObject(System.getenv("COPM_RELAY_CONFIG")) + + if (!relayConfigJSON.has(localNetwork)) { + throw IllegalStateException("env var COPM_RELAY_CONFIG doesn't contain the configuration of networkID $localNetwork.") + } + + val netConfigJson = relayConfigJSON.getJSONObject(localNetwork) + val localRelayEndpoint: String = netConfigJson.getString("relayEndpoint") + logger.debug("messages from ${localNetwork} will be sent to ${localRelayEndpoint}") + return RelayConfig(localRelayEndpoint, this.relayOptions()) + } + + override fun getViewAddressFormat(remoteNetwork: String) : ViewAddressFormat { + val networkConfig = this.getRemoteNetworkConfig(remoteNetwork) + if (! viewAddressFormats.contains(networkConfig.networkType)) { + throw IllegalStateException("no view address formatter found for $remoteNetwork") + } + val clazz = viewAddressFormats[networkConfig.networkType] + return clazz!!.constructors.first().call(networkConfig) as ViewAddressFormat; + } + + override fun getRemoteCopmContract(remoteNetwork: String, asset: DLAsset) : RemoteCopmContract { + val networkConfig = this.getRemoteNetworkConfig(remoteNetwork) + for (contract in remoteCopmContracts) { + if (contract.matchesNetworkTypeAndAsset(networkConfig.networkType, asset)) { + return contract + } + } + throw IllegalStateException("no contract found for $remoteNetwork matching asset ${asset.assetType}") + } + + override fun getRemoteNetworkConfig(remoteNetwork: String): RemoteNetworkConfig { + val netConfigJson = remoteNetworkJson(remoteNetwork) + logger.debug("getting configuration for $remoteNetwork") + logger.debug(netConfigJson.toString()) + val relayEndpoint: String = netConfigJson.getString("relayEndpoint") + val networkType: String = netConfigJson.getString("type") + logger.debug("$remoteNetwork is of type $networkType") + + if (networkType == "corda") { + return RemoteNetworkConfig( + remoteNetwork, + networkType, + relayEndpoint, + "", + listOf(netConfigJson.getString("partyEndPoint")) + ) + } else { + return RemoteNetworkConfig( + remoteNetwork, + networkType, + relayEndpoint, + netConfigJson.getString("channelName"), + emptyList() + ) + } + } + + private fun remoteNetworkJson(networkID: String): JSONObject { + val networksConfigJSON = JSONObject(System.getenv("COPM_REMOTE_CONFIG")) + + // throw exception if the networkID is not present in the file + if (!networksConfigJSON.has(networkID)) { + throw IllegalStateException("env var COPM_REMOTE_CONFIG doesn't contain the configuration of networkID $networkID.") + } + return networksConfigJSON.getJSONObject(networkID) + } + + private fun relayOptions(): RelayOptions { + val relayTLS = System.getenv("RELAY_TLS") ?: "false" + val relayTrustStore = System.getenv("RELAY_TLSCA_TRUST_STORE") ?: "" + val relayTrustStorePassword = System.getenv("RELAY_TLSCA_TRUST_STORE_PASSWORD") ?: "" + val relayCertPaths = System.getenv("RELAY_TLSCA_CERT_PATHS") ?: "" + return RelayOptions( + useTlsForRelay = relayTLS.toBoolean(), + relayTlsTrustStorePath = relayTrustStore, + relayTlsTrustStorePassword = relayTrustStorePassword, + tlsCACertPathsForRelay = relayCertPaths + ) + } +} diff --git a/packages/cacti-plugin-copm-corda/src/test/kotlin/com/copmCorda/interop/corda/RemoteCopmContractCordaFungible.kt b/packages/cacti-plugin-copm-corda/src/test/kotlin/com/copmCorda/interop/corda/RemoteCopmContractCordaFungible.kt new file mode 100644 index 0000000000..5cdbd7ff1f --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/test/kotlin/com/copmCorda/interop/corda/RemoteCopmContractCordaFungible.kt @@ -0,0 +1,18 @@ +package com.copmCorda.interop.corda + +import org.hyperledger.cacti.plugin.copm.interop.RemoteCopmContract +import org.hyperledger.cacti.plugin.copm.types.DLAsset +import org.hyperledger.cacti.plugin.copm.types.DLTransactionParams +import org.hyperledger.cacti.plugin.copm.validators.ValidatedClaimPledgedAssetV1Request + +class RemoteCopmContractCordaFungible : RemoteCopmContract { + override fun matchesNetworkTypeAndAsset(networkType: String, asset: DLAsset): Boolean { + return networkType == "corda" && ! asset.isNFT + } + + override fun getPledgeInfoCmd(claim: ValidatedClaimPledgedAssetV1Request): DLTransactionParams { + return DLTransactionParams("com.cordaSimpleApplication.flow", + "GetAssetPledgeStatusByPledgeId", + listOf(claim.pledgeId, claim.destinationAccount.organization)) + } +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/test/kotlin/com/copmCorda/interop/corda/RemoteCopmContractCordaNFT.kt b/packages/cacti-plugin-copm-corda/src/test/kotlin/com/copmCorda/interop/corda/RemoteCopmContractCordaNFT.kt new file mode 100644 index 0000000000..63507121c7 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/test/kotlin/com/copmCorda/interop/corda/RemoteCopmContractCordaNFT.kt @@ -0,0 +1,19 @@ +package com.copmCorda.interop.corda + +import org.hyperledger.cacti.plugin.copm.interop.RemoteCopmContract +import org.hyperledger.cacti.plugin.copm.types.DLAsset +import org.hyperledger.cacti.plugin.copm.types.DLTransactionParams +import org.hyperledger.cacti.plugin.copm.validators.ValidatedClaimPledgedAssetV1Request + +class RemoteCopmContractCordaNFT : RemoteCopmContract { + + override fun matchesNetworkTypeAndAsset(networkType: String, asset: DLAsset): Boolean { + return networkType == "corda" && asset.isNFT + } + + override fun getPledgeInfoCmd(claim: ValidatedClaimPledgedAssetV1Request): DLTransactionParams { + return DLTransactionParams("com.cordaSimpleApplication.flow", + "GetBondAssetPledgeStatusByPledgeId", + listOf(claim.pledgeId, claim.destinationAccount.organization)) + } +} diff --git a/packages/cacti-plugin-copm-corda/src/test/kotlin/com/copmCorda/interop/fabric/RemoteCopmContractFabricFungible.kt b/packages/cacti-plugin-copm-corda/src/test/kotlin/com/copmCorda/interop/fabric/RemoteCopmContractFabricFungible.kt new file mode 100644 index 0000000000..d5b93263d4 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/test/kotlin/com/copmCorda/interop/fabric/RemoteCopmContractFabricFungible.kt @@ -0,0 +1,21 @@ +package com.copmCorda.interop.fabric + +import org.hyperledger.cacti.plugin.copm.interop.RemoteCopmContract +import org.hyperledger.cacti.plugin.copm.types.DLAsset +import org.hyperledger.cacti.plugin.copm.types.DLTransactionParams +import org.hyperledger.cacti.plugin.copm.validators.ValidatedClaimPledgedAssetV1Request + +class RemoteCopmContractFabricFungible : RemoteCopmContract { + + override fun matchesNetworkTypeAndAsset(networkType: String, asset: DLAsset): Boolean { + return networkType == "fabric" && ! asset.isNFT + } + override fun getPledgeInfoCmd(claim: ValidatedClaimPledgedAssetV1Request): DLTransactionParams { + val params = listOf(claim.pledgeId, + claim.sourceCert, + claim.destinationAccount.organization, + claim.destCert) + return DLTransactionParams("simpleassettransfer","GetTokenAssetPledgeStatus", params ) + } + +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-corda/src/test/kotlin/com/copmCorda/interop/fabric/RemoteCopmContractFabricNFT.kt b/packages/cacti-plugin-copm-corda/src/test/kotlin/com/copmCorda/interop/fabric/RemoteCopmContractFabricNFT.kt new file mode 100644 index 0000000000..66e96f6f40 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/test/kotlin/com/copmCorda/interop/fabric/RemoteCopmContractFabricNFT.kt @@ -0,0 +1,23 @@ +package com.copmCorda.interop.fabric + +import org.hyperledger.cacti.plugin.copm.interop.RemoteCopmContract +import org.hyperledger.cacti.plugin.copm.types.DLAsset +import org.hyperledger.cacti.plugin.copm.types.DLTransactionParams +import org.hyperledger.cacti.plugin.copm.validators.ValidatedClaimPledgedAssetV1Request + +class RemoteCopmContractFabricNFT : RemoteCopmContract { + + override fun matchesNetworkTypeAndAsset(networkType: String, asset: DLAsset): Boolean { + return networkType == "fabric" && asset.isNFT + } + + override fun getPledgeInfoCmd(claim: ValidatedClaimPledgedAssetV1Request): DLTransactionParams { + return DLTransactionParams("simpleassettransfer", + "GetAssetPledgeStatus", + listOf(claim.pledgeId, + claim.sourceCert, + claim.destinationAccount.organization, + claim.destCert ) ) + } + +} diff --git a/packages/cacti-plugin-copm-corda/src/test/kotlin/gradle.properties b/packages/cacti-plugin-copm-corda/src/test/kotlin/gradle.properties new file mode 100644 index 0000000000..d50d97269c --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/test/kotlin/gradle.properties @@ -0,0 +1,25 @@ +name=Test +group=com.cordaCopmClient +version=2.0.0 +weaver_sample_contracts_version=0.4 +kotlin.incremental=false +corda_release_group=net.corda +corda_core_release_group=net.corda +corda_release_version=4.12 +corda_core_release_version=4.12 +corda_core_version=4.12 +gradle_plugin_version=5.1.1 +protobuf_version=0.9.4 +kotlin_version=1.9.23 +junitVersion=4.12 +log4jVersion=2.23.1 +platformVersion=140 +slf4jVersion=2.0.12 +nettyVersion=4.1.77.Final +cordaTokenSDKGroup=com.r3.corda.lib.tokens +cordaTokenSDKVersion=1.3-RC02 +arrow_version=0.10.4 +grpc_version=1.65.0 +grpc_kotlin_version=1.4.1 +coroutines_version=1.8.1 + diff --git a/packages/cacti-plugin-copm-corda/src/test/kotlin/gradle/libs.versions.toml b/packages/cacti-plugin-copm-corda/src/test/kotlin/gradle/libs.versions.toml new file mode 100644 index 0000000000..8bb21088bb --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/test/kotlin/gradle/libs.versions.toml @@ -0,0 +1,28 @@ +# This file was generated by the Gradle 'init' task. +# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format + +[versions] +com-fasterxml-jackson-dataformat-jackson-dataformat-xml = "2.15.2" +com-fasterxml-jackson-dataformat-jackson-dataformat-yaml = "2.15.2" +com-fasterxml-jackson-datatype-jackson-datatype-jsr310 = "2.15.2" +com-fasterxml-jackson-module-jackson-module-kotlin = "2.15.2" +com-google-code-findbugs-jsr305 = "3.0.2" +jakarta-annotation-jakarta-annotation-api = "2.1.0" +jakarta-validation-jakarta-validation-api = "3.0.2" +org-jetbrains-kotlin-kotlin-reflect = "1.7.10" +org-jetbrains-kotlin-kotlin-stdlib-jdk8 = "1.7.10" +org-jetbrains-kotlin-kotlin-test-junit5 = "1.7.10" +org-springframework-boot-spring-boot-starter-web = "3.1.3" + +[libraries] +com-fasterxml-jackson-dataformat-jackson-dataformat-xml = { module = "com.fasterxml.jackson.dataformat:jackson-dataformat-xml", version.ref = "com-fasterxml-jackson-dataformat-jackson-dataformat-xml" } +com-fasterxml-jackson-dataformat-jackson-dataformat-yaml = { module = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml", version.ref = "com-fasterxml-jackson-dataformat-jackson-dataformat-yaml" } +com-fasterxml-jackson-datatype-jackson-datatype-jsr310 = { module = "com.fasterxml.jackson.datatype:jackson-datatype-jsr310", version.ref = "com-fasterxml-jackson-datatype-jackson-datatype-jsr310" } +com-fasterxml-jackson-module-jackson-module-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "com-fasterxml-jackson-module-jackson-module-kotlin" } +com-google-code-findbugs-jsr305 = { module = "com.google.code.findbugs:jsr305", version.ref = "com-google-code-findbugs-jsr305" } +jakarta-annotation-jakarta-annotation-api = { module = "jakarta.annotation:jakarta.annotation-api", version.ref = "jakarta-annotation-jakarta-annotation-api" } +jakarta-validation-jakarta-validation-api = { module = "jakarta.validation:jakarta.validation-api", version.ref = "jakarta-validation-jakarta-validation-api" } +org-jetbrains-kotlin-kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "org-jetbrains-kotlin-kotlin-reflect" } +org-jetbrains-kotlin-kotlin-stdlib-jdk8 = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "org-jetbrains-kotlin-kotlin-stdlib-jdk8" } +org-jetbrains-kotlin-kotlin-test-junit5 = { module = "org.jetbrains.kotlin:kotlin-test-junit5", version.ref = "org-jetbrains-kotlin-kotlin-test-junit5" } +org-springframework-boot-spring-boot-starter-web = { module = "org.springframework.boot:spring-boot-starter-web", version.ref = "org-springframework-boot-spring-boot-starter-web" } diff --git a/packages/cacti-plugin-copm-corda/src/test/kotlin/gradle/wrapper/gradle-wrapper.jar b/packages/cacti-plugin-copm-corda/src/test/kotlin/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..e6441136f3 Binary files /dev/null and b/packages/cacti-plugin-copm-corda/src/test/kotlin/gradle/wrapper/gradle-wrapper.jar differ diff --git a/packages/cacti-plugin-copm-corda/src/test/kotlin/gradle/wrapper/gradle-wrapper.properties b/packages/cacti-plugin-copm-corda/src/test/kotlin/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..a4413138c9 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/test/kotlin/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/packages/cacti-plugin-copm-corda/src/test/kotlin/gradlew b/packages/cacti-plugin-copm-corda/src/test/kotlin/gradlew new file mode 100755 index 0000000000..b740cf1339 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/test/kotlin/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/packages/cacti-plugin-copm-corda/src/test/kotlin/repositories.gradle b/packages/cacti-plugin-copm-corda/src/test/kotlin/repositories.gradle new file mode 100644 index 0000000000..ee4e0ee0da --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/test/kotlin/repositories.gradle @@ -0,0 +1,8 @@ +repositories { + mavenLocal() + mavenCentral() + maven { url 'https://jitpack.io' } + maven { url 'https://download.corda.net/maven/corda-dependencies' } + maven { url 'https://download.corda.net/maven/corda-releases' } + maven { url 'https://repo.gradle.org/gradle/libs-releases' } +} diff --git a/packages/cacti-plugin-copm-corda/src/test/kotlin/settings.gradle b/packages/cacti-plugin-copm-corda/src/test/kotlin/settings.gradle new file mode 100644 index 0000000000..1ec17e37c1 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/test/kotlin/settings.gradle @@ -0,0 +1,7 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * This project uses @Incubating APIs which are subject to change. + */ + +rootProject.name = 'copm-corda' diff --git a/packages/cacti-plugin-copm-corda/src/test/kotlin/start-app.sh b/packages/cacti-plugin-copm-corda/src/test/kotlin/start-app.sh new file mode 100755 index 0000000000..c7341462ac --- /dev/null +++ b/packages/cacti-plugin-copm-corda/src/test/kotlin/start-app.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# Without these we get crashes on JDK 17 an above since the introduction of the +# Java Modules system. + +for i in 1 2 3; do java -jar ${APP}/kotlin-spring/build/libs/copm-corda-2.0.0.jar && break || sleep 5; done diff --git a/packages/cacti-plugin-copm-corda/tsconfig.json b/packages/cacti-plugin-copm-corda/tsconfig.json new file mode 100644 index 0000000000..0c9c1f1db8 --- /dev/null +++ b/packages/cacti-plugin-copm-corda/tsconfig.json @@ -0,0 +1,35 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "composite": true, + "outDir": "./dist/lib/", + "declarationDir": "dist/lib", + "resolveJsonModule": true, + "rootDir": "./src", + "strict": false /* Enable all strict type-checking options. */, + "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */ + + "tsBuildInfoFile": "../../.build-cache/cacti-plugin-copm-corda.tsbuildinfo" + }, + "include": [ + "./src", + "src/**/*.json" + ], + "references": [ + { + "path": "../cacti-copm-core/tsconfig.json" + }, + { + "path": "../cactus-common/tsconfig.json" + }, + { + "path": "../cactus-core/tsconfig.json" + }, + { + "path": "../cactus-core-api/tsconfig.json" + }, + { + "path": "../cactus-test-tooling/tsconfig.json" + } + ] +} \ No newline at end of file diff --git a/packages/cacti-plugin-copm-fabric/README.md b/packages/cacti-plugin-copm-fabric/README.md index a647229d98..a29cb9fec0 100644 --- a/packages/cacti-plugin-copm-fabric/README.md +++ b/packages/cacti-plugin-copm-fabric/README.md @@ -3,7 +3,7 @@ This cactus plugin implements a connectRPC server for the fabric COPM implementation. Command documentation as OpenAPI: -https://jenniferlianne.github.io/cacti/references/openapi/cacti-copm-core_openapi/ +https://hyperledger-cacti.github.io/cacti/references/openapi/cacti-copm-core_openapi/ These endpoints require the following: @@ -28,28 +28,21 @@ The following application-specific interfaces must be implemented: - FabricConfiguration - getConnectionProfile(orgKey: string): object; - - getContractContext(orgKey: string): Promise; - - getOrgWallet(orgKey: string): Promise; + - getContractContext(orgKey: string): Promise\; + - getOrgWallet(orgKey: string): Promise\; - InteropConfiguration (from cacti-copm-common) - getLocalRelayConfig(orgKey: string): LocalRelayConfig; - getRemoteNetworkConfig(remoteOrgKey: string): RemoteNetworkConfig; + - getRemotePledgeStatusCmd(remoteOrgKey: string, ValidatedClaimPledgedAssetRequest): DLTransactionParams; + These implementations are then supplied to the plugin constructor. ## Development -A Makefile is provided which will build a docker weaver network with the following commands: +Please see [the cacti-cop-test README](./../cacti-copm-test/README.md) for details on building a +fabric test network. -- make setup - - build all weaver components -- make pledge-network - - makes a network for running pledge/claim (asset transfer) -- make lock-network - - makes a network for running lock/claim (asset exchange) -- make clean-network - - tear down the current network - -The asset exchanges and asset transfer network modes are currently mutually exclusive. \ No newline at end of file diff --git a/packages/cacti-plugin-copm-fabric/package.json b/packages/cacti-plugin-copm-fabric/package.json index e106445794..4566909b30 100644 --- a/packages/cacti-plugin-copm-fabric/package.json +++ b/packages/cacti-plugin-copm-fabric/package.json @@ -12,12 +12,12 @@ }, "license": "Apache-2.0", "author": "Jennifer Bell", - "scripts": { - "test": "yarn run --top-level test:jest:all ./src/test/typescript/*/*.test.ts", - "test:lock": "yarn run --top-level test:jest:all ./src/test/typescript/integration/test-copm-lock-claim.test.ts", - "test:pledge": "yarn run --top-level test:jest:all ./src/test/typescript/integration/test-copm-pledge-claim.test.ts", - "test:view": "yarn run --top-level test:jest:all ./src/test/typescript/integration/test-copm-getverifiedview.test.ts" - }, + "main": "dist/lib/main/typescript/index.js", + "module": "dist/lib/main/typescript/index.js", + "types": "dist/lib/main/typescript/index.d.ts", + "files": [ + "dist/*" + ], "dependencies": { "@bufbuild/buf": "1.30.0", "@bufbuild/protobuf": "1.10.0", @@ -33,13 +33,11 @@ "fabric-network": "2.2.20" }, "devDependencies": { - "@bufbuild/protoc-gen-es": "1.8.0", "@connectrpc/connect-node": "1.4.0", "@connectrpc/protoc-gen-connect-es": "1.4.0", "@hyperledger/cactus-cmd-api-server": "2.0.0", "@hyperledger/cactus-plugin-keychain-memory": "2.0.0", "@hyperledger/cactus-plugin-ledger-connector-fabric": "2.0.0", - "@hyperledger/cactus-test-tooling": "2.0.0", - "@openapitools/openapi-generator-cli": "2.7.0" + "@hyperledger/cactus-test-tooling": "2.0.0" } } diff --git a/packages/cacti-plugin-copm-fabric/src/main/typescript/endpoints/claim-locked-asset-v1.ts b/packages/cacti-plugin-copm-fabric/src/main/typescript/endpoints/claim-locked-asset-v1.ts index cd1896f801..b35acfd251 100644 --- a/packages/cacti-plugin-copm-fabric/src/main/typescript/endpoints/claim-locked-asset-v1.ts +++ b/packages/cacti-plugin-copm-fabric/src/main/typescript/endpoints/claim-locked-asset-v1.ts @@ -1,7 +1,6 @@ import { Logger } from "@hyperledger/cactus-common"; import { AssetManager } from "@hyperledger/cacti-weaver-sdk-fabric"; import { - DLTransactionParams, Validators, ClaimLockedAssetV1Request, Interfaces as CopmIF, @@ -13,37 +12,22 @@ export async function claimLockedAssetV1Impl( contextFactory: CopmIF.DLTransactionContextFactory, contractName: string, ): Promise { - let transactionParams: DLTransactionParams; const params = Validators.validateClaimLockedAssetRequest(req); const claimInfoStr = AssetManager.createAssetClaimInfoSerialized( params.hashInfo, ); - if (params.asset.isNFT()) { - const agreementStr = AssetManager.createAssetExchangeAgreementSerialized( - params.asset.assetType, - params.asset.idOrQuantity(), - params.destCertificate, - params.sourceCertificate, - ); - transactionParams = { - contract: contractName, - method: "ClaimAsset", - args: [agreementStr, claimInfoStr], - }; - } else { - // NOTE: can not currently claim NFTs with only a lock id - transactionParams = { - contract: contractName, - method: "ClaimFungibleAsset", - args: [params.lockId, claimInfoStr], - }; - } - const transactionContext = await contextFactory.getTransactionContext( params.destination, ); - const claimId = await transactionContext.invoke(transactionParams); + + const claimId = await transactionContext.invoke({ + contract: contractName, + method: params.asset.isNFT() + ? "ClaimAssetUsingContractId" + : "ClaimFungibleAsset", + args: [params.lockId, claimInfoStr], + }); log.debug("claim complete"); return claimId; diff --git a/packages/cacti-plugin-copm-fabric/src/main/typescript/endpoints/claim-pledged-asset-v1.ts b/packages/cacti-plugin-copm-fabric/src/main/typescript/endpoints/claim-pledged-asset-v1.ts index b3e1cea6ec..55008629a5 100644 --- a/packages/cacti-plugin-copm-fabric/src/main/typescript/endpoints/claim-pledged-asset-v1.ts +++ b/packages/cacti-plugin-copm-fabric/src/main/typescript/endpoints/claim-pledged-asset-v1.ts @@ -9,9 +9,10 @@ export async function claimPledgedAssetV1Impl( req: ClaimPledgedAssetV1Request, log: Logger, contextFactory: CopmIF.DLTransactionContextFactory, + interopConfig: CopmIF.InteropConfiguration, contractName: string, ): Promise { - const data = Validators.validateClaimPledgedAssetRequest(req); + const data = new Validators.ValidatedClaimPledgedAssetRequest(req); const interop_context = await contextFactory.getRemoteTransactionContext( data.destAccount, @@ -19,16 +20,7 @@ export async function claimPledgedAssetV1Impl( ); const claimId = await interop_context.invokeFlow( - { - contract: contractName, - method: "GetAssetPledgeStatus", - args: [ - data.pledgeId, - data.sourceCert, - data.destAccount.organization, - data.destCert, - ], - }, + interopConfig.getRemotePledgeStatusCmd(data.sourceNetwork, data), { contract: contractName, method: data.asset.isNFT() ? "ClaimRemoteAsset" : "ClaimRemoteTokenAsset", diff --git a/packages/cacti-plugin-copm-fabric/src/main/typescript/endpoints/lock-asset-impl-v1.ts b/packages/cacti-plugin-copm-fabric/src/main/typescript/endpoints/lock-asset-impl-v1.ts index 2316d81865..57863e81f4 100644 --- a/packages/cacti-plugin-copm-fabric/src/main/typescript/endpoints/lock-asset-impl-v1.ts +++ b/packages/cacti-plugin-copm-fabric/src/main/typescript/endpoints/lock-asset-impl-v1.ts @@ -15,7 +15,7 @@ export async function lockAssetV1Impl( const params = Validators.validateLockAssetRequest(req); const transactionContext = await contextFactory.getTransactionContext( - params.owner, + params.sourceAccount, ); const serializeAgreementFunc = params.asset.isNFT() diff --git a/packages/cacti-plugin-copm-fabric/src/main/typescript/plugin-copm-fabric.ts b/packages/cacti-plugin-copm-fabric/src/main/typescript/plugin-copm-fabric.ts index 199947d53c..37f261493d 100644 --- a/packages/cacti-plugin-copm-fabric/src/main/typescript/plugin-copm-fabric.ts +++ b/packages/cacti-plugin-copm-fabric/src/main/typescript/plugin-copm-fabric.ts @@ -4,6 +4,7 @@ import { Logger, } from "@hyperledger/cactus-common"; import { + ICactusPlugin, ICactusPluginOptions, ICrpcSvcRegistration, IPluginCrpcService, @@ -25,11 +26,12 @@ export interface IPluginCopmFabricOptions extends ICactusPluginOptions { contractNames: CopmContractNames; } -export class PluginCopmFabric implements IPluginCrpcService { +export class PluginCopmFabric implements IPluginCrpcService, ICactusPlugin { public static readonly CLASS_NAME = "PluginCopmFabric"; private readonly instanceId: string; private readonly logLevel: LogLevelDesc; private contextFactory: FabricTransactionContextFactory; + private interopConfig: CopmIF.InteropConfiguration; private copmContractNames: CopmContractNames; private readonly log: Logger; @@ -46,6 +48,7 @@ export class PluginCopmFabric implements IPluginCrpcService { this.log, ); this.copmContractNames = opts.contractNames; + this.interopConfig = opts.interopConfig; this.instanceId = this.opts.instanceId; } @@ -57,6 +60,7 @@ export class PluginCopmFabric implements IPluginCrpcService { const implementation = new CopmFabricImpl( this.log, this.contextFactory, + this.interopConfig, this.copmContractNames, ); diff --git a/packages/cacti-plugin-copm-fabric/src/main/typescript/public-api.ts b/packages/cacti-plugin-copm-fabric/src/main/typescript/public-api.ts index ea1e43660b..d9266e9634 100755 --- a/packages/cacti-plugin-copm-fabric/src/main/typescript/public-api.ts +++ b/packages/cacti-plugin-copm-fabric/src/main/typescript/public-api.ts @@ -6,5 +6,7 @@ export async function createPluginFactory( ): Promise { return new PluginFactoryCopmFabric(pluginFactoryOptions); } - +export { PluginCopmFabric } from "./plugin-copm-fabric"; export { FabricConfiguration } from "./lib/fabric-configuration"; +export { FabricTransactionContextFactory } from "./lib/fabric-context-factory"; +export { FabricContractContext } from "./lib/fabric-types"; diff --git a/packages/cacti-plugin-copm-fabric/src/main/typescript/service-implementation.ts b/packages/cacti-plugin-copm-fabric/src/main/typescript/service-implementation.ts index 97e95d32e6..b75e7fbad3 100644 --- a/packages/cacti-plugin-copm-fabric/src/main/typescript/service-implementation.ts +++ b/packages/cacti-plugin-copm-fabric/src/main/typescript/service-implementation.ts @@ -16,6 +16,7 @@ import { CopmContractNames, } from "@hyperledger-cacti/cacti-copm-core"; import * as Endpoints from "./endpoints"; +import { InteropConfiguration } from "@hyperledger-cacti/cacti-copm-core/src/main/typescript/interfaces"; type DefaultServiceMethodDefinitions = typeof DefaultService.methods; type DefaultServiceMethodNames = keyof DefaultServiceMethodDefinitions; @@ -35,17 +36,25 @@ export class CopmFabricImpl private readonly log: Logger; private readonly contextFactory: CopmIF.DLTransactionContextFactory; private readonly contractNames: CopmContractNames; + private readonly interopConfig: InteropConfiguration; constructor( log: Logger, contextFactory: CopmIF.DLTransactionContextFactory, + interopConfig: InteropConfiguration, copmContractNames: CopmContractNames, ) { this.log = log; this.contextFactory = contextFactory; + this.interopConfig = interopConfig; this.contractNames = copmContractNames; } + public async noopV1(): Promise { + // operation can be used as a health check + return; + } + public async pledgeAssetV1( req: PledgeAssetV1Request, ): Promise { @@ -88,12 +97,19 @@ export class CopmFabricImpl req: ClaimPledgedAssetV1Request, ): Promise { this.log.debug("claimAssetV1 ENTRY req=%o", req); - const claimId = await Endpoints.claimPledgedAssetV1Impl( - req, - this.log, - this.contextFactory, - this.contractNames.pledgeContract, - ); + let claimId; + try { + claimId = await Endpoints.claimPledgedAssetV1Impl( + req, + this.log, + this.contextFactory, + this.interopConfig, + this.contractNames.pledgeContract, + ); + } catch (ex) { + this.log.error(ex); + throw ex; + } const res = new ClaimPledgedAssetV1200ResponsePB({ claimId: claimId }); return res; } diff --git a/packages/cacti-plugin-copm-fabric/src/test/typescript/integration/test-copm-getverifiedview.test.ts b/packages/cacti-plugin-copm-fabric/src/test/typescript/integration/test-copm-getverifiedview.test.ts deleted file mode 100644 index c84d667d30..0000000000 --- a/packages/cacti-plugin-copm-fabric/src/test/typescript/integration/test-copm-getverifiedview.test.ts +++ /dev/null @@ -1,183 +0,0 @@ -import { AddressInfo } from "node:net"; -import http from "node:http"; - -import "jest-extended"; -import { v4 as uuidV4 } from "uuid"; -import { createPromiseClient, PromiseClient } from "@connectrpc/connect"; -import { createConnectTransport } from "@connectrpc/connect-node"; -import { PluginRegistry } from "@hyperledger/cactus-core"; -import { - LogLevelDesc, - Logger, - LoggerProvider, - Servers, -} from "@hyperledger/cactus-common"; -import { - AuthorizationProtocol, - ConfigService, - ApiServer, -} from "@hyperledger/cactus-cmd-api-server"; -import { PluginCopmFabric } from "../../../main/typescript/plugin-copm-fabric"; -import { - PledgeAssetV1Request, - GetVerifiedViewV1Request, - DefaultService, -} from "@hyperledger-cacti/cacti-copm-core"; -import { CopmWeaverFabricTestnet } from "../lib/copm-weaver-fabric-testnet"; -import * as path from "path"; -import * as dotenv from "dotenv"; -import { TestAssetManager } from "../lib/test-asset-manager"; -dotenv.config({ path: path.resolve(__dirname, "../../.env") }); - -const logLevel: LogLevelDesc = "DEBUG"; -const log: Logger = LoggerProvider.getOrCreate({ - label: "plugin-copm-crpc-server-test", - level: logLevel, -}); - -describe("PluginCopmFabric", () => { - let fabricTestnet: CopmWeaverFabricTestnet; - let httpServer: http.Server; - let apiServer: ApiServer; - let assetManager: TestAssetManager; - let net1: string, net2: string, user1: string, user2: string; - let source_cert: string, dest_cert: string; - let client: PromiseClient; - const contractName: string = "simpleassettransfer"; - const proveAssetName: string = "proveasset" + new Date().getTime().toString(); - - beforeAll(async () => { - httpServer = await Servers.startOnPreferredPort(4050); - const addressInfoHttp = httpServer.address() as AddressInfo; - const apiHttpHost = `http://${addressInfoHttp.address}:${addressInfoHttp.port}`; - log.debug("HTTP API host: %s", apiHttpHost); - - const pluginRegistry = new PluginRegistry({ plugins: [] }); - - const cfgSrv = new ConfigService(); - const apiSrvOpts = await cfgSrv.newExampleConfig(); - apiSrvOpts.authorizationProtocol = AuthorizationProtocol.NONE; - apiSrvOpts.logLevel = logLevel; - apiSrvOpts.configFile = ""; - apiSrvOpts.apiCorsDomainCsv = "*"; - apiSrvOpts.apiPort = addressInfoHttp.port; - apiSrvOpts.cockpitPort = 0; - apiSrvOpts.grpcPort = 0; - apiSrvOpts.grpcMtlsEnabled = false; - apiSrvOpts.apiTlsEnabled = false; - apiSrvOpts.crpcPort = 0; - const cfg = await cfgSrv.newExampleConfigConvict(apiSrvOpts); - - log.info("setting up fabric test network"); - - fabricTestnet = new CopmWeaverFabricTestnet(log, contractName); - - const compFabricPlugin = new PluginCopmFabric({ - instanceId: uuidV4(), - logLevel, - fabricConfig: fabricTestnet.fabricConfig, - interopConfig: fabricTestnet.interopConfig, - contractNames: fabricTestnet.contractNames, - }); - - pluginRegistry.add(compFabricPlugin); - - apiServer = new ApiServer({ - httpServerApi: httpServer, - config: cfg.getProperties(), - pluginRegistry, - }); - - log.info("staring api server"); - const { addressInfoGrpc, addressInfoCrpc } = await apiServer.start(); - const grpcPort = addressInfoGrpc.port; - const grpcHost = addressInfoGrpc.address; - const grpcFamily = addressInfoHttp.family; - log.info("gRPC family=%s host=%s port=%s", grpcFamily, grpcHost, grpcPort); - log.info("CRPC AddressInfo=%o", addressInfoCrpc); - - expect(apiServer).toBeTruthy(); - - const transport = createConnectTransport({ - baseUrl: apiHttpHost, - httpVersion: "1.1", - }); - client = createPromiseClient(DefaultService, transport); - - [net1, net2] = fabricTestnet.networkNames(); - [user1, user2] = fabricTestnet.userNames(); - assetManager = fabricTestnet.assetManager(); - - source_cert = await fabricTestnet.getCertificateString({ - organization: net1, - userId: user1, - }); - - dest_cert = await fabricTestnet.getCertificateString({ - organization: net2, - userId: user2, - }); - - log.info("test setup complete"); - }); - - afterAll(async () => { - if (apiServer) { - await apiServer.shutdown(); - } - }); - - test("fabric-fabric get verified view", async () => { - await assetManager.addNonFungibleAsset("bond", proveAssetName, { - organization: net1, - userId: user1, - }); - - const pledgeResult = await client.pledgeAssetV1( - new PledgeAssetV1Request({ - assetPledgeV1PB: { - asset: { - assetType: "bond", - assetId: proveAssetName, - }, - source: { - network: net1, - userId: user1, - }, - destination: { - network: net2, - userId: user2, - }, - expirySecs: BigInt(45), - destinationCertificate: dest_cert, - }, - }), - ); - - expect(pledgeResult).toBeTruthy(); - expect(pledgeResult.pledgeId).toBeString(); - - const res = await client.getVerifiedViewV1( - new GetVerifiedViewV1Request({ - getVerifiedViewV1RequestPB: { - account: { - network: net2, - userId: user2, - }, - view: { - network: net1, - viewAddress: { - contractId: contractName, - function: "GetAssetPledgeStatus", - input: [pledgeResult.pledgeId, source_cert, net2, dest_cert], - }, - }, - }, - }), - ); - - expect(res).toBeTruthy(); - expect(res.data).toBeString(); - log.info(res.data); - }); -}); diff --git a/packages/cacti-plugin-copm-fabric/src/test/typescript/integration/test-copm-lock-claim.test.ts b/packages/cacti-plugin-copm-fabric/src/test/typescript/integration/test-copm-lock-claim.test.ts deleted file mode 100644 index 9192e15885..0000000000 --- a/packages/cacti-plugin-copm-fabric/src/test/typescript/integration/test-copm-lock-claim.test.ts +++ /dev/null @@ -1,249 +0,0 @@ -import { AddressInfo } from "node:net"; -import http from "node:http"; - -import "jest-extended"; -import { v4 as uuidV4 } from "uuid"; -import { createPromiseClient, PromiseClient } from "@connectrpc/connect"; -import { createConnectTransport } from "@connectrpc/connect-node"; -import { PluginRegistry } from "@hyperledger/cactus-core"; -import { - LogLevelDesc, - Logger, - LoggerProvider, - Servers, -} from "@hyperledger/cactus-common"; -import { - AuthorizationProtocol, - ConfigService, - ApiServer, -} from "@hyperledger/cactus-cmd-api-server"; -import { PluginCopmFabric } from "../../../main/typescript/plugin-copm-fabric"; -import { - DefaultService, - ClaimLockedAssetV1Request, - LockAssetV1Request, -} from "@hyperledger-cacti/cacti-copm-core"; -import { CopmWeaverFabricTestnet } from "../lib/copm-weaver-fabric-testnet"; -import { TestAssetManager } from "../lib/test-asset-manager"; -import * as path from "path"; -import * as dotenv from "dotenv"; -dotenv.config({ path: path.resolve(__dirname, "../../.env") }); - -const logLevel: LogLevelDesc = "DEBUG"; -const log: Logger = LoggerProvider.getOrCreate({ - label: "plugin-copm-crpc-server-test", - level: logLevel, -}); - -describe("PluginCopmFabric", () => { - let fabricTestnet: CopmWeaverFabricTestnet; - let httpServer: http.Server; - let apiServer: ApiServer; - let assetManager: TestAssetManager; - let client: PromiseClient; - let user1: string, net1: string, user2: string, net2: string; - - const hashSecret: string = "my_secret_123"; - const lockAssetName: string = "lockasset" + new Date().getTime().toString(); - - beforeAll(async () => { - httpServer = await Servers.startOnPreferredPort(4050); - const addressInfoHttp = httpServer.address() as AddressInfo; - const apiHttpHost = `http://${addressInfoHttp.address}:${addressInfoHttp.port}`; - log.debug("HTTP API host: %s", apiHttpHost); - - const pluginRegistry = new PluginRegistry({ plugins: [] }); - - const cfgSrv = new ConfigService(); - const apiSrvOpts = await cfgSrv.newExampleConfig(); - apiSrvOpts.authorizationProtocol = AuthorizationProtocol.NONE; - apiSrvOpts.logLevel = logLevel; - apiSrvOpts.configFile = ""; - apiSrvOpts.apiCorsDomainCsv = "*"; - apiSrvOpts.apiPort = addressInfoHttp.port; - apiSrvOpts.cockpitPort = 0; - apiSrvOpts.grpcPort = 0; - apiSrvOpts.grpcMtlsEnabled = false; - apiSrvOpts.apiTlsEnabled = false; - apiSrvOpts.crpcPort = 0; - const cfg = await cfgSrv.newExampleConfigConvict(apiSrvOpts); - - fabricTestnet = new CopmWeaverFabricTestnet(log, "simpleasset"); - - const compFabricPlugin = new PluginCopmFabric({ - instanceId: uuidV4(), - logLevel, - fabricConfig: fabricTestnet.fabricConfig, - interopConfig: fabricTestnet.interopConfig, - contractNames: fabricTestnet.contractNames, - }); - - pluginRegistry.add(compFabricPlugin); - - apiServer = new ApiServer({ - httpServerApi: httpServer, - config: cfg.getProperties(), - pluginRegistry, - }); - - log.info("staring api server"); - const { addressInfoGrpc, addressInfoCrpc } = await apiServer.start(); - const grpcPort = addressInfoGrpc.port; - const grpcHost = addressInfoGrpc.address; - const grpcFamily = addressInfoHttp.family; - log.info("gRPC family=%s host=%s port=%s", grpcFamily, grpcHost, grpcPort); - log.info("CRPC AddressInfo=%o", addressInfoCrpc); - - expect(apiServer).toBeTruthy(); - - [net1, net2] = fabricTestnet.networkNames(); - [user1, user2] = fabricTestnet.userNames(); - assetManager = fabricTestnet.assetManager(); - - const transport = createConnectTransport({ - baseUrl: apiHttpHost, - httpVersion: "1.1", - }); - - client = createPromiseClient(DefaultService, transport); - }); - - afterAll(async () => { - if (apiServer) { - await apiServer.shutdown(); - } - }); - - test("fabric-fabric can lock/claim nft on same network by asset agreement", async () => { - const assetType = "bond"; - - const sourceCert = await fabricTestnet.getCertificateString({ - organization: net1, - userId: user1, - }); - const destCert = await fabricTestnet.getCertificateString({ - organization: net1, - userId: user2, - }); - - await assetManager.addNonFungibleAsset(assetType, lockAssetName, { - organization: net1, - userId: user1, - }); - - const lockResult = await client.lockAssetV1( - new LockAssetV1Request({ - assetLockV1PB: { - asset: { - assetType: assetType, - assetId: lockAssetName, - }, - owner: { - network: net1, - userId: user1, - }, - hashInfo: { - secret: hashSecret, - }, - expirySecs: BigInt(45), - sourceCertificate: sourceCert, - destinationCertificate: destCert, - }, - }), - ); - - expect(lockResult).toBeTruthy(); - - const claimResult = await client.claimLockedAssetV1( - new ClaimLockedAssetV1Request({ - assetLockClaimV1PB: { - asset: { - assetType: assetType, - assetId: lockAssetName, - }, - source: { - network: net1, - userId: user1, - }, - destination: { - network: net1, - userId: user2, - }, - sourceCertificate: sourceCert, - destCertificate: destCert, - hashInfo: { - secret: hashSecret, - }, - }, - }), - ); - expect(claimResult).toBeTruthy(); - }); - - test("fabric-fabric can lock/claim tokens on same network", async () => { - const assetType = "token1"; - const assetQuantity = 10; - - await assetManager.addToken(assetType, assetQuantity, { - organization: net2, - userId: user2, - }); - - const srcCert = await fabricTestnet.getCertificateString({ - organization: net2, - userId: user2, - }); - const destCert = await fabricTestnet.getCertificateString({ - organization: net2, - userId: user1, - }); - - const lockResult = await client.lockAssetV1( - new LockAssetV1Request({ - assetLockV1PB: { - asset: { - assetType: assetType, - assetQuantity: assetQuantity, - }, - owner: { network: net2, userId: user2 }, - hashInfo: { - secret: hashSecret, - }, - expirySecs: BigInt(45), - sourceCertificate: srcCert, - destinationCertificate: destCert, - }, - }), - ); - - expect(lockResult).toBeTruthy(); - expect(lockResult.lockId).toBeString(); - log.debug(lockResult.lockId); - - const claimResult = await client.claimLockedAssetV1( - new ClaimLockedAssetV1Request({ - assetLockClaimV1PB: { - lockId: lockResult.lockId, - asset: { - assetType: assetType, - assetQuantity: assetQuantity, - }, - source: { - network: net2, - userId: user2, - }, - destination: { - network: net2, - userId: user1, - }, - sourceCertificate: srcCert, - destCertificate: destCert, - hashInfo: { - secret: hashSecret, - }, - }, - }), - ); - expect(claimResult).toBeTruthy(); - }); -}); diff --git a/packages/cacti-plugin-copm-fabric/src/test/typescript/integration/test-copm-pledge-claim.test.ts b/packages/cacti-plugin-copm-fabric/src/test/typescript/integration/test-copm-pledge-claim.test.ts deleted file mode 100644 index cbaee44ab8..0000000000 --- a/packages/cacti-plugin-copm-fabric/src/test/typescript/integration/test-copm-pledge-claim.test.ts +++ /dev/null @@ -1,255 +0,0 @@ -import { AddressInfo } from "node:net"; -import http from "node:http"; - -import "jest-extended"; -import { v4 as uuidV4 } from "uuid"; -import { createPromiseClient, PromiseClient } from "@connectrpc/connect"; -import { createConnectTransport } from "@connectrpc/connect-node"; -import { PluginRegistry } from "@hyperledger/cactus-core"; -import { - LogLevelDesc, - Logger, - LoggerProvider, - Servers, -} from "@hyperledger/cactus-common"; -import { ApiServer } from "@hyperledger/cactus-cmd-api-server"; -import { AuthorizationProtocol } from "@hyperledger/cactus-cmd-api-server"; -import { ConfigService } from "@hyperledger/cactus-cmd-api-server"; -import { - DefaultService, - ClaimPledgedAssetV1Request, - PledgeAssetV1Request, - AssetAccountV1PB, - DLAccount, -} from "@hyperledger-cacti/cacti-copm-core"; -import { PluginCopmFabric } from "../../../main/typescript/plugin-copm-fabric"; -import { CopmWeaverFabricTestnet } from "../lib/copm-weaver-fabric-testnet"; -import { TestAssetManager } from "../lib/test-asset-manager"; -import * as path from "path"; -import * as dotenv from "dotenv"; -dotenv.config({ path: path.resolve(__dirname, "../../.env") }); - -const logLevel: LogLevelDesc = "DEBUG"; -const log: Logger = LoggerProvider.getOrCreate({ - label: "plugin-copm-crpc-server-test", - level: logLevel, -}); - -describe("PluginCopmFabric", () => { - let fabricTestnet: CopmWeaverFabricTestnet; - let httpServer: http.Server; - let apiServer: ApiServer; - let sourceAccount: DLAccount, destAccount: DLAccount; - let sourceCert: string, destCert: string; - let sourceAccountPB: AssetAccountV1PB, destAccountPB: AssetAccountV1PB; - let assetManager: TestAssetManager; - let client: PromiseClient; - - const contractName: string = "simpleassettransfer"; - const pledgeAssetName: string = - "pledgeasset" + new Date().getTime().toString(); - - beforeAll(async () => { - httpServer = await Servers.startOnPreferredPort(4050); - const addressInfoHttp = httpServer.address() as AddressInfo; - const apiHttpHost = `http://${addressInfoHttp.address}:${addressInfoHttp.port}`; - log.debug("HTTP API host: %s", apiHttpHost); - - const pluginRegistry = new PluginRegistry({ plugins: [] }); - - const cfgSrv = new ConfigService(); - const apiSrvOpts = await cfgSrv.newExampleConfig(); - apiSrvOpts.authorizationProtocol = AuthorizationProtocol.NONE; - apiSrvOpts.logLevel = logLevel; - apiSrvOpts.configFile = ""; - apiSrvOpts.apiCorsDomainCsv = "*"; - apiSrvOpts.apiPort = addressInfoHttp.port; - apiSrvOpts.cockpitPort = 0; - apiSrvOpts.grpcPort = 0; - apiSrvOpts.grpcMtlsEnabled = false; - apiSrvOpts.apiTlsEnabled = false; - apiSrvOpts.crpcPort = 0; - const cfg = await cfgSrv.newExampleConfigConvict(apiSrvOpts); - - log.info("setting up fabric test network"); - - fabricTestnet = new CopmWeaverFabricTestnet(log, contractName); - - const compFabricPlugin = new PluginCopmFabric({ - instanceId: uuidV4(), - logLevel, - fabricConfig: fabricTestnet.fabricConfig, - interopConfig: fabricTestnet.interopConfig, - contractNames: fabricTestnet.contractNames, - }); - - pluginRegistry.add(compFabricPlugin); - - apiServer = new ApiServer({ - httpServerApi: httpServer, - config: cfg.getProperties(), - pluginRegistry, - }); - - log.info("staring api server"); - const { addressInfoGrpc, addressInfoCrpc } = await apiServer.start(); - const grpcPort = addressInfoGrpc.port; - const grpcHost = addressInfoGrpc.address; - const grpcFamily = addressInfoHttp.family; - log.info("gRPC family=%s host=%s port=%s", grpcFamily, grpcHost, grpcPort); - log.info("CRPC AddressInfo=%o", addressInfoCrpc); - - expect(apiServer).toBeTruthy(); - - const [net1, net2] = fabricTestnet.networkNames(); - const [user1, user2] = fabricTestnet.userNames(); - assetManager = fabricTestnet.assetManager(); - sourceAccount = { organization: net1, userId: user1 }; - destAccount = { organization: net2, userId: user2 }; - sourceAccountPB = AssetAccountV1PB.fromJson({ - network: net1, - userId: user1, - }); - destAccountPB = AssetAccountV1PB.fromJson({ network: net2, userId: user2 }); - sourceCert = await fabricTestnet.getCertificateString(sourceAccount); - destCert = await fabricTestnet.getCertificateString(destAccount); - - const transport = createConnectTransport({ - baseUrl: apiHttpHost, - httpVersion: "1.1", - }); - client = createPromiseClient(DefaultService, transport); - - log.info("test setup complete"); - }); - - afterAll(async () => { - if (apiServer) { - await apiServer.shutdown(); - } - }); - - test("fabric-fabric asset nft pledge and claim by asset id", async () => { - const assetType = "bond01"; - - await assetManager.addNonFungibleAsset( - assetType, - pledgeAssetName, - sourceAccount, - ); - - const pledgeNFTResult = await client.pledgeAssetV1( - new PledgeAssetV1Request({ - assetPledgeV1PB: { - asset: { - assetType: assetType, - assetId: pledgeAssetName, - }, - source: sourceAccountPB, - destination: destAccountPB, - expirySecs: BigInt(45), - destinationCertificate: destCert, - }, - }), - ); - - expect(pledgeNFTResult).toBeTruthy(); - expect(pledgeNFTResult.pledgeId).toBeString(); - - const claimNFTResult = await client.claimPledgedAssetV1( - new ClaimPledgedAssetV1Request({ - assetPledgeClaimV1PB: { - pledgeId: pledgeNFTResult.pledgeId, - asset: { - assetType: assetType, - assetId: pledgeAssetName, - }, - source: sourceAccountPB, - destination: destAccountPB, - sourceCertificate: sourceCert, - destCertificate: destCert, - }, - }), - ); - expect(claimNFTResult).toBeTruthy(); - - // Check that the asset changed networks. - expect( - await assetManager.userOwnsNonFungibleAsset( - assetType, - pledgeAssetName, - sourceAccount, - ), - ).toBeFalse(); - - expect( - await assetManager.userOwnsNonFungibleAsset( - assetType, - pledgeAssetName, - destAccount, - ), - ).toBeTrue(); - }); - - test("fabric-fabric asset token pledge and claim", async () => { - const assetType = "token1"; - const exchangeQuantity = 10; - - // ensure initial account balance - user will not have a wallet if 0 tokens - await assetManager.addToken(assetType, 1 + exchangeQuantity, sourceAccount); - await assetManager.addToken(assetType, 1, destAccount); - - const user1StartBalance = await assetManager.tokenBalance( - assetType, - sourceAccount, - ); - const user2StartBalance = await assetManager.tokenBalance( - assetType, - destAccount, - ); - - const pledgeResult = await client.pledgeAssetV1( - new PledgeAssetV1Request({ - assetPledgeV1PB: { - asset: { - assetType: assetType, - assetQuantity: exchangeQuantity, - }, - source: sourceAccountPB, - destination: destAccountPB, - expirySecs: BigInt(45), - destinationCertificate: destCert, - }, - }), - ); - - expect(pledgeResult).toBeTruthy(); - expect(pledgeResult.pledgeId).toBeString(); - - const claimResult = await client.claimPledgedAssetV1( - new ClaimPledgedAssetV1Request({ - assetPledgeClaimV1PB: { - pledgeId: pledgeResult.pledgeId, - asset: { - assetType: assetType, - assetQuantity: exchangeQuantity, - }, - source: sourceAccountPB, - destination: destAccountPB, - sourceCertificate: sourceCert, - destCertificate: destCert, - }, - }), - ); - expect(claimResult).toBeTruthy(); - - // Check that the tokens changed networks. - expect(await assetManager.tokenBalance(assetType, sourceAccount)).toEqual( - user1StartBalance - exchangeQuantity, - ); - - expect(await assetManager.tokenBalance(assetType, destAccount)).toEqual( - user2StartBalance + exchangeQuantity, - ); - }); -}); diff --git a/packages/cacti-plugin-copm-fabric/src/test/typescript/lib/copm-weaver-fabric-testnet.ts b/packages/cacti-plugin-copm-fabric/src/test/typescript/lib/copm-weaver-fabric-testnet.ts deleted file mode 100644 index 299ac0b5c2..0000000000 --- a/packages/cacti-plugin-copm-fabric/src/test/typescript/lib/copm-weaver-fabric-testnet.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { Identity } from "fabric-network"; -import { - DLAccount, - CopmContractNames, -} from "@hyperledger-cacti/cacti-copm-core"; -import { LogLevelDesc, Logger } from "@hyperledger/cactus-common"; -import { TestAssetManager } from "./test-asset-manager"; -import { TestFabricConfiguration } from "./test-fabric-configuration"; -import { FabricTransactionContextFactory } from "../../../main/typescript/lib/fabric-context-factory"; -import { TestInteropConfiguration } from "./test-interop-configuration"; - -type FabricIdentity = Identity & { - credentials: { - certificate: string; - privateKey: string; - }; -}; - -export class CopmWeaverFabricTestnet { - logLevel: LogLevelDesc = "INFO"; - log: Logger; - fabricConfig: TestFabricConfiguration; - interopConfig: TestInteropConfiguration; - contractNames: CopmContractNames; - - private assetContractName: string; - private networkAdminName: string; - - constructor(log: Logger, assetContractName: string) { - this.log = log; - this.assetContractName = assetContractName; - this.networkAdminName = "networkadmin"; - this.fabricConfig = new TestFabricConfiguration(log); - this.interopConfig = new TestInteropConfiguration("interop", this.log); - this.contractNames = { - pledgeContract: "simpleassettransfer", - lockContract: "simpleasset", - }; - } - - public networkNames(): string[] { - return ["network1", "network2"]; - } - - public userNames(): string[] { - return ["alice", "bob"]; - } - - public async getCertificateString(account: DLAccount): Promise { - const wallet = await this.fabricConfig.getOrgWallet(account.organization); - const identity = (await wallet.get(account.userId)) as FabricIdentity; - if (!identity?.credentials?.certificate) { - throw new Error(`no credentials for user ${account.userId}`); - } - const userCert = Buffer.from(identity.credentials.certificate).toString( - "base64", - ); - return userCert; - } - - public assetManager() { - // eslint-disable-next-line @typescript-eslint/no-this-alias - const testnet = this; - return new TestAssetManager( - this.assetContractName, - this.networkAdminName, - new FabricTransactionContextFactory( - this.fabricConfig, - this.interopConfig, - this.log, - ), - async function (account: DLAccount): Promise { - return await testnet.getCertificateString(account); - }, - this.log, - ); - } -} diff --git a/packages/cacti-plugin-copm-fabric/tsconfig.json b/packages/cacti-plugin-copm-fabric/tsconfig.json index 162afd7838..f38d3f6f43 100644 --- a/packages/cacti-plugin-copm-fabric/tsconfig.json +++ b/packages/cacti-plugin-copm-fabric/tsconfig.json @@ -27,9 +27,6 @@ }, { "path": "../cactus-core-api/tsconfig.json" - }, - { - "path": "../cactus-test-tooling/tsconfig.json" } ] } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index a29748bceb..20dd6ceb1a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -127,6 +127,12 @@ { "path": "./packages/cacti-plugin-copm-fabric/tsconfig.json" }, + { + "path": "./packages/cacti-plugin-copm-corda/tsconfig.json" + }, + { + "path": "./packages/cacti-copm-test/tsconfig.json" + }, { "path": "./packages/cactus-test-tooling/tsconfig.json" }, diff --git a/weaver/samples/corda/corda-simple-application/workflows-kotlin/build.gradle b/weaver/samples/corda/corda-simple-application/workflows-kotlin/build.gradle index 4ab12d5824..4223717885 100644 --- a/weaver/samples/corda/corda-simple-application/workflows-kotlin/build.gradle +++ b/weaver/samples/corda/corda-simple-application/workflows-kotlin/build.gradle @@ -7,7 +7,7 @@ cordapp { targetPlatformVersion corda_platform_version minimumPlatformVersion corda_platform_version workflow { - name "Template Flows" + name "Weaver Corda Simple App" vendor "Corda Open Source" licence "Apache License, Version 2.0" versionId 1 diff --git a/weaver/tests/network-setups/corda/makefile b/weaver/tests/network-setups/corda/makefile index 8452932db3..26f7dff730 100644 --- a/weaver/tests/network-setups/corda/makefile +++ b/weaver/tests/network-setups/corda/makefile @@ -70,7 +70,7 @@ stop-network1: docker exec corda_partya_1 bash -c "rm -rf /opt/corda/logs/*" || true (docker logs corda_partyb_1 > /dev/null && docker exec corda_partyb_1 bash -c "rm -rf /opt/corda/logs/*") || true (docker logs corda_partyc_1 > /dev/null && docker exec corda_partyc_1 bash -c "rm -rf /opt/corda/logs/*") || true - docker-compose -f dev/Corda_Network/docker-compose.yml -p corda --profile $(PROFILE) down --volumes || true + docker compose -f dev/Corda_Network/docker-compose.yml -p corda --profile $(PROFILE) down --volumes || true .PHONY: stop-network2 stop-network2: @@ -78,7 +78,7 @@ stop-network2: docker exec corda_network2_partya_1 bash -c "rm -rf /opt/corda/logs/*" || true (docker logs corda_network2_partyb_1 > /dev/null && docker exec corda_network2_partyb_1 bash -c "rm -rf /opt/corda/logs/*") || true (docker logs corda_network2_partyc_1 > /dev/null && docker exec corda_network2_partyc_1 bash -c "rm -rf /opt/corda/logs/*") || true - docker-compose -f dev/Corda_Network2/docker-compose.yml -p corda_network2 --profile $(PROFILE) down --volumes || true + docker compose -f dev/Corda_Network2/docker-compose.yml -p corda_network2 --profile $(PROFILE) down --volumes || true stop: stop-network1 stop-network2 diff --git a/yarn.lock b/yarn.lock index 590decc863..bd0f4a1ac5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9042,13 +9042,60 @@ __metadata: languageName: unknown linkType: soft -"@hyperledger-cacti/cacti-plugin-copm-fabric@workspace:packages/cacti-plugin-copm-fabric": +"@hyperledger-cacti/cacti-copm-test@npm:2.0.0, @hyperledger-cacti/cacti-copm-test@workspace:packages/cacti-copm-test": + version: 0.0.0-use.local + resolution: "@hyperledger-cacti/cacti-copm-test@workspace:packages/cacti-copm-test" + dependencies: + "@connectrpc/connect": "npm:1.4.0" + "@connectrpc/connect-node": "npm:1.4.0" + "@hyperledger-cacti/cacti-copm-core": "npm:2.0.0" + "@hyperledger-cacti/cacti-plugin-copm-corda": "npm:2.0.0" + "@hyperledger-cacti/cacti-plugin-copm-fabric": "npm:2.0.0" + "@hyperledger/cacti-weaver-protos-js": "npm:2.0.0" + "@hyperledger/cacti-weaver-sdk-fabric": "npm:2.0.0" + "@hyperledger/cactus-cmd-api-server": "npm:2.0.0" + "@hyperledger/cactus-common": "npm:2.0.0" + "@hyperledger/cactus-core": "npm:2.0.0" + "@hyperledger/cactus-core-api": "npm:2.0.0" + "@hyperledger/cactus-plugin-ledger-connector-corda": "npm:2.0.0" + "@hyperledger/cactus-test-tooling": "npm:2.0.0" + "@types/dockerode": "npm:3.2.7" + dockerode: "npm:3.3.0" + fabric-ca-client: "npm:2.2.20" + fabric-common: "npm:2.2.20" + fabric-network: "npm:2.2.20" + fs-extra: "npm:11.2.0" + uuid: "npm:10.0.0" + languageName: unknown + linkType: soft + +"@hyperledger-cacti/cacti-plugin-copm-corda@npm:2.0.0, @hyperledger-cacti/cacti-plugin-copm-corda@workspace:packages/cacti-plugin-copm-corda": + version: 0.0.0-use.local + resolution: "@hyperledger-cacti/cacti-plugin-copm-corda@workspace:packages/cacti-plugin-copm-corda" + dependencies: + "@bufbuild/buf": "npm:1.30.0" + "@bufbuild/protobuf": "npm:1.10.0" + "@connectrpc/connect": "npm:1.4.0" + "@connectrpc/connect-node": "npm:1.4.0" + "@connectrpc/connect-web": "npm:1.4.0" + "@hyperledger-cacti/cacti-copm-core": "npm:2.0.0" + "@hyperledger-cacti/cacti-copm-test": "npm:2.0.0" + "@hyperledger/cacti-weaver-protos-js": "npm:2.0.0" + "@hyperledger/cacti-weaver-sdk-fabric": "npm:2.0.0" + "@hyperledger/cactus-common": "npm:2.0.0" + "@hyperledger/cactus-core": "npm:2.0.0" + "@hyperledger/cactus-core-api": "npm:2.0.0" + "@types/convict": "npm:6.1.1" + convict: "npm:6.2.4" + languageName: unknown + linkType: soft + +"@hyperledger-cacti/cacti-plugin-copm-fabric@npm:2.0.0, @hyperledger-cacti/cacti-plugin-copm-fabric@workspace:packages/cacti-plugin-copm-fabric": version: 0.0.0-use.local resolution: "@hyperledger-cacti/cacti-plugin-copm-fabric@workspace:packages/cacti-plugin-copm-fabric" dependencies: "@bufbuild/buf": "npm:1.30.0" "@bufbuild/protobuf": "npm:1.10.0" - "@bufbuild/protoc-gen-es": "npm:1.8.0" "@connectrpc/connect": "npm:1.4.0" "@connectrpc/connect-node": "npm:1.4.0" "@connectrpc/protoc-gen-connect-es": "npm:1.4.0" @@ -9062,7 +9109,6 @@ __metadata: "@hyperledger/cactus-plugin-keychain-memory": "npm:2.0.0" "@hyperledger/cactus-plugin-ledger-connector-fabric": "npm:2.0.0" "@hyperledger/cactus-test-tooling": "npm:2.0.0" - "@openapitools/openapi-generator-cli": "npm:2.7.0" fabric-ca-client: "npm:2.2.20" fabric-common: "npm:2.2.20" fabric-network: "npm:2.2.20"