@onekeyfe/hd-core 1.0.31 → 1.0.32

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AACA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAY,6BAA6B,EAAoB,MAAM,wBAAwB,CAAC;AA6BnG,OAAO,EAEL,WAAW,EAWZ,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,UAAU,CAAC;AAE7D,OAAO,eAAe,MAAM,2BAA2B,CAAC;AAMxD,KAAK,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;AAsCtD,eAAO,MAAM,OAAO,YAAmB,WAAW,WAAW,WAAW,iBA2DvE,CAAC;AA+gBF,eAAO,MAAM,MAAM,YAAa,WAAW,cAAc,MAAM,SA2E9D,CAAC;AAoKF,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,YAAY;IAC5C,OAAO,CAAC,YAAY,CAAsB;IAG1C,OAAO,CAAC,qBAAqB,CAA4B;IAEzD,OAAO,CAAC,iBAAiB,CAAoB;IAE7C,OAAO,CAAC,cAAc;IAWhB,aAAa,CAAC,OAAO,EAAE,WAAW;IAmDxC,OAAO;CAGR;AAED,eAAO,MAAM,QAAQ,YAGpB,CAAC;AAEF,eAAO,MAAM,aAAa,uBAIzB,CAAC;AAMF,eAAO,MAAM,IAAI,aACL,eAAe,aACd,GAAG,WACL,6BAA6B,8BAoBvC,CAAC;AAEF,eAAO,MAAM,eAAe;SAKrB,eAAe,CAAC,KAAK,CAAC;eAChB,GAAG;;UASf,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AACA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAY,6BAA6B,EAAoB,MAAM,wBAAwB,CAAC;AA6BnG,OAAO,EAEL,WAAW,EAWZ,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,UAAU,CAAC;AAE7D,OAAO,eAAe,MAAM,2BAA2B,CAAC;AAMxD,KAAK,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;AAsCtD,eAAO,MAAM,OAAO,YAAmB,WAAW,WAAW,WAAW,iBA2DvE,CAAC;AA8hBF,eAAO,MAAM,MAAM,YAAa,WAAW,cAAc,MAAM,SA2E9D,CAAC;AAoKF,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,YAAY;IAC5C,OAAO,CAAC,YAAY,CAAsB;IAG1C,OAAO,CAAC,qBAAqB,CAA4B;IAEzD,OAAO,CAAC,iBAAiB,CAAoB;IAE7C,OAAO,CAAC,cAAc;IAWhB,aAAa,CAAC,OAAO,EAAE,WAAW;IAmDxC,OAAO;CAGR;AAED,eAAO,MAAM,QAAQ,YAGpB,CAAC;AAEF,eAAO,MAAM,aAAa,uBAIzB,CAAC;AAMF,eAAO,MAAM,IAAI,aACL,eAAe,aACd,GAAG,WACL,6BAA6B,8BAoBvC,CAAC;AAEF,eAAO,MAAM,eAAe;SAKrB,eAAe,CAAC,KAAK,CAAC;eAChB,GAAG;;UASf,CAAC"}
package/dist/index.js CHANGED
@@ -38215,18 +38215,29 @@ const callAPI = (context, message) => __awaiter(void 0, void 0, void 0, function
38215
38215
  }
38216
38216
  return onCallDevice(context, message, method);
38217
38217
  });
