@onekeyfe/hwk-trezor-adapter 1.2.1 → 1.2.2-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,4 +1,4 @@
1
- import { IHardwareWallet, IConnector, TransportType, DeviceInfo, Response, ChainCapability, AllNetworkGetAddressParams, AllNetworkAddressResponse, TrezorDeviceSettingsParams, TrezorBrightnessParams, TrezorChangePinParams, UiResponseEvent, ChainForFingerprint, ICommonCallParams, EvmGetAddressParams, EvmAddress, EvmSignTxTrezorParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, SolGetAddressParams, SolAddress, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature, HardwareEventMap, DeviceEventListener, EvmEthereumDefinitions, ConnectorDevice } from '@onekeyfe/hwk-adapter-core';
1
+ import { IHardwareWallet, IConnector, TransportType, DeviceInfo, Response, ChainCapability, AllNetworkGetAddressParams, AllNetworkAddressResponse, DeviceAuthenticityParams, DeviceAuthenticityResult, TrezorDeviceSettingsParams, TrezorBrightnessParams, TrezorChangePinParams, UiResponseEvent, ChainForFingerprint, ICommonCallParams, EvmGetAddressParams, EvmAddress, EvmSignTxTrezorParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, SolGetAddressParams, SolAddress, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature, HardwareEventMap, DeviceEventListener, EvmEthereumDefinitions, ConnectorDevice } from '@onekeyfe/hwk-adapter-core';
2
2
 
