Documentation ¶
Index ¶
- Constants
- Variables
- func BitlenToBytelen(bitlen uint) uint
- func BytelenToBitlen(bytelen uint) uint
- func ExtractMnemonic(entropy Entropy, list words.List) ([]string, error)
- func ExtractSeed(mnemonic []string, list words.List, password string) ([]byte, error)
- func NormalizeMnemonic(mnemonic []string) []string
- func PadLeftToBitlen(bytes []byte, bitlen uint) []byte
- func RandomBytes(length uint) []byte
- func SplitMnemonic(mnemonic string) []string
- func ValidateMnemonic(mnemonic []string, list words.List) error
- type ChecksumEntropy
- type Entropy
Constants ¶
const ( // Minimum allowed by BIP-39 entropy bitlen MinBitlen = 128 // Maximum allowed by BIP-39 entropy bitlen MaxBitlen = 256 // Divisor that used to get checksum bits of SHA-256 hash BitlenDivisor = 32 // Bits are splitted into groups of 11 bits, which are represents an index of the word GroupBitlen = 11 )
const ( // Minimum allowed by BIP-39 mnemonic length MinLength = 12 // Maximum allowed by BIP-39 mnemonic length MaxLength = 24 // Mnemonic length divisor LengthDivisor = 3 )
const ( // BIP-39 Password prefix PasswordPrefix = "mnemonic" // PBKDF2 Iterations count Iterations = 2048 // PBKDF2 Derived key length KeyLength = 64 )
Variables ¶
var ( // ErrInvalidMnemonicLength ErrInvalidMnemonicLength = errors.New("mnemonic length must be one of 12, 15, 18, 21 or 24") // ErrInvalidMnemonicChecksum ErrInvalidMnemonicChecksum = errors.New("invalid mnemonic checksum") )
var ErrInvalidEntropyBitlen = errors.New("entropy bitlen must be one of 128, 160, 192, 224 or 256")
ErrInvalidEntropyBitlen
Functions ¶
func BitlenToBytelen ¶
BitlenToBytelen converts a bitlet to a bytelen
func BytelenToBitlen ¶
BytelenToBitlen converts a bytelen to a bitlen
func ExtractMnemonic ¶
ExtractMnemonic returns mnemonic phrase based on given entropy and language
func ExtractSeed ¶
ExtractSeed returns seed derived from mnemonic and password
func NormalizeMnemonic ¶
NormalizeMnemonic returns NFKD normalized UTF-8 encoded mnemonic
func PadLeftToBitlen ¶
PadLeftToBitlen pads a byte slice to a given bitlen if needed
func RandomBytes ¶
RandomBytse generates random bytes sequence of given length
func SplitMnemonic ¶
SplitMnemonic splits NFKD normalized string into words
Types ¶
type ChecksumEntropy ¶
type ChecksumEntropy []byte
Entropy with checksum
func (ChecksumEntropy) Bitlen ¶
func (e ChecksumEntropy) Bitlen() uint
Bitlen returns a bitlen of entorpy with checksum
func (ChecksumEntropy) EntropyBitlen ¶
func (e ChecksumEntropy) EntropyBitlen() uint
EntropyBitlen returns a bitlen of entropy without checksum
func (ChecksumEntropy) RemoveChecksum ¶
func (e ChecksumEntropy) RemoveChecksum() (Entropy, []byte)
RemoveChecksum returns initial entropy and checksum separately
type Entropy ¶
type Entropy []byte
Initial entropy
func ExtractEntropy ¶
ExtractEntropy returns entropy based on given mnemonic phrase and language
func NewEntropy ¶
NewEntropy generates new random entropy of bitlen
func (Entropy) AddChecksum ¶
func (e Entropy) AddChecksum() ChecksumEntropy
AddChecksum returns entropy with checksum
func (Entropy) IsValidChecksum ¶
IsValidChecksum validates entorpy checksum