'use strict'; var node_crypto = require('node:crypto'); const msToUnixTimestamp = (ms) => Math.floor(ms / 1000).toString(); const getSecureExpire = (options) => { if ('expire' in options) { return msToUnixTimestamp(new Date(options.expire).getTime()); } return msToUnixTimestamp(Date.now() + options.lifetime); }; /** * Generate a secure signature for signing the upload request to Uploadcare. * * @param secretKey - The secret key used to generate the signature. * @param options - Expiration options for the signature. * @see https://uploadcare.com/docs/security/secure-uploads/ */ const generateSecureSignature = (secret, options) => { const hmac = node_crypto.createHmac('sha256', secret); const secureExpire = getSecureExpire(options); hmac.update(secureExpire); const secureSignature = hmac.digest('hex'); return { secureSignature, secureExpire }; }; exports.generateSecureSignature = generateSecureSignature;