38218
- const waitForPendingPromise = (getPrePendingCallPromise) => __awaiter(void 0, void 0, void 0, function* () {
38218
+ const waitWithTimeout = (promise, timeout) => __awaiter(void 0, void 0, void 0, function* () {
38219
+ const timeoutPromise = new Promise((_, reject) => {
38220
+ setTimeout(() => reject(new Error('Request timeout')), timeout);
38221
+ });
38222
+ return Promise.race([promise, timeoutPromise]);
38223
+ });
38224
+ const waitForPendingPromise = (getPrePendingCallPromise, removePrePendingCallPromise) => __awaiter(void 0, void 0, void 0, function* () {
38219
38225
  const pendingPromise = getPrePendingCallPromise();
38220
38226
  if (pendingPromise) {
38221
38227
  Log.debug('pre pending call promise before call method, wait for it');
38222
- yield pendingPromise;
38228
+ try {
38229
+ yield waitWithTimeout(pendingPromise, 5 * 1000);
38230
+ }
38231
+ catch (error) {
38232
+ }
38233
+ removePrePendingCallPromise === null || removePrePendingCallPromise === void 0 ? void 0 : removePrePendingCallPromise(pendingPromise);
38223
38234
  Log.debug('pre pending call promise before call method done');
38224
38235
  }
38225
38236
  });
38226
38237
  const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, void 0, function* () {
38227
38238
  var _a, _b;
38228
38239
  let messageResponse;
38229
- const { requestQueue, getPrePendingCallPromise } = context;
38240
+ const { requestQueue, getPrePendingCallPromise, setPrePendingCallPromise } = context;
38230
38241
  const connectStateChange = preConnectCache.passphraseState !== method.payload.passphraseState;
38231
38242
  preConnectCache = {
38232
38243
  passphraseState: method.payload.passphraseState,
@@ -38235,7 +38246,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
38235
38246
  Log.debug('passphrase state change, clear device cache');
38236
38247
  DevicePool.clearDeviceCache(method.payload.connectId);
38237
38248
  }
38238
- yield waitForPendingPromise(getPrePendingCallPromise);
38249
+ yield waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
38239
38250
  const task = requestQueue.createTask(method);
38240
38251
  let device;
38241
38252
  try {
@@ -38265,7 +38276,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
38265
38276
  device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
38266
38277
  device.on(DEVICE.SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE, onSelectDeviceInBootloaderForWebDeviceHandler);
38267
38278
  try {
38268
- yield waitForPendingPromise(getPrePendingCallPromise);
38279
+ yield waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
38269
38280
  const inner = () => __awaiter(void 0, void 0, void 0, function* () {
38270
38281
  var _c, _d, _e;
38271
38282
  const versionRange = getMethodVersionRange(device.features, type => method.getVersionRange()[type]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "1.0.31",
3
+ "version": "1.0.32",
4
4
  "description": "> TODO: description",
5
5
  "author": "OneKey",
6
6
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -25,8 +25,8 @@
25
25
  "url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
26
26
  },
27
27
  "dependencies": {
28
- "@onekeyfe/hd-shared": "^1.0.31",
29
- "@onekeyfe/hd-transport": "^1.0.31",
28
+ "@onekeyfe/hd-shared": "^1.0.32",
29
+ "@onekeyfe/hd-transport": "^1.0.32",
30
30
  "axios": "^0.27.2",
31
31
  "bignumber.js": "^9.0.2",
32
32
  "bytebuffer": "^5.0.1",
@@ -46,5 +46,5 @@
46
46
  "@types/web-bluetooth": "^0.0.21",
47
47
  "ripple-keypairs": "^1.1.4"
48
48
  },
49
- "gitHead": "3e31186a4c2969d666a6ea124209075ab7a8e7aa"
49
+ "gitHead": "b84a301dc0cb1cb39a0b0c33536c21d8f2433755"
50
50
  }
package/src/core/index.ts CHANGED
@@ -151,11 +151,26 @@ export const callAPI = async (context: CoreContext, message: CoreMessage) => {
151
151
  return onCallDevice(context, message, method);
152
152
  };
153
153
 
154
- const waitForPendingPromise = async (getPrePendingCallPromise: () => Promise<void> | undefined) => {
154
+ const waitWithTimeout = async (promise: Promise<any>, timeout: number) => {
155
+ const timeoutPromise = new Promise((_, reject) => {
156
+ setTimeout(() => reject(new Error('Request timeout')), timeout);
157
+ });
158
+ return Promise.race([promise, timeoutPromise]);
159
+ };
160
+
161
+ const waitForPendingPromise = async (
162
+ getPrePendingCallPromise: () => Promise<void> | undefined,
163
+ removePrePendingCallPromise?: (promise: Promise<void> | undefined) => void
164
+ ) => {
155
165
  const pendingPromise = getPrePendingCallPromise();
156
166
  if (pendingPromise) {
157
167
  Log.debug('pre pending call promise before call method, wait for it');
158
- await pendingPromise;
168
+ try {
169
+ await waitWithTimeout(pendingPromise, 5 * 1000);
170
+ } catch (error) {
171
+ // ignore timeout error
172
+ }
173
+ removePrePendingCallPromise?.(pendingPromise);
159
174
  Log.debug('pre pending call promise before call method done');
160
175
  }
161
176
  };
@@ -167,7 +182,7 @@ const onCallDevice = async (
167
182
  ): Promise<any> => {
168
183
  let messageResponse: any;
169
184
 
170
- const { requestQueue, getPrePendingCallPromise } = context;
185
+ const { requestQueue, getPrePendingCallPromise, setPrePendingCallPromise } = context;
171
186
 
172
187
  const connectStateChange = preConnectCache.passphraseState !== method.payload.passphraseState;
173
188
 
@@ -180,7 +195,7 @@ const onCallDevice = async (
180
195
  DevicePool.clearDeviceCache(method.payload.connectId);
181
196
  }
182
197
 
183
- await waitForPendingPromise(getPrePendingCallPromise);
198
+ await waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
184
199
 
185
200
  const task = requestQueue.createTask(method);
186
201
 
@@ -225,7 +240,7 @@ const onCallDevice = async (
225
240
  );
226
241
 
227
242
  try {
228
- await waitForPendingPromise(getPrePendingCallPromise);
243
+ await waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
229
244
 
230
245
  const inner = async (): Promise<void> => {
231
246
  // check firmware version
@@ -928,7 +943,7 @@ export default class Core extends EventEmitter {
928
943
  requestQueue: this.requestQueue,
929
944
  methodSynchronize: this.methodSynchronize,
930
945
  getPrePendingCallPromise: () => this.prePendingCallPromise,
931
- setPrePendingCallPromise: (promise: Promise<void>) => {
946
+ setPrePendingCallPromise: (promise: Promise<void> | undefined) => {
932
947
  this.prePendingCallPromise = promise;
933
948
  },
934
949
  };