@onekeyfe/hd-ble-sdk 1.2.8 → 1.2.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.
@@ -1,8 +1,16 @@
1
1
  import { readFileSync } from 'fs';
2
2
  import { resolve } from 'path';
3
3
  import EventEmitter from 'events';
4
- import { CORE_EVENT, initCore } from '@onekeyfe/hd-core';
5
- import { createDeferred } from '@onekeyfe/hd-shared';
4
+ import {
5
+ CORE_EVENT,
6
+ IFRAME,
7
+ LoggerNames,
8
+ UI_EVENT,
9
+ UI_REQUEST,
10
+ getLog,
11
+ initCore,
12
+ } from '@onekeyfe/hd-core';
13
+ import { HardwareErrorCode, createDeferred } from '@onekeyfe/hd-shared';
6
14
 
7
15
  import sdkExport, { messagePromises } from '../src';
8
16
 
@@ -57,6 +65,17 @@ describe('SDK request cleanup', () => {
57
65
  await sdk.dispose();
58
66
  });
59
67
 
68
+ test.each([
69
+ [HardwareErrorCode.BlePoweredOff, UI_REQUEST.BLUETOOTH_POWERED_OFF],
70
+ [HardwareErrorCode.BleUnsupported, UI_REQUEST.BLUETOOTH_UNSUPPORTED],
71
+ [HardwareErrorCode.BleLocationError, UI_REQUEST.LOCATION_PERMISSION],
72
+ ])('emits the adapter UI request for error %s', async (code, type) => {
73
+ const response = { success: false, payload: { code, error: 'Adapter unavailable' } };
74
+ core.handleMessage.mockResolvedValueOnce(response);
75
+ await expect(sdk.call({ method: 'searchDevices' })).resolves.toEqual(response);
76
+ expect(core.handleMessage).toHaveBeenNthCalledWith(2, expect.objectContaining({ type }));
77
+ });
78
+
60
79
  test('removes only the completed request when calls settle out of order', async () => {
61
80
  const first = createDeferred<unknown>();
62
81
  const second = createDeferred<unknown>();
@@ -72,6 +91,31 @@ describe('SDK request cleanup', () => {
72
91
  expect(Object.keys(messagePromises)).toHaveLength(0);
73
92
  });
74
93
 
94
+ test('keeps Monero and Zcash addresses out of the handled-message log', () => {
95
+ core.emit(CORE_EVENT, {
96
+ event: UI_EVENT,
97
+ type: UI_REQUEST.PREVIOUS_ADDRESS_RESULT,
98
+ payload: {
99
+ device: {},
100
+ method: 'moneroGetAddress',
101
+ data: { address: 'synthetic-xmr-address-marker', path: "m/44'/128'/0'" },
102
+ },
103
+ });
104
+ core.emit(CORE_EVENT, {
105
+ event: IFRAME.CALLBACK,
106
+ type: IFRAME.CALLBACK,
107
+ payload: {
108
+ callbackId: 'unregistered',
109
+ data: { network: 'zcash', success: true, payload: { ufvk: 'synthetic-ufvk-marker' } },
110
+ },
111
+ });
112
+
113
+ const logged = JSON.stringify(getLog().filter(entry => entry.prefix === LoggerNames.HdBleSdk));
114
+ expect(logged).toContain('moneroGetAddress');
115
+ expect(logged).toContain('unregistered');
116
+ expect(logged).not.toContain('synthetic-');
117
+ });
118
+
75
119
  test('waits for Core disposal and does not retain old listeners after reinitialization', async () => {
76
120
  const cleanup = createDeferred<void>();
77
121
  core.dispose.mockImplementationOnce(async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AASpD,eAAO,MAAM,eAAe,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAA;CAAO,CAAC;AA+JpE,QAAA,MAAM,cAAc,qCASlB,CAAC;AAEH,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AASpD,eAAO,MAAM,eAAe,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAA;CAAO,CAAC;AAyKpE,QAAA,MAAM,cAAc,qCASlB,CAAC;AAEH,eAAe,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -562,7 +562,8 @@ function handleMessage(message) {
562
562
  });
563
563
  }
564
564
  else {
565
- Log.debug('hd-ble-sdk handleMessage', JSON.stringify(message));
565
+ const blockLog = HardwareSdk.getLogBlockLabel(message);
566
+ Log.debug('hd-ble-sdk handleMessage', blockLog ? { event, type, method: blockLog } : JSON.stringify(HardwareSdk.getSafeLogPayload(message)));
566
567
  }
567
568
  }
568
569
  catch (error) {
@@ -632,7 +633,7 @@ const init = (settings) => __awaiter(void 0, void 0, void 0, function* () {
632
633
  }
633
634
  });
634
635
  const call = (params) => __awaiter(void 0, void 0, void 0, function* () {
635
- var _b, _c, _d;
636
+ var _b, _c, _d, _e, _f;
636
637
  const blockLog = HardwareSdk.getLogBlockLabel(params);
637
638
  Log.debug('call: ', blockLog !== null && blockLog !== void 0 ? blockLog : params);
638
639
  try {
@@ -640,13 +641,19 @@ const call = (params) => __awaiter(void 0, void 0, void 0, function* () {
640
641
  if (response) {
641
642
  Log.debug('response: ', blockLog ? '[REDACTED]' : response);
642
643
  if (!response.success) {
643
- if (((_b = response.payload) === null || _b === void 0 ? void 0 : _b.code) === hdShared.HardwareErrorCode.BlePermissionError) {
644
+ if (((_b = response.payload) === null || _b === void 0 ? void 0 : _b.code) === hdShared.HardwareErrorCode.BlePoweredOff) {
645
+ postMessage(HardwareSdk.createUiMessage(HardwareSdk.UI_REQUEST.BLUETOOTH_POWERED_OFF), false);
646
+ }
647
+ if (((_c = response.payload) === null || _c === void 0 ? void 0 : _c.code) === hdShared.HardwareErrorCode.BleUnsupported) {
648
+ postMessage(HardwareSdk.createUiMessage(HardwareSdk.UI_REQUEST.BLUETOOTH_UNSUPPORTED), false);
649
+ }
650
+ if (((_d = response.payload) === null || _d === void 0 ? void 0 : _d.code) === hdShared.HardwareErrorCode.BlePermissionError) {
644
651
  postMessage(HardwareSdk.createUiMessage(HardwareSdk.UI_REQUEST.BLUETOOTH_PERMISSION), false);
645
652
  }
646
- if (((_c = response.payload) === null || _c === void 0 ? void 0 : _c.code) === hdShared.HardwareErrorCode.BleLocationError) {
653
+ if (((_e = response.payload) === null || _e === void 0 ? void 0 : _e.code) === hdShared.HardwareErrorCode.BleLocationError) {
647
654
  postMessage(HardwareSdk.createUiMessage(HardwareSdk.UI_REQUEST.LOCATION_PERMISSION), false);
648
655
  }
649
- if (((_d = response.payload) === null || _d === void 0 ? void 0 : _d.code) === hdShared.HardwareErrorCode.BleLocationServicesDisabled) {
656
+ if (((_f = response.payload) === null || _f === void 0 ? void 0 : _f.code) === hdShared.HardwareErrorCode.BleLocationServicesDisabled) {
650
657
  postMessage(HardwareSdk.createUiMessage(HardwareSdk.UI_REQUEST.LOCATION_SERVICE_PERMISSION), false);
651
658
  }
652
659
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-ble-sdk",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
4
4
  "author": "OneKey",
5
5
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
6
6
  "license": "ISC",
@@ -21,9 +21,9 @@
21
21
  "lint:fix": "eslint . --fix"
22
22
  },
23
23
  "dependencies": {
24
- "@onekeyfe/hd-core": "1.2.8",
25
- "@onekeyfe/hd-shared": "1.2.8",
26
- "@onekeyfe/hd-transport-react-native": "1.2.8"
24
+ "@onekeyfe/hd-core": "1.2.9",
25
+ "@onekeyfe/hd-shared": "1.2.9",
26
+ "@onekeyfe/hd-transport-react-native": "1.2.9"
27
27
  },
28
- "gitHead": "9f016278a7f395bf66b8502815dc63191e162fd3"
28
+ "gitHead": "36cc567ae08ffb9190b44efc6430d4199343be9e"
29
29
  }
package/src/index.ts CHANGED
@@ -15,6 +15,7 @@ import HardwareSdk, {
15
15
  executeCallback,
16
16
  getLogBlockLabel,
17
17
  getLogger,
18
+ getSafeLogPayload,
18
19
  initCore,
19
20
  parseConnectSettings,
20
21
  setLoggerPostMessage,
@@ -72,7 +73,11 @@ function handleMessage(message: CoreMessage) {
72
73
  progress: message?.payload?.progress,
73
74
  });
74
75
  } else {
75
- Log.debug('hd-ble-sdk handleMessage', JSON.stringify(message));
76
+ const blockLog = getLogBlockLabel(message);
77
+ Log.debug(
78
+ 'hd-ble-sdk handleMessage',
79
+ blockLog ? { event, type, method: blockLog } : JSON.stringify(getSafeLogPayload(message))
80
+ );
76
81
  }
77
82
  } catch (error) {
78
83
  // ignore
@@ -162,6 +167,12 @@ const call = async (params: any) => {
162
167
  Log.debug('response: ', blockLog ? '[REDACTED]' : response);
163
168
 
164
169
  if (!response.success) {
170
+ if (response.payload?.code === HardwareErrorCode.BlePoweredOff) {
171
+ postMessage(createUiMessage(UI_REQUEST.BLUETOOTH_POWERED_OFF), false);
172
+ }
173
+ if (response.payload?.code === HardwareErrorCode.BleUnsupported) {
174
+ postMessage(createUiMessage(UI_REQUEST.BLUETOOTH_UNSUPPORTED), false);
175
+ }
165
176
  if (response.payload?.code === HardwareErrorCode.BlePermissionError) {
166
177
  /**
167
178
  * Send message notification when there is no Bluetooth access permission