mm-btc 0.0.2__py3-none-any.whl → 0.0.4__py3-none-any.whl

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.
mm_btc/cli/__init__.py ADDED
File without changes
mm_btc/cli/cli.py ADDED
@@ -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")
mm_btc/wallet.py CHANGED
@@ -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'
@@ -0,0 +1,14 @@
1
+ mm_btc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ mm_btc/blockstream.py,sha256=HllRQBO1Ezl0ArVH8b-CPRi0f5zdRNXJT_K3oCpAtgg,2159
3
+ mm_btc/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ mm_btc/wallet.py,sha256=9gG_jAsDDInHMFhNcC4vToxzzwM8upAw2KncCPiOaZ8,1741
5
+ mm_btc/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ mm_btc/cli/cli.py,sha256=jWWXgBo1qRYnnheYungdt8IHZnG37U0h6oVo_nh_jm4,1581
7
+ mm_btc/cli/cli_utils.py,sha256=g2o5ySLu-Tw8dZm84ZAsx8862yHij4sDfz4z6uLS2hw,102
8
+ mm_btc/cli/cmd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ mm_btc/cli/cmd/mnemonic_cmd.py,sha256=zAAHr9j0SLJX5BXoiMTZj8pIzTPX26aJEOUi7IN40Ug,1192
10
+ mm_btc-0.0.4.dist-info/METADATA,sha256=FK-azr9otf5iyXg85kx29RNJRaCLMwSALIlSDWfP0fA,858
11
+ mm_btc-0.0.4.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
12
+ mm_btc-0.0.4.dist-info/entry_points.txt,sha256=KphzLNE9eb9H1DO-L0gvBQaQT5ImedyVCN4a6svfiRg,46
13
+ mm_btc-0.0.4.dist-info/top_level.txt,sha256=0X0Ppv_QY0ulzgCB5HNezpaHfQ4wvih_B72hn5hHTUE,7
14
+ mm_btc-0.0.4.dist-info/RECORD,,
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ mm-btc = mm_btc.cli.cli:app
@@ -1,8 +0,0 @@
1
- mm_btc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- mm_btc/blockstream.py,sha256=HllRQBO1Ezl0ArVH8b-CPRi0f5zdRNXJT_K3oCpAtgg,2159
3
- mm_btc/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- mm_btc/wallet.py,sha256=XI2Ju5dELc_2wqyag6M-k5s3EZODN9qJKm3yjurJORE,1375
5
- mm_btc-0.0.2.dist-info/METADATA,sha256=LdFWJbmxkPxaaxnInxW9KlEDh_QMji8xMbf4-n8YxtM,828
6
- mm_btc-0.0.2.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
7
- mm_btc-0.0.2.dist-info/top_level.txt,sha256=0X0Ppv_QY0ulzgCB5HNezpaHfQ4wvih_B72hn5hHTUE,7
8
- mm_btc-0.0.2.dist-info/RECORD,,
File without changes