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