Skip to content

Commit

Permalink
cdk: place utoipa dependency behind mint feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ok300 committed Oct 6, 2024
1 parent 218083d commit 17ec033
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 32 deletions.
4 changes: 2 additions & 2 deletions crates/cdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ license = "MIT"

[features]
default = ["mint", "wallet"]
mint = ["dep:futures"]
mint = ["dep:futures", "dep:utoipa"]
wallet = ["dep:reqwest"]
bench = []

Expand All @@ -39,7 +39,7 @@ tracing = { version = "0.1", default-features = false, features = ["attributes",
thiserror = "1"
futures = { version = "0.3.28", default-features = false, optional = true }
url = "2.3"
utoipa = { version = "4.1.0" }
utoipa = { version = "4.1.0", optional = true}
uuid = { version = "1", features = ["v4"] }

# -Z minimal-versions
Expand Down
6 changes: 3 additions & 3 deletions crates/cdk/src/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::fmt;

use serde::{Deserialize, Serialize};
use thiserror::Error;
#[cfg(feature = "mint")]
use utoipa::ToSchema;

use crate::nuts::CurrencyUnit;
Expand All @@ -26,9 +27,8 @@ pub enum Error {
}

/// Amount can be any unit
#[derive(
Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize, ToSchema,
)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[cfg_attr(feature = "mint", derive(ToSchema))]
#[serde(transparent)]
pub struct Amount(u64);

Expand Down
7 changes: 5 additions & 2 deletions crates/cdk/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::fmt;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_json::Value;
use thiserror::Error;
#[cfg(feature = "mint")]
use utoipa::ToSchema;

#[cfg(feature = "wallet")]
Expand Down Expand Up @@ -244,7 +245,8 @@ pub enum Error {
/// CDK Error Response
///
/// See NUT definition in [00](https://github.com/cashubtc/nuts/blob/main/00.md)
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "mint", derive(ToSchema))]
pub struct ErrorResponse {
/// Error Code
pub code: ErrorCode,
Expand Down Expand Up @@ -399,7 +401,8 @@ impl From<ErrorResponse> for Error {
}

/// Possible Error Codes
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, ToSchema)]
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
#[cfg_attr(feature = "mint", derive(ToSchema))]
pub enum ErrorCode {
/// Token is already spent
TokenAlreadySpent,
Expand Down
7 changes: 5 additions & 2 deletions crates/cdk/src/nuts/nut00/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::string::FromUtf8Error;

use serde::{de, Deserialize, Deserializer, Serialize};
use thiserror::Error;
#[cfg(feature = "mint")]
use utoipa::ToSchema;

use super::nut10;
Expand Down Expand Up @@ -338,7 +339,8 @@ where

/// Currency Unit
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default, ToSchema)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
#[cfg_attr(feature = "mint", derive(ToSchema))]
pub enum CurrencyUnit {
/// Sat
#[default]
Expand Down Expand Up @@ -409,7 +411,8 @@ impl<'de> Deserialize<'de> for CurrencyUnit {

/// Payment Method
#[non_exhaustive]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, ToSchema)]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "mint", derive(ToSchema))]
pub enum PaymentMethod {
/// Bolt11 payment type
#[default]
Expand Down
7 changes: 5 additions & 2 deletions crates/cdk/src/nuts/nut01/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use bitcoin::secp256k1;
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, VecSkipError};
use thiserror::Error;
#[cfg(feature = "mint")]
use utoipa::ToSchema;

mod public_key;
Expand Down Expand Up @@ -39,7 +40,8 @@ pub enum Error {
}

/// Mint Keys [NUT-01]
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, ToSchema)]
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[cfg_attr(feature = "mint", derive(ToSchema))]
pub struct Keys(BTreeMap<String, PublicKey>);

