@matter/protocol 0.12.4-alpha.0-20250211-56b2c53a0 → 0.12.4-alpha.0-20250212-b2729c9eb

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 (236) hide show
  1. package/dist/cjs/action/Interactable.d.ts +36 -0
  2. package/dist/cjs/action/Interactable.d.ts.map +1 -0
  3. package/dist/cjs/action/Interactable.js +22 -0
  4. package/dist/cjs/action/Interactable.js.map +6 -0
  5. package/dist/cjs/action/Val.d.ts +94 -0
  6. package/dist/cjs/action/Val.d.ts.map +1 -0
  7. package/dist/cjs/action/Val.js +33 -0
  8. package/dist/cjs/action/Val.js.map +6 -0
  9. package/dist/cjs/action/errors.d.ts +69 -0
  10. package/dist/cjs/action/errors.d.ts.map +1 -0
  11. package/dist/cjs/action/errors.js +108 -0
  12. package/dist/cjs/action/errors.js.map +6 -0
  13. package/dist/cjs/action/index.d.ts +13 -0
  14. package/dist/cjs/action/index.d.ts.map +1 -0
  15. package/dist/cjs/action/index.js +30 -0
  16. package/dist/cjs/action/index.js.map +6 -0
  17. package/dist/cjs/action/protocols.d.ts +118 -0
  18. package/dist/cjs/action/protocols.d.ts.map +1 -0
  19. package/dist/cjs/action/protocols.js +22 -0
  20. package/dist/cjs/action/protocols.js.map +6 -0
  21. package/dist/cjs/action/request/Invoke.d.ts +35 -0
  22. package/dist/cjs/action/request/Invoke.d.ts.map +1 -0
  23. package/dist/cjs/action/request/Invoke.js +80 -0
  24. package/dist/cjs/action/request/Invoke.js.map +6 -0
  25. package/dist/cjs/action/request/MalformedRequestError.d.ts +14 -0
  26. package/dist/cjs/action/request/MalformedRequestError.d.ts.map +1 -0
  27. package/dist/cjs/action/request/MalformedRequestError.js +32 -0
  28. package/dist/cjs/action/request/MalformedRequestError.js.map +6 -0
  29. package/dist/cjs/action/request/Read.d.ts +141 -0
  30. package/dist/cjs/action/request/Read.d.ts.map +1 -0
  31. package/dist/cjs/action/request/Read.js +173 -0
  32. package/dist/cjs/action/request/Read.js.map +6 -0
  33. package/dist/cjs/action/request/Specifier.d.ts +82 -0
  34. package/dist/cjs/action/request/Specifier.d.ts.map +1 -0
  35. package/dist/cjs/action/request/Specifier.js +88 -0
  36. package/dist/cjs/action/request/Specifier.js.map +6 -0
  37. package/dist/cjs/action/request/Subscribe.d.ts +26 -0
  38. package/dist/cjs/action/request/Subscribe.d.ts.map +1 -0
  39. package/dist/cjs/action/request/Subscribe.js +50 -0
  40. package/dist/cjs/action/request/Subscribe.js.map +6 -0
  41. package/dist/cjs/action/request/Write.d.ts +10 -0
  42. package/dist/cjs/action/request/Write.d.ts.map +1 -0
  43. package/dist/cjs/action/request/Write.js +22 -0
  44. package/dist/cjs/action/request/Write.js.map +6 -0
  45. package/dist/cjs/action/request/index.d.ts +11 -0
  46. package/dist/cjs/action/request/index.d.ts.map +1 -0
  47. package/dist/cjs/action/request/index.js +28 -0
  48. package/dist/cjs/action/request/index.js.map +6 -0
  49. package/dist/cjs/action/response/InvokeResult.d.ts +15 -0
  50. package/dist/cjs/action/response/InvokeResult.d.ts.map +1 -0
  51. package/dist/cjs/action/response/InvokeResult.js +22 -0
  52. package/dist/cjs/action/response/InvokeResult.js.map +6 -0
  53. package/dist/cjs/action/response/ReadResult.d.ts +63 -0
  54. package/dist/cjs/action/response/ReadResult.d.ts.map +1 -0
  55. package/dist/cjs/action/response/ReadResult.js +22 -0
  56. package/dist/cjs/action/response/ReadResult.js.map +6 -0
  57. package/dist/cjs/action/response/SubscribeResult.d.ts +13 -0
  58. package/dist/cjs/action/response/SubscribeResult.d.ts.map +1 -0
  59. package/dist/cjs/action/response/SubscribeResult.js +22 -0
  60. package/dist/cjs/action/response/SubscribeResult.js.map +6 -0
  61. package/dist/cjs/action/response/WriteResult.d.ts +12 -0
  62. package/dist/cjs/action/response/WriteResult.d.ts.map +1 -0
  63. package/dist/cjs/action/response/WriteResult.js +22 -0
  64. package/dist/cjs/action/response/WriteResult.js.map +6 -0
  65. package/dist/cjs/action/response/index.d.ts +10 -0
  66. package/dist/cjs/action/response/index.d.ts.map +1 -0
  67. package/dist/cjs/action/response/index.js +27 -0
  68. package/dist/cjs/action/response/index.js.map +6 -0
  69. package/dist/cjs/action/server/AccessControl.d.ts +152 -0
  70. package/dist/cjs/action/server/AccessControl.d.ts.map +1 -0
  71. package/dist/cjs/action/server/AccessControl.js +287 -0
  72. package/dist/cjs/action/server/AccessControl.js.map +6 -0
  73. package/dist/cjs/action/server/AttributeResponse.d.ts +36 -0
  74. package/dist/cjs/action/server/AttributeResponse.d.ts.map +1 -0
  75. package/dist/cjs/action/server/AttributeResponse.js +352 -0
  76. package/dist/cjs/action/server/AttributeResponse.js.map +6 -0
  77. package/dist/cjs/action/server/ServerInteraction.d.ts +35 -0
  78. package/dist/cjs/action/server/ServerInteraction.d.ts.map +1 -0
  79. package/dist/cjs/action/server/ServerInteraction.js +52 -0
  80. package/dist/cjs/action/server/ServerInteraction.js.map +6 -0
  81. package/dist/cjs/action/server/index.d.ts +9 -0
  82. package/dist/cjs/action/server/index.d.ts.map +1 -0
  83. package/dist/cjs/action/server/index.js +26 -0
  84. package/dist/cjs/action/server/index.js.map +6 -0
  85. package/dist/cjs/index.d.ts +1 -0
  86. package/dist/cjs/index.d.ts.map +1 -1
  87. package/dist/cjs/index.js +1 -0
  88. package/dist/cjs/index.js.map +1 -1
  89. package/dist/cjs/interaction/AccessControlManager.d.ts +1 -1
  90. package/dist/cjs/interaction/AccessControlManager.d.ts.map +1 -1
  91. package/dist/cjs/interaction/AccessControlManager.js +2 -2
  92. package/dist/cjs/interaction/AccessControlManager.js.map +1 -1
  93. package/dist/cjs/interaction/AttributeDataEncoder.d.ts +1 -3
  94. package/dist/cjs/interaction/AttributeDataEncoder.d.ts.map +1 -1
  95. package/dist/cjs/interaction/InteractionMessenger.d.ts +5 -5
  96. package/dist/cjs/interaction/InteractionMessenger.d.ts.map +1 -1
  97. package/dist/cjs/interaction/InteractionServer.d.ts +1 -1
  98. package/dist/cjs/interaction/InteractionServer.d.ts.map +1 -1
  99. package/dist/cjs/interaction/InteractionServer.js +2 -2
  100. package/dist/cjs/interaction/InteractionServer.js.map +1 -1
  101. package/dist/cjs/interaction/ServerSubscription.d.ts +2 -2
  102. package/dist/cjs/interaction/ServerSubscription.d.ts.map +1 -1
  103. package/dist/cjs/interaction/ServerSubscription.js +0 -1
  104. package/dist/cjs/interaction/ServerSubscription.js.map +1 -1
  105. package/dist/cjs/mdns/MdnsScanner.d.ts +2 -2
  106. package/dist/esm/action/Interactable.d.ts +36 -0
  107. package/dist/esm/action/Interactable.d.ts.map +1 -0
  108. package/dist/esm/action/Interactable.js +6 -0
  109. package/dist/esm/action/Interactable.js.map +6 -0
  110. package/dist/esm/action/Val.d.ts +94 -0
  111. package/dist/esm/action/Val.d.ts.map +1 -0
  112. package/dist/esm/action/Val.js +13 -0
  113. package/dist/esm/action/Val.js.map +6 -0
  114. package/dist/esm/action/errors.d.ts +69 -0
  115. package/dist/esm/action/errors.d.ts.map +1 -0
  116. package/dist/esm/action/errors.js +88 -0
  117. package/dist/esm/action/errors.js.map +6 -0
  118. package/dist/esm/action/index.d.ts +13 -0
  119. package/dist/esm/action/index.d.ts.map +1 -0
  120. package/dist/esm/action/index.js +13 -0
  121. package/dist/esm/action/index.js.map +6 -0
  122. package/dist/esm/action/protocols.d.ts +118 -0
  123. package/dist/esm/action/protocols.d.ts.map +1 -0
  124. package/dist/esm/action/protocols.js +6 -0
  125. package/dist/esm/action/protocols.js.map +6 -0
  126. package/dist/esm/action/request/Invoke.d.ts +35 -0
  127. package/dist/esm/action/request/Invoke.d.ts.map +1 -0
  128. package/dist/esm/action/request/Invoke.js +60 -0
  129. package/dist/esm/action/request/Invoke.js.map +6 -0
  130. package/dist/esm/action/request/MalformedRequestError.d.ts +14 -0
  131. package/dist/esm/action/request/MalformedRequestError.d.ts.map +1 -0
  132. package/dist/esm/action/request/MalformedRequestError.js +12 -0
  133. package/dist/esm/action/request/MalformedRequestError.js.map +6 -0
  134. package/dist/esm/action/request/Read.d.ts +141 -0
  135. package/dist/esm/action/request/Read.d.ts.map +1 -0
  136. package/dist/esm/action/request/Read.js +153 -0
  137. package/dist/esm/action/request/Read.js.map +6 -0
  138. package/dist/esm/action/request/Specifier.d.ts +82 -0
  139. package/dist/esm/action/request/Specifier.d.ts.map +1 -0
  140. package/dist/esm/action/request/Specifier.js +68 -0
  141. package/dist/esm/action/request/Specifier.js.map +6 -0
  142. package/dist/esm/action/request/Subscribe.d.ts +26 -0
  143. package/dist/esm/action/request/Subscribe.d.ts.map +1 -0
  144. package/dist/esm/action/request/Subscribe.js +30 -0
  145. package/dist/esm/action/request/Subscribe.js.map +6 -0
  146. package/dist/esm/action/request/Write.d.ts +10 -0
  147. package/dist/esm/action/request/Write.d.ts.map +1 -0
  148. package/dist/esm/action/request/Write.js +6 -0
  149. package/dist/esm/action/request/Write.js.map +6 -0
  150. package/dist/esm/action/request/index.d.ts +11 -0
  151. package/dist/esm/action/request/index.d.ts.map +1 -0
  152. package/dist/esm/action/request/index.js +11 -0
  153. package/dist/esm/action/request/index.js.map +6 -0
  154. package/dist/esm/action/response/InvokeResult.d.ts +15 -0
  155. package/dist/esm/action/response/InvokeResult.d.ts.map +1 -0
  156. package/dist/esm/action/response/InvokeResult.js +6 -0
  157. package/dist/esm/action/response/InvokeResult.js.map +6 -0
  158. package/dist/esm/action/response/ReadResult.d.ts +63 -0
  159. package/dist/esm/action/response/ReadResult.d.ts.map +1 -0
  160. package/dist/esm/action/response/ReadResult.js +6 -0
  161. package/dist/esm/action/response/ReadResult.js.map +6 -0
  162. package/dist/esm/action/response/SubscribeResult.d.ts +13 -0
  163. package/dist/esm/action/response/SubscribeResult.d.ts.map +1 -0
  164. package/dist/esm/action/response/SubscribeResult.js +6 -0
  165. package/dist/esm/action/response/SubscribeResult.js.map +6 -0
  166. package/dist/esm/action/response/WriteResult.d.ts +12 -0
  167. package/dist/esm/action/response/WriteResult.d.ts.map +1 -0
  168. package/dist/esm/action/response/WriteResult.js +6 -0
  169. package/dist/esm/action/response/WriteResult.js.map +6 -0
  170. package/dist/esm/action/response/index.d.ts +10 -0
  171. package/dist/esm/action/response/index.d.ts.map +1 -0
  172. package/dist/esm/action/response/index.js +10 -0
  173. package/dist/esm/action/response/index.js.map +6 -0
  174. package/dist/esm/action/server/AccessControl.d.ts +152 -0
  175. package/dist/esm/action/server/AccessControl.d.ts.map +1 -0
  176. package/dist/esm/action/server/AccessControl.js +267 -0
  177. package/dist/esm/action/server/AccessControl.js.map +6 -0
  178. package/dist/esm/action/server/AttributeResponse.d.ts +36 -0
  179. package/dist/esm/action/server/AttributeResponse.d.ts.map +1 -0
  180. package/dist/esm/action/server/AttributeResponse.js +339 -0
  181. package/dist/esm/action/server/AttributeResponse.js.map +6 -0
  182. package/dist/esm/action/server/ServerInteraction.d.ts +35 -0
  183. package/dist/esm/action/server/ServerInteraction.d.ts.map +1 -0
  184. package/dist/esm/action/server/ServerInteraction.js +32 -0
  185. package/dist/esm/action/server/ServerInteraction.js.map +6 -0
  186. package/dist/esm/action/server/index.d.ts +9 -0
  187. package/dist/esm/action/server/index.d.ts.map +1 -0
  188. package/dist/esm/action/server/index.js +9 -0
  189. package/dist/esm/action/server/index.js.map +6 -0
  190. package/dist/esm/index.d.ts +1 -0
  191. package/dist/esm/index.d.ts.map +1 -1
  192. package/dist/esm/index.js +1 -0
  193. package/dist/esm/index.js.map +1 -1
  194. package/dist/esm/interaction/AccessControlManager.d.ts +1 -1
  195. package/dist/esm/interaction/AccessControlManager.d.ts.map +1 -1
  196. package/dist/esm/interaction/AccessControlManager.js +2 -2
  197. package/dist/esm/interaction/AccessControlManager.js.map +1 -1
  198. package/dist/esm/interaction/AttributeDataEncoder.d.ts +1 -3
  199. package/dist/esm/interaction/AttributeDataEncoder.d.ts.map +1 -1
  200. package/dist/esm/interaction/InteractionMessenger.d.ts +5 -5
  201. package/dist/esm/interaction/InteractionMessenger.d.ts.map +1 -1
  202. package/dist/esm/interaction/InteractionServer.d.ts +1 -1
  203. package/dist/esm/interaction/InteractionServer.d.ts.map +1 -1
  204. package/dist/esm/interaction/InteractionServer.js +2 -2
  205. package/dist/esm/interaction/InteractionServer.js.map +1 -1
  206. package/dist/esm/interaction/ServerSubscription.d.ts +2 -2
  207. package/dist/esm/interaction/ServerSubscription.d.ts.map +1 -1
  208. package/dist/esm/interaction/ServerSubscription.js +0 -1
  209. package/dist/esm/interaction/ServerSubscription.js.map +1 -1
  210. package/dist/esm/mdns/MdnsScanner.d.ts +2 -2
  211. package/package.json +6 -6
  212. package/src/action/Interactable.ts +40 -0
  213. package/src/action/Val.ts +111 -0
  214. package/src/action/errors.ts +119 -0
  215. package/src/action/index.ts +13 -0
  216. package/src/action/protocols.ts +134 -0
  217. package/src/action/request/Invoke.ts +93 -0
  218. package/src/action/request/MalformedRequestError.ts +14 -0
  219. package/src/action/request/Read.ts +356 -0
  220. package/src/action/request/Specifier.ts +146 -0
  221. package/src/action/request/Subscribe.ts +54 -0
  222. package/src/action/request/Write.ts +13 -0
  223. package/src/action/request/index.ts +11 -0
  224. package/src/action/response/InvokeResult.ts +17 -0
  225. package/src/action/response/ReadResult.ts +89 -0
  226. package/src/action/response/SubscribeResult.ts +14 -0
  227. package/src/action/response/WriteResult.ts +13 -0
  228. package/src/action/response/index.ts +10 -0
  229. package/src/action/server/AccessControl.ts +494 -0
  230. package/src/action/server/AttributeResponse.ts +413 -0
  231. package/src/action/server/ServerInteraction.ts +64 -0
  232. package/src/action/server/index.ts +9 -0
  233. package/src/index.ts +1 -0
  234. package/src/interaction/AccessControlManager.ts +3 -3
  235. package/src/interaction/InteractionServer.ts +2 -3
  236. package/src/interaction/ServerSubscription.ts +0 -2
