diff --git a/moksha-core/src/blind.rs b/moksha-core/src/blind.rs index ac8f6f06..591aa345 100644 --- a/moksha-core/src/blind.rs +++ b/moksha-core/src/blind.rs @@ -10,6 +10,7 @@ use secp256k1::{PublicKey, SecretKey}; use serde::{Deserialize, Serialize}; +use utoipa::ToSchema; use crate::{ amount::{generate_random_string, Amount}, @@ -17,18 +18,20 @@ use crate::{ error::MokshaCoreError, }; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct BlindedSignature { pub amount: u64, #[serde(rename = "C_")] + #[schema(value_type=String)] pub c_: PublicKey, pub id: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct BlindedMessage { pub amount: u64, #[serde(rename = "B_")] + #[schema(value_type=String)] pub b_: PublicKey, } diff --git a/moksha-core/src/primitives.rs b/moksha-core/src/primitives.rs index a457bf70..b3916270 100644 --- a/moksha-core/src/primitives.rs +++ b/moksha-core/src/primitives.rs @@ -144,13 +144,13 @@ pub enum PaymentMethod { Bolt11, } -#[derive(Deserialize, Serialize, Debug, Clone)] +#[derive(Deserialize, Serialize, Debug, Clone, ToSchema)] pub struct PostMintQuoteBolt11Request { pub amount: u64, pub unit: CurrencyUnit, } -#[derive(Deserialize, Serialize, Debug, Clone)] +#[derive(Deserialize, Serialize, Debug, Clone, ToSchema)] pub struct PostMintQuoteBolt11Response { pub quote: String, #[serde(rename = "request")] @@ -179,25 +179,25 @@ impl TryFrom for PostMintQuoteBolt11Response { } } -#[derive(Deserialize, Serialize, Debug, Clone)] +#[derive(Deserialize, Serialize, Debug, Clone, ToSchema)] pub struct PostMintBolt11Request { pub quote: String, pub outputs: Vec, } -#[derive(Deserialize, Serialize, Debug, Clone)] +#[derive(Deserialize, Serialize, Debug, Clone, ToSchema)] pub struct PostMintBolt11Response { pub signatures: Vec, } -#[derive(Deserialize, Serialize, Debug, Clone)] +#[derive(Deserialize, Serialize, Debug, Clone, ToSchema)] pub struct PostMeltQuoteBolt11Request { /// payment request pub request: String, pub unit: CurrencyUnit, } -#[derive(Deserialize, Serialize, Debug, Clone)] +#[derive(Deserialize, Serialize, Debug, Clone, ToSchema)] pub struct PostMeltQuoteBolt11Response { pub quote: String, pub amount: u64, @@ -247,14 +247,14 @@ impl TryFrom for PostMeltQuoteBolt11Response { } } -#[derive(Deserialize, Serialize, Debug, Clone)] +#[derive(Deserialize, Serialize, Debug, Clone, ToSchema)] pub struct PostMeltBolt11Request { pub quote: String, pub inputs: Proofs, pub outputs: Vec, } -#[derive(Deserialize, Serialize, Debug, Clone)] +#[derive(Deserialize, Serialize, Debug, Clone, ToSchema)] pub struct PostMeltBolt11Response { pub paid: bool, pub payment_preimage: String, diff --git a/moksha-core/src/proof.rs b/moksha-core/src/proof.rs index 60ebd22c..f8eea993 100644 --- a/moksha-core/src/proof.rs +++ b/moksha-core/src/proof.rs @@ -13,15 +13,17 @@ use secp256k1::PublicKey; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; +use utoipa::ToSchema; use crate::error::MokshaCoreError; #[skip_serializing_none] -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, ToSchema)] pub struct Proof { pub amount: u64, pub secret: String, #[serde(rename = "C")] + #[schema(value_type=String)] pub c: PublicKey, pub id: String, // FIXME use keysetID as specific type / consider making this non optional and brake backwards compatibility pub script: Option, @@ -42,7 +44,7 @@ impl Proof { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct P2SHScript; -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, ToSchema)] pub struct Proofs(pub(super) Vec); impl Proofs { diff --git a/moksha-mint/src/server.rs b/moksha-mint/src/server.rs index 905a76ff..793d1832 100644 --- a/moksha-mint/src/server.rs +++ b/moksha-mint/src/server.rs @@ -11,11 +11,14 @@ use axum::routing::{get_service, post}; use axum::{middleware, Router}; use axum::{routing::get, Json}; use moksha_core::keyset::{generate_hash, Keysets, V1Keyset, V1Keysets}; +use moksha_core::proof::Proofs; use utoipa_swagger_ui::SwaggerUi; use uuid::Uuid; use crate::mint::Mint; use crate::model::{GetMintQuery, PostMintQuery}; +use moksha_core::blind::BlindedMessage; +use moksha_core::blind::BlindedSignature; use moksha_core::primitives::{ CheckFeesRequest, CheckFeesResponse, CurrencyUnit, KeyResponse, KeysResponse, MintInfoNut, MintInfoResponse, MintLegacyInfoResponse, PaymentMethod, PaymentRequest, PostMeltBolt11Request, @@ -78,7 +81,16 @@ pub async fn run_server( #[derive(OpenApi)] #[openapi( - paths(get_info, get_keys, get_keys_by_id, get_keysets), + paths( + get_keys, + get_keys_by_id, + get_keysets, + post_mint_bolt11, + post_mint_quote_bolt11, + get_mint_quote_bolt11, + post_melt_bolt11, + get_info, + ), components(schemas( MintInfoResponse, MintInfoNut, @@ -87,7 +99,18 @@ pub async fn run_server( KeysResponse, KeyResponse, V1Keysets, - V1Keyset + V1Keyset, + BlindedMessage, + BlindedSignature, + Proofs, + PostMintQuoteBolt11Request, + PostMintQuoteBolt11Response, + PostMeltQuoteBolt11Request, + PostMeltQuoteBolt11Response, + PostMeltBolt11Request, + PostMeltBolt11Response, + PostMintBolt11Request, + PostMintBolt11Response, )) )] struct ApiDoc; @@ -358,6 +381,14 @@ async fn get_keysets(State(mint): State) -> Result, Moksha ))) } +#[utoipa::path( + post, + path = "/v1/mint/quote/bolt11", + request_body = PostMintQuoteBolt11Request, + responses( + (status = 200, description = "post mint quote", body = [PostMintQuoteBolt11Response]) + ), + )] async fn post_mint_quote_bolt11( State(mint): State, Json(request): Json, @@ -385,6 +416,17 @@ async fn post_mint_quote_bolt11( })) } +#[utoipa::path( + post, + path = "/v1/mint/bolt11/{quote_id}", + request_body = PostMintBolt11Request, + responses( + (status = 200, description = "post mint quote", body = [PostMintBolt11Response]) + ), + params( + ("quote_id" = String, Path, description = "quote id"), + ) + )] async fn post_mint_bolt11( State(mint): State, Json(request): Json, @@ -407,6 +449,14 @@ async fn post_mint_bolt11( } } +#[utoipa::path( + post, + path = "/v1/melt/quote/bolt11/{quote}", + request_body = PostMeltQuoteBolt11Request, + responses( + (status = 200, description = "post mint quote", body = [PostMeltQuoteBolt11Response]) + ), + )] async fn post_melt_quote_bolt11( State(mint): State, Json(melt_request): Json, @@ -438,6 +488,17 @@ async fn post_melt_quote_bolt11( })?)) } +#[utoipa::path( + post, + path = "/v1/melt/bolt11/{quote_id}", + request_body = PostMeltBolt11Request, + responses( + (status = 200, description = "post melt", body = [PostMeltBolt11Response]) + ), + params( + ("quote_id" = String, Path, description = "quote id"), + ) + )] async fn post_melt_bolt11( State(mint): State, Json(melt_request): Json, @@ -485,6 +546,16 @@ async fn post_melt_bolt11( } } +#[utoipa::path( + get, + path = "/v1/mint/quote/bolt11/{quote_id}", + responses( + (status = 200, description = "get mint quote by id", body = [PostMintQuoteBolt11Response]) + ), + params( + ("quote_id" = String, Path, description = "quote id"), + ) + )] async fn get_mint_quote_bolt11( Path(quote_id): Path, State(mint): State,