@onekeyfe/hd-core 1.0.38-alpha.0 → 1.0.39-alpha.1

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 +27 -12
  23. package/dist/index.js +198 -71
  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 +0 -2
  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 +0 -3
  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 +1 -9
  60. package/src/utils/deviceFeaturesUtils.ts +65 -7
  61. package/src/utils/logger.ts +0 -2
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,7 +877,6 @@ 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";
879
- LoggerNames["HdWebBleTransport"] = "@onekey/hd-web-ble-transport";
880
880
  LoggerNames["Connect"] = "@onekey/connect";
881
881
  LoggerNames["Iframe"] = "IFrame";
882
882
  LoggerNames["SendMessage"] = "[SendMessage]";
@@ -893,7 +893,6 @@ const LoggerMap = {
893
893
  [exports.LoggerNames.HdBleSdk]: initLog(exports.LoggerNames.HdBleSdk),
894
894
  [exports.LoggerNames.HdTransportHttp]: initLog(exports.LoggerNames.HdTransportHttp),
895
895
  [exports.LoggerNames.HdBleTransport]: initLog(exports.LoggerNames.HdBleTransport),
896
- [exports.LoggerNames.HdWebBleTransport]: initLog(exports.LoggerNames.HdWebBleTransport),
897
896
  [exports.LoggerNames.HdTransportLowLevel]: initLog(exports.LoggerNames.HdTransportLowLevel),
898
897
  [exports.LoggerNames.Connect]: initLog(exports.LoggerNames.Connect),
899
898
  [exports.LoggerNames.Iframe]: initLog(exports.LoggerNames.Iframe),
@@ -4331,7 +4330,8 @@ var nested$1 = {
4331
4330
  ButtonRequest_Success: 17,
4332
4331
  ButtonRequest_Warning: 18,
4333
4332
  ButtonRequest_PassphraseEntry: 19,
4334
- ButtonRequest_PinEntry: 20
4333
+ ButtonRequest_PinEntry: 20,
4334
+ ButtonRequest_AttachPin: 8000
4335
4335
  }
4336
4336
  }
4337
4337
  }
@@ -4382,6 +4382,10 @@ var nested$1 = {
4382
4382
  options: {
4383
4383
  deprecated: true
4384
4384
  }
4385
+ },
4386
+ exists_attach_pin_user: {
4387
+ type: "bool",
4388
+ id: 8000
4385
4389
  }
4386
4390
  }
4387
4391
  },
@@ -4401,6 +4405,10 @@ var nested$1 = {
4401
4405
  on_device: {
4402
4406
  type: "bool",
4403
4407
  id: 3
4408
+ },
4409
+ on_device_attach_pin: {
4410
+ type: "bool",
4411
+ id: 8000
4404
4412
  }
4405
4413
  }
4406
4414
  },
@@ -7368,6 +7376,10 @@ var nested$1 = {
7368
7376
  derive_cardano: {
7369
7377
  type: "bool",
7370
7378
  id: 3
7379
+ },
7380
+ passphrase_state: {
7381
+ type: "string",
7382
+ id: 8000
7371
7383
  }
7372
7384
  }
7373
7385
  },
@@ -7748,6 +7760,14 @@ var nested$1 = {
7748
7760
  onekey_se04_state: {
7749
7761
  type: "OneKeySEState",
7750
7762
  id: 624
7763
+ },
7764
+ attach_to_pin_user: {
7765
+ type: "bool",
7766
+ id: 625
7767
+ },
7768
+ unlocked_attach_pin: {
7769
+ type: "bool",
7770
+ id: 626
7751
7771
  }
7752
7772
  },
7753
7773
  nested: {
@@ -8870,6 +8890,30 @@ var nested$1 = {
8870
8890
  }
8871
8891
  }
8872
8892
  },
