indigo-matter-bridge 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # indigo-matter-bridge
2
+
3
+ The Matter **bridge node** for the
4
+ [indigo-matter](https://github.com/simons-plugins/indigo-matter) Indigo plugin.
5
+
6
+ It exports selected [Indigo](https://www.indigodomo.com) devices as Matter
7
+ accessories, so Apple Home, Alexa, Google Home and SmartThings see them as
8
+ ordinary Matter devices on a bridge.
9
+
10
+ > **This package is not useful on its own.** It has no configuration of its own,
11
+ > no discovery, and no idea what an Indigo device is. It is one half of a pair:
12
+ > the plugin decides *what* to export and the node makes it a Matter accessory.
13
+ > Install the Indigo plugin; it installs and manages this package for you, via
14
+ > its own **Plugins ▸ Matter ▸ Install/update the Matter export bridge** menu
15
+ > item and a launchd LaunchAgent it writes.
16
+
17
+ ## Why it is a separate process
18
+
19
+ matter.js is imported **here and nowhere else**. Indigo plugins are Python, and
20
+ the alternative — a Node shim inside the plugin, or a second Matter stack — buys
21
+ two versions of the specification and a second place for accessory identity to
22
+ drift. The plugin talks to this node over a loopback WebSocket with a versioned
23
+ JSON protocol, and refuses to attach on a version mismatch rather than guessing.
24
+
25
+ The contract is
26
+ [`docs/BRIDGE_PROTOCOL.md`](https://github.com/simons-plugins/indigo-matter/blob/main/docs/BRIDGE_PROTOCOL.md)
27
+ in the plugin repository. It is a real contract: both sides' test suites assert
28
+ against one shared file of golden frames, so a frame that changes on one side
29
+ fails the other side's tests.
30
+
31
+ ## Running it by hand
32
+
33
+ Normally the plugin's LaunchAgent does this. For development:
34
+
35
+ ```sh
36
+ node dist/main.js \
37
+ --storage-path ~/Library/Application\ Support/com.simons-plugins.indigo-matter/bridge-node \
38
+ --ws-port 5581 \
39
+ --matter-port 5540 \
40
+ [--mdns-interface en0]
41
+ ```
42
+
43
+ Every flag is validated and the node **refuses to start** on a value it cannot
44
+ parse, rather than silently running somewhere unexpected — including a flag given
45
+ with no value.
46
+
47
+ | Flag | Meaning |
48
+ |---|---|
49
+ | `--storage-path` | Where identity, fabrics and the endpoint-number map live. **Sacred**: losing it un-pairs every ecosystem and duplicates every accessory. |
50
+ | `--ws-port` | The loopback protocol port the plugin dials (default 5581). |
51
+ | `--matter-port` | The Matter UDP port to advertise on (default 5540). |
52
+ | `--mdns-interface` | Pin mDNS to one interface. Omit to let matter.js choose; on a Mac with VPN/utun interfaces, pinning is usually necessary. |
53
+
54
+ The node writes its own log to stdout/stderr. Under the plugin's LaunchAgent that
55
+ is `~/Library/Logs/indigo-matter/bridge-node.log` and `bridge-node.err.log`.
56
+
57
+ ## Storage
58
+
59
+ Two files in `--storage-path`, alongside matter.js's own store:
60
+
61
+ * **`identity.json`** — install id, commissioning passcode and discriminator,
62
+ plus a witness recording that the bridge has been commissioned at least once.
63
+ An unreadable one is moved aside and a replacement minted **in memory only**:
64
+ the `SerialNumber`/`UniqueID` every paired ecosystem knows are never
65
+ overwritten.
66
+ * **`endpoint-map.json`** — the persisted `UniqueID → endpoint number` map. It
67
+ allocates nothing (matter.js owns the numbers); it is an independent *witness*,
68
+ so a lost or reset matter.js store becomes a log line instead of silently
69
+ duplicating every accessory in every ecosystem. Drift is reported and never
70
+ repaired automatically — repairing it would call the same fault clean on the
71
+ next pass.
72
+
73
+ Back both up. The plugin's **Export fabric backup…** menu item covers them.
74
+
75
+ ## Uncertified by design
76
+
77
+ The bridge advertises with the specification's **test vendor id** (`0xFFF1`), so
78
+ every ecosystem shows an "uncertified accessory" warning when you add it. That is
79
+ normal and expected — Homebridge and Home Assistant produce the same warning —
80
+ and choosing "Add Anyway" is the intended path. Matter certification is a paid,
81
+ per-product process that a self-hosted bridge cannot meaningfully complete.
82
+
83
+ ## Development
84
+
85
+ ```sh
86
+ npm install
87
+ npm run build # tsc
88
+ npm test # builds, copies the shared golden frames, runs node --test
89
+ ```
90
+
91
+ The test suite includes an integration file that stands up a **real**
92
+ `ServerNode` on a real Matter stack behind a real WebSocket server, because the
93
+ faults worth catching here (a role factory that builds but writes the wrong
94
+ attribute; a bridged child publishing the wrong manufacturer) cannot fail against
95
+ a stub.
96
+
97
+ ## Licence
98
+
99
+ MIT. Not affiliated with Perceptive Automation, the Connectivity Standards
100
+ Alliance, Apple, Amazon, Google or Samsung.
@@ -0,0 +1,36 @@
1
+ /**
2
+ * CLI argument parsing and defaults for the indigo-matter bridge node.
3
+ *
4
+ * Every knob the plugin needs to drive is a long-form `--flag value` argument;
5
+ * launchd plists are easier to read that way than with environment variables.
6
+ */
7
+ /** Default Matter operational/commissioning port (matter.js's own default). */
8
+ export declare const DEFAULT_MATTER_PORT = 5540;
9
+ /** Default loopback WebSocket port for the plugin protocol (controller uses 5580). */
10
+ export declare const DEFAULT_WS_PORT = 5581;
11
+ /** Storage root, sibling to the controller's directory. See PRD §4.3. */
12
+ export declare const DEFAULT_STORAGE_PATH: string;
13
+ export interface BridgeConfig {
14
+ /** Directory holding matter.js storage plus our own persisted install identity. */
15
+ storagePath: string;
16
+ /** Matter network port. */
17
+ matterPort: number;
18
+ /** Loopback port for the plugin protocol WebSocket server. */
19
+ wsPort: number;
20
+ /** Optional mDNS interface pin (maps to matter.js's `mdns.networkInterface`). */
21
+ mdnsInterface?: string;
22
+ }
23
+ declare const USAGE: string;
24
+ /**
25
+ * Parse `process.argv.slice(2)`. Throws on unknown or malformed arguments — a
26
+ * bad launchd plist should fail loudly at start rather than silently run with
27
+ * defaults on the wrong port.
28
+ */
29
+ export declare function parseArgs(argv: readonly string[]): BridgeConfig | "help";
30
+ /**
31
+ * Fail before start if `--mdns-interface` names something this host does not
32
+ * have: matter.js takes the name on trust and would advertise on nothing,
33
+ * which presents as "the bridge never appears" with no error anywhere.
34
+ */
35
+ export declare function assertMdnsInterface(name: string, available: readonly string[]): void;
36
+ export { USAGE };
package/dist/config.js ADDED
@@ -0,0 +1,91 @@
1
+ /**
2
+ * CLI argument parsing and defaults for the indigo-matter bridge node.
3
+ *
4
+ * Every knob the plugin needs to drive is a long-form `--flag value` argument;
5
+ * launchd plists are easier to read that way than with environment variables.
6
+ */
7
+ import { homedir } from "node:os";
8
+ import { join } from "node:path";
9
+ /** Default Matter operational/commissioning port (matter.js's own default). */
10
+ export const DEFAULT_MATTER_PORT = 5540;
11
+ /** Default loopback WebSocket port for the plugin protocol (controller uses 5580). */
12
+ export const DEFAULT_WS_PORT = 5581;
13
+ /** Storage root, sibling to the controller's directory. See PRD §4.3. */
14
+ export const DEFAULT_STORAGE_PATH = join(homedir(), "Library", "Application Support", "com.simons-plugins.indigo-matter", "bridge-node");
15
+ const USAGE = `indigo-matter-bridge
16
+
17
+ Usage: indigo-matter-bridge [options]
18
+
19
+ Options:
20
+ --storage-path <dir> Storage directory (default: ${DEFAULT_STORAGE_PATH})
21
+ --matter-port <port> Matter network port (default: ${DEFAULT_MATTER_PORT})
22
+ --ws-port <port> Loopback protocol WebSocket port (default: ${DEFAULT_WS_PORT})
23
+ --mdns-interface <if> Pin mDNS to a single network interface (default: all)
24
+ --help Show this message
25
+ `;
26
+ function parsePort(name, raw) {
27
+ const value = Number(raw);
28
+ if (!Number.isInteger(value) || value < 1 || value > 65535) {
29
+ throw new Error(`${name} must be an integer 1-65535, got ${JSON.stringify(raw)}`);
30
+ }
31
+ return value;
32
+ }
33
+ /** Flags that take a following value. Checked before "requires a value", so an
34
+ * unrecognised flag is reported as unknown rather than as a missing value. */
35
+ const VALUE_FLAGS = new Set(["--storage-path", "--matter-port", "--ws-port", "--mdns-interface"]);
36
+ /**
37
+ * Parse `process.argv.slice(2)`. Throws on unknown or malformed arguments — a
38
+ * bad launchd plist should fail loudly at start rather than silently run with
39
+ * defaults on the wrong port.
40
+ */
41
+ export function parseArgs(argv) {
42
+ const config = {
43
+ storagePath: DEFAULT_STORAGE_PATH,
44
+ matterPort: DEFAULT_MATTER_PORT,
45
+ wsPort: DEFAULT_WS_PORT,
46
+ };
47
+ for (let i = 0; i < argv.length; i++) {
48
+ const flag = argv[i];
49
+ if (flag === "--help" || flag === "-h") {
50
+ return "help";
51
+ }
52
+ if (!VALUE_FLAGS.has(flag)) {
53
+ throw new Error(`Unknown argument: ${flag}`);
54
+ }
55
+ const value = argv[i + 1];
56
+ if (value === undefined || value.startsWith("--")) {
57
+ throw new Error(`${flag} requires a value`);
58
+ }
59
+ i++;
60
+ switch (flag) {
61
+ case "--storage-path":
62
+ config.storagePath = value;
63
+ break;
64
+ case "--matter-port":
65
+ config.matterPort = parsePort(flag, value);
66
+ break;
67
+ case "--ws-port":
68
+ config.wsPort = parsePort(flag, value);
69
+ break;
70
+ case "--mdns-interface":
71
+ config.mdnsInterface = value;
72
+ break;
73
+ default:
74
+ throw new Error(`Unknown argument: ${flag}`);
75
+ }
76
+ }
77
+ return config;
78
+ }
79
+ /**
80
+ * Fail before start if `--mdns-interface` names something this host does not
81
+ * have: matter.js takes the name on trust and would advertise on nothing,
82
+ * which presents as "the bridge never appears" with no error anywhere.
83
+ */
84
+ export function assertMdnsInterface(name, available) {
85
+ if (!available.includes(name)) {
86
+ throw new Error(`--mdns-interface ${name} is not a network interface on this host ` +
87
+ `(available: ${available.length > 0 ? available.join(", ") : "none"})`);
88
+ }
89
+ }
90
+ export { USAGE };
91
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,216 @@
1
+ /**
2
+ * The persisted `UniqueID → endpoint number` map, and the drift detector built
3
+ * on it (PRD §4.3, BRIDGE_PROTOCOL §4.3/§3.10/§3.11).
4
+ *
5
+ * **Why this file exists at all.** matter.js persists endpoint numbers itself,
6
+ * keyed on the string `Endpoint.id`, and that is what actually holds identity
7
+ * together across a restart. This map does not allocate anything: it is the
8
+ * independent *witness* of what those numbers were last time, so that the one
9
+ * failure that silently duplicates every accessory in every paired ecosystem —
10
+ * matter.js's storage being lost, moved or reset underneath us — becomes a
11
+ * statement in the log instead of a mystery in someone's Home app. That is
12
+ * matterbridge's `checkEndpointNumbers()` pattern, and PRD §4.3 adopts it for
13
+ * the same reason: it is the only way to make "is it us or the controller?"
14
+ * falsifiable in the field.
15
+ *
16
+ * **It lives outside matter.js's storage context on purpose.** §3.10's factory
17
+ * reset wipes that context; a witness stored inside it would be wiped by the
18
+ * very event it exists to survive, so this file sits beside `identity.json` in
19
+ * the bridge storage dir root and is written through the same atomic write.
20
+ *
21
+ * **Drift is reported, never repaired.** §4.3 is explicit, and the reasoning is
22
+ * asymmetric: a wrong report costs a log line, while an auto-repair that pinned
23
+ * the "right" number would hide the storage loss that caused it and make the
24
+ * next occurrence invisible too. Nothing here mutates a drifted entry — the
25
+ * baseline stays, so the drift keeps being reported until a human resolves it
26
+ * with §3.11.
27
+ *
28
+ * Stdlib only — no matter.js import — which is what lets the whole detector be
29
+ * tested without a Matter stack. Callers hand in `{uniqueId, endpointNumber}`
30
+ * pairs; deriving `uniqueId` from an Indigo device id is `endpoints.ts`'s job.
31
+ */
32
+ import { type DriftEntry } from "./protocol.js";
33
+ /** What the PRD §7 refuse-to-start decision is taken from. */
34
+ export interface EndpointIdentityState {
35
+ /** Does the Matter stack hold at least one fabric right now? */
36
+ commissioned: boolean;
37
+ /**
38
+ * Why a *present* map is unusable, if it is.
39
+ *
40
+ * Deliberately the only map input. An **absent** map is not a fault — see
41
+ * {@link refuseReasonFor} — so `present` has no say in the decision and is
42
+ * not passed here; the caller uses it to choose between bootstrapping a
43
+ * baseline and simply loading one.
44
+ */
45
+ mapProblem?: string;
46
+ /** `identity.commissionedAt` — the witness that we have ever been paired. */
47
+ commissionedAt?: string;
48
+ }
49
+ /**
50
+ * The PRD §7 refuse-to-start decision, as one pure function.
51
+ *
52
+ * Endpoint numbers only matter to somebody who is *paired*, and that asymmetry
53
+ * is the whole rule: on a bridge nothing has ever commissioned, a missing or
54
+ * unreadable map costs precisely nothing, so a fresh install must never be
55
+ * blocked by one. Two conditions remain fatal once a fabric has existed:
56
+ *
57
+ * * **a map that is there and cannot be read** — the numbers being served
58
+ * cannot be checked against a baseline we know exists, and silently
59
+ * re-recording them would bless whatever matter.js happens to hand out this
60
+ * boot as the truth over a file that says something else;
61
+ * * **the witness but no fabrics** — PRD §7's "storage missing but previously
62
+ * commissioned". matter.js's storage has gone, and its own `Endpoint.id →
63
+ * number` allocation went with it, so every accessory is about to be
64
+ * re-created in every ecosystem the user paired.
65
+ *
66
+ * **A commissioned bridge with no map at all is NOT one of them, and the first
67
+ * cut of E5 had that wrong.** Every bridge commissioned before E5 shipped is in
68
+ * exactly that state — fabrics, endpoints, no `endpoint-map.json`, because the
69
+ * file did not exist yet — so refusing would have taken every already-working
70
+ * export offline on upgrade. And the refusal buys nothing even in principle:
71
+ * **matter.js owns the numbers**, keyed on `Endpoint.id` in its own store, and
72
+ * this map is only the independent witness of what they were. A missing witness
73
+ * renumbers precisely nothing; it means we cannot yet *check*, which is what
74
+ * bootstrapping a baseline fixes and what refusing does not. The one thing a
75
+ * missing map must never do is silently paper over a *present* one, which is
76
+ * why `mapProblem` still refuses.
77
+ *
78
+ * Returns the reason to refuse, or `undefined` to serve normally.
79
+ */
80
+ export declare function refuseReasonFor(state: EndpointIdentityState): string | undefined;
81
+ /** Sibling of `identity.json` in the bridge storage dir. */
82
+ export declare const ENDPOINT_MAP_FILE = "endpoint-map.json";
83
+ /** Schema version of the persisted file. Bump only on an incompatible change. */
84
+ export declare const ENDPOINT_MAP_VERSION = 1;
85
+ /** The on-disk shape. */
86
+ export interface EndpointMapFile {
87
+ version: number;
88
+ /** `UniqueID → endpoint number`. */
89
+ endpoints: Record<string, number>;
90
+ }
91
+ /** One live endpoint, as the detector needs to see it. */
92
+ export interface LiveEndpointNumber {
93
+ uniqueId: string;
94
+ endpointNumber: number;
95
+ }
96
+ /** The outcome of reading the file: absent, usable, or present-but-broken. */
97
+ export interface EndpointMapLoad {
98
+ numbers: Map<string, number>;
99
+ /** True when a file was there at all — absent is a first run, not a fault. */
100
+ present: boolean;
101
+ /** Set only when a file was present and could not be used. */
102
+ problem?: string;
103
+ }
104
+ /** Read `endpoint-map.json`. Never throws — the caller decides what a fault means. */
105
+ export declare function loadEndpointMap(storagePath: string): EndpointMapLoad;
106
+ /** Delete `endpoint-map.json`. Returns whether a file was actually removed. */
107
+ export declare function deleteEndpointMap(storagePath: string): boolean;
108
+ /**
109
+ * The map plus the operations §3.10/§3.11 and the drift detector need.
110
+ *
111
+ * One instance per node, constructed at startup and {@link load}ed before the
112
+ * Matter stack comes up, because whether the file is readable is what decides
113
+ * if the node serves endpoints at all.
114
+ */
115
+ export declare class EndpointMapStore {
116
+ #private;
117
+ private readonly storagePath;
118
+ private readonly log;
119
+ /** Injectable so the timestamped quarantine name is testable. */
120
+ private readonly now;
121
+ constructor(storagePath: string, log?: (message: string) => void,
122
+ /** Injectable so the timestamped quarantine name is testable. */
123
+ now?: () => Date);
124
+ /** Read the file into memory. Idempotent; the last read wins. */
125
+ load(): EndpointMapLoad;
126
+ /** True once a file has been read or written — i.e. there is a baseline. */
127
+ get present(): boolean;
128
+ /** Why the present file cannot be used, if it cannot. */
129
+ get problem(): string | undefined;
130
+ /**
131
+ * §4.3 `driftChecked` — whether an empty `drift` is an answer or an absence.
132
+ *
133
+ * False until {@link check} has actually run against a baseline. The two
134
+ * readings of `drift: []` are opposites ("checked, nothing moved" versus
135
+ * "there is nothing to check against yet"), and a client that cannot tell
136
+ * them apart reads a fresh install's silence as an all-clear.
137
+ */
138
+ get checked(): boolean;
139
+ /**
140
+ * §4.3 `warnings` — the persistence failures a client has to be told about.
141
+ *
142
+ * The node's log is stdout, and in this milestone the node is started **by
143
+ * hand**, so stdout is a terminal somebody closed. A map that cannot be
144
+ * written is exactly the fault this file exists to make visible, and it
145
+ * would otherwise be visible only there. `get_status` is polled, so this is
146
+ * the channel that actually reaches a user.
147
+ */
148
+ get warnings(): string[];
149
+ /** The recorded number for a `UniqueID`, if there is one. */
150
+ numberFor(uniqueId: string): number | undefined;
151
+ get size(): number;
152
+ /**
153
+ * Compare the live endpoint numbers against the map (PRD §4.3).
154
+ *
155
+ * Endpoints the map has never seen are *recorded*; endpoints whose number
156
+ * has moved are *reported* and left alone. Persisting only happens when
157
+ * something was actually added, so a steady state costs no disk write per
158
+ * reconcile.
159
+ *
160
+ * A device that is not currently live is not touched either way: §3.3
161
+ * retains the allocation so re-adding the same device restores the same
162
+ * number, and forgetting it here would throw away the very baseline that
163
+ * makes a re-add verifiable.
164
+ */
165
+ check(live: readonly LiveEndpointNumber[]): DriftEntry[];
166
+ /**
167
+ * Adopt a baseline for a bridge that is already commissioned but has no map
168
+ * — the E5 upgrade path (PRD §7).
169
+ *
170
+ * Not a rebuild: there is nothing to discard. A pre-E5 install has fabrics,
171
+ * endpoints and numbers that matter.js has been persisting all along, and
172
+ * the only thing missing is our witness of them. Recording what is already
173
+ * true is the migration; refusing to serve until a human confirms a
174
+ * *rebuild* would take a working bridge offline to fix a file it never had.
175
+ *
176
+ * Returns whether the baseline reached disk.
177
+ */
178
+ seed(numbers: readonly LiveEndpointNumber[], why: string): boolean;
179
+ /**
180
+ * §3.11 — throw the baseline away and adopt the live numbers as the truth.
181
+ *
182
+ * The recovery path out of `endpoint_map_invalid`, and the only operation
183
+ * here that discards a mapping. It does not renumber anything in matter.js:
184
+ * whatever duplication a lost map implies has already happened by the time a
185
+ * user is asked to confirm this, and what the rebuild does is stop refusing
186
+ * and start telling the truth about the numbers that now exist.
187
+ */
188
+ rebuild(live: readonly LiveEndpointNumber[]): boolean;
189
+ /**
190
+ * Copy a present-but-unusable map to `<file>.corrupt-<stamp>` before it is
191
+ * lost.
192
+ *
193
+ * Timestamped like `identity.json.unreadable-<stamp>`, and for the same
194
+ * reason: a fixed name means the *second* thing to go wrong overwrites the
195
+ * evidence of the first, and these bytes are the only surviving record of
196
+ * what the endpoint numbers used to be.
197
+ */
198
+ private quarantineUnusable;
199
+ /**
200
+ * §3.10 with `preserveEndpointNumbers: false` — delete the file and forget
201
+ * everything. The "explicit rebuild" of PRD §7, for when the map itself is
202
+ * what is corrupt.
203
+ */
204
+ discard(): boolean;
205
+ /**
206
+ * Write the current map, reporting whether it landed.
207
+ *
208
+ * Never throws — refusing to serve endpoints because a *witness* could not
209
+ * be written would take down a working bridge over a disk problem. But it
210
+ * is no longer silent to its callers either: an unwritten map means the
211
+ * next start has no baseline, and the two callers that must not report
212
+ * success over that (§3.11's rebuild and §4.3's `driftChecked`) both read
213
+ * the answer.
214
+ */
215
+ private persist;
216
+ }