add fallback to browser is secp256k1
This commit is contained in:
parent
1cbc1bdd9f
commit
0ebe1f0be6
|
@ -7,7 +7,7 @@
|
|||
var EC = require("elliptic").ec;
|
||||
|
||||
var ec = new EC("secp256k1");
|
||||
var cryptoObj = window.crypto || window.msCrypto || {};
|
||||
var cryptoObj = global.crypto || global.msCrypto || {};
|
||||
var subtle = cryptoObj.subtle || cryptoObj.webkitSubtle;
|
||||
|
||||
function assert(condition, message) {
|
||||
|
@ -18,7 +18,7 @@ function assert(condition, message) {
|
|||
|
||||
function randomBytes(size) {
|
||||
var arr = new Uint8Array(size);
|
||||
window.crypto.getRandomValues(arr);
|
||||
global.crypto.getRandomValues(arr);
|
||||
return new Buffer(arr);
|
||||
}
|
||||
|
||||
|
|
7
index.js
7
index.js
|
@ -9,9 +9,12 @@ var promise = typeof Promise === "undefined" ?
|
|||
require("es6-promise").Promise :
|
||||
Promise;
|
||||
var crypto = require("crypto");
|
||||
// TODO(Kagami): We may fallback to pure JS implementation
|
||||
// (`browser.js`) if this modules are failed to load.
|
||||
// try to use secp256k1, fallback to browser implementation
|
||||
try {
|
||||
var secp256k1 = require("secp256k1");
|
||||
} catch (e) {
|
||||
return module.exports = require("./browser");
|
||||
}
|
||||
var ecdh = require("./build/Release/ecdh");
|
||||
|
||||
function assert(condition, message) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user