Skip to content

Commit

Permalink
Merge branch 'main' into smuu/20241213-test-all-curves
Browse files Browse the repository at this point in the history
  • Loading branch information
smuu committed Dec 19, 2024
2 parents bacc54e + 6473451 commit ef9b950
Show file tree
Hide file tree
Showing 21 changed files with 640 additions and 604 deletions.
20 changes: 17 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ default-members = [
"crates/da",
"crates/serde",
"crates/keys",
"crates/tree",
]

members = [
Expand All @@ -40,6 +41,7 @@ members = [
"crates/da",
"crates/serde",
"crates/keys",
"crates/tree",
]
resolver = "2"

Expand Down Expand Up @@ -117,6 +119,7 @@ prism-prover = { path = "crates/node_types/prover" }
prism-tests = { path = "crates/tests" }
prism-keys = { path = "crates/keys" }
prism-serde = { path = "crates/serde" }
prism-tree = { path = "crates/tree" }
prism-lightclient = { path = "crates/node_types/lightclient" }

[patch.crates-io]
Expand Down
5 changes: 1 addition & 4 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ repository.workspace = true

[dependencies]
# prism
prism-errors.workspace = true
prism-keys.workspace = true

# serde
Expand All @@ -18,13 +17,11 @@ serde.workspace = true
# celestia
celestia-types.workspace = true

# tree
jmt.workspace = true
# digest
sha2.workspace = true

# misc
anyhow.workspace = true
log.workspace = true
rand.workspace = true

[features]
Expand Down
23 changes: 5 additions & 18 deletions crates/common/src/digest.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use anyhow::Result;
use jmt::RootHash;
use serde::{Deserialize, Serialize};

use crate::hasher::Hasher;
use prism_serde::{
base64::FromBase64,
hex::{FromHex, ToHex},
raw_or_hex,
};
use sha2::{Digest as _, Sha256};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Copy)]
pub struct Digest(#[serde(with = "raw_or_hex")] pub [u8; 32]);
Expand All @@ -18,17 +17,17 @@ impl Digest {
}

pub fn hash(data: impl AsRef<[u8]>) -> Self {
let mut hasher = Hasher::new();
let mut hasher = Sha256::new();
hasher.update(data.as_ref());
Self(hasher.finalize())
Self(hasher.finalize().into())
}

pub fn hash_items(items: &[impl AsRef<[u8]>]) -> Self {
let mut hasher = Hasher::new();
let mut hasher = Sha256::new();
for item in items {
hasher.update(item.as_ref());
}
Self(hasher.finalize())
Self(hasher.finalize().into())
}

pub const fn zero() -> Self {
Expand All @@ -52,18 +51,6 @@ impl<const N: usize> From<[u8; N]> for Digest {
}
}

impl From<Digest> for RootHash {
fn from(val: Digest) -> RootHash {
RootHash::from(val.0)
}
}

impl From<RootHash> for Digest {
fn from(val: RootHash) -> Digest {
Digest(val.0)
}
}

impl AsRef<[u8]> for Digest {
fn as_ref(&self) -> &[u8] {
&self.0
Expand Down
5 changes: 0 additions & 5 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
pub mod digest;
pub mod hashchain;
pub mod hasher;
pub mod operation;
pub mod transaction;
pub mod tree;

#[macro_use]
extern crate log;

#[cfg(feature = "test_utils")]
pub mod transaction_builder;
Loading

0 comments on commit ef9b950

Please sign in to comment.