diff --git a/js/models/Wallet.js b/js/models/Wallet.js index be28d3808..95ff9e6f7 100644 --- a/js/models/Wallet.js +++ b/js/models/Wallet.js @@ -5,6 +5,7 @@ var preconditions = require('preconditions').singleton(); var inherits = require('inherits'); var events = require('events'); var async = require('async'); +var request = require('request'); var bitcore = require('bitcore'); var BIP21 = bitcore.BIP21; diff --git a/js/util/HTTP.js b/js/util/HTTP.js index 00daa6d93..e900c5334 100644 --- a/js/util/HTTP.js +++ b/js/util/HTTP.js @@ -1,3 +1,5 @@ +var preconditions = require('preconditions').singleton(); + module.exports = { request: function(options, callback) { preconditions.checkArgument(_.isObject(options)); @@ -25,9 +27,9 @@ module.exports = { var req = options; req.headers = req.headers || {}; - req.body = req.body || req.data || {}; + req.body = req.body || req.data || ''; - var xhr = new XMLHttpRequest(); + var xhr = options.xhr || new XMLHttpRequest(); xhr.open(method, url, true); Object.keys(req.headers).forEach(function(key) { @@ -51,6 +53,7 @@ module.exports = { headers[$1.toLowerCase()] = $2; } ); + return ret._success(buf, xhr.status, headers, options); }; diff --git a/package.json b/package.json index e556cb370..108961d7e 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ }, "scripts": { "start": "node server.js", - "coverage": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --reporter spec test", + "coverage": "./node_modules/.bin/istanbul cover -x lib/sjcl.js ./node_modules/.bin/_mocha -- --reporter spec test", "test": "sh test/run.sh", "dist": "node shell/scripts/dist.js", "shell": "node shell/scripts/launch.js", diff --git a/test/util.crypto.js b/test/util.crypto.js index 765e537ba..c6171e1ea 100644 --- a/test/util.crypto.js +++ b/test/util.crypto.js @@ -14,6 +14,19 @@ describe('crypto utils', function() { decrypted.should.equal(message); }); + + it('should decrypt what it encrypts (JSON)', function() { + + var key = 'My secret key'; + var message = {'hola': 'picho'}; + var encrypted = cryptoUtils.encrypt(key, message); + var decrypted = cryptoUtils.decrypt(key, encrypted); + + JSON.parse(decrypted).should.deep.equal(message); + }); + + + it('should return null if the provided key cant decrypt', function() { var key = 'My secret key'; var message = 'My secret message'; @@ -22,6 +35,17 @@ describe('crypto utils', function() { assert(decrypted === null); }); + + + + it('should sign a message', function() { + var key = 'My secret key'; + var message = 'My secret message'; + var signature = cryptoUtils.hmac(key, message); + signature.should.be.equal('6tpegxYl/Eig9k1Lla8b8G8OcdtOxyNbDsdyic1Yzh4='); + }); + + var tests = [ { @@ -55,6 +79,11 @@ describe('crypto utils', function() { phrase.should.equal(expected); }); }); + it('should generate a passphrase using default salt/iter', function() { + var phrase = cryptoUtils.kdf('Pwd123!@#$%^&*(){}[]\|/?.>,<=+-_`~åéþ䲤þçæ¶'); + var expected = 'ml+mMtjgcvL2pdfDwQqW2qONRNjZ3YD8KnGeV3aFjyOoM0ByOmoREw9zBvowC/ZXsfrezbRXX/W/XIzKOqdrXA=='; + phrase.should.equal(expected); + }); });