signInput should test against keys.
This commit is contained in:
parent
645a3a59b2
commit
abc1f2b610
@ -215,7 +215,7 @@ TX.prototype.scriptInput = function scriptInput(index, pub, redeem) {
|
|||||||
// Sign the now-built scriptSigs
|
// Sign the now-built scriptSigs
|
||||||
TX.prototype.signInput = function signInput(index, key, type) {
|
TX.prototype.signInput = function signInput(index, key, type) {
|
||||||
var input, s, hash, signature;
|
var input, s, hash, signature;
|
||||||
var len, redeem, m, n, keys, pub, pubn, ki, signatures, i;
|
var len, redeem, m, n, keys, pub, pubn, pkh, pkhn, ki, signatures, i;
|
||||||
|
|
||||||
if (typeof index !== 'number')
|
if (typeof index !== 'number')
|
||||||
index = this.inputs.indexOf(index);
|
index = this.inputs.indexOf(index);
|
||||||
@ -254,6 +254,12 @@ TX.prototype.signInput = function signInput(index, key, type) {
|
|||||||
// Add the sighash as a single byte to the signature
|
// Add the sighash as a single byte to the signature
|
||||||
signature = signature.concat(type);
|
signature = signature.concat(type);
|
||||||
|
|
||||||
|
// Get compressed and uncompressed pubkeys.
|
||||||
|
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
|
// Script length, needed for multisig
|
||||||
len = input.script.length;
|
len = input.script.length;
|
||||||
|
|
||||||
@ -267,13 +273,32 @@ TX.prototype.signInput = function signInput(index, key, type) {
|
|||||||
// Add signatures.
|
// Add signatures.
|
||||||
if (bcoin.script.isPubkey(s)) {
|
if (bcoin.script.isPubkey(s)) {
|
||||||
// P2PK
|
// P2PK
|
||||||
if (Array.isArray(input.script[0]) && !input.script[0].length)
|
if (!Array.isArray(input.script[0]))
|
||||||
input.script[0] = signature;
|
return false;
|
||||||
|
|
||||||
|
if (input.script[0].length)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Make sure the pubkey is ours.
|
||||||
|
if (!utils.isEqual(s[0], pub) && !utils.isEqual(s[0], pubn))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
input.script[0] = signature;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if (bcoin.script.isPubkeyhash(s)) {
|
} else if (bcoin.script.isPubkeyhash(s)) {
|
||||||
// P2PKH
|
// P2PKH
|
||||||
if (Array.isArray(input.script[0]) && !input.script[0].length)
|
if (!Array.isArray(input.script[0]))
|
||||||
input.script[0] = signature;
|
return false;
|
||||||
|
|
||||||
|
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))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
input.script[0] = signature;
|
||||||
return true;
|
return true;
|
||||||
} else if (bcoin.script.isMultisig(s)) {
|
} else if (bcoin.script.isMultisig(s)) {
|
||||||
// Multisig
|
// Multisig
|
||||||
@ -315,8 +340,6 @@ TX.prototype.signInput = function signInput(index, key, type) {
|
|||||||
// Grab the redeem script's keys to figure
|
// Grab the redeem script's keys to figure
|
||||||
// out where our key should go.
|
// out where our key should go.
|
||||||
keys = s.slice(1, -2);
|
keys = s.slice(1, -2);
|
||||||
pub = key.getPublic(true, 'array');
|
|
||||||
pubn = key.getPublic(false, 'array');
|
|
||||||
|
|
||||||
// Find the key index so we can place
|
// Find the key index so we can place
|
||||||
// the signature in the same index.
|
// the signature in the same index.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user