@dotrino/vaultd 0.175.2 → 0.176.2
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.
- package/lib/src/core/libVersion.js +1 -1
- package/lib/src/core/logAnchor.js +87 -0
- package/lib/src/core/notices.js +13 -2
- package/lib/src/core/vault.js +53 -7
- package/package.json +2 -2
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EL ANCLA DE LA BITÁCORA: que no se pueda cortar el final sin que se note.
|
|
3
|
+
*
|
|
4
|
+
* La bitácora es una cadena (`logSeq` + hash de la anterior), así que reescribir o quitar
|
|
5
|
+
* una entrada del medio se ve. Cortar el FINAL no: un prefijo sigue siendo una cadena
|
|
6
|
+
* válida (modelo de amenazas §4.3). Eso no se cierra en local, porque quien corta tiene la
|
|
7
|
+
* máquina. Se cierra sacando la cabeza de la máquina.
|
|
8
|
+
*
|
|
9
|
+
* Decidido por el dueño (2026-10-26): la cabeza se sella con `signer.dotrino.com` —que da
|
|
10
|
+
* el CUÁNDO, firmado por un tercero— y el recibo viaja a los aparatos con `approve`, que
|
|
11
|
+
* lo GUARDAN. El signer no guarda nada: un recibo que se quedara en este disco se borraría
|
|
12
|
+
* junto con el final que pretende proteger. Un aprobador que recibe un ancla con un
|
|
13
|
+
* `logSeq` menor que el último que guardó, o con el mismo `logSeq` y otra cabeza, sabe que
|
|
14
|
+
* cortaron la bitácora.
|
|
15
|
+
*
|
|
16
|
+
* Al signer solo llega un hash: ni el contenido de la bitácora ni quién es esta bóveda.
|
|
17
|
+
* Sin dependencias de Node: lo corren el binario, la pestaña y la extensión.
|
|
18
|
+
*/
|
|
19
|
+
import { bytesToB64url } from '../b64.js'
|
|
20
|
+
|
|
21
|
+
export const SIGNER_URL = 'https://signer.dotrino.com'
|
|
22
|
+
/** Cada cuánto se mira si hay algo nuevo que anclar. Sin entradas nuevas no se manda nada. */
|
|
23
|
+
export const ANCHOR_EVERY_MS = 6 * 60 * 60 * 1000
|
|
24
|
+
/** Cuánto espera la primera, desde que arranca la bóveda. */
|
|
25
|
+
export const ANCHOR_FIRST_MS = 10 * 60 * 1000
|
|
26
|
+
const SIGNER_TIMEOUT_MS = 15000
|
|
27
|
+
|
|
28
|
+
const fail = (code, message) => Object.assign(new Error(message), { code })
|
|
29
|
+
|
|
30
|
+
/** hex → base64url, que es como el signer pide el hash. */
|
|
31
|
+
export function hexToB64url (hex) {
|
|
32
|
+
if (typeof hex !== 'string' || !/^[0-9a-f]{64}$/.test(hex)) throw fail('anchor-bad-head', 'the log head must be a sha256 in hex')
|
|
33
|
+
const bytes = new Uint8Array(32)
|
|
34
|
+
for (let i = 0; i < 32; i++) bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16)
|
|
35
|
+
return bytesToB64url(bytes)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Pide al signer que selle la cabeza. Devuelve su recibo tal cual (`{ v, op, hash, ts, alg,
|
|
40
|
+
* signature, pubkey }`), que es lo que el aprobador puede verificar sin red. Si el signer no
|
|
41
|
+
* contesta, LANZA: un ancla sin sello no se manda como si lo tuviera.
|
|
42
|
+
*/
|
|
43
|
+
export async function sealHead (head, { fetchFn = globalThis.fetch, signerUrl = SIGNER_URL, timeoutMs = SIGNER_TIMEOUT_MS } = {}) {
|
|
44
|
+
if (typeof fetchFn !== 'function') throw fail('anchor-no-fetch', 'this platform cannot reach the signer')
|
|
45
|
+
const hash = hexToB64url(head)
|
|
46
|
+
const ctl = typeof AbortController === 'function' ? new AbortController() : null
|
|
47
|
+
const timer = ctl ? setTimeout(() => ctl.abort(), timeoutMs) : null
|
|
48
|
+
try {
|
|
49
|
+
const res = await fetchFn(signerUrl + '/seal', {
|
|
50
|
+
method: 'POST',
|
|
51
|
+
headers: { 'content-type': 'application/json' },
|
|
52
|
+
body: JSON.stringify({ hash }),
|
|
53
|
+
...(ctl ? { signal: ctl.signal } : {})
|
|
54
|
+
})
|
|
55
|
+
if (!res.ok) throw fail('anchor-signer-error', `the signer answered ${res.status}`)
|
|
56
|
+
const r = await res.json()
|
|
57
|
+
if (r?.op !== 'seal' || r.hash !== hash || typeof r.ts !== 'number' || typeof r.signature !== 'string') {
|
|
58
|
+
throw fail('anchor-signer-bad-receipt', 'the signer receipt does not match the head it was asked to seal')
|
|
59
|
+
}
|
|
60
|
+
return r
|
|
61
|
+
} catch (e) {
|
|
62
|
+
if (e?.code) throw e
|
|
63
|
+
throw fail('anchor-signer-unreachable', `could not reach the signer: ${e?.message || e}`)
|
|
64
|
+
} finally {
|
|
65
|
+
if (timer) clearTimeout(timer)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Lo que decide el APROBADOR al recibir un ancla, frente a la última que guardó de esa
|
|
71
|
+
* bóveda. Pura, para que el navegador, Kotlin y Swift hagan exactamente lo mismo.
|
|
72
|
+
*
|
|
73
|
+
* · `first` no tenía ninguna: se guarda.
|
|
74
|
+
* · `advanced` la bitácora creció: se guarda la nueva.
|
|
75
|
+
* · `same` nada nuevo.
|
|
76
|
+
* · `truncated` `logSeq` menor que el guardado: cortaron el final.
|
|
77
|
+
* · `forked` mismo `logSeq`, otra cabeza: reescribieron el final.
|
|
78
|
+
*
|
|
79
|
+
* Los dos últimos son la alarma. No se guarda el ancla nueva: la buena es la que ya estaba.
|
|
80
|
+
*/
|
|
81
|
+
export function compareAnchor (last, next) {
|
|
82
|
+
if (!next || typeof next.logSeq !== 'number' || typeof next.head !== 'string') throw fail('anchor-malformed', 'an anchor needs logSeq and head')
|
|
83
|
+
if (!last) return 'first'
|
|
84
|
+
if (next.logSeq < last.logSeq) return 'truncated'
|
|
85
|
+
if (next.logSeq === last.logSeq) return next.head === last.head ? 'same' : 'forked'
|
|
86
|
+
return 'advanced'
|
|
87
|
+
}
|
package/lib/src/core/notices.js
CHANGED
|
@@ -22,7 +22,7 @@ export const NOTICE_TTL_MS = 24 * 60 * 60 * 1000
|
|
|
22
22
|
* (`docs/pairing-protocol.md` §1.7). No pide nada: no hay a quién bloquear, porque ninguno
|
|
23
23
|
* entró. Lo cuenta, con el ID y la máquina de los dos.
|
|
24
24
|
*/
|
|
25
|
-
export const NOTICE_EVS = ['updated', 'update-needs-root', 'pairing-contested']
|
|
25
|
+
export const NOTICE_EVS = ['updated', 'update-needs-root', 'pairing-contested', 'log-anchor']
|
|
26
26
|
|
|
27
27
|
const newId = () => [...crypto.getRandomValues(new Uint8Array(8))].map((b) => b.toString(16).padStart(2, '0')).join('')
|
|
28
28
|
|
|
@@ -58,8 +58,19 @@ export function openNotices ({ disk, now = Date.now }) {
|
|
|
58
58
|
* administrador). `product`: qué (`@dotrino/vaultd` es la propia bóveda);
|
|
59
59
|
* `deviceId`/`label`: el aparato, si fue uno.
|
|
60
60
|
*/
|
|
61
|
-
add (ev, { version, from = null, product = '@dotrino/vaultd', deviceId = null, label = null, devices = null }) {
|
|
61
|
+
add (ev, { version, from = null, product = '@dotrino/vaultd', deviceId = null, label = null, devices = null, logSeq = null, head = null, tsa = null }) {
|
|
62
62
|
if (!NOTICE_EVS.includes(ev)) throw fail('bad-notice', `unknown notice: ${ev}`)
|
|
63
|
+
// EL ANCLA DE LA BITÁCORA (`logAnchor.js`): la cabeza sellada por el signer, para que el
|
|
64
|
+
// aprobador la guarde. Solo se queda la última: la anterior ya no dice nada que esta no diga.
|
|
65
|
+
if (ev === 'log-anchor') {
|
|
66
|
+
if (typeof logSeq !== 'number' || typeof head !== 'string' || !tsa || typeof tsa.signature !== 'string') {
|
|
67
|
+
throw fail('bad-notice', `${ev}: logSeq, head and the signer receipt are required`)
|
|
68
|
+
}
|
|
69
|
+
const n = { id: newId(), ev, logSeq, head, tsa, ts: now() }
|
|
70
|
+
items = [...items.filter(alive).filter((x) => x.ev !== 'log-anchor'), n]
|
|
71
|
+
save()
|
|
72
|
+
return n
|
|
73
|
+
}
|
|
63
74
|
if (ev === 'pairing-contested') {
|
|
64
75
|
if (!Array.isArray(devices) || devices.length < 2) throw fail('bad-notice', `${ev}: the devices that answered are required`)
|
|
65
76
|
const n = {
|
package/lib/src/core/vault.js
CHANGED
|
@@ -47,6 +47,7 @@ import { openCommKey, COMM_CN, COMM_CAPS } from './commKey.js'
|
|
|
47
47
|
import { seal } from '../sealed.js'
|
|
48
48
|
import { MSG, SCOPE, secretsScope, isValidSecretsNs, VAULT_PROTOCOL, VAULT_SPEAKS } from '../protocol.js'
|
|
49
49
|
import { sha256Hex } from './sha256.js'
|
|
50
|
+
import { sealHead, ANCHOR_EVERY_MS, ANCHOR_FIRST_MS } from './logAnchor.js'
|
|
50
51
|
import { createGate } from './gate.js'
|
|
51
52
|
|
|
52
53
|
const b64ToBytes = (s) => Uint8Array.from(atob(s), (c) => c.charCodeAt(0))
|
|
@@ -798,8 +799,9 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
|
|
|
798
799
|
*
|
|
799
800
|
* **Lo que esto NO resuelve, dicho para no venderlo de más:** quien tenga la máquina
|
|
800
801
|
* puede cortar el final de la cadena y quedarse con un prefijo válido. Eso no se cierra
|
|
801
|
-
* en local
|
|
802
|
-
*
|
|
802
|
+
* en local: la cabeza se ancla fuera, sellada por el signer y guardada por los aparatos
|
|
803
|
+
* con `approve` (`anchorLog`, `logAnchor.js`). Lo que la cadena cierra sola es reescribir
|
|
804
|
+
* el pasado sin dejar rastro, que es el caso que importaba.
|
|
803
805
|
*/
|
|
804
806
|
const AUDIT_MAX_BYTES = 1024 * 1024
|
|
805
807
|
/** Cuántos archivos viejos se guardan. Es la RETENCIÓN, y va declarada. */
|
|
@@ -2234,13 +2236,13 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
|
|
|
2234
2236
|
* @returns {Promise<{ approvers: number, sent: number, notice: object|null }>}
|
|
2235
2237
|
*/
|
|
2236
2238
|
/** Manda un aviso ya apuntado (`notices`) a cada aprobador, sellado. Devuelve a cuántos salió. */
|
|
2237
|
-
async function sendNotice (notice, who, what) {
|
|
2239
|
+
async function sendNotice (notice, who, what, { quiet = false } = {}) {
|
|
2238
2240
|
const { id, ev, ts, ...rest } = notice
|
|
2239
2241
|
const body = { ev, id, ...rest, ts }
|
|
2240
2242
|
const seal = await sealOrFail(body)
|
|
2241
2243
|
let sent = 0
|
|
2242
2244
|
for (const pub of who) {
|
|
2243
|
-
try { client.sendByPubkey(pub, { type: MSG.ADMIN_EVENT, body, seal }, { app: 'vault' }); sent++ }
|
|
2245
|
+
try { client.sendByPubkey(pub, { type: MSG.ADMIN_EVENT, body, seal }, { app: 'vault', ...(quiet ? { quiet: true } : {}) }); sent++ }
|
|
2244
2246
|
catch (e) { log(`[vault] could not tell ${pub.slice(0, 24)}… about ${what}: ${e.message}`) }
|
|
2245
2247
|
}
|
|
2246
2248
|
return sent
|
|
@@ -2266,6 +2268,35 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
|
|
|
2266
2268
|
return { approvers: who.length, sent }
|
|
2267
2269
|
}
|
|
2268
2270
|
|
|
2271
|
+
/**
|
|
2272
|
+
* ANCLAR LA BITÁCORA (`logAnchor.js`, modelo de amenazas §4.3): la cabeza, sellada por el
|
|
2273
|
+
* signer, a cada aparato con `approve`. Solo si la bitácora creció desde la última vez, y
|
|
2274
|
+
* sin apuntarlo en ella: una entrada nueva cambiaría la cabeza que se acaba de anclar.
|
|
2275
|
+
* Sin aprobadores no hay dónde dejarla, y se dice. Si el signer no contesta, no se manda
|
|
2276
|
+
* sin sello: se reintenta en la próxima vuelta.
|
|
2277
|
+
*/
|
|
2278
|
+
let anchoredSeq = 0
|
|
2279
|
+
async function anchorLog () {
|
|
2280
|
+
if (!auditPrev || auditSeq <= anchoredSeq) return { anchored: false, reason: 'nothing-new' }
|
|
2281
|
+
const record = await refreshActa()
|
|
2282
|
+
const who = (record?.members || []).filter((m) => Acta.memberCan(record, m.pub, 'approve')).map((m) => m.pub)
|
|
2283
|
+
if (!who.length) {
|
|
2284
|
+
log('[vault] log anchor: nobody can approve, so the log head stays only on this machine (grant it with: dotrino-vault caps <ID> +aprueba)')
|
|
2285
|
+
return { anchored: false, reason: 'no-approvers' }
|
|
2286
|
+
}
|
|
2287
|
+
const logSeq = auditSeq; const head = auditPrev
|
|
2288
|
+
const tsa = await sealHead(head, { fetchFn: platform.fetch || globalThis.fetch })
|
|
2289
|
+
const notice = notices.add('log-anchor', { logSeq, head, tsa })
|
|
2290
|
+
// CALLADO: no es nada que hacer, y timbrar cada pocas horas haría sonar el teléfono con un
|
|
2291
|
+
// pedido vacío. La app lo lee de la lista de avisos la próxima vez que pregunte.
|
|
2292
|
+
const sent = await sendNotice(notice, who, 'the log anchor', { quiet: true })
|
|
2293
|
+
if (!sent) throw Object.assign(new Error('no approver could be told'), { code: 'announce-failed' })
|
|
2294
|
+
anchoredSeq = logSeq
|
|
2295
|
+
log(`[vault] log anchor: entry ${logSeq} sealed and sent to ${sent} of ${who.length} approver(s)`)
|
|
2296
|
+
return { anchored: true, logSeq, sent }
|
|
2297
|
+
}
|
|
2298
|
+
const runAnchor = () => anchorLog().catch((e) => log(`[vault] log anchor: not sent this round (${e.code || 'error'}: ${e.message}); retrying in ${Math.round(ANCHOR_EVERY_MS / 3600000)} h`))
|
|
2299
|
+
|
|
2269
2300
|
async function announceUpdate ({ version, from = null, product = '@dotrino/vaultd', deviceId = null, label = null, ev = 'updated' }) {
|
|
2270
2301
|
const record = await refreshActa()
|
|
2271
2302
|
const who = (record?.members || []).filter((m) => Acta.memberCan(record, m.pub, 'approve')).map((m) => m.pub)
|
|
@@ -2546,6 +2577,14 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
|
|
|
2546
2577
|
log(`[vault] passwords: could not start (${e.message}); everything else keeps going`)
|
|
2547
2578
|
}
|
|
2548
2579
|
|
|
2580
|
+
// La primera ancla sale a los diez minutos de arrancar (lo escrito mientras estuvo apagada) y
|
|
2581
|
+
// luego cada pocas horas. No antes: un arranque no es actividad, y una bóveda que vive menos
|
|
2582
|
+
// —una prueba, un reinicio— no tiene por qué llamar al signer.
|
|
2583
|
+
const anchorFirst = setTimeout(runAnchor, ANCHOR_FIRST_MS)
|
|
2584
|
+
anchorFirst.unref?.()
|
|
2585
|
+
const anchorSweeper = setInterval(runAnchor, ANCHOR_EVERY_MS)
|
|
2586
|
+
anchorSweeper.unref?.()
|
|
2587
|
+
|
|
2549
2588
|
log(`[vault] listo · id ${fp} · ${store.getTree().children.length} nodos`)
|
|
2550
2589
|
|
|
2551
2590
|
// ----- API local (CLI/UI de control) -----
|
|
@@ -3116,14 +3155,18 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
|
|
|
3116
3155
|
// ese aparato no hizo.
|
|
3117
3156
|
//
|
|
3118
3157
|
// Mirando lo que el acta dice HOY, un registro repetido no quita nada y se para aquí.
|
|
3119
|
-
//
|
|
3120
|
-
//
|
|
3121
|
-
//
|
|
3158
|
+
// Y si el dueño volvió a conceder ese permiso, el acta recuerda la fecha de la última
|
|
3159
|
+
// renuncia del miembro (`renouncedAt`, identity ≥ 0.127.0): una que no sea posterior es
|
|
3160
|
+
// una repetición y no se honra (modelo de amenazas §4.4.bis, cerrado el 2026-10-25).
|
|
3122
3161
|
const actual = (await identity.profileActa?.().catch(() => null))?.acta || null
|
|
3123
3162
|
if (!actual) {
|
|
3124
3163
|
audit('rejected', { what: 'renounce', reason: 'no-record' })
|
|
3125
3164
|
return reply(from, { type: MSG.ERROR, error: 'renounce: this vault has no record to apply it to' })
|
|
3126
3165
|
}
|
|
3166
|
+
if (!Acta.renounceIsFresh(actual, record)) {
|
|
3167
|
+
audit('rejected', { what: 'renounce', reason: 'stale' })
|
|
3168
|
+
return reply(from, { type: MSG.ERROR, error: 'renounce: not newer than the last renounce this record saw', code: 'renounce-stale' })
|
|
3169
|
+
}
|
|
3127
3170
|
const has = new Set(Acta.effectiveCaps(actual, record.member) || [])
|
|
3128
3171
|
if (!(record.caps || []).some((c) => has.has(c))) {
|
|
3129
3172
|
audit('rejected', { what: 'renounce', reason: 'nothing-to-remove' })
|
|
@@ -4527,6 +4570,7 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
|
|
|
4527
4570
|
return { answer, withdraw: () => { withdrawn = true; retire() } }
|
|
4528
4571
|
},
|
|
4529
4572
|
announceUpdate,
|
|
4573
|
+
anchorLog,
|
|
4530
4574
|
approvers: async () => {
|
|
4531
4575
|
const record = await refreshActa()
|
|
4532
4576
|
if (!record) return []
|
|
@@ -4759,6 +4803,8 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
|
|
|
4759
4803
|
close () {
|
|
4760
4804
|
for (const stop of [...announcing]) { try { stop() } catch (_) {} }
|
|
4761
4805
|
clearInterval(approvalsSweeper)
|
|
4806
|
+
clearTimeout(anchorFirst)
|
|
4807
|
+
clearInterval(anchorSweeper)
|
|
4762
4808
|
for (const t of pendingNotices.values()) clearTimeout(t)
|
|
4763
4809
|
pendingNotices.clear()
|
|
4764
4810
|
closeTransport()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/vaultd",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.176.2",
|
|
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.
|
|
25
|
+
"@dotrino/identity": "0.127.0",
|
|
26
26
|
"@dotrino/opaque": "0.1.0",
|
|
27
27
|
"@dotrino/passmanager": "0.18.6",
|
|
28
28
|
"@dotrino/proxy-client": "^0.45.0",
|