Skip to content

Commit

Permalink
Merge b49bc0f into 57c2516
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomocaironi committed May 30, 2023
2 parents 57c2516 + b49bc0f commit ae9e3c9
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 30 deletions.
8 changes: 7 additions & 1 deletion HISTORY.md
Expand Up @@ -5,12 +5,18 @@ Notable changes to the codebase are documented here.
Release names follow *[calendar versioning](https://calver.org/)*:
full year, short month, short day (YYYY-M-D)

## v2023.3 (work in progress, not released yet)
## v2023.6 (work in progress, not released yet)

Major changes include:

- TBD

## v2023.5.30

Major changes include:

- Fix circular import between ``script`` and ``b32``

## v2023.2.3

Major changes include:
Expand Down
2 changes: 1 addition & 1 deletion btclib/__init__.py
Expand Up @@ -11,7 +11,7 @@
"""__init__ module for the btclib package."""

name = "btclib"
__version__ = "2023.3"
__version__ = "2023.5.30"
__author__ = "The btclib developers"
__author_email__ = "devs@btclib.org"
__copyright__ = "Copyright (C) 2017-2023 The btclib developers"
Expand Down
12 changes: 3 additions & 9 deletions btclib/b32.py
Expand Up @@ -46,12 +46,11 @@

from typing import Iterable

from btclib.alias import Octets, String, TaprootScriptTree
from btclib.alias import Octets, String
from btclib.bech32 import decode, encode
from btclib.exceptions import BTClibValueError
from btclib.hashes import hash160, sha256
from btclib.network import NETWORKS, network_from_key_value
from btclib.script import output_pubkey
from btclib.to_pub_key import Key, pub_keyinfo_from_key
from btclib.utils import bytes_from_octets

Expand Down Expand Up @@ -170,11 +169,6 @@ def p2wsh(script_pub_key: Octets, network: str = "mainnet") -> str:
return address_from_witness(0, h256, network)


def p2tr(
internal_key: Key | None = None,
script_path: TaprootScriptTree | None = None,
network: str = "mainnet",
) -> str:
def p2tr(output_key: Octets, network: str = "mainnet") -> str:
"""Return the p2tr bech32 address corresponding to a taproot output key."""
pub_key = output_pubkey(internal_key, script_path)[0]
return address_from_witness(1, pub_key, network)
return address_from_witness(1, output_key, network)
21 changes: 9 additions & 12 deletions btclib/script/__init__.py
Expand Up @@ -11,17 +11,7 @@
"""Module btclib.script."""

from btclib.script.script import Command, Script, op_int, parse, serialize
from btclib.script.taproot import (
TaprootScriptTree,
check_output_pubkey,
input_script_sig,
output_prvkey,
output_pubkey,
)
from btclib.script.witness import Witness

# hack to prevent circular import
from btclib.script.script_pub_key import ( # isort:skip
from btclib.script.script_pub_key import (
ScriptPubKey,
address,
assert_nulldata,
Expand All @@ -41,7 +31,14 @@
is_p2wsh,
type_and_payload,
)

from btclib.script.taproot import (
TaprootScriptTree,
check_output_pubkey,
input_script_sig,
output_prvkey,
output_pubkey,
)
from btclib.script.witness import Witness

__all__ = [
"Command",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Expand Up @@ -21,7 +21,7 @@
project = "btclib"
project_copyright = "2017-2023 The btclib developers"
author = "The btclib developers"
release = "2023.3"
release = "2023.5.30"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
8 changes: 4 additions & 4 deletions tests/script/test_script_pub_key.py
Expand Up @@ -580,13 +580,13 @@ def test_non_standard_script_in_p2wsh() -> None:

def test_p2tr() -> None:
pub_key = "cc71eb30d653c0c3163990c47b976f3fb3f37cccdcbedb169a1dfef58bbfbfaf"
payload = output_pubkey(pub_key)[0]
script_pub_key = serialize(["OP_1", payload])
out_pubkey = output_pubkey(pub_key)[0]
script_pub_key = serialize(["OP_1", out_pubkey])
assert_p2tr(script_pub_key)
assert ("p2tr", payload) == type_and_payload(script_pub_key)
assert ("p2tr", out_pubkey) == type_and_payload(script_pub_key)

network = "mainnet"
addr = b32.p2tr(pub_key, network=network)
addr = b32.p2tr(out_pubkey, network=network)
assert addr == address(script_pub_key, network)

assert script_pub_key == ScriptPubKey.from_address(addr).script
Expand Down
2 changes: 1 addition & 1 deletion tests/script/test_taproot.py
Expand Up @@ -131,7 +131,7 @@ def test_bip_test_vector() -> None:
script_tree = convert_script_tree(test["given"]["scriptTree"])

tweaked_pubkey = output_pubkey(f"02{pub_key}", script_tree)[0]
address = b32.p2tr(f"02{pub_key}", script_tree)
address = b32.p2tr(tweaked_pubkey)

assert tweaked_pubkey.hex() == test["intermediary"]["tweakedPubkey"]
assert address == test["expected"]["bip350Address"]
2 changes: 1 addition & 1 deletion tests/test_b32.py
Expand Up @@ -314,7 +314,7 @@ def test_p2wsh() -> None:
def test_p2tr() -> None:
key = 1
pub_key = output_pubkey(key)[0]
addr = b32.p2tr(key)
addr = b32.p2tr(pub_key)
_, wit_prg, _ = b32.witness_from_address(addr)

assert wit_prg == pub_key

0 comments on commit ae9e3c9

Please sign in to comment.