8000 Add crate for common traits by sushisilence · Pull Request #3 · silence-laboratories/sl-crypto · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add crate for common traits #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[workspace]
resolver = "2"
members = [
"crates/sl-mpc-mate",
"crates/sl-oblivious",
"crates/sl-paillier"
"crates/sl-mpc-mate",
"crates/sl-oblivious",
"crates/sl-paillier",
"crates/sl-mpc-traits",
]

[profile.bench]
Expand Down
14 changes: 14 additions & 0 deletions crates/sl-mpc-traits/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "sl-mpc-traits"
version = "0.1.0"
edition = "2021"

[dependencies]
bincode = { version = "1", optional = true }
serde = { version = "1.0", default-features = false, features = [
"derive",
], optional = true }

[features]
default = []
serde = ["dep:serde", "dep:bincode"]
28 changes: 28 additions & 0 deletions crates/sl-mpc-traits/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/// Trait that defines a state transition for any round based protocol.
pub trait Round {
/// Output of the state transition.
type Output;
/// Input of the state transition.
type Input;
/// Transition to the next state.
fn process(self, messages: Self::Input) -> Self::Output;
}

#[cfg(feature = "serde")]
use serde::{de::DeserializeOwned, Serialize};

#[cfg(feature = "serde")]
/// Trait that signifies a persistent object.
/// Encoded using bincode.
pub trait PersistentObject:
Serialize + DeserializeOwned + Send + 'static
{
/// Serialize the object into bytes.
fn to_bytes(&self) -> Option<Vec<u8>> {
bincode::serialize(self).ok()
}
/// Deserialize the object from bytes.
fn from_bytes(bytes: &[u8]) -> Option<Self> {
bincode::deserialize(bytes).ok()
}
}
0