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. With the `sqlx` feature enabled they
20//! derive [`sqlx::FromRow`]; [`order::Order`] and [`dispute::Dispute`]
21//! also implement [`db::Crud`] for SQLite persistence.
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` for persistent structs and exposes
56//! [`db::Crud`] for `Order` and `Dispute`. 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//! * [`db`] — SQLite [`Crud`] trait (`sqlx` feature).
64//! * [`user`] — persistent user representation and rating updates.
65//! * [`rating`] — Nostr-tag-encoded reputation helper.
66//! * [`error`] — unified error taxonomy ([`MostroError`], [`ServiceError`],
67//! [`CantDoReason`]).
68//! * [`nip59`] — GiftWrap wrap/unwrap transport for protocol messages (v1).
69//! * [`transport`] — transport selection: v1 GiftWrap, v2 NIP-44 direct
70//! (`kind: 14`), and the kind-based dispatch between them.
71//! * [`chat`] — P2P buyer/seller and admin/party chat envelope.
72//! * [`prelude`] — convenience re-exports.
73//!
74//! [`MostroError`]: crate::error::MostroError
75//! [`ServiceError`]: crate::error::ServiceError
76//! [`CantDoReason`]: crate::error::CantDoReason
77
78#![doc(html_root_url = "https://docs.rs/mostro-core")]
79#![warn(missing_docs)]
80
81pub mod chat;
82#[cfg(feature = "sqlx")]
83pub mod db;
84pub mod dispute;
85pub mod error;
86pub mod message;
87pub mod nip59;
88pub mod order;
89pub mod prelude;
90pub mod rating;
91pub mod transport;
92pub mod user;