@dotrino/remote-agent 0.9.0 → 0.9.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/README.md CHANGED
File without changes
package/e2e.js CHANGED
File without changes
package/index.js CHANGED
File without changes
package/node-globals.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/remote-agent",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Middleware compartido del ecosistema Dotrino para apps de agente remoto cifrado punto a punto (handshake E2E, emparejamiento SAS con vault, revocación, descubrimiento). Lo consumen dotrino-terminal (PTY) y dotrino-ia (chat con IA).",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -46,12 +46,12 @@
46
46
  ],
47
47
  "peerDependencies": {
48
48
  "@dotrino/identity": ">=0.73.1",
49
- "@dotrino/proxy-client": ">=0.10.1",
49
+ "@dotrino/proxy-client": ">=0.18.2",
50
50
  "@dotrino/vault": ">=0.30.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@dotrino/identity": "0.73.0",
54
- "@dotrino/proxy-client": "0.13.1",
54
+ "@dotrino/proxy-client": "0.18.2",
55
55
  "@dotrino/vault": "0.35.0"
56
56
  }
57
57
  }
package/protocol.js CHANGED
File without changes
package/src/agent.js CHANGED
@@ -111,9 +111,8 @@ export async function startRemoteAgent (opts = {}) {
111
111
  // Identificarse bajo la pubkey de ESTA máquina (firmado con su D).
112
112
  const identify = async () => {
113
113
  if (!client.token) return
114
- const data = { op: 'identify', publickey: myPub, token: client.token, ts: Date.now() }
115
- const { signature } = await signWithDevice({ privateJwk: link.device.privateJwk, data })
116
- await client.identify({ data, signature })
114
+ // El sobre lo arma el pilar (`identifyAs`), que le pone el destinatario.
115
+ await client.identifyAs({ publickey: myPub, sign: (d) => signWithDevice({ privateJwk: link.device.privateJwk, data: d }) })
117
116
  }
118
117
  await identify()
119
118
  client.on('token', () => { identify().catch(() => {}) })
@@ -259,21 +258,21 @@ export async function startRemoteAgent (opts = {}) {
259
258
  const chk = await verifyChain({ data, signature, cert, expectedScope: SIGN_SCOPE, ...contextoActa(), revoked: revokedSet })
260
259
  if (!chk.ok) return send(from, { type: ERROR, error: 'no autorizado: ' + chk.reason })
261
260
  // CERT ∩ ACTA. `verifyChain` comprueba QUIÉN EMITIÓ el papel; que el APARATO siga siendo
262
- // miembro y pueda firmar lo dice el acta, y hay que preguntárselo aparte. Sin esto, un
261
+ // isMember y pueda firmar lo dice el acta, y hay que preguntárselo aparte. Sin esto, un
263
262
  // papel bien firmado por una selladora abría sesión aunque el acta no nombrara a ese
264
263
  // aparato — o ya no lo nombrara. Bajo el modelo viejo daba igual, porque el papel ERA la
265
264
  // autoridad y caducaba; con el papel atado al acta, el acta tiene que decidir.
266
265
  //
267
266
  // SE PREGUNTA POR EL PERMISO, NO POR «FIRMA POR LA PERSONA». Aquí se usaba
268
- // `memberCanSign`, que a un miembro CON `cn` le dice que no salvo que se le nombre su
267
+ // `memberCanSign`, que a un isMember CON `cn` le dice que no salvo que se le nombre su
269
268
  // cajón — y con razón: un servicio habla por la bóveda, no por su dueño. Pero eso es la
270
269
  // pregunta de OTRO mostrador. Lo que pasa aquí es un saludo, y lo que prueba es «soy
271
270
  // este aparato», no «hablo por ti»: exigirle lo segundo dejaba a TODO servicio sin poder
272
271
  // abrir sesión con otro agente. El bot social se pasó así el 1 de septiembre, con un
273
272
  // node de contenido encendido a su lado que le contestaba «ese aparato no firma por este
274
273
  // perfil». Se le pide lo que corresponde: que el acta lo nombre y le reconozca `sign`.
275
- const miembro = (link.acta?.members || []).some((m) => m?.pub === chk.device)
276
- if (!miembro || !memberCan(link.acta, chk.device, 'sign')) {
274
+ const isMember = (link.acta?.members || []).some((m) => m?.pub === chk.device)
275
+ if (!isMember || !memberCan(link.acta, chk.device, 'sign')) {
277
276
  return send(from, { type: ERROR, error: 'no autorizado: acta — este perfil no reconoce a ese aparato' })
278
277
  }
279
278
  if (data.op !== HS || typeof data.eph !== 'string') return send(from, { type: ERROR, error: 'handshake inválido' })
package/src/client.js CHANGED
@@ -21,6 +21,7 @@
21
21
  * `on('message', cb)` recibe los payloads del agente, ya descifrados.
22
22
  */
23
23
  import { verifyChain } from '@dotrino/identity/capabilities'
24
+ import { sealersOf } from '@dotrino/identity/acta'
24
25
  import { makeEphemeral, deriveKey, seal, open } from '../e2e.js'
25
26
  import { HS, ACK, DATA, PING, PONG, ERROR } from '../protocol.js'
26
27
 
@@ -52,6 +53,23 @@ export class RemoteAgentClient {
52
53
 
53
54
  _emit (ev, ...args) { for (const h of (this._h[ev] || [])) { try { h(...args) } catch (_) {} } }
54
55
 
56
+ /**
57
+ * El acta con la que se juzga el papel del agente. Se pide UNA vez por cliente y se
58
+ * guarda: es la política vigente del perfil, no cambia a mitad de una sesión.
59
+ *
60
+ * Si no se puede traer, se devuelve `null` a propósito y `verifyChain` corta con
61
+ * `no-acta`. No hay repliegue: sin acta no hay con qué decidir, y no decidir es que no.
62
+ */
63
+ async _acta () {
64
+ if (this._actaCache !== undefined) return this._actaCache
65
+ let acta = this.link.acta || null
66
+ if (!acta) {
67
+ try { acta = (await this.link.id?.listVaultDevices?.())?.acta || null } catch (_) { acta = null }
68
+ }
69
+ this._actaCache = acta
70
+ return acta
71
+ }
72
+
55
73
  async _identify () {
56
74
  // En modo self NO identificamos esta conexión como P: el proxy enruta por token
57
75
  // las respuestas del agente (no por pubkey), y así no recibimos el fan-out de
@@ -64,9 +82,8 @@ export class RemoteAgentClient {
64
82
  const { id, cert } = this.link
65
83
  const publickey = id.me?.publickey
66
84
  if (!publickey) return
67
- const data = { op: 'identify', publickey, token: this.client.token, ts: Date.now() }
68
- const { signature } = await id.signData(data)
69
- await this.client.identify({ data, signature, cert })
85
+ // El sobre lo arma el pilar (`identifyAs`), que le pone el destinatario.
86
+ await this.client.identifyAs({ publickey, sign: (d) => id.signData(d), cert })
70
87
  }
71
88
 
72
89
  async connect () {
@@ -115,7 +132,19 @@ export class RemoteAgentClient {
115
132
 
116
133
  // El ack debe: (1) encadenar a NUESTRA maestra, (2) estar firmado por el agente
117
134
  // que apuntamos, (3) atar nuestra pub efímera y el sid.
118
- const chk = await verifyChain({ data: res.ack, signature: res.signature, cert: res.cert, trustedIssuer: this.link.iss })
135
+ //
136
+ // CON EL ACTA, o no se juzga. Desde que el papel no vence, `verifyChain` necesita el
137
+ // `seq` del acta y su lista de SELLADORAS: sin eso no puede decir si quien firmó el
138
+ // papel del agente podía hacerlo, y contesta `no-acta` — que es lo correcto, porque
139
+ // decir «vale» sin haber comprobado nada es como entraba un papel viejo. Aquí no se le
140
+ // pasaba: el lado del agente sí lo hacía (`contextoActa`) y este lado se quedó atrás,
141
+ // así que TODA sesión moría con «el agente no está certificado por tu vault: no-acta».
142
+ // `clientLink` no trae el acta, así que se le pide a la bóveda una vez y se guarda.
143
+ const acta = await this._acta()
144
+ const chk = await verifyChain({
145
+ data: res.ack, signature: res.signature, cert: res.cert, trustedIssuer: this.link.iss,
146
+ actaSeq: acta?.seq ?? null, sealers: acta ? sealersOf(acta) : null
147
+ })
119
148
  if (!chk.ok) throw new Error('el agente no está certificado por tu vault: ' + chk.reason)
120
149
  if (res.ack.machine !== this.agentPubkey) throw new Error('el ack vino de otro agente')
121
150
  if (res.ack.ceph !== eph.pub || res.ack.sid !== res.sid) throw new Error('ack no corresponde a este handshake')
package/src/discover.js CHANGED
@@ -24,7 +24,7 @@
24
24
  /**
25
25
  * @param {object} id instancia de Identity (del vault) ya conectada.
26
26
  * @param {string} [label] filtrar por servicio/label exacto (p. ej. `'content'`,
27
- * `'ia-agent'`). Omitir = todos los que tengan nombre y no sean `'cli'` (un navegador
27
+ * `'ia-agent'`). Omitir = todos los que tengan nameOf y no sean `'cli'` (un navegador
28
28
  * enrolado queda como `cli` y no atiende a nadie).
29
29
  * @returns {Promise<Array<{sub:string,label:string,cn:string|null}>>} uno por miembro.
30
30
  */
@@ -37,10 +37,10 @@ export async function listAgentsByLabel (id, label) {
37
37
  if (!acta) return []
38
38
 
39
39
  const mine = id.me?.publickey
40
- const nombre = (m) => m.cn || m.label || null
40
+ const nameOf = (m) => m.cn || m.label || null
41
41
  return (acta.members || [])
42
42
  .filter((m) => m?.pub && m.pub !== mine)
43
- .filter((m) => (label ? nombre(m) === label : (nombre(m) && nombre(m) !== 'cli')))
43
+ .filter((m) => (label ? nameOf(m) === label : (nameOf(m) && nameOf(m) !== 'cli')))
44
44
  .map((m) => ({ sub: m.pub, label: m.label || m.cn || '', cn: m.cn || null }))
45
45
  }
46
46
 
package/src/link.js CHANGED
File without changes