@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.
- package/README.md +20 -7
- package/android/src/main/jniLibs/arm64-v8a/libderec_library.a +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libderec_library.a +0 -0
- package/android/src/main/jniLibs/x86_64/libderec_library.a +0 -0
- package/cpp/Primitives.cpp +13 -7
- package/cpp/ProtocolHost.cpp +4 -5
- package/cpp/StoreCallbacks.cpp +31 -43
- package/cpp/derec_ffi.h +44 -33
- package/ios/DeRecFFI.xcframework/Info.plist +5 -5
- package/ios/DeRecFFI.xcframework/ios-arm64/Headers/derec_ffi.h +44 -33
- package/ios/DeRecFFI.xcframework/ios-arm64/libderec_library.a +0 -0
- package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/Headers/derec_ffi.h +44 -33
- package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/libderec_library.a +2 -2
- package/lib/errors.d.ts +1 -1
- package/lib/errors.js +3 -0
- package/lib/messages.js +5 -3
- package/lib/primitives.d.ts +1 -1
- package/lib/primitives.js +4 -2
- package/lib/protocol.d.ts +9 -5
- package/lib/protocol.js +9 -5
- package/lib/types.d.ts +48 -20
- package/lib/types.js +4 -1
- package/package.json +4 -17
- package/schema/derec_descriptor.bin +0 -0
- package/schema/proto/committedderecshare.proto +93 -0
- package/schema/proto/communicationinfo.proto +104 -0
- package/schema/proto/contact.proto +258 -0
- package/schema/proto/derecmessage.proto +232 -0
- package/schema/proto/derecsecret.proto +163 -0
- package/schema/proto/derectransport.proto +38 -0
- package/schema/proto/error.proto +68 -0
- package/schema/proto/getshare.proto +184 -0
- package/schema/proto/pair.proto +284 -0
- package/schema/proto/parameterrange.proto +36 -0
- package/schema/proto/prepair.proto +163 -0
- package/schema/proto/result.proto +194 -0
- package/schema/proto/secretidsversions.proto +199 -0
- package/schema/proto/storeshare.proto +242 -0
- package/schema/proto/transportprotocol.proto +112 -0
- package/schema/proto/unpair.proto +132 -0
- package/schema/proto/updatechannelinfo.proto +100 -0
- package/schema/proto/verify.proto +160 -0
- package/src/errors.ts +3 -0
- package/src/messages.ts +5 -3
- package/src/primitives.ts +6 -2
- package/src/protocol.ts +10 -6
- package/src/types.ts +49 -23
|
@@ -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
|
-
* `
|
|
869
|
-
*
|
|
870
|
-
*
|
|
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 (*
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
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
|
-
*
|
|
2115
|
-
*
|
|
2116
|
-
*
|
|
2117
|
-
*
|
|
2118
|
-
*
|
|
2119
|
-
*
|
|
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`
|
|
2134
|
-
*
|
|
2135
|
-
*
|
|
2136
|
-
*
|
|
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
|
-
|
|
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,
|
|
@@ -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:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 39449544 bytes
|
|
4
|
+
sha256: f2776c0d3cd0a91e4e6b789bd1446aaf15d7720ed5d7af57319fbe5de5a3cbbc
|
package/lib/errors.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export type DeRecErrorCategory = (typeof DEREC_ERROR_CATEGORIES)[number];
|
|
|
21
21
|
* own before a value reaches the library, so this list is exactly the Rust
|
|
22
22
|
* `Code` table in `library/src/interop/error_codes.rs`.
|
|
23
23
|
*/
|
|
24
|
-
export declare const DEREC_ERROR_CODES: readonly ["ok", "non_ok_status", "version_mismatch", "invariant", "invalid_input", "protobuf_decode", "protobuf_encode", "protocol_violation", "store_error", "builder_error", "missing_shared_key", "role_mismatch", "replica_id_not_configured", "channel_already_paired", "already_restored", "restore_conflict", "replica_id_conflict", "encryption", "keygen", "finish_pairing_initiator", "finish_pairing_responder", "empty_transport_uri", "invalid_contact_message", "invalid_pair_request_message", "invalid_pair_response_message", "prepair_hash_mismatch", "missing_replica_id", "unexpected_replica_id", "incompatible_parameter_range", "empty_channels", "duplicate_channel_id", "invalid_threshold", "empty_secret_data", "vss_share_failed", "invalid_weight", "too_many_subshares", "empty_responses", "empty_committed_derec_share", "decode_committed_derec_share", "decode_derec_share", "secret_id_mismatch", "reconstruction_failed", "malformed_recovered_secret", "ffi_null_ptr", "ffi_bad_length", "ffi_bad_utf8", "ffi_bad_proto", "ffi_invalid_enum", "ffi_bad_shared_key", "ffi_nul_in_string", "transport_invalid", "no_usable_endpoint"];
|
|
24
|
+
export declare const DEREC_ERROR_CODES: readonly ["ok", "non_ok_status", "version_mismatch", "invariant", "invalid_input", "protobuf_decode", "protobuf_encode", "protocol_violation", "store_error", "builder_error", "missing_shared_key", "role_mismatch", "replica_id_not_configured", "channel_already_paired", "already_restored", "restore_conflict", "replica_id_conflict", "fingerprint_mismatch", "encryption", "keygen", "finish_pairing_initiator", "finish_pairing_responder", "empty_transport_uri", "invalid_contact_message", "invalid_pair_request_message", "invalid_pair_response_message", "prepair_hash_mismatch", "missing_replica_id", "unexpected_replica_id", "incompatible_parameter_range", "fingerprint_commitment_mismatch", "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
25
|
export type DeRecErrorCode = (typeof DEREC_ERROR_CODES)[number];
|
|
26
26
|
export interface DeRecError {
|
|
27
27
|
category: DeRecErrorCategory;
|
package/lib/errors.js
CHANGED
|
@@ -59,6 +59,7 @@ exports.DEREC_ERROR_CODES = [
|
|
|
59
59
|
"already_restored",
|
|
60
60
|
"restore_conflict",
|
|
61
61
|
"replica_id_conflict",
|
|
62
|
+
"fingerprint_mismatch",
|
|
62
63
|
"encryption",
|
|
63
64
|
"keygen",
|
|
64
65
|
"finish_pairing_initiator",
|
|
@@ -71,6 +72,7 @@ exports.DEREC_ERROR_CODES = [
|
|
|
71
72
|
"missing_replica_id",
|
|
72
73
|
"unexpected_replica_id",
|
|
73
74
|
"incompatible_parameter_range",
|
|
75
|
+
"fingerprint_commitment_mismatch",
|
|
74
76
|
"empty_channels",
|
|
75
77
|
"duplicate_channel_id",
|
|
76
78
|
"invalid_threshold",
|
|
@@ -78,6 +80,7 @@ exports.DEREC_ERROR_CODES = [
|
|
|
78
80
|
"vss_share_failed",
|
|
79
81
|
"invalid_weight",
|
|
80
82
|
"too_many_subshares",
|
|
83
|
+
"invalid_keep_version",
|
|
81
84
|
"empty_responses",
|
|
82
85
|
"empty_committed_derec_share",
|
|
83
86
|
"decode_committed_derec_share",
|
package/lib/messages.js
CHANGED
|
@@ -33,9 +33,9 @@ exports.encodeOptionalMessage = encodeOptionalMessage;
|
|
|
33
33
|
* surface.
|
|
34
34
|
*
|
|
35
35
|
* Both conversions are keyed by field name, matching the lists in
|
|
36
|
-
* `message_json.rs`. A name-keyed walk is deliberate:
|
|
37
|
-
*
|
|
38
|
-
* bytes" rule
|
|
36
|
+
* `message_json.rs`. A name-keyed walk is deliberate: only the fields that
|
|
37
|
+
* file names change representation, so a structural "array of numbers is
|
|
38
|
+
* bytes" rule cannot corrupt a field that is not bytes.
|
|
39
39
|
*/
|
|
40
40
|
const codec_1 = require("./codec");
|
|
41
41
|
const native_1 = require("./native");
|
|
@@ -96,6 +96,8 @@ const BYTE_FIELDS = new Set([
|
|
|
96
96
|
'mlkem_encapsulation_key',
|
|
97
97
|
'ecies_public_key',
|
|
98
98
|
'contact_binding_hash',
|
|
99
|
+
'fingerprint_commitment',
|
|
100
|
+
'fingerprint_nonce',
|
|
99
101
|
'bytes_value',
|
|
100
102
|
'share',
|
|
101
103
|
'committed_de_rec_share',
|
package/lib/primitives.d.ts
CHANGED
|
@@ -68,7 +68,7 @@ export declare const primitives: {
|
|
|
68
68
|
sharing: {
|
|
69
69
|
request: {
|
|
70
70
|
split(channels: WeightedChannel[], secret_id: bigint, version: number, secret_data: Uint8Array, threshold: number): SplitResult;
|
|
71
|
-
produce(channel_id: bigint, version: number, secret_id: bigint, committed_share: CommittedDeRecShare,
|
|
71
|
+
produce(channel_id: bigint, version: number, secret_id: bigint, committed_share: CommittedDeRecShare, keep_version: number, description: string, shared_key: Uint8Array, reply_to?: TransportProtocol[]): ProduceResult;
|
|
72
72
|
extract(envelope_bytes: Uint8Array, shared_key: Uint8Array): {
|
|
73
73
|
request: StoreShareRequestMessage;
|
|
74
74
|
};
|
package/lib/primitives.js
CHANGED
|
@@ -214,6 +214,7 @@ const pairing = {
|
|
|
214
214
|
mlkem_encapsulation_key: bytes(result.mlkem_encapsulation_key),
|
|
215
215
|
ecies_public_key: bytes(result.ecies_public_key),
|
|
216
216
|
nonce: result.nonce,
|
|
217
|
+
fingerprint_commitment: bytes(result.fingerprint_commitment),
|
|
217
218
|
};
|
|
218
219
|
},
|
|
219
220
|
produce_pre_pair_no_keys(channel_id, request) {
|
|
@@ -229,6 +230,7 @@ const pairing = {
|
|
|
229
230
|
mlkem_encapsulation_key: bytes(result.mlkem_encapsulation_key),
|
|
230
231
|
ecies_public_key: bytes(result.ecies_public_key),
|
|
231
232
|
nonce: result.nonce,
|
|
233
|
+
fingerprint_commitment: bytes(result.fingerprint_commitment),
|
|
232
234
|
};
|
|
233
235
|
},
|
|
234
236
|
},
|
|
@@ -279,8 +281,8 @@ const sharing = {
|
|
|
279
281
|
}
|
|
280
282
|
return { shares };
|
|
281
283
|
},
|
|
282
|
-
produce(channel_id, version, secret_id, committed_share,
|
|
283
|
-
const envelope = call('produce_store_share_request_message', channel_id, version, secret_id, (0, messages_1.encodeMessage)(messages_1.MessageKind.CommittedDeRecShare, committed_share),
|
|
284
|
+
produce(channel_id, version, secret_id, committed_share, keep_version, description, shared_key, reply_to) {
|
|
285
|
+
const envelope = call('produce_store_share_request_message', channel_id, version, secret_id, (0, messages_1.encodeMessage)(messages_1.MessageKind.CommittedDeRecShare, committed_share), keep_version, (0, codec_1.utf8Encode)(description), shared_key, replyTo(reply_to));
|
|
284
286
|
return { envelope: bytes(envelope) };
|
|
285
287
|
},
|
|
286
288
|
extract(envelope_bytes, shared_key) {
|
package/lib/protocol.d.ts
CHANGED
|
@@ -277,22 +277,26 @@ export declare class DeRecProtocol {
|
|
|
277
277
|
getFingerprint(channelId: bigint | number): Promise<string>;
|
|
278
278
|
/**
|
|
279
279
|
* Verify `fingerprint` against the channel's locally-derived one. On
|
|
280
|
-
* match, the channel transitions from `Pending` to `Paired`.
|
|
281
|
-
*
|
|
280
|
+
* match, the channel transitions from `Pending` to `Paired`.
|
|
281
|
+
*
|
|
282
|
+
* A mismatch rejects with code `fingerprint_mismatch` — a possible
|
|
283
|
+
* man-in-the-middle. A `Pending` pairing is revoked: its records, channel
|
|
284
|
+
* key and pairing material are deleted, so pair again. A channel already
|
|
285
|
+
* `Paired` is left as it is.
|
|
282
286
|
*
|
|
283
287
|
* On a replica destination, confirming is also the decision to adopt the
|
|
284
288
|
* group's vault: the source's publish is then installed as it arrives,
|
|
285
289
|
* with no further prompt. Ask the user before calling this; to decline,
|
|
286
|
-
* never confirm.
|
|
290
|
+
* never confirm: expired-channel cleanup removes the channel and its key.
|
|
287
291
|
*
|
|
288
292
|
* On a promotion the current snapshot is published to the promoted peer,
|
|
289
293
|
* reusing the stored helper weights. If one is no longer valid under the
|
|
290
294
|
* current threshold, that publish fails with `invalid_weight` before
|
|
291
295
|
* anything is sent and this throws. The promotion stands: calling this
|
|
292
|
-
* again resolves
|
|
296
|
+
* again resolves and publishes nothing, so call `start` with
|
|
293
297
|
* `ProtectSecret` and valid weights to reach the promoted peer.
|
|
294
298
|
*/
|
|
295
|
-
verifyFingerprint(channelId: bigint | number, fingerprint: string): Promise<
|
|
299
|
+
verifyFingerprint(channelId: bigint | number, fingerprint: string): Promise<void>;
|
|
296
300
|
removeExpiredChannels(olderThanSecs: number): Promise<string[]>;
|
|
297
301
|
/**
|
|
298
302
|
* Rebuild this protocol's `secret_id` namespace from a recovered `Secret`.
|
package/lib/protocol.js
CHANGED
|
@@ -643,23 +643,27 @@ class DeRecProtocol {
|
|
|
643
643
|
}
|
|
644
644
|
/**
|
|
645
645
|
* Verify `fingerprint` against the channel's locally-derived one. On
|
|
646
|
-
* match, the channel transitions from `Pending` to `Paired`.
|
|
647
|
-
*
|
|
646
|
+
* match, the channel transitions from `Pending` to `Paired`.
|
|
647
|
+
*
|
|
648
|
+
* A mismatch rejects with code `fingerprint_mismatch` — a possible
|
|
649
|
+
* man-in-the-middle. A `Pending` pairing is revoked: its records, channel
|
|
650
|
+
* key and pairing material are deleted, so pair again. A channel already
|
|
651
|
+
* `Paired` is left as it is.
|
|
648
652
|
*
|
|
649
653
|
* On a replica destination, confirming is also the decision to adopt the
|
|
650
654
|
* group's vault: the source's publish is then installed as it arrives,
|
|
651
655
|
* with no further prompt. Ask the user before calling this; to decline,
|
|
652
|
-
* never confirm.
|
|
656
|
+
* never confirm: expired-channel cleanup removes the channel and its key.
|
|
653
657
|
*
|
|
654
658
|
* On a promotion the current snapshot is published to the promoted peer,
|
|
655
659
|
* reusing the stored helper weights. If one is no longer valid under the
|
|
656
660
|
* current threshold, that publish fails with `invalid_weight` before
|
|
657
661
|
* anything is sent and this throws. The promotion stands: calling this
|
|
658
|
-
* again resolves
|
|
662
|
+
* again resolves and publishes nothing, so call `start` with
|
|
659
663
|
* `ProtectSecret` and valid weights to reach the promoted peer.
|
|
660
664
|
*/
|
|
661
665
|
async verifyFingerprint(channelId, fingerprint) {
|
|
662
|
-
|
|
666
|
+
await this.host.verifyFingerprint(toBigInt(channelId), fingerprint);
|
|
663
667
|
}
|
|
664
668
|
async removeExpiredChannels(olderThanSecs) {
|
|
665
669
|
const buffer = (await this.host.removeExpiredChannels(olderThanSecs));
|
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.
|
|
233
|
-
*
|
|
234
|
-
*
|
|
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
|
|
240
|
-
* `version`. Asked once per sharing round, before anything is
|
|
241
|
-
* including the rounds the library starts itself; the answer
|
|
242
|
-
* `
|
|
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
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
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
|
-
|
|
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[];
|
|
@@ -1702,6 +1716,11 @@ export interface PairResponseMessage {
|
|
|
1702
1716
|
* its own derivation. Zero on rejection (non-Ok `result.status`).
|
|
1703
1717
|
*/
|
|
1704
1718
|
channel_id: bigint;
|
|
1719
|
+
/**
|
|
1720
|
+
* Present only when `result.status === Ok`. The 32-byte fingerprint nonce
|
|
1721
|
+
* the contact creator committed to in `fingerprint_commitment`.
|
|
1722
|
+
*/
|
|
1723
|
+
fingerprint_nonce?: Uint8Array;
|
|
1705
1724
|
}
|
|
1706
1725
|
export interface PrePairRequestMessage {
|
|
1707
1726
|
nonce: bigint;
|
|
@@ -1720,6 +1739,12 @@ export interface PrePairResponseMessage {
|
|
|
1720
1739
|
ecies_public_key?: Uint8Array;
|
|
1721
1740
|
nonce: bigint;
|
|
1722
1741
|
timestamp?: Timestamp;
|
|
1742
|
+
/**
|
|
1743
|
+
* Present only when `result.status === Ok`. The creator's 32-byte
|
|
1744
|
+
* commitment to the fingerprint nonce its `PairResponseMessage` reveals,
|
|
1745
|
+
* covering the two keys above.
|
|
1746
|
+
*/
|
|
1747
|
+
fingerprint_commitment?: Uint8Array;
|
|
1723
1748
|
}
|
|
1724
1749
|
export interface GetShareRequestMessage {
|
|
1725
1750
|
secret_id: bigint;
|
|
@@ -1761,7 +1786,7 @@ export interface StoreShareRequestMessage {
|
|
|
1761
1786
|
share: Uint8Array;
|
|
1762
1787
|
share_algorithm: number;
|
|
1763
1788
|
version: number;
|
|
1764
|
-
|
|
1789
|
+
keep_version: number;
|
|
1765
1790
|
version_description: string;
|
|
1766
1791
|
timestamp?: Timestamp;
|
|
1767
1792
|
secret_id: bigint;
|
|
@@ -1887,6 +1912,9 @@ export interface ProcessPrePairResult {
|
|
|
1887
1912
|
ecies_public_key: Uint8Array;
|
|
1888
1913
|
/** Nonce echoed from the original `ContactMessage`. */
|
|
1889
1914
|
nonce: bigint;
|
|
1915
|
+
/** The creator's 32-byte commitment to its fingerprint nonce. Copy it into
|
|
1916
|
+
* the contact the pair request is built from, alongside the two keys. */
|
|
1917
|
+
fingerprint_commitment: Uint8Array;
|
|
1890
1918
|
}
|
|
1891
1919
|
/**
|
|
1892
1920
|
* A channel paired with how many subshares it holds. A weight of `1` is an
|
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.10",
|
|
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
|
+
}
|