Skip to content

Commit

Permalink
test still fails
Browse files Browse the repository at this point in the history
  • Loading branch information
sebasti810 committed Sep 20, 2024
1 parent fc052fe commit 473b790
Show file tree
Hide file tree
Showing 22 changed files with 188 additions and 167 deletions.
50 changes: 38 additions & 12 deletions Cargo.lock

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

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ async-trait = "0.1.68"
serde = { version = "1.0.151", features = ["derive"] }
serde_json = "1.0.79"
redis = "0.24.0"
ed25519-dalek = "2.1.0"
ed25519 = "2.2.0"
base64 = "0.22.0"
tokio = { version = "1.16.1", features = ["full"] }
num = "0.4.0"
Expand Down Expand Up @@ -70,7 +68,7 @@ sha2 = "0.10.8"
auto_impl = "1.2.0"
bincode = "1.3.3"
ed25519-consensus = "2.1.0"
curve25519-dalek = "4.1.3"
ed25519-dalek = "2.1.1"
secp256k1 = "0.29.0"
sp1-zkvm = { version = "1.2.0" }
sp1-sdk = { version = "1.2.0" }
Expand All @@ -82,10 +80,14 @@ prism-groth16 = { path = "crates/groth16" }

[patch.crates-io]
sha2-v0-10-8 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", package = "sha2", branch = "patch-sha2-v0.10.8" }
curve25519-dalek = { git = "https://github.com/sp1-patches/curve25519-dalek", branch = "patch-curve25519-v4.1.3" }
curve25519-dalek = { git = "https://github.com/sp1-patches/curve25519-dalek", branch = "patch-curve25519-v4.1.3", package = "ed25519-dalek"}
secp256k1 = { git = "https://github.com/sp1-patches/rust-secp256k1", branch = "patch-secp256k1-v0.29.0" }
ed25519-consensus = { git = "https://github.com/sp1-patches/ed25519-consensus", branch = "patch-v2.1.0" }

[workspace.features]
default = []
test_utils = []

# [workspace.dev-dependencies]
# serial_test = "3.1.1"
# criterion = "0.5.1"
Expand Down
6 changes: 5 additions & 1 deletion crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ sha2.workspace = true
celestia-types.workspace = true
bincode.workspace = true
ed25519-dalek.workspace = true
ed25519.workspace = true
ed25519-consensus.workspace = true
base64.workspace = true
rand.workspace = true

[features]
default = []
test_utils = []
7 changes: 2 additions & 5 deletions crates/common/src/hashchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ use std::{
};

use crate::{
operation::{
CreateAccountArgs, KeyOperationArgs, Operation, PublicKey, ServiceChallengeInput,
SignatureBundle,
},
operation::{CreateAccountArgs, Operation, PublicKey, ServiceChallengeInput},
tree::{hash, Digest, Hasher},
};

Expand Down Expand Up @@ -191,7 +188,7 @@ impl Hashchain {
self.verify_signature(&signing_key, &message, &args.signature.signature)
}
// TODO
Operation::CreateAccount(_) => unimplemented!()
Operation::CreateAccount(_) => unimplemented!(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ pub mod operation;
pub mod signed_content;
pub mod tree;

// todo: add testing feature for use across crates, so we dont have to expose it
#[cfg(feature = "test_utils")]
pub mod test_utils;
46 changes: 23 additions & 23 deletions crates/common/src/operation.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use anyhow::{bail, Context, Result};
use anyhow::{Context, Result};
use bincode;
use celestia_types::Blob;
use prism_errors::GeneralError;
use serde::{Deserialize, Serialize};
use std::{self, fmt::Display, str::FromStr};

use crate::hashchain::Hashchain;
use std::{self, fmt::Display};

#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Hash)]
/// Represents a public key supported by the system.
Expand Down Expand Up @@ -86,6 +84,17 @@ impl Operation {
}
}

