Generate addresses for Account Extended Public Key (specifically bip84_pub
What's the error?
It returns None when hparse function is called.
What's the resolution?
The reason hparse returns None is due to this check. if data is None or prefix is None or not data.startswith(prefix).
The prefix comes out as None. The value for bip84_pub_prefix is not set correctly for LTC. That's why the prefix is None. If you remove this condition check, it will generate the correct LTC addresses nevertheless.
I think the real solution is to update symbol/ltc.py and pass extra kwargs bip84_prv_prefix_hex="04b2430c", bip84_pub_prefix_hex="04B24746", in create_bitcoinish_network function.
Here's my full script if you want to reproduce it.
Dependencies: pycoin==0.92.20230326, tqdm
from pycoin.networks.registry import network_for_netcode
from tqdm import tqdm
# Your BIP32 Account extended public key
ZPUB = "zpub6qXw6cLRkWUQVGgNU1qXhSmGY9fcmvaosAj6NbbMkBZSD1xUhGVyQvyRPEuCizbEn8arDymyAQZzyxRdcjwL9YszG3fZC2cPUg6uiB8ZvuS" # noqa
network = network_for_netcode("LTC")
def derive_bech32_address(zpub, derivation_path):
k = network.parse.bip84_pub(zpub) # k will be None because unless that condition explained above is removed
a = k.subkey_for_path(derivation_path)
bech32_add = network.address.for_p2pkh_wit(a.hash160())
return bech32_add
def generate_ltc_addresses():
addresses = []
COUNT = 100
for i in tqdm(range(COUNT)):
address = derive_bech32_address(ZPUB, f"0/{i}")
addresses.append(address)
with open("ltc_addresses.txt", "w") as f:
for address in addresses:
f.write(f"{address}\n")
if __name__ == "__main__":
generate_ltc_addresses()
What I was trying to do?
Generate addresses for Account Extended Public Key (specifically
bip84_pub
What's the error?
It returns
None
whenhparse
function is called.What's the resolution?
The reason
hparse
returnsNone
is due to this check.if data is None or prefix is None or not data.startswith(prefix)
. Theprefix
comes out asNone
. The value forbip84_pub_prefix
is not set correctly for LTC. That's why the prefix is None. If you remove this condition check, it will generate the correct LTC addresses nevertheless.I think the real solution is to update
symbol/ltc.py
and pass extra kwargsbip84_prv_prefix_hex="04b2430c", bip84_pub_prefix_hex="04B24746",
increate_bitcoinish_network
function.Here's my full script if you want to reproduce it.
Dependencies:
pycoin==0.92.20230326
,tqdm