File tree 1 file changed +19
-10
lines changed
1 file changed +19
-10
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ if (typeof localStorage !== 'undefined') {
22
22
}
23
23
24
24
if ( require ( './package.json' ) . dependencies [ 'react-native-crypto' ] ) {
25
+ // important that this comes before require('crypto')
25
26
const algos = require ( 'browserify-sign/algos' )
26
27
if ( ! algos . sha256 ) {
27
28
algos . sha256 = {
@@ -31,17 +32,25 @@ if (require('./package.json').dependencies['react-native-crypto']) {
31
32
}
32
33
}
33
34
34
- const randomBytes = require ( 'react-native-randombytes' ) . randomBytes
35
-
35
+ let crypto
36
36
if ( typeof window === 'object' ) {
37
- const wCrypto = window . crypto = window . crypto || { }
38
- if ( ! wCrypto . getRandomValues ) {
39
- wCrypto . getRandomValues = function getRandomValues ( arr ) {
40
- const bytes = randomBytes ( arr . length )
41
- for ( var i = 0 ; i < bytes . length ; i ++ ) {
42
- arr [ i ] = bytes [ i ]
43
- }
44
- }
37
+ crypto = window . crypto = window . crypto || { }
38
+ } else {
39
+ crypto = require ( 'crypto' )
40
+ }
41
+
42
+ if ( ! crypto . getRandomValues ) {
43
+ crypto . getRandomValues = getRandomValues
44
+ }
45
+
46
+ let randomBytes
47
+
48
+ function getRandomValues ( arr ) {
49
+ if ( ! randomBytes ) randomBytes = require ( 'react-native-randombytes' ) . randomBytes
50
+
51
+ const bytes = randomBytes ( arr . length )
52
+ for ( var i = 0 ; i < bytes . length ; i ++ ) {
53
+ arr [ i ] = bytes [ i ]
45
54
}
46
55
}
47
56
}
You can’t perform that action at this time.
0 commit comments