diff --git a/package.json b/package.json index 24f87c8..0f43b92 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/singbox-converter.d.ts b/singbox-converter.d.ts new file mode 100644 index 0000000..a76ab82 --- /dev/null +++ b/singbox-converter.d.ts @@ -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; + 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; + +export function convertOutboundToLink(outbound: TOutbound): string; + +export function convertOutboundsToLinks(outbounds: TOutbound[]): string[];