@onekeyfe/hd-transport-usb 1.2.0-alpha.24 → 1.2.0-alpha.26
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-link.test.ts +11 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/package.json +4 -4
- package/src/index.ts +17 -1
|
@@ -253,6 +253,17 @@ const createHarness = () => {
|
|
|
253
253
|
};
|
|
254
254
|
|
|
255
255
|
describe('NodeUsbTransport Protocol V2 link lifecycle', () => {
|
|
256
|
+
test('keeps active links when the Protocol V2 schema is configured repeatedly', () => {
|
|
257
|
+
const transport = new NodeUsbTransport() as any;
|
|
258
|
+
transport.invalidateAllProtocolV2UsbLinks = jest.fn().mockResolvedValue(undefined);
|
|
259
|
+
const schemaSource = JSON.stringify(protocolV2Schema);
|
|
260
|
+
|
|
261
|
+
transport.configureProtocolV2(schemaSource);
|
|
262
|
+
transport.configureProtocolV2(schemaSource);
|
|
263
|
+
|
|
264
|
+
expect(transport.invalidateAllProtocolV2UsbLinks).not.toHaveBeenCalled();
|
|
265
|
+
});
|
|
266
|
+
|
|
256
267
|
test('does not retry a native transfer cancelled by probe cleanup', () => {
|
|
257
268
|
const { transport } = createHarness();
|
|
258
269
|
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ declare class NodeUsbTransport extends ProtocolV2UsbTransportBase<string> {
|
|
|
15
15
|
messages: ReturnType<typeof transport__default.parseConfigure> | undefined;
|
|
16
16
|
/** Protobuf schema for Protocol V2 transports. */
|
|
17
17
|
messagesV2: ReturnType<typeof transport__default.parseConfigure> | undefined;
|
|
18
|
+
private protocolV2SchemaSource;
|
|
18
19
|
name: string;
|
|
19
20
|
version: string;
|
|
20
21
|
configured: boolean;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":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AAQ,EAAE,qBAAqB,GAC9B,OAAO,CAAC,UAAU,CAAC;cAsBN,4BAA4B,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK1F,SAAS,CAAC,8BAA8B,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAKrE,SAAS,CAAC,+BAA+B,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,KAAK;YAOnE,cAAc;YAad,WAAW;IA6CzB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
|
package/dist/index.js
CHANGED
|
@@ -179,7 +179,17 @@ class NodeUsbTransport extends transport.ProtocolV2UsbTransportBase {
|
|
|
179
179
|
return Promise.resolve();
|
|
180
180
|
}
|
|
181
181
|
configureProtocolV2(signedData) {
|
|
182
|
+
var _a;
|
|
183
|
+
const schemaSource = typeof signedData === 'string'
|
|
184
|
+
? signedData
|
|
185
|
+
: (_a = JSON.stringify(signedData)) !== null && _a !== void 0 ? _a : String(signedData);
|
|
186
|
+
if (schemaSource === this.protocolV2SchemaSource)
|
|
187
|
+
return;
|
|
188
|
+
const hadProtocolV2Schema = this.protocolV2SchemaSource !== undefined;
|
|
182
189
|
this.messagesV2 = parseConfigure(signedData);
|
|
190
|
+
this.protocolV2SchemaSource = schemaSource;
|
|
191
|
+
if (!hadProtocolV2Schema)
|
|
192
|
+
return;
|
|
183
193
|
this.invalidateAllProtocolV2UsbLinks('Protocol V2 schema reconfigured').catch(error => { var _a; return (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('[NodeUsbTransport] schema link cleanup failed:', error); });
|
|
184
194
|
}
|
|
185
195
|
listen() {
|
|
@@ -804,7 +814,7 @@ class NodeUsbTransport extends transport.ProtocolV2UsbTransportBase {
|
|
|
804
814
|
(_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug(`[NodeUsbTransport] Protocol V2 link invalidated: ${path}`, reason);
|
|
805
815
|
}
|
|
806
816
|
createProtocolV2UsbTimeoutError(name, timeoutMs) {
|
|
807
|
-
return new
|
|
817
|
+
return new transport.ProtocolV2LinkError('response-timeout', `Protocol V2 response timeout after ${timeoutMs}ms for ${name}`);
|
|
808
818
|
}
|
|
809
819
|
callProtocolV2(path, name, data, options) {
|
|
810
820
|
return __awaiter(this, void 0, void 0, function* () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-usb",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.26",
|
|
4
4
|
"description": "OneKey hardware wallet direct USB transport plugin (libusb)",
|
|
5
5
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,10 +20,10 @@
|
|
|
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.26",
|
|
24
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.26",
|
|
25
25
|
"bytebuffer": "^5.0.1",
|
|
26
26
|
"usb": "^2.14.0"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "1401fef3eb93f5a83ed5e8375b99181b7aaa6054"
|
|
29
29
|
}
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import transport, {
|
|
|
7
7
|
PROTOCOL_V1_USB_PACKET_SIZE,
|
|
8
8
|
PROTOCOL_V2_CHANNEL_USB,
|
|
9
9
|
PROTOCOL_V2_FRAME_MAX_BYTES,
|
|
10
|
+
ProtocolV2LinkError,
|
|
10
11
|
ProtocolV2UsbTransportBase,
|
|
11
12
|
probeProtocolV2 as probeProtocolV2Helper,
|
|
12
13
|
} from '@onekeyfe/hd-transport';
|
|
@@ -163,6 +164,8 @@ export default class NodeUsbTransport extends ProtocolV2UsbTransportBase<string>
|
|
|
163
164
|
/** Protobuf schema for Protocol V2 transports. */
|
|
164
165
|
messagesV2: ReturnType<typeof transport.parseConfigure> | undefined;
|
|
165
166
|
|
|
167
|
+
private protocolV2SchemaSource: string | undefined;
|
|
168
|
+
|
|
166
169
|
name = 'NodeUsbTransport';
|
|
167
170
|
|
|
168
171
|
version = '';
|
|
@@ -225,7 +228,17 @@ export default class NodeUsbTransport extends ProtocolV2UsbTransportBase<string>
|
|
|
225
228
|
}
|
|
226
229
|
|
|
227
230
|
configureProtocolV2(signedData: any) {
|
|
231
|
+
const schemaSource =
|
|
232
|
+
typeof signedData === 'string'
|
|
233
|
+
? signedData
|
|
234
|
+
: JSON.stringify(signedData) ?? String(signedData);
|
|
235
|
+
if (schemaSource === this.protocolV2SchemaSource) return;
|
|
236
|
+
|
|
237
|
+
const hadProtocolV2Schema = this.protocolV2SchemaSource !== undefined;
|
|
228
238
|
this.messagesV2 = parseConfigure(signedData);
|
|
239
|
+
this.protocolV2SchemaSource = schemaSource;
|
|
240
|
+
if (!hadProtocolV2Schema) return;
|
|
241
|
+
|
|
229
242
|
this.invalidateAllProtocolV2UsbLinks('Protocol V2 schema reconfigured').catch(error =>
|
|
230
243
|
this.Log?.debug('[NodeUsbTransport] schema link cleanup failed:', error)
|
|
231
244
|
);
|
|
@@ -1015,7 +1028,10 @@ export default class NodeUsbTransport extends ProtocolV2UsbTransportBase<string>
|
|
|
1015
1028
|
}
|
|
1016
1029
|
|
|
1017
1030
|
protected createProtocolV2UsbTimeoutError(name: string, timeoutMs: number): Error {
|
|
1018
|
-
return new
|
|
1031
|
+
return new ProtocolV2LinkError(
|
|
1032
|
+
'response-timeout',
|
|
1033
|
+
`Protocol V2 response timeout after ${timeoutMs}ms for ${name}`
|
|
1034
|
+
);
|
|
1019
1035
|
}
|
|
1020
1036
|
|
|
1021
1037
|
private async callProtocolV2(
|