diff --git a/package.json b/package.json index 3b5cf18..7d766ac 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,6 @@ "bigi": "1.1.0", "bs58": "1.2.1", "bs58check": "1.0.1", - "crypto-js": "3.1.2-3", "crypto-browserify": "3.0.0", "ecurve": "1.0.0" } diff --git a/src/convert.js b/src/convert.js deleted file mode 100644 index 8548866..0000000 --- a/src/convert.js +++ /dev/null @@ -1,32 +0,0 @@ -var assert = require('assert') -var Crypto = require('crypto-js') -var WordArray = Crypto.lib.WordArray - -function bufferToWordArray(buffer) { - assert(Buffer.isBuffer(buffer), 'Expected Buffer, got', buffer) - - var words = [] - for (var i = 0, b = 0; i < buffer.length; i++, b += 8) { - words[b >>> 5] |= buffer[i] << (24 - b % 32) - } - - return new WordArray.init(words, buffer.length) -} - -function wordArrayToBuffer(wordArray) { - assert(Array.isArray(wordArray.words), 'Expected WordArray, got' + wordArray) - - var words = wordArray.words - var buffer = new Buffer(words.length * 4) - - words.forEach(function(value, i) { - buffer.writeInt32BE(value & -1, i * 4) - }) - - return buffer -} - -module.exports = { - bufferToWordArray: bufferToWordArray, - wordArrayToBuffer: wordArrayToBuffer -} diff --git a/src/crypto.js b/src/crypto.js index 1c8423b..890bf0a 100644 --- a/src/crypto.js +++ b/src/crypto.js @@ -1,8 +1,4 @@ -// Crypto, crypto, where art thou crypto -var assert = require('assert') -var CryptoJS = require('crypto-js') var crypto = require('crypto') -var convert = require('./convert') function hash160(buffer) { return ripemd160(sha256(buffer)) @@ -29,16 +25,8 @@ function HmacSHA256(buffer, secret) { return crypto.createHmac('sha256', secret).update(buffer).digest() } -function HmacSHA512(data, secret) { - assert(Buffer.isBuffer(data), 'Expected Buffer for data, got ' + data) - assert(Buffer.isBuffer(secret), 'Expected Buffer for secret, got ' + secret) - - var dataWords = convert.bufferToWordArray(data) - var secretWords = convert.bufferToWordArray(secret) - - var hash = CryptoJS.HmacSHA512(dataWords, secretWords) - - return convert.wordArrayToBuffer(hash) +function HmacSHA512(buffer, secret) { + return crypto.createHmac('sha512', secret).update(buffer).digest() } module.exports = { diff --git a/src/index.js b/src/index.js index 73f3c1e..0ab57e2 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,6 @@ module.exports = { Address: require('./address'), bufferutils: require('./bufferutils'), - convert: require('./convert'), crypto: require('./crypto'), ecdsa: require('./ecdsa'), ECKey: require('./eckey'), diff --git a/test/convert.js b/test/convert.js deleted file mode 100644 index 0b06e44..0000000 --- a/test/convert.js +++ /dev/null @@ -1,27 +0,0 @@ -var assert = require('assert') -var convert = require('../src/convert') - -var fixtures = require('./fixtures/convert') - -describe('convert', function() { - describe('bufferToWordArray', function() { - fixtures.valid.forEach(function(f) { - it('converts ' + f.hex + ' correctly', function() { - var buffer = new Buffer(f.hex, 'hex') - var result = convert.bufferToWordArray(buffer) - - assert.deepEqual(result, f.wordArray) - }) - }) - }) - - describe('wordArrayToBuffer', function() { - fixtures.valid.forEach(function(f) { - it('converts to ' + f.hex + ' correctly', function() { - var resultHex = convert.wordArrayToBuffer(f.wordArray).toString('hex') - - assert.deepEqual(resultHex, f.hex) - }) - }) - }) -}) diff --git a/test/fixtures/convert.json b/test/fixtures/convert.json deleted file mode 100644 index b759004..0000000 --- a/test/fixtures/convert.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "valid": [ - { - "hex": "0000000000000000000000000000000000000000", - "wordArray": { - "words": [0, 0, 0, 0, 0], - "sigBytes": 20 - } - }, - { - "hex": "62e907b15cbf27d5425399ebf6f0fb50ebb88f18", - "wordArray": { - "words": [1659439025, 1556031445, 1112775147, -151979184, -340226280], - "sigBytes": 20 - } - }, - { - "hex": "ffffffffffffffffffffffffffffffffffffffff", - "wordArray": { - "words": [-1, -1, -1, -1, -1], - "sigBytes": 20 - } - } - ] -}