mnemonic

package module
v0.0.0-...-72af92c Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2018 License: MIT Imports: 7 Imported by: 7

README

Mnemonic

Build Status Go Report Card GoDoc

A BIP 39 implementation in Go.

Features:

  • Generating human readable sentences for seed generation - a la BIP 32
  • All languages mentioned in the proposal supported.
  • 128 bit (12 words) through 256 bit (24 words) entropy.

mnemonic package

  • Generates human readable sentences and the seeds derived from them.
  • Supports all languages mentioned in the BIP 39 proposal.
  • Supports ideogrpahic spaces for Japanese language.

Example:

package main

import (
    "fmt"
    "github.com/brianium/mnemonic"
)

func main() {
    // generate a random Mnemonic in English with 256 bits of entropy
    m, _ := mnemonic.NewRandom(256, mnemonic.English)

    // print the Mnemonic as a sentence
    fmt.Println(m.Sentence())

    // inspect underlying words
    fmt.Println(m.Words)

    // generate a seed from the Mnemonic
    seed := m.GenerateSeed("passphrase")

    // print the seed as a hex encoded string
    fmt.Println(seed)
}

entropy package

  • Supports generating random entropy in the range of 128-256 bits
  • Supports generating entropy from a hex string

Example:

package main

import (
    "fmt"
    "github.com/brianium/mnemonic"
    "github.com/brianium/mnemonic/entropy"
)

func main() {
    // generate some entropy from a hex string
    ent, _ := entropy.FromHex("8197a4a47f0425faeaa69deebc05ca29c0a5b5cc76ceacc0")
    
    // generate a Mnemonic in Japanese with the generated entropy
    jp, _ := mnemonic.New(ent, mnemonic.Japanese)

    // print the Mnemonic as a sentence
    fmt.Println(jp.Sentence())

    // generate some random 256 bit entropy
    rnd, _ := entropy.Random(256)
    
    // generate a Mnemonic in Spanish with the generated entropy
    sp, _ := mnemonic.New(rnd, mnemonic.Spanish)

    // print the Mnemonic as a sentence
    fmt.Println(sp.Sentence())
}

Installation

To install Mnemonic, use go get:

go get github.com/brianium/mnemonic

This will then make the following packages available to you:

github.com/brianium/mnemonic
github.com/brianium/mnemonic/entropy

Import the mnemonic package into your code using this template:

package yours

import (
  "github.com/brianium/mnemonic"
)

func MnemonicJam(passphrase string) {

  m := mnemonic.NewRandom(passphrase)

}

Contributing

Please feel free to submit issues, fork the repository and send pull requests!

When submitting an issue, we ask that you please include a complete test function that demonstrates the issue.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetWord

func GetWord(lang Language, index int64) (string, error)

GetWord returns a word for the given language at the index

Types

type Language

type Language string

Language type indicates supported mnemonic languages

const (
	// English language
	English Language = "english"

	// Japanese language
	Japanese Language = "japanese"

	// Korean language
	Korean Language = "korean"

	// Spanish language
	Spanish Language = "spanish"

	// ChineseSimplified language
	ChineseSimplified Language = "chineseSimplified"

	// ChineseTraditional language
	ChineseTraditional Language = "chineseTraditional"

	// French Language
	French Language = "french"

	// Italian Language
	Italian Language = "italian"
)

type Mnemonic

type Mnemonic struct {
	Words    []string
	Language Language
}

Mnemonic represents a collection of human readable words used for HD wallet seed generation

func New

func New(ent []byte, lang Language) (*Mnemonic, error)

New returns a new Mnemonic for the given entropy and language

func NewRandom

func NewRandom(length int, lang Language) (*Mnemonic, error)

NewRandom returns a new Mnemonic with random entropy of the given length in bits

func (*Mnemonic) GenerateSeed

func (m *Mnemonic) GenerateSeed(passphrase string) *Seed

GenerateSeed returns a seed used for wallet generation per BIP-0032 or similar method. The internal Words set of the Mnemonic will be used

func (*Mnemonic) Sentence

func (m *Mnemonic) Sentence() string

Sentence returns a Mnemonic's word collection as a space separated sentence

type Seed

type Seed struct {
	Bytes []byte
}

Seed represents a binary seed used for HD wallet generation

func NewSeed

func NewSeed(sentence string, passphrase string) *Seed

NewSeed creae a new Seed with the given sentence and passphrase

func (*Seed) String

func (s *Seed) String() string

func (*Seed) ToHex

func (s *Seed) ToHex() string

ToHex returns the seed bytes as a hex encoded string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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