@derec-alliance/react-native 0.0.9 → 0.0.10

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.
Files changed (47) hide show
  1. package/README.md +20 -7
  2. package/android/src/main/jniLibs/arm64-v8a/libderec_library.a +0 -0
  3. package/android/src/main/jniLibs/armeabi-v7a/libderec_library.a +0 -0
  4. package/android/src/main/jniLibs/x86_64/libderec_library.a +0 -0
  5. package/cpp/Primitives.cpp +13 -7
  6. package/cpp/ProtocolHost.cpp +4 -5
  7. package/cpp/StoreCallbacks.cpp +31 -43
  8. package/cpp/derec_ffi.h +44 -33
  9. package/ios/DeRecFFI.xcframework/Info.plist +5 -5
  10. package/ios/DeRecFFI.xcframework/ios-arm64/Headers/derec_ffi.h +44 -33
  11. package/ios/DeRecFFI.xcframework/ios-arm64/libderec_library.a +0 -0
  12. package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/Headers/derec_ffi.h +44 -33
  13. package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/libderec_library.a +2 -2
  14. package/lib/errors.d.ts +1 -1
  15. package/lib/errors.js +3 -0
  16. package/lib/messages.js +5 -3
  17. package/lib/primitives.d.ts +1 -1
  18. package/lib/primitives.js +4 -2
  19. package/lib/protocol.d.ts +9 -5
  20. package/lib/protocol.js +9 -5
  21. package/lib/types.d.ts +48 -20
  22. package/lib/types.js +4 -1
  23. package/package.json +4 -17
  24. package/schema/derec_descriptor.bin +0 -0
  25. package/schema/proto/committedderecshare.proto +93 -0
  26. package/schema/proto/communicationinfo.proto +104 -0
  27. package/schema/proto/contact.proto +258 -0
  28. package/schema/proto/derecmessage.proto +232 -0
  29. package/schema/proto/derecsecret.proto +163 -0
  30. package/schema/proto/derectransport.proto +38 -0
  31. package/schema/proto/error.proto +68 -0
  32. package/schema/proto/getshare.proto +184 -0
  33. package/schema/proto/pair.proto +284 -0
  34. package/schema/proto/parameterrange.proto +36 -0
  35. package/schema/proto/prepair.proto +163 -0
  36. package/schema/proto/result.proto +194 -0
  37. package/schema/proto/secretidsversions.proto +199 -0
  38. package/schema/proto/storeshare.proto +242 -0
  39. package/schema/proto/transportprotocol.proto +112 -0
  40. package/schema/proto/unpair.proto +132 -0
  41. package/schema/proto/updatechannelinfo.proto +100 -0
  42. package/schema/proto/verify.proto +160 -0
  43. package/src/errors.ts +3 -0
  44. package/src/messages.ts +5 -3
  45. package/src/primitives.ts +6 -2
  46. package/src/protocol.ts +10 -6
  47. package/src/types.ts +49 -23
