signTransaction method

Future<SEP30SignatureResponse> signTransaction(
  1. String address,
  2. String signingAddress,
  3. String transaction,
  4. String jwt,
)

Signs a transaction using a recovery signer.

Requests the recovery service to sign a transaction with one of the account's registered signing addresses. Used during account recovery to authorize recovery transactions.

The signing address must correspond to one of the signers returned when registering or querying the account.

Parameters:

  • address Stellar account address
  • signingAddress Signing address from account's registered signers
  • transaction Base64-encoded transaction XDR to sign
  • jwt Authentication token from SEP-10

Returns signature response with transaction signature and network passphrase.

Throws:

See: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0030.md#post-accountsaddresssignsigning-address

Implementation

Future<SEP30SignatureResponse> signTransaction(String address,
    String signingAddress, String transaction, String jwt) async {
  Uri requestURI = Util.appendEndpointToUrl(
      _serviceAddress, 'accounts/$address/sign/$signingAddress');
  Map<String, String> headers = {...(this.httpRequestHeaders ?? {})};
  headers["Authorization"] = "Bearer " + jwt;
  headers.putIfAbsent("Content-Type", () => "application/json");

  SEP30SignatureResponse result = await httpClient
      .post(requestURI,
          body: json.encode({"transaction": transaction}), headers: headers)
      .then((response) {
    switch (response.statusCode) {
      case 200:
        return SEP30SignatureResponse.fromJson(json.decode(response.body));
      case 400:
        throw SEP30BadRequestResponseException(
            errorFromResponseBody(response.body));
      case 401:
        throw SEP30UnauthorizedResponseException(
            errorFromResponseBody(response.body));
      case 404:
        throw SEP30NotFoundResponseException(
            errorFromResponseBody(response.body));
      case 409:
        throw SEP30ConflictResponseException(
            errorFromResponseBody(response.body));
      default:
        throw new SEP30UnknownResponseException(
            response.statusCode, response.body);
    }
  }).catchError((onError) {
    throw onError;
  });

  return result;
}