@dotrino/identity 0.138.0 → 0.140.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/README.md +15 -0
- package/package.json +5 -1
- package/types/acta.d.ts +8 -0
- package/types/core.d.ts +4 -13
- package/types/e2e.d.ts +104 -0
- package/vault/acta.js +10 -2
- package/vault/core.js +9 -72
- package/vault/e2e.js +165 -0
- package/vault/index.html +1 -1
- package/vault/vendor/proxy-client/VERSION.txt +1 -1
- package/vault/vendor/proxy-client/ble/manager.js +3 -0
- package/vault/vendor/proxy-client/client.js +88 -2
- package/vault/vendor/proxy-client/webrtc.js +10 -1
- package/vault/vendor/roadmap/VERSION.txt +1 -1
- package/vault/vendor/roadmap/manifests.js +54 -15
package/README.md
CHANGED
|
@@ -124,6 +124,21 @@ 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
|
|
128
|
+
que tiene su propia llave de cifrado (un agente de `@dotrino/remote-agent`). Son las funciones
|
|
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
|
+
selló:
|
|
131
|
+
|
|
132
|
+
```js
|
|
133
|
+
import { keyIdentity, encryptFor, decryptFrom } from '@dotrino/identity/e2e'
|
|
134
|
+
import { identitySealing } from '@dotrino/proxy-client'
|
|
135
|
+
|
|
136
|
+
// encPub (JWK en texto) + privateKey (CryptoKey ECDH, con deriveKey o solo deriveBits)
|
|
137
|
+
client.updateConfig({ myEncPub: encPub, sealing: identitySealing(keyIdentity({ encPub, privateKey }), { app: 'messenger' }) })
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`keyIdentity` no expande destinatarios por su tarjeta: cifra a las llaves que se le dan.
|
|
141
|
+
|
|
127
142
|
### Firma genérica (0.7.0+)
|
|
128
143
|
|
|
129
144
|
- `id.signData(data)` → `{ signature, publickey }` con encoding canonical-JSON. Lo usa el messenger para construir sobres `identify` que el proxy verifica con su `verifySignatureWithJWK`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/identity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.140.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",
|
|
@@ -38,6 +38,10 @@
|
|
|
38
38
|
"types": "./types/acta.d.ts",
|
|
39
39
|
"import": "./vault/acta.js"
|
|
40
40
|
},
|
|
41
|
+
"./e2e": {
|
|
42
|
+
"types": "./types/e2e.d.ts",
|
|
43
|
+
"import": "./vault/e2e.js"
|
|
44
|
+
},
|
|
41
45
|
"./content": {
|
|
42
46
|
"types": "./types/content.d.ts",
|
|
43
47
|
"import": "./vault/content.js"
|
package/types/acta.d.ts
CHANGED
|
@@ -649,6 +649,14 @@ export const CAPS: readonly string[];
|
|
|
649
649
|
* Y va EN EL ACTA, no en una marca local de una máquina: así lo respeta cualquier bóveda
|
|
650
650
|
* de la cuenta, se ve en la pantalla de permisos como los demás, y se quita quitándolo —
|
|
651
651
|
* sin acordarse de un segundo registro escondido.
|
|
652
|
+
*
|
|
653
|
+
* `terminal` es ABRIR CONSOLAS en las máquinas de la cuenta que corren el agente de Dotrino
|
|
654
|
+
* Terminal, y `desktop` es USAR EL ESCRITORIO de las que corren el de Dotrino Remote Desktop
|
|
655
|
+
* (dueño, 2026-11-16, tras una auditoría de seguridad). Antes bastaba `sign`, así que
|
|
656
|
+
* cualquier aparato que firmara por ti tenía una shell en todas tus máquinas. Los agentes
|
|
657
|
+
* piden el permiso ADEMÁS de `sign`. Los dos conceden, no restringen (ver `checkShape`): un
|
|
658
|
+
* lector viejo los ignora y niega, que es el lado estricto. No tienen scope de certificado,
|
|
659
|
+
* como `unattended`: los mira el agente en el acta.
|
|
652
660
|
*/
|
|
653
661
|
export const DEVICE_CAPS: readonly string[];
|
|
654
662
|
/**
|
package/types/core.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
/** @param {any} v @returns {string} */
|
|
2
2
|
export function canonicalStringify(v: any): string;
|
|
3
|
-
/** @param {ArrayBuffer | ArrayLike<number>} buf @returns {string} */
|
|
4
|
-
export function bufToBase64(buf: ArrayBuffer | ArrayLike<number>): string;
|
|
5
|
-
/** @param {string} b64 @returns {ArrayBuffer} */
|
|
6
|
-
export function base64ToBuf(b64: string): ArrayBuffer;
|
|
7
3
|
/**
|
|
8
4
|
* QUÉ CLASE ES CADA DATO DEL PERFIL: `public` o `private`
|
|
9
5
|
* (`dotrino-vault/docs/datos-del-perfil.md` §2).
|
|
@@ -1011,15 +1007,7 @@ export function createIdentityCore({ kv: hostKv, peers, makeSync, keyStore: host
|
|
|
1011
1007
|
* perfil (§tarjeta). Le escribes a la persona, no al aparato desde el que te habló.
|
|
1012
1008
|
* @param {HandlerParams} params lo que llega por `postMessage` o la API: sin comprobar todavía
|
|
1013
1009
|
*/
|
|
1014
|
-
encrypt({ recipients, plaintext }: HandlerParams): Promise<
|
|
1015
|
-
v: number;
|
|
1016
|
-
iv: string;
|
|
1017
|
-
ct: string;
|
|
1018
|
-
wrap: Record<string, {
|
|
1019
|
-
iv: string;
|
|
1020
|
-
ct: string;
|
|
1021
|
-
}>;
|
|
1022
|
-
}>;
|
|
1010
|
+
encrypt({ recipients, plaintext }: HandlerParams): Promise<import("./e2e.js").E2eEnvelope>;
|
|
1023
1011
|
/**
|
|
1024
1012
|
* Descifra. Busca MI envoltura por el id de mi llave de cifrado (v2); `myToken` ya no
|
|
1025
1013
|
* hace falta y se acepta solo por compatibilidad de llamada.
|
|
@@ -1362,3 +1350,6 @@ export type Acta = import("./acta.js").Acta;
|
|
|
1362
1350
|
export type HandlerParams = Record<string, any>;
|
|
1363
1351
|
import * as Acta from './acta.js';
|
|
1364
1352
|
import * as Content from './content.js';
|
|
1353
|
+
import { bufToBase64 } from './e2e.js';
|
|
1354
|
+
import { base64ToBuf } from './e2e.js';
|
|
1355
|
+
export { bufToBase64, base64ToBuf };
|
package/types/e2e.d.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
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
|
+
/** @param {ArrayBuffer | ArrayLike<number>} buf @returns {string} */
|
|
18
|
+
export function bufToBase64(buf: ArrayBuffer | ArrayLike<number>): string;
|
|
19
|
+
/** @param {string} b64 @returns {ArrayBuffer} */
|
|
20
|
+
export function base64ToBuf(b64: string): ArrayBuffer;
|
|
21
|
+
/** @param {string | JsonWebKey} jwkStr @returns {Promise<CryptoKey>} */
|
|
22
|
+
export function importPeerEncPubkey(jwkStr: string | JsonWebKey): Promise<CryptoKey>;
|
|
23
|
+
/**
|
|
24
|
+
* La clave AES compartida entre mi privada y la pública del otro.
|
|
25
|
+
* @param {any} myPriv CryptoKey ECDH, o el asa de una llave del chip (`external`)
|
|
26
|
+
* @param {CryptoKey} peerPub
|
|
27
|
+
* @returns {Promise<CryptoKey>}
|
|
28
|
+
*/
|
|
29
|
+
export function deriveSharedAesKey(myPriv: any, peerPub: CryptoKey): Promise<CryptoKey>;
|
|
30
|
+
/**
|
|
31
|
+
* 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.
|
|
33
|
+
* @param {string} encPub
|
|
34
|
+
* @returns {Promise<string>}
|
|
35
|
+
*/
|
|
36
|
+
export function encKeyId(encPub: string): Promise<string>;
|
|
37
|
+
/**
|
|
38
|
+
* @typedef {{ v: 2, iv: string, ct: string, wrap: Record<string, { iv: string, ct: string }> }} E2eEnvelope
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* Cifra `plaintext` para cada llave de `encPubs`, con MI privada de cifrado.
|
|
42
|
+
*
|
|
43
|
+
* Un destinatario cuya llave no se puede importar se OMITE y no aparece en `wrap`: quien llama
|
|
44
|
+
* mira si quedó alguien (`identitySealing` lo hace), porque un sobre sin envolturas está cifrado
|
|
45
|
+
* de verdad y no lo abre nadie.
|
|
46
|
+
*
|
|
47
|
+
* @param {{ myEncPrivateKey: any, encPubs: Iterable<string>, plaintext: string }} args
|
|
48
|
+
* @returns {Promise<E2eEnvelope>}
|
|
49
|
+
*/
|
|
50
|
+
export function encryptFor({ myEncPrivateKey, encPubs, plaintext }: {
|
|
51
|
+
myEncPrivateKey: any;
|
|
52
|
+
encPubs: Iterable<string>;
|
|
53
|
+
plaintext: string;
|
|
54
|
+
}): Promise<E2eEnvelope>;
|
|
55
|
+
/**
|
|
56
|
+
* Abre un sobre que me mandó `senderEncPub`. Busca MI envoltura por el id de mi llave (v2);
|
|
57
|
+
* `myToken` solo por los sobres v1, que se indexaban por la conexión.
|
|
58
|
+
*
|
|
59
|
+
* Lanza si no soy destinatario o si no lo selló esa llave (AES-GCM no autentica con otra).
|
|
60
|
+
*
|
|
61
|
+
* @param {{ myEncPrivateKey: any, myEncPub: string, senderEncPub: string, envelope: any, myToken?: string | null }} args
|
|
62
|
+
* @returns {Promise<string>}
|
|
63
|
+
*/
|
|
64
|
+
export function decryptFrom({ myEncPrivateKey, myEncPub, senderEncPub, envelope, myToken }: {
|
|
65
|
+
myEncPrivateKey: any;
|
|
66
|
+
myEncPub: string;
|
|
67
|
+
senderEncPub: string;
|
|
68
|
+
envelope: any;
|
|
69
|
+
myToken?: string | null;
|
|
70
|
+
}): Promise<string>;
|
|
71
|
+
/**
|
|
72
|
+
* UNA IDENTIDAD DE CIFRADO desde un par de llaves suelto, con el dialecto del núcleo
|
|
73
|
+
* (`encryptionPubkey()`, `encrypt(destinatarios, texto)`, `decrypt(remitente, sobre)` →
|
|
74
|
+
* cadena). Es lo que `identitySealing` de `@dotrino/proxy-client` acepta, así que un aparato
|
|
75
|
+
* headless sella con el mismo sobre que una app del navegador:
|
|
76
|
+
*
|
|
77
|
+
* identitySealing(keyIdentity({ encPub, privateKey }), { app: 'messenger' })
|
|
78
|
+
*
|
|
79
|
+
* No expande destinatarios por su tarjeta de perfil (no tiene libreta): cifra a las llaves que
|
|
80
|
+
* se le dan.
|
|
81
|
+
*
|
|
82
|
+
* @param {{ encPub: string, privateKey: any }} keys
|
|
83
|
+
*/
|
|
84
|
+
export function keyIdentity({ encPub, privateKey }: {
|
|
85
|
+
encPub: string;
|
|
86
|
+
privateKey: any;
|
|
87
|
+
}): {
|
|
88
|
+
encryptionPubkey: () => string;
|
|
89
|
+
/** @param {Array<{ encryptionPubkey?: string }>} recipients @param {string} plaintext */
|
|
90
|
+
encrypt: (recipients: Array<{
|
|
91
|
+
encryptionPubkey?: string;
|
|
92
|
+
}>, plaintext: string) => Promise<E2eEnvelope>;
|
|
93
|
+
/** @param {string} senderEncPub @param {any} envelope */
|
|
94
|
+
decrypt: (senderEncPub: string, envelope: any) => Promise<string>;
|
|
95
|
+
};
|
|
96
|
+
export type E2eEnvelope = {
|
|
97
|
+
v: 2;
|
|
98
|
+
iv: string;
|
|
99
|
+
ct: string;
|
|
100
|
+
wrap: Record<string, {
|
|
101
|
+
iv: string;
|
|
102
|
+
ct: string;
|
|
103
|
+
}>;
|
|
104
|
+
};
|
package/vault/acta.js
CHANGED
|
@@ -171,7 +171,7 @@ const conCampoSellador = (acta) => Number(acta?.v) < V_SIN_CAMPO_SELLADOR
|
|
|
171
171
|
* el rol de master, que no se delega. Así un dispositivo con `admin` robado hace daño
|
|
172
172
|
* acotado y **reversible** (se le revoca), en vez de poder dejarte fuera de tu cuenta.
|
|
173
173
|
*/
|
|
174
|
-
export const CAPS = Object.freeze(['sign', 'store', 'read', 'admin', 'approve', 'passwords', 'sealer', 'unattended', 'replica'])
|
|
174
|
+
export const CAPS = Object.freeze(['sign', 'store', 'read', 'admin', 'approve', 'passwords', 'sealer', 'unattended', 'replica', 'terminal', 'desktop'])
|
|
175
175
|
|
|
176
176
|
/** Capacidades de un DISPOSITIVO (sin CN): acceso a todo lo del usuario. */
|
|
177
177
|
/**
|
|
@@ -214,8 +214,16 @@ export const CAPS = Object.freeze(['sign', 'store', 'read', 'admin', 'approve',
|
|
|
214
214
|
* Y va EN EL ACTA, no en una marca local de una máquina: así lo respeta cualquier bóveda
|
|
215
215
|
* de la cuenta, se ve en la pantalla de permisos como los demás, y se quita quitándolo —
|
|
216
216
|
* sin acordarse de un segundo registro escondido.
|
|
217
|
+
*
|
|
218
|
+
* `terminal` es ABRIR CONSOLAS en las máquinas de la cuenta que corren el agente de Dotrino
|
|
219
|
+
* Terminal, y `desktop` es USAR EL ESCRITORIO de las que corren el de Dotrino Remote Desktop
|
|
220
|
+
* (dueño, 2026-11-16, tras una auditoría de seguridad). Antes bastaba `sign`, así que
|
|
221
|
+
* cualquier aparato que firmara por ti tenía una shell en todas tus máquinas. Los agentes
|
|
222
|
+
* piden el permiso ADEMÁS de `sign`. Los dos conceden, no restringen (ver `checkShape`): un
|
|
223
|
+
* lector viejo los ignora y niega, que es el lado estricto. No tienen scope de certificado,
|
|
224
|
+
* como `unattended`: los mira el agente en el acta.
|
|
217
225
|
*/
|
|
218
|
-
export const DEVICE_CAPS = Object.freeze(['sign', 'store', 'read', 'admin', 'approve', 'passwords', 'sealer', 'unattended', 'replica'])
|
|
226
|
+
export const DEVICE_CAPS = Object.freeze(['sign', 'store', 'read', 'admin', 'approve', 'passwords', 'sealer', 'unattended', 'replica', 'terminal', 'desktop'])
|
|
219
227
|
|
|
220
228
|
/**
|
|
221
229
|
* Lo que recibe un dispositivo recién emparejado. `admin` **no está**: no se
|
package/vault/core.js
CHANGED
|
@@ -24,6 +24,7 @@ import * as Content from './content.js'
|
|
|
24
24
|
import { syncPeers, stampOf } from './peerSync.js'
|
|
25
25
|
import { assertionBody, cleanScopes, claimsAllowed, ASSERTION_DEFAULT_TTL_MS, ASSERTION_MAX_TTL_MS } from './assertion.js'
|
|
26
26
|
import { pubkeyId as pubkeyIdOf, signWithDevice, keyLabel } from './capabilities.js'
|
|
27
|
+
import { bufToBase64, base64ToBuf, encryptFor, decryptFrom } from './e2e.js'
|
|
27
28
|
import { enrollDevice as remoteEnroll, requestSign as remoteSign, requestStore as remoteStore, requestDevices as remoteDevices, requestRenew as remoteRenew, requestAdmin as remoteAdmin, requestApproval as remoteApproval, requestRenounce as remoteRenounce, checkMembership as remoteCheck, registerLocalVault } from './remote.js'
|
|
28
29
|
|
|
29
30
|
/**
|
|
@@ -149,45 +150,8 @@ export function canonicalStringify (v) {
|
|
|
149
150
|
return '{' + ks.map(k => JSON.stringify(k) + ':' + canonicalStringify(v[k])).join(',') + '}'
|
|
150
151
|
}
|
|
151
152
|
|
|
152
|
-
|
|
153
|
-
export
|
|
154
|
-
const bytes = new Uint8Array(buf)
|
|
155
|
-
let s = ''
|
|
156
|
-
for (let i = 0; i < bytes.length; i++) s += String.fromCharCode(bytes[i])
|
|
157
|
-
return btoa(s)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/** @param {string} b64 @returns {ArrayBuffer} */
|
|
161
|
-
export function base64ToBuf (b64) {
|
|
162
|
-
const s = atob(b64)
|
|
163
|
-
const bytes = new Uint8Array(s.length)
|
|
164
|
-
for (let i = 0; i < s.length; i++) bytes[i] = s.charCodeAt(i)
|
|
165
|
-
return bytes.buffer
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/** @param {string | JsonWebKey} jwkStr @returns {Promise<CryptoKey>} */
|
|
169
|
-
async function importPeerEncPubkey (jwkStr) {
|
|
170
|
-
const jwk = typeof jwkStr === 'string' ? JSON.parse(jwkStr) : jwkStr
|
|
171
|
-
return crypto.subtle.importKey('jwk', jwk, { name: 'ECDH', namedCurve: 'P-256' }, true, [])
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/** @param {any} myPriv CryptoKey ECDH, o el asa de una llave del chip @param {CryptoKey} peerPub @returns {Promise<CryptoKey>} */
|
|
175
|
-
async function deriveSharedAesKey (myPriv, peerPub) {
|
|
176
|
-
if (myPriv?.external) {
|
|
177
|
-
// Llave EXTERNA: el chip da los 32 bytes del secreto ECDH, que es exactamente lo que
|
|
178
|
-
// `deriveKey` ECDH→AES-256 usa por dentro. Mismo AES, sin que la privada salga.
|
|
179
|
-
const { kty, crv, x, y } = await crypto.subtle.exportKey('jwk', peerPub)
|
|
180
|
-
const bits = await myPriv.deriveBits(JSON.stringify({ kty, crv, x, y }))
|
|
181
|
-
return crypto.subtle.importKey('raw', bits, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])
|
|
182
|
-
}
|
|
183
|
-
return crypto.subtle.deriveKey(
|
|
184
|
-
{ name: 'ECDH', public: peerPub },
|
|
185
|
-
myPriv,
|
|
186
|
-
{ name: 'AES-GCM', length: 256 },
|
|
187
|
-
false,
|
|
188
|
-
['encrypt', 'decrypt']
|
|
189
|
-
)
|
|
190
|
-
}
|
|
153
|
+
// El sobre de persona a persona y sus piezas viven en e2e.js (puras, sin el par de este núcleo).
|
|
154
|
+
export { bufToBase64, base64ToBuf }
|
|
191
155
|
|
|
192
156
|
/** @param {any} privateKey CryptoKey ECDSA, o el asa de una llave del chip @param {Uint8Array<ArrayBuffer>} bytes @returns {Promise<string>} */
|
|
193
157
|
async function signBytes (privateKey, bytes) {
|
|
@@ -947,10 +911,6 @@ export async function createIdentityCore ({ kv: hostKv, peers, makeSync = null,
|
|
|
947
911
|
return r
|
|
948
912
|
}
|
|
949
913
|
|
|
950
|
-
/** Id estable y corto de una llave de cifrado: con esto se indexan las envolturas. */
|
|
951
|
-
/** @param {string} encPub */
|
|
952
|
-
const encKeyId = async (encPub) => (await pubkeyIdOf(encPub)).slice(0, 16)
|
|
953
|
-
|
|
954
914
|
/** @returns {VaultLink | null} */
|
|
955
915
|
const loadVaultCert = () => { try { return JSON.parse(kv.getItem(VAULT_CERT_STORAGE) || 'null') } catch (_) { return null } }
|
|
956
916
|
|
|
@@ -4045,11 +4005,6 @@ export async function createIdentityCore ({ kv: hostKv, peers, makeSync = null,
|
|
|
4045
4005
|
async encrypt ({ recipients, plaintext }) {
|
|
4046
4006
|
if (!Array.isArray(recipients) || recipients.length === 0) throw new Error('recipients required')
|
|
4047
4007
|
if (typeof plaintext !== 'string') throw new Error('plaintext required')
|
|
4048
|
-
const k = await crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, true, ['encrypt', 'decrypt'])
|
|
4049
|
-
const kRaw = await crypto.subtle.exportKey('raw', k)
|
|
4050
|
-
const iv = crypto.getRandomValues(new Uint8Array(12))
|
|
4051
|
-
const ct = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, k, new TextEncoder().encode(plaintext))
|
|
4052
|
-
|
|
4053
4008
|
// Expandir cada destinatario a TODOS los dispositivos de su perfil que conozcamos.
|
|
4054
4009
|
const encPubs = new Set()
|
|
4055
4010
|
const peers = loadPeers()
|
|
@@ -4059,19 +4014,7 @@ export async function createIdentityCore ({ kv: hostKv, peers, makeSync = null,
|
|
|
4059
4014
|
const card = (r.publickey && peers[r.publickey]?.card) || null
|
|
4060
4015
|
for (const kk of (card?.keys || [])) if (kk.encPub) encPubs.add(kk.encPub)
|
|
4061
4016
|
}
|
|
4062
|
-
|
|
4063
|
-
/** @type {Record<string, { iv: string, ct: string }>} */
|
|
4064
|
-
const wrap = {}
|
|
4065
|
-
for (const encPub of encPubs) {
|
|
4066
|
-
try {
|
|
4067
|
-
const peerPub = await importPeerEncPubkey(encPub)
|
|
4068
|
-
const sharedKey = await deriveSharedAesKey(encKeypair.privateKey, peerPub)
|
|
4069
|
-
const wrapIv = crypto.getRandomValues(new Uint8Array(12))
|
|
4070
|
-
const wrappedCt = await crypto.subtle.encrypt({ name: 'AES-GCM', iv: wrapIv }, sharedKey, kRaw)
|
|
4071
|
-
wrap[await encKeyId(encPub)] = { iv: bufToBase64(wrapIv), ct: bufToBase64(new Uint8Array(wrappedCt)) }
|
|
4072
|
-
} catch (e) { /* destinatario omitido */ }
|
|
4073
|
-
}
|
|
4074
|
-
return { v: 2, iv: bufToBase64(iv), ct: bufToBase64(new Uint8Array(ct)), wrap }
|
|
4017
|
+
return encryptFor({ myEncPrivateKey: encKeypair.privateKey, encPubs, plaintext })
|
|
4075
4018
|
},
|
|
4076
4019
|
|
|
4077
4020
|
/**
|
|
@@ -4080,17 +4023,11 @@ export async function createIdentityCore ({ kv: hostKv, peers, makeSync = null,
|
|
|
4080
4023
|
* @param {HandlerParams} params lo que llega por `postMessage` o la API: sin comprobar todavía
|
|
4081
4024
|
*/
|
|
4082
4025
|
async decrypt ({ senderEncryptionPubkey, myToken, envelope }) {
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
const senderPub = await importPeerEncPubkey(senderEncryptionPubkey)
|
|
4089
|
-
const sharedKey = await deriveSharedAesKey(encKeypair.privateKey, senderPub)
|
|
4090
|
-
const kRaw = await crypto.subtle.decrypt({ name: 'AES-GCM', iv: base64ToBuf(myEntry.iv) }, sharedKey, base64ToBuf(myEntry.ct))
|
|
4091
|
-
const k = await crypto.subtle.importKey('raw', kRaw, { name: 'AES-GCM', length: 256 }, false, ['decrypt'])
|
|
4092
|
-
const ptBytes = await crypto.subtle.decrypt({ name: 'AES-GCM', iv: base64ToBuf(envelope.iv) }, k, base64ToBuf(envelope.ct))
|
|
4093
|
-
return { plaintext: new TextDecoder().decode(ptBytes) }
|
|
4026
|
+
const plaintext = await decryptFrom({
|
|
4027
|
+
myEncPrivateKey: encKeypair.privateKey, myEncPub: encPublickeyJwkStr,
|
|
4028
|
+
senderEncPub: senderEncryptionPubkey, envelope, myToken
|
|
4029
|
+
})
|
|
4030
|
+
return { plaintext }
|
|
4094
4031
|
},
|
|
4095
4032
|
|
|
4096
4033
|
async exportIdentity () {
|
package/vault/e2e.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
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
|
+
|
|
18
|
+
/** @param {ArrayBuffer | ArrayLike<number>} buf @returns {string} */
|
|
19
|
+
export function bufToBase64 (buf) {
|
|
20
|
+
const bytes = new Uint8Array(buf)
|
|
21
|
+
let s = ''
|
|
22
|
+
for (let i = 0; i < bytes.length; i++) s += String.fromCharCode(bytes[i])
|
|
23
|
+
return btoa(s)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** @param {string} b64 @returns {ArrayBuffer} */
|
|
27
|
+
export function base64ToBuf (b64) {
|
|
28
|
+
const s = atob(b64)
|
|
29
|
+
const bytes = new Uint8Array(s.length)
|
|
30
|
+
for (let i = 0; i < s.length; i++) bytes[i] = s.charCodeAt(i)
|
|
31
|
+
return bytes.buffer
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @param {string | JsonWebKey} jwkStr @returns {Promise<CryptoKey>} */
|
|
35
|
+
export async function importPeerEncPubkey (jwkStr) {
|
|
36
|
+
const jwk = typeof jwkStr === 'string' ? JSON.parse(jwkStr) : jwkStr
|
|
37
|
+
return crypto.subtle.importKey('jwk', jwk, { name: 'ECDH', namedCurve: 'P-256' }, true, [])
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* La clave AES compartida entre mi privada y la pública del otro.
|
|
42
|
+
* @param {any} myPriv CryptoKey ECDH, o el asa de una llave del chip (`external`)
|
|
43
|
+
* @param {CryptoKey} peerPub
|
|
44
|
+
* @returns {Promise<CryptoKey>}
|
|
45
|
+
*/
|
|
46
|
+
export async function deriveSharedAesKey (myPriv, peerPub) {
|
|
47
|
+
if (myPriv?.external) {
|
|
48
|
+
// Llave EXTERNA: el chip da los 32 bytes del secreto ECDH, que es exactamente lo que
|
|
49
|
+
// `deriveKey` ECDH→AES-256 usa por dentro. Mismo AES, sin que la privada salga.
|
|
50
|
+
const { kty, crv, x, y } = await crypto.subtle.exportKey('jwk', peerPub)
|
|
51
|
+
const bits = await myPriv.deriveBits(JSON.stringify({ kty, crv, x, y }))
|
|
52
|
+
return crypto.subtle.importKey('raw', bits, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])
|
|
53
|
+
}
|
|
54
|
+
if (!myPriv?.usages?.includes('deriveKey')) {
|
|
55
|
+
// Una llave que solo admite `deriveBits` (la de un agente, `makeEncKeypair`): los mismos
|
|
56
|
+
// 32 bytes del secreto ECDH, y el mismo AES que daría `deriveKey`.
|
|
57
|
+
const bits = await crypto.subtle.deriveBits({ name: 'ECDH', public: peerPub }, myPriv, 256)
|
|
58
|
+
return crypto.subtle.importKey('raw', bits, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])
|
|
59
|
+
}
|
|
60
|
+
return crypto.subtle.deriveKey(
|
|
61
|
+
{ name: 'ECDH', public: peerPub },
|
|
62
|
+
myPriv,
|
|
63
|
+
{ name: 'AES-GCM', length: 256 },
|
|
64
|
+
false,
|
|
65
|
+
['encrypt', 'decrypt']
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 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.
|
|
72
|
+
* @param {string} encPub
|
|
73
|
+
* @returns {Promise<string>}
|
|
74
|
+
*/
|
|
75
|
+
export async function encKeyId (encPub) {
|
|
76
|
+
const { pubkeyId } = await import('./capabilities.js')
|
|
77
|
+
return (await pubkeyId(encPub)).slice(0, 16)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @typedef {{ v: 2, iv: string, ct: string, wrap: Record<string, { iv: string, ct: string }> }} E2eEnvelope
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Cifra `plaintext` para cada llave de `encPubs`, con MI privada de cifrado.
|
|
86
|
+
*
|
|
87
|
+
* Un destinatario cuya llave no se puede importar se OMITE y no aparece en `wrap`: quien llama
|
|
88
|
+
* mira si quedó alguien (`identitySealing` lo hace), porque un sobre sin envolturas está cifrado
|
|
89
|
+
* de verdad y no lo abre nadie.
|
|
90
|
+
*
|
|
91
|
+
* @param {{ myEncPrivateKey: any, encPubs: Iterable<string>, plaintext: string }} args
|
|
92
|
+
* @returns {Promise<E2eEnvelope>}
|
|
93
|
+
*/
|
|
94
|
+
export async function encryptFor ({ myEncPrivateKey, encPubs, plaintext }) {
|
|
95
|
+
if (!myEncPrivateKey) throw new Error('encryptFor: myEncPrivateKey required')
|
|
96
|
+
if (typeof plaintext !== 'string') throw new Error('plaintext required')
|
|
97
|
+
const k = await crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, true, ['encrypt', 'decrypt'])
|
|
98
|
+
const kRaw = await crypto.subtle.exportKey('raw', k)
|
|
99
|
+
const iv = crypto.getRandomValues(new Uint8Array(12))
|
|
100
|
+
const ct = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, k, new TextEncoder().encode(plaintext))
|
|
101
|
+
/** @type {Record<string, { iv: string, ct: string }>} */
|
|
102
|
+
const wrap = {}
|
|
103
|
+
for (const encPub of new Set(encPubs)) {
|
|
104
|
+
try {
|
|
105
|
+
const peerPub = await importPeerEncPubkey(encPub)
|
|
106
|
+
const sharedKey = await deriveSharedAesKey(myEncPrivateKey, peerPub)
|
|
107
|
+
const wrapIv = crypto.getRandomValues(new Uint8Array(12))
|
|
108
|
+
const wrappedCt = await crypto.subtle.encrypt({ name: 'AES-GCM', iv: wrapIv }, sharedKey, kRaw)
|
|
109
|
+
wrap[await encKeyId(encPub)] = { iv: bufToBase64(wrapIv), ct: bufToBase64(new Uint8Array(wrappedCt)) }
|
|
110
|
+
} catch (_) { /* destinatario omitido: lo mira quien llama */ }
|
|
111
|
+
}
|
|
112
|
+
return { v: 2, iv: bufToBase64(iv), ct: bufToBase64(new Uint8Array(ct)), wrap }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Abre un sobre que me mandó `senderEncPub`. Busca MI envoltura por el id de mi llave (v2);
|
|
117
|
+
* `myToken` solo por los sobres v1, que se indexaban por la conexión.
|
|
118
|
+
*
|
|
119
|
+
* Lanza si no soy destinatario o si no lo selló esa llave (AES-GCM no autentica con otra).
|
|
120
|
+
*
|
|
121
|
+
* @param {{ myEncPrivateKey: any, myEncPub: string, senderEncPub: string, envelope: any, myToken?: string | null }} args
|
|
122
|
+
* @returns {Promise<string>}
|
|
123
|
+
*/
|
|
124
|
+
export async function decryptFrom ({ myEncPrivateKey, myEncPub, senderEncPub, envelope, myToken = null }) {
|
|
125
|
+
if (!senderEncPub) throw new Error('senderEncryptionPubkey required')
|
|
126
|
+
if (!envelope || (envelope.v !== 1 && envelope.v !== 2)) throw new Error('Unsupported envelope')
|
|
127
|
+
const myId = await encKeyId(myEncPub)
|
|
128
|
+
const myEntry = envelope.wrap && (envelope.wrap[myId] || (myToken ? envelope.wrap[myToken] : null))
|
|
129
|
+
if (!myEntry) throw new Error('this device is not among the message recipients')
|
|
130
|
+
const senderPub = await importPeerEncPubkey(senderEncPub)
|
|
131
|
+
const sharedKey = await deriveSharedAesKey(myEncPrivateKey, senderPub)
|
|
132
|
+
const kRaw = await crypto.subtle.decrypt({ name: 'AES-GCM', iv: new Uint8Array(base64ToBuf(myEntry.iv)) }, sharedKey, base64ToBuf(myEntry.ct))
|
|
133
|
+
const k = await crypto.subtle.importKey('raw', kRaw, { name: 'AES-GCM', length: 256 }, false, ['decrypt'])
|
|
134
|
+
const ptBytes = await crypto.subtle.decrypt({ name: 'AES-GCM', iv: new Uint8Array(base64ToBuf(envelope.iv)) }, k, base64ToBuf(envelope.ct))
|
|
135
|
+
return new TextDecoder().decode(ptBytes)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* UNA IDENTIDAD DE CIFRADO desde un par de llaves suelto, con el dialecto del núcleo
|
|
140
|
+
* (`encryptionPubkey()`, `encrypt(destinatarios, texto)`, `decrypt(remitente, sobre)` →
|
|
141
|
+
* cadena). Es lo que `identitySealing` de `@dotrino/proxy-client` acepta, así que un aparato
|
|
142
|
+
* headless sella con el mismo sobre que una app del navegador:
|
|
143
|
+
*
|
|
144
|
+
* identitySealing(keyIdentity({ encPub, privateKey }), { app: 'messenger' })
|
|
145
|
+
*
|
|
146
|
+
* No expande destinatarios por su tarjeta de perfil (no tiene libreta): cifra a las llaves que
|
|
147
|
+
* se le dan.
|
|
148
|
+
*
|
|
149
|
+
* @param {{ encPub: string, privateKey: any }} keys
|
|
150
|
+
*/
|
|
151
|
+
export function keyIdentity ({ encPub, privateKey }) {
|
|
152
|
+
if (typeof encPub !== 'string' || !encPub) throw new Error('keyIdentity: encPub required')
|
|
153
|
+
if (!privateKey) throw new Error('keyIdentity: privateKey required')
|
|
154
|
+
return {
|
|
155
|
+
encryptionPubkey: () => encPub,
|
|
156
|
+
/** @param {Array<{ encryptionPubkey?: string }>} recipients @param {string} plaintext */
|
|
157
|
+
encrypt: (recipients, plaintext) => encryptFor({
|
|
158
|
+
myEncPrivateKey: privateKey,
|
|
159
|
+
encPubs: (recipients || []).flatMap((r) => (typeof r?.encryptionPubkey === 'string' && r.encryptionPubkey ? [r.encryptionPubkey] : [])),
|
|
160
|
+
plaintext
|
|
161
|
+
}),
|
|
162
|
+
/** @param {string} senderEncPub @param {any} envelope */
|
|
163
|
+
decrypt: (senderEncPub, envelope) => decryptFrom({ myEncPrivateKey: privateKey, myEncPub: encPub, senderEncPub, envelope })
|
|
164
|
+
}
|
|
165
|
+
}
|
package/vault/index.html
CHANGED
|
@@ -188,7 +188,7 @@
|
|
|
188
188
|
document.head.appendChild(goat)
|
|
189
189
|
// Por CDN el topbar va SIEMPRE con `+esm` (CONVENCIONES §5). Pone el idioma en
|
|
190
190
|
// <html lang>, que es de lo que cuelgan los bloques [data-lang].
|
|
191
|
-
import('https://cdn.jsdelivr.net/npm/@dotrino/topbar@0.
|
|
191
|
+
import('https://cdn.jsdelivr.net/npm/@dotrino/topbar@0.17/+esm')
|
|
192
192
|
}
|
|
193
193
|
</script>
|
|
194
194
|
</body>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copia vendorizada de @dotrino/proxy-client@0.
|
|
1
|
+
Copia vendorizada de @dotrino/proxy-client@0.49.1 (dotrino-proxy-client/src/{binpack,ble/manager,ble/wire,canonical,client,encpub,errors,index,parts,sealing,signature,stats-log,stats,webrtc}.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
|
sealing.js resuelve @dotrino/identity/content de forma PEREZOSA (= ../../content.js
|
|
4
4
|
por el import map): solo se carga si de verdad se sella algo.
|
|
@@ -393,9 +393,12 @@ export class BluetoothManager {
|
|
|
393
393
|
async sendDirect (to, wire, highWater = 256 * 1024) {
|
|
394
394
|
const p = this.peers.get(to)
|
|
395
395
|
if (!p || p.state !== 'open') return false
|
|
396
|
+
// Como en WebRTC: un canal que no vacía lo pendiente en 5 s no cuelga a quien manda (0.49.1).
|
|
397
|
+
const since = Date.now()
|
|
396
398
|
while (p.pending > highWater) {
|
|
397
399
|
await new Promise((r) => setTimeout(r, 15))
|
|
398
400
|
if (p.state !== 'open') return false
|
|
401
|
+
if (Date.now() - since > 5000) return false
|
|
399
402
|
}
|
|
400
403
|
return this.trySend(to, wire)
|
|
401
404
|
}
|
|
@@ -23,7 +23,12 @@ const HELLO_TAG = '__cc_hello__'
|
|
|
23
23
|
* que no se le mandan: se lanza `peer-no-binary` y la app lo enseña. La idea del dueño es que
|
|
24
24
|
* todo pase a binario con el tiempo, y esta lista es por donde se sabrá quién ya puede.
|
|
25
25
|
*/
|
|
26
|
-
|
|
26
|
+
// Lo que este cliente entiende, y lo dice al saludar (`helloTo`):
|
|
27
|
+
// - `binary`: tramas con bytes (0.36.0).
|
|
28
|
+
// - `parts`: rearma también lo que llega EN CLARO en partes (0.49.0). Lo sellado se rearma
|
|
29
|
+
// desde 0.33.0; esto es lo que deja trocear a `send` y `sendToOrQueue`, que llevan lo que la
|
|
30
|
+
// app ya cifró por su cuenta (el canal de `@dotrino/remote-agent`).
|
|
31
|
+
const SPEAKS = ['binary', 'parts']
|
|
27
32
|
|
|
28
33
|
/** @typedef {import('./index.js').WebSocketProxyClientOptions} WebSocketProxyClientOptions */
|
|
29
34
|
/** @typedef {import('./index.js').SignFn} SignFn */
|
|
@@ -250,6 +255,8 @@ export class WebSocketProxyClient {
|
|
|
250
255
|
this._nextId = 1
|
|
251
256
|
/** @type {Map<string, TokenWatch>} messageId -> { token, sobre, peerPubkey, timer, queueFallback } */
|
|
252
257
|
this._tokenWatch = new Map()
|
|
258
|
+
/** @type {Map<string, Promise<void>>} token → lo que todavía sale hacia él en partes (send) */
|
|
259
|
+
this._outChains = new Map()
|
|
253
260
|
// Mensajes grandes que llegan en partes (parts.js). Uno que se queda a medias se DICE:
|
|
254
261
|
// con él se pierde el mensaje entero, y eso no puede pasar callado.
|
|
255
262
|
this._parts = new Reassembler({
|
|
@@ -605,6 +612,20 @@ export class WebSocketProxyClient {
|
|
|
605
612
|
'unsealed')
|
|
606
613
|
}
|
|
607
614
|
const tokens = Array.isArray(to) ? to : [to]
|
|
615
|
+
// UNO GRANDE, EN PARTES, A QUIEN LO ENTIENDE (0.49.0): lo que pasa de lo que admite el camino
|
|
616
|
+
// de ese token sale troceado (parts.js) si su saludo dijo `parts`. Y lo que va detrás a un
|
|
617
|
+
// token que está recibiendo partes espera su turno: si no, adelantaría al grande.
|
|
618
|
+
const now = this._queueBehindParts(tokens, payload)
|
|
619
|
+
if (!now.length) return
|
|
620
|
+
this._sendNow(now, payload)
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Lo de `send` que ya no espera a nadie: por el mejor canal de cada token, entero.
|
|
625
|
+
* @param {string[]} tokens
|
|
626
|
+
* @param {any} payload
|
|
627
|
+
*/
|
|
628
|
+
_sendNow (tokens, payload) {
|
|
608
629
|
const messageStr = this._wire(payload)
|
|
609
630
|
if (!this._rtc && !this._ble) {
|
|
610
631
|
this._sendRaw({ to: tokens, message: messageStr })
|
|
@@ -1010,9 +1031,73 @@ export class WebSocketProxyClient {
|
|
|
1010
1031
|
if (!token || !peerPubkey) {
|
|
1011
1032
|
throw errorWithCode('sendToOrQueue: needs the token and whose it is (peerPubkey)', 'no-peer-identity')
|
|
1012
1033
|
}
|
|
1034
|
+
if (!this._queueBehindParts([token], payload, peerPubkey).length) return
|
|
1013
1035
|
this._sendToTokenOrQueue(token, payload, peerPubkey)
|
|
1014
1036
|
}
|
|
1015
1037
|
|
|
1038
|
+
/**
|
|
1039
|
+
* TROCEAR LO QUE LA APP YA CIFRÓ, solo hacia quien sepa rearmarlo (0.49.0).
|
|
1040
|
+
*
|
|
1041
|
+
* Por cada token: si el mensaje no cabe en un mensaje de su camino y la otra punta dijo `parts`
|
|
1042
|
+
* en su saludo, sale en partes; si ya hay partes saliendo hacia ese token, este mensaje se pone
|
|
1043
|
+
* detrás, también uno pequeño, para que llegue en el orden en que se mandó. Devuelve los tokens
|
|
1044
|
+
* que no tienen nada de eso, que se mandan como siempre.
|
|
1045
|
+
*
|
|
1046
|
+
* Quien NO dijo `parts` (no ha saludado, o es de antes: las apps nativas todavía) recibe el
|
|
1047
|
+
* mensaje entero, como antes de esto. No es un repliegue: es lo que esa punta entiende.
|
|
1048
|
+
*
|
|
1049
|
+
* @param {string[]} tokens
|
|
1050
|
+
* @param {any} payload
|
|
1051
|
+
* @param {string} [peerPubkey] de quién es (si es uno solo); si no, lo que dijo su saludo
|
|
1052
|
+
* @returns {string[]}
|
|
1053
|
+
*/
|
|
1054
|
+
_queueBehindParts (tokens, payload, peerPubkey) {
|
|
1055
|
+
/** @type {string[]} */
|
|
1056
|
+
const now = []
|
|
1057
|
+
/** @type {Measured | null} */
|
|
1058
|
+
let m = null
|
|
1059
|
+
for (const t of tokens) {
|
|
1060
|
+
const busy = this._outChains.has(t)
|
|
1061
|
+
let pieces = null
|
|
1062
|
+
if (!this.requireSealed && this.speaks(t, 'parts') === true) {
|
|
1063
|
+
m ||= this._measure(payload)
|
|
1064
|
+
const size = this._directFor(t) ? DIRECT_PART_CHARS : PROXY_PART_CHARS
|
|
1065
|
+
if (!m.bin && m.len > size) pieces = { list: splitParts(/** @type {string} */ (m.whole), size), len: m.len }
|
|
1066
|
+
}
|
|
1067
|
+
if (!pieces && !busy) { now.push(t); continue }
|
|
1068
|
+
const pk = peerPubkey || this.pubkeyOfToken(t) || undefined
|
|
1069
|
+
const job = pieces
|
|
1070
|
+
? async () => {
|
|
1071
|
+
if (!this._directFor(t) && pieces.len > RELAY_MAX_CHARS) {
|
|
1072
|
+
this._upgradeDirect([t])
|
|
1073
|
+
throw errorWithCode(`send: ${pieces.len} chars is more than goes through the proxy live (${RELAY_MAX_CHARS}); it needs a direct channel`, 'too-big-for-relay')
|
|
1074
|
+
}
|
|
1075
|
+
for (const piece of pieces.list) {
|
|
1076
|
+
if (pk) await this._sendPiece(t, this._wire(piece), pk, pieces.len <= QUEUE_MAX_CHARS, pieces.len <= RELAY_MAX_CHARS)
|
|
1077
|
+
else { const d = this._directFor(t); if (!(d && await d.sendDirect(t, this._wire(piece)))) this._sendRaw({ to: [t], message: this._wire(piece) }) }
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
: async () => { if (pk) this._sendToTokenOrQueue(t, payload, pk); else this._sendNow([t], payload) }
|
|
1081
|
+
this._chainOut(t, job)
|
|
1082
|
+
}
|
|
1083
|
+
return now
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
/**
|
|
1087
|
+
* Una cola por token: lo que va a ese token sale en orden. Un fallo se dice por `error`
|
|
1088
|
+
* (`send` no devuelve nada que se pueda esperar), con su `code`.
|
|
1089
|
+
* @param {string} token
|
|
1090
|
+
* @param {() => Promise<void>} job
|
|
1091
|
+
*/
|
|
1092
|
+
_chainOut (token, job) {
|
|
1093
|
+
const prev = this._outChains.get(token) || Promise.resolve()
|
|
1094
|
+
const next = prev.then(job).catch((e) => {
|
|
1095
|
+
this._emit('error', { type: 'client', error: /** @type {{ message?: string }} */ (e).message, code: codeOf(e) || 'send-failed', token })
|
|
1096
|
+
})
|
|
1097
|
+
this._outChains.set(token, next)
|
|
1098
|
+
next.then(() => { if (this._outChains.get(token) === next) this._outChains.delete(token) })
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1016
1101
|
/**
|
|
1017
1102
|
* UN TOKEN MUERTO NO SE TRAGA EL MENSAJE. Un token es una conexión, y cuando la otra punta
|
|
1018
1103
|
* reinicia la app su token deja de existir; la app que lo tenía apuntado sigue mandando ahí
|
|
@@ -1547,7 +1632,8 @@ export class WebSocketProxyClient {
|
|
|
1547
1632
|
this._emit('error', { type: 'unsealed', reason: 'plaintext_rejected', from })
|
|
1548
1633
|
return
|
|
1549
1634
|
}
|
|
1550
|
-
|
|
1635
|
+
// En claro también se rearma (0.49.0): lo que la app cifró por su cuenta llega en partes.
|
|
1636
|
+
this._handOpened(from, payload, { ...meta, sealed: false })
|
|
1551
1637
|
}
|
|
1552
1638
|
|
|
1553
1639
|
/**
|
|
@@ -84,6 +84,9 @@ export function usable (peer) {
|
|
|
84
84
|
return !!(peer && peer.dc && peer.dc.readyState === 'open' && peer.pc && peer.pc.connectionState === 'connected')
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
/** Lo que se espera a que el canal directo vacíe su búfer antes de darlo por muerto. */
|
|
88
|
+
export const STALL_MS = 5000
|
|
89
|
+
|
|
87
90
|
/** @param {typeof RTCPeerConnection | null} impl */
|
|
88
91
|
export function setPeerConnection (impl) { _PC = impl; _PCLookedUp = true }
|
|
89
92
|
|
|
@@ -261,13 +264,19 @@ export class WebRTCManager {
|
|
|
261
264
|
* @param {number} [highWater]
|
|
262
265
|
* @returns {Promise<boolean>}
|
|
263
266
|
*/
|
|
264
|
-
async sendDirect (to, payloadString, highWater = 1024 * 1024) {
|
|
267
|
+
async sendDirect (to, payloadString, highWater = 1024 * 1024, stallMs = STALL_MS) {
|
|
265
268
|
const peer = this.peers.get(to)
|
|
266
269
|
if (!usable(peer)) return false
|
|
267
270
|
const dc = peer.dc
|
|
271
|
+
// UN CANAL QUE NO VACÍA SU BÚFER ESTÁ MUERTO (0.49.1). Esperarlo sin tope colgaba para
|
|
272
|
+
// siempre a quien manda en partes, y con ellas todo lo que iba detrás al mismo destino (el
|
|
273
|
+
// escritorio remoto se quedaba sin escena). Pasado `stallMs` sin bajar, se cierra —la
|
|
274
|
+
// siguiente vez se negocia de nuevo— y se dice que no salió, para que vaya por el proxio.
|
|
275
|
+
const since = Date.now()
|
|
268
276
|
while (dc.bufferedAmount > highWater) {
|
|
269
277
|
await new Promise((r) => setTimeout(r, 15))
|
|
270
278
|
if (!usable(peer)) return false
|
|
279
|
+
if (Date.now() - since > stallMs) { this.closePeer(to); return false }
|
|
271
280
|
}
|
|
272
281
|
try {
|
|
273
282
|
// `send` tiene una sobrecarga por tipo y no acepta la unión; el canal lleva las dos.
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
Copia vendorizada de @dotrino/roadmap@0.4.
|
|
1
|
+
Copia vendorizada de @dotrino/roadmap@0.4.89 (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.
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
export const MANIFESTS = Object.freeze({
|
|
9
9
|
"dotrino": {
|
|
10
10
|
"manifest": "dotrino",
|
|
11
|
-
"seq":
|
|
12
|
-
"issued": "2026-
|
|
11
|
+
"seq": 51,
|
|
12
|
+
"issued": "2026-11-08T20:55:05.000Z",
|
|
13
13
|
"note": "Registro comun de compatibilidad del ecosistema. Se edita a mano en este repo y se consulta con @dotrino/roadmap. Rangos: ver @dotrino/compat/ranges (x.y.z, >= > <= <, «a - b», «*», o una lista que es un O).",
|
|
14
14
|
"products": {
|
|
15
15
|
"compat": {
|
|
@@ -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.
|
|
34
|
+
"current": "0.138.0",
|
|
35
35
|
"protocol": 1,
|
|
36
36
|
"requires": {
|
|
37
37
|
"proxy-client": ">=0.20.0"
|
|
@@ -83,6 +83,32 @@ export const MANIFESTS = Object.freeze({
|
|
|
83
83
|
"proxy": "1.1.0+"
|
|
84
84
|
}
|
|
85
85
|
},
|
|
86
|
+
"notes": {
|
|
87
|
+
"repo": "imdotrino/dotrino-notes",
|
|
88
|
+
"current": "0.3.0",
|
|
89
|
+
"protocol": 1,
|
|
90
|
+
"requires": {
|
|
91
|
+
"identity": ">=0.138.0",
|
|
92
|
+
"store": ">=0.14.3",
|
|
93
|
+
"topbar": ">=0.17.3"
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"notes-android": {
|
|
97
|
+
"repo": "imdotrino/dotrino-notes",
|
|
98
|
+
"current": "0.3.0",
|
|
99
|
+
"protocol": 1,
|
|
100
|
+
"requires": {
|
|
101
|
+
"proxy": "1.1.0+"
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"notes-ios": {
|
|
105
|
+
"repo": "imdotrino/dotrino-notes",
|
|
106
|
+
"current": "0.3.0",
|
|
107
|
+
"protocol": 1,
|
|
108
|
+
"requires": {
|
|
109
|
+
"proxy": "1.1.0+"
|
|
110
|
+
}
|
|
111
|
+
},
|
|
86
112
|
"notifications": {
|
|
87
113
|
"repo": "imdotrino/dotrino-notifications",
|
|
88
114
|
"npm": "@dotrino/notifications",
|
|
@@ -124,7 +150,7 @@ export const MANIFESTS = Object.freeze({
|
|
|
124
150
|
"proxy-client": {
|
|
125
151
|
"repo": "imdotrino/dotrino-proxy-client",
|
|
126
152
|
"npm": "@dotrino/proxy-client",
|
|
127
|
-
"current": "0.
|
|
153
|
+
"current": "0.49.1",
|
|
128
154
|
"protocol": 2,
|
|
129
155
|
"requires": {
|
|
130
156
|
"identity": ">=0.53.0",
|
|
@@ -134,7 +160,7 @@ export const MANIFESTS = Object.freeze({
|
|
|
134
160
|
"remote-agent": {
|
|
135
161
|
"repo": "imdotrino/dotrino-remote-agent",
|
|
136
162
|
"npm": "@dotrino/remote-agent",
|
|
137
|
-
"current": "0.
|
|
163
|
+
"current": "0.37.0",
|
|
138
164
|
"protocol": 1,
|
|
139
165
|
"requires": {
|
|
140
166
|
"identity": ">=0.136.0",
|
|
@@ -161,17 +187,30 @@ export const MANIFESTS = Object.freeze({
|
|
|
161
187
|
"terminal-agent": {
|
|
162
188
|
"repo": "imdotrino/dotrino-terminal",
|
|
163
189
|
"npm": "@dotrino/terminal-agent",
|
|
164
|
-
"current": "0.
|
|
190
|
+
"current": "0.55.0",
|
|
165
191
|
"protocol": 2,
|
|
166
192
|
"requires": {
|
|
167
|
-
"remote-agent": ">=0.
|
|
168
|
-
"identity": ">=0.
|
|
193
|
+
"remote-agent": ">=0.37.0",
|
|
194
|
+
"identity": ">=0.136.0",
|
|
169
195
|
"vault": ">=0.115.0",
|
|
170
|
-
"proxy-client": ">=0.
|
|
171
|
-
"update": ">=0.9.
|
|
196
|
+
"proxy-client": ">=0.49.0",
|
|
197
|
+
"update": ">=0.9.4",
|
|
172
198
|
"vaultd": ">=0.142.0"
|
|
173
199
|
}
|
|
174
200
|
},
|
|
201
|
+
"remote-desktop-agent": {
|
|
202
|
+
"repo": "imdotrino/dotrino-remote-desktop",
|
|
203
|
+
"npm": "@dotrino/remote-desktop-agent",
|
|
204
|
+
"current": "0.5.0",
|
|
205
|
+
"protocol": 1,
|
|
206
|
+
"requires": {
|
|
207
|
+
"remote-agent": ">=0.37.0",
|
|
208
|
+
"proxy-client": ">=0.49.0",
|
|
209
|
+
"identity": ">=0.136.0",
|
|
210
|
+
"vault": ">=0.115.0",
|
|
211
|
+
"update": ">=0.9.4"
|
|
212
|
+
}
|
|
213
|
+
},
|
|
175
214
|
"terminal-ios": {
|
|
176
215
|
"repo": "imdotrino/dotrino-terminal",
|
|
177
216
|
"current": "0.13.8",
|
|
@@ -256,14 +295,14 @@ export const MANIFESTS = Object.freeze({
|
|
|
256
295
|
"theme": {
|
|
257
296
|
"repo": "imdotrino/dotrino-theme",
|
|
258
297
|
"npm": "@dotrino/theme",
|
|
259
|
-
"current": "0.1.
|
|
298
|
+
"current": "0.1.2",
|
|
260
299
|
"protocol": 1,
|
|
261
300
|
"requires": {}
|
|
262
301
|
},
|
|
263
302
|
"topbar": {
|
|
264
303
|
"repo": "imdotrino/dotrino-topbar",
|
|
265
304
|
"npm": "@dotrino/topbar",
|
|
266
|
-
"current": "0.17.
|
|
305
|
+
"current": "0.17.3",
|
|
267
306
|
"protocol": 1,
|
|
268
307
|
"requires": {
|
|
269
308
|
"identity": ">=0.96.1",
|
|
@@ -289,7 +328,7 @@ export const MANIFESTS = Object.freeze({
|
|
|
289
328
|
"vaultd": {
|
|
290
329
|
"repo": "imdotrino/dotrino-vault",
|
|
291
330
|
"npm": "@dotrino/vaultd",
|
|
292
|
-
"current": "0.193.
|
|
331
|
+
"current": "0.193.3",
|
|
293
332
|
"protocol": 1,
|
|
294
333
|
"requires": {
|
|
295
334
|
"identity": ">=0.136.0",
|
|
@@ -342,10 +381,10 @@ export const MANIFESTS = Object.freeze({
|
|
|
342
381
|
},
|
|
343
382
|
"passmanager-extension": {
|
|
344
383
|
"repo": "imdotrino/dotrino-passmanager",
|
|
345
|
-
"current": "0.
|
|
384
|
+
"current": "0.62.0",
|
|
346
385
|
"protocol": 1,
|
|
347
386
|
"requires": {
|
|
348
|
-
"identity": ">=0.
|
|
387
|
+
"identity": ">=0.138.0",
|
|
349
388
|
"proxy-client": ">=0.47.0",
|
|
350
389
|
"vault": ">=0.120.1",
|
|
351
390
|
"proxy": "1.1.0+",
|