-
Notifications
You must be signed in to change notification settings - Fork 9
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
Use static arrays in FerveoPublicKey
serialization
#136
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,36 @@ | ||
pub mod keypair; | ||
pub mod serialization; | ||
|
||
use std::{fmt, fmt::Formatter}; | ||
|
||
pub use keypair::*; | ||
pub use serialization::*; | ||
|
||
#[derive(Debug)] | ||
pub enum Error { | ||
InvalidByteLength(usize, usize), | ||
SerializationError(ark_serialize::SerializationError), | ||
InvalidSeedLength(usize), | ||
} | ||
|
||
impl fmt::Display for Error { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Error::InvalidByteLength(expected, actual) => { | ||
write!( | ||
f, | ||
"Invalid byte length: expected {}, actual {}", | ||
expected, actual | ||
) | ||
} | ||
Error::SerializationError(e) => { | ||
write!(f, "Serialization error: {}", e) | ||
} | ||
Error::InvalidSeedLength(len) => { | ||
write!(f, "Invalid seed length: {}", len) | ||
} | ||
} | ||
} | ||
} | ||
|
||
type Result<T> = std::result::Result<T, Error>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ | |
Keypair, | ||
Validator, | ||
Dkg, | ||
DkgPublicKey | ||
DkgPublicKey, | ||
FerveoPublicKey, | ||
SharedSecret, | ||
) | ||
|
||
|
||
|
@@ -34,26 +36,44 @@ def make_dkg_public_key(): | |
|
||
|
||
def make_shared_secret(): | ||
# TODO: implement this | ||
# TODO: Implement this | ||
# SharedSecret.from_bytes(os.urandom(584)) | ||
pass | ||
|
||
|
||
def make_pk(): | ||
return Keypair.random().public_key() | ||
|
||
|
||
# def test_shared_secret_serialization(): | ||
# shared_secret = create_shared_secret_instance() | ||
# shared_secret = make_shared_secret() | ||
# serialized = bytes(shared_secret) | ||
# deserialized = SharedSecret.from_bytes(serialized) | ||
# TODO: Implement comparison | ||
# assert shared_secret == deserialized | ||
# # TODO: Implement __richcmp__ | ||
# # assert shared_secret == deserialized | ||
# assert serialized == bytes(deserialized) | ||
|
||
def test_keypair_serialization(): | ||
keypair = Keypair.random() | ||
serialized = bytes(keypair) | ||
deserialized = Keypair.from_bytes(serialized) | ||
# TODO: Implement comparison | ||
# assert keypair == deserialized | ||
# TODO: Implement __richcmp__ | ||
# assert serialized == deserialized | ||
assert serialized == bytes(deserialized) | ||
|
||
|
||
def test_dkg_public_key_serialization(): | ||
dkg_pk = make_dkg_public_key() | ||
serialized = bytes(dkg_pk) | ||
deserialized = DkgPublicKey.from_bytes(serialized) | ||
# TODO: Implement __richcmp__ | ||
assert serialized == bytes(deserialized) | ||
assert len(serialized) == DkgPublicKey.serialized_size() | ||
|
||
|
||
def test_public_key_serialization(): | ||
pk = make_pk() | ||
serialized = bytes(pk) | ||
deserialized = FerveoPublicKey.from_bytes(serialized) | ||
assert pk == deserialized | ||
assert len(serialized) == FerveoPublicKey.serialized_size() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to also use Same for L59 as well. |
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.
Can the commented-out TODOs in this test file now be uncommented due to the updated bindings?
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've tried to update some of these tests but I didn't implement
__richcmp__
for all types involved, so I'm going to cut some corners here. Ideally, we would have all class methods implemented, but that's a bit of work and not really worth the effort at this point IMHO.