mostro_core/lib.rs
1//! # Mostro Core
2//!
3//! `mostro-core` is the foundational library behind [Mostro](https://mostro.network),
4//! a peer-to-peer Bitcoin/Lightning over Nostr marketplace. It contains the
5//! protocol-level data types (orders, disputes, users, ratings and messages)
6//! shared between the Mostro daemon and any client, together with the NIP-59
7//! GiftWrap transport used to exchange them privately.
8//!
9//! ## Overview
10//!
11//! A typical Mostro flow involves two peers (a buyer and a seller) and a
12//! Mostro node that coordinates the trade. All protocol-level communication is
13//! expressed through [`message::Message`] values that travel inside encrypted
14//! NIP-59 envelopes built by [`nip59::wrap_message`]. The receiver uses
15//! [`nip59::unwrap_message`] to recover the original [`message::Message`] and,
16//! optionally, the sender's signature.
17//!
18//! Persistent state (orders, disputes, users) is modelled by the [`order`],
19//! [`dispute`] and [`user`] modules. They can optionally derive the
20//! [`sqlx::FromRow`] and `sqlx_crud::SqlxCrud` traits by enabling the
21//! `sqlx` feature.
22//!
23//! ## Quick start
24//!
25//! The [`prelude`] module re-exports the most commonly used types:
26//!
27//! ```
28//! use mostro_core::prelude::*;
29//!
30//! let order = SmallOrder::new(
31//! None,
32//! Some(Kind::Sell),
33//! Some(Status::Pending),
34//! 100,
35//! "eur".to_string(),
36//! None,
37//! None,
38//! 100,
39//! "SEPA".to_string(),
40//! 1,
41//! None,
42//! None,
43//! None,
44//! None,
45//! None,
46//! );
47//! let message = Message::new_order(None, Some(1), Some(2), Action::NewOrder, Some(Payload::Order(order)));
48//! assert!(message.verify());
49//! ```
50//!
51//! ## Cargo features
52//!
53//! * `wasm` *(default)* — enables `wasm-bindgen` annotations on selected types
54//! so the crate can be used from JavaScript/WebAssembly contexts.
55//! * `sqlx` — derives `FromRow` and `SqlxCrud` for the persistent structs
56//! (`Order`, `User`, `Dispute`, `RestoredOrderHelper`, …). Implies `wasm`.
57//!
58//! ## Module map
59//!
60//! * [`message`] — protocol message envelope, actions and payloads.
61//! * [`order`] — order types, states and helpers.
62//! * [`dispute`] — dispute types and states.
63//! * [`user`] — persistent user representation and rating updates.
64//! * [`rating`] — Nostr-tag-encoded reputation helper.
65//! * [`error`] — unified error taxonomy ([`MostroError`], [`ServiceError`],
66//! [`CantDoReason`]).
67//! * [`nip59`] — GiftWrap wrap/unwrap transport.
68//! * [`prelude`] — convenience re-exports.
69//!
70//! [`MostroError`]: crate::error::MostroError
71//! [`ServiceError`]: crate::error::ServiceError
72//! [`CantDoReason`]: crate::error::CantDoReason
73
74#![doc(html_root_url = "https://docs.rs/mostro-core")]
75#![warn(missing_docs)]
76
77pub mod dispute;
78pub mod error;
79pub mod message;
80pub mod nip59;
81pub mod order;
82pub mod prelude;
83pub mod rating;
84pub mod user;