@onekeyfe/hd-transport-web-device 1.1.27-alpha.35 → 1.1.27-alpha.36
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/__tests__/electron-ble-transport.test.ts +231 -0
- package/dist/electron-ble-transport.d.ts +50 -15
- package/dist/electron-ble-transport.d.ts.map +1 -1
- package/dist/index.d.ts +8 -45
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +95 -365
- package/dist/webusb.d.ts +2 -1
- package/dist/webusb.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/electron-ble-transport.ts +605 -132
- package/src/index.ts +1 -2
- package/src/webusb.ts +29 -9
- package/dist/electron-auto-ble-transport.d.ts +0 -79
- package/dist/electron-auto-ble-transport.d.ts.map +0 -1
- package/src/electron-auto-ble-transport.ts +0 -872
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import transport, { PROTOCOL_V2_CHANNEL_BLE_UART, bytesToHex } from '@onekeyfe/hd-transport';
|
|
2
|
+
|
|
3
|
+
import ElectronBleTransport from '../src/electron-ble-transport';
|
|
4
|
+
|
|
5
|
+
const { ProtocolV1, ProtocolV2, parseConfigure } = transport;
|
|
6
|
+
|
|
7
|
+
const protocolV1Schema = {
|
|
8
|
+
nested: {
|
|
9
|
+
Initialize: {
|
|
10
|
+
fields: {},
|
|
11
|
+
},
|
|
12
|
+
Success: {
|
|
13
|
+
fields: {
|
|
14
|
+
message: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
id: 1,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
MessageType: {
|
|
21
|
+
values: {
|
|
22
|
+
MessageType_Initialize: 1,
|
|
23
|
+
MessageType_Success: 2,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const protocolV2Schema = {
|
|
30
|
+
nested: {
|
|
31
|
+
Ping: {
|
|
32
|
+
fields: {
|
|
33
|
+
message: {
|
|
34
|
+
type: 'string',
|
|
35
|
+
id: 1,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
Success: {
|
|
40
|
+
fields: {
|
|
41
|
+
message: {
|
|
42
|
+
type: 'string',
|
|
43
|
+
id: 1,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
MessageType: {
|
|
48
|
+
values: {
|
|
49
|
+
MessageType_Ping: 60206,
|
|
50
|
+
MessageType_Success: 60207,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const schemas = {
|
|
57
|
+
protocolV1: parseConfigure(protocolV1Schema),
|
|
58
|
+
protocolV2: parseConfigure(protocolV2Schema),
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
jest.setTimeout(10_000);
|
|
62
|
+
|
|
63
|
+
const createLogger = () => ({
|
|
64
|
+
debug: jest.fn(),
|
|
65
|
+
error: jest.fn(),
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const createNobleBle = (device = { id: 'flaky-pro2-id', name: 'Unknown BLE Device' }) => ({
|
|
69
|
+
enumerate: jest.fn(() => Promise.resolve([device])),
|
|
70
|
+
getDevice: jest.fn(() => Promise.resolve(device)),
|
|
71
|
+
connect: jest.fn(() => Promise.resolve()),
|
|
72
|
+
disconnect: jest.fn(() => Promise.resolve()),
|
|
73
|
+
subscribe: jest.fn(() => Promise.resolve()),
|
|
74
|
+
unsubscribe: jest.fn(() => Promise.resolve()),
|
|
75
|
+
write: jest.fn(() => Promise.resolve()),
|
|
76
|
+
onNotification: jest.fn(() => jest.fn()),
|
|
77
|
+
onDeviceDisconnected: jest.fn(() => jest.fn()),
|
|
78
|
+
checkAvailability: jest.fn(() =>
|
|
79
|
+
Promise.resolve({
|
|
80
|
+
available: true,
|
|
81
|
+
state: 'poweredOn',
|
|
82
|
+
unsupported: false,
|
|
83
|
+
initialized: true,
|
|
84
|
+
})
|
|
85
|
+
),
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const configureTransport = (nobleBle: ReturnType<typeof createNobleBle>) => {
|
|
89
|
+
(global as any).window = {
|
|
90
|
+
desktopApi: {
|
|
91
|
+
nobleBle,
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const transport = new ElectronBleTransport();
|
|
96
|
+
transport.init(createLogger());
|
|
97
|
+
transport.configure(protocolV1Schema);
|
|
98
|
+
transport.configureProtocolV2(protocolV2Schema);
|
|
99
|
+
return transport;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
describe('ElectronBleTransport protocol detection', () => {
|
|
103
|
+
afterEach(() => {
|
|
104
|
+
delete (global as any).window;
|
|
105
|
+
jest.clearAllMocks();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('detects Protocol V2 after Protocol V1 probe timeout', async () => {
|
|
109
|
+
const device = { id: 'unknown-pro2-id', name: 'Unknown BLE Device' };
|
|
110
|
+
const nobleBle = createNobleBle(device);
|
|
111
|
+
let notificationHandler: ((deviceId: string, data: string) => void) | undefined;
|
|
112
|
+
let writeCount = 0;
|
|
113
|
+
const probeResponse = ProtocolV2.encodeFrame(
|
|
114
|
+
schemas,
|
|
115
|
+
'Success',
|
|
116
|
+
{
|
|
117
|
+
message: 'probe',
|
|
118
|
+
},
|
|
119
|
+
{ router: PROTOCOL_V2_CHANNEL_BLE_UART }
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
nobleBle.onNotification.mockImplementation(handler => {
|
|
123
|
+
notificationHandler = handler;
|
|
124
|
+
return jest.fn();
|
|
125
|
+
});
|
|
126
|
+
nobleBle.write.mockImplementation(() => {
|
|
127
|
+
writeCount += 1;
|
|
128
|
+
if (writeCount > 1) {
|
|
129
|
+
setTimeout(() => notificationHandler?.(device.id, bytesToHex(probeResponse)), 0);
|
|
130
|
+
}
|
|
131
|
+
return Promise.resolve();
|
|
132
|
+
});
|
|
133
|
+
const transport = configureTransport(nobleBle);
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
await expect(transport.acquire({ uuid: device.id })).resolves.toEqual(
|
|
137
|
+
expect.objectContaining({
|
|
138
|
+
uuid: device.id,
|
|
139
|
+
protocolType: 'V2',
|
|
140
|
+
})
|
|
141
|
+
);
|
|
142
|
+
expect(transport.getProtocolType(device.id)).toBe('V2');
|
|
143
|
+
} finally {
|
|
144
|
+
await transport.release(device.id);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('detects Protocol V1 when device responds to Initialize', async () => {
|
|
149
|
+
const device = { id: 'classic-id', name: 'OneKey Classic' };
|
|
150
|
+
const nobleBle = createNobleBle(device);
|
|
151
|
+
let notificationHandler: ((deviceId: string, data: string) => void) | undefined;
|
|
152
|
+
|
|
153
|
+
// Build a V1 Success notification (no 64-byte padding, matching real BLE behaviour).
|
|
154
|
+
// Format: ?## (3f2323) + typeId BE (0002) + length BE (00000004) + protobuf payload (0a026f6b)
|
|
155
|
+
const v1ResponseHex = '3f23230002000000040a026f6b';
|
|
156
|
+
|
|
157
|
+
nobleBle.onNotification.mockImplementation(handler => {
|
|
158
|
+
notificationHandler = handler;
|
|
159
|
+
return jest.fn();
|
|
160
|
+
});
|
|
161
|
+
nobleBle.write.mockImplementation(() => {
|
|
162
|
+
// Respond to first write (V1 Initialize probe) with V1 Success
|
|
163
|
+
setTimeout(() => notificationHandler?.(device.id, v1ResponseHex), 0);
|
|
164
|
+
return Promise.resolve();
|
|
165
|
+
});
|
|
166
|
+
const transport = configureTransport(nobleBle);
|
|
167
|
+
|
|
168
|
+
try {
|
|
169
|
+
await expect(transport.acquire({ uuid: device.id })).resolves.toEqual(
|
|
170
|
+
expect.objectContaining({
|
|
171
|
+
uuid: device.id,
|
|
172
|
+
})
|
|
173
|
+
);
|
|
174
|
+
expect(transport.getProtocolType(device.id)).toBe('V1');
|
|
175
|
+
} finally {
|
|
176
|
+
await transport.release(device.id);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test('throws when both protocol probes fail', async () => {
|
|
181
|
+
const device = { id: 'dead-device-id', name: 'Unknown Device' };
|
|
182
|
+
const nobleBle = createNobleBle(device);
|
|
183
|
+
|
|
184
|
+
// Never respond to writes — both probes will timeout
|
|
185
|
+
nobleBle.onNotification.mockImplementation(() => jest.fn());
|
|
186
|
+
|
|
187
|
+
const transport = configureTransport(nobleBle);
|
|
188
|
+
|
|
189
|
+
await expect(transport.acquire({ uuid: device.id })).rejects.toThrow(
|
|
190
|
+
/Unable to detect BLE protocol/
|
|
191
|
+
);
|
|
192
|
+
expect(transport.getProtocolType(device.id)).toBeUndefined();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test('probes Protocol V2 instead of trusting the Pro2 name hint', async () => {
|
|
196
|
+
const device = { id: 'named-pro2-id', name: 'OneKey Pro 2' };
|
|
197
|
+
const nobleBle = createNobleBle(device);
|
|
198
|
+
let notificationHandler: ((deviceId: string, data: string) => void) | undefined;
|
|
199
|
+
const probeResponse = ProtocolV2.encodeFrame(
|
|
200
|
+
schemas,
|
|
201
|
+
'Success',
|
|
202
|
+
{
|
|
203
|
+
message: 'probe',
|
|
204
|
+
},
|
|
205
|
+
{ router: PROTOCOL_V2_CHANNEL_BLE_UART }
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
nobleBle.onNotification.mockImplementation(handler => {
|
|
209
|
+
notificationHandler = handler;
|
|
210
|
+
return jest.fn();
|
|
211
|
+
});
|
|
212
|
+
nobleBle.write.mockImplementation(() => {
|
|
213
|
+
setTimeout(() => notificationHandler?.(device.id, bytesToHex(probeResponse)), 0);
|
|
214
|
+
return Promise.resolve();
|
|
215
|
+
});
|
|
216
|
+
const transport = configureTransport(nobleBle);
|
|
217
|
+
|
|
218
|
+
try {
|
|
219
|
+
await expect(transport.acquire({ uuid: device.id })).resolves.toEqual(
|
|
220
|
+
expect.objectContaining({
|
|
221
|
+
uuid: device.id,
|
|
222
|
+
protocolType: 'V2',
|
|
223
|
+
})
|
|
224
|
+
);
|
|
225
|
+
expect(nobleBle.write).toHaveBeenCalledTimes(1);
|
|
226
|
+
expect(transport.getProtocolType(device.id)).toBe('V2');
|
|
227
|
+
} finally {
|
|
228
|
+
await transport.release(device.id);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
});
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import transport from '@onekeyfe/hd-transport';
|
|
3
2
|
import type { Deferred } from '@onekeyfe/hd-shared';
|
|
4
|
-
import type EventEmitter from 'events';
|
|
5
|
-
import type { ProtocolType } from '@onekeyfe/hd-transport';
|
|
6
3
|
import type { DesktopAPI } from '@onekeyfe/hd-transport-electron';
|
|
4
|
+
import type { OneKeyDeviceInfo, ProtocolType, TransportCallOptions } from '@onekeyfe/hd-transport';
|
|
5
|
+
import type EventEmitter from 'events';
|
|
7
6
|
declare global {
|
|
8
7
|
interface Window {
|
|
9
8
|
desktopApi?: DesktopAPI;
|
|
@@ -12,35 +11,71 @@ declare global {
|
|
|
12
11
|
export type BleAcquireInput = {
|
|
13
12
|
uuid: string;
|
|
14
13
|
forceCleanRunPromise?: boolean;
|
|
14
|
+
expectedProtocol?: ProtocolType;
|
|
15
15
|
};
|
|
16
16
|
export default class ElectronBleTransport {
|
|
17
|
-
_messages
|
|
17
|
+
private _messages;
|
|
18
|
+
private _messagesV2;
|
|
18
19
|
name: string;
|
|
19
20
|
configured: boolean;
|
|
20
|
-
runPromise: Deferred<
|
|
21
|
+
runPromise: Deferred<Uint8Array | string> | null;
|
|
21
22
|
Log?: any;
|
|
22
23
|
emitter?: EventEmitter;
|
|
23
24
|
private connectedDevices;
|
|
24
|
-
private
|
|
25
|
+
private deviceProtocol;
|
|
26
|
+
private deviceProtocolHints;
|
|
27
|
+
private v1Buffers;
|
|
28
|
+
private v2Assemblers;
|
|
29
|
+
private v2FrameQueues;
|
|
30
|
+
private v2FramePromises;
|
|
31
|
+
private activeProtocolV2Call;
|
|
32
|
+
private nextProtocolV2CallToken;
|
|
25
33
|
private notificationCleanups;
|
|
26
34
|
private disconnectCleanups;
|
|
27
|
-
|
|
35
|
+
private notificationTokens;
|
|
36
|
+
private nextNotificationToken;
|
|
28
37
|
private handleBluetoothError;
|
|
29
38
|
private cleanupDeviceState;
|
|
30
39
|
init(logger: any, emitter?: EventEmitter): void;
|
|
31
40
|
configure(signedData: any): void;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
name: string;
|
|
36
|
-
}[]>;
|
|
41
|
+
configureProtocolV2(signedData: any): void;
|
|
42
|
+
listen(): Promise<OneKeyDeviceInfo[]>;
|
|
43
|
+
enumerate(): Promise<OneKeyDeviceInfo[]>;
|
|
37
44
|
acquire(input: BleAcquireInput): Promise<{
|
|
38
45
|
uuid: string;
|
|
46
|
+
commType: import("@onekeyfe/hd-transport").OneKeyDeviceCommType;
|
|
39
47
|
path: string;
|
|
48
|
+
session?: string | null | undefined;
|
|
49
|
+
debugSession?: string | null | undefined;
|
|
50
|
+
debug: boolean;
|
|
51
|
+
id: string;
|
|
52
|
+
name: string | null;
|
|
53
|
+
protocolType?: ProtocolType | undefined;
|
|
40
54
|
}>;
|
|
41
55
|
release(id: string): Promise<void>;
|
|
42
|
-
private
|
|
43
|
-
|
|
44
|
-
private
|
|
56
|
+
private createProtocolMismatchError;
|
|
57
|
+
private createProtocolDetectionError;
|
|
58
|
+
private clearProbeProtocol;
|
|
59
|
+
private detectProtocol;
|
|
60
|
+
private createNotificationSubscription;
|
|
61
|
+
private resetProbeStateAfterProtocolProbe;
|
|
62
|
+
private probeProtocolV1;
|
|
63
|
+
private probeProtocolV2;
|
|
64
|
+
private writeWithChunking;
|
|
65
|
+
private writeWithRetry;
|
|
66
|
+
private handleNotification;
|
|
67
|
+
private handleProtocolV2Notification;
|
|
68
|
+
private getProtocolV2FrameQueue;
|
|
69
|
+
private resolveProtocolV2Frame;
|
|
70
|
+
private rejectAllProtocolV2Frames;
|
|
71
|
+
private resetProtocolV2Frames;
|
|
72
|
+
private isActiveProtocolV2Call;
|
|
73
|
+
private readProtocolV2Frame;
|
|
74
|
+
private handleProtocolV1Notification;
|
|
75
|
+
call(uuid: string, name: string, data: Record<string, unknown>, options?: TransportCallOptions): Promise<import("@onekeyfe/hd-transport").MessageFromOneKey>;
|
|
76
|
+
private callProtocolV1;
|
|
77
|
+
private callProtocolV2;
|
|
78
|
+
private processProtocolV1Notification;
|
|
79
|
+
getProtocolType(path: string): ProtocolType | undefined;
|
|
45
80
|
}
|
|
46
81
|
//# 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":";
|
|
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;AAWvC,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;IAElD,OAAO,CAAC,cAAc,CAAwC;IAE9D,OAAO,CAAC,mBAAmB,CAAwC;IAEnE,OAAO,CAAC,SAAS,CAAsE;IAEvF,OAAO,CAAC,YAAY,CAAoD;IAExE,OAAO,CAAC,aAAa,CAAwC;IAE7D,OAAO,CAAC,eAAe,CAAgD;IAEvE,OAAO,CAAC,oBAAoB,CAAgD;IAE5E,OAAO,CAAC,uBAAuB,CAAK;IAEpC,OAAO,CAAC,oBAAoB,CAAsC;IAElE,OAAO,CAAC,kBAAkB,CAAsC;IAEhE,OAAO,CAAC,kBAAkB,CAAkC;IAE5D,OAAO,CAAC,qBAAqB,CAAK;IAElC,OAAO,CAAC,oBAAoB;IA+B5B,OAAO,CAAC,kBAAkB;IAyB1B,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,YAAY;IAcxC,SAAS,CAAC,UAAU,EAAE,GAAG;IAKzB,mBAAmB,CAAC,UAAU,EAAE,GAAG;IAK7B,MAAM;IAIN,SAAS,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAqBxC,OAAO,CAAC,KAAK,EAAE,eAAe;;;;;;;;;;;IAuF9B,OAAO,CAAC,EAAE,EAAE,MAAM;IAexB,OAAO,CAAC,2BAA2B;IAOnC,OAAO,CAAC,4BAA4B;IAOpC,OAAO,CAAC,kBAAkB;YAMZ,cAAc;IAqD5B,OAAO,CAAC,8BAA8B;YAgBxB,iCAAiC;YAoCjC,eAAe;YAgBf,eAAe;YAuBf,iBAAiB;YAsBjB,cAAc;IA4B5B,OAAO,CAAC,kBAAkB;IAuB1B,OAAO,CAAC,4BAA4B;IA6BpC,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,yBAAyB;IAQjC,OAAO,CAAC,qBAAqB;IAK7B,OAAO,CAAC,sBAAsB;YAIhB,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;YA+BlB,cAAc;YAuEd,cAAc;IAmF5B,OAAO,CAAC,6BAA6B;IAsCrC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as _onekeyfe_hd_transport from '@onekeyfe/hd-transport';
|
|
2
2
|
import _onekeyfe_hd_transport__default, { AcquireInput, TransportCallOptions, ProtocolType, OneKeyDeviceInfoBase, OneKeyDeviceInfo } from '@onekeyfe/hd-transport';
|
|
3
3
|
import { Deferred } from '@onekeyfe/hd-shared';
|
|
4
|
-
import EventEmitter from 'events';
|
|
5
4
|
import { DesktopAPI } from '@onekeyfe/hd-transport-electron';
|
|
5
|
+
import EventEmitter from 'events';
|
|
6
6
|
|
|
7
7
|
interface DeviceInfo extends OneKeyDeviceInfoBase {
|
|
8
8
|
path: string;
|
|
@@ -33,6 +33,7 @@ declare class WebUsbTransport {
|
|
|
33
33
|
getConnectedDevices(): Promise<DeviceInfo[]>;
|
|
34
34
|
acquire(input: AcquireInput): Promise<string | undefined>;
|
|
35
35
|
private createProtocolMismatchError;
|
|
36
|
+
private createProtocolDetectionError;
|
|
36
37
|
private detectProtocol;
|
|
37
38
|
findDevice(path: string): Promise<USBDevice>;
|
|
38
39
|
connect(path: string, first: boolean): Promise<void>;
|
|
@@ -56,47 +57,7 @@ declare class WebUsbTransport {
|
|
|
56
57
|
private receiveProtocolV2Frame;
|
|
57
58
|
receiveData(path: string, timeoutMs?: number): Promise<string>;
|
|
58
59
|
release(path: string): Promise<void>;
|
|
59
|
-
getProtocolType(path: string): ProtocolType;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
declare global {
|
|
63
|
-
interface Window {
|
|
64
|
-
desktopApi?: DesktopAPI;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
type BleAcquireInput$1 = {
|
|
68
|
-
uuid: string;
|
|
69
|
-
forceCleanRunPromise?: boolean;
|
|
70
|
-
};
|
|
71
|
-
declare class ElectronBleTransport {
|
|
72
|
-
_messages: ReturnType<typeof _onekeyfe_hd_transport__default.parseConfigure> | undefined;
|
|
73
|
-
name: string;
|
|
74
|
-
configured: boolean;
|
|
75
|
-
runPromise: Deferred<any> | null;
|
|
76
|
-
Log?: any;
|
|
77
|
-
emitter?: EventEmitter;
|
|
78
|
-
private connectedDevices;
|
|
79
|
-
private dataBuffers;
|
|
80
|
-
private notificationCleanups;
|
|
81
|
-
private disconnectCleanups;
|
|
82
|
-
getProtocolType(_path: string): ProtocolType;
|
|
83
|
-
private handleBluetoothError;
|
|
84
|
-
private cleanupDeviceState;
|
|
85
|
-
init(logger: any, emitter?: EventEmitter): void;
|
|
86
|
-
configure(signedData: any): void;
|
|
87
|
-
listen(): void;
|
|
88
|
-
enumerate(): Promise<{
|
|
89
|
-
id: string;
|
|
90
|
-
name: string;
|
|
91
|
-
}[]>;
|
|
92
|
-
acquire(input: BleAcquireInput$1): Promise<{
|
|
93
|
-
uuid: string;
|
|
94
|
-
path: string;
|
|
95
|
-
}>;
|
|
96
|
-
release(id: string): Promise<void>;
|
|
97
|
-
private handleNotificationData;
|
|
98
|
-
call(uuid: string, name: string, data: Record<string, unknown>): Promise<_onekeyfe_hd_transport.MessageFromOneKey>;
|
|
99
|
-
private processNotificationPacket;
|
|
60
|
+
getProtocolType(path: string): ProtocolType | undefined;
|
|
100
61
|
}
|
|
101
62
|
|
|
102
63
|
declare global {
|
|
@@ -109,7 +70,7 @@ type BleAcquireInput = {
|
|
|
109
70
|
forceCleanRunPromise?: boolean;
|
|
110
71
|
expectedProtocol?: ProtocolType;
|
|
111
72
|
};
|
|
112
|
-
declare class
|
|
73
|
+
declare class ElectronBleTransport {
|
|
113
74
|
private _messages;
|
|
114
75
|
private _messagesV2;
|
|
115
76
|
name: string;
|
|
@@ -150,6 +111,8 @@ declare class ElectronAutoBleTransport {
|
|
|
150
111
|
}>;
|
|
151
112
|
release(id: string): Promise<void>;
|
|
152
113
|
private createProtocolMismatchError;
|
|
114
|
+
private createProtocolDetectionError;
|
|
115
|
+
private clearProbeProtocol;
|
|
153
116
|
private detectProtocol;
|
|
154
117
|
private createNotificationSubscription;
|
|
155
118
|
private resetProbeStateAfterProtocolProbe;
|
|
@@ -170,7 +133,7 @@ declare class ElectronAutoBleTransport {
|
|
|
170
133
|
private callProtocolV1;
|
|
171
134
|
private callProtocolV2;
|
|
172
135
|
private processProtocolV1Notification;
|
|
173
|
-
getProtocolType(path: string): ProtocolType;
|
|
136
|
+
getProtocolType(path: string): ProtocolType | undefined;
|
|
174
137
|
}
|
|
175
138
|
|
|
176
|
-
export {
|
|
139
|
+
export { ElectronBleTransport, WebUsbTransport };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,UAAU,CAAC;AACvC,OAAO,oBAAoB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,UAAU,CAAC;AACvC,OAAO,oBAAoB,MAAM,0BAA0B,CAAC;AAE5D,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,CAAC"}
|