@dotrino/vaultd 0.170.0 → 0.171.0

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,66 @@
1
+ /**
2
+ * exNotices.js — LOS AVISOS DE EXPULSIÓN YA FIRMADOS, uno por cada aparato que estuvo en las
3
+ * actas de la ventana del historial y ya no está (dueño, 2026-10-22).
4
+ *
5
+ * La bóveda solo atiende al acta (`gate.js`). A quien salió se le contesta UNA cosa —«¿sigo
6
+ * dentro?»— y la respuesta es su aviso, para que se borre aunque el que se le mandó al
7
+ * echarlo no le llegara (la cola del proxio dura 24 h). El aviso se firma una vez, con la
8
+ * bóveda abierta, y se guarda: contestar no firma nada, así que preguntar no sirve para que
9
+ * la maestra firme a pedido de nadie. Sin caducidad: tiene que valer el día que vuelva.
10
+ *
11
+ * Cifrado en reposo, como todo lo de la bóveda. Si no se puede leer, se para y se dice.
12
+ */
13
+ export const EX_NOTICES_FILE = 'exnotices.json'
14
+
15
+ const fail = (code, message) => Object.assign(new Error(message), { code })
16
+
17
+ export function openExNotices ({ disk }) {
18
+ const file = EX_NOTICES_FILE
19
+ const atRest = disk.atRest
20
+ /** pub → { body, signature } */
21
+ let items = load()
22
+
23
+ function load () {
24
+ let raw
25
+ try { raw = disk.read(file) } catch (e) {
26
+ throw fail('exnotices-unreadable', `cannot read ${EX_NOTICES_FILE}: ${e.message}`)
27
+ }
28
+ if (raw == null) return new Map()
29
+ let d
30
+ try { d = JSON.parse(atRest.decrypt(raw)) } catch (e) { throw fail('exnotices-unreadable', `${EX_NOTICES_FILE} cannot be opened: ${e.message}`) }
31
+ if (d?.v !== 1 || !d.items || typeof d.items !== 'object') throw fail('exnotices-unreadable', `${EX_NOTICES_FILE} has an unknown shape`)
32
+ return new Map(Object.entries(d.items))
33
+ }
34
+
35
+ function save () {
36
+ disk.write(file, atRest.encrypt(JSON.stringify({ v: 1, items: Object.fromEntries(items) })))
37
+ }
38
+
39
+ return {
40
+ has: (pub) => items.has(pub),
41
+ get: (pub) => items.get(pub) || null,
42
+ pubs: () => [...items.keys()],
43
+ /**
44
+ * Deja exactamente los avisos de `past` (los ex-miembros de la ventana): firma con `sign`
45
+ * los que falten y quita los de quien ya salió de la ventana. Devuelve cuántos firmó.
46
+ */
47
+ async sync (past, sign) {
48
+ const keep = new Set(past)
49
+ let changed = false
50
+ for (const pub of [...items.keys()]) if (!keep.has(pub)) { items.delete(pub); changed = true }
51
+ let signed = 0
52
+ for (const pub of keep) {
53
+ if (items.has(pub)) continue
54
+ // Sin `nonce` ni `exp`: habla del APARATO, no de un papel, y vale siempre.
55
+ const body = { op: 'revoke', sub: pub, iat: Date.now() }
56
+ items.set(pub, { body, signature: await sign(body) })
57
+ signed++
58
+ changed = true
59
+ }
60
+ if (changed) save()
61
+ return signed
62
+ }
63
+ }
64
+ }
65
+
66
+ export default { openExNotices, EX_NOTICES_FILE }
@@ -8,6 +8,9 @@
8
8
  * con freno por conexión y freno global, antes de cualquier trabajo.
9
9
  * · **El alta de un aparato** (`HELLO`, `ENROLL`, `ACTA_SEALED`): solo mientras hay un
10
10
  * emparejamiento abierto y el mensaje es de ESE emparejamiento. Fuera de eso, nada.
11
+ * · **Los que salieron** (`CHECK`): un aparato de las actas de la ventana que ya no está pasa
12
+ * solo a preguntar si sigue dentro, con su firma y con freno. Se le contesta con su aviso
13
+ * de expulsión ya firmado (`exNotices.js`), para que se borre.
11
14
  *
12
15
  * Lo demás se descarta EN SILENCIO: sin respuesta, sin firma, sin línea en la bitácora y sin
13
16
  * tocar el disco. Antes un desconocido conseguía que la bóveda le contestara con el acta
