UNPKG

@tmawallet/sdk

Version:
29 lines 1.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.randomBytes = void 0; (function () { // Copied from tweetnacl, https://www.npmjs.com/package/tweetnacl // Initialize PRNG if environment provides CSPRNG. // If not, methods calling randombytes will throw. let baseCrypto = typeof self !== 'undefined' ? self.crypto || self.msCrypto : null; if (baseCrypto && typeof baseCrypto.getRandomValues === 'function') { const crypto = baseCrypto; // Browsers. const QUOTA = 65536; exports.randomBytes = (n) => { const v = new Uint8Array(n); for (let i = 0; i < n; i += QUOTA) { crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA))); } return v; }; } else if (typeof require !== 'undefined') { // Node.js. const crypto = require('crypto'); if (crypto && typeof crypto.randomBytes === 'function') { exports.randomBytes = (n) => crypto.randomBytes(n); } } })(); //# sourceMappingURL=randomBytes.js.map