@azure/eventgrid
Version:
An isomorphic client library for the Azure Event Grid service.
17 lines • 788 B
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/// <reference lib="dom"/>
/**
* @internal
*/
export async function sha256Hmac(secret, stringToSign) {
const key = await globalThis.crypto.subtle.importKey("raw", Uint8Array.from(atob(secret), (c) => c.charCodeAt(0)), {
name: "HMAC",
hash: "SHA-256",
}, false, ["sign"]);
const sigArray = await globalThis.crypto.subtle.sign("HMAC", key, new TextEncoder().encode(stringToSign));
// The conversions here are a bit odd but necessary (see "Unicode strings" in the link below)
// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/btoa
return btoa(String.fromCharCode(...new Uint8Array(sigArray)));
}
//# sourceMappingURL=cryptoHelpers-browser.mjs.map