mirror of
https://github.com/aljazceru/cdk.git
synced 2026-02-03 04:06:18 +01:00
feat(mint): store mint_quote_id for blind sig
This commit is contained in:
@@ -49,8 +49,12 @@ async fn main() -> anyhow::Result<()> {
|
||||
let default_filter = "debug";
|
||||
|
||||
let sqlx_filter = "sqlx=warn";
|
||||
let hyper_filter = "hyper=warn";
|
||||
|
||||
let env_filter = EnvFilter::new(format!("{},{}", default_filter, sqlx_filter));
|
||||
let env_filter = EnvFilter::new(format!(
|
||||
"{},{},{}",
|
||||
default_filter, sqlx_filter, hyper_filter
|
||||
));
|
||||
|
||||
tracing_subscriber::fmt().with_env_filter(env_filter).init();
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ use lightning_invoice::Bolt11Invoice;
|
||||
use redb::{Database, MultimapTableDefinition, ReadableTable, TableDefinition};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{Error, PROOFS_STATE_TABLE, PROOFS_TABLE};
|
||||
use super::{Error, PROOFS_STATE_TABLE, PROOFS_TABLE, QUOTE_SIGNATURES_TABLE};
|
||||
|
||||
const MINT_QUOTES_TABLE: TableDefinition<&str, &str> = TableDefinition::new("mint_quotes");
|
||||
const PENDING_PROOFS_TABLE: TableDefinition<[u8; 33], &str> =
|
||||
@@ -32,6 +32,7 @@ pub fn migrate_02_to_03(db: Arc<Database>) -> Result<u32, Error> {
|
||||
pub fn migrate_03_to_04(db: Arc<Database>) -> Result<u32, Error> {
|
||||
let write_txn = db.begin_write()?;
|
||||
let _ = write_txn.open_multimap_table(QUOTE_PROOFS_TABLE)?;
|
||||
let _ = write_txn.open_multimap_table(QUOTE_SIGNATURES_TABLE)?;
|
||||
Ok(4)
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@ const BLINDED_SIGNATURES: TableDefinition<[u8; 33], &str> =
|
||||
TableDefinition::new("blinded_signatures");
|
||||
const QUOTE_PROOFS_TABLE: MultimapTableDefinition<&str, [u8; 33]> =
|
||||
MultimapTableDefinition::new("quote_proofs");
|
||||
const QUOTE_SIGNATURES_TABLE: MultimapTableDefinition<&str, &str> =
|
||||
MultimapTableDefinition::new("quote_signatures");
|
||||
|
||||
const DATABASE_VERSION: u32 = 4;
|
||||
|
||||
@@ -132,6 +134,7 @@ impl MintRedbDatabase {
|
||||
let _ = write_txn.open_table(PROOFS_STATE_TABLE)?;
|
||||
let _ = write_txn.open_table(BLINDED_SIGNATURES)?;
|
||||
let _ = write_txn.open_multimap_table(QUOTE_PROOFS_TABLE)?;
|
||||
let _ = write_txn.open_multimap_table(QUOTE_SIGNATURES_TABLE)?;
|
||||
|
||||
table.insert("db_version", DATABASE_VERSION.to_string().as_str())?;
|
||||
}
|
||||
@@ -636,6 +639,7 @@ impl MintDatabase for MintRedbDatabase {
|
||||
&self,
|
||||
blinded_messages: &[PublicKey],
|
||||
blind_signatures: &[BlindSignature],
|
||||
quote_id: Option<String>,
|
||||
) -> Result<(), Self::Err> {
|
||||
let write_txn = self.db.begin_write().map_err(Error::from)?;
|
||||
|
||||
@@ -643,17 +647,22 @@ impl MintDatabase for MintRedbDatabase {
|
||||
let mut table = write_txn
|
||||
.open_table(BLINDED_SIGNATURES)
|
||||
.map_err(Error::from)?;
|
||||
let mut quote_sigs_table = write_txn
|
||||
.open_multimap_table(QUOTE_SIGNATURES_TABLE)
|
||||
.map_err(Error::from)?;
|
||||
|
||||
for (blinded_message, blind_signature) in blinded_messages.iter().zip(blind_signatures)
|
||||
{
|
||||
let blind_sig = serde_json::to_string(&blind_signature).map_err(Error::from)?;
|
||||
table
|
||||
.insert(
|
||||
blinded_message.to_bytes(),
|
||||
serde_json::to_string(&blind_signature)
|
||||
.map_err(Error::from)?
|
||||
.as_str(),
|
||||
)
|
||||
.insert(blinded_message.to_bytes(), blind_sig.as_str())
|
||||
.map_err(Error::from)?;
|
||||
|
||||
if let Some(quote_id) = "e_id {
|
||||
quote_sigs_table
|
||||
.insert(quote_id.as_str(), blind_sig.as_str())
|
||||
.map_err(Error::from)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
ALTER TABLE proof ADD COLUMN quote_id TEXT;
|
||||
ALTER TABLE blind_signature ADD COLUMN quote_id TEXT;
|
||||
|
||||
@@ -971,20 +971,22 @@ WHERE y=?;
|
||||
&self,
|
||||
blinded_messages: &[PublicKey],
|
||||
blinded_signatures: &[BlindSignature],
|
||||
quote_id: Option<String>,
|
||||
) -> Result<(), Self::Err> {
|
||||
let mut transaction = self.pool.begin().await.map_err(Error::from)?;
|
||||
for (message, signature) in blinded_messages.iter().zip(blinded_signatures) {
|
||||
let res = sqlx::query(
|
||||
r#"
|
||||
INSERT INTO blind_signature
|
||||
(y, amount, keyset_id, c)
|
||||
VALUES (?, ?, ?, ?);
|
||||
(y, amount, keyset_id, c, quote_id)
|
||||
VALUES (?, ?, ?, ?, ?);
|
||||
"#,
|
||||
)
|
||||
.bind(message.to_bytes().to_vec())
|
||||
.bind(u64::from(signature.amount) as i64)
|
||||
.bind(signature.keyset_id.to_string())
|
||||
.bind(signature.c.to_bytes().to_vec())
|
||||
.bind(quote_id.clone())
|
||||
.execute(&mut transaction)
|
||||
.await;
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ pub struct MintMemoryDatabase {
|
||||
proof_state: Arc<Mutex<HashMap<[u8; 33], nut07::State>>>,
|
||||
quote_proofs: Arc<Mutex<HashMap<String, Vec<PublicKey>>>>,
|
||||
blinded_signatures: Arc<RwLock<HashMap<[u8; 33], BlindSignature>>>,
|
||||
quote_signatures: Arc<RwLock<HashMap<String, Vec<BlindSignature>>>>,
|
||||
}
|
||||
|
||||
impl MintMemoryDatabase {
|
||||
@@ -40,6 +41,7 @@ impl MintMemoryDatabase {
|
||||
spent_proofs: Proofs,
|
||||
quote_proofs: HashMap<String, Vec<PublicKey>>,
|
||||
blinded_signatures: HashMap<[u8; 33], BlindSignature>,
|
||||
quote_signatures: HashMap<String, Vec<BlindSignature>>,
|
||||
) -> Result<Self, Error> {
|
||||
let mut proofs = HashMap::new();
|
||||
let mut proof_states = HashMap::new();
|
||||
@@ -71,6 +73,7 @@ impl MintMemoryDatabase {
|
||||
proof_state: Arc::new(Mutex::new(proof_states)),
|
||||
blinded_signatures: Arc::new(RwLock::new(blinded_signatures)),
|
||||
quote_proofs: Arc::new(Mutex::new(quote_proofs)),
|
||||
quote_signatures: Arc::new(RwLock::new(quote_signatures)),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -320,6 +323,7 @@ impl MintDatabase for MintMemoryDatabase {
|
||||
&self,
|
||||
blinded_message: &[PublicKey],
|
||||
blind_signatures: &[BlindSignature],
|
||||
quote_id: Option<String>,
|
||||
) -> Result<(), Self::Err> {
|
||||
let mut current_blinded_signatures = self.blinded_signatures.write().await;
|
||||
|
||||
@@ -327,6 +331,11 @@ impl MintDatabase for MintMemoryDatabase {
|
||||
current_blinded_signatures.insert(blinded_message.to_bytes(), blind_signature.clone());
|
||||
}
|
||||
|
||||
if let Some(quote_id) = quote_id {
|
||||
let mut current_quote_signatures = self.quote_signatures.write().await;
|
||||
current_quote_signatures.insert(quote_id, blind_signatures.to_vec());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -250,6 +250,7 @@ pub trait MintDatabase {
|
||||
&self,
|
||||
blinded_messages: &[PublicKey],
|
||||
blind_signatures: &[BlindSignature],
|
||||
quote_id: Option<String>,
|
||||
) -> Result<(), Self::Err>;
|
||||
/// Get [`BlindSignature`]s
|
||||
async fn get_blind_signatures(
|
||||
|
||||
@@ -662,6 +662,7 @@ impl Mint {
|
||||
.map(|p| p.blinded_secret)
|
||||
.collect::<Vec<PublicKey>>(),
|
||||
&blind_signatures,
|
||||
Some(mint_request.quote.clone()),
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -895,6 +896,7 @@ impl Mint {
|
||||
.map(|o| o.blinded_secret)
|
||||
.collect::<Vec<PublicKey>>(),
|
||||
&promises,
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -1227,6 +1229,7 @@ impl Mint {
|
||||
.map(|o| o.blinded_secret)
|
||||
.collect::<Vec<PublicKey>>(),
|
||||
&change_sigs,
|
||||
Some(quote.id.clone()),
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -1553,6 +1556,7 @@ mod tests {
|
||||
spent_proofs: Proofs,
|
||||
blinded_signatures: HashMap<[u8; 33], BlindSignature>,
|
||||
quote_proofs: HashMap<String, Vec<PublicKey>>,
|
||||
quote_signatures: HashMap<String, Vec<BlindSignature>>,
|
||||
mint_url: &'a str,
|
||||
seed: &'a [u8],
|
||||
mint_info: MintInfo,
|
||||
@@ -1570,6 +1574,7 @@ mod tests {
|
||||
config.spent_proofs,
|
||||
config.quote_proofs,
|
||||
config.blinded_signatures,
|
||||
config.quote_signatures,
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user