Cloud HSM to sign Web3.py Ethereum transactions
Project description
web3-google-hsm
Description
A Python library for using Google Cloud HSM services to sign Ethereum transactions.
Features
- Cloud HSM integration for secure key management.
- Support for web3-google-hsm (extensible to other providers).
- Type-safe configuration using Pydantic.
Installation
- Install using
pip
pip install web3-google-hsm
Usage
Environment Setup
Google Cloud HSM Key
Make sure you have created a key of type ec-sign-secp256k1-sha256
in the Google cloud console. Which will look something like the following
Required Environment Variables
Before using this library, you need to set up the following environment variables:
GOOGLE_CLOUD_PROJECT=your-project-id
GOOGLE_CLOUD_REGION=us-east1
KEY_RING=eth-keyring
KEY_NAME=eth-key
GOOGLE_APPLICATION_CREDENTIALS=path/to/your/service-account.json
Bash
# Add to ~/.bashrc or ~/.bash_profile
export GOOGLE_CLOUD_PROJECT="your-project-id"
export GOOGLE_CLOUD_REGION="us-east1"
export KEY_RING="eth-keyring"
export KEY_NAME="eth-key"
export GOOGLE_APPLICATION_CREDENTIALS="path/to/your/service-account.json"
# Apply changes
source ~/.bashrc # or source ~/.bash_profile
Zsh
# Add to ~/.zshrc
export GOOGLE_CLOUD_PROJECT="your-project-id"
export GOOGLE_CLOUD_REGION="us-east1"
export KEY_RING="eth-keyring"
export KEY_NAME="eth-key"
export GOOGLE_APPLICATION_CREDENTIALS="path/to/your/service-account.json"
# Apply changes
source ~/.zshrc
Fish
# Add to ~/.config/fish/config.fish
set -x GOOGLE_CLOUD_PROJECT "your-project-id"
set -x GOOGLE_CLOUD_REGION "us-east1"
set -x KEY_RING "eth-keyring"
set -x KEY_NAME "eth-key"
set -x GOOGLE_APPLICATION_CREDENTIALS "path/to/your/service-account.json"
set -x INFURA_KEY "your-infura-key"
set -x WEB3_PROVIDER_URI "https://mainnet.infura.io/v3/$INFURA_KEY"
# Apply changes
source ~/.config/fish/config.fish
Using .env File
You can also create a .env file in your project root:
# .env
GOOGLE_CLOUD_PROJECT=your-project-id
GOOGLE_CLOUD_REGION=us-east1
KEY_RING=eth-keyring
KEY_NAME=eth-key
GOOGLE_APPLICATION_CREDENTIALS=path/to/your/service-account.json
Then load it in your Python code:
from dotenv import load_dotenv
load_dotenv()
Environment Variable Descriptions
GOOGLE_CLOUD_PROJECT: Your Google Cloud project IDGOOGLE_CLOUD_REGION: The region where your KMS resources are located (e.g., us-east1, europe-west1)KEY_RING: The name of your KMS key ringKEY_NAME: The name of your KMS keyGOOGLE_APPLICATION_CREDENTIALS: Path to your Google Cloud service account JSON key file
Verifying Setup
You can verify your environment setup with:
from web3_google_hsm.config import BaseConfig
try:
config = BaseConfig()
print("Environment configured successfully!")
print(f"Project ID: {config.project_id}")
print(f"Region: {config.location_id}")
except ValueError as e:
print(f"Configuration error: {e}")
For more information see the following links.
Documentation: https://Aviksaikat.github.io/web3-google-hsm/
Source Code: https://github.com/Ankvik-Tech-Labs/web3-google-hsm
Development
Development
Setup environment
We use Hatch to manage the development environment and production build. Ensure it's installed on your system.
Run unit tests
You can run all the tests with:
hatch run test
Format the code
Execute the following command to apply linting and check typing:
hatch run lint
Publish a new version
You can bump the version, create a commit and associated tag with one command:
hatch version patch
hatch version minor
hatch version major
Your default Git text editor will open so you can add information about the release.
When you push the tag on GitHub, the workflow will automatically publish it on PyPi and a GitHub release will be created as draft.
Serve the documentation
You can serve the Mkdocs documentation with:
hatch run docs-serve
It'll automatically watch for changes in your code.
License
This project is licensed under the terms of the BSD license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file web3_google_hsm-0.0.1.tar.gz.
File metadata
- Download URL: web3_google_hsm-0.0.1.tar.gz
- Upload date:
- Size: 105.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b87b0015cbacd6846a1b2d2bb9843e388550ad0dbcd18170989455919ec92f17
|
|
| MD5 |
17a655bde4068baf804fecb281f2f3fb
|
|
| BLAKE2b-256 |
a353df1c78b9ad66398067cf56575b619dcc51cd26f286bc6287291b7da8413a
|
File details
Details for the file web3_google_hsm-0.0.1-py3-none-any.whl.
File metadata
- Download URL: web3_google_hsm-0.0.1-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53d81b813d92994e8319c1cdae27e60797a028d1959efee2bc7b06970cc0ea0b
|
|
| MD5 |
6df140d95dae47e8b9c620d1e6df0239
|
|
| BLAKE2b-256 |
60ddbbe6f9f3f5582ad3a8f1e49dc480abdf6c0711b61df02db62fd756263563
|