@onekeyfe/hd-web-sdk 0.1.25 → 0.1.28

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.
@@ -4133,6 +4133,10 @@ const inject = ({
4133
4133
  connectId,
4134
4134
  method: 'deviceUpdateReboot'
4135
4135
  }),
4136
+ deviceSupportFeatures: connectId => call({
4137
+ connectId,
4138
+ method: 'deviceSupportFeatures'
4139
+ }),
4136
4140
  deviceVerify: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4137
4141
  connectId,
4138
4142
  method: 'deviceVerify'
@@ -4259,7 +4263,10 @@ const inject = ({
4259
4263
  firmwareUpdate: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4260
4264
  connectId,
4261
4265
  method: 'firmwareUpdate'
4262
- }))
4266
+ })),
4267
+ requestWebUsbDevice: () => call({
4268
+ method: 'requestWebUsbDevice'
4269
+ })
4263
4270
  };
4264
4271
  return api;
4265
4272
  };
@@ -13670,9 +13677,25 @@ const getDeviceBLEFirmwareVersion = features => {
13670
13677
  return null;
13671
13678
  }
13672
13679
 
13680
+ if (!semver__default["default"].valid(features.ble_ver)) {
13681
+ return null;
13682
+ }
13683
+
13673
13684
  return features.ble_ver.split('.');
13674
13685
  };
13675
13686
 
13687
+ const supportInputPinOnSoftware = features => {
13688
+ if (!features) return false;
13689
+ const deviceType = getDeviceType(features);
13690
+
13691
+ if (deviceType === 'touch') {
13692
+ return false;
13693
+ }
13694
+
13695
+ const currentVersion = getDeviceFirmwareVersion(features).join('.');
13696
+ return semver__default["default"].gte(currentVersion, '2.3.0');
13697
+ };
13698
+
13676
13699
  const HD_HARDENED = 0x80000000;
13677
13700
 
13678
13701
  const toHardened = n => (n | HD_HARDENED) >>> 0;
