test: MiniWallet: add P2TR support and use it per default

This commit is contained in:
Sebastian Falbesoner
2021-10-27 11:18:57 +02:00
parent 4a2edf2bf7
commit 041abfebe4
6 changed files with 47 additions and 19 deletions

View File

@@ -5,12 +5,21 @@
"""Encode and decode Bitcoin addresses.
- base58 P2PKH and P2SH addresses.
- bech32 segwit v0 P2WPKH and P2WSH addresses."""
- bech32 segwit v0 P2WPKH and P2WSH addresses.
- bech32m segwit v1 P2TR addresses."""
import enum
import unittest
from .script import hash256, hash160, sha256, CScript, OP_0
from .script import (
CScript,
OP_0,
OP_TRUE,
hash160,
hash256,
sha256,
taproot_construct,
)
from .segwit_addr import encode_segwit_address
from .util import assert_equal
@@ -29,6 +38,21 @@ class AddressType(enum.Enum):
chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
def create_deterministic_address_bcrt1_p2tr_op_true():
"""
Generates a deterministic bech32m address (segwit v1 output) that
can be spent with a witness stack of OP_TRUE and the control block
with internal public key (script-path spending).
Returns a tuple with the generated address and the internal key.
"""
internal_key = (1).to_bytes(32, 'big')
scriptPubKey = taproot_construct(internal_key, [(None, CScript([OP_TRUE]))]).scriptPubKey
address = encode_segwit_address("bcrt", 1, scriptPubKey[2:])
assert_equal(address, 'bcrt1p9yfmy5h72durp7zrhlw9lf7jpwjgvwdg0jr0lqmmjtgg83266lqsekaqka')
return (address, internal_key)
def byte_to_base58(b, version):
result = ''
str = b.hex()