Use Node.js crypto ripemd160 hash if available.

This commit is contained in:
Braydon Fuller 2015-07-08 22:15:20 -04:00
parent 6d86c99314
commit 55afeb3eaf
1 changed files with 11 additions and 2 deletions

View File

@ -28,10 +28,19 @@ Hash.sha256sha256 = function(buf) {
}; };
Hash.ripemd160 = function(buf) { Hash.ripemd160 = function(buf) {
$.checkArgument(BufferUtil.isBuffer(buf));
return crypto.createHash('ripemd160').update(buf).digest();
};
// Node.js crypto ripemd160 hashes are not supported in a browser
// We'll replace with a (slower) version that does.
if (global.window) {
Hash.ripemd160 = function(buf) {
$.checkArgument(BufferUtil.isBuffer(buf)); $.checkArgument(BufferUtil.isBuffer(buf));
var hash = (new hashjs.ripemd160()).update(buf).digest(); var hash = (new hashjs.ripemd160()).update(buf).digest();
return new Buffer(hash); return new Buffer(hash);
}; };
}
Hash.sha256ripemd160 = function(buf) { Hash.sha256ripemd160 = function(buf) {
$.checkArgument(BufferUtil.isBuffer(buf)); $.checkArgument(BufferUtil.isBuffer(buf));