@ours.network/tg-connector 0.1.2 → 0.1.3

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 (30) hide show
  1. package/dist/mufl_code/2DA1D5F860E42C605D92F1E24E2466C70EFDDBF057BBCBA52F0ECC639EFCA387.muflo +0 -0
  2. package/dist/mufl_code/core/CLUSTER_API.md +640 -0
  3. package/dist/mufl_code/core/CLUSTER_CONTRACT.md +121 -0
  4. package/dist/mufl_code/core/CLUSTER_INTRODUCTION_PLAN.md +200 -0
  5. package/dist/mufl_code/core/CONFIGURATION_DESIGN.md +35 -0
  6. package/dist/mufl_code/core/CONFIGURATION_PLAN.md +394 -0
  7. package/dist/mufl_code/core/DEVELOPMENT.md +168 -0
  8. package/dist/mufl_code/core/EPHEMERAL_INVITE_PLAN.md +465 -0
  9. package/dist/mufl_code/core/GROUP_CHAT_DESIGN.md +520 -0
  10. package/dist/mufl_code/core/LICENSE +98 -0
  11. package/dist/mufl_code/core/README.md +76 -0
  12. package/dist/mufl_code/core/a2a_capabilities.mm +350 -0
  13. package/dist/mufl_code/core/a2a_cluster.mm +601 -0
  14. package/dist/mufl_code/core/a2a_control.mm +89 -0
  15. package/dist/mufl_code/core/a2a_messaging.mm +2103 -0
  16. package/dist/mufl_code/core/a2a_monitoring.mm +94 -0
  17. package/dist/mufl_code/core/a2a_protocol.mm +231 -0
  18. package/dist/mufl_code/core/config.mufl +26 -0
  19. package/dist/mufl_code/core/release-notes/2.0.md +268 -0
  20. package/dist/mufl_code/core/release-notes/2.1.md +92 -0
  21. package/dist/mufl_code/core/release-notes/2.2.md +94 -0
  22. package/dist/mufl_code/core/release-notes/3.0.md +162 -0
  23. package/dist/mufl_code/core/release-notes/3.1.md +43 -0
  24. package/dist/mufl_code/core/release-notes/README.md +32 -0
  25. package/dist/mufl_code/core/tests/README.md +66 -0
  26. package/dist/mufl_code/core/tests/run.sh +67 -0
  27. package/dist/mufl_code/core/tests/test.mjs +467 -0
  28. package/dist/mufl_code/core/tests/test_actor.mu +287 -0
  29. package/dist/mufl_code/core/version.mm +24 -0
  30. package/package.json +2 -1
