diff --git a/client/cmd/assetseed/main.go b/client/cmd/assetseed/main.go index dbbc457283..5d366606f3 100644 --- a/client/cmd/assetseed/main.go +++ b/client/cmd/assetseed/main.go @@ -5,45 +5,70 @@ package main import ( "encoding/hex" + "errors" "flag" "fmt" "os" + "time" "decred.org/dcrdex/client/asset" "decred.org/dcrdex/client/core" + "decred.org/dcrdex/client/mnemonic" ) func main() { - var appSeed string - flag.StringVar(&appSeed, "seed", "", "Bison Wallet application seed (128 hexadecimal characters)") + if err := run(); err != nil { + flag.Usage() + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + os.Exit(0) +} + +func run() error { + var appSeedHex, appMnemonic string + flag.StringVar(&appSeedHex, "seedhex", "", "Bison Wallet application seed (128 hexadecimal characters)") + flag.StringVar(&appMnemonic, "mnemonic", "", "Bison Wallet application seed (15 word mnemonic)") var assetID uint flag.UintVar(&assetID, "asset", 0, "Asset ID. BIP-0044 coin type (integer).\n"+ "See https://github.com/satoshilabs/slips/blob/master/slip-0044.md") flag.Parse() - if appSeed == "" { - flag.Usage() - os.Exit(1) + if appSeedHex == "" && appMnemonic == "" { + return errors.New("no app seed set") } - appSeedB, err := hex.DecodeString(appSeed) - if err != nil { - fmt.Fprintf(os.Stderr, "bad app seed: %v\n", err) - os.Exit(1) + if tkn := asset.TokenInfo(uint32(assetID)); tkn != nil { + return fmt.Errorf("this is a token. did you want asset ID %d for %s?\n", tkn.ParentID, asset.Asset(tkn.ParentID).Info.Name) } - if len(appSeedB) != 64 { - fmt.Fprintf(os.Stderr, "app seed is %d bytes, expected 64\n", len(appSeedB)) - os.Exit(1) - } + var ( + appSeedB []byte + bday time.Time + err error + ) - if tkn := asset.TokenInfo(uint32(assetID)); tkn != nil { - fmt.Fprintf(os.Stderr, "this is a token. did you want asset ID %d for %s?\n", tkn.ParentID, asset.Asset(tkn.ParentID).Info.Name) - os.Exit(1) + if appSeedHex != "" { + appSeedB, err = hex.DecodeString(appSeedHex) + if err != nil { + return fmt.Errorf("bad app seed: %v\n", err) + } + + if len(appSeedB) != 64 { + return fmt.Errorf("app seed is %d bytes, expected 64\n", len(appSeedB)) + } + } else { + appSeedB, bday, err = mnemonic.DecodeMnemonic(appMnemonic) + if err != nil { + return fmt.Errorf("bad mnemonic: %v\n", err) + } } seed, _ := core.AssetSeedAndPass(uint32(assetID), appSeedB) fmt.Printf("%x\n", seed) + if !bday.IsZero() { + fmt.Printf("birthday: %v\n", bday) + } - os.Exit(0) + return nil }