@onekeyfe/hd-transport 1.2.0-alpha.11 → 1.2.0-alpha.13
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__/messages.test.js +21 -9
- package/__tests__/protocol-v2.test.js +100 -27
- package/dist/index.d.ts +83 -47
- package/dist/index.js +82 -174
- package/dist/protocols/index.d.ts +8 -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 +49 -7
- package/dist/types/messages.d.ts.map +1 -1
- package/messages-protocol-v2.json +422 -16
- package/package.json +3 -3
- package/scripts/protobuf-build.sh +20 -232
- package/scripts/protobuf-types.js +9 -0
- package/src/protocols/index.ts +15 -38
- 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 +19 -147
- package/src/types/messages.ts +50 -7
- 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
|
@@ -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,8 @@ 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
|
|
204
|
+
const txMetadata = ProtocolV2.inspectFrame(schemas, frame);
|
|
313
205
|
|
|
314
206
|
if (maxFrameBytes !== undefined && frame.length > maxFrameBytes) {
|
|
315
207
|
throw new Error(
|
|
@@ -318,15 +210,13 @@ export class ProtocolV2Session {
|
|
|
318
210
|
}
|
|
319
211
|
|
|
320
212
|
if (!shouldReduceDebug) {
|
|
321
|
-
logger?.debug?.(
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
} seq=${expectedSeq} headerHex=${frameHeaderDebugHex(frame)}`
|
|
329
|
-
);
|
|
213
|
+
logger?.debug?.(`[${logPrefix}] TX`, {
|
|
214
|
+
method: name,
|
|
215
|
+
type: name,
|
|
216
|
+
typeId: txMetadata.messageTypeId,
|
|
217
|
+
seq: txMetadata.seq,
|
|
218
|
+
bytes: frame.length,
|
|
219
|
+
});
|
|
330
220
|
}
|
|
331
221
|
|
|
332
222
|
// Lenient watchdog on the write phase only — see
|
|
@@ -356,40 +246,22 @@ export class ProtocolV2Session {
|
|
|
356
246
|
// Timed out while waiting: drop the late frame and stop reading.
|
|
357
247
|
break;
|
|
358
248
|
}
|
|
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
249
|
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
250
|
if (!isAck) {
|
|
373
|
-
const
|
|
374
|
-
|
|
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
|
-
}
|
|
251
|
+
const rxMetadata = ProtocolV2.inspectFrame(schemas, rxFrame);
|
|
252
|
+
|
|
383
253
|
if (!shouldReduceDebug) {
|
|
384
|
-
logger?.debug?.(
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
);
|
|
254
|
+
logger?.debug?.(`[${logPrefix}] RX`, {
|
|
255
|
+
method: name,
|
|
256
|
+
type: rxMetadata.type,
|
|
257
|
+
typeId: rxMetadata.messageTypeId,
|
|
258
|
+
seq: rxMetadata.seq,
|
|
259
|
+
bytes: rxFrame.length,
|
|
260
|
+
});
|
|
391
261
|
}
|
|
392
262
|
|
|
263
|
+
const decoded = ProtocolV2.decodeFrame(schemas, rxFrame);
|
|
264
|
+
|
|
393
265
|
const response = check.call(decoded);
|
|
394
266
|
if (callOptions.intermediateTypes?.includes(response.type)) {
|
|
395
267
|
callOptions.onIntermediateResponse?.(response);
|
package/src/types/messages.ts
CHANGED
|
@@ -2412,6 +2412,19 @@ export type Features = {
|
|
|
2412
2412
|
onekey_se04_state?: string | null;
|
|
2413
2413
|
attach_to_pin_user?: boolean;
|
|
2414
2414
|
unlocked_attach_pin?: boolean;
|
|
2415
|
+
coprocessor_bt_name?: string;
|
|
2416
|
+
coprocessor_version?: string;
|
|
2417
|
+
coprocessor_bt_enable?: boolean;
|
|
2418
|
+
romloader_version?: string;
|
|
2419
|
+
onekey_romloader_version?: string;
|
|
2420
|
+
onekey_romloader_hash?: string;
|
|
2421
|
+
onekey_bootloader_version?: string;
|
|
2422
|
+
onekey_bootloader_hash?: string;
|
|
2423
|
+
onekey_bootloader_build_id?: string;
|
|
2424
|
+
onekey_coprocessor_bt_name?: string;
|
|
2425
|
+
onekey_coprocessor_version?: string;
|
|
2426
|
+
onekey_coprocessor_build_id?: string;
|
|
2427
|
+
onekey_coprocessor_hash?: string;
|
|
2415
2428
|
};
|
|
2416
2429
|
|
|
2417
2430
|
// OnekeyFeatures
|
|
@@ -4607,6 +4620,9 @@ export type ViewRawData = {
|
|
|
4607
4620
|
export enum ViewSignLayout {
|
|
4608
4621
|
LayoutDefault = 0,
|
|
4609
4622
|
LayoutSafeTxCreate = 1,
|
|
4623
|
+
LayoutFinalConfirm = 2,
|
|
4624
|
+
Layout7702 = 3,
|
|
4625
|
+
LayoutFlat = 4,
|
|
4610
4626
|
}
|
|
4611
4627
|
|
|
4612
4628
|
// ViewSignPage
|
|
@@ -4948,12 +4964,9 @@ export type DeviceSession = {
|
|
|
4948
4964
|
// DeviceSessionAskPin
|
|
4949
4965
|
export type DeviceSessionAskPin = {};
|
|
4950
4966
|
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
unlocked_attach_pin?: boolean;
|
|
4955
|
-
passphrase_protection?: boolean;
|
|
4956
|
-
};
|
|
4967
|
+
export enum DeviceSessionAskPin_FailureSubCodes {
|
|
4968
|
+
UserCancel = 1,
|
|
4969
|
+
}
|
|
4957
4970
|
|
|
4958
4971
|
// DeviceStatus
|
|
4959
4972
|
export type DeviceStatus = {
|
|
@@ -5082,6 +5095,37 @@ export type FilesystemFormat = {
|
|
|
5082
5095
|
// PortfolioUpdate
|
|
5083
5096
|
export type PortfolioUpdate = {};
|
|
5084
5097
|
|
|
5098
|
+
export enum ProtocolV2FailureType {
|
|
5099
|
+
Failure_InvalidMessage = 1,
|
|
5100
|
+
Failure_UndefinedError = 2,
|
|
5101
|
+
Failure_UsageError = 3,
|
|
5102
|
+
Failure_DataError = 4,
|
|
5103
|
+
Failure_ProcessError = 5,
|
|
5104
|
+
}
|
|
5105
|
+
|
|
5106
|
+
export enum Enum_ProtocolV2Capability {
|
|
5107
|
+
Capability_Bitcoin = 1,
|
|
5108
|
+
Capability_Bitcoin_like = 2,
|
|
5109
|
+
Capability_Binance = 3,
|
|
5110
|
+
Capability_Cardano = 4,
|
|
5111
|
+
Capability_Crypto = 5,
|
|
5112
|
+
Capability_EOS = 6,
|
|
5113
|
+
Capability_Ethereum = 7,
|
|
5114
|
+
Capability_Lisk = 8,
|
|
5115
|
+
Capability_Monero = 9,
|
|
5116
|
+
Capability_NEM = 10,
|
|
5117
|
+
Capability_Ripple = 11,
|
|
5118
|
+
Capability_Stellar = 12,
|
|
5119
|
+
Capability_Tezos = 13,
|
|
5120
|
+
Capability_U2F = 14,
|
|
5121
|
+
Capability_Shamir = 15,
|
|
5122
|
+
Capability_ShamirGroups = 16,
|
|
5123
|
+
Capability_PassphraseEntry = 17,
|
|
5124
|
+
Capability_AttachToPin = 18,
|
|
5125
|
+
Capability_EthereumTypedData = 1000,
|
|
5126
|
+
}
|
|
5127
|
+
export type ProtocolV2Capability = keyof typeof Enum_ProtocolV2Capability;
|
|
5128
|
+
|
|
5085
5129
|
// custom connect definitions
|
|
5086
5130
|
export type MessageType = {
|
|
5087
5131
|
AlephiumGetAddress: AlephiumGetAddress;
|
|
@@ -5701,7 +5745,6 @@ export type MessageType = {
|
|
|
5701
5745
|
DeviceSessionGet: DeviceSessionGet;
|
|
5702
5746
|
DeviceSession: DeviceSession;
|
|
5703
5747
|
DeviceSessionAskPin: DeviceSessionAskPin;
|
|
5704
|
-
DeviceSessionPinResult: DeviceSessionPinResult;
|
|
5705
5748
|
DeviceStatus: DeviceStatus;
|
|
5706
5749
|
DeviceStatusGet: DeviceStatusGet;
|
|
5707
5750
|
DevGetOnboardingStatus: DevGetOnboardingStatus;
|
|
@@ -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
|
-
}
|