@stellar/stellar-sdk
Version:
A library for working with the Stellar network, including communication with the Horizon and Soroban RPC servers.
43 lines (39 loc) • 1.24 kB
JavaScript
;
var errors = require('./errors.js');
var keypair = require('../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$1;
try {
keypair$1 = keypair.Keypair.fromPublicKey(signer);
} catch (err) {
throw new errors.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$1.signatureHint())) {
continue;
}
if (keypair$1.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;
}
exports.gatherTxSigners = gatherTxSigners;
exports.verifyTxSignedBy = verifyTxSignedBy;
//# sourceMappingURL=utils.js.map