@ours.network/tg-connector 0.3.2 → 0.3.3-nightly.1

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 (96) hide show
  1. package/README.md +27 -35
  2. package/dist/cli.js +16 -68
  3. package/dist/connector.js +53220 -8213
  4. package/docs/voice-message-contract.md +8 -2
  5. package/package.json +3 -5
  6. package/dist/mufl_code/8A84AD8E225F186F666D3EAB2AFF777A4B9BB1B9C7CCF45CF364497EF16CF3E5.muflo +0 -0
  7. package/dist/mufl_code/actor.mu +0 -1833
  8. package/dist/mufl_code/config.mufl +0 -27
  9. package/dist/mufl_code/core/COMMERCIAL-LICENCE.md +0 -25
  10. package/dist/mufl_code/core/COMPATIBILITY.md +0 -221
  11. package/dist/mufl_code/core/CONTRIBUTING.md +0 -37
  12. package/dist/mufl_code/core/LICENSE +0 -98
  13. package/dist/mufl_code/core/NOTIFICATIONS_CONTRACT.md +0 -290
  14. package/dist/mufl_code/core/README.md +0 -91
  15. package/dist/mufl_code/core/SECURITY.md +0 -40
  16. package/dist/mufl_code/core/TRADEMARKS.md +0 -24
  17. package/dist/mufl_code/core/a2a_capabilities.mm +0 -449
  18. package/dist/mufl_code/core/a2a_cluster.mm +0 -601
  19. package/dist/mufl_code/core/a2a_control.mm +0 -90
  20. package/dist/mufl_code/core/a2a_messaging.mm +0 -4817
  21. package/dist/mufl_code/core/a2a_monitoring.mm +0 -94
  22. package/dist/mufl_code/core/a2a_notification_integration.mm +0 -144
  23. package/dist/mufl_code/core/a2a_notifications.mm +0 -1127
  24. package/dist/mufl_code/core/a2a_protocol.mm +0 -246
  25. package/dist/mufl_code/core/a2a_versions.mm +0 -801
  26. package/dist/mufl_code/core/config.mufl +0 -29
  27. package/dist/mufl_code/core/docs/.vitepress/config.mts +0 -58
  28. package/dist/mufl_code/core/docs/citations.json +0 -688
  29. package/dist/mufl_code/core/docs/guide/01-vendor-the-core.md +0 -50
  30. package/dist/mufl_code/core/docs/guide/02-configure-and-compile.md +0 -100
  31. package/dist/mufl_code/core/docs/guide/03-wire-the-host.md +0 -154
  32. package/dist/mufl_code/core/docs/guide/04-connect-and-message.md +0 -156
  33. package/dist/mufl_code/core/docs/guide/05-test-your-app.md +0 -75
  34. package/dist/mufl_code/core/docs/guide/index.md +0 -63
  35. package/dist/mufl_code/core/docs/how-it-works/capabilities-and-control.md +0 -77
  36. package/dist/mufl_code/core/docs/how-it-works/cluster.md +0 -65
  37. package/dist/mufl_code/core/docs/how-it-works/identity.md +0 -56
  38. package/dist/mufl_code/core/docs/how-it-works/invites-and-contacts.md +0 -76
  39. package/dist/mufl_code/core/docs/how-it-works/messaging.md +0 -55
  40. package/dist/mufl_code/core/docs/how-it-works/monitoring-and-config.md +0 -72
  41. package/dist/mufl_code/core/docs/how-it-works/overview.md +0 -45
  42. package/dist/mufl_code/core/docs/how-it-works/versioning.md +0 -116
  43. package/dist/mufl_code/core/docs/index.md +0 -27
  44. package/dist/mufl_code/core/docs/package-lock.json +0 -3467
  45. package/dist/mufl_code/core/docs/package.json +0 -15
  46. package/dist/mufl_code/core/docs/reference/contributing.md +0 -26
  47. package/dist/mufl_code/core/docs/reference/glossary.md +0 -108
  48. package/dist/mufl_code/core/docs/reference/implementations.md +0 -23
  49. package/dist/mufl_code/core/docs/reference/modules.md +0 -19
  50. package/dist/mufl_code/core/docs/scripts/check-citations.mjs +0 -36
  51. package/dist/mufl_code/core/docs/scripts/check-denylist.mjs +0 -30
  52. package/dist/mufl_code/core/docs/scripts/gen-llms.mjs +0 -32
  53. package/dist/mufl_code/core/docs/workflows/cluster.md +0 -89
  54. package/dist/mufl_code/core/docs/workflows/contact-exchange.md +0 -60
  55. package/dist/mufl_code/core/docs/workflows/contact-restore.md +0 -60
  56. package/dist/mufl_code/core/docs/workflows/control-verbs.md +0 -70
  57. package/dist/mufl_code/core/docs/workflows/index.md +0 -57
  58. package/dist/mufl_code/core/docs/workflows/introductions.md +0 -60
  59. package/dist/mufl_code/core/docs/workflows/messaging.md +0 -75
  60. package/dist/mufl_code/core/docs/workflows/monitoring.md +0 -84
  61. package/dist/mufl_code/core/docs/workflows/notifications.md +0 -109
  62. package/dist/mufl_code/core/release-notes/0.1.md +0 -60
  63. package/dist/mufl_code/core/release-notes/0.3.md +0 -22
  64. package/dist/mufl_code/core/release-notes/0.4.md +0 -97
  65. package/dist/mufl_code/core/tests/README.md +0 -83
  66. package/dist/mufl_code/core/tests/compat/README.md +0 -82
  67. package/dist/mufl_code/core/tests/compat/compat.mjs +0 -245
  68. package/dist/mufl_code/core/tests/compat/compat_peer.mjs +0 -146
  69. package/dist/mufl_code/core/tests/compat/run_compat.sh +0 -96
  70. package/dist/mufl_code/core/tests/corpus.mjs +0 -139
  71. package/dist/mufl_code/core/tests/corpus_actor.mu +0 -242
  72. package/dist/mufl_code/core/tests/fatcompile_actor.mu +0 -52
  73. package/dist/mufl_code/core/tests/mig.mjs +0 -805
  74. package/dist/mufl_code/core/tests/mig_actor.mu +0 -518
  75. package/dist/mufl_code/core/tests/migapp.mjs +0 -431
  76. package/dist/mufl_code/core/tests/migapp_actor.mu +0 -294
  77. package/dist/mufl_code/core/tests/mufl_semantics/run.sh +0 -69
  78. package/dist/mufl_code/core/tests/mufl_semantics/t11_three_version.mufl +0 -47
  79. package/dist/mufl_code/core/tests/mufl_semantics/t2_extra_fields.mufl +0 -11
  80. package/dist/mufl_code/core/tests/mufl_semantics/t7_runtime.mufl +0 -30
  81. package/dist/mufl_code/core/tests/mufl_semantics/t9_passthrough.mufl +0 -19
  82. package/dist/mufl_code/core/tests/mufl_semantics/t_str_order.mufl +0 -19
  83. package/dist/mufl_code/core/tests/notif.mjs +0 -755
  84. package/dist/mufl_code/core/tests/notif_actor.mu +0 -450
  85. package/dist/mufl_code/core/tests/protocol_container.mm +0 -18
  86. package/dist/mufl_code/core/tests/run.sh +0 -65
  87. package/dist/mufl_code/core/tests/run_corpus.sh +0 -51
  88. package/dist/mufl_code/core/tests/run_fatcompile.sh +0 -40
  89. package/dist/mufl_code/core/tests/run_mig.sh +0 -51
  90. package/dist/mufl_code/core/tests/run_migapp.sh +0 -51
  91. package/dist/mufl_code/core/tests/run_notif.sh +0 -57
  92. package/dist/mufl_code/core/tests/test.mjs +0 -750
  93. package/dist/mufl_code/core/tests/test_actor.mu +0 -564
  94. package/dist/mufl_code/core/tests/test_common.mjs +0 -93
  95. package/dist/mufl_code/core/version.mm +0 -24
  96. package/dist/mufl_code/protocol_container.mm +0 -18
