Compare commits

..

3 Commits

Author SHA1 Message Date
Jim McDonald
7215e04a69 Provide withdrawal credentials as part of account info.
Supply clearer message when validator depositdata cannot reach a beacon
node.
2020-06-09 21:01:39 +01:00
Jim McDonald
71e9c0471b Update README 2020-06-08 16:24:23 +01:00
Jim McDonald
1a6f402fb8 Add ability to verify wallet exports 2020-06-08 16:13:35 +01:00
7 changed files with 59 additions and 8 deletions

View File

@@ -5,7 +5,7 @@
A command-line tool for managing common tasks in Ethereum 2.
** Please note that this library uses standards that are not yet final, and as such may result in changes that alter public and private keys. Do not use this library for production use just yet **
**Please note that this tool and its underlying libraries have not yet undergone a security audit; use at your own risk.**
## Table of Contents

View File

@@ -20,6 +20,7 @@ import (
"github.com/spf13/cobra"
pb "github.com/wealdtech/eth2-signer-api/pb/v1"
util "github.com/wealdtech/go-eth2-util"
)
var accountInfoCmd = &cobra.Command{
@@ -33,6 +34,7 @@ In quiet mode this will return 0 if the account exists, otherwise 1.`,
Run: func(cmd *cobra.Command, args []string) {
assert(rootAccount != "", "--account is required")
var withdrawalCredentials []byte
if remote {
listerClient := pb.NewListerClient(remoteGRPCConn)
listAccountsReq := &pb.ListAccountsRequest{
@@ -44,13 +46,18 @@ In quiet mode this will return 0 if the account exists, otherwise 1.`,
errCheck(err, "Failed to access account")
assert(resp.State == pb.ResponseState_SUCCEEDED, "No such account")
assert(len(resp.Accounts) == 1, "No such account")
fmt.Printf("Public key: %#048x\n", resp.Accounts[0].PublicKey)
fmt.Printf("Public key: %#x\n", resp.Accounts[0].PublicKey)
withdrawalCredentials = util.SHA256(resp.Accounts[0].PublicKey)
withdrawalCredentials[0] = byte(0) // BLS_WITHDRAWAL_PREFIX
outputIf(verbose, fmt.Sprintf("Withdrawal credentials: %#x", withdrawalCredentials))
} else {
account, err := accountFromPath(rootAccount)
errCheck(err, "Failed to access wallet")
outputIf(verbose, fmt.Sprintf("UUID: %v", account.ID()))
outputIf(!quiet, fmt.Sprintf("Public key: %#048x", account.PublicKey().Marshal()))
outputIf(!quiet, fmt.Sprintf("Public key: %#x", account.PublicKey().Marshal()))
withdrawalCredentials = util.SHA256(account.PublicKey().Marshal())
withdrawalCredentials[0] = byte(0) // BLS_WITHDRAWAL_PREFIX
outputIf(verbose, fmt.Sprintf("Withdrawal credentials: %#x", withdrawalCredentials))
outputIf(verbose && account.Path() != "", fmt.Sprintf("Path: %s", account.Path()))
}

View File

@@ -112,7 +112,10 @@ In quiet mode this will return 0 if the the data can be generated correctly, oth
err := connect()
errCheck(err, "Failed to connect to beacon node")
config, err := grpc.FetchChainConfig(eth2GRPCConn)
errCheck(err, "Failed to obtain chain configuration")
if err != nil {
outputIf(!quiet, "Could not connect to beacon node; supply a connection with --connection or provide a fork version with --forkversion to generate a deposit")
os.Exit(_exitFailure)
}
genesisForkVersion, exists := config["GenesisForkVersion"]
assert(exists, "Failed to obtain genesis fork version")
forkVersion = genesisForkVersion.([]byte)

View File

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

View File

@@ -14,18 +14,22 @@
package cmd
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"
"github.com/google/uuid"
"github.com/spf13/cobra"
"github.com/wealdtech/go-bytesutil"
"github.com/wealdtech/go-ecodec"
wallet "github.com/wealdtech/go-eth2-wallet"
)
var walletImportData string
var walletImportPassphrase string
var walletImportVerify bool
var walletImportCmd = &cobra.Command{
Use: "import",
@@ -52,8 +56,42 @@ In quiet mode this will return 0 if the wallet is imported successfully, otherwi
importData, err := bytesutil.FromHexString(walletImportData)
errCheck(err, "Failed to decode wallet data")
_, err = wallet.ImportWallet(importData, []byte(walletImportPassphrase))
errCheck(err, "Failed to import wallet")
if walletImportVerify {
type accountInfo struct {
Name string `json:"name"`
}
type walletInfo struct {
ID uuid.UUID `json:"uuid"`
Name string `json:"name"`
Type string `json:"type"`
}
type export struct {
Wallet *walletInfo `json:"wallet"`
Accounts []*accountInfo `json:"accounts"`
}
data, err := ecodec.Decrypt(importData, []byte(walletImportPassphrase))
errCheck(err, "Failed to decrypt wallet")
ext := &export{}
err = json.Unmarshal(data, ext)
errCheck(err, "Failed to read wallet")
outputIf(!quiet, fmt.Sprintf("Wallet name: %s", ext.Wallet.Name))
outputIf(!quiet, fmt.Sprintf("Wallet type: %s", ext.Wallet.Type))
outputIf(verbose, fmt.Sprintf("Wallet UUID: %s", ext.Wallet.ID))
if verbose {
fmt.Printf("Wallet accounts:\n")
for _, account := range ext.Accounts {
outputIf(verbose, fmt.Sprintf(" %s", account.Name))
}
} else {
outputIf(!quiet, fmt.Sprintf("Wallet accounts: %d", len(ext.Accounts)))
}
} else {
_, err = wallet.ImportWallet(importData, []byte(walletImportPassphrase))
errCheck(err, "Failed to import wallet")
}
os.Exit(_exitSuccess)
},
@@ -64,4 +102,5 @@ func init() {
walletFlags(walletImportCmd)
walletImportCmd.Flags().StringVar(&walletImportData, "importdata", "", "The data to import, or the name of a file to read")
walletImportCmd.Flags().StringVar(&walletImportPassphrase, "importpassphrase", "", "Passphrase protecting the data to import")
walletImportCmd.Flags().BoolVar(&walletImportVerify, "verify", false, "Verify the wallet can be imported, but do not import it")
}

View File

@@ -69,6 +69,7 @@ $ ethdo wallet export --wallet="Personal wallet" --exportpassphrase="my export s
`ethdo wallet import` imports a wallet and all of its accounts exported by `ethdo wallet export`. Options for importing a wallet include:
- `importdata`: the data exported by `ethdo wallet export`
- `importpassphrase`: the passphrase that was provided to `ethdo wallet export` to encrypt the data
- `verify`: confirm information about the wallet import without importing it
```sh
$ ethdo wallet import --importdata="0x01c7a27ad40d45b4ae5be5f..." --importpassphrase="my export secret"

1
go.mod
View File

@@ -26,6 +26,7 @@ require (
github.com/tyler-smith/go-bip39 v1.0.2
github.com/wealdtech/eth2-signer-api v1.3.0
github.com/wealdtech/go-bytesutil v1.1.1
github.com/wealdtech/go-ecodec v1.1.0
github.com/wealdtech/go-eth2-types/v2 v2.4.0
github.com/wealdtech/go-eth2-util v1.2.0
github.com/wealdtech/go-eth2-wallet v1.10.0