Documentation ¶
Overview ¶
Package bip39 implements the BIP-0039 specification of using a mnemonic sentence to encode/decode binary entropy and to derive a seed that can then be used to generate deterministic wallets.
This package supports entropy lengths from 128 to 512 bits as long as they are a multiple of 32 bits.
It comes with the official English and Japanese word list, but different word lists can be registered using RegisterWordList as long as they fulfil the requirements for a BIP-0039 word list.
This package is tested against the test vectors provided in the official BIP-0039 specification.
Index ¶
Constants ¶
const (
// SeedSize is the size, in bytes, of a BIP-39 seed.
SeedSize = 64
)
Variables ¶
var ( // ErrInvalidEntropySize is returned when trying to use an entropy with an invalid size. ErrInvalidEntropySize = errors.New("invalid entropy size") // ErrInvalidMnemonic is returned when trying to use a malformed mnemonic. ErrInvalidMnemonic = errors.New("invalid mnemonic") // ErrInvalidChecksum is returned when checksum does not match. ErrInvalidChecksum = errors.New("invalid checksum") )
Functions ¶
func MnemonicToEntropy ¶
MnemonicToEntropy takes a BIP-39 mnemonic sentence and returns the initial entropy used. If the sentence is invalid, an error is returned.
func MnemonicToSeed ¶
MnemonicToSeed 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 RegisterWordList ¶
RegisterWordList registers a function that returns a new instance of the given word list. This is intended to be called from the init function in packages that implement word lists.
func SetWordList ¶
SetWordList sets the list of words to use for mnemonics. The input must be the language key for a registered word list.
Types ¶
type Mnemonic ¶
type Mnemonic []string
Mnemonic is a slice of mnemonic words, with extra utility methods on top.
func EntropyToMnemonic ¶
EntropyToMnemonic generates a BIP-39 mnemonic sentence that satisfies the given entropy length.
func ParseMnemonic ¶
ParseMnemonic parses s as white space separated list of mnemonic words.
func (Mnemonic) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (Mnemonic) String ¶
String will return all the words composing the mnemonic sentence as a single string of space separated words.
func (*Mnemonic) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.