@onekeyfe/hd-core 0.2.7 → 0.2.9

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 (93) hide show
  1. package/dist/api/BaseMethod.d.ts.map +1 -1
  2. package/dist/api/cardano/CardanoGetAddress.d.ts +8 -0
  3. package/dist/api/cardano/CardanoGetAddress.d.ts.map +1 -0
  4. package/dist/api/cardano/CardanoGetPublicKey.d.ts +8 -0
  5. package/dist/api/cardano/CardanoGetPublicKey.d.ts.map +1 -0
  6. package/dist/api/cardano/CardanoSignTransaction.d.ts +9 -0
  7. package/dist/api/cardano/CardanoSignTransaction.d.ts.map +1 -0
  8. package/dist/api/cardano/helper/addressParameters.d.ts +7 -0
  9. package/dist/api/cardano/helper/addressParameters.d.ts.map +1 -0
  10. package/dist/api/cardano/helper/auxiliaryData.d.ts +5 -0
  11. package/dist/api/cardano/helper/auxiliaryData.d.ts.map +1 -0
  12. package/dist/api/cardano/helper/cardanoInputs.d.ts +14 -0
  13. package/dist/api/cardano/helper/cardanoInputs.d.ts.map +1 -0
  14. package/dist/api/cardano/helper/cardanoOutputs.d.ts +11 -0
  15. package/dist/api/cardano/helper/cardanoOutputs.d.ts.map +1 -0
  16. package/dist/api/cardano/helper/certificate.d.ts +9 -0
  17. package/dist/api/cardano/helper/certificate.d.ts.map +1 -0
  18. package/dist/api/cardano/helper/token.d.ts +3 -0
  19. package/dist/api/cardano/helper/token.d.ts.map +1 -0
  20. package/dist/api/cardano/helper/utils.d.ts +3 -0
  21. package/dist/api/cardano/helper/utils.d.ts.map +1 -0
  22. package/dist/api/cardano/helper/witnesses.d.ts +5 -0
  23. package/dist/api/cardano/helper/witnesses.d.ts.map +1 -0
  24. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  25. package/dist/api/helpers/paramsValidator.d.ts +2 -1
  26. package/dist/api/helpers/paramsValidator.d.ts.map +1 -1
  27. package/dist/api/index.d.ts +6 -0
  28. package/dist/api/index.d.ts.map +1 -1
  29. package/dist/api/sui/SuiGetAddress.d.ts +18 -0
  30. package/dist/api/sui/SuiGetAddress.d.ts.map +1 -0
  31. package/dist/api/sui/SuiGetPublicKey.d.ts +21 -0
  32. package/dist/api/sui/SuiGetPublicKey.d.ts.map +1 -0
  33. package/dist/api/sui/SuiSignTransaction.d.ts +15 -0
  34. package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -0
  35. package/dist/core/index.d.ts.map +1 -1
  36. package/dist/device/Device.d.ts +1 -0
  37. package/dist/device/Device.d.ts.map +1 -1
  38. package/dist/index.d.ts +233 -3
  39. package/dist/index.js +1203 -97
  40. package/dist/inject.d.ts.map +1 -1
  41. package/dist/types/api/cardano.d.ts +158 -0
  42. package/dist/types/api/cardano.d.ts.map +1 -0
  43. package/dist/types/api/cardanoGetAddress.d.ts +33 -0
  44. package/dist/types/api/cardanoGetAddress.d.ts.map +1 -0
  45. package/dist/types/api/cardanoGetPublicKey.d.ts +23 -0
  46. package/dist/types/api/cardanoGetPublicKey.d.ts.map +1 -0
  47. package/dist/types/api/cardanoSignTransaction.d.ts +4 -0
  48. package/dist/types/api/cardanoSignTransaction.d.ts.map +1 -0
  49. package/dist/types/api/export.d.ts +3 -0
  50. package/dist/types/api/export.d.ts.map +1 -1
  51. package/dist/types/api/index.d.ts +12 -0
  52. package/dist/types/api/index.d.ts.map +1 -1
  53. package/dist/types/api/suiGetAddress.d.ts +15 -0
  54. package/dist/types/api/suiGetAddress.d.ts.map +1 -0
  55. package/dist/types/api/suiGetPublicKey.d.ts +14 -0
  56. package/dist/types/api/suiGetPublicKey.d.ts.map +1 -0
  57. package/dist/types/api/suiSignTransaction.d.ts +11 -0
  58. package/dist/types/api/suiSignTransaction.d.ts.map +1 -0
  59. package/dist/utils/patch.d.ts +1 -1
  60. package/dist/utils/patch.d.ts.map +1 -1
  61. package/package.json +4 -4
  62. package/src/api/BaseMethod.ts +7 -1
  63. package/src/api/btc/helpers/signtxLegacy.ts +1 -1
  64. package/src/api/cardano/CardanoGetAddress.ts +87 -0
  65. package/src/api/cardano/CardanoGetPublicKey.ts +55 -0
  66. package/src/api/cardano/CardanoSignTransaction.ts +309 -0
  67. package/src/api/cardano/helper/addressParameters.ts +118 -0
  68. package/src/api/cardano/helper/auxiliaryData.ts +74 -0
  69. package/src/api/cardano/helper/cardanoInputs.ts +56 -0
  70. package/src/api/cardano/helper/cardanoOutputs.ts +89 -0
  71. package/src/api/cardano/helper/certificate.ts +199 -0
  72. package/src/api/cardano/helper/token.ts +43 -0
  73. package/src/api/cardano/helper/utils.ts +17 -0
  74. package/src/api/cardano/helper/witnesses.ts +63 -0
  75. package/src/api/firmware/uploadFirmware.ts +1 -3
  76. package/src/api/helpers/paramsValidator.ts +19 -1
  77. package/src/api/index.ts +8 -0
  78. package/src/api/sui/SuiGetAddress.ts +97 -0
  79. package/src/api/sui/SuiGetPublicKey.ts +63 -0
  80. package/src/api/sui/SuiSignTransaction.ts +48 -0
  81. package/src/core/index.ts +1 -0
  82. package/src/data/messages/messages.json +217 -69
  83. package/src/device/Device.ts +5 -0
  84. package/src/inject.ts +14 -0
  85. package/src/types/api/cardano.ts +186 -0
  86. package/src/types/api/cardanoGetAddress.ts +47 -0
  87. package/src/types/api/cardanoGetPublicKey.ts +33 -0
  88. package/src/types/api/cardanoSignTransaction.ts +8 -0
  89. package/src/types/api/export.ts +4 -0
  90. package/src/types/api/index.ts +22 -0
  91. package/src/types/api/suiGetAddress.ts +24 -0
  92. package/src/types/api/suiGetPublicKey.ts +23 -0
  93. package/src/types/api/suiSignTransaction.ts +17 -0
package/dist/index.js CHANGED
@@ -105,6 +105,12 @@ const inject = ({ call, cancel, dispose, eventEmitter, init, uiResponse, }) => {
105
105
  cosmosSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'cosmosSignTransaction' })),
106
106
  xrpGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'xrpGetAddress' })),
107
107
  xrpSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'xrpSignTransaction' })),
108
+ suiGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'suiGetAddress' })),
109
+ suiGetPublicKey: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'suiGetPublicKey' })),
110
+ suiSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'suiSignTransaction' })),
111
+ cardanoGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'cardanoGetAddress' })),
112
+ cardanoGetPublicKey: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'cardanoGetPublicKey' })),
113
+ cardanoSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'cardanoSignTransaction' })),
108
114
  };
109
115
  return api;
110
116
  };
@@ -2830,6 +2836,45 @@ var nested = {
2830
2836
  rule: "required",
2831
2837
  type: "CardanoDerivationType",
2832
2838
  id: 14
2839
+ },
2840
+ include_network_id: {
2841
+ type: "bool",
2842
+ id: 15,
2843
+ options: {
2844
+ "default": false
2845
+ }
2846
+ },
2847
+ script_data_hash: {
2848
+ type: "bytes",
2849
+ id: 16
2850
+ },
2851
+ collateral_inputs_count: {
2852
+ rule: "required",
2853
+ type: "uint32",
2854
+ id: 17
2855
+ },
2856
+ required_signers_count: {
2857
+ rule: "required",
2858
+ type: "uint32",
2859
+ id: 18
2860
+ },
2861
+ has_collateral_return: {
2862
+ type: "bool",
2863
+ id: 19,
2864
+ options: {
2865
+ "default": false
2866
+ }
2867
+ },
2868
+ total_collateral: {
2869
+ type: "uint64",
2870
+ id: 20
2871
+ },
2872
+ reference_inputs_count: {
2873
+ type: "uint32",
2874
+ id: 21,
2875
+ options: {
2876
+ "default": 0
2877
+ }
2833
2878
  }
2834
2879
  }
2835
2880
  },
@@ -6488,6 +6533,53 @@ var nested = {
6488
6533
  fields: {
6489
6534
  }
6490
6535
  },
