@onekeyfe/hd-transport-web-device 1.2.0-alpha.7 → 1.2.0-alpha.71

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/dist/index.d.ts CHANGED
@@ -1,48 +1,99 @@
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;
21
- private mockSerialPaths;
22
- private mockSerialCounter;
23
25
  name: string;
24
26
  stopped: boolean;
25
27
  configured: boolean;
26
28
  Log?: any;
27
29
  usb?: USB;
30
+ /**
31
+ * Cached list of connected devices
32
+ * This is essential for maintaining device references between operations
33
+ */
28
34
  deviceList: Array<DeviceInfo>;
29
35
  configurationId: number;
30
36
  endpointId: number;
31
37
  interfaceId: number;
38
+ constructor();
39
+ /**
40
+ * Initialize WebUSB transport
41
+ */
32
42
  init(logger: any): void;
43
+ /**
44
+ * Configure Protocol V1 protobuf schema (legacy chunked 0x3F framing).
45
+ */
33
46
  configure(signedData: any): void;
47
+ /**
48
+ * Cache the Protocol V2 protobuf schema.
49
+ */
34
50
  configureProtocolV2(signedData: any): void;
51
+ /**
52
+ * Request user to select a device
53
+ * This method must be called in response to a user action
54
+ * to comply with WebUSB security requirements
55
+ */
35
56
  promptDeviceAccess(): Promise<USBDevice | null>;
57
+ /**
58
+ * Enumerate already connected devices
59
+ * This method only returns devices that are already authorized by the browser
60
+ * It does NOT prompt the user to select a device
61
+ */
36
62
  enumerate(): Promise<DeviceInfo[]>;
37
- private getDevicePath;
63
+ /**
64
+ * Get list of connected devices
65
+ */
38
66
  getConnectedDevices(): Promise<DeviceInfo[]>;
67
+ /**
68
+ * Acquire device control
69
+ */
39
70
  acquire(input: AcquireInput): Promise<string | undefined>;
71
+ /**
72
+ * Determine protocol type after connect.
73
+ * Probe Protocol V1 first with Initialize. If it does not answer in time,
74
+ * fall back to a Protocol V2 Ping probe.
75
+ */
40
76
  private createProtocolMismatchError;
77
+ private createProtocolProbeTimeoutError;
41
78
  private createProtocolDetectionError;
42
79
  private detectProtocol;
80
+ /**
81
+ * Find device by path
82
+ */
43
83
  findDevice(path: string): Promise<USBDevice>;
84
+ /**
85
+ * Connect to device with retry mechanism
86
+ */
44
87
  connect(path: string, first: boolean): Promise<void>;
88
+ /**
89
+ * Discover vendor-class (0xFF) interface and its IN/OUT endpoint numbers from USB descriptors.
90
+ * Falls back to legacy hardcoded values if no vendor interface is found.
91
+ */
45
92
  private discoverEndpoints;
93
+ /**
94
+ * Connect to specific device.
95
+ * Discovers interface/endpoint numbers from USB descriptors on first connection.
96
+ */
46
97
  connectToDevice(path: string, first: boolean): Promise<void>;
47
98
  private closeOpenDevice;
48
99
  private clearEndpointHalt;
@@ -55,16 +106,43 @@ declare class WebUsbTransport {
55
106
  private transferOutWithRetry;
56
107
  private transferOutOnce;
57
108
  private transferInWithRetry;
109
+ private transferInOnce;
110
+ private closeConnectionAfterProbe;
58
111
  private resetConnectionAfterProbe;
59
112
  private withProtocolReadTimeout;
60
113
  private probeProtocolV1;
61
114
  private probeProtocolV2;
115
+ /**
116
+ * Call device method — branches to Protocol V1 or Protocol V2 based on active probe.
117
+ */
62
118
  call(path: string, name: string, data: Record<string, unknown>, options?: TransportCallOptions): Promise<_onekeyfe_hd_transport.MessageFromOneKey>;
63
119
  private callProtocolV1;
120
+ /**
121
+ * Send/receive a single call over Protocol V2 (0x5A framing).
122
+ *
123
+ * Encoding: protobuf message → 2-byte LE messageTypeId + pb bytes → Protocol V2 frame
124
+ * Decoding: Protocol V2 frame → messageTypeId + pb bytes → protobuf message
125
+ */
64
126
  private callProtocolV2;
65
- private receiveProtocolV2Frame;
127
+ /**
128
+ * Receive data from device
129
+ */
66
130
  receiveData(path: string, timeoutMs?: number): Promise<string>;
131
+ /**
132
+ * Release device
133
+ */
67
134
  release(path: string): Promise<void>;
135
+ protected getProtocolV2UsbSchemas(): ProtocolV2Schemas;
136
+ protected getProtocolV2UsbLogger(): any;
137
+ protected writeProtocolV2UsbPacket(path: string, frame: Uint8Array, _context: ProtocolV2CallContext): Promise<void>;
138
+ protected readProtocolV2UsbPacket(path: string, _context: ProtocolV2CallContext): Promise<Uint8Array>;
139
+ protected resetProtocolV2UsbNativeLink(path: string, _reason: string): Promise<void>;
140
+ protected onProtocolV2UsbLinkInvalidated(path: string, reason: string): void;
141
+ protected createProtocolV2UsbTimeoutError(name: string, timeoutMs: number): Error;
142
+ /**
143
+ * Expose the detected protocol type for a given device path.
144
+ * Used by upper layers (e.g. TransportManager) to select the correct schema.
145
+ */
68
146
  getProtocolType(path: string): ProtocolType | undefined;
69
147
  }
