sign method

void sign(
  1. KeyPair signer,
  2. Network network
)

Signs the transaction with the given keypair for a specific network.

Adds a signature to this transaction using the provided signer keypair. The signature is computed over the transaction hash for the specified network. Multiple signatures can be added by calling this method multiple times with different signers.

Parameters:

  • signer The KeyPair to sign with (must have the private key)
  • network The Network passphrase (e.g., Network.TESTNET or Network.PUBLIC)

Security notes:

  • Always verify you're signing for the correct network
  • Never reuse signatures across different networks
  • The transaction hash includes the network passphrase to prevent replay attacks

Example:

transaction.sign(sourceKeyPair, Network.TESTNET);
// For multi-sig, add additional signatures
transaction.sign(secondKeyPair, Network.TESTNET);

Implementation

void sign(KeyPair signer, Network network) {
  _mSignatures.add(signer.signDecorated(this.hash(network)));
}