Skip to content

Removal of secure-random in favour of crypto-browserify #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 2 additions & 2 deletions src/eckey.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/wallet.js
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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
Expand Down
13 changes: 6 additions & 7 deletions test/eckey.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
var assert = require('assert')
var crypto = require('../src/crypto')
var crypto = require('crypto')
var crypto2 = require('../src/crypto')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big fan of the name here. Seems like crypto2 is only used once so why not var sha256 = require('../src/crypto').sha256?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, will apply a suitable fix directly.

var networks = require('../src/networks')

var secureRandom = require('secure-random')
var sinon = require('sinon')

var BigInteger = require('bigi')
Expand Down Expand Up @@ -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() {
Expand All @@ -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)

Expand Down