Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Salka1988 committed Mar 3, 2025
1 parent 6bab0fd commit 57da2fc
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 43 deletions.
1 change: 0 additions & 1 deletion e2e/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ tar = { workspace = true }

[dependencies]
anyhow = { workspace = true }
aws-sdk-kms = { workspace = true, features = ["rustls"] }
fuels = { workspace = true, features = ["kms-signer", "test-helpers"] }
testcontainers = { workspace = true }
tokio = { workspace = true, features = ["test-util"] }
Expand Down
21 changes: 14 additions & 7 deletions e2e/src/aws_kms.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
use fuels::accounts::kms::{defaults, AwsClient, BehaviorVersion, Credentials, KmsKey, Region};
use fuels::accounts::kms::{
aws_config::{defaults, BehaviorVersion, Region},
aws_sdk_kms::{
config::Credentials,
types::{KeySpec, KeyUsageType},
Client,
},
KmsKey,
};
use fuels::prelude::Error;
use fuels::types::errors::Context;
use fuels::types::errors::Result;
Expand Down Expand Up @@ -63,7 +71,7 @@ impl AwsKms {
.load()
.await;

let client = AwsClient::new(config);
let client = Client::new(&config);

Ok(AwsKmsProcess {
_container: container,
Expand Down Expand Up @@ -114,18 +122,17 @@ fn spawn_log_printer(container: &testcontainers::ContainerAsync<AwsKmsImage>) {

pub struct AwsKmsProcess {
_container: testcontainers::ContainerAsync<AwsKmsImage>,
client: AwsClient,
client: Client,
url: String,
}

impl AwsKmsProcess {
pub async fn create_key(&self) -> anyhow::Result<KmsTestKey> {
let response = self
.client
.inner()
.create_key()
.key_usage(aws_sdk_kms::types::KeyUsageType::SignVerify)
.key_spec(aws_sdk_kms::types::KeySpec::EccSecgP256K1)
.key_usage(KeyUsageType::SignVerify)
.key_spec(KeySpec::EccSecgP256K1)
.send()
.await?;

Expand All @@ -143,7 +150,7 @@ impl AwsKmsProcess {
})
}

pub fn client(&self) -> &AwsClient {
pub fn client(&self) -> &Client {
&self.client
}

Expand Down
6 changes: 3 additions & 3 deletions packages/fuels-accounts/src/kms/aws.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod client;
mod wallet;

pub use client::*;
pub use wallet::*;

pub use aws_config;
pub use aws_sdk_kms;
23 changes: 0 additions & 23 deletions packages/fuels-accounts/src/kms/aws/client.rs

This file was deleted.

15 changes: 6 additions & 9 deletions packages/fuels-accounts/src/kms/aws/wallet.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::accounts_utils::try_provider_error;
pub use crate::kms::aws::client::AwsClient;
use crate::provider::Provider;
use crate::wallet::Wallet;
use crate::{Account, ViewOnlyAccount};
use aws_sdk_kms::{
primitives::Blob,
types::{KeySpec, MessageType, SigningAlgorithmSpec},
Client,
};
use fuel_crypto::{Message, PublicKey, Signature};
use fuel_types::AssetId;
Expand Down Expand Up @@ -38,7 +38,7 @@ pub struct AwsWallet {
#[derive(Clone, Debug)]
pub struct KmsKey {
key_id: String,
client: AwsClient,
client: Client,
public_key_der: Vec<u8>,
fuel_address: Bech32Address,
}
Expand All @@ -57,7 +57,7 @@ impl KmsKey {
}

/// Creates a new KmsKey from an AWS KMS key ID
pub async fn new(key_id: String, client: &AwsClient) -> Result<Self> {
pub async fn new(key_id: String, client: &Client) -> Result<Self> {
Self::validate_key_spec(client, &key_id).await?;
let public_key = Self::retrieve_public_key(client, &key_id).await?;
let fuel_address = Self::derive_fuel_address(&public_key)?;
Expand All @@ -71,9 +71,8 @@ impl KmsKey {
}

/// Validates that the KMS key is of the expected type
async fn validate_key_spec(client: &AwsClient, key_id: &str) -> Result<()> {
async fn validate_key_spec(client: &Client, key_id: &str) -> Result<()> {
let response = client
.inner()
.get_public_key()
.key_id(key_id)
.send()
Expand All @@ -91,9 +90,8 @@ impl KmsKey {
}

/// Retrieves the public key from AWS KMS
async fn retrieve_public_key(client: &AwsClient, key_id: &str) -> Result<Vec<u8>> {
async fn retrieve_public_key(client: &Client, key_id: &str) -> Result<Vec<u8>> {
let response = client
.inner()
.get_public_key()
.key_id(key_id)
.send()
Expand Down Expand Up @@ -129,7 +127,6 @@ impl KmsKey {
async fn request_kms_signature(&self, message: Message) -> Result<Vec<u8>> {
let response = self
.client
.inner()
.sign()
.key_id(&self.key_id)
.signing_algorithm(SigningAlgorithmSpec::EcdsaSha256)
Expand Down Expand Up @@ -216,7 +213,7 @@ impl AwsWallet {
/// Creates a new AwsWallet with the given KMS key ID
pub async fn with_kms_key(
key_id: impl Into<String>,
aws_client: &AwsClient,
aws_client: &Client,
provider: Option<Provider>,
) -> Result<Self> {
let kms_key = KmsKey::new(key_id.into(), aws_client).await?;
Expand Down

0 comments on commit 57da2fc

Please sign in to comment.