Skip to content

Commit ff135d8

Browse files
authored
up wildcat and wallet core,move sharing logic to core (#572)
1 parent 69db03b commit ff135d8

File tree

10 files changed

+259
-190
lines changed

10 files changed

+259
-190
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 0.4.1
2+
3+
* Add file and pub key to bill to share with external party and add accessors to extract data
4+
* Upgrade wildcat and wallet-core dependencies
5+
16
# 0.4.0
27

38
* Switch to new chain transport leveraging public Nostr threads

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace.package]
2-
version = "0.4.0"
2+
version = "0.4.1"
33
edition = "2024"
44
license = "MIT"
55

@@ -60,4 +60,4 @@ bcr-ebill-core = { path = "./crates/bcr-ebill-core" }
6060
bcr-ebill-persistence = { path = "./crates/bcr-ebill-persistence" }
6161
bcr-ebill-transport = { path = "./crates/bcr-ebill-transport" }
6262
surrealdb = { version = "2.3", default-features = false }
63-
url = {version = "2.5"}
63+
url = { version = "2.5" }

crates/bcr-ebill-api/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ bcr-ebill-transport.workspace = true
3131
tokio.workspace = true
3232
tokio_with_wasm.workspace = true
3333
secp256k1.workspace = true
34-
bcr-wdc-webapi = { git = "https://github.com/BitcreditProtocol/wildcat", tag = "v0.2.0" }
35-
bcr-wdc-quote-client = { git = "https://github.com/BitcreditProtocol/wildcat", tag = "v0.2.0" }
36-
bcr-wdc-key-client = { git = "https://github.com/BitcreditProtocol/wildcat", tag = "v0.2.0" }
37-
bcr-wdc-swap-client = { git = "https://github.com/BitcreditProtocol/wildcat", tag = "v0.2.0" }
38-
bcr-wallet-lib = { git = "https://github.com/BitcreditProtocol/Wallet-Core", rev = "0a974e79d25fd7018a8165d8575cd06a8da9be59"}
39-
cashu = { version = "0.9", default-features = false }
34+
bcr-wdc-webapi = { git = "https://github.com/BitcreditProtocol/wildcat", rev = "15b9a36d7663a592ccc0287d87f8d72746fc2d99" }
35+
bcr-wdc-quote-client = { git = "https://github.com/BitcreditProtocol/wildcat", rev = "15b9a36d7663a592ccc0287d87f8d72746fc2d99" }
36+
bcr-wdc-key-client = { git = "https://github.com/BitcreditProtocol/wildcat", rev = "15b9a36d7663a592ccc0287d87f8d72746fc2d99" }
37+
bcr-wdc-swap-client = { git = "https://github.com/BitcreditProtocol/wildcat", rev = "15b9a36d7663a592ccc0287d87f8d72746fc2d99" }
38+
bcr-wallet-lib = { git = "https://github.com/BitcreditProtocol/Wallet-Core", rev = "f5a1ed4f52f5852bab27ec67996c2f2c8d16c6dd" }
39+
cashu = { version = "0.11", default-features = false }
4040
rand = { version = "0.8" }
4141
hex = { version = "0.4" }
4242
url.workspace = true

