def METHOD_NAME(b):
    """Encode bytes to a base58-encoded string"""
    # Convert big-endian bytes to integer
    n = int("0x0" + hexlify(b).decode("utf8"), 16)
    # Divide that integer into bas58
    res = []
    while n > 0:
        n, r = divmod(n, 58)
        res.append(B58_DIGITS[r])
    res = "".join(res[::-1])
    # Encode leading zeros as base58 zeros
    czero = 0
    pad = 0
    for c in b:
        if c == czero:
            pad += 1
        else:
            break
    return B58_DIGITS[0] * pad + res