@onekeyfe/hwk-trezor-core 1.1.29-alpha.3 → 1.1.29-alpha.4
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 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +13 -120
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -120
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -241,7 +241,6 @@ declare class TrezorDeviceSession {
|
|
|
241
241
|
get isThp(): boolean;
|
|
242
242
|
getThpState(): TrezorThpState | undefined;
|
|
243
243
|
initialize(): Promise<Record<string, unknown>>;
|
|
244
|
-
private handshakeCancel;
|
|
245
244
|
call(name: string, data?: Record<string, unknown>): Promise<{
|
|
246
245
|
type: string;
|
|
247
246
|
message: Record<string, unknown>;
|
package/dist/index.d.ts
CHANGED
|
@@ -241,7 +241,6 @@ declare class TrezorDeviceSession {
|
|
|
241
241
|
get isThp(): boolean;
|
|
242
242
|
getThpState(): TrezorThpState | undefined;
|
|
243
243
|
initialize(): Promise<Record<string, unknown>>;
|
|
244
|
-
private handshakeCancel;
|
|
245
244
|
call(name: string, data?: Record<string, unknown>): Promise<{
|
|
246
245
|
type: string;
|
|
247
246
|
message: Record<string, unknown>;
|
package/dist/index.js
CHANGED
|
@@ -11592,16 +11592,11 @@ var ALWAYS_KEPT_EVENT_PREFIXES = [
|
|
|
11592
11592
|
"thp.call.",
|
|
11593
11593
|
"core.call.",
|
|
11594
11594
|
"core.send.",
|
|
11595
|
-
"call.
|
|
11595
|
+
"connector.call.",
|
|
11596
11596
|
"webusb.scan.filtered",
|
|
11597
11597
|
"webusb.connector.enumerate.filtered",
|
|
11598
11598
|
"ble.connector.enumerate.filtered",
|
|
11599
|
-
"capability.check"
|
|
11600
|
-
"[TrezorSuiteAlignTrace] handshakeCancel.",
|
|
11601
|
-
"[TrezorSuiteAlignTrace] protocolProbe.",
|
|
11602
|
-
"[TrezorSuiteAlignTrace] call.dispatch.",
|
|
11603
|
-
"[TrezorUSBInitTrace] core.call.",
|
|
11604
|
-
"[TrezorUSBInitTrace] core.send."
|
|
11599
|
+
"capability.check"
|
|
11605
11600
|
];
|
|
11606
11601
|
var DROPPED_EVENT_PREFIXES = [
|
|
11607
11602
|
"connector.search.",
|
|
@@ -11737,7 +11732,7 @@ var TrezorCore = class {
|
|
|
11737
11732
|
async call(name4, data = {}, options = {}) {
|
|
11738
11733
|
const thpState = options.thpState;
|
|
11739
11734
|
const { message, chunks } = this.buildChunks(name4, data, thpState);
|
|
11740
|
-
this.log("debug", "
|
|
11735
|
+
this.log("debug", "core.call.start", {
|
|
11741
11736
|
protocol: this.protocol.name,
|
|
11742
11737
|
name: name4,
|
|
11743
11738
|
messageBytes: message.length,
|
|
@@ -11786,7 +11781,7 @@ var TrezorCore = class {
|
|
|
11786
11781
|
async send(name4, data = {}, options = {}) {
|
|
11787
11782
|
const thpState = options.thpState;
|
|
11788
11783
|
const { message, chunks } = this.buildChunks(name4, data, thpState);
|
|
11789
|
-
this.log("debug", "
|
|
11784
|
+
this.log("debug", "core.send.start", {
|
|
11790
11785
|
protocol: this.protocol.name,
|
|
11791
11786
|
name: name4,
|
|
11792
11787
|
messageBytes: message.length,
|
|
@@ -11904,7 +11899,6 @@ var TrezorThpProtocol = class {
|
|
|
11904
11899
|
this.thpState.sync("recv", message.type);
|
|
11905
11900
|
}
|
|
11906
11901
|
};
|
|
11907
|
-
var TREZOR_PROTOCOL_MALFORMED = "Malformed protocol format";
|
|
11908
11902
|
var defaultCoreFactory = (transport, protocol, chunkSize, logger) => new TrezorCore({ transport, protocol, chunkSize, logger });
|
|
11909
11903
|
var normalizePassphrase = (value) => (value ?? "").normalize("NFKD");
|
|
11910
11904
|
var normalizeCreateAppSessionOptions = (options = {}) => {
|
|
@@ -11975,21 +11969,7 @@ var TrezorDeviceSession = class {
|
|
|
11975
11969
|
this.protocol = "v1";
|
|
11976
11970
|
const optsLogger = this.thpOptions?.logger;
|
|
11977
11971
|
this.core = this.coreFactory(this.transport, protocol_v1_exports, this.chunkSize, optsLogger);
|
|
11978
|
-
const cancelResult = await this.handshakeCancel();
|
|
11979
|
-
if (cancelResult === "thp") {
|
|
11980
|
-
if (!this.thpOptions) {
|
|
11981
|
-
throw new Error(
|
|
11982
|
-
"Trezor THP required but the connector was constructed without `thp` options. Pass `thp: { hostName, appName, ... }` so the device can complete pairing."
|
|
11983
|
-
);
|
|
11984
|
-
}
|
|
11985
|
-
this.protocol = "v1";
|
|
11986
|
-
this.core = void 0;
|
|
11987
|
-
return this.initializeThp();
|
|
11988
|
-
}
|
|
11989
11972
|
try {
|
|
11990
|
-
this.log("info", "[TrezorSuiteAlignTrace] protocolProbe.v1Initialize.start", {
|
|
11991
|
-
connectionType: this.connectionType ?? "unknown"
|
|
11992
|
-
});
|
|
11993
11973
|
this.log("debug", "session.call.request", { protocol: "v1", name: "Initialize" });
|
|
11994
11974
|
const response = await this.core.call("Initialize", {});
|
|
11995
11975
|
this.log("debug", "session.call.response", {
|
|
@@ -11998,15 +11978,8 @@ var TrezorDeviceSession = class {
|
|
|
11998
11978
|
responseType: response.type
|
|
11999
11979
|
});
|
|
12000
11980
|
this.currentFeatures = expectMessage(response, "Features").message;
|
|
12001
|
-
this.log("info", "[TrezorSuiteAlignTrace] protocolProbe.v1Initialize.done", {
|
|
12002
|
-
responseType: response.type,
|
|
12003
|
-
features: summarizeFeatures(this.currentFeatures)
|
|
12004
|
-
});
|
|
12005
11981
|
} catch (error2) {
|
|
12006
11982
|
if (error2 instanceof TrezorFailureError && error2.code === "Failure_InvalidProtocol") {
|
|
12007
|
-
this.log("info", "[TrezorSuiteAlignTrace] protocolProbe.thpFallback", {
|
|
12008
|
-
reason: "Failure_InvalidProtocol"
|
|
12009
|
-
});
|
|
12010
11983
|
this.log("info", "session.initialize.thp.fallback", {
|
|
12011
11984
|
reason: "device replied Failure_InvalidProtocol to v1 Initialize"
|
|
12012
11985
|
});
|
|
@@ -12020,10 +11993,6 @@ var TrezorDeviceSession = class {
|
|
|
12020
11993
|
return this.initializeThp();
|
|
12021
11994
|
}
|
|
12022
11995
|
this.log("error", "session.initialize.error", { error: errorToLog(error2) });
|
|
12023
|
-
this.log("error", "[TrezorSuiteAlignTrace] protocolProbe.error", {
|
|
12024
|
-
attemptedProtocol: "v1",
|
|
12025
|
-
error: errorToLog(error2)
|
|
12026
|
-
});
|
|
12027
11996
|
throw error2;
|
|
12028
11997
|
}
|
|
12029
11998
|
this.log("info", "session.initialize.done", {
|
|
@@ -12032,83 +12001,6 @@ var TrezorDeviceSession = class {
|
|
|
12032
12001
|
});
|
|
12033
12002
|
return this.currentFeatures;
|
|
12034
12003
|
}
|
|
12035
|
-
async handshakeCancel() {
|
|
12036
|
-
if (!this.core) return "v1";
|
|
12037
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.start", {
|
|
12038
|
-
connectionType: this.connectionType ?? "unknown"
|
|
12039
|
-
});
|
|
12040
|
-
try {
|
|
12041
|
-
await this.core.send("Cancel", {});
|
|
12042
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.send.done", {
|
|
12043
|
-
connectionType: this.connectionType ?? "unknown"
|
|
12044
|
-
});
|
|
12045
|
-
} catch (error2) {
|
|
12046
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.send.ignored", {
|
|
12047
|
-
error: errorToLog(error2)
|
|
12048
|
-
});
|
|
12049
|
-
return "v1";
|
|
12050
|
-
}
|
|
12051
|
-
for (let attempt = 0; attempt < 10; attempt += 1) {
|
|
12052
|
-
const abortController = new AbortController();
|
|
12053
|
-
const timeoutId = setTimeout(() => {
|
|
12054
|
-
abortController.abort(new Error("Trezor handshake Cancel read timeout"));
|
|
12055
|
-
}, 1e3);
|
|
12056
|
-
try {
|
|
12057
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.read.attempt", {
|
|
12058
|
-
attempt
|
|
12059
|
-
});
|
|
12060
|
-
const response = await this.core.receive({
|
|
12061
|
-
signal: abortController.signal,
|
|
12062
|
-
name: "Cancel"
|
|
12063
|
-
});
|
|
12064
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.done", {
|
|
12065
|
-
attempt,
|
|
12066
|
-
responseType: response.type
|
|
12067
|
-
});
|
|
12068
|
-
return "v1";
|
|
12069
|
-
} catch (error2) {
|
|
12070
|
-
if (error2 instanceof TrezorFailureError) {
|
|
12071
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.failure", {
|
|
12072
|
-
attempt,
|
|
12073
|
-
code: error2.code
|
|
12074
|
-
});
|
|
12075
|
-
if (error2.code === "Failure_InvalidProtocol") {
|
|
12076
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.thpDetected", {
|
|
12077
|
-
reason: "Failure_InvalidProtocol"
|
|
12078
|
-
});
|
|
12079
|
-
return "thp";
|
|
12080
|
-
}
|
|
12081
|
-
if (error2.code === "Failure_Busy") {
|
|
12082
|
-
throw error2;
|
|
12083
|
-
}
|
|
12084
|
-
return "v1";
|
|
12085
|
-
}
|
|
12086
|
-
if (error2 instanceof TrezorProtocolError && error2.code === TREZOR_PROTOCOL_MALFORMED) {
|
|
12087
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.read.malformed", {
|
|
12088
|
-
attempt,
|
|
12089
|
-
error: errorToLog(error2)
|
|
12090
|
-
});
|
|
12091
|
-
continue;
|
|
12092
|
-
}
|
|
12093
|
-
if (isHandshakeCancelReadTimeout(error2)) {
|
|
12094
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.read.timeout.reconnect", {
|
|
12095
|
-
attempt
|
|
12096
|
-
});
|
|
12097
|
-
await this.transport.reconnect?.();
|
|
12098
|
-
continue;
|
|
12099
|
-
}
|
|
12100
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.read.ignored", {
|
|
12101
|
-
attempt,
|
|
12102
|
-
error: errorToLog(error2)
|
|
12103
|
-
});
|
|
12104
|
-
return "v1";
|
|
12105
|
-
} finally {
|
|
12106
|
-
clearTimeout(timeoutId);
|
|
12107
|
-
}
|
|
12108
|
-
}
|
|
12109
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.read.limitReached", {});
|
|
12110
|
-
return "v1";
|
|
12111
|
-
}
|
|
12112
12004
|
async call(name4, data = {}) {
|
|
12113
12005
|
if (!this.core) {
|
|
12114
12006
|
await this.initialize();
|
|
@@ -12190,10 +12082,6 @@ var TrezorDeviceSession = class {
|
|
|
12190
12082
|
const response = await this.core.call("GetFeatures", {}, { thpState: this.thpState });
|
|
12191
12083
|
this.log("info", "thp.getFeatures.response", { responseType: response.type });
|
|
12192
12084
|
this.currentFeatures = expectMessage(response, "Features").message;
|
|
12193
|
-
this.log("info", "[TrezorSuiteAlignTrace] protocolProbe.thpGetFeatures.done", {
|
|
12194
|
-
responseType: response.type,
|
|
12195
|
-
features: summarizeFeatures(this.currentFeatures)
|
|
12196
|
-
});
|
|
12197
12085
|
} catch (error2) {
|
|
12198
12086
|
const code = error2?.code;
|
|
12199
12087
|
if (code === "ThpDeviceLocked" && !hasRetried) {
|
|
@@ -12371,7 +12259,9 @@ var TrezorThpSession = class {
|
|
|
12371
12259
|
await this.pair();
|
|
12372
12260
|
}
|
|
12373
12261
|
if (this.thpState.phase !== "paired") {
|
|
12374
|
-
throw new Error("THP pairing is required before GetFeatures")
|
|
12262
|
+
throw Object.assign(new Error("THP pairing is required before GetFeatures"), {
|
|
12263
|
+
code: "ThpPairingRequired"
|
|
12264
|
+
});
|
|
12375
12265
|
}
|
|
12376
12266
|
this.log("info", "thp.session.done", { phase: this.thpState.phase });
|
|
12377
12267
|
}
|
|
@@ -12461,6 +12351,12 @@ var TrezorThpSession = class {
|
|
|
12461
12351
|
const completionState = completion.message.state;
|
|
12462
12352
|
this.thpState.setIsPaired(completionState !== 0);
|
|
12463
12353
|
this.thpState.setPhase("pairing");
|
|
12354
|
+
if (!completionState && handshakeCredentials.credentials) {
|
|
12355
|
+
this.thpState.removePairingCredential(handshakeCredentials.credentials);
|
|
12356
|
+
await this.options.onPairingCredentialsChanged?.({
|
|
12357
|
+
credentials: this.thpState.pairingCredentials
|
|
12358
|
+
});
|
|
12359
|
+
}
|
|
12464
12360
|
this.log("info", "thp.handshake.done", {
|
|
12465
12361
|
completionState,
|
|
12466
12362
|
isPaired: this.thpState.isPaired,
|
|
@@ -12693,9 +12589,6 @@ function errorToLog(error2) {
|
|
|
12693
12589
|
}
|
|
12694
12590
|
return String(error2);
|
|
12695
12591
|
}
|
|
12696
|
-
function isHandshakeCancelReadTimeout(error2) {
|
|
12697
|
-
return error2 instanceof Error && error2.message === "Trezor handshake Cancel read timeout";
|
|
12698
|
-
}
|
|
12699
12592
|
function summarizeFeatures(features) {
|
|
12700
12593
|
if (!features) return void 0;
|
|
12701
12594
|
return {
|