@onekeyfe/hd-transport 1.1.27 → 1.2.0-alpha.0
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/README.md +2 -4
- package/__tests__/build-receive.test.js +6 -8
- package/__tests__/decode-features.test.js +3 -2
- package/__tests__/messages.test.js +8 -0
- package/__tests__/protocol-v2.test.js +754 -0
- package/dist/constants.d.ts +14 -5
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +934 -41
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +827 -84
- package/dist/protocols/index.d.ts +45 -0
- package/dist/protocols/index.d.ts.map +1 -0
- package/dist/protocols/v1/decode.d.ts +11 -0
- package/dist/protocols/v1/decode.d.ts.map +1 -0
- package/dist/protocols/v1/encode.d.ts +11 -0
- package/dist/protocols/v1/encode.d.ts.map +1 -0
- package/dist/protocols/v1/index.d.ts +5 -0
- package/dist/protocols/v1/index.d.ts.map +1 -0
- package/dist/protocols/v1/packets.d.ts +7 -0
- package/dist/protocols/v1/packets.d.ts.map +1 -0
- package/dist/{serialization → protocols/v1}/receive.d.ts +1 -1
- package/dist/protocols/v1/receive.d.ts.map +1 -0
- package/dist/protocols/v2/constants.d.ts +7 -0
- package/dist/protocols/v2/constants.d.ts.map +1 -0
- package/dist/protocols/v2/crc8.d.ts +3 -0
- package/dist/protocols/v2/crc8.d.ts.map +1 -0
- package/dist/protocols/v2/debug.d.ts +13 -0
- package/dist/protocols/v2/debug.d.ts.map +1 -0
- package/dist/protocols/v2/decode.d.ts +8 -0
- package/dist/protocols/v2/decode.d.ts.map +1 -0
- package/dist/protocols/v2/encode.d.ts +5 -0
- package/dist/protocols/v2/encode.d.ts.map +1 -0
- package/dist/protocols/v2/frame-assembler.d.ts +12 -0
- package/dist/protocols/v2/frame-assembler.d.ts.map +1 -0
- package/dist/protocols/v2/index.d.ts +7 -0
- package/dist/protocols/v2/index.d.ts.map +1 -0
- package/dist/protocols/v2/session.d.ts +50 -0
- package/dist/protocols/v2/session.d.ts.map +1 -0
- package/dist/serialization/index.d.ts +6 -3
- package/dist/serialization/index.d.ts.map +1 -1
- package/dist/serialization/protobuf/decode.d.ts.map +1 -1
- package/dist/serialization/protobuf/messages.d.ts +1 -1
- package/dist/serialization/protobuf/messages.d.ts.map +1 -1
- package/dist/types/messages.d.ts +461 -11
- package/dist/types/messages.d.ts.map +1 -1
- package/dist/types/transport.d.ts +14 -2
- package/dist/types/transport.d.ts.map +1 -1
- package/dist/utils/logBlockCommand.d.ts.map +1 -1
- package/messages-protocol-v2.json +13369 -0
- package/package.json +3 -3
- package/scripts/protobuf-build.sh +314 -20
- package/scripts/protobuf-patches/TxInputType.js +1 -0
- package/scripts/protobuf-patches/index.js +2 -0
- package/scripts/protobuf-types.js +224 -18
- package/src/constants.ts +42 -6
- package/src/index.ts +39 -11
- package/src/protocols/index.ts +144 -0
- package/src/{serialization/protocol → protocols/v1}/decode.ts +4 -4
- package/src/{serialization/protocol → protocols/v1}/encode.ts +18 -13
- package/src/protocols/v1/index.ts +4 -0
- package/src/protocols/v1/packets.ts +53 -0
- package/src/{serialization → protocols/v1}/receive.ts +5 -5
- package/src/protocols/v2/constants.ts +6 -0
- package/src/protocols/v2/crc8.ts +34 -0
- package/src/protocols/v2/debug.ts +26 -0
- package/src/protocols/v2/decode.ts +92 -0
- package/src/protocols/v2/encode.ts +116 -0
- package/src/protocols/v2/frame-assembler.ts +98 -0
- package/src/protocols/v2/index.ts +6 -0
- package/src/protocols/v2/session.ts +429 -0
- package/src/serialization/index.ts +6 -5
- package/src/serialization/protobuf/decode.ts +7 -0
- package/src/serialization/protobuf/messages.ts +8 -4
- package/src/types/messages.ts +606 -13
- package/src/types/transport.ts +26 -2
- package/src/utils/logBlockCommand.ts +9 -1
- package/dist/serialization/protocol/decode.d.ts +0 -11
- package/dist/serialization/protocol/decode.d.ts.map +0 -1
- package/dist/serialization/protocol/encode.d.ts +0 -11
- package/dist/serialization/protocol/encode.d.ts.map +0 -1
- package/dist/serialization/protocol/index.d.ts +0 -3
- package/dist/serialization/protocol/index.d.ts.map +0 -1
- package/dist/serialization/receive.d.ts.map +0 -1
- package/dist/serialization/send.d.ts +0 -7
- package/dist/serialization/send.d.ts.map +0 -1
- package/src/serialization/protocol/index.ts +0 -2
- package/src/serialization/send.ts +0 -58
package/src/types/transport.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type EventEmitter from 'events';
|
|
2
2
|
|
|
3
|
+
export type ProtocolType = 'V1' | 'V2';
|
|
4
|
+
|
|
3
5
|
export type OneKeyDeviceCommType =
|
|
4
6
|
| 'usb'
|
|
5
7
|
| 'webusb'
|
|
@@ -31,17 +33,27 @@ export type OneKeyDeviceInfoBase = {
|
|
|
31
33
|
// TODO: sorting type by communication type
|
|
32
34
|
export type OneKeyDeviceInfo = OneKeyDeviceInfoBase &
|
|
33
35
|
OneKeyDeviceInfoWithSession &
|
|
34
|
-
OneKeyMobileDeviceInfo
|
|
36
|
+
OneKeyMobileDeviceInfo & {
|
|
37
|
+
protocolType?: ProtocolType;
|
|
38
|
+
};
|
|
35
39
|
|
|
36
40
|
export type AcquireInput = {
|
|
37
41
|
path?: string;
|
|
38
42
|
previous?: string | null;
|
|
39
43
|
uuid?: string;
|
|
40
44
|
forceCleanRunPromise?: boolean;
|
|
45
|
+
expectedProtocol?: ProtocolType;
|
|
41
46
|
};
|
|
42
47
|
|
|
43
48
|
export type MessageFromOneKey = { type: string; message: Record<string, any> };
|
|
44
49
|
|
|
50
|
+
export type TransportCallOptions = {
|
|
51
|
+
timeoutMs?: number;
|
|
52
|
+
expectedTypes?: string[];
|
|
53
|
+
intermediateTypes?: string[];
|
|
54
|
+
onIntermediateResponse?: (response: MessageFromOneKey) => void;
|
|
55
|
+
};
|
|
56
|
+
|
|
45
57
|
type ITransportInitFn = (
|
|
46
58
|
logger?: any,
|
|
47
59
|
emitter?: EventEmitter,
|
|
@@ -54,7 +66,13 @@ export type Transport = {
|
|
|
54
66
|
acquire(input: AcquireInput): Promise<string>;
|
|
55
67
|
release(session: string, onclose: boolean): Promise<void>;
|
|
56
68
|
configure(signedData: JSON | string): Promise<void>;
|
|
57
|
-
|
|
69
|
+
configureProtocolV2?: (signedData: JSON | string) => Promise<void> | void;
|
|
70
|
+
call(
|
|
71
|
+
session: string,
|
|
72
|
+
name: string,
|
|
73
|
+
data: Record<string, any>,
|
|
74
|
+
options?: TransportCallOptions
|
|
75
|
+
): Promise<MessageFromOneKey>;
|
|
58
76
|
post(session: string, name: string, data: Record<string, any>): Promise<void>;
|
|
59
77
|
read(session: string): Promise<MessageFromOneKey>;
|
|
60
78
|
cancel(): Promise<void>;
|
|
@@ -63,6 +81,12 @@ export type Transport = {
|
|
|
63
81
|
// used to reset the session of the transport when the session is not valid
|
|
64
82
|
disconnect?: (session: string) => Promise<void>;
|
|
65
83
|
|
|
84
|
+
// Returns the protocol type for a given device path.
|
|
85
|
+
// Single-protocol transports (HTTP, emulator, etc.) return 'V1'.
|
|
86
|
+
// Protocol V2-capable transports return the probed protocol for each device,
|
|
87
|
+
// or undefined before protocol detection succeeds.
|
|
88
|
+
getProtocolType: (path: string) => ProtocolType | undefined;
|
|
89
|
+
|
|
66
90
|
// web-usb, web-bluetooth request device
|
|
67
91
|
promptDeviceAccess?: () => Promise<USBDevice | BluetoothDevice | null>;
|
|
68
92
|
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import ByteBuffer from 'bytebuffer';
|
|
2
|
-
export declare const decode: (byteBuffer: ByteBuffer) => {
|
|
3
|
-
typeId: number;
|
|
4
|
-
buffer: ByteBuffer;
|
|
5
|
-
};
|
|
6
|
-
export declare const decodeChunked: (bytes: ArrayBuffer) => {
|
|
7
|
-
length: number;
|
|
8
|
-
typeId: number;
|
|
9
|
-
restBuffer: ByteBuffer;
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=decode.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../../src/serialization/protocol/decode.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AA0BpC,eAAO,MAAM,MAAM,eAAgB,UAAU;;;CAO5C,CAAC;AAIF,eAAO,MAAM,aAAa,UAAW,WAAW;;;;CAW/C,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import ByteBuffer from 'bytebuffer';
|
|
3
|
-
type Options<Chunked> = {
|
|
4
|
-
chunked: Chunked;
|
|
5
|
-
addTrezorHeaders: boolean;
|
|
6
|
-
messageType: number;
|
|
7
|
-
};
|
|
8
|
-
declare function encode(data: ByteBuffer, options: Options<true>): Buffer[];
|
|
9
|
-
declare function encode(data: ByteBuffer, options: Options<false>): Buffer;
|
|
10
|
-
export { encode };
|
|
11
|
-
//# sourceMappingURL=encode.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../../src/serialization/protocol/encode.ts"],"names":[],"mappings":";AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AAIpC,KAAK,OAAO,CAAC,OAAO,IAAI;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,iBAAS,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,EAAE,CAAC;AACpE,iBAAS,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC;AA+CnE,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/serialization/protocol/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"receive.d.ts","sourceRoot":"","sources":["../../src/serialization/receive.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C,wBAAgB,UAAU,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM;;;;;EAUtD"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import ByteBuffer from 'bytebuffer';
|
|
3
|
-
import type { Root } from 'protobufjs/light';
|
|
4
|
-
export declare function buildOne(messages: Root, name: string, data: Record<string, unknown>): Buffer;
|
|
5
|
-
export declare const buildEncodeBuffers: (messages: Root, name: string, data: Record<string, unknown>) => Buffer[];
|
|
6
|
-
export declare const buildBuffers: (messages: Root, name: string, data: Record<string, unknown>) => ByteBuffer[];
|
|
7
|
-
//# sourceMappingURL=send.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"send.d.ts","sourceRoot":"","sources":["../../src/serialization/send.ts"],"names":[],"mappings":";AAGA,OAAO,UAAU,MAAM,YAAY,CAAC;AAOpC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAI7C,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,UASnF;AAED,eAAO,MAAM,kBAAkB,aAAc,IAAI,QAAQ,MAAM,QAAQ,OAAO,MAAM,EAAE,OAAO,CAAC,aAQ7F,CAAC;AAEF,eAAO,MAAM,YAAY,aAAc,IAAI,QAAQ,MAAM,QAAQ,OAAO,MAAM,EAAE,OAAO,CAAC,iBAsBvF,CAAC"}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
// Logic of sending data to trezor
|
|
2
|
-
//
|
|
3
|
-
// Logic of "call" is broken to two parts - sending and receiving
|
|
4
|
-
import ByteBuffer from 'bytebuffer';
|
|
5
|
-
|
|
6
|
-
import { encode as encodeProtobuf } from './protobuf';
|
|
7
|
-
import { encode as encodeProtocol } from './protocol';
|
|
8
|
-
import { createMessageFromName } from './protobuf/messages';
|
|
9
|
-
import { BUFFER_SIZE, MESSAGE_TOP_CHAR } from '../constants';
|
|
10
|
-
|
|
11
|
-
import type { Root } from 'protobufjs/light';
|
|
12
|
-
|
|
13
|
-
// Sends message to device.
|
|
14
|
-
// Resolves if everything gets sent
|
|
15
|
-
export function buildOne(messages: Root, name: string, data: Record<string, unknown>) {
|
|
16
|
-
const { Message, messageType } = createMessageFromName(messages, name);
|
|
17
|
-
|
|
18
|
-
const buffer = encodeProtobuf(Message, data);
|
|
19
|
-
return encodeProtocol(buffer, {
|
|
20
|
-
addTrezorHeaders: false,
|
|
21
|
-
chunked: false,
|
|
22
|
-
messageType,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const buildEncodeBuffers = (messages: Root, name: string, data: Record<string, unknown>) => {
|
|
27
|
-
const { Message, messageType } = createMessageFromName(messages, name);
|
|
28
|
-
const buffer = encodeProtobuf(Message, data);
|
|
29
|
-
return encodeProtocol(buffer, {
|
|
30
|
-
addTrezorHeaders: true,
|
|
31
|
-
chunked: true,
|
|
32
|
-
messageType,
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export const buildBuffers = (messages: Root, name: string, data: Record<string, unknown>) => {
|
|
37
|
-
// const { Message, messageType } = createMessageFromName(messages, name);
|
|
38
|
-
// const buffer = encodeProtobuf(Message, data);
|
|
39
|
-
// const encodeBuffers = encodeProtocol(buffer, {
|
|
40
|
-
// addTrezorHeaders: true,
|
|
41
|
-
// chunked: true,
|
|
42
|
-
// messageType,
|
|
43
|
-
// });
|
|
44
|
-
|
|
45
|
-
const encodeBuffers = buildEncodeBuffers(messages, name, data);
|
|
46
|
-
|
|
47
|
-
const outBuffers: ByteBuffer[] = [];
|
|
48
|
-
|
|
49
|
-
for (const buf of encodeBuffers) {
|
|
50
|
-
const chunkBuffer = new ByteBuffer(BUFFER_SIZE + 1);
|
|
51
|
-
chunkBuffer.writeByte(MESSAGE_TOP_CHAR);
|
|
52
|
-
chunkBuffer.append(buf);
|
|
53
|
-
chunkBuffer.reset();
|
|
54
|
-
outBuffers.push(chunkBuffer);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return outBuffers;
|
|
58
|
-
};
|