add padding of leading zeros
This commit is contained in:
parent
1ae18d227f
commit
74cecb7fdf
|
@ -5,6 +5,18 @@ var bs58 = require('bs58');
|
|||
|
||||
var BitAuth = {};
|
||||
|
||||
/**
|
||||
* Will add leading zeros to hex string
|
||||
*
|
||||
* @returns {String} A hex string
|
||||
*/
|
||||
BitAuth._addPaddingToHex = function(hex){
|
||||
while( hex.length < 64 ){
|
||||
hex = '0'+hex;
|
||||
}
|
||||
return hex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Will return a key pair and identity
|
||||
*
|
||||
|
@ -17,12 +29,13 @@ BitAuth.generateSin = function() {
|
|||
|
||||
var keys = ecdsa.genKeyPair();
|
||||
|
||||
var publicKey = this.getPublicKeyFromPrivateKey(keys.getPrivate('hex'));
|
||||
var privateKey = this._addPaddingToHex(keys.getPrivate('hex'));
|
||||
var publicKey = this.getPublicKeyFromPrivateKey(privateKey);
|
||||
var sin = this.getSinFromPublicKey(publicKey);
|
||||
|
||||
var sinObj = {
|
||||
created: new Date().getTime(),
|
||||
priv: keys.getPrivate('hex'),
|
||||
priv: privateKey,
|
||||
pub: publicKey,
|
||||
sin: sin
|
||||
}
|
||||
|
@ -43,8 +56,9 @@ BitAuth.getPublicKeyFromPrivateKey = function(privkey) {
|
|||
|
||||
// compressed public key
|
||||
var pubKey = keys.getPublic();
|
||||
var xbuf = new Buffer(pubKey.x.toString('hex'), 'hex');
|
||||
var ybuf = new Buffer(pubKey.y.toString('hex'), 'hex');
|
||||
var xbuf = new Buffer(this._addPaddingToHex(pubKey.x.toString('hex')), 'hex');
|
||||
var ybuf = new Buffer(this._addPaddingToHex(pubKey.y.toString('hex')), 'hex');
|
||||
|
||||
if (ybuf[ybuf.length-1] % 2) { //odd
|
||||
var pub = Buffer.concat([new Buffer([3]), xbuf]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue