diff --git a/cmd/validator/depositdata/input.go b/cmd/validator/depositdata/input.go index d049b12..c81595e 100644 --- a/cmd/validator/depositdata/input.go +++ b/cmd/validator/depositdata/input.go @@ -83,6 +83,8 @@ func input() (*dataIn, error) { return nil, errors.Wrap(err, "failed to obtain public key for withdrawal account") } data.withdrawalCredentials = util.SHA256(pubKey.Marshal()) + // This is hard-coded, to allow deposit data to be generated without a connection to the beacon node. + data.withdrawalCredentials[0] = byte(0) // BLS_WITHDRAWAL_PREFIX case viper.GetString("withdrawalpubkey") != "": withdrawalPubKeyBytes, err := hex.DecodeString(strings.TrimPrefix(viper.GetString("withdrawalpubkey"), "0x")) if err != nil { @@ -96,11 +98,24 @@ func input() (*dataIn, error) { return nil, errors.Wrap(err, "withdrawal public key is not valid") } data.withdrawalCredentials = util.SHA256(withdrawalPubKey.Marshal()) + // This is hard-coded, to allow deposit data to be generated without a connection to the beacon node. + data.withdrawalCredentials[0] = byte(0) // BLS_WITHDRAWAL_PREFIX + case viper.GetString("withdrawaladdress") != "": + // TODO checksum. + withdrawalAddressBytes, err := hex.DecodeString(strings.TrimPrefix(viper.GetString("withdrawaladdress"), "0x")) + if err != nil { + return nil, errors.Wrap(err, "failed to decode withdrawal address") + } + if len(withdrawalAddressBytes) != 20 { + return nil, errors.New("withdrawal address must be exactly 20 bytes in length") + } + data.withdrawalCredentials = make([]byte, 32) + copy(data.withdrawalCredentials[12:32], withdrawalAddressBytes[:]) + // This is hard-coded, to allow deposit data to be generated without a connection to the beacon node. + data.withdrawalCredentials[0] = byte(1) // ETH1_ADDRESS_WITHDRAWAL_PREFIX default: - return nil, errors.New("withdrawalaccount or withdrawal public key is required") + return nil, errors.New("withdrawal account, public key or address is required") } - // This is hard-coded, to allow deposit data to be generated without a connection to the beacon node. - data.withdrawalCredentials[0] = byte(0) // BLS_WITHDRAWAL_PREFIX if viper.GetString("depositvalue") == "" { return nil, errors.New("deposit value is required") diff --git a/cmd/validatordepositdata.go b/cmd/validatordepositdata.go index 542c5a8..1c50ae0 100644 --- a/cmd/validatordepositdata.go +++ b/cmd/validatordepositdata.go @@ -49,9 +49,10 @@ In quiet mode this will return 0 if the the data can be generated correctly, oth func init() { validatorCmd.AddCommand(validatorDepositDataCmd) validatorFlags(validatorDepositDataCmd) - validatorDepositDataCmd.Flags().String("validatoraccount", "", "Account of the account carrying out the validation") - validatorDepositDataCmd.Flags().String("withdrawalaccount", "", "Account of the account to which the validator funds will be withdrawn") + validatorDepositDataCmd.Flags().String("validatoraccount", "", "Account carrying out the validation") + validatorDepositDataCmd.Flags().String("withdrawalaccount", "", "Account to which the validator funds will be withdrawn") validatorDepositDataCmd.Flags().String("withdrawalpubkey", "", "Public key of the account to which the validator funds will be withdrawn") + validatorDepositDataCmd.Flags().String("withdrawaladdress", "", "Ethereum 1 address of the account to which the validator funds will be withdrawn") validatorDepositDataCmd.Flags().String("depositvalue", "", "Value of the amount to be deposited") validatorDepositDataCmd.Flags().Bool("raw", false, "Print raw deposit data transaction data") validatorDepositDataCmd.Flags().String("forkversion", "", "Use a hard-coded fork version (default is to fetch it from the node)") @@ -68,6 +69,9 @@ func validatorDepositdataBindings() { if err := viper.BindPFlag("withdrawalpubkey", validatorDepositDataCmd.Flags().Lookup("withdrawalpubkey")); err != nil { panic(err) } + if err := viper.BindPFlag("withdrawaladdress", validatorDepositDataCmd.Flags().Lookup("withdrawaladdress")); err != nil { + panic(err) + } if err := viper.BindPFlag("depositvalue", validatorDepositDataCmd.Flags().Lookup("depositvalue")); err != nil { panic(err) }