bitmessage-js/lib/crypto.browser.js

29 lines
846 B
JavaScript
Raw Normal View History

2014-12-13 19:56:14 +01:00
/**
* Browser version of the crypto for Bitmessage JS implementation.
2014-12-18 17:47:18 +01:00
*
* Documentation: <http://www.w3.org/TR/WebCryptoAPI/>
* Browsers support: <http://caniuse.com/#feat=cryptography>
* Blink implementation details: <https://sites.google.com/a/chromium.org/dev/blink/webcrypto>
*
* @module bitmessage/crypto.browser
2014-12-13 19:56:14 +01:00
*/
2014-12-18 17:47:18 +01:00
// FIXME(Kagami): Support webkit subtle prefix!
// TODO(Kagami): Try to support IE11.
"use strict";
2014-12-18 17:47:18 +01:00
require("es6-promise").polyfill();
var ripemd160 = require("ripemd160");
exports.sha512 = function(buf) {
return window.crypto.subtle.digest({name: "SHA-512"}, buf).then(function(arr) {
return new Buffer(new Uint8Array(arr));
});
};
2014-12-18 17:47:18 +01:00
exports.ripemd160 = function(buf) {
// XXX(Kagami): No support in browsers via Web Crypto API currently,
// so use module.
return Promise.resolve(ripemd160(buf));
};