@derec-alliance/react-native 0.0.8 → 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 (50) hide show
  1. package/README.md +410 -9
  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/Convert.cpp +9 -0
  6. package/cpp/Convert.h +8 -2
  7. package/cpp/Primitives.cpp +123 -29
  8. package/cpp/ProtocolHost.cpp +4 -5
  9. package/cpp/StoreCallbacks.cpp +148 -61
  10. package/cpp/StoreCallbacks.h +8 -1
  11. package/cpp/derec_ffi.h +127 -48
  12. package/ios/DeRecFFI.xcframework/Info.plist +5 -5
  13. package/ios/DeRecFFI.xcframework/ios-arm64/Headers/derec_ffi.h +127 -48
  14. package/ios/DeRecFFI.xcframework/ios-arm64/libderec_library.a +0 -0
  15. package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/Headers/derec_ffi.h +127 -48
  16. package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/libderec_library.a +2 -2
  17. package/lib/errors.d.ts +11 -1
  18. package/lib/errors.js +66 -1
  19. package/lib/messages.js +5 -3
  20. package/lib/primitives.d.ts +3 -3
  21. package/lib/primitives.js +7 -3
  22. package/lib/protocol.d.ts +110 -10
  23. package/lib/protocol.js +166 -11
  24. package/lib/types.d.ts +474 -48
  25. package/lib/types.js +23 -1
  26. package/package.json +4 -17
  27. package/schema/derec_descriptor.bin +0 -0
  28. package/schema/proto/committedderecshare.proto +93 -0
  29. package/schema/proto/communicationinfo.proto +104 -0
  30. package/schema/proto/contact.proto +258 -0
  31. package/schema/proto/derecmessage.proto +232 -0
  32. package/schema/proto/derecsecret.proto +163 -0
  33. package/schema/proto/derectransport.proto +38 -0
  34. package/schema/proto/error.proto +68 -0
  35. package/schema/proto/getshare.proto +184 -0
  36. package/schema/proto/pair.proto +284 -0
  37. package/schema/proto/parameterrange.proto +36 -0
  38. package/schema/proto/prepair.proto +163 -0
  39. package/schema/proto/result.proto +194 -0
  40. package/schema/proto/secretidsversions.proto +199 -0
  41. package/schema/proto/storeshare.proto +242 -0
  42. package/schema/proto/transportprotocol.proto +112 -0
  43. package/schema/proto/unpair.proto +132 -0
  44. package/schema/proto/updatechannelinfo.proto +100 -0
  45. package/schema/proto/verify.proto +160 -0
  46. package/src/errors.ts +69 -1
  47. package/src/messages.ts +5 -3
  48. package/src/primitives.ts +19 -4
  49. package/src/protocol.ts +175 -13
  50. package/src/types.ts +481 -52
@@ -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
@@ -239,6 +256,12 @@
239
256
 
240
257
  #define DEREC_CODE_VSS_SHARE_FAILED 64
241
258
 
259
+ #define DEREC_CODE_INVALID_WEIGHT 65
260
+
261
+ #define DEREC_CODE_TOO_MANY_SUBSHARES 66
262
+
263
+ #define DEREC_CODE_INVALID_KEEP_VERSION 67
264
+
242
265
  #define DEREC_CODE_EMPTY_RESPONSES 80
243
266
 
244
267
  #define DEREC_CODE_EMPTY_COMMITTED_DEREC_SHARE 81
@@ -289,6 +312,20 @@
289
312
  */
290
313
  #define DEREC_CODE_NO_USABLE_ENDPOINT 121
291
314
 
315
+ /**
316
+ * Return codes for [`crate::interop::ffi::protocol::stores::ShareStoreCallbacks::save`]
317
+ * and `ShareStoreCallbacks::record_verification`: `0` is success, each of
318
+ * these three refuses the write/verification with the matching
319
+ * [`crate::protocol::Refusal`] variant, and any other non-zero value is an
320
+ * ordinary backend failure. The values are the `StatusEnum` numbers the
321
+ * helper answers the owner with, not FFI-local codes.
322
+ */
323
+ #define DEREC_SHARE_STORE_REFUSED_SIZE_LIMIT_EXCEEDED 3
324
+
325
+ #define DEREC_SHARE_STORE_REFUSED_TOO_FREQUENT 4
326
+
327
+ #define DEREC_SHARE_STORE_REFUSED_REJECTED 10
328
+
292
329
  /**
293
330
  * Discriminants selecting which message [`derec_decode_message_json`] and
294
331
  * [`derec_encode_message_json`] operate on.
@@ -686,6 +723,12 @@ typedef struct ProcessPrePairResponseMessageResult {
686
723
  * Nonce echoed from the original `ContactMessage`. Zero on failure.
687
724
  */
