@ours.network/tg-connector 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/mufl_code/2DA1D5F860E42C605D92F1E24E2466C70EFDDBF057BBCBA52F0ECC639EFCA387.muflo +0 -0
  2. package/dist/mufl_code/core/CLUSTER_API.md +640 -0
  3. package/dist/mufl_code/core/CLUSTER_CONTRACT.md +121 -0
  4. package/dist/mufl_code/core/CLUSTER_INTRODUCTION_PLAN.md +200 -0
  5. package/dist/mufl_code/core/CONFIGURATION_DESIGN.md +35 -0
  6. package/dist/mufl_code/core/CONFIGURATION_PLAN.md +394 -0
  7. package/dist/mufl_code/core/DEVELOPMENT.md +168 -0
  8. package/dist/mufl_code/core/EPHEMERAL_INVITE_PLAN.md +465 -0
  9. package/dist/mufl_code/core/GROUP_CHAT_DESIGN.md +520 -0
  10. package/dist/mufl_code/core/LICENSE +98 -0
  11. package/dist/mufl_code/core/README.md +76 -0
  12. package/dist/mufl_code/core/a2a_capabilities.mm +350 -0
  13. package/dist/mufl_code/core/a2a_cluster.mm +601 -0
  14. package/dist/mufl_code/core/a2a_control.mm +89 -0
  15. package/dist/mufl_code/core/a2a_messaging.mm +2103 -0
  16. package/dist/mufl_code/core/a2a_monitoring.mm +94 -0
  17. package/dist/mufl_code/core/a2a_protocol.mm +231 -0
  18. package/dist/mufl_code/core/config.mufl +26 -0
  19. package/dist/mufl_code/core/release-notes/2.0.md +268 -0
  20. package/dist/mufl_code/core/release-notes/2.1.md +92 -0
  21. package/dist/mufl_code/core/release-notes/2.2.md +94 -0
  22. package/dist/mufl_code/core/release-notes/3.0.md +162 -0
  23. package/dist/mufl_code/core/release-notes/3.1.md +43 -0
  24. package/dist/mufl_code/core/release-notes/README.md +32 -0
  25. package/dist/mufl_code/core/tests/README.md +66 -0
  26. package/dist/mufl_code/core/tests/run.sh +67 -0
  27. package/dist/mufl_code/core/tests/test.mjs +467 -0
  28. package/dist/mufl_code/core/tests/test_actor.mu +287 -0
  29. package/dist/mufl_code/core/version.mm +24 -0
  30. package/package.json +2 -1
@@ -0,0 +1,287 @@
1
+ // Self-contained test actor for the core-3.0 ephemeral-invite suite.
2
+ //
3
+ // DERIVED locally for the core repo — it does NOT vendor any consumer/daemon
4
+ // source. It loads only the shared core libraries this suite exercises
5
+ // (a2a_protocol + a2a_messaging + their stdlib deps) and provides the MINIMUM
6
+ // host wiring a packet needs: the storage hooks a2a_messaging::init requires, a
7
+ // tiny inbox, the identity-hierarchy helper trns (so the role scenario can mint
8
+ // a delegation chain), export/import wrappers (migration scenario), and the
9
+ // `qa_*` probe trns the driver uses to inject adversarial inputs and read state.
10
+ //
11
+ // It does NOT load a2a_control / a2a_cluster / a2a_monitoring / a2a_capabilities-
12
+ // init: the invite redeem flow, send_message, the hierarchy chain, and
13
+ // export/import do not depend on them. The redeem transactions themselves
14
+ // (generate_invite / add_contact / submit_invite_response / complete_invite) live
15
+ // in a2a_messaging and are library-routed, so no ::actor:: shim is needed.
16
+
17
+ application actor loads libraries
18
+ identity_proof_document,
19
+ attestation_document,
20
+ native_attestation_document,
21
+ transaction_message_decoder,
22
+ address_document,
23
+ address_document_types,
24
+ key_utils,
25
+ key_storage,
26
+ continuation,
27
+ encrypted_channel,
28
+ a2a_protocol,
29
+ a2a_messaging,
30
+ current_transaction_info,
31
+ protocol_container,
32
+ version
33
+ uses transactions
34
+ {
35
+ hidden
36
+ {
37
+ // Minimal inbox (the app owns message storage; the core calls the hook).
38
+ metadef msg_t: ($sender -> global_id, $text -> str, $wire_id -> str, $reply_wire -> str).
39
+ inbox is msg_t[] = [].
40
+
41
+ // Minimal file store (the app owns file storage; the core calls the hook).
42
+ metadef file_t: ($sender -> global_id, $filename -> str, $mime -> str, $wire_id -> str, $reply_wire -> str).
43
+ files is file_t[] = [].
44
+
45
+ // Wire the deserialization primitive into the libraries that need it.
46
+ _read_or_abort = grab( _read_or_abort ).
47
+ key_storage::init ($_read_or_abort -> _read_or_abort).
48
+ encrypted_channel::init ($_read_or_abort -> _read_or_abort).
49
+
50
+ // Host-protocol action helpers (the driver resolves on kind "data").
51
+ fn _save_state (_) = (transaction::action::return_data ($kind -> $save_state)).
52
+ fn _return_data (payload: any) = (transaction::action::return_data ($kind -> $data, $payload -> payload)).
53
+ fn _notify_agent (payload: any) = (transaction::action::return_data ($kind -> $notify_agent, $payload -> payload)).
54
+
55
+ // Storage hooks: deposit inbound messages; send/remove are no-ops.
56
+ a2a_messaging::init (
57
+ $_read_or_abort -> _read_or_abort,
58
+ $on_message_received -> fn (arg: any) -> transaction::action::type[]
59
+ {
60
+ sid = (arg $sender_id) safe global_id.
61
+ txt = (arg $text) safe str.
62
+ wid is str = "".
63
+ if (arg $wire_id) != NIL { wid -> (arg $wire_id) safe str. }
64
+ rw is str = "".
65
+ if (arg $reply_to) != NIL { rw -> ((arg $reply_to) $wire_id) safe str. }
66
+ inbox (_count inbox|) -> ($sender -> sid, $text -> txt, $wire_id -> wid, $reply_wire -> rw).
67
+ return [ _notify_agent ($event -> $message_received), _save_state NIL ].
68
+ },
69
+ $on_message_sent -> fn (_: any) -> transaction::action::type[] { return []. },
70
+ $on_contact_removed -> fn (_: any) -> transaction::action::type[] { return []. },
71
+ $on_file_received -> fn (arg: any) -> transaction::action::type[]
72
+ {
73
+ sid = (arg $sender_id) safe global_id.
74
+ fname = (arg $filename) safe str.
75
+ mt = (arg $mime) safe str.
76
+ wid is str = "".
77
+ if (arg $wire_id) != NIL { wid -> (arg $wire_id) safe str. }
78
+ rw is str = "".
79
+ if (arg $reply_to) != NIL { rw -> ((arg $reply_to) $wire_id) safe str. }
80
+ files (_count files|) -> ($sender -> sid, $filename -> fname, $mime -> mt, $wire_id -> wid, $reply_wire -> rw).
81
+ return [ _notify_agent ($event -> $file_received), _save_state NIL ].
82
+ },
83
+ $on_file_sent -> fn (_: any) -> transaction::action::type[] { return []. }
84
+ ).
85
+ }
86
+
87
+ // ---- minimal host surface used by the driver ----
88
+ // The core's send_message delivers to the legacy ::actor::receive_message name;
89
+ // this shim routes it into the core receive handler (→ on_message_received hook).
90
+ trn receive_message args: any { return a2a_messaging::handle_receive_message args. }
91
+ trn readonly list_incoming_messages _ { return ($inbox -> inbox). }
92
+ trn readonly list_incoming_files _ { return ($files -> files). }
93
+ // Exercises the metadata-only file monitoring summary directly (the loopback has
94
+ // no bound control plane, so the format + byte-secrecy are asserted on the helper).
95
+ trn qa_file_summary _:($filename -> f: str, $mime -> m: str, $data -> d: bin)
96
+ {
97
+ return transaction::success [ _return_data ($summary -> (a2a_messaging::file_monitor_summary f m d)) ].
98
+ }
99
+ trn readonly export_address_document _ { return (_write address_document::get_my_address_document()). }
100
+
101
+ // Identity-hierarchy helpers (derived equivalents of the host's; used only by
102
+ // the role scenario). sign_delegation/export_root_profile are root-side;
103
+ // set_delegation is role-side.
104
+ trn sign_delegation _:($role_ad -> role_ad_blob: bin, $role_id -> role_id: str)
105
+ {
106
+ current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
107
+ abort "Only a root can sign delegation certs." when a2a_messaging::delegation_cert != NIL.
108
+ role_ad = (_read_or_abort role_ad_blob) safe address_document_types::t_address_document.
109
+ role_cid = role_ad $identity $container_id.
110
+ abort "Cannot delegate to myself." when role_cid == _get_container_id().
111
+ core is a2a_protocol::delegation_core_t = (
112
+ $version -> 1, $role_cid -> role_cid, $role_ad_hash -> (_value_id role_ad),
113
+ $role_id -> role_id, $root_cid -> _get_container_id(),
114
+ $issued_at -> (current_transaction_info::get_transaction_time())?
115
+ ).
116
+ cert is a2a_protocol::delegation_cert_t = ($c -> core, $s -> key_storage::default_sign (_value_id core)).
117
+ return transaction::success [ _return_data ($cert -> (_write cert)) ].
118
+ }
119
+
120
+ trn export_root_profile _
121
+ {
122
+ current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
123
+ abort "Only a root can export a root profile." when a2a_messaging::delegation_cert != NIL.
124
+ my_ad = address_document::get_my_address_document().
125
+ core is a2a_protocol::root_profile_core_t = (
126
+ $version -> 1, $root_cid -> _get_container_id(),
127
+ $name -> a2a_messaging::my_name, $bio -> a2a_messaging::my_bio,
128
+ $keys -> my_ad $identity $key_list
129
+ ).
130
+ profile is a2a_protocol::root_profile_t = ($p -> core, $s -> key_storage::default_sign (_value_id core)).
131
+ return transaction::success [ _return_data ($profile -> (_write profile)) ].
132
+ }
133
+
134
+ trn set_delegation _:($cert -> cert_blob: bin, $root_ad -> root_ad_blob: bin, $root_profile -> rp_blob: bin)
135
+ {
136
+ current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
137
+ cert = (_read_or_abort cert_blob) safe a2a_protocol::delegation_cert_t.
138
+ new_root_ad = (_read_or_abort root_ad_blob) safe address_document_types::t_address_document.
139
+ rp = (_read_or_abort rp_blob) safe a2a_protocol::root_profile_t.
140
+ abort "cert not for me." when (cert $c $role_cid) != _get_container_id().
141
+ my_ad = address_document::get_my_address_document().
142
+ abort "cert AD mismatch." when (cert $c $role_ad_hash) != (_value_id my_ad).
143
+ abort "root AD mismatch." when (new_root_ad $identity $container_id) != (cert $c $root_cid).
144
+ abort "cert not root-signed." when key_storage::check_signature_new_container (_value_id (cert $c)) (cert $s) (new_root_ad $identity $key_list) != TRUE.
145
+ abort "profile not root-signed." when key_storage::check_signature_new_container (_value_id (rp $p)) (rp $s) (new_root_ad $identity $key_list) != TRUE.
146
+ a2a_messaging::delegation_cert -> cert.
147
+ a2a_messaging::root_ad -> new_root_ad.
148
+ a2a_messaging::root_profile -> rp.
149
+ return transaction::success [ _return_data ($delegated -> TRUE), _save_state NIL ].
150
+ }
151
+
152
+ // export/import wrappers (migration scenario): the core state under $core, as a
153
+ // host would compose it. (The app inbox is not part of this suite's migration
154
+ // assertions, so it is omitted to keep the fixture minimal.)
155
+ trn readonly export_state _ { return ($core -> (a2a_messaging::export_core_state NIL)). }
156
+ trn import_state data: any
157
+ {
158
+ current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
159
+ a2a_messaging::import_core_state (data $core).
160
+ return transaction::success [ _return_data ($imported -> TRUE), _save_state NIL ].
161
+ }
162
+
163
+ // ================= TEST PROBES =================
164
+ trn readonly qa_my_cid _ { return ($cid -> _get_container_id()). }
165
+ trn readonly qa_export_ad _ { return ($ad -> (_write address_document::get_my_address_document())). }
166
+
167
+ // Counts over the (non-hidden) core state — for receiver-side assertions.
168
+ trn readonly qa_state _
169
+ {
170
+ return (
171
+ $n_contacts -> (_count a2a_messaging::contacts),
172
+ $n_peer_ads -> (_count a2a_messaging::peer_ads),
173
+ $n_pending_invites -> (_count a2a_messaging::pending_invites),
174
+ $n_pending_redemptions -> (_count a2a_messaging::pending_redemptions),
175
+ $n_contact_roots -> (_count a2a_messaging::contact_roots),
176
+ $n_pending_restores -> (_count a2a_messaging::pending_restores),
177
+ $n_restore_replies -> (_count a2a_messaging::pending_restore_replies),
178
+ $n_deferred -> (_count a2a_messaging::deferred_msgs)
179
+ ).
180
+ }
181
+
182
+ // export-secrecy: hand back export_core_state so the driver confirms neither
183
+ // ephemeral secret store appears in the portable export.
184
+ trn readonly qa_export_core _ { return ($core -> (a2a_messaging::export_core_state NIL)). }
185
+
186
+ // Simulate a breaking-change migration that carried contacts but dropped the
187
+ // address documents (the spec's "degraded contact" state).
188
+ trn qa_strip_peer_ads _
189
+ {
190
+ a2a_messaging::peer_ads -> (,).
191
+ return transaction::success [ _return_data ($stripped -> TRUE) ].
192
+ }
193
+
194
+ // ---- adversarial leg-1 senders (bare-send a crafted submit_invite_response) ----
195
+ trn qa_leg1_badbox _:($invite -> blob: bin)
196
+ {
197
+ inv = (_read_or_abort blob) safe a2a_protocol::invite_eph_t.
198
+ kpr = _crypto_construct_encryption_keypair (inv $v).
199
+ wrong = _crypto_construct_encryption_keypair (inv $v).
200
+ payload = _write ($ad -> (address_document::get_my_address_document()), $cert -> NIL, $root_profile -> NIL, $cp_binding -> NIL, $invite_id -> (inv $d)).
201
+ data = _crypto_encrypt_message (kpr $secret_key) (wrong $public_key) payload.
202
+ return transaction::success [
203
+ transaction::action::send (inv $c) ($name -> "::a2a_messaging::submit_invite_response", $targ -> ($invite_id -> (inv $d), $epk -> (kpr $public_key), $v -> (inv $v), $data -> data)),
204
+ _return_data ($sent -> TRUE)
205
+ ].
206
+ }
207
+ trn qa_leg1_foreign_ad _:($invite -> blob: bin, $foreign_ad -> fad: bin)
208
+ {
209
+ inv = (_read_or_abort blob) safe a2a_protocol::invite_eph_t.
210
+ kpr = _crypto_construct_encryption_keypair (inv $v).
211
+ foreign = (_read_or_abort fad) safe address_document_types::t_address_document.
212
+ payload = _write ($ad -> foreign, $cert -> NIL, $root_profile -> NIL, $cp_binding -> NIL, $invite_id -> (inv $d)).
213
+ data = _crypto_encrypt_message (kpr $secret_key) (inv $k) payload.
214
+ return transaction::success [
215
+ transaction::action::send (inv $c) ($name -> "::a2a_messaging::submit_invite_response", $targ -> ($invite_id -> (inv $d), $epk -> (kpr $public_key), $v -> (inv $v), $data -> data)),
216
+ _return_data ($sent -> TRUE)
217
+ ].
218
+ }
219
+ trn qa_leg1_forged_ad _:($invite -> blob: bin)
220
+ {
221
+ inv = (_read_or_abort blob) safe a2a_protocol::invite_eph_t.
222
+ kpr = _crypto_construct_encryption_keypair (inv $v).
223
+ my_ad = address_document::get_my_address_document().
224
+ forged is address_document_types::t_address_document = ($version -> (my_ad $version), $identity -> (my_ad $identity), $authorizations -> (,)).
225
+ payload = _write ($ad -> forged, $cert -> NIL, $root_profile -> NIL, $cp_binding -> NIL, $invite_id -> (inv $d)).
226
+ data = _crypto_encrypt_message (kpr $secret_key) (inv $k) payload.
227
+ return transaction::success [
228
+ transaction::action::send (inv $c) ($name -> "::a2a_messaging::submit_invite_response", $targ -> ($invite_id -> (inv $d), $epk -> (kpr $public_key), $v -> (inv $v), $data -> data)),
229
+ _return_data ($sent -> TRUE)
230
+ ].
231
+ }
232
+
233
+ // Fire a leg-0 restore request at an arbitrary target (bypassing the
234
+ // degraded-contact trigger) — used to prove the responder's contacts gate.
235
+ trn qa_send_restore_request _:($target -> tgt: global_id)
236
+ {
237
+ actions is transaction::action::type[] = a2a_messaging::begin_contact_restore tgt.
238
+ actions (_count actions|) -> _return_data ($ok -> TRUE).
239
+ return transaction::success actions.
240
+ }
241
+
242
+ // Craft an unsolicited leg-1 (no matching pending_restores at the target).
243
+ trn qa_send_fake_restore_response _:($target -> tgt: global_id)
244
+ {
245
+ scheme = _crypto_default_scheme_id().
246
+ kp = _crypto_construct_encryption_keypair scheme.
247
+ payload = _write ($junk -> "x").
248
+ data = _crypto_encrypt_message (kp $secret_key) (kp $public_key) payload.
249
+ return transaction::success [
250
+ transaction::action::send tgt (
251
+ $name -> "::a2a_messaging::submit_restore_response",
252
+ $targ -> ($rid -> (_new_id "fake restore"), $epk -> (kp $public_key), $v -> scheme, $data -> data)
253
+ ),
254
+ _return_data ($ok -> TRUE)
255
+ ].
256
+ }
257
+
258
+ // ---- leg-3 isolation helpers ----
259
+ // A fake invite carrying a chosen inviter cid; the named cid never minted it, so
260
+ // its leg-2 aborts (unknown invite) and sends no real leg-3 — leaving the
261
+ // responder with a LIVE redemption + kept eph priv to target.
262
+ trn qa_mint_fake_invite _:($inviter_cid -> icid: global_id)
263
+ {
264
+ scheme = _crypto_default_scheme_id().
265
+ kp = _crypto_construct_encryption_keypair scheme.
266
+ iid = _new_id "fake invite".
267
+ inv is a2a_protocol::invite_eph_t = ($d -> iid, $c -> icid, $n -> "Fake", $k -> (kp $public_key), $v -> scheme).
268
+ return transaction::success [ _return_data ($blob -> (_write inv), $invite_id -> iid) ].
269
+ }
270
+ // Crafted leg-3 as a BARE BOXED send to the responder's kept eph pubkey.
271
+ // mode: "real" (sender-pin) | "foreign" (cid-bind leg-3) | "forged" (PoP leg-3).
272
+ trn qa_send_complete _:($target -> tgt: global_id, $invite_id -> iid: global_id, $resp_eph_pub -> rpk: publickey_encrypt, $mode -> mode: str, $foreign_ad -> fad: bin)
273
+ {
274
+ scheme = _crypto_default_scheme_id().
275
+ kpi = _crypto_construct_encryption_keypair scheme.
276
+ my_ad = address_document::get_my_address_document().
277
+ ad is address_document_types::t_address_document = my_ad.
278
+ if mode == "foreign" { ad -> (_read_or_abort fad) safe address_document_types::t_address_document. }
279
+ if mode == "forged" { ad -> ($version -> (my_ad $version), $identity -> (my_ad $identity), $authorizations -> (,)). }
280
+ payload = _write ($ad -> ad, $cert -> NIL, $root_profile -> NIL, $cp_binding -> NIL, $invite_id -> iid).
281
+ data = _crypto_encrypt_message (kpi $secret_key) rpk payload.
282
+ return transaction::success [
283
+ transaction::action::send tgt ($name -> "::a2a_messaging::complete_invite", $targ -> ($invite_id -> iid, $epk -> (kpi $public_key), $v -> scheme, $data -> data)),
284
+ _return_data ($sent -> TRUE)
285
+ ].
286
+ }
287
+ }
@@ -0,0 +1,24 @@
1
+ /*
2
+ This library provides a simple version tracking mechanism for the shared
3
+ ours mufl core. It contains a hardcoded read-only version that can be
4
+ accessed by any library or application that loads it.
5
+ This library has no dependencies and can be included in any packet.
6
+ */
7
+ library version
8
+ {
9
+ metadef version_t: (
10
+ $MAJ -> int,
11
+ $MIN -> int,
12
+ $PATCH -> int
13
+ ).
14
+
15
+ fn create_version (maj: int, min: int, patch: int) = ($MIN -> min, $MAJ -> maj, $PATCH -> patch).
16
+
17
+
18
+ // This MUST be updated every time we update ANY code in the shared core.
19
+ hidden {
20
+ core_version = create_version 0 2 0.
21
+ }
22
+
23
+ fn get_core_version(_) = core_version.
24
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ours.network/tg-connector",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Bridge Telegram bots to ours proxy nodes — one ADAPT wrapper hosting N messenger packets, each connecting one Telegram bot to one ours node. Run `ours-tg-connector add_new_connection`.",
5
5
  "type": "module",
6
6
  "license": "FSL-1.1-Apache-2.0",
@@ -39,6 +39,7 @@
39
39
  "@adapt-toolkit/sdk-native": "0.6.2"
40
40
  },
41
41
  "devDependencies": {
42
+ "@adapt-toolkit/mufl": "0.8.0",
42
43
  "@types/node": "^20.14.0",
43
44
  "esbuild": "^0.24.2",
44
45
  "tsx": "^4.19.0",