UNPKG

expo-crypto-universal-web

Version:

Web implementation of expo-crypto-universal

56 lines (55 loc) 1.53 kB
import { AbstractCryptoModule as s } from "expo-crypto-universal"; class o extends s { /** * Fills the provided Uint8Array with cryptographically strong random values. * @param array - The Uint8Array to fill with random values. * @returns The same Uint8Array, filled with random values. */ getRandomValues(t) { return crypto.getRandomValues(t); } /** * Computes the SHA-256 hash of the provided data. * @param data - The data to hash. * @returns A Promise that resolves to a Uint8Array containing the hash. */ async sha256Async(t) { return new Promise((r, n) => { crypto.subtle.digest("SHA-256", t).then( (e) => r(new Uint8Array(e)), (e) => n(e) ); }); } /** * Computes the SHA-384 hash of the provided data. * @param data - The data to hash. * @returns A Promise that resolves to a Uint8Array containing the hash. */ async sha384Async(t) { return new Promise((r, n) => { crypto.subtle.digest("SHA-384", t).then( (e) => r(new Uint8Array(e)), (e) => n(e) ); }); } /** * Computes the SHA-512 hash of the provided data. * @param data - The data to hash. * @returns A Promise that resolves to a Uint8Array containing the hash. */ async sha512Async(t) { return new Promise((r, n) => { crypto.subtle.digest("SHA-512", t).then( (e) => r(new Uint8Array(e)), (e) => n(e) ); }); } } const u = new o(); export { o as WebCryptoModule, u as webCryptoModule };