code: function fixMultisigOrder (input, transaction, vin) {
    if (input.redeemScriptType !== scriptTypes.MULTISIG || !input.redeemScript) return;
    if (input.pubKeys.length === input.signatures.length) return;
  
    const unmatched = input.signatures.concat();
  
    input.signatures = input.pubKeys.map(pubKey => {
      const keyPair = ECPair.fromPublicKeyBuffer(pubKey);
      let match;
  
      // check for a signature
      unmatched.some((signature, i) => {
        // skip if undefined || OP_0
        if (!signature) return false;
  
        // TODO: avoid O(n) hashForSignature
        const parsed = ECSignature.parseScriptSignature(signature);
        const hash = transaction.hashForSignature(vin, input.redeemScript, parsed.hashType);
  
        // skip if signature does not match pubKey
        if (!keyPair.verify(hash, parsed.signature)) return false;
  
        // remove matched signature from unmatched
        unmatched[i] = undefined;
        match = signature;
  
        return true;
      });
  
      return match;
    });
  }
docs: could be done in expandInput, but requires the original Transaction for hashForSignature