mm-btc 0.0.2__tar.gz → 0.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mm-btc
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Requires-Python: >=3.12
5
5
  Requires-Dist: mm-std~=0.1.0
6
6
  Requires-Dist: hdwallet~=2.2.1
7
+ Requires-Dist: typer~=0.12.3
7
8
  Provides-Extra: dev
8
9
  Requires-Dist: build~=1.2.1; extra == "dev"
9
10
  Requires-Dist: twine~=5.1.0; extra == "dev"
@@ -0,0 +1 @@
1
+ mm-btc
@@ -1,10 +1,11 @@
1
1
  [project]
2
2
  name = "mm-btc"
3
- version = "0.0.2"
3
+ version = "0.0.4"
4
4
  description = ""
5
5
  dependencies = [
6
6
  "mm-std~=0.1.0",
7
- "hdwallet~=2.2.1"
7
+ "hdwallet~=2.2.1",
8
+ "typer~=0.12.3"
8
9
  ]
9
10
  requires-python = ">=3.12"
10
11
  [project.optional-dependencies]
@@ -23,6 +24,8 @@ dev = [
23
24
  "types-requests~=2.32.0.20240523",
24
25
  "types-PyYAML~=6.0.12.12",
25
26
  ]
27
+ [project.scripts]
28
+ mm-btc = "mm_btc.cli.cli:app"
26
29
 
27
30
 
28
31
  [build-system]
@@ -0,0 +1,47 @@
1
+ from typing import Annotated
2
+
3
+ import typer
4
+ from mm_std import print_plain
5
+
6
+ from mm_btc.cli import cli_utils
7
+ from mm_btc.cli.cmd import mnemonic_cmd
8
+
9
+ app = typer.Typer(no_args_is_help=True, pretty_exceptions_enable=False, add_completion=False)
10
+
11
+
12
+ @app.command(name="mnemonic", help="Generate keys based on a mnemonic")
13
+ def mnemonic_command( # nosec B107:hardcoded_password_default
14
+ mnemonic: Annotated[str, typer.Option("--mnemonic", "-m", help="")] = "",
15
+ passphrase: Annotated[str, typer.Option("--passphrase", "-p")] = "",
16
+ path: Annotated[str, typer.Option("--path", help="Derivation path. Examples: bip44, bip88, m/44'/0'/0'/0")] = "bip44",
17
+ hex_: Annotated[bool, typer.Option("--hex", help="Print private key in hex format instead of WIF")] = False,
18
+ words: int = typer.Option(12, "--words", "-w", help="Number of mnemonic words"),
19
+ limit: int = typer.Option(10, "--limit", "-l"),
20
+ testnet: bool = typer.Option(False, "--testnet", "-t", help="Testnet network"),
21
+ ) -> None:
22
+ mnemonic_cmd.run(
23
+ mnemonic_cmd.Args(
24
+ mnemonic=mnemonic,
25
+ passphrase=passphrase,
26
+ words=words,
27
+ limit=limit,
28
+ path=path,
29
+ hex=hex_,
30
+ testnet=testnet,
31
+ )
32
+ )
33
+
34
+
35
+ def version_callback(value: bool) -> None:
36
+ if value:
37
+ print_plain(f"mm-eth version: {cli_utils.get_version()}")
38
+ raise typer.Exit()
39
+
40
+
41
+ @app.callback()
42
+ def main(_version: bool = typer.Option(None, "--version", callback=version_callback, is_eager=True)) -> None:
43
+ pass
44
+
45
+
46
+ if __name__ == "__main_":
47
+ app()
@@ -0,0 +1,5 @@
1
+ import importlib.metadata
2
+
3
+
4
+ def get_version() -> str:
5
+ return importlib.metadata.version("mm-btc")
File without changes
@@ -0,0 +1,48 @@
1
+ from dataclasses import dataclass
2
+ from enum import Enum
3
+
4
+ from mm_std import print_plain
5
+
6
+ from mm_btc.wallet import derive_accounts, generate_mnemonic
7
+
8
+
9
+ class PrivateType(str, Enum):
10
+ hex = "hex"
11
+ wif = "wif"
12
+
13
+
14
+ @dataclass
15
+ class Args:
16
+ mnemonic: str
17
+ passphrase: str
18
+ words: int
19
+ limit: int
20
+ hex: bool # Print private key in hex format instead of WIF
21
+ path: str
22
+ testnet: bool
23
+
24
+
25
+ def run(args: Args) -> None:
26
+ mnemonic = args.mnemonic or generate_mnemonic()
27
+ passphrase = args.passphrase
28
+ path = get_derivation_path_prefix(args.path, args.testnet)
29
+ accounts = derive_accounts(mnemonic, passphrase, path, args.limit)
30
+
31
+ print_plain(f"{mnemonic}")
32
+ if passphrase:
33
+ print_plain(f"{passphrase}")
34
+ for acc in accounts:
35
+ private = acc.private if args.hex else acc.wif
36
+ print_plain(f"{acc.path} {acc.address} {private}")
37
+
38
+
39
+ def get_derivation_path_prefix(path: str, testnet: bool) -> str:
40
+ if path.startswith("m/"):
41
+ return path
42
+ coin = "1" if testnet else "0"
43
+ if path == "bip44":
44
+ return f"m/44'/{coin}'/0'/0"
45
+ if path == "bip84":
46
+ return f"m/84'/{coin}'/0'/0"
47
+
48
+ raise ValueError("Invalid path")
File without changes
@@ -14,10 +14,12 @@ BIP84_TESTNET_PATH = "m/84'/1'/0'/0"
14
14
  class Account:
15
15
  address: str
16
16
  private: str
17
+ wif: str
17
18
  path: str
18
19
 
19
20
 
20
- def generate_mnemonic(language: str = "english", strength: int = 128) -> str:
21
+ def generate_mnemonic(language: str = "english", words: int = 12) -> str:
22
+ strength = mnemonic_words_to_strenght(words)
21
23
  return new_mnemonic(language=language, strength=strength) # type: ignore[no-any-return]
22
24
 
23
25
 
@@ -39,7 +41,22 @@ def derive_accounts(mnemonic: str, passphrase: str, path: str, limit: int) -> li
39
41
  accounts = []
40
42
  for index_path in range(limit):
41
43
  w.from_path(path=f"{path}/{index_path}")
42
- accounts.append(Account(address=w.address(), private=w.wif(), path=f"{path}/{index_path}"))
44
+ accounts.append(Account(address=w.address(), private=w.private_key(), wif=w.wif(), path=f"{path}/{index_path}"))
43
45
  w.clean_derivation()
44
46
 
45
47
  return accounts
48
+
49
+
50
+ def mnemonic_words_to_strenght(words: int) -> int:
51
+ if words == 12:
52
+ return 128
53
+ if words == 15:
54
+ return 160
55
+ if words == 18:
56
+ return 192
57
+ if words == 21:
58
+ return 224
59
+ if words == 24:
60
+ return 256
61
+
62
+ raise ValueError("Invalid words")
@@ -1,9 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mm-btc
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Requires-Python: >=3.12
5
5
  Requires-Dist: mm-std~=0.1.0
6
6
  Requires-Dist: hdwallet~=2.2.1
7
+ Requires-Dist: typer~=0.12.3
7
8
  Provides-Extra: dev
8
9
  Requires-Dist: build~=1.2.1; extra == "dev"
9
10
  Requires-Dist: twine~=5.1.0; extra == "dev"
@@ -7,7 +7,13 @@ src/mm_btc/wallet.py
7
7
  src/mm_btc.egg-info/PKG-INFO
8
8
  src/mm_btc.egg-info/SOURCES.txt
9
9
  src/mm_btc.egg-info/dependency_links.txt
10
+ src/mm_btc.egg-info/entry_points.txt
10
11
  src/mm_btc.egg-info/requires.txt
11
12
  src/mm_btc.egg-info/top_level.txt
13
+ src/mm_btc/cli/__init__.py
14
+ src/mm_btc/cli/cli.py
15
+ src/mm_btc/cli/cli_utils.py
16
+ src/mm_btc/cli/cmd/__init__.py
17
+ src/mm_btc/cli/cmd/mnemonic_cmd.py
12
18
  tests/test_blockstream.py
13
19
  tests/test_wallet.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ mm-btc = mm_btc.cli.cli:app
@@ -1,5 +1,6 @@
1
1
  mm-std~=0.1.0
2
2
  hdwallet~=2.2.1
3
+ typer~=0.12.3
3
4
 
