-
Notifications
You must be signed in to change notification settings - Fork 1
/
libecc-pre.js
30 lines (29 loc) · 1.12 KB
/
libecc-pre.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function randomValueSetup() {
if (Module.getRandomValue === undefined) {
try {
var window_ = 'object' === typeof window ? window : self;
var crypto_ = typeof window_.crypto !== 'undefined' ? window_.crypto : window_.msCrypto;
var randomValuesStandard = function () {
var buf = new Uint32Array(1);
crypto_.getRandomValues(buf);
return buf[0] >>> 0;
};
randomValuesStandard();
Module.getRandomValue = randomValuesStandard;
} catch (e) {
try {
import("crypto").then((crypto) => {
var randomValueNodeJS = function () {
var buf = crypto['randomBytes'](4);
return (buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3]) >>> 0;
};
randomValueNodeJS();
Module.getRandomValue = randomValueNodeJS;
});
} catch (e) {
throw 'No secure random number generator found';
}
}
}
}
randomValueSetup();