@onekeyfe/hwk-trezor-core 1.1.27-alpha.100 → 1.1.29-alpha.1

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.mts CHANGED
@@ -1,6 +1,20 @@
1
+ type TrezorDebugLogLevel = 'debug' | 'info' | 'warn' | 'error';
2
+ type TrezorDebugLogEntry = {
3
+ level: TrezorDebugLogLevel;
4
+ scope: string;
5
+ event: string;
6
+ data?: Record<string, unknown>;
7
+ thpModuleForwarded?: boolean;
8
+ };
9
+ type TrezorDebugLogger = (entry: TrezorDebugLogEntry) => void;
10
+ declare function shouldLogTrezorDebugEntry(entry: TrezorDebugLogEntry): boolean;
11
+ declare function sanitizeTrezorDebugLogData(data?: Record<string, unknown>): Record<string, unknown> | undefined;
12
+ declare function filterTrezorDebugLogEntry(entry: TrezorDebugLogEntry): TrezorDebugLogEntry | undefined;
13
+
1
14
  interface TrezorByteTransport {
2
15
  write(chunk: Buffer, signal?: AbortSignal): Promise<void>;
3
16
  read(signal?: AbortSignal): Promise<Buffer>;
17
+ reconnect?(): Promise<void>;
4
18
  }
5
19
  interface TrezorTransportProtocol {
6
20
  name: 'bridge' | 'v1' | 'v2';
@@ -44,19 +58,15 @@ type TrezorThpCallParams = {
44
58
  data?: Record<string, unknown>;
45
59
  skipAck?: boolean;
46
60
  };
47
- type TrezorDebugLogLevel = 'debug' | 'info' | 'warn' | 'error';
48
- type TrezorDebugLogEntry = {
49
- level: TrezorDebugLogLevel;
50
- scope: string;
51
- event: string;
52
- data?: Record<string, unknown>;
53
- };
54
- type TrezorDebugLogger = (entry: TrezorDebugLogEntry) => void;
55
61
  declare class TrezorFailureError extends Error {
56
62
  readonly code?: unknown;
57
63
  readonly response: TrezorMessageResponse<'Failure'>;
58
64
  constructor(response: TrezorMessageResponse<'Failure'>);
59
65
  }
66
+ declare class TrezorProtocolError extends Error {
67
+ readonly code: string;
68
+ constructor(code: string, message?: string);
69
+ }
60
70
  declare class TrezorCore {
61
71
  private readonly transport;
62
72
  private readonly protocol;
@@ -64,7 +74,13 @@ declare class TrezorCore {
64
74
  private readonly logger?;
65
75
  constructor({ transport, protocol, chunkSize, logger }: TrezorCoreOptions);
66
76
  call(name: TrezorMessageName, data?: Record<string, unknown>, options?: TrezorCallOptions): Promise<TrezorMessageResponse>;
67
- private thpLoopLogger;
77
+ send(name: TrezorMessageName, data?: Record<string, unknown>, options?: TrezorCallOptions): Promise<void>;
78
+ receive(options?: TrezorCallOptions & {
79
+ name?: TrezorMessageName;
80
+ }): Promise<TrezorMessageResponse>;
81
+ private buildChunks;
82
+ private writeChunks;
83
+ private log;
68
84
  }
69
85
  declare class TrezorThpProtocol {
70
86
  private readonly thpState;
@@ -74,10 +90,19 @@ declare class TrezorThpProtocol {
74
90
  private applyReceivedState;
75
91
  }
76
92
  type TrezorCoreLike = {
93
+ send(name: string, data?: Record<string, unknown>, options?: TrezorCallOptions): Promise<void>;
94
+ receive(options?: TrezorCallOptions & {
95
+ name?: string;
96
+ }): Promise<TrezorMessageResponse>;
77
97
  call(name: string, data?: Record<string, unknown>, options?: TrezorCallOptions): Promise<TrezorMessageResponse>;
78
98
  };
79
99
  type TrezorCoreFactory = (transport: TrezorByteTransport, protocol: TrezorTransportProtocol, chunkSize: number, logger?: TrezorDebugLogger) => TrezorCoreLike;
80
100
  type TrezorSessionProtocol = 'v1' | 'thp';
101
+ type TrezorPassphraseMode = 'prompt' | 'empty';
102
+ type TrezorCreateAppSessionOptions = {
103
+ deriveCardano?: boolean;
104
+ passphraseMode?: TrezorPassphraseMode;
105
+ };
81
106
  type TrezorDeviceSessionOptions = {
82
107
  transport: TrezorByteTransport;
83
108
  connectionType?: string;
@@ -158,6 +183,7 @@ type TrezorThpSessionOptions = {
158
183
  nfcData?: string;
159
184
  }) => Promise<TrezorThpPairingResponse>;
160
185
  onButtonRequest?: (payload: Record<string, unknown>) => Promise<void> | void;
186
+ onButtonRequestComplete?: (payload: Record<string, unknown>) => Promise<void> | void;
161
187
  onPinMatrixRequest?: (payload: TrezorPinMatrixRequestPayload) => Promise<string> | string;
162
188
  /**
163
189
  * Provide the passphrase for a session. Called at two points depending on
@@ -184,6 +210,14 @@ type TrezorThpSessionOptions = {
184
210
  }) => Promise<void> | void;
185
211
  logger?: TrezorDebugLogger;
186
212
  };
213
+ /**
214
+ * Trezor derives the wallet from the EXACT passphrase bytes, so normalize to
215
+ * NFKD before sending — matches trezor-suite (DeviceCurrentSession / thp
216
+ * session) and OneKey hd-core. Without it the same human passphrase typed as
217
+ * composed vs decomposed Unicode would open DIFFERENT wallets. Idempotent; ''
218
+ * stays ''. Only for the passphrase string — never the `on_device` path.
219
+ */
220
+ declare const normalizePassphrase: (value: string | undefined) => string;
187
221
  declare class TrezorDeviceSession {
188
222
  private readonly transport;
189
223
  private readonly connectionType?;
@@ -194,6 +228,7 @@ declare class TrezorDeviceSession {
194
228
  private protocol;
195
229
  private thpState?;
196
230
  private thpAppSessionActive;
231
+ private passphraseMode;
197
232
  private currentFeatures?;
198
233
  constructor(options: TrezorDeviceSessionOptions);
199
234
  get features(): Record<string, unknown> | undefined;
@@ -206,6 +241,7 @@ declare class TrezorDeviceSession {
206
241
  get isThp(): boolean;
207
242
  getThpState(): TrezorThpState | undefined;
208
243
  initialize(): Promise<Record<string, unknown>>;
244
+ private handshakeCancel;
209
245
  call(name: string, data?: Record<string, unknown>): Promise<{
210
246
  type: string;
211
247
  message: Record<string, unknown>;
@@ -214,11 +250,12 @@ declare class TrezorDeviceSession {
214
250
  /**
215
251
  * Create a NEW THP application session with a freshly-prompted passphrase
216
252
  * (or empty if the device has no passphrase protection). Returns the new
217
- * session id (hex). The session knows nothing about wallet identity (XFP) —
218
- * the adapter derives that (via master fingerprint) and owns the
219
- * XFP↔sessionId map. Multiple sessions can coexist on one channel.
253
+ * session id (hex). The session knows nothing about wallet identity. Multiple
254
+ * sessions can coexist on one channel, but callers should not rely on cached
255
+ * app-session identity for wallet selection.
220
256
  */
221
- createThpAppSession(deriveCardano?: boolean): Promise<string>;
257
+ createThpAppSession(options?: boolean | TrezorCreateAppSessionOptions): Promise<string>;
258
+ createV1AppSession(options?: TrezorCreateAppSessionOptions): Promise<void>;
222
259
  /**
223
260
  * Switch the active THP session to an existing id (host-side: just sets the
224
261
  * session-id byte in the next message header). The device must still hold
@@ -228,12 +265,15 @@ declare class TrezorDeviceSession {
228
265
  selectThpAppSession(sessionId: string): void;
229
266
  /** Active THP session id (hex), or undefined if none created/selected. */
230
267
  getThpAppSessionId(): string | undefined;
231
- private ensureThpApplicationSession;
268
+ withDeviceState<T>(fn: () => Promise<T>, options?: {
269
+ deriveCardano?: boolean;
270
+ }): Promise<T>;
232
271
  private handleButtonRequest;
272
+ private handleButtonRequestComplete;
233
273
  private handlePinMatrixRequest;
234
274
  private handlePassphraseRequest;
235
275
  private cancelCurrentCall;
236
276
  private log;
237
277
  }
238
278
 
239
- export { type TrezorByteTransport, type TrezorCallOptions, TrezorCore, type TrezorCoreFactory, type TrezorCoreLike, type TrezorCoreOptions, type TrezorDebugLogEntry, type TrezorDebugLogLevel, type TrezorDebugLogger, TrezorDeviceSession, TrezorFailureError, type TrezorMessageName, type TrezorMessageResponse, type TrezorPinMatrixRequestPayload, type TrezorThpCallParams, type TrezorThpCredentials, type TrezorThpHandshakeCredentials, type TrezorThpHandshakeInitHandler, type TrezorThpHandshakeInitResponse, type TrezorThpPairingMethod, TrezorThpProtocol, type TrezorThpRawTransport, type TrezorThpSessionOptions, type TrezorThpState, type TrezorTransportProtocol };
279
+ export { type TrezorByteTransport, type TrezorCallOptions, TrezorCore, type TrezorCoreFactory, type TrezorCoreLike, type TrezorCoreOptions, type TrezorCreateAppSessionOptions, type TrezorDebugLogEntry, type TrezorDebugLogLevel, type TrezorDebugLogger, TrezorDeviceSession, TrezorFailureError, type TrezorMessageName, type TrezorMessageResponse, type TrezorPassphraseMode, type TrezorPinMatrixRequestPayload, TrezorProtocolError, type TrezorThpCallParams, type TrezorThpCredentials, type TrezorThpHandshakeCredentials, type TrezorThpHandshakeInitHandler, type TrezorThpHandshakeInitResponse, type TrezorThpPairingMethod, TrezorThpProtocol, type TrezorThpRawTransport, type TrezorThpSessionOptions, type TrezorThpState, type TrezorTransportProtocol, filterTrezorDebugLogEntry, normalizePassphrase, sanitizeTrezorDebugLogData, shouldLogTrezorDebugEntry };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,20 @@
1
+ type TrezorDebugLogLevel = 'debug' | 'info' | 'warn' | 'error';
2
+ type TrezorDebugLogEntry = {
3
+ level: TrezorDebugLogLevel;
4
+ scope: string;
5
+ event: string;
6
+ data?: Record<string, unknown>;
7
+ thpModuleForwarded?: boolean;
8
+ };
9
+ type TrezorDebugLogger = (entry: TrezorDebugLogEntry) => void;
10
+ declare function shouldLogTrezorDebugEntry(entry: TrezorDebugLogEntry): boolean;
11
+ declare function sanitizeTrezorDebugLogData(data?: Record<string, unknown>): Record<string, unknown> | undefined;
12
+ declare function filterTrezorDebugLogEntry(entry: TrezorDebugLogEntry): TrezorDebugLogEntry | undefined;
13
+
1
14
  interface TrezorByteTransport {
2
15
  write(chunk: Buffer, signal?: AbortSignal): Promise<void>;
3
16
  read(signal?: AbortSignal): Promise<Buffer>;
17
+ reconnect?(): Promise<void>;
4
18
  }
5
19
  interface TrezorTransportProtocol {
6
20
  name: 'bridge' | 'v1' | 'v2';
@@ -44,19 +58,15 @@ type TrezorThpCallParams = {
44
58
  data?: Record<string, unknown>;
45
59
  skipAck?: boolean;
46
60
  };
47
- type TrezorDebugLogLevel = 'debug' | 'info' | 'warn' | 'error';
48
- type TrezorDebugLogEntry = {
49
- level: TrezorDebugLogLevel;
50
- scope: string;
51
- event: string;
52
- data?: Record<string, unknown>;
53
- };
54
- type TrezorDebugLogger = (entry: TrezorDebugLogEntry) => void;
55
61
  declare class TrezorFailureError extends Error {
56
62
  readonly code?: unknown;
57
63
  readonly response: TrezorMessageResponse<'Failure'>;
58
64
  constructor(response: TrezorMessageResponse<'Failure'>);
59
65
  }
66
+ declare class TrezorProtocolError extends Error {
67
+ readonly code: string;
68
+ constructor(code: string, message?: string);
69
+ }
60
70
  declare class TrezorCore {
61
71
  private readonly transport;
62
72
  private readonly protocol;
@@ -64,7 +74,13 @@ declare class TrezorCore {
64
74
  private readonly logger?;
65
75
  constructor({ transport, protocol, chunkSize, logger }: TrezorCoreOptions);
66
76
  call(name: TrezorMessageName, data?: Record<string, unknown>, options?: TrezorCallOptions): Promise<TrezorMessageResponse>;
67
- private thpLoopLogger;
77
+ send(name: TrezorMessageName, data?: Record<string, unknown>, options?: TrezorCallOptions): Promise<void>;
78
+ receive(options?: TrezorCallOptions & {
79
+ name?: TrezorMessageName;
80
+ }): Promise<TrezorMessageResponse>;
81
+ private buildChunks;
82
+ private writeChunks;
83
+ private log;
68
84
  }
69
85
  declare class TrezorThpProtocol {
70
86
  private readonly thpState;
@@ -74,10 +90,19 @@ declare class TrezorThpProtocol {
74
90
  private applyReceivedState;
75
91
  }
76
92
  type TrezorCoreLike = {
93
+ send(name: string, data?: Record<string, unknown>, options?: TrezorCallOptions): Promise<void>;
94
+ receive(options?: TrezorCallOptions & {
95
+ name?: string;
96
+ }): Promise<TrezorMessageResponse>;
77
97
  call(name: string, data?: Record<string, unknown>, options?: TrezorCallOptions): Promise<TrezorMessageResponse>;
78
98
  };
79
99
  type TrezorCoreFactory = (transport: TrezorByteTransport, protocol: TrezorTransportProtocol, chunkSize: number, logger?: TrezorDebugLogger) => TrezorCoreLike;
80
100
  type TrezorSessionProtocol = 'v1' | 'thp';
101
+ type TrezorPassphraseMode = 'prompt' | 'empty';
102
+ type TrezorCreateAppSessionOptions = {
103
+ deriveCardano?: boolean;
104
+ passphraseMode?: TrezorPassphraseMode;
105
+ };
81
106
  type TrezorDeviceSessionOptions = {
82
107
  transport: TrezorByteTransport;
83
108
  connectionType?: string;
@@ -158,6 +183,7 @@ type TrezorThpSessionOptions = {
158
183
  nfcData?: string;
159
184
  }) => Promise<TrezorThpPairingResponse>;
160
185
  onButtonRequest?: (payload: Record<string, unknown>) => Promise<void> | void;
186
+ onButtonRequestComplete?: (payload: Record<string, unknown>) => Promise<void> | void;
161
187
  onPinMatrixRequest?: (payload: TrezorPinMatrixRequestPayload) => Promise<string> | string;
162
188
  /**
163
189
  * Provide the passphrase for a session. Called at two points depending on
@@ -184,6 +210,14 @@ type TrezorThpSessionOptions = {
184
210
  }) => Promise<void> | void;
185
211
  logger?: TrezorDebugLogger;
186
212
  };
213
+ /**
214
+ * Trezor derives the wallet from the EXACT passphrase bytes, so normalize to
215
+ * NFKD before sending — matches trezor-suite (DeviceCurrentSession / thp
216
+ * session) and OneKey hd-core. Without it the same human passphrase typed as
217
+ * composed vs decomposed Unicode would open DIFFERENT wallets. Idempotent; ''
218
+ * stays ''. Only for the passphrase string — never the `on_device` path.
219
+ */
220
+ declare const normalizePassphrase: (value: string | undefined) => string;
187
221
  declare class TrezorDeviceSession {
188
222
  private readonly transport;
189
223
  private readonly connectionType?;
@@ -194,6 +228,7 @@ declare class TrezorDeviceSession {
194
228
  private protocol;
195
229
  private thpState?;
196
230
  private thpAppSessionActive;
231
+ private passphraseMode;
197
232
  private currentFeatures?;
198
233
  constructor(options: TrezorDeviceSessionOptions);
199
234
  get features(): Record<string, unknown> | undefined;
@@ -206,6 +241,7 @@ declare class TrezorDeviceSession {
206
241
  get isThp(): boolean;
207
242
  getThpState(): TrezorThpState | undefined;
208
243
  initialize(): Promise<Record<string, unknown>>;
244
+ private handshakeCancel;
209
245
  call(name: string, data?: Record<string, unknown>): Promise<{
210
246
  type: string;
211
247
  message: Record<string, unknown>;
@@ -214,11 +250,12 @@ declare class TrezorDeviceSession {
214
250
  /**
215
251
  * Create a NEW THP application session with a freshly-prompted passphrase
216
252
  * (or empty if the device has no passphrase protection). Returns the new
217
- * session id (hex). The session knows nothing about wallet identity (XFP) —
218
- * the adapter derives that (via master fingerprint) and owns the
219
- * XFP↔sessionId map. Multiple sessions can coexist on one channel.
253
+ * session id (hex). The session knows nothing about wallet identity. Multiple
254
+ * sessions can coexist on one channel, but callers should not rely on cached
255
+ * app-session identity for wallet selection.
220
256
  */
221
- createThpAppSession(deriveCardano?: boolean): Promise<string>;
257
+ createThpAppSession(options?: boolean | TrezorCreateAppSessionOptions): Promise<string>;
258
+ createV1AppSession(options?: TrezorCreateAppSessionOptions): Promise<void>;
222
259
  /**
223
260
  * Switch the active THP session to an existing id (host-side: just sets the
224
261
  * session-id byte in the next message header). The device must still hold
@@ -228,12 +265,15 @@ declare class TrezorDeviceSession {
228
265
  selectThpAppSession(sessionId: string): void;
229
266
  /** Active THP session id (hex), or undefined if none created/selected. */
230
267
  getThpAppSessionId(): string | undefined;
231
- private ensureThpApplicationSession;
268
+ withDeviceState<T>(fn: () => Promise<T>, options?: {
269
+ deriveCardano?: boolean;
270
+ }): Promise<T>;
232
271
  private handleButtonRequest;
272
+ private handleButtonRequestComplete;
233
273
  private handlePinMatrixRequest;
234
274
  private handlePassphraseRequest;
235
275
  private cancelCurrentCall;
236
276
  private log;
237
277
  }
238
278
 
239
- export { type TrezorByteTransport, type TrezorCallOptions, TrezorCore, type TrezorCoreFactory, type TrezorCoreLike, type TrezorCoreOptions, type TrezorDebugLogEntry, type TrezorDebugLogLevel, type TrezorDebugLogger, TrezorDeviceSession, TrezorFailureError, type TrezorMessageName, type TrezorMessageResponse, type TrezorPinMatrixRequestPayload, type TrezorThpCallParams, type TrezorThpCredentials, type TrezorThpHandshakeCredentials, type TrezorThpHandshakeInitHandler, type TrezorThpHandshakeInitResponse, type TrezorThpPairingMethod, TrezorThpProtocol, type TrezorThpRawTransport, type TrezorThpSessionOptions, type TrezorThpState, type TrezorTransportProtocol };
279
+ export { type TrezorByteTransport, type TrezorCallOptions, TrezorCore, type TrezorCoreFactory, type TrezorCoreLike, type TrezorCoreOptions, type TrezorCreateAppSessionOptions, type TrezorDebugLogEntry, type TrezorDebugLogLevel, type TrezorDebugLogger, TrezorDeviceSession, TrezorFailureError, type TrezorMessageName, type TrezorMessageResponse, type TrezorPassphraseMode, type TrezorPinMatrixRequestPayload, TrezorProtocolError, type TrezorThpCallParams, type TrezorThpCredentials, type TrezorThpHandshakeCredentials, type TrezorThpHandshakeInitHandler, type TrezorThpHandshakeInitResponse, type TrezorThpPairingMethod, TrezorThpProtocol, type TrezorThpRawTransport, type TrezorThpSessionOptions, type TrezorThpState, type TrezorTransportProtocol, filterTrezorDebugLogEntry, normalizePassphrase, sanitizeTrezorDebugLogData, shouldLogTrezorDebugEntry };