From dea969d5441cc00fd44075e987e8faf215966762 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Wed, 16 Jul 2014 13:46:49 -0400 Subject: [PATCH] Added feature to validate a SIN --- lib/bitauth.js | 15 +++++++++++++++ package.json | 1 + test/bitauth.js | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/lib/bitauth.js b/lib/bitauth.js index 98fc875..e24e9b4 100644 --- a/lib/bitauth.js +++ b/lib/bitauth.js @@ -59,4 +59,19 @@ BitAuth.verifySignature = function(data, pubkey, signature, callback) { } }; +BitAuth.validateSin = function(sin, callback) { + var s = new SIN(sin); + + try { + s.validate() + } catch(err) { + if ( callback ) + callback(err); + return false; + } + if ( callback ) + callback(null); + return true; +}; + module.exports = BitAuth; diff --git a/package.json b/package.json index fd0df9a..feb1ab2 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "uglify-js": "~2.4.14", "browserify": "~4.1.11", "should": "~4.0.4", + "expect.js": "~0.3.1", "mocha": "~1.20.1" } } diff --git a/test/bitauth.js b/test/bitauth.js index 94b7185..384063b 100644 --- a/test/bitauth.js +++ b/test/bitauth.js @@ -1,9 +1,12 @@ var should = require('should'); +var expect = require('expect.js'); var bitauth = require('../index'); describe('bitauth', function() { var keys = null; + var sin = 'Tf1Jc1xSbqasm5QLwwSQc5umddx2h7mAMHX'; + var sinb = 'Tf1Jc1xSbqasm5QLwwSQc5umddx2h7mAMhX'; var contract = 'keyboard cat'; var secret = 'o hai, nsa. how i do teh cryptos?'; var password = 's4705hiru13z!'; @@ -59,6 +62,42 @@ describe('bitauth', function() { }); + describe('#validateSinTrue', function() { + + it('should validate the sin as true', function(done) { + var valid = bitauth.validateSin(sin); + should.equal(true, valid); + done(); + }); + + }); + + describe('#validateSinFalse', function() { + + it('should validate the sin as false', function(done) { + var valid = bitauth.validateSin(sinb); + should.equal(false, valid); + done(); + }); + + }); + + describe('#validateSinCallback', function() { + + var received; + + var valid = bitauth.validateSin(sinb, function(err){ + if ( err && typeof(err) == 'object' ) { + received = true; + } + }); + + it('should receive error callback', function() { + expect(received).to.eql(true); + }); + + }); + describe('#encrypt', function() { it('should encrypt the secret message', function(done) {