@ecency/render-helper 2.5.20 → 2.5.21

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,7 +1,6 @@
1
1
  import { DOMParser as DOMParser$1, XMLSerializer } from '@xmldom/xmldom';
2
2
  import he2 from 'he';
3
3
  import xss from 'xss';
4
- import multihash from 'multihashes';
5
4
  import querystring from 'querystring';
6
5
  import { LRUCache } from 'lru-cache';
7
6
  import { Remarkable } from 'remarkable';
@@ -542,10 +541,35 @@ function removeChildNodes(node) {
542
541
  }
543
542
  var proxyBase = "https://i.ecency.com";
544
543
  var urlHashCache = new LRUCache({ max: 500 });
544
+ var BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
545
+ function base58Encode(bytes) {
546
+ if (bytes.length === 0) return "";
547
+ const digits = [0];
548
+ for (let i = 0; i < bytes.length; i++) {
549
+ let carry = bytes[i];
550
+ for (let j = 0; j < digits.length; j++) {
551
+ carry += digits[j] << 8;
552
+ digits[j] = carry % 58;
553
+ carry = carry / 58 | 0;
554
+ }
555
+ while (carry > 0) {
556
+ digits.push(carry % 58);
557
+ carry = carry / 58 | 0;
558
+ }
559
+ }
560
+ let out = "";
561
+ for (let k = 0; k < bytes.length && bytes[k] === 0; k++) out += BASE58_ALPHABET[0];
562
+ for (let q = digits.length - 1; q >= 0; q--) out += BASE58_ALPHABET[digits[q]];
563
+ return out;
564
+ }
565
+ function utf8Bytes(url) {
566
+ if (typeof TextEncoder !== "undefined") return new TextEncoder().encode(url);
567
+ return Uint8Array.from(Buffer.from(url, "utf8"));
568
+ }
545
569
  function getUrlHash(url) {
546
570
  const cached = urlHashCache.get(url);
547
571
  if (cached) return cached;
548
- const hash = multihash.toB58String(Buffer.from(url));
572
+ const hash = base58Encode(utf8Bytes(url));
549
573
  urlHashCache.set(url, hash);
550
574
  return hash;
551
575
  }