x-randomvalues: declare NativeModules locally; resolve braces to @pezkuwi/braces

x-randomvalues read one export from react-native, NativeModules, and
took its types from the deprecated @types/react-native, which depends
on react-native itself: react-native 0.83, metro 0.83 and with them
image-size (open advisory, fixed only in 2.x, which metro 0.83 does not
accept). The two native modules it looks for are now declared in
src/react-native-modules.d.ts; the casts to RNExt are gone and each
module is checked before use. The published react-native.d.ts does not
reference react-native, and react-native/metro leave the dependency
tree.

braces resolves to @pezkuwi/braces 3.0.4: braces 3.0.3, the latest upstream release, has an open advisory with no fixed version (CVE-2026-93687, stack exhaustion through deeply nested patterns); the fork rejects nesting deeper than maxDepth (500) with a SyntaxError.
This commit is contained in:
Satoshi Qazi Muhammed committed 2026-10-10 04:01:02 +04:00
1 parent 090f7f35e2
commit 81e25b008b
5 files changed
+80 -1885

No files matched your search

+1
View File
@@ -40,6 +40,7 @@
"@types/node": "^22.7.5"
},
"resolutions": {
"braces": "npm:@pezkuwi/braces@^3.0.4",
"typescript": "^5.5.4"
}
}
-3
View File
@@ -23,9 +23,6 @@
"@pezkuwi/x-global": "14.0.26",
"tslib": "^2.8.0"
},
"devDependencies": {
"@types/react-native": "^0.73.0"
},
"peerDependencies": {
"@pezkuwi/util": "14.0.26",
"@pezkuwi/wasm-util": "*"
+18
View File
@@ -0,0 +1,18 @@
// Copyright 2017-2026 @pezkuwi/x-randomvalues authors & contributors
// SPDX-License-Identifier: Apache-2.0
// The one React Native export react-native.ts reads, and only the native
// modules it looks for. Declared here instead of installing react-native for
// its types, which brought in its metro and CLI tree as well.
declare module 'react-native' {
interface RandomModules {
ExpoRandom?: {
getRandomBase64String: (length: number) => string;
};
RNGetRandomValues?: {
getRandomBase64: (length: number) => string;
};
}
export const NativeModules: RandomModules;
}
+8 -18
View File
@@ -15,15 +15,6 @@ import { crypto as cryptoBrowser, getRandomValues as getRandomValuesBrowser } fr
export { packageInfo } from './packageInfo.js';
interface RNExt {
ExpoRandom: {
getRandomBase64String: (length: number) => string;
};
RNGetRandomValues: {
getRandomBase64: (length: number) => string;
}
}
/**
* @internal
*
@@ -31,20 +22,19 @@ interface RNExt {
* random utiliy generation functions.
**/
function getRandomValuesRn (output: Uint8Array): Uint8Array {
if (!NativeModules['ExpoRandom'] && !(NativeModules as RNExt).RNGetRandomValues) {
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.');
const { ExpoRandom, RNGetRandomValues } = NativeModules;
if (RNGetRandomValues) {
return base64Decode(RNGetRandomValues.getRandomBase64(output.length), output);
} else if (ExpoRandom) {
return base64Decode(ExpoRandom.getRandomBase64String(output.length), output);
}
return base64Decode(
(NativeModules as RNExt).RNGetRandomValues
? (NativeModules as RNExt).RNGetRandomValues.getRandomBase64(output.length)
: (NativeModules as RNExt).ExpoRandom.getRandomBase64String(output.length),
output
);
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.');
}
// Check for native RN modules first (highest priority)
const hasNativeRNModules = !!NativeModules['ExpoRandom'] || !!(NativeModules as RNExt).RNGetRandomValues;
const hasNativeRNModules = !!NativeModules.ExpoRandom || !!NativeModules.RNGetRandomValues;
const hasNativeCrypto = typeof xglobal.crypto === 'object' && typeof xglobal.crypto.getRandomValues === 'function';
export const getRandomValues = (
+53 -1864
View File
File diff suppressed because it is too large. Load diff