magento2-api-wrapper
Version:
Minimal Magento 2 API library. Both node and browser compatible
17 lines (16 loc) • 708 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createHmacHasher = void 0;
function createHmacHasher(hash) {
return async function hmacHasher(key, content) {
// encoder to convert string to Uint8Array
const enc = new TextEncoder();
const algo = { name: "HMAC", hash };
const cryptKey = await crypto.subtle.importKey("raw", enc.encode(key), algo, false, ["sign", "verify"]);
const signature = await crypto.subtle.sign(algo, cryptKey, enc.encode(content));
const b = new Uint8Array(signature);
// base64 digest
return btoa(String.fromCharCode(...b));
};
}
exports.createHmacHasher = createHmacHasher;