@onekeyfe/hd-core 1.0.37 → 1.0.38-alpha.2

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.
Files changed (61) hide show
  1. package/dist/api/GetPassphraseState.d.ts +1 -1
  2. package/dist/api/allnetwork/AllNetworkGetAddress.d.ts +3 -1
  3. package/dist/api/allnetwork/AllNetworkGetAddress.d.ts.map +1 -1
  4. package/dist/api/device/DeviceUnlock.d.ts +7 -0
  5. package/dist/api/device/DeviceUnlock.d.ts.map +1 -0
  6. package/dist/api/index.d.ts +1 -0
  7. package/dist/api/index.d.ts.map +1 -1
  8. package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
  9. package/dist/core/index.d.ts.map +1 -1
  10. package/dist/data-manager/DataManager.d.ts.map +1 -1
  11. package/dist/data-manager/TransportManager.d.ts.map +1 -1
  12. package/dist/device/Device.d.ts +9 -4
  13. package/dist/device/Device.d.ts.map +1 -1
  14. package/dist/device/DeviceCommands.d.ts +7 -5
  15. package/dist/device/DeviceCommands.d.ts.map +1 -1
  16. package/dist/events/device.d.ts +3 -0
  17. package/dist/events/device.d.ts.map +1 -1
  18. package/dist/events/ui-request.d.ts +2 -1
  19. package/dist/events/ui-request.d.ts.map +1 -1
  20. package/dist/events/ui-response.d.ts +1 -0
  21. package/dist/events/ui-response.d.ts.map +1 -1
  22. package/dist/index.d.ts +28 -11
  23. package/dist/index.js +204 -65
  24. package/dist/inject.d.ts.map +1 -1
  25. package/dist/types/api/deviceUnlock.d.ts +4 -0
  26. package/dist/types/api/deviceUnlock.d.ts.map +1 -0
  27. package/dist/types/api/index.d.ts +2 -0
  28. package/dist/types/api/index.d.ts.map +1 -1
  29. package/dist/types/params.d.ts +1 -0
  30. package/dist/types/params.d.ts.map +1 -1
  31. package/dist/types/settings.d.ts +1 -1
  32. package/dist/types/settings.d.ts.map +1 -1
  33. package/dist/utils/deviceFeaturesUtils.d.ts +16 -2
  34. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  35. package/dist/utils/logger.d.ts +2 -0
  36. package/dist/utils/logger.d.ts.map +1 -1
  37. package/dist/utils/patch.d.ts +1 -1
  38. package/dist/utils/patch.d.ts.map +1 -1
  39. package/package.json +4 -4
  40. package/src/api/FirmwareUpdate.ts +1 -1
  41. package/src/api/GetPassphraseState.ts +4 -4
  42. package/src/api/allnetwork/AllNetworkGetAddress.ts +18 -20
  43. package/src/api/device/DeviceUnlock.ts +26 -0
  44. package/src/api/index.ts +1 -0
  45. package/src/api/stellar/StellarSignTransaction.ts +0 -3
  46. package/src/core/index.ts +17 -8
  47. package/src/data/messages/messages.json +49 -2
  48. package/src/data-manager/DataManager.ts +1 -1
  49. package/src/data-manager/TransportManager.ts +3 -0
  50. package/src/device/Device.ts +92 -20
  51. package/src/device/DeviceCommands.ts +15 -5
  52. package/src/events/device.ts +4 -0
  53. package/src/events/ui-request.ts +2 -1
  54. package/src/events/ui-response.ts +1 -0
  55. package/src/inject.ts +2 -0
  56. package/src/types/api/deviceUnlock.ts +4 -0
  57. package/src/types/api/index.ts +2 -0
  58. package/src/types/params.ts +5 -0
  59. package/src/types/settings.ts +10 -1
  60. package/src/utils/deviceFeaturesUtils.ts +65 -7
  61. package/src/utils/logger.ts +2 -0
package/dist/index.js CHANGED
@@ -73,6 +73,7 @@ const createCoreApi = (call) => ({
73
73
  getPassphraseState: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'getPassphraseState' })),
74
74
  deviceCancel: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceCancel' })),
75
75
  deviceLock: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceLock' })),
76
+ deviceUnlock: (connectId, params) => call(Object.assign(Object.assign({}, params), { useEmptyPassphrase: true, connectId, method: 'deviceUnlock' })),
76
77
  getNextU2FCounter: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'getNextU2FCounter' })),
77
78
  setU2FCounter: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'setU2FCounter' })),
78
79
  allNetworkGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'allNetworkGetAddress' })),
@@ -876,6 +877,7 @@ exports.LoggerNames = void 0;
876
877
  LoggerNames["HdTransportHttp"] = "@onekey/hd-transport-http";
877
878
  LoggerNames["HdTransportLowLevel"] = "@onekey/hd-transport-lowlevel";
878
879
  LoggerNames["HdBleTransport"] = "@onekey/hd-ble-transport";
880
+ LoggerNames["HdWebBleTransport"] = "@onekey/hd-web-ble-transport";
879
881
  LoggerNames["Connect"] = "@onekey/connect";
880
882
  LoggerNames["Iframe"] = "IFrame";
881
883
  LoggerNames["SendMessage"] = "[SendMessage]";
