@meshline/sdk 0.0.0-stage → 0.1.0-alpha.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 (338) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +43 -2
  3. package/dist/channels/repository.d.ts +73 -0
  4. package/dist/channels/repository.d.ts.map +1 -0
  5. package/dist/channels/repository.js +367 -0
  6. package/dist/channels/repository.js.map +1 -0
  7. package/dist/client/account-operations.d.ts +41 -0
  8. package/dist/client/account-operations.d.ts.map +1 -0
  9. package/dist/client/account-operations.js +304 -0
  10. package/dist/client/account-operations.js.map +1 -0
  11. package/dist/client/conversations.d.ts +36 -0
  12. package/dist/client/conversations.d.ts.map +1 -0
  13. package/dist/client/conversations.js +144 -0
  14. package/dist/client/conversations.js.map +1 -0
  15. package/dist/client.d.ts +53 -0
  16. package/dist/client.d.ts.map +1 -0
  17. package/dist/client.js +162 -0
  18. package/dist/client.js.map +1 -0
  19. package/dist/components/account.d.ts +38 -0
  20. package/dist/components/account.d.ts.map +1 -0
  21. package/dist/components/account.js +243 -0
  22. package/dist/components/account.js.map +1 -0
  23. package/dist/components/channel.d.ts +78 -0
  24. package/dist/components/channel.d.ts.map +1 -0
  25. package/dist/components/channel.js +475 -0
  26. package/dist/components/channel.js.map +1 -0
  27. package/dist/components/component.d.ts +49 -0
  28. package/dist/components/component.d.ts.map +1 -0
  29. package/dist/components/component.js +194 -0
  30. package/dist/components/component.js.map +1 -0
  31. package/dist/components/device.d.ts +60 -0
  32. package/dist/components/device.d.ts.map +1 -0
  33. package/dist/components/device.js +648 -0
  34. package/dist/components/device.js.map +1 -0
  35. package/dist/components/group.d.ts +141 -0
  36. package/dist/components/group.d.ts.map +1 -0
  37. package/dist/components/group.js +933 -0
  38. package/dist/components/group.js.map +1 -0
  39. package/dist/components/message.d.ts +63 -0
  40. package/dist/components/message.d.ts.map +1 -0
  41. package/dist/components/message.js +439 -0
  42. package/dist/components/message.js.map +1 -0
  43. package/dist/components/profile.d.ts +37 -0
  44. package/dist/components/profile.d.ts.map +1 -0
  45. package/dist/components/profile.js +232 -0
  46. package/dist/components/profile.js.map +1 -0
  47. package/dist/crypto/groups.d.ts +56 -0
  48. package/dist/crypto/groups.d.ts.map +1 -0
  49. package/dist/crypto/groups.js +163 -0
  50. package/dist/crypto/groups.js.map +1 -0
  51. package/dist/crypto/messages.d.ts +52 -0
  52. package/dist/crypto/messages.d.ts.map +1 -0
  53. package/dist/crypto/messages.js +180 -0
  54. package/dist/crypto/messages.js.map +1 -0
  55. package/dist/crypto/primitives.d.ts +30 -0
  56. package/dist/crypto/primitives.d.ts.map +1 -0
  57. package/dist/crypto/primitives.js +102 -0
  58. package/dist/crypto/primitives.js.map +1 -0
  59. package/dist/errors.d.ts +11 -0
  60. package/dist/errors.d.ts.map +1 -0
  61. package/dist/errors.js +14 -0
  62. package/dist/errors.js.map +1 -0
  63. package/dist/groups/account-sync.d.ts +28 -0
  64. package/dist/groups/account-sync.d.ts.map +1 -0
  65. package/dist/groups/account-sync.js +235 -0
  66. package/dist/groups/account-sync.js.map +1 -0
  67. package/dist/groups/messages.d.ts +39 -0
  68. package/dist/groups/messages.d.ts.map +1 -0
  69. package/dist/groups/messages.js +141 -0
  70. package/dist/groups/messages.js.map +1 -0
  71. package/dist/groups/operations.d.ts +57 -0
  72. package/dist/groups/operations.d.ts.map +1 -0
  73. package/dist/groups/operations.js +225 -0
  74. package/dist/groups/operations.js.map +1 -0
  75. package/dist/groups/repository.d.ts +56 -0
  76. package/dist/groups/repository.d.ts.map +1 -0
  77. package/dist/groups/repository.js +254 -0
  78. package/dist/groups/repository.js.map +1 -0
  79. package/dist/groups/secrets.d.ts +67 -0
  80. package/dist/groups/secrets.d.ts.map +1 -0
  81. package/dist/groups/secrets.js +452 -0
  82. package/dist/groups/secrets.js.map +1 -0
  83. package/dist/groups/state.d.ts +39 -0
  84. package/dist/groups/state.d.ts.map +1 -0
  85. package/dist/groups/state.js +201 -0
  86. package/dist/groups/state.js.map +1 -0
  87. package/dist/identity/identifiers.d.ts +9 -0
  88. package/dist/identity/identifiers.d.ts.map +1 -0
  89. package/dist/identity/identifiers.js +37 -0
  90. package/dist/identity/identifiers.js.map +1 -0
  91. package/dist/identity/neo.d.ts +11 -0
  92. package/dist/identity/neo.d.ts.map +1 -0
  93. package/dist/identity/neo.js +77 -0
  94. package/dist/identity/neo.js.map +1 -0
  95. package/dist/index.d.ts +53 -0
  96. package/dist/index.d.ts.map +1 -0
  97. package/dist/index.js +46 -0
  98. package/dist/index.js.map +1 -0
  99. package/dist/interactions.d.ts +31 -0
  100. package/dist/interactions.d.ts.map +1 -0
  101. package/dist/interactions.js +2 -0
  102. package/dist/interactions.js.map +1 -0
  103. package/dist/messages/account-sender.d.ts +9 -0
  104. package/dist/messages/account-sender.d.ts.map +1 -0
  105. package/dist/messages/account-sender.js +46 -0
  106. package/dist/messages/account-sender.js.map +1 -0
  107. package/dist/messages/contacts.d.ts +103 -0
  108. package/dist/messages/contacts.d.ts.map +1 -0
  109. package/dist/messages/contacts.js +525 -0
  110. package/dist/messages/contacts.js.map +1 -0
  111. package/dist/messages/outbox.d.ts +66 -0
  112. package/dist/messages/outbox.d.ts.map +1 -0
  113. package/dist/messages/outbox.js +167 -0
  114. package/dist/messages/outbox.js.map +1 -0
  115. package/dist/messages/receiver.d.ts +35 -0
  116. package/dist/messages/receiver.d.ts.map +1 -0
  117. package/dist/messages/receiver.js +113 -0
  118. package/dist/messages/receiver.js.map +1 -0
  119. package/dist/messages/repository.d.ts +89 -0
  120. package/dist/messages/repository.d.ts.map +1 -0
  121. package/dist/messages/repository.js +295 -0
  122. package/dist/messages/repository.js.map +1 -0
  123. package/dist/models/authentication.d.ts +37 -0
  124. package/dist/models/authentication.d.ts.map +1 -0
  125. package/dist/models/authentication.js +53 -0
  126. package/dist/models/authentication.js.map +1 -0
  127. package/dist/models/channels.d.ts +141 -0
  128. package/dist/models/channels.d.ts.map +1 -0
  129. package/dist/models/channels.js +258 -0
  130. package/dist/models/channels.js.map +1 -0
  131. package/dist/models/contacts.d.ts +68 -0
  132. package/dist/models/contacts.d.ts.map +1 -0
  133. package/dist/models/contacts.js +186 -0
  134. package/dist/models/contacts.js.map +1 -0
  135. package/dist/models/content.d.ts +37 -0
  136. package/dist/models/content.d.ts.map +1 -0
  137. package/dist/models/content.js +137 -0
  138. package/dist/models/content.js.map +1 -0
  139. package/dist/models/device-state.d.ts +8 -0
  140. package/dist/models/device-state.d.ts.map +1 -0
  141. package/dist/models/device-state.js +22 -0
  142. package/dist/models/device-state.js.map +1 -0
  143. package/dist/models/group-admission.d.ts +111 -0
  144. package/dist/models/group-admission.d.ts.map +1 -0
  145. package/dist/models/group-admission.js +153 -0
  146. package/dist/models/group-admission.js.map +1 -0
  147. package/dist/models/group-keys.d.ts +30 -0
  148. package/dist/models/group-keys.d.ts.map +1 -0
  149. package/dist/models/group-keys.js +52 -0
  150. package/dist/models/group-keys.js.map +1 -0
  151. package/dist/models/group-management.d.ts +190 -0
  152. package/dist/models/group-management.d.ts.map +1 -0
  153. package/dist/models/group-management.js +263 -0
  154. package/dist/models/group-management.js.map +1 -0
  155. package/dist/models/groups.d.ts +81 -0
  156. package/dist/models/groups.d.ts.map +1 -0
  157. package/dist/models/groups.js +127 -0
  158. package/dist/models/groups.js.map +1 -0
  159. package/dist/models/identity.d.ts +47 -0
  160. package/dist/models/identity.d.ts.map +1 -0
  161. package/dist/models/identity.js +136 -0
  162. package/dist/models/identity.js.map +1 -0
  163. package/dist/models/messages.d.ts +104 -0
  164. package/dist/models/messages.d.ts.map +1 -0
  165. package/dist/models/messages.js +168 -0
  166. package/dist/models/messages.js.map +1 -0
  167. package/dist/models/profile.d.ts +24 -0
  168. package/dist/models/profile.d.ts.map +1 -0
  169. package/dist/models/profile.js +47 -0
  170. package/dist/models/profile.js.map +1 -0
  171. package/dist/models/relay.d.ts +39 -0
  172. package/dist/models/relay.d.ts.map +1 -0
  173. package/dist/models/relay.js +160 -0
  174. package/dist/models/relay.js.map +1 -0
  175. package/dist/protocol/codec.d.ts +36 -0
  176. package/dist/protocol/codec.d.ts.map +1 -0
  177. package/dist/protocol/codec.js +144 -0
  178. package/dist/protocol/codec.js.map +1 -0
  179. package/dist/protocol/context.d.ts +14 -0
  180. package/dist/protocol/context.d.ts.map +1 -0
  181. package/dist/protocol/context.js +43 -0
  182. package/dist/protocol/context.js.map +1 -0
  183. package/dist/protocol/encoding.d.ts +15 -0
  184. package/dist/protocol/encoding.d.ts.map +1 -0
  185. package/dist/protocol/encoding.js +133 -0
  186. package/dist/protocol/encoding.js.map +1 -0
  187. package/dist/protocol/json.d.ts +16 -0
  188. package/dist/protocol/json.d.ts.map +1 -0
  189. package/dist/protocol/json.js +172 -0
  190. package/dist/protocol/json.js.map +1 -0
  191. package/dist/protocol/validation.d.ts +4 -0
  192. package/dist/protocol/validation.d.ts.map +1 -0
  193. package/dist/protocol/validation.js +18 -0
  194. package/dist/protocol/validation.js.map +1 -0
  195. package/dist/runtime/abort.d.ts +6 -0
  196. package/dist/runtime/abort.d.ts.map +1 -0
  197. package/dist/runtime/abort.js +32 -0
  198. package/dist/runtime/abort.js.map +1 -0
  199. package/dist/runtime/async-gate.d.ts +6 -0
  200. package/dist/runtime/async-gate.d.ts.map +1 -0
  201. package/dist/runtime/async-gate.js +15 -0
  202. package/dist/runtime/async-gate.js.map +1 -0
  203. package/dist/runtime/async-pulse.d.ts +7 -0
  204. package/dist/runtime/async-pulse.d.ts.map +1 -0
  205. package/dist/runtime/async-pulse.js +23 -0
  206. package/dist/runtime/async-pulse.js.map +1 -0
  207. package/dist/runtime/clock.d.ts +16 -0
  208. package/dist/runtime/clock.d.ts.map +1 -0
  209. package/dist/runtime/clock.js +62 -0
  210. package/dist/runtime/clock.js.map +1 -0
  211. package/dist/runtime/events.d.ts +11 -0
  212. package/dist/runtime/events.d.ts.map +1 -0
  213. package/dist/runtime/events.js +45 -0
  214. package/dist/runtime/events.js.map +1 -0
  215. package/dist/runtime/url.d.ts +3 -0
  216. package/dist/runtime/url.d.ts.map +1 -0
  217. package/dist/runtime/url.js +23 -0
  218. package/dist/runtime/url.js.map +1 -0
  219. package/dist/storage/signed-request.d.ts +14 -0
  220. package/dist/storage/signed-request.d.ts.map +1 -0
  221. package/dist/storage/signed-request.js +26 -0
  222. package/dist/storage/signed-request.js.map +1 -0
  223. package/dist/storage/store.d.ts +58 -0
  224. package/dist/storage/store.d.ts.map +1 -0
  225. package/dist/storage/store.js +52 -0
  226. package/dist/storage/store.js.map +1 -0
  227. package/dist/storage/transaction.d.ts +7 -0
  228. package/dist/storage/transaction.d.ts.map +1 -0
  229. package/dist/storage/transaction.js +22 -0
  230. package/dist/storage/transaction.js.map +1 -0
  231. package/dist/transport/client.d.ts +61 -0
  232. package/dist/transport/client.d.ts.map +1 -0
  233. package/dist/transport/client.js +392 -0
  234. package/dist/transport/client.js.map +1 -0
  235. package/dist/transport/discovery.d.ts +19 -0
  236. package/dist/transport/discovery.d.ts.map +1 -0
  237. package/dist/transport/discovery.js +75 -0
  238. package/dist/transport/discovery.js.map +1 -0
  239. package/dist/transport/endpoint.d.ts +6 -0
  240. package/dist/transport/endpoint.d.ts.map +1 -0
  241. package/dist/transport/endpoint.js +35 -0
  242. package/dist/transport/endpoint.js.map +1 -0
  243. package/dist/transport/http.d.ts +52 -0
  244. package/dist/transport/http.d.ts.map +1 -0
  245. package/dist/transport/http.js +128 -0
  246. package/dist/transport/http.js.map +1 -0
  247. package/dist/transport/pool.d.ts +31 -0
  248. package/dist/transport/pool.d.ts.map +1 -0
  249. package/dist/transport/pool.js +137 -0
  250. package/dist/transport/pool.js.map +1 -0
  251. package/dist/transport/relay-error.d.ts +23 -0
  252. package/dist/transport/relay-error.d.ts.map +1 -0
  253. package/dist/transport/relay-error.js +47 -0
  254. package/dist/transport/relay-error.js.map +1 -0
  255. package/dist/transport/rpc.d.ts +31 -0
  256. package/dist/transport/rpc.d.ts.map +1 -0
  257. package/dist/transport/rpc.js +56 -0
  258. package/dist/transport/rpc.js.map +1 -0
  259. package/dist/transport/session.d.ts +49 -0
  260. package/dist/transport/session.d.ts.map +1 -0
  261. package/dist/transport/session.js +169 -0
  262. package/dist/transport/session.js.map +1 -0
  263. package/dist/transport/socket.d.ts +55 -0
  264. package/dist/transport/socket.d.ts.map +1 -0
  265. package/dist/transport/socket.js +266 -0
  266. package/dist/transport/socket.js.map +1 -0
  267. package/dist/transport/subscription.d.ts +36 -0
  268. package/dist/transport/subscription.d.ts.map +1 -0
  269. package/dist/transport/subscription.js +169 -0
  270. package/dist/transport/subscription.js.map +1 -0
  271. package/package.json +35 -4
  272. package/src/channels/repository.ts +244 -0
  273. package/src/client/account-operations.ts +183 -0
  274. package/src/client/conversations.ts +95 -0
  275. package/src/client.ts +108 -0
  276. package/src/components/account.ts +206 -0
  277. package/src/components/channel.ts +253 -0
  278. package/src/components/component.ts +151 -0
  279. package/src/components/device.ts +455 -0
  280. package/src/components/group.ts +546 -0
  281. package/src/components/message.ts +253 -0
  282. package/src/components/profile.ts +179 -0
  283. package/src/crypto/groups.ts +107 -0
  284. package/src/crypto/messages.ts +129 -0
  285. package/src/crypto/primitives.ts +103 -0
  286. package/src/errors.ts +13 -0
  287. package/src/groups/account-sync.ts +144 -0
  288. package/src/groups/messages.ts +89 -0
  289. package/src/groups/operations.ts +145 -0
  290. package/src/groups/repository.ts +161 -0
  291. package/src/groups/secrets.ts +256 -0
  292. package/src/groups/state.ts +138 -0
  293. package/src/identity/identifiers.ts +41 -0
  294. package/src/identity/neo.ts +72 -0
  295. package/src/index.ts +52 -0
  296. package/src/interactions.ts +35 -0
  297. package/src/messages/account-sender.ts +33 -0
  298. package/src/messages/contacts.ts +379 -0
  299. package/src/messages/outbox.ts +152 -0
  300. package/src/messages/receiver.ts +86 -0
  301. package/src/messages/repository.ts +230 -0
  302. package/src/models/authentication.ts +63 -0
  303. package/src/models/channels.ts +155 -0
  304. package/src/models/contacts.ts +141 -0
  305. package/src/models/content.ts +105 -0
  306. package/src/models/device-state.ts +18 -0
  307. package/src/models/group-admission.ts +110 -0
  308. package/src/models/group-keys.ts +34 -0
  309. package/src/models/group-management.ts +182 -0
  310. package/src/models/groups.ts +100 -0
  311. package/src/models/identity.ts +164 -0
  312. package/src/models/messages.ts +139 -0
  313. package/src/models/profile.ts +46 -0
  314. package/src/models/relay.ts +151 -0
  315. package/src/protocol/codec.ts +144 -0
  316. package/src/protocol/context.ts +39 -0
  317. package/src/protocol/encoding.ts +106 -0
  318. package/src/protocol/json.ts +140 -0
  319. package/src/protocol/validation.ts +13 -0
  320. package/src/runtime/abort.ts +27 -0
  321. package/src/runtime/async-gate.ts +16 -0
  322. package/src/runtime/async-pulse.ts +20 -0
  323. package/src/runtime/clock.ts +63 -0
  324. package/src/runtime/events.ts +31 -0
  325. package/src/runtime/url.ts +17 -0
  326. package/src/storage/signed-request.ts +26 -0
  327. package/src/storage/store.ts +90 -0
  328. package/src/storage/transaction.ts +17 -0
  329. package/src/transport/client.ts +328 -0
  330. package/src/transport/discovery.ts +64 -0
  331. package/src/transport/endpoint.ts +32 -0
  332. package/src/transport/http.ts +129 -0
  333. package/src/transport/pool.ts +115 -0
  334. package/src/transport/relay-error.ts +46 -0
  335. package/src/transport/rpc.ts +56 -0
  336. package/src/transport/session.ts +154 -0
  337. package/src/transport/socket.ts +248 -0
  338. package/src/transport/subscription.ts +117 -0
