bitcoinjs-lib/src/util.js

27 lines
751 B
JavaScript
Raw Normal View History

var convert = require('./convert.js')
2014-03-08 13:02:40 +08:00
var Crypto = require('crypto-js');
var RIPEMD160 = Crypto.RIPEMD160;
var SHA256 = Crypto.SHA256;
var HMAC= Crypto.algo.HMAC;
2013-11-18 23:47:56 -05:00
2014-01-11 13:57:05 +07:00
/**
* Calculate RIPEMD160(SHA256(data)).
*
* Takes an arbitrary byte array as inputs and returns the hash as a byte
* array.
*/
exports.sha256ripe160 = function (data) {
var wordArray = RIPEMD160(SHA256(convert.bytesToWordArray(data)))
return convert.wordArrayToBytes(wordArray)
2014-03-08 13:02:40 +08:00
}
exports.HmacFromBytesToBytes = function (hasher, message, key) {
var hmac = HMAC.create(hasher, convert.bytesToWordArray(key))
hmac.update(convert.bytesToWordArray(message))
return convert.wordArrayToBytes(hmac.finalize())
2014-01-11 13:57:05 +07:00
}
exports.error = function(msg) {
throw new Error(msg);
2014-01-11 13:57:05 +07:00
}