Skip to content
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
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"url": "https://github.com/bitcoinjs/bitcoinjs-lib.git"
},
"devDependencies": {
"browserify": "~4.1.5",
"browserify": "4.1.11",
"coveralls": "~2.10.0",
"helloblock-js": "^0.2.1",
"istanbul": "0.1.30",
Expand Down Expand Up @@ -68,9 +68,13 @@
"test": "npm run-script unit",
"unit": "./node_modules/.bin/istanbul test ./node_modules/.bin/_mocha -- --reporter list `find test -maxdepth 1 -not -type d`"
},
"browser": {
"crypto": "crypto-browserify"
},
"dependencies": {
"bigi": "1.1.0",
"crypto-js": "3.1.2-3",
"crypto-browserify": "2.1.8",
"ecurve": "0.10.0",
"secure-random": "0.2.1"
}
Expand Down
12 changes: 6 additions & 6 deletions src/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ var crypto = require('crypto')
var convert = require('./convert')

function hash160(buffer) {
var step1 = sha256(buffer)

var step2a = convert.bufferToWordArray(step1)
var step2b = CryptoJS.RIPEMD160(step2a)

return convert.wordArrayToBuffer(step2b)
return ripemd160(sha256(buffer))
}

function hash256(buffer) {
return sha256(sha256(buffer))
}

function ripemd160(buffer) {
return crypto.createHash('rmd160').update(buffer).digest()
}

function sha1(buffer) {
return crypto.createHash('sha1').update(buffer).digest()
}
Expand All @@ -43,6 +42,7 @@ function HmacSHA512(data, secret) {
}

module.exports = {
ripemd160: ripemd160,
sha1: sha1,
sha256: sha256,
hash160: hash160,
Expand Down
43 changes: 23 additions & 20 deletions test/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ describe('Crypto', function() {
it('matches the test vectors', function() {
fixtures.before.hex.forEach(function(hex, i) {
var data = new Buffer(hex, 'hex')
var actual = crypto.hash160(data)
var expected = fixtures.after.hash160[i]
var actual = crypto.hash160(data).toString('hex')

assert.equal(actual.toString('hex'), expected)
assert.equal(actual, fixtures.after.hash160[i])
})
})
})
Expand All @@ -20,10 +19,20 @@ describe('Crypto', function() {
it('matches the test vectors', function() {
fixtures.before.hex.forEach(function(hex, i) {
var data = new Buffer(hex, 'hex')
var actual = crypto.hash256(data)
var expected = fixtures.after.hash256[i]
var actual = crypto.hash256(data).toString('hex')

assert.equal(actual.toString('hex'), expected)
assert.equal(actual, fixtures.after.hash256[i])
})
})
})

describe('RIPEMD160', function() {
it('matches the test vectors', function() {
fixtures.before.hex.forEach(function(hex, i) {
var data = new Buffer(hex, 'hex')
var actual = crypto.ripemd160(data).toString('hex')

assert.equal(actual, fixtures.after.ripemd160[i])
})
})
})
Expand All @@ -32,10 +41,9 @@ describe('Crypto', function() {
it('matches the test vectors', function() {
fixtures.before.hex.forEach(function(hex, i) {
var data = new Buffer(hex, 'hex')
var actual = crypto.sha1(data)
var expected = fixtures.after.sha1[i]
var actual = crypto.sha1(data).toString('hex')

assert.equal(actual.toString('hex'), expected)
assert.equal(actual, fixtures.after.sha1[i])
})
})
})
Expand All @@ -44,10 +52,9 @@ describe('Crypto', function() {
it('matches the test vectors', function() {
fixtures.before.hex.forEach(function(hex, i) {
var data = new Buffer(hex, 'hex')
var actual = crypto.sha256(data)
var expected = fixtures.after.sha256[i]
var actual = crypto.sha256(data).toString('hex')

assert.equal(actual.toString('hex'), expected)
assert.equal(actual, fixtures.after.sha256[i])
})
})
})
Expand All @@ -57,11 +64,9 @@ describe('Crypto', function() {
fixtures.before.hex.forEach(function(hex, i) {
var data = new Buffer(hex, 'hex')
var secret = new Buffer(fixtures.before.secret)
var actual = crypto.HmacSHA256(data, secret).toString('hex')

var actual = crypto.HmacSHA256(data, secret)
var expected = fixtures.after.hmacsha256[i]

assert.equal(actual.toString('hex'), expected)
assert.equal(actual, fixtures.after.hmacsha256[i])
})
})
})
Expand All @@ -71,11 +76,9 @@ describe('Crypto', function() {
fixtures.before.hex.forEach(function(hex, i) {
var data = new Buffer(hex, 'hex')
var secret = new Buffer(fixtures.before.secret)
var actual = crypto.HmacSHA512(data, secret).toString('hex')

var actual = crypto.HmacSHA512(data, secret)
var expected = fixtures.after.hmacsha512[i]

assert.equal(actual.toString('hex'), expected)
assert.equal(actual, fixtures.after.hmacsha512[i])
})
})
})
Expand Down
9 changes: 7 additions & 2 deletions test/fixtures/crypto.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"4c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e20446f6e65632061742066617563696275732073617069656e2c2076656c20666163696c6973697320617263752e20536564207574206d61737361206e6962682e205574206d6f6c6c69732070756c76696e6172206d617373612e20557420756c6c616d636f7270657220646f6c6f7220656e696d2c20696e206d6f6c657374696520656e696d20636f6e64696d656e74756d2061632e20416c697175616d206572617420766f6c75747061742e204e756c6c6120736f64616c657320617420647569206e656320"
]
},

"after": {
"hash160": [
"cdb00698f02afd929ffabea308340fa99ac2afa8",
Expand All @@ -22,6 +21,12 @@
"752adad0a7b9ceca853768aebb6965eca126a62965f698a0c1bc43d83db632ad",
"033588797115feb3545052670cac2a46584ab3cb460de63756ee0275e66b5799"
],
"ripemd160": [
"8d1a05d1bc08870968eb8a81ad4393fd3aac6633",
"5825701b4b9767fd35063b286dca3582853e0630",
"cb760221600ed34337ca3ab70016b5f58c838120",
"cad8593dcdef12ee334c97bab9787f07b3f3a1a5"
],
"sha1": [
"cb473678976f425d6ec1339838f11011007ad27d",
"c0357a32ed1f6a03be92dd094476f7f1a2e214ec",
Expand All @@ -47,4 +52,4 @@
"7dee95aa3c462d3eb7ecb61536cb215e471d1fa73d8643a967905946e26c536588c5058abd5a049a22b987db95a7fb420f3bff12359dc53d03d7ce7df714e029"
]
}
}
}