@dotrino/vaultd 0.199.0 → 0.199.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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.123.1'
8
+ export const LIB_VERSION = '0.123.3'
@@ -74,6 +74,8 @@ const MAX_REPLY_BYTES = 768 * 1024
74
74
  // Cuántas actas viajan con el aviso a las hermanas: cada una es el acta entera (unos KB), y el
75
75
  // frame del proxio corta en 1 MB.
76
76
  const SIBLING_ACTAS = 5
77
+ /** Lo más que ocupa el aviso del acta a las hermanas: la trama del proxio es de 1 MB, con margen. */
78
+ const ANNOUNCE_MAX_BYTES = 900 * 1024
77
79
 
78
80
  /**
79
81
  * LA BÓVEDA, la misma en las tres versiones (binario, pestaña y extensión).
@@ -3025,6 +3027,32 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
3025
3027
  * por las reglas de siempre (`handleAdminEvent` → `adoptActa`, en fila desde identity
3026
3028
  * 0.129.2), así que una vieja se rechaza sola.
3027
3029
  */
3030
+ /**
3031
+ * QUE QUEPA EN UNA TRAMA DEL PROXIO. Va en claro por `sendByPubkey`, que no parte el mensaje,
3032
+ * para que una hermana dormida (la Lambda) lo reciba de la cola sin tener que anunciar antes su
3033
+ * llave de cifrado. El proxio corta la conexión entera con 1009 si una trama pasa de 1 MB, y eso
3034
+ * pasaba cada 5 min: el PC de Seyacat se quedaba 24 s fuera de la red y lo que le pedían sus
3035
+ * aparatos no recibía respuesta (2026-12-05). Se quita primero la cadena de selladoras y luego
3036
+ * las actas más viejas; lo que se quita se dice. Si ni el acta sola cabe, no se manda y se dice.
3037
+ */
3038
+ function fitAnnounce (msg) {
3039
+ const size = (o) => byteLength(JSON.stringify(o))
3040
+ let out = msg
3041
+ if (size(out) > ANNOUNCE_MAX_BYTES && out.sealerChain) {
3042
+ out = { ...out, sealerChain: null }
3043
+ log('[vault] record announce too big for one proxy frame: sent without the sealer chain')
3044
+ }
3045
+ while (size(out) > ANNOUNCE_MAX_BYTES && Array.isArray(out.actas) && out.actas.length) {
3046
+ out = { ...out, actas: out.actas.length > 1 ? out.actas.slice(1) : null }
3047
+ log(`[vault] record announce too big for one proxy frame: sent with ${out.actas?.length || 0} past record(s)`)
3048
+ }
3049
+ if (size(out) > ANNOUNCE_MAX_BYTES) {
3050
+ log(`[vault] record #${msg.acta?.seq ?? '?'} does not fit in one proxy frame (${size(out)} bytes): not announced to the sibling vaults`)
3051
+ return null
3052
+ }
3053
+ return out
3054
+ }
3055
+
3028
3056
  async function announceToSiblings (reason) {
3029
3057
  try {
3030
3058
  const acta = (await identity.profileActa?.().catch(() => null))?.acta || null
@@ -3035,11 +3063,14 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
3035
3063
  // que hay detrás —el PC se quedó sin la #75 y la #76 que selló la Nube— y sin ellas no
3036
3064
  // puede poner al día a sus aparatos. Se autentican solas: cada una nombra a la anterior
3037
3065
  // por su hash, y quien las recibe solo acepta las que encajan.
3038
- const actas = (await identity.recentActas?.(SIBLING_ACTAS).catch(() => null))?.actas || null
3066
+ // `{ count }`: con el número a secas la identidad tomaba su valor por defecto (10).
3067
+ const actas = (await identity.recentActas?.({ count: SIBLING_ACTAS }).catch(() => null))?.actas || null
3039
3068
  // Y la cadena de selladoras: con ella llega aunque le falten las de en medio.
3040
3069
  const sealerChain = (await identity.sealerChain?.().catch(() => null)) || null
3070
+ const msg = fitAnnounce({ type: MSG.ADMIN_EVENT, body: { ev: 'record', reason, ts: Date.now() }, acta, actas, sealerChain })
3071
+ if (!msg) return
3041
3072
  for (const m of siblings) {
3042
- try { client.sendByPubkey(m.pub, { type: MSG.ADMIN_EVENT, body: { ev: 'record', reason, ts: Date.now() }, acta, actas, sealerChain }, { quiet: true, app: 'vault' }) }
3073
+ try { client.sendByPubkey(m.pub, msg, { quiet: true, app: 'vault' }) }
3043
3074
  catch (e) { log(`[vault] could not send the record to a sibling vault: ${e.message}`) }
3044
3075
  }
3045
3076
  if (siblings.length) log(`[vault] sent record #${acta.seq} to ${siblings.length} sibling vault(s) on ${reason}`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/vaultd",
3
- "version": "0.199.0",
3
+ "version": "0.199.3",
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": {
package/src/daemon.js CHANGED
@@ -25,10 +25,10 @@ import { parseInvite } from '../lib/src/invite.js'
25
25
  import { scopeToCaps, scopeToCn } from '../lib/src/enroll.js'
26
26
  import { capScope } from '@dotrino/identity/acta'
27
27
  import { watchBinary } from './selfupdate.js'
28
- import { latestRelease, isNewer, CHECK_EVERY_MS, installKind, installRelease } from './update.js'
28
+ import { latestRelease, isNewer, CHECK_EVERY_MS, installKind, installRelease, installUserRelease, userBinDir } from './update.js'
29
29
  import { VERSION } from './version.js'
30
30
  import { readSettings } from './settings.js'
31
- import { startTray } from './tray.js'
31
+ import { startTray, findGui, guiSupportsTray } from './tray.js'
32
32
  import { approversOfAll, firstYes, readAsked, writeAsked, clearAsked, shouldAsk, resultOfNo, readRootTold, writeRootTold, shouldTellRoot } from './updateApproval.js'
33
33
  import { UPDATE_TTL_MS } from '../lib/src/core/approvals.js'
34
34
  import crypto from 'node:crypto'
@@ -1136,7 +1136,7 @@ export async function runDaemon () {
1136
1136
 
1137
1137
  // El icono en la bandeja mientras la bóveda corre (Windows y Linux, con sesión gráfica).
1138
1138
  // Al irse el daemon se cierra la tubería y el icono se va solo: no hace falta pararlo.
1139
- startTray({ log: console.log })
1139
+ if (!startTray({ log: console.log })) ensureTrayWindow().catch((e) => console.log('[vault] tray icon: could not install the window next to the vault: %s', e.message))
1140
1140
 
1141
1141
  /**
1142
1142
  * ¿SALIÓ UNA VERSIÓN NUEVA? Una lectura al día, y nada más.
@@ -1391,3 +1391,25 @@ export async function runDaemon () {
1391
1391
  console.log('[vault] servicio listo.')
1392
1392
  return mgr
1393
1393
  }
1394
+
1395
+ /**
1396
+ * LA VENTANA AL LADO DE LA BÓVEDA, sola. En un Linux con el .deb viejo la ventana que se encuentra
1397
+ * es la de /usr/bin, que el actualizador no toca y que no entiende `--tray` (abría la interfaz
1398
+ * entera cada 30 s: PC de Seyacat, 2026-12-05). Con una instalación de usuario se baja la ventana
1399
+ * del release (verificada, como cualquier actualización) y se pone al lado; desde ahí la pone al
1400
+ * día cada actualización. Cada paso se dice.
1401
+ */
1402
+ async function ensureTrayWindow () {
1403
+ if (process.platform !== 'linux' || installKind() !== 'user') return
1404
+ const gui = findGui()
1405
+ if (!gui || path.dirname(gui) === userBinDir()) return
1406
+ if (guiSupportsTray(gui)) return
1407
+ const rel = await latestRelease()
1408
+ if (!rel?.ok) { console.log('[vault] tray icon: could not read the release to get the window: %s', rel?.reason || 'no reason given'); return }
1409
+ console.log('[vault] tray icon: %s is too old; installing the window of %s next to the vault', gui, rel.version)
1410
+ const r = await installUserRelease(rel, { log: console.log, onlyWindow: true })
1411
+ if (!r.ok) { console.log('[vault] tray icon: could not install the window (%s): %s', r.code || 'error', r.reason); return }
1412
+ console.log('[vault] tray icon: window %s installed next to the vault', rel.version)
1413
+ startTray({ log: console.log })
1414
+ }
1415
+
package/src/tray.js CHANGED
@@ -17,6 +17,16 @@
17
17
  *
18
18
  * Solo en el binario (SEA): desde npm no hay ventana al lado, y en desarrollo cada prueba que
19
19
  * arranca un daemon sacaría un icono.
20
+ *
21
+ * Solo una ventana que sabe hacer de icono. Una anterior a la 0.199.0 no conoce `--tray` y abre
22
+ * la interfaz entera; al cerrarla salía con 0 y el daemon la relanzaba a los 30 s: la ventana
23
+ * «se abría sola» cada rato. Pasa cuando la ventana viene de otra instalación que no se
24
+ * actualiza con el daemon (un .deb viejo en /usr/bin y el daemon autoactualizado en
25
+ * ~/.local/share/dotrino/bin). Por eso:
26
+ * - antes de lanzarla se busca en el binario la marca `TRAY_MARKER` (desktop/src/tray.rs);
27
+ * sin ella no se lanza y se dice en el log;
28
+ * - si el icono sale con 0 sin que el daemon lo haya parado, no era un icono (alguien cerró
29
+ * una ventana): no se relanza y se dice en el log.
20
30
  */
21
31
  import fs from 'node:fs'
22
32
  import path from 'node:path'
@@ -25,6 +35,8 @@ import { execFile, spawn } from 'node:child_process'
25
35
  const RETRY_MS = 30_000
26
36
  /** Código con el que sale `--tray` cuando en esta sesión no puede haber icono. */
27
37
  export const NO_TRAY_EXIT = 3
38
+ /** La marca de una ventana que entiende `--tray`. La misma que `TRAY_MARKER` en desktop/src/tray.rs. */
39
+ export const TRAY_MARKER = 'dotrino-vault-desktop:tray:v1'
28
40
 
29
41
  const GUI_NAME = (platform) => platform === 'win32' ? 'dotrino-vault-desktop.exe' : 'dotrino-vault-desktop'
30
42
 
@@ -40,6 +52,11 @@ export function findGui ({ platform = process.platform, execPath = process.execP
40
52
  return null
41
53
  }
42
54
 
55
+ /** ¿Este binario de la ventana entiende `--tray`? Se mira sin ejecutarlo: ejecutarlo es justo lo que abre la ventana. */
56
+ export function guiSupportsTray (gui, { read = fs.readFileSync } = {}) {
57
+ return read(gui).includes(Buffer.from(TRAY_MARKER))
58
+ }
59
+
43
60
  /** Las variables de una sesión gráfica en Linux, sacadas de un entorno. `null` = no hay. */
44
61
  export function graphicalEnv (env) {
45
62
  const out = {}
@@ -77,13 +94,28 @@ async function sessionNow (platform, env) {
77
94
  * Lanza y mantiene el icono mientras viva este proceso. No hace nada si no es el binario, si
78
95
  * no hay ventana instalada o si el sistema no tiene icono todavía.
79
96
  */
80
- export function startTray ({ log = console.log, platform = process.platform, env = process.env, sea = !!globalThis.__DOTRINO_SEA__ } = {}) {
97
+ export function startTray ({ log = console.log, platform = process.platform, env = process.env, sea = !!globalThis.__DOTRINO_SEA__, find = findGui, supports = guiSupportsTray, spawnFn = spawn } = {}) {
81
98
  if (!sea || (platform !== 'linux' && platform !== 'win32')) return null
82
- const gui = findGui({ platform, env })
83
- if (!gui) return null
99
+ const gui = find({ platform, env })
100
+ if (!gui) {
101
+ log('[vault] tray icon: %s not found next to the vault or in PATH; no tray icon', GUI_NAME(platform))
102
+ return null
103
+ }
104
+ let ok
105
+ try {
106
+ ok = supports(gui)
107
+ } catch (e) {
108
+ log('[vault] tray icon: could not read %s (%s); no tray icon', gui, e.message)
109
+ return null
110
+ }
111
+ if (!ok) {
112
+ log('[vault] tray icon: %s is too old for --tray (it would open the full window); update it to 0.199.0 or later', gui)
113
+ return null
114
+ }
84
115
  let stopped = false
85
116
  let timer = null
86
117
  let child = null
118
+ let waitingLogged = false
87
119
 
88
120
  const later = () => { if (!stopped) { timer = setTimeout(tick, RETRY_MS); timer.unref?.() } }
89
121
 
@@ -91,10 +123,13 @@ export function startTray ({ log = console.log, platform = process.platform, env
91
123
  timer = null
92
124
  if (stopped) return
93
125
  const session = await sessionNow(platform, env)
94
- if (!session) return later()
126
+ if (!session) {
127
+ if (!waitingLogged) { waitingLogged = true; log('[vault] tray icon: no graphical session yet (no DISPLAY or WAYLAND_DISPLAY); checking again every %ds', RETRY_MS / 1000) }
128
+ return later()
129
+ }
95
130
  try {
96
131
  // La entrada por tubería ES el hilo de vida: el icono termina al leer su fin.
97
- child = spawn(gui, ['--tray'], { env: { ...env, ...session }, stdio: ['pipe', 'ignore', 'ignore'], windowsHide: true })
132
+ child = spawnFn(gui, ['--tray'], { env: { ...env, ...session }, stdio: ['pipe', 'ignore', 'ignore'], windowsHide: true })
98
133
  } catch (e) {
99
134
  log('[vault] tray icon: could not start %s (%s)', gui, e.message)
100
135
  return later()
@@ -104,6 +139,9 @@ export function startTray ({ log = console.log, platform = process.platform, env
104
139
  child = null
105
140
  if (stopped) return
106
141
  if (code === NO_TRAY_EXIT) { log('[vault] tray icon: this session has no system tray'); return }
142
+ // `--tray` solo sale con 0 al cerrarse su entrada, y eso lo hace el daemon al pararlo.
143
+ if (code === 0) { log('[vault] tray icon: %s exited by itself, so it is not a tray icon; not starting it again', gui); return }
144
+ log('[vault] tray icon: %s exited with code %s; retrying in %ds', gui, code, RETRY_MS / 1000)
107
145
  later()
108
146
  })
109
147
  // El icono no debe retener al daemon: el daemon se va cuando le toca y la tubería se cierra.
package/src/update.js CHANGED
@@ -16,6 +16,7 @@ import { execFileSync, spawn } from 'node:child_process'
16
16
  import { latestVersion, isNewer, CHECK_EVERY_MS } from '@dotrino/update'
17
17
  import { pickAsset, download, verifyArtifact as verify, fetchVerified } from '@dotrino/update/fetch'
18
18
  import { VERSION } from './version.js'
19
+ import { findGui } from './tray.js'
19
20
  import { ipcWrite } from './ipc.js'
20
21
 
21
22
  export const REPO = 'imdotrino/dotrino-vault'
@@ -96,7 +97,7 @@ export function isUserInstall (execPath = process.execPath, home = os.homedir())
96
97
  *
97
98
  * @returns {Promise<{ok:true, version:string} | {ok:false, code?:string, reason:string, file?:string}>}
98
99
  */
99
- export async function installUserRelease (release, { binDir = userBinDir(), log = () => {}, fetchVerifiedImpl = fetchVerified } = {}) {
100
+ export async function installUserRelease (release, { binDir = userBinDir(), log = () => {}, fetchVerifiedImpl = fetchVerified, withWindow = false, onlyWindow = false } = {}) {
100
101
  const pick = pickAsset(release.assets, [{ kind: 'tar', re: /-linux-x64\.tar\.gz$/ }])
101
102
  if (!pick.ok) return pick
102
103
  // SE TRABAJA EN DISCO, al lado de los binarios, y no en /tmp: en un VPS /tmp es un tmpfs
@@ -107,13 +108,13 @@ export async function installUserRelease (release, { binDir = userBinDir(), log
107
108
  fs.rmSync(work, { recursive: true, force: true })
108
109
  fs.mkdirSync(work, { recursive: true, mode: 0o700 })
109
110
  try {
110
- return await installFrom(work, pick, release, { binDir, log, fetchVerifiedImpl })
111
+ return await installFrom(work, pick, release, { binDir, log, fetchVerifiedImpl, withWindow, onlyWindow })
111
112
  } finally {
112
113
  try { fs.rmSync(work, { recursive: true, force: true }) } catch (_) {}
113
114
  }
114
115
  }
115
116
 
116
- async function installFrom (work, pick, release, { binDir, log, fetchVerifiedImpl }) {
117
+ async function installFrom (work, pick, release, { binDir, log, fetchVerifiedImpl, withWindow = false, onlyWindow = false }) {
117
118
  const got = await fetchVerifiedImpl(pick.asset, { repo: REPO, product: 'dotrino-vault', version: VERSION, dir: work })
118
119
  if (!got.ok) return got
119
120
  log(`[vault] update: ${pick.asset.name} verified against its attestation`)
@@ -124,10 +125,13 @@ async function installFrom (work, pick, release, { binDir, log, fetchVerifiedImp
124
125
  const src = fs.readdirSync(work).map((d) => path.join(work, d)).find((d) => fs.existsSync(path.join(d, 'dotrino-vaultd')))
125
126
  if (!src) return { ok: false, code: 'BAD_TARBALL', reason: 'the tarball has no dotrino-vaultd inside' }
126
127
  fs.mkdirSync(binDir, { recursive: true })
127
- // LA VENTANA se pone al día con la bóveda, pero solo donde ya estaba: una bóveda de
128
- // servidor no tiene por qué recibir un programa de escritorio que nadie instaló.
129
- const names = ['dotrino-vault', 'dotrino-vaultd']
130
- if (fs.existsSync(path.join(binDir, 'dotrino-vault-desktop')) && fs.existsSync(path.join(src, 'dotrino-vault-desktop'))) names.unshift('dotrino-vault-desktop')
128
+ // LA VENTANA se pone al día con la bóveda donde ya estaba, o donde se pide (`withWindow`: la
129
+ // máquina tiene una ventana en el PATH, la del .deb, que el actualizador no puede tocar).
130
+ // Una bóveda de servidor no tiene por qué recibir un programa de escritorio que nadie instaló.
131
+ const hasWindow = fs.existsSync(path.join(src, 'dotrino-vault-desktop'))
132
+ if (onlyWindow && !hasWindow) return { ok: false, code: 'BAD_TARBALL', reason: 'the tarball has no dotrino-vault-desktop inside' }
133
+ const names = onlyWindow ? [] : ['dotrino-vault', 'dotrino-vaultd']
134
+ if (hasWindow && (onlyWindow || withWindow || fs.existsSync(path.join(binDir, 'dotrino-vault-desktop')))) names.unshift('dotrino-vault-desktop')
131
135
  // El CLI primero y el daemon al final: cambiar el daemon es lo que dispara el reinicio.
132
136
  for (const name of names) {
133
137
  const tmp = path.join(binDir, `.${name}.new`)
@@ -194,7 +198,7 @@ function updateWorkDir (platform = process.platform) {
194
198
  */
195
199
  export async function installRelease (release, { log = () => {}, kind = installKind(), fetchVerifiedImpl = fetchVerified, run = spawnDetached, execPath = process.execPath, pid = null } = {}) {
196
200
  if (kind === 'user') {
197
- const r = await installUserRelease(release, { log, fetchVerifiedImpl })
201
+ const r = await installUserRelease(release, { log, fetchVerifiedImpl, withWindow: !!findGui() })
198
202
  return r.ok ? { ...r, then: 'watch' } : r
199
203
  }
200
204
  if (kind === 'inno') return installWindows(release, { log, fetchVerifiedImpl, run })