@matter/protocol 0.18.0 → 0.18.1-alpha.0-20261111-b84c5d1bc

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 (624) hide show
  1. package/dist/cjs/action/Val.d.ts +8 -0
  2. package/dist/cjs/action/Val.d.ts.map +1 -1
  3. package/dist/cjs/action/client/ClientInteraction.d.ts.map +1 -1
  4. package/dist/cjs/action/client/ClientInteraction.js +45 -32
  5. package/dist/cjs/action/client/ClientInteraction.js.map +1 -1
  6. package/dist/cjs/action/client/ClientRequest.d.ts +14 -0
  7. package/dist/cjs/action/client/ClientRequest.d.ts.map +1 -1
  8. package/dist/cjs/action/client/InputChunk.js +39 -2
  9. package/dist/cjs/action/client/InputChunk.js.map +1 -1
  10. package/dist/cjs/action/client/subscription/ClientSubscription.d.ts +2 -0
  11. package/dist/cjs/action/client/subscription/ClientSubscription.d.ts.map +1 -1
  12. package/dist/cjs/action/client/subscription/ClientSubscription.js +4 -0
  13. package/dist/cjs/action/client/subscription/ClientSubscription.js.map +1 -1
  14. package/dist/cjs/action/client/subscription/ClientSubscriptionHandler.d.ts.map +1 -1
  15. package/dist/cjs/action/client/subscription/ClientSubscriptionHandler.js +14 -0
  16. package/dist/cjs/action/client/subscription/ClientSubscriptionHandler.js.map +1 -1
  17. package/dist/cjs/action/client/subscription/PeerSubscription.d.ts +32 -0
  18. package/dist/cjs/action/client/subscription/PeerSubscription.d.ts.map +1 -1
  19. package/dist/cjs/action/client/subscription/PeerSubscription.js +61 -0
  20. package/dist/cjs/action/client/subscription/PeerSubscription.js.map +1 -1
  21. package/dist/cjs/action/errors.d.ts +3 -1
  22. package/dist/cjs/action/errors.d.ts.map +1 -1
  23. package/dist/cjs/action/errors.js +7 -2
  24. package/dist/cjs/action/errors.js.map +1 -1
  25. package/dist/cjs/action/protocols.d.ts +6 -1
  26. package/dist/cjs/action/protocols.d.ts.map +1 -1
  27. package/dist/cjs/action/request/Invoke.d.ts +24 -1
  28. package/dist/cjs/action/request/Invoke.d.ts.map +1 -1
  29. package/dist/cjs/action/request/Invoke.js +40 -12
  30. package/dist/cjs/action/request/Invoke.js.map +1 -1
  31. package/dist/cjs/action/request/Write.d.ts.map +1 -1
  32. package/dist/cjs/action/request/Write.js +6 -5
  33. package/dist/cjs/action/request/Write.js.map +1 -1
  34. package/dist/cjs/action/response/InvokeResult.d.ts +8 -2
  35. package/dist/cjs/action/response/InvokeResult.d.ts.map +1 -1
  36. package/dist/cjs/action/response/InvokeResult.js +28 -0
  37. package/dist/cjs/action/response/InvokeResult.js.map +2 -2
  38. package/dist/cjs/action/response/ReadResult.d.ts +14 -5
  39. package/dist/cjs/action/response/ReadResult.d.ts.map +1 -1
  40. package/dist/cjs/action/server/AttributeReadResponse.d.ts.map +1 -1
  41. package/dist/cjs/action/server/AttributeReadResponse.js +1 -1
  42. package/dist/cjs/action/server/AttributeReadResponse.js.map +1 -1
  43. package/dist/cjs/action/server/AttributeWriteResponse.d.ts.map +1 -1
  44. package/dist/cjs/action/server/AttributeWriteResponse.js +4 -2
  45. package/dist/cjs/action/server/AttributeWriteResponse.js.map +1 -1
  46. package/dist/cjs/action/server/EventReadResponse.d.ts.map +1 -1
  47. package/dist/cjs/action/server/EventReadResponse.js +1 -0
  48. package/dist/cjs/action/server/EventReadResponse.js.map +1 -1
  49. package/dist/cjs/advertisement/mdns/MdnsAdvertisement.d.ts +1 -1
  50. package/dist/cjs/advertisement/mdns/MdnsAdvertisement.d.ts.map +1 -1
  51. package/dist/cjs/advertisement/mdns/MdnsAdvertisement.js +7 -7
  52. package/dist/cjs/advertisement/mdns/MdnsAdvertisement.js.map +1 -1
  53. package/dist/cjs/ble/Ble.d.ts +2 -0
  54. package/dist/cjs/ble/Ble.d.ts.map +1 -1
  55. package/dist/cjs/ble/Ble.js +4 -0
  56. package/dist/cjs/ble/Ble.js.map +1 -1
  57. package/dist/cjs/certificate/CdSigners.d.ts +52 -0
  58. package/dist/cjs/certificate/CdSigners.d.ts.map +1 -0
  59. package/dist/cjs/certificate/CdSigners.js +111 -0
  60. package/dist/cjs/certificate/CdSigners.js.map +6 -0
  61. package/dist/cjs/certificate/CertificateAuthority.d.ts +1 -1
  62. package/dist/cjs/certificate/CertificateAuthority.d.ts.map +1 -1
  63. package/dist/cjs/certificate/DeviceAttestationValidator.d.ts +59 -7
  64. package/dist/cjs/certificate/DeviceAttestationValidator.d.ts.map +1 -1
  65. package/dist/cjs/certificate/DeviceAttestationValidator.js +122 -42
  66. package/dist/cjs/certificate/DeviceAttestationValidator.js.map +1 -1
  67. package/dist/cjs/certificate/DeviceCertification.d.ts.map +1 -1
  68. package/dist/cjs/certificate/DeviceCertification.js +5 -2
  69. package/dist/cjs/certificate/DeviceCertification.js.map +1 -1
  70. package/dist/cjs/certificate/NocsrValidator.d.ts +57 -0
  71. package/dist/cjs/certificate/NocsrValidator.d.ts.map +1 -0
  72. package/dist/cjs/certificate/NocsrValidator.js +109 -0
  73. package/dist/cjs/certificate/NocsrValidator.js.map +6 -0
  74. package/dist/cjs/certificate/PeerData.d.ts +12 -0
  75. package/dist/cjs/certificate/PeerData.d.ts.map +1 -0
  76. package/dist/cjs/certificate/PeerData.js +33 -0
  77. package/dist/cjs/certificate/PeerData.js.map +6 -0
  78. package/dist/cjs/certificate/index.d.ts +2 -0
  79. package/dist/cjs/certificate/index.d.ts.map +1 -1
  80. package/dist/cjs/certificate/index.js +2 -0
  81. package/dist/cjs/certificate/index.js.map +1 -1
  82. package/dist/cjs/certificate/kinds/AttestationCertificates.d.ts +42 -6
  83. package/dist/cjs/certificate/kinds/AttestationCertificates.d.ts.map +1 -1
  84. package/dist/cjs/certificate/kinds/AttestationCertificates.js +110 -13
  85. package/dist/cjs/certificate/kinds/AttestationCertificates.js.map +1 -1
  86. package/dist/cjs/certificate/kinds/Certificate.d.ts +13 -7
  87. package/dist/cjs/certificate/kinds/Certificate.d.ts.map +1 -1
  88. package/dist/cjs/certificate/kinds/Certificate.js +146 -240
  89. package/dist/cjs/certificate/kinds/Certificate.js.map +2 -2
  90. package/dist/cjs/certificate/kinds/CertificationDeclaration.d.ts +21 -3
  91. package/dist/cjs/certificate/kinds/CertificationDeclaration.d.ts.map +1 -1
  92. package/dist/cjs/certificate/kinds/CertificationDeclaration.js +76 -20
  93. package/dist/cjs/certificate/kinds/CertificationDeclaration.js.map +1 -1
  94. package/dist/cjs/certificate/kinds/DistinguishedName.d.ts +190 -0
  95. package/dist/cjs/certificate/kinds/DistinguishedName.d.ts.map +1 -0
  96. package/dist/cjs/certificate/kinds/DistinguishedName.js +417 -0
  97. package/dist/cjs/certificate/kinds/DistinguishedName.js.map +6 -0
  98. package/dist/cjs/certificate/kinds/Icac.d.ts.map +1 -1
  99. package/dist/cjs/certificate/kinds/Icac.js +5 -10
  100. package/dist/cjs/certificate/kinds/Icac.js.map +1 -1
  101. package/dist/cjs/certificate/kinds/Noc.d.ts.map +1 -1
  102. package/dist/cjs/certificate/kinds/Noc.js +5 -4
  103. package/dist/cjs/certificate/kinds/Noc.js.map +1 -1
  104. package/dist/cjs/certificate/kinds/OperationalBase.d.ts.map +1 -1
  105. package/dist/cjs/certificate/kinds/OperationalBase.js +4 -2
  106. package/dist/cjs/certificate/kinds/OperationalBase.js.map +1 -1
  107. package/dist/cjs/certificate/kinds/Rcac.d.ts.map +1 -1
  108. package/dist/cjs/certificate/kinds/Rcac.js +5 -10
  109. package/dist/cjs/certificate/kinds/Rcac.js.map +1 -1
  110. package/dist/cjs/certificate/kinds/Vvsc.d.ts +3 -3
  111. package/dist/cjs/certificate/kinds/Vvsc.d.ts.map +1 -1
  112. package/dist/cjs/certificate/kinds/Vvsc.js +19 -14
  113. package/dist/cjs/certificate/kinds/Vvsc.js.map +1 -1
  114. package/dist/cjs/certificate/kinds/definitions/asn.d.ts +1 -1
  115. package/dist/cjs/certificate/kinds/definitions/asn.d.ts.map +1 -1
  116. package/dist/cjs/certificate/kinds/definitions/asn.js.map +1 -1
  117. package/dist/cjs/certificate/kinds/definitions/attestation.d.ts +15 -15
  118. package/dist/cjs/certificate/kinds/definitions/attestation.d.ts.map +1 -1
  119. package/dist/cjs/certificate/kinds/definitions/base.d.ts +33 -0
  120. package/dist/cjs/certificate/kinds/definitions/base.d.ts.map +1 -1
  121. package/dist/cjs/certificate/kinds/definitions/base.js +8 -1
  122. package/dist/cjs/certificate/kinds/definitions/base.js.map +1 -1
  123. package/dist/cjs/certificate/kinds/definitions/operational.d.ts +24 -20
  124. package/dist/cjs/certificate/kinds/definitions/operational.d.ts.map +1 -1
  125. package/dist/cjs/certificate/kinds/definitions/operational.js +5 -3
  126. package/dist/cjs/certificate/kinds/definitions/operational.js.map +1 -1
  127. package/dist/cjs/codec/MessageCodec.d.ts +27 -2
  128. package/dist/cjs/codec/MessageCodec.d.ts.map +1 -1
  129. package/dist/cjs/codec/MessageCodec.js +81 -74
  130. package/dist/cjs/codec/MessageCodec.js.map +1 -1
  131. package/dist/cjs/common/OperationalCredentialsTypes.d.ts +6 -0
  132. package/dist/cjs/common/OperationalCredentialsTypes.d.ts.map +1 -1
  133. package/dist/cjs/common/OperationalCredentialsTypes.js +2 -0
  134. package/dist/cjs/common/OperationalCredentialsTypes.js.map +1 -1
  135. package/dist/cjs/dcl/DclCertificateService.d.ts +28 -7
  136. package/dist/cjs/dcl/DclCertificateService.d.ts.map +1 -1
  137. package/dist/cjs/dcl/DclCertificateService.js +103 -30
  138. package/dist/cjs/dcl/DclCertificateService.js.map +1 -1
  139. package/dist/cjs/fabric/Fabric.d.ts +10 -5
  140. package/dist/cjs/fabric/Fabric.d.ts.map +1 -1
  141. package/dist/cjs/fabric/Fabric.js +12 -5
  142. package/dist/cjs/fabric/Fabric.js.map +1 -1
  143. package/dist/cjs/fabric/FabricManager.d.ts +2 -2
  144. package/dist/cjs/fabric/FabricManager.js +2 -2
  145. package/dist/cjs/groups/FabricGroups.d.ts +2 -0
  146. package/dist/cjs/groups/FabricGroups.d.ts.map +1 -1
  147. package/dist/cjs/groups/FabricGroups.js +4 -0
  148. package/dist/cjs/groups/FabricGroups.js.map +1 -1
  149. package/dist/cjs/groups/Groups.d.ts +7 -0
  150. package/dist/cjs/groups/Groups.d.ts.map +1 -1
  151. package/dist/cjs/groups/Groups.js +11 -2
  152. package/dist/cjs/groups/Groups.js.map +1 -1
  153. package/dist/cjs/groups/KeySets.d.ts +3 -3
  154. package/dist/cjs/groups/KeySets.js +3 -3
  155. package/dist/cjs/interaction/InteractionMessenger.d.ts +18 -1
  156. package/dist/cjs/interaction/InteractionMessenger.d.ts.map +1 -1
  157. package/dist/cjs/interaction/InteractionMessenger.js +49 -19
  158. package/dist/cjs/interaction/InteractionMessenger.js.map +1 -1
  159. package/dist/cjs/mdns/InterfaceResponder.d.ts +137 -0
  160. package/dist/cjs/mdns/InterfaceResponder.d.ts.map +1 -0
  161. package/dist/cjs/mdns/InterfaceResponder.js +799 -0
  162. package/dist/cjs/mdns/InterfaceResponder.js.map +6 -0
  163. package/dist/cjs/mdns/MdnsServer.d.ts +82 -9
  164. package/dist/cjs/mdns/MdnsServer.d.ts.map +1 -1
  165. package/dist/cjs/mdns/MdnsServer.js +337 -267
  166. package/dist/cjs/mdns/MdnsServer.js.map +2 -2
  167. package/dist/cjs/mdns/MdnsService.d.ts.map +1 -1
  168. package/dist/cjs/mdns/MdnsService.js +3 -1
  169. package/dist/cjs/mdns/MdnsService.js.map +1 -1
  170. package/dist/cjs/peer/AdministratorCommands.d.ts +26 -0
  171. package/dist/cjs/peer/AdministratorCommands.d.ts.map +1 -0
  172. package/dist/cjs/peer/AdministratorCommands.js +40 -0
  173. package/dist/cjs/peer/AdministratorCommands.js.map +6 -0
  174. package/dist/cjs/peer/CommissioningConnection.d.ts.map +1 -1
  175. package/dist/cjs/peer/CommissioningConnection.js +4 -2
  176. package/dist/cjs/peer/CommissioningConnection.js.map +1 -1
  177. package/dist/cjs/peer/ControllerCommissioner.d.ts +9 -0
  178. package/dist/cjs/peer/ControllerCommissioner.d.ts.map +1 -1
  179. package/dist/cjs/peer/ControllerCommissioner.js +59 -13
  180. package/dist/cjs/peer/ControllerCommissioner.js.map +1 -1
  181. package/dist/cjs/peer/ControllerCommissioningFlow.d.ts +7 -7
  182. package/dist/cjs/peer/ControllerCommissioningFlow.d.ts.map +1 -1
  183. package/dist/cjs/peer/ControllerCommissioningFlow.js +124 -67
  184. package/dist/cjs/peer/ControllerCommissioningFlow.js.map +1 -1
  185. package/dist/cjs/peer/OperationalCertificateUpdate.d.ts +181 -0
  186. package/dist/cjs/peer/OperationalCertificateUpdate.d.ts.map +1 -0
  187. package/dist/cjs/peer/OperationalCertificateUpdate.js +553 -0
  188. package/dist/cjs/peer/OperationalCertificateUpdate.js.map +6 -0
  189. package/dist/cjs/peer/Peer.d.ts +5 -0
  190. package/dist/cjs/peer/Peer.d.ts.map +1 -1
  191. package/dist/cjs/peer/Peer.js +29 -1
  192. package/dist/cjs/peer/Peer.js.map +1 -1
  193. package/dist/cjs/peer/PeerAddressStore.d.ts +37 -0
  194. package/dist/cjs/peer/PeerAddressStore.d.ts.map +1 -0
  195. package/dist/cjs/peer/PeerAddressStore.js +114 -0
  196. package/dist/cjs/peer/PeerAddressStore.js.map +6 -0
  197. package/dist/cjs/peer/PeerConnection.d.ts.map +1 -1
  198. package/dist/cjs/peer/PeerConnection.js +0 -1
  199. package/dist/cjs/peer/PeerConnection.js.map +1 -1
  200. package/dist/cjs/peer/PeerDescriptor.d.ts +3 -4
  201. package/dist/cjs/peer/PeerDescriptor.d.ts.map +1 -1
  202. package/dist/cjs/peer/PeerDescriptor.js.map +1 -1
  203. package/dist/cjs/peer/PeerExchangeProvider.d.ts.map +1 -1
  204. package/dist/cjs/peer/PeerExchangeProvider.js +2 -1
  205. package/dist/cjs/peer/PeerExchangeProvider.js.map +1 -1
  206. package/dist/cjs/peer/PeerLossContext.d.ts +10 -2
  207. package/dist/cjs/peer/PeerLossContext.d.ts.map +1 -1
  208. package/dist/cjs/peer/PhysicalDeviceProperties.d.ts +13 -0
  209. package/dist/cjs/peer/PhysicalDeviceProperties.d.ts.map +1 -1
  210. package/dist/cjs/peer/PhysicalDeviceProperties.js +3 -2
  211. package/dist/cjs/peer/PhysicalDeviceProperties.js.map +1 -1
  212. package/dist/cjs/peer/RebootResubscribeArmer.d.ts +3 -3
  213. package/dist/cjs/peer/RebootResubscribeArmer.d.ts.map +1 -1
  214. package/dist/cjs/peer/RebootResubscribeArmer.js +21 -9
  215. package/dist/cjs/peer/RebootResubscribeArmer.js.map +1 -1
  216. package/dist/cjs/peer/index.d.ts +2 -0
  217. package/dist/cjs/peer/index.d.ts.map +1 -1
  218. package/dist/cjs/peer/index.js +2 -0
  219. package/dist/cjs/peer/index.js.map +1 -1
  220. package/dist/cjs/protocol/DeviceAdvertiser.d.ts.map +1 -1
  221. package/dist/cjs/protocol/DeviceAdvertiser.js +1 -1
  222. package/dist/cjs/protocol/DeviceAdvertiser.js.map +1 -1
  223. package/dist/cjs/protocol/ExchangeManager.d.ts +0 -1
  224. package/dist/cjs/protocol/ExchangeManager.d.ts.map +1 -1
  225. package/dist/cjs/protocol/ExchangeManager.js +136 -64
  226. package/dist/cjs/protocol/ExchangeManager.js.map +1 -1
  227. package/dist/cjs/protocol/ExchangeProvider.d.ts +3 -2
  228. package/dist/cjs/protocol/ExchangeProvider.d.ts.map +1 -1
  229. package/dist/cjs/protocol/ExchangeProvider.js.map +1 -1
  230. package/dist/cjs/protocol/MessageExchange.d.ts +13 -0
  231. package/dist/cjs/protocol/MessageExchange.d.ts.map +1 -1
  232. package/dist/cjs/protocol/MessageExchange.js +23 -7
  233. package/dist/cjs/protocol/MessageExchange.js.map +1 -1
  234. package/dist/cjs/protocol/MessageReceptionState.d.ts +1 -1
  235. package/dist/cjs/protocol/errors.d.ts +7 -1
  236. package/dist/cjs/protocol/errors.d.ts.map +1 -1
  237. package/dist/cjs/protocol/errors.js +3 -0
  238. package/dist/cjs/protocol/errors.js.map +1 -1
  239. package/dist/cjs/securechannel/SecureChannelMessenger.d.ts +6 -1
  240. package/dist/cjs/securechannel/SecureChannelMessenger.d.ts.map +1 -1
  241. package/dist/cjs/securechannel/SecureChannelMessenger.js +27 -12
  242. package/dist/cjs/securechannel/SecureChannelMessenger.js.map +1 -1
  243. package/dist/cjs/session/GroupSession.d.ts +58 -15
  244. package/dist/cjs/session/GroupSession.d.ts.map +1 -1
  245. package/dist/cjs/session/GroupSession.js +97 -102
  246. package/dist/cjs/session/GroupSession.js.map +2 -2
  247. package/dist/cjs/session/NodeSession.d.ts +50 -1
  248. package/dist/cjs/session/NodeSession.d.ts.map +1 -1
  249. package/dist/cjs/session/NodeSession.js +80 -4
  250. package/dist/cjs/session/NodeSession.js.map +1 -1
  251. package/dist/cjs/session/SecureSession.d.ts +9 -0
  252. package/dist/cjs/session/SecureSession.d.ts.map +1 -1
  253. package/dist/cjs/session/SecureSession.js +12 -0
  254. package/dist/cjs/session/SecureSession.js.map +1 -1
  255. package/dist/cjs/session/Session.d.ts +2 -2
  256. package/dist/cjs/session/Session.d.ts.map +1 -1
  257. package/dist/cjs/session/Session.js +1 -1
  258. package/dist/cjs/session/SessionManager.d.ts +76 -28
  259. package/dist/cjs/session/SessionManager.d.ts.map +1 -1
  260. package/dist/cjs/session/SessionManager.js +316 -153
  261. package/dist/cjs/session/SessionManager.js.map +2 -2
  262. package/dist/cjs/session/UnsecuredSession.d.ts +0 -1
  263. package/dist/cjs/session/UnsecuredSession.d.ts.map +1 -1
  264. package/dist/cjs/session/UnsecuredSession.js +2 -4
  265. package/dist/cjs/session/UnsecuredSession.js.map +1 -1
  266. package/dist/cjs/session/case/CaseClient.d.ts +5 -0
  267. package/dist/cjs/session/case/CaseClient.d.ts.map +1 -1
  268. package/dist/cjs/session/case/CaseClient.js +12 -11
  269. package/dist/cjs/session/case/CaseClient.js.map +2 -2
  270. package/dist/cjs/session/case/CaseServer.d.ts.map +1 -1
  271. package/dist/cjs/session/case/CaseServer.js +31 -11
  272. package/dist/cjs/session/case/CaseServer.js.map +1 -1
  273. package/dist/esm/action/Val.d.ts +8 -0
  274. package/dist/esm/action/Val.d.ts.map +1 -1
  275. package/dist/esm/action/client/ClientInteraction.d.ts.map +1 -1
  276. package/dist/esm/action/client/ClientInteraction.js +45 -32
  277. package/dist/esm/action/client/ClientInteraction.js.map +1 -1
  278. package/dist/esm/action/client/ClientRequest.d.ts +14 -0
  279. package/dist/esm/action/client/ClientRequest.d.ts.map +1 -1
  280. package/dist/esm/action/client/InputChunk.js +39 -2
  281. package/dist/esm/action/client/InputChunk.js.map +1 -1
  282. package/dist/esm/action/client/subscription/ClientSubscription.d.ts +2 -0
  283. package/dist/esm/action/client/subscription/ClientSubscription.d.ts.map +1 -1
  284. package/dist/esm/action/client/subscription/ClientSubscription.js +4 -0
  285. package/dist/esm/action/client/subscription/ClientSubscription.js.map +1 -1
  286. package/dist/esm/action/client/subscription/ClientSubscriptionHandler.d.ts.map +1 -1
  287. package/dist/esm/action/client/subscription/ClientSubscriptionHandler.js +14 -0
  288. package/dist/esm/action/client/subscription/ClientSubscriptionHandler.js.map +1 -1
  289. package/dist/esm/action/client/subscription/PeerSubscription.d.ts +32 -0
  290. package/dist/esm/action/client/subscription/PeerSubscription.d.ts.map +1 -1
  291. package/dist/esm/action/client/subscription/PeerSubscription.js +61 -0
  292. package/dist/esm/action/client/subscription/PeerSubscription.js.map +1 -1
  293. package/dist/esm/action/errors.d.ts +3 -1
  294. package/dist/esm/action/errors.d.ts.map +1 -1
  295. package/dist/esm/action/errors.js +7 -2
  296. package/dist/esm/action/errors.js.map +1 -1
  297. package/dist/esm/action/protocols.d.ts +6 -1
  298. package/dist/esm/action/protocols.d.ts.map +1 -1
  299. package/dist/esm/action/request/Invoke.d.ts +24 -1
  300. package/dist/esm/action/request/Invoke.d.ts.map +1 -1
  301. package/dist/esm/action/request/Invoke.js +41 -13
  302. package/dist/esm/action/request/Invoke.js.map +1 -1
  303. package/dist/esm/action/request/Write.d.ts.map +1 -1
  304. package/dist/esm/action/request/Write.js +7 -6
  305. package/dist/esm/action/request/Write.js.map +1 -1
  306. package/dist/esm/action/response/InvokeResult.d.ts +8 -2
  307. package/dist/esm/action/response/InvokeResult.d.ts.map +1 -1
  308. package/dist/esm/action/response/InvokeResult.js +26 -0
  309. package/dist/esm/action/response/InvokeResult.js.map +2 -2
  310. package/dist/esm/action/response/ReadResult.d.ts +14 -5
  311. package/dist/esm/action/response/ReadResult.d.ts.map +1 -1
  312. package/dist/esm/action/server/AttributeReadResponse.d.ts.map +1 -1
  313. package/dist/esm/action/server/AttributeReadResponse.js +2 -2
  314. package/dist/esm/action/server/AttributeReadResponse.js.map +1 -1
  315. package/dist/esm/action/server/AttributeWriteResponse.d.ts.map +1 -1
  316. package/dist/esm/action/server/AttributeWriteResponse.js +11 -3
  317. package/dist/esm/action/server/AttributeWriteResponse.js.map +1 -1
  318. package/dist/esm/action/server/EventReadResponse.d.ts.map +1 -1
  319. package/dist/esm/action/server/EventReadResponse.js +1 -0
  320. package/dist/esm/action/server/EventReadResponse.js.map +1 -1
  321. package/dist/esm/advertisement/mdns/MdnsAdvertisement.d.ts +1 -1
  322. package/dist/esm/advertisement/mdns/MdnsAdvertisement.d.ts.map +1 -1
  323. package/dist/esm/advertisement/mdns/MdnsAdvertisement.js +7 -7
  324. package/dist/esm/advertisement/mdns/MdnsAdvertisement.js.map +1 -1
  325. package/dist/esm/ble/Ble.d.ts +2 -0
  326. package/dist/esm/ble/Ble.d.ts.map +1 -1
  327. package/dist/esm/ble/Ble.js +4 -0
  328. package/dist/esm/ble/Ble.js.map +1 -1
  329. package/dist/esm/certificate/CdSigners.d.ts +52 -0
  330. package/dist/esm/certificate/CdSigners.d.ts.map +1 -0
  331. package/dist/esm/certificate/CdSigners.js +91 -0
  332. package/dist/esm/certificate/CdSigners.js.map +6 -0
  333. package/dist/esm/certificate/CertificateAuthority.d.ts +1 -1
  334. package/dist/esm/certificate/CertificateAuthority.d.ts.map +1 -1
  335. package/dist/esm/certificate/DeviceAttestationValidator.d.ts +59 -7
  336. package/dist/esm/certificate/DeviceAttestationValidator.d.ts.map +1 -1
  337. package/dist/esm/certificate/DeviceAttestationValidator.js +124 -45
  338. package/dist/esm/certificate/DeviceAttestationValidator.js.map +1 -1
  339. package/dist/esm/certificate/DeviceCertification.d.ts.map +1 -1
  340. package/dist/esm/certificate/DeviceCertification.js +5 -2
  341. package/dist/esm/certificate/DeviceCertification.js.map +1 -1
  342. package/dist/esm/certificate/NocsrValidator.d.ts +57 -0
  343. package/dist/esm/certificate/NocsrValidator.d.ts.map +1 -0
  344. package/dist/esm/certificate/NocsrValidator.js +89 -0
  345. package/dist/esm/certificate/NocsrValidator.js.map +6 -0
  346. package/dist/esm/certificate/PeerData.d.ts +12 -0
  347. package/dist/esm/certificate/PeerData.d.ts.map +1 -0
  348. package/dist/esm/certificate/PeerData.js +13 -0
  349. package/dist/esm/certificate/PeerData.js.map +6 -0
  350. package/dist/esm/certificate/index.d.ts +2 -0
  351. package/dist/esm/certificate/index.d.ts.map +1 -1
  352. package/dist/esm/certificate/index.js +2 -0
  353. package/dist/esm/certificate/index.js.map +1 -1
  354. package/dist/esm/certificate/kinds/AttestationCertificates.d.ts +42 -6
  355. package/dist/esm/certificate/kinds/AttestationCertificates.d.ts.map +1 -1
  356. package/dist/esm/certificate/kinds/AttestationCertificates.js +112 -15
  357. package/dist/esm/certificate/kinds/AttestationCertificates.js.map +1 -1
  358. package/dist/esm/certificate/kinds/Certificate.d.ts +13 -7
  359. package/dist/esm/certificate/kinds/Certificate.d.ts.map +1 -1
  360. package/dist/esm/certificate/kinds/Certificate.js +153 -256
  361. package/dist/esm/certificate/kinds/Certificate.js.map +2 -2
  362. package/dist/esm/certificate/kinds/CertificationDeclaration.d.ts +21 -3
  363. package/dist/esm/certificate/kinds/CertificationDeclaration.d.ts.map +1 -1
  364. package/dist/esm/certificate/kinds/CertificationDeclaration.js +79 -20
  365. package/dist/esm/certificate/kinds/CertificationDeclaration.js.map +1 -1
  366. package/dist/esm/certificate/kinds/DistinguishedName.d.ts +190 -0
  367. package/dist/esm/certificate/kinds/DistinguishedName.d.ts.map +1 -0
  368. package/dist/esm/certificate/kinds/DistinguishedName.js +422 -0
  369. package/dist/esm/certificate/kinds/DistinguishedName.js.map +6 -0
  370. package/dist/esm/certificate/kinds/Icac.d.ts.map +1 -1
  371. package/dist/esm/certificate/kinds/Icac.js +6 -11
  372. package/dist/esm/certificate/kinds/Icac.js.map +1 -1
  373. package/dist/esm/certificate/kinds/Noc.d.ts.map +1 -1
  374. package/dist/esm/certificate/kinds/Noc.js +5 -4
  375. package/dist/esm/certificate/kinds/Noc.js.map +1 -1
  376. package/dist/esm/certificate/kinds/OperationalBase.d.ts.map +1 -1
  377. package/dist/esm/certificate/kinds/OperationalBase.js +4 -2
  378. package/dist/esm/certificate/kinds/OperationalBase.js.map +1 -1
  379. package/dist/esm/certificate/kinds/Rcac.d.ts.map +1 -1
  380. package/dist/esm/certificate/kinds/Rcac.js +6 -11
  381. package/dist/esm/certificate/kinds/Rcac.js.map +1 -1
  382. package/dist/esm/certificate/kinds/Vvsc.d.ts +3 -3
  383. package/dist/esm/certificate/kinds/Vvsc.d.ts.map +1 -1
  384. package/dist/esm/certificate/kinds/Vvsc.js +20 -15
  385. package/dist/esm/certificate/kinds/Vvsc.js.map +1 -1
  386. package/dist/esm/certificate/kinds/definitions/asn.d.ts +1 -1
  387. package/dist/esm/certificate/kinds/definitions/asn.d.ts.map +1 -1
  388. package/dist/esm/certificate/kinds/definitions/asn.js.map +1 -1
  389. package/dist/esm/certificate/kinds/definitions/attestation.d.ts +15 -15
  390. package/dist/esm/certificate/kinds/definitions/attestation.d.ts.map +1 -1
  391. package/dist/esm/certificate/kinds/definitions/base.d.ts +33 -0
  392. package/dist/esm/certificate/kinds/definitions/base.d.ts.map +1 -1
  393. package/dist/esm/certificate/kinds/definitions/base.js +9 -2
  394. package/dist/esm/certificate/kinds/definitions/base.js.map +1 -1
  395. package/dist/esm/certificate/kinds/definitions/operational.d.ts +24 -20
  396. package/dist/esm/certificate/kinds/definitions/operational.d.ts.map +1 -1
  397. package/dist/esm/certificate/kinds/definitions/operational.js +5 -3
  398. package/dist/esm/certificate/kinds/definitions/operational.js.map +1 -1
  399. package/dist/esm/codec/MessageCodec.d.ts +27 -2
  400. package/dist/esm/codec/MessageCodec.d.ts.map +1 -1
  401. package/dist/esm/codec/MessageCodec.js +82 -75
  402. package/dist/esm/codec/MessageCodec.js.map +1 -1
  403. package/dist/esm/common/OperationalCredentialsTypes.d.ts +6 -0
  404. package/dist/esm/common/OperationalCredentialsTypes.d.ts.map +1 -1
  405. package/dist/esm/common/OperationalCredentialsTypes.js +2 -0
  406. package/dist/esm/common/OperationalCredentialsTypes.js.map +1 -1
  407. package/dist/esm/dcl/DclCertificateService.d.ts +28 -7
  408. package/dist/esm/dcl/DclCertificateService.d.ts.map +1 -1
  409. package/dist/esm/dcl/DclCertificateService.js +108 -31
  410. package/dist/esm/dcl/DclCertificateService.js.map +1 -1
  411. package/dist/esm/fabric/Fabric.d.ts +10 -5
  412. package/dist/esm/fabric/Fabric.d.ts.map +1 -1
  413. package/dist/esm/fabric/Fabric.js +12 -5
  414. package/dist/esm/fabric/Fabric.js.map +1 -1
  415. package/dist/esm/fabric/FabricManager.d.ts +2 -2
  416. package/dist/esm/fabric/FabricManager.js +2 -2
  417. package/dist/esm/groups/FabricGroups.d.ts +2 -0
  418. package/dist/esm/groups/FabricGroups.d.ts.map +1 -1
  419. package/dist/esm/groups/FabricGroups.js +4 -0
  420. package/dist/esm/groups/FabricGroups.js.map +1 -1
  421. package/dist/esm/groups/Groups.d.ts +7 -0
  422. package/dist/esm/groups/Groups.d.ts.map +1 -1
  423. package/dist/esm/groups/Groups.js +11 -2
  424. package/dist/esm/groups/Groups.js.map +1 -1
  425. package/dist/esm/groups/KeySets.d.ts +3 -3
  426. package/dist/esm/groups/KeySets.js +3 -3
  427. package/dist/esm/interaction/InteractionMessenger.d.ts +18 -1
  428. package/dist/esm/interaction/InteractionMessenger.d.ts.map +1 -1
  429. package/dist/esm/interaction/InteractionMessenger.js +50 -20
  430. package/dist/esm/interaction/InteractionMessenger.js.map +1 -1
  431. package/dist/esm/mdns/InterfaceResponder.d.ts +137 -0
  432. package/dist/esm/mdns/InterfaceResponder.d.ts.map +1 -0
  433. package/dist/esm/mdns/InterfaceResponder.js +794 -0
  434. package/dist/esm/mdns/InterfaceResponder.js.map +6 -0
  435. package/dist/esm/mdns/MdnsServer.d.ts +82 -9
  436. package/dist/esm/mdns/MdnsServer.d.ts.map +1 -1
  437. package/dist/esm/mdns/MdnsServer.js +341 -273
  438. package/dist/esm/mdns/MdnsServer.js.map +2 -2
  439. package/dist/esm/mdns/MdnsService.d.ts.map +1 -1
  440. package/dist/esm/mdns/MdnsService.js +3 -1
  441. package/dist/esm/mdns/MdnsService.js.map +1 -1
  442. package/dist/esm/peer/AdministratorCommands.d.ts +26 -0
  443. package/dist/esm/peer/AdministratorCommands.d.ts.map +1 -0
  444. package/dist/esm/peer/AdministratorCommands.js +20 -0
  445. package/dist/esm/peer/AdministratorCommands.js.map +6 -0
  446. package/dist/esm/peer/CommissioningConnection.d.ts.map +1 -1
  447. package/dist/esm/peer/CommissioningConnection.js +4 -2
  448. package/dist/esm/peer/CommissioningConnection.js.map +1 -1
  449. package/dist/esm/peer/ControllerCommissioner.d.ts +9 -0
  450. package/dist/esm/peer/ControllerCommissioner.d.ts.map +1 -1
  451. package/dist/esm/peer/ControllerCommissioner.js +59 -13
  452. package/dist/esm/peer/ControllerCommissioner.js.map +1 -1
  453. package/dist/esm/peer/ControllerCommissioningFlow.d.ts +7 -7
  454. package/dist/esm/peer/ControllerCommissioningFlow.d.ts.map +1 -1
  455. package/dist/esm/peer/ControllerCommissioningFlow.js +125 -70
  456. package/dist/esm/peer/ControllerCommissioningFlow.js.map +1 -1
  457. package/dist/esm/peer/OperationalCertificateUpdate.d.ts +181 -0
  458. package/dist/esm/peer/OperationalCertificateUpdate.d.ts.map +1 -0
  459. package/dist/esm/peer/OperationalCertificateUpdate.js +553 -0
  460. package/dist/esm/peer/OperationalCertificateUpdate.js.map +6 -0
  461. package/dist/esm/peer/Peer.d.ts +5 -0
  462. package/dist/esm/peer/Peer.d.ts.map +1 -1
  463. package/dist/esm/peer/Peer.js +29 -1
  464. package/dist/esm/peer/Peer.js.map +1 -1
  465. package/dist/esm/peer/PeerAddressStore.d.ts +37 -0
  466. package/dist/esm/peer/PeerAddressStore.d.ts.map +1 -0
  467. package/dist/esm/peer/PeerAddressStore.js +94 -0
  468. package/dist/esm/peer/PeerAddressStore.js.map +6 -0
  469. package/dist/esm/peer/PeerConnection.d.ts.map +1 -1
  470. package/dist/esm/peer/PeerConnection.js +0 -1
  471. package/dist/esm/peer/PeerConnection.js.map +1 -1
  472. package/dist/esm/peer/PeerDescriptor.d.ts +3 -4
  473. package/dist/esm/peer/PeerDescriptor.d.ts.map +1 -1
  474. package/dist/esm/peer/PeerDescriptor.js.map +1 -1
  475. package/dist/esm/peer/PeerExchangeProvider.d.ts.map +1 -1
  476. package/dist/esm/peer/PeerExchangeProvider.js +3 -2
  477. package/dist/esm/peer/PeerExchangeProvider.js.map +1 -1
  478. package/dist/esm/peer/PeerLossContext.d.ts +10 -2
  479. package/dist/esm/peer/PeerLossContext.d.ts.map +1 -1
  480. package/dist/esm/peer/PhysicalDeviceProperties.d.ts +13 -0
  481. package/dist/esm/peer/PhysicalDeviceProperties.d.ts.map +1 -1
  482. package/dist/esm/peer/PhysicalDeviceProperties.js +3 -2
  483. package/dist/esm/peer/PhysicalDeviceProperties.js.map +1 -1
  484. package/dist/esm/peer/RebootResubscribeArmer.d.ts +3 -3
  485. package/dist/esm/peer/RebootResubscribeArmer.d.ts.map +1 -1
  486. package/dist/esm/peer/RebootResubscribeArmer.js +21 -9
  487. package/dist/esm/peer/RebootResubscribeArmer.js.map +1 -1
  488. package/dist/esm/peer/index.d.ts +2 -0
  489. package/dist/esm/peer/index.d.ts.map +1 -1
  490. package/dist/esm/peer/index.js +2 -0
  491. package/dist/esm/peer/index.js.map +1 -1
  492. package/dist/esm/protocol/DeviceAdvertiser.d.ts.map +1 -1
  493. package/dist/esm/protocol/DeviceAdvertiser.js +1 -1
  494. package/dist/esm/protocol/DeviceAdvertiser.js.map +1 -1
  495. package/dist/esm/protocol/ExchangeManager.d.ts +0 -1
  496. package/dist/esm/protocol/ExchangeManager.d.ts.map +1 -1
  497. package/dist/esm/protocol/ExchangeManager.js +145 -67
  498. package/dist/esm/protocol/ExchangeManager.js.map +1 -1
  499. package/dist/esm/protocol/ExchangeProvider.d.ts +3 -2
  500. package/dist/esm/protocol/ExchangeProvider.d.ts.map +1 -1
  501. package/dist/esm/protocol/ExchangeProvider.js.map +1 -1
  502. package/dist/esm/protocol/MessageExchange.d.ts +13 -0
  503. package/dist/esm/protocol/MessageExchange.d.ts.map +1 -1
  504. package/dist/esm/protocol/MessageExchange.js +23 -7
  505. package/dist/esm/protocol/MessageExchange.js.map +1 -1
  506. package/dist/esm/protocol/MessageReceptionState.d.ts +1 -1
  507. package/dist/esm/protocol/errors.d.ts +7 -1
  508. package/dist/esm/protocol/errors.d.ts.map +1 -1
  509. package/dist/esm/protocol/errors.js +4 -1
  510. package/dist/esm/protocol/errors.js.map +1 -1
  511. package/dist/esm/securechannel/SecureChannelMessenger.d.ts +6 -1
  512. package/dist/esm/securechannel/SecureChannelMessenger.d.ts.map +1 -1
  513. package/dist/esm/securechannel/SecureChannelMessenger.js +27 -12
  514. package/dist/esm/securechannel/SecureChannelMessenger.js.map +1 -1
  515. package/dist/esm/session/GroupSession.d.ts +58 -15
  516. package/dist/esm/session/GroupSession.d.ts.map +1 -1
  517. package/dist/esm/session/GroupSession.js +97 -102
  518. package/dist/esm/session/GroupSession.js.map +2 -2
  519. package/dist/esm/session/NodeSession.d.ts +50 -1
  520. package/dist/esm/session/NodeSession.d.ts.map +1 -1
  521. package/dist/esm/session/NodeSession.js +83 -5
  522. package/dist/esm/session/NodeSession.js.map +1 -1
  523. package/dist/esm/session/SecureSession.d.ts +9 -0
  524. package/dist/esm/session/SecureSession.d.ts.map +1 -1
  525. package/dist/esm/session/SecureSession.js +18 -1
  526. package/dist/esm/session/SecureSession.js.map +1 -1
  527. package/dist/esm/session/Session.d.ts +2 -2
  528. package/dist/esm/session/Session.d.ts.map +1 -1
  529. package/dist/esm/session/Session.js +1 -1
  530. package/dist/esm/session/SessionManager.d.ts +76 -28
  531. package/dist/esm/session/SessionManager.d.ts.map +1 -1
  532. package/dist/esm/session/SessionManager.js +319 -156
  533. package/dist/esm/session/SessionManager.js.map +2 -2
  534. package/dist/esm/session/UnsecuredSession.d.ts +0 -1
  535. package/dist/esm/session/UnsecuredSession.d.ts.map +1 -1
  536. package/dist/esm/session/UnsecuredSession.js +5 -3
  537. package/dist/esm/session/UnsecuredSession.js.map +1 -1
  538. package/dist/esm/session/case/CaseClient.d.ts +5 -0
  539. package/dist/esm/session/case/CaseClient.d.ts.map +1 -1
  540. package/dist/esm/session/case/CaseClient.js +12 -11
  541. package/dist/esm/session/case/CaseClient.js.map +2 -2
  542. package/dist/esm/session/case/CaseServer.d.ts.map +1 -1
  543. package/dist/esm/session/case/CaseServer.js +31 -11
  544. package/dist/esm/session/case/CaseServer.js.map +1 -1
  545. package/package.json +5 -5
  546. package/src/action/Val.ts +8 -0
  547. package/src/action/client/ClientInteraction.ts +57 -33
  548. package/src/action/client/ClientRequest.ts +15 -0
  549. package/src/action/client/InputChunk.ts +57 -2
  550. package/src/action/client/subscription/ClientSubscription.ts +5 -0
  551. package/src/action/client/subscription/ClientSubscriptionHandler.ts +15 -0
  552. package/src/action/client/subscription/PeerSubscription.ts +73 -0
  553. package/src/action/errors.ts +10 -3
  554. package/src/action/protocols.ts +7 -1
  555. package/src/action/request/Invoke.ts +60 -15
  556. package/src/action/request/Write.ts +7 -6
  557. package/src/action/response/InvokeResult.ts +32 -2
  558. package/src/action/response/ReadResult.ts +15 -5
  559. package/src/action/server/AttributeReadResponse.ts +3 -2
  560. package/src/action/server/AttributeWriteResponse.ts +14 -3
  561. package/src/action/server/EventReadResponse.ts +1 -0
  562. package/src/advertisement/mdns/MdnsAdvertisement.ts +9 -9
  563. package/src/ble/Ble.ts +5 -0
  564. package/src/certificate/CdSigners.ts +137 -0
  565. package/src/certificate/CertificateAuthority.ts +1 -1
  566. package/src/certificate/DeviceAttestationValidator.ts +213 -56
  567. package/src/certificate/DeviceCertification.ts +6 -2
  568. package/src/certificate/NocsrValidator.ts +140 -0
  569. package/src/certificate/PeerData.ts +15 -0
  570. package/src/certificate/index.ts +2 -0
  571. package/src/certificate/kinds/AttestationCertificates.ts +183 -15
  572. package/src/certificate/kinds/Certificate.ts +203 -308
  573. package/src/certificate/kinds/CertificationDeclaration.ts +100 -46
  574. package/src/certificate/kinds/DistinguishedName.ts +677 -0
  575. package/src/certificate/kinds/Icac.ts +7 -12
  576. package/src/certificate/kinds/Noc.ts +12 -8
  577. package/src/certificate/kinds/OperationalBase.ts +5 -2
  578. package/src/certificate/kinds/Rcac.ts +7 -12
  579. package/src/certificate/kinds/Vvsc.ts +24 -15
  580. package/src/certificate/kinds/definitions/asn.ts +1 -1
  581. package/src/certificate/kinds/definitions/attestation.ts +15 -15
  582. package/src/certificate/kinds/definitions/base.ts +43 -1
  583. package/src/certificate/kinds/definitions/operational.ts +4 -3
  584. package/src/codec/MessageCodec.ts +92 -81
  585. package/src/common/OperationalCredentialsTypes.ts +7 -0
  586. package/src/dcl/DclCertificateService.ts +135 -36
  587. package/src/fabric/Fabric.ts +13 -6
  588. package/src/fabric/FabricManager.ts +2 -2
  589. package/src/groups/FabricGroups.ts +5 -0
  590. package/src/groups/Groups.ts +12 -3
  591. package/src/groups/KeySets.ts +3 -3
  592. package/src/interaction/InteractionMessenger.ts +58 -20
  593. package/src/mdns/InterfaceResponder.ts +1031 -0
  594. package/src/mdns/MdnsServer.ts +400 -360
  595. package/src/mdns/MdnsService.ts +2 -0
  596. package/src/peer/AdministratorCommands.ts +37 -0
  597. package/src/peer/CommissioningConnection.ts +5 -1
  598. package/src/peer/ControllerCommissioner.ts +69 -19
  599. package/src/peer/ControllerCommissioningFlow.ts +149 -99
  600. package/src/peer/OperationalCertificateUpdate.ts +922 -0
  601. package/src/peer/Peer.ts +31 -16
  602. package/src/peer/PeerAddressStore.ts +119 -0
  603. package/src/peer/PeerConnection.ts +0 -1
  604. package/src/peer/PeerDescriptor.ts +3 -4
  605. package/src/peer/PeerExchangeProvider.ts +4 -6
  606. package/src/peer/PeerLossContext.ts +11 -2
  607. package/src/peer/PhysicalDeviceProperties.ts +25 -12
  608. package/src/peer/RebootResubscribeArmer.ts +37 -16
  609. package/src/peer/index.ts +2 -0
  610. package/src/protocol/DeviceAdvertiser.ts +5 -1
  611. package/src/protocol/ExchangeManager.ts +162 -88
  612. package/src/protocol/ExchangeProvider.ts +3 -2
  613. package/src/protocol/MessageExchange.ts +29 -7
  614. package/src/protocol/MessageReceptionState.ts +2 -2
  615. package/src/protocol/errors.ts +7 -1
  616. package/src/securechannel/SecureChannelMessenger.ts +26 -13
  617. package/src/session/GroupSession.ts +147 -111
  618. package/src/session/NodeSession.ts +89 -4
  619. package/src/session/SecureSession.ts +27 -1
  620. package/src/session/Session.ts +2 -2
  621. package/src/session/SessionManager.ts +429 -189
  622. package/src/session/UnsecuredSession.ts +9 -3
  623. package/src/session/case/CaseClient.ts +15 -10
  624. package/src/session/case/CaseServer.ts +41 -17
