Coder Social home page Coder Social logo

project-chip / matter.js Goto Github PK

View Code? Open in Web Editor NEW
273.0 15.0 47.0 18.96 MB

A complete typescript implementation of the Matter protocol specification (https://buildwithmatter.com). Includes full support for controller, device, commissioning, secure communications, device types, and cluster definitions.

License: Apache License 2.0

TypeScript 97.83% JavaScript 2.15% Shell 0.01% HTML 0.01%
iot matter smarthome matterprotocol connectedthings

matter.js's People

Contributors

apollon77 avatar automator77 avatar dependabot[bot] avatar digitaldan avatar donnchadh avatar firesuiry avatar hedda avatar jimbuzbee avatar jvmahon avatar lauckhart avatar lboue avatar luligu avatar mahimamandhanaa avatar mfucci avatar orlenkoo avatar sammachin avatar turon avatar vilicvane avatar vves avatar woody-apple avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

matter.js's Issues

ClientCluster implementation example

Hello, thanks for the library, I assume (hope:) I'll contribute a lot in time.

I already implemented the followings:

  • Thermostat Cluster (tested & working)
  • Fan Control Cluster (tested & working)
  • Thermostat Device (tested & working)
  • HVAC Device (stuck :( due to not knowing the mysterious way of adding a client cluster)

I'll create PR's for all of them, but before I need understand how to implement a client cluster for a device. As you know a heating-cooling device (0x300) depends on "thermostat cluster client", can you please provide an example about creating cluster clients, I'm using bridge device node to test the new device implementations, I assume that I'll need the endpoint id of thermostat device added to the aggregator, this is ok, but how should I handle the remaining?

It shoudn't be this hard, I feel that I'm missing something :)

Some clusterExtend logics are incomplete

There is an issue with the gernation of CLuster extends on operational ligic side - tying is correct.

I found this in NetworkCommissioningCluster.
it creates a WiFiNetworkInterfaceOrThreadNetworkInterfaceComponent which is typing wise added if wifi OR thread exists

But in the extendCluster section of the code part this is missing
Bildschirmfoto 2023-07-30 um 11 49 14

When I add basically

            extendCluster(cluster, WiFiNetworkInterfaceOrThreadNetworkInterfaceComponent, { wiFiNetworkInterface: true });
            extendCluster(cluster, WiFiNetworkInterfaceOrThreadNetworkInterfaceComponent, { threadNetworkInterface: true });

it works as expected

format on commit

If formatting is required on commits, reduce developer load by auto-linting on commit using GtiHub hook.

Generate "Timed" Access-flag into clusters

Hey @lauckhart,

for the upcoming finalizations of the protocol I could need support on the generation side of things :-)

I would need to have the "Timed" access flkag to be generated in the relevant attributes and commands. I propose doing that like scene/persistent and such flags.

Thank you

Validate and fix Current Model Validator issues

2023-07-25 13:48:29.617 ERROR ValidateModel        *** Validation error summary ***
2023-07-25 13:48:29.617 ERROR ValidateModel        enum8 with no children code: CHILDLESS_ENUM xref: cluster§1.6.6.3 src: PulseWidthModulation.Step.StepMode
2023-07-25 13:48:29.617 ERROR ValidateModel        enum16 with no children code: CHILDLESS_ENUM xref: cluster§1.8.8.2.1 src: ModeSelect.SemanticTagStruct.Value
2023-07-25 13:48:29.617 ERROR ValidateModel        map8 with no children code: CHILDLESS_BITMAP xref: cluster§3.2.11.21.1 src: ColorControl.MoveColorTemperature.MoveMode
2023-07-25 13:48:29.617 ERROR ValidateModel        map8 with no children code: CHILDLESS_BITMAP xref: cluster§3.2.11.22.1 src: ColorControl.StepColorTemperature.StepMode
2023-07-25 13:48:29.617 ERROR ValidateModel        enum8 with no children code: CHILDLESS_ENUM src: BarrierControl.BarrierMovingState
2023-07-25 13:48:29.618 ERROR ValidateModel        map16 with no children code: CHILDLESS_BITMAP src: BarrierControl.BarrierSafetyStatus
2023-07-25 13:48:29.618 ERROR ValidateModel        map8 with no children code: CHILDLESS_BITMAP src: BarrierControl.BarrierCapabilities
2023-07-25 13:48:29.618 ERROR ValidateModel        map32 with no children code: CHILDLESS_BITMAP src: ElectricalMeasurement.MeasurementType
2023-07-25 13:48:29.618 ERROR ValidateModel        map8 with no children code: CHILDLESS_BITMAP src: ElectricalMeasurement.DcOverloadAlarmsMask
2023-07-25 13:48:29.618 ERROR ValidateModel        map16 with no children code: CHILDLESS_BITMAP src: ElectricalMeasurement.AcOverloadAlarmsMask
2023-07-25 13:48:29.618 ERROR ValidateModel        enum8 with no children code: CHILDLESS_ENUM src: ElectricalMeasurement.GetProfileInfoResponseCommand.ProfileIntervalPeriod
2023-07-25 13:48:29.618 ERROR ValidateModel        enum8 with no children code: CHILDLESS_ENUM src: ElectricalMeasurement.GetMeasurementProfileResponseCommand.ProfileIntervalPeriod
2023-07-25 13:48:29.618 ERROR ValidateModel        enum8 with no children code: CHILDLESS_ENUM src: ElectricalMeasurement.GetMeasurementProfileCommand.NumberOfIntervals
2023-07-25 13:48:29.618 ERROR ValidateModel        enum8 with no children code: CHILDLESS_ENUM src: BinaryInputBasic.Polarity
2023-07-25 13:48:29.618 ERROR ValidateModel        enum8 with no children code: CHILDLESS_ENUM src: BinaryInputBasic.Reliability
2023-07-25 13:48:29.618 ERROR ValidateModel        map8 with no children code: CHILDLESS_BITMAP src: BinaryInputBasic.StatusFlags
2023-07-25 13:48:29.618 ERROR ValidateModel        Error counts by code:
2023-07-25 13:48:29.619 ERROR ValidateModel        ⎸ CHILDLESS_BITMAP: 8
2023-07-25 13:48:29.619 ERROR ValidateModel        ⎸ CHILDLESS_ENUM: 8
2023-07-25 13:48:29.619 ERROR ValidateModel        *** Total 16 validation errors ***

Dynamically adding new devices to a Bridge failing

A dynamically added device to an already running Bridge is not recognized by either Apple or Google. Log of action follows:

2023-07-09 07:59:21.286 DEBUG MessageExchange New exchange protocol: 1 id: 39191 active retransmit ms: 300 idle retransmit ms: 5000 retries: 5
2023-07-09 07:59:21.287 DEBUG MessageExchange Message « id: 39621/39191/218056380 type: 1/8 reqAck: true payload: 1528002801360215370024000224010624020118350118181824ff0118
2023-07-09 07:59:21.287 DEBUG InteractionProtocol Received invoke request from udp://fe80::e6f0:42ff:fe3d:67b2%en0:5540 on session secure/39621: MA-onofflight(0x2)/On/Off(0x6)/on(0x1)
2023-07-09 07:59:21.288 DEBUG CommandServer Invoke on with data undefined
2023-07-09 07:59:21.288 DEBUG InteractionProtocol Storing attribute onOff in cluster On/Off (6)
2023-07-09 07:59:21.295 DEBUG CommissioningServer Endpoint structure got updated ...
2023-07-09 07:59:21.299 DEBUG CommissioningServer Assigned endpoint id 6 for endpoint with serial_node-matter-1688867942490-index_0-serial_node-matter4 / device MA-onofflight and stored it
2023-07-09 07:59:21.303 DEBUG InteractionProtocol Restoring attribute breadcrumb (0) in cluster breadcrumb (48)
2023-07-09 07:59:21.304 DEBUG InteractionProtocol Restoring attribute onOff (0) in cluster onOff (6)
2023-07-09 07:59:21.304 DEBUG CommandServer Invoke on response : undefined
2023-07-09 07:59:21.304 DEBUG ExchangeManager Message » id: 39621/39191/3083325674 type: 1/9 acked: 218056380 reqAck: true payload: 152800360115350137002400022401062402011835012400001818181824ff0118
2023-07-09 07:59:21.320 DEBUG MessageExchange Message « id: 39621/39191/218056381 type: 0/16 acked: 3083325674 reqAck: false payload:
2023-07-09 07:59:21.344 DEBUG SubscriptionHandler Sending subscription update message for ID 1859306161 with 1 values
2023-07-09 07:59:21.344 DEBUG MessageExchange New exchange protocol: 1 id: 12658 active retransmit ms: 300 idle retransmit ms: 5000 retries: 5
2023-07-09 07:59:21.344 DEBUG SubscriptionHandler Sending subscription changes for ID 1859306161: [{"path":{"endpointId":2,"clusterId":6,"attributeId":0},"schema":{},"version":3,"value":true}]
2023-07-09 07:59:21.344 DEBUG ExchangeManager Message » id: 11491/12658/3083325675 type: 1/5 reqAck: true payload: 152600b1c2d26e36011535012400033701240202240306240400182902181818280424ff0118
2023-07-09 07:59:21.344 DEBUG SubscriptionHandler Sending subscription update message for ID 1859306162 with 1 values
2023-07-09 07:59:21.344 DEBUG MessageExchange New exchange protocol: 1 id: 12659 active retransmit ms: 300 idle retransmit ms: 5000 retries: 5
2023-07-09 07:59:21.344 DEBUG SubscriptionHandler Sending subscription changes for ID 1859306162: [{"path":{"endpointId":2,"clusterId":6,"attributeId":0},"schema":{},"version":3,"value":true}]
2023-07-09 07:59:21.344 DEBUG ExchangeManager Message » id: 16097/12659/3083325676 type: 1/5 reqAck: true payload: 152600b2c2d26e36011535012400033701240202240306240400182902181818280424ff0118
2023-07-09 07:59:21.345 DEBUG SubscriptionHandler Sending subscription update message for ID 1859306163 with 1 values
2023-07-09 07:59:21.345 DEBUG MessageExchange New exchange protocol: 1 id: 12660 active retransmit ms: 300 idle retransmit ms: 5000 retries: 5
2023-07-09 07:59:21.345 DEBUG SubscriptionHandler Sending subscription changes for ID 1859306163: [{"path":{"endpointId":2,"clusterId":6,"attributeId":0},"schema":{},"version":3,"value":true}]
2023-07-09 07:59:21.345 DEBUG ExchangeManager Message » id: 54443/12660/3083325677 type: 1/5 reqAck: true payload: 152600b3c2d26e36011535012400033701240202240306240400182902181818280424ff0118
2023-07-09 07:59:21.360 DEBUG MessageExchange Message « id: 39620/12660/210563175 type: 1/1 acked: 3083325677 reqAck: true payload: 1524000024ff0118
2023-07-09 07:59:21.360 DEBUG ExchangeManager Message » id: 54443/12660/3083325678 type: 0/16 acked: 210563175 reqAck: false payload:
2023-07-09 07:59:21.369 DEBUG MessageExchange Message « id: 39621/12658/218056382 type: 1/1 acked: 3083325675 reqAck: true payload: 1524000024ff0118
2023-07-09 07:59:21.369 DEBUG ExchangeManager Message » id: 11491/12658/3083325679 type: 0/16 acked: 218056382 reqAck: false payload:
2023-07-09 07:59:21.369 DEBUG MessageExchange Message « id: 39619/12659/222356079 type: 1/1 acked: 3083325676 reqAck: true payload: 1524000024ff0118
2023-07-09 07:59:21.369 DEBUG ExchangeManager Message » id: 16097/12659/3083325680 type: 0/16 acked: 222356079 reqAck: false payload:

Feature: List all commissioned and connected controllers.

Discussed in #221

Originally posted by Controlhaus July 19, 2023
It would be helpful to visualize connections between bridges or devices and controllers through a set of functions to:

  • get a list of controllers a bridge or device is commissioned to.
  • get the current subscription status of each controller (subscribed or not subscribed).

matter-node Cannot pair Bridge after deleting.

Unable to pair a Bridge a second time after deleting the previously paired bridge in the smart home app (tested with Apple Home).

The Bridge pairs successfully again after deleting the storage directory.

Edit: Here are the log entries from matter-node after pressing delete in Apple Home:
2023-07-13 17:30:18.txt

[test] Add browser compatibility tests to CI

The test framework is designed to run browser compatibility tests, but those aren't run in by the CI to validate PRs don't break browser compatibility. Add the browser tests to CI.

Clusters missing "fabricIndex" field whendata are fabricScoped

When data are defined as "Fabric scoped" they automaticllay include a fabricIndex field with the field id 0xFE. We miss them.

This field is mainly relevant For fabrics field in OperationalCredentialsCLuster FabricDescriptionStruct and leading to Amazon no continueing commissioning process.

Validate "incoming" (decoded) data to defined shema breaks with List chunking

While playing around with node-matter and pairing as controlelr with chip-tool lighting app I came across the protocol options for array/List chunking.

The chip app always send an empty array and then "add" elements to it in additional packages. This is in fact also needed if an array gets that big that it do not fit in one data package.
While this topic itself can not be handled on "pure Tlv level" (aka /src/tlv/TlvArray.ts) the current issue starts when we have a schema with e.g. "minimum 1 list entry". Because decoding the first tlv package gives an empty array and this will fail because we do validation.

The main question that arises is: If devices is sending a invalid value (aka "decode for the library), should that be an exception? In fact we can not do anything against such "Misbehaving devices". In fact yes, it should be still an exception if we want to encode (aka send ourself) such a value, so the shema validation should be used when setting such a value.

The alternative would be to allow a flag when decoding values to not validate the value and the caller ist then self-responsible. (so after processing all value parts we could call validate ourself)

Details for that "Change" (Chunking) handling is in Core Specs "10.5.4.3.1. Lists".

As an example this is the DataReport received from chip tool app for reading one value:

{
    "values": [
        {
            "value": {
                "version": 2206465283,
                "path": {
                    "endpointId": 0,
                    "clusterId": 29,
                    "attributeId": 0
                },
                "value": [
                    {
                        "typeLength": {
                            "type": 22
                        }
                    },
                    {
                        "typeLength": {
                            "type": 24
                        }
                    }
                ]
            }
        },
        {
            "value": {
                "version": 2206465283,
                "path": {
                    "endpointId": 0,
                    "clusterId": 29,
                    "attributeId": 0,
                    "listIndex": null
                },
                "value": [
                    {
                        "typeLength": {
                            "type": 21
                        }
                    },
                    {
                        "tag": {
                            "id": 0
                        },
                        "typeLength": {
                            "type": 4,
                            "length": 0
                        },
                        "value": 22
                    },
                    {
                        "tag": {
                            "id": 1
                        },
                        "typeLength": {
                            "type": 4,
                            "length": 0
                        },
                        "value": 1
                    },
                    {
                        "typeLength": {
                            "type": 24
                        }
                    }
                ]
            }
        }
    ],
    "suppressResponse": true,
    "interactionModelRevision": 1
}

The "Change" logic is within the listIndex field when getting attribute responses. In this case listIndex=null means "add these data to the array".

unused 'default' field in object causes d.ts generation failure

Build the project and observe the generated InteractionClient.d.ts and note the following errors. Easy fix is to remove unused default field.

../chip-matter-wes/packages/matter-node.js/dist/matter/interaction/InteractionClient.d.ts:27:85 - error TS1005: ':' expected.

27     set<T>(_endpointId: number, _clusterId: number, { id, schema, optional, default }: Attribute<T>, _value: T): Promise<void>;
                                                                                       ~

../chip-matter-wes/packages/matter-node.js/dist/matter/interaction/InteractionClient.d.ts:28:112 - error TS1005: ':' expected.

28     subscribe<A extends Attribute<any>>(endpointId: number, clusterId: number, { id, schema, optional, default }: A, listener: (value: AttributeJsType<A>, version: number) => void, minIntervalFloorSeconds: number, maxIntervalCeilingSeconds: number): Promise<void>;```
                                                                                                              

Add Color Control Cluster

Working this, but it will take a while with around 50 Attributes, nearly 20 Commands any many enums and bitmaps.

Pairing with iOS 16.4 and iOS 16.5beta fails

Pairing with iOS 16.4 fails

Pairing with iOS 16.4 fails with error message: Accessory pairing failed

2023-04-04 19:49:12.731 ERROR CaseServer An error occurred during the commissioning Error: Signature verification failed
    at Function.verifySpki (/home/user/matter.js/packages/matter-node.js/src/crypto/Crypto.ts:173:29)
    at CaseServer.<anonymous> (/home/user/matter.js/packages/matter-node.js/src/matter/session/secure/CaseServer.ts:98:20)
    at Generator.next (<anonymous>)
    at fulfilled (/home/user/matter.js/packages/matter-node.js/src/matter/session/secure/CaseServer.ts:10:58)

Details

user@matter-vm:~/matter.js/packages/matter-node.js$ npm run matter

> @project-chip/[email protected] matter
> ts-node --project tsconfig.dist.json src/Device.ts

2023-04-04 19:48:47.914 INFO Device node-matter
2023-04-04 19:48:47.929 DEBUG MdnsBroadcaster announce commissioning mode 1 Matter test device 257 [object Object] 32768 3840
2023-04-04 19:48:47.933 INFO Device Listening
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
█ ▄▄▄▄▄ ██▀▄▀▄█ ▄▄▄▄▄ █
█ █   █ █▄▀▄▀▄█ █   █ █
█ █▄▄▄█ ██ ▀▀▄█ █▄▄▄█ █
█▄▄▄▄▄▄▄█ █ ▀▄█▄▄▄▄▄▄▄█
█▄ ▄█▄ ▄▄ ▀ █  ▄▀██ █▀█
██ █▀▀ ▄▄█ █ ▀▄▄██ ▀█▀█
█▄▄████▄▄▄▀▄▀ ▀██▄▄▀▄▀█
█ ▄▄▄▄▄ █  ▄█▄█▄▄█▄ █ █
█ █   █ █▄▀▀█▄ ▄▀▀▄ ▀██
█ █▄▄▄█ █  ▀█▄█ ▀█  ▀ █
█▄▄▄▄▄▄▄█▄█▄█▄██▄██▄█▄█
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=MT:Y.K90AFN00KA0648G00
Manual pairing code: 34970112332
2023-04-04 19:49:07.126 DEBUG MessageExchange new MessageExchange 0 33825 300 5000 5
...
2023-04-04 19:49:12.653 INFO CaseServer Case server: Received pairing request from udp://fe80::85a:fd3d:ca9f:da30%ens33:56485
2023-04-04 19:49:12.657 DEBUG ExchangeManager sending id:0/33843/2398132853 t:0/49 acked:52639638 reqAck:true payload: 15300120fb625d9ec35057a01b4659f298fbc5e3b11f0a0476c86ad1570dcd5074569b2925020ca1300341044adb8015aad5b556ee8cb6ddd1b30798a2c1b5d4fbeb9d2e23b3203f42e76dec08c43aa00cf0faf32b94d6127e1aa3462083d38aca27a27f5fbe5ed30bba4e5931046301a32f458be3df4d2a47e5521a7500aa28ea91d8c27c035e97cd8f1571933aefdc7a028e3e2c454c6240c02aa4398bcbebfeb973988d92873dbfce303a5f63c28b24fd63c23b09877c0dc1b63dd51bd38ec700899082d078a55fb47a4d38bef1cdce20b7b79da8f8d78acb6ee5a8be873570605aa05e199b87b844e7e4599471b91c356adb694a8d0f175b5a0b5d89695e9343f9389dc979e3ea2f11dc3d3e66b8c5f187c84f6da63650c9973f514823ea06969e01327d95c948841a298588876a9fbb9aafae8d05a3e58438a6f57ed4118e5b0c42789daba7a436693d5a363054e75b2a55c1b742507db2b0301b029bb7c909d7df41eff984becc1a5fa142dbaaff444601d6faf7876c9181189d95258d2159eb13632defe7aedef32eccfc7b852a849e8220d19778854389357e4ed74809ce7f23749259b738316dc7020d37f6e278c94ddf55c60c7c947f0d2b02dddaa9312190d5c181134823f22a0ad88fb574091818
2023-04-04 19:49:12.730 DEBUG MessageExchange onMessageReceived 0 id:0/33843/52639639 t:0/50 acked:2398132853 reqAck:true payload: 153101540180aff63358abdd5f2d31290728a8eebb6dd3c31ff8d9ff111b7a89266057b8fc195851c34c9008a7be58fc2aac4424eb5b66fa11100a7819ea9a723c43ecca5db0082d37db150f771822936b7a5912fc8735b1e3fd37a3d1732849a0b2548aae1de09be507b2dcfac3cbe87df2468852b9f5fee43ce40cfd530d5873ab3a76c4046200393a62c1298c0a96941cefd76046793df34fa1bac713fe5000612f42315d4bb32bf62692a7200ce860341d63da746d947ea1f7ac9ce4b1fd20c3c6767b75fc7cbdb365938f2287f44a3a2ee79622d8462f605f184cc0d9615111e7024e1bd4e8f1f8fa906a6376553d77bae57782166b4cb746436f2986ac4f79b43c26945c900e4ae3321fe5ad668ae898c9aa6270b14f2125bf3266999a3a603ea4d3c64ecd03f541f9f8910d0f228638182332ce60a10a3a634ef0f9eed95b38707978e34d3e03fc93a625072f4f2a37cf3156ea59d518
2023-04-04 19:49:12.731 ERROR CaseServer An error occurred during the commissioning Error: Signature verification failed
    at Function.verifySpki (/home/user/matter.js/packages/matter-node.js/src/crypto/Crypto.ts:173:29)
    at CaseServer.<anonymous> (/home/user/matter.js/packages/matter-node.js/src/matter/session/secure/CaseServer.ts:98:20)
    at Generator.next (<anonymous>)
    at fulfilled (/home/user/matter.js/packages/matter-node.js/src/matter/session/secure/CaseServer.ts:10:58)
2023-04-04 19:49:12.732 DEBUG ExchangeManager sending id:0/33843/2398132854 t:0/64 acked:52639639 reqAck:true payload: 0100000000000200
2023-04-04 19:49:12.800 DEBUG MessageExchange onMessageReceived 0 id:0/33843/52639640 t:0/16 acked:2398132854 reqAck:false payload:

matter-node.js-ios16.4.log

Feature-specific command response not correctly generated

          Network COmmissioning has another intersting topic.

The Scan Result struct contains different fields depending on features, but we generate both fields as mandatory right now. This leads to parsing error "Missing mandatory field threadScanResults" when executing a scanNetworks on a CLuster with Wifi feature (and would vise versa when Thread)

Bildschirmfoto 2023-07-30 um 12 05 03

Bildschirmfoto 2023-07-30 um 12 03 47

Because of the fact that this is on the "command response" level the generator could generate the command differently depending on features and so also have "feature specific responses".

Originally posted by @Apollon77 in #242 (comment)

Crypto sign error

Crypto › sign & verify with raw keys › signs data with generated private key

    Cannot infer named curve from key length

      442 |
      443 |             default:
    > 444 |                 throw new KeyError("Cannot infer named curve from key length");
          |                       ^
      445 |         }
      446 |     }
      447 | }

      at inferCurve (../matter.js/src/crypto/Key.ts:444:23)
      at Key (../matter.js/src/crypto/Key.ts:540:13)
      at PrivateKey (../matter.js/src/crypto/Key.ts:564:12)
      at Object.<anonymous> (test/crypto/CryptoTest.ts:67:54)

seen in https://github.com/project-chip/matter.js/pull/275/checks#step:7:17602

Use matter-controller connect matter fail.

I run

npm run matter

and I get

> @project-chip/[email protected] matter
> ts-node --project tsconfig.dist.json src/Device.ts

2023-04-20 20:17:09.306 INFO Device node-matter
2023-04-20 20:17:09.338 DEBUG MdnsBroadcaster announce commissioning mode 1 Matter test device 257 [object Object] 32768 3840
2023-04-20 20:17:09.341 INFO Device Listening
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
█ ▄▄▄▄▄ ██▀▄▀▄█ ▄▄▄▄▄ █
█ █   █ █▄▀▄▀▄█ █   █ █
█ █▄▄▄█ ██ ▀▀▄█ █▄▄▄█ █
█▄▄▄▄▄▄▄█ █ ▀▄█▄▄▄▄▄▄▄█
█▄ ▄█▄ ▄▄ ▀ █  ▄▀██ █▀█
██ █▀▀ ▄▄█ █ ▀▄▄██ ▀█▀█
█▄▄████▄▄▄▀▄▀ ▀██▄▄▀▄▀█
█ ▄▄▄▄▄ █  ▄█▄█▄▄█▄ █ █
█ █   █ █▄▀▀█▄ ▄▀▀▄ ▀██
█ █▄▄▄█ █  ▀█▄█ ▀█  ▀ █
█▄▄▄▄▄▄▄█▄█▄█▄██▄██▄█▄█
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=MT:Y.K90AFN00KA0648G00
Manual pairing code: 34970112332
2023-04-20 20:17:09.344 DEBUG UdpChannelNode initialize multicast interface 172.16.6.139 udp4 5353 enp9s0
2023-04-20 20:17:09.344 DEBUG UdpChannelNode initialize multicast interface ::%enp9s0 udp6 5353 enp9s0

then I open another shell and run

npm run matter-controller -- -ip 172.16.6.139

but I get

> @project-chip/[email protected] matter-controller
> ts-node --project tsconfig.dist.json src/Controller.ts -ip 172.16.6.139

2023-04-20 20:25:28.927 INFO Controller node-matter
2023-04-20 20:25:28.953 DEBUG MessageExchange new MessageExchange 0 13333 300 5000 5
2023-04-20 20:25:28.954 DEBUG ExchangeManager sending id:0/13333/2895701458 t:0/32 reqAck:true payload: 153001207f734f35a54970d731b73b52eb029a74b8c546d1f2f97e0b46244495e0f411cc25021c6f240300280418
2023-04-20 20:25:28.956 DEBUG MessageExchange new MessageExchange 0 13333 300 5000 5
2023-04-20 20:25:28.957 DEBUG MessageExchange onMessageReceived 0 id:0/13333/2895701458 t:0/32 reqAck:true payload: 153001207f734f35a54970d731b73b52eb029a74b8c546d1f2f97e0b46244495e0f411cc25021c6f240300280418
2023-04-20 20:25:28.957 ERROR ExchangeManager Error: Unsupported protocol 0
    at ExchangeManager.<anonymous> (/home/yinsy/esp/matter.js/packages/matter-node.js/src/matter/common/ExchangeManager.ts:104:54)
    at Generator.next (<anonymous>)
    at fulfilled (/home/yinsy/esp/matter.js/packages/matter-node.js/src/matter/common/ExchangeManager.ts:10:58)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
2023-04-20 20:25:29.298 DEBUG MessageExchange Resubmit message 2895701458 (attempt 1, next backoff time 392ms))
2023-04-20 20:25:29.298 DEBUG ExchangeManager sending id:0/13333/2895701458 t:0/32 reqAck:true payload: 153001207f734f35a54970d731b73b52eb029a74b8c546d1f2f97e0b46244495e0f411cc25021c6f240300280418
2023-04-20 20:25:29.299 DEBUG MessageExchange onMessageReceived 0 id:0/13333/2895701458 t:0/32 reqAck:true payload: 153001207f734f35a54970d731b73b52eb029a74b8c546d1f2f97e0b46244495e0f411cc25021c6f240300280418
2023-04-20 20:25:29.300 DEBUG ExchangeManager sending id:0/13333/2895701459 t:0/16 acked:2895701458 reqAck:false payload: 
2023-04-20 20:25:29.301 DEBUG MessageExchange onMessageReceived 0 id:0/13333/2895701459 t:0/16 acked:2895701458 reqAck:false payload:

it seems not success, is there any wrong operation? how can I solve this?

How to handle on/off request in DeviceNode.ts

Hello,

I working with your repo matter-node.js, thanks for this.
Do you know how to handle on/off request in DeviceNode.ts file?
When I switch on/off from a Matter client, I am getting this from the log:

2023-04-30 14:27:27.716 DEBUG CommandServer Invoke on with data undefined
2023-04-30 14:27:27.716 DEBUG InteractionProtocol Storing attribute onOff in cluster OnOff (6)
2023-04-30 14:27:27.718 DEBUG SubscriptionHandler Sending subscription update message for ID 2935796526 with 1 values
2023-04-30 14:27:27.718 DEBUG MessageExchange new MessageExchange 1 7864 300 5000 5
2023-04-30 14:27:27.718 DEBUG SubscriptionHandler Sending subscription changes for ID 2935796526: [{"path":{"endpointId":4,"clusterId":6,"attributeId":0},"schema":{},"version":29,"value":true}]

Regards

Seems we lose types on feature specific clusters

Add a new test to the Clusterfactorytest.ts like

it("creates clusterserver with a feature and handlers", () => {
            const fullCluster = ClusterServer(
                TestExtensibleCluster.with("Extended"),
                {
                    attr1: 1,
                    attr2: 2,
                },
                {
                    cmd1: ({ attributes: { attr1, attr2 }, session, endpoint}) => {
                        if (attr1 == undefined || attr2 == undefined || session === undefined || endpoint === undefined) throw new Error("Missing attribute");
                    },
                    cmd2: ({ request: { cmdField1 },  attributes: { attr1, attr2 }, session, endpoint}) => {
                        if (cmdField1 === undefined || attr1 == undefined || attr2 == undefined || session === undefined || endpoint === undefined) throw new Error("Missing attribute");
                        return { cmdRet1: 5 };
                    },
                    getAttr1: ({ attributes: { attr1, attr2 }, session, endpoint}) => {
                        if (attr1 == undefined || attr2 == undefined || session === undefined || endpoint === undefined) throw new Error("Missing attribute");
                        return 5;
                    }
                },
                {
                    ev1: true,
                    ev2: true,
                }
            );
        })

including one adkjustment:

const ELEMENTS2 = {
    attributes: {
        attr2: Attribute(4, TlvUInt8)
    },
    commands: {
        cmd2: Command(5, TlvObject({ cmdField1: TlvField(1, TlvUInt16)}), 5, TlvObject({ cmdRet1: TlvField(1, TlvUInt16)}))
    },
    events: {
        ev2: Event(6, EventPriority.Debug, TlvNoArguments)
    }
}

All the attributes and request options are all considered "any" which is wrong. Interestingly enough the return type is interfered correctly.

After tracking it down I ended in the fact that the method extendCluster in CLusterfactory does an "inplace" upgrade for the operative data of the clusters but the typing extension do not seem to work correctly.

Also in BLE branch (in matter-node.js/-examples/DevcieNode.ts we have a Wifi Networking cluster. here it is the same but the typing error also points to something more as it seems:
So adjust to like

Bildschirmfoto 2023-07-27 um 11 41 54

and you get

src/examples/DeviceNode.ts:180:21 - error TS2322: Type '({ request: { ssid, breadcrumb }, attributes: { lastNetworkingStatus }, endpoint }: { request: { ssid: any; breadcrumb: any; }; attributes: { lastNetworkingStatus: any; }; endpoint: any; }) => Promise<{ networkingStatus: NetworkCommissioningStatus; wiFiScanResults: { ...; }[]; }>' is not assignable to type '(args: { request: any; attributes: AttributeServers<{ maxNetworks: FixedAttribute<number, any>; networks: Attribute<TypeFromFields<{ networkId: FieldType<Uint8Array>; connected: FieldType<...>; }>[], any>; interfaceEnabled: WritableAttribute<...>; lastNetworkingStatus: Attribute<...>; lastNetworkId: Attribute<...>; ...'.
  Types of parameters '__0' and 'args' are incompatible.
    Type '{ request: any; attributes: AttributeServers<{ maxNetworks: FixedAttribute<number, any>; networks: Attribute<TypeFromFields<{ networkId: FieldType<Uint8Array>; connected: FieldType<boolean>; }>[], any>; interfaceEnabled: WritableAttribute<...>; lastNetworkingStatus: Attribute<...>; lastNetworkId: Attribute<...>; las...' is not assignable to type '{ request: { ssid: any; breadcrumb: any; }; attributes: { lastNetworkingStatus: any; }; endpoint: any; }'.
      Types of property 'attributes' are incompatible.
        Property 'lastNetworkingStatus' is missing in type 'AttributeServers<{ maxNetworks: FixedAttribute<number, any>; networks: Attribute<TypeFromFields<{ networkId: FieldType<Uint8Array>; connected: FieldType<boolean>; }>[], any>; interfaceEnabled: WritableAttribute<...>; lastNetworkingStatus: Attribute<...>; lastNetworkId: Attribute<...>; lastConnectErrorValue: Attribut...' but required in type '{ lastNetworkingStatus: any; }'.

180                     scanNetworks: async ({
                        ~~~~~~~~~~~~

This brings me to https://github.com/project-chip/matter.js/blob/main/packages/matter.js/src/cluster/server/ClusterServer.ts#L41 where an arg is in and the error "Types of parameters '__0' and 'args' are incompatible." could match to that ?!

So something is lost on the road ...

It seems to work in general for base clusters because we have sevewral such clusters workig including access, so my assumptions went the "Extend" direction that it comes from there.
For me it seems that after Extend the linked Type "CommandHandler" can not infer the types of the command and so ends in the "never" case ... becuse it works with empty method.

cannot run matter-node.js using 'npm run matter'

From a fresh main checkout , I build using npm install and then move to packages/matter-node.js dir.
Then if I run with npm run matter I get the following error.
Before commit 397ede1 this was launching the matter server, as per instructions in packages/matter-node.js/README.md Installation/Usage sections.
OS: Windows 10, Node.js v18.16.0

$ npm run matter

> @project-chip/[email protected] matter
> ts-node --project tsconfig.dist.json src/Device.ts

Error: Cannot find module './Crypto.js'
Require stack:
- C:\matter.js\packages\matter-node.js\src\crypto\CryptoNode.ts
- C:\matter.js\packages\matter-node.js\src\Device.ts
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (C:\matter.js\node_modules\@cspotcode\source-map-support\source-map-support.js:811:30)
    at Function.Module._load (node:internal/modules/cjs/loader:920:27)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (C:\matter.js\packages\matter-node.js\src\crypto\CryptoNode.ts:9:1)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module.m._compile (C:\matter.js\node_modules\ts-node\src\index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Object.require.extensions.<computed> [as .ts] (C:\matter.js\node_modules\ts-node\src\index.ts:1621:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\matter.js\\packages\\matter-node.js\\src\\crypto\\CryptoNode.ts',
    'C:\\matter.js\\packages\\matter-node.js\\src\\Device.ts'
  ]
}
npm ERR! Lifecycle script `matter` failed with error:
npm ERR! Error: command failed
npm ERR!   in workspace: @project-chip/[email protected]
npm ERR!   at location: C:\matter.js\packages\matter-node.js

Resuming after a restart on bridge

Hello,

while using BridgedDeviceNode I'm encountering a problem, whenever bridge restarts none of the paired devices can resume it's session, e.g. whenever I try to switch the light on or off the error is like following (repeated 5 times);

.....`Device is already commissioned. Waiting for controllers to connect ...
2023-05-30 11:11:00.998 DEBUG UdpChannelNode Initialize multicast address: :5353 interface: wlan0 type: udp4
2023-05-30 11:11:00.999 DEBUG UdpChannelNode Initialize multicast address: : interface: wlan0 type: udp6

2023-05-30 11:11:25.826 ERROR ExchangeManager Cannot find a session for ID 49055
at ExchangeManager. (/home/xxx/projects/matter/matter-js-dev/packages/matter.js/src/protocol/ExchangeManager.ts:92:42)
at Generator.next ()
at /home/xxx/projects/matter/matter-js-dev/packages/matter.js/dist/cjs/protocol/ExchangeManager.js:13:71
at new Promise ()
at __awaiter (/home/xxx/projects/matter/matter-js-dev/packages/matter.js/dist/cjs/protocol/ExchangeManager.js:9:12)
at ExchangeManager.onMessage (/home/xxx/projects/matter/matter-js-dev/packages/matter.js/dist/cjs/protocol/ExchangeManager.js:77:16)
at /home/xxx/projects/matter/matter-js-dev/packages/matter.js/src/protocol/ExchangeManager.ts:57:18
at /home/xxx/projects/matter/matter-js-dev/packages/matter.js/src/net/UdpInterface.ts:28:83
at Socket.messageListener (/home/xxx/projects/matter/matter-js-dev/packages/matter-node.js/src/net/UdpChannelNode.ts:58:13)
at Socket.emit (node:events:513:28)`...

after 5th error I assume a new session id is being determined by the controller and it resumes to normal operation:

....... 2023-05-30 11:12:12.785 DEBUG MessageExchange New exchange protocol: 0 id: 44676 active retransmit ms: 300 idle retransmit ms: 5000 retries: 5 2023-05-30 11:12:12.786 DEBUG MessageExchange Message « id: 0/44676/140446173 type: 0/48 reqAck: true payload: 15300120ff610ee0..........

I tried to trigger some events like reachableChanged / startup but nothing changed (i assume they are internal) as thinking that this is the better way in terms of communications, but if we can't announce can we make session permanent with it's id?

ERROR InteractionMessenger TypeError: attribute.addMatterListener is not a function

The logs for this are here and the full code for this is here

But all I was trying to do is understand how to create custom devices.
So instead of :

import { OnOffLightDevice, OnOffPluginUnitDevice } from '@project-chip/matter.js/device'
//----
new OnOffLightDevice()
new OnOffPluginUnitDevice()

I was trying this:

import { DeviceTypes, Device } from '@project-chip/matter.js/device'
import {
	createDefaultOnOffClusterServer,
	createDefaultGroupsClusterServer,
	createDefaultScenesClusterServer,
	createDefaultIdentifyClusterServer
} from '@project-chip/matter.js/cluster'
class OnOffDevice extends Device {
   constructor(type) {
      super(type, {})
      const cluster = createDefaultOnOffClusterServer()
      
      const clusterServers = [
         createDefaultIdentifyClusterServer({
	    identify: data => this._executeHandler('identify', data)
	 }),
         createDefaultGroupsClusterServer(),
	 createDefaultScenesClusterServer(),
         cluster
      ]
      for (const server of clusterServers)
         this.addClusterServer(server)

      this.onOff = state => cluster.setOnOffAttribute(state)
      this.toggle = () => this.onOff(!cluster.getOnOffAttribute())
      cluster.subscribeOnOffAttribute(state => { 
         console.log('state changed here', state)
      })
      this.addCommandHandler('identify', ({ request: { identifyTime } }) =>
         console.log(`Identify OnOffDevice: ${identifyTime}`))
    }
}
//----
new OnOffDevice(DeviceTypes.ON_OFF_PLUGIN_UNIT)
new OnOffDevice(DeviceTypes.ON_OFF_LIGHT)

And I got the following error:

ERROR InteractionMessenger TypeError: attribute.addMatterListener is not a function
    at /root/home/matter.js/packages/matter.js/dist/cjs/protocol/interaction/SubscriptionHandler.js:61:23
    at Array.forEach (<anonymous>)
    at new SubscriptionHandler (/root/home/matter.js/packages/matter.js/dist/cjs/protocol/interaction/SubscriptionHandler.js:55:20)
    at InteractionServer.<anonymous> (/root/home/matter.js/packages/matter.js/dist/cjs/protocol/interaction/InteractionServer.js:471:45)
    at Generator.next (<anonymous>)
    at /root/home/matter.js/packages/matter.js/dist/cjs/protocol/interaction/InteractionServer.js:13:71
    at new Promise (<anonymous>)
    at __awaiter (/root/home/matter.js/packages/matter.js/dist/cjs/protocol/interaction/InteractionServer.js:9:12)
    at InteractionServer.handleSubscribeRequest (/root/home/matter.js/packages/matter.js/dist/cjs/protocol/interaction/InteractionServer.js:437:16)
    at /root/home/matter.js/packages/matter.js/dist/cjs/protocol/interaction/InteractionServer.js:335:265

Duplicate retry timers

Per log review with @Apollon77

"I see the issue, because of the one change there are three attributes changed. I assume because of the subscription wait times where apple usually have "0s" as minimum time the subscription handler goes a bit crazy and fires three subscription notifies "in parallel" ... this alone would not be the issue ... the issue is that also afterwards the "empty" subscriptions are fired that way ... so we have duplicated timers. As I last time looked at that code I had such a suspicion but no time to look into it."

HDBridge.txt

Clean fabric

Hello,

Could you add the procedure to remove the pairing and reset the node?

Regards

Composed Device failure with SmartThings

Paired the example Composed Device with SmartThings (with the usual timeout) but after completion only a single device was shown instead of the expected two. Attempts to turn the single device on/off generated errors within the SmartThings app. Attached log shows the pairing process followed by several attempts to control the single displayed device.

SmartThings-ComposedDeviceNode.txt

[ble][pair] crash on scan

matter-node> pair -b
Error [object Promise]
matter-node> 2023-08-16 13:44:46.330 DEBUG UdpChannelNode Socket created and bound  remoteAddress: undefined:undefined localAddress: :::47487
2023-08-16 13:44:46.348 DEBUG BleScanner Registered waiter for query D:3840 with timeout 15 seconds
2023-08-16 13:44:46.348 DEBUG NobleBleClient noble state is not poweredOn ... delay scanning till poweredOn
2023-08-16 13:44:46.499 DEBUG NobleBleClient Noble state changed to poweredOn
2023-08-16 13:44:46.499 DEBUG NobleBleClient Start scanning for Matter Services ...
2023-08-16 13:45:01.348 DEBUG BleScanner Finishing waiter for query D:3840, resolving: true
2023-08-16 13:45:01.355 WARN CommissioningController Ble commissioning failed: Error: No device discovered using identifier {"longDiscriminator":3840}! Please check that the relevant device is online.
2023-08-16 13:45:01.355 DEBUG MatterController Server addresses to try: udp://::1:5541
2023-08-16 13:45:01.355 DEBUG MatterController Try to communicate with udp://::1:5541 ...
2023-08-16 13:45:01.356 DEBUG MessageExchange New exchange protocol: 0 id: 46787 active retransmit ms: 300 idle retransmit ms: 5000 retries: 5
2023-08-16 13:45:01.357 DEBUG ExchangeManager Message » id: 0/46787/3358292387 type: 0/32 reqAck: true payload: 15300120f90a0fd79b3770469079fb793b0c05e6e74251cf0d03083b97582be65dc4639f2502f2cd240300280418
2023-08-16 13:45:01.729 DEBUG MessageExchange Resubmit message 3358292387 (attempt 1, next backoff time 392ms))
2023-08-16 13:45:01.729 DEBUG ExchangeManager Message » id: 0/46787/3358292387 type: 0/32 reqAck: true payload: 15300120f90a0fd79b3770469079fb793b0c05e6e74251cf0d03083b97582be65dc4639f2502f2cd240300280418
2023-08-16 13:45:02.123 DEBUG MessageExchange Resubmit message 3358292387 (attempt 2, next backoff time 556ms))
2023-08-16 13:45:02.124 DEBUG ExchangeManager Message » id: 0/46787/3358292387 type: 0/32 reqAck: true payload: 15300120f90a0fd79b3770469079fb793b0c05e6e74251cf0d03083b97582be65dc4639f2502f2cd240300280418
2023-08-16 13:45:02.680 DEBUG MessageExchange Resubmit message 3358292387 (attempt 3, next backoff time 871ms))
2023-08-16 13:45:02.680 DEBUG ExchangeManager Message » id: 0/46787/3358292387 type: 0/32 reqAck: true payload: 15300120f90a0fd79b3770469079fb793b0c05e6e74251cf0d03083b97582be65dc4639f2502f2cd240300280418
2023-08-16 13:45:03.552 DEBUG MessageExchange Resubmit message 3358292387 (attempt 4, next backoff time 1616ms))
2023-08-16 13:45:03.552 DEBUG ExchangeManager Message » id: 0/46787/3358292387 type: 0/32 reqAck: true payload: 15300120f90a0fd79b3770469079fb793b0c05e6e74251cf0d03083b97582be65dc4639f2502f2cd240300280418
2023-08-16 13:45:05.172 DEBUG MatterController Failed to communicate with udp://::1:5541, try next server ... Error
    at MessageExchange.retransmitMessage (/home/mturon/src/nest/matter.js/packages/matter.js/src/protocol/MessageExchange.ts:288:44)
    at TimerNode.callback (/home/mturon/src/nest/matter.js/packages/matter.js/src/protocol/MessageExchange.ts:309:26)
    at Timeout._onTimeout (/home/mturon/src/nest/matter.js/packages/matter-node.js/src/time/TimeNode.ts:26:18)
    at listOnTimeout (node:internal/timers:564:17)
    at processTimers (node:internal/timers:507:7)
2023-08-16 13:45:05.187 DEBUG MatterController Server addresses to try: udp://::1:5541
2023-08-16 13:45:05.188 DEBUG MdnsScanner Registered waiter for query _L3840._sub._matterc._udp.local with timeout 15 seconds
2023-08-16 13:45:05.189 DEBUG MdnsScanner Set 2 query records for query _L3840._sub._matterc._udp.local: [{"name":"_matterc._udp.local","recordClass":1,"recordType":12},{"name":"_L3840._sub._matterc._udp.local","recordClass":1,"recordType":12}]
2023-08-16 13:45:05.190 DEBUG MdnsScanner Sending 2 query records for 1 queries with 0 known answers. Re-Announce in 1.5 seconds
2023-08-16 13:45:05.192 DEBUG UdpChannelNode Socket created and bound  remoteAddress: undefined:5353 localAddress: 0.0.0.0:5353
2023-08-16 13:45:05.192 DEBUG UdpChannelNode Socket created and bound  remoteAddress: undefined:5353 localAddress: :::5353
2023-08-16 13:45:05.193 DEBUG UdpChannelNode Initialize multicast address: 100.86.180.251:5353 interface: wlp0s20f3 type: udp4
2023-08-16 13:45:05.193 DEBUG UdpChannelNode Initialize multicast address: ::%wlp0s20f3:5353 interface: wlp0s20f3 type: udp6
2023-08-16 13:45:06.692 DEBUG MdnsScanner Sending 2 query records for 1 queries with 0 known answers. Re-Announce in 3 seconds
2023-08-16 13:45:09.693 DEBUG MdnsScanner Sending 2 query records for 1 queries with 0 known answers. Re-Announce in 6 seconds
2023-08-16 13:45:15.693 DEBUG MdnsScanner Sending 2 query records for 1 queries with 0 known answers. Re-Announce in 12 seconds
2023-08-16 13:45:20.189 DEBUG MdnsScanner Finishing waiter for query _L3840._sub._matterc._udp.local, resolving: true
2023-08-16 13:45:20.190 DEBUG MdnsScanner Removing last query _L3840._sub._matterc._udp.local and stopping announce timer
/home/mturon/src/nest/matter.js/packages/matter.js/src/MatterController.ts:181
            throw new CommissioningError(
                  ^
CommissioningError: No device discovered using identifier {"longDiscriminator":3840}! Please check that the relevant device is online.
    at MatterController.<anonymous> (/home/mturon/src/nest/matter.js/packages/matter.js/src/MatterController.ts:181:19)
    at Generator.next (<anonymous>)
    at fulfilled (/home/mturon/src/nest/matter.js/packages/matter.js/dist/cjs/MatterController.js:10:58)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

Crypro Error "not enough data"

Here and there this error happens:

Error: error:0D06B08E:asn1 encoding routines:asn1_d2i_read_bio:not enough data
    at Sign.sign (node:internal/crypto/sig:131:29)
    at CryptoNode.signPkcs8 (/Users/ingof/Dev/GitHub/matter.js/packages/matter-node.js/dist/crypto/CryptoNode.js:115:44)
    at Function.Crypto.signPkcs8 (/Users/ingof/Dev/GitHub/matter.js/packages/matter.js/dist/cjs/crypto/Crypto.js:46:68)
    at Function.daCertToAsn1 (/Users/ingof/Dev/GitHub/matter.js/packages/matter.js/dist/cjs/certificate/CertificateManager.js:211:75)
    at AttestationCertificateManager.generateDaCert (/Users/ingof/Dev/GitHub/matter.js/packages/matter.js/dist/cjs/certificate/AttestationCertificateManager.js:143:59)
    at AttestationCertificateManager.getDACert (/Users/ingof/Dev/GitHub/matter.js/packages/matter.js/dist/cjs/certificate/AttestationCertificateManager.js:48:23)
    at new CommissioningServer (/Users/ingof/Dev/GitHub/matter.js/packages/matter.js/dist/cjs/CommissioningServer.js:100:54)
    at Device.<anonymous> (/Users/ingof/Dev/GitHub/matter.js/packages/matter-node.js-examples/dist/examples/DeviceNode.js:112:41)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/ingof/Dev/GitHub/matter.js/packages/matter-node.js-examples/dist/examples/DeviceNode.js:11:58) {
  library: 'asn1 encoding routines',
  function: 'asn1_d2i_read_bio',
  reason: 'not enough data',
  code: 'ERR_OSSL_ASN1_NOT_ENOUGH_DATA'
}

We should find out how to work areound that or at least catch-and-retry

Add Mode Select Cluster

Working this one. Interesting cluster that allows fairly arbitrary functionality to be presented to the controller with an overall "description" string and a list of "label" strings that a user would select from in order to tell the cluster to do an operation or switch "modes".

Unable to acquire setup code from Alexa

After commissioning node-matter in Alexa, I tried to acquire a setup code to commission node-matter in Google Home which I've done in the past successfully.

I got an error. This is the trace:

Maybe there is something going on in my network?

2023-2-4 9:3:3.884 DEBUG MessageExchange new MessageExchange 64212 300 2
2023-2-4 9:3:3.884 DEBUG MessageExchange onMessageReceived id:59185/64212/47275422 t:1/10 reqAck:true payload: 152500102724ff0118
2023-2-4 9:3:3.885 DEBUG InteractionProtocol Received timed request from udp://10.75.1.101:5541 on session secure/59185
2023-2-4 9:3:3.885 DEBUG ExchangeManager sending id:59185/64212/1501414735 t:1/1 acked:47275422 reqAck:true payload: 1524000024ff0118
2023-2-4 9:3:3.898 DEBUG MessageExchange onMessageReceived id:59185/64212/47275423 t:1/8 acked:1501414735 reqAck:true payload: 1528002901360215370024000024013c2402001835012500840330016189e0f5b07a6ed27c756dcd0e9f07a581c309b761c27e2f9cd4227fda42e9117c04f7d4703df5ca6ee3c8ede0f2297e8f568605b732185036efaed65ab3cc60af47f6097a6f1f57728b17508f36896ed520e8a3099cee69c1f2f23950ea9a0a16942502650225038813300413534d415254484f4d455f50414b455f53414c5418181824ff0118
2023-2-4 9:3:3.899 DEBUG InteractionProtocol Received invoke request from udp://10.75.1.101:5541 on session secure/59185: 0x0/0x3c/0x0
2023-2-4 9:3:3.907 DEBUG ExchangeManager sending id:59185/64212/1501414736 t:1/9 acked:47275423 reqAck:true payload: 1528003601153500370024000024013c2402001835011818181824ff0118
**2023-2-4 9:3:3.907 ERROR MdnsBroadcaster Error: send EHOSTUNREACH ff02::fb:5353**
2023-2-4 9:3:3.920 DEBUG MessageExchange onMessageReceived id:59185/64212/47275424 t:0/16 acked:1501414736 reqAck:false payload: 
2023-2-4 9:3:4.391 DEBUG MessageExchange new MessageExchange 64213 300 2
2023-2-4 9:3:4.391 DEBUG MessageExchange onMessageReceived id:59185/64213/47275425 t:1/10 reqAck:true payload: 152500102724ff0118
2023-2-4 9:3:4.391 DEBUG InteractionProtocol Received timed request from udp://10.75.1.101:5541 on session secure/59185
2023-2-4 9:3:4.391 DEBUG ExchangeManager sending id:59185/64213/1501414737 t:1/1 acked:47275425 reqAck:true payload: 1524000024ff0118
2023-2-4 9:3:4.397 DEBUG MessageExchange onMessageReceived id:59185/64213/47275426 t:1/8 acked:1501414737 reqAck:true payload: 1528002901360215370024000024013c2402001835012500840330016135e06164c1cb647dc54ec237acd00a1bf61073af8ddad74d17d98aafc006e6d204d852f28d948b2c7409fbe9f294c34c8fecbbef699d3d54e905e992b77b5bf2012b8fedcdec9cbfa8267a213871c45472ebe0dbfbf893eaf89ea4b62bdf2417032502060125038813300413534d415254484f4d455f50414b455f53414c5418181824ff0118
2023-2-4 9:3:4.397 DEBUG InteractionProtocol Received invoke request from udp://10.75.1.101:5541 on session secure/59185: 0x0/0x3c/0x0
2023-2-4 9:3:4.404 DEBUG ExchangeManager sending id:59185/64213/1501414738 t:1/9 acked:47275426 reqAck:true payload: 1528003601153500370024000024013c2402001835011818181824ff0118
**2023-2-4 9:3:4.405 ERROR MdnsBroadcaster Error: send EHOSTUNREACH ff02::fb:5353**
2023-2-4 9:3:4.417 DEBUG MessageExchange onMessageReceived id:59185/64213/47275427 t:0/16 acked:1501414738 reqAck:false payload: 

Resuming a Session the second time fails

I'm using the ControllerNode class to resume a session to an already paired node (Hue bridge ). The pairing works correctly, and the 1st time we resume, this works correctly as well. Unfortunately, after resuming the first time, the CaseClient receives the sigma2resume message in a incompatible format here:

const { sigma2Bytes, sigma2, sigma2Resume } = await messenger.readSigma2();

if i dump the sigma2resume message, it looks something like:

{"resumptionId":{"type":"Buffer","data":[161,2,101,132,250,185,175,4,185,69,179,75,60,143,34,190]},"resumeMic":{"type":"Buffer","data":[134,115,226,224,208,16,250,27,80,52,38,173,21,48,233,95]},"sessionId":18290}

I think the values should be Uint8Arrays, instead they look like raw Node.js Buffer objects. The client then persists these to storage, and the next time it goes to use them (so the second time we resume) we get a range error here when doing the ByteArray concat call:

const resumeKey = await Crypto.hkdf(sharedSecret, ByteArray.concat(random, resumptionId), KDFSR1_KEY_INFO);

I tried hunting this down for a bit, but I can't figure out why these raw buffer objects are returned, where everywhere else it seems to be fine?

Pure JS Crypto Implementation

Feedback appreciated!

Goals:

  • Move remaining matter.js tests from matter-node.js
  • Enable full functionality in non-node environments without proper crypto primitives.

Proposal:

  • Create new matter-crypto.js package parallel to matter.js. Keeps the hair out of matter.js
  • Move Crypto.ts into matter-crypto.ts or (b) make matter-crypto.ts a test-only dependency of matter.ts (which would be a bit circular so could get weird)
  • For completeness, move existing JS crypto dependencies of matter.js (BN and elliptic) to this package as well
  • Implement one of below options for pure-JS crypto. After writing up I lean toward option 2

Option 1: Implement Crypto interface using SJCL

Pros

  • SJCL appears mature
  • AFAICT the only pure-JS library that supports all primitives matter.js requires
  • Could ingest only the subset we need with a small custom build

Cons

  • NPM package includes a subset of functionality that doesn't meet our needs, so custom build would be required
  • Custom build is simple but requires make, java and perl. Not a reasonable dependency for our build, so SCJL.js should probably go in matter.js git as part of matter-crypto.js (along with scripts to recreate)
  • Would require writing new Crypto derivative. Doesn't look terrible but this would be the slow bit
  • Would require ongoing maintenance of two Crypto implementations

Option 2: Shim node's OpenSSL style wrappers

Pros

  • Can use existing implementation: crypto-browserify
  • Fast to implement
  • crypto-browserify is highly modular so we could import only the subset we need
  • Would only need to maintain single implementation
  • Shim can automatically bypass if native crypto is available
  • This implementation could support native crypto in non-Node environments. For example, if I were to create a React Native app I would probably use react-native-fast-crypto which... Emulates node's API by wrapping OpenSSL

Cons

  • Weird dependency for crypto-matter.js on "browserify" component or including subset of crypto-browserify in crypto-matter.js (attributed of course)
  • crypto-browserify doesn't support CCM mode. There's an old PR adding it but we'd need to fork or include patched files in matter.js repo

Option 3: Implement crypto using mix of 3rd party implementations

Pros

  • Could adopt best-in-class implementation of each required feature
  • Keeps dependencies relatively clean

Cons

  • Not clearly superior to previous options as we'd still need to import some of either SJCL or browserify-aes to get CCM mode
  • Some implementations not available in NPM so would require build steps and/or checking into matter.js git
  • Probably slowest in terms of research and implementation

Option 4: New implementation of crypto primitives in matter-crypto.ts

Ha ha, j/k

Trivial: ByteArray thoughts

Some quick ideas r.e. ByteArray.

  • Right now we monkeypatch Uint8Array, might be frowned upon by some library users
  • Could we make ByteArray a subclass of Uint8Array instead of an alias, and put utility functions there?
  • We could also add custom toString and toJSON methods so diagnostics like in #138 would show as hex rather than comma-separated decimal
  • I could also add the base64 utilities using the codec I made for the security stuff

SmartThings Pairing Issue

There is some timeout issue with SmartThings during pairing. Lots of activity on the console, but after about four minutes SmartThings gets some sort of timeout and gives an error of "something went wrong".

But the device is added and functional anyway.

Previously I would get a warning type message in the app that the device had not updated its status yet - try again later, and there would be a battery meter. Both of those issues are now gone. The device is functional, it's just kind of an awkward pairing.

Log attached

SmartThingsPairing.log

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.