improve script.isMultisig.
This commit is contained in:
parent
d316b1c640
commit
f420b41907
@ -1082,8 +1082,9 @@ script.isPubkeyhash = function isPubkeyhash(s, hash) {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
script.isMultisig = function isMultisig(s, pubs) {
|
script.isMultisig = function isMultisig(s, keys) {
|
||||||
var m, n, keys, total;
|
var m, n, i, j;
|
||||||
|
var total = 0;
|
||||||
|
|
||||||
s = script.subscript(s);
|
s = script.subscript(s);
|
||||||
|
|
||||||
@ -1093,43 +1094,52 @@ script.isMultisig = function isMultisig(s, pubs) {
|
|||||||
if (s.length < 4)
|
if (s.length < 4)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// compat
|
|
||||||
if (pubs && !utils.isBuffer(pubs[0]))
|
|
||||||
pubs = [pubs];
|
|
||||||
|
|
||||||
m = s[0];
|
|
||||||
if (typeof m === 'number' && m >= 1 && m <= 15)
|
|
||||||
m = [m];
|
|
||||||
if (!Array.isArray(m) || m.length !== 1)
|
|
||||||
return false;
|
|
||||||
m = m[0] || 0;
|
|
||||||
|
|
||||||
if (s[s.length - 1] !== 'checkmultisig')
|
if (s[s.length - 1] !== 'checkmultisig')
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
n = s[s.length - 2];
|
m = s[0];
|
||||||
if (typeof n === 'number' && n >= 1 && n <= 15)
|
|
||||||
n = [n];
|
if (Array.isArray(m)) {
|
||||||
if (!Array.isArray(n) || n.length !== 1)
|
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)) {
|
||||||
|
if (n.length !== 1)
|
||||||
|
return false;
|
||||||
|
n = n[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(n >= m && n <= 15))
|
||||||
return false;
|
return false;
|
||||||
n = n[0] || 0;
|
|
||||||
|
|
||||||
if (n + 3 !== s.length)
|
if (n + 3 !== s.length)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
keys = s.slice(1, 1 + n);
|
for (i = 1; i < n + 1; i++) {
|
||||||
|
if (!Array.isArray(s[i]))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!keys.every(Array.isArray))
|
if (!keys)
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!pubs)
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
total = keys.filter(function(k) {
|
keys = utils.sortKeys(keys);
|
||||||
return pubs.some(function(pub) {
|
|
||||||
return utils.isEqual(k, pub);
|
for (i = 1; i < n + 1; i++) {
|
||||||
});
|
for (j = 0; j < keys.length; j++) {
|
||||||
}).length;
|
if (utils.isEqual(s[i], keys[j])) {
|
||||||
|
total++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return total === n;
|
return total === n;
|
||||||
};
|
};
|
||||||
@ -1199,8 +1209,11 @@ script.isPubkeyInput = function isPubkeyInput(s, key, tx, i) {
|
|||||||
// Execute the script against our key's
|
// Execute the script against our key's
|
||||||
// checksig script to see if this is our input.
|
// checksig script to see if this is our input.
|
||||||
// This will only work if the script verifies.
|
// This will only work if the script verifies.
|
||||||
if (key)
|
if (key) {
|
||||||
|
assert(tx);
|
||||||
|
assert(i != null);
|
||||||
return script.verify(s, [key, 'checksig'], tx, i);
|
return script.verify(s, [key, 'checksig'], tx, i);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
@ -1247,7 +1260,10 @@ script.isMultisigInput = function isMultisigInput(s, keys, tx, i) {
|
|||||||
// Execute the script against our pubkeys'
|
// Execute the script against our pubkeys'
|
||||||
// redeem script to see if this is our input.
|
// redeem script to see if this is our input.
|
||||||
// This will only work if the script verifies.
|
// This will only work if the script verifies.
|
||||||
if (keys && keys.length >= 2) {
|
if (keys) {
|
||||||
|
assert(keys.length >= 2);
|
||||||
|
assert(tx);
|
||||||
|
assert(i != null);
|
||||||
o = script.redeem(keys, s.length - 1, keys.length);
|
o = script.redeem(keys, s.length - 1, keys.length);
|
||||||
return script.verify(s, o, tx, i);
|
return script.verify(s, o, tx, i);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -754,7 +754,7 @@ utils.hidden = function hidden(obj, prop, value) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
utils.sortKeys = function sortKeys(keys) {
|
utils.sortKeys = function sortKeys(keys) {
|
||||||
return keys.sort(function(a, b) {
|
return keys.slice().sort(function(a, b) {
|
||||||
return new bn(a).cmp(new bn(b)) > 0;
|
return new bn(a).cmp(new bn(b)) > 0;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user