@onekeyfe/hwk-trezor-core 1.1.27-alpha.101 → 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 +39 -16
- package/dist/index.d.ts +39 -16
- package/dist/index.js +261 -267
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +261 -267
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
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
|
|
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;
|
|
@@ -231,11 +250,12 @@ declare class TrezorDeviceSession {
|
|
|
231
250
|
/**
|
|
232
251
|
* Create a NEW THP application session with a freshly-prompted passphrase
|
|
233
252
|
* (or empty if the device has no passphrase protection). Returns the new
|
|
234
|
-
* session id (hex). The session knows nothing about wallet identity
|
|
235
|
-
*
|
|
236
|
-
*
|
|
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.
|
|
237
256
|
*/
|
|
238
|
-
createThpAppSession(
|
|
257
|
+
createThpAppSession(options?: boolean | TrezorCreateAppSessionOptions): Promise<string>;
|
|
258
|
+
createV1AppSession(options?: TrezorCreateAppSessionOptions): Promise<void>;
|
|
239
259
|
/**
|
|
240
260
|
* Switch the active THP session to an existing id (host-side: just sets the
|
|
241
261
|
* session-id byte in the next message header). The device must still hold
|
|
@@ -245,12 +265,15 @@ declare class TrezorDeviceSession {
|
|
|
245
265
|
selectThpAppSession(sessionId: string): void;
|
|
246
266
|
/** Active THP session id (hex), or undefined if none created/selected. */
|
|
247
267
|
getThpAppSessionId(): string | undefined;
|
|
248
|
-
|
|
268
|
+
withDeviceState<T>(fn: () => Promise<T>, options?: {
|
|
269
|
+
deriveCardano?: boolean;
|
|
270
|
+
}): Promise<T>;
|
|
249
271
|
private handleButtonRequest;
|
|
272
|
+
private handleButtonRequestComplete;
|
|
250
273
|
private handlePinMatrixRequest;
|
|
251
274
|
private handlePassphraseRequest;
|
|
252
275
|
private cancelCurrentCall;
|
|
253
276
|
private log;
|
|
254
277
|
}
|
|
255
278
|
|
|
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 };
|
|
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,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
|
|
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;
|
|
@@ -231,11 +250,12 @@ declare class TrezorDeviceSession {
|
|
|
231
250
|
/**
|
|
232
251
|
* Create a NEW THP application session with a freshly-prompted passphrase
|
|
233
252
|
* (or empty if the device has no passphrase protection). Returns the new
|
|
234
|
-
* session id (hex). The session knows nothing about wallet identity
|
|
235
|
-
*
|
|
236
|
-
*
|
|
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.
|
|
237
256
|
*/
|
|
238
|
-
createThpAppSession(
|
|
257
|
+
createThpAppSession(options?: boolean | TrezorCreateAppSessionOptions): Promise<string>;
|
|
258
|
+
createV1AppSession(options?: TrezorCreateAppSessionOptions): Promise<void>;
|
|
239
259
|
/**
|
|
240
260
|
* Switch the active THP session to an existing id (host-side: just sets the
|
|
241
261
|
* session-id byte in the next message header). The device must still hold
|
|
@@ -245,12 +265,15 @@ declare class TrezorDeviceSession {
|
|
|
245
265
|
selectThpAppSession(sessionId: string): void;
|
|
246
266
|
/** Active THP session id (hex), or undefined if none created/selected. */
|
|
247
267
|
getThpAppSessionId(): string | undefined;
|
|
248
|
-
|
|
268
|
+
withDeviceState<T>(fn: () => Promise<T>, options?: {
|
|
269
|
+
deriveCardano?: boolean;
|
|
270
|
+
}): Promise<T>;
|
|
249
271
|
private handleButtonRequest;
|
|
272
|
+
private handleButtonRequestComplete;
|
|
250
273
|
private handlePinMatrixRequest;
|
|
251
274
|
private handlePassphraseRequest;
|
|
252
275
|
private cancelCurrentCall;
|
|
253
276
|
private log;
|
|
254
277
|
}
|
|
255
278
|
|
|
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 };
|
|
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 };
|