|
1 | 1 | use std::collections::HashMap; |
2 | 2 | use std::path::Path; |
3 | 3 |
|
4 | | -use ows_core::{ApiKeyFile, KeyType, OwsError}; |
| 4 | +use ows_core::{ApiKeyFile, EncryptedWallet, OwsError}; |
5 | 5 | use ows_signer::{decrypt, encrypt_with_hkdf, signer_for_chain, CryptoEnvelope, SecretBytes}; |
6 | 6 |
|
7 | 7 | use crate::error::OwsLibError; |
@@ -132,14 +132,7 @@ pub fn sign_with_api_key( |
132 | 132 | } |
133 | 133 |
|
134 | 134 | // 6. Decrypt wallet secret from key file using HKDF(token) |
135 | | - let key = decrypt_key_from_api_key( |
136 | | - &key_file, |
137 | | - &wallet.id, |
138 | | - wallet.key_type.clone(), |
139 | | - token, |
140 | | - chain.chain_type, |
141 | | - index, |
142 | | - )?; |
| 135 | + let key = decrypt_key_from_api_key(&key_file, &wallet, token, chain.chain_type, index)?; |
143 | 136 |
|
144 | 137 | // 7. Sign (extract signable portion first — e.g. strips Solana sig-slot headers) |
145 | 138 | let signer = signer_for_chain(chain.chain_type); |
@@ -200,14 +193,7 @@ pub fn sign_message_with_api_key( |
200 | 193 | })); |
201 | 194 | } |
202 | 195 |
|
203 | | - let key = decrypt_key_from_api_key( |
204 | | - &key_file, |
205 | | - &wallet.id, |
206 | | - wallet.key_type.clone(), |
207 | | - token, |
208 | | - chain.chain_type, |
209 | | - index, |
210 | | - )?; |
| 196 | + let key = decrypt_key_from_api_key(&key_file, &wallet, token, chain.chain_type, index)?; |
211 | 197 | let signer = signer_for_chain(chain.chain_type); |
212 | 198 | let output = signer.sign_message(key.expose(), msg_bytes)?; |
213 | 199 |
|
@@ -267,14 +253,7 @@ pub fn enforce_policy_and_decrypt_key( |
267 | 253 | })); |
268 | 254 | } |
269 | 255 |
|
270 | | - let key = decrypt_key_from_api_key( |
271 | | - &key_file, |
272 | | - &wallet.id, |
273 | | - wallet.key_type.clone(), |
274 | | - token, |
275 | | - chain.chain_type, |
276 | | - index, |
277 | | - )?; |
| 256 | + let key = decrypt_key_from_api_key(&key_file, &wallet, token, chain.chain_type, index)?; |
278 | 257 |
|
279 | 258 | Ok((key, key_file)) |
280 | 259 | } |
@@ -315,21 +294,21 @@ fn load_policies_for_key( |
315 | 294 |
|
316 | 295 | fn decrypt_key_from_api_key( |
317 | 296 | key_file: &ApiKeyFile, |
318 | | - wallet_id: &str, |
319 | | - key_type: KeyType, |
| 297 | + wallet: &EncryptedWallet, |
320 | 298 | token: &str, |
321 | 299 | chain_type: ows_core::ChainType, |
322 | 300 | index: Option<u32>, |
323 | 301 | ) -> Result<SecretBytes, OwsLibError> { |
324 | | - let envelope_value = key_file.wallet_secrets.get(wallet_id).ok_or_else(|| { |
| 302 | + let envelope_value = key_file.wallet_secrets.get(&wallet.id).ok_or_else(|| { |
325 | 303 | OwsLibError::InvalidInput(format!( |
326 | | - "API key has no encrypted secret for wallet {wallet_id}" |
| 304 | + "API key has no encrypted secret for wallet {}", |
| 305 | + wallet.id |
327 | 306 | )) |
328 | 307 | })?; |
329 | 308 |
|
330 | 309 | let envelope: CryptoEnvelope = serde_json::from_value(envelope_value.clone())?; |
331 | 310 | let secret = decrypt(&envelope, token)?; |
332 | | - crate::ops::secret_to_signing_key(&secret, key_type, chain_type, index) |
| 311 | + crate::ops::secret_to_signing_key(&secret, &wallet.key_type, chain_type, index) |
333 | 312 | } |
334 | 313 |
|
335 | 314 | #[cfg(test)] |
|
0 commit comments