@@ -77,9 +80,10 @@ export function claimOf (MSG, p) {
77
80
  * @param {object} o.MSG los tipos del protocolo
78
81
  * @param {() => Promise<object|null>} o.acta el acta vigente de esta bóveda
79
82
  * @param {(type: string, p: object, from: string) => boolean} o.pairing ¿es de un emparejamiento abierto?
83
+ * @param {(pub: string) => boolean} [o.former] ¿estuvo en el acta (y tiene su aviso)?
80
84
  * @param {ReturnType<typeof makeLimiter>} [o.limiter]
81
85
  */
82
- export function createGate ({ MSG, acta, pairing, limiter = makeLimiter(), verify = verifyDeviceSig }) {
86
+ export function createGate ({ MSG, acta, pairing, former = () => false, limiter = makeLimiter(), verify = verifyDeviceSig }) {
83
87
  const LOGIN = new Set([MSG.LOGIN_START, MSG.LOGIN_FINISH, MSG.LOGIN_CLOSE])
84
88
  const PAIRING = new Set([MSG.HELLO, MSG.ENROLL, MSG.ACTA_SEALED])
85
89
  const stats = { dropped: 0, throttled: 0, since: Date.now() }
@@ -100,7 +104,12 @@ export function createGate ({ MSG, acta, pairing, limiter = makeLimiter(), verif
100
104
  if (!claim || typeof claim.pub !== 'string' || !claim.pub) { stats.dropped++; return { ok: false } }
101
105
  // NADA QUE DECIDIR SIN ACTA: se para (no hay a quién atender), no se deja pasar.
102
106
  const record = await acta()
103
- if (!record || !(record.members || []).some((m) => m?.pub === claim.pub)) { stats.dropped++; return { ok: false } }
107
+ if (!record) { stats.dropped++; return { ok: false } }
108
+ const member = (record.members || []).some((m) => m?.pub === claim.pub)
109
+ // Un ex-miembro, solo a preguntar si sigue dentro, y con freno.
110
+ const leaving = !member && type === MSG.CHECK && former(claim.pub)
111
+ if (!member && !leaving) { stats.dropped++; return { ok: false } }
112
+ if (leaving && !limiter.take('check:' + from)) { stats.throttled++; return { ok: false } }
104
113
  if (claim.signature !== null) {
105
114
  const ok = typeof claim.signature === 'string' && claim.data &&
106
115
  await verify({ publickey: claim.pub, data: claim.data, signature: claim.signature }).catch(() => false)
@@ -5,4 +5,4 @@
5
5
  * si no coincide con la del paquete: una versión anunciada que no es la que corre es peor
6
6
  * que no anunciar ninguna.
7
7
  */
8
- export const LIB_VERSION = '0.98.0'
8
+ export const LIB_VERSION = '0.99.0'
@@ -25,6 +25,7 @@ import { openThreadStore, STORE_READ_METHODS, PROFILE_EDIT_METHODS } from './thr
25
25
  import { openSecretsStore, assertVar, RECOVERY as RECOVERY_WRAP, PROFILE_OWNER } from './secretsStore.js'
26
26
  import { openSubacta } from './subacta.js'
27
27
  import { openBlocked } from './blocked.js'
28
+ import { openExNotices } from './exNotices.js'
28
29
  import { openNotifiable } from './notifiable.js'
29
30
  import { openMachines } from './machines.js'
30
31
  import { machineLine } from '@dotrino/identity/machine'
@@ -265,6 +266,7 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
265
266
  const passwordsAtRest = disk.atRest
266
267
  // Los aparatos BLOQUEADOS por un aprobador (`src/blocked.js`). Cifrado en reposo como lo demás.
267
268
  const blocked = openBlocked({ disk })
269
+ const exNotices = openExNotices({ disk })
268
270
  // Qué aprobadores dijeron que pueden recibir avisos (`src/notifiable.js`). No decide nada: se enseña.
269
271
  const notifiable = openNotifiable({ disk })
270
272
  // Dónde corre cada aparato, según lo último que dijo firmado (`src/machines.js`). Se enseña.
@@ -473,6 +475,19 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
473
475
  * maestra o quedándose mudos. Se vio el 2026-09-02: de dos perfiles, el que tenía
474
476
  * contraseña era el que no tenía `commkey.json`.
475
477
  */
478
+ /**
479
+ * LOS AVISOS DE LOS QUE SALIERON (`exNotices.js`): uno firmado por cada aparato de las actas
480
+ * de la ventana que ya no está. Solo con la bóveda ABIERTA y si esta sella: cerrada no firma.
481
+ */
482
+ async function syncExNotices () {
483
+ try {
484
+ if (isLocked() || identity.masterLocked || !(await identity.isMaster?.())) return
485
+ const past = ((await identity.pastMembers()).members || []).map((m) => m.pub)
486
+ const n = await exNotices.sync(past, async (body) => (await identity.signData(body)).signature)
487
+ if (n) log(`[vault] signed the leaving notice of ${n} former member(s): they get it when they ask`)
488
+ } catch (e) { log('[vault] could not prepare the notices for former members:', e.message) }
489
+ }
490
+
476
491
  async function ensureCommKeyInActa () {
477
492
  try {
478
493
  const info = await identity.profileActa?.()
@@ -513,6 +528,7 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
513
528
  // `sealers.js` — es una comodidad para quien lee, nunca una dependencia de la bóveda.
514
529
  startSealersPublisher({ identity, client, log })
515
530
  if (commSealedAtStart) await notifyMembers('commkey')
531
+ await syncExNotices()
516
532
 
517
533
  async function revocationSet () {
518
534
  const { revoked } = await identity.listDelegations()
@@ -1321,9 +1337,13 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
1321
1337
  }
1322
1338
  const record = (await identity.profileActa?.().catch(() => null))?.acta || null
1323
1339
  const inside = (record?.members || []).some((m) => m?.pub === pub)
1324
- audit('check', { device: await deviceIdOf(pub).catch(() => null), in: inside })
1340
+ // Solo de los de dentro: un ex-miembro pregunta con freno y no escribe en la bitácora.
1341
+ if (inside) audit('check', { device: await deviceIdOf(pub).catch(() => null), in: true })
1325
1342
  if (inside) return reply(from, { type: MSG.CHECKED, in: true })
1326
- await notifyIfRevoked(pub, null, null, 'revoked')
1343
+ // UN EX-MIEMBRO: su aviso, el que se firmó una vez (`exNotices`). Primero el aviso y luego
1344
+ // el «no»: el aparato deja de escuchar al recibir el «no». Aquí no se firma nada.
1345
+ const notice = exNotices.get(pub)
1346
+ if (notice) reply(from, { type: MSG.REVOKED, body: notice.body, signature: notice.signature })
1327
1347
  reply(from, { type: MSG.CHECKED, in: false })
1328
1348
  }
1329
1349
 
@@ -2235,7 +2255,8 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
2235
2255
  const gate = createGate({
2236
2256
  MSG,
2237
2257
  acta: async () => (await identity.profileActa?.().catch(() => null))?.acta || null,
2238
- pairing: (type, p) => desk.ownsPairing(type, p)
2258
+ pairing: (type, p) => desk.ownsPairing(type, p),
2259
+ former: (pub) => exNotices.has(pub)
2239
2260
  })
2240
2261
 
2241
2262
  // `listen` y no `client.on`: entrega también lo que llegó encolado antes de este punto.
@@ -2564,6 +2585,8 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
2564
2585
  * `sendByPubkey`, así que al que está apagado le llega cuando encienda (cola 24 h).
2565
2586
  */
2566
2587
  async function notifyMembers (ev, info = {}) {
2588
+ // El acta pudo cambiar (alguien salió): su aviso tiene que estar listo para cuando pregunte.
2589
+ await syncExNotices()
2567
2590
  try {
2568
2591
  // SIN FIRMA, y no falta nada: quien lo usa es el ACTA que viaja al lado, que se
2569
2592
  // autentica sola (otra bóveda la adopta por `canAdopt`; el teléfono solo refresca y
@@ -4328,6 +4351,7 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
4328
4351
  try {
4329
4352
  if (await ensureCommKeyInActa()) { await reidentify?.(); await notifyMembers('commkey') }
4330
4353
  } catch (_) {}
4354
+ await syncExNotices()
4331
4355
  }
4332
4356
  // Y ABSORBER LO PENDIENTE. La subacta ya lo estaba honrando con el perfil cerrado —de
4333
4357
  // eso vive—, pero mientras siga ahí solo lo sabe esta máquina: al sellarlo, entra en
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/vaultd",
3
- "version": "0.170.0",
3
+ "version": "0.171.0",
4
4
  "type": "module",
5
5
  "description": "Certificador personal de Dotrino: daemon headless que custodia la clave maestra y delega capacidades a tus dispositivos por el proxy. Tu CA propia.",
6
6
  "bin": {
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@dotrino/compat": "0.4.0",
25
- "@dotrino/identity": "0.125.0",
25
+ "@dotrino/identity": "0.126.0",
26
26
  "@dotrino/opaque": "0.1.0",
27
27
  "@dotrino/passmanager": "0.18.4",
28
28
  "@dotrino/proxy-client": "0.39.0",