Documentation ¶
Index ¶
- Constants
- Variables
- type ExtendedKey
- func (k *ExtendedKey) BIP44Child(coinType, i uint32) (*ExtendedKey, error)
- func (k *ExtendedKey) Child(i uint32) (*ExtendedKey, error)
- func (k *ExtendedKey) ChildForPurpose(p KeyPurpose, i uint32) (*ExtendedKey, error)
- func (k *ExtendedKey) Derive(path []uint32) (*ExtendedKey, error)
- func (k *ExtendedKey) EthBIP44Child(i uint32) (*ExtendedKey, error)
- func (k *ExtendedKey) EthEIP1581ChatChild(i uint32) (*ExtendedKey, error)
- func (k *ExtendedKey) Neuter() (*ExtendedKey, error)
- func (k *ExtendedKey) String() string
- func (k *ExtendedKey) ToECDSA() *ecdsa.PrivateKey
- type KeyPurpose
- type Language
- type Mnemonic
- func (m *Mnemonic) AvailableLanguages() []Language
- func (m *Mnemonic) MnemonicPhrase(strength entropyStrength, language Language) (string, error)
- func (m *Mnemonic) MnemonicSeed(mnemonic string, password string) []byte
- func (m *Mnemonic) ValidMnemonic(mnemonic string, language Language) bool
- func (m *Mnemonic) WordList(language Language) (*WordList, error)
- type WordList
Constants ¶
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" // MaxDepth is the maximum depth of an extended key. // Extended keys with depth MaxDepth cannot derive child keys. MaxDepth = 255 )
const ( EnglishLanguage = iota ChineseSimplifiedLanguage ChineseTraditionalLanguage FrenchLanguage SpanishLanguage JapaneseLanguage ItalianLanguage RussianLanguage )
available dictionaries
const ( EntropyStrength128 entropyStrength = 128 + 32*iota EntropyStrength160 EntropyStrength192 EntropyStrength224 EntropyStrength256 )
Valid entropy strengths
Variables ¶
var ( ErrInvalidKey = errors.New("key is invalid") ErrInvalidKeyPurpose = errors.New("key purpose 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") ErrMaxDepthExceeded = errors.New("max depth exceeded") )
errors
var (
// PrivateKeyVersion is version for private key
PrivateKeyVersion, _ = hex.DecodeString("0488ADE4")
// PublicKeyVersion is version for public key
PublicKeyVersion, _ = hex.DecodeString("0488B21E")
// EthBIP44ParentPath is BIP44 keys parent's derivation path
EthBIP44ParentPath = []uint32{
HardenedKeyStart + 44,
HardenedKeyStart + CoinTypeETH,
HardenedKeyStart + 0,
0,
}
// EIP1581KeyTypeChat is used as chat key_type in the derivation of EIP1581 keys
EIP1581KeyTypeChat uint32 = 0x00
// EthEIP1581ChatParentPath is EIP-1581 chat keys parent's derivation path
EthEIP1581ChatParentPath = []uint32{
HardenedKeyStart + 43,
HardenedKeyStart + CoinTypeETH,
HardenedKeyStart + 1581,
HardenedKeyStart + EIP1581KeyTypeChat,
}
)
var ErrInvalidEntropyStrength = errors.New("The mnemonic must encode entropy in a multiple of 32 bits, The recommended size of ENT is 128-256 bits")
ErrInvalidEntropyStrength is the error returned by MnemonicPhrase when the entropy strength is not valid. Valid entropy strength values are multiple of 32 between 128 and 256.
var (
ErrInvalidSecretKey = errors.New("generated secret key cannot be used")
)
errors
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 uint8 // 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 []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 BIP44Child is depracated in favour of EthBIP44Child Param coinType is deprecated; we override it to always use CoinTypeETH.
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) ChildForPurpose ¶ added in v0.35.0
func (k *ExtendedKey) ChildForPurpose(p KeyPurpose, i uint32) (*ExtendedKey, error)
ChildForPurpose derives the child key at index i using a derivation path based on the purpose.
func (*ExtendedKey) Derive ¶
func (k *ExtendedKey) Derive(path []uint32) (*ExtendedKey, error)
Derive returns a derived child key at a given path
func (*ExtendedKey) EthBIP44Child ¶ added in v0.35.0
func (k *ExtendedKey) EthBIP44Child(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) EthEIP1581ChatChild ¶ added in v0.35.0
func (k *ExtendedKey) EthEIP1581ChatChild(i uint32) (*ExtendedKey, error)
EthEIP1581ChatChild returns the whisper key #i (where i is child index). EthEIP1581ChatChild format is used is the one defined in the EIP-1581: m / 43' / coin_type' / 1581' / key_type / index
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 KeyPurpose ¶ added in v0.35.0
type KeyPurpose int
const ( KeyPurposeWallet KeyPurpose = iota + 1 KeyPurposeChat )
type Mnemonic ¶
type Mnemonic struct {
// contains filtered or unexported fields
}
Mnemonic represents mnemonic generator inited with a given salt
func NewMnemonic ¶
func NewMnemonic() *Mnemonic
NewMnemonic returns new mnemonic generator nolint: dupl, misspell
func (*Mnemonic) AvailableLanguages ¶
AvailableLanguages returns list of languages available for mnemonic generation
func (*Mnemonic) MnemonicPhrase ¶
MnemonicPhrase returns a human readable seed for BIP32 Hierarchical Deterministic Wallets
func (*Mnemonic) MnemonicSeed ¶
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 ¶
ValidMnemonic validates mnemonic string