buildTrojanConfig static method

String buildTrojanConfig({
  1. required String address,
  2. required int port,
  3. required String password,
  4. String? serverName,
  5. bool allowInsecure = false,
})

Build a minimal Trojan JSON config string.

Implementation

static String buildTrojanConfig({
  required String address,
  required int port,
  required String password,
  String? serverName,
  bool allowInsecure = false,
}) {
  return jsonEncode({
    'log': {'loglevel': 'warning'},
    'inbounds': [
      {
        'port': 10808,
        'protocol': 'socks',
        'settings': {'auth': 'noauth'},
      },
    ],
    'outbounds': [
      {
        'protocol': 'trojan',
        'settings': {
          'servers': [
            {
              'address': address,
              'port': port,
              'password': password,
            },
          ],
        },
        'streamSettings': {
          'network': 'tcp',
          'security': 'tls',
          'tlsSettings': {
            'serverName': serverName ?? address,
            'allowInsecure': allowInsecure,
          },
        },
      },
    ],
  });
}