sign method
Signs the authorization entry. The signature will be set to the soroban credentials
Implementation
void sign(KeyPair signer, Network network) {
XdrSorobanCredentials xdrCredentials = credentials.toXdr();
if (credentials.addressCredentials == null ||
xdrCredentials.type !=
XdrSorobanCredentialsType.SOROBAN_CREDENTIALS_ADDRESS ||
xdrCredentials.address == null) {
throw Exception("no soroban address credentials found");
}
XdrHashIDPreimageSorobanAuthorization authPreimageXdr =
XdrHashIDPreimageSorobanAuthorization(
XdrHash(network.networkId!),
xdrCredentials.address!.nonce,
xdrCredentials.address!.signatureExpirationLedger,
rootInvocation.toXdr());
XdrHashIDPreimage rootInvocationPreimage =
XdrHashIDPreimage(XdrEnvelopeType.ENVELOPE_TYPE_SOROBAN_AUTHORIZATION);
rootInvocationPreimage.sorobanAuthorization = authPreimageXdr;
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);
credentials.addressCredentials!.signature = signature.toXdrSCVal();
}