@matter/protocol 0.16.9 → 0.16.10-alpha.0-20260219-28569004a

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 (84) hide show
  1. package/dist/cjs/action/client/ClientInteraction.d.ts.map +1 -1
  2. package/dist/cjs/action/client/ClientInteraction.js +11 -0
  3. package/dist/cjs/action/client/ClientInteraction.js.map +1 -1
  4. package/dist/cjs/certificate/kinds/Icac.d.ts.map +1 -1
  5. package/dist/cjs/certificate/kinds/Icac.js +7 -1
  6. package/dist/cjs/certificate/kinds/Icac.js.map +1 -1
  7. package/dist/cjs/certificate/kinds/definitions/operational.d.ts +1 -1
  8. package/dist/cjs/certificate/kinds/definitions/operational.js +1 -1
  9. package/dist/cjs/certificate/kinds/definitions/operational.js.map +1 -1
  10. package/dist/cjs/dcl/DclCertificateService.d.ts.map +1 -1
  11. package/dist/cjs/dcl/DclCertificateService.js +18 -2
  12. package/dist/cjs/dcl/DclCertificateService.js.map +1 -1
  13. package/dist/cjs/dcl/DclOtaUpdateService.d.ts +9 -4
  14. package/dist/cjs/dcl/DclOtaUpdateService.d.ts.map +1 -1
  15. package/dist/cjs/dcl/DclOtaUpdateService.js +126 -51
  16. package/dist/cjs/dcl/DclOtaUpdateService.js.map +2 -2
  17. package/dist/cjs/fabric/Fabric.d.ts.map +1 -1
  18. package/dist/cjs/fabric/Fabric.js +0 -11
  19. package/dist/cjs/fabric/Fabric.js.map +1 -1
  20. package/dist/cjs/mdns/MdnsClient.d.ts.map +1 -1
  21. package/dist/cjs/mdns/MdnsClient.js +1 -3
  22. package/dist/cjs/mdns/MdnsClient.js.map +1 -1
  23. package/dist/cjs/peer/PeerSet.d.ts.map +1 -1
  24. package/dist/cjs/peer/PeerSet.js +32 -23
  25. package/dist/cjs/peer/PeerSet.js.map +1 -1
  26. package/dist/cjs/protocol/MRP.d.ts +14 -1
  27. package/dist/cjs/protocol/MRP.d.ts.map +1 -1
  28. package/dist/cjs/protocol/MRP.js +16 -9
  29. package/dist/cjs/protocol/MRP.js.map +1 -1
  30. package/dist/cjs/protocol/MessageChannel.d.ts +3 -1
  31. package/dist/cjs/protocol/MessageChannel.d.ts.map +1 -1
  32. package/dist/cjs/protocol/MessageChannel.js +11 -6
  33. package/dist/cjs/protocol/MessageChannel.js.map +1 -1
  34. package/dist/cjs/protocol/MessageExchange.d.ts.map +1 -1
  35. package/dist/cjs/protocol/MessageExchange.js +7 -5
  36. package/dist/cjs/protocol/MessageExchange.js.map +1 -1
  37. package/dist/esm/action/client/ClientInteraction.d.ts.map +1 -1
  38. package/dist/esm/action/client/ClientInteraction.js +11 -0
  39. package/dist/esm/action/client/ClientInteraction.js.map +1 -1
  40. package/dist/esm/certificate/kinds/Icac.d.ts.map +1 -1
  41. package/dist/esm/certificate/kinds/Icac.js +7 -1
  42. package/dist/esm/certificate/kinds/Icac.js.map +1 -1
  43. package/dist/esm/certificate/kinds/definitions/operational.d.ts +1 -1
  44. package/dist/esm/certificate/kinds/definitions/operational.js +1 -1
  45. package/dist/esm/certificate/kinds/definitions/operational.js.map +1 -1
  46. package/dist/esm/dcl/DclCertificateService.d.ts.map +1 -1
  47. package/dist/esm/dcl/DclCertificateService.js +18 -2
  48. package/dist/esm/dcl/DclCertificateService.js.map +1 -1
  49. package/dist/esm/dcl/DclOtaUpdateService.d.ts +9 -4
  50. package/dist/esm/dcl/DclOtaUpdateService.d.ts.map +1 -1
  51. package/dist/esm/dcl/DclOtaUpdateService.js +126 -51
  52. package/dist/esm/dcl/DclOtaUpdateService.js.map +2 -2
  53. package/dist/esm/fabric/Fabric.d.ts.map +1 -1
  54. package/dist/esm/fabric/Fabric.js +0 -11
  55. package/dist/esm/fabric/Fabric.js.map +1 -1
  56. package/dist/esm/mdns/MdnsClient.d.ts.map +1 -1
  57. package/dist/esm/mdns/MdnsClient.js +1 -3
  58. package/dist/esm/mdns/MdnsClient.js.map +1 -1
  59. package/dist/esm/peer/PeerSet.d.ts.map +1 -1
  60. package/dist/esm/peer/PeerSet.js +32 -23
  61. package/dist/esm/peer/PeerSet.js.map +1 -1
  62. package/dist/esm/protocol/MRP.d.ts +14 -1
  63. package/dist/esm/protocol/MRP.d.ts.map +1 -1
  64. package/dist/esm/protocol/MRP.js +16 -9
  65. package/dist/esm/protocol/MRP.js.map +1 -1
  66. package/dist/esm/protocol/MessageChannel.d.ts +3 -1
  67. package/dist/esm/protocol/MessageChannel.d.ts.map +1 -1
  68. package/dist/esm/protocol/MessageChannel.js +11 -6
  69. package/dist/esm/protocol/MessageChannel.js.map +1 -1
  70. package/dist/esm/protocol/MessageExchange.d.ts.map +1 -1
  71. package/dist/esm/protocol/MessageExchange.js +7 -5
  72. package/dist/esm/protocol/MessageExchange.js.map +1 -1
  73. package/package.json +6 -6
  74. package/src/action/client/ClientInteraction.ts +13 -0
  75. package/src/certificate/kinds/Icac.ts +1 -4
  76. package/src/certificate/kinds/definitions/operational.ts +1 -1
  77. package/src/dcl/DclCertificateService.ts +21 -3
  78. package/src/dcl/DclOtaUpdateService.ts +171 -62
  79. package/src/fabric/Fabric.ts +0 -18
  80. package/src/mdns/MdnsClient.ts +1 -4
  81. package/src/peer/PeerSet.ts +38 -25
  82. package/src/protocol/MRP.ts +32 -8
  83. package/src/protocol/MessageChannel.ts +15 -6
  84. package/src/protocol/MessageExchange.ts +7 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matter/protocol",
