@onekeyfe/hd-core 0.3.39 → 0.3.40-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 (51) hide show
  1. package/dist/api/FirmwareUpdate.d.ts +2 -0
  2. package/dist/api/FirmwareUpdate.d.ts.map +1 -1
  3. package/dist/api/device/DeviceFullyUploadResource.d.ts.map +1 -1
  4. package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
  5. package/dist/api/firmware/bootloaderHelper.d.ts +2 -1
  6. package/dist/api/firmware/bootloaderHelper.d.ts.map +1 -1
  7. package/dist/api/index.d.ts +2 -0
  8. package/dist/api/index.d.ts.map +1 -1
  9. package/dist/api/nervos/NervosGetAddress.d.ts +17 -0
  10. package/dist/api/nervos/NervosGetAddress.d.ts.map +1 -0
  11. package/dist/api/nervos/NervosSignTransaction.d.ts +21 -0
  12. package/dist/api/nervos/NervosSignTransaction.d.ts.map +1 -0
  13. package/dist/api/solana/SolSignTransaction.d.ts +13 -0
  14. package/dist/api/solana/SolSignTransaction.d.ts.map +1 -1
  15. package/dist/api/sui/SuiSignTransaction.d.ts +1 -1
  16. package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
  17. package/dist/index.d.ts +35 -5
  18. package/dist/index.js +487 -89
  19. package/dist/inject.d.ts.map +1 -1
  20. package/dist/types/api/deviceFullyUploadResource.d.ts +3 -1
  21. package/dist/types/api/deviceFullyUploadResource.d.ts.map +1 -1
  22. package/dist/types/api/deviceUpdateBootloader.d.ts +3 -1
  23. package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
  24. package/dist/types/api/export.d.ts +2 -0
  25. package/dist/types/api/export.d.ts.map +1 -1
  26. package/dist/types/api/index.d.ts +4 -0
  27. package/dist/types/api/index.d.ts.map +1 -1
  28. package/dist/types/api/nervosGetAddress.d.ts +15 -0
  29. package/dist/types/api/nervosGetAddress.d.ts.map +1 -0
  30. package/dist/types/api/nervosSignTransaction.d.ts +13 -0
  31. package/dist/types/api/nervosSignTransaction.d.ts.map +1 -0
  32. package/dist/utils/patch.d.ts +1 -1
  33. package/dist/utils/patch.d.ts.map +1 -1
  34. package/package.json +4 -4
  35. package/src/api/FirmwareUpdate.ts +121 -3
  36. package/src/api/device/DeviceFullyUploadResource.ts +17 -14
  37. package/src/api/device/DeviceUpdateBootloader.ts +26 -17
  38. package/src/api/firmware/bootloaderHelper.ts +13 -1
  39. package/src/api/index.ts +4 -0
  40. package/src/api/nervos/NervosGetAddress.ts +76 -0
  41. package/src/api/nervos/NervosSignTransaction.ts +105 -0
  42. package/src/api/solana/SolSignTransaction.ts +35 -0
  43. package/src/api/sui/SuiSignTransaction.ts +3 -3
  44. package/src/data/messages/messages.json +126 -0
  45. package/src/inject.ts +9 -2
  46. package/src/types/api/deviceFullyUploadResource.ts +3 -1
  47. package/src/types/api/deviceUpdateBootloader.ts +6 -1
  48. package/src/types/api/export.ts +3 -0
  49. package/src/types/api/index.ts +8 -0
  50. package/src/types/api/nervosGetAddress.ts +24 -0
  51. package/src/types/api/nervosSignTransaction.ts +19 -0
package/dist/index.js CHANGED
@@ -65,8 +65,8 @@ const createCoreApi = (call) => ({
65
65
  deviceSupportFeatures: connectId => call({ connectId, method: 'deviceSupportFeatures' }),
66
66
  deviceVerify: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceVerify' })),
67
67
  deviceWipe: connectId => call({ connectId, method: 'deviceWipe' }),
68
- deviceFullyUploadResource: connectId => call({ connectId, method: 'deviceFullyUploadResource' }),
69
- deviceUpdateBootloader: connectId => call({ connectId, method: 'deviceUpdateBootloader' }),
68
+ deviceFullyUploadResource: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceFullyUploadResource' })),
69
+ deviceUpdateBootloader: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceUpdateBootloader' })),
70
70
  getPassphraseState: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'getPassphraseState' })),
71
71
  evmGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'evmGetAddress' })),
72
72
  evmGetPublicKey: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'evmGetPublicKey' })),
@@ -136,6 +136,8 @@ const createCoreApi = (call) => ({
136
136
  nostrDecryptMessage: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'nostrDecryptMessage' })),
137
137
  nostrSignSchnorr: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'nostrSignSchnorr' })),
138
138
  lnurlAuth: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'lnurlAuth' })),
139
+ nervosGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'nervosGetAddress' })),
140
+ nervosSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'nervosSignTransaction' })),
139
141
  });
140
142
 
141
143
  const lowLevelInject = ({ call, cancel, dispose, eventEmitter, init, uiResponse, updateSettings, addHardwareGlobalEventListener, }) => {
@@ -706,7 +708,12 @@ function __asyncValues(o) {
706
708
  return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
707
709
  function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
708
710
  function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
709
- }
711
+ }
712
+
713
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
714
+ var e = new Error(message);
715
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
716
+ };
710
717
 
711
718
  const HD_HARDENED = 0x80000000;
712
719
  const toHardened = (n) => (n | HD_HARDENED) >>> 0;
@@ -6555,6 +6562,26 @@ var nested$1 = {
6555
6562
  onekey_serial_no: {
6556
6563
  type: "string",
6557
6564
  id: 612
6565
+ },
6566
+ onekey_boot_build_id: {
6567
+ type: "string",
6568
+ id: 613
6569
+ },
6570
+ onekey_ble_name: {
6571
+ type: "string",
6572
+ id: 614
6573
+ },
6574
+ onekey_ble_version: {
6575
+ type: "string",
6576
+ id: 615
6577
+ },
6578
+ onekey_ble_build_id: {
6579
+ type: "string",
6580
+ id: 616
6581
+ },
6582
+ onekey_ble_hash: {
6583
+ type: "bytes",
6584
+ id: 617
6558
6585
  }
6559
6586
  },
6560
6587
  nested: {
@@ -8873,6 +8900,106 @@ var nested$1 = {
8873
8900
  }
8874
8901
  }
8875
8902
  },
