xray_sdk 0.0.4-beta
xray_sdk: ^0.0.4-beta copied to clipboard
Dart library for generating Xray Core configurations and working with links (parsing/generation) for V2Ray protocols.
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 forxtls-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