-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.js
31 lines (27 loc) · 1.15 KB
/
global.js
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
// Inject node globals into React Native global scope.
// Required for crypto functionality for bitcoinjs-lib, web3, etc.
global.Buffer = require('buffer').Buffer;
//global.Buffer.TYPED_ARRAY_SUPPORT = false;
global.process = require('process');
global.process.env.NODE_ENV = __DEV__ ? 'development' : 'production';
var getRandomValues = function (byteArray) {
var bytes = crypto.rng.randomBytes(byteArray.length);
for (let i = 0; i < byteArray.length; i++) {
byteArray[i] = bytes[i];
}
};
// "But Zach, aren't you just doing the same thing twice?"
// Yes. Initializing the crypto-browserify module eventually requires
// crypto.getRandomValues to exist, so we must add it here once.
// However, crypto-browserify does not support getRandomValues, so we
// must re-add it after loading the module.
global.crypto = { getRandomValues };
global.crypto.rng = require('react-native-randombytes');
global.crypto = require('crypto');
global.crypto.getRandomValues = getRandomValues;
global.crypto.rng = require('react-native-randombytes');
crypto.rng.seedSJCL();
// Needed so that 'stream-http' chooses the right default protocol.
global.location = {
protocol: 'file:'
};