@onekeyfe/react-native-get-random-values 1.1.10

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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +36 -0
  3. package/ReactNativeGetRandomValues.podspec +29 -0
  4. package/android/CMakeLists.txt +24 -0
  5. package/android/build.gradle +128 -0
  6. package/android/gradle.properties +4 -0
  7. package/android/src/main/AndroidManifest.xml +1 -0
  8. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  9. package/android/src/main/java/com/margelo/nitro/reactnativegetrandomvalues/ReactNativeGetRandomValues.kt +15 -0
  10. package/android/src/main/java/com/margelo/nitro/reactnativegetrandomvalues/ReactNativeGetRandomValuesPackage.kt +22 -0
  11. package/ios/ReactNativeGetRandomValues.swift +12 -0
  12. package/lib/module/ReactNativeGetRandomValues.nitro.js +4 -0
  13. package/lib/module/ReactNativeGetRandomValues.nitro.js.map +1 -0
  14. package/lib/module/index.js +86 -0
  15. package/lib/module/index.js.map +1 -0
  16. package/lib/module/module.js +4 -0
  17. package/lib/module/module.js.map +1 -0
  18. package/lib/module/module.native.js +6 -0
  19. package/lib/module/module.native.js.map +1 -0
  20. package/lib/module/package.json +1 -0
  21. package/lib/typescript/package.json +1 -0
  22. package/lib/typescript/src/ReactNativeGetRandomValues.nitro.d.ts +15 -0
  23. package/lib/typescript/src/ReactNativeGetRandomValues.nitro.d.ts.map +1 -0
  24. package/lib/typescript/src/index.d.ts +2 -0
  25. package/lib/typescript/src/index.d.ts.map +1 -0
  26. package/lib/typescript/src/module.d.ts +3 -0
  27. package/lib/typescript/src/module.d.ts.map +1 -0
  28. package/lib/typescript/src/module.native.d.ts +4 -0
  29. package/lib/typescript/src/module.native.d.ts.map +1 -0
  30. package/nitro.json +17 -0
  31. package/nitrogen/generated/android/c++/JHybridReactNativeGetRandomValuesSpec.cpp +52 -0
  32. package/nitrogen/generated/android/c++/JHybridReactNativeGetRandomValuesSpec.hpp +65 -0
  33. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativegetrandomvalues/HybridReactNativeGetRandomValuesSpec.kt +57 -0
  34. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativegetrandomvalues/reactnativegetrandomvaluesOnLoad.kt +35 -0
  35. package/nitrogen/generated/android/reactnativegetrandomvalues+autolinking.cmake +81 -0
  36. package/nitrogen/generated/android/reactnativegetrandomvalues+autolinking.gradle +27 -0
  37. package/nitrogen/generated/android/reactnativegetrandomvaluesOnLoad.cpp +44 -0
  38. package/nitrogen/generated/android/reactnativegetrandomvaluesOnLoad.hpp +25 -0
  39. package/nitrogen/generated/ios/ReactNativeGetRandomValues+autolinking.rb +60 -0
  40. package/nitrogen/generated/ios/ReactNativeGetRandomValues-Swift-Cxx-Bridge.cpp +33 -0
  41. package/nitrogen/generated/ios/ReactNativeGetRandomValues-Swift-Cxx-Bridge.hpp +52 -0
  42. package/nitrogen/generated/ios/ReactNativeGetRandomValues-Swift-Cxx-Umbrella.hpp +44 -0
  43. package/nitrogen/generated/ios/ReactNativeGetRandomValuesAutolinking.mm +33 -0
  44. package/nitrogen/generated/ios/ReactNativeGetRandomValuesAutolinking.swift +25 -0
  45. package/nitrogen/generated/ios/c++/HybridReactNativeGetRandomValuesSpecSwift.cpp +11 -0
  46. package/nitrogen/generated/ios/c++/HybridReactNativeGetRandomValuesSpecSwift.hpp +76 -0
  47. package/nitrogen/generated/ios/swift/HybridReactNativeGetRandomValuesSpec.swift +56 -0
  48. package/nitrogen/generated/ios/swift/HybridReactNativeGetRandomValuesSpec_cxx.swift +131 -0
  49. package/nitrogen/generated/shared/c++/HybridReactNativeGetRandomValuesSpec.cpp +21 -0
  50. package/nitrogen/generated/shared/c++/HybridReactNativeGetRandomValuesSpec.hpp +62 -0
  51. package/package.json +170 -0
  52. package/src/ReactNativeGetRandomValues.nitro.ts +15 -0
  53. package/src/index.tsx +95 -0
  54. package/src/module.native.tsx +8 -0
  55. package/src/module.tsx +4 -0
