Skip to main content

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-44
7//! direct 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//! signed, NIP-44 encrypted `kind: 14` events built by
15//! [`transport::wrap_message_with`]. The receiver uses
16//! [`transport::unwrap_incoming`] to recover the original
17//! [`message::Message`], the sender's trade key, its proven identity and,
18//! optionally, the sender's signature.
19//!
20//! Persistent state (orders, disputes, users) is modelled by the [`order`],
21//! [`dispute`] and [`user`] modules. With the `sqlx` feature enabled they
22//! derive [`sqlx::FromRow`]; [`order::Order`] and [`dispute::Dispute`]
23//! also implement [`db::Crud`] for SQLite persistence.
24//!
25//! ## Quick start
26//!
27//! The [`prelude`] module re-exports the most commonly used types:
28//!
29//! ```
30//! use mostro_core::prelude::*;
31//!
32//! let order = SmallOrder::new(
33//!     None,
34//!     Some(Kind::Sell),
35//!     Some(Status::Pending),
36//!     100,
37//!     "eur".to_string(),
38//!     None,
39//!     None,
40//!     100,
41//!     "SEPA".to_string(),
42//!     1,
43//!     None,
44//!     None,
45//!     None,
46//!     None,
47//!     None,
48//! );
49//! let message = Message::new_order(None, Some(1), Some(2), Action::NewOrder, Some(Payload::Order(order)));
50//! assert!(message.verify());
51//! ```
52//!
53//! ## Cargo features
54//!
55//! * `wasm` *(default)* — enables `wasm-bindgen` annotations on selected types
56//!   so the crate can be used from JavaScript/WebAssembly contexts.
57//! * `sqlx` — derives `FromRow` for persistent structs and exposes
58//!   [`db::Crud`] for `Order` and `Dispute`. Implies `wasm`.
59//!
60//! ## Module map
61//!
62//! * [`message`] — protocol message envelope, actions and payloads.
63//! * [`order`] — order types, states and helpers.
64//! * [`dispute`] — dispute types and states.
65//! * [`db`] — SQLite [`Crud`] trait (`sqlx` feature).
66//! * [`user`] — persistent user representation and rating updates.
67//! * [`rating`] — Nostr-tag-encoded reputation helper.
68//! * [`error`] — unified error taxonomy ([`MostroError`], [`ServiceError`],
69//!   [`CantDoReason`]).
70//! * [`transport`] — the protocol v2 NIP-44 direct transport (`kind: 14`)
71//!   and the transport-driven wrap/unwrap dispatchers.
72//! * [`response`] — validation of the responses a client receives.
73//! * [`chat`] — P2P buyer/seller and admin/party chat envelope.
74//! * [`prelude`] — convenience re-exports.
75//!
76//! [`MostroError`]: crate::error::MostroError
77//! [`ServiceError`]: crate::error::ServiceError
78//! [`CantDoReason`]: crate::error::CantDoReason
79
80#![doc(html_root_url = "https://docs.rs/mostro-core")]
81#![warn(missing_docs)]
82
83pub mod chat;
84#[cfg(feature = "sqlx")]
85pub mod db;
86pub mod dispute;
87pub mod error;
88pub mod message;
89pub mod order;
90pub mod prelude;
91pub mod rating;
92pub mod response;
93pub mod transport;
94pub mod user;