From ee787c1aba62a2769513f6f9274885f4e618e405 Mon Sep 17 00:00:00 2001 From: moricho Date: Tue, 11 Jun 2024 16:20:55 +0900 Subject: [PATCH 1/5] Support gcp option in `cast wallet list` --- Cargo.lock | 1 + crates/cast/Cargo.toml | 4 ++++ crates/cast/bin/cmd/wallet/list.rs | 9 ++++++++- crates/wallets/src/multi_wallet.rs | 4 ++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 9869a2658dd67..ef9c1238c3472 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1930,6 +1930,7 @@ dependencies = [ "foundry-test-utils", "foundry-wallets", "futures", + "gcloud-sdk", "indicatif", "itertools 0.13.0", "rand", diff --git a/crates/cast/Cargo.toml b/crates/cast/Cargo.toml index 602ec57ae4952..f8032ad0382c7 100644 --- a/crates/cast/Cargo.toml +++ b/crates/cast/Cargo.toml @@ -62,6 +62,9 @@ serde.workspace = true # aws-kms aws-sdk-kms = { version = "1", default-features = false, optional = true } +# gcp-kms +gcloud-sdk = { version = "0.24", default-features = false, optional = true } + # bin foundry-cli.workspace = true @@ -96,6 +99,7 @@ openssl = ["foundry-cli/openssl"] asm-keccak = ["alloy-primitives/asm-keccak"] jemalloc = ["dep:tikv-jemallocator"] aws-kms = ["foundry-wallets/aws-kms", "dep:aws-sdk-kms"] +gcp-kms = ["foundry-wallets/gcp-kms", "dep:gcloud-sdk"] isolate-by-default = ["foundry-config/isolate-by-default"] [[bench]] diff --git a/crates/cast/bin/cmd/wallet/list.rs b/crates/cast/bin/cmd/wallet/list.rs index 88b9486058294..099e4647b4ab5 100644 --- a/crates/cast/bin/cmd/wallet/list.rs +++ b/crates/cast/bin/cmd/wallet/list.rs @@ -25,6 +25,10 @@ pub struct ListArgs { #[arg(long, hide = !cfg!(feature = "aws-kms"))] aws: bool, + /// List accounts from Google Cloud KMS. + #[arg(long, hide = !cfg!(feature = "gcp-kms"))] + gcp: bool, + /// List all configured accounts. #[arg(long, group = "hw-wallets")] all: bool, @@ -37,7 +41,10 @@ pub struct ListArgs { impl ListArgs { pub async fn run(self) -> Result<()> { // list local accounts as files in keystore dir, no need to unlock / provide password - if self.dir.is_some() || self.all || (!self.ledger && !self.trezor && !self.aws) { + if self.dir.is_some() || + self.all || + (!self.ledger && !self.trezor && !self.aws && !self.gcp) + { let _ = self.list_local_senders(); } diff --git a/crates/wallets/src/multi_wallet.rs b/crates/wallets/src/multi_wallet.rs index 459074aaa5848..42fe2a07248ae 100644 --- a/crates/wallets/src/multi_wallet.rs +++ b/crates/wallets/src/multi_wallet.rs @@ -221,6 +221,10 @@ pub struct MultiWalletOpts { /// Use AWS Key Management Service. #[arg(long, help_heading = "Wallet options - remote", hide = !cfg!(feature = "aws-kms"))] pub aws: bool, + + /// Use Google Cloud Key Management Service. + #[arg(long, help_heading = "Wallet options - remote", hide = !cfg!(feature = "gcp-kms"))] + pub gcp: bool, } impl MultiWalletOpts { From 4097318ae46bb3dd8aa00dccd68d656234e76d16 Mon Sep 17 00:00:00 2001 From: moricho Date: Sun, 23 Jun 2024 19:19:54 +0900 Subject: [PATCH 2/5] implement `gcp_sugners` to `MultiWalletOpts` --- crates/cast/bin/cmd/wallet/list.rs | 1 + crates/wallets/src/multi_wallet.rs | 31 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/crates/cast/bin/cmd/wallet/list.rs b/crates/cast/bin/cmd/wallet/list.rs index 099e4647b4ab5..20aa0b3e0051f 100644 --- a/crates/cast/bin/cmd/wallet/list.rs +++ b/crates/cast/bin/cmd/wallet/list.rs @@ -54,6 +54,7 @@ impl ListArgs { .mnemonic_indexes(Some(vec![0])) .trezor(self.trezor || self.all) .aws(self.aws || self.all) + .gcp(self.gcp || self.all) .interactives(0) .build() .expect("build multi wallet"); diff --git a/crates/wallets/src/multi_wallet.rs b/crates/wallets/src/multi_wallet.rs index 42fe2a07248ae..c7845e0836fed 100644 --- a/crates/wallets/src/multi_wallet.rs +++ b/crates/wallets/src/multi_wallet.rs @@ -242,6 +242,9 @@ impl MultiWalletOpts { if let Some(aws_signers) = self.aws_signers().await? { signers.extend(aws_signers); } + if let Some(gcp_signer) = self.gcp_signers().await? { + signers.extend(gcp_signer); + } if let Some((pending_keystores, unlocked)) = self.keystores()? { pending.extend(pending_keystores); signers.extend(unlocked); @@ -398,6 +401,34 @@ impl MultiWalletOpts { Ok(None) } + + // TODO: Support multiple keys + pub async fn gcp_signers(&self) -> Result>> { + #[cfg(feature = "gcp-kms")] + if self.gcp { + let mut wallets = vec![]; + + let project_id = std::env::var("GCP_PROJECT_ID")?; + let location = std::env::var("GCP_LOCATION")?; + let key_ring = std::env::var("GCP_KEY_RING")?; + let key_names = std::env::var("GCP_KEY_NAME")?; + let key_version = std::env::var("GCP_KEY_VERSION")?; + + let gcp_signer = WalletSigner::from_gcp( + project_id, + location, + key_ring, + key_names, + key_version.parse()?, + ) + .await?; + wallets.push(gcp_signer); + + return Ok(Some(wallets)); + } + + Ok(None) + } } #[cfg(test)] From 6c667f321767acb95e96d3b154973619601734f3 Mon Sep 17 00:00:00 2001 From: moricho Date: Sun, 14 Jul 2024 19:32:21 +0900 Subject: [PATCH 3/5] add comment --- crates/wallets/src/multi_wallet.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/wallets/src/multi_wallet.rs b/crates/wallets/src/multi_wallet.rs index c7845e0836fed..60de221d951c7 100644 --- a/crates/wallets/src/multi_wallet.rs +++ b/crates/wallets/src/multi_wallet.rs @@ -402,7 +402,16 @@ impl MultiWalletOpts { Ok(None) } - // TODO: Support multiple keys + /// Returns a list of GCP signers if the GCP flag is set. + /// + /// The GCP signers are created from the following environment variables: + /// - GCP_PROJECT_ID: The GCP project ID. e.g. `my-project-123456`. + /// - GCP_LOCATION: The GCP location. e.g. `us-central1`. + /// - GCP_KEY_RING: The GCP key ring name. e.g. `my-key-ring`. + /// - GCP_KEY_NAME: The GCP key name. e.g. `my-key`. + /// - GCP_KEY_VERSION: The GCP key version. e.g. `1`. + /// + /// For more information on GCP KMS, see the [official documentation](https://cloud.google.com/kms/docs). pub async fn gcp_signers(&self) -> Result>> { #[cfg(feature = "gcp-kms")] if self.gcp { From e2f5814304310dd0611692a73729658f49745a13 Mon Sep 17 00:00:00 2001 From: moricho Date: Mon, 15 Jul 2024 16:04:03 +0900 Subject: [PATCH 4/5] Make gcp option infallible if the env vars are missing --- crates/cast/bin/cmd/wallet/list.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/cast/bin/cmd/wallet/list.rs b/crates/cast/bin/cmd/wallet/list.rs index 20aa0b3e0051f..34d5732aa6ecf 100644 --- a/crates/cast/bin/cmd/wallet/list.rs +++ b/crates/cast/bin/cmd/wallet/list.rs @@ -1,5 +1,6 @@ use clap::Parser; use eyre::Result; +use std::env; use foundry_common::fs; use foundry_config::Config; @@ -54,7 +55,7 @@ impl ListArgs { .mnemonic_indexes(Some(vec![0])) .trezor(self.trezor || self.all) .aws(self.aws || self.all) - .gcp(self.gcp || self.all) + .gcp(self.gcp || (self.all && gcp_env_vars_set())) .interactives(0) .build() .expect("build multi wallet"); @@ -114,3 +115,10 @@ impl ListArgs { Ok(()) } } + +fn gcp_env_vars_set() -> bool { + let required_vars = + ["GCP_PROJECT_ID", "GCP_LOCATION", "GCP_KEY_RING", "GCP_KEY_NAME", "GCP_KEY_VERSION"]; + + required_vars.iter().all(|&var| env::var(var).is_ok()) +} From 84904b928cbb05b23c085f2ff92c4940ceef480e Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Tue, 15 Apr 2025 10:00:48 +0200 Subject: [PATCH 5/5] align version with Alloy --- Cargo.lock | 135 ++++---------------------------------- crates/cast/Cargo.toml | 2 +- crates/wallets/Cargo.toml | 2 +- 3 files changed, 13 insertions(+), 126 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6b5ccb70cb9e0..aecec4854cd7a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -617,7 +617,7 @@ dependencies = [ "alloy-primitives", "alloy-signer", "async-trait", - "gcloud-sdk 0.26.4", + "gcloud-sdk", "k256", "spki", "thiserror 2.0.12", @@ -982,7 +982,7 @@ dependencies = [ "anvil-rpc", "anvil-server", "async-trait", - "axum 0.7.9", + "axum", "chrono", "clap", "clap_complete", @@ -1054,7 +1054,7 @@ version = "1.1.0" dependencies = [ "anvil-rpc", "async-trait", - "axum 0.7.9", + "axum", "bytes", "clap", "futures", @@ -1746,7 +1746,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" dependencies = [ "async-trait", - "axum-core 0.4.5", + "axum-core", "base64 0.22.1", "bytes", "futures-util", @@ -1756,7 +1756,7 @@ dependencies = [ "hyper", "hyper-util", "itoa", - "matchit 0.7.3", + "matchit", "memchr", "mime", "percent-encoding", @@ -1776,32 +1776,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "axum" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de45108900e1f9b9242f7f2e254aa3e2c029c921c258fe9e6b4217eeebd54288" -dependencies = [ - "axum-core 0.5.2", - "bytes", - "futures-util", - "http 1.3.1", - "http-body 1.0.1", - "http-body-util", - "itoa", - "matchit 0.8.4", - "memchr", - "mime", - "percent-encoding", - "pin-project-lite", - "rustversion", - "serde", - "sync_wrapper", - "tower 0.5.2", - "tower-layer", - "tower-service", -] - [[package]] name = "axum-core" version = "0.4.5" @@ -1823,25 +1797,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "axum-core" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68464cd0412f486726fb3373129ef5d2993f90c34bc2bc1c1e9943b2f4fc7ca6" -dependencies = [ - "bytes", - "futures-core", - "http 1.3.1", - "http-body 1.0.1", - "http-body-util", - "mime", - "pin-project-lite", - "rustversion", - "sync_wrapper", - "tower-layer", - "tower-service", -] - [[package]] name = "backtrace" version = "0.3.71" @@ -2180,7 +2135,7 @@ dependencies = [ "foundry-test-utils", "foundry-wallets", "futures", - "gcloud-sdk 0.27.0", + "gcloud-sdk", "itertools 0.14.0", "rand 0.8.5", "rayon", @@ -3508,7 +3463,7 @@ dependencies = [ "alloy-signer-local", "alloy-transport", "anvil", - "axum 0.7.9", + "axum", "chrono", "clap", "clap_complete", @@ -3871,7 +3826,7 @@ dependencies = [ "anstream", "anstyle", "async-trait", - "axum 0.7.9", + "axum", "chrono", "clap", "comfy-table", @@ -4313,7 +4268,7 @@ dependencies = [ "eth-keystore", "eyre", "foundry-config", - "gcloud-sdk 0.27.0", + "gcloud-sdk", "rpassword", "serde", "thiserror 2.0.12", @@ -4483,35 +4438,7 @@ dependencies = [ "serde", "serde_json", "tokio", - "tonic 0.12.3", - "tower 0.5.2", - "tower-layer", - "tower-util", - "tracing", - "url", -] - -[[package]] -name = "gcloud-sdk" -version = "0.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00c7dc8c1f6c0865d02a2d931f3a15ac919ef583077c5141fd9b8efa8b493c44" -dependencies = [ - "async-trait", - "bytes", - "chrono", - "futures", - "hyper", - "jsonwebtoken", - "once_cell", - "prost", - "prost-types", - "reqwest", - "secret-vault-value", - "serde", - "serde_json", - "tokio", - "tonic 0.13.0", + "tonic", "tower 0.5.2", "tower-layer", "tower-util", @@ -5972,12 +5899,6 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" -[[package]] -name = "matchit" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" - [[package]] name = "md-5" version = "0.10.6" @@ -9412,7 +9333,7 @@ checksum = "877c5b330756d856ffcc4553ab34a5684481ade925ecc54bcd1bf02b1d0d4d52" dependencies = [ "async-stream", "async-trait", - "axum 0.7.9", + "axum", "base64 0.22.1", "bytes", "h2", @@ -9437,37 +9358,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "tonic" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85839f0b32fd242bb3209262371d07feda6d780d16ee9d2bc88581b89da1549b" -dependencies = [ - "async-trait", - "axum 0.8.3", - "base64 0.22.1", - "bytes", - "h2", - "http 1.3.1", - "http-body 1.0.1", - "http-body-util", - "hyper", - "hyper-timeout", - "hyper-util", - "percent-encoding", - "pin-project 1.1.10", - "prost", - "rustls-native-certs", - "socket2", - "tokio", - "tokio-rustls", - "tokio-stream", - "tower 0.5.2", - "tower-layer", - "tower-service", - "tracing", -] - [[package]] name = "topological-sort" version = "0.2.2" @@ -9502,12 +9392,9 @@ checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" dependencies = [ "futures-core", "futures-util", - "indexmap 2.9.0", "pin-project-lite", - "slab", "sync_wrapper", "tokio", - "tokio-util", "tower-layer", "tower-service", "tracing", diff --git a/crates/cast/Cargo.toml b/crates/cast/Cargo.toml index c9ef60a2ba2e8..407f448cfcbfa 100644 --- a/crates/cast/Cargo.toml +++ b/crates/cast/Cargo.toml @@ -64,7 +64,7 @@ serde.workspace = true aws-sdk-kms = { version = "1", default-features = false, optional = true } # gcp-kms -gcloud-sdk = { version = "0.27", default-features = false, optional = true } +gcloud-sdk = { version = "0.26.4", default-features = false, optional = true } # bin foundry-cli.workspace = true diff --git a/crates/wallets/Cargo.toml b/crates/wallets/Cargo.toml index 16ee875457698..4c3bdabd4bc1b 100644 --- a/crates/wallets/Cargo.toml +++ b/crates/wallets/Cargo.toml @@ -32,7 +32,7 @@ aws-sdk-kms = { version = "1", default-features = false, optional = true } # gcp-kms alloy-signer-gcp = { workspace = true, features = ["eip712"], optional = true } -gcloud-sdk = { version = "0.27", features = [ +gcloud-sdk = { version = "0.26.4", features = [ "google-cloud-kms-v1", "google-longrunning", ], optional = true }