-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: commit reveal test passing again
- Loading branch information
Showing
21 changed files
with
638 additions
and
455 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use k256::ecdsa::{RecoveryId, Signature, VerifyingKey}; | ||
|
||
use crate::types::{Secpk256k1PublicKey, Signature as Sig}; | ||
|
||
pub fn recover_pubkey(msg_hash: [u8; 32], signature: Sig) -> Secpk256k1PublicKey { | ||
let rs = signature.0[0..64].into(); | ||
let id = match signature.0[64] { | ||
0 => RecoveryId::new(false, false), | ||
1 => RecoveryId::new(true, false), | ||
_ => todo!("ERROR"), | ||
}; | ||
|
||
let sig = Signature::from_bytes(rs).expect("TODO"); | ||
|
||
// Recover | ||
let pubkey = VerifyingKey::recover_from_msg(&msg_hash, &sig, id).expect("TODO"); | ||
pubkey.to_sec1_bytes().to_vec() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod consts; | ||
pub mod crypto; | ||
pub mod error; | ||
pub mod msg; | ||
pub mod state; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,92 @@ | ||
use schemars::{ | ||
gen::SchemaGenerator, | ||
schema::{Schema, SchemaObject, SingleOrVec}, | ||
JsonSchema, | ||
}; | ||
use serde::{ | ||
de::{SeqAccess, Visitor}, | ||
ser::SerializeTuple, | ||
Deserialize, Deserializer, Serialize, Serializer, | ||
}; | ||
|
||
pub type Bytes = Vec<u8>; | ||
pub type Commitment = Hash; | ||
pub type Memo = Vec<u8>; | ||
pub type Hash = [u8; 32]; | ||
pub type Secpk256k1PublicKey = Vec<u8>; | ||
|
||
#[derive(Clone, Debug, PartialEq)] | ||
pub struct Signature(pub(crate) [u8; 65]); | ||
|
||
impl Signature { | ||
pub fn new(signature: [u8; 65]) -> Self { | ||
Self(signature) | ||
} | ||
} | ||
|
||
impl Serialize for Signature { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
let mut seq = serializer.serialize_tuple(65)?; | ||
for byte in &self.0 { | ||
seq.serialize_element(byte)?; | ||
} | ||
seq.end() | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for Signature { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
struct ArrayVisitor; | ||
|
||
impl<'de> Visitor<'de> for ArrayVisitor { | ||
type Value = Signature; | ||
|
||
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
formatter.write_str("a byte array of length 65") | ||
} | ||
|
||
fn visit_seq<V>(self, mut seq: V) -> Result<Signature, V::Error> | ||
where | ||
V: SeqAccess<'de>, | ||
{ | ||
let mut array = [0u8; 65]; | ||
for (i, byte) in array.iter_mut().enumerate() { | ||
*byte = seq | ||
.next_element()? | ||
.ok_or_else(|| serde::de::Error::invalid_length(i, &self))?; | ||
} | ||
Ok(Signature(array)) | ||
} | ||
} | ||
|
||
deserializer.deserialize_tuple(65, ArrayVisitor) | ||
} | ||
} | ||
|
||
impl JsonSchema for Signature { | ||
fn schema_name() -> String { | ||
"Signature65".to_string() | ||
} | ||
|
||
fn json_schema(gen: &mut SchemaGenerator) -> Schema { | ||
let schema = SchemaObject { | ||
instance_type: Some(schemars::schema::InstanceType::Array.into()), | ||
array: Some(Box::new(schemars::schema::ArrayValidation { | ||
items: Some(SingleOrVec::Single(Box::new(gen.subschema_for::<u8>()))), | ||
min_items: Some(65), | ||
max_items: Some(65), | ||
unique_items: Some(false), | ||
additional_items: None, | ||
contains: None, | ||
})), | ||
..Default::default() | ||
}; | ||
schema.into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.