wireguard.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { z } from 'zod';
  2. export const WireguardDomainStrategySchema = z.enum([
  3. 'ForceIP',
  4. 'ForceIPv4',
  5. 'ForceIPv4v6',
  6. 'ForceIPv6',
  7. 'ForceIPv6v4',
  8. ]);
  9. export type WireguardDomainStrategy = z.infer<typeof WireguardDomainStrategySchema>;
  10. // Outbound peer is the remote server we connect to: no privateKey, but an
  11. // `endpoint` (host:port) the inbound side does not need.
  12. export const WireguardOutboundPeerSchema = z.object({
  13. publicKey: z.string().min(1),
  14. preSharedKey: z.string().optional(),
  15. allowedIPs: z.array(z.string()).default(['0.0.0.0/0', '::/0']),
  16. endpoint: z.string().min(1),
  17. keepAlive: z.number().int().min(0).optional(),
  18. });
  19. export type WireguardOutboundPeer = z.infer<typeof WireguardOutboundPeerSchema>;
  20. // Wire format: address is a string[] (Xray expects an array even though the
  21. // panel UI stores it comma-joined); reserved is number[] (panel splits the
  22. // comma string and Number()-coerces each entry).
  23. export const WireguardOutboundSettingsSchema = z.object({
  24. mtu: z.number().int().min(1).optional(),
  25. secretKey: z.string().min(1),
  26. address: z.array(z.string()).default([]),
  27. workers: z.number().int().min(1).optional(),
  28. domainStrategy: WireguardDomainStrategySchema.optional(),
  29. reserved: z.array(z.number().int()).optional(),
  30. peers: z.array(WireguardOutboundPeerSchema).min(1),
  31. noKernelTun: z.boolean().default(false),
  32. });
  33. export type WireguardOutboundSettings = z.infer<typeof WireguardOutboundSettingsSchema>;