From e408284b700e24667e09b8b3745d9ee58137e2fc Mon Sep 17 00:00:00 2001 From: zondervancalvez Date: Thu, 24 Feb 2022 14:12:49 +0800 Subject: [PATCH] fix(security): address CVE-2021-23358 fixes: hyperledger#1775 fixes: hyperledger#1775 Signed-off-by: zondervancalvez --- .../cactus-plugin-htlc-eth-besu/package.json | 2 +- .../package.json | 4 +- .../plugin-ledger-connector-besu.ts | 34 +- .../package.json | 2 +- .../package.json | 2 +- .../get-transaction-endpoint.test.ts | 13 +- .../sign-transaction-endpoint.test.ts | 13 +- .../v21-get-balance-endpoint.test.ts | 13 +- .../v21-get-past-logs-endpoint.test.ts | 13 +- .../v21-get-transaction-endpoint.test.ts | 13 +- .../v21-sign-transaction-endpoint.test.ts | 13 +- typings/web3js-quorum/index.d.ts | 490 ++++++++++++++++++ 12 files changed, 573 insertions(+), 39 deletions(-) create mode 100644 typings/web3js-quorum/index.d.ts diff --git a/packages/cactus-plugin-htlc-eth-besu/package.json b/packages/cactus-plugin-htlc-eth-besu/package.json index 951b12c4dff..5be1be7ab86 100644 --- a/packages/cactus-plugin-htlc-eth-besu/package.json +++ b/packages/cactus-plugin-htlc-eth-besu/package.json @@ -86,7 +86,7 @@ "openapi-types": "9.1.0", "typescript-optional": "2.0.1", "web3": "1.5.2", - "web3-eea": "0.11.0" + "web3js-quorum": "21.7.0-rc1" }, "devDependencies": { "@hyperledger/cactus-plugin-keychain-memory": "1.0.0-rc.3", diff --git a/packages/cactus-plugin-ledger-connector-besu/package.json b/packages/cactus-plugin-ledger-connector-besu/package.json index 64bd261f18c..4de81e765cd 100644 --- a/packages/cactus-plugin-ledger-connector-besu/package.json +++ b/packages/cactus-plugin-ledger-connector-besu/package.json @@ -83,9 +83,9 @@ "typescript-optional": "2.0.1", "web3": "1.5.2", "web3-core": "1.5.2", - "web3-eea": "0.11.0", "web3-eth": "1.5.2", - "web3-utils": "1.5.2" + "web3-utils": "1.5.2", + "web3js-quorum": "21.7.0-rc1" }, "devDependencies": { "@hyperledger/cactus-plugin-keychain-memory": "1.0.0-rc.3", diff --git a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/plugin-ledger-connector-besu.ts b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/plugin-ledger-connector-besu.ts index a2931f12bc8..ea258e432d2 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/plugin-ledger-connector-besu.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/plugin-ledger-connector-besu.ts @@ -11,7 +11,8 @@ import OAS from "../json/openapi.json"; import Web3 from "web3"; import type { WebsocketProvider } from "web3-core"; -import EEAClient, { ICallOptions, IWeb3InstanceExtended } from "web3-eea"; +//import EEAClient, { ICallOptions, IWeb3InstanceExtended } from "web3-eea"; +import Web3JsQuorum, { IWeb3Quorum } from "web3js-quorum"; import { Contract, ContractSendMethod } from "web3-eth-contract"; import { TransactionReceipt } from "web3-eth"; @@ -120,7 +121,7 @@ export class PluginLedgerConnectorBesu private readonly log: Logger; private readonly web3Provider: WebsocketProvider; private readonly web3: Web3; - private web3EEA: IWeb3InstanceExtended | undefined; + private web3Quorum: IWeb3Quorum | undefined; private readonly pluginRegistry: PluginRegistry; private contracts: { [name: string]: Contract; @@ -183,8 +184,7 @@ export class PluginLedgerConnectorBesu } public async onPluginInit(): Promise { - const chainId = await this.web3.eth.getChainId(); - this.web3EEA = EEAClient(this.web3, chainId); + this.web3Quorum = Web3JsQuorum(this.web3); } public async shutdown(): Promise { @@ -428,18 +428,19 @@ export class PluginLedgerConnectorBesu privateKey: privKey, privateFor: req.privateTransactionConfig.privateFor, }; - if (!this.web3EEA) { - throw new RuntimeError(`InvalidState: web3EEA not initialized.`); + if (!this.web3Quorum) { + throw new RuntimeError(`InvalidState: web3Quorum not initialized.`); } - const privacyGroupId = this.web3EEA.priv.generatePrivacyGroup(fnParams); + const privacyGroupId = this.web3Quorum.utils.generatePrivacyGroup( + fnParams, + ); this.log.debug("Generated privacyGroupId: ", privacyGroupId); - callOutput = await this.web3EEA.priv.call({ - privacyGroupId, + callOutput = await this.web3Quorum.priv.call(privacyGroupId, { to: contractInstance.options.address, data, // TODO: Update the "from" property of ICallOptions to be optional - } as ICallOptions); + }); success = true; this.log.debug(`Web3 EEA Call output: `, callOutput); @@ -593,11 +594,13 @@ export class PluginLedgerConnectorBesu public async transactPrivate(options: any): Promise { const fnTag = `${this.className}#transactPrivate()`; - if (!this.web3EEA) { + if (!this.web3Quorum) { throw new Error(`${fnTag} Web3 EEA client not initialized.`); } - const txHash = await this.web3EEA.eea.sendRawTransaction(options); + const txHash = await this.web3Quorum.priv.generateAndSendRawTransaction( + options, + ); if (!txHash) { throw new Error(`${fnTag} eea.sendRawTransaction provided no tx hash.`); @@ -611,13 +614,12 @@ export class PluginLedgerConnectorBesu ): Promise { const fnTag = `${this.className}#getPrivateTxReceipt()`; - if (!this.web3EEA) { - throw new Error(`${fnTag} Web3 EEA client not initialized.`); + if (!this.web3Quorum) { + throw new Error(`${fnTag} Web3 Quorum client not initialized.`); } - const txPoolReceipt = await this.web3EEA.priv.getTransactionReceipt( + const txPoolReceipt = await this.web3Quorum.priv.waitForTransactionReceipt( txHash, - privateFrom, ); if (!txPoolReceipt) { throw new RuntimeError(`priv.getTransactionReceipt provided no receipt.`); diff --git a/packages/cactus-test-plugin-htlc-eth-besu/package.json b/packages/cactus-test-plugin-htlc-eth-besu/package.json index 42ad4788e8f..9c7f908c7ad 100644 --- a/packages/cactus-test-plugin-htlc-eth-besu/package.json +++ b/packages/cactus-test-plugin-htlc-eth-besu/package.json @@ -71,7 +71,7 @@ "axios": "0.21.4", "key-encoder": "2.0.3", "web3": "1.5.2", - "web3-eea": "0.11.0" + "web3js-quorum": "21.7.0-rc1" }, "devDependencies": { "@types/express": "4.17.13" diff --git a/packages/cactus-test-plugin-ledger-connector-besu/package.json b/packages/cactus-test-plugin-ledger-connector-besu/package.json index ddfb0da7e49..340ef11beb3 100644 --- a/packages/cactus-test-plugin-ledger-connector-besu/package.json +++ b/packages/cactus-test-plugin-ledger-connector-besu/package.json @@ -68,6 +68,6 @@ "@hyperledger/cactus-test-tooling": "1.0.0-rc.3", "key-encoder": "2.0.3", "web3": "1.5.2", - "web3-eea": "0.11.0" + "web3js-quorum": "21.7.0-rc1" } } diff --git a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-transaction-endpoint.test.ts b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-transaction-endpoint.test.ts index f177a050a7c..9a092967d71 100644 --- a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-transaction-endpoint.test.ts +++ b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-transaction-endpoint.test.ts @@ -5,7 +5,7 @@ import { createServer } from "http"; import KeyEncoder from "key-encoder"; import { AddressInfo } from "net"; import Web3 from "web3"; -import EEAClient, { IWeb3InstanceExtended } from "web3-eea"; +import Web3JsQuorum, { IWeb3Quorum } from "web3js-quorum"; import { ApiServer, @@ -128,7 +128,7 @@ test(testCase, async (t: Test) => { const web3Provider = new Web3.providers.HttpProvider(rpcApiHttpHost); const web3 = new Web3(web3Provider); - const web3Eea: IWeb3InstanceExtended = EEAClient(web3, 2018); + const web3JsQuorum: IWeb3Quorum = Web3JsQuorum(web3); const orionKeyPair = await besuTestLedger.getOrionKeyPair(); const besuKeyPair = await besuTestLedger.getBesuKeyPair(); @@ -145,9 +145,16 @@ test(testCase, async (t: Test) => { privateFor: [orionKeyPair.publicKey], // privateKey: Ethereum private key with which to sign the transaction. privateKey: besuPrivateKey, + gasLimit: "", + gasPrice: "", + privacyGroupId: "", + nonce: "", + to: "", }; - const transactionHash = await web3Eea.eea.sendRawTransaction(contractOptions); + const transactionHash = await web3JsQuorum.priv.generateAndSendRawTransaction( + contractOptions, + ); await web3.eth.getTransaction(transactionHash); diff --git a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/sign-transaction-endpoint.test.ts b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/sign-transaction-endpoint.test.ts index 59bdf4d7de0..02fb90107d8 100644 --- a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/sign-transaction-endpoint.test.ts +++ b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/sign-transaction-endpoint.test.ts @@ -5,7 +5,7 @@ import { createServer } from "http"; import KeyEncoder from "key-encoder"; import { AddressInfo } from "net"; import Web3 from "web3"; -import EEAClient, { IWeb3InstanceExtended } from "web3-eea"; +import Web3JsQuorum, { IWeb3Quorum } from "web3js-quorum"; import { ApiServer, @@ -137,7 +137,7 @@ test(testCase, async (t: Test) => { const web3Provider = new Web3.providers.HttpProvider(rpcApiHttpHost); const web3 = new Web3(web3Provider); - const web3Eea: IWeb3InstanceExtended = EEAClient(web3, 2018); + const web3JsQuorum: IWeb3Quorum = Web3JsQuorum(web3); const orionKeyPair = await besuTestLedger.getOrionKeyPair(); const besuKeyPair = await besuTestLedger.getBesuKeyPair(); @@ -154,9 +154,16 @@ test(testCase, async (t: Test) => { privateFor: [orionKeyPair.publicKey], // privateKey: Ethereum private key with which to sign the transaction. privateKey: besuPrivateKey, + gasLimit: "", + gasPrice: "", + privacyGroupId: "", + nonce: "", + to: "", }; - const transactionHash = await web3Eea.eea.sendRawTransaction(contractOptions); + const transactionHash = await web3JsQuorum.priv.generateAndSendRawTransaction( + contractOptions, + ); const transaction = await web3.eth.getTransaction(transactionHash); const singData = jsObjectSigner.sign(transaction.input); diff --git a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-balance-endpoint.test.ts b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-balance-endpoint.test.ts index 48766eef392..e50f9482522 100644 --- a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-balance-endpoint.test.ts +++ b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-balance-endpoint.test.ts @@ -5,7 +5,7 @@ import { createServer } from "http"; import KeyEncoder from "key-encoder"; import { AddressInfo } from "net"; import Web3 from "web3"; -import EEAClient, { IWeb3InstanceExtended } from "web3-eea"; +import Web3JsQuorum, { IWeb3Quorum } from "web3js-quorum"; import { ApiServer, @@ -131,7 +131,7 @@ test(testCase, async (t: Test) => { const web3Provider = new Web3.providers.HttpProvider(rpcApiHttpHost); const web3 = new Web3(web3Provider); - const web3Eea: IWeb3InstanceExtended = EEAClient(web3, 1337); + const web3JsQuorum: IWeb3Quorum = Web3JsQuorum(web3); const orionKeyPair = await besuTestLedger.getOrionKeyPair(); const besuKeyPair = await besuTestLedger.getBesuKeyPair(); @@ -148,9 +148,16 @@ test(testCase, async (t: Test) => { privateFor: [orionKeyPair.publicKey], // privateKey: Ethereum private key with which to sign the transaction. privateKey: besuPrivateKey, + gasLimit: "", + gasPrice: "", + privacyGroupId: "", + nonce: "", + to: "", }; - const transactionHash = await web3Eea.eea.sendRawTransaction(contractOptions); + const transactionHash = await web3JsQuorum.priv.generateAndSendRawTransaction( + contractOptions, + ); await web3.eth.getTransaction(transactionHash); /* diff --git a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-past-logs-endpoint.test.ts b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-past-logs-endpoint.test.ts index 2ced1d68b38..d9b1b6d5758 100644 --- a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-past-logs-endpoint.test.ts +++ b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-past-logs-endpoint.test.ts @@ -5,7 +5,7 @@ import { createServer } from "http"; import KeyEncoder from "key-encoder"; import { AddressInfo } from "net"; import Web3 from "web3"; -import EEAClient, { IWeb3InstanceExtended } from "web3-eea"; +import Web3JsQuorum, { IWeb3Quorum } from "web3js-quorum"; import { ApiServer, @@ -131,7 +131,7 @@ test(testCase, async (t: Test) => { const web3Provider = new Web3.providers.HttpProvider(rpcApiHttpHost); const web3 = new Web3(web3Provider); - const web3Eea: IWeb3InstanceExtended = EEAClient(web3, 1337); + const web3JsQuorum: IWeb3Quorum = Web3JsQuorum(web3); const orionKeyPair = await besuTestLedger.getOrionKeyPair(); const besuKeyPair = await besuTestLedger.getBesuKeyPair(); @@ -148,9 +148,16 @@ test(testCase, async (t: Test) => { privateFor: [orionKeyPair.publicKey], // privateKey: Ethereum private key with which to sign the transaction. privateKey: besuPrivateKey, + gasLimit: "", + gasPrice: "", + privacyGroupId: "", + nonce: "", + to: "", }; - const transactionHash = await web3Eea.eea.sendRawTransaction(contractOptions); + const transactionHash = await web3JsQuorum.priv.generateAndSendRawTransaction( + contractOptions, + ); await web3.eth.getTransaction(transactionHash); diff --git a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-transaction-endpoint.test.ts b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-transaction-endpoint.test.ts index aaf02f5beef..dc18f2650c0 100644 --- a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-transaction-endpoint.test.ts +++ b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-transaction-endpoint.test.ts @@ -5,7 +5,7 @@ import { createServer } from "http"; import KeyEncoder from "key-encoder"; import { AddressInfo } from "net"; import Web3 from "web3"; -import EEAClient, { IWeb3InstanceExtended } from "web3-eea"; +import Web3JsQuorum, { IWeb3Quorum } from "web3js-quorum"; import { ApiServer, @@ -131,7 +131,7 @@ test(testCase, async (t: Test) => { const web3Provider = new Web3.providers.HttpProvider(rpcApiHttpHost); const web3 = new Web3(web3Provider); - const web3Eea: IWeb3InstanceExtended = EEAClient(web3, 1337); + const web3JsQuorum: IWeb3Quorum = Web3JsQuorum(web3); const orionKeyPair = await besuTestLedger.getOrionKeyPair(); const besuKeyPair = await besuTestLedger.getBesuKeyPair(); @@ -148,9 +148,16 @@ test(testCase, async (t: Test) => { privateFor: [orionKeyPair.publicKey], // privateKey: Ethereum private key with which to sign the transaction. privateKey: besuPrivateKey, + gasLimit: "", + gasPrice: "", + privacyGroupId: "", + nonce: "", + to: "", }; - const transactionHash = await web3Eea.eea.sendRawTransaction(contractOptions); + const transactionHash = await web3JsQuorum.priv.generateAndSendRawTransaction( + contractOptions, + ); await web3.eth.getTransaction(transactionHash); diff --git a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-sign-transaction-endpoint.test.ts b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-sign-transaction-endpoint.test.ts index e84a6fd4d81..50deb65a624 100644 --- a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-sign-transaction-endpoint.test.ts +++ b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-sign-transaction-endpoint.test.ts @@ -5,7 +5,7 @@ import { createServer } from "http"; import KeyEncoder from "key-encoder"; import { AddressInfo } from "net"; import Web3 from "web3"; -import EEAClient, { IWeb3InstanceExtended } from "web3-eea"; +import Web3JsQuorum, { IWeb3Quorum } from "web3js-quorum"; import { ApiServer, @@ -140,7 +140,7 @@ test(testCase, async (t: Test) => { const web3Provider = new Web3.providers.HttpProvider(rpcApiHttpHost); const web3 = new Web3(web3Provider); - const web3Eea: IWeb3InstanceExtended = EEAClient(web3, 1337); + const web3JsQuorum: IWeb3Quorum = Web3JsQuorum(web3); const orionKeyPair = await besuTestLedger.getOrionKeyPair(); const besuKeyPair = await besuTestLedger.getBesuKeyPair(); @@ -157,9 +157,16 @@ test(testCase, async (t: Test) => { privateFor: [orionKeyPair.publicKey], // privateKey: Ethereum private key with which to sign the transaction. privateKey: besuPrivateKey, + gasLimit: "", + gasPrice: "", + privacyGroupId: "", + nonce: "", + to: "", }; - const transactionHash = await web3Eea.eea.sendRawTransaction(contractOptions); + const transactionHash = await web3JsQuorum.priv.generateAndSendRawTransaction( + contractOptions, + ); const transaction = await web3.eth.getTransaction(transactionHash); const singData = jsObjectSigner.sign(transaction.input); diff --git a/typings/web3js-quorum/index.d.ts b/typings/web3js-quorum/index.d.ts new file mode 100644 index 00000000000..85db485152a --- /dev/null +++ b/typings/web3js-quorum/index.d.ts @@ -0,0 +1,490 @@ +declare module "web3js-quorum" { + import {PastLogsOptions} from "web3-core"; + import type Web3 from "web3"; + import type {TransactionConfig, Eth} from "web3-eth"; + import type {Utils} from "web3-utils"; + import * as Buffer from "buffer"; + + + export default function Web3Quorum(web3: Web3, enclaveOptions?: EnclaveOptions, isQuorum?: boolean): IWeb3Quorum; + + export interface IWeb3Quorum extends Web3 { + utils: IUtilsWeb3; + ptm: IPtm + priv: IPrivWeb3; + eth: IEthWeb3; + raft: IRaftWeb3; + istanbul: IIstanbulWeb3; + permission: IPermissionWeb3; + } + + export interface IWeb3Instance { + currentProvider: unknown; + extend: (...args: unknown[]) => T & IWeb3Instance; + } + + export interface EnclaveOptions { + /** + * absolute file path to the ipc of the transaction manager + */ + ipcPath: string + /** + * http url to the transaction manager + */ + privateUrl: string + /** + * TLS configuration for the transaction manager when using HTTPS in privateUrl + * + */ + tlsSettings: TlsSettings + } + + export interface TlsSettings { + /** + * client key buffer + */ + key: Buffer + /** + * client certificate buffer + */ + clcert: Buffer + /** + * CA certificate buffer + */ + cacert: Buffer + allowInsecure: boolean + } + + export interface IUtilsWeb3 extends Utils { + /** + * Generate a privacyGroupId + */ + generatePrivacyGroup(options: IPrivacyOptions): string + + /** + * @function setPrivate + */ + setPrivate(rawTransaction: string): Buffer + } + + export interface IPrivacyOptions { + readonly privateFor: string[]; + readonly privateFrom: string; + } + + export interface IPtm { + send(options: IPtmSend): Promise + + storeRaw(options: IPtmStoreRaw): Promise + + keys(): Promise + + partyInfoKeys(): Promise + + upCheck(): Promise + } + + export interface IPtmSend extends IOptions { + readonly privateFor: string; + } + + export interface IPtmStoreRaw extends IOptions { + } + + interface IOptions { + readonly data: string; + readonly privateFrom: string; + } + + export interface IPrivWeb3 { + call(privacyGroupId: string, call: TransactionConfig, blockNumber?: string): Promise + + debugGetStateRoot(privacyGroupId: string, blockNumber: string | number): Promise + + distributeRawTransaction(transaction: string): Promise; + + /** + * Send the Raw transaction to the Besu node + */ + sendRawTransaction(transaction: string): Promise; + + getEeaTransactionCount(address: string, sender: string, recipients: string[]): Promise + + getFilterChanges(privacyGroupId: string, filterId: string): Promise + + getFilterLogs(privacyGroupId: string, filterId: string): Promise + + getLogs(privacyGroupId: string, filterOptions: PastLogsOptions): Promise + + getPrivacyPrecompileAddress(): Promise + + getPrivateTransaction(transaction: string): Promise + + getTransactionCount(address: string, privacyGroupId: string): Promise; + + /** + * Get the private transaction Receipt. + * @param {String} transactionHash 32-byte hash of a transaction + */ + getTransactionReceipt(transactionHash: string): Promise; + + getCode(privacyGroupId: string, address: string, blockNumber: string | number): Promise + + newFilter(privacyGroupId: string, filter: PastLogsOptions): Promise; + + uninstallFilter(privacyGroupId: string, filter: PastLogsOptions): Promise; + + /** + * Creates an on chain privacy group + */ + createPrivacyGroup(options: ICreatePrivacyGroupOptions): Promise; + + /** + * Returns with the deleted group's ID (same one that was passed in). + */ + deletePrivacyGroup(privacyGroupId: string): Promise; + + /** + * Returns a list of privacy groups containing only the listed members. + * For example, if the listed members are A and B, a privacy group + * containing A, B, and C is not returned. + */ + findPrivacyGroup(members: string[]): Promise; + + subscribe(privacyGroupId: string, type: string, filter: Object): Promise; + + unsubscribe(privacyGroupId: string, subscriptionId: string): Promise; + + waitForTransactionReceipt(txHash: string, retries?: number, delay?: number): Promise + + generateAndDistributeRawTransaction(options: IDistributeRawTransaction): Promise + + generateAndSendRawTransaction(options: ISendRawTransaction): Promise + + subscribeWithPooling(privacyGroupId: string, filter: Object, callback: (error, result) => any): Promise + } + + export interface IPrivacyGroup { + readonly privacyGroupId: string; + readonly type: PrivacyGroupType; + readonly name: string; + readonly description: string; + readonly members: string[]; + } + + export const enum PrivacyGroupType { + LEGACY, + ONCHAIN, + PANTHEON + } + + export interface ICreatePrivacyGroupOptions { + readonly addresses: string[]; + readonly name?: string; + readonly description?: string; + } + + interface IBasicPrivateTransaction { + /** + * Data, 20 bytes Address of the sender. + */ + readonly from: string; + /** + * Data, 20 bytes Address of the receiver, if sending ether, otherwise, null. + */ + readonly to: string; + /** + * Data, 32 bytes Tessera public key of the sender. + */ + readonly privateFrom: string; + /** + * or privacyGroupId Array or Data, 32 bytes Tessera public keys or privacy group ID of the recipients. + */ + readonly privateFor: string | string[]; + } + + export interface IPrivateTransactionReceipt extends IBasicPrivateTransaction { + /** + * Data, 32 bytes Hash of block containing this transaction. + */ + readonly blockHash: string; + /** + * Quantity Block number of block containing this transaction. + */ + readonly blockNumber: number; + /** + * Data, 20 bytes Contract address created if a contract creation transaction, otherwise, null. + */ + readonly contractAddress: string; + /** + * Array Array of log objects generated by this private transaction. + */ + readonly logs: Array; + /** + * Data, 256 bytes Bloom filter for light clients to quickly retrieve related logs. + */ + readonly logsBloom: string; + /** + * Data, 32 bytes Hash of the private transaction. + */ + readonly transactionHash: string; + /** + * Quantity, Integer Index position of transaction in the block. + */ + readonly transactionIndex: number; + /** + * Quantity Either `0x1` (success) or `0x0` (failure). + */ + readonly status: boolean; + /** + * String ABI - encoded string that displays the reason for reverting the transaction.Only available if revert reason is enabled. + */ + readonly revertReason: string; + /** + * Data RLP - encoded return value of a contract call if a value returns, otherwise, null. + */ + readonly output: string; + /** + * Data, 32 bytes Hash of the privacy marker transaction. + */ + readonly commitmentHash: string; + readonly gasUsed: number; + } + + export interface IPrivateTransactionObject extends IBasicPrivateTransaction { + readonly gas: number; + readonly gasPrice: number; + readonly input: string; + readonly nonce: number; + readonly value: number; + readonly v: number; + readonly r: string; + readonly s: string; + readonly privacyGroupId: string; + readonly restriction: string; + } + + /** + * @see https://besu.hyperledger.org/en/stable/Reference/API-Objects/#log-object + */ + export interface ILogObject { + /** + * Tag true if log removed because of a chain reorganization.false if a valid log. + */ + readonly removed: string; + /** + * Quantity, Integer Log index position in the block.null when log is pending. + */ + readonly logIndex: number; + /** + * Quantity, Integer Index position of the starting transaction for the log.null when log is pending. + */ + readonly transactionIndex: number; + /** + * Data, 32 bytes Hash of the starting transaction for the log.null when log is pending. + */ + readonly transactionHash: string; + /** + * Data, 32 bytes Hash of the block that includes the log.null when log is pending. + */ + readonly blockHash: string; + /** + * Quantity Number of block that includes the log.null when log is pending. + */ + readonly blockNumber: number; + /** + * Data, 20 bytes Address the log originated from. + */ + readonly address: string; + /** + * Data Non - indexed arguments of the log. + */ + readonly data: string; + /** + * Array of Data, 32 bytes each Event signature hash and 0 to 3 indexed log arguments. + */ + readonly topics: string[]; + } + + export interface IDistributeRawTransaction { + readonly privateKey: string; + readonly privateFrom: string; + readonly privateFor: string[]; + readonly privacyGroupId: string; + readonly nonce: string; + readonly to: string; + readonly data: string; + } + + export interface ISendRawTransaction extends IDistributeRawTransaction { + readonly gasLimit: string; + readonly gasPrice: string; + } + + export interface IEthWeb3 extends Eth { + sendRawPrivateTransaction(signed: string, privateData: IPrivateData): Promise + + fillTransaction(tx: ITransaction): Promise<{ raw: string, tx: IPrivateTransactionObject }> + + storageRoot(address: string, block?: string): Promise + + getQuorumPayload(id: string): Promise + + sendTransactionAsync(tx: ITransaction): Promise + + getContractPrivacyMetadata(contractAddress: string): Promise + + distributePrivateTransaction(privateTx: string, privateData: IDistributePrivateData): Promise + + getPrivacyPrecompileAddress(): Promise + + getPrivateTransactionByHash(hash: string): Promise + + getPrivateTransactionReceipt(hash: string): Promise + + getPSI(): Promise + + sendGoQuorumTransaction(tx: TransactionConfig): Promise + } + + export interface IPrivateData { + readonly privacyFlag: PrivacyFlag; + readonly privateFor: string[]; + readonly mandatoryFor: string[]; + } + + export interface IDistributePrivateData extends IPrivateData { + readonly privateFrom: string[]; + } + + export const enum PrivacyFlag { + SP, + PP, + MPP, + PSV + } + + export interface ITransaction { + readonly from: string; + readonly to?: string; + readonly value?: number; + readonly data?: string; + readonly privateFor?: string[]; + } + + export interface IContractPrivacyMetadata { + readonly creationTxHash: string; + readonly privacyFlag: PrivacyFlag; + readonly mandatoryFor: string[]; + } + + export interface IRaftWeb3 { + cluster(): Promise + + role(): Promise + + leader(): Promise + + addPeer(enodeId: string): Promise + + removePeer(raftId: number): Promise + + addLearner(enodeId: string): Promise + + promoteToPeer(raftId: number): Promise + } + + export interface ICluster { + readonly hostName: string; + readonly nodeActive: boolean; + readonly nodeId: string; + readonly p2pPort: number; + readonly raftId: string; + readonly raftPort: number; + readonly role: RaftRole; + } + + export const enum RaftRole { + Minter = "minter", + Verifier = "verifier", + Learner = "learner" + } + + export interface IIstanbulWeb3 { + discard(address: string): Promise + + propose(address: string, auth: boolean): Promise + + getValidatorsAtHash(blockHash: string): Promise + + getValidators(block: string | number): Promise + + candidates(): Promise<{[address: string]: boolean}> + + getSnapshot(block: string | number): Promise + + getSnapshotAtHash(blockHash: string): Promise + + nodeAddress(): Promise + + getSignersFromBlock(block: number): Promise + + getSignersFromBlockByHash(block: string): Promise + + status(startBlock: number, endBlock: number): Promise + + isValidator(block: number): Promise + } + + export interface IPermissionWeb3 { + orgList(): Promise + + acctList(): Promise + + nodeList(): Promise + + roleList(): Promise + + getOrgDetails(orgId: string): Promise + + addOrg(orgId: string, enodeId: string, accountId: string): Promise + + approveOrg(orgId: string, enodeId: string, accountId: string): Promise + + updateOrgStatus(orgId: string, action: number): Promise + + approveOrgStatus(orgId: string, action: number): Promise + + addSubOrg(parentOrgId: string, subOrgId: string, enodeId: string): Promise + + addNewRole(orgId: string, roleId: string, accountAccess: string, isVoter: boolean, isAdminRole: boolean): Promise + + removeRole(orgId: string, roleId: string): Promise + + addAccountToOrg(acctId: string, orgId: string, roleId: string): Promise + + changeAccountRole(acctId: string, orgId: string, roleId: string): Promise + + updateAccountStatus(orgId: string, acctId: string, action: string): Promise + + recoverBlackListedAccount(orgId: string, acctId: string): Promise + + approveBlackListedAccountRecovery(orgId: string, acctId: string): Promise + + assignAdminRole(orgId: string, acctId: string, roleId: string): Promise + + approveAdminRole(orgId: string, acctId: string): Promise + + addNode(orgId: string, enodeId: string): Promise + + updateNodeStatus(orgId: string, enodeId: string, action: string): Promise + + recoverBlackListedNode(orgId: string, enodeId: string): Promise + + approveBlackListedNodeRecovery(orgId: string, enodeId: string): Promise + + transactionAllowed(tx: TransactionConfig): Promise + + connectionAllowed(enodeId: string, ip: string, port: number): Promise + } +} \ No newline at end of file