Skip to content

Commit a5d73c3

Browse files
refactor: parse account ID
1 parent aaff760 commit a5d73c3

3 files changed

Lines changed: 56 additions & 59 deletions

File tree

Cargo.lock

Lines changed: 35 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kms/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ bs58 = "0.5"
5757
rand_core = { version = "0.6", features = ["getrandom"] }
5858

5959
# NEAR integration
60-
near-api = "0.8"
61-
near-crypto = "0.26" # Still needed for InMemorySigner in onboard_service.rs
62-
near-account-id = "2.5" # For AccountId type compatibility
60+
near-api = "0.8.3"
61+
near-crypto = "0.34.6" # Still needed for InMemorySigner in onboard_service.rs
6362
byte-slice-cast = "1.2"
6463
url.workspace = true
6564

kms/src/near_kms_client.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ use std::sync::Arc;
2222
use crate::ckd::CkdResponse;
2323
use 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)]
2729
pub 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

Comments
 (0)