@mybucks.online/core 2.2.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/random.js +12 -1
package/package.json
CHANGED
package/src/random.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { randomInt } from "crypto";
|
|
2
1
|
import zxcvbn from "zxcvbn";
|
|
3
2
|
import {
|
|
4
3
|
PASSPHRASE_MIN_ZXCVBN_SCORE,
|
|
@@ -10,6 +9,18 @@ const LOWER = "abcdefghijklmnopqrstuvwxyz";
|
|
|
10
9
|
const DIGITS = "0123456789";
|
|
11
10
|
const SYMBOLS = "`~!@#$%^&*()-_+={}[]\\|:;\"'<>,.?/";
|
|
12
11
|
|
|
12
|
+
function randomInt(max) {
|
|
13
|
+
if (max > 255) {
|
|
14
|
+
throw new RangeError(`max must be <= 255, got ${max}`);
|
|
15
|
+
}
|
|
16
|
+
const arr = new Uint8Array(1);
|
|
17
|
+
const limit = 256 - (256 % max);
|
|
18
|
+
do {
|
|
19
|
+
globalThis.crypto.getRandomValues(arr);
|
|
20
|
+
} while (arr[0] >= limit);
|
|
21
|
+
return arr[0] % max;
|
|
22
|
+
}
|
|
23
|
+
|
|
13
24
|
function randomChar(charset) {
|
|
14
25
|
return charset[randomInt(charset.length)];
|
|
15
26
|
}
|