@@ -0,0 +1,131 @@
1
+ ///
2
+ /// HybridReactNativeGetRandomValuesSpec_cxx.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import Foundation
9
+ import NitroModules
10
+
11
+ /**
12
+ * A class implementation that bridges HybridReactNativeGetRandomValuesSpec over to C++.
13
+ * In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
14
+ *
15
+ * Also, some Swift types need to be bridged with special handling:
16
+ * - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
17
+ * - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
18
+ * - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
19
+ */
20
+ open class HybridReactNativeGetRandomValuesSpec_cxx {
21
+ /**
22
+ * The Swift <> C++ bridge's namespace (`margelo::nitro::reactnativegetrandomvalues::bridge::swift`)
23
+ * from `ReactNativeGetRandomValues-Swift-Cxx-Bridge.hpp`.
24
+ * This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
25
+ */
26
+ public typealias bridge = margelo.nitro.reactnativegetrandomvalues.bridge.swift
27
+
28
+ /**
29
+ * Holds an instance of the `HybridReactNativeGetRandomValuesSpec` Swift protocol.
30
+ */
31
+ private var __implementation: any HybridReactNativeGetRandomValuesSpec
32
+
33
+ /**
34
+ * Holds a weak pointer to the C++ class that wraps the Swift class.
35
+ */
36
+ private var __cxxPart: bridge.std__weak_ptr_HybridReactNativeGetRandomValuesSpec_
37
+
38
+ /**
39
+ * Create a new `HybridReactNativeGetRandomValuesSpec_cxx` that wraps the given `HybridReactNativeGetRandomValuesSpec`.
40
+ * All properties and methods bridge to C++ types.
41
+ */
42
+ public init(_ implementation: any HybridReactNativeGetRandomValuesSpec) {
43
+ self.__implementation = implementation
44
+ self.__cxxPart = .init()
45
+ /* no base class */
46
+ }
47
+
48
+ /**
49
+ * Get the actual `HybridReactNativeGetRandomValuesSpec` instance this class wraps.
50
+ */
51
+ @inline(__always)
52
+ public func getHybridReactNativeGetRandomValuesSpec() -> any HybridReactNativeGetRandomValuesSpec {
53
+ return __implementation
54
+ }
55
+
56
+ /**
57
+ * Casts this instance to a retained unsafe raw pointer.
58
+ * This acquires one additional strong reference on the object!
59
+ */
60
+ public func toUnsafe() -> UnsafeMutableRawPointer {
61
+ return Unmanaged.passRetained(self).toOpaque()
62
+ }
63
+
64
+ /**
65
+ * Casts an unsafe pointer to a `HybridReactNativeGetRandomValuesSpec_cxx`.
66
+ * The pointer has to be a retained opaque `Unmanaged<HybridReactNativeGetRandomValuesSpec_cxx>`.
67
+ * This removes one strong reference from the object!
68
+ */
69
+ public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridReactNativeGetRandomValuesSpec_cxx {
70
+ return Unmanaged<HybridReactNativeGetRandomValuesSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
71
+ }
72
+
73
+ /**
74
+ * Gets (or creates) the C++ part of this Hybrid Object.
75
+ * The C++ part is a `std::shared_ptr<HybridReactNativeGetRandomValuesSpec>`.
76
+ */
77
+ public func getCxxPart() -> bridge.std__shared_ptr_HybridReactNativeGetRandomValuesSpec_ {
78
+ let cachedCxxPart = self.__cxxPart.lock()
79
+ if Bool(fromCxx: cachedCxxPart) {
80
+ return cachedCxxPart
81
+ } else {
82
+ let newCxxPart = bridge.create_std__shared_ptr_HybridReactNativeGetRandomValuesSpec_(self.toUnsafe())
83
+ __cxxPart = bridge.weakify_std__shared_ptr_HybridReactNativeGetRandomValuesSpec_(newCxxPart)
84
+ return newCxxPart
85
+ }
86
+ }
87
+
88
+
89
+
90
+ /**
91
+ * Get the memory size of the Swift class (plus size of any other allocations)
92
+ * so the JS VM can properly track it and garbage-collect the JS object if needed.
93
+ */
94
+ @inline(__always)
95
+ public var memorySize: Int {
96
+ return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
97
+ }
98
+
99
+ /**
100
+ * Call dispose() on the Swift class.
101
+ * This _may_ be called manually from JS.
102
+ */
103
+ @inline(__always)
104
+ public func dispose() {
105
+ self.__implementation.dispose()
106
+ }
107
+
108
+ /**
109
+ * Call toString() on the Swift class.
110
+ */
111
+ @inline(__always)
112
+ public func toString() -> String {
113
+ return self.__implementation.toString()
114
+ }
115
+
116
+ // Properties
117
+
118
+
119
+ // Methods
120
+ @inline(__always)
121
+ public final func getRandomBase64(byteLength: Double) -> bridge.Result_std__string_ {
122
+ do {
123
+ let __result = try self.__implementation.getRandomBase64(byteLength: byteLength)
124
+ let __resultCpp = std.string(__result)
125
+ return bridge.create_Result_std__string_(__resultCpp)
126
+ } catch (let __error) {
127
+ let __exceptionPtr = __error.toCpp()
128
+ return bridge.create_Result_std__string_(__exceptionPtr)
129
+ }
130
+ }
131
+ }
@@ -0,0 +1,21 @@
1
+ ///
2
+ /// HybridReactNativeGetRandomValuesSpec.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridReactNativeGetRandomValuesSpec.hpp"
9
+
10
+ namespace margelo::nitro::reactnativegetrandomvalues {
11
+
12
+ void HybridReactNativeGetRandomValuesSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("getRandomBase64", &HybridReactNativeGetRandomValuesSpec::getRandomBase64);
18
+ });
19
+ }
20
+
21
+ } // namespace margelo::nitro::reactnativegetrandomvalues
@@ -0,0 +1,62 @@
1
+ ///
2
+ /// HybridReactNativeGetRandomValuesSpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+
17
+
18
+ #include <string>
19
+
20
+ namespace margelo::nitro::reactnativegetrandomvalues {
21
+
22
+ using namespace margelo::nitro;
23
+
24
+ /**
25
+ * An abstract base class for `ReactNativeGetRandomValues`
26
+ * Inherit this class to create instances of `HybridReactNativeGetRandomValuesSpec` in C++.
27
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
28
+ * @example
29
+ * ```cpp
30
+ * class HybridReactNativeGetRandomValues: public HybridReactNativeGetRandomValuesSpec {
31
+ * public:
32
+ * HybridReactNativeGetRandomValues(...): HybridObject(TAG) { ... }
33
+ * // ...
34
+ * };
35
+ * ```
36
+ */
37
+ class HybridReactNativeGetRandomValuesSpec: public virtual HybridObject {
38
+ public:
39
+ // Constructor
40
+ explicit HybridReactNativeGetRandomValuesSpec(): HybridObject(TAG) { }
41
+
42
+ // Destructor
43
+ ~HybridReactNativeGetRandomValuesSpec() override = default;
44
+
45
+ public:
46
+ // Properties
47
+
48
+
49
+ public:
50
+ // Methods
51
+ virtual std::string getRandomBase64(double byteLength) = 0;
52
+
53
+ protected:
54
+ // Hybrid Setup
55
+ void loadHybridMethods() override;
56
+
57
+ protected:
58
+ // Tag for logging
59
+ static constexpr auto TAG = "ReactNativeGetRandomValues";
60
+ };
61
+
62
+ } // namespace margelo::nitro::reactnativegetrandomvalues
package/package.json ADDED
@@ -0,0 +1,170 @@
1
+ {
2
+ "name": "@onekeyfe/react-native-get-random-values",
3
+ "version": "1.1.10",
4
+ "description": "react-native-get-random-values",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "source": "./src/index.tsx",
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "android",
19
+ "ios",
20
+ "cpp",
21
+ "nitrogen",
22
+ "nitro.json",
23
+ "*.podspec",
24
+ "react-native.config.js",
25
+ "!ios/build",
26
+ "!android/build",
27
+ "!android/gradle",
28
+ "!android/gradlew",
29
+ "!android/gradlew.bat",
30
+ "!android/local.properties",
31
+ "!**/__tests__",
32
+ "!**/__fixtures__",
33
+ "!**/__mocks__",
34
+ "!**/.*"
35
+ ],
36
+ "scripts": {
37
+ "example": "yarn workspace react-native-get-random-values-example",
38
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
39
+ "prepare": "bob build",
40
+ "nitrogen": "nitrogen",
41
+ "typecheck": "tsc",
42
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
43
+ "test": "jest",
44
+ "release": "yarn prepare && npm whoami && npm publish --access public"
45
+ },
46
+ "keywords": [
47
+ "react-native",
48
+ "ios",
49
+ "android"
50
+ ],
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "git+https://github.com/OneKeyHQ/app-modules/react-native-get-random-values.git"
54
+ },
55
+ "author": "onekeyfe <huanming@onekey.so> (https://github.com/OneKeyHQ/app-modules)",
56
+ "license": "MIT",
57
+ "bugs": {
58
+ "url": "https://github.com/OneKeyHQ/app-modules/react-native-get-random-values/issues"
59
+ },
60
+ "homepage": "https://github.com/OneKeyHQ/app-modules/react-native-get-random-values#readme",
61
+ "publishConfig": {
62
+ "registry": "https://registry.npmjs.org/"
63
+ },
64
+ "devDependencies": {
65
+ "@commitlint/config-conventional": "^19.8.1",
66
+ "@eslint/compat": "^1.3.2",
67
+ "@eslint/eslintrc": "^3.3.1",
68
+ "@eslint/js": "^9.35.0",
69
+ "@react-native/babel-preset": "0.83.0",
70
+ "@react-native/eslint-config": "0.83.0",
71
+ "@release-it/conventional-changelog": "^10.0.1",
72
+ "@types/jest": "^29.5.14",
73
+ "@types/react": "^19.2.0",
74
+ "commitlint": "^19.8.1",
75
+ "del-cli": "^6.0.0",
76
+ "eslint": "^9.35.0",
77
+ "eslint-config-prettier": "^10.1.8",
78
+ "eslint-plugin-prettier": "^5.5.4",
79
+ "jest": "^29.7.0",
80
+ "lefthook": "^2.0.3",
81
+ "nitrogen": "^0.31.10",
82
+ "prettier": "^2.8.8",
83
+ "react": "19.2.0",
84
+ "react-native": "0.83.0",
85
+ "react-native-builder-bob": "^0.40.13",
86
+ "react-native-nitro-modules": "^0.31.10",
87
+ "release-it": "^19.0.4",
88
+ "turbo": "^2.5.6",
89
+ "typescript": "^5.9.2"
90
+ },
91
+ "peerDependencies": {
92
+ "react": "*",
93
+ "react-native": "*",
94
+ "react-native-nitro-modules": "^0.31.10"
95
+ },
96
+ "react-native-builder-bob": {
97
+ "source": "src",
98
+ "output": "lib",
99
+ "targets": [
100
+ [
101
+ "custom",
102
+ {
103
+ "script": "nitrogen",
104
+ "clean": "nitrogen/"
105
+ }
106
+ ],
107
+ [
108
+ "module",
109
+ {
110
+ "esm": true
111
+ }
112
+ ],
113
+ [
114
+ "typescript",
115
+ {
116
+ "project": "tsconfig.build.json"
117
+ }
118
+ ]
119
+ ]
120
+ },
121
+ "prettier": {
122
+ "quoteProps": "consistent",
123
+ "singleQuote": true,
124
+ "tabWidth": 2,
125
+ "trailingComma": "es5",
126
+ "useTabs": false
127
+ },
128
+ "jest": {
129
+ "preset": "react-native",
130
+ "modulePathIgnorePatterns": [
131
+ "<rootDir>/example/node_modules",
132
+ "<rootDir>/lib/"
133
+ ]
134
+ },
135
+ "commitlint": {
136
+ "extends": [
137
+ "@commitlint/config-conventional"
138
+ ]
139
+ },
140
+ "release-it": {
141
+ "git": {
142
+ "commitMessage": "chore: release ${version}",
143
+ "tagName": "v${version}"
144
+ },
145
+ "npm": {
146
+ "publish": true
147
+ },
148
+ "github": {
149
+ "release": true
150
+ },
151
+ "plugins": {
152
+ "@release-it/conventional-changelog": {
153
+ "preset": {
154
+ "name": "angular"
155
+ }
156
+ }
157
+ }
158
+ },
159
+ "create-react-native-library": {
160
+ "type": "nitro-module",
161
+ "languages": "kotlin-swift",
162
+ "tools": [
163
+ "eslint",
164
+ "jest",
165
+ "lefthook",
166
+ "release-it"
167
+ ],
168
+ "version": "0.56.0"
169
+ }
170
+ }
@@ -0,0 +1,15 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+
3
+ export interface ReactNativeGetRandomValuesParams {
4
+ message: string;
5
+ }
6
+
7
+ export interface ReactNativeGetRandomValuesResult {
8
+ success: boolean;
9
+ data: string;
10
+ }
11
+
12
+ export interface ReactNativeGetRandomValues
13
+ extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
14
+ getRandomBase64(byteLength: number): string;
15
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,95 @@
1
+ const base64Decode = require('fast-base64-decode')
2
+ const ExpoCrypto = require('expo-crypto');
3
+ const NativeReactNativeGetRandomValues = require('./module').ReactNativeGetRandomValues;
4
+
5
+ class TypeMismatchError extends Error {}
6
+ class QuotaExceededError extends Error {}
7
+
8
+ let warned = false
9
+ function insecureRandomValues (array: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Uint8ClampedArray) {
10
+ if (!warned) {
11
+ console.warn('Using an insecure random number generator, this should only happen when running in a debugger without support for crypto.getRandomValues')
12
+ warned = true
13
+ }
14
+
15
+ for (let i = 0, r; i < array.length; i++) {
16
+ if ((i & 0x03) === 0) r = Math.random() * 0x100000000
17
+ if (r !== null && r !== undefined) {
18
+ array[i] = (r >>> ((i & 0x03) << 3)) & 0xff
19
+ }
20
+ }
21
+
22
+ return array
23
+ }
24
+
25
+ function markNativeGetRandomValuesCall(message: string, isCallNativeModule: boolean) {
26
+ if (__DEV__) {
27
+ console.log('------------ call crypto.getRandomValues(): ' + message);
28
+ }
29
+ if(isCallNativeModule){
30
+ (global as any).$$onekeyCryptoGetRandomValuesCalls = ((global as any).$$onekeyCryptoGetRandomValuesCalls || 0) + 1;
31
+ (global as any).$$onekeyCryptoGetRandomValuesCallsLastMessage = message;
32
+ }
33
+ }
34
+
35
+ /**
36
+ * @param {number} byteLength
37
+ * @returns {string}
38
+ */
39
+ function getRandomBase64 (byteLength: number) {
40
+ if (NativeReactNativeGetRandomValues.getRandomBase64) {
41
+ markNativeGetRandomValuesCall('NativeModules.RNGetRandomValues.getRandomBase64(byteLength)', true);
42
+ return NativeReactNativeGetRandomValues.getRandomBase64(byteLength)
43
+ } else {
44
+ markNativeGetRandomValuesCall('throw new Error("Native module not found")', false);
45
+ throw new Error('Native module not found')
46
+ }
47
+ }
48
+
49
+ /**
50
+ * @param {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Uint8ClampedArray} array
51
+ */
52
+ function getRandomValues (array: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Uint8ClampedArray) {
53
+ if (!(array instanceof Int8Array || array instanceof Uint8Array || array instanceof Int16Array || array instanceof Uint16Array || array instanceof Int32Array || array instanceof Uint32Array || array instanceof Uint8ClampedArray)) {
54
+ markNativeGetRandomValuesCall('throw new TypeMismatchError("Expected an integer array")', false);
55
+ throw new TypeMismatchError('Expected an integer array')
56
+ }
57
+
58
+ if (array.byteLength > 65536) {
59
+ markNativeGetRandomValuesCall('throw new QuotaExceededError("Can only request a maximum of 65536 bytes")', false);
60
+ throw new QuotaExceededError('Can only request a maximum of 65536 bytes')
61
+ }
62
+
63
+ // Expo SDK 48+
64
+ if (ExpoCrypto.getRandomValues) {
65
+ markNativeGetRandomValuesCall('Expo SDK 48+ global.expo.modules.ExpoCrypto.getRandomValues(array)', true);
66
+ // ExpoCrypto.getRandomValues doesn't return the array
67
+ ExpoCrypto.getRandomValues(array)
68
+ return array
69
+ }
70
+
71
+ // Calling getRandomBase64 in debug mode leads to the error
72
+ // "Calling synchronous methods on native modules is not supported in Chrome".
73
+ // So in that specific case we fall back to just using Math.random.
74
+ if (__DEV__) {
75
+ if (typeof (global as any).nativeCallSyncHook === 'undefined') {
76
+ markNativeGetRandomValuesCall('insecureRandomValues(array)', false);
77
+ return insecureRandomValues(array)
78
+ }
79
+ }
80
+
81
+ base64Decode(getRandomBase64(array.byteLength), new Uint8Array(array.buffer, array.byteOffset, array.byteLength))
82
+
83
+ return array
84
+ }
85
+
86
+ if (typeof global.crypto !== 'object') {
87
+ (global as any).crypto = {}
88
+ }
89
+
90
+ if (typeof global.crypto.getRandomValues !== 'function') {
91
+ (global as any).crypto.getRandomValues = getRandomValues
92
+ }
93
+
94
+
95
+ export { ReactNativeGetRandomValues } from './module';
@@ -0,0 +1,8 @@
1
+ import { NitroModules } from 'react-native-nitro-modules';
2
+ import type { ReactNativeGetRandomValues as ReactNativeGetRandomValuesType } from './ReactNativeGetRandomValues.nitro';
3
+
4
+ const ReactNativeGetRandomValuesHybridObject =
5
+ NitroModules.createHybridObject<ReactNativeGetRandomValuesType>('ReactNativeGetRandomValues');
6
+
7
+ export const ReactNativeGetRandomValues = ReactNativeGetRandomValuesHybridObject;
8
+ export type * from './ReactNativeGetRandomValues.nitro';
package/src/module.tsx ADDED
@@ -0,0 +1,4 @@
1
+ import type { ReactNativeGetRandomValues as ReactNativeGetRandomValuesType } from './ReactNativeGetRandomValues.nitro';
2
+
3
+ export const ReactNativeGetRandomValues = {
4
+ } as ReactNativeGetRandomValuesType;