@@ -0,0 +1,922 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2026 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { ClientInteraction } from "#action/client/ClientInteraction.js";
8
+ import { ClientSubscriptions } from "#action/client/subscription/ClientSubscriptions.js";
9
+ import { Read } from "#action/request/Read.js";
10
+ import { CertificateAuthority } from "#certificate/CertificateAuthority.js";
11
+ import { Dac } from "#certificate/kinds/AttestationCertificates.js";
12
+ import { Noc } from "#certificate/kinds/Noc.js";
13
+ import { NocsrValidator } from "#certificate/NocsrValidator.js";
14
+ import { Fabric } from "#fabric/Fabric.js";
15
+ import { ExchangeManager } from "#protocol/ExchangeManager.js";
16
+ import { DedicatedChannelExchangeProvider } from "#protocol/ExchangeProvider.js";
17
+ import { NodeSession } from "#session/NodeSession.js";
18
+ import { SessionManager } from "#session/SessionManager.js";
19
+ import {
20
+ Bytes,
21
+ Crypto,
22
+ Duration,
23
+ Environment,
24
+ ImplementationError,
25
+ isObject,
26
+ Logger,
27
+ MatterAggregateError,
28
+ MatterError,
29
+ Millis,
30
+ Minutes,
31
+ PublicKey,
32
+ Seconds,
33
+ Time,
34
+ UnexpectedDataError,
35
+ } from "@matter/general";
36
+ import {
37
+ CaseAuthenticatedTag,
38
+ EndpointNumber,
39
+ FabricIndex,
40
+ NodeId,
41
+ ReceivedStatusResponseError,
42
+ StatusResponseError,
43
+ } from "@matter/types";
44
+ import { GeneralCommissioning } from "@matter/types/clusters/general-commissioning";
45
+ import { OperationalCredentials } from "@matter/types/clusters/operational-credentials";
46
+ import { AdministratorCommands } from "./AdministratorCommands.js";
47
+ import { PeerAddress } from "./PeerAddress.js";
48
+ import { FabricChangedError } from "./PeerCommunicationError.js";
49
+ import { PeerSet } from "./PeerSet.js";
50
+
51
+ const logger = Logger.get("OperationalCertificateUpdate");
52
+
53
+ const RootEndpointNumber = EndpointNumber(0);
54
+
55
+ /** Fail-safe time kept back so CommissioningComplete can still arrive after the reconnect. */
56
+ const COMMISSIONING_COMPLETE_MARGIN = Seconds(10);
57
+
58
+ /** Shortest fail-safe that leaves time for the reconnect after {@link COMMISSIONING_COMPLETE_MARGIN}. */
59
+ const MIN_FAILSAFE = Seconds(30);
60
+
61
+ /** ArmFailSafe carries the expiry as uint16 seconds (§ 11.10.7.2). */
62
+ const MAX_FAILSAFE = Seconds(0xffff);
63
+
64
+ /**
65
+ * Thrown when updating the operational certificate of a peer fails.
66
+ *
67
+ * When the update changed or may have changed the peer, the message states which certificate the peer holds afterwards,
68
+ * or that this could not be determined.
69
+ */
70
+ export class OperationalCertificateUpdateError extends MatterError {
71
+ /**
72
+ * The CurrentFabricIndex the peer reported for our fabric at the start of the update. Undefined when the update
73
+ * failed before or while reading it, or when the peer reported an invalid value.
74
+ */
75
+ readonly fabricIndexOnPeer?: FabricIndex;
76
+
77
+ constructor(message: string, options?: OperationalCertificateUpdateError.Options) {
78
+ super(message, options);
79
+ this.fabricIndexOnPeer = options?.fabricIndexOnPeer;
80
+ }
81
+ }
82
+
83
+ export namespace OperationalCertificateUpdateError {
84
+ export interface Options extends ErrorOptions {
85
+ fabricIndexOnPeer?: FabricIndex;
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Thrown when the update did not start because the fail-safe of the peer may be in use: ArmFailSafe answered
91
+ * BusyWithOtherAdmin, or Breadcrumb was not 0 before arming. Nothing changed on the peer; the caller may retry later.
92
+ */
93
+ export class OperationalCertificateUpdateBusyError extends OperationalCertificateUpdateError {}
94
+
95
+ /**
96
+ * Thrown when the peer refused ArmFailSafe with an error code other than BusyWithOtherAdmin, or when the certificate
97
+ * the peer reports for its fabric does not verify. Nothing changed on the peer; a retry fails the same way until the
98
+ * cause on the peer is fixed.
99
+ */
100
+ export class OperationalCertificateUpdateRefusedError extends OperationalCertificateUpdateError {}
101
+
102
+ /**
103
+ * Replacement of the node operational certificate of a commissioned peer, see {@link
104
+ * OperationalCertificateUpdate.update}.
105
+ */
106
+ export namespace OperationalCertificateUpdate {
107
+ /** Default fail-safe for the whole update, including the CASE reconnect with the new certificate. */
108
+ export const DEFAULT_FAILSAFE = Minutes.one;
109
+
110
+ /**
111
+ * Dependencies of {@link update}.
112
+ */
113
+ export interface Context {
114
+ peers: PeerSet;
115
+ sessions: SessionManager;
116
+ exchanges: ExchangeManager;
117
+ ca: CertificateAuthority;
118
+ environment: Environment;
119
+ }
120
+
121
+ /**
122
+ * Options of {@link update}.
123
+ *
124
+ * @see {@link MatterSpecification.v161.Core} § 11.10.7.2
125
+ */
126
+ export interface Options {
127
+ /** The peer whose certificate to replace. */
128
+ address: PeerAddress;
129
+
130
+ /**
131
+ * Fail-safe armed for the whole update. Defaults to {@link DEFAULT_FAILSAFE}; must lie between 30 s
132
+ * and 65535 s. A peer ends the fail-safe early at its `MaxCumulativeFailsafeSeconds`.
133
+ */
134
+ failsafe?: Duration;
135
+
136
+ /** Aborts waiting for any CASE session the update opens with the peer. */
137
+ abort?: AbortSignal;
138
+ }
139
+
140
+ /**
141
+ * Result of {@link update}.
142
+ *
143
+ * @see {@link MatterSpecification.v161.Core} § 11.18.6.10
144
+ */
145
+ export interface Result {
146
+ /**
147
+ * Fabric index of our fabric on the peer, read before the update. An OK NOCResponse must carry the same index;
148
+ * after a lost NOCResponse the index is not confirmed that way.
149
+ */
150
+ fabricIndexOnPeer: FabricIndex;
151
+
152
+ /** Public key of the new node operational key pair. */
153
+ operationalPublicKey: Bytes;
154
+ }
155
+
156
+ /**
157
+ * Replace the node operational certificate (NOC) of a commissioned peer with one for a freshly generated key pair.
158
+ *
159
+ * The node ID, fabric, CASE Authenticated Tags and fabric-scoped data on the peer stay unchanged. The sequence:
160
+ *
161
+ * ```
162
+ * session 1: ArmFailSafe ─ CertificateChainRequest(DAC) ─ CSRRequest(IsForUpdateNOC) ─ UpdateNOC
163
+ * session 2: CommissioningComplete
164
+ * ```
165
+ *
166
+ * CSRRequest and UpdateNOC must share one secure session (§ 11.18.6.7.2). The peer keeps that session only until
167
+ * the NOCResponse is delivered, so CommissioningComplete uses a new CASE session that authenticates the new NOC.
168
+ * The update sends its commands through a {@link ClientInteraction} bound to a CASE session it opens itself. A
169
+ * `ClientNode` cluster command chooses its session on each invoke, so it cannot keep CSRRequest and UpdateNOC on
170
+ * one session or follow the session rule for CommissioningComplete below. The DAC check of the CSR signature only
171
+ * proves that the CSR comes from the holder of the DAC the peer reports; the CASE session already authenticates the
172
+ * peer.
173
+ *
174
+ * The update arms its fail-safe with a random non-zero Breadcrumb. The peer resets Breadcrumb to 0 on a successful
175
+ * CommissioningComplete and on fail-safe expiry or disarm (§ 11.10.7.2, § 11.10.7.6). The fail-safe is bound to
176
+ * the fabric, not to the session, so any operation of the same fabric may re-arm it and overwrite Breadcrumb. The
177
+ * update therefore sends CommissioningComplete only over a session on which it has just read its own Breadcrumb,
178
+ * and it does not arm when Breadcrumb is not 0 at the start, because an ArmFailSafe would join the fail-safe of
179
+ * another operation. When it reads a foreign Breadcrumb after UpdateNOC, it disarms, so that no other operation
180
+ * can commit the pending NOC later, and decides from a second read; a disarm without an armed fail-safe has no
181
+ * effect (§ 11.10.7.2).
182
+ *
183
+ * Failure handling:
184
+ *
185
+ * | Situation | Action and result |
186
+ * | ------------------------------------------ | --------------------------------------------------- |
187
+ * | aborted before or while a session is | send nothing on it; reject with the abort reason |
188
+ * | obtained | |
189
+ * | Breadcrumb not 0 before arming | arm nothing; reject as busy, the caller may retry |
190
+ * | Breadcrumb, NOCs or CurrentFabricIndex | arm nothing; reject, nothing changed |
191
+ * | unreadable before arming | |
192
+ * | the reported NOC fails to verify against | arm nothing; reject as refused, nothing changed |
193
+ * | the fabric root, node ID or fabric ID, or | |
194
+ * | its CATs differ from the CASE session's | |
195
+ * | ArmFailSafe answered with an error code | nothing armed; reject as busy or refused |
196
+ * | ArmFailSafe answered with a status or not | disarm over session 1; reject |
197
+ * | answered | |
198
+ * | a later step before UpdateNOC fails, or | disarm over session 1; previous NOC kept |
199
+ * | the peer refuses UpdateNOC | |
200
+ * | UpdateNOC answered OK with another or no | never send CommissioningComplete: disarm on a new |
201
+ * | FabricIndex than CurrentFabricIndex | session, read again and report the outcome |
202
+ * | after UpdateNOC, on a new CASE session | read Breadcrumb and NOCs, then by the values read: |
203
+ * | - Breadcrumb ours, NOCs is the new NOC | CommissioningComplete: OK → resolve; error code or |
204
+ * | | error status of the peer → disarm and read again; |
205
+ * | | no answer or no response → recovery |
206
+ * | - Breadcrumb 0, NOCs is the previous NOC | send nothing; report previous NOC (fail-safe ended) |
207
+ * | - anything else | disarm and read again |
208
+ * | read again, on another new session | 0 and NOCs is the previous NOC → report previous |
209
+ * | | NOC; 0 and NOCs is the new NOC after a confirmed |
210
+ * | | disarm → resolve; else report the outcome as |
211
+ * | | unknown |
212
+ * | UpdateNOC unanswered; or after a confirmed | recovery, once: the same read and decision on |
213
+ * | UpdateNOC no CASE session, a read or | another new CASE session; a failure there or an |
214
+ * | CommissioningComplete unanswered | abort reports the outcome as unknown |
215
+ *
216
+ * "NOCs is" a certificate means the fabric's NOCs list holds exactly that one certificate; the previous NOC is the
217
+ * one verified before arming. An empty list or a NOC of another rotation counts as anything else.
218
+ *
219
+ * The update never lets another operation commit its new NOC unseen. For that reason the disarm deliberately also
220
+ * reverts what another operation of the same fabric placed in the shared fail-safe context; that operation's
221
+ * CommissioningComplete then fails with NoFailSafe, and it can retry. Matter offers no read of who holds the
222
+ * fail-safe, so an arm with Breadcrumb 0 by another operation before the update starts stays undetectable.
223
+ * Breadcrumb is writable (§ 11.10.6.1), so a stale non-zero value written without a fail-safe makes the update
224
+ * refuse until CommissioningComplete, a fail-safe expiry or a restart of the peer resets it.
225
+ *
226
+ * After UpdateNOC and after a rollback the peer clears our sessions without notice, so we close ours, drop the
227
+ * resumption record and restart subscriptions. An unknown outcome does the same, because the peer may still roll
228
+ * back.
229
+ *
230
+ * Rejects with {@link ImplementationError} for an unknown peer, a fabric whose CA we do not hold or a fail-safe out
231
+ * of range, with the connection error when no CASE session can be established at the start, with {@link
232
+ * OperationalCertificateUpdateBusyError} or {@link OperationalCertificateUpdateRefusedError} when the update armed no
233
+ * fail-safe because of the Breadcrumb, the reported NOC or the ArmFailSafe error code, and with {@link
234
+ * OperationalCertificateUpdateError} for every other failure. Every {@link OperationalCertificateUpdateError}
235
+ * carries the CurrentFabricIndex read at the start in {@link OperationalCertificateUpdateError.fabricIndexOnPeer};
236
+ * the index is undefined when that read failed. The {@link ImplementationError}, the connection error and an abort
237
+ * before the read carry no index.
238
+ *
239
+ * @see {@link MatterSpecification.v161.Core} § 11.18.6.9
240
+ * @see {@link MatterSpecification.v161.Core} § 11.10.7.2
241
+ * @see {@link MatterSpecification.v161.Core} § 11.10.6.1
242
+ */
243
+ export async function update(
244
+ context: Context,
245
+ { address, failsafe = DEFAULT_FAILSAFE, abort }: Options,
246
+ ): Promise<Result> {
247
+ const { peers, ca } = context;
248
+
249
+ const peer = peers.get(address);
250
+ if (peer === undefined) {
251
+ throw new ImplementationError(`Cannot update the operational certificate of unknown peer ${address}`);
252
+ }
253
+ const fabric = peer.fabric;
254
+ if (!Bytes.areEqual(fabric.rootCert, ca.rootCert)) {
255
+ throw new ImplementationError(
256
+ `Cannot update the operational certificate of ${address} because we are not the certificate authority of fabric ${fabric.fabricIndex}`,
257
+ );
258
+ }
259
+ if (failsafe < MIN_FAILSAFE || failsafe > MAX_FAILSAFE) {
260
+ throw new ImplementationError(
261
+ `Fail-safe ${Duration.format(failsafe)} for the operational certificate update of ${address} is outside ${Duration.format(MIN_FAILSAFE)} to ${Duration.format(MAX_FAILSAFE)}`,
262
+ );
263
+ }
264
+
265
+ const first = await connectCase(context, address, { abort });
266
+ const armedAt = Time.nowUs;
267
+ const failsafeLeft = () => Millis(Math.max(Math.floor(failsafe - (Time.nowUs - armedAt)), 0));
268
+
269
+ const failsafeArm: FailsafeArm = { failsafe, breadcrumb: randomBreadcrumb(ca.crypto) };
270
+ let installed: InstalledCertificate;
271
+ try {
272
+ installed = await installNewCertificate(context, first, fabric, failsafeArm);
273
+ } finally {
274
+ await first.interaction.close();
275
+ }
276
+
277
+ if (installed.kind === "refused") {
278
+ if (isArmRefusal(installed.cause)) {
279
+ throw installed.cause;
280
+ }
281
+ throw new OperationalCertificateUpdateError(
282
+ `Updating the operational certificate of ${address} failed; it keeps its previous certificate`,
283
+ { cause: installed.cause, fabricIndexOnPeer: installed.fabricIndex },
284
+ );
285
+ }
286
+ const { fabricIndex } = installed;
287
+
288
+ let cause = installed.kind === "unconfirmed" ? installed.cause : undefined;
289
+ let completion: Completion | undefined;
290
+ if (installed.kind === "installed") {
291
+ try {
292
+ completion = await completeUpdate(context, address, installed, failsafeArm, {
293
+ abort,
294
+ connectionTimeout: Millis(Math.max(failsafeLeft() - COMMISSIONING_COMPLETE_MARGIN, 0)),
295
+ });
296
+ } catch (error) {
297
+ cause = error;
298
+ }
299
+ }
300
+
301
+ const recovered = completion === undefined;
302
+ if (completion === undefined && abort?.aborted) {
303
+ completion = { kind: "unknown" };
304
+ }
305
+ if (completion === undefined) {
306
+ try {
307
+ completion = await completeUpdate(context, address, installed, failsafeArm, { abort });
308
+ } catch (error) {
309
+ completion = {
310
+ kind: "unknown",
311
+ cause:
312
+ cause === undefined
313
+ ? error
314
+ : new MatterAggregateError(
315
+ [cause, error],
316
+ `Recovering the operational certificate update of ${address} failed after an earlier step failed`,
317
+ ),
318
+ };
319
+ }
320
+ }
321
+
322
+ switch (completion.kind) {
323
+ case "completed":
324
+ logger.info(
325
+ "Updated operational certificate of",
326
+ address.toString(),
327
+ ...(recovered ? ["after a recovery"] : []),
328
+ );
329
+ if (installed.refusal !== undefined) {
330
+ throw new OperationalCertificateUpdateError(
331
+ `Updating the operational certificate of ${address} failed; the new certificate is in place, because another operation of the same fabric completed the fail-safe`,
332
+ { cause: installed.refusal, fabricIndexOnPeer: fabricIndex },
333
+ );
334
+ }
335
+ return {
336
+ fabricIndexOnPeer: fabricIndex,
337
+ operationalPublicKey: installed.operationalPublicKey,
338
+ };
339
+
340
+ case "reverted":
341
+ throw new OperationalCertificateUpdateError(
342
+ `Updating the operational certificate of ${address} failed; it reverted to its previous certificate`,
343
+ { cause: completion.cause ?? cause, fabricIndexOnPeer: fabricIndex },
344
+ );
345
+
346
+ case "unknown":
347
+ await forgetSessions(context, address, "Outcome of the operational certificate update is unknown");
348
+ throw new OperationalCertificateUpdateError(
349
+ `Updating the operational certificate of ${address} failed and its outcome is unknown; the peer reverts to its previous certificate when its fail-safe expires, unless this update or another operation of the same fabric completed that fail-safe`,
350
+ { cause: completion.cause ?? cause, fabricIndexOnPeer: fabricIndex },
351
+ );
352
+ }
353
+ }
354
+ }
355
+
356
+ /** Outcome of the steps over the first session. */
357
+ type InstalledCertificate =
358
+ | { kind: "refused"; cause: unknown; fabricIndex: FabricIndex | undefined }
359
+ | ({ kind: "unconfirmed"; cause: unknown } & NewCertificate)
360
+ | ({ kind: "installed" } & NewCertificate);
361
+
362
+ interface NewCertificate {
363
+ nocValue: Bytes;
364
+ operationalPublicKey: Bytes;
365
+
366
+ /** The verified NOC the peer held before the update. */
367
+ previousNoc: Bytes;
368
+
369
+ /** The peer's CurrentFabricIndex for our fabric, read before arming. */
370
+ fabricIndex: FabricIndex;
371
+
372
+ /** Why the update must not commit this certificate; CommissioningComplete is then never sent. */
373
+ refusal?: OperationalCertificateUpdateError;
374
+ }
375
+
376
+ /**
377
+ * Read Breadcrumb, CurrentFabricIndex and the current NOC, then run ArmFailSafe, CertificateChainRequest, CSRRequest and UpdateNOC over
378
+ * {@link session}. The new NOC keeps the CASE Authenticated Tags of the current one. Does not arm when Breadcrumb is
379
+ * not 0 or the current NOC cannot be read or does not verify. On a failure after arming and before UpdateNOC reached
380
+ * the peer, disarms the fail-safe over the same session.
381
+ */
382
+ async function installNewCertificate(
383
+ { ca }: OperationalCertificateUpdate.Context,
384
+ { session, interaction }: AdministratorSession,
385
+ fabric: Fabric,
386
+ failsafeArm: FailsafeArm,
387
+ ): Promise<InstalledCertificate> {
388
+ let breadcrumb: bigint;
389
+ let nocs: OperationalCertificate[];
390
+ let fabricIndex: FabricIndex;
391
+ try {
392
+ ({ breadcrumb, nocs, fabricIndex } = await readStartState(interaction));
393
+ } catch (cause) {
394
+ return { kind: "refused", cause, fabricIndex: undefined };
395
+ }
396
+
397
+ let previous: { noc: Bytes; caseAuthenticatedTags?: readonly CaseAuthenticatedTag[] };
398
+ try {
399
+ previous = await verifiedCurrentNoc(nocs, fabric, interaction.address.nodeId, session.caseAuthenticatedTags);
400
+ } catch (cause) {
401
+ return {
402
+ kind: "refused",
403
+ fabricIndex,
404
+ cause: new OperationalCertificateUpdateRefusedError(
405
+ `Cannot update the operational certificate of ${interaction.address}: the certificate it reports did not verify`,
406
+ { cause, fabricIndexOnPeer: fabricIndex },
407
+ ),
408
+ };
409
+ }
410
+ if (breadcrumb !== 0n) {
411
+ return {
412
+ kind: "refused",
413
+ fabricIndex,
414
+ cause: new OperationalCertificateUpdateBusyError(
415
+ `Cannot update the operational certificate of ${interaction.address}: its Breadcrumb is ${breadcrumb}, so another operation of the same fabric may hold the fail-safe; retry later`,
416
+ { fabricIndexOnPeer: fabricIndex },
417
+ ),
418
+ };
419
+ }
420
+
421
+ let certificate: NewCertificate;
422
+ try {
423
+ await armFailsafe(interaction, failsafeArm, fabricIndex);
424
+ } catch (cause) {
425
+ if (!isArmRefusal(cause)) {
426
+ await disarmFailsafe(interaction);
427
+ }
428
+ return { kind: "refused", cause, fabricIndex };
429
+ }
430
+
431
+ try {
432
+ const { certificate: dac } = responseOf(
433
+ await AdministratorCommands.invoke(
434
+ interaction,
435
+ {
436
+ endpoint: RootEndpointNumber,
437
+ cluster: OperationalCredentials,
438
+ command: "certificateChainRequest",
439
+ fields: { certificateType: OperationalCredentials.CertificateChainType.DacCertificate },
440
+ },
441
+ { useExtendedFailSafeMessageResponseTimeout: true },
442
+ ),
443
+ "CertificateChainRequest",
444
+ );
445
+ const dacPublicKey = PublicKey(Dac.fromAsn1(dac).cert.ellipticCurvePublicKey);
446
+
447
+ const csrNonce = ca.crypto.randomBytes(32);
448
+ const csrResponse = responseOf(
449
+ await AdministratorCommands.invoke(
450
+ interaction,
451
+ {
452
+ endpoint: RootEndpointNumber,
453
+ cluster: OperationalCredentials,
454
+ command: "csrRequest",
455
+ fields: { csrNonce, isForUpdateNoc: true },
456
+ },
457
+ { useExtendedFailSafeMessageResponseTimeout: true },
458
+ ),
459
+ "CSRRequest",
460
+ );
461
+ const operationalPublicKey = await NocsrValidator.validate(
462
+ { crypto: ca.crypto, attestationChallenge: session.attestationChallengeKey, csrNonce, dacPublicKey },
463
+ csrResponse,
464
+ );
465
+ certificate = {
466
+ operationalPublicKey,
467
+ previousNoc: previous.noc,
468
+ fabricIndex,
469
+ nocValue: await ca.generateNoc(
470
+ operationalPublicKey,
471
+ fabric.fabricId,
472
+ interaction.address.nodeId,
473
+ previous.caseAuthenticatedTags,
474
+ ),
475
+ };
476
+ } catch (cause) {
477
+ await disarmFailsafe(interaction);
478
+ return { kind: "refused", cause, fabricIndex };
479
+ }
480
+
481
+ let response: OperationalCredentials.NocResponse;
482
+ try {
483
+ response = responseOf(
484
+ await AdministratorCommands.invoke(
485
+ interaction,
486
+ {
487
+ endpoint: RootEndpointNumber,
488
+ cluster: OperationalCredentials,
489
+ command: "updateNoc",
490
+ fields: { nocValue: certificate.nocValue, icacValue: ca.icacCert },
491
+ },
492
+ { useExtendedFailSafeMessageResponseTimeout: true },
493
+ ),
494
+ "UpdateNOC",
495
+ );
496
+ } catch (cause) {
497
+ if (cause instanceof ReceivedStatusResponseError) {
498
+ await disarmFailsafe(interaction);
499
+ return { kind: "refused", cause, fabricIndex };
500
+ }
501
+
502
+ // The peer may have applied UpdateNOC and then dropped the session or its NOCResponse
503
+ return { kind: "unconfirmed", cause, ...certificate };
504
+ }
505
+
506
+ const { statusCode, debugText } = response;
507
+ if (statusCode !== OperationalCredentials.NodeOperationalCertStatus.Ok) {
508
+ await disarmFailsafe(interaction);
509
+ return {
510
+ kind: "refused",
511
+ fabricIndex,
512
+ cause: new OperationalCertificateUpdateError(
513
+ `UpdateNOC failed with ${OperationalCredentials.NodeOperationalCertStatus[statusCode]} (${statusCode})${debugText ? `, ${debugText}` : ""}`,
514
+ { fabricIndexOnPeer: fabricIndex },
515
+ ),
516
+ };
517
+ }
518
+
519
+ // § 11.18.6.9: an OK NOCResponse carries the index of the updated fabric, which UpdateNOC never changes
520
+ if (response.fabricIndex !== certificate.fabricIndex) {
521
+ return {
522
+ kind: "installed",
523
+ ...certificate,
524
+ refusal: new OperationalCertificateUpdateError(
525
+ `UpdateNOC answered OK for fabric index ${response.fabricIndex ?? "none"} instead of ${certificate.fabricIndex}, the CurrentFabricIndex read before`,
526
+ { fabricIndexOnPeer: certificate.fabricIndex },
527
+ ),
528
+ };
529
+ }
530
+
531
+ return { kind: "installed", ...certificate };
532
+ }
533
+
534
+ /** The fail-safe this update arms and the Breadcrumb that marks it. */
535
+ interface FailsafeArm {
536
+ failsafe: Duration;
537
+ breadcrumb: bigint;
538
+ }
539
+
540
+ /** A random non-zero uint64, so the Breadcrumb tells this update's fail-safe from any other. */
541
+ function randomBreadcrumb(crypto: Crypto) {
542
+ const value = BigInt(`0x${Bytes.toHex(crypto.randomBytes(8))}`);
543
+ return value === 0n ? 1n : value;
544
+ }
545
+
546
+ /** Result of {@link completeUpdate}. */
547
+ type Completion = { kind: "completed" } | { kind: "reverted"; cause?: unknown } | { kind: "unknown"; cause?: unknown };
548
+
549
+ /** The fail-safe was disarmed after UpdateNOC, so only another read can tell the outcome. */
550
+ interface Disarmed {
551
+ kind: "disarmed";
552
+ disarmed: boolean;
553
+ cause?: unknown;
554
+ }
555
+
556
+ /**
557
+ * Send CommissioningComplete over a new CASE session, but only after reading on that session this update's
558
+ * Breadcrumb and the new NOC pending. Otherwise, and when CommissioningComplete fails, disarm and decide from a read
559
+ * on another new session; see the table at {@link OperationalCertificateUpdate.update}.
560
+ *
561
+ * Rejects when the peer cannot be reached, a read fails or CommissioningComplete is not answered. When the read after
562
+ * a refused CommissioningComplete fails, rejects with a {@link MatterAggregateError} of the refusal and the read error.
563
+ */
564
+ async function completeUpdate(
565
+ context: OperationalCertificateUpdate.Context,
566
+ address: PeerAddress,
567
+ certificate: NewCertificate,
568
+ { breadcrumb }: FailsafeArm,
569
+ options: { abort?: AbortSignal; connectionTimeout?: Duration },
570
+ ): Promise<Completion> {
571
+ await forgetSessions(context, address, "Operational certificate of the peer was updated");
572
+ const step = await withCase(context, address, options, async ({ interaction }): Promise<Completion | Disarmed> => {
573
+ const state = await certificateState(interaction);
574
+ const held = heldNoc(state, certificate);
575
+ if (state.breadcrumb === breadcrumb && held === "new") {
576
+ if (certificate.refusal !== undefined) {
577
+ return { kind: "disarmed", cause: certificate.refusal, disarmed: await disarmFailsafe(interaction) };
578
+ }
579
+ const response = await commissioningComplete(interaction);
580
+ if (
581
+ !(response instanceof StatusResponseError) &&
582
+ response.errorCode === GeneralCommissioning.CommissioningError.Ok
583
+ ) {
584
+ return { kind: "completed" };
585
+ }
586
+ return {
587
+ kind: "disarmed",
588
+ cause:
589
+ response instanceof StatusResponseError
590
+ ? response
591
+ : new OperationalCertificateUpdateError(
592
+ `CommissioningComplete failed with ${commissioningErrorText(response.errorCode, response.debugText)}`,
593
+ { fabricIndexOnPeer: certificate.fabricIndex },
594
+ ),
595
+ disarmed: await disarmFailsafe(interaction),
596
+ };
597
+ }
598
+ if (state.breadcrumb === 0n && held === "previous") {
599
+ return { kind: "reverted" };
600
+ }
601
+ return { kind: "disarmed", disarmed: await disarmFailsafe(interaction) };
602
+ });
603
+ if (step.kind !== "disarmed") {
604
+ return step;
605
+ }
606
+
607
+ await forgetSessions(context, address, "Peer may have reverted to its previous operational certificate");
608
+ let state: CertificateState;
609
+ try {
610
+ state = await withCase(context, address, options, ({ interaction }) => certificateState(interaction));
611
+ } catch (error) {
612
+ if (step.cause === undefined) {
613
+ throw error;
614
+ }
615
+ throw new MatterAggregateError(
616
+ [step.cause, error],
617
+ `CommissioningComplete failed and the certificate state of ${address} could not be read again`,
618
+ );
619
+ }
620
+ const held = heldNoc(state, certificate);
621
+ if (state.breadcrumb === 0n && held === "previous") {
622
+ return { kind: "reverted", cause: step.cause };
623
+ }
624
+ if (state.breadcrumb === 0n && held === "new" && step.disarmed) {
625
+ return { kind: "completed" };
626
+ }
627
+ return { kind: "unknown", cause: step.cause };
628
+ }
629
+
630
+ /**
631
+ * Send CommissioningComplete; resolves to the error when the peer answers with an error status instead of a response.
632
+ * Rejects when no answer of the peer arrives, when the answer lacks the command (matter.js then reports
633
+ * NoCommandResponse itself) and when the peer answers with a bare success status.
634
+ */
635
+ async function commissioningComplete(interaction: ClientInteraction) {
636
+ try {
637
+ return responseOf(
638
+ await AdministratorCommands.invoke(
639
+ interaction,
640
+ { endpoint: RootEndpointNumber, cluster: GeneralCommissioning, command: "commissioningComplete" },
641
+ { useExtendedFailSafeMessageResponseTimeout: true },
642
+ ),
643
+ "CommissioningComplete",
644
+ );
645
+ } catch (error) {
646
+ if (error instanceof ReceivedStatusResponseError) {
647
+ return error;
648
+ }
649
+ throw error;
650
+ }
651
+ }
652
+
653
+ /** One entry of the NOCs attribute. */
654
+ interface OperationalCertificate {
655
+ noc: Bytes;
656
+ icac?: Bytes;
657
+ }
658
+
659
+ interface CertificateState {
660
+ /** The Breadcrumb attribute, if the peer reported it. */
661
+ breadcrumb?: bigint;
662
+
663
+ /** The NOCs of the accessing fabric, if the peer reported the NOCs attribute. */
664
+ nocs?: OperationalCertificate[];
665
+
666
+ /** The CurrentFabricIndex attribute, if the peer reported it. */
667
+ fabricIndex?: number;
668
+ }
669
+
670
+ /**
671
+ * Which of the two certificates {@link state} shows as the only NOC of the fabric; undefined for anything else, such
672
+ * as no NOCs value, an empty list or a NOC of another rotation.
673
+ */
674
+ function heldNoc({ nocs }: CertificateState, { nocValue, previousNoc }: NewCertificate) {
675
+ if (nocs?.length !== 1) {
676
+ return undefined;
677
+ }
678
+ const [{ noc }] = nocs;
679
+ if (Bytes.areEqual(noc, nocValue)) {
680
+ return "new";
681
+ }
682
+ if (Bytes.areEqual(noc, previousNoc)) {
683
+ return "previous";
684
+ }
685
+ return undefined;
686
+ }
687
+
688
+ /** Read Breadcrumb, the NOCs and CurrentFabricIndex of the accessing fabric; rejects when one is missing or invalid. */
689
+ async function readStartState(interaction: ClientInteraction) {
690
+ const { breadcrumb, nocs, fabricIndex } = await certificateState(interaction);
691
+ if (breadcrumb === undefined) {
692
+ throw new UnexpectedDataError(`${interaction.address} reported no Breadcrumb value`);
693
+ }
694
+ if (nocs === undefined) {
695
+ throw new UnexpectedDataError(`${interaction.address} reported no NOCs value`);
696
+ }
697
+ if (!FabricIndex.isValid(fabricIndex)) {
698
+ throw new UnexpectedDataError(`${interaction.address} reported CurrentFabricIndex ${fabricIndex ?? "none"}`);
699
+ }
700
+ return { breadcrumb, nocs, fabricIndex };
701
+ }
702
+
703
+ /**
704
+ * The one NOC the peer reports for the accessing fabric, and its CASE Authenticated Tags. The NOCs value is peer data,
705
+ * so the NOC must chain to the root of {@link fabric} and name {@link nodeId} and the fabric ID before our CA copies
706
+ * its tags; otherwise a peer could obtain tags it never held. Its tags must also equal {@link sessionTags}, the tags of
707
+ * the NOC the peer proved to hold in CASE, because an older NOC our CA issued to the same node also verifies and may
708
+ * carry tags a later rotation removed. Rejects when any of this fails.
709
+ */
710
+ async function verifiedCurrentNoc(
711
+ nocs: OperationalCertificate[],
712
+ fabric: Fabric,
713
+ nodeId: NodeId,
714
+ sessionTags: readonly CaseAuthenticatedTag[],
715
+ ) {
716
+ if (nocs.length !== 1) {
717
+ throw new UnexpectedDataError(`Peer reported ${nocs.length} NOCs for its fabric instead of one`);
718
+ }
719
+ const [{ noc, icac }] = nocs;
720
+ await fabric.verifyCredentials(noc, icac);
721
+ const { subject } = Noc.fromTlv(noc).cert;
722
+ if (subject.nodeId !== nodeId || subject.fabricId !== fabric.fabricId) {
723
+ throw new UnexpectedDataError(
724
+ `Reported NOC is for node ${NodeId.strOf(subject.nodeId)} of fabric ${subject.fabricId}, not node ${NodeId.strOf(nodeId)} of fabric ${fabric.fabricId}`,
725
+ );
726
+ }
727
+ const tags = subject.caseAuthenticatedTags ?? [];
728
+ if (tags.length !== sessionTags.length || tags.some(tag => !sessionTags.includes(tag))) {
729
+ throw new UnexpectedDataError(
730
+ `Reported NOC carries CASE Authenticated Tags ${tags.join(", ") || "none"}, not ${sessionTags.join(", ") || "none"} of the NOC the node authenticated with`,
731
+ );
732
+ }
733
+ return { noc, caseAuthenticatedTags: subject.caseAuthenticatedTags };
734
+ }
735
+
736
+ /** Read Breadcrumb, the NOCs and CurrentFabricIndex of the accessing fabric in one request. */
737
+ async function certificateState(interaction: ClientInteraction): Promise<CertificateState> {
738
+ const state: CertificateState = {};
739
+ for await (const chunk of interaction.read(
740
+ Read(
741
+ { fabricFilter: true },
742
+ Read.Attribute({ endpoint: RootEndpointNumber, cluster: GeneralCommissioning, attributes: "breadcrumb" }),
743
+ Read.Attribute({
744
+ endpoint: RootEndpointNumber,
745
+ cluster: OperationalCredentials,
746
+ attributes: ["nocs", "currentFabricIndex"],
747
+ }),
748
+ ),
749
+ )) {
750
+ for await (const report of chunk) {
751
+ if (report.kind !== "attr-value") {
752
+ continue;
753
+ }
754
+ const { value } = report;
755
+ if (report.path.clusterId === GeneralCommissioning.id) {
756
+ if (typeof value === "number" || typeof value === "bigint") {
757
+ state.breadcrumb = BigInt(value);
758
+ }
759
+ continue;
760
+ }
761
+ if (typeof value === "number") {
762
+ state.fabricIndex = value;
763
+ continue;
764
+ }
765
+ if (Array.isArray(value)) {
766
+ state.nocs = value.flatMap(entry =>
767
+ isObject(entry) && Bytes.isBytes(entry.noc)
768
+ ? [{ noc: entry.noc, icac: Bytes.isBytes(entry.icac) ? entry.icac : undefined }]
769
+ : [],
770
+ );
771
+ }
772
+ }
773
+ }
774
+ return state;
775
+ }
776
+
777
+ /**
778
+ * Close our sessions with a peer that cleared them without notice, drop the resumption record that belongs to the
779
+ * replaced certificate, and re-establish subscriptions instead of waiting for them to time out.
780
+ *
781
+ * Logs a failed step and continues, so a cleanup failure never decides the outcome of the update. A session the peer
782
+ * cleared fails on its next use, and a resumption record the peer no longer knows leads to a full CASE handshake.
783
+ */
784
+ async function forgetSessions(
785
+ { peers, sessions, environment }: OperationalCertificateUpdate.Context,
786
+ address: PeerAddress,
787
+ reason: string,
788
+ ) {
789
+ try {
790
+ await peers.for(address).disconnect(new FabricChangedError(reason));
791
+ } catch (error) {
792
+ logger.info(`Could not close the sessions of ${address}:`, error);
793
+ }
794
+ try {
795
+ await sessions.deleteResumptionRecord(address);
796
+ } catch (error) {
797
+ logger.info(`Could not drop the resumption record of ${address}:`, error);
798
+ }
799
+ environment.maybeGet(ClientSubscriptions)?.closeForPeer(address);
800
+ }
801
+
802
+ interface AdministratorSession {
803
+ session: NodeSession;
804
+ interaction: ClientInteraction;
805
+ }
806
+
807
+ /** Obtain a CASE session with the peer and an interaction bound to exactly that session. */
808
+ async function connectCase(
809
+ { peers, exchanges, environment }: OperationalCertificateUpdate.Context,
810
+ address: PeerAddress,
811
+ options: { abort?: AbortSignal; connectionTimeout?: Duration },
812
+ ): Promise<AdministratorSession> {
813
+ const session = await peers.for(address).connect(options);
814
+ options.abort?.throwIfAborted();
815
+ NodeSession.assert(session, `Peer ${address} did not yield a CASE session`);
816
+ return {
817
+ session,
818
+ interaction: new ClientInteraction({
819
+ environment,
820
+ exchangeProvider: new DedicatedChannelExchangeProvider(exchanges, session),
821
+ address,
822
+ }),
823
+ };
824
+ }
825
+
826
+ /** Run {@link fn} with a CASE session from {@link connectCase} and close its interaction afterwards. */
827
+ async function withCase<T>(
828
+ context: OperationalCertificateUpdate.Context,
829
+ address: PeerAddress,
830
+ options: { abort?: AbortSignal; connectionTimeout?: Duration },
831
+ fn: (session: AdministratorSession) => Promise<T>,
832
+ ) {
833
+ const session = await connectCase(context, address, options);
834
+ try {
835
+ return await fn(session);
836
+ } finally {
837
+ await session.interaction.close();
838
+ }
839
+ }
840
+
841
+ /** The update armed no fail-safe, so nothing on the peer needs to be undone. */
842
+ function isArmRefusal(cause: unknown) {
843
+ return (
844
+ cause instanceof OperationalCertificateUpdateBusyError ||
845
+ cause instanceof OperationalCertificateUpdateRefusedError
846
+ );
847
+ }
848
+
849
+ /** Rejects with a Busy or Refused error that carries `fabricIndexOnPeer` when the peer answers with an error code. */
850
+ async function armFailsafe(
851
+ interaction: ClientInteraction,
852
+ { failsafe, breadcrumb }: FailsafeArm,
853
+ fabricIndexOnPeer: FabricIndex,
854
+ ) {
855
+ const { errorCode, debugText } = responseOf(
856
+ await AdministratorCommands.invoke(interaction, {
857
+ endpoint: RootEndpointNumber,
858
+ cluster: GeneralCommissioning,
859
+ command: "armFailSafe",
860
+ fields: { expiryLengthSeconds: Math.ceil(Seconds.of(failsafe)), breadcrumb },
861
+ }),
862
+ "ArmFailSafe",
863
+ );
864
+ if (errorCode === GeneralCommissioning.CommissioningError.Ok) {
865
+ return;
866
+ }
867
+ if (errorCode === GeneralCommissioning.CommissioningError.BusyWithOtherAdmin) {
868
+ throw new OperationalCertificateUpdateBusyError(
869
+ `Cannot update the operational certificate of ${interaction.address}: ArmFailSafe failed because another administrator holds the fail-safe or a commissioning window is open; retry later`,
870
+ { fabricIndexOnPeer },
871
+ );
872
+ }
873
+ throw new OperationalCertificateUpdateRefusedError(
874
+ `Cannot update the operational certificate of ${interaction.address}: ArmFailSafe failed with ${commissioningErrorText(errorCode, debugText)}`,
875
+ { fabricIndexOnPeer },
876
+ );
877
+ }
878
+
879
+ /**
880
+ * Expire the fail-safe at once so the peer rolls back. Failure is logged; it only delays the rollback until the
881
+ * fail-safe expires. Resolves to whether the peer confirmed the disarm.
882
+ */
883
+ async function disarmFailsafe(interaction: ClientInteraction): Promise<boolean> {
884
+ let failure: unknown;
885
+ try {
886
+ const { errorCode, debugText } = responseOf(
887
+ await AdministratorCommands.invoke(interaction, {
888
+ endpoint: RootEndpointNumber,
889
+ cluster: GeneralCommissioning,
890
+ command: "armFailSafe",
891
+ fields: { expiryLengthSeconds: 0, breadcrumb: 0 },
892
+ }),
893
+ "ArmFailSafe",
894
+ );
895
+ if (errorCode === GeneralCommissioning.CommissioningError.Ok) {
896
+ return true;
897
+ }
898
+ failure = commissioningErrorText(errorCode, debugText);
899
+ } catch (error) {
900
+ failure = error;
901
+ }
902
+ logger.info(
903
+ `Could not disarm the fail-safe of ${interaction.address}; it rolls back when the fail-safe expires:`,
904
+ failure,
905
+ );
906
+ return false;
907
+ }
908
+
909
+ function commissioningErrorText(errorCode: GeneralCommissioning.CommissioningError, debugText?: string) {
910
+ return `${GeneralCommissioning.CommissioningError[errorCode]} (${errorCode})${debugText ? `, ${debugText}` : ""}`;
911
+ }
912
+
913
+ /**
914
+ * A response command, which {@link AdministratorCommands.invoke} omits when the peer answers with a bare success
915
+ * status.
916
+ */
917
+ function responseOf<T>(response: T | undefined, command: string): T {
918
+ if (response === undefined) {
919
+ throw new UnexpectedDataError(`${command} was answered with a status instead of a response`);
920
+ }
921
+ return response;
922
+ }