xray_sdk

Dart library for generating Xray Core configurations and working with links (parsing/generation) for V2Ray protocols.

Requirements

To work with the library core, you need to use the third-party c-shared library xray-cshare.

Features

  • Protocols: VLESS, VMess, Trojan, ShadowSocks, WireGuard.
  • Transport: TCP (Raw), WebSocket, gRPC, mKCP, HTTPUpgrade, XHTTP.
  • Security: TLS, REALITY.
  • Link Handling: Parsing and generating vless://, vmess://, trojan://, ss:// links.
  • Utilities: Key generation (X25519, UUID), Xray core management (Start/Stop).

Installation

Add to pubspec.yaml:

dependencies:
  xray_sdk: ^1.0.0

Or run the command:

flutter pub add xray_sdk

Quick Start

Example of creating a VLESS + Reality configuration and generating a link:

import 'package:xray_sdk/config.dart';
import 'package:xray_sdk/share.dart';

void main() {
  // 1. Create client
  final client = VlessClient(
    id: "uuid-1234-5678",
    email: "user@example.com",
    flow: XtlsFlow.xtlsRprxVision,
  );

  // 2. Configure Inbound with Reality
  final inbound = VlessInbound(
    port: Port.single(443),
    tag: "vless-reality",
    settings: VlessInboundSettings(clients: [client]),
    streamSettings: StreamSettings(
      network: StreamNetwork.raw, // TCP
      security: StreamSecurity.reality,
      realitySettings: RealitySettings(
        target: "www.google.com:443",
        serverNames: ["www.google.com"],
        password: "private-key-here",
        shortIds: ["1234"],
        fingerprint: Fingerprint.chrome,
      ),
    ),
  );

  // 3. Generate link
  final share = V2RayShareFormatter();
  final link = share.encodeVlessByClient(inbound, client);
  
  print(link); // vless://uuid...@...?security=reality&...
}

Работа со ссылками (Sharing)

Класс V2RayShareFormatter отвечает за преобразование конфигураций.

Декодирование (Decoding)

final share = V2RayShareFormatter();
try {
  final config = share.decodeVless("vless://...");
  print(config.streamSettings.network);
} catch (e) {
  print("Ошибка парсинга: $e");
}

Encoding

final link = share.encodeVMessByClient(inboundConfig, clientObj);

Configuration Examples

Trojan + gRPC + Reality

final inbound = TrojanInbound(
  port: Port.single(443),
  tag: "trojan-grpc-reality",
  settings: TrojanInboundSettings(clients: [
    TrojanClient(password: "password", email: "trojan@test.com")
  ]),
  streamSettings: StreamSettings(
    network: StreamNetwork.grpc,
    security: StreamSecurity.reality,
    grpcSettings: GrpcSettings(serviceName: 'grpc-trojan'),
    realitySettings: RealitySettings(
      target: "example.com:443",
      serverNames: ["example.com"],
      password: "private-key",
      shortIds: ["1234"],
      fingerprint: Fingerprint.chrome,
    ),
  ),
);

ShadowSocks 2022

final inbound = ShadowSocksOutbound(
  tag: "ss-2022",
  settings: ShadowSocksOutboundSettings(
    uot: true,
    servers: [
      ShadowSocksServer(
        address: "example.com",
        port: 9000,
        method: EncryptionMethod.aes128Gcm,
        password: "server-password",
      ),
    ],
  ),
  streamSettings: StreamSettings(
    network: StreamNetwork.raw,
    security: StreamSecurity.none,
  ),
);

Protocols

  • VLESS: VlessInbound, VlessClient. Support for xtls-rprx-vision.
  • VMess: VMessInbound, VMessClient.
  • Trojan: TrojanInbound, TrojanClient.
  • ShadowSocks: ShadowSocksOutbound, ShadowSocksServer. Support for SIP002 and SIP008.
  • WireGuard: WireguardOutbound, WireguardOutboundPeer.

Transport Configuration (Stream Settings)

The StreamSettings class allows flexible configuration of the transport layer.

  • Network: raw (TCP), ws (WebSocket), grpc (gRPC), kcp (mKCP), httpUpgrade, xhttp.
  • Security: none, tls, reality.

Xray Wrapper

The XrayWrapper class provides access to native Xray core functions (requires libxray library).

final xray = XrayWrapper('libxray.so');
final uuid = xray.generateUuidV4();
final keys = xray.x25519Genkey('private_key');

Code Generation

If you modify models, regenerate serialization files:

flutter pub run build_runner build

Libraries

