secure-ls2 2.1.11 → 2.2.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/README.md +3 -3
- package/dist/secure-ls2.esm.min.mjs +33 -0
- package/dist/secure-ls2.esm.min.mjs.map +1 -0
- package/dist/{secure-ls2.esm.js → secure-ls2.esm.mjs} +58 -10
- package/dist/secure-ls2.esm.mjs.map +1 -0
- package/dist/secure-ls2.js +56 -8
- package/dist/secure-ls2.js.map +1 -1
- package/dist/secure-ls2.min.js +3 -3
- package/dist/secure-ls2.min.js.map +1 -1
- package/package.json +21 -11
- package/types/secure-ls.d.mts +60 -0
- package/types/secure-ls.d.ts +3 -0
- package/.eslintrc +0 -186
- package/.github/FUNDING.yml +0 -6
- package/.github/workflows/test.yml +0 -65
- package/.husky/commit-msg +0 -1
- package/.husky/pre-commit +0 -1
- package/.husky/pre-push +0 -3
- package/.prettierrc +0 -8
- package/CODE_OF_CONDUCT.md +0 -76
- package/CONTRIBUTING.md +0 -46
- package/babel.config.js +0 -3
- package/ci-package.json +0 -47
- package/commitlint.config.js +0 -12
- package/coverage/clover.xml +0 -276
- package/coverage/coverage-final.json +0 -9
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -131
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov.info +0 -549
- package/dist/secure-ls.js +0 -5640
- package/dist/secure-ls.js.map +0 -1
- package/dist/secure-ls.min.js +0 -2559
- package/dist/secure-ls.min.js.map +0 -1
- package/dist/secure-ls2.esm.js.map +0 -1
- package/dist/secure-ls2.esm.min.js +0 -33
- package/dist/secure-ls2.esm.min.js.map +0 -1
- package/eslint.config.mjs +0 -12
- package/example/aes-compressed-realm.js +0 -28
- package/example/aes-compressed.js +0 -12
- package/example/aes-uncompressed.js +0 -12
- package/example/base64-compressed.js +0 -12
- package/example/custom-storage.js +0 -29
- package/example/des-compressed.js +0 -12
- package/example/des-uncompressed.js +0 -12
- package/example/index.html +0 -42
- package/example/only-base64.js +0 -12
- package/example/only-compressed.js +0 -12
- package/example/rabbit-compressed.js +0 -12
- package/example/rabbit-uncompressed.js +0 -12
- package/example/rc4-compressed.js +0 -12
- package/example/rc4-uncompressed.js +0 -12
- package/example/sessionStorage.js +0 -13
- package/example/standard.js +0 -13
- package/example/vendor/screenlog.min.js +0 -115
- package/jest.config.js +0 -10
- package/screenshot.png +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* secure-ls2 - v2.1
|
|
3
|
-
* URL - https://github.com/
|
|
2
|
+
* secure-ls2 - v2.2.1
|
|
3
|
+
* URL - https://github.com/wuc656/secure-ls
|
|
4
4
|
*
|
|
5
5
|
* The MIT License (MIT)
|
|
6
6
|
*
|
|
@@ -184,15 +184,38 @@ const encryptors = {
|
|
|
184
184
|
[_constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.RABBIT]: (crypto_js_rabbit__WEBPACK_IMPORTED_MODULE_4___default()),
|
|
185
185
|
[_constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.RC4]: (crypto_js_rc4__WEBPACK_IMPORTED_MODULE_5___default())
|
|
186
186
|
};
|
|
187
|
+
const createMemoryStorage = () => {
|
|
188
|
+
const store = {};
|
|
189
|
+
return {
|
|
190
|
+
getItem: key => Object.prototype.hasOwnProperty.call(store, key) ? store[key] : null,
|
|
191
|
+
setItem: (key, value) => {
|
|
192
|
+
store[key] = String(value);
|
|
193
|
+
},
|
|
194
|
+
removeItem: key => {
|
|
195
|
+
delete store[key];
|
|
196
|
+
},
|
|
197
|
+
clear: () => {
|
|
198
|
+
for (const key of Object.keys(store)) {
|
|
199
|
+
delete store[key];
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
key: index => Object.keys(store)[index] || null,
|
|
203
|
+
get length() {
|
|
204
|
+
return Object.keys(store).length;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
};
|
|
187
208
|
class SecureLS {
|
|
188
209
|
constructor({
|
|
189
210
|
encryptionSecret = '',
|
|
190
211
|
encryptionNamespace = '',
|
|
191
212
|
isCompression = true,
|
|
192
213
|
encodingType = _constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.BASE64,
|
|
193
|
-
storage
|
|
214
|
+
storage,
|
|
194
215
|
metaKey = _constants__WEBPACK_IMPORTED_MODULE_0__["default"].metaKey
|
|
195
216
|
} = {}) {
|
|
217
|
+
const resolvedStorage = storage || (typeof localStorage !== 'undefined' ? localStorage : createMemoryStorage());
|
|
218
|
+
|
|
196
219
|
// Assign libraries and utilities
|
|
197
220
|
Object.assign(this, {
|
|
198
221
|
_name: 'secure-ls',
|
|
@@ -214,11 +237,11 @@ class SecureLS {
|
|
|
214
237
|
encryptionNamespace,
|
|
215
238
|
isCompression,
|
|
216
239
|
encodingType: encodingType.toLowerCase(),
|
|
217
|
-
storage,
|
|
240
|
+
storage: resolvedStorage,
|
|
218
241
|
metaKey
|
|
219
242
|
};
|
|
220
243
|
this.encryptionSecret = encryptionSecret;
|
|
221
|
-
this.storage =
|
|
244
|
+
this.storage = resolvedStorage;
|
|
222
245
|
this.metaKey = metaKey;
|
|
223
246
|
|
|
224
247
|
// Initialize the class
|
|
@@ -384,7 +407,7 @@ class SecureLS {
|
|
|
384
407
|
this.getEncryptionSecret(key);
|
|
385
408
|
|
|
386
409
|
// add key(s) to Array if not already added, only for keys other than meta key
|
|
387
|
-
if (
|
|
410
|
+
if (String(key) !== String(this.getMetaKey())) {
|
|
388
411
|
if (!_utils__WEBPACK_IMPORTED_MODULE_2__["default"].isKeyPresent(this.allKeys, key)) {
|
|
389
412
|
this.allKeys.push({
|
|
390
413
|
k: key,
|
|
@@ -402,7 +425,7 @@ class SecureLS {
|
|
|
402
425
|
_utils__WEBPACK_IMPORTED_MODULE_2__["default"].warn(_constants__WEBPACK_IMPORTED_MODULE_0__["default"].WarningEnum.KEY_NOT_PROVIDED);
|
|
403
426
|
return;
|
|
404
427
|
}
|
|
405
|
-
if (key === this.
|
|
428
|
+
if (key === this.getMetaKey() && this.getAllKeys().length) {
|
|
406
429
|
_utils__WEBPACK_IMPORTED_MODULE_2__["default"].warn(_constants__WEBPACK_IMPORTED_MODULE_0__["default"].WarningEnum.META_KEY_REMOVE);
|
|
407
430
|
return;
|
|
408
431
|
}
|
|
@@ -417,7 +440,7 @@ class SecureLS {
|
|
|
417
440
|
for (let i = 0, length = keys.length; i < length; i++) {
|
|
418
441
|
this.storage.removeItem(keys[i]);
|
|
419
442
|
}
|
|
420
|
-
this.storage.removeItem(this.
|
|
443
|
+
this.storage.removeItem(this.getMetaKey());
|
|
421
444
|
this.resetAllKeys();
|
|
422
445
|
}
|
|
423
446
|
clear() {
|
|
@@ -447,6 +470,14 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
447
470
|
|
|
448
471
|
let CryptoJSWordArray = {
|
|
449
472
|
random: function (nBytes) {
|
|
473
|
+
const cryptoObj = typeof globalThis !== 'undefined' ? globalThis.crypto : undefined;
|
|
474
|
+
if (cryptoObj && typeof cryptoObj.getRandomValues === 'function') {
|
|
475
|
+
const wordsCount = Math.ceil(nBytes / 4);
|
|
476
|
+
const uint32Arr = new Uint32Array(wordsCount);
|
|
477
|
+
cryptoObj.getRandomValues(uint32Arr);
|
|
478
|
+
const words = Array.from(uint32Arr);
|
|
479
|
+
return new CryptoJSWordArray.Set(words, nBytes);
|
|
480
|
+
}
|
|
450
481
|
let words = [];
|
|
451
482
|
let r = function (mw) {
|
|
452
483
|
let mz = 0x3ade68b1;
|
|
@@ -554,6 +585,18 @@ const enc = {
|
|
|
554
585
|
_Utf8: {
|
|
555
586
|
stringify: wordArray => {
|
|
556
587
|
try {
|
|
588
|
+
const Decoder = typeof TextDecoder !== 'undefined' ? TextDecoder : typeof globalThis !== 'undefined' && globalThis.TextDecoder ? globalThis.TextDecoder : undefined;
|
|
589
|
+
if (Decoder) {
|
|
590
|
+
const sigBytes = wordArray.sigBytes;
|
|
591
|
+
const words = wordArray.words;
|
|
592
|
+
const bytes = new Uint8Array(sigBytes);
|
|
593
|
+
for (let i = 0; i < sigBytes; i++) {
|
|
594
|
+
bytes[i] = words[i >>> 2] >>> 24 - i % 4 * 8 & 0xff;
|
|
595
|
+
}
|
|
596
|
+
return new Decoder('utf-8', {
|
|
597
|
+
fatal: true
|
|
598
|
+
}).decode(bytes);
|
|
599
|
+
}
|
|
557
600
|
return decodeURIComponent(escape(enc.Latin1.stringify(wordArray)));
|
|
558
601
|
} catch (err) {
|
|
559
602
|
throw new Error('Malformed UTF-8 data', err);
|
|
@@ -5495,14 +5538,19 @@ var __webpack_exports__ = {};
|
|
|
5495
5538
|
\**********************/
|
|
5496
5539
|
__webpack_require__.r(__webpack_exports__);
|
|
5497
5540
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
5541
|
+
/* harmony export */ SecureLS: () => (/* reexport safe */ _SecureLS__WEBPACK_IMPORTED_MODULE_0__.SecureLS),
|
|
5498
5542
|
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
5499
5543
|
/* harmony export */ });
|
|
5500
5544
|
/* harmony import */ var _SecureLS__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./SecureLS */ "./src/SecureLS.js");
|
|
5501
5545
|
|
|
5546
|
+
_SecureLS__WEBPACK_IMPORTED_MODULE_0__.SecureLS.default = _SecureLS__WEBPACK_IMPORTED_MODULE_0__.SecureLS;
|
|
5547
|
+
_SecureLS__WEBPACK_IMPORTED_MODULE_0__.SecureLS.SecureLS = _SecureLS__WEBPACK_IMPORTED_MODULE_0__.SecureLS;
|
|
5502
5548
|
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (_SecureLS__WEBPACK_IMPORTED_MODULE_0__.SecureLS);
|
|
5549
|
+
|
|
5503
5550
|
})();
|
|
5504
5551
|
|
|
5552
|
+
const __webpack_exports__SecureLS = __webpack_exports__.SecureLS;
|
|
5505
5553
|
const __webpack_exports__default = __webpack_exports__["default"];
|
|
5506
|
-
export { __webpack_exports__default as default };
|
|
5554
|
+
export { __webpack_exports__SecureLS as SecureLS, __webpack_exports__default as default };
|
|
5507
5555
|
|
|
5508
|
-
//# sourceMappingURL=secure-ls2.esm.
|
|
5556
|
+
//# sourceMappingURL=secure-ls2.esm.mjs.map
|