Skip to main content

ma_core/
lib.rs

1//! # ma-core
2//!
3//! A lean DIDComm service library for the ma ecosystem.
4//!
5//! `ma-core` provides the building blocks for ma-capable endpoints:
6//!
7//! - **DID documents** — create, validate, resolve, and publish `did:ma:` documents
8//!   to IPFS/IPNS (via Kubo or custom backends).
9//! - **Service inboxes** — bounded, TTL-aware FIFO queues ([`Inbox`])
10//!   for receiving validated messages on named protocol services.
11//! - **Outbox sending** — fire-and-forget delivery of validated [`Message`] objects
12//!   to remote endpoints, serialized to CBOR on the wire ([`Outbox`]).
13//! - **Endpoint abstraction** — the [`MaEndpoint`] trait with an iroh-backed
14//!   implementation ([`IrohEndpoint`], behind the `iroh` feature).
15//! - **Transport parsing** — extract endpoint IDs and protocols from DID document
16//!   service strings (`/iroh/<id>/<protocol>`).
17//! - **Identity bootstrap** — secure secret key generation and persistence.
18//!
19//! ## Services
20//!
21//! Every endpoint must provide `/ma/inbox/0.0.1` (the default inbox).
22//! Endpoints may optionally provide `ma/ipfs/0.0.1` to publish DID documents
23//! on behalf of others.
24//!
25//! ## Feature flags
26//!
27//! - **`kubo`** (default) — enables Kubo RPC client for IPFS publishing.
28//! - **`iroh`** — enables the iroh QUIC transport backend ([`IrohEndpoint`],
29//!   [`Channel`], [`Outbox`]).
30//! - **`gossip`** — enables iroh-gossip broadcast helpers.
31//!
32//! ## Platform support
33//!
34//! Core types (`Inbox`, `Service`, transport parsing, validation)
35//! compile on all targets including `wasm32-unknown-unknown`. Kubo, DID
36//! publishing via Kubo requires a native target.
37
38#![forbid(unsafe_code)]
39
40pub mod endpoint;
41pub mod error;
42#[cfg(feature = "gossip")]
43pub mod gossip;
44pub mod identity;
45pub mod inbox;
46pub mod interfaces;
47pub mod ipfs_publish;
48#[cfg(feature = "iroh")]
49pub mod iroh;
50#[cfg(feature = "iroh")]
51pub mod outbox;
52pub mod resolve;
53pub mod service;
54pub mod topic;
55pub mod transport;
56pub(crate) mod ttl_queue;
57
58#[cfg(all(not(target_arch = "wasm32"), feature = "kubo"))]
59pub mod kubo;
60pub mod pinning;
61
62// ─── Re-export did-ma types so users don't need a separate dependency ───────
63
64pub use did_ma::{
65    Did, Document, EncryptionKey, Headers, MaError, Message, Proof, ReplayGuard, SigningKey,
66    VerificationMethod, DEFAULT_MAX_CLOCK_SKEW_SECS, DEFAULT_MESSAGE_TTL_SECS,
67    DEFAULT_REPLAY_WINDOW_SECS,
68};
69
70// ─── Re-export core error type ──────────────────────────────────────────────
71
72pub use error::{Error, Result};
73
74// ─── Re-export service constants ────────────────────────────────────────────
75
76pub use service::{
77    Service, BROADCAST_PROTOCOL, BROADCAST_TOPIC, CONTENT_TYPE_BROADCAST, CONTENT_TYPE_DOC,
78    CONTENT_TYPE_IPFS_REQUEST, CONTENT_TYPE_MESSAGE, INBOX_PROTOCOL, INBOX_PROTOCOL_ID,
79    IPFS_PROTOCOL,
80};
81
82// ─── Re-export Inbox ────────────────────────────────────────────────────────
83
84pub use inbox::Inbox;
85
86// ─── Re-export Topic ────────────────────────────────────────────────────────
87
88pub use topic::{topic_id, Topic, TopicId};
89
90// ─── Re-export endpoint trait and implementations ───────────────────────────
91
92pub use endpoint::{MaEndpoint, DEFAULT_DELIVERY_PROTOCOL_ID};
93#[cfg(feature = "iroh")]
94pub use iroh::channel::Channel;
95#[cfg(feature = "iroh")]
96pub use iroh::IrohEndpoint;
97#[cfg(feature = "iroh")]
98pub use outbox::Outbox;
99
100// ─── Re-export iroh primitives so dependents don't need a direct iroh dep ───
101
102#[cfg(feature = "iroh")]
103pub use ::iroh::endpoint::{presets, Connection, RecvStream, SendStream};
104#[cfg(feature = "iroh")]
105pub use ::iroh::protocol::{AcceptError, ProtocolHandler, Router};
106#[cfg(feature = "iroh")]
107pub use ::iroh::{Endpoint, EndpointAddr, EndpointId, RelayUrl, SecretKey};
108
109// ─── Re-export gossip helpers ────────────────────────────────────────────────
110
111#[cfg(feature = "gossip")]
112pub use gossip::{
113    broadcast_topic_id, gossip_send, gossip_send_text, join_broadcast_channel, join_gossip_topic,
114    topic_id_for,
115};
116
117// ─── Re-export transport parsing ────────────────────────────────────────────
118
119pub use transport::{
120    endpoint_id_from_transport, endpoint_id_from_transport_value, normalize_endpoint_id,
121    protocol_from_transport, resolve_endpoint_for_protocol, resolve_inbox_endpoint_id,
122    transport_string,
123};
124
125// ─── Re-export identity helpers ─────────────────────────────────────────────
126
127pub use identity::{generate_secret_key_file, load_secret_key_bytes, socket_addr_to_multiaddr};
128
129// ─── Re-export DID resolution ───────────────────────────────────────────────
130
131pub use resolve::DidResolver;
132#[cfg(not(target_arch = "wasm32"))]
133pub use resolve::GatewayResolver;
134
135// ─── Re-export existing modules ─────────────────────────────────────────────
136
137pub use interfaces::{DidPublisher, IpfsPublisher};
138#[cfg(all(not(target_arch = "wasm32"), feature = "kubo"))]
139pub use ipfs_publish::KuboDidPublisher;
140#[cfg(all(not(target_arch = "wasm32"), feature = "kubo"))]
141pub use ipfs_publish::{handle_ipfs_publish, publish_did_document_to_kubo};
142pub use ipfs_publish::{
143    validate_ipfs_publish_request, IpfsPublishDidRequest, IpfsPublishDidResponse,
144    ValidatedIpfsPublish,
145};
146#[cfg(all(not(target_arch = "wasm32"), feature = "kubo"))]
147pub use kubo::KuboKey;
148pub use pinning::{pin_update_add_rm, PinUpdateOutcome};