@onekeyfe/hd-transport-web-device 1.2.0-alpha.13 → 1.2.0-alpha.131

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,24 +155,38 @@ 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
185
  private protocolV2Links;
186
+ /** One-shot guard so a missing preload `release` bridge is reported once. */
187
+ private warnedMissingRelease;
97
188
  private notificationCleanups;
189
+ private mtuCleanups;
98
190
  private disconnectCleanups;
99
191
  private notificationTokens;
100
192
  private nextNotificationToken;
@@ -116,7 +208,10 @@ declare class ElectronBleTransport {
116
208
  name: string | null;
117
209
  protocolType?: ProtocolType | undefined;
118
210
  }>;
119
- release(id: string): Promise<void>;
211
+ release(id: string, _onclose?: boolean, keepSession?: boolean): Promise<void>;
212
+ disconnect(id: string): Promise<void>;
213
+ private releaseNative;
214
+ private releaseLogical;
120
215
  private createProtocolMismatchError;
121
216
  private createProtocolDetectionError;
122
217
  private clearProbeProtocol;
@@ -125,18 +220,21 @@ declare class ElectronBleTransport {
125
220
  private resetProbeStateAfterProtocolProbe;
126
221
  private probeProtocolV1;
127
222
  private probeProtocolV2;
128
- private writeWithChunking;
129
223
  private writeOnce;
224
+ private refreshBlePacketCapacity;
225
+ private updateBlePacketCapacity;
226
+ private createMtuSubscription;
227
+ private writeProtocolV2Frame;
130
228
  private handleNotification;
131
229
  private handleProtocolV2Notification;
132
230
  private getProtocolV2FrameQueue;
133
231
  private resolveProtocolV2Frame;
134
- private rejectAllProtocolV2Frames;
135
232
  private resetProtocolV2Frames;
136
233
  private rejectProtocolV2Frames;
137
234
  private readProtocolV2Frame;
138
235
  private handleProtocolV1Notification;
139
236
  call(uuid: string, name: string, data: Record<string, unknown>, options?: TransportCallOptions): Promise<_onekeyfe_hd_transport.MessageFromOneKey>;
237
+ post(uuid: string, name: string, data: Record<string, unknown>): Promise<void>;
140
238
  private callProtocolV1;
141
239
  private callProtocolV2;
142
240
  private createProtocolV2Adapter;