File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
src/hiero_sdk_python/crypto Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,26 @@ def from_bytes(cls, key_bytes: bytes):
5959 except Exception as e :
6060 raise ValueError (f"Failed to load public key (DER): { e } " )
6161
62+ @classmethod
63+ def from_string (cls , key_str ):
64+ """
65+ Load a public key from a hex-encoded string.
66+ For Ed25519, expects 32 bytes. Raw bytes string for ECDSA is not supported for now.
67+ If the key is DER-encoded, tries to parse and detect Ed25519 vs ECDSA.
68+ Args:
69+ key_str (str): The hex-encoded public key string.
70+ Returns:
71+ PublicKey: A new instance of PublicKey.
72+ Raises:
73+ ValueError: If the key is invalid or unsupported.
74+ """
75+ try :
76+ key_bytes = bytes .fromhex (key_str .removeprefix ("0x" ))
77+ except ValueError :
78+ raise ValueError ("Invalid hex-encoded public key string." )
79+
80+ return cls .from_bytes (key_bytes )
81+
6282 def verify (self , signature : bytes , data : bytes ) -> None :
6383 """
6484 Verifies a signature for the given data using this public key.
You can’t perform that action at this time.
0 commit comments