@onekeyfe/hd-transport 1.2.0-alpha.10 → 1.2.0-alpha.12
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.test.js +4 -27
- package/dist/index.d.ts +51 -38
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -176
- package/dist/protocols/index.d.ts +1 -5
- package/dist/protocols/index.d.ts.map +1 -1
- package/dist/protocols/v2/decode.d.ts +1 -2
- package/dist/protocols/v2/decode.d.ts.map +1 -1
- package/dist/protocols/v2/encode.d.ts +2 -3
- package/dist/protocols/v2/encode.d.ts.map +1 -1
- package/dist/protocols/v2/index.d.ts +0 -1
- package/dist/protocols/v2/index.d.ts.map +1 -1
- package/dist/protocols/v2/session.d.ts.map +1 -1
- package/dist/types/messages.d.ts +37 -0
- package/dist/types/messages.d.ts.map +1 -1
- package/messages-protocol-v2.json +92 -8
- package/package.json +2 -2
- package/src/protocols/index.ts +2 -37
- package/src/protocols/v2/decode.ts +1 -23
- package/src/protocols/v2/encode.ts +1 -27
- package/src/protocols/v2/index.ts +0 -1
- package/src/protocols/v2/session.ts +1 -152
- package/src/types/messages.ts +41 -0
- package/dist/protocols/v2/debug.d.ts +0 -13
- package/dist/protocols/v2/debug.d.ts.map +0 -1
- package/src/protocols/v2/debug.ts +0 -26
|
@@ -467,6 +467,7 @@
|
|
|
467
467
|
"MessageType_DeviceSettings": 60410,
|
|
468
468
|
"MessageType_DeviceSettingsGet": 60411,
|
|
469
469
|
"MessageType_DeviceSettingsSet": 60412,
|
|
470
|
+
"MessageType_DeviceSettingsPageShow": 60413,
|
|
470
471
|
"MessageType_DeviceCertificate": 60420,
|
|
471
472
|
"MessageType_DeviceCertificateWrite": 60421,
|
|
472
473
|
"MessageType_DeviceCertificateRead": 60422,
|
|
@@ -7045,14 +7046,6 @@
|
|
|
7045
7046
|
"passphrase_state": {
|
|
7046
7047
|
"type": "string",
|
|
7047
7048
|
"id": 1
|
|
7048
|
-
},
|
|
7049
|
-
"_only_main_pin": {
|
|
7050
|
-
"type": "bool",
|
|
7051
|
-
"id": 2
|
|
7052
|
-
},
|
|
7053
|
-
"allow_create_attach_pin": {
|
|
7054
|
-
"type": "bool",
|
|
7055
|
-
"id": 3
|
|
7056
7049
|
}
|
|
7057
7050
|
}
|
|
7058
7051
|
},
|
|
@@ -11394,6 +11387,20 @@
|
|
|
11394
11387
|
}
|
|
11395
11388
|
}
|
|
11396
11389
|
},
|
|
11390
|
+
"DeviceErrorCode": {
|
|
11391
|
+
"values": {
|
|
11392
|
+
"DeviceError_None": 0,
|
|
11393
|
+
"DeviceError_Busy": 1,
|
|
11394
|
+
"DeviceError_NotInitialized": 2,
|
|
11395
|
+
"DeviceError_ActionCancelled": 3,
|
|
11396
|
+
"DeviceError_PinAlreadyUsed": 4,
|
|
11397
|
+
"DeviceError_PersistFailed": 5,
|
|
11398
|
+
"DeviceError_SeError": 6,
|
|
11399
|
+
"DeviceError_InvalidLanguage": 7,
|
|
11400
|
+
"DeviceError_WallpaperNotUsable": 8,
|
|
11401
|
+
"DeviceError_DeviceLocked": 9
|
|
11402
|
+
}
|
|
11403
|
+
},
|
|
11397
11404
|
"DeviceRebootType": {
|
|
11398
11405
|
"values": {
|
|
11399
11406
|
"Normal": 0,
|
|
@@ -11423,6 +11430,62 @@
|
|
|
11423
11430
|
"language": {
|
|
11424
11431
|
"type": "string",
|
|
11425
11432
|
"id": 3
|
|
11433
|
+
},
|
|
11434
|
+
"wallpaper_path": {
|
|
11435
|
+
"type": "string",
|
|
11436
|
+
"id": 4
|
|
11437
|
+
},
|
|
11438
|
+
"passphrase_enable": {
|
|
11439
|
+
"type": "bool",
|
|
11440
|
+
"id": 6
|
|
11441
|
+
},
|
|
11442
|
+
"brightness": {
|
|
11443
|
+
"type": "uint32",
|
|
11444
|
+
"id": 7
|
|
11445
|
+
},
|
|
11446
|
+
"autolock_delay_ms": {
|
|
11447
|
+
"type": "uint32",
|
|
11448
|
+
"id": 8
|
|
11449
|
+
},
|
|
11450
|
+
"autoshutdown_delay_ms": {
|
|
11451
|
+
"type": "uint32",
|
|
11452
|
+
"id": 9
|
|
11453
|
+
},
|
|
11454
|
+
"animation_enable": {
|
|
11455
|
+
"type": "bool",
|
|
11456
|
+
"id": 10
|
|
11457
|
+
},
|
|
11458
|
+
"tap_to_wake": {
|
|
11459
|
+
"type": "bool",
|
|
11460
|
+
"id": 11
|
|
11461
|
+
},
|
|
11462
|
+
"haptic_feedback": {
|
|
11463
|
+
"type": "bool",
|
|
11464
|
+
"id": 12
|
|
11465
|
+
},
|
|
11466
|
+
"device_name_display_enabled": {
|
|
11467
|
+
"type": "bool",
|
|
11468
|
+
"id": 13
|
|
11469
|
+
},
|
|
11470
|
+
"airgap_mode": {
|
|
11471
|
+
"type": "bool",
|
|
11472
|
+
"id": 14
|
|
11473
|
+
},
|
|
11474
|
+
"fido_enabled": {
|
|
11475
|
+
"type": "bool",
|
|
11476
|
+
"id": 15
|
|
11477
|
+
},
|
|
11478
|
+
"experimental_features": {
|
|
11479
|
+
"type": "bool",
|
|
11480
|
+
"id": 16
|
|
11481
|
+
},
|
|
11482
|
+
"usb_lock_enable": {
|
|
11483
|
+
"type": "bool",
|
|
11484
|
+
"id": 17
|
|
11485
|
+
},
|
|
11486
|
+
"random_keypad": {
|
|
11487
|
+
"type": "bool",
|
|
11488
|
+
"id": 18
|
|
11426
11489
|
}
|
|
11427
11490
|
}
|
|
11428
11491
|
},
|
|
@@ -11438,6 +11501,27 @@
|
|
|
11438
11501
|
}
|
|
11439
11502
|
}
|
|
11440
11503
|
},
|
|
11504
|
+
"DeviceSettingsPage": {
|
|
11505
|
+
"values": {
|
|
11506
|
+
"DeviceReset": 0,
|
|
11507
|
+
"DevicePinChange": 1,
|
|
11508
|
+
"DevicePassphrase": 2,
|
|
11509
|
+
"DeviceAirgap": 3
|
|
11510
|
+
}
|
|
11511
|
+
},
|
|
11512
|
+
"DeviceSettingsPageShow": {
|
|
11513
|
+
"fields": {
|
|
11514
|
+
"page": {
|
|
11515
|
+
"rule": "required",
|
|
11516
|
+
"type": "DeviceSettingsPage",
|
|
11517
|
+
"id": 1
|
|
11518
|
+
},
|
|
11519
|
+
"field_name": {
|
|
11520
|
+
"type": "string",
|
|
11521
|
+
"id": 2
|
|
11522
|
+
}
|
|
11523
|
+
}
|
|
11524
|
+
},
|
|
11441
11525
|
"DeviceCertificate": {
|
|
11442
11526
|
"fields": {
|
|
11443
11527
|
"cert_and_pubkey": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.12",
|
|
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": "3601e8003c96a2a4ca7856e865d16f48c0c5b758"
|
|
32
32
|
}
|
package/src/protocols/index.ts
CHANGED
|
@@ -9,7 +9,6 @@ import { decode as decodeProtobuf } from '../serialization/protobuf/decode';
|
|
|
9
9
|
import { decodeFrame as decodeV2Frame, encodeProtobufFrame, isAckFrame } from './v2';
|
|
10
10
|
|
|
11
11
|
import type { Root } from 'protobufjs/light';
|
|
12
|
-
import type { ProtocolV2DebugLogger } from './v2';
|
|
13
12
|
|
|
14
13
|
export const PROTOCOL_V2_SYS_MESSAGE_THRESHOLD = 60000;
|
|
15
14
|
|
|
@@ -23,9 +22,6 @@ type ProtocolV2FrameOptions = {
|
|
|
23
22
|
router?: number;
|
|
24
23
|
/** Sequence number (1-255). Managed per-session by ProtocolV2Session. */
|
|
25
24
|
seq?: number;
|
|
26
|
-
logger?: ProtocolV2DebugLogger;
|
|
27
|
-
logPrefix?: string;
|
|
28
|
-
context?: string;
|
|
29
25
|
};
|
|
30
26
|
|
|
31
27
|
const resolveProtocolV2EncodeSchema = (name: string, schemas: ProtocolV2Schemas) => {
|
|
@@ -89,52 +85,21 @@ export const ProtocolV2 = {
|
|
|
89
85
|
const rawPbBuffer = pbBuffer.toBuffer() as unknown as ArrayBuffer;
|
|
90
86
|
const pbBytes = new Uint8Array(rawPbBuffer);
|
|
91
87
|
|
|
92
|
-
options.logger?.debug?.(`[${options.logPrefix ?? 'ProtocolV2'}] encode protobuf`, {
|
|
93
|
-
context: options.context ?? `encode:${name}`,
|
|
94
|
-
messageName: name,
|
|
95
|
-
messageTypeId,
|
|
96
|
-
pbPayloadLength: pbBytes.length,
|
|
97
|
-
packetSrc: options.packetSrc ?? 0,
|
|
98
|
-
router: options.router ?? 0,
|
|
99
|
-
});
|
|
100
|
-
|
|
101
88
|
return encodeProtobufFrame(
|
|
102
89
|
messageTypeId,
|
|
103
90
|
pbBytes,
|
|
104
91
|
options.packetSrc,
|
|
105
92
|
options.router,
|
|
106
|
-
{
|
|
107
|
-
logger: options.logger,
|
|
108
|
-
logPrefix: options.logPrefix,
|
|
109
|
-
context: options.context ?? `encode:${name}`,
|
|
110
|
-
messageName: name,
|
|
111
|
-
},
|
|
112
93
|
options.seq
|
|
113
94
|
);
|
|
114
95
|
},
|
|
115
96
|
|
|
116
|
-
decodeFrame(
|
|
117
|
-
|
|
118
|
-
frame: Uint8Array,
|
|
119
|
-
options: Pick<ProtocolV2FrameOptions, 'logger' | 'logPrefix' | 'context'> = {}
|
|
120
|
-
) {
|
|
121
|
-
const { messageTypeId, pbPayload, seq } = decodeV2Frame(frame, {
|
|
122
|
-
logger: options.logger,
|
|
123
|
-
logPrefix: options.logPrefix,
|
|
124
|
-
context: options.context ?? 'decode',
|
|
125
|
-
});
|
|
97
|
+
decodeFrame(schemas: ProtocolV2Schemas, frame: Uint8Array) {
|
|
98
|
+
const { messageTypeId, pbPayload, seq } = decodeV2Frame(frame);
|
|
126
99
|
const { Message, messageName } = createProtocolV2MessageFromType(messageTypeId, schemas);
|
|
127
100
|
const rxByteBuffer = ByteBuffer.wrap(Buffer.from(pbPayload) as unknown as ArrayBuffer);
|
|
128
101
|
const message = decodeProtobuf(Message, rxByteBuffer);
|
|
129
102
|
|
|
130
|
-
options.logger?.debug?.(`[${options.logPrefix ?? 'ProtocolV2'}] decode protobuf`, {
|
|
131
|
-
context: options.context ?? `decode:${messageName}`,
|
|
132
|
-
messageName,
|
|
133
|
-
messageTypeId,
|
|
134
|
-
pbPayloadLength: pbPayload.length,
|
|
135
|
-
seq,
|
|
136
|
-
});
|
|
137
|
-
|
|
138
103
|
return {
|
|
139
104
|
message,
|
|
140
105
|
messageName,
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { PROTO_DATA_TYPE_ACK, PROTO_HEAD_CRC_SIZE, PROTO_HEAD_SOF } from './constants';
|
|
2
2
|
import { crc8 } from './crc8';
|
|
3
|
-
import { logProtocolV2Debug } from './debug';
|
|
4
|
-
|
|
5
|
-
import type { ProtocolV2FrameDebugOptions } from './debug';
|
|
6
3
|
|
|
7
4
|
export interface ProtoV2Frame {
|
|
8
5
|
/** Little-endian message type ID */
|
|
@@ -74,13 +71,8 @@ export function isAckFrame(data: Uint8Array): boolean {
|
|
|
74
71
|
*
|
|
75
72
|
* Returns the decoded messageTypeId, raw protobuf payload, and sequence number.
|
|
76
73
|
*/
|
|
77
|
-
export function decodeFrame(
|
|
78
|
-
data: Uint8Array,
|
|
79
|
-
debugOptions?: ProtocolV2FrameDebugOptions
|
|
80
|
-
): ProtoV2Frame {
|
|
74
|
+
export function decodeFrame(data: Uint8Array): ProtoV2Frame {
|
|
81
75
|
const frameLen = validateFrame(data);
|
|
82
|
-
const expectedHeaderCrc = data[3];
|
|
83
|
-
const expectedFrameCrc = data[frameLen - 1];
|
|
84
76
|
|
|
85
77
|
const seq = data[6];
|
|
86
78
|
// Payload spans bytes 7 to frameLen-2 (inclusive), excluding final CRC byte
|
|
@@ -93,19 +85,5 @@ export function decodeFrame(
|
|
|
93
85
|
const messageTypeId = payloadData[0] + payloadData[1] * 256;
|
|
94
86
|
const pbPayload = payloadData.slice(2);
|
|
95
87
|
|
|
96
|
-
logProtocolV2Debug(debugOptions, 'decode raw frame', {
|
|
97
|
-
frameLen,
|
|
98
|
-
dataLength: data.length,
|
|
99
|
-
router: data[4],
|
|
100
|
-
attr: data[5],
|
|
101
|
-
seq,
|
|
102
|
-
headerCrc: data[3],
|
|
103
|
-
expectedHeaderCrc,
|
|
104
|
-
frameCrc: data[frameLen - 1],
|
|
105
|
-
expectedFrameCrc,
|
|
106
|
-
messageTypeId,
|
|
107
|
-
pbPayloadLength: pbPayload.length,
|
|
108
|
-
});
|
|
109
|
-
|
|
110
88
|
return { messageTypeId, pbPayload, seq };
|
|
111
89
|
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { PROTO_DATA_TYPE_PACKET, PROTO_HEAD_CRC_SIZE, PROTO_HEAD_SOF } from './constants';
|
|
2
2
|
import { crc8 } from './crc8';
|
|
3
|
-
import { logProtocolV2Debug } from './debug';
|
|
4
3
|
import { PROTOCOL_V2_FRAME_MAX_BYTES } from '../../constants';
|
|
5
4
|
|
|
6
|
-
import type { ProtocolV2FrameDebugOptions } from './debug';
|
|
7
|
-
|
|
8
5
|
// Default sequence number when callers do not manage one themselves.
|
|
9
6
|
// Stateful per-session sequencing lives in ProtocolV2Session (session.ts),
|
|
10
7
|
// which advances the counter via nextProtoSeq() and passes it in explicitly.
|
|
@@ -35,7 +32,6 @@ export function encodeFrame(
|
|
|
35
32
|
payload: Uint8Array | null,
|
|
36
33
|
packetSrc?: number,
|
|
37
34
|
router?: number,
|
|
38
|
-
debugOptions?: ProtocolV2FrameDebugOptions,
|
|
39
35
|
seq?: number
|
|
40
36
|
): Uint8Array {
|
|
41
37
|
const resolvedPacketSrc = packetSrc ?? 0;
|
|
@@ -69,17 +65,6 @@ export function encodeFrame(
|
|
|
69
65
|
// CRC8 over entire frame except last byte
|
|
70
66
|
frame[frameLen - 1] = crc8(frame, frameLen - 1);
|
|
71
67
|
|
|
72
|
-
logProtocolV2Debug(debugOptions, 'encode raw frame', {
|
|
73
|
-
frameLen,
|
|
74
|
-
payloadLen,
|
|
75
|
-
packetSrc: resolvedPacketSrc,
|
|
76
|
-
router: frame[4],
|
|
77
|
-
attr: frame[5],
|
|
78
|
-
seq: frame[6],
|
|
79
|
-
headerCrc: frame[3],
|
|
80
|
-
frameCrc: frame[frameLen - 1],
|
|
81
|
-
});
|
|
82
|
-
|
|
83
68
|
return frame;
|
|
84
69
|
}
|
|
85
70
|
|
|
@@ -95,22 +80,11 @@ export function encodeProtobufFrame(
|
|
|
95
80
|
pbPayload: Uint8Array,
|
|
96
81
|
packetSrc?: number,
|
|
97
82
|
router?: number,
|
|
98
|
-
debugOptions?: ProtocolV2FrameDebugOptions,
|
|
99
83
|
seq?: number
|
|
100
84
|
): Uint8Array {
|
|
101
85
|
const payload = new Uint8Array(2 + pbPayload.length);
|
|
102
86
|
payload[0] = messageTypeId % 256;
|
|
103
87
|
payload[1] = Math.floor(messageTypeId / 256) % 256;
|
|
104
88
|
payload.set(pbPayload, 2);
|
|
105
|
-
return encodeFrame(
|
|
106
|
-
payload,
|
|
107
|
-
packetSrc,
|
|
108
|
-
router,
|
|
109
|
-
{
|
|
110
|
-
...debugOptions,
|
|
111
|
-
messageTypeId,
|
|
112
|
-
pbPayloadLength: pbPayload.length,
|
|
113
|
-
},
|
|
114
|
-
seq
|
|
115
|
-
);
|
|
89
|
+
return encodeFrame(payload, packetSrc, router, seq);
|
|
116
90
|
}
|
|
@@ -71,15 +71,6 @@ export function bytesToHex(bytes: Uint8Array): string {
|
|
|
71
71
|
.join('');
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
// Frame header bytes worth logging: SOF, len lo/hi, header CRC, router, attr, seq.
|
|
75
|
-
// The rest of the frame is protobuf payload and may contain sensitive fields
|
|
76
|
-
// (mnemonic words via WordAck, PINs, seeds via LoadDevice, ...), so raw frame
|
|
77
|
-
// hex logs must never include it.
|
|
78
|
-
const PROTOCOL_V2_DEBUG_HEADER_BYTES = 7;
|
|
79
|
-
const PROTOCOL_V2_DEBUG_ARRAY_ITEMS_LIMIT = 20;
|
|
80
|
-
const PROTOCOL_V2_DEBUG_OBJECT_KEYS_LIMIT = 40;
|
|
81
|
-
const PROTOCOL_V2_DEBUG_STRING_LIMIT = 512;
|
|
82
|
-
const PROTOCOL_V2_DEBUG_DEPTH_LIMIT = 4;
|
|
83
74
|
const HIGH_VOLUME_PROTOCOL_V2_CALLS = new Set([
|
|
84
75
|
...LogBlockCommand,
|
|
85
76
|
'FilesystemFileRead',
|
|
@@ -91,102 +82,6 @@ function shouldReduceProtocolV2Debug(name: string) {
|
|
|
91
82
|
return HIGH_VOLUME_PROTOCOL_V2_CALLS.has(name);
|
|
92
83
|
}
|
|
93
84
|
|
|
94
|
-
function frameHeaderDebugHex(frame: Uint8Array): string {
|
|
95
|
-
// Only the frame header is dumped as hex; the payload is logged separately
|
|
96
|
-
// in sanitized/structured form (sanitizeProtocolV2DebugPayload).
|
|
97
|
-
return bytesToHex(frame.slice(0, PROTOCOL_V2_DEBUG_HEADER_BYTES));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function getBinaryByteLength(value: unknown): number | undefined {
|
|
101
|
-
if (value instanceof ArrayBuffer) {
|
|
102
|
-
return value.byteLength;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (ArrayBuffer.isView(value)) {
|
|
106
|
-
return value.byteLength;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (typeof Blob !== 'undefined' && value instanceof Blob) {
|
|
110
|
-
return value.size;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return undefined;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function summarizeRedactedData(value: unknown): string {
|
|
117
|
-
const byteLength = getBinaryByteLength(value);
|
|
118
|
-
if (byteLength !== undefined) {
|
|
119
|
-
return `[redacted data: ${byteLength} bytes]`;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (typeof value === 'string') {
|
|
123
|
-
return `[redacted data: string length=${value.length}]`;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (Array.isArray(value)) {
|
|
127
|
-
return `[redacted data: array length=${value.length}]`;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (value && typeof value === 'object') {
|
|
131
|
-
return `[redacted data: object keys=${Object.keys(value).length}]`;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return `[redacted data: ${typeof value}]`;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function sanitizeProtocolV2DebugPayload(value: unknown, key = '', depth = 0): unknown {
|
|
138
|
-
if (/^(data|payload)$/i.test(key) && value !== null && value !== undefined) {
|
|
139
|
-
return summarizeRedactedData(value);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (/(passphrase|pin|mnemonic|seed|private)/i.test(key)) {
|
|
143
|
-
return '[redacted sensitive value]';
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const byteLength = getBinaryByteLength(value);
|
|
147
|
-
if (byteLength !== undefined) {
|
|
148
|
-
return `[binary: ${byteLength} bytes]`;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (typeof value === 'string') {
|
|
152
|
-
return value.length > PROTOCOL_V2_DEBUG_STRING_LIMIT
|
|
153
|
-
? `${value.slice(0, PROTOCOL_V2_DEBUG_STRING_LIMIT)}... (len=${value.length})`
|
|
154
|
-
: value;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (!value || typeof value !== 'object') {
|
|
158
|
-
return value;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (depth >= PROTOCOL_V2_DEBUG_DEPTH_LIMIT) {
|
|
162
|
-
return Array.isArray(value)
|
|
163
|
-
? `[array length=${value.length}]`
|
|
164
|
-
: `[object keys=${Object.keys(value).length}]`;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (Array.isArray(value)) {
|
|
168
|
-
const items = value
|
|
169
|
-
.slice(0, PROTOCOL_V2_DEBUG_ARRAY_ITEMS_LIMIT)
|
|
170
|
-
.map(item => sanitizeProtocolV2DebugPayload(item, key, depth + 1));
|
|
171
|
-
if (value.length > PROTOCOL_V2_DEBUG_ARRAY_ITEMS_LIMIT) {
|
|
172
|
-
items.push(`... (${value.length - PROTOCOL_V2_DEBUG_ARRAY_ITEMS_LIMIT} more)`);
|
|
173
|
-
}
|
|
174
|
-
return items;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const entries = Object.entries(value).slice(0, PROTOCOL_V2_DEBUG_OBJECT_KEYS_LIMIT);
|
|
178
|
-
const sanitized: Record<string, unknown> = {};
|
|
179
|
-
entries.forEach(([entryKey, entryValue]) => {
|
|
180
|
-
sanitized[entryKey] = sanitizeProtocolV2DebugPayload(entryValue, entryKey, depth + 1);
|
|
181
|
-
});
|
|
182
|
-
if (Object.keys(value).length > PROTOCOL_V2_DEBUG_OBJECT_KEYS_LIMIT) {
|
|
183
|
-
sanitized.__truncated__ = `${
|
|
184
|
-
Object.keys(value).length - PROTOCOL_V2_DEBUG_OBJECT_KEYS_LIMIT
|
|
185
|
-
} more keys`;
|
|
186
|
-
}
|
|
187
|
-
return sanitized;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
85
|
const COMMON_TERMINAL_RESPONSE_TYPES = new Set([
|
|
191
86
|
'Failure',
|
|
192
87
|
'ButtonRequest',
|
|
@@ -305,11 +200,7 @@ export class ProtocolV2Session {
|
|
|
305
200
|
packetSrc,
|
|
306
201
|
router,
|
|
307
202
|
seq: protoSeq,
|
|
308
|
-
logger: shouldReduceDebug ? undefined : logger,
|
|
309
|
-
logPrefix,
|
|
310
|
-
context: `tx:${name}`,
|
|
311
203
|
});
|
|
312
|
-
const expectedSeq = frame[6];
|
|
313
204
|
|
|
314
205
|
if (maxFrameBytes !== undefined && frame.length > maxFrameBytes) {
|
|
315
206
|
throw new Error(
|
|
@@ -317,18 +208,6 @@ export class ProtocolV2Session {
|
|
|
317
208
|
);
|
|
318
209
|
}
|
|
319
210
|
|
|
320
|
-
if (!shouldReduceDebug) {
|
|
321
|
-
logger?.debug?.(
|
|
322
|
-
`[${logPrefix}] TX payload name=${name}`,
|
|
323
|
-
sanitizeProtocolV2DebugPayload(data)
|
|
324
|
-
);
|
|
325
|
-
logger?.debug?.(
|
|
326
|
-
`[${logPrefix}] TX frame name=${name} len=${frame.length} router=${frame[4]} attr=${
|
|
327
|
-
frame[5]
|
|
328
|
-
} seq=${expectedSeq} headerHex=${frameHeaderDebugHex(frame)}`
|
|
329
|
-
);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
211
|
// Lenient watchdog on the write phase only — see
|
|
333
212
|
// PROTOCOL_V2_WRITE_WATCHDOG_TIMEOUT_MS for the rationale.
|
|
334
213
|
await withProtocolTimeout(
|
|
@@ -356,39 +235,9 @@ export class ProtocolV2Session {
|
|
|
356
235
|
// Timed out while waiting: drop the late frame and stop reading.
|
|
357
236
|
break;
|
|
358
237
|
}
|
|
359
|
-
if (!shouldReduceDebug) {
|
|
360
|
-
logger?.debug?.(
|
|
361
|
-
`[${logPrefix}] RX frame len=${rxFrame.length} router=${rxFrame[4]} attr=${
|
|
362
|
-
rxFrame[5]
|
|
363
|
-
} seq=${rxFrame[6]} headerHex=${frameHeaderDebugHex(rxFrame)}`
|
|
364
|
-
);
|
|
365
|
-
}
|
|
366
238
|
const isAck = ProtocolV2.isAckFrame(rxFrame);
|
|
367
|
-
if (isAck) {
|
|
368
|
-
if (!shouldReduceDebug) {
|
|
369
|
-
logger?.debug?.(`[${logPrefix}] skip Proto Link ACK seq=${rxFrame[6]}`);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
239
|
if (!isAck) {
|
|
373
|
-
const decoded = ProtocolV2.decodeFrame(schemas, rxFrame
|
|
374
|
-
logger: shouldReduceDebug ? undefined : logger,
|
|
375
|
-
logPrefix,
|
|
376
|
-
context: `rx:${name}`,
|
|
377
|
-
});
|
|
378
|
-
if (!shouldReduceDebug && decoded.seq !== expectedSeq) {
|
|
379
|
-
logger?.debug?.(
|
|
380
|
-
`[${logPrefix}] seq differs for ${name}: tx=${expectedSeq}, rx=${decoded.seq}`
|
|
381
|
-
);
|
|
382
|
-
}
|
|
383
|
-
if (!shouldReduceDebug) {
|
|
384
|
-
logger?.debug?.(
|
|
385
|
-
`[${logPrefix}] TX name=${name} seq=${expectedSeq} | RX seq=${decoded.seq} messageTypeId=${decoded.messageTypeId} pbPayload=${decoded.pbPayload.length}B`
|
|
386
|
-
);
|
|
387
|
-
logger?.debug?.(
|
|
388
|
-
`[${logPrefix}] RX payload type=${decoded.type} messageTypeId=${decoded.messageTypeId}`,
|
|
389
|
-
sanitizeProtocolV2DebugPayload(decoded.message)
|
|
390
|
-
);
|
|
391
|
-
}
|
|
240
|
+
const decoded = ProtocolV2.decodeFrame(schemas, rxFrame);
|
|
392
241
|
|
|
393
242
|
const response = check.call(decoded);
|
|
394
243
|
if (callOptions.intermediateTypes?.includes(response.type)) {
|
package/src/types/messages.ts
CHANGED
|
@@ -4637,6 +4637,19 @@ export type ProtocolInfo = {
|
|
|
4637
4637
|
protobuf_definition?: string;
|
|
4638
4638
|
};
|
|
4639
4639
|
|
|
4640
|
+
export enum DeviceErrorCode {
|
|
4641
|
+
DeviceError_None = 0,
|
|
4642
|
+
DeviceError_Busy = 1,
|
|
4643
|
+
DeviceError_NotInitialized = 2,
|
|
4644
|
+
DeviceError_ActionCancelled = 3,
|
|
4645
|
+
DeviceError_PinAlreadyUsed = 4,
|
|
4646
|
+
DeviceError_PersistFailed = 5,
|
|
4647
|
+
DeviceError_SeError = 6,
|
|
4648
|
+
DeviceError_InvalidLanguage = 7,
|
|
4649
|
+
DeviceError_WallpaperNotUsable = 8,
|
|
4650
|
+
DeviceError_DeviceLocked = 9,
|
|
4651
|
+
}
|
|
4652
|
+
|
|
4640
4653
|
export enum DeviceRebootType {
|
|
4641
4654
|
Normal = 0,
|
|
4642
4655
|
Romloader = 1,
|
|
@@ -4653,6 +4666,20 @@ export type DeviceSettings = {
|
|
|
4653
4666
|
label?: string;
|
|
4654
4667
|
bt_enable?: boolean;
|
|
4655
4668
|
language?: string;
|
|
4669
|
+
wallpaper_path?: string;
|
|
4670
|
+
passphrase_enable?: boolean;
|
|
4671
|
+
brightness?: number;
|
|
4672
|
+
autolock_delay_ms?: number;
|
|
4673
|
+
autoshutdown_delay_ms?: number;
|
|
4674
|
+
animation_enable?: boolean;
|
|
4675
|
+
tap_to_wake?: boolean;
|
|
4676
|
+
haptic_feedback?: boolean;
|
|
4677
|
+
device_name_display_enabled?: boolean;
|
|
4678
|
+
airgap_mode?: boolean;
|
|
4679
|
+
fido_enabled?: boolean;
|
|
4680
|
+
experimental_features?: boolean;
|
|
4681
|
+
usb_lock_enable?: boolean;
|
|
4682
|
+
random_keypad?: boolean;
|
|
4656
4683
|
};
|
|
4657
4684
|
|
|
4658
4685
|
// DeviceSettingsGet
|
|
@@ -4663,6 +4690,19 @@ export type DeviceSettingsSet = {
|
|
|
4663
4690
|
settings: DeviceSettings;
|
|
4664
4691
|
};
|
|
4665
4692
|
|
|
4693
|
+
export enum DeviceSettingsPage {
|
|
4694
|
+
DeviceReset = 0,
|
|
4695
|
+
DevicePinChange = 1,
|
|
4696
|
+
DevicePassphrase = 2,
|
|
4697
|
+
DeviceAirgap = 3,
|
|
4698
|
+
}
|
|
4699
|
+
|
|
4700
|
+
// DeviceSettingsPageShow
|
|
4701
|
+
export type DeviceSettingsPageShow = {
|
|
4702
|
+
page: DeviceSettingsPage;
|
|
4703
|
+
field_name?: string;
|
|
4704
|
+
};
|
|
4705
|
+
|
|
4666
4706
|
// DeviceCertificate
|
|
4667
4707
|
export type DeviceCertificate = {
|
|
4668
4708
|
cert_and_pubkey: string;
|
|
@@ -5632,6 +5672,7 @@ export type MessageType = {
|
|
|
5632
5672
|
DeviceSettings: DeviceSettings;
|
|
5633
5673
|
DeviceSettingsGet: DeviceSettingsGet;
|
|
5634
5674
|
DeviceSettingsSet: DeviceSettingsSet;
|
|
5675
|
+
DeviceSettingsPageShow: DeviceSettingsPageShow;
|
|
5635
5676
|
DeviceCertificate: DeviceCertificate;
|
|
5636
5677
|
DeviceCertificateWrite: DeviceCertificateWrite;
|
|
5637
5678
|
DeviceCertificateRead: DeviceCertificateRead;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export type ProtocolV2DebugLogger = {
|
|
2
|
-
debug?: (...args: unknown[]) => void;
|
|
3
|
-
};
|
|
4
|
-
export type ProtocolV2FrameDebugOptions = {
|
|
5
|
-
logger?: ProtocolV2DebugLogger;
|
|
6
|
-
logPrefix?: string;
|
|
7
|
-
context?: string;
|
|
8
|
-
messageName?: string;
|
|
9
|
-
messageTypeId?: number;
|
|
10
|
-
pbPayloadLength?: number;
|
|
11
|
-
};
|
|
12
|
-
export declare function logProtocolV2Debug(options: ProtocolV2FrameDebugOptions | undefined, stage: string, details: Record<string, unknown>): void;
|
|
13
|
-
//# sourceMappingURL=debug.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../../src/protocols/v2/debug.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IACxC,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,2BAA2B,GAAG,SAAS,EAChD,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QASjC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export type ProtocolV2DebugLogger = {
|
|
2
|
-
debug?: (...args: unknown[]) => void;
|
|
3
|
-
};
|
|
4
|
-
|
|
5
|
-
export type ProtocolV2FrameDebugOptions = {
|
|
6
|
-
logger?: ProtocolV2DebugLogger;
|
|
7
|
-
logPrefix?: string;
|
|
8
|
-
context?: string;
|
|
9
|
-
messageName?: string;
|
|
10
|
-
messageTypeId?: number;
|
|
11
|
-
pbPayloadLength?: number;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export function logProtocolV2Debug(
|
|
15
|
-
options: ProtocolV2FrameDebugOptions | undefined,
|
|
16
|
-
stage: string,
|
|
17
|
-
details: Record<string, unknown>
|
|
18
|
-
) {
|
|
19
|
-
options?.logger?.debug?.(`[${options.logPrefix ?? 'ProtocolV2'}] ${stage}`, {
|
|
20
|
-
...(options.context ? { context: options.context } : {}),
|
|
21
|
-
...(options.messageName ? { messageName: options.messageName } : {}),
|
|
22
|
-
...(options.messageTypeId !== undefined ? { messageTypeId: options.messageTypeId } : {}),
|
|
23
|
-
...(options.pbPayloadLength !== undefined ? { pbPayloadLength: options.pbPayloadLength } : {}),
|
|
24
|
-
...details,
|
|
25
|
-
});
|
|
26
|
-
}
|