2020-07-19 19:49:44 +02:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
|
|
|
((window) => {
|
2020-09-16 22:22:43 +02:00
|
|
|
const core = window.Deno.core;
|
2020-07-19 19:49:44 +02:00
|
|
|
function getRandomValues(typedArray) {
|
2020-11-14 02:31:57 +05:30
|
|
|
if (typedArray == null) throw new Error("Input must not be null");
|
|
|
|
if (typedArray.length > 65536) {
|
|
|
|
throw new Error("Input must not be longer than 65536");
|
|
|
|
}
|
2020-07-19 19:49:44 +02:00
|
|
|
const ui8 = new Uint8Array(
|
|
|
|
typedArray.buffer,
|
|
|
|
typedArray.byteOffset,
|
|
|
|
typedArray.byteLength,
|
|
|
|
);
|
2020-09-16 22:22:43 +02:00
|
|
|
core.jsonOpSync("op_get_random_values", {}, ui8);
|
2020-07-19 19:49:44 +02:00
|
|
|
return typedArray;
|
|
|
|
}
|
2020-11-14 02:31:57 +05:30
|
|
|
window.crypto = {
|
|
|
|
getRandomValues,
|
|
|
|
};
|
|
|
|
window.__bootstrap = window.__bootstrap || {};
|
2020-07-19 19:49:44 +02:00
|
|
|
window.__bootstrap.crypto = {
|
|
|
|
getRandomValues,
|
|
|
|
};
|
|
|
|
})(this);
|