3
- "version": "0.16.9",
3
+ "version": "0.16.10-alpha.0-20260219-28569004a",
4
4
  "description": "Low-level APIs for Matter interaction",
5
5
  "keywords": [
6
6
  "iot",
@@ -40,13 +40,13 @@
40
40
  "#*": "./src/*"
41
41
  },
42
42
  "dependencies": {
43
- "@matter/general": "0.16.9",
44
- "@matter/model": "0.16.9",
45
- "@matter/types": "0.16.9"
43
+ "@matter/general": "0.16.10-alpha.0-20260219-28569004a",
44
+ "@matter/model": "0.16.10-alpha.0-20260219-28569004a",
45
+ "@matter/types": "0.16.10-alpha.0-20260219-28569004a"
46
46
  },
47
47
  "devDependencies": {
48
- "@matter/tools": "0.16.9",
49
- "@matter/testing": "0.16.9"
48
+ "@matter/tools": "0.16.10-alpha.0-20260219-28569004a",
49
+ "@matter/testing": "0.16.10-alpha.0-20260219-28569004a"
50
50
  },
51
51
  "files": [
52
52
  "dist/**/*",
@@ -373,6 +373,19 @@ export class ClientInteraction<
373
373
  status,
374
374
  clusterStatus,
375
375
  };
376
+
377
+ const cmd = request.commands.get(commandRef);
378
+ if (cmd) {
379
+ logger.info(
380
+ "Invoke",
381
+ Mark.INBOUND,
382
+ messenger.exchange.via,
383
+ messenger.exchange.diagnostics,
384
+ Diagnostic.strong(resolvePathForSpecifier(cmd)),
385
+ Diagnostic.dict({ status: `${Status[status]} (${status})`, clusterStatus }),
386
+ );
387
+ }
388
+
376
389
  return res;
