UNPKG

@openpass/openpass-js-sdk

Version:
22 lines 856 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hashSha256 = exports.generateRandomString = void 0; const cryptoApi = () => window.crypto || window.msCrypto; const cryptoSubtleApi = () => { const crypto = cryptoApi(); return crypto.subtle || crypto.webkitSubtle; }; const generateRandomString = (length = 43) => { const array = new Uint32Array(length); cryptoApi().getRandomValues(array); return Array.from(array, (item) => `0${item.toString(16)}`.slice(-2)).join(""); }; exports.generateRandomString = generateRandomString; const hashSha256 = async (value) => { const encoder = new TextEncoder(); const data = encoder.encode(value); const buffer = await cryptoSubtleApi().digest("SHA-256", data); return buffer; }; exports.hashSha256 = hashSha256; //# sourceMappingURL=crypto.js.map