@onekeyfe/hd-transport-web-device 1.2.0-alpha.2 → 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.
@@ -1,4 +1,5 @@
1
1
  import transport, { PROTOCOL_V2_CHANNEL_BLE_UART, bytesToHex } from '@onekeyfe/hd-transport';
2
+ import { HardwareErrorCode } from '@onekeyfe/hd-shared';
2
3
 
3
4
  import ElectronBleTransport from '../src/electron-ble-transport';
4
5
 
@@ -28,21 +29,25 @@ const protocolV1Schema = {
28
29
 
29
30
  const protocolV2Schema = {
30
31
  nested: {
31
- GetProtoVersion: {
32
+ ProtocolInfoRequest: {
32
33
  fields: {},
33
34
  },
34
- ProtoVersion: {
35
+ ProtocolInfo: {
35
36
  fields: {
36
- major_version: {
37
+ version: {
37
38
  type: 'uint32',
38
39
  id: 1,
39
40
  },
40
- minor_version: {
41
+ supported_messages: {
42
+ rule: 'repeated',
41
43
  type: 'uint32',
42
44
  id: 2,
45
+ options: {
46
+ packed: false,
47
+ },
43
48
  },
44
- patch_version: {
45
- type: 'uint32',
49
+ protobuf_definition: {
50
+ type: 'string',
46
51
  id: 3,
47
52
  },
48
53
  },
@@ -65,8 +70,8 @@ const protocolV2Schema = {
65
70
  },
66
71
  MessageType: {
67
72
  values: {
68
- MessageType_GetProtoVersion: 60200,
69
- MessageType_ProtoVersion: 60201,
73
+ MessageType_ProtocolInfoRequest: 60200,
74
+ MessageType_ProtocolInfo: 60201,
70
75
  MessageType_Ping: 60206,
71
76
  MessageType_Success: 60207,
72
77
  },
@@ -241,6 +246,95 @@ describe('ElectronBleTransport protocol detection', () => {
241
246
  );
242
247
  expect(nobleBle.write).toHaveBeenCalledTimes(1);
243
248
  expect(transport.getProtocolType(device.id)).toBe('V2');
249
+ await expect(transport.call(device.id, 'Ping', { message: 'after-probe' })).resolves.toEqual({
250
+ type: 'Success',
251
+ message: { message: 'ok' },
252
+ });
253
+ const sentSeqs = nobleBle.write.mock.calls.map(([, hex]) =>
254
+ Number.parseInt(hex.slice(12, 14), 16)
255
+ );
256
+ expect(sentSeqs).toEqual([1, 2]);
257
+ } finally {
258
+ await transport.release(device.id);
259
+ }
260
+ });
261
+
262
+ test('rejects the active Protocol V2 reader when pairing is rejected', async () => {
263
+ const device = { id: 'pairing-rejected-pro2-id', name: 'OneKey Pro 2' };
264
+ const nobleBle = createNobleBle(device);
265
+ let notificationHandler: ((deviceId: string, data: string) => void) | undefined;
266
+ let pairingRejected = false;
267
+ const probeResponse = ProtocolV2.encodeFrame(
268
+ schemas,
269
+ 'Success',
270
+ { message: 'ok' },
271
+ { router: PROTOCOL_V2_CHANNEL_BLE_UART }
272
+ );
273
+
274
+ nobleBle.onNotification.mockImplementation(handler => {
275
+ notificationHandler = handler;
276
+ return jest.fn();
277
+ });
278
+ nobleBle.write.mockImplementation(() => {
279
+ setTimeout(
280
+ () =>
281
+ notificationHandler?.(
282
+ device.id,
283
+ pairingRejected ? 'PAIRING_REJECTED' : bytesToHex(probeResponse)
284
+ ),
285
+ 0
286
+ );
287
+ return Promise.resolve();
288
+ });
289
+ const transport = configureTransport(nobleBle);
290
+
291
+ try {
292
+ await transport.acquire({ uuid: device.id });
293
+ pairingRejected = true;
294
+
295
+ await expect(
296
+ transport.call(device.id, 'Ping', { message: 'pairing' }, { timeoutMs: 50 })
297
+ ).rejects.toMatchObject({ errorCode: HardwareErrorCode.BleDeviceBondedCanceled });
298
+ } finally {
299
+ await transport.release(device.id);
300
+ }
301
+ });
302
+
303
+ test('rebuilds the active link when Core acquires the same device again', async () => {
304
+ const device = { id: 'repeated-acquire-pro2-id', name: 'OneKey Pro 2' };
305
+ const nobleBle = createNobleBle(device);
306
+ let notificationHandler: ((deviceId: string, data: string) => void) | undefined;
307
+ const response = ProtocolV2.encodeFrame(
308
+ schemas,
309
+ 'Success',
310
+ { message: 'ok' },
311
+ { router: PROTOCOL_V2_CHANNEL_BLE_UART }
312
+ );
313
+
314
+ nobleBle.onNotification.mockImplementation(handler => {
315
+ notificationHandler = handler;
316
+ return jest.fn();
317
+ });
318
+ nobleBle.write.mockImplementation(() => {
319
+ setTimeout(() => notificationHandler?.(device.id, bytesToHex(response)), 0);
320
+ return Promise.resolve();
321
+ });
322
+ const transport = configureTransport(nobleBle);
323
+
324
+ try {
325
+ await transport.acquire({ uuid: device.id });
326
+ await transport.acquire({ uuid: device.id, expectedProtocol: 'V2' });
327
+ await expect(
328
+ transport.call(device.id, 'Ping', { message: 'after-reacquire' })
329
+ ).resolves.toEqual({
330
+ type: 'Success',
331
+ message: { message: 'ok' },
332
+ });
333
+
334
+ const sentSeqs = nobleBle.write.mock.calls.map(([, hex]) =>
335
+ Number.parseInt(hex.slice(12, 14), 16)
336
+ );
337
+ expect(sentSeqs).toEqual([1, 2]);
244
338
  } finally {
245
339
  await transport.release(device.id);
246
340
  }
@@ -0,0 +1,63 @@
1
+ import transport, { ProtocolV2FrameAssembler } from '@onekeyfe/hd-transport';
2
+
3
+ import WebUsbTransport from '../src/webusb';
4
+
5
+ const schema = {
6
+ nested: {
7
+ Ping: { fields: { message: { type: 'string', id: 1 } } },
8
+ Success: { fields: { message: { type: 'string', id: 1 } } },
9
+ MessageType: {
10
+ values: {
11
+ MessageType_Ping: 60206,
12
+ MessageType_Success: 60207,
13
+ },
14
+ },
15
+ },
16
+ };
17
+
18
+ describe('WebUsbTransport Protocol V2 timeout recovery', () => {
19
+ test('resets the connection between a failed V1 probe and the V2 probe', async () => {
20
+ const webusb = new WebUsbTransport() as any;
21
+ const path = 'pro2-webusb';
22
+ const events: string[] = [];
23
+ webusb.probeProtocolV1 = jest.fn().mockImplementation(() => {
24
+ events.push('probe-v1');
25
+ return Promise.resolve(false);
26
+ });
27
+ webusb.resetConnectionAfterProbe = jest.fn().mockImplementation(() => {
28
+ events.push('reset');
29
+ return Promise.resolve();
30
+ });
31
+ webusb.probeProtocolV2 = jest.fn().mockImplementation(() => {
32
+ events.push('probe-v2');
33
+ return Promise.resolve(true);
34
+ });
35
+
36
+ await expect(webusb.detectProtocol(path)).resolves.toBe('V2');
37
+
38
+ expect(events).toEqual(['probe-v1', 'reset', 'probe-v2']);
39
+ expect(webusb.deviceProtocol.get(path)).toBe('V2');
40
+ });
41
+
42
+ test('invalidates and resets the cached connection before another call can start', async () => {
43
+ const webusb = new WebUsbTransport() as any;
44
+ const path = 'pro2-webusb';
45
+ webusb.messages = transport.parseConfigure(schema);
46
+ webusb.messagesV2 = transport.parseConfigure(schema);
47
+ webusb.protocolV2Assemblers.set(path, new ProtocolV2FrameAssembler());
48
+ webusb.transferOutOnce = jest.fn().mockResolvedValue(undefined);
49
+ webusb.receiveProtocolV2Frame = jest.fn(() => new Promise<void>(() => {}));
50
+ webusb.resetConnectionAfterProbe = jest.fn().mockImplementation(() => {
51
+ webusb.protocolV2Sessions.delete(path);
52
+ webusb.protocolV2ReadTimeouts.delete(path);
53
+ webusb.protocolV2Assemblers.get(path)?.reset();
54
+ });
55
+
56
+ await expect(
57
+ webusb.callProtocolV2(path, 'Ping', { message: 'timeout' }, { timeoutMs: 10 })
58
+ ).rejects.toThrow('timeout');
59
+
60
+ expect(webusb.resetConnectionAfterProbe).toHaveBeenCalledWith(path);
61
+ expect(webusb.protocolV2Sessions.has(path)).toBe(false);
62
+ });
63
+ });
@@ -28,8 +28,7 @@ export default class ElectronBleTransport {
28
28
  private v2Assemblers;
29
29
  private v2FrameQueues;
30
30
  private v2FramePromises;
31
- private activeProtocolV2Call;
32
- private nextProtocolV2CallToken;
31
+ private protocolV2Links;
33
32
  private notificationCleanups;
34
33
  private disconnectCleanups;
35
34
  private notificationTokens;
@@ -62,19 +61,20 @@ export default class ElectronBleTransport {
62
61
  private probeProtocolV1;
63
62
  private probeProtocolV2;
64
63
  private writeWithChunking;
65
- private writeWithRetry;
64
+ private writeOnce;
66
65
  private handleNotification;
67
66
  private handleProtocolV2Notification;
68
67
  private getProtocolV2FrameQueue;
69
68
  private resolveProtocolV2Frame;
70
69
  private rejectAllProtocolV2Frames;
71
70
  private resetProtocolV2Frames;
72
- private isActiveProtocolV2Call;
71
+ private rejectProtocolV2Frames;
73
72
  private readProtocolV2Frame;
74
73
  private handleProtocolV1Notification;
75
74
  call(uuid: string, name: string, data: Record<string, unknown>, options?: TransportCallOptions): Promise<import("@onekeyfe/hd-transport").MessageFromOneKey>;
76
75
  private callProtocolV1;
77
76
  private callProtocolV2;
77
+ private createProtocolV2Adapter;
78
78
  private processProtocolV1Notification;
79
79
  getProtocolType(path: string): ProtocolType | undefined;
80
80
  }
@@ -1 +1 @@
1
- {"version":3,"file":"electron-ble-transport.d.ts","sourceRoot":"","sources":["../src/electron-ble-transport.ts"],"names":[],"mappings":";AAmBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnG,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AAevC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,UAAU,CAAC,EAAE,UAAU,CAAC;KACzB;CACF;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,gBAAgB,CAAC,EAAE,YAAY,CAAC;CACjC,CAAC;AAuCF,MAAM,CAAC,OAAO,OAAO,oBAAoB;IACvC,OAAO,CAAC,SAAS,CAA0D;IAE3E,OAAO,CAAC,WAAW,CAA0D;IAE7E,IAAI,SAA0B;IAE9B,UAAU,UAAS;IAEnB,UAAU,EAAE,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,GAAG,IAAI,CAAQ;IAExD,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,OAAO,CAAC,EAAE,YAAY,CAAC;IAEvB,OAAO,CAAC,gBAAgB,CAA0B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,cAAc;IA6B5B,OAAO,CAAC,uBAAuB;IA0C/B,OAAO,CAAC,6BAA6B;IAsCrC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
package/dist/index.d.ts CHANGED
@@ -4,6 +4,9 @@ import { Deferred } from '@onekeyfe/hd-shared';
4
4
  import { DesktopAPI } from '@onekeyfe/hd-transport-electron';
5
5
  import EventEmitter from 'events';
6
6
 
7
+ /**
8
+ * Device information with path and WebUSB device instance
9
+ */
7
10
  interface DeviceInfo extends OneKeyDeviceInfoBase {
8
11
  path: string;
9
12
  device: USBDevice;
@@ -11,13 +14,25 @@ interface DeviceInfo extends OneKeyDeviceInfoBase {
11
14
  }
12
15
  declare class WebUsbTransport {
13
16
  messages: ReturnType<typeof _onekeyfe_hd_transport__default.parseConfigure> | undefined;
17
+ /** Protobuf schema for Protocol V2 transports. */
14
18
  messagesV2: ReturnType<typeof _onekeyfe_hd_transport__default.parseConfigure> | undefined;
19
+ /** Per-path protocol type detected by active wire-level probe. */
15
20
  private deviceProtocol;
16
21
  private deviceProtocolHints;
22
+ /** Per-device Protocol V2 assembler that retains extra frames from one read. */
17
23
  private protocolV2Assemblers;
24
+ /** Per-device Protocol V2 session that keeps sequence numbers monotonic. */
18
25
  private protocolV2Sessions;
26
+ /** Sequence cursors survive ordinary reconnects and cached session rebuilds. */
27
+ private protocolV2Sequences;
28
+ /** Read timeout for the current Protocol V2 call, consumed by cached readFrame. */
19
29
  private protocolV2ReadTimeouts;
30
+ /** Per-path USB endpoint / interface numbers (discovered from USB descriptors) */
20
31
  private deviceEndpoints;
32
+ /**
33
+ * Early Pro2 boards have no USB serial number. Assign a session-stable mock path per
34
+ * USBDevice instance so discovery retains them; reconnecting creates a new instance/path.
35
+ */
21
36
  private mockSerialPaths;
22
37
  private mockSerialCounter;
23
38
  name: string;
@@ -25,24 +40,75 @@ declare class WebUsbTransport {
25
40
  configured: boolean;
26
41
  Log?: any;
27
42
  usb?: USB;
43
+ /**
44
+ * Cached list of connected devices
45
+ * This is essential for maintaining device references between operations
46
+ */
28
47
  deviceList: Array<DeviceInfo>;
29
48
  configurationId: number;
30
49
  endpointId: number;
31
50
  interfaceId: number;
51
+ /**
52
+ * Initialize WebUSB transport
53
+ */
32
54
  init(logger: any): void;
55
+ /**
56
+ * Configure Protocol V1 protobuf schema (legacy chunked 0x3F framing).
57
+ */
33
58
  configure(signedData: any): void;
59
+ /**
60
+ * Cache the Protocol V2 protobuf schema.
61
+ */
34
62
  configureProtocolV2(signedData: any): void;
63
+ /**
64
+ * Request user to select a device
65
+ * This method must be called in response to a user action
66
+ * to comply with WebUSB security requirements
67
+ */
35
68
  promptDeviceAccess(): Promise<USBDevice | null>;
69
+ /**
70
+ * Enumerate already connected devices
71
+ * This method only returns devices that are already authorized by the browser
72
+ * It does NOT prompt the user to select a device
73
+ */
36
74
  enumerate(): Promise<DeviceInfo[]>;
75
+ /**
76
+ * Use the USB serial as the device path, falling back to a session-stable mock path.
77
+ */
37
78
  private getDevicePath;
79
+ /**
80
+ * Get list of connected devices
81
+ */
38
82
  getConnectedDevices(): Promise<DeviceInfo[]>;
83
+ /**
84
+ * Acquire device control
85
+ */
39
86
  acquire(input: AcquireInput): Promise<string | undefined>;
87
+ /**
88
+ * Determine protocol type after connect.
89
+ * Probe Protocol V1 first with Initialize. If it does not answer in time,
90
+ * fall back to a Protocol V2 Ping probe.
91
+ */
40
92
  private createProtocolMismatchError;
41
93
  private createProtocolDetectionError;
42
94
  private detectProtocol;
95
+ /**
96
+ * Find device by path
97
+ */
43
98
  findDevice(path: string): Promise<USBDevice>;
99
+ /**
100
+ * Connect to device with retry mechanism
101
+ */
44
102
  connect(path: string, first: boolean): Promise<void>;
103
+ /**
104
+ * Discover vendor-class (0xFF) interface and its IN/OUT endpoint numbers from USB descriptors.
105
+ * Falls back to legacy hardcoded values if no vendor interface is found.
106
+ */
45
107
  private discoverEndpoints;
108
+ /**
109
+ * Connect to specific device.
110
+ * Discovers interface/endpoint numbers from USB descriptors on first connection.
111
+ */
46
112
  connectToDevice(path: string, first: boolean): Promise<void>;
47
113
  private closeOpenDevice;
48
114
  private clearEndpointHalt;
@@ -53,17 +119,37 @@ declare class WebUsbTransport {
53
119
  private getTransferInData;
54
120
  private toArrayBuffer;
55
121
  private transferOutWithRetry;
122
+ private transferOutOnce;
56
123
  private transferInWithRetry;
57
124
  private resetConnectionAfterProbe;
58
125
  private withProtocolReadTimeout;
59
126
  private probeProtocolV1;
60
127
  private probeProtocolV2;
128
+ /**
129
+ * Call device method — branches to Protocol V1 or Protocol V2 based on active probe.
130
+ */
61
131
  call(path: string, name: string, data: Record<string, unknown>, options?: TransportCallOptions): Promise<_onekeyfe_hd_transport.MessageFromOneKey>;
62
132
  private callProtocolV1;
133
+ /**
134
+ * Send/receive a single call over Protocol V2 (0x5A framing).
135
+ *
136
+ * Encoding: protobuf message → 2-byte LE messageTypeId + pb bytes → Protocol V2 frame
137
+ * Decoding: Protocol V2 frame → messageTypeId + pb bytes → protobuf message
138
+ */
63
139
  private callProtocolV2;
64
140
  private receiveProtocolV2Frame;
141
+ /**
142
+ * Receive data from device
143
+ */
65
144
  receiveData(path: string, timeoutMs?: number): Promise<string>;
145
+ /**
146
+ * Release device
147
+ */
66
148
  release(path: string): Promise<void>;
149
+ /**
150
+ * Expose the detected protocol type for a given device path.
151
+ * Used by upper layers (e.g. TransportManager) to select the correct schema.
152
+ */
67
153
  getProtocolType(path: string): ProtocolType | undefined;
68
154
  }
69
155
 
@@ -77,6 +163,12 @@ type BleAcquireInput = {
77
163
  forceCleanRunPromise?: boolean;
78
164
  expectedProtocol?: ProtocolType;
79
165
  };
166
+ /**
167
+ * Desktop Electron BLE transport with automatic Protocol V1/V2 detection.
168
+ *
169
+ * Protocol V1 devices continue using chunked packets. Protocol V2 is detected
170
+ * after a Protocol V1 Initialize timeout by probing Protocol V2 Ping.
171
+ */
80
172
  declare class ElectronBleTransport {
81
173
  private _messages;
82
174
  private _messagesV2;
@@ -92,8 +184,7 @@ declare class ElectronBleTransport {
92
184
  private v2Assemblers;
93
185
  private v2FrameQueues;
94
186
  private v2FramePromises;
95
- private activeProtocolV2Call;
96
- private nextProtocolV2CallToken;
187
+ private protocolV2Links;
97
188
  private notificationCleanups;
98
189
  private disconnectCleanups;
99
190
  private notificationTokens;
@@ -126,19 +217,20 @@ declare class ElectronBleTransport {
126
217
  private probeProtocolV1;
127
218
  private probeProtocolV2;
128
219
  private writeWithChunking;
129
- private writeWithRetry;
220
+ private writeOnce;
130
221
  private handleNotification;
131
222
  private handleProtocolV2Notification;
132
223
  private getProtocolV2FrameQueue;
133
224
  private resolveProtocolV2Frame;
134
225
  private rejectAllProtocolV2Frames;
135
226
  private resetProtocolV2Frames;
136
- private isActiveProtocolV2Call;
227
+ private rejectProtocolV2Frames;
137
228
  private readProtocolV2Frame;
138
229
  private handleProtocolV1Notification;
139
230
  call(uuid: string, name: string, data: Record<string, unknown>, options?: TransportCallOptions): Promise<_onekeyfe_hd_transport.MessageFromOneKey>;
140
231
  private callProtocolV1;
141
232
  private callProtocolV2;
233
+ private createProtocolV2Adapter;
142
234
  private processProtocolV1Notification;
143
235
  getProtocolType(path: string): ProtocolType | undefined;
144
236
  }