Skip to content

Commit

Permalink
add google wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
Salka1988 committed Feb 28, 2025
1 parent e30989b commit 428572d
Show file tree
Hide file tree
Showing 6 changed files with 322 additions and 322 deletions.
15 changes: 4 additions & 11 deletions e2e/tests/aws.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#[cfg(test)]
mod tests {
use std::any::Any;
use anyhow::Result;
use e2e::e2e_helpers::start_aws_kms;
use fuels::accounts::kms::{AwsWallet, CredentialsFile};
use fuels::accounts::kms::AwsWallet;
use fuels::accounts::{Account, ViewOnlyAccount};
use fuels::prelude::{launch_provider_and_get_wallet, AssetId, Contract, Error, LoadConfiguration, TxPolicies};
use fuels::prelude::{
launch_provider_and_get_wallet, AssetId, Contract, LoadConfiguration, TxPolicies,
};
use fuels::types::errors::Context;

#[tokio::test(flavor = "multi_thread")]
Expand Down Expand Up @@ -72,12 +73,4 @@ mod tests {

Ok(())
}

#[tokio::test(flavor = "multi_thread")]
async fn fund_google_wallet() -> Result<()> {
let credentials_file = CredentialsFile::new().await.map_err(|e| Error::Other(format!("Failed to create credentials file: {}", e)))?;


Ok(())
}
}
8 changes: 3 additions & 5 deletions packages/fuels-accounts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@ fuel-crypto = { workspace = true, features = ["random"] }
fuel-tx = { workspace = true }
fuel-types = { workspace = true, features = ["random"] }
fuels-core = { workspace = true, default-features = false }
google-cloud-kms = { workspace = true, features = ["auth"], optional = true }
itertools = { workspace = true }
k256 = { workspace = true, features = ["ecdsa-core"] }
k256 = { workspace = true, features = ["ecdsa-core", "pem"] }
rand = { workspace = true, default-features = false }
semver = { workspace = true }
tai64 = { workspace = true, features = ["serde"] }
thiserror = { workspace = true, default-features = false }
tokio = { workspace = true, features = ["full"], optional = true }
zeroize = { workspace = true, features = ["derive"] }
google-cloud-kms = { workspace = true, features = ["auth"], optional = true }
prost = "0.13.5"
tonic = "0.12.3"

[dev-dependencies]
fuel-tx = { workspace = true, features = ["test-helpers", "random"] }
Expand All @@ -54,4 +52,4 @@ std = [
"dep:cynic",
]
test-helpers = []
kms_signer = ["dep:aws-sdk-kms", "dep:aws-config", "dep:google-cloud-kms"]
kms-signer = ["dep:aws-sdk-kms", "dep:aws-config", "dep:google-cloud-kms"]
24 changes: 8 additions & 16 deletions packages/fuels-accounts/src/kms/aws/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ use k256::{
PublicKey as K256PublicKey,
};

/// Error prefix for AWS KMS related operations
const AWS_KMS_ERROR_PREFIX: &str = "AWS KMS Error";
/// Expected key specification for AWS KMS keys
const EXPECTED_KEY_SPEC: KeySpec = KeySpec::EccSecgP256K1;

/// A wallet implementation that uses AWS KMS for signing
Expand All @@ -37,7 +35,6 @@ pub struct AwsWallet {
kms_key: KmsKey,
}

/// Represents an AWS KMS key with Fuel-compatible address
#[derive(Clone, Debug)]
pub struct KmsKey {
key_id: String,
Expand Down Expand Up @@ -120,15 +117,6 @@ impl KmsKey {
Ok(Bech32Address::new(FUEL_BECH32_HRP, fuel_public_key.hash()))
}

/// Signs a message using the AWS KMS key
async fn sign_message(&self, message: Message) -> Result<Signature> {
let signature_der = self.request_kms_signature(message).await?;
let (sig, recovery_id) = self.normalize_signature(&signature_der, message)?;

Ok(self.convert_to_fuel_signature(sig, recovery_id))
}

/// Requests a signature from AWS KMS
async fn request_kms_signature(&self, message: Message) -> Result<Vec<u8>> {
let response = self
.client
Expand All @@ -152,6 +140,14 @@ impl KmsKey {
})
}

/// Signs a message using the AWS KMS key
async fn sign_message(&self, message: Message) -> Result<Signature> {
let signature_der = self.request_kms_signature(message).await?;
let (sig, recovery_id) = self.normalize_signature(&signature_der, message)?;

Ok(self.convert_to_fuel_signature(sig, recovery_id))
}

/// Normalizes a DER signature and determines the recovery ID
fn normalize_signature(
&self,
Expand All @@ -161,7 +157,6 @@ impl KmsKey {
let signature = K256Signature::from_der(signature_der)
.map_err(|_| Error::Other(format!("{AWS_KMS_ERROR_PREFIX}: Invalid DER signature")))?;

// Ensure the signature is in normalized form (low-S value)
let normalized_sig = signature.normalize_s().unwrap_or(signature);
let recovery_id = self.determine_recovery_id(&normalized_sig, message)?;

Expand Down Expand Up @@ -230,13 +225,10 @@ impl AwsWallet {
kms_key,
})
}

/// Returns the Fuel address associated with this wallet
pub fn address(&self) -> &Bech32Address {
&self.kms_key.fuel_address
}

/// Returns the provider associated with this wallet, if any
pub fn provider(&self) -> Option<&Provider> {
self.view_account.provider()
}
Expand Down
5 changes: 2 additions & 3 deletions packages/fuels-accounts/src/kms/google/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub use google_cloud_kms::client::{google_cloud_auth::credentials::CredentialsFile, ClientConfig};
use google_cloud_kms::client::Client;
use fuels_core::types::errors::{Error, Result};
use google_cloud_kms::client::Client;
pub use google_cloud_kms::client::{google_cloud_auth::credentials::CredentialsFile, ClientConfig};

#[derive(Clone, Debug)]
pub struct GoogleClient {
Expand All @@ -9,7 +9,6 @@ pub struct GoogleClient {

impl GoogleClient {
pub async fn new(config: ClientConfig) -> Result<Self> {

let config_debug = format!("{:?}", config);

let client = Client::new(config).await.map_err(|e| {
Expand Down
Loading

0 comments on commit 428572d

Please sign in to comment.