@onekeyfe/hwk-trezor-adapter 1.1.29-alpha.3 → 1.1.29-alpha.5
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 +72 -2
- package/dist/index.d.ts +72 -2
- package/dist/index.js +131 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +130 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
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, EvmSignTxParams, 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, ConnectorDevice } from '@onekeyfe/hwk-adapter-core';
|
|
1
|
+
import { IHardwareWallet, IConnector, TransportType, DeviceInfo, Response, ChainCapability, AllNetworkGetAddressParams, AllNetworkAddressResponse, TrezorDeviceSettingsParams, TrezorBrightnessParams, TrezorChangePinParams, UiResponseEvent, ChainForFingerprint, ICommonCallParams, EvmGetAddressParams, EvmAddress, EvmSignTxParams, 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;
|
|
@@ -190,6 +190,76 @@ declare class TrezorAdapter implements IHardwareWallet {
|
|
|
190
190
|
private _ensureDevicePermission;
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
+
/**
|
|
194
|
+
* Opt-in helpers for fetching Trezor Ethereum "definitions" — the SatoshiLabs-
|
|
195
|
+
* signed network/token metadata a Trezor device uses to render friendly names
|
|
196
|
+
* for chains and tokens that are NOT built into firmware.
|
|
197
|
+
*
|
|
198
|
+
* IMPORTANT — the SDK signing methods (evmSignTransaction / evmGetAddress / …)
|
|
199
|
+
* NEVER call these. A local hardware operation must not silently become a
|
|
200
|
+
* third-party network request (see PR #824 review). The caller decides whether,
|
|
201
|
+
* when, and where to fetch, then passes the result into the sign params as
|
|
202
|
+
* `ethereumDefinitions`. When omitted, the device falls back to a generic
|
|
203
|
+
* confirmation screen and signing still completes.
|
|
204
|
+
*
|
|
205
|
+
* Cross-process note: `fetchImpl` is a FUNCTION and cannot be serialized across
|
|
206
|
+
* an IPC / postMessage boundary. Call these helpers in a network-capable
|
|
207
|
+
* process and send only the resulting bytes (ArrayBuffer/hex) to the process
|
|
208
|
+
* that talks to the device. Use `baseUrl` (a string) to route through your own
|
|
209
|
+
* controlled proxy instead of hitting data.trezor.io directly.
|
|
210
|
+
*/
|
|
211
|
+
/** Default upstream (Trezor). Override with `baseUrl` to use your own proxy. */
|
|
212
|
+
declare const DEFAULT_ETHEREUM_DEFINITIONS_BASE_URL = "https://data.trezor.io/firmware/eth-definitions";
|
|
213
|
+
type FetchLike = (url: string) => Promise<{
|
|
214
|
+
status: number;
|
|
215
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
216
|
+
}>;
|
|
217
|
+
type FetchEthereumDefinitionsParams = {
|
|
218
|
+
chainId?: number;
|
|
219
|
+
slip44?: number;
|
|
220
|
+
contractAddress?: string;
|
|
221
|
+
baseUrl?: string;
|
|
222
|
+
fetchImpl?: FetchLike;
|
|
223
|
+
};
|
|
224
|
+
type BuildEthereumDefinitionsForPathParams = {
|
|
225
|
+
path: string;
|
|
226
|
+
baseUrl?: string;
|
|
227
|
+
fetchImpl?: FetchLike;
|
|
228
|
+
};
|
|
229
|
+
type BuildEthereumDefinitionsForSignTxParams = {
|
|
230
|
+
path: string;
|
|
231
|
+
chainId: number;
|
|
232
|
+
to?: string;
|
|
233
|
+
data?: string;
|
|
234
|
+
baseUrl?: string;
|
|
235
|
+
fetchImpl?: FetchLike;
|
|
236
|
+
};
|
|
237
|
+
/** Derive the SLIP-44 coin type (unhardened) from a BIP44-style path. */
|
|
238
|
+
declare function getSlip44FromPath(path: string): number;
|
|
239
|
+
declare function fetchEthereumDefinitions({ chainId, slip44, contractAddress, baseUrl, fetchImpl, }: FetchEthereumDefinitionsParams): Promise<EvmEthereumDefinitions>;
|
|
240
|
+
declare function buildEthereumDefinitionsForPath({ path, baseUrl, fetchImpl, }: BuildEthereumDefinitionsForPathParams): Promise<EvmEthereumDefinitions>;
|
|
241
|
+
declare function buildEthereumDefinitionsForSignTx({ path, chainId, to, data, baseUrl, fetchImpl, }: BuildEthereumDefinitionsForSignTxParams): Promise<EvmEthereumDefinitions | undefined>;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Opt-in helper for fetching a Trezor Solana token definition. Same contract as
|
|
245
|
+
* the Ethereum helpers (see ./ethereumDefinitions): the SDK signing path NEVER
|
|
246
|
+
* calls this — the caller fetches (through its own `baseUrl` proxy if desired)
|
|
247
|
+
* and passes the bytes into `solSignTransaction` params as
|
|
248
|
+
* `additionalInfo.encodedToken`. When omitted the device shows a generic token
|
|
249
|
+
* confirmation screen and signing still completes.
|
|
250
|
+
*
|
|
251
|
+
* `fetchImpl` is a function and must not cross an IPC boundary — fetch in a
|
|
252
|
+
* network-capable process and pass only the resulting bytes.
|
|
253
|
+
*/
|
|
254
|
+
/** Default upstream (Trezor). Override with `baseUrl` to use your own proxy. */
|
|
255
|
+
declare const DEFAULT_SOLANA_TOKEN_DEFINITION_BASE_URL = "https://data.trezor.io/firmware/definitions/solana/token";
|
|
256
|
+
type FetchSolanaTokenDefinitionParams = {
|
|
257
|
+
tokenMint: string;
|
|
258
|
+
baseUrl?: string;
|
|
259
|
+
fetchImpl?: FetchLike;
|
|
260
|
+
};
|
|
261
|
+
declare function fetchSolanaTokenDefinition({ tokenMint, baseUrl, fetchImpl, }: FetchSolanaTokenDefinitionParams): Promise<ArrayBuffer | undefined>;
|
|
262
|
+
|
|
193
263
|
/**
|
|
194
264
|
* SDK-global event bus. Per-runtime singleton; hosts forward events over their
|
|
195
265
|
* own IPC when the adapter runs in an offscreen/background split.
|
|
@@ -254,4 +324,4 @@ declare function isTrezorBleServiceUuid(uuid: string): boolean;
|
|
|
254
324
|
declare function isTrezorBleDescriptor(descriptor: TrezorBleDescriptor): boolean;
|
|
255
325
|
declare function resolveTrezorBleConnectId(descriptor: TrezorBleDescriptor): string;
|
|
256
326
|
|
|
257
|
-
export { 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, isTrezorBleDescriptor, isTrezorBleServiceUuid, isTrezorBleSupportedModel, isTrezorSafe7BleDescriptor, isTrezorSafe7BleName, normalizeTrezorBleUuid, offSdkEvent, onSdkEvent, resolveTrezorBleConnectId };
|
|
327
|
+
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 };
|
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, EvmSignTxParams, 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, ConnectorDevice } from '@onekeyfe/hwk-adapter-core';
|
|
1
|
+
import { IHardwareWallet, IConnector, TransportType, DeviceInfo, Response, ChainCapability, AllNetworkGetAddressParams, AllNetworkAddressResponse, TrezorDeviceSettingsParams, TrezorBrightnessParams, TrezorChangePinParams, UiResponseEvent, ChainForFingerprint, ICommonCallParams, EvmGetAddressParams, EvmAddress, EvmSignTxParams, 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;
|
|
@@ -190,6 +190,76 @@ declare class TrezorAdapter implements IHardwareWallet {
|
|
|
190
190
|
private _ensureDevicePermission;
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
+
/**
|
|
194
|
+
* Opt-in helpers for fetching Trezor Ethereum "definitions" — the SatoshiLabs-
|
|
195
|
+
* signed network/token metadata a Trezor device uses to render friendly names
|
|
196
|
+
* for chains and tokens that are NOT built into firmware.
|
|
197
|
+
*
|
|
198
|
+
* IMPORTANT — the SDK signing methods (evmSignTransaction / evmGetAddress / …)
|
|
199
|
+
* NEVER call these. A local hardware operation must not silently become a
|
|
200
|
+
* third-party network request (see PR #824 review). The caller decides whether,
|
|
201
|
+
* when, and where to fetch, then passes the result into the sign params as
|
|
202
|
+
* `ethereumDefinitions`. When omitted, the device falls back to a generic
|
|
203
|
+
* confirmation screen and signing still completes.
|
|
204
|
+
*
|
|
205
|
+
* Cross-process note: `fetchImpl` is a FUNCTION and cannot be serialized across
|
|
206
|
+
* an IPC / postMessage boundary. Call these helpers in a network-capable
|
|
207
|
+
* process and send only the resulting bytes (ArrayBuffer/hex) to the process
|
|
208
|
+
* that talks to the device. Use `baseUrl` (a string) to route through your own
|
|
209
|
+
* controlled proxy instead of hitting data.trezor.io directly.
|
|
210
|
+
*/
|
|
211
|
+
/** Default upstream (Trezor). Override with `baseUrl` to use your own proxy. */
|
|
212
|
+
declare const DEFAULT_ETHEREUM_DEFINITIONS_BASE_URL = "https://data.trezor.io/firmware/eth-definitions";
|
|
213
|
+
type FetchLike = (url: string) => Promise<{
|
|
214
|
+
status: number;
|
|
215
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
216
|
+
}>;
|
|
217
|
+
type FetchEthereumDefinitionsParams = {
|
|
218
|
+
chainId?: number;
|
|
219
|
+
slip44?: number;
|
|
220
|
+
contractAddress?: string;
|
|
221
|
+
baseUrl?: string;
|
|
222
|
+
fetchImpl?: FetchLike;
|
|
223
|
+
};
|
|
224
|
+
type BuildEthereumDefinitionsForPathParams = {
|
|
225
|
+
path: string;
|
|
226
|
+
baseUrl?: string;
|
|
227
|
+
fetchImpl?: FetchLike;
|
|
228
|
+
};
|
|
229
|
+
type BuildEthereumDefinitionsForSignTxParams = {
|
|
230
|
+
path: string;
|
|
231
|
+
chainId: number;
|
|
232
|
+
to?: string;
|
|
233
|
+
data?: string;
|
|
234
|
+
baseUrl?: string;
|
|
235
|
+
fetchImpl?: FetchLike;
|
|
236
|
+
};
|
|
237
|
+
/** Derive the SLIP-44 coin type (unhardened) from a BIP44-style path. */
|
|
238
|
+
declare function getSlip44FromPath(path: string): number;
|
|
239
|
+
declare function fetchEthereumDefinitions({ chainId, slip44, contractAddress, baseUrl, fetchImpl, }: FetchEthereumDefinitionsParams): Promise<EvmEthereumDefinitions>;
|
|
240
|
+
declare function buildEthereumDefinitionsForPath({ path, baseUrl, fetchImpl, }: BuildEthereumDefinitionsForPathParams): Promise<EvmEthereumDefinitions>;
|
|
241
|
+
declare function buildEthereumDefinitionsForSignTx({ path, chainId, to, data, baseUrl, fetchImpl, }: BuildEthereumDefinitionsForSignTxParams): Promise<EvmEthereumDefinitions | undefined>;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Opt-in helper for fetching a Trezor Solana token definition. Same contract as
|
|
245
|
+
* the Ethereum helpers (see ./ethereumDefinitions): the SDK signing path NEVER
|
|
246
|
+
* calls this — the caller fetches (through its own `baseUrl` proxy if desired)
|
|
247
|
+
* and passes the bytes into `solSignTransaction` params as
|
|
248
|
+
* `additionalInfo.encodedToken`. When omitted the device shows a generic token
|
|
249
|
+
* confirmation screen and signing still completes.
|
|
250
|
+
*
|
|
251
|
+
* `fetchImpl` is a function and must not cross an IPC boundary — fetch in a
|
|
252
|
+
* network-capable process and pass only the resulting bytes.
|
|
253
|
+
*/
|
|
254
|
+
/** Default upstream (Trezor). Override with `baseUrl` to use your own proxy. */
|
|
255
|
+
declare const DEFAULT_SOLANA_TOKEN_DEFINITION_BASE_URL = "https://data.trezor.io/firmware/definitions/solana/token";
|
|
256
|
+
type FetchSolanaTokenDefinitionParams = {
|
|
257
|
+
tokenMint: string;
|
|
258
|
+
baseUrl?: string;
|
|
259
|
+
fetchImpl?: FetchLike;
|
|
260
|
+
};
|
|
261
|
+
declare function fetchSolanaTokenDefinition({ tokenMint, baseUrl, fetchImpl, }: FetchSolanaTokenDefinitionParams): Promise<ArrayBuffer | undefined>;
|
|
262
|
+
|
|
193
263
|
/**
|
|
194
264
|
* SDK-global event bus. Per-runtime singleton; hosts forward events over their
|
|
195
265
|
* own IPC when the adapter runs in an offscreen/background split.
|
|
@@ -254,4 +324,4 @@ declare function isTrezorBleServiceUuid(uuid: string): boolean;
|
|
|
254
324
|
declare function isTrezorBleDescriptor(descriptor: TrezorBleDescriptor): boolean;
|
|
255
325
|
declare function resolveTrezorBleConnectId(descriptor: TrezorBleDescriptor): string;
|
|
256
326
|
|
|
257
|
-
export { 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, isTrezorBleDescriptor, isTrezorBleServiceUuid, isTrezorBleSupportedModel, isTrezorSafe7BleDescriptor, isTrezorSafe7BleName, normalizeTrezorBleUuid, offSdkEvent, onSdkEvent, resolveTrezorBleConnectId };
|
|
327
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -56,6 +56,9 @@ function debugLog(...args) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// src/adapter/TrezorAdapter.ts
|
|
59
|
+
var KNOWN_HARDWARE_ERROR_CODES = new Set(
|
|
60
|
+
Object.values(_hwkadaptercore.HardwareErrorCode).filter((value) => typeof value === "number")
|
|
61
|
+
);
|
|
59
62
|
var TREZOR_BTC_NETWORK_COIN_MAP = {
|
|
60
63
|
btc: "Bitcoin",
|
|
61
64
|
bitcoin: "Bitcoin",
|
|
@@ -253,6 +256,9 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
253
256
|
if (directCode === "Failure_ActionCancelled") {
|
|
254
257
|
return _hwkadaptercore.HardwareErrorCode.UserRejected;
|
|
255
258
|
}
|
|
259
|
+
if (directCode === "ThpPairingRequired") {
|
|
260
|
+
return _hwkadaptercore.HardwareErrorCode.ThpPairingRequired;
|
|
261
|
+
}
|
|
256
262
|
const message = _optionalChain([error, 'optionalAccess', _9 => _9.message]);
|
|
257
263
|
if (typeof message === "string" && message.includes("Failed to execute 'transfer") && message.includes("on 'USBDevice'")) {
|
|
258
264
|
return _hwkadaptercore.HardwareErrorCode.TransportError;
|
|
@@ -270,6 +276,12 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
270
276
|
if (failure2.code === "Failure_ProcessError" && failure2.message === "Unsupported script type") {
|
|
271
277
|
return _hwkadaptercore.HardwareErrorCode.MethodNotSupported;
|
|
272
278
|
}
|
|
279
|
+
if (failure2.code === "Failure_DataError" && failure2.message === "Forbidden key path") {
|
|
280
|
+
return _hwkadaptercore.HardwareErrorCode.DevicePathForbidden;
|
|
281
|
+
}
|
|
282
|
+
if (failure2.code === "Failure_FirmwareError") {
|
|
283
|
+
return _hwkadaptercore.HardwareErrorCode.MethodNotSupported;
|
|
284
|
+
}
|
|
273
285
|
return void 0;
|
|
274
286
|
}
|
|
275
287
|
/**
|
|
@@ -1031,7 +1043,8 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
1031
1043
|
if (typed.code === "ThpPairingFailed") {
|
|
1032
1044
|
return _hwkadaptercore.failure.call(void 0, _hwkadaptercore.HardwareErrorCode.ThpPairingFailed, _nullishCoalesce(typed.message, () => ( "THP pairing failed")));
|
|
1033
1045
|
}
|
|
1034
|
-
const
|
|
1046
|
+
const trustedNumericCode = typeof typed.code === "number" && KNOWN_HARDWARE_ERROR_CODES.has(typed.code) ? typed.code : void 0;
|
|
1047
|
+
const code = _nullishCoalesce(_nullishCoalesce(trustedNumericCode, () => ( _TrezorAdapter._mapTrezorFailureCode(error))), () => ( _hwkadaptercore.HardwareErrorCode.UnknownError));
|
|
1035
1048
|
return _hwkadaptercore.failure.call(void 0, code, _nullishCoalesce(typed.message, () => ( String(error))));
|
|
1036
1049
|
}
|
|
1037
1050
|
/**
|
|
@@ -1069,6 +1082,115 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
1069
1082
|
}
|
|
1070
1083
|
};
|
|
1071
1084
|
|
|
1085
|
+
// src/utils/ethereumDefinitions.ts
|
|
1086
|
+
var DEFAULT_ETHEREUM_DEFINITIONS_BASE_URL = "https://data.trezor.io/firmware/eth-definitions";
|
|
1087
|
+
function getSlip44FromPath(path) {
|
|
1088
|
+
const segments = path.trim().replace(/^m\//i, "").split("/");
|
|
1089
|
+
const coinType = segments[1];
|
|
1090
|
+
const parsed = coinType === void 0 ? NaN : Number(coinType.replace(/['hH]$/, ""));
|
|
1091
|
+
if (!Number.isFinite(parsed)) {
|
|
1092
|
+
throw new Error(`Cannot derive SLIP-44 coin type from path: ${path}`);
|
|
1093
|
+
}
|
|
1094
|
+
return parsed >= 2147483648 ? parsed - 2147483648 : parsed;
|
|
1095
|
+
}
|
|
1096
|
+
async function fetchEthereumDefinitions({
|
|
1097
|
+
chainId,
|
|
1098
|
+
slip44,
|
|
1099
|
+
contractAddress,
|
|
1100
|
+
baseUrl = DEFAULT_ETHEREUM_DEFINITIONS_BASE_URL,
|
|
1101
|
+
fetchImpl = globalThis.fetch
|
|
1102
|
+
}) {
|
|
1103
|
+
if (!chainId && !slip44) {
|
|
1104
|
+
throw new Error("fetchEthereumDefinitions requires chainId or slip44");
|
|
1105
|
+
}
|
|
1106
|
+
if (!fetchImpl) {
|
|
1107
|
+
return {};
|
|
1108
|
+
}
|
|
1109
|
+
const mode = chainId ? "chain-id" : "slip44";
|
|
1110
|
+
const id = _nullishCoalesce(chainId, () => ( slip44));
|
|
1111
|
+
const definitions = {};
|
|
1112
|
+
const network = await fetchDefinition(`${baseUrl}/${mode}/${id}/network.dat`, fetchImpl);
|
|
1113
|
+
if (network) {
|
|
1114
|
+
definitions.encodedNetwork = network;
|
|
1115
|
+
}
|
|
1116
|
+
if (contractAddress) {
|
|
1117
|
+
const token = await fetchDefinition(
|
|
1118
|
+
`${baseUrl}/${mode}/${id}/token-${stripHexPrefix(contractAddress).toLowerCase()}.dat`,
|
|
1119
|
+
fetchImpl
|
|
1120
|
+
);
|
|
1121
|
+
if (token) {
|
|
1122
|
+
definitions.encodedToken = token;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
return definitions;
|
|
1126
|
+
}
|
|
1127
|
+
async function buildEthereumDefinitionsForPath({
|
|
1128
|
+
path,
|
|
1129
|
+
baseUrl,
|
|
1130
|
+
fetchImpl
|
|
1131
|
+
}) {
|
|
1132
|
+
return fetchEthereumDefinitions({
|
|
1133
|
+
slip44: getSlip44FromPath(path),
|
|
1134
|
+
baseUrl,
|
|
1135
|
+
fetchImpl
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
async function buildEthereumDefinitionsForSignTx({
|
|
1139
|
+
path,
|
|
1140
|
+
chainId,
|
|
1141
|
+
to,
|
|
1142
|
+
data,
|
|
1143
|
+
baseUrl,
|
|
1144
|
+
fetchImpl
|
|
1145
|
+
}) {
|
|
1146
|
+
const dataHex = stripHexPrefix(_nullishCoalesce(data, () => ( "")));
|
|
1147
|
+
if (chainId === 1 && !dataHex) {
|
|
1148
|
+
return void 0;
|
|
1149
|
+
}
|
|
1150
|
+
return fetchEthereumDefinitions({
|
|
1151
|
+
chainId,
|
|
1152
|
+
slip44: getSlip44FromPath(path),
|
|
1153
|
+
contractAddress: dataHex && to ? to : void 0,
|
|
1154
|
+
baseUrl,
|
|
1155
|
+
fetchImpl
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
async function fetchDefinition(url, fetchImpl) {
|
|
1159
|
+
try {
|
|
1160
|
+
const response = await fetchImpl(url);
|
|
1161
|
+
if (response.status !== 200) {
|
|
1162
|
+
return void 0;
|
|
1163
|
+
}
|
|
1164
|
+
return await response.arrayBuffer();
|
|
1165
|
+
} catch (e3) {
|
|
1166
|
+
return void 0;
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
function stripHexPrefix(value) {
|
|
1170
|
+
return value.startsWith("0x") || value.startsWith("0X") ? value.slice(2) : value;
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
// src/utils/solanaTokenDefinition.ts
|
|
1174
|
+
var DEFAULT_SOLANA_TOKEN_DEFINITION_BASE_URL = "https://data.trezor.io/firmware/definitions/solana/token";
|
|
1175
|
+
async function fetchSolanaTokenDefinition({
|
|
1176
|
+
tokenMint,
|
|
1177
|
+
baseUrl = DEFAULT_SOLANA_TOKEN_DEFINITION_BASE_URL,
|
|
1178
|
+
fetchImpl = globalThis.fetch
|
|
1179
|
+
}) {
|
|
1180
|
+
if (!fetchImpl) {
|
|
1181
|
+
return void 0;
|
|
1182
|
+
}
|
|
1183
|
+
try {
|
|
1184
|
+
const response = await fetchImpl(`${baseUrl}/${tokenMint}.dat`);
|
|
1185
|
+
if (response.status !== 200) {
|
|
1186
|
+
return void 0;
|
|
1187
|
+
}
|
|
1188
|
+
return await response.arrayBuffer();
|
|
1189
|
+
} catch (e4) {
|
|
1190
|
+
return void 0;
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1072
1194
|
// src/constants.ts
|
|
1073
1195
|
var TREZOR_SAFE_7_MODEL = "T3W1";
|
|
1074
1196
|
var TREZOR_BLE_SUPPORTED_MODELS = [TREZOR_SAFE_7_MODEL];
|
|
@@ -1128,5 +1250,12 @@ function resolveTrezorBleConnectId(descriptor) {
|
|
|
1128
1250
|
|
|
1129
1251
|
|
|
1130
1252
|
|
|
1131
|
-
|
|
1253
|
+
|
|
1254
|
+
|
|
1255
|
+
|
|
1256
|
+
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
|
|
1260
|
+
exports.DEFAULT_ETHEREUM_DEFINITIONS_BASE_URL = DEFAULT_ETHEREUM_DEFINITIONS_BASE_URL; exports.DEFAULT_SOLANA_TOKEN_DEFINITION_BASE_URL = DEFAULT_SOLANA_TOKEN_DEFINITION_BASE_URL; exports.TREZOR_BLE_PACKET_SIZE = TREZOR_BLE_PACKET_SIZE; exports.TREZOR_BLE_SUPPORTED_MODELS = TREZOR_BLE_SUPPORTED_MODELS; exports.TREZOR_BLE_UUIDS = TREZOR_BLE_UUIDS; exports.TREZOR_SAFE_7_MODEL = TREZOR_SAFE_7_MODEL; exports.TrezorAdapter = TrezorAdapter; exports.buildEthereumDefinitionsForPath = buildEthereumDefinitionsForPath; exports.buildEthereumDefinitionsForSignTx = buildEthereumDefinitionsForSignTx; exports.fetchEthereumDefinitions = fetchEthereumDefinitions; exports.fetchSolanaTokenDefinition = fetchSolanaTokenDefinition; exports.getSlip44FromPath = getSlip44FromPath; exports.isTrezorBleDescriptor = isTrezorBleDescriptor; exports.isTrezorBleServiceUuid = isTrezorBleServiceUuid; exports.isTrezorBleSupportedModel = isTrezorBleSupportedModel; exports.isTrezorSafe7BleDescriptor = isTrezorSafe7BleDescriptor; exports.isTrezorSafe7BleName = isTrezorSafe7BleName; exports.normalizeTrezorBleUuid = normalizeTrezorBleUuid; exports.offSdkEvent = offSdkEvent; exports.onSdkEvent = onSdkEvent; exports.resolveTrezorBleConnectId = resolveTrezorBleConnectId;
|
|
1132
1261
|
//# sourceMappingURL=index.js.map
|