@derec-alliance/react-native 0.0.10 → 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/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
  ];
@@ -131,4 +131,26 @@ 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
+ * 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.
154
+ */
155
+ encrypted_payload(envelope_bytes: Uint8Array): Uint8Array;
134
156
  };
package/lib/primitives.js CHANGED
@@ -403,4 +403,28 @@ exports.envelope = {
403
403
  read_trace_id(envelope_bytes) {
404
404
  return call('read_trace_id_from_envelope', envelope_bytes);
405
405
  },
406
+ /**
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.
426
+ */
427
+ encrypted_payload(envelope_bytes) {
428
+ return bytes(call('encrypted_payload_from_envelope', envelope_bytes));
429
+ },
406
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 `true` and publishes nothing. Call
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
@@ -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
@@ -694,11 +712,19 @@ export type ReplicaDiscoveryParams = Record<string, never>;
694
712
  * source must be removable by the devices that remain, and the library
695
713
  * checks no role. Ask the user before starting this flow, above all when it
696
714
  * names the source. Removing the source promotes the first remaining member
697
- * in the order the channel store's `listReplicas` returns. The removed
698
- * member is not asked and gets no event when told to leave: when a roster
699
- * excluding it arrives it drops its whole `secret_id` partition and emits
700
- * `SelfRemovedFromGroup`. The secret survives on the remaining members and
701
- * the helpers. */
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.
722
+ *
723
+ * Removal does not replace the group key, so it relies on the removed
724
+ * device's library deleting its copy. That covers a lost or stolen device
725
+ * whose storage was not read. Whoever read a device's storage keeps the
726
+ * group key and can decrypt every later publication it obtains, the one
727
+ * completing the removal included. */
702
728
  export interface UnpairReplicaParams {
703
729
  /** The member to remove, as a **decimal** `u64` string — the same form
704
730
  * `ReplicaPaired.peer_replica_id` hands back. A value naming no current
@@ -706,6 +732,26 @@ export interface UnpairReplicaParams {
706
732
  replica_id: string;
707
733
  memo?: string;
708
734
  }
735
+ /** A helper named by a recovery decision (`RecoveryDisputed`,
736
+ * `RecoveryConflict`), so the app can tell the owner who is on each side.
737
+ * `channel_id` is the `u64` as a **decimal** string; `communication_info`
738
+ * is what the helper advertised when it paired, read from its channel
739
+ * record, and is absent when it advertised none. */
740
+ export interface RecoveryHelper {
741
+ channel_id: string;
742
+ communication_info?: Record<string, string>;
743
+ }
744
+ /** One secret a recovery reconstructed, reported in `RecoveryConflict`.
745
+ * `secret` has the shape of `SecretRecovered.secret`, so a confirmed
746
+ * candidate is passed to `restore` the same way. `supported_by` are the
747
+ * helpers whose shares reconstruct it, in the order their shares were
748
+ * collected. */
749
+ export interface RecoveryCandidate {
750
+ secret: Extract<DeRecEvent, {
751
+ type: "SecretRecovered";
752
+ }>["secret"];
753
+ supported_by: RecoveryHelper[];
754
+ }
709
755
  export type DeRecEvent = {
710
756
  type: "PairingCompleted";
711
757
  /** Long-term `channel_id` both peers atomically rotated to at handshake completion. */
@@ -766,7 +812,13 @@ export type DeRecEvent = {
766
812
  type: "ShareConfirmed";
767
813
  channel_id: string;
768
814
  version: number;
769
- } | {
815
+ }
816
+ /** A helper rejected or failed to store our share. `status` and `memo`
817
+ * come from the helper's response, except for a helper that did not
818
+ * answer within `timeouts.sharing_round_secs`: `tick()` then reports it
819
+ * with status `FAIL` and memo `"timeout"`. The memo of a helper's own
820
+ * answer is free text and can read the same. */
821
+ | {
770
822
  type: "ShareRejected";
771
823
  channel_id: string;
772
824
  version: number;
@@ -809,8 +861,12 @@ export type DeRecEvent = {
809
861
  status: StatusEnum;
810
862
  memo: string;
811
863
  }
812
- /** A secret sync could not be delivered to a member at all — distinct from
813
- * `ReplicaSyncRejected`, which is the member answering "no". */
864
+ /** A secret sync could not be delivered to a member, or the member did not
865
+ * acknowledge it within `timeouts.sharing_round_secs` — distinct from
866
+ * `ReplicaSyncRejected`, which is the member answering "no". `reason` is
867
+ * `"timeout"` when the member did not acknowledge in time (reported by
868
+ * `tick()`); otherwise the transport or encoding failure, rendered for
869
+ * display. */
814
870
  | {
815
871
  type: "ReplicaSyncFailed";
816
872
  replica_id: string;
@@ -818,7 +874,9 @@ export type DeRecEvent = {
818
874
  reason: string;
819
875
  }
820
876
  /** A member left the group and its roster row was dropped. Fires on the
821
- * members that remain. */
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. */
822
880
  | {
823
881
  type: "ReplicaRemoved";
824
882
  replica_id: string;
@@ -833,9 +891,11 @@ export type DeRecEvent = {
833
891
  }
834
892
  /** This device left the group and dropped its whole `secret_id` partition —
835
893
  * group channel, helper channels, shares, secrets and the snapshot. Fires
836
- * only once it was told to leave *and* has since seen a roster excluding
837
- * it; absence alone never destroys a copy of the secret. The teardown is
838
- * automatic: this device is not asked first and gets no earlier event. */
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. */
839
899
  | {
840
900
  type: "SelfRemovedFromGroup";
841
901
  version: number;
@@ -902,21 +962,25 @@ export type DeRecEvent = {
902
962
  description: string;
903
963
  }>;
904
964
  }>;
905
- } | {
965
+ }
966
+ /** A helper's share was collected for a recovery. Nothing is
967
+ * reconstructed until every helper asked has answered or
968
+ * `timeouts.get_share_response_secs` has passed since the requests went
969
+ * out (each silent helper is then reported as `RecoverSecretFailed` with
970
+ * error `"timeout"`). The recovery then decides exactly once:
971
+ * `SecretRecovered`, `RecoveryDisputed`, `RecoveryConflict` or
972
+ * `RecoveryIncomplete`. */
973
+ | {
906
974
  type: "RecoveryShareReceived";
907
975
  channel_id: string;
908
976
  shares_received: number;
909
- } | {
910
- type: "RecoveryShareError";
911
- channel_id: string;
912
- shares_received: number;
913
- error: string;
914
977
  }
915
978
  /** A helper refused a recovery share request: its response carried a
916
979
  * 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`. */
980
+ * refusal is not collected and does not count towards `shares_received`,
981
+ * but it is that helper's answer: it answers the helper's
982
+ * `RecoverSecretStarted`, and when it is the last answer due the recovery
983
+ * decides on the shares it holds. */
920
984
  | {
921
985
  type: "RecoveryShareRefused";
922
986
  channel_id: string;
@@ -926,20 +990,24 @@ export type DeRecEvent = {
926
990
  }
927
991
  /** A helper answered with a share that cannot be part of the secret;
928
992
  * `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`. */
993
+ * on arrival and count as that helper's answer; `Forged` (its group
994
+ * reconstructs under one key, but not to a secret, or a single share
995
+ * reconstructs alone) is reported with the recovery's decision, once per
996
+ * helper. The share is set aside — it does not count towards
997
+ * `shares_received` and never blocks the recovery. An honest helper never
998
+ * sends one, so the app may treat it as a sign of a damaged or
999
+ * compromised helper, e.g. offer to unpair it. A share that only
1000
+ * disagrees with the others is never reported here: it is a dispute
1001
+ * (`RecoveryDisputed` / `RecoveryConflict`), not evidence against its
1002
+ * helper. It also answers that helper's `RecoverSecretStarted`. */
936
1003
  | {
937
1004
  type: "RecoveryShareCorrupted";
938
1005
  channel_id: string;
939
1006
  version: number;
940
1007
  reason: CorruptionReason;
941
1008
  }
942
- /** Recovery completed — the typed `Secret` snapshot the owner
1009
+ /** Recovery completed — one secret reconstructed and every collected
1010
+ * share is part of it. `secret` is the typed `Secret` snapshot the owner
943
1011
  * originally protected. Mirrors `ReplicaSecretReceived.secret`:
944
1012
  * `secrets` is the user-facing `Vec<UserSecret>` the application
945
1013
  * fed to `start(FlowKind.ProtectSecret)`; `helpers` and `replicas`
@@ -990,6 +1058,54 @@ export type DeRecEvent = {
990
1058
  * `threshold` on `start(ProtectSecret)`. */
991
1059
  threshold?: number;
992
1060
  };
1061
+ }
1062
+ /** A recovery reconstructed two or more different secrets for `version`,
1063
+ * so it cannot tell which is the owner's. Each candidate is a complete,
1064
+ * self-consistent secret, rebuilt from the shares of the helpers in its
1065
+ * `supported_by`. Fewer than the threshold of colluding helpers can forge
1066
+ * one, so the library never picks: involve the owner and pass the
1067
+ * candidate's `secret` they confirm to `restore`, exactly as the `secret`
1068
+ * of `SecretRecovered`. The helpers backing a rejected candidate are
1069
+ * suspect. `disputed_by` names the helpers holding valid shares of yet
1070
+ * another split that does not reconstruct, so no helper's answer goes
1071
+ * unshown. The recovery is closed when this is emitted. */
1072
+ | {
1073
+ type: "RecoveryConflict";
1074
+ version: number;
1075
+ candidates: RecoveryCandidate[];
1076
+ disputed_by: RecoveryHelper[];
1077
+ }
1078
+ /** A recovery reconstructed one secret for `version`, but other helpers
1079
+ * hold valid shares of a different split that does not reconstruct.
1080
+ * `secret` is complete and self-consistent, rebuilt from the shares of
1081
+ * `supported_by`, and has the shape of `SecretRecovered.secret`. The
1082
+ * shares of `disputed_by` each pass their own proof but belong to another
1083
+ * split at the same version, which an honest sharing never produces.
1084
+ * Either side can be the owner's: colluding helpers can forge a complete
1085
+ * split, and the honest helpers may be too few to reconstruct theirs. The
1086
+ * library never picks: show the owner what `secret` holds and who stands
1087
+ * on each side, and pass `secret` to `restore` only once they confirm it.
1088
+ * The recovery is closed when this is emitted. */
1089
+ | {
1090
+ type: "RecoveryDisputed";
1091
+ version: number;
1092
+ secret: Extract<DeRecEvent, {
1093
+ type: "SecretRecovered";
1094
+ }>["secret"];
1095
+ supported_by: RecoveryHelper[];
1096
+ disputed_by: RecoveryHelper[];
1097
+ }
1098
+ /** A recovery of `(secret_id, version)` closed without reconstructing a
1099
+ * secret: every helper asked has answered, or the rest timed out, and no
1100
+ * collected shares reconstruct. `secret_id` and `version` name the
1101
+ * recovery that closed, since recoveries of several secrets can be open at
1102
+ * once. `shares_received` is the number of helpers whose shares were
1103
+ * collected. Start `RecoverSecret` again to retry. */
1104
+ | {
1105
+ type: "RecoveryIncomplete";
1106
+ secret_id: string;
1107
+ version: number;
1108
+ shares_received: number;
993
1109
  } | {
994
1110
  type: "Unpaired";
995
1111
  channel_id: string;
@@ -1336,8 +1452,18 @@ export type DeRecEvent = {
1336
1452
  * and the encrypted inner message's timestamp differ, or either is
1337
1453
  * absent. `"StaleResponse"` means a `VerifyShareResponse` answered an
1338
1454
  * earlier challenge that a newer one on the channel has replaced; the
1339
- * outstanding challenge is kept. `trace_id` matches the peer's
1340
- * `*Started` event for the same round (`"0"` when the sender set none). */
1455
+ * outstanding challenge is kept. `"Superseded"` means a
1456
+ * `StoreShareRequest` for a version older than the newest one this
1457
+ * helper stores on the channel, and not stored itself; it is not stored
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). */
1341
1467
  | {
1342
1468
  type: "MessageIgnored";
1343
1469
  channel_id: string;
@@ -1438,7 +1564,9 @@ export type DeRecEvent = {
1438
1564
  * `UnpairAck.Required` the channel is now `"Unpairing"`, and an
1439
1565
  * `Unpaired` event follows once the peer acknowledges or the
1440
1566
  * acknowledgement window elapses, or `UnpairRejected` if the peer
1441
- * refuses (the channel is `"Paired"` again). Under
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
1442
1570
  * `UnpairAck.NotRequired`, `Unpaired` follows in the same event vec. */
1443
1571
  | {
1444
1572
  type: "UnpairFailed";
@@ -1564,7 +1692,7 @@ export interface CommunicationInfo {
1564
1692
  }
1565
1693
  /** Why a `MessageIgnored` event dropped a message. Matches the Rust
1566
1694
  * `IgnoreReason` discriminants one-for-one. */
1567
- export type IgnoreReason = "PendingVerification" | "Expired" | "TimestampMismatch" | "StaleResponse";
1695
+ export type IgnoreReason = "PendingVerification" | "Expired" | "TimestampMismatch" | "StaleResponse" | "Superseded" | "ProtocolVersionTooOld" | "ProtocolVersionMismatch";
1568
1696
  /** Why a `PeerNotRestored` event left a roster entry without a channel.
1569
1697
  * Matches the Rust `NotRestoredReason` discriminants one-for-one. */
1570
1698
  export type NotRestoredReason = "NoTransports";
@@ -1576,9 +1704,9 @@ export type VerifyFailureReason = "NoSharedKey" | "NoProof" | "DispatchFailed";
1576
1704
  * Matches the Rust `CorruptionReason` discriminants one-for-one:
1577
1705
  * `Malformed` — no decodable share for the requested secret and version;
1578
1706
  * `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";
1707
+ * `Forged` — its group reconstructs under one key, but not to a secret, or
1708
+ * a single share reconstructs alone; an honest split produces neither. */
1709
+ export type CorruptionReason = "Malformed" | "InvalidProof" | "Forged";
1582
1710
  /**
1583
1711
  * The label vocabulary for `ActionRequired.action_kind`,
1584
1712
  * `AutoAccepted.action_kind` and `RequestFailed.action_kind` — one value per
@@ -1666,7 +1794,8 @@ export interface DeRecAutoAcceptConfig {
1666
1794
  * "unsafe_connection": false,
1667
1795
  * "communication_info": { "name": "alice" },
1668
1796
  * "own_transports": [{ "uri": "https://me.example.com/derec", "protocol": "https" }],
1669
- * "replica_id": "9007199254740993"
1797
+ * "replica_id": "9007199254740993",
1798
+ * "min_protocol_version": { "major": 0, "minor": 1 }
1670
1799
  * }
1671
1800
  * ```
1672
1801
  */
@@ -1689,6 +1818,10 @@ export interface DeRecProtocolConfig {
1689
1818
  /** Decimal string. A `bigint` is rejected; call
1690
1819
  * `DeRecProtocolBuilder.withReplicaId` directly for a `bigint`. */
1691
1820
  replica_id?: string;
1821
+ min_protocol_version?: {
1822
+ major: number;
1823
+ minor: number;
1824
+ };
1692
1825
  }
1693
1826
  export interface PairRequestMessage {
1694
1827
  sender_kind: number;
package/package.json CHANGED
@@ -38,6 +38,6 @@
38
38
  "typescript",
39
39
  "jsi"
40
40
  ],
41
- "version": "0.0.10",
41
+ "version": "0.1.0",
42
42
  "license": "Apache-2.0"
43
43
  }
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
- // because they must be serialized together with the share so that they
62
- // are covered by the same signature.
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).
@@ -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`.
@@ -225,10 +230,11 @@ message ContactMessage {
225
230
  // `contactBindingHash` does not cover this field. An attacker able to
226
231
  // rewrite an out-of-band contact can therefore remove entries. Removing
227
232
  // the secure ones leaves only plaintext, which the recipient's transport
228
- // policy refuses unless plaintext has been explicitly opted into. DeRec
229
- // messages are signed and encrypted at the application layer on every
230
- // transport, so substituting one secure transport for another is not a
231
- // loss of confidentiality or authenticity.
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.
232
238
  repeated TransportProtocol supportedTransports = 9;
233
239
 
234
240
  // The creator's commitment to the fingerprint nonce it reveals in
@@ -239,6 +245,9 @@ message ContactMessage {
239
245
  // || mlkemEncapsulationKey || eciesPublicKey || fingerprintNonce)
240
246
  // ```
241
247
  //
248
+ // As in `contactBindingHash`, the keys are bound only by their fixed
249
+ // sizes, and keys of any other size MUST be refused.
250
+ //
242
251
  // Present, exactly 32 bytes, in `INLINE_KEYS` mode only. In
243
252
  // `HASHED_KEYS` and `NO_KEYS` mode the commitment travels with the keys,
244
253
  // 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.
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
78
  //
79
- // Implementations SHOULD treat messages as idempotent and be resilient to
80
- // retries and duplicate deliveries.
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
+ // and `traceId` are not authenticated, and an envelope can be re-encoded,
86
+ // 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
  //
@@ -130,6 +146,11 @@ message DeRecMessage {
130
146
  // Not yet implemented by this library: a sender may set this field, but it
131
147
  // is not checked on receipt, and it does not trigger key rotation. Replay
132
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.
133
154
  uint32 sequence = 3;
134
155
 
135
156
  // Channel identifier associated with this communication session.
@@ -161,12 +182,11 @@ message DeRecMessage {
161
182
 
162
183
  // Encrypted message payload.
163
184
  //
164
- // This field contains the encrypted bytes of a serialized MessageBody.
165
- // The encryption scheme and key material are defined by the pairing process
166
- // and subsequent key management flows.
167
- //
168
- // Upon decryption, this field MUST deserialize into a valid MessageBody
169
- // 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.
170
190
  bytes message = 6;
171
191
 
172
192
  // Application-supplied correlation token, echoed verbatim by the
@@ -230,3 +250,30 @@ message DeRecMessage {
230
250
  }
231
251
  }
232
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
+ }