bip39

package
v0.0.0-...-9b36151 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2019 License: MIT Imports: 11 Imported by: 0

README

Bitcoin BIP39 - Mnemonic code for generating deterministic keys Build Status codecov Go Report Card GoDoc

Implementation in Go (golang) based on original specs.

This BIP describes the implementation of a mnemonic code or mnemonic sentence -- a group of easy to remember words -- for the generation of deterministic wallets. It consists of two parts: generating the mnemonic, and converting it into a binary seed. This seed can be later used to generate deterministic wallets using BIP-0032 or similar methods

Example

A basic example, more on go docs.

package main

import (
	"fmt"
	"log"
	"strings"
	"github.com/bgadrian/go-mnemonic/bip39"
)

func main() {
	/*
		128 bits -> 12 words
		160 bits -> 15 words
		192 bits -> 18 words
		224 bits -> 21 words
		256 bits -> 24 words
	*/
	//generate a new random 12 english words password (mnemonic)
	newRandomMnemonic, err := bip39.NewMnemonicRandom(128, "")
	if err != nil {
		log.Panic(err)
	}

	password, err := newRandomMnemonic.GetSentence()
	if err != nil {
		log.Panic(err)
	}
	fmt.Printf("the password has %v words\n", len(strings.Split(password, " ")))

	// Output:
	//the password has 12 words
}
TODO
  • create a Mnemonic from a seed
  • implement all word lists

Currently the library only supports the English dictionary, if enough interests is shown it's easy to implement the rest of the word lists.

Documentation

Overview

Package bip39 is an immutable class that represents a BIP39 Mnemonic code.

See BIP39 specification for more info: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
A Mnemonic code is a a group of easy to remember words used for the generation
of deterministic wallets. A Mnemonic can be used to generate a seed using
an optional passphrase, for later generate a HDPrivateKey.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSeed

func NewSeed(mnecmonic, passphrase string) []byte

NewSeed Based on a code (word list) returns the seed (hex bytes)

Types

type Mnemonic

type Mnemonic struct {
	// contains filtered or unexported fields
}

Mnemonic ...

func NewMnemonicFromEntropy

func NewMnemonicFromEntropy(ent []byte, passphrase string) (code *Mnemonic, err error)

NewMnemonicFromEntropy Generates a Mnemonic based on a known entropy (stored as hex bytes)

func NewMnemonicFromSentence

func NewMnemonicFromSentence(sentence string, passphrase string) (code *Mnemonic, e error)

NewMnemonicFromSentence Generates a menmonic based on a known code (list of words).

func NewMnemonicRandom

func NewMnemonicRandom(size int, passphrase string) (code *Mnemonic, e error)

NewMnemonicRandom creates a new random (crypto safe) Mnemonic.Use size 128 for a 12 words code.

func (*Mnemonic) GetEntropyStrHex

func (m *Mnemonic) GetEntropyStrHex() (string, error)

GetEntropyStrHex get the entryope as hex in a string, for easy storage

func (*Mnemonic) GetSeed

func (m *Mnemonic) GetSeed() (seed string, e error)

GetSeed Returns the seed for this Mnemonic (as hex in string)

func (*Mnemonic) GetSentence

func (m *Mnemonic) GetSentence() (string, error)

GetSentence Return the words from this Mnemonic.

Jump to

Keyboard shortcuts

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