Skip to content

Commit

Permalink
Merge 3f5fe3e into ebdb51e
Browse files Browse the repository at this point in the history
  • Loading branch information
fametrano committed Feb 1, 2023
2 parents ebdb51e + 3f5fe3e commit 68af5c3
Show file tree
Hide file tree
Showing 23 changed files with 20 additions and 69 deletions.
37 changes: 18 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,8 @@ repos:
- id: copyright-notice
args: [--notice=COPYRIGHT]
files: python
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py37-plus]
# exclude: *fixtures
language: python
types: [python]
- repo: https://github.com/PyCQA/autoflake
rev: v2.0.0
rev: v2.0.1
hooks:
- id: autoflake
args:
Expand All @@ -61,16 +53,24 @@ repos:
- --remove-rhs-for-unused-variables
language: python
types: [python]
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py37-plus]
# exclude: *fixtures
language: python
types: [python]
- repo: https://github.com/pycqa/isort
rev: 5.11.4
rev: 5.12.0
hooks:
- id: isort
name: isort (black profile, in place fixes)
args: ["--profile", "black", "--filter-files"]
language: python
types: [python]
- repo: https://github.com/PyCQA/docformatter
rev: v1.5.1
rev: v1.6.0.rc1
hooks:
- id: docformatter
description: "Formats docstrings to follow PEP 257."
Expand All @@ -96,8 +96,14 @@ repos:
- id: yesqa
language: python
types: [python]
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
language: python
types: [python]
- repo: https://github.com/psf/black
rev: 22.12.0
rev: 23.1.0
hooks:
- id: black
name: black (in place fixes)
Expand All @@ -109,12 +115,6 @@ repos:
# language_version: python3.11
language: python
types: [python]
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
language: python
types: [python]
- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
hooks:
Expand Down Expand Up @@ -142,7 +142,6 @@ repos:
hooks:
- id: pylint
args: [
"--score=false",
"--disable=E0401", # import-error
]
language: python
Expand Down
1 change: 0 additions & 1 deletion btclib/bip32/bip32.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ def __init__(
key: Octets,
check_validity: bool = True,
) -> None:

super().__init__(
version, depth, parent_fingerprint, index, chain_code, key, False
)
Expand Down
2 changes: 0 additions & 2 deletions btclib/block/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def __init__(
transactions: Sequence[Tx] | None = None,
check_validity: bool = True,
) -> None:

self.header = header

# https://docs.python.org/3/tutorial/controlflow.html#default-argument-values
Expand All @@ -97,7 +96,6 @@ def to_dict(self, check_validity: bool = True) -> dict[str, Any]:
def from_dict(
cls: type[Block], dict_: Mapping[str, Any], check_validity: bool = True
) -> Block:

return cls(
BlockHeader.from_dict(dict_["header"], False),
[Tx.from_dict(tx, False) for tx in dict_["transactions"]],
Expand Down
2 changes: 0 additions & 2 deletions btclib/block/block_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def __init__(
nonce: int = 0,
check_validity: bool = True,
) -> None:

self.version = version
self.previous_block_hash = bytes_from_octets(previous_block_hash)
self.merkle_root = bytes_from_octets(merkle_root_)
Expand Down Expand Up @@ -134,7 +133,6 @@ def to_dict(self, check_validity: bool = True) -> dict[str, int | float | str]:
def from_dict(
cls: type[BlockHeader], dict_: Mapping[str, Any], check_validity: bool = True
) -> BlockHeader:

return cls(
dict_["version"],
dict_["previous_block_hash"],
Expand Down
2 changes: 0 additions & 2 deletions btclib/ecc/dsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ def crack_prv_key_(
sig2: Sig | Octets,
hf: HashF = sha256,
) -> tuple[int, int]:

if isinstance(sig1, Sig):
sig1.assert_valid()
else:
Expand Down Expand Up @@ -590,7 +589,6 @@ def crack_prv_key(
sig2: Sig | Octets,
hf: HashF = sha256,
) -> tuple[int, int]:

msg_hash1 = reduce_to_hlen(msg1, hf)
msg_hash2 = reduce_to_hlen(msg2, hf)

Expand Down
1 change: 0 additions & 1 deletion btclib/ecc/rfc6979_nonce.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
def challenge_(
msg_hash: Octets, ec: Curve = secp256k1, hf: HashF = hashlib.sha256
) -> int:

# the message msg_hash: a hf_len array
hf_len = hf().digest_size
msg_hash = bytes_from_octets(msg_hash, hf_len)
Expand Down
1 change: 0 additions & 1 deletion btclib/mnemonic/entropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ def bin_str_entropy_from_rolls(
min_roll_number = math.ceil(bits / bits_per_roll)
i = 0
for roll in rolls:

# reject invalid rolls not in [1-dice_sides]
if not 0 < roll <= dice_sides:
msg = f"invalid roll: {roll} is not in [1-{dice_sides}]"
Expand Down
2 changes: 0 additions & 2 deletions btclib/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def __init__(
slip132_p2wsh_p2sh_pub: Octets,
check_validity: bool = True,
) -> None:

object.__setattr__(self, "curve", curve)
object.__setattr__(self, "magic_bytes", bytes_from_octets(magic_bytes))
object.__setattr__(self, "genesis_block", bytes_from_octets(genesis_block))
Expand Down Expand Up @@ -175,7 +174,6 @@ def to_dict(self, check_validity: bool = True) -> dict[str, str | None]:
def from_dict(
cls: type[Network], dict_: Mapping[str, Any], check_validity: bool = True
) -> Network:

return cls(
CURVES[dict_["curve"]],
dict_["magic_bytes"],
Expand Down
4 changes: 0 additions & 4 deletions btclib/psbt/psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ def assert_signable(self) -> None:
self.assert_valid()

for i, tx_in in enumerate(self.tx.vin):

non_witness_utxo = self.inputs[i].non_witness_utxo
redeem_script = self.inputs[i].redeem_script
# with python>=3.8 use walrus operator
Expand Down Expand Up @@ -191,7 +190,6 @@ def to_dict(self, check_validity: bool = True) -> dict[str, Any]:
def from_dict(
cls: type[Psbt], dict_: Mapping[str, Any], check_validity: bool = True
) -> Psbt:

return cls(
Tx.from_dict(dict_["tx"]),
[PsbtIn.from_dict(psbt_in, False) for psbt_in in dict_["inputs"]],
Expand Down Expand Up @@ -284,7 +282,6 @@ def b64encode(self, check_validity: bool = True) -> str:
def b64decode(
cls: type[Psbt], psbt_str: String, check_validity: bool = True
) -> Psbt:

if isinstance(psbt_str, str):
psbt_str = psbt_str.strip()

Expand Down Expand Up @@ -366,7 +363,6 @@ def combine_psbts(psbts: Sequence[Psbt]) -> Psbt:

final_psbt.version = max(psbt.version for psbt in psbts)
for psbt in psbts[1:]:

for i, inp in enumerate(final_psbt.inputs):
_combine_field(psbt.inputs[i], inp, "non_witness_utxo")
_combine_field(psbt.inputs[i], inp, "witness_utxo")
Expand Down
2 changes: 0 additions & 2 deletions btclib/psbt/psbt_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ def to_dict(self, check_validity: bool = True) -> dict[str, Any]:
def from_dict(
cls: type[PsbtIn], dict_: Mapping[str, Any], check_validity: bool = True
) -> PsbtIn:

return cls(
Tx.from_dict(dict_["non_witness_utxo"], False)
if dict_["non_witness_utxo"]
Expand Down Expand Up @@ -292,7 +291,6 @@ def serialize(self, check_validity: bool = True) -> bytes:
)

if not self.final_script_sig and not self.final_script_witness:

if self.partial_sigs:
psbt_in_bin.append(
serialize_dict_bytes_bytes(PSBT_IN_PARTIAL_SIG, self.partial_sigs)
Expand Down
1 change: 0 additions & 1 deletion btclib/script/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ def parse(stream: BinaryData, exit_on_op_success: bool = False) -> list[Command]
r: list[Command] = [] # initialize the result list

while True:

t = s.read(1) # get one byte
if not t:
break
Expand Down
2 changes: 0 additions & 2 deletions btclib/script/sig_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ def taproot(
annex: bytes,
message_extension: bytes,
) -> bytes:

if hashtype not in SIG_HASH_TYPES:
raise BTClibValueError(f"Unknown hash type: {hashtype}")
if hashtype & 0x03 == SINGLE and input_index >= len(transaction.vout):
Expand Down Expand Up @@ -265,7 +264,6 @@ def from_tx(prevouts: list[TxOut], tx: Tx, vin_i: int, hash_type: int) -> bytes:
def _script_from_p2tr(
prevouts: list[TxOut], tx: Tx, vin_i: int, hash_type: int
) -> bytes:

witness = tx.vin[vin_i].script_witness
if len(witness.stack) == 0:
raise BTClibValueError("empty stack")
Expand Down
2 changes: 0 additions & 2 deletions btclib/tx/out_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def __init__(
vout: int = 0xFFFFFFFF,
check_validity: bool = True,
) -> None:

object.__setattr__(self, "tx_id", bytes_from_octets(tx_id))
object.__setattr__(self, "vout", vout)

Expand Down Expand Up @@ -80,7 +79,6 @@ def to_dict(self, check_validity: bool = True) -> dict[str, str | int]:
def from_dict(
cls: type[OutPoint], dict_: Mapping[str, Any], check_validity: bool = True
) -> OutPoint:

return cls(dict_["txid"], dict_["vout"], check_validity)

def serialize(self, check_validity: bool = True) -> bytes:
Expand Down
3 changes: 0 additions & 3 deletions btclib/tx/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def __init__(
vout: Sequence[TxOut] | None = None,
check_validity: bool = True,
) -> None:

self.version = version
self.lock_time = lock_time
# https://docs.python.org/3/tutorial/controlflow.html#default-argument-values
Expand Down Expand Up @@ -170,7 +169,6 @@ def to_dict(self, check_validity: bool = True) -> dict[str, str | int | list[Any
def from_dict(
cls: type[Tx], dict_: Mapping[str, Any], check_validity: bool = True
) -> Tx:

return cls(
dict_["version"],
dict_["locktime"],
Expand Down Expand Up @@ -270,7 +268,6 @@ def join_txs(
shuffle_inp: bool,
shuffle_out: bool,
) -> Tx:

version = max(tx.version for tx in txs)
if enforce_same_version and any(tx.version != version for tx in txs):
raise BTClibValueError("Version numbers are not the same")
Expand Down
2 changes: 0 additions & 2 deletions btclib/tx/tx_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def __init__(
script_witness: Witness = Witness(),
check_validity: bool = True,
) -> None:

self.prev_out = prev_out
self.script_sig = bytes_from_octets(script_sig)
self.sequence = sequence
Expand Down Expand Up @@ -114,7 +113,6 @@ def to_dict(self, check_validity: bool = True) -> dict[str, Any]:
def from_dict(
cls: type[TxIn], dict_: Mapping[str, Any], check_validity: bool = True
) -> TxIn:

return cls(
OutPoint.from_dict(dict_["prev_out"], False),
dict_["scriptSig"],
Expand Down
2 changes: 0 additions & 2 deletions btclib/tx/tx_out.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def __init__(
script_pub_key: ScriptPubKey | Octets,
check_validity: bool = True,
) -> None:

object.__setattr__(self, "value", value)
if not isinstance(script_pub_key, ScriptPubKey):
script_bytes = bytes_from_octets(script_pub_key)
Expand Down Expand Up @@ -82,7 +81,6 @@ def to_dict(self, check_validity: bool = True) -> dict[str, Any]:
def from_dict(
cls: type[TxOut], dict_: Mapping[str, Any], check_validity: bool = True
) -> TxOut:

value = sats_from_btc(dict_["value"])
script_bin = dict_["scriptPubKey"]
network = dict_.get("network", "mainnet")
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ exclude = [
profile = "black"

[tool.docformatter]
recursive = true
blank = false
in-place = true

[tool.pydocstyle]
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
packages=find_packages(exclude=["tests", "tests.*"]),
include_package_data=True,
# test_suite="btclib.tests",
# install_requires=[],
extras_require={"secp256k1": ["btclib_libsecp256k1==0.1.0"]},
install_requires=["btclib_libsecp256k1"],
# extras_require={"secp256k1": ["btclib_libsecp256k1"]},
keywords=(
"bitcoin cryptography elliptic-curves ecdsa schnorr RFC-6979 "
"bip32 bip39 electrum base58 bech32 segwit message-signing "
Expand Down
7 changes: 0 additions & 7 deletions tests/ec/test_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ def test_exceptions() -> None:

def test_aff_jac_conversions() -> None:
for ec in all_curves.values():

# just a point, not INF
Q = ec.G
QJ = jac_from_aff(Q)
Expand All @@ -187,7 +186,6 @@ def test_aff_jac_conversions() -> None:
def test_add_double_aff() -> None:
"""Test self-consistency of add and double in affine coordinates."""
for ec in all_curves.values():

# add G and the infinity point
assert ec.add_aff(ec.G, INF) == ec.G
assert ec.add_aff(INF, ec.G) == ec.G
Expand All @@ -210,7 +208,6 @@ def test_add_double_aff() -> None:
def test_add_double_jac() -> None:
"""Test self-consistency of add and double in Jacobian coordinates."""
for ec in all_curves.values():

# add G and the infinity point
assert ec.jac_equality(ec.add_jac(ec.GJ, INFJ), ec.GJ)
assert ec.jac_equality(ec.add_jac(INFJ, ec.GJ), ec.GJ)
Expand All @@ -233,7 +230,6 @@ def test_add_double_jac() -> None:
def test_add_double_aff_jac() -> None:
"""Test consistency between affine and Jacobian add/double methods."""
for ec in all_curves.values():

# just a point, not INF
Q = ec.G
QJ = jac_from_aff(Q)
Expand Down Expand Up @@ -262,7 +258,6 @@ def test_ec_repr() -> None:

def test_is_on_curve() -> None:
for ec in all_curves.values():

with pytest.raises(BTClibValueError, match="point must be a tuple"):
ec.is_on_curve("not a point") # type: ignore[arg-type]

Expand All @@ -277,7 +272,6 @@ def test_is_on_curve() -> None:

def test_negate() -> None:
for ec in all_curves.values():

# just a point, not INF
Q = ec.G
minus_Q = ec.negate(Q)
Expand Down Expand Up @@ -306,7 +300,6 @@ def test_negate() -> None:
def test_symmetry() -> None:
"""Methods to break simmetry: quadratic residue, even/odd, low/high."""
for ec in low_card_curves.values():

# just a point, not INF
Q = ec.G
x_Q = Q[0]
Expand Down
1 change: 0 additions & 1 deletion tests/ec/test_sec_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

def test_octets2point() -> None:
for ec in all_curves.values():

G_bytes = bytes_from_point(ec.G, ec)
G_point = point_from_octets(G_bytes, ec)
assert ec.G == G_point
Expand Down

0 comments on commit 68af5c3

Please sign in to comment.