@bantis/local-cipher 1.0.1 → 2.0.1
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/LICENSE +1 -1
- package/README.md +225 -164
- package/dist/index.d.ts +479 -42
- package/dist/index.esm.js +1018 -133
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1028 -132
- package/dist/index.js.map +1 -1
- package/package.json +21 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,178 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Configuration types for @bantis/local-cipher
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Encryption configuration options
|
|
8
|
+
*/
|
|
9
|
+
interface EncryptionConfig {
|
|
10
|
+
/** Number of PBKDF2 iterations (default: 100000) */
|
|
11
|
+
iterations?: number;
|
|
12
|
+
/** Salt length in bytes (default: 16) */
|
|
13
|
+
saltLength?: number;
|
|
14
|
+
/** IV length in bytes (default: 12) */
|
|
15
|
+
ivLength?: number;
|
|
16
|
+
/** Custom app identifier for fingerprinting (default: 'bantis-local-cipher-v2') */
|
|
17
|
+
appIdentifier?: string;
|
|
18
|
+
/** AES key length in bits (default: 256) */
|
|
19
|
+
keyLength?: 128 | 192 | 256;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Storage configuration options
|
|
23
|
+
*/
|
|
24
|
+
interface StorageConfig {
|
|
25
|
+
/** Enable data compression (default: true for values > 1KB) */
|
|
26
|
+
compression?: boolean;
|
|
27
|
+
/** Compression threshold in bytes (default: 1024) */
|
|
28
|
+
compressionThreshold?: number;
|
|
29
|
+
/** Enable automatic cleanup of expired items (default: true) */
|
|
30
|
+
autoCleanup?: boolean;
|
|
31
|
+
/** Auto cleanup interval in ms (default: 60000 - 1 minute) */
|
|
32
|
+
cleanupInterval?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Debug configuration options
|
|
36
|
+
*/
|
|
37
|
+
interface DebugConfig {
|
|
38
|
+
/** Enable debug mode (default: false) */
|
|
39
|
+
enabled?: boolean;
|
|
40
|
+
/** Log level (default: 'info') */
|
|
41
|
+
logLevel?: LogLevel;
|
|
42
|
+
/** Custom log prefix (default: 'SecureStorage') */
|
|
43
|
+
prefix?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Log levels
|
|
47
|
+
*/
|
|
48
|
+
type LogLevel = 'silent' | 'error' | 'warn' | 'info' | 'debug' | 'verbose';
|
|
49
|
+
/**
|
|
50
|
+
* Complete configuration for SecureStorage
|
|
51
|
+
*/
|
|
52
|
+
interface SecureStorageConfig {
|
|
53
|
+
/** Encryption configuration */
|
|
54
|
+
encryption?: EncryptionConfig;
|
|
55
|
+
/** Storage configuration */
|
|
56
|
+
storage?: StorageConfig;
|
|
57
|
+
/** Debug configuration */
|
|
58
|
+
debug?: DebugConfig;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Stored value with metadata
|
|
62
|
+
*/
|
|
63
|
+
interface StoredValue {
|
|
64
|
+
/** Encrypted value */
|
|
65
|
+
value: string;
|
|
66
|
+
/** Expiration timestamp (ms since epoch) */
|
|
67
|
+
expiresAt?: number;
|
|
68
|
+
/** Creation timestamp (ms since epoch) */
|
|
69
|
+
createdAt: number;
|
|
70
|
+
/** Last modified timestamp (ms since epoch) */
|
|
71
|
+
modifiedAt: number;
|
|
72
|
+
/** Data version for migration */
|
|
73
|
+
version: number;
|
|
74
|
+
/** Whether value is compressed */
|
|
75
|
+
compressed?: boolean;
|
|
76
|
+
/** SHA-256 checksum for integrity */
|
|
77
|
+
checksum?: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Options for setItemWithExpiry
|
|
81
|
+
*/
|
|
82
|
+
interface ExpiryOptions {
|
|
83
|
+
/** Expiration time in milliseconds from now */
|
|
84
|
+
expiresIn?: number;
|
|
85
|
+
/** Absolute expiration date */
|
|
86
|
+
expiresAt?: Date;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Encrypted backup structure
|
|
90
|
+
*/
|
|
91
|
+
interface EncryptedBackup {
|
|
92
|
+
/** Backup version */
|
|
93
|
+
version: string;
|
|
94
|
+
/** Backup timestamp */
|
|
95
|
+
timestamp: number;
|
|
96
|
+
/** Encrypted data */
|
|
97
|
+
data: Record<string, string>;
|
|
98
|
+
/** Backup metadata */
|
|
99
|
+
metadata: {
|
|
100
|
+
/** Key version used for encryption */
|
|
101
|
+
keyVersion: number;
|
|
102
|
+
/** Encryption algorithm */
|
|
103
|
+
algorithm: string;
|
|
104
|
+
/** Number of items */
|
|
105
|
+
itemCount: number;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Integrity information
|
|
110
|
+
*/
|
|
111
|
+
interface IntegrityInfo {
|
|
112
|
+
/** Whether data is valid */
|
|
113
|
+
valid: boolean;
|
|
114
|
+
/** Last modified timestamp */
|
|
115
|
+
lastModified: number;
|
|
116
|
+
/** SHA-256 checksum */
|
|
117
|
+
checksum: string;
|
|
118
|
+
/** Data version */
|
|
119
|
+
version: number;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Storage event types
|
|
123
|
+
*/
|
|
124
|
+
type StorageEventType = 'encrypted' | 'decrypted' | 'deleted' | 'cleared' | 'expired' | 'error' | 'keyRotated' | 'compressed' | 'decompressed';
|
|
125
|
+
/**
|
|
126
|
+
* Storage event data
|
|
127
|
+
*/
|
|
128
|
+
interface StorageEventData {
|
|
129
|
+
/** Event type */
|
|
130
|
+
type: StorageEventType;
|
|
131
|
+
/** Key involved (if applicable) */
|
|
132
|
+
key?: string;
|
|
133
|
+
/** Event timestamp */
|
|
134
|
+
timestamp: number;
|
|
135
|
+
/** Additional metadata */
|
|
136
|
+
metadata?: any;
|
|
137
|
+
/** Error (if type is 'error') */
|
|
138
|
+
error?: Error;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Event listener function
|
|
142
|
+
*/
|
|
143
|
+
type EventListener = (data: StorageEventData) => void;
|
|
144
|
+
/**
|
|
145
|
+
* Default configuration values
|
|
146
|
+
*/
|
|
147
|
+
declare const DEFAULT_CONFIG: Required<SecureStorageConfig>;
|
|
148
|
+
/**
|
|
149
|
+
* Current library version
|
|
150
|
+
*/
|
|
151
|
+
declare const LIBRARY_VERSION = "2.0.0";
|
|
152
|
+
/**
|
|
153
|
+
* Storage data version
|
|
154
|
+
*/
|
|
155
|
+
declare const STORAGE_VERSION = 2;
|
|
156
|
+
|
|
3
157
|
/**
|
|
4
158
|
* EncryptionHelper - Clase responsable de todas las operaciones criptográficas
|
|
5
159
|
* Implementa AES-256-GCM con derivación de claves PBKDF2 y fingerprinting del navegador
|
|
6
160
|
*/
|
|
7
161
|
declare class EncryptionHelper {
|
|
8
162
|
private static readonly ALGORITHM;
|
|
9
|
-
private static readonly KEY_LENGTH;
|
|
10
|
-
private static readonly IV_LENGTH;
|
|
11
|
-
private static readonly SALT_LENGTH;
|
|
12
|
-
private static readonly ITERATIONS;
|
|
13
163
|
private static readonly HASH_ALGORITHM;
|
|
14
164
|
private static readonly SALT_STORAGE_KEY;
|
|
15
|
-
private static readonly
|
|
165
|
+
private static readonly KEY_VERSION_KEY;
|
|
166
|
+
private readonly config;
|
|
16
167
|
private key;
|
|
17
168
|
private baseKey;
|
|
18
169
|
private baseKeyPromise;
|
|
170
|
+
private keyVersion;
|
|
171
|
+
constructor(config?: EncryptionConfig);
|
|
172
|
+
/**
|
|
173
|
+
* Get current key version
|
|
174
|
+
*/
|
|
175
|
+
getKeyVersion(): number;
|
|
19
176
|
/**
|
|
20
177
|
* Genera un fingerprint único del navegador
|
|
21
178
|
* Combina múltiples características del navegador para crear una huella digital
|
|
@@ -74,47 +231,136 @@ declare class EncryptionHelper {
|
|
|
74
231
|
}
|
|
75
232
|
|
|
76
233
|
/**
|
|
77
|
-
*
|
|
78
|
-
|
|
234
|
+
* Namespaced storage for organizing data
|
|
235
|
+
*/
|
|
236
|
+
declare class NamespacedStorage {
|
|
237
|
+
private prefix;
|
|
238
|
+
private storage;
|
|
239
|
+
constructor(storage: any, namespace: string);
|
|
240
|
+
/**
|
|
241
|
+
* Set item in this namespace
|
|
242
|
+
*/
|
|
243
|
+
setItem(key: string, value: string): Promise<void>;
|
|
244
|
+
/**
|
|
245
|
+
* Set item with expiry in this namespace
|
|
246
|
+
*/
|
|
247
|
+
setItemWithExpiry(key: string, value: string, options: {
|
|
248
|
+
expiresIn?: number;
|
|
249
|
+
expiresAt?: Date;
|
|
250
|
+
}): Promise<void>;
|
|
251
|
+
/**
|
|
252
|
+
* Get item from this namespace
|
|
253
|
+
*/
|
|
254
|
+
getItem(key: string): Promise<string | null>;
|
|
255
|
+
/**
|
|
256
|
+
* Remove item from this namespace
|
|
257
|
+
*/
|
|
258
|
+
removeItem(key: string): Promise<void>;
|
|
259
|
+
/**
|
|
260
|
+
* Check if item exists in this namespace
|
|
261
|
+
*/
|
|
262
|
+
hasItem(key: string): Promise<boolean>;
|
|
263
|
+
/**
|
|
264
|
+
* Clear all items in this namespace
|
|
265
|
+
*/
|
|
266
|
+
clearNamespace(): Promise<void>;
|
|
267
|
+
/**
|
|
268
|
+
* Get all keys in this namespace
|
|
269
|
+
*/
|
|
270
|
+
keys(): Promise<string[]>;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* SecureStorage v2 - API de alto nivel que imita localStorage con cifrado automático
|
|
275
|
+
* Incluye: configuración personalizable, eventos, compresión, expiración, namespaces, rotación de claves
|
|
79
276
|
*/
|
|
80
277
|
declare class SecureStorage {
|
|
81
278
|
private static instance;
|
|
82
279
|
private encryptionHelper;
|
|
280
|
+
private eventEmitter;
|
|
281
|
+
private keyRotation;
|
|
282
|
+
private logger;
|
|
283
|
+
private config;
|
|
284
|
+
private cleanupInterval;
|
|
83
285
|
private constructor();
|
|
84
286
|
/**
|
|
85
287
|
* Obtiene la instancia singleton de SecureStorage
|
|
86
288
|
*/
|
|
87
|
-
static getInstance(): SecureStorage;
|
|
289
|
+
static getInstance(config?: SecureStorageConfig): SecureStorage;
|
|
290
|
+
/**
|
|
291
|
+
* Setup automatic cleanup of expired items
|
|
292
|
+
*/
|
|
293
|
+
private setupAutoCleanup;
|
|
88
294
|
/**
|
|
89
295
|
* Guarda un valor encriptado en localStorage
|
|
90
|
-
* @param key - Clave para almacenar
|
|
91
|
-
* @param value - Valor a encriptar y almacenar
|
|
92
296
|
*/
|
|
93
297
|
setItem(key: string, value: string): Promise<void>;
|
|
298
|
+
/**
|
|
299
|
+
* Guarda un valor con tiempo de expiración
|
|
300
|
+
*/
|
|
301
|
+
setItemWithExpiry(key: string, value: string, options: ExpiryOptions): Promise<void>;
|
|
94
302
|
/**
|
|
95
303
|
* Recupera y desencripta un valor de localStorage
|
|
96
|
-
* @param key - Clave a buscar
|
|
97
|
-
* @returns Valor desencriptado o null si no existe
|
|
98
304
|
*/
|
|
99
305
|
getItem(key: string): Promise<string | null>;
|
|
100
306
|
/**
|
|
101
307
|
* Elimina un valor de localStorage
|
|
102
|
-
* @param key - Clave a eliminar
|
|
103
308
|
*/
|
|
104
309
|
removeItem(key: string): Promise<void>;
|
|
105
310
|
/**
|
|
106
311
|
* Verifica si existe un valor para la clave dada
|
|
107
|
-
* @param key - Clave a verificar
|
|
108
|
-
* @returns true si existe, false si no
|
|
109
312
|
*/
|
|
110
313
|
hasItem(key: string): Promise<boolean>;
|
|
111
314
|
/**
|
|
112
315
|
* Limpia todos los datos encriptados
|
|
113
316
|
*/
|
|
114
317
|
clear(): void;
|
|
318
|
+
/**
|
|
319
|
+
* Limpia todos los items expirados
|
|
320
|
+
*/
|
|
321
|
+
cleanExpired(): Promise<number>;
|
|
322
|
+
/**
|
|
323
|
+
* Verifica la integridad de un valor almacenado
|
|
324
|
+
*/
|
|
325
|
+
verifyIntegrity(key: string): Promise<boolean>;
|
|
326
|
+
/**
|
|
327
|
+
* Obtiene información de integridad de un valor
|
|
328
|
+
*/
|
|
329
|
+
getIntegrityInfo(key: string): Promise<IntegrityInfo | null>;
|
|
330
|
+
/**
|
|
331
|
+
* Crea un namespace para organizar datos
|
|
332
|
+
*/
|
|
333
|
+
namespace(name: string): NamespacedStorage;
|
|
334
|
+
/**
|
|
335
|
+
* Rota todas las claves de encriptación
|
|
336
|
+
*/
|
|
337
|
+
rotateKeys(): Promise<void>;
|
|
338
|
+
/**
|
|
339
|
+
* Exporta todos los datos encriptados como backup
|
|
340
|
+
*/
|
|
341
|
+
exportEncryptedData(): Promise<EncryptedBackup>;
|
|
342
|
+
/**
|
|
343
|
+
* Importa datos desde un backup
|
|
344
|
+
*/
|
|
345
|
+
importEncryptedData(backup: any): Promise<void>;
|
|
346
|
+
/**
|
|
347
|
+
* Registra un listener de eventos
|
|
348
|
+
*/
|
|
349
|
+
on(event: StorageEventType, listener: EventListener): void;
|
|
350
|
+
/**
|
|
351
|
+
* Registra un listener de un solo uso
|
|
352
|
+
*/
|
|
353
|
+
once(event: StorageEventType, listener: EventListener): void;
|
|
354
|
+
/**
|
|
355
|
+
* Elimina un listener de eventos
|
|
356
|
+
*/
|
|
357
|
+
off(event: StorageEventType, listener: EventListener): void;
|
|
358
|
+
/**
|
|
359
|
+
* Elimina todos los listeners de un evento
|
|
360
|
+
*/
|
|
361
|
+
removeAllListeners(event?: StorageEventType): void;
|
|
115
362
|
/**
|
|
116
363
|
* Migra datos existentes no encriptados a formato encriptado
|
|
117
|
-
* @param keys - Array de claves a migrar
|
|
118
364
|
*/
|
|
119
365
|
migrateExistingData(keys: string[]): Promise<void>;
|
|
120
366
|
/**
|
|
@@ -125,45 +371,171 @@ declare class SecureStorage {
|
|
|
125
371
|
encryptedKeys: string[];
|
|
126
372
|
unencryptedKeys: string[];
|
|
127
373
|
totalKeys: number;
|
|
374
|
+
config: Required<SecureStorageConfig>;
|
|
128
375
|
};
|
|
376
|
+
/**
|
|
377
|
+
* Calcula el checksum SHA-256 de un valor
|
|
378
|
+
*/
|
|
379
|
+
private calculateChecksum;
|
|
380
|
+
/**
|
|
381
|
+
* Cleanup on destroy
|
|
382
|
+
*/
|
|
383
|
+
destroy(): void;
|
|
129
384
|
}
|
|
130
385
|
|
|
131
|
-
|
|
386
|
+
/**
|
|
387
|
+
* Simple event emitter for storage events
|
|
388
|
+
*/
|
|
389
|
+
declare class EventEmitter {
|
|
390
|
+
private listeners;
|
|
391
|
+
private onceListeners;
|
|
392
|
+
/**
|
|
393
|
+
* Register an event listener
|
|
394
|
+
*/
|
|
395
|
+
on(event: StorageEventType, listener: EventListener): void;
|
|
396
|
+
/**
|
|
397
|
+
* Register a one-time event listener
|
|
398
|
+
*/
|
|
399
|
+
once(event: StorageEventType, listener: EventListener): void;
|
|
400
|
+
/**
|
|
401
|
+
* Remove an event listener
|
|
402
|
+
*/
|
|
403
|
+
off(event: StorageEventType, listener: EventListener): void;
|
|
404
|
+
/**
|
|
405
|
+
* Remove all listeners for an event
|
|
406
|
+
*/
|
|
407
|
+
removeAllListeners(event?: StorageEventType): void;
|
|
408
|
+
/**
|
|
409
|
+
* Emit an event
|
|
410
|
+
*/
|
|
411
|
+
emit(event: StorageEventType, data: Omit<StorageEventData, 'type' | 'timestamp'>): void;
|
|
412
|
+
/**
|
|
413
|
+
* Get listener count for an event
|
|
414
|
+
*/
|
|
415
|
+
listenerCount(event: StorageEventType): number;
|
|
416
|
+
/**
|
|
417
|
+
* Get all event types with listeners
|
|
418
|
+
*/
|
|
419
|
+
eventNames(): StorageEventType[];
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Logger utility for debug mode
|
|
424
|
+
*/
|
|
425
|
+
declare class Logger {
|
|
426
|
+
private enabled;
|
|
427
|
+
private logLevel;
|
|
428
|
+
private prefix;
|
|
429
|
+
private static readonly LOG_LEVELS;
|
|
430
|
+
constructor(config?: DebugConfig);
|
|
431
|
+
private shouldLog;
|
|
432
|
+
private formatMessage;
|
|
433
|
+
error(message: string, ...args: any[]): void;
|
|
434
|
+
warn(message: string, ...args: any[]): void;
|
|
435
|
+
info(message: string, ...args: any[]): void;
|
|
436
|
+
debug(message: string, ...args: any[]): void;
|
|
437
|
+
verbose(message: string, ...args: any[]): void;
|
|
438
|
+
time(label: string): void;
|
|
439
|
+
timeEnd(label: string): void;
|
|
440
|
+
group(label: string): void;
|
|
441
|
+
groupEnd(): void;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Key rotation utilities
|
|
446
|
+
*/
|
|
447
|
+
declare class KeyRotation {
|
|
448
|
+
private encryptionHelper;
|
|
449
|
+
private logger;
|
|
450
|
+
constructor(encryptionHelper: EncryptionHelper, logger?: Logger);
|
|
451
|
+
/**
|
|
452
|
+
* Rotate all encryption keys
|
|
453
|
+
* Re-encrypts all data with a new salt
|
|
454
|
+
*/
|
|
455
|
+
rotateKeys(): Promise<void>;
|
|
456
|
+
/**
|
|
457
|
+
* Export all encrypted data as backup
|
|
458
|
+
*/
|
|
459
|
+
exportEncryptedData(): Promise<EncryptedBackup>;
|
|
460
|
+
/**
|
|
461
|
+
* Import encrypted data from backup
|
|
462
|
+
*/
|
|
463
|
+
importEncryptedData(backup: EncryptedBackup): Promise<void>;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Compression utilities using CompressionStream API
|
|
468
|
+
*/
|
|
469
|
+
/**
|
|
470
|
+
* Check if compression is supported
|
|
471
|
+
*/
|
|
472
|
+
declare function isCompressionSupported(): boolean;
|
|
473
|
+
/**
|
|
474
|
+
* Compress a string using gzip
|
|
475
|
+
*/
|
|
476
|
+
declare function compress(data: string): Promise<Uint8Array>;
|
|
477
|
+
/**
|
|
478
|
+
* Decompress gzip data to string
|
|
479
|
+
*/
|
|
480
|
+
declare function decompress(data: Uint8Array): Promise<string>;
|
|
481
|
+
/**
|
|
482
|
+
* Check if data should be compressed based on size
|
|
483
|
+
*/
|
|
484
|
+
declare function shouldCompress(data: string, threshold?: number): boolean;
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Función de debug para verificar el estado del sistema de encriptación
|
|
488
|
+
* Muestra información detallada en la consola
|
|
489
|
+
*/
|
|
490
|
+
declare function debugEncryptionState(): Promise<void>;
|
|
491
|
+
/**
|
|
492
|
+
* Fuerza la migración de claves comunes a formato encriptado
|
|
493
|
+
* Útil para desarrollo y testing
|
|
494
|
+
*/
|
|
495
|
+
declare function forceMigration(customKeys?: string[]): Promise<void>;
|
|
496
|
+
|
|
132
497
|
/**
|
|
133
498
|
* Hook de React para usar SecureStorage de forma reactiva
|
|
134
499
|
* Similar a useState pero con persistencia encriptada
|
|
135
500
|
*
|
|
136
501
|
* @param key - Clave para almacenar en localStorage
|
|
137
502
|
* @param initialValue - Valor inicial si no existe en storage
|
|
503
|
+
* @param storage - Instancia personalizada de SecureStorage (opcional)
|
|
138
504
|
* @returns [value, setValue, loading, error]
|
|
139
505
|
*
|
|
140
506
|
* @example
|
|
141
507
|
* const [token, setToken, loading] = useSecureStorage('accessToken', '');
|
|
142
508
|
*/
|
|
143
|
-
declare function useSecureStorage<T = string>(key: string, initialValue: T): [T, (value: T) => Promise<void>, boolean, Error | null];
|
|
509
|
+
declare function useSecureStorage<T = string>(key: string, initialValue: T, storage?: SecureStorage): [T, (value: T) => Promise<void>, boolean, Error | null];
|
|
144
510
|
/**
|
|
145
511
|
* Hook para verificar si una clave existe en SecureStorage
|
|
146
512
|
*
|
|
147
513
|
* @param key - Clave a verificar
|
|
514
|
+
* @param storage - Instancia personalizada de SecureStorage (opcional)
|
|
148
515
|
* @returns [exists, loading, error]
|
|
149
516
|
*
|
|
150
517
|
* @example
|
|
151
518
|
* const [hasToken, loading] = useSecureStorageItem('accessToken');
|
|
152
519
|
*/
|
|
153
|
-
declare function useSecureStorageItem(key: string): [boolean, boolean, Error | null];
|
|
520
|
+
declare function useSecureStorageItem(key: string, storage?: SecureStorage): [boolean, boolean, Error | null];
|
|
154
521
|
/**
|
|
155
522
|
* Hook para obtener información de debug del almacenamiento
|
|
156
523
|
*
|
|
524
|
+
* @param storage - Instancia personalizada de SecureStorage (opcional)
|
|
157
525
|
* @returns Información de debug
|
|
158
526
|
*
|
|
159
527
|
* @example
|
|
160
528
|
* const debugInfo = useSecureStorageDebug();
|
|
161
529
|
* console.log(`Claves encriptadas: ${debugInfo.encryptedKeys.length}`);
|
|
162
530
|
*/
|
|
163
|
-
declare function useSecureStorageDebug(): any;
|
|
531
|
+
declare function useSecureStorageDebug(storage?: SecureStorage): any;
|
|
532
|
+
/**
|
|
533
|
+
* Exportar la instancia de SecureStorage para uso directo
|
|
534
|
+
*/
|
|
535
|
+
declare const secureStorage$1: SecureStorage;
|
|
164
536
|
|
|
165
537
|
/**
|
|
166
|
-
* Servicio de Angular para SecureStorage
|
|
538
|
+
* Servicio de Angular para SecureStorage v2
|
|
167
539
|
* Proporciona una API reactiva usando RxJS Observables
|
|
168
540
|
*
|
|
169
541
|
* @example
|
|
@@ -174,11 +546,19 @@ declare function useSecureStorageDebug(): any;
|
|
|
174
546
|
*
|
|
175
547
|
* // Leer
|
|
176
548
|
* this.secureStorage.getItem('token').subscribe(token => console.log(token));
|
|
549
|
+
*
|
|
550
|
+
* // Escuchar eventos
|
|
551
|
+
* this.secureStorage.events$.subscribe(event => console.log(event));
|
|
177
552
|
*/
|
|
178
553
|
declare class SecureStorageService {
|
|
179
554
|
private storage;
|
|
180
555
|
private debugInfo$;
|
|
181
|
-
|
|
556
|
+
private eventsSubject$;
|
|
557
|
+
/**
|
|
558
|
+
* Observable de eventos de storage
|
|
559
|
+
*/
|
|
560
|
+
events$: any;
|
|
561
|
+
constructor(config?: SecureStorageConfig);
|
|
182
562
|
/**
|
|
183
563
|
* Guarda un valor encriptado
|
|
184
564
|
* @param key - Clave
|
|
@@ -186,6 +566,14 @@ declare class SecureStorageService {
|
|
|
186
566
|
* @returns Observable que completa cuando se guarda
|
|
187
567
|
*/
|
|
188
568
|
setItem(key: string, value: string): Observable<void>;
|
|
569
|
+
/**
|
|
570
|
+
* Guarda un valor con expiración
|
|
571
|
+
* @param key - Clave
|
|
572
|
+
* @param value - Valor a guardar
|
|
573
|
+
* @param options - Opciones de expiración
|
|
574
|
+
* @returns Observable que completa cuando se guarda
|
|
575
|
+
*/
|
|
576
|
+
setItemWithExpiry(key: string, value: string, options: ExpiryOptions): Observable<void>;
|
|
189
577
|
/**
|
|
190
578
|
* Recupera un valor desencriptado
|
|
191
579
|
* @param key - Clave
|
|
@@ -208,6 +596,45 @@ declare class SecureStorageService {
|
|
|
208
596
|
* Limpia todos los datos encriptados
|
|
209
597
|
*/
|
|
210
598
|
clear(): void;
|
|
599
|
+
/**
|
|
600
|
+
* Limpia todos los items expirados
|
|
601
|
+
* @returns Observable con el número de items eliminados
|
|
602
|
+
*/
|
|
603
|
+
cleanExpired(): Observable<number>;
|
|
604
|
+
/**
|
|
605
|
+
* Verifica la integridad de un valor
|
|
606
|
+
* @param key - Clave a verificar
|
|
607
|
+
* @returns Observable con true si es válido
|
|
608
|
+
*/
|
|
609
|
+
verifyIntegrity(key: string): Observable<boolean>;
|
|
610
|
+
/**
|
|
611
|
+
* Obtiene información de integridad de un valor
|
|
612
|
+
* @param key - Clave
|
|
613
|
+
* @returns Observable con información de integridad
|
|
614
|
+
*/
|
|
615
|
+
getIntegrityInfo(key: string): Observable<any>;
|
|
616
|
+
/**
|
|
617
|
+
* Crea un namespace para organizar datos
|
|
618
|
+
* @param name - Nombre del namespace
|
|
619
|
+
* @returns Instancia de NamespacedStorage
|
|
620
|
+
*/
|
|
621
|
+
namespace(name: string): NamespacedStorage;
|
|
622
|
+
/**
|
|
623
|
+
* Rota todas las claves de encriptación
|
|
624
|
+
* @returns Observable que completa cuando termina la rotación
|
|
625
|
+
*/
|
|
626
|
+
rotateKeys(): Observable<void>;
|
|
627
|
+
/**
|
|
628
|
+
* Exporta todos los datos como backup
|
|
629
|
+
* @returns Observable con el backup
|
|
630
|
+
*/
|
|
631
|
+
exportEncryptedData(): Observable<EncryptedBackup>;
|
|
632
|
+
/**
|
|
633
|
+
* Importa datos desde un backup
|
|
634
|
+
* @param backup - Backup a importar
|
|
635
|
+
* @returns Observable que completa cuando termina la importación
|
|
636
|
+
*/
|
|
637
|
+
importEncryptedData(backup: EncryptedBackup): Observable<void>;
|
|
211
638
|
/**
|
|
212
639
|
* Migra datos existentes a formato encriptado
|
|
213
640
|
* @param keys - Array de claves a migrar
|
|
@@ -218,12 +645,7 @@ declare class SecureStorageService {
|
|
|
218
645
|
* Obtiene información de debug como Observable
|
|
219
646
|
* @returns Observable con información de debug que se actualiza automáticamente
|
|
220
647
|
*/
|
|
221
|
-
getDebugInfo$(): Observable<
|
|
222
|
-
cryptoSupported: boolean;
|
|
223
|
-
encryptedKeys: string[];
|
|
224
|
-
unencryptedKeys: string[];
|
|
225
|
-
totalKeys: number;
|
|
226
|
-
}>;
|
|
648
|
+
getDebugInfo$(): Observable<any>;
|
|
227
649
|
/**
|
|
228
650
|
* Obtiene información de debug de forma síncrona
|
|
229
651
|
*/
|
|
@@ -234,27 +656,41 @@ declare class SecureStorageService {
|
|
|
234
656
|
* @param value - Objeto a guardar
|
|
235
657
|
*/
|
|
236
658
|
setObject<T>(key: string, value: T): Observable<void>;
|
|
659
|
+
/**
|
|
660
|
+
* Helper para guardar objetos JSON con expiración
|
|
661
|
+
* @param key - Clave
|
|
662
|
+
* @param value - Objeto a guardar
|
|
663
|
+
* @param options - Opciones de expiración
|
|
664
|
+
*/
|
|
665
|
+
setObjectWithExpiry<T>(key: string, value: T, options: ExpiryOptions): Observable<void>;
|
|
237
666
|
/**
|
|
238
667
|
* Helper para recuperar objetos JSON
|
|
239
668
|
* @param key - Clave
|
|
240
669
|
* @returns Observable con el objeto parseado o null
|
|
241
670
|
*/
|
|
242
671
|
getObject<T>(key: string): Observable<T | null>;
|
|
672
|
+
/**
|
|
673
|
+
* Registra un listener para un tipo de evento específico
|
|
674
|
+
* @param event - Tipo de evento
|
|
675
|
+
* @param handler - Función manejadora
|
|
676
|
+
*/
|
|
677
|
+
on(event: any, handler: (data: StorageEventData) => void): void;
|
|
678
|
+
/**
|
|
679
|
+
* Elimina un listener de evento
|
|
680
|
+
* @param event - Tipo de evento
|
|
681
|
+
* @param handler - Función manejadora
|
|
682
|
+
*/
|
|
683
|
+
off(event: any, handler: (data: StorageEventData) => void): void;
|
|
684
|
+
/**
|
|
685
|
+
* Observable filtrado por tipo de evento
|
|
686
|
+
* @param eventType - Tipo de evento a filtrar
|
|
687
|
+
* @returns Observable con eventos del tipo especificado
|
|
688
|
+
*/
|
|
689
|
+
onEvent$(eventType: string): Observable<StorageEventData>;
|
|
243
690
|
}
|
|
244
691
|
|
|
245
692
|
/**
|
|
246
|
-
*
|
|
247
|
-
* Muestra información detallada en la consola
|
|
248
|
-
*/
|
|
249
|
-
declare function debugEncryptionState(): Promise<void>;
|
|
250
|
-
/**
|
|
251
|
-
* Fuerza la migración de claves comunes a formato encriptado
|
|
252
|
-
* Útil para desarrollo y testing
|
|
253
|
-
*/
|
|
254
|
-
declare function forceMigration(customKeys?: string[]): Promise<void>;
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* @mtt/local-cipher
|
|
693
|
+
* @bantis/local-cipher v2.0.0
|
|
258
694
|
* Librería de cifrado local AES-256-GCM para Angular, React y JavaScript
|
|
259
695
|
*
|
|
260
696
|
* @author MTT
|
|
@@ -262,6 +698,7 @@ declare function forceMigration(customKeys?: string[]): Promise<void>;
|
|
|
262
698
|
*/
|
|
263
699
|
|
|
264
700
|
declare const secureStorage: SecureStorage;
|
|
265
|
-
declare const VERSION = "
|
|
701
|
+
declare const VERSION = "2.0.0";
|
|
266
702
|
|
|
267
|
-
export { EncryptionHelper, SecureStorage, SecureStorageService, VERSION, debugEncryptionState, forceMigration, secureStorage$1 as reactSecureStorage, secureStorage, useSecureStorage, useSecureStorageDebug, useSecureStorageItem };
|
|
703
|
+
export { DEFAULT_CONFIG, EncryptionHelper, EventEmitter, KeyRotation, LIBRARY_VERSION, Logger, NamespacedStorage, STORAGE_VERSION, SecureStorage, SecureStorageService, VERSION, compress, debugEncryptionState, decompress, forceMigration, isCompressionSupported, secureStorage$1 as reactSecureStorage, secureStorage, shouldCompress, useSecureStorage, useSecureStorageDebug, useSecureStorageItem };
|
|
704
|
+
export type { DebugConfig, EncryptedBackup, EncryptionConfig, EventListener, ExpiryOptions, IntegrityInfo, LogLevel, SecureStorageConfig, StorageConfig, StorageEventData, StorageEventType, StoredValue };
|