mirror of
https://github.com/aljazceru/cdk.git
synced 2026-01-02 04:25:27 +01:00
bindings/cashu-sdk use Id type
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user