bip39/test
d-yokoi 9f805dfd82
prefer const in README examples
2019-03-25 22:47:27 +09:00
..
index.js prefer simpler module path 2019-03-24 20:49:42 +09:00
readme.js prefer const in README examples 2019-03-25 22:47:27 +09:00
vectors.json Revert "fix issue with 11 bit padding messing up checksum check." 2016-10-06 12:49:50 +02:00
wordlist.json BIP39: allow for custom wordlists 2014-08-13 19:42:21 +10:00

readme.js

const bip39 = require('../')
const Buffer = require('safe-buffer').Buffer
const proxyquire = require('proxyquire')
const test = require('tape')

test('README example 1', function (t) {
  // defaults to BIP39 English word list
  const entropy = 'ffffffffffffffffffffffffffffffff'
  const mnemonic = bip39.entropyToMnemonic(entropy)

  t.plan(2)
  t.equal(mnemonic, 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong')

  // reversible
  t.equal(bip39.mnemonicToEntropy(mnemonic), entropy)
})

test('README example 2', function (t) {
  const stub = {
    randombytes: function (size) {
      return Buffer.from('qwertyuiopasdfghjklzxcvbnm[];,./'.slice(0, size), 'utf8')
    }
  }
  const proxiedbip39 = proxyquire('../', stub)

  // mnemonic strength defaults to 128 bits
  const mnemonic = proxiedbip39.generateMnemonic()

  t.plan(2)
  t.equal(mnemonic, 'imitate robot frame trophy nuclear regret saddle around inflict case oil spice')
  t.equal(bip39.validateMnemonic(mnemonic), true)
})

test('README example 3', function (t) {
  const mnemonic = 'basket actual'
  const seed = bip39.mnemonicToSeed(mnemonic)
  const seedHex = bip39.mnemonicToSeedHex(mnemonic)

  t.plan(3)
  t.equal(seed.toString('hex'), seedHex)
  t.equal(seedHex, '5cf2d4a8b0355e90295bdfc565a022a409af063d5365bb57bf74d9528f494bfa4400f53d8349b80fdae44082d7f9541e1dba2b003bcfec9d0d53781ca676651f')
  t.equal(bip39.validateMnemonic(mnemonic), false)
})