Socket
Socket
Sign inDemoInstall

@hyperledger/cactus-api-client

Package Overview
Dependencies
185
Maintainers
3
Versions
53
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @hyperledger/cactus-api-client

Universal library used by both front end and back end components of Cactus. Aims to be a developer swiss army knife.


Version published
Weekly downloads
76
decreased by-55.29%
Maintainers
3
Created
Weekly downloads
 

Changelog

Source

2.0.0-alpha.2 (2023-09-27)

Bug Fixes

  • besu: testnet web3 version fixed to 1.10.0 (334612d)
  • cactus-core-api: address CVE-2021-38192 - GHSA-x4qm-mcjq-v2gf (ff1afa5), closes #2612
  • cactus-validator-socketio-indy: upgrade pyjwt to 2.4.0 (59f9f91), closes #2614
  • cmd-api-server: fix CVE-2023-36665 protobufjs Prototype Pollution vuln (7bb3957), closes #2682
  • connector-fabric: runTransactionV1 Open API validation crash (516dd49)
  • ejs critical vulnerability CVE-2022-29078 (2813b75)
  • indy-validator: fix package dependencies (a28641a), closes #2596
  • plugin-odap-hermes: fix duplicate enum values of OdapMessageType (292d287), closes #2553
  • security: crash in HeaderParser in dicer (77fb559)
  • security: the CVE-2022-2421 - upgrade socket.io-parser to >=4.2.1 (9172172), closes #2229 #2228
  • security: upgrade fabric 2.x deps to 2.2.18 (36988a5), closes #2610
  • security: vulnerabilities found in cactus-whitepaper (c56334d), closes #2038
  • tessera: updated tessera version error in quorum-all-in-one #2411 (759f305), closes #2240 #2274
  • use common conventions: tsconfig.json, package.json (50f5c02), closes #2216
  • vscode/devcontainer: unexpected exit stdout /etc/passwd (eb0134b), closes #2404
  • weaver-corda: throw error correctly in responder flows (b888a5e)
  • webpack: fix broken bundling - cannot find webpack.config.js (794f0b4)

Code Refactoring

  • cmd-api-server: clean up configuration parameters #720 (b8e8388)

Features

  • besu-test-ledger: send funds to already created address (3a58508), closes #2250
  • cacti-cmd-gui-app: add GUI to visualize Fabric, Ethereum blocks (15d9e9d)
  • cactus-common: add createRuntimeErrorWithCause() & newRex() (b3a508c), closes #1702
  • cactus-core: add GetOpenApiSpecV1EndpointBase<S, P> class (6d68292)
  • cactus-plugin-ledger-connector-cdl-socketio: add new connector plugin (aee28fe), closes #2455
  • cactus-plugin-ledger-connector-ethereum: add new connector plugin (f8a2131), closes #2534
  • cbdc-bridging-app: implementation of CBDC bridging example (ca1b3be), closes #2205
  • cmd-api-server: add GetOpenApiSpecV1Endpoint (HTTP GET) (aeebbd4)
  • connector-besu: add GetOpenApiSpecV1Endpoint (HTTP GET) (76744f0)
  • connector-iroha2: update to the new LTS image as of 28.07.2023 (ccdaa12)
  • connector-quorum: add WebsocketProvider options to quorum LP (b7ad571)
  • connector-tcs-huawei: add initial version (d8d538d)
  • corda asset transfer test workflow added and bug fixes (4b5ee09)
  • fabric-test-ledger: add support to enrolling users in different Orgs (b910681), closes #2248
  • geth-all-in-one: add ethereum test image and helper class (fb4231f), closes #2577
  • openapi: upgrade to 6.3.0 phase1 (a094614), closes #2298
  • plugin-htlc-eth-besu: add private HTLCs and forge build & test (aade510)
  • plugin-persistence-fabric: add new fabric persistence plugin (47a64ee), closes #2259 #2265
  • quorum-connector: add script for checking connection status (d306d21), closes #2309
  • quorum: private transaction support (3c944d6)
  • weaver-corda: support array of remote views, consequent user flow call (a8e5d54)
  • weaver/common: add data view protocol buffer spec & RFCs for Besu (97f17e0)
  • weaver: added multiple participants support for data sharing in corda (4e81b92)

BREAKING CHANGES

  • cmd-api-server: Removed the keyPairPem parameter from the API server configuration.

Readme

Source

@hyperledger/cactus-api-client

Summary

