index: default to randomBuffer

This commit is contained in:
Daniel Cousens 2014-06-25 23:47:30 +10:00
parent e569aeb6d7
commit 99981a1de6
2 changed files with 6 additions and 8 deletions

View File

@ -35,9 +35,9 @@ BIP39.prototype.entropyToMnemonic = function(entropy) {
BIP39.prototype.generateMnemonic = function(strength, rng) {
strength = strength || 128
rng = rng || secureRandom
rng = rng || secureRandom.randomBuffer
var hex = rng.randomBuffer(strength / 8).toString('hex')
var hex = rng(strength / 8).toString('hex')
return this.entropyToMnemonic(hex)
}

View File

@ -36,13 +36,11 @@ describe('generateMnemonic', function() {
})
it('allows a custom RNG to be used', function() {
var rng = {
randomBuffer: function(size) {
var rng = 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')