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`] / [`TtlQueue`])
10//!   for receiving messages on named protocol services.
11//! - **Outbox sending** — fire-and-forget delivery to remote endpoints on any
12//!   registered protocol ([`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//!
31//! ## Platform support
32//!
33//! Core types (`Inbox`, `TtlQueue`, `Service`, transport parsing, validation)
34//! compile on all targets including `wasm32-unknown-unknown`. Kubo, DID
35//! resolution, and iroh require a native target.
36
37#![forbid(unsafe_code)]
38
39pub mod endpoint;
40pub mod error;
41pub mod identity;
42pub mod inbox;
43pub mod interfaces;
44pub mod ipfs_publish;
45#[cfg(all(not(target_arch = "wasm32"), feature = "iroh"))]
46pub mod iroh;
47#[cfg(all(not(target_arch = "wasm32"), feature = "iroh"))]
48pub mod outbox;
49#[cfg(not(target_arch = "wasm32"))]
50pub mod resolve;
51pub mod service;
52pub mod transport;
53pub mod ttl_queue;
54
55#[cfg(all(not(target_arch = "wasm32"), feature = "kubo"))]
56pub mod kubo;
57pub mod pinning;
58
59// ─── Re-export did-ma types so users don't need a separate dependency ───────
60
61pub use did_ma::{
62    Did, Document, EncryptionKey, Headers, MaError, Message, Proof, ReplayGuard, SigningKey,
63    VerificationMethod, DEFAULT_MAX_CLOCK_SKEW_SECS, DEFAULT_MESSAGE_TTL_SECS,
64    DEFAULT_REPLAY_WINDOW_SECS,
65};
66
67// ─── Re-export core error type ──────────────────────────────────────────────
68
69pub use error::{Error, Result};
70
71// ─── Re-export service constants ────────────────────────────────────────────
72
73pub use service::{
74    Service, BROADCAST_PROTOCOL, BROADCAST_TOPIC, CONTENT_TYPE_BROADCAST, CONTENT_TYPE_CHAT,
75    CONTENT_TYPE_EVENT, CONTENT_TYPE_MESSAGE, CONTENT_TYPE_PRESENCE, CONTENT_TYPE_WHISPER,
76    CONTENT_TYPE_WORLD, DEFAULT_CONTENT_TYPE, INBOX_PROTOCOL, IPFS_PROTOCOL,
77};
78
79// ─── Re-export TtlQueue ─────────────────────────────────────────────────────
80
81pub use ttl_queue::TtlQueue;
82
83// ─── Re-export Inbox ────────────────────────────────────────────────────────
84
85pub use inbox::Inbox;
86
87// ─── Re-export endpoint trait and implementations ───────────────────────────
88
89pub use endpoint::{MaEndpoint, DEFAULT_DELIVERY_PROTOCOL_ID};
90#[cfg(all(not(target_arch = "wasm32"), feature = "iroh"))]
91pub use iroh::channel::Channel;
92#[cfg(all(not(target_arch = "wasm32"), feature = "iroh"))]
93pub use iroh::IrohEndpoint;
94#[cfg(all(not(target_arch = "wasm32"), feature = "iroh"))]
95pub use outbox::Outbox;
96
97// ─── Re-export transport parsing ────────────────────────────────────────────
98
99pub use transport::{
100    endpoint_id_from_transport, endpoint_id_from_transport_value, normalize_endpoint_id,
101    protocol_from_transport, resolve_endpoint_for_protocol, resolve_inbox_endpoint_id,
102    transport_string,
103};
104
105// ─── Re-export identity helpers ─────────────────────────────────────────────
106
107pub use identity::{generate_secret_key_file, load_secret_key_bytes, socket_addr_to_multiaddr};
108
109// ─── Re-export DID resolution ───────────────────────────────────────────────
110
111#[cfg(not(target_arch = "wasm32"))]
112pub use resolve::{DidResolver, GatewayResolver};
113
114// ─── Re-export existing modules ─────────────────────────────────────────────
115
116pub use interfaces::{DidPublisher, IpfsPublisher};
117#[cfg(all(not(target_arch = "wasm32"), feature = "kubo"))]
118pub use ipfs_publish::KuboDidPublisher;
119#[cfg(all(not(target_arch = "wasm32"), feature = "kubo"))]
120pub use ipfs_publish::{handle_ipfs_publish, publish_did_document_to_kubo};
121pub use ipfs_publish::{
122    validate_ipfs_publish_request, IpfsPublishDidRequest, IpfsPublishDidResponse,
123    ValidatedIpfsPublish, CONTENT_TYPE_DOC,
124};
125#[cfg(all(not(target_arch = "wasm32"), feature = "kubo"))]
126pub use kubo::KuboKey;
127pub use pinning::{pin_update_add_rm, PinUpdateOutcome};