我正在尝试将一个大整数转换为 base58 检查版本,但这适用于小于 115792089237316195423570985008687907852837564279074904382605163141518161494337 且大于 1 的特定范围,但我想转换一个大于 1 的非常大的整数 python 当我尝试大整数时,我得到无效的私钥错误
这是我试过的代码
from bitcoin import *
import base58
n = 1157920892373161954235709850086879078532699846656405640394575840079099999999999999
def getPrivateKey(my_integer):
# Convert the input integer to a 32-byte binary string
my_binary_string = my_integer.to_bytes(128, byteorder='big')
# Add the prefix byte and checksum to the binary string
my_bytes_with_prefix = b"\x80" + my_binary_string
my_bytes_with_checksum = my_bytes_with_prefix + bin_sha256(bin_sha256(my_bytes_with_prefix))[:4]
# Encode the binary string as a private key in base58 check format
my_private_key = base58.b58encode(my_bytes_with_checksum)
print(my_integer)
print(type(my_integer))
# Convert the public key to an uncompressed address and a compressed address
#my_integer = 11579208923731619542357098500868790785283756427907490438260516314151816149433
print("l = ",my_integer)
public_key = privtopub(my_integer)
uncompressed_address = pubtoaddr(public_key)
compressed_public_key = compress(public_key)
compressed_address = pubtoaddr(compressed_public_key)
# Write the private key, uncompressed address, and compressed address to a file
with open("file.txt", "a") as file :
file.write('My uncompressed address: ' + uncompressed_address + ';')
file.write('My compressed address: ' + compressed_address + ';')
file.write('My private key: ' + my_private_key.decode() + '\n')
#print("Number = ", my_integer)
#print("Private key = ",my_private_key.decode())
file.flush()
return my_private_key
a = getPrivateKey(n)
我得到的错误
raise Exception("Invalid privkey")
Exception: Invalid privkey
有什么办法可以做到这一点。或使用任何其他图书馆或任何东西