@onekeyfe/hwk-trezor-core 1.1.27-alpha.101 → 1.1.29-alpha.10

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,3 +1,16 @@
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>;
@@ -45,15 +58,6 @@ type TrezorThpCallParams = {
45
58
  data?: Record<string, unknown>;
46
59
  skipAck?: boolean;
47
60
  };
48
- type TrezorDebugLogLevel = 'debug' | 'info' | 'warn' | 'error';
49
- type TrezorDebugLogEntry = {
50
- level: TrezorDebugLogLevel;
51
- scope: string;
52
- event: string;
53
- data?: Record<string, unknown>;
54
- thpModuleForwarded?: boolean;
55
- };
56
- type TrezorDebugLogger = (entry: TrezorDebugLogEntry) => void;
57
61
  declare class TrezorFailureError extends Error {
58
62
  readonly code?: unknown;
59
63
  readonly response: TrezorMessageResponse<'Failure'>;
@@ -76,7 +80,7 @@ declare class TrezorCore {
76
80
  }): Promise<TrezorMessageResponse>;
77
81
  private buildChunks;
78
82
  private writeChunks;
79
- private thpLoopLogger;
83
+ private log;
80
84
  }
81
85
  declare class TrezorThpProtocol {
82
86
  private readonly thpState;
@@ -94,6 +98,11 @@ type TrezorCoreLike = {
94
98
  };
95
99
  type TrezorCoreFactory = (transport: TrezorByteTransport, protocol: TrezorTransportProtocol, chunkSize: number, logger?: TrezorDebugLogger) => TrezorCoreLike;
96
100
  type TrezorSessionProtocol = 'v1' | 'thp';
101
+ type TrezorPassphraseMode = 'prompt' | 'empty';
102
+ type TrezorCreateAppSessionOptions = {
103
+ deriveCardano?: boolean;
104
+ passphraseMode?: TrezorPassphraseMode;
105
+ };
97
106
  type TrezorDeviceSessionOptions = {
98
107
  transport: TrezorByteTransport;
99
108
  connectionType?: string;
@@ -174,6 +183,7 @@ type TrezorThpSessionOptions = {
174
183
  nfcData?: string;
175
184
  }) => Promise<TrezorThpPairingResponse>;
176
185
  onButtonRequest?: (payload: Record<string, unknown>) => Promise<void> | void;
186
+ onButtonRequestComplete?: (payload: Record<string, unknown>) => Promise<void> | void;
177
187
  onPinMatrixRequest?: (payload: TrezorPinMatrixRequestPayload) => Promise<string> | string;
178
188
  /**
179
189
  * Provide the passphrase for a session. Called at two points depending on
@@ -200,6 +210,14 @@ type TrezorThpSessionOptions = {
200
210
  }) => Promise<void> | void;
201
211
  logger?: TrezorDebugLogger;
202
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;
203
221
  declare class TrezorDeviceSession {
204
222
  private readonly transport;
205
223
  private readonly connectionType?;
@@ -210,6 +228,7 @@ declare class TrezorDeviceSession {
210
228
  private protocol;
211
229
  private thpState?;
212
230
  private thpAppSessionActive;
231
+ private passphraseMode;
213
232
  private currentFeatures?;
214
233
  constructor(options: TrezorDeviceSessionOptions);
215
234
  get features(): Record<string, unknown> | undefined;
@@ -222,7 +241,6 @@ declare class TrezorDeviceSession {
222
241
  get isThp(): boolean;
223
242
  getThpState(): TrezorThpState | undefined;
224
243
  initialize(): Promise<Record<string, unknown>>;
225
- private handshakeCancel;
226
244
  call(name: string, data?: Record<string, unknown>): Promise<{
227
245
  type: string;
228
246
  message: Record<string, unknown>;
@@ -231,11 +249,12 @@ declare class TrezorDeviceSession {
231
249
  /**
232
250
  * Create a NEW THP application session with a freshly-prompted passphrase
233
251
  * (or empty if the device has no passphrase protection). Returns the new
234
- * session id (hex). The session knows nothing about wallet identity (XFP) —
235
- * the adapter derives that (via master fingerprint) and owns the
236
- * XFP↔sessionId map. Multiple sessions can coexist on one channel.
252
+ * session id (hex). The session knows nothing about wallet identity. Multiple
253
+ * sessions can coexist on one channel, but callers should not rely on cached
254
+ * app-session identity for wallet selection.
237
255
  */
238
- createThpAppSession(deriveCardano?: boolean): Promise<string>;
256
+ createThpAppSession(options?: boolean | TrezorCreateAppSessionOptions): Promise<string>;
257
+ createV1AppSession(options?: TrezorCreateAppSessionOptions): Promise<void>;
239
258
  /**
240
259
  * Switch the active THP session to an existing id (host-side: just sets the
241
260
  * session-id byte in the next message header). The device must still hold
@@ -245,12 +264,15 @@ declare class TrezorDeviceSession {
245
264
  selectThpAppSession(sessionId: string): void;
246
265
  /** Active THP session id (hex), or undefined if none created/selected. */
247
266
  getThpAppSessionId(): string | undefined;
248
- private ensureThpApplicationSession;
267
+ withDeviceState<T>(fn: () => Promise<T>, options?: {
268
+ deriveCardano?: boolean;
269
+ }): Promise<T>;
249
270
  private handleButtonRequest;
271
+ private handleButtonRequestComplete;
250
272
  private handlePinMatrixRequest;
251
273
  private handlePassphraseRequest;
252
274
  private cancelCurrentCall;
253
275
  private log;
254
276
  }
