hdwallet

package module
v0.0.0-...-0c6b725 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

README

hdkeychain

Documentation

Index

Constants

View Source
const (
	// RecommendedSeedLen is the recommended length in bytes for a seed
	// to a master node.
	RecommendedSeedLen = 32 // 256 bits

	// HardenedKeyStart is the index at which a hardended key starts.  Each
	// extended key has 2^31 normal child keys and 2^31 hardned child keys.
	// Thus the range for normal child keys is [0, 2^31 - 1] and the range
	// for hardened child keys is [2^31, 2^32 - 1].
	HardenedKeyStart = 0x80000000 // 2^31

	// MinSeedBytes is the minimum number of bytes allowed for a seed to
	// a master node.
	MinSeedBytes = 16 // 128 bits

	// MaxSeedBytes is the maximum number of bytes allowed for a seed to
	// a master node.
	MaxSeedBytes = 64 // 512 bits

)

Variables

View Source
var (
	ErrNonHardenedChild       = errors.New("ed25519 does not support non hardened children")
	ErrPublicParentDerivation = errors.New("derivation from public parent not supported")
)
View Source
var (
	// ErrDeriveHardFromPublic describes an error in which the caller
	// attempted to derive a hardened extended key from a public key.
	ErrDeriveHardFromPublic = errors.New("cannot derive a hardened key " +
		"from a public key")

	// ErrDeriveBeyondMaxDepth describes an error in which the caller
	// has attempted to derive more than 255 keys from a root key.
	ErrDeriveBeyondMaxDepth = errors.New("cannot derive a key with more than " +
		"255 indices in its path")

	// ErrNotPrivExtKey describes an error in which the caller attempted
	// to extract a private key from a public extended key.
	ErrNotPrivExtKey = errors.New("unable to create private keys from a " +
		"public extended key")

	// ErrInvalidChild describes an error in which the child at a specific
	// index is invalid due to the derived key falling outside of the valid
	// range for secp256k1 private keys.  This error indicates the caller
	// should simply ignore the invalid child extended key at this index and
	// increment to the next index.
	ErrInvalidChild = errors.New("the extended key at this index is invalid")

	// ErrUnusableSeed describes an error in which the provided seed is not
	// usable due to the derived key falling outside of the valid range for
	// secp256k1 private keys.  This error indicates the caller must choose
	// another seed.
	ErrUnusableSeed = errors.New("unusable seed")

	// ErrInvalidSeedLen describes an error in which the provided seed or
	// seed length is not in the allowed range.
	ErrInvalidSeedLen = fmt.Errorf("seed length must be between %d and %d "+
		"bits", MinSeedBytes*8, MaxSeedBytes*8)

	// ErrBadChecksum describes an error in which the checksum encoded with
	// a serialized extended key does not match the calculated value.
	ErrBadChecksum = errors.New("bad extended key checksum")

	// ErrInvalidKeyLen describes an error in which the provided serialized
	// key is not the expected length.
	ErrInvalidKeyLen = errors.New("the provided serialized extended key " +
		"length is invalid")
)
View Source
var ED25519CurvePhrase = []byte("ed25519 seed")
View Source
var Secp256k1CurvePhrase = []byte("Bitcoin seed")

Secp256k1CurvePhrase is the master key used along with a random seed used to generate the master node in the hierarchical tree.

Functions

This section is empty.

Types

type ChildKey

type ChildKey interface {
	Child(k ExtendedKey, i uint32) (*ExtendedKey, error)
}

ChildKey interface

type Ed25519

type Ed25519 struct{}

func (*Ed25519) Child

func (e *Ed25519) Child(k ExtendedKey, i uint32) (*ExtendedKey, error)

type ExtendedKey

type ExtendedKey struct {
	// contains filtered or unexported fields
}

ExtendedKey houses all the information needed to support a hierarchical deterministic extended key. See the package overview documentation for more details on how to use extended keys.

func MasterKeyGenerate

func MasterKeyGenerate(seedBytes []byte, masterKey []byte) *ExtendedKey

func NewExtendedKey

func NewExtendedKey(key, chainCode, parentFP []byte, depth uint8,
	childNum uint32, isPrivate bool) *ExtendedKey

NewExtendedKey returns a new instance of an extended key with the given fields. No error checking is performed here as it's only intended to be a convenience method used to create a populated struct. This function should only by used by applications that need to create custom ExtendedKeys. All other applications should just use NewMaster, Child, or Neuter.

type HDWallet

type HDWallet interface {
	GetKeywords() []string

	GetKeywordsString() string

	// btc
	GetBTCExternalKeyPair(i uint32) (*btcec.PrivateKey, *btcec.PublicKey, error)

	GetBTCChangeKeyPair(i uint32) (*btcec.PrivateKey, *btcec.PublicKey, error)

	// eth
	GetETHKeyPair(i uint32) (*btcec.PrivateKey, *btcec.PublicKey, error)

	// olt
	GetOLTKeyPair(i uint32) (*xEd25519.PrivateKey, xEd25519.PublicKey, error)
}

func NewHDWallet

func NewHDWallet(passphrase string) (HDWallet, error)

NewHDWallet

func NewHDWalletFromKeywords

func NewHDWalletFromKeywords(keywords []string, passphrase string) (HDWallet, error)

NewHDWallet

type Secp256K1

type Secp256K1 struct{}

func (*Secp256K1) Child

func (s *Secp256K1) Child(k ExtendedKey, i uint32) (*ExtendedKey, error)

type Wallet

type Wallet struct {
	Seed []byte
	// contains filtered or unexported fields
}

func (*Wallet) GetBTCChangeKeyPair

func (w *Wallet) GetBTCChangeKeyPair(i uint32) (*btcec.PrivateKey, *btcec.PublicKey, error)

func (*Wallet) GetBTCExternalKeyPair

func (w *Wallet) GetBTCExternalKeyPair(i uint32) (*btcec.PrivateKey, *btcec.PublicKey, error)

func (*Wallet) GetETHKeyPair

func (w *Wallet) GetETHKeyPair(i uint32) (*btcec.PrivateKey, *btcec.PublicKey, error)

func (*Wallet) GetKeywords

func (w *Wallet) GetKeywords() []string

func (*Wallet) GetKeywordsString

func (w *Wallet) GetKeywordsString() string

func (*Wallet) GetOLTKeyPair

func (w *Wallet) GetOLTKeyPair(i uint32) (*xEd25519.PrivateKey, xEd25519.PublicKey, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL