diff --git a/bindings/cashu-js/src/nuts/mod.rs b/bindings/cashu-js/src/nuts/mod.rs index 790c5a6c..c7d2134b 100644 --- a/bindings/cashu-js/src/nuts/mod.rs +++ b/bindings/cashu-js/src/nuts/mod.rs @@ -13,8 +13,8 @@ pub mod nut09; pub use nut00::{JsBlindedMessage, JsBlindedMessages, JsBlindedSignature, JsProof, JsToken}; pub use nut01::{JsKeyPair, JsKeys, JsPublicKey, JsSecretKey}; pub use nut02::{JsId, JsKeySet, JsKeySetsResponse, JsKeysResponse, JsMintKeySet}; -pub use nut03::{JsRequestMintResponse, JsSplitRequest, JsSplitResponse}; -pub use nut04::{JsMintRequest, JsPostMintResponse}; +pub use nut03::{JsSwapRequest, JsSwapResponse}; +pub use nut04::{JsMintBolt11Request, JsMintBolt11Response}; #[cfg(feature = "nut07")] pub use nut07::{JsCheckSpendableRequest, JsCheckSpendableResponse}; -pub use nut08::{JsMeltRequest, JsMeltResponse}; +pub use nut08::{JsMeltBolt11Request, JsMeltBolt11Response}; diff --git a/bindings/cashu-js/src/nuts/nut00/blinded_signature.rs b/bindings/cashu-js/src/nuts/nut00/blinded_signature.rs index cfaa6975..133401fe 100644 --- a/bindings/cashu-js/src/nuts/nut00/blinded_signature.rs +++ b/bindings/cashu-js/src/nuts/nut00/blinded_signature.rs @@ -23,10 +23,10 @@ impl Deref for JsBlindedSignature { impl JsBlindedSignature { #[allow(clippy::new_without_default)] #[wasm_bindgen(constructor)] - pub fn new(id: JsId, amount: JsAmount, c: JsPublicKey) -> Self { + pub fn new(keyset_id: JsId, amount: JsAmount, c: JsPublicKey) -> Self { Self { inner: BlindedSignature { - id: *id.deref(), + keyset_id: *keyset_id.deref(), amount: *amount.deref(), c: c.deref().clone(), }, diff --git a/bindings/cashu-js/src/nuts/nut00/proof.rs b/bindings/cashu-js/src/nuts/nut00/proof.rs index 671a2ded..c6e92309 100644 --- a/bindings/cashu-js/src/nuts/nut00/proof.rs +++ b/bindings/cashu-js/src/nuts/nut00/proof.rs @@ -28,13 +28,13 @@ impl From for JsProof { #[wasm_bindgen(js_class = Proof)] impl JsProof { #[wasm_bindgen(constructor)] - pub fn new(amount: JsAmount, secret: JsSecret, c: JsPublicKey, id: JsId) -> JsProof { + pub fn new(amount: JsAmount, secret: JsSecret, c: JsPublicKey, keyset_id: JsId) -> JsProof { Self { inner: Proof { amount: *amount.deref(), secret: secret.deref().clone(), c: c.deref().clone(), - id: *id.deref(), + keyset_id: *keyset_id.deref(), }, } } @@ -57,9 +57,9 @@ impl JsProof { self.inner.c.clone().into() } - /// Id + /// Keyset Id #[wasm_bindgen(getter)] - pub fn id(&self) -> JsId { - self.inner.id.into() + pub fn keyset_id(&self) -> JsId { + self.inner.keyset_id.into() } } diff --git a/bindings/cashu-js/src/nuts/nut03.rs b/bindings/cashu-js/src/nuts/nut03.rs index 728d9a0b..85cd840a 100644 --- a/bindings/cashu-js/src/nuts/nut03.rs +++ b/bindings/cashu-js/src/nuts/nut03.rs @@ -1,38 +1,38 @@ use std::ops::Deref; -use cashu::nuts::{SplitRequest, SplitResponse}; +use cashu::nuts::{SwapRequest, SwapResponse}; use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; use crate::types::JsAmount; -#[wasm_bindgen(js_name = SplitRequest)] -pub struct JsSplitRequest { - inner: SplitRequest, +#[wasm_bindgen(js_name = SwapRequest)] +pub struct JsSwapRequest { + inner: SwapRequest, } -impl Deref for JsSplitRequest { - type Target = SplitRequest; +impl Deref for JsSwapRequest { + type Target = SwapRequest; fn deref(&self) -> &Self::Target { &self.inner } } -impl From for JsSplitRequest { - fn from(inner: SplitRequest) -> JsSplitRequest { - JsSplitRequest { inner } +impl From for JsSwapRequest { + fn from(inner: SwapRequest) -> JsSwapRequest { + JsSwapRequest { inner } } } -#[wasm_bindgen(js_class = SplitRequest)] -impl JsSplitRequest { +#[wasm_bindgen(js_class = SwapRequest)] +impl JsSwapRequest { #[wasm_bindgen(constructor)] - pub fn new(inputs: JsValue, outputs: JsValue) -> Result { + pub fn new(inputs: JsValue, outputs: JsValue) -> Result { let inputs = serde_wasm_bindgen::from_value(inputs).map_err(into_err)?; let outputs = serde_wasm_bindgen::from_value(outputs).map_err(into_err)?; - Ok(JsSplitRequest { - inner: SplitRequest { inputs, outputs }, + Ok(JsSwapRequest { + inner: SwapRequest { inputs, outputs }, }) } @@ -62,45 +62,43 @@ impl JsSplitRequest { } #[wasm_bindgen(js_name = SplitResponse)] -pub struct JsSplitResponse { - inner: SplitResponse, +pub struct JsSwapResponse { + inner: SwapResponse, } -impl Deref for JsSplitResponse { - type Target = SplitResponse; +impl Deref for JsSwapResponse { + type Target = SwapResponse; fn deref(&self) -> &Self::Target { &self.inner } } -impl From for JsSplitResponse { - fn from(inner: SplitResponse) -> JsSplitResponse { - JsSplitResponse { inner } +impl From for JsSwapResponse { + fn from(inner: SwapResponse) -> JsSwapResponse { + JsSwapResponse { inner } } } #[wasm_bindgen(js_class = SplitResponse)] -impl JsSplitResponse { +impl JsSwapResponse { #[wasm_bindgen(constructor)] - pub fn new(promises: JsValue) -> Result { - let promises = serde_wasm_bindgen::from_value(promises).map_err(into_err)?; + pub fn new(signatures: JsValue) -> Result { + let signatures = serde_wasm_bindgen::from_value(signatures).map_err(into_err)?; - Ok(JsSplitResponse { - inner: SplitResponse { - promises: Some(promises), - }, + Ok(JsSwapResponse { + inner: SwapResponse { signatures }, }) } /// Get Promises #[wasm_bindgen(getter)] - pub fn promises(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.promises).map_err(into_err) + pub fn signatures(&self) -> Result { + serde_wasm_bindgen::to_value(&self.inner.signatures).map_err(into_err) } /// Promises Amount #[wasm_bindgen(js_name = promisesAmount)] - pub fn promises_amount(&self) -> Option { - self.inner.promises_amount().map(|a| a.into()) + pub fn promises_amount(&self) -> JsAmount { + self.inner.promises_amount().into() } } diff --git a/bindings/cashu-js/src/nuts/nut04.rs b/bindings/cashu-js/src/nuts/nut04.rs index 3beb0420..0b1a082f 100644 --- a/bindings/cashu-js/src/nuts/nut04.rs +++ b/bindings/cashu-js/src/nuts/nut04.rs @@ -1,37 +1,37 @@ use std::ops::Deref; -use cashu::nuts::nut04::{MintRequest, PostMintResponse}; +use cashu::nuts::nut04::{MintBolt11Request, MintBolt11Response}; use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; use crate::types::JsAmount; -#[wasm_bindgen(js_name = MintRequest)] -pub struct JsMintRequest { - inner: MintRequest, +#[wasm_bindgen(js_name = MintBolt11Request)] +pub struct JsMintBolt11Request { + inner: MintBolt11Request, } -impl Deref for JsMintRequest { - type Target = MintRequest; +impl Deref for JsMintBolt11Request { + type Target = MintBolt11Request; fn deref(&self) -> &Self::Target { &self.inner } } -impl From for JsMintRequest { - fn from(inner: MintRequest) -> JsMintRequest { - JsMintRequest { inner } +impl From for JsMintBolt11Request { + fn from(inner: MintBolt11Request) -> JsMintBolt11Request { + JsMintBolt11Request { inner } } } -#[wasm_bindgen(js_class = MintRequest)] -impl JsMintRequest { +#[wasm_bindgen(js_class = MintBolt11Request)] +impl JsMintBolt11Request { /// Try From Base 64 String #[wasm_bindgen(constructor)] - pub fn new(outputs: JsValue) -> Result { + pub fn new(quote: String, outputs: JsValue) -> Result { let outputs = serde_wasm_bindgen::from_value(outputs).map_err(into_err)?; - Ok(JsMintRequest { - inner: MintRequest { outputs }, + Ok(JsMintBolt11Request { + inner: MintBolt11Request { quote, outputs }, }) } @@ -47,36 +47,36 @@ impl JsMintRequest { } #[wasm_bindgen(js_name = PostMintResponse)] -pub struct JsPostMintResponse { - inner: PostMintResponse, +pub struct JsMintBolt11Response { + inner: MintBolt11Response, } -impl Deref for JsPostMintResponse { - type Target = PostMintResponse; +impl Deref for JsMintBolt11Response { + type Target = MintBolt11Response; fn deref(&self) -> &Self::Target { &self.inner } } -impl From for JsPostMintResponse { - fn from(inner: PostMintResponse) -> JsPostMintResponse { - JsPostMintResponse { inner } +impl From for JsMintBolt11Response { + fn from(inner: MintBolt11Response) -> JsMintBolt11Response { + JsMintBolt11Response { inner } } } #[wasm_bindgen(js_class = PostMintResponse)] -impl JsPostMintResponse { +impl JsMintBolt11Response { /// Try From Base 64 String #[wasm_bindgen(constructor)] - pub fn new(promises: JsValue) -> Result { - let promises = serde_wasm_bindgen::from_value(promises).map_err(into_err)?; - Ok(JsPostMintResponse { - inner: PostMintResponse { promises }, + pub fn new(signatures: JsValue) -> Result { + let signatures = serde_wasm_bindgen::from_value(signatures).map_err(into_err)?; + Ok(JsMintBolt11Response { + inner: MintBolt11Response { signatures }, }) } #[wasm_bindgen(getter)] - pub fn promises(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.promises).map_err(into_err) + pub fn signatures(&self) -> Result { + serde_wasm_bindgen::to_value(&self.inner.signatures).map_err(into_err) } } diff --git a/bindings/cashu-js/src/nuts/nut08.rs b/bindings/cashu-js/src/nuts/nut08.rs index bd210eea..13ae123e 100644 --- a/bindings/cashu-js/src/nuts/nut08.rs +++ b/bindings/cashu-js/src/nuts/nut08.rs @@ -8,27 +8,27 @@ use crate::error::{into_err, Result}; use crate::types::JsAmount; #[wasm_bindgen(js_name = MeltRequest)] -pub struct JsMeltRequest { +pub struct JsMeltBolt11Request { inner: MeltBolt11Request, } -impl Deref for JsMeltRequest { +impl Deref for JsMeltBolt11Request { type Target = MeltBolt11Request; fn deref(&self) -> &Self::Target { &self.inner } } -impl From for JsMeltRequest { - fn from(inner: MeltBolt11Request) -> JsMeltRequest { - JsMeltRequest { inner } +impl From for JsMeltBolt11Request { + fn from(inner: MeltBolt11Request) -> JsMeltBolt11Request { + JsMeltBolt11Request { inner } } } -#[wasm_bindgen(js_class = MeltRequest)] -impl JsMeltRequest { +#[wasm_bindgen(js_class = MeltBolt11Request)] +impl JsMeltBolt11Request { #[wasm_bindgen(constructor)] - pub fn new(quote: String, inputs: JsValue, outputs: JsValue) -> Result { + pub fn new(quote: String, inputs: JsValue, outputs: JsValue) -> Result { let inputs: Vec = serde_wasm_bindgen::from_value(inputs).map_err(into_err)?; let outputs: Option> = if !outputs.is_null() { Some(serde_wasm_bindgen::from_value(outputs).map_err(into_err)?) @@ -36,7 +36,7 @@ impl JsMeltRequest { None }; - Ok(JsMeltRequest { + Ok(JsMeltBolt11Request { inner: MeltBolt11Request { quote, inputs, @@ -65,36 +65,40 @@ impl JsMeltRequest { } #[wasm_bindgen(js_name = MeltResponse)] -pub struct JsMeltResponse { +pub struct JsMeltBolt11Response { inner: MeltBolt11Response, } -impl Deref for JsMeltResponse { +impl Deref for JsMeltBolt11Response { type Target = MeltBolt11Response; fn deref(&self) -> &Self::Target { &self.inner } } -impl From for JsMeltResponse { - fn from(inner: MeltBolt11Response) -> JsMeltResponse { - JsMeltResponse { inner } +impl From for JsMeltBolt11Response { + fn from(inner: MeltBolt11Response) -> JsMeltBolt11Response { + JsMeltBolt11Response { inner } } } -#[wasm_bindgen(js_class = MeltResponse)] -impl JsMeltResponse { +#[wasm_bindgen(js_class = MeltBolt11Response)] +impl JsMeltBolt11Response { #[wasm_bindgen(constructor)] - pub fn new(paid: bool, proof: String, change: JsValue) -> Result { + pub fn new( + paid: bool, + payment_preimage: Option, + change: JsValue, + ) -> Result { let change: Option> = if change.is_null() { Some(serde_wasm_bindgen::from_value(change).map_err(into_err)?) } else { None }; - Ok(JsMeltResponse { + Ok(JsMeltBolt11Response { inner: MeltBolt11Response { - proof, + payment_preimage, paid, change, }, @@ -109,8 +113,8 @@ impl JsMeltResponse { /// Get Preimage #[wasm_bindgen(getter)] - pub fn proof(&self) -> String { - self.inner.proof.clone() + pub fn payment_preimage(&self) -> Option { + self.inner.payment_preimage.clone() } /// Get Change diff --git a/bindings/cashu-js/src/types/amount.rs b/bindings/cashu-js/src/types/amount.rs index a518a872..48456a93 100644 --- a/bindings/cashu-js/src/types/amount.rs +++ b/bindings/cashu-js/src/types/amount.rs @@ -23,43 +23,23 @@ impl From for JsAmount { } } +impl From for JsAmount { + fn from(amount: u64) -> JsAmount { + JsAmount { + inner: Amount::from(amount), + } + } +} + #[wasm_bindgen(js_class = Amount)] impl JsAmount { #[wasm_bindgen(constructor)] pub fn new(sats: u32) -> Self { Self { - inner: Amount::from_sat(sats as u64), + inner: Amount::from(sats as u64), } } - /// From Sats - #[wasm_bindgen(js_name = fromSat)] - pub fn from_sat(sats: u64) -> Self { - Self { - inner: Amount::from_sat(sats), - } - } - - /// From Msats - #[wasm_bindgen(js_name = fromMSat)] - pub fn from_msat(msats: u64) -> Self { - Self { - inner: Amount::from_msat(msats), - } - } - - /// Get as sats - #[wasm_bindgen(js_name = toSat)] - pub fn to_sat(&self) -> u64 { - self.inner.to_sat() - } - - /// Get as msats - #[wasm_bindgen(js_name = toMSat)] - pub fn to_msat(&self) -> u64 { - self.inner.to_msat() - } - /// Split amount returns sat vec of sats #[wasm_bindgen(js_name = split)] pub fn split(&self) -> Result { diff --git a/bindings/cashu-js/src/types/bolt11_invoice.rs b/bindings/cashu-js/src/types/bolt11_invoice.rs index 08603395..e1ebdc6d 100644 --- a/bindings/cashu-js/src/types/bolt11_invoice.rs +++ b/bindings/cashu-js/src/types/bolt11_invoice.rs @@ -37,7 +37,9 @@ impl JsBolt11Invoice { /// Amount #[wasm_bindgen(getter)] pub fn amount(&self) -> Option { - self.inner.amount_milli_satoshis().map(JsAmount::from_msat) + self.inner + .amount_milli_satoshis() + .map(|a| JsAmount::from(a / 1000)) } /// Invoice as string