@basmilius/apple-airplay 0.0.88 → 0.0.90

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.
package/dist/index.js CHANGED
@@ -1660,8 +1660,7 @@ class AirPlayStream extends EncryptionAwareConnection {
1660
1660
  const aad = data.subarray(offset, offset + 2);
1661
1661
  const ciphertext = data.subarray(offset + 2, offset + 2 + length);
1662
1662
  const authTag = data.subarray(offset + 2 + length, offset + 2 + length + 16);
1663
- const nonce = Buffer.alloc(12);
1664
- nonce.writeBigUInt64LE(BigInt(this.#encryption.readCount++), 4);
1663
+ const nonce = this.nonce(this.#encryption.readCount++);
1665
1664
  const plaintext = Chacha20.decrypt(this.#encryption.readKey, nonce, aad, ciphertext, authTag);
1666
1665
  result = Buffer.concat([result, plaintext]);
1667
1666
  offset += totalChunkLength;
@@ -1675,14 +1674,19 @@ class AirPlayStream extends EncryptionAwareConnection {
1675
1674
  const length = Math.min(total - offset, 1024);
1676
1675
  const leLength = Buffer.alloc(2);
1677
1676
  leLength.writeUInt16LE(length, 0);
1678
- const nonce = Buffer.alloc(12);
1679
- nonce.writeBigUInt64LE(BigInt(this.#encryption.writeCount++), 4);
1677
+ const nonce = this.nonce(this.#encryption.writeCount++);
1680
1678
  const encrypted = Chacha20.encrypt(this.#encryption.writeKey, nonce, leLength, data.subarray(offset, offset + length));
1681
1679
  offset += length;
1682
1680
  result = Buffer.concat([result, leLength, encrypted.ciphertext, encrypted.authTag]);
1683
1681
  }
1684
1682
  return result;
1685
1683
  }
1684
+ nonce(counter) {
1685
+ const nonceArray = new Uint8Array(12);
1686
+ const view = new DataView(nonceArray.buffer);
1687
+ view.setBigUint64(4, BigInt(counter), true);
1688
+ return Buffer.from(nonceArray);
1689
+ }
1686
1690
  }
1687
1691
 
1688
1692
  // src/dataStream.ts
@@ -1877,8 +1881,7 @@ class AirPlayDataStream extends AirPlayStream {
1877
1881
  }
1878
1882
  const frameLength = data.readUInt16LE(offset);
1879
1883
  offset += 2;
1880
- const nonce = Buffer.alloc(12);
1881
- nonce.writeBigUInt64LE(BigInt(readCount++), 4);
1884
+ const nonce = this.nonce(readCount++);
1882
1885
  const end = offset + frameLength + 16;
1883
1886
  if (end > data.length) {
1884
1887
  reporter.warn(`Truncated frame end=${end} length=${data.length}`);
@@ -1901,8 +1904,7 @@ class AirPlayDataStream extends AirPlayStream {
1901
1904
  offset += frame.length;
1902
1905
  const leLength = Buffer.alloc(2);
1903
1906
  leLength.writeUInt16LE(frame.length, 0);
1904
- const nonce = Buffer.alloc(12);
1905
- nonce.writeBigUInt64LE(BigInt(this.#encryption.writeCount++), 4);
1907
+ const nonce = this.nonce(this.#encryption.writeCount++);
1906
1908
  const encrypted = Chacha202.encrypt(this.#encryption.writeKey, nonce, leLength, frame);
1907
1909
  result.push(leLength, encrypted.ciphertext, encrypted.authTag);
1908
1910
  }
package/dist/stream.d.ts CHANGED
@@ -9,4 +9,5 @@ export default class AirPlayStream<TEventMap extends Record<string, any>> extend
9
9
  #private;
10
10
  decrypt(data: Buffer): Promise<Buffer>;
11
11
  encrypt(data: Buffer): Promise<Buffer>;
12
+ nonce(counter: number): Buffer;
12
13
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@basmilius/apple-airplay",
3
3
  "description": "Implementation of Apple's AirPlay2 in Node.js.",
4
- "version": "0.0.88",
4
+ "version": "0.0.90",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": {
@@ -41,8 +41,8 @@
41
41
  }
42
42
  },
43
43
  "dependencies": {
44
- "@basmilius/apple-common": "0.0.88",
45
- "@basmilius/apple-encoding": "0.0.88",
44
+ "@basmilius/apple-common": "0.0.90",
45
+ "@basmilius/apple-encoding": "0.0.90",
46
46
  "@bufbuild/protobuf": "^2.10.2"
47
47
  },
48
48
  "devDependencies": {