@dotrino/identity 0.140.0 → 0.140.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
@@ -124,7 +124,7 @@ Mismo registro de `peers` que arriba, pero filtrado por flag `isContact: true`.
124
124
  - `id.encrypt(recipients, plaintext)` → `{v:1, iv, ct, wrap}` envelope. `recipients` = `[{token, encryptionPubkey}]`. AES-256-GCM con clave efímera por mensaje, envuelta para cada destinatario vía ECDH(P-256). El campo `token` puede ser cualquier identificador estable (en messenger se usa la pubkey del destinatario para sobrevivir cambios de token del proxy).
125
125
  - `id.decrypt(senderEncryptionPubkey, myToken, envelope)` → `{ plaintext }`. Forward-secrecy por mensaje (clave simétrica nueva cada vez).
126
126
 
127
- **El mismo sobre sin el iframe: `@dotrino/identity/e2e` (0.140.0+).** Para un aparato headless
127
+ **El mismo sobre sin el iframe: `@dotrino/identity/e2e` (0.140.1+; la 0.140.0 sellaba sobres vacíos dentro de un service worker).** Para un aparato headless
128
128
  que tiene su propia llave de cifrado (un agente de `@dotrino/remote-agent`). Son las funciones
129
129
  que usa el núcleo por dentro, así que el sobre es byte a byte el mismo y prueba igual quién lo
130
130
  selló:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/identity",
3
- "version": "0.140.0",
3
+ "version": "0.140.2",
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",
@@ -100,5 +100,10 @@
100
100
  },
101
101
  "peerDependencies": {
102
102
  "@dotrino/proxy-client": ">=0.20.0"
103
+ },
104
+ "dotrino": {
105
+ "site": "id",
106
+ "dist": "vault",
107
+ "build": "bash scripts/build-vault-site.sh"
103
108
  }
104
109
  }
package/types/e2e.d.ts CHANGED
@@ -1,19 +1,3 @@
1
- /**
2
- * e2e.js — EL SOBRE DE PERSONA A PERSONA (v2), como funciones puras.
3
- *
4
- * Es el sobre que arma `identity.encrypt` y abre `identity.decrypt`: una clave AES nueva por
5
- * mensaje, envuelta para cada destinatario con ECDH entre la llave de cifrado de QUIEN MANDA y
6
- * la del destinatario. Por eso prueba de quién viene: solo lo pudo armar quien tiene la privada
7
- * de esa llave (el puente `identitySealing` de `@dotrino/proxy-client` la entrega como
8
- * `senderEncPub`).
9
- *
10
- * Vivía solo dentro del núcleo, atado a SU par de llaves. Sale aquí para que un aparato
11
- * headless que tiene su propia llave de cifrado (un agente de `@dotrino/remote-agent`) arme y
12
- * abra el MISMO sobre que una app del navegador, sin una segunda copia de la cripto. El núcleo
13
- * usa estas mismas funciones.
14
- *
15
- * No hay cripto nueva: ECDH P-256 + AES-GCM, como siempre.
16
- */
17
1
  /** @param {ArrayBuffer | ArrayLike<number>} buf @returns {string} */
18
2
  export function bufToBase64(buf: ArrayBuffer | ArrayLike<number>): string;
19
3
  /** @param {string} b64 @returns {ArrayBuffer} */
@@ -29,7 +13,12 @@ export function importPeerEncPubkey(jwkStr: string | JsonWebKey): Promise<Crypto
29
13
  export function deriveSharedAesKey(myPriv: any, peerPub: CryptoKey): Promise<CryptoKey>;
30
14
  /**
31
15
  * Id estable y corto de una llave de cifrado: con esto se indexan las envolturas. Es el
32
- * `pubkeyId` de `capabilities.js` (SHA-256 del JWK canónico) cortado a 16.
16
+ * `pubkeyId` de `keyid.js` (SHA-256 del JWK canónico) cortado a 16.
17
+ *
18
+ * IMPORT ESTÁTICO, y no es estética: un service worker (la extensión de contraseñas) no
19
+ * admite `import()` dinámico. Con `await import('./capabilities.js')` aquí, cada envoltura
20
+ * fallaba dentro del `catch` de `encryptFor` y el sobre salía SIN destinatarios: la bóveda
21
+ * lo recibía, «no es para mí», y la extensión veía silencio (0.140.0, arreglado en 0.140.1).
33
22
  * @param {string} encPub
34
23
  * @returns {Promise<string>}
35
24
  */
package/vault/e2e.js CHANGED
@@ -15,6 +15,8 @@
15
15
  * No hay cripto nueva: ECDH P-256 + AES-GCM, como siempre.
16
16
  */
17
17
 
18
+ import { pubkeyId } from './keyid.js'
19
+
18
20
  /** @param {ArrayBuffer | ArrayLike<number>} buf @returns {string} */
