2019-03-03 23:07:49 +09:00
|
|
|
const createHash = require('create-hash');
|
2014-04-08 22:13:03 +10:00
|
|
|
|
2019-03-03 23:07:49 +09:00
|
|
|
export function ripemd160(buffer: Buffer): Buffer {
|
2019-04-02 18:57:07 +09:00
|
|
|
try {
|
|
|
|
return createHash('rmd160')
|
|
|
|
.update(buffer)
|
|
|
|
.digest();
|
|
|
|
} catch (err) {
|
|
|
|
return createHash('ripemd160')
|
|
|
|
.update(buffer)
|
|
|
|
.digest();
|
|
|
|
}
|
2014-06-26 19:26:21 +10:00
|
|
|
}
|
|
|
|
|
2019-03-03 23:07:49 +09:00
|
|
|
export function sha1(buffer: Buffer): Buffer {
|
|
|
|
return createHash('sha1')
|
|
|
|
.update(buffer)
|
|
|
|
.digest();
|
2014-04-08 22:13:03 +10:00
|
|
|
}
|
|
|
|
|
2019-03-03 23:07:49 +09:00
|
|
|
export function sha256(buffer: Buffer): Buffer {
|
|
|
|
return createHash('sha256')
|
|
|
|
.update(buffer)
|
|
|
|
.digest();
|
2014-04-08 22:13:03 +10:00
|
|
|
}
|
|
|
|
|
2019-03-03 23:07:49 +09:00
|
|
|
export function hash160(buffer: Buffer): Buffer {
|
|
|
|
return ripemd160(sha256(buffer));
|
2016-09-28 08:44:21 +10:00
|
|
|
}
|
|
|
|
|
2019-03-03 23:07:49 +09:00
|
|
|
export function hash256(buffer: Buffer): Buffer {
|
|
|
|
return sha256(sha256(buffer));
|
2016-09-28 08:44:21 +10:00
|
|
|
}
|