publicKey method
The current public key, fetched (and cached) on first use and refetched
once the cached one is past its expiresAt. nowSeconds overrides the
clock for testing.
Implementation
Future<WcVerifyKey> publicKey({int? nowSeconds}) async {
final now =
nowSeconds ?? (DateTime.now().millisecondsSinceEpoch ~/ 1000);
final cached = _cachedKey;
if (cached != null &&
(cached.expiresAt == null || cached.expiresAt! > now)) {
return cached;
}
final body = await httpGet(publicKeyUrl);
final key = WcVerifyKey.fromPublicKeyJson(
(jsonDecode(body) as Map).cast<String, dynamic>());
_cachedKey = key;
return key;
}