Saturday, December 2, 2023

python – How do I generate a testnet segwit v1 taproot compliant bitcoin tackle?


I’ve a script that generates a segwit v1 taproot compliant tackle and personal key. The script at the moment generates a regtest tackle however with minor tweaks it spits out a mainnet tackle. I feel the one distinction between a regtest and mainnet tackle is that for regtest you take away the “bc” from the start of the string and exchange it with “bcrt.” Personal keys for regtest and mainnet seem like the identical. That is my script:

def gen_segwit_v1():
    privkey, pubkey = generate_bip340_key_pair()
    program = pubkey.get_bytes()
    model = 0x01
    tackle = program_to_witness(model, program)
    return privkey, pubkey, tackle

It creates a bitcoin segwit v1 pockets for utilization in taproot transactions. The issue is that my script depends on generate_bip340_key_pair() and program_to_witness() which I copied from https://github.com/bitcoinops/taproot-workshop/blob/grasp/test_framework/tackle.py.

That is what program_to_witness() seems to be like:

def program_to_witness(model, program, foremost=False):
    if (kind(program) is str):
        program = hex_str_to_bytes(program)
    assert 0 <= model <= 16
    assert 2 <= len(program) <= 40
    assert model > 0 or len(program) in [20, 32]
    return segwit_addr.encode_segwit_address("bc" if foremost else "bcrt", model, program)

I wish to generate a testnet Personal Key and a testnet segwit v1 tackle. I feel the non-public keys for testnet and mainnet are completely different. I do not know the technical derivation formulation for bitcoin non-public keys, however for some purpose, the entire testnet non-public keys I’ve generated begin with a “c” and the entire mainnet keys I’ve generated begin with a “Okay” or “L” . I am guessing the formulation is completely different for testnet and mainnet non-public keys.

So in conclusion, is there a easy strategy to generate a testnet non-public key and get the testnet taproot compliant segwit v1 tackle?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles