Socket
Socket
Sign inDemoInstall

dashphrase

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dashphrase

Dash HD Wallet Passphrase generator. Secure, lightweight, BIP-39-compatible Base2048 mnemonic word lists. Works in Node, Bundlers, and Browsers.


Version published
Weekly downloads
63
decreased by-39.42%
Maintainers
1
Weekly downloads
 
Created
Source

dashphrase.js (for browsers)

Secure Dash HD Wallet Passphrase Generator that works in Node, Bundlers, and Browsers.

BIP-39-compatible
uses standard dictionary of Base2048 mnemonic passphrases (word lists)

Lightweight. Zero dependencies. 20kb (17kb min, 7.4kb gz) ~150 LoC.
(most of the package weight is due to the base2048 word list)

Features & Use Cases

  • Base2048 (BIP-0039 compliant)
  • Easy to retype on different devices
  • Seed many, distinct keys from a single passphrase
  • Keys for AES Encryption & Decryption
  • Air Gap security
  • Cryptocurrency wallets
Target EntropyNumber of WordsTotal Bits
128-bit12 words @ 11 bits each= 132 bits (128 bits + 4-bit checksum)
160-bit15 words @ 11 bits each= 165 bits (160 bits + 5-bit checksum)
192-bit18 words @ 11 bits each= 198 bits (192 bits + 6-bit checksum)
224-bit21 words @ 11 bits each= 231 bits (224 bits + 7-bit checksum)
256-bit24 words @ 11 bits each= 264 bits (256 bits + 8-bit checksum)

Install

Node, Bun, & Bundlers:

npm install --save dashphrase@1.2.2
"use strict";

let Dashphrase = require("dashphrase");

Browsers

<script src="https://unpkg.com/dashphrase@1.2.2/dashphrase.js"></script>
<script type="module">
  "use strict";

  let Dashphrase = window.Dashphrase;
  // ...
</script>

Usage

let passphrase = await Dashphrase.generate(128);
// often delay margin arch
// index wrap fault duck
// club fabric demise scout

let keyBytes = await Dashphrase.toSeed(passphrase);
// Uint8Array[64] (suitable for use with importKey for AES, etc)

let fooKeyBytes = await Dashphrase.toSeed(passphrase, "foo");
// Uint8Array[64] (a completely different key, determined by "foo")

Fixture

This is the official Dashphrase test phrase:

zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong

That's eleven (11) 'zoo's and one (1) 'wrong'.

If we decode that, we get the "input entropy".
For extra entropy / projection, we can also use a "secret salt".
If we run the appropriate Key Derivation on those we the "seed".
Described as JSON:

With secret salt:

{
  "inputEntropy": "ffffffffffffffffffffffffffffffff",
  "passphraseMnemonic": "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong",
  "secretSalt": "TREZOR",
  "seed": "ac27495480225222079d7be181583751e86f571027b0497b5b5d11218e0a8a13332572917f0f8e5a589620c6f15b11c61dee327651a14c34e18231052e48c069"
}

Empty secret salt:

{
  "inputEntropy": "ffffffffffffffffffffffffffffffff",
  "passphraseMnemonic": "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong",
  "secretSalt": "",
  "seed": "b6a6d8921942dd9806607ebc2750416b289adea669198769f2e15ed926c3aa92bf88ece232317b4ea463e84b0fcd3b53577812ee449ccc448eb45e6f544e25b6"
}

API

  • generate
    • encode
  • verify (checksum)
    • decode
  • toSeed
  • base2048.includes

Dashphrase.generate(bitlen)

Generate a "Base2048" passphrase - each word represents 11 bits of entropy.

await Dashphrase.generate(bitLen); // *128*, 160, 192, 224, or 256

Dashphrase.encode(bytes)

Encode an array of 16, 20, 24, 28, or 32 bytes (typically a Uint8Array) into a passphrase using the Base2048 word list dictionary.

let bytes = Uint8Array.from([0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255]);

await Dashphrase.encode(bytes);
// "abstract way divert acid useless legend advance theme youth"

Dashphrase.verify(passphrase)

We all make mistakes. Especially typos.

Running the checksum can't guarantee that the passphrase is correct, but most typos - such as brocolli instead of broccoli - will cause it to fail, so that's a start.
(although this does check the checksum as well)

let passphrase = "often delay margin arch ...";
await Dashphrase.verify(passphrase); // true
let passphrase = "often delay margin arch TYPO";
await Dashphrase.verify(passphrase).catch(function (err) {
  // checksum failed?
  throw err;
});

Dashphrase.decode(words, { verify: true })

Decode an string of space-delimited words from the Base2048 dictionary into a Uint8Array.

This will throw an error if any non-Base2048-compatible words are used, or if the checksum does not match.

let words = "abstract way divert acid useless legend advance theme youth";

await Dashphrase.decode(words);
// Uint8Array[12] <0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255>

Dashphrase.toSeed(passphraseMnemonic, saltPassword)

Generate a private key seed or encryption key based on the passphrase (mnemonic word list) and some other string - whether a salt, a password, another passphrase or secret, or an id of some kind.

await Dashphrase.toSeed(passphraseMnemonic, saltPassword || ""); // Uint8Array[64]

Dashphrase.base2048.includes(word)

Check if a given word exists in the base2048 dictionary.

Dashphrase.base2048.includes("broccoli"); // true
Dashphrase.base2048.includes("brocolli"); // false
Get all misspelled words
"hammer spoon brocolli zoo".split(" ").filter(function (word) {
  return word && !Dashphrase.base2048.includes(word);
});
// [ "brocolli" ]

Compatibility Testing

npm run test

LICENSE

Copyright 2023 Dash Incubator
(forked from therootcompany/passphrase.js, re-license as MIT with permission)
Copyright 2021 AJ ONeal (MPL-2.0 License)
Copyright 2021 Root, LLC (MPL-2.0 License)

Keywords

FAQs

Package last updated on 04 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc