one
Version:
One is a React framework for web, iOS, and Android apps.
76 lines (74 loc) • 2.56 kB
JavaScript
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 > 65536) {
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;
}
}
export { MAX_RANDOM_BYTES, fillRandomValues, formatUuidV4, installCryptoPolyfill };
//# sourceMappingURL=random.native.js.map