Skip to content

Commit 5eb3a95

Browse files
FCE-2467: Implement proper crypto polyfil (#442)
## Description - use `react-native-get-random-values` as `getRandomValues`. ## Motivation and Context - We had a temporary implmenation. ## Documentation impact - [ ] Documentation update required - [ ] Documentation updated [in another PR](_) - [x] No documentation update required ## Types of changes - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
1 parent e77eb3d commit 5eb3a95

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

packages/mobile-client/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
},
4444
"dependencies": {
4545
"@fishjam-cloud/react-client": "workspace:*",
46-
"@fishjam-cloud/react-native-webrtc": "git+https://github.com/fishjam-cloud/fishjam-react-native-webrtc.git#abdf79afed7ebe2a91bce23351f01f63decd49bb"
46+
"@fishjam-cloud/react-native-webrtc": "git+https://github.com/fishjam-cloud/fishjam-react-native-webrtc.git#abdf79afed7ebe2a91bce23351f01f63decd49bb",
47+
"react-native-get-random-values": "^1.11.0"
4748
},
4849
"devDependencies": {
4950
"@types/promise-fs": "^2.1.2",

packages/mobile-client/src/webrtc-polyfill.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'react-native-get-random-values';
2+
13
// @ts-ignore - event-target-shim types not properly exported via package.json exports
24
import { EventTarget } from 'event-target-shim';
35

@@ -9,24 +11,6 @@ import { LocalStoragePolyfill } from './polyfills/local-storage';
911
const registerGlobalsPolyfill = () => {
1012
(global as unknown as { EventTarget: typeof EventTarget }).EventTarget = EventTarget;
1113
(global as unknown as { localStorage: typeof localStorage }).localStorage = new LocalStoragePolyfill();
12-
(global as unknown as { crypto: { getRandomValues: (array: Uint8Array) => void } }).crypto = {
13-
getRandomValues: function (array: Uint8Array) {
14-
for (let i = 0; i < array.length; i++) {
15-
array[i] = Math.floor(Math.random() * 256);
16-
}
17-
return array;
18-
},
19-
};
20-
21-
// TODO: FCE-2467 Implement proper polyfill for crypto
22-
(global as unknown as { crypto: { getRandomValues: (array: Uint8Array) => void } }).crypto.getRandomValues =
23-
function (array: Uint8Array) {
24-
for (let i = 0; i < array.length; i++) {
25-
array[i] = Math.floor(Math.random() * 256);
26-
}
27-
return array;
28-
};
29-
3014
registerGlobals();
3115
// Custom overrides
3216
(globalThis.RTCPeerConnection as unknown as typeof RTCPeerConnection) = RTCPeerConnection;

yarn.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3247,6 +3247,7 @@ __metadata:
32473247
eslint-plugin-prettier: "npm:^5.5.1"
32483248
expo-module-scripts: "npm:^5.0.7"
32493249
promise-fs: "npm:^2.1.1"
3250+
react-native-get-random-values: "npm:^1.11.0"
32503251
peerDependencies:
32513252
expo: "*"
32523253
react: "*"
@@ -10508,6 +10509,13 @@ __metadata:
1050810509
languageName: node
1050910510
linkType: hard
1051010511

10512+
"fast-base64-decode@npm:^1.0.0":
10513+
version: 1.0.0
10514+
resolution: "fast-base64-decode@npm:1.0.0"
10515+
checksum: 10c0/6d8feab513222a463d1cb58d24e04d2e04b0791ac6559861f99543daaa590e2636d040d611b40a50799bfb5c5304265d05e3658b5adf6b841a50ef6bf833d821
10516+
languageName: node
10517+
linkType: hard
10518+
1051110519
"fast-deep-equal@npm:^3.1.1, fast-deep-equal@npm:^3.1.3":
1051210520
version: 3.1.3
1051310521
resolution: "fast-deep-equal@npm:3.1.3"
@@ -15280,6 +15288,17 @@ __metadata:
1528015288
languageName: node
1528115289
linkType: hard
1528215290

15291+
"react-native-get-random-values@npm:^1.11.0":
15292+
version: 1.11.0
15293+
resolution: "react-native-get-random-values@npm:1.11.0"
15294+
dependencies:
15295+
fast-base64-decode: "npm:^1.0.0"
15296+
peerDependencies:
15297+
react-native: ">=0.56"
15298+
checksum: 10c0/2ce71f1ab7f5b36d4a9dd59cc80b4aa75526f047c6680a7f1a388fa8b9a62efdacaf7b7de3be593c73e882773b2eee74916b00f7c8b158e40b46388998218586
15299+
languageName: node
15300+
linkType: hard
15301+
1528315302
"react-native-is-edge-to-edge@npm:^1.2.1":
1528415303
version: 1.2.1
1528515304
resolution: "react-native-is-edge-to-edge@npm:1.2.1"

0 commit comments

Comments
 (0)