feat: desktop messaging + pairing + cross-client master-pub attribution (v2.2.0-alpha5)
Two coordinated changes:
1. Desktop client gets a functional Messages section and working pairing
flow, putting it at feature parity with mobile for the v2.2.0 line.
2. Server + both clients teach each other to use the sender's master
Ed25519 (not just their X25519) to address conversations, so a peer
writing from a different linked device still rolls into the same chat.
This is the "new API logic" the desktop scaffold was waiting on.
Server (node/api_relay.go, cmd/node/main.go):
* /relay/inbox items now carry `sender_ed25519_pub` alongside the
per-device `sender_pub`. Empty string for pre-v2.2.0 senders.
* WS `inbox` push summary also includes `sender_ed25519_pub`, so the
client can skip the refetch when the envelope plainly isn't for
the chat they're watching.
* Both existing tests pass.
Mobile client:
* lib/types.ts Envelope grew `sender_ed25519_pub`; fetchInbox normalises
it (default '') for older nodes.
* hooks/useGlobalInbox matches contacts by (master Ed25519 OR legacy
X25519) so an incoming message from a peer's desktop reuses the
existing chat instead of creating a duplicate placeholder.
* hooks/useMessages now takes an optional `contactMasterEd25519` and
exposes a matchesChat() predicate; WS inbox handler uses it too to
avoid spurious refetches.
* chats/[id].tsx passes `contact.address` (master) along with x25519.
Desktop client — all new:
* src/lib/crypto.ts — tweetnacl hex/base64 helpers, generateKeyFile,
encryptMessage/decryptMessage, signBase64, shortAddr. Same signatures
as the mobile lib; uses Chromium's window.crypto, no expo-crypto dep.
* src/lib/tx.ts — buildTransferTx / buildLinkDeviceTx / buildUnlinkDeviceTx
+ submitTx + humanizeTxError, canonical-bytes identical to mobile.
* src/lib/relay.ts — fetchInbox, sendEnvelope, resolveRecipientKeys
(multi-device fan-out with legacy identity.x25519 fallback).
* src/lib/store.ts — zustand state gets messages{}, unread{},
activeChat.
* src/lib/storage.ts — per-chat cache via localStorage (500-msg cap).
* src/hooks/useInboxPoll — 4s polling loop, addresses conversations
by master Ed25519, bumps unread unless chat is active.
* src/sections/messages/* — ChatList (sorted tiles, unread badges),
Conversation (auto-scroll messages + composer + fan-out send,
Enter-to-send / Shift+Enter for newline), EmptyConversation.
* src/auth/Pair.tsx — 6-digit code + device key screen, polls inbox
for a handshake envelope, assembles the KeyFile on arrival.
* Welcome.tsx: Pair button now actually routes to <Pair>; imports
generateKeyFile from lib/crypto (was inlined).
docs/ROADMAP.md delta: alpha5 row flipped to done inline. Alpha6
(feed + wallet) and rc1 (contacts + devices UI + profile) still
pending.
This commit is contained in:
@@ -262,14 +262,17 @@ export async function getTxHistory(pubkey: string, limit = 50): Promise<TxRecord
|
||||
* совместимости с crypto.ts (decryptMessage принимает hex).
|
||||
*/
|
||||
interface InboxItemWire {
|
||||
id: string;
|
||||
sender_pub: string;
|
||||
recipient_pub: string;
|
||||
fee_ut?: number;
|
||||
sent_at: number;
|
||||
sent_at_human?: string;
|
||||
nonce: string; // base64
|
||||
ciphertext: string; // base64
|
||||
id: string;
|
||||
sender_pub: string;
|
||||
/** sender_ed25519_pub was added in v2.2.0; older nodes omit it.
|
||||
Default to empty string when missing. */
|
||||
sender_ed25519_pub?: string;
|
||||
recipient_pub: string;
|
||||
fee_ut?: number;
|
||||
sent_at: number;
|
||||
sent_at_human?: string;
|
||||
nonce: string; // base64
|
||||
ciphertext: string; // base64
|
||||
}
|
||||
|
||||
interface InboxResponseWire {
|
||||
@@ -326,12 +329,13 @@ export async function fetchInbox(x25519PubHex: string): Promise<Envelope[]> {
|
||||
const resp = await get<InboxResponseWire>(`/relay/inbox?pub=${x25519PubHex}`);
|
||||
const items = Array.isArray(resp?.items) ? resp.items : [];
|
||||
return items.map((it): Envelope => ({
|
||||
id: it.id,
|
||||
sender_pub: it.sender_pub,
|
||||
recipient_pub: it.recipient_pub,
|
||||
nonce: bytesToHex(base64ToBytes(it.nonce)),
|
||||
ciphertext: bytesToHex(base64ToBytes(it.ciphertext)),
|
||||
timestamp: it.sent_at ?? 0,
|
||||
id: it.id,
|
||||
sender_pub: it.sender_pub,
|
||||
sender_ed25519_pub: it.sender_ed25519_pub ?? '',
|
||||
recipient_pub: it.recipient_pub,
|
||||
nonce: bytesToHex(base64ToBytes(it.nonce)),
|
||||
ciphertext: bytesToHex(base64ToBytes(it.ciphertext)),
|
||||
timestamp: it.sent_at ?? 0,
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,19 @@ export interface Contact {
|
||||
export interface Envelope {
|
||||
/** sha256(nonce||ciphertext)[:16] hex — stable server-assigned id. */
|
||||
id: string;
|
||||
sender_pub: string; // X25519 hex
|
||||
sender_pub: string; // X25519 hex (this envelope's per-device sender key)
|
||||
/**
|
||||
* sender_ed25519_pub (v2.2.0+): the sender's master Ed25519 identity.
|
||||
* Multiple X25519 pubs under the same identity all share one master —
|
||||
* clients use THIS to group messages into a single conversation even
|
||||
* when the sender replies from different devices.
|
||||
*
|
||||
* Empty string on legacy envelopes from pre-v2.2.0 senders. Consumers
|
||||
* should fall back to `sender_pub` in that case (keeps old clients'
|
||||
* messages visible, even if attribution is per-X25519 rather than
|
||||
* per-identity).
|
||||
*/
|
||||
sender_ed25519_pub: string;
|
||||
recipient_pub: string; // X25519 hex
|
||||
nonce: string; // hex 24 bytes
|
||||
ciphertext: string; // hex NaCl box
|
||||
|
||||
Reference in New Issue
Block a user