forked from Axionvera/pocketpay-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshim.js
More file actions
50 lines (45 loc) · 1.25 KB
/
Copy pathshim.js
File metadata and controls
50 lines (45 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import "react-native-get-random-values";
import * as ExpoCrypto from "expo-crypto";
import "text-encoding";
import { Buffer } from "buffer";
global.Buffer = Buffer;
if (
typeof global.crypto !== "object" ||
typeof global.crypto.getRandomValues !== "function"
) {
const cryptoPolyfill = {
...(typeof global.crypto === "object" ? global.crypto : null),
getRandomValues: (array) => ExpoCrypto.getRandomValues(array),
};
try {
Object.defineProperty(global, "crypto", {
configurable: true,
enumerable: true,
value: cryptoPolyfill,
});
} catch (e) {
global.crypto = cryptoPolyfill;
}
}
console.log(
"[shim] crypto.getRandomValues installed:",
typeof global.crypto === "object" &&
typeof global.crypto.getRandomValues === "function",
);
// Polyfill process for Stellar SDK.
// 'process/browser' avoids Metro treating this as the Node built-in module.
const bProcess = require("process/browser");
if (typeof process === "undefined") {
global.process = bProcess;
} else {
for (var p in bProcess) {
if (!(p in process)) {
process[p] = bProcess[p];
}
}
}
// Polyfill global env
if (!global.process.env) {
global.process.env = {};
}
global.process.env.NODE_ENV = __DEV__ ? "development" : "production";