@semi-app/miplay 0.0.0-stage → 1.0.0

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 (83) hide show
  1. package/README.md +4 -2
  2. package/dist/MAGPIE-LICENSE.txt +21 -0
  3. package/dist/assets/airplay-0f650dbf.png +0 -0
  4. package/dist/assets/index-c3d52e7b.js +1 -0
  5. package/dist/assets/index-cf41e0aa.css +1 -0
  6. package/dist/assets/mina-f2e7977b.png +0 -0
  7. package/dist/assets/miplay-6539f915.js +124 -0
  8. package/dist/assets/miplay-70349e65.png +0 -0
  9. package/dist/assets/miplay-c5d217a1.css +1 -0
  10. package/dist/assets/semi-595e39af.ico +0 -0
  11. package/dist/assets/semi-core-38c824f6.png +0 -0
  12. package/dist/assets/tray-59cb5e08.js +1 -0
  13. package/dist/assets/tray-d30ea4dd.css +1 -0
  14. package/dist/background/main.cjs +19657 -0
  15. package/dist/background/playfair.wasm +0 -0
  16. package/dist/background/vendor/LICENSE +201 -0
  17. package/dist/background/vendor/NOTICE +22 -0
  18. package/dist/background/vendor/README.md +20 -0
  19. package/dist/background/vendor/alac.js +87 -0
  20. package/dist/background/vendor/alacDecoder.js +317 -0
  21. package/dist/background/vendor/appleKey.js +61 -0
  22. package/dist/background/vendor/ntpTiming.js +99 -0
  23. package/dist/background/vendor/package.json +1 -0
  24. package/dist/background/vendor/playfair/BUILD.md +17 -0
  25. package/dist/background/vendor/playfair/LICENSE.md +637 -0
  26. package/dist/background/vendor/playfair/MUSL-COPYRIGHT +193 -0
  27. package/dist/background/vendor/playfair/README.md +24 -0
  28. package/dist/background/vendor/playfair/hand_garble.c +443 -0
  29. package/dist/background/vendor/playfair/modified_md5.c +119 -0
  30. package/dist/background/vendor/playfair/omg_hax.c +540 -0
  31. package/dist/background/vendor/playfair/omg_hax.h +32 -0
  32. package/dist/background/vendor/playfair/playfair.c +31 -0
  33. package/dist/background/vendor/playfair/playfair.h +6 -0
  34. package/dist/background/vendor/playfair/sap_hash.c +96 -0
  35. package/dist/background/vendor/playfair/wasm-wrapper.c +22 -0
  36. package/dist/background/vendor/receiver.js +677 -0
  37. package/dist/index.html +6 -0
  38. package/dist/licenses/@leichtgewicht/ip-codec/LICENSE +21 -0
  39. package/dist/licenses/@mediabunny/aac-encoder/LICENSE +373 -0
  40. package/dist/licenses/array-flatten/LICENSE +21 -0
  41. package/dist/licenses/bonjour/LICENSE +21 -0
  42. package/dist/licenses/buffer-indexof/LICENSE +20 -0
  43. package/dist/licenses/call-bind/LICENSE +21 -0
  44. package/dist/licenses/call-bind-apply-helpers/LICENSE +21 -0
  45. package/dist/licenses/call-bound/LICENSE +21 -0
  46. package/dist/licenses/deep-equal/LICENSE +21 -0
  47. package/dist/licenses/define-data-property/LICENSE +21 -0
  48. package/dist/licenses/define-properties/LICENSE +21 -0
  49. package/dist/licenses/dns-equal/LICENSE +21 -0
  50. package/dist/licenses/dns-packet/LICENSE +21 -0
  51. package/dist/licenses/dns-txt/LICENSE +21 -0
  52. package/dist/licenses/dunder-proto/LICENSE +21 -0
  53. package/dist/licenses/es-define-property/LICENSE +21 -0
  54. package/dist/licenses/es-errors/LICENSE +21 -0
  55. package/dist/licenses/es-object-atoms/LICENSE +21 -0
  56. package/dist/licenses/ffmpeg/COPYING.LGPLv2.1 +502 -0
  57. package/dist/licenses/ffmpeg/LICENSE.md +127 -0
  58. package/dist/licenses/function-bind/LICENSE +20 -0
  59. package/dist/licenses/functions-have-names/LICENSE +21 -0
  60. package/dist/licenses/get-intrinsic/LICENSE +21 -0
  61. package/dist/licenses/get-proto/LICENSE +21 -0
  62. package/dist/licenses/gopd/LICENSE +21 -0
  63. package/dist/licenses/has-property-descriptors/LICENSE +21 -0
  64. package/dist/licenses/has-symbols/LICENSE +21 -0
  65. package/dist/licenses/has-tostringtag/LICENSE +21 -0
  66. package/dist/licenses/hasown/LICENSE +21 -0
  67. package/dist/licenses/is-arguments/LICENSE +20 -0
  68. package/dist/licenses/is-date-object/LICENSE +22 -0
  69. package/dist/licenses/is-regex/LICENSE +20 -0
  70. package/dist/licenses/magpie-MIT.txt +21 -0
  71. package/dist/licenses/math-intrinsics/LICENSE +21 -0
  72. package/dist/licenses/mediabunny/LICENSE +373 -0
  73. package/dist/licenses/mediabunny-MPL-2.0.txt +373 -0
  74. package/dist/licenses/multicast-dns/LICENSE +21 -0
  75. package/dist/licenses/multicast-dns-service-types/LICENSE +21 -0
  76. package/dist/licenses/object-is/LICENSE +20 -0
  77. package/dist/licenses/object-keys/LICENSE +21 -0
  78. package/dist/licenses/regexp.prototype.flags/LICENSE +22 -0
  79. package/dist/licenses/set-function-length/LICENSE +21 -0
  80. package/dist/licenses/set-function-name/LICENSE +21 -0
  81. package/dist/licenses/thunky/LICENSE +21 -0
  82. package/dist/tray.html +5 -0
  83. package/package.json +92 -5
