import type { ParsedNode } from './ss.js'; import { normalizeWsPath } from './util.js'; export function parseTrojan(uri: string): ParsedNode { const url = new URL(uri); const name = decodeURIComponent(url.hash.slice(1)); const server = url.hostname; const port = parseInt(url.port, 10); const password = url.username; const params = url.searchParams; const sni = params.get('sni') || server; let surgeLine = `${name} = trojan, ${server}, ${port}, password=${password}, tls=true, sni=${sni}, skip-cert-verify=false`; if (params.get('type') === 'ws') { const path = params.get('path') || '/'; const host = params.get('host') || sni; surgeLine += `, ws=true, ws-path=${normalizeWsPath(path)}, ws-headers=Host:${host}`; } return { name, type: 'trojan', server, port, surgeLine }; }