688
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;
689
732
  } ProcessPrePairResponseMessageResult;
690
733
 
691
734
  typedef struct PairingFingerprintResult {
@@ -838,10 +881,30 @@ typedef struct SecretStoreCallbacks {
838
881
  * strings, matching the `Vec<u8>` ↔ JSON-array convention used for
839
882
  * every other wire-format buffer in this module.
840
883
  *
841
- * `keep_list` returns the JSON encoding of the application's answer:
842
- * `null` for no list (the owner sends an empty `keepList` and helpers keep
843
- * every version) or an array of version numbers. An empty buffer or return code `1` also
844
- * means `null`.
884
+ * A share crosses as the JSON object
885
+ * `{ "secret_id": "<u64>", "version": <u32>, "bytes": [..], "subshares": <u32>, "threshold": <u32> }`.
886
+ * `subshares` is the owner-side subshare count
887
+ * ([`crate::protocol::types::Share::subshares`]) and `threshold` the
888
+ * owner-side threshold the version was split with
889
+ * ([`crate::protocol::types::Share::threshold`]). Each is omitted when there
890
+ * is none, and absent or `null` reads as none. Store them as given and return
891
+ * them unchanged.
892
+ *
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.
896
+ *
897
+ * `save` and `record_verification` share a return-code convention: `0` is
898
+ * success; `3`/`4`/`10` (the
899
+ * [`DEREC_SHARE_STORE_REFUSED_SIZE_LIMIT_EXCEEDED`](crate::interop::ffi::error::DEREC_SHARE_STORE_REFUSED_SIZE_LIMIT_EXCEEDED) /
900
+ * [`DEREC_SHARE_STORE_REFUSED_TOO_FREQUENT`](crate::interop::ffi::error::DEREC_SHARE_STORE_REFUSED_TOO_FREQUENT) /
901
+ * [`DEREC_SHARE_STORE_REFUSED_REJECTED`](crate::interop::ffi::error::DEREC_SHARE_STORE_REFUSED_REJECTED)
902
+ * constants) refuse the call with the matching
903
+ * [`crate::protocol::Refusal`] variant; any other non-zero value is an
904
+ * ordinary backend failure. `record_verification` is called once per
905
+ * accepted verification challenge, after the challenged share is found and
906
+ * before the helper answers — see
907
+ * [`crate::protocol::DeRecShareStore::record_verification`].
845
908
  */
846
909
  typedef struct ShareStoreCallbacks {
847
910
  void *user_data;
@@ -881,18 +944,23 @@ typedef struct ShareStoreCallbacks {
881
944
  uint64_t channel_id,
882
945
  const uint8_t *versions_json_ptr,
883
946
  size_t versions_json_len);
884
- int32_t (*keep_list)(void *user_data,
885
- uint64_t secret_id,
886
- uint32_t version,
887
- uint8_t **out_ptr,
888
- 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);
951
+ int32_t (*record_verification)(void *user_data,
952
+ uint64_t secret_id,
953
+ uint64_t channel_id,
954
+ uint32_t version);
889
955
  void (*free_buffer)(void *user_data, uint8_t *ptr, size_t len);
890
956
  } ShareStoreCallbacks;
891
957
 
892
958
  /**
893
959
  * Caller-supplied callbacks for the user-secret store. Methods cross
894
960
  * the FFI keyed by `secret_id`; the `UserSecrets` payload travels as a
895
- * JSON buffer matching [`UserSecretsRecord`].
961
+ * JSON buffer matching [`UserSecretsRecord`]. Its `threshold` is the
962
+ * recorded threshold ([`crate::protocol::types::UserSecrets::threshold`]),
963
+ * omitted when there is none; store the buffer as given.
896
964
  */
897
965
  typedef struct UserSecretStoreCallbacks {
898
966
  void *user_data;
@@ -1704,13 +1772,15 @@ struct ProcessPrePairResponseMessageResult process_pre_pair_response_message(con
1704
1772
  * are still passed as individual pointers, since purego marshals
1705
1773
  * pointer-sized arguments natively.
1706
1774
  *
1707
- * `config_json` must deserialize to [`ProtocolConfig`] — all field names
1708
- * `snake_case`. `secret_id` is the only required field. Every other field
1709
- * may be omitted, in which case the value matches
1710
- * [`crate::protocol::DeRecProtocolBuilder::new`]'s own default for that
1711
- * setting: [`ProtocolConfig`]'s field-level `#[serde(default)]` attributes
1712
- * read the same constants the builder does. A field that is present is
1713
- * used as given, including `0`, and validated by the builder.
1775
+ * `config_json` is a JSON object holding `secret_id` plus the canonical
1776
+ * [`DeRecProtocolConfig`] JSON, all field names `snake_case`. `secret_id`
1777
+ * is the only required field. The rest is parsed as a
1778
+ * [`DeRecProtocolConfig`] and applied with
1779
+ * [`crate::protocol::DeRecProtocolBuilder::with_config`]: an omitted field
1780
+ * keeps [`crate::protocol::DeRecProtocolBuilder::new`]'s own default for
1781
+ * that setting, and a field that is present is used as given, including
1782
+ * `0`, and validated by the builder. A key the config does not define is
1783
+ * rejected with `DEREC_CODE_FFI_BAD_PROTO` rather than ignored.
1714
1784
  *
1715
1785
  * ```json
1716
1786
  * {
@@ -1749,7 +1819,8 @@ struct ProcessPrePairResponseMessageResult process_pre_pair_response_message(con
1749
1819
  * "max_unresponsive_deletion_timeout": 0,
1750
1820
  * "min_unresponsive_deactivation_timeout": 0,
1751
1821
  * "max_unresponsive_deactivation_timeout": 0
1752
- * }
1822
+ * },
1823
+ * "max_subshares": null
1753
1824
  * }
1754
1825
  * ```
1755
1826
  *
@@ -1758,9 +1829,10 @@ struct ProcessPrePairResponseMessageResult process_pre_pair_response_message(con
1758
1829
  * preference order — the order decides which of a peer's offered
1759
1830
  * endpoints is used. `protocol` is its name (`"https"`, `"grpc"`) or
1760
1831
  * its `derec_proto::Protocol` discriminant (`0`, `1`). Each entry is validated, and
1761
- * two entries of the same protocol are rejected. Required: an absent or
1762
- * empty list is refused, since a node with no endpoint cannot be reached
1763
- * by any peer.
1832
+ * two entries of the same protocol are rejected. An unknown discriminant
1833
+ * or an invalid URI is rejected with `DEREC_CODE_TRANSPORT_INVALID`.
1834
+ * Required: an absent or empty list is refused, since a node with no
1835
+ * endpoint cannot be reached by any peer.
1764
1836
  * - `threshold`: omitted means [`crate::protocol::DEFAULT_THRESHOLD`]. A
1765
1837
  * `threshold` below `2` is rejected with `DEREC_CODE_INVALID_INPUT`.
1766
1838
  * - `unpair_ack`: `0` / `"required"` = Required, `1` / `"not_required"` =
@@ -1786,6 +1858,11 @@ struct ProcessPrePairResponseMessageResult process_pre_pair_response_message(con
1786
1858
  * string values. Mutually exclusive with a non-empty
1787
1859
  * `communication_info_ptr` buffer; omitted with an empty buffer means
1788
1860
  * no entries.
1861
+ * - `max_subshares`: decimal-string `u64` capping the total subshares one
1862
+ * sharing round may split the secret into, or absent/`null` for no cap.
1863
+ * A cap below `threshold` is rejected by the builder with
1864
+ * `DEREC_CODE_INVALID_INPUT`; a round over the cap fails with
1865
+ * `DEREC_CODE_TOO_MANY_SUBSHARES`.
1789
1866
  *
1790
1867
  * # Safety
1791
1868
  *
@@ -1995,7 +2072,8 @@ struct DeRecError derec_protocol_reject(struct DeRecProtocolHandle *handle,
1995
2072
  * "transports": [{ "uri": "https://replica.example", "protocol": "https" }],
1996
2073
  * "role": "Source", "communication_info": {} }],
1997
2074
  * "shared_key": [..32 bytes..]
1998
- * }
2075
+ * },
2076
+ * "threshold": 3
1999
2077
  * }
2000
2078
  * }
2001
2079
  * ```
@@ -2008,7 +2086,11 @@ struct DeRecError derec_protocol_reject(struct DeRecProtocolHandle *handle,
2008
2086
  * order; `protocol` is its name, `"https"` or `"grpc"`. An absent or
2009
2087
  * `null` `transports` reads as an empty list, and a helper or member with
2010
2088
  * no endpoint gets no channel: restore skips it and reports it as a
2011
- * `PeerNotRestored` event. `role` is `"Source"` or `"Destination"`.
2089
+ * `PeerNotRestored` event. `role` is `"Source"` or `"Destination"`. An
2090
+ * absent or `null` `communication_info` reads as an empty map, and an
2091
+ * absent or `null` helper `weight` as `1`. `threshold` is the threshold the
2092
+ * secret was split with; absent or `null` is none, and a value below `2` is
2093
+ * rejected. Restore writes it into the snapshot.
2012
2094
  *
2013
2095
  * `replicas` is an **object**, not an array, and is omitted entirely when
2014
2096
  * the `secret_id` has no replica group. Every member of the group shares
@@ -2052,34 +2134,23 @@ struct DeRecProtocolFingerprintResult derec_protocol_get_fingerprint(struct DeRe
2052
2134
  * Verify a fingerprint against the channel's locally-derived one. See
2053
2135
  * [`crate::protocol::DeRecProtocol::verify_fingerprint`].
2054
2136
  *
2055
- * Writes `*out_matched = 1` if and only if the comparison
2056
- * affirmatively succeeded. On every other outcome — null-pointer
2057
- * rejection, malformed UTF-8 in `fingerprint_ptr`, a backend error,
2058
- * or a legitimate mismatch — `*out_matched` is set to `0`. Callers
2059
- * MUST also inspect the returned [`DeRecError`] to distinguish a
2060
- * successful mismatch from a failure that could not produce a
2061
- * verdict; treating `out_matched == 0` as "definitely not matched"
2062
- * is safe only after confirming the envelope reports
2063
- * [`DEREC_CATEGORY_OK`](crate::interop::ffi::error::DEREC_CATEGORY_OK).
2064
- *
2065
- * The fail-closed write happens immediately after the null-pointer
2066
- * check, so a caller that allocates the output on the stack and
2067
- * reads it without checking the error envelope still gets `0`,
2068
- * never a stale `1` from uninitialized memory. This neutralizes
2069
- * the "sloppy caller skips the error envelope and reads stale
2070
- * 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.
2071
2143
  *
2072
2144
  * # Safety
2073
2145
  *
2074
- * `handle` and `out_matched` must be valid pointers. `fingerprint_ptr`
2075
- * must be a valid pointer to a NUL-terminated C string. Concurrent
2076
- * calls on the same handle from different threads are safe: the
2077
- * 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.
2078
2150
  */
2079
2151
  struct DeRecError derec_protocol_verify_fingerprint(struct DeRecProtocolHandle *handle,
2080
2152
  uint64_t channel_id,
2081
- const char *fingerprint_ptr,
2082
- uint32_t *out_matched);
2153
+ const char *fingerprint_ptr);
2083
2154
 
2084
2155
  /**
2085
2156
  * Generate an out-of-band contact message used to bootstrap pairing.
@@ -2220,14 +2291,23 @@ struct RecoverFromShareResponsesResult recover_from_share_responses(const uint8_
2220
2291
  uint64_t derec_generate_replica_id(void);
2221
2292
 
2222
2293
  /**
2294
+ * Splits `secret_data` into one committed share per weighted channel; see
2295
+ * [`crate::primitives::sharing::request::split`] for the weight and threshold
2296
+ * rules. Channels are given as the aligned `channels_ptr` / `weights_ptr`
2297
+ * arrays described in the module-level "Weighted channels" section; the
2298
+ * result does not depend on the order they are listed in.
2299
+ *
2223
2300
  * # Safety
2224
2301
  *
2225
- * Non-null input pointers must point to the corresponding readable byte ranges.
2302
+ * Non-null input pointers must point to the corresponding readable ranges:
2303
+ * `secret_data_len` bytes, and `channels_len` entries for each of
2304
+ * `channels_ptr` and `weights_ptr`.
2226
2305
  */
2227
2306
  struct ProtectSecretResult protect_secret(uint64_t secret_id,
2228
2307
  const uint8_t *secret_data_ptr,
2229
2308
  size_t secret_data_len,
2230
2309
  const uint64_t *channels_ptr,
2310
+ const uint32_t *weights_ptr,
2231
2311
  size_t channels_len,
2232
2312
  size_t threshold,
2233
2313
  uint32_t version);
@@ -2242,8 +2322,7 @@ struct ProduceStoreShareRequestMessageResult produce_store_share_request_message
2242
2322
  uint64_t secret_id,
2243
2323
  const uint8_t *committed_share_ptr,
2244
2324
  size_t committed_share_len,
2245
- const uint32_t *keep_list_ptr,
2246
- size_t keep_list_len,
2325
+ uint32_t keep_version,
2247
2326
  const uint8_t *description_ptr,
2248
2327
  size_t description_len,
2249
2328
  const uint8_t *shared_key_ptr,
@@ -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
@@ -239,6 +256,12 @@
239
256
 
240
257
  #define DEREC_CODE_VSS_SHARE_FAILED 64
241
258
 
259
+ #define DEREC_CODE_INVALID_WEIGHT 65
260
+
261
+ #define DEREC_CODE_TOO_MANY_SUBSHARES 66
262
+
263
+ #define DEREC_CODE_INVALID_KEEP_VERSION 67
264
+
242
265
  #define DEREC_CODE_EMPTY_RESPONSES 80
243
266
 
244
267
  #define DEREC_CODE_EMPTY_COMMITTED_DEREC_SHARE 81
@@ -289,6 +312,20 @@
289
312
  */
290
313
  #define DEREC_CODE_NO_USABLE_ENDPOINT 121
291
314
 
315
+ /**
316
+ * Return codes for [`crate::interop::ffi::protocol::stores::ShareStoreCallbacks::save`]
317
+ * and `ShareStoreCallbacks::record_verification`: `0` is success, each of
318
+ * these three refuses the write/verification with the matching
319
+ * [`crate::protocol::Refusal`] variant, and any other non-zero value is an
320
+ * ordinary backend failure. The values are the `StatusEnum` numbers the
321
+ * helper answers the owner with, not FFI-local codes.
322
+ */
323
+ #define DEREC_SHARE_STORE_REFUSED_SIZE_LIMIT_EXCEEDED 3
324
+
325
+ #define DEREC_SHARE_STORE_REFUSED_TOO_FREQUENT 4
326
+
327
+ #define DEREC_SHARE_STORE_REFUSED_REJECTED 10
328
+
292
329
  /**
293
330
  * Discriminants selecting which message [`derec_decode_message_json`] and
294
331
  * [`derec_encode_message_json`] operate on.
@@ -686,6 +723,12 @@ typedef struct ProcessPrePairResponseMessageResult {
686
723
  * Nonce echoed from the original `ContactMessage`. Zero on failure.
687
724
  */
688
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;
689
732
  } ProcessPrePairResponseMessageResult;
690
733
 
691
734
  typedef struct PairingFingerprintResult {
@@ -838,10 +881,30 @@ typedef struct SecretStoreCallbacks {
838
881
  * strings, matching the `Vec<u8>` ↔ JSON-array convention used for
839
882
  * every other wire-format buffer in this module.
840
883
  *
841
- * `keep_list` returns the JSON encoding of the application's answer:
842
- * `null` for no list (the owner sends an empty `keepList` and helpers keep
843
- * every version) or an array of version numbers. An empty buffer or return code `1` also
844
- * means `null`.
884
+ * A share crosses as the JSON object
885
+ * `{ "secret_id": "<u64>", "version": <u32>, "bytes": [..], "subshares": <u32>, "threshold": <u32> }`.
886
+ * `subshares` is the owner-side subshare count
887
+ * ([`crate::protocol::types::Share::subshares`]) and `threshold` the
888
+ * owner-side threshold the version was split with
889
+ * ([`crate::protocol::types::Share::threshold`]). Each is omitted when there
890
+ * is none, and absent or `null` reads as none. Store them as given and return
891
+ * them unchanged.
892
+ *
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.
896
+ *
897
+ * `save` and `record_verification` share a return-code convention: `0` is
898
+ * success; `3`/`4`/`10` (the
899
+ * [`DEREC_SHARE_STORE_REFUSED_SIZE_LIMIT_EXCEEDED`](crate::interop::ffi::error::DEREC_SHARE_STORE_REFUSED_SIZE_LIMIT_EXCEEDED) /
900
+ * [`DEREC_SHARE_STORE_REFUSED_TOO_FREQUENT`](crate::interop::ffi::error::DEREC_SHARE_STORE_REFUSED_TOO_FREQUENT) /
901
+ * [`DEREC_SHARE_STORE_REFUSED_REJECTED`](crate::interop::ffi::error::DEREC_SHARE_STORE_REFUSED_REJECTED)
902
+ * constants) refuse the call with the matching
903
+ * [`crate::protocol::Refusal`] variant; any other non-zero value is an
904
+ * ordinary backend failure. `record_verification` is called once per
905
+ * accepted verification challenge, after the challenged share is found and
906
+ * before the helper answers — see
907
+ * [`crate::protocol::DeRecShareStore::record_verification`].
845
908
  */
846
909
  typedef struct ShareStoreCallbacks {
847
910
  void *user_data;
@@ -881,18 +944,23 @@ typedef struct ShareStoreCallbacks {
881
944
  uint64_t channel_id,
882
945
  const uint8_t *versions_json_ptr,
883
946
  size_t versions_json_len);
884
- int32_t (*keep_list)(void *user_data,
885
- uint64_t secret_id,
886
- uint32_t version,
887
- uint8_t **out_ptr,
888
- 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);
951
+ int32_t (*record_verification)(void *user_data,
952
+ uint64_t secret_id,
953
+ uint64_t channel_id,
954
+ uint32_t version);
889
955
  void (*free_buffer)(void *user_data, uint8_t *ptr, size_t len);
890
956
  } ShareStoreCallbacks;
891
957
 
892
958
  /**
893
959
  * Caller-supplied callbacks for the user-secret store. Methods cross
894
960
  * the FFI keyed by `secret_id`; the `UserSecrets` payload travels as a
895
- * JSON buffer matching [`UserSecretsRecord`].
961
+ * JSON buffer matching [`UserSecretsRecord`]. Its `threshold` is the
962
+ * recorded threshold ([`crate::protocol::types::UserSecrets::threshold`]),
963
+ * omitted when there is none; store the buffer as given.
896
964
  */
897
965
  typedef struct UserSecretStoreCallbacks {
898
966
  void *user_data;
@@ -1704,13 +1772,15 @@ struct ProcessPrePairResponseMessageResult process_pre_pair_response_message(con
1704
1772
  * are still passed as individual pointers, since purego marshals
1705
1773
  * pointer-sized arguments natively.
1706
1774
  *
1707
- * `config_json` must deserialize to [`ProtocolConfig`] — all field names
1708
- * `snake_case`. `secret_id` is the only required field. Every other field
1709
- * may be omitted, in which case the value matches
1710
- * [`crate::protocol::DeRecProtocolBuilder::new`]'s own default for that
1711
- * setting: [`ProtocolConfig`]'s field-level `#[serde(default)]` attributes
1712
- * read the same constants the builder does. A field that is present is
1713
- * used as given, including `0`, and validated by the builder.
1775
+ * `config_json` is a JSON object holding `secret_id` plus the canonical
1776
+ * [`DeRecProtocolConfig`] JSON, all field names `snake_case`. `secret_id`
1777
+ * is the only required field. The rest is parsed as a
1778
+ * [`DeRecProtocolConfig`] and applied with
1779
+ * [`crate::protocol::DeRecProtocolBuilder::with_config`]: an omitted field
1780
+ * keeps [`crate::protocol::DeRecProtocolBuilder::new`]'s own default for
1781
+ * that setting, and a field that is present is used as given, including
1782
+ * `0`, and validated by the builder. A key the config does not define is
1783
+ * rejected with `DEREC_CODE_FFI_BAD_PROTO` rather than ignored.
1714
1784
  *
1715
1785
  * ```json
1716
1786
  * {
@@ -1749,7 +1819,8 @@ struct ProcessPrePairResponseMessageResult process_pre_pair_response_message(con
1749
1819
  * "max_unresponsive_deletion_timeout": 0,
1750
1820
  * "min_unresponsive_deactivation_timeout": 0,
1751
1821
  * "max_unresponsive_deactivation_timeout": 0
1752
- * }
1822
+ * },
1823
+ * "max_subshares": null
1753
1824
  * }
1754
1825
  * ```
1755
1826
  *
@@ -1758,9 +1829,10 @@ struct ProcessPrePairResponseMessageResult process_pre_pair_response_message(con
1758
1829
  * preference order — the order decides which of a peer's offered
1759
1830
  * endpoints is used. `protocol` is its name (`"https"`, `"grpc"`) or
1760
1831
  * its `derec_proto::Protocol` discriminant (`0`, `1`). Each entry is validated, and
1761
- * two entries of the same protocol are rejected. Required: an absent or
1762
- * empty list is refused, since a node with no endpoint cannot be reached
1763
- * by any peer.
1832
+ * two entries of the same protocol are rejected. An unknown discriminant
1833
+ * or an invalid URI is rejected with `DEREC_CODE_TRANSPORT_INVALID`.
1834
+ * Required: an absent or empty list is refused, since a node with no
1835
+ * endpoint cannot be reached by any peer.
1764
1836
  * - `threshold`: omitted means [`crate::protocol::DEFAULT_THRESHOLD`]. A
1765
1837
  * `threshold` below `2` is rejected with `DEREC_CODE_INVALID_INPUT`.
1766
1838
  * - `unpair_ack`: `0` / `"required"` = Required, `1` / `"not_required"` =
@@ -1786,6 +1858,11 @@ struct ProcessPrePairResponseMessageResult process_pre_pair_response_message(con
1786
1858
  * string values. Mutually exclusive with a non-empty
1787
1859
  * `communication_info_ptr` buffer; omitted with an empty buffer means
1788
1860
  * no entries.
1861
+ * - `max_subshares`: decimal-string `u64` capping the total subshares one
1862
+ * sharing round may split the secret into, or absent/`null` for no cap.
1863
+ * A cap below `threshold` is rejected by the builder with
1864
+ * `DEREC_CODE_INVALID_INPUT`; a round over the cap fails with
1865
+ * `DEREC_CODE_TOO_MANY_SUBSHARES`.
1789
1866
  *
1790
1867
  * # Safety
1791
1868
  *
@@ -1995,7 +2072,8 @@ struct DeRecError derec_protocol_reject(struct DeRecProtocolHandle *handle,
1995
2072
  * "transports": [{ "uri": "https://replica.example", "protocol": "https" }],
1996
2073
  * "role": "Source", "communication_info": {} }],
1997
2074
  * "shared_key": [..32 bytes..]
1998
- * }
2075
+ * },
2076
+ * "threshold": 3
1999
2077
  * }
