jwtToken method Null safety

Future<String> jwtToken(
  1. String clientAccountId,
  2. List<KeyPair> signers,
  3. {int? memo,
  4. String? homeDomain,
  5. String? clientDomain,
  6. KeyPair? clientDomainAccountKeyPair}
)

Get JWT token for wallet.

  • Parameter clientAccountId: The account id of the client/user to get the JWT token for.
  • Parameter signers: list of signers (keypairs including secret seed) of the client account
  • Parameter memo: optional, ID memo of the client account if muxed and accountId starts with G
  • Parameter homeDomain: optional, used for requesting the challenge depending on the home domain if needed. The web auth server may serve multiple home domains.
  • Parameter clientDomain: optional, domain of the client hosting it's stellar.toml
  • Parameter clientDomainAccountKeyPair: optional, KeyPair of the client domain account including the seed (mandatory and used for signing the transaction if client domain is provided)

Implementation

Future<String> jwtToken(String clientAccountId, List<KeyPair> signers,
    {int? memo,
    String? homeDomain,
    String? clientDomain,
    KeyPair? clientDomainAccountKeyPair}) async {

  // get the challenge transaction from the web auth server
  String transaction =
      await getChallenge(clientAccountId, memo, homeDomain, clientDomain);

  String? clientDomainAccountId;
  if (clientDomainAccountKeyPair != null) {
    clientDomainAccountId = clientDomainAccountKeyPair.accountId;
  }
  // validate the transaction received from the web auth server.
  validateChallenge(transaction, clientAccountId, clientDomainAccountId,
      gracePeriod, memo); // throws if not valid

  List<KeyPair> mSigners = List.from(signers, growable: true);
  if (clientDomainAccountKeyPair != null) {
    mSigners.add(clientDomainAccountKeyPair);
  }
  // sign the transaction received from the web auth server using the provided user/client keypair by parameter.
  final signedTransaction = signTransaction(transaction, mSigners);

  // request the jwt token by sending back the signed challenge transaction to the web auth server.
  final String jwtToken =
      await sendSignedChallengeTransaction(signedTransaction);

  return jwtToken;
}