@onekeyfe/hwk-trezor-connector 1.2.8-alpha.103 → 1.2.8-alpha.104
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 +143 -75
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +105 -37
- 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");
|
|
@@ -2666,6 +2689,7 @@ function normalizeEthMessage(message, isHex) {
|
|
|
2666
2689
|
}
|
|
2667
2690
|
|
|
2668
2691
|
// src/chains/sol.ts
|
|
2692
|
+
var import_hwk_adapter_core2 = require("@onekeyfe/hwk-adapter-core");
|
|
2669
2693
|
async function solGetAddress(ctx, params) {
|
|
2670
2694
|
const request = readSolGetAddressParams(params);
|
|
2671
2695
|
const response = await ctx.deviceSession.call("SolanaGetAddress", {
|
|
@@ -2712,10 +2736,37 @@ async function solSignTransaction(ctx, params) {
|
|
|
2712
2736
|
}
|
|
2713
2737
|
return { signature };
|
|
2714
2738
|
}
|
|
2715
|
-
async function solSignMessage(
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2739
|
+
async function solSignMessage(ctx, params) {
|
|
2740
|
+
const request = readSolSignMsgParams(params);
|
|
2741
|
+
if (request.messageVersion !== 1) {
|
|
2742
|
+
throw createMethodNotSupportedError(
|
|
2743
|
+
"Trezor supports finalized Solana off-chain message version 1 only"
|
|
2744
|
+
);
|
|
2745
|
+
}
|
|
2746
|
+
const preparedMessage = (0, import_hwk_adapter_core2.prepareSolanaOffchainMessageV1)({
|
|
2747
|
+
message: (0, import_hwk_adapter_core2.hexToBytes)(request.message),
|
|
2748
|
+
requiredSigners: request.requiredSigners
|
|
2749
|
+
});
|
|
2750
|
+
const response = await ctx.deviceSession.call("SolanaSignMessage", {
|
|
2751
|
+
address_n: parseBip32Path(request.path),
|
|
2752
|
+
message: {
|
|
2753
|
+
message: preparedMessage.messageText,
|
|
2754
|
+
signers: preparedMessage.requiredSigners
|
|
2755
|
+
}
|
|
2756
|
+
});
|
|
2757
|
+
if (response.type !== "SolanaMessageSignature") {
|
|
2758
|
+
throw new Error(`Expected SolanaMessageSignature response, received ${response.type}`);
|
|
2759
|
+
}
|
|
2760
|
+
const signature = readString(response.message, "signature");
|
|
2761
|
+
if (!signature) {
|
|
2762
|
+
throw new Error("SolanaMessageSignature response did not include a signature");
|
|
2763
|
+
}
|
|
2764
|
+
const signedData = readString(response.message, "signed_data");
|
|
2765
|
+
const expectedSignedData = (0, import_hwk_adapter_core2.bytesToHex)(preparedMessage.serializedMessage);
|
|
2766
|
+
if (!signedData || stripHexPrefix2(signedData).toLowerCase() !== expectedSignedData) {
|
|
2767
|
+
throw new Error("Trezor signed data does not match the requested Solana off-chain message");
|
|
2768
|
+
}
|
|
2769
|
+
return { signature: stripHexPrefix2(signature).toLowerCase() };
|
|
2719
2770
|
}
|
|
2720
2771
|
function readSolGetAddressParams(params) {
|
|
2721
2772
|
if (!params || typeof params !== "object") {
|
|
@@ -2746,6 +2797,25 @@ function readSolSignTxParams(params) {
|
|
|
2746
2797
|
assertHexString("serializedTx", serializedTx);
|
|
2747
2798
|
return params;
|
|
2748
2799
|
}
|
|
2800
|
+
function readSolSignMsgParams(params) {
|
|
2801
|
+
if (!params || typeof params !== "object") {
|
|
2802
|
+
throw createInvalidParamsError("solSignMessage params must be an object");
|
|
2803
|
+
}
|
|
2804
|
+
const request = params;
|
|
2805
|
+
if (typeof request.path !== "string" || request.path.trim().length === 0) {
|
|
2806
|
+
throw createInvalidParamsError("solSignMessage requires a non-empty path");
|
|
2807
|
+
}
|
|
2808
|
+
if (typeof request.message !== "string" || request.message.length === 0) {
|
|
2809
|
+
throw createInvalidParamsError("solSignMessage requires message as a hex string");
|
|
2810
|
+
}
|
|
2811
|
+
assertHexString("message", request.message);
|
|
2812
|
+
if (request.messageVersion === 1 && !Array.isArray(request.requiredSigners)) {
|
|
2813
|
+
throw createInvalidParamsError(
|
|
2814
|
+
"Solana off-chain message version 1 requires signer public keys"
|
|
2815
|
+
);
|
|
2816
|
+
}
|
|
2817
|
+
return request;
|
|
2818
|
+
}
|
|
2749
2819
|
function stripHexPrefix2(value) {
|
|
2750
2820
|
return value.startsWith("0x") || value.startsWith("0X") ? value.slice(2) : value;
|
|
2751
2821
|
}
|
|
@@ -7668,8 +7738,8 @@ var REQUIRED_DEVICE_CAPABILITIES = {
|
|
|
7668
7738
|
function normalizePassphraseMode(passphraseMode) {
|
|
7669
7739
|
if (passphraseMode === void 0) return "prompt";
|
|
7670
7740
|
if (passphraseMode === "prompt" || passphraseMode === "empty") return passphraseMode;
|
|
7671
|
-
throw (0,
|
|
7672
|
-
code:
|
|
7741
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
7742
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.InvalidParams,
|
|
7673
7743
|
message: `Invalid Trezor passphrase mode: ${String(passphraseMode)}`
|
|
7674
7744
|
});
|
|
7675
7745
|
}
|
|
@@ -7685,8 +7755,8 @@ var MAX_AUTHENTICITY_PROOF_PART_SIZE = 64 * 1024;
|
|
|
7685
7755
|
var MAX_AUTHENTICITY_CERTIFICATE_COUNT = 4;
|
|
7686
7756
|
var validateAuthenticityProofPartSize = (size) => {
|
|
7687
7757
|
if (typeof size !== "number" || !Number.isSafeInteger(size) || size < 0 || size > MAX_AUTHENTICITY_PROOF_PART_SIZE) {
|
|
7688
|
-
throw (0,
|
|
7689
|
-
code:
|
|
7758
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
7759
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UnknownError,
|
|
7690
7760
|
message: `Invalid Trezor authenticity proof part size: ${String(size)}`
|
|
7691
7761
|
});
|
|
7692
7762
|
}
|
|
@@ -7714,15 +7784,15 @@ var readAuthenticityProofPart = async ({
|
|
|
7714
7784
|
request
|
|
7715
7785
|
);
|
|
7716
7786
|
if (response.type !== "AuthenticityProofChunk") {
|
|
7717
|
-
throw (0,
|
|
7718
|
-
code:
|
|
7787
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
7788
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UnknownError,
|
|
7719
7789
|
message: `Expected AuthenticityProofChunk, received ${response.type}`
|
|
7720
7790
|
});
|
|
7721
7791
|
}
|
|
7722
7792
|
const chunk = response.message?.chunk;
|
|
7723
7793
|
if (typeof chunk !== "string" || chunk.length !== requestedSize * 2) {
|
|
7724
|
-
throw (0,
|
|
7725
|
-
code:
|
|
7794
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
7795
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UnknownError,
|
|
7726
7796
|
message: "Trezor returned an invalid authenticity proof chunk"
|
|
7727
7797
|
});
|
|
7728
7798
|
}
|
|
@@ -7734,14 +7804,14 @@ var readAuthenticityProofPart = async ({
|
|
|
7734
7804
|
var readAuthenticityProofStream = async (deviceSession, sizes) => {
|
|
7735
7805
|
const readCertificates = async (proofType, values) => {
|
|
7736
7806
|
if (!Array.isArray(values)) {
|
|
7737
|
-
throw (0,
|
|
7738
|
-
code:
|
|
7807
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
7808
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UnknownError,
|
|
7739
7809
|
message: "Trezor returned invalid authenticity certificate sizes"
|
|
7740
7810
|
});
|
|
7741
7811
|
}
|
|
7742
7812
|
if (values.length > MAX_AUTHENTICITY_CERTIFICATE_COUNT) {
|
|
7743
|
-
throw (0,
|
|
7744
|
-
code:
|
|
7813
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
7814
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UnknownError,
|
|
7745
7815
|
message: `Trezor authenticity proof contains too many certificates: ${values.length}`
|
|
7746
7816
|
});
|
|
7747
7817
|
}
|
|
@@ -7790,13 +7860,13 @@ var TrezorConnectorBase = class {
|
|
|
7790
7860
|
chunkSize;
|
|
7791
7861
|
thp;
|
|
7792
7862
|
// Single owned array — passed by reference into every TrezorThpSession via
|
|
7793
|
-
// `createThpOptions`.
|
|
7794
|
-
//
|
|
7795
|
-
//
|
|
7863
|
+
// `createThpOptions`. Both host updates and authoritative device updates
|
|
7864
|
+
// replace its contents in-place so the next handshake sees fresh credentials
|
|
7865
|
+
// without a connector rebuild.
|
|
7796
7866
|
knownCredentials = [];
|
|
7797
7867
|
deviceSessionFactory;
|
|
7798
7868
|
eventHandlers = /* @__PURE__ */ new Map();
|
|
7799
|
-
uiRequests = new
|
|
7869
|
+
uiRequests = new import_hwk_adapter_core3.UiRequestRegistry();
|
|
7800
7870
|
devices = /* @__PURE__ */ new Map();
|
|
7801
7871
|
sessions = /* @__PURE__ */ new Map();
|
|
7802
7872
|
constructor(options = {}) {
|
|
@@ -7829,21 +7899,6 @@ var TrezorConnectorBase = class {
|
|
|
7829
7899
|
this.knownCredentials.push(...credentials);
|
|
7830
7900
|
}
|
|
7831
7901
|
}
|
|
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
7902
|
resolveUnlistedDevice(_deviceId) {
|
|
7848
7903
|
return void 0;
|
|
7849
7904
|
}
|
|
@@ -7979,14 +8034,18 @@ var TrezorConnectorBase = class {
|
|
|
7979
8034
|
durationMs: Date.now() - startedAt,
|
|
7980
8035
|
error: errorToLog(error)
|
|
7981
8036
|
});
|
|
7982
|
-
|
|
8037
|
+
const serialized = (0, import_hwk_adapter_core3.serializeConnectorError)(error);
|
|
8038
|
+
if (error?.code === "ThpPairingFailed") {
|
|
8039
|
+
serialized.code = import_hwk_adapter_core3.HardwareErrorCode.ThpPairingFailed;
|
|
8040
|
+
}
|
|
8041
|
+
return { success: false, error: serialized };
|
|
7983
8042
|
}
|
|
7984
8043
|
}
|
|
7985
8044
|
async dispatchCall(sessionId, method, params) {
|
|
7986
8045
|
const session = this.sessions.get(sessionId);
|
|
7987
8046
|
if (!session) {
|
|
7988
|
-
throw (0,
|
|
7989
|
-
code:
|
|
8047
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8048
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.DeviceNotFound,
|
|
7990
8049
|
message: `Trezor session not found: ${sessionId}`
|
|
7991
8050
|
});
|
|
7992
8051
|
}
|
|
@@ -8039,8 +8098,8 @@ var TrezorConnectorBase = class {
|
|
|
8039
8098
|
return getTrezorResponseMessage(response);
|
|
8040
8099
|
}
|
|
8041
8100
|
if (response.type !== "AuthenticityProofSizes") {
|
|
8042
|
-
throw (0,
|
|
8043
|
-
code:
|
|
8101
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8102
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UnknownError,
|
|
8044
8103
|
message: `Expected Trezor authenticity proof, received ${response.type}`
|
|
8045
8104
|
});
|
|
8046
8105
|
}
|
|
@@ -8072,8 +8131,8 @@ var TrezorConnectorBase = class {
|
|
|
8072
8131
|
}
|
|
8073
8132
|
const p = params ?? {};
|
|
8074
8133
|
if (!p.thpSessionId) {
|
|
8075
|
-
throw (0,
|
|
8076
|
-
code:
|
|
8134
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8135
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.InvalidParams,
|
|
8077
8136
|
message: "__thpSelectSession requires a thpSessionId"
|
|
8078
8137
|
});
|
|
8079
8138
|
}
|
|
@@ -8118,8 +8177,8 @@ var TrezorConnectorBase = class {
|
|
|
8118
8177
|
case "tronSignMessage":
|
|
8119
8178
|
return tronSignMessage(ctx, params);
|
|
8120
8179
|
default:
|
|
8121
|
-
throw (0,
|
|
8122
|
-
code:
|
|
8180
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8181
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.MethodNotSupported,
|
|
8123
8182
|
message: `TrezorConnector: method "${method}" is not implemented`
|
|
8124
8183
|
});
|
|
8125
8184
|
}
|
|
@@ -8143,8 +8202,8 @@ var TrezorConnectorBase = class {
|
|
|
8143
8202
|
};
|
|
8144
8203
|
this.log(hasAllRequired ? "info" : "warn", "capability.check", checkPayload);
|
|
8145
8204
|
if (hasAllRequired) return;
|
|
8146
|
-
throw (0,
|
|
8147
|
-
code:
|
|
8205
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8206
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.MethodNotSupported,
|
|
8148
8207
|
message: `Trezor device is missing required capability for ${method}: ${required.map((capability) => capability.name).join(", ")}`,
|
|
8149
8208
|
params: {
|
|
8150
8209
|
method,
|
|
@@ -8156,7 +8215,7 @@ var TrezorConnectorBase = class {
|
|
|
8156
8215
|
async cancel(_sessionId) {
|
|
8157
8216
|
}
|
|
8158
8217
|
uiResponse(_response) {
|
|
8159
|
-
if (_response.type ===
|
|
8218
|
+
if (_response.type === import_hwk_adapter_core3.UI_RESPONSE.CANCEL) {
|
|
8160
8219
|
this.uiRequests.cancel();
|
|
8161
8220
|
return;
|
|
8162
8221
|
}
|
|
@@ -8202,8 +8261,8 @@ var TrezorConnectorBase = class {
|
|
|
8202
8261
|
return device;
|
|
8203
8262
|
}
|
|
8204
8263
|
if (!device) {
|
|
8205
|
-
throw (0,
|
|
8206
|
-
code:
|
|
8264
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8265
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.DeviceNotFound,
|
|
8207
8266
|
message: deviceId ? `Trezor device not found: ${deviceId}` : "No Trezor device found"
|
|
8208
8267
|
});
|
|
8209
8268
|
}
|
|
@@ -8221,8 +8280,9 @@ var TrezorConnectorBase = class {
|
|
|
8221
8280
|
if (this.thp?.onPairingRequest) {
|
|
8222
8281
|
return this.thp.onPairingRequest(payload);
|
|
8223
8282
|
}
|
|
8283
|
+
const pairingPromise = this.uiRequests.wait(import_hwk_adapter_core3.UI_REQUEST.REQUEST_TREZOR_THP_PAIRING);
|
|
8224
8284
|
this.emit("ui-request", {
|
|
8225
|
-
type:
|
|
8285
|
+
type: import_hwk_adapter_core3.UI_REQUEST.REQUEST_TREZOR_THP_PAIRING,
|
|
8226
8286
|
payload: {
|
|
8227
8287
|
connectId: device.connectId,
|
|
8228
8288
|
availableMethods: payload.availableMethods,
|
|
@@ -8230,12 +8290,12 @@ var TrezorConnectorBase = class {
|
|
|
8230
8290
|
nfcData: payload.nfcData
|
|
8231
8291
|
}
|
|
8232
8292
|
});
|
|
8233
|
-
return
|
|
8293
|
+
return pairingPromise;
|
|
8234
8294
|
},
|
|
8235
8295
|
onButtonRequest: async (payload) => {
|
|
8236
8296
|
await this.thp?.onButtonRequest?.(payload);
|
|
8237
8297
|
this.emit("ui-request", {
|
|
8238
|
-
type:
|
|
8298
|
+
type: import_hwk_adapter_core3.UI_REQUEST.REQUEST_BUTTON,
|
|
8239
8299
|
payload: {
|
|
8240
8300
|
connectId: device.connectId,
|
|
8241
8301
|
...payload
|
|
@@ -8244,20 +8304,19 @@ var TrezorConnectorBase = class {
|
|
|
8244
8304
|
},
|
|
8245
8305
|
onButtonRequestComplete: async (payload) => {
|
|
8246
8306
|
await this.thp?.onButtonRequestComplete?.(payload);
|
|
8307
|
+
if (payload.responseType === "ButtonRequest") return;
|
|
8247
8308
|
this.emit("ui-event", {
|
|
8248
|
-
type:
|
|
8249
|
-
payload: {
|
|
8250
|
-
sessionId: device.connectId
|
|
8251
|
-
}
|
|
8309
|
+
type: import_hwk_adapter_core3.EConnectorInteraction.InteractionComplete,
|
|
8310
|
+
payload: { sessionId: "" }
|
|
8252
8311
|
});
|
|
8253
8312
|
},
|
|
8254
8313
|
onPinMatrixRequest: async (payload) => {
|
|
8255
8314
|
if (this.thp?.onPinMatrixRequest) {
|
|
8256
8315
|
return this.thp.onPinMatrixRequest(payload);
|
|
8257
8316
|
}
|
|
8258
|
-
const pinPromise = this.uiRequests.wait(
|
|
8317
|
+
const pinPromise = this.uiRequests.wait(import_hwk_adapter_core3.UI_REQUEST.REQUEST_PIN);
|
|
8259
8318
|
this.emit("ui-request", {
|
|
8260
|
-
type:
|
|
8319
|
+
type: import_hwk_adapter_core3.UI_REQUEST.REQUEST_PIN,
|
|
8261
8320
|
payload: {
|
|
8262
8321
|
connectId: device.connectId,
|
|
8263
8322
|
type: payload.type
|
|
@@ -8269,9 +8328,9 @@ var TrezorConnectorBase = class {
|
|
|
8269
8328
|
if (this.thp?.onPassphraseRequest) {
|
|
8270
8329
|
return this.thp.onPassphraseRequest(payload);
|
|
8271
8330
|
}
|
|
8272
|
-
const passphrasePromise = this.uiRequests.wait(
|
|
8331
|
+
const passphrasePromise = this.uiRequests.wait(import_hwk_adapter_core3.UI_REQUEST.REQUEST_PASSPHRASE);
|
|
8273
8332
|
this.emit("ui-request", {
|
|
8274
|
-
type:
|
|
8333
|
+
type: import_hwk_adapter_core3.UI_REQUEST.REQUEST_PASSPHRASE,
|
|
8275
8334
|
payload: {
|
|
8276
8335
|
connectId: device.connectId,
|
|
8277
8336
|
...payload
|
|
@@ -8281,12 +8340,21 @@ var TrezorConnectorBase = class {
|
|
|
8281
8340
|
return res?.passphraseOnDevice ? { on_device: true } : { passphrase: res?.value ?? "" };
|
|
8282
8341
|
},
|
|
8283
8342
|
onPairingCredentialsChanged: async (payload) => {
|
|
8284
|
-
|
|
8343
|
+
const blob = (cred) => cred.credential;
|
|
8344
|
+
const rejected = new Set((payload.removed ?? []).map(blob));
|
|
8345
|
+
const merged = this.knownCredentials.filter((cred) => !rejected.has(blob(cred)));
|
|
8346
|
+
for (const cred of payload.credentials) {
|
|
8347
|
+
if (blob(cred) && !merged.some((existing) => blob(existing) === blob(cred))) {
|
|
8348
|
+
merged.push(cred);
|
|
8349
|
+
}
|
|
8350
|
+
}
|
|
8351
|
+
this.setKnownCredentials(merged);
|
|
8285
8352
|
await this.thp?.onPairingCredentialsChanged?.(payload);
|
|
8286
8353
|
this.emit("device-trezor-thp-credentials-changed", {
|
|
8287
8354
|
connectId: device.connectId,
|
|
8288
8355
|
deviceId: device.deviceId,
|
|
8289
|
-
credentials: payload.credentials
|
|
8356
|
+
credentials: payload.credentials,
|
|
8357
|
+
removed: payload.removed
|
|
8290
8358
|
});
|
|
8291
8359
|
}
|
|
8292
8360
|
};
|
|
@@ -8302,7 +8370,7 @@ var TrezorConnectorBase = class {
|
|
|
8302
8370
|
emitSupportFeatures(session) {
|
|
8303
8371
|
const features = session.deviceSession.features ?? session.features;
|
|
8304
8372
|
session.features = features;
|
|
8305
|
-
this.emit(
|
|
8373
|
+
this.emit(import_hwk_adapter_core3.DEVICE.FEATURES, {
|
|
8306
8374
|
device: {
|
|
8307
8375
|
...session.device,
|
|
8308
8376
|
deviceId: readString(features, "device_id") ?? session.device.deviceId,
|
|
@@ -8325,9 +8393,9 @@ function connectorSessionToDevice(session) {
|
|
|
8325
8393
|
};
|
|
8326
8394
|
}
|
|
8327
8395
|
function rejectKnownNonTrezorDevice(features) {
|
|
8328
|
-
if (!(0,
|
|
8329
|
-
throw (0,
|
|
8330
|
-
code:
|
|
8396
|
+
if (!(0, import_hwk_adapter_core3.isKnownNonTargetHardwareVendor)(features, "trezor")) return;
|
|
8397
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8398
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.DeviceMismatch,
|
|
8331
8399
|
message: "Selected device is not a supported Trezor device.",
|
|
8332
8400
|
params: {
|
|
8333
8401
|
vendor: features.vendor,
|