Skip to content

Commit

Permalink
Merge pull request #46 from lukso-network/fix/new-merge
Browse files Browse the repository at this point in the history
 fix: Merge upstream 'redo 7.7.23'
  • Loading branch information
frozeman authored Jul 25, 2023
2 parents 9f85adb + d5bb14d commit 3c18adc
Show file tree
Hide file tree
Showing 33 changed files with 1,740 additions and 331 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
if: ${{ matrix.os == 'macos' }}
uses: actions/setup-python@v4
with:
python-version: "3.11.3"
python-version: "3.11.4"
- name: Set up Node
uses: actions/setup-node@v3
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ dist/
build/
src/scripts/__pycache__/
stakingdeposit_proxy.spec
eth2deposit_proxy.spec
REQUIREMENT_PACKAGES_PATH/
.build/

# Debugging
keys/
.DS_Store
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Execute all those commands in your terminal to setup your dev environment. You m

```console
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/wagyu/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/$USER/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

git --version
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
"extraFiles": [
"build/bin/*",
{
"from": ".build/${arch}/eth2deposit_proxy",
"to": "build/bin/eth2deposit_proxy"
"from": ".build/${arch}/stakingdeposit_proxy",
"to": "build/bin/stakingdeposit_proxy"
},
"build/word_lists/*",
"static/icon.png",
Expand Down
146 changes: 127 additions & 19 deletions src/electron/Eth2Deposit.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Eth2Deposit.ts
/**
* This Eth2Deposit module exposes the different functions exported by the eth2deposit_proxy
* This Eth2Deposit module exposes the different functions exported by the stakingdeposit_proxy
* application to be used easily with our typescript code.
*
* The eth2deposit_proxy application can be called in 3 different ways:
* The stakingdeposit_proxy application can be called in 3 different ways:
* 1. From a bundled application, when we do release with electron-builder. This bundled
* application will always include a single file application (SFE) version of eth2deposit_proxy.
* application will always include a single file application (SFE) version of stakingdeposit_proxy.
* 2. Using a single file application (SFE) bundled with pyinstaller in an environment where the
* running application is not bundled.
* 3. Using the Python 3 version installed on the current machine and the version available
* in the current environment.
*
* When we want to call the eth2deposit_proxy application, it will detect which way can be called
* When we want to call the stakingdeposit_proxy application, it will detect which way can be called
* in order and use the first one available.
*
* @module
Expand All @@ -36,7 +36,7 @@ const execFileProm = promisify(execFile);
const ETH2_DEPOSIT_DIR_NAME = "tools-key-gen-cli";

/**
* Paths needed to call the eth2deposit_proxy application using the Python 3 version installed on
* Paths needed to call the stakingdeposit_proxy application using the Python 3 version installed on
* the current machine.
*/
const ETH2_DEPOSIT_CLI_PATH = path.join(
Expand All @@ -54,21 +54,21 @@ const WORD_LIST_PATH = path.join(
"word_lists"
);
const REQUIREMENT_PACKAGES_PATH = path.join("dist", "packages");
const ETH2DEPOSIT_PROXY_PATH = path.join(SCRIPTS_PATH, "eth2deposit_proxy.py");
const STAKINGDEPOSIT_PROXY_PATH = path.join(SCRIPTS_PATH, "stakingdeposit_proxy.py");

/**
* Paths needed to call the eth2deposit_proxy application using a single file application (SFE)
* Paths needed to call the stakingdeposit_proxy application using a single file application (SFE)
* bundled with pyinstaller.
*/
const SFE_PATH = path.join(
"build",
"bin",
"eth2deposit_proxy" + (process.platform == "win32" ? ".exe" : "")
"stakingdeposit_proxy" + (process.platform == "win32" ? ".exe" : "")
);
const DIST_WORD_LIST_PATH = path.join(cwd(), "build", "word_lists");

/**
* Paths needed to call the eth2deposit_proxy application from a bundled application.
* Paths needed to call the stakingdeposit_proxy application from a bundled application.
*/
const BUNDLED_SFE_PATH =
process.platform === "darwin"
Expand All @@ -77,14 +77,14 @@ const BUNDLED_SFE_PATH =
"..",
"build",
"bin",
"eth2deposit_proxy/eth2deposit_proxy"
"stakingdeposit_proxy/stakingdeposit_proxy"
)
: path.join(
process.resourcesPath,
"..",
"build",
"bin",
"eth2deposit_proxy" + (process.platform === "win32" ? ".exe" : "")
"stakingdeposit_proxy" + (process.platform === "win32" ? ".exe" : "")
);

const BUNDLED_DIST_WORD_LIST_PATH = path.join(
Expand All @@ -97,12 +97,14 @@ const BUNDLED_DIST_WORD_LIST_PATH = path.join(
const CREATE_MNEMONIC_SUBCOMMAND = "create_mnemonic";
const GENERATE_KEYS_SUBCOMMAND = "generate_keys";
const VALIDATE_MNEMONIC_SUBCOMMAND = "validate_mnemonic";
const VALIDATE_BLS_CREDENTIALS_SUBCOMMAND = "validate_bls_credentials";
const VALIDATE_BLS_CHANGE_SUBCOMMAND = "bls_change";

const PYTHON_EXE = process.platform == "win32" ? "python" : "python3";
const PATH_DELIM = process.platform == "win32" ? ";" : ":";

/**
* Install the required Python packages needed to call the eth2deposit_proxy application using the
* Install the required Python packages needed to call the stakingdeposit_proxy application using the
* Python 3 version installed on the current machine.
*
* @returns Returns a Promise<boolean> that includes a true value if the required Python packages
Expand Down Expand Up @@ -148,7 +150,7 @@ const getPythonPath = async (): Promise<string> => {
};

/**
* Create a new mnemonic by calling the create_mnemonic function from the eth2deposit_proxy
* Create a new mnemonic by calling the create_mnemonic function from the stakingdeposit_proxy
* application.
*
* @param language The mnemonic language. Possible values are `chinese_simplified`,
Expand Down Expand Up @@ -188,7 +190,7 @@ const createMnemonic = async (language: string): Promise<string> => {

executable = PYTHON_EXE;
args = [
ETH2DEPOSIT_PROXY_PATH,
STAKINGDEPOSIT_PROXY_PATH,
CREATE_MNEMONIC_SUBCOMMAND,
WORD_LIST_PATH,
"--language",
Expand All @@ -204,7 +206,7 @@ const createMnemonic = async (language: string): Promise<string> => {
};

/**
* Generate validator keys by calling the generate_keys function from the eth2deposit_proxy
* Generate validator keys by calling the generate_keys function from the stakingdeposit_proxy
* application.
*
* @param mnemonic The mnemonic to be used as the seed for generating the keys.
Expand Down Expand Up @@ -281,7 +283,7 @@ const generateKeys = async (
env.PYTHONPATH = await getPythonPath();

executable = PYTHON_EXE;
args = [ETH2DEPOSIT_PROXY_PATH, GENERATE_KEYS_SUBCOMMAND];
args = [STAKINGDEPOSIT_PROXY_PATH, GENERATE_KEYS_SUBCOMMAND];
if (eth1_withdrawal_address != "") {
args = args.concat([
"--eth1_withdrawal_address",
Expand All @@ -305,7 +307,7 @@ const generateKeys = async (

/**
* Validate a mnemonic using the eth2-deposit-cli logic by calling the validate_mnemonic function
* from the eth2deposit_proxy application.
* from the stakingdeposit_proxy application.
*
* @param mnemonic The mnemonic to be validated.
*
Expand Down Expand Up @@ -336,7 +338,7 @@ const validateMnemonic = async (mnemonic: string): Promise<void> => {

executable = PYTHON_EXE;
args = [
ETH2DEPOSIT_PROXY_PATH,
STAKINGDEPOSIT_PROXY_PATH,
VALIDATE_MNEMONIC_SUBCOMMAND,
WORD_LIST_PATH,
mnemonic,
Expand All @@ -346,4 +348,110 @@ const validateMnemonic = async (mnemonic: string): Promise<void> => {
await execFileProm(executable, args, { env: env });
};

export { createMnemonic, generateKeys, validateMnemonic };
/**
* Validate BLS credentials by calling the validate_bls_credentials function
* from the stakingdeposit_proxy application.
*
* @param chain The network setting for the signing domain. Possible values are `mainnet`,
* `goerli`, `zhejiang`.
* @param mnemonic The mnemonic from which the BLS credentials are derived.
* @param index The index of the first validator's keys.
* @param withdrawal_credentials A list of the old BLS withdrawal credentials of the given validator(s), comma separated.
*
* @returns Returns a Promise<void> that will resolve when the validation is done.
*/
const validateBLSCredentials = async (
chain: string,
mnemonic: string,
index: number,
withdrawal_credentials: string
): Promise<void> => {

let executable:string = "";
let args:string[] = [];
let env = process.env;

if (await doesFileExist(BUNDLED_SFE_PATH)) {
executable = BUNDLED_SFE_PATH;
args = [VALIDATE_BLS_CREDENTIALS_SUBCOMMAND, chain.toLowerCase(), mnemonic, index.toString(), withdrawal_credentials];
} else if (await doesFileExist(SFE_PATH)) {
executable = SFE_PATH;
args = [VALIDATE_BLS_CREDENTIALS_SUBCOMMAND, chain.toLowerCase(), mnemonic, index.toString(), withdrawal_credentials];
} else {
if(!await requireDepositPackages()) {
throw new Error("Failed to validate BLS credentials, don't have the required packages.");
}
env.PYTHONPATH = await getPythonPath();

executable = PYTHON_EXE;
args = [STAKINGDEPOSIT_PROXY_PATH, VALIDATE_BLS_CREDENTIALS_SUBCOMMAND, chain.toLowerCase(), mnemonic, index.toString(), withdrawal_credentials];
}

await execFileProm(executable, args, {env: env});
}

/**
* Generate BTEC file by calling the bls_change function from the stakingdeposit_proxy
* application.
*
* @param folder The folder path for the resulting BTEC file.
* @param chain The network setting for the signing domain. Possible values are `mainnet`,
* `goerli`, `zhejiang`.
* @param mnemonic The mnemonic to be used as the seed for generating the BTEC.
* @param index The index of the first validator's keys.
* @param indices The validator index number(s) as identified on the beacon chain (comma seperated).
* @param withdrawal_credentials A list of the old BLS withdrawal credentials of the given validator(s), comma separated.
* @param execution_address The withdrawal address.
*
* @returns Returns a Promise<void> that will resolve when the generation is done.
*/
const generateBLSChange = async (
folder: string,
chain: string,
mnemonic: string,
index: number,
indices: string,
withdrawal_credentials: string,
execution_address: string

): Promise<void> => {

let executable:string = "";
let args:string[] = [];
let env = process.env;

if (await doesFileExist(BUNDLED_SFE_PATH)) {
executable = BUNDLED_SFE_PATH;
args = [VALIDATE_BLS_CHANGE_SUBCOMMAND];

args = args.concat([folder, chain.toLowerCase(), mnemonic, index.toString(), indices,
withdrawal_credentials, execution_address]);
} else if (await doesFileExist(SFE_PATH)) {
executable = SFE_PATH;
args = [VALIDATE_BLS_CHANGE_SUBCOMMAND];

args = args.concat([folder, chain.toLowerCase(), mnemonic, index.toString(), indices,
withdrawal_credentials, execution_address]);
} else {
if(!await requireDepositPackages()) {
throw new Error("Failed to generate BTEC, don't have the required packages.");
}
env.PYTHONPATH = await getPythonPath();

executable = PYTHON_EXE;
args = [STAKINGDEPOSIT_PROXY_PATH, VALIDATE_BLS_CHANGE_SUBCOMMAND];

args = args.concat([folder, chain.toLowerCase(), mnemonic, index.toString(), indices,
withdrawal_credentials, execution_address]);
}

await execFileProm(executable, args, {env: env});
}

export {
createMnemonic,
generateKeys,
validateMnemonic,
validateBLSCredentials,
generateBLSChange
};
12 changes: 7 additions & 5 deletions src/electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {

import Web3Utils from "web3-utils";

import { createMnemonic, generateKeys, validateMnemonic } from "./Eth2Deposit";
import { createMnemonic, generateKeys, validateMnemonic, validateBLSCredentials, generateBLSChange } from './Eth2Deposit';

import {
doesDirectoryExist,
Expand Down Expand Up @@ -42,10 +42,12 @@ contextBridge.exposeInMainWorld("electronAPI", {
invokeShowOpenDialog: invokeShowOpenDialog,
});

contextBridge.exposeInMainWorld("eth2Deposit", {
createMnemonic: createMnemonic,
generateKeys: generateKeys,
validateMnemonic: validateMnemonic,
contextBridge.exposeInMainWorld('eth2Deposit', {
'createMnemonic': createMnemonic,
'generateKeys': generateKeys,
'validateMnemonic': validateMnemonic,
'validateBLSCredentials': validateBLSCredentials,
'generateBLSChange': generateBLSChange
});

contextBridge.exposeInMainWorld("bashUtils", {
Expand Down
4 changes: 3 additions & 1 deletion src/electron/renderer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export interface IEth2DepositAPI {
createMnemonic: (language: string) => Promise<string>,
generateKeys: (mnemonic: string, index: number, count: number, network: string,
password: string, eth1_withdrawal_address: string, folder: string) => Promise<void>,
validateMnemonic: (mnemonic: string) => Promise<void>
validateMnemonic: (mnemonic: string) => Promise<void>,
validateBLSCredentials: (chain: string, mnemonic: string, index: number, withdrawal_credentials: string) => Promise<void>,
generateBLSChange: (folder: string, chain: string, mnemonic: string, index: number, indices: string, withdrawal_credentials: string, execution_address: string) => Promise<void>,
}

export interface IBashUtilsAPI {
Expand Down
2 changes: 1 addition & 1 deletion src/react/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CssBaseline, ThemeProvider } from "@material-ui/core";
import 'typeface-roboto';
import MainWizard from "./pages/MainWizard";
import theme from "./theme";
import { Network } from './types';
import { Network, ReuseMnemonicAction } from './types';

const Container = styled.main`
display: flex;
Expand Down
Loading

0 comments on commit 3c18adc

Please sign in to comment.