forked from anoma/ferveo
-
Notifications
You must be signed in to change notification settings - Fork 10
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
WASM bindings #10
Merged
piotr-roslaniec
merged 17 commits into
nucypher:main
from
piotr-roslaniec:wasm-bindings
Nov 22, 2022
Merged
WASM bindings #10
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ca2e46e
add wasm setup
piotr-roslaniec 1b96071
setup benchmarks
piotr-roslaniec 9fc2c4b
add bindings for threshold decryption flow
piotr-roslaniec 2462c8a
fix clippy
piotr-roslaniec 7e92e0d
self review
piotr-roslaniec b8b2392
update after rebase
piotr-roslaniec d8b51ce
expose randomness in dkg setup
piotr-roslaniec f93c6d5
add wasm setup
piotr-roslaniec 71ae0c3
add bindings for threshold decryption flow
piotr-roslaniec d80d112
fix clippy
piotr-roslaniec 9d358e1
panicks at 'capacity overflow' during js-benches
piotr-roslaniec d77f3b7
update after rebase
piotr-roslaniec 1688c36
add benchmarks in the browser
piotr-roslaniec c0c2c9e
add info about benchmark setup
piotr-roslaniec 0091ae1
add python bindings and benchmark
piotr-roslaniec 227052a
Merge pull request #18 from nucypher/bindings-python
piotr-roslaniec 85fba9e
Merge pull request #17 from nucypher/benchmark-wasm
piotr-roslaniec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
//! This adds a few utility functions for serializing and deserializing | ||
//! [arkworks](http://arkworks.rs/) types that implement [CanonicalSerialize] and [CanonicalDeserialize]. | ||
//! Adapted from [o1-labs/proof-systems](https://raw.githubusercontent.com/o1-labs/proof-systems/31c76ceae3122f0ce09cded8260960ed5cbbe3d8/utils/src/serialization.rs). | ||
|
||
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; | ||
use serde_with::Bytes; | ||
|
||
// | ||
// Serialization with serde | ||
// | ||
|
||
pub mod ser { | ||
//! You can use this module for serialization and deserializing arkworks types with [serde]. | ||
//! Simply use the following attribute on your field: | ||
//! `#[serde(with = "serialization::ser") attribute"]` | ||
|
||
use super::*; | ||
use serde_with::{DeserializeAs, SerializeAs}; | ||
|
||
/// You can use this to serialize an arkworks type with serde and the "serialize_with" attribute. | ||
/// See <https://serde.rs/field-attrs.html> | ||
pub fn serialize<S>( | ||
val: impl CanonicalSerialize, | ||
serializer: S, | ||
) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
let mut bytes = vec![]; | ||
val.serialize(&mut bytes) | ||
.map_err(serde::ser::Error::custom)?; | ||
|
||
Bytes::serialize_as(&bytes, serializer) | ||
} | ||
|
||
/// You can use this to deserialize an arkworks type with serde and the "deserialize_with" attribute. | ||
/// See <https://serde.rs/field-attrs.html> | ||
pub fn deserialize<'de, T, D>(deserializer: D) -> Result<T, D::Error> | ||
where | ||
T: CanonicalDeserialize, | ||
D: serde::Deserializer<'de>, | ||
{ | ||
let bytes: Vec<u8> = Bytes::deserialize_as(deserializer)?; | ||
T::deserialize(&mut &bytes[..]).map_err(serde::de::Error::custom) | ||
} | ||
} | ||
|
||
// | ||
// Serialization with [serde_with] | ||
// | ||
|
||
/// You can use [SerdeAs] with [serde_with] in order to serialize and deserialize types that implement [CanonicalSerialize] and [CanonicalDeserialize], | ||
/// or containers of types that implement these traits (Vec, arrays, etc.) | ||
/// Simply add annotations like `#[serde_as(as = "serialization::SerdeAs")]` | ||
/// See <https://docs.rs/serde_with/1.10.0/serde_with/guide/serde_as/index.html#switching-from-serdes-with-to-serde_as> | ||
pub struct SerdeAs; | ||
|
||
impl<T> serde_with::SerializeAs<T> for SerdeAs | ||
where | ||
T: CanonicalSerialize, | ||
{ | ||
fn serialize_as<S>(val: &T, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
let mut bytes = vec![]; | ||
val.serialize(&mut bytes) | ||
.map_err(serde::ser::Error::custom)?; | ||
|
||
Bytes::serialize_as(&bytes, serializer) | ||
} | ||
} | ||
|
||
impl<'de, T> serde_with::DeserializeAs<'de, T> for SerdeAs | ||
where | ||
T: CanonicalDeserialize, | ||
{ | ||
fn deserialize_as<D>(deserializer: D) -> Result<T, D::Error> | ||
where | ||
D: serde::Deserializer<'de>, | ||
{ | ||
let bytes: Vec<u8> = Bytes::deserialize_as(deserializer)?; | ||
T::deserialize(&mut &bytes[..]).map_err(serde::de::Error::custom) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops! it seems you removed here the ciphertext from the serialized output!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it very worrisome that this wasn't caught by tests.