@the-polyfills/get-random-values 1.0.1 → 2.0.0
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/src/main/java/com/thepolyfills/getrandomvalues/GetRandomValuesModule.kt +3 -10
- package/android/src/main/java/com/thepolyfills/getrandomvalues/GetRandomValuesPackage.kt +22 -7
- package/ios/GetRandomValues.h +2 -2
- package/ios/GetRandomValues.mm +11 -7
- package/lib/module/NativeGetRandomValues.js +5 -11
- package/lib/module/NativeGetRandomValues.js.map +1 -1
- package/lib/module/utils/get-random-values.js +1 -1
- package/lib/typescript/src/NativeGetRandomValues.d.ts +2 -1
- package/lib/typescript/src/NativeGetRandomValues.d.ts.map +1 -1
- package/package.json +17 -8
- package/src/NativeGetRandomValues.ts +7 -14
- package/src/utils/get-random-values.ts +1 -1
|
@@ -2,19 +2,12 @@ package com.thepolyfills.getrandomvalues
|
|
|
2
2
|
|
|
3
3
|
import android.util.Base64
|
|
4
4
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
6
|
-
import com.facebook.react.bridge.ReactMethod
|
|
7
5
|
import java.security.SecureRandom
|
|
8
6
|
|
|
9
7
|
class GetRandomValuesModule(reactContext: ReactApplicationContext) :
|
|
10
|
-
|
|
8
|
+
NativeGetRandomValuesSpec(reactContext) {
|
|
11
9
|
|
|
12
|
-
override fun
|
|
13
|
-
|
|
14
|
-
// Blocking synchronous method so `getRandomBase64` returns the value
|
|
15
|
-
// directly, matching the synchronous WebCrypto API.
|
|
16
|
-
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
17
|
-
fun getRandomBase64(byteLength: Double): String {
|
|
10
|
+
override fun getRandomBase64(byteLength: Double): String {
|
|
18
11
|
val length = byteLength.toInt()
|
|
19
12
|
|
|
20
13
|
if (length < 0) {
|
|
@@ -32,6 +25,6 @@ class GetRandomValuesModule(reactContext: ReactApplicationContext) :
|
|
|
32
25
|
}
|
|
33
26
|
|
|
34
27
|
companion object {
|
|
35
|
-
const val NAME =
|
|
28
|
+
const val NAME = NativeGetRandomValuesSpec.NAME
|
|
36
29
|
}
|
|
37
30
|
}
|
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
package com.thepolyfills.getrandomvalues
|
|
2
2
|
|
|
3
|
-
import com.facebook.react.
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
4
|
import com.facebook.react.bridge.NativeModule
|
|
5
5
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
-
import com.facebook.react.
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
8
|
+
import java.util.HashMap
|
|
7
9
|
|
|
8
|
-
class GetRandomValuesPackage :
|
|
9
|
-
override fun
|
|
10
|
-
return
|
|
10
|
+
class GetRandomValuesPackage : BaseReactPackage() {
|
|
11
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
12
|
+
return if (name == GetRandomValuesModule.NAME) {
|
|
13
|
+
GetRandomValuesModule(reactContext)
|
|
14
|
+
} else {
|
|
15
|
+
null
|
|
16
|
+
}
|
|
11
17
|
}
|
|
12
18
|
|
|
13
|
-
override fun
|
|
14
|
-
|
|
19
|
+
override fun getReactModuleInfoProvider() = ReactModuleInfoProvider {
|
|
20
|
+
mapOf(
|
|
21
|
+
GetRandomValuesModule.NAME to ReactModuleInfo(
|
|
22
|
+
name = GetRandomValuesModule.NAME,
|
|
23
|
+
className = GetRandomValuesModule.NAME,
|
|
24
|
+
canOverrideExistingModule = false,
|
|
25
|
+
needsEagerInit = false,
|
|
26
|
+
isCxxModule = false,
|
|
27
|
+
isTurboModule = true
|
|
28
|
+
)
|
|
29
|
+
)
|
|
15
30
|
}
|
|
16
31
|
}
|
package/ios/GetRandomValues.h
CHANGED
package/ios/GetRandomValues.mm
CHANGED
|
@@ -3,13 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
@implementation GetRandomValues
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
+ (BOOL)requiresMainQueueSetup {
|
|
9
|
-
return NO;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getRandomBase64 : (double)byteLength) {
|
|
6
|
+
- (NSString *)getRandomBase64:(double)byteLength {
|
|
13
7
|
NSInteger length = (NSInteger)byteLength;
|
|
14
8
|
|
|
15
9
|
if (length < 0) {
|
|
@@ -32,4 +26,14 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getRandomBase64 : (double)byteLength) {
|
|
|
32
26
|
return [data base64EncodedStringWithOptions:0];
|
|
33
27
|
}
|
|
34
28
|
|
|
29
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
30
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params {
|
|
31
|
+
return std::make_shared<facebook::react::NativeGetRandomValuesSpecJSI>(
|
|
32
|
+
params);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
+ (NSString *)moduleName {
|
|
36
|
+
return @"GetRandomValues";
|
|
37
|
+
}
|
|
38
|
+
|
|
35
39
|
@end
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
// Old Architecture (Paper) only: the native module is registered via
|
|
6
|
-
// RCT_EXPORT_MODULE / ReactPackage and looked up through NativeModules.
|
|
7
|
-
// There is intentionally no TurboModuleRegistry usage and no codegen spec
|
|
8
|
-
// in this package.
|
|
9
|
-
|
|
3
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
4
|
+
let cachedSpec = null;
|
|
10
5
|
export function getNativeGetRandomValues() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
throw new Error("Native module 'GetRandomValues' not found. Rebuild the app after installing the package (e.g. `expo prebuild --clean`).");
|
|
6
|
+
if (cachedSpec == null) {
|
|
7
|
+
cachedSpec = TurboModuleRegistry.getEnforcing('GetRandomValues');
|
|
14
8
|
}
|
|
15
|
-
return
|
|
9
|
+
return cachedSpec;
|
|
16
10
|
}
|
|
17
11
|
//# sourceMappingURL=NativeGetRandomValues.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","cachedSpec","getNativeGetRandomValues","getEnforcing"],"sourceRoot":"../../src","sources":["NativeGetRandomValues.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAA0B,cAAc;AAEpE,IAAIC,UAAuB,GAAG,IAAI;AAMlC,OAAO,SAASC,wBAAwBA,CAAA,EAAS;EAC/C,IAAID,UAAU,IAAI,IAAI,EAAE;IACtBA,UAAU,GAAGD,mBAAmB,CAACG,YAAY,CAAO,iBAAiB,CAAC;EACxE;EACA,OAAOF,UAAU;AACnB","ignoreList":[]}
|
|
@@ -38,7 +38,7 @@ export function getRandomValues(array) {
|
|
|
38
38
|
return array;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
//
|
|
41
|
+
// Old-arch remote debugging in Chrome can't call sync TurboModules
|
|
42
42
|
// ("Calling synchronous methods on native modules is not supported in
|
|
43
43
|
// Chrome"), so fall back to Math.random() there.
|
|
44
44
|
if (isRemoteDebuggingInChrome()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeGetRandomValues.d.ts","sourceRoot":"","sources":["../../../src/NativeGetRandomValues.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NativeGetRandomValues.d.ts","sourceRoot":"","sources":["../../../src/NativeGetRandomValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAA;AAIpE,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAA;CAC5C;AAED,wBAAgB,wBAAwB,IAAI,IAAI,CAK/C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@the-polyfills/get-random-values",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Polyfill for crypto.getRandomValues in React Native",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -54,9 +54,10 @@
|
|
|
54
54
|
"@eslint/eslintrc": "^3.3.7",
|
|
55
55
|
"@eslint/js": "^10.0.1",
|
|
56
56
|
"@jest/globals": "^30.5.2",
|
|
57
|
-
"@react-native/babel-preset": "0.
|
|
58
|
-
"@react-native/eslint-config": "0.
|
|
59
|
-
"@
|
|
57
|
+
"@react-native/babel-preset": "0.86.3",
|
|
58
|
+
"@react-native/eslint-config": "0.86.3",
|
|
59
|
+
"@react-native/jest-preset": "0.86.3",
|
|
60
|
+
"@types/react": "^19.2.0",
|
|
60
61
|
"del-cli": "^7.0.0",
|
|
61
62
|
"eslint": "^10.11.0",
|
|
62
63
|
"eslint-config-prettier": "^10.1.8",
|
|
@@ -65,11 +66,11 @@
|
|
|
65
66
|
"jest": "^30.5.2",
|
|
66
67
|
"nodemon": "^3.1.14",
|
|
67
68
|
"prettier": "^3.9.9",
|
|
68
|
-
"react": "19.
|
|
69
|
-
"react-native": "0.
|
|
69
|
+
"react": "19.2.3",
|
|
70
|
+
"react-native": "0.86.3",
|
|
70
71
|
"react-native-builder-bob": "^0.43.1",
|
|
71
72
|
"turbo": "^2.11.3",
|
|
72
|
-
"typescript": "
|
|
73
|
+
"typescript": "^6.0.3"
|
|
73
74
|
},
|
|
74
75
|
"peerDependencies": {
|
|
75
76
|
"react": "*",
|
|
@@ -93,8 +94,16 @@
|
|
|
93
94
|
]
|
|
94
95
|
]
|
|
95
96
|
},
|
|
97
|
+
"codegenConfig": {
|
|
98
|
+
"name": "GetRandomValuesSpec",
|
|
99
|
+
"type": "modules",
|
|
100
|
+
"jsSrcsDir": "src",
|
|
101
|
+
"android": {
|
|
102
|
+
"javaPackageName": "com.thepolyfills.getrandomvalues"
|
|
103
|
+
}
|
|
104
|
+
},
|
|
96
105
|
"jest": {
|
|
97
|
-
"preset": "react-native",
|
|
106
|
+
"preset": "@react-native/jest-preset",
|
|
98
107
|
"testEnvironmentOptions": {
|
|
99
108
|
"customExportConditions": [
|
|
100
109
|
"require",
|
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TurboModuleRegistry, type TurboModule } from 'react-native'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// in this package.
|
|
7
|
-
export interface Spec {
|
|
3
|
+
let cachedSpec: Spec | null = null
|
|
4
|
+
|
|
5
|
+
export interface Spec extends TurboModule {
|
|
8
6
|
getRandomBase64(byteLength: number): string
|
|
9
7
|
}
|
|
10
8
|
|
|
11
9
|
export function getNativeGetRandomValues(): Spec {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (native == null || typeof native.getRandomBase64 !== 'function') {
|
|
15
|
-
throw new Error(
|
|
16
|
-
"Native module 'GetRandomValues' not found. Rebuild the app after installing the package (e.g. `expo prebuild --clean`).",
|
|
17
|
-
)
|
|
10
|
+
if (cachedSpec == null) {
|
|
11
|
+
cachedSpec = TurboModuleRegistry.getEnforcing<Spec>('GetRandomValues')
|
|
18
12
|
}
|
|
19
|
-
|
|
20
|
-
return native
|
|
13
|
+
return cachedSpec
|
|
21
14
|
}
|
|
@@ -58,7 +58,7 @@ export function getRandomValues<T extends ArrayBufferView>(array: T): T {
|
|
|
58
58
|
return array
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
//
|
|
61
|
+
// Old-arch remote debugging in Chrome can't call sync TurboModules
|
|
62
62
|
// ("Calling synchronous methods on native modules is not supported in
|
|
63
63
|
// Chrome"), so fall back to Math.random() there.
|
|
64
64
|
if (isRemoteDebuggingInChrome()) {
|