8903
+ NervosGetAddress: {
8904
+ fields: {
8905
+ address_n: {
8906
+ rule: "repeated",
8907
+ type: "uint32",
8908
+ id: 1,
8909
+ options: {
8910
+ packed: false
8911
+ }
8912
+ },
8913
+ network: {
8914
+ rule: "required",
8915
+ type: "string",
8916
+ id: 2
8917
+ },
8918
+ show_display: {
8919
+ type: "bool",
8920
+ id: 3
8921
+ }
8922
+ }
8923
+ },
8924
+ NervosAddress: {
8925
+ fields: {
8926
+ address: {
8927
+ rule: "required",
8928
+ type: "string",
8929
+ id: 1
8930
+ }
8931
+ }
8932
+ },
8933
+ NervosSignTx: {
8934
+ fields: {
8935
+ address_n: {
8936
+ rule: "repeated",
8937
+ type: "uint32",
8938
+ id: 1,
8939
+ options: {
8940
+ packed: false
8941
+ }
8942
+ },
8943
+ data_initial_chunk: {
8944
+ rule: "required",
8945
+ type: "bytes",
8946
+ id: 2
8947
+ },
8948
+ witness_buffer: {
8949
+ rule: "required",
8950
+ type: "bytes",
8951
+ id: 3
8952
+ },
8953
+ network: {
8954
+ rule: "required",
8955
+ type: "string",
8956
+ id: 4
8957
+ },
8958
+ data_length: {
8959
+ type: "uint32",
8960
+ id: 5
8961
+ }
8962
+ }
8963
+ },
8964
+ NervosSignedTx: {
8965
+ fields: {
8966
+ signature: {
8967
+ rule: "required",
8968
+ type: "bytes",
8969
+ id: 1
8970
+ },
8971
+ address: {
8972
+ rule: "required",
8973
+ type: "string",
8974
+ id: 2
8975
+ }
8976
+ }
8977
+ },
8978
+ NervosTxRequest: {
8979
+ fields: {
8980
+ data_length: {
8981
+ type: "uint32",
8982
+ id: 1
8983
+ },
8984
+ public_key: {
8985
+ type: "bytes",
8986
+ id: 2
8987
+ },
8988
+ signature: {
8989
+ type: "bytes",
8990
+ id: 3
8991
+ }
8992
+ }
8993
+ },
8994
+ NervosTxAck: {
8995
+ fields: {
8996
+ data_chunk: {
8997
+ rule: "required",
8998
+ type: "bytes",
8999
+ id: 1
9000
+ }
9001
+ }
9002
+ },
8876
9003
  NexaGetAddress: {
8877
9004
  fields: {
8878
9005
  address_n: {
@@ -11317,6 +11444,12 @@ var nested$1 = {
11317
11444
  MessageType_NostrSignedSchnorr: 11509,
11318
11445
  MessageType_LnurlAuth: 11600,
11319
11446
  MessageType_LnurlAuthResp: 11601,
11447
+ MessageType_NervosGetAddress: 11701,
11448
+ MessageType_NervosAddress: 11702,
11449
+ MessageType_NervosSignTx: 11703,
11450
+ MessageType_NervosSignedTx: 11704,
11451
+ MessageType_NervosTxRequest: 11705,
11452
+ MessageType_NervosTxAck: 11706,
11320
11453
  MessageType_DeviceBackToBoot: 903,
11321
11454
  MessageType_DeviceInfoSettings: 10001,
11322
11455
  MessageType_GetDeviceInfo: 10002,
@@ -22657,6 +22790,14 @@ function shouldUpdateBootloaderForClassicAndMini({ currentVersion, bootloaderVer
22657
22790
  }
22658
22791
  return false;
22659
22792
  }
22793
+ function isEnteredManuallyBoot(features, updateType) {
22794
+ const deviceType = getDeviceType(features);
22795
+ const isMini = deviceType === 'mini';
22796
+ const isBoot183ClassicUpBle = updateType === 'firmware' &&
22797
+ deviceType === 'classic' &&
22798
+ features.bootloader_version === '1.8.3';
22799
+ return isMini || isBoot183ClassicUpBle;
22800
+ }
22660
22801
 
22661
22802
  function checkNeedUpdateBootForTouch(features) {
22662
22803
  const deviceType = getDeviceType(features);
@@ -22722,7 +22863,7 @@ const createLogMessage = (type, payload) => ({
22722
22863
 
22723
22864
  const MAX_ENTRIES = 500;
22724
22865
  let postMessage$1;
22725
- class Log$9 {
22866
+ class Log$a {
22726
22867
  constructor(prefix, enabled) {
22727
22868
  this.prefix = prefix;
22728
22869
  this.enabled = enabled;
@@ -22774,7 +22915,7 @@ class Log$9 {
22774
22915
  }
22775
22916
  const _logs = {};
22776
22917
  const initLog = (prefix, enabled) => {
22777
- const instance = new Log$9(prefix, !!enabled);
22918
+ const instance = new Log$a(prefix, !!enabled);
22778
22919
  _logs[prefix] = instance;
22779
22920
  return instance;
22780
22921
  };
@@ -23730,7 +23871,7 @@ const LogBlockEvent = new Set([
23730
23871
  UI_RESPONSE.RECEIVE_PASSPHRASE,
23731
23872
  ]);
23732
23873
 
23733
- const Log$8 = getLogger(exports.LoggerNames.DevicePool);
23874
+ const Log$9 = getLogger(exports.LoggerNames.DevicePool);
23734
23875
  const getDiff = (current, descriptors) => {
23735
23876
  const connected = descriptors.filter(d => current.find(x => x.path === d.path) === undefined);
23736
23877
  const disconnected = current.filter(d => descriptors.find(x => x.path === d.path) === undefined);
@@ -23788,30 +23929,25 @@ class DevicePool extends events.exports {
23788
23929
  yield this._checkDevicePool(initOptions);
23789
23930
  return { devices, deviceList };
23790
23931
  }
23791
- Log$8.debug('found device in cache, but path is different: ', connectId);
23932
+ Log$9.debug('found device in cache, but path is different: ', connectId);
23792
23933
  }
23793
23934
  }
23794
23935
  try {
23795
- for (_a = true, descriptorList_1 = __asyncValues(descriptorList); descriptorList_1_1 = yield descriptorList_1.next(), _b = descriptorList_1_1.done, !_b;) {
23936
+ for (_a = true, descriptorList_1 = __asyncValues(descriptorList); descriptorList_1_1 = yield descriptorList_1.next(), _b = descriptorList_1_1.done, !_b; _a = true) {
23796
23937
  _d = descriptorList_1_1.value;
23797
23938
  _a = false;
23798
- try {
23799
- const descriptor = _d;
23800
- const device = yield this._createDevice(descriptor, initOptions);
23801
- if (device.features) {
23802
- const uuid = getDeviceUUID(device.features);
23803
- if (this.devicesCache[uuid]) {
23804
- const cache = this.devicesCache[uuid];
23805
- cache.updateDescriptor(descriptor, true);
23806
- }
23807
- this.devicesCache[uuid] = device;
23808
- devices[uuid] = device;
23939
+ const descriptor = _d;
23940
+ const device = yield this._createDevice(descriptor, initOptions);
23941
+ if (device.features) {
23942
+ const uuid = getDeviceUUID(device.features);
23943
+ if (this.devicesCache[uuid]) {
23944
+ const cache = this.devicesCache[uuid];
23945
+ cache.updateDescriptor(descriptor, true);
23809
23946
  }
23810
- deviceList.push(device);
23811
- }
23812
- finally {
23813
- _a = true;
23947
+ this.devicesCache[uuid] = device;
23948
+ devices[uuid] = device;
23814
23949
  }
23950
+ deviceList.push(device);
23815
23951
  }
23816
23952
  }
23817
23953
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -23854,7 +23990,7 @@ class DevicePool extends events.exports {
23854
23990
  for (let i = this.connectedPool.length - 1; i >= 0; i--) {
23855
23991
  const descriptor = this.connectedPool[i];
23856
23992
  const device = yield this._createDevice(descriptor, initOptions);
23857
- Log$8.debug('emit DEVICE.CONNECT: ', device === null || device === void 0 ? void 0 : device.features);
23993
+ Log$9.debug('emit DEVICE.CONNECT: ', device === null || device === void 0 ? void 0 : device.features);
23858
23994
  this.emitter.emit(DEVICE.CONNECT, device);
23859
23995
  this.connectedPool.splice(i, 1);
23860
23996
  }
@@ -23886,7 +24022,7 @@ class DevicePool extends events.exports {
23886
24022
  this._addConnectedDeviceToPool(d);
23887
24023
  return;
23888
24024
  }
23889
- Log$8.debug('emit DEVICE.CONNECT: ', device.features);
24025
+ Log$9.debug('emit DEVICE.CONNECT: ', device.features);
23890
24026
  this.emitter.emit(DEVICE.CONNECT, device);
23891
24027
  });
23892
24028
  diff.disconnected.forEach(d => {
@@ -23896,7 +24032,7 @@ class DevicePool extends events.exports {
23896
24032
  this._addDisconnectedDeviceToPool(d);
23897
24033
  return;
23898
24034
  }
23899
- Log$8.debug('emit DEVICE.DISCONNECT: ', device.features);
24035
+ Log$9.debug('emit DEVICE.DISCONNECT: ', device.features);
23900
24036
  this.emitter.emit(DEVICE.DISCONNECT, device);
23901
24037
  });
23902
24038
  }
@@ -23933,13 +24069,13 @@ DevicePool.disconnectPool = [];
23933
24069
  DevicePool.devicesCache = {};
23934
24070
  DevicePool.emitter = new events.exports();
23935
24071
 
23936
- const Log$7 = getLogger(exports.LoggerNames.Transport);
24072
+ const Log$8 = getLogger(exports.LoggerNames.Transport);
23937
24073
  const BleLogger = getLogger(exports.LoggerNames.HdBleTransport);
23938
24074
  const HttpLogger = getLogger(exports.LoggerNames.HdTransportHttp);
23939
24075
  const LowLevelLogger = getLogger(exports.LoggerNames.HdTransportLowLevel);
23940
24076
  class TransportManager {
23941
24077
  static load() {
23942
- Log$7.debug('transport manager load');
24078
+ Log$8.debug('transport manager load');
23943
24079
  this.defaultMessages = DataManager.getProtobufMessages();
23944
24080
  this.currentMessages = this.defaultMessages;
23945
24081
  this.messageVersion = 'latest';
@@ -23948,14 +24084,14 @@ class TransportManager {
23948
24084
  return __awaiter(this, void 0, void 0, function* () {
23949
24085
  try {
23950
24086
  const env = DataManager.getSettings('env');
23951
- Log$7.debug('Initializing transports');
24087
+ Log$8.debug('Initializing transports');
23952
24088
  if (env === 'react-native') {
23953
24089
  if (!this.reactNativeInit) {
23954
24090
  yield this.transport.init(BleLogger, DevicePool.emitter);
23955
24091
  this.reactNativeInit = true;
23956
24092
  }
23957
24093
  else {
23958
- Log$7.debug('React Native Do Not Initializing transports');
24094
+ Log$8.debug('React Native Do Not Initializing transports');
23959
24095
  }
23960
24096
  }
23961
24097
  else if (env === 'lowlevel') {
@@ -23967,12 +24103,12 @@ class TransportManager {
23967
24103
  else {
23968
24104
  yield this.transport.init(HttpLogger);
23969
24105
  }
23970
- Log$7.debug('Configuring transports');
24106
+ Log$8.debug('Configuring transports');
23971
24107
  yield this.transport.configure(JSON.stringify(this.defaultMessages));
23972
- Log$7.debug('Configuring transports done');
24108
+ Log$8.debug('Configuring transports done');
23973
24109
  }
23974
24110
  catch (error) {
23975
- Log$7.debug('Initializing transports error: ', error);
24111
+ Log$8.debug('Initializing transports error: ', error);
23976
24112
  if (error.code === 'ECONNABORTED') {
23977
24113
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
23978
24114
  }
@@ -23981,12 +24117,12 @@ class TransportManager {
23981
24117
  }
23982
24118
  static reconfigure(features) {
23983
24119
  return __awaiter(this, void 0, void 0, function* () {
23984
- Log$7.debug(`Begin reconfiguring transports`);
24120
+ Log$8.debug(`Begin reconfiguring transports`);
23985
24121
  const { messageVersion, messages } = getSupportMessageVersion(features);
23986
24122
  if (this.currentMessages === messages || !messages) {
23987
24123
  return;
23988
24124
  }
23989
- Log$7.debug(`Reconfiguring transports version:${messageVersion}`);
24125
+ Log$8.debug(`Reconfiguring transports version:${messageVersion}`);
23990
24126
  try {
23991
24127
  yield this.transport.configure(JSON.stringify(messages));
23992
24128
  this.currentMessages = messages;
@@ -24007,9 +24143,9 @@ class TransportManager {
24007
24143
  }
24008
24144
  if (plugin) {
24009
24145
  this.plugin = plugin;
24010
- Log$7.debug('set transport plugin: ', this.plugin);
24146
+ Log$8.debug('set transport plugin: ', this.plugin);
24011
24147
  }
24012
- Log$7.debug('set transport: ', this.transport);
24148
+ Log$8.debug('set transport: ', this.transport);
24013
24149
  }
24014
24150
  static getTransport() {
24015
24151
  return this.transport;
@@ -24034,7 +24170,7 @@ const assertType = (res, resType) => {
24034
24170
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ResponseUnexpectTypeError, `assertType: Response of unexpected type: ${res.type}. Should be ${resType}`);
24035
24171
  }
24036
24172
  };
24037
- const Log$6 = getLogger(exports.LoggerNames.DeviceCommands);
24173
+ const Log$7 = getLogger(exports.LoggerNames.DeviceCommands);
24038
24174
  class DeviceCommands {
24039
24175
  constructor(device, mainId) {
24040
24176
  this.device = device;
@@ -24056,16 +24192,16 @@ class DeviceCommands {
24056
24192
  call(type, msg = {}) {
24057
24193
  var _a;
24058
24194
  return __awaiter(this, void 0, void 0, function* () {
24059
- Log$6.debug('[DeviceCommands] [call] Sending', type);
24195
+ Log$7.debug('[DeviceCommands] [call] Sending', type);
24060
24196
  try {
24061
24197
  const promise = this.transport.call(this.mainId, type, msg);
24062
24198
  this.callPromise = promise;
24063
24199
  const res = yield promise;
24064
- Log$6.debug('[DeviceCommands] [call] Received', res.type);
24200
+ Log$7.debug('[DeviceCommands] [call] Received', res.type);
24065
24201
  return res;
24066
24202
  }
24067
24203
  catch (error) {
24068
- Log$6.debug('[DeviceCommands] [call] Received error', error);
24204
+ Log$7.debug('[DeviceCommands] [call] Received error', error);
24069
24205
  if (error.errorCode === hdShared.HardwareErrorCode.BleDeviceBondError) {
24070
24206
  return {
24071
24207
  type: 'BleDeviceBondError',
@@ -24077,7 +24213,7 @@ class DeviceCommands {
24077
24213
  const responseData = (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data;
24078
24214
  const responseError = responseData === null || responseData === void 0 ? void 0 : responseData.error;
24079
24215
  if (responseData) {
24080
- Log$6.debug('error response', responseData);
24216
+ Log$7.debug('error response', responseData);
24081
24217
  }
24082
24218
  if (responseError === 'device disconnected during action') {
24083
24219
  return { type: 'BridgeNetworkError', message: {} };
@@ -24104,7 +24240,7 @@ class DeviceCommands {
24104
24240
  assertType(response, resType);
24105
24241
  }
24106
24242
  catch (error) {
24107
- Log$6.debug('DeviceCommands typedcall error: ', error);
24243
+ Log$7.debug('DeviceCommands typedcall error: ', error);
24108
24244
  if (error instanceof hdShared.HardwareError) {
24109
24245
  if (error.errorCode === hdShared.HardwareErrorCode.ResponseUnexpectTypeError) {
24110
24246
  if (error.message.indexOf('BridgeNetworkError') > -1) {
@@ -24131,10 +24267,10 @@ class DeviceCommands {
24131
24267
  _filterCommonTypes(res, callType) {
24132
24268
  try {
24133
24269
  if (DataManager.getSettings('env') === 'react-native') {
24134
- Log$6.debug('_filterCommonTypes: ', JSON.stringify(res));
24270
+ Log$7.debug('_filterCommonTypes: ', JSON.stringify(res));
24135
24271
  }
24136
24272
  else {
24137
- Log$6.debug('_filterCommonTypes: ', res);
24273
+ Log$7.debug('_filterCommonTypes: ', res);
24138
24274
  }
24139
24275
  }
24140
24276
  catch (error) {
@@ -24250,7 +24386,7 @@ class DeviceCommands {
24250
24386
  });
24251
24387
  }
24252
24388
  else {
24253
- Log$6.error('[DeviceCommands] [call] Passphrase callback not configured, cancelling request');
24389
+ Log$7.error('[DeviceCommands] [call] Passphrase callback not configured, cancelling request');
24254
24390
  reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, '_promptPassphrase: Passphrase callback not configured'));
24255
24391
  }
24256
24392
  });
@@ -24277,7 +24413,7 @@ const parseRunOptions = (options) => {
24277
24413
  options = {};
24278
24414
  return options;
24279
24415
  };
24280
- const Log$5 = getLogger(exports.LoggerNames.Device);
24416
+ const Log$6 = getLogger(exports.LoggerNames.Device);
24281
24417
  const deviceSessionCache = {};
24282
24418
  class Device extends events.exports {
24283
24419
  constructor(descriptor) {
@@ -24360,11 +24496,11 @@ class Device extends events.exports {
24360
24496
  if (DataManager.isBleConnect(env)) {
24361
24497
  const res = yield ((_a = this.deviceConnector) === null || _a === void 0 ? void 0 : _a.acquire(this.originalDescriptor.id));
24362
24498
  this.mainId = (_b = res.uuid) !== null && _b !== void 0 ? _b : '';
24363
- Log$5.debug('Expected uuid:', this.mainId);
24499
+ Log$6.debug('Expected uuid:', this.mainId);
24364
24500
  }
24365
24501
  else {
24366
24502
  this.mainId = yield ((_c = this.deviceConnector) === null || _c === void 0 ? void 0 : _c.acquire(this.originalDescriptor.path, this.originalDescriptor.session));
24367
- Log$5.debug('Expected session id:', this.mainId);
24503
+ Log$6.debug('Expected session id:', this.mainId);
24368
24504
  }
24369
24505
  this.updateDescriptor({ [mainIdKey]: this.mainId });
24370
24506
  if (this.commands) {
@@ -24405,7 +24541,7 @@ class Device extends events.exports {
24405
24541
  this.updateDescriptor({ session: null });
24406
24542
  }
24407
24543
  catch (err) {
24408
- Log$5.error('[Device] release error: ', err);
24544
+ Log$6.error('[Device] release error: ', err);
24409
24545
  }
24410
24546
  finally {
24411
24547
  this.needReloadDevice = true;
@@ -24424,8 +24560,8 @@ class Device extends events.exports {
24424
24560
  }
24425
24561
  getInternalState(_deviceId) {
24426
24562
  var _a, _b;
24427
- Log$5.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}`);
24428
- Log$5.debug('getInternalState session cache: ', deviceSessionCache);
24563
+ Log$6.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}`);
24564
+ Log$6.debug('getInternalState session cache: ', deviceSessionCache);
24429
24565
  const deviceId = _deviceId || ((_b = this.features) === null || _b === void 0 ? void 0 : _b.device_id);
24430
24566
  if (!deviceId)
24431
24567
  return undefined;
@@ -24435,7 +24571,7 @@ class Device extends events.exports {
24435
24571
  return deviceSessionCache[usePassKey];
24436
24572
  }
24437
24573
  tryFixInternalState(state, deviceId, sessionId = null) {
24438
- Log$5.debug('tryFixInternalState session param: ', `device_id: ${deviceId}`, `passphraseState: ${state}`, `sessionId: ${sessionId}`);
24574
+ Log$6.debug('tryFixInternalState session param: ', `device_id: ${deviceId}`, `passphraseState: ${state}`, `sessionId: ${sessionId}`);
24439
24575
  const key = `${deviceId}`;
24440
24576
  const session = deviceSessionCache[key];
24441
24577
  if (session) {
@@ -24445,11 +24581,11 @@ class Device extends events.exports {
24445
24581
  else if (sessionId) {
24446
24582
  deviceSessionCache[this.generateStateKey(deviceId, state)] = sessionId;
24447
24583
  }
24448
- Log$5.debug('tryFixInternalState session cache: ', deviceSessionCache);
24584
+ Log$6.debug('tryFixInternalState session cache: ', deviceSessionCache);
24449
24585
  }
24450
24586
  setInternalState(state, initSession) {
24451
24587
  var _a, _b;
24452
- Log$5.debug('setInternalState session param: ', `state: ${state}`, `initSession: ${initSession}`, `device_id: ${(_a = this.features) === null || _a === void 0 ? void 0 : _a.device_id}`, `passphraseState: ${this.passphraseState}`);
24588
+ Log$6.debug('setInternalState session param: ', `state: ${state}`, `initSession: ${initSession}`, `device_id: ${(_a = this.features) === null || _a === void 0 ? void 0 : _a.device_id}`, `passphraseState: ${this.passphraseState}`);
24453
24589
  if (!this.features)
24454
24590
  return;
24455
24591
  if (!this.passphraseState && !initSession)
@@ -24461,11 +24597,11 @@ class Device extends events.exports {
24461
24597
  if (state) {
24462
24598
  deviceSessionCache[key] = state;
24463
24599
  }
24464
- Log$5.debug('setInternalState done session cache: ', deviceSessionCache);
24600
+ Log$6.debug('setInternalState done session cache: ', deviceSessionCache);
24465
24601
  }
24466
24602
  clearInternalState(_deviceId) {
24467
24603
  var _a;
24468
- Log$5.debug('clearInternalState param: ', _deviceId);
24604
+ Log$6.debug('clearInternalState param: ', _deviceId);
24469
24605
  const deviceId = _deviceId || ((_a = this.features) === null || _a === void 0 ? void 0 : _a.device_id);
24470
24606
  if (!deviceId)
24471
24607
  return;
@@ -24478,7 +24614,7 @@ class Device extends events.exports {
24478
24614
  }
24479
24615
  initialize(options) {
24480
24616
  return __awaiter(this, void 0, void 0, function* () {
24481
- Log$5.debug('initialize param:', options);
24617
+ Log$6.debug('initialize param:', options);
24482
24618
  this.passphraseState = options === null || options === void 0 ? void 0 : options.passphraseState;
24483
24619
  if (options === null || options === void 0 ? void 0 : options.initSession) {
24484
24620
  this.clearInternalState(options === null || options === void 0 ? void 0 : options.deviceId);
@@ -24491,7 +24627,7 @@ class Device extends events.exports {
24491
24627
  if (options === null || options === void 0 ? void 0 : options.deriveCardano) {
24492
24628
  payload.derive_cardano = true;
24493
24629
  }
24494
- Log$5.debug('initialize payload:', payload);
24630
+ Log$6.debug('initialize payload:', payload);
24495
24631
  const { message } = yield this.commands.typedCall('Initialize', 'Features', payload);
24496
24632
  this._updateFeatures(message, options === null || options === void 0 ? void 0 : options.initSession);
24497
24633
  yield TransportManager.reconfigure(message);
@@ -24542,7 +24678,7 @@ class Device extends events.exports {
24542
24678
  return __awaiter(this, void 0, void 0, function* () {
24543
24679
  if (this.runPromise) {
24544
24680
  yield this.interruptionFromOutside();
24545
- Log$5.debug('[Device] run error:', 'Device is running, but will cancel previous operate');
24681
+ Log$6.debug('[Device] run error:', 'Device is running, but will cancel previous operate');
24546
24682
  }
24547
24683
  options = parseRunOptions(options);
24548
24684
  this.runPromise = hdShared.createDeferred(this._runInner.bind(this, fn, options));
@@ -24588,7 +24724,7 @@ class Device extends events.exports {
24588
24724
  options.keepSession === false) {
24589
24725
  this.keepSession = false;
24590
24726
  yield this.release();
24591
- Log$5.debug('release device, mainId: ', this.mainId);
24727
+ Log$6.debug('release device, mainId: ', this.mainId);
24592
24728
  }
24593
24729
  if (this.runPromise) {
24594
24730
  this.runPromise.resolve();
@@ -24748,7 +24884,7 @@ const getBleFirmwareReleaseInfo = (features) => {
24748
24884
  };
24749
24885
  };
24750
24886
 
24751
- const Log$4 = getLogger(exports.LoggerNames.Method);
24887
+ const Log$5 = getLogger(exports.LoggerNames.Method);
24752
24888
  class BaseMethod {
24753
24889
  constructor(message) {
24754
24890
  this.shouldEnsureConnected = true;
@@ -24806,7 +24942,7 @@ class BaseMethod {
24806
24942
  checkFlag = true;
24807
24943
  }
24808
24944
  if (checkFlag && ((_c = this.device.features) === null || _c === void 0 ? void 0 : _c.safety_checks) === 'Strict') {
24809
- Log$4.debug('will change safety_checks level');
24945
+ Log$5.debug('will change safety_checks level');
24810
24946
  yield this.device.commands.typedCall('ApplySettings', 'Success', {
24811
24947
  safety_checks: 'PromptTemporarily',
24812
24948
  });
@@ -25865,7 +26001,6 @@ class DeviceFullyUploadResource extends BaseMethod {
25865
26001
  };
25866
26002
  }
25867
26003
  init() {
25868
- this.notAllowDeviceMode = [UI_REQUEST.BOOTLOADER, UI_REQUEST.INITIALIZE];
25869
26004
  this.requireDeviceMode = [];
25870
26005
  this.useDevicePassphraseState = false;
25871
26006
  this.skipForceUpdateCheck = true;
@@ -25884,16 +26019,20 @@ class DeviceFullyUploadResource extends BaseMethod {
25884
26019
  const { features } = device;
25885
26020
  if (!(features === null || features === void 0 ? void 0 : features.bootloader_mode) && features) {
25886
26021
  if (features) {
25887
- this.postTipMessage('CheckLatestUiResource');
25888
- const resourceUrl = DataManager.getSysFullResource(features);
25889
- if (resourceUrl) {
25890
- this.postTipMessage('DownloadLatestUiResource');
25891
- const resource = yield getSysResourceBinary(resourceUrl);
25892
- this.postTipMessage('DownloadLatestUiResourceSuccess');
25893
- if (resource) {
25894
- yield updateResources(this.device.getCommands().typedCall.bind(this.device.getCommands()), this.postMessage, device, resource.binary);
26022
+ let { binary } = this.payload;
26023
+ if (!binary) {
26024
+ this.postTipMessage('CheckLatestUiResource');
26025
+ const resourceUrl = DataManager.getSysFullResource(features);
26026
+ if (resourceUrl) {
26027
+ this.postTipMessage('DownloadLatestUiResource');
26028
+ const resource = yield getSysResourceBinary(resourceUrl);
26029
+ this.postTipMessage('DownloadLatestUiResourceSuccess');
26030
+ if (resource) {
26031
+ binary = resource.binary;
26032
+ }
25895
26033
  }
25896
26034
  }
26035
+ yield updateResources(this.device.getCommands().typedCall.bind(this.device.getCommands()), this.postMessage, device, binary);
25897
26036
  }
25898
26037
  }
25899
26038
  });
@@ -25920,23 +26059,31 @@ class DeviceUpdateBootloader extends BaseMethod {
25920
26059
  this.skipForceUpdateCheck = true;
25921
26060
  }
25922
26061
  updateTouchBootloader(device, features) {
26062
+ var _a;
25923
26063
  return __awaiter(this, void 0, void 0, function* () {
25924
26064
  if (features && !features.bootloader_mode) {
25925
- if (features && checkNeedUpdateBootForTouch(features)) {
25926
- this.postTipMessage('CheckLatestUiResource');
25927
- const resourceUrl = DataManager.getBootloaderResource(features);
25928
- if (resourceUrl) {
25929
- this.postTipMessage('DownloadLatestBootloaderResource');
25930
- const resource = yield getSysResourceBinary(resourceUrl);
25931
- this.postTipMessage('DownloadLatestBootloaderResourceSuccess');
25932
- if (resource) {
25933
- if (!checkBootloaderLength(resource.binary)) {
25934
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CheckDownloadFileError);
26065
+ const needUpdateBoot = checkNeedUpdateBootForTouch(features);
26066
+ const existsBootRes = ((_a = this.payload) === null || _a === void 0 ? void 0 : _a.binary) != null;
26067
+ const hasUpdateBootloader = needUpdateBoot || existsBootRes;
26068
+ if (features && hasUpdateBootloader) {
26069
+ let { binary } = this.payload;
26070
+ if (!binary) {
26071
+ this.postTipMessage('CheckLatestUiResource');
26072
+ const resourceUrl = DataManager.getBootloaderResource(features);
26073
+ if (resourceUrl) {
26074
+ this.postTipMessage('DownloadLatestBootloaderResource');
26075
+ const resource = yield getSysResourceBinary(resourceUrl);
26076
+ this.postTipMessage('DownloadLatestBootloaderResourceSuccess');
26077
+ if (resource) {
26078
+ binary = resource.binary;
25935
26079
  }
25936
- yield updateBootloader(this.device.getCommands().typedCall.bind(this.device.getCommands()), this.postMessage, device, resource.binary);
25937
- return Promise.resolve(true);
25938
26080
  }
25939
26081
  }
26082
+ if (!checkBootloaderLength(binary)) {
26083
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CheckDownloadFileError);
26084
+ }
26085
+ yield updateBootloader(this.device.getCommands().typedCall.bind(this.device.getCommands()), this.postMessage, device, binary);
26086
+ return Promise.resolve(true);
25940
26087
  }
25941
26088
  }
25942
26089
  return Promise.resolve(true);
@@ -25955,10 +26102,22 @@ class DeviceUpdateBootloader extends BaseMethod {
25955
26102
  }
25956
26103
  }
25957
26104
 
26105
+ const Log$4 = getLogger(exports.LoggerNames.Method);
25958
26106
  class FirmwareUpdate extends BaseMethod {
26107
+ constructor() {
26108
+ super(...arguments);
26109
+ this.postTipMessage = (message) => {
26110
+ this.postMessage(createUiMessage(UI_REQUEST.FIRMWARE_TIP, {
26111
+ device: this.device.toMessageObject(),
26112
+ data: {
26113
+ message,
26114
+ },
26115
+ }));
26116
+ };
26117
+ }
25959
26118
  init() {
25960
26119
  this.notAllowDeviceMode = [UI_REQUEST.BOOTLOADER, UI_REQUEST.INITIALIZE];
25961
- this.requireDeviceMode = [UI_REQUEST.BOOTLOADER];
26120
+ this.requireDeviceMode = [];
25962
26121
  this.useDevicePassphraseState = false;
25963
26122
  this.skipForceUpdateCheck = true;
25964
26123
  const { payload } = this;
@@ -25977,10 +26136,80 @@ class FirmwareUpdate extends BaseMethod {
25977
26136
  this.params = Object.assign(Object.assign({}, this.params), { binary: payload.binary });
25978
26137
  }
25979
26138
  }
26139
+ checkDeviceToBootloader(connectId) {
26140
+ const checkPromise = hdShared.createDeferred();
26141
+ const env = DataManager.getSettings('env');
26142
+ const isBleReconnect = connectId && DataManager.isBleConnect(env);
26143
+ Log$4.log('FirmwareUpdateV2 [checkDeviceToBootloader] isBleReconnect: ', isBleReconnect);
26144
+ const intervalTimer = setInterval(() => __awaiter(this, void 0, void 0, function* () {
26145
+ var _a, _b, _c, _d, _e, _f;
26146
+ if (isBleReconnect) {
26147
+ try {
26148
+ yield ((_a = this.device.deviceConnector) === null || _a === void 0 ? void 0 : _a.acquire(this.device.originalDescriptor.id, null, true));
26149
+ yield this.device.initialize();
26150
+ if ((_b = this.device.features) === null || _b === void 0 ? void 0 : _b.bootloader_mode) {
26151
+ clearInterval(intervalTimer);
26152
+ checkPromise === null || checkPromise === void 0 ? void 0 : checkPromise.resolve(true);
26153
+ }
26154
+ }
26155
+ catch (e) {
26156
+ Log$4.log('catch Bluetooth error when device is restarting: ', e);
26157
+ }
26158
+ }
26159
+ else {
26160
+ const deviceDiff = yield ((_c = this.device.deviceConnector) === null || _c === void 0 ? void 0 : _c.enumerate());
26161
+ const devicesDescriptor = (_d = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _d !== void 0 ? _d : [];
26162
+ const { deviceList } = yield DevicePool.getDevices(devicesDescriptor, connectId);
26163
+ if (deviceList.length === 1 && ((_f = (_e = deviceList[0]) === null || _e === void 0 ? void 0 : _e.features) === null || _f === void 0 ? void 0 : _f.bootloader_mode)) {
26164
+ this.device.updateFromCache(deviceList[0]);
26165
+ this.device.commands.disposed = false;
26166
+ clearInterval(intervalTimer);
26167
+ checkPromise === null || checkPromise === void 0 ? void 0 : checkPromise.resolve(true);
26168
+ }
26169
+ }
26170
+ }), isBleReconnect ? 3000 : 2000);
26171
+ setTimeout(() => {
26172
+ if (checkPromise) {
26173
+ clearInterval(intervalTimer);
26174
+ checkPromise.reject(new Error());
26175
+ }
26176
+ }, 30000);
26177
+ return checkPromise;
26178
+ }
25980
26179
  run() {
25981
26180
  var _a;
25982
26181
  return __awaiter(this, void 0, void 0, function* () {
25983
26182
  const { device, params } = this;
26183
+ const { features, commands } = device;
26184
+ const deviceType = getDeviceType(features);
26185
+ if (!(features === null || features === void 0 ? void 0 : features.bootloader_mode) && features) {
26186
+ const uuid = getDeviceUUID(features);
26187
+ if (isEnteredManuallyBoot(features, params.updateType)) {
26188
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateManuallyEnterBoot));
26189
+ }
26190
+ try {
26191
+ this.postTipMessage('AutoRebootToBootloader');
26192
+ const bootRes = yield commands.typedCall('DeviceBackToBoot', 'Success');
26193
+ if (bootRes.type === 'CallMethodError') {
26194
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateAutoEnterBootFailure);
26195
+ }
26196
+ this.postTipMessage('GoToBootloaderSuccess');
26197
+ const checkPromise = this.checkDeviceToBootloader(this.payload.connectId);
26198
+ if (DeviceModelToTypes.model_classic.includes(deviceType)) {
26199
+ DevicePool.clearDeviceCache(uuid);
26200
+ }
26201
+ delete DevicePool.devicesCache[''];
26202
+ yield (checkPromise === null || checkPromise === void 0 ? void 0 : checkPromise.promise);
26203
+ yield wait(deviceType === 'touch' ? 3000 : 1500);
26204
+ }
26205
+ catch (e) {
26206
+ if (e instanceof hdShared.HardwareError) {
26207
+ return Promise.reject(e);
26208
+ }
26209
+ console.log('auto go to bootloader mode failed: ', e);
26210
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateAutoEnterBootFailure));
26211
+ }
26212
+ }
25984
26213
  let binary;
25985
26214
  try {
25986
26215
  if (params.binary) {
@@ -28701,6 +28930,16 @@ class SolSignTransaction extends BaseMethod {
28701
28930
  });
28702
28931
  }
28703
28932
  getVersionRange() {
28933
+ if (this.existsVersionedTx()) {
28934
+ return {
28935
+ model_mini: {
28936
+ min: '3.1.0',
28937
+ },
28938
+ model_touch: {
28939
+ min: '4.3.0',
28940
+ },
28941
+ };
28942
+ }
28704
28943
  return {
28705
28944
  classic: {
28706
28945
  min: '2.1.9',
@@ -28710,6 +28949,28 @@ class SolSignTransaction extends BaseMethod {
28710
28949
  },
28711
28950
  };
28712
28951
  }
28952
+ isVersionedTx(hexString) {
28953
+ if (hexString.length === 0)
28954
+ return false;
28955
+ try {
28956
+ const cleanHexString = hexString.startsWith('0x') ? hexString.slice(2) : hexString;
28957
+ const binary = parseInt(cleanHexString[0], 16).toString(2);
28958
+ return binary[0] === '1';
28959
+ }
28960
+ catch (_a) {
28961
+ return false;
28962
+ }
28963
+ }
28964
+ existsVersionedTx() {
28965
+ for (let i = 0; i < this.params.length; i++) {
28966
+ const param = this.params[i];
28967
+ const { raw_tx } = param;
28968
+ if (this.isVersionedTx(raw_tx)) {
28969
+ return true;
28970
+ }
28971
+ }
28972
+ return false;
28973
+ }
28713
28974
  run() {
28714
28975
  return __awaiter(this, void 0, void 0, function* () {
28715
28976
  const responses = [];
@@ -30012,7 +30273,7 @@ class SuiSignMessage extends BaseMethod {
30012
30273
  class SuiSignTransaction extends BaseMethod {
30013
30274
  constructor() {
30014
30275
  super(...arguments);
30015
- this.chunkSize = 1024;
30276
+ this.chunkByteSize = 1024;
30016
30277
  this.processTxRequest = (typedCall, res, data, offset = 0) => __awaiter(this, void 0, void 0, function* () {
30017
30278
  if (res.type === 'SuiSignedTx') {
30018
30279
  return res.message;
@@ -30076,12 +30337,12 @@ class SuiSignTransaction extends BaseMethod {
30076
30337
  let offset = 0;
30077
30338
  let data = '';
30078
30339
  if (this.supportChunkTransfer()) {
30079
- offset = this.chunkSize;
30340
+ offset = this.chunkByteSize * 2;
30080
30341
  data = this.params.raw_tx;
30081
30342
  this.params = {
30082
30343
  address_n: this.params.address_n,
30083
30344
  raw_tx: '',
30084
- data_initial_chunk: this.params.raw_tx.slice(0, this.chunkSize * 2),
30345
+ data_initial_chunk: this.params.raw_tx.slice(0, this.chunkByteSize * 2),
30085
30346
  data_length: dataLength,
30086
30347
  };
30087
30348
  }
@@ -32111,6 +32372,141 @@ class LnurlAuth1 extends BaseMethod {
32111
32372
  }
32112
32373
  }
32113
32374
 
32375
+ class NervosGetAddress extends BaseMethod {
32376
+ constructor() {
32377
+ super(...arguments);
32378
+ this.hasBundle = false;
32379
+ }
32380
+ init() {
32381
+ var _a;
32382
+ this.checkDeviceId = true;
32383
+ this.notAllowDeviceMode = [...this.notAllowDeviceMode, UI_REQUEST.INITIALIZE];
32384
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
32385
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
32386
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
32387
+ this.params = [];
32388
+ payload.bundle.forEach((batch) => {
32389
+ var _a;
32390
+ const addressN = validatePath(batch.path, 3);
32391
+ validateParams(batch, [
32392
+ { name: 'path', required: true },
32393
+ { name: 'showOnOneKey', type: 'boolean' },
32394
+ { name: 'network', type: 'string' },
32395
+ ]);
32396
+ const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
32397
+ this.params.push({
32398
+ address_n: addressN,
32399
+ show_display: showOnOneKey,
32400
+ network: batch.network,
32401
+ });
32402
+ });
32403
+ }
32404
+ getVersionRange() {
32405
+ return {
32406
+ model_mini: {
32407
+ min: '3.2.0',
32408
+ },
32409
+ model_touch: {
32410
+ min: '4.4.0',
32411
+ },
32412
+ };
32413
+ }
32414
+ run() {
32415
+ return __awaiter(this, void 0, void 0, function* () {
32416
+ const responses = [];
32417
+ for (let i = 0; i < this.params.length; i++) {
32418
+ const param = this.params[i];
32419
+ const res = yield this.device.commands.typedCall('NervosGetAddress', 'NervosAddress', Object.assign({}, param));
32420
+ const { address } = res.message;
32421
+ const result = {
32422
+ path: serializedPath(param.address_n),
32423
+ address,
32424
+ };
32425
+ responses.push(result);
32426
+ this.postPreviousAddressMessage(result);
32427
+ }
32428
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
32429
+ });
32430
+ }
32431
+ }
32432
+
32433
+ class NervosSignTransaction extends BaseMethod {
32434
+ constructor() {
32435
+ super(...arguments);
32436
+ this.hasBundle = false;
32437
+ this.chunkByteSize = 1024;
32438
+ this.processTxRequest = (typedCall, res, data, offset = 0) => __awaiter(this, void 0, void 0, function* () {
32439
+ if (res.type === 'NervosSignedTx') {
32440
+ return {
32441
+ path: serializedPath(this.params.address_n),
32442
+ signature: res.message.signature,
32443
+ };
32444
+ }
32445
+ const { data_length } = res.message;
32446
+ if (!data_length) {
32447
+ return {
32448
+ path: serializedPath(this.params.address_n),
32449
+ signature: res.message.signature,
32450
+ };
32451
+ }
32452
+ const payload = data.slice(offset, offset + data_length * 2);
32453
+ const newOffset = offset + payload.length;
32454
+ const resourceAckParams = {
32455
+ data_chunk: payload,
32456
+ };
32457
+ const response = yield typedCall('NervosTxAck', ['NervosSignedTx', 'NervosTxRequest'], Object.assign({}, resourceAckParams));
32458
+ return this.processTxRequest(typedCall, response, data, newOffset);
32459
+ });
32460
+ }
32461
+ init() {
32462
+ this.checkDeviceId = true;
32463
+ this.notAllowDeviceMode = [...this.notAllowDeviceMode];
32464
+ validateParams(this.payload, [
32465
+ { name: 'path', required: true },
32466
+ { name: 'rawTx', type: 'hexString', required: true },
32467
+ { name: 'witnessHex', type: 'hexString', required: true },
32468
+ { name: 'network', type: 'string', required: true },
32469
+ ]);
32470
+ const { path, rawTx, witnessHex, network } = this.payload;
32471
+ const addressN = validatePath(path, 3);
32472
+ this.params = {
32473
+ address_n: addressN,
32474
+ raw_tx: formatAnyHex(rawTx),
32475
+ witness_buffer: formatAnyHex(witnessHex),
32476
+ network,
32477
+ };
32478
+ }
32479
+ getVersionRange() {
32480
+ return {
32481
+ model_mini: {
32482
+ min: '2.10.0',
32483
+ },
32484
+ model_touch: {
32485
+ min: '4.0.0',
32486
+ },
32487
+ };
32488
+ }
32489
+ min(a, b) {
32490
+ return a < b ? a : b;
32491
+ }
32492
+ run() {
32493
+ return __awaiter(this, void 0, void 0, function* () {
32494
+ const dataLength = this.params.raw_tx.length / 2;
32495
+ const offset = this.min(this.params.raw_tx.length, this.chunkByteSize * 2);
32496
+ const data = this.params.raw_tx;
32497
+ const res = yield this.device.commands.typedCall('NervosSignTx', 'NervosSignedTx', {
32498
+ address_n: this.params.address_n,
32499
+ data_initial_chunk: this.params.raw_tx.slice(0, offset),
32500
+ data_length: dataLength,
32501
+ witness_buffer: this.params.witness_buffer,
32502
+ network: this.params.network,
32503
+ });
32504
+ const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
32505
+ return this.processTxRequest(typedCall, res, data, offset);
32506
+ });
32507
+ }
32508
+ }
32509
+
32114
32510
  var ApiMethods = /*#__PURE__*/Object.freeze({
32115
32511
  __proto__: null,
32116
32512
  searchDevices: SearchDevices,
@@ -32206,7 +32602,9 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
32206
32602
  nostrEncryptMessage: NostrEncryptMessage,
32207
32603
  nostrDecryptMessage: NostrDecryptMessage,
32208
32604
  nostrSignSchnorr: NostrSignSchnorr,
32209
- lnurlAuth: LnurlAuth1
32605
+ lnurlAuth: LnurlAuth1,
32606
+ nervosGetAddress: NervosGetAddress,
32607
+ nervosSignTransaction: NervosSignTransaction
32210
32608
  });
32211
32609
 
32212
32610
  function findMethod(message) {