Skip to content
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

Add dusk_bytes::Serializable for poseidon_merkle::Item<()> #88

Merged
merged 1 commit into from
Aug 8, 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
4 changes: 4 additions & 0 deletions poseidon-merkle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Implement `dusk_bytes::Serializable` for `Item<()>`

## [0.6.0] - 2024-05-22

### Changed
Expand Down
3 changes: 2 additions & 1 deletion poseidon-merkle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ edition = "2021"
license = "MPL-2.0"

[dependencies]
dusk-bytes = "0.1"
dusk-merkle = "0.5"
dusk-poseidon = "0.39"
dusk-bls12_381 = { version = "0.13", default-features = false }
Expand All @@ -38,7 +39,7 @@ rkyv-impl = [
"rkyv",
"bytecheck",
"dusk-bls12_381/rkyv-impl",
"dusk-merkle/rkyv-impl"
"dusk-merkle/rkyv-impl",
]

[[bench]]
Expand Down
19 changes: 19 additions & 0 deletions poseidon-merkle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
pub mod zk;

use dusk_bls12_381::BlsScalar;
use dusk_bytes::Serializable;
use dusk_merkle::Aggregate;
use dusk_poseidon::{Domain, Hash};

Expand Down Expand Up @@ -152,3 +153,21 @@ where
}
}
}

impl Serializable<32> for Item<()> {
type Error = <BlsScalar as Serializable<32>>::Error;

fn from_bytes(buf: &[u8; 32]) -> Result<Self, Self::Error>
where
Self: Sized,
{
Ok(Item {
hash: <BlsScalar as Serializable<32>>::from_bytes(buf)?,
data: (),
})
}

fn to_bytes(&self) -> [u8; 32] {
self.hash.to_bytes()
}
}