@onekeyfe/hwk-trezor-connector 1.2.8-alpha.4 → 1.2.8-alpha.50
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 +139 -75
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +100 -36
- 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,14 @@ var TrezorConnectorBase = class {
|
|
|
7979
8034
|
durationMs: Date.now() - startedAt,
|
|
7980
8035
|
error: errorToLog(error)
|
|
7981
8036
|
});
|
|
7982
|
-
return { success: false, error: (0,
|
|
8037
|
+
return { success: false, error: (0, import_hwk_adapter_core3.serializeConnectorError)(error) };
|
|
7983
8038
|
}
|
|
7984
8039
|
}
|
|
7985
8040
|
async dispatchCall(sessionId, method, params) {
|
|
7986
8041
|
const session = this.sessions.get(sessionId);
|
|
7987
8042
|
if (!session) {
|
|
7988
|
-
throw (0,
|
|
7989
|
-
code:
|
|
8043
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8044
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.DeviceNotFound,
|
|
7990
8045
|
message: `Trezor session not found: ${sessionId}`
|
|
7991
8046
|
});
|
|
7992
8047
|
}
|
|
@@ -8039,8 +8094,8 @@ var TrezorConnectorBase = class {
|
|
|
8039
8094
|
return getTrezorResponseMessage(response);
|
|
8040
8095
|
}
|
|
8041
8096
|
if (response.type !== "AuthenticityProofSizes") {
|
|
8042
|
-
throw (0,
|
|
8043
|
-
code:
|
|
8097
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8098
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UnknownError,
|
|
8044
8099
|
message: `Expected Trezor authenticity proof, received ${response.type}`
|
|
8045
8100
|
});
|
|
8046
8101
|
}
|
|
@@ -8072,8 +8127,8 @@ var TrezorConnectorBase = class {
|
|
|
8072
8127
|
}
|
|
8073
8128
|
const p = params ?? {};
|
|
8074
8129
|
if (!p.thpSessionId) {
|
|
8075
|
-
throw (0,
|
|
8076
|
-
code:
|
|
8130
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8131
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.InvalidParams,
|
|
8077
8132
|
message: "__thpSelectSession requires a thpSessionId"
|
|
8078
8133
|
});
|
|
8079
8134
|
}
|
|
@@ -8118,8 +8173,8 @@ var TrezorConnectorBase = class {
|
|
|
8118
8173
|
case "tronSignMessage":
|
|
8119
8174
|
return tronSignMessage(ctx, params);
|
|
8120
8175
|
default:
|
|
8121
|
-
throw (0,
|
|
8122
|
-
code:
|
|
8176
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8177
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.MethodNotSupported,
|
|
8123
8178
|
message: `TrezorConnector: method "${method}" is not implemented`
|
|
8124
8179
|
});
|
|
8125
8180
|
}
|
|
@@ -8143,8 +8198,8 @@ var TrezorConnectorBase = class {
|
|
|
8143
8198
|
};
|
|
8144
8199
|
this.log(hasAllRequired ? "info" : "warn", "capability.check", checkPayload);
|
|
8145
8200
|
if (hasAllRequired) return;
|
|
8146
|
-
throw (0,
|
|
8147
|
-
code:
|
|
8201
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8202
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.MethodNotSupported,
|
|
8148
8203
|
message: `Trezor device is missing required capability for ${method}: ${required.map((capability) => capability.name).join(", ")}`,
|
|
8149
8204
|
params: {
|
|
8150
8205
|
method,
|
|
@@ -8156,7 +8211,7 @@ var TrezorConnectorBase = class {
|
|
|
8156
8211
|
async cancel(_sessionId) {
|
|
8157
8212
|
}
|
|
8158
8213
|
uiResponse(_response) {
|
|
8159
|
-
if (_response.type ===
|
|
8214
|
+
if (_response.type === import_hwk_adapter_core3.UI_RESPONSE.CANCEL) {
|
|
8160
8215
|
this.uiRequests.cancel();
|
|
8161
8216
|
return;
|
|
8162
8217
|
}
|
|
@@ -8202,8 +8257,8 @@ var TrezorConnectorBase = class {
|
|
|
8202
8257
|
return device;
|
|
8203
8258
|
}
|
|
8204
8259
|
if (!device) {
|
|
8205
|
-
throw (0,
|
|
8206
|
-
code:
|
|
8260
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8261
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.DeviceNotFound,
|
|
8207
8262
|
message: deviceId ? `Trezor device not found: ${deviceId}` : "No Trezor device found"
|
|
8208
8263
|
});
|
|
8209
8264
|
}
|
|
@@ -8221,8 +8276,9 @@ var TrezorConnectorBase = class {
|
|
|
8221
8276
|
if (this.thp?.onPairingRequest) {
|
|
8222
8277
|
return this.thp.onPairingRequest(payload);
|
|
8223
8278
|
}
|
|
8279
|
+
const pairingPromise = this.uiRequests.wait(import_hwk_adapter_core3.UI_REQUEST.REQUEST_TREZOR_THP_PAIRING);
|
|
8224
8280
|
this.emit("ui-request", {
|
|
8225
|
-
type:
|
|
8281
|
+
type: import_hwk_adapter_core3.UI_REQUEST.REQUEST_TREZOR_THP_PAIRING,
|
|
8226
8282
|
payload: {
|
|
8227
8283
|
connectId: device.connectId,
|
|
8228
8284
|
availableMethods: payload.availableMethods,
|
|
@@ -8230,12 +8286,12 @@ var TrezorConnectorBase = class {
|
|
|
8230
8286
|
nfcData: payload.nfcData
|
|
8231
8287
|
}
|
|
8232
8288
|
});
|
|
8233
|
-
return
|
|
8289
|
+
return pairingPromise;
|
|
8234
8290
|
},
|
|
8235
8291
|
onButtonRequest: async (payload) => {
|
|
8236
8292
|
await this.thp?.onButtonRequest?.(payload);
|
|
8237
8293
|
this.emit("ui-request", {
|
|
8238
|
-
type:
|
|
8294
|
+
type: import_hwk_adapter_core3.UI_REQUEST.REQUEST_BUTTON,
|
|
8239
8295
|
payload: {
|
|
8240
8296
|
connectId: device.connectId,
|
|
8241
8297
|
...payload
|
|
@@ -8244,20 +8300,19 @@ var TrezorConnectorBase = class {
|
|
|
8244
8300
|
},
|
|
8245
8301
|
onButtonRequestComplete: async (payload) => {
|
|
8246
8302
|
await this.thp?.onButtonRequestComplete?.(payload);
|
|
8303
|
+
if (payload.responseType === "ButtonRequest") return;
|
|
8247
8304
|
this.emit("ui-event", {
|
|
8248
|
-
type:
|
|
8249
|
-
payload: {
|
|
8250
|
-
sessionId: device.connectId
|
|
8251
|
-
}
|
|
8305
|
+
type: import_hwk_adapter_core3.EConnectorInteraction.InteractionComplete,
|
|
8306
|
+
payload: { sessionId: "" }
|
|
8252
8307
|
});
|
|
8253
8308
|
},
|
|
8254
8309
|
onPinMatrixRequest: async (payload) => {
|
|
8255
8310
|
if (this.thp?.onPinMatrixRequest) {
|
|
8256
8311
|
return this.thp.onPinMatrixRequest(payload);
|
|
8257
8312
|
}
|
|
8258
|
-
const pinPromise = this.uiRequests.wait(
|
|
8313
|
+
const pinPromise = this.uiRequests.wait(import_hwk_adapter_core3.UI_REQUEST.REQUEST_PIN);
|
|
8259
8314
|
this.emit("ui-request", {
|
|
8260
|
-
type:
|
|
8315
|
+
type: import_hwk_adapter_core3.UI_REQUEST.REQUEST_PIN,
|
|
8261
8316
|
payload: {
|
|
8262
8317
|
connectId: device.connectId,
|
|
8263
8318
|
type: payload.type
|
|
@@ -8269,9 +8324,9 @@ var TrezorConnectorBase = class {
|
|
|
8269
8324
|
if (this.thp?.onPassphraseRequest) {
|
|
8270
8325
|
return this.thp.onPassphraseRequest(payload);
|
|
8271
8326
|
}
|
|
8272
|
-
const passphrasePromise = this.uiRequests.wait(
|
|
8327
|
+
const passphrasePromise = this.uiRequests.wait(import_hwk_adapter_core3.UI_REQUEST.REQUEST_PASSPHRASE);
|
|
8273
8328
|
this.emit("ui-request", {
|
|
8274
|
-
type:
|
|
8329
|
+
type: import_hwk_adapter_core3.UI_REQUEST.REQUEST_PASSPHRASE,
|
|
8275
8330
|
payload: {
|
|
8276
8331
|
connectId: device.connectId,
|
|
8277
8332
|
...payload
|
|
@@ -8281,12 +8336,21 @@ var TrezorConnectorBase = class {
|
|
|
8281
8336
|
return res?.passphraseOnDevice ? { on_device: true } : { passphrase: res?.value ?? "" };
|
|
8282
8337
|
},
|
|
8283
8338
|
onPairingCredentialsChanged: async (payload) => {
|
|
8284
|
-
|
|
8339
|
+
const blob = (cred) => cred.credential;
|
|
8340
|
+
const rejected = new Set((payload.removed ?? []).map(blob));
|
|
8341
|
+
const merged = this.knownCredentials.filter((cred) => !rejected.has(blob(cred)));
|
|
8342
|
+
for (const cred of payload.credentials) {
|
|
8343
|
+
if (blob(cred) && !merged.some((existing) => blob(existing) === blob(cred))) {
|
|
8344
|
+
merged.push(cred);
|
|
8345
|
+
}
|
|
8346
|
+
}
|
|
8347
|
+
this.setKnownCredentials(merged);
|
|
8285
8348
|
await this.thp?.onPairingCredentialsChanged?.(payload);
|
|
8286
8349
|
this.emit("device-trezor-thp-credentials-changed", {
|
|
8287
8350
|
connectId: device.connectId,
|
|
8288
8351
|
deviceId: device.deviceId,
|
|
8289
|
-
credentials: payload.credentials
|
|
8352
|
+
credentials: payload.credentials,
|
|
8353
|
+
removed: payload.removed
|
|
8290
8354
|
});
|
|
8291
8355
|
}
|
|
8292
8356
|
};
|
|
@@ -8302,7 +8366,7 @@ var TrezorConnectorBase = class {
|
|
|
8302
8366
|
emitSupportFeatures(session) {
|
|
8303
8367
|
const features = session.deviceSession.features ?? session.features;
|
|
8304
8368
|
session.features = features;
|
|
8305
|
-
this.emit(
|
|
8369
|
+
this.emit(import_hwk_adapter_core3.DEVICE.FEATURES, {
|
|
8306
8370
|
device: {
|
|
8307
8371
|
...session.device,
|
|
8308
8372
|
deviceId: readString(features, "device_id") ?? session.device.deviceId,
|
|
@@ -8325,9 +8389,9 @@ function connectorSessionToDevice(session) {
|
|
|
8325
8389
|
};
|
|
8326
8390
|
}
|
|
8327
8391
|
function rejectKnownNonTrezorDevice(features) {
|
|
8328
|
-
if (!(0,
|
|
8329
|
-
throw (0,
|
|
8330
|
-
code:
|
|
8392
|
+
if (!(0, import_hwk_adapter_core3.isKnownNonTargetHardwareVendor)(features, "trezor")) return;
|
|
8393
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
8394
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.DeviceMismatch,
|
|
8331
8395
|
message: "Selected device is not a supported Trezor device.",
|
|
8332
8396
|
params: {
|
|
8333
8397
|
vendor: features.vendor,
|