eth_account.hdaccount package¶
Submodules¶
eth_account.hdaccount.deterministic module¶
Generate Heirarchical Deterministic Wallets (HDWallet).
Partially implements the BIP-0032, BIP-0043, and BIP-0044 specifications: BIP-0032: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki BIP-0043: https://github.com/bitcoin/bips/blob/master/bip-0043.mediawiki BIP-0044: https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
Skips serialization and public key derivation as unnecssary for this library’s purposes.
Notes¶
- Integers are modulo the order of the curve (referred to as n).
- Addition (+) of two coordinate pair is defined as application of the EC group operation.
- Concatenation (||) is the operation of appending one byte sequence onto another.
Definitions¶
- point(p): returns the coordinate pair resulting from EC point multiplication (repeated application of the EC group operation) of the secp256k1 base point with the integer p.
- ser_32(i): serialize a 32-bit unsigned integer i as a 4-byte sequence, most significant byte first.
- ser_256(p): serializes the integer p as a 32-byte sequence, most significant byte first.
- ser_P(P): serializes the coordinate pair P = (x,y) as a byte sequence using SEC1’s compressed form: (0x02 or 0x03) || ser_256(x), where the header byte depends on the parity of the omitted y coordinate.
- parse_256(p): interprets a 32-byte sequence as a 256-bit number, most significant byte first.
-
class
eth_account.hdaccount.deterministic.
HDPath
(path: str)¶ Bases:
object
-
derive
(seed: bytes) → bytes¶ Perform the BIP32 Heirarchical Derivation recursive loop with the given Path.
Note that the key and chain_code are initialized with the master seed, and that the key that is returned is the child key at the end of derivation process (and the chain code is discarded)
-
encode
() → str¶ Encodes this class to a string (reversing the decoding in the constructor).
-
-
class
eth_account.hdaccount.deterministic.
HardNode
¶ Bases:
eth_account.hdaccount.deterministic.Node
Hard node, where value = index + BIP32_HARDENED_CONSTANT .
-
OFFSET
= 2147483648¶
-
TAG
= 'H'¶
-
-
class
eth_account.hdaccount.deterministic.
Node
¶ Bases:
int
A base node class.
-
OFFSET
= 0¶
-
TAG
= ''¶
-
static
decode
(node: str) → Union[eth_account.hdaccount.deterministic.SoftNode, eth_account.hdaccount.deterministic.HardNode]¶
-
encode
() → str¶
-
serialize
() → bytes¶
-
-
class
eth_account.hdaccount.deterministic.
SoftNode
¶ Bases:
eth_account.hdaccount.deterministic.Node
Soft node (unhardened), where value = index .
-
OFFSET
= 0¶
-
TAG
= ''¶
-
-
eth_account.hdaccount.deterministic.
derive_child_key
(parent_key: bytes, parent_chain_code: bytes, node: eth_account.hdaccount.deterministic.Node) → Tuple[bytes, bytes]¶ Compute a derivitive key from the parent key.
From BIP32:
The function CKDpriv((k_par, c_par), i) → (k_i, c_i) computes a child extended private key from the parent extended private key:
- Check whether the child is a hardened key (i ≥ 2**31). If the child is a hardened key, let I = HMAC-SHA512(Key = c_par, Data = 0x00 || ser_256(k_par) || ser_32(i)). (Note: The 0x00 pads the private key to make it 33 bytes long.) If it is not a hardened key, then let I = HMAC-SHA512(Key = c_par, Data = ser_P(point(k_par)) || ser_32(i)).
- Split I into two 32-byte sequences, I_L and I_R.
- The returned child key k_i is parse_256(I_L) + k_par (mod n).
- The returned chain code c_i is I_R.
- In case parse_256(I_L) ≥ n or k_i = 0, the resulting key is invalid, and one should proceed with the next value for i. (Note: this has probability lower than 1 in 2**127.)
eth_account.hdaccount.mnemonic module¶
-
class
eth_account.hdaccount.mnemonic.
Mnemonic
(raw_language='english')¶ Bases:
object
-
classmethod
detect_language
(raw_mnemonic)¶
-
expand
(mnemonic)¶
-
expand_word
(prefix)¶
-
generate
(num_words: int = 12) → str¶
-
is_mnemonic_valid
(mnemonic)¶
-
static
list_languages
()¶
-
to_mnemonic
(entropy: bytes) → str¶
-
classmethod
-
eth_account.hdaccount.mnemonic.
get_wordlist
(language)¶