-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e751a73
commit 391f9a3
Showing
5 changed files
with
58 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,23 @@ | ||
const crypto = require('crypto-browserify'); | ||
|
||
const nativeCrypto = global.crypto; | ||
if (nativeCrypto) { | ||
nativeCrypto.randomBytes = nativeCrypto.randomBytes || crypto.randomBytes; | ||
// **** for test only | ||
// if (process.env.NODE_ENV !== 'production') { | ||
// const getRandomValuesOld = global.crypto.getRandomValues; | ||
// global.crypto.getRandomValues = function (...args) { | ||
// return getRandomValuesOld.apply(global.crypto, args); | ||
// }; | ||
// } | ||
|
||
if (global.crypto) { | ||
global.crypto.randomBytes = global.crypto.randomBytes || crypto.randomBytes; | ||
crypto.getRandomValues = | ||
crypto.getRandomValues || nativeCrypto.getRandomValues; | ||
crypto.getRandomValues || global.crypto.getRandomValues; | ||
} | ||
crypto.$$isOneKeyShim = true; | ||
nativeCrypto.$$isOneKeyShim = true; | ||
global.crypto.$$isOneKeyShim = true; | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
console.log('crypto-browserify polyfilled', crypto, nativeCrypto); | ||
console.log('crypto-browserify polyfilled', crypto, global.crypto); | ||
} | ||
|
||
module.exports = crypto; |
29 changes: 27 additions & 2 deletions
29
packages/shared/src/modules3rdParty/cross-crypto/index.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,29 @@ | ||
// require.resolve('react-native-crypto') | ||
// react-native-crypto | ||
// react-native-quick-crypto | ||
// react-native-get-random-values | ||
// react-native-randombytes | ||
// react-native-randombytes (deprecated) | ||
|
||
if (global.crypto && global.crypto.getRandomValues) { | ||
delete global.crypto.getRandomValues; | ||
} | ||
// shim global.crypto.getRandomValues | ||
require('react-native-get-random-values'); | ||
|
||
const crypto = require('react-native-crypto'); | ||
|
||
const { randomBytes } = require('@noble/hashes/utils'); | ||
|
||
// re-assign randomBytes from global.crypto.getRandomValues | ||
crypto.randomBytes = randomBytes; | ||
crypto.getRandomValues = | ||
crypto.getRandomValues || global.crypto.getRandomValues; | ||
global.crypto.randomBytes = global.crypto.randomBytes || crypto.randomBytes; | ||
|
||
crypto.$$isOneKeyShim = true; | ||
global.crypto.$$isOneKeyShim = true; | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
console.log('react-native-crypto polyfilled', crypto, global.crypto); | ||
} | ||
|
||
module.exports = crypto; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters