@onekeyfe/hd-web-sdk 0.0.5 → 0.0.8

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.
@@ -5006,6 +5006,24 @@ const getDeviceType = features => {
5006
5006
  const serialNo = features.serial_no;
5007
5007
  const miniFlag = serialNo.slice(0, 2);
5008
5008
  if (miniFlag.toLowerCase() === 'mi') return 'mini';
5009
+ if (miniFlag.toLowerCase() === 'tc') return 'touch';
5010
+ return 'classic';
5011
+ };
5012
+
5013
+ const getDeviceTypeByBleName = name => {
5014
+ if (!name) return 'classic';
5015
+ if (name.startsWith('MI')) return 'mini';
5016
+ if (name.startsWith('T')) return 'touch';
5017
+ return 'classic';
5018
+ };
5019
+
5020
+ const getDeviceTypeByDeviceId = deviceId => {
5021
+ if (!deviceId) {
5022
+ return 'classic';
5023
+ }
5024
+
5025
+ const miniFlag = deviceId.slice(0, 2);
5026
+ if (miniFlag.toLowerCase() === 'mi') return 'mini';
5009
5027
  return 'classic';
5010
5028
  };
5011
5029
 
@@ -14069,7 +14087,9 @@ const UI_REQUEST$1 = {
14069
14087
  REQUEST_PIN: 'ui-request_pin',
14070
14088
  INVALID_PIN: 'ui-invalid_pin',
14071
14089
  REQUEST_BUTTON: 'ui-button',
14072
- CLOSE_UI_WINDOW: 'ui-close_window'
14090
+ CLOSE_UI_WINDOW: 'ui-close_window',
14091
+ BLUETOOTH_PERMISSION: 'ui-bluetooth_permission',
14092
+ LOCATION_PERMISSION: 'ui-location_permission'
14073
14093
  };
14074
14094
 
14075
14095
  const createUiMessage = (type, payload) => ({
@@ -14835,10 +14855,14 @@ class SearchDevices extends BaseMethod {
14835
14855
  const env = DataManager.getSettings('env');
14836
14856
 
14837
14857
  if (env === 'react-native') {
14838
- return devicesDescriptor.map(device => Object.assign(Object.assign({}, device), {
14839
- connectId: device.id,
14840
- deviceType: 'classic'
14841
- }));
14858
+ return devicesDescriptor.map(device => {
14859
+ var _a;
14860
+
14861
+ return Object.assign(Object.assign({}, device), {
14862
+ connectId: device.id,
14863
+ deviceType: getDeviceTypeByBleName((_a = device.name) !== null && _a !== void 0 ? _a : '')
14864
+ });
14865
+ });
14842
14866
  }
14843
14867
 
14844
14868
  const devices = [];
@@ -17303,7 +17327,7 @@ let _uiPromises = [];
17303
17327
  let _callPromise;
17304
17328
 
17305
17329
  const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
17306
- var _a;
17330
+ var _a, _b;
17307
17331
 
17308
17332
  if (!message.id || !message.payload || message.type !== IFRAME.CALL) {
17309
17333
  return Promise.reject(TypedError('Method_InvalidParameter', 'onCall: message.id or message.payload is missing'));
@@ -17325,7 +17349,10 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
17325
17349
  const response = yield method.run();
17326
17350
  return createResponseMessage(method.responseID, true, response);
17327
17351
  } catch (error) {
17328
- return createResponseMessage(method.responseID, false, error);
17352
+ return createResponseMessage(method.responseID, false, {
17353
+ code: error.code,
17354
+ error: (_a = error.message) !== null && _a !== void 0 ? _a : error
17355
+ });
17329
17356
  }
17330
17357
  }
17331
17358
 
@@ -17349,7 +17376,7 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
17349
17376
  }
17350
17377
 
17351
17378
  Log.debug('Call API - setDevice: ', device);
17352
- (_a = method.setDevice) === null || _a === void 0 ? void 0 : _a.call(method, device);
17379
+ (_b = method.setDevice) === null || _b === void 0 ? void 0 : _b.call(method, device);
17353
17380
  device.on(DEVICE.PIN, onDevicePinHandler);
17354
17381
  device.on(DEVICE.BUTTON, (d, code) => {
17355
17382
  onDeviceButtonHandler(d, code);
@@ -17384,7 +17411,13 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
17384
17411
  const deviceRun = () => device.run(inner);
17385
17412
 
17386
17413
  _callPromise = create(deviceRun);
17387
- return yield _callPromise.promise;
17414
+
17415
+ try {
17416
+ return yield _callPromise.promise;
17417
+ } catch (e) {
17418
+ console.log('Device Run Error: ', e);
17419
+ return createResponseMessage(method.responseID, false, e.message);
17420
+ }
17388
17421
  } catch (error) {
17389
17422
  messageResponse = createResponseMessage(method.responseID, false, error);
17390
17423
  _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.reject(TypedError('Call_API', error));
@@ -17486,9 +17519,17 @@ const onDeviceButtonHandler = (...[device, request]) => {
17486
17519
  postMessage(createDeviceMessage(DEVICE.BUTTON, Object.assign(Object.assign({}, request), {
17487
17520
  device: device.toMessageObject()
17488
17521
  })));
17489
- postMessage(createUiMessage(UI_REQUEST$1.REQUEST_BUTTON, {
17490
- device: device.toMessageObject()
17491
- }));
17522
+
17523
+ if (request.code === 'ButtonRequest_PinEntry') {
17524
+ postMessage(createUiMessage(UI_REQUEST$1.REQUEST_PIN, {
17525
+ device: device.toMessageObject(),
17526
+ type: 'ButtonRequest_PinEntry'
17527
+ }));
17528
+ } else {
17529
+ postMessage(createUiMessage(UI_REQUEST$1.REQUEST_BUTTON, {
17530
+ device: device.toMessageObject()
17531
+ }));
17532
+ }
17492
17533
  };
17493
17534
 
17494
17535
  const postMessage = message => {
@@ -17525,6 +17566,13 @@ class Core extends events.exports {
17525
17566
  break;
17526
17567
  }
17527
17568
 
17569
+ case UI_REQUEST$1.BLUETOOTH_PERMISSION:
17570
+ case UI_REQUEST$1.LOCATION_PERMISSION:
17571
+ {
17572
+ postMessage(message);
17573
+ break;
17574
+ }
17575
+
17528
17576
  case IFRAME.CALL:
17529
17577
  {
17530
17578
  const response = yield callAPI(message);
@@ -17559,7 +17607,7 @@ const init = (settings, Transport) => __awaiter(void 0, void 0, void 0, function
17559
17607
  try {
17560
17608
  yield DataManager.load(settings);
17561
17609
  initTransport(Transport);
17562
- } catch (_b) {
17610
+ } catch (_c) {
17563
17611
  Log.error('DataManager.load error');
17564
17612
  }
17565
17613
 
@@ -17618,6 +17666,8 @@ exports.ZP = HardwareSdk;
17618
17666
  exports.yI = enableLog;
17619
17667
  __webpack_unused_export__ = getDeviceLabel;
17620
17668
  __webpack_unused_export__ = getDeviceType;
17669
+ __webpack_unused_export__ = getDeviceTypeByBleName;
17670
+ __webpack_unused_export__ = getDeviceTypeByDeviceId;
17621
17671
  __webpack_unused_export__ = getDeviceUUID;
17622
17672
  __webpack_unused_export__ = getEnv;
17623
17673
  __webpack_unused_export__ = getHDPath;
@@ -17877,6 +17927,7 @@ const MESSAGE_TOP_CHAR = 0x003f;
17877
17927
  const MESSAGE_HEADER_BYTE = 0x23;
17878
17928
  const HEADER_SIZE = 1 + 1 + 4 + 2;
17879
17929
  const BUFFER_SIZE = 63;
17930
+ const COMMON_HEADER_SIZE = 6;
17880
17931
 
17881
17932
  const readHeader = buffer => {
17882
17933
  const typeId = buffer.readUint16();
@@ -18645,6 +18696,7 @@ var index = {
18645
18696
  parseConfigure
18646
18697
  };
18647
18698
  exports.BUFFER_SIZE = BUFFER_SIZE;
18699
+ exports.COMMON_HEADER_SIZE = COMMON_HEADER_SIZE;
18648
18700
  exports.HEADER_SIZE = HEADER_SIZE;
18649
18701
  exports.MESSAGE_HEADER_BYTE = MESSAGE_HEADER_BYTE;
18650
18702
  exports.MESSAGE_TOP_CHAR = MESSAGE_TOP_CHAR;