@onekeyfe/hd-transport-web-device 1.2.0-alpha.26 → 1.2.0-alpha.28
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.
|
@@ -441,4 +441,37 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
441
441
|
await bleTransport.release(device.id);
|
|
442
442
|
}
|
|
443
443
|
});
|
|
444
|
+
|
|
445
|
+
test('rejects oversized Protocol V2 requests before writing to Electron BLE', async () => {
|
|
446
|
+
const device = { id: 'oversized-frame-pro2-id', name: 'OneKey Pro 2' };
|
|
447
|
+
const nobleBle = createNobleBle(device);
|
|
448
|
+
let notificationHandler: ((deviceId: string, data: string) => void) | undefined;
|
|
449
|
+
const probeResponse = ProtocolV2.encodeFrame(
|
|
450
|
+
schemas,
|
|
451
|
+
'Success',
|
|
452
|
+
{ message: 'ok' },
|
|
453
|
+
{ router: PROTOCOL_V2_CHANNEL_BLE_UART }
|
|
454
|
+
);
|
|
455
|
+
nobleBle.onNotification.mockImplementation(handler => {
|
|
456
|
+
notificationHandler = handler;
|
|
457
|
+
return jest.fn();
|
|
458
|
+
});
|
|
459
|
+
nobleBle.write.mockImplementation(() => {
|
|
460
|
+
setTimeout(() => notificationHandler?.(device.id, bytesToHex(probeResponse)), 0);
|
|
461
|
+
return Promise.resolve();
|
|
462
|
+
});
|
|
463
|
+
const bleTransport = configureTransport(nobleBle);
|
|
464
|
+
|
|
465
|
+
try {
|
|
466
|
+
await bleTransport.acquire({ uuid: device.id, expectedProtocol: 'V2' });
|
|
467
|
+
expect(nobleBle.write).toHaveBeenCalledTimes(1);
|
|
468
|
+
|
|
469
|
+
await expect(
|
|
470
|
+
bleTransport.call(device.id, 'Ping', { message: 'x'.repeat(2048) })
|
|
471
|
+
).rejects.toThrow(/Protocol V2 frame too large for transport/);
|
|
472
|
+
expect(nobleBle.write).toHaveBeenCalledTimes(1);
|
|
473
|
+
} finally {
|
|
474
|
+
await bleTransport.release(device.id);
|
|
475
|
+
}
|
|
476
|
+
});
|
|
444
477
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"electron-ble-transport.d.ts","sourceRoot":"","sources":["../src/electron-ble-transport.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"electron-ble-transport.d.ts","sourceRoot":"","sources":["../src/electron-ble-transport.ts"],"names":[],"mappings":";AAsBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnG,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AAIvC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,UAAU,CAAC,EAAE,UAAU,CAAC;KACzB;CACF;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,gBAAgB,CAAC,EAAE,YAAY,CAAC;CACjC,CAAC;AAoCF,MAAM,CAAC,OAAO,OAAO,oBAAoB;IACvC,OAAO,CAAC,SAAS,CAA0D;IAE3E,OAAO,CAAC,WAAW,CAA0D;IAE7E,OAAO,CAAC,6BAA6B,CAAqB;IAE1D,IAAI,SAA0B;IAE9B,UAAU,UAAS;IAEnB,UAAU,EAAE,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,GAAG,IAAI,CAAQ;IAExD,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,OAAO,CAAC,EAAE,YAAY,CAAC;IAEvB,OAAO,CAAC,gBAAgB,CAA0B;IAElD,OAAO,CAAC,cAAc,CAAwC;IAE9D,OAAO,CAAC,mBAAmB,CAAwC;IAEnE,OAAO,CAAC,SAAS,CAAsE;IAEvF,OAAO,CAAC,YAAY,CAAoD;IAExE,OAAO,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AO,CAAC,6BAA6B;IAsCrC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
|
package/dist/index.js
CHANGED
package/jest.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-web-device",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.28",
|
|
4
4
|
"author": "OneKey",
|
|
5
5
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,17 +16,18 @@
|
|
|
16
16
|
"scripts": {
|
|
17
17
|
"dev": "rimraf dist && rollup -c ../../build/rollup.config.js -w",
|
|
18
18
|
"build": "rimraf dist && rollup -c ../../build/rollup.config.js",
|
|
19
|
+
"test": "jest",
|
|
19
20
|
"lint": "eslint .",
|
|
20
21
|
"lint:fix": "eslint . --fix"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
24
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
24
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.28",
|
|
25
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.28"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
|
-
"@onekeyfe/hd-transport-electron": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-transport-electron": "1.2.0-alpha.28",
|
|
28
29
|
"@types/w3c-web-usb": "^1.0.6",
|
|
29
30
|
"@types/web-bluetooth": "^0.0.17"
|
|
30
31
|
},
|
|
31
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "b7c7f9f53c4d745f127d03e0b173e8b759bf8e15"
|
|
32
33
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import transport, {
|
|
2
2
|
PROTOCOL_V1_MESSAGE_HEADER_SIZE,
|
|
3
|
+
PROTOCOL_V2_BLE_FRAME_MAX_BYTES,
|
|
3
4
|
PROTOCOL_V2_CHANNEL_BLE_UART,
|
|
4
5
|
ProtocolV2FrameAssembler,
|
|
5
6
|
ProtocolV2LinkManager,
|
|
@@ -793,6 +794,7 @@ export default class ElectronBleTransport {
|
|
|
793
794
|
|
|
794
795
|
return {
|
|
795
796
|
router: PROTOCOL_V2_CHANNEL_BLE_UART,
|
|
797
|
+
maxFrameBytes: PROTOCOL_V2_BLE_FRAME_MAX_BYTES,
|
|
796
798
|
generation,
|
|
797
799
|
prepareCall: () => {
|
|
798
800
|
assertCurrentGeneration();
|