Skip to content

Commit 120a6a2

Browse files
fix: clippy
1 parent 10bff57 commit 120a6a2

3 files changed

Lines changed: 21 additions & 39 deletions

File tree

kms/src/ckd.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,6 @@ const OUTPUT_SECRET_SIZE: usize = 32;
3232
const APP_ID_DERIVATION_PREFIX: &str = "near-mpc v0.1.0 app_id derivation:";
3333
const KMS_ROOT_KEY_DERIVATION_PATH: &str = "kms-root-key";
3434

35-
/// MPC configuration for key derivation
36-
#[derive(Debug, Clone)]
37-
pub struct MpcConfig {
38-
/// MPC contract ID (e.g., "v1.signer.testnet")
39-
pub mpc_contract_id: String,
40-
/// MPC domain ID for BLS12-381 (usually 2)
41-
pub mpc_domain_id: u64,
42-
/// MPC public key for the domain (BLS12-381 G2) in NEAR format
43-
pub mpc_public_key: String,
44-
/// NEAR KMS contract ID
45-
pub kms_contract_id: String,
46-
/// NEAR RPC URL
47-
pub near_rpc_url: String,
48-
}
49-
5035
#[derive(Clone, Debug, Deserialize)]
5136
pub struct Bls12381G1PublicKey(String);
5237

@@ -208,7 +193,7 @@ pub fn derive_final_key(
208193
pub fn derive_root_key_from_mpc(
209194
mpc_response: &CkdResponse,
210195
ephemeral_private_key: Scalar,
211-
mpc_config: &MpcConfig,
196+
mpc_public_key: &str,
212197
kms_account_id: &str,
213198
) -> Result<[u8; OUTPUT_SECRET_SIZE]> {
214199
// Derive app_id (must match MPC contract derivation)
@@ -219,7 +204,7 @@ pub fn derive_root_key_from_mpc(
219204
&mpc_response.big_y,
220205
&mpc_response.big_c,
221206
ephemeral_private_key,
222-
&mpc_config.mpc_public_key,
207+
mpc_public_key,
223208
&app_id,
224209
)?;
225210

kms/src/near_kms_client.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use anyhow::{Context, Result};
1111
use byte_slice_cast::AsByteSlice;
1212
use fs_err as fs;
13-
use hex;
1413
use near_api::{
1514
types::{AccountId, Data},
1615
Contract, NetworkConfig, SecretKey, Signer,
@@ -258,9 +257,7 @@ pub fn load_or_generate_near_signer(config: &KmsConfig) -> Result<Option<InMemor
258257
///
259258
/// # Errors
260259
/// Returns an error if the public key is not ED25519 (only ED25519 keys are supported for NEAR implicit accounts)
261-
pub fn near_public_key_to_report_data(
262-
public_key: &near_crypto::PublicKey,
263-
) -> Result<[u8; 64]> {
260+
pub fn near_public_key_to_report_data(public_key: &near_crypto::PublicKey) -> Result<[u8; 64]> {
264261
const REPORT_DATA_SIZE: usize = 64;
265262
const BINARY_VERSION_SIZE: usize = 2;
266263
const PUBLIC_KEYS_HASH_SIZE: usize = 48;
@@ -359,11 +356,17 @@ mod tests {
359356

360357
// Verify hash bytes are non-zero (bytes 2-50 should contain the hash)
361358
let hash_section = &report_data[2..50];
362-
assert!(!hash_section.iter().all(|&b| b == 0), "Hash should not be all zeros");
359+
assert!(
360+
!hash_section.iter().all(|&b| b == 0),
361+
"Hash should not be all zeros"
362+
);
363363

364364
// Verify padding bytes are zero (bytes 50-64 should be zero)
365365
let padding_section = &report_data[50..64];
366-
assert!(padding_section.iter().all(|&b| b == 0), "Padding should be zeros");
366+
assert!(
367+
padding_section.iter().all(|&b| b == 0),
368+
"Padding should be zeros"
369+
);
367370
}
368371

369372
#[test]

kms/src/onboard_service.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ use ra_tls::{
2222
};
2323
use safe_write::safe_write;
2424

25-
use crate::ckd::{
26-
derive_root_key_from_mpc, g1_to_near_format, generate_ephemeral_keypair, MpcConfig,
27-
};
25+
use crate::ckd::{derive_root_key_from_mpc, g1_to_near_format, generate_ephemeral_keypair};
2826
use crate::config::{AuthApi, KmsConfig};
29-
use crate::near_kms_client::{load_or_generate_near_signer, near_public_key_to_report_data, NearKmsClient};
27+
use crate::near_kms_client::{
28+
load_or_generate_near_signer, near_public_key_to_report_data, NearKmsClient,
29+
};
3030
use dcap_qvl::collateral;
3131
use near_api::NetworkConfig;
3232
use ra_tls::kdf;
@@ -426,7 +426,10 @@ async fn try_derive_keys_from_mpc(
426426
let mpc_domain_id = near.mpc_domain_id;
427427

428428
let network_id = near.network_id.as_deref().unwrap_or("testnet");
429-
let network_config = NetworkConfig::from_rpc_url(network_id, rpc_url.parse().unwrap());
429+
let network_config = NetworkConfig::from_rpc_url(
430+
network_id,
431+
rpc_url.parse().context("Failed to parse RPC URL")?,
432+
);
430433

431434
// Load or generate NEAR signer (implicit account)
432435
let signer = load_or_generate_near_signer(cfg)?;
@@ -471,15 +474,6 @@ async fn try_derive_keys_from_mpc(
471474

472475
tracing::debug!("Generated ephemeral BLS12-381 keypair");
473476

474-
// Create MPC config
475-
let mpc_config = MpcConfig {
476-
mpc_contract_id: mpc_contract_id.clone(),
477-
mpc_domain_id,
478-
mpc_public_key: mpc_public_key.clone(),
479-
kms_contract_id: kms_contract_id.clone(),
480-
near_rpc_url: rpc_url.to_string(),
481-
};
482-
483477
// Get TDX attestation (quote, collateral, tcb_info) for KMS contract
484478
// The KMS contract's request_kms_root_key() requires attestation verification
485479
let (quote_hex, collateral_json, tcb_info_json) = if quote_enabled {
@@ -498,7 +492,7 @@ async fn try_derive_keys_from_mpc(
498492
let quote_bytes = attestation
499493
.into_inner()
500494
.tdx_quote()
501-
.and_then(|q| Some(q.quote.clone()))
495+
.map(|q| q.quote.clone())
502496
.context("Failed to get TDX quote bytes")?;
503497
let quote_hex = hex::encode(&quote_bytes);
504498

@@ -552,7 +546,7 @@ async fn try_derive_keys_from_mpc(
552546
let root_key = derive_root_key_from_mpc(
553547
&mpc_response,
554548
ephemeral_private_key,
555-
&mpc_config,
549+
&mpc_public_key,
556550
kms_contract_id,
557551
)
558552
.context("Failed to derive root key from MPC response")?;

0 commit comments

Comments
 (0)