Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
"version": "1.0.8",
"description": "A module to convert proxy links to Sing-box format and back, based on Nekobox logic.",
"main": "singbox-converter.js",
"types": "singbox-converter.d.ts",
"type": "module",
"files": [
"singbox-converter.js",
"singbox-converter.d.ts",
"README.md"
],
"repository": {
Expand Down
232 changes: 232 additions & 0 deletions singbox-converter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
export interface IMultiplexOptions {
enabled: true;
protocol: "h2mux" | "smux";
max_streams: number;
padding: boolean;
}

export interface ITLSOptions {
enabled: true;
insecure?: boolean;
server_name?: string;
alpn?: string[];
certificate?: string;
reality?: {
enabled: true;
public_key: string;
short_id?: string;
};
utls?: {
enabled: true;
fingerprint: string;
};
ech?: {
enabled: true;
config: string[];
};
}

export interface IWsTransport {
type: "ws";
headers?: Record<string, string>;
path: string;
max_early_data?: number;
early_data_header_name?: string;
}

export interface IHttpTransport {
type: "http";
path: string;
host?: string[];
method?: string;
}

export interface IGrpcTransport {
type: "grpc";
service_name: string;
}

export interface IQuicTransport {
type: "quic";
}

export interface IHttpUpgradeTransport {
type: "httpupgrade";
host?: string;
path?: string;
}

export type TTransport =
| IWsTransport
| IHttpTransport
| IGrpcTransport
| IQuicTransport
| IHttpUpgradeTransport;

export interface IVlessOutbound {
tag: string;
type: "vless";
server: string;
server_port: number;
uuid: string;
multiplex?: IMultiplexOptions;
tls?: ITLSOptions;
transport?: TTransport;
packet_encoding?: "packetaddr" | "xudp";
flow?: string;
}

export interface IVmessOutbound {
tag: string;
type: "vmess";
server: string;
server_port: number;
uuid: string;
alter_id: number;
security: string;
multiplex?: IMultiplexOptions;
tls?: ITLSOptions;
transport?: TTransport;
packet_encoding?: "packetaddr" | "xudp";
}

export interface ITrojanOutbound {
tag: string;
type: "trojan";
server: string;
server_port: number;
password: string;
multiplex?: IMultiplexOptions;
tls?: ITLSOptions;
transport?: TTransport;
}

export interface IShadowsocksOutbound {
tag: string;
type: "shadowsocks";
server: string;
server_port: number;
method: string;
password: string;
plugin?: string;
plugin_opts?: string;
udp_over_tcp?: boolean;
}

export interface ISocksOutbound {
tag: string;
type: "socks";
server: string;
server_port: number;
version: "4" | "4a" | "5";
username?: string;
password?: string;
udp_over_tcp?: boolean;
}

export interface IHttpOutbound {
tag: string;
type: "http";
server: string;
server_port: number;
username?: string;
password?: string;
tls?: ITLSOptions;
}

export interface IHysteriaOutbound {
tag: string;
type: "hysteria";
server: string;
up_mbps: number;
down_mbps: number;
obfs?: string;
auth_str?: string;
auth?: string;
hop_interval?: string;
disable_mtu_discovery?: boolean;
tls: ITLSOptions;
server_port?: number;
server_ports?: string[];
recv_window_conn?: number;
recv_window?: number;
}

export interface IHysteria2Outbound {
tag: string;
type: "hysteria2";
server: string;
up_mbps: number;
down_mbps: number;
password?: string;
obfs?: { type: "salamander"; password: string } | undefined;
tls: ITLSOptions;
server_port?: number;
server_ports?: string[];
}

export interface ITuicOutbound {
tag: string;
type: "tuic";
server: string;
server_port: number;
uuid: string;
password: string;
congestion_control: string;
zero_rtt_handshake: boolean;
udp_relay_mode?: "native" | "quic";
tls: ITLSOptions & { alpn?: string[]; disable_sni?: boolean };
}

export interface IWireguardOutbound {
tag: string;
type: "wireguard";
server: string;
server_port: number;
local_address: string[];
private_key: string;
peer_public_key: string;
mtu: number;
pre_shared_key?: string;
reserved?: string;
}

export interface ISSHOutbound {
tag: string;
type: "ssh";
server: string;
server_port: number;
user: string;
host_key?: string[];
private_key?: string;
private_key_passphrase?: string;
password?: string;
}

export type TOutbound =
| IVlessOutbound
| IVmessOutbound
| ITrojanOutbound
| IShadowsocksOutbound
| ISocksOutbound
| IHttpOutbound
| IHysteriaOutbound
| IHysteria2Outbound
| ITuicOutbound
| IWireguardOutbound
| ISSHOutbound;

export interface IConvertOptions {
outputPath?: string;
pretty?: boolean;
globalAllowInsecure?: boolean;
}

export function convertToOutbounds(
input: string,
options?: IConvertOptions
): Promise<TOutbound[] | void>;

export function convertOutboundToLink(outbound: TOutbound): string;

export function convertOutboundsToLinks(outbounds: TOutbound[]): string[];