buildVlessConfig static method

String buildVlessConfig({
  1. required String address,
  2. required int port,
  3. required String uuid,
  4. String flow = 'xtls-rprx-vision',
  5. String network = 'tcp',
  6. String security = 'reality',
  7. String? serverName,
  8. String? publicKey,
  9. String? shortId,
})

Build a minimal VLESS-over-Reality JSON config string.

All string parameters are sanitised – they must not contain unescaped JSON special characters supplied by the server.

Implementation

static String buildVlessConfig({
  required String address,
  required int port,
  required String uuid,
  String flow = 'xtls-rprx-vision',
  String network = 'tcp',
  String security = 'reality',
  String? serverName,
  String? publicKey,
  String? shortId,
}) {
  final outbound = {
    'protocol': 'vless',
    'settings': {
      'vnext': [
        {
          'address': address,
          'port': port,
          'users': [
            {'id': uuid, 'flow': flow, 'encryption': 'none'},
          ],
        },
      ],
    },
    'streamSettings': {
      'network': network,
      'security': security,
      if (security == 'reality')
        'realitySettings': {
          'serverName': serverName ?? address,
          'publicKey': publicKey ?? '',
          'shortId': shortId ?? '',
        },
      if (security == 'tls')
        'tlsSettings': {
          'serverName': serverName ?? address,
          'allowInsecure': false,
        },
    },
  };

  return jsonEncode({
    'log': {'loglevel': 'warning'},
    'inbounds': [
      {
        'port': 10808,
        'protocol': 'socks',
        'settings': {'auth': 'noauth'},
      },
    ],
    'outbounds': [outbound],
  });
}