Skip to content

implement keyset info and minting#529

Merged
zupzup merged 2 commits intomasterfrom
517-keyset-info
May 29, 2025
Merged

implement keyset info and minting#529
zupzup merged 2 commits intomasterfrom
517-keyset-info

Conversation

@zupzup
Copy link
Collaborator

@zupzup zupzup commented May 28, 2025

📝 Description

  • Implement checking for keyset info for accepted offers without proofs
  • if keyset info is available, mint and create proofs

Relates to #517


✅ Checklist

Please ensure the following tasks are completed before requesting a review:

  • My code adheres to the coding guidelines of this project.
  • I have run cargo fmt.
  • I have run cargo clippy.
  • I have added or updated tests (if applicable).
  • All CI/CD steps were successful.
  • I have updated the documentation (if applicable).
  • I have checked that there are no console errors or warnings.
  • I have verified that the application builds without errors.
  • I've described the changes made to the API. (modification, addition, deletion).

🚀 Changes Made

See above.


💡 How to Test

Please provide clear instructions on how reviewers can test your changes:

  1. cargo test
  2. create bill, accept, req to mint, get offer, activate keyset, accept, check again -> you should have tokens (can check if valid with Wallet-Core)

🤝 Related Issues

List any related issues, pull requests, or discussions:


📋 Review Guidelines

Please focus on the following while reviewing:

  • Does the code follow the repository's contribution guidelines?
  • Are there any potential bugs or performance issues?
  • Are there any typos or grammatical errors in the code or comments?

@zupzup zupzup self-assigned this May 28, 2025
async fn get_keyset_info(&self, mint_url: &str, keyset_id: &str) -> Result<cdk02::KeySet> {
let base = reqwest::Url::parse(mint_url).map_err(|_| Error::InvalidMintUrl)?;
let url = base
.join(&format!("/v1/keys/{}", keyset_id))

Check warning

Code scanning / clippy

variables can be used directly in the format! string Warning library

variables can be used directly in the format! string
Comment on lines +300 to +375
if let Ok(Some(offer)) = self
.mint_store
.get_offer(&mint_request.mint_request_id)
.await
{
if offer.proofs.is_none() {
debug!(
"Checking for keyset info for {}",
&mint_request.mint_request_id
);
// not finished - check keyset and try to mint and create tokens and persist
match self
.mint_client
.get_keyset_info(&mint_cfg.default_mint_url, &offer.keyset_id)
.await
{
// keyset info is available
Ok(keyset_info) => {
// fetch private key for requester
let private_key = match self.identity_store.get_full().await {
Ok(identity) => {
// check if requester is identity
if identity.identity.node_id
== mint_request.requester_node_id
{
identity.key_pair.get_private_key_string()
} else {
// check if requester is a company
let local_companies: HashMap<
String,
(Company, CompanyKeys),
> = self.company_store.get_all().await?;
if let Some(requester_company) =
local_companies.get(&mint_request.requester_node_id)
{
requester_company.1.private_key.clone()
} else {
// requester is neither identity, nor company
log::warn!(
"Requester for {} is not a local identity, or company",
&mint_request.mint_request_id
);
return Ok(());
}
}
}
Err(e) => {
return Err(e.into());
}
};
debug!(
"Keyset found and minting for {}",
&mint_request.mint_request_id
);
// mint and generate proofs
let proofs = self
.mint_client
.mint(
&mint_cfg.default_mint_url,
keyset_info,
offer.discounted_sum,
&mint_request.mint_request_id,
&private_key,
)
.await?;
// store proofs on the offer
self.mint_store
.add_proofs_to_offer(&mint_request.mint_request_id, &proofs)
.await?;
}
Err(_) => {
info!("No keyset available for {}", mint_request.mint_request_id);
}
};
}
}

Check warning

Code scanning / clippy

this if statement can be collapsed Warning

this if statement can be collapsed
@zupzup zupzup force-pushed the 517-keyset-info branch from 111c6dd to e0afb83 Compare May 28, 2025 14:39
@codecov
Copy link

codecov bot commented May 28, 2025

Codecov Report

Attention: Patch coverage is 0% with 187 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../bcr-ebill-api/src/service/bill_service/service.rs 0.00% 90 Missing ⚠️
crates/bcr-ebill-api/src/external/mint.rs 0.00% 80 Missing ⚠️
crates/bcr-ebill-persistence/src/db/mint.rs 0.00% 17 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link

@stefanbitcr stefanbitcr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

@zupzup zupzup merged commit 548b23a into master May 29, 2025
6 of 7 checks passed
@zupzup zupzup deleted the 517-keyset-info branch May 29, 2025 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants