Browse Source

Merge pull request #247 from dcousens/ecurve

Removal of secure-random in favour of crypto-browserify
hk-custom-address
Wei Lu 11 years ago
parent
commit
6e1bbe8ebe
  1. 9
      package.json
  2. 4
      src/eckey.js
  3. 4
      src/wallet.js
  4. 13
      test/eckey.js

9
package.json

@ -73,11 +73,10 @@
},
"dependencies": {
"bigi": "1.1.0",
"bs58": "1.1.0",
"bs58check": "1.0.0",
"bs58": "1.2.1",
"bs58check": "1.0.1",
"crypto-js": "3.1.2-3",
"crypto-browserify": "2.1.8",
"ecurve": "0.10.0",
"secure-random": "1.1.1"
"crypto-browserify": "3.0.0",
"ecurve": "1.0.0"
}
}

4
src/eckey.js

@ -1,8 +1,8 @@
var assert = require('assert')
var base58check = require('bs58check')
var crypto = require('crypto')
var ecdsa = require('./ecdsa')
var networks = require('./networks')
var secureRandom = require('secure-random')
var BigInteger = require('bigi')
var ECPubKey = require('./ecpubkey')
@ -43,7 +43,7 @@ ECKey.fromWIF = function(string) {
}
ECKey.makeRandom = function(compressed, rng) {
rng = rng || secureRandom.randomBuffer
rng = rng || crypto.randomBytes
var buffer = rng(32)
assert(Buffer.isBuffer(buffer), 'Expected Buffer, got ' + buffer)

4
src/wallet.js

@ -1,6 +1,6 @@
var assert = require('assert')
var crypto = require('crypto')
var networks = require('./networks')
var rng = require('secure-random')
var Address = require('./address')
var HDNode = require('./hdnode')
@ -25,7 +25,7 @@ function Wallet(seed, network) {
// Make a new master key
this.newMasterKey = function(seed) {
seed = seed || new Buffer(rng(32))
seed = seed || crypto.randomBytes(32)
masterkey = HDNode.fromSeedBuffer(seed, network)
// HD first-level child derivation method should be hardened

13
test/eckey.js

@ -1,8 +1,7 @@
var assert = require('assert')
var crypto = require('../src/crypto')
var crypto = require('crypto')
var crypto2 = require('../src/crypto')
var networks = require('../src/networks')
var secureRandom = require('secure-random')
var sinon = require('sinon')
var BigInteger = require('bigi')
@ -84,13 +83,13 @@ describe('ECKey', function() {
var exPrivKey = ECKey.fromWIF(exWIF)
var exBuffer = exPrivKey.d.toBuffer(32)
describe('using default RNG', function() {
describe('uses default crypto RNG', function() {
beforeEach(function() {
sinon.stub(secureRandom, 'randomBuffer').returns(exBuffer)
sinon.stub(crypto, 'randomBytes').returns(exBuffer)
})
afterEach(function() {
secureRandom.randomBuffer.restore()
crypto.randomBytes.restore()
})
it('generates a ECKey', function() {
@ -116,7 +115,7 @@ describe('ECKey', function() {
})
describe('signing', function() {
var hash = crypto.sha256('Vires in numeris')
var hash = crypto2.sha256('Vires in numeris')
var priv = ECKey.makeRandom()
var signature = priv.sign(hash)

Loading…
Cancel
Save