@derec-alliance/react-native 0.0.10 → 0.0.11

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 CHANGED
@@ -190,6 +190,34 @@ from `SharingComplete` with `threshold_met` rather than by counting
190
190
  responses to requests is the application's
191
191
  job](https://github.com/derecalliance/lib-derec/tree/main/library#matching-responses-to-requests-is-the-applications-job).
192
192
 
193
+ A recovery reconstructs nothing until every helper it asked has answered (a
194
+ share, a refusal or a corrupted share all count) or
195
+ `timeouts.get_share_response_secs` has passed since the requests went out;
196
+ each silent helper is then reported as `RecoverSecretFailed` with
197
+ `error: "timeout"` from `tick()`. It then decides exactly once:
198
+
199
+ - `SecretRecovered` — one secret reconstructs and every collected share is
200
+ part of it;
201
+ - `RecoveryDisputed { version, secret, supported_by, disputed_by }` — one
202
+ secret reconstructs, but other helpers hold valid shares of a different
203
+ split that does not. Either side can be the owner's: colluding helpers can
204
+ forge a complete split, and the honest ones may be too few to reconstruct
205
+ theirs. Show the owner what `secret` holds and who stands on each side, and
206
+ pass it to `restore` only once they confirm it;
207
+ - `RecoveryConflict { version, candidates, disputed_by }` — two or more
208
+ different secrets reconstruct. Each candidate carries the `secret` and
209
+ `supported_by`. The library never picks: involve the owner, and pass the
210
+ candidate they confirm to `restore`;
211
+ - `RecoveryIncomplete { secret_id, version, shares_received }` — nothing reconstructs.
212
+ The recovery is closed; start it again to retry.
213
+
214
+ `supported_by` / `disputed_by` name helpers as `RecoveryHelper { channel_id,
215
+ communication_info }`, the `communication_info` being what the helper
216
+ advertised when it paired, so the app can tell the owner who is on each side.
217
+ That is the helper's own configured communication info, not the
218
+ `peer_communication_info` it passed to `start(Pairing)`: a helper that
219
+ configures none is named by its channel alone.
220
+
193
221
  **After recovery: restore or join.** `SecretRecovered` writes nothing, so
194
222
  decide before calling `restore`. When `secret.replicas?.members` names live
195
223
  members other than the lost device, do not restore: tell the user and offer
@@ -209,6 +237,32 @@ envelope and the inner message. A message whose two timestamps differ, or
209
237
  where either or both are absent, is ignored as `MessageIgnored` with
210
238
  `reason: 'TimestampMismatch'`; this includes replies from 0.0.8 peers.
211
239
 
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
+ Detecting both is the app's transport's job: `envelope.message_id(bytes)`
243
+ returns an `id` that is the same for every copy of one message, whatever its
244
+ unauthenticated fields (sequence, trace id, protocol version) say, and a
245
+ `timestamp`. Keep the `id` of every envelope you send and of every envelope
246
+ `process` accepted (no throw and no `MessageIgnored`) until
247
+ `max(received or sent at, timestamp) + inbound_message_secs`, drop an inbound
248
+ envelope whose `id` you kept, and keep the record across restarts. Never key
249
+ on a hash of the raw bytes. A helper ignores a `StoreShareRequest` for a
250
+ version older than the newest it stores on the channel, and not stored
251
+ itself, as `MessageIgnored` with `reason: 'Superseded'`, unanswered. Reject a
252
+ contact update older than the last one you accepted on the channel, using the
253
+ `timestamp` of the envelope that raised it; that needs auto-accept off for
254
+ `UpdateChannelInfo`.
255
+
256
+ A pairing has a lifetime, `timeouts.pairing_secs` (default 30). Both sides
257
+ enforce it and nothing is sent on expiry: `start(FlowKind.Pairing, …)` refuses
258
+ a contact older than it with code `pairing_expired`; the contact's creator
259
+ reports a request on such a contact, or a request older than the lifetime, as
260
+ `MessageIgnored` with reason `"Expired"` before any `ActionRequired`, and
261
+ `accept` refuses a request that outlived it with `pairing_expired`. Pairing
262
+ involves both parties, so treat an expiry as a retry and ask the user to scan
263
+ or share a fresh contact. Keep the scanner's `expired_channels` timeout at
264
+ least `pairing_secs` plus the time a response takes to arrive.
265
+
212
266
  ---
213
267
 
214
268
  ## When `process()` fails
@@ -643,6 +697,8 @@ The canonical JSON, shared by every SDK, is:
643
697
  "inbound_message_secs": 300,
644
698
  "sharing_round_secs": 60,
645
699
  "unpair_ack_secs": 60,
700
+ "get_share_response_secs": 300,
701
+ "pairing_secs": 30,
646
702
  "expired_channels": { "enabled": true, "timeout_in_secs": 300 }
647
703
  },
