diff --git a/lib/bcoin/protocol/parser.js b/lib/bcoin/protocol/parser.js index f8274d54..b84c8ed6 100644 --- a/lib/bcoin/protocol/parser.js +++ b/lib/bcoin/protocol/parser.js @@ -241,7 +241,7 @@ Parser.prototype.parseTxIn = function parseTxIn(p) { hash: p.slice(0, 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) }; }; @@ -259,7 +259,7 @@ Parser.prototype.parseTxOut = function parseTxOut(p) { return { size: off + scriptLen, value: new bn(p.slice(0, 8).reverse()), - script: p.slice(off, off + scriptLen) + script: bcoin.script.decode(p.slice(off, off + scriptLen)) }; }; diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index 38cf3705..7f0de14d 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -22,12 +22,12 @@ function TX(data) { if (data.inputs) { data.inputs.forEach(function(input) { - this.input(input, null, this === data); + this.input(input, null); }, this); } if (data.outputs) { data.outputs.forEach(function(out) { - this.out(out, null, this === data); + this.out(out, null); }, this); } } @@ -46,7 +46,7 @@ TX.prototype.render = function render() { 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) i = { tx: i, index: index }; @@ -64,7 +64,7 @@ TX.prototype.input = function input(i, index, clone) { hash: hash, 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 }); @@ -79,7 +79,7 @@ TX.prototype.inputTx = function inputTx(i, 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') { output = { address: output, @@ -87,8 +87,7 @@ TX.prototype.out = function out(output, value, clone) { }; } - var script = clone ? output.script.slice() : - bcoin.script.decode(output.script); + var script = output.script ? output.script.slice() : []; // Default script if given address if (output.address) { diff --git a/lib/bcoin/wallet.js b/lib/bcoin/wallet.js index c6450792..fa81ff02 100644 --- a/lib/bcoin/wallet.js +++ b/lib/bcoin/wallet.js @@ -38,8 +38,8 @@ Wallet.prototype.getPrivateKey = function getPrivateKey(enc) { return priv; if (enc === 'base58') { - // We'll be using uncompressed public key as an address - var arr = [ 128 ].concat(priv); + // We'll be using compressed public key as an address + var arr = [ 128 ].concat(priv, 1); var chk = utils.checksum(arr); return utils.toBase58(arr.concat(chk)); } else { @@ -48,12 +48,11 @@ Wallet.prototype.getPrivateKey = function getPrivateKey(enc) { }; Wallet.prototype.getPublicKey = function getPublicKey() { - return this.key.getPublic('array'); + return this.key.getPublic(true, 'array'); }; Wallet.prototype.getHash = function getHash() { - var pub = this.key.getPublic('array'); - return utils.ripesha(pub); + return utils.ripesha(this.getPublicKey()); }; Wallet.prototype.getAddress = function getAddress() { @@ -119,7 +118,7 @@ Wallet.prototype.sign = function sign(tx, type) { var inputs = tx.inputs.filter(function(input) { return input.out.tx && this.own(input.out.tx); }, this); - var pub = this.key.getPublic('array'); + var pub = this.getPublicKey(); // Add signature script to each input inputs.forEach(function(input, i) {