2020-07-19 13:49:44 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
|
|
|
((window) => {
|
2020-09-16 16:22:43 -04:00
|
|
|
const core = window.Deno.core;
|
2020-07-19 13:49:44 -04:00
|
|
|
function getRandomValues(typedArray) {
|
2020-11-13 16:01:57 -05:00
|
|
|
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 13:49:44 -04:00
|
|
|
const ui8 = new Uint8Array(
|
|
|
|
typedArray.buffer,
|
|
|
|
typedArray.byteOffset,
|
|
|
|
typedArray.byteLength,
|
|
|
|
);
|
2020-09-16 16:22:43 -04:00
|
|
|
core.jsonOpSync("op_get_random_values", {}, ui8);
|
2020-07-19 13:49:44 -04:00
|
|
|
return typedArray;
|
|
|
|
}
|
2020-11-13 16:01:57 -05:00
|
|
|
window.crypto = {
|
|
|
|
getRandomValues,
|
|
|
|
};
|
|
|
|
window.__bootstrap = window.__bootstrap || {};
|
2020-07-19 13:49:44 -04:00
|
|
|
window.__bootstrap.crypto = {
|
|
|
|
getRandomValues,
|
|
|
|
};
|
|
|
|
})(this);
|