add: restore old crypto package, isomorphic changes things in react-native

This commit is contained in:
Hadar Rottenberg 2020-02-12 21:07:24 +02:00
parent 40b47a2621
commit 72c699f20b
3 changed files with 508 additions and 465 deletions

955
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -59,11 +59,11 @@
},
"optionalDependencies": {
"text-encoding": "^0.7.0",
"emailjs": "^2.2.0"
"emailjs": "^2.2.0",
"@peculiar/webcrypto": "^1.0.22",
"buffer": "^5.4.3"
},
"peerDependencies": {
"isomorphic-webcrypto": "^2.*",
"buffer": "^5.*",
"@gooddollar/react-native-webview-crypto": "^0.*"
},
"devDependencies": {

12
sea.js
View File

@ -182,15 +182,19 @@
api.TextDecoder = TextDecoder;
api.TextEncoder = TextEncoder;
}
if(!api.crypto){try{
if(!api.crypto)
{
try
{
var crypto = USE('crypto', 1);
Object.assign(api, {
crypto,
random: (len) => Buffer.from(crypto.randomBytes(len))
});
const isocrypto = require('isomorphic-webcrypto');
api.ossl = api.subtle = isocrypto.subtle;
}catch(e){
const { Crypto: WebCrypto } = USE('@peculiar/webcrypto', 1);
api.ossl = api.subtle = new WebCrypto({directory: 'ossl'}).subtle // ECDH
}
catch(e){
console.log("text-encoding and isomorphic-webcrypto may not be included by default, please add it to your package.json!");
TEXT_ENCODING_OR_PECULIAR_WEBCRYPTO_NOT_INSTALLED;
}}