mirror of
https://github.com/aljazceru/cdk.git
synced 2026-02-05 05:06:14 +01:00
improve: use features for optional nuts
This commit is contained in:
@@ -12,7 +12,7 @@ crate-type = ["lib", "cdylib", "staticlib"]
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
cashu = { path = "../../crates/cashu", features = ["wallet", "mint"] }
|
||||
cashu = { path = "../../crates/cashu", features = ["wallet", "mint", "all-nuts"] }
|
||||
url = { workspace = true }
|
||||
uniffi = { workspace = true }
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ pub mod nut03;
|
||||
pub mod nut04;
|
||||
pub mod nut05;
|
||||
pub mod nut06;
|
||||
#[cfg(feature = "nut07")]
|
||||
pub mod nut07;
|
||||
pub mod nut08;
|
||||
#[cfg(feature = "nut09")]
|
||||
pub mod nut09;
|
||||
|
||||
@@ -7,8 +7,10 @@ use cashu_js::nuts::nut03::JsRequestMintResponse;
|
||||
use cashu_js::nuts::nut04::JsPostMintResponse;
|
||||
use cashu_js::nuts::nut05::JsCheckFeesResponse;
|
||||
use cashu_js::nuts::nut06::{JsSplitRequest, JsSplitResponse};
|
||||
#[cfg(feature = "nut07")]
|
||||
use cashu_js::nuts::nut07::JsCheckSpendableResponse;
|
||||
use cashu_js::nuts::nut08::JsMeltResponse;
|
||||
#[cfg(feature = "nut09")]
|
||||
use cashu_js::nuts::nut09::JsMintInfo;
|
||||
use cashu_js::{JsAmount, JsBolt11Invoice};
|
||||
use cashu_sdk::client::Client;
|
||||
@@ -125,6 +127,7 @@ impl JsClient {
|
||||
.into())
|
||||
}
|
||||
|
||||
#[cfg(feature = "nut07")]
|
||||
#[wasm_bindgen(js_name = checkSpendable)]
|
||||
pub async fn check_spendable(&self, proofs: JsValue) -> Result<JsCheckSpendableResponse> {
|
||||
let proofs = serde_wasm_bindgen::from_value(proofs).map_err(into_err)?;
|
||||
@@ -137,6 +140,7 @@ impl JsClient {
|
||||
.into())
|
||||
}
|
||||
|
||||
#[cfg(feature = "nut09")]
|
||||
#[wasm_bindgen(js_name = getInfo)]
|
||||
pub async fn get_info(&self) -> Result<JsMintInfo> {
|
||||
Ok(self.inner.get_info().await.map_err(into_err)?.into())
|
||||
|
||||
@@ -3,6 +3,7 @@ use std::ops::Deref;
|
||||
use cashu_js::nuts::nut02::{JsId, JsKeySet, JsKeySetsResponse, JsKeysResponse, JsMintKeySet};
|
||||
use cashu_js::nuts::nut04::{JsMintRequest, JsPostMintResponse};
|
||||
use cashu_js::nuts::nut06::{JsSplitRequest, JsSplitResponse};
|
||||
#[cfg(feature = "nut07")]
|
||||
use cashu_js::nuts::nut07::{JsCheckSpendableRequest, JsCheckSpendableResponse};
|
||||
use cashu_js::nuts::nut08::{JsMeltRequest, JsMeltResponse};
|
||||
use cashu_js::JsAmount;
|
||||
@@ -117,6 +118,7 @@ impl JsMint {
|
||||
}
|
||||
|
||||
/// Check Spendable
|
||||
#[cfg(feature = "nut07")]
|
||||
#[wasm_bindgen(js_name = CheckSpendable)]
|
||||
pub fn check_spendable(
|
||||
&mut self,
|
||||
|
||||
@@ -3,7 +3,9 @@ use std::ops::Deref;
|
||||
use cashu_js::nuts::nut00::{JsBlindedMessages, JsToken};
|
||||
use cashu_js::nuts::nut01::JsKeys;
|
||||
use cashu_js::nuts::nut03::JsRequestMintResponse;
|
||||
use cashu_js::{JsAmount, JsBolt11Invoice, JsProofsStatus};
|
||||
#[cfg(feature = "nut07")]
|
||||
use cashu_js::JsProofsStatus;
|
||||
use cashu_js::{JsAmount, JsBolt11Invoice};
|
||||
use cashu_sdk::wallet::Wallet;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
@@ -39,6 +41,7 @@ impl JsWallet {
|
||||
}
|
||||
|
||||
/// Check Proofs spent
|
||||
#[cfg(feature = "nut07")]
|
||||
#[wasm_bindgen(js_name = checkProofsSpent)]
|
||||
pub async fn check_proofs_spent(&self, proofs: JsValue) -> Result<JsProofsStatus> {
|
||||
let proofs = serde_wasm_bindgen::from_value(proofs).map_err(into_err)?;
|
||||
|
||||
@@ -14,10 +14,13 @@ default = ["mint", "wallet"]
|
||||
mint = ["cashu/mint"]
|
||||
blocking = ["dep:once_cell"]
|
||||
wallet = ["cashu/wallet", "dep:minreq", "dep:once_cell"]
|
||||
nut07 = ["cashu/nut07"]
|
||||
# nut08 = ["cashu/nut08"]
|
||||
nut09 = ["cashu/nut09"]
|
||||
|
||||
|
||||
[dependencies]
|
||||
cashu = { path = "../cashu" }
|
||||
cashu = { path = "../cashu", features = ["nut08"] }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
url = { workspace = true }
|
||||
|
||||
@@ -6,8 +6,10 @@ use cashu::nuts::nut03::RequestMintResponse;
|
||||
use cashu::nuts::nut04::PostMintResponse;
|
||||
use cashu::nuts::nut05::CheckFeesResponse;
|
||||
use cashu::nuts::nut06::{SplitRequest, SplitResponse};
|
||||
#[cfg(feature = "nut07")]
|
||||
use cashu::nuts::nut07::CheckSpendableResponse;
|
||||
use cashu::nuts::nut08::MeltResponse;
|
||||
#[cfg(feature = "nut09")]
|
||||
use cashu::nuts::nut09::MintInfo;
|
||||
use cashu::{Amount, Bolt11Invoice};
|
||||
|
||||
@@ -63,6 +65,7 @@ impl Client {
|
||||
RUNTIME.block_on(async { self.client.split(split_request).await })
|
||||
}
|
||||
|
||||
#[cfg(feature = "nut07")]
|
||||
pub fn check_spendable(
|
||||
&self,
|
||||
proofs: &Vec<nut00::mint::Proof>,
|
||||
@@ -70,6 +73,7 @@ impl Client {
|
||||
RUNTIME.block_on(async { self.client.check_spendable(proofs).await })
|
||||
}
|
||||
|
||||
#[cfg(feature = "nut09")]
|
||||
pub fn get_info(&self) -> Result<MintInfo, Error> {
|
||||
RUNTIME.block_on(async { self.client.get_info().await })
|
||||
}
|
||||
|
||||
@@ -9,8 +9,10 @@ use cashu::nuts::nut03::RequestMintResponse;
|
||||
use cashu::nuts::nut04::{MintRequest, PostMintResponse};
|
||||
use cashu::nuts::nut05::{CheckFeesRequest, CheckFeesResponse};
|
||||
use cashu::nuts::nut06::{SplitRequest, SplitResponse};
|
||||
#[cfg(feature = "nut07")]
|
||||
use cashu::nuts::nut07::{CheckSpendableRequest, CheckSpendableResponse};
|
||||
use cashu::nuts::nut08::{MeltRequest, MeltResponse};
|
||||
#[cfg(feature = "nut09")]
|
||||
use cashu::nuts::nut09::MintInfo;
|
||||
use cashu::nuts::*;
|
||||
use cashu::url::UncheckedUrl;
|
||||
@@ -480,7 +482,7 @@ impl Client {
|
||||
}
|
||||
|
||||
/// Spendable check [NUT-07]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(all(not(target_arch = "wasm32"), feature = "nut07"))]
|
||||
pub async fn check_spendable(
|
||||
&self,
|
||||
proofs: &Vec<nut00::mint::Proof>,
|
||||
@@ -505,7 +507,7 @@ impl Client {
|
||||
}
|
||||
|
||||
/// Spendable check [NUT-07]
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", feature = "nut07"))]
|
||||
pub async fn check_spendable(
|
||||
&self,
|
||||
proofs: &Vec<nut00::mint::Proof>,
|
||||
@@ -535,7 +537,7 @@ impl Client {
|
||||
}
|
||||
|
||||
/// Get Mint Info [NUT-09]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(all(not(target_arch = "wasm32"), feature = "nut09"))]
|
||||
pub async fn get_info(&self) -> Result<MintInfo, Error> {
|
||||
let url = self.mint_url.join("info")?;
|
||||
let res = minreq::get(url).send()?.json::<Value>()?;
|
||||
@@ -549,7 +551,7 @@ impl Client {
|
||||
}
|
||||
|
||||
/// Get Mint Info [NUT-09]
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", feature = "nut09"))]
|
||||
pub async fn get_info(&self) -> Result<MintInfo, Error> {
|
||||
let url = self.mint_url.join("info")?;
|
||||
let res = Request::get(url.as_str())
|
||||
|
||||
@@ -6,6 +6,7 @@ use cashu::nuts::nut00::{BlindedMessage, BlindedSignature, Proof};
|
||||
use cashu::nuts::nut02::mint::KeySet;
|
||||
use cashu::nuts::nut02::Id;
|
||||
use cashu::nuts::nut06::{SplitRequest, SplitResponse};
|
||||
#[cfg(feature = "nut07")]
|
||||
use cashu::nuts::nut07::{CheckSpendableRequest, CheckSpendableResponse};
|
||||
use cashu::nuts::nut08::{MeltRequest, MeltResponse};
|
||||
use cashu::nuts::*;
|
||||
@@ -231,6 +232,7 @@ impl Mint {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "nut07")]
|
||||
pub fn check_spendable(
|
||||
&self,
|
||||
check_spendable: &CheckSpendableRequest,
|
||||
|
||||
@@ -5,13 +5,15 @@ use std::str::FromStr;
|
||||
|
||||
use cashu::dhke::{construct_proofs, unblind_message};
|
||||
use cashu::nuts::nut00::wallet::{BlindedMessages, Token};
|
||||
use cashu::nuts::nut00::{mint, BlindedSignature, Proof, Proofs};
|
||||
use cashu::nuts::nut00::{BlindedSignature, Proof, Proofs};
|
||||
use cashu::nuts::nut01::Keys;
|
||||
use cashu::nuts::nut03::RequestMintResponse;
|
||||
use cashu::nuts::nut06::{SplitPayload, SplitRequest};
|
||||
use cashu::types::{Melted, ProofsStatus, SendProofs};
|
||||
use cashu::types::{Melted, SendProofs};
|
||||
use cashu::Amount;
|
||||
pub use cashu::Bolt11Invoice;
|
||||
#[cfg(feature = "nut07")]
|
||||
use cashu::{nuts::nut00::mint, types::ProofsStatus};
|
||||
use tracing::warn;
|
||||
|
||||
#[cfg(feature = "blocking")]
|
||||
@@ -72,7 +74,7 @@ impl Wallet {
|
||||
// TODO: getter method for keys that if it cant get them try again
|
||||
|
||||
/// Check if a proof is spent
|
||||
#[cfg(not(feature = "blocking"))]
|
||||
#[cfg(all(not(feature = "blocking"), feature = "nut07"))]
|
||||
pub async fn check_proofs_spent(&self, proofs: &mint::Proofs) -> Result<ProofsStatus, Error> {
|
||||
let spendable = self.client.check_spendable(proofs).await?;
|
||||
|
||||
@@ -89,7 +91,7 @@ impl Wallet {
|
||||
}
|
||||
|
||||
/// Check if a proof is spent
|
||||
#[cfg(feature = "blocking")]
|
||||
#[cfg(all(feature = "blocking", feature = "nut07"))]
|
||||
pub fn check_proofs_spent(&self, proofs: &mint::Proofs) -> Result<ProofsStatus, Error> {
|
||||
let spendable = self.client.check_spendable(proofs)?;
|
||||
|
||||
|
||||
@@ -15,6 +15,11 @@ description = "Cashu rust wallet and mint library"
|
||||
default = ["mint", "wallet"]
|
||||
mint = []
|
||||
wallet = []
|
||||
all-nuts = ["nut07", "nut08", "nut09"]
|
||||
nut07 = []
|
||||
nut08 = []
|
||||
nut09 = []
|
||||
|
||||
|
||||
[dependencies]
|
||||
base64 = "0.21.0"
|
||||
|
||||
@@ -5,6 +5,9 @@ pub mod nut03;
|
||||
pub mod nut04;
|
||||
pub mod nut05;
|
||||
pub mod nut06;
|
||||
#[cfg(feature = "nut07")]
|
||||
pub mod nut07;
|
||||
#[cfg(feature = "nut08")]
|
||||
pub mod nut08;
|
||||
#[cfg(feature = "nut09")]
|
||||
pub mod nut09;
|
||||
|
||||
Reference in New Issue
Block a user