@@ -11,13 +11,13 @@ use anyhow::{Context, Result};
1111use fs_err as fs;
1212use hex;
1313use near_api:: {
14- SecretKey ,
1514 types:: { AccountId , Data } ,
16- Contract , NetworkConfig , Signer ,
15+ Contract , NetworkConfig , SecretKey , Signer ,
1716} ;
18- use std :: sync :: Arc ;
17+ use near_crypto :: InMemorySigner ;
1918use serde:: { Deserialize , Serialize } ;
2019use std:: str:: FromStr ;
20+ use std:: sync:: Arc ;
2121
2222use crate :: ckd:: CkdResponse ;
2323use crate :: config:: KmsConfig ;
@@ -46,12 +46,14 @@ impl NearKmsClient {
4646 network_config : NetworkConfig ,
4747 mpc_contract_id : String ,
4848 kms_contract_id : String ,
49- signer : Option < near_crypto :: InMemorySigner > ,
49+ signer : Option < InMemorySigner > ,
5050 ) -> Result < Self > {
51- let mpc_contract_id: AccountId = mpc_contract_id. parse ( )
51+ let mpc_contract_id: AccountId = mpc_contract_id
52+ . parse ( )
5253 . context ( "Failed to parse MPC contract ID" ) ?;
5354
54- let kms_contract_id: AccountId = kms_contract_id. parse ( )
55+ let kms_contract_id: AccountId = kms_contract_id
56+ . parse ( )
5557 . context ( "Failed to parse KMS contract ID" ) ?;
5658
5759 let ( signer_account_id, near_api_signer) = if let Some ( in_memory_signer) = signer {
@@ -64,7 +66,9 @@ impl NearKmsClient {
6466 let signer = Signer :: from_secret_key ( near_api_secret_key)
6567 . context ( "Failed to create near-api Signer" ) ?;
6668
67- let account_id: AccountId = in_memory_signer. account_id . to_string ( )
69+ let account_id: AccountId = in_memory_signer
70+ . account_id
71+ . to_string ( )
6872 . parse ( )
6973 . context ( "Failed to parse account ID" ) ?;
7074
@@ -87,7 +91,8 @@ impl NearKmsClient {
8791
8892 /// Get MPC public key from the contract
8993 pub async fn get_mpc_public_key ( & self , domain_id : u64 ) -> Result < String > {
90- let current_value: Data < String > = self . mpc_contract
94+ let current_value: Data < String > = self
95+ . mpc_contract
9196 . call_function ( "public_key" , serde_json:: json!( { "domain_id" : domain_id } ) )
9297 . read_only ( )
9398 . fetch_from ( & self . network_config )
@@ -113,7 +118,10 @@ impl NearKmsClient {
113118 . signer
114119 . as_ref ( )
115120 . context ( "NEAR signer required for KMS root key requests" ) ?;
116- let signer_account_id = self . signer_account_id . expect ( "Signer account ID required for KMS root key requests" ) ?;
121+ let signer_account_id = self
122+ . signer_account_id
123+ . as_ref ( )
124+ . context ( "Signer account ID required for KMS root key requests" ) ?;
117125
118126 // Create request arguments
119127 let args = RequestKmsRootKeyArgs {
@@ -128,7 +136,7 @@ impl NearKmsClient {
128136 . kms_contract
129137 . call_function ( "request_kms_root_key" , args)
130138 . transaction ( )
131- . with_signer ( self . signer_account_id . clone ( ) , signer. clone ( ) )
139+ . with_signer ( signer_account_id, signer. clone ( ) )
132140 . send_to ( & self . network_config )
133141 . await
134142 . context ( "Failed to call KMS contract" ) ?;
@@ -145,7 +153,7 @@ impl NearKmsClient {
145153 // The return value from Promise callbacks needs to be extracted from the appropriate receipt outcome
146154 // This may require checking the receipt IDs and following the Promise chain, or using
147155 // a helper method if the API provides one
148-
156+
149157 // For now, return an error indicating this needs implementation
150158 // The actual implementation will depend on how the near-api library exposes
151159 // the return values from Promise callbacks in receipt outcomes
@@ -172,16 +180,14 @@ impl NearKmsClient {
172180
173181/// Generate a random NEAR implicit account signer
174182/// The account ID is derived from the Ed25519 public key (64 hex characters)
175- pub fn generate_near_implicit_signer ( ) -> Result < near_crypto:: InMemorySigner > {
176- use near_crypto:: { InMemorySigner , SecretKey } ;
177-
183+ pub fn generate_near_implicit_signer ( ) -> Result < InMemorySigner > {
178184 // Generate random Ed25519 keypair
179- let secret_key = SecretKey :: from_random ( near_crypto:: KeyType :: ED25519 ) ;
185+ let secret_key = near_crypto :: SecretKey :: from_random ( near_crypto:: KeyType :: ED25519 ) ;
180186
181187 // Derive implicit account ID from public key (hex encode the 32-byte public key)
182188 let public_key = secret_key. public_key ( ) ;
183- use byte_slice_cast:: AsByteSlice ;
184- let account_id = match public_key {
189+ use byte_slice_cast:: AsByteSlice ;
190+ let account_id = match public_key {
185191 near_crypto:: PublicKey :: ED25519 ( pk) => {
186192 // Implicit account ID is the hex-encoded public key (64 characters)
187193 hex:: encode ( pk. as_byte_slice ( ) )
@@ -226,8 +232,6 @@ pub fn load_or_generate_near_signer(
226232 . as_str ( )
227233 . context ( "Missing secret_key in signer file" ) ?;
228234
229- use near_crypto:: { InMemorySigner , SecretKey } ;
230-
231235 let account_id_parsed: near_account_id:: AccountId = account_id_str
232236 . parse ( )
233237 . context ( "Failed to parse account ID from signer file" ) ?;
@@ -236,7 +240,8 @@ pub fn load_or_generate_near_signer(
236240
237241 tracing:: info!( "Loaded existing NEAR signer: {}" , account_id_str) ;
238242 Ok ( Some ( InMemorySigner :: from_secret_key (
239- account_id_parsed, secret_key,
243+ account_id_parsed,
244+ secret_key,
240245 ) ) )
241246 } else {
242247 // Generate new signer
0 commit comments