SHA-256 crypto (for WIF)
This commit is contained in:
parent
6e4cb56a27
commit
2e9f064e7e
|
@ -25,6 +25,12 @@ exports.sha512 = function(buf) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.sha256 = function(buf) {
|
||||||
|
return subtle.digest({name: "SHA-256"}, buf).then(function(arr) {
|
||||||
|
return new Buffer(new Uint8Array(arr));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
exports.ripemd160 = function(buf) {
|
exports.ripemd160 = function(buf) {
|
||||||
// XXX(Kagami): No support in browsers via Web Crypto API currently,
|
// XXX(Kagami): No support in browsers via Web Crypto API currently,
|
||||||
// so use module.
|
// so use module.
|
||||||
|
|
|
@ -14,6 +14,12 @@ exports.sha512 = function(buf) {
|
||||||
return Promise.resolve(hash.digest());
|
return Promise.resolve(hash.digest());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.sha256 = function(buf) {
|
||||||
|
var hash = crypto.createHash("sha256");
|
||||||
|
hash.update(buf);
|
||||||
|
return Promise.resolve(hash.digest());
|
||||||
|
};
|
||||||
|
|
||||||
exports.ripemd160 = function(buf) {
|
exports.ripemd160 = function(buf) {
|
||||||
var hash = crypto.createHash("ripemd160");
|
var hash = crypto.createHash("ripemd160");
|
||||||
hash.update(buf);
|
hash.update(buf);
|
||||||
|
|
6
test.js
6
test.js
|
@ -47,6 +47,12 @@ describe("Crypto", function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should implement SHA-256 hash", function() {
|
||||||
|
return bmcrypto.sha256(Buffer("test")).then(function(res) {
|
||||||
|
expect(res.toString("hex")).to.equal("9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("should implement RIPEMD-160 hash", function() {
|
it("should implement RIPEMD-160 hash", function() {
|
||||||
return bmcrypto.ripemd160(Buffer("test")).then(function(res) {
|
return bmcrypto.ripemd160(Buffer("test")).then(function(res) {
|
||||||
expect(res.toString("hex")).to.equal("5e52fee47e6b070565f74372468cdc699de89107");
|
expect(res.toString("hex")).to.equal("5e52fee47e6b070565f74372468cdc699de89107");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user