Skip to content
This repository has been archived by the owner on May 12, 2023. It is now read-only.

brianium/mnemonic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Releases

No releases published

Packages

 
 
 

Languages