Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion crates/cast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ alloy-provider = { workspace = true, features = [
"ws",
"ipc",
"trace-api",
"txpool-api"
"txpool-api",
] }
alloy-rlp.workspace = true
alloy-rpc-types = { workspace = true, features = ["eth", "trace"] }
Expand All @@ -63,6 +63,9 @@ serde.workspace = true
# aws-kms
aws-sdk-kms = { workspace = true, default-features = false, optional = true }

# gcp-kms
gcloud-sdk = { version = "0.26.4", default-features = false, optional = true }

# bin
foundry-cli.workspace = true

Expand Down Expand Up @@ -93,4 +96,5 @@ default = ["jemalloc"]
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"]
18 changes: 17 additions & 1 deletion crates/cast/src/cmd/wallet/list.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clap::Parser;
use eyre::Result;
use std::env;

use foundry_common::{fs, sh_err, sh_println};
use foundry_config::Config;
Expand All @@ -25,6 +26,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,
Expand All @@ -37,7 +42,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();
}

Expand All @@ -47,6 +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_env_vars_set()))
.interactives(0)
.build()
.expect("build multi wallet");
Expand Down Expand Up @@ -108,3 +117,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())
}
2 changes: 1 addition & 1 deletion crates/wallets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ aws-sdk-kms = { workspace = true, default-features = false, optional = true }

# gcp-kms
alloy-signer-gcp = { workspace = true, features = ["eip712"], optional = true }
gcloud-sdk = { version = "0.26", features = [
gcloud-sdk = { version = "0.26.4", features = [
"google-cloud-kms-v1",
"google-longrunning",
], optional = true }
Expand Down
44 changes: 44 additions & 0 deletions crates/wallets/src/multi_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -238,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);
Expand Down Expand Up @@ -397,6 +404,43 @@ impl MultiWalletOpts {

Ok(None)
}

/// 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<Option<Vec<WalletSigner>>> {
#[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)]
Expand Down
Loading