@onekeyfe/hwk-trezor-core 1.1.29-alpha.1 → 1.1.29-alpha.10
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 +21 -122
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -122
- 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
|
@@ -9632,8 +9632,9 @@ function randomBytes(size, callback) {
|
|
|
9632
9632
|
}
|
|
9633
9633
|
throw error2;
|
|
9634
9634
|
}
|
|
9635
|
-
const
|
|
9636
|
-
cryptoApi.getRandomValues(
|
|
9635
|
+
const entropy = new Uint8Array(size);
|
|
9636
|
+
cryptoApi.getRandomValues(entropy);
|
|
9637
|
+
const bytes = Buffer2.from(entropy);
|
|
9637
9638
|
if (callback) {
|
|
9638
9639
|
callback(null, bytes);
|
|
9639
9640
|
return;
|
|
@@ -11592,19 +11593,19 @@ var ALWAYS_KEPT_EVENT_PREFIXES = [
|
|
|
11592
11593
|
"thp.call.",
|
|
11593
11594
|
"core.call.",
|
|
11594
11595
|
"core.send.",
|
|
11595
|
-
"call.
|
|
11596
|
-
"
|
|
11597
|
-
"
|
|
11598
|
-
"
|
|
11599
|
-
"
|
|
11600
|
-
"[TrezorUSBInitTrace] core.call.",
|
|
11601
|
-
"[TrezorUSBInitTrace] core.send."
|
|
11596
|
+
"connector.call.",
|
|
11597
|
+
"webusb.scan.filtered",
|
|
11598
|
+
"webusb.connector.enumerate.filtered",
|
|
11599
|
+
"ble.connector.enumerate.filtered",
|
|
11600
|
+
"capability.check"
|
|
11602
11601
|
];
|
|
11603
11602
|
var DROPPED_EVENT_PREFIXES = [
|
|
11604
11603
|
"connector.search.",
|
|
11605
11604
|
"webusb.scan.",
|
|
11605
|
+
"webusb.connector.enumerate.",
|
|
11606
11606
|
"webusb.closeDevice.",
|
|
11607
11607
|
"webusb.reset.",
|
|
11608
|
+
"ble.connector.enumerate.",
|
|
11608
11609
|
"ble.renderer.scan.",
|
|
11609
11610
|
"ble.main.scan.",
|
|
11610
11611
|
"ble.scan.",
|
|
@@ -11732,7 +11733,7 @@ var TrezorCore = class {
|
|
|
11732
11733
|
async call(name4, data = {}, options = {}) {
|
|
11733
11734
|
const thpState = options.thpState;
|
|
11734
11735
|
const { message, chunks } = this.buildChunks(name4, data, thpState);
|
|
11735
|
-
this.log("debug", "
|
|
11736
|
+
this.log("debug", "core.call.start", {
|
|
11736
11737
|
protocol: this.protocol.name,
|
|
11737
11738
|
name: name4,
|
|
11738
11739
|
messageBytes: message.length,
|
|
@@ -11781,7 +11782,7 @@ var TrezorCore = class {
|
|
|
11781
11782
|
async send(name4, data = {}, options = {}) {
|
|
11782
11783
|
const thpState = options.thpState;
|
|
11783
11784
|
const { message, chunks } = this.buildChunks(name4, data, thpState);
|
|
11784
|
-
this.log("debug", "
|
|
11785
|
+
this.log("debug", "core.send.start", {
|
|
11785
11786
|
protocol: this.protocol.name,
|
|
11786
11787
|
name: name4,
|
|
11787
11788
|
messageBytes: message.length,
|
|
@@ -11899,7 +11900,6 @@ var TrezorThpProtocol = class {
|
|
|
11899
11900
|
this.thpState.sync("recv", message.type);
|
|
11900
11901
|
}
|
|
11901
11902
|
};
|
|
11902
|
-
var TREZOR_PROTOCOL_MALFORMED = "Malformed protocol format";
|
|
11903
11903
|
var defaultCoreFactory = (transport, protocol, chunkSize, logger) => new TrezorCore({ transport, protocol, chunkSize, logger });
|
|
11904
11904
|
var normalizePassphrase = (value) => (value ?? "").normalize("NFKD");
|
|
11905
11905
|
var normalizeCreateAppSessionOptions = (options = {}) => {
|
|
@@ -11970,21 +11970,7 @@ var TrezorDeviceSession = class {
|
|
|
11970
11970
|
this.protocol = "v1";
|
|
11971
11971
|
const optsLogger = this.thpOptions?.logger;
|
|
11972
11972
|
this.core = this.coreFactory(this.transport, protocol_v1_exports, this.chunkSize, optsLogger);
|
|
11973
|
-
const cancelResult = await this.handshakeCancel();
|
|
11974
|
-
if (cancelResult === "thp") {
|
|
11975
|
-
if (!this.thpOptions) {
|
|
11976
|
-
throw new Error(
|
|
11977
|
-
"Trezor THP required but the connector was constructed without `thp` options. Pass `thp: { hostName, appName, ... }` so the device can complete pairing."
|
|
11978
|
-
);
|
|
11979
|
-
}
|
|
11980
|
-
this.protocol = "v1";
|
|
11981
|
-
this.core = void 0;
|
|
11982
|
-
return this.initializeThp();
|
|
11983
|
-
}
|
|
11984
11973
|
try {
|
|
11985
|
-
this.log("info", "[TrezorSuiteAlignTrace] protocolProbe.v1Initialize.start", {
|
|
11986
|
-
connectionType: this.connectionType ?? "unknown"
|
|
11987
|
-
});
|
|
11988
11974
|
this.log("debug", "session.call.request", { protocol: "v1", name: "Initialize" });
|
|
11989
11975
|
const response = await this.core.call("Initialize", {});
|
|
11990
11976
|
this.log("debug", "session.call.response", {
|
|
@@ -11993,15 +11979,8 @@ var TrezorDeviceSession = class {
|
|
|
11993
11979
|
responseType: response.type
|
|
11994
11980
|
});
|
|
11995
11981
|
this.currentFeatures = expectMessage(response, "Features").message;
|
|
11996
|
-
this.log("info", "[TrezorSuiteAlignTrace] protocolProbe.v1Initialize.done", {
|
|
11997
|
-
responseType: response.type,
|
|
11998
|
-
features: summarizeFeatures(this.currentFeatures)
|
|
11999
|
-
});
|
|
12000
11982
|
} catch (error2) {
|
|
12001
11983
|
if (error2 instanceof TrezorFailureError && error2.code === "Failure_InvalidProtocol") {
|
|
12002
|
-
this.log("info", "[TrezorSuiteAlignTrace] protocolProbe.thpFallback", {
|
|
12003
|
-
reason: "Failure_InvalidProtocol"
|
|
12004
|
-
});
|
|
12005
11984
|
this.log("info", "session.initialize.thp.fallback", {
|
|
12006
11985
|
reason: "device replied Failure_InvalidProtocol to v1 Initialize"
|
|
12007
11986
|
});
|
|
@@ -12015,10 +11994,6 @@ var TrezorDeviceSession = class {
|
|
|
12015
11994
|
return this.initializeThp();
|
|
12016
11995
|
}
|
|
12017
11996
|
this.log("error", "session.initialize.error", { error: errorToLog(error2) });
|
|
12018
|
-
this.log("error", "[TrezorSuiteAlignTrace] protocolProbe.error", {
|
|
12019
|
-
attemptedProtocol: "v1",
|
|
12020
|
-
error: errorToLog(error2)
|
|
12021
|
-
});
|
|
12022
11997
|
throw error2;
|
|
12023
11998
|
}
|
|
12024
11999
|
this.log("info", "session.initialize.done", {
|
|
@@ -12027,83 +12002,6 @@ var TrezorDeviceSession = class {
|
|
|
12027
12002
|
});
|
|
12028
12003
|
return this.currentFeatures;
|
|
12029
12004
|
}
|
|
12030
|
-
async handshakeCancel() {
|
|
12031
|
-
if (!this.core) return "v1";
|
|
12032
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.start", {
|
|
12033
|
-
connectionType: this.connectionType ?? "unknown"
|
|
12034
|
-
});
|
|
12035
|
-
try {
|
|
12036
|
-
await this.core.send("Cancel", {});
|
|
12037
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.send.done", {
|
|
12038
|
-
connectionType: this.connectionType ?? "unknown"
|
|
12039
|
-
});
|
|
12040
|
-
} catch (error2) {
|
|
12041
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.send.ignored", {
|
|
12042
|
-
error: errorToLog(error2)
|
|
12043
|
-
});
|
|
12044
|
-
return "v1";
|
|
12045
|
-
}
|
|
12046
|
-
for (let attempt = 0; attempt < 10; attempt += 1) {
|
|
12047
|
-
const abortController = new AbortController();
|
|
12048
|
-
const timeoutId = setTimeout(() => {
|
|
12049
|
-
abortController.abort(new Error("Trezor handshake Cancel read timeout"));
|
|
12050
|
-
}, 1e3);
|
|
12051
|
-
try {
|
|
12052
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.read.attempt", {
|
|
12053
|
-
attempt
|
|
12054
|
-
});
|
|
12055
|
-
const response = await this.core.receive({
|
|
12056
|
-
signal: abortController.signal,
|
|
12057
|
-
name: "Cancel"
|
|
12058
|
-
});
|
|
12059
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.done", {
|
|
12060
|
-
attempt,
|
|
12061
|
-
responseType: response.type
|
|
12062
|
-
});
|
|
12063
|
-
return "v1";
|
|
12064
|
-
} catch (error2) {
|
|
12065
|
-
if (error2 instanceof TrezorFailureError) {
|
|
12066
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.failure", {
|
|
12067
|
-
attempt,
|
|
12068
|
-
code: error2.code
|
|
12069
|
-
});
|
|
12070
|
-
if (error2.code === "Failure_InvalidProtocol") {
|
|
12071
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.thpDetected", {
|
|
12072
|
-
reason: "Failure_InvalidProtocol"
|
|
12073
|
-
});
|
|
12074
|
-
return "thp";
|
|
12075
|
-
}
|
|
12076
|
-
if (error2.code === "Failure_Busy") {
|
|
12077
|
-
throw error2;
|
|
12078
|
-
}
|
|
12079
|
-
return "v1";
|
|
12080
|
-
}
|
|
12081
|
-
if (error2 instanceof TrezorProtocolError && error2.code === TREZOR_PROTOCOL_MALFORMED) {
|
|
12082
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.read.malformed", {
|
|
12083
|
-
attempt,
|
|
12084
|
-
error: errorToLog(error2)
|
|
12085
|
-
});
|
|
12086
|
-
continue;
|
|
12087
|
-
}
|
|
12088
|
-
if (isHandshakeCancelReadTimeout(error2)) {
|
|
12089
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.read.timeout.reconnect", {
|
|
12090
|
-
attempt
|
|
12091
|
-
});
|
|
12092
|
-
await this.transport.reconnect?.();
|
|
12093
|
-
continue;
|
|
12094
|
-
}
|
|
12095
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.read.ignored", {
|
|
12096
|
-
attempt,
|
|
12097
|
-
error: errorToLog(error2)
|
|
12098
|
-
});
|
|
12099
|
-
return "v1";
|
|
12100
|
-
} finally {
|
|
12101
|
-
clearTimeout(timeoutId);
|
|
12102
|
-
}
|
|
12103
|
-
}
|
|
12104
|
-
this.log("info", "[TrezorSuiteAlignTrace] handshakeCancel.read.limitReached", {});
|
|
12105
|
-
return "v1";
|
|
12106
|
-
}
|
|
12107
12005
|
async call(name4, data = {}) {
|
|
12108
12006
|
if (!this.core) {
|
|
12109
12007
|
await this.initialize();
|
|
@@ -12185,10 +12083,6 @@ var TrezorDeviceSession = class {
|
|
|
12185
12083
|
const response = await this.core.call("GetFeatures", {}, { thpState: this.thpState });
|
|
12186
12084
|
this.log("info", "thp.getFeatures.response", { responseType: response.type });
|
|
12187
12085
|
this.currentFeatures = expectMessage(response, "Features").message;
|
|
12188
|
-
this.log("info", "[TrezorSuiteAlignTrace] protocolProbe.thpGetFeatures.done", {
|
|
12189
|
-
responseType: response.type,
|
|
12190
|
-
features: summarizeFeatures(this.currentFeatures)
|
|
12191
|
-
});
|
|
12192
12086
|
} catch (error2) {
|
|
12193
12087
|
const code = error2?.code;
|
|
12194
12088
|
if (code === "ThpDeviceLocked" && !hasRetried) {
|
|
@@ -12366,7 +12260,9 @@ var TrezorThpSession = class {
|
|
|
12366
12260
|
await this.pair();
|
|
12367
12261
|
}
|
|
12368
12262
|
if (this.thpState.phase !== "paired") {
|
|
12369
|
-
throw new Error("THP pairing is required before GetFeatures")
|
|
12263
|
+
throw Object.assign(new Error("THP pairing is required before GetFeatures"), {
|
|
12264
|
+
code: "ThpPairingRequired"
|
|
12265
|
+
});
|
|
12370
12266
|
}
|
|
12371
12267
|
this.log("info", "thp.session.done", { phase: this.thpState.phase });
|
|
12372
12268
|
}
|
|
@@ -12456,6 +12352,12 @@ var TrezorThpSession = class {
|
|
|
12456
12352
|
const completionState = completion.message.state;
|
|
12457
12353
|
this.thpState.setIsPaired(completionState !== 0);
|
|
12458
12354
|
this.thpState.setPhase("pairing");
|
|
12355
|
+
if (!completionState && handshakeCredentials.credentials) {
|
|
12356
|
+
this.thpState.removePairingCredential(handshakeCredentials.credentials);
|
|
12357
|
+
await this.options.onPairingCredentialsChanged?.({
|
|
12358
|
+
credentials: this.thpState.pairingCredentials
|
|
12359
|
+
});
|
|
12360
|
+
}
|
|
12459
12361
|
this.log("info", "thp.handshake.done", {
|
|
12460
12362
|
completionState,
|
|
12461
12363
|
isPaired: this.thpState.isPaired,
|
|
@@ -12688,9 +12590,6 @@ function errorToLog(error2) {
|
|
|
12688
12590
|
}
|
|
12689
12591
|
return String(error2);
|
|
12690
12592
|
}
|
|
12691
|
-
function isHandshakeCancelReadTimeout(error2) {
|
|
12692
|
-
return error2 instanceof Error && error2.message === "Trezor handshake Cancel read timeout";
|
|
12693
|
-
}
|
|
12694
12593
|
function summarizeFeatures(features) {
|
|
12695
12594
|
if (!features) return void 0;
|
|
12696
12595
|
return {
|