@onekeyfe/hwk-trezor-connector 1.2.8-alpha.9 → 1.2.10-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 +0 -6
- package/dist/index.d.ts +0 -6
- package/dist/index.js +146 -76
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +108 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -44,12 +44,6 @@ declare abstract class TrezorConnectorBase implements IConnector {
|
|
|
44
44
|
* the change too — we mutate, not replace.
|
|
45
45
|
*/
|
|
46
46
|
setKnownCredentials(credentials: TrezorThpCredentials[]): void;
|
|
47
|
-
/**
|
|
48
|
-
* Push new credentials minted during pairing into the in-memory array.
|
|
49
|
-
* Deduplicates by the device-minted `credential` blob — the host has no
|
|
50
|
-
* other stable identity for a credential.
|
|
51
|
-
*/
|
|
52
|
-
private mergeKnownCredentials;
|
|
53
47
|
protected abstract enumerateDevices(): Promise<ConnectorDevice[]>;
|
|
54
48
|
protected abstract createByteTransport(device: ConnectorDevice): Promise<TrezorConnectorByteTransport>;
|
|
55
49
|
protected resolveUnlistedDevice(_deviceId: string): ConnectorDevice | undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -44,12 +44,6 @@ declare abstract class TrezorConnectorBase implements IConnector {
|
|
|
44
44
|
* the change too — we mutate, not replace.
|
|
45
45
|
*/
|
|
46
46
|
setKnownCredentials(credentials: TrezorThpCredentials[]): void;
|
|
47
|
-
/**
|
|
48
|
-
* Push new credentials minted during pairing into the in-memory array.
|
|
49
|
-
* Deduplicates by the device-minted `credential` blob — the host has no
|
|
50
|
-
* other stable identity for a credential.
|
|
51
|
-
*/
|
|
52
|
-
private mergeKnownCredentials;
|
|
53
47
|
protected abstract enumerateDevices(): Promise<ConnectorDevice[]>;
|
|
54
48
|
protected abstract createByteTransport(device: ConnectorDevice): Promise<TrezorConnectorByteTransport>;
|
|
55
49
|
protected resolveUnlistedDevice(_deviceId: string): ConnectorDevice | undefined;
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ __export(index_exports, {
|
|
|
26
26
|
shouldLogTrezorDebugEntry: () => import_hwk_trezor_core2.shouldLogTrezorDebugEntry
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(index_exports);
|
|
29
|
-
var
|
|
29
|
+
var import_hwk_adapter_core3 = require("@onekeyfe/hwk-adapter-core");
|
|
30
30
|
var import_hwk_trezor_core = require("@onekeyfe/hwk-trezor-core");
|
|
31
31
|
|
|
32
32
|
// src/chains/utils.ts
|
|
@@ -89,14 +89,12 @@ var BTC_SCRIPT_TYPE_MAP = {
|
|
|
89
89
|
p2pkh: "SPENDADDRESS",
|
|
90
90
|
p2sh: "SPENDP2SHWITNESS",
|
|
91
91
|
p2wpkh: "SPENDWITNESS",
|
|
92
|
-
p2wsh: "SPENDWITNESS",
|
|
93
92
|
p2tr: "SPENDTAPROOT"
|
|
94
93
|
};
|
|
95
94
|
var BTC_CHANGE_OUTPUT_SCRIPT_TYPE_MAP = {
|
|
96
95
|
p2pkh: "PAYTOADDRESS",
|
|
97
96
|
p2sh: "PAYTOP2SHWITNESS",
|
|
98
97
|
p2wpkh: "PAYTOWITNESS",
|
|
99
|
-
p2wsh: "PAYTOWITNESS",
|
|
100
98
|
p2tr: "PAYTOTAPROOT"
|
|
101
99
|
};
|
|
102
100
|
var BTC_COIN_NAME_ALIASES = {
|
|
@@ -120,7 +118,8 @@ function normalizeBtcCoin(coin) {
|
|
|
120
118
|
return BTC_COIN_NAME_ALIASES[coin.toLowerCase()] ?? coin;
|
|
121
119
|
}
|
|
122
120
|
function deriveScriptTypeFromPath(path) {
|
|
123
|
-
const
|
|
121
|
+
const trimmed = path.trim();
|
|
122
|
+
const normalized = /^m\//i.test(trimmed) ? trimmed.slice(2) : trimmed;
|
|
124
123
|
const purpose = normalized.split("/")[0]?.replace(/['hH]$/, "");
|
|
125
124
|
switch (purpose) {
|
|
126
125
|
case "86":
|
|
@@ -132,8 +131,22 @@ function deriveScriptTypeFromPath(path) {
|
|
|
132
131
|
case "44":
|
|
133
132
|
return "p2pkh";
|
|
134
133
|
default:
|
|
135
|
-
return
|
|
134
|
+
return void 0;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function resolveScriptType(map, scriptType, path) {
|
|
138
|
+
const resolved = scriptType ?? deriveScriptTypeFromPath(path);
|
|
139
|
+
if (!resolved) {
|
|
140
|
+
throw createInvalidParamsError(
|
|
141
|
+
`Cannot infer the BTC script type from ${path}; pass scriptType`
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
if (resolved === "p2wsh") {
|
|
145
|
+
throw createInvalidParamsError(
|
|
146
|
+
"BTC p2wsh needs a multisig script; a single key has no p2wsh form"
|
|
147
|
+
);
|
|
136
148
|
}
|
|
149
|
+
return map[resolved];
|
|
137
150
|
}
|
|
138
151
|
async function btcGetAddress(ctx, params) {
|
|
139
152
|
const request = readBtcGetAddressParams(params);
|
|
@@ -141,7 +154,7 @@ async function btcGetAddress(ctx, params) {
|
|
|
141
154
|
address_n: parseBip32Path(request.path),
|
|
142
155
|
coin_name: normalizeBtcCoin(request.coin),
|
|
143
156
|
show_display: request.showOnDevice ?? false,
|
|
144
|
-
script_type: BTC_SCRIPT_TYPE_MAP
|
|
157
|
+
script_type: resolveScriptType(BTC_SCRIPT_TYPE_MAP, request.scriptType, request.path)
|
|
145
158
|
});
|
|
146
159
|
if (response.type !== "Address") {
|
|
147
160
|
throw new Error(`Expected Address response, received ${response.type}`);
|
|
@@ -174,7 +187,7 @@ async function btcSignMessage(ctx, params) {
|
|
|
174
187
|
address_n: parseBip32Path(request.path),
|
|
175
188
|
message: normalizeBtcMessage(request.message, request.hex ?? false),
|
|
176
189
|
coin_name: normalizeBtcCoin(request.coin),
|
|
177
|
-
script_type: BTC_SCRIPT_TYPE_MAP
|
|
190
|
+
script_type: resolveScriptType(BTC_SCRIPT_TYPE_MAP, void 0, request.path)
|
|
178
191
|
};
|
|
179
192
|
if (request.noScriptType) {
|
|
180
193
|
message.no_script_type = true;
|
|
@@ -419,7 +432,7 @@ function inputToTrezor(input) {
|
|
|
419
432
|
prev_hash: input.prevHash,
|
|
420
433
|
prev_index: input.prevIndex,
|
|
421
434
|
amount: input.amount,
|
|
422
|
-
script_type: BTC_SCRIPT_TYPE_MAP
|
|
435
|
+
script_type: resolveScriptType(BTC_SCRIPT_TYPE_MAP, input.scriptType, input.path)
|
|
423
436
|
};
|
|
424
437
|
if (input.sequence !== void 0) result.sequence = input.sequence;
|
|
425
438
|
if (input.origHash !== void 0) result.orig_hash = input.origHash;
|
|
@@ -471,7 +484,11 @@ function outputToTrezor(output2) {
|
|
|
471
484
|
return withOutputMetadata({
|
|
472
485
|
address_n: parseBip32Path(output2.path),
|
|
473
486
|
amount: output2.amount,
|
|
474
|
-
script_type:
|
|
487
|
+
script_type: resolveScriptType(
|
|
488
|
+
BTC_CHANGE_OUTPUT_SCRIPT_TYPE_MAP,
|
|
489
|
+
output2.scriptType,
|
|
490
|
+
output2.path
|
|
491
|
+
)
|
|
475
492
|
});
|
|
476
493
|
}
|
|
477
494
|
throw createInvalidParamsError(
|
|
@@ -662,6 +679,12 @@ function readBtcGetAddressParams(params) {
|
|
|
662
679
|
if (typeof path !== "string" || path.trim().length === 0) {
|
|
663
680
|
throw createInvalidParamsError("btcGetAddress requires a non-empty path");
|
|
664
681
|
}
|
|
682
|
+
const { addressIndex, change } = params;
|
|
683
|
+
if (addressIndex !== void 0 || change !== void 0) {
|
|
684
|
+
throw createInvalidParamsError(
|
|
685
|
+
"Trezor btcGetAddress takes the full address path; addressIndex and change are not supported"
|
|
686
|
+
);
|
|
687
|
+
}
|
|
665
688
|
const { coin } = params;
|
|
666
689
|
if (coin !== void 0 && typeof coin !== "string") {
|
|
667
690
|
throw createInvalidParamsError("btcGetAddress coin must be a string when provided");
|
|
@@ -2416,7 +2439,9 @@ async function evmSignTypedData(ctx, params) {
|
|
|
2416
2439
|
return signTypedDataFull(ctx, request);
|
|
2417
2440
|
}
|
|
2418
2441
|
function isTrezorOne(ctx) {
|
|
2419
|
-
|
|
2442
|
+
const { features } = ctx.deviceSession;
|
|
2443
|
+
const model = features?.internal_model ?? features?.model;
|
|
2444
|
+
return model === "T1B1" || model === "1";
|
|
2420
2445
|
}
|
|
2421
2446
|
function getCallerProvidedTypedDataHashes(request) {
|
|
2422
2447
|
const { domainSeparatorHash, messageHash } = request;
|
|
@@ -2666,6 +2691,7 @@ function normalizeEthMessage(message, isHex) {
|
|
|
2666
2691
|
}
|
|
2667
2692
|
|
|
2668
2693
|
// src/chains/sol.ts
|
|
2694
|
+
var import_hwk_adapter_core2 = require("@onekeyfe/hwk-adapter-core");
|
|
2669
2695
|
async function solGetAddress(ctx, params) {
|
|
2670
2696
|
const request = readSolGetAddressParams(params);
|
|
2671
2697
|
const response = await ctx.deviceSession.call("SolanaGetAddress", {
|
|
@@ -2712,10 +2738,37 @@ async function solSignTransaction(ctx, params) {
|
|
|
2712
2738
|
}
|
|
2713
2739
|
return { signature };
|
|
2714
2740
|
}
|
|
2715
|
-
async function solSignMessage(
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2741
|
+
async function solSignMessage(ctx, params) {
|
|
2742
|
+
const request = readSolSignMsgParams(params);
|
|
2743
|
+
if (request.messageVersion !== 1) {
|
|
2744
|
+
throw createMethodNotSupportedError(
|
|
2745
|
+
"Trezor supports finalized Solana off-chain message version 1 only"
|
|
2746
|
+
);
|
|
2747
|
+
}
|
|
2748
|
+
const preparedMessage = (0, import_hwk_adapter_core2.prepareSolanaOffchainMessageV1)({
|
|
2749
|
+
message: (0, import_hwk_adapter_core2.hexToBytes)(request.message),
|
|
2750
|
+
requiredSigners: request.requiredSigners
|
|
2751
|
+
});
|
|
2752
|
+
const response = await ctx.deviceSession.call("SolanaSignMessage", {
|
|
2753
|
+
address_n: parseBip32Path(request.path),
|
|
2754
|
+
message: {
|
|
2755
|
+
message: preparedMessage.messageText,
|
|
2756
|
+
signers: preparedMessage.requiredSigners
|
|
2757
|
+
}
|
|
2758
|
+
});
|
|
2759
|
+
if (response.type !== "SolanaMessageSignature") {
|
|
2760
|
+
throw new Error(`Expected SolanaMessageSignature response, received ${response.type}`);
|
|
2761
|
+
}
|
|
2762
|
+
const signature = readString(response.message, "signature");
|
|
2763
|
+
if (!signature) {
|
|
2764
|
+
throw new Error("SolanaMessageSignature response did not include a signature");
|
|
2765
|
+
}
|
|
2766
|
+
const signedData = readString(response.message, "signed_data");
|
|
2767
|
+
const expectedSignedData = (0, import_hwk_adapter_core2.bytesToHex)(preparedMessage.serializedMessage);
|
|
2768
|
+
if (!signedData || stripHexPrefix2(signedData).toLowerCase() !== expectedSignedData) {
|
|
2769
|
+
throw new Error("Trezor signed data does not match the requested Solana off-chain message");
|
|
2770
|
+
}
|
|
2771
|
+
return { signature: stripHexPrefix2(signature).toLowerCase() };
|
|
2719
2772
|
}
|
|
2720
2773
|
function readSolGetAddressParams(params) {
|
|
2721
2774
|
if (!params || typeof params !== "object") {
|
|
@@ -2746,6 +2799,25 @@ function readSolSignTxParams(params) {
|
|
|
2746
2799
|
assertHexString("serializedTx", serializedTx);
|
|
2747
2800
|
return params;
|
|
2748
2801
|
}
|
|
2802
|
+
function readSolSignMsgParams(params) {
|
|
2803
|
+
if (!params || typeof params !== "object") {
|
|
2804
|
+
throw createInvalidParamsError("solSignMessage params must be an object");
|
|
2805
|
+
}
|
|
2806
|
+
const request = params;
|
|
2807
|
+
if (typeof request.path !== "string" || request.path.trim().length === 0) {
|
|
2808
|
+
throw createInvalidParamsError("solSignMessage requires a non-empty path");
|
|
2809
|
+
}
|
|
2810
|
+
if (typeof request.message !== "string" || request.message.length === 0) {
|
|
2811
|
+
throw createInvalidParamsError("solSignMessage requires message as a hex string");
|
|
2812
|
+
}
|
|
2813
|
+
assertHexString("message", request.message);
|
|
2814
|
+
if (request.messageVersion === 1 && !Array.isArray(request.requiredSigners)) {
|
|
2815
|
+
throw createInvalidParamsError(
|
|
2816
|
+
"Solana off-chain message version 1 requires signer public keys"
|
|
2817
|
+
);
|
|
2818
|
+
}
|
|
2819
|
+
return request;
|
|
2820
|
+
}
|
|
2749
2821
|
function stripHexPrefix2(value) {
|
|
2750
2822
|
return value.startsWith("0x") || value.startsWith("0X") ? value.slice(2) : value;
|
|
2751
2823
|
}
|
|
@@ -7668,8 +7740,8 @@ var REQUIRED_DEVICE_CAPABILITIES = {
|
|
|
7668
7740
|
function normalizePassphraseMode(passphraseMode) {
|
|
7669
7741
|
if (passphraseMode === void 0) return "prompt";
|
|
7670
7742
|
if (passphraseMode === "prompt" || passphraseMode === "empty") return passphraseMode;
|
|
7671
|
-
throw (0,
|
|
7672
|
-
code:
|
|
7743
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
7744
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.InvalidParams,
|
|
7673
7745
|
message: `Invalid Trezor passphrase mode: ${String(passphraseMode)}`
|
|
7674
7746
|
});
|
|
7675
7747
|
}
|
|
@@ -7685,8 +7757,8 @@ var MAX_AUTHENTICITY_PROOF_PART_SIZE = 64 * 1024;
|
|
|
7685
7757
|
var MAX_AUTHENTICITY_CERTIFICATE_COUNT = 4;
|
|
7686
7758
|
var validateAuthenticityProofPartSize = (size) => {
|
|
7687
7759
|
if (typeof size !== "number" || !Number.isSafeInteger(size) || size < 0 || size > MAX_AUTHENTICITY_PROOF_PART_SIZE) {
|
|
7688
|
-
throw (0,
|
|
7689
|
-
code:
|
|
7760
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
7761
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UnknownError,
|
|
7690
7762
|
message: `Invalid Trezor authenticity proof part size: ${String(size)}`
|
|
7691
7763
|
});
|
|
7692
7764
|
}
|
|
@@ -7714,15 +7786,15 @@ var readAuthenticityProofPart = async ({
|
|
|
7714
7786
|
request
|
|
7715
7787
|
);
|
|
7716
7788
|
if (response.type !== "AuthenticityProofChunk") {
|
|
7717
|
-
throw (0,
|
|
7718
|
-
code:
|
|
7789
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
7790
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UnknownError,
|
|
7719
7791
|
message: `Expected AuthenticityProofChunk, received ${response.type}`
|
|
7720
7792
|
});
|
|
7721
7793
|
}
|
|
7722
7794
|
const chunk = response.message?.chunk;
|
|
7723
7795
|
if (typeof chunk !== "string" || chunk.length !== requestedSize * 2) {
|
|
7724
|
-
throw (0,
|
|
7725
|
-
code:
|
|
7796
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
7797
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UnknownError,
|
|
7726
7798
|
message: "Trezor returned an invalid authenticity proof chunk"
|
|
7727
7799
|
});
|
|
7728
7800
|
}
|
|
@@ -7734,14 +7806,14 @@ var readAuthenticityProofPart = async ({
|
|
|
7734
7806
|
var readAuthenticityProofStream = async (deviceSession, sizes) => {
|
|
7735
7807
|
const readCertificates = async (proofType, values) => {
|
|
7736
7808
|
if (!Array.isArray(values)) {
|
|
7737
|
-
throw (0,
|
|
7738
|
-
code:
|
|
7809
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
7810
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UnknownError,
|
|
7739
7811
|
message: "Trezor returned invalid authenticity certificate sizes"
|
|
7740
7812
|
});
|
|
7741
7813
|
}
|
|
7742
7814
|
if (values.length > MAX_AUTHENTICITY_CERTIFICATE_COUNT) {
|
|
7743
|
-
throw (0,
|
|
7744
|
-
code:
|
|
7815
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
7816
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UnknownError,
|
|
7745
7817
|
message: `Trezor authenticity proof contains too many certificates: ${values.length}`
|
|
7746
7818
|
});
|
|
7747
7819
|
}
|
|
@@ -7790,13 +7862,13 @@ var TrezorConnectorBase = class {
|
|
|
7790
7862
|
chunkSize;
|
|
7791
7863
|
thp;
|
|
7792
7864
|
// Single owned array — passed by reference into every TrezorThpSession via
|
|
7793
|
-
// `createThpOptions`.
|
|
7794
|
-
//
|
|
7795
|
-
//
|
|
7865
|
+
// `createThpOptions`. Both host updates and authoritative device updates
|
|
7866
|
+
// replace its contents in-place so the next handshake sees fresh credentials
|
|
7867
|
+
// without a connector rebuild.
|
|
7796
7868
|
knownCredentials = [];
|
|
7797
7869
|
deviceSessionFactory;
|
|
7798
7870
|
eventHandlers = /* @__PURE__ */ new Map();
|
|
7799
|
-
uiRequests = new
|
|
7871
|
+
uiRequests = new import_hwk_adapter_core3.UiRequestRegistry();
|
|
7800
7872
|
devices = /* @__PURE__ */ new Map();
|
|
7801
7873
|
sessions = /* @__PURE__ */ new Map();
|
|
7802
7874
|
constructor(options = {}) {
|
|
@@ -7829,21 +7901,6 @@ var TrezorConnectorBase = class {
|
|
|
7829
7901
|
this.knownCredentials.push(...credentials);
|
|
7830
7902
|
}
|
|
7831
7903
|
}
|
|
7832
|
-
/**
|
|
7833
|
-
* Push new credentials minted during pairing into the in-memory array.
|
|
7834
|
-
* Deduplicates by the device-minted `credential` blob — the host has no
|
|
7835
|
-
* other stable identity for a credential.
|
|
7836
|
-
*/
|
|
7837
|
-
mergeKnownCredentials(incoming) {
|
|
7838
|
-
for (const cred of incoming) {
|
|
7839
|
-
const blob = cred.credential;
|
|
7840
|
-
if (!blob) continue;
|
|
7841
|
-
const exists2 = this.knownCredentials.some(
|
|
7842
|
-
(existing) => existing.credential === blob
|
|
7843
|
-
);
|
|
7844
|
-
if (!exists2) this.knownCredentials.push(cred);
|
|
7845
|
-
}
|
|
7846
|
-
}
|
|
7847
7904
|
resolveUnlistedDevice(_deviceId) {
|
|
7848
7905
|
return void 0;
|
|
7849
7906
|
}
|
|
@@ -7979,14 +8036,18 @@ var TrezorConnectorBase = class {
|
|
|
7979
8036
|
durationMs: Date.now() - startedAt,
|
|
7980
8037
|
error: errorToLog(error)
|
|
7981
8038
|
});
|
|
7982
|
-
|
|
8039
|
+
const serialized = (0, import_hwk_adapter_core3.serializeConnectorError)(error);
|
|
8040
|
+
if (error?.code === "ThpPairingFailed") {
|
|
8041
|
+
serialized.code = import_hwk_adapter_core3.HardwareErrorCode.ThpPairingFailed;
|
|
8042
|
+
}
|
|
8043
|
+
return { success: false, error: serialized };
|
|
7983
8044
|
}
|
|
7984
8045
|
}
|
|
7985
8046
|
async dispatchCall(sessionId, method, params) {
|
|
7986
8047
|
const session = this.sessions.get(sessionId);
|
|
7987
8048
|
if (!session) {
|
|
7988
|
-
throw (0,
|
|
7989
|
-
code:
|
|
8049
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8050
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.DeviceNotFound,
|
|
7990
8051
|
message: `Trezor session not found: ${sessionId}`
|
|
7991
8052
|
});
|
|
7992
8053
|
}
|
|
@@ -8039,8 +8100,8 @@ var TrezorConnectorBase = class {
|
|
|
8039
8100
|
return getTrezorResponseMessage(response);
|
|
8040
8101
|
}
|
|
8041
8102
|
if (response.type !== "AuthenticityProofSizes") {
|
|
8042
|
-
throw (0,
|
|
8043
|
-
code:
|
|
8103
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8104
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UnknownError,
|
|
8044
8105
|
message: `Expected Trezor authenticity proof, received ${response.type}`
|
|
8045
8106
|
});
|
|
8046
8107
|
}
|
|
@@ -8072,8 +8133,8 @@ var TrezorConnectorBase = class {
|
|
|
8072
8133
|
}
|
|
8073
8134
|
const p = params ?? {};
|
|
8074
8135
|
if (!p.thpSessionId) {
|
|
8075
|
-
throw (0,
|
|
8076
|
-
code:
|
|
8136
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8137
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.InvalidParams,
|
|
8077
8138
|
message: "__thpSelectSession requires a thpSessionId"
|
|
8078
8139
|
});
|
|
8079
8140
|
}
|
|
@@ -8118,8 +8179,8 @@ var TrezorConnectorBase = class {
|
|
|
8118
8179
|
case "tronSignMessage":
|
|
8119
8180
|
return tronSignMessage(ctx, params);
|
|
8120
8181
|
default:
|
|
8121
|
-
throw (0,
|
|
8122
|
-
code:
|
|
8182
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8183
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.MethodNotSupported,
|
|
8123
8184
|
message: `TrezorConnector: method "${method}" is not implemented`
|
|
8124
8185
|
});
|
|
8125
8186
|
}
|
|
@@ -8143,8 +8204,8 @@ var TrezorConnectorBase = class {
|
|
|
8143
8204
|
};
|
|
8144
8205
|
this.log(hasAllRequired ? "info" : "warn", "capability.check", checkPayload);
|
|
8145
8206
|
if (hasAllRequired) return;
|
|
8146
|
-
throw (0,
|
|
8147
|
-
code:
|
|
8207
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8208
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.MethodNotSupported,
|
|
8148
8209
|
message: `Trezor device is missing required capability for ${method}: ${required.map((capability) => capability.name).join(", ")}`,
|
|
8149
8210
|
params: {
|
|
8150
8211
|
method,
|
|
@@ -8156,7 +8217,7 @@ var TrezorConnectorBase = class {
|
|
|
8156
8217
|
async cancel(_sessionId) {
|
|
8157
8218
|
}
|
|
8158
8219
|
uiResponse(_response) {
|
|
8159
|
-
if (_response.type ===
|
|
8220
|
+
if (_response.type === import_hwk_adapter_core3.UI_RESPONSE.CANCEL) {
|
|
8160
8221
|
this.uiRequests.cancel();
|
|
8161
8222
|
return;
|
|
8162
8223
|
}
|
|
@@ -8202,8 +8263,8 @@ var TrezorConnectorBase = class {
|
|
|
8202
8263
|
return device;
|
|
8203
8264
|
}
|
|
8204
8265
|
if (!device) {
|
|
8205
|
-
throw (0,
|
|
8206
|
-
code:
|
|
8266
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8267
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.DeviceNotFound,
|
|
8207
8268
|
message: deviceId ? `Trezor device not found: ${deviceId}` : "No Trezor device found"
|
|
8208
8269
|
});
|
|
8209
8270
|
}
|
|
@@ -8221,8 +8282,9 @@ var TrezorConnectorBase = class {
|
|
|
8221
8282
|
if (this.thp?.onPairingRequest) {
|
|
8222
8283
|
return this.thp.onPairingRequest(payload);
|
|
8223
8284
|
}
|
|
8285
|
+
const pairingPromise = this.uiRequests.wait(import_hwk_adapter_core3.UI_REQUEST.REQUEST_TREZOR_THP_PAIRING);
|
|
8224
8286
|
this.emit("ui-request", {
|
|
8225
|
-
type:
|
|
8287
|
+
type: import_hwk_adapter_core3.UI_REQUEST.REQUEST_TREZOR_THP_PAIRING,
|
|
8226
8288
|
payload: {
|
|
8227
8289
|
connectId: device.connectId,
|
|
8228
8290
|
availableMethods: payload.availableMethods,
|
|
@@ -8230,12 +8292,12 @@ var TrezorConnectorBase = class {
|
|
|
8230
8292
|
nfcData: payload.nfcData
|
|
8231
8293
|
}
|
|
8232
8294
|
});
|
|
8233
|
-
return
|
|
8295
|
+
return pairingPromise;
|
|
8234
8296
|
},
|
|
8235
8297
|
onButtonRequest: async (payload) => {
|
|
8236
8298
|
await this.thp?.onButtonRequest?.(payload);
|
|
8237
8299
|
this.emit("ui-request", {
|
|
8238
|
-
type:
|
|
8300
|
+
type: import_hwk_adapter_core3.UI_REQUEST.REQUEST_BUTTON,
|
|
8239
8301
|
payload: {
|
|
8240
8302
|
connectId: device.connectId,
|
|
8241
8303
|
...payload
|
|
@@ -8244,20 +8306,19 @@ var TrezorConnectorBase = class {
|
|
|
8244
8306
|
},
|
|
8245
8307
|
onButtonRequestComplete: async (payload) => {
|
|
8246
8308
|
await this.thp?.onButtonRequestComplete?.(payload);
|
|
8309
|
+
if (payload.responseType === "ButtonRequest") return;
|
|
8247
8310
|
this.emit("ui-event", {
|
|
8248
|
-
type:
|
|
8249
|
-
payload: {
|
|
8250
|
-
sessionId: device.connectId
|
|
8251
|
-
}
|
|
8311
|
+
type: import_hwk_adapter_core3.EConnectorInteraction.InteractionComplete,
|
|
8312
|
+
payload: { sessionId: "" }
|
|
8252
8313
|
});
|
|
8253
8314
|
},
|
|
8254
8315
|
onPinMatrixRequest: async (payload) => {
|
|
8255
8316
|
if (this.thp?.onPinMatrixRequest) {
|
|
8256
8317
|
return this.thp.onPinMatrixRequest(payload);
|
|
8257
8318
|
}
|
|
8258
|
-
const pinPromise = this.uiRequests.wait(
|
|
8319
|
+
const pinPromise = this.uiRequests.wait(import_hwk_adapter_core3.UI_REQUEST.REQUEST_PIN);
|
|
8259
8320
|
this.emit("ui-request", {
|
|
8260
|
-
type:
|
|
8321
|
+
type: import_hwk_adapter_core3.UI_REQUEST.REQUEST_PIN,
|
|
8261
8322
|
payload: {
|
|
8262
8323
|
connectId: device.connectId,
|
|
8263
8324
|
type: payload.type
|
|
@@ -8269,9 +8330,9 @@ var TrezorConnectorBase = class {
|
|
|
8269
8330
|
if (this.thp?.onPassphraseRequest) {
|
|
8270
8331
|
return this.thp.onPassphraseRequest(payload);
|
|
8271
8332
|
}
|
|
8272
|
-
const passphrasePromise = this.uiRequests.wait(
|
|
8333
|
+
const passphrasePromise = this.uiRequests.wait(import_hwk_adapter_core3.UI_REQUEST.REQUEST_PASSPHRASE);
|
|
8273
8334
|
this.emit("ui-request", {
|
|
8274
|
-
type:
|
|
8335
|
+
type: import_hwk_adapter_core3.UI_REQUEST.REQUEST_PASSPHRASE,
|
|
8275
8336
|
payload: {
|
|
8276
8337
|
connectId: device.connectId,
|
|
8277
8338
|
...payload
|
|
@@ -8281,12 +8342,21 @@ var TrezorConnectorBase = class {
|
|
|
8281
8342
|
return res?.passphraseOnDevice ? { on_device: true } : { passphrase: res?.value ?? "" };
|
|
8282
8343
|
},
|
|
8283
8344
|
onPairingCredentialsChanged: async (payload) => {
|
|
8284
|
-
|
|
8345
|
+
const blob = (cred) => cred.credential;
|
|
8346
|
+
const rejected = new Set((payload.removed ?? []).map(blob));
|
|
8347
|
+
const merged = this.knownCredentials.filter((cred) => !rejected.has(blob(cred)));
|
|
8348
|
+
for (const cred of payload.credentials) {
|
|
8349
|
+
if (blob(cred) && !merged.some((existing) => blob(existing) === blob(cred))) {
|
|
8350
|
+
merged.push(cred);
|
|
8351
|
+
}
|
|
8352
|
+
}
|
|
8353
|
+
this.setKnownCredentials(merged);
|
|
8285
8354
|
await this.thp?.onPairingCredentialsChanged?.(payload);
|
|
8286
8355
|
this.emit("device-trezor-thp-credentials-changed", {
|
|
8287
8356
|
connectId: device.connectId,
|
|
8288
8357
|
deviceId: device.deviceId,
|
|
8289
|
-
credentials: payload.credentials
|
|
8358
|
+
credentials: payload.credentials,
|
|
8359
|
+
removed: payload.removed
|
|
8290
8360
|
});
|
|
8291
8361
|
}
|
|
8292
8362
|
};
|
|
@@ -8302,7 +8372,7 @@ var TrezorConnectorBase = class {
|
|
|
8302
8372
|
emitSupportFeatures(session) {
|
|
8303
8373
|
const features = session.deviceSession.features ?? session.features;
|
|
8304
8374
|
session.features = features;
|
|
8305
|
-
this.emit(
|
|
8375
|
+
this.emit(import_hwk_adapter_core3.DEVICE.FEATURES, {
|
|
8306
8376
|
device: {
|
|
8307
8377
|
...session.device,
|
|
8308
8378
|
deviceId: readString(features, "device_id") ?? session.device.deviceId,
|
|
@@ -8325,9 +8395,9 @@ function connectorSessionToDevice(session) {
|
|
|
8325
8395
|
};
|
|
8326
8396
|
}
|
|
8327
8397
|
function rejectKnownNonTrezorDevice(features) {
|
|
8328
|
-
if (!(0,
|
|
8329
|
-
throw (0,
|
|
8330
|
-
code:
|
|
8398
|
+
if (!(0, import_hwk_adapter_core3.isKnownNonTargetHardwareVendor)(features, "trezor")) return;
|
|
8399
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8400
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.DeviceMismatch,
|
|
8331
8401
|
message: "Selected device is not a supported Trezor device.",
|
|
8332
8402
|
params: {
|
|
8333
8403
|
vendor: features.vendor,
|