2000
2078
  * }
2001
2079
  * ```
@@ -2008,7 +2086,11 @@ struct DeRecError derec_protocol_reject(struct DeRecProtocolHandle *handle,
2008
2086
  * order; `protocol` is its name, `"https"` or `"grpc"`. An absent or
2009
2087
  * `null` `transports` reads as an empty list, and a helper or member with
2010
2088
  * no endpoint gets no channel: restore skips it and reports it as a
2011
- * `PeerNotRestored` event. `role` is `"Source"` or `"Destination"`.
2089
+ * `PeerNotRestored` event. `role` is `"Source"` or `"Destination"`. An
2090
+ * absent or `null` `communication_info` reads as an empty map, and an
2091
+ * absent or `null` helper `weight` as `1`. `threshold` is the threshold the
2092
+ * secret was split with; absent or `null` is none, and a value below `2` is
2093
+ * rejected. Restore writes it into the snapshot.
2012
2094
  *
2013
2095
  * `replicas` is an **object**, not an array, and is omitted entirely when
2014
2096
  * the `secret_id` has no replica group. Every member of the group shares
@@ -2052,34 +2134,23 @@ struct DeRecProtocolFingerprintResult derec_protocol_get_fingerprint(struct DeRe
2052
2134
  * Verify a fingerprint against the channel's locally-derived one. See
2053
2135
  * [`crate::protocol::DeRecProtocol::verify_fingerprint`].
2054
2136
  *
2055
- * Writes `*out_matched = 1` if and only if the comparison
2056
- * affirmatively succeeded. On every other outcome — null-pointer
2057
- * rejection, malformed UTF-8 in `fingerprint_ptr`, a backend error,
2058
- * or a legitimate mismatch — `*out_matched` is set to `0`. Callers
2059
- * MUST also inspect the returned [`DeRecError`] to distinguish a
2060
- * successful mismatch from a failure that could not produce a
2061
- * verdict; treating `out_matched == 0` as "definitely not matched"
2062
- * is safe only after confirming the envelope reports
2063
- * [`DEREC_CATEGORY_OK`](crate::interop::ffi::error::DEREC_CATEGORY_OK).
2064
- *
2065
- * The fail-closed write happens immediately after the null-pointer
2066
- * check, so a caller that allocates the output on the stack and
2067
- * reads it without checking the error envelope still gets `0`,
2068
- * never a stale `1` from uninitialized memory. This neutralizes
2069
- * the "sloppy caller skips the error envelope and reads stale
2070
- * 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.
2071
2143
  *
2072
2144
  * # Safety
2073
2145
  *
2074
- * `handle` and `out_matched` must be valid pointers. `fingerprint_ptr`
2075
- * must be a valid pointer to a NUL-terminated C string. Concurrent
2076
- * calls on the same handle from different threads are safe: the
2077
- * 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.
2078
2150
  */
2079
2151
  struct DeRecError derec_protocol_verify_fingerprint(struct DeRecProtocolHandle *handle,
2080
2152
  uint64_t channel_id,
2081
- const char *fingerprint_ptr,
2082
- uint32_t *out_matched);
2153
+ const char *fingerprint_ptr);
2083
2154
 
2084
2155
  /**
2085
2156
  * Generate an out-of-band contact message used to bootstrap pairing.
@@ -2220,14 +2291,23 @@ struct RecoverFromShareResponsesResult recover_from_share_responses(const uint8_
2220
2291
  uint64_t derec_generate_replica_id(void);
2221
2292
 
2222
2293
  /**
2294
+ * Splits `secret_data` into one committed share per weighted channel; see
2295
+ * [`crate::primitives::sharing::request::split`] for the weight and threshold
2296
+ * rules. Channels are given as the aligned `channels_ptr` / `weights_ptr`
2297
+ * arrays described in the module-level "Weighted channels" section; the
2298
+ * result does not depend on the order they are listed in.
2299
+ *
2223
2300
  * # Safety
2224
2301
  *
2225
- * Non-null input pointers must point to the corresponding readable byte ranges.
2302
+ * Non-null input pointers must point to the corresponding readable ranges:
2303
+ * `secret_data_len` bytes, and `channels_len` entries for each of
2304
+ * `channels_ptr` and `weights_ptr`.
2226
2305
  */
2227
2306
  struct ProtectSecretResult protect_secret(uint64_t secret_id,
2228
2307
  const uint8_t *secret_data_ptr,
2229
2308
  size_t secret_data_len,
2230
2309
  const uint64_t *channels_ptr,
2310
+ const uint32_t *weights_ptr,
2231
2311
  size_t channels_len,
2232
2312
  size_t threshold,
2233
2313
  uint32_t version);
@@ -2242,8 +2322,7 @@ struct ProduceStoreShareRequestMessageResult produce_store_share_request_message
2242
2322
  uint64_t secret_id,
2243
2323
  const uint8_t *committed_share_ptr,
2244
2324
  size_t committed_share_len,
2245
- const uint32_t *keep_list_ptr,
2246
- size_t keep_list_len,
2325
+ uint32_t keep_version,
2247
2326
  const uint8_t *description_ptr,
2248
2327
  size_t description_len,
2249
2328
  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: 38384088 bytes
4
- sha256: 2c1f95ccf45a1a01f488a563ff1f0f4bc56033ee15dcaca4b4aeb3b83eac433e
3
+ size: 39449544 bytes
4
+ sha256: f2776c0d3cd0a91e4e6b789bd1446aaf15d7720ed5d7af57319fbe5de5a3cbbc
package/lib/errors.d.ts CHANGED
@@ -13,9 +13,19 @@ import type { DeRecEvent } from './types';
13
13
  */
14
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"];
15
15
  export type DeRecErrorCategory = (typeof DEREC_ERROR_CATEGORIES)[number];
16
+ /**
17
+ * Every code `derec_error_code_name` can return, and no others.
18
+ *
19
+ * Held to the shared enum fixture by a test, like {@link DEREC_ERROR_CATEGORIES}.
20
+ * Unlike the WASM bindings, this SDK raises no marshalling-level codes of its
21
+ * own before a value reaches the library, so this list is exactly the Rust
22
+ * `Code` table in `library/src/interop/error_codes.rs`.
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", "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", "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"];
25
+ export type DeRecErrorCode = (typeof DEREC_ERROR_CODES)[number];
16
26
  export interface DeRecError {
17
27
  category: DeRecErrorCategory;
18
- code: string;
28
+ code: DeRecErrorCode;
19
29
  message: string;
20
30
  status?: number;
21
31
  memo?: string;