Skip to content

Commit

Permalink
Revert breaking 2.0 changes (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
akarve authored Oct 15, 2024
1 parent ee64195 commit 0cbdb1c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "bipsea"
version = "2.0.1"
version = "3.0.0"
description = "Composable Python CLI for Bitcoin mnemonics and BIP-85 secrets."
readme = "README.md"
authors = ["Aneesh Karve <[email protected]>"]
Expand Down
4 changes: 2 additions & 2 deletions src/bipsea/bip85.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def apply_85(derived_key: ExtendedKey, path: str) -> Dict[str, Union[bytes, str]
depth=bytes(1),
finger=bytes(4),
child_number=bytes(4),
data=bytes(1) + entropy[:32],
chain_code=entropy[32:],
chain_code=entropy[:32],
data=bytes(1) + entropy[32:],
)

return {
Expand Down
4 changes: 2 additions & 2 deletions tests/data/bip85_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"master": "xprv9s21ZrQH143K2LBWUUQRFXhucrQqBpKdRRxNVq2zBqsx8HVqFk2uYo8kmbaLLHRdqtQpUm98uKfu3vca1LqdGhUtyoFnCNkfmXRyPXLjbKb",
"path": "m/83696968'/32'/0'",
"derived_entropy": "ead0b33988a616cf6a497f1c169d9e92562604e38305ccd3fc96f2252c177682",
"derived_key": "xprv9s21ZrQH143K4Px85utdpu6DFvY2NpHkJajPoupAznfiacH2MC9LasyW4uvqKXNxLWcjqGTbHKAhoZoMAbmRe5g9tAPA7cUUX4UVA1vFKFm",
"derived_key": "xprv9s21ZrQH143K2srSbCSg4m4kLvPMzcWydgmKEnMmoZUurYuBuYG46c6P71UGXMzmriLzCCBvKQWBUv3vPB3m1SATMhp3uEjXHJ42jFg7myX",
},
]

Expand All @@ -77,7 +77,7 @@
{
"master": "xprv9s21ZrQH143K2LBWUUQRFXhucrQqBpKdRRxNVq2zBqsx8HVqFk2uYo8kmbaLLHRdqtQpUm98uKfu3vca1LqdGhUtyoFnCNkfmXRyPXLjbKb",
"path": "m/83696968'/707764'/21'/0'",
"derived_entropy": "74a2e87a9ba0cdd549bdd2f9ea880d554c6c355b08ed25088cfa88f3f1c4f74632b652fd4a8f5fda43074c6f6964a3753b08bb5210c8f5e75c07a4c2a20bf6e9",
"derived_entropy": "d7ad61d4a76575c5bad773feeb40299490b224e8e5df6c8ad8fe3d0a6eed7b85ead9fef7bcca8160f0ee48dc6e92b311fc71f2146623cc6952c03ce82c7b63fe",
"derived_pwd": "dKLoepugzdVJvdL56ogNV",
},
]
Expand Down
31 changes: 9 additions & 22 deletions tests/test_bip85.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
)
from bipsea.util import LOGGER_NAME, to_hex_string

XPRV_DERIVED_LEGACY = "xprv9s21ZrQH143K2srSbCSg4m4kLvPMzcWydgmKEnMmoZUurYuBuYG46c6P71UGXMzmriLzCCBvKQWBUv3vPB3m1SATMhp3uEjXHJ42jFg7myX"
BASE64_ENTROPY_LEGACY = "d7ad61d4a76575c5bad773feeb40299490b224e8e5df6c8ad8fe3d0a6eed7b85ead9fef7bcca8160f0ee48dc6e92b311fc71f2146623cc6952c03ce82c7b63fe"


logger = logging.getLogger(LOGGER_NAME)


Expand All @@ -60,16 +56,20 @@ def test_pwd_base64(vector):
path = vector["path"]
output = apply_85(derive(master, path), path)
assert vector["derived_pwd"] == output["application"]
assert vector["derived_entropy"] == to_hex_string(output["entropy"])
# Hardcode what we believe is correct; issue filed to BIP85
assert (
to_hex_string(output["entropy"])
== "74a2e87a9ba0cdd549bdd2f9ea880d554c6c355b08ed25088cfa88f3f1c4f74632b652fd4a8f5fda43074c6f6964a3753b08bb5210c8f5e75c07a4c2a20bf6e9"
)


@pytest.mark.parametrize("vector", PWD_BASE64)
@pytest.mark.xfail(reason="see updated BIP-85 BASE64 test vector")
def test_pwd_base64_entropy_legacy(vector):
@pytest.mark.xfail(reason="wut!? correct password, bad entropy; filed to BIP-85")
def test_pwd_base64_entropy(vector):
master = parse_ext_key(vector["master"])
path = vector["path"]
output = apply_85(derive(master, path), path)
assert BASE64_ENTROPY_LEGACY == to_hex_string(output["entropy"])
assert vector["derived_entropy"] == to_hex_string(output["entropy"])


@pytest.mark.parametrize("vector", PWD_BASE85)
Expand Down Expand Up @@ -155,23 +155,10 @@ def test_xprv(vector):
master = parse_ext_key(vector["master"])
path = vector["path"]
output = apply_85(derive(master, path), path)
assert output["application"] == vector["derived_key"]
assert vector["derived_key"] == output["application"]
assert to_hex_string(output["entropy"]) == vector["derived_entropy"]


@pytest.mark.parametrize("vector", XPRV)
@pytest.mark.xfail(reason="see updated BIP-85 XPRV test vector")
def test_xprv_legacy(vector):
master = parse_ext_key(vector["master"])
path = vector["path"]
output = apply_85(derive(master, path), path)
with pytest.raises(AssertionError) as expected:
assert output["application"] == XPRV_DERIVED_LEGACY
assert to_hex_string(output["entropy"]) == vector["derived_entropy"]

raise expected.value


def test_private_key_to_wif():
"""follow the procedure from
https://en.bitcoin.it/wiki/Wallet_import_format"""
Expand Down

0 comments on commit 0cbdb1c

Please sign in to comment.