react-native-quick-crypto 0.7.9 → 0.7.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +3 -2
- package/android/src/main/cpp/cpp-adapter.cpp +9 -0
- package/cpp/JSIUtils/MGLTypedArray.cpp +38 -17
- package/cpp/JSIUtils/MGLTypedArray.h +20 -1
- package/cpp/MGLQuickCryptoHostObject.h +1 -1
- package/ios/QuickCrypto.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/QuickCrypto.xcodeproj/project.xcworkspace/xcuserdata/brad.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/QuickCrypto.xcodeproj/xcuserdata/brad.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/ios/QuickCryptoModule.mm +10 -0
- package/package.json +1 -1
package/android/build.gradle
CHANGED
|
@@ -171,8 +171,9 @@ repositories {
|
|
|
171
171
|
dependencies {
|
|
172
172
|
//noinspection GradleDynamicVersion
|
|
173
173
|
implementation "com.facebook.react:react-android:+"
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
|
|
175
|
+
// Add a dependency on OpenSSL
|
|
176
|
+
implementation 'io.github.ronickg:openssl:3.3.2'
|
|
176
177
|
}
|
|
177
178
|
|
|
178
179
|
// Resolves "LOCAL_SRC_FILES points to a missing file, Check that libfb.so exists or that its path is correct".
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
#include <fbjni/fbjni.h>
|
|
3
3
|
#include <jni.h>
|
|
4
4
|
#include <jsi/jsi.h>
|
|
5
|
+
#include <memory>
|
|
5
6
|
|
|
6
7
|
#include "MGLQuickCryptoHostObject.h"
|
|
8
|
+
#include "JSIUtils/MGLTypedArray.h"
|
|
7
9
|
|
|
8
10
|
using namespace facebook;
|
|
9
11
|
|
|
@@ -28,6 +30,13 @@ class CryptoCppAdapter : public jni::HybridClass<CryptoCppAdapter> {
|
|
|
28
30
|
auto object = jsi::Object::createFromHostObject(runtime, hostObject);
|
|
29
31
|
runtime.global().setProperty(runtime, "__QuickCryptoProxy",
|
|
30
32
|
std::move(object));
|
|
33
|
+
// Adds the PropNameIDCache object to the Runtime. If the Runtime gets destroyed, the Object gets destroyed and the cache gets invalidated.
|
|
34
|
+
auto propNameIdCache = std::make_shared<InvalidateCacheOnDestroy>(runtime);
|
|
35
|
+
runtime.global().setProperty(
|
|
36
|
+
runtime,
|
|
37
|
+
"rnqcArrayBufferPropNameIdCache",
|
|
38
|
+
jsi::Object::createFromHostObject(runtime, propNameIdCache)
|
|
39
|
+
);
|
|
31
40
|
}
|
|
32
41
|
|
|
33
42
|
void nativeInstall(
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
|
|
11
11
|
#include <algorithm>
|
|
12
12
|
#include <memory>
|
|
13
|
+
#include <utility>
|
|
14
|
+
#include <vector>
|
|
13
15
|
#include <string>
|
|
14
16
|
#include <unordered_map>
|
|
15
17
|
|
|
@@ -40,33 +42,37 @@ enum class Prop {
|
|
|
40
42
|
class PropNameIDCache {
|
|
41
43
|
public:
|
|
42
44
|
const jsi::PropNameID &get(jsi::Runtime &runtime, Prop prop) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
auto key = reinterpret_cast<uintptr_t>(&runtime);
|
|
46
|
+
if (this->props.find(key) == this->props.end()) {
|
|
47
|
+
this->props[key] = std::unordered_map<Prop, std::unique_ptr<jsi::PropNameID>>();
|
|
46
48
|
}
|
|
47
|
-
|
|
49
|
+
if (!this->props[key][prop]) {
|
|
50
|
+
this->props[key][prop] = std::make_unique<jsi::PropNameID>(createProp(runtime, prop));
|
|
51
|
+
}
|
|
52
|
+
return *(this->props[key][prop]);
|
|
48
53
|
}
|
|
49
54
|
|
|
50
|
-
const jsi::PropNameID &getConstructorNameProp(jsi::Runtime &runtime,
|
|
51
|
-
MGLTypedArrayKind kind);
|
|
55
|
+
const jsi::PropNameID &getConstructorNameProp(jsi::Runtime &runtime, MGLTypedArrayKind kind);
|
|
52
56
|
|
|
53
|
-
void invalidate() {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
*/
|
|
58
|
-
//props.erase(props.begin(), props.end());
|
|
57
|
+
void invalidate(uintptr_t key) {
|
|
58
|
+
if (props.find(key) != props.end()) {
|
|
59
|
+
props[key].clear();
|
|
60
|
+
}
|
|
59
61
|
}
|
|
60
|
-
|
|
61
62
|
private:
|
|
62
|
-
std::unordered_map<Prop, std::unique_ptr<jsi::PropNameID
|
|
63
|
+
std::unordered_map<uintptr_t, std::unordered_map<Prop, std::unique_ptr<jsi::PropNameID>>> props;
|
|
63
64
|
|
|
64
65
|
jsi::PropNameID createProp(jsi::Runtime &runtime, Prop prop);
|
|
65
66
|
};
|
|
66
67
|
|
|
67
68
|
PropNameIDCache propNameIDCache;
|
|
68
69
|
|
|
69
|
-
|
|
70
|
+
InvalidateCacheOnDestroy::InvalidateCacheOnDestroy(jsi::Runtime &runtime) {
|
|
71
|
+
key = reinterpret_cast<uintptr_t>(&runtime);
|
|
72
|
+
}
|
|
73
|
+
InvalidateCacheOnDestroy::~InvalidateCacheOnDestroy() {
|
|
74
|
+
propNameIDCache.invalidate(key);
|
|
75
|
+
}
|
|
70
76
|
|
|
71
77
|
MGLTypedArrayKind getTypedArrayKindForName(const std::string &name);
|
|
72
78
|
|
|
@@ -75,8 +81,9 @@ MGLTypedArrayBase::MGLTypedArrayBase(jsi::Runtime &runtime, size_t size,
|
|
|
75
81
|
: MGLTypedArrayBase(
|
|
76
82
|
runtime,
|
|
77
83
|
runtime.global()
|
|
78
|
-
.getProperty(
|
|
79
|
-
|
|
84
|
+
.getProperty(
|
|
85
|
+
runtime,
|
|
86
|
+
propNameIDCache.getConstructorNameProp(runtime, kind))
|
|
80
87
|
.asObject(runtime)
|
|
81
88
|
.asFunction(runtime)
|
|
82
89
|
.callAsConstructor(runtime, {static_cast<double>(size)})
|
|
@@ -236,6 +243,20 @@ void MGLTypedArray<T>::update(jsi::Runtime &runtime,
|
|
|
236
243
|
reinterpret_cast<ContentType<T> *>(rawData));
|
|
237
244
|
}
|
|
238
245
|
|
|
246
|
+
template <MGLTypedArrayKind T>
|
|
247
|
+
void MGLTypedArray<T>::updateUnsafe(jsi::Runtime &runtime, ContentType<T> *data, size_t length) {
|
|
248
|
+
if (length != size(runtime)) {
|
|
249
|
+
throw jsi::JSError(runtime, "TypedArray can only be updated with an array of the same size");
|
|
250
|
+
}
|
|
251
|
+
uint8_t *rawData = getBuffer(runtime).data(runtime) + byteOffset(runtime);
|
|
252
|
+
memcpy(rawData, data, length);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
template <MGLTypedArrayKind T>
|
|
256
|
+
uint8_t* MGLTypedArray<T>::data(jsi::Runtime &runtime) {
|
|
257
|
+
return getBuffer(runtime).data(runtime) + byteOffset(runtime);
|
|
258
|
+
}
|
|
259
|
+
|
|
239
260
|
const jsi::PropNameID &PropNameIDCache::getConstructorNameProp(
|
|
240
261
|
jsi::Runtime &runtime, MGLTypedArrayKind kind) {
|
|
241
262
|
switch (kind) {
|
|
@@ -69,7 +69,24 @@ struct typedArrayTypeMap<MGLTypedArrayKind::Float64Array> {
|
|
|
69
69
|
typedef double type;
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
// Instance of this class will invalidate PropNameIDCache when destructor is called.
|
|
73
|
+
// Attach this object to global in specific jsi::Runtime to make sure lifecycle of
|
|
74
|
+
// the cache object is connected to the lifecycle of the js runtime
|
|
75
|
+
class InvalidateCacheOnDestroy : public jsi::HostObject {
|
|
76
|
+
public:
|
|
77
|
+
explicit InvalidateCacheOnDestroy(jsi::Runtime &runtime);
|
|
78
|
+
virtual ~InvalidateCacheOnDestroy();
|
|
79
|
+
virtual jsi::Value get(jsi::Runtime &, const jsi::PropNameID &name) {
|
|
80
|
+
return jsi::Value::null();
|
|
81
|
+
}
|
|
82
|
+
virtual void set(jsi::Runtime &, const jsi::PropNameID &name, const jsi::Value &value) {}
|
|
83
|
+
virtual std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) {
|
|
84
|
+
return {};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private:
|
|
88
|
+
uintptr_t key;
|
|
89
|
+
};
|
|
73
90
|
|
|
74
91
|
class MGLTypedArrayBase : public jsi::Object {
|
|
75
92
|
public:
|
|
@@ -126,6 +143,8 @@ class MGLTypedArray : public MGLTypedArrayBase {
|
|
|
126
143
|
|
|
127
144
|
std::vector<ContentType<T>> toVector(jsi::Runtime &runtime);
|
|
128
145
|
void update(jsi::Runtime &runtime, const std::vector<ContentType<T>> &data);
|
|
146
|
+
void updateUnsafe(jsi::Runtime &runtime, ContentType<T> *data, size_t length);
|
|
147
|
+
uint8_t* data(jsi::Runtime &runtime);
|
|
129
148
|
};
|
|
130
149
|
|
|
131
150
|
template <MGLTypedArrayKind T>
|
|
@@ -22,7 +22,7 @@ class JSI_EXPORT MGLQuickCryptoHostObject : public MGLSmartHostObject {
|
|
|
22
22
|
std::shared_ptr<react::CallInvoker> jsCallInvoker,
|
|
23
23
|
std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
|
|
24
24
|
|
|
25
|
-
virtual ~MGLQuickCryptoHostObject() {
|
|
25
|
+
virtual ~MGLQuickCryptoHostObject() {}
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
} // namespace margelo
|
|
Binary file
|
package/ios/QuickCrypto.xcodeproj/xcuserdata/brad.xcuserdatad/xcschemes/xcschememanagement.plist
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>SchemeUserState</key>
|
|
6
|
+
<dict>
|
|
7
|
+
<key>QuickCrypto.xcscheme_^#shared#^_</key>
|
|
8
|
+
<dict>
|
|
9
|
+
<key>orderHint</key>
|
|
10
|
+
<integer>0</integer>
|
|
11
|
+
</dict>
|
|
12
|
+
</dict>
|
|
13
|
+
</dict>
|
|
14
|
+
</plist>
|
package/ios/QuickCryptoModule.mm
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
#import <jsi/jsi.h>
|
|
7
7
|
|
|
8
8
|
#import "../cpp/MGLQuickCryptoHostObject.h"
|
|
9
|
+
#import "../cpp/JSIUtils/MGLTypedArray.h"
|
|
9
10
|
|
|
10
11
|
@implementation QuickCryptoModule
|
|
11
12
|
|
|
@@ -40,6 +41,15 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
|
|
|
40
41
|
auto object = jsi::Object::createFromHostObject(runtime, hostObject);
|
|
41
42
|
runtime.global().setProperty(runtime, "__QuickCryptoProxy", std::move(object));
|
|
42
43
|
|
|
44
|
+
// Adds the PropNameIDCache object to the Runtime. If the Runtime gets
|
|
45
|
+
// destroyed, the Object gets destroyed and the cache gets invalidated.
|
|
46
|
+
auto propNameIdCache = std::make_shared<InvalidateCacheOnDestroy>(runtime);
|
|
47
|
+
runtime.global().setProperty(
|
|
48
|
+
runtime,
|
|
49
|
+
"rnqcArrayBufferPropNameIdCache",
|
|
50
|
+
jsi::Object::createFromHostObject(runtime, propNameIdCache)
|
|
51
|
+
);
|
|
52
|
+
|
|
43
53
|
NSLog(@"Successfully installed JSI bindings for react-native-quick-crypto!");
|
|
44
54
|
return @true;
|
|
45
55
|
}
|
package/package.json
CHANGED