mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-10-20 18:56:18 +00:00
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:
1 parent
090f7f35e2
commit
81e25b008b
5 files changed
+80
-1885
No files matched your search
@@ -40,6 +40,7 @@
|
|||||||
"@types/node": "^22.7.5"
|
"@types/node": "^22.7.5"
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
|
"braces": "npm:@pezkuwi/braces@^3.0.4",
|
||||||
"typescript": "^5.5.4"
|
"typescript": "^5.5.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,9 +23,6 @@
|
|||||||
"@pezkuwi/x-global": "14.0.26",
|
"@pezkuwi/x-global": "14.0.26",
|
||||||
"tslib": "^2.8.0"
|
"tslib": "^2.8.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
|
||||||
"@types/react-native": "^0.73.0"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@pezkuwi/util": "14.0.26",
|
"@pezkuwi/util": "14.0.26",
|
||||||
"@pezkuwi/wasm-util": "*"
|
"@pezkuwi/wasm-util": "*"
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -15,15 +15,6 @@ import { crypto as cryptoBrowser, getRandomValues as getRandomValuesBrowser } fr
|
|||||||
|
|
||||||
export { packageInfo } from './packageInfo.js';
|
export { packageInfo } from './packageInfo.js';
|
||||||
|
|
||||||
interface RNExt {
|
|
||||||
ExpoRandom: {
|
|
||||||
getRandomBase64String: (length: number) => string;
|
|
||||||
};
|
|
||||||
RNGetRandomValues: {
|
|
||||||
getRandomBase64: (length: number) => string;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*
|
*
|
||||||
@@ -31,20 +22,19 @@ interface RNExt {
|
|||||||
* random utiliy generation functions.
|
* random utiliy generation functions.
|
||||||
**/
|
**/
|
||||||
function getRandomValuesRn (output: Uint8Array): Uint8Array {
|
function getRandomValuesRn (output: Uint8Array): Uint8Array {
|
||||||
if (!NativeModules['ExpoRandom'] && !(NativeModules as RNExt).RNGetRandomValues) {
|
const { ExpoRandom, RNGetRandomValues } = NativeModules;
|
||||||
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.');
|
|
||||||
|
if (RNGetRandomValues) {
|
||||||
|
return base64Decode(RNGetRandomValues.getRandomBase64(output.length), output);
|
||||||
|
} else if (ExpoRandom) {
|
||||||
|
return base64Decode(ExpoRandom.getRandomBase64String(output.length), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
return base64Decode(
|
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.');
|
||||||
(NativeModules as RNExt).RNGetRandomValues
|
|
||||||
? (NativeModules as RNExt).RNGetRandomValues.getRandomBase64(output.length)
|
|
||||||
: (NativeModules as RNExt).ExpoRandom.getRandomBase64String(output.length),
|
|
||||||
output
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for native RN modules first (highest priority)
|
// 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';
|
const hasNativeCrypto = typeof xglobal.crypto === 'object' && typeof xglobal.crypto.getRandomValues === 'function';
|
||||||
|
|
||||||
export const getRandomValues = (
|
export const getRandomValues = (
|
||||||
|
|||||||
Reference in new issue
Block a user