Skip to main content

Crate mostro_core

Crate mostro_core 

Source
Expand description

§Mostro Core

mostro-core is the foundational library behind Mostro, a peer-to-peer Bitcoin/Lightning over Nostr marketplace. It contains the protocol-level data types (orders, disputes, users, ratings and messages) shared between the Mostro daemon and any client, together with the NIP-59 GiftWrap transport used to exchange them privately.

§Overview

A typical Mostro flow involves two peers (a buyer and a seller) and a Mostro node that coordinates the trade. All protocol-level communication is expressed through message::Message values that travel inside encrypted NIP-59 envelopes built by nip59::wrap_message. The receiver uses nip59::unwrap_message to recover the original message::Message and, optionally, the sender’s signature.

Persistent state (orders, disputes, users) is modelled by the order, dispute and user modules. They can optionally derive the [sqlx::FromRow] and sqlx_crud::SqlxCrud traits by enabling the sqlx feature.

§Quick start

The prelude module re-exports the most commonly used types:

use mostro_core::prelude::*;

let order = SmallOrder::new(
    None,
    Some(Kind::Sell),
    Some(Status::Pending),
    100,
    "eur".to_string(),
    None,
    None,
    100,
    "SEPA".to_string(),
    1,
    None,
    None,
    None,
    None,
    None,
);
let message = Message::new_order(None, Some(1), Some(2), Action::NewOrder, Some(Payload::Order(order)));
assert!(message.verify());

§Cargo features

  • wasm (default) — enables wasm-bindgen annotations on selected types so the crate can be used from JavaScript/WebAssembly contexts.
  • sqlx — derives FromRow and SqlxCrud for the persistent structs (Order, User, Dispute, RestoredOrderHelper, …). Implies wasm.

§Module map

  • message — protocol message envelope, actions and payloads.
  • order — order types, states and helpers.
  • dispute — dispute types and states.
  • user — persistent user representation and rating updates.
  • rating — Nostr-tag-encoded reputation helper.
  • error — unified error taxonomy (MostroError, ServiceError, CantDoReason).
  • nip59 — GiftWrap wrap/unwrap transport.
  • prelude — convenience re-exports.

Modules§

dispute
Dispute representation and lifecycle states.
error
Error taxonomy used across the crate.
message
Protocol message envelope exchanged between clients and a Mostro node.
nip59
NIP-59 GiftWrap transport for Mostro messages.
order
Orders and their lifecycle.
prelude
Convenience re-exports and shared constants.
rating
Encoding of user reputation as Nostr event tags.
user
Persistent user representation and reputation helpers.