jwtToken method
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 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,
{String homeDomain,
String clientDomain,
KeyPair clientDomainAccountKeyPair}) async {
String accountId =
checkNotNull(clientAccountId, "clientAccountId can not be null");
checkNotNull(signers, "signers can not be null");
// get the challenge transaction from the web auth server
String transaction =
await getChallenge(accountId, homeDomain, clientDomain);
String clientDomainAccountId = null;
if (clientDomainAccountKeyPair != null) {
clientDomainAccountId = clientDomainAccountKeyPair.accountId;
}
// validate the transaction received from the web auth server.
validateChallenge(
transaction, accountId, clientDomainAccountId); // throws if not valid
if (clientDomainAccountKeyPair != null) {
signers.add(clientDomainAccountKeyPair);
}
// sign the transaction received from the web auth server using the provided user/client keypair by parameter.
final signedTransaction = signTransaction(transaction, signers);
// request the jwt token by sending back the signed challenge transaction to the web auth server.
final String jwtToken =
await sendSignedChallengeTransaction(signedTransaction);
return jwtToken;
}