648
704
  "parameter_range": { "min_share_size": 1, "max_share_size": 4096 },
@@ -678,6 +734,44 @@ react-native.config.js
678
734
 
679
735
  ---
680
736
 
737
+ ## Security considerations
738
+
739
+ ### An unconfirmed replica member is not part of the group
740
+
741
+ Until a device confirms a member's fingerprint with `verifyFingerprint`, that
742
+ member is not part of the group as far as the device is concerned. It is left
743
+ out of every roster the device publishes (each new version, catch-up answers
744
+ and the vault itself), it is not asked in a replica version check, and it
745
+ cannot succeed a removed source. Every recipient installs a roster's members
746
+ as paired, so listing an unconfirmed one would admit it on their behalf.
747
+
748
+ ### Every helper sees the vault's compressed length
749
+
750
+ The vault (the user's secrets, every helper's channel key and
751
+ `communication_info`, and the replica group key) is compressed as one gzip stream
752
+ before it is encrypted and split. Encryption keeps the length, so every
753
+ helper learns the compressed length of every version. A helper also chooses
754
+ part of what is compressed: its own `communication_info`, which it changes with
755
+ `UpdateChannelInfo`. When that text repeats part of a secret elsewhere in
756
+ the vault, the vault compresses better, so over many versions a corrupted
757
+ helper could learn another helper's channel key, the group key or the
758
+ user's secrets a few characters at a time (the side channel behind CRIME
759
+ and BREACH). Each guess costs a new version, which only the owner creates,
760
+ after a contact change the owner's application has to accept. Keep the `updateChannelInfo` auto-accept flag
761
+ off, and treat a helper that keeps changing its contact details as suspect.
762
+
763
+ ### Decoding a recovered vault has no memory limit
764
+
765
+ In recovery the vault is decrypted from shares that nothing authenticates,
766
+ so a forged recovery group can deliver any payload, including one built to
767
+ exhaust memory. The decoder parses the vault while it inflates it: a
768
+ payload that is not JSON is refused after its first bytes, and padding is
769
+ not buffered. A payload that is valid JSON still receives the memory its
770
+ largest value claims, and gzip lets a payload claim up to about 1030 times
771
+ its own size. The library sets no limit. When memory runs out, the process is killed by the operating system or aborts inside the native library, with no error and no event. To bound it, configure
772
+ `parameter_range.max_share_size`: a recovery share larger than that is refused before anything is
773
+ decoded, so a vault can claim at most about 1030 times that size.
774
+
681
775
  ## License
682
776
 
683
777
  Apache License 2.0
@@ -38,6 +38,8 @@ void throwDeRecError(jsi::Runtime& rt,
38
38
  int32_t peerStatus = error.peer_status;
39
39
  uint32_t expected = error.expected;
40
40
  uint32_t got = error.got;
41
+ bool hasChannelId = process.hasChannelId || error.has_channel_id;
42
+ uint64_t channelId = process.hasChannelId ? process.channelId : error.channel_id;
41
43
 
42
44
  // Release both owned strings in one call, matching the ABI contract.
43
45
  DeRecError owned = error;
@@ -62,9 +64,9 @@ void throwDeRecError(jsi::Runtime& rt,
62
64
  jsi::Value::createFromJsonUtf8(rt, conflictingChannelIdsJson.data(),
63
65
  conflictingChannelIdsJson.size()));
64
66
  }
65
- if (process.hasChannelId) {
67
+ if (hasChannelId) {
66
68
  payload.setProperty(rt, "channel_id",
67
- jsi::String::createFromUtf8(rt, std::to_string(process.channelId)));
69
+ jsi::String::createFromUtf8(rt, std::to_string(channelId)));
68
70
  }
