Skip to content

Commit

Permalink
chore: split model into blind and keyset modules
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Oct 25, 2023
1 parent ffe5cbe commit 6bf6c52
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 43 deletions.
3 changes: 2 additions & 1 deletion flutter/native/src/wasm_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::collections::HashMap;

use async_trait::async_trait;
use gloo_net::http::{Request, Response};
use moksha_core::model::{BlindedMessage, Keysets};
use moksha_core::blind::BlindedMessage;
use moksha_core::keyset::Keysets;
use moksha_core::primitives::CashuErrorResponse;
use moksha_core::primitives::{
CheckFeesRequest, CheckFeesResponse, PaymentRequest, PostMeltRequest, PostMeltResponse,
Expand Down
33 changes: 33 additions & 0 deletions moksha-core/src/blind.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use secp256k1::PublicKey;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BlindedMessage {
pub amount: u64,
#[serde(rename = "B_")]
pub b_: PublicKey,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BlindedSignature {
pub amount: u64,
#[serde(rename = "C_")]
pub c_: PublicKey,
pub id: Option<String>,
}

pub trait TotalAmount {
fn total_amount(&self) -> u64;
}

impl TotalAmount for Vec<BlindedSignature> {
fn total_amount(&self) -> u64 {
self.iter().fold(0, |acc, x| acc + x.amount)
}
}

impl TotalAmount for Vec<BlindedMessage> {
fn total_amount(&self) -> u64 {
self.iter().fold(0, |acc, x| acc + x.amount)
}
}
31 changes: 0 additions & 31 deletions moksha-core/src/model.rs → moksha-core/src/keyset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,6 @@ use crate::{
error::MokshaCoreError,
};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BlindedMessage {
pub amount: u64,
#[serde(rename = "B_")]
pub b_: PublicKey,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BlindedSignature {
pub amount: u64,
#[serde(rename = "C_")]
pub c_: PublicKey,
pub id: Option<String>,
}

pub trait TotalAmount {
fn total_amount(&self) -> u64;
}

impl TotalAmount for Vec<BlindedSignature> {
fn total_amount(&self) -> u64 {
self.iter().fold(0, |acc, x| acc + x.amount)
}
}

impl TotalAmount for Vec<BlindedMessage> {
fn total_amount(&self) -> u64 {
self.iter().fold(0, |acc, x| acc + x.amount)
}
}

#[derive(Debug, Clone)]
pub struct MintKeyset {
pub private_keys: HashMap<u64, SecretKey>,
Expand Down
3 changes: 2 additions & 1 deletion moksha-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
pub mod amount;
pub mod blind;
pub mod crypto;
pub mod dhke;
pub mod error;
pub mod fixture;
pub mod model;
pub mod keyset;
pub mod primitives;
pub mod proof;
pub mod token;
2 changes: 1 addition & 1 deletion moksha-core/src/primitives.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};

use crate::{
model::{BlindedMessage, BlindedSignature},
blind::{BlindedMessage, BlindedSignature},
proof::Proofs,
};

Expand Down
5 changes: 3 additions & 2 deletions moksha-mint/src/mint.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::{collections::HashSet, sync::Arc};

use moksha_core::{
blind::{BlindedMessage, BlindedSignature, TotalAmount},
crypto,
dhke::Dhke,
model::{BlindedMessage, BlindedSignature, MintKeyset, TotalAmount},
keyset::MintKeyset,
primitives::PostSplitResponse,
proof::Proofs,
};
Expand Down Expand Up @@ -309,8 +310,8 @@ mod tests {
use crate::mint::Mint;
use crate::model::{Invoice, PayInvoiceResult};
use crate::{database::MockDatabase, error::MokshaMintError};
use moksha_core::blind::{BlindedMessage, TotalAmount};
use moksha_core::dhke;
use moksha_core::model::{BlindedMessage, TotalAmount};
use moksha_core::primitives::PostSplitRequest;
use moksha_core::proof::Proofs;
use moksha_core::token::TokenV3;
Expand Down
4 changes: 2 additions & 2 deletions moksha-mint/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use axum::extract::{Query, State};
use axum::routing::{get_service, post};
use axum::Router;
use axum::{routing::get, Json};
use moksha_core::model::Keysets;
use moksha_core::keyset::Keysets;

use crate::info::{MintInfoResponse, Parameter};

Expand Down Expand Up @@ -210,7 +210,7 @@ mod tests {

use crate::server::app;
use hyper::{Body, Request, StatusCode};
use moksha_core::model::Keysets;
use moksha_core::keyset::Keysets;
use secp256k1::PublicKey;
use tower::ServiceExt;

Expand Down
3 changes: 2 additions & 1 deletion moksha-wallet/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::collections::HashMap;

use async_trait::async_trait;
use moksha_core::{
model::{BlindedMessage, Keysets},
blind::BlindedMessage,
keyset::Keysets,
primitives::{
CheckFeesResponse, PaymentRequest, PostMeltResponse, PostMintResponse, PostSplitResponse,
},
Expand Down
3 changes: 2 additions & 1 deletion moksha-wallet/src/client/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::collections::HashMap;

use async_trait::async_trait;
use moksha_core::{
model::{BlindedMessage, Keysets},
blind::BlindedMessage,
keyset::Keysets,
primitives::{
CashuErrorResponse, CheckFeesRequest, CheckFeesResponse, PaymentRequest, PostMeltRequest,
PostMeltResponse, PostMintRequest, PostMintResponse, PostSplitRequest, PostSplitResponse,
Expand Down
6 changes: 4 additions & 2 deletions moksha-wallet/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use std::collections::HashMap;

use moksha_core::{
amount::{split_amount, Amount},
blind::{BlindedMessage, BlindedSignature, TotalAmount},
dhke::Dhke,
model::{BlindedMessage, BlindedSignature, Keysets, TotalAmount},
keyset::Keysets,
primitives::{PaymentRequest, PostMeltResponse},
proof::{Proof, Proofs},
token::TokenV3,
Expand Down Expand Up @@ -419,8 +420,9 @@ mod tests {
localstore::{LocalStore, WalletKeyset},
};
use async_trait::async_trait;
use moksha_core::blind::BlindedMessage;
use moksha_core::fixture::{read_fixture, read_fixture_as};
use moksha_core::model::{BlindedMessage, Keysets, MintKeyset};
use moksha_core::keyset::{Keysets, MintKeyset};
use moksha_core::primitives::{
CheckFeesResponse, PaymentRequest, PostMeltResponse, PostMintResponse, PostSplitResponse,
};
Expand Down
3 changes: 2 additions & 1 deletion moksha-wallet/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::collections::HashMap;

use async_trait::async_trait;
use moksha_core::blind::BlindedMessage;
use moksha_core::fixture::{read_fixture, read_fixture_as};
use moksha_core::model::{BlindedMessage, Keysets, MintKeyset};
use moksha_core::keyset::{Keysets, MintKeyset};
use moksha_core::primitives::{
CheckFeesResponse, PaymentRequest, PostMeltResponse, PostMintResponse, PostSplitResponse,
};
Expand Down

0 comments on commit 6bf6c52

Please sign in to comment.