377
390
  } else {
378
391
  // Should not happen but if we ignore the response?
@@ -59,7 +59,7 @@ export class Icac extends OperationalBase<OperationalCertificate.Icac> {
59
59
  issuer: { rcacId },
60
60
  extensions,
61
61
  } = this.cert;
62
- const { fabricId } = subject;
62
+ const { fabricId, icacId } = subject;
63
63
  const { basicConstraints, extendedKeyUsage, subjectKeyIdentifier, authorityKeyIdentifier } = extensions;
64
64
 
65
65
  const { fabricId: rootFabricId } = root.cert.subject;
@@ -79,8 +79,6 @@ export class Icac extends OperationalBase<OperationalCertificate.Icac> {
79
79
  }
80
80
  }
81
81
 
82
- // Ikea Dirigera hub provided an invalid ICAC, so disable these checks for now because also SDK seems to not check it
83
- /*
84
82
  // The subject DN SHALL encode exactly one matter-icac-id attribute.
85
83
  if (icacId === undefined || Array.isArray(icacId)) {
86
84
  throw new CertificateError(`Invalid icacId in Ica certificate: ${Diagnostic.json(icacId)}`);
@@ -90,7 +88,6 @@ export class Icac extends OperationalBase<OperationalCertificate.Icac> {
90
88
  if ("rcacId" in subject) {
91
89
  throw new CertificateError(`Ica certificate must not contain an rcacId.`);
92
90
  }
93
- */
94
91
 
95
92
  // The subject DN SHALL NOT encode any matter-noc-cat attribute.
96
93
  if ("caseAuthenticatedTags" in subject) {
@@ -167,7 +167,7 @@ export namespace OperationalCertificate {
167
167
 
168
168
  export const TlvIcac = BaseMatterCertificate({
169
169
  subject: {
170
- icacId: TlvOptionalField(19, TlvUInt64),
170
+ icacId: TlvField(19, TlvUInt64),
171
171
  fabricId: TlvOptionalField(21, TlvFabricId),
172
172
  },
173
173
  issuer: AllowedSubjectAndIssuerMatterFields,
@@ -324,10 +324,9 @@ export class DclCertificateService {
324
324
  return;
325
325
  }
326
326
 
327
- // Store the index if anything changed
327
+ await this.#saveIndex();
328
328
  const newCerts = this.#certificateIndex.size - initialSize;
329
329
  if (newCerts > 0) {
330
- await this.#saveIndex();
331
330
  logger.info(`Downloaded and stored ${newCerts} new certificates (total: ${this.#certificateIndex.size})`);
332
331
  } else {
333
332
  logger.info(`All certificates up to date (${this.#certificateIndex.size} total)`);
@@ -378,7 +377,20 @@ export class DclCertificateService {
378
377
 
379
378
  // Check if certificate already exists before fetching details (skip check if force is true)
380
379
  if (!force && this.#certificateIndex.has(normalizedSubjectKeyId)) {
381
- logger.debug(`Certificate already exists, skipping`, Diagnostic.dict({ skid: normalizedSubjectKeyId }));
380
+ // If the existing certificate was stored as test but is now found in production DCL, upgrade it
381
+ const existing = this.#certificateIndex.get(normalizedSubjectKeyId)!;
382
+ if (isProduction && !existing.isProduction) {
383
+ existing.isProduction = true;
384
+ logger.debug(
385
+ `Upgraded certificate to production`,
386
+ Diagnostic.dict({ skid: normalizedSubjectKeyId }),
387
+ );
388
+ } else {
389
+ logger.debug(
390
+ `Certificate already exists, skipping`,
391
+ Diagnostic.dict({ skid: normalizedSubjectKeyId }),
392
+ );
393
+ }
382
394
  return;
383
395
  }
384
396
 
@@ -495,6 +507,12 @@ export class DclCertificateService {
495
507
  derBytes: Bytes,
496
508
  metadata: DclCertificateService.CertificateMetadata,
497
509
  ) {
510
+ // Never downgrade isProduction from true to false
511
+ const existing = this.#certificateIndex.get(subjectKeyId);
512
+ if (existing?.isProduction && !metadata.isProduction) {
513
+ metadata = { ...metadata, isProduction: true };
514
+ }
515
+
498
516
  // Store the DER certificate
499
517
  await storage.set(subjectKeyId, derBytes);
500
518
 
@@ -38,6 +38,8 @@ export class OtaUpdateError extends MatterError {
38
38
 
39
39
  export type OtaUpdateSource = "local" | "dcl-prod" | "dcl-test";
40
40
 
41
+ export type OtaStorageMode = "prod" | "test" | "local";
42
+
41
43
  export interface DeviceSoftwareVersionModelDclSchemaWithSource extends DeviceSoftwareVersionModelDclSchema {
42
44
  source: OtaUpdateSource;
43
45
  }
@@ -50,7 +52,7 @@ export type OtaUpdateInfo = DeviceSoftwareVersionModelDclSchemaWithSource;
50
52
 
51
53
  const OTA_DOWNLOAD_TIMEOUT = Minutes(5);
52
54
 
53
- const OTA_FILENAME_REGEX = /^[0-9a-f]+[./][0-9a-f]+[./](?:prod|test)$/i;
55
+ const OTA_FILENAME_REGEX = /^[0-9a-f]+[./][0-9a-f]+[./](?:prod|test|local)[./]\d+$/i;
54
56
 
55
57
  /**
56
58
  * Service to query and manage OTA updates from the Distributed Compliance Ledger (DCL), but also allows to inject own
@@ -78,6 +80,7 @@ export class DclOtaUpdateService {
78
80
  this.#construction = Construction(this, async () => {
79
81
  this.#storageManager = await environment.get(StorageService).open("ota");
80
82
  this.#storage = new ScopedStorage(this.#storageManager.createContext("bin"), "ota");
83
+ await this.#migrateStorage();
81
84
  });
82
85
  }
83
86
 
@@ -94,6 +97,56 @@ export class DclOtaUpdateService {
94
97
  await this.#storageManager?.close();
95
98
  }
96
99
 
100
+ async #migrateStorage() {
101
+ const storage = this.#storage!;
102
+ const context = storage.context;
103
+
104
+ for (const vendorHex of await context.contexts()) {
105
+ const vendorContext = context.createContext(vendorHex);
106
+ for (const productHex of await vendorContext.contexts()) {
107
+ const productContext = vendorContext.createContext(productHex);
108
+ const keys = await productContext.keys();
109
+
110
+ for (const key of keys) {
111
+ if (key !== "prod" && key !== "test") {
112
+ continue; // Not an old-format key
113
+ }
114
+
115
+ try {
116
+ // Read the old file header to extract the software version
117
+ const headerBlob = await productContext.openBlob(key);
118
+ const headerReader = headerBlob.stream().getReader();
119
+ const header = await OtaImageReader.header(headerReader);
120
+ await headerReader.cancel();
121
+ const versionKey = header.softwareVersion.toString();
122
+
123
+ // Copy to new location: mode sub-context + version key
124
+ const modeContext = productContext.createContext(key);
125
+ const copyBlob = await productContext.openBlob(key);
126
+ await modeContext.writeBlobFromStream(versionKey, copyBlob.stream());
127
+
128
+ // Delete old bare key
129
+ await productContext.delete(key);
130
+
131
+ logger.info(
132
+ `Migrated OTA storage: ${vendorHex}.${productHex}.${key} -> ${vendorHex}.${productHex}.${key}.${versionKey}`,
133
+ );
134
+ } catch (error) {
135
+ logger.warn(
136
+ `Failed to migrate OTA file ${vendorHex}.${productHex}.${key}, deleting corrupt entry:`,
137
+ error,
138
+ );
139
+ try {
140
+ await productContext.delete(key);
141
+ } catch {
142
+ // Ignore cleanup errors
143
+ }
144
+ }
145
+ }
146
+ }
147
+ }
148
+ }
149
+
97
150
  async #queryDclForUpdate(options: {
98
151
  vendorId: number;
99
152
  productId: number;
@@ -211,26 +264,27 @@ export class DclOtaUpdateService {
211
264
 
212
265
  const foundUpdates = new Array<DeviceSoftwareVersionModelDclSchemaWithSource>();
213
266
 
214
- // Check for local updates if allowed
267
+ // Check for local updates if allowed — search all modes regardless of isProduction
268
+ // (isProduction controls which DCL to query, not which stored files to consider)
215
269
  if (includeStoredUpdates) {
216
270
  const localUpdates = await this.find({
217
271
  vendorId,
218
272
  productId,
219
- isProduction,
220
273
  currentVersion: currentSoftwareVersion,
221
274
  });
222
- if (localUpdates.length) {
275
+ // Check each stored entry for applicability (highest version first via reverse iteration)
276
+ for (let i = localUpdates.length - 1; i >= 0; i--) {
277
+ const entry = localUpdates[i];
223
278
  const localUpdate: DeviceSoftwareVersionModelDclSchemaWithSource = {
224
- ...localUpdates[0],
279
+ ...entry,
225
280
  vid: VendorId(vendorId),
226
281
  pid: productId,
227
282
  cdVersionNumber: 0,
228
283
  softwareVersionValid: true,
229
284
  schemaVersion: 1,
230
- minApplicableSoftwareVersion: localUpdates[0].minApplicableSoftwareVersion ?? 0,
231
- maxApplicableSoftwareVersion:
232
- localUpdates[0].maxApplicableSoftwareVersion ?? localUpdates[0].softwareVersion - 1,
233
- source: localUpdates[0].mode === "prod" ? "dcl-prod" : "local",
285
+ minApplicableSoftwareVersion: entry.minApplicableSoftwareVersion ?? 0,
286
+ maxApplicableSoftwareVersion: entry.maxApplicableSoftwareVersion ?? entry.softwareVersion - 1,
287
+ source: entry.mode === "prod" ? "dcl-prod" : entry.mode === "test" ? "dcl-test" : "local",
234
288
  };
235
289
  if (
236
290
  localUpdate.softwareVersion > currentSoftwareVersion &&
@@ -319,23 +373,31 @@ export class DclOtaUpdateService {
319
373
  }
320
374
  }
321
375
 
322
- #fileName(vid: number, pid: number, isProduction: boolean) {
323
- return `${vid.toString(16)}.${pid.toString(16)}.${isProduction ? "prod" : "test"}`;
376
+ #fileName(vid: number, pid: number, mode: OtaStorageMode, softwareVersion: number) {
377
+ return `${vid.toString(16)}.${pid.toString(16)}.${mode}.${softwareVersion}`;
324
378
  }
325
379
 
326
380
  /**
327
381
  * Store an OTA update image from a ReadableStream into persistent storage.
328
382
  */
329
- async store(stream: ReadableStream<Uint8Array>, updateInfo: OtaUpdateInfo, isProduction = true) {
383
+ async store(
384
+ stream: ReadableStream<Uint8Array>,
385
+ updateInfo: OtaUpdateInfo,
386
+ // TODO: Change default to "local" on next breaking release
387
+ mode: boolean | OtaStorageMode = true,
388
+ ) {
330
389
  if (this.#storage === undefined) {
331
390
  await this.construction;
332
391
  }
333
392
  const storage = this.#storage!;
334
393
 
394
+ if (typeof mode === "boolean") {
395
+ mode = mode ? "prod" : "test";
396
+ }
397
+
335
398
  const { softwareVersion, softwareVersionString, vid, pid } = updateInfo;
336
399
 
337
- // Generate filename with production/test indicator (version not included as we always use latest)
338
- const filename = this.#fileName(vid, pid, isProduction);
400
+ const filename = this.#fileName(vid, pid, mode, softwareVersion);
339
401
  const fileDesignator = new PersistedFileDesignator(filename, storage);
340
402
 
341
403
  const diagnosticInfo = {
@@ -343,7 +405,7 @@ export class DclOtaUpdateService {
343
405
  vid,
344
406
  pid,
345
407
  v: `${softwareVersion} (${softwareVersionString})`,
346
- prod: isProduction,
408
+ mode,
347
409
  };
348
410
 
349
411
  try {
@@ -384,17 +446,16 @@ export class DclOtaUpdateService {
384
446
  const storage = this.#storage!;
385
447
 
386
448
  const { otaUrl, softwareVersion, softwareVersionString, vid, pid, source } = updateInfo;
387
- const isProduction = source === "dcl-prod";
449
+ const mode: OtaStorageMode = source === "dcl-prod" ? "prod" : source === "dcl-test" ? "test" : "local";
388
450
 
389
451
  const diagnosticInfo = {
390
452
  vid,
391
453
  pid,
392
454
  v: `${softwareVersion} (${softwareVersionString})`,
393
- prod: isProduction,
455
+ mode,
394
456
  };
395
457
 
396
- // Generate filename with production/test indicator (a version not included as we always use latest)
397
- const filename = this.#fileName(vid, pid, isProduction);
458
+ const filename = this.#fileName(vid, pid, mode, softwareVersion);
398
459
  const fileDesignator = new PersistedFileDesignator(filename, storage);
399
460
 
400
461
  if (await fileDesignator.exists()) {
@@ -448,7 +509,7 @@ export class DclOtaUpdateService {
448
509
  throw new OtaUpdateError("No response body received");
449
510
  }
450
511
 
451
- return await this.store(response.body, updateInfo, isProduction);
512
+ return await this.store(response.body, updateInfo, mode);
452
513
  } catch (error) {
453
514
  MatterError.reject(error);
454
515
  const otaError = new OtaUpdateError(`Failed to download OTA image from ${otaUrl}`);
@@ -712,8 +773,10 @@ export class DclOtaUpdateService {
712
773
  const results = await this.#findEntries(this.#storage!.context, options);
713
774
 
714
775
  // Sort by vendor ID, product ID, mode, and version
776
+ const modeOrder: Record<string, number> = { prod: 0, test: 1, local: 2 };
715
777
  results.sort((a, b) => {
716
- if (a.mode !== b.mode) return a.mode === "prod" ? -1 : 1;
778
+ const modeDiff = (modeOrder[a.mode] ?? 99) - (modeOrder[b.mode] ?? 99);
779
+ if (modeDiff !== 0) return modeDiff;
717
780
  if (a.vendorId !== b.vendorId) return a.vendorId - b.vendorId;
718
781
  if (a.productId !== b.productId) return a.productId - b.productId;
719
782
  return a.softwareVersion - b.softwareVersion;
@@ -732,7 +795,7 @@ export class DclOtaUpdateService {
732
795
  return vendorEntries.map(entry => ({
733
796
  ...entry,
734
797
  vendorId,
735
- filename: this.#fileName(vendorId, entry.productId, entry.mode === "prod"),
798
+ filename: this.#fileName(vendorId, entry.productId, entry.mode, entry.softwareVersion),
736
799
  }));
737
800
  }
738
801
 
@@ -745,7 +808,7 @@ export class DclOtaUpdateService {
745
808
  ...vendorEntries.map(entry => ({
746
809
  ...entry,
747
810
  vendorId,
748
- filename: this.#fileName(vendorId, entry.productId, entry.mode === "prod"),
811
+ filename: this.#fileName(vendorId, entry.productId, entry.mode, entry.softwareVersion),
749
812
  })),
750
813
  );
751
814
  }
@@ -779,26 +842,41 @@ export class DclOtaUpdateService {
779
842
  }
780
843
 
781
844
  async #findVendorProductEntries(productContext: StorageContext, options: DclOtaUpdateService.FindOptions) {
782
- const { isProduction } = options;
845
+ const { isProduction, mode: filterMode } = options;
783
846
 
784
847
  const result = new Array<Omit<DclOtaUpdateService.OtaUpdateListEntry, "vendorId" | "productId" | "filename">>();
785
848
 
786
- if (isProduction !== false && (await productContext.has("prod"))) {
787
- const prodResult = await this.#checkEntry(new PersistedFileDesignator("prod", productContext), options);
788
- if (prodResult !== undefined) {
789
- result.push({
790
- ...prodResult,
791
- mode: "prod",
792
- });
849
+ // New format: enumerate mode sub-contexts
850
+ const modeContexts = await productContext.contexts();
851
+ const validModes: OtaStorageMode[] = ["prod", "test", "local"];
852
+
853
+ for (const modeStr of modeContexts) {
854
+ if (!validModes.includes(modeStr as OtaStorageMode)) {
855
+ continue;
793
856
  }
794
- }
795
- if (isProduction !== true && (await productContext.has("test"))) {
796
- const testResult = await this.#checkEntry(new PersistedFileDesignator("test", productContext), options);
797
- if (testResult !== undefined) {
798
- result.push({
799
- ...testResult,
800
- mode: "test",
801
- });
857
+ const mode = modeStr as OtaStorageMode;
858
+
859
+ // Apply mode/isProduction filters
860
+ if (filterMode !== undefined && filterMode !== mode) {
861
+ continue;
862
+ }
863
+ if (filterMode === undefined && isProduction !== undefined) {
864
+ if (isProduction === true && mode !== "prod") continue;
865
+ if (isProduction === false && mode === "prod") continue;
866
+ }
867
+
868
+ const modeContext = productContext.createContext(modeStr);
869
+ const versionKeys = await modeContext.keys();
870
+
871
+ for (const versionKey of versionKeys) {
872
+ const fileDesignator = new PersistedFileDesignator(versionKey, modeContext);
873
+ const entry = await this.#checkEntry(fileDesignator, options);
874
+ if (entry !== undefined) {
875
+ result.push({
876
+ ...entry,
877
+ mode,
878
+ });
879
+ }
802
880
  }
803
881
  }
804
882
 
@@ -810,8 +888,8 @@ export class DclOtaUpdateService {
810
888
  // Read header to get software version and size
811
889
  const blob = await fileDesignator.openBlob();
812
890
  const reader = blob.stream().getReader();
813
-
814
891
  const header = await OtaImageReader.header(reader);
892
+ await reader.cancel();
815
893
 
816
894
  const { currentVersion } = options;
817
895
  if (currentVersion !== undefined) {
@@ -868,27 +946,36 @@ export class DclOtaUpdateService {
868
946
  * If only vendor ID is provided (no product ID), all files for that vendor are deleted.
869
947
  *
870
948
  * @param options - Deletion criteria
871
- * @param options.filename - Specific filename to delete
949
+ * @param options.filename - Specific filename to delete (e.g. `fff1.8000.prod.3`)
872
950
  * @param options.vendorId - Vendor ID to filter files for deletion
873
951
  * @param options.productId - Product ID to filter files for deletion (optional, requires vendorId)
874
- * @param options.isProduction - Production (true) or test (false) mode (defaults to true)
952
+ * @param options.isProduction - @deprecated Use mode instead. Production (true) or test (false) mode
953
+ * @param options.mode - Storage mode: "prod", "test", or "local"
875
954
  * @returns Number of files deleted
876
955
  */
877
- async delete(options: { filename?: string; vendorId?: number; productId?: number; isProduction?: boolean }) {
956
+ async delete(options: {
957
+ filename?: string;
958
+ vendorId?: number;
959
+ productId?: number;
960
+ /** @deprecated Use mode instead */
961
+ isProduction?: boolean;
962
+ mode?: OtaStorageMode;
963
+ }) {
878
964
  if (this.#storage === undefined) {
879
965
  await this.construction;
880
966
  }
881
967
  const storage = this.#storage!;
882
968
 
883
969
  const { vendorId, productId, isProduction } = options;
884
- let { filename } = options;
970
+ let { filename, mode } = options;
885
971
 
886
- if (filename == undefined && vendorId !== undefined && productId !== undefined && isProduction !== undefined) {
887
- filename = this.#fileName(vendorId, productId, isProduction);
972
+ // Backward compat: derive mode from boolean
973
+ if (mode === undefined && isProduction !== undefined) {
974
+ mode = isProduction ? "prod" : "test";
888
975
  }
889
976
 
890
977
  if (filename !== undefined) {
891
- // Delete a specific file by name
978
+ // Delete a specific file by name — fileDesignatorForUpdate expects the new filename format with a version suffix
892
979
  try {
893
980
  const fileDesignator = await this.fileDesignatorForUpdate(filename);
894
981
  await fileDesignator.delete();
@@ -901,27 +988,48 @@ export class DclOtaUpdateService {
901
988
  return 1;
902
989
  }
903
990
 
991
+ if (vendorId !== undefined && productId !== undefined && mode !== undefined) {
992
+ // Delete all versions for this vid/pid/mode
993
+ const vendorHex = vendorId.toString(16);
994
+ const productHex = productId.toString(16);
995
+ const modeContext = storage.context.createContext(vendorHex).createContext(productHex).createContext(mode);
996
+ const versionKeys = await modeContext.keys();
997
+ let deletedCount = 0;
998
+ for (const versionKey of versionKeys) {
999
+ const fd = new PersistedFileDesignator(versionKey, modeContext);
1000
+ await fd.delete();
1001
+ deletedCount++;
1002
+ }
1003
+ if (deletedCount > 0) {
1004
+ logger.info(`Deleted ${deletedCount} OTA file(s) for ${vendorHex}.${productHex}.${mode}`);
1005
+ }
1006
+ return deletedCount;
1007
+ }
1008
+
904
1009
  if (vendorId === undefined) {
905
1010
  throw new OtaUpdateError("Either filename or vendorId must be provided to delete files");
906
1011
  }
907
1012
 
908
- // Delete all files for the vendor with the specified mode
1013
+ // Delete all files for the vendor, optionally filtered by mode
909
1014
  const vendorHex = vendorId.toString(16);
910
-
911
1015
  const vendorStorage = storage.context.createContext(vendorHex);
912
1016
  let deletedCount = 0;
913
-
914
- for (const key of await vendorStorage.contexts()) {
915
- const prodStorage = vendorStorage.createContext(key);
916
- if (isProduction !== false && (await prodStorage.has("prod"))) {
917
- const fileDesignator = new PersistedFileDesignator("prod", prodStorage);
918
- await fileDesignator.delete();
919
- deletedCount++;
920
- }
921
- if (isProduction !== true && (await prodStorage.has("test"))) {
922
- const fileDesignator = new PersistedFileDesignator("test", prodStorage);
923
- await fileDesignator.delete();
924
- deletedCount++;
1017
+ const validModes: OtaStorageMode[] = ["prod", "test", "local"];
1018
+ const modesToDelete = mode !== undefined ? [mode] : validModes;
1019
+
1020
+ for (const productKey of await vendorStorage.contexts()) {
1021
+ const productContext = vendorStorage.createContext(productKey);
1022
+ const modeSubContexts = await productContext.contexts();
1023
+
1024
+ for (const modeStr of modesToDelete) {
1025
+ if (modeSubContexts.includes(modeStr)) {
1026
+ const modeContext = productContext.createContext(modeStr);
1027
+ for (const versionKey of await modeContext.keys()) {
1028
+ const fd = new PersistedFileDesignator(versionKey, modeContext);
1029
+ await fd.delete();
1030
+ deletedCount++;
1031
+ }
1032
+ }
925
1033
  }
926
1034
  }
927
1035
 
@@ -938,7 +1046,7 @@ export namespace DclOtaUpdateService {
938
1046
  softwareVersionString: string;
939
1047
  minApplicableSoftwareVersion?: number;
940
1048
  maxApplicableSoftwareVersion?: number;
941
- mode: "prod" | "test";
1049
+ mode: OtaStorageMode;
942
1050
  size: number;
943
1051
  };
944
1052
 
@@ -946,6 +1054,7 @@ export namespace DclOtaUpdateService {
946
1054
  vendorId?: number;
947
1055
  productId?: number;
948
1056
  isProduction?: boolean;
1057
+ mode?: OtaStorageMode;
949
1058
  currentVersion?: number;
950
1059
  }
951
1060
  }
@@ -295,17 +295,6 @@ export class Fabric {
295
295
  }
296
296
 
297
297
  async verifyCredentials(operationalCert: Bytes, intermediateCACert?: Bytes) {
298
- if (intermediateCACert !== undefined && intermediateCACert.byteLength === 0) {
299
- intermediateCACert = undefined;
300
- }
301
-
302
- // Workaround for an issue with the Ikea hub where the root certificate was also provided as ICAC
303
- // see https://github.com/project-chip/connectedhomeip/issues/42479
304
- if (intermediateCACert !== undefined && Bytes.areEqual(this.rootCert, intermediateCACert)) {
305
- logger.info("Intermediate CA certificate is identical to root certificate; omitting ICAC");
306
- intermediateCACert = undefined;
307
- }
308
-
309
298
  const rootCert = Rcac.fromTlv(this.rootCert);
310
299
  const nocCert = Noc.fromTlv(operationalCert);
311
300
  const icaCert = intermediateCACert !== undefined ? Icac.fromTlv(intermediateCACert) : undefined;
@@ -524,13 +513,6 @@ export class FabricBuilder {
524
513
  throw new MatterFlowError("Root certificate needs to be set first");
525
514
  }
526
515
 
527
- // Workaround for an issue with the Ikea hub where the root certificate was also provided as ICAC
528
- // see https://github.com/project-chip/connectedhomeip/issues/42479
529
- if (intermediateCACert !== undefined && Bytes.areEqual(this.#rootCert, intermediateCACert)) {
530
- logger.info("Intermediate CA certificate is identical to root certificate; omitting ICAC");
531
- intermediateCACert = undefined;
532
- }
533
-
534
516
  const rootCert = Rcac.fromTlv(this.#rootCert);
535
517
  const nocCert = Noc.fromTlv(operationalCert);
536
518
  const icaCert = intermediateCACert !== undefined ? Icac.fromTlv(intermediateCACert) : undefined;
@@ -863,10 +863,7 @@ export class MdnsClient implements Scanner {
863
863
  cancelSignal?.then(
864
864
  () => {
865
865
  canceled = true;
866
- if (queryResolver === undefined) {
867
- // Always finish when the cancelSignal parameter was used, else cancelling is done separately
868
- this.#finishWaiter(queryId, true);
869
- }
866
+ this.#finishWaiter(queryId, true);
870
867
  },
871
868
  cause => {
872
869
  logger.warn("Unexpected error canceling commissioning", cause);