@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
package/lib/types.d.ts CHANGED
@@ -229,30 +229,33 @@ export interface ShareStore {
229
229
  * `versions`. Idempotent: a version that is not stored is skipped, and
230
230
  * an empty array is a no-op.
231
231
  *
232
- * A helper calls this to apply `StoreShareRequestMessage.keepList`, the
233
- * complete set of versions the owner wants retained: every stored
234
- * version outside it is removed once the incoming share is persisted.
232
+ * A helper calls this to apply `StoreShareRequestMessage.keepVersion`:
233
+ * once the incoming share is persisted, every version stored on the
234
+ * channel other than the incoming one and `keepVersion` is removed.
235
235
  * Shares under other channels or partitions must be left untouched.
236
236
  */
237
237
  removeVersions(secretId: string, channelId: string, versions: number[]): Promise<void>;
238
238
  /**
239
- * Owner only: the versions every helper keeps after the owner distributes
240
- * `version`. Asked once per sharing round, before anything is sent,
241
- * including the rounds the library starts itself; the answer becomes
242
- * `keepList` for every helper.
239
+ * Owner only: the one older version every helper keeps after the owner
240
+ * distributes `version`. Asked once per sharing round, before anything is
241
+ * sent, including the rounds the library starts itself; the answer
242
+ * becomes `keepVersion` for every helper.
243
243
  *
244
- * Return `null` or `undefined` to send no `keepList` (it goes out empty):
245
- * helpers then keep every version they hold. An app that wants to cap how
246
- * many versions helpers retain returns that cap here. A returned list is
247
- * used as is, plus `version`, which the library always adds. Helpers
248
- * delete every version that is not listed, so list every version that
249
- * could still become the latest: those that committed (for example, whose
250
- * `SharingComplete` reported `threshold_met`) and those whose round is
251
- * still open. Leave out only versions whose round failed or that the user
252
- * rolled back; a list that leaves out too much can make the secret
253
- * unrecoverable.
244
+ * Resolve to an integer in `0..=4294967295`. A helper that stores
245
+ * `version` keeps it and the returned version, and deletes every other
246
+ * version it holds; `0` keeps no other version. An answer equal to or
247
+ * greater than `version` fails the round with `invalid_keep_version`
248
+ * before anything is sent.
249
+ *
250
+ * Return the last valid version: the newest one whose `SharingComplete`
251
+ * reported `threshold_met`. A version whose round is still open is
252
+ * deleted from every helper that stores `version` unless it is the one
253
+ * returned here. Only the application knows which versions committed.
254
+ * When a helper confirms `version`, the library also removes this
255
+ * device's rows for that channel other than `version` and the returned
256
+ * version.
254
257
  */
255
- keepList(secretId: string, version: number): Promise<number[] | null | undefined>;
258
+ keepVersion(secretId: string, version: number): Promise<number>;
256
259
  /**
257
260
  * Record a verification challenge the helper is about to answer for
258
261
  * `(secretId, channelId, version)`. Called once per accepted challenge,
@@ -487,7 +490,10 @@ export declare enum SenderKind {
487
490
  * are ignored. A man-in-the-middle on the plaintext `PrePair` leg leaves
488
491
  * the two sides with different shared keys and so different fingerprints,
489
492
  * which is what the comparison catches — the role `contact_binding_hash`
490
- * plays for `HashedKeys`.
493
+ * plays for `HashedKeys`. The creator's `PrePair` response also carries a
494
+ * commitment to a nonce it reveals only in its `PairResponse`, and the
495
+ * channel key depends on that nonce, so whoever answers the scanner cannot
496
+ * search offline for keys that make the two fingerprints agree.
491
497
  */
492
498
  export declare enum ContactMode {
493
499
  InlineKeys = 0,
@@ -545,6 +551,14 @@ export interface ContactMessage {
545
551
  /** Present only when `contact_mode === ContactMode.HashedKeys`. SHA-384 digest (48 bytes). */
546
552
  contact_binding_hash?: Uint8Array;
547
553
  timestamp?: Timestamp;
554
+ /**
555
+ * Present only when `contact_mode === ContactMode.InlineKeys`. The
556
+ * creator's 32-byte commitment to the fingerprint nonce its
557
+ * `PairResponseMessage` reveals. For the other modes it arrives with the
558
+ * keys in the `PrePairResponseMessage`; a contact filled in from a
559
+ * `ProcessPrePairResult` must carry it alongside the two keys.
560
+ */
561
+ fingerprint_commitment?: Uint8Array;
548
562
  /** Every transport endpoint the creator of this contact can be reached
549
563
  * on, in its own preference order. */
550
564
  supported_transports: TransportProtocol[];
@@ -662,6 +676,24 @@ export interface Timeouts {
662
676
  /** How long to wait for an unpair acknowledgement before dropping local
663
677
  * channel state anyway. Library default: 60. */
664
678
  unpair_ack_secs?: number;
679
+ /** How long a recovery waits for a helper to answer its share request. A
680
+ * recovery decides only once every helper it asked has answered or this
681
+ * has elapsed since the requests went out; each silent helper is then
682
+ * reported as `RecoverSecretFailed` with error `"timeout"`. The budget is
683
+ * a **human** one when helpers approve share requests by hand. The same
684
+ * budget bounds a replica version check (`FlowKind.ReplicaDiscovery`):
685
+ * once it elapses, the check concludes on the versions already reported.
686
+ * Library default: 300. */
687
+ get_share_response_secs?: number;
688
+ /** How long a pairing stays possible: how old a contact may be when it is
689
+ * scanned or answered, and how old a pairing request may be when it is
690
+ * accepted. Both sides enforce it and nothing is sent on expiry: the
691
+ * scanner refuses an expired contact, and the creator ignores a request on
692
+ * one and refuses a late accept, with `pairing_expired`. The remedy is to
693
+ * scan or share a fresh contact. A scanner's `expired_channels` timeout
694
+ * should be at least this plus the time a response takes to arrive.
695
+ * Library default: 30. */
696
+ pairing_secs?: number;
665
697
  /** Removal of channels still awaiting out-of-band fingerprint
666
698
  * confirmation — every replica pairing, and every `NoKeys` pairing.
667
699
  * Unlike the others this can be disabled, leaving the sweep to the
@@ -684,7 +716,13 @@ export type ReplicaDiscoveryParams = Record<string, never>;
684
716
  * member is not asked and gets no event when told to leave: when a roster
685
717
  * excluding it arrives it drops its whole `secret_id` partition and emits
686
718
  * `SelfRemovedFromGroup`. The secret survives on the remaining members and
687
- * the helpers. */
719
+ * the helpers.
720
+ *
721
+ * Removal does not replace the group key, so it relies on the removed
722
+ * device's library deleting its copy. That covers a lost or stolen device
723
+ * whose storage was not read. Whoever read a device's storage keeps the
724
+ * group key and can decrypt every later publication it obtains, the one
725
+ * completing the removal included. */
688
726
  export interface UnpairReplicaParams {
689
727
  /** The member to remove, as a **decimal** `u64` string — the same form
690
728
  * `ReplicaPaired.peer_replica_id` hands back. A value naming no current
@@ -692,6 +730,26 @@ export interface UnpairReplicaParams {
692
730
  replica_id: string;
693
731
  memo?: string;
694
732
  }
733
+ /** A helper named by a recovery decision (`RecoveryDisputed`,
734
+ * `RecoveryConflict`), so the app can tell the owner who is on each side.
735
+ * `channel_id` is the `u64` as a **decimal** string; `communication_info`
736
+ * is what the helper advertised when it paired, read from its channel
737
+ * record, and is absent when it advertised none. */
738
+ export interface RecoveryHelper {
739
+ channel_id: string;
740
+ communication_info?: Record<string, string>;
741
+ }
742
+ /** One secret a recovery reconstructed, reported in `RecoveryConflict`.
743
+ * `secret` has the shape of `SecretRecovered.secret`, so a confirmed
744
+ * candidate is passed to `restore` the same way. `supported_by` are the
745
+ * helpers whose shares reconstruct it, in the order their shares were
746
+ * collected. */
747
+ export interface RecoveryCandidate {
748
+ secret: Extract<DeRecEvent, {
749
+ type: "SecretRecovered";
750
+ }>["secret"];
751
+ supported_by: RecoveryHelper[];
752
+ }
695
753
  export type DeRecEvent = {
696
754
  type: "PairingCompleted";
697
755
  /** Long-term `channel_id` both peers atomically rotated to at handshake completion. */
@@ -752,7 +810,13 @@ export type DeRecEvent = {
752
810
  type: "ShareConfirmed";
753
811
  channel_id: string;
754
812
  version: number;
755
- } | {
813
+ }
814
+ /** A helper rejected or failed to store our share. `status` and `memo`
815
+ * come from the helper's response, except for a helper that did not
816
+ * answer within `timeouts.sharing_round_secs`: `tick()` then reports it
817
+ * with status `FAIL` and memo `"timeout"`. The memo of a helper's own
818
+ * answer is free text and can read the same. */
819
+ | {
756
820
  type: "ShareRejected";
757
821
  channel_id: string;
758
822
  version: number;
@@ -795,8 +859,12 @@ export type DeRecEvent = {
795
859
  status: StatusEnum;
796
860
  memo: string;
797
861
  }
798
- /** A secret sync could not be delivered to a member at all — distinct from
799
- * `ReplicaSyncRejected`, which is the member answering "no". */
862
+ /** A secret sync could not be delivered to a member, or the member did not
863
+ * acknowledge it within `timeouts.sharing_round_secs` — distinct from
864
+ * `ReplicaSyncRejected`, which is the member answering "no". `reason` is
865
+ * `"timeout"` when the member did not acknowledge in time (reported by
866
+ * `tick()`); otherwise the transport or encoding failure, rendered for
867
+ * display. */
800
868
  | {
801
869
  type: "ReplicaSyncFailed";
802
870
  replica_id: string;
@@ -888,21 +956,25 @@ export type DeRecEvent = {
888
956
  description: string;
889
957
  }>;
890
958
  }>;
891
- } | {
959
+ }
960
+ /** A helper's share was collected for a recovery. Nothing is
961
+ * reconstructed until every helper asked has answered or
962
+ * `timeouts.get_share_response_secs` has passed since the requests went
963
+ * out (each silent helper is then reported as `RecoverSecretFailed` with
964
+ * error `"timeout"`). The recovery then decides exactly once:
965
+ * `SecretRecovered`, `RecoveryDisputed`, `RecoveryConflict` or
966
+ * `RecoveryIncomplete`. */
967
+ | {
892
968
  type: "RecoveryShareReceived";
893
969
  channel_id: string;
894
970
  shares_received: number;
895
- } | {
896
- type: "RecoveryShareError";
897
- channel_id: string;
898
- shares_received: number;
899
- error: string;
900
971
  }
901
972
  /** A helper refused a recovery share request: its response carried a
902
973
  * non-OK `status` (e.g. `UNKNOWN_SHARE_VERSION`) instead of a share. The
903
- * refusal is not collected — it does not count towards `shares_received`
904
- * and the recovery stays open for the other helpers' shares — but it does
905
- * answer that helper's `RecoverSecretStarted`. */
974
+ * refusal is not collected and does not count towards `shares_received`,
975
+ * but it is that helper's answer: it answers the helper's
976
+ * `RecoverSecretStarted`, and when it is the last answer due the recovery
977
+ * decides on the shares it holds. */
906
978
  | {
907
979
  type: "RecoveryShareRefused";
908
980
  channel_id: string;
@@ -912,20 +984,24 @@ export type DeRecEvent = {
912
984
  }
913
985
  /** A helper answered with a share that cannot be part of the secret;
914
986
  * `reason` says how it failed. `Malformed` and `InvalidProof` are judged
915
- * on arrival; `Inconsistent` (valid on its own but disagreeing with the
916
- * shares the secret was rebuilt from) is reported alongside
917
- * `SecretRecovered`, once per helper. The share is set aside — it does
918
- * not count towards `shares_received` and never blocks the recovery. An
919
- * honest helper never sends one, so the app may treat it as a sign of a
920
- * damaged or compromised helper, e.g. offer to unpair it. It also
921
- * answers that helper's `RecoverSecretStarted`. */
987
+ * on arrival and count as that helper's answer; `Forged` (its group
988
+ * reconstructs under one key, but not to a secret, or a single share
989
+ * reconstructs alone) is reported with the recovery's decision, once per
990
+ * helper. The share is set aside — it does not count towards
991
+ * `shares_received` and never blocks the recovery. An honest helper never
992
+ * sends one, so the app may treat it as a sign of a damaged or
993
+ * compromised helper, e.g. offer to unpair it. A share that only
994
+ * disagrees with the others is never reported here: it is a dispute
995
+ * (`RecoveryDisputed` / `RecoveryConflict`), not evidence against its
996
+ * helper. It also answers that helper's `RecoverSecretStarted`. */
922
997
  | {
923
998
  type: "RecoveryShareCorrupted";
924
999
  channel_id: string;
925
1000
  version: number;
926
1001
  reason: CorruptionReason;
927
1002
  }
928
- /** Recovery completed — the typed `Secret` snapshot the owner
1003
+ /** Recovery completed — one secret reconstructed and every collected
1004
+ * share is part of it. `secret` is the typed `Secret` snapshot the owner
929
1005
  * originally protected. Mirrors `ReplicaSecretReceived.secret`:
930
1006
  * `secrets` is the user-facing `Vec<UserSecret>` the application
931
1007
  * fed to `start(FlowKind.ProtectSecret)`; `helpers` and `replicas`
@@ -976,6 +1052,54 @@ export type DeRecEvent = {
976
1052
  * `threshold` on `start(ProtectSecret)`. */
977
1053
  threshold?: number;
978
1054
  };
1055
+ }
1056
+ /** A recovery reconstructed two or more different secrets for `version`,
1057
+ * so it cannot tell which is the owner's. Each candidate is a complete,
1058
+ * self-consistent secret, rebuilt from the shares of the helpers in its
1059
+ * `supported_by`. Fewer than the threshold of colluding helpers can forge
1060
+ * one, so the library never picks: involve the owner and pass the
1061
+ * candidate's `secret` they confirm to `restore`, exactly as the `secret`
1062
+ * of `SecretRecovered`. The helpers backing a rejected candidate are
1063
+ * suspect. `disputed_by` names the helpers holding valid shares of yet
1064
+ * another split that does not reconstruct, so no helper's answer goes
1065
+ * unshown. The recovery is closed when this is emitted. */
1066
+ | {
1067
+ type: "RecoveryConflict";
1068
+ version: number;
1069
+ candidates: RecoveryCandidate[];
1070
+ disputed_by: RecoveryHelper[];
1071
+ }
1072
+ /** A recovery reconstructed one secret for `version`, but other helpers
1073
+ * hold valid shares of a different split that does not reconstruct.
1074
+ * `secret` is complete and self-consistent, rebuilt from the shares of
1075
+ * `supported_by`, and has the shape of `SecretRecovered.secret`. The
1076
+ * shares of `disputed_by` each pass their own proof but belong to another
1077
+ * split at the same version, which an honest sharing never produces.
1078
+ * Either side can be the owner's: colluding helpers can forge a complete
1079
+ * split, and the honest helpers may be too few to reconstruct theirs. The
1080
+ * library never picks: show the owner what `secret` holds and who stands
1081
+ * on each side, and pass `secret` to `restore` only once they confirm it.
1082
+ * The recovery is closed when this is emitted. */
1083
+ | {
1084
+ type: "RecoveryDisputed";
1085
+ version: number;
1086
+ secret: Extract<DeRecEvent, {
1087
+ type: "SecretRecovered";
1088
+ }>["secret"];
1089
+ supported_by: RecoveryHelper[];
1090
+ disputed_by: RecoveryHelper[];
1091
+ }
1092
+ /** A recovery of `(secret_id, version)` closed without reconstructing a
1093
+ * secret: every helper asked has answered, or the rest timed out, and no
1094
+ * collected shares reconstruct. `secret_id` and `version` name the
1095
+ * recovery that closed, since recoveries of several secrets can be open at
1096
+ * once. `shares_received` is the number of helpers whose shares were
1097
+ * collected. Start `RecoverSecret` again to retry. */
1098
+ | {
1099
+ type: "RecoveryIncomplete";
1100
+ secret_id: string;
1101
+ version: number;
1102
+ shares_received: number;
979
1103
  } | {
980
1104
  type: "Unpaired";
981
1105
  channel_id: string;
@@ -1322,7 +1446,10 @@ export type DeRecEvent = {
1322
1446
  * and the encrypted inner message's timestamp differ, or either is
1323
1447
  * absent. `"StaleResponse"` means a `VerifyShareResponse` answered an
1324
1448
  * earlier challenge that a newer one on the channel has replaced; the
1325
- * outstanding challenge is kept. `trace_id` matches the peer's
1449
+ * outstanding challenge is kept. `"Superseded"` means a
1450
+ * `StoreShareRequest` for a version older than the newest one this
1451
+ * helper stores on the channel, and not stored itself; it is not stored
1452
+ * and not answered. `trace_id` matches the peer's
1326
1453
  * `*Started` event for the same round (`"0"` when the sender set none). */
1327
1454
  | {
1328
1455
  type: "MessageIgnored";
@@ -1550,7 +1677,7 @@ export interface CommunicationInfo {
1550
1677
  }
1551
1678
  /** Why a `MessageIgnored` event dropped a message. Matches the Rust
1552
1679
  * `IgnoreReason` discriminants one-for-one. */
1553
- export type IgnoreReason = "PendingVerification" | "Expired" | "TimestampMismatch" | "StaleResponse";
1680
+ export type IgnoreReason = "PendingVerification" | "Expired" | "TimestampMismatch" | "StaleResponse" | "Superseded";
1554
1681
  /** Why a `PeerNotRestored` event left a roster entry without a channel.
1555
1682
  * Matches the Rust `NotRestoredReason` discriminants one-for-one. */
1556
1683
  export type NotRestoredReason = "NoTransports";
@@ -1562,9 +1689,9 @@ export type VerifyFailureReason = "NoSharedKey" | "NoProof" | "DispatchFailed";
1562
1689
  * Matches the Rust `CorruptionReason` discriminants one-for-one:
1563
1690
  * `Malformed` — no decodable share for the requested secret and version;
1564
1691
  * `InvalidProof` — the share fails its own Merkle proof;
1565
- * `Inconsistent` — valid on its own, but its commitment root or ciphertext
1566
- * disagrees with the shares the secret was rebuilt from. */
1567
- export type CorruptionReason = "Malformed" | "InvalidProof" | "Inconsistent";
1692
+ * `Forged` — its group reconstructs under one key, but not to a secret, or
1693
+ * a single share reconstructs alone; an honest split produces neither. */
1694
+ export type CorruptionReason = "Malformed" | "InvalidProof" | "Forged";
1568
1695
  /**
1569
1696
  * The label vocabulary for `ActionRequired.action_kind`,
1570
1697
  * `AutoAccepted.action_kind` and `RequestFailed.action_kind` — one value per
@@ -1702,6 +1829,11 @@ export interface PairResponseMessage {
1702
1829
  * its own derivation. Zero on rejection (non-Ok `result.status`).
1703
1830
  */
1704
1831
  channel_id: bigint;
1832
+ /**
1833
+ * Present only when `result.status === Ok`. The 32-byte fingerprint nonce
1834
+ * the contact creator committed to in `fingerprint_commitment`.
1835
+ */
1836
+ fingerprint_nonce?: Uint8Array;
1705
1837
  }
1706
1838
  export interface PrePairRequestMessage {
1707
1839
  nonce: bigint;
@@ -1720,6 +1852,12 @@ export interface PrePairResponseMessage {
1720
1852
  ecies_public_key?: Uint8Array;
1721
1853
  nonce: bigint;
1722
1854
  timestamp?: Timestamp;
1855
+ /**
1856
+ * Present only when `result.status === Ok`. The creator's 32-byte
1857
+ * commitment to the fingerprint nonce its `PairResponseMessage` reveals,
1858
+ * covering the two keys above.
1859
+ */
1860
+ fingerprint_commitment?: Uint8Array;
1723
1861
  }
1724
1862
  export interface GetShareRequestMessage {
1725
1863
  secret_id: bigint;
@@ -1761,7 +1899,7 @@ export interface StoreShareRequestMessage {
1761
1899
  share: Uint8Array;
1762
1900
  share_algorithm: number;
1763
1901
  version: number;
1764
- keep_list: number[];
1902
+ keep_version: number;
1765
1903
  version_description: string;
1766
1904
  timestamp?: Timestamp;
1767
1905
  secret_id: bigint;
@@ -1887,6 +2025,9 @@ export interface ProcessPrePairResult {
1887
2025
  ecies_public_key: Uint8Array;
1888
2026
  /** Nonce echoed from the original `ContactMessage`. */
1889
2027
  nonce: bigint;
2028
+ /** The creator's 32-byte commitment to its fingerprint nonce. Copy it into
2029
+ * the contact the pair request is built from, alongside the two keys. */
2030
+ fingerprint_commitment: Uint8Array;
1890
2031
  }
1891
2032
  /**
1892
2033
  * A channel paired with how many subshares it holds. A weight of `1` is an
@@ -1908,3 +2049,10 @@ export interface UnpairingProcessResult {
1908
2049
  export interface DiscoveryProcessResult {
1909
2050
  secret_list: SecretVersionEntry[];
1910
2051
  }
2052
+ /** The identity of one delivered message; see `envelope.message_id`. */
2053
+ export interface MessageId {
2054
+ /** SHA-256 of the envelope's encrypted `message` field. */
2055
+ id: Uint8Array;
2056
+ /** The envelope's send time, in seconds since the Unix epoch. */
2057
+ timestamp: bigint;
2058
+ }
package/lib/types.js CHANGED
@@ -169,7 +169,10 @@ var SenderKind;
169
169
  * are ignored. A man-in-the-middle on the plaintext `PrePair` leg leaves
170
170
  * the two sides with different shared keys and so different fingerprints,
171
171
  * which is what the comparison catches — the role `contact_binding_hash`
172
- * plays for `HashedKeys`.
172
+ * plays for `HashedKeys`. The creator's `PrePair` response also carries a
173
+ * commitment to a nonce it reveals only in its `PairResponse`, and the
174
+ * channel key depends on that nonce, so whoever answers the scanner cannot
175
+ * search offline for keys that make the two fingerprints agree.
173
176
  */
174
177
  var ContactMode;
175
178
  (function (ContactMode) {
package/package.json CHANGED
@@ -1,13 +1,10 @@
1
1
  {
2
2
  "name": "@derec-alliance/react-native",
3
- "version": "0.0.9",
4
3
  "description": "React Native bindings for derec-library, the Rust SDK for the DeRec protocol.",
5
- "license": "Apache-2.0",
6
4
  "repository": {
7
5
  "type": "git",
8
6
  "url": "git+https://github.com/derecalliance/lib-derec"
9
7
  },
10
- "homepage": "https://derec.org",
11
8
  "main": "lib/index.js",
12
9
  "types": "lib/index.d.ts",
13
10
  "files": [
@@ -21,26 +18,14 @@
21
18
  "!cpp/tests",
22
19
  "DeRec.podspec",
23
20
  "react-native.config.js",
21
+ "schema",
24
22
  "README.md",
25
23
  "LICENSE"
26
24
  ],
27
- "scripts": {
28
- "build": "tsc --project tsconfig.build.json",
29
- "test": "jest",
30
- "typecheck": "tsc --noEmit"
31
- },
32
25
  "peerDependencies": {
33
26
  "react": ">=18.2.0",
34
27
  "react-native": ">=0.76.0"
35
28
  },
36
- "devDependencies": {
37
- "@types/jest": "^30.0.0",
38
- "@types/node": "^26.3.0",
39
- "jest": "^30.4.2",
40
- "react-native": "^0.87.0",
41
- "ts-jest": "^29.4.12",
42
- "typescript": "^5.9.3"
43
- },
44
29
  "keywords": [
45
30
  "derec",
46
31
  "decentralized",
@@ -52,5 +37,7 @@
52
37
  "android",
53
38
  "typescript",
54
39
  "jsi"
55
- ]
40
+ ],
41
+ "version": "0.0.11",
42
+ "license": "Apache-2.0"
56
43
  }
Binary file
@@ -0,0 +1,93 @@
1
+ /*
2
+ * Copyright (c) DeRec Alliance and its Contributors.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ syntax = "proto3";
7
+
8
+ package org.derecalliance.derec.protobuf;
9
+
10
+ // CommittedDeRecShare represents a DeRec share that has been committed and
11
+ // is ready to be given to a helper for storage.
12
+ //
13
+ // During recovery, this protobuf message is returned.
14
+ //
15
+ // The commitment uses a Merkle tree. The hash of the share given to each
16
+ // helper forms a leaf in the tree, committing to that share's subshares in
17
+ // order. Each leaf and internal node hash is a SHA-256 hash: a leaf is
18
+ // SHA-256(0x00 || k || for each subshare: len(x) || x || len(y) || y), with k
19
+ // (the number of subshares) and every length as an 8-byte big-endian integer,
20
+ // and an internal node is SHA-256(0x02 || left || right). The tree has a fixed depth of 7, unused
21
+ // leaf slots are leaf hashes of random bytes, and every merklePath has
22
+ // exactly 7 entries.
23
+ //
24
+ // The Merkle path from a leaf to the root (i.e., the sibling nodes along
25
+ // that route) is called merklePath. The root hash is referred to as the
26
+ // "commitment".
27
+ message CommittedDeRecShare {
28
+
29
+ // Protobuf serialization of DeRecShare.
30
+ bytes deRecShare = 1;
31
+
32
+ // The Merkle root.
33
+ bytes commitment = 2;
34
+
35
+ // Represents a leaf or interior node in the Merkle path.
36
+ // isLeft is true if the sibling is a left child.
37
+ message SiblingHash {
38
+ bool isLeft = 1;
39
+ bytes hash = 2;
40
+ }
41
+
42
+ // The bottom-up Merkle path from the leaf to the root.
43
+ repeated SiblingHash merklePath = 3;
44
+ }
45
+
46
+
47
+ // DeRecShare contains the information that a sharer provides to a helper.
48
+ //
49
+ // The sharer first generates a random AES-256 key k and uses it to
50
+ // AES-GCM encrypt the secret. A random polynomial f is generated such
51
+ // that f(0) = k. The polynomial is evaluated at random non-zero x values,
52
+ // and each helper receives one or more of the resulting subshares (x, f(x)).
53
+ // The number of subshares a helper holds is its weight; a weight is always
54
+ // below the threshold, so no single helper can reconstruct on its own.
55
+ //
56
+ // The computation is done in the scalar field of the BW6-761 curve. The
57
+ // degree of the polynomial determines the threshold: t distinct subshares,
58
+ // from any combination of helpers, reconstruct k at x = 0.
59
+ //
60
+ // The message also includes the secretId and the share version number,
61
+ // because they must be serialized together with the share so that they
62
+ // are covered by the same signature.
63
+ message DeRecShare {
64
+
65
+ // One subshare: a Shamir (x, y) pair with y = f(x).
66
+ message Subshare {
67
+ // A random non-zero field element, in arkworks compressed
68
+ // serialization (48 bytes, little-endian).
69
+ bytes x = 1;
70
+
71
+ // The value y = f(x), in the same encoding.
72
+ bytes y = 2;
73
+ }
74
+
75
+ // The result of serializing the secret to be shared and encrypting it
76
+ // with a randomly generated AES-256 key.
77
+ bytes encryptedSecret = 1;
78
+
79
+ // The subshares this helper holds, in the order the Merkle leaf
80
+ // commits to. At least one.
81
+ repeated Subshare subshares = 2;
82
+
83
+ // Numeric identifier of the secret associated with the share.
84
+ //
85
+ // Must be unique for each secret created by a sharer.
86
+ uint64 secretId = 3;
87
+
88
+ // Version number of the share.
89
+ //
90
+ // A helper is entitled to ignore any StoreShareRequestMessage whose
91
+ // version is less than or equal to the last seen version.
92
+ uint32 version = 4;
93
+ }
@@ -0,0 +1,104 @@
1
+ /*
2
+ * Copyright (c) DeRec Alliance and its Contributors.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ syntax = "proto3";
7
+
8
+ package org.derecalliance.derec.protobuf;
9
+
10
+ // CommunicationInfoKeyValue represents a single application-defined
11
+ // key-value pair used to convey user-facing identification data.
12
+ //
13
+ // # Purpose
14
+ //
15
+ // This structure is intended for:
16
+ //
17
+ // - displaying human-readable information to users during pairing
18
+ // - helping users identify and confirm counterparties
19
+ // - providing contextual metadata for UI/UX purposes
20
+ //
21
+ // # Semantics
22
+ //
23
+ // - The `key` is an application-defined identifier (e.g., "name", "phone")
24
+ // - The `value` contains the associated data, either as a string or raw bytes
25
+ //
26
+ // The protocol does not interpret these fields; they are opaque to the
27
+ // DeRec protocol and are only intended for application-level use.
28
+ //
29
+ // # Encoding
30
+ //
31
+ // Exactly one of the `value` fields MUST be set.
32
+ //
33
+ // Implementations SHOULD:
34
+ //
35
+ // - prefer `stringValue` for human-readable data
36
+ // - use `bytesValue` for structured or binary data (e.g., encoded identifiers)
37
+ //
38
+ // # Interoperability
39
+ //
40
+ // Applications SHOULD use consistent and well-known keys where possible
41
+ // (e.g., "name", "email", "phone") to improve cross-implementation UX,
42
+ // but no global registry is enforced by the protocol.
43
+ message CommunicationInfoKeyValue {
44
+ // Application-defined key identifying the type of information.
45
+ //
46
+ // Examples include "name", "email", "phone", or "accountId".
47
+ string key = 1;
48
+
49
+ // Value associated with the key.
50
+ //
51
+ // Exactly one of the following fields MUST be set.
52
+ oneof value {
53
+ // Human-readable string value.
54
+ //
55
+ // This is the preferred representation for most user-facing data.
56
+ string stringValue = 2;
57
+
58
+ // Binary value.
59
+ //
60
+ // May be used for structured or encoded data that is not naturally
61
+ // represented as a string.
62
+ bytes bytesValue = 3;
63
+ }
64
+ }
65
+
66
+ // CommunicationInfo contains application-level identifying information
67
+ // about a participant (Owner or Helper).
68
+ //
69
+ // # Purpose
70
+ //
71
+ // This message is used to:
72
+ //
73
+ // - present identifying details to users during pairing
74
+ // - assist users in verifying the identity of the counterparty
75
+ // - provide contextual metadata for UI display
76
+ //
77
+ // # Semantics
78
+ //
79
+ // - The contents are entirely application-defined
80
+ // - The protocol does not validate, interpret, or enforce any schema
81
+ // - Entries are independent key-value pairs
82
+ //
83
+ // # Security Considerations
84
+ //
85
+ // - This data MUST NOT be relied upon for authentication
86
+ // - Authentication is handled outside the protocol (e.g., in-person,
87
+ // KYC, or application-specific mechanisms)
88
+ //
89
+ // # Privacy Considerations
90
+ //
91
+ // - Applications SHOULD avoid including sensitive information unless
92
+ // necessary for the user experience
93
+ // - Users should be informed about what data is being shared
94
+ //
95
+ // # Interoperability
96
+ //
97
+ // While no schema is enforced, using common keys improves usability
98
+ // across implementations.
99
+ message CommunicationInfo {
100
+ // List of key-value entries describing the participant.
101
+ //
102
+ // Each entry represents one piece of identifying information.
103
+ repeated CommunicationInfoKeyValue communicationInfoEntries = 1;
104
+ }