impl From<MintKeys> for Keys {
Expand Down Expand Up @@ -81,7 +83,8 @@ impl Keys {

/// Mint Public Keys [NUT-01]
#[serde_as]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "mint", derive(ToSchema))]
pub struct KeysResponse {
/// Keysets
#[serde_as(as = "VecSkipError<_>")]
Expand Down
6 changes: 4 additions & 2 deletions crates/cdk/src/nuts/nut01/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ use bitcoin::hashes::Hash;
use bitcoin::secp256k1::schnorr::Signature;
use bitcoin::secp256k1::{self, Message, XOnlyPublicKey};
use serde::{Deserialize, Deserializer, Serialize};
#[cfg(feature = "mint")]
use utoipa::ToSchema;

use super::Error;
use crate::SECP256K1;

/// PublicKey
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, ToSchema)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "mint", derive(ToSchema))]
pub struct PublicKey {
#[schema(value_type = String)]
#[cfg_attr(feature = "mint", schema(value_type = String))]
inner: secp256k1::PublicKey,
}

Expand Down
16 changes: 11 additions & 5 deletions crates/cdk/src/nuts/nut02.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use bitcoin::secp256k1;
use serde::{Deserialize, Deserializer, Serialize};
use serde_with::{serde_as, VecSkipError};
use thiserror::Error;
#[cfg(feature = "mint")]
use utoipa::ToSchema;

use super::nut01::Keys;
Expand Down Expand Up @@ -49,7 +50,8 @@ pub enum Error {
}

