add tests
This commit is contained in:
parent
75b77019c4
commit
ca3e3dd3f3
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue