@hive-p2p/server 1.0.79 → 1.0.81
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/core/config.mjs +1 -1
- package/package.json +1 -1
- package/services/converter.mjs +18 -39
package/core/config.mjs
CHANGED
package/package.json
CHANGED
package/services/converter.mjs
CHANGED
|
@@ -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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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 */
|