2014-12-13 18:56:14 +00:00
|
|
|
/**
|
2015-01-03 10:29:22 +00:00
|
|
|
* Browser implementation of platform-specific routines.
|
2014-12-13 18:56:14 +00:00
|
|
|
*/
|
2014-12-14 09:24:35 +00:00
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2015-01-03 14:52:27 +00:00
|
|
|
var createHash = require("sha.js");
|
2015-01-05 13:34:52 +00:00
|
|
|
var hash = require("hash.js");
|
2014-12-18 20:54:27 +00:00
|
|
|
|
2014-12-14 09:24:35 +00:00
|
|
|
exports.sha512 = function(buf) {
|
2015-01-03 14:52:27 +00:00
|
|
|
return createHash("sha512").update(buf).digest();
|
2014-12-14 09:24:35 +00:00
|
|
|
};
|
2014-12-18 16:47:18 +00:00
|
|
|
|
2014-12-19 12:34:33 +00:00
|
|
|
exports.sha256 = function(buf) {
|
2015-01-05 13:41:34 +00:00
|
|
|
return new Buffer(hash.sha256().update(buf).digest());
|
2014-12-19 12:34:33 +00:00
|
|
|
};
|
|
|
|
|
2015-01-05 13:34:52 +00:00
|
|
|
exports.ripemd160 = function(buf) {
|
2015-01-05 13:41:34 +00:00
|
|
|
return new Buffer(hash.ripemd160().update(buf).digest());
|
2015-01-05 13:34:52 +00:00
|
|
|
};
|
2014-12-26 17:17:01 +00:00
|
|
|
|
|
|
|
exports.randomBytes = function(size) {
|
|
|
|
var arr = new Uint8Array(size);
|
|
|
|
window.crypto.getRandomValues(arr);
|
|
|
|
return new Buffer(arr);
|
|
|
|
};
|