@onekeyfe/hd-transport-web-device 1.1.34-alpha.2 → 1.1.34-alpha.3
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 +342 -0
- package/__tests__/webusb-protocol-v2-timeout.test.ts +65 -0
- package/dist/electron-ble-transport.d.ts +50 -14
- package/dist/electron-ble-transport.d.ts.map +1 -1
- package/dist/index.d.ts +173 -18
- package/dist/index.js +922 -144
- package/dist/transportLog.d.ts +7 -0
- package/dist/transportLog.d.ts.map +1 -0
- package/dist/webusb.d.ts +32 -3
- package/dist/webusb.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/electron-ble-transport.ts +595 -172
- package/src/transportLog.ts +11 -0
- package/src/webusb.ts +593 -53
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import transport, { PROTOCOL_V2_CHANNEL_BLE_UART, bytesToHex } from '@onekeyfe/hd-transport';
|
|
2
|
+
import { HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
3
|
+
|
|
4
|
+
import ElectronBleTransport from '../src/electron-ble-transport';
|
|
5
|
+
|
|
6
|
+
const { ProtocolV1, ProtocolV2, parseConfigure } = transport;
|
|
7
|
+
|
|
8
|
+
const protocolV1Schema = {
|
|
9
|
+
nested: {
|
|
10
|
+
Initialize: {
|
|
11
|
+
fields: {},
|
|
12
|
+
},
|
|
13
|
+
Success: {
|
|
14
|
+
fields: {
|
|
15
|
+
message: {
|
|
16
|
+
type: 'string',
|
|
17
|
+
id: 1,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
MessageType: {
|
|
22
|
+
values: {
|
|
23
|
+
MessageType_Initialize: 1,
|
|
24
|
+
MessageType_Success: 2,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const protocolV2Schema = {
|
|
31
|
+
nested: {
|
|
32
|
+
ProtocolInfoRequest: {
|
|
33
|
+
fields: {},
|
|
34
|
+
},
|
|
35
|
+
ProtocolInfo: {
|
|
36
|
+
fields: {
|
|
37
|
+
version: {
|
|
38
|
+
type: 'uint32',
|
|
39
|
+
id: 1,
|
|
40
|
+
},
|
|
41
|
+
supported_messages: {
|
|
42
|
+
rule: 'repeated',
|
|
43
|
+
type: 'uint32',
|
|
44
|
+
id: 2,
|
|
45
|
+
options: {
|
|
46
|
+
packed: false,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
protobuf_definition: {
|
|
50
|
+
type: 'string',
|
|
51
|
+
id: 3,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
Ping: {
|
|
56
|
+
fields: {
|
|
57
|
+
message: {
|
|
58
|
+
type: 'string',
|
|
59
|
+
id: 1,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
Success: {
|
|
64
|
+
fields: {
|
|
65
|
+
message: {
|
|
66
|
+
type: 'string',
|
|
67
|
+
id: 1,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
MessageType: {
|
|
72
|
+
values: {
|
|
73
|
+
MessageType_ProtocolInfoRequest: 60200,
|
|
74
|
+
MessageType_ProtocolInfo: 60201,
|
|
75
|
+
MessageType_Ping: 60206,
|
|
76
|
+
MessageType_Success: 60207,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const schemas = {
|
|
83
|
+
protocolV1: parseConfigure(protocolV1Schema),
|
|
84
|
+
protocolV2: parseConfigure(protocolV2Schema),
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
jest.setTimeout(10_000);
|
|
88
|
+
|
|
89
|
+
const createLogger = () => ({
|
|
90
|
+
debug: jest.fn(),
|
|
91
|
+
error: jest.fn(),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const createNobleBle = (device = { id: 'flaky-pro2-id', name: 'Unknown BLE Device' }) => ({
|
|
95
|
+
enumerate: jest.fn(() => Promise.resolve([device])),
|
|
96
|
+
getDevice: jest.fn(() => Promise.resolve(device)),
|
|
97
|
+
connect: jest.fn(() => Promise.resolve()),
|
|
98
|
+
disconnect: jest.fn(() => Promise.resolve()),
|
|
99
|
+
subscribe: jest.fn(() => Promise.resolve()),
|
|
100
|
+
unsubscribe: jest.fn(() => Promise.resolve()),
|
|
101
|
+
write: jest.fn(() => Promise.resolve()),
|
|
102
|
+
onNotification: jest.fn(() => jest.fn()),
|
|
103
|
+
onDeviceDisconnected: jest.fn(() => jest.fn()),
|
|
104
|
+
checkAvailability: jest.fn(() =>
|
|
105
|
+
Promise.resolve({
|
|
106
|
+
available: true,
|
|
107
|
+
state: 'poweredOn',
|
|
108
|
+
unsupported: false,
|
|
109
|
+
initialized: true,
|
|
110
|
+
})
|
|
111
|
+
),
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const configureTransport = (nobleBle: ReturnType<typeof createNobleBle>) => {
|
|
115
|
+
(global as any).window = {
|
|
116
|
+
desktopApi: {
|
|
117
|
+
nobleBle,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const transport = new ElectronBleTransport();
|
|
122
|
+
transport.init(createLogger());
|
|
123
|
+
transport.configure(protocolV1Schema);
|
|
124
|
+
transport.configureProtocolV2(protocolV2Schema);
|
|
125
|
+
return transport;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
describe('ElectronBleTransport protocol detection', () => {
|
|
129
|
+
afterEach(() => {
|
|
130
|
+
delete (global as any).window;
|
|
131
|
+
jest.clearAllMocks();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('detects Protocol V2 after Protocol V1 probe timeout', async () => {
|
|
135
|
+
const device = { id: 'unknown-pro2-id', name: 'Unknown BLE Device' };
|
|
136
|
+
const nobleBle = createNobleBle(device);
|
|
137
|
+
let notificationHandler: ((deviceId: string, data: string) => void) | undefined;
|
|
138
|
+
const probeResponse = ProtocolV2.encodeFrame(
|
|
139
|
+
schemas,
|
|
140
|
+
'Success',
|
|
141
|
+
{ message: 'ok' },
|
|
142
|
+
{ router: PROTOCOL_V2_CHANNEL_BLE_UART }
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
nobleBle.onNotification.mockImplementation(handler => {
|
|
146
|
+
notificationHandler = handler;
|
|
147
|
+
return jest.fn();
|
|
148
|
+
});
|
|
149
|
+
let writeCount = 0;
|
|
150
|
+
nobleBle.write.mockImplementation(() => {
|
|
151
|
+
writeCount += 1;
|
|
152
|
+
if (writeCount === 2) {
|
|
153
|
+
setTimeout(() => notificationHandler?.(device.id, bytesToHex(probeResponse)), 0);
|
|
154
|
+
}
|
|
155
|
+
return Promise.resolve();
|
|
156
|
+
});
|
|
157
|
+
const transport = configureTransport(nobleBle);
|
|
158
|
+
|
|
159
|
+
try {
|
|
160
|
+
await expect(transport.acquire({ uuid: device.id })).resolves.toEqual(
|
|
161
|
+
expect.objectContaining({
|
|
162
|
+
uuid: device.id,
|
|
163
|
+
protocolType: 'V2',
|
|
164
|
+
})
|
|
165
|
+
);
|
|
166
|
+
expect(transport.getProtocolType(device.id)).toBe('V2');
|
|
167
|
+
} finally {
|
|
168
|
+
await transport.release(device.id);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test('detects Protocol V1 when device responds to Initialize', async () => {
|
|
173
|
+
const device = { id: 'classic-id', name: 'OneKey Classic' };
|
|
174
|
+
const nobleBle = createNobleBle(device);
|
|
175
|
+
let notificationHandler: ((deviceId: string, data: string) => void) | undefined;
|
|
176
|
+
|
|
177
|
+
// Build a V1 Success notification (no 64-byte padding, matching real BLE behaviour).
|
|
178
|
+
// Format: ?## (3f2323) + typeId BE (0002) + length BE (00000004) + protobuf payload (0a026f6b)
|
|
179
|
+
const v1ResponseHex = '3f23230002000000040a026f6b';
|
|
180
|
+
|
|
181
|
+
nobleBle.onNotification.mockImplementation(handler => {
|
|
182
|
+
notificationHandler = handler;
|
|
183
|
+
return jest.fn();
|
|
184
|
+
});
|
|
185
|
+
nobleBle.write.mockImplementation(() => {
|
|
186
|
+
// Respond to first write (V1 Initialize probe) with V1 Success
|
|
187
|
+
setTimeout(() => notificationHandler?.(device.id, v1ResponseHex), 0);
|
|
188
|
+
return Promise.resolve();
|
|
189
|
+
});
|
|
190
|
+
const transport = configureTransport(nobleBle);
|
|
191
|
+
|
|
192
|
+
try {
|
|
193
|
+
await expect(transport.acquire({ uuid: device.id })).resolves.toEqual(
|
|
194
|
+
expect.objectContaining({
|
|
195
|
+
uuid: device.id,
|
|
196
|
+
})
|
|
197
|
+
);
|
|
198
|
+
expect(transport.getProtocolType(device.id)).toBe('V1');
|
|
199
|
+
} finally {
|
|
200
|
+
await transport.release(device.id);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test('throws when both protocol probes fail', async () => {
|
|
205
|
+
const device = { id: 'dead-device-id', name: 'Unknown Device' };
|
|
206
|
+
const nobleBle = createNobleBle(device);
|
|
207
|
+
|
|
208
|
+
// Never respond to writes — both probes will timeout
|
|
209
|
+
nobleBle.onNotification.mockImplementation(() => jest.fn());
|
|
210
|
+
|
|
211
|
+
const transport = configureTransport(nobleBle);
|
|
212
|
+
|
|
213
|
+
await expect(transport.acquire({ uuid: device.id })).rejects.toThrow(
|
|
214
|
+
/Unable to detect BLE protocol/
|
|
215
|
+
);
|
|
216
|
+
expect(transport.getProtocolType(device.id)).toBeUndefined();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test('probes Protocol V2 instead of trusting the Pro2 name hint', async () => {
|
|
220
|
+
const device = { id: 'named-pro2-id', name: 'OneKey Pro 2' };
|
|
221
|
+
const nobleBle = createNobleBle(device);
|
|
222
|
+
let notificationHandler: ((deviceId: string, data: string) => void) | undefined;
|
|
223
|
+
const probeResponse = ProtocolV2.encodeFrame(
|
|
224
|
+
schemas,
|
|
225
|
+
'Success',
|
|
226
|
+
{ message: 'ok' },
|
|
227
|
+
{ router: PROTOCOL_V2_CHANNEL_BLE_UART }
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
nobleBle.onNotification.mockImplementation(handler => {
|
|
231
|
+
notificationHandler = handler;
|
|
232
|
+
return jest.fn();
|
|
233
|
+
});
|
|
234
|
+
nobleBle.write.mockImplementation(() => {
|
|
235
|
+
setTimeout(() => notificationHandler?.(device.id, bytesToHex(probeResponse)), 0);
|
|
236
|
+
return Promise.resolve();
|
|
237
|
+
});
|
|
238
|
+
const transport = configureTransport(nobleBle);
|
|
239
|
+
|
|
240
|
+
try {
|
|
241
|
+
await expect(transport.acquire({ uuid: device.id })).resolves.toEqual(
|
|
242
|
+
expect.objectContaining({
|
|
243
|
+
uuid: device.id,
|
|
244
|
+
protocolType: 'V2',
|
|
245
|
+
})
|
|
246
|
+
);
|
|
247
|
+
expect(nobleBle.write).toHaveBeenCalledTimes(1);
|
|
248
|
+
expect(transport.getProtocolType(device.id)).toBe('V2');
|
|
249
|
+
await expect(transport.call(device.id, 'Ping', { message: 'after-probe' })).resolves.toEqual({
|
|
250
|
+
type: 'Success',
|
|
251
|
+
message: { message: 'ok' },
|
|
252
|
+
});
|
|
253
|
+
const sentSeqs = nobleBle.write.mock.calls.map(([, hex]) =>
|
|
254
|
+
Number.parseInt(hex.slice(12, 14), 16)
|
|
255
|
+
);
|
|
256
|
+
expect(sentSeqs).toEqual([1, 2]);
|
|
257
|
+
} finally {
|
|
258
|
+
await transport.release(device.id);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
test('rejects the active Protocol V2 reader when pairing is rejected', async () => {
|
|
263
|
+
const device = { id: 'pairing-rejected-pro2-id', name: 'OneKey Pro 2' };
|
|
264
|
+
const nobleBle = createNobleBle(device);
|
|
265
|
+
let notificationHandler: ((deviceId: string, data: string) => void) | undefined;
|
|
266
|
+
let pairingRejected = false;
|
|
267
|
+
const probeResponse = ProtocolV2.encodeFrame(
|
|
268
|
+
schemas,
|
|
269
|
+
'Success',
|
|
270
|
+
{ message: 'ok' },
|
|
271
|
+
{ router: PROTOCOL_V2_CHANNEL_BLE_UART }
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
nobleBle.onNotification.mockImplementation(handler => {
|
|
275
|
+
notificationHandler = handler;
|
|
276
|
+
return jest.fn();
|
|
277
|
+
});
|
|
278
|
+
nobleBle.write.mockImplementation(() => {
|
|
279
|
+
setTimeout(
|
|
280
|
+
() =>
|
|
281
|
+
notificationHandler?.(
|
|
282
|
+
device.id,
|
|
283
|
+
pairingRejected ? 'PAIRING_REJECTED' : bytesToHex(probeResponse)
|
|
284
|
+
),
|
|
285
|
+
0
|
|
286
|
+
);
|
|
287
|
+
return Promise.resolve();
|
|
288
|
+
});
|
|
289
|
+
const transport = configureTransport(nobleBle);
|
|
290
|
+
|
|
291
|
+
try {
|
|
292
|
+
await transport.acquire({ uuid: device.id });
|
|
293
|
+
pairingRejected = true;
|
|
294
|
+
|
|
295
|
+
await expect(
|
|
296
|
+
transport.call(device.id, 'Ping', { message: 'pairing' }, { timeoutMs: 50 })
|
|
297
|
+
).rejects.toMatchObject({ errorCode: HardwareErrorCode.BleDeviceBondedCanceled });
|
|
298
|
+
} finally {
|
|
299
|
+
await transport.release(device.id);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test('rebuilds the active link when Core acquires the same device again', async () => {
|
|
304
|
+
const device = { id: 'repeated-acquire-pro2-id', name: 'OneKey Pro 2' };
|
|
305
|
+
const nobleBle = createNobleBle(device);
|
|
306
|
+
let notificationHandler: ((deviceId: string, data: string) => void) | undefined;
|
|
307
|
+
const response = ProtocolV2.encodeFrame(
|
|
308
|
+
schemas,
|
|
309
|
+
'Success',
|
|
310
|
+
{ message: 'ok' },
|
|
311
|
+
{ router: PROTOCOL_V2_CHANNEL_BLE_UART }
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
nobleBle.onNotification.mockImplementation(handler => {
|
|
315
|
+
notificationHandler = handler;
|
|
316
|
+
return jest.fn();
|
|
317
|
+
});
|
|
318
|
+
nobleBle.write.mockImplementation(() => {
|
|
319
|
+
setTimeout(() => notificationHandler?.(device.id, bytesToHex(response)), 0);
|
|
320
|
+
return Promise.resolve();
|
|
321
|
+
});
|
|
322
|
+
const transport = configureTransport(nobleBle);
|
|
323
|
+
|
|
324
|
+
try {
|
|
325
|
+
await transport.acquire({ uuid: device.id });
|
|
326
|
+
await transport.acquire({ uuid: device.id, expectedProtocol: 'V2' });
|
|
327
|
+
await expect(
|
|
328
|
+
transport.call(device.id, 'Ping', { message: 'after-reacquire' })
|
|
329
|
+
).resolves.toEqual({
|
|
330
|
+
type: 'Success',
|
|
331
|
+
message: { message: 'ok' },
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
const sentSeqs = nobleBle.write.mock.calls.map(([, hex]) =>
|
|
335
|
+
Number.parseInt(hex.slice(12, 14), 16)
|
|
336
|
+
);
|
|
337
|
+
expect(sentSeqs).toEqual([1, 2]);
|
|
338
|
+
} finally {
|
|
339
|
+
await transport.release(device.id);
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import transport, { ProtocolV2FrameAssembler } from '@onekeyfe/hd-transport';
|
|
2
|
+
|
|
3
|
+
import WebUsbTransport from '../src/webusb';
|
|
4
|
+
|
|
5
|
+
const schema = {
|
|
6
|
+
nested: {
|
|
7
|
+
Ping: { fields: { message: { type: 'string', id: 1 } } },
|
|
8
|
+
Success: { fields: { message: { type: 'string', id: 1 } } },
|
|
9
|
+
MessageType: {
|
|
10
|
+
values: {
|
|
11
|
+
MessageType_Ping: 60206,
|
|
12
|
+
MessageType_Success: 60207,
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
describe('WebUsbTransport Protocol V2 timeout recovery', () => {
|
|
19
|
+
test('invalidates and resets the cached connection before another call can start', async () => {
|
|
20
|
+
const webusb = new WebUsbTransport() as any;
|
|
21
|
+
const path = 'pro2-webusb';
|
|
22
|
+
webusb.messages = transport.parseConfigure(schema);
|
|
23
|
+
webusb.messagesV2 = transport.parseConfigure(schema);
|
|
24
|
+
webusb.protocolV2Assemblers.set(path, new ProtocolV2FrameAssembler());
|
|
25
|
+
webusb.transferOutOnce = jest.fn().mockResolvedValue(undefined);
|
|
26
|
+
webusb.receiveProtocolV2Frame = jest.fn(() => new Promise(() => {}));
|
|
27
|
+
webusb.resetConnectionAfterProbe = jest.fn().mockImplementation(() => {
|
|
28
|
+
webusb.protocolV2Sessions.delete(path);
|
|
29
|
+
webusb.protocolV2ReadTimeouts.delete(path);
|
|
30
|
+
webusb.protocolV2Assemblers.get(path)?.reset();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
await expect(
|
|
34
|
+
webusb.callProtocolV2(path, 'Ping', { message: 'timeout' }, { timeoutMs: 10 })
|
|
35
|
+
).rejects.toThrow('timeout');
|
|
36
|
+
|
|
37
|
+
expect(webusb.resetConnectionAfterProbe).toHaveBeenCalledWith(path);
|
|
38
|
+
expect(webusb.protocolV2Sessions.has(path)).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('resets a stalled write while retaining the device sequence cursor', async () => {
|
|
42
|
+
const webusb = new WebUsbTransport() as any;
|
|
43
|
+
const path = 'pro2-webusb';
|
|
44
|
+
webusb.messages = transport.parseConfigure(schema);
|
|
45
|
+
webusb.messagesV2 = transport.parseConfigure(schema);
|
|
46
|
+
webusb.protocolV2WriteTimeoutMs = 10;
|
|
47
|
+
webusb.protocolV2Assemblers.set(path, new ProtocolV2FrameAssembler());
|
|
48
|
+
webusb.transferOutOnce = jest.fn(() => new Promise(() => {}));
|
|
49
|
+
webusb.receiveProtocolV2Frame = jest.fn();
|
|
50
|
+
webusb.resetConnectionAfterProbe = jest.fn().mockImplementation(() => {
|
|
51
|
+
webusb.protocolV2Sessions.delete(path);
|
|
52
|
+
webusb.protocolV2ReadTimeouts.delete(path);
|
|
53
|
+
webusb.protocolV2Assemblers.get(path)?.reset();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
await expect(
|
|
57
|
+
webusb.callProtocolV2(path, 'Ping', { message: 'timeout' }, { timeoutMs: 10 })
|
|
58
|
+
).rejects.toThrow('Protocol V2 write timeout after 10ms for Ping');
|
|
59
|
+
|
|
60
|
+
expect(webusb.resetConnectionAfterProbe).toHaveBeenCalledWith(path);
|
|
61
|
+
expect(webusb.protocolV2Sequences.has(path)).toBe(true);
|
|
62
|
+
expect(webusb.protocolV2Sessions.has(path)).toBe(false);
|
|
63
|
+
expect(webusb.receiveProtocolV2Frame).not.toHaveBeenCalled();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -1,8 +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
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';
|
|
6
6
|
declare global {
|
|
7
7
|
interface Window {
|
|
8
8
|
desktopApi?: DesktopAPI;
|
|
@@ -11,35 +11,71 @@ declare global {
|
|
|
11
11
|
export type BleAcquireInput = {
|
|
12
12
|
uuid: string;
|
|
13
13
|
forceCleanRunPromise?: boolean;
|
|
14
|
+
expectedProtocol?: ProtocolType;
|
|
14
15
|
};
|
|
15
16
|
export default class ElectronBleTransport {
|
|
16
|
-
_messages
|
|
17
|
+
private _messages;
|
|
18
|
+
private _messagesV2;
|
|
17
19
|
name: string;
|
|
18
20
|
configured: boolean;
|
|
19
|
-
runPromise: Deferred<
|
|
21
|
+
runPromise: Deferred<Uint8Array | string> | null;
|
|
20
22
|
Log?: any;
|
|
21
23
|
emitter?: EventEmitter;
|
|
22
24
|
private connectedDevices;
|
|
23
|
-
private
|
|
25
|
+
private deviceProtocol;
|
|
26
|
+
private deviceProtocolHints;
|
|
27
|
+
private v1Buffers;
|
|
28
|
+
private v2Assemblers;
|
|
29
|
+
private v2FrameQueues;
|
|
30
|
+
private v2FramePromises;
|
|
31
|
+
private protocolV2Links;
|
|
24
32
|
private notificationCleanups;
|
|
25
33
|
private disconnectCleanups;
|
|
34
|
+
private notificationTokens;
|
|
35
|
+
private nextNotificationToken;
|
|
26
36
|
private handleBluetoothError;
|
|
27
37
|
private cleanupDeviceState;
|
|
28
38
|
init(logger: any, emitter?: EventEmitter): void;
|
|
29
39
|
configure(signedData: any): void;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
name: string;
|
|
34
|
-
}[]>;
|
|
40
|
+
configureProtocolV2(signedData: any): void;
|
|
41
|
+
listen(): Promise<OneKeyDeviceInfo[]>;
|
|
42
|
+
enumerate(): Promise<OneKeyDeviceInfo[]>;
|
|
35
43
|
acquire(input: BleAcquireInput): Promise<{
|
|
36
44
|
uuid: string;
|
|
45
|
+
commType: import("@onekeyfe/hd-transport").OneKeyDeviceCommType;
|
|
37
46
|
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;
|
|
38
53
|
}>;
|
|
39
54
|
release(id: string): Promise<void>;
|
|
40
|
-
|
|
41
|
-
private
|
|
42
|
-
|
|
43
|
-
private
|
|
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;
|
|
44
80
|
}
|
|
45
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":";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,EAAE,MAAM,wBAAwB,CAAC;AACnG,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AAIvC,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,o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