mirror of
https://github.com/aljazceru/cdk.git
synced 2026-01-08 15:35:35 +01:00
feat(mint): add get blinded_sig by keyset
This commit is contained in:
@@ -41,6 +41,7 @@
|
||||
- cdk-cli(receive): Add support for signing keys to be nostr nsec encoded ([thesimplekid]).
|
||||
- cdk-fake-wallet: Add Fake wallet for testing ([thesimplekid]).
|
||||
- cdk(cdk-database/mint): Add `add_proofs`, `get_proofs_by_ys`, `get_proofs_states`, and `update_proofs_states` ([thesimplekid]).
|
||||
- cdk(cdk-database/mint): Add `get_blinded_signatures_for_keyset` to get all blind signatures for a `keyset_id` ([thesimplekid]).
|
||||
|
||||
### Fixed
|
||||
- cdk(mint): `SIG_ALL` is not allowed in `melt` ([thesimplekid]).
|
||||
|
||||
@@ -670,4 +670,27 @@ impl MintDatabase for MintRedbDatabase {
|
||||
|
||||
Ok(signatures)
|
||||
}
|
||||
|
||||
async fn get_blinded_signatures_for_keyset(
|
||||
&self,
|
||||
keyset_id: &Id,
|
||||
) -> Result<Vec<BlindSignature>, Self::Err> {
|
||||
let db = self.db.lock().await;
|
||||
let read_txn = db.begin_read().map_err(Error::from)?;
|
||||
let table = read_txn
|
||||
.open_table(BLINDED_SIGNATURES)
|
||||
.map_err(Error::from)?;
|
||||
|
||||
Ok(table
|
||||
.iter()
|
||||
.map_err(Error::from)?
|
||||
.flatten()
|
||||
.filter_map(|(_m, s)| {
|
||||
match serde_json::from_str::<BlindSignature>(s.value()).ok() {
|
||||
Some(signature) if &signature.keyset_id == keyset_id => Some(signature), // Filter by keyset_id
|
||||
_ => None, // Exclude non-matching entries
|
||||
}
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -685,6 +685,30 @@ WHERE y=?;
|
||||
|
||||
Ok(signatures)
|
||||
}
|
||||
|
||||
async fn get_blinded_signatures_for_keyset(
|
||||
&self,
|
||||
keyset_id: &Id,
|
||||
) -> Result<Vec<BlindSignature>, Self::Err> {
|
||||
let rec = sqlx::query(
|
||||
r#"
|
||||
SELECT *
|
||||
FROM blind_signature
|
||||
WHERE keyset_id=?;
|
||||
"#,
|
||||
)
|
||||
.bind(keyset_id.to_string())
|
||||
.fetch_all(&self.pool)
|
||||
.await;
|
||||
|
||||
let signatures = rec
|
||||
.map_err(Error::from)?
|
||||
.into_iter()
|
||||
.flat_map(sqlite_row_to_blind_signature)
|
||||
.collect();
|
||||
|
||||
Ok(signatures)
|
||||
}
|
||||
}
|
||||
|
||||
fn sqlite_row_to_keyset_info(row: SqliteRow) -> Result<MintKeySetInfo, Error> {
|
||||
|
||||
@@ -303,4 +303,17 @@ impl MintDatabase for MintMemoryDatabase {
|
||||
|
||||
Ok(signatures)
|
||||
}
|
||||
|
||||
async fn get_blinded_signatures_for_keyset(
|
||||
&self,
|
||||
keyset_id: &Id,
|
||||
) -> Result<Vec<BlindSignature>, Self::Err> {
|
||||
let blinded_signatures = self.blinded_signatures.read().await;
|
||||
|
||||
Ok(blinded_signatures
|
||||
.values()
|
||||
.filter(|b| &b.keyset_id == keyset_id)
|
||||
.cloned()
|
||||
.collect())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,4 +237,9 @@ pub trait MintDatabase {
|
||||
&self,
|
||||
blinded_messages: &[PublicKey],
|
||||
) -> Result<Vec<Option<BlindSignature>>, Self::Err>;
|
||||
/// Get [`BlindSignature`]s for keyset_id
|
||||
async fn get_blinded_signatures_for_keyset(
|
||||
&self,
|
||||
keyset_id: &Id,
|
||||
) -> Result<Vec<BlindSignature>, Self::Err>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user