I have a script that generates a segwit v1 taproot compliant address and private key. The script currently generates a regtest address but with minor tweaks it spits out a mainnet address. I think the only difference between a regtest and mainnet address is that for regtest you remove the "bc" from the beginning of the string and replace it with "bcrt." Private keys for regtest and mainnet appear to be the same. This is my script:
def gen_segwit_v1():
privkey, pubkey = generate_bip340_key_pair()
program = pubkey.get_bytes()
version = 0x01
address = program_to_witness(version, program)
return privkey, pubkey, address
It creates a bitcoin segwit v1 wallet for usage in taproot transactions. The problem is that my script relies on generate_bip340_key_pair()
and program_to_witness()
which I copied from https://github.com/bitcoinops/taproot-workshop/blob/master/test_framework/address.py.
This is what program_to_witness()
looks like:
def program_to_witness(version, program, main=False):
if (type(program) is str):
program = hex_str_to_bytes(program)
assert 0 <= version <= 16
assert 2 <= len(program) <= 40
assert version > 0 or len(program) in [20, 32]
return segwit_addr.encode_segwit_address("bc" if main else "bcrt", version, program)
I want to generate a testnet Private Key and a testnet segwit v1 address. I think the private keys for testnet and mainnet are different. I don't know the technical derivation formula for bitcoin private keys, but for some reason, all of the testnet private keys I've generated start with a "c" and all of the mainnet keys I've generated start with a "K" or "L" . I'm guessing the formula is different for testnet and mainnet private keys.
So in conclusion, is there a simple way to generate a testnet private key and get the testnet taproot compliant segwit v1 address?