@bantis/local-cipher 2.0.0 → 2.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/LICENSE +1 -1
- package/README.md +274 -254
- package/dist/angular/SecureStorageService.d.ts +156 -0
- package/dist/angular.d.ts +9 -0
- package/dist/angular.esm.js +1516 -0
- package/dist/angular.esm.js.map +1 -0
- package/dist/angular.js +1535 -0
- package/dist/angular.js.map +1 -0
- package/dist/core/EncryptionHelper.d.ts +76 -0
- package/dist/core/EventEmitter.d.ts +36 -0
- package/dist/core/KeyRotation.d.ts +24 -0
- package/dist/core/NamespacedStorage.d.ts +39 -0
- package/dist/core/SecureStorage.d.ts +114 -0
- package/dist/index.d.ts +16 -700
- package/dist/index.esm.js +9 -440
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +8 -444
- package/dist/index.js.map +1 -1
- package/dist/react/hooks.d.ts +39 -0
- package/dist/react.d.ts +9 -0
- package/dist/react.esm.js +1414 -0
- package/dist/react.esm.js.map +1 -0
- package/dist/react.js +1440 -0
- package/dist/react.js.map +1 -0
- package/dist/types/index.d.ts +153 -0
- package/dist/utils/compression.d.ts +23 -0
- package/dist/utils/debug.d.ts +18 -0
- package/dist/utils/logger.d.ts +22 -0
- package/package.json +48 -13
package/dist/index.d.ts
CHANGED
|
@@ -1,704 +1,20 @@
|
|
|
1
|
-
import { Observable } from 'rxjs';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
|
-
*
|
|
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
|
-
|
|
157
|
-
/**
|
|
158
|
-
* EncryptionHelper - Clase responsable de todas las operaciones criptográficas
|
|
159
|
-
* Implementa AES-256-GCM con derivación de claves PBKDF2 y fingerprinting del navegador
|
|
160
|
-
*/
|
|
161
|
-
declare class EncryptionHelper {
|
|
162
|
-
private static readonly ALGORITHM;
|
|
163
|
-
private static readonly HASH_ALGORITHM;
|
|
164
|
-
private static readonly SALT_STORAGE_KEY;
|
|
165
|
-
private static readonly KEY_VERSION_KEY;
|
|
166
|
-
private readonly config;
|
|
167
|
-
private key;
|
|
168
|
-
private baseKey;
|
|
169
|
-
private baseKeyPromise;
|
|
170
|
-
private keyVersion;
|
|
171
|
-
constructor(config?: EncryptionConfig);
|
|
172
|
-
/**
|
|
173
|
-
* Get current key version
|
|
174
|
-
*/
|
|
175
|
-
getKeyVersion(): number;
|
|
176
|
-
/**
|
|
177
|
-
* Genera un fingerprint único del navegador
|
|
178
|
-
* Combina múltiples características del navegador para crear una huella digital
|
|
179
|
-
*/
|
|
180
|
-
private generateBaseKey;
|
|
181
|
-
/**
|
|
182
|
-
* Hashea un string usando SHA-256
|
|
183
|
-
* @param str - String a hashear
|
|
184
|
-
* @returns Hash hexadecimal
|
|
185
|
-
*/
|
|
186
|
-
private hashString;
|
|
187
|
-
/**
|
|
188
|
-
* Deriva una clave criptográfica usando PBKDF2
|
|
189
|
-
* @param password - Password base (fingerprint)
|
|
190
|
-
* @param salt - Salt aleatorio
|
|
191
|
-
* @returns CryptoKey para AES-GCM
|
|
192
|
-
*/
|
|
193
|
-
private deriveKey;
|
|
194
|
-
/**
|
|
195
|
-
* Inicializa el sistema de encriptación generando un nuevo salt
|
|
196
|
-
*/
|
|
197
|
-
initialize(): Promise<void>;
|
|
198
|
-
/**
|
|
199
|
-
* Inicializa desde un salt almacenado previamente
|
|
200
|
-
*/
|
|
201
|
-
initializeFromStored(): Promise<void>;
|
|
202
|
-
/**
|
|
203
|
-
* Encripta un texto plano usando AES-256-GCM
|
|
204
|
-
* @param plaintext - Texto a encriptar
|
|
205
|
-
* @returns Texto encriptado en Base64 (IV + datos encriptados)
|
|
206
|
-
*/
|
|
207
|
-
encrypt(plaintext: string): Promise<string>;
|
|
208
|
-
/**
|
|
209
|
-
* Desencripta un texto encriptado
|
|
210
|
-
* @param ciphertext - Texto encriptado en Base64
|
|
211
|
-
* @returns Texto plano
|
|
212
|
-
*/
|
|
213
|
-
decrypt(ciphertext: string): Promise<string>;
|
|
214
|
-
/**
|
|
215
|
-
* Encripta el nombre de una clave para ofuscar nombres en localStorage
|
|
216
|
-
* @param keyName - Nombre original de la clave
|
|
217
|
-
* @returns Nombre encriptado con prefijo __enc_
|
|
218
|
-
*/
|
|
219
|
-
encryptKey(keyName: string): Promise<string>;
|
|
220
|
-
/**
|
|
221
|
-
* Limpia todos los datos encriptados del localStorage
|
|
222
|
-
*/
|
|
223
|
-
clearEncryptedData(): void;
|
|
224
|
-
/**
|
|
225
|
-
* Verifica si el navegador soporta Web Crypto API
|
|
226
|
-
*/
|
|
227
|
-
static isSupported(): boolean;
|
|
228
|
-
private arrayBufferToBase64;
|
|
229
|
-
private base64ToArrayBuffer;
|
|
230
|
-
private arrayBufferToHex;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
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
|
|
276
|
-
*/
|
|
277
|
-
declare class SecureStorage {
|
|
278
|
-
private static instance;
|
|
279
|
-
private encryptionHelper;
|
|
280
|
-
private eventEmitter;
|
|
281
|
-
private keyRotation;
|
|
282
|
-
private logger;
|
|
283
|
-
private config;
|
|
284
|
-
private cleanupInterval;
|
|
285
|
-
private constructor();
|
|
286
|
-
/**
|
|
287
|
-
* Obtiene la instancia singleton de SecureStorage
|
|
288
|
-
*/
|
|
289
|
-
static getInstance(config?: SecureStorageConfig): SecureStorage;
|
|
290
|
-
/**
|
|
291
|
-
* Setup automatic cleanup of expired items
|
|
292
|
-
*/
|
|
293
|
-
private setupAutoCleanup;
|
|
294
|
-
/**
|
|
295
|
-
* Guarda un valor encriptado en localStorage
|
|
296
|
-
*/
|
|
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>;
|
|
302
|
-
/**
|
|
303
|
-
* Recupera y desencripta un valor de localStorage
|
|
304
|
-
*/
|
|
305
|
-
getItem(key: string): Promise<string | null>;
|
|
306
|
-
/**
|
|
307
|
-
* Elimina un valor de localStorage
|
|
308
|
-
*/
|
|
309
|
-
removeItem(key: string): Promise<void>;
|
|
310
|
-
/**
|
|
311
|
-
* Verifica si existe un valor para la clave dada
|
|
312
|
-
*/
|
|
313
|
-
hasItem(key: string): Promise<boolean>;
|
|
314
|
-
/**
|
|
315
|
-
* Limpia todos los datos encriptados
|
|
316
|
-
*/
|
|
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;
|
|
362
|
-
/**
|
|
363
|
-
* Migra datos existentes no encriptados a formato encriptado
|
|
364
|
-
*/
|
|
365
|
-
migrateExistingData(keys: string[]): Promise<void>;
|
|
366
|
-
/**
|
|
367
|
-
* Obtiene información de debug sobre el estado del almacenamiento
|
|
368
|
-
*/
|
|
369
|
-
getDebugInfo(): {
|
|
370
|
-
cryptoSupported: boolean;
|
|
371
|
-
encryptedKeys: string[];
|
|
372
|
-
unencryptedKeys: string[];
|
|
373
|
-
totalKeys: number;
|
|
374
|
-
config: Required<SecureStorageConfig>;
|
|
375
|
-
};
|
|
376
|
-
/**
|
|
377
|
-
* Calcula el checksum SHA-256 de un valor
|
|
378
|
-
*/
|
|
379
|
-
private calculateChecksum;
|
|
380
|
-
/**
|
|
381
|
-
* Cleanup on destroy
|
|
382
|
-
*/
|
|
383
|
-
destroy(): void;
|
|
384
|
-
}
|
|
385
|
-
|
|
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
|
-
|
|
497
|
-
/**
|
|
498
|
-
* Hook de React para usar SecureStorage de forma reactiva
|
|
499
|
-
* Similar a useState pero con persistencia encriptada
|
|
500
|
-
*
|
|
501
|
-
* @param key - Clave para almacenar en localStorage
|
|
502
|
-
* @param initialValue - Valor inicial si no existe en storage
|
|
503
|
-
* @param storage - Instancia personalizada de SecureStorage (opcional)
|
|
504
|
-
* @returns [value, setValue, loading, error]
|
|
505
|
-
*
|
|
506
|
-
* @example
|
|
507
|
-
* const [token, setToken, loading] = useSecureStorage('accessToken', '');
|
|
508
|
-
*/
|
|
509
|
-
declare function useSecureStorage<T = string>(key: string, initialValue: T, storage?: SecureStorage): [T, (value: T) => Promise<void>, boolean, Error | null];
|
|
510
|
-
/**
|
|
511
|
-
* Hook para verificar si una clave existe en SecureStorage
|
|
512
|
-
*
|
|
513
|
-
* @param key - Clave a verificar
|
|
514
|
-
* @param storage - Instancia personalizada de SecureStorage (opcional)
|
|
515
|
-
* @returns [exists, loading, error]
|
|
516
|
-
*
|
|
517
|
-
* @example
|
|
518
|
-
* const [hasToken, loading] = useSecureStorageItem('accessToken');
|
|
519
|
-
*/
|
|
520
|
-
declare function useSecureStorageItem(key: string, storage?: SecureStorage): [boolean, boolean, Error | null];
|
|
521
|
-
/**
|
|
522
|
-
* Hook para obtener información de debug del almacenamiento
|
|
523
|
-
*
|
|
524
|
-
* @param storage - Instancia personalizada de SecureStorage (opcional)
|
|
525
|
-
* @returns Información de debug
|
|
526
|
-
*
|
|
527
|
-
* @example
|
|
528
|
-
* const debugInfo = useSecureStorageDebug();
|
|
529
|
-
* console.log(`Claves encriptadas: ${debugInfo.encryptedKeys.length}`);
|
|
530
|
-
*/
|
|
531
|
-
declare function useSecureStorageDebug(storage?: SecureStorage): any;
|
|
532
|
-
/**
|
|
533
|
-
* Exportar la instancia de SecureStorage para uso directo
|
|
534
|
-
*/
|
|
535
|
-
declare const secureStorage$1: SecureStorage;
|
|
536
|
-
|
|
537
|
-
/**
|
|
538
|
-
* Servicio de Angular para SecureStorage v2
|
|
539
|
-
* Proporciona una API reactiva usando RxJS Observables
|
|
540
|
-
*
|
|
541
|
-
* @example
|
|
542
|
-
* constructor(private secureStorage: SecureStorageService) {}
|
|
543
|
-
*
|
|
544
|
-
* // Guardar
|
|
545
|
-
* this.secureStorage.setItem('token', 'abc123').subscribe();
|
|
546
|
-
*
|
|
547
|
-
* // Leer
|
|
548
|
-
* this.secureStorage.getItem('token').subscribe(token => console.log(token));
|
|
549
|
-
*
|
|
550
|
-
* // Escuchar eventos
|
|
551
|
-
* this.secureStorage.events$.subscribe(event => console.log(event));
|
|
552
|
-
*/
|
|
553
|
-
declare class SecureStorageService {
|
|
554
|
-
private storage;
|
|
555
|
-
private debugInfo$;
|
|
556
|
-
private eventsSubject$;
|
|
557
|
-
/**
|
|
558
|
-
* Observable de eventos de storage
|
|
559
|
-
*/
|
|
560
|
-
events$: any;
|
|
561
|
-
constructor(config?: SecureStorageConfig);
|
|
562
|
-
/**
|
|
563
|
-
* Guarda un valor encriptado
|
|
564
|
-
* @param key - Clave
|
|
565
|
-
* @param value - Valor a guardar
|
|
566
|
-
* @returns Observable que completa cuando se guarda
|
|
567
|
-
*/
|
|
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>;
|
|
577
|
-
/**
|
|
578
|
-
* Recupera un valor desencriptado
|
|
579
|
-
* @param key - Clave
|
|
580
|
-
* @returns Observable con el valor o null
|
|
581
|
-
*/
|
|
582
|
-
getItem(key: string): Observable<string | null>;
|
|
583
|
-
/**
|
|
584
|
-
* Elimina un valor
|
|
585
|
-
* @param key - Clave a eliminar
|
|
586
|
-
* @returns Observable que completa cuando se elimina
|
|
587
|
-
*/
|
|
588
|
-
removeItem(key: string): Observable<void>;
|
|
589
|
-
/**
|
|
590
|
-
* Verifica si existe una clave
|
|
591
|
-
* @param key - Clave a verificar
|
|
592
|
-
* @returns Observable con true/false
|
|
593
|
-
*/
|
|
594
|
-
hasItem(key: string): Observable<boolean>;
|
|
595
|
-
/**
|
|
596
|
-
* Limpia todos los datos encriptados
|
|
597
|
-
*/
|
|
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>;
|
|
638
|
-
/**
|
|
639
|
-
* Migra datos existentes a formato encriptado
|
|
640
|
-
* @param keys - Array de claves a migrar
|
|
641
|
-
* @returns Observable que completa cuando termina la migración
|
|
642
|
-
*/
|
|
643
|
-
migrateExistingData(keys: string[]): Observable<void>;
|
|
644
|
-
/**
|
|
645
|
-
* Obtiene información de debug como Observable
|
|
646
|
-
* @returns Observable con información de debug que se actualiza automáticamente
|
|
647
|
-
*/
|
|
648
|
-
getDebugInfo$(): Observable<any>;
|
|
649
|
-
/**
|
|
650
|
-
* Obtiene información de debug de forma síncrona
|
|
651
|
-
*/
|
|
652
|
-
private getDebugInfo;
|
|
653
|
-
/**
|
|
654
|
-
* Helper para guardar objetos JSON
|
|
655
|
-
* @param key - Clave
|
|
656
|
-
* @param value - Objeto a guardar
|
|
657
|
-
*/
|
|
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>;
|
|
666
|
-
/**
|
|
667
|
-
* Helper para recuperar objetos JSON
|
|
668
|
-
* @param key - Clave
|
|
669
|
-
* @returns Observable con el objeto parseado o null
|
|
670
|
-
*/
|
|
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>;
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
/**
|
|
693
|
-
* @bantis/local-cipher v2.0.0
|
|
694
|
-
* Librería de cifrado local AES-256-GCM para Angular, React y JavaScript
|
|
2
|
+
* @bantis/local-cipher - Core Module
|
|
3
|
+
* Framework-agnostic client-side encryption for browser storage
|
|
695
4
|
*
|
|
696
|
-
* @
|
|
5
|
+
* @version 2.1.0
|
|
697
6
|
* @license MIT
|
|
698
7
|
*/
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
export {
|
|
704
|
-
export type {
|
|
8
|
+
export { EncryptionHelper } from './core/EncryptionHelper';
|
|
9
|
+
export { SecureStorage } from './core/SecureStorage';
|
|
10
|
+
export { EventEmitter } from './core/EventEmitter';
|
|
11
|
+
export { KeyRotation } from './core/KeyRotation';
|
|
12
|
+
export { NamespacedStorage } from './core/NamespacedStorage';
|
|
13
|
+
export type { EncryptionConfig, StorageConfig, DebugConfig, SecureStorageConfig, StoredValue, ExpiryOptions, EncryptedBackup, IntegrityInfo, StorageEventType, StorageEventData, EventListener, LogLevel, } from './types';
|
|
14
|
+
export { DEFAULT_CONFIG, LIBRARY_VERSION, STORAGE_VERSION } from './types';
|
|
15
|
+
export { Logger } from './utils/logger';
|
|
16
|
+
export { compress, decompress, shouldCompress, isCompressionSupported } from './utils/compression';
|
|
17
|
+
export { debugEncryptionState, forceMigration } from './utils/debug';
|
|
18
|
+
import { SecureStorage } from './core/SecureStorage';
|
|
19
|
+
export declare const secureStorage: SecureStorage;
|
|
20
|
+
export declare const VERSION = "2.1.0";
|