do not check for uncompressed keys for now.

This commit is contained in:
Christopher Jeffrey 2016-01-12 03:27:50 -08:00
parent abc1f2b610
commit ca03911d80

View File

@ -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;
}