Do not overwrite global variables

Also do not use Promise shim in browsers since it's supported natively
by new browsers (and we can use only new browsers because of the
WebCryptoAPI).
This commit is contained in:
Kagami Hiiragi 2015-01-06 14:21:46 +03:00
parent eabb541b95
commit f10072c932
2 changed files with 5 additions and 4 deletions

View File

@ -4,7 +4,6 @@
"use strict"; "use strict";
require("es6-promise").polyfill();
var EC = require("elliptic").ec; var EC = require("elliptic").ec;
var ec = new EC("secp256k1"); var ec = new EC("secp256k1");

View File

@ -5,7 +5,9 @@
"use strict"; "use strict";
require("es6-promise").polyfill(); var promise = typeof Promise === "undefined" ?
require("es6-promise").Promise :
Promise;
var secp256k1 = require("secp256k1"); var secp256k1 = require("secp256k1");
/** /**
@ -25,7 +27,7 @@ var getPublic = exports.getPublic = secp256k1.createPublicKey;
*/ */
// FIXME(Kagami): What to do in case of invalid nonce? // FIXME(Kagami): What to do in case of invalid nonce?
exports.sign = function(privateKey, msg) { exports.sign = function(privateKey, msg) {
return new Promise(function(resolve, reject) { return new promise(function(resolve, reject) {
try { try {
secp256k1.sign(privateKey, msg, function(code, sig) { secp256k1.sign(privateKey, msg, function(code, sig) {
if (code === 1) { if (code === 1) {
@ -50,7 +52,7 @@ exports.sign = function(privateKey, msg) {
*/ */
exports.verify = function(key, msg, sig) { exports.verify = function(key, msg, sig) {
var publicKey = key.length === 32 ? getPublic(key) : key; var publicKey = key.length === 32 ? getPublic(key) : key;
return new Promise(function(resolve, reject) { return new promise(function(resolve, reject) {
secp256k1.verify(publicKey, msg, sig, function(code) { secp256k1.verify(publicKey, msg, sig, function(code) {
if (code === 1) { if (code === 1) {
resolve(); resolve();