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
package/dist/secure-ls2.js
CHANGED
|
@@ -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
|
*
|
|
@@ -201,15 +201,38 @@ const encryptors = {
|
|
|
201
201
|
[_constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.RABBIT]: (crypto_js_rabbit__WEBPACK_IMPORTED_MODULE_4___default()),
|
|
202
202
|
[_constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.RC4]: (crypto_js_rc4__WEBPACK_IMPORTED_MODULE_5___default())
|
|
203
203
|
};
|
|
204
|
+
const createMemoryStorage = () => {
|
|
205
|
+
const store = {};
|
|
206
|
+
return {
|
|
207
|
+
getItem: key => Object.prototype.hasOwnProperty.call(store, key) ? store[key] : null,
|
|
208
|
+
setItem: (key, value) => {
|
|
209
|
+
store[key] = String(value);
|
|
210
|
+
},
|
|
211
|
+
removeItem: key => {
|
|
212
|
+
delete store[key];
|
|
213
|
+
},
|
|
214
|
+
clear: () => {
|
|
215
|
+
for (const key of Object.keys(store)) {
|
|
216
|
+
delete store[key];
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
key: index => Object.keys(store)[index] || null,
|
|
220
|
+
get length() {
|
|
221
|
+
return Object.keys(store).length;
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
};
|
|
204
225
|
class SecureLS {
|
|
205
226
|
constructor({
|
|
206
227
|
encryptionSecret = '',
|
|
207
228
|
encryptionNamespace = '',
|
|
208
229
|
isCompression = true,
|
|
209
230
|
encodingType = _constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.BASE64,
|
|
210
|
-
storage
|
|
231
|
+
storage,
|
|
211
232
|
metaKey = _constants__WEBPACK_IMPORTED_MODULE_0__["default"].metaKey
|
|
212
233
|
} = {}) {
|
|
234
|
+
const resolvedStorage = storage || (typeof localStorage !== 'undefined' ? localStorage : createMemoryStorage());
|
|
235
|
+
|
|
213
236
|
// Assign libraries and utilities
|
|
214
237
|
Object.assign(this, {
|
|
215
238
|
_name: 'secure-ls',
|
|
@@ -231,11 +254,11 @@ class SecureLS {
|
|
|
231
254
|
encryptionNamespace,
|
|
232
255
|
isCompression,
|
|
233
256
|
encodingType: encodingType.toLowerCase(),
|
|
234
|
-
storage,
|
|
257
|
+
storage: resolvedStorage,
|
|
235
258
|
metaKey
|
|
236
259
|
};
|
|
237
260
|
this.encryptionSecret = encryptionSecret;
|
|
238
|
-
this.storage =
|
|
261
|
+
this.storage = resolvedStorage;
|
|
239
262
|
this.metaKey = metaKey;
|
|
240
263
|
|
|
241
264
|
// Initialize the class
|
|
@@ -401,7 +424,7 @@ class SecureLS {
|
|
|
401
424
|
this.getEncryptionSecret(key);
|
|
402
425
|
|
|
403
426
|
// add key(s) to Array if not already added, only for keys other than meta key
|
|
404
|
-
if (
|
|
427
|
+
if (String(key) !== String(this.getMetaKey())) {
|
|
405
428
|
if (!_utils__WEBPACK_IMPORTED_MODULE_2__["default"].isKeyPresent(this.allKeys, key)) {
|
|
406
429
|
this.allKeys.push({
|
|
407
430
|
k: key,
|
|
@@ -419,7 +442,7 @@ class SecureLS {
|
|
|
419
442
|
_utils__WEBPACK_IMPORTED_MODULE_2__["default"].warn(_constants__WEBPACK_IMPORTED_MODULE_0__["default"].WarningEnum.KEY_NOT_PROVIDED);
|
|
420
443
|
return;
|
|
421
444
|
}
|
|
422
|
-
if (key === this.
|
|
445
|
+
if (key === this.getMetaKey() && this.getAllKeys().length) {
|
|
423
446
|
_utils__WEBPACK_IMPORTED_MODULE_2__["default"].warn(_constants__WEBPACK_IMPORTED_MODULE_0__["default"].WarningEnum.META_KEY_REMOVE);
|
|
424
447
|
return;
|
|
425
448
|
}
|
|
@@ -434,7 +457,7 @@ class SecureLS {
|
|
|
434
457
|
for (let i = 0, length = keys.length; i < length; i++) {
|
|
435
458
|
this.storage.removeItem(keys[i]);
|
|
436
459
|
}
|
|
437
|
-
this.storage.removeItem(this.
|
|
460
|
+
this.storage.removeItem(this.getMetaKey());
|
|
438
461
|
this.resetAllKeys();
|
|
439
462
|
}
|
|
440
463
|
clear() {
|
|
@@ -465,6 +488,14 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
465
488
|
|
|
466
489
|
let CryptoJSWordArray = {
|
|
467
490
|
random: function (nBytes) {
|
|
491
|
+
const cryptoObj = typeof globalThis !== 'undefined' ? globalThis.crypto : undefined;
|
|
492
|
+
if (cryptoObj && typeof cryptoObj.getRandomValues === 'function') {
|
|
493
|
+
const wordsCount = Math.ceil(nBytes / 4);
|
|
494
|
+
const uint32Arr = new Uint32Array(wordsCount);
|
|
495
|
+
cryptoObj.getRandomValues(uint32Arr);
|
|
496
|
+
const words = Array.from(uint32Arr);
|
|
497
|
+
return new CryptoJSWordArray.Set(words, nBytes);
|
|
498
|
+
}
|
|
468
499
|
let words = [];
|
|
469
500
|
let r = function (mw) {
|
|
470
501
|
let mz = 0x3ade68b1;
|
|
@@ -574,6 +605,18 @@ const enc = {
|
|
|
574
605
|
_Utf8: {
|
|
575
606
|
stringify: wordArray => {
|
|
576
607
|
try {
|
|
608
|
+
const Decoder = typeof TextDecoder !== 'undefined' ? TextDecoder : typeof globalThis !== 'undefined' && globalThis.TextDecoder ? globalThis.TextDecoder : undefined;
|
|
609
|
+
if (Decoder) {
|
|
610
|
+
const sigBytes = wordArray.sigBytes;
|
|
611
|
+
const words = wordArray.words;
|
|
612
|
+
const bytes = new Uint8Array(sigBytes);
|
|
613
|
+
for (let i = 0; i < sigBytes; i++) {
|
|
614
|
+
bytes[i] = words[i >>> 2] >>> 24 - i % 4 * 8 & 0xff;
|
|
615
|
+
}
|
|
616
|
+
return new Decoder('utf-8', {
|
|
617
|
+
fatal: true
|
|
618
|
+
}).decode(bytes);
|
|
619
|
+
}
|
|
577
620
|
return decodeURIComponent(escape(enc.Latin1.stringify(wordArray)));
|
|
578
621
|
} catch (err) {
|
|
579
622
|
throw new Error('Malformed UTF-8 data', err);
|
|
@@ -5517,13 +5560,18 @@ var __webpack_exports__ = {};
|
|
|
5517
5560
|
\**********************/
|
|
5518
5561
|
__webpack_require__.r(__webpack_exports__);
|
|
5519
5562
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
5563
|
+
/* harmony export */ SecureLS: () => (/* reexport safe */ _SecureLS__WEBPACK_IMPORTED_MODULE_0__.SecureLS),
|
|
5520
5564
|
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
5521
5565
|
/* harmony export */ });
|
|
5522
5566
|
/* harmony import */ var _SecureLS__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./SecureLS */ "./src/SecureLS.js");
|
|
5523
5567
|
|
|
5568
|
+
_SecureLS__WEBPACK_IMPORTED_MODULE_0__.SecureLS.default = _SecureLS__WEBPACK_IMPORTED_MODULE_0__.SecureLS;
|
|
5569
|
+
_SecureLS__WEBPACK_IMPORTED_MODULE_0__.SecureLS.SecureLS = _SecureLS__WEBPACK_IMPORTED_MODULE_0__.SecureLS;
|
|
5524
5570
|
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (_SecureLS__WEBPACK_IMPORTED_MODULE_0__.SecureLS);
|
|
5571
|
+
|
|
5525
5572
|
})();
|
|
5526
5573
|
|
|
5574
|
+
__webpack_exports__ = __webpack_exports__["default"];
|
|
5527
5575
|
/******/ return __webpack_exports__;
|
|
5528
5576
|
/******/ })()
|
|
5529
5577
|
;
|