margelo / react-native-quick-crypto Goto Github PK
View Code? Open in Web Editor NEW⚡️ A fast implementation of Node's `crypto` module written in C/C++ JSI
License: Other
⚡️ A fast implementation of Node's `crypto` module written in C/C++ JSI
License: Other
So, I have set up the library as directed in the docs. and I'm using crypto.sign
to sign some data. But it produces an error saying undefined is not a function
pointing at sign
function as you can see in the below image
Below is the code I'm executing on press of a button
const operation = crypto.sign(
'RSA-SHA256',
someArrayBuffer,
'key',
);
Hi there,
I can't get authentication tags to validate when using chacha20-poly1305. Decryption works just fine but when I purposefully mangle the authentication tag or the additional authenticated data (aad), it decrypts just fine.
Is there a specific order to run setAAD, update, and setAuthTag or some way to detect this failure mode?
This could be a bug or just user error. Unsure at this point!
Thanks!
It's missing subtle.
Hi!
I'm having this problem running on a Android 5.1 it fails with the following errors:
Error: Requiring module "node_modules/react-native-quick-crypto/src/index.ts", which threw an exception: Error: Exception in HostFunction: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "EVP_PKEY_get0_DSA"
INFO:
React Native: 0.69.5
Android Emulator: Android 5.1.1 (API 22)
Machine: Mac M1
Is it possible to add the Scrypt algorithm? Node.js implements both a synchronous and asynchronous version.
Import of crypto-browserify
for second time would resolve with different result, because of this package changes global
So in my case bip39
lib that uses randomfill
directly (dependency of crypto-browserify)
code of randomfill (when it executed for first time it goes to browser.js):
So basicly while bip39 using this packages, it has its old version, that uses react-native-quick-crypto
, which occurs this error:
bundle crypto-browerify direclty into package
This line
needs to be changed toimport { isBuffer } from './Utils';
Otherwise, it leads to an error in the file react-native-quick-crypto/lib/commonjs/random.js
which contains in the latest version on npm:
var _Utils = require("../src/Utils");
which doesn't exist.
I'm getting the following error while creating a wallet using ethers.
const wallet = ether.Wallet.createRandom()
WARNING: Missing strong random number source
ERROR Error: no secure random source avaialble (operation="crypto.getRandomValues", code=UNSUPPORTED_OPERATION, version=random/5.7.0), js engine: hermes
INFO:
React Native: 0.69.5 (also tested on 0.68.4)
ios Simulator: ios 15
Machine: Mac M1
We get this error when running eas update
:
../../node_modules/react-native-quick-crypto/src/random.ts: Unexpected token: name (_ffff_ffff) in file ../../node_modules/react-native-quick-crypto/src/random.ts at 78:23
Here is an example in our GitHub Actions: https://github.com/showtime-xyz/showtime-frontend/runs/7539838997?check_suite_focus=true
Any idea why?
Base64 conversion (atob
/btoa
) is done using the Buffer
class. We use @craftzdog/react-native-buffer (which itself uses @craftzdog/react-native-quick-base64 under the hood) as a Buffer polyfill for React Native.
While this implementation is fast (C++ JSI), Safari (WebKit) has an even faster implementation by using a lookup table.
We can migrate to this even faster atob
/btoa
(Buffer
) implementation as well to speed up functions even more.
See this file as a starting point for research. Here's their Base64 implementation with a lookup table.
react-native-quick-crypto/src/Utils.ts
Line 154 in ac04d8c
if (isString) {
throw new Error(`${name} is not a string`);
}
validateString
method will throw an error if the input is a string
Repro:
import crypto from 'react-native-quick-crypto'
const sha3 = crypto.createHash('sha3-256')
console.log('hashes:', crypto.getHashes(),'sha3', sha3.update(new Uint8Array(20)).digest('hex'))
=
Result:
hashes: ["sha1", "sha224", "sha256", "sha384", "sha512", "md5", "rmd160", "sha224WithRSAEncryption", "RSA-SHA224", "sha256WithRSAEncryption", "RSA-SHA256", "sha384WithRSAEncryption", "RSA-SHA384", "sha512WithRSAEncryption", "RSA-SHA512", "RSA-SHA1", "ecdsa-with-SHA1", "sha256", "sha224", "sha384", "sha512", "DSA-SHA", "DSA-SHA1", "DSA", "DSA-WITH-SHA224", "DSA-SHA224", "DSA-WITH-SHA256", "DSA-SHA256", "DSA-WITH-SHA384", "DSA-SHA384", "DSA-WITH-SHA512", "DSA-SHA512", "DSA-RIPEMD160", "ripemd160WithRSA", "RSA-RIPEMD160", "md5WithRSAEncryption", "RSA-MD5"] sha3 f3683c9e3da9a7f90397767215345efe3be07565f14ab80d102f50644b98fbfa
So sha3
executes, but according to getHashes shouln't
Source of problem: getHashes is not overriden from crypto-browserify
Hi!
I'm trying to implement a version sscrypto that uses react-native-quick-crypto, and I encountered an issue when using it on iOS in a Release build (it works in a debug build).
Basically, some function calls hang, I get errors like Failed to read asymmetric key
on any test related to RSA. AES seems fine.
Here is how you can reproduce:
git clone https://github.com/seald/sscrypto.git
cd sscrypto
git checkout 9-app-de-tests-rn-2p
npm i
npm run build-rn
cd quickcryptotestapp
yarn
cd ios
pod install
cd ..
yarn run ios # for dev - works (with minor errors that should be addressed nonetheless, since there are no errors when running the same tests on node)
yarn run ios --configuration Release # for prod - fails completely
I'm sorry for the sscrypto boilerplate, I'll try making a smaller dedicated repo that doesn't rely on sscrypto.
EDIT: it works fine for android builds (prod or dev) and ios build (dev)
Is this on roadmap ? We want to use elliptic curve on key generation. Could I make some changes just by reading the nodejs source code ?
Hi, I'm getting this error when building for release on iOS:
Undefined symbols for architecture arm64: "_BIO_ctrl", referenced from: margelo::ParsePublicKeyPEM(std::__1::unique_ptr<evp_pkey_st, margelo::FunctionDeleter<evp_pkey_st, &(EVP_PKEY_free)> >*, char const*, int) in libreact-native-quick-crypto.a(MGLKeys.o) margelo::BIOToStringOrBuffer(bio_st*, margelo::PKFormatType) in libreact-native-quick-crypto.a(MGLKeys.o) "_BIO_free_all", referenced from: std::__1::unique_ptr<bio_st, margelo::FunctionDeleter<bio_st, &(BIO_free_all)> >::~unique_ptr() in libreact-native-quick-crypto.a(MGLKeys.o) "_BIO_new", referenced from: margelo::WritePrivateKey(facebook::jsi::Runtime&, evp_pkey_st*, margelo::PrivateKeyEncodingConfig const&) in libreact-native-quick-crypto.a(MGLKeys.o) margelo::WritePublicKey(facebook::jsi::Runtime&, evp_pkey_st*, margelo::AsymmetricKeyEncodingConfig const&) in libreact-native-quick-crypto.a(MGLKeys.o) "_BIO_new_mem_buf", referenced from: margelo::ParsePublicKeyPEM(std::__1::unique_ptr<evp_pkey_st, margelo::FunctionDeleter<evp_pkey_st, &(EVP_PKEY_free)> >*, char const*, int) in libreact-native-quick-crypto.a(MGLKeys.o) margelo::ParsePrivateKey(std::__1::unique_ptr<evp_pkey_st, margelo::FunctionDeleter<evp_pkey_st, &(EVP_PKEY_free)> >*, margelo::PrivateKeyEncodingConfig const&, char const*, unsigned long) in libreact-native-quick-crypto.a(MGLKeys.o) "_BIO_s_mem", referenced from: margelo::WritePrivateKey(facebook::jsi::Runtime&, evp_pkey_st*, margelo::PrivateKeyEncodingConfig const&) in libreact-native-quick-crypto.a(MGLKeys.o) margelo::WritePublicKey(facebook::jsi::Runtime&, evp_pkey_st*, margelo::AsymmetricKeyEncodingConfig const&) in libreact-native-quick-crypto.a(MGLKeys.o) "_BN_bin2bn", referenced from: margelo::ConvertSignatureToDER(margelo::ManagedEVPPKey const&, margelo::ByteSource&&) in libreact-native-quick-crypto.a(MGLSignHostObjects.o)
Debug build works fine, this happens only on release. What might caused this issue and how to solve it?
react-native info output:
System: OS: macOS 12.6 CPU: (8) x64 Apple M1 Memory: 71.05 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.17.1 - ~/.nvm/versions/node/v16.17.1/bin/node Yarn: 1.22.19 - ~/.nvm/versions/node/v16.17.1/bin/yarn npm: 8.15.0 - ~/.nvm/versions/node/v16.17.1/bin/npm Watchman: 2022.10.03.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.3 - /Users/adrian-synthetify/.rbenv/shims/pod SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0 Android SDK: Not Found IDEs: Android Studio: 2021.3 AI-213.7172.25.2113.9014738 Xcode: 14.0.1/14A400 - /usr/bin/xcodebuild Languages: Java: 11.0.16.1 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.1.0 => 18.1.0 react-native: 0.70.3 => 0.70.3 react-native-macos: Not Found npmGlobalPackages: *react-native*: Not Found
If Flipper is enabled, I'm having this problem when running pod install
:
[!] CocoaPods could not find compatible versions for pod "OpenSSL-Universal":
In Podfile:
OpenSSL-Universal (= 1.1.1100)
react-native-quick-crypto (from `../node_modules/react-native-quick-crypto`) was resolved to 0.4.2, which depends on
OpenSSL-Universal (~> 1.1.1300)
Specs satisfying the `OpenSSL-Universal (= 1.1.1100), OpenSSL-Universal (~> 1.1.1300)` dependency were found, but they required a higher minimum deployment target.
The following error occurred when starting build with 'yarn ios'
** BUILD FAILED **
The following build commands failed: CompileC /Users/user/Library/Developer/Xcode/DerivedData/crypto-eamvswztqbfltyfmctcecemevndi/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/React-Codegen.build/Objects-normal/x86_64/EventEmitters.o /Users/user/develop/native/native-app/ios/build/generated/ios/react/renderer/components/rncore/EventEmitters.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler (in target 'React-Codegen' from project 'Pods')
However, if I specify the new architecture when pod-install, it works ok.
cd ios
USE_FABRIC=1 RCT_NEW_ARCH_ENABLED=1 pod install
0.69.3
System:
OS: macOS 12.4
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Memory: 3.70 GB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 14.19.1 - ~/.volta/tools/image/node/14.19.1/bin/node
Yarn: 1.22.17 - ~/.volta/tools/image/yarn/1.22.17/bin/yarn
npm: 8.4.0 - ~/.volta/tools/image/npm/8.4.0/bin/npm
Watchman: 2022.01.24.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
Android SDK:
API Levels: 29, 30, 31, 32
Build Tools: 29.0.2, 30.0.2, 30.0.3, 31.0.0
System Images: android-30 | Intel x86 Atom_64, android-30 | Google APIs Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 2021.1 AI-211.7628.21.2111.8193401
Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
Languages:
Java: 11.0.11 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.0.0 => 18.0.0
react-native: 0.69.3 => 0.69.3
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found
I got this problem where the package performs as advertised in the ios emulators in my expo bare-workflow project, but then when I build the app and ship it via test flight the app performs as if the library isn't used where there are 6 second lags when the user creates a wallet. Even when I build the production build locally using the yarn react-native run-ios --configuration release
on my emulator it works fine, but if I ship it, it's back to 6 second lags. This has me thinking that the package isn't being used for some reason in production. It may or may not be linked to this error I get when i cd
into my ios
folder and run pod install
i get the following error:
Can't merge user_target_xcconfig for pod targets: ["RNReanimated", "react-native-bignumber", "react-native-quick-crypto"]. Singular build setting CLANG_CXX_LANGUAGE_STANDARD has different values.
If I run the command npx pod install
I get no such error but I have no idea what's happening under the hood, and if the package is actually being included in the build. I'm not sure if it's an error with what I'm doing or on the side of the library, so any help is highly appreciated, Thanks.
Is it possible to have this library working with react-native-windows ?
It would be a great improvment because there are no solution for crypto to work on windows..
Seems like there might be some room for exploration in seeing if there could be usefulness to building a config plugin to help make this easier for folks to use. I'd be open to sponsoring work on it.
When calling crypto.generatePrime
:
TypeError: _reactNativeQuickCrypto.default.generatePrime is not a function.
However, IDE hint indicate the function exists.
lib/typescript/index.d.ts
:
declare const crypto: {
...
generatePrime(size: number, callback: (err: Error | null, prime: ArrayBuffer) => void): void;
generatePrime(size: number, options: FallbackCrypto.GeneratePrimeOptionsBigInt, callback: (err: Error | null, prime: bigint) => void): void;
generatePrime(size: number, options: FallbackCrypto.GeneratePrimeOptionsArrayBuffer, callback: (err: Error | null, prime: ArrayBuffer) => void): void;
generatePrime(size: number, options: FallbackCrypto.GeneratePrimeOptions, callback: (err: Error | null, prime: bigint | ArrayBuffer) => void): void;
...
};
Other functions like crypto.getRandomValues
work without issue.
I have set up the example application and ran the createCipher/createDecipher unit test.
All tests pass except the last one which returns the following error for the test setAutoPadding/setAuthTag/setAAD
:
Invalid authentication tag length
I've debugged the problem and it does not matter if you use Buffer.from("auth_tag")
(just like the unit test) or Uint8Array or ArrayBuffer as tag input, the auth_tag_len_
variable (in MGLCipherHostObject.cpp
) is always 0.
[!] CocoaPods could not find compatible versions for pod "react-native-quick-crypto":
In Podfile:
react-native-quick-crypto (from ../node_modules/react-native-quick-crypto
)
Specs satisfying the react-native-quick-crypto (from
../node_modules/react-native-quick-crypto)
dependency were found, but they required a higher minimum deployment target.
in looking through the code, I was surprised to see crypto-browserify
is included by default.
It'd be nice to expose an option that does not include this by default. I think a big advantage of this kind of library is that it's proving native options for crypto apis, if folks need the crypto-browserify
functionality, it should be more explicit.
Readme says add both:
yarn add react-native-quick-crypto
yarn add react-native-quick-base64
but it actually looks like the sub-deps have it in their dependencies
, so no need to explicitly add on on root level dependencies.
$ npm ls "react-native-quick-base64"
[email protected] /home/ghost/Documents/BlueWallet
├── [email protected]
└─┬ [email protected]
├─┬ @craftzdog/[email protected]
│ └── [email protected] deduped
└── [email protected] deduped
Am I missing something?
I'm not able to build on Android with React Native to 0.71.0
.
Specifically on the terminal i get:
* Where:
Build file '/Users/grenos/myDir/myProj/node_modules/react-native-quick-crypto/android/build.gradle' line: 190
with line 190 being:
def rnAAR = fileTree("${defaultDir.toString()}").matching({ it.include rnAarMatcher }).singleFile
Also on terminal I see:
* What went wrong:
A problem occurred evaluating project ':react-native-quick-crypto'.
> Expected directory '/Users/grenos/myDir/myProj/node_modules/react-native/android' to contain exactly one file, however, it contains no files.
Looking further into this I can see on '/Users/grenos/myDir/myProj/node_modules/react-native/android'
the following README
# The `/android` folder inside `react-native`
Starting from React Native 0.71, we're not shipping the `/android` folder inside the React Native NPM package
anymore due to sizing constraints on NPM. The Android artifacts are distributed via Maven Central.
You can read more about it in this RFC:
https://github.com/react-native-community/discussions-and-proposals/pull/508
If you're a library author and you're manipulating the React Native .aar files, to extract headers,
extract `.so` files or do anything with it, you're probably doing something wrong. React Native
0.71 ships with all the necessary logic to let you consume it transparently by just using:
implementation("com.facebook.react:react-android")
// or to keep backward compatibility with older versions of React Native:
implementation("com.facebook.react:react-native:+")
You should consider refactoring your library code not to unzip/manipulate the React Native .aar files.
This README.md file is kept in this folder as some libraries are checking the existence of the `/android` folder
and failing user builds if the folder is missing.
Unfortunately I'm not an Android developer so I can't contribute to this issue.
Haven't checked iOS yet
EDIT
iOS seems fine.
Hi!
Your isBuffer
function is too strict: it tests if buf
is an instance of Buffer
using instanceof
, and falls back to testing the constructor.name
.
Having a fallback is indeed necessary because there may be multiple implementations of Buffer in the same app, but your fallback actually does not work when the code is minified, because the function names get mangled, which is automatic when Hermes is not used on iOS and android.
This in turns falls back to using the whole underlying ArrayBuffer by doing this:
react-native-quick-crypto/src/Utils.ts
Line 134 in f22faf2
I spent the past 3 days tracking why I had invalid iv
errors that were triggered everywhere in my code only on iOS production builds, I gave a 16 bytes Buffer, but the Cpp code received a 2122 bytes ArrayBuffer, and by monkeypatching the code, I ended up finding out this.
The fix I suggest is to actually use Buffer.isBuffer
instead of your custom isBuffer
.
For reference, this issue is very similar to: feross/buffer#154
Hi, I m trying this shim and made it work, but for some reason it goes awfully slow (trying ethers.createRandom()
as recommended in their cookbook). I want to benchmark that against your example so that I can debug, but I cannot run the example...
yarn run v1.22.15
$ react-native run-ios
info Found Xcode workspace "QuickCryptoExample.xcworkspace"
info Building (using "xcodebuild -workspace QuickCryptoExample.xcworkspace -configuration Debug -scheme QuickCryptoExample -destination id=A8817814-353F-4A39-83C1-277CB90108B6")
error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65. To debug build logs further, consider building your app with Xcode.app, by opening QuickCryptoExample.xcworkspace.
Command line invocation:
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -workspace QuickCryptoExample.xcworkspace -configuration Debug -scheme QuickCryptoExample -destination id=A8817814-353F-4A39-83C1-277CB90108B6
User defaults from command line:
IDEPackageSupportUseBuiltinSCM = YES
2023-01-05 16:48:23.615 xcodebuild[17904:6798671] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionSentinelHostApplications for extension Xcode.DebuggerFoundation.AppExtensionHosts.watchOS of plug-in com.apple.dt.IDEWatchSupportCore
2023-01-05 16:48:23.615 xcodebuild[17904:6798671] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionPointIdentifierToBundleIdentifier for extension Xcode.DebuggerFoundation.AppExtensionToBundleIdentifierMap.watchOS of plug-in com.apple.dt.IDEWatchSupportCore
xcodebuild: error: The workspace named "QuickCryptoExample" does not contain a scheme named "QuickCryptoExample". The "-list" option can be used to find the names of the schemes in the workspace.
info Run CLI with --verbose flag for more details.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
My app Android crash when app open.
React native: 0.69.7
React-native-quick-crypto: 0.5.0
Android version: android 5 Lolipop
Error: Exception in HostFunction: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "RSA_pkey_ctx_ctrl" referenced by "/data/app/com.../lib/arm64/libreactnativequickcrypto.so"..., js engine: hermes, stack:
callNativeSyncHook@1:119501
nonPromiseMethodWrapper@1:116545
anonymous@1:3819173
loadModuleImplementation@1:95498
guardedLoadModule@1:95046
metroRequire@1:94674
anonymous@1:3816944
loadModuleImplementation@1:95498
guardedLoadModule@1:95046
metroRequire@1:94674
anonymous@1:3719073
loadModuleImplementation@1:95498
guardedLoadModule@1:95046
metroRequire@1:94674
anonymous@1:3718806
loadModuleImplementation@1:95498
guardedLoadModule@1:95046
metroRequire@1:94674
anonymous@1:3709697
loadModuleImplementation@1:95498
guardedLoadModule@1:95046
metroRequire@1:94674
anonymous@1:3708715
loadModuleImplementation@1:95498
guardedLoadModule@1:95046
metroRequire@1:94674
anonymous@1:3482992
loadModuleImplementation@1:95498
guardedLoadModule@1:95046
metroRequire@1:94674
anonymous@1:3415184
loadModuleImplementation@1:95498
guardedLoadModule@1:95046
metroRequire@1:94674
anonymous@1:6897174
loadModuleImplementation@1:95498
guardedLoadModule@1:95003
metroRequire@1:94674
App@1:613199
renderWithHooks@1:155457
beginWork$1@1:195952
performUnitOfWork@1:182271
workLoopSync@1:182128
renderRootSync@1:182012
performSyncWorkOnRoot@1:179431
flushSyncCallbacks@1:145677
scheduleUpdateOnFiber@1:176464
updateContainer@1:187434
anonymous@1:196986
renderApplication@1:515338
run@1:512182
runApplication@1:512684
__callFunction@1:120575
anonymous@1:119063
__guard@1:120019
callFunctionReturnFlushedQueue@1:119021
Hi,
I noticed a missing method in the cypher implementation. The getAuthTag
has been commented out.
see code reference
This is breaking my ECIES usage which relies on react-native-quick-crypto
crypto implementation.
I can't find any reasons for the comments?
Currently crypto.subtle support is known to be missing. I propose to add crypto.subtle support. Let me know what the status on this is and whether it's open for PRs.
Hi!
I'm running on a macbook pro from 2017 x86 with macOS 12.5.1, and whenever I try to build for iOS in Release mode with [email protected]
it fails with the following errors:
ld: warning: Could not find or use auto-linked framework 'OpenSSL'
Undefined symbols for architecture x86_64:
for a lot of OpenSSL symbols across the libraryld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The steps to reproduce are:
npx react-native init quickcryptoerror --version 0.68.3
cd quickcryptoerror
yarn add react-native-quick-crypto react-native-quick-base64
cd ios
pod install
cd ..
npx react-native run-ios --configuration Release
I tried to:
IPHONEOS_DEPLOYMENT_TARGET
at 11.0
in the podfile for react-native-quick-crypto -> same errorDo you have an idea of what's happening?
The full error log is here: error-log.txt
If I understand the code correctly, this library does not implement ECDH and it falls back to crypto-browserify.
Are there any plans to implement it? Pure JS implementation from crypto-browserify is slow.
Getting the follow build failure with EAS on Android:
[stderr] FAILURE: Build failed with an exception.
[stderr] * What went wrong:
[stderr] Execution failed for task ':app:mergeDebugNativeLibs'.
[stderr] >
[stderr] A failure occurred while executing com.android.build.gradle.internal.tasks.MergeNativeLibsTask$MergeNativeLibsTaskWorkAction
[stderr] > 2 files found with path 'lib/arm64-v8a/libreact_nativemodule_core.so' from inputs:
[stderr] - /home/expo/workingdir/build/node_modules/react-native-quick-crypto/android/build/intermediates/library_jni/debug/jni/arm64-v8a/libreact_nativemodule_core.so
[stderr] - /home/expo/.gradle/caches/transforms-3/b086d6b8c5a24abb1261b319bf9e994d/transformed/jetified-react-native-0.68.2/jni/arm64-v8a/libreact_nativemodule_core.so
[stderr] If you are using jniLibs and CMake IMPORTED targets, see
[stderr] https://developer.android.com/r/tools/jniLibs-vs-imported-targets
[stderr] * Try:
[stderr] > Run with --stacktrace option to get the stack trace.
[stderr] > Run with --info or --debug option to get more log output.
[stderr] > Run with --scan to get full insights.
[stderr] * Get more help at https://help.gradle.org
[stderr] BUILD FAILED in 15m 4s
Packages:
"expo": "45.0.6",
"react-native": "0.68.2",
"react-native-quick-crypto": "0.4.5",
Build failed when updating react-native version to 0.70.0
/Users/user1/rn/node_modules/react-native-quick-crypto/cpp/Cipher/MGLCipherHostObject.cpp:454:24: error: no member named 'throwJSError' in namespace 'facebook::jsi::detail'
/Users/user1/rn/node_modules/react-native-quick-crypto/cpp/Cipher/MGLCipherHostObject.cpp:470:24: error: no member named 'throwJSError' in namespace 'facebook::jsi::detail'
/Users/user1/rn/node_modules/react-native-quick-crypto/cpp/Cipher/MGLCipherHostObject.cpp:505:24: error: no member named 'throwJSError' in namespace 'facebook::jsi::detail'
When parsing/creating encryption keys there is a variable amount of parameters needed depending on the selected scheme (rsa, rsapps, etc). Node implements the argument parsing by reading directly from the passed arguments from JS, this is also necessary because some data needs to be read/passed/transformed by OpenSSL (BIOPointers and some EVP functions) before actually generating/reading the key.
This is however problematic when using the JSI, because we need to pass the runtime to the threaded implementation. Accessing the runtime from a std::thread can cause crashes. The solution is clear, we need to read all the arguments before doing threaded work. This however is a big big big change, since the number of arguments and their types will change depending on the scheme, we basically need to duplicate/de-attach a lot of the logic and then re-apply it as pure c++ values when doing the key parsing. Basically a from-the-ground up implementation.
One possible path is reading the data from JS without a thread and only doing the key generation step in a thread, here however not sure how much performance we would lose, but it wouldn't require a major re-write. This should be explored first.
I already faced some trouble with race conditions accessing data, I have changed the data parsed to occur before spawning the thread, this seems to work fine for now. But we still need to keep an eye open.
Attempting to upload a Release Archive from Xcode is failing due to usage of non-public symbol: FIPS_mode()
.
I'm encountering the following when trying to build for iOS in Expo EAS.
0.4.3
❌ Undefined symbols for architecture arm64
┌─ Symbol: _SHA512_Init
└─ Referenced from: _fastpbkdf2_hmac_sha512 in libreact-native-quick-crypto.a(fastpbkdf2.o)
❌ ld: symbol(s) not found for architecture arm64
❌ clang: error: linker command failed with exit code 1 (use -v to see invocation)
▸ ** ARCHIVE FAILED **
▸ The following build commands failed:
▸ Ld /Users/expo/Library/Developer/Xcode/DerivedData/Genesis-earvumgnsszrpedcrmdycnmubadt/Build/Intermediates.noindex/ArchiveIntermediates/Genesis/InstallationBuildProductsLocation/Applications/Genesis.app/Genesis normal (in target 'Genesis' from project 'Genesis')
▸ (1 failure)
2022-07-26 16:16:
Any ideas?
Very excited to try this lib!
Hi guys! Since the last update I cannot build my app for Android devices. iOS is working fine but Android crashes as soon as I start building the app.
"react-native": "0.70.8",
"react-native-quick-crypto": "^0.6.1",
I appreciate any help.
Just for the record I recently had to update the library because of the following issue "'value' is unavailable: introduced in iOS 12.0" After updating to Xcode 14.3. Before that, Android was working fine.
Happens intermittently, even though I'm using the same key each time.
Seems to happen if I have already called some combination of pbkdf2Sync
, createDecipheriv
... Will post steps to reproduce at some point.
Exception happens at: https://github.com/margelo/react-native-quick-crypto/blob/main/src/sig.ts#L154
Full trace:
LOG [Error: Exception in HostFunction: Failed to read private key
Error: Failed to read private key
at sign (native)
at sign (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.Evertrove:167843:37)
at anonymous (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.Evertrove:124894:76)
at tryCallTwo (/Users/distiller/react-native/sdks/hermes/build_iphonesimulator/lib/InternalBytecode/InternalBytecode.js:61:9)
at doResolve (/Users/distiller/react-native/sdks/hermes/build_iphonesimulator/lib/InternalBytecode/InternalBytecode.js:216:25)
at Promise (/Users/distiller/react-native/sdks/hermes/build_iphonesimulator/lib/InternalBytecode/InternalBytecode.js:82:14)
at sign (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.Evertrove:124893:27)
at sign (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.Evertrove:349422:45)
at ?anon_0_ (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.Evertrove:292308:45)
at next (native)
at asyncGeneratorStep (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.Evertrove:25680:26)
at _next (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.Evertrove:25702:29)
at tryCallOne (/Users/distiller/react-native/sdks/hermes/build_iphonesimulator/lib/InternalBytecode/InternalBytecode.js:53:16)
at anonymous (/Users/distiller/react-native/sdks/hermes/build_iphonesimulator/lib/InternalBytecode/InternalBytecode.js:139:27)
at apply (native)
at anonymous (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.Evertrove:32266:26)
at _callTimer (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.Evertrove:32166:17)
at _callReactNativeMicrotasksPass (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.Evertrove:32201:17)
at callReactNativeMicrotasks (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.Evertrove:32409:44)
at __callReactNativeMicrotasks (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.Evertrove:3801:46)
at anonymous (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.Evertrove:3579:45)
at __guard (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.Evertrove:3784:15)
at flushedQueue (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.Evertrove:3578:21)]
info Reloading app...
I spend one day and in the case if anyone interested, this is a solution by @margelo itself: ethers-io/ethers.js#2250 (comment)
While installing this library in a react-native 0.69.1 project I faced this problem:
* What went wrong:
A problem occurred evaluating project ':react-native-quick-crypto'.
> Expected directory '~/Projects/react-native-quick-crypto-example/node_modules/react-native/android' to contain exactly one file, however, it contains more than one file.
This is because of bundled hermes that was released with RN 0.69 and can be fixed by changing react-native-quick-crypto/android/build.gradle
file as follows:
@@ -177,7 +177,18 @@ dependencies {
extractJNI("com.facebook.fbjni:fbjni:+")
if (!sourceBuild) {
- def rnAAR = fileTree("${defaultDir.toString()}").matching({ it.include "**/**/*.aar" }).singleFile
+ def buildType = "debug"
+ tasks.all({ task ->
+ if (task.name == "buildCMakeRelease") {
+ buildType = "release"
+ }
+ })
+ def rnAarMatcher = "**/react-native/**/*${buildType}.aar"
+ def rnMinorVersion = reactProperties.getProperty("VERSION_NAME").split("\\.")[1].toInteger()
+ if (rnMinorVersion < 69) {
+ rnAarMatcher = "**/**/*.aar"
+ }
+ def rnAAR = fileTree("${defaultDir.toString()}").matching({ it.include rnAarMatcher }).singleFile
extractJNI(files(rnAAR))
}
}
After this change I got another error:
* What went wrong:
Execution failed for task ':react-native-quick-crypto:downloadBoost'.
> A failure occurred while executing de.undercouch.gradle.tasks.download.internal.DefaultWorkerExecutorHelper$DefaultWorkAction
> de.undercouch.gradle.tasks.download.org.apache.hc.client5.http.ClientProtocolException: Not Found (HTTP status code: 404, URL: https://github.com/react-native-community/boost-for-react-native/releases/download/v1.76.0-0/boost_1_76_0.tar.gz)
Again, it's related to RN 0.69 update that can easily be fixed by changing react-native-quick-crypto/android/build.gradle
file as follows:
@@ -208,7 +218,12 @@ task createNativeDepsDirectories {
}
task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) {
- src("https://github.com/react-native-community/boost-for-react-native/releases/download/v${BOOST_VERSION.replace("_", ".")}-0/boost_${BOOST_VERSION}.tar.gz")
+ def transformedVersion = BOOST_VERSION.replace("_", ".")
+ def srcUrl = "https://boostorg.jfrog.io/artifactory/main/release/${transformedVersion}/source/boost_${BOOST_VERSION}.tar.gz"
+ if (REACT_NATIVE_VERSION < 69) {
+ srcUrl = "https://github.com/react-native-community/boost-for-react-native/releases/download/v${transformedVersion}-0/boost_${BOOST_VERSION}.tar.gz"
+ }
+ src(srcUrl)
onlyIfNewer(true)
overwrite(false)
dest(boost_file)
I'll create a PR with both fixes.
I'm using this package with ethers.js as instructed however the results are the same as using crypto-browserify or using nothing at all. Not sure if I'm using the wrong version of ethers or if there's something wrong with the library
react-native info
info Fetching system and libraries information...
System:
OS: macOS 13.3
CPU: (8) arm64 Apple M1
Memory: 93.13 MB / 8.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.15.0 - /usr/local/bin/node
Yarn: Not Found
npm: 9.5.0 - /usr/local/bin/npm
Watchman: 2023.04.03.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.12.0 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
Android SDK:
API Levels: 30, 33, 33
Build Tools: 30.0.2, 30.0.3, 33.0.2
System Images: android-33 | Google APIs ARM 64 v8a
Android NDK: Not Found
IDEs:
Android Studio: 2022.1 AI-221.6008.13.2211.9619390
Xcode: 14.3/14E222b - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_362 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.2.0 => 18.2.0
react-native: 0.71.6 => 0.71.6
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found
To fix this it is better to configure Metro instead of Babel to replace imports.
I am doing this for expo this way:
// Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require('expo/metro-config');
const cfg = getDefaultConfig(__dirname);
cfg.resolver.extraNodeModules = {
'crypto': `${__dirname}/node_modules/react-native-quick-crypto`,
'stream': `${__dirname}/node_modules/stream-browserify`,
'buffer': `${__dirname}/node_modules/@craftzdog/react-native-buffer`,
};
console.warn(cfg);
module.exports = cfg;
Hello,
I have a problem in Android every time building my project with yarn android
command i have 124Mo to download before i can access to my project. It is very long and on every build. i let you the screenshot of my package version and the build part that takes a long time.
Do you know how can i fix this ?
Thanks
I'm getting this issue.
It's related to the same issue in React Native, which has been fixed facebook/react-native#34106
The current workaround is to manually bump the react-native-quick-crypto and quick-base64 to iOS 12.4 in the project, but it doesn't feel like a stable long term solution, hence this issue.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.