Added feature to validate a SIN

This commit is contained in:
Braydon Fuller 2014-07-16 13:46:49 -04:00
parent 73ca83b520
commit dea969d544
3 changed files with 55 additions and 0 deletions

View File

@ -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;

View File

@ -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"
}
}

View File

@ -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) {