bip39

package
v0.0.0-...-b10619e Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: Apache-2.0 Imports: 11 Imported by: 5

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

View Source
const (
	// SeedSize is the size, in bytes, of a BIP-39 seed.
	SeedSize = 64
)

Variables

View Source
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

func MnemonicToEntropy(mnemonic Mnemonic) ([]byte, error)

MnemonicToEntropy takes a BIP-39 mnemonic sentence and returns the initial entropy used. If the sentence is invalid, an error is returned.

func MnemonicToSeed

func MnemonicToSeed(mnemonic Mnemonic, passphrase string) ([]byte, error)

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

func RegisterWordList(language string, init func() wordlist.List)

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

func SetWordList(language string) error

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

func EntropyToMnemonic(entropy []byte) (Mnemonic, error)

EntropyToMnemonic generates a BIP-39 mnemonic sentence that satisfies the given entropy length.

func ParseMnemonic

func ParseMnemonic(s string) Mnemonic

ParseMnemonic parses s as white space separated list of mnemonic words.

func (Mnemonic) MarshalText

func (ms Mnemonic) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (Mnemonic) String

func (ms Mnemonic) String() string

String will return all the words composing the mnemonic sentence as a single string of space separated words.

func (*Mnemonic) UnmarshalText

func (ms *Mnemonic) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

Directories

Path Synopsis
internal
Package wordlist defines the requirements for a word list used for the bip39 package.
Package wordlist defines the requirements for a word list used for the bip39 package.

Jump to

Keyboard shortcuts

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