refactor(api): use secure RNG, closes #1356 (#1398)

This commit is contained in:
Lucas Fernandes Nogueira
2021-03-30 00:26:40 -03:00
committed by GitHub
parent 4e9d31c70b
commit c8992bb0bf
4 changed files with 17 additions and 42 deletions

5
.changes/secure-rng.md Normal file
View File

@@ -0,0 +1,5 @@
---
"api": patch
---
Use secure RNG on callback function names.

View File

@@ -7,27 +7,12 @@ declare global {
}
}
function s4(): string {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1)
}
function uid(): string {
return (
s4() +
s4() +
'-' +
s4() +
'-' +
s4() +
'-' +
s4() +
'-' +
s4() +
s4() +
s4()
)
const length = new Int8Array(1)
window.crypto.getRandomValues(length)
const array = new Uint8Array(Math.max(16, Math.abs(length[0])))
window.crypto.getRandomValues(array)
return array.join('')
}
function transformCallback(

File diff suppressed because one or more lines are too long

View File

@@ -7,29 +7,14 @@ if (!String.prototype.startsWith) {
}
(function () {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
function uid() {
const length = new Int8Array(1)
window.crypto.getRandomValues(length)
const array = new Uint8Array(Math.max(16, Math.abs(length[0])))
window.crypto.getRandomValues(array)
return array.join('')
}
var uid = function () {
return (
s4() +
s4() +
"-" +
s4() +
"-" +
s4() +
"-" +
s4() +
"-" +
s4() +
s4() +
s4()
);
};
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {