chat: send and receive as ratchet frames through the outbox payload
All checks were successful
ci / test (pull_request) Successful in 4m36s
ci / sdk (pull_request) Successful in 1m15s
android-ci / android (pull_request) Successful in 9m25s

Chat plaintext is ratchet-encrypted once, before the first delivery attempt,
and the frame is what the outbox stores and retries, so a retried message
re-sends identical bytes instead of advancing the sending chain twice.

- dispatch: Kind::Ratchet for the `rat ` prefix, matched before the unknown
  [a-z]{3} prefix rule
- node: encode_chat_frame / ingest_chat_frame (the wire halves of Node::send
  and handle_incoming), bootstrap derived from the peers' static prekey DH
  because the Noise handshake is frozen and carries no ratchet key
- outbox: nullable outbox.payload + Outbox::send_payload; NULL payload keeps
  the previous row-for-row behaviour
- store: additive outbox.payload migration, enqueue_outbox_payload,
  OutboxEntry::payload
- add_friend_payload: a changed prekey clears the (prekey-bound) ratchet state

tests/ratchet_wire.rs (5) covers one frame per send, byte-identical retries,
out-of-order delivery, replay, tampering and fresh-friend both directions.

tests/tui_spec.rs and crates/onionwire-sdk/src/lib.rs only gained a
`payload: None` field in their OutboxEntry test fixtures: the card's required
field on a pub struct cannot be added without it.
This commit is contained in:
agent 2026-09-16 19:02:52 -04:00
commit 69a15fe909
No known key found for this signature in database
9 changed files with 619 additions and 13 deletions

View file

@ -32,6 +32,20 @@ fn known_prefixes_are_typed() {
assert_eq!(classify(b"png 1"), Kind::Ping);
}
#[test]
fn ratchet_frame_is_ratchet() {
// `rat ` is a typed prefix, not chat: the plaintext is a ratchet frame.
assert_eq!(classify(b"rat \x01rest-of-frame"), Kind::Ratchet);
// Matched before the unknown-lowercase-prefix rule, which would Drop it.
assert_eq!(classify(b"rat x"), Kind::Ratchet);
}
#[test]
fn unknown_lowercase_prefix_still_drops() {
assert_eq!(classify(b"rax not a real type"), Kind::Drop);
assert_eq!(classify(b"rat"), Kind::Chat, "3 letters is not a prefix");
}
#[test]
fn uppercase_or_digit_prefix_is_chat() {
assert_eq!(classify(b"ZZZ not typed"), Kind::Chat);