mnemonic

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: MIT Imports: 9 Imported by: 1

README

Mnemonic

Mnemonic is a Go library which which generates mnemonics, which is a way of representing a large randomly-generated number as a sequence of words. A mnemonic gives us a convenient way to store this number, these words then may be used to create a seed. For example we could represent a 128 bit number as the following sequence of words:

"window pig filter walk eye damage arena turtle loyal lobster live act"

The greater the number the larger the sequence of words will be, a 256 bit number would generate a sequence of 24 words.

Installation

$ go get github.com/umahmood/mnemonic

Usage

package main

import (
    "fmt"

    "github.com/umahmood/mnemonic"
)

func main() {
    m, err := mnemonic.New(mnemonic.DefaultConfig) // default 128 bits
    if err != nil {
        // ...
    }
    words, err := m.Words()
    if err != nil {
        // ...
    }
    fmt.Println(words)
}

Output:

[wild cause filter walk eye damage arena turtle loyal lobster live add]

Specifying a non-default config.:

m, err := mnemonic.New(mnemonic.Config{ 
    Bits: 256, // must be a multiple of 32
})

You can specify a passphrase which will be used in generating a seed:

m, err := mnemonic.New(mnemonic.Config{ 
    Bits:       256,
    Passphrase: "To the moon!",
})

Documentation

https://pkg.go.dev/github.com/umahmood/mnemonic

License

See the LICENSE file for license rights and limitations (MIT).

Documentation

Overview

Package mnemonic a way of representing a large randomly-generated number as a sequence of words, making it easier for humans to store.

package main

import (
	"fmt"

	"github.com/umahmood/mnemonic"
)

func main() {
	m, err := mnemonic.New(mnemonic.DefaultConfig)
	if err != nil {
		// ...
	}
	words, err := m.Words()
	if err != nil {
		// ...
	}
	fmt.Println(words)
}

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	Bits:       128,
	Passphrase: "",
}

DefaultConfig to create mnemonics, ideal entropy should be 128 to 256 bits.

View Source
var ErrInvalidBitSize = errors.New("bits must be greater than 0 and multiple of 32")

ErrInvalidBitSize error when bits are not a multiple of 32

Functions

This section is empty.

Types

type Config

type Config struct {
	Bits       int    // Bits entropy to generate, must be a multiple of 32 bits.
	Passphrase string // Optional passphrase allows you to modify the final seed.
}

Config instance

type Mnemonic

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

Mnemonic instance

func New

func New(c Config) (*Mnemonic, error)

New mnemonic instance

func (*Mnemonic) Seed

func (m *Mnemonic) Seed() []byte

Seed creates a 64 byte seed from underlying mnemonic words. The optional passphrase allows you to modify the final seed. Must call Words before this method otherwise seed will be nil.

func (*Mnemonic) Words

func (m *Mnemonic) Words() ([]string, error)

Words returns a randomly generated sequence of (mnemonic) words

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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