Crates.io | evm-signer-kms |
lib.rs | evm-signer-kms |
version | 0.3.0 |
source | src |
created_at | 2024-10-11 06:18:47.583431 |
updated_at | 2024-11-01 00:14:36.833575 |
description | EVM signer using keys from AWS KMS |
homepage | https://github.com/orlowskilp/evm-signer-kms |
repository | https://github.com/orlowskilp/evm-signer-kms |
max_upload_size | |
id | 1404976 |
size | 99,559 |
EVM transaction signing library using key pairs generated and stored in AWS KMS.
Built for:
Works with MUSL and GNU tool chains.
I suggest using the provided Makefile
to get things running fast. The default build
target is x86_64-unknown-linux-gnu
, so this command will build the library with the GNU tool
chain:
make build
If you wish to build it with a different tool chain, it suffices to specify it with the TOOL_CHAIN
environment variable, e.g.:
TOOL_CHAIN=x86_64-unknown-linux-musl make build
The library communicates with AWS KMS API endpoints and thus requires authorization. Additionally it requires AWS region and KMS key ID to be specified in the environment. This is because it was designed with containers and container orchestration in mind.
There are good chances that you will want to inject some secrets into the client application in the container orchestration solution (e.g. using AWS Secrets Manager or HashiCorp Vault).
At the very least the key policy must allow these actions for the IAM role which you are going to use as the principal (see documentation for more details):
kms:DescribeKey
kms:GetPublicKey
kms:Sign
kms:Verify
I suggest using STS to assume a role which is granted permissions to use the secp256k1 key pair in KMS. Once the IAM role is set up, you can assume it by e.g. setting the following environment variables:
export AWS_ACCESS_KEY_ID="[REDACTED]"
export AWS_SECRET_ACCESS_KEY="[REDACTED]"
export AWS_SESSION_TOKEN="[REDACTED]"
The region needs to be inferred from the environment, e.g.:
export AWS_REGION="[REDACTED]"
The KMS key which is going to be used for message digests signing can be identified using a key ID in the UUID format:
export KMS_KEY_ID="[REDACTED]"
Note: The library doesn't understand the KMS_KEY_ID
variable itself, it is just a suggested
way to pass the key ID to the library logic (see examples in the
documentation) for more details.
The easiest way to check whether everything works the way it should is by running tests.
Before running the tests you need to download the public key PEM file and copy it to
./tests/data/pub-key.pem
and then decode it to ./tests/data/pub-key.der
.
Makefile
provides a directive for that:
make fetch-public-key
Once the PEM and DER files are there, run the tests with:
make test
Note: If you downloaded the PEM file using the management console it is going to have the following format:
-----BEGIN PUBLIC KEY-----
...
-----END PUBLIC KEY-----
You can use the supplied helper pem2der.sh
shell script:
cd tests/data
./scripts/pem2der.sh ./pub-key.pem > pub-key.der
If the tests pass, you're all set!
aarch64
support