@@ -13807,7 +13830,7 @@ const createLogMessage = (type, payload) => ({
13807
13830
  const MAX_ENTRIES = 500;
13808
13831
  let postMessage$1;
13809
13832
 
13810
- class Log$6 {
13833
+ class Log$7 {
13811
13834
  constructor(prefix, enabled) {
13812
13835
  this.prefix = prefix;
13813
13836
  this.enabled = enabled;
@@ -13876,7 +13899,7 @@ class Log$6 {
13876
13899
  const _logs = {};
13877
13900
 
13878
13901
  const initLog = (prefix, enabled) => {
13879
- const instance = new Log$6(prefix, !!enabled);
13902
+ const instance = new Log$7(prefix, !!enabled);
13880
13903
  _logs[prefix] = instance;
13881
13904
  return instance;
13882
13905
  };
@@ -13952,6 +13975,8 @@ exports.d0 = void 0;
13952
13975
  LoggerNames["DeviceCommands"] = "DeviceCommands";
13953
13976
  LoggerNames["DeviceConnector"] = "DeviceConnector";
13954
13977
  LoggerNames["DeviceList"] = "DeviceList";
13978
+ LoggerNames["DevicePool"] = "DevicePool";
13979
+ LoggerNames["HdCommonConnectSdk"] = "@onekey/common-connect-sdk";
13955
13980
  LoggerNames["HdBleSdk"] = "@onekey/hd-ble-sdk";
13956
13981
  LoggerNames["HdTransportHttp"] = "@onekey/hd-transport-http";
13957
13982
  LoggerNames["HdBleTransport"] = "@onekey/hd-ble-transport";
@@ -13968,13 +13993,15 @@ const LoggerMap = {
13968
13993
  [exports.d0.DeviceCommands]: initLog(exports.d0.DeviceCommands),
13969
13994
  [exports.d0.DeviceConnector]: initLog(exports.d0.DeviceConnector),
13970
13995
  [exports.d0.DeviceList]: initLog(exports.d0.DeviceList),
13996
+ [exports.d0.DevicePool]: initLog(exports.d0.DevicePool),
13971
13997
  [exports.d0.HdBleSdk]: initLog(exports.d0.HdBleSdk),
13972
13998
  [exports.d0.HdTransportHttp]: initLog(exports.d0.HdTransportHttp),
13973
13999
  [exports.d0.HdBleTransport]: initLog(exports.d0.HdBleTransport),
13974
14000
  [exports.d0.Connect]: initLog(exports.d0.Connect),
13975
14001
  [exports.d0.Iframe]: initLog(exports.d0.Iframe),
13976
14002
  [exports.d0.SendMessage]: initLog(exports.d0.SendMessage),
13977
- [exports.d0.Method]: initLog(exports.d0.Method)
14003
+ [exports.d0.Method]: initLog(exports.d0.Method),
14004
+ [exports.d0.HdCommonConnectSdk]: initLog(exports.d0.Method)
13978
14005
  };
13979
14006
 
13980
14007
  const getLogger = key => LoggerMap[key];
@@ -14151,95 +14178,6 @@ DataManager.getTransportStatus = localVersion => {
14151
14178
  return isLatest ? 'valid' : 'outdated';
14152
14179
  };
14153
14180
 
14154
- const Log$5 = getLogger(exports.d0.Transport);
14155
- const BleLogger = getLogger(exports.d0.HdBleTransport);
14156
- const HttpLogger = getLogger(exports.d0.HdTransportHttp);
14157
-
14158
- class TransportManager {
14159
- static load() {
14160
- Log$5.debug('transport manager load');
14161
- this.defaultMessages = DataManager.getProtobufMessages();
14162
- this.currentMessages = this.defaultMessages;
14163
- }
14164
-
14165
- static configure() {
14166
- return __awaiter(this, void 0, void 0, function* () {
14167
- try {
14168
- const env = DataManager.getSettings('env');
14169
- Log$5.debug('Initializing transports');
14170
-
14171
- if (env === 'react-native') {
14172
- if (!this.reactNativeInit) {
14173
- yield this.transport.init(BleLogger);
14174
- this.reactNativeInit = true;
14175
- } else {
14176
- Log$5.debug('React Native Do Not Initializing transports');
14177
- }
14178
- } else {
14179
- yield this.transport.init(HttpLogger);
14180
- }
14181
-
14182
- Log$5.debug('Configuring transports');
14183
- yield this.transport.configure(JSON.stringify(this.defaultMessages));
14184
- Log$5.debug('Configuring transports done');
14185
- } catch (error) {
14186
- Log$5.debug('Initializing transports error: ', error);
14187
-
14188
- if (error.code === 'ECONNABORTED') {
14189
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
14190
- }
14191
- }
14192
- });
14193
- }
14194
-
14195
- static reconfigure(messages) {
14196
- return __awaiter(this, void 0, void 0, function* () {
14197
- if (Array.isArray(messages)) {
14198
- messages = DataManager.getProtobufMessages();
14199
- }
14200
-
14201
- if (this.currentMessages === messages || !messages) {
14202
- return;
14203
- }
14204
-
14205
- try {
14206
- yield this.transport.configure(JSON.stringify(messages));
14207
- this.currentMessages = messages;
14208
- } catch (error) {
14209
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportInvalidProtobuf, `Transport_InvalidProtobuf: ${error.message}`);
14210
- }
14211
- });
14212
- }
14213
-
14214
- static setTransport(TransportConstructor) {
14215
- const env = DataManager.getSettings('env');
14216
-
14217
- if (env === 'react-native') {
14218
- this.transport = new TransportConstructor({
14219
- scanTimeout: 3000
14220
- });
14221
- } else {
14222
- this.transport = new TransportConstructor();
14223
- }
14224
-
14225
- Log$5.debug('set transport: ', this.transport);
14226
- }
14227
-
14228
- static getTransport() {
14229
- return this.transport;
14230
- }
14231
-
14232
- static getDefaultMessages() {
14233
- return this.defaultMessages;
14234
- }
14235
-
14236
- static getCurrentMessages() {
14237
- return this.currentMessages;
14238
- }
14239
-
14240
- }
14241
-
14242
- TransportManager.reactNativeInit = false;
14243
14181
  const CORE_EVENT = 'CORE_EVENT';
14244
14182
 
14245
14183
  const parseMessage = messageData => {
@@ -14351,6 +14289,7 @@ const DEVICE = {
14351
14289
  PASSPHRASE: 'passphrase',
14352
14290
  PASSPHRASE_ON_DEVICE: 'passphrase_on_device',
14353
14291
  WORD: 'word',
14292
+ SUPPORT_FEATURES: 'support_features',
14354
14293
  FEATURES: 'features'
14355
14294
  };
14356
14295
 
@@ -14372,6 +14311,348 @@ const createFirmwareMessage = (type, payload) => ({
14372
14311
  payload
14373
14312
  });
14374
14313
 
14314
+ const Log$6 = getLogger(exports.d0.DevicePool);
14315
+
14316
+ const getDiff = (current, descriptors) => {
14317
+ const connected = descriptors.filter(d => current.find(x => x.path === d.path) === undefined);
14318
+ const disconnected = current.filter(d => descriptors.find(x => x.path === d.path) === undefined);
14319
+ const changedSessions = descriptors.filter(d => {
14320
+ const currentDescriptor = current.find(x => x.path === d.path);
14321
+
14322
+ if (currentDescriptor) {
14323
+ return currentDescriptor.session !== d.session;
14324
+ }
14325
+
14326
+ return false;
14327
+ });
14328
+ const acquired = changedSessions.filter(d => typeof d.session === 'string');
14329
+ const released = changedSessions.filter(d => typeof d.session !== 'string');
14330
+ const changedDebugSessions = descriptors.filter(d => {
14331
+ const currentDescriptor = current.find(x => x.path === d.path);
14332
+
14333
+ if (currentDescriptor) {
14334
+ return currentDescriptor.debugSession !== d.debugSession;
14335
+ }
14336
+
14337
+ return false;
14338
+ });
14339
+ const debugAcquired = changedSessions.filter(d => typeof d.debugSession === 'string');
14340
+ const debugReleased = changedSessions.filter(d => typeof d.debugSession !== 'string');
14341
+ const didUpdate = connected.length + disconnected.length + changedSessions.length + changedDebugSessions.length > 0;
14342
+ return {
14343
+ connected,
14344
+ disconnected,
14345
+ changedSessions,
14346
+ acquired,
14347
+ released,
14348
+ changedDebugSessions,
14349
+ debugAcquired,
14350
+ debugReleased,
14351
+ didUpdate,
14352
+ descriptors
14353
+ };
14354
+ };
14355
+
14356
+ class DevicePool extends events.exports {
14357
+ static setConnector(connector) {
14358
+ this.connector = connector;
14359
+ }
14360
+
14361
+ static getDevices(descriptorList, connectId) {
14362
+ var descriptorList_1, descriptorList_1_1;
14363
+
14364
+ var e_1, _a;
14365
+
14366
+ return __awaiter(this, void 0, void 0, function* () {
14367
+ Log$6.debug('get device list');
14368
+ const devices = {};
14369
+ const deviceList = [];
14370
+
14371
+ if (connectId) {
14372
+ const device = this.devicesCache[connectId];
14373
+
14374
+ if (device) {
14375
+ const exist = descriptorList.find(d => d.path === device.originalDescriptor.path);
14376
+
14377
+ if (exist) {
14378
+ Log$6.debug('find existed Device: ', connectId);
14379
+ device.updateDescriptor(exist, true);
14380
+ devices[connectId] = device;
14381
+ deviceList.push(device);
14382
+ yield this._checkDevicePool();
14383
+ return {
14384
+ devices,
14385
+ deviceList
14386
+ };
14387
+ }
14388
+
14389
+ Log$6.debug('found device in cache, but path is different: ', connectId);
14390
+ }
14391
+ }
14392
+
14393
+ try {
14394
+ for (descriptorList_1 = __asyncValues(descriptorList); descriptorList_1_1 = yield descriptorList_1.next(), !descriptorList_1_1.done;) {
14395
+ const descriptor = descriptorList_1_1.value;
14396
+ const device = yield this._createDevice(descriptor);
14397
+
14398
+ if (device.features) {
14399
+ const uuid = getDeviceUUID(device.features);
14400
+
14401
+ if (this.devicesCache[uuid]) {
14402
+ const cache = this.devicesCache[uuid];
14403
+ cache.updateDescriptor(descriptor, true);
14404
+ }
14405
+
14406
+ this.devicesCache[uuid] = device;
14407
+ devices[uuid] = device;
14408
+ }
14409
+
14410
+ deviceList.push(device);
14411
+ }
14412
+ } catch (e_1_1) {
14413
+ e_1 = {
14414
+ error: e_1_1
14415
+ };
14416
+ } finally {
14417
+ try {
14418
+ if (descriptorList_1_1 && !descriptorList_1_1.done && (_a = descriptorList_1.return)) yield _a.call(descriptorList_1);
14419
+ } finally {
14420
+ if (e_1) throw e_1.error;
14421
+ }
14422
+ }
14423
+
14424
+ Log$6.debug('get devices result : ', devices, deviceList);
14425
+ console.log('device poll -> connected: ', this.connectedPool);
14426
+ console.log('device poll -> disconnected: ', this.disconnectPool);
14427
+ yield this._checkDevicePool();
14428
+ return {
14429
+ devices,
14430
+ deviceList
14431
+ };
14432
+ });
14433
+ }
14434
+
14435
+ static _createDevice(descriptor) {
14436
+ return __awaiter(this, void 0, void 0, function* () {
14437
+ let device = this.getDeviceByPath(descriptor.path);
14438
+
14439
+ if (!device) {
14440
+ device = Device.fromDescriptor(descriptor);
14441
+ device.deviceConnector = this.connector;
14442
+ yield device.connect();
14443
+ yield device.initialize();
14444
+ yield device.release();
14445
+ }
14446
+
14447
+ return device;
14448
+ });
14449
+ }
14450
+
14451
+ static _checkDevicePool() {
14452
+ return __awaiter(this, void 0, void 0, function* () {
14453
+ yield this._sendConnectMessage();
14454
+
14455
+ this._sendDisconnectMessage();
14456
+ });
14457
+ }
14458
+
14459
+ static _sendConnectMessage() {
14460
+ return __awaiter(this, void 0, void 0, function* () {
14461
+ for (let i = this.connectedPool.length - 1; i >= 0; i--) {
14462
+ const descriptor = this.connectedPool[i];
14463
+ const device = yield this._createDevice(descriptor);
14464
+ Log$6.debug('emit DEVICE.CONNECT: ', device);
14465
+ this.emitter.emit(DEVICE.CONNECT, device);
14466
+ this.connectedPool.splice(i, 1);
14467
+ }
14468
+ });
14469
+ }
14470
+
14471
+ static _sendDisconnectMessage() {
14472
+ for (let i = this.disconnectPool.length - 1; i >= 0; i--) {
14473
+ const descriptor = this.connectedPool[i];
14474
+ const device = this.getDeviceByPath(descriptor.path);
14475
+
14476
+ if (device) {
14477
+ this.emitter.emit(DEVICE.DISCONNECT, device);
14478
+ }
14479
+
14480
+ this.disconnectPool.splice(i, 1);
14481
+ }
14482
+ }
14483
+
14484
+ static reportDeviceChange(upcoming) {
14485
+ const diff = getDiff(this.current || [], upcoming);
14486
+ this.upcoming = upcoming;
14487
+ this.current = this.upcoming;
14488
+ console.log('device pool -> current: ', this.current);
14489
+ console.log('device pool -> upcomming: ', this.upcoming);
14490
+ console.log('DeviceCache.reportDeviceChange diff: ', diff);
14491
+
14492
+ if (!diff.didUpdate) {
14493
+ return;
14494
+ }
14495
+
14496
+ diff.connected.forEach(d => {
14497
+ const device = this.getDeviceByPath(d.path);
14498
+
14499
+ if (!device) {
14500
+ this._addConnectedDeviceToPool(d);
14501
+
14502
+ return;
14503
+ }
14504
+
14505
+ Log$6.debug('emit DEVICE.CONNECT: ', device);
14506
+ this.emitter.emit(DEVICE.CONNECT, device);
14507
+ });
14508
+ diff.disconnected.forEach(d => {
14509
+ this._removeDeviceFromConnectedPool(d.path);
14510
+
14511
+ const device = this.getDeviceByPath(d.path);
14512
+
14513
+ if (!device) {
14514
+ this._addDisconnectedDeviceToPool(d);
14515
+
14516
+ return;
14517
+ }
14518
+
14519
+ Log$6.debug('emit DEVICE.DISCONNECT: ', device);
14520
+ this.emitter.emit(DEVICE.DISCONNECT, device);
14521
+ });
14522
+ }
14523
+
14524
+ static getDeviceByPath(path) {
14525
+ return Object.values(this.devicesCache).find(d => d.originalDescriptor.path === path);
14526
+ }
14527
+
14528
+ static _addConnectedDeviceToPool(descriptor) {
14529
+ const existDescriptorIndex = this.connectedPool.findIndex(d => d.path === descriptor.path);
14530
+
14531
+ if (existDescriptorIndex > -1) {
14532
+ this.connectedPool.splice(existDescriptorIndex, 1, descriptor);
14533
+ return;
14534
+ }
14535
+
14536
+ this.connectedPool.push(descriptor);
14537
+ }
14538
+
14539
+ static _removeDeviceFromConnectedPool(path) {
14540
+ const index = this.connectedPool.findIndex(d => d.path === path);
14541
+
14542
+ if (index > -1) {
14543
+ this.connectedPool.splice(index, 1);
14544
+ }
14545
+ }
14546
+
14547
+ static _addDisconnectedDeviceToPool(descriptor) {
14548
+ const existDescriptorIndex = this.disconnectPool.findIndex(d => d.path === descriptor.path);
14549
+
14550
+ if (existDescriptorIndex > -1) {
14551
+ this.disconnectPool.splice(existDescriptorIndex, 1, descriptor);
14552
+ return;
14553
+ }
14554
+
14555
+ this.disconnectPool.push(descriptor);
14556
+ }
14557
+
14558
+ }
14559
+
14560
+ DevicePool.current = null;
14561
+ DevicePool.upcoming = [];
14562
+ DevicePool.connectedPool = [];
14563
+ DevicePool.disconnectPool = [];
14564
+ DevicePool.devicesCache = {};
14565
+ DevicePool.emitter = new events.exports();
14566
+ const Log$5 = getLogger(exports.d0.Transport);
14567
+ const BleLogger = getLogger(exports.d0.HdBleTransport);
14568
+ const HttpLogger = getLogger(exports.d0.HdTransportHttp);
14569
+
14570
+ class TransportManager {
14571
+ static load() {
14572
+ Log$5.debug('transport manager load');
14573
+ this.defaultMessages = DataManager.getProtobufMessages();
14574
+ this.currentMessages = this.defaultMessages;
14575
+ }
14576
+
14577
+ static configure() {
14578
+ return __awaiter(this, void 0, void 0, function* () {
14579
+ try {
14580
+ const env = DataManager.getSettings('env');
14581
+ Log$5.debug('Initializing transports');
14582
+
14583
+ if (env === 'react-native') {
14584
+ if (!this.reactNativeInit) {
14585
+ yield this.transport.init(BleLogger, DevicePool.emitter);
14586
+ this.reactNativeInit = true;
14587
+ } else {
14588
+ Log$5.debug('React Native Do Not Initializing transports');
14589
+ }
14590
+ } else {
14591
+ yield this.transport.init(HttpLogger);
14592
+ }
14593
+
14594
+ Log$5.debug('Configuring transports');
14595
+ yield this.transport.configure(JSON.stringify(this.defaultMessages));
14596
+ Log$5.debug('Configuring transports done');
14597
+ } catch (error) {
14598
+ Log$5.debug('Initializing transports error: ', error);
14599
+
14600
+ if (error.code === 'ECONNABORTED') {
14601
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
14602
+ }
14603
+ }
14604
+ });
14605
+ }
14606
+
14607
+ static reconfigure(messages) {
14608
+ return __awaiter(this, void 0, void 0, function* () {
14609
+ if (Array.isArray(messages)) {
14610
+ messages = DataManager.getProtobufMessages();
14611
+ }
14612
+
14613
+ if (this.currentMessages === messages || !messages) {
14614
+ return;
14615
+ }
14616
+
14617
+ try {
14618
+ yield this.transport.configure(JSON.stringify(messages));
14619
+ this.currentMessages = messages;
14620
+ } catch (error) {
14621
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportInvalidProtobuf, `Transport_InvalidProtobuf: ${error.message}`);
14622
+ }
14623
+ });
14624
+ }
14625
+
14626
+ static setTransport(TransportConstructor) {
14627
+ const env = DataManager.getSettings('env');
14628
+
14629
+ if (env === 'react-native') {
14630
+ this.transport = new TransportConstructor({
14631
+ scanTimeout: 3000
14632
+ });
14633
+ } else {
14634
+ this.transport = new TransportConstructor();
14635
+ }
14636
+
14637
+ Log$5.debug('set transport: ', this.transport);
14638
+ }
14639
+
14640
+ static getTransport() {
14641
+ return this.transport;
14642
+ }
14643
+
14644
+ static getDefaultMessages() {
14645
+ return this.defaultMessages;
14646
+ }
14647
+
14648
+ static getCurrentMessages() {
14649
+ return this.currentMessages;
14650
+ }
14651
+
14652
+ }
14653
+
14654
+ TransportManager.reactNativeInit = false;
14655
+
14375
14656
  const assertType = (res, resType) => {
14376
14657
  const splitResTypes = Array.isArray(resType) ? resType : resType.split('|');
14377
14658
 
@@ -14523,8 +14804,13 @@ class DeviceCommands {
14523
14804
  }
14524
14805
 
14525
14806
  if (res.type === 'EntropyRequest') ;
14807
+ const isWebusbEnv = DataManager.getSettings('env') === 'webusb';
14526
14808
 
14527
14809
  if (res.type === 'PinMatrixRequest') {
14810
+ if (isWebusbEnv) {
14811
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Please unlock your device'));
14812
+ }
14813
+
14528
14814
  return this._promptPin(res.message.type).then(pin => {
14529
14815
  if (pin === '@@ONEKEY_INPUT_PIN_IN_DEVICE') {
14530
14816
  return this._commonCall('BixinPinInputOnDevice');
@@ -14579,7 +14865,7 @@ const UI_REQUEST = {
14579
14865
  FIRMWARE_NOT_INSTALLED: 'ui-device_firmware_not_installed',
14580
14866
  NOT_USE_ONEKEY_DEVICE: 'ui-device_please_use_onekey_device'
14581
14867
  };
14582
- const DEFAULT_DOMAIN = `https://jssdk.onekey.so/${"0.1.25"}/`;
14868
+ const DEFAULT_DOMAIN = `https://jssdk.onekey.so/${"0.1.28"}/`;
14583
14869
  const DEFAULT_PRIORITY = 2;
14584
14870
  const initialSettings = {
14585
14871
  configSrc: './data/config.json',
@@ -15073,9 +15359,6 @@ class Device extends events.exports {
15073
15359
 
15074
15360
  }
15075
15361
 
15076
- const cacheDeviceMap = {};
15077
- const Log$2 = getLogger(exports.d0.DeviceList);
15078
-
15079
15362
  class DeviceList extends events.exports {
15080
15363
  constructor() {
15081
15364
  super(...arguments);
@@ -15083,67 +15366,17 @@ class DeviceList extends events.exports {
15083
15366
  }
15084
15367
 
15085
15368
  getDeviceLists(connectId) {
15086
- var e_1, _a;
15087
-
15088
- var _b, _c;
15369
+ var _a, _b;
15089
15370
 
15090
15371
  return __awaiter(this, void 0, void 0, function* () {
15091
- const deviceDiff = yield (_b = this.connector) === null || _b === void 0 ? void 0 : _b.enumerate();
15092
- const descriptorList = (_c = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _c !== void 0 ? _c : [];
15372
+ const deviceDiff = yield (_a = this.connector) === null || _a === void 0 ? void 0 : _a.enumerate();
15373
+ const descriptorList = (_b = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _b !== void 0 ? _b : [];
15093
15374
  this.devices = {};
15094
- const deviceList = [];
15095
- Log$2.debug('get device list');
15096
-
15097
- if (connectId) {
15098
- const device = cacheDeviceMap[connectId];
15099
-
15100
- if (device) {
15101
- const exist = descriptorList.find(d => d.path === device.originalDescriptor.path);
15102
-
15103
- if (exist) {
15104
- device.updateDescriptor(exist, true);
15105
- Log$2.debug('find existed Device: ', connectId);
15106
- this.devices[connectId] = device;
15107
- return [device];
15108
- }
15109
- }
15110
- }
15111
-
15112
- try {
15113
- for (var descriptorList_1 = __asyncValues(descriptorList), descriptorList_1_1; descriptorList_1_1 = yield descriptorList_1.next(), !descriptorList_1_1.done;) {
15114
- const descriptor = descriptorList_1_1.value;
15115
- let device = Device.fromDescriptor(descriptor);
15116
- device.deviceConnector = this.connector;
15117
- yield device.connect();
15118
- yield device.initialize();
15119
- yield device.release();
15120
- deviceList.push(device);
15121
-
15122
- if (device.features) {
15123
- const uuid = getDeviceUUID(device.features);
15124
-
15125
- if (cacheDeviceMap[uuid]) {
15126
- const cache = cacheDeviceMap[uuid];
15127
- cache === null || cache === void 0 ? void 0 : cache.updateFromCache(device);
15128
- device = cache;
15129
- }
15130
-
15131
- this.devices[uuid] = device;
15132
- cacheDeviceMap[uuid] = device;
15133
- }
15134
- }
15135
- } catch (e_1_1) {
15136
- e_1 = {
15137
- error: e_1_1
15138
- };
15139
- } finally {
15140
- try {
15141
- if (descriptorList_1_1 && !descriptorList_1_1.done && (_a = descriptorList_1.return)) yield _a.call(descriptorList_1);
15142
- } finally {
15143
- if (e_1) throw e_1.error;
15144
- }
15145
- }
15146
-
15375
+ const {
15376
+ deviceList,
15377
+ devices
15378
+ } = yield DevicePool.getDevices(descriptorList, connectId);
15379
+ this.devices = devices;
15147
15380
  return deviceList;
15148
15381
  });
15149
15382
  }
@@ -15218,6 +15451,15 @@ class BaseMethod {
15218
15451
  })));
15219
15452
  }
15220
15453
 
15454
+ checkDeviceSupportFeature() {
15455
+ if (!this.device || !this.device.features) return;
15456
+ const inputPinOnSoftware = supportInputPinOnSoftware(this.device.features);
15457
+ this.postMessage(createDeviceMessage(DEVICE.SUPPORT_FEATURES, {
15458
+ inputPinOnSoftware,
15459
+ device: this.device.toMessageObject()
15460
+ }));
15461
+ }
15462
+
15221
15463
  dispose() {}
15222
15464
 
15223
15465
  }
@@ -15228,14 +15470,12 @@ class SearchDevices extends BaseMethod {
15228
15470
  }
15229
15471
 
15230
15472
  run() {
15231
- var e_1, _a;
15232
-
15233
- var _b, _c;
15473
+ var _a, _b;
15234
15474
 
15235
15475
  return __awaiter(this, void 0, void 0, function* () {
15236
15476
  yield TransportManager.configure();
15237
- const deviceDiff = yield (_b = this.connector) === null || _b === void 0 ? void 0 : _b.enumerate();
15238
- const devicesDescriptor = (_c = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _c !== void 0 ? _c : [];
15477
+ const deviceDiff = yield (_a = this.connector) === null || _a === void 0 ? void 0 : _a.enumerate();
15478
+ const devicesDescriptor = (_b = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _b !== void 0 ? _b : [];
15239
15479
  const env = DataManager.getSettings('env');
15240
15480
 
15241
15481
  if (env === 'react-native') {
@@ -15249,31 +15489,10 @@ class SearchDevices extends BaseMethod {
15249
15489
  });
15250
15490
  }
15251
15491
 
15252
- const devices = [];
15253
-
15254
- try {
15255
- for (var devicesDescriptor_1 = __asyncValues(devicesDescriptor), devicesDescriptor_1_1; devicesDescriptor_1_1 = yield devicesDescriptor_1.next(), !devicesDescriptor_1_1.done;) {
15256
- const descriptor = devicesDescriptor_1_1.value;
15257
- const device = Device.fromDescriptor(descriptor);
15258
- device.deviceConnector = this.connector;
15259
- yield device.connect();
15260
- yield device.initialize();
15261
- yield device.release();
15262
- devices.push(device);
15263
- }
15264
- } catch (e_1_1) {
15265
- e_1 = {
15266
- error: e_1_1
15267
- };
15268
- } finally {
15269
- try {
15270
- if (devicesDescriptor_1_1 && !devicesDescriptor_1_1.done && (_a = devicesDescriptor_1.return)) yield _a.call(devicesDescriptor_1);
15271
- } finally {
15272
- if (e_1) throw e_1.error;
15273
- }
15274
- }
15275
-
15276
- return devices.map(device => device.toMessageObject());
15492
+ const {
15493
+ deviceList
15494
+ } = yield DevicePool.getDevices(devicesDescriptor);
15495
+ return deviceList.map(device => device.toMessageObject());
15277
15496
  });
15278
15497
  }
15279
15498
 
@@ -16872,6 +17091,20 @@ class DeviceUpdateReboot extends BaseMethod {
16872
17091
 
16873
17092
  }
16874
17093
 
17094
+ class DeviceSupportFeatures extends BaseMethod {
17095
+ init() {}
17096
+
17097
+ run() {
17098
+ if (!this.device.features) return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Device not initialized'));
17099
+ const inputPinOnSoftware = supportInputPinOnSoftware(this.device.features);
17100
+ return Promise.resolve({
17101
+ inputPinOnSoftware,
17102
+ device: this.device.toMessageObject()
17103
+ });
17104
+ }
17105
+
17106
+ }
17107
+
16875
17108
  class DeviceVerify extends BaseMethod {
16876
17109
  init() {
16877
17110
  validateParams(this.payload, [{
@@ -18869,6 +19102,57 @@ class FirmwareUpdate extends BaseMethod {
18869
19102
 
18870
19103
  }
18871
19104
 
19105
+ const Log$2 = getLogger(exports.d0.Method);
19106
+
19107
+ class RequestWebUsbDevice extends BaseMethod {
19108
+ init() {
19109
+ this.useDevice = false;
19110
+ }
19111
+
19112
+ run() {
19113
+ var _a, _b;
19114
+
19115
+ return __awaiter(this, void 0, void 0, function* () {
19116
+ yield TransportManager.configure();
19117
+ const env = DataManager.getSettings('env');
19118
+
19119
+ if (env !== 'webusb') {
19120
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Not webusb environment'));
19121
+ }
19122
+
19123
+ const transport = TransportManager.getTransport();
19124
+
19125
+ try {
19126
+ const device = yield transport.requestDevice();
19127
+
19128
+ if (!device) {
19129
+ return yield Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Please select the device to connect'));
19130
+ }
19131
+
19132
+ const deviceDiff = yield (_a = this.connector) === null || _a === void 0 ? void 0 : _a.enumerate();
19133
+ const devicesDescriptor = (_b = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _b !== void 0 ? _b : [];
19134
+ const {
19135
+ deviceList
19136
+ } = yield DevicePool.getDevices(devicesDescriptor);
19137
+
19138
+ const _device = deviceList.find(d => d.originalDescriptor.path === device.serialNumber);
19139
+
19140
+ if (_device) {
19141
+ return {
19142
+ device: _device.toMessageObject()
19143
+ };
19144
+ }
19145
+
19146
+ return yield Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Please select the device to connect'));
19147
+ } catch (error) {
19148
+ Log$2.debug(error);
19149
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Please select the device to connect'));
19150
+ }
19151
+ });
19152
+ }
19153
+
19154
+ }
19155
+
18872
19156
  class CheckBridgeStatus extends BaseMethod {
18873
19157
  init() {
18874
19158
  this.useDevice = false;
@@ -18905,6 +19189,7 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
18905
19189
  deviceReset: DeviceReset,
18906
19190
  deviceSettings: DeviceSettings,
18907
19191
  deviceUpdateReboot: DeviceUpdateReboot,
19192
+ deviceSupportFeatures: DeviceSupportFeatures,
18908
19193
  deviceVerify: DeviceVerify,
18909
19194
  deviceWipe: DeviceWipe,
18910
19195
  evmGetAddress: EvmGetAddress,
@@ -18926,6 +19211,7 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
18926
19211
  stellarGetAddress: StellarGetAddress,
18927
19212
  stellarSignTransaction: StellarSignTransaction,
18928
19213
  firmwareUpdate: FirmwareUpdate,
19214
+ requestWebUsbDevice: RequestWebUsbDevice,
18929
19215
  getLogs: CheckBridgeStatus
18930
19216
  });
18931
19217
 
@@ -18965,54 +19251,6 @@ const resolveAfter = (msec, value) => new Promise(resolve => {
18965
19251
 
18966
19252
  const Log$1 = getLogger(exports.d0.DeviceConnector);
18967
19253
 
18968
- const getDiff = (current, descriptors) => {
18969
- const env = DataManager.getSettings('env');
18970
-
18971
- if (env === 'react-native') {
18972
- return {
18973
- descriptors
18974
- };
18975
- }
18976
-
18977
- const connected = descriptors.filter(d => current.find(x => x.path === d.path) === undefined);
18978
- const disconnected = current.filter(d => descriptors.find(x => x.path === d.path) === undefined);
18979
- const changedSessions = descriptors.filter(d => {
18980
- const currentDescriptor = current.find(x => x.path === d.path);
18981
-
18982
- if (currentDescriptor) {
18983
- return currentDescriptor.session !== d.session;
18984
- }
18985
-
18986
- return false;
18987
- });
18988
- const acquired = changedSessions.filter(d => typeof d.session === 'string');
18989
- const released = changedSessions.filter(d => typeof d.session !== 'string');
18990
- const changedDebugSessions = descriptors.filter(d => {
18991
- const currentDescriptor = current.find(x => x.path === d.path);
18992
-
18993
- if (currentDescriptor) {
18994
- return currentDescriptor.debugSession !== d.debugSession;
18995
- }
18996
-
18997
- return false;
18998
- });
18999
- const debugAcquired = changedSessions.filter(d => typeof d.debugSession === 'string');
19000
- const debugReleased = changedSessions.filter(d => typeof d.debugSession !== 'string');
19001
- const didUpdate = connected.length + disconnected.length + changedSessions.length + changedDebugSessions.length > 0;
19002
- return {
19003
- connected,
19004
- disconnected,
19005
- changedSessions,
19006
- acquired,
19007
- released,
19008
- changedDebugSessions,
19009
- debugAcquired,
19010
- debugReleased,
19011
- didUpdate,
19012
- descriptors
19013
- };
19014
- };
19015
-
19016
19254
  class DeviceConnector {
19017
19255
  constructor() {
19018
19256
  this.listenTimestamp = 0;
@@ -19021,17 +19259,20 @@ class DeviceConnector {
19021
19259
  this.listening = false;
19022
19260
  TransportManager.load();
19023
19261
  this.transport = TransportManager.getTransport();
19262
+ DevicePool.setConnector(this);
19024
19263
  }
19025
19264
 
19026
19265
  enumerate() {
19027
19266
  return __awaiter(this, void 0, void 0, function* () {
19028
19267
  try {
19029
- this.upcoming = yield this.transport.enumerate();
19268
+ const descriptors = yield this.transport.enumerate();
19269
+ this.upcoming = descriptors;
19030
19270
 
19031
- const diff = this._reportDevicesChange();
19271
+ this._reportDevicesChange();
19032
19272
 
19033
- Log$1.debug('diff result: ', diff);
19034
- return diff;
19273
+ return {
19274
+ descriptors
19275
+ };
19035
19276
  } catch (error) {
19036
19277
  safeThrowError(error);
19037
19278
  }
@@ -19112,9 +19353,7 @@ class DeviceConnector {
19112
19353
  }
19113
19354
 
19114
19355
  _reportDevicesChange() {
19115
- const diff = getDiff(this.current || [], this.upcoming);
19116
- this.current = this.upcoming;
19117
- return diff;
19356
+ DevicePool.reportDeviceChange(this.upcoming);
19118
19357
  }
19119
19358
 
19120
19359
  }
@@ -19155,6 +19394,8 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
19155
19394
  return Promise.reject(error);
19156
19395
  }
19157
19396
 
19397
+ DevicePool.emitter.on(DEVICE.CONNECT, onDeviceConnectHandler);
19398
+
19158
19399
  if (!method.useDevice) {
19159
19400
  try {
19160
19401
  const response = yield method.run();
@@ -19205,11 +19446,17 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
19205
19446
  const currentVersion = getDeviceFirmwareVersion(device.features).join('.');
19206
19447
 
19207
19448
  if (semver__default["default"].valid(versionRange.min) && semver__default["default"].lt(currentVersion, versionRange.min)) {
19208
- return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceFwException, `Device firmware version is too low, please update to ${versionRange.min}`));
19449
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodNeedUpgradeFirmware, `Device firmware version is too low, please update to ${versionRange.min}`, {
19450
+ current: currentVersion,
19451
+ require: versionRange.min
19452
+ }));
19209
19453
  }
19210
19454
 
19211
- if (versionRange.max && semver__default["default"].valid(versionRange.max) && semver__default["default"].gt(currentVersion, versionRange.max)) {
19212
- return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceFwException, `Device firmware version is too high, this method has been deprecated in ${versionRange.max}`));
19455
+ if (versionRange.max && semver__default["default"].valid(versionRange.max) && semver__default["default"].gte(currentVersion, versionRange.max)) {
19456
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodDeprecated, `Device firmware version is too high, this method has been deprecated in ${versionRange.max}`, {
19457
+ current: currentVersion,
19458
+ deprecated: versionRange.max
19459
+ }));
19213
19460
  }
19214
19461
  }
19215
19462
 
@@ -19232,6 +19479,7 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
19232
19479
  }
19233
19480
 
19234
19481
  method.checkFirmwareRelease();
19482
+ method.checkDeviceSupportFeature();
19235
19483
 
19236
19484
  if (_deviceList) {
19237
19485
  yield TransportManager.reconfigure(device.getFirmwareVersion());
@@ -19489,12 +19737,29 @@ const removeDeviceListener = device => {
19489
19737
  device.removeListener(DEVICE.PIN, onDevicePinHandler);
19490
19738
  device.removeListener(DEVICE.BUTTON, onDeviceButtonHandler);
19491
19739
  device.removeListener(DEVICE.FEATURES, onDeviceFeaturesHandler);
19740
+ DevicePool.emitter.removeListener(DEVICE.CONNECT, onDeviceConnectHandler);
19492
19741
  };
19493
19742
 
19494
19743
  const closePopup = () => {
19495
19744
  postMessage(createUiMessage(UI_REQUEST$1.CLOSE_UI_WINDOW));
19496
19745
  };
19497
19746
 
19747
+ const onDeviceConnectHandler = device => {
19748
+ const env = DataManager.getSettings('env');
19749
+ const deviceObject = env === 'react-native' ? device : device.toMessageObject();
19750
+ postMessage(createDeviceMessage(DEVICE.CONNECT, {
19751
+ device: deviceObject
19752
+ }));
19753
+ };
19754
+
19755
+ const onDeviceDisconnectHandler = device => {
19756
+ const env = DataManager.getSettings('env');
19757
+ const deviceObject = env === 'react-native' ? device : device.toMessageObject();
19758
+ postMessage(createDeviceMessage(DEVICE.DISCONNECT, {
19759
+ device: deviceObject
19760
+ }));
19761
+ };
19762
+
19498
19763
  const onDevicePinHandler = (...[device, type, callback]) => __awaiter(void 0, void 0, void 0, function* () {
19499
19764
  Log.debug('onDevicePinHandler');
19500
19765
  const uiPromise = createUiPromise(UI_RESPONSE.RECEIVE_PIN, device);
@@ -19596,6 +19861,7 @@ const initCore = () => {
19596
19861
 
19597
19862
  const initConnector = () => {
19598
19863
  _connector = new DeviceConnector();
19864
+ DevicePool.emitter.on(DEVICE.DISCONNECT, onDeviceDisconnectHandler);
19599
19865
  return _connector;
19600
19866
  };
19601
19867
 
@@ -19952,6 +20218,19 @@ const readHeader = buffer => {
19952
20218
  };
19953
20219
  };
19954
20220
 
20221
+ const readHeaderChunked = buffer => {
20222
+ const sharp1 = buffer.readByte();
20223
+ const sharp2 = buffer.readByte();
20224
+ const typeId = buffer.readUint16();
20225
+ const length = buffer.readUint32();
20226
+ return {
20227
+ sharp1,
20228
+ sharp2,
20229
+ typeId,
20230
+ length
20231
+ };
20232
+ };
20233
+
19955
20234
  const decode = byteBuffer => {
19956
20235
  const {
19957
20236
  typeId
@@ -19962,6 +20241,32 @@ const decode = byteBuffer => {
19962
20241
  };
19963
20242
  };
19964
20243
 
20244
+ const decodeChunked = bytes => {
20245
+ const byteBuffer = ByteBuffer__default["default"].wrap(bytes, undefined, undefined, true);
20246
+ const {
20247
+ sharp1,
20248
+ sharp2,
20249
+ typeId,
20250
+ length
20251
+ } = readHeaderChunked(byteBuffer);
20252
+
20253
+ if (sharp1 !== MESSAGE_HEADER_BYTE || sharp2 !== MESSAGE_HEADER_BYTE) {
20254
+ throw new Error("Didn't receive expected header signature.");
20255
+ }
20256
+
20257
+ return {
20258
+ length,
20259
+ typeId,
20260
+ restBuffer: byteBuffer
20261
+ };
20262
+ };
20263
+
20264
+ var decodeProtocol = /*#__PURE__*/Object.freeze({
20265
+ __proto__: null,
20266
+ decode: decode,
20267
+ decodeChunked: decodeChunked
20268
+ });
20269
+
19965
20270
  function encode(data, options) {
19966
20271
  const {
19967
20272
  addTrezorHeaders,
@@ -20013,17 +20318,21 @@ function buildOne(messages, name, data) {
20013
20318
  });
20014
20319
  }
20015
20320
 
20016
- const buildBuffers = (messages, name, data) => {
20321
+ const buildEncodeBuffers = (messages, name, data) => {
20017
20322
  const {
20018
20323
  Message,
20019
20324
  messageType
20020
20325
  } = createMessageFromName(messages, name);
20021
20326
  const buffer = encode$1(Message, data);
20022
- const encodeBuffers = encode(buffer, {
20327
+ return encode(buffer, {
20023
20328
  addTrezorHeaders: true,
20024
20329
  chunked: true,
20025
20330
  messageType
20026
20331
  });
20332
+ };
20333
+
20334
+ const buildBuffers = (messages, name, data) => {
20335
+ const encodeBuffers = buildEncodeBuffers(messages, name, data);
20027
20336
  const outBuffers = [];
20028
20337
 
20029
20338
  for (const buf of encodeBuffers) {
@@ -20706,8 +21015,10 @@ var index = {
20706
21015
  check,
20707
21016
  buildOne,
20708
21017
  buildBuffers,
21018
+ buildEncodeBuffers,
20709
21019
  receiveOne,
20710
- parseConfigure
21020
+ parseConfigure,
21021
+ decodeProtocol
20711
21022
  };
20712
21023
  exports.BUFFER_SIZE = BUFFER_SIZE;
20713
21024
  exports.COMMON_HEADER_SIZE = COMMON_HEADER_SIZE;
@@ -20816,6 +21127,7 @@ class HardwareError extends Error {
20816
21127
  super();
20817
21128
  this.errorCode = HardwareErrorCode.UnknownError;
20818
21129
  this.message = '';
21130
+ this.params = {};
20819
21131
  const errorMessageMapping = HardwareErrorCodeMessage;
20820
21132
  this.message = errorMessageMapping[HardwareErrorCode.UnknownError];
20821
21133
 
@@ -20829,6 +21141,7 @@ class HardwareError extends Error {
20829
21141
  this.message = fillStringWithArguments(message, hardwareError);
20830
21142
  }
20831
21143
 
21144
+ this.params = hardwareError.params;
20832
21145
  this.errorCode = hardwareError.errorCode;
20833
21146
  }
20834
21147
 
@@ -20860,6 +21173,8 @@ const HardwareErrorCode = {
20860
21173
  CallMethodNotResponse: 404,
20861
21174
  CallMethodInvalidParameter: 405,
20862
21175
  FirmwareUpdateDownloadFailed: 406,
21176
+ CallMethodNeedUpgradeFirmware: 407,
21177
+ CallMethodDeprecated: 408,
20863
21178
  NetworkError: 500,
20864
21179
  TransportNotConfigured: 600,
20865
21180
  TransportCallInProgress: 601,
@@ -20911,6 +21226,8 @@ const HardwareErrorCodeMessage = {
20911
21226
  [HardwareErrorCode.CallMethodNotResponse]: 'Method does not responding',
20912
21227
  [HardwareErrorCode.CallMethodInvalidParameter]: 'Call method invalid parameter',
20913
21228
  [HardwareErrorCode.FirmwareUpdateDownloadFailed]: 'Firmware update download failed',
21229
+ [HardwareErrorCode.CallMethodNeedUpgradeFirmware]: 'Call method need upgrade firmware',
21230
+ [HardwareErrorCode.CallMethodDeprecated]: 'Call method is deprecated',
20914
21231
  [HardwareErrorCode.NetworkError]: 'Network request error',
20915
21232
  [HardwareErrorCode.TransportNotConfigured]: 'Transport not configured',
20916
21233
  [HardwareErrorCode.TransportCallInProgress]: 'Transport call in progress',
@@ -20940,14 +21257,15 @@ const HardwareErrorCodeMessage = {
20940
21257
  [HardwareErrorCode.PollingStop]: 'Polling stop'
20941
21258
  };
20942
21259
 
20943
- const TypedError = (hardwareError, message) => {
21260
+ const TypedError = (hardwareError, message, params) => {
20944
21261
  if (typeof hardwareError === 'string') {
20945
21262
  return new HardwareError(hardwareError);
20946
21263
  }
20947
21264
 
20948
21265
  return new HardwareError({
20949
21266
  errorCode: hardwareError,
20950
- message: message !== null && message !== void 0 ? message : ''
21267
+ message: message !== null && message !== void 0 ? message : '',
21268
+ params
20951
21269
  });
20952
21270
  };
20953
21271
 
@@ -20955,7 +21273,8 @@ const serializeError = payload => {
20955
21273
  if (payload && payload.error instanceof HardwareError) {
20956
21274
  return {
20957
21275
  error: payload.error.message,
20958
- code: payload.error.errorCode
21276
+ code: payload.error.errorCode,
21277
+ params: payload.error.params
20959
21278
  };
20960
21279
  }
20961
21280
 
@@ -44733,6 +45052,7 @@ var IInjectedProviderNames;
44733
45052
  IInjectedProviderNames["ethereum"] = "ethereum";
44734
45053
  IInjectedProviderNames["conflux"] = "conflux";
44735
45054
  IInjectedProviderNames["solana"] = "solana";
45055
+ IInjectedProviderNames["starcoin"] = "starcoin";
44736
45056
  IInjectedProviderNames["sollet"] = "sollet";
44737
45057
  IInjectedProviderNames["near"] = "near";
44738
45058
  IInjectedProviderNames["$private"] = "$private";
@@ -45164,7 +45484,7 @@ function parseOpts(arg) {
45164
45484
 
45165
45485
 
45166
45486
  ;// CONCATENATED MODULE: ../../node_modules/@onekeyfe/cross-inpage-provider-core/dist/versionInfo.js
45167
- const version = '0.0.14';
45487
+ const version = '0.0.17';
45168
45488
  const versionBuild = '2020-0101-1';
45169
45489
  /* harmony default export */ const dist_versionInfo = ({
45170
45490
  version,
@@ -45870,6 +46190,12 @@ class JsBridgeSimple extends (/* unused pure expression or super */ null && (JsB
45870
46190
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
45871
46191
 
45872
46192
  let postMessageListenerAdded = false;
46193
+ /**
46194
+ * When the JsBridgeIframe instance changes, the tag can be changed manually
46195
+ */
46196
+ function setPostMessageListenerFlag(value) {
46197
+ postMessageListenerAdded = value;
46198
+ }
45873
46199
  function setupPostMessageListener(options = {}) {
45874
46200
  if (postMessageListenerAdded) {
45875
46201
  return;
@@ -46006,6 +46332,7 @@ let frameBridge; // eslint-disable-next-line import/no-mutable-exports
46006
46332
 
46007
46333
  let hostBridge;
46008
46334
  const Log = (0,dist/* getLogger */.jl)(dist/* LoggerNames.SendMessage */.d0.SendMessage);
46335
+ const resetListenerFlag = () => setPostMessageListenerFlag(false);
46009
46336
  const createJsBridge = params => {
46010
46337
  const bridge = new JsBridgeIframe(params);
46011
46338
 
@@ -46074,7 +46401,7 @@ const handleMessage = async message => {
46074
46401
  break;
46075
46402
 
46076
46403
  case dist/* DEVICE_EVENT */.Fd:
46077
- if (message.type === dist/* DEVICE.FEATURES */.Td.FEATURES) {
46404
+ if ([dist/* DEVICE.CONNECT */.Td.CONNECT, dist/* DEVICE.DISCONNECT */.Td.DISCONNECT, dist/* DEVICE.FEATURES */.Td.FEATURES, dist/* DEVICE.SUPPORT_FEATURES */.Td.SUPPORT_FEATURES].includes(message.type)) {
46078
46405
  eventEmitter.emit(message.type, message.payload);
46079
46406
  }
46080
46407
 
@@ -46118,17 +46445,22 @@ const cancel = connectId => {
46118
46445
  });
46119
46446
  };
46120
46447
 
46448
+ let prevFrameInstance = null;
46449
+
46121
46450
  const createJSBridge = messageEvent => {
46451
+ var _iframe$instance;
46452
+
46122
46453
  if (messageEvent.origin !== origin) {
46123
46454
  return;
46124
46455
  }
46125
46456
 
46126
- if (!hostBridge) {
46127
- var _iframe$instance;
46457
+ if (!hostBridge || prevFrameInstance !== ((_iframe$instance = instance) === null || _iframe$instance === void 0 ? void 0 : _iframe$instance.contentWindow)) {
46458
+ var _iframe$instance2, _iframe$instance3;
46128
46459
 
46460
+ resetListenerFlag();
46129
46461
  createJsBridge({
46130
46462
  isHost: true,
46131
- remoteFrame: (_iframe$instance = instance) === null || _iframe$instance === void 0 ? void 0 : _iframe$instance.contentWindow,
46463
+ remoteFrame: (_iframe$instance2 = instance) === null || _iframe$instance2 === void 0 ? void 0 : _iframe$instance2.contentWindow,
46132
46464
  remoteFrameName: bridge_config.iframeName,
46133
46465
  selfFrameName: bridge_config.hostName,
46134
46466
  channel: bridge_config.channel,
@@ -46149,6 +46481,7 @@ const createJSBridge = messageEvent => {
46149
46481
  return response;
46150
46482
  }
46151
46483
  });
46484
+ prevFrameInstance = (_iframe$instance3 = instance) === null || _iframe$instance3 === void 0 ? void 0 : _iframe$instance3.contentWindow;
46152
46485
  }
46153
46486
  };
46154
46487
 
@@ -46168,7 +46501,7 @@ const src_init = async settings => {
46168
46501
 
46169
46502
  try {
46170
46503
  await init({ ..._settings,
46171
- version: "0.1.25"
46504
+ version: "0.1.28"
46172
46505
  });
46173
46506
  return true;
46174
46507
  } catch (e) {