UNPKG

@scayle/storefront-core

Version:

Collection of essential utilities to work with the Storefront API

76 lines (75 loc) 2.65 kB
/** * Calculates the MD5 hash of a string. * Uses `CryptoJS` for MD5 calculation. Throws an error if MD5 support is omitted in the build. * * @see https://cryptojs.gitbook.io/docs/ * * @param value The string to hash. * * @returns A Promise that resolves with the MD5 hash as a hex string. * * @throws {Error} If SFC is built without MD5 support (SFC_OMIT_MD5 environment variable is set). */ export declare const md5: (value: string) => Promise<string>; /** * Calculates the SHA256 hash of a string. * * @param value The input string. * * @returns A Promise that resolves with the SHA256 hash as a hexadecimal string. */ export declare const sha256: (value: string) => Promise<string>; /** * Calculates the HMAC (Hash-based Message Authentication Code) of a string. * * @param value The input string (message). * @param secret The secret key. * @param algorithm The hashing algorithm to use (e.g., 'SHA-256'). Defaults to 'SHA-256'. * * @returns A Promise that resolves with the HMAC as a hexadecimal string. */ export declare const hmac: (value: string, secret: string, algorithm?: string) => Promise<string>; /** * Encodes a string to Base64. Works in both Node.js and browser environments. * * @param string The string to encode. * * @returns The Base64 encoded string. */ export declare const encodeBase64: (string: string) => string; /** * Decodes a Base64 encoded string. Works in both Node.js and browser environments. * * @param string The Base64 encoded string. * * @returns The decoded string. */ export declare const decodeBase64: (string: string) => string; /** * Verifies an order success token by comparing its signature with an expected signature. * * @template T The type of the parsed payload. * * @param token The token to verify. * @param secret The secret key used to generate the signature. * * @returns A Promise resolving to the parsed token payload if the signature is valid, or undefined otherwise. */ export declare const verifyOrderSuccessToken: <T = unknown>(token: string, secret: string) => Promise<T | undefined>; /** * Builds a hash payload by stringifying and Base64 encoding a given payload. * * @param payload The payload to hash. * * @returns The Base64 encoded hash payload. */ export declare const buildHashPayload: (payload: unknown) => string; /** * Builds a signature for a given payload hash and secret. * * @param payloadHash The hash of the payload. * @param secret The secret key. * * @returns A Promise resolving to the Base64 encoded signature. */ export declare const buildSignature: (payloadHash: string, secret: string) => Promise<string>;