@onekeyfe/hwk-trezor-adapter 1.1.31 → 1.1.32-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
@@ -87,14 +87,13 @@ declare class TrezorAdapter implements IHardwareWallet {
87
87
  */
88
88
  uiResponse(response: UiResponseEvent): void;
89
89
  /**
90
- * Returns a stable per-seed identifier suitable for device-match verification.
91
- *
92
- * Trezor exposes `device_id` in Features — a server-generated UUID written
93
- * during `wipe_device` and stable for the life of the seed. Unlike Ledger
94
- * (no native id, so a per-chain address is hashed), Trezor's id is global
95
- * across chains, so the `chain` argument is accepted for API parity but
96
- * ignored. For unsupported chains we still surface the id (since it would
97
- * be the same value anyway).
90
+ * Returns the Trezor `device_id` from Features — a random 12-byte value the
91
+ * device stores and regenerates on `wipe_device`. It identifies the PHYSICAL
92
+ * DEVICE, not a seed/wallet: it is shared across passphrase wallets and
93
+ * changes after wipe/restore, so it suits device-match checks but must NOT be
94
+ * used as a wallet fingerprint (use `passphraseState` for wallet identity).
95
+ * Unlike Ledger (which hashes a per-chain address), it is chain-global, so
96
+ * `chain` is accepted for API parity but ignored.
98
97
  */
99
98
  getChainFingerprint(connectId: string, _deviceId: string, _chain: ChainForFingerprint): Promise<Response<string>>;
100
99
  /**
package/dist/index.d.ts CHANGED
@@ -87,14 +87,13 @@ declare class TrezorAdapter implements IHardwareWallet {
87
87
  */
88
88
  uiResponse(response: UiResponseEvent): void;
89
89
  /**
90
- * Returns a stable per-seed identifier suitable for device-match verification.
91
- *
92
- * Trezor exposes `device_id` in Features — a server-generated UUID written
93
- * during `wipe_device` and stable for the life of the seed. Unlike Ledger
94
- * (no native id, so a per-chain address is hashed), Trezor's id is global
95
- * across chains, so the `chain` argument is accepted for API parity but
96
- * ignored. For unsupported chains we still surface the id (since it would
97
- * be the same value anyway).
90
+ * Returns the Trezor `device_id` from Features — a random 12-byte value the
91
+ * device stores and regenerates on `wipe_device`. It identifies the PHYSICAL
92
+ * DEVICE, not a seed/wallet: it is shared across passphrase wallets and
93
+ * changes after wipe/restore, so it suits device-match checks but must NOT be
94
+ * used as a wallet fingerprint (use `passphraseState` for wallet identity).
95
+ * Unlike Ledger (which hashes a per-chain address), it is chain-global, so
96
+ * `chain` is accepted for API parity but ignored.
98
97
  */
99
98
  getChainFingerprint(connectId: string, _deviceId: string, _chain: ChainForFingerprint): Promise<Response<string>>;
100
99
  /**
package/dist/index.js CHANGED
@@ -122,8 +122,8 @@ var TrezorAdapter = class _TrezorAdapter {
122
122
  ...data,
123
123
  payload: {
124
124
  ...payload,
125
- ..._optionalChain([context, 'optionalAccess', _ => _.passphraseState]) !== void 0 ? { passphraseState: context.passphraseState } : {},
126
- ..._optionalChain([context, 'optionalAccess', _2 => _2.useEmptyPassphrase]) !== void 0 ? { useEmptyPassphrase: context.useEmptyPassphrase } : {}
125
+ ..._optionalChain([context, 'optionalAccess', _2 => _2.passphraseState]) !== void 0 ? { passphraseState: context.passphraseState } : {},
126
+ ..._optionalChain([context, 'optionalAccess', _3 => _3.useEmptyPassphrase]) !== void 0 ? { useEmptyPassphrase: context.useEmptyPassphrase } : {}
127
127
  }
128
128
  }
129
129
  );
@@ -177,9 +177,9 @@ var TrezorAdapter = class _TrezorAdapter {
177
177
  return { rest: _nullishCoalesce(params, () => ( {})) };
178
178
  }
179
179
  static _withAllNetworkRequestCommonParams(item, commonParams) {
180
- const autoInstallApp = _optionalChain([commonParams, 'optionalAccess', _3 => _3.autoInstallApp]);
181
- const passphraseState = _optionalChain([commonParams, 'optionalAccess', _4 => _4.passphraseState]);
182
- const useEmptyPassphrase = _optionalChain([commonParams, 'optionalAccess', _5 => _5.useEmptyPassphrase]);
180
+ const autoInstallApp = _optionalChain([commonParams, 'optionalAccess', _4 => _4.autoInstallApp]);
181
+ const passphraseState = _optionalChain([commonParams, 'optionalAccess', _5 => _5.passphraseState]);
182
+ const useEmptyPassphrase = _optionalChain([commonParams, 'optionalAccess', _6 => _6.useEmptyPassphrase]);
183
183
  if (autoInstallApp === void 0 && passphraseState === void 0 && useEmptyPassphrase === void 0) {
184
184
  return item;
185
185
  }
@@ -198,11 +198,18 @@ var TrezorAdapter = class _TrezorAdapter {
198
198
  const sensitiveKeys = /* @__PURE__ */ new Set([
199
199
  "credential",
200
200
  "credentials",
201
+ "entropy",
201
202
  "host_static_key",
203
+ "mnemonic",
204
+ "mnemonics",
202
205
  "passphrase",
203
206
  "passphraseState",
204
207
  "pin",
205
- "trezor_static_public_key"
208
+ "privateKey",
209
+ "seed",
210
+ "trezor_static_public_key",
211
+ "word",
212
+ "words"
206
213
  ]);
207
214
  return Object.fromEntries(
208
215
  Object.entries(value).map(([key, item]) => [
@@ -239,8 +246,8 @@ var TrezorAdapter = class _TrezorAdapter {
239
246
  };
240
247
  }
241
248
  static _trezorFailureMessage(error) {
242
- const response = _optionalChain([error, 'optionalAccess', _6 => _6.response]);
243
- const message = _optionalChain([response, 'optionalAccess', _7 => _7.message]);
249
+ const response = _optionalChain([error, 'optionalAccess', _7 => _7.response]);
250
+ const message = _optionalChain([response, 'optionalAccess', _8 => _8.message]);
244
251
  if (!message || typeof message !== "object") return {};
245
252
  const failureMessage = message;
246
253
  return {
@@ -249,7 +256,7 @@ var TrezorAdapter = class _TrezorAdapter {
249
256
  };
250
257
  }
251
258
  static _mapTrezorFailureCode(error) {
252
- const directCode = _optionalChain([error, 'optionalAccess', _8 => _8.code]);
259
+ const directCode = _optionalChain([error, 'optionalAccess', _9 => _9.code]);
253
260
  if (directCode === "Device_InitializeFailed") {
254
261
  return _hwkadaptercore.HardwareErrorCode.PinCancelled;
255
262
  }
@@ -262,7 +269,7 @@ var TrezorAdapter = class _TrezorAdapter {
262
269
  if (directCode === "Failure_UnexpectedMessage") {
263
270
  return _hwkadaptercore.HardwareErrorCode.MethodNotSupported;
264
271
  }
265
- const message = _optionalChain([error, 'optionalAccess', _9 => _9.message]);
272
+ const message = _optionalChain([error, 'optionalAccess', _10 => _10.message]);
266
273
  if (typeof message === "string" && message.includes("Failed to execute 'transfer") && message.includes("on 'USBDevice'")) {
267
274
  return _hwkadaptercore.HardwareErrorCode.TransportError;
268
275
  }
@@ -410,7 +417,7 @@ var TrezorAdapter = class _TrezorAdapter {
410
417
  async searchDevices(options) {
411
418
  await this._ensureDevicePermission();
412
419
  const scanned = await this._connector.searchDevices(
413
- _optionalChain([options, 'optionalAccess', _10 => _10.waitForAllTransports]) ? { waitForAll: true } : void 0
420
+ _optionalChain([options, 'optionalAccess', _11 => _11.waitForAllTransports]) ? { waitForAll: true } : void 0
414
421
  );
415
422
  const scannedIds = new Set(scanned.map((d) => d.connectId));
416
423
  for (const connectId of [...this._devices.keys()]) {
@@ -457,7 +464,7 @@ var TrezorAdapter = class _TrezorAdapter {
457
464
  let liveDeviceId = "";
458
465
  const topLevelFailureIndexes = /* @__PURE__ */ new Set();
459
466
  const isSingleNetworkBundle = params.bundle.every(
460
- (item) => item.network === _optionalChain([params, 'access', _11 => _11.bundle, 'access', _12 => _12[0], 'optionalAccess', _13 => _13.network])
467
+ (item) => item.network === _optionalChain([params, 'access', _12 => _12.bundle, 'access', _13 => _13[0], 'optionalAccess', _14 => _14.network])
461
468
  );
462
469
  const getLiveDeviceId = async () => {
463
470
  if (liveDeviceId) return _hwkadaptercore.success.call(void 0, liveDeviceId);
@@ -517,7 +524,7 @@ var TrezorAdapter = class _TrezorAdapter {
517
524
  // One named boolean per abort reason.
518
525
  shouldAbortBundle: (response, { index }) => {
519
526
  const isSessionLevelFailure = topLevelFailureIndexes.has(index);
520
- const isWholeChainForbidden = isSingleNetworkBundle && _optionalChain([response, 'access', _14 => _14.payload, 'optionalAccess', _15 => _15.code]) === _hwkadaptercore.HardwareErrorCode.DevicePathForbidden;
527
+ const isWholeChainForbidden = isSingleNetworkBundle && _optionalChain([response, 'access', _15 => _15.payload, 'optionalAccess', _16 => _16.code]) === _hwkadaptercore.HardwareErrorCode.DevicePathForbidden;
521
528
  return isSessionLevelFailure || isWholeChainForbidden;
522
529
  }
523
530
  });
@@ -583,14 +590,13 @@ var TrezorAdapter = class _TrezorAdapter {
583
590
  this._connector.uiResponse(response);
584
591
  }
585
592
  /**
586
- * Returns a stable per-seed identifier suitable for device-match verification.
587
- *
588
- * Trezor exposes `device_id` in Features — a server-generated UUID written
589
- * during `wipe_device` and stable for the life of the seed. Unlike Ledger
590
- * (no native id, so a per-chain address is hashed), Trezor's id is global
591
- * across chains, so the `chain` argument is accepted for API parity but
592
- * ignored. For unsupported chains we still surface the id (since it would
593
- * be the same value anyway).
593
+ * Returns the Trezor `device_id` from Features — a random 12-byte value the
594
+ * device stores and regenerates on `wipe_device`. It identifies the PHYSICAL
595
+ * DEVICE, not a seed/wallet: it is shared across passphrase wallets and
596
+ * changes after wipe/restore, so it suits device-match checks but must NOT be
597
+ * used as a wallet fingerprint (use `passphraseState` for wallet identity).
598
+ * Unlike Ledger (which hashes a per-chain address), it is chain-global, so
599
+ * `chain` is accepted for API parity but ignored.
594
600
  */
595
601
  async getChainFingerprint(connectId, _deviceId, _chain) {
596
602
  return this._getTrezorDeviceId(connectId);
@@ -855,7 +861,7 @@ var TrezorAdapter = class _TrezorAdapter {
855
861
  if (pending) return pending;
856
862
  const promise = (async () => {
857
863
  try {
858
- if (_optionalChain([signal, 'optionalAccess', _16 => _16.aborted])) {
864
+ if (_optionalChain([signal, 'optionalAccess', _17 => _17.aborted])) {
859
865
  throw Object.assign(new Error("Trezor connection aborted"), {
860
866
  code: _hwkadaptercore.HardwareErrorCode.UserAborted
861
867
  });
@@ -901,8 +907,8 @@ var TrezorAdapter = class _TrezorAdapter {
901
907
  passphraseMode: "prompt"
902
908
  })
903
909
  );
904
- if (_optionalChain([created, 'optionalAccess', _17 => _17.protocol]) === "thp" && !created.thpSessionId) return;
905
- if (_optionalChain([created, 'optionalAccess', _18 => _18.protocol]) !== "thp" && _optionalChain([created, 'optionalAccess', _19 => _19.protocol]) !== "v1") return;
910
+ if (_optionalChain([created, 'optionalAccess', _18 => _18.protocol]) === "thp" && !created.thpSessionId) return;
911
+ if (_optionalChain([created, 'optionalAccess', _19 => _19.protocol]) !== "thp" && _optionalChain([created, 'optionalAccess', _20 => _20.protocol]) !== "v1") return;
906
912
  const state = await this._deriveState(sessionId, signal);
907
913
  if (state !== passphraseState) {
908
914
  throw Object.assign(
@@ -916,13 +922,13 @@ var TrezorAdapter = class _TrezorAdapter {
916
922
  }
917
923
  _rememberVerifiedPassphraseSession(connectId, passphraseState, sessionId, created) {
918
924
  let session;
919
- if (_optionalChain([created, 'optionalAccess', _20 => _20.protocol]) === "thp" && typeof created.thpSessionId === "string") {
925
+ if (_optionalChain([created, 'optionalAccess', _21 => _21.protocol]) === "thp" && typeof created.thpSessionId === "string") {
920
926
  session = {
921
927
  sessionId,
922
928
  protocol: "thp",
923
929
  thpSessionId: created.thpSessionId
924
930
  };
925
- } else if (_optionalChain([created, 'optionalAccess', _21 => _21.protocol]) === "v1") {
931
+ } else if (_optionalChain([created, 'optionalAccess', _22 => _22.protocol]) === "v1") {
926
932
  session = {
927
933
  sessionId,
928
934
  protocol: "v1"
@@ -942,7 +948,7 @@ var TrezorAdapter = class _TrezorAdapter {
942
948
  }
943
949
  }
944
950
  async _reuseVerifiedPassphraseSession(connectId, sessionId, passphraseState, signal) {
945
- const cached = _optionalChain([this, 'access', _22 => _22._verifiedPassphraseSessionsByConnectId, 'access', _23 => _23.get, 'call', _24 => _24(connectId), 'optionalAccess', _25 => _25.get, 'call', _26 => _26(passphraseState)]);
951
+ const cached = _optionalChain([this, 'access', _23 => _23._verifiedPassphraseSessionsByConnectId, 'access', _24 => _24.get, 'call', _25 => _25(connectId), 'optionalAccess', _26 => _26.get, 'call', _27 => _27(passphraseState)]);
946
952
  if (!cached || cached.sessionId !== sessionId) {
947
953
  this._forgetVerifiedPassphraseSession(connectId, passphraseState);
948
954
  return false;
@@ -994,7 +1000,7 @@ var TrezorAdapter = class _TrezorAdapter {
994
1000
  showOnDevice: false
995
1001
  })
996
1002
  );
997
- const state = _optionalChain([derived, 'optionalAccess', _27 => _27.publicKey]);
1003
+ const state = _optionalChain([derived, 'optionalAccess', _28 => _28.publicKey]);
998
1004
  if (!state) {
999
1005
  throw Object.assign(new Error("Failed to derive passphrase state (wallet public key)"), {
1000
1006
  code: _hwkadaptercore.HardwareErrorCode.UnknownError
@@ -1020,7 +1026,7 @@ var TrezorAdapter = class _TrezorAdapter {
1020
1026
  signal,
1021
1027
  _TrezorAdapter._callConnector(this._connector, sessionId, "getFeatures", { refresh: true })
1022
1028
  );
1023
- if (_optionalChain([features, 'optionalAccess', _28 => _28.passphrase_protection]) !== true) {
1029
+ if (_optionalChain([features, 'optionalAccess', _29 => _29.passphrase_protection]) !== true) {
1024
1030
  return _hwkadaptercore.success.call(void 0, null);
1025
1031
  }
1026
1032
  this._rememberVerifiedPassphraseSession(connectId, state, sessionId, created);
@@ -1107,6 +1113,21 @@ var TrezorAdapter = class _TrezorAdapter {
1107
1113
 
1108
1114
  // src/utils/ethereumDefinitions.ts
1109
1115
  var DEFAULT_ETHEREUM_DEFINITIONS_BASE_URL = "https://data.trezor.io/firmware/eth-definitions";
1116
+ var DEFINITIONS_FETCH_TIMEOUT_MS = 2e4;
1117
+ async function runWithTimeout(run, timeoutMs = DEFINITIONS_FETCH_TIMEOUT_MS) {
1118
+ let timer;
1119
+ const deadline = new Promise((_, reject) => {
1120
+ timer = setTimeout(
1121
+ () => reject(new Error(`definitions fetch timed out after ${timeoutMs}ms`)),
1122
+ timeoutMs
1123
+ );
1124
+ });
1125
+ try {
1126
+ return await Promise.race([run(), deadline]);
1127
+ } finally {
1128
+ if (timer) clearTimeout(timer);
1129
+ }
1130
+ }
1110
1131
  function getSlip44FromPath(path) {
1111
1132
  const segments = path.trim().replace(/^m\//i, "").split("/");
1112
1133
  const coinType = segments[1];
@@ -1180,11 +1201,13 @@ async function buildEthereumDefinitionsForSignTx({
1180
1201
  }
1181
1202
  async function fetchDefinitionHex(url, fetchImpl) {
1182
1203
  try {
1183
- const response = await fetchImpl(url);
1184
- if (response.status !== 200) {
1185
- return void 0;
1186
- }
1187
- return arrayBufferToHex(await response.arrayBuffer());
1204
+ return await runWithTimeout(async () => {
1205
+ const response = await fetchImpl(url);
1206
+ if (response.status !== 200) {
1207
+ return void 0;
1208
+ }
1209
+ return arrayBufferToHex(await response.arrayBuffer());
1210
+ });
1188
1211
  } catch (e3) {
1189
1212
  return void 0;
1190
1213
  }
@@ -1207,11 +1230,13 @@ async function fetchSolanaTokenDefinition({
1207
1230
  return void 0;
1208
1231
  }
1209
1232
  try {
1210
- const response = await fetchImpl(`${baseUrl}/${tokenMint}.dat`);
1211
- if (response.status !== 200) {
1212
- return void 0;
1213
- }
1214
- return Buffer.from(await response.arrayBuffer()).toString("hex");
1233
+ return await runWithTimeout(async () => {
1234
+ const response = await fetchImpl(`${baseUrl}/${tokenMint}.dat`);
1235
+ if (response.status !== 200) {
1236
+ return void 0;
1237
+ }
1238
+ return Buffer.from(await response.arrayBuffer()).toString("hex");
1239
+ });
1215
1240
  } catch (e4) {
1216
1241
  return void 0;
1217
1242
  }