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.
Files changed (213) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/src/base-plist-service.d.ts +51 -0
  3. package/build/src/base-plist-service.d.ts.map +1 -0
  4. package/build/src/base-plist-service.js +61 -0
  5. package/build/src/base-socket-service.d.ts +15 -0
  6. package/build/src/base-socket-service.d.ts.map +1 -0
  7. package/build/src/base-socket-service.js +46 -0
  8. package/build/src/index.d.ts +9 -0
  9. package/build/src/index.d.ts.map +1 -0
  10. package/build/src/index.js +7 -0
  11. package/build/src/lib/apple-tv/constants.d.ts +77 -0
  12. package/build/src/lib/apple-tv/constants.d.ts.map +1 -0
  13. package/build/src/lib/apple-tv/constants.js +106 -0
  14. package/build/src/lib/apple-tv/encryption/chacha20-poly1305.d.ts +22 -0
  15. package/build/src/lib/apple-tv/encryption/chacha20-poly1305.d.ts.map +1 -0
  16. package/build/src/lib/apple-tv/encryption/chacha20-poly1305.js +97 -0
  17. package/build/src/lib/apple-tv/encryption/ed25519.d.ts +16 -0
  18. package/build/src/lib/apple-tv/encryption/ed25519.d.ts.map +1 -0
  19. package/build/src/lib/apple-tv/encryption/ed25519.js +93 -0
  20. package/build/src/lib/apple-tv/encryption/hkdf.d.ts +18 -0
  21. package/build/src/lib/apple-tv/encryption/hkdf.d.ts.map +1 -0
  22. package/build/src/lib/apple-tv/encryption/hkdf.js +73 -0
  23. package/build/src/lib/apple-tv/encryption/index.d.ts +5 -0
  24. package/build/src/lib/apple-tv/encryption/index.d.ts.map +1 -0
  25. package/build/src/lib/apple-tv/encryption/index.js +4 -0
  26. package/build/src/lib/apple-tv/encryption/opack2.d.ts +57 -0
  27. package/build/src/lib/apple-tv/encryption/opack2.d.ts.map +1 -0
  28. package/build/src/lib/apple-tv/encryption/opack2.js +203 -0
  29. package/build/src/lib/apple-tv/errors.d.ts +17 -0
  30. package/build/src/lib/apple-tv/errors.d.ts.map +1 -0
  31. package/build/src/lib/apple-tv/errors.js +30 -0
  32. package/build/src/lib/apple-tv/tlv/decoder.d.ts +19 -0
  33. package/build/src/lib/apple-tv/tlv/decoder.d.ts.map +1 -0
  34. package/build/src/lib/apple-tv/tlv/decoder.js +49 -0
  35. package/build/src/lib/apple-tv/tlv/encoder.d.ts +10 -0
  36. package/build/src/lib/apple-tv/tlv/encoder.d.ts.map +1 -0
  37. package/build/src/lib/apple-tv/tlv/encoder.js +20 -0
  38. package/build/src/lib/apple-tv/tlv/index.d.ts +4 -0
  39. package/build/src/lib/apple-tv/tlv/index.d.ts.map +1 -0
  40. package/build/src/lib/apple-tv/tlv/index.js +3 -0
  41. package/build/src/lib/apple-tv/tlv/pairing-tlv.d.ts +14 -0
  42. package/build/src/lib/apple-tv/tlv/pairing-tlv.d.ts.map +1 -0
  43. package/build/src/lib/apple-tv/tlv/pairing-tlv.js +27 -0
  44. package/build/src/lib/apple-tv/types.d.ts +36 -0
  45. package/build/src/lib/apple-tv/types.d.ts.map +1 -0
  46. package/build/src/lib/apple-tv/types.js +1 -0
  47. package/build/src/lib/apple-tv/utils/buffer-utils.d.ts +40 -0
  48. package/build/src/lib/apple-tv/utils/buffer-utils.d.ts.map +1 -0
  49. package/build/src/lib/apple-tv/utils/buffer-utils.js +76 -0
  50. package/build/src/lib/apple-tv/utils/index.d.ts +3 -0
  51. package/build/src/lib/apple-tv/utils/index.d.ts.map +1 -0
  52. package/build/src/lib/apple-tv/utils/index.js +2 -0
  53. package/build/src/lib/apple-tv/utils/uuid-generator.d.ts +9 -0
  54. package/build/src/lib/apple-tv/utils/uuid-generator.d.ts.map +1 -0
  55. package/build/src/lib/apple-tv/utils/uuid-generator.js +36 -0
  56. package/build/src/lib/lockdown/index.d.ts +87 -0
  57. package/build/src/lib/lockdown/index.d.ts.map +1 -0
  58. package/build/src/lib/lockdown/index.js +324 -0
  59. package/build/src/lib/pair-record/index.d.ts +3 -0
  60. package/build/src/lib/pair-record/index.d.ts.map +1 -0
  61. package/build/src/lib/pair-record/index.js +2 -0
  62. package/build/src/lib/pair-record/pair-record.d.ts +48 -0
  63. package/build/src/lib/pair-record/pair-record.d.ts.map +1 -0
  64. package/build/src/lib/pair-record/pair-record.js +85 -0
  65. package/build/src/lib/plist/binary-plist-creator.d.ts +14 -0
  66. package/build/src/lib/plist/binary-plist-creator.d.ts.map +1 -0
  67. package/build/src/lib/plist/binary-plist-creator.js +475 -0
  68. package/build/src/lib/plist/binary-plist-parser.d.ts +14 -0
  69. package/build/src/lib/plist/binary-plist-parser.d.ts.map +1 -0
  70. package/build/src/lib/plist/binary-plist-parser.js +449 -0
  71. package/build/src/lib/plist/constants.d.ts +36 -0
  72. package/build/src/lib/plist/constants.d.ts.map +1 -0
  73. package/build/src/lib/plist/constants.js +43 -0
  74. package/build/src/lib/plist/index.d.ts +14 -0
  75. package/build/src/lib/plist/index.d.ts.map +1 -0
  76. package/build/src/lib/plist/index.js +16 -0
  77. package/build/src/lib/plist/length-based-splitter.d.ts +43 -0
  78. package/build/src/lib/plist/length-based-splitter.d.ts.map +1 -0
  79. package/build/src/lib/plist/length-based-splitter.js +228 -0
  80. package/build/src/lib/plist/plist-creator.d.ts +8 -0
  81. package/build/src/lib/plist/plist-creator.d.ts.map +1 -0
  82. package/build/src/lib/plist/plist-creator.js +33 -0
  83. package/build/src/lib/plist/plist-decoder.d.ts +25 -0
  84. package/build/src/lib/plist/plist-decoder.d.ts.map +1 -0
  85. package/build/src/lib/plist/plist-decoder.js +103 -0
  86. package/build/src/lib/plist/plist-encoder.d.ts +10 -0
  87. package/build/src/lib/plist/plist-encoder.d.ts.map +1 -0
  88. package/build/src/lib/plist/plist-encoder.js +27 -0
  89. package/build/src/lib/plist/plist-parser.d.ts +9 -0
  90. package/build/src/lib/plist/plist-parser.d.ts.map +1 -0
  91. package/build/src/lib/plist/plist-parser.js +109 -0
  92. package/build/src/lib/plist/plist-service.d.ts +86 -0
  93. package/build/src/lib/plist/plist-service.d.ts.map +1 -0
  94. package/build/src/lib/plist/plist-service.js +180 -0
  95. package/build/src/lib/plist/unified-plist-creator.d.ts +9 -0
  96. package/build/src/lib/plist/unified-plist-creator.d.ts.map +1 -0
  97. package/build/src/lib/plist/unified-plist-creator.js +14 -0
  98. package/build/src/lib/plist/unified-plist-parser.d.ts +8 -0
  99. package/build/src/lib/plist/unified-plist-parser.d.ts.map +1 -0
  100. package/build/src/lib/plist/unified-plist-parser.js +23 -0
  101. package/build/src/lib/plist/utils.d.ts +97 -0
  102. package/build/src/lib/plist/utils.d.ts.map +1 -0
  103. package/build/src/lib/plist/utils.js +287 -0
  104. package/build/src/lib/remote-xpc/constants.d.ts +20 -0
  105. package/build/src/lib/remote-xpc/constants.d.ts.map +1 -0
  106. package/build/src/lib/remote-xpc/constants.js +21 -0
  107. package/build/src/lib/remote-xpc/handshake-frames.d.ts +74 -0
  108. package/build/src/lib/remote-xpc/handshake-frames.d.ts.map +1 -0
  109. package/build/src/lib/remote-xpc/handshake-frames.js +285 -0
  110. package/build/src/lib/remote-xpc/handshake.d.ts +14 -0
  111. package/build/src/lib/remote-xpc/handshake.d.ts.map +1 -0
  112. package/build/src/lib/remote-xpc/handshake.js +95 -0
  113. package/build/src/lib/remote-xpc/remote-xpc-connection.d.ts +55 -0
  114. package/build/src/lib/remote-xpc/remote-xpc-connection.d.ts.map +1 -0
  115. package/build/src/lib/remote-xpc/remote-xpc-connection.js +365 -0
  116. package/build/src/lib/remote-xpc/xpc-protocol.d.ts +22 -0
  117. package/build/src/lib/remote-xpc/xpc-protocol.d.ts.map +1 -0
  118. package/build/src/lib/remote-xpc/xpc-protocol.js +368 -0
  119. package/build/src/lib/tunnel/index.d.ts +69 -0
  120. package/build/src/lib/tunnel/index.d.ts.map +1 -0
  121. package/build/src/lib/tunnel/index.js +205 -0
  122. package/build/src/lib/tunnel/packet-stream-client.d.ts +46 -0
  123. package/build/src/lib/tunnel/packet-stream-client.d.ts.map +1 -0
  124. package/build/src/lib/tunnel/packet-stream-client.js +152 -0
  125. package/build/src/lib/tunnel/packet-stream-server.d.ts +37 -0
  126. package/build/src/lib/tunnel/packet-stream-server.d.ts.map +1 -0
  127. package/build/src/lib/tunnel/packet-stream-server.js +109 -0
  128. package/build/src/lib/tunnel/tunnel-api-client.d.ts +85 -0
  129. package/build/src/lib/tunnel/tunnel-api-client.d.ts.map +1 -0
  130. package/build/src/lib/tunnel/tunnel-api-client.js +207 -0
  131. package/build/src/lib/tunnel/tunnel-registry-server.d.ts +68 -0
  132. package/build/src/lib/tunnel/tunnel-registry-server.d.ts.map +1 -0
  133. package/build/src/lib/tunnel/tunnel-registry-server.js +351 -0
  134. package/build/src/lib/types.d.ts +238 -0
  135. package/build/src/lib/types.d.ts.map +1 -0
  136. package/build/src/lib/types.js +4 -0
  137. package/build/src/lib/usbmux/index.d.ts +177 -0
  138. package/build/src/lib/usbmux/index.d.ts.map +1 -0
  139. package/build/src/lib/usbmux/index.js +490 -0
  140. package/build/src/lib/usbmux/usbmux-decoder.d.ts +19 -0
  141. package/build/src/lib/usbmux/usbmux-decoder.d.ts.map +1 -0
  142. package/build/src/lib/usbmux/usbmux-decoder.js +38 -0
  143. package/build/src/lib/usbmux/usbmux-encoder.d.ts +12 -0
  144. package/build/src/lib/usbmux/usbmux-encoder.d.ts.map +1 -0
  145. package/build/src/lib/usbmux/usbmux-encoder.js +32 -0
  146. package/build/src/service-connection.d.ts +34 -0
  147. package/build/src/service-connection.d.ts.map +1 -0
  148. package/build/src/service-connection.js +51 -0
  149. package/build/src/services/index.d.ts +6 -0
  150. package/build/src/services/index.d.ts.map +1 -0
  151. package/build/src/services/index.js +5 -0
  152. package/build/src/services/ios/base-service.d.ts +35 -0
  153. package/build/src/services/ios/base-service.d.ts.map +1 -0
  154. package/build/src/services/ios/base-service.js +55 -0
  155. package/build/src/services/ios/diagnostic-service/index.d.ts +46 -0
  156. package/build/src/services/ios/diagnostic-service/index.d.ts.map +1 -0
  157. package/build/src/services/ios/diagnostic-service/index.js +169 -0
  158. package/build/src/services/ios/diagnostic-service/keys.d.ts +5 -0
  159. package/build/src/services/ios/diagnostic-service/keys.d.ts.map +1 -0
  160. package/build/src/services/ios/diagnostic-service/keys.js +770 -0
  161. package/build/src/services/ios/syslog-service/index.d.ts +91 -0
  162. package/build/src/services/ios/syslog-service/index.d.ts.map +1 -0
  163. package/build/src/services/ios/syslog-service/index.js +323 -0
  164. package/build/src/services/ios/tunnel-service/index.d.ts +17 -0
  165. package/build/src/services/ios/tunnel-service/index.d.ts.map +1 -0
  166. package/build/src/services/ios/tunnel-service/index.js +57 -0
  167. package/build/src/services.d.ts +14 -0
  168. package/build/src/services.d.ts.map +1 -0
  169. package/build/src/services.js +48 -0
  170. package/package.json +12 -3
  171. package/src/lib/apple-tv/constants.ts +42 -0
  172. package/src/lib/apple-tv/encryption/chacha20-poly1305.ts +147 -0
  173. package/src/lib/apple-tv/encryption/ed25519.ts +126 -0
  174. package/src/lib/apple-tv/encryption/hkdf.ts +95 -0
  175. package/src/lib/apple-tv/encryption/index.ts +11 -0
  176. package/src/lib/apple-tv/encryption/opack2.ts +257 -0
  177. package/.github/dependabot.yml +0 -38
  178. package/.github/workflows/format-check.yml +0 -43
  179. package/.github/workflows/lint-and-build.yml +0 -40
  180. package/.github/workflows/pr-title.yml +0 -16
  181. package/.github/workflows/publish.js.yml +0 -43
  182. package/.github/workflows/test-validation.yml +0 -40
  183. package/.mocharc.json +0 -8
  184. package/.prettierignore +0 -3
  185. package/.prettierrc +0 -17
  186. package/.releaserc +0 -48
  187. package/assets/images/ios-arch.png +0 -0
  188. package/eslint.config.js +0 -45
  189. package/npm-shrinkwrap.json +0 -2711
  190. package/test/integration/diagnostics-test.ts +0 -44
  191. package/test/integration/read-pair-record-test.ts +0 -39
  192. package/test/integration/tunnel-test.ts +0 -104
  193. package/test/unit/apple-tv/tlv/decoder.spec.ts +0 -144
  194. package/test/unit/apple-tv/tlv/encoder.spec.ts +0 -91
  195. package/test/unit/apple-tv/tlv/pairing-tlv.spec.ts +0 -101
  196. package/test/unit/apple-tv/tlv/tlv-integration.spec.ts +0 -146
  197. package/test/unit/apple-tv/utils/buffer-utils.spec.ts +0 -74
  198. package/test/unit/apple-tv/utils/uuid-generator.spec.ts +0 -39
  199. package/test/unit/fixtures/index.ts +0 -88
  200. package/test/unit/fixtures/usbmuxconnectmessage.bin +0 -0
  201. package/test/unit/fixtures/usbmuxlistdevicemessage.bin +0 -0
  202. package/test/unit/plist/error-handling.spec.ts +0 -101
  203. package/test/unit/plist/fixtures/sample.binary.plist +0 -0
  204. package/test/unit/plist/fixtures/sample.xml.plist +0 -38
  205. package/test/unit/plist/plist-parser.spec.ts +0 -283
  206. package/test/unit/plist/plist.spec.ts +0 -205
  207. package/test/unit/plist/tag-position-handling.spec.ts +0 -90
  208. package/test/unit/plist/unified-plist-parser.spec.ts +0 -227
  209. package/test/unit/plist/utils.spec.ts +0 -249
  210. package/test/unit/plist/xml-cleaning.spec.ts +0 -60
  211. package/test/unit/tunnel/tunnel-registry-server.spec.ts +0 -194
  212. package/test/unit/usbmux/usbmux-specs.ts +0 -71
  213. package/tsconfig.json +0 -36
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## [0.0.5](https://github.com/appium/appium-ios-remotexpc/compare/v0.0.4...v0.0.5) (2025-07-04)
2
+
3
+ ### Miscellaneous Chores
4
+
5
+ * add appletv encryption module for RemoteXPC support ([#50](https://github.com/appium/appium-ios-remotexpc/issues/50)) ([0e5f3c6](https://github.com/appium/appium-ios-remotexpc/commit/0e5f3c6064bb0dc02f05f9349bac942c4c3bc951))
6
+
7
+ ## [0.0.4](https://github.com/appium/appium-ios-remotexpc/compare/v0.0.3...v0.0.4) (2025-07-03)
8
+
9
+ ### Miscellaneous Chores
10
+
11
+ * Add build release to npm module ([#49](https://github.com/appium/appium-ios-remotexpc/issues/49)) ([77c7720](https://github.com/appium/appium-ios-remotexpc/commit/77c77201d730e8a501813fc39bf1a768de2bf497))
12
+
1
13
  ## [0.0.3](https://github.com/appium/appium-ios-remotexpc/compare/v0.0.2...v0.0.3) (2025-07-03)
2
14
 
3
15
  ### Miscellaneous Chores
@@ -0,0 +1,51 @@
1
+ import { Socket } from 'node:net';
2
+ import { PlistService, type PlistServiceOptions } from './lib/plist/plist-service.js';
3
+ import type { PlistDictionary } from './lib/types.js';
4
+ /**
5
+ * Message type for plist communications
6
+ */
7
+ type PlistMessage = PlistDictionary;
8
+ /**
9
+ * Base class for services that use PlistService for communication
10
+ */
11
+ export declare abstract class BasePlistService {
12
+ /**
13
+ * Sends a message and waits for a response
14
+ * @param message The message to send
15
+ * @param timeout Timeout in milliseconds
16
+ * @returns Promise resolving to the response
17
+ */
18
+ sendAndReceive(message: PlistMessage, timeout?: number): Promise<PlistMessage>;
19
+ /**
20
+ * Closes the underlying connection
21
+ */
22
+ close(): void;
23
+ /**
24
+ * Gets the PlistService instance
25
+ * @returns The PlistService instance
26
+ */
27
+ protected getPlistService(): PlistService;
28
+ /**
29
+ * The underlying PlistService instance
30
+ */
31
+ protected _plistService: PlistService;
32
+ /**
33
+ * Creates a new BasePlistService
34
+ * @param plistServiceOrSocket PlistService instance or Socket
35
+ * @param options Configuration options for PlistService
36
+ */
37
+ protected constructor(plistServiceOrSocket: PlistService | Socket, options?: PlistServiceOptions);
38
+ /**
39
+ * Sends a message without waiting for a response
40
+ * @param message The message to send
41
+ */
42
+ protected send(message: PlistMessage): void;
43
+ /**
44
+ * Waits for a message
45
+ * @param timeout Timeout in milliseconds
46
+ * @returns Promise resolving to the received message
47
+ */
48
+ protected receive(timeout?: number): Promise<PlistMessage>;
49
+ }
50
+ export {};
51
+ //# sourceMappingURL=base-plist-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-plist-service.d.ts","sourceRoot":"","sources":["../../src/base-plist-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EACL,YAAY,EACZ,KAAK,mBAAmB,EACzB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD;;GAEG;AACH,KAAK,YAAY,GAAG,eAAe,CAAC;AAEpC;;GAEG;AACH,8BAAsB,gBAAgB;IACpC;;;;;OAKG;IACG,cAAc,CAClB,OAAO,EAAE,YAAY,EACrB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,YAAY,CAAC;IAIxB;;OAEG;IACI,KAAK,IAAI,IAAI;IAIpB;;;OAGG;IACH,SAAS,CAAC,eAAe,IAAI,YAAY;IAIzC;;OAEG;IACH,SAAS,CAAC,aAAa,EAAE,YAAY,CAAC;IAEtC;;;;OAIG;IACH,SAAS,aACP,oBAAoB,EAAE,YAAY,GAAG,MAAM,EAC3C,OAAO,GAAE,mBAAwB;IASnC;;;OAGG;IACH,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAI3C;;;;OAIG;cACa,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CAGjE"}
@@ -0,0 +1,61 @@
1
+ import { Socket } from 'node:net';
2
+ import { PlistService, } from './lib/plist/plist-service.js';
3
+ /**
4
+ * Base class for services that use PlistService for communication
5
+ */
6
+ export class BasePlistService {
7
+ /**
8
+ * Sends a message and waits for a response
9
+ * @param message The message to send
10
+ * @param timeout Timeout in milliseconds
11
+ * @returns Promise resolving to the response
12
+ */
13
+ async sendAndReceive(message, timeout) {
14
+ return this._plistService.sendPlistAndReceive(message, timeout);
15
+ }
16
+ /**
17
+ * Closes the underlying connection
18
+ */
19
+ close() {
20
+ this._plistService.close();
21
+ }
22
+ /**
23
+ * Gets the PlistService instance
24
+ * @returns The PlistService instance
25
+ */
26
+ getPlistService() {
27
+ return this._plistService;
28
+ }
29
+ /**
30
+ * The underlying PlistService instance
31
+ */
32
+ _plistService;
33
+ /**
34
+ * Creates a new BasePlistService
35
+ * @param plistServiceOrSocket PlistService instance or Socket
36
+ * @param options Configuration options for PlistService
37
+ */
38
+ constructor(plistServiceOrSocket, options = {}) {
39
+ if (plistServiceOrSocket instanceof PlistService) {
40
+ this._plistService = plistServiceOrSocket;
41
+ }
42
+ else {
43
+ this._plistService = new PlistService(plistServiceOrSocket, options);
44
+ }
45
+ }
46
+ /**
47
+ * Sends a message without waiting for a response
48
+ * @param message The message to send
49
+ */
50
+ send(message) {
51
+ this._plistService.sendPlist(message);
52
+ }
53
+ /**
54
+ * Waits for a message
55
+ * @param timeout Timeout in milliseconds
56
+ * @returns Promise resolving to the received message
57
+ */
58
+ async receive(timeout) {
59
+ return this._plistService.receivePlist(timeout);
60
+ }
61
+ }
@@ -0,0 +1,15 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import { Socket } from 'node:net';
3
+ import { Readable } from 'node:stream';
4
+ declare class BaseSocketService extends EventEmitter {
5
+ protected _socketClient: Socket;
6
+ protected _isConnected: boolean;
7
+ /**
8
+ * @param socketClient
9
+ */
10
+ constructor(socketClient: Socket);
11
+ _assignClientFailureHandlers(...sourceStreams: Readable[]): void;
12
+ close(): void;
13
+ }
14
+ export { BaseSocketService };
15
+ //# sourceMappingURL=base-socket-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-socket-service.d.ts","sourceRoot":"","sources":["../../src/base-socket-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,cAAM,iBAAkB,SAAQ,YAAY;IAC1C,SAAS,CAAC,aAAa,EAAE,MAAM,CAAC;IAChC,SAAS,CAAC,YAAY,EAAE,OAAO,CAAS;IAExC;;OAEG;gBACS,YAAY,EAAE,MAAM;IA0BhC,4BAA4B,CAAC,GAAG,aAAa,EAAE,QAAQ,EAAE,GAAG,IAAI;IAUhE,KAAK,IAAI,IAAI;CAKd;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import { Socket } from 'node:net';
3
+ import { Readable } from 'node:stream';
4
+ class BaseSocketService extends EventEmitter {
5
+ _socketClient;
6
+ _isConnected = false;
7
+ /**
8
+ * @param socketClient
9
+ */
10
+ constructor(socketClient) {
11
+ super();
12
+ this._socketClient = socketClient;
13
+ // Check if already connected
14
+ this._isConnected = !socketClient.connecting && !socketClient.destroyed;
15
+ // if not connected and it's a raw socket
16
+ if (!this._isConnected && socketClient instanceof Socket) {
17
+ this._socketClient.once('connect', () => {
18
+ this._isConnected = true;
19
+ this.emit('connect');
20
+ });
21
+ }
22
+ // setup basic error handling
23
+ this._socketClient.on('error', (err) => {
24
+ this.emit('error', err);
25
+ });
26
+ this._socketClient.on('close', () => {
27
+ this._isConnected = false;
28
+ this.emit('close');
29
+ });
30
+ }
31
+ _assignClientFailureHandlers(...sourceStreams) {
32
+ for (const evt of ['close', 'end']) {
33
+ this._socketClient.once(evt, () => {
34
+ sourceStreams.map((s) => {
35
+ s.unpipe(this._socketClient);
36
+ });
37
+ });
38
+ }
39
+ }
40
+ close() {
41
+ if (!this._socketClient.destroyed) {
42
+ this._socketClient.end();
43
+ }
44
+ }
45
+ }
46
+ export { BaseSocketService };
@@ -0,0 +1,9 @@
1
+ import { createLockdownServiceByUDID } from './lib/lockdown/index.js';
2
+ import { PacketStreamClient, PacketStreamServer, TunnelManager } from './lib/tunnel/index.js';
3
+ import { TunnelRegistryServer, startTunnelRegistryServer } from './lib/tunnel/tunnel-registry-server.js';
4
+ import { Usbmux, createUsbmux } from './lib/usbmux/index.js';
5
+ import * as Services from './services.js';
6
+ import { startCoreDeviceProxy } from './services/ios/tunnel-service/index.js';
7
+ export type { DiagnosticsService, SyslogService, SocketInfo, TunnelResult, TunnelRegistry, TunnelRegistryEntry, } from './lib/types.js';
8
+ export { createUsbmux, Services, Usbmux, TunnelManager, PacketStreamServer, PacketStreamClient, createLockdownServiceByUDID, startCoreDeviceProxy, TunnelRegistryServer, startTunnelRegistryServer, };
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EAC1B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAE9E,YAAY,EACV,kBAAkB,EAClB,aAAa,EACb,UAAU,EACV,YAAY,EACZ,cAAc,EACd,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,2BAA2B,EAC3B,oBAAoB,EACpB,oBAAoB,EACpB,yBAAyB,GAC1B,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { createLockdownServiceByUDID } from './lib/lockdown/index.js';
2
+ import { PacketStreamClient, PacketStreamServer, TunnelManager, } from './lib/tunnel/index.js';
3
+ import { TunnelRegistryServer, startTunnelRegistryServer, } from './lib/tunnel/tunnel-registry-server.js';
4
+ import { Usbmux, createUsbmux } from './lib/usbmux/index.js';
5
+ import * as Services from './services.js';
6
+ import { startCoreDeviceProxy } from './services/ios/tunnel-service/index.js';
7
+ export { createUsbmux, Services, Usbmux, TunnelManager, PacketStreamServer, PacketStreamClient, createLockdownServiceByUDID, startCoreDeviceProxy, TunnelRegistryServer, startTunnelRegistryServer, };
@@ -0,0 +1,77 @@
1
+ export declare const DEFAULT_PAIRING_CONFIG: {
2
+ readonly timeout: 30000;
3
+ readonly discoveryTimeout: 5000;
4
+ readonly maxRetries: 3;
5
+ readonly pairingDirectory: ".pairing";
6
+ };
7
+ export declare const PairingDataComponentType: {
8
+ readonly METHOD: 0;
9
+ readonly IDENTIFIER: 1;
10
+ readonly SALT: 2;
11
+ readonly PUBLIC_KEY: 3;
12
+ readonly PROOF: 4;
13
+ readonly ENCRYPTED_DATA: 5;
14
+ readonly STATE: 6;
15
+ readonly ERROR: 7;
16
+ readonly RETRY_DELAY: 8;
17
+ readonly CERTIFICATE: 9;
18
+ readonly SIGNATURE: 10;
19
+ readonly PERMISSIONS: 11;
20
+ readonly FRAGMENT_DATA: 12;
21
+ readonly FRAGMENT_LAST: 13;
22
+ readonly SESSION_ID: 14;
23
+ readonly TTL: 15;
24
+ readonly EXTRA_DATA: 16;
25
+ readonly INFO: 17;
26
+ readonly ACL: 18;
27
+ readonly FLAGS: 19;
28
+ readonly VALIDATION_DATA: 20;
29
+ readonly MFI_AUTH_TOKEN: 21;
30
+ readonly MFI_PRODUCT_TYPE: 22;
31
+ readonly SERIAL_NUMBER: 23;
32
+ readonly MFI_AUTH_TOKEN_UUID: 24;
33
+ readonly APP_FLAGS: 25;
34
+ readonly OWNERSHIP_PROOF: 26;
35
+ readonly SETUP_CODE_TYPE: 27;
36
+ readonly PRODUCTION_DATA: 28;
37
+ readonly APP_INFO: 29;
38
+ readonly SEPARATOR: 255;
39
+ };
40
+ export declare const TLV8_MAX_FRAGMENT_SIZE = 255;
41
+ export declare const SRP_PRIME_3072: bigint;
42
+ export declare const SRP_GENERATOR: bigint;
43
+ export declare const SRP_HASH_ALGORITHM = "sha512";
44
+ export declare const SRP_USERNAME = "Pair-Setup";
45
+ export declare const SRP_KEY_LENGTH_BYTES = 384;
46
+ export declare const SRP_PRIVATE_KEY_BITS = 256;
47
+ export declare const HKDF_HASH_ALGORITHM = "sha512";
48
+ export declare const HKDF_HASH_LENGTH = 64;
49
+ export declare const OPACK2_NULL = 3;
50
+ export declare const OPACK2_TRUE = 1;
51
+ export declare const OPACK2_FALSE = 2;
52
+ export declare const OPACK2_SMALL_INT_OFFSET = 8;
53
+ export declare const OPACK2_SMALL_INT_MAX = 39;
54
+ export declare const OPACK2_SMALL_STRING_MAX = 32;
55
+ export declare const OPACK2_SMALL_BYTES_MAX = 32;
56
+ export declare const OPACK2_SMALL_ARRAY_MAX = 15;
57
+ export declare const OPACK2_SMALL_DICT_MAX = 15;
58
+ export declare const OPACK2_INT8_MARKER = 48;
59
+ export declare const OPACK2_INT32_MARKER = 50;
60
+ export declare const OPACK2_INT64_MARKER = 51;
61
+ export declare const OPACK2_FLOAT_MARKER = 53;
62
+ export declare const OPACK2_SMALL_STRING_BASE = 64;
63
+ export declare const OPACK2_STRING_8BIT_LEN_MARKER = 97;
64
+ export declare const OPACK2_STRING_16BIT_LEN_MARKER = 98;
65
+ export declare const OPACK2_STRING_32BIT_LEN_MARKER = 99;
66
+ export declare const OPACK2_SMALL_BYTES_BASE = 112;
67
+ export declare const OPACK2_BYTES_8BIT_LEN_MARKER = 145;
68
+ export declare const OPACK2_BYTES_16BIT_LEN_MARKER = 146;
69
+ export declare const OPACK2_BYTES_32BIT_LEN_MARKER = 147;
70
+ export declare const OPACK2_SMALL_ARRAY_BASE = 208;
71
+ export declare const OPACK2_VARIABLE_ARRAY_MARKER = 223;
72
+ export declare const OPACK2_SMALL_DICT_BASE = 224;
73
+ export declare const OPACK2_VARIABLE_DICT_MARKER = 239;
74
+ export declare const OPACK2_UINT8_MAX = 255;
75
+ export declare const OPACK2_UINT16_MAX = 65535;
76
+ export declare const OPACK2_UINT32_MAX = 4294967295;
77
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/lib/apple-tv/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,sBAAsB;;;;;CAKzB,CAAC;AAGX,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgC3B,CAAC;AAGX,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAG1C,eAAO,MAAM,cAAc,QAc1B,CAAC;AAGF,eAAO,MAAM,aAAa,QAAY,CAAC;AAGvC,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAG3C,eAAO,MAAM,YAAY,eAAe,CAAC;AAGzC,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAGxC,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAGxC,eAAO,MAAM,mBAAmB,WAAW,CAAC;AAG5C,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAGnC,eAAO,MAAM,WAAW,IAAO,CAAC;AAChC,eAAO,MAAM,WAAW,IAAO,CAAC;AAChC,eAAO,MAAM,YAAY,IAAO,CAAC;AACjC,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,oBAAoB,KAAO,CAAC;AACzC,eAAO,MAAM,uBAAuB,KAAO,CAAC;AAC5C,eAAO,MAAM,sBAAsB,KAAO,CAAC;AAC3C,eAAO,MAAM,sBAAsB,KAAK,CAAC;AACzC,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAGxC,eAAO,MAAM,kBAAkB,KAAO,CAAC;AACvC,eAAO,MAAM,mBAAmB,KAAO,CAAC;AACxC,eAAO,MAAM,mBAAmB,KAAO,CAAC;AACxC,eAAO,MAAM,mBAAmB,KAAO,CAAC;AAGxC,eAAO,MAAM,wBAAwB,KAAO,CAAC;AAC7C,eAAO,MAAM,6BAA6B,KAAO,CAAC;AAClD,eAAO,MAAM,8BAA8B,KAAO,CAAC;AACnD,eAAO,MAAM,8BAA8B,KAAO,CAAC;AAGnD,eAAO,MAAM,uBAAuB,MAAO,CAAC;AAC5C,eAAO,MAAM,4BAA4B,MAAO,CAAC;AACjD,eAAO,MAAM,6BAA6B,MAAO,CAAC;AAClD,eAAO,MAAM,6BAA6B,MAAO,CAAC;AAGlD,eAAO,MAAM,uBAAuB,MAAO,CAAC;AAC5C,eAAO,MAAM,4BAA4B,MAAO,CAAC;AAGjD,eAAO,MAAM,sBAAsB,MAAO,CAAC;AAC3C,eAAO,MAAM,2BAA2B,MAAO,CAAC;AAGhD,eAAO,MAAM,gBAAgB,MAAO,CAAC;AACrC,eAAO,MAAM,iBAAiB,QAAS,CAAC;AACxC,eAAO,MAAM,iBAAiB,aAAa,CAAC"}
@@ -0,0 +1,106 @@
1
+ // Default configuration values for Apple TV pairing behavior
2
+ export const DEFAULT_PAIRING_CONFIG = {
3
+ timeout: 30000,
4
+ discoveryTimeout: 5000,
5
+ maxRetries: 3,
6
+ pairingDirectory: '.pairing',
7
+ };
8
+ // TLV8 component type identifiers used in pairing data exchange
9
+ export const PairingDataComponentType = {
10
+ METHOD: 0x00,
11
+ IDENTIFIER: 0x01,
12
+ SALT: 0x02,
13
+ PUBLIC_KEY: 0x03,
14
+ PROOF: 0x04,
15
+ ENCRYPTED_DATA: 0x05,
16
+ STATE: 0x06,
17
+ ERROR: 0x07,
18
+ RETRY_DELAY: 0x08,
19
+ CERTIFICATE: 0x09,
20
+ SIGNATURE: 0x0a,
21
+ PERMISSIONS: 0x0b,
22
+ FRAGMENT_DATA: 0x0c,
23
+ FRAGMENT_LAST: 0x0d,
24
+ SESSION_ID: 0x0e,
25
+ TTL: 0x0f,
26
+ EXTRA_DATA: 0x10,
27
+ INFO: 0x11,
28
+ ACL: 0x12,
29
+ FLAGS: 0x13,
30
+ VALIDATION_DATA: 0x14,
31
+ MFI_AUTH_TOKEN: 0x15,
32
+ MFI_PRODUCT_TYPE: 0x16,
33
+ SERIAL_NUMBER: 0x17,
34
+ MFI_AUTH_TOKEN_UUID: 0x18,
35
+ APP_FLAGS: 0x19,
36
+ OWNERSHIP_PROOF: 0x1a,
37
+ SETUP_CODE_TYPE: 0x1b,
38
+ PRODUCTION_DATA: 0x1c,
39
+ APP_INFO: 0x1d,
40
+ SEPARATOR: 0xff,
41
+ };
42
+ // Maximum allowed size of a TLV8 fragment
43
+ export const TLV8_MAX_FRAGMENT_SIZE = 255;
44
+ // RFC 5054 3072-bit safe prime used for SRP key exchange
45
+ export const SRP_PRIME_3072 = BigInt('0x' +
46
+ 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' +
47
+ '020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' +
48
+ '4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' +
49
+ 'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF05' +
50
+ '98DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB' +
51
+ '9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B' +
52
+ 'E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718' +
53
+ '3995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33' +
54
+ 'A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7' +
55
+ 'ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864' +
56
+ 'D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E2' +
57
+ '08E24FA074E5AB3143DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF');
58
+ // Generator value (g=5) used in SRP key exchange
59
+ export const SRP_GENERATOR = BigInt(5);
60
+ // Hash algorithm used in SRP protocol (per HomeKit spec)
61
+ export const SRP_HASH_ALGORITHM = 'sha512';
62
+ // SRP username identifier used in Apple Pair-Setup
63
+ export const SRP_USERNAME = 'Pair-Setup';
64
+ // Key length in bytes for SRP (3072 bits = 384 bytes)
65
+ export const SRP_KEY_LENGTH_BYTES = 384;
66
+ // Number of bits for SRP private key (usually 256 bits)
67
+ export const SRP_PRIVATE_KEY_BITS = 256;
68
+ // Hash algorithm used for HKDF in pairing encryption
69
+ export const HKDF_HASH_ALGORITHM = 'sha512';
70
+ // Output length (in bytes) for HKDF key derivation
71
+ export const HKDF_HASH_LENGTH = 64;
72
+ // OPACK2 encoding constants
73
+ export const OPACK2_NULL = 0x03;
74
+ export const OPACK2_TRUE = 0x01;
75
+ export const OPACK2_FALSE = 0x02;
76
+ export const OPACK2_SMALL_INT_OFFSET = 8;
77
+ export const OPACK2_SMALL_INT_MAX = 0x27;
78
+ export const OPACK2_SMALL_STRING_MAX = 0x20;
79
+ export const OPACK2_SMALL_BYTES_MAX = 0x20;
80
+ export const OPACK2_SMALL_ARRAY_MAX = 15;
81
+ export const OPACK2_SMALL_DICT_MAX = 15;
82
+ // OPACK2 number type markers
83
+ export const OPACK2_INT8_MARKER = 0x30;
84
+ export const OPACK2_INT32_MARKER = 0x32;
85
+ export const OPACK2_INT64_MARKER = 0x33;
86
+ export const OPACK2_FLOAT_MARKER = 0x35;
87
+ // OPACK2 string type markers
88
+ export const OPACK2_SMALL_STRING_BASE = 0x40;
89
+ export const OPACK2_STRING_8BIT_LEN_MARKER = 0x61;
90
+ export const OPACK2_STRING_16BIT_LEN_MARKER = 0x62;
91
+ export const OPACK2_STRING_32BIT_LEN_MARKER = 0x63;
92
+ // OPACK2 bytes type markers
93
+ export const OPACK2_SMALL_BYTES_BASE = 0x70;
94
+ export const OPACK2_BYTES_8BIT_LEN_MARKER = 0x91;
95
+ export const OPACK2_BYTES_16BIT_LEN_MARKER = 0x92;
96
+ export const OPACK2_BYTES_32BIT_LEN_MARKER = 0x93;
97
+ // OPACK2 array type markers
98
+ export const OPACK2_SMALL_ARRAY_BASE = 0xd0;
99
+ export const OPACK2_VARIABLE_ARRAY_MARKER = 0xdf;
100
+ // OPACK2 dictionary type markers
101
+ export const OPACK2_SMALL_DICT_BASE = 0xe0;
102
+ export const OPACK2_VARIABLE_DICT_MARKER = 0xef;
103
+ // OPACK2 size limits
104
+ export const OPACK2_UINT8_MAX = 0xff;
105
+ export const OPACK2_UINT16_MAX = 0xffff;
106
+ export const OPACK2_UINT32_MAX = 0xffffffff;
@@ -0,0 +1,22 @@
1
+ export interface ChaCha20Poly1305Params {
2
+ plaintext?: Buffer;
3
+ ciphertext?: Buffer;
4
+ key: Buffer;
5
+ nonce: Buffer;
6
+ aad?: Buffer;
7
+ }
8
+ /**
9
+ * Encrypts data using ChaCha20-Poly1305 AEAD cipher
10
+ * @param params - Encryption parameters including plaintext, key, nonce, and optional AAD
11
+ * @returns Buffer containing encrypted data concatenated with authentication tag
12
+ * @throws CryptographyError if encryption fails or required parameters are missing
13
+ */
14
+ export declare function encryptChaCha20Poly1305(params: ChaCha20Poly1305Params): Buffer;
15
+ /**
16
+ * Decrypts data using ChaCha20-Poly1305 AEAD cipher with multiple fallback strategies
17
+ * @param params - Decryption parameters including ciphertext, key, nonce, and optional AAD
18
+ * @returns Buffer containing decrypted plaintext
19
+ * @throws CryptographyError if all decryption attempts fail or required parameters are missing
20
+ */
21
+ export declare function decryptChaCha20Poly1305(params: ChaCha20Poly1305Params): Buffer;
22
+ //# sourceMappingURL=chacha20-poly1305.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chacha20-poly1305.d.ts","sourceRoot":"","sources":["../../../../../src/lib/apple-tv/encryption/chacha20-poly1305.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,sBAAsB;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAOD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,sBAAsB,GAC7B,MAAM,CAiCR;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,sBAAsB,GAC7B,MAAM,CA2ER"}
@@ -0,0 +1,97 @@
1
+ import { logger } from '@appium/support';
2
+ import { createCipheriv, createDecipheriv } from 'node:crypto';
3
+ import { CryptographyError } from '../errors.js';
4
+ const log = logger.getLogger('ChaCha20Poly1305');
5
+ /**
6
+ * Encrypts data using ChaCha20-Poly1305 AEAD cipher
7
+ * @param params - Encryption parameters including plaintext, key, nonce, and optional AAD
8
+ * @returns Buffer containing encrypted data concatenated with authentication tag
9
+ * @throws CryptographyError if encryption fails or required parameters are missing
10
+ */
11
+ export function encryptChaCha20Poly1305(params) {
12
+ const { plaintext, key, nonce, aad } = params;
13
+ if (!plaintext) {
14
+ throw new CryptographyError('Plaintext is required for encryption');
15
+ }
16
+ if (!key || key.length !== 32) {
17
+ throw new CryptographyError('Key must be 32 bytes');
18
+ }
19
+ if (!nonce || nonce.length !== 12) {
20
+ throw new CryptographyError('Nonce must be 12 bytes');
21
+ }
22
+ try {
23
+ const cipher = createCipheriv('chacha20-poly1305', key, nonce);
24
+ if (aad) {
25
+ cipher.setAAD(aad, { plaintextLength: plaintext.length });
26
+ }
27
+ const encrypted = Buffer.concat([cipher.update(plaintext), cipher.final()]);
28
+ const authTag = cipher.getAuthTag();
29
+ return Buffer.concat([encrypted, authTag]);
30
+ }
31
+ catch (error) {
32
+ log.error('ChaCha20-Poly1305 encryption failed:', error);
33
+ const message = error instanceof Error ? error.message : String(error);
34
+ throw new CryptographyError(`ChaCha20-Poly1305 encryption failed: ${message}`);
35
+ }
36
+ }
37
+ /**
38
+ * Decrypts data using ChaCha20-Poly1305 AEAD cipher with multiple fallback strategies
39
+ * @param params - Decryption parameters including ciphertext, key, nonce, and optional AAD
40
+ * @returns Buffer containing decrypted plaintext
41
+ * @throws CryptographyError if all decryption attempts fail or required parameters are missing
42
+ */
43
+ export function decryptChaCha20Poly1305(params) {
44
+ const { ciphertext, key, nonce, aad } = params;
45
+ if (!ciphertext) {
46
+ throw new CryptographyError('Ciphertext is required for decryption');
47
+ }
48
+ if (!key || key.length !== 32) {
49
+ throw new CryptographyError('Key must be 32 bytes');
50
+ }
51
+ if (!nonce || nonce.length !== 12) {
52
+ throw new CryptographyError('Nonce must be 12 bytes');
53
+ }
54
+ if (ciphertext.length < 16) {
55
+ throw new CryptographyError('Ciphertext too short to contain authentication tag');
56
+ }
57
+ // ChaCha20-Poly1305 in Node.js only supports 16-byte authentication tags
58
+ const tagLength = 16;
59
+ const decryptionAttempts = [
60
+ { tagLen: tagLength, aad },
61
+ { tagLen: tagLength, aad: Buffer.alloc(0) },
62
+ { tagLen: tagLength, aad: undefined },
63
+ ];
64
+ let lastError;
65
+ for (const attempt of decryptionAttempts) {
66
+ try {
67
+ const encrypted = ciphertext.subarray(0, ciphertext.length - attempt.tagLen);
68
+ const authTag = ciphertext.subarray(ciphertext.length - attempt.tagLen);
69
+ const decipher = createDecipheriv('chacha20-poly1305', key, nonce);
70
+ decipher.setAuthTag(authTag);
71
+ if (attempt.aad !== undefined) {
72
+ decipher.setAAD(attempt.aad, { plaintextLength: encrypted.length });
73
+ }
74
+ const decrypted = Buffer.concat([
75
+ decipher.update(encrypted),
76
+ decipher.final(),
77
+ ]);
78
+ log.debug('Decryption successful with AAD:', attempt.aad ? 'provided' : 'none');
79
+ return decrypted;
80
+ }
81
+ catch (error) {
82
+ lastError = error instanceof Error ? error : new Error(String(error));
83
+ }
84
+ }
85
+ const errorMessage = lastError
86
+ ? `ChaCha20-Poly1305 decryption failed: ${lastError.message}`
87
+ : 'ChaCha20-Poly1305 decryption failed: invalid ciphertext or authentication tag';
88
+ // Log the error with stack trace for debugging real failures
89
+ // Skip logging in test environment to avoid cluttering test output with expected failures
90
+ if (lastError && process.env.NODE_ENV !== 'test') {
91
+ log.error('All ChaCha20-Poly1305 decryption attempts failed:', {
92
+ message: lastError.message,
93
+ stack: lastError.stack,
94
+ });
95
+ }
96
+ throw new CryptographyError(errorMessage);
97
+ }
@@ -0,0 +1,16 @@
1
+ import type { PairingKeys } from '../types.js';
2
+ /**
3
+ * Generates a new Ed25519 key pair for cryptographic operations
4
+ * @returns PairingKeys object containing 32-byte public and private key buffers
5
+ * @throws CryptographyError if key generation fails
6
+ */
7
+ export declare function generateEd25519KeyPair(): PairingKeys;
8
+ /**
9
+ * Creates an Ed25519 digital signature for the provided data
10
+ * @param data - The data to sign
11
+ * @param privateKey - 32-byte Ed25519 private key
12
+ * @returns Buffer containing the 64-byte signature
13
+ * @throws CryptographyError if signing fails or private key is invalid
14
+ */
15
+ export declare function createEd25519Signature(data: Buffer, privateKey: Buffer): Buffer;
16
+ //# sourceMappingURL=ed25519.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ed25519.d.ts","sourceRoot":"","sources":["../../../../../src/lib/apple-tv/encryption/ed25519.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAW/C;;;;GAIG;AACH,wBAAgB,sBAAsB,IAAI,WAAW,CA4BpD;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GACjB,MAAM,CA0BR"}
@@ -0,0 +1,93 @@
1
+ import { logger } from '@appium/support';
2
+ import { generateKeyPairSync, sign, } from 'node:crypto';
3
+ import { CryptographyError } from '../errors.js';
4
+ const log = logger.getLogger('Ed25519');
5
+ const ED25519_PUBLIC_KEY_LENGTH = 32;
6
+ const ED25519_PRIVATE_KEY_LENGTH = 32;
7
+ const ED25519_PKCS8_PREFIX = Buffer.from('302e020100300506032b657004220420', 'hex');
8
+ /**
9
+ * Generates a new Ed25519 key pair for cryptographic operations
10
+ * @returns PairingKeys object containing 32-byte public and private key buffers
11
+ * @throws CryptographyError if key generation fails
12
+ */
13
+ export function generateEd25519KeyPair() {
14
+ try {
15
+ const keyPair = generateKeyPairSync('ed25519');
16
+ const publicKeyDer = keyPair.publicKey.export({
17
+ type: 'spki',
18
+ format: 'der',
19
+ });
20
+ const privateKeyDer = keyPair.privateKey.export({
21
+ type: 'pkcs8',
22
+ format: 'der',
23
+ });
24
+ const publicKeyBuffer = extractEd25519PublicKey(publicKeyDer);
25
+ const privateKeyBuffer = extractEd25519PrivateKey(privateKeyDer);
26
+ return {
27
+ publicKey: publicKeyBuffer,
28
+ privateKey: privateKeyBuffer,
29
+ };
30
+ }
31
+ catch (error) {
32
+ log.error('Failed to generate Ed25519 key pair:', error);
33
+ const message = error instanceof Error ? error.message : String(error);
34
+ throw new CryptographyError(`Failed to generate Ed25519 key pair: ${message}`);
35
+ }
36
+ }
37
+ /**
38
+ * Creates an Ed25519 digital signature for the provided data
39
+ * @param data - The data to sign
40
+ * @param privateKey - 32-byte Ed25519 private key
41
+ * @returns Buffer containing the 64-byte signature
42
+ * @throws CryptographyError if signing fails or private key is invalid
43
+ */
44
+ export function createEd25519Signature(data, privateKey) {
45
+ if (!data || data.length === 0) {
46
+ throw new CryptographyError('Data to sign cannot be empty');
47
+ }
48
+ if (!privateKey || privateKey.length !== ED25519_PRIVATE_KEY_LENGTH) {
49
+ throw new CryptographyError(`Private key must be ${ED25519_PRIVATE_KEY_LENGTH} bytes`);
50
+ }
51
+ try {
52
+ const privateKeyDer = Buffer.concat([ED25519_PKCS8_PREFIX, privateKey]);
53
+ return sign(null, data, {
54
+ key: privateKeyDer,
55
+ format: 'der',
56
+ type: 'pkcs8',
57
+ });
58
+ }
59
+ catch (error) {
60
+ log.error('Failed to create Ed25519 signature:', error);
61
+ const message = error instanceof Error ? error.message : String(error);
62
+ throw new CryptographyError(`Failed to create Ed25519 signature: ${message}`);
63
+ }
64
+ }
65
+ /**
66
+ * Extracts the raw 32-byte public key from DER-encoded SPKI format
67
+ * @param publicKeyDer - DER-encoded public key
68
+ * @returns 32-byte public key buffer
69
+ * @throws CryptographyError if extraction fails
70
+ */
71
+ function extractEd25519PublicKey(publicKeyDer) {
72
+ if (publicKeyDer.length < ED25519_PUBLIC_KEY_LENGTH) {
73
+ throw new CryptographyError('Invalid public key DER format');
74
+ }
75
+ return publicKeyDer.subarray(publicKeyDer.length - ED25519_PUBLIC_KEY_LENGTH);
76
+ }
77
+ /**
78
+ * Extracts the raw 32-byte private key from DER-encoded PKCS#8 format
79
+ * @param privateKeyDer - DER-encoded private key
80
+ * @returns 32-byte private key buffer
81
+ * @throws CryptographyError if extraction fails
82
+ */
83
+ function extractEd25519PrivateKey(privateKeyDer) {
84
+ const octetStringPattern = Buffer.from([0x04, 0x20]);
85
+ const index = privateKeyDer.indexOf(octetStringPattern);
86
+ if (index !== -1 && index + 34 <= privateKeyDer.length) {
87
+ return privateKeyDer.subarray(index + 2, index + 34);
88
+ }
89
+ if (privateKeyDer.length >= 48) {
90
+ return privateKeyDer.subarray(16, 48);
91
+ }
92
+ throw new CryptographyError('Unable to extract private key from DER format');
93
+ }