@@ -1,1833 +0,0 @@
1
- // ours messenger packet.
2
- //
3
- // One ADAPT node == one of these packets. Two nodes talk directly, peer to
4
- // peer, through a relay broker (no central server). Messages are end-to-end
5
- // encrypted; the key exchange is handled for us by the stdlib `encrypted_channel`
6
- // library — we only ever address peers by their container id.
7
- //
8
- // The shared transaction logic lives in the ours-mufl-core repo (checked
9
- // out as the core/ subfolder of this directory): `a2a_protocol` (wire shapes +
10
- // verification), `a2a_messaging` (contact + message wire path, addressed
11
- // ::a2a_messaging::<name> by the host), and `version`. They are shared with
12
- // the web messenger — change them there, bump core_version, and recompile
13
- // every consumer.
14
- //
15
- // This packet keeps only what is agent-specific:
16
- // - the inbox message store with its lifecycle (unread -> processed ->
17
- // ready_to_delete -> deleted; see get_messages / gc / defer_messages)
18
- // - the local contact book + identity hierarchy transactions (host-fired)
19
- // - export_state / import_state wrappers composing the core helpers with
20
- // the app-side fields (including the legacy-blob migrations)
21
- // - ::actor:: compat shims for the network-visible inbound transactions
22
- // (accept_contact, receive_message) — pre-migration peers send to these
23
- // names, and the core keeps SENDING to them too (Option A: zero network
24
- // break; drop both only when no old clients remain)
25
- //
26
- // Storage is wired into the core via a2a_messaging::init hooks (see the
27
- // hidden block): on_message_received deposits into the inbox (or the
28
- // pending-introduction queue for unknown senders); send/remove hooks are
29
- // agent no-ops.
30
- //
31
- // User transactions (each backs one MCP tool, except gc which the host fires):
32
- // ::a2a_messaging::set_my_name — set the display name peers see for me
33
- // ::a2a_messaging::set_my_bio — set my profile bio (free-text, self-asserted)
34
- // ::a2a_messaging::generate_invite — make an invite blob for a named peer
35
- // ::a2a_messaging::add_contact — join via an invite blob, reply to the inviter
36
- // ::a2a_messaging::send_message — send an e2e-encrypted message to a contact
37
- // ::a2a_messaging::remove_contact — forget a contact
38
- // ::a2a_messaging::list_contacts — (readonly) my contacts
39
- // ::a2a_messaging::list_contact_roots — (readonly) verified root linkage per contact
40
- // ::a2a_messaging::get_version — (readonly) shared-core version
41
- // list_incoming_messages — (readonly) my inbox, with per-message id + status
42
- // get_messages — return unread messages + mark them processed (sole body egress)
43
- // defer_messages — flip processed/ready_to_delete messages back to unread
44
- // gc — two-generation GC of handled messages (host-fired, not a tool)
45
- // ::a2a_messaging::flush_deferred — (host-fired) replay deferred queues once conditions clear
46
- // restore_degraded_contacts — (host-fired) (re)issue restore requests for every degraded contact
47
- // list_degraded_contacts — (readonly) contacts currently degraded (channel needs restore)
48
- // list_deferred_queues — (readonly) per-contact deferred-message queue sizes
49
- //
50
- // Identity hierarchy (host-fired transactions; see IDENTITY-HIERARCHY-DESIGN.md):
51
- // sign_delegation — root-only in practice: sign a delegation cert for a role
52
- // export_root_profile — root-only in practice: my self-signed root profile blob
53
- // set_delegation — role: store my verified delegation cert + root material
54
- // describe_identity — (readonly) name/bio/hierarchy position
55
- // connect_sibling — register an intra-root peer + send sibling_introduce
56
- //
57
- // Local contact book (host-fired transactions; see the design notes above
58
- // local_introduce below):
59
- // export_address_document — (readonly) my signed address document as a blob
60
- // pin_registrar — pin the host registrar's signing keys (pin-once)
61
- // set_local_policy — toggle auto-accept of local introductions
62
- // mint_introduction — registrar-only in practice: sign an introduction credential
63
- // sign_book_entry — registrar-only in practice: sign a contact-book entry
64
- // connect_local — register a book contact + send local_introduce (+ first message)
65
- // approve_introduction — accept a pending local introduction (flushes its queue)
66
- // reject_introduction — drop a pending local introduction
67
- // list_pending_introductions — (readonly) pending introductions (names + queue sizes)
68
- //
69
- // Monitoring + control plane (host-fired unless noted; see
70
- // MONITORING-AND-SHARED-LIBRARY-DESIGN.md):
71
- // get_monitoring_status — (readonly) enabled flag / proxy binding / queue sizes
72
- // sign_monitoring_auth — root-only: sign an enable/disable auth for a role
73
- // set_monitoring — role: verify the root-signed auth, set the flag
74
- // get_monitoring_copies — root: drain queued copies for proxy forwarding
75
- // get_control_requests — root: drain queued proxy control requests
76
- // set_proxy_pending — root: store the host-generated 6-digit code
77
- // verify_proxy_code — root: check a bind attempt (atomic attempts/expiry)
78
- // clear_monitoring_proxy — root: drop the proxy binding
79
- // ::a2a_control::send_control — send an opaque control payload to a contact
80
- //
81
- // External transactions (inbound, not exposed as tools):
82
- // accept_contact — inviter learns the joiner's identity + name (core shim)
83
- // receive_message — store a decrypted inbound message (core shim)
84
- // receive_monitoring_copy — a monitored role of mine reports a message copy
85
- // ::a2a_control::control_message — control payload from a contact (queued for the daemon)
86
- // local_introduce — same-host peer connects via the local contact book
87
- // sibling_introduce — intra-root peer connects, authorized by its delegation cert
88
- // ::a2a_messaging::request_contact_restore / submit_restore_response / complete_restore
89
- // — contact-restore handshake (signed re-key between known contacts)
90
-
91
- application actor loads libraries
92
- identity_proof_document,
93
- attestation_document,
94
- native_attestation_document,
95
- transaction_message_decoder,
96
- address_document,
97
- address_document_types,
98
- key_utils,
99
- key_storage,
100
- continuation,
101
- encrypted_channel,
102
- current_transaction_info,
103
- a2a_protocol,
104
- a2a_messaging,
105
- a2a_control,
106
- a2a_capabilities,
107
- protocol_container,
108
- registration_proof,
109
- version
110
- uses transactions
111
- {
112
- hidden
113
- {
114
- // A received message carries a stable per-packet id and a lifecycle status:
115
- // "unread" (just arrived) -> "processed" (handed to the agent via
116
- // get_messages) -> "ready_to_delete" (first gc tick) -> deleted (next gc
117
- // tick). defer_messages flips "processed"/"ready_to_delete" back to "unread"
118
- // so another session can pick it up — restorable from either generation,
119
- // which is what makes the two-generation gc window race-free.
120
- // $wire_id is the sender-stamped, cross-side handle ("" when the sender
121
- // predates wire ids, or for introduction first-messages); $reply_to is
122
- // the optional pointer at the message this one replies to (NIL = not a
123
- // reply). Both are surfaced by get_messages so an agent can reference a
124
- // message in a reply and recognize an incoming reply pointer.
125
- metadef message_t: ($msg_id -> int, $sender_id -> global_id, $sender_name -> str, $text -> str, $date -> time, $status -> str, $wire_id -> str, $reply_to -> a2a_protocol::reply_ref_t+).
126
- // The pre-lifecycle inbox shape (no per-message id/status). import_state
127
- // migrates blobs in this shape forward — see below.
128
- metadef legacy_message_t: ($sender_id -> global_id, $sender_name -> str, $text -> str, $date -> time).
129
-
130
- // A received FILE, mirroring message_t's lifecycle so the receive path gets the
131
- // same at-least-once / defer / two-generation-gc guarantees as messages. Unlike
132
- // the QA reference (test_actor.mu) this store keeps the bytes ($data) — the
133
- // connector must re-deliver them to Telegram. $wire_id is the sender-stamped
134
- // cross-side handle (shared with messages); $reply_to is NIL unless a reply.
135
- metadef file_t: (
136
- $file_id -> int,
137
- $sender_id -> global_id,
138
- $sender_name -> str,
139
- $filename -> str,
140
- $mime -> str,
141
- $data -> bin,
142
- $date -> time,
143
- $status -> str,
144
- $wire_id -> str,
145
- $reply_to -> a2a_protocol::reply_ref_t+
146
- ).
147
-
148
- // A not-yet-approved local introduction, with its bounded message queue.
149
- // (The local-book WIRE shapes — intro_t, signed_intro_t, book_entry_t —
150
- // live in a2a_protocol; these three are packet-local state/view shapes.)
151
- metadef pending_msg_t: ($text -> str, $date -> time).
152
- metadef pending_intro_t: ($name -> str, $ad -> address_document_types::t_address_document, $messages -> pending_msg_t[]).
153
- metadef pending_view_t: ($name -> str, $queued -> int).
154
-
155
- // Acceptance window for an introduction credential (seconds since mint;
156
- // small negative slack for clock oddities) and the matching nonce-table
157
- // retention horizon (window + slack, so a nonce outlives its credential).
158
- intro_max_age_seconds is int = 300.
159
- intro_max_skew_seconds is int = 30.
160
- seen_nonce_cap is int = 1024.
161
- pending_queue_cap is int = 50.
162
-
163
- // ---- monitoring shapes + limits (see MONITORING-AND-SHARED-LIBRARY-DESIGN.md) ----
164
- // Root-signed authorization for flipping a role's monitoring flag. Like
165
- // a delegation cert, verified against the role's pinned root keys, so
166
- // only this hierarchy's root can change what its roles report.
167
- metadef monitoring_auth_core_t: ($version -> int, $role_cid -> global_id, $enabled -> bool, $issued_at -> time).
168
- metadef monitoring_auth_t: ($c -> monitoring_auth_core_t, $s -> crypto_signature).
169
- // One monitored message, as the role reports it to its root.
170
- metadef monitoring_copy_t: (
171
- $version -> int,
172
- $source_cid -> global_id,
173
- $source_name -> str,
174
- $direction -> str,
175
- $peer_cid -> global_id,
176
- $peer_name -> str,
177
- $date -> time,
178
- $body -> str
179
- ).
180
- // Proxy binding (root only): a pending 6-digit-code verification and
181
- // the verified binding that replaces it on success.
182
- metadef proxy_pending_t: ($code -> str, $proxy_cid -> global_id, $created_at -> time, $attempts -> int).
183
- metadef proxy_binding_t: ($proxy_cid -> global_id, $bound_at -> time).
184
- // One queued control request from the bound browser proxy.
185
- metadef control_req_t: ($sender_cid -> global_id, $sender_name -> str, $payload -> str, $date -> time).
186
-
187
- proxy_code_max_age_seconds is int = 300.
188
- proxy_max_attempts is int = 3.
189
- monitoring_inbox_cap is int = 500.
190
- control_inbox_cap is int = 200.
191
-
192
- // Wire the deserialization primitive into the libraries that need it.
193
- _read_or_abort = grab( _read_or_abort ).
194
- key_storage::init ($_read_or_abort -> _read_or_abort).
195
- encrypted_channel::init ($_read_or_abort -> _read_or_abort).
196
-
197
- // ---- packet state ---------------------------------------------------
198
- // (The shared contact/profile/hierarchy state — my_name, contacts,
199
- // pending_invites, peer_ads, my_bio, delegation_cert, root_ad,
200
- // root_profile, contact_roots — lives in a2a_messaging and is read /
201
- // assigned as a2a_messaging::<field> below.)
202
- //
203
- // Received messages. Each carries its own lifecycle status (see
204
- // message_t / get_messages / gc / defer_messages), so the
205
- // packet is the single authority on what has been read or processed —
206
- // no host-side cursor, safe across concurrent sessions.
207
- inbox is message_t[] = [].
208
- // Monotonic source of per-message ids (the stable handle the agent uses
209
- // to mark a message processed or defer it).
210
- next_msg_seq is int = 1.
211
- // Received files (bytes included), same lifecycle as inbox. Drained by
212
- // get_files, recovered by defer_files, reclaimed by gc.
213
- file_inbox is file_t[] = [].
214
- next_file_seq is int = 1.
215
- // The host registrar's address document (pinned once at identity
216
- // creation / injected on upgrade) — its $identity $key_list is what
217
- // introduction credentials are verified against. NIL means this identity
218
- // accepts no local-book introductions at all.
219
- registrar_ad is address_document_types::t_address_document+ = NIL.
220
- // Whether a verified local introduction registers the joiner immediately
221
- // (TRUE) or parks it in pending_introductions for explicit approval.
222
- local_auto_accept is bool = TRUE.
223
- // Replay guard for introduction credentials: nonce -> when it was seen.
224
- // Lazily purged past the freshness horizon, hard-capped at seen_nonce_cap.
225
- seen_nonces is (global_id ->> time) = (,).
226
- // Verified-but-unapproved local introductions (when auto-accept is off),
227
- // each with a bounded queue of messages awaiting approval.
228
- pending_introductions is (global_id ->> pending_intro_t) = (,).
229
-
230
- // ---- monitoring state -------------------------------------------------
231
- // Whether THIS packet (a role) reports its message traffic to its root.
232
- // Only flipped by a root-signed authorization (set_monitoring).
233
- monitoring_enabled is bool = FALSE.
234
- // Root only: copies received from monitored roles, awaiting the host's
235
- // get_monitoring_copies pull (forwarded to the bound proxy). Capped;
236
- // oldest copies are dropped first when no proxy drains the queue.
237
- monitoring_inbox is monitoring_copy_t[] = [].
238
- // Root only: the in-flight proxy binding (6-digit code verification)
239
- // and the verified proxy that monitoring traffic is forwarded to.
240
- proxy_pending is proxy_pending_t+ = NIL.
241
- monitoring_proxy is proxy_binding_t+ = NIL.
242
- // Root only: control requests from the bound proxy, awaiting the
243
- // host's get_control_requests pull. Kept out of the message inbox so
244
- // agent sessions never see them.
245
- control_inbox is control_req_t[] = [].
246
-
247
- // Signal the host to persist the packet. Only emitted at the end of a
248
- // complete procedure — intermediate states (e.g. channel handshake) are
249
- // never saved, so a crash mid-handshake restores to the last stable point.
250
- fn _save_state (_) = (transaction::action::return_data ($kind -> $save_state)).
251
- fn _return_data (payload: any) = (transaction::action::return_data ($kind -> $data, $payload -> payload)).
252
- fn _notify_agent (payload: any) = (transaction::action::return_data ($kind -> $notify_agent, $payload -> payload)).
253
-
254
- // A typed NIL reply pointer, passed by the call sites that deposit a
255
- // message with no reply context (introduction first-messages, approval
256
- // flush). A bare NIL literal cannot infer the nullable reply_ref_t type
257
- // at the call; this binding gives it one.
258
- no_reply is a2a_protocol::reply_ref_t+ = NIL.
259
-
260
- // Append a message to the inbox under a fresh id; returns the id.
261
- // wire_id is "" for introduction first-messages and pre-1.4 senders;
262
- // reply_to is NIL unless the sender marked this a reply.
263
- fn deposit_message (sender_id: global_id, sender_name: str, text: str, msg_date: time, wire_id: str, reply_to: a2a_protocol::reply_ref_t+) -> int
264
- {
265
- mid = next_msg_seq.
266
- next_msg_seq -> next_msg_seq + 1.
267
- inbox (_count inbox|) -> (
268
- $msg_id -> mid,
269
- $sender_id -> sender_id,
270
- $sender_name -> sender_name,
271
- $text -> text,
272
- $date -> msg_date,
273
- $status -> "unread",
274
- $wire_id -> wire_id,
275
- $reply_to -> reply_to
276
- ).
277
- return mid.
278
- }
279
-
280
- // Append a file to file_inbox under a fresh id; returns the id. Mirrors
281
- // deposit_message. wire_id is "" for a pre-wire sender; reply_to is NIL unless
282
- // the sender marked this a reply.
283
- fn deposit_file (sender_id: global_id, sender_name: str, filename: str, mime: str, data: bin, file_date: time, wire_id: str, reply_to: a2a_protocol::reply_ref_t+) -> int
284
- {
285
- fid = next_file_seq.
286
- next_file_seq -> next_file_seq + 1.
287
- file_inbox (_count file_inbox|) -> (
288
- $file_id -> fid,
289
- $sender_id -> sender_id,
290
- $sender_name -> sender_name,
291
- $filename -> filename,
292
- $mime -> mime,
293
- $data -> data,
294
- $date -> file_date,
295
- $status -> "unread",
296
- $wire_id -> wire_id,
297
- $reply_to -> reply_to
298
- ).
299
- return fid.
300
- }
301
-
302
- // Build the monitoring-copy action for one message IF this packet is a
303
- // monitored role with a live encrypted channel to its root; [] otherwise.
304
- // The is_container_registered guard makes a missing/lost root channel
305
- // degrade to "no copy" instead of failing the user's message — the
306
- // enable flow (host-side) establishes the channel via connect_sibling.
307
- fn monitor_copy_actions (direction: str, peer_cid: global_id, text: str, msg_date: time) -> transaction::action::type[]
308
- {
309
- if monitoring_enabled == FALSE || a2a_messaging::delegation_cert == NIL { return []. }
310
- root_cid = a2a_messaging::delegation_cert? $c $root_cid.
311
- if key_storage::is_container_registered(root_cid) != TRUE { return []. }
312
-
313
- peer_name is str = "".
314
- p = a2a_messaging::contacts peer_cid.
315
- if p != NIL { peer_name -> p? $name. }
316
-
317
- copy is monitoring_copy_t = (
318
- $version -> 1,
319
- $source_cid -> _get_container_id(),
320
- $source_name -> a2a_messaging::my_name,
321
- $direction -> direction,
322
- $peer_cid -> peer_cid,
323
- $peer_name -> peer_name,
324
- $date -> msg_date,
325
- $body -> text
326
- ).
327
- return [
328
- encrypted_channel::send_encrypted_tx root_cid (
329
- $name -> "::actor::receive_monitoring_copy",
330
- $targ -> ($copy -> copy)
331
- )
332
- ].
333
- }
334
-
335
- // Resolve a pending introduction by joiner name or stringified container
336
- // id; aborts when nothing matches.
337
- fn resolve_pending (ref: str) -> global_id
338
- {
339
- found is global_id+ = NIL.
340
- sc pending_introductions -- (cid -> p) ?? found == NIL && ((p $name) == ref || (_str cid) == ref)
341
- {
342
- found -> cid.
343
- }
344
- abort "No pending introduction matches: " + ref when found == NIL.
345
- return found?.
346
- }
347
-
348
- // Wire the agent's storage into the shared messaging core. The receive
349
- // hook owns everything app-specific about an inbound message: known
350
- // senders deposit into the inbox; an unknown sender may be a verified-
351
- // but-unapproved local introduction messaging before approval — queue
352
- // (bounded) inside its pending entry, approval flushes the queue into
353
- // the inbox in order; anything else from an unknown sender is rejected.
354
- // The notification deliberately carries NO message body — only that a
355
- // message arrived, from whom, and its id. The body stays in the packet
356
- // and only leaves through get_messages.
357
- a2a_messaging::init (
358
- $_read_or_abort -> _read_or_abort,
359
- $on_message_received -> fn (arg: any) -> transaction::action::type[]
360
- {
361
- sender_id = (arg $sender_id) safe global_id.
362
- text = (arg $text) safe str.
363
- msg_date = (arg $date) safe time.
364
- wire_id is str = "".
365
- if (arg $wire_id) != NIL { wire_id -> (arg $wire_id) safe str. }
366
- reply_to is a2a_protocol::reply_ref_t+ = NIL.
367
- if (arg $reply_to) != NIL { reply_to -> (arg $reply_to) safe a2a_protocol::reply_ref_t. }
368
-
369
- if (arg $sender_name) == NIL
370
- {
371
- p = pending_introductions sender_id.
372
- abort "Message from an unknown sender was rejected." when p == NIL.
373
- entry = p?.
374
- queued = entry $messages.
375
- abort "Pending-introduction message queue is full; awaiting approval." when (_count queued|) >= pending_queue_cap.
376
- queued (_count queued|) -> ($text -> text, $date -> msg_date).
377
- pending_introductions sender_id -> ($name -> entry $name, $ad -> entry $ad, $messages -> queued).
378
- return [
379
- _notify_agent ($event -> $pending_message, $sender_name -> entry $name, $queued -> _count queued|),
380
- _save_state NIL
381
- ].
382
- }
383
-
384
- sender_name = (arg $sender_name) safe str.
385
- mid = deposit_message sender_id sender_name text msg_date wire_id reply_to.
386
- actions is transaction::action::type[] = [].
387
- sc monitor_copy_actions "in" sender_id text msg_date -- ( -> a)
388
- {
389
- actions (_count actions|) -> a.
390
- }
391
- actions (_count actions|) -> _notify_agent ($event -> $message_received, $sender_name -> sender_name, $msg_id -> mid, $date -> msg_date).
392
- actions (_count actions|) -> _save_state NIL.
393
- return actions.
394
- },
395
- $on_message_sent -> fn (arg: any) -> transaction::action::type[]
396
- {
397
- return monitor_copy_actions "out" ((arg $target_id) safe global_id) ((arg $text) safe str) ((arg $date) safe time).
398
- },
399
- $on_contact_removed -> fn (_: any) -> transaction::action::type[] { return []. },
400
- $on_file_received -> fn (arg: any) -> transaction::action::type[]
401
- {
402
- sender_id = (arg $sender_id) safe global_id.
403
- filename = (arg $filename) safe str.
404
- mime is str = "".
405
- if (arg $mime) != NIL { mime -> (arg $mime) safe str. }
406
- data = (arg $data) safe bin.
407
- file_date = (arg $date) safe time.
408
- wire_id is str = "".
409
- if (arg $wire_id) != NIL { wire_id -> (arg $wire_id) safe str. }
410
- reply_to is a2a_protocol::reply_ref_t+ = NIL.
411
- if (arg $reply_to) != NIL { reply_to -> (arg $reply_to) safe a2a_protocol::reply_ref_t. }
412
-
413
- // The connector serves a single KNOWN proxy contact. A file from an
414
- // unknown/unapproved sender (NIL name) is rejected — unlike messages
415
- // there is deliberately no pending-introduction byte queue (design D7).
416
- abort "File from an unknown sender was rejected." when (arg $sender_name) == NIL.
417
- sender_name = (arg $sender_name) safe str.
418
-
419
- fid = deposit_file sender_id sender_name filename mime data file_date wire_id reply_to.
420
- actions is transaction::action::type[] = [].
421
- // Metadata-only monitoring copy, same path as messages (design D5):
422
- // never the bytes — file_monitor_summary uses _binlen.
423
- sc monitor_copy_actions "in" sender_id (a2a_messaging::file_monitor_summary filename mime data) file_date -- ( -> a)
424
- {
425
- actions (_count actions|) -> a.
426
- }
427
- actions (_count actions|) -> _notify_agent ($event -> $file_received, $sender_name -> sender_name, $file_id -> fid, $date -> file_date).
428
- actions (_count actions|) -> _save_state NIL.
429
- return actions.
430
- },
431
- $on_file_sent -> fn (arg: any) -> transaction::action::type[]
432
- {
433
- // The connector is the sender here; Telegram already holds the
434
- // original, so we persist nothing (design D6). We DO emit the
435
- // metadata-only "out" monitoring copy, mirroring on_message_sent.
436
- return monitor_copy_actions "out" ((arg $target_id) safe global_id) (a2a_messaging::file_monitor_summary ((arg $filename) safe str) ((arg $mime) safe str) ((arg $data) safe bin)) ((arg $date) safe time).
437
- }
438
- ).
439
-
440
- // Wire the control plane (see MONITORING-AND-SHARED-LIBRARY-DESIGN.md
441
- // Part 4): control requests from the bound browser proxy queue in
442
- // control_inbox — NEVER the message inbox, so agent sessions don't see
443
- // them — and the notify event wakes the daemon's dispatcher. The
444
- // payload stays opaque here; sender authorization happens in the
445
- // daemon against the packet's monitoring_proxy / proxy_pending state.
446
- a2a_control::init (
447
- $app_id -> "network.ours.telegram-connector",
448
- $on_control_received -> fn (arg: any) -> transaction::action::type[]
449
- {
450
- abort "Control queue is full." when (_count control_inbox|) >= control_inbox_cap.
451
- sender_name = (arg $sender_name) safe str.
452
- control_inbox (_count control_inbox|) -> (
453
- $sender_cid -> (arg $sender_id) safe global_id,
454
- $sender_name -> sender_name,
455
- $payload -> (arg $payload) safe str,
456
- $date -> (arg $date) safe time
457
- ).
458
- return [
459
- _notify_agent ($event -> $control_request, $sender_name -> sender_name, $queued -> _count control_inbox|),
460
- _save_state NIL
461
- ].
462
- }
463
- ).
464
-
465
- // ---- capabilities manifest (core.connect) -----------------------------
466
- // THE SINGLE ENABLEMENT BOOLEAN. Flipping this to FALSE removes core.connect
467
- // from the live manifest, which (a) hides the Connect surface in any bound
468
- // control plane and (b) makes the core node-side gate in
469
- // ::a2a_messaging::ingest_connect_descriptor reject every introduction
470
- // (it reads a2a_capabilities::self_supports("core.connect"), i.e. this
471
- // manifest). There is NO other connect code in this app: the ingest
472
- // transaction lives entirely in the shared core, so enabling/disabling the
473
- // feature is exactly this flag — zero application logic.
474
- supports_connect is bool = TRUE.
475
-
476
- // The node's live self-description (a2a_capabilities::app_manifest_t),
477
- // served on ::a2a_capabilities::get_manifest and read by self_supports.
478
- // core.configuration is always present (the daemon renders its config
479
- // schema); core.connect is present iff supports_connect. Neither has a
480
- // packet-side verb handler — configuration is daemon-mediated and connect
481
- // is the dedicated core ingest tx — so $supported (below) stays empty.
482
- fn build_manifest (_: any) -> a2a_capabilities::app_manifest_t
483
- {
484
- caps is (str ->> a2a_capabilities::capability_t) = (,).
485
- caps a2a_capabilities::cap_configuration -> (
486
- $cap -> a2a_capabilities::cap_configuration,
487
- $version -> 1,
488
- $params -> "",
489
- $secrets -> (,)
490
- ).
491
- if supports_connect
492
- {
493
- caps a2a_capabilities::cap_connect -> (
494
- $cap -> a2a_capabilities::cap_connect,
495
- $version -> 1,
496
- $params -> "",
497
- $secrets -> (,)
498
- ).
499
- }
500
- // core 0.8.0/0.9.0 — end-to-end double-ratchet + its migration FSM. The
501
- // connector runs the DR-routing core unconditionally, so it always speaks
502
- // the e2e_signed_message envelope (core.e2e) and participates in the
503
- // per-connection migration handshake (core.e2e.migrate). Advertised here so
504
- // a controller's get_manifest / self_supports sees them; the peer-facing
505
- // auto-migration trigger is driven by the $advertise wire piggyback below
506
- // (self_advertises reads init's $advertise, not this describe() map).
507
- caps a2a_capabilities::cap_e2e -> (
508
- $cap -> a2a_capabilities::cap_e2e,
509
- $version -> 1,
510
- $params -> "",
511
- $secrets -> (,)
512
- ).
513
- caps a2a_capabilities::cap_e2e_migrate -> (
514
- $cap -> a2a_capabilities::cap_e2e_migrate,
515
- $version -> 1,
516
- $params -> "",
517
- $secrets -> (,)
518
- ).
519
- return (
520
- $version -> 1,
521
- $app_id -> "network.ours.telegram-connector",
522
- $name -> a2a_messaging::my_name,
523
- $description -> a2a_messaging::my_bio,
524
- $monitoring_status -> "unbound",
525
- $capabilities -> caps
526
- ).
527
- }
528
-
529
- // Wire the capabilities library. $supported lists only caps with a packet
530
- // VERB handler (init fail-fasts if any lacks one) — this app has none, so
531
- // it is empty. core.connect MUST NOT appear here: it has no verb handler
532
- // and would abort init; "supports introductions" is core.connect living in
533
- // describe()'s live $capabilities map (above), per RELEASE_NOTES §B2.
534
- a2a_capabilities::init (
535
- $describe -> build_manifest,
536
- $supported -> [],
537
- // $advertise (core 0.9.0): PROTOCOL-surface capability ids carried on the
538
- // wire piggyback ($caps in invite/restore/migration legs) -> self_caps, so
539
- // self_advertises(cap_e2e_migrate)=TRUE (which gates mig_should_trigger) AND
540
- // peers LEARN these into contact_caps. This — not the $describe manifest — is
541
- // what makes an existing contact auto-migrate to the double ratchet once both
542
- // sides advertise (§5.4). No handler needed (unlike $supported): these ids
543
- // gate traffic shaping only and never route through dispatch.
544
- //
545
- // cap_e2e_rekey (core 0.11): lets a peer REPAIR a diverged DR session with
546
- // us instead of waiting for one to re-establish by accident. A peer that
547
- // detects divergence checks peer_supports_rekey (a2a_messaging.mm:1100 at
548
- // core pin edbb11ad) on US before it will send anything at all — so while
549
- // this id was absent, three separate paths were hard-stopped against us:
550
- // maybe_init_rekey (:1211, never mints), redrive_unacked_actions (:1114,
551
- // returns []) and rekey_ping_actions (:1143, returns []). The responder is
552
- // core-side and library-routed (e2e_rekey_request_tx, :100 -> trn :3827 ->
553
- // handle_e2e_rekey_request :3751), inherited by any actor loading
554
- // a2a_messaging, so this advertisement is all that was missing.
555
- //
556
- // SAFETY — this id is a VERSION CLAIM, not just "I answer rekey": both
557
- // cap-gates above exist because a pre-0.11 peer would deposit unrecognized
558
- // duplicates on redrive and would render a $rekey_ping bootstrap AS AN APP
559
- // MESSAGE. Advertising it from a pre-0.11 core would therefore be a harmful
560
- // false yes. Checked before adding: the deployed connector packet carries
561
- // core.e2e.rekey, rekey_ping, delivered_wire, unacked_e2e and
562
- // e2e_rekey_request — i.e. its core already has receive-side wire_id dedup
563
- // and understands the ping. The npm version string (0.1.8-nightly.4 on the
564
- // running bridge) is NOT a proxy for the compiled core version; they are
565
- // different objects and only the packet answers this question.
566
- $advertise -> [ a2a_capabilities::cap_e2e, a2a_capabilities::cap_e2e_migrate,
567
- a2a_capabilities::cap_e2e_rekey ],
568
- $handlers -> (,),
569
- $on_unknown -> fn (_: any) -> transaction::action::type[] { return []. }
570
- ).
571
- }
572
-
573
- // On recreation the host injects the persisted SIGN secret as init_arg: the
574
- // hex string of the Serialize()'d secretkey_sign. Deserialize it back
575
- // (_hex_string_to_binary -> _read_or_abort) and reseed to restore the
576
- // container address (adapt #77). Fresh-create passes no arg and the
577
- // bootstrapped identity stands.
578
- trn __init arg
579
- {
580
- // Fresh create passes no init_arg — the wrapper hands __init an empty
581
- // dict (not nil), so guard on the actual string type before deserializing
582
- // the persisted SIGN secret (Serialize()-hex) and reseeding (adapt #77).
583
- if _typeof arg == "STRING" {
584
- key_storage::reseed_identity_from_secret
585
- ((_read_or_abort (_hex_string_to_binary (arg SAFE(str)))) SAFE(secretkey_sign)).
586
- }
587
- return ::transaction::success[].
588
- }
589
-
590
- // ---- message store --------------------------------------------------------
591
-
592
- trn readonly list_incoming_messages _
593
- {
594
- return inbox.
595
- }
596
-
597
- trn readonly list_incoming_files _
598
- {
599
- return file_inbox.
600
- }
601
-
602
- // Hand the agent every message it has not seen yet (status "unread") and flip
603
- // those to "processed" — the ONLY place message bodies leave the packet, and
604
- // the sole dedup point: a message is returned exactly once, so an agent that
605
- // reads and acts immediately never double-processes. CRASH WINDOW: a
606
- // "processed" body has already left; an agent that crashes after get_messages
607
- // but before acting must defer_messages to recover it (-> "unread") before gc
608
- // promotes it through "ready_to_delete" and deletes it (>= 1 gc cycle).
609
- trn get_messages _
610
- {
611
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
612
-
613
- fresh is message_t[] = [].
614
- new_inbox is message_t[] = [].
615
- sc inbox -- ( -> m)
616
- {
617
- if (m $status) == "unread"
618
- {
619
- processed_m is message_t = (
620
- $msg_id -> m $msg_id,
621
- $sender_id -> m $sender_id,
622
- $sender_name -> m $sender_name,
623
- $text -> m $text,
624
- $date -> m $date,
625
- $status -> "processed",
626
- $wire_id -> m $wire_id,
627
- $reply_to -> m $reply_to
628
- ).
629
- fresh (_count fresh|) -> m.
630
- new_inbox (_count new_inbox|) -> processed_m.
631
- }
632
- else
633
- {
634
- new_inbox (_count new_inbox|) -> m.
635
- }
636
- }
637
- inbox -> new_inbox.
638
-
639
- return transaction::success [
640
- _return_data ($messages -> fresh),
641
- _save_state NIL
642
- ].
643
- }
644
-
645
- // Hand the agent every file it has not seen (status "unread") and flip those to
646
- // "processed" — the file analogue of get_messages, and the only place file bytes
647
- // leave the packet. Same crash-window contract: a "processed" file already left;
648
- // recover with defer_files before gc reclaims it.
649
- trn get_files _
650
- {
651
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
652
-
653
- fresh is file_t[] = [].
654
- new_inbox is file_t[] = [].
655
- sc file_inbox -- ( -> f)
656
- {
657
- if (f $status) == "unread"
658
- {
659
- processed_f is file_t = (
660
- $file_id -> f $file_id,
661
- $sender_id -> f $sender_id,
662
- $sender_name -> f $sender_name,
663
- $filename -> f $filename,
664
- $mime -> f $mime,
665
- $data -> f $data,
666
- $date -> f $date,
667
- $status -> "processed",
668
- $wire_id -> f $wire_id,
669
- $reply_to -> f $reply_to
670
- ).
671
- fresh (_count fresh|) -> f.
672
- new_inbox (_count new_inbox|) -> processed_f.
673
- }
674
- else
675
- {
676
- new_inbox (_count new_inbox|) -> f.
677
- }
678
- }
679
- file_inbox -> new_inbox.
680
-
681
- return transaction::success [
682
- _return_data ($files -> fresh),
683
- _save_state NIL
684
- ].
685
- }
686
-
687
- // Two-generation garbage collection of handled messages, fired by the host on
688
- // a timer (NOT piggybacked on other transactions — that would collapse the
689
- // window under traffic). Order matters: (A) delete everything already marked
690
- // "ready_to_delete", THEN (B) promote "processed" -> "ready_to_delete". A
691
- // single pass keyed on the current status gives exactly that — a message is in
692
- // one status, so a freshly-processed message is promoted (not dropped) this
693
- // tick and only deleted on the NEXT tick, guaranteeing it survives a full
694
- // cycle (>= 1 interval) as a deferrable "ready_to_delete".
695
- trn gc _
696
- {
697
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
698
-
699
- kept is message_t[] = [].
700
- deleted is int = 0.
701
- promoted is int = 0.
702
- sc inbox -- ( -> m)
703
- {
704
- if (m $status) == "ready_to_delete"
705
- {
706
- deleted -> deleted + 1.
707
- }
708
- elif (m $status) == "processed"
709
- {
710
- kept (_count kept|) -> (
711
- $msg_id -> m $msg_id,
712
- $sender_id -> m $sender_id,
713
- $sender_name -> m $sender_name,
714
- $text -> m $text,
715
- $date -> m $date,
716
- $status -> "ready_to_delete",
717
- $wire_id -> m $wire_id,
718
- $reply_to -> m $reply_to
719
- ).
720
- promoted -> promoted + 1.
721
- }
722
- else
723
- {
724
- kept (_count kept|) -> m.
725
- }
726
- }
727
- inbox -> kept.
728
-
729
- // Same two-generation sweep over the file store: a delivered file's bytes are
730
- // reclaimed a full gc cycle after delivery, exactly like message bodies.
731
- fkept is file_t[] = [].
732
- sc file_inbox -- ( -> f)
733
- {
734
- if (f $status) == "ready_to_delete"
735
- {
736
- deleted -> deleted + 1.
737
- }
738
- elif (f $status) == "processed"
739
- {
740
- fkept (_count fkept|) -> (
741
- $file_id -> f $file_id,
742
- $sender_id -> f $sender_id,
743
- $sender_name -> f $sender_name,
744
- $filename -> f $filename,
745
- $mime -> f $mime,
746
- $data -> f $data,
747
- $date -> f $date,
748
- $status -> "ready_to_delete",
749
- $wire_id -> f $wire_id,
750
- $reply_to -> f $reply_to
751
- ).
752
- promoted -> promoted + 1.
753
- }
754
- else
755
- {
756
- fkept (_count fkept|) -> f.
757
- }
758
- }
759
- file_inbox -> fkept.
760
-
761
- return transaction::success [
762
- _return_data ($deleted -> deleted, $promoted -> promoted),
763
- _save_state NIL
764
- ].
765
- }
766
-
767
- // Put handled messages back into the queue (status -> "unread") so a different
768
- // session picks them up on its next get_messages. Restores from EITHER post-
769
- // read generation — "processed" or "ready_to_delete" — so a message stays
770
- // recoverable across a full gc cycle. The opt-in counterpart to the safe
771
- // default: forgetting to defer just means the message stays handled by you.
772
- trn defer_messages _:($msg_ids -> ids: int[])
773
- {
774
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
775
-
776
- wanted is (int ->> bool) = (,).
777
- sc ids -- ( -> id) { wanted id -> TRUE. }
778
-
779
- new_inbox is message_t[] = [].
780
- deferred is int = 0.
781
- sc inbox -- ( -> m)
782
- {
783
- if (wanted (m $msg_id)) && (((m $status) == "processed") || ((m $status) == "ready_to_delete"))
784
- {
785
- new_inbox (_count new_inbox|) -> (
786
- $msg_id -> m $msg_id,
787
- $sender_id -> m $sender_id,
788
- $sender_name -> m $sender_name,
789
- $text -> m $text,
790
- $date -> m $date,
791
- $status -> "unread",
792
- $wire_id -> m $wire_id,
793
- $reply_to -> m $reply_to
794
- ).
795
- deferred -> deferred + 1.
796
- }
797
- else
798
- {
799
- new_inbox (_count new_inbox|) -> m.
800
- }
801
- }
802
- inbox -> new_inbox.
803
-
804
- return transaction::success [
805
- _return_data ($deferred -> deferred),
806
- _save_state NIL
807
- ].
808
- }
809
-
810
- // Put handled files back into the queue (status -> "unread"), restoring from
811
- // either post-read generation. The file analogue of defer_messages.
812
- trn defer_files _:($file_ids -> ids: int[])
813
- {
814
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
815
-
816
- wanted is (int ->> bool) = (,).
817
- sc ids -- ( -> id) { wanted id -> TRUE. }
818
-
819
- new_inbox is file_t[] = [].
820
- deferred is int = 0.
821
- sc file_inbox -- ( -> f)
822
- {
823
- if (wanted (f $file_id)) && (((f $status) == "processed") || ((f $status) == "ready_to_delete"))
824
- {
825
- new_inbox (_count new_inbox|) -> (
826
- $file_id -> f $file_id,
827
- $sender_id -> f $sender_id,
828
- $sender_name -> f $sender_name,
829
- $filename -> f $filename,
830
- $mime -> f $mime,
831
- $data -> f $data,
832
- $date -> f $date,
833
- $status -> "unread",
834
- $wire_id -> f $wire_id,
835
- $reply_to -> f $reply_to
836
- ).
837
- deferred -> deferred + 1.
838
- }
839
- else
840
- {
841
- new_inbox (_count new_inbox|) -> f.
842
- }
843
- }
844
- file_inbox -> new_inbox.
845
-
846
- return transaction::success [
847
- _return_data ($deferred -> deferred),
848
- _save_state NIL
849
- ].
850
- }
851
-
852
- // ---- local contact book ---------------------------------------------------
853
- // The book itself lives HOST-SIDE (wrapper-local file, remote peers have no
854
- // path to it) and stores only public address material — essentially a stored
855
- // multi-use invite. It bypasses invite generation/delivery, NOT the key
856
- // exchange: connecting still runs the normal encrypted_channel handshake.
857
- // Authorization is per attempt: the host's registrar packet mints a fresh,
858
- // short-lived, registrar-signed introduction credential for each connect, and
859
- // the target verifies it against its pinned registrar keys. An external peer
860
- // can never produce one, so the local boundary holds cryptographically.
861
-
862
- trn readonly export_address_document _
863
- {
864
- return (_write address_document::get_my_address_document()).
865
- }
866
-
867
- // Export the root SIGN secret so the host can persist it (identity.key) and
868
- // reseed a recreated packet to the same address across upgrades (adapt #77).
869
- trn readonly export_signing_secret _
870
- {
871
- return key_storage::export_identity_signing_secret().
872
- }
873
-
874
- trn pin_registrar _:($registrar_ad -> registrar_ad_blob: bin, $replace -> replace: bool+)
875
- {
876
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
877
-
878
- ad = (_read_or_abort registrar_ad_blob) safe address_document_types::t_address_document.
879
- if registrar_ad != NIL
880
- {
881
- // Idempotent re-pin of the same keys is a no-op; CHANGING the pinned
882
- // keys is a deliberate act and must be requested explicitly, so no
883
- // future internal-path code can substitute a registrar silently.
884
- if (_value_id (registrar_ad? $identity $key_list)) == (_value_id (ad $identity $key_list))
885
- {
886
- return transaction::success [
887
- _return_data ($pinned -> TRUE, $changed -> FALSE)
888
- ].
889
- }
890
- abort "A different registrar key list is already pinned; pass $replace -> TRUE to overwrite." when replace == NIL || replace? != TRUE.
891
- }
892
- registrar_ad -> ad.
893
- return transaction::success [
894
- _return_data ($pinned -> TRUE, $changed -> TRUE),
895
- _save_state NIL
896
- ].
897
- }
898
-
899
- trn set_local_policy _:($auto_accept -> auto_accept: bool)
900
- {
901
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
902
- local_auto_accept -> auto_accept.
903
- return transaction::success [
904
- _return_data ($auto_accept -> auto_accept),
905
- _save_state NIL
906
- ].
907
- }
908
-
909
- // Mint an introduction credential. Only meaningful on the host's REGISTRAR
910
- // packet: targets verify the signature against their pinned registrar keys,
911
- // so a credential minted by any other packet simply fails verification.
912
- // Stateless — nothing to save. iat is stamped with transaction time so mint
913
- // and verify use the same clock domain.
914
- trn mint_introduction _:($joiner_ad -> joiner_ad_blob: bin, $target_ad -> target_ad_blob: bin)
915
- {
916
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
917
-
918
- joiner_ad = (_read_or_abort joiner_ad_blob) safe address_document_types::t_address_document.
919
- target_ad = (_read_or_abort target_ad_blob) safe address_document_types::t_address_document.
920
- intro is a2a_protocol::intro_t = (
921
- $version -> 1,
922
- $joiner_cid -> joiner_ad $identity $container_id,
923
- $joiner_ad_hash -> _value_id joiner_ad,
924
- $target_cid -> target_ad $identity $container_id,
925
- $iat -> (current_transaction_info::get_transaction_time())?,
926
- $nonce -> _new_id "ours local introduction"
927
- ).
928
- signed is a2a_protocol::signed_intro_t = ($i -> intro, $s -> key_storage::default_sign (_value_id intro)).
929
- return transaction::success [
930
- _return_data ($intro -> (_write signed))
931
- ].
932
- }
933
-
934
- // Sign a contact-book entry (registrar packet only, same caveat as above).
935
- // Makes the host-side book file tamper-evident: senders re-derive this record
936
- // from the entry they read and verify the signature before connecting.
937
- trn sign_book_entry _:($name -> name: str, $ad -> ad_blob: bin)
938
- {
939
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
940
-
941
- ad = (_read_or_abort ad_blob) safe address_document_types::t_address_document.
942
- entry is a2a_protocol::book_entry_t = ($version -> 1, $name -> name, $ad_hash -> _value_id ad).
943
- return transaction::success [
944
- _return_data ($sig -> (_write (key_storage::default_sign (_value_id entry))))
945
- ].
946
- }
947
-
948
- // Connect to a same-host peer found in the local contact book: verify the
949
- // book entry's registrar signature, register the peer as a contact, then
950
- // introduce myself over the encrypted channel — carrying the credential the
951
- // host just minted for this attempt, plus (optionally) the first message so
952
- // introduction + first delivery are one atomic transaction on the target
953
- // (no introduce-vs-message ordering race).
954
- trn connect_local _:($name -> name: str, $target_ad -> target_ad_blob: bin, $intro -> intro_blob: bin, $entry_sig -> entry_sig_blob: bin, $text -> text: str+)
955
- {
956
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
957
- abort "No registrar pinned — the local contact book is unavailable for this identity." when registrar_ad == NIL.
958
-
959
- target_ad = (_read_or_abort target_ad_blob) safe address_document_types::t_address_document.
960
- target_id = target_ad $identity $container_id.
961
- abort "This contact-book entry is your own identity." when target_id == _get_container_id().
962
-
963
- entry is a2a_protocol::book_entry_t = ($version -> 1, $name -> name, $ad_hash -> _value_id target_ad).
964
- entry_sig = (_read_or_abort entry_sig_blob) safe crypto_signature.
965
- abort "Contact-book entry failed registrar verification." when key_storage::check_signature_new_container (_value_id entry) entry_sig (registrar_ad? $identity $key_list) != TRUE.
966
-
967
- a2a_messaging::contacts target_id -> ($name -> name, $container_id -> target_id).
968
- a2a_messaging::peer_ads target_id -> target_ad.
969
-
970
- my_self_name = a2a_messaging::my_name.
971
- my_ad = address_document::get_my_address_document().
972
- return encrypted_channel::execute_transaction target_id (fn (_) -> transaction::results::type {
973
- return transaction::success [
974
- encrypted_channel::send_encrypted_tx target_id (
975
- $name -> "::actor::local_introduce",
976
- $targ -> ($joiner_name -> my_self_name, $joiner_ad -> my_ad, $intro -> intro_blob, $text -> text)
977
- ),
978
- _return_data ($connected -> name, $container_id -> target_id),
979
- _save_state NIL
980
- ].
981
- }).
982
- }
983
-
984
- trn approve_introduction _:($contact -> ref: str)
985
- {
986
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
987
-
988
- pid = resolve_pending ref.
989
- entry = (pending_introductions pid)?.
990
- a2a_messaging::contacts pid -> ($name -> entry $name, $container_id -> pid).
991
- a2a_messaging::peer_ads pid -> entry $ad.
992
-
993
- queued = entry $messages.
994
- flushed is int = 0.
995
- sc queued -- ( -> m)
996
- {
997
- deposit_message pid (entry $name) (m $text) (m $date) "" no_reply.
998
- flushed -> flushed + 1.
999
- }
1000
- delete pending_introductions pid.
1001
-
1002
- return transaction::success [
1003
- _return_data ($approved -> entry $name, $container_id -> pid, $flushed -> flushed),
1004
- _save_state NIL
1005
- ].
1006
- }
1007
-
1008
- trn reject_introduction _:($contact -> ref: str)
1009
- {
1010
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
1011
-
1012
- pid = resolve_pending ref.
1013
- entry = (pending_introductions pid)?.
1014
- dropped = _count (entry $messages)|.
1015
- delete pending_introductions pid.
1016
-
1017
- return transaction::success [
1018
- _return_data ($rejected -> entry $name, $container_id -> pid, $dropped_messages -> dropped),
1019
- _save_state NIL
1020
- ].
1021
- }
1022
-
1023
- trn readonly list_pending_introductions _
1024
- {
1025
- out is (global_id ->> pending_view_t) = (,).
1026
- sc pending_introductions -- (cid -> p)
1027
- {
1028
- out cid -> ($name -> p $name, $queued -> _count (p $messages)|).
1029
- }
1030
- return out.
1031
- }
1032
-
1033
- // ---- identity hierarchy ---------------------------------------------------
1034
- // Two layers (see IDENTITY-HIERARCHY-DESIGN.md): one ROOT identity per host
1035
- // (represents the person; structurally just a packet with no delegation
1036
- // cert) and ROLE identities under it, each carrying a cert signed by the
1037
- // root. The host drives issuance: it asks the root packet to sign a cert
1038
- // (sign_delegation) and export its profile (export_root_profile), then
1039
- // stores both into the role packet (set_delegation). Intra-root peers
1040
- // (Ring 1) connect via connect_sibling/sibling_introduce with cert-based
1041
- // auto-accept — no registrar credential, no approval queue, and it works
1042
- // for roles that are not published in the local contact book.
1043
-
1044
- // Sign a delegation certificate for a role (meaningful on the ROOT packet:
1045
- // verifiers check the signature against the root's keys, so a cert minted
1046
- // by any other packet fails verification). Stateless — nothing to save.
1047
- trn sign_delegation _:($role_ad -> role_ad_blob: bin, $role_id -> role_id: str)
1048
- {
1049
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
1050
- abort "Only a root identity can sign delegation certificates." when a2a_messaging::delegation_cert != NIL.
1051
-
1052
- role_ad = (_read_or_abort role_ad_blob) safe address_document_types::t_address_document.
1053
- role_cid = role_ad $identity $container_id.
1054
- abort "Cannot issue a delegation certificate to myself." when role_cid == _get_container_id().
1055
-
1056
- core is a2a_protocol::delegation_core_t = (
1057
- $version -> 1,
1058
- $role_cid -> role_cid,
1059
- $role_ad_hash -> _value_id role_ad,
1060
- $role_id -> role_id,
1061
- $root_cid -> _get_container_id(),
1062
- $issued_at -> (current_transaction_info::get_transaction_time())?
1063
- ).
1064
- cert is a2a_protocol::delegation_cert_t = ($c -> core, $s -> key_storage::default_sign (_value_id core)).
1065
- return transaction::success [
1066
- _return_data ($cert -> (_write cert))
1067
- ].
1068
- }
1069
-
1070
- // Export my self-signed root profile (root packet only). Roles embed this
1071
- // in the invites they generate, so external peers learn who is behind the
1072
- // role; it carries my key list so the whole chain verifies standalone.
1073
- trn export_root_profile _
1074
- {
1075
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
1076
- abort "Only a root identity can export a root profile." when a2a_messaging::delegation_cert != NIL.
1077
-
1078
- my_ad = address_document::get_my_address_document().
1079
- core is a2a_protocol::root_profile_core_t = (
1080
- $version -> 1,
1081
- $root_cid -> _get_container_id(),
1082
- $name -> a2a_messaging::my_name,
1083
- $bio -> a2a_messaging::my_bio,
1084
- $keys -> my_ad $identity $key_list
1085
- ).
1086
- profile is a2a_protocol::root_profile_t = ($p -> core, $s -> key_storage::default_sign (_value_id core)).
1087
- return transaction::success [
1088
- _return_data ($profile -> (_write profile))
1089
- ].
1090
- }
1091
-
1092
- // Store my delegation cert + root material (role packet, host-fired after
1093
- // the root signed the cert). Everything is verified before it is stored:
1094
- // a cert that does not name me, does not match my keys, or was not signed
1095
- // by the carried root is rejected. Re-running with fresh material is the
1096
- // refresh path (e.g. the root's bio changed -> new profile, same root).
1097
- trn set_delegation _:($cert -> cert_blob: bin, $root_ad -> root_ad_blob: bin, $root_profile -> rp_blob: bin)
1098
- {
1099
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
1100
-
1101
- cert = (_read_or_abort cert_blob) safe a2a_protocol::delegation_cert_t.
1102
- new_root_ad = (_read_or_abort root_ad_blob) safe address_document_types::t_address_document.
1103
- rp = (_read_or_abort rp_blob) safe a2a_protocol::root_profile_t.
1104
-
1105
- abort "Unsupported delegation certificate version." when (cert $c $version) != 1.
1106
- abort "This delegation certificate was issued to a different identity." when (cert $c $role_cid) != _get_container_id().
1107
- my_ad = address_document::get_my_address_document().
1108
- abort "This delegation certificate does not match my address document." when (cert $c $role_ad_hash) != (_value_id my_ad).
1109
- abort "The root address document does not match the certificate's root." when (new_root_ad $identity $container_id) != (cert $c $root_cid).
1110
- abort "The delegation certificate was not signed by the root." when key_storage::check_signature_new_container (_value_id (cert $c)) (cert $s) (new_root_ad $identity $key_list) != TRUE.
1111
- abort "Unsupported root profile version." when (rp $p $version) != 1.
1112
- abort "The root profile does not match the certificate's root." when (rp $p $root_cid) != (cert $c $root_cid).
1113
- abort "The root profile's key list does not match the root's address document." when (_value_id (rp $p $keys)) != (_value_id (new_root_ad $identity $key_list)).
1114
- abort "The root profile signature is invalid." when key_storage::check_signature_new_container (_value_id (rp $p)) (rp $s) (new_root_ad $identity $key_list) != TRUE.
1115
-
1116
- a2a_messaging::delegation_cert -> cert.
1117
- a2a_messaging::root_ad -> new_root_ad.
1118
- a2a_messaging::root_profile -> rp.
1119
-
1120
- return transaction::success [
1121
- _return_data ($delegated -> TRUE, $root_cid -> (_str (cert $c $root_cid)), $role_id -> cert $c $role_id),
1122
- _save_state NIL
1123
- ].
1124
- }
1125
-
1126
- trn readonly describe_identity _
1127
- {
1128
- if a2a_messaging::delegation_cert == NIL
1129
- {
1130
- return ($name -> a2a_messaging::my_name, $bio -> a2a_messaging::my_bio, $has_cert -> FALSE, $role_id -> "", $root_cid -> "", $root_name -> "", $monitoring_enabled -> monitoring_enabled).
1131
- }
1132
- cert = a2a_messaging::delegation_cert?.
1133
- rname is str = "".
1134
- if a2a_messaging::root_profile != NIL { rname -> a2a_messaging::root_profile? $p $name. }
1135
- return (
1136
- $name -> a2a_messaging::my_name,
1137
- $bio -> a2a_messaging::my_bio,
1138
- $has_cert -> TRUE,
1139
- $role_id -> cert $c $role_id,
1140
- $root_cid -> (_str (cert $c $root_cid)),
1141
- $root_name -> rname,
1142
- $monitoring_enabled -> monitoring_enabled
1143
- ).
1144
- }
1145
-
1146
- // Connect to an intra-root sibling (Ring 1): register it as a contact and
1147
- // introduce myself over the encrypted channel, presenting my delegation
1148
- // cert (NIL when I am the root itself — the channel proves I control the
1149
- // root's keys, which is all a role needs to recognize its root). Like
1150
- // connect_local, the optional first message rides the introduction so
1151
- // introduce + first delivery are one atomic transaction on the target.
1152
- trn connect_sibling _:($name -> name: str, $target_ad -> target_ad_blob: bin, $text -> text: str+)
1153
- {
1154
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
1155
-
1156
- target_ad = (_read_or_abort target_ad_blob) safe address_document_types::t_address_document.
1157
- target_id = target_ad $identity $container_id.
1158
- abort "This sibling is your own identity." when target_id == _get_container_id().
1159
-
1160
- cert_blob is bin+ = NIL.
1161
- if a2a_messaging::delegation_cert != NIL { cert_blob -> (_write a2a_messaging::delegation_cert?). }
1162
-
1163
- a2a_messaging::contacts target_id -> ($name -> name, $container_id -> target_id).
1164
- a2a_messaging::peer_ads target_id -> target_ad.
1165
- // Record the target's root linkage: a sibling shares my root by
1166
- // definition (the receiving side verifies the converse independently).
1167
- if a2a_messaging::delegation_cert != NIL && a2a_messaging::root_profile != NIL
1168
- {
1169
- a2a_messaging::contact_roots target_id -> ($root_cid -> a2a_messaging::delegation_cert? $c $root_cid, $root_name -> a2a_messaging::root_profile? $p $name, $role_id -> name).
1170
- }
1171
- else
1172
- {
1173
- a2a_messaging::contact_roots target_id -> ($root_cid -> _get_container_id(), $root_name -> a2a_messaging::my_name, $role_id -> name).
1174
- }
1175
-
1176
- my_self_name = a2a_messaging::my_name.
1177
- my_ad = address_document::get_my_address_document().
1178
- return encrypted_channel::execute_transaction target_id (fn (_) -> transaction::results::type {
1179
- return transaction::success [
1180
- encrypted_channel::send_encrypted_tx target_id (
1181
- $name -> "::actor::sibling_introduce",
1182
- $targ -> ($joiner_name -> my_self_name, $joiner_ad -> my_ad, $cert -> cert_blob, $text -> text)
1183
- ),
1184
- _return_data ($connected -> name, $container_id -> target_id),
1185
- _save_state NIL
1186
- ].
1187
- }).
1188
- }
1189
-
1190
- // ---- monitoring + control plane -------------------------------------------
1191
- // (see MONITORING-AND-SHARED-LIBRARY-DESIGN.md). A monitored ROLE reports
1192
- // every message it sends/receives to its ROOT (the monitor_copy_actions
1193
- // branches in the storage hooks above); the root queues the copies and the
1194
- // host forwards them to a human proxy bound via 6-digit-code verification.
1195
- // The proxy's control requests (create agent, update role, …) queue in
1196
- // control_inbox and are executed by the host daemon.
1197
-
1198
- trn readonly get_monitoring_status _
1199
- {
1200
- pending is bool = FALSE.
1201
- if proxy_pending != NIL { pending -> TRUE. }
1202
- proxy_out is str = "".
1203
- if monitoring_proxy != NIL { proxy_out -> _str (monitoring_proxy? $proxy_cid). }
1204
- return (
1205
- $monitoring_enabled -> monitoring_enabled,
1206
- $proxy_cid -> proxy_out,
1207
- $proxy_pending -> pending,
1208
- $copies_queued -> _count monitoring_inbox|,
1209
- $control_queued -> _count control_inbox|
1210
- ).
1211
- }
1212
-
1213
- // Sign a monitoring authorization for a role (ROOT packet only — the role
1214
- // verifies the signature against its pinned root keys, so an auth minted
1215
- // by any other packet fails). Stateless, mirrors sign_delegation.
1216
- trn sign_monitoring_auth _:($role_ad -> role_ad_blob: bin, $enabled -> enabled: bool)
1217
- {
1218
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
1219
- abort "Only a root identity can sign monitoring authorizations." when a2a_messaging::delegation_cert != NIL.
1220
-
1221
- role_ad = (_read_or_abort role_ad_blob) safe address_document_types::t_address_document.
1222
- core is monitoring_auth_core_t = (
1223
- $version -> 1,
1224
- $role_cid -> role_ad $identity $container_id,
1225
- $enabled -> enabled,
1226
- $issued_at -> (current_transaction_info::get_transaction_time())?
1227
- ).
1228
- auth is monitoring_auth_t = ($c -> core, $s -> key_storage::default_sign (_value_id core)).
1229
- return transaction::success [
1230
- _return_data ($auth -> (_write auth))
1231
- ].
1232
- }
1233
-
1234
- // Store a verified monitoring flag (ROLE packet, host-fired after the root
1235
- // signed the auth). An auth that does not name me or was not signed by my
1236
- // root is rejected — so even a compromised host process cannot silently
1237
- // flip monitoring without the root packet's keys.
1238
- trn set_monitoring _:($auth -> auth_blob: bin)
1239
- {
1240
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
1241
- abort "Only a delegated role can be monitored." when a2a_messaging::delegation_cert == NIL || a2a_messaging::root_ad == NIL.
1242
-
1243
- auth = (_read_or_abort auth_blob) safe monitoring_auth_t.
1244
- abort "Unsupported monitoring authorization version." when (auth $c $version) != 1.
1245
- abort "This monitoring authorization was issued to a different identity." when (auth $c $role_cid) != _get_container_id().
1246
- abort "The monitoring authorization was not signed by my root." when key_storage::check_signature_new_container (_value_id (auth $c)) (auth $s) (a2a_messaging::root_ad? $identity $key_list) != TRUE.
1247
-
1248
- monitoring_enabled -> auth $c $enabled.
1249
- return transaction::success [
1250
- _return_data ($monitoring_enabled -> monitoring_enabled),
1251
- _save_state NIL
1252
- ].
1253
- }
1254
-
1255
- // A monitored role reports one message copy (ROOT packet, inbound). Only
1256
- // accepted from a verified role of THIS root (the contact_roots linkage
1257
- // recorded by sibling_introduce), and the copy must name its actual sender
1258
- // — a role cannot forge copies on another role's behalf.
1259
- trn receive_monitoring_copy _:($copy -> copy: monitoring_copy_t)
1260
- {
1261
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::external,).
1262
- encrypted_channel::check_encrypted_or_abort().
1263
-
1264
- sender_id = current_transaction_info::get_external_envelope_or_abort() $from.
1265
- link = a2a_messaging::contact_roots sender_id.
1266
- abort "Monitoring copies are only accepted from my own roles." when link == NIL || (link? $root_cid) != _get_container_id().
1267
- abort "Monitoring copy does not name its sender as the source." when (copy $source_cid) != sender_id.
1268
- abort "Unsupported monitoring copy version." when (copy $version) != 1.
1269
-
1270
- // Capped queue, oldest first out: if no proxy drains the root, recent
1271
- // traffic wins over old.
1272
- if (_count monitoring_inbox|) >= monitoring_inbox_cap
1273
- {
1274
- trimmed is monitoring_copy_t[] = [].
1275
- i is int = 0.
1276
- sc monitoring_inbox -- ( -> m)
1277
- {
1278
- if i > 0 { trimmed (_count trimmed|) -> m. }
1279
- i -> i + 1.
1280
- }
1281
- monitoring_inbox -> trimmed.
1282
- }
1283
- monitoring_inbox (_count monitoring_inbox|) -> copy.
1284
-
1285
- return transaction::success [
1286
- _notify_agent ($event -> $monitoring_copy, $source_name -> copy $source_name, $queued -> _count monitoring_inbox|),
1287
- _save_state NIL
1288
- ].
1289
- }
1290
-
1291
- // Drain the queued monitoring copies (ROOT packet, host-fired before
1292
- // forwarding to the bound proxy). Cleared on read, like get_messages.
1293
- trn get_monitoring_copies _
1294
- {
1295
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
1296
-
1297
- copies = monitoring_inbox.
1298
- monitoring_inbox -> [].
1299
- return transaction::success [
1300
- _return_data ($copies -> copies),
1301
- _save_state NIL
1302
- ].
1303
- }
1304
-
1305
- // Drain the queued control requests (ROOT packet, host-fired by the
1306
- // control dispatcher). Cleared on read.
1307
- trn get_control_requests _
1308
- {
1309
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
1310
-
1311
- reqs = control_inbox.
1312
- control_inbox -> [].
1313
- return transaction::success [
1314
- _return_data ($requests -> reqs),
1315
- _save_state NIL
1316
- ].
1317
- }
1318
-
1319
- // Start a proxy binding (ROOT packet, host-fired): remember the code the
1320
- // host generated (MUFL has no random source) for one specific contact.
1321
- // Restarting overwrites any previous pending binding.
1322
- trn set_proxy_pending _:($code -> code: str, $proxy -> proxy_ref: str)
1323
- {
1324
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
1325
- abort "Only a root identity can bind a monitoring proxy." when a2a_messaging::delegation_cert != NIL.
1326
-
1327
- pid = a2a_messaging::resolve_contact proxy_ref.
1328
- proxy_pending -> (
1329
- $code -> code,
1330
- $proxy_cid -> pid,
1331
- $created_at -> (current_transaction_info::get_transaction_time())?,
1332
- $attempts -> 0
1333
- ).
1334
- return transaction::success [
1335
- _return_data ($pending -> TRUE, $proxy_cid -> (_str pid)),
1336
- _save_state NIL
1337
- ].
1338
- }
1339
-
1340
- // Verify a proxy's code attempt (ROOT packet, host-fired when a `bind`
1341
- // control request arrives). Failures are returned as DATA — not aborts —
1342
- // so the attempt counter and expiry clearing persist atomically; an abort
1343
- // would roll them back and reopen the brute-force window.
1344
- trn verify_proxy_code _:($code -> code: str, $sender -> sender_ref: str)
1345
- {
1346
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
1347
-
1348
- if proxy_pending == NIL
1349
- {
1350
- return transaction::success [ _return_data ($verified -> FALSE, $reason -> "no_pending") ].
1351
- }
1352
- p = proxy_pending?.
1353
- now = (current_transaction_info::get_transaction_time())?.
1354
-
1355
- if (_substract_seconds now (p $created_at)) > proxy_code_max_age_seconds
1356
- {
1357
- proxy_pending -> NIL.
1358
- return transaction::success [
1359
- _return_data ($verified -> FALSE, $reason -> "expired"),
1360
- _save_state NIL
1361
- ].
1362
- }
1363
-
1364
- sid = a2a_messaging::resolve_contact sender_ref.
1365
- if sid != (p $proxy_cid)
1366
- {
1367
- // Not the contact this binding was started for: reject without
1368
- // burning an attempt (the code was never compared).
1369
- return transaction::success [ _return_data ($verified -> FALSE, $reason -> "wrong_sender") ].
1370
- }
1371
-
1372
- if code != (p $code)
1373
- {
1374
- attempts = (p $attempts) + 1.
1375
- if attempts >= proxy_max_attempts
1376
- {
1377
- proxy_pending -> NIL.
1378
- return transaction::success [
1379
- _return_data ($verified -> FALSE, $reason -> "too_many_attempts"),
1380
- _save_state NIL
1381
- ].
1382
- }
1383
- proxy_pending -> (
1384
- $code -> p $code,
1385
- $proxy_cid -> p $proxy_cid,
1386
- $created_at -> p $created_at,
1387
- $attempts -> attempts
1388
- ).
1389
- return transaction::success [
1390
- _return_data ($verified -> FALSE, $reason -> "wrong_code", $attempts_left -> proxy_max_attempts - attempts),
1391
- _save_state NIL
1392
- ].
1393
- }
1394
-
1395
- monitoring_proxy -> ($proxy_cid -> sid, $bound_at -> now).
1396
- proxy_pending -> NIL.
1397
- return transaction::success [
1398
- _return_data ($verified -> TRUE, $proxy_cid -> (_str sid)),
1399
- _save_state NIL
1400
- ].
1401
- }
1402
-
1403
- // Drop the proxy binding (and any in-flight code verification).
1404
- trn clear_monitoring_proxy _
1405
- {
1406
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
1407
-
1408
- monitoring_proxy -> NIL.
1409
- proxy_pending -> NIL.
1410
- return transaction::success [
1411
- _return_data ($cleared -> TRUE),
1412
- _save_state NIL
1413
- ].
1414
- }
1415
-
1416
- // ---- upgrade: state export / import -------------------------------------
1417
- // The host persists state by calling export_state (readonly) and serializing
1418
- // the returned value to a code-independent blob. On a code upgrade it also
1419
- // persists the root SIGN secret (export_signing_secret) and recreates the
1420
- // packet with that secret injected as init_arg; __init reseeds the identity
1421
- // from it (reseed_identity_from_secret), which preserves the container
1422
- // address regardless of the seed phrase or key-derivation used to recreate
1423
- // the packet. The blob is then replayed through import_state.
1424
- //
1425
- // The packet-level snapshot is NOT used for upgrades: it is bound to the unit
1426
- // code hash, so a new .muflo cannot load an old snapshot. This data blob is.
1427
- //
1428
- // Core (contact / profile / hierarchy / DR-session) state is carried WHOLE under
1429
- // $core: export_core_state owns its OWN field set, so any field the shared core
1430
- // adds — most importantly $e2e_sessions (the DR ratchet pickles that a manual
1431
- // per-field projection silently DROPPED, losing messages across a reload) — rides
1432
- // forward automatically, and the core's monitoring keys never collide with the
1433
- // APP-level monitoring keys we still own below (they share both names AND shapes).
1434
- // The blob stays code-independent; import_state migrates the pre-namespacing FLAT
1435
- // shape forward (see there). Mirrors ours-mcp's actor exactly.
1436
-
1437
- trn readonly export_state _
1438
- {
1439
- return (
1440
- $app_format_version -> 1,
1441
- $core -> a2a_messaging::export_core_state NIL,
1442
- // ---- app-owned state (route inbox + files + local book + monitoring) ----
1443
- $inbox -> inbox,
1444
- $next_msg_seq -> next_msg_seq,
1445
- $file_inbox -> file_inbox,
1446
- $next_file_seq -> next_file_seq,
1447
- $registrar_ad -> registrar_ad,
1448
- $local_auto_accept -> local_auto_accept,
1449
- // Nonces are exported so a restart does not reopen the replay window
1450
- // for still-fresh credentials; stale ones are purged lazily anyway.
1451
- $seen_nonces -> seen_nonces,
1452
- $pending_introductions -> pending_introductions,
1453
- // App-level (role->root) monitoring — a DISTINCT mechanism from core's
1454
- // forced monitoring. Stays app-owned and top-level; it must NEVER be fed
1455
- // into import_core_state (that would arm core's hidden monitoring_proxy,
1456
- // which the app cannot disarm). See import_state's legacy branch.
1457
- $monitoring_enabled -> monitoring_enabled,
1458
- $monitoring_inbox -> monitoring_inbox,
1459
- $proxy_pending -> proxy_pending,
1460
- $monitoring_proxy -> monitoring_proxy,
1461
- $control_inbox -> control_inbox
1462
- ).
1463
- }
1464
-
1465
- trn import_state data: any
1466
- {
1467
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
1468
-
1469
- // App-level format stamp (absent == 0, every pre-stamp blob). Same contract
1470
- // as the core stamp (see a2a_messaging::import_core_state): additive fields
1471
- // stay optional reads; a future BREAKING app-blob change dispatches here.
1472
- app_fmt is int = 0.
1473
- if (data $app_format_version) != NIL { app_fmt -> (data $app_format_version) safe int. }
1474
- abort "App state blob format_version " + (_str app_fmt) + " is newer than this code (supports up to 1) — upgrade ours-tg-connector before importing." when app_fmt > 1.
1475
-
1476
- // Core fields (contacts/profile/hierarchy/DR-sessions) — validated and restored
1477
- // by the shared library, which also replays every peer's address document
1478
- // through process_address_document so encrypted channels keep working after the
1479
- // upgrade with no re-handshake, and parks $e2e_sessions for the staged commit
1480
- // below. The current export namespaces core under $core, so the core owns its
1481
- // own field set and its monitoring keys never collide with the app's. A
1482
- // PRE-namespacing FLAT blob carries the core fields at the top level — migrate it
1483
- // by feeding import_core_state ONLY the genuine shared fields. We deliberately
1484
- // OMIT proxy_pending / monitoring_proxy on the legacy path: in a flat blob those
1485
- // keys hold the APP-level monitoring state (same names AND shapes as core's), and
1486
- // feeding them to import_core_state would arm core's hidden forced-monitoring
1487
- // proxy — which the app can NEVER disarm. Mirrors ours-mcp's actor exactly.
1488
- if (data $core) != NIL
1489
- {
1490
- a2a_messaging::import_core_state (data $core).
1491
- }
1492
- else
1493
- {
1494
- a2a_messaging::import_core_state (
1495
- $my_name -> data $my_name,
1496
- $contacts -> data $contacts,
1497
- $pending_invites -> data $pending_invites,
1498
- $peer_ads -> data $peer_ads,
1499
- $my_bio -> data $my_bio,
1500
- $delegation_cert -> data $delegation_cert,
1501
- $root_ad -> data $root_ad,
1502
- $root_profile -> data $root_profile,
1503
- $contact_roots -> data $contact_roots
1504
- ).
1505
- }
1506
-
1507
- // The inbox + next_msg_seq are the only parts the message-lifecycle changes
1508
- // touched. A pre-lifecycle blob has no $next_msg_seq and inbox entries with
1509
- // no id/status — MIGRATE it forward (the whole point of code-independent
1510
- // state is that an old export upgrades, never resets): assign each legacy
1511
- // message a sequential id and status "unread", and seed next_msg_seq past
1512
- // them. A current-shape blob is loaded as-is except the gc vocabulary bump
1513
- // ("read" -> "processed", see below).
1514
- if (data $next_msg_seq) == NIL
1515
- {
1516
- legacy_inbox = (data $inbox) safe (legacy_message_t[]).
1517
- migrated is message_t[] = [].
1518
- seq is int = 1.
1519
- sc legacy_inbox -- ( -> m)
1520
- {
1521
- migrated (_count migrated|) -> (
1522
- $msg_id -> seq,
1523
- $sender_id -> m $sender_id,
1524
- $sender_name -> m $sender_name,
1525
- $text -> m $text,
1526
- $date -> m $date,
1527
- $status -> "unread",
1528
- $wire_id -> "",
1529
- $reply_to -> NIL
1530
- ).
1531
- seq -> seq + 1.
1532
- }
1533
- inbox -> migrated.
1534
- next_msg_seq -> seq.
1535
- }
1536
- else
1537
- {
1538
- // Current-shape blob, read field-by-field (NOT a strict message_t[]
1539
- // cast) so a pre-1.4 blob — whose messages have no $wire_id/$reply_to
1540
- // — imports without aborting on the now-required $wire_id. Two
1541
- // forward-migrations: the old "read" status -> "processed" (else the
1542
- // message is stuck: never returned, gc'd, or deferred), and absent
1543
- // wire_id/reply_to default to "" / NIL.
1544
- upgraded is message_t[] = [].
1545
- sc (data $inbox) -- ( -> m)
1546
- {
1547
- mstatus = (((m $status) safe str) == "read" ?? "processed" ; (m $status) safe str).
1548
- mwire is str = "".
1549
- if (m $wire_id) != NIL { mwire -> (m $wire_id) safe str. }
1550
- mreply is a2a_protocol::reply_ref_t+ = NIL.
1551
- if (m $reply_to) != NIL { mreply -> (m $reply_to) safe a2a_protocol::reply_ref_t. }
1552
- upgraded (_count upgraded|) -> (
1553
- $msg_id -> (m $msg_id) safe int,
1554
- $sender_id -> (m $sender_id) safe global_id,
1555
- $sender_name -> (m $sender_name) safe str,
1556
- $text -> (m $text) safe str,
1557
- $date -> (m $date) safe time,
1558
- $status -> mstatus,
1559
- $wire_id -> mwire,
1560
- $reply_to -> mreply
1561
- ).
1562
- }
1563
- inbox -> upgraded.
1564
- next_msg_seq -> (data $next_msg_seq) safe int.
1565
- }
1566
-
1567
- // Local-contact-book state arrived after the original schema — every
1568
- // field is optional in old blobs and defaults stay in place when absent.
1569
- if (data $registrar_ad) != NIL
1570
- {
1571
- registrar_ad -> (data $registrar_ad) safe address_document_types::t_address_document.
1572
- }
1573
- if (data $local_auto_accept) != NIL
1574
- {
1575
- local_auto_accept -> (data $local_auto_accept) safe bool.
1576
- }
1577
- if (data $seen_nonces) != NIL
1578
- {
1579
- seen_nonces -> (data $seen_nonces) safe (global_id ->> time).
1580
- }
1581
- if (data $pending_introductions) != NIL
1582
- {
1583
- pending_introductions -> (data $pending_introductions) safe (global_id ->> pending_intro_t).
1584
- }
1585
-
1586
- // Monitoring + control state arrived after the local-book schema —
1587
- // optional in old blobs the same way.
1588
- if (data $monitoring_enabled) != NIL
1589
- {
1590
- monitoring_enabled -> (data $monitoring_enabled) safe bool.
1591
- }
1592
- if (data $monitoring_inbox) != NIL
1593
- {
1594
- monitoring_inbox -> (data $monitoring_inbox) safe (monitoring_copy_t[]).
1595
- }
1596
- if (data $proxy_pending) != NIL
1597
- {
1598
- proxy_pending -> (data $proxy_pending) safe proxy_pending_t.
1599
- }
1600
- if (data $monitoring_proxy) != NIL
1601
- {
1602
- monitoring_proxy -> (data $monitoring_proxy) safe proxy_binding_t.
1603
- }
1604
- if (data $control_inbox) != NIL
1605
- {
1606
- control_inbox -> (data $control_inbox) safe (control_req_t[]).
1607
- }
1608
-
1609
- // File store arrived with core 3.1 — optional in pre-3.1 blobs; defaults
1610
- // ([] / 1) stay in place when absent, so an old export imports unchanged.
1611
- if (data $next_file_seq) != NIL
1612
- {
1613
- next_file_seq -> (data $next_file_seq) safe int.
1614
- }
1615
- if (data $file_inbox) != NIL
1616
- {
1617
- file_inbox -> (data $file_inbox) safe (file_t[]).
1618
- }
1619
-
1620
- // Pending introducers' keys too: their channel to me predates approval,
1621
- // so it must survive an upgrade exactly like an approved contact's.
1622
- sc pending_introductions -- ( -> p)
1623
- {
1624
- address_document::process_address_document (p $ad) TRUE.
1625
- }
1626
-
1627
- return transaction::success [
1628
- _return_data ($imported -> TRUE, $contacts -> _count a2a_messaging::contacts|, $peers -> _count a2a_messaging::peer_ads|),
1629
- _save_state NIL
1630
- ].
1631
- }
1632
-
1633
- // ---- external (inbound) transactions ------------------------------------
1634
-
1635
- // Compat shims (Option A): pre-migration peers address these as ::actor::*,
1636
- // and the core keeps SENDING to the ::actor:: names too. Each delegates to
1637
- // the shared handler — remove only when no old clients remain.
1638
- trn accept_contact args: any
1639
- {
1640
- return a2a_messaging::handle_accept_contact args.
1641
- }
1642
-
1643
- trn receive_message args: any
1644
- {
1645
- return a2a_messaging::handle_receive_message args.
1646
- }
1647
-
1648
- // A same-host peer connects via the local contact book. The credential must
1649
- // have been minted by THIS HOST's registrar for THIS sender and THIS target,
1650
- // recently, and never seen before — five checks that together make the book
1651
- // path unusable from outside the host:
1652
- // 1. registrar signature over the credential (pinned key list)
1653
- // 2. envelope $from == credential.joiner_cid (no splicing someone
1654
- // else's credential onto your own channel)
1655
- // 3. hash(joiner_ad) == credential.joiner_ad_hash (no AD substitution)
1656
- // 4. credential.target_cid == me (no cross-target reuse)
1657
- // 5. freshness window + unseen nonce (no replay)
1658
- // The encrypted channel itself authenticates that the sender controls its
1659
- // keys, so no extra challenge-response is needed.
1660
- trn local_introduce _:($joiner_name -> joiner_name: str, $joiner_ad -> joiner_ad: address_document_types::t_address_document, $intro -> intro_blob: bin, $text -> text: str+)
1661
- {
1662
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::external,).
1663
- encrypted_channel::check_encrypted_or_abort().
1664
-
1665
- sender_id = current_transaction_info::get_external_envelope_or_abort() $from.
1666
- abort "This identity does not accept local-contact-book introductions." when registrar_ad == NIL.
1667
-
1668
- signed = (_read_or_abort intro_blob) safe a2a_protocol::signed_intro_t.
1669
- intro = signed $i.
1670
- abort "Unsupported introduction credential version." when (intro $version) != 1.
1671
- abort "Introduction credential was not signed by this host's registrar." when key_storage::check_signature_new_container (_value_id intro) (signed $s) (registrar_ad? $identity $key_list) != TRUE.
1672
- abort "Introduction credential was minted for a different sender." when (intro $joiner_cid) != sender_id.
1673
- abort "Introduction credential does not match the sender's address document." when (intro $joiner_ad_hash) != _value_id joiner_ad.
1674
- abort "Introduction credential targets a different identity." when (intro $target_cid) != _get_container_id().
1675
-
1676
- now = (current_transaction_info::get_transaction_time())?.
1677
- age = _substract_seconds now (intro $iat).
1678
- abort "Introduction credential is outside its freshness window." when age > intro_max_age_seconds || age < (0 - intro_max_skew_seconds).
1679
-
1680
- // Lazy nonce GC (drop everything past the retention horizon), then the
1681
- // replay check, then a hard cap so a misbehaving local peer cannot bloat
1682
- // packet state inside the window.
1683
- horizon = intro_max_age_seconds + intro_max_skew_seconds.
1684
- fresh_nonces is (global_id ->> time) = (,).
1685
- sc seen_nonces -- (n -> t)
1686
- {
1687
- if (_substract_seconds now t) <= horizon { fresh_nonces n -> t. }
1688
- }
1689
- seen_nonces -> fresh_nonces.
1690
- abort "Replayed introduction credential." when seen_nonces (intro $nonce) != NIL.
1691
- abort "Too many concurrent introductions; try again shortly." when (_count seen_nonces|) >= seen_nonce_cap.
1692
- seen_nonces (intro $nonce) -> now.
1693
-
1694
- existing = a2a_messaging::contacts sender_id.
1695
- if existing != NIL
1696
- {
1697
- // Already a contact (idempotent re-introduction): keep my assigned
1698
- // name, refresh the stored address document, deliver any payload.
1699
- a2a_messaging::peer_ads sender_id -> joiner_ad.
1700
- if text != NIL
1701
- {
1702
- mid = deposit_message sender_id (existing? $name) text? now "" no_reply.
1703
- return transaction::success [
1704
- _notify_agent ($event -> $message_received, $sender_name -> existing? $name, $msg_id -> mid, $date -> now),
1705
- _save_state NIL
1706
- ].
1707
- }
1708
- return transaction::success [ _save_state NIL ].
1709
- }
1710
-
1711
- if local_auto_accept
1712
- {
1713
- a2a_messaging::contacts sender_id -> ($name -> joiner_name, $container_id -> sender_id).
1714
- a2a_messaging::peer_ads sender_id -> joiner_ad.
1715
- if text != NIL
1716
- {
1717
- mid = deposit_message sender_id joiner_name text? now "" no_reply.
1718
- return transaction::success [
1719
- _notify_agent ($event -> $local_contact_added, $name -> joiner_name, $container_id -> sender_id),
1720
- _notify_agent ($event -> $message_received, $sender_name -> joiner_name, $msg_id -> mid, $date -> now),
1721
- _save_state NIL
1722
- ].
1723
- }
1724
- return transaction::success [
1725
- _notify_agent ($event -> $local_contact_added, $name -> joiner_name, $container_id -> sender_id),
1726
- _save_state NIL
1727
- ].
1728
- }
1729
-
1730
- // Pending-approval policy: park the introduction (with its optional
1731
- // first message) until approve_introduction / reject_introduction.
1732
- queued is pending_msg_t[] = [].
1733
- if text != NIL { queued 0 -> ($text -> text?, $date -> now). }
1734
- pending_introductions sender_id -> ($name -> joiner_name, $ad -> joiner_ad, $messages -> queued).
1735
- return transaction::success [
1736
- _notify_agent ($event -> $local_contact_request, $name -> joiner_name, $container_id -> sender_id, $queued -> _count queued|),
1737
- _save_state NIL
1738
- ].
1739
- }
1740
-
1741
- // An intra-root peer connects (Ring 1 of the identity hierarchy). Trust is
1742
- // the delegation cert, not a registrar credential: the sender presents a
1743
- // cert that must (a) name MY root, (b) verify against my root's keys,
1744
- // (c) name the sender as the role, and (d) match the sender's address
1745
- // document. The encrypted channel authenticates that the sender controls
1746
- // its keys, and a cert is useless on anyone else's channel because of (c) —
1747
- // so no nonce/freshness machinery is needed; the cert is a standing
1748
- // credential, revoked by deleting the role (the root simply stops vouching).
1749
- // A cert-less introduction is accepted ONLY from my root itself (the root
1750
- // has no cert; the channel proves it controls the root's keys).
1751
- // Intra-root introductions auto-accept regardless of local_auto_accept —
1752
- // implicit trust inside the root is the point of Ring 1.
1753
- trn sibling_introduce _:($joiner_name -> joiner_name: str, $joiner_ad -> joiner_ad: address_document_types::t_address_document, $cert -> cert_blob: bin+, $text -> text: str+)
1754
- {
1755
- current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::external,).
1756
- encrypted_channel::check_encrypted_or_abort().
1757
-
1758
- sender_id = current_transaction_info::get_external_envelope_or_abort() $from.
1759
- now = (current_transaction_info::get_transaction_time())?.
1760
-
1761
- link is a2a_protocol::contact_root_t+ = NIL.
1762
- if cert_blob == NIL
1763
- {
1764
- // Sender claims to be my root.
1765
- abort "A certificate-less sibling introduction is only accepted from my root." when a2a_messaging::delegation_cert == NIL.
1766
- abort "Sender is not my root." when sender_id != (a2a_messaging::delegation_cert? $c $root_cid).
1767
- link -> ($root_cid -> sender_id, $root_name -> joiner_name, $role_id -> "").
1768
- }
1769
- else
1770
- {
1771
- cert = (_read_or_abort cert_blob?) safe a2a_protocol::delegation_cert_t.
1772
- abort "Unsupported delegation certificate version." when (cert $c $version) != 1.
1773
- abort "Sibling certificate was issued for a different sender." when (cert $c $role_cid) != sender_id.
1774
- abort "Sibling certificate does not match the sender's address document." when (cert $c $role_ad_hash) != (_value_id joiner_ad).
1775
-
1776
- root_name_known is str = "".
1777
- if a2a_messaging::delegation_cert != NIL
1778
- {
1779
- // I am a role: the cert must name MY root and verify against the
1780
- // root key material pinned at delegation time.
1781
- abort "My root material is missing — cannot verify sibling certificates." when a2a_messaging::root_ad == NIL.
1782
- abort "Sibling certificate names a different root." when (cert $c $root_cid) != (a2a_messaging::delegation_cert? $c $root_cid).
1783
- abort "Sibling certificate was not signed by my root." when key_storage::check_signature_new_container (_value_id (cert $c)) (cert $s) (a2a_messaging::root_ad? $identity $key_list) != TRUE.
1784
- if a2a_messaging::root_profile != NIL { root_name_known -> a2a_messaging::root_profile? $p $name. }
1785
- }
1786
- else
1787
- {
1788
- // I have no cert: I only accept certs that *I* issued, i.e. I am
1789
- // the root. A legacy flat identity fails this check by design.
1790
- abort "Sibling certificate names a different root." when (cert $c $root_cid) != _get_container_id().
1791
- my_ad = address_document::get_my_address_document().
1792
- abort "Sibling certificate was not signed by me." when key_storage::check_signature_new_container (_value_id (cert $c)) (cert $s) (my_ad $identity $key_list) != TRUE.
1793
- root_name_known -> a2a_messaging::my_name.
1794
- }
1795
- link -> ($root_cid -> cert $c $root_cid, $root_name -> root_name_known, $role_id -> cert $c $role_id).
1796
- }
1797
-
1798
- existing = a2a_messaging::contacts sender_id.
1799
- if existing != NIL
1800
- {
1801
- // Already a contact (idempotent re-introduction): keep my assigned
1802
- // name, refresh the stored material, deliver any payload.
1803
- a2a_messaging::peer_ads sender_id -> joiner_ad.
1804
- a2a_messaging::contact_roots sender_id -> link?.
1805
- if text != NIL
1806
- {
1807
- mid = deposit_message sender_id (existing? $name) text? now "" no_reply.
1808
- return transaction::success [
1809
- _notify_agent ($event -> $message_received, $sender_name -> existing? $name, $msg_id -> mid, $date -> now),
1810
- _save_state NIL
1811
- ].
1812
- }
1813
- return transaction::success [ _save_state NIL ].
1814
- }
1815
-
1816
- a2a_messaging::contacts sender_id -> ($name -> joiner_name, $container_id -> sender_id).
1817
- a2a_messaging::peer_ads sender_id -> joiner_ad.
1818
- a2a_messaging::contact_roots sender_id -> link?.
1819
- if text != NIL
1820
- {
1821
- mid = deposit_message sender_id joiner_name text? now "" no_reply.
1822
- return transaction::success [
1823
- _notify_agent ($event -> $sibling_contact_added, $name -> joiner_name, $container_id -> sender_id),
1824
- _notify_agent ($event -> $message_received, $sender_name -> joiner_name, $msg_id -> mid, $date -> now),
1825
- _save_state NIL
1826
- ].
1827
- }
1828
- return transaction::success [
1829
- _notify_agent ($event -> $sibling_contact_added, $name -> joiner_name, $container_id -> sender_id),
1830
- _save_state NIL
1831
- ].
1832
- }
1833
- }