fixed an issue with verifying a signature with a public key with leading zeros
This commit is contained in:
parent
a4309b8f3b
commit
e6bcf12934
|
@ -44,8 +44,8 @@ BitAuth.getPublicKeyFromPrivateKey = function(privkey) {
|
|||
|
||||
// compressed public key
|
||||
var pubKey = keys.getPublic();
|
||||
var xbuf = new Buffer(pubKey.x.toString('hex', 2), 'hex');
|
||||
var ybuf = new Buffer(pubKey.y.toString('hex', 2), 'hex');
|
||||
var xbuf = new Buffer(pubKey.x.toString('hex', 64), 'hex');
|
||||
var ybuf = new Buffer(pubKey.y.toString('hex', 64), 'hex');
|
||||
|
||||
if (ybuf[ybuf.length-1] % 2) { //odd
|
||||
var pub = Buffer.concat([new Buffer([3]), xbuf]);
|
||||
|
|
|
@ -19,6 +19,9 @@ describe('bitauth', function() {
|
|||
sin: 'Tf3yr5tYvccKNVrE26BrPs6LWZRh8woHwjR'
|
||||
}
|
||||
|
||||
// a private key that will produce a public key with a leading zero
|
||||
var privateKeyToZero = 'c6b7f6bfe5bb19b1e390e55ed4ba5df8af6068d0eb89379a33f9c19aacf6c08c';
|
||||
|
||||
// keys generated
|
||||
var keys = null;
|
||||
|
||||
|
@ -99,6 +102,24 @@ describe('bitauth', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should verify the signature with leading zero public key', function(done) {
|
||||
|
||||
var leadingZeroKeys = {
|
||||
priv: privateKeyToZero,
|
||||
pub: bitauth.getPublicKeyFromPrivateKey(privateKeyToZero)
|
||||
};
|
||||
|
||||
signature = bitauth.sign(contract, leadingZeroKeys.priv);
|
||||
bitauth.verifySignature(contract, leadingZeroKeys.pub, signature, function(err, valid){
|
||||
should.not.exist(err);
|
||||
should.exist(valid);
|
||||
valid.should.equal(true);
|
||||
});
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#validateSinTrue', function() {
|
||||
|
|
Loading…
Reference in New Issue