import type { AxiosInstance } from "axios"; interface GenerateAuthHeadersParams { apiKeyId: string; secretKey: string; method: string; path: string; body?: any; nonce?: string; isService?: boolean; } export type HmacAuthHeaders = { "x-levr-auth-type": string; Authorization: string; "x-request-timestamp": string; "x-request-nonce": string; }; /** * Service for generating and validating HMAC-based authentication headers. * * Provides methods to: * - Generate HMAC authentication headers for API requests * - Generate service-to-service authentication headers * - Attach Axios request interceptors for automatic request signing * * @remarks * This service must be initialized with `init()` before generating service auth headers, * which loads `SERVICE_API_KEY_ID` and `SERVICE_API_KEY_SECRET` from environment variables. * * @example * ```typescript * import { hmacService } from "./hmac.service" * * // Initialize service keys from environment * hmacService.init() * * // Generate auth headers manually * const headers = hmacService.generateAuthHeaders({ * apiKeyId: "my-api-key", * secretKey: "my-secret", * method: "POST", * path: "/api/endpoint", * body: { data: "example" } * }) * * // Or use with Axios interceptor * const client = axios.create({ baseURL: "https://api.example.com" }) * hmacService.attachInterceptor(client) * await client.post("/endpoint", { foo: "bar" }, { sign: true }) * ``` */ declare class HmacService { private initialized; private serviceApiKeyId?; private serviceSecretKey?; init(): void; generateAuthHeaders({ apiKeyId, secretKey, method, path, body, nonce, isService, }: GenerateAuthHeadersParams): HmacAuthHeaders; generateServiceAuthHeaders(params: Omit & Partial>): HmacAuthHeaders; /** * Attaches an Axios request interceptor that signs requests when config.sign === true * * Usage example: * * import axios from "axios" * import { hmacService } from "@levr/shared/src/server/services/hmac.service" * * On startup (loads SERVICE_API_KEY_ID and SERVICE_API_KEY_SECRET from env) * hmacService.init() * * Create axios client and attach the interceptor * const client = axios.create({ baseURL: "https://api.my-service.com" }) * hmacService.attachInterceptor(client) * * Make a signed request by setting `sign: true` * await client.post( * "/v1/some/endpoint", * { foo: "bar" }, * { sign: true } * ) */ attachInterceptor(client: AxiosInstance): void; } export declare const hmacService: HmacService; export {};