@dotrino/remote-agent 0.27.0 → 0.29.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 (3) hide show
  1. package/README.md +13 -1
  2. package/package.json +1 -1
  3. package/src/link.js +67 -3
package/README.md CHANGED
@@ -33,7 +33,7 @@ Provee lo común — y **solo** eso:
33
33
  | `@dotrino/remote-agent` | isomórfico | `e2e` (`makeEphemeral`/`deriveKey`/`seal`/`open`) + constantes de protocolo |
34
34
  | `@dotrino/remote-agent/agent` | Node | `startRemoteAgent(opts)` |
35
35
  | `@dotrino/remote-agent/client` | navegador | `RemoteAgentClient` |
36
- | `@dotrino/remote-agent/link` | Node | `enroll`, `loadLink`, `saveLink`, `dataDir`, `parseQr`, `identityFromLink`, `clientLink`, `renewLink` |
36
+ | `@dotrino/remote-agent/link` | Node | `enroll`, `selfLink`, `isSelfLink`, `loadLink`, `saveLink`, `dataDir`, `parseQr`, `identityFromLink`, `clientLink`, `renewLink` |
37
37
  | `@dotrino/remote-agent/discover` | navegador | `listAgentsByLabel`, `probeAgents` |
38
38
  | `@dotrino/remote-agent/instances` | Node | `resolveInstance`, `listInstances`, `lockInstance`, `instancesRoot` |
39
39
 
