Allow deposit data withdrawal address to be specified as a public key

This commit is contained in:
Jim McDonald
2020-05-22 23:37:02 +01:00
parent 9e3bf521a0
commit 710e891844
4 changed files with 30 additions and 11 deletions

View File

@@ -318,7 +318,8 @@ func accountFromPath(path string) (wtypes.Account, error) {
return nil, errors.New("no account name")
}
if wallet.Type() == "hierarchical deterministic" && strings.HasPrefix(accountName, "m/") && rootWalletPassphrase != "" {
if wallet.Type() == "hierarchical deterministic" && strings.HasPrefix(accountName, "m/") {
assert(rootWalletPassphrase != "", "--walletpassphrase is required for direct path derivations")
err = wallet.Unlock([]byte(rootWalletPassphrase))
if err != nil {
return nil, errors.New("invalid wallet passphrase")

View File

@@ -29,6 +29,7 @@ import (
var validatorDepositDataValidatorAccount string
var validatorDepositDataWithdrawalAccount string
var validatorDepositDataWithdrawalPubKey string
var validatorDepositDataDepositValue string
var validatorDepositDataRaw bool
var validatorDepositDataForkVersion string
@@ -61,13 +62,23 @@ In quiet mode this will return 0 if the the data can be generated correctly, oth
}
}
assert(validatorDepositDataWithdrawalAccount != "", "--withdrawalaccount is required")
withdrawalAccount, err := accountFromPath(validatorDepositDataWithdrawalAccount)
errCheck(err, "Failed to obtain withdrawal account")
outputIf(debug, fmt.Sprintf("Withdrawal public key is %048x", withdrawalAccount.PublicKey().Marshal()))
withdrawalCredentials := util.SHA256(withdrawalAccount.PublicKey().Marshal())
errCheck(err, "Failed to hash withdrawal credentials")
assert(validatorDepositDataWithdrawalAccount != "" || validatorDepositDataWithdrawalPubKey != "", "--withdrawalaccount or --withdrawalpubkey is required")
var withdrawalCredentials []byte
if validatorDepositDataWithdrawalAccount != "" {
withdrawalAccount, err := accountFromPath(validatorDepositDataWithdrawalAccount)
errCheck(err, "Failed to obtain withdrawal account")
outputIf(debug, fmt.Sprintf("Withdrawal public key is %048x", withdrawalAccount.PublicKey().Marshal()))
withdrawalCredentials = util.SHA256(withdrawalAccount.PublicKey().Marshal())
errCheck(err, "Failed to hash withdrawal credentials")
} else {
withdrawalPubKeyBytes, err := hex.DecodeString(strings.TrimPrefix(validatorDepositDataWithdrawalPubKey, "0x"))
errCheck(err, "Invalid withdrawal public key")
assert(len(withdrawalPubKeyBytes) == 48, "Public key should be 48 bytes")
withdrawalPubKey, err := e2types.BLSPublicKeyFromBytes(withdrawalPubKeyBytes)
errCheck(err, "Value supplied with --withdrawalpubkey is not a valid public key")
withdrawalCredentials = util.SHA256(withdrawalPubKey.Marshal())
errCheck(err, "Failed to hash withdrawal credentials")
}
// This is hard-coded, to allow deposit data to be generated without a connection to the beacon node.
withdrawalCredentials[0] = byte(0) // BLS_WITHDRAWAL_PREFIX
outputIf(debug, fmt.Sprintf("Withdrawal credentials are %032x", withdrawalCredentials))
@@ -179,6 +190,7 @@ func init() {
validatorFlags(validatorDepositDataCmd)
validatorDepositDataCmd.Flags().StringVar(&validatorDepositDataValidatorAccount, "validatoraccount", "", "Account of the account carrying out the validation")
validatorDepositDataCmd.Flags().StringVar(&validatorDepositDataWithdrawalAccount, "withdrawalaccount", "", "Account of the account to which the validator funds will be withdrawn")
validatorDepositDataCmd.Flags().StringVar(&validatorDepositDataWithdrawalPubKey, "withdrawalpubkey", "", "Public key of the account to which the validator funds will be withdrawn")
validatorDepositDataCmd.Flags().StringVar(&validatorDepositDataDepositValue, "depositvalue", "", "Value of the amount to be deposited")
validatorDepositDataCmd.Flags().BoolVar(&validatorDepositDataRaw, "raw", false, "Print raw deposit data transaction data")
validatorDepositDataCmd.Flags().StringVar(&validatorDepositDataForkVersion, "forkversion", "", "Use a hard-coded fork version (default is to fetch it from the node)")

View File

@@ -30,7 +30,7 @@ var versionCmd = &cobra.Command{
ethdo version.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("1.4.11")
fmt.Println("1.4.12")
if viper.GetBool("verbose") {
buildInfo, ok := dbg.ReadBuildInfo()
if ok {

View File

@@ -339,7 +339,13 @@ Validator commands focus on interaction with Ethereum 2 validators.
#### `depositdata`
`ethdo validator depositdata` generates the data required to deposit one or more Ethereum 2 validators.
`ethdo validator depositdata` generates the data required to deposit one or more Ethereum 2 validators. Options include:
- `withdrawalaccount` specify the account to be used for the withdrawal credentials (if withdrawalpubkey is not supplied)
- `withdrawalpubkey` specify the public key to be used for the withdrawal credentials (if withdrawalaccount is not supplied)
- `validatoraccount` specify the account to be used for the validator
- `depositvalue` specify the amount of the deposit
- `forkversion` specify the fork version for the deposit signature; this should not be included unless the deposit is being generated offline. Note that supplying an incorrect value could result in the loss of your deposit, so only supply this value if you are sure you know what you are doing
- `raw` generate raw hex output that can be supplied as the data to an Ethereum 1 deposit transaction
#### `exit`
@@ -347,7 +353,7 @@ Validator commands focus on interaction with Ethereum 2 validators.
- `epoch` specify an epoch before which this exit is not valid
- `json-output` generate JSON output rather than sending a transaction immediately
- `json` use JSON input created by the `--json-output` option rather than generate data from scratch
- `forkversion` supply a specific fork version; default is to fetch it from the chain but this can be used when generating offline deposits
- `forkversion` specify a specific fork version; default is to fetch it from the chain but this can be used when generating offline deposits
```sh
$ ethdo validator exit --account=Validators/1 --passphrase="my validator secret"