@onekeyfe/hd-core 1.0.36-alpha.1 → 1.0.37-alpha.3

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 (62) 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 +213 -68
  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/firmware/FirmwareUpdateBaseMethod.ts +2 -2
  45. package/src/api/index.ts +1 -0
  46. package/src/api/stellar/StellarSignTransaction.ts +0 -3
  47. package/src/core/index.ts +17 -8
  48. package/src/data/messages/messages.json +49 -2
  49. package/src/data-manager/DataManager.ts +1 -1
  50. package/src/data-manager/TransportManager.ts +3 -0
  51. package/src/device/Device.ts +92 -20
  52. package/src/device/DeviceCommands.ts +15 -5
  53. package/src/events/device.ts +4 -0
  54. package/src/events/ui-request.ts +2 -1
  55. package/src/events/ui-response.ts +1 -0
  56. package/src/inject.ts +2 -0
  57. package/src/types/api/deviceUnlock.ts +4 -0
  58. package/src/types/api/index.ts +2 -0
  59. package/src/types/params.ts +5 -0
  60. package/src/types/settings.ts +10 -1
  61. package/src/utils/deviceFeaturesUtils.ts +72 -8
  62. 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)
@@ -24989,12 +25062,18 @@ const supportBatchPublicKey = (features, options) => {
24989
25062
  if (!!(options === null || options === void 0 ? void 0 : options.includeNode) && deviceType === hdShared.EDeviceType.Pro) {
24990
25063
  return semver__default["default"].gte(currentVersion, '4.14.0');
24991
25064
  }
25065
+ if (!!(options === null || options === void 0 ? void 0 : options.includeNode) && deviceType === hdShared.EDeviceType.Touch) {
25066
+ return semver__default["default"].gte(currentVersion, '4.11.0');
25067
+ }
24992
25068
  if (!!(options === null || options === void 0 ? void 0 : options.includeNode) && DeviceModelToTypes.model_classic1s.includes(deviceType)) {
24993
25069
  return semver__default["default"].gte(currentVersion, '3.12.0');
24994
25070
  }
24995
- if (!!(options === null || options === void 0 ? void 0 : options.includeNode) && deviceType === hdShared.EDeviceType.Classic) {
25071
+ if (!!(options === null || options === void 0 ? void 0 : options.includeNode) && DeviceModelToTypes.model_mini.includes(deviceType)) {
24996
25072
  return semver__default["default"].gte(currentVersion, '3.10.0');
24997
25073
  }
25074
+ if (options === null || options === void 0 ? void 0 : options.includeNode) {
25075
+ return false;
25076
+ }
24998
25077
  if (deviceType === hdShared.EDeviceType.Touch || deviceType === hdShared.EDeviceType.Pro) {
24999
25078
  return semver__default["default"].gte(currentVersion, '3.1.0');
25000
25079
  }
@@ -25953,6 +26032,7 @@ const Log$c = getLogger(exports.LoggerNames.Transport);
25953
26032
  const BleLogger = getLogger(exports.LoggerNames.HdBleTransport);
25954
26033
  const HttpLogger = getLogger(exports.LoggerNames.HdTransportHttp);
25955
26034
  const LowLevelLogger = getLogger(exports.LoggerNames.HdTransportLowLevel);
26035
+ const WebBleLogger = getLogger(exports.LoggerNames.HdWebBleTransport);
25956
26036
  class TransportManager {
25957
26037
  static load() {
25958
26038
  Log$c.debug('transport manager load');
@@ -25980,6 +26060,9 @@ class TransportManager {
25980
26060
  }
25981
26061
  yield this.transport.init(LowLevelLogger, DevicePool.emitter, this.plugin);
25982
26062
  }
26063
+ else if (env === 'desktop-web-ble') {
26064
+ yield this.transport.init(WebBleLogger);
26065
+ }
25983
26066
  else {
25984
26067
  yield this.transport.init(HttpLogger);
25985
26068
  }
@@ -26193,7 +26276,6 @@ class DeviceCommands {
26193
26276
  this.callPromise = promise;
26194
26277
  const res = yield promise;
26195
26278
  Log$b.debug('[DeviceCommands] [call] Received', res.type);
26196
- console.log('[DeviceCommands] [call] Received', res.type);
26197
26279
  return res;
26198
26280
  }
26199
26281
  catch (error) {
@@ -26355,8 +26437,14 @@ class DeviceCommands {
26355
26437
  }, error => Promise.reject(error));
26356
26438
  }
26357
26439
  if (res.type === 'PassphraseRequest') {
26358
- return this._promptPassphrase().then(response => {
26359
- 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
+ }
26360
26448
  return !passphraseOnDevice
26361
26449
  ? this._commonCall('PassphraseAck', { passphrase })
26362
26450
  : this._commonCall('PassphraseAck', { on_device: true });
@@ -26400,7 +26488,7 @@ class DeviceCommands {
26400
26488
  }
26401
26489
  });
26402
26490
  }
26403
- _promptPassphrase() {
26491
+ _promptPassphrase(options) {
26404
26492
  return new Promise((resolve, reject) => {
26405
26493
  const cancelAndReject = (_error) => cancelDeviceInPrompt(this.device, false)
26406
26494
  .then(onCancel => {
@@ -26418,7 +26506,7 @@ class DeviceCommands {
26418
26506
  });
26419
26507
  if (this.device.listenerCount(DEVICE.PASSPHRASE) > 0) {
26420
26508
  this.device.setCancelableAction(cancelAndReject);
26421
- this.device.emit(DEVICE.PASSPHRASE, this.device, (response, error) => {
26509
+ this.device.emit(DEVICE.PASSPHRASE, this.device, options, (response, error) => {
26422
26510
  this.device.clearCancelableAction();
26423
26511
  if (error) {
26424
26512
  cancelAndReject();
@@ -26591,8 +26679,8 @@ class Device extends events.exports {
26591
26679
  }
26592
26680
  getInternalState(_deviceId) {
26593
26681
  var _a, _b;
26594
- 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}`);
26595
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}`);
26596
26684
  const deviceId = _deviceId || ((_b = this.features) === null || _b === void 0 ? void 0 : _b.device_id);
26597
26685
  if (!deviceId)
26598
26686
  return undefined;
@@ -26601,18 +26689,21 @@ class Device extends events.exports {
26601
26689
  const usePassKey = this.generateStateKey(deviceId, this.passphraseState);
26602
26690
  return deviceSessionCache[usePassKey];
26603
26691
  }
26604
- tryFixInternalState(state, deviceId, sessionId = null) {
26605
- Log$a.debug('tryFixInternalState session param: ', `device_id: ${deviceId}`, `passphraseState: ${state}`, `sessionId: ${sessionId}`);
26606
- const key = `${deviceId}`;
26607
- const session = deviceSessionCache[key];
26608
- if (session) {
26609
- deviceSessionCache[this.generateStateKey(deviceId, state)] = session;
26610
- 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
+ }
26611
26701
  }
26612
- else if (sessionId) {
26613
- deviceSessionCache[this.generateStateKey(deviceId, state)] = sessionId;
26702
+ const oldKey = `${deviceId}`;
26703
+ if (deviceSessionCache[oldKey]) {
26704
+ delete deviceSessionCache[oldKey];
26614
26705
  }
26615
- Log$a.debug('tryFixInternalState session cache: ', deviceSessionCache);
26706
+ Log$a.debug('updateInternalState session cache: ', deviceSessionCache);
26616
26707
  }
26617
26708
  setInternalState(state, initSession) {
26618
26709
  var _a, _b;
@@ -26645,7 +26736,6 @@ class Device extends events.exports {
26645
26736
  }
26646
26737
  initialize(options) {
26647
26738
  return __awaiter(this, void 0, void 0, function* () {
26648
- Log$a.debug('initialize param:', options);
26649
26739
  this.passphraseState = options === null || options === void 0 ? void 0 : options.passphraseState;
26650
26740
  if (options === null || options === void 0 ? void 0 : options.initSession) {
26651
26741
  this.clearInternalState(options === null || options === void 0 ? void 0 : options.deviceId);
@@ -26658,7 +26748,13 @@ class Device extends events.exports {
26658
26748
  if (options === null || options === void 0 ? void 0 : options.deriveCardano) {
26659
26749
  payload.derive_cardano = true;
26660
26750
  }
26661
- 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
+ });
26662
26758
  try {
26663
26759
  const { message } = yield Promise.race([
26664
26760
  this.commands.typedCall('Initialize', 'Features', payload),
@@ -26668,6 +26764,7 @@ class Device extends events.exports {
26668
26764
  }, 25 * 1000);
26669
26765
  }),
26670
26766
  ]);
26767
+ Log$a.debug('Initialize device end: ', message);
26671
26768
  this._updateFeatures(message, options === null || options === void 0 ? void 0 : options.initSession);
26672
26769
  yield TransportManager.reconfigure(this.features);
26673
26770
  }
@@ -26919,12 +27016,41 @@ class Device extends events.exports {
26919
27016
  }
26920
27017
  return false;
26921
27018
  }
26922
- 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) {
26923
27026
  return __awaiter(this, void 0, void 0, function* () {
26924
27027
  if (!this.features)
26925
27028
  return false;
26926
- const newState = yield getPassphraseStateWithRefreshDeviceInfo(this);
26927
- 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) {
26928
27054
  this.clearInternalState();
26929
27055
  return false;
26930
27056
  }
@@ -27191,12 +27317,9 @@ class GetPassphraseState extends BaseMethod {
27191
27317
  return __awaiter(this, void 0, void 0, function* () {
27192
27318
  if (!this.device.features)
27193
27319
  return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed));
27194
- const passphraseState = yield getPassphraseStateWithRefreshDeviceInfo(this.device);
27320
+ const { passphraseState } = yield getPassphraseStateWithRefreshDeviceInfo(this.device);
27195
27321
  const { features } = this.device;
27196
27322
  if (features && features.passphrase_protection === true) {
27197
- if (passphraseState && features.device_id) {
27198
- this.device.tryFixInternalState(passphraseState, features.device_id, features.session_id);
27199
- }
27200
27323
  return Promise.resolve(passphraseState);
27201
27324
  }
27202
27325
  return Promise.resolve(undefined);
@@ -28467,6 +28590,27 @@ class DeviceLock extends BaseMethod {
28467
28590
  }
28468
28591
  }
28469
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
+
28470
28614
  class DeviceCancel extends BaseMethod {
28471
28615
  init() {
28472
28616
  this.useDevicePassphraseState = false;
@@ -28611,7 +28755,7 @@ class FirmwareUpdate extends BaseMethod {
28611
28755
  if (e instanceof hdShared.HardwareError) {
28612
28756
  return Promise.reject(e);
28613
28757
  }
28614
- console.log('auto go to bootloader mode failed: ', e);
28758
+ Log$7.log('auto go to bootloader mode failed: ', e);
28615
28759
  return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateAutoEnterBootFailure));
28616
28760
  }
28617
28761
  }
@@ -29116,10 +29260,10 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
29116
29260
  let progress;
29117
29261
  if (totalSize !== undefined && processedSize !== undefined) {
29118
29262
  currentFileProcessed = processedSize + chunkEnd;
29119
- progress = Math.min(Math.floor((currentFileProcessed / totalSize) * 100), 100);
29263
+ progress = Math.min(Math.ceil((currentFileProcessed / totalSize) * 100), 99);
29120
29264
  }
29121
29265
  else {
29122
- progress = Math.min(Math.round(((i + 1) / totalChunks) * 100), 100);
29266
+ progress = Math.min(Math.ceil(((i + 1) / totalChunks) * 100), 99);
29123
29267
  }
29124
29268
  const writeRes = yield this.emmcFileWriteWithRetry(filePath, chunkLength, offset, chunk, overwrite, progress);
29125
29269
  offset += writeRes.message.processed_byte;
@@ -29837,7 +29981,7 @@ class AllNetworkGetAddress extends BaseMethod {
29837
29981
  ]);
29838
29982
  });
29839
29983
  }
29840
- generateMethodName({ network, payload, }) {
29984
+ generateMethodName({ network, payload, originalIndex, }) {
29841
29985
  var _a, _b;
29842
29986
  const { name: networkName, coin } = networkAliases[network] || {
29843
29987
  name: network,
@@ -29851,6 +29995,7 @@ class AllNetworkGetAddress extends BaseMethod {
29851
29995
  methodName: config.methodName,
29852
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 }),
29853
29997
  _originRequestParams: payload,
29998
+ _originalIndex: originalIndex,
29854
29999
  };
29855
30000
  }
29856
30001
  callMethod(methodName, params) {
@@ -29898,10 +30043,11 @@ class AllNetworkGetAddress extends BaseMethod {
29898
30043
  const responses = [];
29899
30044
  const resultMap = {};
29900
30045
  const { bundle } = this.payload;
29901
- const methodReduceParams = bundle
29902
- .map(param => this.generateMethodName({
30046
+ const methodGroups = bundle
30047
+ .map((param, index) => this.generateMethodName({
29903
30048
  network: param.network,
29904
30049
  payload: param,
30050
+ originalIndex: index,
29905
30051
  }))
29906
30052
  .reduce((acc, cur) => {
29907
30053
  if (!acc[cur.methodName]) {
@@ -29910,28 +30056,25 @@ class AllNetworkGetAddress extends BaseMethod {
29910
30056
  acc[cur.methodName].push(cur);
29911
30057
  return acc;
29912
30058
  }, {});
29913
- const methodParamsArray = Object.values(methodReduceParams);
29914
- const generateResponseKey = (payload) => `${payload.path}-${payload.network}-${payload.chainName}-${payload.prefix}`;
29915
- for (let i = 0; i < methodParamsArray.length; i++) {
29916
- const methodParams = methodParamsArray[i];
29917
- const { methodName } = methodParams[0];
29918
- const params = {
29919
- 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))),
29920
30063
  };
29921
- const response = yield this.callMethod(methodName, params);
29922
- for (let i = 0; i < methodParams.length; i++) {
29923
- const { _originRequestParams } = methodParams[i];
29924
- 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}`;
29925
30068
  resultMap[responseKey] = Object.assign(Object.assign({}, _originRequestParams), response[i]);
29926
30069
  }
29927
30070
  if (((_b = (_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle) === null || _b === void 0 ? void 0 : _b.length) > 1) {
29928
30071
  const progress = Math.round(((i + 1) / this.payload.bundle.length) * 100);
29929
30072
  this.postMessage(createUiMessage(UI_REQUEST.DEVICE_PROGRESS, { progress }));
29930
30073
  }
30074
+ i++;
29931
30075
  }
29932
- for (const param of bundle) {
29933
- const responseKey = generateResponseKey(param);
29934
- responses.push(resultMap[responseKey]);
30076
+ for (let i = 0; i < bundle.length; i++) {
30077
+ responses.push(resultMap[i]);
29935
30078
  }
29936
30079
  return Promise.resolve(responses);
29937
30080
  });
@@ -33111,8 +33254,6 @@ class StellarSignTransaction extends BaseMethod {
33111
33254
  this.operations.push(transformed);
33112
33255
  }
33113
33256
  });
33114
- console.log('StellarSignTransactionParams', this.params);
33115
- console.log('StellarSignTransactionOperations', this.operations);
33116
33257
  }
33117
33258
  run() {
33118
33259
  return __awaiter(this, void 0, void 0, function* () {
@@ -37863,6 +38004,7 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
37863
38004
  deviceFullyUploadResource: DeviceFullyUploadResource,
37864
38005
  deviceUpdateBootloader: DeviceUpdateBootloader,
37865
38006
  deviceLock: DeviceLock,
38007
+ deviceUnlock: DeviceUnlock,
37866
38008
  deviceCancel: DeviceCancel,
37867
38009
  setU2FCounter: SetU2FCounter,
37868
38010
  getNextU2FCounter: GetNextU2FCounter,
@@ -38314,7 +38456,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
38314
38456
  try {
38315
38457
  yield waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
38316
38458
  const inner = () => __awaiter(void 0, void 0, void 0, function* () {
38317
- var _c, _d, _e;
38459
+ var _c, _d, _e, _f, _g;
38318
38460
  const versionRange = getMethodVersionRange(device.features, type => method.getVersionRange()[type]);
38319
38461
  if (device.features) {
38320
38462
  yield DataManager.checkAndReloadData();
@@ -38371,12 +38513,13 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
38371
38513
  require: support.require,
38372
38514
  }));
38373
38515
  }
38374
- 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);
38375
38517
  checkPassphraseEnableState(method, device.features);
38376
38518
  if (!passphraseStateSafety) {
38377
38519
  DevicePool.clearDeviceCache(method.payload.connectId);
38378
38520
  return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError));
38379
38521
  }
38522
+ postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_WINDOW));
38380
38523
  }
38381
38524
  try {
38382
38525
  yield method.checkSafetyLevelOnTestNet();
@@ -38387,7 +38530,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
38387
38530
  : hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'open safety check failed.');
38388
38531
  throw error;
38389
38532
  }
38390
- (_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();
38391
38534
  try {
38392
38535
  const response = yield method.run();
38393
38536
  Log.debug('Call API - Inner Method Run: ');
@@ -38705,7 +38848,7 @@ const checkPassphraseEnableState = (method, features) => {
38705
38848
  return;
38706
38849
  if ((features === null || features === void 0 ? void 0 : features.passphrase_protection) === true &&
38707
38850
  (method.payload.passphraseState == null || method.payload.passphraseState === '') &&
38708
- !method.payload.useEmptyPassphrase) {
38851
+ (!method.payload.useEmptyPassphrase || !method.payload.skipPassphraseCheck)) {
38709
38852
  DevicePool.clearDeviceCache(method.payload.connectId);
38710
38853
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceOpenedPassphrase);
38711
38854
  }
@@ -38747,11 +38890,11 @@ const onDevicePinHandler = (...[device, type, callback]) => __awaiter(void 0, vo
38747
38890
  });
38748
38891
  const onDeviceButtonHandler = (...[device, request]) => {
38749
38892
  postMessage(createDeviceMessage(DEVICE.BUTTON, Object.assign(Object.assign({}, request), { device: device.toMessageObject() })));
38750
- if (request.code === 'ButtonRequest_PinEntry') {
38751
- 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');
38752
38895
  postMessage(createUiMessage(UI_REQUEST.REQUEST_PIN, {
38753
38896
  device: device.toMessageObject(),
38754
- type: 'ButtonRequest_PinEntry',
38897
+ type: request.code,
38755
38898
  }));
38756
38899
  }
38757
38900
  else {
@@ -38762,22 +38905,24 @@ const onDeviceButtonHandler = (...[device, request]) => {
38762
38905
  const onDeviceFeaturesHandler = (...[_, features]) => {
38763
38906
  postMessage(createDeviceMessage(DEVICE.FEATURES, Object.assign({}, features)));
38764
38907
  };
38765
- 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* () {
38766
38909
  Log.debug('onDevicePassphraseHandler');
38767
38910
  const uiPromise = createUiPromise(UI_RESPONSE.RECEIVE_PASSPHRASE, device);
38768
38911
  postMessage(createUiMessage(UI_REQUEST.REQUEST_PASSPHRASE, {
38769
38912
  device: device.toMessageObject(),
38770
38913
  passphraseState: device.passphraseState,
38914
+ existsAttachPinUser: requestPayload.existsAttachPinUser,
38771
38915
  }));
38772
38916
  const uiResp = yield uiPromise.promise;
38773
- const { value, passphraseOnDevice, save } = uiResp.payload;
38917
+ const { value, passphraseOnDevice, save, attachPinOnDevice } = uiResp.payload;
38774
38918
  callback({
38775
38919
  passphrase: value.normalize('NFKD'),
38776
38920
  passphraseOnDevice,
38921
+ attachPinOnDevice,
38777
38922
  cache: save,
38778
38923
  });
38779
38924
  });
38780
- const onEmptyPassphraseHandler = (...[_, callback]) => {
38925
+ const onEmptyPassphraseHandler = (...[_, , callback]) => {
38781
38926
  Log.debug('onEmptyPassphraseHandler');
38782
38927
  callback({ passphrase: '' });
38783
38928
  };
@@ -38886,7 +39031,7 @@ const init = (settings, Transport, plugin) => __awaiter(void 0, void 0, void 0,
38886
39031
  yield DataManager.load(settings);
38887
39032
  initTransport(Transport, plugin);
38888
39033
  }
38889
- catch (_f) {
39034
+ catch (_h) {
38890
39035
  Log.error('DataManager.load error');
38891
39036
  }
38892
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;