2014-03-10 02:49:53 +00:00
|
|
|
var assert = require('assert')
|
2014-06-23 03:40:38 +00:00
|
|
|
var wordlist = require('../wordlists/en.json')
|
|
|
|
var vectors = require('./vectors.json').english
|
2014-03-10 02:49:53 +00:00
|
|
|
|
2014-06-23 03:40:38 +00:00
|
|
|
var BIP39 = require('../index.js')
|
2014-03-11 08:01:14 +00:00
|
|
|
var bip39 = new BIP39()
|
|
|
|
|
2014-06-23 07:24:52 +00:00
|
|
|
describe('constructor', function() {
|
|
|
|
it('defaults language to english', function() {
|
2014-03-11 04:38:09 +00:00
|
|
|
assert.deepEqual(bip39.wordlist, wordlist)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2014-06-23 07:24:52 +00:00
|
|
|
describe('mnemonicToSeed', function() {
|
|
|
|
vectors.forEach(function(v, i) {
|
|
|
|
it('works for tests vector ' + i, function() {
|
2014-03-10 02:49:53 +00:00
|
|
|
assert.equal(bip39.mnemonicToSeed(v[1], 'TREZOR'), v[2])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2014-03-11 08:01:14 +00:00
|
|
|
|
2014-06-23 07:24:52 +00:00
|
|
|
describe('entropyToMnemonic', function() {
|
|
|
|
vectors.forEach(function(v, i) {
|
|
|
|
it('works for tests vector ' + i, function() {
|
2014-03-11 08:01:14 +00:00
|
|
|
assert.equal(bip39.entropyToMnemonic(v[0]), v[1])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2014-04-05 04:44:16 +00:00
|
|
|
|
2014-06-23 07:56:08 +00:00
|
|
|
describe('generateMnemonic', function() {
|
|
|
|
it('generates a mnemonic', function() {
|
|
|
|
var mnemonic = bip39.generateMnemonic(96)
|
|
|
|
var words = mnemonic.split(' ')
|
|
|
|
|
|
|
|
assert.equal(words.length, 9)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('allows a custom RNG to be used', function() {
|
|
|
|
var rng = {
|
|
|
|
randomBuffer: function(size) {
|
|
|
|
var buffer = new Buffer(size)
|
|
|
|
buffer.fill(4) // guaranteed random
|
|
|
|
return buffer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var mnemonic = bip39.generateMnemonic(64, rng)
|
|
|
|
assert.equal(mnemonic, 'advice cage absurd amount doctor act')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2014-06-23 07:24:52 +00:00
|
|
|
describe('validate', function() {
|
|
|
|
vectors.forEach(function(v, i) {
|
|
|
|
it('passes check ' + i, function() {
|
2014-04-05 04:44:16 +00:00
|
|
|
assert(bip39.validate(v[1]))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2014-06-23 07:24:52 +00:00
|
|
|
it('fails for mnemonics of wrong length', function() {
|
2014-04-05 04:44:16 +00:00
|
|
|
assert(!bip39.validate('sleep kitten'))
|
|
|
|
assert(!bip39.validate('sleep kitten sleep kitten sleep kitten'))
|
|
|
|
})
|
|
|
|
|
2014-06-23 07:24:52 +00:00
|
|
|
it('fails for mnemonics that contains words not from the word list', function() {
|
2014-04-05 04:44:16 +00:00
|
|
|
assert(!bip39.validate("turtle front uncle idea crush write shrug there lottery flower risky shell"))
|
|
|
|
})
|
|
|
|
|
2014-06-23 07:24:52 +00:00
|
|
|
it('fails for mnemonics of invalid checksum', function() {
|
2014-04-05 04:44:16 +00:00
|
|
|
assert(!bip39.validate('sleep kitten sleep kitten sleep kitten sleep kitten sleep kitten sleep kitten'))
|
|
|
|
})
|
|
|
|
})
|