@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.
- package/LICENSE +21 -0
- package/README.md +36 -0
- package/ReactNativeGetRandomValues.podspec +29 -0
- package/android/CMakeLists.txt +24 -0
- package/android/build.gradle +128 -0
- package/android/gradle.properties +4 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/reactnativegetrandomvalues/ReactNativeGetRandomValues.kt +15 -0
- package/android/src/main/java/com/margelo/nitro/reactnativegetrandomvalues/ReactNativeGetRandomValuesPackage.kt +22 -0
- package/ios/ReactNativeGetRandomValues.swift +12 -0
- package/lib/module/ReactNativeGetRandomValues.nitro.js +4 -0
- package/lib/module/ReactNativeGetRandomValues.nitro.js.map +1 -0
- package/lib/module/index.js +86 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/module.js +4 -0
- package/lib/module/module.js.map +1 -0
- package/lib/module/module.native.js +6 -0
- package/lib/module/module.native.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/ReactNativeGetRandomValues.nitro.d.ts +15 -0
- package/lib/typescript/src/ReactNativeGetRandomValues.nitro.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +2 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/module.d.ts +3 -0
- package/lib/typescript/src/module.d.ts.map +1 -0
- package/lib/typescript/src/module.native.d.ts +4 -0
- package/lib/typescript/src/module.native.d.ts.map +1 -0
- package/nitro.json +17 -0
- package/nitrogen/generated/android/c++/JHybridReactNativeGetRandomValuesSpec.cpp +52 -0
- package/nitrogen/generated/android/c++/JHybridReactNativeGetRandomValuesSpec.hpp +65 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativegetrandomvalues/HybridReactNativeGetRandomValuesSpec.kt +57 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativegetrandomvalues/reactnativegetrandomvaluesOnLoad.kt +35 -0
- package/nitrogen/generated/android/reactnativegetrandomvalues+autolinking.cmake +81 -0
- package/nitrogen/generated/android/reactnativegetrandomvalues+autolinking.gradle +27 -0
- package/nitrogen/generated/android/reactnativegetrandomvaluesOnLoad.cpp +44 -0
- package/nitrogen/generated/android/reactnativegetrandomvaluesOnLoad.hpp +25 -0
- package/nitrogen/generated/ios/ReactNativeGetRandomValues+autolinking.rb +60 -0
- package/nitrogen/generated/ios/ReactNativeGetRandomValues-Swift-Cxx-Bridge.cpp +33 -0
- package/nitrogen/generated/ios/ReactNativeGetRandomValues-Swift-Cxx-Bridge.hpp +52 -0
- package/nitrogen/generated/ios/ReactNativeGetRandomValues-Swift-Cxx-Umbrella.hpp +44 -0
- package/nitrogen/generated/ios/ReactNativeGetRandomValuesAutolinking.mm +33 -0
- package/nitrogen/generated/ios/ReactNativeGetRandomValuesAutolinking.swift +25 -0
- package/nitrogen/generated/ios/c++/HybridReactNativeGetRandomValuesSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridReactNativeGetRandomValuesSpecSwift.hpp +76 -0
- package/nitrogen/generated/ios/swift/HybridReactNativeGetRandomValuesSpec.swift +56 -0
- package/nitrogen/generated/ios/swift/HybridReactNativeGetRandomValuesSpec_cxx.swift +131 -0
- package/nitrogen/generated/shared/c++/HybridReactNativeGetRandomValuesSpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridReactNativeGetRandomValuesSpec.hpp +62 -0
- package/package.json +170 -0
- package/src/ReactNativeGetRandomValues.nitro.ts +15 -0
- package/src/index.tsx +95 -0
- package/src/module.native.tsx +8 -0
- package/src/module.tsx +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 OneKey
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# react-native-get-random-values
|
|
2
|
+
|
|
3
|
+
react-native-get-random-values
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install react-native-get-random-values react-native-nitro-modules
|
|
9
|
+
|
|
10
|
+
> `react-native-nitro-modules` is required as this library relies on [Nitro Modules](https://nitro.margelo.com/).
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { ReactNativeGetRandomValues } from 'react-native-get-random-values';
|
|
17
|
+
|
|
18
|
+
// ...
|
|
19
|
+
|
|
20
|
+
const result = await ReactNativeGetRandomValues.hello({ message: 'World' });
|
|
21
|
+
console.log(result); // { success: true, data: 'Hello, World!' }
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Contributing
|
|
25
|
+
|
|
26
|
+
- [Development workflow](CONTRIBUTING.md#development-workflow)
|
|
27
|
+
- [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
|
|
28
|
+
- [Code of conduct](CODE_OF_CONDUCT.md)
|
|
29
|
+
|
|
30
|
+
## License
|
|
31
|
+
|
|
32
|
+
MIT
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "ReactNativeGetRandomValues"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
14
|
+
s.source = { :git => "https://github.com/OneKeyHQ/app-modules/react-native-get-random-values.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = [
|
|
17
|
+
"ios/**/*.{swift}",
|
|
18
|
+
"ios/**/*.{m,mm}",
|
|
19
|
+
"cpp/**/*.{hpp,cpp}",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
s.dependency 'React-jsi'
|
|
23
|
+
s.dependency 'React-callinvoker'
|
|
24
|
+
|
|
25
|
+
load 'nitrogen/generated/ios/ReactNativeGetRandomValues+autolinking.rb'
|
|
26
|
+
add_nitrogen_files(s)
|
|
27
|
+
|
|
28
|
+
install_modules_dependencies(s)
|
|
29
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
project(reactnativegetrandomvalues)
|
|
2
|
+
cmake_minimum_required(VERSION 3.9.0)
|
|
3
|
+
|
|
4
|
+
set(PACKAGE_NAME reactnativegetrandomvalues)
|
|
5
|
+
set(CMAKE_VERBOSE_MAKEFILE ON)
|
|
6
|
+
set(CMAKE_CXX_STANDARD 20)
|
|
7
|
+
|
|
8
|
+
# Define C++ library and add all sources
|
|
9
|
+
add_library(${PACKAGE_NAME} SHARED src/main/cpp/cpp-adapter.cpp)
|
|
10
|
+
|
|
11
|
+
# Add Nitrogen specs :)
|
|
12
|
+
include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/reactnativegetrandomvalues+autolinking.cmake)
|
|
13
|
+
|
|
14
|
+
# Set up local includes
|
|
15
|
+
include_directories("src/main/cpp" "../cpp")
|
|
16
|
+
|
|
17
|
+
find_library(LOG_LIB log)
|
|
18
|
+
|
|
19
|
+
# Link all libraries together
|
|
20
|
+
target_link_libraries(
|
|
21
|
+
${PACKAGE_NAME}
|
|
22
|
+
${LOG_LIB}
|
|
23
|
+
android # <-- Android core
|
|
24
|
+
)
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.getExtOrDefault = {name ->
|
|
3
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['ReactNativeGetRandomValues_' + name]
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
repositories {
|
|
7
|
+
google()
|
|
8
|
+
mavenCentral()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
dependencies {
|
|
12
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
13
|
+
// noinspection DifferentKotlinGradleVersion
|
|
14
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
def reactNativeArchitectures() {
|
|
19
|
+
def value = rootProject.getProperties().get("reactNativeArchitectures")
|
|
20
|
+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
apply plugin: "com.android.library"
|
|
24
|
+
apply plugin: "kotlin-android"
|
|
25
|
+
apply from: '../nitrogen/generated/android/reactnativegetrandomvalues+autolinking.gradle'
|
|
26
|
+
|
|
27
|
+
apply plugin: "com.facebook.react"
|
|
28
|
+
|
|
29
|
+
def getExtOrIntegerDefault(name) {
|
|
30
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["ReactNativeGetRandomValues_" + name]).toInteger()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
android {
|
|
34
|
+
namespace "com.margelo.nitro.reactnativegetrandomvalues"
|
|
35
|
+
|
|
36
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
37
|
+
|
|
38
|
+
defaultConfig {
|
|
39
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
40
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
41
|
+
|
|
42
|
+
externalNativeBuild {
|
|
43
|
+
cmake {
|
|
44
|
+
cppFlags "-frtti -fexceptions -Wall -fstack-protector-all"
|
|
45
|
+
arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
|
|
46
|
+
abiFilters (*reactNativeArchitectures())
|
|
47
|
+
|
|
48
|
+
buildTypes {
|
|
49
|
+
debug {
|
|
50
|
+
cppFlags "-O1 -g"
|
|
51
|
+
}
|
|
52
|
+
release {
|
|
53
|
+
cppFlags "-O2"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
externalNativeBuild {
|
|
61
|
+
cmake {
|
|
62
|
+
path "CMakeLists.txt"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
packagingOptions {
|
|
67
|
+
excludes = [
|
|
68
|
+
"META-INF",
|
|
69
|
+
"META-INF/**",
|
|
70
|
+
"**/libc++_shared.so",
|
|
71
|
+
"**/libfbjni.so",
|
|
72
|
+
"**/libjsi.so",
|
|
73
|
+
"**/libfolly_json.so",
|
|
74
|
+
"**/libfolly_runtime.so",
|
|
75
|
+
"**/libglog.so",
|
|
76
|
+
"**/libhermes.so",
|
|
77
|
+
"**/libhermes-executor-debug.so",
|
|
78
|
+
"**/libhermes_executor.so",
|
|
79
|
+
"**/libreactnative.so",
|
|
80
|
+
"**/libreactnativejni.so",
|
|
81
|
+
"**/libturbomodulejsijni.so",
|
|
82
|
+
"**/libreact_nativemodule_core.so",
|
|
83
|
+
"**/libjscexecutor.so"
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
buildFeatures {
|
|
88
|
+
buildConfig true
|
|
89
|
+
prefab true
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
buildTypes {
|
|
93
|
+
release {
|
|
94
|
+
minifyEnabled false
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
lintOptions {
|
|
99
|
+
disable "GradleCompatible"
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
compileOptions {
|
|
103
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
104
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
sourceSets {
|
|
108
|
+
main {
|
|
109
|
+
java.srcDirs += [
|
|
110
|
+
"generated/java",
|
|
111
|
+
"generated/jni"
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
repositories {
|
|
118
|
+
mavenCentral()
|
|
119
|
+
google()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
123
|
+
|
|
124
|
+
dependencies {
|
|
125
|
+
implementation "com.facebook.react:react-android"
|
|
126
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
127
|
+
implementation project(":react-native-nitro-modules")
|
|
128
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
package com.margelo.nitro.reactnativegetrandomvalues
|
|
2
|
+
|
|
3
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
4
|
+
|
|
5
|
+
@DoNotStrip
|
|
6
|
+
class ReactNativeGetRandomValues : HybridReactNativeGetRandomValuesSpec() {
|
|
7
|
+
override fun getRandomBase64(byteLength: Double): String {
|
|
8
|
+
val data = ByteArray(byteLength.toInt())
|
|
9
|
+
val random = java.security.SecureRandom()
|
|
10
|
+
|
|
11
|
+
random.nextBytes(data)
|
|
12
|
+
|
|
13
|
+
return android.util.Base64.encodeToString(data, android.util.Base64.NO_WRAP)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
package com.margelo.nitro.reactnativegetrandomvalues
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
7
|
+
|
|
8
|
+
class ReactNativeGetRandomValuesPackage : BaseReactPackage() {
|
|
9
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
10
|
+
return null
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
14
|
+
return ReactModuleInfoProvider { HashMap() }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
companion object {
|
|
18
|
+
init {
|
|
19
|
+
System.loadLibrary("reactnativegetrandomvalues")
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import NitroModules
|
|
2
|
+
|
|
3
|
+
class ReactNativeGetRandomValues: HybridReactNativeGetRandomValuesSpec {
|
|
4
|
+
func getRandomBase64(byteLength: Double) throws -> String {
|
|
5
|
+
let data = NSMutableData(length: Int(byteLength))!
|
|
6
|
+
let result = SecRandomCopyBytes(kSecRandomDefault, Int(byteLength), data.mutableBytes)
|
|
7
|
+
if result != errSecSuccess {
|
|
8
|
+
throw NSError(domain: "ReactNativeGetRandomValues", code: Int(result), userInfo: nil)
|
|
9
|
+
}
|
|
10
|
+
return data.base64EncodedString(options: .lineLength64Characters)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["ReactNativeGetRandomValues.nitro.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const base64Decode = require('fast-base64-decode');
|
|
4
|
+
const ExpoCrypto = require('expo-crypto');
|
|
5
|
+
const NativeReactNativeGetRandomValues = require('./module').ReactNativeGetRandomValues;
|
|
6
|
+
class TypeMismatchError extends Error {}
|
|
7
|
+
class QuotaExceededError extends Error {}
|
|
8
|
+
let warned = false;
|
|
9
|
+
function insecureRandomValues(array) {
|
|
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
|
+
for (let i = 0, r; i < array.length; i++) {
|
|
15
|
+
if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
|
|
16
|
+
if (r !== null && r !== undefined) {
|
|
17
|
+
array[i] = r >>> ((i & 0x03) << 3) & 0xff;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return array;
|
|
21
|
+
}
|
|
22
|
+
function markNativeGetRandomValuesCall(message, isCallNativeModule) {
|
|
23
|
+
if (__DEV__) {
|
|
24
|
+
console.log('------------ call crypto.getRandomValues(): ' + message);
|
|
25
|
+
}
|
|
26
|
+
if (isCallNativeModule) {
|
|
27
|
+
global.$$onekeyCryptoGetRandomValuesCalls = (global.$$onekeyCryptoGetRandomValuesCalls || 0) + 1;
|
|
28
|
+
global.$$onekeyCryptoGetRandomValuesCallsLastMessage = message;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {number} byteLength
|
|
34
|
+
* @returns {string}
|
|
35
|
+
*/
|
|
36
|
+
function getRandomBase64(byteLength) {
|
|
37
|
+
if (NativeReactNativeGetRandomValues.getRandomBase64) {
|
|
38
|
+
markNativeGetRandomValuesCall('NativeModules.RNGetRandomValues.getRandomBase64(byteLength)', true);
|
|
39
|
+
return NativeReactNativeGetRandomValues.getRandomBase64(byteLength);
|
|
40
|
+
} else {
|
|
41
|
+
markNativeGetRandomValuesCall('throw new Error("Native module not found")', false);
|
|
42
|
+
throw new Error('Native module not found');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @param {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Uint8ClampedArray} array
|
|
48
|
+
*/
|
|
49
|
+
function getRandomValues(array) {
|
|
50
|
+
if (!(array instanceof Int8Array || array instanceof Uint8Array || array instanceof Int16Array || array instanceof Uint16Array || array instanceof Int32Array || array instanceof Uint32Array || array instanceof Uint8ClampedArray)) {
|
|
51
|
+
markNativeGetRandomValuesCall('throw new TypeMismatchError("Expected an integer array")', false);
|
|
52
|
+
throw new TypeMismatchError('Expected an integer array');
|
|
53
|
+
}
|
|
54
|
+
if (array.byteLength > 65536) {
|
|
55
|
+
markNativeGetRandomValuesCall('throw new QuotaExceededError("Can only request a maximum of 65536 bytes")', false);
|
|
56
|
+
throw new QuotaExceededError('Can only request a maximum of 65536 bytes');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Expo SDK 48+
|
|
60
|
+
if (ExpoCrypto.getRandomValues) {
|
|
61
|
+
markNativeGetRandomValuesCall('Expo SDK 48+ global.expo.modules.ExpoCrypto.getRandomValues(array)', true);
|
|
62
|
+
// ExpoCrypto.getRandomValues doesn't return the array
|
|
63
|
+
ExpoCrypto.getRandomValues(array);
|
|
64
|
+
return array;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Calling getRandomBase64 in debug mode leads to the error
|
|
68
|
+
// "Calling synchronous methods on native modules is not supported in Chrome".
|
|
69
|
+
// So in that specific case we fall back to just using Math.random.
|
|
70
|
+
if (__DEV__) {
|
|
71
|
+
if (typeof global.nativeCallSyncHook === 'undefined') {
|
|
72
|
+
markNativeGetRandomValuesCall('insecureRandomValues(array)', false);
|
|
73
|
+
return insecureRandomValues(array);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
base64Decode(getRandomBase64(array.byteLength), new Uint8Array(array.buffer, array.byteOffset, array.byteLength));
|
|
77
|
+
return array;
|
|
78
|
+
}
|
|
79
|
+
if (typeof global.crypto !== 'object') {
|
|
80
|
+
global.crypto = {};
|
|
81
|
+
}
|
|
82
|
+
if (typeof global.crypto.getRandomValues !== 'function') {
|
|
83
|
+
global.crypto.getRandomValues = getRandomValues;
|
|
84
|
+
}
|
|
85
|
+
export { ReactNativeGetRandomValues } from './module';
|
|
86
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["base64Decode","require","ExpoCrypto","NativeReactNativeGetRandomValues","ReactNativeGetRandomValues","TypeMismatchError","Error","QuotaExceededError","warned","insecureRandomValues","array","console","warn","i","r","length","Math","random","undefined","markNativeGetRandomValuesCall","message","isCallNativeModule","__DEV__","log","global","$$onekeyCryptoGetRandomValuesCalls","$$onekeyCryptoGetRandomValuesCallsLastMessage","getRandomBase64","byteLength","getRandomValues","Int8Array","Uint8Array","Int16Array","Uint16Array","Int32Array","Uint32Array","Uint8ClampedArray","nativeCallSyncHook","buffer","byteOffset","crypto"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,MAAMA,YAAY,GAAGC,OAAO,CAAC,oBAAoB,CAAC;AAClD,MAAMC,UAAU,GAAGD,OAAO,CAAC,aAAa,CAAC;AACzC,MAAME,gCAAgC,GAAGF,OAAO,CAAC,UAAU,CAAC,CAACG,0BAA0B;AAEvF,MAAMC,iBAAiB,SAASC,KAAK,CAAC;AACtC,MAAMC,kBAAkB,SAASD,KAAK,CAAC;AAEvC,IAAIE,MAAM,GAAG,KAAK;AAClB,SAASC,oBAAoBA,CAAEC,KAAuG,EAAE;EACtI,IAAI,CAACF,MAAM,EAAE;IACXG,OAAO,CAACC,IAAI,CAAC,0IAA0I,CAAC;IACxJJ,MAAM,GAAG,IAAI;EACf;EAEA,KAAK,IAAIK,CAAC,GAAG,CAAC,EAAEC,CAAC,EAAED,CAAC,GAAGH,KAAK,CAACK,MAAM,EAAEF,CAAC,EAAE,EAAE;IACxC,IAAI,CAACA,CAAC,GAAG,IAAI,MAAM,CAAC,EAAEC,CAAC,GAAGE,IAAI,CAACC,MAAM,CAAC,CAAC,GAAG,WAAW;IACrD,IAAIH,CAAC,KAAK,IAAI,IAAIA,CAAC,KAAKI,SAAS,EAAE;MACjCR,KAAK,CAACG,CAAC,CAAC,GAAIC,CAAC,MAAM,CAACD,CAAC,GAAG,IAAI,KAAK,CAAC,CAAC,GAAI,IAAI;IAC7C;EACF;EAEA,OAAOH,KAAK;AACd;AAEA,SAASS,6BAA6BA,CAACC,OAAe,EAAEC,kBAA2B,EAAE;EACnF,IAAIC,OAAO,EAAE;IACXX,OAAO,CAACY,GAAG,CAAC,8CAA8C,GAAGH,OAAO,CAAC;EACvE;EACA,IAAGC,kBAAkB,EAAC;IACnBG,MAAM,CAASC,kCAAkC,GAAG,CAAED,MAAM,CAASC,kCAAkC,IAAI,CAAC,IAAI,CAAC;IACjHD,MAAM,CAASE,6CAA6C,GAAGN,OAAO;EACzE;AACF;;AAEA;AACA;AACA;AACA;AACA,SAASO,eAAeA,CAAEC,UAAkB,EAAE;EAC5C,IAAIzB,gCAAgC,CAACwB,eAAe,EAAE;IACpDR,6BAA6B,CAAC,6DAA6D,EAAE,IAAI,CAAC;IAClG,OAAOhB,gCAAgC,CAACwB,eAAe,CAACC,UAAU,CAAC;EACrE,CAAC,MAAM;IACLT,6BAA6B,CAAC,4CAA4C,EAAE,KAAK,CAAC;IAClF,MAAM,IAAIb,KAAK,CAAC,yBAAyB,CAAC;EAC5C;AACF;;AAEA;AACA;AACA;AACA,SAASuB,eAAeA,CAAEnB,KAAuG,EAAE;EACjI,IAAI,EAAEA,KAAK,YAAYoB,SAAS,IAAIpB,KAAK,YAAYqB,UAAU,IAAIrB,KAAK,YAAYsB,UAAU,IAAItB,KAAK,YAAYuB,WAAW,IAAIvB,KAAK,YAAYwB,UAAU,IAAIxB,KAAK,YAAYyB,WAAW,IAAIzB,KAAK,YAAY0B,iBAAiB,CAAC,EAAE;IACpOjB,6BAA6B,CAAC,0DAA0D,EAAE,KAAK,CAAC;IAChG,MAAM,IAAId,iBAAiB,CAAC,2BAA2B,CAAC;EAC1D;EAEA,IAAIK,KAAK,CAACkB,UAAU,GAAG,KAAK,EAAE;IAC5BT,6BAA6B,CAAC,2EAA2E,EAAE,KAAK,CAAC;IACjH,MAAM,IAAIZ,kBAAkB,CAAC,2CAA2C,CAAC;EAC3E;;EAEA;EACA,IAAIL,UAAU,CAAC2B,eAAe,EAAE;IAC9BV,6BAA6B,CAAC,oEAAoE,EAAE,IAAI,CAAC;IACzG;IACAjB,UAAU,CAAC2B,eAAe,CAACnB,KAAK,CAAC;IACjC,OAAOA,KAAK;EACd;;EAEA;EACA;EACA;EACA,IAAIY,OAAO,EAAE;IACX,IAAI,OAAQE,MAAM,CAASa,kBAAkB,KAAK,WAAW,EAAE;MAC7DlB,6BAA6B,CAAC,6BAA6B,EAAE,KAAK,CAAC;MACnE,OAAOV,oBAAoB,CAACC,KAAK,CAAC;IACpC;EACF;EAEAV,YAAY,CAAC2B,eAAe,CAACjB,KAAK,CAACkB,UAAU,CAAC,EAAE,IAAIG,UAAU,CAACrB,KAAK,CAAC4B,MAAM,EAAE5B,KAAK,CAAC6B,UAAU,EAAE7B,KAAK,CAACkB,UAAU,CAAC,CAAC;EAEjH,OAAOlB,KAAK;AACd;AAEA,IAAI,OAAOc,MAAM,CAACgB,MAAM,KAAK,QAAQ,EAAE;EACpChB,MAAM,CAASgB,MAAM,GAAG,CAAC,CAAC;AAC7B;AAEA,IAAI,OAAOhB,MAAM,CAACgB,MAAM,CAACX,eAAe,KAAK,UAAU,EAAE;EACtDL,MAAM,CAASgB,MAAM,CAACX,eAAe,GAAGA,eAAe;AAC1D;AAGA,SAASzB,0BAA0B,QAAQ,UAAU","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ReactNativeGetRandomValues"],"sourceRoot":"../../src","sources":["module.tsx"],"mappings":";;AAEA,OAAO,MAAMA,0BAA0B,GAAG,CAC1C,CAAmC","ignoreList":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
4
|
+
const ReactNativeGetRandomValuesHybridObject = NitroModules.createHybridObject('ReactNativeGetRandomValues');
|
|
5
|
+
export const ReactNativeGetRandomValues = ReactNativeGetRandomValuesHybridObject;
|
|
6
|
+
//# sourceMappingURL=module.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NitroModules","ReactNativeGetRandomValuesHybridObject","createHybridObject","ReactNativeGetRandomValues"],"sourceRoot":"../../src","sources":["module.native.tsx"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAGzD,MAAMC,sCAAsC,GAC1CD,YAAY,CAACE,kBAAkB,CAAiC,4BAA4B,CAAC;AAE/F,OAAO,MAAMC,0BAA0B,GAAGF,sCAAsC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
export interface ReactNativeGetRandomValuesParams {
|
|
3
|
+
message: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ReactNativeGetRandomValuesResult {
|
|
6
|
+
success: boolean;
|
|
7
|
+
data: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ReactNativeGetRandomValues extends HybridObject<{
|
|
10
|
+
ios: 'swift';
|
|
11
|
+
android: 'kotlin';
|
|
12
|
+
}> {
|
|
13
|
+
getRandomBase64(byteLength: number): string;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=ReactNativeGetRandomValues.nitro.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactNativeGetRandomValues.nitro.d.ts","sourceRoot":"","sources":["../../../src/ReactNativeGetRandomValues.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,WAAW,gCAAgC;IAC/C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gCAAgC;IAC/C,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,0BACf,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,CAAC;IACzD,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;CAC7C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AA8FA,OAAO,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../src/module.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,IAAI,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AAEvH,eAAO,MAAM,0BAA0B,EAClC,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ReactNativeGetRandomValues as ReactNativeGetRandomValuesType } from './ReactNativeGetRandomValues.nitro';
|
|
2
|
+
export declare const ReactNativeGetRandomValues: ReactNativeGetRandomValuesType;
|
|
3
|
+
export type * from './ReactNativeGetRandomValues.nitro';
|
|
4
|
+
//# sourceMappingURL=module.native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.native.d.ts","sourceRoot":"","sources":["../../../src/module.native.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,0BAA0B,IAAI,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AAKvH,eAAO,MAAM,0BAA0B,gCAAyC,CAAC;AACjF,mBAAmB,oCAAoC,CAAC"}
|
package/nitro.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cxxNamespace": ["reactnativegetrandomvalues"],
|
|
3
|
+
"ios": {
|
|
4
|
+
"iosModuleName": "ReactNativeGetRandomValues"
|
|
5
|
+
},
|
|
6
|
+
"android": {
|
|
7
|
+
"androidNamespace": ["reactnativegetrandomvalues"],
|
|
8
|
+
"androidCxxLibName": "reactnativegetrandomvalues"
|
|
9
|
+
},
|
|
10
|
+
"autolinking": {
|
|
11
|
+
"ReactNativeGetRandomValues": {
|
|
12
|
+
"swift": "ReactNativeGetRandomValues",
|
|
13
|
+
"kotlin": "ReactNativeGetRandomValues"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"ignorePaths": ["node_modules"]
|
|
17
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JHybridReactNativeGetRandomValuesSpec.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 "JHybridReactNativeGetRandomValuesSpec.hpp"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
#include <string>
|
|
13
|
+
|
|
14
|
+
namespace margelo::nitro::reactnativegetrandomvalues {
|
|
15
|
+
|
|
16
|
+
jni::local_ref<JHybridReactNativeGetRandomValuesSpec::jhybriddata> JHybridReactNativeGetRandomValuesSpec::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
|
17
|
+
return makeCxxInstance(jThis);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
void JHybridReactNativeGetRandomValuesSpec::registerNatives() {
|
|
21
|
+
registerHybrid({
|
|
22
|
+
makeNativeMethod("initHybrid", JHybridReactNativeGetRandomValuesSpec::initHybrid),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
size_t JHybridReactNativeGetRandomValuesSpec::getExternalMemorySize() noexcept {
|
|
27
|
+
static const auto method = javaClassStatic()->getMethod<jlong()>("getMemorySize");
|
|
28
|
+
return method(_javaPart);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
void JHybridReactNativeGetRandomValuesSpec::dispose() noexcept {
|
|
32
|
+
static const auto method = javaClassStatic()->getMethod<void()>("dispose");
|
|
33
|
+
method(_javaPart);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
std::string JHybridReactNativeGetRandomValuesSpec::toString() {
|
|
37
|
+
static const auto method = javaClassStatic()->getMethod<jni::JString()>("toString");
|
|
38
|
+
auto javaString = method(_javaPart);
|
|
39
|
+
return javaString->toStdString();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Properties
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
// Methods
|
|
46
|
+
std::string JHybridReactNativeGetRandomValuesSpec::getRandomBase64(double byteLength) {
|
|
47
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<jni::JString>(double /* byteLength */)>("getRandomBase64");
|
|
48
|
+
auto __result = method(_javaPart, byteLength);
|
|
49
|
+
return __result->toStdString();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
} // namespace margelo::nitro::reactnativegetrandomvalues
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
#include <NitroModules/JHybridObject.hpp>
|
|
11
|
+
#include <fbjni/fbjni.h>
|
|
12
|
+
#include "HybridReactNativeGetRandomValuesSpec.hpp"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
namespace margelo::nitro::reactnativegetrandomvalues {
|
|
18
|
+
|
|
19
|
+
using namespace facebook;
|
|
20
|
+
|
|
21
|
+
class JHybridReactNativeGetRandomValuesSpec: public jni::HybridClass<JHybridReactNativeGetRandomValuesSpec, JHybridObject>,
|
|
22
|
+
public virtual HybridReactNativeGetRandomValuesSpec {
|
|
23
|
+
public:
|
|
24
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/reactnativegetrandomvalues/HybridReactNativeGetRandomValuesSpec;";
|
|
25
|
+
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
|
|
26
|
+
static void registerNatives();
|
|
27
|
+
|
|
28
|
+
protected:
|
|
29
|
+
// C++ constructor (called from Java via `initHybrid()`)
|
|
30
|
+
explicit JHybridReactNativeGetRandomValuesSpec(jni::alias_ref<jhybridobject> jThis) :
|
|
31
|
+
HybridObject(HybridReactNativeGetRandomValuesSpec::TAG),
|
|
32
|
+
HybridBase(jThis),
|
|
33
|
+
_javaPart(jni::make_global(jThis)) {}
|
|
34
|
+
|
|
35
|
+
public:
|
|
36
|
+
~JHybridReactNativeGetRandomValuesSpec() override {
|
|
37
|
+
// Hermes GC can destroy JS objects on a non-JNI Thread.
|
|
38
|
+
jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public:
|
|
42
|
+
size_t getExternalMemorySize() noexcept override;
|
|
43
|
+
void dispose() noexcept override;
|
|
44
|
+
std::string toString() override;
|
|
45
|
+
|
|
46
|
+
public:
|
|
47
|
+
inline const jni::global_ref<JHybridReactNativeGetRandomValuesSpec::javaobject>& getJavaPart() const noexcept {
|
|
48
|
+
return _javaPart;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
// Properties
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
// Methods
|
|
57
|
+
std::string getRandomBase64(double byteLength) override;
|
|
58
|
+
|
|
59
|
+
private:
|
|
60
|
+
friend HybridBase;
|
|
61
|
+
using HybridBase::HybridBase;
|
|
62
|
+
jni::global_ref<JHybridReactNativeGetRandomValuesSpec::javaobject> _javaPart;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
} // namespace margelo::nitro::reactnativegetrandomvalues
|