@pezkuwi/x-randomvalues 14.0.23 → 14.0.25
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/cjs/packageInfo.js +1 -1
- package/package.json +17 -59
- package/packageInfo.js +1 -1
- package/build/browser.d.ts +0 -3
- package/build/fallback.d.ts +0 -1
- package/build/node.d.ts +0 -3
- package/build/packageInfo.d.ts +0 -6
- package/build/react-native.d.ts +0 -12
- package/build/shim.d.ts +0 -1
- package/build-deno/README.md +0 -3
- package/build-deno/browser.ts +0 -10
- package/build-deno/fallback.ts +0 -22
- package/build-deno/mod.ts +0 -2
- package/build-deno/node.ts +0 -12
- package/build-deno/packageInfo.ts +0 -3
- package/build-deno/react-native.ts +0 -64
- package/build-deno/shim.ts +0 -7
- package/build-tsc/browser.d.ts +0 -3
- package/build-tsc/fallback.d.ts +0 -1
- package/build-tsc/node.d.ts +0 -3
- package/build-tsc/packageInfo.d.ts +0 -6
- package/build-tsc/react-native.d.ts +0 -12
- package/build-tsc/shim.d.ts +0 -1
- package/build-tsc-cjs/browser.js +0 -15
- package/build-tsc-cjs/fallback.js +0 -24
- package/build-tsc-cjs/node.js +0 -18
- package/build-tsc-cjs/packageInfo.js +0 -7
- package/build-tsc-cjs/react-native.js +0 -42
- package/build-tsc-cjs/shim.js +0 -7
- package/build-tsc-esm/browser.js +0 -10
- package/build-tsc-esm/fallback.js +0 -21
- package/build-tsc-esm/node.js +0 -12
- package/build-tsc-esm/packageInfo.js +0 -4
- package/build-tsc-esm/react-native.js +0 -38
- package/build-tsc-esm/shim.js +0 -5
- package/src/browser.ts +0 -14
- package/src/fallback.spec.ts +0 -22
- package/src/fallback.ts +0 -28
- package/src/mod.ts +0 -4
- package/src/node.ts +0 -17
- package/src/packageInfo.ts +0 -6
- package/src/react-native.ts +0 -64
- package/src/shim.ts +0 -7
- package/tsconfig.build.json +0 -15
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.spec.json +0 -17
- package/tsconfig.spec.tsbuildinfo +0 -1
package/cjs/packageInfo.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.packageInfo = void 0;
|
|
4
|
-
exports.packageInfo = { name: '@pezkuwi/x-randomvalues', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '14.0.
|
|
4
|
+
exports.packageInfo = { name: '@pezkuwi/x-randomvalues', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '14.0.23' };
|
package/package.json
CHANGED
|
@@ -15,57 +15,20 @@
|
|
|
15
15
|
},
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"type": "module",
|
|
18
|
-
"
|
|
19
|
-
"version": "14.0.23",
|
|
20
|
-
"browser": "./cjs/browser.js",
|
|
18
|
+
"version": "14.0.25",
|
|
21
19
|
"main": "./cjs/node.js",
|
|
22
|
-
"module": "./node.js",
|
|
20
|
+
"module": "./cjs/node.js",
|
|
21
|
+
"browser": "./cjs/browser.js",
|
|
23
22
|
"react-native": "./cjs/react-native.js",
|
|
23
|
+
"types": "./cjs/node.d.ts",
|
|
24
24
|
"exports": {
|
|
25
|
+
"./cjs/package.json": "./cjs/package.json",
|
|
26
|
+
"./cjs/*": "./cjs/*.js",
|
|
25
27
|
".": {
|
|
26
|
-
"types": "./node.d.ts",
|
|
27
|
-
"react-native":
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"default": "./react-native.js"
|
|
31
|
-
},
|
|
32
|
-
"require": {
|
|
33
|
-
"types": "./cjs/react-native.d.ts",
|
|
34
|
-
"default": "./cjs/react-native.js"
|
|
35
|
-
},
|
|
36
|
-
"default": {
|
|
37
|
-
"types": "./react-native.d.ts",
|
|
38
|
-
"default": "./react-native.js"
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
"browser": {
|
|
42
|
-
"module": {
|
|
43
|
-
"types": "./browser.d.ts",
|
|
44
|
-
"default": "./browser.js"
|
|
45
|
-
},
|
|
46
|
-
"require": {
|
|
47
|
-
"types": "./cjs/browser.d.ts",
|
|
48
|
-
"default": "./cjs/browser.js"
|
|
49
|
-
},
|
|
50
|
-
"default": {
|
|
51
|
-
"types": "./browser.d.ts",
|
|
52
|
-
"default": "./browser.js"
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
"node": {
|
|
56
|
-
"module": {
|
|
57
|
-
"types": "./node.d.ts",
|
|
58
|
-
"default": "./node.js"
|
|
59
|
-
},
|
|
60
|
-
"require": {
|
|
61
|
-
"types": "./cjs/node.d.ts",
|
|
62
|
-
"default": "./cjs/node.js"
|
|
63
|
-
},
|
|
64
|
-
"default": {
|
|
65
|
-
"types": "./node.d.ts",
|
|
66
|
-
"default": "./node.js"
|
|
67
|
-
}
|
|
68
|
-
}
|
|
28
|
+
"types": "./cjs/node.d.ts",
|
|
29
|
+
"react-native": "./cjs/react-native.js",
|
|
30
|
+
"browser": "./cjs/browser.js",
|
|
31
|
+
"node": "./cjs/node.js"
|
|
69
32
|
},
|
|
70
33
|
"./browser": {
|
|
71
34
|
"module": {
|
|
@@ -81,8 +44,6 @@
|
|
|
81
44
|
"default": "./browser.js"
|
|
82
45
|
}
|
|
83
46
|
},
|
|
84
|
-
"./cjs/*": "./cjs/*.js",
|
|
85
|
-
"./cjs/package.json": "./cjs/package.json",
|
|
86
47
|
"./fallback": {
|
|
87
48
|
"module": {
|
|
88
49
|
"types": "./fallback.d.ts",
|
|
@@ -115,7 +76,7 @@
|
|
|
115
76
|
"require": "./cjs/package.json",
|
|
116
77
|
"default": "./package.json"
|
|
117
78
|
},
|
|
118
|
-
"./packageInfo": {
|
|
79
|
+
"./packageInfo.js": {
|
|
119
80
|
"module": {
|
|
120
81
|
"types": "./packageInfo.d.ts",
|
|
121
82
|
"default": "./packageInfo.js"
|
|
@@ -129,7 +90,7 @@
|
|
|
129
90
|
"default": "./packageInfo.js"
|
|
130
91
|
}
|
|
131
92
|
},
|
|
132
|
-
"./packageInfo
|
|
93
|
+
"./packageInfo": {
|
|
133
94
|
"module": {
|
|
134
95
|
"types": "./packageInfo.d.ts",
|
|
135
96
|
"default": "./packageInfo.js"
|
|
@@ -157,7 +118,7 @@
|
|
|
157
118
|
"default": "./react-native.js"
|
|
158
119
|
}
|
|
159
120
|
},
|
|
160
|
-
"./shim": {
|
|
121
|
+
"./shim.js": {
|
|
161
122
|
"module": {
|
|
162
123
|
"types": "./shim.d.ts",
|
|
163
124
|
"default": "./shim.js"
|
|
@@ -171,7 +132,7 @@
|
|
|
171
132
|
"default": "./shim.js"
|
|
172
133
|
}
|
|
173
134
|
},
|
|
174
|
-
"./shim
|
|
135
|
+
"./shim": {
|
|
175
136
|
"module": {
|
|
176
137
|
"types": "./shim.d.ts",
|
|
177
138
|
"default": "./shim.js"
|
|
@@ -187,14 +148,11 @@
|
|
|
187
148
|
}
|
|
188
149
|
},
|
|
189
150
|
"dependencies": {
|
|
190
|
-
"@pezkuwi/x-global": "14.0.
|
|
151
|
+
"@pezkuwi/x-global": "14.0.25",
|
|
191
152
|
"tslib": "^2.8.0"
|
|
192
153
|
},
|
|
193
|
-
"devDependencies": {
|
|
194
|
-
"@types/react-native": "^0.73.0"
|
|
195
|
-
},
|
|
196
154
|
"peerDependencies": {
|
|
197
|
-
"@pezkuwi/util": "14.0.
|
|
198
|
-
"@pezkuwi/wasm-util": "
|
|
155
|
+
"@pezkuwi/util": "14.0.25",
|
|
156
|
+
"@pezkuwi/wasm-util": "7.5.17"
|
|
199
157
|
}
|
|
200
158
|
}
|
package/packageInfo.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const packageInfo = { name: '@pezkuwi/x-randomvalues', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '14.0.
|
|
1
|
+
export const packageInfo = { name: '@pezkuwi/x-randomvalues', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '14.0.23' };
|
package/build/browser.d.ts
DELETED
package/build/fallback.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function insecureRandomValues<T extends Uint8Array>(arr: T): T;
|
package/build/node.d.ts
DELETED
package/build/packageInfo.d.ts
DELETED
package/build/react-native.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export { packageInfo } from './packageInfo.js';
|
|
2
|
-
/**
|
|
3
|
-
* @internal
|
|
4
|
-
*
|
|
5
|
-
* A getRandomValues util that detects and uses the available RN
|
|
6
|
-
* random utiliy generation functions.
|
|
7
|
-
**/
|
|
8
|
-
declare function getRandomValuesRn(output: Uint8Array): Uint8Array;
|
|
9
|
-
export declare const getRandomValues: typeof getRandomValuesRn;
|
|
10
|
-
export declare const crypto: Crypto | {
|
|
11
|
-
getRandomValues: typeof getRandomValuesRn;
|
|
12
|
-
};
|
package/build/shim.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/build-deno/README.md
DELETED
package/build-deno/browser.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { xglobal } from 'https://deno.land/x/pezkuwi/x-global/mod.ts';
|
|
3
|
-
|
|
4
|
-
export { packageInfo } from './packageInfo.ts';
|
|
5
|
-
|
|
6
|
-
export const crypto = xglobal.crypto;
|
|
7
|
-
|
|
8
|
-
export function getRandomValues <T extends Uint8Array> (arr: T): T {
|
|
9
|
-
return crypto.getRandomValues(arr);
|
|
10
|
-
}
|
package/build-deno/fallback.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
let warned = false;
|
|
4
|
-
|
|
5
|
-
export function insecureRandomValues <T extends Uint8Array> (arr: T): T {
|
|
6
|
-
if (!warned) {
|
|
7
|
-
console.warn('Using an insecure random number generator, this should only happen when running in a debugger without support for crypto');
|
|
8
|
-
warned = true;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
let r = 0;
|
|
12
|
-
|
|
13
|
-
for (let i = 0, count = arr.length; i < count; i++) {
|
|
14
|
-
if ((i & 0b11) === 0) {
|
|
15
|
-
r = Math.random() * 0x100000000;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
arr[i] = (r >>> ((i & 0b11) << 3)) & 0xff;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return arr;
|
|
22
|
-
}
|
package/build-deno/mod.ts
DELETED
package/build-deno/node.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import nodeCrypto from 'node:crypto';
|
|
3
|
-
|
|
4
|
-
import { extractGlobal } from 'https://deno.land/x/pezkuwi/x-global/mod.ts';
|
|
5
|
-
|
|
6
|
-
export { packageInfo } from './packageInfo.ts';
|
|
7
|
-
|
|
8
|
-
export const crypto = /*#__PURE__*/ extractGlobal('crypto', nodeCrypto.webcrypto);
|
|
9
|
-
|
|
10
|
-
export function getRandomValues <T extends Uint8Array> (output: T): T {
|
|
11
|
-
return crypto.getRandomValues(output);
|
|
12
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @pezkuwi/x-randomvalues authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
// Adapted from https://github.com/LinusU/react-native-get-random-values/blob/85f48393821c23b83b89a8177f56d3a81dc8b733/index.js
|
|
5
|
-
//
|
|
6
|
-
// Copyright (c) 2018, 2020 Linus Unnebäck
|
|
7
|
-
// SPDX-License-Identifier: MIT
|
|
8
|
-
|
|
9
|
-
import { NativeModules } from 'react-native';
|
|
10
|
-
|
|
11
|
-
import { base64Decode } from '@pezkuwi/wasm-util/base64';
|
|
12
|
-
import { xglobal } from '@pezkuwi/x-global';
|
|
13
|
-
|
|
14
|
-
import { crypto as cryptoBrowser, getRandomValues as getRandomValuesBrowser } from './browser.js';
|
|
15
|
-
|
|
16
|
-
export { packageInfo } from './packageInfo.js';
|
|
17
|
-
|
|
18
|
-
interface RNExt {
|
|
19
|
-
ExpoRandom: {
|
|
20
|
-
getRandomBase64String: (length: number) => string;
|
|
21
|
-
};
|
|
22
|
-
RNGetRandomValues: {
|
|
23
|
-
getRandomBase64: (length: number) => string;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @internal
|
|
29
|
-
*
|
|
30
|
-
* A getRandomValues util that detects and uses the available RN
|
|
31
|
-
* random utiliy generation functions.
|
|
32
|
-
**/
|
|
33
|
-
function getRandomValuesRn (output: Uint8Array): Uint8Array {
|
|
34
|
-
if (!NativeModules['ExpoRandom'] && !(NativeModules as RNExt).RNGetRandomValues) {
|
|
35
|
-
throw new Error('No secure random number generator available. This environment does not support crypto.getRandomValues and no React Native secure RNG module is available.');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return base64Decode(
|
|
39
|
-
(NativeModules as RNExt).RNGetRandomValues
|
|
40
|
-
? (NativeModules as RNExt).RNGetRandomValues.getRandomBase64(output.length)
|
|
41
|
-
: (NativeModules as RNExt).ExpoRandom.getRandomBase64String(output.length),
|
|
42
|
-
output
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Check for native RN modules first (highest priority)
|
|
47
|
-
const hasNativeRNModules = !!NativeModules['ExpoRandom'] || !!(NativeModules as RNExt).RNGetRandomValues;
|
|
48
|
-
const hasNativeCrypto = typeof xglobal.crypto === 'object' && typeof xglobal.crypto.getRandomValues === 'function';
|
|
49
|
-
|
|
50
|
-
export const getRandomValues = (
|
|
51
|
-
hasNativeRNModules
|
|
52
|
-
? getRandomValuesRn
|
|
53
|
-
: hasNativeCrypto
|
|
54
|
-
? getRandomValuesBrowser
|
|
55
|
-
: () => {
|
|
56
|
-
throw new Error('No secure random number generator available. This environment does not support crypto.getRandomValues.');
|
|
57
|
-
}
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
export const crypto = (
|
|
61
|
-
getRandomValues === getRandomValuesBrowser
|
|
62
|
-
? cryptoBrowser
|
|
63
|
-
: { getRandomValues }
|
|
64
|
-
);
|
package/build-deno/shim.ts
DELETED
package/build-tsc/browser.d.ts
DELETED
package/build-tsc/fallback.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function insecureRandomValues<T extends Uint8Array>(arr: T): T;
|
package/build-tsc/node.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export { packageInfo } from './packageInfo.js';
|
|
2
|
-
/**
|
|
3
|
-
* @internal
|
|
4
|
-
*
|
|
5
|
-
* A getRandomValues util that detects and uses the available RN
|
|
6
|
-
* random utiliy generation functions.
|
|
7
|
-
**/
|
|
8
|
-
declare function getRandomValuesRn(output: Uint8Array): Uint8Array;
|
|
9
|
-
export declare const getRandomValues: typeof getRandomValuesRn;
|
|
10
|
-
export declare const crypto: Crypto | {
|
|
11
|
-
getRandomValues: typeof getRandomValuesRn;
|
|
12
|
-
};
|
package/build-tsc/shim.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/build-tsc-cjs/browser.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2017-2025 @pezkuwi/x-randomvalues authors & contributors
|
|
3
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.crypto = exports.packageInfo = void 0;
|
|
6
|
-
exports.getRandomValues = getRandomValues;
|
|
7
|
-
const x_global_1 = require("@pezkuwi/x-global");
|
|
8
|
-
var packageInfo_js_1 = require("./packageInfo.js");
|
|
9
|
-
Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_js_1.packageInfo; } });
|
|
10
|
-
exports.crypto = x_global_1.xglobal.crypto;
|
|
11
|
-
// getRandomValues needs to be called on the crypto object,
|
|
12
|
-
// hence the need for the wrapper function
|
|
13
|
-
function getRandomValues(arr) {
|
|
14
|
-
return exports.crypto.getRandomValues(arr);
|
|
15
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2017-2025 @pezkuwi/x-randomvalues authors & contributors
|
|
3
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.insecureRandomValues = insecureRandomValues;
|
|
6
|
-
// Adapted from https://github.com/LinusU/react-native-get-random-values/blob/85f48393821c23b83b89a8177f56d3a81dc8b733/index.js
|
|
7
|
-
//
|
|
8
|
-
// Copyright (c) 2018, 2020 Linus Unnebäck
|
|
9
|
-
// SPDX-License-Identifier: MIT
|
|
10
|
-
let warned = false;
|
|
11
|
-
function insecureRandomValues(arr) {
|
|
12
|
-
if (!warned) {
|
|
13
|
-
console.warn('Using an insecure random number generator, this should only happen when running in a debugger without support for crypto');
|
|
14
|
-
warned = true;
|
|
15
|
-
}
|
|
16
|
-
let r = 0;
|
|
17
|
-
for (let i = 0, count = arr.length; i < count; i++) {
|
|
18
|
-
if ((i & 0b11) === 0) {
|
|
19
|
-
r = Math.random() * 0x100000000;
|
|
20
|
-
}
|
|
21
|
-
arr[i] = (r >>> ((i & 0b11) << 3)) & 0xff;
|
|
22
|
-
}
|
|
23
|
-
return arr;
|
|
24
|
-
}
|
package/build-tsc-cjs/node.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2017-2025 @pezkuwi/x-randomvalues authors & contributors
|
|
3
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.crypto = exports.packageInfo = void 0;
|
|
6
|
-
exports.getRandomValues = getRandomValues;
|
|
7
|
-
const tslib_1 = require("tslib");
|
|
8
|
-
// Needs Node 15+ for webcrypto
|
|
9
|
-
const node_crypto_1 = tslib_1.__importDefault(require("node:crypto"));
|
|
10
|
-
const x_global_1 = require("@pezkuwi/x-global");
|
|
11
|
-
var packageInfo_js_1 = require("./packageInfo.js");
|
|
12
|
-
Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_js_1.packageInfo; } });
|
|
13
|
-
exports.crypto = (0, x_global_1.extractGlobal)('crypto', node_crypto_1.default.webcrypto);
|
|
14
|
-
// getRandomValues needs to be called on the crypto object,
|
|
15
|
-
// hence the need for the wrapper function
|
|
16
|
-
function getRandomValues(output) {
|
|
17
|
-
return exports.crypto.getRandomValues(output);
|
|
18
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2017-2026 @pezkuwi/x-randomvalues authors & contributors
|
|
3
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.packageInfo = void 0;
|
|
6
|
-
// Do not edit, auto-generated by @pezkuwi/dev
|
|
7
|
-
exports.packageInfo = { name: '@pezkuwi/x-randomvalues', path: 'auto', type: 'auto', version: '14.0.23' };
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2017-2025 @pezkuwi/x-randomvalues authors & contributors
|
|
3
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.crypto = exports.getRandomValues = exports.packageInfo = void 0;
|
|
6
|
-
// Adapted from https://github.com/LinusU/react-native-get-random-values/blob/85f48393821c23b83b89a8177f56d3a81dc8b733/index.js
|
|
7
|
-
//
|
|
8
|
-
// Copyright (c) 2018, 2020 Linus Unnebäck
|
|
9
|
-
// SPDX-License-Identifier: MIT
|
|
10
|
-
const react_native_1 = require("react-native");
|
|
11
|
-
const base64_1 = require("@pezkuwi/wasm-util/base64");
|
|
12
|
-
const x_global_1 = require("@pezkuwi/x-global");
|
|
13
|
-
const browser_js_1 = require("./browser.js");
|
|
14
|
-
var packageInfo_js_1 = require("./packageInfo.js");
|
|
15
|
-
Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_js_1.packageInfo; } });
|
|
16
|
-
/**
|
|
17
|
-
* @internal
|
|
18
|
-
*
|
|
19
|
-
* A getRandomValues util that detects and uses the available RN
|
|
20
|
-
* random utiliy generation functions.
|
|
21
|
-
**/
|
|
22
|
-
function getRandomValuesRn(output) {
|
|
23
|
-
if (!react_native_1.NativeModules['ExpoRandom'] && !react_native_1.NativeModules.RNGetRandomValues) {
|
|
24
|
-
throw new Error('No secure random number generator available. This environment does not support crypto.getRandomValues and no React Native secure RNG module is available.');
|
|
25
|
-
}
|
|
26
|
-
return (0, base64_1.base64Decode)(react_native_1.NativeModules.RNGetRandomValues
|
|
27
|
-
? react_native_1.NativeModules.RNGetRandomValues.getRandomBase64(output.length)
|
|
28
|
-
: react_native_1.NativeModules.ExpoRandom.getRandomBase64String(output.length), output);
|
|
29
|
-
}
|
|
30
|
-
// Check for native RN modules first (highest priority)
|
|
31
|
-
const hasNativeRNModules = !!react_native_1.NativeModules['ExpoRandom'] || !!react_native_1.NativeModules.RNGetRandomValues;
|
|
32
|
-
const hasNativeCrypto = typeof x_global_1.xglobal.crypto === 'object' && typeof x_global_1.xglobal.crypto.getRandomValues === 'function';
|
|
33
|
-
exports.getRandomValues = (hasNativeRNModules
|
|
34
|
-
? getRandomValuesRn
|
|
35
|
-
: hasNativeCrypto
|
|
36
|
-
? browser_js_1.getRandomValues
|
|
37
|
-
: () => {
|
|
38
|
-
throw new Error('No secure random number generator available. This environment does not support crypto.getRandomValues.');
|
|
39
|
-
});
|
|
40
|
-
exports.crypto = (exports.getRandomValues === browser_js_1.getRandomValues
|
|
41
|
-
? browser_js_1.crypto
|
|
42
|
-
: { getRandomValues: exports.getRandomValues });
|
package/build-tsc-cjs/shim.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2017-2025 @pezkuwi/x-randomvalues authors & contributors
|
|
3
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
const x_global_1 = require("@pezkuwi/x-global");
|
|
6
|
-
const x_randomvalues_1 = require("@pezkuwi/x-randomvalues");
|
|
7
|
-
(0, x_global_1.exposeGlobal)('crypto', x_randomvalues_1.crypto);
|
package/build-tsc-esm/browser.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @pezkuwi/x-randomvalues authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { xglobal } from '@pezkuwi/x-global';
|
|
4
|
-
export { packageInfo } from './packageInfo.js';
|
|
5
|
-
export const crypto = xglobal.crypto;
|
|
6
|
-
// getRandomValues needs to be called on the crypto object,
|
|
7
|
-
// hence the need for the wrapper function
|
|
8
|
-
export function getRandomValues(arr) {
|
|
9
|
-
return crypto.getRandomValues(arr);
|
|
10
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @pezkuwi/x-randomvalues authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
// Adapted from https://github.com/LinusU/react-native-get-random-values/blob/85f48393821c23b83b89a8177f56d3a81dc8b733/index.js
|
|
4
|
-
//
|
|
5
|
-
// Copyright (c) 2018, 2020 Linus Unnebäck
|
|
6
|
-
// SPDX-License-Identifier: MIT
|
|
7
|
-
let warned = false;
|
|
8
|
-
export function insecureRandomValues(arr) {
|
|
9
|
-
if (!warned) {
|
|
10
|
-
console.warn('Using an insecure random number generator, this should only happen when running in a debugger without support for crypto');
|
|
11
|
-
warned = true;
|
|
12
|
-
}
|
|
13
|
-
let r = 0;
|
|
14
|
-
for (let i = 0, count = arr.length; i < count; i++) {
|
|
15
|
-
if ((i & 0b11) === 0) {
|
|
16
|
-
r = Math.random() * 0x100000000;
|
|
17
|
-
}
|
|
18
|
-
arr[i] = (r >>> ((i & 0b11) << 3)) & 0xff;
|
|
19
|
-
}
|
|
20
|
-
return arr;
|
|
21
|
-
}
|
package/build-tsc-esm/node.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @pezkuwi/x-randomvalues authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
// Needs Node 15+ for webcrypto
|
|
4
|
-
import nodeCrypto from 'node:crypto';
|
|
5
|
-
import { extractGlobal } from '@pezkuwi/x-global';
|
|
6
|
-
export { packageInfo } from './packageInfo.js';
|
|
7
|
-
export const crypto = /*#__PURE__*/ extractGlobal('crypto', nodeCrypto.webcrypto);
|
|
8
|
-
// getRandomValues needs to be called on the crypto object,
|
|
9
|
-
// hence the need for the wrapper function
|
|
10
|
-
export function getRandomValues(output) {
|
|
11
|
-
return crypto.getRandomValues(output);
|
|
12
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @pezkuwi/x-randomvalues authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
// Adapted from https://github.com/LinusU/react-native-get-random-values/blob/85f48393821c23b83b89a8177f56d3a81dc8b733/index.js
|
|
4
|
-
//
|
|
5
|
-
// Copyright (c) 2018, 2020 Linus Unnebäck
|
|
6
|
-
// SPDX-License-Identifier: MIT
|
|
7
|
-
import { NativeModules } from 'react-native';
|
|
8
|
-
import { base64Decode } from '@pezkuwi/wasm-util/base64';
|
|
9
|
-
import { xglobal } from '@pezkuwi/x-global';
|
|
10
|
-
import { crypto as cryptoBrowser, getRandomValues as getRandomValuesBrowser } from './browser.js';
|
|
11
|
-
export { packageInfo } from './packageInfo.js';
|
|
12
|
-
/**
|
|
13
|
-
* @internal
|
|
14
|
-
*
|
|
15
|
-
* A getRandomValues util that detects and uses the available RN
|
|
16
|
-
* random utiliy generation functions.
|
|
17
|
-
**/
|
|
18
|
-
function getRandomValuesRn(output) {
|
|
19
|
-
if (!NativeModules['ExpoRandom'] && !NativeModules.RNGetRandomValues) {
|
|
20
|
-
throw new Error('No secure random number generator available. This environment does not support crypto.getRandomValues and no React Native secure RNG module is available.');
|
|
21
|
-
}
|
|
22
|
-
return base64Decode(NativeModules.RNGetRandomValues
|
|
23
|
-
? NativeModules.RNGetRandomValues.getRandomBase64(output.length)
|
|
24
|
-
: NativeModules.ExpoRandom.getRandomBase64String(output.length), output);
|
|
25
|
-
}
|
|
26
|
-
// Check for native RN modules first (highest priority)
|
|
27
|
-
const hasNativeRNModules = !!NativeModules['ExpoRandom'] || !!NativeModules.RNGetRandomValues;
|
|
28
|
-
const hasNativeCrypto = typeof xglobal.crypto === 'object' && typeof xglobal.crypto.getRandomValues === 'function';
|
|
29
|
-
export const getRandomValues = (hasNativeRNModules
|
|
30
|
-
? getRandomValuesRn
|
|
31
|
-
: hasNativeCrypto
|
|
32
|
-
? getRandomValuesBrowser
|
|
33
|
-
: () => {
|
|
34
|
-
throw new Error('No secure random number generator available. This environment does not support crypto.getRandomValues.');
|
|
35
|
-
});
|
|
36
|
-
export const crypto = (getRandomValues === getRandomValuesBrowser
|
|
37
|
-
? cryptoBrowser
|
|
38
|
-
: { getRandomValues });
|
package/build-tsc-esm/shim.js
DELETED
package/src/browser.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @pezkuwi/x-randomvalues authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { xglobal } from '@pezkuwi/x-global';
|
|
5
|
-
|
|
6
|
-
export { packageInfo } from './packageInfo.js';
|
|
7
|
-
|
|
8
|
-
export const crypto = xglobal.crypto;
|
|
9
|
-
|
|
10
|
-
// getRandomValues needs to be called on the crypto object,
|
|
11
|
-
// hence the need for the wrapper function
|
|
12
|
-
export function getRandomValues <T extends Uint8Array> (arr: T): T {
|
|
13
|
-
return crypto.getRandomValues(arr);
|
|
14
|
-
}
|
package/src/fallback.spec.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @pezkuwi/x-randomvalues authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
|
|
5
|
-
|
|
6
|
-
import { insecureRandomValues } from './fallback.js';
|
|
7
|
-
|
|
8
|
-
describe('fallback (insecure)', (): void => {
|
|
9
|
-
it('subsequent results does not match', (): void => {
|
|
10
|
-
expect(
|
|
11
|
-
insecureRandomValues(new Uint8Array(32)).toString()
|
|
12
|
-
).not.toEqual(
|
|
13
|
-
insecureRandomValues(new Uint8Array(32)).toString()
|
|
14
|
-
);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('generates with the supplied length', (): void => {
|
|
18
|
-
expect(
|
|
19
|
-
insecureRandomValues(new Uint8Array(128))
|
|
20
|
-
).toHaveLength(128);
|
|
21
|
-
});
|
|
22
|
-
});
|
package/src/fallback.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @pezkuwi/x-randomvalues authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
// Adapted from https://github.com/LinusU/react-native-get-random-values/blob/85f48393821c23b83b89a8177f56d3a81dc8b733/index.js
|
|
5
|
-
//
|
|
6
|
-
// Copyright (c) 2018, 2020 Linus Unnebäck
|
|
7
|
-
// SPDX-License-Identifier: MIT
|
|
8
|
-
|
|
9
|
-
let warned = false;
|
|
10
|
-
|
|
11
|
-
export function insecureRandomValues <T extends Uint8Array> (arr: T): T {
|
|
12
|
-
if (!warned) {
|
|
13
|
-
console.warn('Using an insecure random number generator, this should only happen when running in a debugger without support for crypto');
|
|
14
|
-
warned = true;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
let r = 0;
|
|
18
|
-
|
|
19
|
-
for (let i = 0, count = arr.length; i < count; i++) {
|
|
20
|
-
if ((i & 0b11) === 0) {
|
|
21
|
-
r = Math.random() * 0x100000000;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
arr[i] = (r >>> ((i & 0b11) << 3)) & 0xff;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return arr;
|
|
28
|
-
}
|