-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathmetamask.py
41 lines (37 loc) · 1.3 KB
/
metamask.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
from hdwallet import HDWallet
from hdwallet.mnemonics import (
BIP39Mnemonic, BIP39_MNEMONIC_LANGUAGES, BIP39_MNEMONIC_WORDS
)
from hdwallet.cryptocurrencies import Ethereum as Cryptocurrency
from hdwallet.hds import BIP44HD
from hdwallet.derivations import (
BIP44Derivation, CHANGES
)
# Initialize Ethereum HDWallet
hdwallet: HDWallet = HDWallet(
cryptocurrency=Cryptocurrency,
hd=BIP44HD,
network=Cryptocurrency.NETWORKS.MAINNET,
passphrase=None # "talonlab"
).from_mnemonic( # Get Ethereum HDWallet from mnemonic phrase
mnemonic=BIP39Mnemonic(
mnemonic=BIP39Mnemonic.from_words(
words=BIP39_MNEMONIC_WORDS.TWELVE,
language=BIP39_MNEMONIC_LANGUAGES.ENGLISH
)
)
).from_derivation( # Drive from BIP44 derivation
derivation=BIP44Derivation(
coin_type=Cryptocurrency.COIN_TYPE,
account=0,
change=CHANGES.EXTERNAL_CHAIN,
address=(0, 10) # or "0-10"
)
)
print("Mnemonic:", hdwallet.mnemonic())
print("Base HD Path: m/44'/60'/0'/0/{address}", "\n")
# Print dived Ethereum HDWallet information's
for derivation in hdwallet.dumps(exclude={"root", "indexes"}):
# Print path, address and private_key
print(f"{derivation['at']['path']} {derivation['address']} 0x{derivation['private_key']}")