@@ -0,0 +1,284 @@
1
+ /*
2
+ * Copyright (c) DeRec Alliance and its Contributors.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ syntax = "proto3";
7
+
8
+ import "google/protobuf/timestamp.proto";
9
+ import "communicationinfo.proto";
10
+ import "parameterrange.proto";
11
+ import "result.proto";
12
+ import "transportprotocol.proto";
13
+
14
+ package org.derecalliance.derec.protobuf;
15
+
16
+ // SenderKind identifies the logical role of the sender in the pairing flow.
17
+ //
18
+ // The role determines how the receiver interprets the message and what
19
+ // role each party takes in the resulting channel. Pairs are formed by
20
+ // matching complementary kinds: Owner↔Helper, ReplicaSource↔ReplicaDestination.
21
+ enum SenderKind {
22
+ // Sender is an Owner.
23
+ //
24
+ // Used for all Owner-initiated pairings, whether establishing a new
25
+ // relationship or re-pairing during recovery. There is no protocol-level
26
+ // distinction between the two cases.
27
+ OWNER = 0;
28
+
29
+ // Sender is acting as a Helper.
30
+ //
31
+ // Helpers may initiate pairing in some application flows, though the
32
+ // Owner typically acts as the initiator.
33
+ HELPER = 1;
34
+
35
+ // Sender is the Source side of a replica pair — the device that owns
36
+ // the secrets and pushes them to a destination for backup. The matching
37
+ // peer kind is REPLICA_DESTINATION.
38
+ //
39
+ // Replica pairing follows the same cryptographic handshake as Helper
40
+ // pairing but adds a mandatory fingerprint-verify step before the
41
+ // channel transitions out of `Pending`. After verification, the Source
42
+ // calls ProtectSecret targeting the Destination channel; the library
43
+ // sends a `ReplicaSecretPayload` (full secret + share map) to the
44
+ // Destination via a normal channel-mode `StoreShareRequest`.
45
+ REPLICA_SOURCE = 3;
46
+
47
+ // Sender is the Destination side of a replica pair — the device that
48
+ // receives and stores full secret copies from a Source for backup or
49
+ // recovery purposes. The matching peer kind is REPLICA_SOURCE.
50
+ //
51
+ // The Destination never initiates ProtectSecret on this channel; it
52
+ // only receives `ReplicaSecretPayload` messages and surfaces them to
53
+ // the application via the `ReplicaSecretReceived` event.
54
+ REPLICA_DESTINATION = 4;
55
+ }
56
+
57
+ // PairRequestMessage is the first message in the pairing protocol,
58
+ // sent from the initiator to the responder after receiving a ContactMessage.
59
+ //
60
+ // # Preconditions
61
+ //
62
+ // Before sending this message:
63
+ //
64
+ // - The initiator MUST have received a valid ContactMessage from the responder
65
+ // - The initiator MUST use the responder's public encryption material from
66
+ // the ContactMessage to construct this request
67
+ //
68
+ // # Purpose
69
+ //
70
+ // This message establishes:
71
+ //
72
+ // - the initiator's identity and role (Owner/Helper, recovery mode or not)
73
+ // - fresh cryptographic material for the responder to use in subsequent messages
74
+ // - agreement negotiation inputs (parameter ranges)
75
+ // - binding between the out-of-band contact exchange and this pairing attempt
76
+ // - transport information for future communication
77
+ //
78
+ // # Security Properties
79
+ //
80
+ // - The nonce binds this request to the ContactMessage exchange
81
+ // - The ciphertext and public keys bootstrap a secure communication channel
82
+ // - The message is encrypted and authenticated at the DeRecMessage layer
83
+ //
84
+ // # Outcome
85
+ //
86
+ // Upon successful processing, the responder replies with PairResponseMessage.
87
+ // After this exchange:
88
+ //
89
+ // - both parties know each other's public keys
90
+ // - a secure communication channel is established for subsequent protocol flows
91
+ message PairRequestMessage {
92
+
93
+ // The role of the sender of this message.
94
+ //
95
+ // This informs the responder whether the initiator is:
96
+ //
97
+ // - an Owner (normal or recovery mode), or
98
+ // - a Helper
99
+ //
100
+ // Recovery mode has special semantics for how Helpers associate this
101
+ // pairing with existing stored secrets.
102
+ SenderKind senderKind = 1;
103
+
104
+ // ML-KEM-1024 ciphertext.
105
+ //
106
+ // This ciphertext is generated using the responder's ML-KEM public key
107
+ // obtained from the ContactMessage. It is used to establish shared
108
+ // cryptographic material for securing subsequent communication.
109
+ bytes mlkemCiphertext = 2;
110
+
111
+ // Serialized ECIES public key of the sender.
112
+ //
113
+ // This key is provided to the responder so that future messages can be
114
+ // encrypted toward the initiator.
115
+ bytes eciesPublicKey = 3;
116
+
117
+ // Sender's application-level identifying information.
118
+ //
119
+ // This field is intended for user-facing identification and may include
120
+ // data such as name, phone number, or account identifiers.
121
+ //
122
+ // It is not used directly by the protocol for security decisions.
123
+ CommunicationInfo communicationInfo = 5;
124
+
125
+ // Nonce binding this request to the ContactMessage exchange.
126
+ //
127
+ // This value MUST match the nonce provided in the ContactMessage.
128
+ // It allows the responder to verify that the pairing request corresponds
129
+ // to the same out-of-band interaction, preventing mismatched or spoofed
130
+ // pairing attempts.
131
+ uint64 nonce = 6;
132
+
133
+ // Parameter range supported by the sender.
134
+ //
135
+ // This defines the acceptable configuration space (e.g., thresholds,
136
+ // limits) that the sender is willing to operate under.
137
+ //
138
+ // The responder combines this with its own parameter range to determine
139
+ // whether pairing is possible and which parameters to use.
140
+ ParameterRange parameterRange = 7;
141
+
142
+ // Formerly the singular `transportProtocol`, superseded by `supportedTransports`.
143
+ reserved 8;
144
+ reserved "transportProtocol";
145
+
146
+ // Timestamp indicating when this message was created.
147
+ //
148
+ // Used for observability and may assist in replay detection or timeout
149
+ // handling, depending on the implementation.
150
+ google.protobuf.Timestamp timestamp = 9;
151
+
152
+ // Every transport endpoint the initiator can be reached on, in the
153
+ // initiator's own preference order.
154
+ //
155
+ // Same semantics as `ContactMessage.supportedTransports`: the responder
156
+ // selects by its own preference, and the list MUST carry at least one
157
+ // entry.
158
+ repeated TransportProtocol supportedTransports = 10;
159
+ }
160
+
161
+ // PairResponseMessage is the response to a PairRequestMessage.
162
+ //
163
+ // # Purpose
164
+ //
165
+ // This message completes the pairing handshake. It informs the initiator:
166
+ //
167
+ // - whether the pairing was accepted or rejected
168
+ // - the responder's role and identity information
169
+ // - the responder's supported parameter range
170
+ //
171
+ // # Differences from PairRequestMessage
172
+ //
173
+ // - Does not include encryption public keys, as those were already exchanged
174
+ // via ContactMessage and PairRequestMessage
175
+ // - Includes a Result field indicating success or failure
176
+ //
177
+ // # Semantics
178
+ //
179
+ // - If `result` indicates success, a secure channel is considered established
180
+ // - If `result` indicates failure, the pairing MUST be treated as unsuccessful
181
+ // and no further protocol messages should be exchanged on this channel
182
+ //
183
+ // The nonce MUST match the value provided in the request, ensuring that the
184
+ // response corresponds to the same pairing session.
185
+ message PairResponseMessage {
186
+
187
+ // Result of processing the pairing request.
188
+ //
189
+ // Indicates whether the pairing was successful or failed.
190
+ // Failure may occur due to:
191
+ //
192
+ // - incompatible parameter ranges
193
+ // - failed authentication at the application layer
194
+ // - invalid or malformed request data
195
+ DeRecResult result = 1;
196
+
197
+ // Application-level identifying information of the responder.
198
+ //
199
+ // Intended for user-facing identification and display purposes.
200
+ CommunicationInfo communicationInfo = 4;
201
+
202
+ // Nonce identifying the pairing session.
203
+ //
204
+ // This value MUST exactly match the nonce received in the
205
+ // PairRequestMessage. A mismatch indicates an invalid or unrelated
206
+ // pairing attempt and SHOULD result in rejection.
207
+ uint64 nonce = 5;
208
+
209
+ // Parameter range supported by the responder.
210
+ //
211
+ // The initiator combines this with its own parameter range to determine
212
+ // the final agreed configuration for the channel.
213
+ ParameterRange parameterRange = 6;
214
+
215
+ // Timestamp indicating when this message was created.
216
+ //
217
+ // Used for observability and may assist in replay detection or timeout
218
+ // handling, depending on the implementation.
219
+ google.protobuf.Timestamp timestamp = 7;
220
+
221
+ // Derived channel identifier the two parties switch to immediately after
222
+ // the pairing handshake completes. This message is the only place this
223
+ // value travels on the wire, and it travels encrypted (inside the pairing
224
+ // envelope), so a passive observer who only sees the pre-rekey traffic
225
+ // cannot link the now-paired session to its long-running successor.
226
+ //
227
+ // # Derivation
228
+ //
229
+ // The responder computes:
230
+ //
231
+ // ```text
232
+ // channelId = u64::from_be_bytes(
233
+ // SHA-384(
234
+ // u64_be(originalChannelId) || sharedKeyBytes
235
+ // )[0..8]
236
+ // )
237
+ // ```
238
+ //
239
+ // where `originalChannelId` is the channelId from the contact / pairing
240
+ // envelopes and `sharedKeyBytes` is the channel key derived as described
241
+ // on `fingerprintNonce`.
242
+ //
243
+ // # Validation
244
+ //
245
+ // The requester MUST recompute the same hash with its own derivation of
246
+ // the shared key and reject the response (closing the would-be channel)
247
+ // if the value here does not match. A non-matching value indicates either
248
+ // a key-derivation mismatch (the channel would be unusable anyway) or
249
+ // tampering by a peer that somehow forged a valid envelope but cannot
250
+ // produce the SHA-384 preimage.
251
+ //
252
+ // # Effect
253
+ //
254
+ // Both parties atomically rekey their local channel record from
255
+ // `originalChannelId` to this value once the handshake is accepted. All
256
+ // subsequent envelopes on this channel — including the
257
+ // UpdateChannelInfo handover for the long-term transport — route on the
258
+ // new id.
259
+ uint64 channelId = 8;
260
+
261
+ // The 32-byte fingerprint nonce the creator committed to in
262
+ // `fingerprintCommitment` (on the `ContactMessage` in `INLINE_KEYS` mode,
263
+ // on the `PrePairResponseMessage` otherwise). Present only when
264
+ // `result.status == OK`.
265
+ //
266
+ // The requester MUST recompute the commitment from the creator's keys and
267
+ // this nonce, and reject the response (closing the would-be channel) if
268
+ // it does not match.
269
+ //
270
+ // # Channel key
271
+ //
272
+ // Both parties derive the channel key from the handshake key and this
273
+ // nonce:
274
+ //
275
+ // ```text
276
+ // SHA-256("DeRec channel key v1" || handshakeKey || fingerprintNonce)
277
+ // ```
278
+ //
279
+ // where `handshakeKey` is the ML-KEM shared secret XOR the ECDH shared
280
+ // secret. The channel key encrypts every later message, feeds the
281
+ // `channelId` derivation above, and is what the fingerprint is computed
282
+ // from.
283
+ optional bytes fingerprintNonce = 9;
284
+ }
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Copyright (c) DeRec Alliance and its Contributors.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ syntax = "proto3";
7
+
8
+ package org.derecalliance.derec.protobuf;
9
+
10
+ message ParameterRange {
11
+
12
+ // Minimum and maximum number of bytes the party is willing to store
13
+ // at any given time.
14
+ int64 minShareSize = 1;
15
+ int64 maxShareSize = 2;
16
+
17
+ // Minimum and maximum interval between verification requests that
18
+ // will be accepted.
19
+ int64 minTimeBetweenVerifications = 3;
20
+ int64 maxTimeBetweenVerifications = 4;
21
+
22
+ // Minimum and maximum interval between accepting new share updates.
23
+ int64 minTimeBetweenShareUpdates = 5;
24
+ int64 maxTimeBetweenShareUpdates = 6;
25
+
26
+ // Minimum and maximum timeout period (in seconds) after which the
27
+ // other party is considered unresponsive and the pairing may be
28
+ // removed along with all associated data.
29
+ int64 minUnresponsiveDeletionTimeout = 7;
30
+ int64 maxUnresponsiveDeletionTimeout = 8;
31
+
32
+ // Minimum and maximum timeout period (in seconds) after which the
33
+ // other party is considered inactive.
34
+ int64 minUnresponsiveDeactivationTimeout = 9;
35
+ int64 maxUnresponsiveDeactivationTimeout = 10;
36
+ }
@@ -0,0 +1,163 @@
1
+ /*
2
+ * Copyright (c) DeRec Alliance and its Contributors.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ syntax = "proto3";
7
+
8
+ import "google/protobuf/timestamp.proto";
9
+ import "result.proto";
10
+ import "transportprotocol.proto";
11
+
12
+ package org.derecalliance.derec.protobuf;
13
+
14
+ // PrePairRequestMessage is sent by the recipient of a ContactMessage whose
15
+ // `contactMode == CONTACT_MODE_HASHED_KEYS`. It asks the contact creator for
16
+ // the actual ML-KEM and ECIES public keys that the contact's
17
+ // `contactBindingHash` commits to.
18
+ //
19
+ // # When this is sent
20
+ //
21
+ // `CONTACT_MODE_HASHED_KEYS` contacts carry only a hash of the public keys
22
+ // so they fit in size-constrained out-of-band channels (e.g. QR codes,
23
+ // short URLs). The recipient must obtain the actual keys before it can
24
+ // construct the first encrypted `PairRequestMessage`.
25
+ //
26
+ // # Security
27
+ //
28
+ // This message is plaintext — no shared key has been established yet. The
29
+ // scanner-side integrity check happens after the `PrePairResponseMessage`
30
+ // arrives, by recomputing the hash and matching it against the original
31
+ // `contactBindingHash`. An attacker who intercepts the transport cannot
32
+ // substitute different keys without producing a hash collision.
33
+ //
34
+ // # Envelope
35
+ //
36
+ // The message is wrapped in a `DeRecMessage` envelope just like every
37
+ // other protocol message. The envelope's `channelId` carries the routing
38
+ // key; the envelope's `message` field carries the serialized
39
+ // `PrePairRequestMessage` bytes unencrypted (because no symmetric key
40
+ // exists yet).
41
+ //
42
+ // # Security: transport endpoint is observable
43
+ //
44
+ // Because the envelope is plaintext, the endpoints carried in
45
+ // `PrePairRequestMessage` are visible to any passive observer on the
46
+ // network path. The same applies to the `supportedTransports` carried in
47
+ // the `HASHED_KEYS`-mode `ContactMessage` itself if its out-of-band channel
48
+ // can be observed.
49
+ //
50
+ // The protocol relies on this contract from the application to preserve
51
+ // the security guarantees of `HASHED_KEYS` mode:
52
+ //
53
+ // - The endpoints used during pairing (those advertised in the
54
+ // `ContactMessage` and in `PrePairRequestMessage`) MUST be
55
+ // ephemeral and short-lived — bound to the pairing attempt, not to the
56
+ // long-term identity of either peer.
57
+ // - Once pairing completes, the application MUST swap to a long-term
58
+ // endpoint via an `UpdateChannelInfoRequestMessage`. The ephemeral
59
+ // pairing endpoint is retired after the changeover (see the endpoint-
60
+ // changeover discipline on `UpdateChannelInfoRequestMessage`).
61
+ //
62
+ // `INLINE_KEYS`-mode contacts do not have this constraint because the
63
+ // `PairRequestMessage` is asymmetrically encrypted; only the
64
+ // `ContactMessage` itself crosses an unencrypted channel, which is by
65
+ // definition the trusted out-of-band one.
66
+ message PrePairRequestMessage {
67
+
68
+ // The same `nonce` the original `ContactMessage` advertised. Bound to
69
+ // the contact session; mismatches indicate a stale or spoofed request
70
+ // and the receiver MUST refuse to serve the keys.
71
+ uint64 nonce = 1;
72
+
73
+ // Formerly the singular `transportProtocol`, superseded by `supportedTransports`.
74
+ reserved 2;
75
+ reserved "transportProtocol";
76
+
77
+ // Timestamp indicating when this message was created.
78
+ //
79
+ // This value is expressed in UTC and is used for envelope-vs-body
80
+ // timestamp validation, replay detection, and observability.
81
+ google.protobuf.Timestamp timestamp = 3;
82
+
83
+ // Every transport endpoint the sender of this PrePair request can be
84
+ // reached on for the `PrePairResponseMessage`.
85
+ //
86
+ // Each entry is a complete endpoint: a URI plus the protocol that says
87
+ // how to interpret it. The list is written in the sender's own
88
+ // preference order.
89
+ //
90
+ // # Selection is the recipient's
91
+ //
92
+ // A recipient picks whichever entry suits it, ordered by its **own**
93
+ // preference rather than the sender's. The order here expresses
94
+ // availability, not a ranking the recipient must honor.
95
+ //
96
+ // The list MUST carry at least one entry: a request naming no endpoint
97
+ // gives the recipient nowhere to send the response.
98
+ //
99
+ // # Security
100
+ //
101
+ // PrePair traffic is plaintext — no shared key exists yet — so these
102
+ // endpoints are visible to a passive observer. The recipient's transport
103
+ // policy still refuses plaintext entries unless plaintext has been opted
104
+ // into.
105
+ repeated TransportProtocol supportedTransports = 4;
106
+ }
107
+
108
+ // PrePairResponseMessage is the contact creator's reply to a
109
+ // `PrePairRequestMessage`. On success it carries the real public keys; on
110
+ // failure it carries only a non-`Ok` `DeRecResult`.
111
+ //
112
+ // # Validation by the receiver
113
+ //
114
+ // The recipient (the original scanner of the `ContactMessage`) MUST:
115
+ //
116
+ // - Confirm `result.status == OK`. On non-`Ok`, surface a typed error to
117
+ // the application and do not proceed.
118
+ // - Recompute
119
+ //
120
+ // ```text
121
+ // SHA-384(mlkemEncapsulationKey || eciesPublicKey
122
+ // || u64_be(nonce) || u64_be(channelId))
123
+ // ```
124
+ //
125
+ // and verify it matches the original `ContactMessage.contactBindingHash`.
126
+ // - Only on a match, proceed to construct and send a normal
127
+ // `PairRequestMessage`.
128
+ //
129
+ // # Envelope
130
+ //
131
+ // Plaintext-in-`DeRecMessage`-envelope, same as `PrePairRequestMessage`.
132
+ message PrePairResponseMessage {
133
+
134
+ // Result of processing the `PrePairRequestMessage`. On `OK`, the two
135
+ // key fields below are present. On any non-`Ok` status, the key fields
136
+ // MUST be absent.
137
+ DeRecResult result = 1;
138
+
139
+ // Serialized ML-KEM-1024 encapsulation key. Present only when
140
+ // `result.status == OK`.
141
+ optional bytes mlkemEncapsulationKey = 2;
142
+
143
+ // Serialized ECIES public key. Present only when
144
+ // `result.status == OK`.
145
+ optional bytes eciesPublicKey = 3;
146
+
147
+ // Echoed from the request for session correlation.
148
+ uint64 nonce = 4;
149
+
150
+ // Timestamp indicating when this message was created.
151
+ google.protobuf.Timestamp timestamp = 5;
152
+
153
+ // The creator's commitment to the fingerprint nonce it reveals in
154
+ // `PairResponseMessage.fingerprintNonce`, computed over the two keys
155
+ // above exactly as `ContactMessage.fingerprintCommitment` defines.
156
+ // Present, exactly 32 bytes, only when `result.status == OK`.
157
+ //
158
+ // The receiver MUST refuse a response without one, and MUST later refuse
159
+ // a `PairResponseMessage` whose nonce does not open it. Because the
160
+ // commitment covers the keys, one made for another creator's keys cannot
161
+ // be replayed here.
162
+ optional bytes fingerprintCommitment = 6;
163
+ }
@@ -0,0 +1,194 @@
1
+ /*
2
+ * Copyright (c) DeRec Alliance and its Contributors.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ syntax = "proto3";
7
+
8
+ package org.derecalliance.derec.protobuf;
9
+
10
+ // Result represents the outcome of processing a DeRec protocol request.
11
+ //
12
+ // # Purpose
13
+ //
14
+ // This message is included in response messages to communicate:
15
+ //
16
+ // - whether a request was successfully processed
17
+ // - the type of failure (if any)
18
+ // - optional human-readable context for debugging or user display
19
+ //
20
+ // # Semantics
21
+ //
22
+ // A Result consists of:
23
+ //
24
+ // - a machine-readable `status` code
25
+ // - an optional `memo` providing additional context
26
+ //
27
+ // The `status` field MUST be used by implementations to determine
28
+ // protocol behavior. The `memo` field is informational only.
29
+ //
30
+ // # Usage
31
+ //
32
+ // - Every response message that can fail SHOULD include a Result
33
+ // - Senders MUST inspect the `status` field to determine next steps
34
+ // - The `memo` field MAY be displayed to users or logged for diagnostics
35
+ //
36
+ // # Security Considerations
37
+ //
38
+ // - The `memo` field SHOULD NOT include sensitive internal details
39
+ // - Only high-level or user-safe information should be exposed
40
+ //
41
+ // # Idempotency
42
+ //
43
+ // The Result reflects the outcome of a specific request. Repeated identical
44
+ // requests SHOULD produce consistent Result values unless system state changes.
45
+ message DeRecResult {
46
+ // Status code indicating the outcome of the request.
47
+ StatusEnum status = 1;
48
+
49
+ // Optional human-readable description providing additional details.
50
+ //
51
+ // This field is intended for debugging, logging, or user display.
52
+ // It MUST NOT be relied upon for programmatic decision-making.
53
+ string memo = 2;
54
+ }
55
+
56
+ // StatusEnum defines the set of possible outcomes for processing
57
+ // DeRec protocol requests.
58
+ //
59
+ // # Semantics
60
+ //
61
+ // These values are used across all response messages to provide a consistent
62
+ // interpretation of success and failure conditions.
63
+ //
64
+ // Implementations MUST handle all known values and SHOULD safely ignore
65
+ // unknown values for forward compatibility.
66
+ enum StatusEnum {
67
+
68
+ // The request was successfully handled.
69
+ //
70
+ // No further action is required by the sender.
71
+ OK = 0;
72
+
73
+ // The request was partially fulfilled.
74
+ //
75
+ // The `memo` field SHOULD provide additional context explaining which
76
+ // parts succeeded and which did not.
77
+ PARTIAL = 1;
78
+
79
+ // The request failed for a generic or unspecified reason.
80
+ //
81
+ // The `memo` field MAY provide additional details.
82
+ FAIL = 2;
83
+
84
+ // The request failed because it would exceed the allowed storage limit
85
+ // for this sharer and secret ID.
86
+ //
87
+ // This typically applies to share storage operations.
88
+ SIZE_LIMIT_EXCEEDED = 3;
89
+
90
+ // The request was ignored because it exceeded the allowed frequency.
91
+ //
92
+ // This may be used for rate limiting to prevent abuse or excessive load.
93
+ TOO_FREQUENT = 4;
94
+
95
+ // The specified secret ID is not recognized by the Helper.
96
+ //
97
+ // This may occur during recovery or share retrieval.
98
+ UNKNOWN_SECRET_ID = 5;
99
+
100
+ // The specified share version does not exist for the given secret ID.
101
+ //
102
+ // This may occur if the version was never stored or has been deleted.
103
+ UNKNOWN_SHARE_VERSION = 6;
104
+
105
+ // The message could not be decrypted successfully.
106
+ //
107
+ // This indicates a failure in the cryptographic layer, such as:
108
+ //
109
+ // - incorrect key material
110
+ // - corrupted ciphertext
111
+ DECRYPTION_FAILED = 7;
112
+
113
+ // The message signature or authentication could not be verified.
114
+ //
115
+ // This indicates that the message integrity or authenticity check failed.
116
+ VERIFICATION_FAILED = 8;
117
+
118
+ // The message format is invalid.
119
+ //
120
+ // This includes errors such as:
121
+ //
122
+ // - protobuf parsing failures
123
+ // - missing required fields
124
+ // - structurally invalid messages
125
+ FORMAT_ERROR = 9;
126
+
127
+ // The request was rejected by the counter-party
128
+ //
129
+ // This might be used to indicate the user or system that received the
130
+ // requested rejected it.
131
+ REJECTED = 10;
132
+
133
+ // The pair handshake failed because the two parties' advertised
134
+ // `ParameterRange` values do not overlap on at least one field
135
+ // (e.g. local `minShareSize` exceeds peer `maxShareSize`).
136
+ //
137
+ // Sent on a `PairResponseMessage`; the `memo` field SHOULD describe
138
+ // the offending field and the two `(min, max)` pairs so the
139
+ // initiator can surface a useful diagnostic.
140
+ INCOMPATIBLE_PARAMETER_RANGE = 11;
141
+
142
+ // The announced transport protocol is one the recipient cannot serve.
143
+ //
144
+ // Returned only for a transport change on an **already-established**
145
+ // channel — an `UpdateChannelInfo` announcing a switch the recipient
146
+ // cannot follow. The recipient still holds the peer's previous working
147
+ // endpoint, which is what makes this refusal deliverable at all.
148
+ //
149
+ // It is deliberately **not** used during pairing. Delivery is push-only,
150
+ // so a party that cannot reach a peer also cannot deliver a rejection to
151
+ // it; pairing incompatibility surfaces locally to the application
152
+ // instead.
153
+ UNSUPPORTED_TRANSPORT_PROTOCOL = 12;
154
+
155
+ // A share already exists for this (secretId, version) with different
156
+ // content, so the write was refused.
157
+ //
158
+ // Exactly one writer owns a version. A recipient stores the first write
159
+ // it sees at a version; a later write carrying different bytes is
160
+ // rejected with this status rather than overwriting or coexisting. A
161
+ // byte-identical re-send is an idempotent retry and returns `OK`.
162
+ //
163
+ // Because a single writer always derives `version` as
164
+ // `latest_version + 1`, it can never rewrite a version with different
165
+ // content. Receiving this status therefore means a *second* writer
166
+ // published concurrently — typically the same user acting on two
167
+ // devices at once. Resolution is the application's responsibility: the
168
+ // round has failed and should be republished at a new version.
169
+ VERSION_CONFLICT = 13;
170
+
171
+ // A replica pairing named a `replicaId` that is already in use by another
172
+ // member of the group — including the recipient itself.
173
+ //
174
+ // Every member of a group must be uniquely identified: the roster is keyed
175
+ // by `replicaId`, and messages between members are attributed by it. Two
176
+ // members sharing an id would overwrite each other's roster row and make
177
+ // every acknowledgement ambiguous.
178
+ //
179
+ // `replicaId` is assigned by the application, so a collision is a
180
+ // configuration fault — most often the same identity reused on two devices,
181
+ // such as a cloned device image. Resolution is the application's: assign a
182
+ // distinct id and pair again. The protocol cannot pick one, because it
183
+ // cannot know which device is meant to keep the original.
184
+ //
185
+ // Reported before fingerprint verification: there is no point asking a user
186
+ // to confirm a pairing that cannot be completed.
187
+ REPLICA_ID_CONFLICT = 14;
188
+
189
+ // The Helper is requesting that the Owner terminate the relationship.
190
+ //
191
+ // The Owner SHOULD respond by sending an UnpairRequestMessage and
192
+ // ceasing further communication on the channel.
193
+ REQUEST_TO_CLOSE = 99;
194
+ }