@onekeyfe/hd-transport-usb 1.1.34-alpha.3 → 1.1.34-alpha.4
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/constants.d.ts +5 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/index.d.ts +7 -104
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +106 -446
- package/package.json +4 -4
- package/src/constants.ts +11 -0
- package/src/index.ts +84 -528
- package/__tests__/protocol-v2-link.test.ts +0 -387
- package/dist/transportLog.d.ts +0 -7
- package/dist/transportLog.d.ts.map +0 -1
- package/src/transportLog.ts +0 -11
|
@@ -0,0 +1 @@
|
|
|
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/dist/index.d.ts
CHANGED
|
@@ -1,142 +1,45 @@
|
|
|
1
1
|
import * as transport from '@onekeyfe/hd-transport';
|
|
2
|
-
import transport__default, {
|
|
2
|
+
import transport__default, { OneKeyDeviceInfo, AcquireInput } from '@onekeyfe/hd-transport';
|
|
3
3
|
import EventEmitter from 'events';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* Unlike the old UsbPlugin (which was a LowlevelTransportSharedPlugin piped
|
|
9
|
-
* through LowlevelTransport), this class is a standalone transport that handles
|
|
10
|
-
* both protocol encoding/decoding and USB I/O directly.
|
|
11
|
-
*
|
|
12
|
-
* Modeled after WebUsbTransport.
|
|
13
|
-
*/
|
|
14
|
-
declare class NodeUsbTransport extends ProtocolV2UsbTransportBase<string> {
|
|
5
|
+
declare const PACKET_SIZE = 64;
|
|
6
|
+
|
|
7
|
+
declare class NodeUsbTransport {
|
|
15
8
|
messages: ReturnType<typeof transport__default.parseConfigure> | undefined;
|
|
16
|
-
/** Protobuf schema for Protocol V2 transports. */
|
|
17
|
-
messagesV2: ReturnType<typeof transport__default.parseConfigure> | undefined;
|
|
18
9
|
name: string;
|
|
19
10
|
version: string;
|
|
20
11
|
configured: boolean;
|
|
21
12
|
isOutdated: boolean;
|
|
22
13
|
Log?: any;
|
|
23
14
|
emitter?: EventEmitter;
|
|
24
|
-
/** serial → bus id, built during enumerate */
|
|
25
15
|
private serialToBusId;
|
|
26
|
-
/** path → opened device state */
|
|
27
16
|
private openDevices;
|
|
28
|
-
/** Per-path protocol type detected by active wire-level probe. */
|
|
29
|
-
private deviceProtocol;
|
|
30
|
-
/** per-path reconnect lock to prevent concurrent reconnects */
|
|
31
17
|
private reconnectLocks;
|
|
32
|
-
/**
|
|
33
|
-
* Retain the low-level Transfer so release()/stop() can cancel native pending reads.
|
|
34
|
-
* Endpoint.transfer() hides it and may keep the CLI alive after output completes.
|
|
35
|
-
*/
|
|
36
|
-
private activeTransfers;
|
|
37
|
-
/** set to true when cancel() is called; checked by retry loops */
|
|
38
18
|
private cancelled;
|
|
39
|
-
constructor();
|
|
40
|
-
/**
|
|
41
|
-
* Initialize transport.
|
|
42
|
-
* Signature matches the Transport.init interface (logger, emitter).
|
|
43
|
-
*/
|
|
44
19
|
init(logger: any, emitter?: EventEmitter): Promise<string>;
|
|
45
20
|
configure(signedData: any): Promise<void>;
|
|
46
|
-
configureProtocolV2(signedData: any): void;
|
|
47
21
|
listen(): void;
|
|
48
|
-
stop():
|
|
49
|
-
/**
|
|
50
|
-
* Low-level post (send only, no response). Not used by NodeUsbTransport
|
|
51
|
-
* since call() handles the full send+receive cycle, but required by the Transport interface.
|
|
52
|
-
*/
|
|
22
|
+
stop(): void;
|
|
53
23
|
post(path: string, name: string, data: Record<string, unknown>): Promise<void>;
|
|
54
|
-
/**
|
|
55
|
-
* Low-level read (receive only). Not used by NodeUsbTransport
|
|
56
|
-
* since call() handles the full send+receive cycle, but required by the Transport interface.
|
|
57
|
-
*/
|
|
58
24
|
read(path: string): Promise<{
|
|
59
25
|
message: {
|
|
60
26
|
[key: string]: any;
|
|
61
27
|
};
|
|
62
28
|
type: string;
|
|
63
29
|
}>;
|
|
64
|
-
/**
|
|
65
|
-
* Enumerate connected OneKey USB devices.
|
|
66
|
-
* Opens each device briefly to read its serial number (used as `path`),
|
|
67
|
-
* then closes it. acquire() re-opens from a fresh getDeviceList().
|
|
68
|
-
*/
|
|
69
30
|
enumerate(): Promise<OneKeyDeviceInfo[]>;
|
|
70
|
-
/**
|
|
71
|
-
* Acquire device — open USB device, claim interface, return path (string).
|
|
72
|
-
*/
|
|
73
31
|
acquire(input: AcquireInput): Promise<string>;
|
|
74
|
-
/**
|
|
75
|
-
* Release device — release interface and close.
|
|
76
|
-
*/
|
|
77
32
|
release(path: string, _onclose?: boolean): Promise<void>;
|
|
78
|
-
|
|
79
|
-
private createTrackedTransfer;
|
|
80
|
-
private transferInOnce;
|
|
81
|
-
private transferOutOnce;
|
|
82
|
-
private closeOpenDevice;
|
|
83
|
-
/**
|
|
84
|
-
* Call device method — encode protobuf, send packets, receive response.
|
|
85
|
-
* This is the core method that replaces LowlevelTransport's call + UsbPlugin's send/receive.
|
|
86
|
-
*/
|
|
87
|
-
call(path: string, name: string, data: Record<string, unknown>, options?: TransportCallOptions): Promise<transport.MessageFromOneKey>;
|
|
88
|
-
private callProtocolV1;
|
|
33
|
+
call(path: string, name: string, data: Record<string, unknown>): Promise<transport.MessageFromOneKey>;
|
|
89
34
|
cancel(): void;
|
|
90
|
-
/**
|
|
91
|
-
* Get the current open device for a path, re-resolving from the map
|
|
92
|
-
* so callers always use a fresh reference after reconnect.
|
|
93
|
-
*/
|
|
94
35
|
private getOpenDevice;
|
|
95
36
|
private getErrorMessage;
|
|
96
37
|
private isRetryableError;
|
|
97
|
-
private isUsbTransferTimeout;
|
|
98
|
-
private getDeviceInterface;
|
|
99
|
-
/**
|
|
100
|
-
* Reconnect device before retrying a failed transfer (aligned with WebUsbTransport).
|
|
101
|
-
* Uses per-path lock to prevent concurrent reconnects to the same device.
|
|
102
|
-
*/
|
|
103
38
|
private reconnectForRetry;
|
|
104
|
-
/**
|
|
105
|
-
* Send all encoded chunks to the device with retry.
|
|
106
|
-
* If a chunk fails and triggers reconnect, the entire sequence restarts
|
|
107
|
-
* from chunk 0 because the device resets protocol state on reconnect.
|
|
108
|
-
*/
|
|
109
39
|
private sendAllChunksWithRetry;
|
|
110
|
-
/**
|
|
111
|
-
* USB IN transfer with retry and reconnect (aligned with WebUsbTransport).
|
|
112
|
-
*/
|
|
113
40
|
private transferInWithRetry;
|
|
114
|
-
/**
|
|
115
|
-
* Open a USB device by path (serial number), claim interface, cache endpoints.
|
|
116
|
-
*/
|
|
117
41
|
private openDevice;
|
|
118
|
-
private drainStaleInput;
|
|
119
|
-
private createProtocolMismatchError;
|
|
120
|
-
private createProtocolDetectionError;
|
|
121
|
-
private detectProtocol;
|
|
122
|
-
private resetConnectionAfterProbe;
|
|
123
|
-
private withProtocolReadTimeout;
|
|
124
|
-
private probeProtocolV1;
|
|
125
|
-
private probeProtocolV2;
|
|
126
|
-
protected getProtocolV2UsbSchemas(): ProtocolV2Schemas;
|
|
127
|
-
protected getProtocolV2UsbLogger(): any;
|
|
128
|
-
protected writeProtocolV2UsbPacket(path: string, frame: Uint8Array, _context: ProtocolV2CallContext): Promise<void>;
|
|
129
|
-
protected readProtocolV2UsbPacket(path: string, _context: ProtocolV2CallContext): Promise<Uint8Array>;
|
|
130
|
-
protected resetProtocolV2UsbNativeLink(path: string, _reason: string): Promise<void>;
|
|
131
|
-
protected onProtocolV2UsbLinkInvalidated(path: string, reason: string): void;
|
|
132
|
-
protected createProtocolV2UsbTimeoutError(name: string, timeoutMs: number): Error;
|
|
133
|
-
private callProtocolV2;
|
|
134
|
-
/**
|
|
135
|
-
* Receive a complete protobuf response from the device.
|
|
136
|
-
* Reads 64-byte packets, strips 0x3F marker, reassembles into hex string.
|
|
137
|
-
*/
|
|
138
42
|
private receiveData;
|
|
139
|
-
getProtocolType(path: string): ProtocolType | undefined;
|
|
140
43
|
}
|
|
141
44
|
|
|
142
|
-
export { NodeUsbTransport as default };
|
|
45
|
+
export { PACKET_SIZE, 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.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,SAA8B,MAAM,wBAAwB,CAAC;AAKpE,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AA0J7E,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACnC,QAAQ,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAElE,IAAI,SAAsB;IAE1B,OAAO,SAAM;IAEb,UAAU,UAAS;IAEnB,UAAU,UAAS;IAEnB,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,OAAO,CAAC,EAAE,YAAY,CAAC;IAGvB,OAAO,CAAC,aAAa,CAA6B;IAGlD,OAAO,CAAC,WAAW,CAAiC;IAGpD,OAAO,CAAC,cAAc,CAA0C;IAGhE,OAAO,CAAC,SAAS,CAAS;IAM1B,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,YAAY;IAMxC,SAAS,CAAC,UAAU,EAAE,GAAG;IAOzB,MAAM;IAIN,IAAI;IAQE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAY9E,IAAI,CAAC,IAAI,EAAE,MAAM;;;;;;IAiBjB,SAAS,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;IA8B9C,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;IAkBvC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IA6BxD,IAAI,CAAC,IAAI,EAAE,MAAM,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;AAED,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"}
|