8893
+ GetPassphraseState: {
8894
+ fields: {
8895
+ passphrase_state: {
8896
+ type: "string",
8897
+ id: 1
8898
+ }
8899
+ }
8900
+ },
8901
+ PassphraseState: {
8902
+ fields: {
8903
+ passphrase_state: {
8904
+ type: "string",
8905
+ id: 1
8906
+ },
8907
+ session_id: {
8908
+ type: "bytes",
8909
+ id: 2
8910
+ },
8911
+ unlocked_attach_pin: {
8912
+ type: "bool",
8913
+ id: 3
8914
+ }
8915
+ }
8916
+ },
8873
8917
  MoneroTransactionSourceEntry: {
8874
8918
  fields: {
8875
8919
  outputs: {
@@ -13494,7 +13538,9 @@ var nested$1 = {
13494
13538
  MessageType_ListResDir: 10023,
13495
13539
  MessageType_FileInfoList: 10024,
13496
13540
  MessageType_OnekeyGetFeatures: 10025,
13497
- MessageType_OnekeyFeatures: 10026
13541
+ MessageType_OnekeyFeatures: 10026,
13542
+ MessageType_GetPassphraseState: 10028,
13543
+ MessageType_PassphraseState: 10029
13498
13544
  }
13499
13545
  },
13500
13546
  google: {
@@ -24895,7 +24941,7 @@ DataManager.getTransportStatus = (localVersion) => {
24895
24941
  return isLatest ? 'valid' : 'outdated';
24896
24942
  };
24897
24943
  DataManager.getBridgeChangelog = () => { var _b; return (_b = _a$1.assets) === null || _b === void 0 ? void 0 : _b.bridge.changelog; };
24898
- DataManager.isBleConnect = (env) => env === 'react-native' || env === 'lowlevel' || env === 'desktop-web-ble';
24944
+ DataManager.isBleConnect = (env) => env === 'react-native' || env === 'lowlevel';
24899
24945
  DataManager.isWebUsbConnect = (env) => env === 'webusb';
24900
24946
 
24901
24947
  const PROTOBUF_MESSAGE_CONFIG = {
@@ -24957,21 +25003,40 @@ const supportNewPassphrase = (features) => {
24957
25003
  const currentVersion = getDeviceFirmwareVersion(features).join('.');
24958
25004
  return { support: semver__default["default"].gte(currentVersion, '2.4.0'), require: '2.4.0' };
24959
25005
  };
24960
- const getPassphraseStateWithRefreshDeviceInfo = (device) => __awaiter(void 0, void 0, void 0, function* () {
25006
+ const getPassphraseStateWithRefreshDeviceInfo = (device, options) => __awaiter(void 0, void 0, void 0, function* () {
25007
+ var _a, _b, _c, _d, _e;
24961
25008
  const { features, commands } = device;
24962
25009
  const locked = (features === null || features === void 0 ? void 0 : features.unlocked) === false;
24963
- const passphraseState = yield getPassphraseState(features, commands);
25010
+ const { passphraseState, newSession, unlockedAttachPin } = yield getPassphraseState(features, commands, Object.assign({}, options));
24964
25011
  const isModeT = getDeviceType(features) === hdShared.EDeviceType.Touch || getDeviceType(features) === hdShared.EDeviceType.Pro;
24965
25012
  const needRefreshWithPassphrase = passphraseState && (features === null || features === void 0 ? void 0 : features.passphrase_protection) !== true;
24966
25013
  const needRefreshWithLocked = isModeT && locked;
24967
25014
  if (needRefreshWithLocked || needRefreshWithPassphrase) {
24968
25015
  yield device.getFeatures();
24969
25016
  }
24970
- return passphraseState;
25017
+ if (features === null || features === void 0 ? void 0 : features.device_id) {
25018
+ 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);
25019
+ }
25020
+ return { passphraseState, newSession, unlockedAttachPin };
24971
25021
  });
24972
- const getPassphraseState = (features, commands) => __awaiter(void 0, void 0, void 0, function* () {
25022
+ const getPassphraseState = (features, commands, options) => __awaiter(void 0, void 0, void 0, function* () {
24973
25023
  if (!features)
24974
- return false;
25024
+ return { passphraseState: undefined, newSession: undefined, unlockedAttachPin: undefined };
25025
+ const firmwareVersion = getDeviceFirmwareVersion(features);
25026
+ const deviceType = getDeviceType(features);
25027
+ if (deviceType === hdShared.EDeviceType.Pro && semver__default["default"].gte(firmwareVersion.join('.'), '4.15.0')) {
25028
+ const { message, type } = yield commands.typedCall('GetPassphraseState', 'PassphraseState', {
25029
+ passphrase_state: (options === null || options === void 0 ? void 0 : options.onlyMainPin) ? undefined : options === null || options === void 0 ? void 0 : options.expectPassphraseState,
25030
+ });
25031
+ if (type === 'CallMethodError') {
25032
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Get the passphrase state error');
25033
+ }
25034
+ return {
25035
+ passphraseState: message.passphrase_state,
25036
+ newSession: message.session_id,
25037
+ unlockedAttachPin: message.unlocked_attach_pin,
25038
+ };
25039
+ }
24975
25040
  const { message, type } = yield commands.typedCall('GetAddress', 'Address', {
24976
25041
  address_n: [toHardened(44), toHardened(1), toHardened(0), 0, 0],
24977
25042
  coin_name: 'Testnet',
@@ -24981,7 +25046,11 @@ const getPassphraseState = (features, commands) => __awaiter(void 0, void 0, voi
24981
25046
  if (type === 'CallMethodError') {
24982
25047
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Get the passphrase state error');
24983
25048
  }
24984
- return message.address;
25049
+ return {
25050
+ passphraseState: message.address,
25051
+ newSession: undefined,
25052
+ unlockedAttachPin: undefined,
25053
+ };
24985
25054
  });
24986
25055
  const supportBatchPublicKey = (features, options) => {
24987
25056
  if (!features)
@@ -25961,7 +26030,6 @@ const Log$c = getLogger(exports.LoggerNames.Transport);
25961
26030
  const BleLogger = getLogger(exports.LoggerNames.HdBleTransport);
25962
26031
  const HttpLogger = getLogger(exports.LoggerNames.HdTransportHttp);
25963
26032
  const LowLevelLogger = getLogger(exports.LoggerNames.HdTransportLowLevel);
25964
- const WebBleLogger = getLogger(exports.LoggerNames.HdWebBleTransport);
25965
26033
  class TransportManager {
25966
26034
  static load() {
25967
26035
  Log$c.debug('transport manager load');
@@ -25989,9 +26057,6 @@ class TransportManager {
25989
26057
  }
25990
26058
  yield this.transport.init(LowLevelLogger, DevicePool.emitter, this.plugin);
25991
26059
  }
25992
- else if (env === 'desktop-web-ble') {
25993
- yield this.transport.init(WebBleLogger);
25994
- }
25995
26060
  else {
25996
26061
  yield this.transport.init(HttpLogger);
25997
26062
  }
@@ -26205,7 +26270,6 @@ class DeviceCommands {
26205
26270
  this.callPromise = promise;
26206
26271
  const res = yield promise;
26207
26272
  Log$b.debug('[DeviceCommands] [call] Received', res.type);
26208
- console.log('[DeviceCommands] [call] Received', res.type);
26209
26273
  return res;
26210
26274
  }
26211
26275
  catch (error) {
@@ -26367,8 +26431,14 @@ class DeviceCommands {
26367
26431
  }, error => Promise.reject(error));
26368
26432
  }
26369
26433
  if (res.type === 'PassphraseRequest') {
26370
- return this._promptPassphrase().then(response => {
26371
- const { passphrase, passphraseOnDevice } = response;
26434
+ const existsAttachPinUser = res.message.exists_attach_pin_user;
26435
+ return this._promptPassphrase({
26436
+ existsAttachPinUser,
26437
+ }).then(response => {
26438
+ const { passphrase, passphraseOnDevice, attachPinOnDevice } = response;
26439
+ if (attachPinOnDevice && existsAttachPinUser) {
26440
+ return this._commonCall('PassphraseAck', { on_device_attach_pin: true });
26441
+ }
26372
26442
  return !passphraseOnDevice
26373
26443
  ? this._commonCall('PassphraseAck', { passphrase })
26374
26444
  : this._commonCall('PassphraseAck', { on_device: true });
@@ -26412,7 +26482,7 @@ class DeviceCommands {
26412
26482
  }
26413
26483
  });
26414
26484
  }
26415
- _promptPassphrase() {
26485
+ _promptPassphrase(options) {
26416
26486
  return new Promise((resolve, reject) => {
26417
26487
  const cancelAndReject = (_error) => cancelDeviceInPrompt(this.device, false)
26418
26488
  .then(onCancel => {
@@ -26430,7 +26500,7 @@ class DeviceCommands {
26430
26500
  });
26431
26501
  if (this.device.listenerCount(DEVICE.PASSPHRASE) > 0) {
26432
26502
  this.device.setCancelableAction(cancelAndReject);
26433
- this.device.emit(DEVICE.PASSPHRASE, this.device, (response, error) => {
26503
+ this.device.emit(DEVICE.PASSPHRASE, this.device, options, (response, error) => {
26434
26504
  this.device.clearCancelableAction();
26435
26505
  if (error) {
26436
26506
  cancelAndReject();
@@ -26603,8 +26673,8 @@ class Device extends events.exports {
26603
26673
  }
26604
26674
  getInternalState(_deviceId) {
26605
26675
  var _a, _b;
26606
- 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}`);
26607
26676
  Log$a.debug('getInternalState session cache: ', deviceSessionCache);
26677
+ 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}`);
26608
26678
  const deviceId = _deviceId || ((_b = this.features) === null || _b === void 0 ? void 0 : _b.device_id);
26609
26679
  if (!deviceId)
26610
26680
  return undefined;
@@ -26613,18 +26683,21 @@ class Device extends events.exports {
26613
26683
  const usePassKey = this.generateStateKey(deviceId, this.passphraseState);
26614
26684
  return deviceSessionCache[usePassKey];
26615
26685
  }
26616
- tryFixInternalState(state, deviceId, sessionId = null) {
26617
- Log$a.debug('tryFixInternalState session param: ', `device_id: ${deviceId}`, `passphraseState: ${state}`, `sessionId: ${sessionId}`);
26618
- const key = `${deviceId}`;
26619
- const session = deviceSessionCache[key];
26620
- if (session) {
26621
- deviceSessionCache[this.generateStateKey(deviceId, state)] = session;
26622
- delete deviceSessionCache[key];
26686
+ updateInternalState(enablePassphrase, passphraseState, deviceId, sessionId = null, featuresSessionId = null) {
26687
+ Log$a.debug('updateInternalState session param: ', `device_id: ${deviceId}`, `enablePassphrase: ${enablePassphrase}`, `passphraseState: ${passphraseState}`, `sessionId: ${sessionId}`, `featuresSessionId: ${featuresSessionId}`);
26688
+ if (enablePassphrase) {
26689
+ if (sessionId) {
26690
+ deviceSessionCache[this.generateStateKey(deviceId, passphraseState)] = sessionId;
26691
+ }
26692
+ else if (featuresSessionId) {
26693
+ deviceSessionCache[this.generateStateKey(deviceId, passphraseState)] = featuresSessionId;
26694
+ }
26623
26695
  }
26624
- else if (sessionId) {
26625
- deviceSessionCache[this.generateStateKey(deviceId, state)] = sessionId;
26696
+ const oldKey = `${deviceId}`;
26697
+ if (deviceSessionCache[oldKey]) {
26698
+ delete deviceSessionCache[oldKey];
26626
26699
  }
26627
- Log$a.debug('tryFixInternalState session cache: ', deviceSessionCache);
26700
+ Log$a.debug('updateInternalState session cache: ', deviceSessionCache);
26628
26701
  }
26629
26702
  setInternalState(state, initSession) {
26630
26703
  var _a, _b;
@@ -26657,7 +26730,6 @@ class Device extends events.exports {
26657
26730
  }
26658
26731
  initialize(options) {
26659
26732
  return __awaiter(this, void 0, void 0, function* () {
26660
- Log$a.debug('initialize param:', options);
26661
26733
  this.passphraseState = options === null || options === void 0 ? void 0 : options.passphraseState;
26662
26734
  if (options === null || options === void 0 ? void 0 : options.initSession) {
26663
26735
  this.clearInternalState(options === null || options === void 0 ? void 0 : options.deviceId);
@@ -26670,7 +26742,13 @@ class Device extends events.exports {
26670
26742
  if (options === null || options === void 0 ? void 0 : options.deriveCardano) {
26671
26743
  payload.derive_cardano = true;
26672
26744
  }
26673
- Log$a.debug('initialize payload:', payload);
26745
+ payload.passphrase_state = options === null || options === void 0 ? void 0 : options.passphraseState;
26746
+ Log$a.debug('Initialize device begin:', {
26747
+ deviceId: options === null || options === void 0 ? void 0 : options.deviceId,
26748
+ passphraseState: options === null || options === void 0 ? void 0 : options.passphraseState,
26749
+ initSession: options === null || options === void 0 ? void 0 : options.initSession,
26750
+ InitializePayload: payload,
26751
+ });
26674
26752
  try {
26675
26753
  const { message } = yield Promise.race([
26676
26754
  this.commands.typedCall('Initialize', 'Features', payload),
@@ -26680,6 +26758,7 @@ class Device extends events.exports {
26680
26758
  }, 25 * 1000);
26681
26759
  }),
26682
26760
  ]);
26761
+ Log$a.debug('Initialize device end: ', message);
26683
26762
  this._updateFeatures(message, options === null || options === void 0 ? void 0 : options.initSession);
26684
26763
  yield TransportManager.reconfigure(this.features);
26685
26764
  }
@@ -26931,12 +27010,41 @@ class Device extends events.exports {
26931
27010
  }
26932
27011
  return false;
26933
27012
  }
26934
- checkPassphraseStateSafety(passphraseState) {
27013
+ lockDevice() {
27014
+ return __awaiter(this, void 0, void 0, function* () {
27015
+ const res = yield this.commands.typedCall('LockDevice', 'Success', {});
27016
+ return res.message;
27017
+ });
27018
+ }
27019
+ checkPassphraseStateSafety(passphraseState, useEmptyPassphraseState, skipPassphraseCheck) {
26935
27020
  return __awaiter(this, void 0, void 0, function* () {
26936
27021
  if (!this.features)
26937
27022
  return false;
26938
- const newState = yield getPassphraseStateWithRefreshDeviceInfo(this);
26939
- if (passphraseState && passphraseState !== newState) {
27023
+ const { passphraseState: newPassphraseState, unlockedAttachPin } = yield getPassphraseStateWithRefreshDeviceInfo(this, {
27024
+ expectPassphraseState: passphraseState,
27025
+ onlyMainPin: useEmptyPassphraseState,
27026
+ });
27027
+ if (skipPassphraseCheck) {
27028
+ return true;
27029
+ }
27030
+ const mainWalletUseAttachPin = unlockedAttachPin && useEmptyPassphraseState;
27031
+ const useErrorAttachPin = unlockedAttachPin && passphraseState && passphraseState !== newPassphraseState;
27032
+ Log$a.debug('Check passphrase state safety: ', {
27033
+ passphraseState,
27034
+ newPassphraseState,
27035
+ unlockedAttachPin,
27036
+ useEmptyPassphraseState,
27037
+ });
27038
+ if (mainWalletUseAttachPin || useErrorAttachPin) {
27039
+ try {
27040
+ yield this.lockDevice();
27041
+ }
27042
+ catch (error) {
27043
+ }
27044
+ this.clearInternalState();
27045
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckUnlockTypeError));
27046
+ }
27047
+ if (passphraseState && passphraseState !== newPassphraseState) {
26940
27048
  this.clearInternalState();
26941
27049
  return false;
26942
27050
  }
@@ -27203,12 +27311,9 @@ class GetPassphraseState extends BaseMethod {
27203
27311
  return __awaiter(this, void 0, void 0, function* () {
27204
27312
  if (!this.device.features)
27205
27313
  return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed));
27206
- const passphraseState = yield getPassphraseStateWithRefreshDeviceInfo(this.device);
27314
+ const { passphraseState } = yield getPassphraseStateWithRefreshDeviceInfo(this.device);
27207
27315
  const { features } = this.device;
27208
27316
  if (features && features.passphrase_protection === true) {
27209
- if (passphraseState && features.device_id) {
27210
- this.device.tryFixInternalState(passphraseState, features.device_id, features.session_id);
27211
- }
27212
27317
  return Promise.resolve(passphraseState);
27213
27318
  }
27214
27319
  return Promise.resolve(undefined);
@@ -28479,6 +28584,27 @@ class DeviceLock extends BaseMethod {
28479
28584
  }
28480
28585
  }
28481
28586
 
28587
+ class DeviceUnlock extends BaseMethod {
28588
+ init() {
28589
+ this.useDevicePassphraseState = false;
28590
+ }
28591
+ run() {
28592
+ return __awaiter(this, void 0, void 0, function* () {
28593
+ const { type } = yield this.device.commands.typedCall('GetAddress', 'Address', {
28594
+ address_n: [toHardened(44), toHardened(1), toHardened(0), 0, 0],
28595
+ coin_name: 'Testnet',
28596
+ script_type: 'SPENDADDRESS',
28597
+ show_display: false,
28598
+ });
28599
+ if (type === 'CallMethodError') {
28600
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Get the passphrase state error');
28601
+ }
28602
+ const res = yield this.device.commands.typedCall('GetFeatures', 'Features');
28603
+ return Promise.resolve(res.message);
28604
+ });
28605
+ }
28606
+ }
28607
+
28482
28608
  class DeviceCancel extends BaseMethod {
28483
28609
  init() {
28484
28610
  this.useDevicePassphraseState = false;
@@ -28623,7 +28749,7 @@ class FirmwareUpdate extends BaseMethod {
28623
28749
  if (e instanceof hdShared.HardwareError) {
28624
28750
  return Promise.reject(e);
28625
28751
  }
28626
- console.log('auto go to bootloader mode failed: ', e);
28752
+ Log$7.log('auto go to bootloader mode failed: ', e);
28627
28753
  return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateAutoEnterBootFailure));
28628
28754
  }
28629
28755
  }
@@ -29849,7 +29975,7 @@ class AllNetworkGetAddress extends BaseMethod {
29849
29975
  ]);
29850
29976
  });
29851
29977
  }
29852
- generateMethodName({ network, payload, }) {
29978
+ generateMethodName({ network, payload, originalIndex, }) {
29853
29979
  var _a, _b;
29854
29980
  const { name: networkName, coin } = networkAliases[network] || {
29855
29981
  name: network,
@@ -29863,6 +29989,7 @@ class AllNetworkGetAddress extends BaseMethod {
29863
29989
  methodName: config.methodName,
29864
29990
  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 }),
29865
29991
  _originRequestParams: payload,
29992
+ _originalIndex: originalIndex,
29866
29993
  };
29867
29994
  }
29868
29995
  callMethod(methodName, params) {
@@ -29910,10 +30037,11 @@ class AllNetworkGetAddress extends BaseMethod {
29910
30037
  const responses = [];
29911
30038
  const resultMap = {};
29912
30039
  const { bundle } = this.payload;
29913
- const methodReduceParams = bundle
29914
- .map(param => this.generateMethodName({
30040
+ const methodGroups = bundle
30041
+ .map((param, index) => this.generateMethodName({
29915
30042
  network: param.network,
29916
30043
  payload: param,
30044
+ originalIndex: index,
29917
30045
  }))
29918
30046
  .reduce((acc, cur) => {
29919
30047
  if (!acc[cur.methodName]) {
@@ -29922,28 +30050,25 @@ class AllNetworkGetAddress extends BaseMethod {
29922
30050
  acc[cur.methodName].push(cur);
29923
30051
  return acc;
29924
30052
  }, {});
29925
- const methodParamsArray = Object.values(methodReduceParams);
29926
- const generateResponseKey = (payload) => `${payload.path}-${payload.network}-${payload.chainName}-${payload.prefix}`;
29927
- for (let i = 0; i < methodParamsArray.length; i++) {
29928
- const methodParams = methodParamsArray[i];
29929
- const { methodName } = methodParams[0];
29930
- const params = {
29931
- bundle: methodParams.map(param => (Object.assign({}, param.params))),
30053
+ let i = 0;
30054
+ for (const [methodName, params] of Object.entries(methodGroups)) {
30055
+ const methodParams = {
30056
+ bundle: params.map(param => (Object.assign({}, param.params))),
29932
30057
  };
29933
- const response = yield this.callMethod(methodName, params);
29934
- for (let i = 0; i < methodParams.length; i++) {
29935
- const { _originRequestParams } = methodParams[i];
29936
- const responseKey = generateResponseKey(_originRequestParams);
30058
+ const response = yield this.callMethod(methodName, methodParams);
30059
+ for (let i = 0; i < params.length; i++) {
30060
+ const { _originRequestParams, _originalIndex } = params[i];
30061
+ const responseKey = `${_originalIndex}`;
29937
30062
  resultMap[responseKey] = Object.assign(Object.assign({}, _originRequestParams), response[i]);
29938
30063
  }
29939
30064
  if (((_b = (_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle) === null || _b === void 0 ? void 0 : _b.length) > 1) {
29940
30065
  const progress = Math.round(((i + 1) / this.payload.bundle.length) * 100);
29941
30066
  this.postMessage(createUiMessage(UI_REQUEST.DEVICE_PROGRESS, { progress }));
29942
30067
  }
30068
+ i++;
29943
30069
  }
29944
- for (const param of bundle) {
29945
- const responseKey = generateResponseKey(param);
29946
- responses.push(resultMap[responseKey]);
30070
+ for (let i = 0; i < bundle.length; i++) {
30071
+ responses.push(resultMap[i]);
29947
30072
  }
29948
30073
  return Promise.resolve(responses);
29949
30074
  });
@@ -33123,8 +33248,6 @@ class StellarSignTransaction extends BaseMethod {
33123
33248
  this.operations.push(transformed);
33124
33249
  }
33125
33250
  });
33126
- console.log('StellarSignTransactionParams', this.params);
33127
- console.log('StellarSignTransactionOperations', this.operations);
33128
33251
  }
33129
33252
  run() {
33130
33253
  return __awaiter(this, void 0, void 0, function* () {
@@ -37875,6 +37998,7 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
37875
37998
  deviceFullyUploadResource: DeviceFullyUploadResource,
37876
37999
  deviceUpdateBootloader: DeviceUpdateBootloader,
37877
38000
  deviceLock: DeviceLock,
38001
+ deviceUnlock: DeviceUnlock,
37878
38002
  deviceCancel: DeviceCancel,
37879
38003
  setU2FCounter: SetU2FCounter,
37880
38004
  getNextU2FCounter: GetNextU2FCounter,
@@ -38326,7 +38450,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
38326
38450
  try {
38327
38451
  yield waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
38328
38452
  const inner = () => __awaiter(void 0, void 0, void 0, function* () {
38329
- var _c, _d, _e;
38453
+ var _c, _d, _e, _f, _g;
38330
38454
  const versionRange = getMethodVersionRange(device.features, type => method.getVersionRange()[type]);
38331
38455
  if (device.features) {
38332
38456
  yield DataManager.checkAndReloadData();
@@ -38383,12 +38507,13 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
38383
38507
  require: support.require,
38384
38508
  }));
38385
38509
  }
38386
- const passphraseStateSafety = yield device.checkPassphraseStateSafety((_c = method.payload) === null || _c === void 0 ? void 0 : _c.passphraseState);
38510
+ 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);
38387
38511
  checkPassphraseEnableState(method, device.features);
38388
38512
  if (!passphraseStateSafety) {
38389
38513
  DevicePool.clearDeviceCache(method.payload.connectId);
38390
38514
  return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError));
38391
38515
  }
38516
+ postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_WINDOW));
38392
38517
  }
38393
38518
  try {
38394
38519
  yield method.checkSafetyLevelOnTestNet();
@@ -38399,7 +38524,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
38399
38524
  : hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'open safety check failed.');
38400
38525
  throw error;
38401
38526
  }
38402
- (_e = (_d = method.device) === null || _d === void 0 ? void 0 : _d.commands) === null || _e === void 0 ? void 0 : _e.checkDisposed();
38527
+ (_g = (_f = method.device) === null || _f === void 0 ? void 0 : _f.commands) === null || _g === void 0 ? void 0 : _g.checkDisposed();
38403
38528
  try {
38404
38529
  const response = yield method.run();
38405
38530
  Log.debug('Call API - Inner Method Run: ');
@@ -38717,7 +38842,7 @@ const checkPassphraseEnableState = (method, features) => {
38717
38842
  return;
38718
38843
  if ((features === null || features === void 0 ? void 0 : features.passphrase_protection) === true &&
38719
38844
  (method.payload.passphraseState == null || method.payload.passphraseState === '') &&
38720
- !method.payload.useEmptyPassphrase) {
38845
+ (!method.payload.useEmptyPassphrase || !method.payload.skipPassphraseCheck)) {
38721
38846
  DevicePool.clearDeviceCache(method.payload.connectId);
38722
38847
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceOpenedPassphrase);
38723
38848
  }
@@ -38759,11 +38884,11 @@ const onDevicePinHandler = (...[device, type, callback]) => __awaiter(void 0, vo
38759
38884
  });
38760
38885
  const onDeviceButtonHandler = (...[device, request]) => {
38761
38886
  postMessage(createDeviceMessage(DEVICE.BUTTON, Object.assign(Object.assign({}, request), { device: device.toMessageObject() })));
38762
- if (request.code === 'ButtonRequest_PinEntry') {
38763
- Log.log('request Confirm Input PIN');
38887
+ if (request.code === 'ButtonRequest_PinEntry' || request.code === 'ButtonRequest_AttachPin') {
38888
+ Log.log('request Confirm Input PIN or Attach PIN');
38764
38889
  postMessage(createUiMessage(UI_REQUEST.REQUEST_PIN, {
38765
38890
  device: device.toMessageObject(),
38766
- type: 'ButtonRequest_PinEntry',
38891
+ type: request.code,
38767
38892
  }));
38768
38893
  }
38769
38894
  else {
@@ -38774,22 +38899,24 @@ const onDeviceButtonHandler = (...[device, request]) => {
38774
38899
  const onDeviceFeaturesHandler = (...[_, features]) => {
38775
38900
  postMessage(createDeviceMessage(DEVICE.FEATURES, Object.assign({}, features)));
38776
38901
  };
38777
- const onDevicePassphraseHandler = (...[device, callback]) => __awaiter(void 0, void 0, void 0, function* () {
38902
+ const onDevicePassphraseHandler = (...[device, requestPayload, callback]) => __awaiter(void 0, void 0, void 0, function* () {
38778
38903
  Log.debug('onDevicePassphraseHandler');
38779
38904
  const uiPromise = createUiPromise(UI_RESPONSE.RECEIVE_PASSPHRASE, device);
38780
38905
  postMessage(createUiMessage(UI_REQUEST.REQUEST_PASSPHRASE, {
38781
38906
  device: device.toMessageObject(),
38782
38907
  passphraseState: device.passphraseState,
38908
+ existsAttachPinUser: requestPayload.existsAttachPinUser,
38783
38909
  }));
38784
38910
  const uiResp = yield uiPromise.promise;
38785
- const { value, passphraseOnDevice, save } = uiResp.payload;
38911
+ const { value, passphraseOnDevice, save, attachPinOnDevice } = uiResp.payload;
38786
38912
  callback({
38787
38913
  passphrase: value.normalize('NFKD'),
38788
38914
  passphraseOnDevice,
38915
+ attachPinOnDevice,
38789
38916
  cache: save,
38790
38917
  });
38791
38918
  });
38792
- const onEmptyPassphraseHandler = (...[_, callback]) => {
38919
+ const onEmptyPassphraseHandler = (...[_, , callback]) => {
38793
38920
  Log.debug('onEmptyPassphraseHandler');
38794
38921
  callback({ passphrase: '' });
38795
38922
  };
@@ -38898,7 +39025,7 @@ const init = (settings, Transport, plugin) => __awaiter(void 0, void 0, void 0,
38898
39025
  yield DataManager.load(settings);
38899
39026
  initTransport(Transport, plugin);
38900
39027
  }
38901
- catch (_f) {
39028
+ catch (_h) {
38902
39029
  Log.error('DataManager.load error');
38903
39030
  }
38904
39031
  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;