@onekeyfe/hd-transport 1.2.0-alpha.3 → 1.2.0-alpha.4
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/README.md +1 -1
- package/__tests__/protocol-v2.test.js +104 -77
- package/dist/constants.d.ts +2 -2
- package/dist/index.d.ts +329 -232
- package/dist/index.js +63 -43
- package/dist/protocols/v2/session.d.ts +1 -1
- package/dist/protocols/v2/session.d.ts.map +1 -1
- package/dist/types/messages.d.ts +235 -157
- package/dist/types/messages.d.ts.map +1 -1
- package/messages-protocol-v2.json +486 -1072
- package/package.json +2 -2
- package/scripts/protobuf-build.sh +51 -143
- package/src/constants.ts +2 -2
- package/src/protocols/v2/session.ts +4 -5
- package/src/types/messages.ts +291 -193
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ In order to be able to use new features of onekey-firmware you need to update pr
|
|
|
20
20
|
1. `yarn update-submodules` to update firmware submodule
|
|
21
21
|
1. `yarn update-protobuf` to generate new `./messages.json`, `./messages-protocol-v2.json` and `./src/types/messages.ts`
|
|
22
22
|
|
|
23
|
-
The same task can be run from the repository root with `yarn update-protobuf`. The Protocol V2 schema requires the `firmware-pro2` submodule checked out on branch `
|
|
23
|
+
The same task can be run from the repository root with `yarn update-protobuf`. The Protocol V2 schema requires the `firmware-pro2` submodule checked out on branch `dev`.
|
|
24
24
|
|
|
25
25
|
## Docs
|
|
26
26
|
|
|
@@ -55,21 +55,22 @@ const protocolV1Messages = parseConfigure({
|
|
|
55
55
|
|
|
56
56
|
const protocolV2Messages = parseConfigure({
|
|
57
57
|
nested: {
|
|
58
|
-
|
|
58
|
+
ProtocolInfoRequest: {
|
|
59
59
|
fields: {},
|
|
60
60
|
},
|
|
61
|
-
|
|
61
|
+
ProtocolInfo: {
|
|
62
62
|
fields: {
|
|
63
|
-
|
|
63
|
+
version: {
|
|
64
64
|
type: 'uint32',
|
|
65
65
|
id: 1,
|
|
66
66
|
},
|
|
67
|
-
|
|
67
|
+
supported_messages: {
|
|
68
68
|
type: 'uint32',
|
|
69
69
|
id: 2,
|
|
70
|
+
rule: 'repeated',
|
|
70
71
|
},
|
|
71
|
-
|
|
72
|
-
type: '
|
|
72
|
+
protobuf_definition: {
|
|
73
|
+
type: 'string',
|
|
73
74
|
id: 3,
|
|
74
75
|
},
|
|
75
76
|
},
|
|
@@ -90,18 +91,53 @@ const protocolV2Messages = parseConfigure({
|
|
|
90
91
|
},
|
|
91
92
|
},
|
|
92
93
|
},
|
|
93
|
-
|
|
94
|
-
fields: {
|
|
94
|
+
DeviceFirmwareTarget: {
|
|
95
|
+
fields: {
|
|
96
|
+
target_id: {
|
|
97
|
+
type: 'uint32',
|
|
98
|
+
id: 1,
|
|
99
|
+
},
|
|
100
|
+
path: {
|
|
101
|
+
type: 'string',
|
|
102
|
+
id: 2,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
95
105
|
},
|
|
96
|
-
|
|
106
|
+
DeviceFirmwareUpdateRequest: {
|
|
107
|
+
fields: {
|
|
108
|
+
targets: {
|
|
109
|
+
type: 'DeviceFirmwareTarget',
|
|
110
|
+
id: 1,
|
|
111
|
+
rule: 'repeated',
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
DeviceFirmwareUpdateRecord: {
|
|
97
116
|
fields: {
|
|
98
117
|
target_id: {
|
|
99
118
|
type: 'uint32',
|
|
100
119
|
id: 1,
|
|
101
120
|
},
|
|
102
|
-
|
|
121
|
+
status: {
|
|
103
122
|
type: 'uint32',
|
|
104
|
-
id:
|
|
123
|
+
id: 10,
|
|
124
|
+
},
|
|
125
|
+
payload_version: {
|
|
126
|
+
type: 'uint32',
|
|
127
|
+
id: 20,
|
|
128
|
+
},
|
|
129
|
+
path: {
|
|
130
|
+
type: 'string',
|
|
131
|
+
id: 30,
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
DeviceFirmwareUpdateStatus: {
|
|
136
|
+
fields: {
|
|
137
|
+
records: {
|
|
138
|
+
type: 'DeviceFirmwareUpdateRecord',
|
|
139
|
+
id: 1,
|
|
140
|
+
rule: 'repeated',
|
|
105
141
|
},
|
|
106
142
|
},
|
|
107
143
|
},
|
|
@@ -130,13 +166,13 @@ const protocolV2Messages = parseConfigure({
|
|
|
130
166
|
},
|
|
131
167
|
MessageType: {
|
|
132
168
|
values: {
|
|
133
|
-
|
|
134
|
-
|
|
169
|
+
MessageType_ProtocolInfoRequest: 60200,
|
|
170
|
+
MessageType_ProtocolInfo: 60201,
|
|
135
171
|
MessageType_Ping: 60206,
|
|
136
172
|
MessageType_Success: 60207,
|
|
137
173
|
MessageType_FileWrite: 60805,
|
|
138
|
-
|
|
139
|
-
|
|
174
|
+
MessageType_DeviceFirmwareUpdateRequest: 61000,
|
|
175
|
+
MessageType_DeviceFirmwareUpdateStatus: 61002,
|
|
140
176
|
MessageType_PartialNested: 62000,
|
|
141
177
|
},
|
|
142
178
|
},
|
|
@@ -157,10 +193,10 @@ const rewriteSeq = (frame, seq) => {
|
|
|
157
193
|
|
|
158
194
|
describe('Protocol V2 framing and session', () => {
|
|
159
195
|
test('encodes and decodes Protocol V2 protobuf frames', () => {
|
|
160
|
-
const frame = ProtocolV2.encodeFrame(schemas, '
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
196
|
+
const frame = ProtocolV2.encodeFrame(schemas, 'ProtocolInfo', {
|
|
197
|
+
version: 1,
|
|
198
|
+
supported_messages: [60200, 60201],
|
|
199
|
+
protobuf_definition: 'proto',
|
|
164
200
|
});
|
|
165
201
|
|
|
166
202
|
const parsed = protocolV2.decodeFrame(frame);
|
|
@@ -168,15 +204,15 @@ describe('Protocol V2 framing and session', () => {
|
|
|
168
204
|
|
|
169
205
|
const decoded = ProtocolV2.decodeFrame(schemas, frame);
|
|
170
206
|
expect(decoded).toEqual({
|
|
171
|
-
type: '
|
|
172
|
-
messageName: '
|
|
207
|
+
type: 'ProtocolInfo',
|
|
208
|
+
messageName: 'ProtocolInfo',
|
|
173
209
|
messageTypeId: 60201,
|
|
174
210
|
pbPayload: parsed.pbPayload,
|
|
175
211
|
seq: parsed.seq,
|
|
176
212
|
message: {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
213
|
+
version: 1,
|
|
214
|
+
supported_messages: [60200, 60201],
|
|
215
|
+
protobuf_definition: 'proto',
|
|
180
216
|
},
|
|
181
217
|
});
|
|
182
218
|
});
|
|
@@ -214,10 +250,9 @@ describe('Protocol V2 framing and session', () => {
|
|
|
214
250
|
});
|
|
215
251
|
|
|
216
252
|
test('reassembles split Protocol V2 frames and rejects oversized frames', () => {
|
|
217
|
-
const frame = ProtocolV2.encodeFrame(schemas, '
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
patch_version: 0,
|
|
253
|
+
const frame = ProtocolV2.encodeFrame(schemas, 'ProtocolInfo', {
|
|
254
|
+
version: 1,
|
|
255
|
+
supported_messages: [],
|
|
221
256
|
});
|
|
222
257
|
const assembler = new ProtocolV2FrameAssembler();
|
|
223
258
|
|
|
@@ -229,15 +264,13 @@ describe('Protocol V2 framing and session', () => {
|
|
|
229
264
|
});
|
|
230
265
|
|
|
231
266
|
test('keeps bytes after the first complete frame for the next read', () => {
|
|
232
|
-
const first = ProtocolV2.encodeFrame(schemas, '
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
patch_version: 0,
|
|
267
|
+
const first = ProtocolV2.encodeFrame(schemas, 'ProtocolInfo', {
|
|
268
|
+
version: 1,
|
|
269
|
+
supported_messages: [],
|
|
236
270
|
});
|
|
237
|
-
const second = ProtocolV2.encodeFrame(schemas, '
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
patch_version: 0,
|
|
271
|
+
const second = ProtocolV2.encodeFrame(schemas, 'ProtocolInfo', {
|
|
272
|
+
version: 2,
|
|
273
|
+
supported_messages: [],
|
|
241
274
|
});
|
|
242
275
|
const assembler = new ProtocolV2FrameAssembler();
|
|
243
276
|
const combined = new Uint8Array(first.length + second.length);
|
|
@@ -250,10 +283,9 @@ describe('Protocol V2 framing and session', () => {
|
|
|
250
283
|
|
|
251
284
|
test('session writes one encoded frame and decodes the response frame', async () => {
|
|
252
285
|
const written = [];
|
|
253
|
-
const response = ProtocolV2.encodeFrame(schemas, '
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
patch_version: 1,
|
|
286
|
+
const response = ProtocolV2.encodeFrame(schemas, 'ProtocolInfo', {
|
|
287
|
+
version: 2,
|
|
288
|
+
supported_messages: [60206],
|
|
257
289
|
});
|
|
258
290
|
const session = new ProtocolV2Session({
|
|
259
291
|
schemas,
|
|
@@ -266,18 +298,18 @@ describe('Protocol V2 framing and session', () => {
|
|
|
266
298
|
Promise.resolve(rewriteSeq(response, protocolV2.decodeFrame(written[0]).seq)),
|
|
267
299
|
});
|
|
268
300
|
|
|
269
|
-
const result = await session.call('
|
|
301
|
+
const result = await session.call('ProtocolInfoRequest', {});
|
|
270
302
|
|
|
271
303
|
expect(written).toHaveLength(1);
|
|
272
304
|
expect(written[0][4]).toBe(1);
|
|
273
305
|
expect(written[0][5]).toBe(0);
|
|
274
306
|
expect(protocolV2.decodeFrame(written[0]).messageTypeId).toBe(60200);
|
|
275
307
|
expect(result).toEqual({
|
|
276
|
-
type: '
|
|
308
|
+
type: 'ProtocolInfo',
|
|
277
309
|
message: {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
310
|
+
version: 2,
|
|
311
|
+
supported_messages: [60206],
|
|
312
|
+
protobuf_definition: null,
|
|
281
313
|
},
|
|
282
314
|
});
|
|
283
315
|
});
|
|
@@ -307,10 +339,9 @@ describe('Protocol V2 framing and session', () => {
|
|
|
307
339
|
});
|
|
308
340
|
|
|
309
341
|
test('session accepts response frames with a device-owned seq', async () => {
|
|
310
|
-
const response = ProtocolV2.encodeFrame(schemas, '
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
patch_version: 1,
|
|
342
|
+
const response = ProtocolV2.encodeFrame(schemas, 'ProtocolInfo', {
|
|
343
|
+
version: 2,
|
|
344
|
+
supported_messages: [],
|
|
314
345
|
});
|
|
315
346
|
const logger = {
|
|
316
347
|
debug: jest.fn(),
|
|
@@ -323,12 +354,12 @@ describe('Protocol V2 framing and session', () => {
|
|
|
323
354
|
logger,
|
|
324
355
|
});
|
|
325
356
|
|
|
326
|
-
await expect(session.call('
|
|
327
|
-
type: '
|
|
357
|
+
await expect(session.call('ProtocolInfoRequest', {})).resolves.toEqual({
|
|
358
|
+
type: 'ProtocolInfo',
|
|
328
359
|
message: {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
360
|
+
version: 2,
|
|
361
|
+
supported_messages: [],
|
|
362
|
+
protobuf_definition: null,
|
|
332
363
|
},
|
|
333
364
|
});
|
|
334
365
|
expect(logger.debug).toHaveBeenCalledWith(expect.stringContaining('seq differs'));
|
|
@@ -412,10 +443,9 @@ describe('Protocol V2 framing and session', () => {
|
|
|
412
443
|
const stale = ProtocolV2.encodeFrame(schemas, 'Success', {
|
|
413
444
|
message: 'stale response',
|
|
414
445
|
});
|
|
415
|
-
const response = ProtocolV2.encodeFrame(schemas, '
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
patch_version: 1,
|
|
446
|
+
const response = ProtocolV2.encodeFrame(schemas, 'ProtocolInfo', {
|
|
447
|
+
version: 2,
|
|
448
|
+
supported_messages: [],
|
|
419
449
|
});
|
|
420
450
|
const logger = {
|
|
421
451
|
debug: jest.fn(),
|
|
@@ -430,13 +460,13 @@ describe('Protocol V2 framing and session', () => {
|
|
|
430
460
|
});
|
|
431
461
|
|
|
432
462
|
await expect(
|
|
433
|
-
session.call('
|
|
463
|
+
session.call('ProtocolInfoRequest', {}, { expectedTypes: ['ProtocolInfo'] })
|
|
434
464
|
).resolves.toEqual({
|
|
435
|
-
type: '
|
|
465
|
+
type: 'ProtocolInfo',
|
|
436
466
|
message: {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
467
|
+
version: 2,
|
|
468
|
+
supported_messages: [],
|
|
469
|
+
protobuf_definition: null,
|
|
440
470
|
},
|
|
441
471
|
});
|
|
442
472
|
|
|
@@ -446,9 +476,8 @@ describe('Protocol V2 framing and session', () => {
|
|
|
446
476
|
|
|
447
477
|
test('session consumes intermediate response frames before returning the final response', async () => {
|
|
448
478
|
const written = [];
|
|
449
|
-
const progress = ProtocolV2.encodeFrame(schemas, '
|
|
450
|
-
target_id:
|
|
451
|
-
progress: 42,
|
|
479
|
+
const progress = ProtocolV2.encodeFrame(schemas, 'DeviceFirmwareUpdateStatus', {
|
|
480
|
+
records: [{ target_id: 3, status: 1 }],
|
|
452
481
|
});
|
|
453
482
|
const success = ProtocolV2.encodeFrame(schemas, 'Success', {
|
|
454
483
|
message: 'ok',
|
|
@@ -472,20 +501,19 @@ describe('Protocol V2 framing and session', () => {
|
|
|
472
501
|
});
|
|
473
502
|
|
|
474
503
|
const result = await session.call(
|
|
475
|
-
'
|
|
476
|
-
{},
|
|
504
|
+
'DeviceFirmwareUpdateRequest',
|
|
505
|
+
{ targets: [{ target_id: 3, path: 'vol1:firmware.bin' }] },
|
|
477
506
|
{
|
|
478
|
-
intermediateTypes: ['
|
|
507
|
+
intermediateTypes: ['DeviceFirmwareUpdateStatus'],
|
|
479
508
|
onIntermediateResponse,
|
|
480
509
|
}
|
|
481
510
|
);
|
|
482
511
|
|
|
483
512
|
expect(readFrame).toHaveBeenCalledTimes(2);
|
|
484
513
|
expect(onIntermediateResponse).toHaveBeenCalledWith({
|
|
485
|
-
type: '
|
|
514
|
+
type: 'DeviceFirmwareUpdateStatus',
|
|
486
515
|
message: {
|
|
487
|
-
target_id:
|
|
488
|
-
progress: 42,
|
|
516
|
+
records: [{ target_id: 3, status: 1, payload_version: null, path: null }],
|
|
489
517
|
},
|
|
490
518
|
});
|
|
491
519
|
expect(result).toEqual({
|
|
@@ -575,7 +603,7 @@ describe('Protocol V2 framing and session', () => {
|
|
|
575
603
|
});
|
|
576
604
|
|
|
577
605
|
await expect(
|
|
578
|
-
session.call('
|
|
606
|
+
session.call('ProtocolInfoRequest', {}, { timeoutMs: 10, expectedTypes: ['ProtocolInfo'] })
|
|
579
607
|
).rejects.toThrow('Protocol V2 response timeout');
|
|
580
608
|
|
|
581
609
|
// Without cancellation the loop would skip this unexpected Success frame
|
|
@@ -700,10 +728,9 @@ describe('Protocol V2 framing and session', () => {
|
|
|
700
728
|
});
|
|
701
729
|
|
|
702
730
|
test('assembler drain returns every buffered complete frame', () => {
|
|
703
|
-
const first = ProtocolV2.encodeFrame(schemas, '
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
patch_version: 0,
|
|
731
|
+
const first = ProtocolV2.encodeFrame(schemas, 'ProtocolInfo', {
|
|
732
|
+
version: 1,
|
|
733
|
+
supported_messages: [],
|
|
707
734
|
});
|
|
708
735
|
const second = ProtocolV2.encodeFrame(schemas, 'Success', { message: 'ok' });
|
|
709
736
|
const third = ProtocolV2.encodeFrame(schemas, 'Success', { message: 'last' });
|
package/dist/constants.d.ts
CHANGED
|
@@ -5,9 +5,9 @@ export declare const PROTOCOL_V1_USB_PACKET_SIZE: number;
|
|
|
5
5
|
export declare const PROTOCOL_V1_MESSAGE_HEADER_SIZE: number;
|
|
6
6
|
export declare const PROTOCOL_V1_ENVELOPE_HEADER_SIZE: number;
|
|
7
7
|
export declare const PROTOCOL_V2_FRAME_MAX_BYTES = 4608;
|
|
8
|
-
export declare const PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE =
|
|
8
|
+
export declare const PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE = 4000;
|
|
9
9
|
export declare const PROTOCOL_V2_BLE_FILE_CHUNK_SIZE = 1800;
|
|
10
|
-
export declare const PROTOCOL_V2_FILE_CHUNK_SIZE =
|
|
10
|
+
export declare const PROTOCOL_V2_FILE_CHUNK_SIZE = 4000;
|
|
11
11
|
export declare const PROTOCOL_V2_CHANNEL_USB = 0;
|
|
12
12
|
export declare const PROTOCOL_V2_CHANNEL_BLE_UART = 1;
|
|
13
13
|
export declare const PROTOCOL_V2_CHANNEL_SOCKET = 2;
|