@@ -107,6 +107,18 @@ parámetros (`{ ns, proxyUrl: link.proxy, masterPubkey: link.iss, device, cert,
107
107
  Un agente que corre UNA vez (un bot por cron) no tiene el tic de renovación de
108
108
  `startRemoteAgent`: que llame a `renewLink(link)` en cada corrida, o su cert muere a los 30 días.
109
109
 
110
+ ### Sin bóveda: identidad propia (`selfLink`)
111
+
112
+ Un agente no tiene por qué exigir una bóveda. `selfLink({ label, dir })` crea las llaves
113
+ del aparato (firma y cifrado) y un acta de génesis autofirmada donde él es el único
114
+ miembro: una cuenta de un solo aparato, la misma forma que «este dispositivo es bóveda»
115
+ en el navegador. `identityFromLink` la sirve igual (`signData` lleva la cadena `[génesis]`
116
+ y `verifySignedFor` la acepta); lo que pregunta a una bóveda lanza `no-vault`.
117
+
118
+ Emparejarlo después con una bóveda (`enroll`) le da **una llave nueva** y sobrescribe el
119
+ enlace: una llave vive en una sola cuenta. Si la dirección o el nombre del agente salen de
120
+ la llave, cambian al emparejar.
121
+
110
122
  ### Dónde vive el enlace: `~/.dotrino/agent/<tipo>/<nombre>/` (el estándar)
111
123
 
112
124
  Todo agente guarda su enlace ahí, igual que `dotrino-env` guarda el suyo en
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/remote-agent",
3
- "version": "0.27.0",
3
+ "version": "0.29.0",
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",
package/src/link.js CHANGED
@@ -16,11 +16,11 @@
16
16
  import fs from 'node:fs'
17
17
  import path from 'node:path'
18
18
  import os from 'node:os'
19
- import { signWithDevice, pubkeyId } from '@dotrino/identity/capabilities'
19
+ import { signWithDevice, pubkeyId, makeDeviceKey, makeDeviceEncKey } from '@dotrino/identity/capabilities'
20
20
  import { requestDevices, requestRenew } from '@dotrino/identity/vault/remote.js'
21
21
  import { installNodeGlobals } from '../node-globals.js'
22
22
  import { adoptRecord } from './record.js'
23
- import { verifySealerChain } from '@dotrino/identity/acta'
23
+ import { verifySealerChain, genesisActa, sealActa } from '@dotrino/identity/acta'
24
24
  import { DEFAULT_PROXY, RENEW_BEFORE_MS } from '../protocol.js'
25
25
 
26
26
  export function dataDir (name = 'dotrino-remote-agent') {
@@ -99,6 +99,42 @@ export async function enroll ({ qr, label = 'remote-agent', dir = dataDir(), ns
99
99
  return link
100
100
  }
101
101
 
102
+ /**
103
+ * UNA IDENTIDAD PROPIA, SIN BÓVEDA. El aparato cumple el rol cuando no hay pieza dedicada:
104
+ * crea sus llaves (firma y cifrado) y un acta de génesis autofirmada donde él es el único
105
+ * miembro. Es una cuenta de un solo aparato, igual que «este dispositivo es bóveda» en el
106
+ * navegador: `verifySignedFor` la acepta sin saber nada más, porque la raíz de toda cuenta
107
+ * es un acta autofirmada.
108
+ *
109
+ * El enlace queda `{ device, enc, label, self: true, sealerChain: [génesis], at }`, sin
110
+ * `cert` ni `iss`.
111
+ *
112
+ * EMPAREJARLO DESPUÉS CAMBIA LA LLAVE, a propósito (dueño, 2026-11-04): `enroll` crea otra y
113
+ * sobrescribe este enlace. Una llave está en UNA sola cuenta. Si entrara a una bóveda con la
114
+ * misma, seguiría siendo la raíz de su génesis y podría entrar igual a otras bóvedas.
115
+ *
116
+ * @param {{ label?: string, dir?: string }} [args]
117
+ */
118
+ export async function selfLink ({ label = 'remote-agent', dir = dataDir() } = {}) {
119
+ installNodeGlobals(dir)
120
+ const d = await makeDeviceKey({ label })
121
+ const e = await makeDeviceEncKey()
122
+ const genesis = await sealActa({
123
+ acta: genesisActa({ pub: d.publickey, encPub: e.encPublickey, label }),
124
+ privateJwk: d.privateJwk
125
+ })
126
+ const link = {
127
+ device: { publickey: d.publickey, privateJwk: d.privateJwk },
128
+ enc: { publickey: e.encPublickey, privateJwk: e.encPrivateJwk },
129
+ label, self: true, sealerChain: [genesis], at: Date.now()
130
+ }
131
+ saveLink(dir, link)
132
+ return link
133
+ }
134
+
135
+ /** ¿Es una identidad propia (sin bóveda)? */
136
+ export const isSelfLink = (link) => link?.self === true
137
+
102
138
  /**
103
139
  * La IDENTIDAD de un agente a partir de su enlace: lo que un cliente del ecosistema
104
140
  * espera como `link.id` (`RemoteAgentClient`, `ContentClient`, `listAgentsByLabel`) —
@@ -111,6 +147,7 @@ export async function enroll ({ qr, label = 'remote-agent', dir = dataDir(), ns
111
147
  * @param {{ dir?: string }} [opts] dir para los globals de Node (localStorage del proxy-client).
112
148
  */
113
149
  export function identityFromLink (link, { dir = dataDir() } = {}) {
150
+ if (isSelfLink(link)) return selfIdentity(link, dir)
114
151
  if (!link?.device?.privateJwk || !link?.cert || !link?.iss) throw new Error('invalid link: device/cert/iss required')
115
152
  installNodeGlobals(dir)
116
153
  const device = link.device
@@ -157,6 +194,31 @@ export function identityFromLink (link, { dir = dataDir() } = {}) {
157
194
  }
158
195
  }
159
196
 
197
+ /**
198
+ * La identidad de un enlace propio: firma con su llave y prueba con su génesis. Lo que
199
+ * pregunta a una bóveda no existe aquí, y se dice (`no-vault`) en vez de inventarse.
200
+ */
201
+ function selfIdentity (link, dir) {
202
+ const chain = link.sealerChain
203
+ if (!link?.device?.privateJwk || !Array.isArray(chain) || chain.length !== 1) throw new Error('invalid self link: device and its genesis required')
204
+ installNodeGlobals(dir)
205
+ const device = link.device
206
+ const noVault = () => Promise.reject(Object.assign(new Error('this device has its own identity and is not paired with a vault'), { code: 'no-vault' }))
207
+ return {
208
+ me: { publickey: device.publickey },
209
+ async signData (data) {
210
+ const signed = await signWithDevice({ privateJwk: device.privateJwk, publickey: device.publickey, data })
211
+ return { ...signed, profileId: chain[0].profileId, chain }
212
+ },
213
+ getVaultCert: noVault,
214
+ async vaultStatus () {
215
+ return { paired: false, self: true, master: null, proxy: link.proxy || DEFAULT_PROXY, deviceId: await pubkeyId(device.publickey), seq: chain[0].seq }
216
+ },
217
+ listVaultDevices: noVault,
218
+ async profileActa () { return { acta: chain[0] } }
219
+ }
220
+ }
221
+
160
222
  const trustedActaOf = (link) => (link?.actaTrusted === true && link.acta ? link.acta : null)
161
223
 
162
224
  /** El acta que `listVaultDevices` puede dar por buena. Exportada para las pruebas. */
@@ -256,6 +318,8 @@ export async function renewLink (link, { dir = dataDir(), force = false } = {})
256
318
  * @returns {Promise<{ ok: boolean, seq?: number, reason?: string }>}
257
319
  */
258
320
  export async function refreshChain (link, { dir = dataDir() } = {}) {
321
+ // Una identidad propia es su propia cadena: no hay a quién preguntar ni nada que caduque.
322
+ if (isSelfLink(link)) return { ok: true, seq: link.sealerChain?.[0]?.seq ?? 1, self: true }
259
323
  if (!link?.device?.privateJwk || !link?.cert || !link?.iss) return { ok: false, reason: 'invalid link' }
260
324
  installNodeGlobals(dir)
261
325
  try {
@@ -283,4 +347,4 @@ export function clientLink (link, opts) {
283
347
  return { id: identityFromLink(link, opts), cert: link.cert, iss: link.iss, proxy: link.proxy || DEFAULT_PROXY }
284
348
  }
285
349
 
286
- export default { dataDir, loadLink, saveLink, parseQr, enroll, identityFromLink, clientLink, renewLink, renewalReason, storeRenewedCert, refreshChain }
350
+ export default { dataDir, loadLink, saveLink, parseQr, enroll, selfLink, isSelfLink, identityFromLink, clientLink, renewLink, renewalReason, storeRenewedCert, refreshChain }