Crypto Package Consolidation & Improvements #46
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "develop-crypto-consolidation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Overview
This PR consolidates the
herolib-cryptopackage intoherolib-crypt, establishing a single source of truth for all cryptographic operations in the ecosystem. It eliminates code duplication, unifies testing pathways, and improves the internal architecture while maintaining 100% backward compatibility for downstream consumers (vault, Rhai scripts, etc.).Why Consolidation?
Previously, we maintained two parallel crypto packages (
cryptandcrypto) with redundant signing logic and divergent Rhai bindings. This consolidation:Architecture: The
keysModuleWe have adopted the
keysmodule (from the originalcryptopackage) as the core internal implementation.Legacy Signing Removal
We removed the old procedural signing logic in
asymmetric/signing.rsthat relied on raw byte arrays. This old implementation was prone to errors (e.g., incorrect slice lengths) and lacked the robust error handling of thekeysmodule. Thesigning.rsfile now acts as a thin, backward-compatible wrapper delegating all logic to thekeysmodule.Why
keys?Ed25519Keypair,Ed25519PublicKey) rather than raw bytes, preventing misuse.keypair.sign(),pubkey.verify()).Zeroizesupport) and ensures consistent hex/byte serialization.API Preservation
We maintained strict backward compatibility and added:
Rhai API
Keys Module (30 functions):
ed25519_generate(),ed25519_from_hex(),ed25519_from_bytes()sign(),sign_bytes(),verify(),verify_bytes()public_key(),public_key_hex(),public_key_bytes()to_hex(),to_bytes()(for keypair, pubkey, signature)random_bytes(),encode_hex(),decode_hex()sha256(),sha256_bytes(),secure_compare()verify_ed25519(),verify_ed25519_bytes()Important note: Safety vs Convenience
asymmetricmodule): Less safe. Rhai strings are immutable but linger in memory. You pass the sensitive private key string around by value.keysmodule):We keep both API in Rhai because:
HTTP Signatures Module (10 functions):
httpsig_signer_new(),httpsig_signer_with_headers(),httpsig_signer_with_label()httpsig_sign(),httpsig_verifier_new(),httpsig_verifier_with_key()httpsig_verifier_with_tolerance(),httpsig_verify()httpsig_compute_digest(),httpsig_extract_key_id()Rust API
crypt::asymmetriccrypt::symmetriccrypt::keyscrypt::httpsigArchitecture Comparison:
asymmetricvskeysWe intentionally preserve both modules to serve different needs:
crypt::asymmetric(High-Level)crypt::keys(Low-Level Primitive)Ed25519Keypair/Signaturestructs. Zero-cost validation after creation.Improvements
Downstream Integration
herolib-do(Herodo): Updated REPL with a new/cryptcommand to expose all crypto functions with autocomplete and help documentation.herolib-vault: Compiled and verified against the newherolib-cryptcore.Tooling
run_rhaiandrhai_runnerinto a single, smart tool (examples/run_rhai.rs).cargo run --example run_rhaicargo run --example run_rhai -- path/to/script.rhaiFeature Flags
README Updates
The README was updated:
Verification
Deleted
packages/crypto/directorykeypair/*.rhai)crypto consolidationto Crypto Package Consolidation & Improvements