@onekeyfe/hd-transport-usb 1.1.26 → 1.1.27-alpha.30
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/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -15
- package/package.json +4 -4
- package/src/index.ts +24 -12
- package/dist/constants.d.ts +0 -5
- package/dist/constants.d.ts.map +0 -1
- package/src/constants.ts +0 -11
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import * as transport from '@onekeyfe/hd-transport';
|
|
2
|
-
import transport__default, { OneKeyDeviceInfo, AcquireInput } from '@onekeyfe/hd-transport';
|
|
2
|
+
import transport__default, { ProtocolType, OneKeyDeviceInfo, AcquireInput } from '@onekeyfe/hd-transport';
|
|
3
3
|
import EventEmitter from 'events';
|
|
4
4
|
|
|
5
|
-
declare const PACKET_SIZE = 64;
|
|
6
|
-
|
|
7
5
|
declare class NodeUsbTransport {
|
|
8
6
|
messages: ReturnType<typeof transport__default.parseConfigure> | undefined;
|
|
9
7
|
name: string;
|
|
@@ -16,6 +14,7 @@ declare class NodeUsbTransport {
|
|
|
16
14
|
private openDevices;
|
|
17
15
|
private reconnectLocks;
|
|
18
16
|
private cancelled;
|
|
17
|
+
getProtocolType(_path: string): ProtocolType;
|
|
19
18
|
init(logger: any, emitter?: EventEmitter): Promise<string>;
|
|
20
19
|
configure(signedData: any): Promise<void>;
|
|
21
20
|
listen(): void;
|
|
@@ -42,4 +41,4 @@ declare class NodeUsbTransport {
|
|
|
42
41
|
private receiveData;
|
|
43
42
|
}
|
|
44
43
|
|
|
45
|
-
export {
|
|
44
|
+
export { NodeUsbTransport as default };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.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M,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAkCpE,MAAM;IAWN,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,gBAAgB;IAoBxB,OAAO,CAAC,iBAAiB;YAmDX,sBAAsB;YAyCtB,mBAAmB;IAsCjC,OAAO,CAAC,UAAU;YAgEJ,WAAW;CAkC1B"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var ByteBuffer = require('bytebuffer');
|
|
6
4
|
var usb = require('usb');
|
|
7
5
|
var transport = require('@onekeyfe/hd-transport');
|
|
@@ -61,12 +59,11 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
61
59
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
62
60
|
};
|
|
63
61
|
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
const { parseConfigure, buildEncodeBuffers, decodeProtocol, receiveOne, check } = transport__default["default"];
|
|
62
|
+
const { parseConfigure, ProtocolV1, check } = transport__default["default"];
|
|
63
|
+
const PACKET_SIZE = transport.PROTOCOL_V1_USB_PACKET_SIZE;
|
|
64
|
+
const REPORT_ID = transport.PROTOCOL_V1_REPORT_ID;
|
|
65
|
+
const PAYLOAD_SIZE = transport.PROTOCOL_V1_CHUNK_PAYLOAD_SIZE;
|
|
66
|
+
const HEADER_LENGTH = transport.PROTOCOL_V1_MESSAGE_HEADER_SIZE;
|
|
70
67
|
const INTERFACE_NUMBER = 0;
|
|
71
68
|
const ENDPOINT_IN = 0x81;
|
|
72
69
|
const ENDPOINT_OUT = 0x01;
|
|
@@ -174,6 +171,9 @@ class NodeUsbTransport {
|
|
|
174
171
|
this.reconnectLocks = new Map();
|
|
175
172
|
this.cancelled = false;
|
|
176
173
|
}
|
|
174
|
+
getProtocolType(_path) {
|
|
175
|
+
return 'V1';
|
|
176
|
+
}
|
|
177
177
|
init(logger, emitter) {
|
|
178
178
|
this.Log = logger;
|
|
179
179
|
this.emitter = emitter;
|
|
@@ -194,7 +194,7 @@ class NodeUsbTransport {
|
|
|
194
194
|
if (!this.messages) {
|
|
195
195
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotConfigured);
|
|
196
196
|
}
|
|
197
|
-
const encodeBuffers =
|
|
197
|
+
const encodeBuffers = ProtocolV1.encodeMessageChunks(this.messages, name, data);
|
|
198
198
|
yield this.sendAllChunksWithRetry(path, encodeBuffers);
|
|
199
199
|
});
|
|
200
200
|
}
|
|
@@ -208,7 +208,7 @@ class NodeUsbTransport {
|
|
|
208
208
|
if (!this.messages) {
|
|
209
209
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotConfigured);
|
|
210
210
|
}
|
|
211
|
-
return
|
|
211
|
+
return ProtocolV1.decodeMessage(this.messages, resData);
|
|
212
212
|
});
|
|
213
213
|
}
|
|
214
214
|
enumerate() {
|
|
@@ -295,13 +295,13 @@ class NodeUsbTransport {
|
|
|
295
295
|
else {
|
|
296
296
|
(_b = this.Log) === null || _b === void 0 ? void 0 : _b.debug('NodeUsbTransport call-', ' name: ', name, ' data: ', data);
|
|
297
297
|
}
|
|
298
|
-
const encodeBuffers =
|
|
298
|
+
const encodeBuffers = ProtocolV1.encodeMessageChunks(messages, name, data);
|
|
299
299
|
yield this.sendAllChunksWithRetry(path, encodeBuffers);
|
|
300
300
|
const resData = yield this.receiveData(path, this.getOpenDevice(path));
|
|
301
301
|
if (typeof resData !== 'string') {
|
|
302
302
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.NetworkError, 'Returning data is not string.');
|
|
303
303
|
}
|
|
304
|
-
const jsonData =
|
|
304
|
+
const jsonData = ProtocolV1.decodeMessage(messages, resData);
|
|
305
305
|
return check.call(jsonData);
|
|
306
306
|
});
|
|
307
307
|
}
|
|
@@ -483,7 +483,7 @@ class NodeUsbTransport {
|
|
|
483
483
|
return __awaiter(this, void 0, void 0, function* () {
|
|
484
484
|
const firstPacket = yield this.transferInWithRetry(path, dev, PACKET_SIZE);
|
|
485
485
|
const firstData = skipReportByte(firstPacket);
|
|
486
|
-
const { length, typeId, restBuffer } =
|
|
486
|
+
const { length, typeId, restBuffer } = ProtocolV1.decodeFirstChunk(toArrayBuffer(firstData));
|
|
487
487
|
const lengthWithHeader = Number(length) + HEADER_LENGTH;
|
|
488
488
|
const decoded = new ByteBuffer__default["default"](lengthWithHeader);
|
|
489
489
|
decoded.writeUint16(typeId);
|
|
@@ -509,5 +509,4 @@ class NodeUsbTransport {
|
|
|
509
509
|
}
|
|
510
510
|
}
|
|
511
511
|
|
|
512
|
-
exports
|
|
513
|
-
exports["default"] = NodeUsbTransport;
|
|
512
|
+
module.exports = NodeUsbTransport;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-usb",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.27-alpha.30",
|
|
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.1.
|
|
24
|
-
"@onekeyfe/hd-transport": "1.1.
|
|
23
|
+
"@onekeyfe/hd-shared": "1.1.27-alpha.30",
|
|
24
|
+
"@onekeyfe/hd-transport": "1.1.27-alpha.30",
|
|
25
25
|
"bytebuffer": "^5.0.1",
|
|
26
26
|
"usb": "^2.14.0"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "f1e3a93e766463007436eaa9aff4a271ffd8830c"
|
|
29
29
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
import ByteBuffer from 'bytebuffer';
|
|
2
2
|
import * as usb from 'usb';
|
|
3
|
-
import transport, {
|
|
3
|
+
import transport, {
|
|
4
|
+
LogBlockCommand,
|
|
5
|
+
PROTOCOL_V1_CHUNK_PAYLOAD_SIZE,
|
|
6
|
+
PROTOCOL_V1_MESSAGE_HEADER_SIZE,
|
|
7
|
+
PROTOCOL_V1_REPORT_ID,
|
|
8
|
+
PROTOCOL_V1_USB_PACKET_SIZE,
|
|
9
|
+
} from '@onekeyfe/hd-transport';
|
|
4
10
|
import { ERRORS, HardwareErrorCode, ONEKEY_WEBUSB_FILTER, wait } from '@onekeyfe/hd-shared';
|
|
5
11
|
|
|
6
|
-
import { HEADER_LENGTH, PACKET_SIZE, PAYLOAD_SIZE, REPORT_ID } from './constants';
|
|
7
|
-
|
|
8
12
|
import type EventEmitter from 'events';
|
|
9
|
-
import type { AcquireInput, OneKeyDeviceInfo } from '@onekeyfe/hd-transport';
|
|
13
|
+
import type { AcquireInput, OneKeyDeviceInfo, ProtocolType } from '@onekeyfe/hd-transport';
|
|
14
|
+
|
|
15
|
+
const { parseConfigure, ProtocolV1, check } = transport;
|
|
10
16
|
|
|
11
|
-
const
|
|
17
|
+
const PACKET_SIZE = PROTOCOL_V1_USB_PACKET_SIZE;
|
|
18
|
+
const REPORT_ID = PROTOCOL_V1_REPORT_ID;
|
|
19
|
+
const PAYLOAD_SIZE = PROTOCOL_V1_CHUNK_PAYLOAD_SIZE;
|
|
20
|
+
const HEADER_LENGTH = PROTOCOL_V1_MESSAGE_HEADER_SIZE;
|
|
12
21
|
|
|
13
22
|
/** USB interface number for vendor-specific communication */
|
|
14
23
|
const INTERFACE_NUMBER = 0;
|
|
@@ -187,6 +196,11 @@ export default class NodeUsbTransport {
|
|
|
187
196
|
/** set to true when cancel() is called; checked by retry loops */
|
|
188
197
|
private cancelled = false;
|
|
189
198
|
|
|
199
|
+
// NodeUsbTransport speaks Protocol V1 only (no Pro2 USB support yet via libusb).
|
|
200
|
+
getProtocolType(_path: string): ProtocolType {
|
|
201
|
+
return 'V1';
|
|
202
|
+
}
|
|
203
|
+
|
|
190
204
|
/**
|
|
191
205
|
* Initialize transport.
|
|
192
206
|
* Signature matches the Transport.init interface (logger, emitter).
|
|
@@ -220,7 +234,7 @@ export default class NodeUsbTransport {
|
|
|
220
234
|
if (!this.messages) {
|
|
221
235
|
throw ERRORS.TypedError(HardwareErrorCode.TransportNotConfigured);
|
|
222
236
|
}
|
|
223
|
-
const encodeBuffers =
|
|
237
|
+
const encodeBuffers = ProtocolV1.encodeMessageChunks(this.messages, name, data);
|
|
224
238
|
await this.sendAllChunksWithRetry(path, encodeBuffers);
|
|
225
239
|
}
|
|
226
240
|
|
|
@@ -237,7 +251,7 @@ export default class NodeUsbTransport {
|
|
|
237
251
|
if (!this.messages) {
|
|
238
252
|
throw ERRORS.TypedError(HardwareErrorCode.TransportNotConfigured);
|
|
239
253
|
}
|
|
240
|
-
return
|
|
254
|
+
return ProtocolV1.decodeMessage(this.messages, resData);
|
|
241
255
|
}
|
|
242
256
|
|
|
243
257
|
/**
|
|
@@ -341,7 +355,7 @@ export default class NodeUsbTransport {
|
|
|
341
355
|
}
|
|
342
356
|
|
|
343
357
|
// Encode protobuf message into 63-byte chunks (same as WebUsbTransport)
|
|
344
|
-
const encodeBuffers =
|
|
358
|
+
const encodeBuffers = ProtocolV1.encodeMessageChunks(messages, name, data);
|
|
345
359
|
|
|
346
360
|
// Send all chunks with retry — if any chunk fails and reconnects,
|
|
347
361
|
// restart the entire send sequence from chunk 0 (device resets state on reconnect)
|
|
@@ -352,7 +366,7 @@ export default class NodeUsbTransport {
|
|
|
352
366
|
if (typeof resData !== 'string') {
|
|
353
367
|
throw ERRORS.TypedError(HardwareErrorCode.NetworkError, 'Returning data is not string.');
|
|
354
368
|
}
|
|
355
|
-
const jsonData =
|
|
369
|
+
const jsonData = ProtocolV1.decodeMessage(messages, resData);
|
|
356
370
|
return check.call(jsonData);
|
|
357
371
|
}
|
|
358
372
|
|
|
@@ -605,7 +619,7 @@ export default class NodeUsbTransport {
|
|
|
605
619
|
const firstData = skipReportByte(firstPacket);
|
|
606
620
|
|
|
607
621
|
// Decode header: ## marker → { typeId, length, restBuffer }
|
|
608
|
-
const { length, typeId, restBuffer } =
|
|
622
|
+
const { length, typeId, restBuffer } = ProtocolV1.decodeFirstChunk(toArrayBuffer(firstData));
|
|
609
623
|
|
|
610
624
|
// Allocate result: typeId(2) + length(4) + payload(length)
|
|
611
625
|
const lengthWithHeader = Number(length) + HEADER_LENGTH;
|
|
@@ -634,5 +648,3 @@ export default class NodeUsbTransport {
|
|
|
634
648
|
return Buffer.from(result as unknown as ArrayBuffer).toString('hex');
|
|
635
649
|
}
|
|
636
650
|
}
|
|
637
|
-
|
|
638
|
-
export { PACKET_SIZE } from './constants';
|
package/dist/constants.d.ts
DELETED
package/dist/constants.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW,KAAK,CAAC;AAG9B,eAAO,MAAM,SAAS,KAAO,CAAC;AAG9B,eAAO,MAAM,YAAY,QAAkB,CAAC;AAG5C,eAAO,MAAM,aAAa,IAAI,CAAC"}
|
package/src/constants.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/** USB packet size in bytes */
|
|
2
|
-
export const PACKET_SIZE = 64;
|
|
3
|
-
|
|
4
|
-
/** Protocol marker byte (0x3F = '?') — first byte of every packet */
|
|
5
|
-
export const REPORT_ID = 0x3f;
|
|
6
|
-
|
|
7
|
-
/** Usable payload per packet after stripping the 0x3F report byte */
|
|
8
|
-
export const PAYLOAD_SIZE = PACKET_SIZE - 1;
|
|
9
|
-
|
|
10
|
-
/** Protocol header length: typeId (2 bytes) + length (4 bytes) */
|
|
11
|
-
export const HEADER_LENGTH = 6;
|