3
3
  type TrezorPassphraseCallParams = {
4
4
  passphraseState?: string;
@@ -48,6 +48,7 @@ declare class TrezorAdapter implements IHardwareWallet {
48
48
  private static _isStaleSessionError;
49
49
  private static _errorCode;
50
50
  private static _isConnectionUnavailableError;
51
+ private static _isRecoverableProtocolResidueError;
51
52
  /**
52
53
  * Race a promise against an abort signal. Copied from LedgerAdapter:
53
54
  * IConnector.call() can't actually be cancelled at the protocol level, but
@@ -76,6 +77,21 @@ declare class TrezorAdapter implements IHardwareWallet {
76
77
  getSupportedChains(): ChainCapability[];
77
78
  allNetworkGetAddress(connectId: string, deviceId: string, params: AllNetworkGetAddressParams): Promise<Response<AllNetworkAddressResponse[]>>;
78
79
  getFeatures(connectId: string): Promise<Response<Record<string, unknown>>>;
80
+ /**
81
+ * Device authenticity attestation. Sends a host-generated challenge, has the
82
+ * device sign it with its secure-element key, then verifies the returned
83
+ * certificate chain up to a trusted Trezor root CA. On success returns a
84
+ * `deviceId` that uniquely identifies the physical device, survives wipe, and
85
+ * cannot be forged from a seed. Only trust the result when `verified` is true
86
+ * (and `usedDebugKey` is false in production).
87
+ *
88
+ * Requires a secure-element model (Safe 3 = T2B1/T3B1, Safe 5 = T3T1, T3W1)
89
+ * and an on-device confirmation. Older models (T1B1, T2T1) will fail.
90
+ *
91
+ * `dangerouslyAllowDebugKeys` accepts simulator / development root keys — NEVER
92
+ * enable it in a production accounting flow, it lets an emulator mint any id.
93
+ */
94
+ verifyDeviceAuthenticity(connectId: string, params?: DeviceAuthenticityParams): Promise<Response<DeviceAuthenticityResult>>;
79
95
  deviceSettings(connectId: string, params: TrezorDeviceSettingsParams): Promise<Response<Record<string, unknown>>>;
80
96
  setBrightness(connectId: string, params?: TrezorBrightnessParams): Promise<Response<Record<string, unknown>>>;
81
97
  changePin(connectId: string, params?: TrezorChangePinParams): Promise<Response<Record<string, unknown>>>;
@@ -192,6 +208,77 @@ declare class TrezorAdapter implements IHardwareWallet {
192
208
  private _ensureDevicePermission;
193
209
  }
194
210
 
211
+ type CertPubKeys = {
212
+ rootPubKeysOptiga: string[];
213
+ rootPubKeysTropic?: string[];
214
+ };
215
+ type ModelPubKeys = CertPubKeys & {
216
+ debug?: CertPubKeys;
217
+ };
218
+ interface DeviceAuthenticityConfig {
219
+ version: number;
220
+ [model: string]: ModelPubKeys | number | undefined;
221
+ }
222
+
223
+ /** Raw fields taken from a Trezor `AuthenticityProof` message. */
224
+ type AuthenticityProof = {
225
+ optiga_certificates: string[];
226
+ optiga_signature: string;
227
+ tropic_certificates?: string[];
228
+ tropic_signature?: string;
229
+ mcu_certificates?: string[];
230
+ mcu_signature?: string;
231
+ };
232
+ type AuthenticateDeviceResult = {
233
+ /**
234
+ * True only when every layer implemented by this verifier and required by
235
+ * the explicit model policy verified up to a trusted Trezor root CA AND the
236
+ * device signed our challenge:
237
+ * - Optiga (all secure-element models), and
238
+ * - Tropic (T3W1 / Safe 7).
239
+ * This is the currently implemented client policy, not full parity with the
240
+ * latest capability-based Trezor Connect policy. Raw MCU fields remain in the
241
+ * returned proof but are not yet a client-side pass/fail condition.
242
+ * The reward backend must independently verify the same raw proof under its
243
+ * own versioned policy; this client result is only a UX preview.
244
+ */
245
+ verified: boolean;
246
+ /**
247
+ * SHA3-256 of the verified Optiga device-attestation public key. It survives
248
+ * wipe/recovery and has one representation across supported models. Do NOT
249
+ * trust it when `verified` is false — it is then attacker-controlled.
250
+ */
251
+ deviceId?: string;
252
+ /** Raw device attestation public key (hex) from the Optiga device certificate. */
253
+ deviceCertPubKey?: string;
254
+ /** X.509 subject serial number (hex), only present on T3W1 and above. */
255
+ serialNumber?: string;
256
+ rootPubKey?: string;
257
+ caPubKey?: string;
258
+ /**
259
+ * True when the chain matched a DEBUG/staging root key (simulator / dev
260
+ * device). A production accounting flow must reject verified results that
261
+ * have `usedDebugKey === true`.
262
+ */
263
+ usedDebugKey?: boolean;
264
+ /** Failure reason when `verified` is false. */
265
+ error?: string;
266
+ };
267
+ declare const getRequiredDeviceAuthenticityLayers: (deviceModel: string) => readonly ('optiga' | 'tropic')[];
268
+ /**
269
+ * Verify a Trezor `AuthenticityProof` against a challenge and derive a stable
270
+ * per-device id. `challenge` must be the exact random bytes sent in the
271
+ * `AuthenticateDevice` request. Never throws — malformed input from a malicious
272
+ * device is folded into `{ verified: false }`.
273
+ */
274
+ declare const authenticateDeviceFromProof: ({ proof, challenge, deviceModel, config, allowDebugKeys, }: {
275
+ proof: AuthenticityProof;
276
+ challenge: Buffer;
277
+ deviceModel: string;
278
+ config?: DeviceAuthenticityConfig | undefined;
279
+ allowDebugKeys?: boolean | undefined;
280
+ }) => AuthenticateDeviceResult;
281
+
195
282
  /**
196
283
  * Opt-in helpers for fetching Trezor Ethereum "definitions" — the SatoshiLabs-
197
284
  * signed network/token metadata a Trezor device uses to render friendly names
@@ -326,4 +413,4 @@ declare function isTrezorBleServiceUuid(uuid: string): boolean;
326
413
  declare function isTrezorBleDescriptor(descriptor: TrezorBleDescriptor): boolean;
327
414
  declare function resolveTrezorBleConnectId(descriptor: TrezorBleDescriptor): string;
328
415
 
329
- export { type BuildEthereumDefinitionsForPathParams, type BuildEthereumDefinitionsForSignTxParams, DEFAULT_ETHEREUM_DEFINITIONS_BASE_URL, DEFAULT_SOLANA_TOKEN_DEFINITION_BASE_URL, type FetchEthereumDefinitionsParams, type FetchLike, type FetchSolanaTokenDefinitionParams, type SdkEvent, type SdkEventListener, type SdkLogEvent, TREZOR_BLE_PACKET_SIZE, TREZOR_BLE_SUPPORTED_MODELS, TREZOR_BLE_UUIDS, TREZOR_SAFE_7_MODEL, TrezorAdapter, type TrezorBleDescriptor, type TrezorBleTransport, type TrezorBleTransportFactory, type TrezorConnectedDevice, type TrezorConnectorDevice, buildEthereumDefinitionsForPath, buildEthereumDefinitionsForSignTx, fetchEthereumDefinitions, fetchSolanaTokenDefinition, getSlip44FromPath, isTrezorBleDescriptor, isTrezorBleServiceUuid, isTrezorBleSupportedModel, isTrezorSafe7BleDescriptor, isTrezorSafe7BleName, normalizeTrezorBleUuid, offSdkEvent, onSdkEvent, resolveTrezorBleConnectId };
416
+ export { type AuthenticateDeviceResult, type AuthenticityProof, type BuildEthereumDefinitionsForPathParams, type BuildEthereumDefinitionsForSignTxParams, DEFAULT_ETHEREUM_DEFINITIONS_BASE_URL, DEFAULT_SOLANA_TOKEN_DEFINITION_BASE_URL, type FetchEthereumDefinitionsParams, type FetchLike, type FetchSolanaTokenDefinitionParams, type SdkEvent, type SdkEventListener, type SdkLogEvent, TREZOR_BLE_PACKET_SIZE, TREZOR_BLE_SUPPORTED_MODELS, TREZOR_BLE_UUIDS, TREZOR_SAFE_7_MODEL, TrezorAdapter, type TrezorBleDescriptor, type TrezorBleTransport, type TrezorBleTransportFactory, type TrezorConnectedDevice, type TrezorConnectorDevice, authenticateDeviceFromProof, buildEthereumDefinitionsForPath, buildEthereumDefinitionsForSignTx, fetchEthereumDefinitions, fetchSolanaTokenDefinition, getRequiredDeviceAuthenticityLayers, getSlip44FromPath, isTrezorBleDescriptor, isTrezorBleServiceUuid, isTrezorBleSupportedModel, isTrezorSafe7BleDescriptor, isTrezorSafe7BleName, normalizeTrezorBleUuid, offSdkEvent, onSdkEvent, resolveTrezorBleConnectId };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IHardwareWallet, IConnector, TransportType, DeviceInfo, Response, ChainCapability, AllNetworkGetAddressParams, AllNetworkAddressResponse, TrezorDeviceSettingsParams, TrezorBrightnessParams, TrezorChangePinParams, UiResponseEvent, ChainForFingerprint, ICommonCallParams, EvmGetAddressParams, EvmAddress, EvmSignTxTrezorParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, SolGetAddressParams, SolAddress, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature, HardwareEventMap, DeviceEventListener, EvmEthereumDefinitions, ConnectorDevice } from '@onekeyfe/hwk-adapter-core';
1
+ import { IHardwareWallet, IConnector, TransportType, DeviceInfo, Response, ChainCapability, AllNetworkGetAddressParams, AllNetworkAddressResponse, DeviceAuthenticityParams, DeviceAuthenticityResult, TrezorDeviceSettingsParams, TrezorBrightnessParams, TrezorChangePinParams, UiResponseEvent, ChainForFingerprint, ICommonCallParams, EvmGetAddressParams, EvmAddress, EvmSignTxTrezorParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, SolGetAddressParams, SolAddress, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature, HardwareEventMap, DeviceEventListener, EvmEthereumDefinitions, ConnectorDevice } from '@onekeyfe/hwk-adapter-core';
2
2
 
3
3
  type TrezorPassphraseCallParams = {
4
4
  passphraseState?: string;
@@ -48,6 +48,7 @@ declare class TrezorAdapter implements IHardwareWallet {
48
48
  private static _isStaleSessionError;
49
49
  private static _errorCode;
50
50
  private static _isConnectionUnavailableError;
51
+ private static _isRecoverableProtocolResidueError;
51
52
  /**
52
53
  * Race a promise against an abort signal. Copied from LedgerAdapter:
53
54
  * IConnector.call() can't actually be cancelled at the protocol level, but
@@ -76,6 +77,21 @@ declare class TrezorAdapter implements IHardwareWallet {
76
77
  getSupportedChains(): ChainCapability[];
77
78
  allNetworkGetAddress(connectId: string, deviceId: string, params: AllNetworkGetAddressParams): Promise<Response<AllNetworkAddressResponse[]>>;
78
79
  getFeatures(connectId: string): Promise<Response<Record<string, unknown>>>;
80
+ /**
81
+ * Device authenticity attestation. Sends a host-generated challenge, has the
82
+ * device sign it with its secure-element key, then verifies the returned
83
+ * certificate chain up to a trusted Trezor root CA. On success returns a
84
+ * `deviceId` that uniquely identifies the physical device, survives wipe, and
85
+ * cannot be forged from a seed. Only trust the result when `verified` is true
86
+ * (and `usedDebugKey` is false in production).
87
+ *
88
+ * Requires a secure-element model (Safe 3 = T2B1/T3B1, Safe 5 = T3T1, T3W1)
89
+ * and an on-device confirmation. Older models (T1B1, T2T1) will fail.
90
+ *
91
+ * `dangerouslyAllowDebugKeys` accepts simulator / development root keys — NEVER
92
+ * enable it in a production accounting flow, it lets an emulator mint any id.
93
+ */
94
+ verifyDeviceAuthenticity(connectId: string, params?: DeviceAuthenticityParams): Promise<Response<DeviceAuthenticityResult>>;
79
95
  deviceSettings(connectId: string, params: TrezorDeviceSettingsParams): Promise<Response<Record<string, unknown>>>;
80
96
  setBrightness(connectId: string, params?: TrezorBrightnessParams): Promise<Response<Record<string, unknown>>>;
81
97
  changePin(connectId: string, params?: TrezorChangePinParams): Promise<Response<Record<string, unknown>>>;
@@ -192,6 +208,77 @@ declare class TrezorAdapter implements IHardwareWallet {
192
208
  private _ensureDevicePermission;
193
209
  }
194
210
 
211
+ type CertPubKeys = {
212
+ rootPubKeysOptiga: string[];
213
+ rootPubKeysTropic?: string[];
214
+ };
215
+ type ModelPubKeys = CertPubKeys & {
216
+ debug?: CertPubKeys;
217
+ };
218
+ interface DeviceAuthenticityConfig {
219
+ version: number;
220
+ [model: string]: ModelPubKeys | number | undefined;
221
+ }
222
+
223
+ /** Raw fields taken from a Trezor `AuthenticityProof` message. */
224
+ type AuthenticityProof = {
225
+ optiga_certificates: string[];
226
+ optiga_signature: string;
227
+ tropic_certificates?: string[];
228
+ tropic_signature?: string;
229
+ mcu_certificates?: string[];
230
+ mcu_signature?: string;
231
+ };
232
+ type AuthenticateDeviceResult = {
233
+ /**
234
+ * True only when every layer implemented by this verifier and required by
235
+ * the explicit model policy verified up to a trusted Trezor root CA AND the
236
+ * device signed our challenge:
237
+ * - Optiga (all secure-element models), and
238
+ * - Tropic (T3W1 / Safe 7).
239
+ * This is the currently implemented client policy, not full parity with the
240
+ * latest capability-based Trezor Connect policy. Raw MCU fields remain in the
241
+ * returned proof but are not yet a client-side pass/fail condition.
242
+ * The reward backend must independently verify the same raw proof under its
243
+ * own versioned policy; this client result is only a UX preview.
244
+ */
245
+ verified: boolean;
246
+ /**
247
+ * SHA3-256 of the verified Optiga device-attestation public key. It survives
248
+ * wipe/recovery and has one representation across supported models. Do NOT
249
+ * trust it when `verified` is false — it is then attacker-controlled.
250
+ */
251
+ deviceId?: string;
252
+ /** Raw device attestation public key (hex) from the Optiga device certificate. */
253
+ deviceCertPubKey?: string;
254
+ /** X.509 subject serial number (hex), only present on T3W1 and above. */
255
+ serialNumber?: string;
256
+ rootPubKey?: string;
257
+ caPubKey?: string;
258
+ /**
259
+ * True when the chain matched a DEBUG/staging root key (simulator / dev
260
+ * device). A production accounting flow must reject verified results that
261
+ * have `usedDebugKey === true`.
262
+ */
263
+ usedDebugKey?: boolean;
264
+ /** Failure reason when `verified` is false. */
265
+ error?: string;
266
+ };
267
+ declare const getRequiredDeviceAuthenticityLayers: (deviceModel: string) => readonly ('optiga' | 'tropic')[];
268
+ /**
269
+ * Verify a Trezor `AuthenticityProof` against a challenge and derive a stable
270
+ * per-device id. `challenge` must be the exact random bytes sent in the
271
+ * `AuthenticateDevice` request. Never throws — malformed input from a malicious
272
+ * device is folded into `{ verified: false }`.
273
+ */
274
+ declare const authenticateDeviceFromProof: ({ proof, challenge, deviceModel, config, allowDebugKeys, }: {
275
+ proof: AuthenticityProof;
276
+ challenge: Buffer;
277
+ deviceModel: string;
278
+ config?: DeviceAuthenticityConfig | undefined;
279
+ allowDebugKeys?: boolean | undefined;
280
+ }) => AuthenticateDeviceResult;
281
+
195
282
  /**
196
283
  * Opt-in helpers for fetching Trezor Ethereum "definitions" — the SatoshiLabs-
197
284
  * signed network/token metadata a Trezor device uses to render friendly names
@@ -326,4 +413,4 @@ declare function isTrezorBleServiceUuid(uuid: string): boolean;
326
413
  declare function isTrezorBleDescriptor(descriptor: TrezorBleDescriptor): boolean;
327
414
  declare function resolveTrezorBleConnectId(descriptor: TrezorBleDescriptor): string;
328
415
 
329
- export { type BuildEthereumDefinitionsForPathParams, type BuildEthereumDefinitionsForSignTxParams, DEFAULT_ETHEREUM_DEFINITIONS_BASE_URL, DEFAULT_SOLANA_TOKEN_DEFINITION_BASE_URL, type FetchEthereumDefinitionsParams, type FetchLike, type FetchSolanaTokenDefinitionParams, type SdkEvent, type SdkEventListener, type SdkLogEvent, TREZOR_BLE_PACKET_SIZE, TREZOR_BLE_SUPPORTED_MODELS, TREZOR_BLE_UUIDS, TREZOR_SAFE_7_MODEL, TrezorAdapter, type TrezorBleDescriptor, type TrezorBleTransport, type TrezorBleTransportFactory, type TrezorConnectedDevice, type TrezorConnectorDevice, buildEthereumDefinitionsForPath, buildEthereumDefinitionsForSignTx, fetchEthereumDefinitions, fetchSolanaTokenDefinition, getSlip44FromPath, isTrezorBleDescriptor, isTrezorBleServiceUuid, isTrezorBleSupportedModel, isTrezorSafe7BleDescriptor, isTrezorSafe7BleName, normalizeTrezorBleUuid, offSdkEvent, onSdkEvent, resolveTrezorBleConnectId };
416
+ export { type AuthenticateDeviceResult, type AuthenticityProof, type BuildEthereumDefinitionsForPathParams, type BuildEthereumDefinitionsForSignTxParams, DEFAULT_ETHEREUM_DEFINITIONS_BASE_URL, DEFAULT_SOLANA_TOKEN_DEFINITION_BASE_URL, type FetchEthereumDefinitionsParams, type FetchLike, type FetchSolanaTokenDefinitionParams, type SdkEvent, type SdkEventListener, type SdkLogEvent, TREZOR_BLE_PACKET_SIZE, TREZOR_BLE_SUPPORTED_MODELS, TREZOR_BLE_UUIDS, TREZOR_SAFE_7_MODEL, TrezorAdapter, type TrezorBleDescriptor, type TrezorBleTransport, type TrezorBleTransportFactory, type TrezorConnectedDevice, type TrezorConnectorDevice, authenticateDeviceFromProof, buildEthereumDefinitionsForPath, buildEthereumDefinitionsForSignTx, fetchEthereumDefinitions, fetchSolanaTokenDefinition, getRequiredDeviceAuthenticityLayers, getSlip44FromPath, isTrezorBleDescriptor, isTrezorBleServiceUuid, isTrezorBleSupportedModel, isTrezorSafe7BleDescriptor, isTrezorSafe7BleName, normalizeTrezorBleUuid, offSdkEvent, onSdkEvent, resolveTrezorBleConnectId };