From 2640b521967de51dc84e30f27749256da6369434 Mon Sep 17 00:00:00 2001 From: jagpreetsinghsasan Date: Wed, 16 Dec 2020 11:59:24 +0530 Subject: [PATCH] feat(besu): remove references to gethkeychainpassword Primary change -------------- 1. Web3SigningCredentialType.GETHKEYCHAINPASSWORD is removed as Hyperledger Besu doesn't support the PERSONAL api for --rpc-http-api as per the discussion mentioned here https://chat.hyperledger.org/channel/besu-contributors?msg=GqQXfW3k79ygRtx5Q Minor refractorings that were also needed to accomodate 1) ---------------------------------------------------------- 2. Corresponding references to GETHKEYCHAINPASSWORD were removed from code and open-api-specs Signed-off-by: jagpreetsinghsasan --- .../src/main/json/generated/openapi-spec.json | 29 ---------- .../generated/openapi/typescript-axios/api.ts | 28 +--------- .../src/main/typescript/model-type-guards.ts | 7 --- .../src/main/typescript/openapi-spec.ts | 28 ---------- .../plugin-ledger-connector-besu.ts | 36 ++---------- .../deploy-contract-from-json.test.ts | 56 ------------------- 6 files changed, 6 insertions(+), 178 deletions(-) diff --git a/packages/cactus-plugin-ledger-connector-besu/src/main/json/generated/openapi-spec.json b/packages/cactus-plugin-ledger-connector-besu/src/main/json/generated/openapi-spec.json index fba8f39b93..7532e19d5d 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/main/json/generated/openapi-spec.json +++ b/packages/cactus-plugin-ledger-connector-besu/src/main/json/generated/openapi-spec.json @@ -36,9 +36,6 @@ "propertyName": "type" }, "oneOf": [ - { - "$ref": "#/components/schemas/Web3SigningCredentialGethKeychainPassword" - }, { "$ref": "#/components/schemas/Web3SigningCredentialCactusKeychainRef" }, @@ -55,32 +52,6 @@ } } }, - "Web3SigningCredentialGethKeychainPassword": { - "type": "object", - "required": [ - "type", - "ethAccount", - "secret" - ], - "properties": { - "type": { - "$ref": "#/components/schemas/Web3SigningCredentialType" - }, - "ethAccount": { - "type": "string", - "description": "The ethereum account (public key) that the credential belongs to. Basically the username in the traditional terminology of authentication.", - "minLength": 64, - "maxLength": 64, - "nullable": false - }, - "secret": { - "type": "string", - "description": "A geth keychain unlock password.", - "minLength": 0, - "maxLength": 65535 - } - } - }, "Web3SigningCredentialCactusKeychainRef": { "type": "object", "required": [ diff --git a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/generated/openapi/typescript-axios/api.ts b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/generated/openapi/typescript-axios/api.ts index 226ccc8741..301e976a54 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/generated/openapi/typescript-axios/api.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/generated/openapi/typescript-axios/api.ts @@ -357,7 +357,7 @@ export interface SolidityContractJsonArtifact { * @type Web3SigningCredential * @export */ -export type Web3SigningCredential = Web3SigningCredentialCactusKeychainRef | Web3SigningCredentialGethKeychainPassword | Web3SigningCredentialNone | Web3SigningCredentialPrivateKeyHex; +export type Web3SigningCredential = Web3SigningCredentialCactusKeychainRef | Web3SigningCredentialNone | Web3SigningCredentialPrivateKeyHex; /** * @@ -390,31 +390,6 @@ export interface Web3SigningCredentialCactusKeychainRef { */ keychainId: string; } -/** - * - * @export - * @interface Web3SigningCredentialGethKeychainPassword - */ -export interface Web3SigningCredentialGethKeychainPassword { - /** - * - * @type {Web3SigningCredentialType} - * @memberof Web3SigningCredentialGethKeychainPassword - */ - type: Web3SigningCredentialType; - /** - * The ethereum account (public key) that the credential belongs to. Basically the username in the traditional terminology of authentication. - * @type {string} - * @memberof Web3SigningCredentialGethKeychainPassword - */ - ethAccount: string; - /** - * A geth keychain unlock password. - * @type {string} - * @memberof Web3SigningCredentialGethKeychainPassword - */ - secret: string; -} /** * Using this denotes that there is no signing required because the transaction is pre-signed. * @export @@ -460,7 +435,6 @@ export interface Web3SigningCredentialPrivateKeyHex { */ export enum Web3SigningCredentialType { CACTUSKEYCHAINREF = 'CACTUS_KEYCHAIN_REF', - GETHKEYCHAINPASSWORD = 'GETH_KEYCHAIN_PASSWORD', PRIVATEKEYHEX = 'PRIVATE_KEY_HEX', NONE = 'NONE' } diff --git a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/model-type-guards.ts b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/model-type-guards.ts index 97c72529ed..8769513067 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/model-type-guards.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/model-type-guards.ts @@ -1,5 +1,4 @@ import { - Web3SigningCredentialGethKeychainPassword, Web3SigningCredentialNone, Web3SigningCredentialPrivateKeyHex, Web3SigningCredentialType, @@ -16,9 +15,3 @@ export function isWeb3SigningCredentialNone( ): x is Web3SigningCredentialNone { return x?.type && x?.type === Web3SigningCredentialType.NONE; } - -export function isWeb3SigningCredentialGethKeychainPassword( - x: any -): x is Web3SigningCredentialGethKeychainPassword { - return x?.type && x?.type === Web3SigningCredentialType.GETHKEYCHAINPASSWORD; -} diff --git a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/openapi-spec.ts b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/openapi-spec.ts index 8291db4cb4..75f66c1b69 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/openapi-spec.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/openapi-spec.ts @@ -40,10 +40,6 @@ export const CACTUS_OPEN_API_JSON: OpenAPIV3.Document = { propertyName: "type", }, oneOf: [ - { - $ref: - "#/components/schemas/Web3SigningCredentialGethKeychainPassword", - }, { $ref: "#/components/schemas/Web3SigningCredentialCactusKeychainRef", }, @@ -56,30 +52,6 @@ export const CACTUS_OPEN_API_JSON: OpenAPIV3.Document = { }, }, }, - Web3SigningCredentialGethKeychainPassword: { - type: "object", - required: ["type", "ethAccount", "secret"], - properties: { - type: { - $ref: "#/components/schemas/Web3SigningCredentialType", - }, - ethAccount: { - type: "string", - description: - "The ethereum account (public key) that the credential " + - " belongs to. Basically the username in the traditional terminology of authentication.", - minLength: 64, - maxLength: 64, - nullable: false, - }, - secret: { - type: "string", - description: "A geth keychain unlock password.", - minLength: 0, - maxLength: 65535, - }, - }, - }, Web3SigningCredentialCactusKeychainRef: { type: "object", required: ["type", "ethAccount", "keychainId", "keychainEntryKey"], 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 b227004631..2fa5135a8a 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 @@ -45,7 +45,6 @@ import { SignTransactionRequest, SignTransactionResponse, Web3SigningCredentialCactusKeychainRef, - Web3SigningCredentialGethKeychainPassword, Web3SigningCredentialPrivateKeyHex, Web3SigningCredentialType, } from "./generated/openapi/typescript-axios/"; @@ -197,9 +196,7 @@ export class PluginLedgerConnectorBesu if (isWeb3SigningCredentialNone(req.web3SigningCredential)) { throw new Error(`${fnTag} Cannot deploy contract with pre-signed TX`); } - const web3SigningCredential = req.web3SigningCredential as - | Web3SigningCredentialGethKeychainPassword - | Web3SigningCredentialPrivateKeyHex; + const web3SigningCredential = req.web3SigningCredential as Web3SigningCredentialPrivateKeyHex; const payload = (method.send as any).request(); const { params } = payload; @@ -227,12 +224,12 @@ export class PluginLedgerConnectorBesu const fnTag = `${this.className}#transact()`; switch (req.web3SigningCredential.type) { + // Web3SigningCredentialType.GETHKEYCHAINPASSWORD is removed as Hyperledger Besu doesn't support the PERSONAL api + // for --rpc-http-api as per the discussion mentioned here + // https://chat.hyperledger.org/channel/besu-contributors?msg=GqQXfW3k79ygRtx5Q case Web3SigningCredentialType.CACTUSKEYCHAINREF: { return this.transactCactusKeychainRef(req); } - case Web3SigningCredentialType.GETHKEYCHAINPASSWORD: { - return this.transactGethKeychain(req); - } case Web3SigningCredentialType.PRIVATEKEYHEX: { return this.transactPrivateKey(req); } @@ -272,27 +269,6 @@ export class PluginLedgerConnectorBesu } } - public async transactGethKeychain( - txIn: RunTransactionRequest - ): Promise { - const fnTag = `${this.className}#transactGethKeychain()`; - const { sendTransaction } = this.web3.eth.personal; - const { transactionConfig, web3SigningCredential } = txIn; - const { - secret, - } = web3SigningCredential as Web3SigningCredentialGethKeychainPassword; - try { - const txHash = await sendTransaction(transactionConfig, secret); - const transactionReceipt = await this.pollForTxReceipt(txHash); - return { transactionReceipt }; - } catch (ex) { - throw new Error( - `${fnTag} Failed to invoke web3.eth.personal.sendTransaction(). ` + - `InnerException: ${ex.stack}` - ); - } - } - public async transactPrivateKey( req: RunTransactionRequest ): Promise { @@ -382,9 +358,7 @@ export class PluginLedgerConnectorBesu if (isWeb3SigningCredentialNone(req.web3SigningCredential)) { throw new Error(`${fnTag} Cannot deploy contract with pre-signed TX`); } - const web3SigningCredential = req.web3SigningCredential as - | Web3SigningCredentialGethKeychainPassword - | Web3SigningCredentialPrivateKeyHex; + const web3SigningCredential = req.web3SigningCredential as Web3SigningCredentialPrivateKeyHex; return this.transact({ transactionConfig: { diff --git a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/deploy-contract-from-json.test.ts b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/deploy-contract-from-json.test.ts index ec3eb32fd3..0434f8f885 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/deploy-contract-from-json.test.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/deploy-contract-from-json.test.ts @@ -124,62 +124,6 @@ test("deploys contract via .json file", async (t: Test) => { ); }); - // FIXME: Stop skipping this test once the 'personal' API is enabled in the - // Besu Test Ledger image by default. - test.skip("invoke Web3SigningCredentialType.GETHKEYCHAINPASSWORD", async (t2: Test) => { - const newName = `DrCactus${uuidv4()}`; - const setNameOut = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, - invocationType: EthContractInvocationType.SEND, - methodName: "setName", - params: [newName], - web3SigningCredential: { - ethAccount: firstHighNetWorthAccount, - secret: "", - type: Web3SigningCredentialType.GETHKEYCHAINPASSWORD, - }, - }); - t2.ok(setNameOut, "setName() invocation #1 output is truthy OK"); - - const getNameOut = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, - invocationType: EthContractInvocationType.SEND, - methodName: "getName", - params: [], - web3SigningCredential: { - ethAccount: firstHighNetWorthAccount, - secret: "", - type: Web3SigningCredentialType.GETHKEYCHAINPASSWORD, - }, - }); - t2.ok( - getNameOut.transactionReceipt, - `getName() SEND invocation produced receipt OK` - ); - - const { callOutput: getNameOut2 } = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, - invocationType: EthContractInvocationType.CALL, - methodName: "getName", - params: [], - web3SigningCredential: { - ethAccount: firstHighNetWorthAccount, - secret: "", - type: Web3SigningCredentialType.GETHKEYCHAINPASSWORD, - }, - }); - t2.equal( - getNameOut2, - newName, - "setName() invocation #2 output is truthy OK" - ); - - t2.end(); - }); - test("invoke Web3SigningCredentialType.NONE", async (t2: Test) => { const testEthAccount2 = web3.eth.accounts.create(uuidv4());