@onekeyfe/hd-web-sdk 0.2.8 → 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.
@@ -7467,6 +7467,21 @@ const inject = ({
7467
7467
  connectId,
7468
7468
  deviceId,
7469
7469
  method: 'suiSignTransaction'
7470
+ })),
7471
+ cardanoGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
7472
+ connectId,
7473
+ deviceId,
7474
+ method: 'cardanoGetAddress'
7475
+ })),
7476
+ cardanoGetPublicKey: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
7477
+ connectId,
7478
+ deviceId,
7479
+ method: 'cardanoGetPublicKey'
7480
+ })),
7481
+ cardanoSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
7482
+ connectId,
7483
+ deviceId,
7484
+ method: 'cardanoSignTransaction'
7470
7485
  }))
7471
7486
  };
7472
7487
  return api;
@@ -10268,6 +10283,45 @@ var nested = {
10268
10283
  rule: "required",
10269
10284
  type: "CardanoDerivationType",
10270
10285
  id: 14
10286
+ },
10287
+ include_network_id: {
10288
+ type: "bool",
10289
+ id: 15,
10290
+ options: {
10291
+ "default": false
10292
+ }
10293
+ },
10294
+ script_data_hash: {
10295
+ type: "bytes",
10296
+ id: 16
10297
+ },
10298
+ collateral_inputs_count: {
10299
+ rule: "required",
10300
+ type: "uint32",
10301
+ id: 17
10302
+ },
10303
+ required_signers_count: {
10304
+ rule: "required",
10305
+ type: "uint32",
10306
+ id: 18
10307
+ },
10308
+ has_collateral_return: {
10309
+ type: "bool",
10310
+ id: 19,
10311
+ options: {
10312
+ "default": false
10313
+ }
10314
+ },
10315
+ total_collateral: {
10316
+ type: "uint64",
10317
+ id: 20
10318
+ },
10319
+ reference_inputs_count: {
10320
+ type: "uint32",
10321
+ id: 21,
10322
+ options: {
10323
+ "default": 0
10324
+ }
10271
10325
  }
10272
10326
  }
10273
10327
  },
@@ -19452,6 +19506,10 @@ class Device extends events.exports {
19452
19506
  payload.session_id = internalState;
19453
19507
  }
19454
19508
 
19509
+ if (options === null || options === void 0 ? void 0 : options.deriveCardano) {
19510
+ payload.derive_cardano = true;
19511
+ }
19512
+
19455
19513
  Log$5.debug('initialize payload:', payload);
19456
19514
  const {
19457
19515
  message
@@ -19818,8 +19876,10 @@ class BaseMethod {
19818
19876
  checkDeviceSupportFeature() {
19819
19877
  if (!this.device || !this.device.features) return;
19820
19878
  const inputPinOnSoftware = supportInputPinOnSoftware(this.device.features);
19879
+ const modifyHomescreen = supportModifyHomescreen(this.device.features);
19821
19880
  this.postMessage(createDeviceMessage(DEVICE.SUPPORT_FEATURES, {
19822
19881
  inputPinOnSoftware,
19882
+ modifyHomescreen,
19823
19883
  device: this.device.toMessageObject()
19824
19884
  }));
19825
19885
  }
@@ -20149,6 +20209,17 @@ const validateParams = (values, fields) => {
20149
20209
 
20150
20210
  break;
20151
20211
 
20212
+ case 'uint':
20213
+ if (typeof value !== 'string' && typeof value !== 'number') {
20214
+ throw invalidParameter(`Parameter [${field.name}] has invalid type. "string|number" expected.`);
20215
+ }
20216
+
20217
+ if (typeof value === 'number' && !Number.isSafeInteger(value) || !/^(?:[1-9]\d*|\d)$/.test(value.toString().replace(/^-/, field.allowNegative ? '' : '-'))) {
20218
+ throw invalidParameter(`Parameter [${field.name}] has invalid value "${value}". Integer representation expected.`);
20219
+ }
20220
+
20221
+ break;
20222
+
20152
20223
  case 'bigNumber':
20153
20224
  if (typeof value !== 'string') {
20154
20225
  throw invalidParameter(`Parameter [${field.name}] is of type invalid and should be [string].`);
@@ -20686,8 +20757,6 @@ const getInfo = ({
20686
20757
  return findLatestRelease(releaseInfo);
20687
20758
  };
20688
20759
 
20689
- getLogger(exports.d0.Device);
20690
-
20691
20760
  const postConfirmationMessage = device => {
20692
20761
  var _a;
20693
20762
 
@@ -22072,7 +22141,7 @@ const saveTxSignatures = (serializedTx, signatures, txRequest) => {
22072
22141
 
22073
22142
  if (typeof signature_index === 'number') {
22074
22143
  if (!signature) {
22075
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'saveTxSignatures: Unexpected null in trezor:TxRequestSerialized signature.');
22144
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'saveTxSignatures: Unexpected null in oneKey:TxRequestSerialized signature.');
22076
22145
  }
22077
22146
 
22078
22147
  signatures[signature_index] = signature;
@@ -25730,6 +25799,1175 @@ class SuiSignTransaction extends BaseMethod {
25730
25799
 
25731
25800
  }
25732
25801
 
25802
+ const safeThrowError = error => {
25803
+ if (error instanceof hdShared.HardwareError) {
25804
+ throw error;
25805
+ } else if (error.code === 'ERR_NETWORK') {
25806
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeNotInstalled);
25807
+ } else if (error.code === 'ECONNABORTED') {
25808
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
25809
+ } else {
25810
+ throw hdShared.ERRORS.TypedError(error);
25811
+ }
25812
+ };
25813
+
25814
+ const validateAddressParameters = addressParameters => {
25815
+ validateParams(addressParameters, [{
25816
+ name: 'addressType',
25817
+ type: 'number',
25818
+ required: true
25819
+ }, {
25820
+ name: 'stakingKeyHash',
25821
+ type: 'string'
25822
+ }, {
25823
+ name: 'paymentScriptHash',
25824
+ type: 'string'
25825
+ }, {
25826
+ name: 'stakingScriptHash',
25827
+ type: 'string'
25828
+ }]);
25829
+
25830
+ if (addressParameters.path) {
25831
+ validatePath(addressParameters.path);
25832
+ }
25833
+
25834
+ if (addressParameters.stakingPath) {
25835
+ validatePath(addressParameters.stakingPath);
25836
+ }
25837
+
25838
+ if (addressParameters.certificatePointer) {
25839
+ validateParams(addressParameters.certificatePointer, [{
25840
+ name: 'blockIndex',
25841
+ type: 'number',
25842
+ required: true
25843
+ }, {
25844
+ name: 'txIndex',
25845
+ type: 'number',
25846
+ required: true
25847
+ }, {
25848
+ name: 'certificateIndex',
25849
+ type: 'number',
25850
+ required: true
25851
+ }]);
25852
+ }
25853
+ };
25854
+
25855
+ const addressParametersToProto = addressParameters => {
25856
+ let path = [];
25857
+
25858
+ if (addressParameters.path) {
25859
+ path = validatePath(addressParameters.path, 3);
25860
+ }
25861
+
25862
+ let stakingPath = [];
25863
+
25864
+ if (addressParameters.stakingPath) {
25865
+ stakingPath = validatePath(addressParameters.stakingPath, 3);
25866
+ }
25867
+
25868
+ let certificatePointer;
25869
+
25870
+ if (addressParameters.certificatePointer) {
25871
+ certificatePointer = {
25872
+ block_index: addressParameters.certificatePointer.blockIndex,
25873
+ tx_index: addressParameters.certificatePointer.txIndex,
25874
+ certificate_index: addressParameters.certificatePointer.certificateIndex
25875
+ };
25876
+ }
25877
+
25878
+ return {
25879
+ address_type: addressParameters.addressType,
25880
+ address_n: path,
25881
+ address_n_staking: stakingPath,
25882
+ staking_key_hash: addressParameters.stakingKeyHash,
25883
+ certificate_pointer: certificatePointer,
25884
+ script_payment_hash: addressParameters.paymentScriptHash,
25885
+ script_staking_hash: addressParameters.stakingScriptHash
25886
+ };
25887
+ };
25888
+
25889
+ const addressParametersFromProto = addressParameters => {
25890
+ let certificatePointer;
25891
+
25892
+ if (addressParameters.certificate_pointer) {
25893
+ certificatePointer = {
25894
+ blockIndex: addressParameters.certificate_pointer.block_index,
25895
+ txIndex: addressParameters.certificate_pointer.tx_index,
25896
+ certificateIndex: addressParameters.certificate_pointer.certificate_index
25897
+ };
25898
+ }
25899
+
25900
+ return {
25901
+ addressType: addressParameters.address_type,
25902
+ path: addressParameters.address_n,
25903
+ stakingPath: addressParameters.address_n_staking,
25904
+ stakingKeyHash: addressParameters.staking_key_hash,
25905
+ certificatePointer
25906
+ };
25907
+ };
25908
+
25909
+ const modifyAddressParametersForBackwardsCompatibility = address_parameters => {
25910
+ if (address_parameters.address_type === hdTransport.Messages.CardanoAddressType.REWARD) {
25911
+ let {
25912
+ address_n,
25913
+ address_n_staking
25914
+ } = address_parameters;
25915
+
25916
+ if (address_n.length > 0 && address_n_staking.length > 0) {
25917
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Only stakingPath is allowed for CardanoAddressType.REWARD`);
25918
+ }
25919
+
25920
+ if (address_n.length > 0) {
25921
+ address_n_staking = address_n;
25922
+ address_n = [];
25923
+ }
25924
+
25925
+ return Object.assign(Object.assign({}, address_parameters), {
25926
+ address_n,
25927
+ address_n_staking
25928
+ });
25929
+ }
25930
+
25931
+ return address_parameters;
25932
+ };
25933
+
25934
+ class CardanoGetAddress extends BaseMethod {
25935
+ init() {
25936
+ var _a;
25937
+
25938
+ this.checkDeviceId = true;
25939
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
25940
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
25941
+ const payload = this.hasBundle ? this.payload : {
25942
+ bundle: [this.payload]
25943
+ };
25944
+ this.params = payload.bundle.map(batch => {
25945
+ validateParams(batch, [{
25946
+ name: 'addressParameters',
25947
+ type: 'object',
25948
+ required: true
25949
+ }, {
25950
+ name: 'networkId',
25951
+ type: 'number',
25952
+ required: true
25953
+ }, {
25954
+ name: 'protocolMagic',
25955
+ type: 'number',
25956
+ required: true
25957
+ }, {
25958
+ name: 'derivationType',
25959
+ type: 'number'
25960
+ }, {
25961
+ name: 'address',
25962
+ type: 'string'
25963
+ }, {
25964
+ name: 'showOnTrezor',
25965
+ type: 'boolean'
25966
+ }]);
25967
+ validateAddressParameters(batch.addressParameters);
25968
+ return {
25969
+ address_parameters: addressParametersToProto(batch.addressParameters),
25970
+ address: batch.address,
25971
+ protocol_magic: batch.protocolMagic,
25972
+ network_id: batch.networkId,
25973
+ derivation_type: typeof batch.derivationType !== 'undefined' ? batch.derivationType : hdTransport.Messages.CardanoDerivationType.ICARUS_TREZOR,
25974
+ show_display: typeof batch.showOnOneKey === 'boolean' ? !!batch.showOneKey : true
25975
+ };
25976
+ });
25977
+ }
25978
+
25979
+ run() {
25980
+ return __awaiter(this, void 0, void 0, function* () {
25981
+ const responses = [];
25982
+
25983
+ for (const batch of this.params) {
25984
+ const {
25985
+ address_parameters,
25986
+ protocol_magic,
25987
+ network_id,
25988
+ derivation_type,
25989
+ show_display
25990
+ } = batch;
25991
+ const response = yield this.device.commands.typedCall('CardanoGetAddress', 'CardanoAddress', {
25992
+ address_parameters,
25993
+ protocol_magic,
25994
+ network_id,
25995
+ derivation_type,
25996
+ show_display
25997
+ });
25998
+ const publicKeyRes = yield this.device.commands.typedCall('CardanoGetPublicKey', 'CardanoPublicKey', {
25999
+ address_n: address_parameters.address_n.slice(0, 3),
26000
+ derivation_type,
26001
+ show_display
26002
+ });
26003
+ responses.push({
26004
+ addressParameters: addressParametersFromProto(batch.address_parameters),
26005
+ protocolMagic: batch.protocol_magic,
26006
+ networkId: batch.network_id,
26007
+ serializedPath: serializedPath(batch.address_parameters.address_n),
26008
+ serializedStakingPath: serializedPath(batch.address_parameters.address_n_staking),
26009
+ address: response.message.address,
26010
+ xpub: publicKeyRes.message.xpub
26011
+ });
26012
+ }
26013
+
26014
+ return this.hasBundle ? responses : responses[0];
26015
+ });
26016
+ }
26017
+
26018
+ }
26019
+
26020
+ class CardanoGetPublicKey extends BaseMethod {
26021
+ init() {
26022
+ var _a;
26023
+
26024
+ this.checkDeviceId = true;
26025
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
26026
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
26027
+ const payload = this.hasBundle ? this.payload : {
26028
+ bundle: [this.payload]
26029
+ };
26030
+ validateParams(payload, [{
26031
+ name: 'bundle',
26032
+ type: 'array'
26033
+ }]);
26034
+ this.params = payload.bundle.map(batch => {
26035
+ validateParams(batch, [{
26036
+ name: 'path',
26037
+ required: true
26038
+ }, {
26039
+ name: 'derivationType',
26040
+ type: 'number'
26041
+ }, {
26042
+ name: 'showOnTrezor',
26043
+ type: 'boolean'
26044
+ }]);
26045
+ const path = validatePath(batch.path, 3);
26046
+ return {
26047
+ address_n: path,
26048
+ derivation_type: typeof batch.derivationType !== 'undefined' ? batch.derivationType : hdTransport.Messages.CardanoDerivationType.ICARUS_TREZOR,
26049
+ show_display: typeof batch.showOnOneKey === 'boolean' ? batch.showOnOneKey : false
26050
+ };
26051
+ });
26052
+ }
26053
+
26054
+ run() {
26055
+ return __awaiter(this, void 0, void 0, function* () {
26056
+ const responses = [];
26057
+ const cmd = this.device.getCommands();
26058
+
26059
+ for (let i = 0; i < this.params.length; i++) {
26060
+ const batch = this.params[i];
26061
+ const {
26062
+ message
26063
+ } = yield cmd.typedCall('CardanoGetPublicKey', 'CardanoPublicKey', batch);
26064
+ responses.push({
26065
+ path: batch.address_n,
26066
+ serializedPath: serializedPath(batch.address_n),
26067
+ publicKey: message.xpub,
26068
+ node: message.node
26069
+ });
26070
+ }
26071
+
26072
+ return this.hasBundle ? responses : responses[0];
26073
+ });
26074
+ }
26075
+
26076
+ }
26077
+
26078
+ const transformInput = input => {
26079
+ validateParams(input, [{
26080
+ name: 'prev_hash',
26081
+ type: 'string',
26082
+ required: true
26083
+ }, {
26084
+ name: 'prev_index',
26085
+ type: 'number',
26086
+ required: true
26087
+ }]);
26088
+ return {
26089
+ input: {
26090
+ prev_hash: input.prev_hash,
26091
+ prev_index: input.prev_index
26092
+ },
26093
+ path: input.path ? validatePath(input.path, 5) : undefined
26094
+ };
26095
+ };
26096
+
26097
+ const transformCollateralInput = collateralInput => {
26098
+ validateParams(collateralInput, [{
26099
+ name: 'prev_hash',
26100
+ type: 'string',
26101
+ required: true
26102
+ }, {
26103
+ name: 'prev_index',
26104
+ type: 'number',
26105
+ required: true
26106
+ }]);
26107
+ return {
26108
+ collateralInput: {
26109
+ prev_hash: collateralInput.prev_hash,
26110
+ prev_index: collateralInput.prev_index
26111
+ },
26112
+ path: collateralInput.path ? validatePath(collateralInput.path, 5) : undefined
26113
+ };
26114
+ };
26115
+
26116
+ const transformReferenceInput = referenceInput => {
26117
+ validateParams(referenceInput, [{
26118
+ name: 'prev_hash',
26119
+ type: 'string',
26120
+ required: true
26121
+ }, {
26122
+ name: 'prev_index',
26123
+ type: 'number',
26124
+ required: true
26125
+ }]);
26126
+ return {
26127
+ prev_hash: referenceInput.prev_hash,
26128
+ prev_index: referenceInput.prev_index
26129
+ };
26130
+ };
26131
+
26132
+ const validateTokens = tokenAmounts => {
26133
+ tokenAmounts.forEach(tokenAmount => {
26134
+ validateParams(tokenAmount, [{
26135
+ name: 'assetNameBytes',
26136
+ type: 'string',
26137
+ required: true
26138
+ }, {
26139
+ name: 'amount',
26140
+ type: 'uint'
26141
+ }, {
26142
+ name: 'mintAmount',
26143
+ type: 'uint',
26144
+ allowNegative: true
26145
+ }]);
26146
+ });
26147
+ };
26148
+
26149
+ const validateTokenBundle = tokenBundle => {
26150
+ tokenBundle.forEach(tokenGroup => {
26151
+ validateParams(tokenGroup, [{
26152
+ name: 'policyId',
26153
+ type: 'string',
26154
+ required: true
26155
+ }, {
26156
+ name: 'tokenAmounts',
26157
+ type: 'array',
26158
+ required: true
26159
+ }]);
26160
+ validateTokens(tokenGroup.tokenAmounts);
26161
+ });
26162
+ };
26163
+
26164
+ const tokenBundleToProto = tokenBundle => {
26165
+ validateTokenBundle(tokenBundle);
26166
+ return tokenBundle.map(tokenGroup => ({
26167
+ policyId: tokenGroup.policyId,
26168
+ tokens: tokenAmountsToProto(tokenGroup.tokenAmounts)
26169
+ }));
26170
+ };
26171
+
26172
+ const tokenAmountsToProto = tokenAmounts => tokenAmounts.map(tokenAmount => ({
26173
+ asset_name_bytes: tokenAmount.assetNameBytes,
26174
+ amount: tokenAmount.amount,
26175
+ mint_amount: tokenAmount.mintAmount
26176
+ }));
26177
+
26178
+ const hexStringByteLength = s => s.length / 2;
26179
+
26180
+ const sendChunkedHexString = (typedCall, data, chunkSize, messageType) => __awaiter(void 0, void 0, void 0, function* () {
26181
+ let processedSize = 0;
26182
+
26183
+ while (processedSize < data.length) {
26184
+ const chunk = data.slice(processedSize, processedSize + chunkSize);
26185
+ yield typedCall(messageType, 'CardanoTxItemAck', {
26186
+ data: chunk
26187
+ });
26188
+ processedSize += chunkSize;
26189
+ }
26190
+ });
26191
+
26192
+ const transformOutput = output => {
26193
+ validateParams(output, [{
26194
+ name: 'address',
26195
+ type: 'string'
26196
+ }, {
26197
+ name: 'amount',
26198
+ type: 'uint',
26199
+ required: true
26200
+ }, {
26201
+ name: 'tokenBundle',
26202
+ type: 'array',
26203
+ allowEmpty: true
26204
+ }, {
26205
+ name: 'datumHash',
26206
+ type: 'string'
26207
+ }, {
26208
+ name: 'format',
26209
+ type: 'number'
26210
+ }, {
26211
+ name: 'inlineDatum',
26212
+ type: 'string'
26213
+ }, {
26214
+ name: 'referenceScript',
26215
+ type: 'string'
26216
+ }]);
26217
+ const result = {
26218
+ output: {
26219
+ amount: output.amount,
26220
+ asset_groups_count: 0,
26221
+ datum_hash: output.datumHash,
26222
+ format: output.format,
26223
+ inline_datum_size: output.inlineDatum ? hexStringByteLength(output.inlineDatum) : undefined,
26224
+ reference_script_size: output.referenceScript ? hexStringByteLength(output.referenceScript) : undefined
26225
+ },
26226
+ inlineDatum: output.inlineDatum,
26227
+ referenceScript: output.referenceScript
26228
+ };
26229
+
26230
+ if (output.addressParameters) {
26231
+ validateAddressParameters(output.addressParameters);
26232
+ result.output.address_parameters = addressParametersToProto(output.addressParameters);
26233
+ } else {
26234
+ result.output.address = output.address;
26235
+ }
26236
+
26237
+ if (output.tokenBundle) {
26238
+ result.tokenBundle = tokenBundleToProto(output.tokenBundle);
26239
+ result.output.asset_groups_count = result.tokenBundle.length;
26240
+ } else {
26241
+ result.output.asset_groups_count = 0;
26242
+ }
26243
+
26244
+ return result;
26245
+ };
26246
+
26247
+ const sendOutput = (typedCall, outputWithData) => __awaiter(void 0, void 0, void 0, function* () {
26248
+ const MAX_CHUNK_SIZE = 1024 * 2;
26249
+ const {
26250
+ output,
26251
+ tokenBundle,
26252
+ inlineDatum,
26253
+ referenceScript
26254
+ } = outputWithData;
26255
+ yield typedCall('CardanoTxOutput', 'CardanoTxItemAck', output);
26256
+
26257
+ if (tokenBundle) {
26258
+ for (const assetGroup of tokenBundle) {
26259
+ yield typedCall('CardanoAssetGroup', 'CardanoTxItemAck', {
26260
+ policy_id: assetGroup.policyId,
26261
+ tokens_count: assetGroup.tokens.length
26262
+ });
26263
+
26264
+ for (const token of assetGroup.tokens) {
26265
+ yield typedCall('CardanoToken', 'CardanoTxItemAck', token);
26266
+ }
26267
+ }
26268
+ }
26269
+
26270
+ if (inlineDatum) {
26271
+ yield sendChunkedHexString(typedCall, inlineDatum, MAX_CHUNK_SIZE, 'CardanoTxInlineDatumChunk');
26272
+ }
26273
+
26274
+ if (referenceScript) {
26275
+ yield sendChunkedHexString(typedCall, referenceScript, MAX_CHUNK_SIZE, 'CardanoTxReferenceScriptChunk');
26276
+ }
26277
+ });
26278
+
26279
+ const ipv4AddressToHex = ipv4Address => Buffer.from(ipv4Address.split('.').map(ipPart => parseInt(ipPart, 10))).toString('hex');
26280
+
26281
+ const ipv6AddressToHex = ipv6Address => ipv6Address.split(':').join('');
26282
+
26283
+ const validatePoolMargin = margin => {
26284
+ validateParams(margin, [{
26285
+ name: 'numerator',
26286
+ type: 'string',
26287
+ required: true
26288
+ }, {
26289
+ name: 'denominator',
26290
+ type: 'string',
26291
+ required: true
26292
+ }]);
26293
+ };
26294
+
26295
+ const validatePoolMetadata = metadata => {
26296
+ validateParams(metadata, [{
26297
+ name: 'url',
26298
+ type: 'string',
26299
+ required: true
26300
+ }, {
26301
+ name: 'hash',
26302
+ type: 'string',
26303
+ required: true
26304
+ }]);
26305
+ };
26306
+
26307
+ const validatePoolRelay = relay => {
26308
+ validateParams(relay, [{
26309
+ name: 'type',
26310
+ type: 'number',
26311
+ required: true
26312
+ }]);
26313
+
26314
+ if (relay.type === hdTransport.Messages.CardanoPoolRelayType.SINGLE_HOST_IP) {
26315
+ const paramsToValidate = [{
26316
+ name: 'port',
26317
+ type: 'number',
26318
+ required: true
26319
+ }];
26320
+
26321
+ if (relay.ipv4Address) {
26322
+ paramsToValidate.push({
26323
+ name: 'ipv4Address',
26324
+ type: 'string',
26325
+ required: false
26326
+ });
26327
+ }
26328
+
26329
+ if (relay.ipv6Address) {
26330
+ paramsToValidate.push({
26331
+ name: 'ipv6Address',
26332
+ type: 'string',
26333
+ required: false
26334
+ });
26335
+ }
26336
+
26337
+ validateParams(relay, paramsToValidate);
26338
+
26339
+ if (!relay.ipv4Address && !relay.ipv6Address) {
26340
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Either ipv4Address or ipv6Address must be supplied');
26341
+ }
26342
+ } else if (relay.type === hdTransport.Messages.CardanoPoolRelayType.SINGLE_HOST_NAME) {
26343
+ validateParams(relay, [{
26344
+ name: 'hostName',
26345
+ type: 'string',
26346
+ required: true
26347
+ }, {
26348
+ name: 'port',
26349
+ type: 'number',
26350
+ required: true
26351
+ }]);
26352
+ } else if (relay.type === hdTransport.Messages.CardanoPoolRelayType.MULTIPLE_HOST_NAME) {
26353
+ validateParams(relay, [{
26354
+ name: 'hostName',
26355
+ type: 'string',
26356
+ required: true
26357
+ }]);
26358
+ }
26359
+ };
26360
+
26361
+ const validatePoolOwners = owners => {
26362
+ owners.forEach(owner => {
26363
+ if (owner.stakingKeyHash) {
26364
+ validateParams(owner, [{
26365
+ name: 'stakingKeyHash',
26366
+ type: 'string',
26367
+ required: !owner.stakingKeyPath
26368
+ }]);
26369
+ }
26370
+
26371
+ if (owner.stakingKeyPath) {
26372
+ validatePath(owner.stakingKeyPath, 5);
26373
+ }
26374
+
26375
+ if (!owner.stakingKeyHash && !owner.stakingKeyPath) {
26376
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Either stakingKeyHash or stakingKeyPath must be supplied');
26377
+ }
26378
+ });
26379
+ const ownersAsPathCount = owners.filter(owner => !!owner.stakingKeyPath).length;
26380
+
26381
+ if (ownersAsPathCount !== 1) {
26382
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Exactly one pool owner must be given as a path');
26383
+ }
26384
+ };
26385
+
26386
+ const validatePoolParameters = poolParameters => {
26387
+ validateParams(poolParameters, [{
26388
+ name: 'poolId',
26389
+ type: 'string',
26390
+ required: true
26391
+ }, {
26392
+ name: 'vrfKeyHash',
26393
+ type: 'string',
26394
+ required: true
26395
+ }, {
26396
+ name: 'pledge',
26397
+ type: 'string',
26398
+ required: true
26399
+ }, {
26400
+ name: 'cost',
26401
+ type: 'string',
26402
+ required: true
26403
+ }, {
26404
+ name: 'margin',
26405
+ type: 'object',
26406
+ required: true
26407
+ }, {
26408
+ name: 'rewardAccount',
26409
+ type: 'string',
26410
+ required: true
26411
+ }, {
26412
+ name: 'owners',
26413
+ type: 'array',
26414
+ required: true
26415
+ }, {
26416
+ name: 'relays',
26417
+ type: 'array',
26418
+ required: true,
26419
+ allowEmpty: true
26420
+ }, {
26421
+ name: 'metadata',
26422
+ type: 'object'
26423
+ }]);
26424
+ validatePoolMargin(poolParameters.margin);
26425
+ validatePoolOwners(poolParameters.owners);
26426
+ poolParameters.relays.forEach(validatePoolRelay);
26427
+
26428
+ if (poolParameters.metadata) {
26429
+ validatePoolMetadata(poolParameters.metadata);
26430
+ }
26431
+ };
26432
+
26433
+ const transformPoolParameters = poolParameters => {
26434
+ if (!poolParameters) {
26435
+ return {
26436
+ poolParameters: undefined,
26437
+ poolOwners: [],
26438
+ poolRelays: []
26439
+ };
26440
+ }
26441
+
26442
+ validatePoolParameters(poolParameters);
26443
+ return {
26444
+ poolParameters: {
26445
+ pool_id: poolParameters.poolId,
26446
+ vrf_key_hash: poolParameters.vrfKeyHash,
26447
+ pledge: poolParameters.pledge,
26448
+ cost: poolParameters.cost,
26449
+ margin_numerator: poolParameters.margin.numerator,
26450
+ margin_denominator: poolParameters.margin.denominator,
26451
+ reward_account: poolParameters.rewardAccount,
26452
+ metadata: poolParameters.metadata,
26453
+ owners_count: poolParameters.owners.length,
26454
+ relays_count: poolParameters.relays.length
26455
+ },
26456
+ poolOwners: poolParameters.owners.map(owner => ({
26457
+ staking_key_hash: owner.stakingKeyHash,
26458
+ staking_key_path: owner.stakingKeyPath ? validatePath(owner.stakingKeyPath, 5) : undefined
26459
+ })),
26460
+ poolRelays: poolParameters.relays.map(relay => ({
26461
+ type: relay.type,
26462
+ ipv4_address: relay.ipv4Address ? ipv4AddressToHex(relay.ipv4Address) : undefined,
26463
+ ipv6_address: relay.ipv6Address ? ipv6AddressToHex(relay.ipv6Address) : undefined,
26464
+ host_name: relay.hostName,
26465
+ port: relay.port
26466
+ }))
26467
+ };
26468
+ };
26469
+
26470
+ const transformCertificate = certificate => {
26471
+ const paramsToValidate = [{
26472
+ name: 'type',
26473
+ type: 'number',
26474
+ required: true
26475
+ }];
26476
+
26477
+ if (certificate.type !== hdTransport.Messages.CardanoCertificateType.STAKE_POOL_REGISTRATION) {
26478
+ paramsToValidate.push({
26479
+ name: 'scriptHash',
26480
+ type: 'string'
26481
+ });
26482
+ paramsToValidate.push({
26483
+ name: 'keyHash',
26484
+ type: 'string'
26485
+ });
26486
+ }
26487
+
26488
+ if (certificate.type === hdTransport.Messages.CardanoCertificateType.STAKE_DELEGATION) {
26489
+ paramsToValidate.push({
26490
+ name: 'pool',
26491
+ type: 'string',
26492
+ required: true
26493
+ });
26494
+ }
26495
+
26496
+ if (certificate.type === hdTransport.Messages.CardanoCertificateType.STAKE_POOL_REGISTRATION) {
26497
+ paramsToValidate.push({
26498
+ name: 'poolParameters',
26499
+ type: 'object',
26500
+ required: true
26501
+ });
26502
+ }
26503
+
26504
+ validateParams(certificate, paramsToValidate);
26505
+ const {
26506
+ poolParameters,
26507
+ poolOwners,
26508
+ poolRelays
26509
+ } = transformPoolParameters(certificate.poolParameters);
26510
+ return {
26511
+ certificate: {
26512
+ type: certificate.type,
26513
+ path: certificate.path ? validatePath(certificate.path, 5) : undefined,
26514
+ script_hash: certificate.scriptHash,
26515
+ key_hash: certificate.keyHash,
26516
+ pool: certificate.pool,
26517
+ pool_parameters: poolParameters
26518
+ },
26519
+ poolOwners,
26520
+ poolRelays
26521
+ };
26522
+ };
26523
+
26524
+ const transformCatalystRegistrationParameters = catalystRegistrationParameters => {
26525
+ validateParams(catalystRegistrationParameters, [{
26526
+ name: 'votingPublicKey',
26527
+ type: 'string',
26528
+ required: true
26529
+ }, {
26530
+ name: 'stakingPath',
26531
+ required: true
26532
+ }, {
26533
+ name: 'nonce',
26534
+ type: 'uint',
26535
+ required: true
26536
+ }]);
26537
+ validateAddressParameters(catalystRegistrationParameters.rewardAddressParameters);
26538
+ return {
26539
+ voting_public_key: catalystRegistrationParameters.votingPublicKey,
26540
+ staking_path: validatePath(catalystRegistrationParameters.stakingPath, 3),
26541
+ reward_address_parameters: addressParametersToProto(catalystRegistrationParameters.rewardAddressParameters),
26542
+ nonce: catalystRegistrationParameters.nonce
26543
+ };
26544
+ };
26545
+
26546
+ const transformAuxiliaryData = auxiliaryData => {
26547
+ validateParams(auxiliaryData, [{
26548
+ name: 'hash',
26549
+ type: 'string'
26550
+ }]);
26551
+ let catalystRegistrationParameters;
26552
+
26553
+ if (auxiliaryData.catalystRegistrationParameters) {
26554
+ catalystRegistrationParameters = transformCatalystRegistrationParameters(auxiliaryData.catalystRegistrationParameters);
26555
+ }
26556
+
26557
+ return {
26558
+ hash: auxiliaryData.hash,
26559
+ catalyst_registration_parameters: catalystRegistrationParameters
26560
+ };
26561
+ };
26562
+
26563
+ const modifyAuxiliaryDataForBackwardsCompatibility = auxiliary_data => {
26564
+ const {
26565
+ catalyst_registration_parameters
26566
+ } = auxiliary_data;
26567
+
26568
+ if (catalyst_registration_parameters) {
26569
+ catalyst_registration_parameters.reward_address_parameters = modifyAddressParametersForBackwardsCompatibility(catalyst_registration_parameters.reward_address_parameters);
26570
+ return Object.assign(Object.assign({}, auxiliary_data), {
26571
+ catalyst_registration_parameters
26572
+ });
26573
+ }
26574
+
26575
+ return auxiliary_data;
26576
+ };
26577
+
26578
+ const gatherWitnessPaths = (inputsWithPath, certificatesWithPoolOwnersAndRelays, withdrawals, collateralInputsWithPath, requiredSigners, additionalWitnessRequests, signingMode) => {
26579
+ const witnessPaths = new Map();
26580
+
26581
+ function _insert(path) {
26582
+ const pathKey = JSON.stringify(path);
26583
+ witnessPaths.set(pathKey, path);
26584
+ }
26585
+
26586
+ if (signingMode !== hdTransport.Messages.CardanoTxSigningMode.MULTISIG_TRANSACTION) {
26587
+ inputsWithPath.forEach(({
26588
+ path
26589
+ }) => {
26590
+ if (path) _insert(path);
26591
+ });
26592
+ certificatesWithPoolOwnersAndRelays.forEach(({
26593
+ certificate,
26594
+ poolOwners
26595
+ }) => {
26596
+ if (certificate.path && (certificate.type === hdTransport.Messages.CardanoCertificateType.STAKE_DELEGATION || certificate.type === hdTransport.Messages.CardanoCertificateType.STAKE_DEREGISTRATION)) {
26597
+ _insert(certificate.path);
26598
+ }
26599
+
26600
+ poolOwners.forEach(poolOwner => {
26601
+ if (poolOwner.staking_key_path) _insert(poolOwner.staking_key_path);
26602
+ });
26603
+ });
26604
+ withdrawals.forEach(({
26605
+ path
26606
+ }) => {
26607
+ if (path) _insert(path);
26608
+ });
26609
+ }
26610
+
26611
+ if (signingMode === hdTransport.Messages.CardanoTxSigningMode.PLUTUS_TRANSACTION) {
26612
+ collateralInputsWithPath.forEach(({
26613
+ path
26614
+ }) => {
26615
+ if (path) _insert(path);
26616
+ });
26617
+ }
26618
+
26619
+ requiredSigners.forEach(({
26620
+ key_path
26621
+ }) => {
26622
+ if (key_path) _insert(key_path);
26623
+ });
26624
+ additionalWitnessRequests.forEach(path => {
26625
+ _insert(path);
26626
+ });
26627
+ return Array.from(witnessPaths.values());
26628
+ };
26629
+
26630
+ class CardanoSignTransaction extends BaseMethod {
26631
+ init() {
26632
+ var _a;
26633
+
26634
+ this.checkDeviceId = true;
26635
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
26636
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
26637
+ const {
26638
+ payload
26639
+ } = this;
26640
+ validateParams(payload, [{
26641
+ name: 'signingMode',
26642
+ type: 'number',
26643
+ required: true
26644
+ }, {
26645
+ name: 'inputs',
26646
+ type: 'array',
26647
+ required: true
26648
+ }, {
26649
+ name: 'outputs',
26650
+ type: 'array',
26651
+ required: true,
26652
+ allowEmpty: true
26653
+ }, {
26654
+ name: 'fee',
26655
+ type: 'uint',
26656
+ required: true
26657
+ }, {
26658
+ name: 'ttl',
26659
+ type: 'uint'
26660
+ }, {
26661
+ name: 'certificates',
26662
+ type: 'array',
26663
+ allowEmpty: true
26664
+ }, {
26665
+ name: 'withdrawals',
26666
+ type: 'array',
26667
+ allowEmpty: true
26668
+ }, {
26669
+ name: 'mint',
26670
+ type: 'array',
26671
+ allowEmpty: true
26672
+ }, {
26673
+ name: 'validityIntervalStart',
26674
+ type: 'uint'
26675
+ }, {
26676
+ name: 'scriptDataHash',
26677
+ type: 'string'
26678
+ }, {
26679
+ name: 'collateralInputs',
26680
+ type: 'array',
26681
+ allowEmpty: true
26682
+ }, {
26683
+ name: 'requiredSigners',
26684
+ type: 'array',
26685
+ allowEmpty: true
26686
+ }, {
26687
+ name: 'totalCollateral',
26688
+ type: 'uint'
26689
+ }, {
26690
+ name: 'referenceInputs',
26691
+ type: 'array',
26692
+ allowEmpty: true
26693
+ }, {
26694
+ name: 'protocolMagic',
26695
+ type: 'number',
26696
+ required: true
26697
+ }, {
26698
+ name: 'networkId',
26699
+ type: 'number',
26700
+ required: true
26701
+ }, {
26702
+ name: 'additionalWitnessRequests',
26703
+ type: 'array',
26704
+ allowEmpty: true
26705
+ }, {
26706
+ name: 'derivationType',
26707
+ type: 'number'
26708
+ }, {
26709
+ name: 'includeNetworkId',
26710
+ type: 'boolean'
26711
+ }]);
26712
+ const inputsWithPath = payload.inputs.map(transformInput);
26713
+ const outputsWithData = payload.outputs.map(transformOutput);
26714
+ let certificatesWithPoolOwnersAndRelays = [];
26715
+
26716
+ if (payload.certificates) {
26717
+ certificatesWithPoolOwnersAndRelays = payload.certificates.map(transformCertificate);
26718
+ }
26719
+
26720
+ let withdrawals = [];
26721
+
26722
+ if (payload.withdrawals) {
26723
+ withdrawals = payload.withdrawals.map(withdrawal => {
26724
+ validateParams(withdrawal, [{
26725
+ name: 'amount',
26726
+ type: 'uint',
26727
+ required: true
26728
+ }, {
26729
+ name: 'scriptHash',
26730
+ type: 'string'
26731
+ }, {
26732
+ name: 'keyHash',
26733
+ type: 'string'
26734
+ }]);
26735
+ return {
26736
+ path: withdrawal.path ? validatePath(withdrawal.path, 5) : undefined,
26737
+ amount: withdrawal.amount,
26738
+ script_hash: withdrawal.scriptHash,
26739
+ key_hash: withdrawal.keyHash
26740
+ };
26741
+ });
26742
+ }
26743
+
26744
+ let mint = [];
26745
+
26746
+ if (payload.mint) {
26747
+ mint = tokenBundleToProto(payload.mint);
26748
+ }
26749
+
26750
+ let auxiliaryData;
26751
+
26752
+ if (payload.auxiliaryData) {
26753
+ auxiliaryData = transformAuxiliaryData(payload.auxiliaryData);
26754
+ }
26755
+
26756
+ let additionalWitnessRequests = [];
26757
+
26758
+ if (payload.additionalWitnessRequests) {
26759
+ additionalWitnessRequests = payload.additionalWitnessRequests.map(witnessRequest => validatePath(witnessRequest, 3));
26760
+ }
26761
+
26762
+ let collateralInputsWithPath = [];
26763
+
26764
+ if (payload.collateralInputs) {
26765
+ collateralInputsWithPath = payload.collateralInputs.map(transformCollateralInput);
26766
+ }
26767
+
26768
+ let requiredSigners = [];
26769
+
26770
+ if (payload.requiredSigners) {
26771
+ requiredSigners = payload.requiredSigners.map(requiredSigner => {
26772
+ validateParams(requiredSigner, [{
26773
+ name: 'keyHash',
26774
+ type: 'string'
26775
+ }]);
26776
+ return {
26777
+ key_path: requiredSigner.keyPath ? validatePath(requiredSigner.keyPath, 3) : undefined,
26778
+ key_hash: requiredSigner.keyHash
26779
+ };
26780
+ });
26781
+ }
26782
+
26783
+ const collateralReturnWithData = payload.collateralReturn ? transformOutput(payload.collateralReturn) : undefined;
26784
+ let referenceInputs = [];
26785
+
26786
+ if (payload.referenceInputs) {
26787
+ referenceInputs = payload.referenceInputs.map(transformReferenceInput);
26788
+ }
26789
+
26790
+ this.params = {
26791
+ signingMode: payload.signingMode,
26792
+ inputsWithPath,
26793
+ outputsWithData,
26794
+ fee: payload.fee,
26795
+ ttl: payload.ttl,
26796
+ certificatesWithPoolOwnersAndRelays,
26797
+ withdrawals,
26798
+ mint,
26799
+ auxiliaryData,
26800
+ validityIntervalStart: payload.validityIntervalStart,
26801
+ scriptDataHash: payload.scriptDataHash,
26802
+ collateralInputsWithPath,
26803
+ requiredSigners,
26804
+ collateralReturnWithData,
26805
+ totalCollateral: payload.totalCollateral,
26806
+ referenceInputs,
26807
+ protocolMagic: payload.protocolMagic,
26808
+ networkId: payload.networkId,
26809
+ witnessPaths: gatherWitnessPaths(inputsWithPath, certificatesWithPoolOwnersAndRelays, withdrawals, collateralInputsWithPath, requiredSigners, additionalWitnessRequests, payload.signingMode),
26810
+ additionalWitnessRequests,
26811
+ derivationType: typeof payload.derivationType !== 'undefined' ? payload.derivationType : hdTransport.Messages.CardanoDerivationType.ICARUS_TREZOR,
26812
+ includeNetworkId: payload.includeNetworkId
26813
+ };
26814
+ }
26815
+
26816
+ signTx() {
26817
+ return __awaiter(this, void 0, void 0, function* () {
26818
+ const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
26819
+ const hasAuxiliaryData = !!this.params.auxiliaryData;
26820
+ const signTxInitMessage = {
26821
+ signing_mode: this.params.signingMode,
26822
+ protocol_magic: this.params.protocolMagic,
26823
+ network_id: this.params.networkId,
26824
+ inputs_count: this.params.inputsWithPath.length,
26825
+ outputs_count: this.params.outputsWithData.length,
26826
+ fee: this.params.fee,
26827
+ ttl: this.params.ttl,
26828
+ certificates_count: this.params.certificatesWithPoolOwnersAndRelays.length,
26829
+ withdrawals_count: this.params.withdrawals.length,
26830
+ has_auxiliary_data: hasAuxiliaryData,
26831
+ validity_interval_start: this.params.validityIntervalStart,
26832
+ witness_requests_count: this.params.witnessPaths.length,
26833
+ minting_asset_groups_count: this.params.mint.length,
26834
+ script_data_hash: this.params.scriptDataHash,
26835
+ collateral_inputs_count: this.params.collateralInputsWithPath.length,
26836
+ required_signers_count: this.params.requiredSigners.length,
26837
+ has_collateral_return: this.params.collateralReturnWithData != null,
26838
+ total_collateral: this.params.totalCollateral,
26839
+ reference_inputs_count: this.params.referenceInputs.length,
26840
+ derivation_type: this.params.derivationType,
26841
+ include_network_id: this.params.includeNetworkId
26842
+ };
26843
+ yield typedCall('CardanoSignTxInit', 'CardanoTxItemAck', signTxInitMessage);
26844
+
26845
+ for (const {
26846
+ input
26847
+ } of this.params.inputsWithPath) {
26848
+ yield typedCall('CardanoTxInput', 'CardanoTxItemAck', input);
26849
+ }
26850
+
26851
+ for (const outputWithData of this.params.outputsWithData) {
26852
+ yield sendOutput(typedCall, outputWithData);
26853
+ }
26854
+
26855
+ for (const {
26856
+ certificate,
26857
+ poolOwners,
26858
+ poolRelays
26859
+ } of this.params.certificatesWithPoolOwnersAndRelays) {
26860
+ yield typedCall('CardanoTxCertificate', 'CardanoTxItemAck', certificate);
26861
+
26862
+ for (const poolOwner of poolOwners) {
26863
+ yield typedCall('CardanoPoolOwner', 'CardanoTxItemAck', poolOwner);
26864
+ }
26865
+
26866
+ for (const poolRelay of poolRelays) {
26867
+ yield typedCall('CardanoPoolRelayParameters', 'CardanoTxItemAck', poolRelay);
26868
+ }
26869
+ }
26870
+
26871
+ for (const withdrawal of this.params.withdrawals) {
26872
+ yield typedCall('CardanoTxWithdrawal', 'CardanoTxItemAck', withdrawal);
26873
+ }
26874
+
26875
+ let auxiliaryDataSupplement;
26876
+
26877
+ if (this.params.auxiliaryData) {
26878
+ const {
26879
+ catalyst_registration_parameters
26880
+ } = this.params.auxiliaryData;
26881
+
26882
+ if (catalyst_registration_parameters) {
26883
+ this.params.auxiliaryData = modifyAuxiliaryDataForBackwardsCompatibility(this.params.auxiliaryData);
26884
+ }
26885
+
26886
+ const {
26887
+ message
26888
+ } = yield typedCall('CardanoTxAuxiliaryData', 'CardanoTxAuxiliaryDataSupplement', this.params.auxiliaryData);
26889
+ const auxiliaryDataType = hdTransport.Messages.CardanoTxAuxiliaryDataSupplementType[message.type];
26890
+
26891
+ if (auxiliaryDataType !== hdTransport.Messages.CardanoTxAuxiliaryDataSupplementType.NONE) {
26892
+ auxiliaryDataSupplement = {
26893
+ type: auxiliaryDataType,
26894
+ auxiliaryDataHash: message.auxiliary_data_hash,
26895
+ catalystSignature: message.catalyst_signature
26896
+ };
26897
+ }
26898
+
26899
+ yield typedCall('CardanoTxHostAck', 'CardanoTxItemAck');
26900
+ }
26901
+
26902
+ if (this.params.mint.length > 0) {
26903
+ yield typedCall('CardanoTxMint', 'CardanoTxItemAck', {
26904
+ asset_groups_count: this.params.mint.length
26905
+ });
26906
+
26907
+ for (const assetGroup of this.params.mint) {
26908
+ yield typedCall('CardanoAssetGroup', 'CardanoTxItemAck', {
26909
+ policy_id: assetGroup.policyId,
26910
+ tokens_count: assetGroup.tokens.length
26911
+ });
26912
+
26913
+ for (const token of assetGroup.tokens) {
26914
+ yield typedCall('CardanoToken', 'CardanoTxItemAck', token);
26915
+ }
26916
+ }
26917
+ }
26918
+
26919
+ for (const {
26920
+ collateralInput
26921
+ } of this.params.collateralInputsWithPath) {
26922
+ yield typedCall('CardanoTxCollateralInput', 'CardanoTxItemAck', collateralInput);
26923
+ }
26924
+
26925
+ for (const requiredSigner of this.params.requiredSigners) {
26926
+ yield typedCall('CardanoTxRequiredSigner', 'CardanoTxItemAck', requiredSigner);
26927
+ }
26928
+
26929
+ if (this.params.collateralReturnWithData) {
26930
+ yield sendOutput(typedCall, this.params.collateralReturnWithData);
26931
+ }
26932
+
26933
+ for (const referenceInput of this.params.referenceInputs) {
26934
+ yield typedCall('CardanoTxReferenceInput', 'CardanoTxItemAck', referenceInput);
26935
+ }
26936
+
26937
+ const witnesses = [];
26938
+
26939
+ for (const path of this.params.witnessPaths) {
26940
+ const {
26941
+ message
26942
+ } = yield typedCall('CardanoTxWitnessRequest', 'CardanoTxWitnessResponse', {
26943
+ path
26944
+ });
26945
+ witnesses.push({
26946
+ type: hdTransport.Messages.CardanoTxWitnessType[message.type],
26947
+ pubKey: message.pub_key,
26948
+ signature: message.signature,
26949
+ chainCode: message.chain_code
26950
+ });
26951
+ }
26952
+
26953
+ const {
26954
+ message: txBodyHashMessage
26955
+ } = yield typedCall('CardanoTxHostAck', 'CardanoTxBodyHash');
26956
+ yield typedCall('CardanoTxHostAck', 'CardanoSignTxFinished');
26957
+ return {
26958
+ hash: txBodyHashMessage.tx_hash,
26959
+ witnesses,
26960
+ auxiliaryDataSupplement
26961
+ };
26962
+ });
26963
+ }
26964
+
26965
+ run() {
26966
+ return this.signTx();
26967
+ }
26968
+
26969
+ }
26970
+
25733
26971
  var ApiMethods = /*#__PURE__*/Object.freeze({
25734
26972
  __proto__: null,
25735
26973
  searchDevices: SearchDevices,
@@ -25802,7 +27040,10 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
25802
27040
  xrpSignTransaction: XrpGetAddress,
25803
27041
  suiGetAddress: SuiGetAddress,
25804
27042
  suiGetPublicKey: SuiGetPublicKey,
25805
- suiSignTransaction: SuiSignTransaction
27043
+ suiSignTransaction: SuiSignTransaction,
27044
+ cardanoGetAddress: CardanoGetAddress,
27045
+ cardanoGetPublicKey: CardanoGetPublicKey,
27046
+ cardanoSignTransaction: CardanoSignTransaction
25806
27047
  });
25807
27048
 
25808
27049
  function findMethod(message) {
@@ -25823,18 +27064,6 @@ function findMethod(message) {
25823
27064
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Method ${method} is not set`);
25824
27065
  }
25825
27066
 
25826
- const safeThrowError = error => {
25827
- if (error instanceof hdShared.HardwareError) {
25828
- throw error;
25829
- } else if (error.code === 'ERR_NETWORK') {
25830
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeNotInstalled);
25831
- } else if (error.code === 'ECONNABORTED') {
25832
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
25833
- } else {
25834
- throw hdShared.ERRORS.TypedError(error);
25835
- }
25836
- };
25837
-
25838
27067
  const resolveAfter = (msec, value) => new Promise(resolve => {
25839
27068
  setTimeout(resolve, msec, value);
25840
27069
  });
@@ -25954,7 +27183,8 @@ const Log = getLogger(exports.d0.Core);
25954
27183
  const parseInitOptions = method => ({
25955
27184
  initSession: method === null || method === void 0 ? void 0 : method.payload.initSession,
25956
27185
  passphraseState: method === null || method === void 0 ? void 0 : method.payload.passphraseState,
25957
- deviceId: method === null || method === void 0 ? void 0 : method.payload.deviceId
27186
+ deviceId: method === null || method === void 0 ? void 0 : method.payload.deviceId,
27187
+ deriveCardano: method === null || method === void 0 ? void 0 : method.name.startsWith('cardano')
25958
27188
  });
25959
27189
 
25960
27190
  let _core;
@@ -72173,7 +73403,7 @@ module.exports = {"i8":"6.5.4"};
72173
73403
  /***/ ((module) => {
72174
73404
 
72175
73405
  "use strict";
72176
- module.exports = JSON.parse('{"name":"@onekeyfe/hd-core","version":"0.2.8","description":"> TODO: description","author":"OneKey","homepage":"https://github.com/OneKeyHQ/hardware-js-sdk#readme","license":"ISC","main":"dist/index.js","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/OneKeyHQ/hardware-js-sdk.git"},"publishConfig":{"access":"public"},"scripts":{"dev":"rimraf dist && rollup -c ../../build/rollup.config.js -w","build":"rimraf dist && rollup -c ../../build/rollup.config.js","lint":"eslint .","lint:fix":"eslint . --fix"},"bugs":{"url":"https://github.com/OneKeyHQ/hardware-js-sdk/issues"},"dependencies":{"@onekeyfe/hd-shared":"^0.2.8","@onekeyfe/hd-transport":"^0.2.8","axios":"^0.27.2","bignumber.js":"^9.0.2","jszip":"^3.10.1","parse-uri":"^1.0.7","semver":"^7.3.7"},"peerDependencies":{"@noble/hashes":"^1.1.3","ripple-keypairs":"^1.1.4"},"devDependencies":{"@noble/hashes":"^1.1.3","@types/parse-uri":"^1.0.0","@types/semver":"^7.3.9","ripple-keypairs":"^1.1.4"}}');
73406
+ module.exports = JSON.parse('{"name":"@onekeyfe/hd-core","version":"0.2.9","description":"> TODO: description","author":"OneKey","homepage":"https://github.com/OneKeyHQ/hardware-js-sdk#readme","license":"ISC","main":"dist/index.js","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/OneKeyHQ/hardware-js-sdk.git"},"publishConfig":{"access":"public"},"scripts":{"dev":"rimraf dist && rollup -c ../../build/rollup.config.js -w","build":"rimraf dist && rollup -c ../../build/rollup.config.js","lint":"eslint .","lint:fix":"eslint . --fix"},"bugs":{"url":"https://github.com/OneKeyHQ/hardware-js-sdk/issues"},"dependencies":{"@onekeyfe/hd-shared":"^0.2.9","@onekeyfe/hd-transport":"^0.2.9","axios":"^0.27.2","bignumber.js":"^9.0.2","jszip":"^3.10.1","parse-uri":"^1.0.7","semver":"^7.3.7"},"peerDependencies":{"@noble/hashes":"^1.1.3","ripple-keypairs":"^1.1.4"},"devDependencies":{"@noble/hashes":"^1.1.3","@types/parse-uri":"^1.0.0","@types/semver":"^7.3.9","ripple-keypairs":"^1.1.4"}}');
72177
73407
 
72178
73408
  /***/ })
72179
73409
 
@@ -74712,7 +75942,7 @@ const src_init = async settings => {
74712
75942
 
74713
75943
  try {
74714
75944
  await init({ ..._settings,
74715
- version: "0.2.8"
75945
+ version: "0.2.9"
74716
75946
  });
74717
75947
  return true;
74718
75948
  } catch (e) {