mneumonic

package
v0.0.0-...-485d38d Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2017 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Go implementation of the mneumonic library - https://github.com/ggozad/mnemonic.js

Usage: import "github.com/vennd/mneumonic"

// Generate a new mneumonic m := mneumonic.GenerateRandom(128) w := m.toWords() h := m.toHex()

// Recover the hexstring from a mneumonic wordArray := strings.Split("dig direction boyfriend imagine remove shown look two choose sorrow cheat close", " ") m := mneumonic.FromWords(wordArray) h := m.toHex()

Index

Constants

This section is empty.

Variables

View Source
var Wc = 1626
View Source
var Words = []string{} /* 1626 elements not displayed */

Functions

This section is empty.

Types

type Mneumonic

type Mneumonic []uint32

func FromHexstring

func FromHexstring(hexString string) Mneumonic

func FromWords

func FromWords(args []string) Mneumonic

// Reconstruct from words

i = 0; n = Mnemonic.wc;
l = args.length / 3;
this.random = new Uint32Array(l);
for (; i < l; i++) {
    w1 = Mnemonic.words.indexOf(args[3 * i]);
    w2 = Mnemonic.words.indexOf(args[3 * i + 1]);
    w3 = Mnemonic.words.indexOf(args[3 * i + 2]);
    this.random[i] = w1 + n * Mnemonic._mod(w2 - w1, n) + n * n * Mnemonic._mod(w3 - w2, n);
}

func GenerateRandom

func GenerateRandom(bits int) Mneumonic

func (Mneumonic) ToHex

func (random Mneumonic) ToHex() string
Mnemonic.prototype.toHex = function () {
    var l = this.random.length, res = '', i = 0;
    for (; i < l; i++) {
        res += ('00000000' + this.random[i].toString(16)).substr(-8);
    }
    return res;
};

func (Mneumonic) ToWords

func (random Mneumonic) ToWords() []string
Mnemonic.prototype.toWords = function () {
    var i = 0, l = this.random.length, n = Mnemonic.wc, words = [], x, w1, w2, w3;
    for (; i < l; i++) {
        x = this.random[i];
        w1 = x % n;
        w2 = (((x / n) >> 0) + w1 ) % n;
        w3 = (((((x / n) >> 0) / n ) >> 0) + w2 ) % n;
        words.push(Mnemonic.words[w1]);
        words.push(Mnemonic.words[w2]);
        words.push(Mnemonic.words[w3]);
    }
    return words;
};strconv.ParseUint(stringChunk, 10, 32)

Jump to

Keyboard shortcuts

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