From ca03911d80b93e6e006f26f677835d927ac08896 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 12 Jan 2016 03:27:50 -0800 Subject: [PATCH] do not check for uncompressed keys for now. --- lib/bcoin/tx.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index 2b852032..387aff58 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -215,7 +215,7 @@ TX.prototype.scriptInput = function scriptInput(index, pub, redeem) { // Sign the now-built scriptSigs TX.prototype.signInput = function signInput(index, key, type) { var input, s, hash, signature; - var len, redeem, m, n, keys, pub, pubn, pkh, pkhn, ki, signatures, i; + var len, redeem, m, n, keys, pub, pkh, ki, signatures, i; if (typeof index !== 'number') index = this.inputs.indexOf(index); @@ -254,11 +254,9 @@ TX.prototype.signInput = function signInput(index, key, type) { // Add the sighash as a single byte to the signature signature = signature.concat(type); - // Get compressed and uncompressed pubkeys. + // Get pubkey and pubkey hash. pub = key.getPublic(true, 'array'); - pubn = key.getPublic(false, 'array'); pkh = bcoin.wallet.key2hash(pub); - pkhn = bcoin.wallet.key2hash(pubn); // Script length, needed for multisig len = input.script.length; @@ -273,14 +271,17 @@ TX.prototype.signInput = function signInput(index, key, type) { // Add signatures. if (bcoin.script.isPubkey(s)) { // P2PK + + // Something is wrong. Abort. if (!Array.isArray(input.script[0])) return false; + // Already signed. if (input.script[0].length) return true; // Make sure the pubkey is ours. - if (!utils.isEqual(s[0], pub) && !utils.isEqual(s[0], pubn)) + if (!utils.isEqual(pub, s[0])) return false; input.script[0] = signature; @@ -288,17 +289,21 @@ TX.prototype.signInput = function signInput(index, key, type) { return true; } else if (bcoin.script.isPubkeyhash(s)) { // P2PKH + + // Something is wrong. Abort. if (!Array.isArray(input.script[0])) return false; + // Already signed. if (input.script[0].length) return true; // Make sure the pubkey hash is ours. - if (!utils.isEqual(s[2], pkh) && !utils.isEqual(s[2], pkhn)) + if (!utils.isEqual(pkh, s[2])) return false; input.script[0] = signature; + return true; } else if (bcoin.script.isMultisig(s)) { // Multisig @@ -344,7 +349,7 @@ TX.prototype.signInput = function signInput(index, key, type) { // Find the key index so we can place // the signature in the same index. for (ki = 0; ki < keys.length; ki++) { - if (utils.isEqual(pub, keys[ki]) || utils.isEqual(pubn, keys[ki])) + if (utils.isEqual(pub, keys[ki])) break; }