# Fides Fides is a library for cryptographic primitives. ## Author - Roy R. O. Okello: [Email](mailto:royokello@protonmail.com) & [GitHub](https://github.com/royokello) ## Features - Digital Signature Algorithms - Hashing - Public Key Exchange - Data Structures like Bloom Filters & Radix Tree ## Digital Signature Algorithms ### ed25519 `secret_key -> secret_key` `public_key: secret_key -> public_key` `sign: message, secret_key -> signature` `verify: message, public_key, signature -> bool` ## Public Key Exchange ### x25519 `secret_key -> secret_key` `public_key: secret_key -> public_key` `shared_key: public_key, secret_key -> shared_secret` ## Data Structures ### Bloom Filter ### Radix Tree **Structs** `RadixTree`: Represents the radix tree, generic over `K` for key and `V` for value. - `nodes`: `HashMap` storing the nodes of the tree, each identified by a 32-byte array. - `parents`: `HashMap` tracking the parent of each node. - `root`: 32-byte array representing the root node. `RadixNode`: Represents a single node within the `RadixTree`. - `children`: `BTreeMap` mapping keys to child node hashes. - `key`: `Vec` representing the node's key. - `value`: Optional `V` holding the value associated with the key. **Methods** `new() -> Self`: Creates a new instance of `RadixTree`. `insert(&mut self, key: I, value: V)`: Inserts a key-value pair into the tree. `rehash(&mut self, child_hash: &[u8; 32])`: Updates the hash of a child node. `remove(&mut self, key: I) -> Result<(), Box>`: Removes a key-value pair. `search(&self, key: I) -> Option<&V>`: Searches for a value by key. `split_node(&mut self, node_hash: [u8; 32], split_position: usize) -> Result<([u8; 32], [u8; 32]), Box>`: Splits a node at a specified position. **Traits** IntoBytes: Provides functionality to serialize RadixTree and RadixNode into bytes. - For RadixNode: `into_bytes(&self) -> Vec`: Serializes the RadixNode into a byte vector. This includes serializing the children, key, and value fields. - For RadixTree: `into_bytes(&self) -> Vec`: Serializes the entire RadixTree into a byte vector. This process involves serializing the root and each node in nodes (using RadixNode's into_bytes method). ### Merkle Tree **Structs** `MerkleTree`: Represents the Merkle Tree, generic over T for the data stored in each node. - `nodes`: `HashMap<[u8; 32], MerkleNode>` storing the nodes of the tree, each identified by a 32-byte array. - `root`: `[u8; 32]` representing the root node. - `parents`: `HashMap<[u8; 32], [u8; 32]>` tracking the parent of each node. **Methods** `new()`: Creates a new instance of MerkleTree. `hash(&self)`: Returns the root of the Merkle Tree. `append(mut self, data: T)`: Appends data to the Merkle Tree. `replace(mut self, index: usize, data: T)`: Replaces the data at the specified index in the Merkle Tree. **Traits** IntoBytes: Provides functionality to serialize MerkleTree and MerkleNode into bytes. - For MerkleTree: `into_bytes(&self) -> Vec` - For MerkleNode: `into_bytes(&self) -> Vec` TryFromBytes: Provides functionality to deserialize MerkleTree and MerkleNode from bytes. - For MerkleTree: `try_from_bytes(value: &[u8]) -> Result>` - For MerkleNode: `try_from_bytes(value: &[u8]) -> Result>` ## Future - 🎲 Random Number Generator - 🔒 Encryption - 🏗 Accumulation - 📜 Commitment Schemes - 😎 Zero-knowledge Proof Schemes - ⏲ Verifiable Delay Function - 🔢 Fully Homomorphic Encryption ## License MIT License Copyright Stelar Labs Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. ## Disclaimer THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.