@onekeyfe/hd-transport 1.2.0-alpha.20 → 1.2.0-alpha.21
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/__tests__/protocol-v2-link-manager.test.js +0 -25
- package/__tests__/protocol-v2.test.js +41 -53
- package/dist/index.d.ts +2 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -55
- package/dist/protocols/index.d.ts +1 -2
- package/dist/protocols/index.d.ts.map +1 -1
- package/dist/protocols/v2/decode.d.ts +0 -1
- package/dist/protocols/v2/decode.d.ts.map +1 -1
- package/dist/protocols/v2/link-manager.d.ts +0 -1
- package/dist/protocols/v2/link-manager.d.ts.map +1 -1
- package/dist/protocols/v2/session.d.ts +0 -4
- package/dist/protocols/v2/session.d.ts.map +1 -1
- package/dist/types/messages.d.ts +1 -1
- package/dist/types/messages.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/protocols/index.ts +13 -8
- package/src/protocols/v2/decode.ts +0 -7
- package/src/protocols/v2/link-manager.ts +0 -2
- package/src/protocols/v2/session.ts +4 -59
- package/src/types/messages.ts +1 -1
|
@@ -61,13 +61,6 @@ export function isAckFrame(data: Uint8Array): boolean {
|
|
|
61
61
|
return true;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
export function getAckSequence(data: Uint8Array): number | undefined {
|
|
65
|
-
if (!isAckFrame(data)) {
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
return data[6];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
64
|
/**
|
|
72
65
|
* Parse and validate a Protocol V2 response frame.
|
|
73
66
|
*
|
|
@@ -17,7 +17,6 @@ export interface ProtocolV2LinkAdapter {
|
|
|
17
17
|
logger?: ProtocolV2SessionOptions['logger'];
|
|
18
18
|
logPrefix?: string;
|
|
19
19
|
createTimeoutError?: ProtocolV2SessionOptions['createTimeoutError'];
|
|
20
|
-
writeTimeoutMs?: number;
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
export type ProtocolV2LinkManagerOptions<Key> = {
|
|
@@ -129,7 +128,6 @@ export class ProtocolV2LinkManager<Key> {
|
|
|
129
128
|
logger: adapter.logger,
|
|
130
129
|
logPrefix: adapter.logPrefix,
|
|
131
130
|
createTimeoutError: adapter.createTimeoutError,
|
|
132
|
-
writeTimeoutMs: adapter.writeTimeoutMs,
|
|
133
131
|
});
|
|
134
132
|
const link = { adapter, session, state };
|
|
135
133
|
this.links.set(key, link);
|
|
@@ -38,8 +38,6 @@ export type ProtocolV2SessionOptions = {
|
|
|
38
38
|
createTimeoutError?: (name: string, timeoutMs: number) => Error;
|
|
39
39
|
sequenceCursor?: ProtocolV2SequenceCursor;
|
|
40
40
|
generation?: number;
|
|
41
|
-
writeTimeoutMs?: number;
|
|
42
|
-
deliveryTimeoutMs?: number;
|
|
43
41
|
};
|
|
44
42
|
|
|
45
43
|
export type ProtocolV2CallOptions = {
|
|
@@ -138,12 +136,6 @@ export async function withProtocolTimeout<T>(
|
|
|
138
136
|
}
|
|
139
137
|
}
|
|
140
138
|
|
|
141
|
-
// A transport write must never keep the serialized device queue pending forever.
|
|
142
|
-
// Callers must classify a timeout as link-fatal and reset the physical adapter so
|
|
143
|
-
// the losing Promise cannot continue on the next connection generation.
|
|
144
|
-
export const PROTOCOL_V2_WRITE_WATCHDOG_TIMEOUT_MS = 30_000;
|
|
145
|
-
export const PROTOCOL_V2_DELIVERY_WATCHDOG_TIMEOUT_MS = 5_000;
|
|
146
|
-
|
|
147
139
|
export class ProtocolV2Session {
|
|
148
140
|
private readonly options: ProtocolV2SessionOptions;
|
|
149
141
|
|
|
@@ -188,8 +180,6 @@ export class ProtocolV2Session {
|
|
|
188
180
|
logPrefix = 'ProtocolV2',
|
|
189
181
|
createTimeoutError,
|
|
190
182
|
generation = 0,
|
|
191
|
-
writeTimeoutMs = PROTOCOL_V2_WRITE_WATCHDOG_TIMEOUT_MS,
|
|
192
|
-
deliveryTimeoutMs = PROTOCOL_V2_DELIVERY_WATCHDOG_TIMEOUT_MS,
|
|
193
183
|
} = this.options;
|
|
194
184
|
|
|
195
185
|
const shouldReduceDebug = shouldReduceProtocolV2Debug(name);
|
|
@@ -227,26 +217,13 @@ export class ProtocolV2Session {
|
|
|
227
217
|
);
|
|
228
218
|
}
|
|
229
219
|
|
|
230
|
-
await
|
|
231
|
-
writeFrame(frame, callContext),
|
|
232
|
-
writeTimeoutMs,
|
|
233
|
-
() => new Error(`Protocol V2 write timeout after ${writeTimeoutMs}ms for ${name}`)
|
|
234
|
-
);
|
|
220
|
+
await writeFrame(frame, callContext);
|
|
235
221
|
|
|
236
222
|
// Cancellation flag for the read loop: when the response timeout fires,
|
|
237
223
|
// Promise.race alone would leave this loop running as a zombie that keeps
|
|
238
224
|
// consuming frames meant for the next call. The timeout callback flips the
|
|
239
225
|
// flag so the loop exits and discards any late frame.
|
|
240
226
|
const cancellation = { cancelled: false };
|
|
241
|
-
let resolveDelivery: () => void = () => undefined;
|
|
242
|
-
let deliveryConfirmed = false;
|
|
243
|
-
const deliveryPromise = new Promise<void>(resolve => {
|
|
244
|
-
resolveDelivery = () => {
|
|
245
|
-
if (deliveryConfirmed) return;
|
|
246
|
-
deliveryConfirmed = true;
|
|
247
|
-
resolve();
|
|
248
|
-
};
|
|
249
|
-
});
|
|
250
227
|
|
|
251
228
|
const readResponse = async (): Promise<MessageFromOneKey> => {
|
|
252
229
|
// Some Protocol V2 operations emit progress notifications before the
|
|
@@ -258,15 +235,8 @@ export class ProtocolV2Session {
|
|
|
258
235
|
// Timed out while waiting: drop the late frame and stop reading.
|
|
259
236
|
break;
|
|
260
237
|
}
|
|
261
|
-
const
|
|
262
|
-
if (
|
|
263
|
-
if (ackSequence === protoSeq) {
|
|
264
|
-
resolveDelivery();
|
|
265
|
-
}
|
|
266
|
-
} else {
|
|
267
|
-
// Some firmware versions return the protobuf response without a separate
|
|
268
|
-
// ACK. Receiving any valid response frame proves that the request arrived.
|
|
269
|
-
resolveDelivery();
|
|
238
|
+
const isAck = ProtocolV2.isAckFrame(rxFrame);
|
|
239
|
+
if (!isAck) {
|
|
270
240
|
// Suppress Protocol V2 RX frame logs to avoid excessive transport diagnostics.
|
|
271
241
|
/*
|
|
272
242
|
const rxMetadata = ProtocolV2.inspectFrame(schemas, rxFrame);
|
|
@@ -303,7 +273,7 @@ export class ProtocolV2Session {
|
|
|
303
273
|
throw new Error(`Protocol V2 read loop cancelled after timeout for ${name}`);
|
|
304
274
|
};
|
|
305
275
|
|
|
306
|
-
|
|
276
|
+
return withProtocolTimeout(
|
|
307
277
|
readResponse(),
|
|
308
278
|
callOptions.timeoutMs,
|
|
309
279
|
() =>
|
|
@@ -314,31 +284,6 @@ export class ProtocolV2Session {
|
|
|
314
284
|
cancellation.cancelled = true;
|
|
315
285
|
}
|
|
316
286
|
);
|
|
317
|
-
const deliverySignal = Promise.race([deliveryPromise, responsePromise.then(() => undefined)]);
|
|
318
|
-
const deliveryWatchdog = withProtocolTimeout(
|
|
319
|
-
deliverySignal,
|
|
320
|
-
deliveryTimeoutMs,
|
|
321
|
-
() => new Error(`Protocol V2 delivery timeout after ${deliveryTimeoutMs}ms for ${name}`),
|
|
322
|
-
() => {
|
|
323
|
-
cancellation.cancelled = true;
|
|
324
|
-
}
|
|
325
|
-
);
|
|
326
|
-
|
|
327
|
-
try {
|
|
328
|
-
const firstResult = await Promise.race([
|
|
329
|
-
deliveryWatchdog.then(() => ({ kind: 'delivered' as const })),
|
|
330
|
-
responsePromise.then(response => ({ kind: 'response' as const, response })),
|
|
331
|
-
]);
|
|
332
|
-
if (firstResult.kind === 'response') {
|
|
333
|
-
return firstResult.response;
|
|
334
|
-
}
|
|
335
|
-
return await responsePromise;
|
|
336
|
-
} catch (error) {
|
|
337
|
-
cancellation.cancelled = true;
|
|
338
|
-
deliveryWatchdog.catch(() => undefined);
|
|
339
|
-
responsePromise.catch(() => undefined);
|
|
340
|
-
throw error;
|
|
341
|
-
}
|
|
342
287
|
}
|
|
343
288
|
}
|
|
344
289
|
|
package/src/types/messages.ts
CHANGED
|
@@ -2359,7 +2359,7 @@ export enum Enum_SafetyCheckLevel {
|
|
|
2359
2359
|
PromptAlways = 1,
|
|
2360
2360
|
PromptTemporarily = 2,
|
|
2361
2361
|
}
|
|
2362
|
-
export type SafetyCheckLevel = keyof typeof Enum_SafetyCheckLevel;
|
|
2362
|
+
export type SafetyCheckLevel = keyof typeof Enum_SafetyCheckLevel | Enum_SafetyCheckLevel;
|
|
2363
2363
|
|
|
2364
2364
|
// Initialize
|
|
2365
2365
|
export type Initialize = {
|