From 053224f55762d545f6ea656228f922630dc0dbf5 Mon Sep 17 00:00:00 2001 From: Michal Bajer Date: Thu, 20 Jun 2024 17:56:40 +0200 Subject: [PATCH] feat(tcs-huawei-socketio): remove deprecated connector - Remove `cactus-plugin-ledger-connector-tcs-huawei-socketio` connector and any reference to it. - This is not permanent - we'd love to bring the package back once the necessary refactors are done! - See issue #3155 on github for more details on context and reasoning of this decision. Part of #3155 Signed-off-by: Michal Bajer --- .eslintignore | 3 - .../.gitignore | 1 - .../CHANGELOG.md | 69 ------ .../Dockerfile | 13 -- .../README.md | 77 ------- .../package.json | 79 ------- .../sample-config/default.yaml | 21 -- .../src/main/typescript/common/core/app.ts | 53 ----- .../main/typescript/common/core/bin/www.ts | 144 ------------- .../src/main/typescript/common/core/config.ts | 37 ---- .../main/typescript/connector/PluginUtil.ts | 87 -------- .../connector/ServerMonitorPlugin.ts | 198 ------------------ .../connector/ValidatorAuthentication.ts | 33 --- .../tsconfig.json | 20 -- tsconfig.json | 3 - yarn.lock | 78 +------ 16 files changed, 1 insertion(+), 915 deletions(-) delete mode 100644 packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/.gitignore delete mode 100644 packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/CHANGELOG.md delete mode 100644 packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/Dockerfile delete mode 100644 packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/README.md delete mode 100644 packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/package.json delete mode 100644 packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/sample-config/default.yaml delete mode 100644 packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/common/core/app.ts delete mode 100644 packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/common/core/bin/www.ts delete mode 100644 packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/common/core/config.ts delete mode 100644 packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/connector/PluginUtil.ts delete mode 100644 packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/connector/ServerMonitorPlugin.ts delete mode 100644 packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/connector/ValidatorAuthentication.ts delete mode 100644 packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/tsconfig.json diff --git a/.eslintignore b/.eslintignore index 9d60a71574..ca8304a9a8 100644 --- a/.eslintignore +++ b/.eslintignore @@ -23,9 +23,6 @@ packages/cactus-cmd-socketio-server/src/main/typescript/verifier/Verifier.ts packages/cactus-cmd-socketio-server/src/main/typescript/verifier/VerifierFactory.ts packages/cactus-cmd-socketio-server/src/test/typescript/unit/Verifier.test.ts -packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/common/core/app.ts -packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/connector/ServerMonitorPlugin.ts - weaver/common/policy-dsl/index.js weaver/common/policy-dsl/parser/PolicyListener.js weaver/common/policy-dsl/parser/PolicyParser.js diff --git a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/.gitignore b/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/.gitignore deleted file mode 100644 index 849ddff3b7..0000000000 --- a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/.gitignore +++ /dev/null @@ -1 +0,0 @@ -dist/ diff --git a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/CHANGELOG.md b/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/CHANGELOG.md deleted file mode 100644 index a605ac4aa0..0000000000 --- a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/CHANGELOG.md +++ /dev/null @@ -1,69 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -# [2.0.0-rc.3](https://github.com/hyperledger/cacti/compare/v2.0.0-rc.2...v2.0.0-rc.3) (2024-07-21) - -### Code Refactoring - -* retire connector plugin specific container images, fix docs ([24b5888](https://github.com/hyperledger/cacti/commit/24b5888247d134ea417fc0e83dccc9826b4075f3)) - -### BREAKING CHANGES - -* Container images are being deleted here and will also -get deleted from GHCR. Though the public APIs of the Typescript code -do not change, still, some parts of the documentation will become invalid -until we update it to match the changes here. -I invested a large amount of effort into doing this documentation update -as part of this change but it is very likely that I've missed a few spots -and therefore it is best to mark this as a breaking change in my opinion -to call attention to the fact that we still have ways to go with updating -the documentation around these container images. - -1. Deleted all the container images that were just wrappers around the -cmd-api-server container image installing their own npm package from -the registry. -The reason for this is that they ended up just being maintenance burden -since we can achieve the exact same things just by re-using the API server's -container image directly. -2. This way we don't have to deal with CVEs in 10x container images when -it's really just the one container image that we use as the base that needs -to deal with them anyway. -3. I also spent quite a bit of effort in this change to update the README.md -files of the packages where previously we had plugin specific container images -defined so that the README.md files have the tutorials that are more up to -date compared to how they were (most of them had the tutorials completely -broken for a long while which was causing a lot of difficulties to the -newcomers who were trying to work with the packages). -4. The reason why they got so out of date traces back to the undue maintenance -burden of keeping separate images for each connector plugin. We hope that -with this simplification we can keep the documentation continuously up to -date since it will require less time do so. -5. Also deleted the ci.yaml container building jobs which were relevant to -the scope of this change so that we also save on CI resources, another -long-running project that's been in need of some attention from the maintainers. - -Signed-off-by: Peter Somogyvari - -# [2.0.0-rc.2](https://github.com/hyperledger/cacti/compare/v2.0.0-rc.1...v2.0.0-rc.2) (2024-07-03) - -**Note:** Version bump only for package @hyperledger/cactus-plugin-ledger-connector-tcs-huawei-socketio - -# [2.0.0-rc.1](https://github.com/hyperledger/cacti/compare/v2.0.0-alpha.2...v2.0.0-rc.1) (2024-06-14) - -### Bug Fixes - -* **security:** address CVE-2021-3749 - axios >=0.22.0 ([61fc700](https://github.com/hyperledger/cacti/commit/61fc7001b1dd0849ab1d9bcab08e2475c695adae)) -* **security:** remediate qs vulnerability CVE-2022-24999 ([536b6b1](https://github.com/hyperledger/cacti/commit/536b6b1b7ab9014ebcd6b162e1a467e78b52afdd)) - -# [2.0.0-alpha.2](https://github.com/hyperledger/cacti/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2023-09-27) - -### Bug Fixes - -* **security:** the CVE-2022-2421 - upgrade socket.io-parser to >=4.2.1 ([9172172](https://github.com/hyperledger/cacti/commit/917217227a3fa53a00429f047cd6318862e6ab8d)), closes [#2229](https://github.com/hyperledger/cacti/issues/2229) [#2228](https://github.com/hyperledger/cacti/issues/2228) -* use common conventions: tsconfig.json, package.json ([50f5c02](https://github.com/hyperledger/cacti/commit/50f5c02190ba28b77492c09e81f5d5ba6578e862)), closes [#2216](https://github.com/hyperledger/cacti/issues/2216) - -### Features - -* **connector-tcs-huawei:** add initial version ([d8d538d](https://github.com/hyperledger/cacti/commit/d8d538d42692ddf01ef24327cb31bd8e6cd48c01)) diff --git a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/Dockerfile b/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/Dockerfile deleted file mode 100644 index 97a0951d2e..0000000000 --- a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -# TODO -# Install connector as yarn package like in @hyperledger/cactus-plugin-ledger-connector-besu - -FROM node:16 - -WORKDIR /root/cactus/ - -COPY ./dist ./dist/ -COPY ./dist/yarn.lock ./package.json ./ -RUN yarn install --production --frozen-lockfile --non-interactive --cache-folder ./.yarnCache; rm -rf ./.yarnCache - -EXPOSE 5140 -CMD [ "npm", "run", "start" ] diff --git a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/README.md b/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/README.md deleted file mode 100644 index 25ab51f302..0000000000 --- a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/README.md +++ /dev/null @@ -1,77 +0,0 @@ - -# `@hyperledger/cactus-plugin-ledger-connector-tcs-huawei-socketio` - -This plugin provides `Cactus` a way to interact with tcs-huawei networks.tcs-huawei (Trusted Cross-chain Service-Huawei) is a blockchain integration service on Huawei Cloud. Using this we can perform: -- `startMonitor`: Start monitoring blocks on the ledgers -- `stopMonitor`: Stop the block monitoring - -## Summary -- [Getting started](#getting-started) -- [Usage samples](#usage-samples) -- [Contributing](#contributing) -- [License](#license) -- [Acknowledgments](#acknowledgments) - -## Getting started - -### Required software components -- OS: Linux (recommended Ubuntu20.04,18.04 or CentOS7) -- Docker (recommend: v17.06.2-ce or greater) -- node.js v16 (recommend: v16 or greater) - -### Prerequisites -- Please ensure that the destination ledger (default: [tcs-huawei](../../tools/docker/tcs-huawei-testnet)) is already launched. - -## Boot methods - -### Common setup -1. Always run configure command first, from the project root directory: - ``` - pushd ../.. - npm run configure - popd - ``` - -1. Copy default configuration -- **Remember to replace default CA and to adjust the `default.yaml` configuration on production deployments!** - ``` - mkdir -p /etc/cactus/connector-tcs-huawei-socketio/ - rm -r /etc/cactus/connector-tcs-huawei-socketio/* - cp -rf ./sample-config/* /etc/cactus/connector-tcs-huawei-socketio/ - ``` - -### Docker -``` -# Build -docker build . -t cactus-plugin-ledger-connector-tcs-huawei-socketio - - -``` - -### Manual -- Ensure ledger ports are exposed to the host first. - -``` -npm run start -``` - -## Usage samples -- To confirm the operation of this package, please refer to the following business-logic sample application: - - [cactus-example-electricity-trade](../../examples/cactus-example-electricity-trade) - -## Contributing - -We welcome contributions to Hyperledger Cactus in many forms, and there's always plenty to do! - -Please review [CONTRIBUTING.md](../../CONTRIBUTING.md) to get started. - -## License - -This distribution is published under the Apache License Version 2.0 found in the [LICENSE](../../LICENSE) file. - -## Acknowledgments diff --git a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/package.json b/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/package.json deleted file mode 100644 index e4594dcb10..0000000000 --- a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/package.json +++ /dev/null @@ -1,79 +0,0 @@ -{ - "name": "@hyperledger/cactus-plugin-ledger-connector-tcs-huawei-socketio", - "version": "2.0.0-rc.3", - "description": "Allows Cactus nodes to connect to a Trusted Cross-chain Service-Huawei", - "keywords": [ - "Hyperledger", - "Cactus", - "Integration", - "Blockchain", - "Distributed Ledger Technology" - ], - "homepage": "https://github.com/hyperledger/cacti#readme", - "bugs": { - "url": "https://github.com/hyperledger/cacti/issues" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/hyperledger/cacti.git" - }, - "license": "Apache-2.0", - "author": { - "name": "Hyperledger Cactus Contributors", - "email": "cactus@lists.hyperledger.org", - "url": "https://www.hyperledger.org/use/cacti" - }, - "contributors": [ - { - "name": "Please add yourself to the list of contributors", - "email": "your.name@example.com", - "url": "https://example.com" - } - ], - "main": "dist/lib/main/typescript/index.js", - "module": "dist/lib/main/typescript/index.js", - "browser": "dist/cactus-plugin-htlc-eth-besu.web.umd.js", - "types": "dist/lib/main/typescript/index.d.ts", - "files": [ - "dist/*" - ], - "scripts": { - "build": "npm run build-ts && npm run build:dev:backend:postbuild", - "build-ts": "tsc", - "build:dev:backend:postbuild": "npm run init", - "debug": "nodemon --inspect ./dist/common/core/bin/www.js", - "init": "cp -af ../../yarn.lock ./dist/yarn.lock", - "start": "cd ./dist && node common/core/bin/www.js" - }, - "dependencies": { - "@types/node": "18.11.9", - "body-parser": "1.20.2", - "cbor": "6.0.1", - "config": "3.3.7", - "cookie-parser": "1.4.6", - "debug": "4.3.1", - "express": "4.19.2", - "js-yaml": "3.14.1", - "jsonwebtoken": "9.0.0", - "log4js": "6.4.1", - "morgan": "1.10.0", - "serve-favicon": "2.4.5", - "shelljs": "0.8.5", - "socket.io": "4.6.2", - "xmlhttprequest": "1.8.0" - }, - "devDependencies": { - "@types/body-parser": "1.19.3", - "@types/config": "0.0.41", - "@types/cookie-parser": "1.4.5", - "@types/express": "4.17.21", - "@types/http-errors": "2.0.1" - }, - "engines": { - "node": ">=18", - "npm": ">=8" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/sample-config/default.yaml b/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/sample-config/default.yaml deleted file mode 100644 index 6d63362cde..0000000000 --- a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/sample-config/default.yaml +++ /dev/null @@ -1,21 +0,0 @@ -sslParam: - port: 5140 - key: "/etc/cactus/connector-tcs-huawei/CA/connector.priv" - cert: "/etc/cactus/connector-tcs-huawei/CA/connector.crt" - clientCert: "/etc/cactus/connector-tcs-huawei/cert.pem" - clientKey: "/etc/cactus/connector-tcs-huawei/key.pem" -blockMonitor: - request: - method: "GET" - host: "https://127.0.0.1:30081/" - getChannelListCommand: "v1/blockcross/channel/list" - getLatestBlockNumberCommand: "blocks?limit=1" - periodicMonitoringCommand1: "blocks?start=" - periodicMonitoringCommand2: "&reverse" - pollingInterval: 5000 -testURL: - request: - method: "GET" - host: "https://relay1/v1/blockcross/channel/list" -logLevel: "debug" -CertCheck: diff --git a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/common/core/app.ts b/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/common/core/app.ts deleted file mode 100644 index 110e6257fd..0000000000 --- a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/common/core/app.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2021 Hyperledger Cactus Contributors - * SPDX-License-Identifier: Apache-2.0 - * - * app.js - */ - -/* Summary: - * - */ - -import type { NextFunction, Request, RequestHandler, Response } from "express"; -import createError = require("http-errors"); -import express = require("express"); -import cookieParser = require("cookie-parser"); -import bodyParser = require("body-parser"); - -const app: express.Express = express(); - -app.use(bodyParser.json()); -app.use(bodyParser.urlencoded({ extended: false })); -app.use(cookieParser() as RequestHandler); - -// catch 404 and forward to error handler -app.use((req: Request, res: Response, next: NextFunction) => { - next(createError(404)); -}); - -// error handler -app.use( - ( - err: { message: string; status?: number }, - req: Request, - res: Response, - next: NextFunction, - ) => { - // set locals, only providing error in development - res.locals.message = err.message; - res.locals.error = req.app.get("env") === "development" ? err : {}; - - // set erreor response - const errorResponse: {} = { - statusCode: err.status || 500, - message: err.message, - }; - - // render the error page - res.status(err.status || 500); - res.send(errorResponse); - }, -); - -export default app; diff --git a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/common/core/bin/www.ts b/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/common/core/bin/www.ts deleted file mode 100644 index 62be3ba22d..0000000000 --- a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/common/core/bin/www.ts +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env node -/* - * Copyright 2021 Hyperledger Cactus Contributors - * SPDX-License-Identifier: Apache-2.0 - * - * www.js - */ - -/* Summary: - * Connector: a part independent of end-chains - */ - -/** - * Module dependencies. - */ - - import app from "../app"; - const debug = require("debug")("connector:server"); - import https = require("https"); - import * as config from "../config"; - import fs = require("fs"); - import { Server } from "socket.io"; - - // Log settings - import { getLogger } from "log4js"; - const logger = getLogger("connector_main[" + process.pid + "]"); - logger.level = config.read('logLevel', 'info'); - - // destination dependency (MONITOR) implementation class - import { ServerMonitorPlugin } from "../../../connector/ServerMonitorPlugin"; - const Smonitor = new ServerMonitorPlugin(); - - /** - * Get port from environment and store in Express. - */ - - const sslport = normalizePort(process.env.PORT || config.read('sslParam.port')); - app.set("port", sslport); - - // Specify private key and certificate - const sslParam = { - key: fs.readFileSync(config.read('sslParam.key')), - cert: fs.readFileSync(config.read('sslParam.cert')), - }; - - /** - * Create HTTPS server. - */ - - const server = https.createServer(sslParam, app); // Start as an https server. - const io = new Server(server); - - /** - * Listen on provided port, on all network interfaces. - */ - - server.listen(sslport, function () { - console.log("listening on *:" + sslport); - }); - server.on("error", onError); - server.on("listening", onListening); - - /** - * Normalize a port into a number, string, or false. - */ - - function normalizePort(val: string) { - const port = parseInt(val, 10); - - if (isNaN(port)) { - // named pipe - return val; - } - - if (port >= 0) { - // port number - return port; - } - - return false; - } - - /** - * Event listener for HTTPS server "error" event. - */ - - function onError(error: any) { - if (error.syscall !== "listen") { - throw error; - } - - const bind = - typeof sslport === "string" ? "Pipe " + sslport : "Port " + sslport; - - // handle specific listen errors with friendly messages - switch (error.code) { - case "EACCES": - console.error(bind + " requires elevated privileges"); - process.exit(1); - break; - case "EADDRINUSE": - console.error(bind + " is already in use"); - process.exit(1); - break; - default: - throw error; - } - } - - /** - * Event listener for HTTPS server "listening" event. - */ - - function onListening() { - const addr = server.address(); - - if (!addr) { - logger.error("Could not get running server address - exit."); - process.exit(1); - } - - const bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port; - debug("Listening on " + bind); - } - - io.on("connection", function (client) { - logger.info("Client " + client.id + " connected."); - - /** - * startMonitor: starting block generation event monitoring - **/ - client.on("startMonitor", function (data) { - Smonitor.startMonitor(client.id, data.filterKey, (callbackData) => { - let emitType = ""; - if (callbackData.status == 200) { - emitType = "eventReceived"; - logger.info("event data callbacked."); - } else { - emitType = "monitor_error"; - } - client.emit(emitType, callbackData); - }); - }); - }); \ No newline at end of file diff --git a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/common/core/config.ts b/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/common/core/config.ts deleted file mode 100644 index 327e7efb4f..0000000000 --- a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/common/core/config.ts +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2021 Hyperledger Cactus Contributors - * SPDX-License-Identifier: Apache-2.0 - * - * config.js - */ - -// TODO - Common - -export const DEFAULT_NODE_CONFIG_DIR = "/etc/cactus/connector-tcs-huawei/"; -if (!process.env["NODE_CONFIG_DIR"]) { - // Must be set before import config - process.env["NODE_CONFIG_DIR"] = DEFAULT_NODE_CONFIG_DIR; -} - -import config from "config"; - -/** - * Get configuration entry (uses node-config setup) - * - * @param key : Key to retrieve - * @param defaultValue : Value to return if key is not present in the config. - * @returns : Configuration value - */ -export function read(key: string, defaultValue?: T): T { - if (config.has(key)) { - return config.get(key); - } - - if (defaultValue) { - return defaultValue; - } - - throw Error( - `Missing configuration entry '${key}', config dir = ${process.env["NODE_CONFIG_DIR"]}`, - ); -} diff --git a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/connector/PluginUtil.ts b/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/connector/PluginUtil.ts deleted file mode 100644 index e495670453..0000000000 --- a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/connector/PluginUtil.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2021 Hyperledger Cactus Contributors - * SPDX-License-Identifier: Apache-2.0 - * - * PluginUtil.js - */ - -const cbor = require("cbor"); - -/* - * Summary: - * Cooperation server: utility library dependent on endchains - * For example, implementing internal functions that should not be exposed as functions of server plugins. - */ - -/* - * convNum - * - * @param {String/Number} value: The scientific string or numeric value to be converted. For numbers, it is returned as is. - * @param {String/Number} defaultValue: The value to use if conversion was not possible. Text or number in scientific notation. Optional. - * - * @return {Number} The value converted to a number, or the defaultValue if the conversion failed. - * - * @desc exponentiation is also supported. The following formats are supported:. (value, defaultValue) - * 3.78*10^14 - * 3.78e14 - */ -exports.convNum = function convNum( - value: number | string, - defaultValue: number | string, -) { - let retValue = 0; - let defValue = 0; - - switch (typeof defaultValue) { - case "number": - defValue = defaultValue; - break; - case "string": - const defValueStr = defaultValue.replace(/\*10\^/g, "e"); - defValue = parseFloat(defValueStr); - break; - default: - // undefined should also be included here. - // Fixed value because of cumbersome handling. - defValue = 0; - break; - } // switch(typeof(defaultValue)) - - if (Number.isNaN(defValue)) { - // number is guaranteed. - defValue = 0; - } - - switch (typeof value) { - case "number": - retValue = value; - break; - case "string": - const valueStr = value.replace(/\*10\^/g, "e"); - retValue = parseFloat(valueStr); - break; - default: - // Set default value. - retValue = defValue; - break; - } // switch(typeof(value)) - - if (Number.isNaN(retValue)) { - // number is guaranteed. - retValue = defValue; - } - - return retValue; -}; - -exports.convertBlockNumber = function (value: number) { - return "0x" + ("0000000000000000" + value.toString(16)).substr(-16); -}; - -exports.decodeBase64 = function (encoded: string): Buffer { - return Buffer.from(encoded, "base64"); -}; - -exports.deccodeCbor = function (encoded: any): Array { - return cbor.decodeAllSync(encoded); -}; diff --git a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/connector/ServerMonitorPlugin.ts b/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/connector/ServerMonitorPlugin.ts deleted file mode 100644 index 81799d552d..0000000000 --- a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/connector/ServerMonitorPlugin.ts +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright 2021 Hyperledger Cactus Contributors - * SPDX-License-Identifier: Apache-2.0 - * - * ServerMonitorPlugin.js - */ - -/* - * Summary: - * Connector: monitoring class of a part dependent on end-chains - * Used in the case of monitoring continuously. - * Processing that ends with the acceptance of a single event is handled by a custom function implementation in server plugins. - * Unlike server plugins, it basically does not handle its own functions. - */ - -// configuration file -const SplugUtil = require("./PluginUtil"); -import * as config from "../common/core/config"; -// Log settings -import { getLogger } from "log4js"; -const logger = getLogger("ServerMonitorPlugin[" + process.pid + "]"); -logger.level = config.read("logLevel", "info"); -// utility -import { ValidatorAuthentication } from "./ValidatorAuthentication"; -const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; - -import https from "https"; -import fs = require("fs"); - -export type MonitorCallback = (callback: { - status: number; - blockData: string; -}) => void; - -/* - * ServerMonitorPlugin - * Class definitions of server monitoring - */ -export class ServerMonitorPlugin { - currentBlockNumber: number; - - /* - * constructors - */ - constructor() { - // Define dependent specific settings - this.currentBlockNumber = -1; - } - - /* - * startMonitor - * Start Monitoring - * @param {string} clientId: Client ID from which monitoring start request was made - * @param {string} filterKey: Key to filter blocks - * @param {function} cb: A callback function that receives monitoring results at any time. - */ - startMonitor(clientId: string, filterKey: string, cb: MonitorCallback) { - const request_blocknum_body = JSON.stringify({ - to_chain: "B0123456789012345678901234567890123456789", - from_chaincode_id: "QueryChainCode", - to_chaincode_id: "QueryChainCode", - to_query_func_name: "QueryBlockNum", - args: ["a"], - }); - //- (not recommended - only for development): Temporarily set CertCheck to false when using a self-signed certificate - let CertCheck = config.read("CertCheck"); - if (CertCheck == undefined) { - CertCheck = true; - } - const options: https.RequestOptions = { - hostname: "agent", - port: 8080, - path: "/v1/cross/transaction/query", - method: "POST", - headers: { - "Content-Type": "text/plain", - "Content-Length": Buffer.byteLength(request_blocknum_body), - }, - cert: fs.readFileSync(config.read("sslParam.clientCert")), - key: fs.readFileSync(config.read("sslParam.clientKey")), - rejectUnauthorized: CertCheck, - }; - - let resData; - let blockNum; - const that = this; - const req = https.request(options, (res) => { - res.on("data", (d) => { - resData = JSON.parse(d); - that.currentBlockNumber = resData.data.payload; - setInterval(function () { - that.periodicMonitoring(clientId, filterKey, cb); - }, 2000); - }); - }); - - req.write(request_blocknum_body); - - req.on("error", (error) => { - logger.error(error); - }); - req.end(); - - logger.info("*** START MONITOR ***"); - logger.info("Client ID :" + clientId); - logger.debug(`filterKey = ${filterKey}`); - } - - /* - * periodicMonitoring - * Periodic monitoring - * @param {string} clientId: Client ID from which monitoring start request was made - * @param {string} filterKey: Key to filter blocks - * @param {function} cb: A callback function that receives monitoring results at any time. - */ - periodicMonitoring(clientId: string, filterKey: string, cb: MonitorCallback) { - let targetBlockNum: number = this.currentBlockNumber; - targetBlockNum++; - const request_block_body = JSON.stringify({ - to_chain: "B0123456789012345678901234567890123456789", - from_chaincode_id: "QueryChainCode", - to_chaincode_id: "QueryChainCode", - to_query_func_name: "GetBlockByNumber", - args: [targetBlockNum.toString()], - }); - let CertCheck = config.read("CertCheck"); - if (CertCheck == undefined) { - CertCheck = true; - } - const options: https.RequestOptions = { - hostname: "agent", - port: 8080, - path: "/v1/cross/transaction/query", - method: "POST", - headers: { - "Content-Type": "text/plain", - "Content-Length": Buffer.byteLength(request_block_body), - }, - cert: fs.readFileSync(config.read("sslParam.clientCert")), - key: fs.readFileSync(config.read("sslParam.clientKey")), - rejectUnauthorized: CertCheck, - }; - - let resData; - const transactionDataArray: any[] = []; - const that = this; - const req = https.request(options, (res) => { - res.on("data", (d) => { - resData = JSON.parse(d); - if (resData.error_message == "block not found") { - logger.debug("block not found, continue to poll"); - return; - } - const payload = JSON.parse(resData.data.payload); - if (payload.Header.BlockNum != targetBlockNum) { - logger.error( - "expected ", - targetBlockNum, - " get ", - payload.Header.BlockNum, - ); - return; - } - for (const transaction of payload.Data) { - transactionDataArray.push(transaction); - } - if (this.currentBlockNumber < targetBlockNum) { - this.currentBlockNumber = targetBlockNum; - } - if (transactionDataArray.length > 0) { - logger.info("*** SEND TRANSACTION DATA ***"); - logger.debug( - `transactionDataArray = ${JSON.stringify(transactionDataArray)}`, - ); - const signedTransactionDataArray = ValidatorAuthentication.sign({ - blockData: transactionDataArray, - }); - logger.debug( - `signedTransactionDataArray = ${signedTransactionDataArray}`, - ); - const retObj = { - status: 200, - blockData: signedTransactionDataArray, - }; - cb(retObj); - } - this.currentBlockNumber + 1; - }); - }); - - req.write(request_block_body); - - req.on("error", (error) => { - logger.error(error); - }); - req.end(); - } -} diff --git a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/connector/ValidatorAuthentication.ts b/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/connector/ValidatorAuthentication.ts deleted file mode 100644 index 4ab02e4521..0000000000 --- a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/src/main/typescript/connector/ValidatorAuthentication.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2020-2021 Hyperledger Cactus Contributors - * SPDX-License-Identifier: Apache-2.0 - * - * ValidatorAuthentication.ts - */ - -const fs = require("fs"); -const path = require("path"); -const jwt = require("jsonwebtoken"); -import * as config from "../common/core/config"; -import { getLogger } from "log4js"; -const logger = getLogger("ValidatorAuthentication[" + process.pid + "]"); -logger.level = config.read("logLevel", "info"); - -const privateKey = fs.readFileSync( - path.resolve(__dirname, config.read("sslParam.key")), -); - -export class ValidatorAuthentication { - static sign(payload: object): string { - const option = { - algorithm: "ES256", - expiresIn: "1000", - }; - - // logger.debug(`payload = ${JSON.stringify(payload)}`); - const signature: string = jwt.sign(payload, privateKey, option); - // logger.debug(`signature = ${signature}`); - logger.debug(`signature: OK`); - return signature; - } -} diff --git a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/tsconfig.json b/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/tsconfig.json deleted file mode 100644 index 9eec1442cb..0000000000 --- a/packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/tsconfig.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "compilerOptions": { - "composite": true, - "outDir": "./dist/lib/", - "declarationDir": "dist/lib", - "resolveJsonModule": true, - "rootDir": "./src", - "sourceMap": false, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "tsBuildInfoFile": "../../.build-cache/cactus-plugin-ledger-connector-tcs-huawei-socketio.tsbuildinfo" - }, - "include": [ - "./src/main/typescript/common/core/*.ts", - "./src/main/typescript/common/core/bin/*.ts", - "./src/main/typescript/common/core/config/*.ts", - "./src/main/typescript/connector/*.ts" - ] -} diff --git a/tsconfig.json b/tsconfig.json index 6c1da3f0cb..ce7a9f42f8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -76,9 +76,6 @@ { "path": "./packages/cactus-plugin-ledger-connector-cdl/tsconfig.json" }, - { - "path": "./packages/cactus-plugin-ledger-connector-tcs-huawei-socketio/tsconfig.json" - }, { "path": "./packages/cactus-plugin-ledger-connector-xdai/tsconfig.json" }, diff --git a/yarn.lock b/yarn.lock index a7f5a3dca4..804380647b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10495,33 +10495,6 @@ __metadata: languageName: unknown linkType: soft -"@hyperledger/cactus-plugin-ledger-connector-tcs-huawei-socketio@workspace:packages/cactus-plugin-ledger-connector-tcs-huawei-socketio": - version: 0.0.0-use.local - resolution: "@hyperledger/cactus-plugin-ledger-connector-tcs-huawei-socketio@workspace:packages/cactus-plugin-ledger-connector-tcs-huawei-socketio" - dependencies: - "@types/body-parser": "npm:1.19.3" - "@types/config": "npm:0.0.41" - "@types/cookie-parser": "npm:1.4.5" - "@types/express": "npm:4.17.21" - "@types/http-errors": "npm:2.0.1" - "@types/node": "npm:18.11.9" - body-parser: "npm:1.20.2" - cbor: "npm:6.0.1" - config: "npm:3.3.7" - cookie-parser: "npm:1.4.6" - debug: "npm:4.3.1" - express: "npm:4.19.2" - js-yaml: "npm:3.14.1" - jsonwebtoken: "npm:9.0.0" - log4js: "npm:6.4.1" - morgan: "npm:1.10.0" - serve-favicon: "npm:2.4.5" - shelljs: "npm:0.8.5" - socket.io: "npm:4.6.2" - xmlhttprequest: "npm:1.8.0" - languageName: unknown - linkType: soft - "@hyperledger/cactus-plugin-ledger-connector-xdai@npm:2.0.0-rc.3, @hyperledger/cactus-plugin-ledger-connector-xdai@workspace:packages/cactus-plugin-ledger-connector-xdai": version: 0.0.0-use.local resolution: "@hyperledger/cactus-plugin-ledger-connector-xdai@workspace:packages/cactus-plugin-ledger-connector-xdai" @@ -16528,13 +16501,6 @@ __metadata: languageName: node linkType: hard -"@types/config@npm:0.0.41": - version: 0.0.41 - resolution: "@types/config@npm:0.0.41" - checksum: 10/528eb5e5d60c48cf82a2b0988ee1e5e088472698ad25944131b0ba87b2e3bb0989f3b4d45edb9d49eefcc8bf158c267905c386aaec15857b9fb24be449c3f27c - languageName: node - linkType: hard - "@types/config@npm:3.3.0": version: 3.3.0 resolution: "@types/config@npm:3.3.0" @@ -16954,7 +16920,7 @@ __metadata: languageName: node linkType: hard -"@types/http-errors@npm:*, @types/http-errors@npm:2.0.1": +"@types/http-errors@npm:*": version: 2.0.1 resolution: "@types/http-errors@npm:2.0.1" checksum: 10/3bb0c50b0a652e679a84c30cd0340d696c32ef6558518268c238840346c077f899315daaf1c26c09c57ddd5dc80510f2a7f46acd52bf949e339e35ed3ee9654f @@ -22387,16 +22353,6 @@ __metadata: languageName: node linkType: hard -"cbor@npm:6.0.1": - version: 6.0.1 - resolution: "cbor@npm:6.0.1" - dependencies: - bignumber.js: "npm:^9.0.1" - nofilter: "npm:^1.0.4" - checksum: 10/bcc41e3af491a01316bf849293332000b9bc754572ef99a5c6f076eace208366493e5f96f7fb35827f4cbf495c0fb16684fe86dea91be444d42eb4cfed9868e2 - languageName: node - linkType: hard - "cbor@npm:9.0.1": version: 9.0.1 resolution: "cbor@npm:9.0.1" @@ -25050,18 +25006,6 @@ __metadata: languageName: node linkType: hard -"debug@npm:4.3.1": - version: 4.3.1 - resolution: "debug@npm:4.3.1" - dependencies: - ms: "npm:2.1.2" - peerDependenciesMeta: - supports-color: - optional: true - checksum: 10/37b9f90428b65e59eb47f74435a9fc73dcb46b3550e838c0037ac05910f689bd59fd1d4a51154c1df3471a2f3e5926af8880cbe9f9f3b68beb7b2f8197a26f4a - languageName: node - linkType: hard - "debug@npm:4.3.5, debug@npm:~4.3.4": version: 4.3.5 resolution: "debug@npm:4.3.5" @@ -47089,13 +47033,6 @@ __metadata: languageName: node linkType: hard -"safe-buffer@npm:5.1.1": - version: 5.1.1 - resolution: "safe-buffer@npm:5.1.1" - checksum: 10/e8acac337b7d7e108fcfe2b8b2cb20952abb1ed11dc60968b7adffb19b9477893d44136987a420f90ff4d7a0a1a932f147b3a222f73001f59fb4822097a1616d - languageName: node - linkType: hard - "safe-buffer@npm:5.1.2, safe-buffer@npm:~5.1.0, safe-buffer@npm:~5.1.1": version: 5.1.2 resolution: "safe-buffer@npm:5.1.2" @@ -47640,19 +47577,6 @@ __metadata: languageName: node linkType: hard -"serve-favicon@npm:2.4.5": - version: 2.4.5 - resolution: "serve-favicon@npm:2.4.5" - dependencies: - etag: "npm:~1.8.1" - fresh: "npm:0.5.2" - ms: "npm:2.0.0" - parseurl: "npm:~1.3.2" - safe-buffer: "npm:5.1.1" - checksum: 10/ee5ac9c055a062a0d39af45aa6a0d34e8641119366283214b732e1780f48e3c0c1082cc0f6e12a4b8ceaf104a0f858ce91b8c76a39a543ca5f7606cdb90db92a - languageName: node - linkType: hard - "serve-index@npm:^1.9.1": version: 1.9.1 resolution: "serve-index@npm:1.9.1"