mirror of
https://github.com/aljazceru/cdk.git
synced 2026-01-07 15:05:34 +01:00
refactor: rename BlindedSignature to BlindSignature
This commit is contained in:
@@ -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;
|
||||
@@ -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 {
|
||||
@@ -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)),
|
||||
@@ -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()
|
||||
@@ -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()
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
@@ -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};
|
||||
@@ -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()?;
|
||||
@@ -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)?;
|
||||
@@ -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)?;
|
||||
|
||||
@@ -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")]
|
||||
@@ -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,
|
||||
@@ -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,
|
||||
@@ -372,7 +369,7 @@ impl Mint {
|
||||
|
||||
#[cfg(feature = "nut12")]
|
||||
{
|
||||
blinded_signature = BlindedSignature::new_dleq(
|
||||
blinded_signature = BlindSignature::new_dleq(
|
||||
*amount,
|
||||
c.into(),
|
||||
keyset.id,
|
||||
|
||||
@@ -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};
|
||||
@@ -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![];
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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,
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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")]
|
||||
|
||||
@@ -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};
|
||||
@@ -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,
|
||||
}
|
||||
@@ -59,7 +59,7 @@ impl SwapResponse {
|
||||
pub fn promises_amount(&self) -> Amount {
|
||||
self.signatures
|
||||
.iter()
|
||||
.map(|BlindedSignature { amount, .. }| *amount)
|
||||
.map(|BlindSignature { amount, .. }| *amount)
|
||||
.sum()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)]
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -132,7 +132,7 @@ impl Proof {
|
||||
}
|
||||
}
|
||||
|
||||
impl BlindedSignature {
|
||||
impl BlindSignature {
|
||||
pub fn new_dleq(
|
||||
amount: Amount,
|
||||
blinded_signature: PublicKey,
|
||||
@@ -149,7 +149,7 @@ impl BlindedSignature {
|
||||
&mint_secretkey,
|
||||
)?;
|
||||
|
||||
Ok(BlindedSignature {
|
||||
Ok(BlindSignature {
|
||||
amount,
|
||||
keyset_id,
|
||||
c: blinded_signature,
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user