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

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 (527) 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 +19 -20
  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/errors.d.ts +3 -1
  11. package/dist/cjs/action/errors.d.ts.map +1 -1
  12. package/dist/cjs/action/errors.js +7 -2
  13. package/dist/cjs/action/errors.js.map +1 -1
  14. package/dist/cjs/action/protocols.d.ts +6 -1
  15. package/dist/cjs/action/protocols.d.ts.map +1 -1
  16. package/dist/cjs/action/request/Invoke.d.ts +24 -1
  17. package/dist/cjs/action/request/Invoke.d.ts.map +1 -1
  18. package/dist/cjs/action/request/Invoke.js +40 -12
  19. package/dist/cjs/action/request/Invoke.js.map +1 -1
  20. package/dist/cjs/action/request/Write.d.ts.map +1 -1
  21. package/dist/cjs/action/request/Write.js +6 -5
  22. package/dist/cjs/action/request/Write.js.map +1 -1
  23. package/dist/cjs/action/response/ReadResult.d.ts +14 -5
  24. package/dist/cjs/action/response/ReadResult.d.ts.map +1 -1
  25. package/dist/cjs/action/server/AttributeReadResponse.d.ts.map +1 -1
  26. package/dist/cjs/action/server/AttributeReadResponse.js +1 -1
  27. package/dist/cjs/action/server/AttributeReadResponse.js.map +1 -1
  28. package/dist/cjs/action/server/AttributeWriteResponse.d.ts.map +1 -1
  29. package/dist/cjs/action/server/AttributeWriteResponse.js +4 -2
  30. package/dist/cjs/action/server/AttributeWriteResponse.js.map +1 -1
  31. package/dist/cjs/action/server/EventReadResponse.d.ts.map +1 -1
  32. package/dist/cjs/action/server/EventReadResponse.js +1 -0
  33. package/dist/cjs/action/server/EventReadResponse.js.map +1 -1
  34. package/dist/cjs/advertisement/mdns/MdnsAdvertisement.d.ts +1 -1
  35. package/dist/cjs/advertisement/mdns/MdnsAdvertisement.d.ts.map +1 -1
  36. package/dist/cjs/advertisement/mdns/MdnsAdvertisement.js +7 -7
  37. package/dist/cjs/advertisement/mdns/MdnsAdvertisement.js.map +1 -1
  38. package/dist/cjs/ble/Ble.d.ts +2 -0
  39. package/dist/cjs/ble/Ble.d.ts.map +1 -1
  40. package/dist/cjs/ble/Ble.js +4 -0
  41. package/dist/cjs/ble/Ble.js.map +1 -1
  42. package/dist/cjs/certificate/CdSigners.d.ts +52 -0
  43. package/dist/cjs/certificate/CdSigners.d.ts.map +1 -0
  44. package/dist/cjs/certificate/CdSigners.js +111 -0
  45. package/dist/cjs/certificate/CdSigners.js.map +6 -0
  46. package/dist/cjs/certificate/CertificateAuthority.d.ts +1 -1
  47. package/dist/cjs/certificate/CertificateAuthority.d.ts.map +1 -1
  48. package/dist/cjs/certificate/DeviceAttestationValidator.d.ts +53 -7
  49. package/dist/cjs/certificate/DeviceAttestationValidator.d.ts.map +1 -1
  50. package/dist/cjs/certificate/DeviceAttestationValidator.js +114 -42
  51. package/dist/cjs/certificate/DeviceAttestationValidator.js.map +1 -1
  52. package/dist/cjs/certificate/DeviceCertification.d.ts.map +1 -1
  53. package/dist/cjs/certificate/DeviceCertification.js +5 -2
  54. package/dist/cjs/certificate/DeviceCertification.js.map +1 -1
  55. package/dist/cjs/certificate/index.d.ts +1 -0
  56. package/dist/cjs/certificate/index.d.ts.map +1 -1
  57. package/dist/cjs/certificate/index.js +1 -0
  58. package/dist/cjs/certificate/index.js.map +1 -1
  59. package/dist/cjs/certificate/kinds/AttestationCertificates.d.ts +42 -6
  60. package/dist/cjs/certificate/kinds/AttestationCertificates.d.ts.map +1 -1
  61. package/dist/cjs/certificate/kinds/AttestationCertificates.js +110 -13
  62. package/dist/cjs/certificate/kinds/AttestationCertificates.js.map +1 -1
  63. package/dist/cjs/certificate/kinds/Certificate.d.ts +13 -7
  64. package/dist/cjs/certificate/kinds/Certificate.d.ts.map +1 -1
  65. package/dist/cjs/certificate/kinds/Certificate.js +146 -240
  66. package/dist/cjs/certificate/kinds/Certificate.js.map +2 -2
  67. package/dist/cjs/certificate/kinds/CertificationDeclaration.d.ts +21 -3
  68. package/dist/cjs/certificate/kinds/CertificationDeclaration.d.ts.map +1 -1
  69. package/dist/cjs/certificate/kinds/CertificationDeclaration.js +76 -20
  70. package/dist/cjs/certificate/kinds/CertificationDeclaration.js.map +1 -1
  71. package/dist/cjs/certificate/kinds/DistinguishedName.d.ts +190 -0
  72. package/dist/cjs/certificate/kinds/DistinguishedName.d.ts.map +1 -0
  73. package/dist/cjs/certificate/kinds/DistinguishedName.js +417 -0
  74. package/dist/cjs/certificate/kinds/DistinguishedName.js.map +6 -0
  75. package/dist/cjs/certificate/kinds/Icac.d.ts.map +1 -1
  76. package/dist/cjs/certificate/kinds/Icac.js +5 -10
  77. package/dist/cjs/certificate/kinds/Icac.js.map +1 -1
  78. package/dist/cjs/certificate/kinds/Noc.d.ts.map +1 -1
  79. package/dist/cjs/certificate/kinds/Noc.js +5 -4
  80. package/dist/cjs/certificate/kinds/Noc.js.map +1 -1
  81. package/dist/cjs/certificate/kinds/OperationalBase.d.ts.map +1 -1
  82. package/dist/cjs/certificate/kinds/OperationalBase.js +4 -2
  83. package/dist/cjs/certificate/kinds/OperationalBase.js.map +1 -1
  84. package/dist/cjs/certificate/kinds/Rcac.d.ts.map +1 -1
  85. package/dist/cjs/certificate/kinds/Rcac.js +5 -10
  86. package/dist/cjs/certificate/kinds/Rcac.js.map +1 -1
  87. package/dist/cjs/certificate/kinds/Vvsc.d.ts +3 -3
  88. package/dist/cjs/certificate/kinds/Vvsc.d.ts.map +1 -1
  89. package/dist/cjs/certificate/kinds/Vvsc.js +19 -14
  90. package/dist/cjs/certificate/kinds/Vvsc.js.map +1 -1
  91. package/dist/cjs/certificate/kinds/definitions/asn.d.ts +1 -1
  92. package/dist/cjs/certificate/kinds/definitions/asn.d.ts.map +1 -1
  93. package/dist/cjs/certificate/kinds/definitions/asn.js.map +1 -1
  94. package/dist/cjs/certificate/kinds/definitions/attestation.d.ts +15 -15
  95. package/dist/cjs/certificate/kinds/definitions/attestation.d.ts.map +1 -1
  96. package/dist/cjs/certificate/kinds/definitions/base.d.ts +33 -0
  97. package/dist/cjs/certificate/kinds/definitions/base.d.ts.map +1 -1
  98. package/dist/cjs/certificate/kinds/definitions/base.js +8 -1
  99. package/dist/cjs/certificate/kinds/definitions/base.js.map +1 -1
  100. package/dist/cjs/certificate/kinds/definitions/operational.d.ts +24 -20
  101. package/dist/cjs/certificate/kinds/definitions/operational.d.ts.map +1 -1
  102. package/dist/cjs/certificate/kinds/definitions/operational.js +5 -3
  103. package/dist/cjs/certificate/kinds/definitions/operational.js.map +1 -1
  104. package/dist/cjs/codec/MessageCodec.d.ts +27 -2
  105. package/dist/cjs/codec/MessageCodec.d.ts.map +1 -1
  106. package/dist/cjs/codec/MessageCodec.js +81 -74
  107. package/dist/cjs/codec/MessageCodec.js.map +1 -1
  108. package/dist/cjs/dcl/DclCertificateService.d.ts +28 -7
  109. package/dist/cjs/dcl/DclCertificateService.d.ts.map +1 -1
  110. package/dist/cjs/dcl/DclCertificateService.js +103 -30
  111. package/dist/cjs/dcl/DclCertificateService.js.map +1 -1
  112. package/dist/cjs/fabric/Fabric.d.ts +10 -5
  113. package/dist/cjs/fabric/Fabric.d.ts.map +1 -1
  114. package/dist/cjs/fabric/Fabric.js +12 -5
  115. package/dist/cjs/fabric/Fabric.js.map +1 -1
  116. package/dist/cjs/fabric/FabricManager.d.ts +2 -2
  117. package/dist/cjs/fabric/FabricManager.js +2 -2
  118. package/dist/cjs/groups/FabricGroups.d.ts +2 -0
  119. package/dist/cjs/groups/FabricGroups.d.ts.map +1 -1
  120. package/dist/cjs/groups/FabricGroups.js +4 -0
  121. package/dist/cjs/groups/FabricGroups.js.map +1 -1
  122. package/dist/cjs/groups/Groups.d.ts +7 -0
  123. package/dist/cjs/groups/Groups.d.ts.map +1 -1
  124. package/dist/cjs/groups/Groups.js +11 -2
  125. package/dist/cjs/groups/Groups.js.map +1 -1
  126. package/dist/cjs/groups/KeySets.d.ts +3 -3
  127. package/dist/cjs/groups/KeySets.js +3 -3
  128. package/dist/cjs/mdns/InterfaceResponder.d.ts +137 -0
  129. package/dist/cjs/mdns/InterfaceResponder.d.ts.map +1 -0
  130. package/dist/cjs/mdns/InterfaceResponder.js +799 -0
  131. package/dist/cjs/mdns/InterfaceResponder.js.map +6 -0
  132. package/dist/cjs/mdns/MdnsServer.d.ts +82 -9
  133. package/dist/cjs/mdns/MdnsServer.d.ts.map +1 -1
  134. package/dist/cjs/mdns/MdnsServer.js +337 -267
  135. package/dist/cjs/mdns/MdnsServer.js.map +2 -2
  136. package/dist/cjs/peer/CommissioningConnection.d.ts.map +1 -1
  137. package/dist/cjs/peer/CommissioningConnection.js +4 -2
  138. package/dist/cjs/peer/CommissioningConnection.js.map +1 -1
  139. package/dist/cjs/peer/ControllerCommissioner.d.ts.map +1 -1
  140. package/dist/cjs/peer/ControllerCommissioner.js +48 -13
  141. package/dist/cjs/peer/ControllerCommissioner.js.map +1 -1
  142. package/dist/cjs/peer/ControllerCommissioningFlow.d.ts +7 -7
  143. package/dist/cjs/peer/ControllerCommissioningFlow.d.ts.map +1 -1
  144. package/dist/cjs/peer/ControllerCommissioningFlow.js +109 -32
  145. package/dist/cjs/peer/ControllerCommissioningFlow.js.map +1 -1
  146. package/dist/cjs/peer/Peer.d.ts +5 -0
  147. package/dist/cjs/peer/Peer.d.ts.map +1 -1
  148. package/dist/cjs/peer/Peer.js +29 -1
  149. package/dist/cjs/peer/Peer.js.map +1 -1
  150. package/dist/cjs/peer/PeerAddressStore.d.ts +37 -0
  151. package/dist/cjs/peer/PeerAddressStore.d.ts.map +1 -0
  152. package/dist/cjs/peer/PeerAddressStore.js +114 -0
  153. package/dist/cjs/peer/PeerAddressStore.js.map +6 -0
  154. package/dist/cjs/peer/PeerConnection.d.ts.map +1 -1
  155. package/dist/cjs/peer/PeerConnection.js +0 -1
  156. package/dist/cjs/peer/PeerConnection.js.map +1 -1
  157. package/dist/cjs/peer/PeerDescriptor.d.ts +3 -4
  158. package/dist/cjs/peer/PeerDescriptor.d.ts.map +1 -1
  159. package/dist/cjs/peer/PeerDescriptor.js.map +1 -1
  160. package/dist/cjs/peer/PeerExchangeProvider.d.ts.map +1 -1
  161. package/dist/cjs/peer/PeerExchangeProvider.js +2 -1
  162. package/dist/cjs/peer/PeerExchangeProvider.js.map +1 -1
  163. package/dist/cjs/peer/PeerLossContext.d.ts +10 -2
  164. package/dist/cjs/peer/PeerLossContext.d.ts.map +1 -1
  165. package/dist/cjs/peer/PhysicalDeviceProperties.d.ts +13 -0
  166. package/dist/cjs/peer/PhysicalDeviceProperties.d.ts.map +1 -1
  167. package/dist/cjs/peer/PhysicalDeviceProperties.js +3 -2
  168. package/dist/cjs/peer/PhysicalDeviceProperties.js.map +1 -1
  169. package/dist/cjs/peer/RebootResubscribeArmer.d.ts +3 -3
  170. package/dist/cjs/peer/RebootResubscribeArmer.d.ts.map +1 -1
  171. package/dist/cjs/peer/RebootResubscribeArmer.js +21 -9
  172. package/dist/cjs/peer/RebootResubscribeArmer.js.map +1 -1
  173. package/dist/cjs/peer/index.d.ts +1 -0
  174. package/dist/cjs/peer/index.d.ts.map +1 -1
  175. package/dist/cjs/peer/index.js +1 -0
  176. package/dist/cjs/peer/index.js.map +1 -1
  177. package/dist/cjs/protocol/DeviceAdvertiser.d.ts.map +1 -1
  178. package/dist/cjs/protocol/DeviceAdvertiser.js +1 -1
  179. package/dist/cjs/protocol/DeviceAdvertiser.js.map +1 -1
  180. package/dist/cjs/protocol/ExchangeManager.d.ts +0 -1
  181. package/dist/cjs/protocol/ExchangeManager.d.ts.map +1 -1
  182. package/dist/cjs/protocol/ExchangeManager.js +136 -64
  183. package/dist/cjs/protocol/ExchangeManager.js.map +1 -1
  184. package/dist/cjs/protocol/ExchangeProvider.d.ts +3 -2
  185. package/dist/cjs/protocol/ExchangeProvider.d.ts.map +1 -1
  186. package/dist/cjs/protocol/ExchangeProvider.js.map +1 -1
  187. package/dist/cjs/protocol/MessageExchange.d.ts +13 -0
  188. package/dist/cjs/protocol/MessageExchange.d.ts.map +1 -1
  189. package/dist/cjs/protocol/MessageExchange.js +16 -6
  190. package/dist/cjs/protocol/MessageExchange.js.map +1 -1
  191. package/dist/cjs/protocol/MessageReceptionState.d.ts +1 -1
  192. package/dist/cjs/protocol/errors.d.ts +7 -1
  193. package/dist/cjs/protocol/errors.d.ts.map +1 -1
  194. package/dist/cjs/protocol/errors.js +3 -0
  195. package/dist/cjs/protocol/errors.js.map +1 -1
  196. package/dist/cjs/securechannel/SecureChannelMessenger.d.ts +6 -1
  197. package/dist/cjs/securechannel/SecureChannelMessenger.d.ts.map +1 -1
  198. package/dist/cjs/securechannel/SecureChannelMessenger.js +27 -12
  199. package/dist/cjs/securechannel/SecureChannelMessenger.js.map +1 -1
  200. package/dist/cjs/session/GroupSession.d.ts +58 -15
  201. package/dist/cjs/session/GroupSession.d.ts.map +1 -1
  202. package/dist/cjs/session/GroupSession.js +97 -102
  203. package/dist/cjs/session/GroupSession.js.map +2 -2
  204. package/dist/cjs/session/NodeSession.d.ts +50 -1
  205. package/dist/cjs/session/NodeSession.d.ts.map +1 -1
  206. package/dist/cjs/session/NodeSession.js +80 -4
  207. package/dist/cjs/session/NodeSession.js.map +1 -1
  208. package/dist/cjs/session/SecureSession.d.ts +9 -0
  209. package/dist/cjs/session/SecureSession.d.ts.map +1 -1
  210. package/dist/cjs/session/SecureSession.js +12 -0
  211. package/dist/cjs/session/SecureSession.js.map +1 -1
  212. package/dist/cjs/session/Session.d.ts +2 -2
  213. package/dist/cjs/session/Session.d.ts.map +1 -1
  214. package/dist/cjs/session/Session.js +1 -1
  215. package/dist/cjs/session/SessionManager.d.ts +76 -28
  216. package/dist/cjs/session/SessionManager.d.ts.map +1 -1
  217. package/dist/cjs/session/SessionManager.js +316 -153
  218. package/dist/cjs/session/SessionManager.js.map +2 -2
  219. package/dist/cjs/session/UnsecuredSession.d.ts +0 -1
  220. package/dist/cjs/session/UnsecuredSession.d.ts.map +1 -1
  221. package/dist/cjs/session/UnsecuredSession.js +2 -4
  222. package/dist/cjs/session/UnsecuredSession.js.map +1 -1
  223. package/dist/cjs/session/case/CaseClient.d.ts +5 -0
  224. package/dist/cjs/session/case/CaseClient.d.ts.map +1 -1
  225. package/dist/cjs/session/case/CaseClient.js +12 -11
  226. package/dist/cjs/session/case/CaseClient.js.map +2 -2
  227. package/dist/cjs/session/case/CaseServer.d.ts.map +1 -1
  228. package/dist/cjs/session/case/CaseServer.js +31 -11
  229. package/dist/cjs/session/case/CaseServer.js.map +1 -1
  230. package/dist/esm/action/Val.d.ts +8 -0
  231. package/dist/esm/action/Val.d.ts.map +1 -1
  232. package/dist/esm/action/client/ClientInteraction.d.ts.map +1 -1
  233. package/dist/esm/action/client/ClientInteraction.js +19 -20
  234. package/dist/esm/action/client/ClientInteraction.js.map +1 -1
  235. package/dist/esm/action/client/ClientRequest.d.ts +14 -0
  236. package/dist/esm/action/client/ClientRequest.d.ts.map +1 -1
  237. package/dist/esm/action/client/InputChunk.js +39 -2
  238. package/dist/esm/action/client/InputChunk.js.map +1 -1
  239. package/dist/esm/action/errors.d.ts +3 -1
  240. package/dist/esm/action/errors.d.ts.map +1 -1
  241. package/dist/esm/action/errors.js +7 -2
  242. package/dist/esm/action/errors.js.map +1 -1
  243. package/dist/esm/action/protocols.d.ts +6 -1
  244. package/dist/esm/action/protocols.d.ts.map +1 -1
  245. package/dist/esm/action/request/Invoke.d.ts +24 -1
  246. package/dist/esm/action/request/Invoke.d.ts.map +1 -1
  247. package/dist/esm/action/request/Invoke.js +41 -13
  248. package/dist/esm/action/request/Invoke.js.map +1 -1
  249. package/dist/esm/action/request/Write.d.ts.map +1 -1
  250. package/dist/esm/action/request/Write.js +7 -6
  251. package/dist/esm/action/request/Write.js.map +1 -1
  252. package/dist/esm/action/response/ReadResult.d.ts +14 -5
  253. package/dist/esm/action/response/ReadResult.d.ts.map +1 -1
  254. package/dist/esm/action/server/AttributeReadResponse.d.ts.map +1 -1
  255. package/dist/esm/action/server/AttributeReadResponse.js +2 -2
  256. package/dist/esm/action/server/AttributeReadResponse.js.map +1 -1
  257. package/dist/esm/action/server/AttributeWriteResponse.d.ts.map +1 -1
  258. package/dist/esm/action/server/AttributeWriteResponse.js +11 -3
  259. package/dist/esm/action/server/AttributeWriteResponse.js.map +1 -1
  260. package/dist/esm/action/server/EventReadResponse.d.ts.map +1 -1
  261. package/dist/esm/action/server/EventReadResponse.js +1 -0
  262. package/dist/esm/action/server/EventReadResponse.js.map +1 -1
  263. package/dist/esm/advertisement/mdns/MdnsAdvertisement.d.ts +1 -1
  264. package/dist/esm/advertisement/mdns/MdnsAdvertisement.d.ts.map +1 -1
  265. package/dist/esm/advertisement/mdns/MdnsAdvertisement.js +7 -7
  266. package/dist/esm/advertisement/mdns/MdnsAdvertisement.js.map +1 -1
  267. package/dist/esm/ble/Ble.d.ts +2 -0
  268. package/dist/esm/ble/Ble.d.ts.map +1 -1
  269. package/dist/esm/ble/Ble.js +4 -0
  270. package/dist/esm/ble/Ble.js.map +1 -1
  271. package/dist/esm/certificate/CdSigners.d.ts +52 -0
  272. package/dist/esm/certificate/CdSigners.d.ts.map +1 -0
  273. package/dist/esm/certificate/CdSigners.js +91 -0
  274. package/dist/esm/certificate/CdSigners.js.map +6 -0
  275. package/dist/esm/certificate/CertificateAuthority.d.ts +1 -1
  276. package/dist/esm/certificate/CertificateAuthority.d.ts.map +1 -1
  277. package/dist/esm/certificate/DeviceAttestationValidator.d.ts +53 -7
  278. package/dist/esm/certificate/DeviceAttestationValidator.d.ts.map +1 -1
  279. package/dist/esm/certificate/DeviceAttestationValidator.js +115 -43
  280. package/dist/esm/certificate/DeviceAttestationValidator.js.map +1 -1
  281. package/dist/esm/certificate/DeviceCertification.d.ts.map +1 -1
  282. package/dist/esm/certificate/DeviceCertification.js +5 -2
  283. package/dist/esm/certificate/DeviceCertification.js.map +1 -1
  284. package/dist/esm/certificate/index.d.ts +1 -0
  285. package/dist/esm/certificate/index.d.ts.map +1 -1
  286. package/dist/esm/certificate/index.js +1 -0
  287. package/dist/esm/certificate/index.js.map +1 -1
  288. package/dist/esm/certificate/kinds/AttestationCertificates.d.ts +42 -6
  289. package/dist/esm/certificate/kinds/AttestationCertificates.d.ts.map +1 -1
  290. package/dist/esm/certificate/kinds/AttestationCertificates.js +112 -15
  291. package/dist/esm/certificate/kinds/AttestationCertificates.js.map +1 -1
  292. package/dist/esm/certificate/kinds/Certificate.d.ts +13 -7
  293. package/dist/esm/certificate/kinds/Certificate.d.ts.map +1 -1
  294. package/dist/esm/certificate/kinds/Certificate.js +153 -256
  295. package/dist/esm/certificate/kinds/Certificate.js.map +2 -2
  296. package/dist/esm/certificate/kinds/CertificationDeclaration.d.ts +21 -3
  297. package/dist/esm/certificate/kinds/CertificationDeclaration.d.ts.map +1 -1
  298. package/dist/esm/certificate/kinds/CertificationDeclaration.js +79 -20
  299. package/dist/esm/certificate/kinds/CertificationDeclaration.js.map +1 -1
  300. package/dist/esm/certificate/kinds/DistinguishedName.d.ts +190 -0
  301. package/dist/esm/certificate/kinds/DistinguishedName.d.ts.map +1 -0
  302. package/dist/esm/certificate/kinds/DistinguishedName.js +422 -0
  303. package/dist/esm/certificate/kinds/DistinguishedName.js.map +6 -0
  304. package/dist/esm/certificate/kinds/Icac.d.ts.map +1 -1
  305. package/dist/esm/certificate/kinds/Icac.js +6 -11
  306. package/dist/esm/certificate/kinds/Icac.js.map +1 -1
  307. package/dist/esm/certificate/kinds/Noc.d.ts.map +1 -1
  308. package/dist/esm/certificate/kinds/Noc.js +5 -4
  309. package/dist/esm/certificate/kinds/Noc.js.map +1 -1
  310. package/dist/esm/certificate/kinds/OperationalBase.d.ts.map +1 -1
  311. package/dist/esm/certificate/kinds/OperationalBase.js +4 -2
  312. package/dist/esm/certificate/kinds/OperationalBase.js.map +1 -1
  313. package/dist/esm/certificate/kinds/Rcac.d.ts.map +1 -1
  314. package/dist/esm/certificate/kinds/Rcac.js +6 -11
  315. package/dist/esm/certificate/kinds/Rcac.js.map +1 -1
  316. package/dist/esm/certificate/kinds/Vvsc.d.ts +3 -3
  317. package/dist/esm/certificate/kinds/Vvsc.d.ts.map +1 -1
  318. package/dist/esm/certificate/kinds/Vvsc.js +20 -15
  319. package/dist/esm/certificate/kinds/Vvsc.js.map +1 -1
  320. package/dist/esm/certificate/kinds/definitions/asn.d.ts +1 -1
  321. package/dist/esm/certificate/kinds/definitions/asn.d.ts.map +1 -1
  322. package/dist/esm/certificate/kinds/definitions/asn.js.map +1 -1
  323. package/dist/esm/certificate/kinds/definitions/attestation.d.ts +15 -15
  324. package/dist/esm/certificate/kinds/definitions/attestation.d.ts.map +1 -1
  325. package/dist/esm/certificate/kinds/definitions/base.d.ts +33 -0
  326. package/dist/esm/certificate/kinds/definitions/base.d.ts.map +1 -1
  327. package/dist/esm/certificate/kinds/definitions/base.js +9 -2
  328. package/dist/esm/certificate/kinds/definitions/base.js.map +1 -1
  329. package/dist/esm/certificate/kinds/definitions/operational.d.ts +24 -20
  330. package/dist/esm/certificate/kinds/definitions/operational.d.ts.map +1 -1
  331. package/dist/esm/certificate/kinds/definitions/operational.js +5 -3
  332. package/dist/esm/certificate/kinds/definitions/operational.js.map +1 -1
  333. package/dist/esm/codec/MessageCodec.d.ts +27 -2
  334. package/dist/esm/codec/MessageCodec.d.ts.map +1 -1
  335. package/dist/esm/codec/MessageCodec.js +82 -75
  336. package/dist/esm/codec/MessageCodec.js.map +1 -1
  337. package/dist/esm/dcl/DclCertificateService.d.ts +28 -7
  338. package/dist/esm/dcl/DclCertificateService.d.ts.map +1 -1
  339. package/dist/esm/dcl/DclCertificateService.js +108 -31
  340. package/dist/esm/dcl/DclCertificateService.js.map +1 -1
  341. package/dist/esm/fabric/Fabric.d.ts +10 -5
  342. package/dist/esm/fabric/Fabric.d.ts.map +1 -1
  343. package/dist/esm/fabric/Fabric.js +12 -5
  344. package/dist/esm/fabric/Fabric.js.map +1 -1
  345. package/dist/esm/fabric/FabricManager.d.ts +2 -2
  346. package/dist/esm/fabric/FabricManager.js +2 -2
  347. package/dist/esm/groups/FabricGroups.d.ts +2 -0
  348. package/dist/esm/groups/FabricGroups.d.ts.map +1 -1
  349. package/dist/esm/groups/FabricGroups.js +4 -0
  350. package/dist/esm/groups/FabricGroups.js.map +1 -1
  351. package/dist/esm/groups/Groups.d.ts +7 -0
  352. package/dist/esm/groups/Groups.d.ts.map +1 -1
  353. package/dist/esm/groups/Groups.js +11 -2
  354. package/dist/esm/groups/Groups.js.map +1 -1
  355. package/dist/esm/groups/KeySets.d.ts +3 -3
  356. package/dist/esm/groups/KeySets.js +3 -3
  357. package/dist/esm/mdns/InterfaceResponder.d.ts +137 -0
  358. package/dist/esm/mdns/InterfaceResponder.d.ts.map +1 -0
  359. package/dist/esm/mdns/InterfaceResponder.js +794 -0
  360. package/dist/esm/mdns/InterfaceResponder.js.map +6 -0
  361. package/dist/esm/mdns/MdnsServer.d.ts +82 -9
  362. package/dist/esm/mdns/MdnsServer.d.ts.map +1 -1
  363. package/dist/esm/mdns/MdnsServer.js +341 -273
  364. package/dist/esm/mdns/MdnsServer.js.map +2 -2
  365. package/dist/esm/peer/CommissioningConnection.d.ts.map +1 -1
  366. package/dist/esm/peer/CommissioningConnection.js +4 -2
  367. package/dist/esm/peer/CommissioningConnection.js.map +1 -1
  368. package/dist/esm/peer/ControllerCommissioner.d.ts.map +1 -1
  369. package/dist/esm/peer/ControllerCommissioner.js +48 -13
  370. package/dist/esm/peer/ControllerCommissioner.js.map +1 -1
  371. package/dist/esm/peer/ControllerCommissioningFlow.d.ts +7 -7
  372. package/dist/esm/peer/ControllerCommissioningFlow.d.ts.map +1 -1
  373. package/dist/esm/peer/ControllerCommissioningFlow.js +109 -32
  374. package/dist/esm/peer/ControllerCommissioningFlow.js.map +1 -1
  375. package/dist/esm/peer/Peer.d.ts +5 -0
  376. package/dist/esm/peer/Peer.d.ts.map +1 -1
  377. package/dist/esm/peer/Peer.js +29 -1
  378. package/dist/esm/peer/Peer.js.map +1 -1
  379. package/dist/esm/peer/PeerAddressStore.d.ts +37 -0
  380. package/dist/esm/peer/PeerAddressStore.d.ts.map +1 -0
  381. package/dist/esm/peer/PeerAddressStore.js +94 -0
  382. package/dist/esm/peer/PeerAddressStore.js.map +6 -0
  383. package/dist/esm/peer/PeerConnection.d.ts.map +1 -1
  384. package/dist/esm/peer/PeerConnection.js +0 -1
  385. package/dist/esm/peer/PeerConnection.js.map +1 -1
  386. package/dist/esm/peer/PeerDescriptor.d.ts +3 -4
  387. package/dist/esm/peer/PeerDescriptor.d.ts.map +1 -1
  388. package/dist/esm/peer/PeerDescriptor.js.map +1 -1
  389. package/dist/esm/peer/PeerExchangeProvider.d.ts.map +1 -1
  390. package/dist/esm/peer/PeerExchangeProvider.js +3 -2
  391. package/dist/esm/peer/PeerExchangeProvider.js.map +1 -1
  392. package/dist/esm/peer/PeerLossContext.d.ts +10 -2
  393. package/dist/esm/peer/PeerLossContext.d.ts.map +1 -1
  394. package/dist/esm/peer/PhysicalDeviceProperties.d.ts +13 -0
  395. package/dist/esm/peer/PhysicalDeviceProperties.d.ts.map +1 -1
  396. package/dist/esm/peer/PhysicalDeviceProperties.js +3 -2
  397. package/dist/esm/peer/PhysicalDeviceProperties.js.map +1 -1
  398. package/dist/esm/peer/RebootResubscribeArmer.d.ts +3 -3
  399. package/dist/esm/peer/RebootResubscribeArmer.d.ts.map +1 -1
  400. package/dist/esm/peer/RebootResubscribeArmer.js +21 -9
  401. package/dist/esm/peer/RebootResubscribeArmer.js.map +1 -1
  402. package/dist/esm/peer/index.d.ts +1 -0
  403. package/dist/esm/peer/index.d.ts.map +1 -1
  404. package/dist/esm/peer/index.js +1 -0
  405. package/dist/esm/peer/index.js.map +1 -1
  406. package/dist/esm/protocol/DeviceAdvertiser.d.ts.map +1 -1
  407. package/dist/esm/protocol/DeviceAdvertiser.js +1 -1
  408. package/dist/esm/protocol/DeviceAdvertiser.js.map +1 -1
  409. package/dist/esm/protocol/ExchangeManager.d.ts +0 -1
  410. package/dist/esm/protocol/ExchangeManager.d.ts.map +1 -1
  411. package/dist/esm/protocol/ExchangeManager.js +145 -67
  412. package/dist/esm/protocol/ExchangeManager.js.map +1 -1
  413. package/dist/esm/protocol/ExchangeProvider.d.ts +3 -2
  414. package/dist/esm/protocol/ExchangeProvider.d.ts.map +1 -1
  415. package/dist/esm/protocol/ExchangeProvider.js.map +1 -1
  416. package/dist/esm/protocol/MessageExchange.d.ts +13 -0
  417. package/dist/esm/protocol/MessageExchange.d.ts.map +1 -1
  418. package/dist/esm/protocol/MessageExchange.js +16 -6
  419. package/dist/esm/protocol/MessageExchange.js.map +1 -1
  420. package/dist/esm/protocol/MessageReceptionState.d.ts +1 -1
  421. package/dist/esm/protocol/errors.d.ts +7 -1
  422. package/dist/esm/protocol/errors.d.ts.map +1 -1
  423. package/dist/esm/protocol/errors.js +4 -1
  424. package/dist/esm/protocol/errors.js.map +1 -1
  425. package/dist/esm/securechannel/SecureChannelMessenger.d.ts +6 -1
  426. package/dist/esm/securechannel/SecureChannelMessenger.d.ts.map +1 -1
  427. package/dist/esm/securechannel/SecureChannelMessenger.js +27 -12
  428. package/dist/esm/securechannel/SecureChannelMessenger.js.map +1 -1
  429. package/dist/esm/session/GroupSession.d.ts +58 -15
  430. package/dist/esm/session/GroupSession.d.ts.map +1 -1
  431. package/dist/esm/session/GroupSession.js +97 -102
  432. package/dist/esm/session/GroupSession.js.map +2 -2
  433. package/dist/esm/session/NodeSession.d.ts +50 -1
  434. package/dist/esm/session/NodeSession.d.ts.map +1 -1
  435. package/dist/esm/session/NodeSession.js +83 -5
  436. package/dist/esm/session/NodeSession.js.map +1 -1
  437. package/dist/esm/session/SecureSession.d.ts +9 -0
  438. package/dist/esm/session/SecureSession.d.ts.map +1 -1
  439. package/dist/esm/session/SecureSession.js +18 -1
  440. package/dist/esm/session/SecureSession.js.map +1 -1
  441. package/dist/esm/session/Session.d.ts +2 -2
  442. package/dist/esm/session/Session.d.ts.map +1 -1
  443. package/dist/esm/session/Session.js +1 -1
  444. package/dist/esm/session/SessionManager.d.ts +76 -28
  445. package/dist/esm/session/SessionManager.d.ts.map +1 -1
  446. package/dist/esm/session/SessionManager.js +319 -156
  447. package/dist/esm/session/SessionManager.js.map +2 -2
  448. package/dist/esm/session/UnsecuredSession.d.ts +0 -1
  449. package/dist/esm/session/UnsecuredSession.d.ts.map +1 -1
  450. package/dist/esm/session/UnsecuredSession.js +5 -3
  451. package/dist/esm/session/UnsecuredSession.js.map +1 -1
  452. package/dist/esm/session/case/CaseClient.d.ts +5 -0
  453. package/dist/esm/session/case/CaseClient.d.ts.map +1 -1
  454. package/dist/esm/session/case/CaseClient.js +12 -11
  455. package/dist/esm/session/case/CaseClient.js.map +2 -2
  456. package/dist/esm/session/case/CaseServer.d.ts.map +1 -1
  457. package/dist/esm/session/case/CaseServer.js +31 -11
  458. package/dist/esm/session/case/CaseServer.js.map +1 -1
  459. package/package.json +5 -5
  460. package/src/action/Val.ts +8 -0
  461. package/src/action/client/ClientInteraction.ts +19 -21
  462. package/src/action/client/ClientRequest.ts +15 -0
  463. package/src/action/client/InputChunk.ts +57 -2
  464. package/src/action/errors.ts +10 -3
  465. package/src/action/protocols.ts +7 -1
  466. package/src/action/request/Invoke.ts +60 -15
  467. package/src/action/request/Write.ts +7 -6
  468. package/src/action/response/ReadResult.ts +15 -5
  469. package/src/action/server/AttributeReadResponse.ts +3 -2
  470. package/src/action/server/AttributeWriteResponse.ts +14 -3
  471. package/src/action/server/EventReadResponse.ts +1 -0
  472. package/src/advertisement/mdns/MdnsAdvertisement.ts +9 -9
  473. package/src/ble/Ble.ts +5 -0
  474. package/src/certificate/CdSigners.ts +137 -0
  475. package/src/certificate/CertificateAuthority.ts +1 -1
  476. package/src/certificate/DeviceAttestationValidator.ts +202 -54
  477. package/src/certificate/DeviceCertification.ts +6 -2
  478. package/src/certificate/index.ts +1 -0
  479. package/src/certificate/kinds/AttestationCertificates.ts +183 -15
  480. package/src/certificate/kinds/Certificate.ts +203 -308
  481. package/src/certificate/kinds/CertificationDeclaration.ts +100 -46
  482. package/src/certificate/kinds/DistinguishedName.ts +677 -0
  483. package/src/certificate/kinds/Icac.ts +7 -12
  484. package/src/certificate/kinds/Noc.ts +12 -8
  485. package/src/certificate/kinds/OperationalBase.ts +5 -2
  486. package/src/certificate/kinds/Rcac.ts +7 -12
  487. package/src/certificate/kinds/Vvsc.ts +24 -15
  488. package/src/certificate/kinds/definitions/asn.ts +1 -1
  489. package/src/certificate/kinds/definitions/attestation.ts +15 -15
  490. package/src/certificate/kinds/definitions/base.ts +43 -1
  491. package/src/certificate/kinds/definitions/operational.ts +4 -3
  492. package/src/codec/MessageCodec.ts +92 -81
  493. package/src/dcl/DclCertificateService.ts +135 -36
  494. package/src/fabric/Fabric.ts +13 -6
  495. package/src/fabric/FabricManager.ts +2 -2
  496. package/src/groups/FabricGroups.ts +5 -0
  497. package/src/groups/Groups.ts +12 -3
  498. package/src/groups/KeySets.ts +3 -3
  499. package/src/mdns/InterfaceResponder.ts +1031 -0
  500. package/src/mdns/MdnsServer.ts +400 -360
  501. package/src/peer/CommissioningConnection.ts +5 -1
  502. package/src/peer/ControllerCommissioner.ts +57 -19
  503. package/src/peer/ControllerCommissioningFlow.ts +132 -56
  504. package/src/peer/Peer.ts +31 -16
  505. package/src/peer/PeerAddressStore.ts +119 -0
  506. package/src/peer/PeerConnection.ts +0 -1
  507. package/src/peer/PeerDescriptor.ts +3 -4
  508. package/src/peer/PeerExchangeProvider.ts +4 -6
  509. package/src/peer/PeerLossContext.ts +11 -2
  510. package/src/peer/PhysicalDeviceProperties.ts +25 -12
  511. package/src/peer/RebootResubscribeArmer.ts +37 -16
  512. package/src/peer/index.ts +1 -0
  513. package/src/protocol/DeviceAdvertiser.ts +5 -1
  514. package/src/protocol/ExchangeManager.ts +162 -88
  515. package/src/protocol/ExchangeProvider.ts +3 -2
  516. package/src/protocol/MessageExchange.ts +22 -6
  517. package/src/protocol/MessageReceptionState.ts +2 -2
  518. package/src/protocol/errors.ts +7 -1
  519. package/src/securechannel/SecureChannelMessenger.ts +26 -13
  520. package/src/session/GroupSession.ts +147 -111
  521. package/src/session/NodeSession.ts +89 -4
  522. package/src/session/SecureSession.ts +27 -1
  523. package/src/session/Session.ts +2 -2
  524. package/src/session/SessionManager.ts +429 -189
  525. package/src/session/UnsecuredSession.ts +9 -3
  526. package/src/session/case/CaseClient.ts +15 -10
  527. package/src/session/case/CaseServer.ts +41 -17
