@derec-alliance/react-native 0.0.1 → 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 +30 -4
- 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 +147 -27
- package/ios/DeRecFFI.xcframework/Info.plist +5 -5
- package/ios/DeRecFFI.xcframework/ios-arm64/Headers/derec_ffi.h +147 -27
- package/ios/DeRecFFI.xcframework/ios-arm64/libderec_library.a +0 -0
- package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/Headers/derec_ffi.h +147 -27
- package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/libderec_library.a +0 -0
- package/lib/errors.d.ts +2 -2
- package/lib/errors.js +2 -2
- package/lib/messages.d.ts +2 -2
- package/lib/messages.js +2 -2
- package/lib/primitives.d.ts +9 -9
- package/lib/primitives.js +63 -13
- package/lib/protocol.d.ts +91 -12
- package/lib/protocol.js +125 -14
- package/lib/types.d.ts +328 -30
- package/lib/types.js +109 -2
- package/package.json +3 -16
- package/src/errors.ts +2 -2
- package/src/messages.ts +2 -2
- package/src/primitives.ts +77 -21
- package/src/protocol.ts +144 -19
- package/src/types.ts +394 -36
|
@@ -26,23 +26,48 @@
|
|
|
26
26
|
*/
|
|
27
27
|
#define SHARE_ALGORITHM_REPLICA_SECRET 1
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Schema version stamped onto every channel record this build writes.
|
|
31
|
+
*
|
|
32
|
+
* Applications persist [`HelperChannel`] and [`ReplicaMember`] as opaque
|
|
33
|
+
* blobs whose shape the *library* owns, so a field change here is a
|
|
34
|
+
* migration the application cannot write without knowing a schema it does
|
|
35
|
+
* not define. The marker is what lets the library do that migration itself:
|
|
36
|
+
* a reader can tell a record apart by the shape it was written in rather
|
|
37
|
+
* than by guessing from which fields happen to be present.
|
|
38
|
+
*
|
|
39
|
+
* A record written before the marker existed deserializes as version 0 and
|
|
40
|
+
* is upgraded on read. A record claiming a version *newer* than this build
|
|
41
|
+
* understands is refused, because the alternative is silently dropping
|
|
42
|
+
* fields this build cannot see and writing the truncated result back.
|
|
43
|
+
*
|
|
44
|
+
* The value tracks the release that last changed the shape, not the release
|
|
45
|
+
* that is current: it moved to 3 when `transport` became `transports`, and
|
|
46
|
+
* stays there until the next shape change.
|
|
47
|
+
*
|
|
48
|
+
* Declared unconditionally, unlike the serde impls that stamp it: the SDK
|
|
49
|
+
* bridges mirror this number in their own encoders, and a constant they must
|
|
50
|
+
* agree with should not appear and disappear with a feature flag.
|
|
51
|
+
*/
|
|
52
|
+
#define CHANNEL_RECORD_SCHEMA_VERSION 3
|
|
53
|
+
|
|
29
54
|
/**
|
|
30
55
|
* Latest encoding major version, used for all new encodes. Bump only on a
|
|
31
56
|
* breaking format change, adding the matching `vN` module and match arm.
|
|
32
57
|
*/
|
|
33
|
-
#define LATEST
|
|
58
|
+
#define LATEST 3
|
|
34
59
|
|
|
35
60
|
/**
|
|
36
61
|
* Minimum number of shares required to reconstruct the secret, absent an
|
|
37
|
-
* explicit [`DeRecProtocolBuilder::with_threshold`] call. This is the sole
|
|
38
|
-
* definition of the value — [`DeRecProtocolBuilder::new`] and the FFI
|
|
62
|
+
* explicit [`DeRecProtocolBuilder::with_threshold`](crate::protocol::DeRecProtocolBuilder::with_threshold) call. This is the sole
|
|
63
|
+
* definition of the value — [`DeRecProtocolBuilder::new`](crate::protocol::DeRecProtocolBuilder::new) and the FFI
|
|
39
64
|
* config's serde default both read it rather than each hardcoding `3`.
|
|
40
65
|
*/
|
|
41
66
|
#define DEFAULT_THRESHOLD 3
|
|
42
67
|
|
|
43
68
|
/**
|
|
44
69
|
* Number of recent share versions each helper retains, absent an explicit
|
|
45
|
-
* [`DeRecProtocolBuilder::with_keep_versions_count`] call. Sole definition
|
|
70
|
+
* [`DeRecProtocolBuilder::with_keep_versions_count`](crate::protocol::DeRecProtocolBuilder::with_keep_versions_count) call. Sole definition
|
|
46
71
|
* of the value; see [`DEFAULT_THRESHOLD`].
|
|
47
72
|
*/
|
|
48
73
|
#define DEFAULT_KEEP_VERSIONS_COUNT 3
|
|
@@ -263,13 +288,32 @@
|
|
|
263
288
|
*/
|
|
264
289
|
#define DEREC_CODE_TRANSPORT_INVALID 120
|
|
265
290
|
|
|
291
|
+
/**
|
|
292
|
+
* No transport is shared with the peer — its offered endpoints and this
|
|
293
|
+
* application's served endpoints intersect to nothing. Always a local,
|
|
294
|
+
* terminal error: push-only delivery means an unreachable peer also
|
|
295
|
+
* cannot be told. `DEREC_CATEGORY_INVALID_INPUT`.
|
|
296
|
+
*/
|
|
297
|
+
#define DEREC_CODE_NO_USABLE_ENDPOINT 121
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Both plaintext opt-in flags were set explicitly and disagree: the
|
|
301
|
+
* deprecated `unsafe_http` says one thing and `unsafe_connection` the
|
|
302
|
+
* other. Raised at protocol construction rather than resolved by
|
|
303
|
+
* precedence, because the flag precedence would favour is the one being
|
|
304
|
+
* removed, and a configuration layer that emits every field
|
|
305
|
+
* unconditionally would otherwise let a defaulted value silently beat a
|
|
306
|
+
* deliberate one. Set only `unsafe_connection`.
|
|
307
|
+
* `DEREC_CATEGORY_INVALID_INPUT`.
|
|
308
|
+
*/
|
|
309
|
+
#define DEREC_CODE_CONFLICTING_PLAINTEXT_OPT_IN 122
|
|
310
|
+
|
|
266
311
|
/**
|
|
267
312
|
* Discriminants selecting which message [`derec_decode_message_json`] and
|
|
268
313
|
* [`derec_encode_message_json`] operate on.
|
|
269
314
|
*
|
|
270
|
-
* Mirrored in
|
|
271
|
-
*
|
|
272
|
-
* unhandled value.
|
|
315
|
+
* Mirrored in the shared enum fixture, which every SDK asserts against, so a
|
|
316
|
+
* message added here cannot reach a binding as a silently unhandled value.
|
|
273
317
|
*/
|
|
274
318
|
#define DEREC_MESSAGE_KIND_PAIR_REQUEST 0
|
|
275
319
|
|
|
@@ -302,7 +346,7 @@
|
|
|
302
346
|
/**
|
|
303
347
|
* Not a standalone message on the wire, but it crosses this FFI on its own
|
|
304
348
|
* as the `transport_protocol` argument of `create_contact_message` and the
|
|
305
|
-
* `
|
|
349
|
+
* `peer_transports` result of `produce_pair_response_message`.
|
|
306
350
|
*/
|
|
307
351
|
#define DEREC_MESSAGE_KIND_TRANSPORT_PROTOCOL 14
|
|
308
352
|
|
|
@@ -346,13 +390,13 @@
|
|
|
346
390
|
* Replica catch-up. Takes no parameters: the group and this device's own
|
|
347
391
|
* version are both read from the stores.
|
|
348
392
|
*/
|
|
349
|
-
#define
|
|
393
|
+
#define FLOW_KIND_REPLICA_DISCOVERY 7
|
|
350
394
|
|
|
351
395
|
/**
|
|
352
396
|
* Remove a member from the replica group. Params:
|
|
353
397
|
* `{ "replica_id": "<decimal>", "memo": "<optional>" }`.
|
|
354
398
|
*/
|
|
355
|
-
#define
|
|
399
|
+
#define FLOW_KIND_UNPAIR_REPLICA 8
|
|
356
400
|
|
|
357
401
|
/**
|
|
358
402
|
* Opaque handle returned by [`derec_protocol_new`] and consumed by
|
|
@@ -553,7 +597,7 @@ typedef struct ExtractPairRequestResult {
|
|
|
553
597
|
typedef struct ProducePairResponseMessageResult {
|
|
554
598
|
struct DeRecError error;
|
|
555
599
|
struct DeRecBuffer response_wire_bytes;
|
|
556
|
-
struct DeRecBuffer
|
|
600
|
+
struct DeRecBuffer peer_transports;
|
|
557
601
|
struct DeRecBuffer shared_key;
|
|
558
602
|
/**
|
|
559
603
|
* Post-handshake rekey channel id the responder is committing to.
|
|
@@ -695,6 +739,17 @@ typedef struct DeRecProtocolNewResult {
|
|
|
695
739
|
* [`crate::protocol::types::HelperChannel`] and
|
|
696
740
|
* [`crate::protocol::types::ReplicaMember`] respectively.
|
|
697
741
|
*
|
|
742
|
+
* Both listing callbacks receive a `filter` buffer holding a JSON-encoded
|
|
743
|
+
* [`crate::protocol::types::HelperFilter`] or
|
|
744
|
+
* [`crate::protocol::types::ReplicaFilter`] — an object with `ids`, `status`,
|
|
745
|
+
* `role` and `exclude`, where an empty array or a null `role` restricts
|
|
746
|
+
* nothing. A backend should apply it in its query rather than by listing
|
|
747
|
+
* everything and discarding rows; see
|
|
748
|
+
* [`crate::protocol::types::ChannelFilter`]. The library re-applies it to
|
|
749
|
+
* whatever comes back, so ignoring it is slow rather than wrong — but
|
|
750
|
+
* returning fewer rows than it selects is wrong, and undetectable. The buffer is owned
|
|
751
|
+
* by the caller and valid only for the duration of the call.
|
|
752
|
+
*
|
|
698
753
|
* The order `list_replicas` returns is significant in exactly one situation —
|
|
699
754
|
* it selects the successor when the group's source is removed. See
|
|
700
755
|
* [`crate::protocol::DeRecChannelStore::replicas`] for the full contract.
|
|
@@ -718,8 +773,18 @@ typedef struct ChannelStoreCallbacks {
|
|
|
718
773
|
uint64_t channel_id,
|
|
719
774
|
uint64_t replica_id,
|
|
720
775
|
uint32_t *out_existed);
|
|
721
|
-
int32_t (*list_helpers)(void *user_data,
|
|
722
|
-
|
|
776
|
+
int32_t (*list_helpers)(void *user_data,
|
|
777
|
+
uint64_t secret_id,
|
|
778
|
+
const uint8_t *filter,
|
|
779
|
+
size_t filter_len,
|
|
780
|
+
uint8_t **out_ptr,
|
|
781
|
+
size_t *out_len);
|
|
782
|
+
int32_t (*list_replicas)(void *user_data,
|
|
783
|
+
uint64_t secret_id,
|
|
784
|
+
const uint8_t *filter,
|
|
785
|
+
size_t filter_len,
|
|
786
|
+
uint8_t **out_ptr,
|
|
787
|
+
size_t *out_len);
|
|
723
788
|
int32_t (*link_channel)(void *user_data, uint64_t secret_id, uint64_t a, uint64_t b);
|
|
724
789
|
int32_t (*linked_channels)(void *user_data,
|
|
725
790
|
uint64_t secret_id,
|
|
@@ -862,10 +927,24 @@ typedef struct StateStoreCallbacks {
|
|
|
862
927
|
*/
|
|
863
928
|
typedef struct TransportCallbacks {
|
|
864
929
|
void *user_data;
|
|
930
|
+
/**
|
|
931
|
+
* Deliver `bytes` to a peer reachable at any of `endpoints`.
|
|
932
|
+
*
|
|
933
|
+
* `endpoints` is a length-delimited sequence of encoded
|
|
934
|
+
* `TransportProtocol` messages — each entry preceded by its protobuf
|
|
935
|
+
* varint byte length, the same framing protobuf uses for a repeated
|
|
936
|
+
* embedded message field. They are the endpoints that peer advertised,
|
|
937
|
+
* in the order it offered them, already filtered to those the library
|
|
938
|
+
* will record.
|
|
939
|
+
*
|
|
940
|
+
* The library does not rank them. Which endpoint to dial, and whether
|
|
941
|
+
* to fall back to another when one is unreachable, is the
|
|
942
|
+
* implementation's choice. Return `0` once the message has reached any
|
|
943
|
+
* one of them; non-zero only when it reached none.
|
|
944
|
+
*/
|
|
865
945
|
int32_t (*send)(void *user_data,
|
|
866
|
-
const uint8_t *
|
|
867
|
-
size_t
|
|
868
|
-
int32_t protocol,
|
|
946
|
+
const uint8_t *endpoints_ptr,
|
|
947
|
+
size_t endpoints_len,
|
|
869
948
|
const uint8_t *bytes,
|
|
870
949
|
size_t len);
|
|
871
950
|
} TransportCallbacks;
|
|
@@ -1288,8 +1367,8 @@ struct DeRecMessageJsonResult derec_encode_message_json(int32_t kind,
|
|
|
1288
1367
|
*/
|
|
1289
1368
|
struct CreateContactMessageResult create_contact_message(uint64_t channel_id,
|
|
1290
1369
|
int32_t contact_mode,
|
|
1291
|
-
const uint8_t *
|
|
1292
|
-
size_t
|
|
1370
|
+
const uint8_t *transport_protocols_ptr,
|
|
1371
|
+
size_t transport_protocols_len,
|
|
1293
1372
|
uint32_t has_nonce,
|
|
1294
1373
|
uint64_t nonce);
|
|
1295
1374
|
|
|
@@ -1363,8 +1442,8 @@ struct DecodeContactMessageResult decode_contact_message(const uint8_t *contact_
|
|
|
1363
1442
|
* Non-null input pointers must point to the corresponding readable byte ranges.
|
|
1364
1443
|
*/
|
|
1365
1444
|
struct ProducePairRequestMessageResult produce_pair_request_message(int32_t sender_kind,
|
|
1366
|
-
const uint8_t *
|
|
1367
|
-
size_t
|
|
1445
|
+
const uint8_t *transport_protocols_ptr,
|
|
1446
|
+
size_t transport_protocols_len,
|
|
1368
1447
|
const uint8_t *contact_message_ptr,
|
|
1369
1448
|
size_t contact_message_len,
|
|
1370
1449
|
const uint8_t *communication_info_ptr,
|
|
@@ -1403,7 +1482,8 @@ struct ProducePairResponseMessageResult produce_pair_response_message(uint64_t c
|
|
|
1403
1482
|
const uint8_t *communication_info_ptr,
|
|
1404
1483
|
size_t communication_info_len,
|
|
1405
1484
|
const uint8_t *parameter_range_ptr,
|
|
1406
|
-
size_t parameter_range_len
|
|
1485
|
+
size_t parameter_range_len,
|
|
1486
|
+
uint32_t unsafe_connection);
|
|
1407
1487
|
|
|
1408
1488
|
/**
|
|
1409
1489
|
* # Safety
|
|
@@ -1440,8 +1520,8 @@ struct ProcessPairResponseMessageResult process_pair_response_message(const uint
|
|
|
1440
1520
|
*
|
|
1441
1521
|
* Non-null input pointers must point to the corresponding readable byte ranges.
|
|
1442
1522
|
*/
|
|
1443
|
-
struct ProducePrePairRequestMessageResult produce_pre_pair_request_message(const uint8_t *
|
|
1444
|
-
size_t
|
|
1523
|
+
struct ProducePrePairRequestMessageResult produce_pre_pair_request_message(const uint8_t *transport_protocols_ptr,
|
|
1524
|
+
size_t transport_protocols_len,
|
|
1445
1525
|
const uint8_t *contact_message_ptr,
|
|
1446
1526
|
size_t contact_message_len);
|
|
1447
1527
|
|
|
@@ -1528,6 +1608,7 @@ struct ProcessPrePairResponseMessageResult process_pre_pair_response_message(con
|
|
|
1528
1608
|
* "secret_id": "12345678901234567890",
|
|
1529
1609
|
* "own_transport_uri": "https://example.com/derec",
|
|
1530
1610
|
* "own_transport_protocol": 1,
|
|
1611
|
+
* "own_transports": [{ "uri": "https://example.com/derec", "protocol": 0 }],
|
|
1531
1612
|
* "threshold": 3,
|
|
1532
1613
|
* "keep_versions_count": 2,
|
|
1533
1614
|
* "timeout_in_secs": 30,
|
|
@@ -1554,6 +1635,11 @@ struct ProcessPrePairResponseMessageResult process_pre_pair_response_message(con
|
|
|
1554
1635
|
* `derec_protocol_set_own_transport` must be called before pairing
|
|
1555
1636
|
* in that case.
|
|
1556
1637
|
* - `own_transport_protocol`: [`derec_proto::Protocol`] discriminant.
|
|
1638
|
+
* - `own_transports`: every endpoint this application serves, in
|
|
1639
|
+
* preference order — the order decides which of a peer's offered
|
|
1640
|
+
* endpoints is used. Optional; when non-empty it takes precedence over
|
|
1641
|
+
* `own_transport_uri` / `own_transport_protocol`, which stay fully
|
|
1642
|
+
* supported for callers that serve a single transport.
|
|
1557
1643
|
* - `threshold` / `keep_versions_count`: optional; omitted means
|
|
1558
1644
|
* [`crate::protocol::DEFAULT_THRESHOLD`] /
|
|
1559
1645
|
* [`crate::protocol::DEFAULT_KEEP_VERSIONS_COUNT`].
|
|
@@ -1635,10 +1721,17 @@ struct DeRecError derec_protocol_set_communication_info(struct DeRecProtocolHand
|
|
|
1635
1721
|
size_t info_json_len);
|
|
1636
1722
|
|
|
1637
1723
|
/**
|
|
1638
|
-
* Replace this node's
|
|
1639
|
-
*
|
|
1640
|
-
*
|
|
1641
|
-
*
|
|
1724
|
+
* Replace this node's endpoint **for one protocol**, leaving the others
|
|
1725
|
+
* alone. A node serves at most one endpoint per protocol, so the `(uri,
|
|
1726
|
+
* protocol)` pair identifies the entry it replaces; an entry for a protocol
|
|
1727
|
+
* not yet served is appended, and a replaced one keeps its position in the
|
|
1728
|
+
* preference order. See
|
|
1729
|
+
* [`crate::protocol::DeRecProtocol::set_own_transport`] for the changeover
|
|
1730
|
+
* discipline (keep the old endpoint up during the transition).
|
|
1731
|
+
*
|
|
1732
|
+
* Superseded by [`derec_protocol_set_own_transports`], which takes the
|
|
1733
|
+
* whole preference list and is the only way to change *which* protocols
|
|
1734
|
+
* this node serves, or their order.
|
|
1642
1735
|
*
|
|
1643
1736
|
* # Safety
|
|
1644
1737
|
*
|
|
@@ -1651,11 +1744,38 @@ struct DeRecError derec_protocol_set_communication_info(struct DeRecProtocolHand
|
|
|
1651
1744
|
* from different threads are safe: the handle's internal mutex
|
|
1652
1745
|
* serializes them.
|
|
1653
1746
|
*/
|
|
1747
|
+
__attribute__((deprecated("use derec_protocol_set_own_transports, which takes the whole preference list; removed at 0.0.5")))
|
|
1654
1748
|
struct DeRecError derec_protocol_set_own_transport(struct DeRecProtocolHandle *handle,
|
|
1655
1749
|
const uint8_t *uri_ptr,
|
|
1656
1750
|
size_t uri_len,
|
|
1657
1751
|
int32_t protocol);
|
|
1658
1752
|
|
|
1753
|
+
/**
|
|
1754
|
+
* Replace every endpoint this node advertises, in preference order.
|
|
1755
|
+
*
|
|
1756
|
+
* The runtime counterpart to the `own_transports` array accepted by
|
|
1757
|
+
* [`super::derec_protocol_new`], and the way to change the whole set:
|
|
1758
|
+
* `derec_protocol_set_own_transport` replaces only the entry for the
|
|
1759
|
+
* protocol its URI names. A device serves at most one endpoint per
|
|
1760
|
+
* protocol, so this list is a preference order over distinct protocols and
|
|
1761
|
+
* two entries of the same protocol are rejected. Body is the same JSON
|
|
1762
|
+
* shape that config array uses — `[{"uri": "...", "protocol": 0}, ...]`.
|
|
1763
|
+
*
|
|
1764
|
+
* Every entry is validated before any is stored, so a malformed URI
|
|
1765
|
+
* leaves the previous set intact rather than half-applied.
|
|
1766
|
+
*
|
|
1767
|
+
* # Safety
|
|
1768
|
+
*
|
|
1769
|
+
* `handle` must be a valid pointer returned by
|
|
1770
|
+
* [`super::derec_protocol_new`]. `json_ptr`/`json_len` must describe a
|
|
1771
|
+
* readable byte range. Concurrent calls on the same handle from
|
|
1772
|
+
* different threads are safe: the handle's internal mutex serializes
|
|
1773
|
+
* them.
|
|
1774
|
+
*/
|
|
1775
|
+
struct DeRecError derec_protocol_set_own_transports(struct DeRecProtocolHandle *handle,
|
|
1776
|
+
const uint8_t *json_ptr,
|
|
1777
|
+
size_t json_len);
|
|
1778
|
+
|
|
1659
1779
|
/**
|
|
1660
1780
|
* Remove `Pending` channels older than `older_than_secs`. See
|
|
1661
1781
|
* [`crate::protocol::DeRecProtocol::remove_expired_channels`] for the
|
|
Binary file
|
package/lib/errors.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Every category name `derec_error_category_name` can return, and no others.
|
|
3
3
|
*
|
|
4
|
-
* This is the authoritative list for this SDK,
|
|
5
|
-
*
|
|
4
|
+
* This is the authoritative list for this SDK, held to the Rust enum by a
|
|
5
|
+
* test against the shared enum fixture so the two cannot drift.
|
|
6
6
|
* It deliberately differs from `@derec-alliance/nodejs`'s union, which was
|
|
7
7
|
* the original source of this file: that union lists `"wasm"`, a category no
|
|
8
8
|
* C-ABI binding can ever emit, and omits `"ok"`, `"ffi"` and `"state_store"`,
|
package/lib/errors.js
CHANGED
|
@@ -6,8 +6,8 @@ exports.DEREC_ERROR_CATEGORIES = void 0;
|
|
|
6
6
|
/**
|
|
7
7
|
* Every category name `derec_error_category_name` can return, and no others.
|
|
8
8
|
*
|
|
9
|
-
* This is the authoritative list for this SDK,
|
|
10
|
-
*
|
|
9
|
+
* This is the authoritative list for this SDK, held to the Rust enum by a
|
|
10
|
+
* test against the shared enum fixture so the two cannot drift.
|
|
11
11
|
* It deliberately differs from `@derec-alliance/nodejs`'s union, which was
|
|
12
12
|
* the original source of this file: that union lists `"wasm"`, a category no
|
|
13
13
|
* C-ABI binding can ever emit, and omits `"ok"`, `"ffi"` and `"state_store"`,
|
package/lib/messages.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Selects which message the JSON codec operates on.
|
|
3
3
|
*
|
|
4
|
-
* Mirrors
|
|
5
|
-
*
|
|
4
|
+
* Mirrors the crate's `MessageKind`, which the shared enum fixture holds
|
|
5
|
+
* both sides to — so a message
|
|
6
6
|
* added in Rust cannot reach this SDK as a silently unhandled value.
|
|
7
7
|
*/
|
|
8
8
|
export declare enum MessageKind {
|
package/lib/messages.js
CHANGED
|
@@ -42,8 +42,8 @@ const native_1 = require("./native");
|
|
|
42
42
|
/**
|
|
43
43
|
* Selects which message the JSON codec operates on.
|
|
44
44
|
*
|
|
45
|
-
* Mirrors
|
|
46
|
-
*
|
|
45
|
+
* Mirrors the crate's `MessageKind`, which the shared enum fixture holds
|
|
46
|
+
* both sides to — so a message
|
|
47
47
|
* added in Rust cannot reach this SDK as a silently unhandled value.
|
|
48
48
|
*/
|
|
49
49
|
var MessageKind;
|
package/lib/primitives.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ declare function decodeContact(wire: Uint8Array | ArrayBuffer): ContactMessage;
|
|
|
12
12
|
export declare const primitives: {
|
|
13
13
|
discovery: {
|
|
14
14
|
request: {
|
|
15
|
-
produce(channel_id: bigint, shared_key: Uint8Array, reply_to?: TransportProtocol
|
|
15
|
+
produce(channel_id: bigint, shared_key: Uint8Array, reply_to?: TransportProtocol[]): ProduceResult;
|
|
16
16
|
extract(envelope_bytes: Uint8Array, shared_key: Uint8Array): {
|
|
17
17
|
request: GetSecretIdsVersionsRequestMessage;
|
|
18
18
|
};
|
|
@@ -27,22 +27,22 @@ export declare const primitives: {
|
|
|
27
27
|
};
|
|
28
28
|
pairing: {
|
|
29
29
|
request: {
|
|
30
|
-
create_contact(channel_id: bigint, contact_mode: ContactMode | number,
|
|
30
|
+
create_contact(channel_id: bigint, contact_mode: ContactMode | number, transport_protocols: TransportProtocol[]): CreateContactResult;
|
|
31
31
|
/** Proto-encodes a `ContactMessage`. Rejects a contact that violates the
|
|
32
32
|
* mode/field invariant rather than serializing it. */
|
|
33
33
|
encode_contact: typeof encodeContact;
|
|
34
34
|
/** Decodes proto `ContactMessage` bytes. Rejects a contact that violates
|
|
35
35
|
* the mode/field invariant rather than returning it. */
|
|
36
36
|
decode_contact: typeof decodeContact;
|
|
37
|
-
produce(kind: SenderKind,
|
|
37
|
+
produce(kind: SenderKind, transport_protocols: TransportProtocol[], contact_message: ContactMessage, communication_info: CommunicationInfo | null, parameter_range: ParameterRange | null): PairingRequestProduceResult;
|
|
38
38
|
extract(envelope_bytes: Uint8Array, secret_key: Uint8Array): {
|
|
39
39
|
request: PairRequestMessage;
|
|
40
40
|
};
|
|
41
|
-
produce_pre_pair(
|
|
41
|
+
produce_pre_pair(own_transports: TransportProtocol[], contact_message: ContactMessage): ProducePrePairResult;
|
|
42
42
|
extract_pre_pair(envelope_bytes: Uint8Array): PrePairRequestExtractResult;
|
|
43
43
|
};
|
|
44
44
|
response: {
|
|
45
|
-
produce(channel_id: bigint, request: PairRequestMessage, secret_key: Uint8Array, communication_info: CommunicationInfo | null, parameter_range: ParameterRange | null): PairingResponseProduceResult;
|
|
45
|
+
produce(channel_id: bigint, request: PairRequestMessage, secret_key: Uint8Array, communication_info: CommunicationInfo | null, parameter_range: ParameterRange | null, unsafe_connection?: boolean): PairingResponseProduceResult;
|
|
46
46
|
extract(envelope_bytes: Uint8Array, secret_key: Uint8Array): {
|
|
47
47
|
response: PairResponseMessage;
|
|
48
48
|
};
|
|
@@ -54,7 +54,7 @@ export declare const primitives: {
|
|
|
54
54
|
};
|
|
55
55
|
recovery: {
|
|
56
56
|
request: {
|
|
57
|
-
produce(channel_id: bigint, secret_id: bigint, version: number, shared_key: Uint8Array, reply_to?: TransportProtocol
|
|
57
|
+
produce(channel_id: bigint, secret_id: bigint, version: number, shared_key: Uint8Array, reply_to?: TransportProtocol[]): ProduceResult;
|
|
58
58
|
extract(envelope_bytes: Uint8Array, shared_key: Uint8Array): {
|
|
59
59
|
request: GetShareRequestMessage;
|
|
60
60
|
};
|
|
@@ -70,7 +70,7 @@ export declare const primitives: {
|
|
|
70
70
|
sharing: {
|
|
71
71
|
request: {
|
|
72
72
|
split(channels: bigint[], secret_id: bigint, version: number, secret_data: Uint8Array, threshold: number): SplitResult;
|
|
73
|
-
produce(channel_id: bigint, version: number, secret_id: bigint, committed_share: CommittedDeRecShare, keep_list: number[], description: string, shared_key: Uint8Array, reply_to?: TransportProtocol
|
|
73
|
+
produce(channel_id: bigint, version: number, secret_id: bigint, committed_share: CommittedDeRecShare, keep_list: number[], description: string, shared_key: Uint8Array, reply_to?: TransportProtocol[]): ProduceResult;
|
|
74
74
|
extract(envelope_bytes: Uint8Array, shared_key: Uint8Array): {
|
|
75
75
|
request: StoreShareRequestMessage;
|
|
76
76
|
};
|
|
@@ -85,7 +85,7 @@ export declare const primitives: {
|
|
|
85
85
|
};
|
|
86
86
|
unpairing: {
|
|
87
87
|
request: {
|
|
88
|
-
produce(channel_id: bigint, memo: string, shared_key: Uint8Array, reply_to?: TransportProtocol
|
|
88
|
+
produce(channel_id: bigint, memo: string, shared_key: Uint8Array, reply_to?: TransportProtocol[]): ProduceResult;
|
|
89
89
|
extract(envelope_bytes: Uint8Array, shared_key: Uint8Array): {
|
|
90
90
|
request: UnpairRequestMessage;
|
|
91
91
|
};
|
|
@@ -109,7 +109,7 @@ export declare const primitives: {
|
|
|
109
109
|
};
|
|
110
110
|
verification: {
|
|
111
111
|
request: {
|
|
112
|
-
produce(channel_id: bigint, secret_id: bigint, version: number, shared_key: Uint8Array, reply_to?: TransportProtocol
|
|
112
|
+
produce(channel_id: bigint, secret_id: bigint, version: number, shared_key: Uint8Array, reply_to?: TransportProtocol[]): ProduceResult;
|
|
113
113
|
extract(envelope_bytes: Uint8Array, shared_key: Uint8Array): {
|
|
114
114
|
request: VerifyShareRequestMessage;
|
|
115
115
|
};
|
package/lib/primitives.js
CHANGED
|
@@ -28,11 +28,11 @@ function call(name, ...args) {
|
|
|
28
28
|
function bytes(value) {
|
|
29
29
|
return new Uint8Array(value);
|
|
30
30
|
}
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
31
|
+
/** An omitted or empty list means "no override" for every reply-to argument;
|
|
32
|
+
* the C ABI reads a zero-length buffer as absent, and the responder then
|
|
33
|
+
* routes to the endpoints already recorded for the channel. */
|
|
34
34
|
function replyTo(value) {
|
|
35
|
-
return
|
|
35
|
+
return value && value.length > 0 ? encodeTransportList(value) : new Uint8Array(0);
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
38
|
* `ContactMessage` keeps its own dedicated codec rather than going through
|
|
@@ -79,14 +79,64 @@ const discovery = {
|
|
|
79
79
|
},
|
|
80
80
|
},
|
|
81
81
|
};
|
|
82
|
+
/**
|
|
83
|
+
* Frames a preference-ordered endpoint list for the native seam: each entry
|
|
84
|
+
* preceded by its protobuf varint byte length. Order is preserved exactly.
|
|
85
|
+
*/
|
|
86
|
+
function encodeTransportList(transports) {
|
|
87
|
+
const entries = transports.map((t) => new Uint8Array((0, messages_1.encodeMessage)(messages_1.MessageKind.TransportProtocol, t)));
|
|
88
|
+
const out = [];
|
|
89
|
+
for (const entry of entries) {
|
|
90
|
+
let len = entry.length;
|
|
91
|
+
do {
|
|
92
|
+
let b = len & 0x7f;
|
|
93
|
+
len >>>= 7;
|
|
94
|
+
if (len !== 0)
|
|
95
|
+
b |= 0x80;
|
|
96
|
+
out.push(b);
|
|
97
|
+
} while (len !== 0);
|
|
98
|
+
out.push(...entry);
|
|
99
|
+
}
|
|
100
|
+
return new Uint8Array(out);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Reads the framing `encodeTransportList` writes. Order is the peer's and is
|
|
104
|
+
* preserved exactly — the library filters a peer's endpoints but never ranks
|
|
105
|
+
* them, so this order is the peer's own preference, not a recommendation.
|
|
106
|
+
*/
|
|
107
|
+
function decodeTransportList(framed) {
|
|
108
|
+
const buf = framed instanceof Uint8Array ? framed : new Uint8Array(framed);
|
|
109
|
+
const out = [];
|
|
110
|
+
let i = 0;
|
|
111
|
+
while (i < buf.length) {
|
|
112
|
+
let len = 0;
|
|
113
|
+
let shift = 0;
|
|
114
|
+
for (;;) {
|
|
115
|
+
if (i >= buf.length) {
|
|
116
|
+
throw new Error('truncated transport list: length prefix runs past the end');
|
|
117
|
+
}
|
|
118
|
+
const b = buf[i++];
|
|
119
|
+
len |= (b & 0x7f) << shift;
|
|
120
|
+
if ((b & 0x80) === 0)
|
|
121
|
+
break;
|
|
122
|
+
shift += 7;
|
|
123
|
+
}
|
|
124
|
+
if (i + len > buf.length) {
|
|
125
|
+
throw new Error('truncated transport list: entry runs past the end');
|
|
126
|
+
}
|
|
127
|
+
out.push((0, messages_1.decodeMessage)(messages_1.MessageKind.TransportProtocol, buf.subarray(i, i + len)));
|
|
128
|
+
i += len;
|
|
129
|
+
}
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
82
132
|
const pairing = {
|
|
83
133
|
request: {
|
|
84
|
-
create_contact(channel_id, contact_mode,
|
|
134
|
+
create_contact(channel_id, contact_mode, transport_protocols) {
|
|
85
135
|
// The C entry point also accepts a caller-supplied nonce behind a
|
|
86
136
|
// presence flag. `@derec-alliance/nodejs` has no such parameter, so the
|
|
87
137
|
// flag is 0 and the library generates one — the same behaviour, not a
|
|
88
138
|
// default invented here.
|
|
89
|
-
const result = call('create_contact_message', channel_id, contact_mode, (
|
|
139
|
+
const result = call('create_contact_message', channel_id, contact_mode, encodeTransportList(transport_protocols), 0, 0n);
|
|
90
140
|
return {
|
|
91
141
|
contact_message: decodeContact(result.contact_wire_bytes),
|
|
92
142
|
secret_key: bytes(result.secret_key_material),
|
|
@@ -98,8 +148,8 @@ const pairing = {
|
|
|
98
148
|
/** Decodes proto `ContactMessage` bytes. Rejects a contact that violates
|
|
99
149
|
* the mode/field invariant rather than returning it. */
|
|
100
150
|
decode_contact: decodeContact,
|
|
101
|
-
produce(kind,
|
|
102
|
-
const result = call('produce_pair_request_message', kind, (
|
|
151
|
+
produce(kind, transport_protocols, contact_message, communication_info, parameter_range) {
|
|
152
|
+
const result = call('produce_pair_request_message', kind, encodeTransportList(transport_protocols), encodeContact(contact_message), (0, messages_1.encodeOptionalMessage)(messages_1.MessageKind.CommunicationInfo, communication_info), (0, messages_1.encodeOptionalMessage)(messages_1.MessageKind.ParameterRange, parameter_range));
|
|
103
153
|
return {
|
|
104
154
|
envelope: bytes(result.request_wire_bytes),
|
|
105
155
|
initiator_contact_message: decodeContact(result.initiator_contact_message_wire_bytes),
|
|
@@ -112,8 +162,8 @@ const pairing = {
|
|
|
112
162
|
request: (0, messages_1.decodeMessage)(messages_1.MessageKind.PairRequest, result.request_proto_bytes),
|
|
113
163
|
};
|
|
114
164
|
},
|
|
115
|
-
produce_pre_pair(
|
|
116
|
-
const envelope = call('produce_pre_pair_request_message', (
|
|
165
|
+
produce_pre_pair(own_transports, contact_message) {
|
|
166
|
+
const envelope = call('produce_pre_pair_request_message', encodeTransportList(own_transports), encodeContact(contact_message));
|
|
117
167
|
return { envelope: bytes(envelope) };
|
|
118
168
|
},
|
|
119
169
|
extract_pre_pair(envelope_bytes) {
|
|
@@ -124,11 +174,11 @@ const pairing = {
|
|
|
124
174
|
},
|
|
125
175
|
},
|
|
126
176
|
response: {
|
|
127
|
-
produce(channel_id, request, secret_key, communication_info, parameter_range) {
|
|
128
|
-
const result = call('produce_pair_response_message', channel_id, (0, messages_1.encodeMessage)(messages_1.MessageKind.PairRequest, request), secret_key, (0, messages_1.encodeOptionalMessage)(messages_1.MessageKind.CommunicationInfo, communication_info), (0, messages_1.encodeOptionalMessage)(messages_1.MessageKind.ParameterRange, parameter_range));
|
|
177
|
+
produce(channel_id, request, secret_key, communication_info, parameter_range, unsafe_connection = false) {
|
|
178
|
+
const result = call('produce_pair_response_message', channel_id, (0, messages_1.encodeMessage)(messages_1.MessageKind.PairRequest, request), secret_key, (0, messages_1.encodeOptionalMessage)(messages_1.MessageKind.CommunicationInfo, communication_info), (0, messages_1.encodeOptionalMessage)(messages_1.MessageKind.ParameterRange, parameter_range), unsafe_connection);
|
|
129
179
|
return {
|
|
130
180
|
envelope: bytes(result.response_wire_bytes),
|
|
131
|
-
|
|
181
|
+
peer_transports: decodeTransportList(result.peer_transports),
|
|
132
182
|
shared_key: bytes(result.shared_key),
|
|
133
183
|
channel_id: result.channel_id,
|
|
134
184
|
};
|