@derec-alliance/react-native 0.0.11 → 0.1.0
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 +40 -13
- 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 +11 -15
- package/cpp/derec_ffi.h +14 -18
- package/ios/DeRecFFI.xcframework/ios-arm64/Headers/derec_ffi.h +14 -18
- package/ios/DeRecFFI.xcframework/ios-arm64/libderec_library.a +0 -0
- package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/Headers/derec_ffi.h +14 -18
- package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/libderec_library.a +2 -2
- package/lib/primitives.d.ts +21 -9
- package/lib/primitives.js +21 -10
- package/lib/protocol.d.ts +25 -0
- package/lib/protocol.js +11 -0
- package/lib/types.d.ts +35 -22
- package/package.json +1 -1
- package/schema/derec_descriptor.bin +0 -0
- package/schema/proto/committedderecshare.proto +5 -3
- package/schema/proto/contact.proto +5 -4
- package/schema/proto/derecmessage.proto +40 -9
- package/schema/proto/derectransport.proto +9 -3
- package/schema/proto/result.proto +3 -2
- package/schema/proto/transportprotocol.proto +4 -2
- package/src/primitives.ts +21 -14
- package/src/protocol.ts +29 -0
- package/src/types.ts +32 -22
package/README.md
CHANGED
|
@@ -238,21 +238,48 @@ where either or both are absent, is ignored as `MessageIgnored` with
|
|
|
238
238
|
`reason: 'TimestampMismatch'`; this includes replies from 0.0.8 peers.
|
|
239
239
|
|
|
240
240
|
Within the inbound window `process` handles every copy of a message it is
|
|
241
|
-
given, including one of this device's own messages delivered back to it
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
241
|
+
given, including one of this device's own messages delivered back to it: both
|
|
242
|
+
ends of a channel encrypt under one key, so a reflected message decrypts as if
|
|
243
|
+
the peer had sent it. The library bounds a message's age and keeps each flow
|
|
244
|
+
safe to repeat; it does not remember which messages it has seen. Detecting
|
|
245
|
+
replays and reflections is the app's job, since the app owns the transport,
|
|
246
|
+
and how it does so is its choice. `sequence` is not a replay counter. If the
|
|
247
|
+
app does detect duplicates, key on the envelope's encrypted `message` field:
|
|
248
|
+
it cannot be changed without failing decryption and differs for every
|
|
249
|
+
message, since each is sealed under a fresh random nonce;
|
|
250
|
+
`envelope.encrypted_payload` reads that field. Never key on a hash of the raw
|
|
251
|
+
envelope: `sequence` and `traceId` are not authenticated and an
|
|
252
|
+
envelope can be re-encoded, so a copy can arrive as different bytes. Keep each
|
|
253
|
+
key for the inbound window measured from the later of the envelope's arrival
|
|
254
|
+
(or send) and its `timestamp`, and keep the record across restarts. A sender
|
|
255
|
+
that retries by building the message again draws a new nonce, so its retry is
|
|
256
|
+
a new message. A helper ignores a `StoreShareRequest` for a version older than
|
|
257
|
+
the newest it stores on the channel, and not stored itself, as
|
|
258
|
+
`MessageIgnored` with `reason: "Superseded"`, unanswered. Reject a contact
|
|
259
|
+
update older than the last one you accepted on the channel, using the
|
|
253
260
|
`timestamp` of the envelope that raised it; that needs auto-accept off for
|
|
254
261
|
`UpdateChannelInfo`.
|
|
255
262
|
|
|
263
|
+
Choose `timeouts.inbound_message_secs` to cover the longest a message can take
|
|
264
|
+
to arrive plus the clock difference between devices (default 300 seconds; a
|
|
265
|
+
store-and-forward relay with devices offline for long periods may need an
|
|
266
|
+
hour); a longer window is a longer replay exposure, so a duplicate record must
|
|
267
|
+
cover all of it. What each flow does with a message it already handled is in
|
|
268
|
+
[Replays and
|
|
269
|
+
reflections](https://github.com/derecalliance/lib-derec/tree/main/library#replays-and-reflections).
|
|
270
|
+
|
|
271
|
+
The envelope's protocol version is copied into the encrypted payload and
|
|
272
|
+
checked like the timestamp, so it cannot be changed undetected: a message
|
|
273
|
+
whose copy differs is ignored as `MessageIgnored` with
|
|
274
|
+
`reason: 'ProtocolVersionMismatch'`. A message from an earlier release carries
|
|
275
|
+
no copy, which reads as 0.0, its envelope's version.
|
|
276
|
+
`withMinProtocolVersion(major, minor)` (default 0.0, every version;
|
|
277
|
+
`min_protocol_version` in the config JSON) stops accepting older releases:
|
|
278
|
+
once every peer runs 0.1.0 or later, raise it to 0.1, and a message naming an
|
|
279
|
+
older version is ignored as `MessageIgnored` with
|
|
280
|
+
`reason: 'ProtocolVersionTooOld'`: nothing in it is decrypted, stored or
|
|
281
|
+
answered.
|
|
282
|
+
|
|
256
283
|
A pairing has a lifetime, `timeouts.pairing_secs` (default 30). Both sides
|
|
257
284
|
enforce it and nothing is sent on expiry: `start(FlowKind.Pairing, …)` refuses
|
|
258
285
|
a contact older than it with code `pairing_expired`; the contact's creator
|
|
@@ -564,7 +591,7 @@ case nothing is sent:
|
|
|
564
591
|
- `accept()` throws. The pairing has completed and its response was sent,
|
|
565
592
|
but `PairingCompleted` is not returned.
|
|
566
593
|
- `verifyFingerprint()` throws. The promotion stands: calling it again
|
|
567
|
-
resolves
|
|
594
|
+
resolves and publishes nothing.
|
|
568
595
|
|
|
569
596
|
Call `start` with `ProtectSecret` and valid weights to publish to every
|
|
570
597
|
helper.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/cpp/Primitives.cpp
CHANGED
|
@@ -375,24 +375,20 @@ jsi::Value readTraceId(jsi::Runtime& rt,
|
|
|
375
375
|
return jsi::Value(rt, jsi::BigInt::fromUint64(rt, result.trace_id));
|
|
376
376
|
}
|
|
377
377
|
|
|
378
|
-
/// `
|
|
379
|
-
|
|
380
|
-
jsi::Value
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
requireArgs(rt, "message_id_from_envelope", count, 1);
|
|
378
|
+
/// `encrypted_payload_from_envelope(envelope: ArrayBuffer) -> ArrayBuffer`
|
|
379
|
+
jsi::Value encryptedPayload(jsi::Runtime& rt,
|
|
380
|
+
const jsi::Value&,
|
|
381
|
+
const jsi::Value* args,
|
|
382
|
+
size_t count) {
|
|
383
|
+
requireArgs(rt, "encrypted_payload_from_envelope", count, 1);
|
|
385
384
|
ByteView envelope = asBytes(rt, args[0]);
|
|
386
|
-
|
|
385
|
+
EncryptedPayloadResult result =
|
|
386
|
+
encrypted_payload_from_envelope(envelope.ptr, envelope.len);
|
|
387
387
|
if (result.error.code != 0) {
|
|
388
388
|
throwDeRecError(rt, result.error);
|
|
389
389
|
}
|
|
390
|
-
std::vector<uint8_t>
|
|
391
|
-
|
|
392
|
-
payload.setProperty(rt, "id", toArrayBuffer(rt, id.data(), id.size()));
|
|
393
|
-
payload.setProperty(rt, "timestamp",
|
|
394
|
-
jsi::BigInt::fromUint64(rt, result.timestamp));
|
|
395
|
-
return payload;
|
|
390
|
+
std::vector<uint8_t> bytes = takeBuffer(result.payload);
|
|
391
|
+
return toArrayBuffer(rt, bytes.data(), bytes.size());
|
|
396
392
|
}
|
|
397
393
|
|
|
398
394
|
/// `version() -> { major: number, minor: number }` — the protocol version the
|
|
@@ -1405,7 +1401,7 @@ void installPrimitives(jsi::Runtime& rt, jsi::Object& host) {
|
|
|
1405
1401
|
processGetSecretIdsVersionsResponseMessage);
|
|
1406
1402
|
bind(rt, host, "apply_trace_id_to_envelope", 2, applyTraceId);
|
|
1407
1403
|
bind(rt, host, "read_trace_id_from_envelope", 1, readTraceId);
|
|
1408
|
-
bind(rt, host, "
|
|
1404
|
+
bind(rt, host, "encrypted_payload_from_envelope", 1, encryptedPayload);
|
|
1409
1405
|
bind(rt, host, "create_contact_message", 5, createContactMessage);
|
|
1410
1406
|
bind(rt, host, "encode_contact_message", 1, encodeContactMessage);
|
|
1411
1407
|
bind(rt, host, "decode_contact_message", 1, decodeContactMessage);
|
package/cpp/derec_ffi.h
CHANGED
|
@@ -42,14 +42,15 @@
|
|
|
42
42
|
* fields this build cannot see and writing the truncated result back.
|
|
43
43
|
*
|
|
44
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`,
|
|
46
|
-
*
|
|
45
|
+
* that is current: it moved to 3 when `transport` became `transports`, to 4
|
|
46
|
+
* when [`ReplicaMember::handover_channel`] was added, and stays there until
|
|
47
|
+
* the next shape change.
|
|
47
48
|
*
|
|
48
49
|
* Declared unconditionally, unlike the serde impls that stamp it: the SDK
|
|
49
50
|
* bridges mirror this number in their own encoders, and a constant they must
|
|
50
51
|
* agree with should not appear and disappear with a feature flag.
|
|
51
52
|
*/
|
|
52
|
-
#define CHANNEL_RECORD_SCHEMA_VERSION
|
|
53
|
+
#define CHANNEL_RECORD_SCHEMA_VERSION 4
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
56
|
* Latest encoding major version, used for all new encodes. Bump only on a
|
|
@@ -582,19 +583,13 @@ typedef struct ReadTraceIdResult {
|
|
|
582
583
|
uint64_t trace_id;
|
|
583
584
|
} ReadTraceIdResult;
|
|
584
585
|
|
|
585
|
-
typedef struct
|
|
586
|
+
typedef struct EncryptedPayloadResult {
|
|
586
587
|
struct DeRecError error;
|
|
587
588
|
/**
|
|
588
|
-
*
|
|
589
|
-
* on error.
|
|
589
|
+
* The envelope's encrypted `message` field. Empty on error.
|
|
590
590
|
*/
|
|
591
|
-
struct DeRecBuffer
|
|
592
|
-
|
|
593
|
-
* The envelope's send time, in seconds since the Unix epoch. Zero on
|
|
594
|
-
* error.
|
|
595
|
-
*/
|
|
596
|
-
uint64_t timestamp;
|
|
597
|
-
} MessageIdResult;
|
|
591
|
+
struct DeRecBuffer payload;
|
|
592
|
+
} EncryptedPayloadResult;
|
|
598
593
|
|
|
599
594
|
/**
|
|
600
595
|
* Result of a message JSON codec call. `bytes` is UTF-8 JSON for
|
|
@@ -1469,17 +1464,18 @@ struct ReadTraceIdResult read_trace_id_from_envelope(const uint8_t *envelope_ptr
|
|
|
1469
1464
|
size_t envelope_len);
|
|
1470
1465
|
|
|
1471
1466
|
/**
|
|
1472
|
-
*
|
|
1473
|
-
*
|
|
1474
|
-
*
|
|
1467
|
+
* Read the encrypted `message` field off an envelope, without the channel
|
|
1468
|
+
* key: the part of an envelope the application's duplicate detection can
|
|
1469
|
+
* key on.
|
|
1475
1470
|
*
|
|
1476
|
-
* Mirrors [`crate::derec_message::
|
|
1471
|
+
* Mirrors [`crate::derec_message::encrypted_payload`].
|
|
1477
1472
|
*
|
|
1478
1473
|
* # Safety
|
|
1479
1474
|
*
|
|
1480
1475
|
* `envelope_ptr` must point to a readable byte range of length `envelope_len`.
|
|
1481
1476
|
*/
|
|
1482
|
-
struct
|
|
1477
|
+
struct EncryptedPayloadResult encrypted_payload_from_envelope(const uint8_t *envelope_ptr,
|
|
1478
|
+
size_t envelope_len);
|
|
1483
1479
|
|
|
1484
1480
|
/**
|
|
1485
1481
|
* Releases the owned strings carried by a [`DeRecError`]. After
|
|
@@ -42,14 +42,15 @@
|
|
|
42
42
|
* fields this build cannot see and writing the truncated result back.
|
|
43
43
|
*
|
|
44
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`,
|
|
46
|
-
*
|
|
45
|
+
* that is current: it moved to 3 when `transport` became `transports`, to 4
|
|
46
|
+
* when [`ReplicaMember::handover_channel`] was added, and stays there until
|
|
47
|
+
* the next shape change.
|
|
47
48
|
*
|
|
48
49
|
* Declared unconditionally, unlike the serde impls that stamp it: the SDK
|
|
49
50
|
* bridges mirror this number in their own encoders, and a constant they must
|
|
50
51
|
* agree with should not appear and disappear with a feature flag.
|
|
51
52
|
*/
|
|
52
|
-
#define CHANNEL_RECORD_SCHEMA_VERSION
|
|
53
|
+
#define CHANNEL_RECORD_SCHEMA_VERSION 4
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
56
|
* Latest encoding major version, used for all new encodes. Bump only on a
|
|
@@ -582,19 +583,13 @@ typedef struct ReadTraceIdResult {
|
|
|
582
583
|
uint64_t trace_id;
|
|
583
584
|
} ReadTraceIdResult;
|
|
584
585
|
|
|
585
|
-
typedef struct
|
|
586
|
+
typedef struct EncryptedPayloadResult {
|
|
586
587
|
struct DeRecError error;
|
|
587
588
|
/**
|
|
588
|
-
*
|
|
589
|
-
* on error.
|
|
589
|
+
* The envelope's encrypted `message` field. Empty on error.
|
|
590
590
|
*/
|
|
591
|
-
struct DeRecBuffer
|
|
592
|
-
|
|
593
|
-
* The envelope's send time, in seconds since the Unix epoch. Zero on
|
|
594
|
-
* error.
|
|
595
|
-
*/
|
|
596
|
-
uint64_t timestamp;
|
|
597
|
-
} MessageIdResult;
|
|
591
|
+
struct DeRecBuffer payload;
|
|
592
|
+
} EncryptedPayloadResult;
|
|
598
593
|
|
|
599
594
|
/**
|
|
600
595
|
* Result of a message JSON codec call. `bytes` is UTF-8 JSON for
|
|
@@ -1469,17 +1464,18 @@ struct ReadTraceIdResult read_trace_id_from_envelope(const uint8_t *envelope_ptr
|
|
|
1469
1464
|
size_t envelope_len);
|
|
1470
1465
|
|
|
1471
1466
|
/**
|
|
1472
|
-
*
|
|
1473
|
-
*
|
|
1474
|
-
*
|
|
1467
|
+
* Read the encrypted `message` field off an envelope, without the channel
|
|
1468
|
+
* key: the part of an envelope the application's duplicate detection can
|
|
1469
|
+
* key on.
|
|
1475
1470
|
*
|
|
1476
|
-
* Mirrors [`crate::derec_message::
|
|
1471
|
+
* Mirrors [`crate::derec_message::encrypted_payload`].
|
|
1477
1472
|
*
|
|
1478
1473
|
* # Safety
|
|
1479
1474
|
*
|
|
1480
1475
|
* `envelope_ptr` must point to a readable byte range of length `envelope_len`.
|
|
1481
1476
|
*/
|
|
1482
|
-
struct
|
|
1477
|
+
struct EncryptedPayloadResult encrypted_payload_from_envelope(const uint8_t *envelope_ptr,
|
|
1478
|
+
size_t envelope_len);
|
|
1483
1479
|
|
|
1484
1480
|
/**
|
|
1485
1481
|
* Releases the owned strings carried by a [`DeRecError`]. After
|
|
Binary file
|
|
@@ -42,14 +42,15 @@
|
|
|
42
42
|
* fields this build cannot see and writing the truncated result back.
|
|
43
43
|
*
|
|
44
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`,
|
|
46
|
-
*
|
|
45
|
+
* that is current: it moved to 3 when `transport` became `transports`, to 4
|
|
46
|
+
* when [`ReplicaMember::handover_channel`] was added, and stays there until
|
|
47
|
+
* the next shape change.
|
|
47
48
|
*
|
|
48
49
|
* Declared unconditionally, unlike the serde impls that stamp it: the SDK
|
|
49
50
|
* bridges mirror this number in their own encoders, and a constant they must
|
|
50
51
|
* agree with should not appear and disappear with a feature flag.
|
|
51
52
|
*/
|
|
52
|
-
#define CHANNEL_RECORD_SCHEMA_VERSION
|
|
53
|
+
#define CHANNEL_RECORD_SCHEMA_VERSION 4
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
56
|
* Latest encoding major version, used for all new encodes. Bump only on a
|
|
@@ -582,19 +583,13 @@ typedef struct ReadTraceIdResult {
|
|
|
582
583
|
uint64_t trace_id;
|
|
583
584
|
} ReadTraceIdResult;
|
|
584
585
|
|
|
585
|
-
typedef struct
|
|
586
|
+
typedef struct EncryptedPayloadResult {
|
|
586
587
|
struct DeRecError error;
|
|
587
588
|
/**
|
|
588
|
-
*
|
|
589
|
-
* on error.
|
|
589
|
+
* The envelope's encrypted `message` field. Empty on error.
|
|
590
590
|
*/
|
|
591
|
-
struct DeRecBuffer
|
|
592
|
-
|
|
593
|
-
* The envelope's send time, in seconds since the Unix epoch. Zero on
|
|
594
|
-
* error.
|
|
595
|
-
*/
|
|
596
|
-
uint64_t timestamp;
|
|
597
|
-
} MessageIdResult;
|
|
591
|
+
struct DeRecBuffer payload;
|
|
592
|
+
} EncryptedPayloadResult;
|
|
598
593
|
|
|
599
594
|
/**
|
|
600
595
|
* Result of a message JSON codec call. `bytes` is UTF-8 JSON for
|
|
@@ -1469,17 +1464,18 @@ struct ReadTraceIdResult read_trace_id_from_envelope(const uint8_t *envelope_ptr
|
|
|
1469
1464
|
size_t envelope_len);
|
|
1470
1465
|
|
|
1471
1466
|
/**
|
|
1472
|
-
*
|
|
1473
|
-
*
|
|
1474
|
-
*
|
|
1467
|
+
* Read the encrypted `message` field off an envelope, without the channel
|
|
1468
|
+
* key: the part of an envelope the application's duplicate detection can
|
|
1469
|
+
* key on.
|
|
1475
1470
|
*
|
|
1476
|
-
* Mirrors [`crate::derec_message::
|
|
1471
|
+
* Mirrors [`crate::derec_message::encrypted_payload`].
|
|
1477
1472
|
*
|
|
1478
1473
|
* # Safety
|
|
1479
1474
|
*
|
|
1480
1475
|
* `envelope_ptr` must point to a readable byte range of length `envelope_len`.
|
|
1481
1476
|
*/
|
|
1482
|
-
struct
|
|
1477
|
+
struct EncryptedPayloadResult encrypted_payload_from_envelope(const uint8_t *envelope_ptr,
|
|
1478
|
+
size_t envelope_len);
|
|
1483
1479
|
|
|
1484
1480
|
/**
|
|
1485
1481
|
* Releases the owned strings carried by a [`DeRecError`]. After
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/libderec_library.a
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 43864016 bytes
|
|
4
|
+
sha256: e030b8f985557aab348f556650070ced884b76c0ac66f701f338d09ce561055e
|
package/lib/primitives.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CommittedDeRecShare, CommunicationInfo, ContactMessage, ContactMode, CreateContactResult, DiscoveryProcessResult, GetSecretIdsVersionsRequestMessage, GetSecretIdsVersionsResponseMessage, GetShareRequestMessage, GetShareResponseMessage,
|
|
1
|
+
import type { CommittedDeRecShare, CommunicationInfo, ContactMessage, ContactMode, CreateContactResult, DiscoveryProcessResult, GetSecretIdsVersionsRequestMessage, GetSecretIdsVersionsResponseMessage, GetShareRequestMessage, GetShareResponseMessage, PairRequestMessage, PairResponseMessage, PairingProcessResult, PairingRequestProduceResult, PairingResponseProduceResult, ParameterRange, PrePairRequestExtractResult, PrePairRequestMessage, PrePairResponseExtractResult, PrePairResponseMessage, ProcessPrePairResult, ProducePrePairNoKeysResult, ProducePrePairResult, ProduceResult, RecoverResult, SecretVersionEntry, SenderKind, SharingResponseProduceResult, SplitResult, StoreShareRequestMessage, StoreShareResponseMessage, TransportProtocol, UnpairRequestMessage, UnpairResponseMessage, UnpairingProcessResult, VerifyShareRequestMessage, VerifyShareResponseMessage, WeightedChannel } from './types';
|
|
2
2
|
export declare const primitives: {
|
|
3
3
|
discovery: {
|
|
4
4
|
request: {
|
|
@@ -132,13 +132,25 @@ export declare const envelope: {
|
|
|
132
132
|
apply_trace_id(envelope_bytes: Uint8Array, trace_id: bigint): Uint8Array;
|
|
133
133
|
read_trace_id(envelope_bytes: Uint8Array): bigint;
|
|
134
134
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
135
|
+
* Read the encrypted `message` field off an envelope, without the channel
|
|
136
|
+
* key: the part of an envelope an application can key duplicate detection
|
|
137
|
+
* on.
|
|
138
|
+
*
|
|
139
|
+
* It cannot be changed without failing decryption, and every message is
|
|
140
|
+
* sealed under a fresh random nonce, so it is the same for every copy of
|
|
141
|
+
* one message and different for every other message, even one with the
|
|
142
|
+
* same body. The cleartext fields around it (`sequence`, `traceId`) are
|
|
143
|
+
* not authenticated, and protobuf accepts more than one encoding of the
|
|
144
|
+
* same envelope, so a copy can arrive as different bytes: a hash of the
|
|
145
|
+
* raw envelope does not identify a message. How to key on these bytes (as
|
|
146
|
+
* they are, or hashed) and for how long is the application's choice.
|
|
147
|
+
*
|
|
148
|
+
* The plaintext `PrePair` leg of `HashedKeys` pairing is the exception: its
|
|
149
|
+
* `message` field is not encrypted, so a copy re-encoded inside it reads
|
|
150
|
+
* differently. That leg is not authenticated at all; the contact's nonce
|
|
151
|
+
* is what binds it.
|
|
152
|
+
*
|
|
153
|
+
* Throws when the bytes are not an envelope.
|
|
142
154
|
*/
|
|
143
|
-
|
|
155
|
+
encrypted_payload(envelope_bytes: Uint8Array): Uint8Array;
|
|
144
156
|
};
|
package/lib/primitives.js
CHANGED
|
@@ -404,16 +404,27 @@ exports.envelope = {
|
|
|
404
404
|
return call('read_trace_id_from_envelope', envelope_bytes);
|
|
405
405
|
},
|
|
406
406
|
/**
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
407
|
+
* Read the encrypted `message` field off an envelope, without the channel
|
|
408
|
+
* key: the part of an envelope an application can key duplicate detection
|
|
409
|
+
* on.
|
|
410
|
+
*
|
|
411
|
+
* It cannot be changed without failing decryption, and every message is
|
|
412
|
+
* sealed under a fresh random nonce, so it is the same for every copy of
|
|
413
|
+
* one message and different for every other message, even one with the
|
|
414
|
+
* same body. The cleartext fields around it (`sequence`, `traceId`) are
|
|
415
|
+
* not authenticated, and protobuf accepts more than one encoding of the
|
|
416
|
+
* same envelope, so a copy can arrive as different bytes: a hash of the
|
|
417
|
+
* raw envelope does not identify a message. How to key on these bytes (as
|
|
418
|
+
* they are, or hashed) and for how long is the application's choice.
|
|
419
|
+
*
|
|
420
|
+
* The plaintext `PrePair` leg of `HashedKeys` pairing is the exception: its
|
|
421
|
+
* `message` field is not encrypted, so a copy re-encoded inside it reads
|
|
422
|
+
* differently. That leg is not authenticated at all; the contact's nonce
|
|
423
|
+
* is what binds it.
|
|
424
|
+
*
|
|
425
|
+
* Throws when the bytes are not an envelope.
|
|
414
426
|
*/
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
return { id: bytes(result.id), timestamp: result.timestamp };
|
|
427
|
+
encrypted_payload(envelope_bytes) {
|
|
428
|
+
return bytes(call('encrypted_payload_from_envelope', envelope_bytes));
|
|
418
429
|
},
|
|
419
430
|
};
|
package/lib/protocol.d.ts
CHANGED
|
@@ -135,6 +135,14 @@ export declare class DeRecProtocolBuilder {
|
|
|
135
135
|
withAutoAccept(policy: AutoAcceptPolicy): this;
|
|
136
136
|
/** Default: unset. */
|
|
137
137
|
withReplicaId(replicaId: bigint | number): this;
|
|
138
|
+
/**
|
|
139
|
+
* The oldest protocol version whose messages this device still accepts.
|
|
140
|
+
* An inbound envelope naming an older version is ignored with
|
|
141
|
+
* `MessageIgnored` reason `"ProtocolVersionTooOld"`: nothing is
|
|
142
|
+
* decrypted, stored or answered. Default: 0.0, which accepts every
|
|
143
|
+
* version.
|
|
144
|
+
*/
|
|
145
|
+
withMinProtocolVersion(major: number, minor: number): this;
|
|
138
146
|
/**
|
|
139
147
|
* Declare the bounds this node advertises during pair negotiation.
|
|
140
148
|
*
|
|
@@ -258,6 +266,23 @@ export declare class DeRecProtocol {
|
|
|
258
266
|
start(flowKind: FlowKind.Unpair, params: UnpairParams): Promise<DeRecEvent[]>;
|
|
259
267
|
start(flowKind: FlowKind.UpdateChannelInfo, params: UpdateChannelInfoParams): Promise<DeRecEvent[]>;
|
|
260
268
|
start(flowKind: FlowKind.ReplicaDiscovery, params?: ReplicaDiscoveryParams): Promise<DeRecEvent[]>;
|
|
269
|
+
/** Remove a member from the replica group; naming this device is a
|
|
270
|
+
* voluntary departure. It tells every member, the departing one included,
|
|
271
|
+
* then either drops the named member on this device at once, with any key
|
|
272
|
+
* only it used, and reports `ReplicaRemoved`, or, when removing this
|
|
273
|
+
* device, publishes without its own row and then drops the whole
|
|
274
|
+
* `secret_id` partition, reporting `SelfRemovedFromGroup`. Either way it
|
|
275
|
+
* publishes the latest snapshot, or an empty payload when there is none,
|
|
276
|
+
* with a roster that omits the member; that round's events follow, as for
|
|
277
|
+
* `start(FlowKind.ProtectSecret)`. The application publishes nothing
|
|
278
|
+
* itself to complete a removal.
|
|
279
|
+
*
|
|
280
|
+
* The departing member is on no distribution list from then on. Every
|
|
281
|
+
* other member flags it when told and drops it, with `ReplicaRemoved`,
|
|
282
|
+
* once that roster arrives. When this device removes itself, the remaining
|
|
283
|
+
* members acknowledge the publish after it dropped the group channel, and
|
|
284
|
+
* `process` fails those acknowledgements with an unknown-channel error,
|
|
285
|
+
* which can be disregarded. */
|
|
261
286
|
start(flowKind: FlowKind.UnpairReplica, params: UnpairReplicaParams): Promise<DeRecEvent[]>;
|
|
262
287
|
process(message: Uint8Array): Promise<DeRecEvent[]>;
|
|
263
288
|
tick(): Promise<DeRecEvent[]>;
|
package/lib/protocol.js
CHANGED
|
@@ -411,6 +411,17 @@ class DeRecProtocolBuilder {
|
|
|
411
411
|
this.config.replica_id = BigInt(replicaId).toString();
|
|
412
412
|
return this;
|
|
413
413
|
}
|
|
414
|
+
/**
|
|
415
|
+
* The oldest protocol version whose messages this device still accepts.
|
|
416
|
+
* An inbound envelope naming an older version is ignored with
|
|
417
|
+
* `MessageIgnored` reason `"ProtocolVersionTooOld"`: nothing is
|
|
418
|
+
* decrypted, stored or answered. Default: 0.0, which accepts every
|
|
419
|
+
* version.
|
|
420
|
+
*/
|
|
421
|
+
withMinProtocolVersion(major, minor) {
|
|
422
|
+
this.config.min_protocol_version = { major, minor };
|
|
423
|
+
return this;
|
|
424
|
+
}
|
|
414
425
|
/**
|
|
415
426
|
* Declare the bounds this node advertises during pair negotiation.
|
|
416
427
|
*
|
package/lib/types.d.ts
CHANGED
|
@@ -604,7 +604,7 @@ export interface ProtectSecretParams {
|
|
|
604
604
|
* (`PairingCompleted` included); `accept()` throws after the pairing has
|
|
605
605
|
* completed and its response was sent, without returning
|
|
606
606
|
* `PairingCompleted`; `verifyFingerprint()` throws after the promotion,
|
|
607
|
-
* which stands, and a retry resolves
|
|
607
|
+
* which stands, and a retry resolves and publishes nothing. Call
|
|
608
608
|
* `start` with `ProtectSecret` and valid weights to publish.
|
|
609
609
|
*
|
|
610
610
|
* When the paired helpers' resolved total is below the round's threshold
|
|
@@ -712,11 +712,13 @@ export type ReplicaDiscoveryParams = Record<string, never>;
|
|
|
712
712
|
* source must be removable by the devices that remain, and the library
|
|
713
713
|
* checks no role. Ask the user before starting this flow, above all when it
|
|
714
714
|
* names the source. Removing the source promotes the first remaining member
|
|
715
|
-
* in the order the channel store's `listReplicas` returns
|
|
716
|
-
*
|
|
717
|
-
*
|
|
718
|
-
* `SelfRemovedFromGroup`.
|
|
719
|
-
* the
|
|
715
|
+
* in the order the channel store's `listReplicas` returns; removing a sole
|
|
716
|
+
* source dissolves the group. The removed member is not asked: when the
|
|
717
|
+
* notice naming it arrives it drops its whole `secret_id` partition and
|
|
718
|
+
* emits `SelfRemovedFromGroup`. If the notice is lost it keeps what it held,
|
|
719
|
+
* but it is sent nothing new and the remaining members refuse its messages
|
|
720
|
+
* once the roster without it has reached them. The secret survives on the
|
|
721
|
+
* remaining members and the helpers.
|
|
720
722
|
*
|
|
721
723
|
* Removal does not replace the group key, so it relies on the removed
|
|
722
724
|
* device's library deleting its copy. That covers a lost or stolen device
|
|
@@ -872,7 +874,9 @@ export type DeRecEvent = {
|
|
|
872
874
|
reason: string;
|
|
873
875
|
}
|
|
874
876
|
/** A member left the group and its roster row was dropped. Fires on the
|
|
875
|
-
*
|
|
877
|
+
* device that ran the removal, when it starts it, and on every other
|
|
878
|
+
* remaining member when the roster without the member arrives. The
|
|
879
|
+
* departing device reports `SelfRemovedFromGroup` instead. */
|
|
876
880
|
| {
|
|
877
881
|
type: "ReplicaRemoved";
|
|
878
882
|
replica_id: string;
|
|
@@ -887,9 +891,11 @@ export type DeRecEvent = {
|
|
|
887
891
|
}
|
|
888
892
|
/** This device left the group and dropped its whole `secret_id` partition —
|
|
889
893
|
* group channel, helper channels, shares, secrets and the snapshot. Fires
|
|
890
|
-
*
|
|
891
|
-
*
|
|
892
|
-
*
|
|
894
|
+
* when this device is told to leave, when it removes itself after
|
|
895
|
+
* publishing the roster without it, or when a roster excluding it arrives
|
|
896
|
+
* after it was told to leave by a device on an earlier release. The
|
|
897
|
+
* teardown is automatic: this device is not asked first and gets no
|
|
898
|
+
* earlier event. */
|
|
893
899
|
| {
|
|
894
900
|
type: "SelfRemovedFromGroup";
|
|
895
901
|
version: number;
|
|
@@ -1449,8 +1455,15 @@ export type DeRecEvent = {
|
|
|
1449
1455
|
* outstanding challenge is kept. `"Superseded"` means a
|
|
1450
1456
|
* `StoreShareRequest` for a version older than the newest one this
|
|
1451
1457
|
* helper stores on the channel, and not stored itself; it is not stored
|
|
1452
|
-
* and not answered. `
|
|
1453
|
-
*
|
|
1458
|
+
* and not answered. `"ProtocolVersionTooOld"` means the envelope names a
|
|
1459
|
+
* protocol version older than the one set with `withMinProtocolVersion`;
|
|
1460
|
+
* nothing is decrypted, stored or answered. `"ProtocolVersionMismatch"`
|
|
1461
|
+
* means the envelope's protocol version and the copy inside the
|
|
1462
|
+
* encrypted payload differ: the envelope was altered or built by a
|
|
1463
|
+
* non-conforming peer; a payload from a release that writes no version
|
|
1464
|
+
* reads as 0.0, the version such a release puts on its envelope.
|
|
1465
|
+
* `trace_id` matches the peer's `*Started` event for the same round
|
|
1466
|
+
* (`"0"` when the sender set none). */
|
|
1454
1467
|
| {
|
|
1455
1468
|
type: "MessageIgnored";
|
|
1456
1469
|
channel_id: string;
|
|
@@ -1551,7 +1564,9 @@ export type DeRecEvent = {
|
|
|
1551
1564
|
* `UnpairAck.Required` the channel is now `"Unpairing"`, and an
|
|
1552
1565
|
* `Unpaired` event follows once the peer acknowledges or the
|
|
1553
1566
|
* acknowledgement window elapses, or `UnpairRejected` if the peer
|
|
1554
|
-
* refuses (the channel is `"Paired"` again
|
|
1567
|
+
* refuses: after `start(Unpair)` the channel is `"Paired"` again; a
|
|
1568
|
+
* recovery channel `restore` unpaired is dropped instead, and
|
|
1569
|
+
* `Unpaired` follows the `UnpairRejected`. Under
|
|
1555
1570
|
* `UnpairAck.NotRequired`, `Unpaired` follows in the same event vec. */
|
|
1556
1571
|
| {
|
|
1557
1572
|
type: "UnpairFailed";
|
|
@@ -1677,7 +1692,7 @@ export interface CommunicationInfo {
|
|
|
1677
1692
|
}
|
|
1678
1693
|
/** Why a `MessageIgnored` event dropped a message. Matches the Rust
|
|
1679
1694
|
* `IgnoreReason` discriminants one-for-one. */
|
|
1680
|
-
export type IgnoreReason = "PendingVerification" | "Expired" | "TimestampMismatch" | "StaleResponse" | "Superseded";
|
|
1695
|
+
export type IgnoreReason = "PendingVerification" | "Expired" | "TimestampMismatch" | "StaleResponse" | "Superseded" | "ProtocolVersionTooOld" | "ProtocolVersionMismatch";
|
|
1681
1696
|
/** Why a `PeerNotRestored` event left a roster entry without a channel.
|
|
1682
1697
|
* Matches the Rust `NotRestoredReason` discriminants one-for-one. */
|
|
1683
1698
|
export type NotRestoredReason = "NoTransports";
|
|
@@ -1779,7 +1794,8 @@ export interface DeRecAutoAcceptConfig {
|
|
|
1779
1794
|
* "unsafe_connection": false,
|
|
1780
1795
|
* "communication_info": { "name": "alice" },
|
|
1781
1796
|
* "own_transports": [{ "uri": "https://me.example.com/derec", "protocol": "https" }],
|
|
1782
|
-
* "replica_id": "9007199254740993"
|
|
1797
|
+
* "replica_id": "9007199254740993",
|
|
1798
|
+
* "min_protocol_version": { "major": 0, "minor": 1 }
|
|
1783
1799
|
* }
|
|
1784
1800
|
* ```
|
|
1785
1801
|
*/
|
|
@@ -1802,6 +1818,10 @@ export interface DeRecProtocolConfig {
|
|
|
1802
1818
|
/** Decimal string. A `bigint` is rejected; call
|
|
1803
1819
|
* `DeRecProtocolBuilder.withReplicaId` directly for a `bigint`. */
|
|
1804
1820
|
replica_id?: string;
|
|
1821
|
+
min_protocol_version?: {
|
|
1822
|
+
major: number;
|
|
1823
|
+
minor: number;
|
|
1824
|
+
};
|
|
1805
1825
|
}
|
|
1806
1826
|
export interface PairRequestMessage {
|
|
1807
1827
|
sender_kind: number;
|
|
@@ -2049,10 +2069,3 @@ export interface UnpairingProcessResult {
|
|
|
2049
2069
|
export interface DiscoveryProcessResult {
|
|
2050
2070
|
secret_list: SecretVersionEntry[];
|
|
2051
2071
|
}
|
|
2052
|
-
/** The identity of one delivered message; see `envelope.message_id`. */
|
|
2053
|
-
export interface MessageId {
|
|
2054
|
-
/** SHA-256 of the envelope's encrypted `message` field. */
|
|
2055
|
-
id: Uint8Array;
|
|
2056
|
-
/** The envelope's send time, in seconds since the Unix epoch. */
|
|
2057
|
-
timestamp: bigint;
|
|
2058
|
-
}
|
package/package.json
CHANGED
|
Binary file
|
|
@@ -57,9 +57,11 @@ message CommittedDeRecShare {
|
|
|
57
57
|
// degree of the polynomial determines the threshold: t distinct subshares,
|
|
58
58
|
// from any combination of helpers, reconstruct k at x = 0.
|
|
59
59
|
//
|
|
60
|
-
// The message also includes the secretId and the share version number,
|
|
61
|
-
//
|
|
62
|
-
// are covered by the
|
|
60
|
+
// The message also includes the secretId and the share version number, so
|
|
61
|
+
// that a holder can tell which secret and version a share belongs to. They
|
|
62
|
+
// are not covered by the Merkle commitment, which hashes only the subshares:
|
|
63
|
+
// in transit they are authenticated with the rest of the message by the
|
|
64
|
+
// channel's authenticated encryption.
|
|
63
65
|
message DeRecShare {
|
|
64
66
|
|
|
65
67
|
// One subshare: a Shamir (x, y) pair with y = f(x).
|
|
@@ -230,10 +230,11 @@ message ContactMessage {
|
|
|
230
230
|
// `contactBindingHash` does not cover this field. An attacker able to
|
|
231
231
|
// rewrite an out-of-band contact can therefore remove entries. Removing
|
|
232
232
|
// the secure ones leaves only plaintext, which the recipient's transport
|
|
233
|
-
// policy refuses unless plaintext has been explicitly opted into.
|
|
234
|
-
// messages are
|
|
235
|
-
//
|
|
236
|
-
// loss of confidentiality or
|
|
233
|
+
// policy refuses unless plaintext has been explicitly opted into. On an
|
|
234
|
+
// established channel DeRec messages are encrypted and authenticated with
|
|
235
|
+
// AES-256-GCM at the application layer on every transport, so substituting
|
|
236
|
+
// one secure transport for another is not a loss of confidentiality or
|
|
237
|
+
// authenticity.
|
|
237
238
|
repeated TransportProtocol supportedTransports = 9;
|
|
238
239
|
|
|
239
240
|
// The creator's commitment to the fingerprint nonce it reveals in
|
|
@@ -81,9 +81,9 @@ package org.derecalliance.derec.protobuf;
|
|
|
81
81
|
// encrypt under one key, so a message delivered back to its own sender
|
|
82
82
|
// decrypts there too. The transport MUST:
|
|
83
83
|
//
|
|
84
|
-
// - identify an envelope by a hash of its `message` field only. `sequence
|
|
85
|
-
// `traceId`
|
|
86
|
-
//
|
|
84
|
+
// - identify an envelope by a hash of its `message` field only. `sequence`
|
|
85
|
+
// and `traceId` are not authenticated, and an envelope can be re-encoded,
|
|
86
|
+
// so a copy can arrive as different bytes;
|
|
87
87
|
// - keep the identity of every envelope it accepted and of every envelope
|
|
88
88
|
// it sent until the later of its arrival (or sending) and its `timestamp`,
|
|
89
89
|
// plus the inbound-message window, and drop an inbound envelope whose
|
|
@@ -146,6 +146,11 @@ message DeRecMessage {
|
|
|
146
146
|
// Not yet implemented by this library: a sender may set this field, but it
|
|
147
147
|
// is not checked on receipt, and it does not trigger key rotation. Replay
|
|
148
148
|
// protection currently relies on `timestamp`.
|
|
149
|
+
//
|
|
150
|
+
// Unlike `timestamp` and the protocol version, this field has no copy in
|
|
151
|
+
// the encrypted payload, so it is not authenticated: it can be changed in
|
|
152
|
+
// transit without failing decryption. Giving it a meaning requires such a
|
|
153
|
+
// copy, checked on receipt.
|
|
149
154
|
uint32 sequence = 3;
|
|
150
155
|
|
|
151
156
|
// Channel identifier associated with this communication session.
|
|
@@ -177,12 +182,11 @@ message DeRecMessage {
|
|
|
177
182
|
|
|
178
183
|
// Encrypted message payload.
|
|
179
184
|
//
|
|
180
|
-
// This field contains the encrypted bytes of a serialized
|
|
181
|
-
//
|
|
182
|
-
// and subsequent key management
|
|
183
|
-
//
|
|
184
|
-
//
|
|
185
|
-
// containing exactly one protocol message.
|
|
185
|
+
// This field contains the encrypted bytes of a serialized DeRecPayload,
|
|
186
|
+
// which carries exactly one protocol message. The encryption scheme and key
|
|
187
|
+
// material are defined by the pairing process and subsequent key management
|
|
188
|
+
// flows. The `PrePair` leg of pairing, sent before any key exists, carries
|
|
189
|
+
// the DeRecPayload unencrypted.
|
|
186
190
|
bytes message = 6;
|
|
187
191
|
|
|
188
192
|
// Application-supplied correlation token, echoed verbatim by the
|
|
@@ -246,3 +250,30 @@ message DeRecMessage {
|
|
|
246
250
|
}
|
|
247
251
|
}
|
|
248
252
|
}
|
|
253
|
+
|
|
254
|
+
// The payload a DeRecMessage carries in `message`: one protocol message,
|
|
255
|
+
// identified by name, and a copy of the envelope's protocol version.
|
|
256
|
+
//
|
|
257
|
+
// Fields 1 and 2 are those of google.protobuf.Any, so a reader that decodes
|
|
258
|
+
// the payload as Any reads the same message and skips fields 3 and 4.
|
|
259
|
+
//
|
|
260
|
+
// The receiver checks that the copied version equals the envelope's
|
|
261
|
+
// `protocolVersionMajor` and `protocolVersionMinor`, and discards the message
|
|
262
|
+
// otherwise, as it does for the timestamp. The payload is encrypted and
|
|
263
|
+
// authenticated, so the envelope's version cannot be changed undetected. A
|
|
264
|
+
// payload from a release that writes no version reads as 0.0, the version
|
|
265
|
+
// such a release puts on its envelope.
|
|
266
|
+
message DeRecPayload {
|
|
267
|
+
// `type.derec.org/` followed by the message's name, e.g.
|
|
268
|
+
// `type.derec.org/StoreShareRequestMessage`.
|
|
269
|
+
string type_url = 1;
|
|
270
|
+
|
|
271
|
+
// The encoded protocol message.
|
|
272
|
+
bytes value = 2;
|
|
273
|
+
|
|
274
|
+
// Copy of the envelope's `protocolVersionMajor`.
|
|
275
|
+
uint32 protocolVersionMajor = 3;
|
|
276
|
+
|
|
277
|
+
// Copy of the envelope's `protocolVersionMinor`.
|
|
278
|
+
uint32 protocolVersionMinor = 4;
|
|
279
|
+
}
|
|
@@ -25,9 +25,15 @@ import "google/protobuf/empty.proto";
|
|
|
25
25
|
///
|
|
26
26
|
/// # Security
|
|
27
27
|
///
|
|
28
|
-
/// This service provides no security guarantees of its own.
|
|
29
|
-
/// `DeRecMessage`
|
|
30
|
-
///
|
|
28
|
+
/// This service provides no security guarantees of its own. On an established
|
|
29
|
+
/// channel, every `DeRecMessage` payload is encrypted and authenticated with
|
|
30
|
+
/// AES-256-GCM under the channel's shared key at the application layer; the
|
|
31
|
+
/// pairing messages are protected by the pairing handshake instead. Messages
|
|
32
|
+
/// are not signed. The envelope header is not covered by the authentication
|
|
33
|
+
/// tag: the receiver binds `timestamp` and the protocol version to copies in
|
|
34
|
+
/// the authenticated payload, and `channelId` selects the key, so none of
|
|
35
|
+
/// them can be altered undetected; `sequence` and `traceId` carry no
|
|
36
|
+
/// authenticated meaning. A message remains valid regardless of transport.
|
|
31
37
|
service DeRecTransport {
|
|
32
38
|
/// Deliver one DeRec envelope to this endpoint.
|
|
33
39
|
///
|
|
@@ -110,9 +110,10 @@ enum StatusEnum {
|
|
|
110
110
|
// - corrupted ciphertext
|
|
111
111
|
DECRYPTION_FAILED = 7;
|
|
112
112
|
|
|
113
|
-
//
|
|
113
|
+
// A share does not verify against its Merkle commitment.
|
|
114
114
|
//
|
|
115
|
-
//
|
|
115
|
+
// Sent in answer to a share whose subshares and Merkle path do not
|
|
116
|
+
// reproduce the commitment it carries.
|
|
116
117
|
VERIFICATION_FAILED = 8;
|
|
117
118
|
|
|
118
119
|
// The message format is invalid.
|
|
@@ -54,8 +54,10 @@ enum Protocol {
|
|
|
54
54
|
/// how to establish communication channels.
|
|
55
55
|
///
|
|
56
56
|
/// A TransportProtocol does not itself provide security guarantees.
|
|
57
|
-
///
|
|
58
|
-
/// application layer, regardless of
|
|
57
|
+
/// DeRec protocol messages on an established channel are encrypted and
|
|
58
|
+
/// authenticated with AES-256-GCM at the application layer, regardless of
|
|
59
|
+
/// the underlying transport; the pairing messages are protected by the
|
|
60
|
+
/// pairing handshake.
|
|
59
61
|
///
|
|
60
62
|
/// # Semantics
|
|
61
63
|
///
|
package/src/primitives.ts
CHANGED
|
@@ -44,7 +44,6 @@ import type {
|
|
|
44
44
|
GetSecretIdsVersionsResponseMessage,
|
|
45
45
|
GetShareRequestMessage,
|
|
46
46
|
GetShareResponseMessage,
|
|
47
|
-
MessageId,
|
|
48
47
|
PairRequestMessage,
|
|
49
48
|
PairResponseMessage,
|
|
50
49
|
PairingProcessResult,
|
|
@@ -897,19 +896,27 @@ export const envelope = {
|
|
|
897
896
|
return call('read_trace_id_from_envelope', envelope_bytes) as bigint;
|
|
898
897
|
},
|
|
899
898
|
/**
|
|
900
|
-
*
|
|
901
|
-
*
|
|
902
|
-
*
|
|
903
|
-
*
|
|
904
|
-
*
|
|
905
|
-
*
|
|
906
|
-
*
|
|
899
|
+
* Read the encrypted `message` field off an envelope, without the channel
|
|
900
|
+
* key: the part of an envelope an application can key duplicate detection
|
|
901
|
+
* on.
|
|
902
|
+
*
|
|
903
|
+
* It cannot be changed without failing decryption, and every message is
|
|
904
|
+
* sealed under a fresh random nonce, so it is the same for every copy of
|
|
905
|
+
* one message and different for every other message, even one with the
|
|
906
|
+
* same body. The cleartext fields around it (`sequence`, `traceId`) are
|
|
907
|
+
* not authenticated, and protobuf accepts more than one encoding of the
|
|
908
|
+
* same envelope, so a copy can arrive as different bytes: a hash of the
|
|
909
|
+
* raw envelope does not identify a message. How to key on these bytes (as
|
|
910
|
+
* they are, or hashed) and for how long is the application's choice.
|
|
911
|
+
*
|
|
912
|
+
* The plaintext `PrePair` leg of `HashedKeys` pairing is the exception: its
|
|
913
|
+
* `message` field is not encrypted, so a copy re-encoded inside it reads
|
|
914
|
+
* differently. That leg is not authenticated at all; the contact's nonce
|
|
915
|
+
* is what binds it.
|
|
916
|
+
*
|
|
917
|
+
* Throws when the bytes are not an envelope.
|
|
907
918
|
*/
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
id: ArrayBuffer;
|
|
911
|
-
timestamp: bigint;
|
|
912
|
-
};
|
|
913
|
-
return { id: bytes(result.id), timestamp: result.timestamp };
|
|
919
|
+
encrypted_payload(envelope_bytes: Uint8Array): Uint8Array {
|
|
920
|
+
return bytes(call('encrypted_payload_from_envelope', envelope_bytes));
|
|
914
921
|
},
|
|
915
922
|
};
|
package/src/protocol.ts
CHANGED
|
@@ -479,6 +479,18 @@ export class DeRecProtocolBuilder {
|
|
|
479
479
|
return this;
|
|
480
480
|
}
|
|
481
481
|
|
|
482
|
+
/**
|
|
483
|
+
* The oldest protocol version whose messages this device still accepts.
|
|
484
|
+
* An inbound envelope naming an older version is ignored with
|
|
485
|
+
* `MessageIgnored` reason `"ProtocolVersionTooOld"`: nothing is
|
|
486
|
+
* decrypted, stored or answered. Default: 0.0, which accepts every
|
|
487
|
+
* version.
|
|
488
|
+
*/
|
|
489
|
+
withMinProtocolVersion(major: number, minor: number): this {
|
|
490
|
+
this.config.min_protocol_version = { major, minor };
|
|
491
|
+
return this;
|
|
492
|
+
}
|
|
493
|
+
|
|
482
494
|
/**
|
|
483
495
|
* Declare the bounds this node advertises during pair negotiation.
|
|
484
496
|
*
|
|
@@ -702,6 +714,23 @@ export class DeRecProtocol {
|
|
|
702
714
|
start(flowKind: FlowKind.Unpair, params: UnpairParams): Promise<DeRecEvent[]>;
|
|
703
715
|
start(flowKind: FlowKind.UpdateChannelInfo, params: UpdateChannelInfoParams): Promise<DeRecEvent[]>;
|
|
704
716
|
start(flowKind: FlowKind.ReplicaDiscovery, params?: ReplicaDiscoveryParams): Promise<DeRecEvent[]>;
|
|
717
|
+
/** Remove a member from the replica group; naming this device is a
|
|
718
|
+
* voluntary departure. It tells every member, the departing one included,
|
|
719
|
+
* then either drops the named member on this device at once, with any key
|
|
720
|
+
* only it used, and reports `ReplicaRemoved`, or, when removing this
|
|
721
|
+
* device, publishes without its own row and then drops the whole
|
|
722
|
+
* `secret_id` partition, reporting `SelfRemovedFromGroup`. Either way it
|
|
723
|
+
* publishes the latest snapshot, or an empty payload when there is none,
|
|
724
|
+
* with a roster that omits the member; that round's events follow, as for
|
|
725
|
+
* `start(FlowKind.ProtectSecret)`. The application publishes nothing
|
|
726
|
+
* itself to complete a removal.
|
|
727
|
+
*
|
|
728
|
+
* The departing member is on no distribution list from then on. Every
|
|
729
|
+
* other member flags it when told and drops it, with `ReplicaRemoved`,
|
|
730
|
+
* once that roster arrives. When this device removes itself, the remaining
|
|
731
|
+
* members acknowledge the publish after it dropped the group channel, and
|
|
732
|
+
* `process` fails those acknowledgements with an unknown-channel error,
|
|
733
|
+
* which can be disregarded. */
|
|
705
734
|
start(flowKind: FlowKind.UnpairReplica, params: UnpairReplicaParams): Promise<DeRecEvent[]>;
|
|
706
735
|
async start(flowKind: FlowKind, params?: unknown): Promise<DeRecEvent[]> {
|
|
707
736
|
const paramsBytes = buildStartParams(flowKind, params);
|
package/src/types.ts
CHANGED
|
@@ -756,7 +756,7 @@ export interface ProtectSecretParams {
|
|
|
756
756
|
* (`PairingCompleted` included); `accept()` throws after the pairing has
|
|
757
757
|
* completed and its response was sent, without returning
|
|
758
758
|
* `PairingCompleted`; `verifyFingerprint()` throws after the promotion,
|
|
759
|
-
* which stands, and a retry resolves
|
|
759
|
+
* which stands, and a retry resolves and publishes nothing. Call
|
|
760
760
|
* `start` with `ProtectSecret` and valid weights to publish.
|
|
761
761
|
*
|
|
762
762
|
* When the paired helpers' resolved total is below the round's threshold
|
|
@@ -868,11 +868,13 @@ export type ReplicaDiscoveryParams = Record<string, never>;
|
|
|
868
868
|
* source must be removable by the devices that remain, and the library
|
|
869
869
|
* checks no role. Ask the user before starting this flow, above all when it
|
|
870
870
|
* names the source. Removing the source promotes the first remaining member
|
|
871
|
-
* in the order the channel store's `listReplicas` returns
|
|
872
|
-
*
|
|
873
|
-
*
|
|
874
|
-
* `SelfRemovedFromGroup`.
|
|
875
|
-
* the
|
|
871
|
+
* in the order the channel store's `listReplicas` returns; removing a sole
|
|
872
|
+
* source dissolves the group. The removed member is not asked: when the
|
|
873
|
+
* notice naming it arrives it drops its whole `secret_id` partition and
|
|
874
|
+
* emits `SelfRemovedFromGroup`. If the notice is lost it keeps what it held,
|
|
875
|
+
* but it is sent nothing new and the remaining members refuse its messages
|
|
876
|
+
* once the roster without it has reached them. The secret survives on the
|
|
877
|
+
* remaining members and the helpers.
|
|
876
878
|
*
|
|
877
879
|
* Removal does not replace the group key, so it relies on the removed
|
|
878
880
|
* device's library deleting its copy. That covers a lost or stolen device
|
|
@@ -1005,7 +1007,9 @@ export type DeRecEvent =
|
|
|
1005
1007
|
* display. */
|
|
1006
1008
|
| { type: "ReplicaSyncFailed"; replica_id: string; version: number; reason: string }
|
|
1007
1009
|
/** A member left the group and its roster row was dropped. Fires on the
|
|
1008
|
-
*
|
|
1010
|
+
* device that ran the removal, when it starts it, and on every other
|
|
1011
|
+
* remaining member when the roster without the member arrives. The
|
|
1012
|
+
* departing device reports `SelfRemovedFromGroup` instead. */
|
|
1009
1013
|
| { type: "ReplicaRemoved"; replica_id: string }
|
|
1010
1014
|
/** The group's source role moved to another member because the previous
|
|
1011
1015
|
* source is leaving. Fires on the device that chose the successor — which
|
|
@@ -1014,9 +1018,11 @@ export type DeRecEvent =
|
|
|
1014
1018
|
| { type: "ReplicaSourceChanged"; replica_id: string }
|
|
1015
1019
|
/** This device left the group and dropped its whole `secret_id` partition —
|
|
1016
1020
|
* group channel, helper channels, shares, secrets and the snapshot. Fires
|
|
1017
|
-
*
|
|
1018
|
-
*
|
|
1019
|
-
*
|
|
1021
|
+
* when this device is told to leave, when it removes itself after
|
|
1022
|
+
* publishing the roster without it, or when a roster excluding it arrives
|
|
1023
|
+
* after it was told to leave by a device on an earlier release. The
|
|
1024
|
+
* teardown is automatic: this device is not asked first and gets no
|
|
1025
|
+
* earlier event. */
|
|
1020
1026
|
| { type: "SelfRemovedFromGroup"; version: number }
|
|
1021
1027
|
/** A replica catch-up finished. `fetched_from` is absent when this device
|
|
1022
1028
|
* was already current, in which case no hydration event follows. */
|
|
@@ -1509,8 +1515,15 @@ export type DeRecEvent =
|
|
|
1509
1515
|
* outstanding challenge is kept. `"Superseded"` means a
|
|
1510
1516
|
* `StoreShareRequest` for a version older than the newest one this
|
|
1511
1517
|
* helper stores on the channel, and not stored itself; it is not stored
|
|
1512
|
-
* and not answered. `
|
|
1513
|
-
*
|
|
1518
|
+
* and not answered. `"ProtocolVersionTooOld"` means the envelope names a
|
|
1519
|
+
* protocol version older than the one set with `withMinProtocolVersion`;
|
|
1520
|
+
* nothing is decrypted, stored or answered. `"ProtocolVersionMismatch"`
|
|
1521
|
+
* means the envelope's protocol version and the copy inside the
|
|
1522
|
+
* encrypted payload differ: the envelope was altered or built by a
|
|
1523
|
+
* non-conforming peer; a payload from a release that writes no version
|
|
1524
|
+
* reads as 0.0, the version such a release puts on its envelope.
|
|
1525
|
+
* `trace_id` matches the peer's `*Started` event for the same round
|
|
1526
|
+
* (`"0"` when the sender set none). */
|
|
1514
1527
|
| {
|
|
1515
1528
|
type: "MessageIgnored";
|
|
1516
1529
|
channel_id: string;
|
|
@@ -1582,7 +1595,9 @@ export type DeRecEvent =
|
|
|
1582
1595
|
* `UnpairAck.Required` the channel is now `"Unpairing"`, and an
|
|
1583
1596
|
* `Unpaired` event follows once the peer acknowledges or the
|
|
1584
1597
|
* acknowledgement window elapses, or `UnpairRejected` if the peer
|
|
1585
|
-
* refuses (the channel is `"Paired"` again
|
|
1598
|
+
* refuses: after `start(Unpair)` the channel is `"Paired"` again; a
|
|
1599
|
+
* recovery channel `restore` unpaired is dropped instead, and
|
|
1600
|
+
* `Unpaired` follows the `UnpairRejected`. Under
|
|
1586
1601
|
* `UnpairAck.NotRequired`, `Unpaired` follows in the same event vec. */
|
|
1587
1602
|
| { type: "UnpairFailed"; channel_id: string; error: string }
|
|
1588
1603
|
| { type: "UnpairStarted"; channel_id: string; trace_id: string }
|
|
@@ -1711,7 +1726,7 @@ export interface CommunicationInfo {
|
|
|
1711
1726
|
|
|
1712
1727
|
/** Why a `MessageIgnored` event dropped a message. Matches the Rust
|
|
1713
1728
|
* `IgnoreReason` discriminants one-for-one. */
|
|
1714
|
-
export type IgnoreReason = "PendingVerification" | "Expired" | "TimestampMismatch" | "StaleResponse" | "Superseded";
|
|
1729
|
+
export type IgnoreReason = "PendingVerification" | "Expired" | "TimestampMismatch" | "StaleResponse" | "Superseded" | "ProtocolVersionTooOld" | "ProtocolVersionMismatch";
|
|
1715
1730
|
|
|
1716
1731
|
/** Why a `PeerNotRestored` event left a roster entry without a channel.
|
|
1717
1732
|
* Matches the Rust `NotRestoredReason` discriminants one-for-one. */
|
|
@@ -1830,7 +1845,8 @@ export interface DeRecAutoAcceptConfig {
|
|
|
1830
1845
|
* "unsafe_connection": false,
|
|
1831
1846
|
* "communication_info": { "name": "alice" },
|
|
1832
1847
|
* "own_transports": [{ "uri": "https://me.example.com/derec", "protocol": "https" }],
|
|
1833
|
-
* "replica_id": "9007199254740993"
|
|
1848
|
+
* "replica_id": "9007199254740993",
|
|
1849
|
+
* "min_protocol_version": { "major": 0, "minor": 1 }
|
|
1834
1850
|
* }
|
|
1835
1851
|
* ```
|
|
1836
1852
|
*/
|
|
@@ -1853,6 +1869,7 @@ export interface DeRecProtocolConfig {
|
|
|
1853
1869
|
/** Decimal string. A `bigint` is rejected; call
|
|
1854
1870
|
* `DeRecProtocolBuilder.withReplicaId` directly for a `bigint`. */
|
|
1855
1871
|
replica_id?: string;
|
|
1872
|
+
min_protocol_version?: { major: number; minor: number };
|
|
1856
1873
|
}
|
|
1857
1874
|
|
|
1858
1875
|
export interface PairRequestMessage {
|
|
@@ -2150,10 +2167,3 @@ export interface DiscoveryProcessResult {
|
|
|
2150
2167
|
secret_list: SecretVersionEntry[];
|
|
2151
2168
|
}
|
|
2152
2169
|
|
|
2153
|
-
/** The identity of one delivered message; see `envelope.message_id`. */
|
|
2154
|
-
export interface MessageId {
|
|
2155
|
-
/** SHA-256 of the envelope's encrypted `message` field. */
|
|
2156
|
-
id: Uint8Array;
|
|
2157
|
-
/** The envelope's send time, in seconds since the Unix epoch. */
|
|
2158
|
-
timestamp: bigint;
|
|
2159
|
-
}
|