@onekeyfe/hd-transport-react-native 1.2.8-alpha.114 → 1.2.8-alpha.116
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 +27 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +290 -35
- package/package.json +5 -5
- package/src/__tests__/enumerate.test.ts +0 -139
- package/src/__tests__/nativeFrameWrite.test.ts +917 -0
- package/src/index.ts +412 -54
|
@@ -214,142 +214,3 @@ describe('ReactNativeBleTransport iOS discovery', () => {
|
|
|
214
214
|
expect(devices.map(device => device.id)).toEqual(['wallet-peripheral']);
|
|
215
215
|
});
|
|
216
216
|
});
|
|
217
|
-
|
|
218
|
-
describe('ReactNativeBleTransport advertisement color', () => {
|
|
219
|
-
const PRO2_SERVICE_UUIDS = [
|
|
220
|
-
'0000180a-0000-1000-8000-00805f9b34fb',
|
|
221
|
-
'0000180f-0000-1000-8000-00805f9b34fb',
|
|
222
|
-
'0000fffd-0000-1000-8000-00805f9b34fb',
|
|
223
|
-
ONEKEY_SERVICE_UUID,
|
|
224
|
-
];
|
|
225
|
-
const manufacturerData = (bytes: number[]) => Buffer.from(bytes).toString('base64');
|
|
226
|
-
|
|
227
|
-
const scanOnce = async (advertisements: Record<string, unknown>[]) => {
|
|
228
|
-
const blePlxManager = {
|
|
229
|
-
startDeviceScan: jest.fn((_serviceUUIDs, _options, listener) => {
|
|
230
|
-
queueMicrotask(() => {
|
|
231
|
-
advertisements.forEach(advertisement => listener(null, advertisement));
|
|
232
|
-
});
|
|
233
|
-
}),
|
|
234
|
-
stopDeviceScan: jest.fn(),
|
|
235
|
-
};
|
|
236
|
-
const transport = new ReactNativeBleTransport({ scanTimeout: 1 });
|
|
237
|
-
transport.blePlxManager = blePlxManager as never;
|
|
238
|
-
transport.init({ debug: jest.fn(), error: jest.fn() }, new EventEmitter());
|
|
239
|
-
return transport.enumerate();
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
beforeEach(() => {
|
|
243
|
-
jest.clearAllMocks();
|
|
244
|
-
jest.mocked(getConnectedDeviceIds).mockResolvedValue([]);
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
afterEach(() => {
|
|
248
|
-
Object.assign(Platform, { OS: 'ios', Version: undefined });
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
test('keeps the color from an unnamed iOS advertisement for the named device', async () => {
|
|
252
|
-
const devices = await scanOnce([
|
|
253
|
-
{
|
|
254
|
-
id: 'COLOR-UNNAMED',
|
|
255
|
-
name: null,
|
|
256
|
-
localName: null,
|
|
257
|
-
serviceUUIDs: PRO2_SERVICE_UUIDS,
|
|
258
|
-
manufacturerData: manufacturerData([0x42, 0, 0, 0, 0]),
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
id: 'COLOR-UNNAMED',
|
|
262
|
-
name: 'Pro 2 769D',
|
|
263
|
-
localName: 'Pro 2 769D',
|
|
264
|
-
serviceUUIDs: PRO2_SERVICE_UUIDS,
|
|
265
|
-
manufacturerData: null,
|
|
266
|
-
},
|
|
267
|
-
]);
|
|
268
|
-
|
|
269
|
-
expect(devices).toHaveLength(1);
|
|
270
|
-
expect(devices[0]).toMatchObject({ id: 'COLOR-UNNAMED', bleColorCode: 'B' });
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
test('fills a later color without letting a legacy payload clear it', async () => {
|
|
274
|
-
Object.assign(Platform, { OS: 'android', Version: 30 });
|
|
275
|
-
|
|
276
|
-
const devices = await scanOnce([
|
|
277
|
-
{
|
|
278
|
-
id: 'AA:BB:CC:00:00:01',
|
|
279
|
-
name: 'Neo 1A2B',
|
|
280
|
-
serviceUUIDs: PRO2_SERVICE_UUIDS,
|
|
281
|
-
manufacturerData: null,
|
|
282
|
-
},
|
|
283
|
-
{
|
|
284
|
-
id: 'AA:BB:CC:00:00:01',
|
|
285
|
-
name: 'Neo 1A2B',
|
|
286
|
-
serviceUUIDs: PRO2_SERVICE_UUIDS,
|
|
287
|
-
manufacturerData: manufacturerData([0x45, 0, 0, 0, 0]),
|
|
288
|
-
},
|
|
289
|
-
{
|
|
290
|
-
id: 'AA:BB:CC:00:00:01',
|
|
291
|
-
name: 'Neo 1A2B',
|
|
292
|
-
serviceUUIDs: PRO2_SERVICE_UUIDS,
|
|
293
|
-
manufacturerData: manufacturerData([0, 0, 0, 0]),
|
|
294
|
-
},
|
|
295
|
-
]);
|
|
296
|
-
|
|
297
|
-
expect(devices).toHaveLength(1);
|
|
298
|
-
expect(devices[0]).toMatchObject({ id: 'AA:BB:CC:00:00:01', bleColorCode: 'E' });
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
test('reports no color for legacy, unset or undecodable payloads', async () => {
|
|
302
|
-
const devices = await scanOnce([
|
|
303
|
-
{
|
|
304
|
-
id: 'LEGACY-NONCE',
|
|
305
|
-
name: 'Pro 2 0001',
|
|
306
|
-
serviceUUIDs: PRO2_SERVICE_UUIDS,
|
|
307
|
-
manufacturerData: manufacturerData([0, 0, 0, 0]),
|
|
308
|
-
},
|
|
309
|
-
{
|
|
310
|
-
id: 'SN-NOT-SYNCED',
|
|
311
|
-
name: 'Pro 2 0002',
|
|
312
|
-
serviceUUIDs: PRO2_SERVICE_UUIDS,
|
|
313
|
-
manufacturerData: manufacturerData([0, 0, 0, 0, 0]),
|
|
314
|
-
},
|
|
315
|
-
{
|
|
316
|
-
id: 'INVALID-BASE64',
|
|
317
|
-
name: 'Pro 2 0003',
|
|
318
|
-
serviceUUIDs: PRO2_SERVICE_UUIDS,
|
|
319
|
-
manufacturerData: '%%%',
|
|
320
|
-
},
|
|
321
|
-
]);
|
|
322
|
-
|
|
323
|
-
expect(devices.map(device => device.id)).toEqual([
|
|
324
|
-
'LEGACY-NONCE',
|
|
325
|
-
'SN-NOT-SYNCED',
|
|
326
|
-
'INVALID-BASE64',
|
|
327
|
-
]);
|
|
328
|
-
devices.forEach(device => expect(device).not.toHaveProperty('bleColorCode'));
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
test('reuses an earlier color for a connected peripheral that no longer advertises', async () => {
|
|
332
|
-
await scanOnce([
|
|
333
|
-
{
|
|
334
|
-
id: 'CONNECTED-NEO',
|
|
335
|
-
name: 'Neo 3C4D',
|
|
336
|
-
serviceUUIDs: PRO2_SERVICE_UUIDS,
|
|
337
|
-
manufacturerData: manufacturerData([0x46, 0, 0, 0, 0]),
|
|
338
|
-
},
|
|
339
|
-
]);
|
|
340
|
-
// iOS reports already-connected peripherals with lowercased ids.
|
|
341
|
-
jest.mocked(getConnectedDeviceIds).mockResolvedValueOnce([
|
|
342
|
-
{
|
|
343
|
-
id: 'connected-neo',
|
|
344
|
-
name: 'Neo 3C4D',
|
|
345
|
-
localName: null,
|
|
346
|
-
serviceUUIDs: [ONEKEY_SERVICE_UUID],
|
|
347
|
-
},
|
|
348
|
-
] as never);
|
|
349
|
-
|
|
350
|
-
const devices = await scanOnce([]);
|
|
351
|
-
|
|
352
|
-
expect(devices).toHaveLength(1);
|
|
353
|
-
expect(devices[0]).toMatchObject({ id: 'connected-neo', bleColorCode: 'F' });
|
|
354
|
-
});
|
|
355
|
-
});
|