2019-03-25 22:47:27 +09:00
|
|
|
const bip39 = require('../')
|
|
|
|
const Buffer = require('safe-buffer').Buffer
|
|
|
|
const proxyquire = require('proxyquire')
|
|
|
|
const test = require('tape')
|
2017-05-12 12:26:48 +10:00
|
|
|
|
|
|
|
test('README example 1', function (t) {
|
|
|
|
// defaults to BIP39 English word list
|
2019-03-25 22:47:27 +09:00
|
|
|
const entropy = 'ffffffffffffffffffffffffffffffff'
|
|
|
|
const mnemonic = bip39.entropyToMnemonic(entropy)
|
2017-05-12 12:26:48 +10:00
|
|
|
|
|
|
|
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) {
|
2019-03-25 22:47:27 +09:00
|
|
|
const stub = {
|
2017-05-12 12:26:48 +10:00
|
|
|
randombytes: function (size) {
|
2018-12-20 15:15:25 +09:00
|
|
|
return Buffer.from('qwertyuiopasdfghjklzxcvbnm[];,./'.slice(0, size), 'utf8')
|
2017-05-12 12:26:48 +10:00
|
|
|
}
|
|
|
|
}
|
2019-03-25 22:47:27 +09:00
|
|
|
const proxiedbip39 = proxyquire('../', stub)
|
2017-05-12 12:26:48 +10:00
|
|
|
|
|
|
|
// mnemonic strength defaults to 128 bits
|
2019-03-25 22:47:27 +09:00
|
|
|
const mnemonic = proxiedbip39.generateMnemonic()
|
2017-05-12 12:26:48 +10:00
|
|
|
|
|
|
|
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) {
|
2019-03-25 22:47:27 +09:00
|
|
|
const mnemonic = 'basket actual'
|
2019-04-02 18:03:44 +09:00
|
|
|
const seed = bip39.mnemonicToSeedSync(mnemonic)
|
2017-05-12 12:26:48 +10:00
|
|
|
|
2019-04-02 18:03:44 +09:00
|
|
|
t.plan(2)
|
|
|
|
t.equal(seed.toString('hex'), '5cf2d4a8b0355e90295bdfc565a022a409af063d5365bb57bf74d9528f494bfa4400f53d8349b80fdae44082d7f9541e1dba2b003bcfec9d0d53781ca676651f')
|
2017-05-12 12:26:48 +10:00
|
|
|
t.equal(bip39.validateMnemonic(mnemonic), false)
|
|
|
|
})
|