Skip to content

Commit a77430d

Browse files
author
Yuanheng Wang
committed
fixing ExtendedSigning key from_hdwallet func
1 parent d62e2a1 commit a77430d

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

pycardano/key.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,15 @@ def from_hdwallet(cls, hdwallet: HDWallet) -> ExtendedSigningKey:
192192
"The hdwallet doesn't contain extended private key or chain code info."
193193
)
194194

195-
return Key(
195+
# return Key(
196+
# payload=hdwallet.xprivate_key + hdwallet.public_key + hdwallet.chain_code,
197+
# key_type="PaymentExtendedSigningKeyShelley_ed25519_bip32",
198+
# description="Payment Signing Key",
199+
# )
200+
201+
return cls(
196202
payload=hdwallet.xprivate_key + hdwallet.public_key + hdwallet.chain_code,
197-
type="PaymentExtendedSigningKeyShelley_ed25519_bip32",
203+
key_type="PaymentExtendedSigningKeyShelley_ed25519_bip32",
198204
description="Payment Signing Key",
199205
)
200206

test/pycardano/backend/test_bip32.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from pycardano.address import Address
22
from pycardano.crypto.bip32 import HDWallet
3-
from pycardano.key import PaymentVerificationKey
3+
from pycardano.key import ExtendedSigningKey, PaymentVerificationKey
44
from pycardano.network import Network
55

66
# Tests copied from: https://github.com/Emurgo/cardano-serialization-lib/blob/master/rust/src/address.rs
@@ -108,3 +108,21 @@ def test_payment_address_24_base():
108108
Address(spend_vk.hash(), stake_vk.hash(), network=Network.MAINNET).encode()
109109
== "addr1qyy6nhfyks7wdu3dudslys37v252w2nwhv0fw2nfawemmn8k8ttq8f3gag0h89aepvx3xf69g0l9pf80tqv7cve0l33sdn8p3d"
110110
)
111+
112+
113+
def test_payment_address_24_base_2():
114+
hdwallet = HDWallet.from_mnemonic(MNEMONIC_24)
115+
hdwallet_spend = hdwallet.derive_from_path("m/1852'/1815'/0'/0/0")
116+
spend_extended_sk = ExtendedSigningKey.from_hdwallet(hdwallet_spend)
117+
spend_extended_vk = spend_extended_sk.to_verification_key()
118+
119+
hdwallet_stake = hdwallet.derive_from_path("m/1852'/1815'/0'/2/0")
120+
stake_extended_sk = ExtendedSigningKey.from_hdwallet(hdwallet_stake)
121+
stake_extended_vk = stake_extended_sk.to_verification_key()
122+
123+
assert (
124+
Address(
125+
spend_extended_vk.hash(), stake_extended_vk.hash(), network=Network.MAINNET
126+
).encode()
127+
== "addr1qyy6nhfyks7wdu3dudslys37v252w2nwhv0fw2nfawemmn8k8ttq8f3gag0h89aepvx3xf69g0l9pf80tqv7cve0l33sdn8p3d"
128+
)

0 commit comments

Comments
 (0)