sing-box-kit 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/index.d.mts +453 -59
- package/dist/index.mjs +833 -47
- package/docs/generators.md +31 -0
- package/docs/internal/README.md +2 -2
- package/docs/proxy-profiles.md +63 -0
- package/docs/rules.md +5 -3
- package/docs/settings.md +2 -0
- package/index.ts +3 -1
- package/package.json +7 -3
- package/schema/README.md +1 -1
- package/src/compile.ts +2 -2
- package/src/factories.ts +73 -68
- package/src/generate.ts +116 -0
- package/src/internal/certificate.ts +72 -0
- package/src/internal/crypto.ts +34 -0
- package/src/internal/ech.ts +32 -0
- package/src/internal/reality.ts +21 -0
- package/src/ip.ts +63 -0
- package/src/proxy-profile.ts +847 -0
- package/src/rules.ts +6 -14
- package/src/settings.ts +11 -1
- package/src/user.ts +82 -5
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ bun config.ts > config.json
|
|
|
26
26
|
sing-box check -c config.json
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
On Node.js 22.
|
|
29
|
+
On Node.js 22.13 or later, install with `npm install sing-box-kit`, save the same example as `config.mjs`, and generate JSON with `node config.mjs > config.json`.
|
|
30
30
|
|
|
31
31
|
To run the example from a source checkout, run `vp install --frozen-lockfile` and use `./index` as the import path.
|
|
32
32
|
|
|
@@ -34,7 +34,9 @@ To run the example from a source checkout, run `vp install --frozen-lockfile` an
|
|
|
34
34
|
|
|
35
35
|
- [Build and validate a configuration](docs/configuration.md)
|
|
36
36
|
- [Resource factories and registration](docs/resources.md)
|
|
37
|
+
- [Generate server and client proxy configurations](docs/proxy-profiles.md)
|
|
37
38
|
- [Listen, dial, resolver, and TLS settings](docs/settings.md)
|
|
39
|
+
- [Generate credentials and key pairs](docs/generators.md)
|
|
38
40
|
- [Routing rules and shared conditions](docs/rules.md)
|
|
39
41
|
- [DNS rules and response evaluation](docs/dns-rules.md)
|
|
40
42
|
|
package/dist/index.d.mts
CHANGED
|
@@ -3314,7 +3314,7 @@ type Endpoint = {
|
|
|
3314
3314
|
fallback_delay?: Duration;
|
|
3315
3315
|
};
|
|
3316
3316
|
type UDPTimeout = number | string;
|
|
3317
|
-
type Inbound = {
|
|
3317
|
+
type Inbound$1 = {
|
|
3318
3318
|
type: "anytls";
|
|
3319
3319
|
tag?: string;
|
|
3320
3320
|
listen?: string;
|
|
@@ -3862,7 +3862,7 @@ type V2RayTransport = {
|
|
|
3862
3862
|
path?: string;
|
|
3863
3863
|
headers?: HTTPHeader;
|
|
3864
3864
|
};
|
|
3865
|
-
type Outbound = {
|
|
3865
|
+
type Outbound$1 = {
|
|
3866
3866
|
type: "anytls";
|
|
3867
3867
|
tag?: string;
|
|
3868
3868
|
detour?: string;
|
|
@@ -5042,8 +5042,8 @@ interface SingBoxConfig {
|
|
|
5042
5042
|
http_clients?: HTTPClient[];
|
|
5043
5043
|
network_namespaces?: NetworkNamespace[];
|
|
5044
5044
|
endpoints?: Endpoint[];
|
|
5045
|
-
inbounds?: Inbound[];
|
|
5046
|
-
outbounds?: Outbound[];
|
|
5045
|
+
inbounds?: Inbound$1[];
|
|
5046
|
+
outbounds?: Outbound$1[];
|
|
5047
5047
|
route?: RouteOptions;
|
|
5048
5048
|
services?: Service[];
|
|
5049
5049
|
experimental?: ExperimentalOptions;
|
|
@@ -5788,13 +5788,50 @@ type InlineHttpClient = ReadonlyJson<Exclude<HTTPClientReference$1, HttpClientVa
|
|
|
5788
5788
|
readonly tag?: never;
|
|
5789
5789
|
};
|
|
5790
5790
|
type HttpClientInput = ReadonlyJson<HTTPClientReference$1>;
|
|
5791
|
+
type ProtocolTlsOptions<K, T> = T & (K extends "naive" ? {
|
|
5792
|
+
readonly alpn?: never;
|
|
5793
|
+
} : unknown);
|
|
5791
5794
|
declare const userBrand: unique symbol;
|
|
5792
5795
|
interface User {
|
|
5793
5796
|
readonly name: string;
|
|
5794
5797
|
readonly [userBrand]: true;
|
|
5795
5798
|
}
|
|
5799
|
+
type Password = {
|
|
5800
|
+
readonly password: string;
|
|
5801
|
+
};
|
|
5802
|
+
interface UserCredentials {
|
|
5803
|
+
readonly anytls?: Password;
|
|
5804
|
+
readonly http?: Password;
|
|
5805
|
+
readonly hysteria?: StrictUnion<{
|
|
5806
|
+
readonly auth: string | readonly number[];
|
|
5807
|
+
} | {
|
|
5808
|
+
readonly auth_str: string;
|
|
5809
|
+
}>;
|
|
5810
|
+
readonly hysteria2?: Password;
|
|
5811
|
+
readonly mixed?: Password;
|
|
5812
|
+
readonly naive?: Password;
|
|
5813
|
+
readonly shadowsocks?: Password;
|
|
5814
|
+
readonly shadowtls?: Password;
|
|
5815
|
+
readonly snell?: {
|
|
5816
|
+
readonly userkey: string;
|
|
5817
|
+
};
|
|
5818
|
+
readonly socks?: Password;
|
|
5819
|
+
readonly trojan?: Password;
|
|
5820
|
+
readonly tuic?: Password & {
|
|
5821
|
+
readonly uuid: string;
|
|
5822
|
+
};
|
|
5823
|
+
readonly vless?: {
|
|
5824
|
+
readonly uuid: string;
|
|
5825
|
+
readonly flow?: string;
|
|
5826
|
+
};
|
|
5827
|
+
readonly vmess?: {
|
|
5828
|
+
readonly uuid: string;
|
|
5829
|
+
readonly alter_id?: number;
|
|
5830
|
+
};
|
|
5831
|
+
}
|
|
5796
5832
|
export declare function user(input: {
|
|
5797
5833
|
name: string;
|
|
5834
|
+
credentials?: UserCredentials;
|
|
5798
5835
|
}): User;
|
|
5799
5836
|
interface ListenMethod<T> {
|
|
5800
5837
|
listen(options?: T): this;
|
|
@@ -5825,79 +5862,108 @@ declare const endpointRoles: {
|
|
|
5825
5862
|
readonly openconnect: "openconnect-endpoint";
|
|
5826
5863
|
readonly "openvpn-client": "openvpn-client-endpoint";
|
|
5827
5864
|
};
|
|
5828
|
-
type PasswordEntry<Name extends "username" | "name"> = {
|
|
5829
|
-
readonly user: User;
|
|
5830
|
-
readonly password: string;
|
|
5831
|
-
} & { readonly [K in Name]?: never; };
|
|
5832
|
-
type MixedEntry = PasswordEntry<"username"> | (Readonly<User$1> & {
|
|
5833
|
-
user?: never;
|
|
5834
|
-
});
|
|
5835
|
-
type ShadowsocksEntry = PasswordEntry<"name"> | (Readonly<ShadowsocksUser> & {
|
|
5836
|
-
user?: never;
|
|
5837
|
-
});
|
|
5838
|
-
type VlessEntry = Required<Pick<VLESSUser, "uuid">> & Pick<VLESSUser, "flow"> & {
|
|
5839
|
-
user: User;
|
|
5840
|
-
name?: never;
|
|
5841
|
-
};
|
|
5842
5865
|
declare const authOptions: {
|
|
5866
|
+
readonly anytls: {
|
|
5867
|
+
readonly name: "name";
|
|
5868
|
+
readonly allowRaw: true;
|
|
5869
|
+
};
|
|
5870
|
+
readonly http: {
|
|
5871
|
+
readonly name: "username";
|
|
5872
|
+
readonly allowRaw: true;
|
|
5873
|
+
};
|
|
5874
|
+
readonly hysteria: {
|
|
5875
|
+
readonly name: "name";
|
|
5876
|
+
readonly allowRaw: true;
|
|
5877
|
+
};
|
|
5878
|
+
readonly hysteria2: {
|
|
5879
|
+
readonly name: "name";
|
|
5880
|
+
readonly allowRaw: true;
|
|
5881
|
+
};
|
|
5843
5882
|
readonly mixed: {
|
|
5844
5883
|
readonly name: "username";
|
|
5845
|
-
readonly credentials: readonly ["password"];
|
|
5846
|
-
readonly required: readonly ["password"];
|
|
5847
5884
|
readonly allowRaw: true;
|
|
5848
5885
|
};
|
|
5849
|
-
readonly
|
|
5886
|
+
readonly naive: {
|
|
5850
5887
|
readonly name: "username";
|
|
5851
|
-
readonly
|
|
5852
|
-
readonly required: readonly ["password"];
|
|
5888
|
+
readonly allowRaw: true;
|
|
5853
5889
|
};
|
|
5854
5890
|
readonly shadowsocks: {
|
|
5855
|
-
readonly
|
|
5856
|
-
readonly
|
|
5891
|
+
readonly name: "name";
|
|
5892
|
+
readonly allowRaw: true;
|
|
5893
|
+
};
|
|
5894
|
+
readonly shadowtls: {
|
|
5895
|
+
readonly name: "name";
|
|
5896
|
+
readonly allowRaw: true;
|
|
5897
|
+
};
|
|
5898
|
+
readonly snell: {
|
|
5899
|
+
readonly name: "name";
|
|
5900
|
+
readonly allowRaw: true;
|
|
5901
|
+
};
|
|
5902
|
+
readonly socks: {
|
|
5903
|
+
readonly name: "username";
|
|
5904
|
+
readonly allowRaw: false;
|
|
5905
|
+
};
|
|
5906
|
+
readonly trojan: {
|
|
5907
|
+
readonly name: "name";
|
|
5908
|
+
readonly allowRaw: true;
|
|
5909
|
+
};
|
|
5910
|
+
readonly tuic: {
|
|
5857
5911
|
readonly name: "name";
|
|
5858
5912
|
readonly allowRaw: true;
|
|
5859
5913
|
};
|
|
5860
5914
|
readonly vless: {
|
|
5861
5915
|
readonly name: "name";
|
|
5862
|
-
readonly
|
|
5863
|
-
|
|
5916
|
+
readonly allowRaw: false;
|
|
5917
|
+
};
|
|
5918
|
+
readonly vmess: {
|
|
5919
|
+
readonly name: "name";
|
|
5920
|
+
readonly allowRaw: true;
|
|
5864
5921
|
};
|
|
5865
5922
|
};
|
|
5866
|
-
type
|
|
5867
|
-
type
|
|
5868
|
-
|
|
5869
|
-
|
|
5923
|
+
type AuthKind = keyof typeof authOptions;
|
|
5924
|
+
type ShadowsocksEntry = User | (Readonly<ShadowsocksUser> & {
|
|
5925
|
+
user?: never;
|
|
5926
|
+
});
|
|
5927
|
+
type Catalog$1 = SBKitInputs["factories"];
|
|
5928
|
+
type Kind<T extends Target> = keyof Catalog$1[T] & string;
|
|
5929
|
+
type Groups<T extends Target, K extends Kind<T>> = ReadonlyJson<Catalog$1[T][K]>;
|
|
5930
|
+
type StrictTransport<O> = O extends {
|
|
5931
|
+
readonly transport?: infer V;
|
|
5932
|
+
} ? O & {
|
|
5933
|
+
readonly transport?: StrictUnion<NonNullable<V>>;
|
|
5934
|
+
} : O;
|
|
5935
|
+
type Options$1<T extends Target, K extends Kind<T>> = Groups<T, K> extends {
|
|
5870
5936
|
options: infer O;
|
|
5871
|
-
} ? StrictUnion<O
|
|
5937
|
+
} ? StrictUnion<StrictTransport<O>> : never;
|
|
5872
5938
|
type Tag = string | readonly string[] | undefined;
|
|
5873
5939
|
type ExtraRoles<T extends Target, K> = T extends "endpoints" ? (K extends keyof typeof endpointRoles ? (typeof endpointRoles)[K] : never) | (K extends (typeof preferredRouteEndpoints)[number] ? "preferred-routes" : never) : T extends "outbounds" ? K extends "bridge" ? "preferred-routes" : never : T extends "services" ? K extends "resolved" ? "resolved-service" : never : T extends "dns.servers" ? K extends (typeof preferredDnsKinds)[number] ? "preferred-domain" : never : never;
|
|
5874
|
-
type Profile<T extends Target, K, F> = "enabled" extends keyof F ? T extends "inbounds" | "services" ? ServerTls | (K extends "vless" ? RealityServerTls : never) : ClientTls | (K extends "vless" ? RealityClientTls : never) : never;
|
|
5940
|
+
type Profile$1<T extends Target, K, F> = "enabled" extends keyof F ? T extends "inbounds" | "services" ? ServerTls | (K extends "vless" ? RealityServerTls : never) : ClientTls | (K extends "vless" ? RealityClientTls : never) : never;
|
|
5875
5941
|
type Built<T extends Target, K extends Kind<T>, V extends Tag = string, G = Groups<T, K>> = Resource<T, K, V, (typeof targetRoles)[T][number] | ExtraRoles<T, K>> & (G extends {
|
|
5876
5942
|
listen: infer L;
|
|
5877
5943
|
} ? ListenMethod<L> : unknown) & (G extends {
|
|
5878
5944
|
dial: infer D;
|
|
5879
5945
|
} ? DialMethod<D> : unknown) & (G extends {
|
|
5880
5946
|
tls: infer F;
|
|
5881
|
-
} ? TlsMethod<(F & {
|
|
5947
|
+
} ? TlsMethod<ProtocolTlsOptions<K, (F & {
|
|
5882
5948
|
side?: never;
|
|
5883
|
-
}) | Profile<T, K, F
|
|
5949
|
+
}) | Profile$1<T, K, F>>> : unknown) & (T extends "inbounds" ? (K extends keyof typeof authOptions ? AuthMethod : unknown) : unknown);
|
|
5884
5950
|
type Factory<T extends Target, K extends Kind<T>> = T extends "services" | "http_clients" ? {
|
|
5885
|
-
(options: Options<T, K> & {
|
|
5951
|
+
(options: Options$1<T, K> & {
|
|
5886
5952
|
tag: string;
|
|
5887
5953
|
}): Built<T, K>;
|
|
5888
|
-
(...args: {} extends Options<T, K> ? [options?: Options<T, K>] : [options: Options<T, K>]): Built<T, K, string | undefined>;
|
|
5889
|
-
} : (options: Options<T, K>) => Built<T, K>;
|
|
5954
|
+
(...args: {} extends Options$1<T, K> ? [options?: Options$1<T, K>] : [options: Options$1<T, K>]): Built<T, K, string | undefined>;
|
|
5955
|
+
} : (options: Options$1<T, K>) => Built<T, K>;
|
|
5890
5956
|
type Factories<T extends Target> = { [K in Kind<T> as CamelCase<K>]: Factory<T, K>; };
|
|
5891
|
-
type ShadowsocksBase = Omit<Options<"inbounds", "shadowsocks">, "method" | "users" | "managed">;
|
|
5892
|
-
type Method = Options<"inbounds", "shadowsocks">["method"];
|
|
5893
|
-
type MultiMethod = Exclude<Method, "none">;
|
|
5957
|
+
type ShadowsocksBase = Omit<Options$1<"inbounds", "shadowsocks">, "method" | "users" | "managed">;
|
|
5958
|
+
type Method = Options$1<"inbounds", "shadowsocks">["method"];
|
|
5959
|
+
type MultiMethod$1 = Exclude<Method, "none">;
|
|
5894
5960
|
type ManagedShadowsocks = ShadowsocksBase & {
|
|
5895
|
-
method: MultiMethod;
|
|
5961
|
+
method: MultiMethod$1;
|
|
5896
5962
|
managed: true;
|
|
5897
5963
|
users?: readonly [];
|
|
5898
5964
|
};
|
|
5899
5965
|
type StaticShadowsocks = ShadowsocksBase & {
|
|
5900
|
-
method: MultiMethod;
|
|
5966
|
+
method: MultiMethod$1;
|
|
5901
5967
|
managed?: false;
|
|
5902
5968
|
users: readonly [ShadowsocksEntry, ...ShadowsocksEntry[]];
|
|
5903
5969
|
};
|
|
@@ -5906,31 +5972,32 @@ type ShadowsocksOptions = ShadowsocksBase & ({
|
|
|
5906
5972
|
managed?: false;
|
|
5907
5973
|
users?: readonly [];
|
|
5908
5974
|
} | {
|
|
5909
|
-
method: MultiMethod;
|
|
5975
|
+
method: MultiMethod$1;
|
|
5910
5976
|
managed?: boolean;
|
|
5911
5977
|
users?: readonly [];
|
|
5912
5978
|
} | {
|
|
5913
|
-
method: MultiMethod;
|
|
5979
|
+
method: MultiMethod$1;
|
|
5914
5980
|
managed?: false;
|
|
5915
5981
|
users?: readonly ShadowsocksEntry[];
|
|
5916
5982
|
});
|
|
5917
|
-
type
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
5983
|
+
type InboundUsers<O, K extends AuthKind> = O extends {
|
|
5984
|
+
users?: readonly (infer Entry)[];
|
|
5985
|
+
} ? Omit<O, "users"> & (O extends {
|
|
5986
|
+
users: unknown;
|
|
5987
|
+
} ? {
|
|
5988
|
+
readonly users: readonly User[];
|
|
5989
|
+
} : {
|
|
5990
|
+
readonly users?: readonly (User | ((typeof authOptions)[K]["allowRaw"] extends true ? Entry & {
|
|
5991
|
+
user?: never;
|
|
5992
|
+
} : never))[];
|
|
5993
|
+
}) : O;
|
|
5994
|
+
type InboundFactories = Omit<Factories<"inbounds">, AuthKind> & { [K in Exclude<AuthKind, "shadowsocks">]: (options: StrictUnion<InboundUsers<Options$1<"inbounds", K>, K>>) => Built<"inbounds", K>; } & {
|
|
5928
5995
|
shadowsocks: {
|
|
5929
5996
|
(options: ManagedShadowsocks | StaticShadowsocks): Built<"inbounds", "shadowsocks"> & SsmInbound;
|
|
5930
5997
|
(options: ShadowsocksOptions): Built<"inbounds", "shadowsocks">;
|
|
5931
5998
|
};
|
|
5932
5999
|
};
|
|
5933
|
-
type RuleSetFactory<K extends "local" | "remote"> = <const T extends string | readonly string[]>(options: Omit<Options<"route.rule_set", K>, "tag"> & {
|
|
6000
|
+
type RuleSetFactory<K extends "local" | "remote"> = <const T extends string | readonly string[]>(options: Omit<Options$1<"route.rule_set", K>, "tag"> & {
|
|
5934
6001
|
readonly tag: T;
|
|
5935
6002
|
}) => Built<"route.rule_set", K, T>;
|
|
5936
6003
|
export declare const inbound: Readonly<InboundFactories>;
|
|
@@ -5942,10 +6009,337 @@ export declare const certificateProvider: Readonly<Factories<"certificate_provid
|
|
|
5942
6009
|
export declare const networkNamespace: Readonly<Factories<"network_namespaces">>;
|
|
5943
6010
|
export declare const httpClient: Factory<"http_clients", "http-client">;
|
|
5944
6011
|
export declare const ruleSet: Readonly<{
|
|
5945
|
-
inline(options: Omit<Options<"route.rule_set", "inline">, "tag"> & {
|
|
6012
|
+
inline(options: Omit<Options$1<"route.rule_set", "inline">, "tag"> & {
|
|
5946
6013
|
tag: string;
|
|
5947
6014
|
}): Built<"route.rule_set", "inline">;
|
|
5948
6015
|
local: RuleSetFactory<"local">;
|
|
5949
6016
|
remote: RuleSetFactory<"remote">;
|
|
5950
6017
|
}>;
|
|
5951
|
-
|
|
6018
|
+
type Protocol = Exclude<keyof UserCredentials, "mixed">;
|
|
6019
|
+
type TransportProtocol = "vmess" | "vless" | "trojan";
|
|
6020
|
+
type TlsUnsupported = "shadowsocks" | "snell" | "socks";
|
|
6021
|
+
type Catalog = SBKitInputs["factories"];
|
|
6022
|
+
type Options<T extends "inbounds" | "outbounds", K extends Protocol> = ReadonlyJson<Catalog[T][K]["options"]>;
|
|
6023
|
+
type Inbound<K extends Protocol> = ReturnType<(typeof inbound)[K]>;
|
|
6024
|
+
type Outbound<K extends Protocol> = ReturnType<(typeof outbound)[K]>;
|
|
6025
|
+
type Users = readonly [User, ...User[]];
|
|
6026
|
+
type Port = {
|
|
6027
|
+
readonly host: string;
|
|
6028
|
+
readonly port: number;
|
|
6029
|
+
};
|
|
6030
|
+
type Direct = {
|
|
6031
|
+
readonly connect: Port;
|
|
6032
|
+
readonly realm?: never;
|
|
6033
|
+
};
|
|
6034
|
+
type Hopping = {
|
|
6035
|
+
readonly host: string;
|
|
6036
|
+
readonly ports: string | readonly string[];
|
|
6037
|
+
};
|
|
6038
|
+
type HysteriaDirect = {
|
|
6039
|
+
readonly connect: StrictUnion<Port | Hopping>;
|
|
6040
|
+
readonly realm?: never;
|
|
6041
|
+
};
|
|
6042
|
+
type Transport = StrictUnion<{
|
|
6043
|
+
readonly type: "tcp" | "quic";
|
|
6044
|
+
} | ReadonlyJson<Pick<Extract<V2RayTransport$1, {
|
|
6045
|
+
type: "http";
|
|
6046
|
+
}>, "type" | "host" | "path" | "method">> | ReadonlyJson<Pick<Extract<V2RayTransport$1, {
|
|
6047
|
+
type: "ws";
|
|
6048
|
+
}>, "type" | "path" | "max_early_data" | "early_data_header_name">> | ReadonlyJson<Pick<Extract<V2RayTransport$1, {
|
|
6049
|
+
type: "grpc";
|
|
6050
|
+
}>, "type" | "service_name">> | ReadonlyJson<Pick<Extract<V2RayTransport$1, {
|
|
6051
|
+
type: "httpupgrade";
|
|
6052
|
+
}>, "type" | "host" | "path">>> & { readonly [Key in AllTransportSideFields]?: never; };
|
|
6053
|
+
type NormalTls = {
|
|
6054
|
+
readonly mode: "tls";
|
|
6055
|
+
readonly serverName?: string;
|
|
6056
|
+
readonly alpn?: string | readonly string[];
|
|
6057
|
+
};
|
|
6058
|
+
type RealityTls = {
|
|
6059
|
+
readonly mode: "reality";
|
|
6060
|
+
readonly serverName: string;
|
|
6061
|
+
readonly handshake: Port & Dial;
|
|
6062
|
+
readonly keyPair: {
|
|
6063
|
+
readonly privateKey: string;
|
|
6064
|
+
readonly publicKey: string;
|
|
6065
|
+
};
|
|
6066
|
+
} & StrictUnion<{
|
|
6067
|
+
readonly shortId: string;
|
|
6068
|
+
} | {
|
|
6069
|
+
readonly shortIds: readonly [string, ...string[]];
|
|
6070
|
+
}>;
|
|
6071
|
+
type NoTls = {
|
|
6072
|
+
readonly mode: "none";
|
|
6073
|
+
};
|
|
6074
|
+
type TransportTls<K extends TransportProtocol> = StrictUnion<{
|
|
6075
|
+
readonly transport: Transport;
|
|
6076
|
+
readonly tls: NormalTls;
|
|
6077
|
+
} | {
|
|
6078
|
+
readonly transport?: Exclude<Transport, {
|
|
6079
|
+
type: "tcp" | "quic";
|
|
6080
|
+
}> | {
|
|
6081
|
+
readonly type: "tcp";
|
|
6082
|
+
};
|
|
6083
|
+
readonly tls?: NormalTls | NoTls | (K extends "vless" ? RealityTls : never);
|
|
6084
|
+
}>;
|
|
6085
|
+
declare const sharedOption: {
|
|
6086
|
+
readonly hysteria: "obfs";
|
|
6087
|
+
readonly hysteria2: "obfs";
|
|
6088
|
+
readonly shadowsocks: "method";
|
|
6089
|
+
};
|
|
6090
|
+
declare const ownedServer: readonly ["tag", "users", "password", "version", "transport", "managed", "destinations", "psk", "mode", "obfs_mode", "realm", "handshake"];
|
|
6091
|
+
declare const ownedClient: readonly ["tag", "server", "server_port", "server_ports", "username", "password", "uuid", "flow", "alter_id", "auth", "auth_str", "userkey", "psk", "version", "transport", "mode", "obfs_mode", "realm"];
|
|
6092
|
+
type SharedOption<K extends Protocol> = K extends keyof typeof sharedOption ? (typeof sharedOption)[K] : never;
|
|
6093
|
+
type SideOptions<O, Keys extends PropertyKey> = O extends unknown ? Omit<O, Keys> & { readonly [K in Extract<Keys, keyof O | "version" | "transport">]?: never; } : never;
|
|
6094
|
+
type ProfileOutboundOptions<K extends Protocol, Input> = K extends "snell" ? Extract<StrictUnion<Options<"outbounds", "snell">>, {
|
|
6095
|
+
version: [Input] extends [{
|
|
6096
|
+
readonly version: 5;
|
|
6097
|
+
}] ? 4 : 6;
|
|
6098
|
+
}> : Options<"outbounds", K>;
|
|
6099
|
+
type Realm = ReadonlyJson<Required<Pick<Hysteria2InboundRealm$1, "server_url" | "realm_id" | "stun_servers">>> & ReadonlyJson<Pick<Hysteria2InboundRealm$1, "token">>;
|
|
6100
|
+
type RealmLocal = ReadonlyJson<Omit<Hysteria2InboundRealm$1, "server_url" | "realm_id" | "stun_servers">>;
|
|
6101
|
+
type ServerSettings<K extends Protocol, Input> = {
|
|
6102
|
+
readonly tag: string;
|
|
6103
|
+
readonly listen?: ReadonlyJson<Catalog["inbounds"][K]["listen"]> & {
|
|
6104
|
+
readonly address?: string;
|
|
6105
|
+
};
|
|
6106
|
+
readonly options?: SideOptions<Options<"inbounds", K>, (typeof ownedServer)[number] | SharedOption<K>>;
|
|
6107
|
+
readonly tls?: K extends TlsUnsupported | "shadowtls" ? never : ProtocolTlsOptions<K, ReadonlyJson<Omit<InboundTLSOptions$1, "enabled" | "reality">>>;
|
|
6108
|
+
readonly transport?: K extends TransportProtocol ? TransportSideOptions<ProfileTransport<Input>, false> : never;
|
|
6109
|
+
readonly realm?: K extends "hysteria2" ? RealmLocal : never;
|
|
6110
|
+
};
|
|
6111
|
+
type ClientTls$1 = ReadonlyJson<Omit<OutboundTLSOptions$1, "enabled" | "server_name" | "reality">>;
|
|
6112
|
+
type ClientSettings<K extends Protocol, Input> = {
|
|
6113
|
+
readonly tag: string;
|
|
6114
|
+
readonly dial?: ReadonlyJson<Catalog["outbounds"][K]["dial"]>;
|
|
6115
|
+
readonly options?: SideOptions<ProfileOutboundOptions<K, Input>, (typeof ownedClient)[number] | SharedOption<K>>;
|
|
6116
|
+
readonly tls?: K extends TlsUnsupported ? never : ProtocolTlsOptions<K, ClientTls$1>;
|
|
6117
|
+
readonly transport?: K extends TransportProtocol ? TransportSideOptions<ProfileTransport<Input>, true> : never;
|
|
6118
|
+
readonly realm?: K extends "hysteria2" ? Omit<RealmLocal, "stun_domain_resolver"> : never;
|
|
6119
|
+
readonly shortId?: K extends "vless" ? string : never;
|
|
6120
|
+
};
|
|
6121
|
+
interface Profile<K extends Protocol, Authenticated extends boolean, ExtraInbound = unknown, Input = unknown> {
|
|
6122
|
+
server(this: void, options: ServerSettings<K, Input>): Inbound<K> & ExtraInbound;
|
|
6123
|
+
client(this: void, ...args: Authenticated extends true ? [user: User, options: ClientSettings<K, Input>] : [options: ClientSettings<K, Input>]): Outbound<K>;
|
|
6124
|
+
}
|
|
6125
|
+
type TransportInput<K extends TransportProtocol> = Direct & {
|
|
6126
|
+
readonly users: Users;
|
|
6127
|
+
} & TransportTls<K>;
|
|
6128
|
+
type VlessInput = TransportInput<"vless">;
|
|
6129
|
+
type VlessProfile<Input = unknown> = Profile<"vless", true, unknown, Input>;
|
|
6130
|
+
type VlessProfileResult<Input = unknown> = VlessProfile<Input> | Promise<VlessProfile<Input>>;
|
|
6131
|
+
type PlainInput = Direct & {
|
|
6132
|
+
readonly tls?: NormalTls | NoTls;
|
|
6133
|
+
};
|
|
6134
|
+
type RequiredTlsInput<K extends Protocol = Protocol> = Direct & {
|
|
6135
|
+
readonly users: Users;
|
|
6136
|
+
readonly tls: ProtocolTlsOptions<K, NormalTls>;
|
|
6137
|
+
};
|
|
6138
|
+
type HysteriaInput = HysteriaDirect & Pick<RequiredTlsInput, "users" | "tls"> & Pick<Options<"inbounds", "hysteria">, "obfs">;
|
|
6139
|
+
type Hysteria2Input = {
|
|
6140
|
+
readonly users: Users;
|
|
6141
|
+
} & Pick<Options<"inbounds", "hysteria2">, "obfs"> & ((HysteriaDirect & {
|
|
6142
|
+
readonly tls: NormalTls;
|
|
6143
|
+
}) | {
|
|
6144
|
+
readonly connect?: never;
|
|
6145
|
+
readonly realm: Realm;
|
|
6146
|
+
readonly tls: NormalTls & {
|
|
6147
|
+
readonly serverName: string;
|
|
6148
|
+
};
|
|
6149
|
+
});
|
|
6150
|
+
type SocksInput = Direct & {
|
|
6151
|
+
readonly version?: "4" | "4a" | "5";
|
|
6152
|
+
};
|
|
6153
|
+
type SnellInput = Direct & {
|
|
6154
|
+
readonly psk: string;
|
|
6155
|
+
} & StrictUnion<{
|
|
6156
|
+
readonly version: 5;
|
|
6157
|
+
readonly obfs_mode?: "none" | "http" | "tls";
|
|
6158
|
+
} | {
|
|
6159
|
+
readonly version?: 6;
|
|
6160
|
+
readonly mode?: "default" | "unshaped" | "unsafe-raw";
|
|
6161
|
+
}>;
|
|
6162
|
+
type ShadowTlsInput = Direct & {
|
|
6163
|
+
readonly handshake: ReadonlyJson<ShadowTLSHandshakeOptions$1> & {
|
|
6164
|
+
readonly server: string;
|
|
6165
|
+
readonly server_port: number;
|
|
6166
|
+
};
|
|
6167
|
+
readonly serverName: string;
|
|
6168
|
+
};
|
|
6169
|
+
type ShadowsocksInput = Direct;
|
|
6170
|
+
type ShadowsocksMethod = Options<"inbounds", "shadowsocks">["method"];
|
|
6171
|
+
type MultiMethod = Exclude<ShadowsocksMethod, "none" | "2022-blake3-chacha20-poly1305">;
|
|
6172
|
+
type SharedPassword = StrictUnion<{
|
|
6173
|
+
readonly method: "none";
|
|
6174
|
+
} | {
|
|
6175
|
+
readonly method: Exclude<ShadowsocksMethod, "none">;
|
|
6176
|
+
readonly password: string;
|
|
6177
|
+
}>;
|
|
6178
|
+
type MultiPassword = StrictUnion<{
|
|
6179
|
+
readonly method: Extract<MultiMethod, `2022-${string}`>;
|
|
6180
|
+
readonly serverKey: string;
|
|
6181
|
+
} | {
|
|
6182
|
+
readonly method: Exclude<MultiMethod, `2022-${string}`>;
|
|
6183
|
+
}>;
|
|
6184
|
+
declare const localTransportFields: {
|
|
6185
|
+
readonly tcp: readonly [];
|
|
6186
|
+
readonly quic: readonly [];
|
|
6187
|
+
readonly http: readonly ["headers", "idle_timeout", "ping_timeout"];
|
|
6188
|
+
readonly ws: readonly ["headers"];
|
|
6189
|
+
readonly grpc: readonly ["idle_timeout", "ping_timeout"];
|
|
6190
|
+
readonly httpupgrade: readonly ["headers"];
|
|
6191
|
+
};
|
|
6192
|
+
declare const grpcClientFields: readonly ["permit_without_stream"];
|
|
6193
|
+
type TransportKind = keyof typeof localTransportFields;
|
|
6194
|
+
type TransportSelection<K extends TransportKind> = {
|
|
6195
|
+
readonly transport: {
|
|
6196
|
+
readonly type: K;
|
|
6197
|
+
};
|
|
6198
|
+
};
|
|
6199
|
+
type ProfileTransport<Input> = Input extends TransportSelection<infer K> ? K : "tcp";
|
|
6200
|
+
type TransportSideField<K extends TransportKind, Client extends boolean> = (typeof localTransportFields)[K][number] | (Client extends true ? (K extends "grpc" ? (typeof grpcClientFields)[number] : never) : never);
|
|
6201
|
+
type AllTransportSideFields = TransportSideField<TransportKind, true>;
|
|
6202
|
+
type CommonTransportSideFields<K extends TransportKind, Client extends boolean> = keyof (K extends TransportKind ? Record<TransportSideField<K, Client>, true> : never) & AllTransportSideFields;
|
|
6203
|
+
type TransportSideOptions<K extends TransportKind, Client extends boolean, Allowed extends AllTransportSideFields = CommonTransportSideFields<K, Client>> = [Allowed] extends [never] ? never : ReadonlyJson<Pick<StrictUnion<V2RayTransport$1>, Allowed>> & { readonly [Key in Exclude<AllTransportSideFields, Allowed>]?: never; };
|
|
6204
|
+
declare function http(input: PlainInput & {
|
|
6205
|
+
readonly users: Users;
|
|
6206
|
+
}): Profile<"http", true>;
|
|
6207
|
+
declare function http(input: PlainInput & {
|
|
6208
|
+
readonly users?: never;
|
|
6209
|
+
}): Profile<"http", false>;
|
|
6210
|
+
declare function socks(input: SocksInput & {
|
|
6211
|
+
readonly users: Users;
|
|
6212
|
+
}): Profile<"socks", true>;
|
|
6213
|
+
declare function socks(input: SocksInput & {
|
|
6214
|
+
readonly users?: never;
|
|
6215
|
+
}): Profile<"socks", false>;
|
|
6216
|
+
declare function snell<const Version extends 5 | 6 = 6>(input: SnellInput & {
|
|
6217
|
+
readonly version?: Version;
|
|
6218
|
+
readonly users: Users;
|
|
6219
|
+
}): Profile<"snell", true, unknown, {
|
|
6220
|
+
readonly version: Version;
|
|
6221
|
+
}>;
|
|
6222
|
+
declare function snell<const Version extends 5 | 6 = 6>(input: SnellInput & {
|
|
6223
|
+
readonly version?: Version;
|
|
6224
|
+
readonly users?: never;
|
|
6225
|
+
}): Profile<"snell", false, unknown, {
|
|
6226
|
+
readonly version: Version;
|
|
6227
|
+
}>;
|
|
6228
|
+
declare function shadowtls(input: ShadowTlsInput & {
|
|
6229
|
+
readonly version?: 3;
|
|
6230
|
+
readonly users: Users;
|
|
6231
|
+
readonly password?: never;
|
|
6232
|
+
}): Profile<"shadowtls", true>;
|
|
6233
|
+
declare function shadowtls(input: ShadowTlsInput & {
|
|
6234
|
+
readonly version: 1;
|
|
6235
|
+
readonly users?: never;
|
|
6236
|
+
readonly password?: never;
|
|
6237
|
+
}): Profile<"shadowtls", false>;
|
|
6238
|
+
declare function shadowtls(input: ShadowTlsInput & {
|
|
6239
|
+
readonly version: 2;
|
|
6240
|
+
readonly users?: never;
|
|
6241
|
+
readonly password: string;
|
|
6242
|
+
}): Profile<"shadowtls", false>;
|
|
6243
|
+
declare function shadowsocks(input: ShadowsocksInput & MultiPassword & {
|
|
6244
|
+
readonly managed: true;
|
|
6245
|
+
readonly users?: never;
|
|
6246
|
+
readonly password?: never;
|
|
6247
|
+
}): Profile<"shadowsocks", true, SsmInbound>;
|
|
6248
|
+
declare function shadowsocks(input: ShadowsocksInput & MultiPassword & {
|
|
6249
|
+
readonly managed?: false;
|
|
6250
|
+
readonly users: Users;
|
|
6251
|
+
readonly password?: never;
|
|
6252
|
+
}): Profile<"shadowsocks", true, SsmInbound>;
|
|
6253
|
+
declare function shadowsocks(input: ShadowsocksInput & SharedPassword & {
|
|
6254
|
+
readonly managed?: false;
|
|
6255
|
+
readonly users?: never;
|
|
6256
|
+
readonly serverKey?: never;
|
|
6257
|
+
}): Profile<"shadowsocks", false>;
|
|
6258
|
+
declare function vless<const Transport extends TransportKind>(input: VlessInput & TransportSelection<Transport> & {
|
|
6259
|
+
readonly tls: RealityTls;
|
|
6260
|
+
}): Promise<VlessProfile<TransportSelection<Transport>>>;
|
|
6261
|
+
declare function vless<const Transport extends TransportKind>(input: VlessInput & TransportSelection<Transport> & {
|
|
6262
|
+
readonly tls?: NormalTls | NoTls;
|
|
6263
|
+
}): VlessProfile<TransportSelection<Transport>>;
|
|
6264
|
+
declare function vless<const Transport extends TransportKind>(input: VlessInput & TransportSelection<Transport>): VlessProfileResult<TransportSelection<Transport>>;
|
|
6265
|
+
declare function vless(input: VlessInput & {
|
|
6266
|
+
readonly tls: RealityTls;
|
|
6267
|
+
}): Promise<VlessProfile>;
|
|
6268
|
+
declare function vless(input: VlessInput & {
|
|
6269
|
+
readonly tls?: NormalTls | NoTls;
|
|
6270
|
+
}): VlessProfile;
|
|
6271
|
+
declare function vless(input: VlessInput): VlessProfileResult;
|
|
6272
|
+
export declare const proxyProfile: Readonly<{
|
|
6273
|
+
anytls: (input: RequiredTlsInput) => Profile<"anytls", true, unknown, unknown>;
|
|
6274
|
+
http: typeof http;
|
|
6275
|
+
hysteria: (input: HysteriaInput) => Profile<"hysteria", true, unknown, unknown>;
|
|
6276
|
+
hysteria2: (input: Hysteria2Input) => Profile<"hysteria2", true, unknown, unknown>;
|
|
6277
|
+
naive: (input: RequiredTlsInput<"naive">) => Profile<"naive", true, unknown, unknown>;
|
|
6278
|
+
shadowsocks: typeof shadowsocks;
|
|
6279
|
+
shadowtls: typeof shadowtls;
|
|
6280
|
+
snell: typeof snell;
|
|
6281
|
+
socks: typeof socks;
|
|
6282
|
+
trojan: {
|
|
6283
|
+
<const Transport extends TransportKind>(input: TransportInput<"trojan"> & TransportSelection<Transport>): Profile<"trojan", true, unknown, TransportSelection<Transport>>;
|
|
6284
|
+
(input: TransportInput<"trojan">): Profile<"trojan", true, unknown, unknown>;
|
|
6285
|
+
};
|
|
6286
|
+
tuic: (input: RequiredTlsInput) => Profile<"tuic", true, unknown, unknown>;
|
|
6287
|
+
vless: typeof vless;
|
|
6288
|
+
vmess: {
|
|
6289
|
+
<const Transport extends TransportKind>(input: TransportInput<"vmess"> & TransportSelection<Transport>): Profile<"vmess", true, unknown, TransportSelection<Transport>>;
|
|
6290
|
+
(input: TransportInput<"vmess">): Profile<"vmess", true, unknown, unknown>;
|
|
6291
|
+
};
|
|
6292
|
+
}>;
|
|
6293
|
+
declare function uuid(): string;
|
|
6294
|
+
declare function random(length: number): Uint8Array;
|
|
6295
|
+
declare function randomHex(length: number): string;
|
|
6296
|
+
declare function randomBase64(length: number): string;
|
|
6297
|
+
declare function randomBase64Url(length: number): string;
|
|
6298
|
+
declare function x25519PublicKey(privateKey: Uint8Array): Promise<Uint8Array>;
|
|
6299
|
+
declare function x25519KeyPair(): Promise<{
|
|
6300
|
+
privateKey: Uint8Array<ArrayBuffer>;
|
|
6301
|
+
publicKey: Uint8Array<ArrayBufferLike>;
|
|
6302
|
+
}>;
|
|
6303
|
+
declare function reality(): Promise<{
|
|
6304
|
+
privateKey: string;
|
|
6305
|
+
publicKey: string;
|
|
6306
|
+
}>;
|
|
6307
|
+
declare function wireguard(): Promise<{
|
|
6308
|
+
privateKey: string;
|
|
6309
|
+
publicKey: string;
|
|
6310
|
+
}>;
|
|
6311
|
+
declare function vapidKeyPair(): Promise<{
|
|
6312
|
+
privateKey: string;
|
|
6313
|
+
publicKey: string;
|
|
6314
|
+
}>;
|
|
6315
|
+
declare function tailcatKeyPair(): Promise<{
|
|
6316
|
+
privateKey: string;
|
|
6317
|
+
publicKey: string;
|
|
6318
|
+
discoKey: string;
|
|
6319
|
+
preSharedKey: string;
|
|
6320
|
+
address: string;
|
|
6321
|
+
}>;
|
|
6322
|
+
declare function echKeyPair(publicName: string): Promise<{
|
|
6323
|
+
config: string;
|
|
6324
|
+
key: string;
|
|
6325
|
+
}>;
|
|
6326
|
+
declare function tlsKeyPair(serverName: string, months?: number): Promise<{
|
|
6327
|
+
privateKey: string;
|
|
6328
|
+
certificate: string;
|
|
6329
|
+
}>;
|
|
6330
|
+
export declare const generate: {
|
|
6331
|
+
readonly uuid: typeof uuid;
|
|
6332
|
+
readonly random: typeof random;
|
|
6333
|
+
readonly randomHex: typeof randomHex;
|
|
6334
|
+
readonly randomBase64: typeof randomBase64;
|
|
6335
|
+
readonly randomBase64Url: typeof randomBase64Url;
|
|
6336
|
+
readonly x25519KeyPair: typeof x25519KeyPair;
|
|
6337
|
+
readonly x25519PublicKey: typeof x25519PublicKey;
|
|
6338
|
+
readonly reality: typeof reality;
|
|
6339
|
+
readonly wireguard: typeof wireguard;
|
|
6340
|
+
readonly vapidKeyPair: typeof vapidKeyPair;
|
|
6341
|
+
readonly tailcatKeyPair: typeof tailcatKeyPair;
|
|
6342
|
+
readonly echKeyPair: typeof echKeyPair;
|
|
6343
|
+
readonly tlsKeyPair: typeof tlsKeyPair;
|
|
6344
|
+
};
|
|
6345
|
+
export type { ClientTls, CompileInput, Condition, Dial, DirectDial, DnsRuleAction, DomainResolver, HeadlessRule, HttpClientInput, InboundListener, InlineHttpClient, Listener, MatchFields, RealityClientTls, RealityServerTls, RouteRuleAction, RuleAction, RuleValue, Scope, ServerTls, SingBoxConfig, User, UserCredentials };
|