mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-29 15:50:28 +01:00
12 lines
314 B
TypeScript
12 lines
314 B
TypeScript
|
/* 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('');
|
||
|
}
|