0xMiden / 0xMiden/protocol

Refactoring `AccountFile` struct

Offen
#1,790 7 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
rust
Vorherrschende Sprache
Rust
Sterne
132
Forks
167
Ø Merge
1 T. 23 Std.
Gemergte PRs (30 T.)
110

Beschreibung

## Background

Opening this issue as it is related to Bobbin's comment here: https://github.com/0xMiden/miden-base/pull/1759#pullrequestreview-3143063931

Currently the `AccountFile` struct from the miden-objects crate serves as a serializable container for exporting and importing complete account data, including private keys.

`AccountFile`: https://github.com/0xMiden/miden-base/blob/66020c312d1ce05ec53057906e7356f3ecd028ce/crates/miden-objects/src/account/file.rs#L34

Afaik this is a fairly old `struct` that has been in miden-base for quite some time and it can potentially be refactored to address the issues listed below.

*Note*:
This issue also relates to the `AuthScheme` enum in miden-base as it is used to identify the public keys associated with an account to later query the client `keystore` to get the associated private keys.

`AuthScheme`: https://github.com/0xMiden/miden-base/blob/66020c312d1ce05ec53057906e7356f3ecd028ce/crates/miden-lib/src/auth.rs#L6

### `AccountFile` Current Limitations and Issues:
*Security Concerns:*

* Private keys are stored in plaintext within the serialized format
* No encryption or password protection for exported files
* Sensitive data can be easily extracted from .mac files

*Usability Issues:*

* Single monolithic structure for all export scenarios
* No granular control over what data to export
* Limited metadata about export context or purpose

## Potential Refactoring Approaches
1. Separation of Concerns
```rs
// Separate account data from authentication data
pub struct AccountExport {
pub account: Account,
pub account_seed: Option,
pub metadata: ExportMetadata,
}

pub struct AuthenticationExport {
pub account_id: AccountId,
pub auth_keys: Vec,
pub encryption: Option,
}
```

2. Flexible Export Types
```rs
pub enum ExportType {
AccountOnly, // Just account state, no keys
AccountWithPublicKeys, // Account + public keys only
FullExport, // Account + private keys (current behavior)
}
```

3. Enhanced Security
```rs
pub struct SecureAccountFile {
pub account_data: AccountExport,
pub encrypted_auth_data: Option,
pub export_metadata: ExportMetadata,
}
```
### Current Export Usage Patterns:
CLI Export - [Creates .mac files for account backup](https://github.com/0xMiden/miden-client/blob/7af734d77ddbcc39aef5c915bd391c1c1e7e4dae/bin/miden-cli/src/commands/export.rs#L106)

Web Client Export: [Exports account data as serialized bytes for web applications](https://github.com/0xMiden/miden-client/blob/7af734d77ddbcc39aef5c915bd391c1c1e7e4dae/crates/web-client/src/export.rs#L99)

### Current Import Usage Patterns:

CLI Import:[ Reads .mac files and restores accounts](https://github.com/0xMiden/miden-client/blob/7af734d77ddbcc39aef5c915bd391c1c1e7e4dae/bin/miden-cli/src/commands/import.rs#L77)

Web Client Import: [Deserializes account data from bytes](https://github.com/0xMiden/miden-client/blob/7af734d77ddbcc39aef5c915bd391c1c1e7e4dae/crates/web-client/src/import.rs#L25)

_________

CC-ing @bobbinth & @igamigo

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.