Skip to content

Commit

Permalink
refactor: rename BlindedSignature to BlindSignature
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Mar 31, 2024
1 parent b77ea56 commit 57f4090
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 42 deletions.
12 changes: 6 additions & 6 deletions crates/cashu-sdk/src/mint/localstore/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::Arc;
use async_trait::async_trait;
use cashu::dhke::hash_to_curve;
use cashu::nuts::nut02::mint::KeySet;
use cashu::nuts::{BlindedSignature, CurrencyUnit, Id, MintInfo, Proof, Proofs, PublicKey};
use cashu::nuts::{BlindSignature, CurrencyUnit, Id, MintInfo, Proof, Proofs, PublicKey};
use cashu::secret::Secret;
use cashu::types::{MeltQuote, MintQuote};
use tokio::sync::Mutex;
Expand All @@ -20,7 +20,7 @@ pub struct MemoryLocalStore {
melt_quotes: Arc<Mutex<HashMap<String, MeltQuote>>>,
pending_proofs: Arc<Mutex<HashMap<Vec<u8>, Proof>>>,
spent_proofs: Arc<Mutex<HashMap<Vec<u8>, Proof>>>,
blinded_signatures: Arc<Mutex<HashMap<Box<[u8]>, BlindedSignature>>>,
blinded_signatures: Arc<Mutex<HashMap<Box<[u8]>, BlindSignature>>>,
}

