Compare commits

...

1 Commits

Author SHA1 Message Date
Jim McDonald
1a6f402fb8 Add ability to verify wallet exports 2020-06-08 16:13:35 +01:00
4 changed files with 44 additions and 3 deletions

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.18")
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