/** * License Guard — 本地授权校验核心 * * 三道门禁: * 1. Boot Gate: Gateway 启动时校验签名+过期 * 2. Feature Gate: 运行时检查功能开关 * 3. Quota Gate: 运行时检查配额 (Token/消息数) * * 零 SaaS 依赖,全部本地完成。 */ import type { LicensePayload, LicenseFeatures, LicenseQuotas, LicenseValidation, LicensePlan } from './types.js'; /** * 对 payload 生成 HMAC-SHA256 签名 */ export declare function signPayload(payload: LicensePayload, secret: string): string; /** * 校验签名是否匹配 */ export declare function verifySignature(payload: LicensePayload, signature: string, secret: string): boolean; /** * 生成简单机器指纹: hostname + cpuModel + totalMem * 不追求绝对唯一,只是防止 license 直接拷贝到别的机器 */ export declare function getMachineId(): string; export declare class LicenseGuard { private licensePath; private secret; private license; private validation; private usageFile; private dailyMessages; private monthlyTokens; private lastResetDay; private lastResetMonth; constructor(licensePath: string, secret: string, usagePath?: string); /** * Gateway 启动时调用 — 读取 + 校验 License * @returns 校验结果,调用方根据 valid 决定是否继续启动 */ boot(): Promise; /** * 检查某个功能是否启用 */ isFeatureEnabled(feature: keyof LicenseFeatures): boolean; /** * 获取当前生效的套餐 */ getEffectivePlan(): LicensePlan; /** * 获取当前配额 */ getQuotas(): LicenseQuotas; /** * 检查是否可以发送消息 (日消息配额) */ canSendMessage(): { allowed: boolean; reason?: string; }; /** * 检查是否可以消耗 Token (月 Token 配额) */ canConsumeTokens(estimatedTokens: number): { allowed: boolean; reason?: string; }; /** * 记录消息发送 */ recordMessage(): void; /** * 记录 Token 消耗 */ recordTokens(tokens: number): void; /** * 获取用量摘要 */ getUsageSummary(): { dailyMessages: number; monthlyTokens: number; quotas: LicenseQuotas; }; private fail; private createFreeLicense; private resetCountersIfNeeded; private saveTimer; private saveUsageDebounced; private loadUsage; } //# sourceMappingURL=license-guard.d.ts.map