mm-btc 0.0.2__tar.gz → 0.0.3__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.3
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"
@@ -1,10 +1,11 @@
1
1
  [project]
2
2
  name = "mm-btc"
3
- version = "0.0.2"
3
+ version = "0.0.3"
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,45 @@
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", "-pass")] = "",
16
+ path: Annotated[str, typer.Option("--path", help="Derivation path. Examples: bip44, bip88, m/44'/0'/0'/0")] = "bip44",
17
+ words: int = typer.Option(12, "--words", "-w", help="Number of mnemonic words"),
18
+ limit: int = typer.Option(10, "--limit", "-l"),
19
+ testnet: bool = typer.Option(False, "--testnet", "-t", help="Testnet network"),
20
+ ) -> None:
21
+ mnemonic_cmd.run(
22
+ mnemonic_cmd.Args(
23
+ mnemonic=mnemonic,
24
+ passphrase=passphrase,
25
+ words=words,
26
+ limit=limit,
27
+ path=path,
28
+ testnet=testnet,
29
+ )
30
+ )
31
+
32
+
33
+ def version_callback(value: bool) -> None:
34
+ if value:
35
+ print_plain(f"mm-eth version: {cli_utils.get_version()}")
36
+ raise typer.Exit()
37
+
38
+
39
+ @app.callback()
40
+ def main(_version: bool = typer.Option(None, "--version", callback=version_callback, is_eager=True)) -> None:
41
+ pass
42
+
43
+
44
+ if __name__ == "__main_":
45
+ 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,39 @@
1
+ from dataclasses import dataclass
2
+
3
+ from mm_std import print_plain
4
+
5
+ from mm_btc.wallet import derive_accounts, generate_mnemonic
6
+
7
+
8
+ @dataclass
9
+ class Args:
10
+ mnemonic: str
11
+ passphrase: str
12
+ words: int
13
+ limit: int
14
+ path: str
15
+ testnet: bool
16
+
17
+
18
+ def run(args: Args) -> None:
19
+ mnemonic = args.mnemonic or generate_mnemonic()
20
+ passphrase = args.passphrase
21
+ path = get_derivation_path_prefix(args.path, args.testnet)
22
+ accounts = derive_accounts(mnemonic, passphrase, path, args.limit)
23
+
24
+ print_plain(f"mnemonic: {mnemonic}")
25
+ print_plain(f"passphrase: {passphrase}")
26
+ for acc in accounts:
27
+ print_plain(f"{acc.path} {acc.address} {acc.private}")
28
+
29
+
30
+ def get_derivation_path_prefix(path: str, testnet: bool) -> str:
31
+ if path.startswith("m/"):
32
+ return path
33
+ coin = "1" if testnet else "0"
34
+ if path == "bip44":
35
+ return f"m/44'/{coin}'/0'/0"
36
+ if path == "bip84":
37
+ return f"m/84'/{coin}'/0'/0"
38
+
39
+ raise ValueError("Invalid path")
File without changes
@@ -17,7 +17,8 @@ class Account:
17
17
  path: str
18
18
 
19
19
 
20
- def generate_mnemonic(language: str = "english", strength: int = 128) -> str:
20
+ def generate_mnemonic(language: str = "english", words: int = 12) -> str:
21
+ strength = mnemonic_words_to_strenght(words)
21
22
  return new_mnemonic(language=language, strength=strength) # type: ignore[no-any-return]
22
23
 
23
24
 
@@ -43,3 +44,18 @@ def derive_accounts(mnemonic: str, passphrase: str, path: str, limit: int) -> li
43
44
  w.clean_derivation()
44
45
 
45
46
  return accounts
47
+
48
+
49
+ def mnemonic_words_to_strenght(words: int) -> int:
50
+ if words == 12:
51
+ return 128
52
+ if words == 15:
53
+ return 160
54
+ if words == 18:
55
+ return 192
56
+ if words == 21:
57
+ return 224
58
+ if words == 24:
59
+ return 256
60
+
61
+ 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.3
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
@@ -9,7 +9,7 @@ from mm_btc.wallet import (
9
9
 
10
10
 
11
11
  def test_generate_mnemonic():
12
- mnemonic = generate_mnemonic(strength=256)
12
+ mnemonic = generate_mnemonic(words=24)
13
13
  assert len(mnemonic.split()) == 24
14
14
 
15
15
  assert generate_mnemonic() != generate_mnemonic()
File without changes
File without changes
File without changes
File without changes
File without changes