UNPKG

@imgproxy/imgproxy-node

Version:

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

14 lines (13 loc) 443 B
import crypto from "crypto"; const hexDecode = (hex) => Buffer.from(hex, "hex"); const sign = (target, signPair) => { const hmac = crypto.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}`; }; export default getSignedUrl;