addSignature method
Adds a signature to the transaction.
Implementation
void addSignature(SolAddress address, List<int> signature,
{bool verifySignature = true}) {
if (signature.length != SolanaTransactionConstant.signatureLengthInBytes) {
throw const SolanaPluginException("Signature must be 64 bytes long");
}
final signerPubkeys =
message.accountKeys.sublist(0, message.header.numRequiredSignatures);
final signerIndex =
signerPubkeys.indexWhere((pubkey) => pubkey.address == address.address);
if (signerIndex < 0) {
throw SolanaPluginException(
"Cannot add signature, $address is not required to sign this transaction");
}
if (verifySignature &&
!address
.toPublicKey()
.verify(message: serializeMessage(), signature: signature)) {
throw const SolanaPluginException("Signature verification failed.");
}
List<List<int>> currentSigs = List.from(_signatures);
currentSigs[signerIndex] = List<int>.unmodifiable(signature);
_signatures = List<List<int>>.unmodifiable(currentSigs);
}