diff --git a/README.md b/README.md index 5bc54ac..1401cdc 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,18 @@ # python-bip44 -Simple python bip44 implementation = mnemonic + bip32. +Simple python bip44 implementation. Mnemonic + bip32. + +## Quickstart +```python +>>> from coincurve import PrivateKey +>>> from bip44.wallet import Wallet +>>> from bip44.utils import get_eth_addr +>>> mnemonic = "purity tunnel grid error scout long fruit false embody caught skin gate" +>>> w = Wallet(mnemonic) +>>> sk, pk = w.derive_account("eth", account=0) +>>> sk = PrivateKey(sk) +>>> sk.public_key.format() == pk +True +>>> get_eth_addr(pk) +'0x7ad23d6ed9a1d98e240988bed0d78e8c81ec296c' +``` diff --git a/bip44/utils.py b/bip44/utils.py index caf33f9..59492a3 100644 --- a/bip44/utils.py +++ b/bip44/utils.py @@ -1,6 +1,6 @@ from typing import List - from bip32 import HARDENED_INDEX +from coincurve import PublicKey from sha3 import keccak_256 as _keccak_256 @@ -28,4 +28,6 @@ def parse_path(s: str) -> List[int]: def get_eth_addr(pk: bytes) -> str: + if len(pk) != 64: + pk = PublicKey(pk).format(False)[1:] return f"0x{keccak_256(pk)[-20:].hex()}" diff --git a/pyproject.toml b/pyproject.toml index 508ed1c..af2509c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,11 @@ [tool.poetry] name = "bip44" version = "0.0.1" -description = "Mnemonic + python-bip32" +description = "Simple python bip44 implementation. Mnemonic + bip32." +repository = "https://github.com/kigawas/python-bip44" authors = ["Weiliang Li "] +maintainers = ["Weiliang Li "] +readme = "README.md" license = "MIT" [tool.poetry.dependencies] diff --git a/tests/test_bip44.py b/tests/test_bip44.py index 44e7f2b..4cbc4a9 100644 --- a/tests/test_bip44.py +++ b/tests/test_bip44.py @@ -37,4 +37,4 @@ def test_btc_wallet(): assert sk == expected_sk assert pk == expected_pk - assert pk == PublicKey.from_secret(expected_pk).format() + assert pk == PublicKey.from_secret(expected_sk).format()