@onekeyfe/react-native-get-random-values 1.1.18 → 1.1.20
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/android/build.gradle
CHANGED
|
@@ -125,4 +125,6 @@ dependencies {
|
|
|
125
125
|
implementation "com.facebook.react:react-android"
|
|
126
126
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
127
127
|
implementation project(":react-native-nitro-modules")
|
|
128
|
+
|
|
129
|
+
implementation project(":react-native-native-logger")
|
|
128
130
|
}
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
package com.margelo.nitro.reactnativegetrandomvalues
|
|
2
2
|
|
|
3
3
|
import com.facebook.proguard.annotations.DoNotStrip
|
|
4
|
+
import com.margelo.nitro.nativelogger.OneKeyLog
|
|
4
5
|
|
|
5
6
|
@DoNotStrip
|
|
6
7
|
class ReactNativeGetRandomValues : HybridReactNativeGetRandomValuesSpec() {
|
|
7
8
|
override fun getRandomBase64(byteLength: Double): String {
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
try {
|
|
10
|
+
val data = ByteArray(byteLength.toInt())
|
|
11
|
+
val random = java.security.SecureRandom()
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
random.nextBytes(data)
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
return android.util.Base64.encodeToString(data, android.util.Base64.NO_WRAP)
|
|
16
|
+
} catch (e: Exception) {
|
|
17
|
+
OneKeyLog.error("RandomValues", "SecureRandom failed: ${e.message}")
|
|
18
|
+
throw e
|
|
19
|
+
}
|
|
14
20
|
}
|
|
15
21
|
}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import NitroModules
|
|
2
|
+
import ReactNativeNativeLogger
|
|
2
3
|
|
|
3
4
|
class ReactNativeGetRandomValues: HybridReactNativeGetRandomValuesSpec {
|
|
4
5
|
func getRandomBase64(byteLength: Double) throws -> String {
|
|
5
|
-
let
|
|
6
|
-
let
|
|
6
|
+
let length = Int(byteLength)
|
|
7
|
+
guard length > 0, let data = NSMutableData(length: length) else {
|
|
8
|
+
OneKeyLog.error("RandomValues", "Failed to allocate buffer of size \(Int(byteLength))")
|
|
9
|
+
throw NSError(domain: "ReactNativeGetRandomValues", code: -1, userInfo: nil)
|
|
10
|
+
}
|
|
11
|
+
let result = SecRandomCopyBytes(kSecRandomDefault, length, data.mutableBytes)
|
|
7
12
|
if result != errSecSuccess {
|
|
13
|
+
OneKeyLog.error("RandomValues", "SecRandomCopyBytes failed with status: \(result)")
|
|
8
14
|
throw NSError(domain: "ReactNativeGetRandomValues", code: Int(result), userInfo: nil)
|
|
9
15
|
}
|
|
10
16
|
return data.base64EncodedString(options: .lineLength64Characters)
|