@@ -22,6 +22,8 @@ use std::sync::Arc;
2222use crate :: ckd:: CkdResponse ;
2323use crate :: config:: KmsConfig ;
2424
25+ const NEAR_SIGNER_FILE : & str = "near_signer.json" ;
26+
2527/// Request KMS root key arguments (matching NEAR KMS contract interface)
2628#[ derive( Debug , Serialize , Deserialize ) ]
2729pub struct RequestKmsRootKeyArgs {
@@ -136,7 +138,7 @@ impl NearKmsClient {
136138 . kms_contract
137139 . call_function ( "request_kms_root_key" , args)
138140 . transaction ( )
139- . with_signer ( signer_account_id, signer. clone ( ) )
141+ . with_signer ( signer_account_id. clone ( ) , signer. clone ( ) )
140142 . send_to ( & self . network_config )
141143 . await
142144 . context ( "Failed to call KMS contract" ) ?;
@@ -195,28 +197,29 @@ pub fn generate_near_implicit_signer() -> Result<InMemorySigner> {
195197 _ => anyhow:: bail!( "Unexpected key type for NEAR implicit account" ) ,
196198 } ;
197199
198- // InMemorySigner::from_secret_key expects AccountId which can be parsed from string
199- // The AccountId type is re-exported from near-account-id crate
200- let account_id: near_account_id:: AccountId = account_id
200+ let account_id: AccountId = account_id
201201 . parse ( )
202202 . context ( "Failed to parse generated account ID" ) ?;
203203
204- Ok ( InMemorySigner :: from_secret_key ( account_id, secret_key) )
204+ let public_key = secret_key. public_key ( ) ;
205+ Ok ( InMemorySigner {
206+ account_id,
207+ secret_key,
208+ public_key,
209+ } )
205210}
206211
207212/// Load or generate NEAR signer (stored persistently)
208213///
209214/// This function checks if a signer already exists in the cert_dir, and if not,
210215/// generates a new random NEAR implicit account signer and saves it.
211- pub fn load_or_generate_near_signer (
212- config : & KmsConfig ,
213- ) -> Result < Option < near_crypto:: InMemorySigner > > {
216+ pub fn load_or_generate_near_signer ( config : & KmsConfig ) -> Result < Option < InMemorySigner > > {
214217 // Only generate if using NEAR auth
215218 if !matches ! ( & config. auth_api, crate :: config:: AuthApi :: Near { .. } ) {
216219 return Ok ( None ) ;
217220 }
218221
219- let signer_path = config. cert_dir . join ( "near_signer.json" ) ;
222+ let signer_path = config. cert_dir . join ( NEAR_SIGNER_FILE ) ;
220223
221224 if signer_path. exists ( ) {
222225 // Load existing signer
@@ -232,17 +235,20 @@ pub fn load_or_generate_near_signer(
232235 . as_str ( )
233236 . context ( "Missing secret_key in signer file" ) ?;
234237
235- let account_id_parsed: near_account_id :: AccountId = account_id_str
238+ let account_id_parsed: AccountId = account_id_str
236239 . parse ( )
237240 . context ( "Failed to parse account ID from signer file" ) ?;
238241 let secret_key = near_crypto:: SecretKey :: from_str ( secret_key_str)
239242 . context ( "Failed to parse secret key from signer file" ) ?;
240243
241244 tracing:: info!( "Loaded existing NEAR signer: {}" , account_id_str) ;
242- Ok ( Some ( InMemorySigner :: from_secret_key (
243- account_id_parsed,
245+ let public_key = secret_key. public_key ( ) ;
246+ let signer = InMemorySigner {
247+ account_id : account_id_parsed,
244248 secret_key,
245- ) ) )
249+ public_key,
250+ } ;
251+ Ok ( Some ( signer) )
246252 } else {
247253 // Generate new signer
248254 let signer = generate_near_implicit_signer ( ) ?;
0 commit comments