UNPKG

773 BJavaScriptView Raw
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT license.
3import { encodeUTF8, encodeBase64 } from "./encode";
4import atob from "./atob";
5import { globalCrypto } from "./globalCrypto";
6export async function hmac(key, message) {
7 const importParams = { name: "HMAC", hash: { name: "SHA-256" } };
8 const encodedMessage = new Uint8Array([...unescape(encodeURIComponent(message))].map((c) => c.charCodeAt(0)));
9 const encodedKey = encodeUTF8(atob(key));
10 const cryptoKey = await globalCrypto.subtle.importKey("raw", encodedKey, importParams, false, [
11 "sign",
12 ]);
13 const signature = await globalCrypto.subtle.sign(importParams, cryptoKey, encodedMessage);
14 return encodeBase64(signature);
15}
16//# sourceMappingURL=hmac.browser.js.map
\No newline at end of file