Skip to content

Commit ae2aafb

Browse files
committed
fix: generate(ed25519)
Signed-off-by: exploreriii <[email protected]>
1 parent 8b956f3 commit ae2aafb

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

examples/account_create.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def create_new_account():
2121
operator_key = PrivateKey.from_string_ed25519(os.getenv('OPERATOR_KEY'))
2222
client.set_operator(operator_id, operator_key)
2323

24-
new_account_private_key = PrivateKey.generate_ed25519()
24+
new_account_private_key = PrivateKey.generate("ed25519")
2525
new_account_public_key = new_account_private_key.public_key()
2626

2727
transaction = (

examples/keys_private_der.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,50 @@
11
"""
22
Example file: Demonstrating how to serialize a PrivateKey to DER (hex)
33
and then load it back.
4-
*WARNING* DER seeds should not be printed or exposed in a realworld scenario
4+
*WARNING* DER‐encoded private keys should not be printed or exposed in a real-world scenario.
55
"""
6+
67
from cryptography.exceptions import InvalidSignature
78
from hiero_sdk_python.crypto.private_key import PrivateKey
89

910
def example_serialize_ed25519_der() -> None:
10-
1111
print("=== Ed25519: Serialize to DER ===")
12-
privkey = PrivateKey.generate_ed25519()
12+
13+
privkey = PrivateKey.generate("ed25519")
1314
print("Generated Ed25519 key:", privkey)
1415

15-
# Convert to DER (TraditionalOpenSSL)
16+
# This emits PKCS#8 DER by default
1617
der_bytes = privkey.to_bytes_der()
1718
print("DER bytes length =", len(der_bytes))
1819

1920
der_hex = der_bytes.hex()
2021
print("DER hex =", der_hex)
2122

22-
# Load it back
23+
# Load it back from hex
2324
privkey2 = PrivateKey.from_string_der(der_hex)
24-
print("Loaded back from DER =", privkey2)
25+
print("Loaded back from DER:", privkey2)
2526

26-
# Sign test
27+
# Sign & verify
2728
signature = privkey2.sign(b"test")
2829
privkey2.public_key().verify(signature, b"test")
2930
print("Ed25519 DER reload: Verified signature OK.\n")
3031

3132
def example_serialize_ecdsa_der() -> None:
32-
3333
print("=== ECDSA: Serialize to DER ===")
34-
privkey = PrivateKey.generate_ecdsa()
34+
35+
# use generate("ecdsa")
36+
privkey = PrivateKey.generate("ecdsa")
3537
print("Generated ECDSA key:", privkey)
3638

37-
# Convert to DER
3839
der_bytes = privkey.to_bytes_der()
40+
print("DER bytes length =", len(der_bytes))
41+
3942
der_hex = der_bytes.hex()
4043
print("DER hex =", der_hex)
4144

42-
# Load it back
4345
privkey2 = PrivateKey.from_string_der(der_hex)
44-
print("Loaded back from DER =", privkey2)
46+
print("Loaded back from DER:", privkey2)
4547

46-
# Sign test
4748
signature = privkey2.sign(b"hello ECDSA serialization")
4849
privkey2.public_key().verify(signature, b"hello ECDSA serialization")
4950
print("ECDSA DER reload: Verified signature OK.\n")

examples/query_balance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def create_account_and_transfer():
2626
client.set_operator(operator_id, operator_key)
2727

2828
# Create new account
29-
new_account_private_key = PrivateKey.generate_ed25519()
29+
new_account_private_key = PrivateKey.generate("ed25519")
3030
new_account_public_key = new_account_private_key.public_key()
3131
transaction = AccountCreateTransaction(
3232
key=new_account_public_key,

test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def load_operator_credentials():
8383

8484
def create_new_account(client, initial_balance=100000000):
8585
"""Tests account creation"""
86-
new_account_private_key = PrivateKey.generate_ed25519()
86+
new_account_private_key = PrivateKey.generate("ed25519")
8787

8888
new_account_public_key = new_account_private_key.public_key()
8989

0 commit comments

Comments
 (0)