@dotrino/vaultd 0.165.0 → 0.165.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.
@@ -67,38 +67,38 @@ export async function createTransport ({ identity, url = DEFAULT_PROXY, commKey
67
67
  // La puerta tiene que decidir AL INSTANTE (la señal llega y o se atiende o no), y pedir
68
68
  // el acta es asíncrono. Así que se guarda una copia y se refresca donde ya se refresca
69
69
  // todo: en `identify`, que es lo que corre cada vez que el acta cambia o se reconecta.
70
- let actaVista = null
70
+ let seenActa = null
71
71
  // ¿Está esta bóveda ATADA al proxio ahora mismo? Conectado no es identificado: el socket
72
72
  // puede estar perfectamente abierto y el sobre rechazado, y entonces nadie la alcanza por
73
73
  // su pubkey. Se expone para que `status` lo enseñe en vez de dejarlo a un log del arranque.
74
- let identificado = false
75
- const enElActa = (token) => {
74
+ let identified = false
75
+ const inActa = (token) => {
76
76
  // SIN ACTA NO SE NEGOCIA. No se sabe quién es nadie, y en la duda no se arranca a
77
77
  // parsear red no confiable. Se sigue por el proxio, que es el escalón que siempre está.
78
- if (!actaVista) return false
79
- return (actaVista.members || []).some((m) => m?.pub === token)
78
+ if (!seenActa) return false
79
+ return (seenActa.members || []).some((m) => m?.pub === token)
80
80
  }
81
- const client = makeClient ? makeClient({ url, acceptDirectFrom: enElActa }) : new WebSocketProxyClient({
82
- url, enableWebRTC: true, acceptDirectFrom: enElActa, autoReconnect: true,
81
+ const client = makeClient ? makeClient({ url, acceptDirectFrom: inActa }) : new WebSocketProxyClient({
82
+ url, enableWebRTC: true, acceptDirectFrom: inActa, autoReconnect: true,
83
83
  maxReconnectAttempts: 100000, reconnectDelay: 4000
84
84
  })
85
85
 
86
86
  await client.connect()
87
87
 
88
88
  const identify = async () => {
89
- identificado = false
89
+ identified = false
90
90
  if (!client.token) return
91
91
  const record = (await identity.profileActa?.().catch(() => null))?.acta || null
92
- actaVista = record // la copia que mira la puerta del canal directo
92
+ seenActa = record // la copia que mira la puerta del canal directo
93
93
  const comm = commKey?.pub?.() || null
94
94
  // ¿Nos nombra el acta? Con `cn` o sin él, lo que el proxio mira es la pertenencia.
95
- const esMiembro = comm && (record?.members || []).some((m) => m?.pub === comm)
95
+ const isMember = comm && (record?.members || []).some((m) => m?.pub === comm)
96
96
 
97
- if (comm && esMiembro) {
97
+ if (comm && isMember) {
98
98
  // El sobre lo arma el pilar (`identifyAs`), que le pone el destinatario.
99
99
  try {
100
100
  await client.identifyAs({ publickey: comm, sign: (d) => commKey.sign(d), acta: record })
101
- identificado = true
101
+ identified = true
102
102
  // SE DICE QUE SE IDENTIFICÓ, y con qué llave. Este camino era MUDO: al pasar de la
103
103
  // maestra a la llave de comunicación, el único rastro de «estoy alcanzable» que
104
104
  // quedaba en el log era el del repliegue. Así que cuando la consola decía «no
@@ -133,7 +133,7 @@ export async function createTransport ({ identity, url = DEFAULT_PROXY, commKey
133
133
  if (!publickey) return
134
134
  log('[vault] identifying with the master key: this vault is not in its own record yet (open the profile once to fix it)')
135
135
  await client.identifyAs({ publickey, sign: (d) => identity.signData(d), acta: record })
136
- identificado = true
136
+ identified = true
137
137
  } catch (e) {
138
138
  log(`[vault] cannot identify on the proxy yet: ${e.message} — the profile still opens; unlock it once and it gets its own communication key`)
139
139
  }
@@ -175,7 +175,7 @@ export async function createTransport ({ identity, url = DEFAULT_PROXY, commKey
175
175
  */
176
176
  let announcedAt = 0
177
177
  const announceAccount = async () => {
178
- if (!announce || !identificado) return
178
+ if (!announce || !identified) return
179
179
  announcedAt = Date.now()
180
180
  try { await client.publish(announce) } catch (e) {
181
181
  log(`[vault] could not announce this account on the proxy (${e.message}) — a borrowed machine will not find this vault by its address`)
@@ -190,38 +190,38 @@ export async function createTransport ({ identity, url = DEFAULT_PROXY, commKey
190
190
  * lo que se pierde es que la despierten, y eso no se puede callar.
191
191
  */
192
192
  const registerWake = async () => {
193
- if (!wakeUrl || !identificado) return
193
+ if (!wakeUrl || !identified) return
194
194
  const comm = commKey?.pub?.() || null
195
- if (!comm || !actaVista) { log('[vault] cannot register the wake URL: no communication key in the record yet'); return }
195
+ if (!comm || !seenActa) { log('[vault] cannot register the wake URL: no communication key in the record yet'); return }
196
196
  try {
197
- await client.registerWake({ publicKey: comm, sign: (d) => commKey.sign(d), url: wakeUrl, acta: actaVista, channel: announce || undefined })
197
+ await client.registerWake({ publicKey: comm, sign: (d) => commKey.sign(d), url: wakeUrl, acta: seenActa, channel: announce || undefined })
198
198
  log('[vault] wake URL registered on the proxy')
199
199
  } catch (e) {
200
200
  log(`[vault] could not register the wake URL (${e.code || ''} ${e.message}) — the proxy will not wake this vault`)
201
201
  }
202
202
  }
203
203
 
204
- let reintento = null
205
- let fallos = 0
204
+ let retry = null
205
+ let failures = 0
206
206
  const identifyWithRetry = async () => {
207
- if (reintento) { clearTimeout(reintento); reintento = null }
207
+ if (retry) { clearTimeout(retry); retry = null }
208
208
  try {
209
209
  await identify()
210
210
  await announceAccount()
211
211
  await registerWake()
212
- if (fallos) log(`[vault] identified on the proxy after ${fallos + 1} attempt(s)`)
213
- fallos = 0
212
+ if (failures) log(`[vault] identified on the proxy after ${failures + 1} attempt(s)`)
213
+ failures = 0
214
214
  } catch (e) {
215
- fallos++
216
- const espera = Math.min(60000, 5000 * fallos)
217
- log(`[vault] could not identify on the proxy (${e.message}) — retrying in ${Math.round(espera / 1000)}s; until then this vault is unreachable and cannot ring anyone`)
218
- reintento = setTimeout(() => { reintento = null; identifyWithRetry() }, espera)
219
- reintento.unref?.()
215
+ failures++
216
+ const wait = Math.min(60000, 5000 * failures)
217
+ log(`[vault] could not identify on the proxy (${e.message}) — retrying in ${Math.round(wait / 1000)}s; until then this vault is unreachable and cannot ring anyone`)
218
+ retry = setTimeout(() => { retry = null; identifyWithRetry() }, wait)
219
+ retry.unref?.()
220
220
  }
221
221
  }
222
222
  await identifyWithRetry()
223
223
  // Re-identificar al reconectar (el token cambia).
224
- client.on('token', () => { fallos = 0; identifyWithRetry() })
224
+ client.on('token', () => { failures = 0; identifyWithRetry() })
225
225
 
226
226
  /**
227
227
  * QUE NO SE PUEDA VOLVER A QUEDAR MUDA.
@@ -247,7 +247,7 @@ export async function createTransport ({ identity, url = DEFAULT_PROXY, commKey
247
247
  let saidDown = false
248
248
  client.on('disconnect', ({ code, reason } = {}) => {
249
249
  // Sin socket no hay nadie atado al proxio: lo que se identificó era la conexión anterior.
250
- identificado = false
250
+ identified = false
251
251
  if (!downSince) downSince = Date.now()
252
252
  if (saidDown) return
253
253
  saidDown = true
@@ -267,7 +267,7 @@ export async function createTransport ({ identity, url = DEFAULT_PROXY, commKey
267
267
  // borra al caerse, así que mirarlo daba la bóveda por vuelta con el socket cerrado: el
268
268
  // 2026-10-15 dijo «back on the proxy after 50s», no volvió a marcar nunca y pasó hora y
269
269
  // media fuera, avisando cada 10 minutos de que no podía anunciarse.
270
- if (identificado && client.isConnected && client.token) {
270
+ if (identified && client.isConnected && client.token) {
271
271
  if (downSince) log(`[vault] back on the proxy after ${Math.round((Date.now() - downSince) / 1000)}s`)
272
272
  downSince = 0; saidDown = false
273
273
  // EL ANUNCIO CADUCA: el proxio borra una entrada de canal a los 20 minutos de publicada.
@@ -286,5 +286,5 @@ export async function createTransport ({ identity, url = DEFAULT_PROXY, commKey
286
286
  }, RECHECK_MS)
287
287
  watchdog.unref?.()
288
288
 
289
- return { client, token: client.token, identify: identifyWithRetry, isIdentified: () => identificado }
289
+ return { client, token: client.token, identify: identifyWithRetry, isIdentified: () => identified }
290
290
  }