@onekeyfe/hd-transport-web-device 1.2.0-alpha.3 → 1.2.0-alpha.30

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.
@@ -16,6 +16,7 @@ export type BleAcquireInput = {
16
16
  export default class ElectronBleTransport {
17
17
  private _messages;
18
18
  private _messagesV2;
19
+ private protocolV2SchemaConfiguration;
19
20
  name: string;
20
21
  configured: boolean;
21
22
  runPromise: Deferred<Uint8Array | string> | null;
@@ -28,8 +29,7 @@ export default class ElectronBleTransport {
28
29
  private v2Assemblers;
29
30
  private v2FrameQueues;
30
31
  private v2FramePromises;
31
- private activeProtocolV2Call;
32
- private nextProtocolV2CallToken;
32
+ private protocolV2Links;
33
33
  private notificationCleanups;
34
34
  private disconnectCleanups;
35
35
  private notificationTokens;
@@ -61,20 +61,21 @@ export default class ElectronBleTransport {
61
61
  private resetProbeStateAfterProtocolProbe;
62
62
  private probeProtocolV1;
63
63
  private probeProtocolV2;
64
- private writeWithChunking;
65
- private writeWithRetry;
64
+ private writeOnce;
65
+ private writeProtocolV2Frame;
66
66
  private handleNotification;
67
67
  private handleProtocolV2Notification;
68
68
  private getProtocolV2FrameQueue;
69
69
  private resolveProtocolV2Frame;
70
70
  private rejectAllProtocolV2Frames;
71
71
  private resetProtocolV2Frames;
72
- private isActiveProtocolV2Call;
72
+ private rejectProtocolV2Frames;
73
73
  private readProtocolV2Frame;
74
74
  private handleProtocolV1Notification;
75
75
  call(uuid: string, name: string, data: Record<string, unknown>, options?: TransportCallOptions): Promise<import("@onekeyfe/hd-transport").MessageFromOneKey>;
76
76
  private callProtocolV1;
77
77
  private callProtocolV2;
78
+ private createProtocolV2Adapter;
78
79
  private processProtocolV1Notification;
79
80
  getProtocolType(path: string): ProtocolType | undefined;
80
81
  }
@@ -1 +1 @@
1
- {"version":3,"file":"electron-ble-transport.d.ts","sourceRoot":"","sources":["../src/electron-ble-transport.ts"],"names":[],"mappings":";AAmBA,OAAO,KA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AAS,CAAC,UAAU,EAAE,GAAG;IAKzB,mBAAmB,CAAC,UAAU,EAAE,GAAG;IAgB7B,MAAM;IAIN,SAAS,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAqBxC,OAAO,CAAC,KAAK,EAAE,eAAe;;;;;;;;;;;IAoF9B,OAAO,CAAC,EAAE,EAAE,MAAM;IAgBxB,OAAO,CAAC,2BAA2B;IAOnC,OAAO,CAAC,4BAA4B;IAOpC,OAAO,CAAC,kBAAkB;YAMZ,cAAc;IA+C5B,OAAO,CAAC,8BAA8B;YAgBxB,iCAAiC;YAqCjC,eAAe;YAgBf,eAAe;YAuBf,SAAS;IASvB,OAAO,CAAC,oBAAoB;IAmB5B,OAAO,CAAC,kBAAkB;IAwB1B,OAAO,CAAC,4BAA4B;IAkBpC,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,yBAAyB;IAQjC,OAAO,CAAC,qBAAqB;IAK7B,OAAO,CAAC,sBAAsB;YAShB,mBAAmB;IAiBjC,OAAO,CAAC,4BAA4B;IAgB9B,IAAI,CACR,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,oBAAoB;YA2BlB,cAAc;YAuEd,cAAc;IA0B5B,OAAO,CAAC,uBAAuB;IAyC/B,OAAO,CAAC,6BAA6B;IAsCrC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
package/dist/index.d.ts CHANGED
@@ -1,23 +1,31 @@
1
1
  import * as _onekeyfe_hd_transport from '@onekeyfe/hd-transport';
2
- import _onekeyfe_hd_transport__default, { AcquireInput, TransportCallOptions, ProtocolType, OneKeyDeviceInfoBase, OneKeyDeviceInfo } from '@onekeyfe/hd-transport';
2
+ import _onekeyfe_hd_transport__default, { ProtocolV2UsbTransportBase, AcquireInput, TransportCallOptions, ProtocolV2Schemas, ProtocolV2CallContext, ProtocolType, OneKeyDeviceInfoBase, OneKeyDeviceInfo } from '@onekeyfe/hd-transport';
3
3
  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;
10
13
  protocolType?: ProtocolType;
11
14
  }
12
- declare class WebUsbTransport {
15
+ declare class WebUsbTransport extends ProtocolV2UsbTransportBase<string> {
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
+ private protocolV2SchemaSource;
20
+ /** Per-path protocol type detected by active wire-level probe. */
15
21
  private deviceProtocol;
16
22
  private deviceProtocolHints;
17
- private protocolV2Assemblers;
18
- private protocolV2Sessions;
19
- private protocolV2ReadTimeouts;
23
+ /** Per-path USB endpoint / interface numbers (discovered from USB descriptors) */
20
24
  private deviceEndpoints;
25
+ /**
26
+ * Early Pro2 boards have no USB serial number. Assign a session-stable mock path per
27
+ * USBDevice instance so discovery retains them; reconnecting creates a new instance/path.
28
+ */
21
29
  private mockSerialPaths;
22
30
  private mockSerialCounter;
23
31
  name: string;
@@ -25,24 +33,77 @@ declare class WebUsbTransport {
25
33
  configured: boolean;
26
34
  Log?: any;
27
35
  usb?: USB;
36
+ /**
37
+ * Cached list of connected devices
38
+ * This is essential for maintaining device references between operations
39
+ */
28
40
  deviceList: Array<DeviceInfo>;
29
41
  configurationId: number;
30
42
  endpointId: number;
31
43
  interfaceId: number;
44
+ constructor();
45
+ /**
46
+ * Initialize WebUSB transport
47
+ */
32
48
  init(logger: any): void;
49
+ /**
50
+ * Configure Protocol V1 protobuf schema (legacy chunked 0x3F framing).
51
+ */
33
52
  configure(signedData: any): void;
53
+ /**
54
+ * Cache the Protocol V2 protobuf schema.
55
+ */
34
56
  configureProtocolV2(signedData: any): void;
57
+ /**
58
+ * Request user to select a device
59
+ * This method must be called in response to a user action
60
+ * to comply with WebUSB security requirements
61
+ */
35
62
  promptDeviceAccess(): Promise<USBDevice | null>;
63
+ /**
64
+ * Enumerate already connected devices
65
+ * This method only returns devices that are already authorized by the browser
66
+ * It does NOT prompt the user to select a device
67
+ */
36
68
  enumerate(): Promise<DeviceInfo[]>;
69
+ /**
70
+ * Use the USB serial as the device path, falling back to a session-stable mock path.
71
+ */
37
72
  private getDevicePath;
73
+ /**
74
+ * Get list of connected devices
75
+ */
38
76
  getConnectedDevices(): Promise<DeviceInfo[]>;
77
+ /**
78
+ * Acquire device control
79
+ */
39
80
  acquire(input: AcquireInput): Promise<string | undefined>;
81
+ /**
82
+ * Determine protocol type after connect.
83
+ * Probe Protocol V1 first with Initialize. If it does not answer in time,
84
+ * fall back to a Protocol V2 Ping probe.
85
+ */
40
86
  private createProtocolMismatchError;
87
+ private createProtocolProbeTimeoutError;
41
88
  private createProtocolDetectionError;
42
89
  private detectProtocol;
90
+ /**
91
+ * Find device by path
92
+ */
43
93
  findDevice(path: string): Promise<USBDevice>;
94
+ /**
95
+ * Connect to device with retry mechanism
96
+ */
44
97
  connect(path: string, first: boolean): Promise<void>;
98
+ /**
99
+ * Discover vendor-class (0xFF) interface and its IN/OUT endpoint numbers from USB descriptors.
100
+ * Falls back to legacy hardcoded values if no vendor interface is found.
101
+ */
45
102
  private discoverEndpoints;
103
+ /**
104
+ * Connect to specific device.
105
+ * Discovers interface/endpoint numbers from USB descriptors on first connection.
106
+ */
46
107
  connectToDevice(path: string, first: boolean): Promise<void>;
47
108
  private closeOpenDevice;
48
109
  private clearEndpointHalt;
@@ -53,17 +114,44 @@ declare class WebUsbTransport {
53
114
  private getTransferInData;
54
115
  private toArrayBuffer;
55
116
  private transferOutWithRetry;
117
+ private transferOutOnce;
56
118
  private transferInWithRetry;
119
+ private transferInOnce;
57
120
  private resetConnectionAfterProbe;
58
121
  private withProtocolReadTimeout;
59
122
  private probeProtocolV1;
60
123
  private probeProtocolV2;
124
+ /**
125
+ * Call device method — branches to Protocol V1 or Protocol V2 based on active probe.
126
+ */
61
127
  call(path: string, name: string, data: Record<string, unknown>, options?: TransportCallOptions): Promise<_onekeyfe_hd_transport.MessageFromOneKey>;
62
128
  private callProtocolV1;
129
+ /**
130
+ * Send/receive a single call over Protocol V2 (0x5A framing).
131
+ *
132
+ * Encoding: protobuf message → 2-byte LE messageTypeId + pb bytes → Protocol V2 frame
133
+ * Decoding: Protocol V2 frame → messageTypeId + pb bytes → protobuf message
134
+ */
63
135
  private callProtocolV2;
64
- private receiveProtocolV2Frame;
136
+ /**
137
+ * Receive data from device
138
+ */
65
139
  receiveData(path: string, timeoutMs?: number): Promise<string>;
140
+ /**
141
+ * Release device
142
+ */
66
143
  release(path: string): Promise<void>;
144
+ protected getProtocolV2UsbSchemas(): ProtocolV2Schemas;
145
+ protected getProtocolV2UsbLogger(): any;
146
+ protected writeProtocolV2UsbPacket(path: string, frame: Uint8Array, _context: ProtocolV2CallContext): Promise<void>;
147
+ protected readProtocolV2UsbPacket(path: string, _context: ProtocolV2CallContext): Promise<Uint8Array>;
148
+ protected resetProtocolV2UsbNativeLink(path: string, _reason: string): Promise<void>;
149
+ protected onProtocolV2UsbLinkInvalidated(path: string, reason: string): void;
150
+ protected createProtocolV2UsbTimeoutError(name: string, timeoutMs: number): Error;
151
+ /**
152
+ * Expose the detected protocol type for a given device path.
153
+ * Used by upper layers (e.g. TransportManager) to select the correct schema.
154
+ */
67
155
  getProtocolType(path: string): ProtocolType | undefined;
68
156
  }
69
157
 
@@ -77,9 +165,16 @@ type BleAcquireInput = {
77
165
  forceCleanRunPromise?: boolean;
78
166
  expectedProtocol?: ProtocolType;
79
167
  };
168
+ /**
169
+ * Desktop Electron BLE transport with automatic Protocol V1/V2 detection.
170
+ *
171
+ * Protocol V1 devices continue using chunked packets. Protocol V2 is detected
172
+ * after a Protocol V1 Initialize timeout by probing Protocol V2 Ping.
173
+ */
80
174
  declare class ElectronBleTransport {
81
175
  private _messages;
82
176
  private _messagesV2;
177
+ private protocolV2SchemaConfiguration;
83
178
  name: string;
84
179
  configured: boolean;
85
180
  runPromise: Deferred<Uint8Array | string> | null;
@@ -92,8 +187,7 @@ declare class ElectronBleTransport {
92
187
  private v2Assemblers;
93
188
  private v2FrameQueues;
94
189
  private v2FramePromises;
95
- private activeProtocolV2Call;
96
- private nextProtocolV2CallToken;
190
+ private protocolV2Links;
97
191
  private notificationCleanups;
98
192
  private disconnectCleanups;
99
193
  private notificationTokens;
@@ -125,20 +219,21 @@ declare class ElectronBleTransport {
125
219
  private resetProbeStateAfterProtocolProbe;
126
220
  private probeProtocolV1;
127
221
  private probeProtocolV2;
128
- private writeWithChunking;
129
- private writeWithRetry;
222
+ private writeOnce;
223
+ private writeProtocolV2Frame;
130
224
  private handleNotification;
131
225
  private handleProtocolV2Notification;
132
226
  private getProtocolV2FrameQueue;
133
227
  private resolveProtocolV2Frame;
134
228
  private rejectAllProtocolV2Frames;
135
229
  private resetProtocolV2Frames;
136
- private isActiveProtocolV2Call;
230
+ private rejectProtocolV2Frames;
137
231
  private readProtocolV2Frame;
138
232
  private handleProtocolV1Notification;
139
233
  call(uuid: string, name: string, data: Record<string, unknown>, options?: TransportCallOptions): Promise<_onekeyfe_hd_transport.MessageFromOneKey>;
140
234
  private callProtocolV1;
141
235
  private callProtocolV2;
236
+ private createProtocolV2Adapter;
142
237
  private processProtocolV1Notification;
143
238
  getProtocolType(path: string): ProtocolType | undefined;
144
239
  }