rejectSessionAuthenticate method

  1. @override
Future<void> rejectSessionAuthenticate({
  1. required int id,
  2. required ReownSignError reason,
})
override

Implementation

@override
Future<void> rejectSessionAuthenticate({
  required int id,
  required ReownSignError reason,
}) async {
  _checkInitialized();

  final pendingSessionAuthRequests = getPendingSessionAuthRequests();

  if (!pendingSessionAuthRequests.containsKey(id)) {
    throw Errors.getInternalError(
      Errors.MISSING_OR_INVALID,
      context: 'rejectSessionAuthenticate() '
          'Could not find pending auth request with id $id',
    ).toSignError();
  }

  final pendingRequest = pendingSessionAuthRequests[id]!;
  if (!pendingRequest.transportType.isLinkMode) {
    _confirmOnlineStateOrThrow();
  }

  final receiverPublicKey = pendingRequest.requester.publicKey;
  final senderPublicKey = await core.crypto.generateKeyPair();
  final responseTopic = core.crypto.getUtils().hashKey(receiverPublicKey);

  final encodeOpts = EncodeOptions(
    type: EncodeOptions.TYPE_1,
    receiverPublicKey: receiverPublicKey,
    senderPublicKey: senderPublicKey,
  );

  final method = MethodConstants.WC_SESSION_AUTHENTICATE;
  final rpcOpts = MethodConstants.RPC_OPTS[method];
  await core.pairing.sendError(
    id,
    responseTopic,
    method,
    JsonRpcError(code: reason.code, message: reason.message),
    encodeOptions: encodeOpts,
    rpcOptions: rpcOpts?['reject'],
    appLink: _getAppLinkIfEnabled(pendingRequest.requester.metadata),
  );

  await sessionAuthRequests.delete(id.toString());
  await _deleteProposal(id);
}