6536
+ RebootToBoardloader: {
6537
+ fields: {
6538
+ }
6539
+ },
6540
+ ListResDir: {
6541
+ fields: {
6542
+ path: {
6543
+ rule: "required",
6544
+ type: "string",
6545
+ id: 1
6546
+ }
6547
+ }
6548
+ },
6549
+ FileInfoList: {
6550
+ fields: {
6551
+ files: {
6552
+ rule: "repeated",
6553
+ type: "FileInfo",
6554
+ id: 1
6555
+ }
6556
+ },
6557
+ nested: {
6558
+ FileInfo: {
6559
+ fields: {
6560
+ name: {
6561
+ rule: "required",
6562
+ type: "string",
6563
+ id: 1
6564
+ },
6565
+ size: {
6566
+ rule: "required",
6567
+ type: "uint64",
6568
+ id: 2
6569
+ }
6570
+ }
6571
+ }
6572
+ }
6573
+ },
6574
+ DeviceEraseSector: {
6575
+ fields: {
6576
+ sector: {
6577
+ rule: "required",
6578
+ type: "uint32",
6579
+ id: 1
6580
+ }
6581
+ }
6582
+ },
6491
6583
  MoneroTransactionSourceEntry: {
6492
6584
  fields: {
6493
6585
  outputs: {
@@ -8631,6 +8723,61 @@ var nested = {
8631
8723
  }
8632
8724
  }
8633
8725
  },
8726
+ SuiGetAddress: {
8727
+ fields: {
8728
+ address_n: {
8729
+ rule: "repeated",
8730
+ type: "uint32",
8731
+ id: 1,
8732
+ options: {
8733
+ packed: false
8734
+ }
8735
+ },
8736
+ show_display: {
8737
+ type: "bool",
8738
+ id: 2
8739
+ }
8740
+ }
8741
+ },
8742
+ SuiAddress: {
8743
+ fields: {
8744
+ address: {
8745
+ type: "string",
8746
+ id: 1
8747
+ }
8748
+ }
8749
+ },
8750
+ SuiSignTx: {
8751
+ fields: {
8752
+ address_n: {
8753
+ rule: "repeated",
8754
+ type: "uint32",
8755
+ id: 1,
8756
+ options: {
8757
+ packed: false
8758
+ }
8759
+ },
8760
+ raw_tx: {
8761
+ rule: "required",
8762
+ type: "bytes",
8763
+ id: 2
8764
+ }
8765
+ }
8766
+ },
8767
+ SuiSignedTx: {
8768
+ fields: {
8769
+ public_key: {
8770
+ rule: "required",
8771
+ type: "bytes",
8772
+ id: 1
8773
+ },
8774
+ signature: {
8775
+ rule: "required",
8776
+ type: "bytes",
8777
+ id: 2
8778
+ }
8779
+ }
8780
+ },
8634
8781
  TezosGetAddress: {
8635
8782
  fields: {
8636
8783
  address_n: {
@@ -9629,6 +9776,10 @@ var nested = {
9629
9776
  MessageType_AlgorandAddress: 10901,
9630
9777
  MessageType_AlgorandSignTx: 10902,
9631
9778
  MessageType_AlgorandSignedTx: 10903,
9779
+ MessageType_SuiGetAddress: 11100,
9780
+ MessageType_SuiAddress: 11101,
9781
+ MessageType_SuiSignTx: 11102,
9782
+ MessageType_SuiSignedTx: 11103,
9632
9783
  MessageType_DeviceBackToBoot: 903,
9633
9784
  MessageType_DeviceInfoSettings: 10001,
9634
9785
  MessageType_GetDeviceInfo: 10002,
@@ -9649,7 +9800,11 @@ var nested = {
9649
9800
  MessageType_ZoomRequest: 10019,
9650
9801
  MessageType_ResourceRequest: 10020,
9651
9802
  MessageType_ResourceAck: 10021,
9652
- MessageType_ResourceUpdate: 10022
9803
+ MessageType_ResourceUpdate: 10022,
9804
+ MessageType_ListResDir: 10023,
9805
+ MessageType_FileInfoList: 10024,
9806
+ MessageType_RebootToBoardloader: 10025,
9807
+ MessageType_DeviceEraseSector: 10026
9653
9808
  }
9654
9809
  },
9655
9810
  google: {
@@ -11726,6 +11881,9 @@ class Device extends events.exports {
11726
11881
  if (internalState) {
11727
11882
  payload.session_id = internalState;
11728
11883
  }
11884
+ if (options === null || options === void 0 ? void 0 : options.deriveCardano) {
11885
+ payload.derive_cardano = true;
11886
+ }
11729
11887
  Log$5.debug('initialize payload:', payload);
11730
11888
  const { message } = yield this.commands.typedCall('Initialize', 'Features', payload);
11731
11889
  this._updateFeatures(message, options === null || options === void 0 ? void 0 : options.initSession);
@@ -12022,8 +12180,10 @@ class BaseMethod {
12022
12180
  if (!this.device || !this.device.features)
12023
12181
  return;
12024
12182
  const inputPinOnSoftware = supportInputPinOnSoftware(this.device.features);
12183
+ const modifyHomescreen = supportModifyHomescreen(this.device.features);
12025
12184
  this.postMessage(createDeviceMessage(DEVICE.SUPPORT_FEATURES, {
12026
12185
  inputPinOnSoftware,
12186
+ modifyHomescreen,
12027
12187
  device: this.device.toMessageObject(),
12028
12188
  }));
12029
12189
  }
@@ -12290,6 +12450,15 @@ const validateParams = (values, fields) => {
12290
12450
  throw invalidParameter(`Parameter "${field.name}" is empty.`);
12291
12451
  }
12292
12452
  break;
12453
+ case 'uint':
12454
+ if (typeof value !== 'string' && typeof value !== 'number') {
12455
+ throw invalidParameter(`Parameter [${field.name}] has invalid type. "string|number" expected.`);
12456
+ }
12457
+ if ((typeof value === 'number' && !Number.isSafeInteger(value)) ||
12458
+ !/^(?:[1-9]\d*|\d)$/.test(value.toString().replace(/^-/, field.allowNegative ? '' : '-'))) {
12459
+ throw invalidParameter(`Parameter [${field.name}] has invalid value "${value}". Integer representation expected.`);
12460
+ }
12461
+ break;
12293
12462
  case 'bigNumber':
12294
12463
  if (typeof value !== 'string') {
12295
12464
  throw invalidParameter(`Parameter [${field.name}] is of type invalid and should be [string].`);
@@ -12678,7 +12847,6 @@ const getInfo = ({ features, updateType }) => {
12678
12847
  return findLatestRelease(releaseInfo);
12679
12848
  };
12680
12849
 
12681
- getLogger(exports.LoggerNames.Device);
12682
12850
  const postConfirmationMessage = (device) => {
12683
12851
  var _a;
12684
12852
  if ((_a = device.features) === null || _a === void 0 ? void 0 : _a.firmware_present) {
@@ -13735,7 +13903,7 @@ const saveTxSignatures = (serializedTx, signatures, txRequest) => {
13735
13903
  }
13736
13904
  if (typeof signature_index === 'number') {
13737
13905
  if (!signature) {
13738
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'saveTxSignatures: Unexpected null in trezor:TxRequestSerialized signature.');
13906
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'saveTxSignatures: Unexpected null in oneKey:TxRequestSerialized signature.');
13739
13907
  }
13740
13908
  signatures[signature_index] = signature;
13741
13909
  }
@@ -16170,104 +16338,1041 @@ class XrpGetAddress extends BaseMethod {
16170
16338
  }
16171
16339
  }
16172
16340
 
16173
- var ApiMethods = /*#__PURE__*/Object.freeze({
16174
- __proto__: null,
16175
- searchDevices: SearchDevices,
16176
- getFeatures: GetFeatures,
16177
- getPassphraseState: GetPassphraseState,
16178
- getLogs: CheckBridgeStatus$1,
16179
- checkFirmwareRelease: CheckFirmwareRelease,
16180
- checkBLEFirmwareRelease: CheckBLEFirmwareRelease,
16181
- checkTransportRelease: CheckTransportRelease,
16182
- checkBridgeStatus: CheckBridgeStatus,
16183
- deviceBackup: DeviceBackup,
16184
- deviceChangePin: DeviceChangePin,
16185
- deviceFlags: DeviceFlags,
16186
- deviceRebootToBootloader: DeviceRebootToBootloader,
16187
- deviceRecovery: DeviceRecovery,
16188
- deviceReset: DeviceReset,
16189
- deviceSettings: DeviceSettings,
16190
- deviceUpdateReboot: DeviceUpdateReboot,
16191
- deviceUploadResource: DeviceUploadResource,
16192
- deviceSupportFeatures: DeviceSupportFeatures,
16193
- deviceVerify: DeviceVerify,
16194
- deviceWipe: DeviceWipe,
16195
- deviceFullyUploadResource: DeviceFullyUploadResource,
16196
- firmwareUpdate: FirmwareUpdate$1,
16197
- firmwareUpdateV2: FirmwareUpdate,
16198
- requestWebUsbDevice: RequestWebUsbDevice,
16199
- cipherKeyValue: CipherKeyValue,
16200
- btcGetAddress: BTCGetAddress,
16201
- btcGetPublicKey: BTCGetPublicKey,
16202
- btcSignMessage: BTCSignMessage,
16203
- btcSignTransaction: BTCSignTransaction,
16204
- btcVerifyMessage: BTCVerifyMessage,
16205
- confluxGetAddress: ConfluxGetAddress,
16206
- confluxSignMessage: ConfluxSignMessage,
16207
- confluxSignMessageCIP23: ConfluxSignMessageCIP23,
16208
- confluxSignTransaction: ConfluxSignTransaction,
16209
- evmGetAddress: EvmGetAddress,
16210
- evmGetPublicKey: EVMGetPublicKey,
16211
- evmSignMessage: EVMSignMessage$2,
16212
- evmSignMessageEIP712: EVMSignMessageEIP712,
16213
- evmSignTransaction: EVMSignTransaction,
16214
- evmSignTypedData: EVMSignTypedData,
16215
- evmVerifyMessage: EVMSignMessage$1,
16216
- starcoinGetAddress: StarcoinGetAddress,
16217
- starcoinGetPublicKey: StarcoinGetPublicKey,
16218
- starcoinSignMessage: StarcoinSignMessage,
16219
- starcoinSignTransaction: StarcoinSignTransaction,
16220
- starcoinVerifyMessage: EVMSignMessage,
16221
- nemGetAddress: NEMGetAddress,
16222
- nemSignTransaction: NEMSignTransaction,
16223
- solGetAddress: SolGetAddress,
16224
- solSignTransaction: SolSignTransaction,
16225
- stellarGetAddress: StellarGetAddress,
16226
- stellarSignTransaction: StellarSignTransaction,
16227
- tronGetAddress: TronGetAddress,
16228
- tronSignMessage: TronSignMessage,
16229
- tronSignTransaction: TronSignTransaction,
16230
- nearGetAddress: NearGetAddress,
16231
- nearSignTransaction: NearSignTransaction,
16232
- aptosGetAddress: AptosGetAddress,
16233
- aptosGetPublicKey: AptosGetPublicKey,
16234
- aptosSignTransaction: AptosSignTransaction,
16235
- aptosSignMessage: AptosSignMessage,
16236
- algoGetAddress: AlgoGetAddress,
16237
- algoSignTransaction: AlgoSignTransaction,
16238
- cosmosGetAddress: CosmosGetAddress,
16239
- cosmosGetPublicKey: CosmosGetPublicKey,
16240
- cosmosSignTransaction: CosmosSignTransaction,
16241
- xrpGetAddress: XrpGetAddress$1,
16242
- xrpSignTransaction: XrpGetAddress
16243
- });
16244
-
16245
- function findMethod(message) {
16246
- const { method } = message.payload;
16247
- if (typeof method !== 'string') {
16248
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Method is not set');
16249
- }
16250
- const MethodConstructor = ApiMethods[method];
16251
- if (MethodConstructor) {
16252
- return new MethodConstructor(message);
16253
- }
16254
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Method ${method} is not set`);
16255
- }
16256
-
16257
- const safeThrowError = (error) => {
16258
- if (error instanceof hdShared.HardwareError) {
16259
- throw error;
16341
+ class SuiGetAddress extends BaseMethod {
16342
+ constructor() {
16343
+ super(...arguments);
16344
+ this.hasBundle = false;
16260
16345
  }
16261
- else if (error.code === 'ERR_NETWORK') {
16262
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeNotInstalled);
16346
+ init() {
16347
+ var _a;
16348
+ this.checkDeviceId = true;
16349
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
16350
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
16351
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
16352
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
16353
+ this.params = [];
16354
+ payload.bundle.forEach((batch) => {
16355
+ var _a;
16356
+ const addressN = validatePath(batch.path, 3);
16357
+ validateParams(batch, [
16358
+ { name: 'path', required: true },
16359
+ { name: 'showOnOneKey', type: 'boolean' },
16360
+ ]);
16361
+ const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
16362
+ this.params.push({
16363
+ address_n: addressN,
16364
+ show_display: showOnOneKey,
16365
+ });
16366
+ });
16263
16367
  }
16264
- else if (error.code === 'ECONNABORTED') {
16265
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
16368
+ publicKeyToAddress(publicKey) {
16369
+ const hash = sha3.sha3_256.create();
16370
+ hash.update('\x00');
16371
+ hash.update(hexToBytes(publicKey));
16372
+ return `0x${utils.bytesToHex(hash.digest().slice(0, 20))}`;
16266
16373
  }
16267
- else {
16268
- throw hdShared.ERRORS.TypedError(error);
16374
+ getVersionRange() {
16375
+ return {
16376
+ model_mini: {
16377
+ min: '2.9.0',
16378
+ },
16379
+ model_touch: {
16380
+ min: '3.5.0',
16381
+ },
16382
+ };
16269
16383
  }
16270
- };
16384
+ run() {
16385
+ var _a;
16386
+ return __awaiter(this, void 0, void 0, function* () {
16387
+ if (this.hasBundle && supportBatchPublicKey((_a = this.device) === null || _a === void 0 ? void 0 : _a.features)) {
16388
+ const res = yield this.device.commands.typedCall('BatchGetPublickeys', 'EcdsaPublicKeys', {
16389
+ paths: this.params,
16390
+ ecdsa_curve_name: 'ed25519',
16391
+ });
16392
+ const result = res.message.public_keys.map((publicKey, index) => ({
16393
+ path: serializedPath(this.params[index].address_n),
16394
+ publicKey,
16395
+ address: this.publicKeyToAddress(publicKey),
16396
+ }));
16397
+ return Promise.resolve(result);
16398
+ }
16399
+ const responses = [];
16400
+ for (let i = 0; i < this.params.length; i++) {
16401
+ const param = this.params[i];
16402
+ const res = yield this.device.commands.typedCall('SuiGetAddress', 'SuiAddress', Object.assign({}, param));
16403
+ const { address } = res.message;
16404
+ responses.push({
16405
+ path: serializedPath(param.address_n),
16406
+ address: address === null || address === void 0 ? void 0 : address.toLowerCase(),
16407
+ });
16408
+ }
16409
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
16410
+ });
16411
+ }
16412
+ }
16413
+
16414
+ class SuiGetPublicKey extends BaseMethod {
16415
+ constructor() {
16416
+ super(...arguments);
16417
+ this.hasBundle = false;
16418
+ }
16419
+ init() {
16420
+ var _a;
16421
+ this.checkDeviceId = true;
16422
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
16423
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
16424
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
16425
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
16426
+ this.params = [];
16427
+ payload.bundle.forEach((batch) => {
16428
+ var _a;
16429
+ const addressN = validatePath(batch.path, 3);
16430
+ validateParams(batch, [
16431
+ { name: 'path', required: true },
16432
+ { name: 'showOnOneKey', type: 'boolean' },
16433
+ ]);
16434
+ const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
16435
+ this.params.push({
16436
+ address_n: addressN,
16437
+ show_display: showOnOneKey,
16438
+ });
16439
+ });
16440
+ }
16441
+ getVersionRange() {
16442
+ return {
16443
+ model_mini: {
16444
+ min: '2.9.0',
16445
+ },
16446
+ model_touch: {
16447
+ min: '3.5.0',
16448
+ },
16449
+ };
16450
+ }
16451
+ run() {
16452
+ return __awaiter(this, void 0, void 0, function* () {
16453
+ const res = yield this.device.commands.typedCall('BatchGetPublickeys', 'EcdsaPublicKeys', {
16454
+ paths: this.params,
16455
+ ecdsa_curve_name: 'ed25519',
16456
+ });
16457
+ const responses = res.message.public_keys.map((publicKey, index) => ({
16458
+ path: serializedPath(this.params[index].address_n),
16459
+ publicKey,
16460
+ }));
16461
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
16462
+ });
16463
+ }
16464
+ }
16465
+
16466
+ class SuiSignTransaction extends BaseMethod {
16467
+ init() {
16468
+ this.checkDeviceId = true;
16469
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
16470
+ validateParams(this.payload, [
16471
+ { name: 'path', required: true },
16472
+ { name: 'rawTx', type: 'hexString', required: true },
16473
+ ]);
16474
+ const { path, rawTx } = this.payload;
16475
+ const addressN = validatePath(path, 3);
16476
+ this.params = {
16477
+ address_n: addressN,
16478
+ raw_tx: formatAnyHex(rawTx),
16479
+ };
16480
+ }
16481
+ getVersionRange() {
16482
+ return {
16483
+ model_mini: {
16484
+ min: '2.9.0',
16485
+ },
16486
+ model_touch: {
16487
+ min: '3.5.0',
16488
+ },
16489
+ };
16490
+ }
16491
+ run() {
16492
+ return __awaiter(this, void 0, void 0, function* () {
16493
+ const res = yield this.device.commands.typedCall('SuiSignTx', 'SuiSignedTx', Object.assign({}, this.params));
16494
+ return Promise.resolve(res.message);
16495
+ });
16496
+ }
16497
+ }
16498
+
16499
+ const safeThrowError = (error) => {
16500
+ if (error instanceof hdShared.HardwareError) {
16501
+ throw error;
16502
+ }
16503
+ else if (error.code === 'ERR_NETWORK') {
16504
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeNotInstalled);
16505
+ }
16506
+ else if (error.code === 'ECONNABORTED') {
16507
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
16508
+ }
16509
+ else {
16510
+ throw hdShared.ERRORS.TypedError(error);
16511
+ }
16512
+ };
16513
+
16514
+ const validateAddressParameters = (addressParameters) => {
16515
+ validateParams(addressParameters, [
16516
+ { name: 'addressType', type: 'number', required: true },
16517
+ { name: 'stakingKeyHash', type: 'string' },
16518
+ { name: 'paymentScriptHash', type: 'string' },
16519
+ { name: 'stakingScriptHash', type: 'string' },
16520
+ ]);
16521
+ if (addressParameters.path) {
16522
+ validatePath(addressParameters.path);
16523
+ }
16524
+ if (addressParameters.stakingPath) {
16525
+ validatePath(addressParameters.stakingPath);
16526
+ }
16527
+ if (addressParameters.certificatePointer) {
16528
+ validateParams(addressParameters.certificatePointer, [
16529
+ { name: 'blockIndex', type: 'number', required: true },
16530
+ { name: 'txIndex', type: 'number', required: true },
16531
+ { name: 'certificateIndex', type: 'number', required: true },
16532
+ ]);
16533
+ }
16534
+ };
16535
+ const addressParametersToProto = (addressParameters) => {
16536
+ let path = [];
16537
+ if (addressParameters.path) {
16538
+ path = validatePath(addressParameters.path, 3);
16539
+ }
16540
+ let stakingPath = [];
16541
+ if (addressParameters.stakingPath) {
16542
+ stakingPath = validatePath(addressParameters.stakingPath, 3);
16543
+ }
16544
+ let certificatePointer;
16545
+ if (addressParameters.certificatePointer) {
16546
+ certificatePointer = {
16547
+ block_index: addressParameters.certificatePointer.blockIndex,
16548
+ tx_index: addressParameters.certificatePointer.txIndex,
16549
+ certificate_index: addressParameters.certificatePointer.certificateIndex,
16550
+ };
16551
+ }
16552
+ return {
16553
+ address_type: addressParameters.addressType,
16554
+ address_n: path,
16555
+ address_n_staking: stakingPath,
16556
+ staking_key_hash: addressParameters.stakingKeyHash,
16557
+ certificate_pointer: certificatePointer,
16558
+ script_payment_hash: addressParameters.paymentScriptHash,
16559
+ script_staking_hash: addressParameters.stakingScriptHash,
16560
+ };
16561
+ };
16562
+ const addressParametersFromProto = (addressParameters) => {
16563
+ let certificatePointer;
16564
+ if (addressParameters.certificate_pointer) {
16565
+ certificatePointer = {
16566
+ blockIndex: addressParameters.certificate_pointer.block_index,
16567
+ txIndex: addressParameters.certificate_pointer.tx_index,
16568
+ certificateIndex: addressParameters.certificate_pointer.certificate_index,
16569
+ };
16570
+ }
16571
+ return {
16572
+ addressType: addressParameters.address_type,
16573
+ path: addressParameters.address_n,
16574
+ stakingPath: addressParameters.address_n_staking,
16575
+ stakingKeyHash: addressParameters.staking_key_hash,
16576
+ certificatePointer,
16577
+ };
16578
+ };
16579
+ const modifyAddressParametersForBackwardsCompatibility = (address_parameters) => {
16580
+ if (address_parameters.address_type === hdTransport.Messages.CardanoAddressType.REWARD) {
16581
+ let { address_n, address_n_staking } = address_parameters;
16582
+ if (address_n.length > 0 && address_n_staking.length > 0) {
16583
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Only stakingPath is allowed for CardanoAddressType.REWARD`);
16584
+ }
16585
+ if (address_n.length > 0) {
16586
+ address_n_staking = address_n;
16587
+ address_n = [];
16588
+ }
16589
+ return Object.assign(Object.assign({}, address_parameters), { address_n,
16590
+ address_n_staking });
16591
+ }
16592
+ return address_parameters;
16593
+ };
16594
+
16595
+ class CardanoGetAddress extends BaseMethod {
16596
+ init() {
16597
+ var _a;
16598
+ this.checkDeviceId = true;
16599
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
16600
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
16601
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
16602
+ this.params = payload.bundle.map((batch) => {
16603
+ validateParams(batch, [
16604
+ { name: 'addressParameters', type: 'object', required: true },
16605
+ { name: 'networkId', type: 'number', required: true },
16606
+ { name: 'protocolMagic', type: 'number', required: true },
16607
+ { name: 'derivationType', type: 'number' },
16608
+ { name: 'address', type: 'string' },
16609
+ { name: 'showOnTrezor', type: 'boolean' },
16610
+ ]);
16611
+ validateAddressParameters(batch.addressParameters);
16612
+ return {
16613
+ address_parameters: addressParametersToProto(batch.addressParameters),
16614
+ address: batch.address,
16615
+ protocol_magic: batch.protocolMagic,
16616
+ network_id: batch.networkId,
16617
+ derivation_type: typeof batch.derivationType !== 'undefined'
16618
+ ? batch.derivationType
16619
+ : hdTransport.Messages.CardanoDerivationType.ICARUS_TREZOR,
16620
+ show_display: typeof batch.showOnOneKey === 'boolean' ? !!batch.showOneKey : true,
16621
+ };
16622
+ });
16623
+ }
16624
+ run() {
16625
+ return __awaiter(this, void 0, void 0, function* () {
16626
+ const responses = [];
16627
+ for (const batch of this.params) {
16628
+ const { address_parameters, protocol_magic, network_id, derivation_type, show_display } = batch;
16629
+ const response = yield this.device.commands.typedCall('CardanoGetAddress', 'CardanoAddress', {
16630
+ address_parameters,
16631
+ protocol_magic,
16632
+ network_id,
16633
+ derivation_type,
16634
+ show_display,
16635
+ });
16636
+ const publicKeyRes = yield this.device.commands.typedCall('CardanoGetPublicKey', 'CardanoPublicKey', {
16637
+ address_n: address_parameters.address_n.slice(0, 3),
16638
+ derivation_type,
16639
+ show_display,
16640
+ });
16641
+ responses.push({
16642
+ addressParameters: addressParametersFromProto(batch.address_parameters),
16643
+ protocolMagic: batch.protocol_magic,
16644
+ networkId: batch.network_id,
16645
+ serializedPath: serializedPath(batch.address_parameters.address_n),
16646
+ serializedStakingPath: serializedPath(batch.address_parameters.address_n_staking),
16647
+ address: response.message.address,
16648
+ xpub: publicKeyRes.message.xpub,
16649
+ });
16650
+ }
16651
+ return this.hasBundle ? responses : responses[0];
16652
+ });
16653
+ }
16654
+ }
16655
+
16656
+ class CardanoGetPublicKey extends BaseMethod {
16657
+ init() {
16658
+ var _a;
16659
+ this.checkDeviceId = true;
16660
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
16661
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
16662
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
16663
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
16664
+ this.params = payload.bundle.map((batch) => {
16665
+ validateParams(batch, [
16666
+ { name: 'path', required: true },
16667
+ { name: 'derivationType', type: 'number' },
16668
+ { name: 'showOnTrezor', type: 'boolean' },
16669
+ ]);
16670
+ const path = validatePath(batch.path, 3);
16671
+ return {
16672
+ address_n: path,
16673
+ derivation_type: typeof batch.derivationType !== 'undefined'
16674
+ ? batch.derivationType
16675
+ : hdTransport.Messages.CardanoDerivationType.ICARUS_TREZOR,
16676
+ show_display: typeof batch.showOnOneKey === 'boolean' ? batch.showOnOneKey : false,
16677
+ };
16678
+ });
16679
+ }
16680
+ run() {
16681
+ return __awaiter(this, void 0, void 0, function* () {
16682
+ const responses = [];
16683
+ const cmd = this.device.getCommands();
16684
+ for (let i = 0; i < this.params.length; i++) {
16685
+ const batch = this.params[i];
16686
+ const { message } = yield cmd.typedCall('CardanoGetPublicKey', 'CardanoPublicKey', batch);
16687
+ responses.push({
16688
+ path: batch.address_n,
16689
+ serializedPath: serializedPath(batch.address_n),
16690
+ publicKey: message.xpub,
16691
+ node: message.node,
16692
+ });
16693
+ }
16694
+ return this.hasBundle ? responses : responses[0];
16695
+ });
16696
+ }
16697
+ }
16698
+
16699
+ const transformInput = (input) => {
16700
+ validateParams(input, [
16701
+ { name: 'prev_hash', type: 'string', required: true },
16702
+ { name: 'prev_index', type: 'number', required: true },
16703
+ ]);
16704
+ return {
16705
+ input: {
16706
+ prev_hash: input.prev_hash,
16707
+ prev_index: input.prev_index,
16708
+ },
16709
+ path: input.path ? validatePath(input.path, 5) : undefined,
16710
+ };
16711
+ };
16712
+ const transformCollateralInput = (collateralInput) => {
16713
+ validateParams(collateralInput, [
16714
+ { name: 'prev_hash', type: 'string', required: true },
16715
+ { name: 'prev_index', type: 'number', required: true },
16716
+ ]);
16717
+ return {
16718
+ collateralInput: {
16719
+ prev_hash: collateralInput.prev_hash,
16720
+ prev_index: collateralInput.prev_index,
16721
+ },
16722
+ path: collateralInput.path ? validatePath(collateralInput.path, 5) : undefined,
16723
+ };
16724
+ };
16725
+ const transformReferenceInput = (referenceInput) => {
16726
+ validateParams(referenceInput, [
16727
+ { name: 'prev_hash', type: 'string', required: true },
16728
+ { name: 'prev_index', type: 'number', required: true },
16729
+ ]);
16730
+ return {
16731
+ prev_hash: referenceInput.prev_hash,
16732
+ prev_index: referenceInput.prev_index,
16733
+ };
16734
+ };
16735
+
16736
+ const validateTokens = (tokenAmounts) => {
16737
+ tokenAmounts.forEach(tokenAmount => {
16738
+ validateParams(tokenAmount, [
16739
+ { name: 'assetNameBytes', type: 'string', required: true },
16740
+ { name: 'amount', type: 'uint' },
16741
+ { name: 'mintAmount', type: 'uint', allowNegative: true },
16742
+ ]);
16743
+ });
16744
+ };
16745
+ const validateTokenBundle = (tokenBundle) => {
16746
+ tokenBundle.forEach(tokenGroup => {
16747
+ validateParams(tokenGroup, [
16748
+ { name: 'policyId', type: 'string', required: true },
16749
+ { name: 'tokenAmounts', type: 'array', required: true },
16750
+ ]);
16751
+ validateTokens(tokenGroup.tokenAmounts);
16752
+ });
16753
+ };
16754
+ const tokenBundleToProto = (tokenBundle) => {
16755
+ validateTokenBundle(tokenBundle);
16756
+ return tokenBundle.map(tokenGroup => ({
16757
+ policyId: tokenGroup.policyId,
16758
+ tokens: tokenAmountsToProto(tokenGroup.tokenAmounts),
16759
+ }));
16760
+ };
16761
+ const tokenAmountsToProto = (tokenAmounts) => tokenAmounts.map(tokenAmount => ({
16762
+ asset_name_bytes: tokenAmount.assetNameBytes,
16763
+ amount: tokenAmount.amount,
16764
+ mint_amount: tokenAmount.mintAmount,
16765
+ }));
16766
+
16767
+ const hexStringByteLength = (s) => s.length / 2;
16768
+ const sendChunkedHexString = (typedCall, data, chunkSize, messageType) => __awaiter(void 0, void 0, void 0, function* () {
16769
+ let processedSize = 0;
16770
+ while (processedSize < data.length) {
16771
+ const chunk = data.slice(processedSize, processedSize + chunkSize);
16772
+ yield typedCall(messageType, 'CardanoTxItemAck', {
16773
+ data: chunk,
16774
+ });
16775
+ processedSize += chunkSize;
16776
+ }
16777
+ });
16778
+
16779
+ const transformOutput = (output) => {
16780
+ validateParams(output, [
16781
+ { name: 'address', type: 'string' },
16782
+ { name: 'amount', type: 'uint', required: true },
16783
+ { name: 'tokenBundle', type: 'array', allowEmpty: true },
16784
+ { name: 'datumHash', type: 'string' },
16785
+ { name: 'format', type: 'number' },
16786
+ { name: 'inlineDatum', type: 'string' },
16787
+ { name: 'referenceScript', type: 'string' },
16788
+ ]);
16789
+ const result = {
16790
+ output: {
16791
+ amount: output.amount,
16792
+ asset_groups_count: 0,
16793
+ datum_hash: output.datumHash,
16794
+ format: output.format,
16795
+ inline_datum_size: output.inlineDatum ? hexStringByteLength(output.inlineDatum) : undefined,
16796
+ reference_script_size: output.referenceScript
16797
+ ? hexStringByteLength(output.referenceScript)
16798
+ : undefined,
16799
+ },
16800
+ inlineDatum: output.inlineDatum,
16801
+ referenceScript: output.referenceScript,
16802
+ };
16803
+ if (output.addressParameters) {
16804
+ validateAddressParameters(output.addressParameters);
16805
+ result.output.address_parameters = addressParametersToProto(output.addressParameters);
16806
+ }
16807
+ else {
16808
+ result.output.address = output.address;
16809
+ }
16810
+ if (output.tokenBundle) {
16811
+ result.tokenBundle = tokenBundleToProto(output.tokenBundle);
16812
+ result.output.asset_groups_count = result.tokenBundle.length;
16813
+ }
16814
+ else {
16815
+ result.output.asset_groups_count = 0;
16816
+ }
16817
+ return result;
16818
+ };
16819
+ const sendOutput = (typedCall, outputWithData) => __awaiter(void 0, void 0, void 0, function* () {
16820
+ const MAX_CHUNK_SIZE = 1024 * 2;
16821
+ const { output, tokenBundle, inlineDatum, referenceScript } = outputWithData;
16822
+ yield typedCall('CardanoTxOutput', 'CardanoTxItemAck', output);
16823
+ if (tokenBundle) {
16824
+ for (const assetGroup of tokenBundle) {
16825
+ yield typedCall('CardanoAssetGroup', 'CardanoTxItemAck', {
16826
+ policy_id: assetGroup.policyId,
16827
+ tokens_count: assetGroup.tokens.length,
16828
+ });
16829
+ for (const token of assetGroup.tokens) {
16830
+ yield typedCall('CardanoToken', 'CardanoTxItemAck', token);
16831
+ }
16832
+ }
16833
+ }
16834
+ if (inlineDatum) {
16835
+ yield sendChunkedHexString(typedCall, inlineDatum, MAX_CHUNK_SIZE, 'CardanoTxInlineDatumChunk');
16836
+ }
16837
+ if (referenceScript) {
16838
+ yield sendChunkedHexString(typedCall, referenceScript, MAX_CHUNK_SIZE, 'CardanoTxReferenceScriptChunk');
16839
+ }
16840
+ });
16841
+
16842
+ const ipv4AddressToHex = (ipv4Address) => Buffer.from(ipv4Address.split('.').map(ipPart => parseInt(ipPart, 10))).toString('hex');
16843
+ const ipv6AddressToHex = (ipv6Address) => ipv6Address.split(':').join('');
16844
+ const validatePoolMargin = (margin) => {
16845
+ validateParams(margin, [
16846
+ { name: 'numerator', type: 'string', required: true },
16847
+ { name: 'denominator', type: 'string', required: true },
16848
+ ]);
16849
+ };
16850
+ const validatePoolMetadata = (metadata) => {
16851
+ validateParams(metadata, [
16852
+ { name: 'url', type: 'string', required: true },
16853
+ { name: 'hash', type: 'string', required: true },
16854
+ ]);
16855
+ };
16856
+ const validatePoolRelay = (relay) => {
16857
+ validateParams(relay, [{ name: 'type', type: 'number', required: true }]);
16858
+ if (relay.type === hdTransport.Messages.CardanoPoolRelayType.SINGLE_HOST_IP) {
16859
+ const paramsToValidate = [
16860
+ { name: 'port', type: 'number', required: true },
16861
+ ];
16862
+ if (relay.ipv4Address) {
16863
+ paramsToValidate.push({ name: 'ipv4Address', type: 'string', required: false });
16864
+ }
16865
+ if (relay.ipv6Address) {
16866
+ paramsToValidate.push({ name: 'ipv6Address', type: 'string', required: false });
16867
+ }
16868
+ validateParams(relay, paramsToValidate);
16869
+ if (!relay.ipv4Address && !relay.ipv6Address) {
16870
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Either ipv4Address or ipv6Address must be supplied');
16871
+ }
16872
+ }
16873
+ else if (relay.type === hdTransport.Messages.CardanoPoolRelayType.SINGLE_HOST_NAME) {
16874
+ validateParams(relay, [
16875
+ { name: 'hostName', type: 'string', required: true },
16876
+ { name: 'port', type: 'number', required: true },
16877
+ ]);
16878
+ }
16879
+ else if (relay.type === hdTransport.Messages.CardanoPoolRelayType.MULTIPLE_HOST_NAME) {
16880
+ validateParams(relay, [{ name: 'hostName', type: 'string', required: true }]);
16881
+ }
16882
+ };
16883
+ const validatePoolOwners = (owners) => {
16884
+ owners.forEach(owner => {
16885
+ if (owner.stakingKeyHash) {
16886
+ validateParams(owner, [
16887
+ { name: 'stakingKeyHash', type: 'string', required: !owner.stakingKeyPath },
16888
+ ]);
16889
+ }
16890
+ if (owner.stakingKeyPath) {
16891
+ validatePath(owner.stakingKeyPath, 5);
16892
+ }
16893
+ if (!owner.stakingKeyHash && !owner.stakingKeyPath) {
16894
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Either stakingKeyHash or stakingKeyPath must be supplied');
16895
+ }
16896
+ });
16897
+ const ownersAsPathCount = owners.filter(owner => !!owner.stakingKeyPath).length;
16898
+ if (ownersAsPathCount !== 1) {
16899
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Exactly one pool owner must be given as a path');
16900
+ }
16901
+ };
16902
+ const validatePoolParameters = (poolParameters) => {
16903
+ validateParams(poolParameters, [
16904
+ { name: 'poolId', type: 'string', required: true },
16905
+ { name: 'vrfKeyHash', type: 'string', required: true },
16906
+ { name: 'pledge', type: 'string', required: true },
16907
+ { name: 'cost', type: 'string', required: true },
16908
+ { name: 'margin', type: 'object', required: true },
16909
+ { name: 'rewardAccount', type: 'string', required: true },
16910
+ { name: 'owners', type: 'array', required: true },
16911
+ { name: 'relays', type: 'array', required: true, allowEmpty: true },
16912
+ { name: 'metadata', type: 'object' },
16913
+ ]);
16914
+ validatePoolMargin(poolParameters.margin);
16915
+ validatePoolOwners(poolParameters.owners);
16916
+ poolParameters.relays.forEach(validatePoolRelay);
16917
+ if (poolParameters.metadata) {
16918
+ validatePoolMetadata(poolParameters.metadata);
16919
+ }
16920
+ };
16921
+ const transformPoolParameters = (poolParameters) => {
16922
+ if (!poolParameters) {
16923
+ return { poolParameters: undefined, poolOwners: [], poolRelays: [] };
16924
+ }
16925
+ validatePoolParameters(poolParameters);
16926
+ return {
16927
+ poolParameters: {
16928
+ pool_id: poolParameters.poolId,
16929
+ vrf_key_hash: poolParameters.vrfKeyHash,
16930
+ pledge: poolParameters.pledge,
16931
+ cost: poolParameters.cost,
16932
+ margin_numerator: poolParameters.margin.numerator,
16933
+ margin_denominator: poolParameters.margin.denominator,
16934
+ reward_account: poolParameters.rewardAccount,
16935
+ metadata: poolParameters.metadata,
16936
+ owners_count: poolParameters.owners.length,
16937
+ relays_count: poolParameters.relays.length,
16938
+ },
16939
+ poolOwners: poolParameters.owners.map(owner => ({
16940
+ staking_key_hash: owner.stakingKeyHash,
16941
+ staking_key_path: owner.stakingKeyPath ? validatePath(owner.stakingKeyPath, 5) : undefined,
16942
+ })),
16943
+ poolRelays: poolParameters.relays.map(relay => ({
16944
+ type: relay.type,
16945
+ ipv4_address: relay.ipv4Address ? ipv4AddressToHex(relay.ipv4Address) : undefined,
16946
+ ipv6_address: relay.ipv6Address ? ipv6AddressToHex(relay.ipv6Address) : undefined,
16947
+ host_name: relay.hostName,
16948
+ port: relay.port,
16949
+ })),
16950
+ };
16951
+ };
16952
+ const transformCertificate = (certificate) => {
16953
+ const paramsToValidate = [
16954
+ { name: 'type', type: 'number', required: true },
16955
+ ];
16956
+ if (certificate.type !== hdTransport.Messages.CardanoCertificateType.STAKE_POOL_REGISTRATION) {
16957
+ paramsToValidate.push({ name: 'scriptHash', type: 'string' });
16958
+ paramsToValidate.push({ name: 'keyHash', type: 'string' });
16959
+ }
16960
+ if (certificate.type === hdTransport.Messages.CardanoCertificateType.STAKE_DELEGATION) {
16961
+ paramsToValidate.push({ name: 'pool', type: 'string', required: true });
16962
+ }
16963
+ if (certificate.type === hdTransport.Messages.CardanoCertificateType.STAKE_POOL_REGISTRATION) {
16964
+ paramsToValidate.push({ name: 'poolParameters', type: 'object', required: true });
16965
+ }
16966
+ validateParams(certificate, paramsToValidate);
16967
+ const { poolParameters, poolOwners, poolRelays } = transformPoolParameters(certificate.poolParameters);
16968
+ return {
16969
+ certificate: {
16970
+ type: certificate.type,
16971
+ path: certificate.path ? validatePath(certificate.path, 5) : undefined,
16972
+ script_hash: certificate.scriptHash,
16973
+ key_hash: certificate.keyHash,
16974
+ pool: certificate.pool,
16975
+ pool_parameters: poolParameters,
16976
+ },
16977
+ poolOwners,
16978
+ poolRelays,
16979
+ };
16980
+ };
16981
+
16982
+ const transformCatalystRegistrationParameters = (catalystRegistrationParameters) => {
16983
+ validateParams(catalystRegistrationParameters, [
16984
+ { name: 'votingPublicKey', type: 'string', required: true },
16985
+ { name: 'stakingPath', required: true },
16986
+ { name: 'nonce', type: 'uint', required: true },
16987
+ ]);
16988
+ validateAddressParameters(catalystRegistrationParameters.rewardAddressParameters);
16989
+ return {
16990
+ voting_public_key: catalystRegistrationParameters.votingPublicKey,
16991
+ staking_path: validatePath(catalystRegistrationParameters.stakingPath, 3),
16992
+ reward_address_parameters: addressParametersToProto(catalystRegistrationParameters.rewardAddressParameters),
16993
+ nonce: catalystRegistrationParameters.nonce,
16994
+ };
16995
+ };
16996
+ const transformAuxiliaryData = (auxiliaryData) => {
16997
+ validateParams(auxiliaryData, [
16998
+ {
16999
+ name: 'hash',
17000
+ type: 'string',
17001
+ },
17002
+ ]);
17003
+ let catalystRegistrationParameters;
17004
+ if (auxiliaryData.catalystRegistrationParameters) {
17005
+ catalystRegistrationParameters = transformCatalystRegistrationParameters(auxiliaryData.catalystRegistrationParameters);
17006
+ }
17007
+ return {
17008
+ hash: auxiliaryData.hash,
17009
+ catalyst_registration_parameters: catalystRegistrationParameters,
17010
+ };
17011
+ };
17012
+ const modifyAuxiliaryDataForBackwardsCompatibility = (auxiliary_data) => {
17013
+ const { catalyst_registration_parameters } = auxiliary_data;
17014
+ if (catalyst_registration_parameters) {
17015
+ catalyst_registration_parameters.reward_address_parameters =
17016
+ modifyAddressParametersForBackwardsCompatibility(catalyst_registration_parameters.reward_address_parameters);
17017
+ return Object.assign(Object.assign({}, auxiliary_data), { catalyst_registration_parameters });
17018
+ }
17019
+ return auxiliary_data;
17020
+ };
17021
+
17022
+ const gatherWitnessPaths = (inputsWithPath, certificatesWithPoolOwnersAndRelays, withdrawals, collateralInputsWithPath, requiredSigners, additionalWitnessRequests, signingMode) => {
17023
+ const witnessPaths = new Map();
17024
+ function _insert(path) {
17025
+ const pathKey = JSON.stringify(path);
17026
+ witnessPaths.set(pathKey, path);
17027
+ }
17028
+ if (signingMode !== hdTransport.Messages.CardanoTxSigningMode.MULTISIG_TRANSACTION) {
17029
+ inputsWithPath.forEach(({ path }) => {
17030
+ if (path)
17031
+ _insert(path);
17032
+ });
17033
+ certificatesWithPoolOwnersAndRelays.forEach(({ certificate, poolOwners }) => {
17034
+ if (certificate.path &&
17035
+ (certificate.type === hdTransport.Messages.CardanoCertificateType.STAKE_DELEGATION ||
17036
+ certificate.type === hdTransport.Messages.CardanoCertificateType.STAKE_DEREGISTRATION)) {
17037
+ _insert(certificate.path);
17038
+ }
17039
+ poolOwners.forEach(poolOwner => {
17040
+ if (poolOwner.staking_key_path)
17041
+ _insert(poolOwner.staking_key_path);
17042
+ });
17043
+ });
17044
+ withdrawals.forEach(({ path }) => {
17045
+ if (path)
17046
+ _insert(path);
17047
+ });
17048
+ }
17049
+ if (signingMode === hdTransport.Messages.CardanoTxSigningMode.PLUTUS_TRANSACTION) {
17050
+ collateralInputsWithPath.forEach(({ path }) => {
17051
+ if (path)
17052
+ _insert(path);
17053
+ });
17054
+ }
17055
+ requiredSigners.forEach(({ key_path }) => {
17056
+ if (key_path)
17057
+ _insert(key_path);
17058
+ });
17059
+ additionalWitnessRequests.forEach(path => {
17060
+ _insert(path);
17061
+ });
17062
+ return Array.from(witnessPaths.values());
17063
+ };
17064
+
17065
+ class CardanoSignTransaction extends BaseMethod {
17066
+ init() {
17067
+ var _a;
17068
+ this.checkDeviceId = true;
17069
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
17070
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
17071
+ const { payload } = this;
17072
+ validateParams(payload, [
17073
+ { name: 'signingMode', type: 'number', required: true },
17074
+ { name: 'inputs', type: 'array', required: true },
17075
+ { name: 'outputs', type: 'array', required: true, allowEmpty: true },
17076
+ { name: 'fee', type: 'uint', required: true },
17077
+ { name: 'ttl', type: 'uint' },
17078
+ { name: 'certificates', type: 'array', allowEmpty: true },
17079
+ { name: 'withdrawals', type: 'array', allowEmpty: true },
17080
+ { name: 'mint', type: 'array', allowEmpty: true },
17081
+ { name: 'validityIntervalStart', type: 'uint' },
17082
+ { name: 'scriptDataHash', type: 'string' },
17083
+ { name: 'collateralInputs', type: 'array', allowEmpty: true },
17084
+ { name: 'requiredSigners', type: 'array', allowEmpty: true },
17085
+ { name: 'totalCollateral', type: 'uint' },
17086
+ { name: 'referenceInputs', type: 'array', allowEmpty: true },
17087
+ { name: 'protocolMagic', type: 'number', required: true },
17088
+ { name: 'networkId', type: 'number', required: true },
17089
+ { name: 'additionalWitnessRequests', type: 'array', allowEmpty: true },
17090
+ { name: 'derivationType', type: 'number' },
17091
+ { name: 'includeNetworkId', type: 'boolean' },
17092
+ ]);
17093
+ const inputsWithPath = payload.inputs.map(transformInput);
17094
+ const outputsWithData = payload.outputs.map(transformOutput);
17095
+ let certificatesWithPoolOwnersAndRelays = [];
17096
+ if (payload.certificates) {
17097
+ certificatesWithPoolOwnersAndRelays = payload.certificates.map(transformCertificate);
17098
+ }
17099
+ let withdrawals = [];
17100
+ if (payload.withdrawals) {
17101
+ withdrawals = payload.withdrawals.map((withdrawal) => {
17102
+ validateParams(withdrawal, [
17103
+ { name: 'amount', type: 'uint', required: true },
17104
+ { name: 'scriptHash', type: 'string' },
17105
+ { name: 'keyHash', type: 'string' },
17106
+ ]);
17107
+ return {
17108
+ path: withdrawal.path ? validatePath(withdrawal.path, 5) : undefined,
17109
+ amount: withdrawal.amount,
17110
+ script_hash: withdrawal.scriptHash,
17111
+ key_hash: withdrawal.keyHash,
17112
+ };
17113
+ });
17114
+ }
17115
+ let mint = [];
17116
+ if (payload.mint) {
17117
+ mint = tokenBundleToProto(payload.mint);
17118
+ }
17119
+ let auxiliaryData;
17120
+ if (payload.auxiliaryData) {
17121
+ auxiliaryData = transformAuxiliaryData(payload.auxiliaryData);
17122
+ }
17123
+ let additionalWitnessRequests = [];
17124
+ if (payload.additionalWitnessRequests) {
17125
+ additionalWitnessRequests = payload.additionalWitnessRequests.map((witnessRequest) => validatePath(witnessRequest, 3));
17126
+ }
17127
+ let collateralInputsWithPath = [];
17128
+ if (payload.collateralInputs) {
17129
+ collateralInputsWithPath = payload.collateralInputs.map(transformCollateralInput);
17130
+ }
17131
+ let requiredSigners = [];
17132
+ if (payload.requiredSigners) {
17133
+ requiredSigners = payload.requiredSigners.map((requiredSigner) => {
17134
+ validateParams(requiredSigner, [{ name: 'keyHash', type: 'string' }]);
17135
+ return {
17136
+ key_path: requiredSigner.keyPath ? validatePath(requiredSigner.keyPath, 3) : undefined,
17137
+ key_hash: requiredSigner.keyHash,
17138
+ };
17139
+ });
17140
+ }
17141
+ const collateralReturnWithData = payload.collateralReturn
17142
+ ? transformOutput(payload.collateralReturn)
17143
+ : undefined;
17144
+ let referenceInputs = [];
17145
+ if (payload.referenceInputs) {
17146
+ referenceInputs = payload.referenceInputs.map(transformReferenceInput);
17147
+ }
17148
+ this.params = {
17149
+ signingMode: payload.signingMode,
17150
+ inputsWithPath,
17151
+ outputsWithData,
17152
+ fee: payload.fee,
17153
+ ttl: payload.ttl,
17154
+ certificatesWithPoolOwnersAndRelays,
17155
+ withdrawals,
17156
+ mint,
17157
+ auxiliaryData,
17158
+ validityIntervalStart: payload.validityIntervalStart,
17159
+ scriptDataHash: payload.scriptDataHash,
17160
+ collateralInputsWithPath,
17161
+ requiredSigners,
17162
+ collateralReturnWithData,
17163
+ totalCollateral: payload.totalCollateral,
17164
+ referenceInputs,
17165
+ protocolMagic: payload.protocolMagic,
17166
+ networkId: payload.networkId,
17167
+ witnessPaths: gatherWitnessPaths(inputsWithPath, certificatesWithPoolOwnersAndRelays, withdrawals, collateralInputsWithPath, requiredSigners, additionalWitnessRequests, payload.signingMode),
17168
+ additionalWitnessRequests,
17169
+ derivationType: typeof payload.derivationType !== 'undefined'
17170
+ ? payload.derivationType
17171
+ : hdTransport.Messages.CardanoDerivationType.ICARUS_TREZOR,
17172
+ includeNetworkId: payload.includeNetworkId,
17173
+ };
17174
+ }
17175
+ signTx() {
17176
+ return __awaiter(this, void 0, void 0, function* () {
17177
+ const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
17178
+ const hasAuxiliaryData = !!this.params.auxiliaryData;
17179
+ const signTxInitMessage = {
17180
+ signing_mode: this.params.signingMode,
17181
+ protocol_magic: this.params.protocolMagic,
17182
+ network_id: this.params.networkId,
17183
+ inputs_count: this.params.inputsWithPath.length,
17184
+ outputs_count: this.params.outputsWithData.length,
17185
+ fee: this.params.fee,
17186
+ ttl: this.params.ttl,
17187
+ certificates_count: this.params.certificatesWithPoolOwnersAndRelays.length,
17188
+ withdrawals_count: this.params.withdrawals.length,
17189
+ has_auxiliary_data: hasAuxiliaryData,
17190
+ validity_interval_start: this.params.validityIntervalStart,
17191
+ witness_requests_count: this.params.witnessPaths.length,
17192
+ minting_asset_groups_count: this.params.mint.length,
17193
+ script_data_hash: this.params.scriptDataHash,
17194
+ collateral_inputs_count: this.params.collateralInputsWithPath.length,
17195
+ required_signers_count: this.params.requiredSigners.length,
17196
+ has_collateral_return: this.params.collateralReturnWithData != null,
17197
+ total_collateral: this.params.totalCollateral,
17198
+ reference_inputs_count: this.params.referenceInputs.length,
17199
+ derivation_type: this.params.derivationType,
17200
+ include_network_id: this.params.includeNetworkId,
17201
+ };
17202
+ yield typedCall('CardanoSignTxInit', 'CardanoTxItemAck', signTxInitMessage);
17203
+ for (const { input } of this.params.inputsWithPath) {
17204
+ yield typedCall('CardanoTxInput', 'CardanoTxItemAck', input);
17205
+ }
17206
+ for (const outputWithData of this.params.outputsWithData) {
17207
+ yield sendOutput(typedCall, outputWithData);
17208
+ }
17209
+ for (const { certificate, poolOwners, poolRelays } of this.params
17210
+ .certificatesWithPoolOwnersAndRelays) {
17211
+ yield typedCall('CardanoTxCertificate', 'CardanoTxItemAck', certificate);
17212
+ for (const poolOwner of poolOwners) {
17213
+ yield typedCall('CardanoPoolOwner', 'CardanoTxItemAck', poolOwner);
17214
+ }
17215
+ for (const poolRelay of poolRelays) {
17216
+ yield typedCall('CardanoPoolRelayParameters', 'CardanoTxItemAck', poolRelay);
17217
+ }
17218
+ }
17219
+ for (const withdrawal of this.params.withdrawals) {
17220
+ yield typedCall('CardanoTxWithdrawal', 'CardanoTxItemAck', withdrawal);
17221
+ }
17222
+ let auxiliaryDataSupplement;
17223
+ if (this.params.auxiliaryData) {
17224
+ const { catalyst_registration_parameters } = this.params.auxiliaryData;
17225
+ if (catalyst_registration_parameters) {
17226
+ this.params.auxiliaryData = modifyAuxiliaryDataForBackwardsCompatibility(this.params.auxiliaryData);
17227
+ }
17228
+ const { message } = yield typedCall('CardanoTxAuxiliaryData', 'CardanoTxAuxiliaryDataSupplement', this.params.auxiliaryData);
17229
+ const auxiliaryDataType = hdTransport.Messages.CardanoTxAuxiliaryDataSupplementType[message.type];
17230
+ if (auxiliaryDataType !== hdTransport.Messages.CardanoTxAuxiliaryDataSupplementType.NONE) {
17231
+ auxiliaryDataSupplement = {
17232
+ type: auxiliaryDataType,
17233
+ auxiliaryDataHash: message.auxiliary_data_hash,
17234
+ catalystSignature: message.catalyst_signature,
17235
+ };
17236
+ }
17237
+ yield typedCall('CardanoTxHostAck', 'CardanoTxItemAck');
17238
+ }
17239
+ if (this.params.mint.length > 0) {
17240
+ yield typedCall('CardanoTxMint', 'CardanoTxItemAck', {
17241
+ asset_groups_count: this.params.mint.length,
17242
+ });
17243
+ for (const assetGroup of this.params.mint) {
17244
+ yield typedCall('CardanoAssetGroup', 'CardanoTxItemAck', {
17245
+ policy_id: assetGroup.policyId,
17246
+ tokens_count: assetGroup.tokens.length,
17247
+ });
17248
+ for (const token of assetGroup.tokens) {
17249
+ yield typedCall('CardanoToken', 'CardanoTxItemAck', token);
17250
+ }
17251
+ }
17252
+ }
17253
+ for (const { collateralInput } of this.params.collateralInputsWithPath) {
17254
+ yield typedCall('CardanoTxCollateralInput', 'CardanoTxItemAck', collateralInput);
17255
+ }
17256
+ for (const requiredSigner of this.params.requiredSigners) {
17257
+ yield typedCall('CardanoTxRequiredSigner', 'CardanoTxItemAck', requiredSigner);
17258
+ }
17259
+ if (this.params.collateralReturnWithData) {
17260
+ yield sendOutput(typedCall, this.params.collateralReturnWithData);
17261
+ }
17262
+ for (const referenceInput of this.params.referenceInputs) {
17263
+ yield typedCall('CardanoTxReferenceInput', 'CardanoTxItemAck', referenceInput);
17264
+ }
17265
+ const witnesses = [];
17266
+ for (const path of this.params.witnessPaths) {
17267
+ const { message } = yield typedCall('CardanoTxWitnessRequest', 'CardanoTxWitnessResponse', {
17268
+ path,
17269
+ });
17270
+ witnesses.push({
17271
+ type: hdTransport.Messages.CardanoTxWitnessType[message.type],
17272
+ pubKey: message.pub_key,
17273
+ signature: message.signature,
17274
+ chainCode: message.chain_code,
17275
+ });
17276
+ }
17277
+ const { message: txBodyHashMessage } = yield typedCall('CardanoTxHostAck', 'CardanoTxBodyHash');
17278
+ yield typedCall('CardanoTxHostAck', 'CardanoSignTxFinished');
17279
+ return { hash: txBodyHashMessage.tx_hash, witnesses, auxiliaryDataSupplement };
17280
+ });
17281
+ }
17282
+ run() {
17283
+ return this.signTx();
17284
+ }
17285
+ }
17286
+
17287
+ var ApiMethods = /*#__PURE__*/Object.freeze({
17288
+ __proto__: null,
17289
+ searchDevices: SearchDevices,
17290
+ getFeatures: GetFeatures,
17291
+ getPassphraseState: GetPassphraseState,
17292
+ getLogs: CheckBridgeStatus$1,
17293
+ checkFirmwareRelease: CheckFirmwareRelease,
17294
+ checkBLEFirmwareRelease: CheckBLEFirmwareRelease,
17295
+ checkTransportRelease: CheckTransportRelease,
17296
+ checkBridgeStatus: CheckBridgeStatus,
17297
+ deviceBackup: DeviceBackup,
17298
+ deviceChangePin: DeviceChangePin,
17299
+ deviceFlags: DeviceFlags,
17300
+ deviceRebootToBootloader: DeviceRebootToBootloader,
17301
+ deviceRecovery: DeviceRecovery,
17302
+ deviceReset: DeviceReset,
17303
+ deviceSettings: DeviceSettings,
17304
+ deviceUpdateReboot: DeviceUpdateReboot,
17305
+ deviceUploadResource: DeviceUploadResource,
17306
+ deviceSupportFeatures: DeviceSupportFeatures,
17307
+ deviceVerify: DeviceVerify,
17308
+ deviceWipe: DeviceWipe,
17309
+ deviceFullyUploadResource: DeviceFullyUploadResource,
17310
+ firmwareUpdate: FirmwareUpdate$1,
17311
+ firmwareUpdateV2: FirmwareUpdate,
17312
+ requestWebUsbDevice: RequestWebUsbDevice,
17313
+ cipherKeyValue: CipherKeyValue,
17314
+ btcGetAddress: BTCGetAddress,
17315
+ btcGetPublicKey: BTCGetPublicKey,
17316
+ btcSignMessage: BTCSignMessage,
17317
+ btcSignTransaction: BTCSignTransaction,
17318
+ btcVerifyMessage: BTCVerifyMessage,
17319
+ confluxGetAddress: ConfluxGetAddress,
17320
+ confluxSignMessage: ConfluxSignMessage,
17321
+ confluxSignMessageCIP23: ConfluxSignMessageCIP23,
17322
+ confluxSignTransaction: ConfluxSignTransaction,
17323
+ evmGetAddress: EvmGetAddress,
17324
+ evmGetPublicKey: EVMGetPublicKey,
17325
+ evmSignMessage: EVMSignMessage$2,
17326
+ evmSignMessageEIP712: EVMSignMessageEIP712,
17327
+ evmSignTransaction: EVMSignTransaction,
17328
+ evmSignTypedData: EVMSignTypedData,
17329
+ evmVerifyMessage: EVMSignMessage$1,
17330
+ starcoinGetAddress: StarcoinGetAddress,
17331
+ starcoinGetPublicKey: StarcoinGetPublicKey,
17332
+ starcoinSignMessage: StarcoinSignMessage,
17333
+ starcoinSignTransaction: StarcoinSignTransaction,
17334
+ starcoinVerifyMessage: EVMSignMessage,
17335
+ nemGetAddress: NEMGetAddress,
17336
+ nemSignTransaction: NEMSignTransaction,
17337
+ solGetAddress: SolGetAddress,
17338
+ solSignTransaction: SolSignTransaction,
17339
+ stellarGetAddress: StellarGetAddress,
17340
+ stellarSignTransaction: StellarSignTransaction,
17341
+ tronGetAddress: TronGetAddress,
17342
+ tronSignMessage: TronSignMessage,
17343
+ tronSignTransaction: TronSignTransaction,
17344
+ nearGetAddress: NearGetAddress,
17345
+ nearSignTransaction: NearSignTransaction,
17346
+ aptosGetAddress: AptosGetAddress,
17347
+ aptosGetPublicKey: AptosGetPublicKey,
17348
+ aptosSignTransaction: AptosSignTransaction,
17349
+ aptosSignMessage: AptosSignMessage,
17350
+ algoGetAddress: AlgoGetAddress,
17351
+ algoSignTransaction: AlgoSignTransaction,
17352
+ cosmosGetAddress: CosmosGetAddress,
17353
+ cosmosGetPublicKey: CosmosGetPublicKey,
17354
+ cosmosSignTransaction: CosmosSignTransaction,
17355
+ xrpGetAddress: XrpGetAddress$1,
17356
+ xrpSignTransaction: XrpGetAddress,
17357
+ suiGetAddress: SuiGetAddress,
17358
+ suiGetPublicKey: SuiGetPublicKey,
17359
+ suiSignTransaction: SuiSignTransaction,
17360
+ cardanoGetAddress: CardanoGetAddress,
17361
+ cardanoGetPublicKey: CardanoGetPublicKey,
17362
+ cardanoSignTransaction: CardanoSignTransaction
17363
+ });
17364
+
17365
+ function findMethod(message) {
17366
+ const { method } = message.payload;
17367
+ if (typeof method !== 'string') {
17368
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Method is not set');
17369
+ }
17370
+ const MethodConstructor = ApiMethods[method];
17371
+ if (MethodConstructor) {
17372
+ return new MethodConstructor(message);
17373
+ }
17374
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Method ${method} is not set`);
17375
+ }
16271
17376
 
16272
17377
  const resolveAfter = (msec, value) => new Promise(resolve => {
16273
17378
  setTimeout(resolve, msec, value);
@@ -16375,6 +17480,7 @@ const parseInitOptions = (method) => ({
16375
17480
  initSession: method === null || method === void 0 ? void 0 : method.payload.initSession,
16376
17481
  passphraseState: method === null || method === void 0 ? void 0 : method.payload.passphraseState,
16377
17482
  deviceId: method === null || method === void 0 ? void 0 : method.payload.deviceId,
17483
+ deriveCardano: method === null || method === void 0 ? void 0 : method.name.startsWith('cardano'),
16378
17484
  });
16379
17485
  let _core;
16380
17486
  let _deviceList;