@@ -0,0 +1,81 @@
1
+ import { type ExtensibleModel, type ValueCodec } from '../protocol/codec.js';
2
+ import { type NetworkContext } from '../protocol/context.js';
3
+ import { type JsonObject } from '../protocol/json.js';
4
+ import { type ContentReference, type MessageBody } from './content.js';
5
+ import { type DeviceCertificate } from './identity.js';
6
+ import { type EncryptedPayload } from './messages.js';
7
+ export interface GroupRef {
8
+ readonly groupId: string;
9
+ readonly relayId: string;
10
+ }
11
+ export declare function validateGroupRef(value: GroupRef): void;
12
+ export interface GroupSecretBox extends ExtensibleModel {
13
+ readonly alg: string;
14
+ readonly enc: Uint8Array;
15
+ readonly sealedSecret: Uint8Array;
16
+ }
17
+ export declare const groupSecretBoxCodec: import("../protocol/codec.js").ProtocolCodec<GroupSecretBox>;
18
+ export declare function validateGroupSecretBox(value: GroupSecretBox): void;
19
+ /** The sender identity is carried by the verified timeline event and certificate, never by this envelope. */
20
+ export interface GroupMessageEnvelope extends ExtensibleModel {
21
+ readonly messageId: string;
22
+ readonly groupId: string;
23
+ readonly epoch: number;
24
+ readonly createdAt: number;
25
+ readonly payload: EncryptedPayload;
26
+ readonly deviceSignature: Uint8Array;
27
+ }
28
+ export declare const groupMessageEnvelopeCodec: import("../protocol/codec.js").ProtocolCodec<GroupMessageEnvelope>;
29
+ export declare const groupMessageEnvelopeInput: (value: GroupMessageEnvelope, context: NetworkContext) => Uint8Array;
30
+ export declare function validateGroupMessageEnvelope(value: GroupMessageEnvelope): void;
31
+ /** Historical signature integrity only; membership, epoch and event ordering require verified management state. */
32
+ export declare function verifyGroupMessageEnvelope(value: GroupMessageEnvelope, sender: DeviceCertificate, signerDeviceId: string, context: NetworkContext): void;
33
+ export interface GroupMessage extends ExtensibleModel {
34
+ readonly body?: MessageBody;
35
+ readonly attachments?: readonly ContentReference[];
36
+ readonly replyToSeq?: number;
37
+ }
38
+ export declare const groupMessageCodec: import("../protocol/codec.js").ProtocolCodec<GroupMessage>;
39
+ export declare function validateGroupMessage(value: GroupMessage): void;
40
+ export interface GroupMemberNicknameUpdate extends ExtensibleModel {
41
+ readonly nickname: string | null;
42
+ }
43
+ export declare const groupMemberNicknameUpdateCodec: import("../protocol/codec.js").ProtocolCodec<GroupMemberNicknameUpdate>;
44
+ export declare function validateGroupMemberNicknameUpdate(value: GroupMemberNicknameUpdate): void;
45
+ /** Preserves authenticated but business-invalid content so the receiver can record diagnostics without stalling its cursor. */
46
+ export declare const groupPayloadCodec: ValueCodec<JsonObject>;
47
+ export declare function validateGroupPayload(value: JsonObject): void;
48
+ export interface GroupMemberKey extends ExtensibleModel {
49
+ readonly account: string;
50
+ readonly memberEncryptionPublicKey: Uint8Array;
51
+ }
52
+ export declare const groupMemberKeyCodec: import("../protocol/codec.js").ProtocolCodec<GroupMemberKey>;
53
+ export declare function validateGroupMemberKey(value: GroupMemberKey): void;
54
+ export interface GroupHistorySecret extends ExtensibleModel {
55
+ readonly groupId: string;
56
+ readonly epoch: number;
57
+ readonly applicationSecret: Uint8Array;
58
+ }
59
+ export declare const groupHistorySecretCodec: import("../protocol/codec.js").ProtocolCodec<GroupHistorySecret>;
60
+ export declare function validateGroupHistorySecret(value: GroupHistorySecret): void;
61
+ export interface GroupMemberPrivateState extends ExtensibleModel, GroupRef {
62
+ readonly memberEncryptionPrivateKey: Uint8Array;
63
+ }
64
+ export declare const groupMemberPrivateStateCodec: import("../protocol/codec.js").ProtocolCodec<GroupMemberPrivateState>;
65
+ export declare function validateGroupMemberPrivateState(value: GroupMemberPrivateState): void;
66
+ export interface AccountGroupHistorySecretSync extends ExtensibleModel {
67
+ readonly secrets: readonly GroupHistorySecret[];
68
+ }
69
+ export declare const accountGroupHistorySecretSyncCodec: import("../protocol/codec.js").ProtocolCodec<AccountGroupHistorySecretSync>;
70
+ export declare function validateAccountGroupHistorySecretSync(value: AccountGroupHistorySecretSync): void;
71
+ export interface AccountGroupPrivateStateSync extends ExtensibleModel {
72
+ readonly states: readonly GroupMemberPrivateState[];
73
+ }
74
+ export declare const accountGroupPrivateStateSyncCodec: import("../protocol/codec.js").ProtocolCodec<AccountGroupPrivateStateSync>;
75
+ export declare function validateAccountGroupPrivateStateSync(value: AccountGroupPrivateStateSync): void;
76
+ export interface AccountGroupPrivateStateRequest extends ExtensibleModel {
77
+ readonly groupId?: string;
78
+ }
79
+ export declare const accountGroupPrivateStateRequestCodec: import("../protocol/codec.js").ProtocolCodec<AccountGroupPrivateStateRequest>;
80
+ export declare function validateAccountGroupPrivateStateRequest(value: AccountGroupPrivateStateRequest): void;
81
+ //# sourceMappingURL=groups.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"groups.d.ts","sourceRoot":"","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Identifier } from '../identity/identifiers.js';
4
+ import { validateAccountId, validateRelayId } from '../identity/neo.js';
5
+ import { array, bytes, defineCodec, integer, text } from '../protocol/codec.js';
6
+ import { signingInput } from '../protocol/context.js';
7
+ import { encodeUtf8 } from '../protocol/encoding.js';
8
+ import { canonicalJson, parseJson, requireObject, requireSafeInteger } from '../protocol/json.js';
9
+ import { validateCompleteObject } from '../protocol/validation.js';
10
+ import { containsNonWhitespace, contentReferenceCodec, messageBodyCodec, validateAttachments, validateMessageBody } from './content.js';
11
+ import { certificateId, validateCertificate } from './identity.js';
12
+ import { encryptedPayloadCodec, validateEncryptedPayload } from './messages.js';
13
+ export function validateGroupRef(value) { validateIdentifier('group', value.groupId); validateRelayId(value.relayId); }
14
+ export const groupSecretBoxCodec = defineCodec({ alg: { wire: 'alg', codec: text }, enc: { wire: 'enc', codec: bytes }, sealedSecret: { wire: 'sealed_secret', codec: bytes } });
15
+ export function validateGroupSecretBox(value) {
16
+ validateCompleteObject(groupSecretBoxCodec.encode(value));
17
+ if (value.alg !== 'X25519-HKDF-SHA256-AES256GCM')
18
+ throw new ProtocolError('unsupported_algorithm', 'Unsupported group secret box algorithm.');
19
+ requireLength(value.enc, 32, 'Ephemeral public key');
20
+ requireLength(value.sealedSecret, 60, 'Sealed group secret');
21
+ }
22
+ export const groupMessageEnvelopeCodec = defineCodec({ messageId: { wire: 'message_id', codec: text }, groupId: { wire: 'group_id', codec: text },
23
+ epoch: { wire: 'epoch', codec: integer }, createdAt: { wire: 'created_at', codec: integer }, payload: { wire: 'payload', codec: encryptedPayloadCodec },
24
+ deviceSignature: { wire: 'device_signature', codec: bytes } }, 'meshline.group.message');
25
+ export const groupMessageEnvelopeInput = (value, context) => signingInput(groupMessageEnvelopeCodec.encode(value), context, ['device_signature']);
26
+ export function validateGroupMessageEnvelope(value) {
27
+ validateCompleteObject(groupMessageEnvelopeCodec.encode(value));
28
+ validateIdentifier('message', value.messageId);
29
+ validateIdentifier('group', value.groupId);
30
+ requireSafeInteger(value.epoch, 0);
31
+ requireSafeInteger(value.createdAt, 0);
32
+ requireLength(value.deviceSignature, 64, 'Group message signature');
33
+ validateEncryptedPayload(value.payload);
34
+ if (encodeUtf8(groupMessageEnvelopeCodec.stringify(value)).length > 262144)
35
+ throw new ProtocolError('invalid_size', 'Group message envelope exceeds 262144 canonical UTF-8 bytes.');
36
+ }
37
+ /** Historical signature integrity only; membership, epoch and event ordering require verified management state. */
38
+ export function verifyGroupMessageEnvelope(value, sender, signerDeviceId, context) {
39
+ validateGroupMessageEnvelope(value);
40
+ validateCertificate(sender, context);
41
+ validateIdentifier('device', signerDeviceId);
42
+ if (certificateId(sender, context) !== signerDeviceId)
43
+ throw new ProtocolError('invalid_identity', 'Group event signing certificate belongs to another device.');
44
+ if (!verifyDevice(groupMessageEnvelopeInput(value, context), value.deviceSignature, sender.signingPublicKey))
45
+ throw new ProtocolError('invalid_signature', 'Invalid group message signature.');
46
+ }
47
+ export const groupMessageCodec = defineCodec({ body: { wire: 'body', codec: messageBodyCodec, optional: true }, attachments: { wire: 'attachments', codec: array(contentReferenceCodec), optional: true },
48
+ replyToSeq: { wire: 'reply_to_seq', codec: integer, optional: true } }, 'meshline.group.message.content');
49
+ export function validateGroupMessage(value) {
50
+ validateCompleteObject(groupMessageCodec.encode(value));
51
+ if (value.body)
52
+ validateMessageBody(value.body);
53
+ if (value.attachments)
54
+ validateAttachments(value.attachments);
55
+ if (!value.body && !value.attachments?.length)
56
+ throw new ProtocolError('invalid_message', 'A group message requires a body or at least one attachment.');
57
+ if (value.replyToSeq !== undefined)
58
+ requireSafeInteger(value.replyToSeq, 1);
59
+ }
60
+ export const groupMemberNicknameUpdateCodec = defineCodec({ nickname: { wire: 'nickname', codec: text, nullable: true } }, 'meshline.group.member.nickname.update');
61
+ export function validateGroupMemberNicknameUpdate(value) {
62
+ const wire = groupMemberNicknameUpdateCodec.encode(value);
63
+ if (wire.nickname === null)
64
+ delete wire.nickname;
65
+ validateCompleteObject(wire);
66
+ if (value.nickname !== null && (!containsNonWhitespace(value.nickname) || encodeUtf8(value.nickname).length > 256))
67
+ throw new ProtocolError('invalid_nickname', 'A group nickname requires non-whitespace text and at most 256 UTF-8 bytes.');
68
+ }
69
+ /** Preserves authenticated but business-invalid content so the receiver can record diagnostics without stalling its cursor. */
70
+ export const groupPayloadCodec = {
71
+ decode(value) {
72
+ const object = requireObject(value);
73
+ const copy = requireObject(parseJson(canonicalJson(object)));
74
+ if (typeof copy.$type !== 'string')
75
+ throw new ProtocolError('invalid_type', 'Group content requires a string $type.');
76
+ const complete = { ...copy };
77
+ if (complete.$type === 'meshline.group.member.nickname.update' && complete.nickname === null)
78
+ delete complete.nickname;
79
+ validateCompleteObject(complete);
80
+ return copy;
81
+ },
82
+ encode(value) { return this.decode(value); },
83
+ };
84
+ export function validateGroupPayload(value) {
85
+ const wire = groupPayloadCodec.decode(value);
86
+ if (wire.$type === 'meshline.group.message.content')
87
+ validateGroupMessage(groupMessageCodec.decode(wire));
88
+ else if (wire.$type === 'meshline.group.member.nickname.update')
89
+ validateGroupMemberNicknameUpdate(groupMemberNicknameUpdateCodec.decode(wire));
90
+ }
91
+ export const groupMemberKeyCodec = defineCodec({ account: { wire: 'account', codec: text }, memberEncryptionPublicKey: { wire: 'member_encryption_public_key', codec: bytes } });
92
+ export function validateGroupMemberKey(value) { validateCompleteObject(groupMemberKeyCodec.encode(value)); validateAccountId(value.account); requireLength(value.memberEncryptionPublicKey, 32, 'Member encryption public key'); }
93
+ export const groupHistorySecretCodec = defineCodec({ groupId: { wire: 'group_id', codec: text }, epoch: { wire: 'epoch', codec: integer }, applicationSecret: { wire: 'application_secret', codec: bytes } });
94
+ export function validateGroupHistorySecret(value) { validateCompleteObject(groupHistorySecretCodec.encode(value)); validateIdentifier('group', value.groupId); requireSafeInteger(value.epoch, 0); requireLength(value.applicationSecret, 32, 'Epoch application secret'); }
95
+ export const groupMemberPrivateStateCodec = defineCodec({ groupId: { wire: 'group_id', codec: text }, relayId: { wire: 'relay_id', codec: text }, memberEncryptionPrivateKey: { wire: 'member_encryption_private_key', codec: bytes } });
96
+ export function validateGroupMemberPrivateState(value) { validateCompleteObject(groupMemberPrivateStateCodec.encode(value)); validateGroupRef(value); requireLength(value.memberEncryptionPrivateKey, 32, 'Member encryption private key'); }
97
+ export const accountGroupHistorySecretSyncCodec = defineCodec({ secrets: { wire: 'secrets', codec: array(groupHistorySecretCodec) } }, 'meshline.account.group.history_secret.sync');
98
+ export function validateAccountGroupHistorySecretSync(value) {
99
+ validateCompleteObject(accountGroupHistorySecretSyncCodec.encode(value));
100
+ if (!value.secrets.length)
101
+ throw new ProtocolError('invalid_size', 'History secret synchronization requires at least one secret.');
102
+ const ids = new Set();
103
+ for (const secret of value.secrets) {
104
+ validateGroupHistorySecret(secret);
105
+ const id = `${secret.groupId}|${secret.epoch}`;
106
+ if (ids.has(id))
107
+ throw new ProtocolError('duplicate_secret', 'History secret synchronization repeats a group and epoch.');
108
+ ids.add(id);
109
+ }
110
+ }
111
+ export const accountGroupPrivateStateSyncCodec = defineCodec({ states: { wire: 'states', codec: array(groupMemberPrivateStateCodec) } }, 'meshline.account.group.state.sync');
112
+ export function validateAccountGroupPrivateStateSync(value) {
113
+ validateCompleteObject(accountGroupPrivateStateSyncCodec.encode(value));
114
+ if (!value.states.length)
115
+ throw new ProtocolError('invalid_size', 'Private state synchronization requires at least one state.');
116
+ const ids = new Set();
117
+ for (const state of value.states) {
118
+ validateGroupMemberPrivateState(state);
119
+ if (ids.has(state.groupId))
120
+ throw new ProtocolError('duplicate_group', 'Private state synchronization repeats a group.');
121
+ ids.add(state.groupId);
122
+ }
123
+ }
124
+ export const accountGroupPrivateStateRequestCodec = defineCodec({ groupId: { wire: 'group_id', codec: text, optional: true } }, 'meshline.account.group.state.request');
125
+ export function validateAccountGroupPrivateStateRequest(value) { validateCompleteObject(accountGroupPrivateStateRequestCodec.encode(value)); if (value.groupId !== undefined)
126
+ validateIdentifier('group', value.groupId); }
127
+ //# sourceMappingURL=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OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { type ExtensibleModel } from '../protocol/codec.js';
2
+ import { NetworkContext } from '../protocol/context.js';
3
+ export interface DeviceCertificate extends ExtensibleModel {
4
+ readonly account: string;
5
+ readonly accountPublicKey: Uint8Array;
6
+ readonly signingPublicKey: Uint8Array;
7
+ readonly encryptionPublicKey: Uint8Array;
8
+ readonly notBefore: number;
9
+ readonly expiresAt: number;
10
+ readonly deviceSignature: Uint8Array;
11
+ readonly accountSignature: Uint8Array;
12
+ }
13
+ export declare const deviceCertificateCodec: import("../protocol/codec.js").ProtocolCodec<DeviceCertificate>;
14
+ export declare function certificateId(certificate: DeviceCertificate, context: NetworkContext): string;
15
+ export declare function certificateDeviceInput(certificate: DeviceCertificate, context: NetworkContext): Uint8Array;
16
+ export declare function certificateAccountInput(certificate: DeviceCertificate, context: NetworkContext): Uint8Array;
17
+ /** Checks complete certificate integrity; current account authorization is a separate operation. */
18
+ export declare function validateCertificate(certificate: DeviceCertificate, context: NetworkContext): void;
19
+ export interface AccountDeviceState extends ExtensibleModel {
20
+ readonly account: string;
21
+ readonly accountPublicKey: Uint8Array;
22
+ readonly revision: number;
23
+ readonly certificates: readonly DeviceCertificate[];
24
+ readonly accountSignature: Uint8Array;
25
+ }
26
+ export declare const accountDeviceStateCodec: import("../protocol/codec.js").ProtocolCodec<AccountDeviceState>;
27
+ export declare function deviceStateInput(state: AccountDeviceState, context: NetworkContext): Uint8Array;
28
+ export declare function validateDeviceState(state: AccountDeviceState, context: NetworkContext): void;
29
+ /** The state must have passed validateDeviceState before use as trusted authorization. */
30
+ export declare function authorizedDevice(state: AccountDeviceState, deviceId: string, context: NetworkContext, now: number): DeviceCertificate;
31
+ export interface AccountRoute extends ExtensibleModel {
32
+ readonly account: string;
33
+ readonly accountPublicKey: Uint8Array;
34
+ readonly revision: number;
35
+ readonly relayId: string;
36
+ readonly updatedAt: number;
37
+ readonly expiresAt: number;
38
+ readonly accountSignature: Uint8Array;
39
+ readonly relaySignature?: Uint8Array;
40
+ }
41
+ export declare const accountRouteCodec: import("../protocol/codec.js").ProtocolCodec<AccountRoute>;
42
+ export declare function routeAccountInput(route: AccountRoute, context: NetworkContext): Uint8Array;
43
+ export declare function routeRelayInput(route: AccountRoute, context: NetworkContext): Uint8Array;
44
+ /** Relay acknowledgement, when present, must additionally be checked against the relay key. */
45
+ export declare function validateRoute(route: AccountRoute, context: NetworkContext, now: number): void;
46
+ export declare function compareRoutes(left: AccountRoute, right: AccountRoute): 'older' | 'newer' | 'equivalent' | 'conflict';
47
+ //# sourceMappingURL=identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/models/identity.ts"],"names":[],"mappings":"AAIA,OAAO,EAA4C,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACtG,OAAO,EAAE,cAAc,EAAgB,MAAM,wBAAwB,CAAC;AAKtE,MAAM,WAAW,iBAAkB,SAAQ,eAAe;IACtD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,gBAAgB,EAAE,UAAU,CAAC;IACtC,QAAQ,CAAC,gBAAgB,EAAE,UAAU,CAAC;IACtC,QAAQ,CAAC,mBAAmB,EAAE,UAAU,CAAC;IACzC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,eAAe,EAAE,UAAU,CAAC;IACrC,QAAQ,CAAC,gBAAgB,EAAE,UAAU,CAAC;CACzC;AAED,eAAO,MAAM,sBAAsB,iEASF,CAAC;AAElC,wBAAgB,aAAa,CAAC,WAAW,EAAE,iBAAiB,EAAE,OAAO,EAAE,cAAc,GAAG,MAAM,CAE7F;AAED,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,iBAAiB,EAAE,OAAO,EAAE,cAAc,GAAG,UAAU,CA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AAC,cAAc,CAAC,EAAE,UAAU,CAAC;CACxC;AAED,eAAO,MAAM,iBAAiB,4DAKF,CAAC;AAE7B,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,GAAG,UAAU,CAE1F;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,GAAG,UAAU,CAExF;AAED,+FAA+F;AAC/F,wBAAgB,aAAa,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAc7F;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,GAAG,OAAO,GAAG,YAAY,GAAG,UAAU,CAWpH"}
@@ -0,0 +1,136 @@
1
+ import { requireLength, verifyAccount, verifyDevice } from '../crypto/primitives.js';
2
+ import { ProtocolError } from '../errors.js';
3
+ import { deriveDeviceId, validateIdentifier } from '../identity/identifiers.js';
4
+ import { matchesAccount, validateRelayId } from '../identity/neo.js';
5
+ import { array, bytes, defineCodec, integer, text } from '../protocol/codec.js';
6
+ import { NetworkContext, signingInput } from '../protocol/context.js';
7
+ import { encodeUtf8 } from '../protocol/encoding.js';
8
+ import { canonicalJson, requireSafeInteger } from '../protocol/json.js';
9
+ import { validateCompleteObject } from '../protocol/validation.js';
10
+ export const deviceCertificateCodec = defineCodec({
11
+ account: { wire: 'account', codec: text },
12
+ accountPublicKey: { wire: 'account_public_key', codec: bytes },
13
+ signingPublicKey: { wire: 'signing_public_key', codec: bytes },
14
+ encryptionPublicKey: { wire: 'encryption_public_key', codec: bytes },
15
+ notBefore: { wire: 'not_before', codec: integer },
16
+ expiresAt: { wire: 'expires_at', codec: integer },
17
+ deviceSignature: { wire: 'device_signature', codec: bytes },
18
+ accountSignature: { wire: 'account_signature', codec: bytes },
19
+ }, 'meshline.device.certificate');
20
+ export function certificateId(certificate, context) {
21
+ return deriveDeviceId(certificate.account, certificate.signingPublicKey, certificate.encryptionPublicKey, context);
22
+ }
23
+ export function certificateDeviceInput(certificate, context) {
24
+ return signingInput(deviceCertificateCodec.encode(certificate), context, ['device_signature', 'account_signature']);
25
+ }
26
+ export function certificateAccountInput(certificate, context) {
27
+ return signingInput(deviceCertificateCodec.encode(certificate), context, ['account_signature']);
28
+ }
29
+ /** Checks complete certificate integrity; current account authorization is a separate operation. */
30
+ export function validateCertificate(certificate, context) {
31
+ validateCompleteObject(deviceCertificateCodec.encode(certificate));
32
+ requireLength(certificate.signingPublicKey, 32, 'Signing public key');
33
+ requireLength(certificate.encryptionPublicKey, 32, 'Encryption public key');
34
+ requireLength(certificate.deviceSignature, 64, 'Device signature');
35
+ requireLength(certificate.accountSignature, 64, 'Account signature');
36
+ requireSafeInteger(certificate.notBefore, 0);
37
+ requireSafeInteger(certificate.expiresAt, 0);
38
+ if (certificate.expiresAt <= certificate.notBefore || certificate.expiresAt - certificate.notBefore > 720 * 86400)
39
+ throw new ProtocolError('invalid_time', 'Certificate validity must be positive and at most 720 days.');
40
+ if (!matchesAccount(certificate.account, certificate.accountPublicKey))
41
+ throw new ProtocolError('invalid_identity', 'Certificate account does not match its public key.');
42
+ if (encodeUtf8(deviceCertificateCodec.stringify(certificate)).length > 4096)
43
+ throw new ProtocolError('invalid_size', 'Certificate exceeds 4096 bytes.');
44
+ if (!verifyDevice(certificateDeviceInput(certificate, context), certificate.deviceSignature, certificate.signingPublicKey))
45
+ throw new ProtocolError('invalid_signature', 'Invalid certificate device signature.');
46
+ if (!verifyAccount(certificateAccountInput(certificate, context), certificate.accountSignature, certificate.accountPublicKey))
47
+ throw new ProtocolError('invalid_signature', 'Invalid certificate account signature.');
48
+ }
49
+ export const accountDeviceStateCodec = defineCodec({
50
+ account: { wire: 'account', codec: text }, accountPublicKey: { wire: 'account_public_key', codec: bytes },
51
+ revision: { wire: 'revision', codec: integer }, certificates: { wire: 'certificates', codec: array(deviceCertificateCodec) },
52
+ accountSignature: { wire: 'account_signature', codec: bytes },
53
+ }, 'meshline.account.device.state');
54
+ export function deviceStateInput(state, context) {
55
+ return signingInput(accountDeviceStateCodec.encode(state), context, ['account_signature']);
56
+ }
57
+ export function validateDeviceState(state, context) {
58
+ validateCompleteObject(accountDeviceStateCodec.encode(state));
59
+ requireSafeInteger(state.revision, 0);
60
+ if (!matchesAccount(state.account, state.accountPublicKey))
61
+ throw new ProtocolError('invalid_identity', 'Device state account does not match its key.');
62
+ if (state.certificates.length > 8)
63
+ throw new ProtocolError('invalid_size', 'At most eight devices may be authorized.');
64
+ if (encodeUtf8(accountDeviceStateCodec.stringify(state)).length > 131072)
65
+ throw new ProtocolError('invalid_size', 'Device state exceeds 131072 bytes.');
66
+ const identities = new Set();
67
+ for (const certificate of state.certificates) {
68
+ validateCertificate(certificate, context);
69
+ if (certificate.account !== state.account)
70
+ throw new ProtocolError('invalid_identity', 'Certificate belongs to another account.');
71
+ const id = certificateId(certificate, context);
72
+ if (identities.has(id))
73
+ throw new ProtocolError('duplicate_device', 'Duplicate device identity.');
74
+ identities.add(id);
75
+ }
76
+ if (!verifyAccount(deviceStateInput(state, context), state.accountSignature, state.accountPublicKey))
77
+ throw new ProtocolError('invalid_signature', 'Invalid device state signature.');
78
+ }
79
+ /** The state must have passed validateDeviceState before use as trusted authorization. */
80
+ export function authorizedDevice(state, deviceId, context, now) {
81
+ requireSafeInteger(now, 0);
82
+ validateIdentifier('device', deviceId);
83
+ const certificate = state.certificates.find(item => certificateId(item, context) === deviceId);
84
+ if (!certificate)
85
+ throw new ProtocolError('unauthorized_device', 'Device is not registered in the account state.');
86
+ if (now < certificate.notBefore || now >= certificate.expiresAt)
87
+ throw new ProtocolError('unauthorized_device', 'Device is outside its authorization window.');
88
+ return certificate;
89
+ }
90
+ export const accountRouteCodec = defineCodec({
91
+ account: { wire: 'account', codec: text }, accountPublicKey: { wire: 'account_public_key', codec: bytes },
92
+ revision: { wire: 'revision', codec: integer }, relayId: { wire: 'relay_id', codec: text },
93
+ updatedAt: { wire: 'updated_at', codec: integer }, expiresAt: { wire: 'expires_at', codec: integer },
94
+ accountSignature: { wire: 'account_signature', codec: bytes }, relaySignature: { wire: 'relay_signature', codec: bytes, optional: true },
95
+ }, 'meshline.account.route');
96
+ export function routeAccountInput(route, context) {
97
+ return signingInput(accountRouteCodec.encode(route), context, ['account_signature', 'relay_signature']);
98
+ }
99
+ export function routeRelayInput(route, context) {
100
+ return signingInput(accountRouteCodec.encode(route), context, ['relay_signature']);
101
+ }
102
+ /** Relay acknowledgement, when present, must additionally be checked against the relay key. */
103
+ export function validateRoute(route, context, now) {
104
+ validateCompleteObject(accountRouteCodec.encode(route));
105
+ requireSafeInteger(now, 0);
106
+ requireSafeInteger(route.revision, 0);
107
+ requireSafeInteger(route.updatedAt, 0);
108
+ requireSafeInteger(route.expiresAt, 0);
109
+ validateRelayId(route.relayId);
110
+ if (route.expiresAt <= route.updatedAt || route.expiresAt - route.updatedAt > 315_360_000 || route.expiresAt <= now)
111
+ throw new ProtocolError('invalid_time', 'Route is expired or has an invalid validity window.');
112
+ if (!matchesAccount(route.account, route.accountPublicKey))
113
+ throw new ProtocolError('invalid_identity', 'Route account does not match its key.');
114
+ if (route.relaySignature !== undefined)
115
+ requireLength(route.relaySignature, 64, 'Relay signature');
116
+ if (encodeUtf8(accountRouteCodec.stringify(route)).length > 4096)
117
+ throw new ProtocolError('invalid_size', 'Route exceeds 4096 bytes.');
118
+ if (!verifyAccount(routeAccountInput(route, context), route.accountSignature, route.accountPublicKey))
119
+ throw new ProtocolError('invalid_signature', 'Invalid account route signature.');
120
+ }
121
+ export function compareRoutes(left, right) {
122
+ if (left.account !== right.account)
123
+ throw new ProtocolError('invalid_identity', 'Routes belong to different accounts.');
124
+ if (left.revision < right.revision)
125
+ return 'older';
126
+ if (left.revision > right.revision)
127
+ return 'newer';
128
+ const unsigned = (value) => {
129
+ const object = accountRouteCodec.encode(value);
130
+ delete object.account_signature;
131
+ delete object.relay_signature;
132
+ return object;
133
+ };
134
+ return canonicalJson(unsigned(left)) === canonicalJson(unsigned(right)) ? 'equivalent' : 'conflict';
135
+ }
136
+ //# sourceMappingURL=identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/models/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAwB,MAAM,sBAAsB,CAAC;AACtG,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAmB,MAAM,qBAAqB,CAAC;AACzF,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAanE,MAAM,CAAC,MAAM,sBAAsB,GAAG,WAAW,CAAoB;IACjE,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE;IACzC,gBAAgB,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,KAAK,EAAE,KAAK,EAAE;IAC9D,gBAAgB,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,KAAK,EAAE,KAAK,EAAE;IAC9D,mBAAmB,EAAE,EAAE,IAAI,EAAE,uBAAuB,EAAE,KAAK,EAAE,KAAK,EAAE;IACpE,SAAS,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE;IACjD,SAAS,EAAE,EA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CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ;QAAE,OAAO,OAAO,CAAC;IACnD,IAAI,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ;QAAE,OAAO,OAAO,CAAC;IACnD,MAAM,QAAQ,GAAG,CAAC,KAAmB,EAAc,EAAE;QACjD,MAAM,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/C,OAAO,MAAM,CAAC,iBAAiB,CAAC;QAChC,OAAO,MAAM,CAAC,eAAe,CAAC;QAC9B,OAAO,MAAM,CAAC;IAClB,CAAC,CAAC;IACF,OAAO,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC;AACxG,CAAC"}
@@ -0,0 +1,104 @@
1
+ import { type ExtensibleModel, type ValueCodec } from '../protocol/codec.js';
2
+ import { type NetworkContext } from '../protocol/context.js';
3
+ import { type JsonObject } from '../protocol/json.js';
4
+ import { type RelayFailure } from '../transport/relay-error.js';
5
+ import { type ContentReference, type MessageBody } from './content.js';
6
+ import { type ContactAuthorization } from './contacts.js';
7
+ import { type DeviceCertificate } from './identity.js';
8
+ /** Complete wire business object. Unknown types may be stored but cannot authorize protocol state changes. */
9
+ export declare const messagePayloadCodec: ValueCodec<JsonObject>;
10
+ export interface EncryptedPayload extends ExtensibleModel {
11
+ readonly alg: string;
12
+ readonly nonce: Uint8Array;
13
+ readonly ciphertext: Uint8Array;
14
+ }
15
+ export declare const encryptedPayloadCodec: import("../protocol/codec.js").ProtocolCodec<EncryptedPayload>;
16
+ export declare function validateEncryptedPayload(value: EncryptedPayload): void;
17
+ export interface MessageEnvelope extends ExtensibleModel {
18
+ readonly messageId: string;
19
+ readonly createdAt: number;
20
+ readonly from: string;
21
+ readonly fromDeviceId: string;
22
+ readonly to: string;
23
+ readonly payload: EncryptedPayload;
24
+ readonly deviceSignature: Uint8Array;
25
+ }
26
+ export declare const messageEnvelopeCodec: import("../protocol/codec.js").ProtocolCodec<MessageEnvelope>;
27
+ export declare const messageEnvelopeInput: (value: MessageEnvelope, context: NetworkContext) => Uint8Array;
28
+ export declare function validateMessageEnvelope(value: MessageEnvelope): void;
29
+ /** Historical signature integrity only. Current device authority is checked separately by the receiver's business workflow. */
30
+ export declare function verifyMessageEnvelope(value: MessageEnvelope, sender: DeviceCertificate, context: NetworkContext): void;
31
+ export interface MessageKeyBox extends ExtensibleModel {
32
+ readonly deviceId: string;
33
+ readonly alg: string;
34
+ readonly enc: Uint8Array;
35
+ readonly sealedKey: Uint8Array;
36
+ }
37
+ export declare const messageKeyBoxCodec: import("../protocol/codec.js").ProtocolCodec<MessageKeyBox>;
38
+ export declare function validateMessageKeyBox(value: MessageKeyBox): void;
39
+ export declare function validateMessageKeyBoxes(values: readonly MessageKeyBox[]): void;
40
+ export interface MessageSendRequest extends ExtensibleModel {
41
+ readonly envelope: MessageEnvelope;
42
+ readonly senderBoxes?: readonly MessageKeyBox[];
43
+ readonly recipientBoxes: readonly MessageKeyBox[];
44
+ readonly authorization?: ContactAuthorization;
45
+ }
46
+ export declare const messageSendRequestCodec: import("../protocol/codec.js").ProtocolCodec<MessageSendRequest>;
47
+ export declare function validateMessageSendRequest(value: MessageSendRequest, now: number): void;
48
+ export interface DirectMessageReference extends ExtensibleModel {
49
+ readonly from: string;
50
+ readonly messageId: string;
51
+ }
52
+ export declare const directMessageReferenceCodec: import("../protocol/codec.js").ProtocolCodec<DirectMessageReference>;
53
+ export interface DirectMessage extends ExtensibleModel {
54
+ readonly body?: MessageBody;
55
+ readonly attachments?: readonly ContentReference[];
56
+ readonly replyTo?: DirectMessageReference;
57
+ }
58
+ export declare const directMessageCodec: import("../protocol/codec.js").ProtocolCodec<DirectMessage>;
59
+ export declare function validateDirectMessage(value: DirectMessage): void;
60
+ export interface MessageTimelineEntry extends ExtensibleModel {
61
+ readonly sequence: number;
62
+ readonly envelope: MessageEnvelope;
63
+ readonly keyBox: MessageKeyBox;
64
+ readonly acceptedAt: number;
65
+ }
66
+ export declare const messageTimelineEntryCodec: import("../protocol/codec.js").ProtocolCodec<MessageTimelineEntry>;
67
+ export interface MessageTimelinePage extends ExtensibleModel {
68
+ readonly items: readonly MessageTimelineEntry[];
69
+ readonly certificates: readonly DeviceCertificate[];
70
+ readonly hasMore: boolean;
71
+ readonly hasRetentionGap?: boolean;
72
+ }
73
+ export declare const messageTimelinePageCodec: import("../protocol/codec.js").ProtocolCodec<MessageTimelinePage>;
74
+ /** Checks page ordering and certificate availability. Each entry still requires decryption and business validation before cursor commit. */
75
+ export declare function validateMessageTimelinePage(value: MessageTimelinePage, context: NetworkContext, after?: number): void;
76
+ export interface MessageTimelineQuery extends ExtensibleModel {
77
+ readonly after?: number;
78
+ readonly limit?: number;
79
+ }
80
+ export declare const messageTimelineQueryCodec: import("../protocol/codec.js").ProtocolCodec<MessageTimelineQuery>;
81
+ export declare function validateMessageTimelineQuery(value: MessageTimelineQuery): void;
82
+ export interface MessageDeliveryQuery extends ExtensibleModel {
83
+ readonly messageId: string;
84
+ }
85
+ export declare const messageDeliveryQueryCodec: import("../protocol/codec.js").ProtocolCodec<MessageDeliveryQuery>;
86
+ export type MessageDeliveryState = 'delivering' | 'target_accepted' | 'failed';
87
+ export interface MessageDeliveryStatus extends ExtensibleModel {
88
+ readonly status: MessageDeliveryState;
89
+ readonly error?: RelayFailure;
90
+ readonly acceptedAt: number;
91
+ }
92
+ export declare const messageDeliveryStatusCodec: import("../protocol/codec.js").ProtocolCodec<MessageDeliveryStatus>;
93
+ export declare function validateMessageDeliveryStatus(value: MessageDeliveryStatus): void;
94
+ export interface DeviceStateChanged extends ExtensibleModel {
95
+ readonly revision: number;
96
+ }
97
+ export declare const deviceStateChangedCodec: import("../protocol/codec.js").ProtocolCodec<DeviceStateChanged>;
98
+ export declare function validateDeviceStateChanged(value: DeviceStateChanged): void;
99
+ export interface MessageTimelineChangedNotification extends ExtensibleModel {
100
+ readonly head: number;
101
+ }
102
+ export declare const messageTimelineChangedCodec: import("../protocol/codec.js").ProtocolCodec<MessageTimelineChangedNotification>;
103
+ export declare function validateMessageTimelineChanged(value: MessageTimelineChangedNotification): void;
104
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/models/messages.ts"],"names":[],"mappings":"AAIA,OAAO,EAAkE,KAAK,eAAe,EAAE,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC7I,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE3E,OAAO,EAA+D,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEnH,OAAO,EAAqB,KAAK,YAAY,EAAE,MAAM,6BAA6B,CAAC;AACnF,OAAO,EAAqF,KAAK,gBAAgB,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAC1J,OAAO,EAA0E,KAAK,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAClI,OAAO,EAA8D,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEnH,8GAA8G;AAC9G,eAAO,MAAM,mBAAmB,EAAE,UAAU,CAAC,UAAU,CAOtD,CAAC;AAEF,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IAAG,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAA;CAAE;AAC/I,eAAO,MAAM,qBAAqB,gEAAiK,CAAC;AACpM,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAKtE;AACD,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACpD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QA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