@derec-alliance/react-native 0.0.9 → 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.
Files changed (47) hide show
  1. package/README.md +114 -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 +38 -9
  6. package/cpp/Primitives.h +5 -3
  7. package/cpp/ProtocolHost.cpp +4 -5
  8. package/cpp/StoreCallbacks.cpp +31 -43
  9. package/cpp/derec_ffi.h +98 -33
  10. package/ios/DeRecFFI.xcframework/ios-arm64/Headers/derec_ffi.h +98 -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 +98 -33
  13. package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/libderec_library.a +2 -2
  14. package/lib/errors.d.ts +8 -3
  15. package/lib/errors.js +6 -0
  16. package/lib/messages.js +5 -3
  17. package/lib/primitives.d.ts +12 -2
  18. package/lib/primitives.js +17 -2
  19. package/lib/protocol.d.ts +9 -5
  20. package/lib/protocol.js +9 -5
  21. package/lib/types.d.ts +194 -46
  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 +266 -0
  28. package/schema/proto/derecmessage.proto +248 -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 +164 -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 +12 -1
  44. package/src/messages.ts +5 -3
  45. package/src/primitives.ts +23 -2
  46. package/src/protocol.ts +10 -6
  47. package/src/types.ts +185 -43
@@ -106,6 +106,8 @@
106
106
 
107
107
  #define DEREC_CATEGORY_STATE_STORE 15
108
108
 
109
+ #define DEREC_CATEGORY_TRANSPORT 16
110
+
109
111
  #define DEREC_CODE_OK 0
110
112
 
111
113
  #define DEREC_CODE_NON_OK_STATUS 1
@@ -180,6 +182,13 @@
180
182
  */
181
183
  #define DEREC_CODE_REPLICA_ID_CONFLICT 16
182
184
 
185
+ /**
186
+ * `derec_protocol_verify_fingerprint`: the fingerprint compared out of band
187
+ * does not match the channel key — a possible man-in-the-middle. A `Pending`
188
+ * pairing has been revoked; pair again. `DEREC_CATEGORY_PAIRING`.
189
+ */
190
+ #define DEREC_CODE_FINGERPRINT_MISMATCH 17
191
+
183
192
  #define DEREC_CODE_ENCRYPTION 20
184
193
 
185
194
  #define DEREC_CODE_KEYGEN 21
@@ -229,6 +238,24 @@
229
238
  */
230
239
  #define DEREC_CODE_INCOMPATIBLE_PARAMETER_RANGE 47
231
240
 
241
+ /**
242
+ * The fingerprint nonce in a `PairResponseMessage` does not open the
243
+ * commitment the contact creator published with its keys. Surfaced as
244
+ * [`DEREC_CATEGORY_PAIRING`]; the pairing does not complete. Either the
245
+ * response or the keys did not come from the party that made the
246
+ * commitment, so applications can treat it as a possible
247
+ * man-in-the-middle.
248
+ */
249
+ #define DEREC_CODE_FINGERPRINT_COMMITMENT_MISMATCH 48
250
+
251
+ /**
252
+ * The pairing outlived `Timeouts::pairing`: the scanner refuses a contact
253
+ * older than it, and the contact's creator refuses to accept a request
254
+ * that arrives after it. Surfaced as [`DEREC_CATEGORY_PAIRING`]; nothing is
255
+ * sent to the peer, and a fresh contact starts a new pairing.
256
+ */
257
+ #define DEREC_CODE_PAIRING_EXPIRED 49
258
+
232
259
  #define DEREC_CODE_EMPTY_CHANNELS 60
233
260
 
234
261
  #define DEREC_CODE_DUPLICATE_CHANNEL_ID 61
@@ -243,6 +270,8 @@
243
270
 
244
271
  #define DEREC_CODE_TOO_MANY_SUBSHARES 66
245
272
 
273
+ #define DEREC_CODE_INVALID_KEEP_VERSION 67
274
+
246
275
  #define DEREC_CODE_EMPTY_RESPONSES 80
247
276
 
248
277
  #define DEREC_CODE_EMPTY_COMMITTED_DEREC_SHARE 81
