diff --git a/bindings/cashu-ffi/src/cashu.udl b/bindings/cashu-ffi/src/cashu.udl index 0210327d..c81b2a97 100644 --- a/bindings/cashu-ffi/src/cashu.udl +++ b/bindings/cashu-ffi/src/cashu.udl @@ -10,6 +10,7 @@ interface CashuError { [Enum] interface CurrencyUnit { Sat(); + Usd(); Custom(string unit); }; @@ -21,12 +22,7 @@ interface Bolt11Invoice { }; interface Amount { - u64 to_sat(); - u64 to_msat(); - [Name = from_sat] - constructor(u64 sat); - [Name = from_msat] - constructor(u64 msat); + constructor(u64 amount); sequence split(); }; @@ -58,6 +54,7 @@ interface SecretKey { interface BlindedMessage { constructor(Id keyset_id, Amount amount, PublicKey b); Amount amount(); + Id keyset_id(); PublicKey b(); }; @@ -66,12 +63,12 @@ interface Proof { Amount amount(); Secret secret(); PublicKey c(); - Id id(); + Id keyset_id(); }; interface BlindedSignature { - constructor(Id id, Amount amount, PublicKey c); - Id id(); + constructor(Id keyset_id, Amount amount, PublicKey c); + Id keyset_id(); Amount amount(); PublicKey c(); }; @@ -81,7 +78,7 @@ interface MintProof { Amount? amount(); Secret secret(); PublicKey? c(); - Id? id(); + Id? keyset_id(); }; @@ -150,6 +147,36 @@ interface KeySetResponse { sequence keysets(); }; +// --- NUT-04 + +interface MintQuoteBolt11Request { + constructor(Amount amount, string unit); + Amount amount(); +}; + + +interface MintQuoteBolt11Response { + constructor(string quote, string request, boolean paid, u64 expiry); + string quote(); + string request(); + boolean paid(); + u64 expiry(); +}; + + +interface MintBolt11Request { + constructor(string quote, sequence outputs); + string quote(); + sequence outputs(); +}; + +interface MintBolt11Response { + constructor(sequence signatures); + sequence signatures(); +}; + +// --- + // NUT-05 interface MeltQuoteBolt11Response { @@ -166,35 +193,23 @@ interface MeltQuoteBolt11Request { [Throws=CashuError] constructor(string request, string unit); string request(); - string unit(); }; interface MeltBolt11Request { [Throws=CashuError] - constructor(sequence inputs, string quote); + constructor(string quote, sequence inputs, sequence? outputs); sequence inputs(); string quote(); }; -interface RequestMintResponse { - [Throws=CashuError] - constructor(string invoice, string hash); - string invoice(); - string hash(); +interface MeltBolt11Response { + constructor(boolean paid, string? payment_preimage, sequence? change); + string? payment_preimage(); + boolean paid(); }; -interface MintRequest { - constructor(sequence outputs); - sequence outputs(); - Amount total_amount(); -}; - -interface PostMintResponse { - constructor(sequence promises); - sequence promises(); -}; - -interface SplitRequest { +// ---- +interface SwapRequest { constructor(sequence proofs, sequence outputs); sequence proofs(); sequence outputs(); @@ -202,11 +217,9 @@ interface SplitRequest { Amount output_amount(); }; -interface SplitResponse { +interface SwapResponse { constructor(sequence promises); - sequence promises(); - Amount? promises_amount(); - + sequence signatures(); }; interface CheckSpendableRequest { @@ -220,21 +233,6 @@ interface CheckSpendableResponse { sequence pending(); }; -interface MeltRequest { - [Throws=CashuError] - constructor(sequence proofs, string Invoice, sequence? outputs); - sequence proofs(); - string invoice(); - sequence? outputs(); -}; - -interface MeltResponse { - constructor(boolean paid, string? preimage, sequence? change); - boolean paid(); - string? preimage(); - sequence? change(); -}; - interface MintVersion { constructor(string name, string version); string name(); @@ -242,14 +240,13 @@ interface MintVersion { }; interface MintInfo { - constructor(string? name, PublicKey? pubkey, MintVersion? version, string? description, string? description_long, sequence>? contact, sequence nuts, string? motd); + constructor(string? name, PublicKey? pubkey, MintVersion? version, string? description, string? description_long, sequence>? contact, string nuts, string? motd); string? name(); PublicKey? pubkey(); MintVersion? version(); string? description(); string? description_long(); sequence>? contact(); - sequence nuts(); string? motd(); }; diff --git a/bindings/cashu-ffi/src/lib.rs b/bindings/cashu-ffi/src/lib.rs index a6548996..ac62e339 100644 --- a/bindings/cashu-ffi/src/lib.rs +++ b/bindings/cashu-ffi/src/lib.rs @@ -18,15 +18,17 @@ mod ffi { pub use crate::nuts::nut01::public_key::PublicKey; pub use crate::nuts::nut01::secret_key::SecretKey; pub use crate::nuts::nut02::{Id, KeySet, KeySetResponse, MintKeySet}; - pub use crate::nuts::nut03::{RequestMintResponse, SplitRequest, SplitResponse}; - pub use crate::nuts::nut04::{MintRequest, PostMintResponse}; + pub use crate::nuts::nut03::{SwapRequest, SwapResponse}; + pub use crate::nuts::nut04::{ + MintBolt11Request, MintBolt11Response, MintQuoteBolt11Request, MintQuoteBolt11Response, + }; pub use crate::nuts::nut05::{ MeltBolt11Request as Nut05MeltBolt11Request, MeltBolt11Response as Nut05MeltBolt11Response, - MeltQuoteBolt11Request, + MeltQuoteBolt11Request, MeltQuoteBolt11Response, }; + pub use crate::nuts::nut06::{MintInfo, MintVersion}; pub use crate::nuts::nut07::{CheckSpendableRequest, CheckSpendableResponse}; pub use crate::nuts::nut08::{MeltBolt11Request, MeltBolt11Response}; - pub use crate::nuts::nut09::{MintInfo, MintVersion}; pub use crate::types::amount::Amount; pub use crate::types::{Bolt11Invoice, KeySetInfo, Secret}; diff --git a/bindings/cashu-ffi/src/nuts/mod.rs b/bindings/cashu-ffi/src/nuts/mod.rs index aa0a442e..add1d404 100644 --- a/bindings/cashu-ffi/src/nuts/mod.rs +++ b/bindings/cashu-ffi/src/nuts/mod.rs @@ -4,6 +4,6 @@ pub mod nut02; pub mod nut03; pub mod nut04; pub mod nut05; +pub mod nut06; pub mod nut07; pub mod nut08; -pub mod nut09; diff --git a/bindings/cashu-ffi/src/nuts/nut00/blinded_message.rs b/bindings/cashu-ffi/src/nuts/nut00/blinded_message.rs index b183362a..fe8466b7 100644 --- a/bindings/cashu-ffi/src/nuts/nut00/blinded_message.rs +++ b/bindings/cashu-ffi/src/nuts/nut00/blinded_message.rs @@ -32,6 +32,10 @@ impl BlindedMessage { Arc::new(self.inner.amount.into()) } + pub fn keyset_id(&self) -> Arc { + Arc::new(self.inner.keyset_id.into()) + } + pub fn b(&self) -> Arc { Arc::new(self.inner.b.clone().into()) } diff --git a/bindings/cashu-ffi/src/nuts/nut00/blinded_signature.rs b/bindings/cashu-ffi/src/nuts/nut00/blinded_signature.rs index 5fbc96a8..5ec154ec 100644 --- a/bindings/cashu-ffi/src/nuts/nut00/blinded_signature.rs +++ b/bindings/cashu-ffi/src/nuts/nut00/blinded_signature.rs @@ -17,18 +17,18 @@ impl Deref for BlindedSignature { } impl BlindedSignature { - pub fn new(id: Arc, amount: Arc, c: Arc) -> Self { + pub fn new(keyset_id: Arc, amount: Arc, c: Arc) -> Self { Self { inner: BlindedSignatureSdk { - id: *id.as_ref().deref(), + keyset_id: *keyset_id.as_ref().deref(), amount: *amount.as_ref().deref(), c: c.as_ref().into(), }, } } - pub fn id(&self) -> Arc { - Arc::new(self.inner.id.into()) + pub fn keyset_id(&self) -> Arc { + Arc::new(self.inner.keyset_id.into()) } pub fn amount(&self) -> Arc { diff --git a/bindings/cashu-ffi/src/nuts/nut00/proof.rs b/bindings/cashu-ffi/src/nuts/nut00/proof.rs index 5072a9e2..9cbb0a3a 100644 --- a/bindings/cashu-ffi/src/nuts/nut00/proof.rs +++ b/bindings/cashu-ffi/src/nuts/nut00/proof.rs @@ -18,13 +18,18 @@ impl Deref for Proof { } impl Proof { - pub fn new(amount: Arc, secret: Arc, c: Arc, id: Arc) -> Self { + pub fn new( + amount: Arc, + secret: Arc, + c: Arc, + keyset_id: Arc, + ) -> Self { Self { inner: ProofSdk { amount: *amount.as_ref().deref(), secret: secret.as_ref().deref().clone(), c: c.as_ref().deref().clone(), - id: *id.as_ref().deref(), + keyset_id: *keyset_id.as_ref().deref(), }, } } @@ -41,8 +46,8 @@ impl Proof { Arc::new(self.inner.c.clone().into()) } - pub fn id(&self) -> Arc { - Arc::new(self.id.into()) + pub fn keyset_id(&self) -> Arc { + Arc::new(self.keyset_id.into()) } } @@ -52,7 +57,7 @@ impl From<&Proof> for ProofSdk { amount: *proof.amount().as_ref().deref(), secret: proof.secret().as_ref().deref().clone(), c: proof.c().deref().into(), - id: proof.id, + keyset_id: proof.keyset_id, } } } @@ -88,14 +93,14 @@ pub mod mint { amount: Option>, secret: Arc, c: Option>, - id: Option>, + keyset_id: Option>, ) -> Self { Self { inner: ProofSdk { amount: amount.map(|a| *a.as_ref().deref()), secret: secret.as_ref().deref().clone(), c: c.map(|c| c.as_ref().into()), - id: id.map(|id| *id.as_ref().deref()), + keyset_id: keyset_id.map(|id| *id.as_ref().deref()), }, } } @@ -112,8 +117,8 @@ pub mod mint { self.inner.c.clone().map(|c| Arc::new(c.into())) } - pub fn id(&self) -> Option> { - self.inner.id.map(|id| Arc::new(id.into())) + pub fn keyset_id(&self) -> Option> { + self.inner.keyset_id.map(|id| Arc::new(id.into())) } } diff --git a/bindings/cashu-ffi/src/nuts/nut00/token.rs b/bindings/cashu-ffi/src/nuts/nut00/token.rs index d3d63924..acef0532 100644 --- a/bindings/cashu-ffi/src/nuts/nut00/token.rs +++ b/bindings/cashu-ffi/src/nuts/nut00/token.rs @@ -10,14 +10,16 @@ use crate::error::Result; use crate::{MintProofs, Proof}; pub enum CurrencyUnit { - Sat, + Sat(), + Usd(), Custom { unit: String }, } impl From<&CurrencyUnit> for CurrencyUnitSdk { fn from(unit: &CurrencyUnit) -> CurrencyUnitSdk { match unit { - CurrencyUnit::Sat => CurrencyUnitSdk::Sat, + CurrencyUnit::Sat() => CurrencyUnitSdk::Sat, + CurrencyUnit::Usd() => CurrencyUnitSdk::Usd, CurrencyUnit::Custom { unit } => CurrencyUnitSdk::Custom(unit.clone()), } } @@ -26,7 +28,8 @@ impl From<&CurrencyUnit> for CurrencyUnitSdk { impl From for CurrencyUnit { fn from(unit: CurrencyUnitSdk) -> CurrencyUnit { match unit { - CurrencyUnitSdk::Sat => CurrencyUnit::Sat, + CurrencyUnitSdk::Sat => CurrencyUnit::Sat(), + CurrencyUnitSdk::Usd => CurrencyUnit::Usd(), CurrencyUnitSdk::Custom(unit) => CurrencyUnit::Custom { unit: unit.clone() }, } } diff --git a/bindings/cashu-ffi/src/nuts/nut01/keys.rs b/bindings/cashu-ffi/src/nuts/nut01/keys.rs index 0fc4f71f..166fbbdb 100644 --- a/bindings/cashu-ffi/src/nuts/nut01/keys.rs +++ b/bindings/cashu-ffi/src/nuts/nut01/keys.rs @@ -29,7 +29,7 @@ impl From for Keys { let keys = keys .keys() .into_iter() - .map(|(amount, pk)| (amount.to_sat().to_string(), Arc::new(pk.into()))) + .map(|(amount, pk)| (u64::from(amount).to_string(), Arc::new(pk.into()))) .collect(); Keys::new(keys) @@ -42,7 +42,7 @@ impl Keys { .into_iter() .map(|(amount, pk)| { ( - AmountSdk::from_sat(amount.parse::().unwrap()), + AmountSdk::from(amount.parse::().unwrap()), pk.as_ref().into(), ) }) @@ -57,7 +57,7 @@ impl Keys { self.inner .keys() .into_iter() - .map(|(amount, pk)| (amount.to_sat().to_string(), Arc::new(pk.into()))) + .map(|(amount, pk)| (u64::from(amount).to_string(), Arc::new(pk.into()))) .collect() } @@ -71,7 +71,7 @@ impl Keys { self.inner .as_hashmap() .into_iter() - .map(|(amount, pk)| (amount.to_sat().to_string(), pk)) + .map(|(amount, pk)| (u64::from(amount).to_string(), pk)) .collect() } } diff --git a/bindings/cashu-ffi/src/nuts/nut03/mod.rs b/bindings/cashu-ffi/src/nuts/nut03/mod.rs index 6aad1dcd..87287e0d 100644 --- a/bindings/cashu-ffi/src/nuts/nut03/mod.rs +++ b/bindings/cashu-ffi/src/nuts/nut03/mod.rs @@ -1,28 +1,28 @@ use std::ops::Deref; use std::sync::Arc; -use cashu::nuts::{SplitRequest as SplitRequestSdk, SplitResponse as SplitResponseSdk}; +use cashu::nuts::{SwapRequest as SwapRequestSdk, SwapResponse as SwapResponseSdk}; use crate::{Amount, BlindedMessage, BlindedSignature, Proof}; -pub struct SplitRequest { - inner: SplitRequestSdk, +pub struct SwapRequest { + inner: SwapRequestSdk, } -impl Deref for SplitRequest { - type Target = SplitRequestSdk; +impl Deref for SwapRequest { + type Target = SwapRequestSdk; fn deref(&self) -> &Self::Target { &self.inner } } -impl SplitRequest { +impl SwapRequest { pub fn new(proofs: Vec>, outputs: Vec>) -> Self { let proofs = proofs.into_iter().map(|p| p.as_ref().into()).collect(); let outputs = outputs.into_iter().map(|o| o.as_ref().into()).collect(); Self { - inner: SplitRequestSdk::new(proofs, outputs), + inner: SwapRequestSdk::new(proofs, outputs), } } @@ -53,35 +53,30 @@ impl SplitRequest { } } -pub struct SplitResponse { - inner: SplitResponseSdk, +pub struct SwapResponse { + inner: SwapResponseSdk, } -impl SplitResponse { - pub fn new(promises: Vec>) -> Self { - let promises = promises.into_iter().map(|p| p.as_ref().into()).collect(); +impl SwapResponse { + pub fn new(signatures: Vec>) -> Self { + let signatures = signatures.into_iter().map(|p| p.as_ref().into()).collect(); Self { - inner: SplitResponseSdk::new(promises), + inner: SwapResponseSdk::new(signatures), } } - pub fn promises(&self) -> Vec> { + pub fn signatures(&self) -> Vec> { self.inner - .promises + .signatures .clone() - .unwrap_or_default() .into_iter() .map(|p| Arc::new(p.into())) .collect() } - - pub fn promises_amount(&self) -> Option> { - self.inner.promises_amount().map(|a| Arc::new(a.into())) - } } -impl From for SplitResponse { - fn from(inner: cashu::nuts::SplitResponse) -> SplitResponse { - SplitResponse { inner } +impl From for SwapResponse { + fn from(inner: SwapResponseSdk) -> SwapResponse { + SwapResponse { inner } } } diff --git a/bindings/cashu-ffi/src/nuts/nut04/mod.rs b/bindings/cashu-ffi/src/nuts/nut04/mod.rs index 303e68ff..9851bdba 100644 --- a/bindings/cashu-ffi/src/nuts/nut04/mod.rs +++ b/bindings/cashu-ffi/src/nuts/nut04/mod.rs @@ -1,33 +1,123 @@ use std::ops::Deref; +use std::str::FromStr; use std::sync::Arc; -use cashu::nuts::nut04::{MintRequest as MintRequestSdk, PostMintResponse as PostMintResponseSdk}; +use cashu::nuts::{ + CurrencyUnit, MintBolt11Request as MintBolt11RequestSdk, + MintBolt11Response as MintBolt11ResponseSdk, + MintQuoteBolt11Request as MintQuoteBolt11RequestSdk, + MintQuoteBolt11Response as MintQuoteBolt11ResponseSdk, +}; use crate::{Amount, BlindedMessage, BlindedSignature}; -pub struct MintRequest { - inner: MintRequestSdk, +pub struct MintQuoteBolt11Request { + inner: MintQuoteBolt11RequestSdk, } -impl Deref for MintRequest { - type Target = MintRequestSdk; +impl Deref for MintQuoteBolt11Request { + type Target = MintQuoteBolt11RequestSdk; fn deref(&self) -> &Self::Target { &self.inner } } -impl MintRequest { - pub fn new(outputs: Vec>) -> Self { +impl MintQuoteBolt11Request { + pub fn new(amount: Arc, unit: String) -> Self { Self { - inner: MintRequestSdk { - outputs: outputs - .into_iter() - .map(|o| o.as_ref().deref().clone()) - .collect(), + inner: MintQuoteBolt11RequestSdk { + amount: amount.as_ref().deref().clone(), + unit: CurrencyUnit::from_str(&unit).unwrap(), }, } } + pub fn amount(&self) -> Arc { + Arc::new(self.inner.amount.into()) + } + + pub fn unit(&self) -> Arc { + Arc::new(self.inner.clone().unit.into()) + } +} + +impl From for MintQuoteBolt11Request { + fn from(inner: MintQuoteBolt11RequestSdk) -> MintQuoteBolt11Request { + MintQuoteBolt11Request { inner } + } +} + +pub struct MintQuoteBolt11Response { + inner: MintQuoteBolt11ResponseSdk, +} + +impl Deref for MintQuoteBolt11Response { + type Target = MintQuoteBolt11ResponseSdk; + fn deref(&self) -> &Self::Target { + &self.inner + } +} + +impl MintQuoteBolt11Response { + pub fn new(quote: String, request: String, paid: bool, expiry: u64) -> Self { + Self { + inner: MintQuoteBolt11ResponseSdk { + quote, + request, + paid, + expiry, + }, + } + } + + pub fn quote(&self) -> String { + self.quote.clone() + } + + pub fn request(&self) -> String { + self.request.clone() + } + + pub fn paid(&self) -> bool { + self.paid + } + + pub fn expiry(&self) -> u64 { + self.expiry + } +} + +impl From for MintQuoteBolt11Response { + fn from(inner: MintQuoteBolt11ResponseSdk) -> MintQuoteBolt11Response { + MintQuoteBolt11Response { inner } + } +} + +pub struct MintBolt11Request { + inner: MintBolt11RequestSdk, +} + +impl Deref for MintBolt11Request { + type Target = MintBolt11RequestSdk; + fn deref(&self) -> &Self::Target { + &self.inner + } +} + +impl MintBolt11Request { + pub fn new(quote: String, outputs: Vec>) -> Self { + Self { + inner: MintBolt11RequestSdk { + quote, + outputs: outputs.iter().map(|o| o.as_ref().deref().clone()).collect(), + }, + } + } + + pub fn quote(&self) -> String { + self.quote.clone() + } + pub fn outputs(&self) -> Vec> { self.inner .outputs @@ -36,50 +126,37 @@ impl MintRequest { .map(|o| Arc::new(o.into())) .collect() } - - pub fn total_amount(&self) -> Arc { - Arc::new(self.inner.total_amount().into()) - } } -impl From for MintRequest { - fn from(inner: cashu::nuts::nut04::MintRequest) -> MintRequest { - MintRequest { inner } - } +pub struct MintBolt11Response { + inner: MintBolt11ResponseSdk, } -pub struct PostMintResponse { - inner: PostMintResponseSdk, -} - -impl Deref for PostMintResponse { - type Target = PostMintResponseSdk; +impl Deref for MintBolt11Response { + type Target = MintBolt11ResponseSdk; fn deref(&self) -> &Self::Target { &self.inner } } -impl PostMintResponse { - pub fn new(promises: Vec>) -> Self { +impl MintBolt11Response { + pub fn new(signatures: Vec>) -> Self { Self { - inner: PostMintResponseSdk { - promises: promises.into_iter().map(|p| p.as_ref().into()).collect(), + inner: MintBolt11ResponseSdk { + signatures: signatures + .into_iter() + .map(|s| s.as_ref().deref().clone()) + .collect(), }, } } - pub fn promises(&self) -> Vec> { + pub fn signatures(&self) -> Vec> { self.inner - .promises + .signatures .clone() .into_iter() - .map(|p| Arc::new(p.into())) + .map(|o| Arc::new(o.into())) .collect() } } - -impl From for PostMintResponse { - fn from(inner: cashu::nuts::nut04::PostMintResponse) -> PostMintResponse { - PostMintResponse { inner } - } -} diff --git a/bindings/cashu-ffi/src/nuts/nut05/mod.rs b/bindings/cashu-ffi/src/nuts/nut05/mod.rs index f64eae5d..abd2ca92 100644 --- a/bindings/cashu-ffi/src/nuts/nut05/mod.rs +++ b/bindings/cashu-ffi/src/nuts/nut05/mod.rs @@ -110,7 +110,7 @@ impl MeltBolt11Request { } pub fn quote(&self) -> String { - self.inner.quote + self.inner.quote.clone() } } @@ -119,11 +119,15 @@ pub struct MeltBolt11Response { } impl MeltBolt11Response { - pub fn new(paid: bool, proof: String, change: Option>>) -> Self { + pub fn new( + paid: bool, + payment_preimage: Option, + change: Option>>, + ) -> Self { Self { inner: MeltBolt11ResponseSdk { paid, - proof, + payment_preimage, change: change.map(|c| c.into_iter().map(|b| b.as_ref().deref().clone()).collect()), }, } @@ -133,7 +137,7 @@ impl MeltBolt11Response { self.inner.paid } - pub fn proof(&self) -> String { - self.inner.proof.clone() + pub fn payment_preimage(&self) -> Option { + self.inner.payment_preimage.clone() } } diff --git a/bindings/cashu-ffi/src/nuts/nut09/mod.rs b/bindings/cashu-ffi/src/nuts/nut06.rs similarity index 79% rename from bindings/cashu-ffi/src/nuts/nut09/mod.rs rename to bindings/cashu-ffi/src/nuts/nut06.rs index 2cf0fb05..b550dfcc 100644 --- a/bindings/cashu-ffi/src/nuts/nut09/mod.rs +++ b/bindings/cashu-ffi/src/nuts/nut06.rs @@ -1,7 +1,7 @@ use std::ops::Deref; use std::sync::Arc; -use cashu::nuts::nut09::{MintInfo as MintInfoSdk, MintVersion as MintVersionSdk}; +use cashu::nuts::{MintInfo as MintInfoSdk, MintVersion as MintVersionSdk, Nuts as NutsSdk}; use crate::PublicKey; @@ -57,7 +57,8 @@ impl MintInfo { description: Option, description_long: Option, contact: Option>>, - nuts: Vec, + // TODO: Should be a nuts type + nuts: String, motd: Option, ) -> Self { let pubkey = pubkey.map(|p| p.as_ref().deref().clone()); @@ -70,7 +71,7 @@ impl MintInfo { description, description_long, contact, - nuts, + nuts: NutsSdk::default(), motd, }, } @@ -100,8 +101,8 @@ impl MintInfo { self.inner.contact.clone() } - pub fn nuts(&self) -> Vec { - self.inner.nuts.clone() + pub fn nuts(&self) -> Arc { + Arc::new(self.inner.nuts.clone().into()) } pub fn motd(&self) -> Option { @@ -109,8 +110,25 @@ impl MintInfo { } } -impl From for MintInfo { - fn from(inner: cashu::nuts::nut09::MintInfo) -> MintInfo { +impl From for MintInfo { + fn from(inner: MintInfoSdk) -> MintInfo { MintInfo { inner } } } + +pub struct Nuts { + inner: NutsSdk, +} + +impl Deref for Nuts { + type Target = NutsSdk; + fn deref(&self) -> &Self::Target { + &self.inner + } +} + +impl From for Nuts { + fn from(inner: NutsSdk) -> Nuts { + Nuts { inner } + } +} diff --git a/bindings/cashu-ffi/src/nuts/nut08/mod.rs b/bindings/cashu-ffi/src/nuts/nut08/mod.rs index 8390a1ff..4b6537ff 100644 --- a/bindings/cashu-ffi/src/nuts/nut08/mod.rs +++ b/bindings/cashu-ffi/src/nuts/nut08/mod.rs @@ -80,11 +80,15 @@ impl From for cashu::nuts::nut08::MeltBolt11Response { } impl MeltBolt11Response { - pub fn new(paid: bool, proof: String, change: Option>>) -> Self { + pub fn new( + paid: bool, + payment_preimage: Option, + change: Option>>, + ) -> Self { Self { inner: MeltBolt11ResponseSdk { paid, - proof, + payment_preimage, change: change .map(|change| change.into_iter().map(|bs| bs.as_ref().into()).collect()), }, @@ -95,8 +99,8 @@ impl MeltBolt11Response { self.inner.paid } - pub fn proof(&self) -> String { - self.inner.proof.clone() + pub fn payment_preimage(&self) -> Option { + self.inner.payment_preimage.clone() } pub fn change(&self) -> Option>> { diff --git a/bindings/cashu-ffi/src/types/amount.rs b/bindings/cashu-ffi/src/types/amount.rs index d70fb37a..b4c136ec 100644 --- a/bindings/cashu-ffi/src/types/amount.rs +++ b/bindings/cashu-ffi/src/types/amount.rs @@ -15,29 +15,9 @@ impl Deref for Amount { } impl Amount { - pub fn new(sats: u64) -> Self { + pub fn new(amount: u64) -> Self { Self { - inner: AmountSdk::from_sat(sats), - } - } - - pub fn to_sat(&self) -> u64 { - self.inner.to_sat() - } - - pub fn to_msat(&self) -> u64 { - self.inner.to_msat() - } - - pub fn from_sat(sats: u64) -> Self { - Self { - inner: AmountSdk::from_sat(sats), - } - } - - pub fn from_msat(msats: u64) -> Self { - Self { - inner: AmountSdk::from_msat(msats), + inner: AmountSdk::from(amount), } } @@ -47,13 +27,10 @@ impl Amount { /// Split into parts that are powers of two pub fn split(&self) -> Vec> { - let sats = self.inner.to_sat(); - (0_u64..64) - .rev() - .filter_map(|bit| { - let part = 1 << bit; - ((sats & part) == part).then_some(Arc::new(Self::from_sat(part))) - }) + self.inner + .split() + .into_iter() + .map(|a| Arc::new(a.into())) .collect() } } @@ -69,3 +46,9 @@ impl From<&Amount> for AmountSdk { amount.inner } } + +impl From for Amount { + fn from(amount: u64) -> Amount { + AmountSdk::from(amount).into() + } +} diff --git a/bindings/cashu-ffi/src/types/bolt11_invoice.rs b/bindings/cashu-ffi/src/types/bolt11_invoice.rs index 3b6a4457..9d48a285 100644 --- a/bindings/cashu-ffi/src/types/bolt11_invoice.rs +++ b/bindings/cashu-ffi/src/types/bolt11_invoice.rs @@ -38,6 +38,6 @@ impl Bolt11Invoice { pub fn amount(&self) -> Option> { self.inner .amount_milli_satoshis() - .map(|a| Arc::new(Amount::from_msat(a))) + .map(|a| Arc::new(Amount::from(a / 1000).into())) } } diff --git a/crates/cashu-sdk/src/mint.rs b/crates/cashu-sdk/src/mint.rs index a2887111..40c4ef4f 100644 --- a/crates/cashu-sdk/src/mint.rs +++ b/crates/cashu-sdk/src/mint.rs @@ -151,21 +151,21 @@ impl Mint { }) } - pub fn process_split_request( + pub fn process_swap_request( &mut self, - split_request: SwapRequest, + swap_request: SwapRequest, ) -> Result { - let proofs_total = split_request.input_amount(); + let proofs_total = swap_request.input_amount(); - let output_total = split_request.output_amount(); + let output_total = swap_request.output_amount(); if proofs_total != output_total { return Err(Error::Amount); } - let proof_count = split_request.inputs.len(); + let proof_count = swap_request.inputs.len(); - let secrets: HashSet = split_request + let secrets: HashSet = swap_request .inputs .iter() .map(|p| p.secret.clone()) @@ -176,7 +176,7 @@ impl Mint { return Err(Error::DuplicateProofs); } - for proof in &split_request.inputs { + for proof in &swap_request.inputs { self.verify_proof(proof)? } @@ -184,7 +184,7 @@ impl Mint { self.spent_secrets.insert(secret); } - let promises: Vec = split_request + let promises: Vec = swap_request .outputs .iter() .map(|b| self.blind_sign(b).unwrap()) diff --git a/crates/cashu/src/nuts/mod.rs b/crates/cashu/src/nuts/mod.rs index 42249dba..b8aa512d 100644 --- a/crates/cashu/src/nuts/mod.rs +++ b/crates/cashu/src/nuts/mod.rs @@ -25,7 +25,7 @@ pub use nut04::{ #[cfg(not(feature = "nut08"))] pub use nut05::{MeltBolt11Request, MeltBolt11Response}; pub use nut05::{MeltQuoteBolt11Request, MeltQuoteBolt11Response}; -pub use nut06::{MintInfo, MintVersion}; +pub use nut06::{MintInfo, MintVersion, Nuts}; #[cfg(feature = "wallet")] #[cfg(feature = "nut07")] pub use nut07::{CheckSpendableRequest, CheckSpendableResponse}; diff --git a/crates/cashu/src/nuts/nut04.rs b/crates/cashu/src/nuts/nut04.rs index bf204ab0..f7e9994c 100644 --- a/crates/cashu/src/nuts/nut04.rs +++ b/crates/cashu/src/nuts/nut04.rs @@ -9,7 +9,7 @@ use crate::Amount; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct MintQuoteBolt11Request { /// Amount - pub amount: u64, + pub amount: Amount, /// Unit wallet would like to pay with pub unit: CurrencyUnit, }