Transaction Signing
Transaction signing is a crucial security step that proves you have the authority to spend from an address. Trident provides multiple ways to sign transactions.
Signing Methods
1. Sign with ApiWrapper Instance
The simplest way is to use the private key bound to your ApiWrapper instance:
// The private key is already bound when creating the client
ApiWrapper client = ApiWrapper.ofNile("your_private_key");
// Sign directly with bound private key
Transaction signedTxn = client.signTransaction(transaction);
2. Sign with Specific KeyPair
You can also sign with any KeyPair:
// Create or import a KeyPair
KeyPair keyPair = new KeyPair("private_key");
// Sign with specific KeyPair
Transaction signedTxn = client.signTransaction(transaction, keyPair);
Signature Validation
Trident provides methods to validate signature correctness using transaction ID and signature message. The validation works by:
- Recovering the public key from the signed message
- Converting the public key to an address
- Comparing with the initiator's address
Verify Methods
// Verify using raw data
boolean isValid = SignatureValidator.verify(byte[] txid, byte[] signature, byte[] ownerAddress);
// Verify using String format
boolean isValid = SignatureValidator.verify(String txid, String signature, String ownerAddress);
Note
The transaction ID (txid) is obtained by calculating SHA256 of Transaction.rawData
Security Notice
- Never share or expose your private keys
- Always verify the transaction details before signing
- Keep your signing environment secure and isolated