69
71
  if (!process.eventsJson.empty()) {
70
72
  payload.setProperty(rt, "events",
@@ -373,6 +375,26 @@ jsi::Value readTraceId(jsi::Runtime& rt,
373
375
  return jsi::Value(rt, jsi::BigInt::fromUint64(rt, result.trace_id));
374
376
  }
375
377
 
378
+ /// `message_id_from_envelope(envelope: ArrayBuffer)
379
+ /// -> { id: ArrayBuffer, timestamp: bigint }`
380
+ jsi::Value messageId(jsi::Runtime& rt,
381
+ const jsi::Value&,
382
+ const jsi::Value* args,
383
+ size_t count) {
384
+ requireArgs(rt, "message_id_from_envelope", count, 1);
385
+ ByteView envelope = asBytes(rt, args[0]);
386
+ MessageIdResult result = message_id_from_envelope(envelope.ptr, envelope.len);
387
+ if (result.error.code != 0) {
388
+ throwDeRecError(rt, result.error);
389
+ }
390
+ std::vector<uint8_t> id = takeBuffer(result.id);
391
+ auto payload = jsi::Object(rt);
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;
396
+ }
397
+
376
398
  /// `version() -> { major: number, minor: number }` — the protocol version the
377
399
  /// core writes into every envelope it produces.
378
400
  jsi::Value protocolVersion(jsi::Runtime& rt,
@@ -1383,6 +1405,7 @@ void installPrimitives(jsi::Runtime& rt, jsi::Object& host) {
1383
1405
  processGetSecretIdsVersionsResponseMessage);
1384
1406
  bind(rt, host, "apply_trace_id_to_envelope", 2, applyTraceId);
1385
1407
  bind(rt, host, "read_trace_id_from_envelope", 1, readTraceId);
1408
+ bind(rt, host, "message_id_from_envelope", 1, messageId);
1386
1409
  bind(rt, host, "create_contact_message", 5, createContactMessage);
1387
1410
  bind(rt, host, "encode_contact_message", 1, encodeContactMessage);
1388
1411
  bind(rt, host, "decode_contact_message", 1, decodeContactMessage);
package/cpp/Primitives.h CHANGED
@@ -34,9 +34,11 @@ struct ProcessFailureDetails {
34
34
  uint64_t channelId = 0;
35
35
  };
36
36
 
37
- /// As above, additionally attaching `channel_id` (a decimal string) when
38
- /// `process.hasChannelId` is set, and `events` (the JSON array verbatim)
39
- /// when `process.eventsJson` is non-empty. Only `process` produces these.
37
+ /// As above, additionally attaching `events` (the JSON array verbatim) when
38
+ /// `process.eventsJson` is non-empty, which only `process` produces.
39
+ /// `channel_id` (a decimal string) is `process.channelId` when
40
+ /// `process.hasChannelId` is set, else the error's own channel when it
41
+ /// names one.
40
42
  [[noreturn]] void throwDeRecError(facebook::jsi::Runtime& rt,
41
43
  const DeRecError& error,
42
44
  const std::vector<uint8_t>& conflictingChannelIdsJson,
package/cpp/derec_ffi.h CHANGED
@@ -106,6 +106,8 @@
106
106
 
107
107
  #define DEREC_CATEGORY_STATE_STORE 15
108
108
 
109
+ #define DEREC_CATEGORY_TRANSPORT 16
110
+
109
111
  #define DEREC_CODE_OK 0
110
112
 
111
113
  #define DEREC_CODE_NON_OK_STATUS 1
@@ -246,6 +248,14 @@
246
248
  */
247
249
  #define DEREC_CODE_FINGERPRINT_COMMITMENT_MISMATCH 48
248
250
 
251
+ /**
252
+ * The pairing outlived `Timeouts::pairing`: the scanner refuses a contact
253
+ * older than it, and the contact's creator refuses to accept a request
254
+ * that arrives after it. Surfaced as [`DEREC_CATEGORY_PAIRING`]; nothing is
255
+ * sent to the peer, and a fresh contact starts a new pairing.
256
+ */
257
+ #define DEREC_CODE_PAIRING_EXPIRED 49
258
+
249
259
  #define DEREC_CODE_EMPTY_CHANNELS 60
250
260
 
251
261
  #define DEREC_CODE_DUPLICATE_CHANNEL_ID 61
@@ -312,6 +322,13 @@
312
322
  */
313
323
  #define DEREC_CODE_NO_USABLE_ENDPOINT 121
314
324
 
325
+ /**
326
+ * The application's transport delivered a message to none of the peer's
327
+ * endpoints: the `send` callback returned non-zero.
328
+ * `DEREC_CATEGORY_TRANSPORT`.
329
+ */
330
+ #define DEREC_CODE_TRANSPORT_SEND_FAILED 123
331
+
315
332
  /**
316
333
  * Return codes for [`crate::interop::ffi::protocol::stores::ShareStoreCallbacks::save`]
317
334
  * and `ShareStoreCallbacks::record_verification`: `0` is success, each of
@@ -494,6 +511,14 @@ typedef struct DeRecError {
494
511
  * Valid when `code == DEREC_CODE_VERSION_MISMATCH`.
495
512
  */
496
513
  uint32_t got;
514
+ /**
515
+ * Whether `channel_id` is set: the error names the channel it is about.
516
+ */
517
+ bool has_channel_id;
518
+ /**
519
+ * The channel the error is about. Valid when `has_channel_id`.
520
+ */
521
+ uint64_t channel_id;
497
522
  } DeRecError;
498
523
 
499
524
  typedef struct DeRecBuffer {
@@ -557,6 +582,20 @@ typedef struct ReadTraceIdResult {
557
582
  uint64_t trace_id;
558
583
  } ReadTraceIdResult;
559
584
 
585
+ typedef struct MessageIdResult {
586
+ struct DeRecError error;
587
+ /**
588
+ * SHA-256 of the envelope's encrypted `message` field (32 bytes). Empty
589
+ * on error.
590
+ */
591
+ struct DeRecBuffer id;
592
+ /**
593
+ * The envelope's send time, in seconds since the Unix epoch. Zero on
594
+ * error.
595
+ */
596
+ uint64_t timestamp;
597
+ } MessageIdResult;
598
+
560
599
  /**
561
600
  * Result of a message JSON codec call. `bytes` is UTF-8 JSON for
562
601
  * [`derec_decode_message_json`] and protobuf wire bytes for
@@ -1429,6 +1468,19 @@ struct ApplyTraceIdResult apply_trace_id_to_envelope(const uint8_t *envelope_ptr
1429
1468
  struct ReadTraceIdResult read_trace_id_from_envelope(const uint8_t *envelope_ptr,
1430
1469
  size_t envelope_len);
1431
1470
 
1471
+ /**
1472
+ * Identify an envelope for replay and reflection detection: the same `id`
1473
+ * for every copy of one message, whatever its unauthenticated cleartext
1474
+ * fields say, and a different one for every other message.
1475
+ *
1476
+ * Mirrors [`crate::derec_message::message_id`].
1477
+ *
1478
+ * # Safety
1479
+ *
1480
+ * `envelope_ptr` must point to a readable byte range of length `envelope_len`.
1481
+ */
1482
+ struct MessageIdResult message_id_from_envelope(const uint8_t *envelope_ptr, size_t envelope_len);
1483
+
1432
1484
  /**
1433
1485
  * Releases the owned strings carried by a [`DeRecError`]. After
1434
1486
  * returning, `error.message` and `error.peer_memo` are both null —
@@ -1804,6 +1856,8 @@ struct ProcessPrePairResponseMessageResult process_pre_pair_response_message(con
1804
1856
  * "inbound_message_secs": 300,
1805
1857
  * "sharing_round_secs": 60,
1806
1858
  * "unpair_ack_secs": 60,
1859
+ * "get_share_response_secs": 300,
1860
+ * "pairing_secs": 30,
1807
1861
  * "expired_channels": { "enabled": true, "timeout_in_secs": 300 }
1808
1862
  * },
1809
1863
  * "unsafe_connection": false,
@@ -10,15 +10,18 @@
10
10
  <key>HeadersPath</key>
11
11
  <string>Headers</string>
12
12
  <key>LibraryIdentifier</key>
13
- <string>ios-arm64</string>
13
+ <string>ios-arm64_x86_64-simulator</string>
14
14
  <key>LibraryPath</key>
15
15
  <string>libderec_library.a</string>
16
16
  <key>SupportedArchitectures</key>
17
17
  <array>
18
18
  <string>arm64</string>
19
+ <string>x86_64</string>
19
20
  </array>
20
21
  <key>SupportedPlatform</key>
21
22
  <string>ios</string>
23
+ <key>SupportedPlatformVariant</key>
24
+ <string>simulator</string>
22
25
  </dict>
23
26
  <dict>
24
27
  <key>BinaryPath</key>
@@ -26,18 +29,15 @@
26
29
  <key>HeadersPath</key>
27
30
  <string>Headers</string>
28
31
  <key>LibraryIdentifier</key>
29
- <string>ios-arm64_x86_64-simulator</string>
32
+ <string>ios-arm64</string>
30
33
  <key>LibraryPath</key>
31
34
  <string>libderec_library.a</string>
32
35
  <key>SupportedArchitectures</key>
33
36
  <array>
34
37
  <string>arm64</string>
35
- <string>x86_64</string>
36
38
  </array>
37
39
  <key>SupportedPlatform</key>
38
40
  <string>ios</string>
39
- <key>SupportedPlatformVariant</key>
40
- <string>simulator</string>
41
41
  </dict>
42
42
  </array>
43
43
  <key>CFBundlePackageType</key>
@@ -106,6 +106,8 @@
106
106
 
107
107
  #define DEREC_CATEGORY_STATE_STORE 15
108
108
 
109
+ #define DEREC_CATEGORY_TRANSPORT 16
110
+
109
111
  #define DEREC_CODE_OK 0
110
112
 
111
113
  #define DEREC_CODE_NON_OK_STATUS 1
@@ -246,6 +248,14 @@
246
248
  */
247
249
  #define DEREC_CODE_FINGERPRINT_COMMITMENT_MISMATCH 48
248
250
 
251
+ /**
252
+ * The pairing outlived `Timeouts::pairing`: the scanner refuses a contact
253
+ * older than it, and the contact's creator refuses to accept a request
254
+ * that arrives after it. Surfaced as [`DEREC_CATEGORY_PAIRING`]; nothing is
255
+ * sent to the peer, and a fresh contact starts a new pairing.
256
+ */
257
+ #define DEREC_CODE_PAIRING_EXPIRED 49
258
+
249
259
  #define DEREC_CODE_EMPTY_CHANNELS 60
250
260
 
251
261
  #define DEREC_CODE_DUPLICATE_CHANNEL_ID 61
@@ -312,6 +322,13 @@
312
322
  */
313
323
  #define DEREC_CODE_NO_USABLE_ENDPOINT 121
314
324
 
325
+ /**
326
+ * The application's transport delivered a message to none of the peer's
327
+ * endpoints: the `send` callback returned non-zero.
328
+ * `DEREC_CATEGORY_TRANSPORT`.
329
+ */
330
+ #define DEREC_CODE_TRANSPORT_SEND_FAILED 123
331
+
315
332
  /**
316
333
  * Return codes for [`crate::interop::ffi::protocol::stores::ShareStoreCallbacks::save`]
317
334
  * and `ShareStoreCallbacks::record_verification`: `0` is success, each of
@@ -494,6 +511,14 @@ typedef struct DeRecError {
494
511
  * Valid when `code == DEREC_CODE_VERSION_MISMATCH`.
495
512
  */
496
513
  uint32_t got;
514
+ /**
515
+ * Whether `channel_id` is set: the error names the channel it is about.
516
+ */
517
+ bool has_channel_id;
518
+ /**
519
+ * The channel the error is about. Valid when `has_channel_id`.
520
+ */
521
+ uint64_t channel_id;
497
522
  } DeRecError;
498
523
 
499
524
  typedef struct DeRecBuffer {
@@ -557,6 +582,20 @@ typedef struct ReadTraceIdResult {
557
582
  uint64_t trace_id;
558
583
  } ReadTraceIdResult;
559
584
 
585
+ typedef struct MessageIdResult {
586
+ struct DeRecError error;
587
+ /**
588
+ * SHA-256 of the envelope's encrypted `message` field (32 bytes). Empty
589
+ * on error.
590
+ */
591
+ struct DeRecBuffer id;
592
+ /**
593
+ * The envelope's send time, in seconds since the Unix epoch. Zero on
594
+ * error.
595
+ */
596
+ uint64_t timestamp;
597
+ } MessageIdResult;
598
+
560
599
  /**
561
600
  * Result of a message JSON codec call. `bytes` is UTF-8 JSON for
562
601
  * [`derec_decode_message_json`] and protobuf wire bytes for
@@ -1429,6 +1468,19 @@ struct ApplyTraceIdResult apply_trace_id_to_envelope(const uint8_t *envelope_ptr
1429
1468
  struct ReadTraceIdResult read_trace_id_from_envelope(const uint8_t *envelope_ptr,
1430
1469
  size_t envelope_len);
1431
1470
 
1471
+ /**
1472
+ * Identify an envelope for replay and reflection detection: the same `id`
1473
+ * for every copy of one message, whatever its unauthenticated cleartext
1474
+ * fields say, and a different one for every other message.
1475
+ *
1476
+ * Mirrors [`crate::derec_message::message_id`].
1477
+ *
1478
+ * # Safety
1479
+ *
1480
+ * `envelope_ptr` must point to a readable byte range of length `envelope_len`.
1481
+ */
1482
+ struct MessageIdResult message_id_from_envelope(const uint8_t *envelope_ptr, size_t envelope_len);
1483
+
1432
1484
  /**
1433
1485
  * Releases the owned strings carried by a [`DeRecError`]. After
1434
1486
  * returning, `error.message` and `error.peer_memo` are both null —
@@ -1804,6 +1856,8 @@ struct ProcessPrePairResponseMessageResult process_pre_pair_response_message(con
1804
1856
  * "inbound_message_secs": 300,
1805
1857
  * "sharing_round_secs": 60,
1806
1858
  * "unpair_ack_secs": 60,
1859
+ * "get_share_response_secs": 300,
1860
+ * "pairing_secs": 30,
1807
1861
  * "expired_channels": { "enabled": true, "timeout_in_secs": 300 }
1808
1862
  * },
1809
1863
  * "unsafe_connection": false,
@@ -106,6 +106,8 @@
106
106
 
107
107
  #define DEREC_CATEGORY_STATE_STORE 15
108
108
 
109
+ #define DEREC_CATEGORY_TRANSPORT 16
110
+
109
111
  #define DEREC_CODE_OK 0
110
112
 
111
113
  #define DEREC_CODE_NON_OK_STATUS 1
@@ -246,6 +248,14 @@
246
248
  */
247
249
  #define DEREC_CODE_FINGERPRINT_COMMITMENT_MISMATCH 48
248
250
 
251
+ /**
252
+ * The pairing outlived `Timeouts::pairing`: the scanner refuses a contact
253
+ * older than it, and the contact's creator refuses to accept a request
254
+ * that arrives after it. Surfaced as [`DEREC_CATEGORY_PAIRING`]; nothing is
255
+ * sent to the peer, and a fresh contact starts a new pairing.
256
+ */
257
+ #define DEREC_CODE_PAIRING_EXPIRED 49
258
+
249
259
  #define DEREC_CODE_EMPTY_CHANNELS 60
250
260
 
251
261
  #define DEREC_CODE_DUPLICATE_CHANNEL_ID 61
@@ -312,6 +322,13 @@
312
322
  */
313
323
  #define DEREC_CODE_NO_USABLE_ENDPOINT 121
314
324
 
325
+ /**
326
+ * The application's transport delivered a message to none of the peer's
327
+ * endpoints: the `send` callback returned non-zero.
328
+ * `DEREC_CATEGORY_TRANSPORT`.
329
+ */
330
+ #define DEREC_CODE_TRANSPORT_SEND_FAILED 123
331
+
315
332
  /**
316
333
  * Return codes for [`crate::interop::ffi::protocol::stores::ShareStoreCallbacks::save`]
317
334
  * and `ShareStoreCallbacks::record_verification`: `0` is success, each of
@@ -494,6 +511,14 @@ typedef struct DeRecError {
494
511
  * Valid when `code == DEREC_CODE_VERSION_MISMATCH`.
495
512
  */
496
513
  uint32_t got;
514
+ /**
515
+ * Whether `channel_id` is set: the error names the channel it is about.
516
+ */
517
+ bool has_channel_id;
518
+ /**
519
+ * The channel the error is about. Valid when `has_channel_id`.
520
+ */
521
+ uint64_t channel_id;
497
522
  } DeRecError;
498
523
 
499
524
  typedef struct DeRecBuffer {
@@ -557,6 +582,20 @@ typedef struct ReadTraceIdResult {
557
582
  uint64_t trace_id;
558
583
  } ReadTraceIdResult;
559
584
 
585
+ typedef struct MessageIdResult {
586
+ struct DeRecError error;
587
+ /**
588
+ * SHA-256 of the envelope's encrypted `message` field (32 bytes). Empty
589
+ * on error.
590
+ */
591
+ struct DeRecBuffer id;
592
+ /**
593
+ * The envelope's send time, in seconds since the Unix epoch. Zero on
594
+ * error.
595
+ */
596
+ uint64_t timestamp;
597
+ } MessageIdResult;
598
+
560
599
  /**
561
600
  * Result of a message JSON codec call. `bytes` is UTF-8 JSON for
562
601
  * [`derec_decode_message_json`] and protobuf wire bytes for
@@ -1429,6 +1468,19 @@ struct ApplyTraceIdResult apply_trace_id_to_envelope(const uint8_t *envelope_ptr
1429
1468
  struct ReadTraceIdResult read_trace_id_from_envelope(const uint8_t *envelope_ptr,
1430
1469
  size_t envelope_len);
1431
1470
 
1471
+ /**
1472
+ * Identify an envelope for replay and reflection detection: the same `id`
1473
+ * for every copy of one message, whatever its unauthenticated cleartext
1474
+ * fields say, and a different one for every other message.
1475
+ *
1476
+ * Mirrors [`crate::derec_message::message_id`].
1477
+ *
1478
+ * # Safety
1479
+ *
1480
+ * `envelope_ptr` must point to a readable byte range of length `envelope_len`.
1481
+ */
1482
+ struct MessageIdResult message_id_from_envelope(const uint8_t *envelope_ptr, size_t envelope_len);
1483
+
1432
1484
  /**
1433
1485
  * Releases the owned strings carried by a [`DeRecError`]. After
1434
1486
  * returning, `error.message` and `error.peer_memo` are both null —
@@ -1804,6 +1856,8 @@ struct ProcessPrePairResponseMessageResult process_pre_pair_response_message(con
1804
1856
  * "inbound_message_secs": 300,
1805
1857
  * "sharing_round_secs": 60,
1806
1858
  * "unpair_ack_secs": 60,
1859
+ * "get_share_response_secs": 300,
1860
+ * "pairing_secs": 30,
1807
1861
  * "expired_channels": { "enabled": true, "timeout_in_secs": 300 }
1808
1862
  * },
1809
1863
  * "unsafe_connection": false,
@@ -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: 39449544 bytes
4
- sha256: f2776c0d3cd0a91e4e6b789bd1446aaf15d7720ed5d7af57319fbe5de5a3cbbc
3
+ size: 40069496 bytes
4
+ sha256: 8179350754f8ced0c1e1ff992ce3a3c3dbd5177a5ecb9d04099c765c17633f12
package/lib/errors.d.ts CHANGED
@@ -11,7 +11,7 @@ import type { DeRecEvent } from './types';
11
11
  * The nodejs union is arguably wrong on its own terms too, but correcting it
12
12
  * is a change to that package, not this one.
13
13
  */
14
- export declare const DEREC_ERROR_CATEGORIES: readonly ["ok", "ffi", "pairing", "sharing", "recovery", "verification", "discovery", "unpairing", "derec_message", "secret_store", "channel_store", "share_store", "input", "protobuf", "invariant", "state_store"];
14
+ export declare const DEREC_ERROR_CATEGORIES: readonly ["ok", "ffi", "pairing", "sharing", "recovery", "verification", "discovery", "unpairing", "derec_message", "secret_store", "channel_store", "share_store", "input", "protobuf", "invariant", "state_store", "transport"];
15
15
  export type DeRecErrorCategory = (typeof DEREC_ERROR_CATEGORIES)[number];
16
16
  /**
17
17
  * Every code `derec_error_code_name` can return, and no others.
@@ -21,7 +21,7 @@ export type DeRecErrorCategory = (typeof DEREC_ERROR_CATEGORIES)[number];
21
21
  * own before a value reaches the library, so this list is exactly the Rust
22
22
  * `Code` table in `library/src/interop/error_codes.rs`.
23
23
  */
24
- export declare const DEREC_ERROR_CODES: readonly ["ok", "non_ok_status", "version_mismatch", "invariant", "invalid_input", "protobuf_decode", "protobuf_encode", "protocol_violation", "store_error", "builder_error", "missing_shared_key", "role_mismatch", "replica_id_not_configured", "channel_already_paired", "already_restored", "restore_conflict", "replica_id_conflict", "fingerprint_mismatch", "encryption", "keygen", "finish_pairing_initiator", "finish_pairing_responder", "empty_transport_uri", "invalid_contact_message", "invalid_pair_request_message", "invalid_pair_response_message", "prepair_hash_mismatch", "missing_replica_id", "unexpected_replica_id", "incompatible_parameter_range", "fingerprint_commitment_mismatch", "empty_channels", "duplicate_channel_id", "invalid_threshold", "empty_secret_data", "vss_share_failed", "invalid_weight", "too_many_subshares", "invalid_keep_version", "empty_responses", "empty_committed_derec_share", "decode_committed_derec_share", "decode_derec_share", "secret_id_mismatch", "reconstruction_failed", "malformed_recovered_secret", "ffi_null_ptr", "ffi_bad_length", "ffi_bad_utf8", "ffi_bad_proto", "ffi_invalid_enum", "ffi_bad_shared_key", "ffi_nul_in_string", "transport_invalid", "no_usable_endpoint"];
24
+ export declare const DEREC_ERROR_CODES: readonly ["ok", "non_ok_status", "version_mismatch", "invariant", "invalid_input", "protobuf_decode", "protobuf_encode", "protocol_violation", "store_error", "builder_error", "missing_shared_key", "role_mismatch", "replica_id_not_configured", "channel_already_paired", "already_restored", "restore_conflict", "replica_id_conflict", "fingerprint_mismatch", "encryption", "keygen", "finish_pairing_initiator", "finish_pairing_responder", "empty_transport_uri", "invalid_contact_message", "invalid_pair_request_message", "invalid_pair_response_message", "prepair_hash_mismatch", "missing_replica_id", "unexpected_replica_id", "incompatible_parameter_range", "fingerprint_commitment_mismatch", "pairing_expired", "empty_channels", "duplicate_channel_id", "invalid_threshold", "empty_secret_data", "vss_share_failed", "invalid_weight", "too_many_subshares", "invalid_keep_version", "empty_responses", "empty_committed_derec_share", "decode_committed_derec_share", "decode_derec_share", "secret_id_mismatch", "reconstruction_failed", "malformed_recovered_secret", "ffi_null_ptr", "ffi_bad_length", "ffi_bad_utf8", "ffi_bad_proto", "ffi_invalid_enum", "ffi_bad_shared_key", "ffi_nul_in_string", "transport_invalid", "no_usable_endpoint", "transport_send_failed"];
25
25
  export type DeRecErrorCode = (typeof DEREC_ERROR_CODES)[number];
26
26
  export interface DeRecError {
27
27
  category: DeRecErrorCategory;
@@ -38,7 +38,12 @@ export interface DeRecError {
38
38
  * Clear exactly these and retry `restore`.
39
39
  */
40
40
  channel_ids?: string[];
41
- /** The channel the failing inbound message arrived on, when `process()` could tell. */
41
+ /**
42
+ * The channel the error is about: the one named by
43
+ * `"channel_already_paired"`, `"fingerprint_mismatch"` and
44
+ * `"role_mismatch"`, or, on a failed `process()`, the channel the failing
45
+ * inbound message arrived on.
46
+ */
42
47
  channel_id?: string;
43
48
  /**
44
49
  * On a failed `process()`: the events it produced before failing, such as
package/lib/errors.js CHANGED
@@ -32,6 +32,7 @@ exports.DEREC_ERROR_CATEGORIES = [
32
32
  "protobuf",
33
33
  "invariant",
34
34
  "state_store",
35
+ "transport",
35
36
  ];
36
37
  /**
37
38
  * Every code `derec_error_code_name` can return, and no others.
@@ -73,6 +74,7 @@ exports.DEREC_ERROR_CODES = [
73
74
  "unexpected_replica_id",
74
75
  "incompatible_parameter_range",
75
76
  "fingerprint_commitment_mismatch",
77
+ "pairing_expired",
76
78
  "empty_channels",
77
79
  "duplicate_channel_id",
78
80
  "invalid_threshold",
@@ -97,4 +99,5 @@ exports.DEREC_ERROR_CODES = [
97
99
  "ffi_nul_in_string",
98
100
  "transport_invalid",
99
101
  "no_usable_endpoint",
102
+ "transport_send_failed",
100
103
  ];
@@ -1,4 +1,4 @@
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';
1
+ import type { CommittedDeRecShare, CommunicationInfo, ContactMessage, ContactMode, CreateContactResult, DiscoveryProcessResult, GetSecretIdsVersionsRequestMessage, GetSecretIdsVersionsResponseMessage, GetShareRequestMessage, GetShareResponseMessage, MessageId, 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: {
@@ -131,4 +131,14 @@ export declare const primitives: {
131
131
  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
+ /**
135
+ * Identify an envelope for replay and reflection detection. `id` is the
136
+ * same for every copy of one message, whatever its unauthenticated
137
+ * cleartext fields say, and different for every other message. Keep the
138
+ * `id` of every envelope sent and of every envelope `process` accepted
139
+ * until `max(received or sent at, timestamp) + inbound_message_secs`, keep
140
+ * the record across restarts, and drop an inbound envelope whose `id` is
141
+ * kept. The README has the full contract.
142
+ */
143
+ message_id(envelope_bytes: Uint8Array): MessageId;
134
144
  };
package/lib/primitives.js CHANGED
@@ -403,4 +403,17 @@ exports.envelope = {
403
403
  read_trace_id(envelope_bytes) {
404
404
  return call('read_trace_id_from_envelope', envelope_bytes);
405
405
  },
406
+ /**
407
+ * Identify an envelope for replay and reflection detection. `id` is the
408
+ * same for every copy of one message, whatever its unauthenticated
409
+ * cleartext fields say, and different for every other message. Keep the
410
+ * `id` of every envelope sent and of every envelope `process` accepted
411
+ * until `max(received or sent at, timestamp) + inbound_message_secs`, keep
412
+ * the record across restarts, and drop an inbound envelope whose `id` is
413
+ * kept. The README has the full contract.
414
+ */
415
+ message_id(envelope_bytes) {
416
+ const result = call('message_id_from_envelope', envelope_bytes);
417
+ return { id: bytes(result.id), timestamp: result.timestamp };
418
+ },
406
419
  };