1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-25 03:20:23 +01:00
metamask-extension/shared/modules/hash.utils.ts

12 lines
314 B
TypeScript
Raw Normal View History

/* eslint-disable no-undef */
export async function sha256(str: string): Promise<string> {
const buf = await crypto.subtle.digest(
'SHA-256',
new TextEncoder().encode(str),
);
return Array.prototype.map
.call(new Uint8Array(buf), (x: number) => `00${x.toString(16)}`.slice(-2))
.join('');
}