npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@duality-solutions/bitcore-mnemonic-dynamic

v1.0.1

Published

BIP39 Mnemonics for Dynamic

Downloads

17

Readme

bitcore-mnemonic-dynamic

Note: This package has been deprecated

This module is superceded the functionality in @duality-solutions/dynamic-lib, please use that package moving forward.

Build Status NPM Package

BIP39 Mnemonics for Dynamic

A module for bitcore-lib-dynamic that implements Mnemonic code for generating deterministic keys.

Install

npm install @duality-solutions/dynamic-mnemonic

Usage

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.

There are many examples of how to use it on the developer guide section for mnemonic. For example, the following code would generate a new random mnemonic code and convert it to a HDPrivateKey.

var Mnemonic = require('@duality-solutions/bitcore-mnemonic-dynamic');
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('@duality-solutions/bitcore-mnemonic-dynamic');
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('@duality-solutions/bitcore-mnemonic-dynamic');
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('@duality-solutions/bitcore-mnemonic-dynamic');

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('@duality-solutions/bitcore-mnemonic-dynamic');
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

Browser Usage

A webpack config is included in order to build a browser bundle:

npm run build

This will generate a file dist/dynamic-mnemonic.js, which can be included into your HTML a-like so:

<html lang="en">
<head>
  <title>Tester - Bitcore Mnemonic Dynamic</title>
  <script language="javascript" src="dist/bitcore-mnemonic-dynamic.js"></script>
</head>
<body>
  <script>
    document.addEventListener("DOMContentLoaded", function() {
      var mnemonic = new dynamicMnemonic();
      console.log("MNEMONIC: " + mnemonic.toString());

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

      console.log("xpriv1: " + xpriv1);
      console.log("xpriv2: " + xpriv2);
    });
  </script>
</body>
</html>

This test snippet is included as a file in this repo called "example.html", and you can test this in a browser. We'll use Docker to simplify this:

docker run --rm --name nginx -p 127.0.0.1:80:80 -v $PWD:/usr/share/nginx/html nginx:alpine

Now navigate to http://localhost/example.html and open a console window. You should see the expected console output from the console.log lines in the HTML snippet above.

Contributing

Feel free to dive in! Open an issue or submit PRs.

License

Code released under the MIT license.

Copyright 2013-2019 BitPay, Inc. Bitcore is a trademark maintained by BitPay, Inc.
Copyright 2019 Duality Blockchain Solutions LLC.