@onekeyfe/hwk-trezor-connector 1.2.8 → 1.2.10-alpha.2
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");
|
|
@@ -2668,6 +2691,7 @@ function normalizeEthMessage(message, isHex) {
|
|
|
2668
2691
|
}
|
|
2669
2692
|
|
|
2670
2693
|
// src/chains/sol.ts
|
|
2694
|
+
var import_hwk_adapter_core2 = require("@onekeyfe/hwk-adapter-core");
|
|
2671
2695
|
async function solGetAddress(ctx, params) {
|
|
2672
2696
|
const request = readSolGetAddressParams(params);
|
|
2673
2697
|
const response = await ctx.deviceSession.call("SolanaGetAddress", {
|
|
@@ -2714,10 +2738,37 @@ async function solSignTransaction(ctx, params) {
|
|
|
2714
2738
|
}
|
|
2715
2739
|
return { signature };
|
|
2716
2740
|
}
|
|
2717
|
-
async function solSignMessage(
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
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() };
|
|
2721
2772
|
}
|
|
2722
2773
|
function readSolGetAddressParams(params) {
|
|
2723
2774
|
if (!params || typeof params !== "object") {
|
|
@@ -2748,6 +2799,25 @@ function readSolSignTxParams(params) {
|
|
|
2748
2799
|
assertHexString("serializedTx", serializedTx);
|
|
2749
2800
|
return params;
|
|
2750
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
|
+
}
|
|
2751
2821
|
function stripHexPrefix2(value) {
|
|
2752
2822
|
return value.startsWith("0x") || value.startsWith("0X") ? value.slice(2) : value;
|
|
2753
2823
|
}
|
|
@@ -7670,8 +7740,8 @@ var REQUIRED_DEVICE_CAPABILITIES = {
|
|
|
7670
7740
|
function normalizePassphraseMode(passphraseMode) {
|
|
7671
7741
|
if (passphraseMode === void 0) return "prompt";
|
|
7672
7742
|
if (passphraseMode === "prompt" || passphraseMode === "empty") return passphraseMode;
|
|
7673
|
-
throw (0,
|
|
7674
|
-
code:
|
|
7743
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
7744
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.InvalidParams,
|
|
7675
7745
|
message: `Invalid Trezor passphrase mode: ${String(passphraseMode)}`
|
|
7676
7746
|
});
|
|
7677
7747
|
}
|
|
@@ -7687,8 +7757,8 @@ var MAX_AUTHENTICITY_PROOF_PART_SIZE = 64 * 1024;
|
|
|
7687
7757
|
var MAX_AUTHENTICITY_CERTIFICATE_COUNT = 4;
|
|
7688
7758
|
var validateAuthenticityProofPartSize = (size) => {
|
|
7689
7759
|
if (typeof size !== "number" || !Number.isSafeInteger(size) || size < 0 || size > MAX_AUTHENTICITY_PROOF_PART_SIZE) {
|
|
7690
|
-
throw (0,
|
|
7691
|
-
code:
|
|
7760
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
7761
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UnknownError,
|
|
7692
7762
|
message: `Invalid Trezor authenticity proof part size: ${String(size)}`
|
|
7693
7763
|
});
|
|
7694
7764
|
}
|
|
@@ -7716,15 +7786,15 @@ var readAuthenticityProofPart = async ({
|
|
|
7716
7786
|
request
|
|
7717
7787
|
);
|
|
7718
7788
|
if (response.type !== "AuthenticityProofChunk") {
|
|
7719
|
-
throw (0,
|
|
7720
|
-
code:
|
|
7789
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
7790
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UnknownError,
|
|
7721
7791
|
message: `Expected AuthenticityProofChunk, received ${response.type}`
|
|
7722
7792
|
});
|
|
7723
7793
|
}
|
|
7724
7794
|
const chunk = response.message?.chunk;
|
|
7725
7795
|
if (typeof chunk !== "string" || chunk.length !== requestedSize * 2) {
|
|
7726
|
-
throw (0,
|
|
7727
|
-
code:
|
|
7796
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
7797
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UnknownError,
|
|
7728
7798
|
message: "Trezor returned an invalid authenticity proof chunk"
|
|
7729
7799
|
});
|
|
7730
7800
|
}
|
|
@@ -7736,14 +7806,14 @@ var readAuthenticityProofPart = async ({
|
|
|
7736
7806
|
var readAuthenticityProofStream = async (deviceSession, sizes) => {
|
|
7737
7807
|
const readCertificates = async (proofType, values) => {
|
|
7738
7808
|
if (!Array.isArray(values)) {
|
|
7739
|
-
throw (0,
|
|
7740
|
-
code:
|
|
7809
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
7810
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UnknownError,
|
|
7741
7811
|
message: "Trezor returned invalid authenticity certificate sizes"
|
|
7742
7812
|
});
|
|
7743
7813
|
}
|
|
7744
7814
|
if (values.length > MAX_AUTHENTICITY_CERTIFICATE_COUNT) {
|
|
7745
|
-
throw (0,
|
|
7746
|
-
code:
|
|
7815
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
7816
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UnknownError,
|
|
7747
7817
|
message: `Trezor authenticity proof contains too many certificates: ${values.length}`
|
|
7748
7818
|
});
|
|
7749
7819
|
}
|
|
@@ -7792,13 +7862,13 @@ var TrezorConnectorBase = class {
|
|
|
7792
7862
|
chunkSize;
|
|
7793
7863
|
thp;
|
|
7794
7864
|
// Single owned array — passed by reference into every TrezorThpSession via
|
|
7795
|
-
// `createThpOptions`.
|
|
7796
|
-
//
|
|
7797
|
-
//
|
|
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.
|
|
7798
7868
|
knownCredentials = [];
|
|
7799
7869
|
deviceSessionFactory;
|
|
7800
7870
|
eventHandlers = /* @__PURE__ */ new Map();
|
|
7801
|
-
uiRequests = new
|
|
7871
|
+
uiRequests = new import_hwk_adapter_core3.UiRequestRegistry();
|
|
7802
7872
|
devices = /* @__PURE__ */ new Map();
|
|
7803
7873
|
sessions = /* @__PURE__ */ new Map();
|
|
7804
7874
|
constructor(options = {}) {
|
|
@@ -7831,21 +7901,6 @@ var TrezorConnectorBase = class {
|
|
|
7831
7901
|
this.knownCredentials.push(...credentials);
|
|
7832
7902
|
}
|
|
7833
7903
|
}
|
|
7834
|
-
/**
|
|
7835
|
-
* Push new credentials minted during pairing into the in-memory array.
|
|
7836
|
-
* Deduplicates by the device-minted `credential` blob — the host has no
|
|
7837
|
-
* other stable identity for a credential.
|
|
7838
|
-
*/
|
|
7839
|
-
mergeKnownCredentials(incoming) {
|
|
7840
|
-
for (const cred of incoming) {
|
|
7841
|
-
const blob = cred.credential;
|
|
7842
|
-
if (!blob) continue;
|
|
7843
|
-
const exists2 = this.knownCredentials.some(
|
|
7844
|
-
(existing) => existing.credential === blob
|
|
7845
|
-
);
|
|
7846
|
-
if (!exists2) this.knownCredentials.push(cred);
|
|
7847
|
-
}
|
|
7848
|
-
}
|
|
7849
7904
|
resolveUnlistedDevice(_deviceId) {
|
|
7850
7905
|
return void 0;
|
|
7851
7906
|
}
|
|
@@ -7981,14 +8036,18 @@ var TrezorConnectorBase = class {
|
|
|
7981
8036
|
durationMs: Date.now() - startedAt,
|
|
7982
8037
|
error: errorToLog(error)
|
|
7983
8038
|
});
|
|
7984
|
-
|
|
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 };
|
|
7985
8044
|
}
|
|
7986
8045
|
}
|
|
7987
8046
|
async dispatchCall(sessionId, method, params) {
|
|
7988
8047
|
const session = this.sessions.get(sessionId);
|
|
7989
8048
|
if (!session) {
|
|
7990
|
-
throw (0,
|
|
7991
|
-
code:
|
|
8049
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8050
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.DeviceNotFound,
|
|
7992
8051
|
message: `Trezor session not found: ${sessionId}`
|
|
7993
8052
|
});
|
|
7994
8053
|
}
|
|
@@ -8041,8 +8100,8 @@ var TrezorConnectorBase = class {
|
|
|
8041
8100
|
return getTrezorResponseMessage(response);
|
|
8042
8101
|
}
|
|
8043
8102
|
if (response.type !== "AuthenticityProofSizes") {
|
|
8044
|
-
throw (0,
|
|
8045
|
-
code:
|
|
8103
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8104
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UnknownError,
|
|
8046
8105
|
message: `Expected Trezor authenticity proof, received ${response.type}`
|
|
8047
8106
|
});
|
|
8048
8107
|
}
|
|
@@ -8074,8 +8133,8 @@ var TrezorConnectorBase = class {
|
|
|
8074
8133
|
}
|
|
8075
8134
|
const p = params ?? {};
|
|
8076
8135
|
if (!p.thpSessionId) {
|
|
8077
|
-
throw (0,
|
|
8078
|
-
code:
|
|
8136
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8137
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.InvalidParams,
|
|
8079
8138
|
message: "__thpSelectSession requires a thpSessionId"
|
|
8080
8139
|
});
|
|
8081
8140
|
}
|
|
@@ -8120,8 +8179,8 @@ var TrezorConnectorBase = class {
|
|
|
8120
8179
|
case "tronSignMessage":
|
|
8121
8180
|
return tronSignMessage(ctx, params);
|
|
8122
8181
|
default:
|
|
8123
|
-
throw (0,
|
|
8124
|
-
code:
|
|
8182
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8183
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.MethodNotSupported,
|
|
8125
8184
|
message: `TrezorConnector: method "${method}" is not implemented`
|
|
8126
8185
|
});
|
|
8127
8186
|
}
|
|
@@ -8145,8 +8204,8 @@ var TrezorConnectorBase = class {
|
|
|
8145
8204
|
};
|
|
8146
8205
|
this.log(hasAllRequired ? "info" : "warn", "capability.check", checkPayload);
|
|
8147
8206
|
if (hasAllRequired) return;
|
|
8148
|
-
throw (0,
|
|
8149
|
-
code:
|
|
8207
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8208
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.MethodNotSupported,
|
|
8150
8209
|
message: `Trezor device is missing required capability for ${method}: ${required.map((capability) => capability.name).join(", ")}`,
|
|
8151
8210
|
params: {
|
|
8152
8211
|
method,
|
|
@@ -8158,7 +8217,7 @@ var TrezorConnectorBase = class {
|
|
|
8158
8217
|
async cancel(_sessionId) {
|
|
8159
8218
|
}
|
|
8160
8219
|
uiResponse(_response) {
|
|
8161
|
-
if (_response.type ===
|
|
8220
|
+
if (_response.type === import_hwk_adapter_core3.UI_RESPONSE.CANCEL) {
|
|
8162
8221
|
this.uiRequests.cancel();
|
|
8163
8222
|
return;
|
|
8164
8223
|
}
|
|
@@ -8204,8 +8263,8 @@ var TrezorConnectorBase = class {
|
|
|
8204
8263
|
return device;
|
|
8205
8264
|
}
|
|
8206
8265
|
if (!device) {
|
|
8207
|
-
throw (0,
|
|
8208
|
-
code:
|
|
8266
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8267
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.DeviceNotFound,
|
|
8209
8268
|
message: deviceId ? `Trezor device not found: ${deviceId}` : "No Trezor device found"
|
|
8210
8269
|
});
|
|
8211
8270
|
}
|
|
@@ -8223,8 +8282,9 @@ var TrezorConnectorBase = class {
|
|
|
8223
8282
|
if (this.thp?.onPairingRequest) {
|
|
8224
8283
|
return this.thp.onPairingRequest(payload);
|
|
8225
8284
|
}
|
|
8285
|
+
const pairingPromise = this.uiRequests.wait(import_hwk_adapter_core3.UI_REQUEST.REQUEST_TREZOR_THP_PAIRING);
|
|
8226
8286
|
this.emit("ui-request", {
|
|
8227
|
-
type:
|
|
8287
|
+
type: import_hwk_adapter_core3.UI_REQUEST.REQUEST_TREZOR_THP_PAIRING,
|
|
8228
8288
|
payload: {
|
|
8229
8289
|
connectId: device.connectId,
|
|
8230
8290
|
availableMethods: payload.availableMethods,
|
|
@@ -8232,12 +8292,12 @@ var TrezorConnectorBase = class {
|
|
|
8232
8292
|
nfcData: payload.nfcData
|
|
8233
8293
|
}
|
|
8234
8294
|
});
|
|
8235
|
-
return
|
|
8295
|
+
return pairingPromise;
|
|
8236
8296
|
},
|
|
8237
8297
|
onButtonRequest: async (payload) => {
|
|
8238
8298
|
await this.thp?.onButtonRequest?.(payload);
|
|
8239
8299
|
this.emit("ui-request", {
|
|
8240
|
-
type:
|
|
8300
|
+
type: import_hwk_adapter_core3.UI_REQUEST.REQUEST_BUTTON,
|
|
8241
8301
|
payload: {
|
|
8242
8302
|
connectId: device.connectId,
|
|
8243
8303
|
...payload
|
|
@@ -8246,20 +8306,19 @@ var TrezorConnectorBase = class {
|
|
|
8246
8306
|
},
|
|
8247
8307
|
onButtonRequestComplete: async (payload) => {
|
|
8248
8308
|
await this.thp?.onButtonRequestComplete?.(payload);
|
|
8309
|
+
if (payload.responseType === "ButtonRequest") return;
|
|
8249
8310
|
this.emit("ui-event", {
|
|
8250
|
-
type:
|
|
8251
|
-
payload: {
|
|
8252
|
-
sessionId: device.connectId
|
|
8253
|
-
}
|
|
8311
|
+
type: import_hwk_adapter_core3.EConnectorInteraction.InteractionComplete,
|
|
8312
|
+
payload: { sessionId: "" }
|
|
8254
8313
|
});
|
|
8255
8314
|
},
|
|
8256
8315
|
onPinMatrixRequest: async (payload) => {
|
|
8257
8316
|
if (this.thp?.onPinMatrixRequest) {
|
|
8258
8317
|
return this.thp.onPinMatrixRequest(payload);
|
|
8259
8318
|
}
|
|
8260
|
-
const pinPromise = this.uiRequests.wait(
|
|
8319
|
+
const pinPromise = this.uiRequests.wait(import_hwk_adapter_core3.UI_REQUEST.REQUEST_PIN);
|
|
8261
8320
|
this.emit("ui-request", {
|
|
8262
|
-
type:
|
|
8321
|
+
type: import_hwk_adapter_core3.UI_REQUEST.REQUEST_PIN,
|
|
8263
8322
|
payload: {
|
|
8264
8323
|
connectId: device.connectId,
|
|
8265
8324
|
type: payload.type
|
|
@@ -8271,9 +8330,9 @@ var TrezorConnectorBase = class {
|
|
|
8271
8330
|
if (this.thp?.onPassphraseRequest) {
|
|
8272
8331
|
return this.thp.onPassphraseRequest(payload);
|
|
8273
8332
|
}
|
|
8274
|
-
const passphrasePromise = this.uiRequests.wait(
|
|
8333
|
+
const passphrasePromise = this.uiRequests.wait(import_hwk_adapter_core3.UI_REQUEST.REQUEST_PASSPHRASE);
|
|
8275
8334
|
this.emit("ui-request", {
|
|
8276
|
-
type:
|
|
8335
|
+
type: import_hwk_adapter_core3.UI_REQUEST.REQUEST_PASSPHRASE,
|
|
8277
8336
|
payload: {
|
|
8278
8337
|
connectId: device.connectId,
|
|
8279
8338
|
...payload
|
|
@@ -8283,12 +8342,21 @@ var TrezorConnectorBase = class {
|
|
|
8283
8342
|
return res?.passphraseOnDevice ? { on_device: true } : { passphrase: res?.value ?? "" };
|
|
8284
8343
|
},
|
|
8285
8344
|
onPairingCredentialsChanged: async (payload) => {
|
|
8286
|
-
|
|
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);
|
|
8287
8354
|
await this.thp?.onPairingCredentialsChanged?.(payload);
|
|
8288
8355
|
this.emit("device-trezor-thp-credentials-changed", {
|
|
8289
8356
|
connectId: device.connectId,
|
|
8290
8357
|
deviceId: device.deviceId,
|
|
8291
|
-
credentials: payload.credentials
|
|
8358
|
+
credentials: payload.credentials,
|
|
8359
|
+
removed: payload.removed
|
|
8292
8360
|
});
|
|
8293
8361
|
}
|
|
8294
8362
|
};
|
|
@@ -8304,7 +8372,7 @@ var TrezorConnectorBase = class {
|
|
|
8304
8372
|
emitSupportFeatures(session) {
|
|
8305
8373
|
const features = session.deviceSession.features ?? session.features;
|
|
8306
8374
|
session.features = features;
|
|
8307
|
-
this.emit(
|
|
8375
|
+
this.emit(import_hwk_adapter_core3.DEVICE.FEATURES, {
|
|
8308
8376
|
device: {
|
|
8309
8377
|
...session.device,
|
|
8310
8378
|
deviceId: readString(features, "device_id") ?? session.device.deviceId,
|
|
@@ -8327,9 +8395,9 @@ function connectorSessionToDevice(session) {
|
|
|
8327
8395
|
};
|
|
8328
8396
|
}
|
|
8329
8397
|
function rejectKnownNonTrezorDevice(features) {
|
|
8330
|
-
if (!(0,
|
|
8331
|
-
throw (0,
|
|
8332
|
-
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,
|
|
8333
8401
|
message: "Selected device is not a supported Trezor device.",
|
|
8334
8402
|
params: {
|
|
8335
8403
|
vendor: features.vendor,
|