@@ -293,6 +322,13 @@
293
322
  */
294
323
  #define DEREC_CODE_NO_USABLE_ENDPOINT 121
295
324
 
325
+ /**
326
+ * The application's transport delivered a message to none of the peer's
327
+ * endpoints: the `send` callback returned non-zero.
328
+ * `DEREC_CATEGORY_TRANSPORT`.
329
+ */
330
+ #define DEREC_CODE_TRANSPORT_SEND_FAILED 123
331
+
296
332
  /**
297
333
  * Return codes for [`crate::interop::ffi::protocol::stores::ShareStoreCallbacks::save`]
298
334
  * and `ShareStoreCallbacks::record_verification`: `0` is success, each of
@@ -475,6 +511,14 @@ typedef struct DeRecError {
475
511
  * Valid when `code == DEREC_CODE_VERSION_MISMATCH`.
476
512
  */
477
513
  uint32_t got;
514
+ /**
515
+ * Whether `channel_id` is set: the error names the channel it is about.
516
+ */
517
+ bool has_channel_id;
518
+ /**
519
+ * The channel the error is about. Valid when `has_channel_id`.
520
+ */
521
+ uint64_t channel_id;
478
522
  } DeRecError;
479
523
 
480
524
  typedef struct DeRecBuffer {
@@ -538,6 +582,20 @@ typedef struct ReadTraceIdResult {
538
582
  uint64_t trace_id;
539
583
  } ReadTraceIdResult;
540
584
 
585
+ typedef struct MessageIdResult {
586
+ struct DeRecError error;
587
+ /**
588
+ * SHA-256 of the envelope's encrypted `message` field (32 bytes). Empty
589
+ * on error.
590
+ */
591
+ struct DeRecBuffer id;
592
+ /**
593
+ * The envelope's send time, in seconds since the Unix epoch. Zero on
594
+ * error.
595
+ */
596
+ uint64_t timestamp;
597
+ } MessageIdResult;
598
+
541
599
  /**
542
600
  * Result of a message JSON codec call. `bytes` is UTF-8 JSON for
543
601
  * [`derec_decode_message_json`] and protobuf wire bytes for
@@ -704,6 +762,12 @@ typedef struct ProcessPrePairResponseMessageResult {
704
762
  * Nonce echoed from the original `ContactMessage`. Zero on failure.
705
763
  */
706
764
  uint64_t nonce;
765
+ /**
766
+ * The creator's 32-byte commitment to its fingerprint nonce. Carry it
767
+ * into the contact the pair request is built from, in
768
+ * `fingerprint_commitment`, alongside the two keys.
769
+ */
770
+ struct DeRecBuffer fingerprint_commitment;
707
771
  } ProcessPrePairResponseMessageResult;
708
772
 
