commons

package
v0.0.0-...-c0918f9 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2019 License: Apache-2.0 Imports: 17 Imported by: 1

Documentation

Overview

Package bip32 provides ...

Package bip32 provides ...

Index

Constants

View Source
const (
	//HardenedKeyStart hardended key starts.
	HardenedKeyStart uint32 = 0x80000000 // 2^31

)

Variables

View Source
var (
	// ErrInvalidSeedLen seed Len error
	ErrInvalidSeedLen = errors.New("seed lenght must be between 128 and 512 bits")
	// 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")

	// ErrKeyByteSize error extended key bytes
	ErrKeyByteSize = errors.New("error extended key bytes")

	//ErrDeriveBeyondMaxDepth max 255 indices
	ErrDeriveBeyondMaxDepth = errors.New("cannot derive a key with more than 255 indices in its path")

	// ErrDeriveHardFromPublic cannot derive a hardened key from a public key
	ErrDeriveHardFromPublic = errors.New("cannot derive a hardened key from a public key")

	//ErrInvalidChild  child index invalid
	ErrInvalidChild = errors.New("the extended key at this index is invalid")

	// ErrNotPrivExtKey  not Private Key
	ErrNotPrivExtKey = errors.New("cant't create private keys from public extended key")
)
View Source
var (
	// ErrInvalidMnemonic is returned when trying to use a malformed mnemonic.
	ErrInvalidMnemonic = errors.New("Invalid mnenomic")

	// ErrEntropyLengthInvalid is returned when trying to use an entropy set with
	// an invalid size.
	ErrEntropyLengthInvalid = errors.New("Entropy length must be [128, 256] and a multiple of 32")

	// ErrValidatedSeedLengthMismatch is returned when a validated seed is not the
	// same size as the given seed. This should never happen is present only as a
	// sanity assertion.
	ErrValidatedSeedLengthMismatch = errors.New("Seed length does not match validated seed length")

	// ErrChecksumIncorrect is returned when entropy has the incorrect checksum.
	ErrChecksumIncorrect = errors.New("Checksum incorrect")
)
View Source
var ErrKeyPathFormat = errors.New("Wallet Path Error")
View Source
var ErrParentKey = errors.New("Key must master")

Functions

func EntropyFromMnemonic

func EntropyFromMnemonic(mnemonic string) ([]byte, error)

EntropyFromMnemonic takes a mnemonic generated by this library, and returns the input entropy used to generate the given mnemonic. An error is returned if the given mnemonic is invalid.

func GetWordList

func GetWordList() []string

GetWordList gets the list of words to use for mnemonics.

func IsMnemonicValid

func IsMnemonicValid(mnemonic string) bool

IsMnemonicValid attempts to verify that the provided mnemonic is valid. Validity is determined by both the number of words being appropriate, and that all the words in the mnemonic are present in the word list.

func MnemonicToByteArray

func MnemonicToByteArray(mnemonic string, raw ...bool) ([]byte, error)

MnemonicToByteArray takes a mnemonic string and turns it into a byte array suitable for creating another mnemonic. An error is returned if the mnemonic is invalid.

func NewEntropy

func NewEntropy(bitSize int) ([]byte, error)

NewEntropy will create random entropy bytes so long as the requested size bitSize is an appropriate size.

bitSize has to be a multiple 32 and be within the inclusive range of {128, 256}

func NewMnemonic

func NewMnemonic(entropy []byte) (string, error)

NewMnemonic will return a string consisting of the mnemonic words for the given entropy. If the provide entropy is invalid, an error will be returned.

func NewSeed

func NewSeed(mnemonic string, password string) []byte

NewSeed creates a hashed seed output given a provided string and password. No checking is performed to validate that the string provided is a valid mnemonic.

func NewSeedWithErrorChecking

func NewSeedWithErrorChecking(mnemonic string, password string) ([]byte, error)

NewSeedWithErrorChecking creates a hashed seed output given the mnemonic string and a password. An error is returned if the mnemonic is not convertible to a byte array.

func SetWordList

func SetWordList(list []string)

SetWordList sets the list of words to use for mnemonics. Currently the list that is set is used package-wide.

Types

type ExtendedKey

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

ExtendedKey private/public key data

func NewMasterKey

func NewMasterKey(seed []byte, params *chaincfg.Params) (*ExtendedKey, error)

NewMasterKey create a new master key data from seed

func (*ExtendedKey) Address

func (key *ExtendedKey) Address() (*ec.AddressPubKeyHash, error)

Address return pay-to-pubkey-has (P2PKH) address

func (*ExtendedKey) B58Serialize

func (key *ExtendedKey) B58Serialize() string

func (*ExtendedKey) DerivePath

func (key *ExtendedKey) DerivePath(pathStr string) (*ExtendedKey, error)

DerivePath return key by path : m/0'/1/2' etc...

func (*ExtendedKey) ECPrivKey

func (key *ExtendedKey) ECPrivKey() (*ec.PrivateKey, error)

func (*ExtendedKey) HardenedChild

func (key *ExtendedKey) HardenedChild(i uint32) (*ExtendedKey, error)

HardenedChild derivation hardened child

func (*ExtendedKey) Serialize

func (key *ExtendedKey) Serialize() ([]byte, error)

Jump to

Keyboard shortcuts

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