19
21
  export function bufToBase64 (buf) {
20
22
  const bytes = new Uint8Array(buf)
@@ -68,12 +70,16 @@ export async function deriveSharedAesKey (myPriv, peerPub) {
68
70
 
69
71
  /**
70
72
  * Id estable y corto de una llave de cifrado: con esto se indexan las envolturas. Es el
71
- * `pubkeyId` de `capabilities.js` (SHA-256 del JWK canónico) cortado a 16.
73
+ * `pubkeyId` de `keyid.js` (SHA-256 del JWK canónico) cortado a 16.
74
+ *
75
+ * IMPORT ESTÁTICO, y no es estética: un service worker (la extensión de contraseñas) no
76
+ * admite `import()` dinámico. Con `await import('./capabilities.js')` aquí, cada envoltura
77
+ * fallaba dentro del `catch` de `encryptFor` y el sobre salía SIN destinatarios: la bóveda
78
+ * lo recibía, «no es para mí», y la extensión veía silencio (0.140.0, arreglado en 0.140.1).
72
79
  * @param {string} encPub
73
80
  * @returns {Promise<string>}
74
81
  */
75
82
  export async function encKeyId (encPub) {
76
- const { pubkeyId } = await import('./capabilities.js')
77
83
  return (await pubkeyId(encPub)).slice(0, 16)
78
84
  }
79
85
 
@@ -100,6 +106,8 @@ export async function encryptFor ({ myEncPrivateKey, encPubs, plaintext }) {
100
106
  const ct = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, k, new TextEncoder().encode(plaintext))
101
107
  /** @type {Record<string, { iv: string, ct: string }>} */
102
108
  const wrap = {}
109
+ /** @type {any} */
110
+ let lastError = null
103
111
  for (const encPub of new Set(encPubs)) {
104
112
  try {
105
113
  const peerPub = await importPeerEncPubkey(encPub)
@@ -107,7 +115,13 @@ export async function encryptFor ({ myEncPrivateKey, encPubs, plaintext }) {
107
115
  const wrapIv = crypto.getRandomValues(new Uint8Array(12))
108
116
  const wrappedCt = await crypto.subtle.encrypt({ name: 'AES-GCM', iv: wrapIv }, sharedKey, kRaw)
109
117
  wrap[await encKeyId(encPub)] = { iv: bufToBase64(wrapIv), ct: bufToBase64(new Uint8Array(wrappedCt)) }
110
- } catch (_) { /* destinatario omitido: lo mira quien llama */ }
118
+ } catch (e) { lastError = e /* destinatario omitido; si no queda NINGUNO, se para abajo */ }
119
+ }
120
+ // UN SOBRE SIN ENVOLTURAS NO LO ABRE NADIE, y salir así es fallar en silencio: el otro lado
121
+ // lo descarta («no es para mí») y quien pidió solo ve que nadie contesta. Se para aquí, con
122
+ // la causa.
123
+ if (Object.keys(wrap).length === 0) {
124
+ throw Object.assign(new Error('encryptFor: no recipient could be sealed' + (lastError ? ` (${lastError.message})` : '')), { code: 'no-recipients' })
111
125
  }
112
126
  return { v: 2, iv: bufToBase64(iv), ct: bufToBase64(new Uint8Array(ct)), wrap }
113
127
  }
@@ -103,14 +103,21 @@ export async function sendToVault (client, { dest, to = null, acta = null, paylo
103
103
  // esconderle nada, y ahí la bóveda no tiene llave de cifrado que anunciar.
104
104
  if (client?.local) { client.sendByPubkey(dest, payload, opts); return { sealed: 0, why: 'local' } }
105
105
  const keys = to ? [to] : vaultKeysOf(await latestActa(client, acta))
106
- const encPubs = []
106
+ /** @type {{ key: string, peerEncPub: string }[]} */
107
+ const sealed = []
107
108
  let lastError = null
108
109
  for (const k of keys) {
109
- try { encPubs.push(await client.encPubOf(k)) } catch (e) { lastError = e }
110
+ try { sealed.push({ key: k, peerEncPub: await client.encPubOf(k) }) } catch (e) { lastError = e }
110
111
  }
111
- if (encPubs.length) {
112
- for (const peerEncPub of encPubs) await client.sendSealed([dest], payload, { peerEncPub, ...opts })
113
- return { sealed: encPubs.length }
112
+ // CADA SOBRE A LA LLAVE DE SU BÓVEDA, no todos a `dest`. `dest` es la maestra de la bóveda que
113
+ // firmó el papel, y una bóveda se ata en el proxio con su llave de comunicación y con el
114
+ // `profileId` (la maestra de la PRIMERA): la maestra de una hermana no la escucha nadie. Un
115
+ // aparato con el papel renovado por una hermana (la Nube, otra máquina) mandaba todo a una
116
+ // dirección muerta y la cuenta no contestaba con las bóvedas encendidas (la tableta de
117
+ // Seyacat, 2026-12-05). Regla del dueño: contesta la bóveda que esté encendida.
118
+ if (sealed.length) {
119
+ for (const { key, peerEncPub } of sealed) await client.sendSealed([key], payload, { peerEncPub, ...opts })
120
+ return { sealed: sealed.length }
114
121
  }
115
122
  const why = keys.length ? (/** @type {{ code?: string } | null} */ (lastError)?.code || 'no-encpub') : 'no-vault-key'
116
123
  if (!plainAllowed(now)) {