Added feature to validate a SIN
This commit is contained in:
parent
73ca83b520
commit
dea969d544
|
@ -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;
|
module.exports = BitAuth;
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
"uglify-js": "~2.4.14",
|
"uglify-js": "~2.4.14",
|
||||||
"browserify": "~4.1.11",
|
"browserify": "~4.1.11",
|
||||||
"should": "~4.0.4",
|
"should": "~4.0.4",
|
||||||
|
"expect.js": "~0.3.1",
|
||||||
"mocha": "~1.20.1"
|
"mocha": "~1.20.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
var should = require('should');
|
var should = require('should');
|
||||||
|
var expect = require('expect.js');
|
||||||
var bitauth = require('../index');
|
var bitauth = require('../index');
|
||||||
|
|
||||||
describe('bitauth', function() {
|
describe('bitauth', function() {
|
||||||
|
|
||||||
var keys = null;
|
var keys = null;
|
||||||
|
var sin = 'Tf1Jc1xSbqasm5QLwwSQc5umddx2h7mAMHX';
|
||||||
|
var sinb = 'Tf1Jc1xSbqasm5QLwwSQc5umddx2h7mAMhX';
|
||||||
var contract = 'keyboard cat';
|
var contract = 'keyboard cat';
|
||||||
var secret = 'o hai, nsa. how i do teh cryptos?';
|
var secret = 'o hai, nsa. how i do teh cryptos?';
|
||||||
var password = 's4705hiru13z!';
|
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() {
|
describe('#encrypt', function() {
|
||||||
|
|
||||||
it('should encrypt the secret message', function(done) {
|
it('should encrypt the secret message', function(done) {
|
||||||
|
|
Loading…
Reference in New Issue