@@ -0,0 +1,677 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2026 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import {
8
+ Bytes,
9
+ CertificateError,
10
+ ImplementationError,
11
+ InternalError,
12
+ UnexpectedDataError,
13
+ X509,
14
+ X520,
15
+ } from "@matter/general";
16
+ import {
17
+ CaseAuthenticatedTag,
18
+ FabricId,
19
+ NodeId,
20
+ ObjectSchema,
21
+ TlvAny,
22
+ TlvEncodingOptions,
23
+ TlvFields,
24
+ TlvReader,
25
+ TlvSchema,
26
+ TlvTag,
27
+ TlvTaggedListPreservingOrder,
28
+ TlvType,
29
+ TlvTypeLength,
30
+ TlvWriter,
31
+ TypeFromFields,
32
+ ValidationDatatypeMismatchError,
33
+ VendorId,
34
+ } from "@matter/types";
35
+ import {
36
+ FabricId_Matter,
37
+ FirmwareSigningId_Matter,
38
+ IcacId_Matter,
39
+ NocCat_Matter,
40
+ NodeId_Matter,
41
+ ProductId_Matter,
42
+ RcacId_Matter,
43
+ VendorId_Matter,
44
+ VvsId_Matter,
45
+ } from "./definitions/asn.js";
46
+
47
+ /**
48
+ * Thrown when a DER certificate, such as a DAC, PAI, PAA or VVSC, is well-formed but violates its X.509 profile,
49
+ * including a VendorID or ProductID in the distinguished name that is malformed or repeated.
50
+ *
51
+ * @see {@link MatterSpecification.v161.Core} § 6.2.2.2
52
+ * @see {@link MatterSpecification.v161.Core} § 6.2.2.3
53
+ * @see {@link MatterSpecification.v161.Core} § 6.2.2.4
54
+ */
55
+ export class CertificateProfileError extends CertificateError {}
56
+
57
+ /**
58
+ * Extract a VendorID or ProductID encoded via the "fallback method" (Matter spec 6.2.2.2): the
59
+ * prefix `Mvid:`/`Mpid:` followed by 4 uppercase hexadecimal characters, anywhere within a
60
+ * `commonName`. Returns the leftmost correctly-encoded value, or `undefined` if the prefix is
61
+ * absent. Throws if the prefix appears but no correctly-encoded value exists (spec 6.2.2.2.1).
62
+ */
63
+ export function parseMatterFallbackVidPid(commonName: string, prefix: "Mvid:" | "Mpid:"): number | undefined {
64
+ const match = commonName.match(new RegExp(`${prefix}([0-9A-F]{4})`));
65
+ if (match !== null) {
66
+ return parseInt(match[1], 16);
67
+ }
68
+ if (commonName.includes(prefix)) {
69
+ throw new CertificateError(`commonName contains ${prefix} not followed by 4 uppercase hex digits`);
70
+ }
71
+ return undefined;
72
+ }
73
+
74
+ /**
75
+ * A certificate subject or issuer as the ordered list of its relative distinguished names (RDNs).
76
+ *
77
+ * A decoded certificate offers two views of each DN:
78
+ *
79
+ * | View | Holds | Used for |
80
+ * |-----------------------------------------|---------------------------------------------------------|--------------|
81
+ * | object (`cert.subject`, `cert.issuer`) | one property per attribute, the first value of a | reading |
82
+ * | | repeated standard attribute, all CATs in an array | |
83
+ * | RDN list (`rdnsOf(cert.subject)`) | every RDN in encoded order, repeats included | re-encoding |
84
+ *
85
+ * Standard attributes such as commonName or organizationalUnitName may repeat, as the `Name` structure of X.509 allows.
86
+ * Only the RDN list keeps all of them, and only the RDN list keeps each CAT at its position between other attributes,
87
+ * so a re-encoded certificate matches the bytes its issuer signed, in TLV and in DER.
88
+ *
89
+ * A DER DN can re-encode differently. The list is not complete. Known cases are:
90
+ *
91
+ * - an attribute of a type the decoder does not know, which the decoder leaves out of the RDN list
92
+ * - a VendorID or ProductID that was malformed and accepted as a profile violation, which is left out too
93
+ * - an RDN of more than one attribute (a Matter certificate "SHALL be always a single DN attribute", § 6.5.6.1), which
94
+ * the decoder splits into one RDN per attribute
95
+ * - a string type other than the one the encoder writes, such as a PrintableString VendorID or a domainComponent that
96
+ * is not an IA5String
97
+ *
98
+ * Signature verification of a DER certificate uses its original bytes, so only conversion to TLV is affected.
99
+ *
100
+ * A DN built in code has no RDN list and encodes from its properties in property order. Each property must be a DN
101
+ * attribute of the object view, otherwise encoding throws {@link ImplementationError}.
102
+ *
103
+ * The decoders keep the RDN list outside the DN object, keyed by the object. Only the decoders add a list, and a
104
+ * decoded DN is frozen, so changing one of its properties throws a `TypeError` instead of encoding a list that no
105
+ * longer matches the properties. To change a decoded DN, build a new object, for example `{ ...cert.subject, nodeId }`.
106
+ * Such a copy is a new object without an RDN list and encodes from its properties. A certificate built around such a
107
+ * copy must leave out `tbsDer`, `subjectDer` and `issuerDer` of a parsed certificate, because these hold the original
108
+ * bytes.
109
+ *
110
+ * @see {@link MatterSpecification.v161.Core} § 6.5.6
111
+ */
112
+ export namespace DistinguishedName {
113
+ /** Attributes with a string value, named as in the object view. The `Ps` variants are PrintableString. */
114
+ export type StringAttribute =
115
+ | "commonName"
116
+ | "surName"
117
+ | "serialNum"
118
+ | "countryName"
119
+ | "localityName"
120
+ | "stateOrProvinceName"
121
+ | "orgName"
122
+ | "orgUnitName"
123
+ | "title"
124
+ | "name"
125
+ | "givenName"
126
+ | "initials"
127
+ | "genQualifier"
128
+ | "dnQualifier"
129
+ | "pseudonym"
130
+ | "domainComponent"
131
+ | "commonNamePs"
132
+ | "surNamePs"
133
+ | "serialNumPs"
134
+ | "countryNamePs"
135
+ | "localityNamePs"
136
+ | "stateOrProvinceNamePs"
137
+ | "orgNamePs"
138
+ | "orgUnitNamePs"
139
+ | "titlePs"
140
+ | "namePs"
141
+ | "givenNamePs"
142
+ | "initialsPs"
143
+ | "genQualifierPs"
144
+ | "dnQualifierPs"
145
+ | "pseudonymPs";
146
+
147
+ /** Matter-specific attributes with a 64-bit identifier value. */
148
+ export type IdentifierAttribute = "firmwareSigningId" | "icacId" | "rcacId" | "vvsId";
149
+
150
+ /**
151
+ * One RDN. `type` is the name of the attribute in the object view, except that each matter-noc-cat is its own
152
+ * `caseAuthenticatedTag` entry. `vendorId` and `productId` have no Matter-TLV encoding.
153
+ */
154
+ export type Rdn =
155
+ | { readonly type: StringAttribute; readonly value: string }
156
+ | { readonly type: "nodeId"; readonly value: NodeId }
157
+ | { readonly type: "fabricId"; readonly value: FabricId }
158
+ | { readonly type: IdentifierAttribute; readonly value: number | bigint }
159
+ | { readonly type: "caseAuthenticatedTag"; readonly value: CaseAuthenticatedTag }
160
+ | { readonly type: "vendorId"; readonly value: VendorId }
161
+ | { readonly type: "productId"; readonly value: number };
162
+
163
+ /** The object view of a DN. A decoded DN is frozen, so its properties are read-only. */
164
+ export type View = { readonly [K in StringAttribute]?: string } & {
165
+ readonly [K in IdentifierAttribute]?: number | bigint;
166
+ } & {
167
+ readonly nodeId?: NodeId;
168
+ readonly fabricId?: FabricId;
169
+ readonly caseAuthenticatedTags?: readonly CaseAuthenticatedTag[];
170
+ readonly vendorId?: VendorId;
171
+ readonly productId?: number;
172
+ };
173
+
174
+ /** The type of a decoded DN whose attributes are the fields of a TLV schema: read-only, arrays included. */
175
+ export type Frozen<T> = {
176
+ readonly [K in keyof T]: T[K] extends (infer U)[] | undefined
177
+ ? undefined extends T[K]
178
+ ? readonly U[] | undefined
179
+ : readonly U[]
180
+ : T[K];
181
+ };
182
+
183
+ /**
184
+ * The RDN list of a DN that a decoder returned, or undefined for a DN built in code, a copy of a decoded DN
185
+ * included. The list and its entries are frozen.
186
+ */
187
+ export function rdnsOf(dn: object): readonly Rdn[] | undefined {
188
+ return decodedRdns.get(dn);
189
+ }
190
+
191
+ /**
192
+ * The RDNs a DN encodes to: its RDN list, or for a DN built in code one RDN per property in property order and one
193
+ * per CAT. The VendorID and ProductID properties are left out when the commonNames already give them by the
194
+ * fallback method (§ 6.2.2.2).
195
+ *
196
+ * @throws ImplementationError if a DN built in code has a defined property that is not a DN attribute
197
+ */
198
+ export function encodedRdnsOf(dn: View): readonly Rdn[] {
199
+ return rdnsOf(dn) ?? rdnsOfProperties(dn);
200
+ }
201
+
202
+ /**
203
+ * The number of RDNs a DN encodes to, see {@link encodedRdnsOf}.
204
+ *
205
+ * @see {@link MatterSpecification.v161.Core} § 6.5.6.3
206
+ */
207
+ export function rdnCount(dn: View) {
208
+ return encodedRdnsOf(dn).length;
209
+ }
210
+ }
211
+
212
+ /** Written only by {@link decodeDistinguishedName}, so a DN object the caller built or copied has no entry. */
213
+ const decodedRdns = new WeakMap<object, readonly DistinguishedName.Rdn[]>();
214
+
215
+ type Mutable<T> = { -readonly [K in keyof T]: T[K] extends readonly (infer U)[] | undefined ? U[] | undefined : T[K] };
216
+
217
+ type VidPidAttribute = "vendorId" | "productId";
218
+
219
+ export interface DnDecodeOptions {
220
+ /** Leave a malformed or repeated VendorID or ProductID undefined instead of throwing {@link CertificateProfileError}. */
221
+ acceptMalformedVidPid?: boolean;
222
+
223
+ /**
224
+ * The raw bytes of every commonName of the DN in encoded order. Setting this reads VendorID and ProductID from
225
+ * them ("fallback method"). The DER decoder sets it when the DN has no matter-oid-vid or matter-oid-pid
226
+ * attribute, counting a malformed one too. The bytes are needed because CHIP cuts the value at 64 bytes before it
227
+ * decodes the text, and invalid UTF-8 changes the length of the decoded text.
228
+ */
229
+ fallbackCommonNames?: readonly Uint8Array[];
230
+
231
+ /**
232
+ * VendorID or ProductID attributes that were malformed, accepted as a profile violation and left out of the RDN
233
+ * list. They read as undefined even if another attribute of the same type is well-formed.
234
+ */
235
+ malformed?: ReadonlySet<VidPidAttribute>;
236
+ }
237
+
238
+ /**
239
+ * Build the frozen object view of a DN from its RDN list and record the list for {@link DistinguishedName.rdnsOf}.
240
+ * The TLV and the DER decoder both use this, so these rules hold for either encoding:
241
+ *
242
+ * - A Matter-specific attribute other than matter-noc-cat occurs at most once (§ 6.5.6.3 for node, fabric, icac, rcac
243
+ * and vvs, which also allows up to three matter-noc-cat; matter.js also limits firmware-signing-id to one, which the
244
+ * specification does not require; § 6.2.2.3 and § 6.2.2.4 for VendorID and ProductID). A repeated VendorID or ProductID throws
245
+ * {@link CertificateProfileError} unless `acceptMalformedVidPid` is set, any other repeat {@link CertificateError}.
246
+ * - A standard attribute may repeat. The object view holds its first value.
247
+ * - With {@link DnDecodeOptions.fallbackCommonNames}, VendorID and ProductID come from the first commonName that
248
+ * carries a VendorID or ProductID; see {@link fallbackVidPid}.
249
+ *
250
+ * @see {@link MatterSpecification.v161.Core} § 6.2.2.2
251
+ */
252
+ export function decodeDistinguishedName(
253
+ rdns: readonly DistinguishedName.Rdn[],
254
+ options: DnDecodeOptions = {},
255
+ ): DistinguishedName.View {
256
+ const { acceptMalformedVidPid = false, fallbackCommonNames } = options;
257
+ const view: Mutable<DistinguishedName.View> = {};
258
+ const unusable = new Set<VidPidAttribute>(options.malformed);
259
+ const matterAttributes = new Set<DistinguishedName.Rdn["type"]>();
260
+
261
+ const repeated = (type: DistinguishedName.Rdn["type"]) => {
262
+ const message = `Distinguished name contains ${type} more than once`;
263
+ if (type !== "vendorId" && type !== "productId") {
264
+ throw new CertificateError(message);
265
+ }
266
+ if (!acceptMalformedVidPid) {
267
+ throw new CertificateProfileError(message);
268
+ }
269
+ unusable.add(type);
270
+ };
271
+
272
+ for (const rdn of rdns) {
273
+ if (rdn.type === "caseAuthenticatedTag") {
274
+ (view.caseAuthenticatedTags ??= []).push(rdn.value);
275
+ continue;
276
+ }
277
+ if (isMatterAttribute(rdn.type)) {
278
+ if (matterAttributes.has(rdn.type)) {
279
+ repeated(rdn.type);
280
+ continue;
281
+ }
282
+ matterAttributes.add(rdn.type);
283
+ }
284
+ switch (rdn.type) {
285
+ case "nodeId":
286
+ view.nodeId = rdn.value;
287
+ break;
288
+ case "fabricId":
289
+ view.fabricId = rdn.value;
290
+ break;
291
+ case "firmwareSigningId":
292
+ case "icacId":
293
+ case "rcacId":
294
+ case "vvsId":
295
+ view[rdn.type] = rdn.value;
296
+ break;
297
+ case "vendorId":
298
+ view.vendorId = rdn.value;
299
+ break;
300
+ case "productId":
301
+ view.productId = rdn.value;
302
+ break;
303
+ default:
304
+ view[rdn.type] ??= rdn.value;
305
+ }
306
+ }
307
+
308
+ if (fallbackCommonNames !== undefined) {
309
+ const { vendorId, productId } = fallbackVidPid(fallbackCommonNames);
310
+ if (vendorId !== undefined) {
311
+ view.vendorId = VendorId(vendorId, false);
312
+ }
313
+ if (productId !== undefined) {
314
+ view.productId = productId;
315
+ }
316
+ }
317
+
318
+ for (const type of unusable) {
319
+ delete view[type];
320
+ }
321
+
322
+ if (view.caseAuthenticatedTags !== undefined) {
323
+ Object.freeze(view.caseAuthenticatedTags);
324
+ }
325
+ const decoded = Object.freeze(view);
326
+ decodedRdns.set(decoded, Object.freeze(rdns.map(rdn => Object.freeze({ ...rdn }))));
327
+ return decoded;
328
+ }
329
+
330
+ function isMatterAttribute(type: DistinguishedName.Rdn["type"]) {
331
+ switch (type) {
332
+ case "nodeId":
333
+ case "fabricId":
334
+ case "firmwareSigningId":
335
+ case "icacId":
336
+ case "rcacId":
337
+ case "vvsId":
338
+ case "vendorId":
339
+ case "productId":
340
+ return true;
341
+ }
342
+ return false;
343
+ }
344
+
345
+ /** Maximum number of bytes of a commonName that CHIP searches for `Mvid:` and `Mpid:` (`kMax_CommonNameAttr_Length`). */
346
+ const MAX_FALLBACK_COMMON_NAME_BYTES = 64;
347
+
348
+ function commonNamesOf(rdns: readonly { type: string; value: unknown }[]) {
349
+ return rdns.flatMap(({ type, value }) =>
350
+ type === "commonName" || type === "commonNamePs" ? [Bytes.of(Bytes.fromString(String(value)))] : [],
351
+ );
352
+ }
353
+
354
+ /**
355
+ * VendorID and ProductID from the first commonName that carries a VendorID or ProductID ("fallback method",
356
+ * § 6.2.2.2). Later commonNames are not read, and the first 64 bytes of a commonName are searched.
357
+ *
358
+ * The specification does not say how to read more than one commonName. This follows the CHIP SDK,
359
+ * `ExtractVIDPIDFromAttributeString` in `src/crypto/CHIPCryptoPAL.cpp`, which stops at the first commonName with a
360
+ * value, so a VendorID and a ProductID in different commonNames do not combine.
361
+ *
362
+ * @throws CertificateError if a commonName read has a prefix without a correctly encoded value
363
+ */
364
+ function fallbackVidPid(commonNames: readonly Uint8Array[]): { vendorId?: number; productId?: number } {
365
+ for (const commonName of commonNames) {
366
+ const searched = Bytes.toString(commonName.subarray(0, MAX_FALLBACK_COMMON_NAME_BYTES));
367
+ const vendorId = parseMatterFallbackVidPid(searched, "Mvid:");
368
+ const productId = parseMatterFallbackVidPid(searched, "Mpid:");
369
+ if (vendorId !== undefined || productId !== undefined) {
370
+ return { vendorId, productId };
371
+ }
372
+ }
373
+ return {};
374
+ }
375
+
376
+ /**
377
+ * The RDN for an attribute named as in the object view, or undefined for a name that is not a DN attribute. The value
378
+ * is not checked: it comes from a TLV schema, from the DER decoder or from a DN the caller built.
379
+ */
380
+ export function rdnOf(type: string, value: any): DistinguishedName.Rdn | undefined {
381
+ switch (type) {
382
+ case "commonName":
383
+ case "surName":
384
+ case "serialNum":
385
+ case "countryName":
386
+ case "localityName":
387
+ case "stateOrProvinceName":
388
+ case "orgName":
389
+ case "orgUnitName":
390
+ case "title":
391
+ case "name":
392
+ case "givenName":
393
+ case "initials":
394
+ case "genQualifier":
395
+ case "dnQualifier":
396
+ case "pseudonym":
397
+ case "domainComponent":
398
+ case "commonNamePs":
399
+ case "surNamePs":
400
+ case "serialNumPs":
401
+ case "countryNamePs":
402
+ case "localityNamePs":
403
+ case "stateOrProvinceNamePs":
404
+ case "orgNamePs":
405
+ case "orgUnitNamePs":
406
+ case "titlePs":
407
+ case "namePs":
408
+ case "givenNamePs":
409
+ case "initialsPs":
410
+ case "genQualifierPs":
411
+ case "dnQualifierPs":
412
+ case "pseudonymPs":
413
+ return { type, value };
414
+ case "firmwareSigningId":
415
+ case "icacId":
416
+ case "rcacId":
417
+ case "vvsId":
418
+ return { type, value };
419
+ case "nodeId":
420
+ return { type, value };
421
+ case "fabricId":
422
+ return { type, value };
423
+ case "caseAuthenticatedTag":
424
+ return { type, value };
425
+ case "vendorId":
426
+ return { type, value };
427
+ case "productId":
428
+ return { type, value };
429
+ }
430
+ return undefined;
431
+ }
432
+
433
+ /**
434
+ * Whether the commonNames of a DN already give exactly its `vendorId` and `productId` properties by the "fallback
435
+ * method" (§ 6.2.2.2), so that no VendorID or ProductID attribute is needed.
436
+ *
437
+ * A decoder skips the fallback for the whole DN when either attribute is present. So the attributes are left out
438
+ * only when the fallback gives both properties, including an absent one. If one property differs, both are written
439
+ * as attributes, because a lone attribute would hide the other value that the commonName carries. A commonName
440
+ * with a malformed prefix counts as not carrying a value, because the decoder does not read it next to an attribute.
441
+ */
442
+ function commonNameCarriesVidPid(dn: DistinguishedName.View) {
443
+ if (dn.vendorId === undefined && dn.productId === undefined) {
444
+ return false;
445
+ }
446
+ try {
447
+ const { vendorId, productId } = fallbackVidPid(
448
+ commonNamesOf(Object.entries(dn).map(([type, value]) => ({ type, value }))),
449
+ );
450
+ return vendorId === dn.vendorId && productId === dn.productId;
451
+ } catch (error) {
452
+ if (error instanceof CertificateError) {
453
+ return false;
454
+ }
455
+ throw error;
456
+ }
457
+ }
458
+
459
+ /** See {@link DistinguishedName.encodedRdnsOf}. */
460
+ function rdnsOfProperties(dn: DistinguishedName.View) {
461
+ const omitVidPid = commonNameCarriesVidPid(dn);
462
+
463
+ const rdns = new Array<DistinguishedName.Rdn>();
464
+ for (const [name, value] of Object.entries(dn)) {
465
+ if (value === undefined || (omitVidPid && (name === "vendorId" || name === "productId"))) {
466
+ continue;
467
+ }
468
+ const { caseAuthenticatedTags } = dn;
469
+ if (name === "caseAuthenticatedTags" && caseAuthenticatedTags !== undefined) {
470
+ for (const tag of caseAuthenticatedTags) {
471
+ rdns.push({ type: "caseAuthenticatedTag", value: tag });
472
+ }
473
+ continue;
474
+ }
475
+ // A single CAT is an RDN type, not a property of the object view
476
+ const rdn = name === "caseAuthenticatedTag" ? undefined : rdnOf(name, value);
477
+ if (rdn === undefined) {
478
+ throw new ImplementationError(`Distinguished name property "${name}" is not a DN attribute`);
479
+ }
480
+ rdns.push(rdn);
481
+ }
482
+ return rdns;
483
+ }
484
+
485
+ /**
486
+ * Convert a subject or issuer to the DER AST of an X.509 Name, one SET per RDN. A decoded DN encodes from its RDN
487
+ * list, a DN built in code from its properties.
488
+ */
489
+ export function distinguishedNameToAsn1(dn: DistinguishedName.View): X509.DistinguishedName {
490
+ if (dn.caseAuthenticatedTags !== undefined) {
491
+ CaseAuthenticatedTag.validateNocTagList(dn.caseAuthenticatedTags);
492
+ }
493
+ const asn: X509.DistinguishedName = {};
494
+ DistinguishedName.encodedRdnsOf(dn).forEach((rdn, index) => {
495
+ asn[`rdn${index}`] = rdnToAsn1(rdn);
496
+ });
497
+ return asn;
498
+ }
499
+
500
+ function rdnToAsn1(rdn: DistinguishedName.Rdn) {
501
+ switch (rdn.type) {
502
+ case "commonName":
503
+ return X520.CommonName(rdn.value);
504
+ case "surName":
505
+ return X520.SurName(rdn.value);
506
+ case "serialNum":
507
+ return X520.SerialNumber(rdn.value);
508
+ case "countryName":
509
+ return X520.CountryName(rdn.value);
510
+ case "localityName":
511
+ return X520.LocalityName(rdn.value);
512
+ case "stateOrProvinceName":
513
+ return X520.StateOrProvinceName(rdn.value);
514
+ case "orgName":
515
+ return X520.OrganisationName(rdn.value);
516
+ case "orgUnitName":
517
+ return X520.OrganizationalUnitName(rdn.value);
518
+ case "title":
519
+ return X520.Title(rdn.value);
520
+ case "name":
521
+ return X520.Name(rdn.value);
522
+ case "givenName":
523
+ return X520.GivenName(rdn.value);
524
+ case "initials":
525
+ return X520.Initials(rdn.value);
526
+ case "genQualifier":
527
+ return X520.GenerationQualifier(rdn.value);
528
+ case "dnQualifier":
529
+ return X520.DnQualifier(rdn.value);
530
+ case "pseudonym":
531
+ return X520.Pseudonym(rdn.value);
532
+ case "domainComponent":
533
+ return X520.DomainComponent(rdn.value);
534
+ case "commonNamePs":
535
+ return X520.CommonName(rdn.value, true);
536
+ case "surNamePs":
537
+ return X520.SurName(rdn.value, true);
538
+ case "serialNumPs":
539
+ return X520.SerialNumber(rdn.value, true);
540
+ case "countryNamePs":
541
+ return X520.CountryName(rdn.value, true);
542
+ case "localityNamePs":
543
+ return X520.LocalityName(rdn.value, true);
544
+ case "stateOrProvinceNamePs":
545
+ return X520.StateOrProvinceName(rdn.value, true);
546
+ case "orgNamePs":
547
+ return X520.OrganisationName(rdn.value, true);
548
+ case "orgUnitNamePs":
549
+ return X520.OrganizationalUnitName(rdn.value, true);
550
+ case "titlePs":
551
+ return X520.Title(rdn.value, true);
552
+ case "namePs":
553
+ return X520.Name(rdn.value, true);
554
+ case "givenNamePs":
555
+ return X520.GivenName(rdn.value, true);
556
+ case "initialsPs":
557
+ return X520.Initials(rdn.value, true);
558
+ case "genQualifierPs":
559
+ return X520.GenerationQualifier(rdn.value, true);
560
+ case "dnQualifierPs":
561
+ return X520.DnQualifier(rdn.value, true);
562
+ case "pseudonymPs":
563
+ return X520.Pseudonym(rdn.value, true);
564
+ case "nodeId":
565
+ return NodeId_Matter(rdn.value);
566
+ case "fabricId":
567
+ return FabricId_Matter(rdn.value);
568
+ case "firmwareSigningId":
569
+ return FirmwareSigningId_Matter(rdn.value);
570
+ case "icacId":
571
+ return IcacId_Matter(rdn.value);
572
+ case "rcacId":
573
+ return RcacId_Matter(rdn.value);
574
+ case "vvsId":
575
+ return VvsId_Matter(rdn.value);
576
+ case "caseAuthenticatedTag":
577
+ return NocCat_Matter(rdn.value);
578
+ case "vendorId":
579
+ return VendorId_Matter(rdn.value);
580
+ case "productId":
581
+ return ProductId_Matter(rdn.value);
582
+ }
583
+ }
584
+
585
+ /**
586
+ * TLV schema of a certificate subject or issuer, a TLV list of DN attributes (§ 6.5.6).
587
+ *
588
+ * The decoded value is the frozen object view. {@link DistinguishedName.rdnsOf} returns its RDN list. Encoding writes
589
+ * the RDNs of {@link DistinguishedName.encodedRdnsOf}. Each RDN value is validated with its field schema, so a repeated
590
+ * value that the TLV decoder would read back differently is refused. Validation checks the object view against
591
+ * `fields`, so mandatory attributes and the maximum number of CATs are enforced as for a tagged list.
592
+ */
593
+ export class DistinguishedNameSchema<F extends TlvFields> extends TlvSchema<
594
+ DistinguishedName.Frozen<TypeFromFields<F>>
595
+ > {
596
+ readonly #fields: F;
597
+ readonly #properties: ObjectSchema<TlvFields>;
598
+ readonly #nameById = new Map<number, string>();
599
+
600
+ constructor(fields: F) {
601
+ super();
602
+ this.#fields = fields;
603
+ this.#properties = TlvTaggedListPreservingOrder(fields);
604
+ for (const name in fields) {
605
+ this.#nameById.set(fields[name].id, name);
606
+ }
607
+ }
608
+
609
+ override validate(value: DistinguishedName.Frozen<TypeFromFields<F>>) {
610
+ this.#properties.validate(value);
611
+ }
612
+
613
+ override encodeTlvInternal(
614
+ writer: TlvWriter,
615
+ value: DistinguishedName.Frozen<TypeFromFields<F>>,
616
+ tag?: TlvTag,
617
+ options?: TlvEncodingOptions,
618
+ ) {
619
+ writer.writeTag({ type: TlvType.List }, tag);
620
+ for (const { type, value: rdnValue } of DistinguishedName.encodedRdnsOf(value)) {
621
+ const name = type === "caseAuthenticatedTag" ? "caseAuthenticatedTags" : type;
622
+ if (!Object.hasOwn(this.#fields, name)) {
623
+ throw new ValidationDatatypeMismatchError(`Field "${name}" is not defined in the TLV DN schema.`, name);
624
+ }
625
+ const { id, schema } = this.#fields[name];
626
+ schema.validate(rdnValue);
627
+ schema.encodeTlvInternal(writer, rdnValue, { id }, options);
628
+ }
629
+ writer.writeTag({ type: TlvType.EndOfContainer });
630
+ }
631
+
632
+ override decodeTlvInternalValue(
633
+ reader: TlvReader,
634
+ typeLength: TlvTypeLength,
635
+ ): DistinguishedName.Frozen<TypeFromFields<F>> {
636
+ if (typeLength.type !== TlvType.List) {
637
+ throw new UnexpectedDataError(`Unexpected type ${typeLength.type} (expected ${TlvType.List}).`);
638
+ }
639
+ const rdns = new Array<DistinguishedName.Rdn>();
640
+ while (true) {
641
+ const { tag: { profile, id } = {}, typeLength: elementTypeLength } = reader.readTagType();
642
+ if (elementTypeLength.type === TlvType.EndOfContainer) {
643
+ break;
644
+ }
645
+ if (profile !== undefined) {
646
+ throw new UnexpectedDataError("Distinguished name element tags should be context-specific.");
647
+ }
648
+ if (id === undefined) {
649
+ throw new UnexpectedDataError("Distinguished name element tags should have an id.");
650
+ }
651
+ const name = this.#nameById.get(id);
652
+ if (name === undefined) {
653
+ TlvAny.decodeTlvInternalValue(reader, elementTypeLength);
654
+ continue;
655
+ }
656
+ const value = this.#fields[name].schema.decodeTlvInternalValue(reader, elementTypeLength);
657
+ const rdn = rdnOf(name === "caseAuthenticatedTags" ? "caseAuthenticatedTag" : name, value);
658
+ if (rdn === undefined) {
659
+ throw new InternalError(`TLV DN field ${name} is not a DN attribute`);
660
+ }
661
+ rdns.push(rdn);
662
+ }
663
+ const view = decodeDistinguishedName(rdns);
664
+ this.#assertFields(view);
665
+ return view;
666
+ }
667
+
668
+ /** Validates during decode too, even with `decode(bytes, false)`, because the view is built without the field types. */
669
+ #assertFields(
670
+ view: DistinguishedName.View,
671
+ ): asserts view is DistinguishedName.View & DistinguishedName.Frozen<TypeFromFields<F>> {
672
+ this.#properties.validate(view);
673
+ }
674
+ }
675
+
676
+ /** TLV schema of a certificate subject or issuer, see {@link DistinguishedNameSchema}. */
677
+ export const TlvDistinguishedName = <F extends TlvFields>(fields: F) => new DistinguishedNameSchema(fields);