255
277
 
256
- 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, TrezorProtocolError, type TrezorThpCallParams, type TrezorThpCredentials, type TrezorThpHandshakeCredentials, type TrezorThpHandshakeInitHandler, type TrezorThpHandshakeInitResponse, type TrezorThpPairingMethod, TrezorThpProtocol, type TrezorThpRawTransport, type TrezorThpSessionOptions, type TrezorThpState, type TrezorTransportProtocol };
278
+ 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,3 +1,16 @@
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>;
@@ -45,15 +58,6 @@ type TrezorThpCallParams = {
45
58
  data?: Record<string, unknown>;
46
59
  skipAck?: boolean;
47
60
  };
48
- type TrezorDebugLogLevel = 'debug' | 'info' | 'warn' | 'error';
49
- type TrezorDebugLogEntry = {
50
- level: TrezorDebugLogLevel;
51
- scope: string;
52
- event: string;
53
- data?: Record<string, unknown>;
54
- thpModuleForwarded?: boolean;
55
- };
56
- type TrezorDebugLogger = (entry: TrezorDebugLogEntry) => void;
57
61
  declare class TrezorFailureError extends Error {
58
62
  readonly code?: unknown;
59
63
  readonly response: TrezorMessageResponse<'Failure'>;
@@ -76,7 +80,7 @@ declare class TrezorCore {
76
80
  }): Promise<TrezorMessageResponse>;
77
81
  private buildChunks;
78
82
  private writeChunks;
79
- private thpLoopLogger;
83
+ private log;
80
84
  }
