wallet: use compressed public key

This commit is contained in:
Fedor Indutny 2014-05-05 17:39:22 +04:00
parent 62d9af1194
commit fb651d703e
3 changed files with 13 additions and 15 deletions

View File

@ -241,7 +241,7 @@ Parser.prototype.parseTxIn = function parseTxIn(p) {
hash: p.slice(0, 32), hash: p.slice(0, 32),
index: readU32(p, 32) index: readU32(p, 32)
}, },
script: p.slice(off, off + scriptLen), script: bcoin.script.decode(p.slice(off, off + scriptLen)),
seq: readU32(p, off + scriptLen) seq: readU32(p, off + scriptLen)
}; };
}; };
@ -259,7 +259,7 @@ Parser.prototype.parseTxOut = function parseTxOut(p) {
return { return {
size: off + scriptLen, size: off + scriptLen,
value: new bn(p.slice(0, 8).reverse()), value: new bn(p.slice(0, 8).reverse()),
script: p.slice(off, off + scriptLen) script: bcoin.script.decode(p.slice(off, off + scriptLen))
}; };
}; };

View File

@ -22,12 +22,12 @@ function TX(data) {
if (data.inputs) { if (data.inputs) {
data.inputs.forEach(function(input) { data.inputs.forEach(function(input) {
this.input(input, null, this === data); this.input(input, null);
}, this); }, this);
} }
if (data.outputs) { if (data.outputs) {
data.outputs.forEach(function(out) { data.outputs.forEach(function(out) {
this.out(out, null, this === data); this.out(out, null);
}, this); }, this);
} }
} }
@ -46,7 +46,7 @@ TX.prototype.render = function render() {
return bcoin.protocol.framer.tx(this); return bcoin.protocol.framer.tx(this);
}; };
TX.prototype.input = function input(i, index, clone) { TX.prototype.input = function input(i, index) {
if (i instanceof TX) if (i instanceof TX)
i = { tx: i, index: index }; i = { tx: i, index: index };
@ -64,7 +64,7 @@ TX.prototype.input = function input(i, index, clone) {
hash: hash, hash: hash,
index: i.out ? i.out.index : i.index, index: i.out ? i.out.index : i.index,
}, },
script: clone ? i.script.slice() : bcoin.script.decode(i.script), script: i.script ? i.script.slice() : [],
seq: i.seq === undefined ? 0xffffffff : i.seq seq: i.seq === undefined ? 0xffffffff : i.seq
}); });
@ -79,7 +79,7 @@ TX.prototype.inputTx = function inputTx(i, tx) {
this.inputs[i].out.tx = tx; this.inputs[i].out.tx = tx;
}; };
TX.prototype.out = function out(output, value, clone) { TX.prototype.out = function out(output, value) {
if (typeof output === 'string') { if (typeof output === 'string') {
output = { output = {
address: output, address: output,
@ -87,8 +87,7 @@ TX.prototype.out = function out(output, value, clone) {
}; };
} }
var script = clone ? output.script.slice() : var script = output.script ? output.script.slice() : [];
bcoin.script.decode(output.script);
// Default script if given address // Default script if given address
if (output.address) { if (output.address) {

View File

@ -38,8 +38,8 @@ Wallet.prototype.getPrivateKey = function getPrivateKey(enc) {
return priv; return priv;
if (enc === 'base58') { if (enc === 'base58') {
// We'll be using uncompressed public key as an address // We'll be using compressed public key as an address
var arr = [ 128 ].concat(priv); var arr = [ 128 ].concat(priv, 1);
var chk = utils.checksum(arr); var chk = utils.checksum(arr);
return utils.toBase58(arr.concat(chk)); return utils.toBase58(arr.concat(chk));
} else { } else {
@ -48,12 +48,11 @@ Wallet.prototype.getPrivateKey = function getPrivateKey(enc) {
}; };
Wallet.prototype.getPublicKey = function getPublicKey() { Wallet.prototype.getPublicKey = function getPublicKey() {
return this.key.getPublic('array'); return this.key.getPublic(true, 'array');
}; };
Wallet.prototype.getHash = function getHash() { Wallet.prototype.getHash = function getHash() {
var pub = this.key.getPublic('array'); return utils.ripesha(this.getPublicKey());
return utils.ripesha(pub);
}; };
Wallet.prototype.getAddress = function getAddress() { Wallet.prototype.getAddress = function getAddress() {
@ -119,7 +118,7 @@ Wallet.prototype.sign = function sign(tx, type) {
var inputs = tx.inputs.filter(function(input) { var inputs = tx.inputs.filter(function(input) {
return input.out.tx && this.own(input.out.tx); return input.out.tx && this.own(input.out.tx);
}, this); }, this);
var pub = this.key.getPublic('array'); var pub = this.getPublicKey();
// Add signature script to each input // Add signature script to each input
inputs.forEach(function(input, i) { inputs.forEach(function(input, i) {