Notfound99k / mnemonic

BIP 39 implemented in Go, support mnemonic check checksum

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mnemonic

Build Status Go Report Card GoDoc

A BIP 39 implementation in Go.

This project forked from https://github.com/brianium/mnemonic and change some code.

Features:

  • Add IsMnemonicValid method for check sentences whether valid
  • Add RecoverFromMnemonic method to recover mnemonic to seed
  • 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/alphaqiu/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())
    valid, _ := mnemonic.IsMnemonicValid(mnemonic.English, m.Sentence())
    fmt.Println(valid)
    m, _ = mnemonic.RecoverFromMnemonic(mnemonic.English, 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/alphaqiu/mnemonic"
    "github.com/alphaqiu/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/alphaqiu/mnemonic

This will then make the following packages available to you:

github.com/alphaqiu/mnemonic
github.com/alphaqiu/mnemonic/entropy

Import the mnemonic package into your code using this template:

package yours

import (
  "github.com/alphaqiu/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.

About

BIP 39 implemented in Go, support mnemonic check checksum

License:Other


Languages

Language:Go 100.0%