@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/src/node.js
CHANGED
|
@@ -21,14 +21,24 @@ import os from 'node:os'
|
|
|
21
21
|
import { createIdentityCore } from '../vault/core.js'
|
|
22
22
|
import { IdentityFacade } from '../vault/facade.js'
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Cifrado en reposo del archivo de la identidad (lo pone quien hospeda, p. ej. la bóveda).
|
|
26
|
+
* @typedef {{ encrypt (text: string): string, decrypt (blob: string): string }} AtRest
|
|
27
|
+
*/
|
|
28
|
+
|
|
24
29
|
/**
|
|
25
30
|
* kv síncrono respaldado por un archivo JSON (estilo localStorage).
|
|
26
31
|
*
|
|
27
32
|
* `atRest` (opcional) cifra el archivo entero en disco: quien lo provee decide con qué
|
|
28
33
|
* (el vault lo liga a la máquina, ver `dotrino-vault/src/atrest.js`). Si el archivo estaba
|
|
29
34
|
* en claro se lee igual y queda cifrado en la primera escritura, sin pedir nada.
|
|
35
|
+
*
|
|
36
|
+
* @param {string} filePath
|
|
37
|
+
* @param {AtRest | null} [atRest]
|
|
38
|
+
* @returns {import('../vault/core.js').Kv}
|
|
30
39
|
*/
|
|
31
40
|
function fileKv (filePath, atRest = null) {
|
|
41
|
+
/** @type {Record<string, string>} */
|
|
32
42
|
let data = {}
|
|
33
43
|
try {
|
|
34
44
|
if (fs.existsSync(filePath)) {
|
|
@@ -48,10 +58,17 @@ function fileKv (filePath, atRest = null) {
|
|
|
48
58
|
}
|
|
49
59
|
}
|
|
50
60
|
|
|
51
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* Peer book respaldado por un archivo JSON (interfaz de vault/peerStore.js).
|
|
63
|
+
* @param {string} filePath
|
|
64
|
+
* @returns {import('../vault/core.js').CorePeers}
|
|
65
|
+
*/
|
|
52
66
|
function filePeers (filePath) {
|
|
67
|
+
/** @type {import('../vault/peerStore.js').PeerBook} */
|
|
53
68
|
let peers = {}
|
|
69
|
+
/** @type {(() => void) | null} */
|
|
54
70
|
let markDirty = null
|
|
71
|
+
/** @type {string | null} */
|
|
55
72
|
let pid = null // multi-perfil: el peer book se namespacea por perfil
|
|
56
73
|
const fileFor = () => pid ? path.join(path.dirname(filePath), `peers.${pid}.json`) : filePath
|
|
57
74
|
const flush = () => {
|
|
@@ -60,7 +77,9 @@ function filePeers (filePath) {
|
|
|
60
77
|
fs.writeFileSync(f, JSON.stringify(peers))
|
|
61
78
|
}
|
|
62
79
|
return {
|
|
80
|
+
/** @param {string | null} p */
|
|
63
81
|
setProfile (p) { pid = p || null },
|
|
82
|
+
/** @param {string} newPid */
|
|
64
83
|
adoptLegacy (newPid) {
|
|
65
84
|
// Migración: copia el peers.json viejo (sin namespace) al perfil newPid.
|
|
66
85
|
try {
|
|
@@ -79,16 +98,16 @@ function filePeers (filePath) {
|
|
|
79
98
|
return peers
|
|
80
99
|
},
|
|
81
100
|
loadPeers: () => peers,
|
|
82
|
-
savePeers: (next) => { peers = next; flush(); if (markDirty) markDirty() },
|
|
83
|
-
setPeersDirect: (next) => { peers = next; flush() },
|
|
84
|
-
upsertPeer: (publickey, patch) => {
|
|
101
|
+
savePeers: (/** @type {import('../vault/peerStore.js').PeerBook} */ next) => { peers = next; flush(); if (markDirty) markDirty() },
|
|
102
|
+
setPeersDirect: (/** @type {import('../vault/peerStore.js').PeerBook} */ next) => { peers = next; flush() },
|
|
103
|
+
upsertPeer: (/** @type {string} */ publickey, /** @type {Record<string, any>} */ patch) => {
|
|
85
104
|
const existing = peers[publickey] || { publickey, firstSeen: Date.now() }
|
|
86
105
|
peers[publickey] = { ...existing, ...patch, publickey, lastSeen: Date.now() }
|
|
87
106
|
flush()
|
|
88
107
|
if (markDirty) markDirty()
|
|
89
108
|
return peers[publickey]
|
|
90
109
|
},
|
|
91
|
-
onDirty: (fn) => { markDirty = fn }
|
|
110
|
+
onDirty: (/** @type {(() => void) | null} */ fn) => { markDirty = fn }
|
|
92
111
|
}
|
|
93
112
|
}
|
|
94
113
|
|
|
@@ -99,6 +118,8 @@ export class Identity extends IdentityFacade {
|
|
|
99
118
|
* @param {Object} [options]
|
|
100
119
|
* @param {string} [options.dir] Directorio de persistencia de esta identidad.
|
|
101
120
|
* Cada directorio = un usuario distinto. Default: ~/.dotrino/identity
|
|
121
|
+
* @param {AtRest | null} [options.atRest] cifrado en reposo del archivo de la identidad
|
|
122
|
+
* @param {import('../vault/core.js').KeyLock | null} [options.keyLock] candado de la maestra
|
|
102
123
|
*/
|
|
103
124
|
constructor (options = {}) {
|
|
104
125
|
super(null)
|
|
@@ -114,6 +135,9 @@ export class Identity extends IdentityFacade {
|
|
|
114
135
|
* Crea/abre una identidad headless. A diferencia del navegador NO es singleton:
|
|
115
136
|
* cada `dir` distinto devuelve una identidad independiente (para correr muchos
|
|
116
137
|
* bots-usuario en el mismo proceso).
|
|
138
|
+
*
|
|
139
|
+
* @param {{ dir?: string, atRest?: AtRest | null, keyLock?: import('../vault/core.js').KeyLock | null }} [options]
|
|
140
|
+
* @returns {Promise<Identity>}
|
|
117
141
|
*/
|
|
118
142
|
static async connect (options = {}) {
|
|
119
143
|
const inst = new Identity(options)
|