@onekeyfe/hd-transport 1.2.8-alpha.112 → 1.2.8-alpha.113
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-file-write-pipeline.test.js +417 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +42 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +186 -38
- package/dist/protocols/v2/session.d.ts +4 -1
- package/dist/protocols/v2/session.d.ts.map +1 -1
- package/dist/types/transport.d.ts +5 -1
- package/dist/types/transport.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/constants.ts +7 -0
- package/src/index.ts +1 -0
- package/src/protocols/v2/session.ts +300 -63
- package/src/types/transport.ts +19 -6
package/dist/index.js
CHANGED
|
@@ -276,6 +276,7 @@ const PROTOCOL_V2_BLE_FILE_CHUNK_SIZE = 1800;
|
|
|
276
276
|
const PROTOCOL_V2_BLE_FIRMWARE_FILE_CHUNK_SIZE = 1960;
|
|
277
277
|
const PROTOCOL_V2_BLE_FILE_READ_CHUNK_SIZE = 900;
|
|
278
278
|
const PROTOCOL_V2_BLE_FRAME_MAX_BYTES = 2048;
|
|
279
|
+
const PROTOCOL_V2_FILE_WRITE_PIPELINE_WINDOW = 2;
|
|
279
280
|
const PROTOCOL_V2_FILE_CHUNK_SIZE = PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE;
|
|
280
281
|
const PROTOCOL_V2_CHANNEL_USB = 0;
|
|
281
282
|
const PROTOCOL_V2_CHANNEL_BLE_UART = 1;
|
|
@@ -1107,6 +1108,23 @@ function withProtocolTimeout(promise, timeoutMs, createTimeoutError, onTimeout,
|
|
|
1107
1108
|
}
|
|
1108
1109
|
});
|
|
1109
1110
|
}
|
|
1111
|
+
function readFileWriteChunk(request) {
|
|
1112
|
+
var _a;
|
|
1113
|
+
const file = request.file;
|
|
1114
|
+
const offset = Number(file === null || file === void 0 ? void 0 : file.offset);
|
|
1115
|
+
const totalSize = Number(file === null || file === void 0 ? void 0 : file.total_size);
|
|
1116
|
+
const length = Number((_a = file === null || file === void 0 ? void 0 : file.data) === null || _a === void 0 ? void 0 : _a.byteLength);
|
|
1117
|
+
if (typeof (file === null || file === void 0 ? void 0 : file.path) !== 'string' ||
|
|
1118
|
+
!Number.isSafeInteger(offset) ||
|
|
1119
|
+
offset < 0 ||
|
|
1120
|
+
!Number.isSafeInteger(totalSize) ||
|
|
1121
|
+
!Number.isSafeInteger(length) ||
|
|
1122
|
+
length <= 0 ||
|
|
1123
|
+
offset + length > totalSize) {
|
|
1124
|
+
throw new Error('Protocol V2 file write pipeline chunk is invalid');
|
|
1125
|
+
}
|
|
1126
|
+
return { path: file.path, offset, end: offset + length, totalSize };
|
|
1127
|
+
}
|
|
1110
1128
|
class ProtocolV2Session {
|
|
1111
1129
|
constructor(options) {
|
|
1112
1130
|
var _a;
|
|
@@ -1150,6 +1168,9 @@ class ProtocolV2Session {
|
|
|
1150
1168
|
return result;
|
|
1151
1169
|
}
|
|
1152
1170
|
executeCall(name, data, callOptions) {
|
|
1171
|
+
if (callOptions.fileWritePipeline) {
|
|
1172
|
+
return this.executeFileWritePipeline(name, data, callOptions, callOptions.fileWritePipeline);
|
|
1173
|
+
}
|
|
1153
1174
|
const { schemas, router, packetSrc = PROTOCOL_V2_PACKET_SRC_COMMAND, maxFrameBytes, prepareCall, writeFrame, readFrame, logger, logPrefix = 'ProtocolV2', createTimeoutError, generation = 0, } = this.options;
|
|
1154
1175
|
const timeoutMs = callOptions.timeoutMs && callOptions.timeoutMs > 0
|
|
1155
1176
|
? callOptions.timeoutMs
|
|
@@ -1197,44 +1218,8 @@ class ProtocolV2Session {
|
|
|
1197
1218
|
const rxFrame = yield readFrame(baseCallContext);
|
|
1198
1219
|
if (abortController.signal.aborted)
|
|
1199
1220
|
break;
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
header = ProtocolV2.inspectFrameHeader(rxFrame);
|
|
1203
|
-
}
|
|
1204
|
-
catch (cause) {
|
|
1205
|
-
throw new ProtocolV2LinkError('frame', `Protocol V2 frame validation failed: ${getErrorMessage(cause)}`, cause);
|
|
1206
|
-
}
|
|
1207
|
-
if (header.router !== router) {
|
|
1208
|
-
throw new ProtocolV2LinkError('router', `Protocol V2 router mismatch: expected ${router}, got ${header.router}`);
|
|
1209
|
-
}
|
|
1210
|
-
if (header.packetSrc !== packetSrc) {
|
|
1211
|
-
throw new ProtocolV2LinkError('packet-source', `Protocol V2 packet source mismatch: expected ${packetSrc}, got ${header.packetSrc}`);
|
|
1212
|
-
}
|
|
1213
|
-
let isAck;
|
|
1214
|
-
try {
|
|
1215
|
-
isAck = ProtocolV2.isAckFrame(rxFrame);
|
|
1216
|
-
}
|
|
1217
|
-
catch (cause) {
|
|
1218
|
-
throw new ProtocolV2LinkError('frame', `Protocol V2 ACK validation failed: ${getErrorMessage(cause)}`, cause);
|
|
1219
|
-
}
|
|
1220
|
-
if (isAck) {
|
|
1221
|
-
if (header.seq !== protoSeq) {
|
|
1222
|
-
throw new ProtocolV2LinkError('ack-sequence', `Protocol V2 ACK sequence mismatch: expected ${protoSeq}, got ${header.seq}`);
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
else {
|
|
1226
|
-
let decoded;
|
|
1227
|
-
try {
|
|
1228
|
-
decoded = ProtocolV2.decodeFrame(schemas, rxFrame);
|
|
1229
|
-
}
|
|
1230
|
-
catch (cause) {
|
|
1231
|
-
throw new ProtocolV2LinkError('frame', `Protocol V2 frame decode failed: ${getErrorMessage(cause)}`, cause);
|
|
1232
|
-
}
|
|
1233
|
-
if (this.lastResponseSequence === decoded.seq) {
|
|
1234
|
-
throw new ProtocolV2LinkError('response-sequence', `Protocol V2 duplicate response sequence: ${decoded.seq}`);
|
|
1235
|
-
}
|
|
1236
|
-
this.lastResponseSequence = decoded.seq;
|
|
1237
|
-
const response = call(decoded);
|
|
1221
|
+
const response = this.parseResponseFrame(rxFrame, [protoSeq]);
|
|
1222
|
+
if (response) {
|
|
1238
1223
|
const { pendingResponseAfterWrite } = this;
|
|
1239
1224
|
let belongsToWriteOnlyCall = false;
|
|
1240
1225
|
if (pendingResponseAfterWrite) {
|
|
@@ -1271,6 +1256,168 @@ class ProtocolV2Session {
|
|
|
1271
1256
|
abortController.abort();
|
|
1272
1257
|
});
|
|
1273
1258
|
}
|
|
1259
|
+
parseResponseFrame(rxFrame, ackSequences) {
|
|
1260
|
+
const { schemas, router, packetSrc = PROTOCOL_V2_PACKET_SRC_COMMAND } = this.options;
|
|
1261
|
+
let header;
|
|
1262
|
+
try {
|
|
1263
|
+
header = ProtocolV2.inspectFrameHeader(rxFrame);
|
|
1264
|
+
}
|
|
1265
|
+
catch (cause) {
|
|
1266
|
+
throw new ProtocolV2LinkError('frame', `Protocol V2 frame validation failed: ${getErrorMessage(cause)}`, cause);
|
|
1267
|
+
}
|
|
1268
|
+
if (header.router !== router) {
|
|
1269
|
+
throw new ProtocolV2LinkError('router', `Protocol V2 router mismatch: expected ${router}, got ${header.router}`);
|
|
1270
|
+
}
|
|
1271
|
+
if (header.packetSrc !== packetSrc) {
|
|
1272
|
+
throw new ProtocolV2LinkError('packet-source', `Protocol V2 packet source mismatch: expected ${packetSrc}, got ${header.packetSrc}`);
|
|
1273
|
+
}
|
|
1274
|
+
let isAck;
|
|
1275
|
+
try {
|
|
1276
|
+
isAck = ProtocolV2.isAckFrame(rxFrame);
|
|
1277
|
+
}
|
|
1278
|
+
catch (cause) {
|
|
1279
|
+
throw new ProtocolV2LinkError('frame', `Protocol V2 ACK validation failed: ${getErrorMessage(cause)}`, cause);
|
|
1280
|
+
}
|
|
1281
|
+
if (isAck) {
|
|
1282
|
+
if (!ackSequences.includes(header.seq)) {
|
|
1283
|
+
throw new ProtocolV2LinkError('ack-sequence', `Protocol V2 ACK sequence mismatch: expected ${ackSequences.join('|')}, got ${header.seq}`);
|
|
1284
|
+
}
|
|
1285
|
+
return undefined;
|
|
1286
|
+
}
|
|
1287
|
+
let decoded;
|
|
1288
|
+
try {
|
|
1289
|
+
decoded = ProtocolV2.decodeFrame(schemas, rxFrame);
|
|
1290
|
+
}
|
|
1291
|
+
catch (cause) {
|
|
1292
|
+
throw new ProtocolV2LinkError('frame', `Protocol V2 frame decode failed: ${getErrorMessage(cause)}`, cause);
|
|
1293
|
+
}
|
|
1294
|
+
if (this.lastResponseSequence === decoded.seq) {
|
|
1295
|
+
throw new ProtocolV2LinkError('response-sequence', `Protocol V2 duplicate response sequence: ${decoded.seq}`);
|
|
1296
|
+
}
|
|
1297
|
+
this.lastResponseSequence = decoded.seq;
|
|
1298
|
+
return call(decoded);
|
|
1299
|
+
}
|
|
1300
|
+
executeFileWritePipeline(name, data, callOptions, pipeline) {
|
|
1301
|
+
var _a;
|
|
1302
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1303
|
+
if (name !== 'FilesystemFileWrite') {
|
|
1304
|
+
throw new Error(`Protocol V2 file write pipeline does not support ${name}`);
|
|
1305
|
+
}
|
|
1306
|
+
if (this.pendingResponseAfterWrite) {
|
|
1307
|
+
throw new Error('Protocol V2 file write pipeline cannot start while a response is pending');
|
|
1308
|
+
}
|
|
1309
|
+
const { schemas, router, packetSrc = PROTOCOL_V2_PACKET_SRC_COMMAND, maxFrameBytes, prepareCall, writeFrame, readFrame, logger, logPrefix = 'ProtocolV2', createTimeoutError, generation = 0, } = this.options;
|
|
1310
|
+
const timeoutMs = callOptions.timeoutMs && callOptions.timeoutMs > 0
|
|
1311
|
+
? callOptions.timeoutMs
|
|
1312
|
+
: PROTOCOL_V2_DEFAULT_RESPONSE_TIMEOUT_MS;
|
|
1313
|
+
const abortController = new AbortController();
|
|
1314
|
+
const context = Object.assign(Object.assign({ messageName: name, timeoutMs, highThroughput: true }, (callOptions.writeWithResponse === undefined
|
|
1315
|
+
? {}
|
|
1316
|
+
: { writeWithResponse: callOptions.writeWithResponse })), { generation, signal: abortController.signal });
|
|
1317
|
+
const withStepTimeout = (promise, stepTimeoutMs = timeoutMs) => withProtocolTimeout(promise, stepTimeoutMs, () => createTimeoutError
|
|
1318
|
+
? createTimeoutError(name, timeoutMs)
|
|
1319
|
+
: new Error(`Protocol V2 response timeout after ${timeoutMs}ms for ${name}`), () => {
|
|
1320
|
+
abortController.abort();
|
|
1321
|
+
});
|
|
1322
|
+
let progressDeadline = 0;
|
|
1323
|
+
const markProgress = () => {
|
|
1324
|
+
progressDeadline = Date.now() + timeoutMs;
|
|
1325
|
+
};
|
|
1326
|
+
const inFlight = [];
|
|
1327
|
+
let firstRequest = data;
|
|
1328
|
+
let path;
|
|
1329
|
+
let totalSize;
|
|
1330
|
+
let nextOffset;
|
|
1331
|
+
let sourceDone = false;
|
|
1332
|
+
let failure;
|
|
1333
|
+
let lastConfirmed;
|
|
1334
|
+
const sendNextChunk = () => __awaiter(this, void 0, void 0, function* () {
|
|
1335
|
+
var _b, _c;
|
|
1336
|
+
const request = firstRequest !== null && firstRequest !== void 0 ? firstRequest : (yield pipeline.next());
|
|
1337
|
+
firstRequest = undefined;
|
|
1338
|
+
if (!request) {
|
|
1339
|
+
sourceDone = true;
|
|
1340
|
+
return;
|
|
1341
|
+
}
|
|
1342
|
+
const chunk = readFileWriteChunk(request);
|
|
1343
|
+
if ((path !== undefined && chunk.path !== path) ||
|
|
1344
|
+
(totalSize !== undefined && chunk.totalSize !== totalSize) ||
|
|
1345
|
+
(nextOffset !== undefined && chunk.offset !== nextOffset)) {
|
|
1346
|
+
throw new Error(`Protocol V2 file write pipeline chunk out of order: expected offset ${String(nextOffset)}, got ${chunk.offset}`);
|
|
1347
|
+
}
|
|
1348
|
+
path = chunk.path;
|
|
1349
|
+
totalSize = chunk.totalSize;
|
|
1350
|
+
nextOffset = chunk.end;
|
|
1351
|
+
const seq = this.sequenceCursor.next();
|
|
1352
|
+
const frame = ProtocolV2.encodeFrame(schemas, name, request, {
|
|
1353
|
+
packetSrc,
|
|
1354
|
+
router,
|
|
1355
|
+
seq,
|
|
1356
|
+
});
|
|
1357
|
+
if (maxFrameBytes !== undefined && frame.length > maxFrameBytes) {
|
|
1358
|
+
throw new Error(`Protocol V2 frame too large for transport: ${frame.length} > ${maxFrameBytes}`);
|
|
1359
|
+
}
|
|
1360
|
+
const writeStartedAt = Date.now();
|
|
1361
|
+
yield withStepTimeout(this.serializeWrite(() => writeFrame(frame, context)));
|
|
1362
|
+
inFlight.push({ seq, path: chunk.path, offset: chunk.offset, end: chunk.end });
|
|
1363
|
+
markProgress();
|
|
1364
|
+
try {
|
|
1365
|
+
(_b = callOptions.onWriteCompleted) === null || _b === void 0 ? void 0 : _b.call(callOptions, {
|
|
1366
|
+
elapsedMs: Math.max(Date.now() - writeStartedAt, 0),
|
|
1367
|
+
frameBytes: frame.byteLength,
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
catch (error) {
|
|
1371
|
+
(_c = logger === null || logger === void 0 ? void 0 : logger.error) === null || _c === void 0 ? void 0 : _c.call(logger, `${logPrefix} write metrics callback failed: ${String(error)}`);
|
|
1372
|
+
}
|
|
1373
|
+
});
|
|
1374
|
+
yield withStepTimeout(Promise.resolve().then(() => prepareCall === null || prepareCall === void 0 ? void 0 : prepareCall(context)));
|
|
1375
|
+
while (!sourceDone && inFlight.length < PROTOCOL_V2_FILE_WRITE_PIPELINE_WINDOW) {
|
|
1376
|
+
yield sendNextChunk();
|
|
1377
|
+
}
|
|
1378
|
+
while (inFlight.length > 0) {
|
|
1379
|
+
const rxFrame = yield withStepTimeout(readFrame(context), Math.max(progressDeadline - Date.now(), 1));
|
|
1380
|
+
const response = this.parseResponseFrame(rxFrame, inFlight.map(item => item.seq));
|
|
1381
|
+
if (!response) ;
|
|
1382
|
+
else if (response.type === 'FilesystemFile') {
|
|
1383
|
+
const [expected] = inFlight;
|
|
1384
|
+
const { message } = response;
|
|
1385
|
+
if (Number(message.processed_byte) !== expected.end ||
|
|
1386
|
+
message.path !== expected.path ||
|
|
1387
|
+
Number(message.offset) !== expected.offset ||
|
|
1388
|
+
Number(message.total_size) !== totalSize) {
|
|
1389
|
+
throw new ProtocolV2LinkError('frame', `Protocol V2 file write response does not match chunk ${expected.offset}-${expected.end}: got offset ${String(message.offset)} processed_byte ${String(message.processed_byte)}`);
|
|
1390
|
+
}
|
|
1391
|
+
inFlight.shift();
|
|
1392
|
+
markProgress();
|
|
1393
|
+
if (!failure) {
|
|
1394
|
+
lastConfirmed = response;
|
|
1395
|
+
pipeline.onResponse(response);
|
|
1396
|
+
if (!sourceDone) {
|
|
1397
|
+
yield sendNextChunk();
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
else if (response.type === 'Failure') {
|
|
1402
|
+
inFlight.shift();
|
|
1403
|
+
markProgress();
|
|
1404
|
+
failure = failure !== null && failure !== void 0 ? failure : response;
|
|
1405
|
+
sourceDone = true;
|
|
1406
|
+
}
|
|
1407
|
+
else if (COMMON_TERMINAL_RESPONSE_TYPES.has(response.type)) {
|
|
1408
|
+
throw new ProtocolV2LinkError('frame', `Protocol V2 file write pipeline received unexpected ${response.type}`);
|
|
1409
|
+
}
|
|
1410
|
+
else {
|
|
1411
|
+
(_a = logger === null || logger === void 0 ? void 0 : logger.debug) === null || _a === void 0 ? void 0 : _a.call(logger, `[${logPrefix}] skip unexpected response for ${name}: expected=FilesystemFile got=${response.type}`);
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
const terminal = failure !== null && failure !== void 0 ? failure : lastConfirmed;
|
|
1415
|
+
if (!terminal) {
|
|
1416
|
+
throw new ProtocolV2LinkError('frame', 'Protocol V2 file write pipeline ended unconfirmed');
|
|
1417
|
+
}
|
|
1418
|
+
return terminal;
|
|
1419
|
+
});
|
|
1420
|
+
}
|
|
1274
1421
|
}
|
|
1275
1422
|
function probeProtocolV2({ call, timeoutMs, logger, logPrefix = 'ProtocolV2', onBeforeProbe, onProbeFailed, shouldRethrow, }) {
|
|
1276
1423
|
var _a, _b, _c;
|
|
@@ -2555,6 +2702,7 @@ exports.PROTOCOL_V2_CHANNEL_SOCKET = PROTOCOL_V2_CHANNEL_SOCKET;
|
|
|
2555
2702
|
exports.PROTOCOL_V2_CHANNEL_USB = PROTOCOL_V2_CHANNEL_USB;
|
|
2556
2703
|
exports.PROTOCOL_V2_DEFAULT_RESPONSE_TIMEOUT_MS = PROTOCOL_V2_DEFAULT_RESPONSE_TIMEOUT_MS;
|
|
2557
2704
|
exports.PROTOCOL_V2_FILE_CHUNK_SIZE = PROTOCOL_V2_FILE_CHUNK_SIZE;
|
|
2705
|
+
exports.PROTOCOL_V2_FILE_WRITE_PIPELINE_WINDOW = PROTOCOL_V2_FILE_WRITE_PIPELINE_WINDOW;
|
|
2558
2706
|
exports.PROTOCOL_V2_FRAME_MAX_BYTES = PROTOCOL_V2_FRAME_MAX_BYTES;
|
|
2559
2707
|
exports.PROTOCOL_V2_PACKET_SRC_COMMAND = PROTOCOL_V2_PACKET_SRC_COMMAND;
|
|
2560
2708
|
exports.PROTOCOL_V2_SYS_MESSAGE_THRESHOLD = PROTOCOL_V2_SYS_MESSAGE_THRESHOLD;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ProtocolV2FrameAssembler, concatUint8Arrays } from './frame-assembler';
|
|
2
2
|
import { ProtocolV2SequenceCursor } from './sequence-cursor';
|
|
3
3
|
import type { Root } from 'protobufjs/light';
|
|
4
|
-
import type { MessageFromOneKey, TransportWriteMetrics } from '../../types';
|
|
4
|
+
import type { MessageFromOneKey, ProtocolV2FileWritePipeline, TransportWriteMetrics } from '../../types';
|
|
5
5
|
export * from './errors';
|
|
6
6
|
export type ProtocolV2Schemas = {
|
|
7
7
|
protocolV1: Root;
|
|
@@ -42,6 +42,7 @@ export type ProtocolV2CallOptions = {
|
|
|
42
42
|
returnAfterWrite?: boolean;
|
|
43
43
|
onResponseAfterWrite?: (response: MessageFromOneKey) => void;
|
|
44
44
|
writeWithResponse?: boolean;
|
|
45
|
+
fileWritePipeline?: ProtocolV2FileWritePipeline;
|
|
45
46
|
};
|
|
46
47
|
export { concatUint8Arrays, ProtocolV2FrameAssembler };
|
|
47
48
|
export { ProtocolV2SequenceCursor };
|
|
@@ -67,6 +68,8 @@ export declare class ProtocolV2Session {
|
|
|
67
68
|
sendFlowControl(name: string, data: Record<string, unknown>): Promise<MessageFromOneKey>;
|
|
68
69
|
private serializeWrite;
|
|
69
70
|
private executeCall;
|
|
71
|
+
private parseResponseFrame;
|
|
72
|
+
private executeFileWritePipeline;
|
|
70
73
|
}
|
|
71
74
|
export declare function probeProtocolV2({ call, timeoutMs, logger, logPrefix, onBeforeProbe, onProbeFailed, shouldRethrow, }: {
|
|
72
75
|
call: (name: string, data: Record<string, unknown>, options?: ProtocolV2CallOptions) => Promise<MessageFromOneKey>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/protocols/v2/session.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/protocols/v2/session.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAW7D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EACV,iBAAiB,EACjB,2BAA2B,EAC3B,qBAAqB,EACtB,MAAM,aAAa,CAAC;AAErB,cAAc,UAAU,CAAC;AAEzB,MAAM,MAAM,iBAAiB,GAAG;IAC9B,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,OAAO,CAAC;IACxB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,UA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ColorCode?: string;
|
|
27
26
|
};
|
|
28
27
|
export type OneKeyDeviceInfoBase = {
|
|
29
28
|
commType: OneKeyDeviceCommType;
|
|
@@ -49,6 +48,10 @@ export type TransportWriteMetrics = {
|
|
|
49
48
|
elapsedMs: number;
|
|
50
49
|
frameBytes: number;
|
|
51
50
|
};
|
|
51
|
+
export type ProtocolV2FileWritePipeline = {
|
|
52
|
+
next: () => Promise<Record<string, unknown> | undefined>;
|
|
53
|
+
onResponse: (response: MessageFromOneKey) => void;
|
|
54
|
+
};
|
|
52
55
|
export type TransportCallOptions = {
|
|
53
56
|
timeoutMs?: number;
|
|
54
57
|
expectedTypes?: string[];
|
|
@@ -58,6 +61,7 @@ export type TransportCallOptions = {
|
|
|
58
61
|
returnAfterWrite?: boolean;
|
|
59
62
|
onResponseAfterWrite?: (response: MessageFromOneKey) => void;
|
|
60
63
|
writeWithResponse?: boolean;
|
|
64
|
+
fileWritePipeline?: ProtocolV2FileWritePipeline;
|
|
61
65
|
};
|
|
62
66
|
type ITransportInitFn = (logger?: any, emitter?: EventEmitter, plugin?: LowlevelTransportSharedPlugin) => Promise<string>;
|
|
63
67
|
export type Transport = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/types/transport.ts"],"names":[],"mappings":";;;AAAA,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AAEvC,eAAO,MAAM,eAAe;;CAElB,CAAC;AAEX,MAAM,MAAM,8BAA8B,GAAG;IAC3C,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,IAAI,CAAC;AAEvC,MAAM,MAAM,oBAAoB,GAC5B,KAAK,GACL,QAAQ,GACR,KAAK,GACL,QAAQ,GACR,cAAc,GACd,QAAQ,GACR,UAAU,CAAC;AAEf,MAAM,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;IAC5C,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5C,2BAA2B,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAEjG,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport",
|
|
3
|
-
"version": "1.2.8-alpha.
|
|
3
|
+
"version": "1.2.8-alpha.113",
|
|
4
4
|
"description": "Transport layer abstractions and utilities for OneKey hardware SDK.",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"long": "^4.0.0",
|
|
29
29
|
"protobufjs": "^6.11.2"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "c56caf8fdd87e3a00bdc90aca044e75693704ae3"
|
|
32
32
|
}
|
package/src/constants.ts
CHANGED
|
@@ -41,6 +41,13 @@ export const PROTOCOL_V2_BLE_FILE_READ_CHUNK_SIZE = 900;
|
|
|
41
41
|
/** Pro2 BLE/UART RX FIFO must hold a complete Proto Link frame. */
|
|
42
42
|
export const PROTOCOL_V2_BLE_FRAME_MAX_BYTES = 2048;
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* FilesystemFileWrite frames kept in flight by a file write pipeline. The main MCU copies a
|
|
46
|
+
* complete frame out of its UART FIFO before handling it, but a frame waiting to be parsed and
|
|
47
|
+
* the next one being received can both be resident: two full frames must fit (4096-byte FIFO).
|
|
48
|
+
*/
|
|
49
|
+
export const PROTOCOL_V2_FILE_WRITE_PIPELINE_WINDOW = 2;
|
|
50
|
+
|
|
44
51
|
/** @deprecated Use the transport-specific WebUSB or BLE file chunk constant. */
|
|
45
52
|
export const PROTOCOL_V2_FILE_CHUNK_SIZE = PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE;
|
|
46
53
|
|