Skip to content

Commit

Permalink
fix: order of fields in Proof
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Jan 10, 2024
1 parent d8e1d52 commit 5fa15e3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
20 changes: 7 additions & 13 deletions moksha-core/src/dhke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ pub fn public_key_from_hex(hex: &str) -> secp256k1::PublicKey {

#[cfg(test)]
mod tests {
use std::str::FromStr;

use crate::dhke::{public_key_from_hex, Dhke};
use anyhow::Ok;
use pretty_assertions::assert_eq;
Expand All @@ -154,10 +156,8 @@ mod tests {
String::from_utf8(input_vec).expect("Invalid UTF-8 String")
}

fn private_key_from_hex(hex: &str) -> secp256k1::SecretKey {
use hex::FromHex;
let input_vec: Vec<u8> = Vec::from_hex(hex).expect("Invalid Hex String");
secp256k1::SecretKey::from_slice(&input_vec).expect("Invalid SecretKey")
fn pk_from_hex(hex: &str) -> secp256k1::SecretKey {
secp256k1::SecretKey::from_str(hex).expect("Invalid SecretKey")
}

#[test]
Expand Down Expand Up @@ -221,9 +221,7 @@ mod tests {
hex_to_string("0000000000000000000000000000000000000000000000000000000000000001");
let (pub_key, _) = dhke.step1_alice("test_message", Some(blinding_factor.as_bytes()))?;

let a = private_key_from_hex(
"0000000000000000000000000000000000000000000000000000000000000001",
);
let a = pk_from_hex("0000000000000000000000000000000000000000000000000000000000000001");

let c = dhke.step2_bob(pub_key, &a)?;
let c_str = c.to_string();
Expand All @@ -242,9 +240,7 @@ mod tests {
"02a9acc1e48c25eeeb9289b5031cc57da9fe72f3fe2861d264bdc074209b107ba2",
);

let r = private_key_from_hex(
"0000000000000000000000000000000000000000000000000000000000000001",
);
let r = pk_from_hex("0000000000000000000000000000000000000000000000000000000000000001");

let a = public_key_from_hex(
"020000000000000000000000000000000000000000000000000000000000000001",
Expand Down Expand Up @@ -275,9 +271,7 @@ mod tests {
let dhke = Dhke::new();

// Generate Alice's private key and public key
let a = private_key_from_hex(
"0000000000000000000000000000000000000000000000000000000000000001",
);
let a = pk_from_hex("0000000000000000000000000000000000000000000000000000000000000001");
let A = a.public_key(&dhke.secp);

let blinding_factor =
Expand Down
4 changes: 2 additions & 2 deletions moksha-core/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ use crate::error::MokshaCoreError;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, ToSchema)]
pub struct Proof {
pub amount: u64,
#[serde(rename = "id")]
pub keyset_id: String, // FIXME use keysetID as specific type
pub secret: String,
#[serde(rename = "C")]
#[schema(value_type = String)]
pub c: PublicKey,
#[serde(rename = "id")]
pub keyset_id: String, // FIXME use keysetID as specific type
pub script: Option<P2SHScript>,
}

Expand Down
8 changes: 1 addition & 7 deletions moksha-core/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ impl TokenV3 {

pub fn serialize(&self) -> Result<String, MokshaCoreError> {
let json = serde_json::to_string(&self)?;
println!("json: {}", json);
Ok(format!(
"{}{}",
TOKEN_PREFIX_V3,
Expand Down Expand Up @@ -201,8 +200,7 @@ mod tests {
assert_eq!(token.unit, Some(CurrencyUnit::Sat));

let token_serialized = token.serialize()?;
// FIXME this fails
//assert_eq!(token_serialized, "cashuAeyJ0b2tlbiI6W3sibWludCI6Imh0dHBzOi8vODMzMy5zcGFjZTozMzM4IiwicHJvb2ZzIjpbeyJhbW91bnQiOjIsImlkIjoiMDA5YTFmMjkzMjUzZTQxZSIsInNlY3JldCI6IjQwNzkxNWJjMjEyYmU2MWE3N2UzZTZkMmFlYjRjNzI3OTgwYmRhNTFjZDA2YTZhZmMyOWUyODYxNzY4YTc4MzciLCJDIjoiMDJiYzkwOTc5OTdkODFhZmIyY2M3MzQ2YjVlNDM0NWE5MzQ2YmQyYTUwNmViNzk1ODU5OGE3MmYwY2Y4NTE2M2VhIn0seyJhbW91bnQiOjgsImlkIjoiMDA5YTFmMjkzMjUzZTQxZSIsInNlY3JldCI6ImZlMTUxMDkzMTRlNjFkNzc1NmIwZjhlZTBmMjNhNjI0YWNhYTNmNGUwNDJmNjE0MzNjNzI4YzcwNTdiOTMxYmUiLCJDIjoiMDI5ZThlNTA1MGI4OTBhN2Q2YzA5NjhkYjE2YmMxZDVkNWZhMDQwZWExZGUyODRmNmVjNjlkNjEyOTlmNjcxMDU5In1dfV0sInVuaXQiOiJzYXQiLCJtZW1vIjoiVGhhbmsgeW91LiJ9");
assert_eq!(token_serialized, "cashuAeyJ0b2tlbiI6W3sibWludCI6Imh0dHBzOi8vODMzMy5zcGFjZTozMzM4IiwicHJvb2ZzIjpbeyJhbW91bnQiOjIsImlkIjoiMDA5YTFmMjkzMjUzZTQxZSIsInNlY3JldCI6IjQwNzkxNWJjMjEyYmU2MWE3N2UzZTZkMmFlYjRjNzI3OTgwYmRhNTFjZDA2YTZhZmMyOWUyODYxNzY4YTc4MzciLCJDIjoiMDJiYzkwOTc5OTdkODFhZmIyY2M3MzQ2YjVlNDM0NWE5MzQ2YmQyYTUwNmViNzk1ODU5OGE3MmYwY2Y4NTE2M2VhIn0seyJhbW91bnQiOjgsImlkIjoiMDA5YTFmMjkzMjUzZTQxZSIsInNlY3JldCI6ImZlMTUxMDkzMTRlNjFkNzc1NmIwZjhlZTBmMjNhNjI0YWNhYTNmNGUwNDJmNjE0MzNjNzI4YzcwNTdiOTMxYmUiLCJDIjoiMDI5ZThlNTA1MGI4OTBhN2Q2YzA5NjhkYjE2YmMxZDVkNWZhMDQwZWExZGUyODRmNmVjNjlkNjEyOTlmNjcxMDU5In1dfV0sInVuaXQiOiJzYXQiLCJtZW1vIjoiVGhhbmsgeW91LiJ9");
Ok(())
}

Expand Down Expand Up @@ -273,10 +271,6 @@ mod tests {
let tokens = TokenV3::deserialize(input)?;
assert_eq!(tokens.memo, Some("Thank you.".to_string()),);
assert_eq!(tokens.tokens.len(), 1);
println!("tokens: {:?}", tokens);
let js = serde_json::to_string_pretty(&tokens).unwrap();
println!("{}", js);

Ok(())
}
}

0 comments on commit 5fa15e3

Please sign in to comment.