Skip to content

Commit

Permalink
imp: removed ethereum-utils::base64
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed Dec 11, 2024
1 parent 2b5eaa0 commit b1e90e2
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 23 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion packages/ethereum-light-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
thiserror = { workspace = true }
sha2 = { workspace = true }
serde_with = { workspace = true }
serde_with = { workspace = true, features = ["base64"] }

# TODO: From union (might be removed if they are replaced by something more standard). #147
typenum = { workspace = true, features = ["const-generics"] }
Expand Down
4 changes: 3 additions & 1 deletion packages/ethereum-light-client/src/test/fixture_types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use serde::{Deserialize, Serialize};
use serde_with::{base64::Base64, serde_as};

use crate::{
client_state::ClientState,
Expand All @@ -21,9 +22,10 @@ pub struct InitialState {
pub consensus_state: ConsensusState,
}

#[serde_as]
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug)]
pub struct CommitmentProof {
#[serde(with = "ethereum_utils::base64")]
#[serde_as(as = "Base64")]
pub path: Vec<u8>,
pub storage_proof: StorageProof,
pub proof_height: Height,
Expand Down
4 changes: 3 additions & 1 deletion packages/ethereum-light-client/src/types/sync_committee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use alloy_primitives::Bytes;
use ethereum_utils::slot::compute_epoch_at_slot;
use serde::{Deserialize, Serialize};
use serde_with::{base64::Base64, serde_as};
use tree_hash_derive::TreeHash;

use super::{
Expand Down Expand Up @@ -70,10 +71,11 @@ impl TrustedSyncCommittee {
}

/// The sync committee aggregate
#[serde_as]
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, Default)]
pub struct SyncAggregate {
/// The bits representing the sync committee's participation.
#[serde(with = "ethereum_utils::base64")]
#[serde_as(as = "Base64")]
pub sync_committee_bits: Bytes, // TODO: Consider changing this to a BitVector
/// The aggregated signature of the sync committee.
#[serde(with = "ethereum_utils::base64::fixed_size")]
Expand Down
4 changes: 3 additions & 1 deletion packages/ethereum-light-client/src/types/wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use alloy_primitives::{aliases::B32, Bloom, Bytes, FixedBytes, B256};
use serde::{Deserialize, Serialize};
use serde_with::{base64::Base64, serde_as};
use tree_hash::{MerkleHasher, TreeHash, BYTES_PER_CHUNK};

use super::bls::BlsPublicKey;
Expand Down Expand Up @@ -30,8 +31,9 @@ impl TreeHash for WrappedVersion {
}

/// A wrapper around [`Bytes`] that implements [`TreeHash`] and uses a base64 encoding.
#[serde_as]
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, Default)]
pub struct WrappedBytes(#[serde(with = "ethereum_utils::base64")] pub Bytes);
pub struct WrappedBytes(#[serde_as(as = "Base64")] pub Bytes);

impl TreeHash for WrappedBytes {
fn tree_hash_type() -> tree_hash::TreeHashType {
Expand Down
18 changes: 0 additions & 18 deletions packages/ethereum-utils/src/base64.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use alloy_primitives::B256;
use base64::{prelude::*, DecodeError};
use serde::{de, Deserialize, Deserializer};

pub trait FromBase64: Sized {
fn from_base64(s: &str) -> Result<Self, DecodeError>;
Expand All @@ -17,23 +16,6 @@ impl FromBase64 for B256 {
}
}

pub fn serialize<S, T: AsRef<[u8]>>(data: T, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(&BASE64_STANDARD.encode(data))
}

pub fn deserialize<'de, D, T>(deserializer: D) -> Result<T, D::Error>
where
D: Deserializer<'de>,
T: TryFrom<Vec<u8>>,
{
let s = String::deserialize(deserializer)?;
let decoded = from_base64(&s).map_err(de::Error::custom)?;
T::try_from(decoded).map_err(|_| de::Error::custom("Invalid base64 data"))
}

pub mod fixed_size {
use base64::prelude::*;
use serde::{de, Deserialize, Deserializer};
Expand Down
1 change: 1 addition & 0 deletions programs/cw-ics08-wasm-eth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ cw-storage-plus = { workspace = true }
prost = { workspace = true, features = ["std"] }
serde = { workspace = true }
serde_json = { workspace = true }
serde_with = { workspace = true, features = ["base64"] }
thiserror = { workspace = true }

[dev-dependencies]
Expand Down
4 changes: 3 additions & 1 deletion programs/cw-ics08-wasm-eth/src/test/fixture_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use ethereum_light_client::{
types::{height::Height, light_client::Header, storage_proof::StorageProof},
};
use serde::{Deserialize, Serialize};
use serde_with::{base64::Base64, serde_as};

// TODO: Remove this file once these types are in a separate package #143

Expand All @@ -20,9 +21,10 @@ pub struct InitialState {
pub consensus_state: ConsensusState,
}

#[serde_as]
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug)]
pub struct CommitmentProof {
#[serde(with = "ethereum_utils::base64")]
#[serde_as(as = "Base64")]
pub path: Vec<u8>,
pub storage_proof: StorageProof,
pub proof_height: Height,
Expand Down

0 comments on commit b1e90e2

Please sign in to comment.