Replies: 1 comment
-
|
Derivation requires the chain-code, turn the private key into an extended (x) private key, then proceed to derive. #!/usr/bin/env python3
from hdwallet import HDWallet
from hdwallet.cryptocurrencies import Bitcoin as Cryptocurrency
from hdwallet.derivations import BIP44Derivation, CHANGES
from hdwallet.consts import PUBLIC_KEY_TYPES
from hdwallet.hds import BIP44HD
from hdwallet.keys import serialize
from hdwallet.utils import integer_to_bytes
master_private_key_hex = "7c8b1b8348631aa09e98cf4e86858e22c6d8b382d2228df561ded313272ed20c"
master_chain_code_hex = "22938455321020ade51c052afdbb95f6b9c32ee42ec6f979c2de4ef6a605a087"
master_xprivate_key_hex = serialize(
version=integer_to_bytes(
Cryptocurrency.NETWORKS.MAINNET.XPRIVATE_KEY_VERSIONS.P2PKH
),
depth=0,
parent_fingerprint="00000000",
index=0,
chain_code=master_chain_code_hex,
key="00" + master_private_key_hex,
encoded=True
)
master_public_key_x_hex = "8fc6455779401f53aa4d54447b8e548b5a4dd5af80b91209f3a3abde74ce7353"
master_public_key_y_hex = "a165346d0f3dd44fd8d97900d00e324f712d926b01f3b0cfebbdbd4dabdaa18c"
path = "0"
child_chain_code_hex = "03786e91869cb5d09d1613920f331276e05c5469e844acc25620f013a4cb041d9f"
child_public_key_x_hex = "dfad72df0c7d16b9eb1d406fa674e2fabed4c96188d19e55228d1816a36d0b94"
child_public_key_y_hex = "8f7564d215755b1a49cd197c109cc54b1346aad41baba40b75ece2a7cf7319b9"
hdwallet: HDWallet = HDWallet(
cryptocurrency=Cryptocurrency,
hd=BIP44HD,
network=Cryptocurrency.NETWORKS.MAINNET,
public_key_type=PUBLIC_KEY_TYPES.COMPRESSED,
).from_xprivate_key(
xprivate_key=master_xprivate_key_hex
)
uncompressed_root_pub_key = hdwallet.root_public_key(PUBLIC_KEY_TYPES.UNCOMPRESSED)
raw_bytes = bytes.fromhex(uncompressed_root_pub_key)
root_x_coord_uncompressed = raw_bytes[1:33].hex()
root_y_coord_uncompressed = raw_bytes[33:65].hex()
assert(hdwallet.root_chain_code()==master_chain_code_hex)
assert(root_x_coord_uncompressed==master_public_key_x_hex)
assert(root_y_coord_uncompressed==master_public_key_y_hex)
hdwallet.from_derivation(
derivation=BIP44Derivation(
coin_type=Cryptocurrency.COIN_TYPE,
account=0,
change=CHANGES.EXTERNAL_CHAIN,
address=0
)
) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have this data from another library:
And I want to reproduce the same result using hdwallet.
Here I can I create the private key and check its public key coordinates are correct:
The above asserts pass successfully. But when I try to test the HD derivation using the code below:
It raises this error:
How should I set the root_private_key and root_chain_code? It'd be appreciated if you help me complete the above example, please. A colab notebook is ready here for your convenience.
Beta Was this translation helpful? Give feedback.
All reactions