Package: eth-signer
eth-signerA Python library for transaction signing using AWS Key Management Service.DependenciesPython 3.6+QuickStartThis Package is available onPyPI. Install via pip as:pipinstalleth-signerUsageeth-signerneeds AWS-KMS Client Object fromboto3to sign Ethereum transaction or message.In the following example, the Basic use ofeth-signerwithboto3has been given.Step - 1 :  Install required dependencies$pip3installboto3eth-signerweb3Step - 2 : Create a new key pair using boto3 ( Optional )importboto3frometh_signer.signerimportAWSKMSKeyfromweb3importWeb3# Get a kms_client Object From boto3kms_client=boto3.client('kms','us-east-1')# Generate new Key Pair using kms_clientnew_key=kms.create_key(Description='New Eth Key',KeyUsage='SIGN_VERIFY',KeySpec='ECC_SECG_P256K1',Origin='AWS_KMS',MultiRegion=False)# Use KekId of newly generated key pair for AWSKMSKey Objectkey_id=new_key['KeyMetadata']['KeyId']kms_signer=AWSKMSKey(kms_client,key_id)# Print Key ID and Eth addressprint("KeyId: ",key_id)print("Eth Address: ",kms_signer.address)Output:KeyId:af8929db-010c-4476-00X0-0X00000X00X0EthAddress:0x40532E26c7100D72ee1CF91Ed65b44A4aEAC2b0fStep - 3 : Send a new transaction using web3, boto3 and eth-signerExample 1: Transfer 0.01 ETH from AWS KMS managed Ethereum Account to another Ethereum Account. ( Please, do make you have sufficient balance in Account before executing the example code.)importboto3frometh_signer.signerimportAWSKMSKeyfromweb3importWeb3# Get a kms_client Object From boto3kms_client=boto3.client('kms','us-east-1')# User a KeyId of the AWS KMS Keykey_id='af8929db-010c-4476-00X0-0X00000X00X0'kms_signer=AWSKMSKey(kms_client,key_id)web3=Web3(Web3.HTTPProvider('https://ropsten.infura.io/v3/<PROJECT_ID>'))nonce=web3.eth.get_transaction_count(kms_signer.address)print(web3.eth.getBalance(kms_signer.address))# build a transaction in a dictionarytx_obj={"nonce":nonce,"from":kms_signer.address,"to":'0xBe0745cF5b82aB1de6fB1CEd849081BE06d9b3be',"value":web3.toWei(0.01,"ether"),"gas":200000,"gasPrice":web3.toWei("50","gwei"),}signed_tx=kms_signer.sign_transaction(tx_obj)tx_hash=web3.eth.send_raw_transaction(signed_tx.rawTransaction)print("https://ropsten.etherscan.io/tx/"+tx_hash.hex())Output:34750000000000000https://ropsten.etherscan.io/tx/0x826a52e59431a4be8780807cdd09da01d0dbbb00848fd7c9dff8383869c7372cTransaction onetherscan.ioExample 2: Transfer 0.01 ETH from AWS KMS managed Ethereum Account to another Ethereum Account. ( Please, do make you have sufficient balance in Account before executing the example code.) (Using EIP-1559 Dynamic fee transaction)importboto3frometh_signer.signerimportAWSKMSKeyfromweb3importWeb3# Get a kms_client Object From boto3kms_client=boto3.client('kms','us-east-1')# User a KeyId of the AWS KMS Keykey_id='af8929db-010c-4476-00X0-0X00000X00X0'kms_signer=AWSKMSKey(kms_client,key_id)web3=Web3(Web3.HTTPProvider('https://ropsten.infura.io/v3/<PROJECT_ID>'))nonce=web3.eth.get_transaction_count(kms_signer.address)print(web3.eth.getBalance(kms_signer.address))# build a transaction in a dictionarytx_obj={"nonce":nonce,"from":kms_signer.address,"to":"0xBe0745cF5b82aB1de6fB1CEd849081BE06d9b3be","value":web3.toWei(12,"wei"),"gas":25000,"maxFeePerGas":web3.toWei(5,"gwei"),"maxPriorityFeePerGas":web3.toWei(5,"gwei"),"type":"0x2",# ChainId "0x3" for ropsten chain"chainId":"0x3",}signed_tx=kms_signer.sign_transaction(tx_obj)tx_hash=web3.eth.send_raw_transaction(signed_tx.rawTransaction)print("https://ropsten.etherscan.io/tx/"+tx_hash.hex())Output:34750000000000000https://ropsten.etherscan.io/tx/0xb7248612afb1b8ff2388b9ddfed6127c8b8d4e6dcc609816fd421cd6c1e8b3f1Transaction onetherscan.ioExample 3 : Sign and Verify a Messageimportboto3frometh_account.messagesimportencode_defunctfromweb3.autoimportw3# Get a kms_client Object From boto3kms_client=boto3.client('kms','us-east-1')# User a KeyId of the AWS KMS Keykey_id='af8929db-010c-4476-00X0-0X00000X00X0'kms_signer=AWSKMSKey(kms_client,key_id)msg="From eth-signer"message=encode_defunct(text=msg)# Sign a Messagesigned_message=kms_signer.sign_message(message)# Recover Eth address from original message and Signatureeth_address=w3.eth.account.recover_message(message,signature=signed_message.signature)print("Eth Address: ",eth_address)# Recover Eth address from signed messageeth_address=w3.eth.account.recoverHash(signed_message.messageHash,signature=signed_message.signature)print("Eth Address: ",eth_address)Output:EthAddress:0x40532E26c7100D72ee1CF91Ed65b44A4aEAC2b0fEthAddress:0x40532E26c7100D72ee1CF91Ed65b44A4aEAC2b0fFeaturesSupport for Ethereum Transaction and Message Signing using AWS Key Management ServiceContributorsKalpesh SejpalMedium Article from Lucas HenningRuntime dependenciesThe distributed eth-signer contains software from the following projects from PyPi:eth-utilseth-typinghexbyteseth-rlppycryptodomeboto3flake8isortmypySphinxsphinx_rtd_themetowncrierbumpversionsetuptoolstoxtwine