idmint 1.0.2 → 1.0.3
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/dist/index.js +4 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,20 +4,13 @@
|
|
|
4
4
|
*/
|
|
5
5
|
const ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_";
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
* - Browser: crypto.getRandomValues
|
|
9
|
-
* - Node.js: require("crypto").randomBytes
|
|
7
|
+
* Secure random bytes (Browser + Node 16+)
|
|
10
8
|
*/
|
|
11
9
|
function getRandomBytes(size) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
globalThis.crypto.getRandomValues) {
|
|
15
|
-
return globalThis.crypto.getRandomValues(new Uint8Array(size));
|
|
10
|
+
if (!globalThis.crypto || !globalThis.crypto.getRandomValues) {
|
|
11
|
+
throw new Error("Secure crypto API not available. This environment is not supported.");
|
|
16
12
|
}
|
|
17
|
-
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
19
|
-
const { randomBytes } = require("crypto");
|
|
20
|
-
return randomBytes(size);
|
|
13
|
+
return globalThis.crypto.getRandomValues(new Uint8Array(size));
|
|
21
14
|
}
|
|
22
15
|
/**
|
|
23
16
|
* Generate a secure unique ID
|