@onekeyfe/hd-transport-lowlevel 1.2.0-alpha.28 → 1.2.0-alpha.29
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.
- package/__tests__/protocol-v2.test.js +17 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -11
- package/package.json +4 -4
- package/src/index.ts +23 -11
|
@@ -162,6 +162,23 @@ describe('LowlevelTransport protocol framing', () => {
|
|
|
162
162
|
});
|
|
163
163
|
});
|
|
164
164
|
|
|
165
|
+
test('uses the Protocol V2 BLE writer with the lowlevel compatibility packet size', async () => {
|
|
166
|
+
const plugin = createPlugin({ devices: [], responses: [] });
|
|
167
|
+
const lowlevel = configureTransport(plugin);
|
|
168
|
+
const context = {
|
|
169
|
+
messageName: 'Ping',
|
|
170
|
+
timeoutMs: 1000,
|
|
171
|
+
highVolume: false,
|
|
172
|
+
generation: 1,
|
|
173
|
+
signal: new AbortController().signal,
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
await lowlevel.writeProtocolV2Frame('pro2-id', new Uint8Array(130), context, jest.fn());
|
|
177
|
+
|
|
178
|
+
expect(plugin.send).toHaveBeenCalledTimes(3);
|
|
179
|
+
expect(plugin.send.mock.calls.map(([, hex]) => hex.length / 2)).toEqual([64, 64, 2]);
|
|
180
|
+
});
|
|
181
|
+
|
|
165
182
|
test('rejects calls before protocol detection', async () => {
|
|
166
183
|
const responseChunks = ProtocolV1.encodeTransportPackets(schemas.protocolV1, 'Success', {
|
|
167
184
|
message: 'ok',
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,SAYN,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,YAAY,MA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AG;IAiBnC,MAAM;IAIA,SAAS;IAWT,OAAO,CAAC,KAAK,EAAE,oBAAoB;;;;IAgCnC,OAAO,CAAC,IAAI,EAAE,MAAM;IAgBpB,IAAI,CACR,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,oBAAoB;YAsBlB,cAAc;IA6E5B,OAAO,CAAC,0BAA0B;IAOlC,OAAO,CAAC,2BAA2B;IAOnC,OAAO,CAAC,4BAA4B;IAOpC,OAAO,CAAC,kBAAkB;YAMZ,cAAc;YAsDd,yBAAyB;YAiCzB,eAAe;YAgBf,eAAe;YA6Bf,UAAU;YAUV,qBAAqB;YAmBrB,mBAAmB;YAqBnB,oBAAoB;YAgBpB,cAAc;IAwB5B,OAAO,CAAC,uBAAuB;IAgC/B,OAAO,CAAC,2BAA2B;IAMnC,MAAM;CAGP"}
|
package/dist/index.js
CHANGED
|
@@ -160,7 +160,7 @@ class LowlevelTransport {
|
|
|
160
160
|
this.Log.debug('lowlelvel transport connect error: ', error);
|
|
161
161
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.LowlevelTrasnportConnectError, (_a = error.message) !== null && _a !== void 0 ? _a : error);
|
|
162
162
|
}
|
|
163
|
-
this.protocolV2Assemblers.set(input.uuid, new transport.ProtocolV2FrameAssembler());
|
|
163
|
+
this.protocolV2Assemblers.set(input.uuid, new transport.ProtocolV2FrameAssembler(transport.PROTOCOL_V2_BLE_FRAME_MAX_BYTES));
|
|
164
164
|
const protocolHint = input.expectedProtocol
|
|
165
165
|
? undefined
|
|
166
166
|
: this.deviceProtocolHints.get(input.uuid);
|
|
@@ -430,7 +430,7 @@ class LowlevelTransport {
|
|
|
430
430
|
return __awaiter(this, void 0, void 0, function* () {
|
|
431
431
|
let assembler = this.protocolV2Assemblers.get(uuid);
|
|
432
432
|
if (!assembler) {
|
|
433
|
-
assembler = new transport.ProtocolV2FrameAssembler();
|
|
433
|
+
assembler = new transport.ProtocolV2FrameAssembler(transport.PROTOCOL_V2_BLE_FRAME_MAX_BYTES);
|
|
434
434
|
this.protocolV2Assemblers.set(uuid, assembler);
|
|
435
435
|
}
|
|
436
436
|
const queuedFrame = assembler.push(new Uint8Array(0));
|
|
@@ -447,12 +447,16 @@ class LowlevelTransport {
|
|
|
447
447
|
return frame;
|
|
448
448
|
});
|
|
449
449
|
}
|
|
450
|
-
writeProtocolV2Frame(uuid, frame) {
|
|
450
|
+
writeProtocolV2Frame(uuid, frame, context, assertCurrentGeneration) {
|
|
451
451
|
return __awaiter(this, void 0, void 0, function* () {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
452
|
+
yield transport.writeProtocolV2BleFrame({
|
|
453
|
+
frame,
|
|
454
|
+
packetCapacity: LOWLEVEL_PROTOCOL_V2_PACKET_LENGTH,
|
|
455
|
+
assertActive: assertCurrentGeneration,
|
|
456
|
+
signal: context.signal,
|
|
457
|
+
abortMessage: `Protocol V2 BLE write aborted for ${context.messageName}`,
|
|
458
|
+
writePacket: packet => this.plugin.send(uuid, transport.bytesToHex(packet)),
|
|
459
|
+
});
|
|
456
460
|
});
|
|
457
461
|
}
|
|
458
462
|
callProtocolV2(uuid, name, data, options) {
|
|
@@ -486,10 +490,7 @@ class LowlevelTransport {
|
|
|
486
490
|
assertCurrentGeneration();
|
|
487
491
|
(_a = this.protocolV2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
|
|
488
492
|
},
|
|
489
|
-
writeFrame: (frame) =>
|
|
490
|
-
assertCurrentGeneration();
|
|
491
|
-
return this.writeProtocolV2Frame(uuid, frame);
|
|
492
|
-
},
|
|
493
|
+
writeFrame: (frame, context) => this.writeProtocolV2Frame(uuid, frame, context, assertCurrentGeneration),
|
|
493
494
|
readFrame: (context) => {
|
|
494
495
|
assertCurrentGeneration();
|
|
495
496
|
return this.readProtocolV2Frame(uuid, context.timeoutMs, context.messageName);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-lowlevel",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.29",
|
|
4
4
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"lint:fix": "eslint . --fix"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
24
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
23
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.29",
|
|
24
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.29"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "4a4019e439cc472f89fd15ab47e84ef0ed43166a"
|
|
27
27
|
}
|
package/src/index.ts
CHANGED
|
@@ -10,12 +10,14 @@ import transport, {
|
|
|
10
10
|
hexToBytes,
|
|
11
11
|
probeProtocolV2 as probeProtocolV2Helper,
|
|
12
12
|
withProtocolTimeout,
|
|
13
|
+
writeProtocolV2BleFrame,
|
|
13
14
|
} from '@onekeyfe/hd-transport';
|
|
14
15
|
|
|
15
16
|
import type EventEmitter from 'events';
|
|
16
17
|
import type {
|
|
17
18
|
LowLevelDevice,
|
|
18
19
|
LowlevelTransportSharedPlugin,
|
|
20
|
+
ProtocolV2CallContext,
|
|
19
21
|
ProtocolType,
|
|
20
22
|
TransportCallOptions,
|
|
21
23
|
} from '@onekeyfe/hd-transport';
|
|
@@ -185,7 +187,10 @@ export default class LowlevelTransport {
|
|
|
185
187
|
);
|
|
186
188
|
}
|
|
187
189
|
|
|
188
|
-
this.protocolV2Assemblers.set(
|
|
190
|
+
this.protocolV2Assemblers.set(
|
|
191
|
+
input.uuid,
|
|
192
|
+
new ProtocolV2FrameAssembler(PROTOCOL_V2_BLE_FRAME_MAX_BYTES)
|
|
193
|
+
);
|
|
189
194
|
const protocolHint = input.expectedProtocol
|
|
190
195
|
? undefined
|
|
191
196
|
: this.deviceProtocolHints.get(input.uuid);
|
|
@@ -507,7 +512,7 @@ export default class LowlevelTransport {
|
|
|
507
512
|
private async readProtocolV2Frame(uuid: string, timeoutMs?: number, commandName = 'ProtocolV2') {
|
|
508
513
|
let assembler = this.protocolV2Assemblers.get(uuid);
|
|
509
514
|
if (!assembler) {
|
|
510
|
-
assembler = new ProtocolV2FrameAssembler();
|
|
515
|
+
assembler = new ProtocolV2FrameAssembler(PROTOCOL_V2_BLE_FRAME_MAX_BYTES);
|
|
511
516
|
this.protocolV2Assemblers.set(uuid, assembler);
|
|
512
517
|
}
|
|
513
518
|
|
|
@@ -525,11 +530,20 @@ export default class LowlevelTransport {
|
|
|
525
530
|
return frame;
|
|
526
531
|
}
|
|
527
532
|
|
|
528
|
-
private async writeProtocolV2Frame(
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
+
private async writeProtocolV2Frame(
|
|
534
|
+
uuid: string,
|
|
535
|
+
frame: Uint8Array,
|
|
536
|
+
context: ProtocolV2CallContext,
|
|
537
|
+
assertCurrentGeneration: () => void
|
|
538
|
+
) {
|
|
539
|
+
await writeProtocolV2BleFrame({
|
|
540
|
+
frame,
|
|
541
|
+
packetCapacity: LOWLEVEL_PROTOCOL_V2_PACKET_LENGTH,
|
|
542
|
+
assertActive: assertCurrentGeneration,
|
|
543
|
+
signal: context.signal,
|
|
544
|
+
abortMessage: `Protocol V2 BLE write aborted for ${context.messageName}`,
|
|
545
|
+
writePacket: packet => this.plugin.send(uuid, bytesToHex(packet)),
|
|
546
|
+
});
|
|
533
547
|
}
|
|
534
548
|
|
|
535
549
|
private async callProtocolV2(
|
|
@@ -572,10 +586,8 @@ export default class LowlevelTransport {
|
|
|
572
586
|
assertCurrentGeneration();
|
|
573
587
|
this.protocolV2Assemblers.get(uuid)?.reset();
|
|
574
588
|
},
|
|
575
|
-
writeFrame: (frame: Uint8Array) =>
|
|
576
|
-
assertCurrentGeneration
|
|
577
|
-
return this.writeProtocolV2Frame(uuid, frame);
|
|
578
|
-
},
|
|
589
|
+
writeFrame: (frame: Uint8Array, context: ProtocolV2CallContext) =>
|
|
590
|
+
this.writeProtocolV2Frame(uuid, frame, context, assertCurrentGeneration),
|
|
579
591
|
readFrame: (context: { messageName: string; timeoutMs?: number }) => {
|
|
580
592
|
assertCurrentGeneration();
|
|
581
593
|
return this.readProtocolV2Frame(uuid, context.timeoutMs, context.messageName);
|