Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hierarchical SINs #7

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/bitauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var Key = bitcore.Key;
var SIN = bitcore.SIN;
var SINKey = bitcore.SINKey
var util = bitcore.util;
var HKey = bitcore.HierarchicalKey;

var BitAuth = {};

Expand All @@ -13,6 +14,25 @@ BitAuth.generateSin = function() {
return sk.storeObj();
};

BitAuth.genHSin = function() {
var hkey = new bitcore.HierarchicalKey();
var hsin = {
hsinpriv: hkey.extendedPrivateKeyString(),
SIN: BitAuth.getSinFromPublicKey(hkey.eckey.public.toString('hex'))
};
return hsin;
};

BitAuth.hSin = function(hsinpriv, path) {
var hkey = new bitcore.HierarchicalKey(hsinpriv);
var hkey2 = hkey.derive(path);
var hsin = {
hsinpriv: hkey2.extendedPrivateKeyString(),
SIN: BitAuth.getSinFromPublicKey(hkey2.eckey.public.toString('hex'))
};
return hsin
};

BitAuth.getPublicKeyFromPrivateKey = function(privkey) {
try {
var key = new Key();
Expand Down
39 changes: 39 additions & 0 deletions test/bitauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,45 @@ describe('bitauth', function() {

});

describe('#genHSin', function() {

it('should generate a hierarchical sin object', function() {
var hsin = bitauth.genHSin();
should.exist(hsin.hsinpriv);
hsin.hsinpriv.length.should.equal(111);
should.exist(hsin.SIN);
});

});

describe('#hSin', function() {

it('should generate m/1/3', function() {
var hsin = bitauth.genHSin();
hsin = bitauth.hSin(hsin.hsinpriv, 'm/1/3');
should.exist(hsin.hsinpriv);
hsin.hsinpriv.length.should.equal(111);
should.exist(hsin.SIN);
});

it('should generate m/0/4', function() {
var hsin = bitauth.genHSin();
hsin = bitauth.hSin(hsin.hsinpriv, 'm/0/4');
should.exist(hsin.hsinpriv);
hsin.hsinpriv.length.should.equal(111);
should.exist(hsin.SIN);
});

it('should generate m/9/3/3/2/4000', function() {
var hsin = bitauth.genHSin();
hsin = bitauth.hSin(hsin.hsinpriv, 'm/9/3/3/2/4000');
should.exist(hsin.hsinpriv);
hsin.hsinpriv.length.should.equal(111);
should.exist(hsin.SIN);
});

});

describe('#getPublicKeyFromPrivateKey', function() {

it('should properly get the public key', function(done) {
Expand Down