Better handling of crypto object
This commit is contained in:
parent
aa37b2a599
commit
5311484662
|
@ -7,8 +7,8 @@
|
||||||
var EC = require("elliptic").ec;
|
var EC = require("elliptic").ec;
|
||||||
|
|
||||||
var ec = new EC("secp256k1");
|
var ec = new EC("secp256k1");
|
||||||
// TODO(Kagami): Try to support IE11.
|
var cryptoObj = window.crypto || window.msCrypto || {};
|
||||||
var subtle = window.crypto.subtle || window.crypto.webkitSubtle;
|
var subtle = cryptoObj.subtle || cryptoObj.webkitSubtle;
|
||||||
|
|
||||||
function assert(condition, message) {
|
function assert(condition, message) {
|
||||||
if (!condition) {
|
if (!condition) {
|
||||||
|
@ -111,7 +111,7 @@ var derive = exports.derive = function(privateKeyA, publicKeyB) {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.encrypt = function(publicKeyTo, msg, opts) {
|
exports.encrypt = function(publicKeyTo, msg, opts) {
|
||||||
assert(subtle, "WebCryptoAPI is not supported");
|
assert(subtle, "WebCryptoAPI is not available");
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
// Tmp variables to save context from flat promises;
|
// Tmp variables to save context from flat promises;
|
||||||
var iv, ephemPublicKey, ciphertext, macKey;
|
var iv, ephemPublicKey, ciphertext, macKey;
|
||||||
|
@ -141,7 +141,7 @@ exports.encrypt = function(publicKeyTo, msg, opts) {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.decrypt = function(privateKey, opts) {
|
exports.decrypt = function(privateKey, opts) {
|
||||||
assert(subtle, "WebCryptoAPI is not supported");
|
assert(subtle, "WebCryptoAPI is not available");
|
||||||
// Tmp variable to save context from flat promises;
|
// Tmp variable to save context from flat promises;
|
||||||
var encryptionKey;
|
var encryptionKey;
|
||||||
return derive(privateKey, opts.ephemPublicKey).then(function(Px) {
|
return derive(privateKey, opts.ephemPublicKey).then(function(Px) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user