pub fn get_signature_bundle(&self) -> Option<SignatureBundle> {
match self {
Operation::AddKey(args) => Some(args.signature.clone()),
Operation::RevokeKey(args) => Some(args.signature.clone()),
Operation::CreateAccount(args) => Some(SignatureBundle {
key_idx: 0,
signature: args.signature.clone(),
}),
}
}

pub fn without_signature(&self) -> Self {
match self {
Operation::AddKey(args) => Operation::AddKey(KeyOperationArgs {
Expand All @@ -104,23 +113,20 @@ impl Operation {
signature: Vec::new(),
},
}),
// TODO: create account
_ => panic!("Unsupported operation type"),
Operation::CreateAccount(args) => Operation::CreateAccount(CreateAccountArgs {
id: args.id.clone(),
value: args.value.clone(),
signature: Vec::new(),
service_id: args.service_id.clone(),
challenge: args.challenge.clone(),
}),
}
}

pub fn validate(&self) -> Result<()> {
match &self {
Operation::AddKey(KeyOperationArgs {
id,
value,
signature,
})
| Operation::RevokeKey(KeyOperationArgs {
id,
value,
signature,
}) => {
Operation::AddKey(KeyOperationArgs { id, signature, .. })
| Operation::RevokeKey(KeyOperationArgs { id, signature, .. }) => {
if id.is_empty() {
return Err(
GeneralError::MissingArgumentError("id is empty".to_string()).into(),
Expand All @@ -138,13 +144,7 @@ impl Operation {

Ok(())
}
Operation::CreateAccount(CreateAccountArgs {
id,
value,
signature,
service_id: _,
challenge,
}) => {
Operation::CreateAccount(CreateAccountArgs { id, challenge, .. }) => {
if id.is_empty() {
return Err(
GeneralError::MissingArgumentError("id is empty".to_string()).into(),
Expand Down
13 changes: 8 additions & 5 deletions crates/common/src/signed_content.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use anyhow::Result;
use base64::{engine::general_purpose::STANDARD as engine, Engine as _};
use ed25519::Signature;
use ed25519_dalek::{Verifier, VerifyingKey as Ed25519VerifyingKey};
use ed25519_consensus::Signature;
use ed25519_consensus::VerificationKey;
use ed25519_consensus::VerificationKeyBytes;
use prism_errors::{GeneralError, PrismError};

pub trait SignedContent {
Expand All @@ -10,7 +11,7 @@ pub trait SignedContent {
fn get_public_key(&self) -> Result<String>;
}

pub fn decode_public_key(pub_key_str: &String) -> Result<Ed25519VerifyingKey> {
pub fn decode_public_key(pub_key_str: &String) -> Result<VerificationKey> {
// decode the public key from base64 string to bytes
let public_key_bytes = engine
.decode(pub_key_str)
Expand All @@ -20,7 +21,9 @@ pub fn decode_public_key(pub_key_str: &String) -> Result<Ed25519VerifyingKey> {
.try_into()
.map_err(|_| GeneralError::ParsingError("Vec<u8> to [u8; 32]".to_string()))?;

Ed25519VerifyingKey::from_bytes(&public_key_array)
VerificationKeyBytes::try_from(public_key_array)
.map_err(|_| GeneralError::DecodingError("ed25519 verifying key bytes".to_string()))?
.try_into()
.map_err(|_| GeneralError::DecodingError("ed25519 verifying key".to_string()).into())
}

Expand All @@ -40,7 +43,7 @@ pub fn verify_signature<T: SignedContent>(
let content = item.get_plaintext()?;
let signature = item.get_signature()?;

match public_key.verify(content.as_slice(), &signature) {
match public_key.verify(&signature, content.as_slice()) {
Ok(_) => Ok(content),
Err(e) => Err(GeneralError::InvalidSignature(e).into()),
}
Expand Down
Loading

0 comments on commit 473b790

Please sign in to comment.