impl MemoryLocalStore {
Expand All @@ -33,7 +33,7 @@ impl MemoryLocalStore {
melt_quotes: Vec<MeltQuote>,
pending_proofs: Proofs,
spent_proofs: Proofs,
blinded_signatures: HashMap<Box<[u8]>, BlindedSignature>,
blinded_signatures: HashMap<Box<[u8]>, BlindSignature>,
) -> Result<Self, Error> {
Ok(Self {
mint_info: Arc::new(Mutex::new(mint_info)),
Expand Down Expand Up @@ -226,7 +226,7 @@ impl LocalStore for MemoryLocalStore {
async fn add_blinded_signature(
&self,
blinded_message: PublicKey,
blinded_signature: BlindedSignature,
blinded_signature: BlindSignature,
) -> Result<(), Error> {
self.blinded_signatures
.lock()
Expand All @@ -238,7 +238,7 @@ impl LocalStore for MemoryLocalStore {
async fn get_blinded_signature(
&self,
blinded_message: &PublicKey,
) -> Result<Option<BlindedSignature>, Error> {
) -> Result<Option<BlindSignature>, Error> {
Ok(self
.blinded_signatures
.lock()
Expand All @@ -250,7 +250,7 @@ impl LocalStore for MemoryLocalStore {
async fn get_blinded_signatures(
&self,
blinded_messages: Vec<PublicKey>,
) -> Result<Vec<Option<BlindedSignature>>, Error> {
) -> Result<Vec<Option<BlindSignature>>, Error> {
let mut signatures = Vec::with_capacity(blinded_messages.len());

let blinded_signatures = self.blinded_signatures.lock().await;
Expand Down
8 changes: 4 additions & 4 deletions crates/cashu-sdk/src/mint/localstore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::collections::HashMap;

use async_trait::async_trait;
use cashu::nuts::nut02::mint::KeySet;
use cashu::nuts::{BlindedSignature, CurrencyUnit, Id, MintInfo, Proof, PublicKey};
use cashu::nuts::{BlindSignature, CurrencyUnit, Id, MintInfo, Proof, PublicKey};
use cashu::secret::Secret;
use cashu::types::{MeltQuote, MintQuote};
pub use memory::MemoryLocalStore;
Expand Down Expand Up @@ -82,14 +82,14 @@ pub trait LocalStore {
async fn add_blinded_signature(
&self,
blinded_message: PublicKey,
blinded_signature: BlindedSignature,
blinded_signature: BlindSignature,
) -> Result<(), Error>;
async fn get_blinded_signature(
&self,
blinded_message: &PublicKey,
) -> Result<Option<BlindedSignature>, Error>;
) -> Result<Option<BlindSignature>, Error>;
async fn get_blinded_signatures(
&self,
blinded_messages: Vec<PublicKey>,
) -> Result<Vec<Option<BlindedSignature>>, Error>;
) -> Result<Vec<Option<BlindSignature>>, Error>;
}
8 changes: 4 additions & 4 deletions crates/cashu-sdk/src/mint/localstore/redb_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::Arc;
use async_trait::async_trait;
use cashu::dhke::hash_to_curve;
use cashu::nuts::{
BlindedSignature, CurrencyUnit, Id, MintInfo, MintKeySet as KeySet, Proof, PublicKey,
BlindSignature, CurrencyUnit, Id, MintInfo, MintKeySet as KeySet, Proof, PublicKey,
};
use cashu::secret::Secret;
use cashu::types::{MeltQuote, MintQuote};
Expand Down Expand Up @@ -399,7 +399,7 @@ impl LocalStore for RedbLocalStore {
async fn add_blinded_signature(
&self,
blinded_message: PublicKey,
blinded_signature: BlindedSignature,
blinded_signature: BlindSignature,
) -> Result<(), Error> {
let db = self.db.lock().await;
let write_txn = db.begin_write()?;
Expand All @@ -420,7 +420,7 @@ impl LocalStore for RedbLocalStore {
async fn get_blinded_signature(
&self,
blinded_message: &PublicKey,
) -> Result<Option<BlindedSignature>, Error> {
) -> Result<Option<BlindSignature>, Error> {
let db = self.db.lock().await;
let read_txn = db.begin_read()?;
let table = read_txn.open_table(BLINDED_SIGNATURES)?;
Expand All @@ -435,7 +435,7 @@ impl LocalStore for RedbLocalStore {
async fn get_blinded_signatures(
&self,
blinded_messages: Vec<PublicKey>,
) -> Result<Vec<Option<BlindedSignature>>, Error> {
) -> Result<Vec<Option<BlindSignature>>, Error> {
let db = self.db.lock().await;
let read_txn = db.begin_read()?;
let table = read_txn.open_table(BLINDED_SIGNATURES)?;
Expand Down
11 changes: 4 additions & 7 deletions crates/cashu-sdk/src/mint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cashu::error::ErrorResponse;
#[cfg(feature = "nut07")]
use cashu::nuts::nut07::{ProofState, State};
use cashu::nuts::{
BlindedMessage, BlindedSignature, MeltBolt11Request, MeltBolt11Response, Proof, SwapRequest,
BlindSignature, BlindedMessage, MeltBolt11Request, MeltBolt11Response, Proof, SwapRequest,
SwapResponse, *,
};
#[cfg(feature = "nut07")]
Expand Down Expand Up @@ -325,10 +325,7 @@ impl Mint {
})
}

async fn blind_sign(
&self,
blinded_message: &BlindedMessage,
) -> Result<BlindedSignature, Error> {
async fn blind_sign(&self, blinded_message: &BlindedMessage) -> Result<BlindSignature, Error> {
let BlindedMessage {
amount,
b,
Expand Down Expand Up @@ -363,7 +360,7 @@ impl Mint {
let blinded_signature;
#[cfg(not(feature = "nut12"))]
{
blinded_signature = BlindedSignature {
blinded_signature = BlindSignature {
amount: *amount,
c: c.into(),
keyset_id: keyset.id,
Expand All @@ -372,7 +369,7 @@ impl Mint {

#[cfg(feature = "nut12")]
{
blinded_signature = BlindedSignature::new_dleq(
blinded_signature = BlindSignature::new_dleq(
*amount,
c.into(),
keyset.id,
Expand Down
4 changes: 2 additions & 2 deletions crates/cashu-sdk/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use cashu::nuts::nut11::SigningKey;
#[cfg(feature = "nut07")]
use cashu::nuts::PublicKey;
use cashu::nuts::{
BlindedSignature, CurrencyUnit, Id, KeySet, KeySetInfo, Keys, MintInfo, P2PKConditions,
BlindSignature, CurrencyUnit, Id, KeySet, KeySetInfo, Keys, MintInfo, P2PKConditions,
PreMintSecrets, PreSwap, Proof, Proofs, SigFlag, SwapRequest, Token,
};
use cashu::types::{MeltQuote, Melted, MintQuote};
Expand Down Expand Up @@ -532,7 +532,7 @@ impl<C: Client, L: LocalStore> Wallet<C, L> {
pub async fn process_swap_response(
&self,
blinded_messages: PreMintSecrets,
promises: Vec<BlindedSignature>,
promises: Vec<BlindSignature>,
) -> Result<Proofs, Error> {
let mut proofs = vec![];

Expand Down
4 changes: 2 additions & 2 deletions crates/cashu/src/dhke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ mod wallet {

use super::hash_to_curve;
use crate::error;
use crate::nuts::{BlindedSignature, Keys, Proof, Proofs, PublicKey, *};
use crate::nuts::{BlindSignature, Keys, Proof, Proofs, PublicKey, *};
use crate::secret::Secret;

/// Blind Message Alice Step one
Expand Down Expand Up @@ -100,7 +100,7 @@ mod wallet {

/// Construct Proof
pub fn construct_proofs(
promises: Vec<BlindedSignature>,
promises: Vec<BlindSignature>,
rs: Vec<nut01::SecretKey>,
secrets: Vec<Secret>,
keys: &Keys,
Expand Down
2 changes: 1 addition & 1 deletion crates/cashu/src/nuts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub mod nut13;

#[cfg(feature = "wallet")]
pub use nut00::wallet::{PreMint, PreMintSecrets, Token};
pub use nut00::{BlindedMessage, BlindedSignature, CurrencyUnit, PaymentMethod, Proof};
pub use nut00::{BlindSignature, BlindedMessage, CurrencyUnit, PaymentMethod, Proof};
pub use nut01::{Keys, KeysResponse, PublicKey, SecretKey};
pub use nut02::mint::KeySet as MintKeySet;
pub use nut02::{Id, KeySet, KeySetInfo, KeysetResponse};
Expand Down
4 changes: 2 additions & 2 deletions crates/cashu/src/nuts/nut00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ impl MintProofs {
}
}

/// Promise (BlindedSignature) [NUT-00]
/// Promise (BlindSignature) [NUT-00]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BlindedSignature {
pub struct BlindSignature {
pub amount: Amount,
/// Keyset Id
#[serde(rename = "id")]
Expand Down
8 changes: 4 additions & 4 deletions crates/cashu/src/nuts/nut03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use serde::{Deserialize, Serialize};

use super::nut00::BlindedSignature;
use super::nut00::BlindSignature;
#[cfg(feature = "wallet")]
use crate::nuts::PreMintSecrets;
use crate::nuts::{BlindedMessage, Proofs};
Expand Down Expand Up @@ -46,11 +46,11 @@ impl SwapRequest {
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SwapResponse {
/// Promises
pub signatures: Vec<BlindedSignature>,
pub signatures: Vec<BlindSignature>,
}

impl SwapResponse {
pub fn new(promises: Vec<BlindedSignature>) -> SwapResponse {
pub fn new(promises: Vec<BlindSignature>) -> SwapResponse {
SwapResponse {
signatures: promises,
}
Expand All @@ -59,7 +59,7 @@ impl SwapResponse {
pub fn promises_amount(&self) -> Amount {
self.signatures
.iter()
.map(|BlindedSignature { amount, .. }| *amount)
.map(|BlindSignature { amount, .. }| *amount)
.sum()
}
}
4 changes: 2 additions & 2 deletions crates/cashu/src/nuts/nut04.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// https://github.com/cashubtc/nuts/blob/main/04.md
use serde::{Deserialize, Serialize};

use super::{BlindedMessage, BlindedSignature, CurrencyUnit, PaymentMethod};
use super::{BlindSignature, BlindedMessage, CurrencyUnit, PaymentMethod};
use crate::types::MintQuote;
use crate::Amount;

Expand Down Expand Up @@ -61,7 +61,7 @@ impl MintBolt11Request {
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct MintBolt11Response {
/// Blinded Signatures
pub signatures: Vec<BlindedSignature>,
pub signatures: Vec<BlindSignature>,
}

/// Mint Method Settings
Expand Down
4 changes: 2 additions & 2 deletions crates/cashu/src/nuts/nut08.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use serde::{Deserialize, Serialize};

use super::{BlindedMessage, BlindedSignature, Proofs};
use super::{BlindSignature, BlindedMessage, Proofs};
use crate::Amount;

/// Melt Bolt11 Request [NUT-08]
Expand Down Expand Up @@ -36,7 +36,7 @@ impl MeltBolt11Request {
pub struct MeltBolt11Response {
pub paid: bool,
pub payment_preimage: Option<String>,
pub change: Option<Vec<BlindedSignature>>,
pub change: Option<Vec<BlindSignature>>,
}

impl MeltBolt11Response {
Expand Down
4 changes: 2 additions & 2 deletions crates/cashu/src/nuts/nut09.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use serde::{Deserialize, Serialize};

use super::{BlindedMessage, BlindedSignature};
use super::{BlindSignature, BlindedMessage};

/// Restore Request [NUT-09]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
Expand All @@ -19,7 +19,7 @@ pub struct RestoreResponse {
/// Signatures
// TODO: remove rename just for temp compatanlite with nutshell
#[serde(rename = "promises")]
pub signatures: Vec<BlindedSignature>,
pub signatures: Vec<BlindSignature>,
}

mod test {
Expand Down
8 changes: 4 additions & 4 deletions crates/cashu/src/nuts/nut12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use log::{debug, warn};
use serde::{Deserialize, Serialize};
use thiserror::Error;

use super::{BlindedSignature, Id, Proof, PublicKey, SecretKey};
use super::{BlindSignature, Id, Proof, PublicKey, SecretKey};
use crate::dhke::{hash_e, hash_to_curve};
use crate::Amount;

Expand Down Expand Up @@ -132,7 +132,7 @@ impl Proof {
}
}

impl BlindedSignature {
impl BlindSignature {
pub fn new_dleq(
amount: Amount,
blinded_signature: PublicKey,
Expand All @@ -149,7 +149,7 @@ impl BlindedSignature {
&mint_secretkey,
)?;

Ok(BlindedSignature {
Ok(BlindSignature {
amount,
keyset_id,
c: blinded_signature,
Expand Down Expand Up @@ -209,7 +209,7 @@ mod tests {
fn test_blind_signature_dleq() {
let blinded_sig = r#"{"amount":8,"id":"00882760bfa2eb41","C_":"02a9acc1e48c25eeeb9289b5031cc57da9fe72f3fe2861d264bdc074209b107ba2","dleq":{"e":"9818e061ee51d5c8edc3342369a554998ff7b4381c8652d724cdf46429be73d9","s":"9818e061ee51d5c8edc3342369a554998ff7b4381c8652d724cdf46429be73da"}}"#;

let blinded: BlindedSignature = serde_json::from_str(blinded_sig).unwrap();
let blinded: BlindSignature = serde_json::from_str(blinded_sig).unwrap();

let secret_key =
SecretKey::from_hex("0000000000000000000000000000000000000000000000000000000000000001")
Expand Down

0 comments on commit 57f4090

Please sign in to comment.