miden_objects/conversion/
account_file.rs1use miden_protocol::account::auth::AuthSecretKey;
2use miden_protocol::utils::serde::Serializable;
3
4use crate::account_file::AccountFile;
5use crate::proto;
6
7#[cfg(test)]
8mod tests;
9
10impl From<&AuthSecretKey> for proto::account_file::AuthSecretKey {
14 fn from(secret_key: &AuthSecretKey) -> Self {
15 use proto::account_file::auth_secret_key::Key;
16
17 let key = match secret_key {
18 AuthSecretKey::Falcon512Poseidon2(key) => Key::Falcon512Poseidon2(key.to_bytes()),
19 AuthSecretKey::EcdsaK256Keccak(key) => Key::EcdsaK256Keccak(key.to_bytes()),
20 _ => unreachable!(
22 "every auth secret key scheme should have a corresponding protobuf variant"
23 ),
24 };
25 Self { key: Some(key) }
26 }
27}
28
29impl From<AuthSecretKey> for proto::account_file::AuthSecretKey {
30 fn from(secret_key: AuthSecretKey) -> Self {
31 Self::from(&secret_key)
32 }
33}
34
35impl From<&AccountFile> for proto::account_file::AccountFile {
39 fn from(file: &AccountFile) -> Self {
40 let version = proto::account_file::account_file::Version::V1(file.into());
41 Self { version: Some(version) }
42 }
43}
44
45impl From<AccountFile> for proto::account_file::AccountFile {
46 fn from(file: AccountFile) -> Self {
47 Self::from(&file)
48 }
49}
50
51impl From<&AccountFile> for proto::account_file::AccountFileV1 {
52 fn from(file: &AccountFile) -> Self {
53 Self {
54 account: Some(file.account().into()),
55 auth_secret_keys: file.auth_secret_keys().iter().map(Into::into).collect(),
56 }
57 }
58}