import { GeneratorOptions } from '@vonage/jwt'; import { AuthParams } from './types/AuthParams.js'; import { AuthQueryParams } from './types/AuthQueryParams.js'; import { AuthSignedParams } from './types/AuthSignedParams.js'; import { SignedHashParams } from './types/SignedHashParams.js'; import { AuthInterface } from './interfaces/AuthInterface.js'; import './enums/AlgroithmTypes.js'; /** * Authentication class used for generating Authentication headers and query parameters. * * @remarks * This client is only available as a standalone client. It cannot be * instantiated from the server-sdk package. * * @example * Create a standard authentication object. * * ```ts * import { Auth } from '@vonage/auth'; * * const auth = new Auth({ * apiKey: VONAGE_API_KEY, * apiSecret: VONAGE_API_SECRET, * applicationId: VONAGE_APPLICATION_ID, * privateKey: VONAGE_APPLICATION_PRIVATE_KEY_PATH, * }); * ``` */ declare class Auth implements AuthInterface { /** * @property {string} apiKey - The API key used for authentication. */ apiKey: string; /** * @property {string} apiSecret - The API secret used for authentication. */ apiSecret: string; /** * @property {string | null} [privateKey] - The private key used for JWT * authentication, either as a string or read from a file. */ privateKey?: string | Buffer | null; /** * @property {string | null} [applicationId] - The application ID used for * JWT authentication. */ applicationId?: string | null; /** * @property {SignedHashParams | null} [signature] - The signature parameters * used for signature authentication. */ signature?: SignedHashParams | null; /** * @property {GeneratorOptions} jwtOptions - Options used for generating JWTs. */ jwtOptions: GeneratorOptions; constructor(opts?: AuthParams); /** * Generates query parameters for authentication, optionally merging with * provided parameters. * * * @param {T} [params] - Additional parameters to merge with the * generated authentication query parameters. * * @return {Promise} - A promise that resolves * with the merged authentication query parameters. * * @throws {MissingApiKeyError} - Thrown when the API key is missing. * @throws {MissingApiSecretError} - Thrown when the API secret is missing. * @throws {InvalidApiKeyError} - Thrown when the API key is not a valid string. * @throws {InvalidApiSecretError} - Thrown when the API secret is not a valid string. * * @example * Generate query parameters * * ```ts * const queryParams = await auth.getQueryParams(); * ``` * * @example * Generate query parameters and merge with additional Parameters * * ```ts * const queryParams = await auth.getQueryParams({ * to: '15555555555', * from: '15555555556', * text: 'Hello from Vonage SMS API' * }); * ``` */ getQueryParams: (params?: AuthQueryParams & T) => Promise; /** * Generates a basic authentication header. * * @return {Promise} - A promise that resolves with the * generated basic authentication header. * * @throws {MissingApiKeyError} - Thrown when the API key is missing. * @throws {MissingApiSecretError} - Thrown when the API secret is missing. * @throws {InvalidApiKeyError} - Thrown when the API key is not a valid string. * @throws {InvalidApiSecretError} - Thrown when the API secret is not a valid string. * * @example * Generate a basic authentication headers * * ```ts * const basicAuthHeader = await auth.createBasicHeader(); * ``` */ createBasicHeader: () => Promise; /** * Generates a bearer authentication header. * * @return {Promise} - A promise that resolves with the * generated bearer authentication header. * * @example * Generate a bearer authentication headers * * ```ts * const bearerAuthHeader = await auth.createBearerHeader(); * ``` */ createBearerHeader: () => Promise; /** * Generates a signature hash for authentication, merging it with * provided parameters. * * @template T - Type of the parameters to merge with. * @param {T} params - Parameters to merge with the generated * signature hash. * @return {Promise} - A promise that resolves * with the merged signature hash and parameters. * * @throws {MissingApiKeyError} - Thrown when the API key is missing. * @throws {InvalidApiKeyError} - Thrown when the API key is not a valid string. * @throws {MissingSignatureError} - Thrown when the signature algorithm is missing. * @throws {MissingApiSecretError} - Thrown when the API secret is missing. * @throws {InvalidApiSecretError} - Thrown when the API secret is not a valid string. * @throws {InvalidSignatureAlgorithmError} - Thrown when an invalid signature algorithm is provided. * * @example * Generate a signature hash * * ```ts * const signatureHash = await auth.createSignatureHash({ * to: '15555555555', * from: '15555555556', * text: 'Hello from Vonage SMS API', * timestamp: '1516878400', * sig: 'a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6', * }); * ``` */ createSignatureHash: (params: AuthSignedParams & T) => Promise; } export { Auth };