@onekeyfe/hardware-cli 1.2.0-alpha.11 → 1.2.0-alpha.12

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.
@@ -288,9 +288,9 @@ function subscribeNotifications(deviceId, generation, notifyCharacteristic) {
288
288
  throw hd_shared_1.ERRORS.TypedError(hd_shared_1.HardwareErrorCode.BleCharacteristicNotifyChangeFailure);
289
289
  });
290
290
  }
291
- function writeCharacteristic(characteristic, buffer) {
291
+ function writeCharacteristic(characteristic, buffer, withoutResponse) {
292
292
  return new Promise((resolve, reject) => {
293
- characteristic.write(buffer, true, (error) => {
293
+ characteristic.write(buffer, withoutResponse, (error) => {
294
294
  if (error) {
295
295
  reject(error);
296
296
  return;
@@ -359,7 +359,7 @@ function createNobleBlePlugin() {
359
359
  const buffer = Buffer.from(data, 'hex');
360
360
  for (let offset = 0; offset < buffer.length; offset += BLE_PACKET_SIZE) {
361
361
  const chunk = buffer.subarray(offset, Math.min(offset + BLE_PACKET_SIZE, buffer.length));
362
- await writeCharacteristic(characteristics.write, chunk);
362
+ await writeCharacteristic(characteristics.write, chunk, true);
363
363
  if (offset + BLE_PACKET_SIZE < buffer.length) {
364
364
  await (0, hd_shared_1.wait)(BLE_WRITE_DELAY);
365
365
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hardware-cli",
3
- "version": "1.2.0-alpha.11",
3
+ "version": "1.2.0-alpha.12",
4
4
  "description": "OneKey hardware wallet CLI for testing device communication",
5
5
  "author": "OneKey",
6
6
  "license": "Apache-2.0",
@@ -30,12 +30,12 @@
30
30
  "test": "jest"
31
31
  },
32
32
  "dependencies": {
33
- "@onekeyfe/hd-common-connect-sdk": "1.2.0-alpha.11",
34
- "@onekeyfe/hd-core": "1.2.0-alpha.11",
35
- "@onekeyfe/hd-shared": "1.2.0-alpha.11",
36
- "@onekeyfe/hd-transport-usb": "1.2.0-alpha.11",
33
+ "@onekeyfe/hd-common-connect-sdk": "1.2.0-alpha.12",
34
+ "@onekeyfe/hd-core": "1.2.0-alpha.12",
35
+ "@onekeyfe/hd-shared": "1.2.0-alpha.12",
36
+ "@onekeyfe/hd-transport-usb": "1.2.0-alpha.12",
37
37
  "@stoprocent/noble": "2.3.16",
38
38
  "commander": "^12.0.0"
39
39
  },
40
- "gitHead": "05d3421ec00e07e99f6665e6436a612503e32dfc"
40
+ "gitHead": "3601e8003c96a2a4ca7856e865d16f48c0c5b758"
41
41
  }
@@ -39,6 +39,7 @@ const createPeripheral = (id: string) => {
39
39
  connect: jest.fn(callback => callback()),
40
40
  disconnect: jest.fn(callback => callback()),
41
41
  },
42
+ write,
42
43
  notify,
43
44
  };
44
45
  };
@@ -110,4 +111,33 @@ describe('Noble BLE plugin notification routing', () => {
110
111
 
111
112
  expect(result).toBe('completed');
112
113
  });
114
+
115
+ test('uses withoutResponse for normal and high-volume writes', async () => {
116
+ const device = createPeripheral('device-a');
117
+ const noble = new EventEmitter() as EventEmitter & {
118
+ state: string;
119
+ startScanning: jest.Mock;
120
+ stopScanning: jest.Mock;
121
+ };
122
+ noble.state = 'poweredOn';
123
+ noble.startScanning = jest.fn((_services, _duplicates, callback) => {
124
+ callback?.();
125
+ noble.emit('discover', device.peripheral);
126
+ });
127
+ noble.stopScanning = jest.fn(callback => callback?.());
128
+ jest.doMock('@stoprocent/noble', () => noble);
129
+
130
+ const { createNobleBlePlugin } = await import('../transports/nobleBlePlugin');
131
+ const plugin = createNobleBlePlugin();
132
+ await plugin.init();
133
+ await plugin.connect('device-a');
134
+
135
+ await plugin.send('device-a', 'aa');
136
+ await plugin.send('device-a', 'bb');
137
+
138
+ expect(device.write.write.mock.calls.map(([, withoutResponse]) => withoutResponse)).toEqual([
139
+ true,
140
+ true,
141
+ ]);
142
+ });
113
143
  });
@@ -379,9 +379,13 @@ function subscribeNotifications(
379
379
  });
380
380
  }
381
381
 
382
- function writeCharacteristic(characteristic: Characteristic, buffer: Buffer) {
382
+ function writeCharacteristic(
383
+ characteristic: Characteristic,
384
+ buffer: Buffer,
385
+ withoutResponse: boolean
386
+ ) {
383
387
  return new Promise<void>((resolve, reject) => {
384
- characteristic.write(buffer, true, (error?: Error) => {
388
+ characteristic.write(buffer, withoutResponse, (error?: Error) => {
385
389
  if (error) {
386
390
  reject(error);
387
391
  return;
@@ -463,7 +467,7 @@ export function createNobleBlePlugin(): LowlevelTransportSharedPlugin {
463
467
  const buffer = Buffer.from(data, 'hex');
464
468
  for (let offset = 0; offset < buffer.length; offset += BLE_PACKET_SIZE) {
465
469
  const chunk = buffer.subarray(offset, Math.min(offset + BLE_PACKET_SIZE, buffer.length));
466
- await writeCharacteristic(characteristics.write, chunk);
470
+ await writeCharacteristic(characteristics.write, chunk, true);
467
471
  if (offset + BLE_PACKET_SIZE < buffer.length) {
468
472
  await wait(BLE_WRITE_DELAY);
469
473
  }