@cello-protocol/client 0.0.4 → 0.0.5

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.
@@ -0,0 +1,21 @@
1
+ -- V1__client_schema.sql
2
+ -- CELLO-PERSIST-009: Initial client-side encrypted database schema.
3
+ --
4
+ -- Tables:
5
+ -- client_store — opaque key/value blob store (implements ClientStore interface)
6
+ --
7
+ -- Note: schema_migrations is NOT created here. The migration runner bootstraps
8
+ -- that table itself before executing any migration files, so it must not appear
9
+ -- inside a migration transaction.
10
+ --
11
+ -- All data at rest is protected by SQLCipher (AES-256-CBC with PBKDF2 key derivation).
12
+ -- The db_key is never stored here — it is derived at runtime from identity_key via HKDF.
13
+
14
+ -- Opaque key/value store backing the ClientStore interface.
15
+ -- key: stable string identifier (session keys, trust data, key material, etc.)
16
+ -- value: raw bytes (BLOB)
17
+ CREATE TABLE IF NOT EXISTS client_store (
18
+ key TEXT NOT NULL PRIMARY KEY,
19
+ value BLOB NOT NULL,
20
+ updated_at TEXT NOT NULL DEFAULT (datetime('now'))
21
+ );
@@ -0,0 +1,274 @@
1
+ -- V2__client_schema_structured.sql
2
+ -- CELLO-PERSIST-024: Structured client-side SQLCipher schema.
3
+ --
4
+ -- This migration:
5
+ -- 1. Drops the V1 client_store table (placeholder KV store, no production users)
6
+ -- 2. Creates 18 structured tables covering all durable state
7
+ --
8
+ -- All data at rest is protected by SQLCipher (AES-256-CBC with PBKDF2 key derivation).
9
+ -- The db_key is never stored here — derived at runtime from K_local via HKDF.
10
+
11
+ -- Drop the placeholder KV table — all state migrates to structured tables.
12
+ DROP TABLE IF EXISTS client_store;
13
+
14
+ -- ── 1. agents ────────────────────────────────────────────────
15
+ CREATE TABLE IF NOT EXISTS agents (
16
+ pubkey TEXT NOT NULL,
17
+ agent_name TEXT NOT NULL DEFAULT '',
18
+ key_file_path TEXT NOT NULL,
19
+ ml_dsa_key_file_path TEXT,
20
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
21
+ last_seen_at TEXT NOT NULL DEFAULT (datetime('now')),
22
+ is_active INTEGER NOT NULL DEFAULT 1,
23
+ PRIMARY KEY (pubkey)
24
+ );
25
+
26
+ -- ── 2. registration_state ────────────────────────────────────
27
+ CREATE TABLE IF NOT EXISTS registration_state (
28
+ agent_pubkey TEXT NOT NULL,
29
+ agent_id TEXT NOT NULL,
30
+ primary_pubkey TEXT NOT NULL,
31
+ ml_dsa_pubkey TEXT NOT NULL,
32
+ registered_at INTEGER NOT NULL,
33
+ status TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('active')),
34
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
35
+ PRIMARY KEY (agent_pubkey),
36
+ FOREIGN KEY (agent_pubkey) REFERENCES agents(pubkey) ON DELETE CASCADE,
37
+ UNIQUE (agent_id)
38
+ );
39
+
40
+ -- ── 3. frost_key_shares ──────────────────────────────────────
41
+ CREATE TABLE IF NOT EXISTS frost_key_shares (
42
+ agent_pubkey TEXT NOT NULL,
43
+ epoch_id TEXT NOT NULL,
44
+ primary_pubkey TEXT NOT NULL,
45
+ identifier TEXT NOT NULL,
46
+ signing_share BLOB NOT NULL,
47
+ threshold INTEGER NOT NULL,
48
+ participants INTEGER NOT NULL,
49
+ commitments_cbor BLOB NOT NULL,
50
+ verifying_shares_cbor BLOB NOT NULL,
51
+ dkg_method TEXT NOT NULL CHECK (dkg_method IN ('trusted_dealer','network_dkg')),
52
+ is_active INTEGER NOT NULL DEFAULT 1,
53
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
54
+ validated_at TEXT,
55
+ PRIMARY KEY (agent_pubkey, epoch_id),
56
+ FOREIGN KEY (agent_pubkey) REFERENCES agents(pubkey) ON DELETE CASCADE
57
+ );
58
+ CREATE UNIQUE INDEX IF NOT EXISTS uq_frost_key_shares_active
59
+ ON frost_key_shares(agent_pubkey) WHERE is_active = 1;
60
+
61
+ -- ── 4. ml_dsa_keypairs ───────────────────────────────────────
62
+ CREATE TABLE IF NOT EXISTS ml_dsa_keypairs (
63
+ agent_pubkey TEXT NOT NULL,
64
+ ml_dsa_pubkey TEXT NOT NULL,
65
+ secret_key_blob BLOB NOT NULL,
66
+ algorithm TEXT NOT NULL DEFAULT 'ML-DSA-44',
67
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
68
+ PRIMARY KEY (agent_pubkey),
69
+ FOREIGN KEY (agent_pubkey) REFERENCES agents(pubkey) ON DELETE CASCADE
70
+ );
71
+
72
+ -- ── 5. connection_policy ─────────────────────────────────────
73
+ CREATE TABLE IF NOT EXISTS connection_policy (
74
+ agent_pubkey TEXT NOT NULL,
75
+ mode TEXT NOT NULL CHECK (mode IN ('open','selective','guarded','closed')),
76
+ review_mode TEXT NOT NULL CHECK (review_mode IN ('deterministic','inference')),
77
+ updated_at TEXT NOT NULL DEFAULT (datetime('now')),
78
+ PRIMARY KEY (agent_pubkey),
79
+ FOREIGN KEY (agent_pubkey) REFERENCES agents(pubkey) ON DELETE CASCADE
80
+ );
81
+
82
+ -- ── 6. connection_policy_requirements ───────────────────────
83
+ CREATE TABLE IF NOT EXISTS connection_policy_requirements (
84
+ agent_pubkey TEXT NOT NULL,
85
+ position INTEGER NOT NULL,
86
+ signal_type TEXT NOT NULL CHECK (signal_type IN ('endorsement','attestation','pseudonym_age','registration_age')),
87
+ condition_json TEXT NOT NULL,
88
+ PRIMARY KEY (agent_pubkey, position),
89
+ FOREIGN KEY (agent_pubkey) REFERENCES connection_policy(agent_pubkey) ON DELETE CASCADE
90
+ );
91
+
92
+ -- ── 7. connections ───────────────────────────────────────────
93
+ CREATE TABLE IF NOT EXISTS connections (
94
+ connection_id TEXT NOT NULL,
95
+ agent_pubkey TEXT NOT NULL,
96
+ counterparty_pubkey TEXT NOT NULL,
97
+ counterparty_primary_pubkey TEXT NOT NULL DEFAULT '',
98
+ counterparty_ml_dsa_pubkey TEXT NOT NULL DEFAULT '',
99
+ established_at INTEGER NOT NULL,
100
+ status TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('active')),
101
+ profile_unchecked INTEGER NOT NULL DEFAULT 0,
102
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
103
+ PRIMARY KEY (connection_id),
104
+ FOREIGN KEY (agent_pubkey) REFERENCES agents(pubkey) ON DELETE CASCADE,
105
+ UNIQUE (agent_pubkey, counterparty_pubkey)
106
+ );
107
+ CREATE INDEX IF NOT EXISTS idx_connections_agent ON connections(agent_pubkey);
108
+
109
+ -- ── 8. endorsements ──────────────────────────────────────────
110
+ CREATE TABLE IF NOT EXISTS endorsements (
111
+ agent_pubkey TEXT NOT NULL,
112
+ endorser_pubkey TEXT NOT NULL,
113
+ endorser_ml_dsa_pubkey BLOB NOT NULL,
114
+ target_pubkey TEXT NOT NULL,
115
+ endorsement_type TEXT NOT NULL,
116
+ created_at INTEGER NOT NULL,
117
+ expires_at INTEGER NOT NULL,
118
+ endorser_ml_dsa_sig BLOB NOT NULL,
119
+ received_at TEXT NOT NULL DEFAULT (datetime('now')),
120
+ PRIMARY KEY (agent_pubkey, endorser_pubkey),
121
+ FOREIGN KEY (agent_pubkey) REFERENCES agents(pubkey) ON DELETE CASCADE
122
+ );
123
+ CREATE INDEX IF NOT EXISTS idx_endorsements_expires ON endorsements(expires_at);
124
+
125
+ -- ── 9. attestations ──────────────────────────────────────────
126
+ CREATE TABLE IF NOT EXISTS attestations (
127
+ agent_pubkey TEXT NOT NULL,
128
+ attester_pubkey TEXT NOT NULL,
129
+ attestation_type TEXT NOT NULL,
130
+ attester_ml_dsa_pubkey BLOB NOT NULL,
131
+ attestation_data BLOB NOT NULL,
132
+ created_at INTEGER NOT NULL,
133
+ expires_at INTEGER NOT NULL,
134
+ attester_ml_dsa_sig BLOB NOT NULL,
135
+ received_at TEXT NOT NULL DEFAULT (datetime('now')),
136
+ PRIMARY KEY (agent_pubkey, attester_pubkey, attestation_type),
137
+ FOREIGN KEY (agent_pubkey) REFERENCES agents(pubkey) ON DELETE CASCADE
138
+ );
139
+ CREATE INDEX IF NOT EXISTS idx_attestations_expires ON attestations(expires_at);
140
+
141
+ -- ── 10. peers ────────────────────────────────────────────────
142
+ CREATE TABLE IF NOT EXISTS peers (
143
+ agent_pubkey TEXT NOT NULL,
144
+ peer_pubkey_hex TEXT NOT NULL,
145
+ peer_id TEXT NOT NULL,
146
+ multiaddrs TEXT NOT NULL,
147
+ added_at TEXT NOT NULL DEFAULT (datetime('now')),
148
+ last_seen_at TEXT,
149
+ updated_at TEXT NOT NULL DEFAULT (datetime('now')),
150
+ PRIMARY KEY (agent_pubkey, peer_pubkey_hex),
151
+ FOREIGN KEY (agent_pubkey) REFERENCES agents(pubkey) ON DELETE CASCADE
152
+ );
153
+ CREATE UNIQUE INDEX IF NOT EXISTS uq_peers_peer_id ON peers(agent_pubkey, peer_id);
154
+
155
+ -- ── 11. sessions ─────────────────────────────────────────────
156
+ CREATE TABLE IF NOT EXISTS sessions (
157
+ session_id TEXT NOT NULL,
158
+ agent_pubkey TEXT NOT NULL,
159
+ counterparty_pubkey BLOB NOT NULL,
160
+ counterparty_peer_id TEXT NOT NULL,
161
+ counterparty_multiaddrs TEXT NOT NULL,
162
+ relay_peer_id TEXT NOT NULL,
163
+ relay_multiaddrs TEXT NOT NULL,
164
+ directory_peer_id TEXT NOT NULL,
165
+ directory_multiaddrs TEXT NOT NULL,
166
+ directory_pubkey BLOB NOT NULL,
167
+ genesis_prev_root BLOB NOT NULL,
168
+ last_seen_seq INTEGER NOT NULL DEFAULT 0,
169
+ last_sent_seq INTEGER NOT NULL DEFAULT 0,
170
+ next_expected_seq INTEGER NOT NULL DEFAULT 1,
171
+ status TEXT NOT NULL CHECK (status IN ('active','transport_lost','sealing','sealed','seal_rejected','seal_deferred')),
172
+ desynchronized INTEGER NOT NULL DEFAULT 0,
173
+ leaf_count INTEGER NOT NULL DEFAULT 0,
174
+ sealed_root BLOB,
175
+ seal_type TEXT CHECK (seal_type IN ('frost','bilateral','unilateral')),
176
+ close_timestamp INTEGER,
177
+ frost_signature BLOB,
178
+ signer_pubkey BLOB,
179
+ directory_signature BLOB,
180
+ checkpoint_status TEXT NOT NULL DEFAULT 'pending' CHECK (checkpoint_status IN ('pending','confirmed')),
181
+ checkpoint_peak_hash TEXT,
182
+ checkpoint_leaf_index INTEGER,
183
+ checkpoint_sibling_hashes TEXT,
184
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
185
+ updated_at TEXT NOT NULL DEFAULT (datetime('now')),
186
+ PRIMARY KEY (session_id, agent_pubkey),
187
+ FOREIGN KEY (agent_pubkey) REFERENCES agents(pubkey) ON DELETE CASCADE
188
+ );
189
+ CREATE INDEX IF NOT EXISTS idx_sessions_agent ON sessions(agent_pubkey, status);
190
+
191
+ -- ── 12. session_tree_leaves ──────────────────────────────────
192
+ CREATE TABLE IF NOT EXISTS session_tree_leaves (
193
+ session_id TEXT NOT NULL,
194
+ agent_pubkey TEXT NOT NULL,
195
+ leaf_index INTEGER NOT NULL,
196
+ leaf_kind TEXT NOT NULL CHECK (leaf_kind IN ('msg','ctrl')),
197
+ s2_cbor BLOB NOT NULL,
198
+ sequence_number INTEGER NOT NULL,
199
+ accepted_at TEXT NOT NULL DEFAULT (datetime('now')),
200
+ PRIMARY KEY (session_id, agent_pubkey, leaf_index),
201
+ FOREIGN KEY (agent_pubkey) REFERENCES agents(pubkey) ON DELETE CASCADE,
202
+ FOREIGN KEY (session_id, agent_pubkey) REFERENCES sessions(session_id, agent_pubkey) ON DELETE CASCADE
203
+ );
204
+ CREATE INDEX IF NOT EXISTS idx_session_tree_leaves_seq
205
+ ON session_tree_leaves(session_id, agent_pubkey, sequence_number);
206
+
207
+ -- ── 13. pending_hashes ───────────────────────────────────────
208
+ CREATE TABLE IF NOT EXISTS pending_hashes (
209
+ id INTEGER NOT NULL PRIMARY KEY,
210
+ agent_pubkey TEXT NOT NULL,
211
+ session_id TEXT NOT NULL,
212
+ hash_hex TEXT NOT NULL,
213
+ enqueued_at INTEGER NOT NULL,
214
+ FOREIGN KEY (agent_pubkey) REFERENCES agents(pubkey) ON DELETE CASCADE,
215
+ UNIQUE (agent_pubkey, session_id, hash_hex)
216
+ );
217
+ CREATE INDEX IF NOT EXISTS idx_pending_hashes_agent_session
218
+ ON pending_hashes(agent_pubkey, session_id);
219
+
220
+ -- ── 14. relay_ack_receipts ───────────────────────────────────
221
+ CREATE TABLE IF NOT EXISTS relay_ack_receipts (
222
+ hash_hex TEXT NOT NULL,
223
+ agent_pubkey TEXT NOT NULL,
224
+ session_id TEXT NOT NULL,
225
+ relay_id TEXT NOT NULL,
226
+ relay_pubkey_hex TEXT NOT NULL,
227
+ sequence_number INTEGER NOT NULL,
228
+ relay_timestamp INTEGER NOT NULL,
229
+ signature_hex TEXT NOT NULL,
230
+ acked_at TEXT NOT NULL DEFAULT (datetime('now')),
231
+ PRIMARY KEY (hash_hex, agent_pubkey),
232
+ FOREIGN KEY (agent_pubkey) REFERENCES agents(pubkey) ON DELETE CASCADE
233
+ );
234
+
235
+ -- ── 15. backup_metadata ──────────────────────────────────────
236
+ CREATE TABLE IF NOT EXISTS backup_metadata (
237
+ agent_pubkey TEXT NOT NULL,
238
+ completed_at TEXT NOT NULL,
239
+ destination_url TEXT NOT NULL,
240
+ checksum TEXT NOT NULL,
241
+ updated_at TEXT NOT NULL DEFAULT (datetime('now')),
242
+ PRIMARY KEY (agent_pubkey),
243
+ FOREIGN KEY (agent_pubkey) REFERENCES agents(pubkey) ON DELETE CASCADE
244
+ );
245
+
246
+ -- ── 16. known_relays ─────────────────────────────────────────
247
+ CREATE TABLE IF NOT EXISTS known_relays (
248
+ relay_id TEXT NOT NULL PRIMARY KEY,
249
+ relay_pubkey_hex TEXT NOT NULL,
250
+ source TEXT NOT NULL,
251
+ last_seen_at TEXT NOT NULL DEFAULT (datetime('now'))
252
+ );
253
+
254
+ -- ── 17. pending_connection_requests ──────────────────────────
255
+ CREATE TABLE IF NOT EXISTS pending_connection_requests (
256
+ request_id TEXT NOT NULL,
257
+ agent_pubkey TEXT NOT NULL,
258
+ from_pubkey TEXT NOT NULL,
259
+ package_cbor BLOB NOT NULL,
260
+ arrived_at TEXT NOT NULL DEFAULT (datetime('now')),
261
+ round INTEGER NOT NULL DEFAULT 1,
262
+ PRIMARY KEY (request_id, agent_pubkey),
263
+ FOREIGN KEY (agent_pubkey) REFERENCES agents(pubkey) ON DELETE CASCADE
264
+ );
265
+
266
+ -- ── 18. decided_connection_requests ──────────────────────────
267
+ CREATE TABLE IF NOT EXISTS decided_connection_requests (
268
+ request_id TEXT NOT NULL,
269
+ agent_pubkey TEXT NOT NULL,
270
+ decision TEXT NOT NULL CHECK (decision IN ('accepted','rejected','more_disclosure')),
271
+ decided_at TEXT NOT NULL DEFAULT (datetime('now')),
272
+ PRIMARY KEY (request_id, agent_pubkey),
273
+ FOREIGN KEY (agent_pubkey) REFERENCES agents(pubkey) ON DELETE CASCADE
274
+ );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cello-protocol/client",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "engines": {
@@ -19,6 +19,7 @@
19
19
  },
20
20
  "files": [
21
21
  "dist/",
22
+ "db/",
22
23
  "package.json"
23
24
  ],
24
25
  "dependencies": {
@@ -32,9 +33,9 @@
32
33
  "it-length-prefixed": "^10.0.1",
33
34
  "it-pipe": "^3.0.1",
34
35
  "zod": "^4.4.2",
35
- "@cello-protocol/crypto": "0.0.4",
36
+ "@cello-protocol/protocol-types": "0.0.3",
36
37
  "@cello-protocol/transport": "0.0.3",
37
- "@cello-protocol/protocol-types": "0.0.3"
38
+ "@cello-protocol/crypto": "0.0.4"
38
39
  },
39
40
  "devDependencies": {
40
41
  "@claude-flow/testing": "3.0.0-alpha.6",