@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
package/README.md CHANGED
@@ -161,13 +161,13 @@ A stored proof is either confirmed by its helper or part of a sharing round
161
161
  still open: when a round settles a channel as failed (a rejection or a
162
162
  timeout), that channel's proof is deleted. A confirmation also deletes the
163
163
  proofs of versions the helper dropped: a helper that stores a version
164
- deletes every other version that round's `keepList` leaves out, so when it
164
+ deletes every other version except that round's `keepVersion`, so when it
165
165
  confirms, its proofs for those versions are deleted here too (the confirmed
166
- version stays). A helper that rejects the round keeps its older versions, and
167
- so do their proofs; with no keep list nothing is deleted. A replica Destination never sees the helpers' answers, and it keeps every
166
+ version and `keepVersion` stay). A helper that rejects the round keeps its
167
+ older versions, and so do their proofs. A replica Destination never sees the helpers' answers, and it keeps every
168
168
  proof it receives: it never deletes one on its own, and freeing that storage
169
169
  is the app's concern. Verifying on a Destination a version that a helper
170
- refused, or later dropped under the `keepList`, gets `ShareVerifyRejected`
170
+ refused, or later dropped under a `keepVersion`, gets `ShareVerifyRejected`
171
171
  (`UNKNOWN_SHARE_VERSION`) from that helper, where the Source reports
172
172
  `NoProof`. The app may delete such rows from the Destination's share store;
173
173
  verifying a version whose rows are gone then gives `VerifySharesFailed` with
@@ -178,6 +178,18 @@ proof sends nothing and returns `VerifySharesFailed` with
178
178
  ignored as `MessageIgnored` with `reason: 'StaleResponse'`, and the current
179
179
  challenge stays open; a response missing its `result` is still an error.
180
180
 
