replace Math.random with crypto random function

This commit is contained in:
David Christofas
2022-07-04 14:38:20 +02:00
parent 1cff5f36a5
commit cdd70d2800

View File

@@ -1,5 +1,16 @@
export function withClientRequestState(obj) {
obj.state = Math.random().toString(36).substring(7);
obj.state = generateState(16);
return obj;
}
function dec2hex (dec) {
return dec.toString(16).padStart(2, "0")
}
// generateState :: Integer -> String
function generateState (len) {
var arr = new Uint8Array((len || 16) / 2)
window.crypto.getRandomValues(arr)
return Array.from(arr, dec2hex).join('')
}