bindings/cashu-sdk use Id type

This commit is contained in:
thesimplekid
2023-09-09 13:18:22 +01:00
parent 9343f95f2b
commit 85d0db95ce
3 changed files with 29 additions and 18 deletions

View File

@@ -31,6 +31,11 @@ interface Secret {
sequence<u8> as_bytes();
};
interface Id {
[Throws=CashuError]
constructor(string id);
};
interface PublicKey {
[Throws=CashuError, Name=from_hex]
constructor(string hex);
@@ -51,26 +56,26 @@ interface BlindedMessage {
};
interface Proof {
constructor(Amount amount, Secret secret, PublicKey c, string? id);
constructor(Amount amount, Secret secret, PublicKey c, Id? id);
Amount amount();
Secret secret();
PublicKey c();
string? id();
Id? id();
};
interface BlindedSignature {
constructor(string id, Amount amount, PublicKey c);
string id();
constructor(Id id, Amount amount, PublicKey c);
Id id();
Amount amount();
PublicKey c();
};
interface MintProof {
constructor(Amount? amount, Secret secret, PublicKey? c, string? id);
constructor(Amount? amount, Secret secret, PublicKey? c, Id? id);
Amount? amount();
Secret secret();
PublicKey? c();
string? id();
Id? id();
};
@@ -119,8 +124,8 @@ interface Keys {
};
interface KeySet {
constructor(string id, Keys keys);
string id();
constructor(Id id, Keys keys);
Id id();
Keys keys();
};
@@ -131,8 +136,8 @@ interface MintKeySet {
};
interface KeySetResponse {
constructor(sequence<string> keyset_ids);
sequence<string> keyset_ids();
constructor(sequence<Id> keyset_ids);
sequence<Id> keyset_ids();
};
interface RequestMintResponse {
@@ -319,11 +324,12 @@ interface Wallet {
interface Mint {
[Throws=CashuSdkError]
constructor(string secret, string derivation_path, record<string, MintKeySet> inactive_keysets, sequence<Secret> spent_secrets, u8 max_order);
KeySet active_keyset_pubkeys();
KeySetResponse keysets();
MintKeySet active_keyset();
KeySet? keyset(string id);
KeySet? keyset(Id id);
[Throws=CashuSdkError]
PostMintResponse process_mint_request(MintRequest mint_request);
[Throws=CashuSdkError]

View File

@@ -7,7 +7,7 @@ mod wallet;
mod ffi {
pub use cashu_ffi::{
Amount, BlindedMessage, BlindedMessages, BlindedSignature, Bolt11Invoice, CashuError,
CheckFeesRequest, CheckFeesResponse, CheckSpendableRequest, CheckSpendableResponse,
CheckFeesRequest, CheckFeesResponse, CheckSpendableRequest, CheckSpendableResponse, Id,
InvoiceStatus, KeyPair, KeySet, KeySetResponse, Keys, MeltRequest, MeltResponse, MintInfo,
MintKeySet, MintProof, MintProofs, MintRequest, MintVersion, Nut05MeltRequest,
Nut05MeltResponse, PostMintResponse, Proof, PublicKey, RequestMintResponse, Secret,

View File

@@ -6,9 +6,11 @@ use std::{
use cashu_sdk::mint::Mint as MintSdk;
use cashu_sdk::nuts::nut02::Id as IdSdk;
use crate::error::Result;
use cashu_ffi::{
Amount, CheckSpendableRequest, CheckSpendableResponse, KeySet, KeySetResponse, MeltRequest,
Amount, CheckSpendableRequest, CheckSpendableResponse, Id, KeySet, KeySetResponse, MeltRequest,
MeltResponse, MintKeySet, MintRequest, PostMintResponse, Proof, Secret, SplitRequest,
SplitResponse,
};
@@ -24,7 +26,7 @@ impl Mint {
inactive_keysets: HashMap<String, Arc<MintKeySet>>,
spent_secrets: Vec<Arc<Secret>>,
max_order: u8,
) -> Self {
) -> Result<Self> {
let spent_secrets = spent_secrets
.into_iter()
.map(|s| s.as_ref().deref().clone())
@@ -32,10 +34,13 @@ impl Mint {
let inactive_keysets = inactive_keysets
.into_iter()
.map(|(k, v)| (k, v.as_ref().deref().clone()))
.flat_map(|(k, v)| {
let id = IdSdk::try_from_base64(&k);
id.map(|id| (id, v.as_ref().deref().clone()))
})
.collect();
Self {
Ok(Self {
inner: MintSdk::new(
&secret,
&derivation_path,
@@ -44,7 +49,7 @@ impl Mint {
max_order,
)
.into(),
}
})
}
pub fn active_keyset_pubkeys(&self) -> Arc<KeySet> {
@@ -59,7 +64,7 @@ impl Mint {
Arc::new(self.inner.read().unwrap().active_keyset.clone().into())
}
pub fn keyset(&self, id: String) -> Option<Arc<KeySet>> {
pub fn keyset(&self, id: Arc<Id>) -> Option<Arc<KeySet>> {
self.inner
.read()
.unwrap()