@pezkuwi/x-randomvalues 14.0.13 → 14.0.15
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 +16 -58
- package/packageInfo.js +1 -1
- package/build/LICENSE +0 -201
- package/build/README.md +0 -3
- package/build/browser.d.ts +0 -3
- package/build/browser.js +0 -6
- package/build/cjs/browser.d.ts +0 -3
- package/build/cjs/browser.js +0 -11
- package/build/cjs/fallback.d.ts +0 -1
- package/build/cjs/fallback.js +0 -18
- package/build/cjs/node.d.ts +0 -3
- package/build/cjs/node.js +0 -13
- package/build/cjs/package.json +0 -3
- package/build/cjs/packageInfo.d.ts +0 -6
- package/build/cjs/packageInfo.js +0 -4
- package/build/cjs/react-native.d.ts +0 -12
- package/build/cjs/react-native.js +0 -35
- package/build/cjs/shim.d.ts +0 -1
- package/build/cjs/shim.js +0 -5
- package/build/fallback.d.ts +0 -1
- package/build/fallback.js +0 -15
- package/build/node.d.ts +0 -3
- package/build/node.js +0 -7
- package/build/package.json +0 -158
- package/build/packageInfo.d.ts +0 -6
- package/build/packageInfo.js +0 -1
- package/build/react-native.d.ts +0 -12
- package/build/react-native.js +0 -31
- package/build/shim.d.ts +0 -1
- package/build/shim.js +0 -3
- 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 -57
- package/build-deno/shim.ts +0 -5
- 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 -11
- package/build-tsc-cjs/fallback.js +0 -18
- package/build-tsc-cjs/node.js +0 -13
- package/build-tsc-cjs/packageInfo.js +0 -4
- package/build-tsc-cjs/react-native.js +0 -35
- package/build-tsc-cjs/shim.js +0 -5
- package/build-tsc-esm/browser.js +0 -6
- package/build-tsc-esm/fallback.js +0 -15
- package/build-tsc-esm/node.js +0 -7
- package/build-tsc-esm/packageInfo.js +0 -1
- package/build-tsc-esm/react-native.js +0 -31
- package/build-tsc-esm/shim.js +0 -3
- 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/build/package.json
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"author": "Dijital Kurdistan Tech Institute <dev@pezkuwichain.io>",
|
|
3
|
-
"bugs": "https://github.com/pezkuwichain/pezkuwi-common/issues",
|
|
4
|
-
"description": "A cross-environment window.crypto.getRandomValues replacement",
|
|
5
|
-
"engines": {
|
|
6
|
-
"node": ">=18"
|
|
7
|
-
},
|
|
8
|
-
"homepage": "https://github.com/pezkuwichain/pezkuwi-common/tree/master/packages/x-randomvalues#readme",
|
|
9
|
-
"license": "Apache-2.0",
|
|
10
|
-
"name": "@pezkuwi/x-randomvalues",
|
|
11
|
-
"repository": {
|
|
12
|
-
"directory": "packages/x-randomvalues",
|
|
13
|
-
"type": "git",
|
|
14
|
-
"url": "https://github.com/pezkuwichain/pezkuwi-common.git"
|
|
15
|
-
},
|
|
16
|
-
"sideEffects": false,
|
|
17
|
-
"type": "module",
|
|
18
|
-
"version": "14.0.13",
|
|
19
|
-
"main": "./cjs/node.js",
|
|
20
|
-
"module": "./cjs/node.js",
|
|
21
|
-
"browser": "./cjs/browser.js",
|
|
22
|
-
"react-native": "./cjs/react-native.js",
|
|
23
|
-
"types": "./cjs/node.d.ts",
|
|
24
|
-
"exports": {
|
|
25
|
-
"./cjs/package.json": "./cjs/package.json",
|
|
26
|
-
"./cjs/*": "./cjs/*.js",
|
|
27
|
-
".": {
|
|
28
|
-
"types": "./cjs/node.d.ts./cjs/node.js",
|
|
29
|
-
"react-native": "./cjs/react-native.js./cjs/react-native.js",
|
|
30
|
-
"browser": "./cjs/browser.js./cjs/browser.js",
|
|
31
|
-
"node": "./cjs/node.js./cjs/node.js"
|
|
32
|
-
},
|
|
33
|
-
"./browser": {
|
|
34
|
-
"module": {
|
|
35
|
-
"types": "./browser.d.ts",
|
|
36
|
-
"default": "./browser.js"
|
|
37
|
-
},
|
|
38
|
-
"require": {
|
|
39
|
-
"types": "./cjs/browser.d.ts",
|
|
40
|
-
"default": "./cjs/browser.js"
|
|
41
|
-
},
|
|
42
|
-
"default": {
|
|
43
|
-
"types": "./browser.d.ts",
|
|
44
|
-
"default": "./browser.js"
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
"./fallback": {
|
|
48
|
-
"module": {
|
|
49
|
-
"types": "./fallback.d.ts",
|
|
50
|
-
"default": "./fallback.js"
|
|
51
|
-
},
|
|
52
|
-
"require": {
|
|
53
|
-
"types": "./cjs/fallback.d.ts",
|
|
54
|
-
"default": "./cjs/fallback.js"
|
|
55
|
-
},
|
|
56
|
-
"default": {
|
|
57
|
-
"types": "./fallback.d.ts",
|
|
58
|
-
"default": "./fallback.js"
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
"./node": {
|
|
62
|
-
"module": {
|
|
63
|
-
"types": "./node.d.ts",
|
|
64
|
-
"default": "./node.js"
|
|
65
|
-
},
|
|
66
|
-
"require": {
|
|
67
|
-
"types": "./cjs/node.d.ts",
|
|
68
|
-
"default": "./cjs/node.js"
|
|
69
|
-
},
|
|
70
|
-
"default": {
|
|
71
|
-
"types": "./node.d.ts",
|
|
72
|
-
"default": "./node.js"
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
"./package.json": {
|
|
76
|
-
"require": "./cjs/package.json",
|
|
77
|
-
"default": "./package.json"
|
|
78
|
-
},
|
|
79
|
-
"./packageInfo.js": {
|
|
80
|
-
"module": {
|
|
81
|
-
"types": "./packageInfo.d.ts",
|
|
82
|
-
"default": "./packageInfo.js"
|
|
83
|
-
},
|
|
84
|
-
"require": {
|
|
85
|
-
"types": "./cjs/packageInfo.d.ts",
|
|
86
|
-
"default": "./cjs/packageInfo.js"
|
|
87
|
-
},
|
|
88
|
-
"default": {
|
|
89
|
-
"types": "./packageInfo.d.ts",
|
|
90
|
-
"default": "./packageInfo.js"
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
"./packageInfo": {
|
|
94
|
-
"module": {
|
|
95
|
-
"types": "./packageInfo.d.ts",
|
|
96
|
-
"default": "./packageInfo.js"
|
|
97
|
-
},
|
|
98
|
-
"require": {
|
|
99
|
-
"types": "./cjs/packageInfo.d.ts",
|
|
100
|
-
"default": "./cjs/packageInfo.js"
|
|
101
|
-
},
|
|
102
|
-
"default": {
|
|
103
|
-
"types": "./packageInfo.d.ts",
|
|
104
|
-
"default": "./packageInfo.js"
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
"./react-native": {
|
|
108
|
-
"module": {
|
|
109
|
-
"types": "./react-native.d.ts",
|
|
110
|
-
"default": "./react-native.js"
|
|
111
|
-
},
|
|
112
|
-
"require": {
|
|
113
|
-
"types": "./cjs/react-native.d.ts",
|
|
114
|
-
"default": "./cjs/react-native.js"
|
|
115
|
-
},
|
|
116
|
-
"default": {
|
|
117
|
-
"types": "./react-native.d.ts",
|
|
118
|
-
"default": "./react-native.js"
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
"./shim.js": {
|
|
122
|
-
"module": {
|
|
123
|
-
"types": "./shim.d.ts",
|
|
124
|
-
"default": "./shim.js"
|
|
125
|
-
},
|
|
126
|
-
"require": {
|
|
127
|
-
"types": "./cjs/shim.d.ts",
|
|
128
|
-
"default": "./cjs/shim.js"
|
|
129
|
-
},
|
|
130
|
-
"default": {
|
|
131
|
-
"types": "./shim.d.ts",
|
|
132
|
-
"default": "./shim.js"
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
"./shim": {
|
|
136
|
-
"module": {
|
|
137
|
-
"types": "./shim.d.ts",
|
|
138
|
-
"default": "./shim.js"
|
|
139
|
-
},
|
|
140
|
-
"require": {
|
|
141
|
-
"types": "./cjs/shim.d.ts",
|
|
142
|
-
"default": "./cjs/shim.js"
|
|
143
|
-
},
|
|
144
|
-
"default": {
|
|
145
|
-
"types": "./shim.d.ts",
|
|
146
|
-
"default": "./shim.js"
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
"dependencies": {
|
|
151
|
-
"@pezkuwi/x-global": "14.0.12",
|
|
152
|
-
"tslib": "^2.8.0"
|
|
153
|
-
},
|
|
154
|
-
"peerDependencies": {
|
|
155
|
-
"@pezkuwi/util": "14.0.12",
|
|
156
|
-
"@pezkuwi/wasm-util": "*"
|
|
157
|
-
}
|
|
158
|
-
}
|
package/build/packageInfo.d.ts
DELETED
package/build/packageInfo.js
DELETED
|
@@ -1 +0,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.13' };
|
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/react-native.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { NativeModules } from 'react-native';
|
|
2
|
-
import { base64Decode } from '@pezkuwi/wasm-util/base64';
|
|
3
|
-
import { xglobal } from '@pezkuwi/x-global';
|
|
4
|
-
import { crypto as cryptoBrowser, getRandomValues as getRandomValuesBrowser } from './browser.js';
|
|
5
|
-
export { packageInfo } from './packageInfo.js';
|
|
6
|
-
/**
|
|
7
|
-
* @internal
|
|
8
|
-
*
|
|
9
|
-
* A getRandomValues util that detects and uses the available RN
|
|
10
|
-
* random utiliy generation functions.
|
|
11
|
-
**/
|
|
12
|
-
function getRandomValuesRn(output) {
|
|
13
|
-
if (!NativeModules['ExpoRandom'] && !NativeModules.RNGetRandomValues) {
|
|
14
|
-
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.');
|
|
15
|
-
}
|
|
16
|
-
return base64Decode(NativeModules.RNGetRandomValues
|
|
17
|
-
? NativeModules.RNGetRandomValues.getRandomBase64(output.length)
|
|
18
|
-
: NativeModules.ExpoRandom.getRandomBase64String(output.length), output);
|
|
19
|
-
}
|
|
20
|
-
const hasNativeRNModules = !!NativeModules['ExpoRandom'] || !!NativeModules.RNGetRandomValues;
|
|
21
|
-
const hasNativeCrypto = typeof xglobal.crypto === 'object' && typeof xglobal.crypto.getRandomValues === 'function';
|
|
22
|
-
export const getRandomValues = (hasNativeRNModules
|
|
23
|
-
? getRandomValuesRn
|
|
24
|
-
: hasNativeCrypto
|
|
25
|
-
? getRandomValuesBrowser
|
|
26
|
-
: () => {
|
|
27
|
-
throw new Error('No secure random number generator available. This environment does not support crypto.getRandomValues.');
|
|
28
|
-
});
|
|
29
|
-
export const crypto = (getRandomValues === getRandomValuesBrowser
|
|
30
|
-
? cryptoBrowser
|
|
31
|
-
: { getRandomValues });
|
package/build/shim.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/build/shim.js
DELETED
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,57 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { NativeModules } from 'https://esm.sh/react-native';
|
|
4
|
-
|
|
5
|
-
import { base64Decode } from 'https://deno.land/x/pezkuwi/wasm-util/base64.ts';
|
|
6
|
-
import { xglobal } from 'https://deno.land/x/pezkuwi/x-global/mod.ts';
|
|
7
|
-
|
|
8
|
-
import { crypto as cryptoBrowser, getRandomValues as getRandomValuesBrowser } from './browser.ts';
|
|
9
|
-
|
|
10
|
-
export { packageInfo } from './packageInfo.ts';
|
|
11
|
-
|
|
12
|
-
interface RNExt {
|
|
13
|
-
ExpoRandom: {
|
|
14
|
-
getRandomBase64String: (length: number) => string;
|
|
15
|
-
};
|
|
16
|
-
RNGetRandomValues: {
|
|
17
|
-
getRandomBase64: (length: number) => string;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @internal
|
|
23
|
-
*
|
|
24
|
-
* A getRandomValues util that detects and uses the available RN
|
|
25
|
-
* random utiliy generation functions.
|
|
26
|
-
**/
|
|
27
|
-
function getRandomValuesRn (output: Uint8Array): Uint8Array {
|
|
28
|
-
if (!NativeModules['ExpoRandom'] && !(NativeModules as RNExt).RNGetRandomValues) {
|
|
29
|
-
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.');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return base64Decode(
|
|
33
|
-
(NativeModules as RNExt).RNGetRandomValues
|
|
34
|
-
? (NativeModules as RNExt).RNGetRandomValues.getRandomBase64(output.length)
|
|
35
|
-
: (NativeModules as RNExt).ExpoRandom.getRandomBase64String(output.length),
|
|
36
|
-
output
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const hasNativeRNModules = !!NativeModules['ExpoRandom'] || !!(NativeModules as RNExt).RNGetRandomValues;
|
|
41
|
-
const hasNativeCrypto = typeof xglobal.crypto === 'object' && typeof xglobal.crypto.getRandomValues === 'function';
|
|
42
|
-
|
|
43
|
-
export const getRandomValues = (
|
|
44
|
-
hasNativeRNModules
|
|
45
|
-
? getRandomValuesRn
|
|
46
|
-
: hasNativeCrypto
|
|
47
|
-
? getRandomValuesBrowser
|
|
48
|
-
: () => {
|
|
49
|
-
throw new Error('No secure random number generator available. This environment does not support crypto.getRandomValues.');
|
|
50
|
-
}
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
export const crypto = (
|
|
54
|
-
getRandomValues === getRandomValuesBrowser
|
|
55
|
-
? cryptoBrowser
|
|
56
|
-
: { getRandomValues }
|
|
57
|
-
);
|
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,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.crypto = exports.packageInfo = void 0;
|
|
4
|
-
exports.getRandomValues = getRandomValues;
|
|
5
|
-
const x_global_1 = require("@pezkuwi/x-global");
|
|
6
|
-
var packageInfo_js_1 = require("./packageInfo.js");
|
|
7
|
-
Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_js_1.packageInfo; } });
|
|
8
|
-
exports.crypto = x_global_1.xglobal.crypto;
|
|
9
|
-
function getRandomValues(arr) {
|
|
10
|
-
return exports.crypto.getRandomValues(arr);
|
|
11
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.insecureRandomValues = insecureRandomValues;
|
|
4
|
-
let warned = false;
|
|
5
|
-
function insecureRandomValues(arr) {
|
|
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
|
-
let r = 0;
|
|
11
|
-
for (let i = 0, count = arr.length; i < count; i++) {
|
|
12
|
-
if ((i & 0b11) === 0) {
|
|
13
|
-
r = Math.random() * 0x100000000;
|
|
14
|
-
}
|
|
15
|
-
arr[i] = (r >>> ((i & 0b11) << 3)) & 0xff;
|
|
16
|
-
}
|
|
17
|
-
return arr;
|
|
18
|
-
}
|
package/build-tsc-cjs/node.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.crypto = exports.packageInfo = void 0;
|
|
4
|
-
exports.getRandomValues = getRandomValues;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const node_crypto_1 = tslib_1.__importDefault(require("node:crypto"));
|
|
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 = (0, x_global_1.extractGlobal)('crypto', node_crypto_1.default.webcrypto);
|
|
11
|
-
function getRandomValues(output) {
|
|
12
|
-
return exports.crypto.getRandomValues(output);
|
|
13
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.crypto = exports.getRandomValues = exports.packageInfo = void 0;
|
|
4
|
-
const react_native_1 = require("react-native");
|
|
5
|
-
const base64_1 = require("@pezkuwi/wasm-util/base64");
|
|
6
|
-
const x_global_1 = require("@pezkuwi/x-global");
|
|
7
|
-
const browser_js_1 = require("./browser.js");
|
|
8
|
-
var packageInfo_js_1 = require("./packageInfo.js");
|
|
9
|
-
Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_js_1.packageInfo; } });
|
|
10
|
-
/**
|
|
11
|
-
* @internal
|
|
12
|
-
*
|
|
13
|
-
* A getRandomValues util that detects and uses the available RN
|
|
14
|
-
* random utiliy generation functions.
|
|
15
|
-
**/
|
|
16
|
-
function getRandomValuesRn(output) {
|
|
17
|
-
if (!react_native_1.NativeModules['ExpoRandom'] && !react_native_1.NativeModules.RNGetRandomValues) {
|
|
18
|
-
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.');
|
|
19
|
-
}
|
|
20
|
-
return (0, base64_1.base64Decode)(react_native_1.NativeModules.RNGetRandomValues
|
|
21
|
-
? react_native_1.NativeModules.RNGetRandomValues.getRandomBase64(output.length)
|
|
22
|
-
: react_native_1.NativeModules.ExpoRandom.getRandomBase64String(output.length), output);
|
|
23
|
-
}
|
|
24
|
-
const hasNativeRNModules = !!react_native_1.NativeModules['ExpoRandom'] || !!react_native_1.NativeModules.RNGetRandomValues;
|
|
25
|
-
const hasNativeCrypto = typeof x_global_1.xglobal.crypto === 'object' && typeof x_global_1.xglobal.crypto.getRandomValues === 'function';
|
|
26
|
-
exports.getRandomValues = (hasNativeRNModules
|
|
27
|
-
? getRandomValuesRn
|
|
28
|
-
: hasNativeCrypto
|
|
29
|
-
? browser_js_1.getRandomValues
|
|
30
|
-
: () => {
|
|
31
|
-
throw new Error('No secure random number generator available. This environment does not support crypto.getRandomValues.');
|
|
32
|
-
});
|
|
33
|
-
exports.crypto = (exports.getRandomValues === browser_js_1.getRandomValues
|
|
34
|
-
? browser_js_1.crypto
|
|
35
|
-
: { getRandomValues: exports.getRandomValues });
|
package/build-tsc-cjs/shim.js
DELETED
package/build-tsc-esm/browser.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
let warned = false;
|
|
2
|
-
export function insecureRandomValues(arr) {
|
|
3
|
-
if (!warned) {
|
|
4
|
-
console.warn('Using an insecure random number generator, this should only happen when running in a debugger without support for crypto');
|
|
5
|
-
warned = true;
|
|
6
|
-
}
|
|
7
|
-
let r = 0;
|
|
8
|
-
for (let i = 0, count = arr.length; i < count; i++) {
|
|
9
|
-
if ((i & 0b11) === 0) {
|
|
10
|
-
r = Math.random() * 0x100000000;
|
|
11
|
-
}
|
|
12
|
-
arr[i] = (r >>> ((i & 0b11) << 3)) & 0xff;
|
|
13
|
-
}
|
|
14
|
-
return arr;
|
|
15
|
-
}
|
package/build-tsc-esm/node.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import nodeCrypto from 'node:crypto';
|
|
2
|
-
import { extractGlobal } from '@pezkuwi/x-global';
|
|
3
|
-
export { packageInfo } from './packageInfo.js';
|
|
4
|
-
export const crypto = /*#__PURE__*/ extractGlobal('crypto', nodeCrypto.webcrypto);
|
|
5
|
-
export function getRandomValues(output) {
|
|
6
|
-
return crypto.getRandomValues(output);
|
|
7
|
-
}
|
|
@@ -1 +0,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.13' };
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { NativeModules } from 'react-native';
|
|
2
|
-
import { base64Decode } from '@pezkuwi/wasm-util/base64';
|
|
3
|
-
import { xglobal } from '@pezkuwi/x-global';
|
|
4
|
-
import { crypto as cryptoBrowser, getRandomValues as getRandomValuesBrowser } from './browser.js';
|
|
5
|
-
export { packageInfo } from './packageInfo.js';
|
|
6
|
-
/**
|
|
7
|
-
* @internal
|
|
8
|
-
*
|
|
9
|
-
* A getRandomValues util that detects and uses the available RN
|
|
10
|
-
* random utiliy generation functions.
|
|
11
|
-
**/
|
|
12
|
-
function getRandomValuesRn(output) {
|
|
13
|
-
if (!NativeModules['ExpoRandom'] && !NativeModules.RNGetRandomValues) {
|
|
14
|
-
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.');
|
|
15
|
-
}
|
|
16
|
-
return base64Decode(NativeModules.RNGetRandomValues
|
|
17
|
-
? NativeModules.RNGetRandomValues.getRandomBase64(output.length)
|
|
18
|
-
: NativeModules.ExpoRandom.getRandomBase64String(output.length), output);
|
|
19
|
-
}
|
|
20
|
-
const hasNativeRNModules = !!NativeModules['ExpoRandom'] || !!NativeModules.RNGetRandomValues;
|
|
21
|
-
const hasNativeCrypto = typeof xglobal.crypto === 'object' && typeof xglobal.crypto.getRandomValues === 'function';
|
|
22
|
-
export const getRandomValues = (hasNativeRNModules
|
|
23
|
-
? getRandomValuesRn
|
|
24
|
-
: hasNativeCrypto
|
|
25
|
-
? getRandomValuesBrowser
|
|
26
|
-
: () => {
|
|
27
|
-
throw new Error('No secure random number generator available. This environment does not support crypto.getRandomValues.');
|
|
28
|
-
});
|
|
29
|
-
export const crypto = (getRandomValues === getRandomValuesBrowser
|
|
30
|
-
? cryptoBrowser
|
|
31
|
-
: { 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
|
-
}
|
package/src/mod.ts
DELETED
package/src/node.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @pezkuwi/x-randomvalues authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
// Needs Node 15+ for webcrypto
|
|
5
|
-
import nodeCrypto from 'node:crypto';
|
|
6
|
-
|
|
7
|
-
import { extractGlobal } from '@pezkuwi/x-global';
|
|
8
|
-
|
|
9
|
-
export { packageInfo } from './packageInfo.js';
|
|
10
|
-
|
|
11
|
-
export const crypto = /*#__PURE__*/ extractGlobal('crypto', nodeCrypto.webcrypto);
|
|
12
|
-
|
|
13
|
-
// getRandomValues needs to be called on the crypto object,
|
|
14
|
-
// hence the need for the wrapper function
|
|
15
|
-
export function getRandomValues <T extends Uint8Array> (output: T): T {
|
|
16
|
-
return crypto.getRandomValues(output);
|
|
17
|
-
}
|