@onekeyfe/hwk-trezor-connector 1.2.8-alpha.1 → 1.2.8-alpha.3
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 +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +74 -137
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -98
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -44,6 +44,12 @@ 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;
|
|
47
53
|
protected abstract enumerateDevices(): Promise<ConnectorDevice[]>;
|
|
48
54
|
protected abstract createByteTransport(device: ConnectorDevice): Promise<TrezorConnectorByteTransport>;
|
|
49
55
|
protected resolveUnlistedDevice(_deviceId: string): ConnectorDevice | undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -44,6 +44,12 @@ 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;
|
|
47
53
|
protected abstract enumerateDevices(): Promise<ConnectorDevice[]>;
|
|
48
54
|
protected abstract createByteTransport(device: ConnectorDevice): Promise<TrezorConnectorByteTransport>;
|
|
49
55
|
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_core2 = 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,12 +89,14 @@ var BTC_SCRIPT_TYPE_MAP = {
|
|
|
89
89
|
p2pkh: "SPENDADDRESS",
|
|
90
90
|
p2sh: "SPENDP2SHWITNESS",
|
|
91
91
|
p2wpkh: "SPENDWITNESS",
|
|
92
|
+
p2wsh: "SPENDWITNESS",
|
|
92
93
|
p2tr: "SPENDTAPROOT"
|
|
93
94
|
};
|
|
94
95
|
var BTC_CHANGE_OUTPUT_SCRIPT_TYPE_MAP = {
|
|
95
96
|
p2pkh: "PAYTOADDRESS",
|
|
96
97
|
p2sh: "PAYTOP2SHWITNESS",
|
|
97
98
|
p2wpkh: "PAYTOWITNESS",
|
|
99
|
+
p2wsh: "PAYTOWITNESS",
|
|
98
100
|
p2tr: "PAYTOTAPROOT"
|
|
99
101
|
};
|
|
100
102
|
var BTC_COIN_NAME_ALIASES = {
|
|
@@ -118,8 +120,7 @@ function normalizeBtcCoin(coin) {
|
|
|
118
120
|
return BTC_COIN_NAME_ALIASES[coin.toLowerCase()] ?? coin;
|
|
119
121
|
}
|
|
120
122
|
function deriveScriptTypeFromPath(path) {
|
|
121
|
-
const
|
|
122
|
-
const normalized = /^m\//i.test(trimmed) ? trimmed.slice(2) : trimmed;
|
|
123
|
+
const normalized = path.startsWith("m/") ? path.slice(2) : path;
|
|
123
124
|
const purpose = normalized.split("/")[0]?.replace(/['hH]$/, "");
|
|
124
125
|
switch (purpose) {
|
|
125
126
|
case "86":
|
|
@@ -131,22 +132,8 @@ function deriveScriptTypeFromPath(path) {
|
|
|
131
132
|
case "44":
|
|
132
133
|
return "p2pkh";
|
|
133
134
|
default:
|
|
134
|
-
return
|
|
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
|
-
);
|
|
135
|
+
return "p2wpkh";
|
|
148
136
|
}
|
|
149
|
-
return map[resolved];
|
|
150
137
|
}
|
|
151
138
|
async function btcGetAddress(ctx, params) {
|
|
152
139
|
const request = readBtcGetAddressParams(params);
|
|
@@ -154,7 +141,7 @@ async function btcGetAddress(ctx, params) {
|
|
|
154
141
|
address_n: parseBip32Path(request.path),
|
|
155
142
|
coin_name: normalizeBtcCoin(request.coin),
|
|
156
143
|
show_display: request.showOnDevice ?? false,
|
|
157
|
-
script_type:
|
|
144
|
+
script_type: BTC_SCRIPT_TYPE_MAP[request.scriptType ?? deriveScriptTypeFromPath(request.path)]
|
|
158
145
|
});
|
|
159
146
|
if (response.type !== "Address") {
|
|
160
147
|
throw new Error(`Expected Address response, received ${response.type}`);
|
|
@@ -187,7 +174,7 @@ async function btcSignMessage(ctx, params) {
|
|
|
187
174
|
address_n: parseBip32Path(request.path),
|
|
188
175
|
message: normalizeBtcMessage(request.message, request.hex ?? false),
|
|
189
176
|
coin_name: normalizeBtcCoin(request.coin),
|
|
190
|
-
script_type:
|
|
177
|
+
script_type: BTC_SCRIPT_TYPE_MAP[deriveScriptTypeFromPath(request.path)]
|
|
191
178
|
};
|
|
192
179
|
if (request.noScriptType) {
|
|
193
180
|
message.no_script_type = true;
|
|
@@ -432,7 +419,7 @@ function inputToTrezor(input) {
|
|
|
432
419
|
prev_hash: input.prevHash,
|
|
433
420
|
prev_index: input.prevIndex,
|
|
434
421
|
amount: input.amount,
|
|
435
|
-
script_type:
|
|
422
|
+
script_type: BTC_SCRIPT_TYPE_MAP[input.scriptType ?? deriveScriptTypeFromPath(input.path)]
|
|
436
423
|
};
|
|
437
424
|
if (input.sequence !== void 0) result.sequence = input.sequence;
|
|
438
425
|
if (input.origHash !== void 0) result.orig_hash = input.origHash;
|
|
@@ -484,11 +471,7 @@ function outputToTrezor(output2) {
|
|
|
484
471
|
return withOutputMetadata({
|
|
485
472
|
address_n: parseBip32Path(output2.path),
|
|
486
473
|
amount: output2.amount,
|
|
487
|
-
script_type:
|
|
488
|
-
BTC_CHANGE_OUTPUT_SCRIPT_TYPE_MAP,
|
|
489
|
-
output2.scriptType,
|
|
490
|
-
output2.path
|
|
491
|
-
)
|
|
474
|
+
script_type: BTC_CHANGE_OUTPUT_SCRIPT_TYPE_MAP[output2.scriptType ?? deriveScriptTypeFromPath(output2.path)]
|
|
492
475
|
});
|
|
493
476
|
}
|
|
494
477
|
throw createInvalidParamsError(
|
|
@@ -679,12 +662,6 @@ function readBtcGetAddressParams(params) {
|
|
|
679
662
|
if (typeof path !== "string" || path.trim().length === 0) {
|
|
680
663
|
throw createInvalidParamsError("btcGetAddress requires a non-empty path");
|
|
681
664
|
}
|
|
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
|
-
}
|
|
688
665
|
const { coin } = params;
|
|
689
666
|
if (coin !== void 0 && typeof coin !== "string") {
|
|
690
667
|
throw createInvalidParamsError("btcGetAddress coin must be a string when provided");
|
|
@@ -2689,7 +2666,6 @@ function normalizeEthMessage(message, isHex) {
|
|
|
2689
2666
|
}
|
|
2690
2667
|
|
|
2691
2668
|
// src/chains/sol.ts
|
|
2692
|
-
var import_hwk_adapter_core2 = require("@onekeyfe/hwk-adapter-core");
|
|
2693
2669
|
async function solGetAddress(ctx, params) {
|
|
2694
2670
|
const request = readSolGetAddressParams(params);
|
|
2695
2671
|
const response = await ctx.deviceSession.call("SolanaGetAddress", {
|
|
@@ -2736,37 +2712,10 @@ async function solSignTransaction(ctx, params) {
|
|
|
2736
2712
|
}
|
|
2737
2713
|
return { signature };
|
|
2738
2714
|
}
|
|
2739
|
-
async function solSignMessage(
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
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() };
|
|
2715
|
+
async function solSignMessage(_ctx, _params) {
|
|
2716
|
+
throw createMethodNotSupportedError(
|
|
2717
|
+
"Trezor firmware does not support Solana message signing \u2014 only solSignTransaction is available"
|
|
2718
|
+
);
|
|
2770
2719
|
}
|
|
2771
2720
|
function readSolGetAddressParams(params) {
|
|
2772
2721
|
if (!params || typeof params !== "object") {
|
|
@@ -2797,25 +2746,6 @@ function readSolSignTxParams(params) {
|
|
|
2797
2746
|
assertHexString("serializedTx", serializedTx);
|
|
2798
2747
|
return params;
|
|
2799
2748
|
}
|
|
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
|
-
}
|
|
2819
2749
|
function stripHexPrefix2(value) {
|
|
2820
2750
|
return value.startsWith("0x") || value.startsWith("0X") ? value.slice(2) : value;
|
|
2821
2751
|
}
|
|
@@ -7738,8 +7668,8 @@ var REQUIRED_DEVICE_CAPABILITIES = {
|
|
|
7738
7668
|
function normalizePassphraseMode(passphraseMode) {
|
|
7739
7669
|
if (passphraseMode === void 0) return "prompt";
|
|
7740
7670
|
if (passphraseMode === "prompt" || passphraseMode === "empty") return passphraseMode;
|
|
7741
|
-
throw (0,
|
|
7742
|
-
code:
|
|
7671
|
+
throw (0, import_hwk_adapter_core2.createHwkError)({
|
|
7672
|
+
code: import_hwk_adapter_core2.HardwareErrorCode.InvalidParams,
|
|
7743
7673
|
message: `Invalid Trezor passphrase mode: ${String(passphraseMode)}`
|
|
7744
7674
|
});
|
|
7745
7675
|
}
|
|
@@ -7755,8 +7685,8 @@ var MAX_AUTHENTICITY_PROOF_PART_SIZE = 64 * 1024;
|
|
|
7755
7685
|
var MAX_AUTHENTICITY_CERTIFICATE_COUNT = 4;
|
|
7756
7686
|
var validateAuthenticityProofPartSize = (size) => {
|
|
7757
7687
|
if (typeof size !== "number" || !Number.isSafeInteger(size) || size < 0 || size > MAX_AUTHENTICITY_PROOF_PART_SIZE) {
|
|
7758
|
-
throw (0,
|
|
7759
|
-
code:
|
|
7688
|
+
throw (0, import_hwk_adapter_core2.createHwkError)({
|
|
7689
|
+
code: import_hwk_adapter_core2.HardwareErrorCode.UnknownError,
|
|
7760
7690
|
message: `Invalid Trezor authenticity proof part size: ${String(size)}`
|
|
7761
7691
|
});
|
|
7762
7692
|
}
|
|
@@ -7784,15 +7714,15 @@ var readAuthenticityProofPart = async ({
|
|
|
7784
7714
|
request
|
|
7785
7715
|
);
|
|
7786
7716
|
if (response.type !== "AuthenticityProofChunk") {
|
|
7787
|
-
throw (0,
|
|
7788
|
-
code:
|
|
7717
|
+
throw (0, import_hwk_adapter_core2.createHwkError)({
|
|
7718
|
+
code: import_hwk_adapter_core2.HardwareErrorCode.UnknownError,
|
|
7789
7719
|
message: `Expected AuthenticityProofChunk, received ${response.type}`
|
|
7790
7720
|
});
|
|
7791
7721
|
}
|
|
7792
7722
|
const chunk = response.message?.chunk;
|
|
7793
7723
|
if (typeof chunk !== "string" || chunk.length !== requestedSize * 2) {
|
|
7794
|
-
throw (0,
|
|
7795
|
-
code:
|
|
7724
|
+
throw (0, import_hwk_adapter_core2.createHwkError)({
|
|
7725
|
+
code: import_hwk_adapter_core2.HardwareErrorCode.UnknownError,
|
|
7796
7726
|
message: "Trezor returned an invalid authenticity proof chunk"
|
|
7797
7727
|
});
|
|
7798
7728
|
}
|
|
@@ -7804,14 +7734,14 @@ var readAuthenticityProofPart = async ({
|
|
|
7804
7734
|
var readAuthenticityProofStream = async (deviceSession, sizes) => {
|
|
7805
7735
|
const readCertificates = async (proofType, values) => {
|
|
7806
7736
|
if (!Array.isArray(values)) {
|
|
7807
|
-
throw (0,
|
|
7808
|
-
code:
|
|
7737
|
+
throw (0, import_hwk_adapter_core2.createHwkError)({
|
|
7738
|
+
code: import_hwk_adapter_core2.HardwareErrorCode.UnknownError,
|
|
7809
7739
|
message: "Trezor returned invalid authenticity certificate sizes"
|
|
7810
7740
|
});
|
|
7811
7741
|
}
|
|
7812
7742
|
if (values.length > MAX_AUTHENTICITY_CERTIFICATE_COUNT) {
|
|
7813
|
-
throw (0,
|
|
7814
|
-
code:
|
|
7743
|
+
throw (0, import_hwk_adapter_core2.createHwkError)({
|
|
7744
|
+
code: import_hwk_adapter_core2.HardwareErrorCode.UnknownError,
|
|
7815
7745
|
message: `Trezor authenticity proof contains too many certificates: ${values.length}`
|
|
7816
7746
|
});
|
|
7817
7747
|
}
|
|
@@ -7860,13 +7790,13 @@ var TrezorConnectorBase = class {
|
|
|
7860
7790
|
chunkSize;
|
|
7861
7791
|
thp;
|
|
7862
7792
|
// Single owned array — passed by reference into every TrezorThpSession via
|
|
7863
|
-
// `createThpOptions`.
|
|
7864
|
-
//
|
|
7865
|
-
// without a connector rebuild.
|
|
7793
|
+
// `createThpOptions`. setKnownCredentials() and the auto-merge inside
|
|
7794
|
+
// onPairingCredentialsChanged both mutate this array in-place so the next
|
|
7795
|
+
// handshake sees fresh credentials without a connector rebuild.
|
|
7866
7796
|
knownCredentials = [];
|
|
7867
7797
|
deviceSessionFactory;
|
|
7868
7798
|
eventHandlers = /* @__PURE__ */ new Map();
|
|
7869
|
-
uiRequests = new
|
|
7799
|
+
uiRequests = new import_hwk_adapter_core2.UiRequestRegistry();
|
|
7870
7800
|
devices = /* @__PURE__ */ new Map();
|
|
7871
7801
|
sessions = /* @__PURE__ */ new Map();
|
|
7872
7802
|
constructor(options = {}) {
|
|
@@ -7899,6 +7829,21 @@ var TrezorConnectorBase = class {
|
|
|
7899
7829
|
this.knownCredentials.push(...credentials);
|
|
7900
7830
|
}
|
|
7901
7831
|
}
|
|
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
|
+
}
|
|
7902
7847
|
resolveUnlistedDevice(_deviceId) {
|
|
7903
7848
|
return void 0;
|
|
7904
7849
|
}
|
|
@@ -8034,14 +7979,14 @@ var TrezorConnectorBase = class {
|
|
|
8034
7979
|
durationMs: Date.now() - startedAt,
|
|
8035
7980
|
error: errorToLog(error)
|
|
8036
7981
|
});
|
|
8037
|
-
return { success: false, error: (0,
|
|
7982
|
+
return { success: false, error: (0, import_hwk_adapter_core2.serializeConnectorError)(error) };
|
|
8038
7983
|
}
|
|
8039
7984
|
}
|
|
8040
7985
|
async dispatchCall(sessionId, method, params) {
|
|
8041
7986
|
const session = this.sessions.get(sessionId);
|
|
8042
7987
|
if (!session) {
|
|
8043
|
-
throw (0,
|
|
8044
|
-
code:
|
|
7988
|
+
throw (0, import_hwk_adapter_core2.createHwkError)({
|
|
7989
|
+
code: import_hwk_adapter_core2.HardwareErrorCode.DeviceNotFound,
|
|
8045
7990
|
message: `Trezor session not found: ${sessionId}`
|
|
8046
7991
|
});
|
|
8047
7992
|
}
|
|
@@ -8094,8 +8039,8 @@ var TrezorConnectorBase = class {
|
|
|
8094
8039
|
return getTrezorResponseMessage(response);
|
|
8095
8040
|
}
|
|
8096
8041
|
if (response.type !== "AuthenticityProofSizes") {
|
|
8097
|
-
throw (0,
|
|
8098
|
-
code:
|
|
8042
|
+
throw (0, import_hwk_adapter_core2.createHwkError)({
|
|
8043
|
+
code: import_hwk_adapter_core2.HardwareErrorCode.UnknownError,
|
|
8099
8044
|
message: `Expected Trezor authenticity proof, received ${response.type}`
|
|
8100
8045
|
});
|
|
8101
8046
|
}
|
|
@@ -8127,8 +8072,8 @@ var TrezorConnectorBase = class {
|
|
|
8127
8072
|
}
|
|
8128
8073
|
const p = params ?? {};
|
|
8129
8074
|
if (!p.thpSessionId) {
|
|
8130
|
-
throw (0,
|
|
8131
|
-
code:
|
|
8075
|
+
throw (0, import_hwk_adapter_core2.createHwkError)({
|
|
8076
|
+
code: import_hwk_adapter_core2.HardwareErrorCode.InvalidParams,
|
|
8132
8077
|
message: "__thpSelectSession requires a thpSessionId"
|
|
8133
8078
|
});
|
|
8134
8079
|
}
|
|
@@ -8173,8 +8118,8 @@ var TrezorConnectorBase = class {
|
|
|
8173
8118
|
case "tronSignMessage":
|
|
8174
8119
|
return tronSignMessage(ctx, params);
|
|
8175
8120
|
default:
|
|
8176
|
-
throw (0,
|
|
8177
|
-
code:
|
|
8121
|
+
throw (0, import_hwk_adapter_core2.createHwkError)({
|
|
8122
|
+
code: import_hwk_adapter_core2.HardwareErrorCode.MethodNotSupported,
|
|
8178
8123
|
message: `TrezorConnector: method "${method}" is not implemented`
|
|
8179
8124
|
});
|
|
8180
8125
|
}
|
|
@@ -8198,8 +8143,8 @@ var TrezorConnectorBase = class {
|
|
|
8198
8143
|
};
|
|
8199
8144
|
this.log(hasAllRequired ? "info" : "warn", "capability.check", checkPayload);
|
|
8200
8145
|
if (hasAllRequired) return;
|
|
8201
|
-
throw (0,
|
|
8202
|
-
code:
|
|
8146
|
+
throw (0, import_hwk_adapter_core2.createHwkError)({
|
|
8147
|
+
code: import_hwk_adapter_core2.HardwareErrorCode.MethodNotSupported,
|
|
8203
8148
|
message: `Trezor device is missing required capability for ${method}: ${required.map((capability) => capability.name).join(", ")}`,
|
|
8204
8149
|
params: {
|
|
8205
8150
|
method,
|
|
@@ -8211,7 +8156,7 @@ var TrezorConnectorBase = class {
|
|
|
8211
8156
|
async cancel(_sessionId) {
|
|
8212
8157
|
}
|
|
8213
8158
|
uiResponse(_response) {
|
|
8214
|
-
if (_response.type ===
|
|
8159
|
+
if (_response.type === import_hwk_adapter_core2.UI_RESPONSE.CANCEL) {
|
|
8215
8160
|
this.uiRequests.cancel();
|
|
8216
8161
|
return;
|
|
8217
8162
|
}
|
|
@@ -8257,8 +8202,8 @@ var TrezorConnectorBase = class {
|
|
|
8257
8202
|
return device;
|
|
8258
8203
|
}
|
|
8259
8204
|
if (!device) {
|
|
8260
|
-
throw (0,
|
|
8261
|
-
code:
|
|
8205
|
+
throw (0, import_hwk_adapter_core2.createHwkError)({
|
|
8206
|
+
code: import_hwk_adapter_core2.HardwareErrorCode.DeviceNotFound,
|
|
8262
8207
|
message: deviceId ? `Trezor device not found: ${deviceId}` : "No Trezor device found"
|
|
8263
8208
|
});
|
|
8264
8209
|
}
|
|
@@ -8276,9 +8221,8 @@ var TrezorConnectorBase = class {
|
|
|
8276
8221
|
if (this.thp?.onPairingRequest) {
|
|
8277
8222
|
return this.thp.onPairingRequest(payload);
|
|
8278
8223
|
}
|
|
8279
|
-
const pairingPromise = this.uiRequests.wait(import_hwk_adapter_core3.UI_REQUEST.REQUEST_TREZOR_THP_PAIRING);
|
|
8280
8224
|
this.emit("ui-request", {
|
|
8281
|
-
type:
|
|
8225
|
+
type: import_hwk_adapter_core2.UI_REQUEST.REQUEST_TREZOR_THP_PAIRING,
|
|
8282
8226
|
payload: {
|
|
8283
8227
|
connectId: device.connectId,
|
|
8284
8228
|
availableMethods: payload.availableMethods,
|
|
@@ -8286,12 +8230,12 @@ var TrezorConnectorBase = class {
|
|
|
8286
8230
|
nfcData: payload.nfcData
|
|
8287
8231
|
}
|
|
8288
8232
|
});
|
|
8289
|
-
return
|
|
8233
|
+
return this.uiRequests.wait(import_hwk_adapter_core2.UI_REQUEST.REQUEST_TREZOR_THP_PAIRING);
|
|
8290
8234
|
},
|
|
8291
8235
|
onButtonRequest: async (payload) => {
|
|
8292
8236
|
await this.thp?.onButtonRequest?.(payload);
|
|
8293
8237
|
this.emit("ui-request", {
|
|
8294
|
-
type:
|
|
8238
|
+
type: import_hwk_adapter_core2.UI_REQUEST.REQUEST_BUTTON,
|
|
8295
8239
|
payload: {
|
|
8296
8240
|
connectId: device.connectId,
|
|
8297
8241
|
...payload
|
|
@@ -8300,19 +8244,20 @@ var TrezorConnectorBase = class {
|
|
|
8300
8244
|
},
|
|
8301
8245
|
onButtonRequestComplete: async (payload) => {
|
|
8302
8246
|
await this.thp?.onButtonRequestComplete?.(payload);
|
|
8303
|
-
if (payload.responseType === "ButtonRequest") return;
|
|
8304
8247
|
this.emit("ui-event", {
|
|
8305
|
-
type:
|
|
8306
|
-
payload: {
|
|
8248
|
+
type: import_hwk_adapter_core2.EConnectorInteraction.InteractionComplete,
|
|
8249
|
+
payload: {
|
|
8250
|
+
sessionId: device.connectId
|
|
8251
|
+
}
|
|
8307
8252
|
});
|
|
8308
8253
|
},
|
|
8309
8254
|
onPinMatrixRequest: async (payload) => {
|
|
8310
8255
|
if (this.thp?.onPinMatrixRequest) {
|
|
8311
8256
|
return this.thp.onPinMatrixRequest(payload);
|
|
8312
8257
|
}
|
|
8313
|
-
const pinPromise = this.uiRequests.wait(
|
|
8258
|
+
const pinPromise = this.uiRequests.wait(import_hwk_adapter_core2.UI_REQUEST.REQUEST_PIN);
|
|
8314
8259
|
this.emit("ui-request", {
|
|
8315
|
-
type:
|
|
8260
|
+
type: import_hwk_adapter_core2.UI_REQUEST.REQUEST_PIN,
|
|
8316
8261
|
payload: {
|
|
8317
8262
|
connectId: device.connectId,
|
|
8318
8263
|
type: payload.type
|
|
@@ -8324,9 +8269,9 @@ var TrezorConnectorBase = class {
|
|
|
8324
8269
|
if (this.thp?.onPassphraseRequest) {
|
|
8325
8270
|
return this.thp.onPassphraseRequest(payload);
|
|
8326
8271
|
}
|
|
8327
|
-
const passphrasePromise = this.uiRequests.wait(
|
|
8272
|
+
const passphrasePromise = this.uiRequests.wait(import_hwk_adapter_core2.UI_REQUEST.REQUEST_PASSPHRASE);
|
|
8328
8273
|
this.emit("ui-request", {
|
|
8329
|
-
type:
|
|
8274
|
+
type: import_hwk_adapter_core2.UI_REQUEST.REQUEST_PASSPHRASE,
|
|
8330
8275
|
payload: {
|
|
8331
8276
|
connectId: device.connectId,
|
|
8332
8277
|
...payload
|
|
@@ -8336,15 +8281,7 @@ var TrezorConnectorBase = class {
|
|
|
8336
8281
|
return res?.passphraseOnDevice ? { on_device: true } : { passphrase: res?.value ?? "" };
|
|
8337
8282
|
},
|
|
8338
8283
|
onPairingCredentialsChanged: async (payload) => {
|
|
8339
|
-
|
|
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);
|
|
8284
|
+
this.mergeKnownCredentials(payload.credentials);
|
|
8348
8285
|
await this.thp?.onPairingCredentialsChanged?.(payload);
|
|
8349
8286
|
this.emit("device-trezor-thp-credentials-changed", {
|
|
8350
8287
|
connectId: device.connectId,
|
|
@@ -8365,7 +8302,7 @@ var TrezorConnectorBase = class {
|
|
|
8365
8302
|
emitSupportFeatures(session) {
|
|
8366
8303
|
const features = session.deviceSession.features ?? session.features;
|
|
8367
8304
|
session.features = features;
|
|
8368
|
-
this.emit(
|
|
8305
|
+
this.emit(import_hwk_adapter_core2.DEVICE.FEATURES, {
|
|
8369
8306
|
device: {
|
|
8370
8307
|
...session.device,
|
|
8371
8308
|
deviceId: readString(features, "device_id") ?? session.device.deviceId,
|
|
@@ -8388,9 +8325,9 @@ function connectorSessionToDevice(session) {
|
|
|
8388
8325
|
};
|
|
8389
8326
|
}
|
|
8390
8327
|
function rejectKnownNonTrezorDevice(features) {
|
|
8391
|
-
if (!(0,
|
|
8392
|
-
throw (0,
|
|
8393
|
-
code:
|
|
8328
|
+
if (!(0, import_hwk_adapter_core2.isKnownNonTargetHardwareVendor)(features, "trezor")) return;
|
|
8329
|
+
throw (0, import_hwk_adapter_core2.createHwkError)({
|
|
8330
|
+
code: import_hwk_adapter_core2.HardwareErrorCode.DeviceMismatch,
|
|
8394
8331
|
message: "Selected device is not a supported Trezor device.",
|
|
8395
8332
|
params: {
|
|
8396
8333
|
vendor: features.vendor,
|