UNPKG

@zebec-network/core-utils

Version:
18 lines (17 loc) 748 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hashSHA256 = hashSHA256; exports.hashSHA256ToBuffer = hashSHA256ToBuffer; async function hashSHA256(input) { const utf8 = new TextEncoder().encode(input); const hashBuffer = await crypto.subtle.digest("SHA-256", utf8); const hashArray = Array.from(new Uint8Array(hashBuffer)); const hashHex = hashArray.map((bytes) => bytes.toString(16).padStart(2, "0")).join(""); return hashHex; } async function hashSHA256ToBuffer(input) { const utf8 = new TextEncoder().encode(input); const hashArrayBuffer = await crypto.subtle.digest("SHA-256", utf8); const hashBuffer = Buffer.from(new Uint8Array(hashArrayBuffer)); return hashBuffer; }