@matter/protocol 0.13.1-alpha.0-20250429-fd3557399 → 0.13.1-alpha.0-20250502-43a54f780

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.
Files changed (118) hide show
  1. package/dist/cjs/action/response/ReadResult.d.ts +4 -0
  2. package/dist/cjs/action/response/ReadResult.d.ts.map +1 -1
  3. package/dist/cjs/action/server/AttributeResponse.d.ts +1 -1
  4. package/dist/cjs/action/server/AttributeResponse.d.ts.map +1 -1
  5. package/dist/cjs/action/server/AttributeResponse.js +37 -17
  6. package/dist/cjs/action/server/AttributeResponse.js.map +2 -2
  7. package/dist/cjs/interaction/AttributeDataEncoder.d.ts +1 -1
  8. package/dist/cjs/interaction/AttributeDataEncoder.d.ts.map +1 -1
  9. package/dist/cjs/interaction/InteractionEndpointStructure.d.ts +37 -1
  10. package/dist/cjs/interaction/InteractionEndpointStructure.d.ts.map +1 -1
  11. package/dist/cjs/interaction/InteractionEndpointStructure.js +34 -15
  12. package/dist/cjs/interaction/InteractionEndpointStructure.js.map +1 -1
  13. package/dist/cjs/interaction/InteractionMessenger.js +1 -1
  14. package/dist/cjs/interaction/InteractionMessenger.js.map +1 -1
  15. package/dist/cjs/interaction/ServerSubscription.d.ts +1 -2
  16. package/dist/cjs/interaction/ServerSubscription.d.ts.map +1 -1
  17. package/dist/cjs/interaction/ServerSubscription.js +20 -20
  18. package/dist/cjs/interaction/ServerSubscription.js.map +1 -1
  19. package/dist/cjs/interaction/SubscriptionClient.d.ts +2 -1
  20. package/dist/cjs/interaction/SubscriptionClient.d.ts.map +1 -1
  21. package/dist/cjs/interaction/SubscriptionClient.js +2 -1
  22. package/dist/cjs/interaction/SubscriptionClient.js.map +1 -1
  23. package/dist/cjs/interaction/index.d.ts +0 -1
  24. package/dist/cjs/interaction/index.d.ts.map +1 -1
  25. package/dist/cjs/interaction/index.js +0 -1
  26. package/dist/cjs/interaction/index.js.map +1 -1
  27. package/dist/cjs/protocol/ExchangeManager.d.ts.map +1 -1
  28. package/dist/cjs/protocol/ExchangeManager.js +17 -2
  29. package/dist/cjs/protocol/ExchangeManager.js.map +1 -1
  30. package/dist/cjs/protocol/MessageExchange.d.ts +2 -1
  31. package/dist/cjs/protocol/MessageExchange.d.ts.map +1 -1
  32. package/dist/cjs/protocol/MessageExchange.js +6 -3
  33. package/dist/cjs/protocol/MessageExchange.js.map +1 -1
  34. package/dist/cjs/protocol/ProtocolHandler.d.ts +1 -0
  35. package/dist/cjs/protocol/ProtocolHandler.d.ts.map +1 -1
  36. package/dist/cjs/securechannel/SecureChannelProtocol.d.ts +1 -0
  37. package/dist/cjs/securechannel/SecureChannelProtocol.d.ts.map +1 -1
  38. package/dist/cjs/securechannel/SecureChannelProtocol.js +1 -0
  39. package/dist/cjs/securechannel/SecureChannelProtocol.js.map +1 -1
  40. package/dist/cjs/session/case/CaseServer.d.ts +1 -0
  41. package/dist/cjs/session/case/CaseServer.d.ts.map +1 -1
  42. package/dist/cjs/session/case/CaseServer.js +1 -0
  43. package/dist/cjs/session/case/CaseServer.js.map +1 -1
  44. package/dist/cjs/session/pase/PaseServer.d.ts +1 -0
  45. package/dist/cjs/session/pase/PaseServer.d.ts.map +1 -1
  46. package/dist/cjs/session/pase/PaseServer.js +1 -0
  47. package/dist/cjs/session/pase/PaseServer.js.map +1 -1
  48. package/dist/esm/action/response/ReadResult.d.ts +4 -0
  49. package/dist/esm/action/response/ReadResult.d.ts.map +1 -1
  50. package/dist/esm/action/server/AttributeResponse.d.ts +1 -1
  51. package/dist/esm/action/server/AttributeResponse.d.ts.map +1 -1
  52. package/dist/esm/action/server/AttributeResponse.js +37 -17
  53. package/dist/esm/action/server/AttributeResponse.js.map +1 -1
  54. package/dist/esm/interaction/AttributeDataEncoder.d.ts +1 -1
  55. package/dist/esm/interaction/AttributeDataEncoder.d.ts.map +1 -1
  56. package/dist/esm/interaction/InteractionEndpointStructure.d.ts +37 -1
  57. package/dist/esm/interaction/InteractionEndpointStructure.d.ts.map +1 -1
  58. package/dist/esm/interaction/InteractionEndpointStructure.js +21 -7
  59. package/dist/esm/interaction/InteractionEndpointStructure.js.map +1 -1
  60. package/dist/esm/interaction/InteractionMessenger.js +1 -1
  61. package/dist/esm/interaction/InteractionMessenger.js.map +1 -1
  62. package/dist/esm/interaction/ServerSubscription.d.ts +1 -2
  63. package/dist/esm/interaction/ServerSubscription.d.ts.map +1 -1
  64. package/dist/esm/interaction/ServerSubscription.js +4 -4
  65. package/dist/esm/interaction/ServerSubscription.js.map +1 -1
  66. package/dist/esm/interaction/SubscriptionClient.d.ts +2 -1
  67. package/dist/esm/interaction/SubscriptionClient.d.ts.map +1 -1
  68. package/dist/esm/interaction/SubscriptionClient.js +2 -1
  69. package/dist/esm/interaction/SubscriptionClient.js.map +1 -1
  70. package/dist/esm/interaction/index.d.ts +0 -1
  71. package/dist/esm/interaction/index.d.ts.map +1 -1
  72. package/dist/esm/interaction/index.js +0 -1
  73. package/dist/esm/interaction/index.js.map +1 -1
  74. package/dist/esm/protocol/ExchangeManager.d.ts.map +1 -1
  75. package/dist/esm/protocol/ExchangeManager.js +17 -2
  76. package/dist/esm/protocol/ExchangeManager.js.map +1 -1
  77. package/dist/esm/protocol/MessageExchange.d.ts +2 -1
  78. package/dist/esm/protocol/MessageExchange.d.ts.map +1 -1
  79. package/dist/esm/protocol/MessageExchange.js +6 -3
  80. package/dist/esm/protocol/MessageExchange.js.map +1 -1
  81. package/dist/esm/protocol/ProtocolHandler.d.ts +1 -0
  82. package/dist/esm/protocol/ProtocolHandler.d.ts.map +1 -1
  83. package/dist/esm/securechannel/SecureChannelProtocol.d.ts +1 -0
  84. package/dist/esm/securechannel/SecureChannelProtocol.d.ts.map +1 -1
  85. package/dist/esm/securechannel/SecureChannelProtocol.js +1 -0
  86. package/dist/esm/securechannel/SecureChannelProtocol.js.map +1 -1
  87. package/dist/esm/session/case/CaseServer.d.ts +1 -0
  88. package/dist/esm/session/case/CaseServer.d.ts.map +1 -1
  89. package/dist/esm/session/case/CaseServer.js +1 -0
  90. package/dist/esm/session/case/CaseServer.js.map +1 -1
  91. package/dist/esm/session/pase/PaseServer.d.ts +1 -0
  92. package/dist/esm/session/pase/PaseServer.d.ts.map +1 -1
  93. package/dist/esm/session/pase/PaseServer.js +1 -0
  94. package/dist/esm/session/pase/PaseServer.js.map +1 -1
  95. package/package.json +6 -6
  96. package/src/action/response/ReadResult.ts +4 -0
  97. package/src/action/server/AttributeResponse.ts +40 -17
  98. package/src/interaction/AttributeDataEncoder.ts +1 -1
  99. package/src/interaction/InteractionEndpointStructure.ts +62 -12
  100. package/src/interaction/InteractionMessenger.ts +1 -1
  101. package/src/interaction/ServerSubscription.ts +5 -5
  102. package/src/interaction/SubscriptionClient.ts +2 -2
  103. package/src/interaction/index.ts +0 -1
  104. package/src/protocol/ExchangeManager.ts +36 -2
  105. package/src/protocol/MessageExchange.ts +6 -3
  106. package/src/protocol/ProtocolHandler.ts +1 -0
  107. package/src/securechannel/SecureChannelProtocol.ts +1 -0
  108. package/src/session/case/CaseServer.ts +1 -0
  109. package/src/session/pase/PaseServer.ts +1 -0
  110. package/dist/cjs/interaction/InteractionServer.d.ts +0 -132
  111. package/dist/cjs/interaction/InteractionServer.d.ts.map +0 -1
  112. package/dist/cjs/interaction/InteractionServer.js +0 -1166
  113. package/dist/cjs/interaction/InteractionServer.js.map +0 -6
  114. package/dist/esm/interaction/InteractionServer.d.ts +0 -132
  115. package/dist/esm/interaction/InteractionServer.d.ts.map +0 -1
  116. package/dist/esm/interaction/InteractionServer.js +0 -1177
  117. package/dist/esm/interaction/InteractionServer.js.map +0 -6
  118. package/src/interaction/InteractionServer.ts +0 -1649