/// Keyset version
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, ToSchema)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "mint", derive(ToSchema))]
pub enum KeySetVersion {
/// Current Version 00
Version00,
Expand Down Expand Up @@ -84,7 +86,8 @@ impl fmt::Display for KeySetVersion {
/// anyone who knows the set of public keys of a mint. The keyset ID **CAN**
/// be stored in a Cashu token such that the token can be used to identify
/// which mint or keyset it was generated from.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, ToSchema)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "mint", derive(ToSchema))]
pub struct Id {
version: KeySetVersion,
id: [u8; Self::BYTELEN],
Expand Down Expand Up @@ -224,15 +227,17 @@ impl From<&Keys> for Id {
/// Mint Keysets [NUT-02]
/// Ids of mints keyset ids
#[serde_as]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "mint", derive(ToSchema))]
pub struct KeysetResponse {
/// set of public key ids that the mint generates
#[serde_as(as = "VecSkipError<_>")]
pub keysets: Vec<KeySetInfo>,
}

/// Keyset
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, ToSchema)]
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[cfg_attr(feature = "mint", derive(ToSchema))]
pub struct KeySet {
/// Keyset [`Id`]
pub id: Id,
Expand All @@ -254,7 +259,8 @@ impl From<MintKeySet> for KeySet {
}

/// KeySetInfo
#[derive(Debug, Clone, Hash, PartialEq, Eq, Deserialize, Serialize, ToSchema)]
#[derive(Debug, Clone, Hash, PartialEq, Eq, Deserialize, Serialize)]
#[cfg_attr(feature = "mint", derive(ToSchema))]
pub struct KeySetInfo {
/// Keyset [`Id`]
pub id: Id,
Expand Down
8 changes: 5 additions & 3 deletions crates/cdk/src/nuts/nut04.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::str::FromStr;
use serde::{Deserialize, Deserializer, Serialize};
use serde_json::Value;
use thiserror::Error;
#[cfg(feature = "mint")]
use utoipa::ToSchema;

use super::nut00::{BlindSignature, BlindedMessage, CurrencyUnit, PaymentMethod};
Expand Down Expand Up @@ -203,7 +204,8 @@ pub struct MintBolt11Response {
}

/// Mint Method Settings
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, ToSchema)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "mint", derive(ToSchema))]
pub struct MintMethodSettings {
/// Payment Method e.g. bolt11
pub method: PaymentMethod,
Expand All @@ -221,8 +223,8 @@ pub struct MintMethodSettings {
}

/// Mint Settings
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, ToSchema)]
#[schema(as = nut04::Settings)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "mint", derive(ToSchema), schema(as = nut04::Settings))]
pub struct Settings {
/// Methods to mint
pub methods: Vec<MintMethodSettings>,
Expand Down
8 changes: 5 additions & 3 deletions crates/cdk/src/nuts/nut05.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::str::FromStr;
use serde::{Deserialize, Deserializer, Serialize};
use serde_json::Value;
use thiserror::Error;
#[cfg(feature = "mint")]
use utoipa::ToSchema;

use super::nut00::{BlindSignature, BlindedMessage, CurrencyUnit, PaymentMethod, Proofs};
Expand Down Expand Up @@ -229,7 +230,8 @@ impl MeltBolt11Request {
}

/// Melt Method Settings
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, ToSchema)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "mint", derive(ToSchema))]
pub struct MeltMethodSettings {
/// Payment Method e.g. bolt11
pub method: PaymentMethod,
Expand Down Expand Up @@ -266,8 +268,8 @@ impl Settings {
}

/// Melt Settings
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, ToSchema)]
#[schema(as = nut05::Settings)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "mint", derive(ToSchema), schema(as = nut05::Settings))]
pub struct Settings {
/// Methods to melt
pub methods: Vec<MeltMethodSettings>,
Expand Down
16 changes: 11 additions & 5 deletions crates/cdk/src/nuts/nut06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
//! <https://github.com/cashubtc/nuts/blob/main/06.md>
use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[cfg(feature = "mint")]
use utoipa::ToSchema;

use super::nut01::PublicKey;
use super::{nut04, nut05, nut15, MppMethodSettings};

/// Mint Version
#[derive(Debug, Clone, PartialEq, Eq, Hash, ToSchema)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "mint", derive(ToSchema))]
pub struct MintVersion {
/// Mint Software name
pub name: String,
Expand Down Expand Up @@ -52,7 +54,8 @@ impl<'de> Deserialize<'de> for MintVersion {
}

/// Mint Info [NIP-06]
#[derive(Default, Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, ToSchema)]
#[derive(Default, Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "mint", derive(ToSchema))]
pub struct MintInfo {
/// name of the mint and should be recognizable
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -188,7 +191,8 @@ impl MintInfo {
}

/// Supported nuts and settings
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, ToSchema)]
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "mint", derive(ToSchema))]
pub struct Nuts {
/// NUT04 Settings
#[serde(default)]
Expand Down Expand Up @@ -322,13 +326,15 @@ impl Nuts {
}

/// Check state Settings
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash, Serialize, Deserialize, ToSchema)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "mint", derive(ToSchema))]
pub struct SupportedSettings {
supported: bool,
}

/// Contact Info
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, ToSchema)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "mint", derive(ToSchema))]
pub struct ContactInfo {
/// Contact Method i.e. nostr
pub method: String,
Expand Down
8 changes: 5 additions & 3 deletions crates/cdk/src/nuts/nut15.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! <https://github.com/cashubtc/nuts/blob/main/15.md>
use serde::{Deserialize, Serialize};
#[cfg(feature = "mint")]
use utoipa::ToSchema;

use super::{CurrencyUnit, PaymentMethod};
Expand All @@ -17,7 +18,8 @@ pub struct Mpp {
}

/// Mpp Method Settings
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, ToSchema)]
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "mint", derive(ToSchema))]
pub struct MppMethodSettings {
/// Payment Method e.g. bolt11
pub method: PaymentMethod,
Expand All @@ -28,8 +30,8 @@ pub struct MppMethodSettings {
}

/// Mpp Settings
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, ToSchema)]
#[schema(as = nut15::Settings)]
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "mint", derive(ToSchema), schema(as = nut15::Settings))]
pub struct Settings {
/// Method settings
pub methods: Vec<MppMethodSettings>,
Expand Down

0 comments on commit 17ec033

Please sign in to comment.