/** * 根据时间和当前系统配置计算 token(存量 MD5 算法) * * @param accessKey 当前系统的唯一 key * @param timestamp 时间参数(可选,默认当前时间戳) * @returns 包含 sign(MD5 签名)和 timestamp 的对象 */ declare function createApiToken(accessKey: string, timestamp?: string | number): { sign: string; timestamp: string | number; }; /** 参与 v2 签名的请求上下文(客户端与服务端必须传入一致的值) */ export interface ApiSignPayload { method?: string; path?: string; body?: unknown; } /** v2 签名结果 */ export interface ApiTokenV2 { sign: string; timestamp: number; nonce: string; alg: 'hmac-sha256'; } /** 校验选项 */ export interface VerifyApiTokenOptions { /** 允许的时间偏差(毫秒),默认 5 分钟 */ windowMs?: number; /** 当前时间,便于测试注入 */ now?: number; } /** 稳定序列化:对象键排序,保证客户端/服务端 JSON 键顺序不同也能得到同一摘要 */ export declare function stableStringify(value: unknown): string; /** * 生成 HMAC-SHA256 签名。 * 摘要内容:timestamp.nonce.METHOD.path.稳定序列化的 body */ export declare function createApiTokenV2(accessKey: string, payload?: ApiSignPayload, timestamp?: number, nonce?: string): ApiTokenV2; /** 恒定时间比较两个 hex 字符串;长度不等、非 hex、空串一律返回 false 且不抛异常 */ export declare function timingSafeEqualHex(a: string, b: string): boolean; /** 校验 v2 签名(含时间窗校验,不含 nonce 去重;去重请用 createReplayGuard) */ export declare function verifyApiToken(accessKey: string, token: Partial | null | undefined, payload?: ApiSignPayload, options?: VerifyApiTokenOptions): boolean; /** 内存重放防护(单实例)。多实例部署时应换成共享缓存实现同一接口 */ export interface ReplayGuard { checkAndRemember(key: string, now?: number): boolean; size(): number; clear(): void; } export declare function createReplayGuard(options?: { windowMs?: number; max?: number; now?: number; }): ReplayGuard; declare const _default: { createApiToken: typeof createApiToken; createApiTokenV2: typeof createApiTokenV2; verifyApiToken: typeof verifyApiToken; timingSafeEqualHex: typeof timingSafeEqualHex; createReplayGuard: typeof createReplayGuard; stableStringify: typeof stableStringify; }; export default _default;