Skip to content

Commit

Permalink
Merge pull request #9 from GridPlus/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
alex-miller-0 authored Dec 19, 2022
2 parents b8bd311 + 49d9844 commit 049c569
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 53 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "lattice-cli",
"version": "0.1.0",
"version": "0.1.1",
"description": "CLI for interacting with gridplus-sdk",
"main": "./dist/lattice-cli.js",
"types": "./dist/lattice-cli.d.ts",
"scripts": {
"clean": "rm -rf dist && rm -rf release",
"build": "tsc -p tsconfig.json && npx pkg -c package.json dist/lattice-cli.js",
"start": "ts-node ./src/lattice-cli.ts",
"release": "npm run clean && npm run build"
"release": "npm run clean && npm run build && chmod 755 release/*"
},
"keywords": [],
"author": "Doug Lance",
Expand All @@ -19,7 +19,7 @@
"dotenv": "^16.0.0",
"enquirer": "^2.3.6",
"gridplus-sdk": "^2.4.1",
"lattice-eth2-utils": "^0.4.2",
"lattice-eth2-utils": "^0.4.3",
"spinnies": "^0.5.1",
"ts-node": "^10.7.0"
},
Expand Down
54 changes: 13 additions & 41 deletions src/commands/buildDepositData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AbiCoder } from '@ethersproject/abi';
import {
chmodSync,
existsSync,
mkdirSync,
writeFileSync,
Expand Down Expand Up @@ -126,8 +127,6 @@ export async function cmdGenDepositData(client: Client) {

// 5. Build deposit data in interactive loop
while (true) {
let withdrawalKey: string;

// 5.1. Get encrypted private key for depositor
const keystoreSpinner = startNewSpinner(
`Exporting encrypted keystore for validator #${depositPath[2]}. This will take about 30 seconds.`,
Expand Down Expand Up @@ -158,38 +157,6 @@ export async function cmdGenDepositData(client: Client) {
}
}

// 5.2. Build deposit data record
// First determine the withdrawal credentials
if (eth1Addr !== '') {
withdrawalKey = eth1Addr;
} else {
const withdrawalKeySpinner = startNewSpinner(
`Fetching BLS withdrawal key for validator #${depositPath[2]}.`,
"yellow"
);
try {
// If no withdrawalKey was set, we will be using the defaulBLS withBIP39 draw.
// Derived according to EIP2334.al key associated with a deposit path
withdrawalKey = await getBlsWithdrawalKey(client, depositPath);
closeSpinner(
withdrawalKeySpinner,
`Fetched BLS withdrawal key for validator #${depositPath[2]}.`
);
} catch (err) {
closeSpinner(
withdrawalKeySpinner,
`Failed to fetch BLS withdrawal key for validator #${depositPath[2]}.`,
false
);
const shouldContinue = await promptForBool(`Try again? `);
if (!shouldContinue) {
break;
} else {
continue;
}
}
}

// Now we can generate the deposit data
const depositDataSpinner = startNewSpinner(
`Waiting for signature from validator #${depositPath[2]}.`,
Expand All @@ -198,7 +165,7 @@ export async function cmdGenDepositData(client: Client) {
try {
const opts = {
...ETH2Constants.NETWORKS.MAINNET_GENESIS, // TODO: Make this configurable
withdrawalKey,
withdrawTo: eth1Addr !== '' ? eth1Addr : undefined,
amountGwei: depositAmountGwei,
};
if (exportCalldata) {
Expand Down Expand Up @@ -267,10 +234,11 @@ export async function cmdGenDepositData(client: Client) {
mkdirSync(fDir);
}
for (let i = 0; i < depositData.length; i++) {
writeFileSync(
fDir + `/keystore-m_12381_3600_${startingIdx + i}_0_0-${datetime}.json`,
keystores[i]
);
const fPath = fDir + `/keystore-m_12381_3600_${startingIdx + i}_0_0-${datetime}.json`;
writeFileSync(fPath, keystores[i]);
// These are JSON files so they don't really need to be executable,
// but this matches the permissions from the official Ethereum Deposit CLI.
chmodSync(fPath, "710");
};
const fName = exportCalldata ?
`deposit-calldata-${datetime}.json` :
Expand Down Expand Up @@ -311,8 +279,12 @@ async function getKeystore(client: Client, depositPath: number[]): Promise<strin
*/
function getPubkeyFromCalldata(calldata: string): string {
const coder = new AbiCoder();
const decoded = coder.decode(ETH2Constants.ABIS.DEPOSIT, calldata);
if (decoded[0].length / 2 !== 48) {
// Need to remove the function selector (first 4 bytes) and 0x prefix
const slicedCalldata = calldata.slice(10);
const decoded = coder.decode(ETH2Constants.ABIS.DEPOSIT, '0x' + slicedCalldata);
// Make sure the first argument is a BLS pubkey. Note that ethers will return
// 0x-prefixed hex strings.
if ((decoded[0].length - 2) / 2 !== 48) {
throw new Error("Invalid pubkey length encoded into message. Aborting.");
}
return decoded[0];
Expand Down

0 comments on commit 049c569

Please sign in to comment.