@@ -22,8 +22,10 @@ import {
22
22
  StatusResponseError,
23
23
  WildcardPathFlagsBitmap,
24
24
  } from "#types";
25
+ import { DataModelPath } from "@matter/model";
26
+ import { TlvSchema } from "@matter/types";
25
27
 
26
- export const GlobalAttrIds = new Set(Object.values(GlobalAttributes).map(attr => attr.id));
28
+ export const GlobalAttrIds = new Set(Object.values(GlobalAttributes({})).map(attr => attr.id));
27
29
  export const WildcardPathFlagsCodec = BitmapSchema(WildcardPathFlagsBitmap);
28
30
  export const FallbackLimits: AccessControl.Limits = {
29
31
  fabricScoped: false,
@@ -188,7 +190,17 @@ export class AttributeResponse<SessionT extends AccessControl.Session = AccessCo
188
190
  }
189
191
 
190
192
  // Validate access. Order here prescribed by 1.4 core spec 8.4.3.2
191
- switch (this.#session.authorityAt(limits.readLevel)) {
193
+ // We need some fallback location if cluster is not defined
194
+ const location = {
195
+ ...(cluster?.location ?? {
196
+ path: DataModelPath.none,
197
+ endpoint: endpointId,
198
+ cluster: clusterId,
199
+ }),
200
+ owningFabric: this.#session.fabric,
201
+ };
202
+ const permission = this.#session.authorityAt(limits.readLevel, location);
203
+ switch (permission) {
192
204
  case AccessControl.Authority.Granted:
193
205
  break;
194
206
 
@@ -201,9 +213,7 @@ export class AttributeResponse<SessionT extends AccessControl.Session = AccessCo
201
213
  return;
202
214
 
203
215
  default:
204
- throw new InternalError(
205
- `Unsupported authorization state ${this.#session.authorityAt(limits.readLevel)}`,
206
- );
216
+ throw new InternalError(`Unsupported authorization state ${permission}`);
207
217
  }
208
218
  if (endpoint === undefined) {
209
219
  this.#addStatus(path, Status.UnsupportedEndpoint);
@@ -246,8 +256,13 @@ export class AttributeResponse<SessionT extends AccessControl.Session = AccessCo
246
256
  this.#currentState = cluster.open(this.#session);
247
257
  }
248
258
 
249
- // Perform actual read
250
- this.#addValue(path, this.#currentState);
259
+ // Perform actual read of one attribute
260
+ this.#addValue(
261
+ path,
262
+ this.#currentState[attributeId],
263
+ cluster.version,
264
+ this.#currentCluster.type.attributes[attributeId]!.tlv,
265
+ );
251
266
  });
