Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assetseed: Update to work with mnemonic. #3128

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 42 additions & 17 deletions client/cmd/assetseed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading