@project-chip/matter.js 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/README.md +14 -0
  2. package/dist/cjs/cluster/AccessControlCluster.js +105 -0
  3. package/dist/cjs/cluster/BasicInformationCluster.js +92 -0
  4. package/dist/cjs/cluster/BindingCluster.js +51 -0
  5. package/dist/cjs/cluster/BridgedDeviceBasicInformationCluster.js +75 -0
  6. package/dist/cjs/cluster/Cluster.js +49 -0
  7. package/dist/cjs/cluster/DescriptorCluster.js +53 -0
  8. package/dist/cjs/cluster/GeneralCommissioningCluster.js +89 -0
  9. package/dist/cjs/cluster/GroupsCluster.js +140 -0
  10. package/dist/cjs/cluster/IdentifyCluster.js +55 -0
  11. package/dist/cjs/cluster/LabelCluster.js +55 -0
  12. package/dist/cjs/cluster/OnOffCluster.js +105 -0
  13. package/dist/cjs/cluster/OperationalCredentialsCluster.js +205 -0
  14. package/dist/cjs/cluster/ScenesCluster.js +236 -0
  15. package/dist/cjs/common/AttributeId.js +23 -0
  16. package/dist/cjs/common/ClusterId.js +24 -0
  17. package/dist/cjs/common/DeviceTypeId.js +23 -0
  18. package/dist/cjs/common/EndpointNumber.js +23 -0
  19. package/dist/cjs/common/FabricId.js +24 -0
  20. package/dist/cjs/common/FabricIndex.js +28 -0
  21. package/dist/cjs/common/GroupId.js +30 -0
  22. package/dist/cjs/common/NodeId.js +31 -0
  23. package/dist/cjs/common/SubjectId.js +11 -0
  24. package/dist/cjs/common/VendorId.js +25 -0
  25. package/{dist-cjs → dist/cjs}/matter.js +12 -0
  26. package/dist/cjs/protocol/InteractionProtocol.js +136 -0
  27. package/dist/cjs/schema/BitmapSchema.js +133 -0
  28. package/{dist-cjs → dist/cjs}/schema/Schema.js +0 -0
  29. package/{dist-cjs → dist/cjs}/spec/Specifications.js +0 -0
  30. package/{dist-cjs → dist/cjs}/tlv/TlvAny.js +0 -0
  31. package/{dist-cjs → dist/cjs}/tlv/TlvArray.js +0 -0
  32. package/{dist-cjs → dist/cjs}/tlv/TlvBoolean.js +0 -0
  33. package/{dist-cjs → dist/cjs}/tlv/TlvCodec.js +0 -0
  34. package/{dist-cjs → dist/cjs}/tlv/TlvNullable.js +0 -0
  35. package/{dist-cjs → dist/cjs}/tlv/TlvNumber.js +0 -0
  36. package/{dist-cjs → dist/cjs}/tlv/TlvObject.js +6 -2
  37. package/{dist-cjs → dist/cjs}/tlv/TlvSchema.js +0 -0
  38. package/{dist-cjs → dist/cjs}/tlv/TlvString.js +0 -0
  39. package/{dist-cjs → dist/cjs}/tlv/TlvVoid.js +0 -0
  40. package/{dist-cjs → dist/cjs}/tlv/TlvWrapper.js +0 -0
  41. package/{dist-cjs → dist/cjs}/util/ByteArray.js +2 -0
  42. package/{dist-cjs → dist/cjs}/util/DataReader.js +0 -0
  43. package/{dist-cjs → dist/cjs}/util/DataWriter.js +0 -0
  44. package/{dist-cjs → dist/cjs}/util/Number.js +0 -0
  45. package/{dist-cjs → dist/cjs}/util/Type.js +3 -0
  46. package/dist/dts/cluster/AccessControlCluster.d.ts +108 -0
  47. package/dist/dts/cluster/BasicInformationCluster.d.ts +57 -0
  48. package/dist/dts/cluster/BindingCluster.d.ts +23 -0
  49. package/dist/dts/cluster/BridgedDeviceBasicInformationCluster.d.ts +53 -0
  50. package/dist/dts/cluster/Cluster.d.ts +109 -0
  51. package/dist/dts/cluster/DescriptorCluster.d.ts +25 -0
  52. package/dist/dts/cluster/GeneralCommissioningCluster.d.ts +94 -0
  53. package/dist/dts/cluster/GroupsCluster.d.ts +92 -0
  54. package/dist/dts/cluster/IdentifyCluster.d.ts +60 -0
  55. package/dist/dts/cluster/LabelCluster.d.ts +34 -0
  56. package/dist/dts/cluster/OnOffCluster.d.ts +85 -0
  57. package/dist/dts/cluster/OperationalCredentialsCluster.d.ts +156 -0
  58. package/dist/dts/cluster/ScenesCluster.d.ts +200 -0
  59. package/dist/dts/common/AttributeId.d.ts +17 -0
  60. package/dist/dts/common/ClusterId.d.ts +18 -0
  61. package/dist/dts/common/DeviceTypeId.d.ts +17 -0
  62. package/dist/dts/common/EndpointNumber.d.ts +17 -0
  63. package/dist/dts/common/FabricId.d.ts +18 -0
  64. package/dist/dts/common/FabricIndex.d.ts +22 -0
  65. package/dist/dts/common/GroupId.d.ts +24 -0
  66. package/dist/dts/common/NodeId.d.ts +19 -0
  67. package/dist/dts/common/SubjectId.d.ts +15 -0
  68. package/dist/dts/common/VendorId.d.ts +19 -0
  69. package/dist/{matter.d.ts → dts/matter.d.ts} +12 -0
  70. package/dist/dts/protocol/InteractionProtocol.d.ts +159 -0
  71. package/dist/{schema → dts/schema}/BitmapSchema.d.ts +15 -3
  72. package/dist/{schema → dts/schema}/Schema.d.ts +0 -0
  73. package/dist/{spec → dts/spec}/Specifications.d.ts +0 -0
  74. package/dist/{tlv → dts/tlv}/TlvAny.d.ts +0 -0
  75. package/dist/{tlv → dts/tlv}/TlvArray.d.ts +0 -0
  76. package/dist/{tlv → dts/tlv}/TlvBoolean.d.ts +0 -0
  77. package/dist/{tlv → dts/tlv}/TlvCodec.d.ts +0 -0
  78. package/dist/{tlv → dts/tlv}/TlvNullable.d.ts +0 -0
  79. package/dist/{tlv → dts/tlv}/TlvNumber.d.ts +0 -0
  80. package/dist/{tlv → dts/tlv}/TlvObject.d.ts +0 -0
  81. package/dist/{tlv → dts/tlv}/TlvSchema.d.ts +0 -0
  82. package/dist/{tlv → dts/tlv}/TlvString.d.ts +0 -0
  83. package/dist/{tlv → dts/tlv}/TlvVoid.d.ts +0 -0
  84. package/dist/{tlv → dts/tlv}/TlvWrapper.d.ts +0 -0
  85. package/dist/{util → dts/util}/ByteArray.d.ts +0 -0
  86. package/dist/{util → dts/util}/DataReader.d.ts +0 -0
  87. package/dist/{util → dts/util}/DataWriter.d.ts +0 -0
  88. package/dist/{util → dts/util}/Number.d.ts +0 -0
  89. package/dist/{util → dts/util}/Type.d.ts +1 -0
  90. package/dist/es/cluster/AccessControlCluster.js +102 -0
  91. package/dist/es/cluster/BasicInformationCluster.js +89 -0
  92. package/dist/es/cluster/BindingCluster.js +48 -0
  93. package/dist/es/cluster/BridgedDeviceBasicInformationCluster.js +72 -0
  94. package/dist/es/cluster/Cluster.js +36 -0
  95. package/dist/es/cluster/DescriptorCluster.js +50 -0
  96. package/dist/es/cluster/GeneralCommissioningCluster.js +86 -0
  97. package/dist/es/cluster/GroupsCluster.js +137 -0
  98. package/dist/es/cluster/IdentifyCluster.js +52 -0
  99. package/dist/es/cluster/LabelCluster.js +52 -0
  100. package/dist/es/cluster/OnOffCluster.js +102 -0
  101. package/dist/es/cluster/OperationalCredentialsCluster.js +202 -0
  102. package/dist/es/cluster/ScenesCluster.js +233 -0
  103. package/dist/es/common/AttributeId.js +19 -0
  104. package/dist/es/common/ClusterId.js +20 -0
  105. package/dist/es/common/DeviceTypeId.js +19 -0
  106. package/dist/es/common/EndpointNumber.js +19 -0
  107. package/dist/es/common/FabricId.js +20 -0
  108. package/dist/es/common/FabricIndex.js +24 -0
  109. package/dist/es/common/GroupId.js +26 -0
  110. package/dist/es/common/NodeId.js +27 -0
  111. package/dist/es/common/SubjectId.js +8 -0
  112. package/dist/es/common/VendorId.js +21 -0
  113. package/dist/{matter.js → es/matter.js} +12 -0
  114. package/dist/es/protocol/InteractionProtocol.js +133 -0
  115. package/dist/es/schema/BitmapSchema.js +125 -0
  116. package/dist/{schema → es/schema}/Schema.js +0 -0
  117. package/dist/{spec → es/spec}/Specifications.js +0 -0
  118. package/dist/{tlv → es/tlv}/TlvAny.js +0 -0
  119. package/dist/{tlv → es/tlv}/TlvArray.js +0 -0
  120. package/dist/{tlv → es/tlv}/TlvBoolean.js +0 -0
  121. package/dist/{tlv → es/tlv}/TlvCodec.js +0 -0
  122. package/dist/{tlv → es/tlv}/TlvNullable.js +0 -0
  123. package/dist/{tlv → es/tlv}/TlvNumber.js +0 -0
  124. package/dist/{tlv → es/tlv}/TlvObject.js +6 -2
  125. package/dist/{tlv → es/tlv}/TlvSchema.js +0 -0
  126. package/dist/{tlv → es/tlv}/TlvString.js +0 -0
  127. package/dist/{tlv → es/tlv}/TlvVoid.js +0 -0
  128. package/dist/{tlv → es/tlv}/TlvWrapper.js +0 -0
  129. package/dist/{util → es/util}/ByteArray.js +2 -0
  130. package/dist/{util → es/util}/DataReader.js +0 -0
  131. package/dist/{util → es/util}/DataWriter.js +0 -0
  132. package/dist/{util → es/util}/Number.js +0 -0
  133. package/dist/{util → es/util}/Type.js +1 -1
  134. package/package.json +7 -8
  135. package/dist/schema/BitmapSchema.js +0 -48
  136. package/dist-cjs/schema/BitmapSchema.js +0 -55
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Project CHIP Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { TlvUInt32 } from "../tlv/TlvNumber.js";
7
+ import { TlvWrapper } from "../tlv/TlvWrapper.js";
8
+ /**
9
+ * A Cluster Identifier is a 32 bit number and SHALL reference a single cluster specification and
10
+ * SHALL define conformance to that specification.
11
+ *
12
+ * @see {@link MatterCoreSpecificationV1_0} § 7.10
13
+ */
14
+ export class ClusterId {
15
+ constructor(id) {
16
+ this.id = id;
17
+ }
18
+ }
19
+ /** Tlv schema for a cluster Id. */
20
+ export const TlvClusterId = new TlvWrapper(TlvUInt32, clusterId => clusterId.id, value => new ClusterId(value));
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Project CHIP Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { TlvUInt32 } from "../tlv/TlvNumber.js";
7
+ import { TlvWrapper } from "../tlv/TlvWrapper.js";
8
+ /**
9
+ * A Device type ID is a 32-bit number that defines the type of the device.
10
+ *
11
+ * @see {@link MatterCoreSpecificationV1_0} § 7.15
12
+ */
13
+ export class DeviceTypeId {
14
+ constructor(id) {
15
+ this.id = id;
16
+ }
17
+ }
18
+ /** Tlv schema for a Device type ID. */
19
+ export const TlvDeviceTypeId = new TlvWrapper(TlvUInt32, deviceTypeId => deviceTypeId.id, value => new DeviceTypeId(value));
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Project CHIP Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { TlvUInt16 } from "../tlv/TlvNumber.js";
7
+ import { TlvWrapper } from "../tlv/TlvWrapper.js";
8
+ /**
9
+ * A Endpoint Number is a 16-bit number that that indicates an instance of a device type.
10
+ *
11
+ * @see {@link MatterCoreSpecificationV1_0} § 7.18.2.11
12
+ */
13
+ export class EndpointNumber {
14
+ constructor(number) {
15
+ this.number = number;
16
+ }
17
+ }
18
+ /** Tlv schema for an Endpoint number. */
19
+ export const TlvEndpointNumber = new TlvWrapper(TlvUInt16, endpointNumber => endpointNumber.number, value => new EndpointNumber(value));
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Project CHIP Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { TlvUInt64 } from "../tlv/TlvNumber.js";
7
+ import { TlvWrapper } from "../tlv/TlvWrapper.js";
8
+ /**
9
+ * A Fabric ID is a 64-bit number that uniquely identifies the Fabric within the scope of
10
+ * a particular root CA.
11
+ *
12
+ * @see {@link MatterCoreSpecificationV1_0} § 2.5.1
13
+ */
14
+ export class FabricId {
15
+ constructor(id) {
16
+ this.id = id;
17
+ }
18
+ }
19
+ /** Tlv schema for a Node Identifier. */
20
+ export const TlvFabricId = new TlvWrapper(TlvUInt64, fabricId => fabricId.id, value => new FabricId(BigInt(value)));
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Project CHIP Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { TlvUInt8 } from "../tlv/TlvNumber.js";
7
+ import { TlvWrapper } from "../tlv/TlvWrapper.js";
8
+ /**
9
+ * Each fabric supported on a node is referenced by fabric-index that is unique on the node. This
10
+ * fabric-index enables the look-up of the full fabric information from the fabric-index. A fabric-index
11
+ * of 0 (zero) or null SHALL indicate that there is no fabric associated with the context in which the
12
+ * fabric-index is being used. If fabric-index is used in a context that is exclusively associated with
13
+ * a fabric, such as fabric-scoped data model elements, then the fabric-index values SHALL NOT include 0
14
+ * (zero) or null.
15
+ *
16
+ * @see {@link MatterCoreSpecificationV1_0} § 7.5.2
17
+ */
18
+ export class FabricIndex {
19
+ constructor(index) {
20
+ this.index = index;
21
+ }
22
+ }
23
+ /** Tlv Schema for a Fabric Index. */
24
+ export const TlvFabricIndex = new TlvWrapper(TlvUInt8.bound({ min: 1, max: 254 }), farbricIndex => farbricIndex.index, value => new FabricIndex(value));
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Project CHIP Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { TlvUInt16 } from "../tlv/TlvNumber.js";
7
+ import { TlvWrapper } from "../tlv/TlvWrapper.js";
8
+ /**
9
+ * A Group Identifier (Group ID or GID) is a 16-bit number that identifies a set of Nodes across a
10
+ * Fabric at the message layer (see Section 4.15, “Group Key Management”). A Group ID can further
11
+ * be bound to one or more Endpoints within each Node in the group at the interaction layer.
12
+ *
13
+ * The Group ID space is allocated as described in Table 2, “Group ID Allocations”:
14
+ * 0x0000 - Null or unspecified Group ID
15
+ * 0x0001 - 0xFEFF: Application Group ID, assigned by fabric Administrator
16
+ * 0xFF00 - 0xFFFF: Universal Group ID range reserved for static multicast and anycast identifiers
17
+ *
18
+ * @see {@link MatterCoreSpecificationV1_0} § 2.5.4
19
+ */
20
+ export class GroupId {
21
+ constructor(id) {
22
+ this.id = id;
23
+ }
24
+ }
25
+ /** Tlv Schema for a Group Id. */
26
+ export const TlvGroupId = new TlvWrapper(TlvUInt16, groupId => groupId.id, value => new GroupId(value));
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Project CHIP Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { TlvUInt64 } from "../tlv/TlvNumber.js";
7
+ import { TlvWrapper } from "../tlv/TlvWrapper.js";
8
+ import { Endian } from "../util/ByteArray.js";
9
+ import { DataWriter } from "../util/DataWriter.js";
10
+ /**
11
+ * A Node Identifier (Node ID) is a 64-bit number that uniquely identifies an individual Node or a
12
+ * group of Nodes on a Fabric.
13
+ *
14
+ * @see {@link MatterCoreSpecificationV1_0} § 2.5.5
15
+ */
16
+ export class NodeId {
17
+ constructor(id) {
18
+ this.id = id;
19
+ }
20
+ toString() {
21
+ const writer = new DataWriter(Endian.Big);
22
+ writer.writeUInt64(this.id);
23
+ return writer.toByteArray().toHex().toUpperCase();
24
+ }
25
+ }
26
+ /** Tlv schema for a Node Identifier. */
27
+ export const TlvNodeId = new TlvWrapper(TlvUInt64, nodeId => nodeId.id, value => new NodeId(BigInt(value)));
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Project CHIP Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { TlvNodeId } from "./NodeId.js";
7
+ /** Tlv schema for a Subject Id */
8
+ export const TlvSubjectId = TlvNodeId;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Project CHIP Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { TlvUInt16 } from "../tlv/TlvNumber.js";
7
+ import { TlvWrapper } from "../tlv/TlvWrapper.js";
8
+ /**
9
+ * A Vendor Identifier (Vendor ID or VID) is a 16-bit number that uniquely identifies a particular
10
+ * product manufacturer, vendor, or group thereof. Each Vendor ID is statically allocated by the
11
+ * Connectivity Standards Alliance (see [CSA Manufacturer Code Database]).
12
+ *
13
+ * @see {@link MatterCoreSpecificationV1_0} § 2.5.2
14
+ */
15
+ export class VendorId {
16
+ constructor(id) {
17
+ this.id = id;
18
+ }
19
+ }
20
+ /** Data model for a Vendor Identifier. */
21
+ export const TlvVendorId = new TlvWrapper(TlvUInt16, vendorId => vendorId.id, value => new VendorId(value));
@@ -20,3 +20,15 @@ export * from "./tlv/TlvString.js";
20
20
  export * from "./tlv/TlvNumber.js";
21
21
  export * from "./tlv/TlvVoid.js";
22
22
  export * from "./tlv/TlvWrapper.js";
23
+ export * from "./cluster/AccessControlCluster.js";
24
+ export * from "./cluster/BasicInformationCluster.js";
25
+ export * from "./cluster/BindingCluster.js";
26
+ export * from "./cluster/BridgedDeviceBasicInformationCluster.js";
27
+ export * from "./cluster/DescriptorCluster.js";
28
+ export * from "./cluster/GeneralCommissioningCluster.js";
29
+ export * from "./cluster/GroupsCluster.js";
30
+ export * from "./cluster/IdentifyCluster.js";
31
+ export * from "./cluster/LabelCluster.js";
32
+ export * from "./cluster/OnOffCluster.js";
33
+ export * from "./cluster/OperationalCredentialsCluster.js";
34
+ export * from "./cluster/ScenesCluster.js";
@@ -0,0 +1,133 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Project CHIP Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { TlvNodeId } from "../common/NodeId.js";
7
+ import { TlvAny } from "../tlv/TlvAny.js";
8
+ import { TlvArray } from "../tlv/TlvArray.js";
9
+ import { TlvBoolean } from "../tlv/TlvBoolean.js";
10
+ import { TlvEnum, TlvUInt16, TlvUInt32, TlvUInt64, TlvUInt8 } from "../tlv/TlvNumber.js";
11
+ import { TlvField, TlvList, TlvObject, TlvOptionalField } from "../tlv/TlvObject.js";
12
+ /**
13
+ * @see {@link MatterCoreSpecificationV1_0}, section 10.6.1. StatusResponseMessage
14
+ */
15
+ export const TlvStatusResponse = TlvObject({
16
+ status: TlvField(0, TlvEnum()),
17
+ interactionModelRevision: TlvField(0xFF, TlvUInt8),
18
+ });
19
+ /**
20
+ * @see {@link MatterCoreSpecificationV1_0}, section 10.5.2. AttributePathIB
21
+ */
22
+ const TlvAttributePath = TlvList({
23
+ endpointId: TlvOptionalField(2, TlvUInt16),
24
+ clusterId: TlvOptionalField(3, TlvUInt32),
25
+ id: TlvOptionalField(4, TlvUInt32),
26
+ });
27
+ /**
28
+ * @see {@link MatterCoreSpecificationV1_0}, section 10.6.2. ReadRequestMessage
29
+ */
30
+ export const TlvReadRequest = TlvObject({
31
+ attributes: TlvField(0, TlvArray(TlvAttributePath)),
32
+ isFabricFiltered: TlvField(3, TlvBoolean),
33
+ interactionModelRevision: TlvField(0xFF, TlvUInt8),
34
+ });
35
+ /**
36
+ * @see {@link MatterCoreSpecificationV1_0}, section 10.6.3. ReportDataMessage
37
+ */
38
+ export const TlvReportData = TlvObject({
39
+ subscriptionId: TlvOptionalField(0, TlvUInt32),
40
+ values: TlvField(1, TlvArray(TlvObject({
41
+ value: TlvField(1, TlvObject({
42
+ version: TlvField(0, TlvUInt32),
43
+ path: TlvField(1, TlvList({
44
+ endpointId: TlvField(2, TlvUInt16),
45
+ clusterId: TlvField(3, TlvUInt32),
46
+ id: TlvField(4, TlvUInt32),
47
+ })),
48
+ value: TlvField(2, TlvAny),
49
+ })),
50
+ }))),
51
+ isFabricFiltered: TlvOptionalField(4, TlvBoolean),
52
+ interactionModelRevision: TlvField(0xFF, TlvUInt8),
53
+ });
54
+ /**
55
+ * @see {@link MatterCoreSpecificationV1_0}, section 10.6.4. SubscribeRequestMessage
56
+ */
57
+ export const TlvSubscribeRequest = TlvObject({
58
+ keepSubscriptions: TlvField(0, TlvBoolean),
59
+ minIntervalFloorSeconds: TlvField(1, TlvUInt16),
60
+ maxIntervalCeilingSeconds: TlvField(2, TlvUInt16),
61
+ attributeRequests: TlvOptionalField(3, TlvArray(TlvAttributePath)),
62
+ eventRequests: TlvOptionalField(4, TlvArray(TlvList({
63
+ node: TlvField(0, TlvNodeId),
64
+ endpoint: TlvField(1, TlvUInt16),
65
+ cluster: TlvField(2, TlvUInt32),
66
+ event: TlvField(3, TlvUInt32),
67
+ isUrgent: TlvField(4, TlvBoolean),
68
+ }))),
69
+ eventFilters: TlvOptionalField(5, TlvArray(TlvList({
70
+ node: TlvField(0, TlvNodeId),
71
+ eventMin: TlvField(1, TlvUInt64),
72
+ }))),
73
+ isFabricFiltered: TlvField(7, TlvBoolean),
74
+ dataVersionFilters: TlvOptionalField(8, TlvArray(TlvObject({
75
+ path: TlvField(0, TlvList({
76
+ node: TlvField(0, TlvNodeId),
77
+ endpoint: TlvField(1, TlvUInt16),
78
+ cluster: TlvField(2, TlvUInt32),
79
+ })),
80
+ dataVersion: TlvField(1, TlvUInt32),
81
+ }))),
82
+ });
83
+ /**
84
+ * @see {@link MatterCoreSpecificationV1_0}, section 10.6.5. SubscribeResponseMessage
85
+ */
86
+ export const TlvSubscribeResponse = TlvObject({
87
+ subscriptionId: TlvField(0, TlvUInt32),
88
+ maxIntervalCeilingSeconds: TlvField(2, TlvUInt16),
89
+ interactionModelRevision: TlvField(0xFF, TlvUInt8),
90
+ });
91
+ /**
92
+ * @see {@link MatterCoreSpecificationV1_0}, section 10.6.9. InvokeRequestMessage
93
+ */
94
+ export const TlvInvokeRequest = TlvObject({
95
+ suppressResponse: TlvField(0, TlvBoolean),
96
+ timedRequest: TlvField(1, TlvBoolean),
97
+ invokes: TlvField(2, TlvArray(TlvObject({
98
+ path: TlvField(0, TlvList({
99
+ endpointId: TlvField(0, TlvUInt16),
100
+ clusterId: TlvField(1, TlvUInt32),
101
+ id: TlvField(2, TlvUInt32),
102
+ })),
103
+ args: TlvField(1, TlvAny),
104
+ }))),
105
+ interactionModelRevision: TlvField(0xFF, TlvUInt8),
106
+ });
107
+ /**
108
+ * @see {@link MatterCoreSpecificationV1_0}, section 10.6.10. InvokeResponseMessage
109
+ */
110
+ export const TlvInvokeResponse = TlvObject({
111
+ suppressResponse: TlvField(0, TlvBoolean),
112
+ responses: TlvField(1, TlvArray(TlvObject({
113
+ response: TlvOptionalField(0, TlvObject({
114
+ path: TlvField(0, TlvList({
115
+ endpointId: TlvField(0, TlvUInt16),
116
+ clusterId: TlvField(1, TlvUInt32),
117
+ id: TlvField(2, TlvUInt32),
118
+ })),
119
+ response: TlvField(1, TlvAny),
120
+ })),
121
+ result: TlvOptionalField(1, TlvObject({
122
+ path: TlvField(0, TlvList({
123
+ endpointId: TlvField(0, TlvUInt16),
124
+ clusterId: TlvField(1, TlvUInt32),
125
+ id: TlvField(2, TlvUInt32),
126
+ })),
127
+ result: TlvField(1, TlvObject({
128
+ code: TlvField(0, TlvUInt16),
129
+ })),
130
+ })),
131
+ }))),
132
+ interactionModelRevision: TlvField(0xFF, TlvUInt8),
133
+ });
@@ -0,0 +1,125 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Project CHIP Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { ByteArray } from "../util/ByteArray";
7
+ import { Schema } from "./Schema";
8
+ const BitRange = (type, offset, length) => ({ type, offset, length });
9
+ export const BitFlag = (offset) => BitRange(0 /* BitRangeType.Flag */, offset, 1);
10
+ export const BitField = (offset, length) => BitRange(1 /* BitRangeType.Number */, offset, length);
11
+ export const BitFieldEnum = (offset, length) => BitRange(2 /* BitRangeType.Enum */, offset, length);
12
+ class BitmapSchemaInternal extends Schema {
13
+ constructor(bitSchemas) {
14
+ super();
15
+ this.bitSchemas = bitSchemas;
16
+ const masks = {};
17
+ for (const name in this.bitSchemas) {
18
+ const { offset, length } = this.bitSchemas[name];
19
+ masks[name] = ((1 << length) - 1) << offset;
20
+ }
21
+ this.masks = masks;
22
+ // TODO: validate that bitSchemas is coherent
23
+ }
24
+ encodeInternal(value) {
25
+ let result = 0;
26
+ for (const name in this.bitSchemas) {
27
+ const { type, offset } = this.bitSchemas[name];
28
+ switch (type) {
29
+ case 0 /* BitRangeType.Flag */:
30
+ if (value[name])
31
+ result |= this.masks[name];
32
+ break;
33
+ case 2 /* BitRangeType.Enum */:
34
+ case 1 /* BitRangeType.Number */:
35
+ result |= value[name] << offset;
36
+ }
37
+ }
38
+ return result;
39
+ }
40
+ decodeInternal(bitmap) {
41
+ const result = {};
42
+ for (const name in this.bitSchemas) {
43
+ const { type, offset } = this.bitSchemas[name];
44
+ const mask = this.masks[name];
45
+ if (type === 0 /* BitRangeType.Flag */) {
46
+ result[name] = (bitmap & mask) !== 0;
47
+ }
48
+ else {
49
+ result[name] = (bitmap & mask) >> offset;
50
+ }
51
+ }
52
+ return result;
53
+ }
54
+ }
55
+ class ByteArrayBitmapSchemaInternal extends Schema {
56
+ constructor(bitSchemas) {
57
+ super();
58
+ this.bitSchemas = bitSchemas;
59
+ let maxBitLength = 0;
60
+ const maskOffset = {};
61
+ for (const name in this.bitSchemas) {
62
+ const { offset, length } = this.bitSchemas[name];
63
+ const bitOffset = offset % 8;
64
+ const byteOffset = (offset - bitOffset) / 8;
65
+ const mask = ((1 << length) - 1) << bitOffset;
66
+ maskOffset[name] = { bitOffset, byteOffset, mask };
67
+ maxBitLength = Math.max(maxBitLength, offset + length);
68
+ }
69
+ this.byteArrayLength = Math.ceil(maxBitLength / 8);
70
+ this.maskOffset = maskOffset;
71
+ }
72
+ encodeInternal(value) {
73
+ let result = new ByteArray(this.byteArrayLength);
74
+ for (const name in this.bitSchemas) {
75
+ const { type } = this.bitSchemas[name];
76
+ let { mask, bitOffset, byteOffset } = this.maskOffset[name];
77
+ switch (type) {
78
+ case 0 /* BitRangeType.Flag */:
79
+ if (value[name])
80
+ result[byteOffset] |= mask;
81
+ break;
82
+ case 2 /* BitRangeType.Enum */:
83
+ case 1 /* BitRangeType.Number */:
84
+ let numValue = value[name];
85
+ while (mask !== 0) {
86
+ result[byteOffset++] |= ((numValue & mask) << bitOffset) & 0xFF;
87
+ const bitWritten = 8 - bitOffset;
88
+ bitOffset = 0;
89
+ numValue = numValue >> bitWritten;
90
+ mask = mask >> 8;
91
+ }
92
+ }
93
+ }
94
+ return result;
95
+ }
96
+ decodeInternal(bitmap) {
97
+ if (bitmap.length !== this.byteArrayLength)
98
+ throw new Error(`Unexpected length: ${bitmap.length}. Expected ${this.byteArrayLength}`);
99
+ const result = {};
100
+ for (const name in this.bitSchemas) {
101
+ const { type } = this.bitSchemas[name];
102
+ let { mask, bitOffset, byteOffset } = this.maskOffset[name];
103
+ if (type === 0 /* BitRangeType.Flag */) {
104
+ result[name] = (bitmap[byteOffset] & mask) !== 0;
105
+ }
106
+ else {
107
+ let value = 0;
108
+ let valueBitOffset = 0;
109
+ while (mask !== 0) {
110
+ value |= ((bitmap[byteOffset++] & mask) >> bitOffset) << valueBitOffset;
111
+ const bitWritten = 8 - bitOffset;
112
+ bitOffset = 0;
113
+ valueBitOffset += bitWritten;
114
+ mask = mask >> 8;
115
+ }
116
+ result[name] = value;
117
+ }
118
+ }
119
+ return result;
120
+ }
121
+ }
122
+ /** Declares a bitmap schema by indicating the bit position and their names. */
123
+ export const BitmapSchema = (bitSchemas) => new BitmapSchemaInternal(bitSchemas);
124
+ /** Declares a bitmap schema backed by a ByteArray by indicating the bit position and their names. */
125
+ export const ByteArrayBitmapSchema = (bitSchemas) => new ByteArrayBitmapSchemaInternal(bitSchemas);
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -4,6 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { TlvSchema } from "./TlvSchema.js";
7
+ import { TlvAny } from "./TlvAny.js";
7
8
  ;
8
9
  /**
9
10
  * Schema to encode an object in TLV.
@@ -48,8 +49,11 @@ export class ObjectSchema extends TlvSchema {
48
49
  if (id === undefined)
49
50
  throw new Error("Structure element tags should have an id.");
50
51
  const fieldName = this.fieldById[id];
51
- if (fieldName === undefined)
52
- throw new Error(`Unknown field ${id}`);
52
+ if (fieldName === undefined) {
53
+ // Ignore unknown field by decoding it as raw TLV so we skip forward the proper length.
54
+ TlvAny.decodeTlvInternalValue(reader, elementTypeLength);
55
+ continue;
56
+ }
53
57
  const { field, name } = fieldName;
54
58
  result[name] = field.schema.decodeTlvInternalValue(reader, elementTypeLength);
55
59
  }
File without changes
File without changes
File without changes
File without changes
@@ -16,6 +16,8 @@ Uint8Array.prototype.equals = function (other) {
16
16
  };
17
17
  Uint8Array.fromHex = function (hexString) {
18
18
  var _a;
19
+ if (hexString.length === 0)
20
+ return new ByteArray(0);
19
21
  if (hexString.length % 2 !== 0)
20
22
  throw new Error("Hex string should have an even length.");
21
23
  const bytes = (_a = hexString.match(/.{1,2}/g)) === null || _a === void 0 ? void 0 : _a.map(byteHex => parseInt(byteHex, 16));
File without changes
File without changes
File without changes
@@ -3,4 +3,4 @@
3
3
  * Copyright 2022 Project CHIP Authors
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- export {};
6
+ export const Merge = (a, b) => (Object.assign(Object.assign({}, a), b));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@project-chip/matter.js",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "description": "Matter protocol in pure js",
5
5
  "keywords": [
6
6
  "iot",
@@ -23,8 +23,8 @@
23
23
  "url": "https://github.com/project-chip/matter.js.git"
24
24
  },
25
25
  "scripts": {
26
- "clean": "rm -rf dist; rm -rf dist-cjs",
27
- "build": "npm run clean; tsc --project tsconfig.dist.json; tsc --project tsconfig.dist-cjs.json",
26
+ "clean": "rm -rf dist; rm -rf out",
27
+ "build": "npm run clean; tsc --project tsconfig.dist-es.json; tsc --project tsconfig.dist-cjs.json; tsc --project tsconfig.dist-dts.json",
28
28
  "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
29
29
  "test-web": "karma start karma.conf.cjs"
30
30
  },
@@ -40,10 +40,9 @@
40
40
  "typescript": "^4.9.3"
41
41
  },
42
42
  "files": [
43
- "dist/**/*",
44
- "dist-cjs/**/*"
43
+ "dist/**/*"
45
44
  ],
46
- "main": "dist-cjs/matter.js",
47
- "module": "dist/matter.js",
48
- "types": "dist/matter.d.ts"
45
+ "main": "dist/cjs/matter.js",
46
+ "module": "dist/es/matter.js",
47
+ "types": "dist/dts/matter.d.ts"
49
48
  }
@@ -1,48 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2022 Project CHIP Authors
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import { Schema } from "./Schema.js";
7
- const BitRange = (type, offset, length) => ({ type, mask: ((1 << length) - 1) << offset, offset });
8
- export const BitFlag = (offset) => BitRange(0 /* BitRangeType.Flag */, offset, 1);
9
- export const BitField = (offset, length) => BitRange(1 /* BitRangeType.Number */, offset, length);
10
- export const BitFieldEnum = (offset, length) => BitRange(2 /* BitRangeType.Enum */, offset, length);
11
- class BitmapSchemaInternal extends Schema {
12
- constructor(bitSchemas) {
13
- super();
14
- this.bitSchemas = bitSchemas;
15
- // TODO: validate that bitSchemas is coherent
16
- }
17
- encodeInternal(value) {
18
- let result = 0;
19
- for (const name in this.bitSchemas) {
20
- const { type, offset, mask } = this.bitSchemas[name];
21
- switch (type) {
22
- case 0 /* BitRangeType.Flag */:
23
- if (value[name])
24
- result |= mask;
25
- break;
26
- case 2 /* BitRangeType.Enum */:
27
- case 1 /* BitRangeType.Number */:
28
- result |= value[name] << offset;
29
- }
30
- }
31
- return result;
32
- }
33
- decodeInternal(bitmap) {
34
- const result = {};
35
- for (const name in this.bitSchemas) {
36
- const { type, offset, mask } = this.bitSchemas[name];
37
- if (type === 0 /* BitRangeType.Flag */) {
38
- result[name] = (bitmap & mask) !== 0;
39
- }
40
- else {
41
- result[name] = (bitmap & mask) >> offset;
42
- }
43
- }
44
- return result;
45
- }
46
- }
47
- /** Declares a bitmap schema by indicating the bit position and their names. */
48
- export const BitmapSchema = (bitSchemas) => new BitmapSchemaInternal(bitSchemas);