Skip to content

Commit

Permalink
feat: add gcp-signer
Browse files Browse the repository at this point in the history
  • Loading branch information
Adegbite Ademola Kelvin authored and Adegbite Ademola Kelvin committed Dec 9, 2024
1 parent 5a6776f commit 5453322
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ alloy = { version = "0.7", features = [
"signer-mnemonic",
"signer-trezor",
"signer-yubihsm",
"signer-gcp"
] }

foundry-fork-db = "0.8"
Expand Down
4 changes: 4 additions & 0 deletions examples/wallets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ workspace = true

[dev-dependencies]
alloy.workspace = true
gcloud-sdk = {version = "0.25.0", features = [
"google-cloud-kms-v1",
"google-longrunning"
]}

aws-config = { version = "1.5", default-features = false }
aws-sdk-kms = { version = "1.50", default-features = false }
Expand Down
32 changes: 32 additions & 0 deletions examples/wallets/examples/gcp_signer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//! Example of how to use GCP Ethereum Signer.
use alloy::signers::gcp::{GcpKeyRingRef, GcpSigner, KeySpecifier};
use alloy::signers::Signer;
use gcloud_sdk::{
google::cloud::kms::v1::key_management_service_client::KeyManagementServiceClient, GoogleApi,
};

#[tokio::main]
async fn main() {
// environment variable, preferably to be set in a dotenv file
let project_id = "GOOGLE_PROJECT_ID";
let location = "GOOGLE_LOCATION";
let keyring = "GOOGLE_KEYRING";
let key_name = "GOOGLE_KEY_NAME";

let keyring = GcpKeyRingRef::new(&project_id, &location, &keyring);
let client = GoogleApi::from_function(
KeyManagementServiceClient::new,
"https://cloudkms.googleapis.com",
None,
)
.await
.expect("Failed to create GCP KMS Client");

let key_version = 1;

let specifier = KeySpecifier::new(keyring, &key_name, key_version);
let signer = GcpSigner::new(client, specifier, Some(key_version)).await.expect("get_key");
let message = vec![0, 1, 2, 3];
let sig = signer.sign_message(&message).await.unwrap();
assert_eq!(sig.recover_address_from_msg(message).unwrap(), signer.address());
}

0 comments on commit 5453322

Please sign in to comment.