The Hyperledger Cactus API Client package is designed to be a generic extension with convenience features wrapped around the [typescript-axios flavored API clients](https://github.com/OpenAPITools/openapi-generator/blob/v5.2.1/docs/generators/typescript-axios.md) that we auto-generate and ship with each web service-enabled plugin such as the API clients of the

The code generation for the listed code folders above is done by the OpenAPI Generator tool that can convert OpenAPI V3 json specifications of ours straight into the program code of the API clients.

The above means that the ApiClient class is not the one containing the implementation responsible for executing all the supported API calls by a Cactus node (which would make it a monolith, something that we try to avoid as it is the opposite of a flexible plugin architecture)

For example you can use the @hyperledger/cactus-api-client node package to perform Cactus node discovery based on ledger IDs (that can be obtained from the ConsortiumDatabase as defined by the generated models of the @hyperledger/cactus-core-api package.

While you can generate API Clients for the Cactus API specifications in any supported langauge of the OpenAPI Generator the features provided by this package will have to be developed separately (if not already done by the Cactus maintainers). Currently the only implementation of the abstract API Client and its features (node discovery) is in Typescript (e.g. the @hyperledger/cactus-api-client package).

Usage

Routing to Cactus Node with connector to specific ledger

Let's say you have a consortium with several members who all have their own ledgers deployed as well. The ConsortiumDatabase will therefore contain the entities pertaining to these entities (such as the ledgers or the members themselves) meaning that if you are developing an application that needs to perform operations on one of the ledgers in the consortium then you have a couple of different ways of obtaining an API client to do just that:

Leverage the ConsortiumDatabase for discovery
import { ApiClient } from "@hyperledger/cactus-api-client";

import { ConsortiumDatabase, Ledger, LedgerType } from "@hyperledger/cactus-core-api";

import { PluginRegistry } from "@hyperledger/cactus-core";

import { DefaultApi as QuorumApi } from "@hyperledger/cactus-plugin-ledger-connector-quorum";

const mainFn = async () => {
  const ledgerId = "theIdOfYourLedgerInTheConsortiumDatabase";

  // How you obtain a consortium provider is dependent on which consortium
  // plugin you use and your exact deployment scenario
  const consortiumProvider: IAsyncProvider<ConsortiumDatabase> = ...;
  const consortiumDatabase: ConsortiumDatabase = await consortiumProvider.get();
  const consortium = consortiumDatabase.consortium[0];

  const mainApiClient = new ApiClient({ basePath: consortium.mainApiHost });

  // This client is now configured to point to a node that has a connector to
  // the ledger referenced by `ledgerId`
  const apiClient = await mainApiClient.ofLedger(ledgerId, QuorumApi);

  // Use the client to perform any supported operation on the ledger
};

mainFn();
Use a provided mainApiHost and ledgerId
import { ApiClient } from "@hyperledger/cactus-api-client";

import { ConsortiumDatabase, Ledger, LedgerType } from "@hyperledger/cactus-core-api";

import { PluginRegistry } from "@hyperledger/cactus-core";

import { DefaultApi as QuorumApi } from "@hyperledger/cactus-plugin-ledger-connector-quorum";

const mainFn = async () => {
  const ledgerId = "theIdOfYourLedgerInTheConsortiumDatabase";
  const consortiumMainApiHost = "https://cactus.example.com";

  const mainApiClient = new ApiClient({ basePath: consortiumMainApiHost });

  // This client is now configured to point to a node that has a connector to
  // the ledger referenced by `ledgerId`
  const apiClient = await mainApiClient.ofLedger(ledgerId, QuorumApi);
}

mainFn();
Use the API host of a node directly
import { ApiClient } from "@hyperledger/cactus-api-client";

import { ConsortiumDatabase, Ledger, LedgerType } from "@hyperledger/cactus-core-api";

import { PluginRegistry } from "@hyperledger/cactus-core";

import { DefaultApi as QuorumApi } from "@hyperledger/cactus-plugin-ledger-connector-quorum";

const mainFn = async () => {
  const nodeApiHost = "https://my-node.cactus.example.com";

  const mainApiClient = new ApiClient({ basePath: nodeApiHost });

  // This client is now configured to point to a node that has a connector to the ledger of your choice
  const apiClient = await mainApiClient.extendWith(QuorumApi);
}

mainFn();

Public API Surface

DefaultConsortiumProvider

Builds the default Consortium provider that can be used by this object to retrieve the Cactus Consortium metadata object when necessary (one such case is when we need information about the consortium nodes to perform routing requests to a specific ledger via a connector plugin, but later other uses could be added as well).

The DefaultConsortiumProvider class leverages the simplest consortium plugin that we have at the time of this writing: @hyperledger/cactus-plugin-consortium-manual which holds the consortium metadata as pre-configured by the consortium operators.

The pattern we use in the ApiClient class is that you can inject your own IAsyncProvider<Consortium> implementation which then will be used for routing information and in theory you can implement completely arbitrary consortium management in your own consortium plugins which then Cactus can use and leverage for the routing. This allows us to support any exotic consortium management algorithms that people may come up with such as storing the consortium definition in a multi-sig smart contract or have the list of consortium nodes be powered by some sort of automatic service discovery or anything else that people might think of.

ApiClient

Class responsible for providing additional functionality to the DefaultApi classes of the generated clients (OpenAPI generator / typescript-axios).

Each package (plugin) can define it's own OpenAPI spec which means that they all can ship with their own DefaultApi class that is generated directly from the respective OpenAPI spec of the package/plugin.

The functionality provided by this class is meant to be common traints that can be useful for all of those different DefaultApi implementations.

One such common trait is the client side component of the routing that decides which Cactus node to point the ApiClient towards (which is in itself ends up being the act of routing).

@see — https ://github.com/OpenAPITools/openapi-generator/blob/v5.0.0-beta2/modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache#L337

@see — https ://github.com/OpenAPITools/openapi-generator/blob/v5.0.0/docs/generators/typescript-axios.md

Keywords

FAQs

Last updated on 04 Oct 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc