@cello-protocol/cli 0.0.306 → 0.0.307

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 (234) hide show
  1. package/.claude-plugin/marketplace.json +15 -0
  2. package/README.md +107 -0
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +564 -0
  5. package/dist/daemon/account-page-assets.d.ts +4 -0
  6. package/dist/daemon/account-page-assets.js +160 -0
  7. package/dist/daemon/account-page.d.ts +14 -0
  8. package/dist/daemon/account-page.js +104 -0
  9. package/dist/daemon/address.d.ts +10 -0
  10. package/dist/daemon/address.js +34 -0
  11. package/dist/daemon/away.d.ts +31 -0
  12. package/dist/daemon/away.js +65 -0
  13. package/dist/daemon/channel-store.d.ts +112 -0
  14. package/dist/daemon/channel-store.js +284 -0
  15. package/dist/daemon/channels.d.ts +46 -0
  16. package/dist/daemon/channels.js +1049 -0
  17. package/dist/daemon/contacts.d.ts +26 -0
  18. package/dist/daemon/contacts.js +74 -0
  19. package/dist/daemon/engine.d.ts +80 -0
  20. package/dist/daemon/engine.js +2882 -0
  21. package/dist/daemon/errors.d.ts +5 -0
  22. package/dist/daemon/errors.js +16 -0
  23. package/dist/daemon/governance.d.ts +66 -0
  24. package/dist/daemon/governance.js +514 -0
  25. package/dist/daemon/guards.d.ts +36 -0
  26. package/dist/daemon/guards.js +140 -0
  27. package/dist/daemon/issuer-client.d.ts +56 -0
  28. package/dist/daemon/issuer-client.js +143 -0
  29. package/dist/daemon/link.d.ts +30 -0
  30. package/dist/daemon/link.js +191 -0
  31. package/dist/daemon/log.d.ts +1 -0
  32. package/dist/daemon/log.js +4 -0
  33. package/dist/daemon/main.d.ts +1 -0
  34. package/dist/daemon/main.js +511 -0
  35. package/dist/daemon/paths.d.ts +6 -0
  36. package/dist/daemon/paths.js +21 -0
  37. package/dist/daemon/pii.d.ts +24 -0
  38. package/dist/daemon/pii.js +146 -0
  39. package/dist/daemon/policy-cadence.d.ts +33 -0
  40. package/dist/daemon/policy-cadence.js +59 -0
  41. package/dist/daemon/policy-proposals.d.ts +41 -0
  42. package/dist/daemon/policy-proposals.js +83 -0
  43. package/dist/daemon/policy-store.d.ts +47 -0
  44. package/dist/daemon/policy-store.js +144 -0
  45. package/dist/daemon/presented.d.ts +36 -0
  46. package/dist/daemon/presented.js +94 -0
  47. package/dist/daemon/rate-limit.d.ts +17 -0
  48. package/dist/daemon/rate-limit.js +44 -0
  49. package/dist/daemon/reach.d.ts +63 -0
  50. package/dist/daemon/reach.js +207 -0
  51. package/dist/daemon/screening.d.ts +97 -0
  52. package/dist/daemon/screening.js +362 -0
  53. package/dist/daemon/settings.d.ts +125 -0
  54. package/dist/daemon/settings.js +73 -0
  55. package/dist/daemon/signal-rules.d.ts +55 -0
  56. package/dist/daemon/signal-rules.js +127 -0
  57. package/dist/daemon/signal-store.d.ts +53 -0
  58. package/dist/daemon/signal-store.js +114 -0
  59. package/dist/daemon/store.d.ts +188 -0
  60. package/dist/daemon/store.js +474 -0
  61. package/dist/daemon/tiers.d.ts +14 -0
  62. package/dist/daemon/tiers.js +9 -0
  63. package/dist/daemon/wallet.d.ts +73 -0
  64. package/dist/daemon/wallet.js +428 -0
  65. package/dist/daemon/who-label.d.ts +3 -0
  66. package/dist/daemon/who-label.js +11 -0
  67. package/dist/guidance.d.ts +39 -0
  68. package/dist/guidance.js +98 -0
  69. package/dist/hermes-bridge.d.ts +26 -0
  70. package/dist/hermes-bridge.js +180 -0
  71. package/dist/install-mcp.d.ts +6 -0
  72. package/dist/install-mcp.js +77 -0
  73. package/dist/ipc/client.d.ts +18 -0
  74. package/dist/ipc/client.js +107 -0
  75. package/dist/ipc/operations.d.ts +30 -0
  76. package/dist/ipc/operations.js +835 -0
  77. package/dist/ipc/protocol.d.ts +21 -0
  78. package/dist/ipc/protocol.js +1 -0
  79. package/dist/issuer-list-sign.d.ts +12 -0
  80. package/dist/issuer-list-sign.js +43 -0
  81. package/dist/local-operations.d.ts +2 -0
  82. package/dist/local-operations.js +73 -0
  83. package/dist/mcp-tools.d.ts +14 -0
  84. package/dist/mcp-tools.js +45 -0
  85. package/dist/mcp.d.ts +2 -0
  86. package/dist/mcp.js +155 -0
  87. package/dist/protocol/aead.d.ts +4 -0
  88. package/dist/protocol/aead.js +35 -0
  89. package/dist/protocol/cbor.d.ts +40 -0
  90. package/dist/protocol/cbor.js +106 -0
  91. package/dist/protocol/chain.d.ts +44 -0
  92. package/dist/protocol/chain.js +126 -0
  93. package/dist/protocol/channel.d.ts +153 -0
  94. package/dist/protocol/channel.js +298 -0
  95. package/dist/protocol/encode.d.ts +6 -0
  96. package/dist/protocol/encode.js +21 -0
  97. package/dist/protocol/identity.d.ts +27 -0
  98. package/dist/protocol/identity.js +94 -0
  99. package/dist/protocol/issuer-list.d.ts +56 -0
  100. package/dist/protocol/issuer-list.js +193 -0
  101. package/dist/protocol/issuer-roots.d.ts +6 -0
  102. package/dist/protocol/issuer-roots.js +10 -0
  103. package/dist/protocol/key-agreement.d.ts +20 -0
  104. package/dist/protocol/key-agreement.js +88 -0
  105. package/dist/protocol/merkle.d.ts +16 -0
  106. package/dist/protocol/merkle.js +166 -0
  107. package/dist/protocol/ml-dsa.d.ts +28 -0
  108. package/dist/protocol/ml-dsa.js +58 -0
  109. package/dist/protocol/ml-kem.d.ts +14 -0
  110. package/dist/protocol/ml-kem.js +57 -0
  111. package/dist/protocol/pq-errors.d.ts +9 -0
  112. package/dist/protocol/pq-errors.js +23 -0
  113. package/dist/protocol/pq-warnings.d.ts +1 -0
  114. package/dist/protocol/pq-warnings.js +18 -0
  115. package/dist/protocol/presented-signals.d.ts +17 -0
  116. package/dist/protocol/presented-signals.js +92 -0
  117. package/dist/protocol/salt.d.ts +5 -0
  118. package/dist/protocol/salt.js +47 -0
  119. package/dist/protocol/seal.d.ts +58 -0
  120. package/dist/protocol/seal.js +220 -0
  121. package/dist/protocol/signal.d.ts +54 -0
  122. package/dist/protocol/signal.js +266 -0
  123. package/dist/protocol/status.d.ts +41 -0
  124. package/dist/protocol/status.js +64 -0
  125. package/dist/protocol/structures.d.ts +359 -0
  126. package/dist/protocol/structures.js +296 -0
  127. package/dist/protocol/transcript.d.ts +61 -0
  128. package/dist/protocol/transcript.js +319 -0
  129. package/dist/protocol/wire.d.ts +212 -0
  130. package/dist/protocol/wire.js +161 -0
  131. package/dist/require-node.d.ts +1 -0
  132. package/dist/require-node.js +10 -0
  133. package/dist/screener/affordance.d.ts +1 -0
  134. package/dist/screener/affordance.js +2 -0
  135. package/dist/screener/classifier-selfcheck.d.ts +29 -0
  136. package/dist/screener/classifier-selfcheck.js +56 -0
  137. package/dist/screener/exfil.d.ts +11 -0
  138. package/dist/screener/exfil.js +45 -0
  139. package/dist/screener/gitleaks-rules.d.ts +9 -0
  140. package/dist/screener/gitleaks-rules.js +226 -0
  141. package/dist/screener/inbound.d.ts +25 -0
  142. package/dist/screener/inbound.js +102 -0
  143. package/dist/screener/injection-classifier-onnx.d.ts +20 -0
  144. package/dist/screener/injection-classifier-onnx.js +89 -0
  145. package/dist/screener/injection-classifier-wasm.d.ts +2 -0
  146. package/dist/screener/injection-classifier-wasm.js +97 -0
  147. package/dist/screener/injection-patterns.d.ts +8 -0
  148. package/dist/screener/injection-patterns.js +48 -0
  149. package/dist/screener/injection-windows.d.ts +9 -0
  150. package/dist/screener/injection-windows.js +37 -0
  151. package/dist/screener/language.d.ts +15 -0
  152. package/dist/screener/language.js +71 -0
  153. package/dist/screener/linear-regex.d.ts +8 -0
  154. package/dist/screener/linear-regex.js +27 -0
  155. package/dist/screener/model-installer.d.ts +14 -0
  156. package/dist/screener/model-installer.js +61 -0
  157. package/dist/screener/outbound.d.ts +19 -0
  158. package/dist/screener/outbound.js +62 -0
  159. package/dist/screener/sanitize.d.ts +44 -0
  160. package/dist/screener/sanitize.js +361 -0
  161. package/dist/screener/scan-variants.d.ts +5 -0
  162. package/dist/screener/scan-variants.js +146 -0
  163. package/dist/screener/screener-model-manifest.d.ts +16 -0
  164. package/dist/screener/screener-model-manifest.js +20 -0
  165. package/dist/screener/screener-state.d.ts +29 -0
  166. package/dist/screener/screener-state.js +119 -0
  167. package/dist/screener/secrets.d.ts +18 -0
  168. package/dist/screener/secrets.js +84 -0
  169. package/dist/screener/worker.d.ts +6 -0
  170. package/dist/screener/worker.js +83 -0
  171. package/dist/setup.d.ts +9 -0
  172. package/dist/setup.js +252 -0
  173. package/dist/shipped-issuer-list.d.ts +1 -0
  174. package/dist/shipped-issuer-list.js +3 -0
  175. package/dist/signals-text.d.ts +46 -0
  176. package/dist/signals-text.js +81 -0
  177. package/dist/verify-seal.d.ts +9 -0
  178. package/dist/verify-seal.js +30 -0
  179. package/hermes/plugin/__init__.py +1040 -0
  180. package/hermes/plugin/plugin.yaml +30 -0
  181. package/hermes/skills/cello-bridge-setup/SKILL.md +38 -0
  182. package/hermes/skills/cello-policy/SKILL.md +44 -0
  183. package/package.json +48 -16
  184. package/plugins/cello/.claude-plugin/plugin.json +19 -0
  185. package/plugins/cello/.mcp.json +7 -0
  186. package/plugins/cello/skills/cello/SKILL.md +117 -0
  187. package/dist/arg-parse.d.ts +0 -19
  188. package/dist/arg-parse.d.ts.map +0 -1
  189. package/dist/arg-parse.js +0 -29
  190. package/dist/arg-parse.js.map +0 -1
  191. package/dist/bin/cello.d.ts +0 -15
  192. package/dist/bin/cello.d.ts.map +0 -1
  193. package/dist/bin/cello.js +0 -110
  194. package/dist/bin/cello.js.map +0 -1
  195. package/dist/cli-args.d.ts +0 -62
  196. package/dist/cli-args.d.ts.map +0 -1
  197. package/dist/cli-args.js +0 -129
  198. package/dist/cli-args.js.map +0 -1
  199. package/dist/commands.d.ts +0 -196
  200. package/dist/commands.d.ts.map +0 -1
  201. package/dist/commands.js +0 -1544
  202. package/dist/commands.js.map +0 -1
  203. package/dist/hermes/assets.d.ts +0 -41
  204. package/dist/hermes/assets.d.ts.map +0 -1
  205. package/dist/hermes/assets.js +0 -2281
  206. package/dist/hermes/assets.js.map +0 -1
  207. package/dist/hermes/install-hermes.d.ts +0 -50
  208. package/dist/hermes/install-hermes.d.ts.map +0 -1
  209. package/dist/hermes/install-hermes.js +0 -232
  210. package/dist/hermes/install-hermes.js.map +0 -1
  211. package/dist/json-out.d.ts +0 -41
  212. package/dist/json-out.d.ts.map +0 -1
  213. package/dist/json-out.js +0 -59
  214. package/dist/json-out.js.map +0 -1
  215. package/dist/node-runtime-guard-init.d.ts +0 -6
  216. package/dist/node-runtime-guard-init.d.ts.map +0 -1
  217. package/dist/node-runtime-guard-init.js +0 -7
  218. package/dist/node-runtime-guard-init.js.map +0 -1
  219. package/dist/node-runtime-guard.d.ts +0 -48
  220. package/dist/node-runtime-guard.d.ts.map +0 -1
  221. package/dist/node-runtime-guard.js +0 -79
  222. package/dist/node-runtime-guard.js.map +0 -1
  223. package/dist/parity-commands.d.ts +0 -427
  224. package/dist/parity-commands.d.ts.map +0 -1
  225. package/dist/parity-commands.js +0 -953
  226. package/dist/parity-commands.js.map +0 -1
  227. package/dist/registry.d.ts +0 -120
  228. package/dist/registry.d.ts.map +0 -1
  229. package/dist/registry.js +0 -2169
  230. package/dist/registry.js.map +0 -1
  231. package/dist/screener-commands.d.ts +0 -85
  232. package/dist/screener-commands.d.ts.map +0 -1
  233. package/dist/screener-commands.js +0 -313
  234. package/dist/screener-commands.js.map +0 -1
@@ -0,0 +1,359 @@
1
+ import type { PublicIdentity } from "./identity.ts";
2
+ export declare class UnknownFormat extends RangeError {
3
+ }
4
+ export declare function assertFlat(bytes: Uint8Array, arity: number | null, options?: {
5
+ booleans?: boolean;
6
+ }): void;
7
+ export interface Structure<T> {
8
+ readonly tag: string;
9
+ encode(fields: T): Uint8Array;
10
+ decode(bytes: Uint8Array): T;
11
+ }
12
+ export declare const EntryKind: {
13
+ readonly message: 1;
14
+ readonly close: 2;
15
+ };
16
+ export type EntryKind = (typeof EntryKind)[keyof typeof EntryKind];
17
+ export declare const EntryMode: {
18
+ readonly reply: 1;
19
+ readonly notice: 2;
20
+ };
21
+ export type EntryMode = (typeof EntryMode)[keyof typeof EntryMode];
22
+ export interface EntryFields {
23
+ serverId: Uint8Array;
24
+ sessionId: Uint8Array;
25
+ authorId: Uint8Array;
26
+ authorSeq: number;
27
+ prevOwnHash: Uint8Array;
28
+ readPosition: number;
29
+ readRoot: Uint8Array;
30
+ kind: EntryKind;
31
+ mode: EntryMode;
32
+ contentHash: Uint8Array;
33
+ ciphertextHash: Uint8Array;
34
+ notAfter: number;
35
+ }
36
+ export declare const entryStructure: Structure<EntryFields>;
37
+ export declare const entryBytes: (fields: EntryFields) => Uint8Array;
38
+ export declare function entryHash(e: EntryFields): Uint8Array;
39
+ export declare function ciphertextHash(ciphertext: Uint8Array): Uint8Array;
40
+ export interface AckFields {
41
+ serverId: Uint8Array;
42
+ sessionId: Uint8Array;
43
+ position: number;
44
+ entryHash: Uint8Array;
45
+ root: Uint8Array;
46
+ time: number;
47
+ }
48
+ export declare const ackStructure: Structure<AckFields>;
49
+ export declare const ackBytes: (fields: AckFields) => Uint8Array;
50
+ export interface DeliveryAckFields {
51
+ serverId: Uint8Array;
52
+ sessionId: Uint8Array;
53
+ readerId: Uint8Array;
54
+ throughPosition: number;
55
+ entryHash: Uint8Array;
56
+ root: Uint8Array;
57
+ screenedThrough: number;
58
+ refused: Uint8Array;
59
+ }
60
+ export declare const MAX_REFUSED_POSITIONS = 512;
61
+ export declare function refusedList(positions: readonly number[]): Uint8Array;
62
+ export declare function readRefusedList(bytes: Uint8Array): number[];
63
+ export declare const deliveryAckStructure: Structure<DeliveryAckFields>;
64
+ export declare const deliveryAckBytes: (fields: DeliveryAckFields) => Uint8Array;
65
+ export interface RegisterFields {
66
+ serverId: Uint8Array;
67
+ identity: PublicIdentity;
68
+ }
69
+ export declare const registerStructure: Structure<{
70
+ serverId: Uint8Array;
71
+ ed: Uint8Array;
72
+ pq: Uint8Array;
73
+ }>;
74
+ export declare const registerBytes: (r: RegisterFields) => Uint8Array;
75
+ export interface AgentAuthFields {
76
+ serverId: Uint8Array;
77
+ agentId: Uint8Array;
78
+ serverNonce: Uint8Array;
79
+ clientNonce: Uint8Array;
80
+ }
81
+ export declare const agentAuthStructure: Structure<AgentAuthFields>;
82
+ export declare const agentAuthBytes: (fields: AgentAuthFields) => Uint8Array;
83
+ export interface ServerAuthFields {
84
+ serverId: Uint8Array;
85
+ clientNonce: Uint8Array;
86
+ serverNonce: Uint8Array;
87
+ }
88
+ export declare const serverAuthStructure: Structure<ServerAuthFields>;
89
+ export declare const serverAuthBytes: (fields: ServerAuthFields) => Uint8Array;
90
+ export declare const MAX_PRESENTED_SIGNALS = 8;
91
+ export declare const MAX_PRESENTED_BYTES = 65536;
92
+ export interface EncryptionKeyFields {
93
+ agentId: Uint8Array;
94
+ mlKemPublic: Uint8Array;
95
+ revision: number;
96
+ issuedAt: number;
97
+ }
98
+ export declare const encryptionKeyStructure: Structure<EncryptionKeyFields>;
99
+ export declare const encryptionKeyBytes: (fields: EncryptionKeyFields) => Uint8Array;
100
+ export interface OfferFields {
101
+ serverId: Uint8Array;
102
+ sessionId: Uint8Array;
103
+ callerId: Uint8Array;
104
+ calleeId: Uint8Array;
105
+ x25519Public: Uint8Array;
106
+ mlKemPublic: Uint8Array;
107
+ expiresAt: number;
108
+ signalsCiphertext: Uint8Array;
109
+ sealedSignals: Uint8Array;
110
+ }
111
+ export declare const offerStructure: Structure<OfferFields>;
112
+ export declare const offerBytes: (fields: OfferFields) => Uint8Array;
113
+ export interface AcceptFields {
114
+ offerHash: Uint8Array;
115
+ x25519Public: Uint8Array;
116
+ mlKemCiphertext: Uint8Array;
117
+ sealedSalt: Uint8Array;
118
+ sealedName: Uint8Array;
119
+ sealedSignals: Uint8Array;
120
+ }
121
+ export declare const acceptStructure: Structure<AcceptFields>;
122
+ export declare const acceptBytes: (fields: AcceptFields) => Uint8Array;
123
+ export interface RefuseFields {
124
+ offerHash: Uint8Array;
125
+ mlKemCiphertext: Uint8Array;
126
+ sealedReason: Uint8Array;
127
+ }
128
+ export declare const refuseStructure: Structure<RefuseFields>;
129
+ export declare const refuseBytes: (fields: RefuseFields) => Uint8Array;
130
+ export interface GreetingFields {
131
+ offerHash: Uint8Array;
132
+ sealedText: Uint8Array;
133
+ }
134
+ export declare const greetingStructure: Structure<GreetingFields>;
135
+ export declare const greetingBytes: (fields: GreetingFields) => Uint8Array;
136
+ export interface ConfirmFields {
137
+ acceptHash: Uint8Array;
138
+ sealedSalt: Uint8Array;
139
+ sealedName: Uint8Array;
140
+ }
141
+ export declare const confirmStructure: Structure<ConfirmFields>;
142
+ export declare const confirmBytes: (fields: ConfirmFields) => Uint8Array;
143
+ export interface AssignmentFields {
144
+ serverId: Uint8Array;
145
+ sessionId: Uint8Array;
146
+ callerId: Uint8Array;
147
+ calleeId: Uint8Array;
148
+ confirmHash: Uint8Array;
149
+ time: number;
150
+ }
151
+ export declare const assignmentStructure: Structure<AssignmentFields>;
152
+ export declare const assignmentBytes: (fields: AssignmentFields) => Uint8Array;
153
+ export interface SealRequestFields {
154
+ serverId: Uint8Array;
155
+ sessionId: Uint8Array;
156
+ sealerId: Uint8Array;
157
+ counterpartyId: Uint8Array;
158
+ throughPosition: number;
159
+ root: Uint8Array;
160
+ }
161
+ export declare const sealRequestStructure: Structure<SealRequestFields>;
162
+ export declare const sealRequestBytes: (fields: SealRequestFields) => Uint8Array;
163
+ export interface SealCertificateFields {
164
+ sealKeyId: Uint8Array;
165
+ serverId: Uint8Array;
166
+ sessionId: Uint8Array;
167
+ sealerId: Uint8Array;
168
+ counterpartyId: Uint8Array;
169
+ requestHash: Uint8Array;
170
+ root: Uint8Array;
171
+ throughPosition: number;
172
+ tip: number;
173
+ closed: number;
174
+ receivedThrough: number;
175
+ deliveryAckHash: Uint8Array;
176
+ time: number;
177
+ }
178
+ export declare const sealCertificateStructure: Structure<SealCertificateFields>;
179
+ export declare const sealCertificateBytes: (fields: SealCertificateFields) => Uint8Array;
180
+ export interface SealLogHeadFields {
181
+ sealKeyId: Uint8Array;
182
+ size: number;
183
+ root: Uint8Array;
184
+ time: number;
185
+ }
186
+ export declare const sealLogHeadStructure: Structure<SealLogHeadFields>;
187
+ export declare const sealLogHeadBytes: (fields: SealLogHeadFields) => Uint8Array;
188
+ export interface SealKeyBindingFields {
189
+ serverId: Uint8Array;
190
+ sealKeyId: Uint8Array;
191
+ }
192
+ export declare const sealKeyBindingStructure: Structure<SealKeyBindingFields>;
193
+ export declare const sealKeyBindingBytes: (fields: SealKeyBindingFields) => Uint8Array;
194
+ export declare function structureHash(bytes: Uint8Array): Uint8Array;
195
+ export declare const AgentStatus: {
196
+ readonly active: 1;
197
+ readonly suspended: 2;
198
+ readonly retired: 3;
199
+ };
200
+ export type AgentStatus = (typeof AgentStatus)[keyof typeof AgentStatus];
201
+ export declare const StatusReason: {
202
+ readonly none: 0;
203
+ readonly owner_request: 1;
204
+ readonly lost_machine: 2;
205
+ readonly compromise: 3;
206
+ };
207
+ export type StatusReason = (typeof StatusReason)[keyof typeof StatusReason];
208
+ export declare const StatusIssuer: {
209
+ readonly agent: 1;
210
+ readonly portal: 2;
211
+ readonly server: 3;
212
+ };
213
+ export type StatusIssuer = (typeof StatusIssuer)[keyof typeof StatusIssuer];
214
+ export interface StatusStatementFields {
215
+ agentId: Uint8Array;
216
+ status: AgentStatus;
217
+ reason: StatusReason;
218
+ issuer: StatusIssuer;
219
+ issuerId: Uint8Array;
220
+ issuedAt: number;
221
+ }
222
+ export declare const statusStatementStructure: Structure<StatusStatementFields>;
223
+ export declare const statusStatementBytes: (fields: StatusStatementFields) => Uint8Array;
224
+ export interface StatusWitnessFields {
225
+ serverId: Uint8Array;
226
+ agentId: Uint8Array;
227
+ seq: number;
228
+ prevHash: Uint8Array;
229
+ statementHash: Uint8Array;
230
+ time: number;
231
+ }
232
+ export declare const statusWitnessStructure: Structure<StatusWitnessFields>;
233
+ export declare const statusWitnessBytes: (fields: StatusWitnessFields) => Uint8Array;
234
+ export declare const ChannelVisibility: {
235
+ readonly public: 1;
236
+ readonly private: 2;
237
+ };
238
+ export type ChannelVisibility = (typeof ChannelVisibility)[keyof typeof ChannelVisibility];
239
+ export declare const ChannelPosting: {
240
+ readonly admin: 1;
241
+ readonly posters: 2;
242
+ readonly members: 3;
243
+ };
244
+ export type ChannelPosting = (typeof ChannelPosting)[keyof typeof ChannelPosting];
245
+ export interface ChannelRecordFields {
246
+ channelId: Uint8Array;
247
+ adminId: Uint8Array;
248
+ visibility: number;
249
+ }
250
+ export declare const channelRecordStructure: Structure<ChannelRecordFields>;
251
+ export declare const channelRecordBytes: (fields: ChannelRecordFields) => Uint8Array;
252
+ export interface ChannelInfoFields {
253
+ channelId: Uint8Array;
254
+ revision: number;
255
+ posting: number;
256
+ retentionMs: number;
257
+ generation: number;
258
+ x25519Public: Uint8Array;
259
+ mlKemPublic: Uint8Array;
260
+ posters: Uint8Array;
261
+ name: Uint8Array;
262
+ }
263
+ export declare const channelInfoStructure: Structure<ChannelInfoFields>;
264
+ export declare const channelInfoBytes: (fields: ChannelInfoFields) => Uint8Array;
265
+ export interface ChannelPostFields {
266
+ channelId: Uint8Array;
267
+ generation: number;
268
+ authorId: Uint8Array;
269
+ authorSeq: number;
270
+ publishedAt: number;
271
+ titleHash: Uint8Array;
272
+ bodyHash: Uint8Array;
273
+ }
274
+ export declare const channelPostStructure: Structure<ChannelPostFields>;
275
+ export declare const channelPostBytes: (fields: ChannelPostFields) => Uint8Array;
276
+ export interface ChannelPostAckFields {
277
+ serverId: Uint8Array;
278
+ channelId: Uint8Array;
279
+ position: number;
280
+ postHash: Uint8Array;
281
+ time: number;
282
+ }
283
+ export declare const channelPostAckStructure: Structure<ChannelPostAckFields>;
284
+ export declare const channelPostAckBytes: (fields: ChannelPostAckFields) => Uint8Array;
285
+ export interface ChannelStateFields {
286
+ serverId: Uint8Array;
287
+ channelId: Uint8Array;
288
+ firstHeld: number;
289
+ tip: number;
290
+ time: number;
291
+ }
292
+ export declare const channelStateStructure: Structure<ChannelStateFields>;
293
+ export declare const channelStateBytes: (fields: ChannelStateFields) => Uint8Array;
294
+ export interface ChannelMemberKeyFields {
295
+ channelId: Uint8Array;
296
+ agentId: Uint8Array;
297
+ x25519Public: Uint8Array;
298
+ mlKemPublic: Uint8Array;
299
+ requestedAt: number;
300
+ }
301
+ export declare const channelMemberKeyStructure: Structure<ChannelMemberKeyFields>;
302
+ export declare const channelMemberKeyBytes: (fields: ChannelMemberKeyFields) => Uint8Array;
303
+ export interface ChannelRosterFields {
304
+ channelId: Uint8Array;
305
+ revision: number;
306
+ generation: number;
307
+ prevHash: Uint8Array;
308
+ membersHash: Uint8Array;
309
+ }
310
+ export declare const channelRosterStructure: Structure<ChannelRosterFields>;
311
+ export declare const channelRosterBytes: (fields: ChannelRosterFields) => Uint8Array;
312
+ export interface ChannelKeyEntryFields {
313
+ channelId: Uint8Array;
314
+ generation: number;
315
+ memberId: Uint8Array;
316
+ rosterHash: Uint8Array;
317
+ sealedHash: Uint8Array;
318
+ }
319
+ export declare const channelKeyEntryStructure: Structure<ChannelKeyEntryFields>;
320
+ export declare const channelKeyEntryBytes: (fields: ChannelKeyEntryFields) => Uint8Array;
321
+ export interface Body {
322
+ n: Uint8Array;
323
+ text: string;
324
+ signal: "over" | "standby" | "wrap" | null;
325
+ est_minutes: number | null;
326
+ one_message?: true;
327
+ }
328
+ export declare const bodyStructure: Structure<{
329
+ n: Uint8Array;
330
+ text: string;
331
+ signal: string | null;
332
+ estSeconds: number | null;
333
+ oneMessage: number;
334
+ }>;
335
+ export declare function bodyBytes(b: Body): Uint8Array;
336
+ export declare function readBodyBytes(bytes: Uint8Array): Body | null;
337
+ export declare const identityStructure: Structure<{
338
+ ed: Uint8Array;
339
+ pq: Uint8Array;
340
+ }>;
341
+ export declare const identityBytes: (pub: {
342
+ ed: Uint8Array;
343
+ pq: Uint8Array;
344
+ }) => Uint8Array;
345
+ export declare const rosterMemberStructure: Structure<{
346
+ ed: Uint8Array;
347
+ pq: Uint8Array;
348
+ memberKey: Uint8Array;
349
+ signatureEd: Uint8Array;
350
+ signaturePq: Uint8Array;
351
+ }>;
352
+ export declare const rosterMemberBytes: (m: {
353
+ ed: Uint8Array;
354
+ pq: Uint8Array;
355
+ memberKey: Uint8Array;
356
+ signatureEd: Uint8Array;
357
+ signaturePq: Uint8Array;
358
+ }) => Uint8Array;
359
+ export declare function rosterMembersBytes(memberHashes: readonly Uint8Array[]): Uint8Array;
@@ -0,0 +1,296 @@
1
+ // The exact bytes each party signs. The wire format can change without touching these.
2
+ import { sha256 } from "@noble/hashes/sha2.js";
3
+ import { decodeCbor, encodeCbor } from "./cbor.js";
4
+ import { HASH_BYTES, SESSION_ID_BYTES } from "./encode.js";
5
+ import { ML_KEM_CIPHERTEXT_BYTES, ML_KEM_PUBLIC_KEY_BYTES } from "./ml-kem.js";
6
+ // A record names its own format in its tag, in slot 0, so a later change to the wire or the format leaves old records verifiable.
7
+ // Unknown tags are refused as an unknown format, never as a forgery.
8
+ export class UnknownFormat extends RangeError {
9
+ }
10
+ // Every structure here is a flat array, so this walks every item before cbor-x sees it. That decoder allocates an array's declared
11
+ // length before reading it: measured, 8 KB of nested headers costs 1 GB. Floats and tags fail here too, so a signed number is never a float.
12
+ // Booleans are refused unless a format asks for them, and a null arity means any length: the caller checks each slot.
13
+ export function assertFlat(bytes, arity, options = {}) {
14
+ const fail = () => { throw new RangeError("this isn't a flat CBOR array of the expected length"); };
15
+ const head = (at) => {
16
+ const first = bytes[at] ?? fail();
17
+ const info = first & 0x1f;
18
+ const major = first >> 5;
19
+ if (info < 24)
20
+ return { major, value: info, next: at + 1 };
21
+ if (info > 27)
22
+ return fail();
23
+ const width = 2 ** (info - 24);
24
+ if (at + 1 + width > bytes.length)
25
+ fail();
26
+ let value = 0;
27
+ for (let i = 0; i < width; i++)
28
+ value = value * 256 + bytes[at + 1 + i];
29
+ return { major, value, next: at + 1 + width };
30
+ };
31
+ const top = head(0);
32
+ if (top.major !== 4 || (arity !== null && top.value !== arity))
33
+ fail();
34
+ let at = top.next;
35
+ for (let i = 0; i < top.value; i++) {
36
+ if (bytes[at] === 0xf6 || (options.booleans && (bytes[at] === 0xf4 || bytes[at] === 0xf5))) {
37
+ at += 1;
38
+ continue;
39
+ }
40
+ const item = head(at);
41
+ if (item.major === 0)
42
+ at = item.next;
43
+ else if (item.major === 2 || item.major === 3)
44
+ at = item.next + item.value;
45
+ else
46
+ fail();
47
+ if (at > bytes.length)
48
+ fail();
49
+ }
50
+ if (at !== bytes.length)
51
+ fail();
52
+ }
53
+ // Integers above 2^32-1 go as a CBOR bigint. cbor-x writes a larger plain number as a float64, and two implementations
54
+ // that disagree about which they emit produce different signed bytes for the same value.
55
+ function toCborInt(name, value) {
56
+ if (!Number.isSafeInteger(value) || value < 0)
57
+ throw new RangeError(`${name} isn't an integer this code can hold exactly: ${value}`);
58
+ return value > 0xffffffff ? BigInt(value) : value;
59
+ }
60
+ function fromCborInt(name, value) {
61
+ const asNumber = typeof value === "bigint" && value <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(value) : value;
62
+ if (typeof asNumber !== "number" || !Number.isSafeInteger(asNumber) || asNumber < 0)
63
+ throw new RangeError(`${name} isn't an integer this code can hold exactly`);
64
+ return asNumber;
65
+ }
66
+ const DEFAULT_MAX_BYTES = 8_192;
67
+ function structure(tag, slots, options = {}) {
68
+ const keys = Object.keys(slots);
69
+ const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
70
+ const width = (key, value) => {
71
+ const slot = slots[key];
72
+ if (!(value instanceof Uint8Array) || (typeof slot === "number" && value.length !== slot)) {
73
+ throw new RangeError(`${key} must be ${typeof slot === "number" ? `${slot} ` : ""}bytes, got ${value instanceof Uint8Array ? value.length : "none"}`);
74
+ }
75
+ return value;
76
+ };
77
+ return {
78
+ tag,
79
+ encode(fields) {
80
+ options.check?.(fields);
81
+ const items = [tag];
82
+ for (const key of keys) {
83
+ const slot = slots[key];
84
+ const value = fields[key];
85
+ if (slot === "int")
86
+ items.push(toCborInt(key, value));
87
+ else if (slot === "intOrNull")
88
+ items.push(value === null ? null : toCborInt(key, value));
89
+ else if (slot === "text" || slot === "textOrNull") {
90
+ if (typeof value !== "string" && !(slot === "textOrNull" && value === null))
91
+ throw new RangeError(`${key} must be text`);
92
+ items.push(value);
93
+ }
94
+ else
95
+ items.push(width(key, value));
96
+ }
97
+ return new Uint8Array(encodeCbor(items));
98
+ },
99
+ decode(bytes) {
100
+ if (bytes.length > maxBytes)
101
+ throw new RangeError(`${tag} can't be over ${maxBytes} bytes`);
102
+ assertFlat(bytes, keys.length + 1);
103
+ const items = decodeCbor(bytes);
104
+ if (items[0] !== tag)
105
+ throw new UnknownFormat(`this is ${typeof items[0] === "string" ? items[0].slice(0, 64) : "unnamed"}, and ${tag} was expected`);
106
+ const out = {};
107
+ keys.forEach((key, i) => {
108
+ const slot = slots[key];
109
+ const value = items[i + 1];
110
+ if (slot === "int")
111
+ out[key] = fromCborInt(key, value);
112
+ else if (slot === "intOrNull")
113
+ out[key] = value === null ? null : fromCborInt(key, value);
114
+ else if (slot === "text" || slot === "textOrNull") {
115
+ if (typeof value !== "string" && !(slot === "textOrNull" && value === null))
116
+ throw new RangeError(`${key} must be text`);
117
+ out[key] = value;
118
+ }
119
+ else
120
+ out[key] = new Uint8Array(width(key, value instanceof Uint8Array ? new Uint8Array(value) : value));
121
+ });
122
+ options.check?.(out);
123
+ return out;
124
+ },
125
+ };
126
+ }
127
+ const X25519_PUBLIC_KEY_BYTES = 32;
128
+ const NONCE_BYTES = 32;
129
+ const ED25519_PUBLIC_KEY_WIDTH = 32;
130
+ const ML_DSA_PUBLIC_KEY_WIDTH = 1312;
131
+ export const EntryKind = { message: 1, close: 2 };
132
+ // reply: refused if something the author hasn't read has landed. notice: sent regardless.
133
+ export const EntryMode = { reply: 1, notice: 2 };
134
+ export const entryStructure = structure("cello-entry-v1", { serverId: HASH_BYTES, sessionId: SESSION_ID_BYTES, authorId: HASH_BYTES, authorSeq: "int", prevOwnHash: HASH_BYTES, readPosition: "int", readRoot: HASH_BYTES, kind: "int", mode: "int", contentHash: HASH_BYTES, ciphertextHash: HASH_BYTES, notAfter: "int" }, { check: (e) => {
135
+ if (!Object.values(EntryKind).includes(e.kind))
136
+ throw new RangeError(`unknown entry kind: ${e.kind}`);
137
+ if (!Object.values(EntryMode).includes(e.mode))
138
+ throw new RangeError(`unknown entry mode: ${e.mode}`);
139
+ } });
140
+ export const entryBytes = (fields) => entryStructure.encode(fields);
141
+ // For an entry this machine is about to sign. A received one is hashed over its bytes as received.
142
+ export function entryHash(e) {
143
+ return sha256(entryBytes(e));
144
+ }
145
+ export function ciphertextHash(ciphertext) {
146
+ return sha256(ciphertext);
147
+ }
148
+ export const ackStructure = structure("cello-ack-v1", { serverId: HASH_BYTES, sessionId: SESSION_ID_BYTES, position: "int", entryHash: HASH_BYTES, root: HASH_BYTES, time: "int" });
149
+ export const ackBytes = (fields) => ackStructure.encode(fields);
150
+ export const MAX_REFUSED_POSITIONS = 512;
151
+ export function refusedList(positions) {
152
+ const out = new Uint8Array(positions.length * 8);
153
+ const view = new DataView(out.buffer);
154
+ positions.forEach((position, i) => view.setBigUint64(i * 8, BigInt(position)));
155
+ return out;
156
+ }
157
+ export function readRefusedList(bytes) {
158
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.length);
159
+ return Array.from({ length: bytes.length / 8 }, (_, i) => Number(view.getBigUint64(i * 8)));
160
+ }
161
+ export const deliveryAckStructure = structure("cello-delivery-ack-v1", { serverId: HASH_BYTES, sessionId: SESSION_ID_BYTES, readerId: HASH_BYTES, throughPosition: "int", entryHash: HASH_BYTES, root: HASH_BYTES, screenedThrough: "int", refused: "bytes" }, { check: (d) => {
162
+ if (d.screenedThrough > d.throughPosition)
163
+ throw new RangeError(`a delivery ack can't say it screened through ${d.screenedThrough} when it only covers ${d.throughPosition}`);
164
+ if (d.refused.length % 8 !== 0 || d.refused.length > MAX_REFUSED_POSITIONS * 8)
165
+ throw new RangeError("the refused list must be whole positions, within its limit");
166
+ let last = 0;
167
+ for (const position of readRefusedList(d.refused)) {
168
+ if (!Number.isSafeInteger(position) || position <= last || position > d.throughPosition)
169
+ throw new RangeError("the refused list must ascend, within what the ack covers");
170
+ last = position;
171
+ }
172
+ } });
173
+ export const deliveryAckBytes = (fields) => deliveryAckStructure.encode(fields);
174
+ const MAX_NAME_BYTES = 64;
175
+ export const registerStructure = structure("cello-register-v1", { serverId: HASH_BYTES, ed: ED25519_PUBLIC_KEY_WIDTH, pq: ML_DSA_PUBLIC_KEY_WIDTH });
176
+ export const registerBytes = (r) => registerStructure.encode({ serverId: r.serverId, ed: r.identity.ed, pq: r.identity.pq });
177
+ export const agentAuthStructure = structure("cello-agent-auth-v1", { serverId: HASH_BYTES, agentId: HASH_BYTES, serverNonce: NONCE_BYTES, clientNonce: NONCE_BYTES });
178
+ export const agentAuthBytes = (fields) => agentAuthStructure.encode(fields);
179
+ export const serverAuthStructure = structure("cello-server-auth-v1", { serverId: HASH_BYTES, clientNonce: NONCE_BYTES, serverNonce: NONCE_BYTES });
180
+ export const serverAuthBytes = (fields) => serverAuthStructure.encode(fields);
181
+ // The most signals one side presents with a call, and the most its sealed box may hold. The structures that carry them are capped a little above.
182
+ export const MAX_PRESENTED_SIGNALS = 8;
183
+ export const MAX_PRESENTED_BYTES = 65_536;
184
+ const PRESENTING_STRUCTURE_MAX_BYTES = 70_000;
185
+ export const encryptionKeyStructure = structure("cello-agent-encryption-key-v1", { agentId: HASH_BYTES, mlKemPublic: ML_KEM_PUBLIC_KEY_BYTES, revision: "int", issuedAt: "int" });
186
+ export const encryptionKeyBytes = (fields) => encryptionKeyStructure.encode(fields);
187
+ // Both or neither: a ciphertext with no box, or a box with no key to open it, is something else.
188
+ function presentedCheck(box, name) {
189
+ if (box.length > MAX_PRESENTED_BYTES)
190
+ throw new RangeError(`${name} can't be over ${MAX_PRESENTED_BYTES} bytes, and this is ${box.length}`);
191
+ }
192
+ export const offerStructure = structure("cello-session-offer-v1", { serverId: HASH_BYTES, sessionId: SESSION_ID_BYTES, callerId: HASH_BYTES, calleeId: HASH_BYTES, x25519Public: X25519_PUBLIC_KEY_BYTES, mlKemPublic: ML_KEM_PUBLIC_KEY_BYTES, expiresAt: "int", signalsCiphertext: "bytes", sealedSignals: "bytes" }, {
193
+ maxBytes: PRESENTING_STRUCTURE_MAX_BYTES,
194
+ check: (o) => {
195
+ if (o.signalsCiphertext.length !== 0 && o.signalsCiphertext.length !== ML_KEM_CIPHERTEXT_BYTES)
196
+ throw new RangeError(`signalsCiphertext must be empty or ${ML_KEM_CIPHERTEXT_BYTES} bytes, and this is ${o.signalsCiphertext.length}`);
197
+ if ((o.signalsCiphertext.length === 0) !== (o.sealedSignals.length === 0))
198
+ throw new RangeError("signalsCiphertext and sealedSignals must both be present or both be empty");
199
+ presentedCheck(o.sealedSignals, "sealedSignals");
200
+ },
201
+ });
202
+ export const offerBytes = (fields) => offerStructure.encode(fields);
203
+ export const acceptStructure = structure("cello-session-accept-v1", { offerHash: HASH_BYTES, x25519Public: X25519_PUBLIC_KEY_BYTES, mlKemCiphertext: ML_KEM_CIPHERTEXT_BYTES, sealedSalt: "bytes", sealedName: "bytes", sealedSignals: "bytes" }, {
204
+ maxBytes: PRESENTING_STRUCTURE_MAX_BYTES,
205
+ check: (a) => presentedCheck(a.sealedSignals, "sealedSignals"),
206
+ });
207
+ export const acceptBytes = (fields) => acceptStructure.encode(fields);
208
+ export const refuseStructure = structure("cello-session-refuse-v1", { offerHash: HASH_BYTES, mlKemCiphertext: ML_KEM_CIPHERTEXT_BYTES, sealedReason: "bytes" }, { maxBytes: 500_000 });
209
+ export const refuseBytes = (fields) => refuseStructure.encode(fields);
210
+ export const greetingStructure = structure("cello-session-greeting-v1", { offerHash: HASH_BYTES, sealedText: "bytes" }, { maxBytes: 500_000 });
211
+ export const greetingBytes = (fields) => greetingStructure.encode(fields);
212
+ export const confirmStructure = structure("cello-session-confirm-v1", { acceptHash: HASH_BYTES, sealedSalt: "bytes", sealedName: "bytes" });
213
+ export const confirmBytes = (fields) => confirmStructure.encode(fields);
214
+ export const assignmentStructure = structure("cello-session-assignment-v1", { serverId: HASH_BYTES, sessionId: SESSION_ID_BYTES, callerId: HASH_BYTES, calleeId: HASH_BYTES, confirmHash: HASH_BYTES, time: "int" });
215
+ export const assignmentBytes = (fields) => assignmentStructure.encode(fields);
216
+ export const sealRequestStructure = structure("cello-seal-request-v1", { serverId: HASH_BYTES, sessionId: SESSION_ID_BYTES, sealerId: HASH_BYTES, counterpartyId: HASH_BYTES, throughPosition: "int", root: HASH_BYTES });
217
+ export const sealRequestBytes = (fields) => sealRequestStructure.encode(fields);
218
+ export const sealCertificateStructure = structure("cello-seal-certificate-v1", { sealKeyId: HASH_BYTES, serverId: HASH_BYTES, sessionId: SESSION_ID_BYTES, sealerId: HASH_BYTES, counterpartyId: HASH_BYTES, requestHash: HASH_BYTES, root: HASH_BYTES, throughPosition: "int", tip: "int", closed: "int", receivedThrough: "int", deliveryAckHash: HASH_BYTES, time: "int" }, { check: (c) => {
219
+ if (c.closed !== 0 && c.closed !== 1)
220
+ throw new RangeError(`closed must be 0 or 1, got ${c.closed}`);
221
+ } });
222
+ export const sealCertificateBytes = (fields) => sealCertificateStructure.encode(fields);
223
+ export const sealLogHeadStructure = structure("cello-seal-log-head-v1", { sealKeyId: HASH_BYTES, size: "int", root: HASH_BYTES, time: "int" });
224
+ export const sealLogHeadBytes = (fields) => sealLogHeadStructure.encode(fields);
225
+ export const sealKeyBindingStructure = structure("cello-seal-key-binding-v1", { serverId: HASH_BYTES, sealKeyId: HASH_BYTES });
226
+ export const sealKeyBindingBytes = (fields) => sealKeyBindingStructure.encode(fields);
227
+ export function structureHash(bytes) {
228
+ return sha256(bytes);
229
+ }
230
+ // ---- An agent's status ----
231
+ export const AgentStatus = { active: 1, suspended: 2, retired: 3 };
232
+ export const StatusReason = { none: 0, owner_request: 1, lost_machine: 2, compromise: 3 };
233
+ // Who signed. agent: the identity's own keys. portal: a key a server is configured to trust. server: that server's operator, good on that server only.
234
+ export const StatusIssuer = { agent: 1, portal: 2, server: 3 };
235
+ export const statusStatementStructure = structure("cello-agent-status-v1", { agentId: HASH_BYTES, status: "int", reason: "int", issuer: "int", issuerId: HASH_BYTES, issuedAt: "int" }, { check: (s) => {
236
+ if (!Object.values(AgentStatus).includes(s.status))
237
+ throw new RangeError(`unknown agent status: ${s.status}`);
238
+ if (!Object.values(StatusReason).includes(s.reason))
239
+ throw new RangeError(`unknown status reason: ${s.reason}`);
240
+ if (!Object.values(StatusIssuer).includes(s.issuer))
241
+ throw new RangeError(`unknown status issuer: ${s.issuer}`);
242
+ } });
243
+ export const statusStatementBytes = (fields) => statusStatementStructure.encode(fields);
244
+ export const statusWitnessStructure = structure("cello-agent-status-witness-v1", { serverId: HASH_BYTES, agentId: HASH_BYTES, seq: "int", prevHash: HASH_BYTES, statementHash: HASH_BYTES, time: "int" });
245
+ export const statusWitnessBytes = (fields) => statusWitnessStructure.encode(fields);
246
+ export const ChannelVisibility = { public: 1, private: 2 };
247
+ export const ChannelPosting = { admin: 1, posters: 2, members: 3 };
248
+ export const channelRecordStructure = structure("cello-channel-record-v1", { channelId: HASH_BYTES, adminId: HASH_BYTES, visibility: "int" });
249
+ export const channelRecordBytes = (fields) => channelRecordStructure.encode(fields);
250
+ export const channelInfoStructure = structure("cello-channel-info-v1", { channelId: HASH_BYTES, revision: "int", posting: "int", retentionMs: "int", generation: "int", x25519Public: X25519_PUBLIC_KEY_BYTES, mlKemPublic: ML_KEM_PUBLIC_KEY_BYTES, posters: "bytes", name: "bytes" }, { maxBytes: 2_000_000, check: (i) => {
251
+ if (i.posters.length % HASH_BYTES !== 0)
252
+ throw new RangeError("the poster list must be whole ids");
253
+ if (i.name.length === 0 || i.name.length > MAX_NAME_BYTES)
254
+ throw new RangeError(`a channel name must be 1 to ${MAX_NAME_BYTES} bytes`);
255
+ } });
256
+ export const channelInfoBytes = (fields) => channelInfoStructure.encode(fields);
257
+ export const channelPostStructure = structure("cello-channel-post-v1", { channelId: HASH_BYTES, generation: "int", authorId: HASH_BYTES, authorSeq: "int", publishedAt: "int", titleHash: HASH_BYTES, bodyHash: HASH_BYTES });
258
+ export const channelPostBytes = (fields) => channelPostStructure.encode(fields);
259
+ export const channelPostAckStructure = structure("cello-channel-post-ack-v1", { serverId: HASH_BYTES, channelId: HASH_BYTES, position: "int", postHash: HASH_BYTES, time: "int" });
260
+ export const channelPostAckBytes = (fields) => channelPostAckStructure.encode(fields);
261
+ export const channelStateStructure = structure("cello-channel-state-v1", { serverId: HASH_BYTES, channelId: HASH_BYTES, firstHeld: "int", tip: "int", time: "int" });
262
+ export const channelStateBytes = (fields) => channelStateStructure.encode(fields);
263
+ export const channelMemberKeyStructure = structure("cello-channel-member-key-v1", { channelId: HASH_BYTES, agentId: HASH_BYTES, x25519Public: X25519_PUBLIC_KEY_BYTES, mlKemPublic: ML_KEM_PUBLIC_KEY_BYTES, requestedAt: "int" });
264
+ export const channelMemberKeyBytes = (fields) => channelMemberKeyStructure.encode(fields);
265
+ export const channelRosterStructure = structure("cello-channel-roster-v1", { channelId: HASH_BYTES, revision: "int", generation: "int", prevHash: HASH_BYTES, membersHash: HASH_BYTES });
266
+ export const channelRosterBytes = (fields) => channelRosterStructure.encode(fields);
267
+ export const channelKeyEntryStructure = structure("cello-channel-key-entry-v1", { channelId: HASH_BYTES, generation: "int", memberId: HASH_BYTES, rosterHash: HASH_BYTES, sealedHash: HASH_BYTES });
268
+ export const channelKeyEntryBytes = (fields) => channelKeyEntryStructure.encode(fields);
269
+ export const bodyStructure = structure("cello-body-v1", { n: "bytes", text: "text", signal: "textOrNull", estSeconds: "intOrNull", oneMessage: "int" }, { maxBytes: 1_100_000 });
270
+ export function bodyBytes(b) {
271
+ return bodyStructure.encode({ n: b.n, text: b.text, signal: b.signal, estSeconds: b.est_minutes === null ? null : Math.ceil(b.est_minutes * 60), oneMessage: b.one_message ? 1 : 0 });
272
+ }
273
+ // Null for anything that isn't exactly what a CELLO client writes.
274
+ export function readBodyBytes(bytes) {
275
+ try {
276
+ const b = bodyStructure.decode(bytes);
277
+ if (b.signal !== null && b.signal !== "over" && b.signal !== "standby" && b.signal !== "wrap")
278
+ return null;
279
+ if (b.oneMessage !== 0 && b.oneMessage !== 1)
280
+ return null;
281
+ return { n: b.n, text: b.text, signal: b.signal, est_minutes: b.estSeconds === null ? null : b.estSeconds / 60, ...(b.oneMessage === 1 ? { one_message: true } : {}) };
282
+ }
283
+ catch {
284
+ return null;
285
+ }
286
+ }
287
+ export const identityStructure = structure("cello-identity-v1", { ed: ED25519_PUBLIC_KEY_WIDTH, pq: ML_DSA_PUBLIC_KEY_WIDTH });
288
+ export const identityBytes = (pub) => identityStructure.encode({ ed: pub.ed, pq: pub.pq });
289
+ // One roster member: what they signed, exactly as they signed it, with their keys and signature.
290
+ export const rosterMemberStructure = structure("cello-channel-member-v1", { ed: ED25519_PUBLIC_KEY_WIDTH, pq: ML_DSA_PUBLIC_KEY_WIDTH, memberKey: "bytes", signatureEd: "bytes", signaturePq: "bytes" });
291
+ export const rosterMemberBytes = (m) => rosterMemberStructure.encode(m);
292
+ const rosterMembersTag = "cello-channel-members-v1";
293
+ // A list of any length, so it's hashed as its members' hashes: tag, then each 32-byte hash, in order.
294
+ export function rosterMembersBytes(memberHashes) {
295
+ return new Uint8Array(encodeCbor([rosterMembersTag, ...memberHashes]));
296
+ }