@derec-alliance/react-native 0.0.1
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/DeRec.podspec +25 -0
- package/LICENSE +201 -0
- package/README.md +222 -0
- package/android/CMakeLists.txt +38 -0
- package/android/build.gradle +79 -0
- package/android/src/main/AndroidManifest.xml +12 -0
- package/android/src/main/java/org/derec/DeRecModule.kt +56 -0
- package/android/src/main/java/org/derec/DeRecPackage.kt +24 -0
- package/android/src/main/jni/OnLoad.cpp +39 -0
- package/android/src/main/jniLibs/arm64-v8a/libderec_library.a +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libderec_library.a +0 -0
- package/android/src/main/jniLibs/x86_64/libderec_library.a +0 -0
- package/cpp/Convert.cpp +50 -0
- package/cpp/Convert.h +38 -0
- package/cpp/DeRecInstaller.cpp +186 -0
- package/cpp/DeRecInstaller.h +28 -0
- package/cpp/Invoker.h +20 -0
- package/cpp/JsCallbackBridge.cpp +144 -0
- package/cpp/JsCallbackBridge.h +148 -0
- package/cpp/Primitives.cpp +1193 -0
- package/cpp/Primitives.h +39 -0
- package/cpp/ProtocolHost.cpp +613 -0
- package/cpp/ProtocolHost.h +88 -0
- package/cpp/RuntimeInvoker.h +29 -0
- package/cpp/StoreCallbacks.cpp +1293 -0
- package/cpp/StoreCallbacks.h +111 -0
- package/cpp/WorkerThread.cpp +74 -0
- package/cpp/WorkerThread.h +54 -0
- package/cpp/derec_ffi.h +2145 -0
- package/ios/DeRec.h +23 -0
- package/ios/DeRec.mm +39 -0
- package/ios/DeRecFFI.xcframework/Info.plist +48 -0
- package/ios/DeRecFFI.xcframework/ios-arm64/Headers/derec_ffi.h +2145 -0
- package/ios/DeRecFFI.xcframework/ios-arm64/libderec_library.a +0 -0
- package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/Headers/derec_ffi.h +2145 -0
- package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/libderec_library.a +0 -0
- package/lib/binary.d.ts +19 -0
- package/lib/binary.js +164 -0
- package/lib/codec.d.ts +16 -0
- package/lib/codec.js +80 -0
- package/lib/errors.d.ts +23 -0
- package/lib/errors.js +35 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +27 -0
- package/lib/messages.d.ts +41 -0
- package/lib/messages.js +192 -0
- package/lib/native.d.ts +11 -0
- package/lib/native.js +40 -0
- package/lib/primitives.d.ts +137 -0
- package/lib/primitives.js +329 -0
- package/lib/protocol.d.ts +188 -0
- package/lib/protocol.js +514 -0
- package/lib/types.d.ts +1014 -0
- package/lib/types.js +63 -0
- package/package.json +55 -0
- package/react-native.config.js +19 -0
- package/src/binary.ts +182 -0
- package/src/codec.ts +79 -0
- package/src/errors.ts +45 -0
- package/src/index.ts +7 -0
- package/src/messages.ts +192 -0
- package/src/native.ts +52 -0
- package/src/primitives.ts +770 -0
- package/src/protocol.ts +621 -0
- package/src/types.ts +1040 -0
package/DeRec.podspec
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "DeRec"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.license = "Apache-2.0"
|
|
10
|
+
s.authors = "DeRec Alliance"
|
|
11
|
+
s.homepage = "https://derec.org"
|
|
12
|
+
s.platforms = { :ios => "13.4" }
|
|
13
|
+
s.source = { :git => "https://github.com/derecalliance/lib-derec.git" }
|
|
14
|
+
|
|
15
|
+
s.source_files = "ios/**/*.{h,mm}", "cpp/**/*.{h,cpp}"
|
|
16
|
+
s.exclude_files = "cpp/tests/**/*"
|
|
17
|
+
s.vendored_frameworks = "ios/DeRecFFI.xcframework"
|
|
18
|
+
|
|
19
|
+
s.pod_target_xcconfig = {
|
|
20
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
|
|
21
|
+
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/cpp\""
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
install_modules_dependencies(s)
|
|
25
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# DeRec React Native SDK
|
|
2
|
+
|
|
3
|
+
React Native bindings for `derec-library`, the Rust SDK implementing the
|
|
4
|
+
DeRec protocol.
|
|
5
|
+
|
|
6
|
+
DeRec enables decentralized recovery of secrets by distributing encrypted
|
|
7
|
+
shares across trusted helpers. This package exposes the Rust core to
|
|
8
|
+
JavaScript/TypeScript through a JSI (JavaScript Interface) native module —
|
|
9
|
+
all cryptography, protobuf handling and protocol validation run in native
|
|
10
|
+
code; the JS side only marshals arguments and results.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @derec-alliance/react-native
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
or with yarn:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
yarn add @derec-alliance/react-native
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
iOS additionally requires a pod install:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
cd ios && pod install
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Autolinking picks up the podspec and the Android Gradle module automatically
|
|
33
|
+
via `react-native.config.js` — no manual native project edits are needed on
|
|
34
|
+
either platform.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Requirements
|
|
39
|
+
|
|
40
|
+
| | |
|
|
41
|
+
|---|---|
|
|
42
|
+
| `react-native` | >= 0.76.0 |
|
|
43
|
+
| `react` | >= 18.2.0 |
|
|
44
|
+
| iOS deployment target | 13.4+ |
|
|
45
|
+
| Android `minSdk` | 24 |
|
|
46
|
+
|
|
47
|
+
This package ships a compiled C++/JSI native module (an iOS XCFramework and
|
|
48
|
+
per-ABI Android static libraries). **It cannot run inside Expo Go.** Expo Go
|
|
49
|
+
is a fixed, pre-built binary that only contains the native modules Expo
|
|
50
|
+
shipped with it — any package with custom native code, this one included,
|
|
51
|
+
requires an [Expo dev build](https://docs.expo.dev/develop/development-builds/introduction/)
|
|
52
|
+
(`npx expo run:ios` / `npx expo run:android`, or `eas build --profile
|
|
53
|
+
development`) instead. This is not specific to DeRec; it is true of every
|
|
54
|
+
React Native library that ships native code.
|
|
55
|
+
|
|
56
|
+
Plain (non-Expo) React Native projects are unaffected — a normal debug or
|
|
57
|
+
release build already includes whatever native modules are linked in.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Quickstart: pairing two devices
|
|
62
|
+
|
|
63
|
+
`DeRecProtocol` is the orchestrator: it owns protocol state, drives flows to
|
|
64
|
+
completion, and reports progress as `DeRecEvent`s. Build one with
|
|
65
|
+
`DeRecProtocolBuilder`, supplying an implementation of each store interface
|
|
66
|
+
and a `Transport` for sending outbound messages:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import {
|
|
70
|
+
ContactMode,
|
|
71
|
+
DeRecProtocolBuilder,
|
|
72
|
+
FlowKind,
|
|
73
|
+
SenderKind,
|
|
74
|
+
} from '@derec-alliance/react-native';
|
|
75
|
+
|
|
76
|
+
const protocol = new DeRecProtocolBuilder(secretId) // bigint | number
|
|
77
|
+
.withChannelStore(myChannelStore)
|
|
78
|
+
.withShareStore(myShareStore)
|
|
79
|
+
.withSecretStore(mySecretStore)
|
|
80
|
+
.withUserSecretStore(myUserSecretStore)
|
|
81
|
+
.withStateStore(myStateStore)
|
|
82
|
+
.withTransport(myTransport)
|
|
83
|
+
.withOwnTransport({ uri: 'https://owner.example.com', protocol: 'https' })
|
|
84
|
+
.withThreshold(2)
|
|
85
|
+
.build();
|
|
86
|
+
|
|
87
|
+
// Out-of-band: hand `contact` to the peer (QR code, deep link, ...).
|
|
88
|
+
const contact = await protocol.createContact(null, ContactMode.InlineKeys);
|
|
89
|
+
|
|
90
|
+
// Peer side, once it has `contact`:
|
|
91
|
+
// const events = await peerProtocol.start(FlowKind.Pairing, {
|
|
92
|
+
// kind: SenderKind.Helper,
|
|
93
|
+
// contact,
|
|
94
|
+
// });
|
|
95
|
+
|
|
96
|
+
// Owner side, once the peer's response arrives over your transport:
|
|
97
|
+
const events = await protocol.process(responseBytes);
|
|
98
|
+
for (const event of events) {
|
|
99
|
+
if (event.type === 'PairingCompleted') {
|
|
100
|
+
// event.channel_id is the long-term id both sides rotated to.
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`protocol.free()` releases the native handle once the protocol instance is no
|
|
106
|
+
longer needed (safe to call more than once).
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Store interfaces
|
|
111
|
+
|
|
112
|
+
The application layer owns all persistence; the library never writes to disk
|
|
113
|
+
directly. `DeRecProtocolBuilder` takes one implementation of each interface
|
|
114
|
+
declared in `src/types.ts`:
|
|
115
|
+
|
|
116
|
+
- **`ChannelStore`** — pairing state: helper channels and replica-group
|
|
117
|
+
membership, keyed by `(channelId, replicaId)`.
|
|
118
|
+
- **`ShareStore`** — versioned VSS shares this device holds as a helper.
|
|
119
|
+
- **`SecretStore`** — small per-channel key material (shared keys, etc.),
|
|
120
|
+
distinct from share bytes.
|
|
121
|
+
- **`UserSecretStore`** — the most recent user-facing secret snapshot per
|
|
122
|
+
`secretId`, used to auto-publish to newly paired peers.
|
|
123
|
+
- **`StateStore`** — in-flight orchestrator bookkeeping (pending
|
|
124
|
+
verifications, recoveries, unpairs, sharing rounds, sync checks) so a
|
|
125
|
+
multi-round flow survives an app restart.
|
|
126
|
+
- **`Transport`** — outbound delivery. `send(endpoint, message)` posts a
|
|
127
|
+
wire-format envelope to a peer; it is a mailbox, not a request/response
|
|
128
|
+
call, since not every peer (e.g. a phone behind NAT) can be dialed back.
|
|
129
|
+
|
|
130
|
+
Every method is `async` and keyed by decimal-string ids — see the next
|
|
131
|
+
section for why that differs from `DeRecProtocol`'s own methods. Full field-
|
|
132
|
+
level contracts are documented as TSDoc on each interface in `src/types.ts`.
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Threading model
|
|
137
|
+
|
|
138
|
+
The native module runs each `DeRecProtocol` instance's flow logic (`start`,
|
|
139
|
+
`process`, `tick`, `accept`, `restore`, ...) on a dedicated worker thread, off
|
|
140
|
+
the JavaScript thread, precisely because that logic calls back into your
|
|
141
|
+
store and transport implementations — which are themselves JavaScript and
|
|
142
|
+
can take an unbounded amount of time (disk I/O, network requests). Those
|
|
143
|
+
methods return a `Promise`.
|
|
144
|
+
|
|
145
|
+
**Primitives are the exception.** The functions under `primitives.*` (and
|
|
146
|
+
`envelope.*`) are pure byte transforms with no store or transport callbacks,
|
|
147
|
+
so they run synchronously, in-line, on the calling JavaScript thread —
|
|
148
|
+
including `primitives.sharing.request.split` (`protect_secret`), which does
|
|
149
|
+
real cryptographic work: Shamir secret splitting, AES-GCM encryption, and
|
|
150
|
+
Merkle tree construction over the shares. For a handful of small shares this
|
|
151
|
+
is fast; for larger secrets or higher share counts it will block rendering
|
|
152
|
+
for its duration. Applications that need this work off the JS thread should
|
|
153
|
+
drive it through `DeRecProtocol` (e.g. `start(FlowKind.ProtectSecret, ...)`)
|
|
154
|
+
instead of calling the primitive directly.
|
|
155
|
+
|
|
156
|
+
**Do not call protocol methods from inside a store callback.** A store
|
|
157
|
+
method (`load`, `save`, `remove`, ...) is invoked as a callback into
|
|
158
|
+
JavaScript, with the protocol's worker blocked waiting for the promise that
|
|
159
|
+
callback returns. Calling a `DeRecProtocol` method from inside the body of
|
|
160
|
+
that callback would enqueue a new unit of work onto the very worker that is
|
|
161
|
+
already blocked waiting for you — an unbreakable deadlock. The binding
|
|
162
|
+
detects this and rejects the call with an explicit error instead of hanging.
|
|
163
|
+
|
|
164
|
+
The restriction is exactly that narrow: it applies to the store method's own
|
|
165
|
+
body, not to the whole window your returned promise is pending, and not to
|
|
166
|
+
other JavaScript code that merely runs at the same time. Protocol calls from
|
|
167
|
+
anywhere else are always safe — the worker is serial, so they simply run
|
|
168
|
+
after whatever is in flight.
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## Known differences from `@derec-alliance/nodejs`
|
|
173
|
+
|
|
174
|
+
**`setCommunicationInfo()` and `setOwnTransport()` return a `Promise`.**
|
|
175
|
+
`@derec-alliance/nodejs` declares both `void`. Here they must not run on the
|
|
176
|
+
JavaScript thread: the underlying FFI setter takes the same handle lock a
|
|
177
|
+
running flow holds across its store callbacks, and those callbacks block the
|
|
178
|
+
worker until JavaScript settles them — so a synchronous setter would block
|
|
179
|
+
the JavaScript thread on a lock only the JavaScript thread can release. The
|
|
180
|
+
binding queues them onto the same serial worker every flow runs on instead.
|
|
181
|
+
The nodejs SDK is WASM and single-threaded, so it cannot hit this. Code that
|
|
182
|
+
ignores the return value — the way nodejs code calls these — is unaffected;
|
|
183
|
+
awaiting them additionally lets a failure surface instead of vanishing.
|
|
184
|
+
|
|
185
|
+
**The `DeRecErrorCategory` union differs from nodejs's.** This SDK's union
|
|
186
|
+
omits `"wasm"`, which a C-ABI binding can never emit, and adds `"ok"`,
|
|
187
|
+
`"ffi"` and `"state_store"`, which it can. A test pins the union to
|
|
188
|
+
`bindings/test_fixture/enums.json` so it stays in step with the Rust enum.
|
|
189
|
+
|
|
190
|
+
**Ids are decimal strings in stores, `bigint | number` on `DeRecProtocol`.**
|
|
191
|
+
Store interfaces (`ChannelStore`, `ShareStore`, event fields such as
|
|
192
|
+
`channel_id` / `replica_id`, etc.) use decimal strings for every `u64` id,
|
|
193
|
+
matching the TypeScript store contracts and avoiding the precision loss a
|
|
194
|
+
JS `number` would suffer above 2^53. `DeRecProtocol`'s own methods
|
|
195
|
+
(`createContact`, `getFingerprint`, `verifyFingerprint`, the builder's
|
|
196
|
+
`withReplicaId`, ...) instead take `bigint | number` directly, since those
|
|
197
|
+
call sites hand the id straight to the native layer rather than round-
|
|
198
|
+
tripping it through storage. Both conventions are deliberate; keep track of
|
|
199
|
+
which side of the boundary an id is on rather than assuming one form
|
|
200
|
+
everywhere.
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Package contents
|
|
205
|
+
|
|
206
|
+
```text
|
|
207
|
+
lib/ compiled TypeScript output (index.js, index.d.ts, ...)
|
|
208
|
+
src/ TypeScript source
|
|
209
|
+
cpp/ JSI native module (shared by iOS and Android)
|
|
210
|
+
ios/ DeRecFFI.xcframework, iOS module glue
|
|
211
|
+
android/ Gradle module, JNI glue
|
|
212
|
+
DeRec.podspec
|
|
213
|
+
react-native.config.js
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## License
|
|
219
|
+
|
|
220
|
+
Apache License 2.0
|
|
221
|
+
|
|
222
|
+
See `LICENSE` for details.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.13)
|
|
2
|
+
project(derec_jsi)
|
|
3
|
+
|
|
4
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
5
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
6
|
+
|
|
7
|
+
# React Native ships jsi, reactnative and fbjni as prefab packages. They have
|
|
8
|
+
# to be imported explicitly: without these `find_package` calls the
|
|
9
|
+
# `ReactAndroid::*` and `fbjni::*` targets do not exist, and the link below
|
|
10
|
+
# fails at CMake configure time rather than at build time. `prefab` is enabled
|
|
11
|
+
# on the module in build.gradle, which is what puts them on the search path.
|
|
12
|
+
find_package(ReactAndroid REQUIRED CONFIG)
|
|
13
|
+
find_package(fbjni REQUIRED CONFIG)
|
|
14
|
+
|
|
15
|
+
# Non-recursive on purpose: `cpp/tests/` holds the host-only test harness,
|
|
16
|
+
# which must not be compiled into the device library.
|
|
17
|
+
file(GLOB DEREC_CPP_SOURCES "${CMAKE_SOURCE_DIR}/../cpp/*.cpp")
|
|
18
|
+
|
|
19
|
+
add_library(derec_jsi SHARED
|
|
20
|
+
${DEREC_CPP_SOURCES}
|
|
21
|
+
"${CMAKE_SOURCE_DIR}/src/main/jni/OnLoad.cpp"
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
target_include_directories(derec_jsi PRIVATE "${CMAKE_SOURCE_DIR}/../cpp")
|
|
25
|
+
|
|
26
|
+
# The Rust core links in statically, so a single .so ships per ABI.
|
|
27
|
+
add_library(derec_rust STATIC IMPORTED)
|
|
28
|
+
set_target_properties(derec_rust PROPERTIES IMPORTED_LOCATION
|
|
29
|
+
"${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libderec_library.a")
|
|
30
|
+
|
|
31
|
+
target_link_libraries(derec_jsi
|
|
32
|
+
derec_rust
|
|
33
|
+
ReactAndroid::jsi
|
|
34
|
+
ReactAndroid::reactnative
|
|
35
|
+
fbjni::fbjni
|
|
36
|
+
android
|
|
37
|
+
log
|
|
38
|
+
)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
// An autolinked library module is configured by the host app's Gradle build,
|
|
3
|
+
// so the toolchain versions have to come from the app rather than be pinned
|
|
4
|
+
// here — a library that hardcoded them would collide with whatever React
|
|
5
|
+
// Native version the app is on. The literals are fallbacks for a standalone
|
|
6
|
+
// build only.
|
|
7
|
+
def kotlinVersion = rootProject.ext.has('kotlinVersion')
|
|
8
|
+
? rootProject.ext.get('kotlinVersion')
|
|
9
|
+
: '2.2.0'
|
|
10
|
+
|
|
11
|
+
repositories {
|
|
12
|
+
google()
|
|
13
|
+
mavenCentral()
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
dependencies {
|
|
17
|
+
classpath("com.android.tools.build:gradle:9.2.1")
|
|
18
|
+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
def derecExtOr(name, defaultValue) {
|
|
23
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : defaultValue
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
apply plugin: "com.android.library"
|
|
27
|
+
apply plugin: "org.jetbrains.kotlin.android"
|
|
28
|
+
|
|
29
|
+
android {
|
|
30
|
+
namespace "org.derec"
|
|
31
|
+
compileSdk derecExtOr('compileSdkVersion', 35).toString().toInteger()
|
|
32
|
+
|
|
33
|
+
// Must match the NDK `scripts/prepare-react-native-package.sh` built
|
|
34
|
+
// `libderec_library.a` with. Left unset, AGP picks its own default — a
|
|
35
|
+
// different NDK than the archive was compiled against, which links the two
|
|
36
|
+
// C++ runtimes together and fails in ways that surface at run time.
|
|
37
|
+
// Not named `ndk`: that would shadow the `ndk { }` DSL block in
|
|
38
|
+
// `defaultConfig` below, and Groovy resolves the local first — turning the
|
|
39
|
+
// block into a call on a String.
|
|
40
|
+
def requestedNdkVersion = derecExtOr('ndkVersion', null)
|
|
41
|
+
if (requestedNdkVersion != null) {
|
|
42
|
+
ndkVersion requestedNdkVersion.toString()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
defaultConfig {
|
|
46
|
+
minSdk derecExtOr('minSdkVersion', 24).toString().toInteger()
|
|
47
|
+
|
|
48
|
+
externalNativeBuild {
|
|
49
|
+
cmake {
|
|
50
|
+
cppFlags "-frtti -fexceptions -std=c++17"
|
|
51
|
+
arguments "-DANDROID_STL=c++_shared"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// `i686-linux-android` is deliberately absent: `prepare-react-native-
|
|
56
|
+
// package.sh` does not build it, so listing it here would fail the link
|
|
57
|
+
// rather than skip the ABI.
|
|
58
|
+
ndk {
|
|
59
|
+
abiFilters "arm64-v8a", "armeabi-v7a", "x86_64"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
externalNativeBuild {
|
|
64
|
+
cmake {
|
|
65
|
+
path "CMakeLists.txt"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
buildFeatures {
|
|
70
|
+
buildConfig false
|
|
71
|
+
// Puts React Native's jsi/reactnative and fbjni prefab packages on CMake's
|
|
72
|
+
// search path; `find_package` in CMakeLists.txt fails without it.
|
|
73
|
+
prefab true
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
dependencies {
|
|
78
|
+
implementation "com.facebook.react:react-android"
|
|
79
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<!--
|
|
3
|
+
Required for autolinking, not for its contents.
|
|
4
|
+
|
|
5
|
+
React Native's Android autolinking treats a dependency as having no Android
|
|
6
|
+
platform unless this file exists: without it `platforms.android` resolves to
|
|
7
|
+
null, `packageImportPath` is never computed, and `DeRecPackage` is silently
|
|
8
|
+
left out of the generated `PackageList` — the module is simply absent at run
|
|
9
|
+
time, with no build error. The package name comes from `namespace` in
|
|
10
|
+
build.gradle, so nothing else belongs here.
|
|
11
|
+
-->
|
|
12
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
package org.derec
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
5
|
+
import com.facebook.react.bridge.ReactMethod
|
|
6
|
+
import com.facebook.react.common.annotations.FrameworkAPI
|
|
7
|
+
import com.facebook.react.turbomodule.core.CallInvokerHolderImpl
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Minimal module whose only job is to install the `__DeRec` JSI host object.
|
|
11
|
+
*
|
|
12
|
+
* iOS reaches the runtime through `RCTTurboModuleWithJSIBindings`, which the
|
|
13
|
+
* platform calls on its own. Android has no equivalent hook for a module that
|
|
14
|
+
* is not code-generated, so JavaScript calls [install] once, synchronously,
|
|
15
|
+
* before the first use of the SDK — see `src/native.ts`.
|
|
16
|
+
*/
|
|
17
|
+
class DeRecModule(reactContext: ReactApplicationContext) :
|
|
18
|
+
ReactContextBaseJavaModule(reactContext) {
|
|
19
|
+
|
|
20
|
+
override fun getName() = NAME
|
|
21
|
+
|
|
22
|
+
// `jsCallInvokerHolder` is annotated `@FrameworkAPI`: React Native reserves
|
|
23
|
+
// it for framework authors and may change it in a minor release. There is no
|
|
24
|
+
// stable alternative for reaching the CallInvoker from a module that is not
|
|
25
|
+
// code-generated, so the opt-in is deliberate and the risk is a compile
|
|
26
|
+
// failure on upgrade — not a silent behaviour change.
|
|
27
|
+
@OptIn(FrameworkAPI::class)
|
|
28
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
29
|
+
fun install(): Boolean {
|
|
30
|
+
val context = reactApplicationContext
|
|
31
|
+
val runtimePtr = context.javaScriptContextHolder?.get() ?: return false
|
|
32
|
+
// `jsCallInvokerHolder` on the context, not `catalystInstance` — there is
|
|
33
|
+
// no catalyst instance in a bridgeless app, which is the default from
|
|
34
|
+
// React Native 0.76 onward, and touching it throws there.
|
|
35
|
+
val holder = context.jsCallInvokerHolder as? CallInvokerHolderImpl ?: return false
|
|
36
|
+
nativeInstall(runtimePtr, holder)
|
|
37
|
+
return true
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
override fun invalidate() {
|
|
41
|
+
nativeInvalidate()
|
|
42
|
+
super.invalidate()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private external fun nativeInstall(runtimePtr: Long, callInvokerHolder: Any)
|
|
46
|
+
|
|
47
|
+
private external fun nativeInvalidate()
|
|
48
|
+
|
|
49
|
+
companion object {
|
|
50
|
+
const val NAME = "DeRec"
|
|
51
|
+
|
|
52
|
+
init {
|
|
53
|
+
System.loadLibrary("derec_jsi")
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
package org.derec
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.uimanager.ViewManager
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Registers [DeRecModule] with the host app.
|
|
10
|
+
*
|
|
11
|
+
* React Native's Android autolinking discovers a library by finding a
|
|
12
|
+
* `ReactPackage` implementation in its sources; without one the module is
|
|
13
|
+
* never instantiated and `install()` is unreachable from JavaScript, so the
|
|
14
|
+
* `__DeRec` host object never appears. iOS needs no equivalent — there,
|
|
15
|
+
* `RCT_EXPORT_MODULE()` registers the module at load time.
|
|
16
|
+
*/
|
|
17
|
+
class DeRecPackage : ReactPackage {
|
|
18
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> =
|
|
19
|
+
listOf(DeRecModule(reactContext))
|
|
20
|
+
|
|
21
|
+
override fun createViewManagers(
|
|
22
|
+
reactContext: ReactApplicationContext,
|
|
23
|
+
): List<ViewManager<*, *>> = emptyList()
|
|
24
|
+
}
|