@bantis/local-cipher 2.1.0 → 2.2.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/dist/angular/SecureStorageService.d.ts +1 -1
- package/dist/angular.esm.js +33 -24
- package/dist/angular.esm.js.map +1 -1
- package/dist/angular.js +33 -24
- package/dist/angular.js.map +1 -1
- package/dist/core/NamespacedStorage.d.ts +3 -0
- package/dist/index.esm.js +31 -22
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +31 -22
- package/dist/index.js.map +1 -1
- package/dist/react/hooks.d.ts +8 -2
- package/dist/react.esm.js +31 -22
- package/dist/react.esm.js.map +1 -1
- package/dist/react.js +31 -22
- package/dist/react.js.map +1 -1
- package/package.json +7 -3
package/dist/react.esm.js
CHANGED
|
@@ -108,7 +108,7 @@ class EncryptionHelper {
|
|
|
108
108
|
// Derivar la clave AES-GCM
|
|
109
109
|
return crypto.subtle.deriveKey({
|
|
110
110
|
name: 'PBKDF2',
|
|
111
|
-
salt,
|
|
111
|
+
salt: salt,
|
|
112
112
|
iterations: this.config.iterations,
|
|
113
113
|
hash: EncryptionHelper.HASH_ALGORITHM,
|
|
114
114
|
}, keyMaterial, {
|
|
@@ -390,7 +390,7 @@ class Logger {
|
|
|
390
390
|
return false;
|
|
391
391
|
return Logger.LOG_LEVELS[level] <= Logger.LOG_LEVELS[this.logLevel];
|
|
392
392
|
}
|
|
393
|
-
formatMessage(level, message
|
|
393
|
+
formatMessage(level, message) {
|
|
394
394
|
const timestamp = new Date().toISOString();
|
|
395
395
|
return `[${this.prefix}] [${level.toUpperCase()}] ${timestamp} - ${message}`;
|
|
396
396
|
}
|
|
@@ -543,17 +543,37 @@ class NamespacedStorage {
|
|
|
543
543
|
this.storage = storage;
|
|
544
544
|
this.prefix = `__ns_${namespace}__`;
|
|
545
545
|
}
|
|
546
|
+
async getIndex() {
|
|
547
|
+
const indexValue = await this.storage.getItem(`${this.prefix}__index__`);
|
|
548
|
+
return indexValue ? JSON.parse(indexValue) : [];
|
|
549
|
+
}
|
|
550
|
+
async saveToIndex(key) {
|
|
551
|
+
const index = await this.getIndex();
|
|
552
|
+
if (!index.includes(key)) {
|
|
553
|
+
index.push(key);
|
|
554
|
+
await this.storage.setItem(`${this.prefix}__index__`, JSON.stringify(index));
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
async removeFromIndex(key) {
|
|
558
|
+
const index = await this.getIndex();
|
|
559
|
+
const newIndex = index.filter(k => k !== key);
|
|
560
|
+
if (newIndex.length !== index.length) {
|
|
561
|
+
await this.storage.setItem(`${this.prefix}__index__`, JSON.stringify(newIndex));
|
|
562
|
+
}
|
|
563
|
+
}
|
|
546
564
|
/**
|
|
547
565
|
* Set item in this namespace
|
|
548
566
|
*/
|
|
549
567
|
async setItem(key, value) {
|
|
550
|
-
|
|
568
|
+
await this.storage.setItem(`${this.prefix}${key}`, value);
|
|
569
|
+
await this.saveToIndex(key);
|
|
551
570
|
}
|
|
552
571
|
/**
|
|
553
572
|
* Set item with expiry in this namespace
|
|
554
573
|
*/
|
|
555
574
|
async setItemWithExpiry(key, value, options) {
|
|
556
|
-
|
|
575
|
+
await this.storage.setItemWithExpiry(`${this.prefix}${key}`, value, options);
|
|
576
|
+
await this.saveToIndex(key);
|
|
557
577
|
}
|
|
558
578
|
/**
|
|
559
579
|
* Get item from this namespace
|
|
@@ -565,7 +585,8 @@ class NamespacedStorage {
|
|
|
565
585
|
* Remove item from this namespace
|
|
566
586
|
*/
|
|
567
587
|
async removeItem(key) {
|
|
568
|
-
|
|
588
|
+
await this.storage.removeItem(`${this.prefix}${key}`);
|
|
589
|
+
await this.removeFromIndex(key);
|
|
569
590
|
}
|
|
570
591
|
/**
|
|
571
592
|
* Check if item exists in this namespace
|
|
@@ -577,29 +598,17 @@ class NamespacedStorage {
|
|
|
577
598
|
* Clear all items in this namespace
|
|
578
599
|
*/
|
|
579
600
|
async clearNamespace() {
|
|
580
|
-
const keysToRemove =
|
|
581
|
-
for (let i = 0; i < localStorage.length; i++) {
|
|
582
|
-
const key = localStorage.key(i);
|
|
583
|
-
if (key && key.includes(this.prefix)) {
|
|
584
|
-
keysToRemove.push(key.replace(this.prefix, ''));
|
|
585
|
-
}
|
|
586
|
-
}
|
|
601
|
+
const keysToRemove = await this.getIndex();
|
|
587
602
|
for (const key of keysToRemove) {
|
|
588
|
-
await this.removeItem(key);
|
|
603
|
+
await this.storage.removeItem(`${this.prefix}${key}`);
|
|
589
604
|
}
|
|
605
|
+
await this.storage.removeItem(`${this.prefix}__index__`);
|
|
590
606
|
}
|
|
591
607
|
/**
|
|
592
608
|
* Get all keys in this namespace
|
|
593
609
|
*/
|
|
594
610
|
async keys() {
|
|
595
|
-
|
|
596
|
-
for (let i = 0; i < localStorage.length; i++) {
|
|
597
|
-
const key = localStorage.key(i);
|
|
598
|
-
if (key && key.includes(this.prefix)) {
|
|
599
|
-
keys.push(key.replace(this.prefix, ''));
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
return keys;
|
|
611
|
+
return this.getIndex();
|
|
603
612
|
}
|
|
604
613
|
}
|
|
605
614
|
|
|
@@ -622,7 +631,6 @@ async function compress(data) {
|
|
|
622
631
|
return encoder.encode(data);
|
|
623
632
|
}
|
|
624
633
|
try {
|
|
625
|
-
const encoder = new TextEncoder();
|
|
626
634
|
const stream = new Blob([data]).stream();
|
|
627
635
|
const compressedStream = stream.pipeThrough(new CompressionStream('gzip'));
|
|
628
636
|
const compressedBlob = await new Response(compressedStream).blob();
|
|
@@ -1151,6 +1159,7 @@ class SecureStorage {
|
|
|
1151
1159
|
}
|
|
1152
1160
|
this.removeAllListeners();
|
|
1153
1161
|
this.logger.info('SecureStorage destroyed');
|
|
1162
|
+
SecureStorage.instance = null;
|
|
1154
1163
|
}
|
|
1155
1164
|
}
|
|
1156
1165
|
SecureStorage.instance = null;
|