@@ -0,0 +1,267 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2025 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Access, AccessLevel, ElementTag, ValueModel } from "#model";
7
+ import { StatusCode } from "#types";
8
+ import { InvokeError, ReadError, SchemaImplementationError, WriteError } from "../errors.js";
9
+ const cache = /* @__PURE__ */ new WeakMap();
10
+ function AccessControl(schema) {
11
+ let enforcer = cache.get(schema);
12
+ if (enforcer === void 0) {
13
+ enforcer = enforcerFor(schema);
14
+ }
15
+ return enforcer;
16
+ }
17
+ ((AccessControl2) => {
18
+ let Authority;
19
+ ((Authority2) => {
20
+ Authority2[Authority2["Granted"] = 1] = "Granted";
21
+ Authority2[Authority2["Unauthorized"] = 2] = "Unauthorized";
22
+ Authority2[Authority2["Restricted"] = 3] = "Restricted";
23
+ })(Authority = AccessControl2.Authority || (AccessControl2.Authority = {}));
24
+ })(AccessControl || (AccessControl = {}));
25
+ Object.freeze(AccessControl);
26
+ Object.freeze(AccessControl.Authority);
27
+ function enforcerFor(schema) {
28
+ if (schema.tag === ElementTag.Command) {
29
+ return commandEnforcerFor(schema);
30
+ }
31
+ return dataEnforcerFor(schema);
32
+ }
33
+ function dataEnforcerFor(schema) {
34
+ const limits = limitsFor(schema);
35
+ let mayRead = (session, location) => {
36
+ if (session.offline || session.command) {
37
+ return true;
38
+ }
39
+ return session.authorityAt(limits.readLevel, location) === 1 /* Granted */;
40
+ };
41
+ let mayWrite = (session, location) => {
42
+ if (session.offline || session.command) {
43
+ return true;
44
+ }
45
+ return session.authorityAt(limits.writeLevel, location) === 1 /* Granted */;
46
+ };
47
+ let authorizeRead = (session, location) => {
48
+ if (session.offline || session.command) {
49
+ return;
50
+ }
51
+ if (session.authorityAt(limits.readLevel, location) === 1 /* Granted */) {
52
+ return;
53
+ }
54
+ throw new ReadError(location, "Permission denied", StatusCode.UnsupportedAccess);
55
+ };
56
+ let authorizeWrite = (session, location) => {
57
+ if (session.offline || session.command) {
58
+ return;
59
+ }
60
+ if (session.authorityAt(limits.writeLevel, location) === 1 /* Granted */) {
61
+ return;
62
+ }
63
+ throw new WriteError(location, "Permission denied", StatusCode.UnsupportedAccess);
64
+ };
65
+ if (limits.timed) {
66
+ const wrappedAuthorizeWrite = authorizeWrite;
67
+ const wrappedMayWrite = mayWrite;
68
+ authorizeWrite = (session, location) => {
69
+ if (!session.offline && !session.timed) {
70
+ throw new WriteError(
71
+ location,
72
+ "Permission denied because interaction is not timed",
73
+ StatusCode.NeedsTimedInteraction
74
+ );
75
+ }
76
+ wrappedAuthorizeWrite?.(session, location);
77
+ };
78
+ mayWrite = (session, location) => {
79
+ if (!session.offline && !session.timed) {
80
+ return false;
81
+ }
82
+ return wrappedMayWrite(session, location);
83
+ };
84
+ }
85
+ if (limits.fabricSensitive) {
86
+ const wrappedAuthorizeRead = authorizeRead;
87
+ const wrappedMayRead = mayRead;
88
+ const wrappedAuthorizeWrite = authorizeWrite;
89
+ const wrappedMayWrite = mayWrite;
90
+ authorizeRead = (session, location) => {
91
+ if (session.offline || session.command) {
92
+ return;
93
+ }
94
+ if (session.fabricFiltered) {
95
+ if (session.fabric === void 0) {
96
+ throw new ReadError(
97
+ location,
98
+ "Permission denied: No accessing fabric",
99
+ StatusCode.UnsupportedAccess
100
+ );
101
+ }
102
+ if (location?.owningFabric && location.owningFabric !== session.fabric) {
103
+ throw new ReadError(
104
+ location,
105
+ "Permission denied: Owning/accessing fabric mismatch",
106
+ StatusCode.UnsupportedAccess
107
+ );
108
+ }
109
+ }
110
+ wrappedAuthorizeRead(session, location);
111
+ };
112
+ mayRead = (session, location) => {
113
+ if (session.offline || session.command) {
114
+ return true;
115
+ }
116
+ if (session.fabric === void 0) {
117
+ return false;
118
+ }
119
+ if (location?.owningFabric && location.owningFabric !== session.fabric) {
120
+ return false;
121
+ }
122
+ return wrappedMayRead(session, location);
123
+ };
124
+ authorizeWrite = (session, location) => {
125
+ if (session.offline || session.command) {
126
+ return;
127
+ }
128
+ if (session.fabric === void 0) {
129
+ throw new WriteError(location, "Permission denied: No accessing fabric", StatusCode.UnsupportedAccess);
130
+ }
131
+ if (location?.owningFabric && location.owningFabric !== session.fabric) {
132
+ throw new WriteError(location, "Permission denied: Owning/accessing fabric mismatch");
133
+ }
134
+ wrappedAuthorizeWrite(session, location);
135
+ };
136
+ mayWrite = (session, location) => {
137
+ if (session.offline || session.command) {
138
+ return true;
139
+ }
140
+ if (session.fabric === void 0) {
141
+ return false;
142
+ }
143
+ if (location?.owningFabric && location.owningFabric !== session.fabric) {
144
+ return false;
145
+ }
146
+ return wrappedMayWrite(session, location);
147
+ };
148
+ }
149
+ if (!limits.readable) {
150
+ authorizeRead = (session, location) => {
151
+ if (session.offline || session.command) {
152
+ return;
153
+ }
154
+ throw new ReadError(location, "Permission defined: Value is write-only");
155
+ };
156
+ mayRead = (session) => {
157
+ return !!session.offline || !!session.command;
158
+ };
159
+ }
160
+ if (!limits.writable) {
161
+ authorizeWrite = (session, location) => {
162
+ if (session.offline || session.command) {
163
+ return;
164
+ }
165
+ throw new WriteError(location, "Permission denied: Value is read-only");
166
+ };
167
+ mayWrite = (session) => {
168
+ return !!session.offline || !!session.command;
169
+ };
170
+ }
171
+ return Object.freeze({
172
+ limits,
173
+ authorizeRead,
174
+ mayRead,
175
+ authorizeWrite,
176
+ mayWrite,
177
+ authorizeInvoke(_session, location) {
178
+ throw new SchemaImplementationError(location, "Permission denied: Invoke request but non-command schema");
179
+ },
180
+ mayInvoke() {
181
+ return false;
182
+ }
183
+ });
184
+ }
185
+ function commandEnforcerFor(schema) {
186
+ const limits = limitsFor(schema);
187
+ const timed = schema.effectiveAccess.timed;
188
+ const fabric = schema.effectiveAccess.fabric;
189
+ return {
190
+ limits,
191
+ authorizeRead(_session, location) {
192
+ throw new SchemaImplementationError(location, "Permission denied: Read request but command schema");
193
+ },
194
+ mayRead() {
195
+ return false;
196
+ },
197
+ authorizeWrite(_session, location) {
198
+ throw new SchemaImplementationError(location, "Permission denied: Write request but command schema");
199
+ },
200
+ mayWrite() {
201
+ return false;
202
+ },
203
+ authorizeInvoke(session, location) {
204
+ if (session.offline) {
205
+ return;
206
+ }
207
+ if (!session.command) {
208
+ throw new InvokeError(location, "Invoke attempt without command context");
209
+ }
210
+ if (timed && !session.timed) {
211
+ throw new InvokeError(
212
+ location,
213
+ "Invoke attempt without required timed context",
214
+ StatusCode.TimedRequestMismatch
215
+ );
216
+ }
217
+ if (fabric && session.fabric === void 0) {
218
+ throw new WriteError(location, "Permission denied: No accessing fabric", StatusCode.UnsupportedAccess);
219
+ }
220
+ if (session.authorityAt(limits.writeLevel, location) === 1 /* Granted */) {
221
+ return;
222
+ }
223
+ throw new InvokeError(location, "Permission denied", StatusCode.UnsupportedAccess);
224
+ },
225
+ mayInvoke(session, location) {
226
+ if (session.offline) {
227
+ return true;
228
+ }
229
+ if (!session.command) {
230
+ return false;
231
+ }
232
+ if (timed && !session.timed) {
233
+ return false;
234
+ }
235
+ if (fabric && session.fabric === void 0) {
236
+ return false;
237
+ }
238
+ return session.authorityAt(limits.writeLevel, location) === 1 /* Granted */;
239
+ }
240
+ };
241
+ }
242
+ function limitsFor(schema) {
243
+ const access = schema.effectiveAccess;
244
+ const quality = schema instanceof ValueModel ? schema.effectiveQuality : void 0;
245
+ let fixed = quality?.fixed;
246
+ for (let s = schema.parent; !fixed && s instanceof ValueModel; s = s.parent) {
247
+ if (s.effectiveQuality.fixed) {
248
+ fixed = true;
249
+ }
250
+ }
251
+ const limits = Object.freeze({
252
+ readable: access.readable,
253
+ writable: access.writable && !fixed,
254
+ fabricScoped: access.fabric === Access.Fabric.Scoped || access.fabric === Access.Fabric.Sensitive,
255
+ fabricSensitive: access.fabric === Access.Fabric.Sensitive,
256
+ timed: access.timed === true,
257
+ // Official Matter defaults are View for read and Operate for write. However, the schema's effective access
258
+ // should already have these defaults. Here we just adopt minimum needed rights as a safe fallback access level.
259
+ readLevel: access.readPriv === void 0 ? AccessLevel.View : Access.PrivilegeLevel[access.readPriv],
260
+ writeLevel: access.writePriv === void 0 ? AccessLevel.Operate : Access.PrivilegeLevel[access.writePriv]
261
+ });
262
+ return limits;
263
+ }
264
+ export {
265
+ AccessControl
266
+ };
267
+ //# sourceMappingURL=AccessControl.js.map
@@ -0,0 +1,6 @@
1
+ {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AAO,eAAe,OAAO,SAAS;AAAA,EAC7G,CAAC;AAED,SAAO;AACX;",
5
+ "names": ["AccessControl", "Authority"]
6
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2025 Project CHIP Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { NodeProtocol } from "#action/protocols.js";
7
+ import { Read } from "#action/request/Read.js";
8
+ import { ReadResult } from "#action/response/ReadResult.js";
9
+ import { AccessControl } from "#action/server/AccessControl.js";
10
+ export declare const GlobalAttrIds: Set<any>;
11
+ export declare const WildcardPathFlagsCodec: import("#types").BitmapSchemaInternal<{
12
+ skipRootNode: import("#types").BitFlag;
13
+ skipGlobalAttributes: import("#types").BitFlag;
14
+ skipAttributeList: import("#types").BitFlag;
15
+ reserved1: import("#types").BitFlag;
16
+ skipCommandLists: import("#types").BitFlag;
17
+ skipCustomElements: import("#types").BitFlag;
18
+ skipFixedAttributes: import("#types").BitFlag;
19
+ skipChangesOmittedAttributes: import("#types").BitFlag;
20
+ skipDiagnosticsClusters: import("#types").BitFlag;
21
+ }>;
22
+ export declare const FallbackLimits: AccessControl.Limits;
23
+ /**
24
+ * Implements read of attribute data for Matter "read" and "subscribe" interactions.
25
+ *
26
+ * TODO - profile; ensure nested functions are properly JITed and/or inlined
27
+ */
28
+ export declare class AttributeResponse<SessionT extends AccessControl.Session = AccessControl.Session> {
29
+ #private;
30
+ constructor(node: NodeProtocol, session: SessionT, { dataVersionFilters, attributeRequests }: Read.Attributes);
31
+ /**
32
+ * Emits chunks produced by paths added via {@link #addWildcard} and {@link #addConcrete}.
33
+ */
34
+ [Symbol.iterator](): Generator<ReadResult.Chunk, void, void>;
35
+ }
36
+ //# sourceMappingURL=AttributeResponse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AttributeResponse.d.ts","sourceRoot":"","sources":["../../../../src/action/server/AttributeResponse.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAA4D,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC9G,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAgBhE,eAAO,MAAM,aAAa,UAAgE,CAAC;AAC3F,eAAO,MAAM,sBAAsB;;;;;;;;;;EAAwC,CAAC;AAC5E,eAAO,MAAM,cAAc,EAAE,aAAa,CAAC,MAQ1C,CAAC;AAEF;;;;GAIG;AACH,qBAAa,iBAAiB,CAAC,QAAQ,SAAS,aAAa,CAAC,OAAO,GAAG,aAAa,CAAC,OAAO;;gBAwB7E,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,EAAE,IAAI,CAAC,UAAU;IAkC7G;;OAEG;IACF,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC;CAqThE"}
@@ -0,0 +1,339 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2025 Project CHIP Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { AccessControl } from "#action/server/AccessControl.js";
7
+ import { InternalError } from "#general";
8
+ import { AccessLevel, ElementTag } from "#model";
9
+ import {
10
+ BitmapSchema,
11
+ GlobalAttributes,
12
+ NodeId,
13
+ Status,
14
+ StatusResponseError,
15
+ WildcardPathFlagsBitmap
16
+ } from "#types";
17
+ const GlobalAttrIds = new Set(Object.values(GlobalAttributes).map((attr) => attr.id));
18
+ const WildcardPathFlagsCodec = BitmapSchema(WildcardPathFlagsBitmap);
19
+ const FallbackLimits = {
20
+ fabricScoped: false,
21
+ fabricSensitive: false,
22
+ readable: true,
23
+ readLevel: AccessLevel.View,
24
+ timed: false,
25
+ writable: true,
26
+ writeLevel: AccessLevel.Administer
27
+ };
28
+ class AttributeResponse {
29
+ // Configuration
30
+ #session;
31
+ #node;
32
+ #versions;
33
+ // Each input AttributePathIB that does not have an error installs a producer. Producers run after validation and
34
+ // generate actual attribute data
35
+ #dataProducers;
36
+ // The initial "chunk" may be a list of errors. As producers execute it is a set of records associated with the
37
+ // most recently touched endpoint. When the endpoint changes the previous chunk emits
38
+ #chunk;
39
+ // The following state updates as data producers execute. This serves both to convey state between functions and as
40
+ // a cache between producers that touch the same endpoint and/or cluster
41
+ #currentEndpoint;
42
+ #currentCluster;
43
+ #currentState;
44
+ #wildcardPathFlags = 0;
45
+ // The node ID may be expensive to retrieve and is invariant so we cache it here
46
+ #cachedNodeId;
47
+ constructor(node, session, { dataVersionFilters, attributeRequests }) {
48
+ this.#node = node;
49
+ this.#session = session;
50
+ const nodeId = session.fabric === void 0 ? NodeId.UNSPECIFIED_NODE_ID : this.#nodeId;
51
+ if (dataVersionFilters?.length) {
52
+ this.#versions = {};
53
+ for (const {
54
+ path: { nodeId: filterNodeId, endpointId, clusterId },
55
+ dataVersion
56
+ } of dataVersionFilters) {
57
+ if (filterNodeId !== void 0 && filterNodeId !== nodeId) {
58
+ continue;
59
+ }
60
+ if (typeof endpointId !== "number") {
61
+ continue;
62
+ }
63
+ (this.#versions[endpointId] ?? (this.#versions[endpointId] = {}))[clusterId] = dataVersion;
64
+ }
65
+ }
66
+ for (const path of attributeRequests) {
67
+ if (path.endpointId === void 0 || path.clusterId === void 0 || path.attributeId === void 0) {
68
+ this.#addWildcard(path);
69
+ } else {
70
+ this.#addConcrete(path);
71
+ }
72
+ }
73
+ }
74
+ /**
75
+ * Emits chunks produced by paths added via {@link #addWildcard} and {@link #addConcrete}.
76
+ */
77
+ *[Symbol.iterator]() {
78
+ if (this.#dataProducers) {
79
+ for (const producer of this.#dataProducers) {
80
+ yield* producer.apply(this);
81
+ }
82
+ }
83
+ if (this.#chunk !== void 0) {
84
+ yield this.#chunk;
85
+ }
86
+ }
87
+ /**
88
+ * Validate a wildcard path and update internal state.
89
+ */
90
+ #addWildcard(path) {
91
+ const { nodeId, endpointId, clusterId, attributeId, wildcardPathFlags } = path;
92
+ if (nodeId !== void 0 && nodeId !== this.#nodeId) {
93
+ return;
94
+ }
95
+ const wpf = wildcardPathFlags ? WildcardPathFlagsCodec.encode(wildcardPathFlags) : 0;
96
+ if (clusterId === void 0 && attributeId !== void 0 && !GlobalAttrIds.has(attributeId)) {
97
+ throw new StatusResponseError(
98
+ `Illegal read of wildcard cluster with non-global attribute #${attributeId}`,
99
+ Status.InvalidAction
100
+ );
101
+ }
102
+ if (endpointId === void 0) {
103
+ this.#addProducer(function* () {
104
+ this.#wildcardPathFlags = wpf;
105
+ for (const endpoint2 of this.#node) {
106
+ yield* this.#readEndpointForWildcard(endpoint2, path);
107
+ }
108
+ });
109
+ return;
110
+ }
111
+ const endpoint = this.#node[endpointId];
112
+ if (endpoint) {
113
+ this.#addProducer(function() {
114
+ this.#wildcardPathFlags = wpf;
115
+ return this.#readEndpointForWildcard(endpoint, path);
116
+ });
117
+ }
118
+ }
119
+ /**
120
+ * Validate a concrete path and update internal state.
121
+ */
122
+ #addConcrete(path) {
123
+ const { nodeId, endpointId, clusterId, attributeId } = path;
124
+ if (nodeId !== void 0 && this.#nodeId !== nodeId) {
125
+ this.#addStatus(path, Status.UnsupportedNode);
126
+ }
127
+ const endpoint = this.#node[endpointId];
128
+ const cluster = endpoint?.[clusterId];
129
+ const attribute = cluster?.type.attributes[attributeId];
130
+ let limits;
131
+ if (attribute === void 0) {
132
+ const modelAttr = this.#node.matter.member(path.clusterId, [ElementTag.Cluster])?.member(path.attributeId, [ElementTag.Attribute]);
133
+ if (modelAttr) {
134
+ limits = AccessControl(modelAttr).limits;
135
+ } else {
136
+ limits = FallbackLimits;
137
+ }
138
+ } else {
139
+ limits = attribute.limits;
140
+ }
141
+ switch (this.#session.authorityAt(limits.readLevel)) {
142
+ case AccessControl.Authority.Granted:
143
+ break;
144
+ case AccessControl.Authority.Unauthorized:
145
+ this.#addStatus(path, Status.UnsupportedAccess);
146
+ return;
147
+ case AccessControl.Authority.Restricted:
148
+ this.#addStatus(path, Status.AccessRestricted);
149
+ return;
150
+ default:
151
+ throw new InternalError(
152
+ `Unsupported authorization state ${this.#session.authorityAt(limits.readLevel)}`
153
+ );
154
+ }
155
+ if (endpoint === void 0) {
156
+ this.#addStatus(path, Status.UnsupportedEndpoint);
157
+ return;
158
+ }
159
+ if (cluster === void 0) {
160
+ this.#addStatus(path, Status.UnsupportedCluster);
161
+ return;
162
+ }
163
+ if (attribute === void 0) {
164
+ this.#addStatus(path, Status.UnsupportedAttribute);
165
+ return;
166
+ }
167
+ if (!limits.readable) {
168
+ this.#addStatus(path, Status.UnsupportedRead);
169
+ return;
170
+ }
171
+ const skipVersion = this.#versions?.[path.endpointId]?.[path.clusterId];
172
+ if (skipVersion !== void 0 && skipVersion === cluster.version) {
173
+ return;
174
+ }
175
+ this.#addProducer(function* () {
176
+ if (this.#currentEndpoint !== endpoint) {
177
+ if (this.#chunk) {
178
+ yield this.#chunk;
179
+ this.#chunk = void 0;
180
+ }
181
+ this.#currentEndpoint = endpoint;
182
+ this.#currentCluster = cluster;
183
+ this.#currentState = cluster.open(this.#session);
184
+ } else if (this.#currentCluster !== cluster) {
185
+ this.#currentCluster = cluster;
186
+ this.#currentState = cluster.open(this.#session);
187
+ } else if (this.#currentState === void 0) {
188
+ this.#currentState = cluster.open(this.#session);
189
+ }
190
+ this.#addValue(path, this.#currentState);
191
+ });
192
+ }
193
+ /**
194
+ * Starts new chunk or adds to current chunk all values from {@link endpoint} selected by {@link path}.
195
+ *
196
+ * Emits previous chunk if it exists and was not for this endpoint. This means that our chunk size is one endpoint
197
+ * worth of data, except for the initial error chunk if there are path errors.
198
+ *
199
+ * {@link this.#wildcardPathFlags} to numeric bitmap must be set prior to invocation.
200
+ *
201
+ * TODO - skip endpoints for which subject is unauthorized
202
+ */
203
+ *#readEndpointForWildcard(endpoint, path) {
204
+ if (endpoint.wildcardPathFlags & this.#wildcardPathFlags) {
205
+ return;
206
+ }
207
+ if (this.#currentEndpoint !== endpoint) {
208
+ if (this.#chunk) {
209
+ yield this.#chunk;
210
+ this.#chunk = void 0;
211
+ }
212
+ this.#currentEndpoint = endpoint;
213
+ this.#currentCluster = void 0;
214
+ }
215
+ const { clusterId } = path;
216
+ if (clusterId === void 0) {
217
+ for (const cluster of endpoint) {
218
+ this.#readClusterForWildcard(cluster, path);
219
+ }
220
+ } else {
221
+ const cluster = endpoint[clusterId];
222
+ if (cluster !== void 0) {
223
+ this.#readClusterForWildcard(cluster, path);
224
+ }
225
+ }
226
+ }
227
+ /**
228
+ * Read values from a specific {@link cluster} for a wildcard path.
229
+ *
230
+ * Depends on state initialized by {@link #readEndpointForWildcard}.
231
+ *
232
+ * TODO - skip clusters for which subject is unauthorized
233
+ */
234
+ #readClusterForWildcard(cluster, path) {
235
+ if (cluster.type.wildcardPathFlags & this.#wildcardPathFlags) {
236
+ return;
237
+ }
238
+ if (this.#currentCluster !== cluster) {
239
+ this.#currentCluster = cluster;
240
+ this.#currentState = void 0;
241
+ }
242
+ const skipVersion = this.#versions?.[this.#currentEndpoint.id]?.[cluster.type.id];
243
+ if (skipVersion !== void 0 && skipVersion === cluster.version) {
244
+ return;
245
+ }
246
+ const { attributeId } = path;
247
+ if (attributeId === void 0) {
248
+ for (const attribute of cluster.type.attributes) {
249
+ this.#readAttributeForWildcard(attribute, path);
250
+ }
251
+ } else {
252
+ const attribute = cluster.type.attributes[attributeId];
253
+ if (attribute !== void 0) {
254
+ this.#readAttributeForWildcard(attribute, path);
255
+ }
256
+ }
257
+ }
258
+ /**
259
+ * Read values from a specific {@link attribute} for a wildcard path.
260
+ *
261
+ * Depends on state initialized by {@link #readClusterForWildcard}.
262
+ */
263
+ #readAttributeForWildcard(attribute, path) {
264
+ if (attribute.wildcardPathFlags & this.#wildcardPathFlags) {
265
+ return;
266
+ }
267
+ if (!attribute.limits.readable || this.#session.authorityAt(attribute.limits.readLevel, this.#currentCluster.location) !== AccessControl.Authority.Granted) {
268
+ return;
269
+ }
270
+ if (this.#currentState === void 0) {
271
+ this.#currentState = this.#currentCluster.open(this.#session);
272
+ }
273
+ this.#addValue(
274
+ {
275
+ ...path,
276
+ endpointId: this.#currentEndpoint?.id,
277
+ clusterId: this.#currentCluster?.type.id,
278
+ attributeId: attribute.id
279
+ },
280
+ this.#currentState[attribute.id]
281
+ );
282
+ }
283
+ /**
284
+ * Add a function that produces data. These functions are run after validation of input paths.
285
+ */
286
+ #addProducer(producer) {
287
+ if (this.#dataProducers) {
288
+ this.#dataProducers.push(producer);
289
+ } else {
290
+ this.#dataProducers = [producer];
291
+ }
292
+ }
293
+ /**
294
+ * Add a status value.
295
+ */
296
+ #addStatus(path, status) {
297
+ const report = {
298
+ kind: "attr-status",
299
+ path,
300
+ status
301
+ };
302
+ if (this.#chunk) {
303
+ this.#chunk.push(report);
304
+ } else {
305
+ this.#chunk = [report];
306
+ }
307
+ }
308
+ /**
309
+ * Add an attribute value.
310
+ */
311
+ #addValue(path, value) {
312
+ const report = {
313
+ kind: "attr-value",
314
+ path,
315
+ value
316
+ };
317
+ if (this.#chunk) {
318
+ this.#chunk.push(report);
319
+ } else {
320
+ this.#chunk = [report];
321
+ }
322
+ }
323
+ /**
324
+ * The node ID used to filter paths with node ID specified. Unsure if this is ever actually used.
325
+ */
326
+ get #nodeId() {
327
+ if (this.#cachedNodeId === void 0) {
328
+ this.#cachedNodeId = (this.#session.fabric && this.#node.nodeIdFor(this.#session.fabric)) ?? NodeId.UNSPECIFIED_NODE_ID;
329
+ }
330
+ return this.#cachedNodeId;
331
+ }
332
+ }
333
+ export {
334
+ AttributeResponse,
335
+ FallbackLimits,
336
+ GlobalAttrIds,
337
+ WildcardPathFlagsCodec
338
+ };
339
+ //# sourceMappingURL=AttributeResponse.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/action/server/AttributeResponse.ts"],
4
+ "mappings": "AAAA;AAAA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