mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-22 09:08:03 +00:00
chore: update to version 14.0.11 and align website URLs
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
import { NativeModules } from 'react-native';
|
||||
import { base64Decode } from '@pezkuwi/wasm-util/base64';
|
||||
import { xglobal } from '@pezkuwi/x-global';
|
||||
import { crypto as cryptoBrowser, getRandomValues as getRandomValuesBrowser } from './browser.js';
|
||||
export { packageInfo } from './packageInfo.js';
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* A getRandomValues util that detects and uses the available RN
|
||||
* random utiliy generation functions.
|
||||
**/
|
||||
function getRandomValuesRn(output) {
|
||||
if (!NativeModules['ExpoRandom'] && !NativeModules.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.');
|
||||
}
|
||||
return base64Decode(NativeModules.RNGetRandomValues
|
||||
? NativeModules.RNGetRandomValues.getRandomBase64(output.length)
|
||||
: NativeModules.ExpoRandom.getRandomBase64String(output.length), output);
|
||||
}
|
||||
const hasNativeRNModules = !!NativeModules['ExpoRandom'] || !!NativeModules.RNGetRandomValues;
|
||||
const hasNativeCrypto = typeof xglobal.crypto === 'object' && typeof xglobal.crypto.getRandomValues === 'function';
|
||||
export const getRandomValues = (hasNativeRNModules
|
||||
? getRandomValuesRn
|
||||
: hasNativeCrypto
|
||||
? getRandomValuesBrowser
|
||||
: () => {
|
||||
throw new Error('No secure random number generator available. This environment does not support crypto.getRandomValues.');
|
||||
});
|
||||
export const crypto = (getRandomValues === getRandomValuesBrowser
|
||||
? cryptoBrowser
|
||||
: { getRandomValues });
|
||||
Reference in New Issue
Block a user