config
config/enums
core
packages/config/config
packages/config/enums/address_port_strategy
packages/config/enums/allocate_strategy
packages/config/enums/api_service
packages/config/enums/balancer_strategy_type
packages/config/enums/certificate_usage_type
packages/config/enums/dns_query_strategy
packages/config/enums/domain_strategy
packages/config/enums/encryption_method
packages/config/enums/fingerprint
packages/config/enums/headers_type
packages/config/enums/index
packages/config/enums/kcp_header_type
packages/config/enums/log_level
packages/config/enums/net_protocol
packages/config/enums/network
packages/config/enums/non_ip_query_type
packages/config/enums/operating_system
packages/config/enums/protocol
packages/config/enums/routing_domain_strategy
packages/config/enums/routing_rule_type
packages/config/enums/socks_auth
packages/config/enums/stream_network
packages/config/enums/stream_security
packages/config/enums/tcp_congestion
packages/config/enums/tproxy
packages/config/enums/traffic_type
packages/config/enums/transport_protocol
packages/config/enums/vless_encryption
packages/config/enums/vmess_security
packages/config/enums/xhttp_mode
packages/config/enums/xtls_flow
packages/config/helpers/enum_encoder
packages/config/helpers/split_enum_converter
packages/config/index
packages/config/models/api_config
packages/config/models/burst_observatory_config
packages/config/models/common/client_server
packages/config/models/common/port
packages/config/models/common/vnext_model
packages/config/models/common/with_level
packages/config/models/common/with_user_level
packages/config/models/dns/common_rules
packages/config/models/dns/dns_config
packages/config/models/dns/dns_hosts_converter
packages/config/models/dns/dns_server
packages/config/models/dns/dns_servers_converter
packages/config/models/dns/index
packages/config/models/fake_dns_config
packages/config/models/inbound/decodemo_door_inbound
packages/config/models/inbound/fallback
packages/config/models/inbound/http_inbound
packages/config/models/inbound/inbound
packages/config/models/inbound/inbound_client
packages/config/models/inbound/index
packages/config/models/inbound/shadow_socks_inbound
packages/config/models/inbound/socks_inbound
packages/config/models/inbound/trojan_inbound
packages/config/models/inbound/tun_inbound
packages/config/models/inbound/vless_inbound
packages/config/models/inbound/vmess_inbound
packages/config/models/inbound/wireguard_inbound
packages/config/models/log_config
packages/config/models/metrics_config
packages/config/models/observatory_config
packages/config/models/outbound/blackhole_outbound
packages/config/models/outbound/dns_outbound
packages/config/models/outbound/freedom_outbound
packages/config/models/outbound/http_outbound
packages/config/models/outbound/hysteria_outbound
packages/config/models/outbound/index
packages/config/models/outbound/loopback_outbound
packages/config/models/outbound/mux
packages/config/models/outbound/outbound
packages/config/models/outbound/proxy_settings
packages/config/models/outbound/shadowsocks_outbound
packages/config/models/outbound/socks_outbound
packages/config/models/outbound/trojan_outbound
packages/config/models/outbound/vless_outbound
packages/config/models/outbound/vmess_outbound
packages/config/models/outbound/wireguard_outbound
packages/config/models/ping_config
packages/config/models/policy/index
packages/config/models/policy/level_policy
packages/config/models/policy/policy_config
packages/config/models/policy/system_policy
packages/config/models/reverse/index
packages/config/models/reverse/reverse_bridge
packages/config/models/reverse/reverse_config
packages/config/models/reverse/reverse_portal
packages/config/models/routing/balancer_strategy
packages/config/models/routing/balancer_strategy_settings
packages/config/models/routing/index
packages/config/models/routing/routing_balancer
packages/config/models/routing/routing_config
packages/config/models/routing/routing_rule
packages/config/models/stats_config
packages/config/models/transport/custom_sockopt
packages/config/models/transport/grpc_settings
packages/config/models/transport/happy_eyeballs
packages/config/models/transport/http_upgrade_settings
packages/config/models/transport/hysteria_settings
packages/config/models/transport/index
packages/config/models/transport/kcp_settings
packages/config/models/transport/raw_settings
packages/config/models/transport/reality_settings
packages/config/models/transport/sockopt
packages/config/models/transport/stream_settings
packages/config/models/transport/tls_certificate
packages/config/models/transport/tls_settings
packages/config/models/transport/transport_config
packages/config/models/transport/ws_settings
packages/config/models/transport/xhttp_settings
packages/config/models/version_config
packages/core/index
packages/core/models/wrapper
packages/core/native/xray_wrapper
packages/core/xray_core
packages/core/xray_lib
packages/share/index
packages/share/share_distributor
packages/share/share_entity
packages/share/v2ray/helpers/base64
packages/share/v2ray/helpers/common
packages/share/v2ray/helpers/query
packages/share/v2ray/helpers/random
packages/share/v2ray/helpers/security
packages/share/v2ray/helpers/stream
packages/share/v2ray/hysteria_entity
packages/share/v2ray/index
packages/share/v2ray/models/hysteria_options
packages/share/v2ray/models/reality_transfer_options
packages/share/v2ray/models/shadowsocks_options
packages/share/v2ray/models/stream_options
packages/share/v2ray/models/transfer_options
packages/share/v2ray/models/trojan_options
packages/share/v2ray/models/vless_options
packages/share/v2ray/models/vmess_options
packages/share/v2ray/shadowsocks_entity
packages/share/v2ray/socks_entity
packages/share/v2ray/trojan_entity
packages/share/v2ray/v2ray_entity
packages/share/v2ray/vless_entity
packages/share/v2ray/vmess_entity
share
share/v2ray