@dotrino/identity 0.123.0 → 0.124.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/identity",
3
- "version": "0.123.0",
3
+ "version": "0.124.0",
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.js CHANGED
@@ -431,10 +431,10 @@ export class Identity {
431
431
  * está emparejada con esa misma bóveda. Si no, falla antes de tocar la red.
432
432
  * @returns {Promise<{ ok:boolean, deviceId:string, master:string, exp:number, scope:string[] }>}
433
433
  */
434
- async enrollDevice (qr, { label = '', join = 'current' } = {}) {
434
+ async enrollDevice (qr, { label = '', join = 'current', account = null } = {}) {
435
435
  // DÓNDE CORRE se mira AQUÍ, en la página, y no dentro del iframe: el iframe no ve si la
436
436
  // página es una extensión o la app nativa (`vault/machine.js`).
437
- return this._call('vaultPair', { qr, label, join, machine: browserMachine() }, 200000)
437
+ return this._call('vaultPair', { qr, label, join, account, machine: browserMachine() }, 200000)
438
438
  }
439
439
 
440
440
  /** Estado de emparejamiento: { paired, deviceId?, master?, scope?, exp?, pairedAt? }. */
package/vault/acta.js CHANGED
@@ -35,7 +35,7 @@
35
35
  * Módulo PURO: sin kv, sin red, sin disco. Cripto de `./capabilities.js`.
36
36
  */
37
37
  import { canonicalStringify } from './core.js'
38
- import { signWithDevice, verifyDeviceSig, verifyDelegation, keyLabel } from './capabilities.js'
38
+ import { signWithDevice, verifyDeviceSig, verifyDelegation, keyLabel, pubkeyId } from './capabilities.js'
39
39
  import { cleanMachine } from './machine.js'
40
40
  export { cleanMachine }
41
41
 
@@ -639,6 +639,22 @@ export async function verifySignedBy (args = {}) {
639
639
  return { ok: true, profileId: c.profileId, seq: c.seq, signer: publickey }
640
640
  }
641
641
 
642
+ /**
643
+ * ¿ESTA INVITACIÓN ES DE LA CUENTA QUE ESPERO? Para un aparato que solo puede entrar en una
644
+ * cuenta (la réplica o la bóveda alojadas, que van atadas a la cuenta que las pagó). El reto del
645
+ * alta trae la cadena de selladoras de la bóveda que invita: se verifica, se comprueba que quien
646
+ * contestó sella esa cuenta y se compara el id del perfil con el esperado (`pubkeyId`, 64 hex).
647
+ * Devuelve `null` si es la cuenta, o el porqué si no.
648
+ */
649
+ export async function accountMismatch (chain, iss, account) {
650
+ if (!Array.isArray(chain) || !chain.length) return 'the vault did not say which account it belongs to (it may need an update)'
651
+ const c = await verifySealerChain(chain)
652
+ if (!c.ok) return 'the vault account could not be verified: ' + c.reason
653
+ if (!canSeal(chain[chain.length - 1], iss)) return 'the vault that answered does not seal that account'
654
+ const got = await pubkeyId(c.profileId)
655
+ return got === account ? null : `the invitation is from account ${got}, not from ${account}`
656
+ }
657
+
642
658
  export async function verifySealerChain (chain, { expectedProfileId = null } = {}) {
643
659
  if (!Array.isArray(chain) || !chain.length) return { ok: false, reason: 'empty-chain' }
644
660
  const [raiz] = chain
@@ -1307,7 +1323,7 @@ export async function canAdopt ({ candidate, current }) {
1307
1323
  }
1308
1324
 
1309
1325
  export default {
1310
- ACTA_V, CAPS, CAP_SCOPE, genesisActa, actaBody, actaHash, memberId, checkShape, verifySealerChain, verifySignedBy,
1326
+ ACTA_V, CAPS, CAP_SCOPE, genesisActa, actaBody, actaHash, memberId, checkShape, verifySealerChain, accountMismatch, verifySignedBy,
1311
1327
  sealActa, verifyActa, checkVaultReply, applyChanges, makeRenounce, verifyRenounce,
1312
1328
  makeContinuity, verifyContinuity,
1313
1329
  cardBody, makeProfileCard, verifyProfileCard, canAdoptCard, sealersOf, canSeal,
package/vault/core.js CHANGED
@@ -1329,7 +1329,7 @@ export async function createIdentityCore ({ kv: hostKv, peers, makeSync = null,
1329
1329
  * cert contra la bóveda y entra a su cuenta. Aparte para que la decisión de CUÁL cuenta y
1330
1330
  * el deshacerla si esto falla vivan juntos arriba, y aquí solo quede el trámite.
1331
1331
  */
1332
- async function pairWithVault ({ qr, label = '', machine = undefined }) {
1332
+ async function pairWithVault ({ qr, label = '', machine = undefined, account = null }) {
1333
1333
  // Usa la PROPIA llave de identidad de este navegador como dispositivo: el cert delega
1334
1334
  // TU identidad (P) desde la maestra M → una sola identidad (signData/identify/cert = P).
1335
1335
  // La privada es la CryptoKey del perfil (no extractable): se pasa como `privateKey`
@@ -1343,7 +1343,7 @@ export async function createIdentityCore ({ kv: hostKv, peers, makeSync = null,
1343
1343
  const continuity = (mine && mine.members.length === 1 && !isPendingJoin())
1344
1344
  ? await Acta.makeContinuity({ member: publickeyJwkStr, from: mine.profileId, privateKey: masterKey() })
1345
1345
  : null
1346
- const res = await remoteEnroll({ qr, device, continuity, encPub: encPublickeyJwkStr, label: label || me?.nickname || '', machine: machine === undefined && pageMachine ? pageMachine : machine, onChallenge: (c) => emitVault({ phase: 'challenge', deviceId: c.deviceId, code: c.code }) })
1346
+ const res = await remoteEnroll({ qr, device, continuity, encPub: encPublickeyJwkStr, label: label || me?.nickname || '', machine: machine === undefined && pageMachine ? pageMachine : machine, account, onChallenge: (c) => emitVault({ phase: 'challenge', deviceId: c.deviceId, code: c.code }) })
1347
1347
  kv.setItem(VAULT_DEVICE_STORAGE, JSON.stringify({ useIdentityKey: true, publickey: publickeyJwkStr }))
1348
1348
  kv.setItem(VAULT_CERT_STORAGE, JSON.stringify({ cert: res.cert, master: res.master, proxy: res.proxy, deviceId: res.deviceId, pairedAt: Date.now() }))
1349
1349
  // Conectarse a una bóveda es ENTRAR A SU CUENTA: el acta viene con el cert.
@@ -2936,7 +2936,7 @@ export async function createIdentityCore ({ kv: hostKv, peers, makeSync = null,
2936
2936
  * master: si esta cuenta ya la manda otra bóveda, no hay nada que
2937
2937
  * regalar y falla en voz alta.
2938
2938
  */
2939
- async vaultPair ({ qr, label = '', join = 'current', machine = undefined }) {
2939
+ async vaultPair ({ qr, label = '', join = 'current', machine = undefined, account = null }) {
2940
2940
  if (join === 'adopt') return handlers.vaultAdopt({ qr, label, machine })
2941
2941
  // La cuenta abierta AQUÍ y la que se cree para este intento. `born` es la que hay que
2942
2942
  // tirar si el emparejamiento no llega a término: nació para él y no tiene nada dentro.
@@ -2967,7 +2967,7 @@ export async function createIdentityCore ({ kv: hostKv, peers, makeSync = null,
2967
2967
  }
2968
2968
  }
2969
2969
  try {
2970
- return await pairWithVault({ qr, label, machine })
2970
+ return await pairWithVault({ qr, label, machine, account })
2971
2971
  } catch (e) {
2972
2972
  // El intento falló (código vencido, la bóveda dijo que no, se agotó la espera): la
2973
2973
  // cuenta que nació para él se va con él. Si no, cada reintento dejaba una cuenta
package/vault/facade.js CHANGED
@@ -136,7 +136,7 @@ export class IdentityFacade {
136
136
  /** Rota la clave de contenido (corta el acceso al contenido FUTURO de quien ya no está). */
137
137
  rotateContentKey () { return this._h('rotateContentKey') }
138
138
  // Emparejar ESTE dispositivo con el vault del usuario (Fase 1)
139
- enrollDevice (qr, { label = '', join = 'current' } = {}) { return this._h('vaultPair', { qr, label, join }) }
139
+ enrollDevice (qr, { label = '', join = 'current', account = null } = {}) { return this._h('vaultPair', { qr, label, join, account }) }
140
140
  vaultStatus () { return this._h('vaultStatus') }
141
141
  unpairDevice () { return this._h('vaultUnpair') }
142
142
  vaultSign (payload) { return this._h('vaultSign', { payload }) }
package/vault/remote.js CHANGED
@@ -14,7 +14,7 @@
14
14
  * `@dotrino/proxy-client` (importado perezosamente; solo se carga al emparejar).
15
15
  */
16
16
  import { makeDeviceKey, signWithDevice, verifyDeviceSig, makePairingCode, commitCode, keyLabel } from './capabilities.js'
17
- import { checkVaultReply } from './acta.js'
17
+ import { checkVaultReply, accountMismatch } from './acta.js'
18
18
  import { cleanMachine, browserMachine } from './machine.js'
19
19
 
20
20
  const MSG = {
@@ -143,9 +143,11 @@ async function askVault (client, qr) {
143
143
  * @param {(c:{deviceId:string, code:string})=>void} [opts.onChallenge] Para mostrar el código a tipear en el PC.
144
144
  * @param {string} [opts.label]
145
145
  * @param {number} [opts.approveTimeoutMs] Espera de la aprobación humana (def 3 min).
146
+ * @param {string} [opts.account] si viene (`pubkeyId` del perfil, 64 hex), SOLO entra en esa cuenta:
147
+ * se comprueba al llegar el reto, antes de enseñar el código (`wrong-account`).
146
148
  * @returns {Promise<{device, cert, master:string, proxy:string, deviceId:string, account:string}>}
147
149
  */
148
- export async function enrollDevice ({ qr, device, onChallenge, label = '', continuity = null, encPub = null, approveTimeoutMs = 180000, intent = 'join', profileId = null, onAdopt = null, machine = undefined } = {}) {
150
+ export async function enrollDevice ({ qr, device, onChallenge, label = '', continuity = null, encPub = null, approveTimeoutMs = 180000, intent = 'join', profileId = null, onAdopt = null, machine = undefined, account = null } = {}) {
149
151
  if (!qr?.sn || !(qr.iss || qr.conn)) throw new Error('invalid qr: missing vault or nonce')
150
152
  const { WebSocketProxyClient } = await import('@dotrino/proxy-client')
151
153
  const client = new WebSocketProxyClient({ url: qr.proxy || 'wss://proxy.dotrino.com', enableWebRTC: false, autoReconnect: false })
@@ -196,7 +198,13 @@ export async function enrollDevice ({ qr, device, onChallenge, label = '', conti
196
198
  const off = client.on('message', async (_from, p) => {
197
199
  if (!p || typeof p !== 'object') return
198
200
  if ((p.type === MSG.ENROLL_CHALLENGE || p.type === MSG.ERROR) && !await fromMyVault(p, qr)) return
199
- if (p.type === MSG.ENROLL_CHALLENGE) { try { onChallenge?.({ deviceId, code }) } catch (_) {} }
201
+ if (p.type === MSG.ENROLL_CHALLENGE) {
202
+ if (account) {
203
+ const why = await accountMismatch(p.signed?.chain, qr.iss, account)
204
+ if (why) { cleanup(); reject(Object.assign(new Error(why), { code: 'wrong-account' })); return }
205
+ }
206
+ try { onChallenge?.({ deviceId, code }) } catch (_) {}
207
+ }
200
208
  // El vault ECHA el código que tipeaste; aceptamos SOLO si coincide con el que generamos.
201
209
  // (Un código distinto = un vault que no lo conoce → lo ignoramos y seguimos esperando.)
202
210
  else if (p.type === MSG.ENROLLED) { if (p.code === code) { cleanup(); resolve(p) } }
@@ -1,3 +1,3 @@
1
- Copia vendorizada de @dotrino/roadmap@0.4.46 (dotrino-roadmap/src/{index,manifests}.js).
1
+ Copia vendorizada de @dotrino/roadmap@0.4.49 (dotrino-roadmap/src/{index,manifests}.js).
2
2
  NO se edita a mano: la escribe `node vendor.mjs` y la vigila test/vendor-up-to-date.test.mjs.
3
3
  El registro de versiones rotas que viaja con cada versión. Importa @dotrino/compat/ranges.
@@ -31,7 +31,7 @@ export const MANIFESTS = Object.freeze({
31
31
  "identity": {
32
32
  "repo": "imdotrino/dotrino-identity",
33
33
  "npm": "@dotrino/identity",
34
- "current": "0.121.8",
34
+ "current": "0.123.0",
35
35
  "protocol": 1,
36
36
  "requires": {
37
37
  "proxy-client": ">=0.13.1"
@@ -131,7 +131,7 @@ export const MANIFESTS = Object.freeze({
131
131
  "remote-agent": {
132
132
  "repo": "imdotrino/dotrino-remote-agent",
133
133
  "npm": "@dotrino/remote-agent",
134
- "current": "0.22.5",
134
+ "current": "0.23.1",
135
135
  "protocol": 1,
136
136
  "requires": {
137
137
  "identity": ">=0.121.7",
@@ -253,7 +253,7 @@ export const MANIFESTS = Object.freeze({
253
253
  "vault": {
254
254
  "repo": "imdotrino/dotrino-vault",
255
255
  "npm": "@dotrino/vault",
256
- "current": "0.94.0",
256
+ "current": "0.95.1",
257
257
  "protocol": 1,
258
258
  "requires": {
259
259
  "vaultd": ">=0.105.0",
@@ -269,7 +269,7 @@ export const MANIFESTS = Object.freeze({
269
269
  "vaultd": {
270
270
  "repo": "imdotrino/dotrino-vault",
271
271
  "npm": "@dotrino/vaultd",
272
- "current": "0.166.2",
272
+ "current": "0.167.1",
273
273
  "protocol": 1,
274
274
  "requires": {
275
275
  "identity": ">=0.118.0",
@@ -332,22 +332,22 @@ export const MANIFESTS = Object.freeze({
332
332
  },
333
333
  "app": {
334
334
  "repo": "imdotrino/dotrino-app",
335
- "current": "0.4.24",
335
+ "current": "0.4.25",
336
336
  "protocol": 1,
337
337
  "requires": {
338
- "proxy": "1.4.7+",
339
- "vaultd": ">=0.114.0",
340
- "identity": ">=0.110.1"
338
+ "proxy": "1.6.0+",
339
+ "vaultd": ">=0.159.0",
340
+ "identity": ">=0.117.2"
341
341
  }
342
342
  },
343
343
  "app-ios": {
344
344
  "repo": "imdotrino/dotrino-app",
345
- "current": "0.4.14",
345
+ "current": "0.4.15",
346
346
  "protocol": 1,
347
347
  "requires": {
348
- "proxy": "1.4.7+",
349
- "vaultd": ">=0.114.0",
350
- "identity": ">=0.110.1"
348
+ "proxy": "1.6.0+",
349
+ "vaultd": ">=0.159.0",
350
+ "identity": ">=0.117.2"
351
351
  }
352
352
  },
353
353
  "social-bot": {
@@ -364,14 +364,14 @@ export const MANIFESTS = Object.freeze({
364
364
  "accounts": {
365
365
  "repo": "imdotrino/dotrino-accounts",
366
366
  "npm": null,
367
- "current": "0.3.2",
367
+ "current": "0.5.0",
368
368
  "protocol": 1,
369
369
  "requires": {
370
370
  "identity": ">=0.116.0",
371
- "remote-agent": ">=0.19.0",
372
- "vault": ">=0.94.0",
371
+ "remote-agent": ">=0.23.1",
372
+ "vault": ">=0.95.0",
373
373
  "pay": ">=0.2.0",
374
- "vaultd": ">=0.166.2"
374
+ "vaultd": ">=0.167.0"
375
375
  }
376
376
  },
377
377
  "ai": {
@@ -1,4 +1,4 @@
1
- Copia vendorizada de @dotrino/vault@0.95.0 (dotrino-vault/lib/src/{admin,b64,browser,core/approvals,core/backup,core/blocked,core/browserDisk,core/commKey,core/disk,core/libVersion,core/machines,core/notices,core/notifiable,core/passwords,core/sealKey,core/sealer,core/sealers,core/secretsStore,core/sha256,core/store,core/subacta,core/threadStore,core/transport,core/vault,enroll,index,loginClient,passwordLogins,procContext,protocol,revocation,sealed}.js).
1
+ Copia vendorizada de @dotrino/vault@0.95.1 (dotrino-vault/lib/src/{admin,b64,browser,core/approvals,core/backup,core/blocked,core/browserDisk,core/commKey,core/disk,core/libVersion,core/machines,core/notices,core/notifiable,core/passwords,core/sealKey,core/sealer,core/sealers,core/secretsStore,core/sha256,core/store,core/subacta,core/threadStore,core/transport,core/vault,enroll,index,loginClient,passwordLogins,procContext,protocol,revocation,sealed}.js).
2
2
  NO se edita a mano: la escribe `node vendor.mjs` y la vigila test/vendor-up-to-date.test.mjs.
3
3
  browser.js es la bóveda de esta pestaña: el MISMO núcleo que el binario (core/), con
4
4
  el disco en IndexedDB. Importa @dotrino/{compat,roadmap,passmanager,store/core} y
@@ -5,4 +5,4 @@
5
5
  * si no coincide con la del paquete: una versión anunciada que no es la que corre es peor
6
6
  * que no anunciar ninguna.
7
7
  */
8
- export const LIB_VERSION = '0.95.0'
8
+ export const LIB_VERSION = '0.95.1'
@@ -24,7 +24,11 @@
24
24
  * `bad-action-signature`, `cert-device-mismatch`, `untrusted-issuer`…) son ruido o gente
25
25
  * ajena: ahí no hay a quién avisar de nada.
26
26
  */
27
- export const STALE_PAPER = Object.freeze(['revoked', 'expired', 'scope'])
27
+ // `legacy-cert-retired` (un papel del modelo viejo, sin `seq`) también: se rechaza ANTES de
28
+ // mirar la firma del certificado, pero DESPUÉS de la del aparato, así que el aviso solo
29
+ // puede ir a la llave de quien pregunta. Sin él, un navegador quitado del acta que guardaba
30
+ // un papel viejo se quedaba con la cuenta abierta para siempre (93D9-1B36, 2026-10-19).
31
+ export const STALE_PAPER = Object.freeze(['revoked', 'expired', 'scope', 'legacy-cert-retired'])
28
32
  const STALE = new Set(STALE_PAPER)
29
33
 
30
34
  /** ¿El motivo del rechazo es «tu papel ya no sirve»? */