buildAuthenticator method

  1. @override
BaseAuthenticator buildAuthenticator(
  1. Map<String, dynamic> opts
)
override

Implementation

@override
BaseAuthenticator buildAuthenticator(Map<String, dynamic> opts) {
  auth = (String? nonce) {
    if (opts['jwt'] == null || opts['seed'] == null) {
      throw NatsError.errorForCode(ErrorCode.ClearedPair);
    }
    final sd = _decodeSeed(opts['seed']);
    final kp = _signKeyPairFromSeed(sd);
    final challenge = Uint8List.fromList(utf8.encode(nonce ?? ''));
    final signedMsg = Int32List(SignLength.Signature + challenge.length);
    _sign(signedMsg, challenge, challenge.length, kp['secretKey']);
    final sig = Uint8List(SignLength.Signature);
    for (int i1 = 0; i1 < sig.length; i1++) {
      sig[i1] = signedMsg[i1];
    }
    final sk = base64.encode(sig);
    final pk = _encode(false, sd['prefix'], kp['publicKey']);
    return {'jwt': opts['jwt'], 'nkey': pk, 'sig': sk};
  };
  return this;
}