@merklevault/core 0.1.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 +256 -0
- package/dist/index.cjs +2065 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +303 -0
- package/dist/index.d.ts +303 -0
- package/dist/index.js +2028 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @merklevault/core — Types publics du SDK
|
|
5
|
+
*
|
|
6
|
+
* Ces types constituent l'API publique du SDK.
|
|
7
|
+
* Toute modification est un breaking change.
|
|
8
|
+
*/
|
|
9
|
+
interface MerkleVaultOptions {
|
|
10
|
+
/** Chemin vers le dossier de donnees du vault */
|
|
11
|
+
dataDir: string;
|
|
12
|
+
/** Chemin vers le binaire Kubo/IPFS (optionnel, auto-detecte sinon) */
|
|
13
|
+
kuboBinaryPath?: string;
|
|
14
|
+
/** Port de l'API Kubo (defaut: 5101) */
|
|
15
|
+
kuboApiPort?: number;
|
|
16
|
+
/** Delai d'auto-lock en millisecondes (defaut: 15 min = 900000) */
|
|
17
|
+
autoLockMs?: number;
|
|
18
|
+
/** Desactiver l'auto-lock (defaut: false) */
|
|
19
|
+
disableAutoLock?: boolean;
|
|
20
|
+
}
|
|
21
|
+
interface FileNode {
|
|
22
|
+
id: number;
|
|
23
|
+
parentId: number | null;
|
|
24
|
+
name: string;
|
|
25
|
+
kind: 'file' | 'folder';
|
|
26
|
+
createdAt: number;
|
|
27
|
+
modifiedAt: number;
|
|
28
|
+
deletedAt: number | null;
|
|
29
|
+
currentVersionId: number | null;
|
|
30
|
+
}
|
|
31
|
+
interface FileVersion {
|
|
32
|
+
id: number;
|
|
33
|
+
nodeId: number;
|
|
34
|
+
cid: string;
|
|
35
|
+
sizeBytes: number;
|
|
36
|
+
sha256Plain: string | null;
|
|
37
|
+
createdAt: number;
|
|
38
|
+
encAlgo: string;
|
|
39
|
+
provider: 'local' | 'pinata';
|
|
40
|
+
pinataCid: string | null;
|
|
41
|
+
syncStatus: SyncStatusValue;
|
|
42
|
+
}
|
|
43
|
+
type SyncStatusValue = 'none' | 'pending' | 'syncing' | 'synced' | 'error';
|
|
44
|
+
interface VaultInfo {
|
|
45
|
+
initialized: boolean;
|
|
46
|
+
unlocked: boolean;
|
|
47
|
+
}
|
|
48
|
+
interface CreateVaultResult {
|
|
49
|
+
/** Phrase de recuperation BIP39 (24 mots) — a afficher UNE SEULE FOIS */
|
|
50
|
+
mnemonic: string;
|
|
51
|
+
}
|
|
52
|
+
type CloudProvider = 'local' | 'pinata';
|
|
53
|
+
interface PinataCredentials {
|
|
54
|
+
apiKey?: string;
|
|
55
|
+
secretApiKey?: string;
|
|
56
|
+
jwt?: string;
|
|
57
|
+
gateway?: string;
|
|
58
|
+
}
|
|
59
|
+
interface CloudConfig {
|
|
60
|
+
provider: CloudProvider;
|
|
61
|
+
active: boolean;
|
|
62
|
+
hasCredentials: boolean;
|
|
63
|
+
gateway: string | null;
|
|
64
|
+
}
|
|
65
|
+
interface SyncStatus {
|
|
66
|
+
total: number;
|
|
67
|
+
synced: number;
|
|
68
|
+
pending: number;
|
|
69
|
+
errors: number;
|
|
70
|
+
provider: CloudProvider;
|
|
71
|
+
}
|
|
72
|
+
interface AddFileResult {
|
|
73
|
+
node: FileNode;
|
|
74
|
+
version: FileVersion;
|
|
75
|
+
cid: string;
|
|
76
|
+
}
|
|
77
|
+
interface GetFileResult {
|
|
78
|
+
node: FileNode;
|
|
79
|
+
data: Buffer;
|
|
80
|
+
cid: string;
|
|
81
|
+
size: number;
|
|
82
|
+
}
|
|
83
|
+
interface FolderListing {
|
|
84
|
+
node: FileNode;
|
|
85
|
+
children: FileNode[];
|
|
86
|
+
}
|
|
87
|
+
interface DaemonStatus {
|
|
88
|
+
kuboReady: boolean;
|
|
89
|
+
kuboPid: number | null;
|
|
90
|
+
rootNode: FileNode;
|
|
91
|
+
ipfsOnline: boolean;
|
|
92
|
+
vaultInitialized: boolean;
|
|
93
|
+
vaultUnlocked: boolean;
|
|
94
|
+
cloudProvider: CloudProvider;
|
|
95
|
+
cloudActive: boolean;
|
|
96
|
+
}
|
|
97
|
+
type VaultEventType = 'vault:created' | 'vault:unlocked' | 'vault:locked' | 'file:added' | 'file:deleted' | 'file:renamed' | 'file:moved' | 'folder:created' | 'sync:started' | 'sync:progress' | 'sync:complete' | 'sync:error' | 'cloud:configured' | 'cloud:toggled' | 'kubo:ready' | 'kubo:crash' | 'error';
|
|
98
|
+
interface VaultEvent {
|
|
99
|
+
type: VaultEventType;
|
|
100
|
+
data?: any;
|
|
101
|
+
timestamp: number;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @merklevault/core — Classe facade principale
|
|
106
|
+
*
|
|
107
|
+
* Encapsule toute la logique metier de MerkleVault :
|
|
108
|
+
* - Gestion du vault (creation, deverrouillage, recovery)
|
|
109
|
+
* - CRUD fichiers/dossiers sur IPFS (Kubo)
|
|
110
|
+
* - Chiffrement E2E (XChaCha20-Poly1305 + Argon2id)
|
|
111
|
+
* - Synchronisation cloud (Pinata)
|
|
112
|
+
*
|
|
113
|
+
* Usage :
|
|
114
|
+
* import { MerkleVault } from '@merklevault/core';
|
|
115
|
+
* const vault = new MerkleVault({ dataDir: './my-vault' });
|
|
116
|
+
* await vault.start();
|
|
117
|
+
* await vault.create({ password: 'secret' });
|
|
118
|
+
* const file = await vault.addFile(buffer, { name: 'doc.pdf' });
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
declare class MerkleVault extends EventEmitter {
|
|
122
|
+
private opts;
|
|
123
|
+
private kubo;
|
|
124
|
+
private db;
|
|
125
|
+
private store;
|
|
126
|
+
private kuboStore;
|
|
127
|
+
private syncProcessor;
|
|
128
|
+
private masterKey;
|
|
129
|
+
private lockTimer;
|
|
130
|
+
private started;
|
|
131
|
+
constructor(options: MerkleVaultOptions);
|
|
132
|
+
/**
|
|
133
|
+
* Demarre le vault : initialise la DB, lance Kubo, restaure la config cloud.
|
|
134
|
+
* Doit etre appele avant toute autre operation.
|
|
135
|
+
*/
|
|
136
|
+
start(): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Arrete le vault proprement : ferme Kubo, la DB, le sync processor.
|
|
139
|
+
*/
|
|
140
|
+
stop(): Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* Verifie que le vault est demarre, sinon throw.
|
|
143
|
+
*/
|
|
144
|
+
private ensureStarted;
|
|
145
|
+
/**
|
|
146
|
+
* Verifie que le vault est deverrouille, sinon throw.
|
|
147
|
+
*/
|
|
148
|
+
private ensureUnlocked;
|
|
149
|
+
/**
|
|
150
|
+
* Cree un nouveau vault avec un mot de passe.
|
|
151
|
+
* Retourne la phrase de recuperation BIP39 (24 mots).
|
|
152
|
+
*
|
|
153
|
+
* @param password - Mot de passe maitre (min 8 caracteres)
|
|
154
|
+
* @returns Phrase de recuperation a afficher UNE SEULE FOIS
|
|
155
|
+
*/
|
|
156
|
+
create(password: string): Promise<CreateVaultResult>;
|
|
157
|
+
/**
|
|
158
|
+
* Deverrouille le vault avec le mot de passe.
|
|
159
|
+
*
|
|
160
|
+
* @param password - Mot de passe maitre
|
|
161
|
+
* @returns true si le deverrouillage a reussi
|
|
162
|
+
* @throws Si le mot de passe est invalide
|
|
163
|
+
*/
|
|
164
|
+
unlock(password: string): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Verrouille le vault — efface la master key de la memoire.
|
|
167
|
+
*/
|
|
168
|
+
lock(): void;
|
|
169
|
+
/**
|
|
170
|
+
* Recupere le vault via la phrase BIP39 et definit un nouveau mot de passe.
|
|
171
|
+
*
|
|
172
|
+
* @param mnemonic - Phrase de recuperation (24 mots)
|
|
173
|
+
* @param newPassword - Nouveau mot de passe
|
|
174
|
+
*/
|
|
175
|
+
recover(mnemonic: string, newPassword: string): Promise<boolean>;
|
|
176
|
+
/**
|
|
177
|
+
* Change le mot de passe du vault sans re-chiffrer les fichiers.
|
|
178
|
+
*
|
|
179
|
+
* @param oldPassword - Ancien mot de passe
|
|
180
|
+
* @param newPassword - Nouveau mot de passe
|
|
181
|
+
*/
|
|
182
|
+
changePassword(oldPassword: string, newPassword: string): Promise<boolean>;
|
|
183
|
+
/**
|
|
184
|
+
* Retourne l'etat du vault (initialise, deverrouille).
|
|
185
|
+
*/
|
|
186
|
+
getVaultInfo(): VaultInfo;
|
|
187
|
+
/**
|
|
188
|
+
* Verifie si le vault est deverrouille.
|
|
189
|
+
*/
|
|
190
|
+
isUnlocked(): boolean;
|
|
191
|
+
/**
|
|
192
|
+
* Ajoute un fichier au vault depuis un Buffer.
|
|
193
|
+
*
|
|
194
|
+
* @param data - Contenu du fichier
|
|
195
|
+
* @param options - Nom et dossier parent
|
|
196
|
+
* @returns Noeud cree, version et CID
|
|
197
|
+
*/
|
|
198
|
+
addFile(data: Buffer, options: {
|
|
199
|
+
name: string;
|
|
200
|
+
parentId?: number;
|
|
201
|
+
}): Promise<AddFileResult>;
|
|
202
|
+
/**
|
|
203
|
+
* Ajoute un fichier depuis un chemin sur le disque.
|
|
204
|
+
*
|
|
205
|
+
* @param filePath - Chemin absolu du fichier
|
|
206
|
+
* @param options - Nom (optionnel, deduit du path) et dossier parent
|
|
207
|
+
*/
|
|
208
|
+
addFileFromPath(filePath: string, options?: {
|
|
209
|
+
name?: string;
|
|
210
|
+
parentId?: number;
|
|
211
|
+
}): Promise<AddFileResult>;
|
|
212
|
+
/**
|
|
213
|
+
* Recupere le contenu dechiffre d'un fichier.
|
|
214
|
+
*
|
|
215
|
+
* @param nodeId - ID du noeud fichier
|
|
216
|
+
* @returns Contenu dechiffre + metadonnees
|
|
217
|
+
*/
|
|
218
|
+
getFile(nodeId: number): Promise<GetFileResult>;
|
|
219
|
+
/**
|
|
220
|
+
* Liste le contenu d'un dossier.
|
|
221
|
+
*
|
|
222
|
+
* @param parentId - ID du dossier (undefined = racine)
|
|
223
|
+
*/
|
|
224
|
+
listFolder(parentId?: number): FolderListing;
|
|
225
|
+
/**
|
|
226
|
+
* Recupere un noeud par son ID.
|
|
227
|
+
*/
|
|
228
|
+
getNode(nodeId: number): FileNode | null;
|
|
229
|
+
/**
|
|
230
|
+
* Recupere le chemin complet d'un noeud (fil d'ariane).
|
|
231
|
+
*/
|
|
232
|
+
getNodePath(nodeId: number): FileNode[];
|
|
233
|
+
/**
|
|
234
|
+
* Recupere le noeud racine.
|
|
235
|
+
*/
|
|
236
|
+
getRootNode(): FileNode;
|
|
237
|
+
/**
|
|
238
|
+
* Cree un nouveau dossier.
|
|
239
|
+
*
|
|
240
|
+
* @param name - Nom du dossier
|
|
241
|
+
* @param parentId - ID du dossier parent (defaut: racine)
|
|
242
|
+
*/
|
|
243
|
+
createFolder(name: string, parentId?: number): FileNode;
|
|
244
|
+
/**
|
|
245
|
+
* Renomme un noeud (fichier ou dossier).
|
|
246
|
+
*/
|
|
247
|
+
rename(nodeId: number, newName: string): void;
|
|
248
|
+
/**
|
|
249
|
+
* Deplace un noeud vers un autre dossier.
|
|
250
|
+
*/
|
|
251
|
+
move(nodeId: number, newParentId: number): void;
|
|
252
|
+
/**
|
|
253
|
+
* Supprime un noeud (soft delete → corbeille).
|
|
254
|
+
* Unpin de Pinata si le fichier y est synchronise.
|
|
255
|
+
*/
|
|
256
|
+
delete(nodeId: number): Promise<void>;
|
|
257
|
+
/**
|
|
258
|
+
* Restaure un noeud depuis la corbeille.
|
|
259
|
+
*/
|
|
260
|
+
restore(nodeId: number): void;
|
|
261
|
+
/**
|
|
262
|
+
* Liste les elements dans la corbeille.
|
|
263
|
+
*/
|
|
264
|
+
listTrash(): FileNode[];
|
|
265
|
+
/**
|
|
266
|
+
* Recupere l'historique des versions d'un fichier.
|
|
267
|
+
*/
|
|
268
|
+
getVersions(nodeId: number): FileVersion[];
|
|
269
|
+
/**
|
|
270
|
+
* Recherche dans le vault (FTS5).
|
|
271
|
+
*/
|
|
272
|
+
search(query: string): FileNode[];
|
|
273
|
+
/**
|
|
274
|
+
* Configure les credentials Pinata et teste la connexion.
|
|
275
|
+
*
|
|
276
|
+
* @param credentials - JWT ou apiKey + secretApiKey
|
|
277
|
+
* @returns true si la connexion a reussi
|
|
278
|
+
*/
|
|
279
|
+
configureCloud(credentials: PinataCredentials): Promise<boolean>;
|
|
280
|
+
/**
|
|
281
|
+
* Active ou desactive la synchronisation cloud.
|
|
282
|
+
*/
|
|
283
|
+
toggleCloud(enabled: boolean): CloudProvider;
|
|
284
|
+
/**
|
|
285
|
+
* Retourne la configuration cloud actuelle.
|
|
286
|
+
*/
|
|
287
|
+
getCloudConfig(): CloudConfig;
|
|
288
|
+
/**
|
|
289
|
+
* Retourne le statut de synchronisation.
|
|
290
|
+
*/
|
|
291
|
+
getSyncStatus(): SyncStatus;
|
|
292
|
+
/**
|
|
293
|
+
* Retourne le statut global du vault.
|
|
294
|
+
*/
|
|
295
|
+
getStatus(): Promise<DaemonStatus>;
|
|
296
|
+
private loadVaultConfig;
|
|
297
|
+
private saveVaultConfig;
|
|
298
|
+
private restoreCloudConfig;
|
|
299
|
+
private resetLockTimer;
|
|
300
|
+
private emitEvent;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export { type AddFileResult, type CloudConfig, type CloudProvider, type CreateVaultResult, type DaemonStatus, type FileNode, type FileVersion, type FolderListing, type GetFileResult, MerkleVault, type MerkleVaultOptions, type PinataCredentials, type SyncStatus, type SyncStatusValue, type VaultEvent, type VaultEventType, type VaultInfo };
|