get-random-values 3.0.0 → 4.1.0
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/CHANGELOG.md +16 -0
- package/LICENSE.txt +1 -1
- package/README.md +3 -3
- package/index.d.ts +2 -2
- package/index.js +21 -15
- package/package.json +15 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## [4.1.0](https://github.com/kenany/get-random-values/compare/4.0.0...4.1.0) (2025-10-15)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* replace global with window-or-global ([47cb6eb](https://github.com/kenany/get-random-values/commit/47cb6eb517d725248791867661865416e177eec7))
|
|
6
|
+
|
|
7
|
+
## [4.0.0](https://github.com/kenany/get-random-values/compare/3.0.0...4.0.0) (2025-08-13)
|
|
8
|
+
|
|
9
|
+
### ⚠ BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* Node.js v18 is no longer supported.
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* drop Node.js v18 support ([ddef386](https://github.com/kenany/get-random-values/commit/ddef386fc0bc842f1e6eed6beac8dea6947f3655))
|
|
16
|
+
|
|
1
17
|
## [3.0.0](https://github.com/kenany/get-random-values/compare/2.1.0...3.0.0) (2023-09-21)
|
|
2
18
|
|
|
3
19
|
|
package/LICENSE.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2014–
|
|
1
|
+
Copyright 2014–2025 Kenan Yildirim <https://kenany.me/>
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
4
4
|
this software and associated documentation files (the "Software"), to deal in
|
package/README.md
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
## Example
|
|
7
7
|
|
|
8
8
|
``` javascript
|
|
9
|
-
|
|
9
|
+
const getRandomValues = require('get-random-values');
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
const array = new Uint32Array(10);
|
|
12
12
|
getRandomValues(array);
|
|
13
13
|
// => [
|
|
14
14
|
// => 183,
|
|
@@ -33,7 +33,7 @@ $ npm install get-random-values
|
|
|
33
33
|
## API
|
|
34
34
|
|
|
35
35
|
``` javascript
|
|
36
|
-
|
|
36
|
+
const getRandomValues = require('get-random-values');
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
### `getRandomValues(buf)`
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export = getRandomValues;
|
|
2
2
|
/**
|
|
3
|
-
* @template {ArrayBufferView
|
|
3
|
+
* @template {ArrayBufferView<ArrayBufferLike>} T
|
|
4
4
|
* @param {T} buf
|
|
5
5
|
* @returns {T}
|
|
6
6
|
*/
|
|
7
|
-
declare function getRandomValues<T extends ArrayBufferView
|
|
7
|
+
declare function getRandomValues<T extends ArrayBufferView<ArrayBufferLike>>(buf: T): T;
|
package/index.js
CHANGED
|
@@ -1,41 +1,47 @@
|
|
|
1
|
-
|
|
1
|
+
const nodeCrypto = require('node:crypto');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
var nodeCrypto = require('crypto');
|
|
3
|
+
const window = require('window-or-global');
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
|
-
* @template {ArrayBufferView
|
|
6
|
+
* @template {ArrayBufferView<ArrayBufferLike>} T
|
|
8
7
|
* @param {T} buf
|
|
9
8
|
* @returns {T}
|
|
10
9
|
*/
|
|
11
10
|
function getRandomValues(buf) {
|
|
12
|
-
if (window.crypto
|
|
11
|
+
if (window.crypto?.getRandomValues) {
|
|
13
12
|
return window.crypto.getRandomValues(buf);
|
|
14
13
|
}
|
|
15
|
-
|
|
14
|
+
|
|
15
|
+
if (
|
|
16
|
+
typeof window.msCrypto === 'object' &&
|
|
17
|
+
typeof window.msCrypto.getRandomValues === 'function'
|
|
18
|
+
) {
|
|
16
19
|
return window.msCrypto.getRandomValues(buf);
|
|
17
20
|
}
|
|
21
|
+
|
|
18
22
|
if (nodeCrypto.randomBytes) {
|
|
19
23
|
if (!(buf instanceof Uint8Array)) {
|
|
20
24
|
throw new TypeError('expected Uint8Array');
|
|
21
25
|
}
|
|
22
|
-
if (buf.length >
|
|
23
|
-
|
|
26
|
+
if (buf.length > 65_536) {
|
|
27
|
+
const e = new Error(
|
|
28
|
+
"Failed to execute 'getRandomValues' on 'Crypto': The " +
|
|
29
|
+
"ArrayBufferView's byte length (" +
|
|
30
|
+
buf.length +
|
|
31
|
+
') exceeds the ' +
|
|
32
|
+
'number of bytes of entropy available via this API (65536).'
|
|
33
|
+
);
|
|
24
34
|
// @ts-expect-error
|
|
25
35
|
e.code = 22;
|
|
26
|
-
e.message = 'Failed to execute \'getRandomValues\' on \'Crypto\': The ' +
|
|
27
|
-
'ArrayBufferView\'s byte length (' + buf.length + ') exceeds the ' +
|
|
28
|
-
'number of bytes of entropy available via this API (65536).';
|
|
29
36
|
e.name = 'QuotaExceededError';
|
|
30
37
|
throw e;
|
|
31
38
|
}
|
|
32
|
-
|
|
39
|
+
const bytes = nodeCrypto.randomBytes(buf.length);
|
|
33
40
|
buf.set(bytes);
|
|
34
41
|
return buf;
|
|
35
42
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
43
|
+
|
|
44
|
+
throw new Error('No secure random number generator available.');
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
module.exports = getRandomValues;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "get-random-values",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "`window.crypto.getRandomValues` with fallback to Node.js crypto",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"crypto"
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"test": "test"
|
|
21
21
|
},
|
|
22
22
|
"engines": {
|
|
23
|
-
"node": "
|
|
23
|
+
"node": "20 || 22 || >=24"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"clean": "rimraf --glob test/**/*.d.ts *.d.ts",
|
|
27
|
-
"lint": "
|
|
27
|
+
"lint": "biome check .",
|
|
28
28
|
"release": "semantic-release",
|
|
29
29
|
"type-coverage": "type-coverage --at-least 100 --detail --strict",
|
|
30
30
|
"prebuild": "npm run clean",
|
|
@@ -35,24 +35,24 @@
|
|
|
35
35
|
"prepack": "npm run build"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"global": "^
|
|
38
|
+
"window-or-global": "^1.0.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@
|
|
41
|
+
"@biomejs/biome": "2.2.5",
|
|
42
|
+
"@kenan/biome-config": "1.0.4",
|
|
42
43
|
"@semantic-release/changelog": "^6.0.3",
|
|
43
44
|
"@semantic-release/git": "^10.0.1",
|
|
44
|
-
"@tsconfig/
|
|
45
|
-
"@types/lodash.isfunction": "^3.0.
|
|
46
|
-
"@types/tape": "^5.
|
|
47
|
-
"conventional-changelog-conventionalcommits": "^
|
|
48
|
-
"eslint": "^8.49.0",
|
|
45
|
+
"@tsconfig/node20": "20.1.6",
|
|
46
|
+
"@types/lodash.isfunction": "^3.0.9",
|
|
47
|
+
"@types/tape": "^5.8.1",
|
|
48
|
+
"conventional-changelog-conventionalcommits": "^9.1.0",
|
|
49
49
|
"is-browser": "^2.1.0",
|
|
50
50
|
"lodash.isfunction": "^3.0.9",
|
|
51
|
-
"rimraf": "^
|
|
52
|
-
"semantic-release": "^
|
|
53
|
-
"tape": "^5.
|
|
54
|
-
"type-coverage": "^2.
|
|
55
|
-
"typescript": "
|
|
51
|
+
"rimraf": "^6.0.1",
|
|
52
|
+
"semantic-release": "^24.2.9",
|
|
53
|
+
"tape": "^5.9.0",
|
|
54
|
+
"type-coverage": "^2.29.7",
|
|
55
|
+
"typescript": "5.9.3"
|
|
56
56
|
},
|
|
57
57
|
"browser": {
|
|
58
58
|
"crypto": false
|