@riddix/hamh 2.1.0-alpha.493 → 2.1.0-alpha.494

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.
@@ -9825,12 +9825,12 @@ var init_StandardCrypto = __esm({
9825
9825
  implementationName = "JS";
9826
9826
  #crypto;
9827
9827
  #subtle;
9828
- constructor(crypto7 = globalThis.crypto) {
9829
- const { subtle } = crypto7;
9830
- assertInterface("crypto", crypto7, requiredCryptoMethods);
9828
+ constructor(crypto8 = globalThis.crypto) {
9829
+ const { subtle } = crypto8;
9830
+ assertInterface("crypto", crypto8, requiredCryptoMethods);
9831
9831
  assertInterface("crypto.subtle", subtle, requiredSubtleMethods);
9832
9832
  super();
9833
- this.#crypto = crypto7;
9833
+ this.#crypto = crypto8;
9834
9834
  this.#subtle = subtle;
9835
9835
  }
9836
9836
  get subtle() {
@@ -10013,9 +10013,9 @@ var init_StandardCrypto = __esm({
10013
10013
  }
10014
10014
  };
10015
10015
  if ("crypto" in globalThis && globalThis.crypto?.subtle) {
10016
- const crypto7 = new StandardCrypto();
10017
- Environment.default.set(Entropy, crypto7);
10018
- Environment.default.set(Crypto, crypto7);
10016
+ const crypto8 = new StandardCrypto();
10017
+ Environment.default.set(Entropy, crypto8);
10018
+ Environment.default.set(Crypto, crypto8);
10019
10019
  }
10020
10020
  }
10021
10021
  });
@@ -10025,9 +10025,9 @@ function MockCrypto(index = 128, implementation = StandardCrypto) {
10025
10025
  if (index < 0 || index > 255) {
10026
10026
  throw new ImplementationError(`Index for stable crypto must be 0-255`);
10027
10027
  }
10028
- const crypto7 = new implementation();
10029
- const { randomBytes: randomBytes2, createKeyPair } = crypto7;
10030
- Object.defineProperties(crypto7, {
10028
+ const crypto8 = new implementation();
10029
+ const { randomBytes: randomBytes2, createKeyPair } = crypto8;
10030
+ Object.defineProperties(crypto8, {
10031
10031
  index: {
10032
10032
  get() {
10033
10033
  return index;
@@ -10038,12 +10038,12 @@ function MockCrypto(index = 128, implementation = StandardCrypto) {
10038
10038
  },
10039
10039
  entropic: {
10040
10040
  get() {
10041
- return crypto7.randomBytes === randomBytes2;
10041
+ return crypto8.randomBytes === randomBytes2;
10042
10042
  },
10043
10043
  set(entropic) {
10044
10044
  if (entropic) {
10045
- crypto7.randomBytes = randomBytes2;
10046
- crypto7.createKeyPair = createKeyPair;
10045
+ crypto8.randomBytes = randomBytes2;
10046
+ crypto8.createKeyPair = createKeyPair;
10047
10047
  } else {
10048
10048
  disableEntropy();
10049
10049
  }
@@ -10051,15 +10051,15 @@ function MockCrypto(index = 128, implementation = StandardCrypto) {
10051
10051
  }
10052
10052
  });
10053
10053
  disableEntropy();
10054
- return crypto7;
10054
+ return crypto8;
10055
10055
  function disableEntropy() {
10056
- crypto7.randomBytes = function getRandomDataNONENTROPIC(length) {
10056
+ crypto8.randomBytes = function getRandomDataNONENTROPIC(length) {
10057
10057
  const result = new Uint8Array(length);
10058
10058
  result.fill(index);
10059
10059
  return result;
10060
10060
  };
10061
- crypto7.createKeyPair = function getRandomDataNONENTROPIC() {
10062
- const privateBits = ec.mapHashToField(Bytes.of(crypto7.randomBytes(48)), ec.p256.Point.CURVE().n);
10061
+ crypto8.createKeyPair = function getRandomDataNONENTROPIC() {
10062
+ const privateBits = ec.mapHashToField(Bytes.of(crypto8.randomBytes(48)), ec.p256.Point.CURVE().n);
10063
10063
  return Key({
10064
10064
  kty: KeyType.EC,
10065
10065
  crv: CurveType.p256,
@@ -10092,9 +10092,9 @@ var init_NodeJsStyleCrypto = __esm({
10092
10092
  NodeJsStyleCrypto = class extends Crypto {
10093
10093
  implementationName = "Node.js";
10094
10094
  #crypto;
10095
- constructor(crypto7) {
10095
+ constructor(crypto8) {
10096
10096
  super();
10097
- this.#crypto = crypto7;
10097
+ this.#crypto = crypto8;
10098
10098
  }
10099
10099
  encrypt(key, data, nonce, aad) {
10100
10100
  const cipher = this.#crypto.createCipheriv(CRYPTO_ENCRYPT_ALGORITHM, Bytes.of(key), Bytes.of(nonce), {
@@ -10368,29 +10368,29 @@ var init_Spake2p = __esm({
10368
10368
  #context;
10369
10369
  #random;
10370
10370
  #w0;
10371
- static async computeW0W1(crypto7, { iterations, salt }, pin) {
10371
+ static async computeW0W1(crypto8, { iterations, salt }, pin) {
10372
10372
  const pinWriter = new DataWriter(Endian.Little);
10373
10373
  pinWriter.writeUInt32(pin);
10374
10374
  const ws2 = Bytes.of(
10375
- await crypto7.createPbkdf2Key(pinWriter.toByteArray(), salt, iterations, CRYPTO_W_SIZE_BYTES * 2)
10375
+ await crypto8.createPbkdf2Key(pinWriter.toByteArray(), salt, iterations, CRYPTO_W_SIZE_BYTES * 2)
10376
10376
  );
10377
10377
  const curve = Point2.CURVE();
10378
10378
  const w0 = mod2(bytesToNumberBE(ws2.slice(0, 40)), curve.n);
10379
10379
  const w1 = mod2(bytesToNumberBE(ws2.slice(40, 80)), curve.n);
10380
10380
  return { w0, w1 };
10381
10381
  }
10382
- static async computeW0L(crypto7, pbkdfParameters, pin) {
10383
- const { w0, w1 } = await this.computeW0W1(crypto7, pbkdfParameters, pin);
10382
+ static async computeW0L(crypto8, pbkdfParameters, pin) {
10383
+ const { w0, w1 } = await this.computeW0W1(crypto8, pbkdfParameters, pin);
10384
10384
  const L = Point2.BASE.multiply(w1).toBytes(false);
10385
10385
  return { w0, L };
10386
10386
  }
10387
- static create(crypto7, context, w0) {
10387
+ static create(crypto8, context, w0) {
10388
10388
  const curve = Point2.CURVE();
10389
- const random = crypto7.randomBigInt(32, curve.p);
10390
- return new _Spake2p(crypto7, context, random, w0);
10389
+ const random = crypto8.randomBigInt(32, curve.p);
10390
+ return new _Spake2p(crypto8, context, random, w0);
10391
10391
  }
10392
- constructor(crypto7, context, random, w0) {
10393
- this.#crypto = crypto7;
10392
+ constructor(crypto8, context, random, w0) {
10393
+ this.#crypto = crypto8;
10394
10394
  this.#context = context;
10395
10395
  this.#random = random;
10396
10396
  this.#w0 = w0;
@@ -10521,10 +10521,10 @@ var init_X509 = __esm({
10521
10521
  init_Pem();
10522
10522
  init_X962();
10523
10523
  ((X5092) => {
10524
- async function sign(crypto7, key, cert) {
10524
+ async function sign(crypto8, key, cert) {
10525
10525
  return {
10526
10526
  ...cert,
10527
- signature: (await crypto7.signEcdsa(key, certificateToDer(cert))).der
10527
+ signature: (await crypto8.signEcdsa(key, certificateToDer(cert))).der
10528
10528
  };
10529
10529
  }
10530
10530
  X5092.sign = sign;
@@ -46460,9 +46460,9 @@ var init_NodeId = __esm({
46460
46460
  return hex.fixed(nodeId3, 16);
46461
46461
  }
46462
46462
  NodeId2.strOf = strOf;
46463
- NodeId2.randomOperationalNodeId = (crypto7) => {
46463
+ NodeId2.randomOperationalNodeId = (crypto8) => {
46464
46464
  while (true) {
46465
- const randomBigInt = crypto7.randomBigInt(8);
46465
+ const randomBigInt = crypto8.randomBigInt(8);
46466
46466
  if (randomBigInt >= OPERATIONAL_NODE_MIN && randomBigInt <= OPERATIONAL_NODE_MAX) {
46467
46467
  return NodeId2(randomBigInt);
46468
46468
  }
@@ -88338,11 +88338,11 @@ var init_GlobalFabricId = __esm({
88338
88338
  return hex.fixed(id, 16);
88339
88339
  }
88340
88340
  GlobalFabricId2.strOf = strOf;
88341
- async function compute(crypto7, id, caKey) {
88341
+ async function compute(crypto8, id, caKey) {
88342
88342
  const saltWriter = new DataWriter();
88343
88343
  saltWriter.writeUInt64(id);
88344
88344
  return GlobalFabricId2(
88345
- await crypto7.createHkdfKey(
88345
+ await crypto8.createHkdfKey(
88346
88346
  Bytes.of(caKey).slice(1),
88347
88347
  saltWriter.toByteArray(),
88348
88348
  COMPRESSED_FABRIC_ID_INFO,
@@ -90621,8 +90621,8 @@ var init_Certificate = __esm({
90621
90621
  * Sign the certificate using the provided crypto and key.
90622
90622
  * It throws a CertificateError if the certificate is already signed.
90623
90623
  */
90624
- async sign(crypto7, key) {
90625
- this.signature = await crypto7.signEcdsa(key, this.asUnsignedDer());
90624
+ async sign(crypto8, key) {
90625
+ this.signature = await crypto8.signEcdsa(key, this.asUnsignedDer());
90626
90626
  }
90627
90627
  /**
90628
90628
  * Serialize as signed DER.
@@ -90684,7 +90684,7 @@ var init_Certificate = __esm({
90684
90684
  }
90685
90685
  };
90686
90686
  ((Certificate2) => {
90687
- async function createCertificateSigningRequest(crypto7, key) {
90687
+ async function createCertificateSigningRequest(crypto8, key) {
90688
90688
  const request = {
90689
90689
  version: 0,
90690
90690
  subject: { organization: X520.OrganisationName("CSR") },
@@ -90694,7 +90694,7 @@ var init_Certificate = __esm({
90694
90694
  return DerCodec.encode({
90695
90695
  request,
90696
90696
  signAlgorithm: X962.EcdsaWithSHA256,
90697
- signature: DerBitString((await crypto7.signEcdsa(key, DerCodec.encode(request))).der)
90697
+ signature: DerBitString((await crypto8.signEcdsa(key, DerCodec.encode(request))).der)
90698
90698
  });
90699
90699
  }
90700
90700
  Certificate2.createCertificateSigningRequest = createCertificateSigningRequest;
@@ -90973,7 +90973,7 @@ var init_Certificate = __esm({
90973
90973
  };
90974
90974
  }
90975
90975
  Certificate2.parseAsn1Certificate = parseAsn1Certificate;
90976
- async function getPublicKeyFromCsr(crypto7, encodedCsr) {
90976
+ async function getPublicKeyFromCsr(crypto8, encodedCsr) {
90977
90977
  const { _elements: rootElements } = DerCodec.decode(encodedCsr);
90978
90978
  if (rootElements?.length !== 3) {
90979
90979
  throw new CertificateError("Invalid CSR data");
@@ -91011,7 +91011,7 @@ var init_Certificate = __esm({
91011
91011
  if (signatureAlgorithmBytes === void 0 || !Bytes.areEqual(X962.EcdsaWithSHA256._objectId._bytes, signatureAlgorithmBytes)) {
91012
91012
  throw new CertificateError("Unsupported signature algorithm in CSR");
91013
91013
  }
91014
- await crypto7.verifyEcdsa(
91014
+ await crypto8.verifyEcdsa(
91015
91015
  PublicKey(publicKey),
91016
91016
  DerCodec.encode(requestNode),
91017
91017
  new EcdsaSignature(signatureNode._bytes, "der")
@@ -91240,7 +91240,7 @@ var init_Icac = __esm({
91240
91240
  * Verify requirements a Matter Intermediate CA certificate must fulfill.
91241
91241
  * Rules for this are listed in @see {@link MatterSpecification.v12.Core} §6.5.x
91242
91242
  */
91243
- async verify(crypto7, root) {
91243
+ async verify(crypto8, root) {
91244
91244
  this.generalVerify();
91245
91245
  const {
91246
91246
  subject,
@@ -91316,7 +91316,7 @@ var init_Icac = __esm({
91316
91316
  `Ica certificate authorityKeyIdentifier must be equal to root cert subjectKeyIdentifier.`
91317
91317
  );
91318
91318
  }
91319
- await crypto7.verifyEcdsa(PublicKey(root.cert.ellipticCurvePublicKey), this.asUnsignedDer(), this.signature);
91319
+ await crypto8.verifyEcdsa(PublicKey(root.cert.ellipticCurvePublicKey), this.asUnsignedDer(), this.signature);
91320
91320
  }
91321
91321
  };
91322
91322
  }
@@ -91367,7 +91367,7 @@ var init_Noc = __esm({
91367
91367
  * Verify requirements a Matter Node Operational certificate must fulfill.
91368
91368
  * Rules for this are listed in @see {@link MatterSpecification.v12.Core} §6.5.x
91369
91369
  */
91370
- async verify(crypto7, root, ica) {
91370
+ async verify(crypto8, root, ica) {
91371
91371
  this.generalVerify();
91372
91372
  const {
91373
91373
  subject,
@@ -91452,7 +91452,7 @@ var init_Noc = __esm({
91452
91452
  `Noc certificate authorityKeyIdentifier must be equal to Root/Ica subjectKeyIdentifier.`
91453
91453
  );
91454
91454
  }
91455
- await crypto7.verifyEcdsa(PublicKey(issuer.cert.ellipticCurvePublicKey), this.asUnsignedDer(), this.signature);
91455
+ await crypto8.verifyEcdsa(PublicKey(issuer.cert.ellipticCurvePublicKey), this.asUnsignedDer(), this.signature);
91456
91456
  }
91457
91457
  };
91458
91458
  }
@@ -93037,10 +93037,10 @@ var init_MessageCounter = __esm({
93037
93037
  * counter is not allowed to rollover and the callback is called before a rollover would happen. Optionally provide
93038
93038
  * a number of messages before the rollover callback is called (Default 1000).
93039
93039
  */
93040
- constructor(crypto7, onRollover, rolloverInfoDifference = ROLLOVER_INFO_DIFFERENCE) {
93040
+ constructor(crypto8, onRollover, rolloverInfoDifference = ROLLOVER_INFO_DIFFERENCE) {
93041
93041
  this.onRollover = onRollover;
93042
93042
  this.rolloverInfoDifference = rolloverInfoDifference;
93043
- this.messageCounter = (crypto7.randomUint32 >>> 4) + 1;
93043
+ this.messageCounter = (crypto8.randomUint32 >>> 4) + 1;
93044
93044
  }
93045
93045
  messageCounter;
93046
93046
  async getIncrementedCounter() {
@@ -93058,8 +93058,8 @@ var init_MessageCounter = __esm({
93058
93058
  }
93059
93059
  };
93060
93060
  PersistedMessageCounter = class _PersistedMessageCounter extends MessageCounter {
93061
- constructor(crypto7, storageContext, storageKey, aboutToRolloverCallback, rolloverInfoDifference = ROLLOVER_INFO_DIFFERENCE) {
93062
- super(crypto7, aboutToRolloverCallback, rolloverInfoDifference);
93061
+ constructor(crypto8, storageContext, storageKey, aboutToRolloverCallback, rolloverInfoDifference = ROLLOVER_INFO_DIFFERENCE) {
93062
+ super(crypto8, aboutToRolloverCallback, rolloverInfoDifference);
93063
93063
  this.storageContext = storageContext;
93064
93064
  this.storageKey = storageKey;
93065
93065
  this.#construction = Construction(this, async () => {
@@ -93078,10 +93078,10 @@ var init_MessageCounter = __esm({
93078
93078
  get construction() {
93079
93079
  return this.#construction;
93080
93080
  }
93081
- static async create(crypto7, storageContext, storageKey, aboutToRolloverCallback, rolloverInfoDifference = ROLLOVER_INFO_DIFFERENCE) {
93081
+ static async create(crypto8, storageContext, storageKey, aboutToRolloverCallback, rolloverInfoDifference = ROLLOVER_INFO_DIFFERENCE) {
93082
93082
  return asyncNew(
93083
93083
  _PersistedMessageCounter,
93084
- crypto7,
93084
+ crypto8,
93085
93085
  storageContext,
93086
93086
  storageKey,
93087
93087
  aboutToRolloverCallback,
@@ -93994,7 +93994,7 @@ var init_NodeSession = __esm({
93994
93994
  }
93995
93995
  constructor(config10) {
93996
93996
  const {
93997
- crypto: crypto7,
93997
+ crypto: crypto8,
93998
93998
  manager,
93999
93999
  id,
94000
94000
  fabric,
@@ -94012,14 +94012,14 @@ var init_NodeSession = __esm({
94012
94012
  setActiveTimestamp: true,
94013
94013
  // We always set the active timestamp for Secure sessions
94014
94014
  // Can be changed to a PersistedMessageCounter if we implement session storage
94015
- messageCounter: new MessageCounter(crypto7, async () => {
94015
+ messageCounter: new MessageCounter(crypto8, async () => {
94016
94016
  await this.initiateClose(async () => {
94017
94017
  await this.closeSubscriptions(true);
94018
94018
  });
94019
94019
  }),
94020
94020
  messageReceptionState: new MessageReceptionStateEncryptedWithoutRollover(0)
94021
94021
  });
94022
- this.#crypto = crypto7;
94022
+ this.#crypto = crypto8;
94023
94023
  this.#id = id;
94024
94024
  this.#fabric = fabric;
94025
94025
  this.#peerNodeId = peerNodeId;
@@ -94468,22 +94468,22 @@ var init_CaseClient = __esm({
94468
94468
  }
94469
94469
  }
94470
94470
  async #doPair(messenger, exchange, fabric, peerNodeId, caseAuthenticatedTags) {
94471
- const { crypto: crypto7 } = fabric;
94472
- const initiatorRandom = crypto7.randomBytes(32);
94471
+ const { crypto: crypto8 } = fabric;
94472
+ const initiatorRandom = crypto8.randomBytes(32);
94473
94473
  const initiatorSessionId = await this.#sessions.getNextAvailableSessionId();
94474
94474
  const { operationalIdentityProtectionKey, operationalCert: localNoc, intermediateCACert: localIcac } = fabric;
94475
- const localKey = await crypto7.createKeyPair();
94475
+ const localKey = await crypto8.createKeyPair();
94476
94476
  let sigma1Bytes;
94477
94477
  let resumed = false;
94478
94478
  let resumptionRecord = this.#sessions.findResumptionRecordByAddress(fabric.addressOf(peerNodeId));
94479
94479
  if (resumptionRecord !== void 0) {
94480
94480
  const { sharedSecret, resumptionId } = resumptionRecord;
94481
- const resumeKey = await crypto7.createHkdfKey(
94481
+ const resumeKey = await crypto8.createHkdfKey(
94482
94482
  sharedSecret,
94483
94483
  Bytes.concat(initiatorRandom, resumptionId),
94484
94484
  KDFSR1_KEY_INFO
94485
94485
  );
94486
- const initiatorResumeMic = crypto7.encrypt(resumeKey, new Uint8Array(0), RESUME1_MIC_NONCE);
94486
+ const initiatorResumeMic = crypto8.encrypt(resumeKey, new Uint8Array(0), RESUME1_MIC_NONCE);
94487
94487
  sigma1Bytes = await messenger.sendSigma1({
94488
94488
  initiatorSessionId,
94489
94489
  destinationId: await fabric.currentDestinationIdFor(peerNodeId, initiatorRandom),
@@ -94518,8 +94518,8 @@ var init_CaseClient = __esm({
94518
94518
  ...resumptionSessionParams ?? {}
94519
94519
  };
94520
94520
  const resumeSalt = Bytes.concat(initiatorRandom, resumptionId);
94521
- const resumeKey = await crypto7.createHkdfKey(sharedSecret, resumeSalt, KDFSR2_KEY_INFO);
94522
- crypto7.decrypt(resumeKey, resumeMic, RESUME2_MIC_NONCE);
94521
+ const resumeKey = await crypto8.createHkdfKey(sharedSecret, resumeSalt, KDFSR2_KEY_INFO);
94522
+ crypto8.decrypt(resumeKey, resumeMic, RESUME2_MIC_NONCE);
94523
94523
  const secureSessionSalt = Bytes.concat(initiatorRandom, resumptionRecord.resumptionId);
94524
94524
  secureSession = await this.#sessions.createSecureSession({
94525
94525
  channel: exchange.channel.channel,
@@ -94563,15 +94563,15 @@ var init_CaseClient = __esm({
94563
94563
  ...exchange.session.parameters,
94564
94564
  ...responderSessionParams ?? {}
94565
94565
  };
94566
- const sharedSecret = await crypto7.generateDhSecret(localKey, PublicKey(peerKey));
94566
+ const sharedSecret = await crypto8.generateDhSecret(localKey, PublicKey(peerKey));
94567
94567
  const sigma2Salt = Bytes.concat(
94568
94568
  operationalIdentityProtectionKey,
94569
94569
  responderRandom,
94570
94570
  peerKey,
94571
- await crypto7.computeHash(sigma1Bytes)
94571
+ await crypto8.computeHash(sigma1Bytes)
94572
94572
  );
94573
- const sigma2Key = await crypto7.createHkdfKey(sharedSecret, sigma2Salt, KDFSR2_INFO);
94574
- const peerEncryptedData = crypto7.decrypt(sigma2Key, peerEncrypted, TBE_DATA2_NONCE);
94573
+ const sigma2Key = await crypto8.createHkdfKey(sharedSecret, sigma2Salt, KDFSR2_INFO);
94574
+ const peerEncryptedData = crypto8.decrypt(sigma2Key, peerEncrypted, TBE_DATA2_NONCE);
94575
94575
  const {
94576
94576
  responderNoc: peerNoc,
94577
94577
  responderIcac: peerIcac,
@@ -94588,7 +94588,7 @@ var init_CaseClient = __esm({
94588
94588
  ellipticCurvePublicKey: peerPublicKey,
94589
94589
  subject: { fabricId: peerFabricIdNOCert, nodeId: peerNodeIdNOCert }
94590
94590
  } = Noc.fromTlv(peerNoc).cert;
94591
- await crypto7.verifyEcdsa(PublicKey(peerPublicKey), peerSignatureData, new EcdsaSignature(peerSignature));
94591
+ await crypto8.verifyEcdsa(PublicKey(peerPublicKey), peerSignatureData, new EcdsaSignature(peerSignature));
94592
94592
  if (peerNodeIdNOCert !== peerNodeId) {
94593
94593
  throw new UnexpectedDataError(
94594
94594
  `The node ID in the peer certificate ${peerNodeIdNOCert} doesn't match the expected peer node ID ${peerNodeId}`
@@ -94612,9 +94612,9 @@ var init_CaseClient = __esm({
94612
94612
  await fabric.verifyCredentials(peerNoc, peerIcac);
94613
94613
  const sigma3Salt = Bytes.concat(
94614
94614
  operationalIdentityProtectionKey,
94615
- await crypto7.computeHash([sigma1Bytes, sigma2Bytes])
94615
+ await crypto8.computeHash([sigma1Bytes, sigma2Bytes])
94616
94616
  );
94617
- const sigma3Key = await crypto7.createHkdfKey(sharedSecret, sigma3Salt, KDFSR3_INFO);
94617
+ const sigma3Key = await crypto8.createHkdfKey(sharedSecret, sigma3Salt, KDFSR3_INFO);
94618
94618
  const signatureData = TlvSignedData.encode({
94619
94619
  responderNoc: localNoc,
94620
94620
  responderIcac: localIcac,
@@ -94627,13 +94627,13 @@ var init_CaseClient = __esm({
94627
94627
  responderIcac: localIcac,
94628
94628
  signature: signature.bytes
94629
94629
  });
94630
- const encrypted = crypto7.encrypt(sigma3Key, encryptedData, TBE_DATA3_NONCE);
94630
+ const encrypted = crypto8.encrypt(sigma3Key, encryptedData, TBE_DATA3_NONCE);
94631
94631
  const sigma3Bytes = await messenger.sendSigma3({ encrypted });
94632
94632
  await messenger.waitForSuccess("Sigma3-Success");
94633
94633
  const sessionCaseAuthenticatedTags = caseAuthenticatedTags ?? resumptionRecord?.caseAuthenticatedTags;
94634
94634
  const secureSessionSalt = Bytes.concat(
94635
94635
  operationalIdentityProtectionKey,
94636
- await crypto7.computeHash([sigma1Bytes, sigma2Bytes, sigma3Bytes])
94636
+ await crypto8.computeHash([sigma1Bytes, sigma2Bytes, sigma3Bytes])
94637
94637
  );
94638
94638
  secureSession = await this.#sessions.createSecureSession({
94639
94639
  channel: exchange.channel.channel,
@@ -94711,7 +94711,7 @@ var init_Rcac = __esm({
94711
94711
  * Verify requirements a Matter Root certificate must fulfill.
94712
94712
  * Rules for this are listed in @see {@link MatterSpecification.v12.Core} §6.5.x
94713
94713
  */
94714
- async verify(crypto7) {
94714
+ async verify(crypto8) {
94715
94715
  this.generalVerify();
94716
94716
  const { subject, extensions } = this.cert;
94717
94717
  const { fabricId: fabricId3, rcacId } = subject;
@@ -94768,7 +94768,7 @@ var init_Rcac = __esm({
94768
94768
  `Root certificate authorityKeyIdentifier must be equal to subjectKeyIdentifier.`
94769
94769
  );
94770
94770
  }
94771
- await crypto7.verifyEcdsa(PublicKey(this.cert.ellipticCurvePublicKey), this.asUnsignedDer(), this.signature);
94771
+ await crypto8.verifyEcdsa(PublicKey(this.cert.ellipticCurvePublicKey), this.asUnsignedDer(), this.signature);
94772
94772
  }
94773
94773
  };
94774
94774
  }
@@ -94903,8 +94903,8 @@ var init_KeySets = __esm({
94903
94903
  };
94904
94904
  }
94905
94905
  /** Calculates a group session id based on the operational group key. */
94906
- async sessionIdFromKey(crypto7, operationalGroupKey) {
94907
- const groupKeyHash = await crypto7.createHkdfKey(operationalGroupKey, new Uint8Array(), GROUP_KEY_INFO, 2);
94906
+ async sessionIdFromKey(crypto8, operationalGroupKey) {
94907
+ const groupKeyHash = await crypto8.createHkdfKey(operationalGroupKey, new Uint8Array(), GROUP_KEY_INFO, 2);
94908
94908
  return new DataReader(groupKeyHash).readUInt16();
94909
94909
  }
94910
94910
  /**
@@ -94957,8 +94957,8 @@ var init_MessagingState = __esm({
94957
94957
  #messageDataReceptionState = /* @__PURE__ */ new Map();
94958
94958
  #crypto;
94959
94959
  #storage;
94960
- constructor(crypto7, storage2) {
94961
- this.#crypto = crypto7;
94960
+ constructor(crypto8, storage2) {
94961
+ this.#crypto = crypto8;
94962
94962
  if (storage2 !== void 0) {
94963
94963
  this.#storage = storage2;
94964
94964
  }
@@ -95491,8 +95491,8 @@ var init_Fabric = __esm({
95491
95491
  * Certain derived fields that require async crypto operations to compute must be supplied here. Use {@link create}
95492
95492
  * to populate these fields automatically.
95493
95493
  */
95494
- constructor(crypto7, config10) {
95495
- this.#crypto = crypto7;
95494
+ constructor(crypto8, config10) {
95495
+ this.#crypto = crypto8;
95496
95496
  this.fabricIndex = config10.fabricIndex;
95497
95497
  this.fabricId = config10.fabricId;
95498
95498
  this.nodeId = config10.nodeId;
@@ -95521,20 +95521,20 @@ var init_Fabric = __esm({
95521
95521
  *
95522
95522
  * This async creation path populates derived fields that require async crypto operations to compute.
95523
95523
  */
95524
- static async create(crypto7, config10) {
95524
+ static async create(crypto8, config10) {
95525
95525
  let { globalId, operationalIdentityProtectionKey } = config10;
95526
95526
  if (globalId === void 0) {
95527
95527
  const caKey = config10.rootPublicKey ?? Rcac.publicKeyOfTlv(config10.rootCert);
95528
- globalId = await GlobalFabricId.compute(crypto7, config10.fabricId, caKey);
95528
+ globalId = await GlobalFabricId.compute(crypto8, config10.fabricId, caKey);
95529
95529
  }
95530
95530
  if (operationalIdentityProtectionKey === void 0) {
95531
- operationalIdentityProtectionKey = await crypto7.createHkdfKey(
95531
+ operationalIdentityProtectionKey = await crypto8.createHkdfKey(
95532
95532
  config10.identityProtectionKey,
95533
95533
  Bytes.fromBigInt(globalId, 8),
95534
95534
  GROUP_SECURITY_INFO
95535
95535
  );
95536
95536
  }
95537
- return new _Fabric(crypto7, {
95537
+ return new _Fabric(crypto8, {
95538
95538
  ...config10,
95539
95539
  globalId,
95540
95540
  operationalIdentityProtectionKey
@@ -95791,12 +95791,12 @@ var init_Fabric = __esm({
95791
95791
  #vvsc;
95792
95792
  #fabricIndex;
95793
95793
  #label = "";
95794
- constructor(crypto7, key) {
95795
- this.#crypto = crypto7;
95794
+ constructor(crypto8, key) {
95795
+ this.#crypto = crypto8;
95796
95796
  this.#keyPair = key;
95797
95797
  }
95798
- static async create(crypto7) {
95799
- return new _FabricBuilder(crypto7, await crypto7.createKeyPair());
95798
+ static async create(crypto8) {
95799
+ return new _FabricBuilder(crypto8, await crypto8.createKeyPair());
95800
95800
  }
95801
95801
  get publicKey() {
95802
95802
  return this.#keyPair.publicKey;
@@ -95955,8 +95955,8 @@ var init_FabricManager = __esm({
95955
95955
  failsafeClosed: Observable()
95956
95956
  };
95957
95957
  #construction;
95958
- constructor(crypto7, storage2) {
95959
- this.#crypto = crypto7;
95958
+ constructor(crypto8, storage2) {
95959
+ this.#crypto = crypto8;
95960
95960
  this.#storage = storage2;
95961
95961
  let construct;
95962
95962
  if (this.#storage === void 0) {
@@ -95969,7 +95969,7 @@ var init_FabricManager = __esm({
95969
95969
  }
95970
95970
  const fabrics = await this.#storage.get("fabrics", []);
95971
95971
  for (const fabricConfig of fabrics) {
95972
- this.#addNewFabric(await Fabric.create(crypto7, fabricConfig));
95972
+ this.#addNewFabric(await Fabric.create(crypto8, fabricConfig));
95973
95973
  }
95974
95974
  this.#nextFabricIndex = await this.#storage.get("nextFabricIndex", this.#nextFabricIndex);
95975
95975
  this.#initializationDone = true;
@@ -96265,14 +96265,14 @@ var init_CaseServer = __esm({
96265
96265
  return false;
96266
96266
  }
96267
96267
  const { sharedSecret, fabric, peerNodeId, caseAuthenticatedTags } = cx.resumptionRecord;
96268
- const { crypto: crypto7 } = this.#fabrics;
96269
- const peerResumeKey = await crypto7.createHkdfKey(
96268
+ const { crypto: crypto8 } = this.#fabrics;
96269
+ const peerResumeKey = await crypto8.createHkdfKey(
96270
96270
  sharedSecret,
96271
96271
  Bytes.concat(cx.peerRandom, cx.peerResumptionId),
96272
96272
  KDFSR1_KEY_INFO
96273
96273
  );
96274
96274
  try {
96275
- crypto7.decrypt(peerResumeKey, cx.peerResumeMic, RESUME1_MIC_NONCE);
96275
+ crypto8.decrypt(peerResumeKey, cx.peerResumeMic, RESUME1_MIC_NONCE);
96276
96276
  } catch (e) {
96277
96277
  CryptoDecryptError.accept(e);
96278
96278
  cx.peerResumptionId = cx.peerResumeMic = void 0;
@@ -96296,8 +96296,8 @@ var init_CaseServer = __esm({
96296
96296
  // Session establishment could still fail, so add session ourselves to the manager
96297
96297
  });
96298
96298
  const resumeSalt = Bytes.concat(cx.peerRandom, cx.localResumptionId);
96299
- const resumeKey = await crypto7.createHkdfKey(sharedSecret, resumeSalt, KDFSR2_KEY_INFO);
96300
- const resumeMic = crypto7.encrypt(resumeKey, new Uint8Array(0), RESUME2_MIC_NONCE);
96299
+ const resumeKey = await crypto8.createHkdfKey(sharedSecret, resumeSalt, KDFSR2_KEY_INFO);
96300
+ const resumeMic = crypto8.encrypt(resumeKey, new Uint8Array(0), RESUME2_MIC_NONCE);
96301
96301
  try {
96302
96302
  const responderSessionParams = this.#sessions.sessionParameters;
96303
96303
  await cx.messenger.sendSigma2Resume({
@@ -96326,20 +96326,20 @@ var init_CaseServer = __esm({
96326
96326
  ) {
96327
96327
  return false;
96328
96328
  }
96329
- const { crypto: crypto7 } = this.#fabrics;
96330
- const responderRandom = crypto7.randomBytes(32);
96329
+ const { crypto: crypto8 } = this.#fabrics;
96330
+ const responderRandom = crypto8.randomBytes(32);
96331
96331
  const fabric = await this.#fabrics.findFabricFromDestinationId(cx.destinationId, cx.peerRandom);
96332
96332
  const { operationalCert: nodeOpCert, intermediateCACert, operationalIdentityProtectionKey } = fabric;
96333
- const key = await crypto7.createKeyPair();
96333
+ const key = await crypto8.createKeyPair();
96334
96334
  const responderEcdhPublicKey = key.publicBits;
96335
- const sharedSecret = await crypto7.generateDhSecret(key, PublicKey(cx.peerEcdhPublicKey));
96335
+ const sharedSecret = await crypto8.generateDhSecret(key, PublicKey(cx.peerEcdhPublicKey));
96336
96336
  const sigma2Salt = Bytes.concat(
96337
96337
  operationalIdentityProtectionKey,
96338
96338
  responderRandom,
96339
96339
  responderEcdhPublicKey,
96340
- await crypto7.computeHash(cx.bytes)
96340
+ await crypto8.computeHash(cx.bytes)
96341
96341
  );
96342
- const sigma2Key = await crypto7.createHkdfKey(sharedSecret, sigma2Salt, KDFSR2_INFO);
96342
+ const sigma2Key = await crypto8.createHkdfKey(sharedSecret, sigma2Salt, KDFSR2_INFO);
96343
96343
  const signatureData = TlvSignedData.encode({
96344
96344
  responderNoc: nodeOpCert,
96345
96345
  responderIcac: intermediateCACert,
@@ -96353,7 +96353,7 @@ var init_CaseServer = __esm({
96353
96353
  signature: signature.bytes,
96354
96354
  resumptionId: cx.localResumptionId
96355
96355
  });
96356
- const encrypted = crypto7.encrypt(sigma2Key, encryptedData, TBE_DATA2_NONCE);
96356
+ const encrypted = crypto8.encrypt(sigma2Key, encryptedData, TBE_DATA2_NONCE);
96357
96357
  const responderSessionId = await this.#sessions.getNextAvailableSessionId();
96358
96358
  const sigma2Bytes = await cx.messenger.sendSigma2({
96359
96359
  responderRandom,
@@ -96369,10 +96369,10 @@ var init_CaseServer = __esm({
96369
96369
  } = await cx.messenger.readSigma3();
96370
96370
  const sigma3Salt = Bytes.concat(
96371
96371
  operationalIdentityProtectionKey,
96372
- await crypto7.computeHash([cx.bytes, sigma2Bytes])
96372
+ await crypto8.computeHash([cx.bytes, sigma2Bytes])
96373
96373
  );
96374
- const sigma3Key = await crypto7.createHkdfKey(sharedSecret, sigma3Salt, KDFSR3_INFO);
96375
- const peerDecryptedData = crypto7.decrypt(sigma3Key, peerEncrypted, TBE_DATA3_NONCE);
96374
+ const sigma3Key = await crypto8.createHkdfKey(sharedSecret, sigma3Salt, KDFSR3_INFO);
96375
+ const peerDecryptedData = crypto8.decrypt(sigma3Key, peerEncrypted, TBE_DATA3_NONCE);
96376
96376
  const {
96377
96377
  responderNoc: peerNewOpCert,
96378
96378
  responderIcac: peerIntermediateCACert,
@@ -96392,10 +96392,10 @@ var init_CaseServer = __esm({
96392
96392
  if (fabric.fabricId !== peerFabricId) {
96393
96393
  throw new UnexpectedDataError(`Fabric ID mismatch: ${fabric.fabricId} !== ${peerFabricId}`);
96394
96394
  }
96395
- await crypto7.verifyEcdsa(PublicKey(peerPublicKey), peerSignatureData, new EcdsaSignature(peerSignature));
96395
+ await crypto8.verifyEcdsa(PublicKey(peerPublicKey), peerSignatureData, new EcdsaSignature(peerSignature));
96396
96396
  const secureSessionSalt = Bytes.concat(
96397
96397
  operationalIdentityProtectionKey,
96398
- await crypto7.computeHash([cx.bytes, sigma2Bytes, sigma3Bytes])
96398
+ await crypto8.computeHash([cx.bytes, sigma2Bytes, sigma3Bytes])
96399
96399
  );
96400
96400
  const secureSession = await this.#sessions.createSecureSession({
96401
96401
  channel,
@@ -96440,8 +96440,8 @@ var init_CaseServer = __esm({
96440
96440
  peerSessionParams;
96441
96441
  resumptionRecord;
96442
96442
  #localResumptionId;
96443
- constructor(crypto7, messenger, bytes, sigma1, resumptionRecord) {
96444
- this.crypto = crypto7;
96443
+ constructor(crypto8, messenger, bytes, sigma1, resumptionRecord) {
96444
+ this.crypto = crypto8;
96445
96445
  this.messenger = messenger;
96446
96446
  this.bytes = bytes;
96447
96447
  this.peerSessionId = sigma1.initiatorSessionId;
@@ -96937,25 +96937,25 @@ var init_PaseClient = __esm({
96937
96937
  constructor(sessions) {
96938
96938
  this.#sessions = sessions;
96939
96939
  }
96940
- static async generatePakePasscodeVerifier(crypto7, setupPinCode, pbkdfParameters) {
96941
- const { w0, L } = await Spake2p.computeW0L(crypto7, pbkdfParameters, setupPinCode);
96940
+ static async generatePakePasscodeVerifier(crypto8, setupPinCode, pbkdfParameters) {
96941
+ const { w0, L } = await Spake2p.computeW0L(crypto8, pbkdfParameters, setupPinCode);
96942
96942
  return Bytes.concat(numberToBytesBE3(w0, 32), L);
96943
96943
  }
96944
- static generateRandomPasscode(crypto7) {
96944
+ static generateRandomPasscode(crypto8) {
96945
96945
  let passcode;
96946
- passcode = crypto7.randomUint32 % 99999998 + 1;
96946
+ passcode = crypto8.randomUint32 % 99999998 + 1;
96947
96947
  if (CommissioningOptions.FORBIDDEN_PASSCODES.includes(passcode)) {
96948
96948
  passcode += 1;
96949
96949
  }
96950
96950
  return passcode;
96951
96951
  }
96952
- static generateRandomDiscriminator(crypto7) {
96953
- return crypto7.randomUint16 % 4096;
96952
+ static generateRandomDiscriminator(crypto8) {
96953
+ return crypto8.randomUint16 % 4096;
96954
96954
  }
96955
96955
  async pair(initiatorSessionParams, exchange, channel, setupPin) {
96956
96956
  const messenger = new PaseClientMessenger(exchange);
96957
- const { crypto: crypto7 } = this.#sessions;
96958
- const initiatorRandom = crypto7.randomBytes(32);
96957
+ const { crypto: crypto8 } = this.#sessions;
96958
+ const initiatorRandom = crypto8.randomBytes(32);
96959
96959
  const initiatorSessionId = await this.#sessions.getNextAvailableSessionId();
96960
96960
  const requestPayload = await messenger.sendPbkdfParamRequest({
96961
96961
  initiatorRandom,
@@ -96979,10 +96979,10 @@ var init_PaseClient = __esm({
96979
96979
  ...exchange.session.parameters,
96980
96980
  ...responderSessionParams ?? {}
96981
96981
  };
96982
- const { w0, w1 } = await Spake2p.computeW0W1(crypto7, pbkdfParameters, setupPin);
96982
+ const { w0, w1 } = await Spake2p.computeW0W1(crypto8, pbkdfParameters, setupPin);
96983
96983
  const spake2p = Spake2p.create(
96984
- crypto7,
96985
- await crypto7.computeHash([SPAKE_CONTEXT, requestPayload, responsePayload]),
96984
+ crypto8,
96985
+ await crypto8.computeHash([SPAKE_CONTEXT, requestPayload, responsePayload]),
96986
96986
  w0
96987
96987
  );
96988
96988
  const X = spake2p.computeX();
@@ -97093,7 +97093,7 @@ var init_PaseServer = __esm({
97093
97093
  }
97094
97094
  }
97095
97095
  }
97096
- async handlePairingRequest(crypto7, channel) {
97096
+ async handlePairingRequest(crypto8, channel) {
97097
97097
  const messenger = this.#pairingMessenger;
97098
97098
  logger40.info("Received pairing request", Mark.INBOUND, Diagnostic.via(messenger.channelName));
97099
97099
  this.#pairingTimer = Time.getTimer(
@@ -97115,7 +97115,7 @@ var init_PaseServer = __esm({
97115
97115
  throw new UnexpectedDataError(`Unsupported passcode ID ${passcodeId}.`);
97116
97116
  }
97117
97117
  const responderSessionId = await this.sessions.getNextAvailableSessionId();
97118
- const responderRandom = crypto7.randomBytes(32);
97118
+ const responderRandom = crypto8.randomBytes(32);
97119
97119
  const responderSessionParams = this.sessions.sessionParameters;
97120
97120
  if (initiatorSessionParams !== void 0) {
97121
97121
  messenger.channel.session.timingParameters = initiatorSessionParams;
@@ -97128,8 +97128,8 @@ var init_PaseServer = __esm({
97128
97128
  responderSessionParams
97129
97129
  });
97130
97130
  const spake2p = Spake2p.create(
97131
- crypto7,
97132
- await crypto7.computeHash([SPAKE_CONTEXT, requestPayload, responsePayload]),
97131
+ crypto8,
97132
+ await crypto8.computeHash([SPAKE_CONTEXT, requestPayload, responsePayload]),
97133
97133
  this.w0
97134
97134
  );
97135
97135
  const { x: X } = await messenger.readPasePake1();
@@ -97197,14 +97197,14 @@ var init_UnsecuredSession = __esm({
97197
97197
  supportsMRP = true;
97198
97198
  type = SessionType.Unicast;
97199
97199
  constructor(config10) {
97200
- const { crypto: crypto7, initiatorNodeId, isInitiator } = config10;
97200
+ const { crypto: crypto8, initiatorNodeId, isInitiator } = config10;
97201
97201
  super({
97202
97202
  ...config10,
97203
97203
  setActiveTimestamp: !isInitiator,
97204
97204
  // When we are the initiator we assume the node is in idle mode
97205
97205
  messageReceptionState: new MessageReceptionStateUnencryptedWithRollover()
97206
97206
  });
97207
- this.#initiatorNodeId = initiatorNodeId ?? NodeId.randomOperationalNodeId(crypto7);
97207
+ this.#initiatorNodeId = initiatorNodeId ?? NodeId.randomOperationalNodeId(crypto8);
97208
97208
  }
97209
97209
  get isSecure() {
97210
97210
  return false;
@@ -97291,11 +97291,11 @@ var init_SessionManager = __esm({
97291
97291
  constructor(context) {
97292
97292
  this.#context = context;
97293
97293
  const {
97294
- fabrics: { crypto: crypto7 }
97294
+ fabrics: { crypto: crypto8 }
97295
97295
  } = context;
97296
97296
  this.#sessionParameters = SessionParameters({ ...SessionParameters.defaults, ...context.parameters });
97297
- this.#nextSessionId = crypto7.randomUint16;
97298
- this.#globalUnencryptedMessageCounter = new MessageCounter(crypto7);
97297
+ this.#nextSessionId = crypto8.randomUint16;
97298
+ this.#globalUnencryptedMessageCounter = new MessageCounter(crypto8);
97299
97299
  this.#observers.on(context.fabrics.events.deleting, async (fabric) => {
97300
97300
  await this.deleteResumptionRecordsForFabric(fabric);
97301
97301
  });
@@ -100871,18 +100871,18 @@ var init_ProtocolMocks = __esm({
100871
100871
  init_MessageExchange();
100872
100872
  ((ProtocolMocks2) => {
100873
100873
  class Fabric2 extends Fabric {
100874
- constructor(config10, crypto7) {
100875
- if (!crypto7) {
100876
- crypto7 = Environment.default.maybeGet(Crypto);
100877
- if (!(crypto7 instanceof MockCrypto)) {
100878
- crypto7 = MockCrypto();
100874
+ constructor(config10, crypto8) {
100875
+ if (!crypto8) {
100876
+ crypto8 = Environment.default.maybeGet(Crypto);
100877
+ if (!(crypto8 instanceof MockCrypto)) {
100878
+ crypto8 = MockCrypto();
100879
100879
  }
100880
100880
  }
100881
- const keyPair = config10?.keyPair ?? crypto7.createKeyPair();
100881
+ const keyPair = config10?.keyPair ?? crypto8.createKeyPair();
100882
100882
  if (MaybePromise.is(keyPair)) {
100883
100883
  throw new ImplementationError("Must provide key pair with async crypto");
100884
100884
  }
100885
- super(crypto7, {
100885
+ super(crypto8, {
100886
100886
  ...Fabric2.defaults,
100887
100887
  ...config10,
100888
100888
  keyPair
@@ -100912,7 +100912,7 @@ var init_ProtocolMocks = __esm({
100912
100912
  constructor(config10) {
100913
100913
  const index = config10?.index ?? 1;
100914
100914
  const fabricIndex = config10?.fabricIndex ?? 1;
100915
- const crypto7 = config10?.crypto ?? Environment.default.get(Crypto);
100915
+ const crypto8 = config10?.crypto ?? Environment.default.get(Crypto);
100916
100916
  const fabric = config10 && "fabric" in config10 ? config10.fabric : new Fabric2({ fabricIndex });
100917
100917
  const maxPayloadSize = config10?.maxPayloadSize;
100918
100918
  let channel;
@@ -100931,7 +100931,7 @@ var init_ProtocolMocks = __esm({
100931
100931
  encryptKey: Bytes.empty,
100932
100932
  isInitiator: true,
100933
100933
  ...config10,
100934
- crypto: crypto7,
100934
+ crypto: crypto8,
100935
100935
  fabric
100936
100936
  };
100937
100937
  delete fullConfig.channel;
@@ -100940,11 +100940,11 @@ var init_ProtocolMocks = __esm({
100940
100940
  this.lifetime = Lifetime.mock;
100941
100941
  }
100942
100942
  static async create(config10) {
100943
- const crypto7 = config10?.crypto ?? config10?.manager?.crypto ?? Environment.default.get(Crypto);
100943
+ const crypto8 = config10?.crypto ?? config10?.manager?.crypto ?? Environment.default.get(Crypto);
100944
100944
  const index = config10?.index ?? 1;
100945
100945
  return NodeSession.create.call(this, {
100946
100946
  id: index,
100947
- crypto: crypto7,
100947
+ crypto: crypto8,
100948
100948
  peerNodeId: NodeId(0),
100949
100949
  peerSessionId: index,
100950
100950
  sharedSecret: Bytes.empty,
@@ -106671,9 +106671,9 @@ var init_MdnsAdvertiser = __esm({
106671
106671
  init_CommissionerMdnsAdvertisement();
106672
106672
  init_OperationalMdnsAdvertisement();
106673
106673
  MdnsAdvertiser = class _MdnsAdvertiser extends Advertiser {
106674
- constructor(crypto7, server, options) {
106674
+ constructor(crypto8, server, options) {
106675
106675
  super(options?.lifetime);
106676
- this.crypto = crypto7;
106676
+ this.crypto = crypto8;
106677
106677
  this.server = server;
106678
106678
  this.port = options?.port ?? STANDARD_MATTER_PORT;
106679
106679
  this.omitPrivateDetails = options?.omitPrivateDetails ?? false;
@@ -108118,8 +108118,8 @@ var init_AttestationCertificates = __esm({
108118
108118
  * Sign the certificate using the provided crypto and key.
108119
108119
  * If the certificate is already signed, it throws a CertificateError.
108120
108120
  */
108121
- async sign(crypto7, key) {
108122
- this.signature = await crypto7.signEcdsa(key, this.asUnsignedDer());
108121
+ async sign(crypto8, key) {
108122
+ this.signature = await crypto8.signEcdsa(key, this.asUnsignedDer());
108123
108123
  }
108124
108124
  };
108125
108125
  Paa = class _Paa extends AttestationBaseCertificate {
@@ -108168,17 +108168,17 @@ var init_AttestationCertificateManager = __esm({
108168
108168
  #paiCertId = BigInt(1);
108169
108169
  #paiCertBytes;
108170
108170
  #nextCertificateId = 2;
108171
- constructor(crypto7, vendorId3, paiKeyPair, paiKeyIdentifier) {
108172
- this.#crypto = crypto7;
108171
+ constructor(crypto8, vendorId3, paiKeyPair, paiKeyIdentifier) {
108172
+ this.#crypto = crypto8;
108173
108173
  this.#vendorId = vendorId3;
108174
108174
  this.#paiKeyPair = paiKeyPair;
108175
108175
  this.#paiKeyIdentifier = paiKeyIdentifier;
108176
108176
  this.#paiCertBytes = this.generatePAICert(vendorId3);
108177
108177
  }
108178
- static async create(crypto7, vendorId3) {
108179
- const key = await crypto7.createKeyPair();
108180
- const identifier = Bytes.of(await crypto7.computeHash(key.publicKey));
108181
- return new _AttestationCertificateManager(crypto7, vendorId3, key, identifier.slice(0, 20));
108178
+ static async create(crypto8, vendorId3) {
108179
+ const key = await crypto8.createKeyPair();
108180
+ const identifier = Bytes.of(await crypto8.computeHash(key.publicKey));
108181
+ return new _AttestationCertificateManager(crypto8, vendorId3, key, identifier.slice(0, 20));
108182
108182
  }
108183
108183
  getPAICert() {
108184
108184
  return this.#paiCertBytes;
@@ -108324,11 +108324,11 @@ var init_CertificateAuthority = __esm({
108324
108324
  get construction() {
108325
108325
  return this.#construction;
108326
108326
  }
108327
- static async create(crypto7, options, generateIntermediateCert) {
108328
- return asyncNew(_CertificateAuthority, crypto7, options, generateIntermediateCert);
108327
+ static async create(crypto8, options, generateIntermediateCert) {
108328
+ return asyncNew(_CertificateAuthority, crypto8, options, generateIntermediateCert);
108329
108329
  }
108330
- constructor(crypto7, options, generateIntermediateCert) {
108331
- this.#crypto = crypto7;
108330
+ constructor(crypto8, options, generateIntermediateCert) {
108331
+ this.#crypto = crypto8;
108332
108332
  this.#construction = Construction(this, async () => {
108333
108333
  if (typeof options === "boolean") {
108334
108334
  generateIntermediateCert = options;
@@ -108610,7 +108610,7 @@ var init_CertificationDeclaration = __esm({
108610
108610
  * Generator which is the main usage for the class from outside.
108611
108611
  * It constructs the class with the relevant details and returns a signed ASN.1 DER version of the CD.
108612
108612
  */
108613
- static generate(crypto7, vendorId3, productId, provisional = false) {
108613
+ static generate(crypto8, vendorId3, productId, provisional = false) {
108614
108614
  const cd = new _CertificationDeclaration(
108615
108615
  {
108616
108616
  formatVersion: 1,
@@ -108626,7 +108626,7 @@ var init_CertificationDeclaration = __esm({
108626
108626
  },
108627
108627
  TestCMS_SignerSubjectKeyIdentifier
108628
108628
  );
108629
- return cd.asSignedAsn1(crypto7, PrivateKey(TestCMS_SignerPrivateKey));
108629
+ return cd.asSignedAsn1(crypto8, PrivateKey(TestCMS_SignerPrivateKey));
108630
108630
  }
108631
108631
  constructor(content, subjectKeyIdentifier) {
108632
108632
  this.#eContent = CertificationDeclaration.TlvDc.encode(content);
@@ -108635,7 +108635,7 @@ var init_CertificationDeclaration = __esm({
108635
108635
  /**
108636
108636
  * Returns the signed certificate in ASN.1 DER format.
108637
108637
  */
108638
- async asSignedAsn1(crypto7, privateKey) {
108638
+ async asSignedAsn1(crypto8, privateKey) {
108639
108639
  const cert = {
108640
108640
  version: 3,
108641
108641
  digestAlgorithm: [Shs.SHA256_CMS],
@@ -108646,7 +108646,7 @@ var init_CertificationDeclaration = __esm({
108646
108646
  subjectKeyIdentifier: ContextTaggedBytes(0, this.#subjectKeyIdentifier),
108647
108647
  digestAlgorithm: Shs.SHA256_CMS,
108648
108648
  signatureAlgorithm: X962.EcdsaWithSHA256,
108649
- signature: (await crypto7.signEcdsa(privateKey, this.#eContent)).der
108649
+ signature: (await crypto8.signEcdsa(privateKey, this.#eContent)).der
108650
108650
  }
108651
108651
  ]
108652
108652
  };
@@ -108684,8 +108684,8 @@ var init_DeviceCertification = __esm({
108684
108684
  get declaration() {
108685
108685
  return this.#assertInitialized().declaration;
108686
108686
  }
108687
- constructor(crypto7, config10, product) {
108688
- this.#crypto = crypto7;
108687
+ constructor(crypto8, config10, product) {
108688
+ this.#crypto = crypto8;
108689
108689
  let configProvider;
108690
108690
  if (typeof config10 === "function") {
108691
108691
  configProvider = config10;
@@ -108696,13 +108696,13 @@ var init_DeviceCertification = __esm({
108696
108696
  if (product === void 0) {
108697
108697
  throw new ImplementationError(`Cannot generate device certification without product information`);
108698
108698
  }
108699
- const paa = await AttestationCertificateManager.create(crypto7, product.vendorId);
108699
+ const paa = await AttestationCertificateManager.create(crypto8, product.vendorId);
108700
108700
  const { keyPair: dacKeyPair, dac } = await paa.getDACert(product.productId);
108701
108701
  return {
108702
108702
  privateKey: PrivateKey(dacKeyPair.privateKey),
108703
108703
  certificate: dac,
108704
108704
  intermediateCertificate: await paa.getPAICert(),
108705
- declaration: await CertificationDeclaration2.generate(crypto7, product.vendorId, product.productId)
108705
+ declaration: await CertificationDeclaration2.generate(crypto8, product.vendorId, product.productId)
108706
108706
  };
108707
108707
  };
108708
108708
  }
@@ -109493,8 +109493,8 @@ var init_OtaImageReader = __esm({
109493
109493
  return reader.#headerData;
109494
109494
  }
109495
109495
  /** Read and validate the full OTA image file from the stream and returns the header data on success. */
109496
- static async file(streamReader, crypto7, expectedTotalSize, options) {
109497
- const reader = new _OtaImageReader(streamReader, crypto7);
109496
+ static async file(streamReader, crypto8, expectedTotalSize, options) {
109497
+ const reader = new _OtaImageReader(streamReader, crypto8);
109498
109498
  if (options?.checksumType !== void 0) {
109499
109499
  reader.#fullFileChecksumType = options.checksumType;
109500
109500
  }
@@ -109528,8 +109528,8 @@ var init_OtaImageReader = __esm({
109528
109528
  * Read and validate OTA file, extracting payload to a writable stream.
109529
109529
  * Returns the header information after successful validation and extraction.
109530
109530
  */
109531
- static async extractPayload(streamReader, payloadWriter, crypto7, expectedTotalSize) {
109532
- const reader = new _OtaImageReader(streamReader, crypto7);
109531
+ static async extractPayload(streamReader, payloadWriter, crypto8, expectedTotalSize) {
109532
+ const reader = new _OtaImageReader(streamReader, crypto8);
109533
109533
  const { remainingData } = await reader.#processHeader(false);
109534
109534
  if (reader.#headerData === void 0) {
109535
109535
  throw new InternalError("OTA header not read");
@@ -109545,9 +109545,9 @@ var init_OtaImageReader = __esm({
109545
109545
  }
109546
109546
  return reader.#headerData;
109547
109547
  }
109548
- constructor(streamReader, crypto7) {
109548
+ constructor(streamReader, crypto8) {
109549
109549
  this.#streamReader = streamReader;
109550
- this.#crypto = crypto7;
109550
+ this.#crypto = crypto8;
109551
109551
  }
109552
109552
  get totalSize() {
109553
109553
  return this.#totalSize;
@@ -125833,8 +125833,8 @@ var init_VendorIdVerification = __esm({
125833
125833
  }
125834
125834
  VendorIdVerification2.dataToSign = dataToSign;
125835
125835
  async function verify(node, options) {
125836
- const crypto7 = node.env.get(Crypto);
125837
- const clientChallenge = crypto7.randomBytes(32);
125836
+ const crypto8 = node.env.get(Crypto);
125837
+ const clientChallenge = crypto8.randomBytes(32);
125838
125838
  const {
125839
125839
  fabric: { fabricIndex }
125840
125840
  } = options;
@@ -125857,7 +125857,7 @@ var init_VendorIdVerification = __esm({
125857
125857
  return void 0;
125858
125858
  }
125859
125859
  const { noc, rcac, fabric } = options;
125860
- return await verifyData(crypto7, {
125860
+ return await verifyData(crypto8, {
125861
125861
  clientChallenge,
125862
125862
  attChallenge: session.attestationChallengeKey,
125863
125863
  signVerificationResponse,
@@ -125867,7 +125867,7 @@ var init_VendorIdVerification = __esm({
125867
125867
  });
125868
125868
  }
125869
125869
  VendorIdVerification2.verify = verify;
125870
- async function verifyData(crypto7, options) {
125870
+ async function verifyData(crypto8, options) {
125871
125871
  const {
125872
125872
  clientChallenge,
125873
125873
  attChallenge,
@@ -125893,14 +125893,14 @@ var init_VendorIdVerification = __esm({
125893
125893
  }
125894
125894
  }).signatureData;
125895
125895
  try {
125896
- await crypto7.verifyEcdsa(PublicKey(rootPublicKey), tbs, new EcdsaSignature(signature));
125896
+ await crypto8.verifyEcdsa(PublicKey(rootPublicKey), tbs, new EcdsaSignature(signature));
125897
125897
  const rootCert = Rcac.fromTlv(rcac);
125898
125898
  const nocCert = Noc.fromTlv(noc);
125899
125899
  const icaCert = icac ? Icac.fromTlv(icac) : void 0;
125900
125900
  if (icaCert !== void 0) {
125901
- await icaCert.verify(crypto7, rootCert);
125901
+ await icaCert.verify(crypto8, rootCert);
125902
125902
  }
125903
- await nocCert.verify(crypto7, rootCert, icaCert);
125903
+ await nocCert.verify(crypto8, rootCert, icaCert);
125904
125904
  } catch (error) {
125905
125905
  CryptoError.accept(error);
125906
125906
  logger103.error("Could not verify VendorId", error);
@@ -125930,13 +125930,13 @@ var init_VendorIdVerification = __esm({
125930
125930
  `VVSC SubjectKeyIdentifier does not match signerSkid in VID Verification Statement`
125931
125931
  );
125932
125932
  }
125933
- await vvscCert.verify(crypto7);
125933
+ await vvscCert.verify(crypto8);
125934
125934
  const ourStatement = createStatementBytes({
125935
125935
  version: vidStatementVersion,
125936
125936
  fabricBindingMessage: tbs,
125937
125937
  signerSkid
125938
125938
  });
125939
- await crypto7.verifyEcdsa(
125939
+ await crypto8.verifyEcdsa(
125940
125940
  PublicKey(ellipticCurvePublicKey),
125941
125941
  ourStatement,
125942
125942
  new EcdsaSignature(vidStatementSignature)
@@ -130205,8 +130205,8 @@ var init_OtaSoftwareUpdateProviderServer = __esm({
130205
130205
  // the usual bdx session timeout is 5 minutes, so let's use this
130206
130206
  };
130207
130207
  }
130208
- const crypto7 = this.env.get(Crypto);
130209
- const updateToken = crypto7.randomBytes(OTA_UPDATE_TOKEN_LENGTH_BYTES);
130208
+ const crypto8 = this.env.get(Crypto);
130209
+ const updateToken = crypto8.randomBytes(OTA_UPDATE_TOKEN_LENGTH_BYTES);
130210
130210
  if (consentRequired && !request.requestorCanConsent) {
130211
130211
  this.#updateInProgressDetails(peerAddress, updateToken, OtaUpdateStatus.WaitForConsent, newSoftwareVersion);
130212
130212
  const { consentState, delayTime = Seconds(120) } = await this.requestUserConsentForUpdate(
@@ -132681,8 +132681,8 @@ var init_OtaSoftwareUpdateRequestorServer = __esm({
132681
132681
  try {
132682
132682
  const blob = await this.downloadLocation.openBlob();
132683
132683
  totalSize = blob.size;
132684
- const crypto7 = this.env.get(Crypto);
132685
- const header = await OtaImageReader.file(blob.stream().getReader(), crypto7);
132684
+ const crypto8 = this.env.get(Crypto);
132685
+ const header = await OtaImageReader.file(blob.stream().getReader(), crypto8);
132686
132686
  const { softwareVersion: otaFileSoftwareVersion } = header;
132687
132687
  if (newSoftwareVersion === void 0) {
132688
132688
  const { softwareVersion: currentSoftwareVersion } = this.#basicInformationState();
@@ -141853,9 +141853,9 @@ var init_ServerNetworkRuntime = __esm({
141853
141853
  lifetime: this.construction,
141854
141854
  ...this.owner.state.commissioning.mdns
141855
141855
  };
141856
- const crypto7 = this.owner.env.get(Crypto);
141856
+ const crypto8 = this.owner.env.get(Crypto);
141857
141857
  const { server } = this.#services.get(MdnsService);
141858
- this.#mdnsAdvertiser = new MdnsAdvertiser(crypto7, server, { ...options, port });
141858
+ this.#mdnsAdvertiser = new MdnsAdvertiser(crypto8, server, { ...options, port });
141859
141859
  }
141860
141860
  return this.#mdnsAdvertiser;
141861
141861
  }
@@ -145421,14 +145421,14 @@ function rootDirOf(env) {
145421
145421
  function configureCrypto(env) {
145422
145422
  Boot.init(() => {
145423
145423
  if (env.vars.boolean("nodejs.crypto")) {
145424
- let crypto7;
145424
+ let crypto8;
145425
145425
  if (!isBunjs()) {
145426
- crypto7 = new NodeJsCrypto();
145426
+ crypto8 = new NodeJsCrypto();
145427
145427
  } else {
145428
- crypto7 = new StandardCrypto(global.crypto);
145428
+ crypto8 = new StandardCrypto(global.crypto);
145429
145429
  }
145430
- env.set(Entropy, crypto7);
145431
- env.set(Crypto, crypto7);
145430
+ env.set(Entropy, crypto8);
145431
+ env.set(Crypto, crypto8);
145432
145432
  return;
145433
145433
  }
145434
145434
  if (Environment.default.has(Entropy)) {
@@ -159417,6 +159417,7 @@ var DimmablePlugInUnitDeviceDefinition = MutableEndpoint({
159417
159417
  )
159418
159418
  });
159419
159419
  Object.freeze(DimmablePlugInUnitDeviceDefinition);
159420
+ var DimmablePlugInUnitDevice = DimmablePlugInUnitDeviceDefinition;
159420
159421
 
159421
159422
  // ../../node_modules/.pnpm/@matter+node@0.16.10/node_modules/@matter/node/dist/esm/devices/dimmer-switch.js
159422
159423
  init_IdentifyServer();
@@ -164696,10 +164697,6 @@ import * as path12 from "node:path";
164696
164697
  // src/plugins/plugin-device-factory.ts
164697
164698
  init_esm();
164698
164699
 
164699
- // src/matter/behaviors/basic-information-server.ts
164700
- init_esm7();
164701
- import crypto4 from "node:crypto";
164702
-
164703
164700
  // ../../node_modules/.pnpm/@matter+main@0.16.10/node_modules/@matter/main/dist/esm/behaviors.js
164704
164701
  init_nodejs();
164705
164702
 
@@ -165657,92 +165654,14 @@ init_window_covering();
165657
165654
  init_ClientBehavior();
165658
165655
  var WindowCoveringClientConstructor = ClientBehavior(WindowCovering3.Complete);
165659
165656
 
165660
- // src/services/bridges/bridge-data-provider.ts
165661
- init_service();
165662
- import { values as values2 } from "lodash-es";
165663
- var BridgeDataProvider = class extends Service {
165664
- data;
165665
- constructor(initial) {
165666
- super("BridgeDataProvider");
165667
- this.data = Object.assign({}, initial);
165668
- }
165669
- /************************************************
165670
- * BridgeData interface
165671
- ************************************************/
165672
- get id() {
165673
- return this.data.id;
165674
- }
165675
- get basicInformation() {
165676
- return this.data.basicInformation;
165677
- }
165678
- get name() {
165679
- return this.data.name;
165680
- }
165681
- get port() {
165682
- return this.data.port;
165683
- }
165684
- get filter() {
165685
- return this.data.filter;
165686
- }
165687
- get featureFlags() {
165688
- return this.data.featureFlags;
165689
- }
165690
- get countryCode() {
165691
- return this.data.countryCode;
165692
- }
165693
- get icon() {
165694
- return this.data.icon;
165695
- }
165696
- get priority() {
165697
- return this.data.priority;
165698
- }
165699
- /************************************************
165700
- * Functions
165701
- ************************************************/
165702
- update(data) {
165703
- if (this.id !== data.id) {
165704
- throw new Error("ID of update request does not match bridge data id.");
165705
- }
165706
- Object.assign(this.data, data);
165707
- }
165708
- /**
165709
- * @deprecated
165710
- */
165711
- withMetadata(status3, serverNode, deviceCount, failedEntities = []) {
165712
- const commissioning = serverNode.state.commissioning;
165713
- return {
165714
- id: this.id,
165715
- name: this.name,
165716
- filter: this.filter,
165717
- port: this.port,
165718
- featureFlags: this.featureFlags,
165719
- basicInformation: this.basicInformation,
165720
- countryCode: this.countryCode,
165721
- icon: this.icon,
165722
- priority: this.priority,
165723
- status: status3.code,
165724
- statusReason: status3.reason,
165725
- commissioning: commissioning ? {
165726
- isCommissioned: commissioning.commissioned,
165727
- passcode: commissioning.passcode,
165728
- discriminator: commissioning.discriminator,
165729
- manualPairingCode: commissioning.pairingCodes.manualPairingCode,
165730
- qrPairingCode: commissioning.pairingCodes.qrPairingCode,
165731
- fabrics: values2(commissioning.fabrics).map((fabric) => ({
165732
- fabricIndex: fabric.fabricIndex,
165733
- fabricId: Number(fabric.fabricId),
165734
- nodeId: Number(fabric.nodeId),
165735
- rootNodeId: Number(fabric.rootNodeId),
165736
- rootVendorId: fabric.rootVendorId,
165737
- label: fabric.label
165738
- }))
165739
- } : void 0,
165740
- deviceCount,
165741
- failedEntities: failedEntities.length > 0 ? failedEntities : void 0
165742
- };
165743
- }
165657
+ // src/matter/behaviors/identify-server.ts
165658
+ var IdentifyServer2 = class extends IdentifyServer {
165744
165659
  };
165745
165660
 
165661
+ // src/plugins/plugin-basic-information-server.ts
165662
+ init_esm7();
165663
+ import crypto4 from "node:crypto";
165664
+
165746
165665
  // src/utils/apply-patch-state.ts
165747
165666
  init_esm();
165748
165667
  var logger158 = Logger.get("ApplyPatchState");
@@ -165811,56 +165730,6 @@ function deepEqual(a, b) {
165811
165730
  return a === b;
165812
165731
  }
165813
165732
 
165814
- // src/matter/behaviors/basic-information-server.ts
165815
- init_home_assistant_entity_behavior();
165816
- var BasicInformationServer2 = class extends BridgedDeviceBasicInformationServer {
165817
- async initialize() {
165818
- await super.initialize();
165819
- const homeAssistant = await this.agent.load(HomeAssistantEntityBehavior);
165820
- this.update(homeAssistant.entity);
165821
- this.reactTo(homeAssistant.onChange, this.update);
165822
- }
165823
- update(entity) {
165824
- if (!entity.state) {
165825
- return;
165826
- }
165827
- const { basicInformation } = this.env.get(BridgeDataProvider);
165828
- const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
165829
- const device = entity.deviceRegistry;
165830
- applyPatchState(this.state, {
165831
- vendorId: VendorId(basicInformation.vendorId),
165832
- vendorName: ellipse(32, device?.manufacturer) ?? hash(32, basicInformation.vendorName),
165833
- productName: ellipse(32, device?.model_id) ?? ellipse(32, device?.model) ?? hash(32, basicInformation.productName),
165834
- productLabel: ellipse(64, device?.model) ?? hash(64, basicInformation.productLabel),
165835
- hardwareVersion: basicInformation.hardwareVersion,
165836
- softwareVersion: basicInformation.softwareVersion,
165837
- hardwareVersionString: ellipse(64, device?.hw_version),
165838
- softwareVersionString: ellipse(64, device?.sw_version),
165839
- nodeLabel: ellipse(32, homeAssistant.state.customName) ?? ellipse(32, entity.state?.attributes?.friendly_name) ?? ellipse(32, entity.entity_id),
165840
- reachable: entity.state?.state != null && entity.state.state !== "unavailable",
165841
- // The device serial number is available in `device?.serial_number`, but
165842
- // we're keeping it as the entity ID for now to avoid breaking existing
165843
- // deployments.
165844
- serialNumber: hash(32, entity.entity_id),
165845
- // UniqueId helps controllers (especially Alexa) identify devices across
165846
- // multiple fabric connections. Using MD5 hash of entity_id for stability.
165847
- uniqueId: crypto4.createHash("md5").update(entity.entity_id).digest("hex").substring(0, 32)
165848
- });
165849
- }
165850
- };
165851
- function ellipse(maxLength, value) {
165852
- return trimToLength(value, maxLength, "...");
165853
- }
165854
- function hash(maxLength, value) {
165855
- const hashLength = 4;
165856
- const suffix = crypto4.createHash("md5").update(value ?? "").digest("hex").substring(0, hashLength);
165857
- return trimToLength(value, maxLength, suffix);
165858
- }
165859
-
165860
- // src/matter/behaviors/identify-server.ts
165861
- var IdentifyServer2 = class extends IdentifyServer {
165862
- };
165863
-
165864
165733
  // src/plugins/plugin-behavior.ts
165865
165734
  init_esm7();
165866
165735
  var PluginDeviceBehavior = class extends Behavior {
@@ -165884,62 +165753,129 @@ var PluginDeviceBehavior = class extends Behavior {
165884
165753
  PluginDeviceBehavior2.Events = Events2;
165885
165754
  })(PluginDeviceBehavior || (PluginDeviceBehavior = {}));
165886
165755
 
165756
+ // src/plugins/plugin-basic-information-server.ts
165757
+ var PluginBasicInformationServer = class extends BridgedDeviceBasicInformationServer {
165758
+ async initialize() {
165759
+ await super.initialize();
165760
+ const pluginDevice = this.agent.get(PluginDeviceBehavior);
165761
+ const device = pluginDevice.device;
165762
+ applyPatchState(this.state, {
165763
+ vendorId: VendorId(65521),
165764
+ vendorName: truncate(32, pluginDevice.pluginName),
165765
+ productName: truncate(32, device.deviceType),
165766
+ nodeLabel: truncate(32, device.name),
165767
+ serialNumber: crypto4.createHash("md5").update(`plugin_${device.id}`).digest("hex").substring(0, 32),
165768
+ uniqueId: crypto4.createHash("md5").update(`plugin_${device.id}`).digest("hex").substring(0, 32),
165769
+ reachable: true
165770
+ });
165771
+ }
165772
+ };
165773
+ function truncate(maxLength, value) {
165774
+ if (value.length <= maxLength) return value;
165775
+ return `${value.substring(0, maxLength - 3)}...`;
165776
+ }
165777
+
165887
165778
  // src/plugins/plugin-device-factory.ts
165888
165779
  var logger159 = Logger.get("PluginDeviceFactory");
165889
165780
  var deviceTypeMap = {
165890
165781
  on_off_light: () => OnOffLightDevice.with(
165891
165782
  IdentifyServer2,
165892
- BasicInformationServer2,
165783
+ PluginBasicInformationServer,
165893
165784
  PluginDeviceBehavior
165894
165785
  ),
165895
165786
  dimmable_light: () => DimmableLightDevice.with(
165896
165787
  IdentifyServer2,
165897
- BasicInformationServer2,
165788
+ PluginBasicInformationServer,
165789
+ PluginDeviceBehavior
165790
+ ),
165791
+ color_temperature_light: () => ColorTemperatureLightDevice.with(
165792
+ IdentifyServer2,
165793
+ PluginBasicInformationServer,
165794
+ PluginDeviceBehavior
165795
+ ),
165796
+ extended_color_light: () => ExtendedColorLightDevice.with(
165797
+ IdentifyServer2,
165798
+ PluginBasicInformationServer,
165898
165799
  PluginDeviceBehavior
165899
165800
  ),
165900
165801
  on_off_plugin_unit: () => OnOffPlugInUnitDevice.with(
165901
165802
  IdentifyServer2,
165902
- BasicInformationServer2,
165803
+ PluginBasicInformationServer,
165804
+ PluginDeviceBehavior
165805
+ ),
165806
+ dimmable_plug_in_unit: () => DimmablePlugInUnitDevice.with(
165807
+ IdentifyServer2,
165808
+ PluginBasicInformationServer,
165903
165809
  PluginDeviceBehavior
165904
165810
  ),
165905
165811
  temperature_sensor: () => TemperatureSensorDevice.with(
165906
165812
  IdentifyServer2,
165907
- BasicInformationServer2,
165813
+ PluginBasicInformationServer,
165908
165814
  PluginDeviceBehavior
165909
165815
  ),
165910
165816
  humidity_sensor: () => HumiditySensorDevice.with(
165911
165817
  IdentifyServer2,
165912
- BasicInformationServer2,
165818
+ PluginBasicInformationServer,
165819
+ PluginDeviceBehavior
165820
+ ),
165821
+ pressure_sensor: () => PressureSensorDevice.with(
165822
+ IdentifyServer2,
165823
+ PluginBasicInformationServer,
165824
+ PluginDeviceBehavior
165825
+ ),
165826
+ flow_sensor: () => FlowSensorDevice.with(
165827
+ IdentifyServer2,
165828
+ PluginBasicInformationServer,
165913
165829
  PluginDeviceBehavior
165914
165830
  ),
165915
165831
  light_sensor: () => LightSensorDevice.with(
165916
165832
  IdentifyServer2,
165917
- BasicInformationServer2,
165833
+ PluginBasicInformationServer,
165918
165834
  PluginDeviceBehavior
165919
165835
  ),
165920
165836
  occupancy_sensor: () => OccupancySensorDevice.with(
165921
165837
  IdentifyServer2,
165922
- BasicInformationServer2,
165838
+ PluginBasicInformationServer,
165923
165839
  PluginDeviceBehavior
165924
165840
  ),
165925
165841
  contact_sensor: () => ContactSensorDevice.with(
165926
165842
  IdentifyServer2,
165927
- BasicInformationServer2,
165843
+ PluginBasicInformationServer,
165844
+ PluginDeviceBehavior
165845
+ ),
165846
+ air_quality_sensor: () => AirQualitySensorDevice.with(
165847
+ IdentifyServer2,
165848
+ PluginBasicInformationServer,
165928
165849
  PluginDeviceBehavior
165929
165850
  ),
165930
165851
  thermostat: () => ThermostatDevice.with(
165931
165852
  IdentifyServer2,
165932
- BasicInformationServer2,
165853
+ PluginBasicInformationServer,
165933
165854
  PluginDeviceBehavior
165934
165855
  ),
165935
165856
  door_lock: () => DoorLockDevice.with(
165936
165857
  IdentifyServer2,
165937
- BasicInformationServer2,
165858
+ PluginBasicInformationServer,
165938
165859
  PluginDeviceBehavior
165939
165860
  ),
165940
165861
  fan: () => FanDevice.with(
165941
165862
  IdentifyServer2,
165942
- BasicInformationServer2,
165863
+ PluginBasicInformationServer,
165864
+ PluginDeviceBehavior
165865
+ ),
165866
+ window_covering: () => WindowCoveringDevice.with(
165867
+ IdentifyServer2,
165868
+ PluginBasicInformationServer,
165869
+ PluginDeviceBehavior
165870
+ ),
165871
+ generic_switch: () => GenericSwitchDevice.with(
165872
+ IdentifyServer2,
165873
+ PluginBasicInformationServer,
165874
+ PluginDeviceBehavior
165875
+ ),
165876
+ water_leak_detector: () => WaterLeakDetectorDevice.with(
165877
+ IdentifyServer2,
165878
+ PluginBasicInformationServer,
165943
165879
  PluginDeviceBehavior
165944
165880
  )
165945
165881
  };
@@ -165960,10 +165896,12 @@ init_esm();
165960
165896
  import * as fs10 from "node:fs";
165961
165897
  import * as path11 from "node:path";
165962
165898
  var logger160 = Logger.get("PluginStorage");
165899
+ var SAVE_DEBOUNCE_MS = 500;
165963
165900
  var FilePluginStorage = class {
165964
165901
  data = {};
165965
165902
  dirty = false;
165966
165903
  filePath;
165904
+ saveTimer;
165967
165905
  constructor(storageDir, pluginName) {
165968
165906
  const safePluginName = pluginName.replace(/[^a-zA-Z0-9_-]/g, "_");
165969
165907
  this.filePath = path11.join(storageDir, `plugin-${safePluginName}.json`);
@@ -165976,12 +165914,12 @@ var FilePluginStorage = class {
165976
165914
  async set(key, value) {
165977
165915
  this.data[key] = value;
165978
165916
  this.dirty = true;
165979
- this.save();
165917
+ this.scheduleSave();
165980
165918
  }
165981
165919
  async delete(key) {
165982
165920
  delete this.data[key];
165983
165921
  this.dirty = true;
165984
- this.save();
165922
+ this.scheduleSave();
165985
165923
  }
165986
165924
  async keys() {
165987
165925
  return Object.keys(this.data);
@@ -165997,8 +165935,16 @@ var FilePluginStorage = class {
165997
165935
  this.data = {};
165998
165936
  }
165999
165937
  }
165938
+ scheduleSave() {
165939
+ if (this.saveTimer) clearTimeout(this.saveTimer);
165940
+ this.saveTimer = setTimeout(() => this.save(), SAVE_DEBOUNCE_MS);
165941
+ }
166000
165942
  save() {
166001
165943
  if (!this.dirty) return;
165944
+ if (this.saveTimer) {
165945
+ clearTimeout(this.saveTimer);
165946
+ this.saveTimer = void 0;
165947
+ }
166002
165948
  try {
166003
165949
  const dir = path11.dirname(this.filePath);
166004
165950
  if (!fs10.existsSync(dir)) {
@@ -166010,6 +165956,9 @@ var FilePluginStorage = class {
166010
165956
  logger160.warn(`Failed to save plugin storage to ${this.filePath}:`, e);
166011
165957
  }
166012
165958
  }
165959
+ flush() {
165960
+ this.save();
165961
+ }
166013
165962
  };
166014
165963
 
166015
165964
  // src/plugins/safe-plugin-runner.ts
@@ -166126,11 +166075,15 @@ var SafePluginRunner = class {
166126
166075
 
166127
166076
  // src/plugins/plugin-manager.ts
166128
166077
  var logger162 = Logger.get("PluginManager");
166078
+ var PLUGIN_API_VERSION = 1;
166079
+ var MAX_PLUGIN_DEVICE_ID_LENGTH = 100;
166129
166080
  function validatePluginDevice(device) {
166130
166081
  if (!device || typeof device !== "object") return "device must be an object";
166131
166082
  const d = device;
166132
166083
  if (!d.id || typeof d.id !== "string")
166133
166084
  return "device.id must be a non-empty string";
166085
+ if (d.id.length > MAX_PLUGIN_DEVICE_ID_LENGTH)
166086
+ return `device.id too long (${d.id.length} chars, max ${MAX_PLUGIN_DEVICE_ID_LENGTH})`;
166134
166087
  if (!d.name || typeof d.name !== "string")
166135
166088
  return "device.name must be a non-empty string";
166136
166089
  if (!d.deviceType || typeof d.deviceType !== "string")
@@ -166197,6 +166150,11 @@ var PluginManager = class {
166197
166150
  if (!manifest.main || typeof manifest.main !== "string") {
166198
166151
  throw new Error(`Plugin at ${packagePath} package.json missing "main"`);
166199
166152
  }
166153
+ if (manifest.hamhPluginApiVersion != null && manifest.hamhPluginApiVersion !== PLUGIN_API_VERSION) {
166154
+ logger162.warn(
166155
+ `Plugin "${manifest.name}" declares API version ${manifest.hamhPluginApiVersion}, current is ${PLUGIN_API_VERSION}. It may not work correctly.`
166156
+ );
166157
+ }
166200
166158
  const module = await this.runner.run(
166201
166159
  manifest.name,
166202
166160
  "import",
@@ -166345,6 +166303,10 @@ var PluginManager = class {
166345
166303
  () => instance.plugin.onShutdown(reason)
166346
166304
  );
166347
166305
  }
166306
+ const storage2 = instance.context.storage;
166307
+ if (storage2 instanceof FilePluginStorage) {
166308
+ storage2.flush();
166309
+ }
166348
166310
  instance.started = false;
166349
166311
  logger162.info(`Plugin "${name}" shut down`);
166350
166312
  }
@@ -167102,6 +167064,92 @@ ${e?.toString()}`);
167102
167064
  }
167103
167065
  };
167104
167066
 
167067
+ // src/services/bridges/bridge-data-provider.ts
167068
+ init_service();
167069
+ import { values as values2 } from "lodash-es";
167070
+ var BridgeDataProvider = class extends Service {
167071
+ data;
167072
+ constructor(initial) {
167073
+ super("BridgeDataProvider");
167074
+ this.data = Object.assign({}, initial);
167075
+ }
167076
+ /************************************************
167077
+ * BridgeData interface
167078
+ ************************************************/
167079
+ get id() {
167080
+ return this.data.id;
167081
+ }
167082
+ get basicInformation() {
167083
+ return this.data.basicInformation;
167084
+ }
167085
+ get name() {
167086
+ return this.data.name;
167087
+ }
167088
+ get port() {
167089
+ return this.data.port;
167090
+ }
167091
+ get filter() {
167092
+ return this.data.filter;
167093
+ }
167094
+ get featureFlags() {
167095
+ return this.data.featureFlags;
167096
+ }
167097
+ get countryCode() {
167098
+ return this.data.countryCode;
167099
+ }
167100
+ get icon() {
167101
+ return this.data.icon;
167102
+ }
167103
+ get priority() {
167104
+ return this.data.priority;
167105
+ }
167106
+ /************************************************
167107
+ * Functions
167108
+ ************************************************/
167109
+ update(data) {
167110
+ if (this.id !== data.id) {
167111
+ throw new Error("ID of update request does not match bridge data id.");
167112
+ }
167113
+ Object.assign(this.data, data);
167114
+ }
167115
+ /**
167116
+ * @deprecated
167117
+ */
167118
+ withMetadata(status3, serverNode, deviceCount, failedEntities = []) {
167119
+ const commissioning = serverNode.state.commissioning;
167120
+ return {
167121
+ id: this.id,
167122
+ name: this.name,
167123
+ filter: this.filter,
167124
+ port: this.port,
167125
+ featureFlags: this.featureFlags,
167126
+ basicInformation: this.basicInformation,
167127
+ countryCode: this.countryCode,
167128
+ icon: this.icon,
167129
+ priority: this.priority,
167130
+ status: status3.code,
167131
+ statusReason: status3.reason,
167132
+ commissioning: commissioning ? {
167133
+ isCommissioned: commissioning.commissioned,
167134
+ passcode: commissioning.passcode,
167135
+ discriminator: commissioning.discriminator,
167136
+ manualPairingCode: commissioning.pairingCodes.manualPairingCode,
167137
+ qrPairingCode: commissioning.pairingCodes.qrPairingCode,
167138
+ fabrics: values2(commissioning.fabrics).map((fabric) => ({
167139
+ fabricIndex: fabric.fabricIndex,
167140
+ fabricId: Number(fabric.fabricId),
167141
+ nodeId: Number(fabric.nodeId),
167142
+ rootNodeId: Number(fabric.rootNodeId),
167143
+ rootVendorId: fabric.rootVendorId,
167144
+ label: fabric.label
167145
+ }))
167146
+ } : void 0,
167147
+ deviceCount,
167148
+ failedEntities: failedEntities.length > 0 ? failedEntities : void 0
167149
+ };
167150
+ }
167151
+ };
167152
+
167105
167153
  // src/services/bridges/bridge-endpoint-manager.ts
167106
167154
  init_esm7();
167107
167155
  init_service();
@@ -167308,6 +167356,54 @@ function testBit(value, bitValue) {
167308
167356
  return !!(value & bitValue);
167309
167357
  }
167310
167358
 
167359
+ // src/matter/behaviors/basic-information-server.ts
167360
+ init_esm7();
167361
+ import crypto6 from "node:crypto";
167362
+ init_home_assistant_entity_behavior();
167363
+ var BasicInformationServer2 = class extends BridgedDeviceBasicInformationServer {
167364
+ async initialize() {
167365
+ await super.initialize();
167366
+ const homeAssistant = await this.agent.load(HomeAssistantEntityBehavior);
167367
+ this.update(homeAssistant.entity);
167368
+ this.reactTo(homeAssistant.onChange, this.update);
167369
+ }
167370
+ update(entity) {
167371
+ if (!entity.state) {
167372
+ return;
167373
+ }
167374
+ const { basicInformation } = this.env.get(BridgeDataProvider);
167375
+ const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
167376
+ const device = entity.deviceRegistry;
167377
+ applyPatchState(this.state, {
167378
+ vendorId: VendorId(basicInformation.vendorId),
167379
+ vendorName: ellipse(32, device?.manufacturer) ?? hash(32, basicInformation.vendorName),
167380
+ productName: ellipse(32, device?.model_id) ?? ellipse(32, device?.model) ?? hash(32, basicInformation.productName),
167381
+ productLabel: ellipse(64, device?.model) ?? hash(64, basicInformation.productLabel),
167382
+ hardwareVersion: basicInformation.hardwareVersion,
167383
+ softwareVersion: basicInformation.softwareVersion,
167384
+ hardwareVersionString: ellipse(64, device?.hw_version),
167385
+ softwareVersionString: ellipse(64, device?.sw_version),
167386
+ nodeLabel: ellipse(32, homeAssistant.state.customName) ?? ellipse(32, entity.state?.attributes?.friendly_name) ?? ellipse(32, entity.entity_id),
167387
+ reachable: entity.state?.state != null && entity.state.state !== "unavailable",
167388
+ // The device serial number is available in `device?.serial_number`, but
167389
+ // we're keeping it as the entity ID for now to avoid breaking existing
167390
+ // deployments.
167391
+ serialNumber: hash(32, entity.entity_id),
167392
+ // UniqueId helps controllers (especially Alexa) identify devices across
167393
+ // multiple fabric connections. Using MD5 hash of entity_id for stability.
167394
+ uniqueId: crypto6.createHash("md5").update(entity.entity_id).digest("hex").substring(0, 32)
167395
+ });
167396
+ }
167397
+ };
167398
+ function ellipse(maxLength, value) {
167399
+ return trimToLength(value, maxLength, "...");
167400
+ }
167401
+ function hash(maxLength, value) {
167402
+ const hashLength = 4;
167403
+ const suffix = crypto6.createHash("md5").update(value ?? "").digest("hex").substring(0, hashLength);
167404
+ return trimToLength(value, maxLength, suffix);
167405
+ }
167406
+
167311
167407
  // src/matter/endpoints/composed/composed-air-purifier-endpoint.ts
167312
167408
  init_home_assistant_entity_behavior();
167313
167409
 
@@ -177954,7 +178050,7 @@ var LegacyEndpoint = class _LegacyEndpoint extends EntityEndpoint {
177954
178050
 
177955
178051
  // src/services/home-assistant/api/subscribe-entities.ts
177956
178052
  init_esm();
177957
- import crypto6 from "node:crypto";
178053
+ import crypto7 from "node:crypto";
177958
178054
  import {
177959
178055
  getCollection
177960
178056
  } from "home-assistant-js-websocket";
@@ -178038,7 +178134,7 @@ var subscribeUpdates = (conn, store, entityIds) => {
178038
178134
  });
178039
178135
  };
178040
178136
  function createEntitiesHash(entityIds) {
178041
- return crypto6.createHash("sha256").update(entityIds.join(",")).digest("hex").substring(0, 16);
178137
+ return crypto7.createHash("sha256").update(entityIds.join(",")).digest("hex").substring(0, 16);
178042
178138
  }
178043
178139
  var entitiesColl = (conn, entityIds) => {
178044
178140
  if (atLeastHaVersion(conn.haVersion, 2022, 4, 0)) {