Skip to content

Commit

Permalink
bug: Using p instead of n for addmod
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu committed Feb 3, 2020
1 parent aec0ddf commit 8319c4a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion eth_account/hdaccount/deterministic.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
keys,
)

SECP256K1_N = 2**256 - 2**32 - 2**9 - 2**8 - 2**7 - 2**6 - 2**4 - 1
SECP256K1_N = int("FFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFE_BAAEDCE6_AF48A03B_BFD25E8C_D0364141", 16)


def hmac_sha512(chain_code: bytes, data: bytes) -> bytes:
Expand Down Expand Up @@ -155,6 +155,8 @@ def derive_child_key(
assert len(ec_point(parent_key)) == 33 # Should be guarenteed by Account class
child = hmac_sha512(parent_chain_code, ec_point(parent_key) + node.serialize())

assert len(child) == 64

if to_int(child[:32]) >= SECP256K1_N:
# Invalid key, compute using next node (< 2**-127 probability)
return derive_child_key(parent_key, parent_chain_code, node + 1)
Expand Down

0 comments on commit 8319c4a

Please sign in to comment.