sign method Null safety
Sign the contract authorization, the signature will be added to the signatureArgs
For custom accounts, this signature format may not be applicable.
See Soroban Documentation - Stellar Account Signatures soroban.stellar.org/docs/how-to-guides/invoking-contracts-with-transactions#stellar-account-signatures
Implementation
void sign(KeyPair signer, Network network) {
if (address == null || nonce == null) {
throw Exception("address and nonce must be set.");
}
XdrHashIDPreimageContractAuth contractAuthPreimageXdr =
XdrHashIDPreimageContractAuth(XdrHash(network.networkId!),
XdrUint64(nonce!), rootInvocation.toXdr());
XdrHashIDPreimage rootInvocationPreimage =
XdrHashIDPreimage(XdrEnvelopeType.ENVELOPE_TYPE_CONTRACT_AUTH);
rootInvocationPreimage.contractAuth = contractAuthPreimageXdr;
XdrDataOutputStream xdrOutputStream = XdrDataOutputStream();
XdrHashIDPreimage.encode(xdrOutputStream, rootInvocationPreimage);
Uint8List payload = Util.hash(Uint8List.fromList(xdrOutputStream.bytes));
Uint8List signatureBytes = signer.sign(payload);
AccountEd25519Signature signature =
AccountEd25519Signature(signer.xdrPublicKey, signatureBytes);
signatureArgs.add(signature.toXdrSCVal());
}