@dotrino/identity 0.136.0 → 0.136.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/package.json +3 -2
- package/src/index.d.ts +60 -2
- package/src/index.js +364 -81
- package/src/node.js +29 -5
- package/types/acta.d.ts +397 -175
- package/types/assertion.d.ts +25 -18
- package/types/avatar.d.ts +14 -3
- package/types/capabilities.d.ts +110 -61
- package/types/content.d.ts +88 -45
- package/types/core.d.ts +578 -383
- package/types/keyid.d.ts +10 -3
- package/types/machine.d.ts +5 -1
- package/types/peerStore.d.ts +80 -0
- package/types/peerSync.d.ts +20 -6
- package/types/remote.d.ts +170 -42
- package/types/session.d.ts +74 -81
- package/types/sessionFlow.d.ts +108 -33
- package/types/vaultSeal.d.ts +21 -9
- package/vault/acta.js +245 -29
- package/vault/assertion.js +13 -4
- package/vault/avatar.js +12 -1
- package/vault/capabilities.js +56 -6
- package/vault/channel.js +18 -2
- package/vault/content.js +60 -6
- package/vault/core.js +419 -88
- package/vault/externalKeys.js +34 -2
- package/vault/facade.js +182 -24
- package/vault/globals.d.ts +60 -0
- package/vault/keyid.js +10 -1
- package/vault/machine.js +7 -1
- package/vault/nativeStore.js +21 -4
- package/vault/originPolicy.js +13 -2
- package/vault/peerStore.js +57 -10
- package/vault/peerSync.js +23 -4
- package/vault/remote.js +132 -32
- package/vault/session.js +24 -7
- package/vault/sessionFlow.js +43 -9
- package/vault/sync.js +59 -15
- package/vault/vault.js +78 -49
- package/vault/vaultSeal.js +18 -7
- package/vault/vendor/compat/VERSION.txt +1 -1
- package/vault/vendor/compat/advisory.js +58 -8
- package/vault/vendor/compat/index.js +57 -6
- package/vault/vendor/compat/ranges.js +12 -2
- package/vault/vendor/proxy-client/VERSION.txt +1 -1
- package/vault/vendor/proxy-client/client.js +41 -19
- package/vault/vendor/roadmap/manifests.js +23 -23
- package/vault/vendor/store/VERSION.txt +1 -1
- package/vault/vendor/vault/VERSION.txt +1 -1
- package/vault/vendor/vault/core/libVersion.js +1 -1
- package/vault/vendor/vault/core/transport.js +15 -3
- package/vault/vendor/vault/core/vault.js +71 -1
- package/vault/vendor/vault/protocol.js +25 -0
package/types/keyid.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* id corto y estable de un pubkey (sha-256 hex de los campos canónicos del JWK).
|
|
3
|
+
* @param {string | JsonWebKey} publicJwkStr
|
|
4
|
+
* @returns {Promise<string>}
|
|
5
|
+
*/
|
|
6
|
+
export function pubkeyId(publicJwkStr: string | JsonWebKey): Promise<string>;
|
|
3
7
|
/**
|
|
4
8
|
* La huella que SÍ se le enseña a una persona: `AB12-CD34`. Corta, comparable de un vistazo
|
|
5
9
|
* y la misma en todo el ecosistema (emparejamiento, acta, lista de dispositivos).
|
|
10
|
+
*
|
|
11
|
+
* @param {string | JsonWebKey | null | undefined} publicJwkStr
|
|
12
|
+
* @returns {Promise<string>}
|
|
6
13
|
*/
|
|
7
|
-
export function keyLabel(publicJwkStr:
|
|
14
|
+
export function keyLabel(publicJwkStr: string | JsonWebKey | null | undefined): Promise<string>;
|
|
8
15
|
declare namespace _default {
|
|
9
16
|
export { pubkeyId };
|
|
10
17
|
export { keyLabel };
|
package/types/machine.d.ts
CHANGED
|
@@ -9,7 +9,11 @@ export function cleanMachine(raw: any): {
|
|
|
9
9
|
os: string;
|
|
10
10
|
name: string;
|
|
11
11
|
} | null;
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Una línea para enseñarlo: `node · Linux 7.0.0 · mi-pc`. Vacía si no hay nada.
|
|
14
|
+
* @param {any} m
|
|
15
|
+
* @returns {string}
|
|
16
|
+
*/
|
|
13
17
|
export function machineLine(m: any): string;
|
|
14
18
|
/**
|
|
15
19
|
* La máquina de ESTE navegador. `env` se inyecta en las pruebas; en la página es `globalThis`.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** @param {PeerBackend | null | undefined} b */
|
|
2
|
+
export function useBackend(b: PeerBackend | null | undefined): void;
|
|
3
|
+
/**
|
|
4
|
+
* Registra el callback que marca el estado como "sucio" para el sync.
|
|
5
|
+
* @param {(() => void) | null} fn
|
|
6
|
+
*/
|
|
7
|
+
export function onDirty(fn: (() => void) | null): void;
|
|
8
|
+
/**
|
|
9
|
+
* Multi-perfil: namespacea el peer book por perfil. El core lo llama antes de initPeerStorage.
|
|
10
|
+
* @param {string | null | undefined} pid
|
|
11
|
+
* @param {{ volatile?: boolean }} [opts]
|
|
12
|
+
*/
|
|
13
|
+
export function setProfile(pid: string | null | undefined, { volatile: esVolatil }?: {
|
|
14
|
+
volatile?: boolean;
|
|
15
|
+
}): void;
|
|
16
|
+
/**
|
|
17
|
+
* Migración: copia el peer book VIEJO (pre-multi-perfil, sin namespace) al perfil `pid`.
|
|
18
|
+
* @param {string} pid
|
|
19
|
+
*/
|
|
20
|
+
export function adoptLegacy(pid: string): Promise<void>;
|
|
21
|
+
/** @returns {Promise<PeerBook>} */
|
|
22
|
+
export function initPeerStorage(): Promise<PeerBook>;
|
|
23
|
+
/**
|
|
24
|
+
* Promesa que resuelve cuando se completaron los write-through pendientes (tests).
|
|
25
|
+
* @returns {Promise<void>}
|
|
26
|
+
*/
|
|
27
|
+
export function flushPeers(): Promise<void>;
|
|
28
|
+
/** @returns {PeerBook} */
|
|
29
|
+
export function loadPeers(): PeerBook;
|
|
30
|
+
/** @param {PeerBook} peers */
|
|
31
|
+
export function savePeers(peers: PeerBook): void;
|
|
32
|
+
/**
|
|
33
|
+
* Escritura directa (merge del sync): persiste sin marcar dirty.
|
|
34
|
+
* @param {PeerBook} peers
|
|
35
|
+
*/
|
|
36
|
+
export function setPeersDirect(peers: PeerBook): void;
|
|
37
|
+
/**
|
|
38
|
+
* @param {string} publickey
|
|
39
|
+
* @param {Record<string, any>} patch
|
|
40
|
+
* @returns {PeerRecord}
|
|
41
|
+
*/
|
|
42
|
+
export function upsertPeer(publickey: string, patch: Record<string, any>): PeerRecord;
|
|
43
|
+
export function _resetForTest(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Almacén del peer book del vault (nicknames + ratings + endorsements firmados).
|
|
46
|
+
*
|
|
47
|
+
* Migrado de localStorage (~5 MB de techo, compartido) a IndexedDB (cuota grande,
|
|
48
|
+
* non-evictable con `persist()`), porque el peer book crece con los contactos y,
|
|
49
|
+
* sobre todo, con los endorsements del registro de reputación. Patrón idéntico
|
|
50
|
+
* al del store del ecosistema:
|
|
51
|
+
* - `_peers` en memoria es la fuente de verdad en runtime.
|
|
52
|
+
* - `loadPeers()` es SÍNCRONA (lee la cache) → los handlers del vault no cambian.
|
|
53
|
+
* - `initPeerStorage()` (async, en el bootstrap) la rellena desde IndexedDB,
|
|
54
|
+
* MIGRANDO una sola vez del localStorage viejo. Si IndexedDB no está (modo
|
|
55
|
+
* privado) cae a localStorage para no perder función.
|
|
56
|
+
* - `savePeers()` actualiza la cache y hace write-through async a IndexedDB.
|
|
57
|
+
*
|
|
58
|
+
* El módulo es independiente del resto del vault (testeable en aislamiento).
|
|
59
|
+
*/
|
|
60
|
+
export const PEERS_STORAGE: "dotrino.identity.peers";
|
|
61
|
+
/**
|
|
62
|
+
* La ficha de un contacto: `publickey` y lo que sus pantallas apunten (apodo, avatar, fechas).
|
|
63
|
+
*/
|
|
64
|
+
export type PeerRecord = {
|
|
65
|
+
publickey: string;
|
|
66
|
+
firstSeen?: number;
|
|
67
|
+
lastSeen?: number;
|
|
68
|
+
changedAt?: number;
|
|
69
|
+
} & Record<string, any>;
|
|
70
|
+
/**
|
|
71
|
+
* El libro de contactos: pubkey → ficha.
|
|
72
|
+
*/
|
|
73
|
+
export type PeerBook = Record<string, PeerRecord>;
|
|
74
|
+
/**
|
|
75
|
+
* Dónde guarda la app el libro (el almacén de la app nativa).
|
|
76
|
+
*/
|
|
77
|
+
export type PeerBackend = {
|
|
78
|
+
get(key: string): Promise<any>;
|
|
79
|
+
put(key: string, val: any): Promise<void>;
|
|
80
|
+
};
|
package/types/peerSync.d.ts
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* La última vez que la ficha cambió: la vio (`lastSeen`) o la tocaste (`changedAt`).
|
|
3
|
+
* @param {{ lastSeen?: unknown, changedAt?: unknown } | null | undefined} rec
|
|
4
|
+
* @returns {number}
|
|
5
|
+
*/
|
|
6
|
+
export function stampOf(rec: {
|
|
7
|
+
lastSeen?: unknown;
|
|
8
|
+
changedAt?: unknown;
|
|
9
|
+
} | null | undefined): number;
|
|
10
|
+
/**
|
|
11
|
+
* El id de la entrada: de su llave, estable y sin comillas (sha-256, 32 hex).
|
|
12
|
+
* @param {unknown} publickey
|
|
13
|
+
* @returns {Promise<string>}
|
|
14
|
+
*/
|
|
15
|
+
export function peerIdOf(publickey: unknown): Promise<string>;
|
|
5
16
|
/**
|
|
6
17
|
* Reconciliar el libro con la bóveda. `peers` es el libro de aquí (`{ publickey: ficha }`),
|
|
7
18
|
* `call(method, args)` habla con el almacén de la bóveda. Devuelve las fichas que llegaron (para
|
|
8
19
|
* fundirlas aquí) y cuántas subieron.
|
|
20
|
+
*
|
|
21
|
+
* @param {{ peers: Record<string, any> | null | undefined, call: (method: string, args: any) => Promise<any> }} args
|
|
22
|
+
* @returns {Promise<{ incoming: any[], pushed: number }>}
|
|
9
23
|
*/
|
|
10
24
|
export function syncPeers({ peers, call }: {
|
|
11
|
-
peers: any;
|
|
12
|
-
call: any
|
|
25
|
+
peers: Record<string, any> | null | undefined;
|
|
26
|
+
call: (method: string, args: any) => Promise<any>;
|
|
13
27
|
}): Promise<{
|
|
14
28
|
incoming: any[];
|
|
15
29
|
pushed: number;
|
package/types/remote.d.ts
CHANGED
|
@@ -1,44 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Un aparato enrolado: su llave (en JWK, CryptoKey o un firmador externo) y su máquina.
|
|
3
|
+
* @typedef {{ publickey: string, privateJwk?: JsonWebKey, privateKey?: import('./capabilities.js').SigningKey | null,
|
|
4
|
+
* sign?: (text: string) => Promise<string>, machine?: any, label?: string, deviceId?: string }} DeviceKey
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Lo que se usa del cliente del proxio (`@dotrino/proxy-client`), o del local que imita su forma.
|
|
8
|
+
* @typedef {{ local?: boolean, token?: string | null,
|
|
9
|
+
* on (event: string, fn: (from: string, payload: any, meta?: any) => void): () => unknown,
|
|
10
|
+
* send? (to: string, payload: any): void,
|
|
11
|
+
* sendByPubkey (to: string | string[], payload: any, opts?: any): void,
|
|
12
|
+
* identify? (envelope: { data: any, signature: string, cert?: any, acta?: any }): Promise<any>,
|
|
13
|
+
* connect? (): Promise<unknown>, identifyAs? (args: any): Promise<unknown>,
|
|
14
|
+
* redeemPairingCode? (code: string): Promise<any>,
|
|
15
|
+
* close (): void }} VaultClient
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Con qué se habla con la bóveda emparejada.
|
|
19
|
+
* @typedef {{ master: string, proxy: string, device: DeviceKey, cert: any, acta?: any,
|
|
20
|
+
* onRevoked?: (() => void) | null, timeoutMs?: number, to?: string | null }} PairingContext
|
|
21
|
+
*/
|
|
1
22
|
/**
|
|
2
23
|
* ¿Es AUTÉNTICO este `vault.revoked`? Solo lo es si va firmado por la maestra PINEADA al
|
|
3
24
|
* emparejar, es para ESTE dispositivo y no ha caducado. Es la única puerta al autoborrado:
|
|
4
25
|
* un `vault.error` con la palabra «revocado» no borra nada (cierra el wipe-DoS, ver
|
|
5
26
|
* `dotrino-vault/docs/pairing-protocol.md §2.3`).
|
|
27
|
+
* @param {{ body: any, signature: unknown, master: string, devicePubkey: string, currentNonce?: string | null }} args
|
|
28
|
+
* @returns {Promise<boolean>}
|
|
6
29
|
*/
|
|
7
30
|
export function isAuthenticRevoke({ body, signature, master, devicePubkey, currentNonce }: {
|
|
8
31
|
body: any;
|
|
9
|
-
signature:
|
|
10
|
-
master:
|
|
11
|
-
devicePubkey:
|
|
12
|
-
currentNonce?:
|
|
32
|
+
signature: unknown;
|
|
33
|
+
master: string;
|
|
34
|
+
devicePubkey: string;
|
|
35
|
+
currentNonce?: string | null;
|
|
13
36
|
}): Promise<boolean>;
|
|
14
37
|
/**
|
|
15
38
|
* @param {Object} opts
|
|
16
|
-
* @param {{v
|
|
39
|
+
* @param {{v?:number, iss?:string, proxy?:string, token?:string, sn:string, conn?:string, acct?:string, m?:any}} opts.qr QR v2 del vault.
|
|
17
40
|
* @param {(c:{deviceId:string, code:string})=>void} [opts.onChallenge] Para mostrar el código a tipear en el PC.
|
|
18
|
-
* @param {string[]} [opts.requireCaps] permisos del acta sin los que este aparato no entra (`sealer`
|
|
41
|
+
* @param {string[] | null} [opts.requireCaps] permisos del acta sin los que este aparato no entra (`sealer`
|
|
19
42
|
* para una bóveda): si la invitación no los da, se para antes del código (`missing-caps`).
|
|
20
43
|
* @param {string} [opts.label]
|
|
21
44
|
* @param {number} [opts.approveTimeoutMs] Espera de la aprobación humana (def 3 min).
|
|
22
|
-
* @param {string} [opts.account] si viene (`pubkeyId` del perfil, 64 hex), SOLO entra en esa cuenta:
|
|
45
|
+
* @param {string | null} [opts.account] si viene (`pubkeyId` del perfil, 64 hex), SOLO entra en esa cuenta:
|
|
23
46
|
* se comprueba al llegar el reto, antes de enseñar el código (`wrong-account`).
|
|
24
|
-
* @
|
|
47
|
+
* @param {any} [opts.device]
|
|
48
|
+
* @param {any} [opts.continuity]
|
|
49
|
+
* @param {string | null} [opts.encPub]
|
|
50
|
+
* @param {string} [opts.intent]
|
|
51
|
+
* @param {string | null} [opts.profileId]
|
|
52
|
+
* @param {((m: { pub: string, encPub: string | null, label: string }) => any) | null} [opts.onAdopt]
|
|
53
|
+
* @param {any} [opts.machine]
|
|
54
|
+
* @returns {Promise<{device: any, cert: any, master:string, proxy:string, deviceId:string, account:string, acta?: any, adopted?: boolean}>}
|
|
25
55
|
*/
|
|
26
56
|
export function enrollDevice({ qr, device, onChallenge, label, continuity, encPub, approveTimeoutMs, intent, profileId, onAdopt, machine, account, requireCaps }?: {
|
|
27
57
|
qr: {
|
|
28
|
-
v
|
|
29
|
-
iss
|
|
30
|
-
proxy
|
|
31
|
-
token
|
|
58
|
+
v?: number;
|
|
59
|
+
iss?: string;
|
|
60
|
+
proxy?: string;
|
|
61
|
+
token?: string;
|
|
32
62
|
sn: string;
|
|
63
|
+
conn?: string;
|
|
64
|
+
acct?: string;
|
|
65
|
+
m?: any;
|
|
33
66
|
};
|
|
34
67
|
onChallenge?: (c: {
|
|
35
68
|
deviceId: string;
|
|
36
69
|
code: string;
|
|
37
70
|
}) => void;
|
|
38
|
-
requireCaps?: string[];
|
|
71
|
+
requireCaps?: string[] | null;
|
|
39
72
|
label?: string;
|
|
40
73
|
approveTimeoutMs?: number;
|
|
41
|
-
account?: string;
|
|
74
|
+
account?: string | null;
|
|
75
|
+
device?: any;
|
|
76
|
+
continuity?: any;
|
|
77
|
+
encPub?: string | null;
|
|
78
|
+
intent?: string;
|
|
79
|
+
profileId?: string | null;
|
|
80
|
+
onAdopt?: ((m: {
|
|
81
|
+
pub: string;
|
|
82
|
+
encPub: string | null;
|
|
83
|
+
label: string;
|
|
84
|
+
}) => any) | null;
|
|
85
|
+
machine?: any;
|
|
42
86
|
}): Promise<{
|
|
43
87
|
device: any;
|
|
44
88
|
cert: any;
|
|
@@ -46,21 +90,31 @@ export function enrollDevice({ qr, device, onChallenge, label, continuity, encPu
|
|
|
46
90
|
proxy: string;
|
|
47
91
|
deviceId: string;
|
|
48
92
|
account: string;
|
|
93
|
+
acta?: any;
|
|
94
|
+
adopted?: boolean;
|
|
49
95
|
}>;
|
|
50
96
|
/**
|
|
51
97
|
* Pide a la MAESTRA (en el vault del PC) que firme `payload`, adjuntando el cert de
|
|
52
98
|
* delegación de este dispositivo. La maestra nunca sale del vault: vuelve solo la
|
|
53
99
|
* firma. Requiere que el vault esté online.
|
|
100
|
+
* @param {PairingContext & { payload: any }} args
|
|
54
101
|
* @returns {Promise<{ signature:string, publickey:string }>} publickey = la maestra.
|
|
55
102
|
*/
|
|
56
|
-
export function requestSign({ master, proxy, device, cert, acta, payload, onRevoked, timeoutMs }?: {
|
|
57
|
-
|
|
58
|
-
timeoutMs?: number;
|
|
103
|
+
export function requestSign({ master, proxy, device, cert, acta, payload, onRevoked, timeoutMs }?: PairingContext & {
|
|
104
|
+
payload: any;
|
|
59
105
|
}): Promise<{
|
|
60
106
|
signature: string;
|
|
61
107
|
publickey: string;
|
|
62
108
|
}>;
|
|
63
|
-
|
|
109
|
+
/**
|
|
110
|
+
* @param {string} master
|
|
111
|
+
* @param {(onReply: (reply: any) => void) => { send (payload: any): void, close (): void }} open
|
|
112
|
+
* @returns {() => void}
|
|
113
|
+
*/
|
|
114
|
+
export function registerLocalVault(master: string, open: (onReply: (reply: any) => void) => {
|
|
115
|
+
send(payload: any): void;
|
|
116
|
+
close(): void;
|
|
117
|
+
}): () => void;
|
|
64
118
|
/**
|
|
65
119
|
* PREGUNTA SIN CERTIFICADO: «¿sigo estando en el acta?».
|
|
66
120
|
*
|
|
@@ -72,20 +126,39 @@ export function registerLocalVault(master: any, open: any): () => void;
|
|
|
72
126
|
* La bóveda contesta sí o no, y nada más. Si el no viene acompañado del aviso FIRMADO de
|
|
73
127
|
* expulsión, ESE es el que borra la cuenta aquí (`onRevoked`); el «no» pelado no borra
|
|
74
128
|
* nada, como cualquier otro mensaje sin firma.
|
|
129
|
+
* @param {{ master: string, proxy: string, device: DeviceKey, acta?: any, onRevoked?: (() => void) | null, timeoutMs?: number }} args
|
|
130
|
+
* @returns {Promise<{ in?: boolean, wiped?: boolean, error?: string, code?: string }>}
|
|
75
131
|
*/
|
|
76
132
|
export function checkMembership({ master, proxy, device, acta, onRevoked, timeoutMs }?: {
|
|
133
|
+
master: string;
|
|
134
|
+
proxy: string;
|
|
135
|
+
device: DeviceKey;
|
|
77
136
|
acta?: any;
|
|
137
|
+
onRevoked?: (() => void) | null;
|
|
78
138
|
timeoutMs?: number;
|
|
79
|
-
}): Promise<
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
139
|
+
}): Promise<{
|
|
140
|
+
in?: boolean;
|
|
141
|
+
wiped?: boolean;
|
|
142
|
+
error?: string;
|
|
143
|
+
code?: string;
|
|
144
|
+
}>;
|
|
145
|
+
/**
|
|
146
|
+
* Lee/escribe el store de hilos+aperturas EN el vault (con el cert del dispositivo).
|
|
147
|
+
* @param {PairingContext & { method: string, args?: any, enc?: any, wake?: boolean }} args
|
|
148
|
+
* @returns {Promise<any>}
|
|
149
|
+
*/
|
|
150
|
+
export function requestStore({ master, proxy, device, cert, acta, method, args, enc, onRevoked, wake }?: PairingContext & {
|
|
151
|
+
method: string;
|
|
152
|
+
args?: any;
|
|
153
|
+
enc?: any;
|
|
83
154
|
wake?: boolean;
|
|
84
155
|
}): Promise<any>;
|
|
85
|
-
/**
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
156
|
+
/**
|
|
157
|
+
* Lista (solo lectura) los dispositivos enrolados en tu vault.
|
|
158
|
+
* @param {PairingContext & { sinceSeq?: number }} args
|
|
159
|
+
*/
|
|
160
|
+
export function requestDevices({ master, to, timeoutMs, proxy, device, cert, acta, sinceSeq, onRevoked }?: PairingContext & {
|
|
161
|
+
sinceSeq?: number;
|
|
89
162
|
}): Promise<{
|
|
90
163
|
devices: any;
|
|
91
164
|
siblingCerts: any;
|
|
@@ -97,12 +170,12 @@ export function requestDevices({ master, to, timeoutMs, proxy, device, cert, act
|
|
|
97
170
|
/**
|
|
98
171
|
* RENUEVA el cert de este dispositivo (requiere el cert aún VIGENTE y no revocado):
|
|
99
172
|
* el vault firma uno fresco para la misma sub-clave y scope, sin QR ni aprobación.
|
|
100
|
-
* @
|
|
173
|
+
* @param {PairingContext} args
|
|
174
|
+
* @returns {Promise<{ cert: any, acta: any }>}
|
|
101
175
|
*/
|
|
102
|
-
export function requestRenew({ master, proxy, device, cert, acta, onRevoked }?: {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
cert: object;
|
|
176
|
+
export function requestRenew({ master, proxy, device, cert, acta, onRevoked }?: PairingContext): Promise<{
|
|
177
|
+
cert: any;
|
|
178
|
+
acta: any;
|
|
106
179
|
}>;
|
|
107
180
|
/**
|
|
108
181
|
* Manda a la bóveda la RENUNCIA de este dispositivo para que la selle en el acta.
|
|
@@ -115,12 +188,14 @@ export function requestRenew({ master, proxy, device, cert, acta, onRevoked }?:
|
|
|
115
188
|
*
|
|
116
189
|
* El `record` va FIRMADO por el propio miembro y solo puede QUITAR, así que la bóveda no
|
|
117
190
|
* necesita comprobar ningún certificado para honrarlo: le basta la firma.
|
|
191
|
+
* @param {PairingContext & { record: any }} args
|
|
192
|
+
* @returns {Promise<{ ok: boolean, seq: number | null }>}
|
|
118
193
|
*/
|
|
119
|
-
export function requestRenounce({ master, proxy, device, cert, acta, record, onRevoked }?: {
|
|
120
|
-
|
|
194
|
+
export function requestRenounce({ master, proxy, device, cert, acta, record, onRevoked }?: PairingContext & {
|
|
195
|
+
record: any;
|
|
121
196
|
}): Promise<{
|
|
122
197
|
ok: boolean;
|
|
123
|
-
seq:
|
|
198
|
+
seq: number | null;
|
|
124
199
|
}>;
|
|
125
200
|
/**
|
|
126
201
|
* CONSOLA REMOTA (`dotrino-vault/docs/consola-remota.md`): administrar el perfil desde
|
|
@@ -133,31 +208,84 @@ export function requestRenounce({ master, proxy, device, cert, acta, record, onR
|
|
|
133
208
|
*
|
|
134
209
|
* El `nonce` de un solo uso va en cada petición porque `approve` y `revoke` cambian
|
|
135
210
|
* estado, y para eso la ventana de frescura de ±5 min no alcanza.
|
|
211
|
+
* @param {PairingContext & { op: string, nonce?: string } & Record<string, any>} args
|
|
212
|
+
* @returns {Promise<any>}
|
|
136
213
|
*/
|
|
137
|
-
export function requestAdmin({ master, to, timeoutMs, proxy, device, cert, acta, op, onRevoked, nonce: dado, ...rest }?: {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}): Promise<any>;
|
|
214
|
+
export function requestAdmin({ master, to, timeoutMs, proxy, device, cert, acta, op, onRevoked, nonce: dado, ...rest }?: PairingContext & {
|
|
215
|
+
op: string;
|
|
216
|
+
nonce?: string;
|
|
217
|
+
} & Record<string, any>): Promise<any>;
|
|
141
218
|
/**
|
|
142
219
|
* PEDIDOS DE APROBACIÓN (cajones con `approval`): `approvals` (listar) · `approve` ·
|
|
143
220
|
* `deny`. Van por `vault.secrets`, firmados por un aparato cuyo cert lleve
|
|
144
221
|
* `vault:approve` — que, como `admin`, no se recibe al emparejar: se concede a mano.
|
|
145
222
|
* La bóveda contesta un cuerpo firmado por la maestra (`{ op, items | ok }`).
|
|
223
|
+
* @param {PairingContext & { op: string, id?: string, notify?: boolean }} args
|
|
224
|
+
* @returns {Promise<any>}
|
|
146
225
|
*/
|
|
147
|
-
export function requestApproval({ master, proxy, device, cert, acta, op, id, notify, onRevoked }?: {
|
|
148
|
-
|
|
226
|
+
export function requestApproval({ master, proxy, device, cert, acta, op, id, notify, onRevoked }?: PairingContext & {
|
|
227
|
+
op: string;
|
|
228
|
+
id?: string;
|
|
229
|
+
notify?: boolean;
|
|
149
230
|
}): Promise<any>;
|
|
150
231
|
/**
|
|
151
232
|
* ¿Es AUTÉNTICO este `vault.admin.event` (entró o salió alguien del perfil)? Solo si va
|
|
152
233
|
* firmado por la maestra PINEADA. Un aviso sin firma no se muestra: si no, cualquiera
|
|
153
234
|
* podría llenar de alarmas falsas los dispositivos del usuario.
|
|
235
|
+
* @param {{ body: any, signature: unknown, master: string }} args
|
|
236
|
+
* @returns {Promise<boolean>}
|
|
154
237
|
*/
|
|
155
238
|
export function isAuthenticAdminEvent({ body, signature, master }: {
|
|
156
239
|
body: any;
|
|
157
|
-
signature:
|
|
158
|
-
master:
|
|
240
|
+
signature: unknown;
|
|
241
|
+
master: string;
|
|
159
242
|
}): Promise<boolean>;
|
|
160
243
|
export { MSG as VAULT_MSG };
|
|
244
|
+
/**
|
|
245
|
+
* Un aparato enrolado: su llave (en JWK, CryptoKey o un firmador externo) y su máquina.
|
|
246
|
+
*/
|
|
247
|
+
export type DeviceKey = {
|
|
248
|
+
publickey: string;
|
|
249
|
+
privateJwk?: JsonWebKey;
|
|
250
|
+
privateKey?: import("./capabilities.js").SigningKey | null;
|
|
251
|
+
sign?: (text: string) => Promise<string>;
|
|
252
|
+
machine?: any;
|
|
253
|
+
label?: string;
|
|
254
|
+
deviceId?: string;
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* Lo que se usa del cliente del proxio (`@dotrino/proxy-client`), o del local que imita su forma.
|
|
258
|
+
*/
|
|
259
|
+
export type VaultClient = {
|
|
260
|
+
local?: boolean;
|
|
261
|
+
token?: string | null;
|
|
262
|
+
on(event: string, fn: (from: string, payload: any, meta?: any) => void): () => unknown;
|
|
263
|
+
send?(to: string, payload: any): void;
|
|
264
|
+
sendByPubkey(to: string | string[], payload: any, opts?: any): void;
|
|
265
|
+
identify?(envelope: {
|
|
266
|
+
data: any;
|
|
267
|
+
signature: string;
|
|
268
|
+
cert?: any;
|
|
269
|
+
acta?: any;
|
|
270
|
+
}): Promise<any>;
|
|
271
|
+
connect?(): Promise<unknown>;
|
|
272
|
+
identifyAs?(args: any): Promise<unknown>;
|
|
273
|
+
redeemPairingCode?(code: string): Promise<any>;
|
|
274
|
+
close(): void;
|
|
275
|
+
};
|
|
276
|
+
/**
|
|
277
|
+
* Con qué se habla con la bóveda emparejada.
|
|
278
|
+
*/
|
|
279
|
+
export type PairingContext = {
|
|
280
|
+
master: string;
|
|
281
|
+
proxy: string;
|
|
282
|
+
device: DeviceKey;
|
|
283
|
+
cert: any;
|
|
284
|
+
acta?: any;
|
|
285
|
+
onRevoked?: (() => void) | null;
|
|
286
|
+
timeoutMs?: number;
|
|
287
|
+
to?: string | null;
|
|
288
|
+
};
|
|
161
289
|
declare namespace MSG {
|
|
162
290
|
let HELLO: string;
|
|
163
291
|
let HELLO_OK: string;
|
package/types/session.d.ts
CHANGED
|
@@ -1,50 +1,61 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Normaliza los alcances pedidos: solo los del catálogo, sin repetidos y en orden estable.
|
|
3
|
+
* @param {unknown} scopes
|
|
4
|
+
* @returns {string[]}
|
|
5
|
+
*/
|
|
6
|
+
export function cleanSessionScopes(scopes: unknown): string[];
|
|
7
|
+
/**
|
|
8
|
+
* El cuerpo que firma el aparato que respalda. Un solo sitio: quien firma y quien verifica miran lo mismo.
|
|
9
|
+
* @param {{ sid: string, s: string, by: string, origin: string, scopes?: unknown, iat: number, exp: number }} args
|
|
10
|
+
*/
|
|
4
11
|
export function sessionBody({ sid, s, by, origin, scopes, iat, exp }: {
|
|
5
|
-
sid:
|
|
6
|
-
s:
|
|
7
|
-
by:
|
|
8
|
-
origin:
|
|
9
|
-
scopes
|
|
10
|
-
iat:
|
|
11
|
-
exp:
|
|
12
|
+
sid: string;
|
|
13
|
+
s: string;
|
|
14
|
+
by: string;
|
|
15
|
+
origin: string;
|
|
16
|
+
scopes?: unknown;
|
|
17
|
+
iat: number;
|
|
18
|
+
exp: number;
|
|
12
19
|
}): {
|
|
13
20
|
v: number;
|
|
14
21
|
op: string;
|
|
15
|
-
sid:
|
|
16
|
-
s:
|
|
17
|
-
by:
|
|
18
|
-
origin:
|
|
19
|
-
scopes:
|
|
20
|
-
iat:
|
|
21
|
-
exp:
|
|
22
|
+
sid: string;
|
|
23
|
+
s: string;
|
|
24
|
+
by: string;
|
|
25
|
+
origin: string;
|
|
26
|
+
scopes: string[];
|
|
27
|
+
iat: number;
|
|
28
|
+
exp: number;
|
|
22
29
|
};
|
|
23
30
|
/**
|
|
24
31
|
* Firma un papel de sesión. Lo llama el APARATO que respalda, con su propia llave.
|
|
25
32
|
*
|
|
26
33
|
* `sign` recibe el cuerpo y devuelve la firma (o el paquete del vault). No se le pasa la
|
|
27
34
|
* privada: este módulo no toca llaves.
|
|
35
|
+
* @param {{ sid: string, s: string, by: string, origin: string, scopes?: unknown, ttlMs?: number, now?: number }} args
|
|
36
|
+
* @param {(body: object) => Promise<string | { signature?: string }>} sign
|
|
28
37
|
*/
|
|
29
38
|
export function signSession({ sid, s, by, origin, scopes, ttlMs, now }: {
|
|
30
|
-
sid:
|
|
31
|
-
s:
|
|
32
|
-
by:
|
|
33
|
-
origin:
|
|
34
|
-
scopes
|
|
35
|
-
ttlMs
|
|
39
|
+
sid: string;
|
|
40
|
+
s: string;
|
|
41
|
+
by: string;
|
|
42
|
+
origin: string;
|
|
43
|
+
scopes?: unknown;
|
|
44
|
+
ttlMs?: number;
|
|
36
45
|
now?: number;
|
|
37
|
-
}, sign:
|
|
38
|
-
|
|
46
|
+
}, sign: (body: object) => Promise<string | {
|
|
47
|
+
signature?: string;
|
|
48
|
+
}>): Promise<{
|
|
49
|
+
sig: string;
|
|
39
50
|
v: number;
|
|
40
51
|
op: string;
|
|
41
|
-
sid:
|
|
42
|
-
s:
|
|
43
|
-
by:
|
|
44
|
-
origin:
|
|
45
|
-
scopes:
|
|
46
|
-
iat:
|
|
47
|
-
exp:
|
|
52
|
+
sid: string;
|
|
53
|
+
s: string;
|
|
54
|
+
by: string;
|
|
55
|
+
origin: string;
|
|
56
|
+
scopes: string[];
|
|
57
|
+
iat: number;
|
|
58
|
+
exp: number;
|
|
48
59
|
}>;
|
|
49
60
|
/**
|
|
50
61
|
* ¿Vale este papel de sesión, AHORA?
|
|
@@ -53,74 +64,56 @@ export function signSession({ sid, s, by, origin, scopes, ttlMs, now }: {
|
|
|
53
64
|
* el aparato que respalda sigue siendo de la casa —que es lo que hace que quitar un aparato
|
|
54
65
|
* se lleve por delante sus sesiones—. Devuelve `{ ok, profileId, scopes, sid, exp }` o
|
|
55
66
|
* `{ ok:false, reason }`.
|
|
67
|
+
* @param {any} paper
|
|
68
|
+
* @param {{ chain?: any, expectedProfileId?: string | null, origin?: string | null, now?: number, maxSkewMs?: number }} [opts]
|
|
69
|
+
* @returns {Promise<{ ok: false, reason: string } | { ok: true, profileId: string, seq: number, sid: string, s: string, by: string, origin: string, scopes: string[], exp: number }>}
|
|
56
70
|
*/
|
|
57
71
|
export function verifySession(paper: any, { chain, expectedProfileId, origin, now, maxSkewMs }?: {
|
|
58
|
-
|
|
59
|
-
|
|
72
|
+
chain?: any;
|
|
73
|
+
expectedProfileId?: string | null;
|
|
74
|
+
origin?: string | null;
|
|
60
75
|
now?: number;
|
|
61
76
|
maxSkewMs?: number;
|
|
62
77
|
}): Promise<{
|
|
63
|
-
ok:
|
|
78
|
+
ok: false;
|
|
64
79
|
reason: string;
|
|
65
|
-
profileId?: undefined;
|
|
66
|
-
seq?: undefined;
|
|
67
|
-
sid?: undefined;
|
|
68
|
-
s?: undefined;
|
|
69
|
-
by?: undefined;
|
|
70
|
-
origin?: undefined;
|
|
71
|
-
scopes?: undefined;
|
|
72
|
-
exp?: undefined;
|
|
73
80
|
} | {
|
|
74
|
-
ok:
|
|
75
|
-
profileId:
|
|
76
|
-
seq:
|
|
77
|
-
sid:
|
|
78
|
-
s:
|
|
79
|
-
by:
|
|
80
|
-
origin:
|
|
81
|
-
scopes:
|
|
82
|
-
exp:
|
|
83
|
-
reason?: undefined;
|
|
81
|
+
ok: true;
|
|
82
|
+
profileId: string;
|
|
83
|
+
seq: number;
|
|
84
|
+
sid: string;
|
|
85
|
+
s: string;
|
|
86
|
+
by: string;
|
|
87
|
+
origin: string;
|
|
88
|
+
scopes: string[];
|
|
89
|
+
exp: number;
|
|
84
90
|
}>;
|
|
85
91
|
/**
|
|
86
92
|
* ¿Firmó ESTA SESIÓN esto, y podía?
|
|
87
93
|
*
|
|
88
94
|
* Es lo que llama quien recibe algo de una sesión: comprueba la firma de la llave de
|
|
89
95
|
* sesión, el papel que la respalda y —si se pide— que el alcance cubra lo que se pretende.
|
|
96
|
+
* @param {{ data?: unknown, signature?: unknown, session?: any, chain?: any, scope?: string | null, origin?: string | null, expectedProfileId?: string | null, now?: number }} [args]
|
|
97
|
+
* @returns {Promise<{ ok: false, reason: string } | { ok: true, profileId: string, sid: string, scopes: string[], exp: number }>}
|
|
90
98
|
*/
|
|
91
99
|
export function verifySessionSigned({ data, signature, session, chain, scope, origin, expectedProfileId, now }?: {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
data?: unknown;
|
|
101
|
+
signature?: unknown;
|
|
102
|
+
session?: any;
|
|
103
|
+
chain?: any;
|
|
104
|
+
scope?: string | null;
|
|
105
|
+
origin?: string | null;
|
|
106
|
+
expectedProfileId?: string | null;
|
|
95
107
|
now?: number;
|
|
96
108
|
}): Promise<{
|
|
97
|
-
ok:
|
|
109
|
+
ok: false;
|
|
98
110
|
reason: string;
|
|
99
|
-
profileId?: undefined;
|
|
100
|
-
seq?: undefined;
|
|
101
|
-
sid?: undefined;
|
|
102
|
-
s?: undefined;
|
|
103
|
-
by?: undefined;
|
|
104
|
-
origin?: undefined;
|
|
105
|
-
scopes?: undefined;
|
|
106
|
-
exp?: undefined;
|
|
107
|
-
} | {
|
|
108
|
-
ok: boolean;
|
|
109
|
-
profileId: any;
|
|
110
|
-
seq: any;
|
|
111
|
-
sid: any;
|
|
112
|
-
s: any;
|
|
113
|
-
by: any;
|
|
114
|
-
origin: any;
|
|
115
|
-
scopes: any[];
|
|
116
|
-
exp: any;
|
|
117
|
-
reason?: undefined;
|
|
118
111
|
} | {
|
|
119
|
-
ok:
|
|
120
|
-
profileId:
|
|
121
|
-
sid:
|
|
122
|
-
scopes:
|
|
123
|
-
exp:
|
|
112
|
+
ok: true;
|
|
113
|
+
profileId: string;
|
|
114
|
+
sid: string;
|
|
115
|
+
scopes: string[];
|
|
116
|
+
exp: number;
|
|
124
117
|
}>;
|
|
125
118
|
export const SESSION_V: 1;
|
|
126
119
|
/** Cuánto dura una sesión. Horas, no meses: es un rato en un aparato que no es tuyo. */
|