@onekeyfe/hd-transport-lowlevel 1.2.0-alpha.125 → 1.2.0-alpha.126
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 +40 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -3
- package/package.json +4 -4
- package/src/index.ts +25 -6
|
@@ -68,12 +68,25 @@ const protocolV2Schema = {
|
|
|
68
68
|
},
|
|
69
69
|
},
|
|
70
70
|
},
|
|
71
|
+
Failure: {
|
|
72
|
+
fields: {
|
|
73
|
+
code: {
|
|
74
|
+
type: 'uint32',
|
|
75
|
+
id: 1,
|
|
76
|
+
},
|
|
77
|
+
message: {
|
|
78
|
+
type: 'string',
|
|
79
|
+
id: 2,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
71
83
|
MessageType: {
|
|
72
84
|
values: {
|
|
73
85
|
MessageType_ProtocolInfoRequest: 60200,
|
|
74
86
|
MessageType_ProtocolInfo: 60201,
|
|
75
87
|
MessageType_Ping: 60206,
|
|
76
88
|
MessageType_Success: 60207,
|
|
89
|
+
MessageType_Failure: 60208,
|
|
77
90
|
},
|
|
78
91
|
},
|
|
79
92
|
},
|
|
@@ -373,6 +386,33 @@ describe('LowlevelTransport protocol framing', () => {
|
|
|
373
386
|
expect(plugin.receive).toHaveBeenCalledTimes(1);
|
|
374
387
|
});
|
|
375
388
|
|
|
389
|
+
test('disconnects and clears a lowlevel connection when Protocol V2 reports link disabled', async () => {
|
|
390
|
+
const failureResponse = ProtocolV2.encodeFrame(
|
|
391
|
+
schemas,
|
|
392
|
+
'Failure',
|
|
393
|
+
{ code: 5, message: 'link disabled' },
|
|
394
|
+
{ router: PROTOCOL_V2_CHANNEL_BLE_UART }
|
|
395
|
+
);
|
|
396
|
+
const plugin = createPlugin({
|
|
397
|
+
devices: [{ id: 'usb-owned-id', name: 'OneKey Pro 2', commType: 'ble' }],
|
|
398
|
+
responses: [bytesToHex(failureResponse)],
|
|
399
|
+
});
|
|
400
|
+
const lowlevel = configureTransport(plugin);
|
|
401
|
+
|
|
402
|
+
await expect(
|
|
403
|
+
lowlevel.acquire({ uuid: 'usb-owned-id', expectedProtocol: 'V2' })
|
|
404
|
+
).rejects.toMatchObject({
|
|
405
|
+
name: 'ProtocolV2LinkDisabledError',
|
|
406
|
+
failureCode: 5,
|
|
407
|
+
firmwareMessage: 'link disabled',
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
expect(plugin.disconnect).toHaveBeenCalledWith('usb-owned-id');
|
|
411
|
+
expect(lowlevel.connectedDevices.has('usb-owned-id')).toBe(false);
|
|
412
|
+
expect(lowlevel.getProtocolType('usb-owned-id')).toBeUndefined();
|
|
413
|
+
expect(lowlevel.protocolV2Assemblers.has('usb-owned-id')).toBe(false);
|
|
414
|
+
});
|
|
415
|
+
|
|
376
416
|
test('resets the lowlevel connection before probing Protocol V2 after a V1 timeout', async () => {
|
|
377
417
|
const probeResponse = ProtocolV2.encodeFrame(
|
|
378
418
|
schemas,
|
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,SAYN,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EACV,cAAc,EACd,6BAA6B,EAC7B,YAAY,EAEZ,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAUpD,wBAAgB,+BAA+B,CAAC,EAC9C,OAAO,EACP,iBAAiB,EACjB,GAAG,EACH,YAAY,GACb,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC;CACtB,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,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,oBAAoB;YAoBlB,cAAc;IA6E5B,OAAO,CAAC,0BAA0B;IAOlC,OAAO,CAAC,2BAA2B;IAOnC,OAAO,CAAC,4BAA4B;IAOpC,OAAO,CAAC,kBAAkB;YAMZ,cAAc;YA2Cd,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
|
@@ -145,7 +145,7 @@ class LowlevelTransport {
|
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
147
|
acquire(input) {
|
|
148
|
-
var _a, _b;
|
|
148
|
+
var _a, _b, _c, _d;
|
|
149
149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
150
|
const alreadyConnected = this.connectedDevices.has(input.uuid);
|
|
151
151
|
try {
|
|
@@ -164,8 +164,31 @@ class LowlevelTransport {
|
|
|
164
164
|
const protocolHint = input.expectedProtocol
|
|
165
165
|
? undefined
|
|
166
166
|
: (_b = input.protocolHint) !== null && _b !== void 0 ? _b : this.deviceProtocolHints.get(input.uuid);
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
try {
|
|
168
|
+
const protocolType = yield this.detectProtocol(input.uuid, input.expectedProtocol, protocolHint);
|
|
169
|
+
return { uuid: input.uuid, protocolType };
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
try {
|
|
173
|
+
yield this.protocolV2Links.invalidateLink(input.uuid, 'Lowlevel transport acquire failed');
|
|
174
|
+
}
|
|
175
|
+
catch (cleanupError) {
|
|
176
|
+
(_c = this.Log) === null || _c === void 0 ? void 0 : _c.debug('[LowlevelTransport] acquire link cleanup failed:', cleanupError);
|
|
177
|
+
}
|
|
178
|
+
try {
|
|
179
|
+
yield this.plugin.disconnect(input.uuid);
|
|
180
|
+
}
|
|
181
|
+
catch (cleanupError) {
|
|
182
|
+
(_d = this.Log) === null || _d === void 0 ? void 0 : _d.debug('[LowlevelTransport] acquire disconnect failed:', cleanupError);
|
|
183
|
+
}
|
|
184
|
+
finally {
|
|
185
|
+
this.connectedDevices.delete(input.uuid);
|
|
186
|
+
this.deviceProtocol.delete(input.uuid);
|
|
187
|
+
this.protocolV2Assemblers.delete(input.uuid);
|
|
188
|
+
this.advanceProtocolV2Generation(input.uuid);
|
|
189
|
+
}
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
169
192
|
});
|
|
170
193
|
}
|
|
171
194
|
release(uuid) {
|
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.126",
|
|
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.126",
|
|
24
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.126"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "c82189b36d650aec460a6f29bd467bf16a74e510"
|
|
27
27
|
}
|
package/src/index.ts
CHANGED
|
@@ -194,12 +194,31 @@ export default class LowlevelTransport {
|
|
|
194
194
|
const protocolHint = input.expectedProtocol
|
|
195
195
|
? undefined
|
|
196
196
|
: input.protocolHint ?? this.deviceProtocolHints.get(input.uuid);
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
197
|
+
try {
|
|
198
|
+
const protocolType = await this.detectProtocol(
|
|
199
|
+
input.uuid,
|
|
200
|
+
input.expectedProtocol,
|
|
201
|
+
protocolHint
|
|
202
|
+
);
|
|
203
|
+
return { uuid: input.uuid, protocolType };
|
|
204
|
+
} catch (error) {
|
|
205
|
+
try {
|
|
206
|
+
await this.protocolV2Links.invalidateLink(input.uuid, 'Lowlevel transport acquire failed');
|
|
207
|
+
} catch (cleanupError) {
|
|
208
|
+
this.Log?.debug('[LowlevelTransport] acquire link cleanup failed:', cleanupError);
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
await this.plugin.disconnect(input.uuid);
|
|
212
|
+
} catch (cleanupError) {
|
|
213
|
+
this.Log?.debug('[LowlevelTransport] acquire disconnect failed:', cleanupError);
|
|
214
|
+
} finally {
|
|
215
|
+
this.connectedDevices.delete(input.uuid);
|
|
216
|
+
this.deviceProtocol.delete(input.uuid);
|
|
217
|
+
this.protocolV2Assemblers.delete(input.uuid);
|
|
218
|
+
this.advanceProtocolV2Generation(input.uuid);
|
|
219
|
+
}
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
203
222
|
}
|
|
204
223
|
|
|
205
224
|
async release(uuid: string) {
|