252
267
  }
253
268
 
@@ -344,15 +359,21 @@ export class AttributeResponse<SessionT extends AccessControl.Session = AccessCo
344
359
  if (this.#currentState === undefined) {
345
360
  this.#currentState = this.#currentCluster!.open(this.#session);
346
361
  }
347
- this.#addValue(
348
- {
349
- ...path,
350
- endpointId: this.#currentEndpoint?.id as EndpointNumber,
351
- clusterId: this.#currentCluster?.type.id as ClusterId,
352
- attributeId: attribute.id,
353
- },
354
- this.#currentState[attribute.id],
355
- );
362
+ const value = this.#currentState[attribute.id];
363
+ if (value !== undefined) {
364
+ // Only if we have a state value set
365
+ this.#addValue(
366
+ {
367
+ ...path,
368
+ endpointId: this.#currentEndpoint?.id as EndpointNumber,
369
+ clusterId: this.#currentCluster?.type.id as ClusterId,
370
+ attributeId: attribute.id,
371
+ },
372
+ this.#currentState[attribute.id],
373
+ this.#currentCluster!.version,
374
+ attribute.tlv,
375
+ );
376
+ }
356
377
  }
357
378
 
358
379
  /**
@@ -386,11 +407,13 @@ export class AttributeResponse<SessionT extends AccessControl.Session = AccessCo
386
407
  /**
387
408
  * Add an attribute value.
388
409
  */
389
- #addValue(path: ReadResult.ConcreteAttributePath, value: unknown) {
410
+ #addValue(path: ReadResult.ConcreteAttributePath, value: unknown, version: number, tlv: TlvSchema<unknown>) {
390
411
  const report: ReadResult.AttributeValue = {
391
412
  kind: "attr-value",
392
413
  path,
393
414
  value,
415
+ version,
416
+ tlv,
394
417
  };
395
418
 
