@digitalcredentials/sha256-universal
Version:
A minimal Typescript SHA-256 digest library for Node.js, browsers, and React Native.
23 lines (22 loc) • 710 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.sha256digest = void 0;
/*
* Copyright (c) 2022 Digital Credentials Consortium.
*/
const isomorphic_webcrypto_1 = require("isomorphic-webcrypto");
require("fast-text-encoding");
/**
* Hashes a string of data using SHA-256.
*
* @param {string|Uint8Array} data - Data to hash.
*
* @return {Promise<Uint8Array>} the hash digest.
*/
async function sha256digest(data) {
const bytes = typeof data === 'string' ? new TextEncoder().encode(data) : data;
return new Uint8Array(
// @ts-ignore
await isomorphic_webcrypto_1.default.subtle.digest({ name: 'SHA-256' }, bytes));
}
exports.sha256digest = sha256digest;