UNPKG

542 BJavaScriptView Raw
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT license.
3import { encodeUTF8 } from "./encode";
4import { globalCrypto } from "./globalCrypto";
5export async function digest(str) {
6 const data = encodeUTF8(str);
7 const hash = await globalCrypto.subtle.digest("SHA-256", data);
8 return bufferToHex(hash);
9}
10function bufferToHex(buffer) {
11 return Array.prototype.map
12 .call(new Uint8Array(buffer), (item) => ("00" + item.toString(16)).slice(-2))
13 .join("");
14}
15//# sourceMappingURL=digest.browser.js.map
\No newline at end of file