mm-btc 0.1.2__py3-none-any.whl → 0.1.3__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/cli.py +3 -0
- mm_btc/cli/cmd/mnemonic_cmd.py +3 -2
- mm_btc/wallet.py +39 -20
- mm_btc-0.1.3.dist-info/METADATA +10 -0
- {mm_btc-0.1.2.dist-info → mm_btc-0.1.3.dist-info}/RECORD +7 -7
- {mm_btc-0.1.2.dist-info → mm_btc-0.1.3.dist-info}/WHEEL +1 -1
- mm_btc-0.1.2.dist-info/METADATA +0 -9
- {mm_btc-0.1.2.dist-info → mm_btc-0.1.3.dist-info}/entry_points.txt +0 -0
mm_btc/cli/cli.py
CHANGED
|
@@ -7,6 +7,7 @@ from mm_std import print_plain
|
|
|
7
7
|
|
|
8
8
|
from mm_btc.cli import cli_utils
|
|
9
9
|
from mm_btc.cli.cmd import address_cmd, create_tx_cmd, decode_tx_cmd, mnemonic_cmd, utxo_cmd
|
|
10
|
+
from mm_btc.wallet import AddressType
|
|
10
11
|
|
|
11
12
|
app = typer.Typer(no_args_is_help=True, pretty_exceptions_enable=False, add_completion=False)
|
|
12
13
|
|
|
@@ -17,6 +18,7 @@ def mnemonic_command( # nosec B107:hardcoded_password_default
|
|
|
17
18
|
mnemonic: Annotated[str, typer.Option("--mnemonic", "-m", help="")] = "",
|
|
18
19
|
passphrase: Annotated[str, typer.Option("--passphrase", "-p")] = "",
|
|
19
20
|
path: Annotated[str, typer.Option("--path", help="Derivation path. Examples: bip44, bip88, m/44'/0'/0'/0")] = "bip44",
|
|
21
|
+
address_type: Annotated[AddressType, typer.Option("--address-type", "-a", help="Bitcoin address type")] = AddressType.P2WPKH,
|
|
20
22
|
hex_: Annotated[bool, typer.Option("--hex", help="Print private key in hex format instead of WIF")] = False,
|
|
21
23
|
words: int = typer.Option(12, "--words", "-w", help="Number of mnemonic words"),
|
|
22
24
|
limit: int = typer.Option(10, "--limit", "-l"),
|
|
@@ -30,6 +32,7 @@ def mnemonic_command( # nosec B107:hardcoded_password_default
|
|
|
30
32
|
words=words,
|
|
31
33
|
limit=limit,
|
|
32
34
|
path=path,
|
|
35
|
+
address_type=address_type,
|
|
33
36
|
hex=hex_,
|
|
34
37
|
testnet=testnet,
|
|
35
38
|
)
|
mm_btc/cli/cmd/mnemonic_cmd.py
CHANGED
|
@@ -3,7 +3,7 @@ from enum import Enum
|
|
|
3
3
|
|
|
4
4
|
from mm_std import print_plain
|
|
5
5
|
|
|
6
|
-
from mm_btc.wallet import derive_accounts, generate_mnemonic
|
|
6
|
+
from mm_btc.wallet import AddressType, derive_accounts, generate_mnemonic
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class PrivateType(str, Enum):
|
|
@@ -18,6 +18,7 @@ class Args:
|
|
|
18
18
|
words: int
|
|
19
19
|
limit: int
|
|
20
20
|
hex: bool # Print private key in hex format instead of WIF
|
|
21
|
+
address_type: AddressType
|
|
21
22
|
path: str
|
|
22
23
|
testnet: bool
|
|
23
24
|
|
|
@@ -26,7 +27,7 @@ def run(args: Args) -> None:
|
|
|
26
27
|
mnemonic = args.mnemonic or generate_mnemonic()
|
|
27
28
|
passphrase = args.passphrase
|
|
28
29
|
path = get_derivation_path_prefix(args.path, args.testnet)
|
|
29
|
-
accounts = derive_accounts(mnemonic, passphrase, path, args.limit)
|
|
30
|
+
accounts = derive_accounts(mnemonic, passphrase, path, args.address_type, args.limit)
|
|
30
31
|
|
|
31
32
|
print_plain(f"{mnemonic}")
|
|
32
33
|
if passphrase:
|
mm_btc/wallet.py
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
from dataclasses import dataclass
|
|
2
|
+
from enum import Enum, unique
|
|
2
3
|
|
|
3
|
-
from hdwallet import
|
|
4
|
-
from hdwallet.
|
|
5
|
-
from hdwallet.
|
|
4
|
+
from hdwallet import HDWallet
|
|
5
|
+
from hdwallet.cryptocurrencies import Bitcoin
|
|
6
|
+
from hdwallet.derivations import CustomDerivation
|
|
7
|
+
from hdwallet.hds import BIP32HD
|
|
8
|
+
from hdwallet.mnemonics import BIP39Mnemonic
|
|
9
|
+
from mnemonic import Mnemonic
|
|
6
10
|
|
|
7
11
|
BIP44_MAINNET_PATH = "m/44'/0'/0'/0"
|
|
8
12
|
BIP44_TESTNET_PATH = "m/44'/1'/0'/0"
|
|
@@ -18,30 +22,45 @@ class Account:
|
|
|
18
22
|
path: str
|
|
19
23
|
|
|
20
24
|
|
|
25
|
+
@unique
|
|
26
|
+
class AddressType(str, Enum):
|
|
27
|
+
P2PKH = "P2PKH" # Pay to Public Key Hash
|
|
28
|
+
P2SH = "P2SH" # Pay to Script Hash
|
|
29
|
+
P2TR = "P2TR" # Taproot
|
|
30
|
+
P2WPKH = "P2WPKH" # Native SegWit
|
|
31
|
+
P2WPKH_IN_P2SH = "P2WPKH-In-P2SH"
|
|
32
|
+
P2WSH = "P2WSH" # Native SegWit
|
|
33
|
+
P2WSH_IN_P2SH = "P2WSH-In-P2SH"
|
|
34
|
+
|
|
35
|
+
|
|
21
36
|
def generate_mnemonic(language: str = "english", words: int = 12) -> str:
|
|
22
|
-
strength
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if
|
|
28
|
-
|
|
29
|
-
elif
|
|
30
|
-
|
|
31
|
-
elif
|
|
32
|
-
|
|
33
|
-
elif
|
|
34
|
-
|
|
37
|
+
return Mnemonic(language).generate(strength=mnemonic_words_to_strenght(words))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def derive_accounts(mnemonic: str, passphrase: str, path_prefix: str, address_type: AddressType, limit: int) -> list[Account]:
|
|
41
|
+
coin = Bitcoin
|
|
42
|
+
if path_prefix.startswith("m/84'/1'"):
|
|
43
|
+
network = coin.NETWORKS.TESTNET
|
|
44
|
+
elif path_prefix.startswith("m/44'/1'"):
|
|
45
|
+
network = coin.NETWORKS.TESTNET
|
|
46
|
+
elif path_prefix.startswith("m/84'/0'"):
|
|
47
|
+
network = coin.NETWORKS.MAINNET
|
|
48
|
+
elif path_prefix.startswith("m/44'/0'"):
|
|
49
|
+
network = coin.NETWORKS.MAINNET
|
|
35
50
|
else:
|
|
36
51
|
raise ValueError("Invalid path")
|
|
37
52
|
|
|
38
|
-
|
|
39
|
-
|
|
53
|
+
wallet = HDWallet(cryptocurrency=coin, network=network, hd=BIP32HD, passphrase=passphrase).from_mnemonic(
|
|
54
|
+
BIP39Mnemonic(mnemonic)
|
|
55
|
+
)
|
|
56
|
+
wallet.clean_derivation()
|
|
40
57
|
|
|
41
58
|
accounts = []
|
|
42
59
|
for index_path in range(limit):
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
wallet.clean_derivation()
|
|
61
|
+
path = f"{path_prefix}/{index_path}"
|
|
62
|
+
w = wallet.from_derivation(derivation=CustomDerivation(path=path))
|
|
63
|
+
accounts.append(Account(address=w.address(address_type), private=w.private_key(), wif=w.wif(), path=path))
|
|
45
64
|
w.clean_derivation()
|
|
46
65
|
|
|
47
66
|
return accounts
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mm-btc
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Requires-Python: >=3.12
|
|
5
|
+
Requires-Dist: bitcoinlib~=0.7.1
|
|
6
|
+
Requires-Dist: bit~=0.8.0
|
|
7
|
+
Requires-Dist: hdwallet~=3.2.0
|
|
8
|
+
Requires-Dist: mm-std~=0.1.9
|
|
9
|
+
Requires-Dist: mnemonic>=0.21
|
|
10
|
+
Requires-Dist: typer>=0.15.1
|
|
@@ -2,17 +2,17 @@ mm_btc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
2
2
|
mm_btc/blockstream.py,sha256=U2_pc6RYAkFcCvH_WrxjIm13VNavyY3WgK8ePowV-Ic,3620
|
|
3
3
|
mm_btc/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
4
|
mm_btc/tx.py,sha256=7KTMNuL1n8rRj_245BV1bH9M2_PctNvlvPsLEsRTYx4,245
|
|
5
|
-
mm_btc/wallet.py,sha256=
|
|
5
|
+
mm_btc/wallet.py,sha256=E9XKZMQx48JiGRDG8ij7cbilNPVmcpmS6jAGBzXfV9U,2475
|
|
6
6
|
mm_btc/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
-
mm_btc/cli/cli.py,sha256=
|
|
7
|
+
mm_btc/cli/cli.py,sha256=uD49Nek6ZuBLnNOjGghSHv5eNPS2E6hTyCyjvvMOmGU,2620
|
|
8
8
|
mm_btc/cli/cli_utils.py,sha256=g2o5ySLu-Tw8dZm84ZAsx8862yHij4sDfz4z6uLS2hw,102
|
|
9
9
|
mm_btc/cli/cmd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
10
|
mm_btc/cli/cmd/address_cmd.py,sha256=fipX9FiQ2EgCEq8nVN6ELnDMoR5KTIX7bpAaRK3t_yg,284
|
|
11
11
|
mm_btc/cli/cmd/create_tx_cmd.py,sha256=dIuQBTOqTSefC6aMbrBN6Pq0EwV2G2ESM1tLU4WyFoU,690
|
|
12
12
|
mm_btc/cli/cmd/decode_tx_cmd.py,sha256=0jGlUjnA1X2Q2aYwSBeAjqVNZIBsW5X2lEwIpSfWJsU,175
|
|
13
|
-
mm_btc/cli/cmd/mnemonic_cmd.py,sha256=
|
|
13
|
+
mm_btc/cli/cmd/mnemonic_cmd.py,sha256=CY6tPsqOTNfM-4WhKDhqitCi2OeqSIUMEUTFIRGHwIg,1254
|
|
14
14
|
mm_btc/cli/cmd/utxo_cmd.py,sha256=mp-lVLURpXFqO3IeBIEwnHusEvT5tFjUKxnRYC-rFqQ,294
|
|
15
|
-
mm_btc-0.1.
|
|
16
|
-
mm_btc-0.1.
|
|
17
|
-
mm_btc-0.1.
|
|
18
|
-
mm_btc-0.1.
|
|
15
|
+
mm_btc-0.1.3.dist-info/METADATA,sha256=XP2L_wEpJRZGBh2WG_hSaY6HMhkDPrqEIXf6R-z1pJE,252
|
|
16
|
+
mm_btc-0.1.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
17
|
+
mm_btc-0.1.3.dist-info/entry_points.txt,sha256=KphzLNE9eb9H1DO-L0gvBQaQT5ImedyVCN4a6svfiRg,46
|
|
18
|
+
mm_btc-0.1.3.dist-info/RECORD,,
|
mm_btc-0.1.2.dist-info/METADATA
DELETED
|
File without changes
|