@stellar/stellar-sdk
Version:
A library for working with the Stellar network, including communication with the Horizon and Soroban RPC servers.
40 lines (37 loc) • 1.18 kB
JavaScript
import { InvalidChallengeError } from './errors.js';
import { Keypair } from '../base/keypair.js';
function gatherTxSigners(transaction, signers) {
const hashedSignatureBase = transaction.hash();
const txSignatures = [...transaction.signatures];
const signersFound = /* @__PURE__ */ new Set();
for (const signer of signers) {
if (txSignatures.length === 0) {
break;
}
let keypair;
try {
keypair = Keypair.fromPublicKey(signer);
} catch (err) {
throw new InvalidChallengeError(
`Signer is not a valid address: ${err.message}`
);
}
for (let i = 0; i < txSignatures.length; i++) {
const decSig = txSignatures[i];
if (!decSig.hint().equals(keypair.signatureHint())) {
continue;
}
if (keypair.verify(hashedSignatureBase, decSig.signature())) {
signersFound.add(signer);
txSignatures.splice(i, 1);
break;
}
}
}
return Array.from(signersFound);
}
function verifyTxSignedBy(transaction, accountID) {
return gatherTxSigners(transaction, [accountID]).length !== 0;
}
export { gatherTxSigners, verifyTxSignedBy };
//# sourceMappingURL=utils.js.map