@onekeyfe/hwk-trezor-adapter 1.1.32-alpha.1 → 1.1.32
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 +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +39 -64
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -87,13 +87,14 @@ declare class TrezorAdapter implements IHardwareWallet {
|
|
|
87
87
|
*/
|
|
88
88
|
uiResponse(response: UiResponseEvent): void;
|
|
89
89
|
/**
|
|
90
|
-
* Returns
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
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).
|
|
97
98
|
*/
|
|
98
99
|
getChainFingerprint(connectId: string, _deviceId: string, _chain: ChainForFingerprint): Promise<Response<string>>;
|
|
99
100
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -87,13 +87,14 @@ declare class TrezorAdapter implements IHardwareWallet {
|
|
|
87
87
|
*/
|
|
88
88
|
uiResponse(response: UiResponseEvent): void;
|
|
89
89
|
/**
|
|
90
|
-
* Returns
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
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).
|
|
97
98
|
*/
|
|
98
99
|
getChainFingerprint(connectId: string, _deviceId: string, _chain: ChainForFingerprint): Promise<Response<string>>;
|
|
99
100
|
/**
|
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',
|
|
126
|
-
..._optionalChain([context, 'optionalAccess',
|
|
125
|
+
..._optionalChain([context, 'optionalAccess', _ => _.passphraseState]) !== void 0 ? { passphraseState: context.passphraseState } : {},
|
|
126
|
+
..._optionalChain([context, 'optionalAccess', _2 => _2.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',
|
|
181
|
-
const passphraseState = _optionalChain([commonParams, 'optionalAccess',
|
|
182
|
-
const useEmptyPassphrase = _optionalChain([commonParams, 'optionalAccess',
|
|
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]);
|
|
183
183
|
if (autoInstallApp === void 0 && passphraseState === void 0 && useEmptyPassphrase === void 0) {
|
|
184
184
|
return item;
|
|
185
185
|
}
|
|
@@ -198,18 +198,11 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
198
198
|
const sensitiveKeys = /* @__PURE__ */ new Set([
|
|
199
199
|
"credential",
|
|
200
200
|
"credentials",
|
|
201
|
-
"entropy",
|
|
202
201
|
"host_static_key",
|
|
203
|
-
"mnemonic",
|
|
204
|
-
"mnemonics",
|
|
205
202
|
"passphrase",
|
|
206
203
|
"passphraseState",
|
|
207
204
|
"pin",
|
|
208
|
-
"
|
|
209
|
-
"seed",
|
|
210
|
-
"trezor_static_public_key",
|
|
211
|
-
"word",
|
|
212
|
-
"words"
|
|
205
|
+
"trezor_static_public_key"
|
|
213
206
|
]);
|
|
214
207
|
return Object.fromEntries(
|
|
215
208
|
Object.entries(value).map(([key, item]) => [
|
|
@@ -246,8 +239,8 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
246
239
|
};
|
|
247
240
|
}
|
|
248
241
|
static _trezorFailureMessage(error) {
|
|
249
|
-
const response = _optionalChain([error, 'optionalAccess',
|
|
250
|
-
const message = _optionalChain([response, 'optionalAccess',
|
|
242
|
+
const response = _optionalChain([error, 'optionalAccess', _6 => _6.response]);
|
|
243
|
+
const message = _optionalChain([response, 'optionalAccess', _7 => _7.message]);
|
|
251
244
|
if (!message || typeof message !== "object") return {};
|
|
252
245
|
const failureMessage = message;
|
|
253
246
|
return {
|
|
@@ -256,7 +249,7 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
256
249
|
};
|
|
257
250
|
}
|
|
258
251
|
static _mapTrezorFailureCode(error) {
|
|
259
|
-
const directCode = _optionalChain([error, 'optionalAccess',
|
|
252
|
+
const directCode = _optionalChain([error, 'optionalAccess', _8 => _8.code]);
|
|
260
253
|
if (directCode === "Device_InitializeFailed") {
|
|
261
254
|
return _hwkadaptercore.HardwareErrorCode.PinCancelled;
|
|
262
255
|
}
|
|
@@ -269,7 +262,7 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
269
262
|
if (directCode === "Failure_UnexpectedMessage") {
|
|
270
263
|
return _hwkadaptercore.HardwareErrorCode.MethodNotSupported;
|
|
271
264
|
}
|
|
272
|
-
const message = _optionalChain([error, 'optionalAccess',
|
|
265
|
+
const message = _optionalChain([error, 'optionalAccess', _9 => _9.message]);
|
|
273
266
|
if (typeof message === "string" && message.includes("Failed to execute 'transfer") && message.includes("on 'USBDevice'")) {
|
|
274
267
|
return _hwkadaptercore.HardwareErrorCode.TransportError;
|
|
275
268
|
}
|
|
@@ -417,7 +410,7 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
417
410
|
async searchDevices(options) {
|
|
418
411
|
await this._ensureDevicePermission();
|
|
419
412
|
const scanned = await this._connector.searchDevices(
|
|
420
|
-
_optionalChain([options, 'optionalAccess',
|
|
413
|
+
_optionalChain([options, 'optionalAccess', _10 => _10.waitForAllTransports]) ? { waitForAll: true } : void 0
|
|
421
414
|
);
|
|
422
415
|
const scannedIds = new Set(scanned.map((d) => d.connectId));
|
|
423
416
|
for (const connectId of [...this._devices.keys()]) {
|
|
@@ -464,7 +457,7 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
464
457
|
let liveDeviceId = "";
|
|
465
458
|
const topLevelFailureIndexes = /* @__PURE__ */ new Set();
|
|
466
459
|
const isSingleNetworkBundle = params.bundle.every(
|
|
467
|
-
(item) => item.network === _optionalChain([params, 'access',
|
|
460
|
+
(item) => item.network === _optionalChain([params, 'access', _11 => _11.bundle, 'access', _12 => _12[0], 'optionalAccess', _13 => _13.network])
|
|
468
461
|
);
|
|
469
462
|
const getLiveDeviceId = async () => {
|
|
470
463
|
if (liveDeviceId) return _hwkadaptercore.success.call(void 0, liveDeviceId);
|
|
@@ -524,7 +517,7 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
524
517
|
// One named boolean per abort reason.
|
|
525
518
|
shouldAbortBundle: (response, { index }) => {
|
|
526
519
|
const isSessionLevelFailure = topLevelFailureIndexes.has(index);
|
|
527
|
-
const isWholeChainForbidden = isSingleNetworkBundle && _optionalChain([response, 'access',
|
|
520
|
+
const isWholeChainForbidden = isSingleNetworkBundle && _optionalChain([response, 'access', _14 => _14.payload, 'optionalAccess', _15 => _15.code]) === _hwkadaptercore.HardwareErrorCode.DevicePathForbidden;
|
|
528
521
|
return isSessionLevelFailure || isWholeChainForbidden;
|
|
529
522
|
}
|
|
530
523
|
});
|
|
@@ -590,13 +583,14 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
590
583
|
this._connector.uiResponse(response);
|
|
591
584
|
}
|
|
592
585
|
/**
|
|
593
|
-
* Returns
|
|
594
|
-
*
|
|
595
|
-
*
|
|
596
|
-
*
|
|
597
|
-
*
|
|
598
|
-
*
|
|
599
|
-
*
|
|
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).
|
|
600
594
|
*/
|
|
601
595
|
async getChainFingerprint(connectId, _deviceId, _chain) {
|
|
602
596
|
return this._getTrezorDeviceId(connectId);
|
|
@@ -861,7 +855,7 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
861
855
|
if (pending) return pending;
|
|
862
856
|
const promise = (async () => {
|
|
863
857
|
try {
|
|
864
|
-
if (_optionalChain([signal, 'optionalAccess',
|
|
858
|
+
if (_optionalChain([signal, 'optionalAccess', _16 => _16.aborted])) {
|
|
865
859
|
throw Object.assign(new Error("Trezor connection aborted"), {
|
|
866
860
|
code: _hwkadaptercore.HardwareErrorCode.UserAborted
|
|
867
861
|
});
|
|
@@ -907,8 +901,8 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
907
901
|
passphraseMode: "prompt"
|
|
908
902
|
})
|
|
909
903
|
);
|
|
910
|
-
if (_optionalChain([created, 'optionalAccess',
|
|
911
|
-
if (_optionalChain([created, 'optionalAccess',
|
|
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;
|
|
912
906
|
const state = await this._deriveState(sessionId, signal);
|
|
913
907
|
if (state !== passphraseState) {
|
|
914
908
|
throw Object.assign(
|
|
@@ -922,13 +916,13 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
922
916
|
}
|
|
923
917
|
_rememberVerifiedPassphraseSession(connectId, passphraseState, sessionId, created) {
|
|
924
918
|
let session;
|
|
925
|
-
if (_optionalChain([created, 'optionalAccess',
|
|
919
|
+
if (_optionalChain([created, 'optionalAccess', _20 => _20.protocol]) === "thp" && typeof created.thpSessionId === "string") {
|
|
926
920
|
session = {
|
|
927
921
|
sessionId,
|
|
928
922
|
protocol: "thp",
|
|
929
923
|
thpSessionId: created.thpSessionId
|
|
930
924
|
};
|
|
931
|
-
} else if (_optionalChain([created, 'optionalAccess',
|
|
925
|
+
} else if (_optionalChain([created, 'optionalAccess', _21 => _21.protocol]) === "v1") {
|
|
932
926
|
session = {
|
|
933
927
|
sessionId,
|
|
934
928
|
protocol: "v1"
|
|
@@ -948,7 +942,7 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
948
942
|
}
|
|
949
943
|
}
|
|
950
944
|
async _reuseVerifiedPassphraseSession(connectId, sessionId, passphraseState, signal) {
|
|
951
|
-
const cached = _optionalChain([this, 'access',
|
|
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)]);
|
|
952
946
|
if (!cached || cached.sessionId !== sessionId) {
|
|
953
947
|
this._forgetVerifiedPassphraseSession(connectId, passphraseState);
|
|
954
948
|
return false;
|
|
@@ -1000,7 +994,7 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
1000
994
|
showOnDevice: false
|
|
1001
995
|
})
|
|
1002
996
|
);
|
|
1003
|
-
const state = _optionalChain([derived, 'optionalAccess',
|
|
997
|
+
const state = _optionalChain([derived, 'optionalAccess', _27 => _27.publicKey]);
|
|
1004
998
|
if (!state) {
|
|
1005
999
|
throw Object.assign(new Error("Failed to derive passphrase state (wallet public key)"), {
|
|
1006
1000
|
code: _hwkadaptercore.HardwareErrorCode.UnknownError
|
|
@@ -1026,7 +1020,7 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
1026
1020
|
signal,
|
|
1027
1021
|
_TrezorAdapter._callConnector(this._connector, sessionId, "getFeatures", { refresh: true })
|
|
1028
1022
|
);
|
|
1029
|
-
if (_optionalChain([features, 'optionalAccess',
|
|
1023
|
+
if (_optionalChain([features, 'optionalAccess', _28 => _28.passphrase_protection]) !== true) {
|
|
1030
1024
|
return _hwkadaptercore.success.call(void 0, null);
|
|
1031
1025
|
}
|
|
1032
1026
|
this._rememberVerifiedPassphraseSession(connectId, state, sessionId, created);
|
|
@@ -1113,21 +1107,6 @@ var TrezorAdapter = class _TrezorAdapter {
|
|
|
1113
1107
|
|
|
1114
1108
|
// src/utils/ethereumDefinitions.ts
|
|
1115
1109
|
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
|
-
}
|
|
1131
1110
|
function getSlip44FromPath(path) {
|
|
1132
1111
|
const segments = path.trim().replace(/^m\//i, "").split("/");
|
|
1133
1112
|
const coinType = segments[1];
|
|
@@ -1201,13 +1180,11 @@ async function buildEthereumDefinitionsForSignTx({
|
|
|
1201
1180
|
}
|
|
1202
1181
|
async function fetchDefinitionHex(url, fetchImpl) {
|
|
1203
1182
|
try {
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
return arrayBufferToHex(await response.arrayBuffer());
|
|
1210
|
-
});
|
|
1183
|
+
const response = await fetchImpl(url);
|
|
1184
|
+
if (response.status !== 200) {
|
|
1185
|
+
return void 0;
|
|
1186
|
+
}
|
|
1187
|
+
return arrayBufferToHex(await response.arrayBuffer());
|
|
1211
1188
|
} catch (e3) {
|
|
1212
1189
|
return void 0;
|
|
1213
1190
|
}
|
|
@@ -1230,13 +1207,11 @@ async function fetchSolanaTokenDefinition({
|
|
|
1230
1207
|
return void 0;
|
|
1231
1208
|
}
|
|
1232
1209
|
try {
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
return Buffer.from(await response.arrayBuffer()).toString("hex");
|
|
1239
|
-
});
|
|
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");
|
|
1240
1215
|
} catch (e4) {
|
|
1241
1216
|
return void 0;
|
|
1242
1217
|
}
|