@@ -0,0 +1,61 @@
1
+ import { constants, privateDecrypt, privateEncrypt } from 'node:crypto';
2
+ /**
3
+ * The RSA key every AirPlay 1 sender assumes a receiver holds.
4
+ *
5
+ * A sender wraps its AES audio key in the AirPort Express public key and the
6
+ * protocol has no way to negotiate a different one, so a receiver either holds
7
+ * this exact private key or cannot read a single audio packet. That is why a
8
+ * receiver advertising `et=0` gets abandoned right after OPTIONS: an iPhone
9
+ * will not send audio it cannot encrypt.
10
+ *
11
+ * Every third-party RAOP receiver ships it for the same reason -- shairport-sync
12
+ * and libraop among them -- and it has been public for well over a decade.
13
+ */
14
+ const PRIVATE_KEY = '-----BEGIN RSA PRIVATE KEY-----\n' +
15
+ 'MIIEpQIBAAKCAQEA59dE8qLieItsH1WgjrcFRKj6eUWqi+bGLOX1HL3U3GhC/j0Qg90u3sG/1CUt\n' +
16
+ 'wC5vOYvfDmFI6oSFXi5ELabWJmT2dKHzBJKa3k9ok+8t9ucRqMd6DZHJ2YCCLlDRKSKv6kDqnw4U\n' +
17
+ 'wPdpOMXziC/AMj3Z/lUVX1G7WSHCAWKf1zNS1eLvqr+boEjXuBOitnZ/bDzPHrTOZz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
+ 'cJyRM9SJ7OKlGt0FMSdJD5KG0XPIpAVNwgpXXH5MDJg09KHeh0kXo+QA6viFBi21y340NonnEfdf\n' +
31
+ '54PX4ZGS/Xac1UK+pLkBB+zRAoGAf0AY3H3qKS2lMEI4bzEFoHeK3G895pDaK3TFBVmD7fV0Zhov\n' +
32
+ '17fegFPMwOII8MisYm9ZfT2Z0s5Ro3s5rkt+nvLAdfC/PYPKzTLalpGSwomSNYJcB9HNMlmhkGzc\n' +
33
+ '1JnLYT4iyUyx6pcZBmCd8bD0iwY/FzcgNDaUmbX9+XDvRA0CgYEAkE7pIPlE71qvfJQgoA9em0gI\n' +
34
+ 'LAuE4Pu13aKiJnfft7hIjbK+5kyb3TysZvoyDnb3HOKvInK7vXbKuU4ISgxB2bB3HcYzQMGsz1qJ\n' +
35
+ '2gG0N5hvJpzwwhbhXqFKA4zaaSrw622wDniAK5MlIE0tIAKKP4yxNGjoD2QYjhBGuhvkWKY=\n' +
36
+ '-----END RSA PRIVATE KEY-----\n';
37
+ /** Unwrap an `rsaaeskey` from the SDP into the 16-byte AES key. */
38
+ export function decryptAesKey(wrapped) {
39
+ return privateDecrypt({ key: PRIVATE_KEY, padding: constants.RSA_PKCS1_OAEP_PADDING }, wrapped);
40
+ }
41
+ /**
42
+ * Sign an `Apple-Challenge` into the `Apple-Response` header value.
43
+ *
44
+ * The signed blob is the challenge followed by our address and MAC, zero-filled
45
+ * to 32 bytes. The sender rebuilds it from what it knows about us, so both
46
+ * halves have to agree byte for byte.
47
+ */
48
+ export function answerChallenge(challenge, localAddress, mac) {
49
+ const data = Buffer.alloc(32);
50
+ const used = challenge.copy(data, 0, 0, Math.min(challenge.length, 32 - 10));
51
+ const octets = localAddress.split('.');
52
+ if (octets.length === 4) {
53
+ Buffer.from(octets.map((o) => Number(o) & 0xff)).copy(data, used);
54
+ mac.copy(data, used + 4, 0, 6);
55
+ }
56
+ else {
57
+ mac.copy(data, used, 0, 6);
58
+ }
59
+ const signed = privateEncrypt({ key: PRIVATE_KEY, padding: constants.RSA_PKCS1_PADDING }, data);
60
+ return signed.toString('base64').replace(/=+$/, '');
61
+ }
@@ -0,0 +1,99 @@
1
+ /**
2
+ * The legacy NTP timing lane.
3
+ *
4
+ * Not every AirPlay 2 receiver does PTP, and the ones that do not are not
5
+ * honest about it: a device can advertise SupportsPTP, accept a PTP session
6
+ * SETUP with a 200, and then never send a single clock probe — after which it
7
+ * renders silence while the sender looks perfectly healthy. Measured on a
8
+ * BeoLab 50: audio on the wire at the right rate, nothing coming back, no
9
+ * sound. The tell is in the SETUP reply, which carries a `timingPort` instead
10
+ * of just a `timingPeerInfo`.
11
+ *
12
+ * For those receivers the sender runs this instead: a responder the device
13
+ * polls for the time, and a different sync packet. Apple receivers are the
14
+ * opposite case — they render silence on an NTP-timed realtime stream — so the
15
+ * two lanes are not interchangeable, they are per device.
16
+ */
17
+ import { createSocket } from 'node:dgram';
18
+ /** Seconds between 1900 (NTP) and 1970 (Unix). */
19
+ const NTP_EPOCH_DELTA = 2_208_988_800;
20
+ const REQUEST_TYPE = 0xd2;
21
+ const RESPONSE_TYPE = 0xd3;
22
+ const REQUEST_SIZE = 32;
23
+ /** Now, as an NTP fixed-point value (seconds << 32 | fraction). */
24
+ export function ntpNow() {
25
+ const ms = Date.now();
26
+ const seconds = BigInt(Math.floor(ms / 1000) + NTP_EPOCH_DELTA);
27
+ const fraction = (BigInt(ms % 1000) << 32n) / 1000n;
28
+ return (seconds << 32n) | fraction;
29
+ }
30
+ /**
31
+ * Answers a receiver's timing requests so it can place our clock.
32
+ *
33
+ * The exchange is the RAOP one: a 32-byte request with type 0xD2, answered with
34
+ * type 0xD3 carrying the request's transmit time as the reference, plus our
35
+ * receive and transmit times. Left unanswered the receiver has no timeline and
36
+ * plays nothing.
37
+ */
38
+ export class NtpTimingResponder {
39
+ socket = null;
40
+ /** Requests answered — a receiver that stops asking has dropped the session. */
41
+ exchanges = 0;
42
+ async start() {
43
+ const socket = createSocket({ type: 'udp4', reuseAddr: true });
44
+ socket.on('message', (msg, rinfo) => this.onMessage(msg, rinfo));
45
+ socket.on('error', () => {
46
+ /* a timing socket error surfaces as the receiver going quiet */
47
+ });
48
+ await new Promise((resolve, reject) => {
49
+ socket.once('error', reject);
50
+ socket.bind(0, () => {
51
+ socket.removeListener('error', reject);
52
+ resolve();
53
+ });
54
+ });
55
+ this.socket = socket;
56
+ return socket.address().port;
57
+ }
58
+ stop() {
59
+ this.socket?.close();
60
+ this.socket = null;
61
+ }
62
+ onMessage(msg, rinfo) {
63
+ if (msg.length < REQUEST_SIZE || msg[1] !== REQUEST_TYPE) {
64
+ return;
65
+ }
66
+ const response = Buffer.alloc(32);
67
+ response[0] = 0x80;
68
+ response[1] = RESPONSE_TYPE;
69
+ // Reference time: the request's own transmit timestamp, echoed back.
70
+ msg.copy(response, 8, 24, 32);
71
+ const now = ntpNow();
72
+ response.writeUInt32BE(Number(now >> 32n), 16);
73
+ response.writeUInt32BE(Number(now & 0xffffffffn), 20);
74
+ // We answer immediately, so transmit time is the receive time.
75
+ response.copy(response, 24, 16, 24);
76
+ this.socket?.send(response, rinfo.port, rinfo.address);
77
+ this.exchanges++;
78
+ }
79
+ }
80
+ /**
81
+ * The NTP flavour of the anchor packet (20 bytes, type 0xD4) — where the media
82
+ * timeline sits on the NTP clock. The PTP lane sends a different, longer one.
83
+ *
84
+ * :param rtpTimestamp: the sender's current RTP position.
85
+ * :param leadFrames: how far ahead of the render point that position is.
86
+ */
87
+ export function buildNtpSyncPacket(rtpTimestamp, leadFrames, first) {
88
+ const packet = Buffer.alloc(20);
89
+ packet[0] = first ? 0x90 : 0x80;
90
+ packet[1] = 0xd4;
91
+ packet.writeUInt16BE(0x0007, 2);
92
+ const playing = rtpTimestamp >= leadFrames ? rtpTimestamp - leadFrames : 0;
93
+ packet.writeUInt32BE(playing >>> 0, 4);
94
+ const now = ntpNow();
95
+ packet.writeUInt32BE(Number(now >> 32n), 8);
96
+ packet.writeUInt32BE(Number(now & 0xffffffffn), 12);
97
+ packet.writeUInt32BE(rtpTimestamp >>> 0, 16);
98
+ return packet;
99
+ }
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,17 @@
1
+ # Rebuild the portable module
2
+
3
+ Use Zig 0.14.1. No Python is required. From this source directory:
4
+
5
+ ```sh
6
+ zig cc -target wasm32-wasi -mexec-model=reactor -O2 -fwrapv -fno-strict-aliasing -DNDEBUG \
7
+ playfair.c omg_hax.c modified_md5.c sap_hash.c hand_garble.c wasm-wrapper.c \
8
+ -Wl,--export=key_message_buffer -Wl,--export=wrapped_key_buffer \
9
+ -Wl,--export=plain_key_buffer -Wl,--export=unwrap_key -Wl,--export=wipe_key_buffers \
10
+ -Wl,-z,stack-size=65536 -Wl,--initial-memory=1048576 -Wl,--max-memory=1048576 \
11
+ -Wl,--strip-all -o ../../playfair.wasm
12
+ ```
13
+
14
+ The repository wrapper is `scripts/build-miplay-fairplay.cjs`. Compile flags retain
15
+ 32-bit wrapping semantics and disable strict-aliasing assumptions required by the
16
+ original implementation. The result has no imports and can be loaded with plain
17
+ WebAssembly in Node, without a WASI host or OS-specific native addon.