4
5
  [dev]
5
6
  build~=1.2.1
@@ -1,24 +1,24 @@
1
1
  from mm_btc import blockstream
2
2
 
3
3
 
4
- def test_get_address(binance_address):
4
+ def test_get_address(binance_address, proxies):
5
5
  # non-empty address
6
- res = blockstream.get_address(binance_address)
6
+ res = blockstream.get_address(binance_address, proxies=proxies)
7
7
  assert res.unwrap().chain_stats.tx_count > 800
8
8
 
9
9
  # empty address
10
- res = blockstream.get_address("bc1pa48c294qk7yd7sc8y0wxydc3a2frv5j83e65rvm48v3ej098s5zs8kvh6d")
10
+ res = blockstream.get_address("bc1pa48c294qk7yd7sc8y0wxydc3a2frv5j83e65rvm48v3ej098s5zs8kvh6d", proxies=proxies)
11
11
  assert res.unwrap().chain_stats.tx_count == 0
12
12
 
13
13
  # invalid address
14
- res = blockstream.get_address("bc1pa48c294qk7yd7sc8y0wxydc3a2frv5j83e65rvm48v3ej098s5zs8kvh5d")
14
+ res = blockstream.get_address("bc1pa48c294qk7yd7sc8y0wxydc3a2frv5j83e65rvm48v3ej098s5zs8kvh5d", proxies=proxies)
15
15
  assert res.unwrap_err() == blockstream.ERROR_INVALID_ADDRESS
16
16
 
17
17
  # invalid network
18
- res = blockstream.get_address(binance_address, testnet=True)
18
+ res = blockstream.get_address(binance_address, testnet=True, proxies=proxies)
19
19
  assert res.unwrap_err() == blockstream.ERROR_INVALID_NETWORK
20
20
 
21
21
 
22
- def test_get_confirmed_balance(binance_address):
23
- res = blockstream.get_confirmed_balance(binance_address)
22
+ def test_get_confirmed_balance(binance_address, proxies):
23
+ res = blockstream.get_confirmed_balance(binance_address, proxies=proxies)
24
24
  assert res.unwrap() > 0