396
419
  if (this.#chunk) {
@@ -68,7 +68,7 @@ export type DataReportPayload = BaseDataReport & {
68
68
  /**
69
69
  * Type for the DataReport Generator function to send all data
70
70
  */
71
- export type DataReportPayloadIterator = IterableIterator<EventOrAttributeDataPayload>;
71
+ export type DataReportPayloadIterator = AsyncIterableIterator<EventOrAttributeDataPayload>;
72
72
 
73
73
  export function encodeAttributePayloadData(
74
74
  attributePayload: AttributeReportPayload,
@@ -30,23 +30,73 @@ import {
30
30
  TypeFromSchema,
31
31
  WildcardPathFlagsBitmap,
32
32
  } from "#types";
33
+ import { TlvClusterPath } from "@matter/types";
33
34
  import { AnyAttributeServer } from "../cluster/server/AttributeServer.js";
34
35
  import { ClusterServer } from "../cluster/server/ClusterServer.js";
35
36
  import { CommandServer } from "../cluster/server/CommandServer.js";
36
37
  import { AnyEventServer } from "../cluster/server/EventServer.js";
37
38
  import { EndpointInterface } from "../endpoint/EndpointInterface.js";
38
- import {
39
- AttributePath,
40
- AttributeWithPath,
41
- CommandPath,
42
- CommandWithPath,
43
- EventPath,
44
- EventWithPath,
45
- attributePathToId,
46
- commandPathToId,
47
- eventPathToId,
48
- genericElementPathToId,
49
- } from "./InteractionServer.js";
39
+
40
+ export interface CommandPath {
41
+ nodeId?: NodeId;
42
+ endpointId: EndpointNumber;
43
+ clusterId: ClusterId;
44
+ commandId: CommandId;
45
+ }
46
+
47
+ export interface AttributePath {
48
+ nodeId?: NodeId;
49
+ endpointId: EndpointNumber;
50
+ clusterId: ClusterId;
51
+ attributeId: AttributeId;
52
+ }
53
+
54
+ export interface EventPath {
55
+ nodeId?: NodeId;
56
+ endpointId: EndpointNumber;
57
+ clusterId: ClusterId;
58
+ eventId: EventId;
59
+ isUrgent?: boolean;
60
+ }
61
+
62
+ export interface AttributeWithPath {
63
+ path: AttributePath;
64
+ attribute: AnyAttributeServer<any>;
65
+ }
66
+
67
+ export interface EventWithPath {
68
+ path: EventPath;
69
+ event: AnyEventServer<any, any>;
70
+ }
71
+
72
+ export interface CommandWithPath {
73
+ path: CommandPath;
74
+ command: CommandServer<any, any>;
75
+ }
76
+
77
+ export function genericElementPathToId(
78
+ endpointId: EndpointNumber | undefined,
79
+ clusterId: ClusterId | undefined,
80
+ elementId: number | undefined,
81
+ ) {
82
+ return `${endpointId}/${clusterId}/${elementId}`;
83
+ }
84
+
85
+ export function commandPathToId({ endpointId, clusterId, commandId }: CommandPath) {
86
+ return genericElementPathToId(endpointId, clusterId, commandId);
87
+ }
88
+
89
+ export function attributePathToId({ endpointId, clusterId, attributeId }: TypeFromSchema<typeof TlvAttributePath>) {
90
+ return genericElementPathToId(endpointId, clusterId, attributeId);
91
+ }
92
+
93
+ export function eventPathToId({ endpointId, clusterId, eventId }: TypeFromSchema<typeof TlvEventPath>) {
94
+ return genericElementPathToId(endpointId, clusterId, eventId);
95
+ }
96
+
97
+ export function clusterPathToId({ nodeId, endpointId, clusterId }: TypeFromSchema<typeof TlvClusterPath>) {
98
+ return `${nodeId}/${endpointId}/${clusterId}`;
99
+ }
50
100
 
51
101
  /**
52
102
  * List of global attributes to skip when the WildcardSkipGlobalAttributes bit is set in an Wildcard Path Flags
@@ -383,7 +383,7 @@ export class InteractionServerMessenger extends InteractionMessenger {
383
383
  !processQueueFirst &&
384
384
  !attributeReportsToSend[0].needSendNext))
385
385
  ) {
386
- const { done, value } = payload.next();
386
+ const { done, value } = await payload.next();
387
387
  if (done) {
388
388
  allDataReceived = true;
389
389
  if (attributeReportsToSend.length === 0 && eventReportsToSend.length === 0) {
@@ -40,17 +40,17 @@ import { AnyAttributeServer, FabricScopedAttributeServer } from "../cluster/serv
40
40
  import { AnyEventServer, FabricSensitiveEventServer } from "../cluster/server/EventServer.js";
41
41
  import { NoChannelError } from "../protocol/ChannelManager.js";
42
42
  import { EventReportPayload } from "./AttributeDataEncoder.js";
43
- import { InteractionEndpointStructure } from "./InteractionEndpointStructure.js";
44
- import { InteractionServerMessenger } from "./InteractionMessenger.js";
45
43
  import {
46
44
  AttributePath,
47
45
  AttributeWithPath,
48
46
  EventPath,
49
47
  EventWithPath,
48
+ InteractionEndpointStructure,
50
49
  attributePathToId,
51
50
  clusterPathToId,
52
51
  eventPathToId,
53
- } from "./InteractionServer.js";
52
+ } from "./InteractionEndpointStructure.js";
53
+ import { InteractionServerMessenger } from "./InteractionMessenger.js";
54
54
  import { Subscription, SubscriptionCriteria } from "./Subscription.js";
55
55
 
56
56
  const logger = Logger.get("ServerSubscription");
@@ -722,7 +722,7 @@ export class ServerSubscription extends Subscription {
722
722
  * A thrown exception will cancel the sending process immediately.
723
723
  * TODO: Streamline all this with the normal Read flow to also handle Concrete Path subscriptions with errors correctly
724
724
  */
725
- *#iterateInitialSubscriptionData(
725
+ async *#iterateInitialSubscriptionData(
726
726
  attributesToSend: {
727
727
  newAttributes: AttributeWithPath[];
728
728
  attributeErrors: TypeFromSchema<typeof TlvAttributeStatus>[];
@@ -955,7 +955,7 @@ export class ServerSubscription extends Subscription {
955
955
  * the controller.
956
956
  * A thrown exception will cancel the sending process immediately.
957
957
  */
958
- *#iterateDataUpdate(attributes: AttributePathWithValueVersion<any>[], events: EventPathWithEventData<any>[]) {
958
+ async *#iterateDataUpdate(attributes: AttributePathWithValueVersion<any>[], events: EventPathWithEventData<any>[]) {
959
959
  for (const {
960
960
  path,
961
961
  schema,
@@ -26,6 +26,8 @@ export interface RegisteredSubscription {
26
26
  * Incoming data reports must match to a subscription registered with {@link add} or the exchange is invalid.
27
27
  */
28
28
  export class SubscriptionClient implements ProtocolHandler {
29
+ readonly id = INTERACTION_PROTOCOL_ID;
30
+ readonly requiresSecureSession = true;
29
31
  readonly #listeners = new Map<number, (dataReport: DataReport) => MaybePromise<void>>();
30
32
  readonly #timeouts = new Map<number, Timer>();
31
33
 
@@ -37,8 +39,6 @@ export class SubscriptionClient implements ProtocolHandler {
37
39
  return client;
38
40
  }
39
41
 
40
- readonly id = INTERACTION_PROTOCOL_ID;
41
-
42
42
  /**
43
43
  * Register a subscription.
44
44
  */
@@ -11,7 +11,6 @@ export * from "./EventDataDecoder.js";
11
11
  export * from "./InteractionClient.js";
12
12
  export * from "./InteractionEndpointStructure.js";
13
13
  export * from "./InteractionMessenger.js";
14
- export * from "./InteractionServer.js";
15
14
  export * from "./ServerSubscription.js";
16
15
  export * from "./Subscription.js";
17
16
  export * from "./SubscriptionClient.js";
@@ -238,7 +238,7 @@ export class ExchangeManager {
238
238
 
239
239
  let isDuplicate;
240
240
  try {
241
- session?.updateMessageCounter(packet.header.messageId, packet.header.sourceNodeId);
241
+ session.updateMessageCounter(packet.header.messageId, packet.header.sourceNodeId);
242
242
  isDuplicate = false;
243
243
  } catch (e) {
244
244
  DuplicateMessageError.accept(e);
@@ -260,6 +260,27 @@ export class ExchangeManager {
260
260
  }
261
261
 
262
262
  if (exchange !== undefined) {
263
+ if (
264
+ exchange.requiresSecureSession !== session.isSecure ||
265
+ exchange.session.id !== packet.header.sessionId ||
266
+ exchange.isClosing
267
+ ) {
268
+ logger.debug(
269
+ `Ignoring message ${messageId} for protocol ${message.payloadHeader.protocolId} and exchange id ${message.payloadHeader.exchangeId} on channel ${channel.name} because ${
270
+ exchange.isClosing
271
+ ? "exchange is closing"
272
+ : exchange.session.id !== packet.header.sessionId
273
+ ? `session ID mismatch ${exchange.session.id} vs ${packet.header.sessionId}`
274
+ : `session security requirements (${exchange.requiresSecureSession}) not fulfilled`
275
+ }`,
276
+ );
277
+ await exchange.send(SecureMessageType.StandaloneAck, new Uint8Array(0), {
278
+ includeAcknowledgeMessageId: message.packetHeader.messageId,
279
+ });
280
+ await exchange.close();
281
+ return;
282
+ }
283
+
263
284
  await exchange.onMessageReceived(message, isDuplicate);
264
285
  } else {
265
286
  if (this.#closing) return;
@@ -271,7 +292,20 @@ export class ExchangeManager {
271
292
 
272
293
  const protocolHandler = this.#protocols.get(message.payloadHeader.protocolId);
273
294
 
274
- if (protocolHandler !== undefined && message.payloadHeader.isInitiatorMessage && !isDuplicate) {
295
+ // Having a "Secure Session" means it is encrypted in our internal working
296
+ // TODO When adding Group sessions, we need to check how to adjust that handling
297
+ if (protocolHandler !== undefined && protocolHandler.requiresSecureSession !== session.isSecure) {
298
+ logger.debug(
299
+ `Ignoring message ${messageId} for protocol ${message.payloadHeader.protocolId} and exchange id ${message.payloadHeader.exchangeId} on channel ${channel.name} because not matching the security requirements.`,
300
+ );
301
+ }
302
+
303
+ if (
304
+ protocolHandler !== undefined &&
305
+ message.payloadHeader.isInitiatorMessage &&
306
+ !isDuplicate &&
307
+ protocolHandler.requiresSecureSession === session.isSecure
308
+ ) {
275
309
  if (
276
310
  message.payloadHeader.messageType == SecureMessageType.StandaloneAck &&
277
311
  !message.payloadHeader.requiresAck
@@ -142,6 +142,7 @@ export class MessageExchange {
142
142
  initialMessage.packetHeader.sourceNodeId,
143
143
  initialMessage.payloadHeader.exchangeId,
144
144
  initialMessage.payloadHeader.protocolId,
145
+ session.isSecure,
145
146
  );
146
147
  }
147
148
 
@@ -157,6 +158,7 @@ export class MessageExchange {
157
158
  session.peerNodeId,
158
159
  exchangeId,
159
160
  protocolId,
161
+ session.isSecure,
160
162
  );
161
163
  }
162
164
 
@@ -201,6 +203,7 @@ export class MessageExchange {
201
203
  peerNodeId: NodeId | undefined,
202
204
  exchangeId: number,
203
205
  protocolId: number,
206
+ readonly requiresSecureSession: boolean,
204
207
  ) {
205
208
  const { channel } = context;
206
209
  const { session } = channel;
@@ -282,7 +285,7 @@ export class MessageExchange {
282
285
  async onMessageReceived(message: Message, duplicate = false) {
283
286
  logger.debug("Message «", MessageCodec.messageDiagnostics(message, { duplicate }));
284
287
 
285
- // Adjust the incoming message when ack was required but this exchange do not use it to skip all relevant logic
288
+ // Adjust the incoming message when ack was required, but this exchange does not use it to skip all relevant logic
286
289
  if (message.payloadHeader.requiresAck && !this.#useMRP) {
287
290
  logger.debug("Ignoring ack-required flag because MRP is not used for this exchange");
288
291
  message.payloadHeader.requiresAck = false;
@@ -303,14 +306,14 @@ export class MessageExchange {
303
306
  this.session.notifyActivity(true);
304
307
 
305
308
  if (duplicate) {
306
- // Received a message retransmission but the reply is not ready yet, ignoring
309
+ // Received a message retransmission, but the reply is not ready yet, ignoring
307
310
  if (requiresAck) {
308
311
  await this.sendStandaloneAckForMessage(message);
309
312
  }
310
313
  return;
311
314
  }
312
315
  if (messageId === this.#sentMessageToAck?.payloadHeader.ackedMessageId) {
313
- // Received a message retransmission, this means that the other side didn't get our ack
316
+ // Received a message retransmission. This means that the other side didn't get our ack
314
317
  // Resending the previous reply message which contains the ack
315
318
  await this.channel.send(this.#sentMessageToAck);
316
319
  return;
@@ -9,6 +9,7 @@ import { MessageExchange } from "./MessageExchange.js";
9
9
 
10
10
  export interface ProtocolHandler {
11
11
  readonly id: number;
12
+ readonly requiresSecureSession: boolean;
12
13
  onNewExchange(exchange: MessageExchange, message: Message): Promise<void>;
13
14
  close(): Promise<void>;
14
15
  }
@@ -29,6 +29,7 @@ const logger = Logger.get("SecureChannelProtocol");
29
29
 
30
30
  export class StatusReportOnlySecureChannelProtocol implements ProtocolHandler {
31
31
  readonly id = SECURE_CHANNEL_PROTOCOL_ID;
32
+ readonly requiresSecureSession = false;
32
33
 
33
34
  async onNewExchange(exchange: MessageExchange, message: Message) {
34
35
  const messageType = message.payloadHeader.messageType;
@@ -31,6 +31,7 @@ const logger = Logger.get("CaseServer");
31
31
 
32
32
  export class CaseServer implements ProtocolHandler {
33
33
  readonly id = SECURE_CHANNEL_PROTOCOL_ID;
34
+ readonly requiresSecureSession = false;
34
35
 
35
36
  #sessions: SessionManager;
36
37
  #fabrics: FabricManager;
@@ -34,6 +34,7 @@ export class MaximumPasePairingErrorsReachedError extends MatterFlowError {}
34
34
 
35
35
  export class PaseServer implements ProtocolHandler {
36
36
  readonly id = SECURE_CHANNEL_PROTOCOL_ID;
37
+ readonly requiresSecureSession = false;
37
38
 
38
39
  #pairingTimer: Timer | undefined;
39
40
  #pairingErrors = 0;
@@ -1,132 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2022-2025 Matter.js Authors
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import { Observable, ServerAddressIp } from "#general";
7
- import { PeerAddress } from "#peer/PeerAddress.js";
8
- import { SessionManager } from "#session/SessionManager.js";
9
- import { AttributeId, ClusterId, CommandId, EndpointNumber, EventId, NodeId, StatusCode, TlvAttributePath, TlvClusterPath, TlvEventFilter, TlvEventPath, TypeFromSchema } from "#types";
10
- import { AnyAttributeServer, AttributeServer } from "../cluster/server/AttributeServer.js";
11
- import { CommandServer } from "../cluster/server/CommandServer.js";
12
- import { AnyEventServer } from "../cluster/server/EventServer.js";
13
- import { Message } from "../codec/MessageCodec.js";
14
- import { EndpointInterface } from "../endpoint/EndpointInterface.js";
15
- import { MessageExchange } from "../protocol/MessageExchange.js";
16
- import { ProtocolHandler } from "../protocol/ProtocolHandler.js";
17
- import { SecureSession } from "../session/SecureSession.js";
18
- import { DataReportPayloadIterator } from "./AttributeDataEncoder.js";
19
- import { InteractionEndpointStructure } from "./InteractionEndpointStructure.js";
20
- import { DataReport, InteractionRecipient, InteractionServerMessenger, InvokeRequest, ReadRequest, SubscribeRequest, TimedRequest, WriteRequest, WriteResponse } from "./InteractionMessenger.js";
21
- import { ServerSubscription } from "./ServerSubscription.js";
22
- import { ServerSubscriptionConfig } from "./SubscriptionOptions.js";
23
- export interface PeerSubscription {
24
- subscriptionId: number;
25
- peerAddress: PeerAddress;
26
- minIntervalFloorSeconds: number;
27
- maxIntervalCeilingSeconds: number;
28
- attributeRequests?: TypeFromSchema<typeof TlvAttributePath>[];
29
- eventRequests?: TypeFromSchema<typeof TlvEventPath>[];
30
- isFabricFiltered: boolean;
31
- maxInterval: number;
32
- sendInterval: number;
33
- operationalAddress?: ServerAddressIp;
34
- }
35
- export interface CommandPath {
36
- nodeId?: NodeId;
37
- endpointId: EndpointNumber;
38
- clusterId: ClusterId;
39
- commandId: CommandId;
40
- }
41
- export interface AttributePath {
42
- nodeId?: NodeId;
43
- endpointId: EndpointNumber;
44
- clusterId: ClusterId;
45
- attributeId: AttributeId;
46
- }
47
- export interface EventPath {
48
- nodeId?: NodeId;
49
- endpointId: EndpointNumber;
50
- clusterId: ClusterId;
51
- eventId: EventId;
52
- isUrgent?: boolean;
53
- }
54
- export interface AttributeWithPath {
55
- path: AttributePath;
56
- attribute: AnyAttributeServer<any>;
57
- }
58
- export interface EventWithPath {
59
- path: EventPath;
60
- event: AnyEventServer<any, any>;
61
- }
62
- export interface CommandWithPath {
63
- path: CommandPath;
64
- command: CommandServer<any, any>;
65
- }
66
- export declare function genericElementPathToId(endpointId: EndpointNumber | undefined, clusterId: ClusterId | undefined, elementId: number | undefined): string;
67
- export declare function commandPathToId({ endpointId, clusterId, commandId }: CommandPath): string;
68
- export declare function attributePathToId({ endpointId, clusterId, attributeId }: TypeFromSchema<typeof TlvAttributePath>): string;
69
- export declare function eventPathToId({ endpointId, clusterId, eventId }: TypeFromSchema<typeof TlvEventPath>): string;
70
- export declare function clusterPathToId({ nodeId, endpointId, clusterId }: TypeFromSchema<typeof TlvClusterPath>): string;
71
- export declare function validateReadAttributesPath(path: TypeFromSchema<typeof TlvAttributePath>, isGroupSession?: boolean): void;
72
- export declare function validateReadEventPath(path: TypeFromSchema<typeof TlvEventPath>, isGroupSession?: boolean): void;
73
- /**
74
- * Interfaces {@link InteractionServer} with other components.
75
- */
76
- export interface InteractionContext {
77
- readonly sessions: SessionManager;
78
- readonly structure: InteractionEndpointStructure;
79
- readonly subscriptionOptions?: Partial<ServerSubscriptionConfig>;
80
- readonly maxPathsPerInvoke?: number;
81
- initiateExchange(address: PeerAddress, protocolId: number): MessageExchange;
82
- }
83
- /**
84
- * Translates interactions from the Matter protocol to matter.js APIs.
85
- */
86
- export declare class InteractionServer implements ProtocolHandler, InteractionRecipient {
87
- #private;
88
- readonly id = 1;
89
- constructor(context: InteractionContext);
90
- protected get isClosing(): boolean;
91
- get maxPathsPerInvoke(): number;
92
- get subscriptionEstablishmentStarted(): Observable<[peerAddress: PeerAddress], void>;
93
- onNewExchange(exchange: MessageExchange, message: Message): Promise<void>;
94
- get clientHandler(): ProtocolHandler | undefined;
95
- set clientHandler(clientHandler: ProtocolHandler);
96
- handleReadRequest(exchange: MessageExchange, readRequest: ReadRequest, message: Message): Promise<{
97
- dataReport: DataReport;
98
- payload?: DataReportPayloadIterator;
99
- }>;
100
- protected readAttribute(_path: AttributePath, attribute: AnyAttributeServer<any>, exchange: MessageExchange, isFabricFiltered: boolean, message: Message, offline?: boolean): {
101
- version: number;
102
- value: any;
103
- };
104
- /**
105
- * Reads the attributes for the given endpoint.
106
- * This can currently only be used for subscriptions because errors are ignored!
107
- */
108
- protected readEndpointAttributesForSubscription(attributes: {
109
- path: AttributePath;
110
- attribute: AnyAttributeServer<any>;
111
- }[], exchange: MessageExchange, isFabricFiltered: boolean, message: Message, offline?: boolean): {
112
- path: AttributePath;
113
- attribute: AnyAttributeServer<unknown>;
114
- value: any;
115
- version: number;
116
- }[];
117
- protected readEvent(_path: EventPath, eventFilters: TypeFromSchema<typeof TlvEventFilter>[] | undefined, event: AnyEventServer<any, any>, exchange: MessageExchange, isFabricFiltered: boolean, message: Message): Promise<import("../index.js").NumberedOccurrence[]>;
118
- handleWriteRequest(exchange: MessageExchange, { suppressResponse, timedRequest, writeRequests, interactionModelRevision, moreChunkedMessages }: WriteRequest, message: Message): Promise<WriteResponse>;
119
- protected writeAttribute(_path: AttributePath, attribute: AttributeServer<any>, value: any, exchange: MessageExchange, message: Message, _endpoint: EndpointInterface, _receivedWithinTimedInteraction?: boolean, isListWrite?: boolean): Promise<void>;
120
- handleSubscribeRequest(exchange: MessageExchange, request: SubscribeRequest, messenger: InteractionServerMessenger, message: Message): Promise<void>;
121
- establishFormerSubscription({ subscriptionId, attributeRequests, eventRequests, isFabricFiltered, minIntervalFloorSeconds, maxIntervalCeilingSeconds, maxInterval, sendInterval, }: PeerSubscription, session: SecureSession): Promise<ServerSubscription>;
122
- handleInvokeRequest(exchange: MessageExchange, { invokeRequests, timedRequest, suppressResponse, interactionModelRevision }: InvokeRequest, messenger: InteractionServerMessenger, message: Message): Promise<void>;
123
- protected invokeCommand(_path: CommandPath, command: CommandServer<any, any>, exchange: MessageExchange, commandFields: any, message: Message, endpoint: EndpointInterface, _receivedWithinTimedInteraction?: boolean): Promise<{
124
- code: StatusCode;
125
- clusterCode?: number;
126
- responseId: CommandId;
127
- response: import("#types").TlvStream;
128
- }>;
129
- handleTimedRequest(exchange: MessageExchange, { timeout, interactionModelRevision }: TimedRequest): void;
130
- close(): Promise<void>;
131
- }
132
- //# sourceMappingURL=InteractionServer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InteractionServer.d.ts","sourceRoot":"","sources":["../../../src/interaction/InteractionServer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAQH,UAAU,EACV,eAAe,EAClB,MAAM,UA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