@onekeyfe/hwk-trezor-connector 1.1.27-alpha.100

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.
@@ -0,0 +1,69 @@
1
+ import { IConnector, ConnectionType, ConnectorDevice, ConnectorSession, ConnectorEventType, ConnectorEventMap } from '@onekeyfe/hwk-adapter-core';
2
+ import { TrezorThpSessionOptions, TrezorByteTransport, TrezorDeviceSession, TrezorThpCredentials } from '@onekeyfe/hwk-trezor-core';
3
+
4
+ type TrezorConnectorByteTransport = TrezorByteTransport & {
5
+ close?(): Promise<void>;
6
+ /**
7
+ * Subscribe to physical-disconnect events from the underlying transport
8
+ * (e.g. BLE link drop). Returns an unsubscribe function.
9
+ */
10
+ onDisconnect?(handler: () => void): () => void;
11
+ };
12
+ type TrezorConnectorBaseOptions = {
13
+ connectionType?: ConnectionType;
14
+ chunkSize?: number;
15
+ thp?: TrezorThpSessionOptions;
16
+ deviceSessionFactory?: (params: {
17
+ transport: TrezorConnectorByteTransport;
18
+ connectionType: ConnectionType;
19
+ chunkSize: number;
20
+ thp?: TrezorThpSessionOptions;
21
+ }) => TrezorDeviceSession;
22
+ };
23
+ declare abstract class TrezorConnectorBase implements IConnector {
24
+ readonly connectionType: ConnectionType;
25
+ private readonly chunkSize;
26
+ private readonly thp?;
27
+ private readonly knownCredentials;
28
+ private readonly deviceSessionFactory;
29
+ private readonly eventHandlers;
30
+ private readonly uiRequests;
31
+ private readonly devices;
32
+ private readonly sessions;
33
+ protected constructor(options?: TrezorConnectorBaseOptions);
34
+ /**
35
+ * Replace the in-memory THP pairing credential list. Caller (host) reads
36
+ * persisted credentials from storage and pushes them in here before the
37
+ * first connect; the device sees them via `ThpHandshakeInitRequest` and
38
+ * routes through the autoconnect path instead of CodeEntry.
39
+ *
40
+ * Empty list = "no credentials known" = fresh pairing on next connect.
41
+ * The internal array is reused so any in-flight TrezorThpSession picks up
42
+ * the change too — we mutate, not replace.
43
+ */
44
+ setKnownCredentials(credentials: TrezorThpCredentials[]): void;
45
+ /**
46
+ * Push new credentials minted during pairing into the in-memory array.
47
+ * Deduplicates by the device-minted `credential` blob — the host has no
48
+ * other stable identity for a credential.
49
+ */
50
+ private mergeKnownCredentials;
51
+ protected abstract enumerateDevices(): Promise<ConnectorDevice[]>;
52
+ protected abstract createByteTransport(device: ConnectorDevice): Promise<TrezorConnectorByteTransport>;
53
+ protected resolveUnlistedDevice(_deviceId: string): ConnectorDevice | undefined;
54
+ searchDevices(): Promise<ConnectorDevice[]>;
55
+ connect(deviceId?: string): Promise<ConnectorSession>;
56
+ disconnect(sessionId: string): Promise<void>;
57
+ call(sessionId: string, method: string, params: unknown): Promise<unknown>;
58
+ cancel(_sessionId: string): Promise<void>;
59
+ uiResponse(_response: Parameters<IConnector['uiResponse']>[0]): void;
60
+ on<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
61
+ off<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
62
+ reset(): void;
63
+ protected emit<K extends ConnectorEventType>(event: K, data: ConnectorEventMap[K]): void;
64
+ private resolveDevice;
65
+ private createThpOptions;
66
+ private log;
67
+ }
68
+
69
+ export { TrezorConnectorBase, type TrezorConnectorBaseOptions, type TrezorConnectorByteTransport };
@@ -0,0 +1,69 @@
1
+ import { IConnector, ConnectionType, ConnectorDevice, ConnectorSession, ConnectorEventType, ConnectorEventMap } from '@onekeyfe/hwk-adapter-core';
2
+ import { TrezorThpSessionOptions, TrezorByteTransport, TrezorDeviceSession, TrezorThpCredentials } from '@onekeyfe/hwk-trezor-core';
3
+
4
+ type TrezorConnectorByteTransport = TrezorByteTransport & {
5
+ close?(): Promise<void>;
6
+ /**
7
+ * Subscribe to physical-disconnect events from the underlying transport
8
+ * (e.g. BLE link drop). Returns an unsubscribe function.
9
+ */
10
+ onDisconnect?(handler: () => void): () => void;
11
+ };
12
+ type TrezorConnectorBaseOptions = {
13
+ connectionType?: ConnectionType;
14
+ chunkSize?: number;
15
+ thp?: TrezorThpSessionOptions;
16
+ deviceSessionFactory?: (params: {
17
+ transport: TrezorConnectorByteTransport;
18
+ connectionType: ConnectionType;
19
+ chunkSize: number;
20
+ thp?: TrezorThpSessionOptions;
21
+ }) => TrezorDeviceSession;
22
+ };
23
+ declare abstract class TrezorConnectorBase implements IConnector {
24
+ readonly connectionType: ConnectionType;
25
+ private readonly chunkSize;
26
+ private readonly thp?;
27
+ private readonly knownCredentials;
28
+ private readonly deviceSessionFactory;
29
+ private readonly eventHandlers;
30
+ private readonly uiRequests;
31
+ private readonly devices;
32
+ private readonly sessions;
33
+ protected constructor(options?: TrezorConnectorBaseOptions);
34
+ /**
35
+ * Replace the in-memory THP pairing credential list. Caller (host) reads
36
+ * persisted credentials from storage and pushes them in here before the
37
+ * first connect; the device sees them via `ThpHandshakeInitRequest` and
38
+ * routes through the autoconnect path instead of CodeEntry.
39
+ *
40
+ * Empty list = "no credentials known" = fresh pairing on next connect.
41
+ * The internal array is reused so any in-flight TrezorThpSession picks up
42
+ * the change too — we mutate, not replace.
43
+ */
44
+ setKnownCredentials(credentials: TrezorThpCredentials[]): void;
45
+ /**
46
+ * Push new credentials minted during pairing into the in-memory array.
47
+ * Deduplicates by the device-minted `credential` blob — the host has no
48
+ * other stable identity for a credential.
49
+ */
50
+ private mergeKnownCredentials;
51
+ protected abstract enumerateDevices(): Promise<ConnectorDevice[]>;
52
+ protected abstract createByteTransport(device: ConnectorDevice): Promise<TrezorConnectorByteTransport>;
53
+ protected resolveUnlistedDevice(_deviceId: string): ConnectorDevice | undefined;
54
+ searchDevices(): Promise<ConnectorDevice[]>;
55
+ connect(deviceId?: string): Promise<ConnectorSession>;
56
+ disconnect(sessionId: string): Promise<void>;
57
+ call(sessionId: string, method: string, params: unknown): Promise<unknown>;
58
+ cancel(_sessionId: string): Promise<void>;
59
+ uiResponse(_response: Parameters<IConnector['uiResponse']>[0]): void;
60
+ on<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
61
+ off<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
62
+ reset(): void;
63
+ protected emit<K extends ConnectorEventType>(event: K, data: ConnectorEventMap[K]): void;
64
+ private resolveDevice;
65
+ private createThpOptions;
66
+ private log;
67
+ }
68
+
69
+ export { TrezorConnectorBase, type TrezorConnectorBaseOptions, type TrezorConnectorByteTransport };