709
773
  typedef struct PairingFingerprintResult {
@@ -865,10 +929,9 @@ typedef struct SecretStoreCallbacks {
865
929
  * is none, and absent or `null` reads as none. Store them as given and return
866
930
  * them unchanged.
867
931
  *
868
- * `keep_list` returns the JSON encoding of the application's answer:
869
- * `null` for no list (the owner sends an empty `keepList` and helpers keep
870
- * every version) or an array of version numbers. An empty buffer or return code `1` also
871
- * means `null`.
932
+ * `keep_version` writes the application's answer to `out_version`: the one
933
+ * version, other than `version`, every helper keeps, or `0` to keep no
934
+ * other version. Any non-zero return code is a backend failure.
872
935
  *
873
936
  * `save` and `record_verification` share a return-code convention: `0` is
874
937
  * success; `3`/`4`/`10` (the
@@ -920,11 +983,10 @@ typedef struct ShareStoreCallbacks {
920
983
  uint64_t channel_id,
921
984
  const uint8_t *versions_json_ptr,
922
985
  size_t versions_json_len);
923
- int32_t (*keep_list)(void *user_data,
924
- uint64_t secret_id,
925
- uint32_t version,
926
- uint8_t **out_ptr,
927
- size_t *out_len);
986
+ int32_t (*keep_version)(void *user_data,
987
+ uint64_t secret_id,
988
+ uint32_t version,
989
+ uint32_t *out_version);
928
990
  int32_t (*record_verification)(void *user_data,
929
991
  uint64_t secret_id,
930
992
  uint64_t channel_id,
@@ -1406,6 +1468,19 @@ struct ApplyTraceIdResult apply_trace_id_to_envelope(const uint8_t *envelope_ptr
1406
1468
  struct ReadTraceIdResult read_trace_id_from_envelope(const uint8_t *envelope_ptr,
1407
1469
  size_t envelope_len);
1408
1470
 
1471
+ /**
1472
+ * Identify an envelope for replay and reflection detection: the same `id`
1473
+ * for every copy of one message, whatever its unauthenticated cleartext
1474
+ * fields say, and a different one for every other message.
1475
+ *
1476
+ * Mirrors [`crate::derec_message::message_id`].
1477
+ *
1478
+ * # Safety
1479
+ *
1480
+ * `envelope_ptr` must point to a readable byte range of length `envelope_len`.
1481
+ */
1482
+ struct MessageIdResult message_id_from_envelope(const uint8_t *envelope_ptr, size_t envelope_len);
1483
+
1409
1484
  /**
1410
1485
  * Releases the owned strings carried by a [`DeRecError`]. After
1411
1486
  * returning, `error.message` and `error.peer_memo` are both null —
@@ -1781,6 +1856,8 @@ struct ProcessPrePairResponseMessageResult process_pre_pair_response_message(con
1781
1856
  * "inbound_message_secs": 300,
1782
1857
  * "sharing_round_secs": 60,
1783
1858
  * "unpair_ack_secs": 60,
1859
+ * "get_share_response_secs": 300,
1860
+ * "pairing_secs": 30,
1784
1861
  * "expired_channels": { "enabled": true, "timeout_in_secs": 300 }
1785
1862
  * },
1786
1863
  * "unsafe_connection": false,
@@ -2111,34 +2188,23 @@ struct DeRecProtocolFingerprintResult derec_protocol_get_fingerprint(struct DeRe
2111
2188
  * Verify a fingerprint against the channel's locally-derived one. See
2112
2189
  * [`crate::protocol::DeRecProtocol::verify_fingerprint`].
2113
2190
  *
2114
- * Writes `*out_matched = 1` if and only if the comparison
2115
- * affirmatively succeeded. On every other outcome — null-pointer
2116
- * rejection, malformed UTF-8 in `fingerprint_ptr`, a backend error,
2117
- * or a legitimate mismatch — `*out_matched` is set to `0`. Callers
2118
- * MUST also inspect the returned [`DeRecError`] to distinguish a
2119
- * successful mismatch from a failure that could not produce a
2120
- * verdict; treating `out_matched == 0` as "definitely not matched"
2121
- * is safe only after confirming the envelope reports
2122
- * [`DEREC_CATEGORY_OK`](crate::interop::ffi::error::DEREC_CATEGORY_OK).
2123
- *
2124
- * The fail-closed write happens immediately after the null-pointer
2125
- * check, so a caller that allocates the output on the stack and
2126
- * reads it without checking the error envelope still gets `0`,
2127
- * never a stale `1` from uninitialized memory. This neutralizes
2128
- * the "sloppy caller skips the error envelope and reads stale
2129
- * stack" footgun on the MITM-protection gate.
2191
+ * Success means the comparison matched and the channel is confirmed. Every
2192
+ * other outcome is an error envelope; a mismatch is
2193
+ * [`DEREC_CODE_FINGERPRINT_MISMATCH`](crate::interop::ffi::error::DEREC_CODE_FINGERPRINT_MISMATCH),
2194
+ * after which a `Pending` pairing has been revoked. There is no verdict to
2195
+ * read apart from the envelope, so a caller cannot mistake a failure for a
2196
+ * match.
2130
2197
  *
2131
2198
  * # Safety
2132
2199
  *
2133
- * `handle` and `out_matched` must be valid pointers. `fingerprint_ptr`
2134
- * must be a valid pointer to a NUL-terminated C string. Concurrent
2135
- * calls on the same handle from different threads are safe: the
2136
- * handle's internal mutex serializes them.
2200
+ * `handle` must be a valid pointer. `fingerprint_ptr` must be a valid
2201
+ * pointer to a NUL-terminated C string. Concurrent calls on the same handle
2202
+ * from different threads are safe: the handle's internal mutex serializes
2203
+ * them.
2137
2204
  */
2138
2205
  struct DeRecError derec_protocol_verify_fingerprint(struct DeRecProtocolHandle *handle,
2139
2206
  uint64_t channel_id,
2140
- const char *fingerprint_ptr,
2141
- uint32_t *out_matched);
2207
+ const char *fingerprint_ptr);
2142
2208
 
2143
2209
  /**
2144
2210
  * Generate an out-of-band contact message used to bootstrap pairing.
@@ -2310,8 +2376,7 @@ struct ProduceStoreShareRequestMessageResult produce_store_share_request_message
2310
2376
  uint64_t secret_id,
2311
2377
  const uint8_t *committed_share_ptr,
2312
2378
  size_t committed_share_len,
2313
- const uint32_t *keep_list_ptr,
2314
- size_t keep_list_len,
2379
+ uint32_t keep_version,
2315
2380
  const uint8_t *description_ptr,
2316
2381
  size_t description_len,
2317
2382
  const uint8_t *shared_key_ptr,
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/libderec_library.a
3
- size: 39345736 bytes
4
- sha256: ba3ef018d9a8d24ff7859106f19da05e272a9dc2fa8935202eac4d5af54e35b3
3
+ size: 40069496 bytes
4
+ sha256: 8179350754f8ced0c1e1ff992ce3a3c3dbd5177a5ecb9d04099c765c17633f12
package/lib/errors.d.ts CHANGED
@@ -11,7 +11,7 @@ import type { DeRecEvent } from './types';
11
11
  * The nodejs union is arguably wrong on its own terms too, but correcting it
12
12
  * is a change to that package, not this one.
13
13
  */
14
- export declare const DEREC_ERROR_CATEGORIES: readonly ["ok", "ffi", "pairing", "sharing", "recovery", "verification", "discovery", "unpairing", "derec_message", "secret_store", "channel_store", "share_store", "input", "protobuf", "invariant", "state_store"];
14
+ export declare const DEREC_ERROR_CATEGORIES: readonly ["ok", "ffi", "pairing", "sharing", "recovery", "verification", "discovery", "unpairing", "derec_message", "secret_store", "channel_store", "share_store", "input", "protobuf", "invariant", "state_store", "transport"];
15
15
  export type DeRecErrorCategory = (typeof DEREC_ERROR_CATEGORIES)[number];
16
16
  /**
17
17
  * Every code `derec_error_code_name` can return, and no others.
@@ -21,7 +21,7 @@ export type DeRecErrorCategory = (typeof DEREC_ERROR_CATEGORIES)[number];
21
21
  * own before a value reaches the library, so this list is exactly the Rust
22
22
  * `Code` table in `library/src/interop/error_codes.rs`.
23
23
  */
24
- export declare const DEREC_ERROR_CODES: readonly ["ok", "non_ok_status", "version_mismatch", "invariant", "invalid_input", "protobuf_decode", "protobuf_encode", "protocol_violation", "store_error", "builder_error", "missing_shared_key", "role_mismatch", "replica_id_not_configured", "channel_already_paired", "already_restored", "restore_conflict", "replica_id_conflict", "encryption", "keygen", "finish_pairing_initiator", "finish_pairing_responder", "empty_transport_uri", "invalid_contact_message", "invalid_pair_request_message", "invalid_pair_response_message", "prepair_hash_mismatch", "missing_replica_id", "unexpected_replica_id", "incompatible_parameter_range", "empty_channels", "duplicate_channel_id", "invalid_threshold", "empty_secret_data", "vss_share_failed", "invalid_weight", "too_many_subshares", "empty_responses", "empty_committed_derec_share", "decode_committed_derec_share", "decode_derec_share", "secret_id_mismatch", "reconstruction_failed", "malformed_recovered_secret", "ffi_null_ptr", "ffi_bad_length", "ffi_bad_utf8", "ffi_bad_proto", "ffi_invalid_enum", "ffi_bad_shared_key", "ffi_nul_in_string", "transport_invalid", "no_usable_endpoint"];
24
+ export declare const DEREC_ERROR_CODES: readonly ["ok", "non_ok_status", "version_mismatch", "invariant", "invalid_input", "protobuf_decode", "protobuf_encode", "protocol_violation", "store_error", "builder_error", "missing_shared_key", "role_mismatch", "replica_id_not_configured", "channel_already_paired", "already_restored", "restore_conflict", "replica_id_conflict", "fingerprint_mismatch", "encryption", "keygen", "finish_pairing_initiator", "finish_pairing_responder", "empty_transport_uri", "invalid_contact_message", "invalid_pair_request_message", "invalid_pair_response_message", "prepair_hash_mismatch", "missing_replica_id", "unexpected_replica_id", "incompatible_parameter_range", "fingerprint_commitment_mismatch", "pairing_expired", "empty_channels", "duplicate_channel_id", "invalid_threshold", "empty_secret_data", "vss_share_failed", "invalid_weight", "too_many_subshares", "invalid_keep_version", "empty_responses", "empty_committed_derec_share", "decode_committed_derec_share", "decode_derec_share", "secret_id_mismatch", "reconstruction_failed", "malformed_recovered_secret", "ffi_null_ptr", "ffi_bad_length", "ffi_bad_utf8", "ffi_bad_proto", "ffi_invalid_enum", "ffi_bad_shared_key", "ffi_nul_in_string", "transport_invalid", "no_usable_endpoint", "transport_send_failed"];
25
25
  export type DeRecErrorCode = (typeof DEREC_ERROR_CODES)[number];
26
26
  export interface DeRecError {
27
27
  category: DeRecErrorCategory;
@@ -38,7 +38,12 @@ export interface DeRecError {
38
38
  * Clear exactly these and retry `restore`.
39
39
  */
40
40
  channel_ids?: string[];
41
- /** The channel the failing inbound message arrived on, when `process()` could tell. */
41
+ /**
42
+ * The channel the error is about: the one named by
43
+ * `"channel_already_paired"`, `"fingerprint_mismatch"` and
44
+ * `"role_mismatch"`, or, on a failed `process()`, the channel the failing
45
+ * inbound message arrived on.
46
+ */
42
47
  channel_id?: string;
43
48
  /**
44
49
  * On a failed `process()`: the events it produced before failing, such as
package/lib/errors.js CHANGED
@@ -32,6 +32,7 @@ exports.DEREC_ERROR_CATEGORIES = [
32
32
  "protobuf",
33
33
  "invariant",
34
34
  "state_store",
35
+ "transport",
35
36
  ];
36
37
  /**
37
38
  * Every code `derec_error_code_name` can return, and no others.
@@ -59,6 +60,7 @@ exports.DEREC_ERROR_CODES = [
59
60
  "already_restored",
60
61
  "restore_conflict",
61
62
  "replica_id_conflict",
63
+ "fingerprint_mismatch",
62
64
  "encryption",
63
65
  "keygen",
64
66
  "finish_pairing_initiator",
@@ -71,6 +73,8 @@ exports.DEREC_ERROR_CODES = [
71
73
  "missing_replica_id",
72
74
  "unexpected_replica_id",
73
75
  "incompatible_parameter_range",
76
+ "fingerprint_commitment_mismatch",
77
+ "pairing_expired",
74
78
  "empty_channels",
75
79
  "duplicate_channel_id",
76
80
  "invalid_threshold",
@@ -78,6 +82,7 @@ exports.DEREC_ERROR_CODES = [
78
82
  "vss_share_failed",
79
83
  "invalid_weight",
80
84
  "too_many_subshares",
85
+ "invalid_keep_version",
81
86
  "empty_responses",
82
87
  "empty_committed_derec_share",
83
88
  "decode_committed_derec_share",
@@ -94,4 +99,5 @@ exports.DEREC_ERROR_CODES = [
94
99
  "ffi_nul_in_string",
95
100
  "transport_invalid",
96
101
  "no_usable_endpoint",
102
+ "transport_send_failed",
97
103
  ];
package/lib/messages.js CHANGED
@@ -33,9 +33,9 @@ exports.encodeOptionalMessage = encodeOptionalMessage;
33
33
  * surface.
34
34
  *
35
35
  * Both conversions are keyed by field name, matching the lists in
36
- * `message_json.rs`. A name-keyed walk is deliberate: `keep_list` is a
37
- * genuine `number[]` and must stay one, so a structural "array of numbers is
38
- * bytes" rule would corrupt it.
36
+ * `message_json.rs`. A name-keyed walk is deliberate: only the fields that
37
+ * file names change representation, so a structural "array of numbers is
38
+ * bytes" rule cannot corrupt a field that is not bytes.
39
39
  */
40
40
  const codec_1 = require("./codec");
41
41
  const native_1 = require("./native");
@@ -96,6 +96,8 @@ const BYTE_FIELDS = new Set([
96
96
  'mlkem_encapsulation_key',
97
97
  'ecies_public_key',
98
98
  'contact_binding_hash',
99
+ 'fingerprint_commitment',
100
+ 'fingerprint_nonce',
99
101
  'bytes_value',
100
102
  'share',
101
103
  'committed_de_rec_share',
@@ -1,4 +1,4 @@
1
- import type { CommittedDeRecShare, CommunicationInfo, ContactMessage, ContactMode, CreateContactResult, DiscoveryProcessResult, GetSecretIdsVersionsRequestMessage, GetSecretIdsVersionsResponseMessage, GetShareRequestMessage, GetShareResponseMessage, PairRequestMessage, PairResponseMessage, PairingProcessResult, PairingRequestProduceResult, PairingResponseProduceResult, ParameterRange, PrePairRequestExtractResult, PrePairRequestMessage, PrePairResponseExtractResult, PrePairResponseMessage, ProcessPrePairResult, ProducePrePairNoKeysResult, ProducePrePairResult, ProduceResult, RecoverResult, SecretVersionEntry, SenderKind, SharingResponseProduceResult, SplitResult, StoreShareRequestMessage, StoreShareResponseMessage, TransportProtocol, UnpairRequestMessage, UnpairResponseMessage, UnpairingProcessResult, VerifyShareRequestMessage, VerifyShareResponseMessage, WeightedChannel } from './types';
1
+ import type { CommittedDeRecShare, CommunicationInfo, ContactMessage, ContactMode, CreateContactResult, DiscoveryProcessResult, GetSecretIdsVersionsRequestMessage, GetSecretIdsVersionsResponseMessage, GetShareRequestMessage, GetShareResponseMessage, MessageId, PairRequestMessage, PairResponseMessage, PairingProcessResult, PairingRequestProduceResult, PairingResponseProduceResult, ParameterRange, PrePairRequestExtractResult, PrePairRequestMessage, PrePairResponseExtractResult, PrePairResponseMessage, ProcessPrePairResult, ProducePrePairNoKeysResult, ProducePrePairResult, ProduceResult, RecoverResult, SecretVersionEntry, SenderKind, SharingResponseProduceResult, SplitResult, StoreShareRequestMessage, StoreShareResponseMessage, TransportProtocol, UnpairRequestMessage, UnpairResponseMessage, UnpairingProcessResult, VerifyShareRequestMessage, VerifyShareResponseMessage, WeightedChannel } from './types';
2
2
  export declare const primitives: {
3
3
  discovery: {
4
4
  request: {
@@ -68,7 +68,7 @@ export declare const primitives: {
68
68
  sharing: {
69
69
  request: {
70
70
  split(channels: WeightedChannel[], secret_id: bigint, version: number, secret_data: Uint8Array, threshold: number): SplitResult;
71
- produce(channel_id: bigint, version: number, secret_id: bigint, committed_share: CommittedDeRecShare, keep_list: number[], description: string, shared_key: Uint8Array, reply_to?: TransportProtocol[]): ProduceResult;
71
+ produce(channel_id: bigint, version: number, secret_id: bigint, committed_share: CommittedDeRecShare, keep_version: number, description: string, shared_key: Uint8Array, reply_to?: TransportProtocol[]): ProduceResult;
72
72
  extract(envelope_bytes: Uint8Array, shared_key: Uint8Array): {
73
73
  request: StoreShareRequestMessage;
74
74
  };
@@ -131,4 +131,14 @@ export declare const primitives: {
131
131
  export declare const envelope: {
132
132
  apply_trace_id(envelope_bytes: Uint8Array, trace_id: bigint): Uint8Array;
133
133
  read_trace_id(envelope_bytes: Uint8Array): bigint;
134
+ /**
135
+ * Identify an envelope for replay and reflection detection. `id` is the
136
+ * same for every copy of one message, whatever its unauthenticated
137
+ * cleartext fields say, and different for every other message. Keep the
138
+ * `id` of every envelope sent and of every envelope `process` accepted
139
+ * until `max(received or sent at, timestamp) + inbound_message_secs`, keep
140
+ * the record across restarts, and drop an inbound envelope whose `id` is
141
+ * kept. The README has the full contract.
142
+ */
143
+ message_id(envelope_bytes: Uint8Array): MessageId;
134
144
  };
package/lib/primitives.js CHANGED
@@ -214,6 +214,7 @@ const pairing = {
214
214
  mlkem_encapsulation_key: bytes(result.mlkem_encapsulation_key),
215
215
  ecies_public_key: bytes(result.ecies_public_key),
216
216
  nonce: result.nonce,
217
+ fingerprint_commitment: bytes(result.fingerprint_commitment),
217
218
  };
218
219
  },
219
220
  produce_pre_pair_no_keys(channel_id, request) {
@@ -229,6 +230,7 @@ const pairing = {
229
230
  mlkem_encapsulation_key: bytes(result.mlkem_encapsulation_key),
230
231
  ecies_public_key: bytes(result.ecies_public_key),
231
232
  nonce: result.nonce,
233
+ fingerprint_commitment: bytes(result.fingerprint_commitment),
232
234
  };
233
235
  },
234
236
  },
@@ -279,8 +281,8 @@ const sharing = {
279
281
  }
280
282
  return { shares };
281
283
  },
282
- produce(channel_id, version, secret_id, committed_share, keep_list, description, shared_key, reply_to) {
283
- const envelope = call('produce_store_share_request_message', channel_id, version, secret_id, (0, messages_1.encodeMessage)(messages_1.MessageKind.CommittedDeRecShare, committed_share), keep_list, (0, codec_1.utf8Encode)(description), shared_key, replyTo(reply_to));
284
+ produce(channel_id, version, secret_id, committed_share, keep_version, description, shared_key, reply_to) {
285
+ const envelope = call('produce_store_share_request_message', channel_id, version, secret_id, (0, messages_1.encodeMessage)(messages_1.MessageKind.CommittedDeRecShare, committed_share), keep_version, (0, codec_1.utf8Encode)(description), shared_key, replyTo(reply_to));
284
286
  return { envelope: bytes(envelope) };
285
287
  },
286
288
  extract(envelope_bytes, shared_key) {
@@ -401,4 +403,17 @@ exports.envelope = {
401
403
  read_trace_id(envelope_bytes) {
402
404
  return call('read_trace_id_from_envelope', envelope_bytes);
403
405
  },
406
+ /**
407
+ * Identify an envelope for replay and reflection detection. `id` is the
408
+ * same for every copy of one message, whatever its unauthenticated
409
+ * cleartext fields say, and different for every other message. Keep the
410
+ * `id` of every envelope sent and of every envelope `process` accepted
411
+ * until `max(received or sent at, timestamp) + inbound_message_secs`, keep
412
+ * the record across restarts, and drop an inbound envelope whose `id` is
413
+ * kept. The README has the full contract.
414
+ */
415
+ message_id(envelope_bytes) {
416
+ const result = call('message_id_from_envelope', envelope_bytes);
417
+ return { id: bytes(result.id), timestamp: result.timestamp };
418
+ },
404
419
  };
package/lib/protocol.d.ts CHANGED
@@ -277,22 +277,26 @@ export declare class DeRecProtocol {
277
277
  getFingerprint(channelId: bigint | number): Promise<string>;
278
278
  /**
279
279
  * Verify `fingerprint` against the channel's locally-derived one. On
280
- * match, the channel transitions from `Pending` to `Paired`. Returns
281
- * `true` on confirmation, `false` on mismatch.
280
+ * match, the channel transitions from `Pending` to `Paired`.
281
+ *
282
+ * A mismatch rejects with code `fingerprint_mismatch` — a possible
283
+ * man-in-the-middle. A `Pending` pairing is revoked: its records, channel
284
+ * key and pairing material are deleted, so pair again. A channel already
285
+ * `Paired` is left as it is.
282
286
  *
283
287
  * On a replica destination, confirming is also the decision to adopt the
284
288
  * group's vault: the source's publish is then installed as it arrives,
285
289
  * with no further prompt. Ask the user before calling this; to decline,
286
- * never confirm.
290
+ * never confirm: expired-channel cleanup removes the channel and its key.
287
291
  *
288
292
  * On a promotion the current snapshot is published to the promoted peer,
289
293
  * reusing the stored helper weights. If one is no longer valid under the
290
294
  * current threshold, that publish fails with `invalid_weight` before
291
295
  * anything is sent and this throws. The promotion stands: calling this
292
- * again resolves `true` and publishes nothing, so call `start` with
296
+ * again resolves and publishes nothing, so call `start` with
293
297
  * `ProtectSecret` and valid weights to reach the promoted peer.
294
298
  */
295
- verifyFingerprint(channelId: bigint | number, fingerprint: string): Promise<boolean>;
299
+ verifyFingerprint(channelId: bigint | number, fingerprint: string): Promise<void>;
296
300
  removeExpiredChannels(olderThanSecs: number): Promise<string[]>;
297
301
  /**
298
302
  * Rebuild this protocol's `secret_id` namespace from a recovered `Secret`.
package/lib/protocol.js CHANGED
@@ -643,23 +643,27 @@ class DeRecProtocol {
643
643
  }
644
644
  /**
645
645
  * Verify `fingerprint` against the channel's locally-derived one. On
646
- * match, the channel transitions from `Pending` to `Paired`. Returns
647
- * `true` on confirmation, `false` on mismatch.
646
+ * match, the channel transitions from `Pending` to `Paired`.
647
+ *
648
+ * A mismatch rejects with code `fingerprint_mismatch` — a possible
649
+ * man-in-the-middle. A `Pending` pairing is revoked: its records, channel
650
+ * key and pairing material are deleted, so pair again. A channel already
651
+ * `Paired` is left as it is.
648
652
  *
649
653
  * On a replica destination, confirming is also the decision to adopt the
650
654
  * group's vault: the source's publish is then installed as it arrives,
651
655
  * with no further prompt. Ask the user before calling this; to decline,
652
- * never confirm.
656
+ * never confirm: expired-channel cleanup removes the channel and its key.
653
657
  *
654
658
  * On a promotion the current snapshot is published to the promoted peer,
655
659
  * reusing the stored helper weights. If one is no longer valid under the
656
660
  * current threshold, that publish fails with `invalid_weight` before
657
661
  * anything is sent and this throws. The promotion stands: calling this
658
- * again resolves `true` and publishes nothing, so call `start` with
662
+ * again resolves and publishes nothing, so call `start` with
659
663
  * `ProtectSecret` and valid weights to reach the promoted peer.
660
664
  */
661
665
  async verifyFingerprint(channelId, fingerprint) {
662
- return (await this.host.verifyFingerprint(toBigInt(channelId), fingerprint));
666
+ await this.host.verifyFingerprint(toBigInt(channelId), fingerprint);
663
667
  }
664
668
  async removeExpiredChannels(olderThanSecs) {
665
669
  const buffer = (await this.host.removeExpiredChannels(olderThanSecs));