secure-ls2 2.1.9 → 2.1.10
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/.eslintrc +186 -186
- package/.github/FUNDING.yml +6 -6
- package/.github/workflows/test.yml +65 -65
- package/.husky/commit-msg +1 -1
- package/.husky/pre-commit +1 -1
- package/.husky/pre-push +3 -3
- package/.prettierrc +8 -8
- package/LICENSE +21 -21
- package/ci-package.json +47 -47
- package/coverage/clover.xml +170 -163
- package/coverage/coverage-final.json +5 -5
- package/coverage/lcov-report/index.html +17 -17
- package/coverage/lcov.info +316 -300
- package/dist/secure-ls2.esm.js +58 -48
- package/dist/secure-ls2.esm.js.map +1 -1
- package/dist/secure-ls2.esm.min.js +2 -2
- package/dist/secure-ls2.esm.min.js.map +1 -1
- package/dist/secure-ls2.js +58 -48
- package/dist/secure-ls2.js.map +1 -1
- package/dist/secure-ls2.min.js +2 -2
- package/dist/secure-ls2.min.js.map +1 -1
- package/eslint.config.mjs +12 -12
- package/example/index.html +42 -42
- package/package.json +13 -13
- package/types/secure-ls.d.ts +58 -58
package/dist/secure-ls2.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* secure-ls2 - v2.1.
|
|
2
|
+
* secure-ls2 - v2.1.10
|
|
3
3
|
* URL - https://github.com/softvar/secure-ls
|
|
4
4
|
*
|
|
5
5
|
* The MIT License (MIT)
|
|
@@ -57,13 +57,20 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
57
57
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
58
58
|
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
59
59
|
/* harmony export */ });
|
|
60
|
+
const BASE64_KEY_STR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
61
|
+
const BASE64_PATTERN = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
60
62
|
const Base64 = {
|
|
61
|
-
_keyStr:
|
|
63
|
+
_keyStr: BASE64_KEY_STR,
|
|
62
64
|
encode: function (e) {
|
|
63
|
-
|
|
65
|
+
const keyStr = this._keyStr;
|
|
66
|
+
const output = [];
|
|
64
67
|
let n, r, i, s, o, u, a;
|
|
65
68
|
let f = 0;
|
|
69
|
+
let outputIndex = 0;
|
|
66
70
|
e = Base64._utf8Encode(e);
|
|
71
|
+
if (keyStr === BASE64_KEY_STR && typeof btoa === 'function') {
|
|
72
|
+
return btoa(e);
|
|
73
|
+
}
|
|
67
74
|
while (f < e.length) {
|
|
68
75
|
n = e.charCodeAt(f++);
|
|
69
76
|
r = e.charCodeAt(f++);
|
|
@@ -77,76 +84,77 @@ const Base64 = {
|
|
|
77
84
|
} else if (isNaN(i)) {
|
|
78
85
|
a = 64;
|
|
79
86
|
}
|
|
80
|
-
|
|
87
|
+
output[outputIndex++] = keyStr.charAt(s) + keyStr.charAt(o) + keyStr.charAt(u) + keyStr.charAt(a);
|
|
81
88
|
}
|
|
82
|
-
return
|
|
89
|
+
return output.join('');
|
|
83
90
|
},
|
|
84
91
|
decode: function (e) {
|
|
85
|
-
|
|
92
|
+
const keyStr = this._keyStr;
|
|
93
|
+
const output = [];
|
|
86
94
|
let n, r, i;
|
|
87
95
|
let s, o, u, a;
|
|
88
96
|
let f = 0;
|
|
97
|
+
let outputIndex = 0;
|
|
89
98
|
e = e.replace(/[^A-Za-z0-9+/=]/g, '');
|
|
99
|
+
if (keyStr === BASE64_KEY_STR && typeof atob === 'function' && BASE64_PATTERN.test(e)) {
|
|
100
|
+
return Base64._utf8Decode(atob(e));
|
|
101
|
+
}
|
|
90
102
|
while (f < e.length) {
|
|
91
|
-
s =
|
|
92
|
-
o =
|
|
93
|
-
u =
|
|
94
|
-
a =
|
|
103
|
+
s = keyStr.indexOf(e.charAt(f++));
|
|
104
|
+
o = keyStr.indexOf(e.charAt(f++));
|
|
105
|
+
u = keyStr.indexOf(e.charAt(f++));
|
|
106
|
+
a = keyStr.indexOf(e.charAt(f++));
|
|
95
107
|
n = s << 2 | o >> 4;
|
|
96
108
|
r = (o & 15) << 4 | u >> 2;
|
|
97
109
|
i = (u & 3) << 6 | a;
|
|
98
|
-
t = t + String.fromCharCode(n);
|
|
99
110
|
if (u !== 64) {
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
t = t + String.fromCharCode(i);
|
|
111
|
+
output[outputIndex++] = a !== 64 ? String.fromCharCode(n, r, i) : String.fromCharCode(n, r);
|
|
112
|
+
} else {
|
|
113
|
+
output[outputIndex++] = String.fromCharCode(n);
|
|
104
114
|
}
|
|
105
115
|
}
|
|
106
|
-
|
|
107
|
-
return t;
|
|
116
|
+
return Base64._utf8Decode(output.join(''));
|
|
108
117
|
},
|
|
109
118
|
_utf8Encode: function (e) {
|
|
110
119
|
e = e.replace(/\r\n/g, '\n');
|
|
111
|
-
|
|
120
|
+
const output = [];
|
|
121
|
+
let outputIndex = 0;
|
|
112
122
|
for (let n = 0; n < e.length; n++) {
|
|
113
123
|
let r = e.charCodeAt(n);
|
|
114
124
|
if (r < 128) {
|
|
115
|
-
|
|
125
|
+
output[outputIndex++] = e.charAt(n);
|
|
116
126
|
} else if (r > 127 && r < 2048) {
|
|
117
|
-
|
|
118
|
-
t += String.fromCharCode(r & 63 | 128);
|
|
127
|
+
output[outputIndex++] = String.fromCharCode(r >> 6 | 192, r & 63 | 128);
|
|
119
128
|
} else {
|
|
120
|
-
|
|
121
|
-
t += String.fromCharCode(r >> 6 & 63 | 128);
|
|
122
|
-
t += String.fromCharCode(r & 63 | 128);
|
|
129
|
+
output[outputIndex++] = String.fromCharCode(r >> 12 | 224, r >> 6 & 63 | 128, r & 63 | 128);
|
|
123
130
|
}
|
|
124
131
|
}
|
|
125
|
-
return
|
|
132
|
+
return output.join('');
|
|
126
133
|
},
|
|
127
134
|
_utf8Decode: function (e) {
|
|
128
|
-
|
|
135
|
+
const output = [];
|
|
129
136
|
let n = 0;
|
|
130
137
|
let r, c2, c3;
|
|
138
|
+
let outputIndex = 0;
|
|
131
139
|
|
|
132
140
|
// r = c2 = 0;
|
|
133
141
|
while (n < e.length) {
|
|
134
142
|
r = e.charCodeAt(n);
|
|
135
143
|
if (r < 128) {
|
|
136
|
-
|
|
144
|
+
output[outputIndex++] = e.charAt(n);
|
|
137
145
|
n++;
|
|
138
146
|
} else if (r > 191 && r < 224) {
|
|
139
147
|
c2 = e.charCodeAt(n + 1);
|
|
140
|
-
|
|
148
|
+
output[outputIndex++] = String.fromCharCode((r & 31) << 6 | c2 & 63);
|
|
141
149
|
n += 2;
|
|
142
150
|
} else {
|
|
143
151
|
c2 = e.charCodeAt(n + 1);
|
|
144
152
|
c3 = e.charCodeAt(n + 2);
|
|
145
|
-
|
|
153
|
+
output[outputIndex++] = String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
|
|
146
154
|
n += 3;
|
|
147
155
|
}
|
|
148
156
|
}
|
|
149
|
-
return
|
|
157
|
+
return output.join('');
|
|
150
158
|
}
|
|
151
159
|
};
|
|
152
160
|
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Base64);
|
|
@@ -234,7 +242,7 @@ class SecureLS {
|
|
|
234
242
|
this.init();
|
|
235
243
|
}
|
|
236
244
|
init() {
|
|
237
|
-
|
|
245
|
+
const metaData = this.getMetaData();
|
|
238
246
|
this._isBase64 = this._isBase64EncryptionType();
|
|
239
247
|
this._isAES = this._isAESEncryptionType();
|
|
240
248
|
this._isDES = this._isDESEncryptionType();
|
|
@@ -263,22 +271,23 @@ class SecureLS {
|
|
|
263
271
|
_isDataCompressionEnabled() {
|
|
264
272
|
return this.config.isCompression;
|
|
265
273
|
}
|
|
274
|
+
_isDataEncryptionEnabled() {
|
|
275
|
+
return this._isAES || this._isDES || this._isRabbit || this._isRC4;
|
|
276
|
+
}
|
|
266
277
|
getEncryptionSecret(key) {
|
|
267
|
-
|
|
268
|
-
let obj = _utils__WEBPACK_IMPORTED_MODULE_2__["default"].getObjectFromKey(metaData.keys, key);
|
|
269
|
-
if (!obj) {
|
|
278
|
+
if (!this._isDataEncryptionEnabled()) {
|
|
270
279
|
return;
|
|
271
280
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
} else {
|
|
280
|
-
this.encryptionSecret = this.config.encryptionSecret || obj.s || '';
|
|
281
|
+
const metaData = this.getMetaData();
|
|
282
|
+
const obj = _utils__WEBPACK_IMPORTED_MODULE_2__["default"].getObjectFromKey(metaData.keys, key);
|
|
283
|
+
if (typeof this.config.encryptionSecret === 'undefined') {
|
|
284
|
+
this.encryptionSecret = obj.s;
|
|
285
|
+
if (!this.encryptionSecret) {
|
|
286
|
+
this.encryptionSecret = _utils__WEBPACK_IMPORTED_MODULE_2__["default"].generateSecretKey();
|
|
287
|
+
this.setMetaData();
|
|
281
288
|
}
|
|
289
|
+
} else {
|
|
290
|
+
this.encryptionSecret = this.config.encryptionSecret || obj.s || '';
|
|
282
291
|
}
|
|
283
292
|
}
|
|
284
293
|
getEncryptionType() {
|
|
@@ -292,7 +301,7 @@ class SecureLS {
|
|
|
292
301
|
this.storage.setItem(key, data);
|
|
293
302
|
}
|
|
294
303
|
setMetaData() {
|
|
295
|
-
|
|
304
|
+
const dataToStore = this.processData({
|
|
296
305
|
keys: this.allKeys
|
|
297
306
|
}, true);
|
|
298
307
|
|
|
@@ -343,7 +352,7 @@ class SecureLS {
|
|
|
343
352
|
|
|
344
353
|
// PUBLIC APIs
|
|
345
354
|
getAllKeys() {
|
|
346
|
-
|
|
355
|
+
const data = this.getMetaData();
|
|
347
356
|
return _utils__WEBPACK_IMPORTED_MODULE_2__["default"].extractKeyNames(data) || [];
|
|
348
357
|
}
|
|
349
358
|
get(key, isAllKeysData) {
|
|
@@ -421,8 +430,8 @@ class SecureLS {
|
|
|
421
430
|
this.storage.removeItem(key);
|
|
422
431
|
}
|
|
423
432
|
removeAll() {
|
|
424
|
-
|
|
425
|
-
for (let i = 0; i <
|
|
433
|
+
const keys = this.getAllKeys();
|
|
434
|
+
for (let i = 0, length = keys.length; i < length; i++) {
|
|
426
435
|
this.storage.removeItem(keys[i]);
|
|
427
436
|
}
|
|
428
437
|
this.storage.removeItem(this.metaKey);
|
|
@@ -617,7 +626,8 @@ const utils = {
|
|
|
617
626
|
}) => k);
|
|
618
627
|
},
|
|
619
628
|
isKeyPresent: (allKeys = [], key) => {
|
|
620
|
-
|
|
629
|
+
const keyName = String(key);
|
|
630
|
+
return allKeys.some(item => String(item.k) === keyName);
|
|
621
631
|
},
|
|
622
632
|
removeFromKeysList: (allKeys = [], key) => {
|
|
623
633
|
const index = allKeys.findIndex(item => item.k === key);
|