diff --git a/lib/crypto.browser.js b/lib/crypto.browser.js index d2fd33f..dc78860 100644 --- a/lib/crypto.browser.js +++ b/lib/crypto.browser.js @@ -7,16 +7,20 @@ * * @module bitmessage/crypto.browser */ -// FIXME(Kagami): Support webkit subtle prefix! -// TODO(Kagami): Try to support IE11. "use strict"; require("es6-promise").polyfill(); var ripemd160 = require("ripemd160"); +var assert = require("./utils").assert; + +// Support `webkit` prefix for Safari (not tested yet). +// TODO(Kagami): Try to support IE11. +var subtle = window.crypto.subtle || window.crypto.webkitSubtle; +assert(subtle, "WebCryptoAPI is not supported"); exports.sha512 = function(buf) { - return window.crypto.subtle.digest({name: "SHA-512"}, buf).then(function(arr) { + return subtle.digest({name: "SHA-512"}, buf).then(function(arr) { return new Buffer(new Uint8Array(arr)); }); };