diff --git a/package.json b/package.json index 45bb6ad..9609408 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ ], "scripts": { "make-dist": "sh scripts/make-dist.sh", + "test": "node_modules/.bin/mocha test/* --reporter spec", "postinstall": "npm run make-dist" }, "main": "index.js", @@ -26,6 +27,8 @@ }, "devDependencies": { "uglify-js": "~2.4.14", - "browserify": "~4.1.11" + "browserify": "~4.1.11", + "should": "~4.0.4", + "mocha": "~1.20.1" } } diff --git a/test/bitauth.js b/test/bitauth.js new file mode 100644 index 0000000..e2d2b12 --- /dev/null +++ b/test/bitauth.js @@ -0,0 +1,82 @@ +var should = require('should'); +var bitauth = require('../index'); + +describe('bitauth', function() { + + var keys = null; + var contract = 'keyboard cat'; + var secret = 'o hai, nsa. how i do teh cryptos?'; + var password = 's4705hiru13z!'; + var signature = null; + var enc = null; + + describe('#generateSin', function() { + + it('should generate a sin object', function(done) { + keys = bitauth.generateSin(); + should.exist(keys); + should.exist(keys.pub); + should.exist(keys.priv); + should.exist(keys.sin); + done(); + }); + + }); + + describe('#getPublicKeyFromPrivateKey', function() { + + it('should properly get the public key', function(done) { + bitauth.getPublicKeyFromPrivateKey(keys.priv).should.equal(keys.pub); + done(); + }); + + }); + + describe('#getSinFromPublicKey', function() { + + it('should properly get the sin', function(done) { + bitauth.getSinFromPublicKey(keys.pub).should.equal(keys.sin); + done(); + }); + + }); + + describe('#sign', function() { + + it('should sign the string', function(done) { + signature = bitauth.sign(contract, keys.priv); + should.exist(signature); + done(); + }); + + }); + + describe('#verifySignature', function() { + + it('should verify the signature', function(done) { + bitauth.verifySignature(contract, keys.pub, signature, done); + }); + + }); + + describe('#encrypt', function() { + + it('should encrypt the secret message', function(done) { + enc = bitauth.encrypt(password, secret); + should.exist(enc); + done(); + }); + + }); + + describe('#decrypt', function() { + + it('should decrypt the secret message', function(done) { + var dec = bitauth.decrypt(password, enc); + should.exist(dec); + done(); + }); + + }); + +});