add random function.
This commit is contained in:
parent
aadb1fb4e0
commit
abcd174bd3
@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
var bcoin = require('../bcoin');
|
||||
var elliptic = require('elliptic');
|
||||
var bn = require('bn.js');
|
||||
var utils = bcoin.utils;
|
||||
var assert = utils.assert;
|
||||
@ -31,6 +32,12 @@ ec.generate = function generate(options) {
|
||||
return { privateKey: priv, publicKey: pub };
|
||||
};
|
||||
|
||||
ec.random = function random(size) {
|
||||
if (bcoin.crypto)
|
||||
return bcoin.crypto.randomBytes(size);
|
||||
return new Buffer(elliptic.rand(size));
|
||||
};
|
||||
|
||||
ec.verify = function verify(msg, sig, key, historical) {
|
||||
if (key.getPublicKey)
|
||||
key = key.getPublicKey();
|
||||
|
||||
@ -75,7 +75,7 @@ function HDSeed(options) {
|
||||
options = options || {};
|
||||
|
||||
this.bits = options.bits || 128;
|
||||
this.entropy = options.entropy || new Buffer(elliptic.rand(this.bits / 8));
|
||||
this.entropy = options.entropy || bcoin.ec.random(this.bits / 8);
|
||||
this.mnemonic = options.mnemonic || HDSeed._mnemonic(this.entropy);
|
||||
this.seed = this.createSeed(options.passphrase);
|
||||
}
|
||||
@ -622,7 +622,7 @@ HDPrivateKey.prototype._generate = function _generate(privateKey, entropy) {
|
||||
privateKey = bcoin.keypair._fromSecret(privateKey).privateKey;
|
||||
|
||||
if (!entropy)
|
||||
entropy = new Buffer(elliptic.rand(32));
|
||||
entropy = bcoin.ec.random(32);
|
||||
|
||||
return {
|
||||
version: network[this.network].prefixes.xprivkey,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user