UNPKG

@imgproxy/imgproxy-node

Version:

Official node url-builder lib for imgproxy - fast and secure standalone server for resizing and converting remote images

19 lines (18 loc) 696 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const crypto_1 = __importDefault(require("crypto")); const hexDecode = (hex) => Buffer.from(hex, "hex"); const sign = (target, signPair) => { const hmac = crypto_1.default.createHmac("sha256", hexDecode(signPair.key)); hmac.update(hexDecode(signPair.salt)); hmac.update(target); return hmac.digest("base64url"); }; const getSignedUrl = (path, pair) => { const signature = sign(path, pair); return `/${signature}${path}`; }; exports.default = getSignedUrl;