Skip to content

Commit a5924f8

Browse files
authored
chore: add bonjour service and AppleTV device info defaults (#53)
* chore: add bonjour service and appletv device info defaults * refactor: fix review comments from copilot * address review comments * address review comments * add proper reject and export types in correct way * adress review comments * address review comments
1 parent 612eb2b commit a5924f8

File tree

6 files changed

+918
-0
lines changed

6 files changed

+918
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { hostname } from 'node:os';
2+
3+
import { Opack2 } from '../encryption/index.js';
4+
import type { AppleTVDeviceInfo } from '../types.js';
5+
6+
type OpackSerialized = Buffer;
7+
8+
const DEFAULT_ALT_IRK = Buffer.from([
9+
0xe9, 0xe8, 0x2d, 0xc0, 0x6a, 0x49, 0x79, 0x6b, 0x56, 0x6f, 0x54, 0x00, 0x19,
10+
0xb1, 0xc7, 0x7b,
11+
]);
12+
const DEFAULT_BT_ADDR = '11:22:33:44:55:66';
13+
const DEFAULT_MAC_BUFFER = Buffer.from([0x11, 0x22, 0x33, 0x44, 0x55, 0x66]);
14+
const DEFAULT_PAIRING_SERIAL = 'AAAAAAAAAAAA';
15+
16+
/**
17+
* Creates a standardized Apple TV device information object with default values
18+
* and the specified identifier as the account ID.
19+
*
20+
* @param identifier - Unique identifier to use as the account ID
21+
* @returns Complete Apple TV device information object
22+
*/
23+
export function createAppleTVDeviceInfo(identifier: string): AppleTVDeviceInfo {
24+
return {
25+
altIRK: DEFAULT_ALT_IRK,
26+
btAddr: DEFAULT_BT_ADDR,
27+
mac: DEFAULT_MAC_BUFFER,
28+
remotePairingSerialNumber: DEFAULT_PAIRING_SERIAL,
29+
accountID: identifier,
30+
model: 'computer-model',
31+
name: hostname(),
32+
};
33+
}
34+
35+
/**
36+
* Encodes Apple TV device information into a binary buffer using Opack2 serialization.
37+
* This creates the device info object and immediately serializes it for transmission.
38+
*
39+
* @param identifier - Unique identifier to use as the account ID
40+
* @returns Serialized device information as a Buffer
41+
*/
42+
export function encodeAppleTVDeviceInfo(identifier: string): OpackSerialized {
43+
const deviceInfo = createAppleTVDeviceInfo(identifier);
44+
45+
// Cast to SerializableValue to ensure type compatibility with Opack2.dumps
46+
// The AppleTVDeviceInfo structure is compatible with OPACK2 serialization
47+
return Opack2.dumps(deviceInfo as Record<string, any>);
48+
}

src/lib/apple-tv/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Core exports
2+
export type {
3+
AppleTVDeviceInfo,
4+
PairingKeys,
5+
PairingResult,
6+
PairingConfig,
7+
TLV8Item,
8+
PairingDataComponentTypeValue,
9+
Opack2Value,
10+
Opack2Array,
11+
Opack2Dictionary,
12+
} from './types.js';
13+
export * from './errors.js';
14+
export * from './constants.js';
15+
export * from './utils/index.js';
16+
export * from './deviceInfo/index.js';
17+
export * from './encryption/index.js';
18+
export * from './tlv/index.js';
19+
export * from './srp/index.js';

0 commit comments

Comments
 (0)