Skip to content

Instantly share code, notes, and snippets.

@r-n-o
Last active May 30, 2023 21:16
Show Gist options
  • Save r-n-o/53ebc92b92115b4c77314d6b4d56f9c8 to your computer and use it in GitHub Desktop.
Save r-n-o/53ebc92b92115b4c77314d6b4d56f9c8 to your computer and use it in GitHub Desktop.
HDWallet derivation

HDWallet derivation

This small script is proof that CB wallet does what I think it does, and using the standard derivation paths from BIP44.

And no. There are no assets associated with this seed phrase. Sorry.

#!/usr/bin/env python3
from hdwallet import HDWallet
from hdwallet.utils import generate_entropy
from hdwallet.symbols import ETH
from typing import Optional
from eth_account import Account
import secrets
import json
# import our mnemonic
wallet = HDWallet().from_mnemonic(mnemonic='dice work glue there kiwi shadow promote aim virtual fever oval fringe')
# That's our master seed!
print(wallet.seed())
# Derivation from path is also possible:
# wallet.from_path("m/44'/60'/0'/0/0").
# But doing it step-by-step is more educational.
wallet.from_index(44, hardened=True)
wallet.from_index(60, hardened=True)
wallet.from_index(0, hardened=True)
wallet.from_index(0)
# Change this to "1" or "2" or "3" to derive other addresses!
wallet.from_index(0)
# We should now be able to get the private key
print("Address 1 should have the following private key:", wallet.private_key())
# Derive our ETH address
private_key = "0x" + wallet.private_key()
eth_account = Account.from_key(private_key)
print("Address 1 should have the following ETH address:", eth_account.address)
python test.py
9a446cc1a7ef20bfe98ab357632b04bd6ef610be3d31d13507d539597640e49b2a4ad6a83d59d076498c53879208247d1cf929094a92daf11b7067e0a1f1ebc7
Address 1 should have the following private key: c4af5354df5dc2f2e8e4382b403effcf8221a49d37b22a9afaa0dc1ff70dad69
Address 1 should have the following ETH address: 0xedfB27C192D68B4D023945B618038BCfDB74e49e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment