commands

package
Version: v0.0.0-...-821bc58 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultEntropySize = 256

Variables

View Source
var AccountsCmd = &cobra.Command{
	Use:   "accounts",
	Short: "Display accounts for a given mnemonic code",
	Long:  "",
	RunE: func(cmd *cobra.Command, args []string) error {
		printf("How many words? ")
		wordsCount := readUint()
		if _, exist := allowedNumbers[wordsCount]; !exist {
			return errors.New("Invalid value, allowed values: 12, 15, 18, 21, 24")
		}

		words := make([]string, wordsCount)
		for i := uint32(0); i < wordsCount; i++ {
			printf("Enter word #%-4d", i+1)
			words[i] = readString()
			if !wordsRegexp.MatchString(words[i]) {
				println("Invalid word, try again.")
				i--
			}
		}

		printf("Enter password (leave empty if none): ")
		password := readString()

		mnemonic := strings.Join(words, " ")
		println("Mnemonic:", mnemonic)

		seed, err := bip39.NewSeedWithErrorChecking(mnemonic, password)
		if err != nil {
			return errors.New("Invalid words or checksum")
		}

		println("BIP39 Seed:", hex.EncodeToString(seed))

		masterKey, err := derivation.DeriveForPath(derivation.StellarAccountPrefix, seed)
		if err != nil {
			return errors.Wrap(err, "Error deriving master key")
		}

		println("m/44'/148' key:", hex.EncodeToString(masterKey.Key))

		println("")

		for i := uint32(startID); i < startID+count; i++ {
			key, err := masterKey.Derive(derivation.FirstHardenedIndex + i)
			if err != nil {
				return errors.Wrap(err, "Error deriving child key")
			}

			kp, err := keypair.FromRawSeed(key.RawSeed())
			if err != nil {
				return errors.Wrap(err, "Error creating key pair")
			}

			println(fmt.Sprintf(derivation.StellarAccountPathFormat, i), kp.Address(), kp.Seed())
		}

		return nil
	},
}
View Source
var NewCmd = &cobra.Command{
	Use:   "new",
	Short: "Generates a new mnemonic code",
	Long:  "",
	RunE: func(cmd *cobra.Command, args []string) error {
		entropy, err := bip39.NewEntropy(DefaultEntropySize)
		if err != nil {
			return errors.Wrap(err, "Error generating entropy")
		}

		mnemonic, err := bip39.NewMnemonic(entropy)
		if err != nil {
			return errors.Wrap(err, "Error generating mnemonic code")
		}

		words := strings.Split(mnemonic, " ")
		for i := 0; i < len(words); i++ {
			printf("word %02d/24: %10s", i+1, words[i])
			readString()
		}

		println("WARNING! Store the words above in a safe place!")
		println("WARNING! If you lose your words, you will lose access to funds in all derived accounts!")
		println("WARNING! Anyone who has access to these words can spend your funds!")
		println("")
		println("Use: `stellar-hd-wallet accounts` command to see generated accounts.")

		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL