@onekeyfe/hd-core 1.2.2-alpha.120 → 1.2.2-alpha.122

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 CHANGED
@@ -43705,6 +43705,18 @@ class TransportManager {
43705
43705
  this.defaultMessages = DataManager.getProtobufMessages();
43706
43706
  this.currentMessages = this.defaultMessages;
43707
43707
  this.protocolV1MessageSchema = 'v1CurrentSchema';
43708
+ this.webUsbInit = false;
43709
+ }
43710
+ static ensureInitialized() {
43711
+ return __awaiter(this, void 0, void 0, function* () {
43712
+ const env = DataManager.getSettings('env');
43713
+ if (env !== 'webusb' && env !== 'desktop-webusb')
43714
+ return;
43715
+ if (this.webUsbInit)
43716
+ return;
43717
+ yield this.transport.init(WebUsbLogger, DevicePool.emitter);
43718
+ this.webUsbInit = true;
43719
+ });
43708
43720
  }
43709
43721
  static configure() {
43710
43722
  return __awaiter(this, void 0, void 0, function* () {
@@ -43733,7 +43745,7 @@ class TransportManager {
43733
43745
  yield this.transport.init(WebBleLogger, DevicePool.emitter);
43734
43746
  }
43735
43747
  else if (env === 'webusb' || env === 'desktop-webusb') {
43736
- yield this.transport.init(WebUsbLogger, DevicePool.emitter);
43748
+ yield this.ensureInitialized();
43737
43749
  }
43738
43750
  else {
43739
43751
  yield this.transport.init(HttpLogger);
@@ -43816,6 +43828,7 @@ class TransportManager {
43816
43828
  }
43817
43829
  }
43818
43830
  TransportManager.reactNativeInit = false;
43831
+ TransportManager.webUsbInit = false;
43819
43832
  TransportManager.protocolV1MessageSchema = 'v1CurrentSchema';
43820
43833
  TransportManager.plugin = null;
43821
43834
 
@@ -46495,6 +46508,7 @@ class Device extends events.exports {
46495
46508
  }
46496
46509
  else if (!acquired) {
46497
46510
  if (mainId && (deviceConnector === null || deviceConnector === void 0 ? void 0 : deviceConnector.disconnect)) {
46511
+ Log$h.debug('interruptionFromUser: disconnecting device without acquire, mainId:', mainId);
46498
46512
  yield deviceConnector.disconnect(mainId);
46499
46513
  }
46500
46514
  if (this.connectionAttempt === attempt)
@@ -47263,6 +47277,48 @@ class PreInitialize extends BaseMethod {
47263
47277
  }
47264
47278
 
47265
47279
  const Log$e = getLogger(exports.LoggerNames.DevicePool);
47280
+ const getDescriptorKeys = (descriptor) => [descriptor.path, descriptor.id].filter((key) => typeof key === 'string' && key.length > 0);
47281
+ const isOwnedByActiveWebUsbRequest = (descriptor, requestQueue) => {
47282
+ if (!requestQueue)
47283
+ return false;
47284
+ return getDescriptorKeys(descriptor).some(key => requestQueue.getRequestTasksIdByConnectId(key).length > 0);
47285
+ };
47286
+ const getUsbHandle = (descriptor) => descriptor === null || descriptor === void 0 ? void 0 : descriptor.device;
47287
+ const getOwningRequestDevice = (descriptor, requestQueue) => {
47288
+ var _a, _b;
47289
+ if (!requestQueue)
47290
+ return undefined;
47291
+ const usbHandle = getUsbHandle(descriptor);
47292
+ if (usbHandle === undefined)
47293
+ return undefined;
47294
+ for (const key of getDescriptorKeys(descriptor)) {
47295
+ for (const requestId of requestQueue.getRequestTasksIdByConnectId(key)) {
47296
+ const device = (_a = requestQueue.getTask(requestId)) === null || _a === void 0 ? void 0 : _a.method.device;
47297
+ if ((device === null || device === void 0 ? void 0 : device.features) &&
47298
+ (device.mainId === key || ((_b = device.originalDescriptor) === null || _b === void 0 ? void 0 : _b.path) === key) &&
47299
+ getUsbHandle(device.originalDescriptor) === usbHandle) {
47300
+ return device;
47301
+ }
47302
+ }
47303
+ }
47304
+ return undefined;
47305
+ };
47306
+ const toSearchDeviceFromDescriptor = (descriptor) => {
47307
+ const connectId = descriptor.path || descriptor.id || null;
47308
+ return {
47309
+ connectId,
47310
+ uuid: '',
47311
+ serialNo: null,
47312
+ deviceId: null,
47313
+ deviceType: hdShared.EDeviceType.Unknown,
47314
+ name: descriptor.name || connectId || '',
47315
+ commType: descriptor.commType,
47316
+ };
47317
+ };
47318
+ const toSearchDevice = (device) => {
47319
+ const message = device.toMessageObject();
47320
+ return message ? message : null;
47321
+ };
47266
47322
  class SearchDevices extends BaseMethod {
47267
47323
  init() {
47268
47324
  this.useDevice = false;
@@ -47270,20 +47326,32 @@ class SearchDevices extends BaseMethod {
47270
47326
  this.skipForceUpdateCheck = true;
47271
47327
  }
47272
47328
  run() {
47273
- var _a, _b, _c, _d, _e;
47329
+ var _a, _b, _c, _d, _e, _f, _g;
47274
47330
  return __awaiter(this, void 0, void 0, function* () {
47275
- yield TransportManager.configure();
47276
- const deviceDiff = yield ((_a = this.connector) === null || _a === void 0 ? void 0 : _a.enumerate());
47277
- const devicesDescriptor = (_b = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _b !== void 0 ? _b : [];
47278
47331
  const env = DataManager.getSettings('env');
47332
+ const isWebUsb = env === 'webusb' || env === 'desktop-webusb';
47333
+ const requestQueue = (_a = this.context) === null || _a === void 0 ? void 0 : _a.requestQueue;
47334
+ const hasActiveWebUsbRequest = isWebUsb && ((_b = requestQueue === null || requestQueue === void 0 ? void 0 : requestQueue.getRequestTasksId().length) !== null && _b !== void 0 ? _b : 0) > 0;
47335
+ if (isWebUsb) {
47336
+ try {
47337
+ yield TransportManager.ensureInitialized();
47338
+ }
47339
+ catch (error) {
47340
+ Log$e.debug('WebUSB bring-up unavailable', error);
47341
+ }
47342
+ }
47343
+ if (!hasActiveWebUsbRequest)
47344
+ yield TransportManager.configure();
47345
+ const deviceDiff = yield ((_c = this.connector) === null || _c === void 0 ? void 0 : _c.enumerate());
47346
+ const devicesDescriptor = (_d = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _d !== void 0 ? _d : [];
47279
47347
  if (DataManager.isBleConnect(env)) {
47280
47348
  const devices = [];
47281
47349
  const seenIds = new Set();
47282
47350
  for (const device of devicesDescriptor) {
47283
- const lowerId = (_c = device.id) === null || _c === void 0 ? void 0 : _c.toLowerCase();
47351
+ const lowerId = (_e = device.id) === null || _e === void 0 ? void 0 : _e.toLowerCase();
47284
47352
  if (!seenIds.has(lowerId)) {
47285
47353
  seenIds.add(lowerId);
47286
- const rawBleName = (_e = (_d = device.name) !== null && _d !== void 0 ? _d : device.localName) !== null && _e !== void 0 ? _e : '';
47354
+ const rawBleName = (_g = (_f = device.name) !== null && _f !== void 0 ? _f : device.localName) !== null && _g !== void 0 ? _g : '';
47287
47355
  const bleName = hdShared.canonicalizePro2BleAdvertisementName(rawBleName);
47288
47356
  devices.push(Object.assign(Object.assign({}, device), { connectId: device.id, serialNo: null, uuid: '', deviceId: null, name: bleName || device.name, deviceType: getDeviceTypeByBleName(bleName) }));
47289
47357
  }
@@ -47292,22 +47360,34 @@ class SearchDevices extends BaseMethod {
47292
47360
  }
47293
47361
  const deviceList = [];
47294
47362
  for (const descriptor of devicesDescriptor) {
47295
- try {
47296
- const result = yield DevicePool.getDevices([descriptor], descriptor.path, {
47297
- connectProtocol: undefined,
47298
- forceProtocolDetection: true,
47299
- refreshRuntimeState: true,
47300
- });
47301
- deviceList.push(...result.deviceList);
47363
+ if (hasActiveWebUsbRequest && isOwnedByActiveWebUsbRequest(descriptor, requestQueue)) {
47364
+ const cached = DevicePool.getDeviceByPath(descriptor.path);
47365
+ const known = (cached === null || cached === void 0 ? void 0 : cached.features) ? cached : getOwningRequestDevice(descriptor, requestQueue);
47366
+ const message = known ? toSearchDevice(known) : null;
47367
+ deviceList.push(message !== null && message !== void 0 ? message : toSearchDeviceFromDescriptor(descriptor));
47302
47368
  }
47303
- catch (error) {
47304
- const errorCode = error && typeof error === 'object' && 'errorCode' in error
47305
- ? error.errorCode
47306
- : undefined;
47307
- Log$e.debug('Skip unavailable device during search', Object.assign({ path: descriptor.path }, (errorCode !== undefined ? { errorCode } : {})));
47369
+ else {
47370
+ try {
47371
+ const result = yield DevicePool.getDevices([descriptor], descriptor.path, {
47372
+ connectProtocol: undefined,
47373
+ forceProtocolDetection: true,
47374
+ refreshRuntimeState: true,
47375
+ });
47376
+ for (const device of result.deviceList) {
47377
+ const message = toSearchDevice(device);
47378
+ if (message)
47379
+ deviceList.push(message);
47380
+ }
47381
+ }
47382
+ catch (error) {
47383
+ const errorCode = error && typeof error === 'object' && 'errorCode' in error
47384
+ ? error.errorCode
47385
+ : undefined;
47386
+ Log$e.debug('Skip unavailable device during search', Object.assign({ path: descriptor.path }, (errorCode !== undefined ? { errorCode } : {})));
47387
+ }
47308
47388
  }
47309
47389
  }
47310
- return deviceList.map(device => device.toMessageObject());
47390
+ return deviceList;
47311
47391
  });
47312
47392
  }
47313
47393
  }
@@ -55964,7 +56044,7 @@ class AllNetworkGetAddressBase extends BaseMethod {
55964
56044
  this.protocolV2ResumedSeedDomains.add('cardano');
55965
56045
  }
55966
56046
  }
55967
- callMethod(methodName, params, rootFingerprint) {
56047
+ callMethod(methodName, params, rootFingerprint, postMessage = this.postMessage) {
55968
56048
  var _a, _b, _c;
55969
56049
  return __awaiter(this, void 0, void 0, function* () {
55970
56050
  const method = findMethod({
@@ -55973,7 +56053,7 @@ class AllNetworkGetAddressBase extends BaseMethod {
55973
56053
  payload: Object.assign({ connectId: this.payload.connectId, deviceId: this.payload.deviceId, method: methodName }, params),
55974
56054
  });
55975
56055
  method.connector = this.connector;
55976
- method.postMessage = this.postMessage;
56056
+ method.postMessage = postMessage;
55977
56057
  if (this.context) {
55978
56058
  (_a = method.setContext) === null || _a === void 0 ? void 0 : _a.call(method, this.context);
55979
56059
  }
@@ -56088,7 +56168,9 @@ class AllNetworkGetAddressBase extends BaseMethod {
56088
56168
  return __awaiter(this, void 0, void 0, function* () {
56089
56169
  this.loadingCleanupInBackground = false;
56090
56170
  try {
56091
- if (this.device.isProtocolV2() && this.device.getCurrentDeviceType() === hdShared.EDeviceType.Pro2) {
56171
+ if (this.device.isProtocolV2() &&
56172
+ (this.device.getCurrentDeviceType() === hdShared.EDeviceType.Pro2 ||
56173
+ this.device.getCurrentDeviceType() === hdShared.EDeviceType.Neo)) {
56092
56174
  const protocolInfo = yield this.device.ensureProtocolV2RuntimeContext();
56093
56175
  if (supportsProtocolV2Message(protocolInfo, 60461)) {
56094
56176
  const { commands } = this.device;
@@ -56184,11 +56266,53 @@ function handleSkippableHardwareError(e, device, method) {
56184
56266
  }
56185
56267
 
56186
56268
  class AllNetworkGetAddress extends AllNetworkGetAddressBase {
56269
+ checkAborted() {
56270
+ var _a;
56271
+ if ((_a = this.abortController) === null || _a === void 0 ? void 0 : _a.signal.aborted) {
56272
+ throw new Error(hdShared.HardwareErrorCodeMessage[hdShared.HardwareErrorCode.RepeatUnlocking]);
56273
+ }
56274
+ }
56275
+ callAddressGroup(methodName, params, rootFingerprint) {
56276
+ return __awaiter(this, void 0, void 0, function* () {
56277
+ const methodCallParams = { bundle: params.map(param => (Object.assign({}, param.params))) };
56278
+ if (!this.device.isProtocolV2() || params.length === 1) {
56279
+ return this.callMethod(methodName, methodCallParams, rootFingerprint);
56280
+ }
56281
+ const postedAddressCounts = new Map();
56282
+ let runningIndividually = false;
56283
+ const postMessage = message => {
56284
+ var _a;
56285
+ if (message.type === UI_REQUEST.PREVIOUS_ADDRESS_RESULT) {
56286
+ const { path, address } = message.payload.data;
56287
+ const key = JSON.stringify([path, address]);
56288
+ const count = (_a = postedAddressCounts.get(key)) !== null && _a !== void 0 ? _a : 0;
56289
+ if (runningIndividually && count > 0) {
56290
+ postedAddressCounts.set(key, count - 1);
56291
+ return;
56292
+ }
56293
+ if (!runningIndividually)
56294
+ postedAddressCounts.set(key, count + 1);
56295
+ }
56296
+ this.postMessage(message);
56297
+ };
56298
+ if (params.every(param => param._originRequestParams.showOnOneKey === false)) {
56299
+ const response = yield this.callMethod(methodName, methodCallParams, rootFingerprint, postMessage);
56300
+ if (response.some(item => item.success))
56301
+ return response;
56302
+ }
56303
+ runningIndividually = true;
56304
+ const responses = [];
56305
+ for (const param of params) {
56306
+ this.checkAborted();
56307
+ const response = yield this.callMethod(methodName, { bundle: [Object.assign({}, param.params)] }, rootFingerprint, postMessage);
56308
+ responses.push(...response);
56309
+ }
56310
+ return responses;
56311
+ });
56312
+ }
56187
56313
  getAllNetworkAddress(rootFingerprint) {
56188
- var _a, _b, _c;
56189
56314
  return __awaiter(this, void 0, void 0, function* () {
56190
56315
  const responses = [];
56191
- const resultMap = {};
56192
56316
  const { bundle } = this.payload;
56193
56317
  const methodParams = bundle.map((param, index) => this.generateMethodName({
56194
56318
  network: param.network,
@@ -56204,38 +56328,12 @@ class AllNetworkGetAddress extends AllNetworkGetAddressBase {
56204
56328
  }, new Map());
56205
56329
  let processed = 0;
56206
56330
  for (const [methodName, params] of methodGroups.entries()) {
56207
- const methodCallParams = {
56208
- bundle: params.map(param => (Object.assign({}, param.params))),
56209
- };
56210
- if ((_a = this.abortController) === null || _a === void 0 ? void 0 : _a.signal.aborted) {
56211
- throw new Error(hdShared.HardwareErrorCodeMessage[hdShared.HardwareErrorCode.RepeatUnlocking]);
56212
- }
56213
- const isProtocolV2 = this.device.isProtocolV2();
56214
- const runIndividually = isProtocolV2 &&
56215
- params.length > 1 &&
56216
- params.some(param => param._originRequestParams.showOnOneKey !== false);
56217
- let response = [];
56218
- if (!runIndividually) {
56219
- response = yield this.callMethod(methodName, methodCallParams, rootFingerprint);
56220
- }
56221
- if (isProtocolV2 &&
56222
- params.length > 1 &&
56223
- (runIndividually || response.every(item => !item.success))) {
56224
- response = [];
56225
- for (const param of params) {
56226
- if ((_b = this.abortController) === null || _b === void 0 ? void 0 : _b.signal.aborted) {
56227
- throw new Error(hdShared.HardwareErrorCodeMessage[hdShared.HardwareErrorCode.RepeatUnlocking]);
56228
- }
56229
- const itemResponse = yield this.callMethod(methodName, { bundle: [Object.assign({}, param.params)] }, rootFingerprint);
56230
- response.push(...itemResponse);
56231
- }
56232
- }
56233
- if ((_c = this.abortController) === null || _c === void 0 ? void 0 : _c.signal.aborted) {
56234
- throw new Error(hdShared.HardwareErrorCodeMessage[hdShared.HardwareErrorCode.RepeatUnlocking]);
56235
- }
56331
+ this.checkAborted();
56332
+ const response = yield this.callAddressGroup(methodName, params, rootFingerprint);
56333
+ this.checkAborted();
56236
56334
  for (let index = 0; index < params.length; index++) {
56237
56335
  const { _originRequestParams, _originalIndex } = params[index];
56238
- resultMap[`${_originalIndex}`] = Object.assign(Object.assign({}, _originRequestParams), response[index]);
56336
+ responses[_originalIndex] = Object.assign(Object.assign({}, _originRequestParams), response[index]);
56239
56337
  }
56240
56338
  processed += params.length;
56241
56339
  if (bundle.length > 1) {
@@ -56243,11 +56341,8 @@ class AllNetworkGetAddress extends AllNetworkGetAddressBase {
56243
56341
  this.postMessage(createUiMessage(UI_REQUEST.DEVICE_PROGRESS, { progress }));
56244
56342
  }
56245
56343
  }
56246
- for (let i = 0; i < bundle.length; i++) {
56247
- responses.push(resultMap[i]);
56248
- }
56249
56344
  this.abortController = null;
56250
- return Promise.resolve(responses);
56345
+ return responses;
56251
56346
  });
56252
56347
  }
56253
56348
  }
@@ -65880,7 +65975,7 @@ const createUiProgressMessageFilter = (intervalMs = DEFAULT_UI_PROGRESS_INTERVAL
65880
65975
 
65881
65976
  const Log = getLogger(exports.LoggerNames.Core);
65882
65977
  const PRE_INITIALIZE_TTL_MS = 60 * 1000;
65883
- const PRE_PENDING_CALL_TIMEOUT_MS = 15 * 1000;
65978
+ const PRE_PENDING_CALL_TIMEOUT_MS = 5 * 1000;
65884
65979
  const PRO2_USB_SIGNING_COOLDOWN_MS = 1000;
65885
65980
  const preWarmInflight = new Map();
65886
65981
  const preWarmDoneAt = new Map();
@@ -65960,6 +66055,7 @@ const callAPI = (context, message) => __awaiter(void 0, void 0, void 0, function
65960
66055
  }
65961
66056
  };
65962
66057
  (_a = method.setContext) === null || _a === void 0 ? void 0 : _a.call(method, context);
66058
+ method.context = context;
65963
66059
  method.requestContext = createRequestContext(method.responseID, method.name, {
65964
66060
  sdkInstanceId: context.sdkInstanceId,
65965
66061
  connectId: method.connectId,
@@ -65977,7 +66073,11 @@ const callAPI = (context, message) => __awaiter(void 0, void 0, void 0, function
65977
66073
  if (!method.useDevice) {
65978
66074
  updateMethodRequestContext(method, { status: 'running' });
65979
66075
  try {
65980
- const response = yield method.run();
66076
+ const env = DataManager.getSettings('env');
66077
+ const response = method.name === 'searchDevices' &&
66078
+ (DataManager.isBrowserWebUsb(env) || DataManager.isDesktopWebUsb(env))
66079
+ ? yield context.methodSynchronize(() => method.run(), 'webusb-discovery')
66080
+ : yield method.run();
65981
66081
  completeMethodRequestContext(method);
65982
66082
  return createResponseMessage(method.responseID, true, response);
65983
66083
  }
@@ -66048,20 +66148,28 @@ const waitForPendingPromise = (connectId, getPrePendingCallPromise, removePrePen
66048
66148
  if (pendingPromise) {
66049
66149
  Log.debug('pre pending call promise before call method, wait for it');
66050
66150
  let timer;
66151
+ let timedOut = false;
66152
+ let completed = false;
66051
66153
  try {
66052
66154
  yield Promise.race([
66053
66155
  pendingPromise,
66054
- new Promise((_, reject) => {
66156
+ new Promise(resolve => {
66055
66157
  timer = setTimeout(() => {
66056
- reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceBusy, 'Previous device cancellation is still draining'));
66158
+ timedOut = true;
66159
+ resolve();
66057
66160
  }, PRE_PENDING_CALL_TIMEOUT_MS);
66058
66161
  }),
66059
66162
  ]);
66060
- removePrePendingCallPromise === null || removePrePendingCallPromise === void 0 ? void 0 : removePrePendingCallPromise(connectId, pendingPromise);
66163
+ completed = !timedOut;
66061
66164
  }
66062
66165
  finally {
66063
66166
  if (timer)
66064
66167
  clearTimeout(timer);
66168
+ if (timedOut || completed)
66169
+ removePrePendingCallPromise === null || removePrePendingCallPromise === void 0 ? void 0 : removePrePendingCallPromise(connectId, pendingPromise);
66170
+ }
66171
+ if (timedOut) {
66172
+ Log.warn('pre pending call promise timed out before call method', { connectId });
66065
66173
  }
66066
66174
  Log.debug('pre pending call promise before call method done');
66067
66175
  }
@@ -66109,7 +66217,22 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
66109
66217
  context.registerCallbackTask(method.connectId, preWarmCallbackTask);
66110
66218
  }
66111
66219
  const pollingId = pollingManager.start(connectId);
66112
- device = yield ensureConnected(context, method, connectId, pollingId, method.abortSignal);
66220
+ const env = DataManager.getSettings('env');
66221
+ const connect = () => ensureConnected(context, method, connectId, pollingId, method.abortSignal);
66222
+ if (DataManager.isBrowserWebUsb(env) || DataManager.isDesktopWebUsb(env)) {
66223
+ const connectPromise = context.methodSynchronize(() => __awaiter(void 0, void 0, void 0, function* () {
66224
+ var _k;
66225
+ if ((_k = method.abortSignal) === null || _k === void 0 ? void 0 : _k.aborted) {
66226
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled);
66227
+ }
66228
+ return connect();
66229
+ }), 'webusb-discovery');
66230
+ connectPromise.catch(() => undefined);
66231
+ device = yield requestQueue.waitForTask(task, () => connectPromise);
66232
+ }
66233
+ else {
66234
+ device = yield connect();
66235
+ }
66113
66236
  if ((_e = method.abortSignal) === null || _e === void 0 ? void 0 : _e.aborted) {
66114
66237
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled);
66115
66238
  }
@@ -66174,12 +66297,12 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
66174
66297
  return waitForPendingPromise((_a = method.connectId) !== null && _a !== void 0 ? _a : '', getPrePendingCallPromise, removePrePendingCallPromise);
66175
66298
  });
66176
66299
  const inner = () => __awaiter(void 0, void 0, void 0, function* () {
66177
- var _k, _l;
66300
+ var _l, _m;
66178
66301
  method.assertProtocolSupported(device.getProtocol(), device.getCurrentFirmwareType());
66179
66302
  protocolV2Operation = device.isProtocolV2();
66180
66303
  const versionRange = device.getCurrentMethodVersionRange(type => method.getVersionRange()[type]);
66181
- const currentFirmwareVersion = (_k = device.getCurrentFirmwareVersionString()) !== null && _k !== void 0 ? _k : '0.0.0';
66182
- const currentBleVersion = (_l = device.getCurrentBLEFirmwareVersionString()) !== null && _l !== void 0 ? _l : '0.0.0';
66304
+ const currentFirmwareVersion = (_l = device.getCurrentFirmwareVersionString()) !== null && _l !== void 0 ? _l : '0.0.0';
66305
+ const currentBleVersion = (_m = device.getCurrentBLEFirmwareVersionString()) !== null && _m !== void 0 ? _m : '0.0.0';
66183
66306
  const deviceFirmwareType = device.getCurrentFirmwareType();
66184
66307
  let newVersionStatus;
66185
66308
  if (device.features && !device.isProtocolV2()) {
@@ -66257,7 +66380,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
66257
66380
  }
66258
66381
  },
66259
66382
  prepare: () => __awaiter(void 0, void 0, void 0, function* () {
66260
- var _m, _o, _p, _q, _r, _s;
66383
+ var _o, _p, _q, _r, _s, _t;
66261
66384
  if (method.deviceId && method.checkDeviceId && !deviceIdCheckedDuringUnlockPreflight) {
66262
66385
  const isSameDeviceID = yield checkLiveDeviceId(device, method.deviceId);
66263
66386
  if (!isSameDeviceID) {
@@ -66277,7 +66400,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
66277
66400
  require: support.require,
66278
66401
  });
66279
66402
  }
66280
- const passphraseStateSafety = yield device.checkPassphraseStateSafety((_m = method.payload) === null || _m === void 0 ? void 0 : _m.passphraseState, (_o = method.payload) === null || _o === void 0 ? void 0 : _o.useEmptyPassphrase, (_p = method.payload) === null || _p === void 0 ? void 0 : _p.skipPassphraseCheck, resolveDeriveCardano(method), (_q = method.protocolV2UnlockContext) === null || _q === void 0 ? void 0 : _q.preflightMainPinSelected);
66403
+ const passphraseStateSafety = yield device.checkPassphraseStateSafety((_o = method.payload) === null || _o === void 0 ? void 0 : _o.passphraseState, (_p = method.payload) === null || _p === void 0 ? void 0 : _p.useEmptyPassphrase, (_q = method.payload) === null || _q === void 0 ? void 0 : _q.skipPassphraseCheck, resolveDeriveCardano(method), (_r = method.protocolV2UnlockContext) === null || _r === void 0 ? void 0 : _r.preflightMainPinSelected);
66281
66404
  checkPassphraseEnableState(method, device.features);
66282
66405
  if (!passphraseStateSafety) {
66283
66406
  DevicePool.clearDeviceCache(method.payload.connectId);
@@ -66295,7 +66418,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
66295
66418
  ? e
66296
66419
  : hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'open safety check failed.');
66297
66420
  }
66298
- (_s = (_r = method.device) === null || _r === void 0 ? void 0 : _r.commands) === null || _s === void 0 ? void 0 : _s.checkDisposed();
66421
+ (_t = (_s = method.device) === null || _s === void 0 ? void 0 : _s.commands) === null || _t === void 0 ? void 0 : _t.checkDisposed();
66299
66422
  }),
66300
66423
  });
66301
66424
  messageResponse = createResponseMessage(method.responseID, true, response);
@@ -66650,10 +66773,11 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
66650
66773
  const POLL_INTERVAL_TIME = (method.payload && method.payload.pollIntervalTime) || 1000;
66651
66774
  const TIME_OUT = (method.payload && method.payload.timeout) || 10000;
66652
66775
  let timer = null;
66776
+ let lastInitializeError;
66653
66777
  Log.debug(`EnsureConnected function start, MAX_RETRY_COUNT=${MAX_RETRY_COUNT}, POLL_INTERVAL_TIME=${POLL_INTERVAL_TIME} `);
66654
66778
  const poll = (time = POLL_INTERVAL_TIME) => __awaiter(void 0, void 0, void 0, function* () {
66655
66779
  return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
66656
- var _t;
66780
+ var _u;
66657
66781
  const abort = () => {
66658
66782
  if (abortSignal && abortSignal.aborted) {
66659
66783
  if (timer) {
@@ -66682,8 +66806,10 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
66682
66806
  Log.debug('EnsureConnected function try count: ', tryCount, ' poll interval time: ', time);
66683
66807
  try {
66684
66808
  yield initDeviceList(method);
66809
+ lastInitializeError = undefined;
66685
66810
  }
66686
66811
  catch (error) {
66812
+ lastInitializeError = error;
66687
66813
  Log.debug('device list error: ', error);
66688
66814
  if ([
66689
66815
  hdShared.HardwareErrorCode.BridgeNotInstalled,
@@ -66696,6 +66822,7 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
66696
66822
  }
66697
66823
  if (error.errorCode === hdShared.HardwareErrorCode.TransportNotConfigured) {
66698
66824
  yield TransportManager.configure();
66825
+ lastInitializeError = undefined;
66699
66826
  }
66700
66827
  }
66701
66828
  if (abort()) {
@@ -66778,13 +66905,16 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
66778
66905
  clearTimeout(timer);
66779
66906
  }
66780
66907
  Log.debug('EnsureConnected get to max try count, will return: ', tryCount);
66781
- if (DataManager.isBrowserWebUsb(env) && !((_t = method.payload) === null || _t === void 0 ? void 0 : _t.skipWebDevicePrompt)) {
66908
+ const preserveWebUsbInitError = DataManager.isBrowserWebUsb(env) || DataManager.isDesktopWebUsb(env);
66909
+ const needsPermissionPrompt = DataManager.isBrowserWebUsb(env) && !((_u = method.payload) === null || _u === void 0 ? void 0 : _u.skipWebDevicePrompt);
66910
+ const fallbackError = needsPermissionPrompt
66911
+ ? hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WebDeviceNotFoundOrNeedsPermission)
66912
+ : hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound);
66913
+ const errorToReject = preserveWebUsbInitError && lastInitializeError ? lastInitializeError : fallbackError;
66914
+ if (needsPermissionPrompt && errorToReject === fallbackError) {
66782
66915
  postMessage(createUiMessage(UI_REQUEST.WEB_DEVICE_PROMPT_ACCESS_PERMISSION));
66783
- reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WebDeviceNotFoundOrNeedsPermission));
66784
- }
66785
- else {
66786
- reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound));
66787
66916
  }
66917
+ reject(errorToReject);
66788
66918
  return;
66789
66919
  }
66790
66920
  if (abort()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "1.2.2-alpha.120",
3
+ "version": "1.2.2-alpha.122",
4
4
  "description": "Core processes and APIs for communicating with OneKey hardware devices.",
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.2.2-alpha.120",
29
- "@onekeyfe/hd-transport": "1.2.2-alpha.120",
28
+ "@onekeyfe/hd-shared": "1.2.2-alpha.122",
29
+ "@onekeyfe/hd-transport": "1.2.2-alpha.122",
30
30
  "axios": "1.15.2",
31
31
  "bignumber.js": "^9.0.2",
32
32
  "buffer": "^6.0.3",
@@ -46,5 +46,5 @@
46
46
  "@types/w3c-web-usb": "^1.0.10",
47
47
  "@types/web-bluetooth": "^0.0.21"
48
48
  },
49
- "gitHead": "26958fa2be6aa34a07f42403fb7022d2785e70b9"
49
+ "gitHead": "37770cd3ae109751f082715228b6155487b7da56"
50
50
  }