70
148
 
@@ -77,25 +155,36 @@ type BleAcquireInput = {
77
155
  uuid: string;
78
156
  forceCleanRunPromise?: boolean;
79
157
  expectedProtocol?: ProtocolType;
158
+ protocolHint?: ProtocolType;
80
159
  };
160
+ /**
161
+ * Desktop Electron BLE transport with automatic Protocol V1/V2 detection.
162
+ *
163
+ * Protocol V1 devices continue using chunked packets. Protocol V2 is detected
164
+ * after a Protocol V1 GetFeatures timeout by probing Protocol V2 Ping.
165
+ */
81
166
  declare class ElectronBleTransport {
82
167
  private _messages;
83
168
  private _messagesV2;
169
+ private protocolV2SchemaConfiguration;
84
170
  name: string;
85
171
  configured: boolean;
86
172
  runPromise: Deferred<Uint8Array | string> | null;
173
+ private runPromiseDeviceId;
87
174
  Log?: any;
88
175
  emitter?: EventEmitter;
89
176
  private connectedDevices;
90
177
  private deviceProtocol;
91
178
  private deviceProtocolHints;
179
+ private deviceMtus;
180
+ private devicePacketCapacities;
92
181
  private v1Buffers;
93
182
  private v2Assemblers;
94
183
  private v2FrameQueues;
95
184
  private v2FramePromises;
96
- private activeProtocolV2Call;
97
- private nextProtocolV2CallToken;
185
+ private protocolV2Links;
98
186
  private notificationCleanups;
187
+ private mtuCleanups;
99
188
  private disconnectCleanups;
100
189
  private notificationTokens;
101
190
  private nextNotificationToken;
@@ -118,6 +207,7 @@ declare class ElectronBleTransport {
118
207
  protocolType?: ProtocolType | undefined;
119
208
  }>;
120
209
  release(id: string): Promise<void>;
210
+ private releaseNative;
121
211
  private createProtocolMismatchError;
122
212
  private createProtocolDetectionError;
123
213
  private clearProbeProtocol;
@@ -126,20 +216,23 @@ declare class ElectronBleTransport {
126
216
  private resetProbeStateAfterProtocolProbe;
127
217
  private probeProtocolV1;
128
218
  private probeProtocolV2;
129
- private writeWithChunking;
130
219
  private writeOnce;
220
+ private refreshBlePacketCapacity;
221
+ private updateBlePacketCapacity;
222
+ private createMtuSubscription;
223
+ private writeProtocolV2Frame;
131
224
  private handleNotification;
132
225
  private handleProtocolV2Notification;
133
226
  private getProtocolV2FrameQueue;
134
227
  private resolveProtocolV2Frame;
135
- private rejectAllProtocolV2Frames;
136
228
  private resetProtocolV2Frames;
137
- private isActiveProtocolV2Call;
229
+ private rejectProtocolV2Frames;
138
230
  private readProtocolV2Frame;
139
231
  private handleProtocolV1Notification;
140
232
  call(uuid: string, name: string, data: Record<string, unknown>, options?: TransportCallOptions): Promise<_onekeyfe_hd_transport.MessageFromOneKey>;
141
233
  private callProtocolV1;
142
234
  private callProtocolV2;
235
+ private createProtocolV2Adapter;
143
236
  private processProtocolV1Notification;
144
237
  getProtocolType(path: string): ProtocolType | undefined;
145
238
  }