EthKmsClient
EthKmsClient
__init__(self, aws_access_key_id=None, aws_secret_access_key=None, region_name=None, boto_kms_client=None)
special
Client allows you to interact with AWS KMS resources.
Parameters: |
|
---|
Source code in eth_kms_signer/signer.py
def __init__(
self,
aws_access_key_id=None,
aws_secret_access_key=None,
region_name=None,
boto_kms_client=None,
):
"""Client allows you to interact with AWS KMS resources.
Args:
aws_access_key_id (str, optional): AWS access key ID
aws_secret_access_key (str, optional): AWS secret access key
region_name (str, optional): Default region when creating new connections
boto_kms_client (Any, optional): Use this client instead of creating new one
"""
if boto_kms_client is not None:
self.client = boto_kms_client
else:
self.client = boto3.client(
"kms",
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
region_name=region_name,
)
get_address(self, key_id)
Get checksummed address for a KMS KeyId
Parameters: |
|
---|
Returns: |
|
---|
Source code in eth_kms_signer/signer.py
def get_address(self, key_id: str) -> ChecksumAddress:
"""Get checksummed address for a KMS KeyId
Args:
key_id (str): KeyID for which the address needs to be retrieved
Returns:
ChecksumAddress: Checksummed address
"""
return get_address_from_pub(self.get_public_key(key_id))
get_public_key(self, key_id)
Get public key for a key id in AWS KMS
Parameters: |
|
---|
Returns: |
|
---|
Source code in eth_kms_signer/signer.py
def get_public_key(self, key_id: str) -> bytes:
"""Get public key for a key id in AWS KMS
Args:
key_id (str): KeyID for which the public key needs to be retrieved
Returns:
bytes: Uncompressed public key
"""
response = self.client.get_public_key(KeyId=key_id)
pem = base64.b64encode((response.get("PublicKey")))
key = VerifyingKey.from_pem(pem).to_string()
return key
sign_transaction(self, tx, key_id)
Sign an ETH transaction using the Key ID in AWS KMS
Parameters: |
|
---|
Returns: |
|
---|
Source code in eth_kms_signer/signer.py
def sign_transaction(self, tx: Dict, key_id: str) -> bytes:
"""Sign an ETH transaction using the Key ID in AWS KMS
Args:
tx (Dict): Dictionary representing the tx
key_id (str): KeyID to be used for signing
Returns:
bytes: Signed transaction
"""
if "type" in tx and hexstr_if_str(to_int)(tx["type"]) != "0x0":
return self._sign_typed_transaction(tx, key_id)
return self._sign_legacy_transaction(tx, key_id)