@onekeyfe/hd-transport-react-native 0.0.8 → 0.0.9

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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AE,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;;;IAyJpC,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
@@ -47,6 +47,13 @@ const getConnectedDeviceIds = (serviceUuids) => __awaiter(void 0, void 0, void 0
47
47
  return Object.assign({ id, name }, advertising);
48
48
  });
49
49
  });
50
+ const getBondedDevices = () => __awaiter(void 0, void 0, void 0, function* () {
51
+ const peripherals = yield BleManager__default["default"].getBondedPeripherals();
52
+ return peripherals.map(peripheral => {
53
+ const { id, name, advertising = {} } = peripheral;
54
+ return Object.assign({ id, name }, advertising);
55
+ });
56
+ });
50
57
 
51
58
  const PERMISSION_ERROR = 'Bluetooth required to be turned on';
52
59
  const LOCATION_ERROR = 'Device is not authorized to use BluetoothLE';
@@ -281,7 +288,7 @@ class ReactNativeBleTransport {
281
288
  if (!uuid) {
282
289
  throw new Error('uuid is required');
283
290
  }
284
- let device;
291
+ let device = null;
285
292
  if (transportCache[uuid]) {
286
293
  console.log('@onekey/hd-ble-sdk transport not be released, will release: ', uuid);
287
294
  yield this.release(uuid);
@@ -341,6 +348,11 @@ class ReactNativeBleTransport {
341
348
  }
342
349
  }
343
350
  }
351
+ const bondedDevices = yield getBondedDevices();
352
+ const hasBonded = !!bondedDevices.find(bondedDevice => bondedDevice.id === (device === null || device === void 0 ? void 0 : device.id));
353
+ if (!hasBonded) {
354
+ throw new Error('device is not bonded');
355
+ }
344
356
  yield device.discoverAllServicesAndCharacteristics();
345
357
  let infos = tryToGetConfiguration(device);
346
358
  let characteristics;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-react-native",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
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.8",
23
+ "@onekeyfe/hd-transport": "^0.0.9",
24
24
  "react-native-ble-manager": "^8.1.0",
25
25
  "react-native-ble-plx": "^2.0.3"
26
26
  },
27
- "gitHead": "edfa30382fdf36182bc389c8ff1dd1a689096592"
27
+ "gitHead": "728d72e4c7ddc10227fff49c3cb8d4a0ff205fac"
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
@@ -7,7 +7,7 @@ import {
7
7
  Characteristic,
8
8
  ScanMode,
9
9
  } from 'react-native-ble-plx';
10
- import { initializeBleManager, getConnectedDeviceIds } from './BleManager';
10
+ import { initializeBleManager, getConnectedDeviceIds, getBondedDevices } from './BleManager';
11
11
  import { subscribeBleOn } from './subscribeBleOn';
12
12
  import {
13
13
  PERMISSION_ERROR,
@@ -155,7 +155,7 @@ export default class ReactNativeBleTransport {
155
155
  throw new Error('uuid is required');
156
156
  }
157
157
 
158
- let device;
158
+ let device: Device | null = null;
159
159
 
160
160
  if (transportCache[uuid]) {
161
161
  /**
@@ -227,6 +227,13 @@ export default class ReactNativeBleTransport {
227
227
  }
228
228
  }
229
229
 
230
+ // check device is bonded
231
+ const bondedDevices = await getBondedDevices();
232
+ const hasBonded = !!bondedDevices.find(bondedDevice => bondedDevice.id === device?.id);
233
+ if (!hasBonded) {
234
+ throw new Error('device is not bonded');
235
+ }
236
+
230
237
  await device.discoverAllServicesAndCharacteristics();
231
238
  let infos = tryToGetConfiguration(device);
232
239
  let characteristics;