UNPKG

@lodestar/beacon-node

Version:

A Typescript implementation of the beacon chain

37 lines 1.88 kB
import { digest } from "@chainsafe/as-sha256"; import { Tree, toGindex } from "@chainsafe/persistent-merkle-tree"; import { BLS_WITHDRAWAL_PREFIX, DOMAIN_DEPOSIT, ETH1_ADDRESS_WITHDRAWAL_PREFIX, MAX_EFFECTIVE_BALANCE, } from "@lodestar/params"; import { ZERO_HASH, computeDomain, computeSigningRoot, interopSecretKeys } from "@lodestar/state-transition"; import { ssz } from "@lodestar/types"; /** * Compute and return deposit data from other validators. */ export function interopDeposits(config, depositDataRootList, validatorCount, { withEth1Credentials } = {}) { depositDataRootList.commit(); const depositTreeDepth = depositDataRootList.type.depth; // set credentials if we want withdrawal on or off const withdrawalCredentialsPrefix = withEth1Credentials ? ETH1_ADDRESS_WITHDRAWAL_PREFIX : BLS_WITHDRAWAL_PREFIX; return interopSecretKeys(validatorCount).map((secretKey, i) => { const pubkey = secretKey.toPublicKey().toBytes(); // create DepositData const withdrawalCredentials = digest(pubkey); withdrawalCredentials[0] = withdrawalCredentialsPrefix; const data = { pubkey, withdrawalCredentials, amount: MAX_EFFECTIVE_BALANCE, signature: Buffer.alloc(0), }; const domain = computeDomain(DOMAIN_DEPOSIT, config.GENESIS_FORK_VERSION, ZERO_HASH); const signingRoot = computeSigningRoot(ssz.phase0.DepositMessage, data, domain); data.signature = secretKey.sign(signingRoot).toBytes(); // Add to merkle tree depositDataRootList.push(ssz.phase0.DepositData.hashTreeRoot(data)); depositDataRootList.commit(); return { proof: new Tree(depositDataRootList.node).getSingleProof(toGindex(depositTreeDepth, BigInt(i))), data, }; }); } //# sourceMappingURL=deposits.js.map