@onekeyfe/hd-transport-react-native 0.0.7 → 0.0.10

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.
@@ -8,4 +8,13 @@ export declare const getConnectedDeviceIds: (serviceUuids: string[]) => Promise<
8
8
  id: string;
9
9
  name: string | undefined;
10
10
  }[]>;
11
+ export declare const getBondedDevices: () => Promise<{
12
+ isConnectable?: boolean | undefined;
13
+ localName?: string | undefined;
14
+ manufacturerData?: any;
15
+ serviceUUIDs?: string[] | undefined;
16
+ txPowerLevel?: number | undefined;
17
+ id: string;
18
+ name: string | undefined;
19
+ }[]>;
11
20
  //# sourceMappingURL=BleManager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BleManager.d.ts","sourceRoot":"","sources":["../src/BleManager.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,YAEhC,CAAC;AAOF,eAAO,MAAM,qBAAqB,iBAAwB,MAAM,EAAE;;;;;;;;IAMjE,CAAC"}
1
+ {"version":3,"file":"BleManager.d.ts","sourceRoot":"","sources":["../src/BleManager.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,YAEhC,CAAC;AAOF,eAAO,MAAM,qBAAqB,iBAAwB,MAAM,EAAE;;;;;;;;IAMjE,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;;;;;IAM5B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,SAAiC,MAAM,wBAAwB,CAAC;AACvE,OAAO,EACL,UAAU,IAAI,aAAa,EAC3B,MAAM,EAEN,cAAc,EAEf,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,gBAAgB,EAChB,cAAc,EAIf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,QAAQ,EAA4B,MAAM,kBAAkB,CAAC;AAItE,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE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AAE,UAAU,CAAC,OAAO,SAAS,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAEnE,UAAU,UAAS;IAEnB,OAAO,UAAS;IAEhB,WAAW,SAAQ;IAEnB,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;gBAE5B,OAAO,EAAE,gBAAgB;IAIrC,IAAI;IAEJ,SAAS,CAAC,UAAU,EAAE,GAAG;IAMzB,MAAM;IAIN,aAAa,IAAI,OAAO,CAAC,aAAa,CAAC;IAYjC,SAAS;IAoET,OAAO,CAAC,KAAK,EAAE,eAAe;;;IA2JpC,sBAAsB,CAAC,cAAc,EAAE,cAAc;IA+C/C,OAAO,CAAC,IAAI,EAAE,MAAM;IAepB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAmDpE,IAAI;CAGL;AAED,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,CAAC"}
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var reactNative = require('react-native');
5
6
  var buffer = require('buffer');
6
7
  var transport = require('@onekeyfe/hd-transport');
7
8
  var reactNativeBlePlx = require('react-native-ble-plx');
@@ -47,6 +48,13 @@ const getConnectedDeviceIds = (serviceUuids) => __awaiter(void 0, void 0, void 0
47
48
  return Object.assign({ id, name }, advertising);
48
49
  });
49
50
  });
51
+ const getBondedDevices = () => __awaiter(void 0, void 0, void 0, function* () {
52
+ const peripherals = yield BleManager__default["default"].getBondedPeripherals();
53
+ return peripherals.map(peripheral => {
54
+ const { id, name, advertising = {} } = peripheral;
55
+ return Object.assign({ id, name }, advertising);
56
+ });
57
+ });
50
58
 
51
59
  const PERMISSION_ERROR = 'Bluetooth required to be turned on';
52
60
  const LOCATION_ERROR = 'Device is not authorized to use BluetoothLE';
@@ -281,7 +289,7 @@ class ReactNativeBleTransport {
281
289
  if (!uuid) {
282
290
  throw new Error('uuid is required');
283
291
  }
284
- let device;
292
+ let device = null;
285
293
  if (transportCache[uuid]) {
286
294
  console.log('@onekey/hd-ble-sdk transport not be released, will release: ', uuid);
287
295
  yield this.release(uuid);
@@ -341,6 +349,13 @@ class ReactNativeBleTransport {
341
349
  }
342
350
  }
343
351
  }
352
+ if (reactNative.Platform.OS === 'android') {
353
+ const bondedDevices = yield getBondedDevices();
354
+ const hasBonded = !!bondedDevices.find(bondedDevice => bondedDevice.id === (device === null || device === void 0 ? void 0 : device.id));
355
+ if (!hasBonded) {
356
+ throw new Error('device is not bonded');
357
+ }
358
+ }
344
359
  yield device.discoverAllServicesAndCharacteristics();
345
360
  let infos = tryToGetConfiguration(device);
346
361
  let characteristics;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-react-native",
3
- "version": "0.0.7",
3
+ "version": "0.0.10",
4
4
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -20,9 +20,9 @@
20
20
  "lint:fix": "eslint . --fix"
21
21
  },
22
22
  "dependencies": {
23
- "@onekeyfe/hd-transport": "^0.0.7",
23
+ "@onekeyfe/hd-transport": "^0.0.10",
24
24
  "react-native-ble-manager": "^8.1.0",
25
25
  "react-native-ble-plx": "^2.0.3"
26
26
  },
27
- "gitHead": "7be7677368fcb50f411891f009367424ea77df33"
27
+ "gitHead": "b1f3f06c56fda840f4e55f2d033f7b84f16e8873"
28
28
  }
package/src/BleManager.ts CHANGED
@@ -16,3 +16,11 @@ export const getConnectedDeviceIds = async (serviceUuids: string[]) => {
16
16
  return { id, name, ...advertising };
17
17
  });
18
18
  };
19
+
20
+ export const getBondedDevices = async () => {
21
+ const peripherals = await BleManager.getBondedPeripherals();
22
+ return peripherals.map(peripheral => {
23
+ const { id, name, advertising = {} } = peripheral;
24
+ return { id, name, ...advertising };
25
+ });
26
+ };
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Platform } from 'react-native';
1
2
  import { Buffer } from 'buffer';
2
3
  import transport, { COMMON_HEADER_SIZE } from '@onekeyfe/hd-transport';
3
4
  import {
@@ -7,7 +8,7 @@ import {
7
8
  Characteristic,
8
9
  ScanMode,
9
10
  } from 'react-native-ble-plx';
10
- import { initializeBleManager, getConnectedDeviceIds } from './BleManager';
11
+ import { initializeBleManager, getConnectedDeviceIds, getBondedDevices } from './BleManager';
11
12
  import { subscribeBleOn } from './subscribeBleOn';
12
13
  import {
13
14
  PERMISSION_ERROR,
@@ -155,7 +156,7 @@ export default class ReactNativeBleTransport {
155
156
  throw new Error('uuid is required');
156
157
  }
157
158
 
158
- let device;
159
+ let device: Device | null = null;
159
160
 
160
161
  if (transportCache[uuid]) {
161
162
  /**
@@ -227,6 +228,15 @@ export default class ReactNativeBleTransport {
227
228
  }
228
229
  }
229
230
 
231
+ // check device is bonded
232
+ if (Platform.OS === 'android') {
233
+ const bondedDevices = await getBondedDevices();
234
+ const hasBonded = !!bondedDevices.find(bondedDevice => bondedDevice.id === device?.id);
235
+ if (!hasBonded) {
236
+ throw new Error('device is not bonded');
237
+ }
238
+ }
239
+
230
240
  await device.discoverAllServicesAndCharacteristics();
231
241
  let infos = tryToGetConfiguration(device);
232
242
  let characteristics;