1212"""
1313
1414from dataclasses import dataclass , field
15- from typing import Optional , Any , List
15+ from typing import Optional , Any , List , Union
1616
1717from hiero_sdk_python .Duration import Duration
1818from hiero_sdk_python .channels import _Channel
2626from hiero_sdk_python .tokens .token_type import TokenType
2727from hiero_sdk_python .tokens .supply_type import SupplyType
2828from hiero_sdk_python .account .account_id import AccountId
29+ from hiero_sdk_python .crypto .public_key import PublicKey
2930from hiero_sdk_python .crypto .private_key import PrivateKey
3031from hiero_sdk_python .tokens .custom_fee import CustomFee
3132
3233AUTO_RENEW_PERIOD = Duration (7890000 ) # around 90 days in seconds
3334DEFAULT_TRANSACTION_FEE = 3_000_000_000
3435
36+ Key = Union [PublicKey , PrivateKey ]
37+
3538@dataclass
3639class TokenParams :
3740 """
@@ -81,14 +84,14 @@ class TokenKeys:
8184 kyc_key: The KYC key for the token to grant KYC to an account.
8285 """
8386
84- admin_key : Optional [PrivateKey ] = None
85- supply_key : Optional [PrivateKey ] = None
86- freeze_key : Optional [PrivateKey ] = None
87- wipe_key : Optional [PrivateKey ] = None
88- metadata_key : Optional [PrivateKey ] = None
89- pause_key : Optional [PrivateKey ] = None
90- kyc_key : Optional [PrivateKey ] = None
91- fee_schedule_key : Optional [PrivateKey ] = None
87+ admin_key : Optional [Key ] = None
88+ supply_key : Optional [Key ] = None
89+ freeze_key : Optional [Key ] = None
90+ wipe_key : Optional [Key ] = None
91+ metadata_key : Optional [Key ] = None
92+ pause_key : Optional [Key ] = None
93+ kyc_key : Optional [Key ] = None
94+ fee_schedule_key : Optional [Key ] = None
9295
9396class TokenCreateValidator :
9497 """Token, key and freeze checks for creating a token as per the proto"""
@@ -368,43 +371,43 @@ def set_memo(self, memo: str) -> "TokenCreateTransaction":
368371 self ._token_params .memo = memo
369372 return self
370373
371- def set_admin_key (self , key : PrivateKey ) -> "TokenCreateTransaction" :
374+ def set_admin_key (self , key : Key ) -> "TokenCreateTransaction" :
372375 """ Sets the admin key for the token, which allows updating and deleting the token."""
373376 self ._require_not_frozen ()
374377 self ._keys .admin_key = key
375378 return self
376379
377- def set_supply_key (self , key : PrivateKey ) -> "TokenCreateTransaction" :
380+ def set_supply_key (self , key : Key ) -> "TokenCreateTransaction" :
378381 """ Sets the supply key for the token, which allows minting and burning tokens."""
379382 self ._require_not_frozen ()
380383 self ._keys .supply_key = key
381384 return self
382385
383- def set_freeze_key (self , key : PrivateKey ) -> "TokenCreateTransaction" :
386+ def set_freeze_key (self , key : Key ) -> "TokenCreateTransaction" :
384387 """ Sets the freeze key for the token, which allows freezing and unfreezing accounts."""
385388 self ._require_not_frozen ()
386389 self ._keys .freeze_key = key
387390 return self
388391
389- def set_wipe_key (self , key : PrivateKey ) -> "TokenCreateTransaction" :
392+ def set_wipe_key (self , key : Key ) -> "TokenCreateTransaction" :
390393 """ Sets the wipe key for the token, which allows wiping tokens from an account."""
391394 self ._require_not_frozen ()
392395 self ._keys .wipe_key = key
393396 return self
394397
395- def set_metadata_key (self , key : PrivateKey ) -> "TokenCreateTransaction" :
398+ def set_metadata_key (self , key : Key ) -> "TokenCreateTransaction" :
396399 """ Sets the metadata key for the token, which allows updating NFT metadata."""
397400 self ._require_not_frozen ()
398401 self ._keys .metadata_key = key
399402 return self
400403
401- def set_pause_key (self , key : PrivateKey ) -> "TokenCreateTransaction" :
404+ def set_pause_key (self , key : Key ) -> "TokenCreateTransaction" :
402405 """ Sets the pause key for the token, which allows pausing and unpausing the token."""
403406 self ._require_not_frozen ()
404407 self ._keys .pause_key = key
405408 return self
406409
407- def set_kyc_key (self , key : PrivateKey ) -> "TokenCreateTransaction" :
410+ def set_kyc_key (self , key : Key ) -> "TokenCreateTransaction" :
408411 """ Sets the KYC key for the token, which allows granting KYC to an account."""
409412 self ._require_not_frozen ()
410413 self ._keys .kyc_key = key
@@ -416,26 +419,35 @@ def set_custom_fees(self, custom_fees: List[CustomFee]) -> "TokenCreateTransacti
416419 self ._token_params .custom_fees = custom_fees
417420 return self
418421
419- def set_fee_schedule_key (self , key : PrivateKey ) -> "TokenCreateTransaction" :
422+ def set_fee_schedule_key (self , key : Key ) -> "TokenCreateTransaction" :
420423 """Sets the fee schedule key for the token."""
421424 self ._require_not_frozen ()
422425 self ._keys .fee_schedule_key = key
423426 return self
424427
425- def _to_proto_key (self , private_key : Optional [PrivateKey ]) -> Optional [basic_types_pb2 .Key ]:
428+ def _to_proto_key (self , key : Optional [Key ]) -> Optional [basic_types_pb2 .Key ]:
426429 """
427- Helper method to convert a private key to protobuf Key format.
430+ Helper method to convert a PrivateKey or PublicKey to protobuf Key format.
428431
429432 Args:
430- private_key (PrivateKey , Optional): The private key to convert, or None
433+ key (Key , Optional): The private key or public key to convert, or None
431434
432435 Returns:
433- basic_types_pb2.Key (Optional): The protobuf key or None if private_key is None
436+ basic_types_pb2.Key (Optional): The protobuf key or None if key is None
434437 """
435- if not private_key :
438+ if not key :
436439 return None
437440
438- return private_key .public_key ()._to_proto ()
441+ # If PrivateKey, get public key first
442+ if isinstance (key , PrivateKey ):
443+ return key .public_key ()._to_proto ()
444+
445+ # If PublicKey, just convert it...
446+ if isinstance (key , PublicKey ):
447+ return key ._to_proto ()
448+
449+ # Handle any other case (though type hinting should prevent this)
450+ raise TypeError ("Key must be of type PrivateKey or PublicKey" )
439451
440452 def freeze_with (self , client ) -> "TokenCreateTransaction" :
441453 """
0 commit comments