let isMultisig handle m and n validation.
This commit is contained in:
parent
f17f3b5bee
commit
fdc72b2062
@ -1097,17 +1097,6 @@ script.isMultisig = function isMultisig(s, keys) {
|
||||
if (s[s.length - 1] !== 'checkmultisig')
|
||||
return false;
|
||||
|
||||
m = s[0];
|
||||
|
||||
if (Array.isArray(m)) {
|
||||
if (m.length !== 1)
|
||||
return false;
|
||||
m = m[0];
|
||||
}
|
||||
|
||||
if (!(m >= 1 && m <= 15))
|
||||
return false;
|
||||
|
||||
n = s[s.length - 2];
|
||||
|
||||
if (Array.isArray(n)) {
|
||||
@ -1116,7 +1105,18 @@ script.isMultisig = function isMultisig(s, keys) {
|
||||
n = n[0];
|
||||
}
|
||||
|
||||
if (!(n >= m && n <= 15))
|
||||
if (!(n >= 1 && n <= 15))
|
||||
return false;
|
||||
|
||||
m = s[0];
|
||||
|
||||
if (Array.isArray(m)) {
|
||||
if (m.length !== 1)
|
||||
return false;
|
||||
m = m[0];
|
||||
}
|
||||
|
||||
if (!(m >= 1 && m <= n))
|
||||
return false;
|
||||
|
||||
if (n + 3 !== s.length)
|
||||
|
||||
@ -198,7 +198,7 @@ TX.prototype.scriptInput = function scriptInput(index, pub, redeem) {
|
||||
// Grab `n` value (number of keys).
|
||||
n = s[s.length - 2];
|
||||
if (Array.isArray(n))
|
||||
n = n[0] || 0;
|
||||
n = n[0];
|
||||
|
||||
// Fill script with `n` signature slots.
|
||||
for (i = 0; i < n; i++)
|
||||
@ -281,15 +281,15 @@ TX.prototype.signInput = function signInput(index, key, type) {
|
||||
// Grab `m` value (number of sigs required).
|
||||
m = s[0];
|
||||
if (Array.isArray(m))
|
||||
m = m[0] || 0;
|
||||
m = m[0];
|
||||
|
||||
// Grab `n` value (number of keys).
|
||||
n = s[s.length - 2];
|
||||
if (Array.isArray(m))
|
||||
n = n[0] || 0;
|
||||
if (Array.isArray(n))
|
||||
n = n[0];
|
||||
|
||||
// Something is very wrong here. Abort.
|
||||
if (m < 1 || m > 15 || n < m || n > 15 || len - 1 > n)
|
||||
if (len - 1 > n)
|
||||
return;
|
||||
|
||||
// Count the number of current signatures.
|
||||
@ -480,11 +480,11 @@ TX.prototype.scriptOutput = function scriptOutput(index, options) {
|
||||
m = options.m || keys.length;
|
||||
n = options.n || keys.length;
|
||||
|
||||
assert(m >= 1 && m <= n);
|
||||
if (options.scripthash)
|
||||
assert(n >= 1 && n <= 15);
|
||||
else
|
||||
assert(n >= 1 && n <= 3);
|
||||
if (!(m >= 1 && m <= n))
|
||||
return;
|
||||
|
||||
if (!(n >= 1 && n <= (options.scripthash ? 15 : 3)))
|
||||
return;
|
||||
|
||||
script = bcoin.script.redeem(keys, m, n);
|
||||
} else if (bcoin.wallet.validateAddress(options.address, 'scripthash')) {
|
||||
@ -689,7 +689,7 @@ TX.prototype.maxSize = function maxSize() {
|
||||
// Get the previous m value:
|
||||
m = s[0];
|
||||
if (Array.isArray(m))
|
||||
m = m[0] || 0;
|
||||
m = m[0];
|
||||
assert(m >= 1 && m <= 3);
|
||||
// OP_0
|
||||
size += 1;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user