@@ -892,6 +894,7 @@ const LoggerMap = {
892
894
  [exports.LoggerNames.HdBleSdk]: initLog(exports.LoggerNames.HdBleSdk),
893
895
  [exports.LoggerNames.HdTransportHttp]: initLog(exports.LoggerNames.HdTransportHttp),
894
896
  [exports.LoggerNames.HdBleTransport]: initLog(exports.LoggerNames.HdBleTransport),
897
+ [exports.LoggerNames.HdWebBleTransport]: initLog(exports.LoggerNames.HdWebBleTransport),
895
898
  [exports.LoggerNames.HdTransportLowLevel]: initLog(exports.LoggerNames.HdTransportLowLevel),
896
899
  [exports.LoggerNames.Connect]: initLog(exports.LoggerNames.Connect),
897
900
  [exports.LoggerNames.Iframe]: initLog(exports.LoggerNames.Iframe),
@@ -4329,7 +4332,8 @@ var nested$1 = {
4329
4332
  ButtonRequest_Success: 17,
4330
4333
  ButtonRequest_Warning: 18,
4331
4334
  ButtonRequest_PassphraseEntry: 19,
4332
- ButtonRequest_PinEntry: 20
4335
+ ButtonRequest_PinEntry: 20,
4336
+ ButtonRequest_AttachPin: 8000
4333
4337
  }
4334
4338
  }
4335
4339
  }
@@ -4380,6 +4384,10 @@ var nested$1 = {
4380
4384
  options: {
4381
4385
  deprecated: true
4382
4386
  }
4387
+ },
4388
+ exists_attach_pin_user: {
4389
+ type: "bool",
4390
+ id: 8000
4383
4391
  }
4384
4392
  }
4385
4393
  },
@@ -4399,6 +4407,10 @@ var nested$1 = {
4399
4407
  on_device: {
4400
4408
  type: "bool",
4401
4409
  id: 3
4410
+ },
4411
+ on_device_attach_pin: {
4412
+ type: "bool",
4413
+ id: 8000
4402
4414
  }
4403
4415
  }
4404
4416
  },
@@ -7366,6 +7378,10 @@ var nested$1 = {
7366
7378
  derive_cardano: {
7367
7379
  type: "bool",
7368
7380
  id: 3
7381
+ },
7382
+ passphrase_state: {
7383
+ type: "string",
7384
+ id: 8000
7369
7385
  }
7370
7386
  }
7371
7387
  },
@@ -7746,6 +7762,14 @@ var nested$1 = {
7746
7762
  onekey_se04_state: {
7747
7763
  type: "OneKeySEState",
7748
7764
  id: 624
7765
+ },
7766
+ attach_to_pin_user: {
7767
+ type: "bool",
7768
+ id: 625
7769
+ },
7770
+ unlocked_attach_pin: {
7771
+ type: "bool",
7772
+ id: 626
7749
7773
  }
7750
7774
  },
7751
7775
  nested: {
@@ -8868,6 +8892,30 @@ var nested$1 = {
8868
8892
  }
8869
8893
  }
8870
8894
  },