@@ -0,0 +1,465 @@
1
+ # Ephemeral-Key Slim Invite — Implementation Plan (core 3.0)
2
+
3
+ > **Replace the fat, identity-bearing invite with a slim one carrying only an
4
+ > ephemeral encryption pubkey + the inviter's container_id + a name. Both parties'
5
+ > address documents (and, for roles, the delegation chain) are exchanged over a
6
+ > two-message encrypted hop instead of riding in the invite.** Dramatically smaller
7
+ > invites; the root cert / root profile never appear in the invite. This plan covers
8
+ > ONLY the shared mufl core change. Daemon / consumer / messenger integration and
9
+ > release-note prose are later phases.
10
+
11
+ **Status:** DESIGN — approved in shape by user 2026-06-20. Do **not** implement yet.
12
+
13
+ ---
14
+
15
+ ## 0. Decisions locked by the user (2026-06-20)
16
+
17
+ 1. **Address in the invite = the inviter's `container_id`.** It is *not* key-derived
18
+ today; key-derivation is planned later. We use `container_id` as-is now. The
19
+ strength of the receiver's identity pin tracks that future work — this redesign
20
+ neither improves nor regresses it (today's `add_contact`/`accept_contact` already
21
+ pin on `container_id` the same way; see §6).
22
+ 2. **Do NOT touch `encrypted_channel` (stdlib).** The eph keypair is generated in
23
+ `a2a_messaging` with the raw `_crypto_*` primitives. The peer's AD is delivered
24
+ one-shot, boxed to the eph key. Once the inviter runs `process_address_document`
25
+ on the responder's AD, the responder is registered, so the reply (leg 3) and all
26
+ future traffic ride the **existing** `encrypted_channel` unchanged.
27
+ 3. **The inviter stores per-invite state anyway** (it already tracks `pending_invites`),
28
+ so persisting the eph private key per outstanding invite is acceptable — with the
29
+ secrecy guardrail in §4 (eph privkeys live in a **non-exported** state field).
30
+
31
+ ---
32
+
33
+ ## 0b. CORRECTION — leg-3 mechanism (empirical, during M2, 2026-06-20)
34
+
35
+ **The M0 spike's leg-3 conclusion is REVERSED.** `encrypted_channel` is NOT viable for leg-3:
36
+ `send_encrypted_tx` from the inviter to the responder fails RECEIVER-SIDE with
37
+ `"Unknown source key for message decryption"` (`key_storage.mm:291`) — the transport decrypt looks
38
+ up the SENDER (inviter) key by id, but the responder has not registered the inviter yet (it learns
39
+ the inviter only inside leg-3's payload). M0 Q1 validated only the inviter-side `is_container_registered`
40
+ gate, never the responder decrypting; the `"Unknown source key"` rejection the spike logged on node B
41
+ and dismissed as benign WAS the signal.
42
+
43
+ **Leg-3 is now BOXED (symmetric to leg-1)** — the only mechanism viable with the available primitives:
44
+ - The responder KEEPS its leg-1 ephemeral PRIVATE key in a NEW hidden, non-exported store
45
+ `pending_redemption_keys` (same INV-4 treatment as `pending_invite_keys`).
46
+ - Leg-2 sends leg-3 as a BARE boxed send: a FRESH inviter ephemeral; box `{inviter_ad, cert?,
47
+ root_profile?, cp_binding?}` to the RESPONDER's eph pub (the `$epk` carried in leg-1); ship the
48
+ fresh inviter eph pub in cleartext.
49
+ - The leg-3 handler DROPS `check_encrypted_or_abort` and decrypts with the kept responder eph priv +
50
+ the inviter eph pub from the envelope. All gates unchanged (pend lookup → inviter-cid pin →
51
+ cid-bind → `process_address_document` PoP → chain; INV-5 preserved).
52
+ - The earlier §5.3 fallback ("box to the responder's REAL key") is ALSO wrong — the stdlib never
53
+ exposes a raw long-term encryption privkey (§2 fact 3), so leg-3 must box to the EPH key.
54
+
55
+ **Consequences:** restart-transience now covers BOTH eph stores (`pending_invite_keys` AND
56
+ `pending_redemption_keys`), both excluded from `export_core_state`. `encrypted_channel` is unchanged
57
+ and resumes for ALL post-contact `send_message` traffic (after leg-3 both sides have registered each
58
+ other via `process_address_document`). **Supersedes the leg-3 mechanism in §2, §5.3, §5.4 below.**
59
+
60
+ ---
61
+
62
+ ## 1. What exists today (core 2.17 — being replaced)
63
+
64
+ - **Fat invite shapes** (`a2a_protocol.mm`):
65
+ - `invite_t` (L27): `invite_id`, `name`, `container_id`, **full public key list**, **self-signatures**.
66
+ - `invite_role_t` (L75): all of the above **plus** `delegation_cert`, **`root_profile`**
67
+ (which embeds *the root's entire key list* + name + bio, L48), plus optional `root_cp_binding`.
68
+ The root key list is the heavy part — exactly the bulk this change removes.
69
+ - **Mint** (`a2a_messaging.mm`): `mint_invite` (L467) builds the blob and registers
70
+ `pending_invites[invite_id] = assigned_name`; shared by `generate_invite` (L503) and the
71
+ cluster child-invite path (a2a_cluster relays the blob **opaquely** — it never parses it).
72
+ - **Redeem** (`add_contact`, L520): rebuilds the inviter AD from the carried keys
73
+ (`rebuild_peer_address_document`), verifies self-sigs + delegation chain **offline from
74
+ the invite**, stores `peer_ads`, then rides `encrypted_channel::execute_transaction` (L606)
75
+ — a full ECDH handshake (≈3 legs) — to deliver `accept_contact`.
76
+ - **Accept** (`handle_accept_contact`, L1169): cid-binds the joiner AD to the channel sender
77
+ (`joiner_ad.container_id == sender_id`), runs `process_address_document(ad, TRUE)` (PoP
78
+ self-sig enforcement — the linchpin), verifies the joiner's chain, registers, consumes the
79
+ invite (`delete pending_invites`).
80
+ - **State**: `pending_invites is (global_id ->> str)` (L75), **exported** in
81
+ `export_core_state` and imported `safe (global_id ->> str)`.
82
+
83
+ Net today: invite is a *standing identity-disclosure token* (anyone who sees it gets the
84
+ inviter's keys, and for roles the whole root profile + org chain), and redemption costs
85
+ ≈4 wire messages (ECDH handshake + accept).
86
+
87
+ ---
88
+
89
+ ## 2. Target flow (slim invite + 2-message exchange)
90
+
91
+ Roles: **Inviter** = generates the invite. **Responder** = redeems it.
92
+
93
+ ```
94
+ (OOB) Inviter ──► Responder : slim invite { invite_id, inviter_cid, inviter_name,
95
+ eph_pub_inviter, scheme }
96
+
97
+ leg 1 Responder ──► Inviter : submit_invite_response (BARE send, NOT encrypted transport)
98
+ { invite_id, eph_pub_responder, scheme,
99
+ data = box(eph_priv_responder, eph_pub_inviter,
100
+ _write{ responder_AD, cert?, root_profile?, cp_binding?, invite_id }) }
101
+
102
+ leg 3 Inviter ──► Responder : complete_invite (via encrypted_channel — responder now registered)
103
+ { invite_id, inviter_AD, cert?, root_profile?, cp_binding? }
104
+ ```
105
+
106
+ After leg 3, **both** sides hold the other's verified AD + contact + (optional) root linkage,
107
+ symmetric to today's end state. Subsequent `send_message` uses `encrypted_channel` normally.
108
+
109
+ **Wire cost: 1 OOB + 2 on-wire messages** — fewer than today's ≈4. The "extra step" the user
110
+ described is conceptual (the inviter must now actively send its AD back); on the wire this is
111
+ *cheaper*, not more expensive.
112
+
113
+ **Why a responder eph keypair is MANDATORY (not a design choice) — three facts stack:**
114
+ 1. At leg 1 the responder does NOT hold the inviter's AD / default encryption key — the slim
115
+ invite carries only an *ephemeral* pubkey (the whole size saving). So "encrypt with the
116
+ counterparty's AD default key" is unavailable here; the inviter's real key arrives on leg 3.
117
+ 2. The only primitive is a **two-key ECDH box** — `_crypto_encrypt_message(my_priv, their_pub, msg)`;
118
+ to open it the inviter computes `box(eph_priv_inviter, responder_pub)`, so the responder's
119
+ matching pubkey MUST travel in cleartext beside the ciphertext (the `authorize_packet` idiom,
120
+ `encrypted_channel.mm:118-124`).
121
+ 3. The responder cannot use its OWN long-term encryption key for that box: `_crypto_encrypt_message`
122
+ needs a **raw private key**, and the stdlib never exposes your long-term encryption privkey as a
123
+ raw value. `key_storage::default_encrypt` (`key_storage.mm:273`) keeps it internal AND only
124
+ targets an *already-registered* recipient container (`:276` aborts otherwise) — it cannot encrypt
125
+ to a bare ephemeral pubkey. The only raw privkey `a2a_messaging` can obtain is from
126
+ `_crypto_construct_encryption_keypair` → a fresh ephemeral.
127
+
128
+ So the responder generates one fresh ephemeral keypair, ships `eph_pub_responder` in cleartext, and
129
+ discards it after the hop. Bonus: forward secrecy for the leg-1 "who is connecting" metadata.
130
+ **Everything from leg 3 onward is the unchanged current scheme** (inviter has the responder
131
+ registered → replies with its AD over `encrypted_channel` → responder `process_address_document`s
132
+ it). The only inherent change vs today: **disclosure order flips — the responder discloses first**
133
+ (to flip it, the inviter would have to encrypt to the responder before knowing any responder key,
134
+ which is impossible; moving the bulk off the OOB channel forces recipient-first).
135
+
136
+ ---
137
+
138
+ ## 3. Wire shapes (`a2a_protocol.mm`)
139
+
140
+ ```
141
+ // Slim invite. Carries ONLY an ephemeral encryption pubkey, the inviter's
142
+ // routing/identity cid, a display name, and the crypto scheme id. No identity
143
+ // keys, no self-sigs, no cert, no root profile — those move to the encrypted hop.
144
+ metadef invite_eph_t: (
145
+ $d -> global_id, // invite_id (correlates leg-1 to the stored eph privkey; single-use)
146
+ $c -> global_id, // inviter container_id (routing target + identity pin)
147
+ $n -> str, // inviter display name (metadata only)
148
+ $k -> publickey_encrypt, // eph_pub_inviter
149
+ $v -> int // crypto scheme id (_crypto_default_scheme_id at mint time)
150
+ ).
151
+ ```
152
+
153
+ Leg-1 and leg-3 transaction payloads are passed as `any` (like `accept_contact` today) for
154
+ forward-compat; documented inner shapes:
155
+
156
+ ```
157
+ // Cleartext envelope of leg 1 (the AD etc. live inside `data`, boxed).
158
+ // { $invite_id -> global_id, $epk -> publickey_encrypt /*responder eph pub*/,
159
+ // $v -> int /*scheme*/, $data -> crypto_message }
160
+ // Decrypted `data` payload (and the leg-3 cleartext payload) share this identity bundle:
161
+ // { $ad -> t_address_document, $cert -> bin+, $root_profile -> bin+,
162
+ // $cp_binding -> bin+, $invite_id -> global_id }
163
+ ```
164
+
165
+ Legacy `invite_t` / `invite_role_t` and `rebuild_peer_address_document`: see §7 (versioning).
166
+
167
+ ---
168
+
169
+ ## 4. State changes (`a2a_messaging.mm`)
170
+
171
+ 1. **`pending_invites` gains structure.** From `(global_id ->> str)` to a record map:
172
+ ```
173
+ metadef pending_invite_t: ($assigned -> str, $eph_pub -> publickey_encrypt, $scheme -> int).
174
+ pending_invites is (global_id ->> pending_invite_t) = (,).
175
+ ```
176
+ (Keep `$assigned` = the existing empty-string "no assigned name" sentinel.)
177
+
178
+ 2. **NEW non-exported secret store** for eph private keys:
179
+ ```
180
+ hidden { pending_invite_keys is (global_id ->> secretkey_encrypt) = (,). } // invite_id -> eph_priv
181
+ ```
182
+ **Excluded from `export_core_state`** so the export blob never carries secrets. Consequence:
183
+ invites outstanding at export time become unredeemable after import — acceptable (invites are
184
+ transient). Document this in the 3.0 note. (`pending_invite_keys` is also where single-use
185
+ consumption deletes the secret.)
186
+
187
+ 3. **NEW responder-side pending-redemption store** (no secrets):
188
+ ```
189
+ metadef pending_redemption_t: ($inviter_cid -> global_id, $custom_name -> str).
190
+ pending_redemptions is (global_id ->> pending_redemption_t) = (,). // invite_id -> who I'm redeeming
191
+ ```
192
+ Needed so leg-3 (`complete_invite`) knows the chosen contact name + expected inviter cid.
193
+ May be omitted from export (transient) or exported (no secrets) — pick in §10.
194
+
195
+ 4. **`import_core_state` migration.** Old blobs have `pending_invites : (global_id ->> str)`.
196
+ On import, if the value matches the old str-map shape, drop it (or wrap each into a
197
+ `pending_invite_t` with NIL eph material → unredeemable, same outcome). Simplest: treat
198
+ `pending_invites` as optional and reset to empty on a shape mismatch. New stores default empty.
199
+
200
+ ---
201
+
202
+ ## 5. Transaction-by-transaction spec (`a2a_messaging.mm`)
203
+
204
+ New tx-name consts (mirror L42-43):
205
+ ```
206
+ submit_invite_response_tx = "::actor::submit_invite_response".
207
+ complete_invite_tx = "::actor::complete_invite".
208
+ ```
209
+
210
+ ### 5.1 `mint_invite` → `mint_eph_invite (assigned: str)` (replaces L467)
211
+ - `scheme = _crypto_default_scheme_id()`.
212
+ - `kp = _crypto_construct_encryption_keypair scheme`.
213
+ - `invite_id = _new_id "ours invite"`.
214
+ - `pending_invites invite_id -> ($assigned -> assigned, $eph_pub -> kp $public_key, $scheme -> scheme)`.
215
+ - `pending_invite_keys invite_id -> kp $secret_key`. *(secret store)*
216
+ - `my_ad = get_my_address_document()`.
217
+ - Build `invite_eph_t = ($d -> invite_id, $c -> (my_ad $identity $container_id), $n -> my_name, $k -> kp $public_key, $v -> scheme)`.
218
+ - Return `($blob -> _write invite_eph_t, $invite_id -> invite_id)`. **Caller emits `_save_state`.**
219
+ - No role branch — roles emit the same slim shape (the cert/root_profile move to leg 3).
220
+
221
+ `generate_invite` (L503) unchanged in signature; just calls `mint_eph_invite`. The cluster
222
+ child-invite path is unaffected (it relays the opaque blob).
223
+
224
+ ### 5.2 `add_contact` → responder leg 1 (rework L520)
225
+ Keep the trn name `add_contact` (or rename to `redeem_invite`; decide in §10). Body:
226
+ - `validate_origin_or_abort(user)`.
227
+ - Parse `invite_eph_t`: `invite_id`, `inviter_cid`, `inviter_name`, `eph_pub_inviter`, `scheme`.
228
+ - `abort "This invite is your own." when inviter_cid == _get_container_id()`.
229
+ - `kpr = _crypto_construct_encryption_keypair scheme` (responder ephemeral).
230
+ - Assemble identity bundle:
231
+ ```
232
+ cert_blob, rp_blob, rpb_blob = (my role material, as today's add_contact L570-578)
233
+ payload = _write ($ad -> my_ad, $cert -> cert_blob, $root_profile -> rp_blob,
234
+ $cp_binding -> rpb_blob, $invite_id -> invite_id).
235
+ data = _crypto_encrypt_message (kpr $secret_key) eph_pub_inviter payload.
236
+ ```
237
+ - `contact_name = (custom_name == NIL ?? "" ; custom_name?)`; store
238
+ `pending_redemptions invite_id -> ($inviter_cid -> inviter_cid, $custom_name -> contact_name)`.
239
+ - Emit a **bare** send (NOT `send_encrypted_tx` — the inviter is not yet registered; raw
240
+ `transaction::action::send` to an unregistered target is the established pattern, cf.
241
+ `encrypted_channel.mm:73`):
242
+ ```
243
+ transaction::action::send inviter_cid
244
+ ($name -> submit_invite_response_tx,
245
+ $targ -> ($invite_id -> invite_id, $epk -> (kpr $public_key), $v -> scheme, $data -> data))
246
+ ```
247
+ - `_return_data` (pending status — the contact is not final until leg 3) + `_save_state NIL`.
248
+ - Discard `kpr` (one-shot; not stored).
249
+
250
+ ### 5.3 `submit_invite_response` → inviter leg 2 (NEW inbound)
251
+ `trn submit_invite_response args: any` → `handle_submit_invite_response`:
252
+ - `validate_origin_or_abort(external)`. **Do NOT `check_encrypted_or_abort`** — leg 1 is a bare
253
+ transport carrying a box; confidentiality/integrity come from the box, authenticity from the
254
+ cid-bind + PoP below. (Reviewer note: this is the one inbound that intentionally skips the
255
+ encryption check; the box is the protection.)
256
+ - `sender_id = get_external_envelope_or_abort() $from`.
257
+ - `invite_id = (args $invite_id) safe global_id`.
258
+ - **Single-use gate:** `rec = pending_invites invite_id`; `abort "Unknown or already-redeemed invite." when rec == NIL`.
259
+ - `eph_priv = pending_invite_keys invite_id`; `abort when eph_priv == NIL`.
260
+ - `epk_r = (args $epk) safe publickey_encrypt`; `ct = (args $data) safe crypto_message`.
261
+ - `payload = _read_or_abort << _crypto_decrypt_message eph_priv epk_r ct` (aborts on tamper / wrong key).
262
+ - `responder_ad = (payload $ad) safe t_address_document`.
263
+ - **D8 cid-bind:** `abort "Address document does not belong to the sender." when (responder_ad $identity $container_id) != sender_id`.
264
+ - `process_address_document responder_ad TRUE` — PoP self-sig enforcement; **registers the responder**.
265
+ - Optional chain: if `(payload $cert) != NIL` → `verify_peer_delegation` + pin `cp_binding`
266
+ (reuse the exact logic from today's `handle_accept_contact` L1191-1207).
267
+ - Register: `contacts[sender_id]`, `peer_ads[sender_id] = responder_ad`, `contact_roots` if any.
268
+ Name = `rec $assigned` if non-empty, else the responder's self-name / cid (today's L1181-1186 rule).
269
+ - **Consume:** `delete pending_invites invite_id`; `delete pending_invite_keys invite_id`.
270
+ - **Reply leg 3 over `encrypted_channel`** (responder now registered, per decision #2):
271
+ ```
272
+ encrypted_channel::send_encrypted_tx sender_id
273
+ ($name -> complete_invite_tx,
274
+ $targ -> ($invite_id -> invite_id, $ad -> my_ad,
275
+ $cert -> my_cert_blob, $root_profile -> my_rp_blob, $cp_binding -> my_rpb_blob))
276
+ ```
277
+ (my_* role material exactly as `add_contact` builds today, L570-578.)
278
+ - `_notify_agent contact_accepted` + `_save_state NIL`.
279
+
280
+ > **⚠ M1 spike — intra-transaction registration visibility.** This handler calls
281
+ > `process_address_document` (registers the responder) and then `send_encrypted_tx`
282
+ > (asserts `is_container_registered`) **in the same transaction**. The stdlib handshake does
283
+ > these across a continuation boundary (`encrypted_channel.mm:103-106`), so we must confirm the
284
+ > registration is visible *within the same tx*. **Validate this first.** If it does NOT hold,
285
+ > fallback: make leg 3 a **bare boxed send** too — encrypt `inviter_AD` to the responder's real
286
+ > encryption pubkey (now known from `responder_ad`) with a fresh inviter ephemeral, mirroring
287
+ > leg 1; `complete_invite` then decrypts with the responder's real key. (User preference is the
288
+ > `encrypted_channel` path; the fallback is only if the spike fails.)
289
+
290
+ ### 5.4 `complete_invite` → responder leg 3 (NEW inbound)
291
+ `trn complete_invite args: any` → `handle_complete_invite`:
292
+ - `validate_origin_or_abort(external)`; `check_encrypted_or_abort()` (this leg IS via the channel).
293
+ - `sender_id = get_external_envelope_or_abort() $from`.
294
+ - `invite_id = (args $invite_id) safe global_id`.
295
+ - `pend = pending_redemptions invite_id`; `abort "Unsolicited completion." when pend == NIL`.
296
+ - `abort "Completion from unexpected inviter." when sender_id != pend $inviter_cid`.
297
+ - `inviter_ad = (args $ad) safe t_address_document`.
298
+ - **cid-bind:** `abort when (inviter_ad $identity $container_id) != sender_id`.
299
+ - `process_address_document inviter_ad TRUE`.
300
+ - Optional chain: `verify_peer_delegation` + pin `cp_binding` (same reuse).
301
+ - Register: `contacts[sender_id]` under `pend $custom_name` (or the inviter's self-name `args.../`
302
+ invite name when empty), `peer_ads[sender_id] = inviter_ad`, `contact_roots` if any.
303
+ - `delete pending_redemptions invite_id`.
304
+ - `_notify_agent ($event -> $contact_added, ...)` + `_save_state NIL`.
305
+
306
+ ---
307
+
308
+ ## 6. Security analysis & invariants (critic will enforce)
309
+
310
+ **Properties preserved (vs today):**
311
+ - **Identity pin = OOB-delivered `container_id`.** Both leg 2 and leg 3 enforce
312
+ `received_AD.container_id == envelope.$from` AND `process_address_document(ad, TRUE)`
313
+ (PoP self-sig — see [[process-address-document-semantics]]). Identical to today's
314
+ `handle_accept_contact` gate. Pin strength tracks the (planned) `container_id` key-derivation;
315
+ not regressed.
316
+ - **Single-use redemption.** `pending_invites[invite_id]` + `pending_invite_keys[invite_id]`
317
+ consumed on first valid leg 2 — same anti-multi-use role as today's `pending_invites` gate.
318
+ - **Delegation chain verification** unchanged (`verify_peer_delegation`, `verify_root_cp_binding`);
319
+ only its transport moves (invite → encrypted hop). "No chain ⇒ treat as flat/root" stays the
320
+ structural default — no downgrade.
321
+ - **MITM exposure unchanged** — both designs are TOFU rooted in the OOB invite channel; an active
322
+ OOB attacker can substitute the whole invite in either design, and the defense is the same
323
+ (verify the cid you ended up pinned to, out of band).
324
+
325
+ **Improvements:**
326
+ - **Privacy / reduced disclosure.** An intercepted invite leaks only `{eph_pub, cid, name}` —
327
+ no keys, no `root_profile`, no org chain. Today's invite leaks the inviter's full identity (and
328
+ for roles the entire root profile + delegation chain) to anyone who sees it. The identity bundle
329
+ now travels only inside a box, to a party that has proven liveness.
330
+ - **Leaked-invite blast radius shrinks.** A leaked slim invite forces an attacker to actively
331
+ round-trip (revealing its own cid) and is single-use; a leaked fat invite is passive total
332
+ identity exposure.
333
+
334
+ **New risks (accepted / mitigated):**
335
+ - **Eph privkey at rest** (`pending_invite_keys`) per outstanding invite — weaker forward secrecy
336
+ for the leg-1 payload than the truly-ephemeral handshake keys. Mitigations: kept in a
337
+ **non-exported** hidden field (§4.2); single-use delete; **add an expiry/TTL sweep** (decision §10).
338
+ - **Leg 1 is an unauthenticated bare inbound.** Anyone holding the (leaked) invite can spam
339
+ `submit_invite_response`, each forcing a decrypt attempt. Bounded DoS: aborts cheaply on the
340
+ `pending_invites` lookup / box-open / cid-bind, and the first valid one consumes the invite.
341
+ Note in the threat model; no state is mutated before the gates pass.
342
+ - **Disclosure order flips** — the responder reveals its identity first (boxed to an
343
+ unauthenticated eph key) before learning the inviter's verified identity in leg 3. Neutral under
344
+ OOB-trust; the responder can `abort`/discard at leg 3 if the inviter cid mismatches, but has by
345
+ then disclosed to whoever held `eph_priv`. Acceptable; document it.
346
+ - **No hand-rolled handshake.** We use only one-shot `_crypto_encrypt_message`/`decrypt` (the
347
+ established `authorize_packet` idiom) — there is no interactive multi-leg key agreement to get
348
+ wrong. `encrypted_channel` is untouched (decision #2).
349
+
350
+ **Hard invariants (do not break):**
351
+ - Every inbound AD is cid-bound to `envelope.$from` **and** `process_address_document(ad, TRUE)`'d
352
+ before it is stored or trusted.
353
+ - `pending_invite_keys` is NEVER included in `export_core_state`.
354
+ - The invite is consumed (both stores) exactly once, on the first valid leg 2.
355
+ - Leg 1 must not mutate persistent contact state before all gates (lookup → decrypt → cid-bind →
356
+ PoP) pass.
357
+
358
+ ---
359
+
360
+ ## 7. Backward compatibility & versioning
361
+
362
+ This is a **breaking** invite-format + flow change → **`version.mm` 2.17 → 3.0 (MAJOR)**.
363
+
364
+ Options for the legacy `invite_t`/`invite_role_t` redemption path:
365
+ - **(A) Clean break (recommended).** Remove `invite_t`, `invite_role_t`,
366
+ `rebuild_peer_address_document`, and the old `add_contact` body. Invites are short-lived
367
+ artifacts, consumers pin/lag core versions and re-issue invites on upgrade, and dual flows
368
+ double the security-critical surface. The 3.0 note states old invites are not redeemable.
369
+ - **(B) Transitional dual-redeem.** Keep the legacy metadefs + `rebuild_peer_address_document`;
370
+ in `add_contact`, sniff the blob (e.g. `$k` is a single `publickey_encrypt` for slim vs a key
371
+ list for legacy, or a format/version discriminator field) and branch to the old path. More
372
+ code, more risk; only if a live deployment must redeem outstanding fat invites across the bump.
373
+
374
+ Recommend **(A)** unless a concrete outstanding-invite migration need surfaces.
375
+
376
+ ---
377
+
378
+ ## 8. Work breakdown (core mufl only)
379
+
380
+ | # | File | Change | Size |
381
+ |---|------|--------|------|
382
+ | 1 | `a2a_protocol.mm` | Add `invite_eph_t`; document leg-1/leg-3 payload shapes. Per §7: remove or retain legacy `invite_t`/`invite_role_t` + `rebuild_peer_address_document`. | S |
383
+ | 2 | `a2a_messaging.mm` | State: `pending_invites` → `(global_id ->> pending_invite_t)`; add hidden non-exported `pending_invite_keys`; add `pending_redemptions`. | S |
384
+ | 3 | `a2a_messaging.mm` | `mint_invite` → `mint_eph_invite` (§5.1). `generate_invite` rewires to it. | S |
385
+ | 4 | `a2a_messaging.mm` | Rework `add_contact`/`redeem_invite` → responder leg 1 (§5.2). | M |
386
+ | 5 | `a2a_messaging.mm` | New `submit_invite_response` + `handle_*` → inviter leg 2 (§5.3), incl. the M1 spike. | M |
387
+ | 6 | `a2a_messaging.mm` | New `complete_invite` + `handle_*` → responder leg 3 (§5.4). | M |
388
+ | 7 | `a2a_messaging.mm` | New tx-name consts; `export_core_state` (ensure NO eph secrets); `import_core_state` migration (§4.4). | S |
389
+ | 8 | `version.mm` | `create_version 2 17` → `create_version 3 0` (MAJOR). | XS |
390
+ | 9 | `release-notes/3.0.md` | New note per the existing release-notes convention (header + shipped txns + breaking-change + security notes). | S |
391
+ | 10 | (compile) | Clean compile against the ADAPT toolkit; no consumer wiring (see [[qa-toolchain-mufl-core]]). | — |
392
+
393
+ `a2a_cluster.mm`: **no change** — it relays the invite blob opaquely (host runs `generate_invite`
394
+ in the child packet; `register_child_invite` forwards an opaque bin). Confirm during review.
395
+
396
+ ---
397
+
398
+ ## 9. Test plan (core-level, loopback per [[qa-toolchain-mufl-core]])
399
+
400
+ 1. **Compile** clean; `get_version` → 3.0.
401
+ 2. **Slim invite shape** — `generate_invite` blob parses as `invite_eph_t`; carries no key list,
402
+ no cert, no root_profile; size << a legacy role invite (assert byte-length drop).
403
+ 3. **M1 spike (do first)** — confirm `process_address_document` registration is visible to
404
+ `send_encrypted_tx` within the same tx (leg 2). If not, switch leg 3 to the boxed fallback (§5.3).
405
+ 4. **Happy path (flat)** — inviter `generate_invite` → responder leg 1 → leg 2 registers responder +
406
+ replies → leg 3 registers inviter. Both `list_contacts` show the other; `peer_ads` populated both
407
+ ways; subsequent `send_message` round-trips.
408
+ 5. **Happy path (role)** — inviter and/or responder are delegated roles; chains verify on the
409
+ encrypted hop; `contact_roots` + `contact_cp_bindings` pinned both directions.
410
+ 6. **Single-use** — a second leg 1 for the same `invite_id` aborts ("already-redeemed").
411
+ 7. **Tamper** — corrupted `data` (box) aborts at decrypt; wrong `epk` aborts; no contact written.
412
+ 8. **cid-bind** — leg-1 AD whose `container_id != $from` aborts; leg-3 from a sender `!= inviter_cid`
413
+ aborts.
414
+ 9. **PoP** — forged/inconsistent AD aborts in `process_address_document` (both legs).
415
+ 10. **Export secrecy** — `export_core_state` output contains NO eph private key; an outstanding
416
+ invite does not survive export→import (documented behavior).
417
+ 11. **DoS gate** — unsolicited `submit_invite_response` with an unknown `invite_id` aborts before
418
+ any state mutation.
419
+
420
+ ---
421
+
422
+ ## 10. Open decisions
423
+
424
+ - **Legacy redemption: clean break (A) or transitional dual path (B)?** Recommend A. (§7)
425
+ - **Trn naming:** keep `add_contact` for the responder leg, or rename to `redeem_invite`
426
+ (clearer now that it no longer "adds" synchronously — the contact finalizes at leg 3)?
427
+ - **Eph-key TTL:** add an expiry sweep for `pending_invites`/`pending_invite_keys` (bounds the
428
+ at-rest-secret window and stale-invite growth)? Recommend yes; needs a time source + sweep hook.
429
+ - **`pending_redemptions` export:** export it (no secrets, lets a mid-flight redemption survive
430
+ upgrade) or keep transient (simpler)? Minor.
431
+ - **Metadata in the invite:** name only (locked), or also a short inviter bio? User said name only.
432
+
433
+ ---
434
+
435
+ ## 10a. Rejected alternative — two-keypair "symmetric key" invite
436
+
437
+ **Idea (considered 2026-06-20):** mint two ephemeral keypairs A, B; ship `(pub_A, priv_B)` in the
438
+ invite, retain `priv_A`. Both sides derive the same ECDH shared secret `K` (`box(priv_B,pub_A) ==
439
+ box(priv_A,pub_B)`), so the responder encrypts leg 1 with `K` **without generating its own keypair
440
+ or shipping a cleartext pubkey**. Correct observation that this is just a **pre-shared symmetric
441
+ key** encoded through the two-key box API.
442
+
443
+ **Rejected — it converts the invite from a PUBLIC token into a SECRET-bearing one,** for marginal
444
+ gain (saves the responder one `_crypto_construct_encryption_keypair`):
445
+ - **OOB channel requirement upgrades** from *authentic-only* to *authentic AND confidential* — the
446
+ invite now carries `priv_B`, and anyone who sees the invite derives `K`.
447
+ - **Metadata privacy lost** vs an attacker who sees the invite *and* the wire: they derive `K` and
448
+ decrypt leg 1 (who connected to whom). The single-pubkey design keeps this private (decryption
449
+ needs `priv_eph_inviter`, which never leaves the inviter).
450
+ - **Human-factors footgun:** users paste/screenshot/log invites; a public-key invite is safe to
451
+ handle carelessly, a secret-bearing one is not.
452
+ - **Fixed-`K` nonce hygiene** is sharper than per-box fresh ephemerals.
453
+ - **No authentication benefit:** identity still rests entirely on `process_address_document` +
454
+ `container_id` pin; `K` is transport-only, so this changes confidentiality, never auth.
455
+
456
+ Keep the single ephemeral **public** key in the invite (§3). The responder keygen it requires is
457
+ cheap and keeps the invite safe to handle as a non-secret.
458
+
459
+ ## 11. Sequencing
460
+
461
+ - **M0 — M1 spike** (§9.3): intra-tx registration visibility → fixes the leg-3 mechanism.
462
+ - **M1 — Shapes + state + mint** (#1–#3, #8): compile.
463
+ - **M2 — Three legs** (#4–#6) + happy-path + single-use + tamper + cid-bind tests.
464
+ - **M3 — Export/import + migration** (#7) + export-secrecy test.
465
+ - **M4 — Release note** (#9) + critic review against §6 invariants.