@hive-p2p/server 1.0.79 → 1.0.80

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hive-p2p/server",
3
- "version": "1.0.79",
3
+ "version": "1.0.80",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -84,46 +84,25 @@ export class Converter {
84
84
  }
85
85
  /** @param {Uint8Array} uint8Array - Uint8Array to convert to string */
86
86
  bytesToHex(uint8Array, minLength = 0) { return Converter.bytesToHex(uint8Array, minLength); }
87
-
88
- // BASE58
89
- /** @param {string} hex - Hex string to convert to base58 */
90
- hexToBase58(hex) {
91
- const num = Converter.hexToBigInt(hex);
92
- let base58 = '';
93
- let n = num;
94
- while (n > 0) {
95
- const remainder = n % BigInt(58);
96
- base58 = base58AlphabetArray[Number(remainder)] + base58;
97
- n = n / BigInt(58);
98
- }
99
-
100
- //const bytes = isNode ? Buffer.from(base58) : new TextEncoder().encode(base58);
101
- const bytes = this.textEncoder.encode(base58);
102
- for (let i = 0; i < bytes.length && bytes[i] === 0; i++) base58 = '1' + base58;
103
87
 
104
- return base58;
105
- }
106
- /** @param {string} base58 - Base58 string to convert to Hex */
107
- base58ToHex(base58, minLength = 0) {
108
- let num = BigInt(0);
109
- const base = BigInt(58);
110
- for (const char of base58) num = num * base + BigInt(base58Alphabet[char]);
111
-
112
- let hex = num.toString(16);
113
- if (hex.length % 2 !== 0) hex = '0' + hex;
114
- if (minLength > 0) hex = hex.padStart(minLength, '0');
115
- return hex;
116
- }
117
- /** @param {string} addressBase58 - Base58 address to convert to Uint8Array(16 bytes) */
118
- addressBase58ToBytes(addressBase58) {
119
- const hex = this.base58ToHex(addressBase58, 32);
120
- return this.hexToBytes(hex);
121
- }
122
- /** @param {Uint8Array} addressUint8Array - Uint8Array(16 bytes) to convert to base58 */
123
- addressBytesToBase58(addressUint8Array) {
124
- const hex = this.bytesToHex(addressUint8Array, 32);
125
- return this.hexToBase58(hex);
126
- }
88
+ // BASE58
89
+ /** @param {number} num - Unsigned integer 4bytes to convert to Base58 string @param {number} [minLength] - Minimum length of the output string, padded with '1', default: 6 */
90
+ static uint32ToB58(num, minLength = 6) {
91
+ if (num === 0) return '1';
92
+
93
+ let result = '';
94
+ while (num > 0) {
95
+ result = base58AlphabetArray[num % 58] + result;
96
+ num = Math.floor(num / 58);
97
+ }
98
+ return result.padStart(minLength, '1');
99
+ }
100
+ /** @param {string} b58 - Base58 string to convert to uint32 */
101
+ static b58ToUint32(b58) {
102
+ let result = 0;
103
+ for (const char of b58) result = result * 58 + base58Alphabet[char];
104
+ return result;
105
+ }
127
106
 
128
107
  // OTHERS
129
108
  /** @param {string} hex - Hex string to convert to BigInt */