2014-04-08 14:13:03 +02:00
|
|
|
var crypto = require('crypto')
|
|
|
|
|
|
|
|
function hash160(buffer) {
|
2014-06-26 11:26:21 +02:00
|
|
|
return ripemd160(sha256(buffer))
|
2014-04-08 14:13:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function hash256(buffer) {
|
|
|
|
return sha256(sha256(buffer))
|
|
|
|
}
|
|
|
|
|
2014-06-26 11:26:21 +02:00
|
|
|
function ripemd160(buffer) {
|
2014-06-26 11:26:54 +02:00
|
|
|
return crypto.createHash('rmd160').update(buffer).digest()
|
2014-06-26 11:26:21 +02:00
|
|
|
}
|
|
|
|
|
2014-04-08 14:13:03 +02:00
|
|
|
function sha1(buffer) {
|
|
|
|
return crypto.createHash('sha1').update(buffer).digest()
|
|
|
|
}
|
|
|
|
|
|
|
|
function sha256(buffer) {
|
|
|
|
return crypto.createHash('sha256').update(buffer).digest()
|
|
|
|
}
|
|
|
|
|
2014-05-10 01:55:55 +02:00
|
|
|
// FIXME: Name not consistent with others
|
2014-05-16 04:36:09 +02:00
|
|
|
function HmacSHA256(buffer, secret) {
|
2014-12-08 01:13:42 +01:00
|
|
|
console.warn('Hmac* functions are deprecated for removal in 2.0.0, use node crypto instead')
|
2014-05-16 04:36:09 +02:00
|
|
|
return crypto.createHmac('sha256', secret).update(buffer).digest()
|
|
|
|
}
|
|
|
|
|
2014-09-05 17:05:50 +02:00
|
|
|
function HmacSHA512(buffer, secret) {
|
2014-12-08 01:13:42 +01:00
|
|
|
console.warn('Hmac* functions are deprecated for removal in 2.0.0, use node crypto instead')
|
2014-09-05 17:05:50 +02:00
|
|
|
return crypto.createHmac('sha512', secret).update(buffer).digest()
|
2014-05-10 01:55:55 +02:00
|
|
|
}
|
|
|
|
|
2014-04-08 14:13:03 +02:00
|
|
|
module.exports = {
|
2014-06-26 11:26:21 +02:00
|
|
|
ripemd160: ripemd160,
|
2014-04-08 14:13:03 +02:00
|
|
|
sha1: sha1,
|
|
|
|
sha256: sha256,
|
|
|
|
hash160: hash160,
|
2014-05-10 01:55:55 +02:00
|
|
|
hash256: hash256,
|
2014-05-16 04:36:09 +02:00
|
|
|
HmacSHA256: HmacSHA256,
|
2014-05-10 01:55:55 +02:00
|
|
|
HmacSHA512: HmacSHA512
|
2014-03-08 06:02:40 +01:00
|
|
|
}
|