secure-ls2 2.2.0 → 2.2.2

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.
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * secure-ls2 - v2.2.0
3
- * URL - https://github.com/softvar/secure-ls
2
+ * secure-ls2 - v2.2.2
3
+ * URL - https://github.com/wuc656/secure-ls
4
4
  *
5
5
  * The MIT License (MIT)
6
6
  *
@@ -470,6 +470,14 @@ __webpack_require__.r(__webpack_exports__);
470
470
 
471
471
  let CryptoJSWordArray = {
472
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
+ }
473
481
  let words = [];
474
482
  let r = function (mw) {
475
483
  let mz = 0x3ade68b1;
@@ -577,6 +585,18 @@ const enc = {
577
585
  _Utf8: {
578
586
  stringify: wordArray => {
579
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
+ }
580
600
  return decodeURIComponent(escape(enc.Latin1.stringify(wordArray)));
581
601
  } catch (err) {
582
602
  throw new Error('Malformed UTF-8 data', err);