@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/lib/types.d.ts CHANGED
@@ -676,6 +676,24 @@ export interface Timeouts {
676
676
  /** How long to wait for an unpair acknowledgement before dropping local
677
677
  * channel state anyway. Library default: 60. */
678
678
  unpair_ack_secs?: number;
679
+ /** How long a recovery waits for a helper to answer its share request. A
680
+ * recovery decides only once every helper it asked has answered or this
681
+ * has elapsed since the requests went out; each silent helper is then
682
+ * reported as `RecoverSecretFailed` with error `"timeout"`. The budget is
683
+ * a **human** one when helpers approve share requests by hand. The same
684
+ * budget bounds a replica version check (`FlowKind.ReplicaDiscovery`):
685
+ * once it elapses, the check concludes on the versions already reported.
686
+ * Library default: 300. */
687
+ get_share_response_secs?: number;
688
+ /** How long a pairing stays possible: how old a contact may be when it is
689
+ * scanned or answered, and how old a pairing request may be when it is
690
+ * accepted. Both sides enforce it and nothing is sent on expiry: the
691
+ * scanner refuses an expired contact, and the creator ignores a request on
692
+ * one and refuses a late accept, with `pairing_expired`. The remedy is to
693
+ * scan or share a fresh contact. A scanner's `expired_channels` timeout
694
+ * should be at least this plus the time a response takes to arrive.
695
+ * Library default: 30. */
696
+ pairing_secs?: number;
679
697
  /** Removal of channels still awaiting out-of-band fingerprint
680
698
  * confirmation — every replica pairing, and every `NoKeys` pairing.
681
699
  * Unlike the others this can be disabled, leaving the sweep to the
@@ -698,7 +716,13 @@ export type ReplicaDiscoveryParams = Record<string, never>;
698
716
  * member is not asked and gets no event when told to leave: when a roster
699
717
  * excluding it arrives it drops its whole `secret_id` partition and emits
700
718
  * `SelfRemovedFromGroup`. The secret survives on the remaining members and
701
- * the helpers. */
719
+ * the helpers.
720
+ *
721
+ * Removal does not replace the group key, so it relies on the removed
722
+ * device's library deleting its copy. That covers a lost or stolen device
723
+ * whose storage was not read. Whoever read a device's storage keeps the
724
+ * group key and can decrypt every later publication it obtains, the one
725
+ * completing the removal included. */
702
726
  export interface UnpairReplicaParams {
703
727
  /** The member to remove, as a **decimal** `u64` string — the same form
704
728
  * `ReplicaPaired.peer_replica_id` hands back. A value naming no current
@@ -706,6 +730,26 @@ export interface UnpairReplicaParams {
706
730
  replica_id: string;
707
731
  memo?: string;
708
732
  }
733
+ /** A helper named by a recovery decision (`RecoveryDisputed`,
734
+ * `RecoveryConflict`), so the app can tell the owner who is on each side.
735
+ * `channel_id` is the `u64` as a **decimal** string; `communication_info`
736
+ * is what the helper advertised when it paired, read from its channel
737
+ * record, and is absent when it advertised none. */
738
+ export interface RecoveryHelper {
739
+ channel_id: string;
740
+ communication_info?: Record<string, string>;
741
+ }
742
+ /** One secret a recovery reconstructed, reported in `RecoveryConflict`.
743
+ * `secret` has the shape of `SecretRecovered.secret`, so a confirmed
744
+ * candidate is passed to `restore` the same way. `supported_by` are the
745
+ * helpers whose shares reconstruct it, in the order their shares were
746
+ * collected. */
747
+ export interface RecoveryCandidate {
748
+ secret: Extract<DeRecEvent, {
749
+ type: "SecretRecovered";
750
+ }>["secret"];
751
+ supported_by: RecoveryHelper[];
752
+ }
709
753
  export type DeRecEvent = {
710
754
  type: "PairingCompleted";
711
755
  /** Long-term `channel_id` both peers atomically rotated to at handshake completion. */
@@ -766,7 +810,13 @@ export type DeRecEvent = {
766
810
  type: "ShareConfirmed";
767
811
  channel_id: string;
768
812
  version: number;
769
- } | {
813
+ }
814
+ /** A helper rejected or failed to store our share. `status` and `memo`
815
+ * come from the helper's response, except for a helper that did not
816
+ * answer within `timeouts.sharing_round_secs`: `tick()` then reports it
817
+ * with status `FAIL` and memo `"timeout"`. The memo of a helper's own
818
+ * answer is free text and can read the same. */
819
+ | {
770
820
  type: "ShareRejected";
771
821
  channel_id: string;
772
822
  version: number;
@@ -809,8 +859,12 @@ export type DeRecEvent = {
809
859
  status: StatusEnum;
810
860
  memo: string;
811
861
  }
812
- /** A secret sync could not be delivered to a member at all — distinct from
813
- * `ReplicaSyncRejected`, which is the member answering "no". */
862
+ /** A secret sync could not be delivered to a member, or the member did not
863
+ * acknowledge it within `timeouts.sharing_round_secs` — distinct from
864
+ * `ReplicaSyncRejected`, which is the member answering "no". `reason` is
865
+ * `"timeout"` when the member did not acknowledge in time (reported by
866
+ * `tick()`); otherwise the transport or encoding failure, rendered for
867
+ * display. */
814
868
  | {
815
869
  type: "ReplicaSyncFailed";
816
870
  replica_id: string;
@@ -902,21 +956,25 @@ export type DeRecEvent = {
902
956
  description: string;
903
957
  }>;
904
958
  }>;
905
- } | {
959
+ }
960
+ /** A helper's share was collected for a recovery. Nothing is
961
+ * reconstructed until every helper asked has answered or
962
+ * `timeouts.get_share_response_secs` has passed since the requests went
963
+ * out (each silent helper is then reported as `RecoverSecretFailed` with
964
+ * error `"timeout"`). The recovery then decides exactly once:
965
+ * `SecretRecovered`, `RecoveryDisputed`, `RecoveryConflict` or
966
+ * `RecoveryIncomplete`. */
967
+ | {
906
968
  type: "RecoveryShareReceived";
907
969
  channel_id: string;
908
970
  shares_received: number;
909
- } | {
910
- type: "RecoveryShareError";
911
- channel_id: string;
912
- shares_received: number;
913
- error: string;
914
971
  }
915
972
  /** A helper refused a recovery share request: its response carried a
916
973
  * non-OK `status` (e.g. `UNKNOWN_SHARE_VERSION`) instead of a share. The
917
- * refusal is not collected — it does not count towards `shares_received`
918
- * and the recovery stays open for the other helpers' shares — but it does
919
- * answer that helper's `RecoverSecretStarted`. */
974
+ * refusal is not collected and does not count towards `shares_received`,
975
+ * but it is that helper's answer: it answers the helper's
976
+ * `RecoverSecretStarted`, and when it is the last answer due the recovery
977
+ * decides on the shares it holds. */
920
978
  | {
921
979
  type: "RecoveryShareRefused";
922
980
  channel_id: string;
@@ -926,20 +984,24 @@ export type DeRecEvent = {
926
984
  }
927
985
  /** A helper answered with a share that cannot be part of the secret;
928
986
  * `reason` says how it failed. `Malformed` and `InvalidProof` are judged
929
- * on arrival; `Inconsistent` (valid on its own but disagreeing with the
930
- * shares the secret was rebuilt from) is reported alongside
931
- * `SecretRecovered`, once per helper. The share is set aside — it does
932
- * not count towards `shares_received` and never blocks the recovery. An
933
- * honest helper never sends one, so the app may treat it as a sign of a
934
- * damaged or compromised helper, e.g. offer to unpair it. It also
935
- * answers that helper's `RecoverSecretStarted`. */
987
+ * on arrival and count as that helper's answer; `Forged` (its group
988
+ * reconstructs under one key, but not to a secret, or a single share
989
+ * reconstructs alone) is reported with the recovery's decision, once per
990
+ * helper. The share is set aside — it does not count towards
991
+ * `shares_received` and never blocks the recovery. An honest helper never
992
+ * sends one, so the app may treat it as a sign of a damaged or
993
+ * compromised helper, e.g. offer to unpair it. A share that only
994
+ * disagrees with the others is never reported here: it is a dispute
995
+ * (`RecoveryDisputed` / `RecoveryConflict`), not evidence against its
996
+ * helper. It also answers that helper's `RecoverSecretStarted`. */
936
997
  | {
937
998
  type: "RecoveryShareCorrupted";
938
999
  channel_id: string;
939
1000
  version: number;
940
1001
  reason: CorruptionReason;
941
1002
  }
942
- /** Recovery completed — the typed `Secret` snapshot the owner
1003
+ /** Recovery completed — one secret reconstructed and every collected
1004
+ * share is part of it. `secret` is the typed `Secret` snapshot the owner
943
1005
  * originally protected. Mirrors `ReplicaSecretReceived.secret`:
944
1006
  * `secrets` is the user-facing `Vec<UserSecret>` the application
945
1007
  * fed to `start(FlowKind.ProtectSecret)`; `helpers` and `replicas`
@@ -990,6 +1052,54 @@ export type DeRecEvent = {
990
1052
  * `threshold` on `start(ProtectSecret)`. */
991
1053
  threshold?: number;
992
1054
  };
1055
+ }
1056
+ /** A recovery reconstructed two or more different secrets for `version`,
1057
+ * so it cannot tell which is the owner's. Each candidate is a complete,
1058
+ * self-consistent secret, rebuilt from the shares of the helpers in its
1059
+ * `supported_by`. Fewer than the threshold of colluding helpers can forge
1060
+ * one, so the library never picks: involve the owner and pass the
1061
+ * candidate's `secret` they confirm to `restore`, exactly as the `secret`
1062
+ * of `SecretRecovered`. The helpers backing a rejected candidate are
1063
+ * suspect. `disputed_by` names the helpers holding valid shares of yet
1064
+ * another split that does not reconstruct, so no helper's answer goes
1065
+ * unshown. The recovery is closed when this is emitted. */
1066
+ | {
1067
+ type: "RecoveryConflict";
1068
+ version: number;
1069
+ candidates: RecoveryCandidate[];
1070
+ disputed_by: RecoveryHelper[];
1071
+ }
1072
+ /** A recovery reconstructed one secret for `version`, but other helpers
1073
+ * hold valid shares of a different split that does not reconstruct.
1074
+ * `secret` is complete and self-consistent, rebuilt from the shares of
1075
+ * `supported_by`, and has the shape of `SecretRecovered.secret`. The
1076
+ * shares of `disputed_by` each pass their own proof but belong to another
1077
+ * split at the same version, which an honest sharing never produces.
1078
+ * Either side can be the owner's: colluding helpers can forge a complete
1079
+ * split, and the honest helpers may be too few to reconstruct theirs. The
1080
+ * library never picks: show the owner what `secret` holds and who stands
1081
+ * on each side, and pass `secret` to `restore` only once they confirm it.
1082
+ * The recovery is closed when this is emitted. */
1083
+ | {
1084
+ type: "RecoveryDisputed";
1085
+ version: number;
1086
+ secret: Extract<DeRecEvent, {
1087
+ type: "SecretRecovered";
1088
+ }>["secret"];
1089
+ supported_by: RecoveryHelper[];
1090
+ disputed_by: RecoveryHelper[];
1091
+ }
1092
+ /** A recovery of `(secret_id, version)` closed without reconstructing a
1093
+ * secret: every helper asked has answered, or the rest timed out, and no
1094
+ * collected shares reconstruct. `secret_id` and `version` name the
1095
+ * recovery that closed, since recoveries of several secrets can be open at
1096
+ * once. `shares_received` is the number of helpers whose shares were
1097
+ * collected. Start `RecoverSecret` again to retry. */
1098
+ | {
1099
+ type: "RecoveryIncomplete";
1100
+ secret_id: string;
1101
+ version: number;
1102
+ shares_received: number;
993
1103
  } | {
994
1104
  type: "Unpaired";
995
1105
  channel_id: string;
@@ -1336,7 +1446,10 @@ export type DeRecEvent = {
1336
1446
  * and the encrypted inner message's timestamp differ, or either is
1337
1447
  * absent. `"StaleResponse"` means a `VerifyShareResponse` answered an
1338
1448
  * earlier challenge that a newer one on the channel has replaced; the
1339
- * outstanding challenge is kept. `trace_id` matches the peer's
1449
+ * outstanding challenge is kept. `"Superseded"` means a
1450
+ * `StoreShareRequest` for a version older than the newest one this
1451
+ * helper stores on the channel, and not stored itself; it is not stored
1452
+ * and not answered. `trace_id` matches the peer's
1340
1453
  * `*Started` event for the same round (`"0"` when the sender set none). */
1341
1454
  | {
1342
1455
  type: "MessageIgnored";
@@ -1564,7 +1677,7 @@ export interface CommunicationInfo {
1564
1677
  }
1565
1678
  /** Why a `MessageIgnored` event dropped a message. Matches the Rust
1566
1679
  * `IgnoreReason` discriminants one-for-one. */
1567
- export type IgnoreReason = "PendingVerification" | "Expired" | "TimestampMismatch" | "StaleResponse";
1680
+ export type IgnoreReason = "PendingVerification" | "Expired" | "TimestampMismatch" | "StaleResponse" | "Superseded";
1568
1681
  /** Why a `PeerNotRestored` event left a roster entry without a channel.
1569
1682
  * Matches the Rust `NotRestoredReason` discriminants one-for-one. */
1570
1683
  export type NotRestoredReason = "NoTransports";
@@ -1576,9 +1689,9 @@ export type VerifyFailureReason = "NoSharedKey" | "NoProof" | "DispatchFailed";
1576
1689
  * Matches the Rust `CorruptionReason` discriminants one-for-one:
1577
1690
  * `Malformed` — no decodable share for the requested secret and version;
1578
1691
  * `InvalidProof` — the share fails its own Merkle proof;
1579
- * `Inconsistent` — valid on its own, but its commitment root or ciphertext
1580
- * disagrees with the shares the secret was rebuilt from. */
1581
- export type CorruptionReason = "Malformed" | "InvalidProof" | "Inconsistent";
1692
+ * `Forged` — its group reconstructs under one key, but not to a secret, or
1693
+ * a single share reconstructs alone; an honest split produces neither. */
1694
+ export type CorruptionReason = "Malformed" | "InvalidProof" | "Forged";
1582
1695
  /**
1583
1696
  * The label vocabulary for `ActionRequired.action_kind`,
1584
1697
  * `AutoAccepted.action_kind` and `RequestFailed.action_kind` — one value per
@@ -1936,3 +2049,10 @@ export interface UnpairingProcessResult {
1936
2049
  export interface DiscoveryProcessResult {
1937
2050
  secret_list: SecretVersionEntry[];
1938
2051
  }
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
@@ -38,6 +38,6 @@
38
38
  "typescript",
39
39
  "jsi"
40
40
  ],
41
- "version": "0.0.10",
41
+ "version": "0.0.11",
42
42
  "license": "Apache-2.0"
43
43
  }
Binary file
@@ -155,6 +155,11 @@ message ContactMessage {
155
155
  // )
156
156
  // ```
157
157
  //
158
+ // The keys are concatenated without their lengths, so the hash binds
159
+ // them only because each has a fixed size: 1568 bytes for the ML-KEM-1024
160
+ // encapsulation key and 65 bytes for the uncompressed secp256k1 point.
161
+ // Keys of any other size MUST be refused rather than hashed.
162
+ //
158
163
  // The recipient obtains the actual keys via `PrePairRequest` and
159
164
  // recomputes this hash to confirm integrity before proceeding to
160
165
  // `PairRequestMessage`.
@@ -239,6 +244,9 @@ message ContactMessage {
239
244
  // || mlkemEncapsulationKey || eciesPublicKey || fingerprintNonce)
240
245
  // ```
241
246
  //
247
+ // As in `contactBindingHash`, the keys are bound only by their fixed
248
+ // sizes, and keys of any other size MUST be refused.
249
+ //
242
250
  // Present, exactly 32 bytes, in `INLINE_KEYS` mode only. In
243
251
  // `HASHED_KEYS` and `NO_KEYS` mode the commitment travels with the keys,
244
252
  // in `PrePairResponseMessage.fingerprintCommitment`, and this field MUST
@@ -69,15 +69,31 @@ package org.derecalliance.derec.protobuf;
69
69
  // - detect duplicates or out-of-order delivery
70
70
  // - support replay protection
71
71
  //
72
- // These semantics are not yet implemented by this library: a sender may set
73
- // `sequence`, but it is not checked on receipt. Replay protection currently
74
- // relies on `timestamp`: an envelope older than the receiver's configured
75
- // inbound-message window is discarded. After decryption the receiver also
76
- // checks that `envelope.timestamp` equals the inner message's `timestamp`, and
77
- // discards the message if they differ or either is absent.
78
- //
79
- // Implementations SHOULD treat messages as idempotent and be resilient to
80
- // retries and duplicate deliveries.
72
+ // These semantics are not implemented by this library: a sender may set
73
+ // `sequence`, but it is not checked on receipt. An envelope older than the
74
+ // receiver's configured inbound-message window is discarded. After
75
+ // decryption the receiver also checks that `envelope.timestamp` equals the
76
+ // inner message's `timestamp`, and discards the message if they differ or
77
+ // either is absent.
78
+ //
79
+ // Within the window, detecting a message delivered more than once is the
80
+ // receiving application's transport layer's job. Both ends of a channel
81
+ // encrypt under one key, so a message delivered back to its own sender
82
+ // decrypts there too. The transport MUST:
83
+ //
84
+ // - identify an envelope by a hash of its `message` field only. `sequence`,
85
+ // `traceId` and the protocol version are not authenticated, and an
86
+ // envelope can be re-encoded, so a copy can arrive as different bytes;
87
+ // - keep the identity of every envelope it accepted and of every envelope
88
+ // it sent until the later of its arrival (or sending) and its `timestamp`,
89
+ // plus the inbound-message window, and drop an inbound envelope whose
90
+ // identity it keeps;
91
+ // - record an inbound identity only once the message was accepted.
92
+ //
93
+ // A message held back and delivered late is a first delivery and is not
94
+ // caught this way. A receiver MUST NOT store a share version older than the
95
+ // newest it stores on the channel, and SHOULD reject a channel-info update
96
+ // older than the last one it accepted on the channel.
81
97
  //
82
98
  // # Key Rotation
83
99
  //
@@ -123,6 +123,7 @@ message PrePairRequestMessage {
123
123
  // ```
124
124
  //
125
125
  // and verify it matches the original `ContactMessage.contactBindingHash`.
126
+ // Keys whose sizes are not the fixed ones count as a mismatch.
126
127
  // - Only on a match, proceed to construct and send a normal
127
128
  // `PairRequestMessage`.
128
129
  //
package/src/errors.ts CHANGED
@@ -32,6 +32,7 @@ export const DEREC_ERROR_CATEGORIES = [
32
32
  "protobuf",
33
33
  "invariant",
34
34
  "state_store",
35
+ "transport",
35
36
  ] as const;
36
37
 
37
38
  export type DeRecErrorCategory = (typeof DEREC_ERROR_CATEGORIES)[number];
@@ -76,6 +77,7 @@ export const DEREC_ERROR_CODES = [
76
77
  "unexpected_replica_id",
77
78
  "incompatible_parameter_range",
78
79
  "fingerprint_commitment_mismatch",
80
+ "pairing_expired",
79
81
  "empty_channels",
80
82
  "duplicate_channel_id",
81
83
  "invalid_threshold",
@@ -100,6 +102,7 @@ export const DEREC_ERROR_CODES = [
100
102
  "ffi_nul_in_string",
101
103
  "transport_invalid",
102
104
  "no_usable_endpoint",
105
+ "transport_send_failed",
103
106
  ] as const;
104
107
 
105
108
  export type DeRecErrorCode = (typeof DEREC_ERROR_CODES)[number];
@@ -119,7 +122,12 @@ export interface DeRecError {
119
122
  * Clear exactly these and retry `restore`.
120
123
  */
121
124
  channel_ids?: string[];
122
- /** The channel the failing inbound message arrived on, when `process()` could tell. */
125
+ /**
126
+ * The channel the error is about: the one named by
127
+ * `"channel_already_paired"`, `"fingerprint_mismatch"` and
128
+ * `"role_mismatch"`, or, on a failed `process()`, the channel the failing
129
+ * inbound message arrived on.
130
+ */
123
131
  channel_id?: string;
124
132
  /**
125
133
  * On a failed `process()`: the events it produced before failing, such as
package/src/primitives.ts CHANGED
@@ -44,6 +44,7 @@ import type {
44
44
  GetSecretIdsVersionsResponseMessage,
45
45
  GetShareRequestMessage,
46
46
  GetShareResponseMessage,
47
+ MessageId,
47
48
  PairRequestMessage,
48
49
  PairResponseMessage,
49
50
  PairingProcessResult,
@@ -895,4 +896,20 @@ export const envelope = {
895
896
  read_trace_id(envelope_bytes: Uint8Array): bigint {
896
897
  return call('read_trace_id_from_envelope', envelope_bytes) as bigint;
897
898
  },
899
+ /**
900
+ * Identify an envelope for replay and reflection detection. `id` is the
901
+ * same for every copy of one message, whatever its unauthenticated
902
+ * cleartext fields say, and different for every other message. Keep the
903
+ * `id` of every envelope sent and of every envelope `process` accepted
904
+ * until `max(received or sent at, timestamp) + inbound_message_secs`, keep
905
+ * the record across restarts, and drop an inbound envelope whose `id` is
906
+ * kept. The README has the full contract.
907
+ */
908
+ message_id(envelope_bytes: Uint8Array): MessageId {
909
+ const result = call('message_id_from_envelope', envelope_bytes) as {
910
+ id: ArrayBuffer;
911
+ timestamp: bigint;
912
+ };
913
+ return { id: bytes(result.id), timestamp: result.timestamp };
914
+ },
898
915
  };
package/src/types.ts CHANGED
@@ -833,6 +833,24 @@ export interface Timeouts {
833
833
  /** How long to wait for an unpair acknowledgement before dropping local
834
834
  * channel state anyway. Library default: 60. */
835
835
  unpair_ack_secs?: number;
836
+ /** How long a recovery waits for a helper to answer its share request. A
837
+ * recovery decides only once every helper it asked has answered or this
838
+ * has elapsed since the requests went out; each silent helper is then
839
+ * reported as `RecoverSecretFailed` with error `"timeout"`. The budget is
840
+ * a **human** one when helpers approve share requests by hand. The same
841
+ * budget bounds a replica version check (`FlowKind.ReplicaDiscovery`):
842
+ * once it elapses, the check concludes on the versions already reported.
843
+ * Library default: 300. */
844
+ get_share_response_secs?: number;
845
+ /** How long a pairing stays possible: how old a contact may be when it is
846
+ * scanned or answered, and how old a pairing request may be when it is
847
+ * accepted. Both sides enforce it and nothing is sent on expiry: the
848
+ * scanner refuses an expired contact, and the creator ignores a request on
849
+ * one and refuses a late accept, with `pairing_expired`. The remedy is to
850
+ * scan or share a fresh contact. A scanner's `expired_channels` timeout
851
+ * should be at least this plus the time a response takes to arrive.
852
+ * Library default: 30. */
853
+ pairing_secs?: number;
836
854
  /** Removal of channels still awaiting out-of-band fingerprint
837
855
  * confirmation — every replica pairing, and every `NoKeys` pairing.
838
856
  * Unlike the others this can be disabled, leaving the sweep to the
@@ -854,7 +872,13 @@ export type ReplicaDiscoveryParams = Record<string, never>;
854
872
  * member is not asked and gets no event when told to leave: when a roster
855
873
  * excluding it arrives it drops its whole `secret_id` partition and emits
856
874
  * `SelfRemovedFromGroup`. The secret survives on the remaining members and
857
- * the helpers. */
875
+ * the helpers.
876
+ *
877
+ * Removal does not replace the group key, so it relies on the removed
878
+ * device's library deleting its copy. That covers a lost or stolen device
879
+ * whose storage was not read. Whoever read a device's storage keeps the
880
+ * group key and can decrypt every later publication it obtains, the one
881
+ * completing the removal included. */
858
882
  export interface UnpairReplicaParams {
859
883
  /** The member to remove, as a **decimal** `u64` string — the same form
860
884
  * `ReplicaPaired.peer_replica_id` hands back. A value naming no current
@@ -864,6 +888,26 @@ export interface UnpairReplicaParams {
864
888
  memo?: string;
865
889
  }
866
890
 
891
+ /** A helper named by a recovery decision (`RecoveryDisputed`,
892
+ * `RecoveryConflict`), so the app can tell the owner who is on each side.
893
+ * `channel_id` is the `u64` as a **decimal** string; `communication_info`
894
+ * is what the helper advertised when it paired, read from its channel
895
+ * record, and is absent when it advertised none. */
896
+ export interface RecoveryHelper {
897
+ channel_id: string;
898
+ communication_info?: Record<string, string>;
899
+ }
900
+
901
+ /** One secret a recovery reconstructed, reported in `RecoveryConflict`.
902
+ * `secret` has the shape of `SecretRecovered.secret`, so a confirmed
903
+ * candidate is passed to `restore` the same way. `supported_by` are the
904
+ * helpers whose shares reconstruct it, in the order their shares were
905
+ * collected. */
906
+ export interface RecoveryCandidate {
907
+ secret: Extract<DeRecEvent, { type: "SecretRecovered" }>["secret"];
908
+ supported_by: RecoveryHelper[];
909
+ }
910
+
867
911
  export type DeRecEvent =
868
912
  | {
869
913
  type: "PairingCompleted";
@@ -917,6 +961,11 @@ export type DeRecEvent =
917
961
  * from the application's own share store does not raise it. */
918
962
  | { type: "ShareRefused"; channel_id: string; version: number; status: StatusEnum; memo: string }
919
963
  | { type: "ShareConfirmed"; channel_id: string; version: number }
964
+ /** A helper rejected or failed to store our share. `status` and `memo`
965
+ * come from the helper's response, except for a helper that did not
966
+ * answer within `timeouts.sharing_round_secs`: `tick()` then reports it
967
+ * with status `FAIL` and memo `"timeout"`. The memo of a helper's own
968
+ * answer is free text and can read the same. */
920
969
  | { type: "ShareRejected"; channel_id: string; version: number; status: StatusEnum; memo: string }
921
970
  /** A publishing round finished — every targeted helper confirmed,
922
971
  * rejected, or timed out.
@@ -948,8 +997,12 @@ export type DeRecEvent =
948
997
  status: StatusEnum;
949
998
  memo: string;
950
999
  }
951
- /** A secret sync could not be delivered to a member at all — distinct from
952
- * `ReplicaSyncRejected`, which is the member answering "no". */
1000
+ /** A secret sync could not be delivered to a member, or the member did not
1001
+ * acknowledge it within `timeouts.sharing_round_secs` — distinct from
1002
+ * `ReplicaSyncRejected`, which is the member answering "no". `reason` is
1003
+ * `"timeout"` when the member did not acknowledge in time (reported by
1004
+ * `tick()`); otherwise the transport or encoding failure, rendered for
1005
+ * display. */
953
1006
  | { type: "ReplicaSyncFailed"; replica_id: string; version: number; reason: string }
954
1007
  /** A member left the group and its roster row was dropped. Fires on the
955
1008
  * members that remain. */
@@ -1003,25 +1056,36 @@ export type DeRecEvent =
1003
1056
 
1004
1057
  secrets: Array<{ secret_id: string; versions: Array<{ version: number; description: string }> }>;
1005
1058
  }
1059
+ /** A helper's share was collected for a recovery. Nothing is
1060
+ * reconstructed until every helper asked has answered or
1061
+ * `timeouts.get_share_response_secs` has passed since the requests went
1062
+ * out (each silent helper is then reported as `RecoverSecretFailed` with
1063
+ * error `"timeout"`). The recovery then decides exactly once:
1064
+ * `SecretRecovered`, `RecoveryDisputed`, `RecoveryConflict` or
1065
+ * `RecoveryIncomplete`. */
1006
1066
  | { type: "RecoveryShareReceived"; channel_id: string; shares_received: number }
1007
- | { type: "RecoveryShareError"; channel_id: string; shares_received: number; error: string }
1008
1067
  /** A helper refused a recovery share request: its response carried a
1009
1068
  * non-OK `status` (e.g. `UNKNOWN_SHARE_VERSION`) instead of a share. The
1010
- * refusal is not collected — it does not count towards `shares_received`
1011
- * and the recovery stays open for the other helpers' shares — but it does
1012
- * answer that helper's `RecoverSecretStarted`. */
1069
+ * refusal is not collected and does not count towards `shares_received`,
1070
+ * but it is that helper's answer: it answers the helper's
1071
+ * `RecoverSecretStarted`, and when it is the last answer due the recovery
1072
+ * decides on the shares it holds. */
1013
1073
  | { type: "RecoveryShareRefused"; channel_id: string; version: number; status: StatusEnum; memo: string }
1014
1074
  /** A helper answered with a share that cannot be part of the secret;
1015
1075
  * `reason` says how it failed. `Malformed` and `InvalidProof` are judged
1016
- * on arrival; `Inconsistent` (valid on its own but disagreeing with the
1017
- * shares the secret was rebuilt from) is reported alongside
1018
- * `SecretRecovered`, once per helper. The share is set aside — it does
1019
- * not count towards `shares_received` and never blocks the recovery. An
1020
- * honest helper never sends one, so the app may treat it as a sign of a
1021
- * damaged or compromised helper, e.g. offer to unpair it. It also
1022
- * answers that helper's `RecoverSecretStarted`. */
1076
+ * on arrival and count as that helper's answer; `Forged` (its group
1077
+ * reconstructs under one key, but not to a secret, or a single share
1078
+ * reconstructs alone) is reported with the recovery's decision, once per
1079
+ * helper. The share is set aside — it does not count towards
1080
+ * `shares_received` and never blocks the recovery. An honest helper never
1081
+ * sends one, so the app may treat it as a sign of a damaged or
1082
+ * compromised helper, e.g. offer to unpair it. A share that only
1083
+ * disagrees with the others is never reported here: it is a dispute
1084
+ * (`RecoveryDisputed` / `RecoveryConflict`), not evidence against its
1085
+ * helper. It also answers that helper's `RecoverSecretStarted`. */
1023
1086
  | { type: "RecoveryShareCorrupted"; channel_id: string; version: number; reason: CorruptionReason }
1024
- /** Recovery completed — the typed `Secret` snapshot the owner
1087
+ /** Recovery completed — one secret reconstructed and every collected
1088
+ * share is part of it. `secret` is the typed `Secret` snapshot the owner
1025
1089
  * originally protected. Mirrors `ReplicaSecretReceived.secret`:
1026
1090
  * `secrets` is the user-facing `Vec<UserSecret>` the application
1027
1091
  * fed to `start(FlowKind.ProtectSecret)`; `helpers` and `replicas`
@@ -1073,6 +1137,47 @@ export type DeRecEvent =
1073
1137
  threshold?: number;
1074
1138
  };
1075
1139
  }
1140
+ /** A recovery reconstructed two or more different secrets for `version`,
1141
+ * so it cannot tell which is the owner's. Each candidate is a complete,
1142
+ * self-consistent secret, rebuilt from the shares of the helpers in its
1143
+ * `supported_by`. Fewer than the threshold of colluding helpers can forge
1144
+ * one, so the library never picks: involve the owner and pass the
1145
+ * candidate's `secret` they confirm to `restore`, exactly as the `secret`
1146
+ * of `SecretRecovered`. The helpers backing a rejected candidate are
1147
+ * suspect. `disputed_by` names the helpers holding valid shares of yet
1148
+ * another split that does not reconstruct, so no helper's answer goes
1149
+ * unshown. The recovery is closed when this is emitted. */
1150
+ | {
1151
+ type: "RecoveryConflict";
1152
+ version: number;
1153
+ candidates: RecoveryCandidate[];
1154
+ disputed_by: RecoveryHelper[];
1155
+ }
1156
+ /** A recovery reconstructed one secret for `version`, but other helpers
1157
+ * hold valid shares of a different split that does not reconstruct.
1158
+ * `secret` is complete and self-consistent, rebuilt from the shares of
1159
+ * `supported_by`, and has the shape of `SecretRecovered.secret`. The
1160
+ * shares of `disputed_by` each pass their own proof but belong to another
1161
+ * split at the same version, which an honest sharing never produces.
1162
+ * Either side can be the owner's: colluding helpers can forge a complete
1163
+ * split, and the honest helpers may be too few to reconstruct theirs. The
1164
+ * library never picks: show the owner what `secret` holds and who stands
1165
+ * on each side, and pass `secret` to `restore` only once they confirm it.
1166
+ * The recovery is closed when this is emitted. */
1167
+ | {
1168
+ type: "RecoveryDisputed";
1169
+ version: number;
1170
+ secret: Extract<DeRecEvent, { type: "SecretRecovered" }>["secret"];
1171
+ supported_by: RecoveryHelper[];
1172
+ disputed_by: RecoveryHelper[];
1173
+ }
1174
+ /** A recovery of `(secret_id, version)` closed without reconstructing a
1175
+ * secret: every helper asked has answered, or the rest timed out, and no
1176
+ * collected shares reconstruct. `secret_id` and `version` name the
1177
+ * recovery that closed, since recoveries of several secrets can be open at
1178
+ * once. `shares_received` is the number of helpers whose shares were
1179
+ * collected. Start `RecoverSecret` again to retry. */
1180
+ | { type: "RecoveryIncomplete"; secret_id: string; version: number; shares_received: number }
1076
1181
 
1077
1182
  | { type: "Unpaired"; channel_id: string }
1078
1183
 
@@ -1401,7 +1506,10 @@ export type DeRecEvent =
1401
1506
  * and the encrypted inner message's timestamp differ, or either is
1402
1507
  * absent. `"StaleResponse"` means a `VerifyShareResponse` answered an
1403
1508
  * earlier challenge that a newer one on the channel has replaced; the
1404
- * outstanding challenge is kept. `trace_id` matches the peer's
1509
+ * outstanding challenge is kept. `"Superseded"` means a
1510
+ * `StoreShareRequest` for a version older than the newest one this
1511
+ * helper stores on the channel, and not stored itself; it is not stored
1512
+ * and not answered. `trace_id` matches the peer's
1405
1513
  * `*Started` event for the same round (`"0"` when the sender set none). */
1406
1514
  | {
1407
1515
  type: "MessageIgnored";
@@ -1603,7 +1711,7 @@ export interface CommunicationInfo {
1603
1711
 
1604
1712
  /** Why a `MessageIgnored` event dropped a message. Matches the Rust
1605
1713
  * `IgnoreReason` discriminants one-for-one. */
1606
- export type IgnoreReason = "PendingVerification" | "Expired" | "TimestampMismatch" | "StaleResponse";
1714
+ export type IgnoreReason = "PendingVerification" | "Expired" | "TimestampMismatch" | "StaleResponse" | "Superseded";
1607
1715
 
1608
1716
  /** Why a `PeerNotRestored` event left a roster entry without a channel.
1609
1717
  * Matches the Rust `NotRestoredReason` discriminants one-for-one. */
@@ -1618,9 +1726,9 @@ export type VerifyFailureReason = "NoSharedKey" | "NoProof" | "DispatchFailed";
1618
1726
  * Matches the Rust `CorruptionReason` discriminants one-for-one:
1619
1727
  * `Malformed` — no decodable share for the requested secret and version;
1620
1728
  * `InvalidProof` — the share fails its own Merkle proof;
1621
- * `Inconsistent` — valid on its own, but its commitment root or ciphertext
1622
- * disagrees with the shares the secret was rebuilt from. */
1623
- export type CorruptionReason = "Malformed" | "InvalidProof" | "Inconsistent";
1729
+ * `Forged` — its group reconstructs under one key, but not to a secret, or
1730
+ * a single share reconstructs alone; an honest split produces neither. */
1731
+ export type CorruptionReason = "Malformed" | "InvalidProof" | "Forged";
1624
1732
 
1625
1733
  /**
1626
1734
  * The label vocabulary for `ActionRequired.action_kind`,
@@ -2041,3 +2149,11 @@ export interface UnpairingProcessResult {
2041
2149
  export interface DiscoveryProcessResult {
2042
2150
  secret_list: SecretVersionEntry[];
2043
2151
  }
2152
+
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
+ }