@derec-alliance/react-native 0.0.2 → 0.0.3
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/README.md +28 -2
- 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/Primitives.cpp +27 -18
- package/cpp/ProtocolHost.cpp +37 -0
- package/cpp/StoreCallbacks.cpp +127 -19
- package/cpp/derec_ffi.h +145 -24
- package/ios/DeRecFFI.xcframework/Info.plist +5 -5
- package/ios/DeRecFFI.xcframework/ios-arm64/Headers/derec_ffi.h +145 -24
- package/ios/DeRecFFI.xcframework/ios-arm64/libderec_library.a +0 -0
- package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/Headers/derec_ffi.h +145 -24
- package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/libderec_library.a +0 -0
- package/lib/primitives.d.ts +9 -9
- package/lib/primitives.js +63 -13
- package/lib/protocol.d.ts +85 -6
- package/lib/protocol.js +119 -8
- package/lib/types.d.ts +313 -29
- package/lib/types.js +109 -2
- package/package.json +3 -16
- package/src/primitives.ts +77 -21
- package/src/protocol.ts +138 -13
- package/src/types.ts +379 -35
package/lib/protocol.js
CHANGED
|
@@ -56,12 +56,14 @@ function decodeEvents(buffer) {
|
|
|
56
56
|
* against does not carry this enum (it
|
|
57
57
|
* only covers the Rust-internal serde enums listed under its `"enums"` key);
|
|
58
58
|
* the transport `Protocol` enum lives in `protobufs/transportprotocol.proto`
|
|
59
|
-
* instead, where
|
|
59
|
+
* instead, where `HTTPS = 0` and `GRPC = 1` are defined.
|
|
60
60
|
*/
|
|
61
61
|
function protocolDiscriminant(protocol) {
|
|
62
62
|
switch (protocol.toLowerCase()) {
|
|
63
63
|
case 'https':
|
|
64
64
|
return 0;
|
|
65
|
+
case 'grpc':
|
|
66
|
+
return 1;
|
|
65
67
|
default:
|
|
66
68
|
throw new Error(`DeRec: unknown transport protocol "${protocol}"`);
|
|
67
69
|
}
|
|
@@ -117,7 +119,7 @@ function buildRestoreParams(recoveredSecret, version) {
|
|
|
117
119
|
helpers: recoveredSecret.helpers.map((helper) => {
|
|
118
120
|
const out = {
|
|
119
121
|
channel_id: helper.channel_id,
|
|
120
|
-
|
|
122
|
+
transports: helper.transports,
|
|
121
123
|
shared_key: Array.from(helper.shared_key),
|
|
122
124
|
};
|
|
123
125
|
const info = communicationInfoOrOmit(helper.communication_info);
|
|
@@ -138,7 +140,7 @@ function buildRestoreParams(recoveredSecret, version) {
|
|
|
138
140
|
members: recoveredSecret.replicas.members.map((member) => {
|
|
139
141
|
const out = {
|
|
140
142
|
replica_id: member.replica_id,
|
|
141
|
-
|
|
143
|
+
transports: member.transports,
|
|
142
144
|
role: member.role,
|
|
143
145
|
};
|
|
144
146
|
const info = communicationInfoOrOmit(member.communication_info);
|
|
@@ -217,16 +219,22 @@ function buildStartParams(flowKind, params) {
|
|
|
217
219
|
if (p.communication_info !== undefined) {
|
|
218
220
|
out.communication_info = p.communication_info;
|
|
219
221
|
}
|
|
220
|
-
if (p.
|
|
222
|
+
if (p.own_transports !== undefined && p.own_transports.length > 0) {
|
|
223
|
+
out.own_transports = p.own_transports;
|
|
224
|
+
// The first entry also fills the deprecated singular field so a peer
|
|
225
|
+
// predating `supported_transports` still learns the new address.
|
|
226
|
+
out.transport_protocol = p.own_transports[0];
|
|
227
|
+
}
|
|
228
|
+
else if (p.transport_protocol !== undefined) {
|
|
221
229
|
out.transport_protocol = p.transport_protocol;
|
|
222
230
|
}
|
|
223
231
|
return (0, codec_1.jsonToBytes)(out);
|
|
224
232
|
}
|
|
225
|
-
case types_1.FlowKind.
|
|
233
|
+
case types_1.FlowKind.ReplicaDiscovery:
|
|
226
234
|
// No parameters: the group and this device's own version both come
|
|
227
235
|
// from the stores.
|
|
228
236
|
return (0, codec_1.jsonToBytes)({});
|
|
229
|
-
case types_1.FlowKind.
|
|
237
|
+
case types_1.FlowKind.UnpairReplica: {
|
|
230
238
|
const p = params;
|
|
231
239
|
const out = { replica_id: p.replica_id };
|
|
232
240
|
if (p.memo !== undefined) {
|
|
@@ -288,11 +296,41 @@ class DeRecProtocolBuilder {
|
|
|
288
296
|
this.stores.transport = transport;
|
|
289
297
|
return this;
|
|
290
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* @deprecated Use {@link withOwnTransports}, which takes the whole
|
|
301
|
+
* preference list — `withOwnTransports([endpoint])` is the direct
|
|
302
|
+
* replacement. Removed at 0.0.5.
|
|
303
|
+
*/
|
|
291
304
|
withOwnTransport(endpoint) {
|
|
292
305
|
this.config.own_transport_uri = endpoint.uri;
|
|
293
306
|
this.config.own_transport_protocol = protocolDiscriminant(endpoint.protocol);
|
|
294
307
|
return this;
|
|
295
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Set every transport endpoint this application serves, in preference
|
|
311
|
+
* order. Written to the config's `own_transports` array, which takes
|
|
312
|
+
* precedence over `own_transport_uri` / `own_transport_protocol` on the
|
|
313
|
+
* Rust side when non-empty — see `ProtocolConfig` in
|
|
314
|
+
* `library/src/interop/ffi/protocol/handle/mod.rs`.
|
|
315
|
+
*
|
|
316
|
+
* The order given is forwarded verbatim: it is not sorted, deduplicated,
|
|
317
|
+
* or reordered here. It is this application's own preference and
|
|
318
|
+
* decides which of a peer's offered endpoints is used. Every listed
|
|
319
|
+
* transport must actually be served, because delivery is push-only —
|
|
320
|
+
* listing an endpoint this application does not serve makes pairing
|
|
321
|
+
* succeed and replies vanish.
|
|
322
|
+
*
|
|
323
|
+
* Supersedes {@link withOwnTransport} for applications serving more
|
|
324
|
+
* than one transport; the single-endpoint setter remains fully
|
|
325
|
+
* supported.
|
|
326
|
+
*/
|
|
327
|
+
withOwnTransports(transports) {
|
|
328
|
+
this.config.own_transports = transports.map((t) => ({
|
|
329
|
+
uri: t.uri,
|
|
330
|
+
protocol: protocolDiscriminant(t.protocol),
|
|
331
|
+
}));
|
|
332
|
+
return this;
|
|
333
|
+
}
|
|
296
334
|
/** Default: 3. */
|
|
297
335
|
withThreshold(threshold) {
|
|
298
336
|
this.config.threshold = threshold;
|
|
@@ -314,11 +352,28 @@ class DeRecProtocolBuilder {
|
|
|
314
352
|
this.config.timeouts = { ...timeouts };
|
|
315
353
|
return this;
|
|
316
354
|
}
|
|
317
|
-
/**
|
|
355
|
+
/**
|
|
356
|
+
* @deprecated Use {@link withUnsafeConnection}, which names both gated
|
|
357
|
+
* schemes. Removed at 0.0.5. Default: false.
|
|
358
|
+
*/
|
|
318
359
|
withUnsafeHttp(allow) {
|
|
319
360
|
this.config.unsafe_http = allow;
|
|
320
361
|
return this;
|
|
321
362
|
}
|
|
363
|
+
/**
|
|
364
|
+
* Accept plaintext `http://` and `grpc://` transport endpoints.
|
|
365
|
+
* **Development only.** Default: false. Supersedes
|
|
366
|
+
* {@link withUnsafeHttp}, which names only the HTTP scheme.
|
|
367
|
+
*
|
|
368
|
+
* Either flag alone is honored. Setting both to disagreeing values fails
|
|
369
|
+
* construction with the error code `CONFLICTING_PLAINTEXT_OPT_IN` rather
|
|
370
|
+
* than resolving silently, because precedence would hand the decision to
|
|
371
|
+
* the flag being removed.
|
|
372
|
+
*/
|
|
373
|
+
withUnsafeConnection(allow) {
|
|
374
|
+
this.config.unsafe_connection = allow;
|
|
375
|
+
return this;
|
|
376
|
+
}
|
|
322
377
|
/**
|
|
323
378
|
* Default: empty. `derec_protocol_new`'s own `communication_info` argument
|
|
324
379
|
* is a pre-encoded `CommunicationInfo` protobuf message, and this SDK has
|
|
@@ -382,6 +437,32 @@ class DeRecProtocolBuilder {
|
|
|
382
437
|
this.config.replica_id = BigInt(replicaId).toString();
|
|
383
438
|
return this;
|
|
384
439
|
}
|
|
440
|
+
/**
|
|
441
|
+
* Declare the bounds this node advertises during pair negotiation.
|
|
442
|
+
*
|
|
443
|
+
* Embedded in outbound `PairRequest`/`PairResponse` envelopes and checked
|
|
444
|
+
* against the peer's range on inbound ones: a range that fails to
|
|
445
|
+
* intersect rejects the pairing. Every bound is optional and defaults to
|
|
446
|
+
* `0`, which the protocol reads as "no constraint on this dimension".
|
|
447
|
+
*
|
|
448
|
+
* Default: unset — no constraints advertised, every peer range accepted.
|
|
449
|
+
*/
|
|
450
|
+
withParameterRange(range) {
|
|
451
|
+
const n = (v) => Number(v ?? 0n);
|
|
452
|
+
this.config.parameter_range = {
|
|
453
|
+
min_share_size: n(range.min_share_size),
|
|
454
|
+
max_share_size: n(range.max_share_size),
|
|
455
|
+
min_time_between_verifications: n(range.min_time_between_verifications),
|
|
456
|
+
max_time_between_verifications: n(range.max_time_between_verifications),
|
|
457
|
+
min_time_between_share_updates: n(range.min_time_between_share_updates),
|
|
458
|
+
max_time_between_share_updates: n(range.max_time_between_share_updates),
|
|
459
|
+
min_unresponsive_deletion_timeout: n(range.min_unresponsive_deletion_timeout),
|
|
460
|
+
max_unresponsive_deletion_timeout: n(range.max_unresponsive_deletion_timeout),
|
|
461
|
+
min_unresponsive_deactivation_timeout: n(range.min_unresponsive_deactivation_timeout),
|
|
462
|
+
max_unresponsive_deactivation_timeout: n(range.max_unresponsive_deactivation_timeout),
|
|
463
|
+
};
|
|
464
|
+
return this;
|
|
465
|
+
}
|
|
385
466
|
build() {
|
|
386
467
|
const config = {
|
|
387
468
|
secret_id: this.secretIdValue.toString(),
|
|
@@ -454,10 +535,40 @@ class DeRecProtocol {
|
|
|
454
535
|
setCommunicationInfo(info) {
|
|
455
536
|
return this.host.setCommunicationInfo((0, codec_1.jsonToBytes)(info));
|
|
456
537
|
}
|
|
457
|
-
/**
|
|
538
|
+
/**
|
|
539
|
+
* Replace this node's endpoint for one protocol, leaving the others
|
|
540
|
+
* alone. A node serves at most one endpoint per protocol, so the
|
|
541
|
+
* `(uri, protocol)` pair identifies the entry it replaces; an entry for a
|
|
542
|
+
* protocol not yet served is appended, and a replaced one keeps its
|
|
543
|
+
* position in the preference order.
|
|
544
|
+
*
|
|
545
|
+
* Returns a `Promise` for the same reason {@link setCommunicationInfo} does.
|
|
546
|
+
*
|
|
547
|
+
* @deprecated Use {@link setOwnTransports}, which takes the whole
|
|
548
|
+
* preference list and is the only way to change which protocols this node
|
|
549
|
+
* serves, or their order. Removed at 0.0.5.
|
|
550
|
+
*/
|
|
458
551
|
setOwnTransport(uri, protocol) {
|
|
459
552
|
return this.host.setOwnTransport(uri, protocolDiscriminant(protocol));
|
|
460
553
|
}
|
|
554
|
+
/**
|
|
555
|
+
* Replaces every endpoint this node advertises, in preference order —
|
|
556
|
+
* the runtime counterpart to `withOwnTransports`, and the only way to
|
|
557
|
+
* change a multi-endpoint node's set ({@link setOwnTransport} collapses
|
|
558
|
+
* it to the one endpoint it is given).
|
|
559
|
+
*
|
|
560
|
+
* Every entry is validated before any is stored, so a malformed URI
|
|
561
|
+
* leaves the previous set intact. An empty array is rejected.
|
|
562
|
+
*
|
|
563
|
+
* Returns a `Promise` for the same reason {@link setCommunicationInfo} does.
|
|
564
|
+
*/
|
|
565
|
+
setOwnTransports(transports) {
|
|
566
|
+
const wire = transports.map(({ uri, protocol }) => ({
|
|
567
|
+
uri,
|
|
568
|
+
protocol: protocolDiscriminant(protocol),
|
|
569
|
+
}));
|
|
570
|
+
return this.host.setOwnTransports((0, codec_1.jsonToBytes)(wire));
|
|
571
|
+
}
|
|
461
572
|
/**
|
|
462
573
|
* Decodes the `contact_wire_bytes` `derec_protocol_create_contact`
|
|
463
574
|
* produces into a typed `ContactMessage`, so an application can read the
|