Skip to content

Commit

Permalink
feat(besu): remove references to gethkeychainpassword
Browse files Browse the repository at this point in the history
        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 <jagpreet.singh.sasan@accenture.com>
  • Loading branch information
jagpreetsinghsasan authored and petermetz committed Dec 18, 2020
1 parent 455414d commit 2640b52
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
"propertyName": "type"
},
"oneOf": [
{
"$ref": "#/components/schemas/Web3SigningCredentialGethKeychainPassword"
},
{
"$ref": "#/components/schemas/Web3SigningCredentialCactusKeychainRef"
},
Expand All @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export interface SolidityContractJsonArtifact {
* @type Web3SigningCredential
* @export
*/
export type Web3SigningCredential = Web3SigningCredentialCactusKeychainRef | Web3SigningCredentialGethKeychainPassword | Web3SigningCredentialNone | Web3SigningCredentialPrivateKeyHex;
export type Web3SigningCredential = Web3SigningCredentialCactusKeychainRef | Web3SigningCredentialNone | Web3SigningCredentialPrivateKeyHex;

/**
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -460,7 +435,6 @@ export interface Web3SigningCredentialPrivateKeyHex {
*/
export enum Web3SigningCredentialType {
CACTUSKEYCHAINREF = 'CACTUS_KEYCHAIN_REF',
GETHKEYCHAINPASSWORD = 'GETH_KEYCHAIN_PASSWORD',
PRIVATEKEYHEX = 'PRIVATE_KEY_HEX',
NONE = 'NONE'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
Web3SigningCredentialGethKeychainPassword,
Web3SigningCredentialNone,
Web3SigningCredentialPrivateKeyHex,
Web3SigningCredentialType,
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ export const CACTUS_OPEN_API_JSON: OpenAPIV3.Document = {
propertyName: "type",
},
oneOf: [
{
$ref:
"#/components/schemas/Web3SigningCredentialGethKeychainPassword",
},
{
$ref: "#/components/schemas/Web3SigningCredentialCactusKeychainRef",
},
Expand All @@ -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"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import {
SignTransactionRequest,
SignTransactionResponse,
Web3SigningCredentialCactusKeychainRef,
Web3SigningCredentialGethKeychainPassword,
Web3SigningCredentialPrivateKeyHex,
Web3SigningCredentialType,
} from "./generated/openapi/typescript-axios/";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -272,27 +269,6 @@ export class PluginLedgerConnectorBesu
}
}

public async transactGethKeychain(
txIn: RunTransactionRequest
): Promise<RunTransactionResponse> {
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<RunTransactionResponse> {
Expand Down Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit 2640b52

Please sign in to comment.