Files
proxy-station/shared/src/protocols.ts
YANG JIANKUAN a5d980a5e9 feat: 添加 WireGuard 设备管理并完善客户端分流
实现独立加密设备身份、网关 agent、持久生命周期任务和 Surge/FlClash 专属订阅凭证。

完善 Shadowrocket 规则转换与 Clash AI DNS,增加 Surge FFSB 适配、规则快照、运维工具及验收文档。
2026-11-02 22:44:23 +08:00

57 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export const PROTOCOLS = ['vmess', 'trojan', 'shadowsocks', 'hysteria2'] as const;
export type Protocol = (typeof PROTOCOLS)[number];
export const CLIENTS = ['surge', 'shadowrocket', 'clash'] as const;
export type ClientType = (typeof CLIENTS)[number];
export const CLIENT_LABELS: Record<ClientType, string> = {
surge: 'Surge (macOS)',
shadowrocket: 'ShadowRocket (iOS)',
clash: 'FlClash',
};
export type Egress = 'direct' | 'warp' | 'unknown';
/** Surge 与 Clash 使用 IETF 命名,Xray 分享链接使用简名 */
export const SS_CIPHER_ALIASES: Record<string, string> = {
'chacha20-poly1305': 'chacha20-ietf-poly1305',
'xchacha20-poly1305': 'xchacha20-ietf-poly1305',
};
export function normalizeSsCipher(method: string): string {
return SS_CIPHER_ALIASES[method] ?? method;
}
export interface NodeCapabilityInput {
protocol: Protocol;
network: 'tcp' | 'ws';
alterId?: number;
security?: string;
}
export interface CapabilityVerdict {
ok: boolean;
reason?: string;
}
/**
* 客户端能力矩阵:不支持的组合在下发订阅时自动屏蔽。
* Surge 的 ss 类型没有 WebSocket 传输(仅 simple-obfs),SS over WS 线路必须排除。
*/
export function clientSupports(client: ClientType, node: NodeCapabilityInput): CapabilityVerdict {
if (client === 'surge' && node.protocol === 'shadowsocks' && node.network === 'ws') {
return { ok: false, reason: 'Surge 不支持 Shadowsocks over WebSocket' };
}
if (client === 'surge' && node.protocol === 'vmess') {
if ((node.alterId ?? 0) !== 0) return { ok: false, reason: 'Surge 下发仅支持 alterId=0 的 VMess AEAD 节点' };
if (!['auto', 'aes-128-gcm', 'chacha20-poly1305', 'chacha20-ietf-poly1305'].includes(node.security ?? 'auto')) {
return { ok: false, reason: `Surge 不支持该 VMess 加密方式:${node.security}` };
}
}
if (client === 'clash' && node.protocol === 'vmess'
&& !['auto', 'none', 'zero', 'aes-128-gcm', 'chacha20-poly1305', 'chacha20-ietf-poly1305'].includes(node.security ?? 'auto')) {
return { ok: false, reason: `Clash 不支持该 VMess 加密方式:${node.security}` };
}
return { ok: true };
}