Use for loop instead of some to allow for future await usage
This commit is contained in:
parent
4bed585f6a
commit
84d5e67e38
2 changed files with 10 additions and 8 deletions
|
@ -936,8 +936,9 @@ function checkSignArgs(txb, signParams) {
|
||||||
}
|
}
|
||||||
function trySign(input, ourPubKey, keyPair, signatureHash, hashType, useLowR) {
|
function trySign(input, ourPubKey, keyPair, signatureHash, hashType, useLowR) {
|
||||||
// enforce in order signing of public keys
|
// enforce in order signing of public keys
|
||||||
const signed = input.pubkeys.some((pubKey, i) => {
|
let signed = false;
|
||||||
if (!ourPubKey.equals(pubKey)) return false;
|
for (const [i, pubKey] of input.pubkeys.entries()) {
|
||||||
|
if (!ourPubKey.equals(pubKey)) continue;
|
||||||
if (input.signatures[i]) throw new Error('Signature already exists');
|
if (input.signatures[i]) throw new Error('Signature already exists');
|
||||||
// TODO: add tests
|
// TODO: add tests
|
||||||
if (ourPubKey.length !== 33 && input.hasWitness) {
|
if (ourPubKey.length !== 33 && input.hasWitness) {
|
||||||
|
@ -947,8 +948,8 @@ function trySign(input, ourPubKey, keyPair, signatureHash, hashType, useLowR) {
|
||||||
}
|
}
|
||||||
const signature = keyPair.sign(signatureHash, useLowR);
|
const signature = keyPair.sign(signatureHash, useLowR);
|
||||||
input.signatures[i] = bscript.signature.encode(signature, hashType);
|
input.signatures[i] = bscript.signature.encode(signature, hashType);
|
||||||
return true;
|
signed = true;
|
||||||
});
|
}
|
||||||
if (!signed) throw new Error('Key pair cannot sign for this input');
|
if (!signed) throw new Error('Key pair cannot sign for this input');
|
||||||
}
|
}
|
||||||
function getSigningData(
|
function getSigningData(
|
||||||
|
|
|
@ -1170,8 +1170,9 @@ function trySign(
|
||||||
useLowR: boolean,
|
useLowR: boolean,
|
||||||
): void {
|
): void {
|
||||||
// enforce in order signing of public keys
|
// enforce in order signing of public keys
|
||||||
const signed = input.pubkeys!.some((pubKey, i) => {
|
let signed = false;
|
||||||
if (!ourPubKey.equals(pubKey!)) return false;
|
for (const [i, pubKey] of input.pubkeys!.entries()) {
|
||||||
|
if (!ourPubKey.equals(pubKey!)) continue;
|
||||||
if (input.signatures![i]) throw new Error('Signature already exists');
|
if (input.signatures![i]) throw new Error('Signature already exists');
|
||||||
|
|
||||||
// TODO: add tests
|
// TODO: add tests
|
||||||
|
@ -1183,8 +1184,8 @@ function trySign(
|
||||||
|
|
||||||
const signature = keyPair.sign(signatureHash, useLowR);
|
const signature = keyPair.sign(signatureHash, useLowR);
|
||||||
input.signatures![i] = bscript.signature.encode(signature, hashType);
|
input.signatures![i] = bscript.signature.encode(signature, hashType);
|
||||||
return true;
|
signed = true;
|
||||||
});
|
}
|
||||||
|
|
||||||
if (!signed) throw new Error('Key pair cannot sign for this input');
|
if (!signed) throw new Error('Key pair cannot sign for this input');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue