appium-ios-remotexpc 0.0.3 → 0.0.5
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/CHANGELOG.md +12 -0
- package/build/src/base-plist-service.d.ts +51 -0
- package/build/src/base-plist-service.d.ts.map +1 -0
- package/build/src/base-plist-service.js +61 -0
- package/build/src/base-socket-service.d.ts +15 -0
- package/build/src/base-socket-service.d.ts.map +1 -0
- package/build/src/base-socket-service.js +46 -0
- package/build/src/index.d.ts +9 -0
- package/build/src/index.d.ts.map +1 -0
- package/build/src/index.js +7 -0
- package/build/src/lib/apple-tv/constants.d.ts +77 -0
- package/build/src/lib/apple-tv/constants.d.ts.map +1 -0
- package/build/src/lib/apple-tv/constants.js +106 -0
- package/build/src/lib/apple-tv/encryption/chacha20-poly1305.d.ts +22 -0
- package/build/src/lib/apple-tv/encryption/chacha20-poly1305.d.ts.map +1 -0
- package/build/src/lib/apple-tv/encryption/chacha20-poly1305.js +97 -0
- package/build/src/lib/apple-tv/encryption/ed25519.d.ts +16 -0
- package/build/src/lib/apple-tv/encryption/ed25519.d.ts.map +1 -0
- package/build/src/lib/apple-tv/encryption/ed25519.js +93 -0
- package/build/src/lib/apple-tv/encryption/hkdf.d.ts +18 -0
- package/build/src/lib/apple-tv/encryption/hkdf.d.ts.map +1 -0
- package/build/src/lib/apple-tv/encryption/hkdf.js +73 -0
- package/build/src/lib/apple-tv/encryption/index.d.ts +5 -0
- package/build/src/lib/apple-tv/encryption/index.d.ts.map +1 -0
- package/build/src/lib/apple-tv/encryption/index.js +4 -0
- package/build/src/lib/apple-tv/encryption/opack2.d.ts +57 -0
- package/build/src/lib/apple-tv/encryption/opack2.d.ts.map +1 -0
- package/build/src/lib/apple-tv/encryption/opack2.js +203 -0
- package/build/src/lib/apple-tv/errors.d.ts +17 -0
- package/build/src/lib/apple-tv/errors.d.ts.map +1 -0
- package/build/src/lib/apple-tv/errors.js +30 -0
- package/build/src/lib/apple-tv/tlv/decoder.d.ts +19 -0
- package/build/src/lib/apple-tv/tlv/decoder.d.ts.map +1 -0
- package/build/src/lib/apple-tv/tlv/decoder.js +49 -0
- package/build/src/lib/apple-tv/tlv/encoder.d.ts +10 -0
- package/build/src/lib/apple-tv/tlv/encoder.d.ts.map +1 -0
- package/build/src/lib/apple-tv/tlv/encoder.js +20 -0
- package/build/src/lib/apple-tv/tlv/index.d.ts +4 -0
- package/build/src/lib/apple-tv/tlv/index.d.ts.map +1 -0
- package/build/src/lib/apple-tv/tlv/index.js +3 -0
- package/build/src/lib/apple-tv/tlv/pairing-tlv.d.ts +14 -0
- package/build/src/lib/apple-tv/tlv/pairing-tlv.d.ts.map +1 -0
- package/build/src/lib/apple-tv/tlv/pairing-tlv.js +27 -0
- package/build/src/lib/apple-tv/types.d.ts +36 -0
- package/build/src/lib/apple-tv/types.d.ts.map +1 -0
- package/build/src/lib/apple-tv/types.js +1 -0
- package/build/src/lib/apple-tv/utils/buffer-utils.d.ts +40 -0
- package/build/src/lib/apple-tv/utils/buffer-utils.d.ts.map +1 -0
- package/build/src/lib/apple-tv/utils/buffer-utils.js +76 -0
- package/build/src/lib/apple-tv/utils/index.d.ts +3 -0
- package/build/src/lib/apple-tv/utils/index.d.ts.map +1 -0
- package/build/src/lib/apple-tv/utils/index.js +2 -0
- package/build/src/lib/apple-tv/utils/uuid-generator.d.ts +9 -0
- package/build/src/lib/apple-tv/utils/uuid-generator.d.ts.map +1 -0
- package/build/src/lib/apple-tv/utils/uuid-generator.js +36 -0
- package/build/src/lib/lockdown/index.d.ts +87 -0
- package/build/src/lib/lockdown/index.d.ts.map +1 -0
- package/build/src/lib/lockdown/index.js +324 -0
- package/build/src/lib/pair-record/index.d.ts +3 -0
- package/build/src/lib/pair-record/index.d.ts.map +1 -0
- package/build/src/lib/pair-record/index.js +2 -0
- package/build/src/lib/pair-record/pair-record.d.ts +48 -0
- package/build/src/lib/pair-record/pair-record.d.ts.map +1 -0
- package/build/src/lib/pair-record/pair-record.js +85 -0
- package/build/src/lib/plist/binary-plist-creator.d.ts +14 -0
- package/build/src/lib/plist/binary-plist-creator.d.ts.map +1 -0
- package/build/src/lib/plist/binary-plist-creator.js +475 -0
- package/build/src/lib/plist/binary-plist-parser.d.ts +14 -0
- package/build/src/lib/plist/binary-plist-parser.d.ts.map +1 -0
- package/build/src/lib/plist/binary-plist-parser.js +449 -0
- package/build/src/lib/plist/constants.d.ts +36 -0
- package/build/src/lib/plist/constants.d.ts.map +1 -0
- package/build/src/lib/plist/constants.js +43 -0
- package/build/src/lib/plist/index.d.ts +14 -0
- package/build/src/lib/plist/index.d.ts.map +1 -0
- package/build/src/lib/plist/index.js +16 -0
- package/build/src/lib/plist/length-based-splitter.d.ts +43 -0
- package/build/src/lib/plist/length-based-splitter.d.ts.map +1 -0
- package/build/src/lib/plist/length-based-splitter.js +228 -0
- package/build/src/lib/plist/plist-creator.d.ts +8 -0
- package/build/src/lib/plist/plist-creator.d.ts.map +1 -0
- package/build/src/lib/plist/plist-creator.js +33 -0
- package/build/src/lib/plist/plist-decoder.d.ts +25 -0
- package/build/src/lib/plist/plist-decoder.d.ts.map +1 -0
- package/build/src/lib/plist/plist-decoder.js +103 -0
- package/build/src/lib/plist/plist-encoder.d.ts +10 -0
- package/build/src/lib/plist/plist-encoder.d.ts.map +1 -0
- package/build/src/lib/plist/plist-encoder.js +27 -0
- package/build/src/lib/plist/plist-parser.d.ts +9 -0
- package/build/src/lib/plist/plist-parser.d.ts.map +1 -0
- package/build/src/lib/plist/plist-parser.js +109 -0
- package/build/src/lib/plist/plist-service.d.ts +86 -0
- package/build/src/lib/plist/plist-service.d.ts.map +1 -0
- package/build/src/lib/plist/plist-service.js +180 -0
- package/build/src/lib/plist/unified-plist-creator.d.ts +9 -0
- package/build/src/lib/plist/unified-plist-creator.d.ts.map +1 -0
- package/build/src/lib/plist/unified-plist-creator.js +14 -0
- package/build/src/lib/plist/unified-plist-parser.d.ts +8 -0
- package/build/src/lib/plist/unified-plist-parser.d.ts.map +1 -0
- package/build/src/lib/plist/unified-plist-parser.js +23 -0
- package/build/src/lib/plist/utils.d.ts +97 -0
- package/build/src/lib/plist/utils.d.ts.map +1 -0
- package/build/src/lib/plist/utils.js +287 -0
- package/build/src/lib/remote-xpc/constants.d.ts +20 -0
- package/build/src/lib/remote-xpc/constants.d.ts.map +1 -0
- package/build/src/lib/remote-xpc/constants.js +21 -0
- package/build/src/lib/remote-xpc/handshake-frames.d.ts +74 -0
- package/build/src/lib/remote-xpc/handshake-frames.d.ts.map +1 -0
- package/build/src/lib/remote-xpc/handshake-frames.js +285 -0
- package/build/src/lib/remote-xpc/handshake.d.ts +14 -0
- package/build/src/lib/remote-xpc/handshake.d.ts.map +1 -0
- package/build/src/lib/remote-xpc/handshake.js +95 -0
- package/build/src/lib/remote-xpc/remote-xpc-connection.d.ts +55 -0
- package/build/src/lib/remote-xpc/remote-xpc-connection.d.ts.map +1 -0
- package/build/src/lib/remote-xpc/remote-xpc-connection.js +365 -0
- package/build/src/lib/remote-xpc/xpc-protocol.d.ts +22 -0
- package/build/src/lib/remote-xpc/xpc-protocol.d.ts.map +1 -0
- package/build/src/lib/remote-xpc/xpc-protocol.js +368 -0
- package/build/src/lib/tunnel/index.d.ts +69 -0
- package/build/src/lib/tunnel/index.d.ts.map +1 -0
- package/build/src/lib/tunnel/index.js +205 -0
- package/build/src/lib/tunnel/packet-stream-client.d.ts +46 -0
- package/build/src/lib/tunnel/packet-stream-client.d.ts.map +1 -0
- package/build/src/lib/tunnel/packet-stream-client.js +152 -0
- package/build/src/lib/tunnel/packet-stream-server.d.ts +37 -0
- package/build/src/lib/tunnel/packet-stream-server.d.ts.map +1 -0
- package/build/src/lib/tunnel/packet-stream-server.js +109 -0
- package/build/src/lib/tunnel/tunnel-api-client.d.ts +85 -0
- package/build/src/lib/tunnel/tunnel-api-client.d.ts.map +1 -0
- package/build/src/lib/tunnel/tunnel-api-client.js +207 -0
- package/build/src/lib/tunnel/tunnel-registry-server.d.ts +68 -0
- package/build/src/lib/tunnel/tunnel-registry-server.d.ts.map +1 -0
- package/build/src/lib/tunnel/tunnel-registry-server.js +351 -0
- package/build/src/lib/types.d.ts +238 -0
- package/build/src/lib/types.d.ts.map +1 -0
- package/build/src/lib/types.js +4 -0
- package/build/src/lib/usbmux/index.d.ts +177 -0
- package/build/src/lib/usbmux/index.d.ts.map +1 -0
- package/build/src/lib/usbmux/index.js +490 -0
- package/build/src/lib/usbmux/usbmux-decoder.d.ts +19 -0
- package/build/src/lib/usbmux/usbmux-decoder.d.ts.map +1 -0
- package/build/src/lib/usbmux/usbmux-decoder.js +38 -0
- package/build/src/lib/usbmux/usbmux-encoder.d.ts +12 -0
- package/build/src/lib/usbmux/usbmux-encoder.d.ts.map +1 -0
- package/build/src/lib/usbmux/usbmux-encoder.js +32 -0
- package/build/src/service-connection.d.ts +34 -0
- package/build/src/service-connection.d.ts.map +1 -0
- package/build/src/service-connection.js +51 -0
- package/build/src/services/index.d.ts +6 -0
- package/build/src/services/index.d.ts.map +1 -0
- package/build/src/services/index.js +5 -0
- package/build/src/services/ios/base-service.d.ts +35 -0
- package/build/src/services/ios/base-service.d.ts.map +1 -0
- package/build/src/services/ios/base-service.js +55 -0
- package/build/src/services/ios/diagnostic-service/index.d.ts +46 -0
- package/build/src/services/ios/diagnostic-service/index.d.ts.map +1 -0
- package/build/src/services/ios/diagnostic-service/index.js +169 -0
- package/build/src/services/ios/diagnostic-service/keys.d.ts +5 -0
- package/build/src/services/ios/diagnostic-service/keys.d.ts.map +1 -0
- package/build/src/services/ios/diagnostic-service/keys.js +770 -0
- package/build/src/services/ios/syslog-service/index.d.ts +91 -0
- package/build/src/services/ios/syslog-service/index.d.ts.map +1 -0
- package/build/src/services/ios/syslog-service/index.js +323 -0
- package/build/src/services/ios/tunnel-service/index.d.ts +17 -0
- package/build/src/services/ios/tunnel-service/index.d.ts.map +1 -0
- package/build/src/services/ios/tunnel-service/index.js +57 -0
- package/build/src/services.d.ts +14 -0
- package/build/src/services.d.ts.map +1 -0
- package/build/src/services.js +48 -0
- package/package.json +12 -3
- package/src/lib/apple-tv/constants.ts +42 -0
- package/src/lib/apple-tv/encryption/chacha20-poly1305.ts +147 -0
- package/src/lib/apple-tv/encryption/ed25519.ts +126 -0
- package/src/lib/apple-tv/encryption/hkdf.ts +95 -0
- package/src/lib/apple-tv/encryption/index.ts +11 -0
- package/src/lib/apple-tv/encryption/opack2.ts +257 -0
- package/.github/dependabot.yml +0 -38
- package/.github/workflows/format-check.yml +0 -43
- package/.github/workflows/lint-and-build.yml +0 -40
- package/.github/workflows/pr-title.yml +0 -16
- package/.github/workflows/publish.js.yml +0 -43
- package/.github/workflows/test-validation.yml +0 -40
- package/.mocharc.json +0 -8
- package/.prettierignore +0 -3
- package/.prettierrc +0 -17
- package/.releaserc +0 -48
- package/assets/images/ios-arch.png +0 -0
- package/eslint.config.js +0 -45
- package/npm-shrinkwrap.json +0 -2711
- package/test/integration/diagnostics-test.ts +0 -44
- package/test/integration/read-pair-record-test.ts +0 -39
- package/test/integration/tunnel-test.ts +0 -104
- package/test/unit/apple-tv/tlv/decoder.spec.ts +0 -144
- package/test/unit/apple-tv/tlv/encoder.spec.ts +0 -91
- package/test/unit/apple-tv/tlv/pairing-tlv.spec.ts +0 -101
- package/test/unit/apple-tv/tlv/tlv-integration.spec.ts +0 -146
- package/test/unit/apple-tv/utils/buffer-utils.spec.ts +0 -74
- package/test/unit/apple-tv/utils/uuid-generator.spec.ts +0 -39
- package/test/unit/fixtures/index.ts +0 -88
- package/test/unit/fixtures/usbmuxconnectmessage.bin +0 -0
- package/test/unit/fixtures/usbmuxlistdevicemessage.bin +0 -0
- package/test/unit/plist/error-handling.spec.ts +0 -101
- package/test/unit/plist/fixtures/sample.binary.plist +0 -0
- package/test/unit/plist/fixtures/sample.xml.plist +0 -38
- package/test/unit/plist/plist-parser.spec.ts +0 -283
- package/test/unit/plist/plist.spec.ts +0 -205
- package/test/unit/plist/tag-position-handling.spec.ts +0 -90
- package/test/unit/plist/unified-plist-parser.spec.ts +0 -227
- package/test/unit/plist/utils.spec.ts +0 -249
- package/test/unit/plist/xml-cleaning.spec.ts +0 -60
- package/test/unit/tunnel/tunnel-registry-server.spec.ts +0 -194
- package/test/unit/usbmux/usbmux-specs.ts +0 -71
- package/tsconfig.json +0 -36
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface HKDFParams {
|
|
2
|
+
ikm: Buffer;
|
|
3
|
+
salt: Buffer | null;
|
|
4
|
+
info: Buffer;
|
|
5
|
+
length: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* HMAC-based Key Derivation Function (HKDF) as defined in RFC 5869
|
|
9
|
+
* Derives cryptographic keys from input key material using a two-step process:
|
|
10
|
+
* 1. Extract: Generate a pseudorandom key from the input key material
|
|
11
|
+
* 2. Expand: Expand the pseudorandom key to the desired output length
|
|
12
|
+
*
|
|
13
|
+
* @param params - HKDF parameters including input key material, salt, info, and desired output length
|
|
14
|
+
* @returns Buffer containing the derived key material of specified length
|
|
15
|
+
* @throws CryptographyError if derivation fails or parameters are invalid
|
|
16
|
+
*/
|
|
17
|
+
export declare function hkdf(params: HKDFParams): Buffer;
|
|
18
|
+
//# sourceMappingURL=hkdf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hkdf.d.ts","sourceRoot":"","sources":["../../../../../src/lib/apple-tv/encryption/hkdf.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAID;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CA6B/C"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { logger } from '@appium/support';
|
|
2
|
+
import { createHmac } from 'node:crypto';
|
|
3
|
+
import { HKDF_HASH_ALGORITHM, HKDF_HASH_LENGTH } from '../constants.js';
|
|
4
|
+
import { CryptographyError } from '../errors.js';
|
|
5
|
+
const log = logger.getLogger('HKDF');
|
|
6
|
+
const MAX_OUTPUT_LENGTH = 255 * HKDF_HASH_LENGTH;
|
|
7
|
+
/**
|
|
8
|
+
* HMAC-based Key Derivation Function (HKDF) as defined in RFC 5869
|
|
9
|
+
* Derives cryptographic keys from input key material using a two-step process:
|
|
10
|
+
* 1. Extract: Generate a pseudorandom key from the input key material
|
|
11
|
+
* 2. Expand: Expand the pseudorandom key to the desired output length
|
|
12
|
+
*
|
|
13
|
+
* @param params - HKDF parameters including input key material, salt, info, and desired output length
|
|
14
|
+
* @returns Buffer containing the derived key material of specified length
|
|
15
|
+
* @throws CryptographyError if derivation fails or parameters are invalid
|
|
16
|
+
*/
|
|
17
|
+
export function hkdf(params) {
|
|
18
|
+
const { ikm, salt, info, length } = params;
|
|
19
|
+
if (!ikm || ikm.length === 0) {
|
|
20
|
+
throw new CryptographyError('Input key material (IKM) cannot be empty');
|
|
21
|
+
}
|
|
22
|
+
if (!info) {
|
|
23
|
+
throw new CryptographyError('Info parameter is required');
|
|
24
|
+
}
|
|
25
|
+
if (length <= 0) {
|
|
26
|
+
throw new CryptographyError('Output length must be positive');
|
|
27
|
+
}
|
|
28
|
+
if (length > MAX_OUTPUT_LENGTH) {
|
|
29
|
+
throw new CryptographyError(`Output length cannot exceed ${MAX_OUTPUT_LENGTH} bytes`);
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const extractedKey = hkdfExtract(ikm, salt);
|
|
33
|
+
return hkdfExpand(extractedKey, info, length);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
log.error('HKDF derivation failed:', error);
|
|
37
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
38
|
+
throw new CryptographyError(`HKDF derivation failed: ${message}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* HKDF Extract step: generates a pseudorandom key from input key material
|
|
43
|
+
* @param ikm - Input key material
|
|
44
|
+
* @param salt - Optional salt value (uses zero salt if null)
|
|
45
|
+
* @returns Pseudorandom key of hash length
|
|
46
|
+
*/
|
|
47
|
+
function hkdfExtract(ikm, salt) {
|
|
48
|
+
const actualSalt = salt || Buffer.alloc(HKDF_HASH_LENGTH);
|
|
49
|
+
return createHmac(HKDF_HASH_ALGORITHM, actualSalt).update(ikm).digest();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* HKDF Expand a step: expands a pseudorandom key to desired output length
|
|
53
|
+
* @param prk - Pseudorandom key from extract step
|
|
54
|
+
* @param info - Context and application specific information
|
|
55
|
+
* @param length - Desired output key material length
|
|
56
|
+
* @returns Output key material of specified length
|
|
57
|
+
*/
|
|
58
|
+
function hkdfExpand(prk, info, length) {
|
|
59
|
+
const numberOfBlocks = Math.ceil(length / HKDF_HASH_LENGTH);
|
|
60
|
+
const blocks = [];
|
|
61
|
+
let previousBlock = Buffer.alloc(0);
|
|
62
|
+
for (let blockIndex = 1; blockIndex <= numberOfBlocks; blockIndex++) {
|
|
63
|
+
const hmac = createHmac(HKDF_HASH_ALGORITHM, prk);
|
|
64
|
+
hmac.update(previousBlock);
|
|
65
|
+
hmac.update(info);
|
|
66
|
+
hmac.update(Buffer.from([blockIndex]));
|
|
67
|
+
const currentBlock = hmac.digest();
|
|
68
|
+
blocks.push(currentBlock);
|
|
69
|
+
previousBlock = currentBlock;
|
|
70
|
+
}
|
|
71
|
+
const outputKeyMaterial = Buffer.concat(blocks);
|
|
72
|
+
return outputKeyMaterial.subarray(0, length);
|
|
73
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Opack2 } from './opack2.js';
|
|
2
|
+
export { encryptChaCha20Poly1305, decryptChaCha20Poly1305, type ChaCha20Poly1305Params, } from './chacha20-poly1305.js';
|
|
3
|
+
export { generateEd25519KeyPair, createEd25519Signature } from './ed25519.js';
|
|
4
|
+
export { hkdf, type HKDFParams } from './hkdf.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/lib/apple-tv/encryption/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,KAAK,sBAAsB,GAC5B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAE9E,OAAO,EAAE,IAAI,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
interface SerializableArray extends Array<SerializableValue> {
|
|
2
|
+
}
|
|
3
|
+
interface SerializableObject extends Record<string, SerializableValue> {
|
|
4
|
+
}
|
|
5
|
+
type SerializableValue = null | undefined | boolean | number | string | Buffer | SerializableArray | SerializableObject;
|
|
6
|
+
/**
|
|
7
|
+
* OPACK2 binary serialization format encoder
|
|
8
|
+
* Implements Apple's OPACK2 protocol for efficient binary serialization of structured data
|
|
9
|
+
*/
|
|
10
|
+
export declare class Opack2 {
|
|
11
|
+
/**
|
|
12
|
+
* Serializes a JavaScript object to OPACK2 binary format
|
|
13
|
+
* @param obj - The object to serialize (supports primitives, arrays, objects, and Buffers)
|
|
14
|
+
* @returns Buffer containing the serialized data
|
|
15
|
+
* @throws AppleTVError if the object contains unsupported types
|
|
16
|
+
*/
|
|
17
|
+
static dumps(obj: SerializableValue): Buffer;
|
|
18
|
+
/**
|
|
19
|
+
* Main encoding dispatcher that routes values to appropriate type-specific encoders
|
|
20
|
+
* @param obj - Value to encode
|
|
21
|
+
* @returns Buffer containing encoded value
|
|
22
|
+
* @throws AppleTVError for unsupported types
|
|
23
|
+
*/
|
|
24
|
+
private static encode;
|
|
25
|
+
/**
|
|
26
|
+
* Encodes numeric values with the appropriate size optimization
|
|
27
|
+
* @param num - Number to encode
|
|
28
|
+
* @returns Buffer containing encoded number
|
|
29
|
+
*/
|
|
30
|
+
private static encodeNumber;
|
|
31
|
+
/**
|
|
32
|
+
* Encodes UTF-8 strings with length-optimized headers
|
|
33
|
+
* @param str - String to encode
|
|
34
|
+
* @returns Buffer containing encoded string
|
|
35
|
+
*/
|
|
36
|
+
private static encodeString;
|
|
37
|
+
/**
|
|
38
|
+
* Encodes binary data with length-optimized headers
|
|
39
|
+
* @param bytes - Buffer to encode
|
|
40
|
+
* @returns Buffer containing encoded binary data
|
|
41
|
+
*/
|
|
42
|
+
private static encodeBytes;
|
|
43
|
+
/**
|
|
44
|
+
* Encodes arrays with count-optimized headers
|
|
45
|
+
* @param arr - Array to encode
|
|
46
|
+
* @returns Buffer containing encoded array
|
|
47
|
+
*/
|
|
48
|
+
private static encodeArray;
|
|
49
|
+
/**
|
|
50
|
+
* Encodes objects/dictionaries with count-optimized headers
|
|
51
|
+
* @param dict - Object to encode
|
|
52
|
+
* @returns Buffer containing encoded dictionary
|
|
53
|
+
*/
|
|
54
|
+
private static encodeDict;
|
|
55
|
+
}
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=opack2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opack2.d.ts","sourceRoot":"","sources":["../../../../../src/lib/apple-tv/encryption/opack2.ts"],"names":[],"mappings":"AAGA,UAAU,iBAAkB,SAAQ,KAAK,CAAC,iBAAiB,CAAC;CAAG;AAC/D,UAAU,kBAAmB,SAAQ,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC;CAAG;AAEzE,KAAK,iBAAiB,GAClB,IAAI,GACJ,SAAS,GACT,OAAO,GACP,MAAM,GACN,MAAM,GACN,MAAM,GACN,iBAAiB,GACjB,kBAAkB,CAAC;AAEvB;;;GAGG;AACH,qBAAa,MAAM;IACjB;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,iBAAiB,GAAG,MAAM;IAI5C;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,MAAM;IAwCrB;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY;IAiC3B;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY;IAqC3B;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IAoC1B;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IAuB1B;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;CAyB1B"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import * as constants from '../constants.js';
|
|
2
|
+
import { AppleTVError } from '../errors.js';
|
|
3
|
+
/**
|
|
4
|
+
* OPACK2 binary serialization format encoder
|
|
5
|
+
* Implements Apple's OPACK2 protocol for efficient binary serialization of structured data
|
|
6
|
+
*/
|
|
7
|
+
export class Opack2 {
|
|
8
|
+
/**
|
|
9
|
+
* Serializes a JavaScript object to OPACK2 binary format
|
|
10
|
+
* @param obj - The object to serialize (supports primitives, arrays, objects, and Buffers)
|
|
11
|
+
* @returns Buffer containing the serialized data
|
|
12
|
+
* @throws AppleTVError if the object contains unsupported types
|
|
13
|
+
*/
|
|
14
|
+
static dumps(obj) {
|
|
15
|
+
return this.encode(obj);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Main encoding dispatcher that routes values to appropriate type-specific encoders
|
|
19
|
+
* @param obj - Value to encode
|
|
20
|
+
* @returns Buffer containing encoded value
|
|
21
|
+
* @throws AppleTVError for unsupported types
|
|
22
|
+
*/
|
|
23
|
+
static encode(obj) {
|
|
24
|
+
if (obj === null || obj === undefined) {
|
|
25
|
+
return Buffer.from([constants.OPACK2_NULL]);
|
|
26
|
+
}
|
|
27
|
+
if (typeof obj === 'boolean') {
|
|
28
|
+
return Buffer.from([
|
|
29
|
+
obj ? constants.OPACK2_TRUE : constants.OPACK2_FALSE,
|
|
30
|
+
]);
|
|
31
|
+
}
|
|
32
|
+
if (typeof obj === 'number') {
|
|
33
|
+
return this.encodeNumber(obj);
|
|
34
|
+
}
|
|
35
|
+
if (typeof obj === 'string') {
|
|
36
|
+
return this.encodeString(obj);
|
|
37
|
+
}
|
|
38
|
+
if (Buffer.isBuffer(obj)) {
|
|
39
|
+
return this.encodeBytes(obj);
|
|
40
|
+
}
|
|
41
|
+
if (Array.isArray(obj)) {
|
|
42
|
+
return this.encodeArray(obj);
|
|
43
|
+
}
|
|
44
|
+
if (typeof obj === 'object' &&
|
|
45
|
+
!Array.isArray(obj) &&
|
|
46
|
+
!Buffer.isBuffer(obj)) {
|
|
47
|
+
return this.encodeDict(obj);
|
|
48
|
+
}
|
|
49
|
+
throw new AppleTVError(`Unsupported type for OPACK2 serialization: ${typeof obj}`);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Encodes numeric values with the appropriate size optimization
|
|
53
|
+
* @param num - Number to encode
|
|
54
|
+
* @returns Buffer containing encoded number
|
|
55
|
+
*/
|
|
56
|
+
static encodeNumber(num) {
|
|
57
|
+
if (!Number.isInteger(num) || num < 0) {
|
|
58
|
+
const buffer = Buffer.allocUnsafe(5);
|
|
59
|
+
buffer[0] = constants.OPACK2_FLOAT_MARKER;
|
|
60
|
+
buffer.writeFloatLE(num, 1);
|
|
61
|
+
return buffer;
|
|
62
|
+
}
|
|
63
|
+
if (num <= constants.OPACK2_SMALL_INT_MAX) {
|
|
64
|
+
return Buffer.from([num + constants.OPACK2_SMALL_INT_OFFSET]);
|
|
65
|
+
}
|
|
66
|
+
if (num <= constants.OPACK2_UINT8_MAX) {
|
|
67
|
+
return Buffer.from([constants.OPACK2_INT8_MARKER, num]);
|
|
68
|
+
}
|
|
69
|
+
if (num <= constants.OPACK2_UINT32_MAX) {
|
|
70
|
+
const buffer = Buffer.allocUnsafe(5);
|
|
71
|
+
buffer[0] = constants.OPACK2_INT32_MARKER;
|
|
72
|
+
buffer.writeUInt32LE(num, 1);
|
|
73
|
+
return buffer;
|
|
74
|
+
}
|
|
75
|
+
if (num <= Number.MAX_SAFE_INTEGER) {
|
|
76
|
+
const buffer = Buffer.allocUnsafe(9);
|
|
77
|
+
buffer[0] = constants.OPACK2_INT64_MARKER;
|
|
78
|
+
buffer.writeBigUInt64LE(BigInt(num), 1);
|
|
79
|
+
return buffer;
|
|
80
|
+
}
|
|
81
|
+
throw new AppleTVError(`Number too large for OPACK2 encoding: ${num}`);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Encodes UTF-8 strings with length-optimized headers
|
|
85
|
+
* @param str - String to encode
|
|
86
|
+
* @returns Buffer containing encoded string
|
|
87
|
+
*/
|
|
88
|
+
static encodeString(str) {
|
|
89
|
+
const encoded = Buffer.from(str, 'utf8');
|
|
90
|
+
const length = encoded.length;
|
|
91
|
+
if (length <= constants.OPACK2_SMALL_STRING_MAX) {
|
|
92
|
+
return Buffer.concat([
|
|
93
|
+
Buffer.from([constants.OPACK2_SMALL_STRING_BASE + length]),
|
|
94
|
+
encoded,
|
|
95
|
+
]);
|
|
96
|
+
}
|
|
97
|
+
if (length <= constants.OPACK2_UINT8_MAX) {
|
|
98
|
+
return Buffer.concat([
|
|
99
|
+
Buffer.from([constants.OPACK2_STRING_8BIT_LEN_MARKER, length]),
|
|
100
|
+
encoded,
|
|
101
|
+
]);
|
|
102
|
+
}
|
|
103
|
+
if (length <= constants.OPACK2_UINT16_MAX) {
|
|
104
|
+
const header = Buffer.allocUnsafe(3);
|
|
105
|
+
header[0] = constants.OPACK2_STRING_16BIT_LEN_MARKER;
|
|
106
|
+
header.writeUInt16BE(length, 1);
|
|
107
|
+
return Buffer.concat([header, encoded]);
|
|
108
|
+
}
|
|
109
|
+
if (length <= constants.OPACK2_UINT32_MAX) {
|
|
110
|
+
const header = Buffer.allocUnsafe(5);
|
|
111
|
+
header[0] = constants.OPACK2_STRING_32BIT_LEN_MARKER;
|
|
112
|
+
header.writeUInt32BE(length, 1);
|
|
113
|
+
return Buffer.concat([header, encoded]);
|
|
114
|
+
}
|
|
115
|
+
throw new AppleTVError(`String too long for OPACK2 encoding: ${length} bytes`);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Encodes binary data with length-optimized headers
|
|
119
|
+
* @param bytes - Buffer to encode
|
|
120
|
+
* @returns Buffer containing encoded binary data
|
|
121
|
+
*/
|
|
122
|
+
static encodeBytes(bytes) {
|
|
123
|
+
const length = bytes.length;
|
|
124
|
+
if (length <= constants.OPACK2_SMALL_BYTES_MAX) {
|
|
125
|
+
return Buffer.concat([
|
|
126
|
+
Buffer.from([constants.OPACK2_SMALL_BYTES_BASE + length]),
|
|
127
|
+
bytes,
|
|
128
|
+
]);
|
|
129
|
+
}
|
|
130
|
+
if (length <= constants.OPACK2_UINT8_MAX) {
|
|
131
|
+
return Buffer.concat([
|
|
132
|
+
Buffer.from([constants.OPACK2_BYTES_8BIT_LEN_MARKER, length]),
|
|
133
|
+
bytes,
|
|
134
|
+
]);
|
|
135
|
+
}
|
|
136
|
+
if (length <= constants.OPACK2_UINT16_MAX) {
|
|
137
|
+
const header = Buffer.allocUnsafe(3);
|
|
138
|
+
header[0] = constants.OPACK2_BYTES_16BIT_LEN_MARKER;
|
|
139
|
+
header.writeUInt16BE(length, 1);
|
|
140
|
+
return Buffer.concat([header, bytes]);
|
|
141
|
+
}
|
|
142
|
+
if (length <= constants.OPACK2_UINT32_MAX) {
|
|
143
|
+
const header = Buffer.allocUnsafe(5);
|
|
144
|
+
header[0] = constants.OPACK2_BYTES_32BIT_LEN_MARKER;
|
|
145
|
+
header.writeUInt32BE(length, 1);
|
|
146
|
+
return Buffer.concat([header, bytes]);
|
|
147
|
+
}
|
|
148
|
+
throw new AppleTVError(`Byte array too long for OPACK2 encoding: ${length} bytes`);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Encodes arrays with count-optimized headers
|
|
152
|
+
* @param arr - Array to encode
|
|
153
|
+
* @returns Buffer containing encoded array
|
|
154
|
+
*/
|
|
155
|
+
static encodeArray(arr) {
|
|
156
|
+
const length = arr.length;
|
|
157
|
+
if (length <= constants.OPACK2_SMALL_ARRAY_MAX) {
|
|
158
|
+
const parts = [
|
|
159
|
+
Buffer.from([constants.OPACK2_SMALL_ARRAY_BASE + length]),
|
|
160
|
+
];
|
|
161
|
+
for (const item of arr) {
|
|
162
|
+
parts.push(this.encode(item));
|
|
163
|
+
}
|
|
164
|
+
return Buffer.concat(parts);
|
|
165
|
+
}
|
|
166
|
+
const parts = [
|
|
167
|
+
Buffer.from([constants.OPACK2_VARIABLE_ARRAY_MARKER]),
|
|
168
|
+
];
|
|
169
|
+
for (const item of arr) {
|
|
170
|
+
parts.push(this.encode(item));
|
|
171
|
+
}
|
|
172
|
+
parts.push(Buffer.from([constants.OPACK2_NULL]));
|
|
173
|
+
return Buffer.concat(parts);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Encodes objects/dictionaries with count-optimized headers
|
|
177
|
+
* @param dict - Object to encode
|
|
178
|
+
* @returns Buffer containing encoded dictionary
|
|
179
|
+
*/
|
|
180
|
+
static encodeDict(dict) {
|
|
181
|
+
const entries = Object.entries(dict);
|
|
182
|
+
const length = entries.length;
|
|
183
|
+
if (length < constants.OPACK2_SMALL_DICT_MAX) {
|
|
184
|
+
const parts = [
|
|
185
|
+
Buffer.from([constants.OPACK2_SMALL_DICT_BASE + length]),
|
|
186
|
+
];
|
|
187
|
+
for (const [key, value] of entries) {
|
|
188
|
+
parts.push(this.encode(key));
|
|
189
|
+
parts.push(this.encode(value));
|
|
190
|
+
}
|
|
191
|
+
return Buffer.concat(parts);
|
|
192
|
+
}
|
|
193
|
+
const parts = [
|
|
194
|
+
Buffer.from([constants.OPACK2_VARIABLE_DICT_MARKER]),
|
|
195
|
+
];
|
|
196
|
+
for (const [key, value] of entries) {
|
|
197
|
+
parts.push(this.encode(key));
|
|
198
|
+
parts.push(this.encode(value));
|
|
199
|
+
}
|
|
200
|
+
parts.push(Buffer.from([constants.OPACK2_NULL, constants.OPACK2_NULL]));
|
|
201
|
+
return Buffer.concat(parts);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class AppleTVError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class PairingError extends AppleTVError {
|
|
5
|
+
code?: string | undefined;
|
|
6
|
+
details?: any | undefined;
|
|
7
|
+
constructor(message: string, code?: string | undefined, details?: any | undefined);
|
|
8
|
+
}
|
|
9
|
+
export declare class NetworkError extends AppleTVError {
|
|
10
|
+
}
|
|
11
|
+
export declare class CryptographyError extends AppleTVError {
|
|
12
|
+
}
|
|
13
|
+
export declare class SRPError extends AppleTVError {
|
|
14
|
+
}
|
|
15
|
+
export declare class TLV8Error extends AppleTVError {
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../src/lib/apple-tv/errors.ts"],"names":[],"mappings":"AACA,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;CAK5B;AAGD,qBAAa,YAAa,SAAQ,YAAY;IAGnC,IAAI,CAAC,EAAE,MAAM;IACb,OAAO,CAAC,EAAE,GAAG;gBAFpB,OAAO,EAAE,MAAM,EACR,IAAI,CAAC,EAAE,MAAM,YAAA,EACb,OAAO,CAAC,EAAE,GAAG,YAAA;CAIvB;AAGD,qBAAa,YAAa,SAAQ,YAAY;CAAG;AAGjD,qBAAa,iBAAkB,SAAQ,YAAY;CAAG;AAGtD,qBAAa,QAAS,SAAQ,YAAY;CAAG;AAG7C,qBAAa,SAAU,SAAQ,YAAY;CAAG"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Base error class for all Apple TV related errors
|
|
2
|
+
export class AppleTVError extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = new.target.name;
|
|
6
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
// Represents an error that occurs during the pairing process
|
|
10
|
+
export class PairingError extends AppleTVError {
|
|
11
|
+
code;
|
|
12
|
+
details;
|
|
13
|
+
constructor(message, code, details) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.code = code;
|
|
16
|
+
this.details = details;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
// Represents an error related to network communication
|
|
20
|
+
export class NetworkError extends AppleTVError {
|
|
21
|
+
}
|
|
22
|
+
// Represents an error occurring during cryptographic operations
|
|
23
|
+
export class CryptographyError extends AppleTVError {
|
|
24
|
+
}
|
|
25
|
+
// Represents an error specific to SRP (Secure Remote Password) protocol
|
|
26
|
+
export class SRPError extends AppleTVError {
|
|
27
|
+
}
|
|
28
|
+
// Represents an error related to TLV8 encoding/decoding
|
|
29
|
+
export class TLV8Error extends AppleTVError {
|
|
30
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PairingDataComponentTypeValue, TLV8Item } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Decodes a TLV8-formatted buffer into an array of TLV8 items.
|
|
4
|
+
*
|
|
5
|
+
* @param buffer - A Node.js Buffer containing TLV8 encoded data
|
|
6
|
+
* @returns Array of TLV8Item objects with `type` and `data`
|
|
7
|
+
* @throws TLV8Error if the buffer does not contain valid TLV8 data
|
|
8
|
+
*/
|
|
9
|
+
export declare function decodeTLV8(buffer: Buffer): TLV8Item[];
|
|
10
|
+
/**
|
|
11
|
+
* Decodes a TLV8-formatted buffer into a dictionary mapping
|
|
12
|
+
* each TLV8 type to its corresponding data buffer. If the same
|
|
13
|
+
* type occurs more than once, their values are concatenated.
|
|
14
|
+
*
|
|
15
|
+
* @param buffer - A Node.js Buffer containing TLV8 encoded data
|
|
16
|
+
* @returns A dictionary of type-value mappings
|
|
17
|
+
*/
|
|
18
|
+
export declare function decodeTLV8ToDict(buffer: Buffer): Partial<Record<PairingDataComponentTypeValue, Buffer>>;
|
|
19
|
+
//# sourceMappingURL=decoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decoder.d.ts","sourceRoot":"","sources":["../../../../../src/lib/apple-tv/tlv/decoder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,6BAA6B,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE3E;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,EAAE,CA4BrD;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,6BAA6B,EAAE,MAAM,CAAC,CAAC,CAiBxD"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { TLV8Error } from '../errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* Decodes a TLV8-formatted buffer into an array of TLV8 items.
|
|
4
|
+
*
|
|
5
|
+
* @param buffer - A Node.js Buffer containing TLV8 encoded data
|
|
6
|
+
* @returns Array of TLV8Item objects with `type` and `data`
|
|
7
|
+
* @throws TLV8Error if the buffer does not contain valid TLV8 data
|
|
8
|
+
*/
|
|
9
|
+
export function decodeTLV8(buffer) {
|
|
10
|
+
const items = [];
|
|
11
|
+
let offset = 0;
|
|
12
|
+
while (offset < buffer.length) {
|
|
13
|
+
if (offset + 2 > buffer.length) {
|
|
14
|
+
throw new TLV8Error(`Invalid TLV8: insufficient data for type and length at offset ${offset}`);
|
|
15
|
+
}
|
|
16
|
+
const type = buffer[offset];
|
|
17
|
+
const length = buffer[offset + 1];
|
|
18
|
+
offset += 2;
|
|
19
|
+
if (offset + length > buffer.length) {
|
|
20
|
+
throw new TLV8Error(`Invalid TLV8: insufficient data for value at offset ${offset}`);
|
|
21
|
+
}
|
|
22
|
+
const data = buffer.subarray(offset, offset + length);
|
|
23
|
+
offset += length;
|
|
24
|
+
items.push({ type, data });
|
|
25
|
+
}
|
|
26
|
+
return items;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Decodes a TLV8-formatted buffer into a dictionary mapping
|
|
30
|
+
* each TLV8 type to its corresponding data buffer. If the same
|
|
31
|
+
* type occurs more than once, their values are concatenated.
|
|
32
|
+
*
|
|
33
|
+
* @param buffer - A Node.js Buffer containing TLV8 encoded data
|
|
34
|
+
* @returns A dictionary of type-value mappings
|
|
35
|
+
*/
|
|
36
|
+
export function decodeTLV8ToDict(buffer) {
|
|
37
|
+
const items = decodeTLV8(buffer);
|
|
38
|
+
const result = {};
|
|
39
|
+
for (const { type, data } of items) {
|
|
40
|
+
if (!result[type]) {
|
|
41
|
+
result[type] = [];
|
|
42
|
+
}
|
|
43
|
+
result[type].push(data);
|
|
44
|
+
}
|
|
45
|
+
return Object.fromEntries(Object.entries(result).map(([type, buffers]) => [
|
|
46
|
+
type,
|
|
47
|
+
Buffer.concat(buffers),
|
|
48
|
+
]));
|
|
49
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TLV8Item } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Encodes an array of TLV8 items into a single TLV8-compliant buffer.
|
|
4
|
+
* If a data value exceeds TLV8_MAX_FRAGMENT_SIZE, it will be split across multiple entries.
|
|
5
|
+
*
|
|
6
|
+
* @param items - Array of TLV8 items to encode
|
|
7
|
+
* @returns A Buffer containing the encoded TLV8 data
|
|
8
|
+
*/
|
|
9
|
+
export declare function encodeTLV8(items: TLV8Item[]): Buffer;
|
|
10
|
+
//# sourceMappingURL=encoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoder.d.ts","sourceRoot":"","sources":["../../../../../src/lib/apple-tv/tlv/encoder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,MAAM,CAsBpD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TLV8_MAX_FRAGMENT_SIZE } from '../constants.js';
|
|
2
|
+
/**
|
|
3
|
+
* Encodes an array of TLV8 items into a single TLV8-compliant buffer.
|
|
4
|
+
* If a data value exceeds TLV8_MAX_FRAGMENT_SIZE, it will be split across multiple entries.
|
|
5
|
+
*
|
|
6
|
+
* @param items - Array of TLV8 items to encode
|
|
7
|
+
* @returns A Buffer containing the encoded TLV8 data
|
|
8
|
+
*/
|
|
9
|
+
export function encodeTLV8(items) {
|
|
10
|
+
const chunks = [];
|
|
11
|
+
for (const { type, data } of items) {
|
|
12
|
+
let offset = 0;
|
|
13
|
+
while (offset < data.length) {
|
|
14
|
+
const fragmentLength = Math.min(TLV8_MAX_FRAGMENT_SIZE, data.length - offset);
|
|
15
|
+
chunks.push(Buffer.from([type, fragmentLength]), data.subarray(offset, offset + fragmentLength));
|
|
16
|
+
offset += fragmentLength;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return Buffer.concat(chunks);
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/lib/apple-tv/tlv/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,GAC3B,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates TLV8-encoded setup data for manual pairing, with default METHOD and STATE.
|
|
3
|
+
*
|
|
4
|
+
* @returns Base64-encoded TLV8 string for manual pairing
|
|
5
|
+
*/
|
|
6
|
+
export declare function createSetupManualPairingData(): string;
|
|
7
|
+
/**
|
|
8
|
+
* Creates TLV8-encoded data for pair verification, including the X25519 public key.
|
|
9
|
+
*
|
|
10
|
+
* @param x25519PublicKey - A buffer containing the X25519 public key
|
|
11
|
+
* @returns Base64-encoded TLV8 string for verification
|
|
12
|
+
*/
|
|
13
|
+
export declare function createPairVerificationData(x25519PublicKey: Buffer): string;
|
|
14
|
+
//# sourceMappingURL=pairing-tlv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pairing-tlv.d.ts","sourceRoot":"","sources":["../../../../../src/lib/apple-tv/tlv/pairing-tlv.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,4BAA4B,IAAI,MAAM,CAOrD;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAO1E"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { PairingDataComponentType } from '../constants.js';
|
|
2
|
+
import { encodeTLV8 } from './encoder.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates TLV8-encoded setup data for manual pairing, with default METHOD and STATE.
|
|
5
|
+
*
|
|
6
|
+
* @returns Base64-encoded TLV8 string for manual pairing
|
|
7
|
+
*/
|
|
8
|
+
export function createSetupManualPairingData() {
|
|
9
|
+
const tlv = encodeTLV8([
|
|
10
|
+
{ type: PairingDataComponentType.METHOD, data: Buffer.from([0x00]) },
|
|
11
|
+
{ type: PairingDataComponentType.STATE, data: Buffer.from([0x01]) },
|
|
12
|
+
]);
|
|
13
|
+
return tlv.toString('base64');
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates TLV8-encoded data for pair verification, including the X25519 public key.
|
|
17
|
+
*
|
|
18
|
+
* @param x25519PublicKey - A buffer containing the X25519 public key
|
|
19
|
+
* @returns Base64-encoded TLV8 string for verification
|
|
20
|
+
*/
|
|
21
|
+
export function createPairVerificationData(x25519PublicKey) {
|
|
22
|
+
const tlv = encodeTLV8([
|
|
23
|
+
{ type: PairingDataComponentType.STATE, data: Buffer.from([0x01]) },
|
|
24
|
+
{ type: PairingDataComponentType.PUBLIC_KEY, data: x25519PublicKey },
|
|
25
|
+
]);
|
|
26
|
+
return tlv.toString('base64');
|
|
27
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface AppleTVDeviceInfo {
|
|
2
|
+
altIRK: Buffer;
|
|
3
|
+
btAddr: string;
|
|
4
|
+
mac: Buffer;
|
|
5
|
+
remotePairingSerialNumber: string;
|
|
6
|
+
accountID: string;
|
|
7
|
+
model: string;
|
|
8
|
+
name: string;
|
|
9
|
+
}
|
|
10
|
+
export interface PairingKeys {
|
|
11
|
+
publicKey: Buffer;
|
|
12
|
+
privateKey: Buffer;
|
|
13
|
+
}
|
|
14
|
+
export interface PairingResult {
|
|
15
|
+
success: boolean;
|
|
16
|
+
pairingFile?: string;
|
|
17
|
+
deviceId: string;
|
|
18
|
+
error?: Error;
|
|
19
|
+
}
|
|
20
|
+
export interface PairingConfig {
|
|
21
|
+
timeout: number;
|
|
22
|
+
discoveryTimeout: number;
|
|
23
|
+
maxRetries: number;
|
|
24
|
+
pairingDirectory: string;
|
|
25
|
+
}
|
|
26
|
+
export interface TLV8Item {
|
|
27
|
+
type: PairingDataComponentTypeValue;
|
|
28
|
+
data: Buffer;
|
|
29
|
+
}
|
|
30
|
+
export type PairingDataComponentTypeValue = number;
|
|
31
|
+
export type Opack2Value = null | undefined | boolean | number | string | Buffer | Opack2Array | Opack2Dictionary;
|
|
32
|
+
export interface Opack2Array extends Array<Opack2Value> {
|
|
33
|
+
}
|
|
34
|
+
export interface Opack2Dictionary extends Record<string, Opack2Value> {
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/lib/apple-tv/types.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,yBAAyB,EAAE,MAAM,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAGD,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAGD,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAGD,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAGD,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,6BAA6B,CAAC;IACpC,IAAI,EAAE,MAAM,CAAC;CACd;AAGD,MAAM,MAAM,6BAA6B,GAAG,MAAM,CAAC;AAGnD,MAAM,MAAM,WAAW,GACnB,IAAI,GACJ,SAAS,GACT,OAAO,GACP,MAAM,GACN,MAAM,GACN,MAAM,GACN,WAAW,GACX,gBAAgB,CAAC;AAGrB,MAAM,WAAW,WAAY,SAAQ,KAAK,CAAC,WAAW,CAAC;CAAG;AAG1D,MAAM,WAAW,gBAAiB,SAAQ,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|