feat(age): add BIP39 mnemonic support for Identity #587
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces support for BIP39 mnemonics to the
agecrate, enabling users to backup and restorex25519::Identityusing a 24-word phrase. This facilitates deterministic key generation and easier key management.Changes
ageCrateIdentity::from_secret_bytes: A public method to construct anIdentityfrom a raw 32-byte array.# Securitysection to the documentation warning users to only provide high-entropy inputs (CSPRNG or KDF derived).bip39Feature:bip39(v2.0).bip39feature flag toCargo.toml.Identity::to_mnemonic(&self) -> Mnemonic: Serializes the secret key into a 24-word English mnemonic.Identity::from_mnemonic(&Mnemonic) -> Result<Self, &'static str>: Restores an identity from a mnemonic.Zeroizetrait before being dropped.Testing
identity_from_secret_bytes: Verifies raw byte deserialization.mnemonic_round_trip: Verifies that an identity can be converted to a mnemonic and restored back correctly (guarded bybip39feature).invalid_mnemonic_length: Ensures that mnemonics with insufficient entropy (e.g., 12 words/128 bits) are rejected safely.Verification
Run the tests including the new feature:
cargo test --package age --lib --features bip39