Merge pull request #4 from englercj/master
Add fallback to browser is secp256k1
This commit is contained in:
commit
b8be4b2f64
|
@ -7,7 +7,7 @@
|
||||||
var EC = require("elliptic").ec;
|
var EC = require("elliptic").ec;
|
||||||
|
|
||||||
var ec = new EC("secp256k1");
|
var ec = new EC("secp256k1");
|
||||||
var cryptoObj = window.crypto || window.msCrypto || {};
|
var cryptoObj = global.crypto || global.msCrypto || {};
|
||||||
var subtle = cryptoObj.subtle || cryptoObj.webkitSubtle;
|
var subtle = cryptoObj.subtle || cryptoObj.webkitSubtle;
|
||||||
|
|
||||||
function assert(condition, message) {
|
function assert(condition, message) {
|
||||||
|
@ -18,7 +18,7 @@ function assert(condition, message) {
|
||||||
|
|
||||||
function randomBytes(size) {
|
function randomBytes(size) {
|
||||||
var arr = new Uint8Array(size);
|
var arr = new Uint8Array(size);
|
||||||
window.crypto.getRandomValues(arr);
|
global.crypto.getRandomValues(arr);
|
||||||
return new Buffer(arr);
|
return new Buffer(arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
index.js
11
index.js
|
@ -9,10 +9,17 @@ var promise = typeof Promise === "undefined" ?
|
||||||
require("es6-promise").Promise :
|
require("es6-promise").Promise :
|
||||||
Promise;
|
Promise;
|
||||||
var crypto = require("crypto");
|
var crypto = require("crypto");
|
||||||
// TODO(Kagami): We may fallback to pure JS implementation
|
// try to use secp256k1, fallback to browser implementation
|
||||||
// (`browser.js`) if this modules are failed to load.
|
try {
|
||||||
var secp256k1 = require("secp256k1");
|
var secp256k1 = require("secp256k1");
|
||||||
var ecdh = require("./build/Release/ecdh");
|
var ecdh = require("./build/Release/ecdh");
|
||||||
|
} catch (e) {
|
||||||
|
if (process.env.ECCRYPTO_NO_FALLBACK) {
|
||||||
|
throw e;
|
||||||
|
} else {
|
||||||
|
return (module.exports = require("./browser"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function assert(condition, message) {
|
function assert(condition, message) {
|
||||||
if (!condition) {
|
if (!condition) {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
"browser": "browser.js",
|
"browser": "browser.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"install": "node-gyp rebuild || exit 0",
|
"install": "node-gyp rebuild || exit 0",
|
||||||
"test": "mocha && xvfb-run -a karma start && jshint .",
|
"test": "ECCRYPTO_NO_FALLBACK=1 mocha && xvfb-run -a karma start && jshint .",
|
||||||
"m": "mocha",
|
"m": "mocha",
|
||||||
"k": "xvfb-run -a karma start",
|
"k": "xvfb-run -a karma start",
|
||||||
"kc": "xvfb-run -a karma start --browsers Chromium",
|
"kc": "xvfb-run -a karma start --browsers Chromium",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user