Math.random change to cryptoObj.getRandomValues (#8)

This commit is contained in:
elaco 2019-11-03 17:20:38 +02:00 коммит произвёл GitHub
Родитель 14576ee0d1
Коммит 0f2f8f8f3a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 14 добавлений и 2 удалений

Просмотреть файл

@ -1,6 +1,6 @@
{ {
"name": "window-post-message-proxy", "name": "window-post-message-proxy",
"version": "0.2.5", "version": "0.2.6",
"description": "A library used in place of the native window.postMessage which when used on both the sending and receiving windows allow for a nicer asynchronouse promise messaging between the windows", "description": "A library used in place of the native window.postMessage which when used on both the sending and receiving windows allow for a nicer asynchronouse promise messaging between the windows",
"main": "dist/windowPostMessageProxy.js", "main": "dist/windowPostMessageProxy.js",
"typings": "dist/windowPostMessageProxy.d.ts", "typings": "dist/windowPostMessageProxy.d.ts",

Просмотреть файл

@ -1,3 +1,9 @@
declare global {
interface Window {
msCrypto: Crypto;
}
}
interface IDeferred { interface IDeferred {
resolve: <T>(value?: T | Promise<T>) => void; resolve: <T>(value?: T | Promise<T>) => void;
reject: <T>(error: T) => void; reject: <T>(error: T) => void;
@ -85,7 +91,13 @@ export class WindowPostMessageProxy {
* Utility to generate random sequence of characters used as tracking id for promises. * Utility to generate random sequence of characters used as tracking id for promises.
*/ */
private static createRandomString(): string { private static createRandomString(): string {
return (Math.random() + 1).toString(36).substring(7);
// window.msCrypto for IE
var cryptoObj = window.crypto || window.msCrypto;
var randomValueArray = new Uint32Array(1);
cryptoObj.getRandomValues(randomValueArray);
return randomValueArray[0].toString(36).substring(1);
} }
// Private // Private