shadowsocks.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { z } from 'zod';
  2. export const SSMethodSchema = z.enum([
  3. 'aes-256-gcm',
  4. 'chacha20-poly1305',
  5. 'chacha20-ietf-poly1305',
  6. 'xchacha20-ietf-poly1305',
  7. '2022-blake3-aes-128-gcm',
  8. '2022-blake3-aes-256-gcm',
  9. '2022-blake3-chacha20-poly1305',
  10. ]);
  11. export type SSMethod = z.infer<typeof SSMethodSchema>;
  12. export const SSNetworkSchema = z.enum(['tcp', 'udp', 'tcp,udp']);
  13. export type SSNetwork = z.infer<typeof SSNetworkSchema>;
  14. // On a single-user shadowsocks inbound the client carries no method/password
  15. // of its own — the inbound-level method+password are authoritative. On a
  16. // 2022-blake3 multi-user setup each client provides its own password (and
  17. // optionally a per-client method).
  18. export const ShadowsocksClientSchema = z.object({
  19. method: z.string().default(''),
  20. password: z.string().default(''),
  21. email: z.string().min(1),
  22. limitIp: z.number().int().min(0).default(0),
  23. totalGB: z.number().int().min(0).default(0),
  24. expiryTime: z.number().int().default(0),
  25. enable: z.boolean().default(true),
  26. tgId: z.number().int().default(0),
  27. subId: z.string().default(''),
  28. comment: z.string().default(''),
  29. reset: z.number().int().min(0).default(0),
  30. created_at: z.number().int().optional(),
  31. updated_at: z.number().int().optional(),
  32. });
  33. export type ShadowsocksClient = z.infer<typeof ShadowsocksClientSchema>;
  34. export const ShadowsocksInboundSettingsSchema = z.object({
  35. method: SSMethodSchema.default('2022-blake3-aes-256-gcm'),
  36. password: z.string().default(''),
  37. network: SSNetworkSchema.default('tcp'),
  38. clients: z.array(ShadowsocksClientSchema).default([]),
  39. ivCheck: z.boolean().default(false),
  40. });
  41. export type ShadowsocksInboundSettings = z.infer<typeof ShadowsocksInboundSettingsSchema>;