@derec-alliance/react-native 0.0.10 → 0.1.0
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 +122 -1
- 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 +21 -2
- package/cpp/Primitives.h +5 -3
- package/cpp/derec_ffi.h +53 -3
- package/ios/DeRecFFI.xcframework/Info.plist +5 -5
- package/ios/DeRecFFI.xcframework/ios-arm64/Headers/derec_ffi.h +53 -3
- package/ios/DeRecFFI.xcframework/ios-arm64/libderec_library.a +0 -0
- package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/Headers/derec_ffi.h +53 -3
- package/ios/DeRecFFI.xcframework/ios-arm64_x86_64-simulator/libderec_library.a +2 -2
- package/lib/errors.d.ts +8 -3
- package/lib/errors.js +3 -0
- package/lib/primitives.d.ts +22 -0
- package/lib/primitives.js +24 -0
- package/lib/protocol.d.ts +25 -0
- package/lib/protocol.js +11 -0
- package/lib/types.d.ts +171 -38
- package/package.json +1 -1
- package/schema/derec_descriptor.bin +0 -0
- package/schema/proto/committedderecshare.proto +5 -3
- package/schema/proto/contact.proto +13 -4
- package/schema/proto/derecmessage.proto +61 -14
- package/schema/proto/derectransport.proto +9 -3
- package/schema/proto/prepair.proto +1 -0
- package/schema/proto/result.proto +3 -2
- package/schema/proto/transportprotocol.proto +4 -2
- package/src/errors.ts +9 -1
- package/src/primitives.ts +24 -0
- package/src/protocol.ts +29 -0
- package/src/types.ts +158 -32
package/README.md
CHANGED
|
@@ -190,6 +190,34 @@ from `SharingComplete` with `threshold_met` rather than by counting
|
|
|
190
190
|
responses to requests is the application's
|
|
191
191
|
job](https://github.com/derecalliance/lib-derec/tree/main/library#matching-responses-to-requests-is-the-applications-job).
|
|
192
192
|
|
|
193
|
+
A recovery reconstructs nothing until every helper it asked has answered (a
|
|
194
|
+
share, a refusal or a corrupted share all count) or
|
|
195
|
+
`timeouts.get_share_response_secs` has passed since the requests went out;
|
|
196
|
+
each silent helper is then reported as `RecoverSecretFailed` with
|
|
197
|
+
`error: "timeout"` from `tick()`. It then decides exactly once:
|
|
198
|
+
|
|
199
|
+
- `SecretRecovered` — one secret reconstructs and every collected share is
|
|
200
|
+
part of it;
|
|
201
|
+
- `RecoveryDisputed { version, secret, supported_by, disputed_by }` — one
|
|
202
|
+
secret reconstructs, but other helpers hold valid shares of a different
|
|
203
|
+
split that does not. Either side can be the owner's: colluding helpers can
|
|
204
|
+
forge a complete split, and the honest ones may be too few to reconstruct
|
|
205
|
+
theirs. Show the owner what `secret` holds and who stands on each side, and
|
|
206
|
+
pass it to `restore` only once they confirm it;
|
|
207
|
+
- `RecoveryConflict { version, candidates, disputed_by }` — two or more
|
|
208
|
+
different secrets reconstruct. Each candidate carries the `secret` and
|
|
209
|
+
`supported_by`. The library never picks: involve the owner, and pass the
|
|
210
|
+
candidate they confirm to `restore`;
|
|
211
|
+
- `RecoveryIncomplete { secret_id, version, shares_received }` — nothing reconstructs.
|
|
212
|
+
The recovery is closed; start it again to retry.
|
|
213
|
+
|
|
214
|
+
`supported_by` / `disputed_by` name helpers as `RecoveryHelper { channel_id,
|
|
215
|
+
communication_info }`, the `communication_info` being what the helper
|
|
216
|
+
advertised when it paired, so the app can tell the owner who is on each side.
|
|
217
|
+
That is the helper's own configured communication info, not the
|
|
218
|
+
`peer_communication_info` it passed to `start(Pairing)`: a helper that
|
|
219
|
+
configures none is named by its channel alone.
|
|
220
|
+
|
|
193
221
|
**After recovery: restore or join.** `SecretRecovered` writes nothing, so
|
|
194
222
|
decide before calling `restore`. When `secret.replicas?.members` names live
|
|
195
223
|
members other than the lost device, do not restore: tell the user and offer
|
|
@@ -209,6 +237,59 @@ envelope and the inner message. A message whose two timestamps differ, or
|
|
|
209
237
|
where either or both are absent, is ignored as `MessageIgnored` with
|
|
210
238
|
`reason: 'TimestampMismatch'`; this includes replies from 0.0.8 peers.
|
|
211
239
|
|
|
240
|
+
Within the inbound window `process` handles every copy of a message it is
|
|
241
|
+
given, including one of this device's own messages delivered back to it: both
|
|
242
|
+
ends of a channel encrypt under one key, so a reflected message decrypts as if
|
|
243
|
+
the peer had sent it. The library bounds a message's age and keeps each flow
|
|
244
|
+
safe to repeat; it does not remember which messages it has seen. Detecting
|
|
245
|
+
replays and reflections is the app's job, since the app owns the transport,
|
|
246
|
+
and how it does so is its choice. `sequence` is not a replay counter. If the
|
|
247
|
+
app does detect duplicates, key on the envelope's encrypted `message` field:
|
|
248
|
+
it cannot be changed without failing decryption and differs for every
|
|
249
|
+
message, since each is sealed under a fresh random nonce;
|
|
250
|
+
`envelope.encrypted_payload` reads that field. Never key on a hash of the raw
|
|
251
|
+
envelope: `sequence` and `traceId` are not authenticated and an
|
|
252
|
+
envelope can be re-encoded, so a copy can arrive as different bytes. Keep each
|
|
253
|
+
key for the inbound window measured from the later of the envelope's arrival
|
|
254
|
+
(or send) and its `timestamp`, and keep the record across restarts. A sender
|
|
255
|
+
that retries by building the message again draws a new nonce, so its retry is
|
|
256
|
+
a new message. A helper ignores a `StoreShareRequest` for a version older than
|
|
257
|
+
the newest it stores on the channel, and not stored itself, as
|
|
258
|
+
`MessageIgnored` with `reason: "Superseded"`, unanswered. Reject a contact
|
|
259
|
+
update older than the last one you accepted on the channel, using the
|
|
260
|
+
`timestamp` of the envelope that raised it; that needs auto-accept off for
|
|
261
|
+
`UpdateChannelInfo`.
|
|
262
|
+
|
|
263
|
+
Choose `timeouts.inbound_message_secs` to cover the longest a message can take
|
|
264
|
+
to arrive plus the clock difference between devices (default 300 seconds; a
|
|
265
|
+
store-and-forward relay with devices offline for long periods may need an
|
|
266
|
+
hour); a longer window is a longer replay exposure, so a duplicate record must
|
|
267
|
+
cover all of it. What each flow does with a message it already handled is in
|
|
268
|
+
[Replays and
|
|
269
|
+
reflections](https://github.com/derecalliance/lib-derec/tree/main/library#replays-and-reflections).
|
|
270
|
+
|
|
271
|
+
The envelope's protocol version is copied into the encrypted payload and
|
|
272
|
+
checked like the timestamp, so it cannot be changed undetected: a message
|
|
273
|
+
whose copy differs is ignored as `MessageIgnored` with
|
|
274
|
+
`reason: 'ProtocolVersionMismatch'`. A message from an earlier release carries
|
|
275
|
+
no copy, which reads as 0.0, its envelope's version.
|
|
276
|
+
`withMinProtocolVersion(major, minor)` (default 0.0, every version;
|
|
277
|
+
`min_protocol_version` in the config JSON) stops accepting older releases:
|
|
278
|
+
once every peer runs 0.1.0 or later, raise it to 0.1, and a message naming an
|
|
279
|
+
older version is ignored as `MessageIgnored` with
|
|
280
|
+
`reason: 'ProtocolVersionTooOld'`: nothing in it is decrypted, stored or
|
|
281
|
+
answered.
|
|
282
|
+
|
|
283
|
+
A pairing has a lifetime, `timeouts.pairing_secs` (default 30). Both sides
|
|
284
|
+
enforce it and nothing is sent on expiry: `start(FlowKind.Pairing, …)` refuses
|
|
285
|
+
a contact older than it with code `pairing_expired`; the contact's creator
|
|
286
|
+
reports a request on such a contact, or a request older than the lifetime, as
|
|
287
|
+
`MessageIgnored` with reason `"Expired"` before any `ActionRequired`, and
|
|
288
|
+
`accept` refuses a request that outlived it with `pairing_expired`. Pairing
|
|
289
|
+
involves both parties, so treat an expiry as a retry and ask the user to scan
|
|
290
|
+
or share a fresh contact. Keep the scanner's `expired_channels` timeout at
|
|
291
|
+
least `pairing_secs` plus the time a response takes to arrive.
|
|
292
|
+
|
|
212
293
|
---
|
|
213
294
|
|
|
214
295
|
## When `process()` fails
|
|
@@ -510,7 +591,7 @@ case nothing is sent:
|
|
|
510
591
|
- `accept()` throws. The pairing has completed and its response was sent,
|
|
511
592
|
but `PairingCompleted` is not returned.
|
|
512
593
|
- `verifyFingerprint()` throws. The promotion stands: calling it again
|
|
513
|
-
resolves
|
|
594
|
+
resolves and publishes nothing.
|
|
514
595
|
|
|
515
596
|
Call `start` with `ProtectSecret` and valid weights to publish to every
|
|
516
597
|
helper.
|
|
@@ -643,6 +724,8 @@ The canonical JSON, shared by every SDK, is:
|
|
|
643
724
|
"inbound_message_secs": 300,
|
|
644
725
|
"sharing_round_secs": 60,
|
|
645
726
|
"unpair_ack_secs": 60,
|
|
727
|
+
"get_share_response_secs": 300,
|
|
728
|
+
"pairing_secs": 30,
|
|
646
729
|
"expired_channels": { "enabled": true, "timeout_in_secs": 300 }
|
|
647
730
|
},
|
|
648
731
|
"parameter_range": { "min_share_size": 1, "max_share_size": 4096 },
|
|
@@ -678,6 +761,44 @@ react-native.config.js
|
|
|
678
761
|
|
|
679
762
|
---
|
|
680
763
|
|
|
764
|
+
## Security considerations
|
|
765
|
+
|
|
766
|
+
### An unconfirmed replica member is not part of the group
|
|
767
|
+
|
|
768
|
+
Until a device confirms a member's fingerprint with `verifyFingerprint`, that
|
|
769
|
+
member is not part of the group as far as the device is concerned. It is left
|
|
770
|
+
out of every roster the device publishes (each new version, catch-up answers
|
|
771
|
+
and the vault itself), it is not asked in a replica version check, and it
|
|
772
|
+
cannot succeed a removed source. Every recipient installs a roster's members
|
|
773
|
+
as paired, so listing an unconfirmed one would admit it on their behalf.
|
|
774
|
+
|
|
775
|
+
### Every helper sees the vault's compressed length
|
|
776
|
+
|
|
777
|
+
The vault (the user's secrets, every helper's channel key and
|
|
778
|
+
`communication_info`, and the replica group key) is compressed as one gzip stream
|
|
779
|
+
before it is encrypted and split. Encryption keeps the length, so every
|
|
780
|
+
helper learns the compressed length of every version. A helper also chooses
|
|
781
|
+
part of what is compressed: its own `communication_info`, which it changes with
|
|
782
|
+
`UpdateChannelInfo`. When that text repeats part of a secret elsewhere in
|
|
783
|
+
the vault, the vault compresses better, so over many versions a corrupted
|
|
784
|
+
helper could learn another helper's channel key, the group key or the
|
|
785
|
+
user's secrets a few characters at a time (the side channel behind CRIME
|
|
786
|
+
and BREACH). Each guess costs a new version, which only the owner creates,
|
|
787
|
+
after a contact change the owner's application has to accept. Keep the `updateChannelInfo` auto-accept flag
|
|
788
|
+
off, and treat a helper that keeps changing its contact details as suspect.
|
|
789
|
+
|
|
790
|
+
### Decoding a recovered vault has no memory limit
|
|
791
|
+
|
|
792
|
+
In recovery the vault is decrypted from shares that nothing authenticates,
|
|
793
|
+
so a forged recovery group can deliver any payload, including one built to
|
|
794
|
+
exhaust memory. The decoder parses the vault while it inflates it: a
|
|
795
|
+
payload that is not JSON is refused after its first bytes, and padding is
|
|
796
|
+
not buffered. A payload that is valid JSON still receives the memory its
|
|
797
|
+
largest value claims, and gzip lets a payload claim up to about 1030 times
|
|
798
|
+
its own size. The library sets no limit. When memory runs out, the process is killed by the operating system or aborts inside the native library, with no error and no event. To bound it, configure
|
|
799
|
+
`parameter_range.max_share_size`: a recovery share larger than that is refused before anything is
|
|
800
|
+
decoded, so a vault can claim at most about 1030 times that size.
|
|
801
|
+
|
|
681
802
|
## License
|
|
682
803
|
|
|
683
804
|
Apache License 2.0
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/cpp/Primitives.cpp
CHANGED
|
@@ -38,6 +38,8 @@ void throwDeRecError(jsi::Runtime& rt,
|
|
|
38
38
|
int32_t peerStatus = error.peer_status;
|
|
39
39
|
uint32_t expected = error.expected;
|
|
40
40
|
uint32_t got = error.got;
|
|
41
|
+
bool hasChannelId = process.hasChannelId || error.has_channel_id;
|
|
42
|
+
uint64_t channelId = process.hasChannelId ? process.channelId : error.channel_id;
|
|
41
43
|
|
|
42
44
|
// Release both owned strings in one call, matching the ABI contract.
|
|
43
45
|
DeRecError owned = error;
|
|
@@ -62,9 +64,9 @@ void throwDeRecError(jsi::Runtime& rt,
|
|
|
62
64
|
jsi::Value::createFromJsonUtf8(rt, conflictingChannelIdsJson.data(),
|
|
63
65
|
conflictingChannelIdsJson.size()));
|
|
64
66
|
}
|
|
65
|
-
if (
|
|
67
|
+
if (hasChannelId) {
|
|
66
68
|
payload.setProperty(rt, "channel_id",
|
|
67
|
-
jsi::String::createFromUtf8(rt, std::to_string(
|
|
69
|
+
jsi::String::createFromUtf8(rt, std::to_string(channelId)));
|
|
68
70
|
}
|
|
69
71
|
if (!process.eventsJson.empty()) {
|
|
70
72
|
payload.setProperty(rt, "events",
|
|
@@ -373,6 +375,22 @@ jsi::Value readTraceId(jsi::Runtime& rt,
|
|
|
373
375
|
return jsi::Value(rt, jsi::BigInt::fromUint64(rt, result.trace_id));
|
|
374
376
|
}
|
|
375
377
|
|
|
378
|
+
/// `encrypted_payload_from_envelope(envelope: ArrayBuffer) -> ArrayBuffer`
|
|
379
|
+
jsi::Value encryptedPayload(jsi::Runtime& rt,
|
|
380
|
+
const jsi::Value&,
|
|
381
|
+
const jsi::Value* args,
|
|
382
|
+
size_t count) {
|
|
383
|
+
requireArgs(rt, "encrypted_payload_from_envelope", count, 1);
|
|
384
|
+
ByteView envelope = asBytes(rt, args[0]);
|
|
385
|
+
EncryptedPayloadResult result =
|
|
386
|
+
encrypted_payload_from_envelope(envelope.ptr, envelope.len);
|
|
387
|
+
if (result.error.code != 0) {
|
|
388
|
+
throwDeRecError(rt, result.error);
|
|
389
|
+
}
|
|
390
|
+
std::vector<uint8_t> bytes = takeBuffer(result.payload);
|
|
391
|
+
return toArrayBuffer(rt, bytes.data(), bytes.size());
|
|
392
|
+
}
|
|
393
|
+
|
|
376
394
|
/// `version() -> { major: number, minor: number }` — the protocol version the
|
|
377
395
|
/// core writes into every envelope it produces.
|
|
378
396
|
jsi::Value protocolVersion(jsi::Runtime& rt,
|
|
@@ -1383,6 +1401,7 @@ void installPrimitives(jsi::Runtime& rt, jsi::Object& host) {
|
|
|
1383
1401
|
processGetSecretIdsVersionsResponseMessage);
|
|
1384
1402
|
bind(rt, host, "apply_trace_id_to_envelope", 2, applyTraceId);
|
|
1385
1403
|
bind(rt, host, "read_trace_id_from_envelope", 1, readTraceId);
|
|
1404
|
+
bind(rt, host, "encrypted_payload_from_envelope", 1, encryptedPayload);
|
|
1386
1405
|
bind(rt, host, "create_contact_message", 5, createContactMessage);
|
|
1387
1406
|
bind(rt, host, "encode_contact_message", 1, encodeContactMessage);
|
|
1388
1407
|
bind(rt, host, "decode_contact_message", 1, decodeContactMessage);
|
package/cpp/Primitives.h
CHANGED
|
@@ -34,9 +34,11 @@ struct ProcessFailureDetails {
|
|
|
34
34
|
uint64_t channelId = 0;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
/// As above, additionally attaching `
|
|
38
|
-
/// `process.
|
|
39
|
-
///
|
|
37
|
+
/// As above, additionally attaching `events` (the JSON array verbatim) when
|
|
38
|
+
/// `process.eventsJson` is non-empty, which only `process` produces.
|
|
39
|
+
/// `channel_id` (a decimal string) is `process.channelId` when
|
|
40
|
+
/// `process.hasChannelId` is set, else the error's own channel when it
|
|
41
|
+
/// names one.
|
|
40
42
|
[[noreturn]] void throwDeRecError(facebook::jsi::Runtime& rt,
|
|
41
43
|
const DeRecError& error,
|
|
42
44
|
const std::vector<uint8_t>& conflictingChannelIdsJson,
|
package/cpp/derec_ffi.h
CHANGED
|
@@ -42,14 +42,15 @@
|
|
|
42
42
|
* fields this build cannot see and writing the truncated result back.
|
|
43
43
|
*
|
|
44
44
|
* The value tracks the release that last changed the shape, not the release
|
|
45
|
-
* that is current: it moved to 3 when `transport` became `transports`,
|
|
46
|
-
*
|
|
45
|
+
* that is current: it moved to 3 when `transport` became `transports`, to 4
|
|
46
|
+
* when [`ReplicaMember::handover_channel`] was added, and stays there until
|
|
47
|
+
* the next shape change.
|
|
47
48
|
*
|
|
48
49
|
* Declared unconditionally, unlike the serde impls that stamp it: the SDK
|
|
49
50
|
* bridges mirror this number in their own encoders, and a constant they must
|
|
50
51
|
* agree with should not appear and disappear with a feature flag.
|
|
51
52
|
*/
|
|
52
|
-
#define CHANNEL_RECORD_SCHEMA_VERSION
|
|
53
|
+
#define CHANNEL_RECORD_SCHEMA_VERSION 4
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
56
|
* Latest encoding major version, used for all new encodes. Bump only on a
|
|
@@ -106,6 +107,8 @@
|
|
|
106
107
|
|
|
107
108
|
#define DEREC_CATEGORY_STATE_STORE 15
|
|
108
109
|
|
|
110
|
+
#define DEREC_CATEGORY_TRANSPORT 16
|
|
111
|
+
|
|
109
112
|
#define DEREC_CODE_OK 0
|
|
110
113
|
|
|
111
114
|
#define DEREC_CODE_NON_OK_STATUS 1
|
|
@@ -246,6 +249,14 @@
|
|
|
246
249
|
*/
|
|
247
250
|
#define DEREC_CODE_FINGERPRINT_COMMITMENT_MISMATCH 48
|
|
248
251
|
|
|
252
|
+
/**
|
|
253
|
+
* The pairing outlived `Timeouts::pairing`: the scanner refuses a contact
|
|
254
|
+
* older than it, and the contact's creator refuses to accept a request
|
|
255
|
+
* that arrives after it. Surfaced as [`DEREC_CATEGORY_PAIRING`]; nothing is
|
|
256
|
+
* sent to the peer, and a fresh contact starts a new pairing.
|
|
257
|
+
*/
|
|
258
|
+
#define DEREC_CODE_PAIRING_EXPIRED 49
|
|
259
|
+
|
|
249
260
|
#define DEREC_CODE_EMPTY_CHANNELS 60
|
|
250
261
|
|
|
251
262
|
#define DEREC_CODE_DUPLICATE_CHANNEL_ID 61
|
|
@@ -312,6 +323,13 @@
|
|
|
312
323
|
*/
|
|
313
324
|
#define DEREC_CODE_NO_USABLE_ENDPOINT 121
|
|
314
325
|
|
|
326
|
+
/**
|
|
327
|
+
* The application's transport delivered a message to none of the peer's
|
|
328
|
+
* endpoints: the `send` callback returned non-zero.
|
|
329
|
+
* `DEREC_CATEGORY_TRANSPORT`.
|
|
330
|
+
*/
|
|
331
|
+
#define DEREC_CODE_TRANSPORT_SEND_FAILED 123
|
|
332
|
+
|
|
315
333
|
/**
|
|
316
334
|
* Return codes for [`crate::interop::ffi::protocol::stores::ShareStoreCallbacks::save`]
|
|
317
335
|
* and `ShareStoreCallbacks::record_verification`: `0` is success, each of
|
|
@@ -494,6 +512,14 @@ typedef struct DeRecError {
|
|
|
494
512
|
* Valid when `code == DEREC_CODE_VERSION_MISMATCH`.
|
|
495
513
|
*/
|
|
496
514
|
uint32_t got;
|
|
515
|
+
/**
|
|
516
|
+
* Whether `channel_id` is set: the error names the channel it is about.
|
|
517
|
+
*/
|
|
518
|
+
bool has_channel_id;
|
|
519
|
+
/**
|
|
520
|
+
* The channel the error is about. Valid when `has_channel_id`.
|
|
521
|
+
*/
|
|
522
|
+
uint64_t channel_id;
|
|
497
523
|
} DeRecError;
|
|
498
524
|
|
|
499
525
|
typedef struct DeRecBuffer {
|
|
@@ -557,6 +583,14 @@ typedef struct ReadTraceIdResult {
|
|
|
557
583
|
uint64_t trace_id;
|
|
558
584
|
} ReadTraceIdResult;
|
|
559
585
|
|
|
586
|
+
typedef struct EncryptedPayloadResult {
|
|
587
|
+
struct DeRecError error;
|
|
588
|
+
/**
|
|
589
|
+
* The envelope's encrypted `message` field. Empty on error.
|
|
590
|
+
*/
|
|
591
|
+
struct DeRecBuffer payload;
|
|
592
|
+
} EncryptedPayloadResult;
|
|
593
|
+
|
|
560
594
|
/**
|
|
561
595
|
* Result of a message JSON codec call. `bytes` is UTF-8 JSON for
|
|
562
596
|
* [`derec_decode_message_json`] and protobuf wire bytes for
|
|
@@ -1429,6 +1463,20 @@ struct ApplyTraceIdResult apply_trace_id_to_envelope(const uint8_t *envelope_ptr
|
|
|
1429
1463
|
struct ReadTraceIdResult read_trace_id_from_envelope(const uint8_t *envelope_ptr,
|
|
1430
1464
|
size_t envelope_len);
|
|
1431
1465
|
|
|
1466
|
+
/**
|
|
1467
|
+
* Read the encrypted `message` field off an envelope, without the channel
|
|
1468
|
+
* key: the part of an envelope the application's duplicate detection can
|
|
1469
|
+
* key on.
|
|
1470
|
+
*
|
|
1471
|
+
* Mirrors [`crate::derec_message::encrypted_payload`].
|
|
1472
|
+
*
|
|
1473
|
+
* # Safety
|
|
1474
|
+
*
|
|
1475
|
+
* `envelope_ptr` must point to a readable byte range of length `envelope_len`.
|
|
1476
|
+
*/
|
|
1477
|
+
struct EncryptedPayloadResult encrypted_payload_from_envelope(const uint8_t *envelope_ptr,
|
|
1478
|
+
size_t envelope_len);
|
|
1479
|
+
|
|
1432
1480
|
/**
|
|
1433
1481
|
* Releases the owned strings carried by a [`DeRecError`]. After
|
|
1434
1482
|
* returning, `error.message` and `error.peer_memo` are both null —
|
|
@@ -1804,6 +1852,8 @@ struct ProcessPrePairResponseMessageResult process_pre_pair_response_message(con
|
|
|
1804
1852
|
* "inbound_message_secs": 300,
|
|
1805
1853
|
* "sharing_round_secs": 60,
|
|
1806
1854
|
* "unpair_ack_secs": 60,
|
|
1855
|
+
* "get_share_response_secs": 300,
|
|
1856
|
+
* "pairing_secs": 30,
|
|
1807
1857
|
* "expired_channels": { "enabled": true, "timeout_in_secs": 300 }
|
|
1808
1858
|
* },
|
|
1809
1859
|
* "unsafe_connection": false,
|
|
@@ -10,15 +10,18 @@
|
|
|
10
10
|
<key>HeadersPath</key>
|
|
11
11
|
<string>Headers</string>
|
|
12
12
|
<key>LibraryIdentifier</key>
|
|
13
|
-
<string>ios-
|
|
13
|
+
<string>ios-arm64_x86_64-simulator</string>
|
|
14
14
|
<key>LibraryPath</key>
|
|
15
15
|
<string>libderec_library.a</string>
|
|
16
16
|
<key>SupportedArchitectures</key>
|
|
17
17
|
<array>
|
|
18
18
|
<string>arm64</string>
|
|
19
|
+
<string>x86_64</string>
|
|
19
20
|
</array>
|
|
20
21
|
<key>SupportedPlatform</key>
|
|
21
22
|
<string>ios</string>
|
|
23
|
+
<key>SupportedPlatformVariant</key>
|
|
24
|
+
<string>simulator</string>
|
|
22
25
|
</dict>
|
|
23
26
|
<dict>
|
|
24
27
|
<key>BinaryPath</key>
|
|
@@ -26,18 +29,15 @@
|
|
|
26
29
|
<key>HeadersPath</key>
|
|
27
30
|
<string>Headers</string>
|
|
28
31
|
<key>LibraryIdentifier</key>
|
|
29
|
-
<string>ios-
|
|
32
|
+
<string>ios-arm64</string>
|
|
30
33
|
<key>LibraryPath</key>
|
|
31
34
|
<string>libderec_library.a</string>
|
|
32
35
|
<key>SupportedArchitectures</key>
|
|
33
36
|
<array>
|
|
34
37
|
<string>arm64</string>
|
|
35
|
-
<string>x86_64</string>
|
|
36
38
|
</array>
|
|
37
39
|
<key>SupportedPlatform</key>
|
|
38
40
|
<string>ios</string>
|
|
39
|
-
<key>SupportedPlatformVariant</key>
|
|
40
|
-
<string>simulator</string>
|
|
41
41
|
</dict>
|
|
42
42
|
</array>
|
|
43
43
|
<key>CFBundlePackageType</key>
|
|
@@ -42,14 +42,15 @@
|
|
|
42
42
|
* fields this build cannot see and writing the truncated result back.
|
|
43
43
|
*
|
|
44
44
|
* The value tracks the release that last changed the shape, not the release
|
|
45
|
-
* that is current: it moved to 3 when `transport` became `transports`,
|
|
46
|
-
*
|
|
45
|
+
* that is current: it moved to 3 when `transport` became `transports`, to 4
|
|
46
|
+
* when [`ReplicaMember::handover_channel`] was added, and stays there until
|
|
47
|
+
* the next shape change.
|
|
47
48
|
*
|
|
48
49
|
* Declared unconditionally, unlike the serde impls that stamp it: the SDK
|
|
49
50
|
* bridges mirror this number in their own encoders, and a constant they must
|
|
50
51
|
* agree with should not appear and disappear with a feature flag.
|
|
51
52
|
*/
|
|
52
|
-
#define CHANNEL_RECORD_SCHEMA_VERSION
|
|
53
|
+
#define CHANNEL_RECORD_SCHEMA_VERSION 4
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
56
|
* Latest encoding major version, used for all new encodes. Bump only on a
|
|
@@ -106,6 +107,8 @@
|
|
|
106
107
|
|
|
107
108
|
#define DEREC_CATEGORY_STATE_STORE 15
|
|
108
109
|
|
|
110
|
+
#define DEREC_CATEGORY_TRANSPORT 16
|
|
111
|
+
|
|
109
112
|
#define DEREC_CODE_OK 0
|
|
110
113
|
|
|
111
114
|
#define DEREC_CODE_NON_OK_STATUS 1
|
|
@@ -246,6 +249,14 @@
|
|
|
246
249
|
*/
|
|
247
250
|
#define DEREC_CODE_FINGERPRINT_COMMITMENT_MISMATCH 48
|
|
248
251
|
|
|
252
|
+
/**
|
|
253
|
+
* The pairing outlived `Timeouts::pairing`: the scanner refuses a contact
|
|
254
|
+
* older than it, and the contact's creator refuses to accept a request
|
|
255
|
+
* that arrives after it. Surfaced as [`DEREC_CATEGORY_PAIRING`]; nothing is
|
|
256
|
+
* sent to the peer, and a fresh contact starts a new pairing.
|
|
257
|
+
*/
|
|
258
|
+
#define DEREC_CODE_PAIRING_EXPIRED 49
|
|
259
|
+
|
|
249
260
|
#define DEREC_CODE_EMPTY_CHANNELS 60
|
|
250
261
|
|
|
251
262
|
#define DEREC_CODE_DUPLICATE_CHANNEL_ID 61
|
|
@@ -312,6 +323,13 @@
|
|
|
312
323
|
*/
|
|
313
324
|
#define DEREC_CODE_NO_USABLE_ENDPOINT 121
|
|
314
325
|
|
|
326
|
+
/**
|
|
327
|
+
* The application's transport delivered a message to none of the peer's
|
|
328
|
+
* endpoints: the `send` callback returned non-zero.
|
|
329
|
+
* `DEREC_CATEGORY_TRANSPORT`.
|
|
330
|
+
*/
|
|
331
|
+
#define DEREC_CODE_TRANSPORT_SEND_FAILED 123
|
|
332
|
+
|
|
315
333
|
/**
|
|
316
334
|
* Return codes for [`crate::interop::ffi::protocol::stores::ShareStoreCallbacks::save`]
|
|
317
335
|
* and `ShareStoreCallbacks::record_verification`: `0` is success, each of
|
|
@@ -494,6 +512,14 @@ typedef struct DeRecError {
|
|
|
494
512
|
* Valid when `code == DEREC_CODE_VERSION_MISMATCH`.
|
|
495
513
|
*/
|
|
496
514
|
uint32_t got;
|
|
515
|
+
/**
|
|
516
|
+
* Whether `channel_id` is set: the error names the channel it is about.
|
|
517
|
+
*/
|
|
518
|
+
bool has_channel_id;
|
|
519
|
+
/**
|
|
520
|
+
* The channel the error is about. Valid when `has_channel_id`.
|
|
521
|
+
*/
|
|
522
|
+
uint64_t channel_id;
|
|
497
523
|
} DeRecError;
|
|
498
524
|
|
|
499
525
|
typedef struct DeRecBuffer {
|
|
@@ -557,6 +583,14 @@ typedef struct ReadTraceIdResult {
|
|
|
557
583
|
uint64_t trace_id;
|
|
558
584
|
} ReadTraceIdResult;
|
|
559
585
|
|
|
586
|
+
typedef struct EncryptedPayloadResult {
|
|
587
|
+
struct DeRecError error;
|
|
588
|
+
/**
|
|
589
|
+
* The envelope's encrypted `message` field. Empty on error.
|
|
590
|
+
*/
|
|
591
|
+
struct DeRecBuffer payload;
|
|
592
|
+
} EncryptedPayloadResult;
|
|
593
|
+
|
|
560
594
|
/**
|
|
561
595
|
* Result of a message JSON codec call. `bytes` is UTF-8 JSON for
|
|
562
596
|
* [`derec_decode_message_json`] and protobuf wire bytes for
|
|
@@ -1429,6 +1463,20 @@ struct ApplyTraceIdResult apply_trace_id_to_envelope(const uint8_t *envelope_ptr
|
|
|
1429
1463
|
struct ReadTraceIdResult read_trace_id_from_envelope(const uint8_t *envelope_ptr,
|
|
1430
1464
|
size_t envelope_len);
|
|
1431
1465
|
|
|
1466
|
+
/**
|
|
1467
|
+
* Read the encrypted `message` field off an envelope, without the channel
|
|
1468
|
+
* key: the part of an envelope the application's duplicate detection can
|
|
1469
|
+
* key on.
|
|
1470
|
+
*
|
|
1471
|
+
* Mirrors [`crate::derec_message::encrypted_payload`].
|
|
1472
|
+
*
|
|
1473
|
+
* # Safety
|
|
1474
|
+
*
|
|
1475
|
+
* `envelope_ptr` must point to a readable byte range of length `envelope_len`.
|
|
1476
|
+
*/
|
|
1477
|
+
struct EncryptedPayloadResult encrypted_payload_from_envelope(const uint8_t *envelope_ptr,
|
|
1478
|
+
size_t envelope_len);
|
|
1479
|
+
|
|
1432
1480
|
/**
|
|
1433
1481
|
* Releases the owned strings carried by a [`DeRecError`]. After
|
|
1434
1482
|
* returning, `error.message` and `error.peer_memo` are both null —
|
|
@@ -1804,6 +1852,8 @@ struct ProcessPrePairResponseMessageResult process_pre_pair_response_message(con
|
|
|
1804
1852
|
* "inbound_message_secs": 300,
|
|
1805
1853
|
* "sharing_round_secs": 60,
|
|
1806
1854
|
* "unpair_ack_secs": 60,
|
|
1855
|
+
* "get_share_response_secs": 300,
|
|
1856
|
+
* "pairing_secs": 30,
|
|
1807
1857
|
* "expired_channels": { "enabled": true, "timeout_in_secs": 300 }
|
|
1808
1858
|
* },
|
|
1809
1859
|
* "unsafe_connection": false,
|
|
Binary file
|
|
@@ -42,14 +42,15 @@
|
|
|
42
42
|
* fields this build cannot see and writing the truncated result back.
|
|
43
43
|
*
|
|
44
44
|
* The value tracks the release that last changed the shape, not the release
|
|
45
|
-
* that is current: it moved to 3 when `transport` became `transports`,
|
|
46
|
-
*
|
|
45
|
+
* that is current: it moved to 3 when `transport` became `transports`, to 4
|
|
46
|
+
* when [`ReplicaMember::handover_channel`] was added, and stays there until
|
|
47
|
+
* the next shape change.
|
|
47
48
|
*
|
|
48
49
|
* Declared unconditionally, unlike the serde impls that stamp it: the SDK
|
|
49
50
|
* bridges mirror this number in their own encoders, and a constant they must
|
|
50
51
|
* agree with should not appear and disappear with a feature flag.
|
|
51
52
|
*/
|
|
52
|
-
#define CHANNEL_RECORD_SCHEMA_VERSION
|
|
53
|
+
#define CHANNEL_RECORD_SCHEMA_VERSION 4
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
56
|
* Latest encoding major version, used for all new encodes. Bump only on a
|
|
@@ -106,6 +107,8 @@
|
|
|
106
107
|
|
|
107
108
|
#define DEREC_CATEGORY_STATE_STORE 15
|
|
108
109
|
|
|
110
|
+
#define DEREC_CATEGORY_TRANSPORT 16
|
|
111
|
+
|
|
109
112
|
#define DEREC_CODE_OK 0
|
|
110
113
|
|
|
111
114
|
#define DEREC_CODE_NON_OK_STATUS 1
|
|
@@ -246,6 +249,14 @@
|
|
|
246
249
|
*/
|
|
247
250
|
#define DEREC_CODE_FINGERPRINT_COMMITMENT_MISMATCH 48
|
|
248
251
|
|
|
252
|
+
/**
|
|
253
|
+
* The pairing outlived `Timeouts::pairing`: the scanner refuses a contact
|
|
254
|
+
* older than it, and the contact's creator refuses to accept a request
|
|
255
|
+
* that arrives after it. Surfaced as [`DEREC_CATEGORY_PAIRING`]; nothing is
|
|
256
|
+
* sent to the peer, and a fresh contact starts a new pairing.
|
|
257
|
+
*/
|
|
258
|
+
#define DEREC_CODE_PAIRING_EXPIRED 49
|
|
259
|
+
|
|
249
260
|
#define DEREC_CODE_EMPTY_CHANNELS 60
|
|
250
261
|
|
|
251
262
|
#define DEREC_CODE_DUPLICATE_CHANNEL_ID 61
|
|
@@ -312,6 +323,13 @@
|
|
|
312
323
|
*/
|
|
313
324
|
#define DEREC_CODE_NO_USABLE_ENDPOINT 121
|
|
314
325
|
|
|
326
|
+
/**
|
|
327
|
+
* The application's transport delivered a message to none of the peer's
|
|
328
|
+
* endpoints: the `send` callback returned non-zero.
|
|
329
|
+
* `DEREC_CATEGORY_TRANSPORT`.
|
|
330
|
+
*/
|
|
331
|
+
#define DEREC_CODE_TRANSPORT_SEND_FAILED 123
|
|
332
|
+
|
|
315
333
|
/**
|
|
316
334
|
* Return codes for [`crate::interop::ffi::protocol::stores::ShareStoreCallbacks::save`]
|
|
317
335
|
* and `ShareStoreCallbacks::record_verification`: `0` is success, each of
|
|
@@ -494,6 +512,14 @@ typedef struct DeRecError {
|
|
|
494
512
|
* Valid when `code == DEREC_CODE_VERSION_MISMATCH`.
|
|
495
513
|
*/
|
|
496
514
|
uint32_t got;
|
|
515
|
+
/**
|
|
516
|
+
* Whether `channel_id` is set: the error names the channel it is about.
|
|
517
|
+
*/
|
|
518
|
+
bool has_channel_id;
|
|
519
|
+
/**
|
|
520
|
+
* The channel the error is about. Valid when `has_channel_id`.
|
|
521
|
+
*/
|
|
522
|
+
uint64_t channel_id;
|
|
497
523
|
} DeRecError;
|
|
498
524
|
|
|
499
525
|
typedef struct DeRecBuffer {
|
|
@@ -557,6 +583,14 @@ typedef struct ReadTraceIdResult {
|
|
|
557
583
|
uint64_t trace_id;
|
|
558
584
|
} ReadTraceIdResult;
|
|
559
585
|
|
|
586
|
+
typedef struct EncryptedPayloadResult {
|
|
587
|
+
struct DeRecError error;
|
|
588
|
+
/**
|
|
589
|
+
* The envelope's encrypted `message` field. Empty on error.
|
|
590
|
+
*/
|
|
591
|
+
struct DeRecBuffer payload;
|
|
592
|
+
} EncryptedPayloadResult;
|
|
593
|
+
|
|
560
594
|
/**
|
|
561
595
|
* Result of a message JSON codec call. `bytes` is UTF-8 JSON for
|
|
562
596
|
* [`derec_decode_message_json`] and protobuf wire bytes for
|
|
@@ -1429,6 +1463,20 @@ struct ApplyTraceIdResult apply_trace_id_to_envelope(const uint8_t *envelope_ptr
|
|
|
1429
1463
|
struct ReadTraceIdResult read_trace_id_from_envelope(const uint8_t *envelope_ptr,
|
|
1430
1464
|
size_t envelope_len);
|
|
1431
1465
|
|
|
1466
|
+
/**
|
|
1467
|
+
* Read the encrypted `message` field off an envelope, without the channel
|
|
1468
|
+
* key: the part of an envelope the application's duplicate detection can
|
|
1469
|
+
* key on.
|
|
1470
|
+
*
|
|
1471
|
+
* Mirrors [`crate::derec_message::encrypted_payload`].
|
|
1472
|
+
*
|
|
1473
|
+
* # Safety
|
|
1474
|
+
*
|
|
1475
|
+
* `envelope_ptr` must point to a readable byte range of length `envelope_len`.
|
|
1476
|
+
*/
|
|
1477
|
+
struct EncryptedPayloadResult encrypted_payload_from_envelope(const uint8_t *envelope_ptr,
|
|
1478
|
+
size_t envelope_len);
|
|
1479
|
+
|
|
1432
1480
|
/**
|
|
1433
1481
|
* Releases the owned strings carried by a [`DeRecError`]. After
|
|
1434
1482
|
* returning, `error.message` and `error.peer_memo` are both null —
|
|
@@ -1804,6 +1852,8 @@ struct ProcessPrePairResponseMessageResult process_pre_pair_response_message(con
|
|
|
1804
1852
|
* "inbound_message_secs": 300,
|
|
1805
1853
|
* "sharing_round_secs": 60,
|
|
1806
1854
|
* "unpair_ack_secs": 60,
|
|
1855
|
+
* "get_share_response_secs": 300,
|
|
1856
|
+
* "pairing_secs": 30,
|
|
1807
1857
|
* "expired_channels": { "enabled": true, "timeout_in_secs": 300 }
|
|
1808
1858
|
* },
|
|
1809
1859
|
* "unsafe_connection": false,
|
|
@@ -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: 43864016 bytes
|
|
4
|
+
sha256: e030b8f985557aab348f556650070ced884b76c0ac66f701f338d09ce561055e
|
package/lib/errors.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type { DeRecEvent } from './types';
|
|
|
11
11
|
* The nodejs union is arguably wrong on its own terms too, but correcting it
|
|
12
12
|
* is a change to that package, not this one.
|
|
13
13
|
*/
|
|
14
|
-
export declare const DEREC_ERROR_CATEGORIES: readonly ["ok", "ffi", "pairing", "sharing", "recovery", "verification", "discovery", "unpairing", "derec_message", "secret_store", "channel_store", "share_store", "input", "protobuf", "invariant", "state_store"];
|
|
14
|
+
export declare const DEREC_ERROR_CATEGORIES: readonly ["ok", "ffi", "pairing", "sharing", "recovery", "verification", "discovery", "unpairing", "derec_message", "secret_store", "channel_store", "share_store", "input", "protobuf", "invariant", "state_store", "transport"];
|
|
15
15
|
export type DeRecErrorCategory = (typeof DEREC_ERROR_CATEGORIES)[number];
|
|
16
16
|
/**
|
|
17
17
|
* Every code `derec_error_code_name` can return, and no others.
|
|
@@ -21,7 +21,7 @@ export type DeRecErrorCategory = (typeof DEREC_ERROR_CATEGORIES)[number];
|
|
|
21
21
|
* own before a value reaches the library, so this list is exactly the Rust
|
|
22
22
|
* `Code` table in `library/src/interop/error_codes.rs`.
|
|
23
23
|
*/
|
|
24
|
-
export declare const DEREC_ERROR_CODES: readonly ["ok", "non_ok_status", "version_mismatch", "invariant", "invalid_input", "protobuf_decode", "protobuf_encode", "protocol_violation", "store_error", "builder_error", "missing_shared_key", "role_mismatch", "replica_id_not_configured", "channel_already_paired", "already_restored", "restore_conflict", "replica_id_conflict", "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"];
|
|
24
|
+
export declare const DEREC_ERROR_CODES: readonly ["ok", "non_ok_status", "version_mismatch", "invariant", "invalid_input", "protobuf_decode", "protobuf_encode", "protocol_violation", "store_error", "builder_error", "missing_shared_key", "role_mismatch", "replica_id_not_configured", "channel_already_paired", "already_restored", "restore_conflict", "replica_id_conflict", "fingerprint_mismatch", "encryption", "keygen", "finish_pairing_initiator", "finish_pairing_responder", "empty_transport_uri", "invalid_contact_message", "invalid_pair_request_message", "invalid_pair_response_message", "prepair_hash_mismatch", "missing_replica_id", "unexpected_replica_id", "incompatible_parameter_range", "fingerprint_commitment_mismatch", "pairing_expired", "empty_channels", "duplicate_channel_id", "invalid_threshold", "empty_secret_data", "vss_share_failed", "invalid_weight", "too_many_subshares", "invalid_keep_version", "empty_responses", "empty_committed_derec_share", "decode_committed_derec_share", "decode_derec_share", "secret_id_mismatch", "reconstruction_failed", "malformed_recovered_secret", "ffi_null_ptr", "ffi_bad_length", "ffi_bad_utf8", "ffi_bad_proto", "ffi_invalid_enum", "ffi_bad_shared_key", "ffi_nul_in_string", "transport_invalid", "no_usable_endpoint", "transport_send_failed"];
|
|
25
25
|
export type DeRecErrorCode = (typeof DEREC_ERROR_CODES)[number];
|
|
26
26
|
export interface DeRecError {
|
|
27
27
|
category: DeRecErrorCategory;
|
|
@@ -38,7 +38,12 @@ export interface DeRecError {
|
|
|
38
38
|
* Clear exactly these and retry `restore`.
|
|
39
39
|
*/
|
|
40
40
|
channel_ids?: string[];
|
|
41
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* The channel the error is about: the one named by
|
|
43
|
+
* `"channel_already_paired"`, `"fingerprint_mismatch"` and
|
|
44
|
+
* `"role_mismatch"`, or, on a failed `process()`, the channel the failing
|
|
45
|
+
* inbound message arrived on.
|
|
46
|
+
*/
|
|
42
47
|
channel_id?: string;
|
|
43
48
|
/**
|
|
44
49
|
* On a failed `process()`: the events it produced before failing, such as
|