Skip to content

Commit

Permalink
chore: dont depend on ed25519 on unionlabs
Browse files Browse the repository at this point in the history
Signed-off-by: aeryz <[email protected]>
  • Loading branch information
aeryz committed Mar 5, 2025
1 parent 684f709 commit f484389
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion lib/unionlabs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ bcs = { workspace = true }
bincode = { workspace = true, features = ["alloc", "derive"], optional = true }
borsh = { workspace = true, features = ["borsh-derive"], optional = true }
bs58 = "0.4"
ed25519-zebra = { version = "4.0" }
near-primitives-core = { version = "0.21", optional = true }
near-sdk = { workspace = true, optional = true }
schemars = { workspace = true, features = ["derive"], optional = true }
Expand Down
25 changes: 8 additions & 17 deletions lib/unionlabs/src/aptos/signed_data.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use ed25519_zebra::SigningKey;
use macros::model;
use sha2::Digest;
use unionlabs_primitives::H512;
Expand All @@ -13,22 +12,14 @@ pub struct SignedData<T> {
}

impl<T: Encode<Bincode> + Clone> SignedData<T> {
pub fn sign(signing_key: &SigningKey, data: T) -> Self {
let signature = signing_key.sign(&Self::internal_hash(&data));
Self {
signature: H512::new(signature.to_bytes()),
data,
}
}

fn internal_hash(data: &T) -> Vec<u8> {
sha2::Sha256::new()
.chain_update(data.clone().encode())
.finalize()
.to_vec()
}

pub fn hash(&self) -> Vec<u8> {
Self::internal_hash(&self.data)
hash_signature_data(self.data.clone())
}
}

pub fn hash_signature_data<T: Encode<Bincode> + Clone>(data: T) -> Vec<u8> {
sha2::Sha256::new()
.chain_update(data.encode())
.finalize()
.to_vec()
}
29 changes: 16 additions & 13 deletions voyager/modules/proof/movement/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ use serde_json::Value;
use tracing::{debug, instrument};
use unionlabs::{
aptos::{
signed_data::SignedData,
signed_data::{hash_signature_data, SignedData},
sparse_merkle_proof::{SparseMerkleLeafNode, SparseMerkleProof},
storage_proof::{StateValue, StateValueMetadata, StorageProof},
},
ibc::core::client::height::Height,
primitives::{H256, U256},
primitives::{H256, H512, U256},
ErrorReporter,
};
use voyager_message::{
Expand Down Expand Up @@ -157,19 +157,22 @@ impl ProofModuleServer<IbcUnion> for Module {
// at.revision_height,
// ).await;

let signed_data = SignedData::sign(
&self.auth_signing_key,
StorageProof {
state_value: None,
proof: SparseMerkleProof {
leaf: None,
siblings: Vec::new(),
},
let proof = StorageProof {
state_value: None,
proof: SparseMerkleProof {
leaf: None,
siblings: Vec::new(),
},
);

};
let signed_data = self
.auth_signing_key
.sign(&hash_signature_data(proof.clone()));
let signed_proof = SignedData {
signature: H512::new(signed_data.to_bytes()),
data: proof,
};
Ok((
into_value(signed_data),
into_value(signed_proof),
// TODO: Implement properly, see above
ProofType::Membership,
))
Expand Down
14 changes: 11 additions & 3 deletions voyager/plugins/client-update/movement/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ use serde::{Deserialize, Serialize};
use tracing::{debug, instrument};
use unionlabs::{
aptos::{
account::AccountAddress, signed_data::SignedData, state_proof::StateProof,
account::AccountAddress,
signed_data::{hash_signature_data, SignedData},
state_proof::StateProof,
transaction_proof::TransactionInfoWithProof,
},
ibc::core::client::height::Height,
primitives::{H160, H256},
primitives::{H160, H256, H512},
};
use voyager_message::{
call::Call,
Expand Down Expand Up @@ -236,7 +238,13 @@ impl PluginServer<ModuleCall, ModuleCallback> for Module {
},
new_height: to,
};
let signed_header = SignedData::sign(&self.auth_signing_key, header);
let signed_data = self
.auth_signing_key
.sign(&hash_signature_data(header.clone()));
let signed_header = SignedData {
signature: H512::new(signed_data.to_bytes()),
data: header,
};
Ok(data(OrderedHeaders {
headers: vec![(
DecodedHeaderMeta {
Expand Down

0 comments on commit f484389

Please sign in to comment.