Skip to content

Latest commit

 

History

History
62 lines (42 loc) · 2.82 KB

mnemonic.md

File metadata and controls

62 lines (42 loc) · 2.82 KB

Dash Mnemonic

The Mnemonic class provides an implementation of a mnemonic code or mnemonic sentence – a group of easy to remember words – for the generation of deterministic keys. The class handles code generation and its later conversion to a HDPrivateKey. See the official BIP-0039 for technical background information.

For example, the following code would generate a new random mnemonic code and convert it to a HDPrivateKey.

var Mnemonic = require('@gohelpfund/helpcore-mnemonic');
var code = new Mnemonic(Mnemonic.Words.SPANISH);
code.toString(); // natal hada sutil año sólido papel jamón combate aula flota ver esfera...
var xpriv = code.toHDPrivateKey();

Mnemonic generation

For creating a new random mnemonic code you just create a new instance.

var Mnemonic = require('@gohelpfund/helpcore-mnemonic');
var code = new Mnemonic();

code.toString(); // 'select scout crash enforce riot rival spring whale hollow radar rule sentence'

Multi-language support

The Mnemonic class can use any list of 2048 unique words to generate the mnemonic code. For convenience the class provides default word lists for the following languages: English (default), Chinese, French, Japanese and Spanish. Those word list are published under Mnemonic.Words.LANGUAGE, take a look at the following example:

var Mnemonic = require('@gohelpfund/helpcore-mnemonic');
var code = new Mnemonic(Mnemonic.Words.SPANISH);
code.toString(); // natal hada sutil año sólido papel jamón combate aula flota ver esfera...

var myWordList = [ 'abandon', 'ability', 'able', 'about', 'above', ... ];
var customCode = new Mnemonic(myWordList);

Validating a mnemonic

The Mnemonic class provides a static method to check if a mnemonic string is valid. If you generated the mnemonic code using any of the default word list, the class will identify it, otherwise you must provide the word list used.

var Mnemonic = require('@gohelpfund/helpcore-mnemonic');

var code = 'select scout crash enforce riot rival spring whale hollow radar rule sentence';
var valid = Mnemonic.isValid(code);

// using a custom word list
var validCutom = Mnemonic.isValid(code, customWordlist);

Generating a private key

A mnemonic encodes entropy that can be used for creating a seed and later a HDPrivateKey. During the seed generation process a passphrase can be used. The code for doing so looks like this:

var Mnemonic = require('@gohelpfund/helpcore-mnemonic');
var code = new Mnemonic('select scout crash enforce riot rival spring whale hollow radar rule sentence');

var xpriv1 = code.toHDPrivateKey(); // no passphrase
var xpriv2 = code.toHDPrivateKey('my passphrase'); // using a passphrase