UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

103 lines (101 loc) • 3.51 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var random_exports = {}; __export(random_exports, { MAX_RANDOM_BYTES: () => MAX_RANDOM_BYTES, fillRandomValues: () => fillRandomValues, formatUuidV4: () => formatUuidV4, installCryptoPolyfill: () => installCryptoPolyfill }); module.exports = __toCommonJS(random_exports); var MAX_RANDOM_BYTES = 65536; var HEX_DIGITS = "0123456789abcdef"; function formatUuidV4(bytes) { if (bytes.length !== 16) { throw new RangeError(`randomUUID: expected 16 random bytes, got ${bytes.length}.`); } var versioned = bytes.slice(); versioned[6] = versioned[6] & 15 | 64; versioned[8] = versioned[8] & 63 | 128; var hex = function hex2(index) { return HEX_DIGITS[versioned[index] >> 4] + HEX_DIGITS[versioned[index] & 15]; }; return hex(0) + hex(1) + hex(2) + hex(3) + "-" + hex(4) + hex(5) + "-" + hex(6) + hex(7) + "-" + hex(8) + hex(9) + "-" + hex(10) + hex(11) + hex(12) + hex(13) + hex(14) + hex(15); } var INTEGER_ARRAY_TAGS = /* @__PURE__ */ new Set([ "[object Int8Array]", "[object Uint8Array]", "[object Uint8ClampedArray]", "[object Int16Array]", "[object Uint16Array]", "[object Int32Array]", "[object Uint32Array]", "[object BigInt64Array]", "[object BigUint64Array]" ]); function quotaExceededError() { var error = new Error(`crypto.getRandomValues: byteLength exceeds ${MAX_RANDOM_BYTES}.`); error.name = "QuotaExceededError"; return error; } function fillRandomValues(view, source) { if (!INTEGER_ARRAY_TAGS.has(Object.prototype.toString.call(view))) { throw new TypeError(`crypto.getRandomValues: expected an integer TypedArray, got ${Object.prototype.toString.call(view)}.`); } if (view.byteLength > MAX_RANDOM_BYTES) { throw quotaExceededError(); } if (view.byteLength === 0) { return view; } if (!(view.buffer instanceof ArrayBuffer)) { throw new TypeError("crypto.getRandomValues: shared memory is not supported."); } source.fill(new Uint8Array(view.buffer, view.byteOffset, view.byteLength)); return view; } function installCryptoPolyfill(source) { var target = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : globalThis; var existing = target.crypto; if (existing != null && typeof existing.getRandomValues === "function" && typeof existing.randomUUID === "function") { return; } var getRandomValues = function getRandomValues2(view) { return fillRandomValues(view, source); }; var randomUUID = function randomUUID2() { return source.randomUUID(); }; if (existing == null) { target.crypto = { getRandomValues, randomUUID }; return; } if (typeof existing.getRandomValues !== "function") { existing.getRandomValues = getRandomValues; } if (typeof existing.randomUUID !== "function") { existing.randomUUID = randomUUID; } }