1 |
|
2 |
|
3 | import { encodeUTF8, encodeBase64 } from "./encode";
|
4 | import atob from "./atob";
|
5 | import { globalCrypto } from "./globalCrypto";
|
6 | export 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 |
|
\ | No newline at end of file |