signJWT method

  1. @override
Future<String> signJWT({
  1. required String sub,
  2. required String aud,
  3. required int ttl,
  4. required RelayAuthKeyPair keyPair,
  5. int? iat,
})
override

Implementation

@override
Future<String> signJWT({
  required String sub,
  required String aud,
  required int ttl,
  required RelayAuthKeyPair keyPair,
  int? iat,
}) async {
  iat ??= DateTime.now().millisecondsSinceEpoch ~/ 1000 - 60;
  final JWTHeader header = JWTHeader();
  final String iss = encodeIss(keyPair.publicKeyBytes);
  final int exp = iat + ttl;
  final JWTPayload payload = JWTPayload(
    iss,
    sub,
    aud,
    iat,
    exp,
  );
  final Uint8List data = encodeData(
    JWTData(
      header,
      payload,
    ),
  );
  Uint8List signature = ed.sign(
    ed.PrivateKey(keyPair.privateKeyBytes),
    data,
  );
  // List<int> signature = keyPair.sign(data);
  return encodeJWT(JWTSigned(signature, payload));
}