Merge pull request #11 from pezkuwichain/deps/no-unfixed-advisories

x-randomvalues: declare NativeModules locally; resolve braces to @pezkuwi/braces
This commit is contained in:
SatoshiQaziMuhammed authored and GitHub committed 2026-10-10 04:09:16 +04:00
commit f4256caaeb
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