33from itertools import chain
44from typing import TYPE_CHECKING , ClassVar
55
6- from ape .types import AddressType
6+ from ape .types import AddressType , HexBytes
77from botocore .exceptions import BotoCoreError # type: ignore[import-untyped]
88from pydantic import BaseModel , Field , SecretStr , field_validator
99
@@ -104,8 +104,12 @@ def set_alias(self, alias: str):
104104 self .cached_alias = alias
105105
106106 @property
107- def public_key (self ):
108- return self .kms_client .get_public_key (KeyId = self .id )["PublicKey" ]
107+ def public_key (self ) -> HexBytes :
108+ try :
109+ return HexBytes (self .kms_client .get_public_key (KeyId = self .id )["PublicKey" ][- 64 :])
110+ except (self .kms_client .exceptions .KMSInvalidStateException , BotoCoreError ) as e :
111+ # NOTE: Handle here since `.keys` is the main access point for the external API
112+ raise AwsAccessError (e ) from e
109113
110114 @property
111115 def address (self ) -> AddressType :
@@ -114,7 +118,7 @@ def address(self) -> AddressType:
114118
115119 from eth_utils import keccak , to_checksum_address
116120
117- return AddressType (to_checksum_address (keccak (self .public_key [ - 64 :] )[- 20 :]. hex (). lower () ))
121+ return AddressType (to_checksum_address (keccak (self .public_key )[- 20 :]))
118122
119123 def add_tags (self , tags : list [dict [str , str ]]):
120124 self .kms_client .tag_resource (KeyId = self .id , Tags = tags )
0 commit comments