This example demonstrates how to use a Google Cloud KMS key to securely sign transactions in OpenZeppelin Relayer.
- A Google Cloud account with KMS enabled
- Rust and Cargo installed
- Git
- Docker
- Docker Compose
Clone this repository to your local machine:
git clone https://github.com/OpenZeppelin/openzeppelin-relayer
cd openzeppelin-relayer- Go to the Google Cloud Console
- Create a new project or select an existing one
- Enable the Cloud KMS API for your project
- Create a Key Ring and a Key (for Solana use ED25519)
- Grant your service account the
Cloud KMS CryptoKey Signer/Verifierrole
- In the Google Cloud Console, go to IAM & Admin > Service Accounts
- Create a new service account or use an existing one
- Grant it access to your KMS key
- Create and download a JSON key for this service account
Create an environment file by copying the example:
cp examples/solana-google-cloud-kms-signer/.env.example examples/solana-google-cloud-kms-signer/.envEdit the config.json file and update the following variables:
{
"signers": [
{
"id": "google-cloud-kms-signer-solana",
"type": "google_cloud_kms",
"config": {
"service_account": {
"project_id": "your_project_id",
"private_key_id": {
"type": "env",
"value": "GOOGLE_CLOUD_KMS_PRIVATE_KEY_ID"
},
"private_key": {
"type": "env",
"value": "GOOGLE_CLOUD_KMS_PRIVATE_KEY"
},
"client_email": {
"type": "env",
"value": "GOOGLE_CLOUD_KMS_CLIENT_EMAIL"
},
"client_id": "your_client_id"
},
"key": {
"key_ring_id": "your_key_ring_id",
"key_id": "your_key_id"
}
}
}
]
}Populate .env file with config values for private_key_id, private_key and client_email.
Generate random keys for API authentication and webhook signing:
# Generate API key
cargo run --example generate_uuid
# Generate webhook signing key
cargo run --example generate_uuidAdd these to your .env file:
WEBHOOK_SIGNING_KEY=generated_webhook_key
API_KEY=generated_api_keyUpdate the examples/solana-google-cloud-kms-signer/config/config.json file with your webhook configuration:
- For testing, get a webhook URL from Webhook.site
- Update the config file:
{
"notifications": [
{
"url": "your_webhook_url"
}
]
}Start the service with Docker Compose:
docker compose -f examples/solana-google-cloud-kms-signer/docker-compose.yaml up- The service exposes a REST API
- You can test it using curl or any HTTP client:
curl -X GET http://localhost:8080/api/v1/relayers \
-H "Content-Type: application/json" \
-H "AUTHORIZATION: Bearer YOUR_API_KEY"If you encounter issues:
- Verify your Google Cloud KMS credentials and permissions are correct
- Check the service logs for detailed error messages
- Verify the transaction format matches the expected schema