crates/bcr-ebill-api/src/external/mint.rs

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ use std::str::FromStr;
33
use crate::util;
44
use async_trait::async_trait;
55
use bcr_ebill_core::{
6-
PostalAddress, SecretKey, ServiceTraitBounds,
7-
bill::BitcreditBill,
6+
NodeId, PostalAddress, SecretKey, ServiceTraitBounds,
7+
bill::{BillId, BitcreditBill},
88
contact::{BillAnonParticipant, BillIdentParticipant, BillParticipant, ContactType},
99
util::{BcrKeys, date::DateTimeUtc},
1010
};
11-
use bcr_wallet_lib::wallet::TokenOperations;
1211
use bcr_wdc_key_client::KeyClient;
1312
use bcr_wdc_quote_client::QuoteClient;
1413
use bcr_wdc_swap_client::SwapClient;
@@ -81,7 +80,12 @@ use mockall::automock;
8180
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
8281
pub trait MintClientApi: ServiceTraitBounds {
8382
/// Check if the given proofs were already spent
84-
async fn check_if_proofs_are_spent(&self, mint_url: &str, proofs: &str) -> Result<bool>;
83+
async fn check_if_proofs_are_spent(
84+
&self,
85+
mint_url: &str,
86+
proofs: &str,
87+
keyset_id: &str,
88+
) -> Result<bool>;
8589
/// Mint and return encoded token
8690
async fn mint(
8791
&self,
@@ -159,7 +163,12 @@ impl MintClient {
159163
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
160164
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
161165
impl MintClientApi for MintClient {
162-
async fn check_if_proofs_are_spent(&self, mint_url: &str, proofs: &str) -> Result<bool> {
166+
async fn check_if_proofs_are_spent(
167+
&self,
168+
mint_url: &str,
169+
proofs: &str,
170+
keyset_id: &str,
171+
) -> Result<bool> {
163172
let token_mint_url =
164173
cashu::MintUrl::from_str(mint_url).map_err(|_| Error::InvalidMintUrl)?;
165174
let token =
@@ -169,7 +178,25 @@ impl MintClientApi for MintClient {
169178
return Err(Error::InvalidToken.into());
170179
}
171180

172-
let ys = token.proofs().ys().map_err(|_| Error::PubKey)?;
181+
let keyset_id_parsed = cdk02::Id::from_str(keyset_id).map_err(|e| {
182+
log::error!("Error parsing keyset id {keyset_id} for {mint_url}: {e}");
183+
Error::InvalidKeySetId
184+
})?;
185+
186+
let keyset_info = self
187+
.key_client(mint_url)?
188+
.keyset_info(keyset_id_parsed)
189+
.await
190+
.map_err(|e| {
191+
log::error!("Error getting keyset info from {mint_url}: {e}");
192+
Error::KeyClient
193+
})?;
194+
195+
let ys = token
196+
.proofs(&[keyset_info])
197+
.map_err(|_| Error::InvalidToken)?
198+
.ys()
199+
.map_err(|_| Error::PubKey)?;
173200

174201
let proof_states = self
175202
.swap_client(mint_url)?
@@ -230,7 +257,7 @@ impl MintClientApi for MintClient {
230257

231258
// generate token from proofs
232259
let token =
233-
bcr_wallet_lib::wallet::Token::new_credit(token_mint_url, currency, None, proofs);
260+
bcr_wallet_lib::wallet::Token::new_bitcr(token_mint_url, proofs, None, currency);
234261

235262
Ok(token.to_string())
236263
}
@@ -263,7 +290,7 @@ impl MintClientApi for MintClient {
263290
files: &[Url],
264291
) -> Result<String> {
265292
let bill_info = BillInfo {
266-
id: bill.id.clone().to_string(),
293+
id: map_bill_id(bill.id.clone()),
267294
drawee: map_bill_ident_participant(bill.drawee.to_owned()),
268295
drawer: map_bill_ident_participant(bill.drawer.to_owned()),
269296
payee: map_bill_participant(bill.payee.to_owned()),
@@ -454,7 +481,7 @@ fn map_bill_anon_participant(
454481
ident: BillAnonParticipant,
455482
) -> bcr_wdc_webapi::bill::BillAnonParticipant {
456483
bcr_wdc_webapi::bill::BillAnonParticipant {
457-
node_id: ident.node_id.to_string(),
484+
node_id: map_node_id(ident.node_id),
458485
email: ident.email,
459486
nostr_relays: ident.nostr_relays,
460487
}
@@ -465,7 +492,7 @@ fn map_bill_ident_participant(
465492
) -> bcr_wdc_webapi::bill::BillIdentParticipant {
466493
bcr_wdc_webapi::bill::BillIdentParticipant {
467494
t: map_contact_type(ident.t),
468-
node_id: ident.node_id.to_string(),
495+
node_id: map_node_id(ident.node_id),
469496
name: ident.name,
470497
postal_address: map_postal_address(ident.postal_address),
471498
email: ident.email,
@@ -489,3 +516,11 @@ fn map_postal_address(pa: PostalAddress) -> bcr_wdc_webapi::identity::PostalAddr
489516
address: pa.address,
490517
}
491518
}
519+
520+
fn map_bill_id(bill_id: BillId) -> bcr_wdc_webapi::bill::BillId {
521+
bcr_wdc_webapi::bill::BillId::from_str(&bill_id.to_string()).expect("is a bill id")
522+
}
523+
524+
fn map_node_id(node_id: NodeId) -> bcr_wdc_webapi::bill::NodeId {
525+
bcr_wdc_webapi::bill::NodeId::from_str(&node_id.to_string()).expect("is a node id")
526+
}

crates/bcr-ebill-api/src/service/bill_service/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ mod issue;
2929
mod payment;
3030
mod propagation;
3131
mod service;
32-
mod sharing;
3332
#[cfg(test)]
3433
pub mod test_utils;
3534

@@ -6364,6 +6363,7 @@ pub mod tests {
63646363
id: cdk02::Id::try_from("00c7b45973e5f0fc".to_owned()).unwrap(),
63656364
unit: cashu::CurrencyUnit::Sat,
63666365
keys: cashu::Keys::new(std::collections::BTreeMap::default()),
6366+
final_expiry: None,
63676367
})
63686368
});
63696369
ctx.mint_client
@@ -6421,11 +6421,12 @@ pub mod tests {
64216421
id: cdk02::Id::try_from("00c7b45973e5f0fc".to_owned()).unwrap(),
64226422
unit: cashu::CurrencyUnit::Sat,
64236423
keys: cashu::Keys::new(std::collections::BTreeMap::default()),
6424+
final_expiry: None,
64246425
})
64256426
});
64266427
ctx.mint_client
64276428
.expect_check_if_proofs_are_spent()
6428-
.returning(|_, _| Ok(true));
6429+
.returning(|_, _, _| Ok(true));
64296430
ctx.mint_store
64306431
.expect_set_proofs_to_spent_for_offer()
64316432
.returning(|_| Ok(()));

crates/bcr-ebill-api/src/service/bill_service/service.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,11 @@ impl BillService {
409409
if let Some(proofs) = offer.proofs {
410410
match self
411411
.mint_client
412-
.check_if_proofs_are_spent(&mint_cfg.default_mint_url, &proofs)
412+
.check_if_proofs_are_spent(
413+
&mint_cfg.default_mint_url,
414+
&proofs,
415+
&offer.keyset_id,
416+
)
413417
.await
414418
{
415419
Ok(spent) => {

crates/bcr-ebill-api/src/service/bill_service/sharing.rs

Lines changed: 0 additions & 140 deletions
This file was deleted.

crates/bcr-ebill-core/src/bill/mod.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use crate::{
1515
network_char,
1616
util::{self, BcrKeys},
1717
};
18-
use borsh::{BorshDeserialize, BorshSerialize};
1918
use secp256k1::{PublicKey, SecretKey};
2019
use serde::{Deserialize, Serialize};
2120

@@ -610,27 +609,3 @@ pub struct PastPaymentDataRecourse {
610609
pub mempool_link_for_address_to_pay: String,
611610
pub status: PastPaymentStatus,
612611
}
613-
614-
#[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize, Debug, Clone)]
615-
pub struct BillToShareWithExternalParty {
616-
/// The bill id
617-
pub bill_id: BillId,
618-
/// The base58 encoded, encrypted BillBlockPlaintextWrapper of the bill
619-
pub data: String,
620-
#[borsh(
621-
serialize_with = "crate::util::borsh::serialize_vec_url",
622-
deserialize_with = "crate::util::borsh::deserialize_vec_url"
623-
)]
624-
/// The file urls of bill files, encrypted with the receiver's key, uploaded to Nostr
625-
pub file_urls: Vec<url::Url>,
626-
/// The hash over the unencrypted data
627-
pub hash: String,
628-
/// The signature over the hash by the sharer of the bill
629-
pub signature: String,
630-
#[borsh(
631-
serialize_with = "crate::util::borsh::serialize_pubkey",
632-
deserialize_with = "crate::util::borsh::deserialize_pubkey"
633-
)]
634-
/// The receiver's pub key
635-
pub receiver: PublicKey,
636-
}

0 commit comments

Comments
 (0)