@onekeyfe/hwk-trezor-core 1.2.10 → 1.2.11-alpha.1
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.js +31 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -11759,6 +11759,22 @@ function shouldMarkThpModuleHandled(entry) {
|
|
|
11759
11759
|
|
|
11760
11760
|
// src/index.ts
|
|
11761
11761
|
init_buffer();
|
|
11762
|
+
function trackTransportFailure() {
|
|
11763
|
+
let failure;
|
|
11764
|
+
return {
|
|
11765
|
+
run: async (io) => {
|
|
11766
|
+
try {
|
|
11767
|
+
return await io();
|
|
11768
|
+
} catch (error2) {
|
|
11769
|
+
failure ??= { error: error2 };
|
|
11770
|
+
throw error2;
|
|
11771
|
+
}
|
|
11772
|
+
},
|
|
11773
|
+
rethrow: () => {
|
|
11774
|
+
if (failure) throw failure.error;
|
|
11775
|
+
}
|
|
11776
|
+
};
|
|
11777
|
+
}
|
|
11762
11778
|
var unwrapTransportAbortSignal = (options) => {
|
|
11763
11779
|
if (!options) return void 0;
|
|
11764
11780
|
if ("addEventListener" in options && typeof options.addEventListener === "function") {
|
|
@@ -11816,20 +11832,26 @@ var TrezorCore = class {
|
|
|
11816
11832
|
});
|
|
11817
11833
|
if (this.protocol.name === "v2") {
|
|
11818
11834
|
const previousNonce = thpState?.sendNonce;
|
|
11835
|
+
const transportFailure = trackTransportFailure();
|
|
11819
11836
|
const response = await callThpMessage({
|
|
11820
11837
|
thpState,
|
|
11821
11838
|
chunks,
|
|
11822
11839
|
apiWrite: async (chunk, options2) => {
|
|
11823
|
-
await
|
|
11840
|
+
await transportFailure.run(
|
|
11841
|
+
() => this.transport.write(chunk, unwrapTransportAbortSignal(options2))
|
|
11842
|
+
);
|
|
11824
11843
|
return { success: true, payload: void 0 };
|
|
11825
11844
|
},
|
|
11826
11845
|
apiRead: async (options2) => {
|
|
11827
|
-
const payload = await
|
|
11846
|
+
const payload = await transportFailure.run(
|
|
11847
|
+
() => this.transport.read(unwrapTransportAbortSignal(options2))
|
|
11848
|
+
);
|
|
11828
11849
|
return { success: true, payload: toRuntimeBuffer(payload) };
|
|
11829
11850
|
},
|
|
11830
11851
|
signal: options.signal
|
|
11831
11852
|
});
|
|
11832
11853
|
if (!response.success) {
|
|
11854
|
+
transportFailure.rethrow();
|
|
11833
11855
|
throw new Error(response.error.message ?? response.error.code);
|
|
11834
11856
|
}
|
|
11835
11857
|
if (previousNonce === thpState?.sendNonce) {
|
|
@@ -11866,14 +11888,16 @@ var TrezorCore = class {
|
|
|
11866
11888
|
await this.writeChunks(chunks, options.signal);
|
|
11867
11889
|
}
|
|
11868
11890
|
async receive(options = {}) {
|
|
11891
|
+
const transportFailure = trackTransportFailure();
|
|
11869
11892
|
const response = await receiveAndParse(async () => {
|
|
11870
|
-
const payload = await this.transport.read(options.signal);
|
|
11893
|
+
const payload = await transportFailure.run(() => this.transport.read(options.signal));
|
|
11871
11894
|
return {
|
|
11872
11895
|
success: true,
|
|
11873
11896
|
payload: toRuntimeBuffer(payload)
|
|
11874
11897
|
};
|
|
11875
11898
|
}, this.protocol);
|
|
11876
11899
|
if (!response.success) {
|
|
11900
|
+
transportFailure.rethrow();
|
|
11877
11901
|
throw new TrezorProtocolError(response.error.code, response.error.message);
|
|
11878
11902
|
}
|
|
11879
11903
|
if (isFailureResponse(response.payload)) {
|
|
@@ -11928,16 +11952,17 @@ var TrezorThpProtocol = class {
|
|
|
11928
11952
|
}
|
|
11929
11953
|
const previousNonce = this.thpState.sendNonce;
|
|
11930
11954
|
const chunk = toRuntimeBuffer(this.encode(params));
|
|
11955
|
+
const transportFailure = trackTransportFailure();
|
|
11931
11956
|
const result = await callThpMessage({
|
|
11932
11957
|
thpState: this.thpState,
|
|
11933
11958
|
chunks: [chunk],
|
|
11934
11959
|
skipAck: params.skipAck,
|
|
11935
11960
|
apiWrite: async (data) => {
|
|
11936
|
-
await transport.write?.(connectId, Uint8Array.from(data));
|
|
11961
|
+
await transportFailure.run(async () => transport.write?.(connectId, Uint8Array.from(data)));
|
|
11937
11962
|
return { success: true, payload: void 0 };
|
|
11938
11963
|
},
|
|
11939
11964
|
apiRead: async () => {
|
|
11940
|
-
const data = await transport.read?.(connectId);
|
|
11965
|
+
const data = await transportFailure.run(async () => transport.read?.(connectId));
|
|
11941
11966
|
if (!data) {
|
|
11942
11967
|
return {
|
|
11943
11968
|
success: false,
|
|
@@ -11948,6 +11973,7 @@ var TrezorThpProtocol = class {
|
|
|
11948
11973
|
}
|
|
11949
11974
|
});
|
|
11950
11975
|
if (!result.success) {
|
|
11976
|
+
transportFailure.rethrow();
|
|
11951
11977
|
throw new Error(result.error.message ?? result.error.code);
|
|
11952
11978
|
}
|
|
11953
11979
|
if (previousNonce === this.thpState.sendNonce) {
|