extkeys

package
v0.0.0-...-919ab28 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2017 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HardenedKeyStart defines a starting point for hardened key.
	// Each extended key has 2^31 normal child keys and 2^31 hardened 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

	// CoinTypeBTC is BTC coin type
	CoinTypeBTC = 0 // 0x80000000

	// CoinTypeTestNet is test net coin type
	CoinTypeTestNet = 1 // 0x80000001

	// CoinTypeETH is ETH coin type
	CoinTypeETH = 60 // 0x8000003c

	// EmptyExtendedKeyString marker string for zero extended key
	EmptyExtendedKeyString = "Zeroed extended key"
)
View Source
const (
	EnglishLanguage = iota
	ChineseSimplifiedLanguage
	ChineseTraditionalLanguage
	FrenchLanguage
	SpanishLanguage
	JapaneseLanguage
	ItalianLanguage
	RussianLanguage
)

available dictionaries

View Source
const Salt = "status-im"

Salt is input salt to mnemonic key

Variables

View Source
var (
	ErrInvalidKey                 = errors.New("key is invalid")
	ErrInvalidSeed                = errors.New("seed is invalid")
	ErrInvalidSeedLen             = fmt.Errorf("the recommended size of seed is %d-%d bits", MinSeedBytes, MaxSeedBytes)
	ErrDerivingHardenedFromPublic = errors.New("cannot derive a hardened key from public key")
	ErrBadChecksum                = errors.New("bad extended key checksum")
	ErrInvalidKeyLen              = errors.New("serialized extended key length is invalid")
	ErrDerivingChild              = errors.New("error deriving child key")
	ErrInvalidMasterKey           = errors.New("invalid master key supplied")
)

errors

View Source
var (
	// PrivateKeyVersion is version for private key
	PrivateKeyVersion, _ = hex.DecodeString("0488ADE4")

	// PublicKeyVersion is version for public key
	PublicKeyVersion, _ = hex.DecodeString("0488B21E")
)
View Source
var (
	ErrInvalidSecretKey = errors.New("generated secret key cannot be used")
)

errors

View Source
var Languages = [...]string{
	"English",
	"Chinese (Simplified)",
	"Chinese (Traditional)",
	"French",
	"Spanish",
	"Japanese",
	"Italian",
	"Russian",
}

Languages is a list of supported languages for which mnemonic keys can be generated

Functions

This section is empty.

Types

type ExtendedKey

type ExtendedKey struct {
	Version          []byte // 4 bytes, mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private
	Depth            uint16 // 1 byte,  depth: 0x00 for master nodes, 0x01 for level-1 derived keys, ....
	FingerPrint      []byte // 4 bytes, fingerprint of the parent's key (0x00000000 if master key)
	ChildNumber      uint32 // 4 bytes, This is ser32(i) for i in xi = xpar/i, with xi the key being serialized. (0x00000000 if master key)
	KeyData          []byte // 33 bytes, the public key or private key data (serP(K) for public keys, 0x00 || ser256(k) for private keys)
	ChainCode        []byte // 32 bytes, the chain code
	IsPrivate        bool   // (non-serialized) if false, this chain will only contain a public key and can only create a public key chain.
	CachedPubKeyData []byte // (non-serialized) used for memoization of public key (calculated from a private key)
}

ExtendedKey represents BIP44-compliant HD key

func NewKeyFromString

func NewKeyFromString(key string) (*ExtendedKey, error)

NewKeyFromString returns a new extended key instance from a base58-encoded extended key.

func NewMaster

func NewMaster(seed, salt []byte) (*ExtendedKey, error)

NewMaster creates new master node, root of HD chain/tree. Both master and child nodes are of ExtendedKey type, and all the children derive from the root node.

func (*ExtendedKey) BIP44Child

func (k *ExtendedKey) BIP44Child(coinType, i uint32) (*ExtendedKey, error)

BIP44Child returns Status CKD#i (where i is child index). BIP44 format is used: m / purpose' / coin_type' / account' / change / address_index

func (*ExtendedKey) Child

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

Child derives extended key at a given index i. If parent is private, then derived key is also private. If parent is public, then derived is public.

If i >= HardenedKeyStart, then hardened key is generated. You can only generate hardened keys from private parent keys. If you try generating hardened key form public parent key, ErrDerivingHardenedFromPublic is returned.

There are four CKD (child key derivation) scenarios: 1) Private extended key -> Hardened child private extended key 2) Private extended key -> Non-hardened child private extended key 3) Public extended key -> Non-hardened child public extended key 4) Public extended key -> Hardened child public extended key (INVALID!)

func (*ExtendedKey) Derive

func (k *ExtendedKey) Derive(path []uint32) (*ExtendedKey, error)

Derive returns a derived child key at a given path

func (*ExtendedKey) Neuter

func (k *ExtendedKey) Neuter() (*ExtendedKey, error)

Neuter returns a new extended public key from a give extended private key. If the input extended key is already public, it will be returned unaltered.

func (*ExtendedKey) String

func (k *ExtendedKey) String() string

String returns the extended key as a human-readable base58-encoded string.

func (*ExtendedKey) ToECDSA

func (k *ExtendedKey) ToECDSA() *ecdsa.PrivateKey

ToECDSA returns the key data as ecdsa.PrivateKey

type Language

type Language int

Language is language identifier

type Mnemonic

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

Mnemonic represents mnemonic generator inited with a given salt

func NewMnemonic

func NewMnemonic(salt string) *Mnemonic

NewMnemonic returns new mnemonic generator nolint: dupl, misspell

func (*Mnemonic) AvailableLanguages

func (m *Mnemonic) AvailableLanguages() []Language

AvailableLanguages returns list of languages available for mnemonic generation

func (*Mnemonic) MnemonicPhrase

func (m *Mnemonic) MnemonicPhrase(strength, language Language) (string, error)

MnemonicPhrase returns a human readable seed for BIP32 Hierarchical Deterministic Wallets

func (*Mnemonic) MnemonicSeed

func (m *Mnemonic) MnemonicSeed(mnemonic string, password string) []byte

MnemonicSeed creates and returns a binary seed from the mnemonic. We use the PBKDF2 function with a mnemonic sentence (in UTF-8 NFKD) used as the password and the string SALT + passphrase (again in UTF-8 NFKD) used as the salt. The iteration count is set to 2048 and HMAC-SHA512 is used as the pseudo-random function. The length of the derived key is 512 bits (= 64 bytes).

func (*Mnemonic) ValidMnemonic

func (m *Mnemonic) ValidMnemonic(mnemonic string, language Language) bool

ValidMnemonic validates mnemonic string

func (*Mnemonic) WordList

func (m *Mnemonic) WordList(language Language) (*WordList, error)

WordList returns list of words for a given language

type WordList

type WordList [2048]string

WordList is a list of input strings out of which mnemonic phrase is generated

Jump to

Keyboard shortcuts

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