@limrun/ui 0.14.0-rc.4 → 0.14.0-rc.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/dist/app-store-relay/index.cjs +3 -3
- package/dist/app-store-relay/index.d.ts +108 -4
- package/dist/app-store-relay/index.js +353 -160
- package/dist/app-store-relay/react.cjs +1 -1
- package/dist/app-store-relay/react.js +1 -1
- package/dist/apple-credentials/index.cjs +1 -1
- package/dist/apple-credentials/index.d.ts +59 -8
- package/dist/apple-credentials/index.js +197 -133
- package/dist/client-C9z_sgOf.js +1 -0
- package/dist/{client-DSuNtWDv.mjs → client-CFDB4mX5.mjs} +37 -30
- package/dist/core/device-install/apple/provisioning.d.ts +25 -0
- package/dist/core/device-install/apple/relay.d.ts +13 -0
- package/dist/core/device-install/storage/secret-store.d.ts +24 -1
- package/dist/device-build/index.cjs +1 -1
- package/dist/device-build/index.js +1 -1
- package/dist/device-install/index.cjs +1 -1
- package/dist/device-install/index.js +175 -172
- package/dist/{provisioning-B_DefBEp.mjs → provisioning-CDPvxd1h.mjs} +63 -32
- package/dist/provisioning-CbC4h--7.js +1 -0
- package/package.json +1 -1
- package/src/app-store-relay/index.ts +358 -23
- package/src/apple-credentials/index.test.ts +22 -0
- package/src/apple-credentials/index.ts +161 -14
- package/src/core/device-install/apple/client.ts +13 -6
- package/src/core/device-install/apple/provisioning.test.ts +30 -0
- package/src/core/device-install/apple/provisioning.ts +39 -0
- package/src/core/device-install/apple/relay.ts +20 -0
- package/src/core/device-install/operations/operations.ts +6 -1
- package/src/core/device-install/storage/secret-store.ts +36 -2
- package/dist/client-D1drDXxE.js +0 -1
- package/dist/provisioning-BlQMccX_.js +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { e as
|
|
1
|
+
import { e as w } from "../errors-gy8yQJos.mjs";
|
|
2
2
|
import { j as Ue, n as Se, k as ve } from "../browser-storage-BnO-Ma-e.mjs";
|
|
3
|
-
const v = 1,
|
|
3
|
+
const v = 1, d = 16, s = {
|
|
4
4
|
DeviceHello: 1,
|
|
5
5
|
OpenStream: 2,
|
|
6
6
|
OpenResult: 3,
|
|
@@ -15,31 +15,31 @@ const v = 1, f = 16, s = {
|
|
|
15
15
|
PairRecordReady: 12
|
|
16
16
|
};
|
|
17
17
|
function V(e) {
|
|
18
|
-
const t = new Uint8Array(
|
|
19
|
-
return
|
|
18
|
+
const t = new Uint8Array(d + e.payload.byteLength), n = new DataView(t.buffer);
|
|
19
|
+
return n.setUint8(0, v), n.setUint8(1, e.type), n.setUint8(2, 0), n.setUint8(3, 0), n.setUint32(4, e.requestId), n.setUint32(8, e.streamId), n.setUint32(12, e.payload.byteLength), t.set(e.payload, d), t;
|
|
20
20
|
}
|
|
21
21
|
function A(e) {
|
|
22
|
-
if (e.byteLength <
|
|
22
|
+
if (e.byteLength < d)
|
|
23
23
|
throw new Error(`Relay frame too short: ${e.byteLength}`);
|
|
24
|
-
const t = new DataView(e.buffer, e.byteOffset, e.byteLength),
|
|
25
|
-
if (
|
|
26
|
-
throw new Error(`Unsupported relay protocol version ${
|
|
27
|
-
const
|
|
28
|
-
if (e.byteLength !==
|
|
24
|
+
const t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = t.getUint8(0);
|
|
25
|
+
if (n !== v)
|
|
26
|
+
throw new Error(`Unsupported relay protocol version ${n}`);
|
|
27
|
+
const r = t.getUint32(12);
|
|
28
|
+
if (e.byteLength !== d + r)
|
|
29
29
|
throw new Error(
|
|
30
|
-
`Relay frame length mismatch: got ${e.byteLength}, expected ${
|
|
30
|
+
`Relay frame length mismatch: got ${e.byteLength}, expected ${d + r}`
|
|
31
31
|
);
|
|
32
32
|
return {
|
|
33
33
|
type: t.getUint8(1),
|
|
34
34
|
requestId: t.getUint32(4),
|
|
35
35
|
streamId: t.getUint32(8),
|
|
36
|
-
payload: e.slice(
|
|
36
|
+
payload: e.slice(d)
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
function l(e) {
|
|
40
40
|
return new TextEncoder().encode(JSON.stringify(e));
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function y(e) {
|
|
43
43
|
return JSON.parse(new TextDecoder().decode(e));
|
|
44
44
|
}
|
|
45
45
|
async function C() {
|
|
@@ -48,60 +48,60 @@ async function C() {
|
|
|
48
48
|
return navigator.usb.requestDevice({ filters: [{ vendorId: 1452 }] });
|
|
49
49
|
}
|
|
50
50
|
function L(e) {
|
|
51
|
-
const t = [],
|
|
52
|
-
(a) => a.configurationValue ===
|
|
51
|
+
const t = [], n = e.configuration?.configurationValue, r = e.configurations.find(
|
|
52
|
+
(a) => a.configurationValue === n
|
|
53
53
|
);
|
|
54
|
-
|
|
54
|
+
r && t.push(...U(r));
|
|
55
55
|
for (const a of e.configurations)
|
|
56
|
-
a.configurationValue !==
|
|
56
|
+
a.configurationValue !== n && t.push(...U(a));
|
|
57
57
|
return t;
|
|
58
58
|
}
|
|
59
59
|
function U(e) {
|
|
60
60
|
const t = [];
|
|
61
|
-
for (const
|
|
62
|
-
for (const
|
|
63
|
-
|
|
61
|
+
for (const n of e.interfaces)
|
|
62
|
+
for (const r of n.alternates)
|
|
63
|
+
r.interfaceClass === 255 && r.interfaceSubclass === 254 && r.interfaceProtocol === 2 && t.push({
|
|
64
64
|
configurationValue: e.configurationValue,
|
|
65
|
-
interfaceNumber:
|
|
66
|
-
alternateSetting:
|
|
67
|
-
endpoints:
|
|
65
|
+
interfaceNumber: n.interfaceNumber,
|
|
66
|
+
alternateSetting: r.alternateSetting,
|
|
67
|
+
endpoints: r.endpoints
|
|
68
68
|
});
|
|
69
69
|
return t;
|
|
70
70
|
}
|
|
71
71
|
async function T(e, t) {
|
|
72
72
|
e.opened || await e.open(), (!e.configuration || e.configuration.configurationValue !== t.configurationValue) && await e.selectConfiguration(t.configurationValue), await e.claimInterface(t.interfaceNumber), await e.selectAlternateInterface(t.interfaceNumber, t.alternateSetting);
|
|
73
73
|
}
|
|
74
|
-
function
|
|
74
|
+
function B(e) {
|
|
75
75
|
const t = e.endpoints.find(
|
|
76
|
-
(
|
|
77
|
-
),
|
|
78
|
-
(
|
|
76
|
+
(r) => r.direction === "out" && r.type === "bulk"
|
|
77
|
+
), n = e.endpoints.find(
|
|
78
|
+
(r) => r.direction === "in" && r.type === "bulk"
|
|
79
79
|
);
|
|
80
|
-
if (!t || !
|
|
80
|
+
if (!t || !n)
|
|
81
81
|
throw new Error("Could not find usbmux bulk endpoints.");
|
|
82
|
-
return { outEndpoint: t, inEndpoint:
|
|
82
|
+
return { outEndpoint: t, inEndpoint: n };
|
|
83
83
|
}
|
|
84
|
-
async function R(e, t,
|
|
85
|
-
const
|
|
86
|
-
if (
|
|
87
|
-
throw new Error(`USB transferOut failed: ${
|
|
88
|
-
|
|
84
|
+
async function R(e, t, n) {
|
|
85
|
+
const r = await e.transferOut(t.endpointNumber, n);
|
|
86
|
+
if (r.status !== "ok")
|
|
87
|
+
throw new Error(`USB transferOut failed: ${r.status}`);
|
|
88
|
+
n.byteLength % t.packetSize === 0 && await e.transferOut(t.endpointNumber, new Uint8Array());
|
|
89
89
|
}
|
|
90
|
-
async function
|
|
91
|
-
const
|
|
92
|
-
if (
|
|
93
|
-
throw new Error(`USB transferIn failed: ${
|
|
94
|
-
return new Uint8Array(
|
|
90
|
+
async function W(e, t, n = 16384) {
|
|
91
|
+
const r = await e.transferIn(t.endpointNumber, n);
|
|
92
|
+
if (r.status !== "ok" || !r.data)
|
|
93
|
+
throw new Error(`USB transferIn failed: ${r.status}`);
|
|
94
|
+
return new Uint8Array(r.data.buffer, r.data.byteOffset, r.data.byteLength);
|
|
95
95
|
}
|
|
96
|
-
const E = 0, F = 2, k = 6, _ = 4277009102, m = 2, M = 4,
|
|
96
|
+
const E = 0, F = 2, k = 6, _ = 4277009102, m = 2, M = 4, f = 16, j = 49152;
|
|
97
97
|
async function H(e, t) {
|
|
98
|
-
const { inEndpoint:
|
|
99
|
-
i.setUint32(0, 2), i.setUint32(4, 0), i.setUint32(8, 0), await R(e,
|
|
100
|
-
const o = await
|
|
98
|
+
const { inEndpoint: n, outEndpoint: r } = B(t), a = new Uint8Array(12), i = new DataView(a.buffer);
|
|
99
|
+
i.setUint32(0, 2), i.setUint32(4, 0), i.setUint32(8, 0), await R(e, r, O(E, a));
|
|
100
|
+
const o = await x(e, n, 1), c = new DataView(o.payload.buffer, o.payload.byteOffset).getUint32(0), u = {
|
|
101
101
|
device: e,
|
|
102
102
|
candidate: t,
|
|
103
|
-
inEndpoint:
|
|
104
|
-
outEndpoint:
|
|
103
|
+
inEndpoint: n,
|
|
104
|
+
outEndpoint: r,
|
|
105
105
|
muxVersion: c,
|
|
106
106
|
txSeq: 0,
|
|
107
107
|
rxSeq: 65535,
|
|
@@ -110,12 +110,12 @@ async function H(e, t) {
|
|
|
110
110
|
writeChain: Promise.resolve(),
|
|
111
111
|
closed: !1
|
|
112
112
|
};
|
|
113
|
-
return c >= 2 && await
|
|
113
|
+
return c >= 2 && await I(u, F, new Uint8Array([7])), Y(u), u;
|
|
114
114
|
}
|
|
115
115
|
async function J(e, t) {
|
|
116
116
|
if (e.closed)
|
|
117
117
|
throw new Error("usbmux session is closed.");
|
|
118
|
-
let
|
|
118
|
+
let n, r;
|
|
119
119
|
const a = {
|
|
120
120
|
session: e,
|
|
121
121
|
sport: e.nextSport++,
|
|
@@ -125,17 +125,17 @@ async function J(e, t) {
|
|
|
125
125
|
queue: [],
|
|
126
126
|
waiters: [],
|
|
127
127
|
opened: new Promise((i, o) => {
|
|
128
|
-
|
|
128
|
+
n = i, r = o;
|
|
129
129
|
}),
|
|
130
|
-
resolveOpened:
|
|
131
|
-
rejectOpened:
|
|
130
|
+
resolveOpened: n,
|
|
131
|
+
rejectOpened: r
|
|
132
132
|
};
|
|
133
|
-
return e.streams.set(g(t, a.sport), a), await
|
|
133
|
+
return e.streams.set(g(t, a.sport), a), await h(a, m, new Uint8Array()), await a.opened, a;
|
|
134
134
|
}
|
|
135
135
|
async function G(e, t) {
|
|
136
136
|
if (e.session.closed)
|
|
137
137
|
throw new Error("usbmux session is closed.");
|
|
138
|
-
await
|
|
138
|
+
await h(e, f, t), e.seq += t.byteLength;
|
|
139
139
|
}
|
|
140
140
|
async function Q(e) {
|
|
141
141
|
if (e.queue.length > 0)
|
|
@@ -146,94 +146,94 @@ async function Q(e) {
|
|
|
146
146
|
e.waiters.push(t);
|
|
147
147
|
});
|
|
148
148
|
}
|
|
149
|
-
function
|
|
149
|
+
function P(e) {
|
|
150
150
|
e.closed = !0;
|
|
151
151
|
for (const t of e.streams.values())
|
|
152
152
|
for (t.error = new Error("usbmux session closed"), t.rejectOpened(t.error); t.waiters.length > 0; )
|
|
153
153
|
t.waiters.shift()(new Uint8Array());
|
|
154
154
|
e.streams.clear();
|
|
155
155
|
}
|
|
156
|
-
async function
|
|
157
|
-
const
|
|
158
|
-
a.setUint16(0, e.sport), a.setUint16(2, e.dport), a.setUint32(4, e.seq), a.setUint32(8, e.ack), a.setUint8(12, 80), a.setUint8(13, t), a.setUint16(14, 512),
|
|
156
|
+
async function h(e, t, n) {
|
|
157
|
+
const r = new Uint8Array(20 + n.byteLength), a = new DataView(r.buffer);
|
|
158
|
+
a.setUint16(0, e.sport), a.setUint16(2, e.dport), a.setUint32(4, e.seq), a.setUint32(8, e.ack), a.setUint8(12, 80), a.setUint8(13, t), a.setUint16(14, 512), r.set(n, 20), await I(e.session, k, r);
|
|
159
159
|
}
|
|
160
|
-
async function
|
|
160
|
+
async function I(e, t, n) {
|
|
161
161
|
if (e.closed)
|
|
162
162
|
throw new Error("usbmux session is closed.");
|
|
163
163
|
return e.writeChain = e.writeChain.then(async () => {
|
|
164
164
|
if (e.closed) return;
|
|
165
|
-
const
|
|
166
|
-
await R(e.device, e.outEndpoint,
|
|
165
|
+
const r = e.muxVersion >= 2 ? z(t, n, e.txSeq++, e.rxSeq) : O(t, n);
|
|
166
|
+
await R(e.device, e.outEndpoint, r);
|
|
167
167
|
}), e.writeChain;
|
|
168
168
|
}
|
|
169
169
|
async function Y(e) {
|
|
170
170
|
try {
|
|
171
171
|
for (; ; ) {
|
|
172
172
|
if (e.closed) return;
|
|
173
|
-
const t = await
|
|
173
|
+
const t = await x(e.device, e.inEndpoint, e.muxVersion);
|
|
174
174
|
if (e.closed) return;
|
|
175
175
|
if (t.rxSeq !== void 0 && (e.rxSeq = t.rxSeq), t.protocol !== k)
|
|
176
176
|
continue;
|
|
177
|
-
const
|
|
178
|
-
if (
|
|
179
|
-
if (
|
|
180
|
-
for (
|
|
181
|
-
|
|
182
|
-
e.streams.delete(g(
|
|
177
|
+
const n = X(t.payload), r = e.streams.get(g(n.sport, n.dport));
|
|
178
|
+
if (r) {
|
|
179
|
+
if (n.flags & M) {
|
|
180
|
+
for (r.error = new Error(`Device reset stream ${r.dport}`), r.rejectOpened(r.error); r.waiters.length > 0; )
|
|
181
|
+
r.waiters.shift()(new Uint8Array());
|
|
182
|
+
e.streams.delete(g(r.dport, r.sport));
|
|
183
183
|
continue;
|
|
184
184
|
}
|
|
185
|
-
if ((
|
|
186
|
-
|
|
185
|
+
if ((n.flags & (m | f)) === (m | f)) {
|
|
186
|
+
r.seq += 1, r.ack = n.seq + 1, await h(r, f, new Uint8Array()), r.resolveOpened();
|
|
187
187
|
continue;
|
|
188
188
|
}
|
|
189
|
-
|
|
189
|
+
n.payload.byteLength !== 0 && (r.ack = n.seq + n.payload.byteLength, await h(r, f, new Uint8Array()), r.waiters.length > 0 ? r.waiters.shift()(n.payload) : r.queue.push(n.payload));
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
} catch {
|
|
193
|
-
e.closed ||
|
|
193
|
+
e.closed || P(e);
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
-
async function
|
|
196
|
+
async function x(e, t, n) {
|
|
197
197
|
for (; ; ) {
|
|
198
|
-
const
|
|
199
|
-
if (!(
|
|
198
|
+
const r = await W(e, t), a = K(r, n);
|
|
199
|
+
if (!(n === 1 && a.protocol !== E))
|
|
200
200
|
return a;
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
function O(e, t) {
|
|
204
|
-
const
|
|
205
|
-
return
|
|
204
|
+
const n = new Uint8Array(8 + t.byteLength), r = new DataView(n.buffer);
|
|
205
|
+
return r.setUint32(0, e), r.setUint32(4, n.byteLength), n.set(t, 8), n;
|
|
206
206
|
}
|
|
207
|
-
function z(e, t,
|
|
207
|
+
function z(e, t, n, r) {
|
|
208
208
|
const a = new Uint8Array(16 + t.byteLength), i = new DataView(a.buffer);
|
|
209
|
-
return i.setUint32(0, e), i.setUint32(4, a.byteLength), i.setUint32(8, _), i.setUint16(12,
|
|
209
|
+
return i.setUint32(0, e), i.setUint32(4, a.byteLength), i.setUint32(8, _), i.setUint16(12, n), i.setUint16(14, r), a.set(t, 16), a;
|
|
210
210
|
}
|
|
211
211
|
function K(e, t) {
|
|
212
|
-
const
|
|
212
|
+
const n = new DataView(e.buffer, e.byteOffset, e.byteLength), r = n.getUint32(0), a = n.getUint32(4), i = t >= 2 ? 16 : 8;
|
|
213
213
|
return {
|
|
214
|
-
protocol:
|
|
214
|
+
protocol: r,
|
|
215
215
|
length: a,
|
|
216
|
-
rxSeq: t >= 2 ?
|
|
216
|
+
rxSeq: t >= 2 ? n.getUint16(14) : void 0,
|
|
217
217
|
payload: e.slice(i, a)
|
|
218
218
|
};
|
|
219
219
|
}
|
|
220
220
|
function X(e) {
|
|
221
|
-
const t = new DataView(e.buffer, e.byteOffset, e.byteLength),
|
|
221
|
+
const t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = (t.getUint8(12) >> 4) * 4;
|
|
222
222
|
return {
|
|
223
223
|
sport: t.getUint16(0),
|
|
224
224
|
dport: t.getUint16(2),
|
|
225
225
|
seq: t.getUint32(4),
|
|
226
226
|
ack: t.getUint32(8),
|
|
227
227
|
flags: t.getUint8(13),
|
|
228
|
-
payload: e.slice(
|
|
228
|
+
payload: e.slice(n)
|
|
229
229
|
};
|
|
230
230
|
}
|
|
231
231
|
function g(e, t) {
|
|
232
232
|
return `${e}:${t}`;
|
|
233
233
|
}
|
|
234
234
|
class Z {
|
|
235
|
-
constructor(t,
|
|
236
|
-
this.webSocketUrl = t, this.session =
|
|
235
|
+
constructor(t, n, r, a) {
|
|
236
|
+
this.webSocketUrl = t, this.session = n, this.deviceHello = r, this.log = a;
|
|
237
237
|
}
|
|
238
238
|
socket;
|
|
239
239
|
streams = /* @__PURE__ */ new Map();
|
|
@@ -246,11 +246,11 @@ class Z {
|
|
|
246
246
|
this.closed = !0, this.log("Relay socket closed"), this.frameQueue.finally(() => {
|
|
247
247
|
this.pairRecordWaiter && (this.pairRecordWaiter.reject(new Error("Relay socket closed")), this.pairRecordWaiter = void 0);
|
|
248
248
|
});
|
|
249
|
-
}, await new Promise((
|
|
250
|
-
t.onopen = () =>
|
|
251
|
-
}), t.onmessage = (
|
|
252
|
-
const
|
|
253
|
-
this.enqueueFrame(
|
|
249
|
+
}, await new Promise((n, r) => {
|
|
250
|
+
t.onopen = () => n(), t.onerror = () => r(new Error("WebSocket connection failed"));
|
|
251
|
+
}), t.onmessage = (n) => {
|
|
252
|
+
const r = n.data instanceof ArrayBuffer ? new Uint8Array(n.data) : new Uint8Array();
|
|
253
|
+
this.enqueueFrame(r);
|
|
254
254
|
}, await this.send({
|
|
255
255
|
type: s.DeviceHello,
|
|
256
256
|
requestId: 0,
|
|
@@ -259,8 +259,8 @@ class Z {
|
|
|
259
259
|
}), this.log("Connected WebSocket relay");
|
|
260
260
|
}
|
|
261
261
|
async startPairing() {
|
|
262
|
-
const t = new Promise((
|
|
263
|
-
this.pairRecordWaiter = { resolve:
|
|
262
|
+
const t = new Promise((n, r) => {
|
|
263
|
+
this.pairRecordWaiter = { resolve: n, reject: r };
|
|
264
264
|
});
|
|
265
265
|
return await this.send({
|
|
266
266
|
type: s.StartPairing,
|
|
@@ -269,20 +269,20 @@ class Z {
|
|
|
269
269
|
payload: l({})
|
|
270
270
|
}), this.log("Pairing requested"), t;
|
|
271
271
|
}
|
|
272
|
-
async startInstall(t,
|
|
272
|
+
async startInstall(t, n) {
|
|
273
273
|
await this.send({
|
|
274
274
|
type: s.StartInstall,
|
|
275
275
|
requestId: 0,
|
|
276
276
|
streamId: 0,
|
|
277
|
-
payload: l({ ...t, ...
|
|
277
|
+
payload: l({ ...t, ...n })
|
|
278
278
|
}), this.log("Installation requested");
|
|
279
279
|
}
|
|
280
280
|
close() {
|
|
281
281
|
this.closed = !0, this.socket?.close();
|
|
282
282
|
}
|
|
283
283
|
enqueueFrame(t) {
|
|
284
|
-
this.frameQueue = this.frameQueue.then(() => this.handleFrame(A(t))).catch((
|
|
285
|
-
this.log("Relay frame handling failed",
|
|
284
|
+
this.frameQueue = this.frameQueue.then(() => this.handleFrame(A(t))).catch((n) => {
|
|
285
|
+
this.log("Relay frame handling failed", n instanceof Error ? n.message : String(n));
|
|
286
286
|
});
|
|
287
287
|
}
|
|
288
288
|
async handleFrame(t) {
|
|
@@ -291,26 +291,26 @@ class Z {
|
|
|
291
291
|
await this.handleOpenStream(
|
|
292
292
|
t.requestId,
|
|
293
293
|
t.streamId,
|
|
294
|
-
|
|
294
|
+
y(t.payload).port
|
|
295
295
|
);
|
|
296
296
|
break;
|
|
297
297
|
case s.StreamData: {
|
|
298
|
-
const
|
|
299
|
-
if (!
|
|
300
|
-
await G(
|
|
298
|
+
const n = this.streams.get(t.streamId);
|
|
299
|
+
if (!n) throw new Error(`Unknown stream ${t.streamId}`);
|
|
300
|
+
await G(n, t.payload);
|
|
301
301
|
break;
|
|
302
302
|
}
|
|
303
303
|
case s.StreamClose:
|
|
304
304
|
this.streams.delete(t.streamId);
|
|
305
305
|
break;
|
|
306
306
|
case s.InstallProgress:
|
|
307
|
-
this.log(te(
|
|
307
|
+
this.log(te(y(t.payload).message));
|
|
308
308
|
break;
|
|
309
309
|
case s.Error:
|
|
310
310
|
this.handleError(t.payload);
|
|
311
311
|
break;
|
|
312
312
|
case s.PairRecordReady:
|
|
313
|
-
this.handlePairRecordReady(
|
|
313
|
+
this.handlePairRecordReady(y(t.payload));
|
|
314
314
|
break;
|
|
315
315
|
case s.Ping:
|
|
316
316
|
await this.send({
|
|
@@ -323,29 +323,29 @@ class Z {
|
|
|
323
323
|
}
|
|
324
324
|
}
|
|
325
325
|
handleError(t) {
|
|
326
|
-
const
|
|
327
|
-
this.log("Server error",
|
|
326
|
+
const n = ee(t);
|
|
327
|
+
this.log("Server error", n), this.pairRecordWaiter && (this.pairRecordWaiter.reject(new Error(n)), this.pairRecordWaiter = void 0);
|
|
328
328
|
}
|
|
329
329
|
handlePairRecordReady(t) {
|
|
330
330
|
this.log("Pair record received", t.udid), this.pairRecordWaiter?.resolve(t), this.pairRecordWaiter = void 0;
|
|
331
331
|
}
|
|
332
|
-
async handleOpenStream(t,
|
|
332
|
+
async handleOpenStream(t, n, r) {
|
|
333
333
|
try {
|
|
334
|
-
const a = await J(this.session,
|
|
335
|
-
this.streams.set(
|
|
334
|
+
const a = await J(this.session, r);
|
|
335
|
+
this.streams.set(n, a), await this.send({
|
|
336
336
|
type: s.OpenResult,
|
|
337
337
|
requestId: t,
|
|
338
|
-
streamId:
|
|
338
|
+
streamId: n,
|
|
339
339
|
payload: l({ ok: !0 })
|
|
340
|
-
}), this.log(`Opened device stream ${
|
|
340
|
+
}), this.log(`Opened device stream ${n} to port ${r}`), this.pumpDeviceToServer(n, a);
|
|
341
341
|
} catch (a) {
|
|
342
342
|
this.log(
|
|
343
|
-
`Open device stream ${
|
|
343
|
+
`Open device stream ${n} failed`,
|
|
344
344
|
a instanceof Error ? a.message : String(a)
|
|
345
345
|
), await this.send({
|
|
346
346
|
type: s.OpenResult,
|
|
347
347
|
requestId: t,
|
|
348
|
-
streamId:
|
|
348
|
+
streamId: n,
|
|
349
349
|
payload: l({
|
|
350
350
|
ok: !1,
|
|
351
351
|
error: a instanceof Error ? a.message : String(a)
|
|
@@ -353,25 +353,25 @@ class Z {
|
|
|
353
353
|
});
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
|
-
async pumpDeviceToServer(t,
|
|
356
|
+
async pumpDeviceToServer(t, n) {
|
|
357
357
|
try {
|
|
358
358
|
for (; ; ) {
|
|
359
|
-
const
|
|
359
|
+
const r = await Q(n);
|
|
360
360
|
if (this.closed) return;
|
|
361
361
|
await this.send({
|
|
362
362
|
type: s.StreamData,
|
|
363
363
|
requestId: 0,
|
|
364
364
|
streamId: t,
|
|
365
|
-
payload:
|
|
365
|
+
payload: r
|
|
366
366
|
});
|
|
367
367
|
}
|
|
368
|
-
} catch (
|
|
369
|
-
this.log(`Device stream ${t} closed`,
|
|
368
|
+
} catch (r) {
|
|
369
|
+
this.log(`Device stream ${t} closed`, r instanceof Error ? r.message : String(r)), await this.send({
|
|
370
370
|
type: s.StreamClose,
|
|
371
371
|
requestId: 0,
|
|
372
372
|
streamId: t,
|
|
373
373
|
payload: l({
|
|
374
|
-
reason:
|
|
374
|
+
reason: r instanceof Error ? r.message : String(r)
|
|
375
375
|
})
|
|
376
376
|
});
|
|
377
377
|
}
|
|
@@ -389,8 +389,8 @@ class Z {
|
|
|
389
389
|
function ee(e) {
|
|
390
390
|
const t = new TextDecoder().decode(e);
|
|
391
391
|
try {
|
|
392
|
-
const
|
|
393
|
-
return S(
|
|
392
|
+
const n = JSON.parse(t);
|
|
393
|
+
return S(n.error ?? t);
|
|
394
394
|
} catch {
|
|
395
395
|
return S(t);
|
|
396
396
|
}
|
|
@@ -402,47 +402,47 @@ function te(e) {
|
|
|
402
402
|
const t = "install status: ";
|
|
403
403
|
if (!e.startsWith(t))
|
|
404
404
|
return e;
|
|
405
|
-
const
|
|
406
|
-
if (
|
|
407
|
-
const o = p(
|
|
408
|
-
return `Install error: ${
|
|
405
|
+
const n = e.slice(t.length), r = p(n, "Error");
|
|
406
|
+
if (r) {
|
|
407
|
+
const o = p(n, "ErrorDescription");
|
|
408
|
+
return `Install error: ${r}${o ? ` — ${o}` : ""}`;
|
|
409
409
|
}
|
|
410
|
-
const a = p(
|
|
410
|
+
const a = p(n, "Status") ?? "Unknown", i = p(n, "PercentComplete");
|
|
411
411
|
return `Install progress: ${i ? `${i}% ` : ""}${a}`;
|
|
412
412
|
}
|
|
413
413
|
function p(e, t) {
|
|
414
|
-
const
|
|
415
|
-
`<key>\\s*${
|
|
414
|
+
const r = new RegExp(
|
|
415
|
+
`<key>\\s*${ne(
|
|
416
416
|
t
|
|
417
417
|
)}\\s*</key>\\s*<(?:string|integer|real)>([\\s\\S]*?)</(?:string|integer|real)>`
|
|
418
418
|
).exec(e);
|
|
419
|
-
return
|
|
419
|
+
return r ? re(r[1].trim()) : void 0;
|
|
420
420
|
}
|
|
421
|
-
function
|
|
421
|
+
function ne(e) {
|
|
422
422
|
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
423
423
|
}
|
|
424
|
-
function
|
|
424
|
+
function re(e) {
|
|
425
425
|
return e.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&");
|
|
426
426
|
}
|
|
427
427
|
async function ae({ log: e }) {
|
|
428
428
|
e("Selecting USB device");
|
|
429
|
-
const t = await C(),
|
|
429
|
+
const t = await C(), n = ue(t);
|
|
430
430
|
return e(
|
|
431
431
|
"Selected USB device",
|
|
432
432
|
`${t.manufacturerName ?? ""} ${t.productName ?? ""} ${t.serialNumber ?? ""}`.trim()
|
|
433
|
-
),
|
|
433
|
+
), n;
|
|
434
434
|
}
|
|
435
435
|
async function ie({
|
|
436
436
|
registryApiUrl: e,
|
|
437
437
|
token: t,
|
|
438
|
-
organizationId:
|
|
439
|
-
log:
|
|
438
|
+
organizationId: n,
|
|
439
|
+
log: r,
|
|
440
440
|
target: a
|
|
441
441
|
}) {
|
|
442
|
-
const i = N(e, t,
|
|
442
|
+
const i = N(e, t, n);
|
|
443
443
|
let o;
|
|
444
444
|
try {
|
|
445
|
-
o = await $(i, a,
|
|
445
|
+
o = await $(i, a, r);
|
|
446
446
|
const c = await o.startPairing();
|
|
447
447
|
return { relay: o, pairRecord: c, target: a };
|
|
448
448
|
} catch (c) {
|
|
@@ -452,55 +452,55 @@ async function ie({
|
|
|
452
452
|
async function oe({
|
|
453
453
|
registryApiUrl: e,
|
|
454
454
|
token: t,
|
|
455
|
-
organizationId:
|
|
456
|
-
log:
|
|
455
|
+
organizationId: n,
|
|
456
|
+
log: r,
|
|
457
457
|
target: a,
|
|
458
458
|
pairRecord: i,
|
|
459
459
|
installSource: o
|
|
460
460
|
}) {
|
|
461
|
-
const c = N(e, t,
|
|
461
|
+
const c = N(e, t, n);
|
|
462
462
|
let u;
|
|
463
463
|
try {
|
|
464
|
-
return u = await $(c, a,
|
|
464
|
+
return u = await $(c, a, r), await u.startInstall(i, o), u;
|
|
465
465
|
} catch (D) {
|
|
466
466
|
throw u?.close(), D;
|
|
467
467
|
}
|
|
468
468
|
}
|
|
469
469
|
async function se(e, t) {
|
|
470
470
|
if (e) {
|
|
471
|
-
if (e.session && (
|
|
471
|
+
if (e.session && (P(e.session), e.session = void 0), e.claimedInterfaceNumber !== void 0)
|
|
472
472
|
try {
|
|
473
473
|
await e.device.releaseInterface(e.claimedInterfaceNumber), t?.("Released usbmux interface");
|
|
474
|
-
} catch (
|
|
475
|
-
t?.("USB interface release failed",
|
|
474
|
+
} catch (n) {
|
|
475
|
+
t?.("USB interface release failed", w(n));
|
|
476
476
|
} finally {
|
|
477
477
|
e.claimedInterfaceNumber = void 0;
|
|
478
478
|
}
|
|
479
479
|
if (e.device.opened)
|
|
480
480
|
try {
|
|
481
481
|
await e.device.close(), t?.("Closed USB device");
|
|
482
|
-
} catch (
|
|
483
|
-
t?.("USB device close failed",
|
|
482
|
+
} catch (n) {
|
|
483
|
+
t?.("USB device close failed", w(n));
|
|
484
484
|
}
|
|
485
485
|
}
|
|
486
486
|
}
|
|
487
|
-
async function $(e, t,
|
|
488
|
-
await ce(t,
|
|
489
|
-
const
|
|
490
|
-
return await
|
|
487
|
+
async function $(e, t, n) {
|
|
488
|
+
await ce(t, n);
|
|
489
|
+
const r = new Z(e, t.session, t.hello, n);
|
|
490
|
+
return await r.connect(), r;
|
|
491
491
|
}
|
|
492
492
|
async function ce(e, t) {
|
|
493
493
|
if (!e.session)
|
|
494
494
|
try {
|
|
495
495
|
e.candidate = await le(e, t), e.session = await H(e.device, e.candidate), t("Created usbmux session");
|
|
496
|
-
} catch (
|
|
497
|
-
throw await se(e, t),
|
|
496
|
+
} catch (n) {
|
|
497
|
+
throw await se(e, t), n;
|
|
498
498
|
}
|
|
499
499
|
}
|
|
500
500
|
function ue(e) {
|
|
501
501
|
return {
|
|
502
502
|
device: e,
|
|
503
|
-
candidate:
|
|
503
|
+
candidate: de(e),
|
|
504
504
|
hello: {
|
|
505
505
|
serialNumber: e.serialNumber,
|
|
506
506
|
productName: e.productName,
|
|
@@ -511,44 +511,47 @@ function ue(e) {
|
|
|
511
511
|
};
|
|
512
512
|
}
|
|
513
513
|
async function le(e, t) {
|
|
514
|
-
const
|
|
515
|
-
if (
|
|
516
|
-
let
|
|
517
|
-
for (const
|
|
518
|
-
for (const
|
|
514
|
+
const n = q(e.device);
|
|
515
|
+
if (n.length === 0) throw new Error("No Apple usbmux interface found.");
|
|
516
|
+
let r;
|
|
517
|
+
for (const i of n)
|
|
518
|
+
for (const o of [1, 2])
|
|
519
519
|
try {
|
|
520
520
|
return e.device.opened || await e.device.open(), t(
|
|
521
521
|
"Claiming usbmux interface",
|
|
522
|
-
`configuration ${
|
|
523
|
-
), await T(e.device,
|
|
522
|
+
`configuration ${i.configurationValue}, interface ${i.interfaceNumber}, alternate ${i.alternateSetting}, attempt ${o}`
|
|
523
|
+
), await T(e.device, i), e.claimedInterfaceNumber = i.interfaceNumber, t(
|
|
524
524
|
"Claimed usbmux interface",
|
|
525
|
-
`configuration ${
|
|
526
|
-
),
|
|
527
|
-
} catch (
|
|
528
|
-
|
|
525
|
+
`configuration ${i.configurationValue}, interface ${i.interfaceNumber}`
|
|
526
|
+
), i;
|
|
527
|
+
} catch (c) {
|
|
528
|
+
r = c, t(
|
|
529
529
|
"USB interface claim failed",
|
|
530
|
-
`configuration ${
|
|
531
|
-
), await
|
|
530
|
+
`configuration ${i.configurationValue}, interface ${i.interfaceNumber}: ${w(c)}`
|
|
531
|
+
), await fe(e), await pe(250);
|
|
532
532
|
}
|
|
533
|
-
|
|
533
|
+
const a = r ? ` (${w(r)})` : "";
|
|
534
|
+
throw new Error(
|
|
535
|
+
`Could not get exclusive USB access to the iPhone${a}. Another app on this computer is likely connected to it. Close other browser tabs that use this device, quit iPhone Mirroring, Xcode, eject iPhone in Finder windows showing the phone and try again.`
|
|
536
|
+
);
|
|
534
537
|
}
|
|
535
|
-
function
|
|
538
|
+
function de(e) {
|
|
536
539
|
const t = q(e)[0];
|
|
537
540
|
if (!t) throw new Error("No Apple usbmux interface found.");
|
|
538
541
|
return t;
|
|
539
542
|
}
|
|
540
543
|
function q(e) {
|
|
541
|
-
const t = L(e),
|
|
544
|
+
const t = L(e), n = e.configuration?.configurationValue;
|
|
542
545
|
return [
|
|
543
|
-
...t.filter((
|
|
544
|
-
...t.filter((
|
|
546
|
+
...t.filter((r) => r.configurationValue === n),
|
|
547
|
+
...t.filter((r) => r.configurationValue !== n)
|
|
545
548
|
];
|
|
546
549
|
}
|
|
547
|
-
function N(e, t,
|
|
548
|
-
const
|
|
549
|
-
return
|
|
550
|
+
function N(e, t, n) {
|
|
551
|
+
const r = new URL(e);
|
|
552
|
+
return r.protocol = r.protocol === "https:" ? "wss:" : "ws:", r.pathname = `${r.pathname.replace(/\/$/, "")}/ios/device/ws`, t && r.searchParams.set("token", t), n && r.searchParams.set("organization", n), r.toString();
|
|
550
553
|
}
|
|
551
|
-
async function
|
|
554
|
+
async function fe(e) {
|
|
552
555
|
if (e.claimedInterfaceNumber !== void 0) {
|
|
553
556
|
try {
|
|
554
557
|
await e.device.releaseInterface(e.claimedInterfaceNumber);
|