diff --git a/bindings/cashu-ffi/src/cashu.udl b/bindings/cashu-ffi/src/cashu.udl index 662d6684..e128c0e4 100644 --- a/bindings/cashu-ffi/src/cashu.udl +++ b/bindings/cashu-ffi/src/cashu.udl @@ -22,6 +22,11 @@ interface Amount { sequence split(); }; +interface Secret { + constructor(); + sequence as_bytes(); +}; + interface PublicKey { [Throws=CashuError, Name=from_hex] @@ -43,9 +48,9 @@ interface BlindedMessage { }; interface Proof { - constructor(Amount amount, string secret, PublicKey c, string? id); + constructor(Amount amount, Secret secret, PublicKey c, string? id); Amount amount(); - string secret(); + Secret secret(); PublicKey c(); string? id(); }; @@ -58,9 +63,9 @@ interface BlindedSignature { }; interface MintProof { - constructor(Amount? amount, string secret, PublicKey? c, string? id); + constructor(Amount? amount, Secret secret, PublicKey? c, string? id); Amount? amount(); - string secret(); + Secret secret(); PublicKey? c(); string? id(); @@ -91,7 +96,7 @@ interface BlindedMessages { [Throws=CashuError, Name=blank] constructor(Amount fee_reserve); sequence blinded_messages(); - sequence secrets(); + sequence secrets(); sequence rs(); sequence amounts(); }; diff --git a/bindings/cashu-ffi/src/lib.rs b/bindings/cashu-ffi/src/lib.rs index 7045ba76..247755de 100644 --- a/bindings/cashu-ffi/src/lib.rs +++ b/bindings/cashu-ffi/src/lib.rs @@ -27,6 +27,7 @@ mod ffi { pub use crate::nuts::nut09::{MintInfo, MintVersion}; pub use crate::types::amount::Amount; pub use crate::types::Bolt11Invoice; + pub use crate::types::Secret; pub use cashu::types::InvoiceStatus; diff --git a/bindings/cashu-ffi/src/nuts/nut00/blinded_messages.rs b/bindings/cashu-ffi/src/nuts/nut00/blinded_messages.rs index d6877323..66638850 100644 --- a/bindings/cashu-ffi/src/nuts/nut00/blinded_messages.rs +++ b/bindings/cashu-ffi/src/nuts/nut00/blinded_messages.rs @@ -2,7 +2,7 @@ use std::{ops::Deref, sync::Arc}; use cashu::nuts::nut00::wallet::BlindedMessages as BlindedMessagesSdk; -use crate::{error::Result, Amount, BlindedMessage, SecretKey}; +use crate::{error::Result, Amount, BlindedMessage, Secret, SecretKey}; pub struct BlindedMessages { inner: BlindedMessagesSdk, @@ -37,8 +37,13 @@ impl BlindedMessages { .collect() } - pub fn secrets(&self) -> Vec { - self.inner.secrets.clone() + pub fn secrets(&self) -> Vec> { + self.inner + .secrets + .clone() + .into_iter() + .map(|s| Arc::new(s.into())) + .collect() } pub fn rs(&self) -> Vec> { diff --git a/bindings/cashu-ffi/src/nuts/nut00/proof.rs b/bindings/cashu-ffi/src/nuts/nut00/proof.rs index 17c67a69..2a3ab6a1 100644 --- a/bindings/cashu-ffi/src/nuts/nut00/proof.rs +++ b/bindings/cashu-ffi/src/nuts/nut00/proof.rs @@ -2,7 +2,7 @@ use std::{ops::Deref, sync::Arc}; use cashu::nuts::nut00::Proof as ProofSdk; -use crate::{Amount, PublicKey}; +use crate::{types::Secret, Amount, PublicKey}; pub struct Proof { inner: ProofSdk, @@ -16,11 +16,16 @@ impl Deref for Proof { } impl Proof { - pub fn new(amount: Arc, secret: String, c: Arc, id: Option) -> Self { + pub fn new( + amount: Arc, + secret: Arc, + c: Arc, + id: Option, + ) -> Self { Self { inner: ProofSdk { amount: *amount.as_ref().deref(), - secret, + secret: secret.as_ref().deref().clone(), c: c.as_ref().deref().clone(), id, }, @@ -31,8 +36,8 @@ impl Proof { Arc::new(self.inner.amount.into()) } - pub fn secret(&self) -> String { - self.inner.secret.clone() + pub fn secret(&self) -> Arc { + Arc::new(self.inner.secret.clone().into()) } pub fn c(&self) -> Arc { @@ -48,7 +53,7 @@ impl From<&Proof> for ProofSdk { fn from(proof: &Proof) -> ProofSdk { ProofSdk { amount: *proof.amount().as_ref().deref(), - secret: proof.secret(), + secret: proof.secret().as_ref().deref().clone(), c: proof.c().deref().into(), id: proof.id(), } @@ -67,6 +72,7 @@ pub mod mint { use cashu::nuts::nut00::mint::Proof as ProofSdk; + use crate::types::Secret; use crate::Amount; use crate::PublicKey; @@ -84,14 +90,14 @@ pub mod mint { impl Proof { pub fn new( amount: Option>, - secret: String, + secret: Arc, c: Option>, id: Option, ) -> Self { Self { inner: ProofSdk { amount: amount.map(|a| *a.as_ref().deref()), - secret, + secret: secret.as_ref().deref().clone(), c: c.map(|c| c.as_ref().into()), id, }, @@ -102,8 +108,8 @@ pub mod mint { self.inner.amount.map(|a| Arc::new(a.into())) } - pub fn secret(&self) -> String { - self.inner.secret.clone() + pub fn secret(&self) -> Arc { + Arc::new(self.inner.secret.clone().into()) } pub fn c(&self) -> Option> { diff --git a/bindings/cashu-ffi/src/types/mod.rs b/bindings/cashu-ffi/src/types/mod.rs index 03a97470..27a825a3 100644 --- a/bindings/cashu-ffi/src/types/mod.rs +++ b/bindings/cashu-ffi/src/types/mod.rs @@ -1,4 +1,6 @@ pub mod amount; pub mod bolt11_invoice; +pub mod secret; pub use bolt11_invoice::Bolt11Invoice; +pub use secret::Secret; diff --git a/bindings/cashu-ffi/src/types/secret.rs b/bindings/cashu-ffi/src/types/secret.rs new file mode 100644 index 00000000..788028db --- /dev/null +++ b/bindings/cashu-ffi/src/types/secret.rs @@ -0,0 +1,38 @@ +use std::ops::Deref; + +use cashu::secret::Secret as SecretSdk; + +pub struct Secret { + inner: SecretSdk, +} + +impl Deref for Secret { + type Target = SecretSdk; + fn deref(&self) -> &Self::Target { + &self.inner + } +} + +impl Secret { + pub fn new() -> Self { + Self { + inner: SecretSdk::new(), + } + } + + pub fn as_bytes(&self) -> Vec { + self.inner.as_bytes().to_vec() + } +} + +impl From for Secret { + fn from(inner: SecretSdk) -> Secret { + Secret { inner } + } +} + +impl From for SecretSdk { + fn from(secret: Secret) -> SecretSdk { + secret.inner + } +}