|
2 | 2 |
|
3 | 3 | from hdwallet import HDWallet |
4 | 4 | from hdwallet.mnemonics import BIP39Mnemonic |
5 | | -from hdwallet.seeds import BIP39Seed |
| 5 | +from hdwallet.seeds import BIP39Seed, SLIP39Seed |
6 | 6 | from hdwallet.cryptocurrencies import Ethereum as Cryptocurrency |
7 | 7 | from hdwallet.hds import BIP44HD |
8 | 8 | from hdwallet.derivations import ( |
|
15 | 15 | MNEMONIC: str = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon " \ |
16 | 16 | "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art" |
17 | 17 |
|
18 | | -# Initialize Ethereum HDWallet |
| 18 | +# Initialize Ethereum HDWallet using BIP-39 Entropy as Seed |
19 | 19 | hdwallet: HDWallet = HDWallet( |
20 | 20 | cryptocurrency=Cryptocurrency, |
21 | 21 | hd=BIP44HD, |
22 | 22 | network=Cryptocurrency.NETWORKS.MAINNET, |
23 | 23 | passphrase=None |
24 | 24 | ).from_seed( # Get Ethereum HDWallet from seed |
25 | | - seed=BIP39Seed( |
| 25 | + seed=SLIP39Seed( |
26 | 26 | seed=BIP39Mnemonic.decode(mnemonic=MNEMONIC) # Use decoded mnemonic (entropy) directly as seed |
27 | 27 | ) |
28 | 28 | ).from_derivation( # Drive from BIP44 derivation |
|
36 | 36 |
|
37 | 37 | # Same address of Brave crypto wallets extension |
38 | 38 | # print(json.dumps(hdwallet.dump(exclude={"indexes"}), indent=4, ensure_ascii=False)) |
| 39 | +print(f"Path: {hdwallet.path()}") |
39 | 40 | print(f"Address: {hdwallet.address()}") |
| 41 | + |
| 42 | +assert hdwallet.address() == "0xACA6302EcBde40120cb8A08361D8BD461282Bd18" |
| 43 | + |
| 44 | +# Initialize Ethereum HDWallet using BIP-39 Seed (confirmed current Brave Wallet behavior) |
| 45 | +hdwallet: HDWallet = HDWallet( |
| 46 | + cryptocurrency=Cryptocurrency, |
| 47 | + hd=BIP44HD, |
| 48 | + network=Cryptocurrency.NETWORKS.MAINNET, |
| 49 | + passphrase=None |
| 50 | +).from_seed( # Get Ethereum HDWallet from seed |
| 51 | + seed=BIP39Seed.from_mnemonic(mnemonic=MNEMONIC) # Use BIP-39 encoded mnemonic as seed |
| 52 | +).from_derivation( # Drive from BIP44 derivation |
| 53 | + derivation=BIP44Derivation( |
| 54 | + coin_type=Cryptocurrency.COIN_TYPE, |
| 55 | + account=0, |
| 56 | + change=CHANGES.EXTERNAL_CHAIN, |
| 57 | + address=0 |
| 58 | + ) |
| 59 | +) |
| 60 | + |
| 61 | +# print(json.dumps(hdwallet.dump(exclude={"indexes"}), indent=4, ensure_ascii=False)) |
| 62 | +print(f"Address: {hdwallet.address()}") |
| 63 | +assert hdwallet.address() == "0xF278cF59F82eDcf871d630F28EcC8056f25C1cdb" |
0 commit comments