81
85
  declare class TrezorThpProtocol {
82
86
  private readonly thpState;
@@ -94,6 +98,11 @@ type TrezorCoreLike = {
94
98
  };
95
99
  type TrezorCoreFactory = (transport: TrezorByteTransport, protocol: TrezorTransportProtocol, chunkSize: number, logger?: TrezorDebugLogger) => TrezorCoreLike;
96
100
  type TrezorSessionProtocol = 'v1' | 'thp';
101
+ type TrezorPassphraseMode = 'prompt' | 'empty';
102
+ type TrezorCreateAppSessionOptions = {
103
+ deriveCardano?: boolean;
104
+ passphraseMode?: TrezorPassphraseMode;
105
+ };
97
106
  type TrezorDeviceSessionOptions = {
98
107
  transport: TrezorByteTransport;
99
108
  connectionType?: string;
@@ -174,6 +183,7 @@ type TrezorThpSessionOptions = {
174
183
  nfcData?: string;
175
184
  }) => Promise<TrezorThpPairingResponse>;
176
185
  onButtonRequest?: (payload: Record<string, unknown>) => Promise<void> | void;
186
+ onButtonRequestComplete?: (payload: Record<string, unknown>) => Promise<void> | void;
177
187
  onPinMatrixRequest?: (payload: TrezorPinMatrixRequestPayload) => Promise<string> | string;
178
188
  /**
179
189
  * Provide the passphrase for a session. Called at two points depending on
@@ -200,6 +210,14 @@ type TrezorThpSessionOptions = {
200
210
  }) => Promise<void> | void;
201
211
  logger?: TrezorDebugLogger;
202
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;
203
221
  declare class TrezorDeviceSession {
204
222
  private readonly transport;
205
223
  private readonly connectionType?;
@@ -210,6 +228,7 @@ declare class TrezorDeviceSession {
210
228
  private protocol;
211
229
  private thpState?;
212
230
  private thpAppSessionActive;
231
+ private passphraseMode;
213
232
  private currentFeatures?;
214
233
  constructor(options: TrezorDeviceSessionOptions);
215
234
  get features(): Record<string, unknown> | undefined;
@@ -222,7 +241,6 @@ declare class TrezorDeviceSession {
222
241
  get isThp(): boolean;
223
242
  getThpState(): TrezorThpState | undefined;
224
243
  initialize(): Promise<Record<string, unknown>>;
225
- private handshakeCancel;
226
244
  call(name: string, data?: Record<string, unknown>): Promise<{
227
245
  type: string;
228
246
  message: Record<string, unknown>;
@@ -231,11 +249,12 @@ declare class TrezorDeviceSession {
231
249
  /**
232
250
  * Create a NEW THP application session with a freshly-prompted passphrase
233
251
  * (or empty if the device has no passphrase protection). Returns the new
234
- * session id (hex). The session knows nothing about wallet identity (XFP) —
235
- * the adapter derives that (via master fingerprint) and owns the
236
- * XFP↔sessionId map. Multiple sessions can coexist on one channel.
252
+ * session id (hex). The session knows nothing about wallet identity. Multiple
253
+ * sessions can coexist on one channel, but callers should not rely on cached
254
+ * app-session identity for wallet selection.
237
255
  */
238
- createThpAppSession(deriveCardano?: boolean): Promise<string>;
256
+ createThpAppSession(options?: boolean | TrezorCreateAppSessionOptions): Promise<string>;
257
+ createV1AppSession(options?: TrezorCreateAppSessionOptions): Promise<void>;
239
258
  /**
240
259
  * Switch the active THP session to an existing id (host-side: just sets the
241
260
  * session-id byte in the next message header). The device must still hold
@@ -245,12 +264,15 @@ declare class TrezorDeviceSession {
245
264
  selectThpAppSession(sessionId: string): void;
246
265
  /** Active THP session id (hex), or undefined if none created/selected. */
247
266
  getThpAppSessionId(): string | undefined;
248
- private ensureThpApplicationSession;
267
+ withDeviceState<T>(fn: () => Promise<T>, options?: {
268
+ deriveCardano?: boolean;
269
+ }): Promise<T>;
249
270
  private handleButtonRequest;
271
+ private handleButtonRequestComplete;
250
272
  private handlePinMatrixRequest;
251
273
  private handlePassphraseRequest;
252
274
  private cancelCurrentCall;
253
275
  private log;
254
276
  }
255
277
 
256
- 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, TrezorProtocolError, type TrezorThpCallParams, type TrezorThpCredentials, type TrezorThpHandshakeCredentials, type TrezorThpHandshakeInitHandler, type TrezorThpHandshakeInitResponse, type TrezorThpPairingMethod, TrezorThpProtocol, type TrezorThpRawTransport, type TrezorThpSessionOptions, type TrezorThpState, type TrezorTransportProtocol };
278
+ 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 };