@meshsdk/core-cst 1.9.0-beta.7 → 1.9.0-beta.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.
package/dist/index.cjs CHANGED
@@ -3683,7 +3683,9 @@ var import_util = require("@cardano-sdk/util");
3683
3683
  var Slot = import_core.Cardano.Slot;
3684
3684
  var Value = import_core.Serialization.Value;
3685
3685
  var Transaction = import_core.Serialization.Transaction;
3686
- var TransactionId = import_core.Cardano.TransactionId;
3686
+ var TransactionId = (value) => {
3687
+ return import_core.Cardano.TransactionId(value);
3688
+ };
3687
3689
  var TransactionBody = import_core.Serialization.TransactionBody;
3688
3690
  var TransactionWitnessSet = import_core.Serialization.TransactionWitnessSet;
3689
3691
  var AuxilliaryData = import_core.Serialization.AuxiliaryData;
@@ -3719,7 +3721,9 @@ var Ed25519PrivateExtendedKeyHex = (value) => (0, import_util.typedHex)(value, 1
3719
3721
  var Ed25519KeyHash2 = Crypto.Ed25519KeyHash;
3720
3722
  var Ed25519KeyHashHex2 = Crypto.Ed25519KeyHashHex;
3721
3723
  var Hash28ByteBase162 = Crypto.Hash28ByteBase16;
3722
- var Hash32ByteBase162 = Crypto.Hash32ByteBase16;
3724
+ var Hash32ByteBase162 = (value) => {
3725
+ return Crypto.Hash32ByteBase16(value);
3726
+ };
3723
3727
  var CredentialType = import_core.Cardano.CredentialType;
3724
3728
  var Certificate = import_core.Serialization.Certificate;
3725
3729
  var PoolId = import_core.Cardano.PoolId;
@@ -3749,7 +3753,9 @@ var CborWriter = import_core.Serialization.CborWriter;
3749
3753
  var ConstrPlutusData = import_core.Serialization.ConstrPlutusData;
3750
3754
  var RewardAccount = import_core.Cardano.RewardAccount;
3751
3755
  var Hash = import_core.Serialization.Hash;
3752
- var DatumHash = Crypto.Hash32ByteBase16;
3756
+ var DatumHash = (value) => {
3757
+ return Crypto.Hash32ByteBase16(value);
3758
+ };
3753
3759
  var Datum = import_core.Serialization.Datum;
3754
3760
  var ExUnits = import_core.Serialization.ExUnits;
3755
3761
  var NetworkId = import_core.Cardano.NetworkId;
@@ -4415,7 +4421,7 @@ var parseInlineDatum = (utxo) => {
4415
4421
  const datumCbor = utxo.inline_datum || "";
4416
4422
  return datumCborToJson(datumCbor);
4417
4423
  };
4418
- var deserializeDataHash = (dataHash) => DatumHash.fromHexBlob((0, import_util3.HexBlob)(dataHash));
4424
+ var deserializeDataHash = (dataHash) => DatumHash(dataHash);
4419
4425
  var deserializePlutusData = (plutusData) => PlutusData.fromCbor((0, import_util3.HexBlob)(plutusData));
4420
4426
 
4421
4427
  // src/utils/deserializer.ts
@@ -4442,7 +4448,7 @@ var deserializeScriptRef = (scriptRef) => Script.fromCbor((0, import_util4.HexBl
4442
4448
  var deserializeTxUnspentOutput = (txUnspentOutput) => TransactionUnspentOutput.fromCbor((0, import_util4.HexBlob)(txUnspentOutput));
4443
4449
  var deserializeValue = (value) => Value.fromCbor((0, import_util4.HexBlob)(value));
4444
4450
  var deserializeTx = (tx) => Transaction.fromCbor(import_core2.Serialization.TxCBOR(tx));
4445
- var deserializeTxHash = (txHash) => TransactionId.fromHexBlob((0, import_util4.HexBlob)(txHash));
4451
+ var deserializeTxHash = (txHash) => TransactionId(txHash);
4446
4452
 
4447
4453
  // src/utils/converter.ts
4448
4454
  var toAddress = (bech325) => Address.fromBech32(bech325);
@@ -5784,6 +5790,7 @@ var CardanoSDKSerializer = class {
5784
5790
  verbose;
5785
5791
  protocolParams;
5786
5792
  constructor(protocolParams, verbose = false) {
5793
+ (0, import_core7.setInConwayEra)(true);
5787
5794
  this.protocolParams = protocolParams || import_common8.DEFAULT_PROTOCOL_PARAMETERS;
5788
5795
  this.verbose = verbose;
5789
5796
  }
@@ -6285,9 +6292,7 @@ var CardanoSDKSerializerCore = class {
6285
6292
  if (output.datum?.type === "Hash") {
6286
6293
  cardanoOutput.setDatum(
6287
6294
  Datum.newDataHash(
6288
- DatumHash.fromHexBlob(
6289
- (0, import_util9.HexBlob)(fromBuilderToPlutusData(output.datum.data).hash())
6290
- )
6295
+ DatumHash(fromBuilderToPlutusData(output.datum.data).hash())
6291
6296
  )
6292
6297
  );
6293
6298
  } else if (output.datum?.type === "Inline") {
@@ -6343,7 +6348,7 @@ var CardanoSDKSerializerCore = class {
6343
6348
  let referenceInputsList = [...referenceInputs.values()];
6344
6349
  referenceInputsList.push(
6345
6350
  new TransactionInput(
6346
- TransactionId.fromHexBlob((0, import_util9.HexBlob)(refInput.txHash)),
6351
+ TransactionId(refInput.txHash),
6347
6352
  BigInt(refInput.txIndex)
6348
6353
  )
6349
6354
  );
@@ -6859,7 +6864,7 @@ var CardanoSDKSerializerCore = class {
6859
6864
  toCardanoAddress(changeAddress),
6860
6865
  remainingValue
6861
6866
  );
6862
- let minUtxoValue = (160 + dummyChangeOutput.toCbor().length / 2 + 1) * this.protocolParams.coinsPerUtxoSize;
6867
+ currentOutputs.push(dummyChangeOutput);
6863
6868
  this.txBody.setFee(BigInt("10000000"));
6864
6869
  const numberOfRequiredWitnesses = this.countNumberOfRequiredWitnesses();
6865
6870
  const dummyTx = this.createDummyTx(numberOfRequiredWitnesses);
@@ -6872,18 +6877,21 @@ var CardanoSDKSerializerCore = class {
6872
6877
  dummyTx,
6873
6878
  this.refScriptSize
6874
6879
  );
6875
- if (remainingValue.coin() >= fee + BigInt(minUtxoValue)) {
6876
- dummyChangeOutput.amount().setCoin(dummyChangeOutput.amount().coin() - fee);
6877
- currentOutputs.push(dummyChangeOutput);
6878
- this.txBody.setOutputs(currentOutputs);
6879
- remainingValue = new Value(BigInt(0));
6880
- } else if (remainingValue.coin() >= fee) {
6880
+ let minUtxoValue = (160 + dummyChangeOutput.toCbor().length / 2 + 1) * this.protocolParams.coinsPerUtxoSize;
6881
+ if (remainingValue.coin() <= fee + BigInt(minUtxoValue)) {
6881
6882
  if (remainingValue.multiasset() && remainingValue.multiasset().size > 0) {
6882
6883
  throw new Error(
6883
6884
  "Insufficient funds to create change output with tokens"
6884
6885
  );
6885
6886
  } else {
6886
6887
  fee = remainingValue.coin();
6888
+ currentOutputs.pop();
6889
+ }
6890
+ } else {
6891
+ const changeOutput = currentOutputs.pop();
6892
+ if (changeOutput) {
6893
+ changeOutput.amount().setCoin(changeOutput.amount().coin() - fee);
6894
+ currentOutputs.push(changeOutput);
6887
6895
  }
6888
6896
  }
6889
6897
  this.txBody.setFee(fee);
package/dist/index.d.cts CHANGED
@@ -2,7 +2,7 @@ import { Cardano, Serialization } from '@cardano-sdk/core';
2
2
  import * as core from '@cardano-sdk/core';
3
3
  export { core as CardanoSDK };
4
4
  export { Cardano, Serialization } from '@cardano-sdk/core';
5
- import { HexBlob as HexBlob$1, OpaqueString } from '@cardano-sdk/util';
5
+ import { OpaqueString, HexBlob as HexBlob$1 } from '@cardano-sdk/util';
6
6
  import * as util from '@cardano-sdk/util';
7
7
  export { util as CardanoSDKUtil };
8
8
  import * as Crypto from '@cardano-sdk/crypto';
@@ -18,10 +18,7 @@ type Value = Serialization.Value;
18
18
  type TokenMap = Cardano.TokenMap;
19
19
  declare const Transaction: typeof Serialization.Transaction;
20
20
  type Transaction = Serialization.Transaction;
21
- declare const TransactionId: {
22
- (value: string): Cardano.TransactionId;
23
- fromHexBlob(value: HexBlob$1): Cardano.TransactionId;
24
- };
21
+ declare const TransactionId: (value: string) => Cardano.TransactionId;
25
22
  type TransactionId = Cardano.TransactionId;
26
23
  declare const TransactionBody: typeof Serialization.TransactionBody;
27
24
  type TransactionBody = Serialization.TransactionBody;
@@ -113,10 +110,7 @@ declare const Hash28ByteBase16: {
113
110
  fromEd25519KeyHashHex(value: Crypto.Ed25519KeyHashHex): Crypto.Hash28ByteBase16;
114
111
  };
115
112
  type Hash28ByteBase16 = Crypto.Hash28ByteBase16;
116
- declare const Hash32ByteBase16: {
117
- (value: string): Crypto.Hash32ByteBase16;
118
- fromHexBlob<T>(value: HexBlob$1): T;
119
- };
113
+ declare const Hash32ByteBase16: (value: string) => Crypto.Hash32ByteBase16;
120
114
  type Hash32ByteBase16 = Crypto.Hash32ByteBase16;
121
115
  declare const CredentialType: typeof Cardano.CredentialType;
122
116
  type CredentialType = Cardano.CredentialType;
@@ -186,10 +180,7 @@ declare const RewardAccount: {
186
180
  type RewardAccount = Cardano.RewardAccount;
187
181
  declare const Hash: typeof Serialization.Hash;
188
182
  type Hash<T extends string> = Serialization.Hash<T>;
189
- declare const DatumHash: {
190
- (value: string): Crypto.Hash32ByteBase16;
191
- fromHexBlob<T>(value: HexBlob$1): T;
192
- };
183
+ declare const DatumHash: (value: string) => Crypto.Hash32ByteBase16;
193
184
  type DatumHash = Crypto.Hash32ByteBase16;
194
185
  declare const Datum: typeof Serialization.Datum;
195
186
  type Datum = PlutusData | DatumHash;
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { Cardano, Serialization } from '@cardano-sdk/core';
2
2
  import * as core from '@cardano-sdk/core';
3
3
  export { core as CardanoSDK };
4
4
  export { Cardano, Serialization } from '@cardano-sdk/core';
5
- import { HexBlob as HexBlob$1, OpaqueString } from '@cardano-sdk/util';
5
+ import { OpaqueString, HexBlob as HexBlob$1 } from '@cardano-sdk/util';
6
6
  import * as util from '@cardano-sdk/util';
7
7
  export { util as CardanoSDKUtil };
8
8
  import * as Crypto from '@cardano-sdk/crypto';
@@ -18,10 +18,7 @@ type Value = Serialization.Value;
18
18
  type TokenMap = Cardano.TokenMap;
19
19
  declare const Transaction: typeof Serialization.Transaction;
20
20
  type Transaction = Serialization.Transaction;
21
- declare const TransactionId: {
22
- (value: string): Cardano.TransactionId;
23
- fromHexBlob(value: HexBlob$1): Cardano.TransactionId;
24
- };
21
+ declare const TransactionId: (value: string) => Cardano.TransactionId;
25
22
  type TransactionId = Cardano.TransactionId;
26
23
  declare const TransactionBody: typeof Serialization.TransactionBody;
27
24
  type TransactionBody = Serialization.TransactionBody;
@@ -113,10 +110,7 @@ declare const Hash28ByteBase16: {
113
110
  fromEd25519KeyHashHex(value: Crypto.Ed25519KeyHashHex): Crypto.Hash28ByteBase16;
114
111
  };
115
112
  type Hash28ByteBase16 = Crypto.Hash28ByteBase16;
116
- declare const Hash32ByteBase16: {
117
- (value: string): Crypto.Hash32ByteBase16;
118
- fromHexBlob<T>(value: HexBlob$1): T;
119
- };
113
+ declare const Hash32ByteBase16: (value: string) => Crypto.Hash32ByteBase16;
120
114
  type Hash32ByteBase16 = Crypto.Hash32ByteBase16;
121
115
  declare const CredentialType: typeof Cardano.CredentialType;
122
116
  type CredentialType = Cardano.CredentialType;
@@ -186,10 +180,7 @@ declare const RewardAccount: {
186
180
  type RewardAccount = Cardano.RewardAccount;
187
181
  declare const Hash: typeof Serialization.Hash;
188
182
  type Hash<T extends string> = Serialization.Hash<T>;
189
- declare const DatumHash: {
190
- (value: string): Crypto.Hash32ByteBase16;
191
- fromHexBlob<T>(value: HexBlob$1): T;
192
- };
183
+ declare const DatumHash: (value: string) => Crypto.Hash32ByteBase16;
193
184
  type DatumHash = Crypto.Hash32ByteBase16;
194
185
  declare const Datum: typeof Serialization.Datum;
195
186
  type Datum = PlutusData | DatumHash;
package/dist/index.js CHANGED
@@ -3494,7 +3494,9 @@ import { HexBlob as CardanoHexBlob, typedHex } from "@cardano-sdk/util";
3494
3494
  var Slot = Cardano.Slot;
3495
3495
  var Value = Serialization.Value;
3496
3496
  var Transaction = Serialization.Transaction;
3497
- var TransactionId = Cardano.TransactionId;
3497
+ var TransactionId = (value) => {
3498
+ return Cardano.TransactionId(value);
3499
+ };
3498
3500
  var TransactionBody = Serialization.TransactionBody;
3499
3501
  var TransactionWitnessSet = Serialization.TransactionWitnessSet;
3500
3502
  var AuxilliaryData = Serialization.AuxiliaryData;
@@ -3530,7 +3532,9 @@ var Ed25519PrivateExtendedKeyHex = (value) => typedHex(value, 128);
3530
3532
  var Ed25519KeyHash2 = Crypto.Ed25519KeyHash;
3531
3533
  var Ed25519KeyHashHex2 = Crypto.Ed25519KeyHashHex;
3532
3534
  var Hash28ByteBase162 = Crypto.Hash28ByteBase16;
3533
- var Hash32ByteBase162 = Crypto.Hash32ByteBase16;
3535
+ var Hash32ByteBase162 = (value) => {
3536
+ return Crypto.Hash32ByteBase16(value);
3537
+ };
3534
3538
  var CredentialType = Cardano.CredentialType;
3535
3539
  var Certificate = Serialization.Certificate;
3536
3540
  var PoolId = Cardano.PoolId;
@@ -3560,7 +3564,9 @@ var CborWriter = Serialization.CborWriter;
3560
3564
  var ConstrPlutusData = Serialization.ConstrPlutusData;
3561
3565
  var RewardAccount = Cardano.RewardAccount;
3562
3566
  var Hash = Serialization.Hash;
3563
- var DatumHash = Crypto.Hash32ByteBase16;
3567
+ var DatumHash = (value) => {
3568
+ return Crypto.Hash32ByteBase16(value);
3569
+ };
3564
3570
  var Datum = Serialization.Datum;
3565
3571
  var ExUnits = Serialization.ExUnits;
3566
3572
  var NetworkId = Cardano.NetworkId;
@@ -4249,7 +4255,7 @@ var parseInlineDatum = (utxo) => {
4249
4255
  const datumCbor = utxo.inline_datum || "";
4250
4256
  return datumCborToJson(datumCbor);
4251
4257
  };
4252
- var deserializeDataHash = (dataHash) => DatumHash.fromHexBlob(HexBlob3(dataHash));
4258
+ var deserializeDataHash = (dataHash) => DatumHash(dataHash);
4253
4259
  var deserializePlutusData = (plutusData) => PlutusData.fromCbor(HexBlob3(plutusData));
4254
4260
 
4255
4261
  // src/utils/deserializer.ts
@@ -4276,7 +4282,7 @@ var deserializeScriptRef = (scriptRef) => Script.fromCbor(HexBlob4(scriptRef));
4276
4282
  var deserializeTxUnspentOutput = (txUnspentOutput) => TransactionUnspentOutput.fromCbor(HexBlob4(txUnspentOutput));
4277
4283
  var deserializeValue = (value) => Value.fromCbor(HexBlob4(value));
4278
4284
  var deserializeTx = (tx) => Transaction.fromCbor(Serialization2.TxCBOR(tx));
4279
- var deserializeTxHash = (txHash) => TransactionId.fromHexBlob(HexBlob4(txHash));
4285
+ var deserializeTxHash = (txHash) => TransactionId(txHash);
4280
4286
 
4281
4287
  // src/utils/converter.ts
4282
4288
  var toAddress = (bech325) => Address.fromBech32(bech325);
@@ -5117,7 +5123,7 @@ var resolveEd25519KeyHash = (bech325) => {
5117
5123
  };
5118
5124
 
5119
5125
  // src/serializer/index.ts
5120
- import { Serialization as Serialization6 } from "@cardano-sdk/core";
5126
+ import { Serialization as Serialization6, setInConwayEra } from "@cardano-sdk/core";
5121
5127
  import { HexBlob as HexBlob9 } from "@cardano-sdk/util";
5122
5128
  import {
5123
5129
  Cbor as Cbor2,
@@ -5636,6 +5642,7 @@ var CardanoSDKSerializer = class {
5636
5642
  verbose;
5637
5643
  protocolParams;
5638
5644
  constructor(protocolParams, verbose = false) {
5645
+ setInConwayEra(true);
5639
5646
  this.protocolParams = protocolParams || DEFAULT_PROTOCOL_PARAMETERS;
5640
5647
  this.verbose = verbose;
5641
5648
  }
@@ -6137,9 +6144,7 @@ var CardanoSDKSerializerCore = class {
6137
6144
  if (output.datum?.type === "Hash") {
6138
6145
  cardanoOutput.setDatum(
6139
6146
  Datum.newDataHash(
6140
- DatumHash.fromHexBlob(
6141
- HexBlob9(fromBuilderToPlutusData(output.datum.data).hash())
6142
- )
6147
+ DatumHash(fromBuilderToPlutusData(output.datum.data).hash())
6143
6148
  )
6144
6149
  );
6145
6150
  } else if (output.datum?.type === "Inline") {
@@ -6195,7 +6200,7 @@ var CardanoSDKSerializerCore = class {
6195
6200
  let referenceInputsList = [...referenceInputs.values()];
6196
6201
  referenceInputsList.push(
6197
6202
  new TransactionInput(
6198
- TransactionId.fromHexBlob(HexBlob9(refInput.txHash)),
6203
+ TransactionId(refInput.txHash),
6199
6204
  BigInt(refInput.txIndex)
6200
6205
  )
6201
6206
  );
@@ -6711,7 +6716,7 @@ var CardanoSDKSerializerCore = class {
6711
6716
  toCardanoAddress(changeAddress),
6712
6717
  remainingValue
6713
6718
  );
6714
- let minUtxoValue = (160 + dummyChangeOutput.toCbor().length / 2 + 1) * this.protocolParams.coinsPerUtxoSize;
6719
+ currentOutputs.push(dummyChangeOutput);
6715
6720
  this.txBody.setFee(BigInt("10000000"));
6716
6721
  const numberOfRequiredWitnesses = this.countNumberOfRequiredWitnesses();
6717
6722
  const dummyTx = this.createDummyTx(numberOfRequiredWitnesses);
@@ -6724,18 +6729,21 @@ var CardanoSDKSerializerCore = class {
6724
6729
  dummyTx,
6725
6730
  this.refScriptSize
6726
6731
  );
6727
- if (remainingValue.coin() >= fee + BigInt(minUtxoValue)) {
6728
- dummyChangeOutput.amount().setCoin(dummyChangeOutput.amount().coin() - fee);
6729
- currentOutputs.push(dummyChangeOutput);
6730
- this.txBody.setOutputs(currentOutputs);
6731
- remainingValue = new Value(BigInt(0));
6732
- } else if (remainingValue.coin() >= fee) {
6732
+ let minUtxoValue = (160 + dummyChangeOutput.toCbor().length / 2 + 1) * this.protocolParams.coinsPerUtxoSize;
6733
+ if (remainingValue.coin() <= fee + BigInt(minUtxoValue)) {
6733
6734
  if (remainingValue.multiasset() && remainingValue.multiasset().size > 0) {
6734
6735
  throw new Error(
6735
6736
  "Insufficient funds to create change output with tokens"
6736
6737
  );
6737
6738
  } else {
6738
6739
  fee = remainingValue.coin();
6740
+ currentOutputs.pop();
6741
+ }
6742
+ } else {
6743
+ const changeOutput = currentOutputs.pop();
6744
+ if (changeOutput) {
6745
+ changeOutput.amount().setCoin(changeOutput.amount().coin() - fee);
6746
+ currentOutputs.push(changeOutput);
6739
6747
  }
6740
6748
  }
6741
6749
  this.txBody.setFee(fee);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshsdk/core-cst",
3
- "version": "1.9.0-beta.7",
3
+ "version": "1.9.0-beta.9",
4
4
  "description": "Types and utilities functions between Mesh and cardano-js-sdk",
5
5
  "main": "./dist/index.cjs",
6
6
  "browser": "./dist/index.js",
@@ -45,7 +45,7 @@
45
45
  "@harmoniclabs/pair": "1.0.0",
46
46
  "@harmoniclabs/plutus-data": "1.2.4",
47
47
  "@harmoniclabs/uplc": "1.2.4",
48
- "@meshsdk/common": "1.9.0-beta.7",
48
+ "@meshsdk/common": "1.9.0-beta.9",
49
49
  "@types/base32-encoding": "^1.0.2",
50
50
  "base32-encoding": "^1.0.0",
51
51
  "bech32": "^2.0.0",