Last active
July 30, 2024 14:21
-
-
Save nflaig/2c39a657900e0fd5500d059d3e381ba6 to your computer and use it in GitHub Desktop.
Generate ETH deposit data (based on https://github.com/ChainSafe/lodestar/blob/8a6bc9dbf6d59ff430e70e6df659204bc60f9225/packages/state-transition/test/perf/block/util.ts#L199)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bls from "@chainsafe/bls"; | |
import { deriveKeyFromMnemonic, deriveEth2ValidatorKeys } from "@chainsafe/bls-keygen"; | |
import { fromHexString, toHexString } from "@chainsafe/ssz"; | |
import { computeDomain, computeSigningRoot, ZERO_HASH } from "@lodestar/state-transition"; | |
import { DOMAIN_DEPOSIT } from "@lodestar/params"; | |
import { mainnetChainConfig } from "@lodestar/config/networks"; | |
import { ssz } from "@lodestar/types/phase0"; | |
const masterSK = deriveKeyFromMnemonic("your mnemonic phrase goes here"); | |
const sk = bls.SecretKey.fromBytes(deriveEth2ValidatorKeys(masterSK, 0).signing); | |
console.log("Pubkey: " + sk.toPublicKey().toHex()); | |
const pubkey = sk.toPublicKey().toBytes(); | |
const eth1Address = "your eth1 address goes here"; | |
const withdrawalCredentials = fromHexString("0x010000000000000000000000" + eth1Address.replace("0x", "")); | |
const depositMessage = { pubkey, withdrawalCredentials, amount: 32e9 }; | |
const domain = computeDomain(DOMAIN_DEPOSIT, mainnetChainConfig.GENESIS_FORK_VERSION, ZERO_HASH); | |
const signingRoot = computeSigningRoot(ssz.DepositMessage, depositMessage, domain); | |
const depositData = { ...depositMessage, signature: sk.sign(signingRoot).toBytes() }; | |
console.log("Deposit data: %o", ssz.DepositData.toJson(depositData)); | |
const depositDataRoot = ssz.DepositData.hashTreeRoot(depositData); | |
console.log("Deposit data root: " + toHexString(depositDataRoot)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment