@onekeyfe/hd-web-sdk 0.2.8 → 0.2.10

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,1196 @@ 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, _b;
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
+ this.isCheck = !!((_b = this.payload) === null || _b === void 0 ? void 0 : _b.isCheck);
25942
+ const payload = this.hasBundle ? this.payload : {
25943
+ bundle: [this.payload]
25944
+ };
25945
+ this.params = payload.bundle.map(batch => {
25946
+ validateParams(batch, [{
25947
+ name: 'addressParameters',
25948
+ type: 'object',
25949
+ required: true
25950
+ }, {
25951
+ name: 'networkId',
25952
+ type: 'number',
25953
+ required: true
25954
+ }, {
25955
+ name: 'protocolMagic',
25956
+ type: 'number',
25957
+ required: true
25958
+ }, {
25959
+ name: 'derivationType',
25960
+ type: 'number'
25961
+ }, {
25962
+ name: 'address',
25963
+ type: 'string'
25964
+ }, {
25965
+ name: 'showOnOneKey',
25966
+ type: 'boolean'
25967
+ }]);
25968
+ validateAddressParameters(batch.addressParameters);
25969
+ return {
25970
+ address_parameters: addressParametersToProto(batch.addressParameters),
25971
+ address: batch.address,
25972
+ protocol_magic: batch.protocolMagic,
25973
+ network_id: batch.networkId,
25974
+ derivation_type: typeof batch.derivationType !== 'undefined' ? batch.derivationType : hdTransport.Messages.CardanoDerivationType.ICARUS_TREZOR,
25975
+ show_display: typeof batch.showOnOneKey === 'boolean' ? !!batch.showOnOneKey : true
25976
+ };
25977
+ });
25978
+ }
25979
+
25980
+ run() {
25981
+ return __awaiter(this, void 0, void 0, function* () {
25982
+ const responses = [];
25983
+
25984
+ for (const batch of this.params) {
25985
+ const {
25986
+ address_parameters,
25987
+ protocol_magic,
25988
+ network_id,
25989
+ derivation_type,
25990
+ show_display
25991
+ } = batch;
25992
+ const response = yield this.device.commands.typedCall('CardanoGetAddress', 'CardanoAddress', {
25993
+ address_parameters,
25994
+ protocol_magic,
25995
+ network_id,
25996
+ derivation_type,
25997
+ show_display
25998
+ });
25999
+ let xpub;
26000
+ let stakeAddress;
26001
+
26002
+ if (address_parameters.address_type === hdTransport.Messages.CardanoAddressType.BASE && !this.isCheck) {
26003
+ const publicKeyRes = yield this.device.commands.typedCall('CardanoGetPublicKey', 'CardanoPublicKey', {
26004
+ address_n: address_parameters.address_n.slice(0, 3),
26005
+ derivation_type,
26006
+ show_display
26007
+ });
26008
+ xpub = publicKeyRes.message.xpub;
26009
+ const stakeAddressRes = yield this.device.commands.typedCall('CardanoGetAddress', 'CardanoAddress', {
26010
+ address_parameters: {
26011
+ address_type: hdTransport.Messages.CardanoAddressType.REWARD,
26012
+ address_n: [],
26013
+ address_n_staking: address_parameters.address_n_staking
26014
+ },
26015
+ protocol_magic,
26016
+ network_id,
26017
+ derivation_type,
26018
+ show_display
26019
+ });
26020
+ stakeAddress = stakeAddressRes.message.address;
26021
+ }
26022
+
26023
+ responses.push({
26024
+ addressParameters: addressParametersFromProto(batch.address_parameters),
26025
+ protocolMagic: batch.protocol_magic,
26026
+ networkId: batch.network_id,
26027
+ serializedPath: serializedPath(batch.address_parameters.address_n),
26028
+ serializedStakingPath: serializedPath(batch.address_parameters.address_n_staking),
26029
+ address: response.message.address,
26030
+ xpub,
26031
+ stakeAddress
26032
+ });
26033
+ }
26034
+
26035
+ return this.hasBundle ? responses : responses[0];
26036
+ });
26037
+ }
26038
+
26039
+ }
26040
+
26041
+ class CardanoGetPublicKey extends BaseMethod {
26042
+ init() {
26043
+ var _a;
26044
+
26045
+ this.checkDeviceId = true;
26046
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
26047
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
26048
+ const payload = this.hasBundle ? this.payload : {
26049
+ bundle: [this.payload]
26050
+ };
26051
+ validateParams(payload, [{
26052
+ name: 'bundle',
26053
+ type: 'array'
26054
+ }]);
26055
+ this.params = payload.bundle.map(batch => {
26056
+ validateParams(batch, [{
26057
+ name: 'path',
26058
+ required: true
26059
+ }, {
26060
+ name: 'derivationType',
26061
+ type: 'number'
26062
+ }, {
26063
+ name: 'showOnTrezor',
26064
+ type: 'boolean'
26065
+ }]);
26066
+ const path = validatePath(batch.path, 3);
26067
+ return {
26068
+ address_n: path,
26069
+ derivation_type: typeof batch.derivationType !== 'undefined' ? batch.derivationType : hdTransport.Messages.CardanoDerivationType.ICARUS_TREZOR,
26070
+ show_display: typeof batch.showOnOneKey === 'boolean' ? batch.showOnOneKey : false
26071
+ };
26072
+ });
26073
+ }
26074
+
26075
+ run() {
26076
+ return __awaiter(this, void 0, void 0, function* () {
26077
+ const responses = [];
26078
+ const cmd = this.device.getCommands();
26079
+
26080
+ for (let i = 0; i < this.params.length; i++) {
26081
+ const batch = this.params[i];
26082
+ const {
26083
+ message
26084
+ } = yield cmd.typedCall('CardanoGetPublicKey', 'CardanoPublicKey', batch);
26085
+ responses.push({
26086
+ path: batch.address_n,
26087
+ serializedPath: serializedPath(batch.address_n),
26088
+ publicKey: message.xpub,
26089
+ node: message.node
26090
+ });
26091
+ }
26092
+
26093
+ return this.hasBundle ? responses : responses[0];
26094
+ });
26095
+ }
26096
+
26097
+ }
26098
+
26099
+ const transformInput = input => {
26100
+ validateParams(input, [{
26101
+ name: 'prev_hash',
26102
+ type: 'string',
26103
+ required: true
26104
+ }, {
26105
+ name: 'prev_index',
26106
+ type: 'number',
26107
+ required: true
26108
+ }]);
26109
+ return {
26110
+ input: {
26111
+ prev_hash: input.prev_hash,
26112
+ prev_index: input.prev_index
26113
+ },
26114
+ path: input.path ? validatePath(input.path, 5) : undefined
26115
+ };
26116
+ };
26117
+
26118
+ const transformCollateralInput = collateralInput => {
26119
+ validateParams(collateralInput, [{
26120
+ name: 'prev_hash',
26121
+ type: 'string',
26122
+ required: true
26123
+ }, {
26124
+ name: 'prev_index',
26125
+ type: 'number',
26126
+ required: true
26127
+ }]);
26128
+ return {
26129
+ collateralInput: {
26130
+ prev_hash: collateralInput.prev_hash,
26131
+ prev_index: collateralInput.prev_index
26132
+ },
26133
+ path: collateralInput.path ? validatePath(collateralInput.path, 5) : undefined
26134
+ };
26135
+ };
26136
+
26137
+ const transformReferenceInput = referenceInput => {
26138
+ validateParams(referenceInput, [{
26139
+ name: 'prev_hash',
26140
+ type: 'string',
26141
+ required: true
26142
+ }, {
26143
+ name: 'prev_index',
26144
+ type: 'number',
26145
+ required: true
26146
+ }]);
26147
+ return {
26148
+ prev_hash: referenceInput.prev_hash,
26149
+ prev_index: referenceInput.prev_index
26150
+ };
26151
+ };
26152
+
26153
+ const validateTokens = tokenAmounts => {
26154
+ tokenAmounts.forEach(tokenAmount => {
26155
+ validateParams(tokenAmount, [{
26156
+ name: 'assetNameBytes',
26157
+ type: 'string',
26158
+ required: true
26159
+ }, {
26160
+ name: 'amount',
26161
+ type: 'uint'
26162
+ }, {
26163
+ name: 'mintAmount',
26164
+ type: 'uint',
26165
+ allowNegative: true
26166
+ }]);
26167
+ });
26168
+ };
26169
+
26170
+ const validateTokenBundle = tokenBundle => {
26171
+ tokenBundle.forEach(tokenGroup => {
26172
+ validateParams(tokenGroup, [{
26173
+ name: 'policyId',
26174
+ type: 'string',
26175
+ required: true
26176
+ }, {
26177
+ name: 'tokenAmounts',
26178
+ type: 'array',
26179
+ required: true
26180
+ }]);
26181
+ validateTokens(tokenGroup.tokenAmounts);
26182
+ });
26183
+ };
26184
+
26185
+ const tokenBundleToProto = tokenBundle => {
26186
+ validateTokenBundle(tokenBundle);
26187
+ return tokenBundle.map(tokenGroup => ({
26188
+ policyId: tokenGroup.policyId,
26189
+ tokens: tokenAmountsToProto(tokenGroup.tokenAmounts)
26190
+ }));
26191
+ };
26192
+
26193
+ const tokenAmountsToProto = tokenAmounts => tokenAmounts.map(tokenAmount => ({
26194
+ asset_name_bytes: tokenAmount.assetNameBytes,
26195
+ amount: tokenAmount.amount,
26196
+ mint_amount: tokenAmount.mintAmount
26197
+ }));
26198
+
26199
+ const hexStringByteLength = s => s.length / 2;
26200
+
26201
+ const sendChunkedHexString = (typedCall, data, chunkSize, messageType) => __awaiter(void 0, void 0, void 0, function* () {
26202
+ let processedSize = 0;
26203
+
26204
+ while (processedSize < data.length) {
26205
+ const chunk = data.slice(processedSize, processedSize + chunkSize);
26206
+ yield typedCall(messageType, 'CardanoTxItemAck', {
26207
+ data: chunk
26208
+ });
26209
+ processedSize += chunkSize;
26210
+ }
26211
+ });
26212
+
26213
+ const transformOutput = output => {
26214
+ validateParams(output, [{
26215
+ name: 'address',
26216
+ type: 'string'
26217
+ }, {
26218
+ name: 'amount',
26219
+ type: 'uint',
26220
+ required: true
26221
+ }, {
26222
+ name: 'tokenBundle',
26223
+ type: 'array',
26224
+ allowEmpty: true
26225
+ }, {
26226
+ name: 'datumHash',
26227
+ type: 'string'
26228
+ }, {
26229
+ name: 'format',
26230
+ type: 'number'
26231
+ }, {
26232
+ name: 'inlineDatum',
26233
+ type: 'string'
26234
+ }, {
26235
+ name: 'referenceScript',
26236
+ type: 'string'
26237
+ }]);
26238
+ const result = {
26239
+ output: {
26240
+ amount: output.amount,
26241
+ asset_groups_count: 0,
26242
+ datum_hash: output.datumHash,
26243
+ format: output.format,
26244
+ inline_datum_size: output.inlineDatum ? hexStringByteLength(output.inlineDatum) : undefined,
26245
+ reference_script_size: output.referenceScript ? hexStringByteLength(output.referenceScript) : undefined
26246
+ },
26247
+ inlineDatum: output.inlineDatum,
26248
+ referenceScript: output.referenceScript
26249
+ };
26250
+
26251
+ if (output.addressParameters) {
26252
+ validateAddressParameters(output.addressParameters);
26253
+ result.output.address_parameters = addressParametersToProto(output.addressParameters);
26254
+ } else {
26255
+ result.output.address = output.address;
26256
+ }
26257
+
26258
+ if (output.tokenBundle) {
26259
+ result.tokenBundle = tokenBundleToProto(output.tokenBundle);
26260
+ result.output.asset_groups_count = result.tokenBundle.length;
26261
+ } else {
26262
+ result.output.asset_groups_count = 0;
26263
+ }
26264
+
26265
+ return result;
26266
+ };
26267
+
26268
+ const sendOutput = (typedCall, outputWithData) => __awaiter(void 0, void 0, void 0, function* () {
26269
+ const MAX_CHUNK_SIZE = 1024 * 2;
26270
+ const {
26271
+ output,
26272
+ tokenBundle,
26273
+ inlineDatum,
26274
+ referenceScript
26275
+ } = outputWithData;
26276
+ yield typedCall('CardanoTxOutput', 'CardanoTxItemAck', output);
26277
+
26278
+ if (tokenBundle) {
26279
+ for (const assetGroup of tokenBundle) {
26280
+ yield typedCall('CardanoAssetGroup', 'CardanoTxItemAck', {
26281
+ policy_id: assetGroup.policyId,
26282
+ tokens_count: assetGroup.tokens.length
26283
+ });
26284
+
26285
+ for (const token of assetGroup.tokens) {
26286
+ yield typedCall('CardanoToken', 'CardanoTxItemAck', token);
26287
+ }
26288
+ }
26289
+ }
26290
+
26291
+ if (inlineDatum) {
26292
+ yield sendChunkedHexString(typedCall, inlineDatum, MAX_CHUNK_SIZE, 'CardanoTxInlineDatumChunk');
26293
+ }
26294
+
26295
+ if (referenceScript) {
26296
+ yield sendChunkedHexString(typedCall, referenceScript, MAX_CHUNK_SIZE, 'CardanoTxReferenceScriptChunk');
26297
+ }
26298
+ });
26299
+
26300
+ const ipv4AddressToHex = ipv4Address => Buffer.from(ipv4Address.split('.').map(ipPart => parseInt(ipPart, 10))).toString('hex');
26301
+
26302
+ const ipv6AddressToHex = ipv6Address => ipv6Address.split(':').join('');
26303
+
26304
+ const validatePoolMargin = margin => {
26305
+ validateParams(margin, [{
26306
+ name: 'numerator',
26307
+ type: 'string',
26308
+ required: true
26309
+ }, {
26310
+ name: 'denominator',
26311
+ type: 'string',
26312
+ required: true
26313
+ }]);
26314
+ };
26315
+
26316
+ const validatePoolMetadata = metadata => {
26317
+ validateParams(metadata, [{
26318
+ name: 'url',
26319
+ type: 'string',
26320
+ required: true
26321
+ }, {
26322
+ name: 'hash',
26323
+ type: 'string',
26324
+ required: true
26325
+ }]);
26326
+ };
26327
+
26328
+ const validatePoolRelay = relay => {
26329
+ validateParams(relay, [{
26330
+ name: 'type',
26331
+ type: 'number',
26332
+ required: true
26333
+ }]);
26334
+
26335
+ if (relay.type === hdTransport.Messages.CardanoPoolRelayType.SINGLE_HOST_IP) {
26336
+ const paramsToValidate = [{
26337
+ name: 'port',
26338
+ type: 'number',
26339
+ required: true
26340
+ }];
26341
+
26342
+ if (relay.ipv4Address) {
26343
+ paramsToValidate.push({
26344
+ name: 'ipv4Address',
26345
+ type: 'string',
26346
+ required: false
26347
+ });
26348
+ }
26349
+
26350
+ if (relay.ipv6Address) {
26351
+ paramsToValidate.push({
26352
+ name: 'ipv6Address',
26353
+ type: 'string',
26354
+ required: false
26355
+ });
26356
+ }
26357
+
26358
+ validateParams(relay, paramsToValidate);
26359
+
26360
+ if (!relay.ipv4Address && !relay.ipv6Address) {
26361
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Either ipv4Address or ipv6Address must be supplied');
26362
+ }
26363
+ } else if (relay.type === hdTransport.Messages.CardanoPoolRelayType.SINGLE_HOST_NAME) {
26364
+ validateParams(relay, [{
26365
+ name: 'hostName',
26366
+ type: 'string',
26367
+ required: true
26368
+ }, {
26369
+ name: 'port',
26370
+ type: 'number',
26371
+ required: true
26372
+ }]);
26373
+ } else if (relay.type === hdTransport.Messages.CardanoPoolRelayType.MULTIPLE_HOST_NAME) {
26374
+ validateParams(relay, [{
26375
+ name: 'hostName',
26376
+ type: 'string',
26377
+ required: true
26378
+ }]);
26379
+ }
26380
+ };
26381
+
26382
+ const validatePoolOwners = owners => {
26383
+ owners.forEach(owner => {
26384
+ if (owner.stakingKeyHash) {
26385
+ validateParams(owner, [{
26386
+ name: 'stakingKeyHash',
26387
+ type: 'string',
26388
+ required: !owner.stakingKeyPath
26389
+ }]);
26390
+ }
26391
+
26392
+ if (owner.stakingKeyPath) {
26393
+ validatePath(owner.stakingKeyPath, 5);
26394
+ }
26395
+
26396
+ if (!owner.stakingKeyHash && !owner.stakingKeyPath) {
26397
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Either stakingKeyHash or stakingKeyPath must be supplied');
26398
+ }
26399
+ });
26400
+ const ownersAsPathCount = owners.filter(owner => !!owner.stakingKeyPath).length;
26401
+
26402
+ if (ownersAsPathCount !== 1) {
26403
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Exactly one pool owner must be given as a path');
26404
+ }
26405
+ };
26406
+
26407
+ const validatePoolParameters = poolParameters => {
26408
+ validateParams(poolParameters, [{
26409
+ name: 'poolId',
26410
+ type: 'string',
26411
+ required: true
26412
+ }, {
26413
+ name: 'vrfKeyHash',
26414
+ type: 'string',
26415
+ required: true
26416
+ }, {
26417
+ name: 'pledge',
26418
+ type: 'string',
26419
+ required: true
26420
+ }, {
26421
+ name: 'cost',
26422
+ type: 'string',
26423
+ required: true
26424
+ }, {
26425
+ name: 'margin',
26426
+ type: 'object',
26427
+ required: true
26428
+ }, {
26429
+ name: 'rewardAccount',
26430
+ type: 'string',
26431
+ required: true
26432
+ }, {
26433
+ name: 'owners',
26434
+ type: 'array',
26435
+ required: true
26436
+ }, {
26437
+ name: 'relays',
26438
+ type: 'array',
26439
+ required: true,
26440
+ allowEmpty: true
26441
+ }, {
26442
+ name: 'metadata',
26443
+ type: 'object'
26444
+ }]);
26445
+ validatePoolMargin(poolParameters.margin);
26446
+ validatePoolOwners(poolParameters.owners);
26447
+ poolParameters.relays.forEach(validatePoolRelay);
26448
+
26449
+ if (poolParameters.metadata) {
26450
+ validatePoolMetadata(poolParameters.metadata);
26451
+ }
26452
+ };
26453
+
26454
+ const transformPoolParameters = poolParameters => {
26455
+ if (!poolParameters) {
26456
+ return {
26457
+ poolParameters: undefined,
26458
+ poolOwners: [],
26459
+ poolRelays: []
26460
+ };
26461
+ }
26462
+
26463
+ validatePoolParameters(poolParameters);
26464
+ return {
26465
+ poolParameters: {
26466
+ pool_id: poolParameters.poolId,
26467
+ vrf_key_hash: poolParameters.vrfKeyHash,
26468
+ pledge: poolParameters.pledge,
26469
+ cost: poolParameters.cost,
26470
+ margin_numerator: poolParameters.margin.numerator,
26471
+ margin_denominator: poolParameters.margin.denominator,
26472
+ reward_account: poolParameters.rewardAccount,
26473
+ metadata: poolParameters.metadata,
26474
+ owners_count: poolParameters.owners.length,
26475
+ relays_count: poolParameters.relays.length
26476
+ },
26477
+ poolOwners: poolParameters.owners.map(owner => ({
26478
+ staking_key_hash: owner.stakingKeyHash,
26479
+ staking_key_path: owner.stakingKeyPath ? validatePath(owner.stakingKeyPath, 5) : undefined
26480
+ })),
26481
+ poolRelays: poolParameters.relays.map(relay => ({
26482
+ type: relay.type,
26483
+ ipv4_address: relay.ipv4Address ? ipv4AddressToHex(relay.ipv4Address) : undefined,
26484
+ ipv6_address: relay.ipv6Address ? ipv6AddressToHex(relay.ipv6Address) : undefined,
26485
+ host_name: relay.hostName,
26486
+ port: relay.port
26487
+ }))
26488
+ };
26489
+ };
26490
+
26491
+ const transformCertificate = certificate => {
26492
+ const paramsToValidate = [{
26493
+ name: 'type',
26494
+ type: 'number',
26495
+ required: true
26496
+ }];
26497
+
26498
+ if (certificate.type !== hdTransport.Messages.CardanoCertificateType.STAKE_POOL_REGISTRATION) {
26499
+ paramsToValidate.push({
26500
+ name: 'scriptHash',
26501
+ type: 'string'
26502
+ });
26503
+ paramsToValidate.push({
26504
+ name: 'keyHash',
26505
+ type: 'string'
26506
+ });
26507
+ }
26508
+
26509
+ if (certificate.type === hdTransport.Messages.CardanoCertificateType.STAKE_DELEGATION) {
26510
+ paramsToValidate.push({
26511
+ name: 'pool',
26512
+ type: 'string',
26513
+ required: true
26514
+ });
26515
+ }
26516
+
26517
+ if (certificate.type === hdTransport.Messages.CardanoCertificateType.STAKE_POOL_REGISTRATION) {
26518
+ paramsToValidate.push({
26519
+ name: 'poolParameters',
26520
+ type: 'object',
26521
+ required: true
26522
+ });
26523
+ }
26524
+
26525
+ validateParams(certificate, paramsToValidate);
26526
+ const {
26527
+ poolParameters,
26528
+ poolOwners,
26529
+ poolRelays
26530
+ } = transformPoolParameters(certificate.poolParameters);
26531
+ return {
26532
+ certificate: {
26533
+ type: certificate.type,
26534
+ path: certificate.path ? validatePath(certificate.path, 5) : undefined,
26535
+ script_hash: certificate.scriptHash,
26536
+ key_hash: certificate.keyHash,
26537
+ pool: certificate.pool,
26538
+ pool_parameters: poolParameters
26539
+ },
26540
+ poolOwners,
26541
+ poolRelays
26542
+ };
26543
+ };
26544
+
26545
+ const transformCatalystRegistrationParameters = catalystRegistrationParameters => {
26546
+ validateParams(catalystRegistrationParameters, [{
26547
+ name: 'votingPublicKey',
26548
+ type: 'string',
26549
+ required: true
26550
+ }, {
26551
+ name: 'stakingPath',
26552
+ required: true
26553
+ }, {
26554
+ name: 'nonce',
26555
+ type: 'uint',
26556
+ required: true
26557
+ }]);
26558
+ validateAddressParameters(catalystRegistrationParameters.rewardAddressParameters);
26559
+ return {
26560
+ voting_public_key: catalystRegistrationParameters.votingPublicKey,
26561
+ staking_path: validatePath(catalystRegistrationParameters.stakingPath, 3),
26562
+ reward_address_parameters: addressParametersToProto(catalystRegistrationParameters.rewardAddressParameters),
26563
+ nonce: catalystRegistrationParameters.nonce
26564
+ };
26565
+ };
26566
+
26567
+ const transformAuxiliaryData = auxiliaryData => {
26568
+ validateParams(auxiliaryData, [{
26569
+ name: 'hash',
26570
+ type: 'string'
26571
+ }]);
26572
+ let catalystRegistrationParameters;
26573
+
26574
+ if (auxiliaryData.catalystRegistrationParameters) {
26575
+ catalystRegistrationParameters = transformCatalystRegistrationParameters(auxiliaryData.catalystRegistrationParameters);
26576
+ }
26577
+
26578
+ return {
26579
+ hash: auxiliaryData.hash,
26580
+ catalyst_registration_parameters: catalystRegistrationParameters
26581
+ };
26582
+ };
26583
+
26584
+ const modifyAuxiliaryDataForBackwardsCompatibility = auxiliary_data => {
26585
+ const {
26586
+ catalyst_registration_parameters
26587
+ } = auxiliary_data;
26588
+
26589
+ if (catalyst_registration_parameters) {
26590
+ catalyst_registration_parameters.reward_address_parameters = modifyAddressParametersForBackwardsCompatibility(catalyst_registration_parameters.reward_address_parameters);
26591
+ return Object.assign(Object.assign({}, auxiliary_data), {
26592
+ catalyst_registration_parameters
26593
+ });
26594
+ }
26595
+
26596
+ return auxiliary_data;
26597
+ };
26598
+
26599
+ const gatherWitnessPaths = (inputsWithPath, certificatesWithPoolOwnersAndRelays, withdrawals, collateralInputsWithPath, requiredSigners, additionalWitnessRequests, signingMode) => {
26600
+ const witnessPaths = new Map();
26601
+
26602
+ function _insert(path) {
26603
+ const pathKey = JSON.stringify(path);
26604
+ witnessPaths.set(pathKey, path);
26605
+ }
26606
+
26607
+ if (signingMode !== hdTransport.Messages.CardanoTxSigningMode.MULTISIG_TRANSACTION) {
26608
+ inputsWithPath.forEach(({
26609
+ path
26610
+ }) => {
26611
+ if (path) _insert(path);
26612
+ });
26613
+ certificatesWithPoolOwnersAndRelays.forEach(({
26614
+ certificate,
26615
+ poolOwners
26616
+ }) => {
26617
+ if (certificate.path && (certificate.type === hdTransport.Messages.CardanoCertificateType.STAKE_DELEGATION || certificate.type === hdTransport.Messages.CardanoCertificateType.STAKE_DEREGISTRATION)) {
26618
+ _insert(certificate.path);
26619
+ }
26620
+
26621
+ poolOwners.forEach(poolOwner => {
26622
+ if (poolOwner.staking_key_path) _insert(poolOwner.staking_key_path);
26623
+ });
26624
+ });
26625
+ withdrawals.forEach(({
26626
+ path
26627
+ }) => {
26628
+ if (path) _insert(path);
26629
+ });
26630
+ }
26631
+
26632
+ if (signingMode === hdTransport.Messages.CardanoTxSigningMode.PLUTUS_TRANSACTION) {
26633
+ collateralInputsWithPath.forEach(({
26634
+ path
26635
+ }) => {
26636
+ if (path) _insert(path);
26637
+ });
26638
+ }
26639
+
26640
+ requiredSigners.forEach(({
26641
+ key_path
26642
+ }) => {
26643
+ if (key_path) _insert(key_path);
26644
+ });
26645
+ additionalWitnessRequests.forEach(path => {
26646
+ _insert(path);
26647
+ });
26648
+ return Array.from(witnessPaths.values());
26649
+ };
26650
+
26651
+ class CardanoSignTransaction extends BaseMethod {
26652
+ init() {
26653
+ var _a;
26654
+
26655
+ this.checkDeviceId = true;
26656
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
26657
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
26658
+ const {
26659
+ payload
26660
+ } = this;
26661
+ validateParams(payload, [{
26662
+ name: 'signingMode',
26663
+ type: 'number',
26664
+ required: true
26665
+ }, {
26666
+ name: 'inputs',
26667
+ type: 'array',
26668
+ required: true
26669
+ }, {
26670
+ name: 'outputs',
26671
+ type: 'array',
26672
+ required: true,
26673
+ allowEmpty: true
26674
+ }, {
26675
+ name: 'fee',
26676
+ type: 'uint',
26677
+ required: true
26678
+ }, {
26679
+ name: 'ttl',
26680
+ type: 'uint'
26681
+ }, {
26682
+ name: 'certificates',
26683
+ type: 'array',
26684
+ allowEmpty: true
26685
+ }, {
26686
+ name: 'withdrawals',
26687
+ type: 'array',
26688
+ allowEmpty: true
26689
+ }, {
26690
+ name: 'mint',
26691
+ type: 'array',
26692
+ allowEmpty: true
26693
+ }, {
26694
+ name: 'validityIntervalStart',
26695
+ type: 'uint'
26696
+ }, {
26697
+ name: 'scriptDataHash',
26698
+ type: 'string'
26699
+ }, {
26700
+ name: 'collateralInputs',
26701
+ type: 'array',
26702
+ allowEmpty: true
26703
+ }, {
26704
+ name: 'requiredSigners',
26705
+ type: 'array',
26706
+ allowEmpty: true
26707
+ }, {
26708
+ name: 'totalCollateral',
26709
+ type: 'uint'
26710
+ }, {
26711
+ name: 'referenceInputs',
26712
+ type: 'array',
26713
+ allowEmpty: true
26714
+ }, {
26715
+ name: 'protocolMagic',
26716
+ type: 'number',
26717
+ required: true
26718
+ }, {
26719
+ name: 'networkId',
26720
+ type: 'number',
26721
+ required: true
26722
+ }, {
26723
+ name: 'additionalWitnessRequests',
26724
+ type: 'array',
26725
+ allowEmpty: true
26726
+ }, {
26727
+ name: 'derivationType',
26728
+ type: 'number'
26729
+ }, {
26730
+ name: 'includeNetworkId',
26731
+ type: 'boolean'
26732
+ }]);
26733
+ const inputsWithPath = payload.inputs.map(transformInput);
26734
+ const outputsWithData = payload.outputs.map(transformOutput);
26735
+ let certificatesWithPoolOwnersAndRelays = [];
26736
+
26737
+ if (payload.certificates) {
26738
+ certificatesWithPoolOwnersAndRelays = payload.certificates.map(transformCertificate);
26739
+ }
26740
+
26741
+ let withdrawals = [];
26742
+
26743
+ if (payload.withdrawals) {
26744
+ withdrawals = payload.withdrawals.map(withdrawal => {
26745
+ validateParams(withdrawal, [{
26746
+ name: 'amount',
26747
+ type: 'uint',
26748
+ required: true
26749
+ }, {
26750
+ name: 'scriptHash',
26751
+ type: 'string'
26752
+ }, {
26753
+ name: 'keyHash',
26754
+ type: 'string'
26755
+ }]);
26756
+ return {
26757
+ path: withdrawal.path ? validatePath(withdrawal.path, 5) : undefined,
26758
+ amount: withdrawal.amount,
26759
+ script_hash: withdrawal.scriptHash,
26760
+ key_hash: withdrawal.keyHash
26761
+ };
26762
+ });
26763
+ }
26764
+
26765
+ let mint = [];
26766
+
26767
+ if (payload.mint) {
26768
+ mint = tokenBundleToProto(payload.mint);
26769
+ }
26770
+
26771
+ let auxiliaryData;
26772
+
26773
+ if (payload.auxiliaryData) {
26774
+ auxiliaryData = transformAuxiliaryData(payload.auxiliaryData);
26775
+ }
26776
+
26777
+ let additionalWitnessRequests = [];
26778
+
26779
+ if (payload.additionalWitnessRequests) {
26780
+ additionalWitnessRequests = payload.additionalWitnessRequests.map(witnessRequest => validatePath(witnessRequest, 3));
26781
+ }
26782
+
26783
+ let collateralInputsWithPath = [];
26784
+
26785
+ if (payload.collateralInputs) {
26786
+ collateralInputsWithPath = payload.collateralInputs.map(transformCollateralInput);
26787
+ }
26788
+
26789
+ let requiredSigners = [];
26790
+
26791
+ if (payload.requiredSigners) {
26792
+ requiredSigners = payload.requiredSigners.map(requiredSigner => {
26793
+ validateParams(requiredSigner, [{
26794
+ name: 'keyHash',
26795
+ type: 'string'
26796
+ }]);
26797
+ return {
26798
+ key_path: requiredSigner.keyPath ? validatePath(requiredSigner.keyPath, 3) : undefined,
26799
+ key_hash: requiredSigner.keyHash
26800
+ };
26801
+ });
26802
+ }
26803
+
26804
+ const collateralReturnWithData = payload.collateralReturn ? transformOutput(payload.collateralReturn) : undefined;
26805
+ let referenceInputs = [];
26806
+
26807
+ if (payload.referenceInputs) {
26808
+ referenceInputs = payload.referenceInputs.map(transformReferenceInput);
26809
+ }
26810
+
26811
+ this.params = {
26812
+ signingMode: payload.signingMode,
26813
+ inputsWithPath,
26814
+ outputsWithData,
26815
+ fee: payload.fee,
26816
+ ttl: payload.ttl,
26817
+ certificatesWithPoolOwnersAndRelays,
26818
+ withdrawals,
26819
+ mint,
26820
+ auxiliaryData,
26821
+ validityIntervalStart: payload.validityIntervalStart,
26822
+ scriptDataHash: payload.scriptDataHash,
26823
+ collateralInputsWithPath,
26824
+ requiredSigners,
26825
+ collateralReturnWithData,
26826
+ totalCollateral: payload.totalCollateral,
26827
+ referenceInputs,
26828
+ protocolMagic: payload.protocolMagic,
26829
+ networkId: payload.networkId,
26830
+ witnessPaths: gatherWitnessPaths(inputsWithPath, certificatesWithPoolOwnersAndRelays, withdrawals, collateralInputsWithPath, requiredSigners, additionalWitnessRequests, payload.signingMode),
26831
+ additionalWitnessRequests,
26832
+ derivationType: typeof payload.derivationType !== 'undefined' ? payload.derivationType : hdTransport.Messages.CardanoDerivationType.ICARUS_TREZOR,
26833
+ includeNetworkId: payload.includeNetworkId
26834
+ };
26835
+ }
26836
+
26837
+ signTx() {
26838
+ return __awaiter(this, void 0, void 0, function* () {
26839
+ const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
26840
+ const hasAuxiliaryData = !!this.params.auxiliaryData;
26841
+ const signTxInitMessage = {
26842
+ signing_mode: this.params.signingMode,
26843
+ protocol_magic: this.params.protocolMagic,
26844
+ network_id: this.params.networkId,
26845
+ inputs_count: this.params.inputsWithPath.length,
26846
+ outputs_count: this.params.outputsWithData.length,
26847
+ fee: this.params.fee,
26848
+ ttl: this.params.ttl,
26849
+ certificates_count: this.params.certificatesWithPoolOwnersAndRelays.length,
26850
+ withdrawals_count: this.params.withdrawals.length,
26851
+ has_auxiliary_data: hasAuxiliaryData,
26852
+ validity_interval_start: this.params.validityIntervalStart,
26853
+ witness_requests_count: this.params.witnessPaths.length,
26854
+ minting_asset_groups_count: this.params.mint.length,
26855
+ script_data_hash: this.params.scriptDataHash,
26856
+ collateral_inputs_count: this.params.collateralInputsWithPath.length,
26857
+ required_signers_count: this.params.requiredSigners.length,
26858
+ has_collateral_return: this.params.collateralReturnWithData != null,
26859
+ total_collateral: this.params.totalCollateral,
26860
+ reference_inputs_count: this.params.referenceInputs.length,
26861
+ derivation_type: this.params.derivationType,
26862
+ include_network_id: this.params.includeNetworkId
26863
+ };
26864
+ yield typedCall('CardanoSignTxInit', 'CardanoTxItemAck', signTxInitMessage);
26865
+
26866
+ for (const {
26867
+ input
26868
+ } of this.params.inputsWithPath) {
26869
+ yield typedCall('CardanoTxInput', 'CardanoTxItemAck', input);
26870
+ }
26871
+
26872
+ for (const outputWithData of this.params.outputsWithData) {
26873
+ yield sendOutput(typedCall, outputWithData);
26874
+ }
26875
+
26876
+ for (const {
26877
+ certificate,
26878
+ poolOwners,
26879
+ poolRelays
26880
+ } of this.params.certificatesWithPoolOwnersAndRelays) {
26881
+ yield typedCall('CardanoTxCertificate', 'CardanoTxItemAck', certificate);
26882
+
26883
+ for (const poolOwner of poolOwners) {
26884
+ yield typedCall('CardanoPoolOwner', 'CardanoTxItemAck', poolOwner);
26885
+ }
26886
+
26887
+ for (const poolRelay of poolRelays) {
26888
+ yield typedCall('CardanoPoolRelayParameters', 'CardanoTxItemAck', poolRelay);
26889
+ }
26890
+ }
26891
+
26892
+ for (const withdrawal of this.params.withdrawals) {
26893
+ yield typedCall('CardanoTxWithdrawal', 'CardanoTxItemAck', withdrawal);
26894
+ }
26895
+
26896
+ let auxiliaryDataSupplement;
26897
+
26898
+ if (this.params.auxiliaryData) {
26899
+ const {
26900
+ catalyst_registration_parameters
26901
+ } = this.params.auxiliaryData;
26902
+
26903
+ if (catalyst_registration_parameters) {
26904
+ this.params.auxiliaryData = modifyAuxiliaryDataForBackwardsCompatibility(this.params.auxiliaryData);
26905
+ }
26906
+
26907
+ const {
26908
+ message
26909
+ } = yield typedCall('CardanoTxAuxiliaryData', 'CardanoTxAuxiliaryDataSupplement', this.params.auxiliaryData);
26910
+ const auxiliaryDataType = hdTransport.Messages.CardanoTxAuxiliaryDataSupplementType[message.type];
26911
+
26912
+ if (auxiliaryDataType !== hdTransport.Messages.CardanoTxAuxiliaryDataSupplementType.NONE) {
26913
+ auxiliaryDataSupplement = {
26914
+ type: auxiliaryDataType,
26915
+ auxiliaryDataHash: message.auxiliary_data_hash,
26916
+ catalystSignature: message.catalyst_signature
26917
+ };
26918
+ }
26919
+
26920
+ yield typedCall('CardanoTxHostAck', 'CardanoTxItemAck');
26921
+ }
26922
+
26923
+ if (this.params.mint.length > 0) {
26924
+ yield typedCall('CardanoTxMint', 'CardanoTxItemAck', {
26925
+ asset_groups_count: this.params.mint.length
26926
+ });
26927
+
26928
+ for (const assetGroup of this.params.mint) {
26929
+ yield typedCall('CardanoAssetGroup', 'CardanoTxItemAck', {
26930
+ policy_id: assetGroup.policyId,
26931
+ tokens_count: assetGroup.tokens.length
26932
+ });
26933
+
26934
+ for (const token of assetGroup.tokens) {
26935
+ yield typedCall('CardanoToken', 'CardanoTxItemAck', token);
26936
+ }
26937
+ }
26938
+ }
26939
+
26940
+ for (const {
26941
+ collateralInput
26942
+ } of this.params.collateralInputsWithPath) {
26943
+ yield typedCall('CardanoTxCollateralInput', 'CardanoTxItemAck', collateralInput);
26944
+ }
26945
+
26946
+ for (const requiredSigner of this.params.requiredSigners) {
26947
+ yield typedCall('CardanoTxRequiredSigner', 'CardanoTxItemAck', requiredSigner);
26948
+ }
26949
+
26950
+ if (this.params.collateralReturnWithData) {
26951
+ yield sendOutput(typedCall, this.params.collateralReturnWithData);
26952
+ }
26953
+
26954
+ for (const referenceInput of this.params.referenceInputs) {
26955
+ yield typedCall('CardanoTxReferenceInput', 'CardanoTxItemAck', referenceInput);
26956
+ }
26957
+
26958
+ const witnesses = [];
26959
+
26960
+ for (const path of this.params.witnessPaths) {
26961
+ const {
26962
+ message
26963
+ } = yield typedCall('CardanoTxWitnessRequest', 'CardanoTxWitnessResponse', {
26964
+ path
26965
+ });
26966
+ witnesses.push({
26967
+ type: hdTransport.Messages.CardanoTxWitnessType[message.type],
26968
+ pubKey: message.pub_key,
26969
+ signature: message.signature,
26970
+ chainCode: message.chain_code
26971
+ });
26972
+ }
26973
+
26974
+ const {
26975
+ message: txBodyHashMessage
26976
+ } = yield typedCall('CardanoTxHostAck', 'CardanoTxBodyHash');
26977
+ yield typedCall('CardanoTxHostAck', 'CardanoSignTxFinished');
26978
+ return {
26979
+ hash: txBodyHashMessage.tx_hash,
26980
+ witnesses,
26981
+ auxiliaryDataSupplement
26982
+ };
26983
+ });
26984
+ }
26985
+
26986
+ run() {
26987
+ return this.signTx();
26988
+ }
26989
+
26990
+ }
26991
+
25733
26992
  var ApiMethods = /*#__PURE__*/Object.freeze({
25734
26993
  __proto__: null,
25735
26994
  searchDevices: SearchDevices,
@@ -25802,7 +27061,10 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
25802
27061
  xrpSignTransaction: XrpGetAddress,
25803
27062
  suiGetAddress: SuiGetAddress,
25804
27063
  suiGetPublicKey: SuiGetPublicKey,
25805
- suiSignTransaction: SuiSignTransaction
27064
+ suiSignTransaction: SuiSignTransaction,
27065
+ cardanoGetAddress: CardanoGetAddress,
27066
+ cardanoGetPublicKey: CardanoGetPublicKey,
27067
+ cardanoSignTransaction: CardanoSignTransaction
25806
27068
  });
25807
27069
 
25808
27070
  function findMethod(message) {
@@ -25823,18 +27085,6 @@ function findMethod(message) {
25823
27085
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Method ${method} is not set`);
25824
27086
  }
25825
27087
 
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
27088
  const resolveAfter = (msec, value) => new Promise(resolve => {
25839
27089
  setTimeout(resolve, msec, value);
25840
27090
  });
@@ -25954,7 +27204,8 @@ const Log = getLogger(exports.d0.Core);
25954
27204
  const parseInitOptions = method => ({
25955
27205
  initSession: method === null || method === void 0 ? void 0 : method.payload.initSession,
25956
27206
  passphraseState: method === null || method === void 0 ? void 0 : method.payload.passphraseState,
25957
- deviceId: method === null || method === void 0 ? void 0 : method.payload.deviceId
27207
+ deviceId: method === null || method === void 0 ? void 0 : method.payload.deviceId,
27208
+ deriveCardano: method === null || method === void 0 ? void 0 : method.name.startsWith('cardano')
25958
27209
  });
25959
27210
 
25960
27211
  let _core;
@@ -72173,7 +73424,7 @@ module.exports = {"i8":"6.5.4"};
72173
73424
  /***/ ((module) => {
72174
73425
 
72175
73426
  "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"}}');
73427
+ module.exports = JSON.parse('{"name":"@onekeyfe/hd-core","version":"0.2.10","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.10","@onekeyfe/hd-transport":"^0.2.10","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
73428
 
72178
73429
  /***/ })
72179
73430
 
@@ -74712,7 +75963,7 @@ const src_init = async settings => {
74712
75963
 
74713
75964
  try {
74714
75965
  await init({ ..._settings,
74715
- version: "0.2.8"
75966
+ version: "0.2.10"
74716
75967
  });
74717
75968
  return true;
74718
75969
  } catch (e) {