bip39

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2021 License: ISC Imports: 9 Imported by: 2

Documentation

Overview

Package bip39 implements the bip39 protocol https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki This protocol relates closely with bip32 (https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) and allows a memorable word list to be generated for a user of a wallet to store. This is a bit more user friendly than users dealing with hex strings etc.

Users can supply an additional entropy by supplying an optional passcode which is used to generate the seed.

The seed can then be passed to an hd (bip32) private key generation function to produce the wallet private master key.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLength = errors.New("invalid number of bits requested, " +
		"should be a multiple of 32 and between 128 and 256 (inclusive)")
	ErrInvalidMnemonic = errors.New("invalid mnemonic; length should be a multiple of 3 between 12 and 24")
	ErrInvalidWordlist = errors.New("mnemonic contains invalid word (word not in approved wordlist)")
)

Sentinel errors raised by the lib.

View Source
var English = strings.Split(strings.TrimSpace(english), "\n")

English is a slice of mnemonic words taken from the bip39 specification https://raw.githubusercontent.com/bitcoin/bips/master/bip-0039/english.txt

Functions

func GenerateEntropy

func GenerateEntropy(length Entropy) ([]byte, error)

GenerateEntropy will generate a bytearray of cryptographically random bytes with the length of bytes determined by the length supplied.

If the length is invalid a bip39.ErrInvalidLength will be returned.

func Mnemonic

func Mnemonic(entropy []byte, passcode string) (mnemonic string, seed []byte, e error)

Mnemonic will create a new mnemonic sentence using the supplied entropy bytes, if the entropy supplied is not a valid length a bip39.ErrInvalidLength error will be returned.

An optional passcode can be supplied which will be used in the returned seed to provide an additional security measure.

func MnemonicToSeed

func MnemonicToSeed(words, passcode string) ([]byte, error)

MnemonicToSeed will validate a mnemonic and then generate the seed to be used in a BIP32 masterkey generation call.

This can be used if re-generating a wallet from an existing mnemonic.

Types

type Entropy

type Entropy uint32

Entropy contains valid entropy lengths, these are multiples of 32 and between 128 & 256.

const (
	EntWords12 Entropy = 128
	EntWords15 Entropy = 160
	EntWords18 Entropy = 192
	EntWords21 Entropy = 224
	EntWords24 Entropy = 256
)

Allowed mnemonic lengths to supply to the GenerateEntropy function.

Jump to

Keyboard shortcuts

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