crypto: remove cryptojs

This commit is contained in:
Daniel Cousens 2014-09-06 01:05:50 +10:00
parent e3d05c6f2c
commit c96b862530
6 changed files with 2 additions and 100 deletions

View file

@ -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"
}

View file

@ -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
}

View file

@ -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 = {

View file

@ -1,7 +1,6 @@
module.exports = {
Address: require('./address'),
bufferutils: require('./bufferutils'),
convert: require('./convert'),
crypto: require('./crypto'),
ecdsa: require('./ecdsa'),
ECKey: require('./eckey'),

View file

@ -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)
})
})
})
})

View file

@ -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
}
}
]
}