@onekeyfe/hd-transport 1.2.0-alpha.3 → 1.2.0-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/README.md +1 -1
- package/__tests__/messages.test.js +142 -0
- package/__tests__/protocol-v2-ble-frame-writer.test.js +119 -0
- package/__tests__/protocol-v2-link-manager.test.js +389 -0
- package/__tests__/protocol-v2-usb-transport-base.test.js +330 -0
- package/__tests__/protocol-v2.test.js +555 -119
- package/dist/constants.d.ts +6 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +981 -278
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +759 -247
- package/dist/protocols/index.d.ts +14 -5
- package/dist/protocols/index.d.ts.map +1 -1
- package/dist/protocols/v2/ble-frame-writer.d.ts +15 -0
- package/dist/protocols/v2/ble-frame-writer.d.ts.map +1 -0
- package/dist/protocols/v2/constants.d.ts +1 -0
- package/dist/protocols/v2/constants.d.ts.map +1 -1
- package/dist/protocols/v2/decode.d.ts +13 -2
- package/dist/protocols/v2/decode.d.ts.map +1 -1
- package/dist/protocols/v2/encode.d.ts +2 -3
- package/dist/protocols/v2/encode.d.ts.map +1 -1
- package/dist/protocols/v2/errors.d.ts +8 -0
- package/dist/protocols/v2/errors.d.ts.map +1 -0
- package/dist/protocols/v2/frame-assembler.d.ts.map +1 -1
- package/dist/protocols/v2/index.d.ts +2 -1
- package/dist/protocols/v2/index.d.ts.map +1 -1
- package/dist/protocols/v2/link-manager.d.ts +38 -0
- package/dist/protocols/v2/link-manager.d.ts.map +1 -0
- package/dist/protocols/v2/sequence-cursor.d.ts +5 -0
- package/dist/protocols/v2/sequence-cursor.d.ts.map +1 -0
- package/dist/protocols/v2/session.d.ts +19 -5
- package/dist/protocols/v2/session.d.ts.map +1 -1
- package/dist/protocols/v2/usb-transport-base.d.ts +32 -0
- package/dist/protocols/v2/usb-transport-base.d.ts.map +1 -0
- package/dist/serialization/protobuf/decode.d.ts.map +1 -1
- package/dist/types/messages.d.ts +523 -158
- package/dist/types/messages.d.ts.map +1 -1
- package/dist/types/transport.d.ts +13 -3
- package/dist/types/transport.d.ts.map +1 -1
- package/messages-protocol-v2.json +796 -620
- package/package.json +3 -3
- package/scripts/protobuf-build.sh +96 -310
- package/scripts/protobuf-patches/index.js +1 -0
- package/scripts/protobuf-types.js +19 -1
- package/src/constants.ts +29 -15
- package/src/index.ts +11 -1
- package/src/protocols/index.ts +39 -40
- package/src/protocols/v2/ble-frame-writer.ts +77 -0
- package/src/protocols/v2/constants.ts +1 -0
- package/src/protocols/v2/crc8.ts +1 -1
- package/src/protocols/v2/decode.ts +71 -37
- package/src/protocols/v2/encode.ts +2 -28
- package/src/protocols/v2/errors.ts +25 -0
- package/src/protocols/v2/frame-assembler.ts +6 -4
- package/src/protocols/v2/index.ts +2 -1
- package/src/protocols/v2/link-manager.ts +186 -0
- package/src/protocols/v2/sequence-cursor.ts +10 -0
- package/src/protocols/v2/session.ts +157 -201
- package/src/protocols/v2/usb-transport-base.ts +213 -0
- package/src/serialization/protobuf/decode.ts +4 -1
- package/src/types/messages.ts +623 -181
- package/src/types/transport.ts +13 -3
- package/dist/protocols/v2/debug.d.ts +0 -13
- package/dist/protocols/v2/debug.d.ts.map +0 -1
- package/src/protocols/v2/debug.ts +0 -26
package/src/types/transport.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import type EventEmitter from 'events';
|
|
2
2
|
|
|
3
|
+
export const TRANSPORT_EVENT = {
|
|
4
|
+
DEVICE_DISCONNECT: 'transport-device-disconnect',
|
|
5
|
+
} as const;
|
|
6
|
+
|
|
7
|
+
export type TransportDeviceDisconnectEvent = {
|
|
8
|
+
id: string;
|
|
9
|
+
connectId: string;
|
|
10
|
+
name: string | null;
|
|
11
|
+
};
|
|
12
|
+
|
|
3
13
|
export type ProtocolType = 'V1' | 'V2';
|
|
4
14
|
|
|
5
15
|
export type OneKeyDeviceCommType =
|
|
@@ -92,7 +102,7 @@ export type Transport = {
|
|
|
92
102
|
|
|
93
103
|
// resolves when the transport can be used; rejects when it cannot
|
|
94
104
|
init: ITransportInitFn;
|
|
95
|
-
stop(): void
|
|
105
|
+
stop(): void | Promise<void>;
|
|
96
106
|
|
|
97
107
|
configured: boolean;
|
|
98
108
|
version: string;
|
|
@@ -105,8 +115,8 @@ export type Transport = {
|
|
|
105
115
|
export type LowLevelDevice = OneKeyDeviceInfoBase & { id: string; name: string };
|
|
106
116
|
export type LowlevelTransportSharedPlugin = {
|
|
107
117
|
enumerate: () => Promise<LowLevelDevice[]>;
|
|
108
|
-
send: (uuid: string, data: string) => Promise<void>;
|
|
109
|
-
receive: () => Promise<string>;
|
|
118
|
+
send: (uuid: string, data: string, options?: { withoutResponse?: boolean }) => Promise<void>;
|
|
119
|
+
receive: (uuid?: string) => Promise<string>;
|
|
110
120
|
connect: (uuid: string) => Promise<void>;
|
|
111
121
|
disconnect: (uuid: string) => Promise<void>;
|
|
112
122
|
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export type ProtocolV2DebugLogger = {
|
|
2
|
-
debug?: (...args: unknown[]) => void;
|
|
3
|
-
};
|
|
4
|
-
export type ProtocolV2FrameDebugOptions = {
|
|
5
|
-
logger?: ProtocolV2DebugLogger;
|
|
6
|
-
logPrefix?: string;
|
|
7
|
-
context?: string;
|
|
8
|
-
messageName?: string;
|
|
9
|
-
messageTypeId?: number;
|
|
10
|
-
pbPayloadLength?: number;
|
|
11
|
-
};
|
|
12
|
-
export declare function logProtocolV2Debug(options: ProtocolV2FrameDebugOptions | undefined, stage: string, details: Record<string, unknown>): void;
|
|
13
|
-
//# sourceMappingURL=debug.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../../src/protocols/v2/debug.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IACxC,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,2BAA2B,GAAG,SAAS,EAChD,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QASjC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export type ProtocolV2DebugLogger = {
|
|
2
|
-
debug?: (...args: unknown[]) => void;
|
|
3
|
-
};
|
|
4
|
-
|
|
5
|
-
export type ProtocolV2FrameDebugOptions = {
|
|
6
|
-
logger?: ProtocolV2DebugLogger;
|
|
7
|
-
logPrefix?: string;
|
|
8
|
-
context?: string;
|
|
9
|
-
messageName?: string;
|
|
10
|
-
messageTypeId?: number;
|
|
11
|
-
pbPayloadLength?: number;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export function logProtocolV2Debug(
|
|
15
|
-
options: ProtocolV2FrameDebugOptions | undefined,
|
|
16
|
-
stage: string,
|
|
17
|
-
details: Record<string, unknown>
|
|
18
|
-
) {
|
|
19
|
-
options?.logger?.debug?.(`[${options.logPrefix ?? 'ProtocolV2'}] ${stage}`, {
|
|
20
|
-
...(options.context ? { context: options.context } : {}),
|
|
21
|
-
...(options.messageName ? { messageName: options.messageName } : {}),
|
|
22
|
-
...(options.messageTypeId !== undefined ? { messageTypeId: options.messageTypeId } : {}),
|
|
23
|
-
...(options.pbPayloadLength !== undefined ? { pbPayloadLength: options.pbPayloadLength } : {}),
|
|
24
|
-
...details,
|
|
25
|
-
});
|
|
26
|
-
}
|