@dotrino/identity 0.22.0 → 0.22.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/identity",
3
- "version": "0.22.0",
3
+ "version": "0.22.1",
4
4
  "description": "Identidad y rating de usuarios compartidos entre apps de Dotrino (vault iframe + postMessage)",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/index.d.ts CHANGED
@@ -173,6 +173,7 @@ export class Identity {
173
173
  selfVaultApprove (deviceId: string, code: string): Promise<any>
174
174
  selfVaultReject (deviceId: string): Promise<{ ok: true }>
175
175
  selfVaultRevoke (nonce: string): Promise<any>
176
+ selfVaultProbe (pubkeys: string[]): Promise<{ online: string[] }>
176
177
  onSelfVault (handler: (payload: any) => void): () => void
177
178
  on (event: 'peer_updated' | 'me_updated' | 'sync' | 'vault' | 'selfVault', handler: (payload: any) => void): () => void
178
179
  }
package/src/index.js CHANGED
@@ -340,6 +340,8 @@ export class Identity {
340
340
  async selfVaultReject (deviceId) { return this._call('selfVaultReject', { deviceId }) }
341
341
  /** Revoca una máquina/agente enrolado por nonce de delegación. */
342
342
  async selfVaultRevoke (nonce) { return this._call('selfVaultRevoke', { nonce }) }
343
+ /** Presencia online (ping/pong) de las máquinas enroladas. Devuelve { online: [pubkeys] }. */
344
+ async selfVaultProbe (pubkeys) { return this._call('selfVaultProbe', { pubkeys }, 10000) }
343
345
  /** Suscribe a eventos del self-vault ('selfVault'): { running?, pending?, error? }. */
344
346
  onSelfVault (handler) { return this.on('selfVault', handler) }
345
347
 
package/vault/vault.js CHANGED
@@ -154,6 +154,34 @@ import { pubkeyId } from './capabilities.js'
154
154
  else releaseSelfLock()
155
155
  })
156
156
 
157
+ // Sonda de presencia (ping/pong por el proxy del daemon). Mandamos AMBOS tipos
158
+ // (ra.ping para agentes @dotrino/remote-agent —ia—; terminal.ping para terminal
159
+ // pre-migración) y consideramos online si responde cualquiera. Reusa el cliente
160
+ // del proxy del daemon activo en ESTE iframe; si no hay daemon, devuelve vacío.
161
+ function probeOnline (pubkeys, { timeoutMs = 4000 } = {}) {
162
+ return new Promise((resolve) => {
163
+ const online = new Set()
164
+ const client = daemon?.client
165
+ if (!client?.sendByPubkey || !pubkeys.length) return resolve(online)
166
+ let rest = pubkeys.length
167
+ const byNonce = new Map()
168
+ const off = client.on('message', (_f, p) => {
169
+ if (!p || typeof p !== 'object') return
170
+ if (p.type === 'ra.pong' || p.type === 'terminal.pong') {
171
+ const pk = byNonce.get(p.n)
172
+ if (pk) { online.add(pk); byNonce.delete(p.n); settle() }
173
+ }
174
+ })
175
+ function settle () { if (--rest <= 0) { off(); resolve(online) } }
176
+ for (const pk of pubkeys) {
177
+ const n = pk.slice(0, 6) + Math.random().toString(36).slice(2, 8)
178
+ byNonce.set(n, pk)
179
+ try { client.sendByPubkey(pk, { type: 'ra.ping', n }); client.sendByPubkey(pk, { type: 'terminal.ping', n }) } catch {}
180
+ setTimeout(settle, timeoutMs)
181
+ }
182
+ })
183
+ }
184
+
157
185
  // Handlers de UI (emparejamiento/gestión) expuestos por postMessage. Las ACCIONES
158
186
  // (pairing/approve) requieren que ESTE iframe sea el daemon activo (la pestaña visible);
159
187
  // la lectura (máquinas/pending) siempre funciona (lee delegaciones persistidas).
@@ -205,7 +233,10 @@ import { pubkeyId } from './capabilities.js'
205
233
  selfVaultRevoke: async ({ nonce }) => {
206
234
  if (daemon) return daemon.revoke(nonce)
207
235
  return handlers.revokeDelegation({ nonce })
208
- }
236
+ },
237
+ // Presencia online (ping/pong) de las máquinas enroladas. Requiere que ESTE
238
+ // iframe sea el daemon activo (tiene el cliente del proxy); si no, devuelve [].
239
+ selfVaultProbe: async ({ pubkeys }) => ({ online: [...(await probeOnline(pubkeys || []))] })
209
240
  }
210
241
 
211
242
  window.addEventListener('message', async (event) => {