8895
+ GetPassphraseState: {
8896
+ fields: {
8897
+ passphrase_state: {
8898
+ type: "string",
8899
+ id: 1
8900
+ }
8901
+ }
8902
+ },
8903
+ PassphraseState: {
8904
+ fields: {
8905
+ passphrase_state: {
8906
+ type: "string",
8907
+ id: 1
8908
+ },
8909
+ session_id: {
8910
+ type: "bytes",
8911
+ id: 2
8912
+ },
8913
+ unlocked_attach_pin: {
8914
+ type: "bool",
8915
+ id: 3
8916
+ }
8917
+ }
8918
+ },
8871
8919
  MoneroTransactionSourceEntry: {
8872
8920
  fields: {
8873
8921
  outputs: {
@@ -13492,7 +13540,9 @@ var nested$1 = {
13492
13540
  MessageType_ListResDir: 10023,
13493
13541
  MessageType_FileInfoList: 10024,
13494
13542
  MessageType_OnekeyGetFeatures: 10025,
13495
- MessageType_OnekeyFeatures: 10026
13543
+ MessageType_OnekeyFeatures: 10026,
13544
+ MessageType_GetPassphraseState: 10028,
13545
+ MessageType_PassphraseState: 10029
13496
13546
  }
13497
13547
  },
13498
13548
  google: {
@@ -24893,7 +24943,7 @@ DataManager.getTransportStatus = (localVersion) => {
24893
24943
  return isLatest ? 'valid' : 'outdated';
24894
24944
  };
24895
24945
  DataManager.getBridgeChangelog = () => { var _b; return (_b = _a$1.assets) === null || _b === void 0 ? void 0 : _b.bridge.changelog; };
24896
- DataManager.isBleConnect = (env) => env === 'react-native' || env === 'lowlevel';
24946
+ DataManager.isBleConnect = (env) => env === 'react-native' || env === 'lowlevel' || env === 'desktop-web-ble';
24897
24947
  DataManager.isWebUsbConnect = (env) => env === 'webusb';
24898
24948
 
24899
24949
  const PROTOBUF_MESSAGE_CONFIG = {
@@ -24955,21 +25005,40 @@ const supportNewPassphrase = (features) => {
24955
25005
  const currentVersion = getDeviceFirmwareVersion(features).join('.');
24956
25006
  return { support: semver__default["default"].gte(currentVersion, '2.4.0'), require: '2.4.0' };
24957
25007
  };
24958
- const getPassphraseStateWithRefreshDeviceInfo = (device) => __awaiter(void 0, void 0, void 0, function* () {
25008
+ const getPassphraseStateWithRefreshDeviceInfo = (device, options) => __awaiter(void 0, void 0, void 0, function* () {
25009
+ var _a, _b, _c, _d, _e;
24959
25010
  const { features, commands } = device;
24960
25011
  const locked = (features === null || features === void 0 ? void 0 : features.unlocked) === false;
24961
- const passphraseState = yield getPassphraseState(features, commands);
25012
+ const { passphraseState, newSession, unlockedAttachPin } = yield getPassphraseState(features, commands, Object.assign({}, options));
24962
25013
  const isModeT = getDeviceType(features) === hdShared.EDeviceType.Touch || getDeviceType(features) === hdShared.EDeviceType.Pro;
24963
25014
  const needRefreshWithPassphrase = passphraseState && (features === null || features === void 0 ? void 0 : features.passphrase_protection) !== true;
24964
25015
  const needRefreshWithLocked = isModeT && locked;
24965
25016
  if (needRefreshWithLocked || needRefreshWithPassphrase) {
24966
25017
  yield device.getFeatures();
24967
25018
  }
24968
- return passphraseState;
25019
+ if (features === null || features === void 0 ? void 0 : features.device_id) {
25020
+ device.updateInternalState((_b = (_a = device.features) === null || _a === void 0 ? void 0 : _a.passphrase_protection) !== null && _b !== void 0 ? _b : false, passphraseState, (_d = (_c = device.features) === null || _c === void 0 ? void 0 : _c.device_id) !== null && _d !== void 0 ? _d : '', newSession, (_e = device.features) === null || _e === void 0 ? void 0 : _e.session_id);
25021
+ }
25022
+ return { passphraseState, newSession, unlockedAttachPin };
24969
25023
  });
24970
- const getPassphraseState = (features, commands) => __awaiter(void 0, void 0, void 0, function* () {
25024
+ const getPassphraseState = (features, commands, options) => __awaiter(void 0, void 0, void 0, function* () {
24971
25025
  if (!features)
24972
- return false;
25026
+ return { passphraseState: undefined, newSession: undefined, unlockedAttachPin: undefined };
25027
+ const firmwareVersion = getDeviceFirmwareVersion(features);
25028
+ const deviceType = getDeviceType(features);
25029
+ if (deviceType === hdShared.EDeviceType.Pro && semver__default["default"].gte(firmwareVersion.join('.'), '4.15.0')) {
25030
+ const { message, type } = yield commands.typedCall('GetPassphraseState', 'PassphraseState', {
25031
+ passphrase_state: (options === null || options === void 0 ? void 0 : options.onlyMainPin) ? undefined : options === null || options === void 0 ? void 0 : options.expectPassphraseState,
25032
+ });
25033
+ if (type === 'CallMethodError') {
25034
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Get the passphrase state error');
25035
+ }
25036
+ return {
25037
+ passphraseState: message.passphrase_state,
25038
+ newSession: message.session_id,
25039
+ unlockedAttachPin: message.unlocked_attach_pin,
25040
+ };
25041
+ }
24973
25042
  const { message, type } = yield commands.typedCall('GetAddress', 'Address', {
24974
25043
  address_n: [toHardened(44), toHardened(1), toHardened(0), 0, 0],
24975
25044
  coin_name: 'Testnet',
@@ -24979,7 +25048,11 @@ const getPassphraseState = (features, commands) => __awaiter(void 0, void 0, voi
24979
25048
  if (type === 'CallMethodError') {
24980
25049
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Get the passphrase state error');
24981
25050
  }
24982
- return message.address;
25051
+ return {
25052
+ passphraseState: message.address,
25053
+ newSession: undefined,
25054
+ unlockedAttachPin: undefined,
25055
+ };
24983
25056
  });
24984
25057
  const supportBatchPublicKey = (features, options) => {
24985
25058
  if (!features)
@@ -25959,6 +26032,7 @@ const Log$c = getLogger(exports.LoggerNames.Transport);
25959
26032
  const BleLogger = getLogger(exports.LoggerNames.HdBleTransport);
25960
26033
  const HttpLogger = getLogger(exports.LoggerNames.HdTransportHttp);
25961
26034
  const LowLevelLogger = getLogger(exports.LoggerNames.HdTransportLowLevel);
26035
+ const WebBleLogger = getLogger(exports.LoggerNames.HdWebBleTransport);
25962
26036
  class TransportManager {
25963
26037
  static load() {
25964
26038
  Log$c.debug('transport manager load');
@@ -25986,6 +26060,9 @@ class TransportManager {
25986
26060
  }
25987
26061
  yield this.transport.init(LowLevelLogger, DevicePool.emitter, this.plugin);
25988
26062
  }
26063
+ else if (env === 'desktop-web-ble') {
26064
+ yield this.transport.init(WebBleLogger);
26065
+ }
25989
26066
  else {
25990
26067
  yield this.transport.init(HttpLogger);
25991
26068
  }
@@ -26199,7 +26276,6 @@ class DeviceCommands {
26199
26276
  this.callPromise = promise;
26200
26277
  const res = yield promise;
26201
26278
  Log$b.debug('[DeviceCommands] [call] Received', res.type);
26202
- console.log('[DeviceCommands] [call] Received', res.type);
26203
26279
  return res;
26204
26280
  }
26205
26281
  catch (error) {
@@ -26361,8 +26437,14 @@ class DeviceCommands {
26361
26437
  }, error => Promise.reject(error));
26362
26438
  }
26363
26439
  if (res.type === 'PassphraseRequest') {
26364
- return this._promptPassphrase().then(response => {
26365
- const { passphrase, passphraseOnDevice } = response;
26440
+ const existsAttachPinUser = res.message.exists_attach_pin_user;
26441
+ return this._promptPassphrase({
26442
+ existsAttachPinUser,
26443
+ }).then(response => {
26444
+ const { passphrase, passphraseOnDevice, attachPinOnDevice } = response;
26445
+ if (attachPinOnDevice && existsAttachPinUser) {
26446
+ return this._commonCall('PassphraseAck', { on_device_attach_pin: true });
26447
+ }
26366
26448
  return !passphraseOnDevice
26367
26449
  ? this._commonCall('PassphraseAck', { passphrase })
26368
26450
  : this._commonCall('PassphraseAck', { on_device: true });
@@ -26406,7 +26488,7 @@ class DeviceCommands {
26406
26488
  }
26407
26489
  });
26408
26490
  }
26409
- _promptPassphrase() {
26491
+ _promptPassphrase(options) {
26410
26492
  return new Promise((resolve, reject) => {
26411
26493
  const cancelAndReject = (_error) => cancelDeviceInPrompt(this.device, false)
26412
26494
  .then(onCancel => {
@@ -26424,7 +26506,7 @@ class DeviceCommands {
26424
26506
  });
26425
26507
  if (this.device.listenerCount(DEVICE.PASSPHRASE) > 0) {
26426
26508
  this.device.setCancelableAction(cancelAndReject);
26427
- this.device.emit(DEVICE.PASSPHRASE, this.device, (response, error) => {
26509
+ this.device.emit(DEVICE.PASSPHRASE, this.device, options, (response, error) => {
26428
26510
  this.device.clearCancelableAction();
26429
26511
  if (error) {
26430
26512
  cancelAndReject();
@@ -26597,8 +26679,8 @@ class Device extends events.exports {
26597
26679
  }
26598
26680
  getInternalState(_deviceId) {
26599
26681
  var _a, _b;
26600
- Log$a.debug('getInternalState session param: ', `device_id: ${_deviceId}`, `features.device_id: ${(_a = this.features) === null || _a === void 0 ? void 0 : _a.device_id}`, `passphraseState: ${this.passphraseState}`);
26601
26682
  Log$a.debug('getInternalState session cache: ', deviceSessionCache);
26683
+ Log$a.debug('getInternalState session param: ', `device_id: ${_deviceId}`, `features.device_id: ${(_a = this.features) === null || _a === void 0 ? void 0 : _a.device_id}`, `passphraseState: ${this.passphraseState}`);
26602
26684
  const deviceId = _deviceId || ((_b = this.features) === null || _b === void 0 ? void 0 : _b.device_id);
26603
26685
  if (!deviceId)
26604
26686
  return undefined;
@@ -26607,18 +26689,21 @@ class Device extends events.exports {
26607
26689
  const usePassKey = this.generateStateKey(deviceId, this.passphraseState);
26608
26690
  return deviceSessionCache[usePassKey];
26609
26691
  }
26610
- tryFixInternalState(state, deviceId, sessionId = null) {
26611
- Log$a.debug('tryFixInternalState session param: ', `device_id: ${deviceId}`, `passphraseState: ${state}`, `sessionId: ${sessionId}`);
26612
- const key = `${deviceId}`;
26613
- const session = deviceSessionCache[key];
26614
- if (session) {
26615
- deviceSessionCache[this.generateStateKey(deviceId, state)] = session;
26616
- delete deviceSessionCache[key];
26692
+ updateInternalState(enablePassphrase, passphraseState, deviceId, sessionId = null, featuresSessionId = null) {
26693
+ Log$a.debug('updateInternalState session param: ', `device_id: ${deviceId}`, `enablePassphrase: ${enablePassphrase}`, `passphraseState: ${passphraseState}`, `sessionId: ${sessionId}`, `featuresSessionId: ${featuresSessionId}`);
26694
+ if (enablePassphrase) {
26695
+ if (sessionId) {
26696
+ deviceSessionCache[this.generateStateKey(deviceId, passphraseState)] = sessionId;
26697
+ }
26698
+ else if (featuresSessionId) {
26699
+ deviceSessionCache[this.generateStateKey(deviceId, passphraseState)] = featuresSessionId;
26700
+ }
26617
26701
  }
26618
- else if (sessionId) {
26619
- deviceSessionCache[this.generateStateKey(deviceId, state)] = sessionId;
26702
+ const oldKey = `${deviceId}`;
26703
+ if (deviceSessionCache[oldKey]) {
26704
+ delete deviceSessionCache[oldKey];
26620
26705
  }
26621
- Log$a.debug('tryFixInternalState session cache: ', deviceSessionCache);
26706
+ Log$a.debug('updateInternalState session cache: ', deviceSessionCache);
26622
26707
  }
26623
26708
  setInternalState(state, initSession) {
26624
26709
  var _a, _b;
@@ -26651,7 +26736,6 @@ class Device extends events.exports {
26651
26736
  }
26652
26737
  initialize(options) {
26653
26738
  return __awaiter(this, void 0, void 0, function* () {
26654
- Log$a.debug('initialize param:', options);
26655
26739
  this.passphraseState = options === null || options === void 0 ? void 0 : options.passphraseState;
26656
26740
  if (options === null || options === void 0 ? void 0 : options.initSession) {
26657
26741
  this.clearInternalState(options === null || options === void 0 ? void 0 : options.deviceId);
@@ -26664,7 +26748,13 @@ class Device extends events.exports {
26664
26748
  if (options === null || options === void 0 ? void 0 : options.deriveCardano) {
26665
26749
  payload.derive_cardano = true;
26666
26750
  }
26667
- Log$a.debug('initialize payload:', payload);
26751
+ payload.passphrase_state = options === null || options === void 0 ? void 0 : options.passphraseState;
26752
+ Log$a.debug('Initialize device begin:', {
26753
+ deviceId: options === null || options === void 0 ? void 0 : options.deviceId,
26754
+ passphraseState: options === null || options === void 0 ? void 0 : options.passphraseState,
26755
+ initSession: options === null || options === void 0 ? void 0 : options.initSession,
26756
+ InitializePayload: payload,
26757
+ });
26668
26758
  try {
26669
26759
  const { message } = yield Promise.race([
26670
26760
  this.commands.typedCall('Initialize', 'Features', payload),
@@ -26674,6 +26764,7 @@ class Device extends events.exports {
26674
26764
  }, 25 * 1000);
26675
26765
  }),
26676
26766
  ]);
26767
+ Log$a.debug('Initialize device end: ', message);
26677
26768
  this._updateFeatures(message, options === null || options === void 0 ? void 0 : options.initSession);
26678
26769
  yield TransportManager.reconfigure(this.features);
26679
26770
  }
@@ -26925,12 +27016,41 @@ class Device extends events.exports {
26925
27016
  }
26926
27017
  return false;
26927
27018
  }
26928
- checkPassphraseStateSafety(passphraseState) {
27019
+ lockDevice() {
27020
+ return __awaiter(this, void 0, void 0, function* () {
27021
+ const res = yield this.commands.typedCall('LockDevice', 'Success', {});
27022
+ return res.message;
27023
+ });
27024
+ }
27025
+ checkPassphraseStateSafety(passphraseState, useEmptyPassphraseState, skipPassphraseCheck) {
26929
27026
  return __awaiter(this, void 0, void 0, function* () {
26930
27027
  if (!this.features)
26931
27028
  return false;
26932
- const newState = yield getPassphraseStateWithRefreshDeviceInfo(this);
26933
- if (passphraseState && passphraseState !== newState) {
27029
+ const { passphraseState: newPassphraseState, unlockedAttachPin } = yield getPassphraseStateWithRefreshDeviceInfo(this, {
27030
+ expectPassphraseState: passphraseState,
27031
+ onlyMainPin: useEmptyPassphraseState,
27032
+ });
27033
+ if (skipPassphraseCheck) {
27034
+ return true;
27035
+ }
27036
+ const mainWalletUseAttachPin = unlockedAttachPin && useEmptyPassphraseState;
27037
+ const useErrorAttachPin = unlockedAttachPin && passphraseState && passphraseState !== newPassphraseState;
27038
+ Log$a.debug('Check passphrase state safety: ', {
27039
+ passphraseState,
27040
+ newPassphraseState,
27041
+ unlockedAttachPin,
27042
+ useEmptyPassphraseState,
27043
+ });
27044
+ if (mainWalletUseAttachPin || useErrorAttachPin) {
27045
+ try {
27046
+ yield this.lockDevice();
27047
+ }
27048
+ catch (error) {
27049
+ }
27050
+ this.clearInternalState();
27051
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckUnlockTypeError));
27052
+ }
27053
+ if (passphraseState && passphraseState !== newPassphraseState) {
26934
27054
  this.clearInternalState();
26935
27055
  return false;
26936
27056
  }
@@ -27197,12 +27317,9 @@ class GetPassphraseState extends BaseMethod {
27197
27317
  return __awaiter(this, void 0, void 0, function* () {
27198
27318
  if (!this.device.features)
27199
27319
  return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed));
27200
- const passphraseState = yield getPassphraseStateWithRefreshDeviceInfo(this.device);
27320
+ const { passphraseState } = yield getPassphraseStateWithRefreshDeviceInfo(this.device);
27201
27321
  const { features } = this.device;
27202
27322
  if (features && features.passphrase_protection === true) {
27203
- if (passphraseState && features.device_id) {
27204
- this.device.tryFixInternalState(passphraseState, features.device_id, features.session_id);
27205
- }
27206
27323
  return Promise.resolve(passphraseState);
27207
27324
  }
27208
27325
  return Promise.resolve(undefined);
@@ -28473,6 +28590,27 @@ class DeviceLock extends BaseMethod {
28473
28590
  }
28474
28591
  }
28475
28592
 
28593
+ class DeviceUnlock extends BaseMethod {
28594
+ init() {
28595
+ this.useDevicePassphraseState = false;
28596
+ }
28597
+ run() {
28598
+ return __awaiter(this, void 0, void 0, function* () {
28599
+ const { type } = yield this.device.commands.typedCall('GetAddress', 'Address', {
28600
+ address_n: [toHardened(44), toHardened(1), toHardened(0), 0, 0],
28601
+ coin_name: 'Testnet',
28602
+ script_type: 'SPENDADDRESS',
28603
+ show_display: false,
28604
+ });
28605
+ if (type === 'CallMethodError') {
28606
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Get the passphrase state error');
28607
+ }
28608
+ const res = yield this.device.commands.typedCall('GetFeatures', 'Features');
28609
+ return Promise.resolve(res.message);
28610
+ });
28611
+ }
28612
+ }
28613
+
28476
28614
  class DeviceCancel extends BaseMethod {
28477
28615
  init() {
28478
28616
  this.useDevicePassphraseState = false;
@@ -28617,7 +28755,7 @@ class FirmwareUpdate extends BaseMethod {
28617
28755
  if (e instanceof hdShared.HardwareError) {
28618
28756
  return Promise.reject(e);
28619
28757
  }
28620
- console.log('auto go to bootloader mode failed: ', e);
28758
+ Log$7.log('auto go to bootloader mode failed: ', e);
28621
28759
  return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateAutoEnterBootFailure));
28622
28760
  }
28623
28761
  }
@@ -29843,7 +29981,7 @@ class AllNetworkGetAddress extends BaseMethod {
29843
29981
  ]);
29844
29982
  });
29845
29983
  }
29846
- generateMethodName({ network, payload, }) {
29984
+ generateMethodName({ network, payload, originalIndex, }) {
29847
29985
  var _a, _b;
29848
29986
  const { name: networkName, coin } = networkAliases[network] || {
29849
29987
  name: network,
@@ -29857,6 +29995,7 @@ class AllNetworkGetAddress extends BaseMethod {
29857
29995
  methodName: config.methodName,
29858
29996
  params: Object.assign(Object.assign({}, ((_b = (_a = config === null || config === void 0 ? void 0 : config.getParams) === null || _a === void 0 ? void 0 : _a.call(config, payload, coin, config.methodName)) !== null && _b !== void 0 ? _b : payload)), { originPayload: payload }),
29859
29997
  _originRequestParams: payload,
29998
+ _originalIndex: originalIndex,
29860
29999
  };
29861
30000
  }
29862
30001
  callMethod(methodName, params) {
@@ -29904,10 +30043,11 @@ class AllNetworkGetAddress extends BaseMethod {
29904
30043
  const responses = [];
29905
30044
  const resultMap = {};
29906
30045
  const { bundle } = this.payload;
29907
- const methodReduceParams = bundle
29908
- .map(param => this.generateMethodName({
30046
+ const methodGroups = bundle
30047
+ .map((param, index) => this.generateMethodName({
29909
30048
  network: param.network,
29910
30049
  payload: param,
30050
+ originalIndex: index,
29911
30051
  }))
29912
30052
  .reduce((acc, cur) => {
29913
30053
  if (!acc[cur.methodName]) {
@@ -29916,28 +30056,25 @@ class AllNetworkGetAddress extends BaseMethod {
29916
30056
  acc[cur.methodName].push(cur);
29917
30057
  return acc;
29918
30058
  }, {});
29919
- const methodParamsArray = Object.values(methodReduceParams);
29920
- const generateResponseKey = (payload) => `${payload.path}-${payload.network}-${payload.chainName}-${payload.prefix}`;
29921
- for (let i = 0; i < methodParamsArray.length; i++) {
29922
- const methodParams = methodParamsArray[i];
29923
- const { methodName } = methodParams[0];
29924
- const params = {
29925
- bundle: methodParams.map(param => (Object.assign({}, param.params))),
30059
+ let i = 0;
30060
+ for (const [methodName, params] of Object.entries(methodGroups)) {
30061
+ const methodParams = {
30062
+ bundle: params.map(param => (Object.assign({}, param.params))),
29926
30063
  };
29927
- const response = yield this.callMethod(methodName, params);
29928
- for (let i = 0; i < methodParams.length; i++) {
29929
- const { _originRequestParams } = methodParams[i];
29930
- const responseKey = generateResponseKey(_originRequestParams);
30064
+ const response = yield this.callMethod(methodName, methodParams);
30065
+ for (let i = 0; i < params.length; i++) {
30066
+ const { _originRequestParams, _originalIndex } = params[i];
30067
+ const responseKey = `${_originalIndex}`;
29931
30068
  resultMap[responseKey] = Object.assign(Object.assign({}, _originRequestParams), response[i]);
29932
30069
  }
29933
30070
  if (((_b = (_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle) === null || _b === void 0 ? void 0 : _b.length) > 1) {
29934
30071
  const progress = Math.round(((i + 1) / this.payload.bundle.length) * 100);
29935
30072
  this.postMessage(createUiMessage(UI_REQUEST.DEVICE_PROGRESS, { progress }));
29936
30073
  }
30074
+ i++;
29937
30075
  }
29938
- for (const param of bundle) {
29939
- const responseKey = generateResponseKey(param);
29940
- responses.push(resultMap[responseKey]);
30076
+ for (let i = 0; i < bundle.length; i++) {
30077
+ responses.push(resultMap[i]);
29941
30078
  }
29942
30079
  return Promise.resolve(responses);
29943
30080
  });
@@ -33117,8 +33254,6 @@ class StellarSignTransaction extends BaseMethod {
33117
33254
  this.operations.push(transformed);
33118
33255
  }
33119
33256
  });
33120
- console.log('StellarSignTransactionParams', this.params);
33121
- console.log('StellarSignTransactionOperations', this.operations);
33122
33257
  }
33123
33258
  run() {
33124
33259
  return __awaiter(this, void 0, void 0, function* () {
@@ -37869,6 +38004,7 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
37869
38004
  deviceFullyUploadResource: DeviceFullyUploadResource,
37870
38005
  deviceUpdateBootloader: DeviceUpdateBootloader,
37871
38006
  deviceLock: DeviceLock,
38007
+ deviceUnlock: DeviceUnlock,
37872
38008
  deviceCancel: DeviceCancel,
37873
38009
  setU2FCounter: SetU2FCounter,
37874
38010
  getNextU2FCounter: GetNextU2FCounter,
@@ -38320,7 +38456,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
38320
38456
  try {
38321
38457
  yield waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
38322
38458
  const inner = () => __awaiter(void 0, void 0, void 0, function* () {
38323
- var _c, _d, _e;
38459
+ var _c, _d, _e, _f, _g;
38324
38460
  const versionRange = getMethodVersionRange(device.features, type => method.getVersionRange()[type]);
38325
38461
  if (device.features) {
38326
38462
  yield DataManager.checkAndReloadData();
@@ -38377,12 +38513,13 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
38377
38513
  require: support.require,
38378
38514
  }));
38379
38515
  }
38380
- const passphraseStateSafety = yield device.checkPassphraseStateSafety((_c = method.payload) === null || _c === void 0 ? void 0 : _c.passphraseState);
38516
+ const passphraseStateSafety = yield device.checkPassphraseStateSafety((_c = method.payload) === null || _c === void 0 ? void 0 : _c.passphraseState, (_d = method.payload) === null || _d === void 0 ? void 0 : _d.useEmptyPassphrase, (_e = method.payload) === null || _e === void 0 ? void 0 : _e.skipPassphraseCheck);
38381
38517
  checkPassphraseEnableState(method, device.features);
38382
38518
  if (!passphraseStateSafety) {
38383
38519
  DevicePool.clearDeviceCache(method.payload.connectId);
38384
38520
  return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError));
38385
38521
  }
38522
+ postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_WINDOW));
38386
38523
  }
38387
38524
  try {
38388
38525
  yield method.checkSafetyLevelOnTestNet();
@@ -38393,7 +38530,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
38393
38530
  : hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'open safety check failed.');
38394
38531
  throw error;
38395
38532
  }
38396
- (_e = (_d = method.device) === null || _d === void 0 ? void 0 : _d.commands) === null || _e === void 0 ? void 0 : _e.checkDisposed();
38533
+ (_g = (_f = method.device) === null || _f === void 0 ? void 0 : _f.commands) === null || _g === void 0 ? void 0 : _g.checkDisposed();
38397
38534
  try {
38398
38535
  const response = yield method.run();
38399
38536
  Log.debug('Call API - Inner Method Run: ');
@@ -38711,7 +38848,7 @@ const checkPassphraseEnableState = (method, features) => {
38711
38848
  return;
38712
38849
  if ((features === null || features === void 0 ? void 0 : features.passphrase_protection) === true &&
38713
38850
  (method.payload.passphraseState == null || method.payload.passphraseState === '') &&
38714
- !method.payload.useEmptyPassphrase) {
38851
+ (!method.payload.useEmptyPassphrase || !method.payload.skipPassphraseCheck)) {
38715
38852
  DevicePool.clearDeviceCache(method.payload.connectId);
38716
38853
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceOpenedPassphrase);
38717
38854
  }
@@ -38753,11 +38890,11 @@ const onDevicePinHandler = (...[device, type, callback]) => __awaiter(void 0, vo
38753
38890
  });
38754
38891
  const onDeviceButtonHandler = (...[device, request]) => {
38755
38892
  postMessage(createDeviceMessage(DEVICE.BUTTON, Object.assign(Object.assign({}, request), { device: device.toMessageObject() })));
38756
- if (request.code === 'ButtonRequest_PinEntry') {
38757
- Log.log('request Confirm Input PIN');
38893
+ if (request.code === 'ButtonRequest_PinEntry' || request.code === 'ButtonRequest_AttachPin') {
38894
+ Log.log('request Confirm Input PIN or Attach PIN');
38758
38895
  postMessage(createUiMessage(UI_REQUEST.REQUEST_PIN, {
38759
38896
  device: device.toMessageObject(),
38760
- type: 'ButtonRequest_PinEntry',
38897
+ type: request.code,
38761
38898
  }));
38762
38899
  }
38763
38900
  else {
@@ -38768,22 +38905,24 @@ const onDeviceButtonHandler = (...[device, request]) => {
38768
38905
  const onDeviceFeaturesHandler = (...[_, features]) => {
38769
38906
  postMessage(createDeviceMessage(DEVICE.FEATURES, Object.assign({}, features)));
38770
38907
  };
38771
- const onDevicePassphraseHandler = (...[device, callback]) => __awaiter(void 0, void 0, void 0, function* () {
38908
+ const onDevicePassphraseHandler = (...[device, requestPayload, callback]) => __awaiter(void 0, void 0, void 0, function* () {
38772
38909
  Log.debug('onDevicePassphraseHandler');
38773
38910
  const uiPromise = createUiPromise(UI_RESPONSE.RECEIVE_PASSPHRASE, device);
38774
38911
  postMessage(createUiMessage(UI_REQUEST.REQUEST_PASSPHRASE, {
38775
38912
  device: device.toMessageObject(),
38776
38913
  passphraseState: device.passphraseState,
38914
+ existsAttachPinUser: requestPayload.existsAttachPinUser,
38777
38915
  }));
38778
38916
  const uiResp = yield uiPromise.promise;
38779
- const { value, passphraseOnDevice, save } = uiResp.payload;
38917
+ const { value, passphraseOnDevice, save, attachPinOnDevice } = uiResp.payload;
38780
38918
  callback({
38781
38919
  passphrase: value.normalize('NFKD'),
38782
38920
  passphraseOnDevice,
38921
+ attachPinOnDevice,
38783
38922
  cache: save,
38784
38923
  });
38785
38924
  });
38786
- const onEmptyPassphraseHandler = (...[_, callback]) => {
38925
+ const onEmptyPassphraseHandler = (...[_, , callback]) => {
38787
38926
  Log.debug('onEmptyPassphraseHandler');
38788
38927
  callback({ passphrase: '' });
38789
38928
  };
@@ -38892,7 +39031,7 @@ const init = (settings, Transport, plugin) => __awaiter(void 0, void 0, void 0,
38892
39031
  yield DataManager.load(settings);
38893
39032
  initTransport(Transport, plugin);
38894
39033
  }
38895
- catch (_f) {
39034
+ catch (_h) {
38896
39035
  Log.error('DataManager.load error');
38897
39036
  }
38898
39037
  enableLog(DataManager.getSettings('debug'));
@@ -1 +1 @@
1
- {"version":3,"file":"inject.d.ts","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,UAAU,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;IAC3B,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC1C,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAC5B,UAAU,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAClC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC1B,eAAe,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC7C;AAED,eAAO,MAAM,MAAM,gGAShB,SAAS,KAAG,OAiCd,CAAC;AAEF,eAAO,MAAM,aAAa,SAClB,OAAO,CAAC,MAAM,CAAC,KACpB,KACD,OAAO,EACL,IAAI,GACJ,KAAK,GACL,MAAM,GACN,oBAAoB,GACpB,MAAM,GACN,MAAM,GACN,SAAS,GACT,YAAY,GACZ,QAAQ,GACR,gBAAgB,GAChB,iBAAiB,CAyRnB,CAAC"}
1
+ {"version":3,"file":"inject.d.ts","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,UAAU,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;IAC3B,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC1C,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAC5B,UAAU,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAClC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC1B,eAAe,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC7C;AAED,eAAO,MAAM,MAAM,gGAShB,SAAS,KAAG,OAiCd,CAAC;AAEF,eAAO,MAAM,aAAa,SAClB,OAAO,CAAC,MAAM,CAAC,KACpB,KACD,OAAO,EACL,IAAI,GACJ,KAAK,GACL,MAAM,GACN,oBAAoB,GACpB,MAAM,GACN,MAAM,GACN,SAAS,GACT,YAAY,GACZ,QAAQ,GACR,gBAAgB,GAChB,iBAAiB,CA2RnB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { Features } from '@onekeyfe/hd-transport';
2
+ import type { CommonParams, Response } from '../params';
3
+ export declare function deviceUnlock(connectId: string, params?: CommonParams): Response<Features>;
4
+ //# sourceMappingURL=deviceUnlock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deviceUnlock.d.ts","sourceRoot":"","sources":["../../../src/types/api/deviceUnlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAExD,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC"}
@@ -31,6 +31,7 @@ import { deviceSupportFeatures } from './deviceSupportFeatures';
31
31
  import { deviceFullyUploadResource } from './deviceFullyUploadResource';
32
32
  import { deviceUpdateBootloader } from './deviceUpdateBootloader';
33
33
  import { deviceLock } from './deviceLock';
34
+ import { deviceUnlock } from './deviceUnlock';
34
35
  import { deviceCancel } from './deviceCancel';
35
36
  import { getNextU2FCounter } from './getNextU2FCounter';
36
37
  import { setU2FCounter } from './setU2FCounter';
@@ -166,6 +167,7 @@ export type CoreApi = {
166
167
  deviceFullyUploadResource: typeof deviceFullyUploadResource;
167
168
  deviceUpdateBootloader: typeof deviceUpdateBootloader;
168
169
  deviceLock: typeof deviceLock;
170
+ deviceUnlock: typeof deviceUnlock;
169
171
  deviceCancel: typeof deviceCancel;
170
172
  getNextU2FCounter: typeof getNextU2FCounter;
171
173
  setU2FCounter: typeof setU2FCounter;