@onekeyfe/hd-transport-web-device 1.1.34-alpha.3 → 1.1.34-alpha.4

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,8 +1,8 @@
1
1
  /// <reference types="node" />
2
+ import transport from '@onekeyfe/hd-transport';
2
3
  import type { Deferred } from '@onekeyfe/hd-shared';
3
- import type { DesktopAPI } from '@onekeyfe/hd-transport-electron';
4
- import type { OneKeyDeviceInfo, ProtocolType, TransportCallOptions } from '@onekeyfe/hd-transport';
5
4
  import type EventEmitter from 'events';
5
+ import type { DesktopAPI } from '@onekeyfe/hd-transport-electron';
6
6
  declare global {
7
7
  interface Window {
8
8
  desktopApi?: DesktopAPI;
@@ -11,71 +11,34 @@ declare global {
11
11
  export type BleAcquireInput = {
12
12
  uuid: string;
13
13
  forceCleanRunPromise?: boolean;
14
- expectedProtocol?: ProtocolType;
15
14
  };
16
15
  export default class ElectronBleTransport {
17
- private _messages;
18
- private _messagesV2;
16
+ _messages: ReturnType<typeof transport.parseConfigure> | undefined;
19
17
  name: string;
20
18
  configured: boolean;
21
- runPromise: Deferred<Uint8Array | string> | null;
19
+ runPromise: Deferred<any> | null;
22
20
  Log?: any;
23
21
  emitter?: EventEmitter;
24
22
  private connectedDevices;
25
- private deviceProtocol;
26
- private deviceProtocolHints;
27
- private v1Buffers;
28
- private v2Assemblers;
29
- private v2FrameQueues;
30
- private v2FramePromises;
31
- private protocolV2Links;
23
+ private dataBuffers;
32
24
  private notificationCleanups;
33
25
  private disconnectCleanups;
34
- private notificationTokens;
35
- private nextNotificationToken;
36
26
  private handleBluetoothError;
37
27
  private cleanupDeviceState;
38
28
  init(logger: any, emitter?: EventEmitter): void;
39
29
  configure(signedData: any): void;
40
- configureProtocolV2(signedData: any): void;
41
- listen(): Promise<OneKeyDeviceInfo[]>;
42
- enumerate(): Promise<OneKeyDeviceInfo[]>;
30
+ listen(): void;
31
+ enumerate(): Promise<{
32
+ id: string;
33
+ name: string;
34
+ }[]>;
43
35
  acquire(input: BleAcquireInput): Promise<{
44
36
  uuid: string;
45
- commType: import("@onekeyfe/hd-transport").OneKeyDeviceCommType;
46
37
  path: string;
47
- session?: string | null | undefined;
48
- debugSession?: string | null | undefined;
49
- debug: boolean;
50
- id: string;
51
- name: string | null;
52
- protocolType?: ProtocolType | undefined;
53
38
  }>;
54
39
  release(id: string): Promise<void>;
55
- private createProtocolMismatchError;
56
- private createProtocolDetectionError;
57
- private clearProbeProtocol;
58
- private detectProtocol;
59
- private createNotificationSubscription;
60
- private resetProbeStateAfterProtocolProbe;
61
- private probeProtocolV1;
62
- private probeProtocolV2;
63
- private writeWithChunking;
64
- private writeOnce;
65
- private handleNotification;
66
- private handleProtocolV2Notification;
67
- private getProtocolV2FrameQueue;
68
- private resolveProtocolV2Frame;
69
- private rejectAllProtocolV2Frames;
70
- private resetProtocolV2Frames;
71
- private rejectProtocolV2Frames;
72
- private readProtocolV2Frame;
73
- private handleProtocolV1Notification;
74
- call(uuid: string, name: string, data: Record<string, unknown>, options?: TransportCallOptions): Promise<import("@onekeyfe/hd-transport").MessageFromOneKey>;
75
- private callProtocolV1;
76
- private callProtocolV2;
77
- private createProtocolV2Adapter;
78
- private processProtocolV1Notification;
79
- getProtocolType(path: string): ProtocolType | undefined;
40
+ private handleNotificationData;
41
+ call(uuid: string, name: string, data: Record<string, unknown>): Promise<import("@onekeyfe/hd-transport").MessageFromOneKey>;
42
+ private processNotificationPacket;
80
43
  }
81
44
  //# sourceMappingURL=electron-ble-transport.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"electron-ble-transport.d.ts","sourceRoot":"","sources":["../src/electron-ble-transport.ts"],"names":[],"mappings":";AAoBA,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,EA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KACzB;CACF;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AASF,MAAM,CAAC,OAAO,OAAO,oBAAoB;IACvC,SAAS,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAEnE,IAAI,SAA0B;IAE9B,UAAU,UAAS;IAEnB,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAExC,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,OAAO,CAAC,EAAE,YAAY,CAAC;IAGvB,OAAO,CAAC,gBAAgB,CAA0B;IAGlD,OAAO,CAAC,WAAW,CAAsE;IAGzF,OAAO,CAAC,oBAAoB,CAAsC;IAGlE,OAAO,CAAC,kBAAkB,CAAsC;IAGhE,OAAO,CAAC,oBAAoB;IAmC5B,OAAO,CAAC,kBAAkB;IAmB1B,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,YAAY;IAexC,SAAS,CAAC,UAAU,EAAE,GAAG;IAMzB,MAAM;IAEA,SAAS,IAAI,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAcpD,OAAO,CAAC,KAAK,EAAE,eAAe;;;;IA8E9B,OAAO,CAAC,EAAE,EAAE,MAAM;IAwBxB,OAAO,CAAC,sBAAsB;IA2BxB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IA2EpE,OAAO,CAAC,yBAAyB;CAyDlC"}
package/dist/index.d.ts CHANGED
@@ -1,118 +1,33 @@
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';
1
+ import * as transport from '@onekeyfe/hd-transport';
2
+ import transport__default, { AcquireInput, OneKeyDeviceInfoBase } from '@onekeyfe/hd-transport';
3
3
  import { Deferred } from '@onekeyfe/hd-shared';
4
- import { DesktopAPI } from '@onekeyfe/hd-transport-electron';
5
4
  import EventEmitter from 'events';
5
+ import { DesktopAPI } from '@onekeyfe/hd-transport-electron';
6
6
 
7
- /**
8
- * Device information with path and WebUSB device instance
9
- */
10
7
  interface DeviceInfo extends OneKeyDeviceInfoBase {
11
8
  path: string;
12
9
  device: USBDevice;
13
- protocolType?: ProtocolType;
14
10
  }
15
11
  declare class WebUsbTransport {
16
- messages: ReturnType<typeof _onekeyfe_hd_transport__default.parseConfigure> | undefined;
17
- /** Protobuf schema for Protocol V2 transports. */
18
- messagesV2: ReturnType<typeof _onekeyfe_hd_transport__default.parseConfigure> | undefined;
19
- /** Per-path protocol type detected by active wire-level probe. */
20
- private deviceProtocol;
21
- private deviceProtocolHints;
22
- /** Per-device Protocol V2 assembler that retains extra frames from one read. */
23
- private protocolV2Assemblers;
24
- /** Per-device Protocol V2 session that keeps sequence numbers monotonic. */
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. */
29
- private protocolV2ReadTimeouts;
30
- private protocolV2WriteTimeoutMs;
31
- /** Per-path USB endpoint / interface numbers (discovered from USB descriptors) */
32
- private deviceEndpoints;
33
- /**
34
- * Early Pro2 boards have no USB serial number. Assign a session-stable mock path per
35
- * USBDevice instance so discovery retains them; reconnecting creates a new instance/path.
36
- */
37
- private mockSerialPaths;
38
- private mockSerialCounter;
12
+ messages: ReturnType<typeof transport__default.parseConfigure> | undefined;
39
13
  name: string;
40
14
  stopped: boolean;
41
15
  configured: boolean;
42
16
  Log?: any;
43
17
  usb?: USB;
44
- /**
45
- * Cached list of connected devices
46
- * This is essential for maintaining device references between operations
47
- */
48
18
  deviceList: Array<DeviceInfo>;
49
19
  configurationId: number;
50
20
  endpointId: number;
51
21
  interfaceId: number;
52
- /**
53
- * Initialize WebUSB transport
54
- */
55
22
  init(logger: any): void;
56
- /**
57
- * Configure Protocol V1 protobuf schema (legacy chunked 0x3F framing).
58
- */
59
23
  configure(signedData: any): void;
60
- /**
61
- * Cache the Protocol V2 protobuf schema.
62
- */
63
- configureProtocolV2(signedData: any): void;
64
- /**
65
- * Request user to select a device
66
- * This method must be called in response to a user action
67
- * to comply with WebUSB security requirements
68
- */
69
24
  promptDeviceAccess(): Promise<USBDevice | null>;
70
- /**
71
- * Enumerate already connected devices
72
- * This method only returns devices that are already authorized by the browser
73
- * It does NOT prompt the user to select a device
74
- */
75
25
  enumerate(): Promise<DeviceInfo[]>;
76
- /**
77
- * Use the USB serial as the device path, falling back to a session-stable mock path.
78
- */
79
- private getDevicePath;
80
- /**
81
- * Get list of connected devices
82
- */
83
26
  getConnectedDevices(): Promise<DeviceInfo[]>;
84
- /**
85
- * Acquire device control
86
- */
87
27
  acquire(input: AcquireInput): Promise<string | undefined>;
88
- /**
89
- * Determine protocol type after connect.
90
- * Probe Protocol V1 first with Initialize. If it does not answer in time,
91
- * fall back to a Protocol V2 Ping probe.
92
- */
93
- private createProtocolMismatchError;
94
- private createProtocolDetectionError;
95
- private detectProtocol;
96
- /**
97
- * Find device by path
98
- */
99
28
  findDevice(path: string): Promise<USBDevice>;
100
- /**
101
- * Connect to device with retry mechanism
102
- */
103
29
  connect(path: string, first: boolean): Promise<void>;
104
- /**
105
- * Discover vendor-class (0xFF) interface and its IN/OUT endpoint numbers from USB descriptors.
106
- * Falls back to legacy hardcoded values if no vendor interface is found.
107
- */
108
- private discoverEndpoints;
109
- /**
110
- * Connect to specific device.
111
- * Discovers interface/endpoint numbers from USB descriptors on first connection.
112
- */
113
30
  connectToDevice(path: string, first: boolean): Promise<void>;
114
- private closeOpenDevice;
115
- private clearEndpointHalt;
116
31
  post(session: string, name: string, data: Record<string, unknown>): Promise<void>;
117
32
  private getErrorMessage;
118
33
  private isRetryablePacketIoError;
@@ -120,38 +35,10 @@ declare class WebUsbTransport {
120
35
  private getTransferInData;
121
36
  private toArrayBuffer;
122
37
  private transferOutWithRetry;
123
- private transferOutOnce;
124
38
  private transferInWithRetry;
125
- private resetConnectionAfterProbe;
126
- private withProtocolReadTimeout;
127
- private probeProtocolV1;
128
- private probeProtocolV2;
129
- /**
130
- * Call device method — branches to Protocol V1 or Protocol V2 based on active probe.
131
- */
132
- call(path: string, name: string, data: Record<string, unknown>, options?: TransportCallOptions): Promise<_onekeyfe_hd_transport.MessageFromOneKey>;
133
- private callProtocolV1;
134
- /**
135
- * Send/receive a single call over Protocol V2 (0x5A framing).
136
- *
137
- * Encoding: protobuf message → 2-byte LE messageTypeId + pb bytes → Protocol V2 frame
138
- * Decoding: Protocol V2 frame → messageTypeId + pb bytes → protobuf message
139
- */
140
- private callProtocolV2;
141
- private receiveProtocolV2Frame;
142
- /**
143
- * Receive data from device
144
- */
145
- receiveData(path: string, timeoutMs?: number): Promise<string>;
146
- /**
147
- * Release device
148
- */
39
+ call(path: string, name: string, data: Record<string, unknown>): Promise<transport.MessageFromOneKey>;
40
+ receiveData(path: string): Promise<string>;
149
41
  release(path: string): Promise<void>;
150
- /**
151
- * Expose the detected protocol type for a given device path.
152
- * Used by upper layers (e.g. TransportManager) to select the correct schema.
153
- */
154
- getProtocolType(path: string): ProtocolType | undefined;
155
42
  }
156
43
 
157
44
  declare global {
@@ -162,78 +49,35 @@ declare global {
162
49
  type BleAcquireInput = {
163
50
  uuid: string;
164
51
  forceCleanRunPromise?: boolean;
165
- expectedProtocol?: ProtocolType;
166
52
  };
167
- /**
168
- * Desktop Electron BLE transport with automatic Protocol V1/V2 detection.
169
- *
170
- * Protocol V1 devices continue using chunked packets. Protocol V2 is detected
171
- * after a Protocol V1 Initialize timeout by probing Protocol V2 Ping.
172
- */
173
53
  declare class ElectronBleTransport {
174
- private _messages;
175
- private _messagesV2;
54
+ _messages: ReturnType<typeof transport__default.parseConfigure> | undefined;
176
55
  name: string;
177
56
  configured: boolean;
178
- runPromise: Deferred<Uint8Array | string> | null;
57
+ runPromise: Deferred<any> | null;
179
58
  Log?: any;
180
59
  emitter?: EventEmitter;
181
60
  private connectedDevices;
182
- private deviceProtocol;
183
- private deviceProtocolHints;
184
- private v1Buffers;
185
- private v2Assemblers;
186
- private v2FrameQueues;
187
- private v2FramePromises;
188
- private protocolV2Links;
61
+ private dataBuffers;
189
62
  private notificationCleanups;
190
63
  private disconnectCleanups;
191
- private notificationTokens;
192
- private nextNotificationToken;
193
64
  private handleBluetoothError;
194
65
  private cleanupDeviceState;
195
66
  init(logger: any, emitter?: EventEmitter): void;
196
67
  configure(signedData: any): void;
197
- configureProtocolV2(signedData: any): void;
198
- listen(): Promise<OneKeyDeviceInfo[]>;
199
- enumerate(): Promise<OneKeyDeviceInfo[]>;
68
+ listen(): void;
69
+ enumerate(): Promise<{
70
+ id: string;
71
+ name: string;
72
+ }[]>;
200
73
  acquire(input: BleAcquireInput): Promise<{
201
74
  uuid: string;
202
- commType: _onekeyfe_hd_transport.OneKeyDeviceCommType;
203
75
  path: string;
204
- session?: string | null | undefined;
205
- debugSession?: string | null | undefined;
206
- debug: boolean;
207
- id: string;
208
- name: string | null;
209
- protocolType?: ProtocolType | undefined;
210
76
  }>;
211
77
  release(id: string): Promise<void>;
212
- private createProtocolMismatchError;
213
- private createProtocolDetectionError;
214
- private clearProbeProtocol;
215
- private detectProtocol;
216
- private createNotificationSubscription;
217
- private resetProbeStateAfterProtocolProbe;
218
- private probeProtocolV1;
219
- private probeProtocolV2;
220
- private writeWithChunking;
221
- private writeOnce;
222
- private handleNotification;
223
- private handleProtocolV2Notification;
224
- private getProtocolV2FrameQueue;
225
- private resolveProtocolV2Frame;
226
- private rejectAllProtocolV2Frames;
227
- private resetProtocolV2Frames;
228
- private rejectProtocolV2Frames;
229
- private readProtocolV2Frame;
230
- private handleProtocolV1Notification;
231
- call(uuid: string, name: string, data: Record<string, unknown>, options?: TransportCallOptions): Promise<_onekeyfe_hd_transport.MessageFromOneKey>;
232
- private callProtocolV1;
233
- private callProtocolV2;
234
- private createProtocolV2Adapter;
235
- private processProtocolV1Notification;
236
- getProtocolType(path: string): ProtocolType | undefined;
78
+ private handleNotificationData;
79
+ call(uuid: string, name: string, data: Record<string, unknown>): Promise<transport.MessageFromOneKey>;
80
+ private processNotificationPacket;
237
81
  }
238
82
 
239
83
  export { ElectronBleTransport, WebUsbTransport };