181
+ Matching responses to requests is the app's concern. The library applies a
182
+ response that changes stored state only against the flow that asked for it,
183
+ and reports the rest as they arrive without matching them: `ShareConfirmed`
184
+ and `ShareRejected` (a sharing round counts only the helpers it is waiting
185
+ for), `SecretsDiscovered`, `ChannelInfoUpdated`, `ChannelInfoUpdateRejected`
186
+ and `ErrorResponseReceived`. An app that acts on these should record what it
187
+ started and match each event against it, and decide which versions committed
188
+ from `SharingComplete` with `threshold_met` rather than by counting
189
+ `ShareConfirmed`, since a helper can confirm twice or unasked. See [Matching
190
+ responses to requests is the application's
191
+ job](https://github.com/derecalliance/lib-derec/tree/main/library#matching-responses-to-requests-is-the-applications-job).
192
+
181
193
  **After recovery: restore or join.** `SecretRecovered` writes nothing, so
182
194
  decide before calling `restore`. When `secret.replicas?.members` names live
183
195
  members other than the lost device, do not restore: tell the user and offer
@@ -303,9 +315,10 @@ declared in `src/types.ts`:
303
315
  - **`ChannelStore`** — pairing state: helper channels and replica-group
304
316
  membership, keyed by `(channelId, replicaId)`.
305
317
  - **`ShareStore`** — versioned VSS shares this device holds as a helper.
306
- On an owner, `keepList` chooses which versions helpers keep; returning
307
- `null` sends no keepList, so helpers keep every version; see
308
- [the owner's keep list](https://github.com/derecalliance/lib-derec/tree/main/library#share-store-the-owners-keep-list).
318
+ On an owner, `keepVersion` chooses the one older version helpers keep
319
+ besides the one being shared (`0` keeps none); an answer equal to or
320
+ greater than that version fails the round with `invalid_keep_version`; see
321
+ [`DeRecShareStore::keep_version`](https://docs.rs/derec-library/latest/derec_library/protocol/traits/trait.DeRecShareStore.html#tymethod.keep_version).
309
322
  - **`SecretStore`** — small per-channel key material (shared keys, etc.),
310
323
  distinct from share bytes.
311
324
  - **`UserSecretStore`** — the most recent user-facing secret snapshot per
@@ -209,8 +209,7 @@ std::vector<uint64_t> asU64Array(jsi::Runtime& rt, const char* name, const jsi::
209
209
  }
210
210
 
211
211
  /// Read a JS array of `number` elements as a `uint32_t` vector. Used for
212
- /// `protect_secret`'s `weights` and
213
- /// `produce_store_share_request_message`'s `keep_list` arguments.
212
+ /// `protect_secret`'s `weights` argument.
214
213
  std::vector<uint32_t> asU32Array(jsi::Runtime& rt, const char* name, const jsi::Value& value) {
215
214
  std::vector<uint32_t> out;
216
215
  if (value.isNull() || value.isUndefined()) {
@@ -761,7 +760,7 @@ jsi::Value extractPrePairResponse(jsi::Runtime& rt,
761
760
 
762
761
  /// `process_pre_pair_response_message(contactMessage: ArrayBuffer,
763
762
  /// responseProto: ArrayBuffer) -> { mlkem_encapsulation_key,
764
- /// ecies_public_key, nonce }`
763
+ /// ecies_public_key, nonce, fingerprint_commitment }`
765
764
  jsi::Value processPrePairResponseMessage(jsi::Runtime& rt,
766
765
  const jsi::Value&,
767
766
  const jsi::Value* args,
@@ -777,6 +776,7 @@ jsi::Value processPrePairResponseMessage(jsi::Runtime& rt,
777
776
  }
778
777
  std::vector<uint8_t> mlkemKey = takeBuffer(result.mlkem_encapsulation_key);
779
778
  std::vector<uint8_t> eciesKey = takeBuffer(result.ecies_public_key);
779
+ std::vector<uint8_t> commitment = takeBuffer(result.fingerprint_commitment);
780
780
  auto payload = jsi::Object(rt);
781
781
  payload.setProperty(rt, "mlkem_encapsulation_key",
782
782
  toArrayBuffer(rt, mlkemKey.data(), mlkemKey.size()));
@@ -784,6 +784,8 @@ jsi::Value processPrePairResponseMessage(jsi::Runtime& rt,
784
784
  toArrayBuffer(rt, eciesKey.data(), eciesKey.size()));
785
785
  payload.setProperty(rt, "nonce",
786
786
  jsi::Value(rt, jsi::BigInt::fromUint64(rt, result.nonce)));
787
+ payload.setProperty(rt, "fingerprint_commitment",
788
+ toArrayBuffer(rt, commitment.data(), commitment.size()));
787
789
  return jsi::Value(rt, payload);
788
790
  }
789
791
 
@@ -816,7 +818,7 @@ jsi::Value producePrePairNoKeysResponseMessage(jsi::Runtime& rt,
816
818
 
817
819
  /// `process_pre_pair_no_keys_response_message(contactMessage: ArrayBuffer,
818
820
  /// responseProto: ArrayBuffer) -> { mlkem_encapsulation_key,
819
- /// ecies_public_key, nonce }`
821
+ /// ecies_public_key, nonce, fingerprint_commitment }`
820
822
  jsi::Value processPrePairNoKeysResponseMessage(jsi::Runtime& rt,
821
823
  const jsi::Value&,
822
824
  const jsi::Value* args,
@@ -834,6 +836,7 @@ jsi::Value processPrePairNoKeysResponseMessage(jsi::Runtime& rt,
834
836
  }
835
837
  std::vector<uint8_t> mlkemKey = takeBuffer(result.mlkem_encapsulation_key);
836
838
  std::vector<uint8_t> eciesKey = takeBuffer(result.ecies_public_key);
839
+ std::vector<uint8_t> commitment = takeBuffer(result.fingerprint_commitment);
837
840
  auto payload = jsi::Object(rt);
838
841
  payload.setProperty(rt, "mlkem_encapsulation_key",
839
842
  toArrayBuffer(rt, mlkemKey.data(), mlkemKey.size()));
@@ -841,6 +844,8 @@ jsi::Value processPrePairNoKeysResponseMessage(jsi::Runtime& rt,
841
844
  toArrayBuffer(rt, eciesKey.data(), eciesKey.size()));
842
845
  payload.setProperty(rt, "nonce",
843
846
  jsi::Value(rt, jsi::BigInt::fromUint64(rt, result.nonce)));
847
+ payload.setProperty(rt, "fingerprint_commitment",
848
+ toArrayBuffer(rt, commitment.data(), commitment.size()));
844
849
  return jsi::Value(rt, payload);
845
850
  }
846
851
 
@@ -1004,7 +1009,7 @@ jsi::Value protectSecret(jsi::Runtime& rt,
1004
1009
  }
1005
1010
 
1006
1011
  /// `produce_store_share_request_message(channelId: bigint, version: number,
1007
- /// secretId: bigint, committedShare: ArrayBuffer, keepList: number[],
1012
+ /// secretId: bigint, committedShare: ArrayBuffer, keepVersion: number,
1008
1013
  /// description: ArrayBuffer, sharedKey: ArrayBuffer, replyTo:
1009
1014
  /// ArrayBuffer|null) -> ArrayBuffer`
1010
1015
  jsi::Value produceStoreShareRequestMessage(jsi::Runtime& rt,
@@ -1017,14 +1022,15 @@ jsi::Value produceStoreShareRequestMessage(jsi::Runtime& rt,
1017
1022
  rt, "produce_store_share_request_message", "version", args[1], std::numeric_limits<uint32_t>::max()));
1018
1023
  uint64_t secretId = asU64(rt, args[2]);
1019
1024
  ByteView committedShare = asBytes(rt, args[3]);
1020
- std::vector<uint32_t> keepList = asU32Array(rt, "produce_store_share_request_message", args[4]);
1025
+ auto keepVersion = static_cast<uint32_t>(asScalarInteger(
1026
+ rt, "produce_store_share_request_message", "keep_version", args[4], std::numeric_limits<uint32_t>::max()));
1021
1027
  ByteView description = asBytes(rt, args[5]);
1022
1028
  ByteView sharedKey = asBytes(rt, args[6]);
1023
1029
  ByteView replyTo = asBytes(rt, args[7]);
1024
1030
  ProduceStoreShareRequestMessageResult result =
1025
1031
  produce_store_share_request_message(
1026
1032
  channelId, version, secretId, committedShare.ptr,
1027
- committedShare.len, keepList.data(), keepList.size(),
1033
+ committedShare.len, keepVersion,
1028
1034
  description.ptr, description.len, sharedKey.ptr, sharedKey.len,
1029
1035
  replyTo.ptr, replyTo.len);
1030
1036
  if (result.error.code != 0) {
@@ -538,16 +538,15 @@ jsi::Value ProtocolHost::get(jsi::Runtime& rt, const jsi::PropNameID& name) {
538
538
  DeRecProtocolHandle* handle = handle_;
539
539
 
540
540
  auto body = [handle, channelId, fingerprint]() -> std::vector<uint8_t> {
541
- uint32_t matched = 0;
542
541
  DeRecError error = derec_protocol_verify_fingerprint(
543
- handle, channelId, fingerprint.c_str(), &matched);
542
+ handle, channelId, fingerprint.c_str());
544
543
  if (error.code != DEREC_CODE_OK) {
545
544
  throw FfiFailure(error);
546
545
  }
547
- return std::vector<uint8_t>{static_cast<uint8_t>(matched != 0 ? 1 : 0)};
546
+ return {};
548
547
  };
549
- auto convert = [](jsi::Runtime&, std::vector<uint8_t>& bytes) {
550
- return jsi::Value(!bytes.empty() && bytes[0] != 0);
548
+ auto convert = [](jsi::Runtime&, std::vector<uint8_t>&) {
549
+ return jsi::Value::undefined();
551
550
  };
552
551
  return runAsync(rt2, std::move(body), std::move(convert));
553
552
  });
@@ -335,38 +335,27 @@ CallResult toStateLoadAllResult(jsi::Runtime& rt, const jsi::Value& value) {
335
335
  return CallResult{0, std::vector<uint8_t>(text.begin(), text.end())};
336
336
  }
337
337
 
338
- /// `ShareStore.keepList(): Promise<number[] | null | undefined>`. Encodes the
339
- /// resolved value as the wire's `Option<Vec<u32>>` JSON: `null` for
340
- /// `null`/`undefined`, otherwise the array of versions.
338
+ /// `ShareStore.keepVersion(): Promise<number>`. Encodes the resolved version
339
+ /// as 4 little-endian bytes so the calling function can rebuild
340
+ /// `out_version`.
341
341
  ///
342
- /// Anything else, or an entry that is not an integer in `0..=4294967295`, is
343
- /// a backend failure: reading it as `null` would silently send an empty
344
- /// keepList, so helpers would keep every version instead of the list the
345
- /// application meant to send.
346
- CallResult toKeepListResult(jsi::Runtime& rt, const jsi::Value& value) {
347
- if (value.isNull() || value.isUndefined()) {
348
- return CallResult{0, {'n', 'u', 'l', 'l'}};
349
- }
350
- if (!value.isObject() || !value.asObject(rt).isArray(rt)) {
342
+ /// Anything other than an integer in `0..=4294967295` is a backend failure:
343
+ /// reading it as `0` would silently tell helpers to keep no other version.
344
+ CallResult toKeepVersionResult(jsi::Runtime&, const jsi::Value& value) {
345
+ if (!value.isNumber()) {
351
346
  return CallResult{kBackendFailure, {}};
352
347
  }
353
- jsi::Array arr = value.asObject(rt).asArray(rt);
354
- size_t n = arr.size(rt);
355
- std::string text = "[";
356
- for (size_t i = 0; i < n; ++i) {
357
- jsi::Value entry = arr.getValueAtIndex(rt, i);
358
- if (!entry.isNumber()) {
359
- return CallResult{kBackendFailure, {}};
360
- }
361
- double version = entry.asNumber();
362
- if (!(version >= 0 && version <= 4294967295.0) || version != static_cast<double>(static_cast<uint32_t>(version))) {
363
- return CallResult{kBackendFailure, {}};
364
- }
365
- if (i != 0) text += ',';
366
- text += std::to_string(static_cast<uint32_t>(version));
348
+ double raw = value.asNumber();
349
+ if (!(raw >= 0 && raw <= 4294967295.0) || raw != static_cast<double>(static_cast<uint32_t>(raw))) {
350
+ return CallResult{kBackendFailure, {}};
367
351
  }
368
- text += ']';
369
- return CallResult{0, std::vector<uint8_t>(text.begin(), text.end())};
352
+ auto version = static_cast<uint32_t>(raw);
353
+ std::vector<uint8_t> bytes(4);
354
+ bytes[0] = static_cast<uint8_t>(version & 0xFF);
355
+ bytes[1] = static_cast<uint8_t>((version >> 8) & 0xFF);
356
+ bytes[2] = static_cast<uint8_t>((version >> 16) & 0xFF);
357
+ bytes[3] = static_cast<uint8_t>((version >> 24) & 0xFF);
358
+ return CallResult{0, bytes};
370
359
  }
371
360
 
372
361
  /// Reads the `refusal` property a `ShareStore.save`/`recordVerification`
@@ -951,29 +940,28 @@ extern "C" int32_t shareStoreRemoveVersions(void* userData, uint64_t secretId, u
951
940
  return result.code;
952
941
  }
953
942
 
954
- /// `ShareStore.keepList(secretId, version) -> number[] | null`
955
- extern "C" int32_t shareStoreKeepList(void* userData, uint64_t secretId, uint32_t version, uint8_t** outPtr,
956
- size_t* outLen) {
943
+ /// `ShareStore.keepVersion(secretId, version) -> number`
944
+ extern "C" int32_t shareStoreKeepVersion(void* userData, uint64_t secretId, uint32_t version,
945
+ uint32_t* outVersion) {
957
946
  auto* self = static_cast<StoreBindings*>(userData);
958
947
  auto keepAlive = self->shared_from_this();
959
948
  CallResult result =
960
949
  keepAlive->bridge().callSync([keepAlive, secretId, version](std::function<void(CallResult)> settle) {
961
950
  jsi::Runtime& rt = keepAlive->runtime();
962
951
  auto store = keepAlive->shareStore();
963
- auto method = store->getPropertyAsFunction(rt, "keepList");
952
+ auto method = store->getPropertyAsFunction(rt, "keepVersion");
964
953
  jsi::Value promise =
965
954
  method.callWithThis(rt, *store, idVal(rt, secretId), jsi::Value(static_cast<double>(version)));
966
- keepAlive->settleFromPromise(rt, std::move(promise), std::move(settle), toKeepListResult);
955
+ keepAlive->settleFromPromise(rt, std::move(promise), std::move(settle), toKeepVersionResult);
967
956
  });
968
- if (result.code == 0) {
969
- if (!writeOut(result.bytes, outPtr, outLen)) {
970
- return kBackendFailure;
971
- }
972
- } else {
973
- *outPtr = nullptr;
974
- *outLen = 0;
957
+ if (result.code == 0 && result.bytes.size() == 4) {
958
+ *outVersion = static_cast<uint32_t>(result.bytes[0]) | (static_cast<uint32_t>(result.bytes[1]) << 8) |
959
+ (static_cast<uint32_t>(result.bytes[2]) << 16) |
960
+ (static_cast<uint32_t>(result.bytes[3]) << 24);
961
+ return 0;
975
962
  }
976
- return result.code;
963
+ *outVersion = 0;
964
+ return result.code == 0 ? kBackendFailure : result.code;
977
965
  }
978
966
 
979
967
  /// `UserSecretStore.loadLatest(secretId) -> UserSecrets | null`
@@ -1302,7 +1290,7 @@ std::shared_ptr<StoreBindings> StoreBindings::create(jsi::Runtime& rt, jsi::Obje
1302
1290
  shareStoreSave, // save
1303
1291
  shareStoreRemoveChannel, // remove_channel
1304
1292
  shareStoreRemoveVersions, // remove_versions
1305
- shareStoreKeepList, // keep_list
1293
+ shareStoreKeepVersion, // keep_version
1306
1294
  shareStoreRecordVerification, // record_verification
1307
1295
  storeFreeBuffer, // free_buffer
1308
1296
  };
@@ -1351,7 +1339,7 @@ std::shared_ptr<StoreBindings> StoreBindings::create(jsi::Runtime& rt, jsi::Obje
1351
1339
  requireField(rt, bindings->shareCallbacks_.save, "ShareStoreCallbacks.save");
1352
1340
  requireField(rt, bindings->shareCallbacks_.remove_channel, "ShareStoreCallbacks.remove_channel");
1353
1341
  requireField(rt, bindings->shareCallbacks_.remove_versions, "ShareStoreCallbacks.remove_versions");
1354
- requireField(rt, bindings->shareCallbacks_.keep_list, "ShareStoreCallbacks.keep_list");
1342
+ requireField(rt, bindings->shareCallbacks_.keep_version, "ShareStoreCallbacks.keep_version");
1355
1343
  requireField(rt, bindings->shareCallbacks_.record_verification,
1356
1344
  "ShareStoreCallbacks.record_verification");
1357
1345
  requireField(rt, bindings->shareCallbacks_.free_buffer, "ShareStoreCallbacks.free_buffer");
package/cpp/derec_ffi.h CHANGED
@@ -180,6 +180,13 @@
180
180
  */
181
181
  #define DEREC_CODE_REPLICA_ID_CONFLICT 16
182
182
 
183
+ /**
184
+ * `derec_protocol_verify_fingerprint`: the fingerprint compared out of band
185
+ * does not match the channel key — a possible man-in-the-middle. A `Pending`
186
+ * pairing has been revoked; pair again. `DEREC_CATEGORY_PAIRING`.
187
+ */
188
+ #define DEREC_CODE_FINGERPRINT_MISMATCH 17
189
+
183
190
  #define DEREC_CODE_ENCRYPTION 20
184
191
 
185
192
  #define DEREC_CODE_KEYGEN 21
@@ -229,6 +236,16 @@
229
236
  */
230
237
  #define DEREC_CODE_INCOMPATIBLE_PARAMETER_RANGE 47
231
238
 
239
+ /**
240
+ * The fingerprint nonce in a `PairResponseMessage` does not open the
241
+ * commitment the contact creator published with its keys. Surfaced as
242
+ * [`DEREC_CATEGORY_PAIRING`]; the pairing does not complete. Either the
243
+ * response or the keys did not come from the party that made the
244
+ * commitment, so applications can treat it as a possible
245
+ * man-in-the-middle.
246
+ */
247
+ #define DEREC_CODE_FINGERPRINT_COMMITMENT_MISMATCH 48
248
+
232
249
  #define DEREC_CODE_EMPTY_CHANNELS 60
233
250
 
234
251
  #define DEREC_CODE_DUPLICATE_CHANNEL_ID 61
@@ -243,6 +260,8 @@
243
260
 
244
261
  #define DEREC_CODE_TOO_MANY_SUBSHARES 66
245
262
 
263
+ #define DEREC_CODE_INVALID_KEEP_VERSION 67
264
+
246
265
  #define DEREC_CODE_EMPTY_RESPONSES 80
247
266
 
248
267
  #define DEREC_CODE_EMPTY_COMMITTED_DEREC_SHARE 81
@@ -704,6 +723,12 @@ typedef struct ProcessPrePairResponseMessageResult {
704
723
  * Nonce echoed from the original `ContactMessage`. Zero on failure.
705
724
  */
706
725
  uint64_t nonce;
726
+ /**
727
+ * The creator's 32-byte commitment to its fingerprint nonce. Carry it
728
+ * into the contact the pair request is built from, in
729
+ * `fingerprint_commitment`, alongside the two keys.
730
+ */
731
+ struct DeRecBuffer fingerprint_commitment;
707
732
  } ProcessPrePairResponseMessageResult;
708
733
 
709
734
  typedef struct PairingFingerprintResult {
@@ -865,10 +890,9 @@ typedef struct SecretStoreCallbacks {
865
890
  * is none, and absent or `null` reads as none. Store them as given and return
866
891
  * them unchanged.
867
892
  *
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`.
893
+ * `keep_version` writes the application's answer to `out_version`: the one
894
+ * version, other than `version`, every helper keeps, or `0` to keep no
895
+ * other version. Any non-zero return code is a backend failure.
872
896
  *
873
897
  * `save` and `record_verification` share a return-code convention: `0` is
874
898
  * success; `3`/`4`/`10` (the
@@ -920,11 +944,10 @@ typedef struct ShareStoreCallbacks {
920
944
  uint64_t channel_id,
921
945
  const uint8_t *versions_json_ptr,
922
946
  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);
947
+ int32_t (*keep_version)(void *user_data,
948
+ uint64_t secret_id,
949
+ uint32_t version,
950
+ uint32_t *out_version);
928
951
  int32_t (*record_verification)(void *user_data,
929
952
  uint64_t secret_id,
930
953
  uint64_t channel_id,
@@ -2111,34 +2134,23 @@ struct DeRecProtocolFingerprintResult derec_protocol_get_fingerprint(struct DeRe
2111
2134
  * Verify a fingerprint against the channel's locally-derived one. See
2112
2135
  * [`crate::protocol::DeRecProtocol::verify_fingerprint`].
2113
2136
  *
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.
2137
+ * Success means the comparison matched and the channel is confirmed. Every
2138
+ * other outcome is an error envelope; a mismatch is
2139
+ * [`DEREC_CODE_FINGERPRINT_MISMATCH`](crate::interop::ffi::error::DEREC_CODE_FINGERPRINT_MISMATCH),
2140
+ * after which a `Pending` pairing has been revoked. There is no verdict to
2141
+ * read apart from the envelope, so a caller cannot mistake a failure for a
2142
+ * match.
2130
2143
  *
2131
2144
  * # Safety
2132
2145
  *
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.
2146
+ * `handle` must be a valid pointer. `fingerprint_ptr` must be a valid
2147
+ * pointer to a NUL-terminated C string. Concurrent calls on the same handle
2148
+ * from different threads are safe: the handle's internal mutex serializes
2149
+ * them.
2137
2150
  */
2138
2151
  struct DeRecError derec_protocol_verify_fingerprint(struct DeRecProtocolHandle *handle,
2139
2152
  uint64_t channel_id,
2140
- const char *fingerprint_ptr,
2141
- uint32_t *out_matched);
2153
+ const char *fingerprint_ptr);
2142
2154
 
2143
2155
  /**
2144
2156
  * Generate an out-of-band contact message used to bootstrap pairing.
@@ -2310,8 +2322,7 @@ struct ProduceStoreShareRequestMessageResult produce_store_share_request_message
2310
2322
  uint64_t secret_id,
2311
2323
  const uint8_t *committed_share_ptr,
2312
2324
  size_t committed_share_len,
2313
- const uint32_t *keep_list_ptr,
2314
- size_t keep_list_len,
2325
+ uint32_t keep_version,
2315
2326
  const uint8_t *description_ptr,
2316
2327
  size_t description_len,
2317
2328
  const uint8_t *shared_key_ptr,
@@ -10,18 +10,15 @@
10
10
  <key>HeadersPath</key>
11
11
  <string>Headers</string>
12
12
  <key>LibraryIdentifier</key>
13
- <string>ios-arm64_x86_64-simulator</string>
13
+ <string>ios-arm64</string>
14
14
  <key>LibraryPath</key>
15
15
  <string>libderec_library.a</string>
16
16
  <key>SupportedArchitectures</key>
17
17
  <array>
18
18
  <string>arm64</string>
19
- <string>x86_64</string>
20
19
  </array>
21
20
  <key>SupportedPlatform</key>
22
21
  <string>ios</string>
23
- <key>SupportedPlatformVariant</key>
24
- <string>simulator</string>
25
22
  </dict>
26
23
  <dict>
27
24
  <key>BinaryPath</key>
@@ -29,15 +26,18 @@
29
26
  <key>HeadersPath</key>
30
27
  <string>Headers</string>
31
28
  <key>LibraryIdentifier</key>
32
- <string>ios-arm64</string>
29
+ <string>ios-arm64_x86_64-simulator</string>
33
30
  <key>LibraryPath</key>
34
31
  <string>libderec_library.a</string>
35
32
  <key>SupportedArchitectures</key>
36
33
  <array>
37
34
  <string>arm64</string>
35
+ <string>x86_64</string>
38
36
  </array>
39
37
  <key>SupportedPlatform</key>
40
38
  <string>ios</string>
39
+ <key>SupportedPlatformVariant</key>
40
+ <string>simulator</string>
41
41
  </dict>
42
42
  </array>
43
43
  <key>CFBundlePackageType</key>
@@ -180,6 +180,13 @@
180
180
  */
181
181
  #define DEREC_CODE_REPLICA_ID_CONFLICT 16
182
182
 
183
+ /**
184
+ * `derec_protocol_verify_fingerprint`: the fingerprint compared out of band
185
+ * does not match the channel key — a possible man-in-the-middle. A `Pending`
186
+ * pairing has been revoked; pair again. `DEREC_CATEGORY_PAIRING`.
187
+ */
188
+ #define DEREC_CODE_FINGERPRINT_MISMATCH 17
189
+
183
190
  #define DEREC_CODE_ENCRYPTION 20
184
191
 
185
192
  #define DEREC_CODE_KEYGEN 21
@@ -229,6 +236,16 @@
229
236
  */
230
237
  #define DEREC_CODE_INCOMPATIBLE_PARAMETER_RANGE 47
231
238
 
239
+ /**
240
+ * The fingerprint nonce in a `PairResponseMessage` does not open the
241
+ * commitment the contact creator published with its keys. Surfaced as
242
+ * [`DEREC_CATEGORY_PAIRING`]; the pairing does not complete. Either the
243
+ * response or the keys did not come from the party that made the
244
+ * commitment, so applications can treat it as a possible
245
+ * man-in-the-middle.
246
+ */
247
+ #define DEREC_CODE_FINGERPRINT_COMMITMENT_MISMATCH 48
248
+
232
249
  #define DEREC_CODE_EMPTY_CHANNELS 60
233
250
 
234
251
  #define DEREC_CODE_DUPLICATE_CHANNEL_ID 61
@@ -243,6 +260,8 @@
243
260
 
244
261
  #define DEREC_CODE_TOO_MANY_SUBSHARES 66
245
262
 
263
+ #define DEREC_CODE_INVALID_KEEP_VERSION 67
264
+
246
265
  #define DEREC_CODE_EMPTY_RESPONSES 80
247
266
 
248
267
  #define DEREC_CODE_EMPTY_COMMITTED_DEREC_SHARE 81
@@ -704,6 +723,12 @@ typedef struct ProcessPrePairResponseMessageResult {
704
723
  * Nonce echoed from the original `ContactMessage`. Zero on failure.
705
724
  */
706
725
  uint64_t nonce;
726
+ /**
727
+ * The creator's 32-byte commitment to its fingerprint nonce. Carry it
728
+ * into the contact the pair request is built from, in
729
+ * `fingerprint_commitment`, alongside the two keys.
730
+ */
731
+ struct DeRecBuffer fingerprint_commitment;
707
732
  } ProcessPrePairResponseMessageResult;
708
733
 
709
734
  typedef struct PairingFingerprintResult {
@@ -865,10 +890,9 @@ typedef struct SecretStoreCallbacks {
865
890
  * is none, and absent or `null` reads as none. Store them as given and return
866
891
  * them unchanged.
867
892
  *
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`.
893
+ * `keep_version` writes the application's answer to `out_version`: the one
894
+ * version, other than `version`, every helper keeps, or `0` to keep no
895
+ * other version. Any non-zero return code is a backend failure.
872
896
  *
873
897
  * `save` and `record_verification` share a return-code convention: `0` is
874
898
  * success; `3`/`4`/`10` (the
@@ -920,11 +944,10 @@ typedef struct ShareStoreCallbacks {
920
944
  uint64_t channel_id,
921
945
  const uint8_t *versions_json_ptr,
922
946
  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);
947
+ int32_t (*keep_version)(void *user_data,
948
+ uint64_t secret_id,
949
+ uint32_t version,
950
+ uint32_t *out_version);
928
951
  int32_t (*record_verification)(void *user_data,
929
952
  uint64_t secret_id,
930
953
  uint64_t channel_id,
@@ -2111,34 +2134,23 @@ struct DeRecProtocolFingerprintResult derec_protocol_get_fingerprint(struct DeRe
2111
2134
  * Verify a fingerprint against the channel's locally-derived one. See
2112
2135
  * [`crate::protocol::DeRecProtocol::verify_fingerprint`].
2113
2136
  *
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.
2137
+ * Success means the comparison matched and the channel is confirmed. Every
2138
+ * other outcome is an error envelope; a mismatch is
2139
+ * [`DEREC_CODE_FINGERPRINT_MISMATCH`](crate::interop::ffi::error::DEREC_CODE_FINGERPRINT_MISMATCH),
2140
+ * after which a `Pending` pairing has been revoked. There is no verdict to
2141
+ * read apart from the envelope, so a caller cannot mistake a failure for a
2142
+ * match.
2130
2143
  *
2131
2144
  * # Safety
2132
2145
  *
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.
2146
+ * `handle` must be a valid pointer. `fingerprint_ptr` must be a valid
2147
+ * pointer to a NUL-terminated C string. Concurrent calls on the same handle
2148
+ * from different threads are safe: the handle's internal mutex serializes
2149
+ * them.
2137
2150
  */
2138
2151
  struct DeRecError derec_protocol_verify_fingerprint(struct DeRecProtocolHandle *handle,
2139
2152
  uint64_t channel_id,
2140
- const char *fingerprint_ptr,
2141
- uint32_t *out_matched);
2153
+ const char *fingerprint_ptr);
2142
2154
 
2143
2155
  /**
2144
2156
  * Generate an out-of-band contact message used to bootstrap pairing.
@@ -2310,8 +2322,7 @@ struct ProduceStoreShareRequestMessageResult produce_store_share_request_message
2310
2322
  uint64_t secret_id,
2311
2323
  const uint8_t *committed_share_ptr,
2312
2324
  size_t committed_share_len,
2313
- const uint32_t *keep_list_ptr,
2314
- size_t keep_list_len,
2325
+ uint32_t keep_version,
2315
2326
  const uint8_t *description_ptr,
2316
2327
  size_t description_len,
2317
2328
  const uint8_t *shared_key_ptr,