Use for loop instead of some to allow for future await usage

This commit is contained in:
junderw 2019-06-14 12:20:12 +09:00
parent 4bed585f6a
commit 84d5e67e38
No known key found for this signature in database
GPG key ID: B256185D3A971908
2 changed files with 10 additions and 8 deletions

View file

@ -936,8 +936,9 @@ function checkSignArgs(txb, signParams) {
}
function trySign(input, ourPubKey, keyPair, signatureHash, hashType, useLowR) {
// enforce in order signing of public keys
const signed = input.pubkeys.some((pubKey, i) => {
if (!ourPubKey.equals(pubKey)) return false;
let signed = false;
for (const [i, pubKey] of input.pubkeys.entries()) {
if (!ourPubKey.equals(pubKey)) continue;
if (input.signatures[i]) throw new Error('Signature already exists');
// TODO: add tests
if (ourPubKey.length !== 33 && input.hasWitness) {
@ -947,8 +948,8 @@ function trySign(input, ourPubKey, keyPair, signatureHash, hashType, useLowR) {
}
const signature = keyPair.sign(signatureHash, useLowR);
input.signatures[i] = bscript.signature.encode(signature, hashType);
return true;
});
signed = true;
}
if (!signed) throw new Error('Key pair cannot sign for this input');
}
function getSigningData(