jwtToken method
Get JWT token for wallet.
- Parameter userKeyPair: The keypair of the wallet to get the JWT token for. It must contain the secret seed for signing the challenge
- Parameter homeDomain: optional, used for requesting the challenge depending on the home domain if needed. The web auth server may serve multiple home domains.
Implementation
Future<String> jwtToken(KeyPair userKeyPair, [String homeDomain]) async {
KeyPair kp = checkNotNull(userKeyPair, "keyPair can not be null");
// get the challenge transaction from the web auth server
String transaction = await getChallenge(kp.accountId, homeDomain);
// validate the transaction received from the web auth server.
validateChallenge(transaction, kp.accountId); // throws if not valid
// sign the transaction received from the web auth server using the provided user/client keypair by parameter.
final signedTransaction = signTransaction(transaction, kp);
// request the jwt token by sending back the signed challenge transaction to the web auth server.
final String jwtToken = await sendSignedChallengeTransaction(signedTransaction);
return jwtToken;
}