bitcoinjs-lib/src/crypto.js

43 lines
1 KiB
JavaScript
Raw Normal View History

var crypto = require('crypto')
2015-02-23 00:36:57 +01:00
function hash160 (buffer) {
2014-06-26 11:26:21 +02:00
return ripemd160(sha256(buffer))
}
2015-02-23 00:36:57 +01:00
function hash256 (buffer) {
return sha256(sha256(buffer))
}
2015-02-23 00:36:57 +01: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
}
2015-02-23 00:36:57 +01:00
function sha1 (buffer) {
return crypto.createHash('sha1').update(buffer).digest()
}
2015-02-23 00:36:57 +01:00
function sha256 (buffer) {
return crypto.createHash('sha256').update(buffer).digest()
}
// FIXME: Name not consistent with others
2015-02-23 00:36:57 +01: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')
return crypto.createHmac('sha256', secret).update(buffer).digest()
}
2015-02-23 00:36:57 +01: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()
}
module.exports = {
2014-06-26 11:26:21 +02:00
ripemd160: ripemd160,
sha1: sha1,
sha256: sha256,
hash160: hash160,
hash256: hash256,
HmacSHA256: HmacSHA256,
HmacSHA512: HmacSHA512
2014-03-08 06:02:40 +01:00
}