@dotrino/vault 0.72.0 → 0.73.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/service.js +20 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/vault",
3
- "version": "0.72.0",
3
+ "version": "0.73.0",
4
4
  "description": "Usa ESTE dispositivo (navegador) como bóveda/CA del ecosistema Dotrino: atiende enrolamientos por el proxy y firma certificados de delegación a tus máquinas. Incluye el cliente de SERVICIO (Node): un proyecto se enrola una vez y jala sus credenciales del vault en vez del .env (`import '@dotrino/vault/config'`).",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/service.js CHANGED
@@ -313,7 +313,7 @@ export async function sayHello (client, qr) {
313
313
  const hello = await new Promise((resolve, reject) => {
314
314
  const off = client.on('message', (_f, p) => {
315
315
  if (p?.type === MSG.HELLO_OK) { finish(); verifyHello(p, qr.sn).then(resolve, reject) }
316
- else if (p?.type === MSG.ERROR) { finish(); reject(new Error(p.error)) }
316
+ else if (p?.type === MSG.ERROR) { finish(); reject(vaultError(p)) }
317
317
  })
318
318
  const t = setTimeout(() => { finish(); reject(new Error('the vault did not answer: that code may have expired')) }, 15000)
319
319
  const finish = () => { off(); clearTimeout(t) }
@@ -387,7 +387,7 @@ export async function enrollWithVault ({ qr, label = 'agent', expectedScope = nu
387
387
  if (p.type === MSG.ENROLL_CHALLENGE) {
388
388
  const show = onCode || (({ deviceId, code }) => console.log(`[vault] device ${deviceId} · approve it on the vault: dotrino-vault approve ${code}`))
389
389
  show({ deviceId, code })
390
- } else if (p.type === MSG.ENROLLED) { cleanup(); resolve(p) } else if (p.type === MSG.ERROR) { cleanup(); reject(new Error(p.error)) }
390
+ } else if (p.type === MSG.ENROLLED) { cleanup(); resolve(p) } else if (p.type === MSG.ERROR) { cleanup(); reject(vaultError(p)) }
391
391
  })
392
392
  const t = setTimeout(() => { cleanup(); reject(new Error('timeout waiting for approval on the vault')) }, approveTimeoutMs)
393
393
  const cleanup = () => { off(); clearTimeout(t) }
@@ -507,7 +507,7 @@ export async function registerEncKey ({ dir, ns, proxyUrl, masterPubkey, device,
507
507
  const pending = waitForMsg(client, (p) => p.type === MSG.SECRETS_RESULT || p.type === MSG.ERROR, timeoutMs)
508
508
  client.sendByPubkey(masterPubkey, { type: MSG.SECRETS, data, signature, cert })
509
509
  const res = await pending
510
- if (res.type === MSG.ERROR) throw new Error(res.error)
510
+ if (res.type === MSG.ERROR) throw vaultError(res)
511
511
  return { encPub, created, ok: true }
512
512
  } finally { client.close() }
513
513
  }
@@ -656,7 +656,7 @@ export async function fetchSecrets ({ dir, ns, proxyUrl, masterPubkey, device, c
656
656
  try { res = await pending; break } catch (e) { ultimo = e }
657
657
  }
658
658
  if (!res) throw ultimo || new Error('nobody answered: neither the vault nor any replica')
659
- if (res.type === MSG.ERROR) throw new Error(res.error)
659
+ if (res.type === MSG.ERROR) throw vaultError(res)
660
660
 
661
661
  // CAJÓN CON APROBACIÓN: la bóveda contesta «pendiente» (firmado) y la respuesta de
662
662
  // verdad llega cuando el aparato que aprueba firme — por esta misma conexión, que
@@ -668,7 +668,7 @@ export async function fetchSecrets ({ dir, ns, proxyUrl, masterPubkey, device, c
668
668
  const until = typeof res.body.exp === 'number' ? Math.max(5000, res.body.exp - Date.now() + 5000) : approvalTimeoutMs
669
669
  res = await waitForMsg(client, (p) => (p.type === MSG.SECRETS_RESULT && p.body?.op === 'secrets.result') || p.type === MSG.ERROR, Math.min(until, approvalTimeoutMs))
670
670
  .catch((e) => { throw new Error(/timeout/.test(e.message) ? 'approval: nobody approved the request in time' : e.message) })
671
- if (res.type === MSG.ERROR) throw new Error(res.error)
671
+ if (res.type === MSG.ERROR) throw vaultError(res)
672
672
  }
673
673
 
674
674
  // AUTENTICIDAD: la firma NO es de la maestra. El acta dice qué llave vale para esto
@@ -1244,9 +1244,23 @@ function fingerprintOf (secrets) {
1244
1244
  */
1245
1245
  const FINAL_CODES = new Set([
1246
1246
  'no-wrapping', // falta la envoltura, y solo la fabrica el dueño abriendo la bóveda
1247
- 'plaintext-var' // el valor está en claro en la bóveda: hay que volver a escribirlo
1247
+ 'plaintext-var', // el valor está en claro en la bóveda: hay que volver a escribirlo
1248
+ // NADIE EN EL ACTA PUEDE APROBAR: reintentar no lo arregla, y callarlo es lo peor. Pasó el
1249
+ // 2026-09-24: la limpieza de aparatos muertos se llevó al único teléfono con `aprueba`, y
1250
+ // `dotrino-env` se quedó reintentando cada minuto sin decir nada mientras la bóveda
1251
+ // contestaba exactamente qué había que hacer.
1252
+ 'no-approver'
1248
1253
  ])
1249
1254
 
1255
+ /**
1256
+ * Un `vault.error` como Error CON SU `code`. Antes se construía con el texto a secas, y el
1257
+ * código que la bóveda manda para distinguir los casos se perdía justo aquí — así que
1258
+ * `isFinal` no podía reconocer ninguno por `code` y todo se reintentaba.
1259
+ */
1260
+ function vaultError (p) {
1261
+ return Object.assign(new Error(p?.error || 'vault error'), { code: p?.code || null })
1262
+ }
1263
+
1250
1264
  export function isFinal (e) {
1251
1265
  if (FINAL_CODES.has(e?.code)) return true
1252
1266
  return /not enrolled|invalid ns|unauthorized: (revoked|expired|scope|cn|untrusted-issuer|cert-device-mismatch|denied)/.test(e?.message || '')