mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-25 08:35:09 +01:00
bindings/cashu improve: use secret type
This commit is contained in:
@@ -22,6 +22,11 @@ interface Amount {
|
||||
sequence<Amount> split();
|
||||
};
|
||||
|
||||
interface Secret {
|
||||
constructor();
|
||||
sequence<u8> 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<BlindedMessage> blinded_messages();
|
||||
sequence<string> secrets();
|
||||
sequence<Secret> secrets();
|
||||
sequence<SecretKey> rs();
|
||||
sequence<Amount> amounts();
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<String> {
|
||||
self.inner.secrets.clone()
|
||||
pub fn secrets(&self) -> Vec<Arc<Secret>> {
|
||||
self.inner
|
||||
.secrets
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|s| Arc::new(s.into()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn rs(&self) -> Vec<Arc<SecretKey>> {
|
||||
|
||||
@@ -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<Amount>, secret: String, c: Arc<PublicKey>, id: Option<String>) -> Self {
|
||||
pub fn new(
|
||||
amount: Arc<Amount>,
|
||||
secret: Arc<Secret>,
|
||||
c: Arc<PublicKey>,
|
||||
id: Option<String>,
|
||||
) -> 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<Secret> {
|
||||
Arc::new(self.inner.secret.clone().into())
|
||||
}
|
||||
|
||||
pub fn c(&self) -> Arc<PublicKey> {
|
||||
@@ -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<Arc<Amount>>,
|
||||
secret: String,
|
||||
secret: Arc<Secret>,
|
||||
c: Option<Arc<PublicKey>>,
|
||||
id: Option<String>,
|
||||
) -> 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<Secret> {
|
||||
Arc::new(self.inner.secret.clone().into())
|
||||
}
|
||||
|
||||
pub fn c(&self) -> Option<Arc<PublicKey>> {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
pub mod amount;
|
||||
pub mod bolt11_invoice;
|
||||
pub mod secret;
|
||||
|
||||
pub use bolt11_invoice::Bolt11Invoice;
|
||||
pub use secret::Secret;
|
||||
|
||||
38
bindings/cashu-ffi/src/types/secret.rs
Normal file
38
bindings/cashu-ffi/src/types/secret.rs
Normal file
@@ -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<u8> {
|
||||
self.inner.as_bytes().to_vec()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SecretSdk> for Secret {
|
||||
fn from(inner: SecretSdk) -> Secret {
|
||||
Secret { inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Secret> for SecretSdk {
|
||||
fn from(secret: Secret) -> SecretSdk {
|
||||
secret.inner
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user