1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
//! A Matter implementation in Rust: one crate, `no_std`, no allocation, and no runtime of
//! its own.
//!
//! [Matter](https://csa-iot.org/all-solutions/matter/) is the CSA's smart-home standard —
//! the protocol behind Apple Home, Google Home, Alexa and SmartThings. This crate targets
//! **specification 1.6** (approved 2026-06-16) and is built to be *certifiable* rather
//! than merely interoperable: the same data model the certification Test Harness reads is
//! the data model this crate is generated from.
//!
//! # Status
//!
//! Under construction and pre-1.0. A device can be commissioned into a fabric end to end — over
//! IPv6, BLE, Wi-Fi PAF or NFC — answer Reads, Writes and Invokes against a `const` data model,
//! hold subscriptions, enforce §6.6's access control, take part in groupcast, move a firmware
//! image over BDX and advertise itself over DNS-SD, with [`messaging`] composing the layers so
//! that a datagram finds its session, exchange and protocol. The CHIP SDK's own `chip-tool`
//! commissions the `light` example through the whole of §5.5, and eleven of the CSA Test
//! Harness's certification cases pass against it.
//!
//! What is missing is most of the application clusters' *behaviour* behind the generated
//! descriptors, and the facades — `Node::builder`, `Controller` — that would turn the examples'
//! hand-assembly into three lines. The
//! [README](https://github.com/hupe1980/matter-kit#status) carries the layer-by-layer table;
//! each module here states which sections it implements.
//!
//! # Three things that shape the whole crate
//!
//! **A capacity is declared once, and the specification checks it.** Every table in the stack
//! — fabrics, sessions, exchanges, subscriptions, access-control entries — is a fixed-capacity
//! array whose length is its own const parameter, and each one carries a `const` assertion that
//! the length can keep the promises [`Config`] makes to each fabric. A node that could not pass
//! certification does not compile, and the failing rule is named in the build error. Two
//! libraries in one binary cannot fight over it the way they fight over a Cargo feature.
//!
//! ```compile_fail
//! use matter_kit::{Config, DefaultConfig, acl::Acl};
//!
//! // Core §2.11.1.1 wants four access-control entries for each of five fabrics.
//! let too_small: Acl<DefaultConfig, 4, 4, 3> = Acl::new();
//! ```
//!
//! ```
//! use matter_kit::{Capacity, Config, DefaultConfig, acl::Acl};
//!
//! // The defaults are the specification's own minima, so naming none of them is conformant.
//! let acl: Acl<DefaultConfig> = Acl::new();
//! assert_eq!(<Acl<DefaultConfig> as Capacity>::PER_FABRIC, DefaultConfig::ACL_ENTRIES_PER_FABRIC);
//! ```
//!
//! **No runtime is chosen for you.** The crate is `async` over [`core::future`] and talks
//! to the outside world through the traits in [`platform`]: sockets, timers, randomness,
//! storage, cryptography. No executor crate is in the dependency tree at all; `examples/`
//! run on a `block_on` of their own. One consequence worth having: every timeout in the
//! specification — MRP backoff, the fail-safe, an intermittently-connected device's idle
//! period — is driven by a [`platform::Timer`], so [`platform::sim`] runs an hour-long
//! scenario in microseconds.
//!
//! **Nothing panics on network input.** `unwrap`, `expect`, `panic!` and slice indexing
//! are denied crate-wide; every parser returns [`Error`]. Resource exhaustion is a value
//! ([`ErrorCode::NoSpace`], [`ErrorCode::Busy`]), so a device that runs out of exchanges
//! answers rather than aborts.
//!
//! # Commissioning, in miniature
//!
//! The whole of PASE: a printed passcode becomes three shared keys, without the passcode
//! ever crossing the wire. Needs the `rustcrypto` feature, which is on by default.
//!
//! The salt and iteration count below are the CHIP test vectors, so that this example is the
//! protocol and nothing else. A product's are neither: §3.9 allows 1 000 to 100 000 iterations
//! and the floor is what an offline attack on leaked verifier material is priced at, and a salt
//! shared between devices shares its pre-computation with all of them. Draw the salt per device
//! at manufacture and put the iteration count well above the minimum — `examples/light` does
//! both.
//!
//! ```
//! # #[cfg(feature = "rustcrypto")]
//! # fn demo() -> Result<(), matter_kit::Error> {
//! use matter_kit::crypto::Spake2pVerifierData;
//! use matter_kit::msg::SessionId;
//! use matter_kit::sc::{PaseInitiator, PaseResponder, PbkdfParameters, ResponderConfig};
//!
//! // What a factory burns into the device. The passcode itself is never stored.
//! let parameters = PbkdfParameters::new(1_000, b"SPAKE2P Key Salt")?;
//! let verifier =
//! Spake2pVerifierData::from_passcode(20_202_021, ¶meters.salt, parameters.iterations)?;
//!
//! let mut device = PaseResponder::new(
//! ResponderConfig { verifier, parameters: parameters.clone(), session_params: None },
//! SessionId(1),
//! );
//! let mut commissioner =
//! PaseInitiator::new(20_202_021, SessionId(2), Some(parameters), None);
//!
//! let (mut a, mut b) = ([0u8; 512], [0u8; 512]);
//! let n = commissioner.start(&[0x11; 32], &mut a)?;
//! let n = device.on_pbkdf_param_request(&a[..n], &[0x22; 32], &mut b)?;
//! let n = commissioner.on_pbkdf_param_response(&b[..n], &[0x33; 32], &mut a)?;
//! let n = device.on_pake1(&a[..n], &[0x44; 32], &mut b)?;
//! let n = commissioner.on_pake2(&b[..n], &mut a)?;
//! let (n, device_keys) = device.on_pake3(&a[..n], &mut b)?;
//! let commissioner_keys = commissioner.on_pake_finished(&b[..n])?;
//!
//! // Both ends now hold the same three keys.
//! assert_eq!(commissioner_keys.i2r, device_keys.i2r);
//! # Ok(())
//! # }
//! # fn main() {
//! # #[cfg(feature = "rustcrypto")]
//! # demo().expect("the exchange completes");
//! # }
//! ```
//!
//! # Matching on an event
//!
//! Enums this crate *reports* through are `#[non_exhaustive]`; enums the **specification**
//! closes are not. So a `match` on a protocol state is still checked for completeness —
//! which is where you want to be told about a new variant — and a `match` on a stream of
//! events does not break when a new one is worth reporting.
//!
//! ---
//!
//! Matter® is a registered trademark of the Connectivity Standards Alliance. This project
//! is not affiliated with or endorsed by the Alliance, and nothing here is a certified
//! implementation.
// The crate-wide `deny` list in `Cargo.toml` is aimed at code that faces the network.
// Test code faces a test: `unwrap` there is a legible assertion, and writing
// `let Some(x) = .. else { panic!() }` around every fixture buys nothing and hides the
// intent. The denials stay in force for everything that ships.
extern crate alloc;
/// The fabric's certificate authority needs [`cert`] and [`crypto`]'s signing.
pub use ;
pub use ;
/// The Matter specification version this crate implements, in the encoding of the Basic
/// Information cluster's `SpecificationVersion` attribute (Core §11.1.5.22).
///
/// The four component bytes are major, minor, patch and reserved: `0x01_06_00_00` is
/// 1.6.0. A larger value is newer.
pub const SPECIFICATION_VERSION: u32 = 0x0106_0000;
/// The Data Model revision this crate implements — §7.1.1's revision 21, "Added Revision
/// conformance".
///
/// §11.1.5.1 requires a node to report "the revision number of the Data Model against which
/// the Node is certified", and "one of the valid values listed in Section 7.1.1". The table
/// grew by one between releases and the split is easy to miss: 1.5.1 ends at
/// `20 — Removed P quality and added Revision conformance`, and 1.6 divides that single row
/// into `20 — Removed P quality` and `21 — Added Revision conformance`. A 1.6 node reports
/// 21; carrying 20 forward advertises a 1.5.1 data model.
///
/// It lives here rather than in the Basic Information cluster because it is also
/// `DATA_MODEL_REVISION` in the `session-parameter-struct` of §4.13.1, which is exchanged
/// long before any cluster is readable. `clusters::basic_information` re-exports it.
pub const DATA_MODEL_REVISION: u16 = 21;
/// The IANA-assigned UDP port for Matter (Core §2.5.6.3).
pub const PORT: u16 = 5540;
/// The README's `rust` blocks, compiled as doctests.
///
/// Under `cfg(doctest)` only, so the README is not pulled into the crate's own
/// documentation — this exists so a landing-page example cannot quietly stop compiling.
;