authenticate method

Future<DC<Exception, String>> authenticate(
  1. EthPrivateKey credentials
)

This function authenticates the provided credentials by sending a request to the server.

It takes in an EthPrivateKey as an argument and returns a Future that resolves to a DC object with an Exception as the first type parameter and a String as the second type parameter.

If the authentication process is successful, the Future will contain the JWT token returned by the server, wrapped in a DC.data object.

If an error occurs during the authentication process, the Future will contain an Exception object wrapped in a DC.error object.

Implementation

Future<DC<Exception, String>> authenticate(EthPrivateKey credentials) async {
  try {
    final AuthDto auth = SmartWalletAuth.signer(credentials);
    final Response response = await _dio.post(
      '/v1/smart-wallets/auth',
      data: auth.toJson(),
    );
    final String jwt = response.data['jwt'];
    jwtToken = jwt;

    webSocketConnection = await WebSocketConnection.init(
      jwtToken: jwt,
      websocketServerURL: websocketServerURL,
    );

    return DC.data(jwt);
  } catch (e) {
    return DC.error(Exception(e.toString()));
  }
}