@onekeyfe/hwk-trezor-adapter 1.1.29-alpha.4 → 1.1.29-alpha.6
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 +130 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +129 -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
|
@@ -146,7 +146,7 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
146
146
|
}
|
|
147
147
|
static _createDeviceBusyError(method) {
|
|
148
148
|
return Object.assign(new Error(`Trezor is busy with another request (${method})`), {
|
|
149
|
-
code: _hwkadaptercore.HardwareErrorCode.
|
|
149
|
+
code: _hwkadaptercore.HardwareErrorCode.DeviceBusyInternal
|
|
150
150
|
});
|
|
151
151
|
}
|
|
152
152
|
/**
|
|
@@ -259,6 +259,9 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
259
259
|
if (directCode === "ThpPairingRequired") {
|
|
260
260
|
return _hwkadaptercore.HardwareErrorCode.ThpPairingRequired;
|
|
261
261
|
}
|
|
262
|
+
if (directCode === "Failure_UnexpectedMessage") {
|
|
263
|
+
return _hwkadaptercore.HardwareErrorCode.MethodNotSupported;
|
|
264
|
+
}
|
|
262
265
|
const message = _optionalChain([error, 'optionalAccess', _9 => _9.message]);
|
|
263
266
|
if (typeof message === "string" && message.includes("Failed to execute 'transfer") && message.includes("on 'USBDevice'")) {
|
|
264
267
|
return _hwkadaptercore.HardwareErrorCode.TransportError;
|
|
@@ -282,6 +285,15 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
282
285
|
if (failure2.code === "Failure_FirmwareError") {
|
|
283
286
|
return _hwkadaptercore.HardwareErrorCode.MethodNotSupported;
|
|
284
287
|
}
|
|
288
|
+
if (failure2.code === "Failure_UnexpectedMessage") {
|
|
289
|
+
return _hwkadaptercore.HardwareErrorCode.MethodNotSupported;
|
|
290
|
+
}
|
|
291
|
+
if (failure2.code === "Failure_NotInitialized") {
|
|
292
|
+
return _hwkadaptercore.HardwareErrorCode.DeviceNotInitialized;
|
|
293
|
+
}
|
|
294
|
+
if (failure2.code === "Failure_Busy" || failure2.code === "Failure_InProgress") {
|
|
295
|
+
return _hwkadaptercore.HardwareErrorCode.DeviceBusyInternal;
|
|
296
|
+
}
|
|
285
297
|
return void 0;
|
|
286
298
|
}
|
|
287
299
|
/**
|
|
@@ -1082,6 +1094,115 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
1082
1094
|
}
|
|
1083
1095
|
};
|
|
1084
1096
|
|
|
1097
|
+
// src/utils/ethereumDefinitions.ts
|
|
1098
|
+
var DEFAULT_ETHEREUM_DEFINITIONS_BASE_URL = "https://data.trezor.io/firmware/eth-definitions";
|
|
1099
|
+
function getSlip44FromPath(path) {
|
|
1100
|
+
const segments = path.trim().replace(/^m\//i, "").split("/");
|
|
1101
|
+
const coinType = segments[1];
|
|
1102
|
+
const parsed = coinType === void 0 ? NaN : Number(coinType.replace(/['hH]$/, ""));
|
|
1103
|
+
if (!Number.isFinite(parsed)) {
|
|
1104
|
+
throw new Error(`Cannot derive SLIP-44 coin type from path: ${path}`);
|
|
1105
|
+
}
|
|
1106
|
+
return parsed >= 2147483648 ? parsed - 2147483648 : parsed;
|
|
1107
|
+
}
|
|
1108
|
+
async function fetchEthereumDefinitions({
|
|
1109
|
+
chainId,
|
|
1110
|
+
slip44,
|
|
1111
|
+
contractAddress,
|
|
1112
|
+
baseUrl = DEFAULT_ETHEREUM_DEFINITIONS_BASE_URL,
|
|
1113
|
+
fetchImpl = globalThis.fetch
|
|
1114
|
+
}) {
|
|
1115
|
+
if (!chainId && !slip44) {
|
|
1116
|
+
throw new Error("fetchEthereumDefinitions requires chainId or slip44");
|
|
1117
|
+
}
|
|
1118
|
+
if (!fetchImpl) {
|
|
1119
|
+
return {};
|
|
1120
|
+
}
|
|
1121
|
+
const mode = chainId ? "chain-id" : "slip44";
|
|
1122
|
+
const id = _nullishCoalesce(chainId, () => ( slip44));
|
|
1123
|
+
const definitions = {};
|
|
1124
|
+
const network = await fetchDefinition(`${baseUrl}/${mode}/${id}/network.dat`, fetchImpl);
|
|
1125
|
+
if (network) {
|
|
1126
|
+
definitions.encodedNetwork = network;
|
|
1127
|
+
}
|
|
1128
|
+
if (contractAddress) {
|
|
1129
|
+
const token = await fetchDefinition(
|
|
1130
|
+
`${baseUrl}/${mode}/${id}/token-${stripHexPrefix(contractAddress).toLowerCase()}.dat`,
|
|
1131
|
+
fetchImpl
|
|
1132
|
+
);
|
|
1133
|
+
if (token) {
|
|
1134
|
+
definitions.encodedToken = token;
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
return definitions;
|
|
1138
|
+
}
|
|
1139
|
+
async function buildEthereumDefinitionsForPath({
|
|
1140
|
+
path,
|
|
1141
|
+
baseUrl,
|
|
1142
|
+
fetchImpl
|
|
1143
|
+
}) {
|
|
1144
|
+
return fetchEthereumDefinitions({
|
|
1145
|
+
slip44: getSlip44FromPath(path),
|
|
1146
|
+
baseUrl,
|
|
1147
|
+
fetchImpl
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
async function buildEthereumDefinitionsForSignTx({
|
|
1151
|
+
path,
|
|
1152
|
+
chainId,
|
|
1153
|
+
to,
|
|
1154
|
+
data,
|
|
1155
|
+
baseUrl,
|
|
1156
|
+
fetchImpl
|
|
1157
|
+
}) {
|
|
1158
|
+
const dataHex = stripHexPrefix(_nullishCoalesce(data, () => ( "")));
|
|
1159
|
+
if (chainId === 1 && !dataHex) {
|
|
1160
|
+
return void 0;
|
|
1161
|
+
}
|
|
1162
|
+
return fetchEthereumDefinitions({
|
|
1163
|
+
chainId,
|
|
1164
|
+
slip44: getSlip44FromPath(path),
|
|
1165
|
+
contractAddress: dataHex && to ? to : void 0,
|
|
1166
|
+
baseUrl,
|
|
1167
|
+
fetchImpl
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
async function fetchDefinition(url, fetchImpl) {
|
|
1171
|
+
try {
|
|
1172
|
+
const response = await fetchImpl(url);
|
|
1173
|
+
if (response.status !== 200) {
|
|
1174
|
+
return void 0;
|
|
1175
|
+
}
|
|
1176
|
+
return await response.arrayBuffer();
|
|
1177
|
+
} catch (e3) {
|
|
1178
|
+
return void 0;
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
function stripHexPrefix(value) {
|
|
1182
|
+
return value.startsWith("0x") || value.startsWith("0X") ? value.slice(2) : value;
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
// src/utils/solanaTokenDefinition.ts
|
|
1186
|
+
var DEFAULT_SOLANA_TOKEN_DEFINITION_BASE_URL = "https://data.trezor.io/firmware/definitions/solana/token";
|
|
1187
|
+
async function fetchSolanaTokenDefinition({
|
|
1188
|
+
tokenMint,
|
|
1189
|
+
baseUrl = DEFAULT_SOLANA_TOKEN_DEFINITION_BASE_URL,
|
|
1190
|
+
fetchImpl = globalThis.fetch
|
|
1191
|
+
}) {
|
|
1192
|
+
if (!fetchImpl) {
|
|
1193
|
+
return void 0;
|
|
1194
|
+
}
|
|
1195
|
+
try {
|
|
1196
|
+
const response = await fetchImpl(`${baseUrl}/${tokenMint}.dat`);
|
|
1197
|
+
if (response.status !== 200) {
|
|
1198
|
+
return void 0;
|
|
1199
|
+
}
|
|
1200
|
+
return await response.arrayBuffer();
|
|
1201
|
+
} catch (e4) {
|
|
1202
|
+
return void 0;
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1085
1206
|
// src/constants.ts
|
|
1086
1207
|
var TREZOR_SAFE_7_MODEL = "T3W1";
|
|
1087
1208
|
var TREZOR_BLE_SUPPORTED_MODELS = [TREZOR_SAFE_7_MODEL];
|
|
@@ -1141,5 +1262,12 @@ function resolveTrezorBleConnectId(descriptor) {
|
|
|
1141
1262
|
|
|
1142
1263
|
|
|
1143
1264
|
|
|
1144
|
-
|
|
1265
|
+
|
|
1266
|
+
|
|
1267
|
+
|
|
1268
|
+
|
|
1269
|
+
|
|
1270
|
+
|
|
1271
|
+
|
|
1272
|
+
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;
|
|
1145
1273
|
//# sourceMappingURL=index.js.map
|