Documentation
¶
Overview ¶
Package gomatter is a from-scratch, dependency-free Matter (CSA) device stack in pure Go. Create a Device, plug typed device handles into it (package device), and Run a node a controller can pair and drive — discovery, PASE, attestation, CASE and the Interaction Model are wired for you.
log := console.New() // or any *slog.Logger
dev, err := gomatter.NewDevice("Desk Lamp", onboarding.SetupPayload{
VendorID: 0xFFF1, ProductID: 0x8000,
Discovery: onboarding.DiscoveryOnNetwork,
Discriminator: 3840, Passcode: 20202021,
}, gomatter.WithLogger(log.Slog()))
if err != nil { ... }
lamp := device.NewLight("Desk Lamp")
dev.Add(lamp)
dev.Run(ctx) // later: lamp.On(), lamp.Off() drive the controller
Topology is derived from what you add: one endpoint is a flat node, many are an Aggregator/bridge — there is no mode to set.
Index ¶
- type Component
- type Device
- func (d *Device) Add(c Component)
- func (d *Device) Endpoints() []*cluster.Endpoint
- func (d *Device) IsBridge() bool
- func (d *Device) PrintPairing()
- func (d *Device) ProductName() string
- func (d *Device) Push()
- func (d *Device) Remove(c Component)
- func (d *Device) Run(ctx context.Context) error
- func (d *Device) VendorName() string
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Component ¶
Component is anything that can be added to a Device — the device handles from package device (NewLight, NewComposite, …) satisfy it. Re-exported so callers can store handles (e.g. to Remove them later) without naming an internal type.
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device is a runnable Matter node: mDNS discovery, the commissioning handshakes, and the Interaction Model over the device handles you Add. It implements im.Model.
func NewDevice ¶
func NewDevice(name string, payload onboarding.SetupPayload, opts ...Option) (*Device, error)
NewDevice creates a device from a product name and an onboarding payload. Plug in device handles with Add, then Run; the topology (flat vs Aggregator/bridge) is derived from what you added. It binds no sockets; call Run to advertise and serve.
func (*Device) Add ¶
Add plugs a device handle (device.NewLight, device.NewTempSensor, …) into the node and wires its push callback. Safe before or during Run: if the device is already serving, the structure change is applied on the serving goroutine and pushed on the controller's subscription — no re-pairing.
func (*Device) IsBridge ¶
IsBridge derives the topology: more than one endpoint ⇒ an Aggregator (bridge).
func (*Device) PrintPairing ¶
func (d *Device) PrintPairing()
PrintPairing renders the pairing QR and the manual setup code to stderr.
func (*Device) ProductName ¶
ProductName is the device's product name (Basic Information / mDNS).
func (*Device) Push ¶
func (d *Device) Push()
Push re-reports the current attribute values on active subscriptions. Handle Set… methods push automatically once added; call this only to force a report.
func (*Device) Run ¶
Run advertises the device over mDNS and serves commissioning + operational traffic until ctx is cancelled. It blocks. Unless suppressed, it prints the pairing console first. Add handles before calling Run.
func (*Device) VendorName ¶
VendorName is the device's vendor name (Basic Information).
type Option ¶
type Option func(*config)
Option configures a Device.
func WithLogger ¶
WithLogger sets the logger (default: a colored console logger to stderr). Any *slog.Logger works; console.New().Slog() is the batteries-included choice.
func WithStatePath ¶
WithStatePath persists the commissioning identity to path, so a restart reconnects (CASE) without re-pairing. Empty (default) = in-memory only.
func WithoutPairingConsole ¶
func WithoutPairingConsole() Option
WithoutPairingConsole suppresses printing the QR + manual code on Run.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package console is a small, dependency-free colored logger for the terminal, built on log/slog.
|
Package console is a small, dependency-free colored logger for the terminal, built on log/slog. |
|
Package device provides the typed device handles you plug into a gomatter.Device.
|
Package device provides the typed device handles you plug into a gomatter.Device. |
|
examples
|
|
|
hub
command
Command hub exposes four On/Off lights as separate, individually-roomable devices.
|
Command hub exposes four On/Off lights as separate, individually-roomable devices. |
|
onoff-light
command
Command onoff-light is the smallest useful gomatter device: a single On/Off light that a real Matter controller can discover, pair and toggle.
|
Command onoff-light is the smallest useful gomatter device: a single On/Off light that a real Matter controller can discover, pair and toggle. |
|
weather
command
Command weather exposes a single composite device with three read-only measurements on one endpoint — temperature, humidity and barometric pressure.
|
Command weather exposes a single composite device with three read-only measurements on one endpoint — temperature, humidity and barometric pressure. |
|
internal
|
|
|
attest
Package attest provides Matter device attestation using the public CSA test credentials (route B): the test DAC/PAI for VID 0xFFF1 / PID 0x8000 (which chain to the CSA test PAA that commissioners trust) and a Certification Declaration signed with the CSA test CD-signing key.
|
Package attest provides Matter device attestation using the public CSA test credentials (route B): the test DAC/PAI for VID 0xFFF1 / PID 0x8000 (which chain to the CSA test PAA that commissioners trust) and a Certification Declaration signed with the CSA test CD-signing key. |
|
casesession
Package casesession implements the device (responder) side of Matter CASE — the certificate-authenticated session the commissioner opens over the operational network after AddNOC (spec §4.14):
|
Package casesession implements the device (responder) side of Matter CASE — the certificate-authenticated session the commissioner opens over the operational network after AddNOC (spec §4.14): |
|
ccm
Package ccm implements AES-CCM as Matter uses it for message encryption: 128-bit key, 13-byte nonce, 16-byte tag (spec §4.7 / RFC 3610 / NIST SP 800-38C).
|
Package ccm implements AES-CCM as Matter uses it for message encryption: 128-bit key, 13-byte nonce, 16-byte tag (spec §4.7 / RFC 3610 / NIST SP 800-38C). |
|
cluster
Package cluster is gomatter's device model engine: the Matter cluster contract and the concrete cluster implementations, plus the Endpoint that holds them.
|
Package cluster is gomatter's device model engine: the Matter cluster contract and the concrete cluster implementations, plus the Endpoint that holds them. |
|
im
Package im is a minimal Matter Interaction Model responder — enough of the commissioning surface to answer what a commissioner reads/invokes right after PASE: a ReadRequest for the General Commissioning / Basic Information / Network Commissioning attributes, and the ArmFailSafe command.
|
Package im is a minimal Matter Interaction Model responder — enough of the commissioning surface to answer what a commissioner reads/invokes right after PASE: a ReadRequest for the General Commissioning / Basic Information / Network Commissioning attributes, and the ArmFailSafe command. |
|
logger
Package logger is a thin printf-style adapter over *slog.Logger for the library internals.
|
Package logger is a thin printf-style adapter over *slog.Logger for the library internals. |
|
mdns
Package mdns is a tiny, dependency-free multicast-DNS responder — just enough to advertise a Matter commissionable node (_matterc._udp) so a commissioner can discover the device on the LAN.
|
Package mdns is a tiny, dependency-free multicast-DNS responder — just enough to advertise a Matter commissionable node (_matterc._udp) so a commissioner can discover the device on the LAN. |
|
message
Package message encodes/decodes the Matter message + protocol (exchange) headers for the unsecured session used during PASE (spec §4.4).
|
Package message encodes/decodes the Matter message + protocol (exchange) headers for the unsecured session used during PASE (spec §4.4). |
|
opcreds
Package opcreds reads the operational identity Matter assigns at AddNOC and derives the values needed for operational discovery and CASE: the operational Node ID and Fabric ID (from the NOC), the root public key (from the trusted root cert), and the Compressed Fabric ID.
|
Package opcreds reads the operational identity Matter assigns at AddNOC and derives the values needed for operational discovery and CASE: the operational Node ID and Fabric ID (from the NOC), the root public key (from the trusted root cert), and the Compressed Fabric ID. |
|
pase
Package pase implements the device (responder) side of Matter PASE — the Secure Channel exchange that turns the setup passcode into an encrypted session, using SPAKE2+ (spec §4.13 / §3.10):
|
Package pase implements the device (responder) side of Matter PASE — the Secure Channel exchange that turns the setup passcode into an encrypted session, using SPAKE2+ (spec §4.13 / §3.10): |
|
session
Package session is the Matter secure (encrypted) message layer that takes over once PASE establishes keys.
|
Package session is the Matter secure (encrypted) message layer that takes over once PASE establishes keys. |
|
spake2p
Package spake2p implements SPAKE2+ over NIST P-256 as used by Matter's PASE (Passcode-Authenticated Session Establishment), spec §3.10 / RFC 9383.
|
Package spake2p implements SPAKE2+ over NIST P-256 as used by Matter's PASE (Passcode-Authenticated Session Establishment), spec §3.10 / RFC 9383. |
|
state
Package state persists the device's commissioning result so it survives restarts — a real Matter device keeps its operational credentials in non-volatile storage so the commissioner can reconnect (CASE) without re-commissioning.
|
Package state persists the device's commissioning result so it survives restarts — a real Matter device keeps its operational credentials in non-volatile storage so the commissioner can reconnect (CASE) without re-commissioning. |
|
tlv
Package tlv is a small Matter TLV (Tag-Length-Value) codec covering the Appendix A element types: signed/unsigned integers (1–8 octet), booleans, single/double floats, UTF-8 and octet strings (1/2/4/8-octet length), null, and the struct/array/list containers.
|
Package tlv is a small Matter TLV (Tag-Length-Value) codec covering the Appendix A element types: signed/unsigned integers (1–8 octet), booleans, single/double floats, UTF-8 and octet strings (1/2/4/8-octet length), null, and the struct/array/list containers. |
|
transport
Package transport is the Matter UDP message layer.
|
Package transport is the Matter UDP message layer. |
|
Package onboarding builds the Matter setup payload: the "MT:" QR-code string and the 11-digit manual pairing code, per the Matter Core spec §5.1.
|
Package onboarding builds the Matter setup payload: the "MT:" QR-code string and the 11-digit manual pairing code, per the Matter Core spec §5.1. |
|
Package qr is a small, dependency-free QR Code encoder good enough to render a Matter "MT:" onboarding payload in the terminal.
|
Package qr is a small, dependency-free QR Code encoder good enough to render a Matter "MT:" onboarding payload in the terminal. |