Fix Base58 padding for string representation of binary data (#4527).
This commit is contained in:
parent
f6d155c820
commit
ccac24a5b0
@ -42,12 +42,21 @@ const BN_58 = BigInt(58);
|
||||
* Encode %%value%% as a Base58-encoded string.
|
||||
*/
|
||||
export function encodeBase58(_value: BytesLike): string {
|
||||
let value = toBigInt(getBytes(_value));
|
||||
const bytes = getBytes(_value);
|
||||
|
||||
let value = toBigInt(bytes);
|
||||
let result = "";
|
||||
while (value) {
|
||||
result = Alphabet[Number(value % BN_58)] + result;
|
||||
value /= BN_58;
|
||||
}
|
||||
|
||||
// Account for leading padding zeros
|
||||
for (let i = 0; i < bytes.length; i++) {
|
||||
if (bytes[i]) { break; }
|
||||
result = Alphabet[0] + result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user