@@ -0,0 +1,45 @@
1
+ from mm_btc.wallet import (
2
+ BIP44_MAINNET_PATH,
3
+ BIP44_TESTNET_PATH,
4
+ BIP84_MAINNET_PATH,
5
+ BIP84_TESTNET_PATH,
6
+ derive_accounts,
7
+ generate_mnemonic,
8
+ )
9
+
10
+
11
+ def test_generate_mnemonic():
12
+ mnemonic = generate_mnemonic(words=24)
13
+ assert len(mnemonic.split()) == 24
14
+
15
+ assert generate_mnemonic() != generate_mnemonic()
16
+
17
+
18
+ def test_derive_accounts(mnemonic, passphrase):
19
+ # mainnet bip44
20
+ accs = derive_accounts(mnemonic, passphrase, BIP44_MAINNET_PATH, 2)
21
+ assert accs[1].path == "m/44'/0'/0'/0/1"
22
+ assert accs[1].address == "13MJrGQq8RwLcGfdnY58666kCsZqevsadE"
23
+ assert accs[1].private == "0d5feb50af849f2ebcc0c83a4446ddbceefd7b0ceba437a57161fa37702d096e"
24
+ assert accs[1].wif == "Kwfi75WxsuaKnmxRUQDoEZDzKXkMC8E9Pzk3vVjEdPsJu1DXCFPv"
25
+
26
+ # mainnet bip84
27
+ accs = derive_accounts(mnemonic, passphrase, BIP84_MAINNET_PATH, 2)
28
+ assert accs[1].path == "m/84'/0'/0'/0/1"
29
+ assert accs[1].address == "bc1qszqeg6gfcmt8zurkeayes2895urnea2m54rt3w"
30
+ assert accs[1].private == "1cc57553f9e3e1b863693be92ac753f682f61f1a2dede2ceff97262027635334"
31
+ assert accs[1].wif == "KxBdzQTQduYKoec1FWgwMDF9R1a4UdQp3ezyhjniw4W2k54Cb6gE"
32
+
33
+ # testnet bip44
34
+ accs = derive_accounts(mnemonic, passphrase, BIP44_TESTNET_PATH, 2)
35
+ assert accs[1].path == "m/44'/1'/0'/0/1"
36
+ assert accs[1].address == "miRfXh2aH6pjhdo5EoBt4RRdAipR88dcV3"
37
+ assert accs[1].private == "3a2e8fc45c75ab8a7cdafacf7c77c941f8eebc813ee2f0e17ee86e7ac8584b3a"
38
+ assert accs[1].wif == "cPXoLA4cRKxeht4iH6ZsCDQxPspFi8SEieZNTKDzGgog94Zg5Y64"
39
+
40
+ # testnet bip84
41
+ accs = derive_accounts(mnemonic, passphrase, BIP84_TESTNET_PATH, 2)
42
+ assert accs[1].path == "m/84'/1'/0'/0/1"
43
+ assert accs[1].address == "tb1qp36pk9w408pgfpwn5myxwurr3fhzryn0lpyah2"
44
+ assert accs[1].private == "150fd20e4cb377ae57b43fed59ca2765a9f5d91a20640a4cfdf43ceb5403d48c"
45
+ assert accs[1].wif == "cNHeFPcfq2XFfDAgq9icSK8NX29C1exPHekqYQdWgruQ6gPMBmXD"
mm_btc-0.0.2/README.txt DELETED
@@ -1,2 +0,0 @@
1
- For tests:
2
- - binance address: 34xp4vRoCGJym3xR7yCVPFHoCNxv4Twseo
@@ -1,44 +0,0 @@
1
- from mm_btc.wallet import (
2
- BIP44_MAINNET_PATH,
3
- BIP44_TESTNET_PATH,
4
- BIP84_MAINNET_PATH,
5
- BIP84_TESTNET_PATH,
6
- derive_accounts,
7
- generate_mnemonic,
8
- )
9
-
10
-
11
- def test_generate_mnemonic():
12
- mnemonic = generate_mnemonic(strength=256)
13
- assert len(mnemonic.split()) == 24
14
-
15
- assert generate_mnemonic() != generate_mnemonic()
16
-
17
-
18
- def test_derive_accounts():
19
- mnemonic = "arrange mutual earth tackle smart kangaroo rigid census exotic acoustic stock dream eager area laptop"
20
- passphrase = "my-secret"
21
-
22
- # mainnet bip44
23
- accs = derive_accounts(mnemonic, passphrase, BIP44_MAINNET_PATH, 2)
24
- assert accs[1].path == "m/44'/0'/0'/0/1"
25
- assert accs[1].address == "1L4Ghh4kuJuRCXrFrczwCV2TaggfCgf6B3"
26
- assert accs[1].private == "Kz4zoYPJ5astywoTbxHQr5SgFvMCekMqnWDFnXjY9CfvFtyNnGiE"
27
-
28
- # mainnet bip84
29
- accs = derive_accounts(mnemonic, passphrase, BIP84_MAINNET_PATH, 2)
30
- assert accs[1].path == "m/84'/0'/0'/0/1"
31
- assert accs[1].address == "bc1qrq2mwuqz3utyqz97xjq5npl0dyq5gmddpxdf8k"
32
- assert accs[1].private == "L447sW2JenqmEMMi7GoiUZDxTpY3Ni5ZfRrRxAbufiYwZV1AHytj"
33
-
34
- # testnet bip44
35
- accs = derive_accounts(mnemonic, passphrase, BIP44_TESTNET_PATH, 2)
36
- assert accs[1].path == "m/44'/1'/0'/0/1"
37
- assert accs[1].address == "n3DsvbopmKJaxHNgdZ6VVK4mB9fcuhXy5w"
38
- assert accs[1].private == "cVsAhYpSm2x8V2fQJdjmfBGm1aW7xKH1U8eZTpG9giz8usxNv4da"
39
-
40
- # testnet bip84
41
- accs = derive_accounts(mnemonic, passphrase, BIP84_TESTNET_PATH, 2)
42
- assert accs[1].path == "m/84'/1'/0'/0/1"
43
- assert accs[1].address == "tb1q4cu7pgs0w5s4ctjz4m6gx6m4rv8eqjwtnt0a4j"
44
- assert accs[1].private == "cPASMrozgCxXD6GQsJhge7hPY81j3huF8RJBY1PYwKmUVSYgeSRw"
File without changes
File without changes
File without changes