From 00f6fa46b34b78e926a907ee24faec78a65eafc1 Mon Sep 17 00:00:00 2001 From: chiefbiiko Date: Fri, 17 May 2019 20:03:01 +0200 Subject: Add crypto.getRandomValues() (#2327) --- js/globals.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'js/globals.ts') diff --git a/js/globals.ts b/js/globals.ts index 765215661..c8289d305 100644 --- a/js/globals.ts +++ b/js/globals.ts @@ -10,6 +10,7 @@ import { window } from "./window"; import * as blob from "./blob"; import * as consoleTypes from "./console"; +import * as csprng from "./get_random_values"; import * as customEvent from "./custom_event"; import * as deno from "./deno"; import * as domTypes from "./dom_types"; @@ -69,6 +70,10 @@ window.console = console; window.setTimeout = timers.setTimeout; window.setInterval = timers.setInterval; window.location = (undefined as unknown) as domTypes.Location; +// The following Crypto interface implementation is not up to par with the +// standard https://www.w3.org/TR/WebCryptoAPI/#crypto-interface as it does not +// yet incorporate the SubtleCrypto interface as its "subtle" property. +window.crypto = (csprng as unknown) as Crypto; // When creating the runtime type library, we use modifications to `window` to // determine what is in the global namespace. When we put a class in the @@ -135,3 +140,19 @@ export interface ImportMeta { url: string; main: boolean; } + +export interface Crypto { + readonly subtle: null; + getRandomValues: < + T extends + | Int8Array + | Uint8Array + | Uint8ClampedArray + | Int16Array + | Uint16Array + | Int32Array + | Uint32Array + >( + typedArray: T + ) => T; +} -- cgit v1.2.3