@meshsdk/wallet 2.0.0-beta.7 → 2.0.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.
Files changed (3) hide show
  1. package/dist/index.cjs +447 -58
  2. package/dist/index.js +444 -55
  3. package/package.json +9 -13
package/dist/index.cjs CHANGED
@@ -4,6 +4,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
8
  var __commonJS = (cb, mod) => function __require() {
8
9
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
10
  };
@@ -28,6 +29,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
29
  mod
29
30
  ));
30
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
31
33
 
32
34
  // node_modules/@noble/hashes/cryptoNode.js
33
35
  var require_cryptoNode = __commonJS({
@@ -24748,26 +24750,8 @@ var MeshCardanoBrowserWallet = class _MeshCardanoBrowserWallet extends CardanoBr
24748
24750
  // src/cardano/wallet/mesh/cardano-headless-wallet.ts
24749
24751
  var import_core9 = require("@cardano-sdk/core");
24750
24752
 
24751
- // src/cardano/utils/value.ts
24752
- var import_core5 = require("@cardano-sdk/core");
24753
- function mergeValue(a, b) {
24754
- const ma = a.multiasset() ?? /* @__PURE__ */ new Map();
24755
- b.multiasset()?.forEach((v, k) => {
24756
- const newVal = (ma.get(k) ?? 0n) + v;
24757
- if (newVal == 0n) {
24758
- ma.delete(k);
24759
- } else {
24760
- ma.set(k, newVal);
24761
- }
24762
- });
24763
- return new import_core5.Serialization.Value(
24764
- BigInt(a.coin()) + BigInt(b.coin()),
24765
- ma.size > 0 ? ma : void 0
24766
- );
24767
- }
24768
-
24769
24753
  // src/cardano/address/single-address-manager.ts
24770
- var import_core6 = require("@cardano-sdk/core");
24754
+ var import_core5 = require("@cardano-sdk/core");
24771
24755
  var AddressManager = class _AddressManager {
24772
24756
  static async create(config) {
24773
24757
  let paymentSigner;
@@ -24856,7 +24840,7 @@ var AddressManager = class _AddressManager {
24856
24840
  );
24857
24841
  }
24858
24842
  constructor(paymentCredential, stakeCredential, drepCredential, paymentSigner, networkId, stakeSigner, drepSigner) {
24859
- (0, import_core6.setInConwayEra)(true);
24843
+ (0, import_core5.setInConwayEra)(true);
24860
24844
  this.paymentCredential = paymentCredential;
24861
24845
  this.stakeCredential = stakeCredential;
24862
24846
  this.drepCredential = drepCredential;
@@ -24914,7 +24898,7 @@ var AddressManager = class _AddressManager {
24914
24898
  };
24915
24899
 
24916
24900
  // src/cardano/signer/cardano-signer.ts
24917
- var import_core7 = require("@cardano-sdk/core");
24901
+ var import_core6 = require("@cardano-sdk/core");
24918
24902
  var import_crypto5 = require("@cardano-sdk/crypto");
24919
24903
  var import_util5 = require("@cardano-sdk/util");
24920
24904
  var import_cbor2 = require("@harmoniclabs/cbor");
@@ -24924,6 +24908,49 @@ var import_bech32 = __toESM(require_dist(), 1);
24924
24908
  var import_blake2b = __toESM(require_blake2b2(), 1);
24925
24909
  var import_blakejs = __toESM(require_blakejs(), 1);
24926
24910
  var import_bip393 = __toESM(require_src(), 1);
24911
+ var POLICY_ID_LENGTH = 56;
24912
+ var byteString = (bytes) => {
24913
+ if (bytes.length % 2 !== 0) {
24914
+ throw new Error("Invalid hex string - odd length: " + bytes);
24915
+ }
24916
+ if (!/^[0-9a-fA-F]*$/.test(bytes)) {
24917
+ throw new Error("Invalid hex string - non-hex string character: " + bytes);
24918
+ }
24919
+ return {
24920
+ bytes
24921
+ };
24922
+ };
24923
+ var integer = (int) => ({ int });
24924
+ var assocMap = (mapItems, validation = true) => ({
24925
+ map: mapItems.map(([k, v]) => {
24926
+ if (validation) {
24927
+ if (typeof k !== "object" || typeof v !== "object") {
24928
+ throw new Error(
24929
+ `Map item of JSON Cardano data type must be an object - ${k}, ${v}`
24930
+ );
24931
+ }
24932
+ }
24933
+ return { k, v };
24934
+ })
24935
+ });
24936
+ var policyId = (bytes) => {
24937
+ if (bytes.length !== POLICY_ID_LENGTH && bytes !== "") {
24938
+ throw new Error(
24939
+ `Invalid policy id for [${bytes}] - should be ${POLICY_ID_LENGTH / 2} bytes (${POLICY_ID_LENGTH} hex length) long or empty string for lovelace`
24940
+ );
24941
+ }
24942
+ return byteString(bytes);
24943
+ };
24944
+ var currencySymbol = (bytes) => policyId(bytes);
24945
+ var assetName = (bytes) => {
24946
+ if (bytes.length > 64) {
24947
+ throw new Error(
24948
+ `Invalid asset name for [${bytes}] - should be less than 32 bytes (64 hex length) long`
24949
+ );
24950
+ }
24951
+ return byteString(bytes);
24952
+ };
24953
+ var tokenName = (bytes) => assetName(bytes);
24927
24954
  var stringToHex = (str) => Buffer.from(str, "utf8").toString("hex");
24928
24955
  var isHexString = (hex) => /^[0-9A-F]*$/i.test(hex);
24929
24956
  var SLOT_CONFIG_NETWORK = {
@@ -24960,6 +24987,364 @@ var SLOT_CONFIG_NETWORK = {
24960
24987
  epochLength: 0
24961
24988
  }
24962
24989
  };
24990
+ var BigNum = class _BigNum {
24991
+ constructor(value2) {
24992
+ __publicField(this, "value");
24993
+ if (!value2) {
24994
+ this.value = BigInt(0);
24995
+ return;
24996
+ }
24997
+ this.value = BigInt(value2);
24998
+ }
24999
+ static new(value2) {
25000
+ if (!value2) {
25001
+ return new _BigNum(0);
25002
+ }
25003
+ return new _BigNum(value2);
25004
+ }
25005
+ // Operators
25006
+ divFloor(other) {
25007
+ this.value = this.value / other.value;
25008
+ return this;
25009
+ }
25010
+ checkedMul(other) {
25011
+ this.value *= other.value;
25012
+ return this;
25013
+ }
25014
+ checkedAdd(other) {
25015
+ this.value += other.value;
25016
+ return this;
25017
+ }
25018
+ checkedSub(other) {
25019
+ this.value -= other.value;
25020
+ return this;
25021
+ }
25022
+ clampedSub(other) {
25023
+ const result = this.value - other.value;
25024
+ this.value = result < 0n ? 0n : result;
25025
+ return this;
25026
+ }
25027
+ // Comparators
25028
+ lessThan(other) {
25029
+ return this.value < other.value;
25030
+ }
25031
+ compare(other) {
25032
+ if (this.value === other.value) {
25033
+ return 0;
25034
+ } else if (this.value < other.value) {
25035
+ return -1;
25036
+ } else {
25037
+ return 1;
25038
+ }
25039
+ }
25040
+ // Override
25041
+ toString() {
25042
+ return this.value.toString();
25043
+ }
25044
+ };
25045
+ var compareByteOrder = (a, b) => a < b ? -1 : a > b ? 1 : 0;
25046
+ var _a;
25047
+ var MeshValue = (_a = class {
25048
+ constructor(value2 = {}) {
25049
+ __publicField(this, "value");
25050
+ /**
25051
+ * Add an asset to the Value class's value record.
25052
+ * @param asset The asset to add
25053
+ * @returns The updated MeshValue object
25054
+ */
25055
+ __publicField(this, "addAsset", (asset) => {
25056
+ const quantity = BigInt(asset.quantity);
25057
+ const { unit } = asset;
25058
+ if (this.value[unit]) {
25059
+ this.value[unit] += quantity;
25060
+ } else {
25061
+ this.value[unit] = quantity;
25062
+ }
25063
+ return this;
25064
+ });
25065
+ /**
25066
+ * Add an array of assets to the Value class's value record.
25067
+ * @param assets The assets to add
25068
+ * @returns The updated MeshValue object
25069
+ */
25070
+ __publicField(this, "addAssets", (assets) => {
25071
+ assets.forEach((asset) => {
25072
+ this.addAsset(asset);
25073
+ });
25074
+ return this;
25075
+ });
25076
+ /**
25077
+ * Substract an asset from the Value class's value record.
25078
+ * @param asset The asset to subtract
25079
+ * @returns The updated MeshValue object
25080
+ */
25081
+ __publicField(this, "negateAsset", (asset) => {
25082
+ const { unit, quantity: assetQty } = asset;
25083
+ const quantity = BigNum.new(this.value[unit]);
25084
+ quantity.clampedSub(BigNum.new(assetQty));
25085
+ if (quantity.value === BigInt(0)) {
25086
+ delete this.value[unit];
25087
+ } else {
25088
+ this.value[unit] = quantity.value;
25089
+ }
25090
+ return this;
25091
+ });
25092
+ /**
25093
+ * Subtract an array of assets from the Value class's value record.
25094
+ * @param assets The assets to subtract
25095
+ * @returns The updated MeshValue object
25096
+ */
25097
+ __publicField(this, "negateAssets", (assets) => {
25098
+ assets.forEach((asset) => {
25099
+ this.negateAsset(asset);
25100
+ });
25101
+ return this;
25102
+ });
25103
+ /**
25104
+ * Get the quantity of asset object per unit
25105
+ * @param unit The unit to get the quantity of
25106
+ * @returns The quantity of the asset
25107
+ */
25108
+ __publicField(this, "get", (unit) => {
25109
+ return this.value[unit] ? BigInt(this.value[unit]) : BigInt(0);
25110
+ });
25111
+ /**
25112
+ * Get all assets that belong to a specific policy ID
25113
+ * @param policyId The policy ID to filter by
25114
+ * @returns Array of assets that match the policy ID
25115
+ */
25116
+ __publicField(this, "getPolicyAssets", (policyId2) => {
25117
+ const assets = [];
25118
+ Object.entries(this.value).forEach(([unit, quantity]) => {
25119
+ if (unit.startsWith(policyId2)) {
25120
+ assets.push({
25121
+ unit,
25122
+ quantity: quantity.toString()
25123
+ });
25124
+ }
25125
+ });
25126
+ return assets;
25127
+ });
25128
+ /**
25129
+ * Get all asset units
25130
+ * @returns The asset units
25131
+ */
25132
+ __publicField(this, "units", () => {
25133
+ return Object.keys(this.value);
25134
+ });
25135
+ /**
25136
+ * Check if the value is greater than or equal to another value
25137
+ * @param other - The value to compare against
25138
+ * @returns boolean
25139
+ */
25140
+ __publicField(this, "geq", (other) => {
25141
+ return Object.keys(other.value).every((key) => this.geqUnit(key, other));
25142
+ });
25143
+ /**
25144
+ * Check if the specific unit of value is greater than or equal to that unit of another value
25145
+ * @param unit - The unit to compare
25146
+ * @param other - The value to compare against
25147
+ * @returns boolean
25148
+ */
25149
+ __publicField(this, "geqUnit", (unit, other) => {
25150
+ if (this.value[unit] === void 0 || other.value[unit] === void 0) {
25151
+ return false;
25152
+ }
25153
+ return BigInt(this.value[unit]) >= BigInt(other.value[unit]);
25154
+ });
25155
+ /**
25156
+ * Check if the value is less than or equal to another value
25157
+ * @param other - The value to compare against
25158
+ * @returns boolean
25159
+ */
25160
+ __publicField(this, "leq", (other) => {
25161
+ return Object.keys(this.value).every((key) => this.leqUnit(key, other));
25162
+ });
25163
+ /**
25164
+ * Check if the specific unit of value is less than or equal to that unit of another value
25165
+ * @param unit - The unit to compare
25166
+ * @param other - The value to compare against
25167
+ * @returns boolean
25168
+ */
25169
+ __publicField(this, "leqUnit", (unit, other) => {
25170
+ if (this.value[unit] === void 0 || other.value[unit] === void 0) {
25171
+ return false;
25172
+ }
25173
+ return BigInt(this.value[unit]) <= BigInt(other.value[unit]);
25174
+ });
25175
+ /**
25176
+ * Check if the value is equal to another value
25177
+ * @param other - The value to compare against
25178
+ * @returns boolean
25179
+ */
25180
+ __publicField(this, "eq", (other) => {
25181
+ return Object.keys(this.value).every((key) => this.eqUnit(key, other));
25182
+ });
25183
+ /**
25184
+ * Check if the specific unit of value is equal to that unit of another value
25185
+ * @param unit - The unit to compare
25186
+ * @param other - The value to compare against
25187
+ * @returns boolean
25188
+ */
25189
+ __publicField(this, "eqUnit", (unit, other) => {
25190
+ if (this.value[unit] === void 0 || other.value[unit] === void 0) {
25191
+ return false;
25192
+ }
25193
+ return BigInt(this.value[unit]) === BigInt(other.value[unit]);
25194
+ });
25195
+ /**
25196
+ * Check if the value is empty
25197
+ * @returns boolean
25198
+ */
25199
+ __publicField(this, "isEmpty", () => {
25200
+ return Object.keys(this.value).length === 0;
25201
+ });
25202
+ /**
25203
+ * Merge the given values
25204
+ * @param values The other values to merge
25205
+ * @returns this
25206
+ */
25207
+ __publicField(this, "merge", (values) => {
25208
+ const valuesArray = Array.isArray(values) ? values : [values];
25209
+ valuesArray.forEach((other) => {
25210
+ Object.entries(other.value).forEach(([key, value2]) => {
25211
+ this.value[key] = (this.value[key] !== void 0 ? BigInt(this.value[key]) : BigInt(0)) + BigInt(value2);
25212
+ });
25213
+ });
25214
+ return this;
25215
+ });
25216
+ /**
25217
+ * Convert the MeshValue object into an array of Asset
25218
+ * @returns The array of Asset
25219
+ */
25220
+ __publicField(this, "toAssets", () => {
25221
+ const assets = [];
25222
+ Object.entries(this.value).forEach(([unit, quantity]) => {
25223
+ assets.push({ unit, quantity: quantity.toString() });
25224
+ });
25225
+ return assets;
25226
+ });
25227
+ /**
25228
+ * Convert the MeshValue object into Cardano data Value in Mesh Data type
25229
+ * Entries are sorted by byte ordering of policy ID, then token name
25230
+ */
25231
+ __publicField(this, "toData", () => {
25232
+ const unsortedMap = /* @__PURE__ */ new Map();
25233
+ this.toAssets().forEach((asset) => {
25234
+ const sanitizedName = asset.unit.replace("lovelace", "");
25235
+ const policy = sanitizedName.slice(0, 56) || "";
25236
+ const token = sanitizedName.slice(56) || "";
25237
+ if (!unsortedMap.has(policy)) {
25238
+ unsortedMap.set(policy, /* @__PURE__ */ new Map());
25239
+ }
25240
+ const tokenMap = unsortedMap.get(policy);
25241
+ const quantity = tokenMap?.get(token);
25242
+ if (!quantity) {
25243
+ tokenMap.set(token, BigInt(asset.quantity));
25244
+ } else {
25245
+ tokenMap.set(token, quantity + BigInt(asset.quantity));
25246
+ }
25247
+ });
25248
+ const sortedPolicies = Array.from(unsortedMap.keys()).sort(compareByteOrder);
25249
+ const valueMap = /* @__PURE__ */ new Map();
25250
+ sortedPolicies.forEach((policy) => {
25251
+ const unsortedTokenMap = unsortedMap.get(policy);
25252
+ const sortedTokens = Array.from(unsortedTokenMap.keys()).sort(
25253
+ compareByteOrder
25254
+ );
25255
+ const sortedTokenMap = /* @__PURE__ */ new Map();
25256
+ sortedTokens.forEach((token) => {
25257
+ sortedTokenMap.set(token, unsortedTokenMap.get(token));
25258
+ });
25259
+ valueMap.set(policy, sortedTokenMap);
25260
+ });
25261
+ return valueMap;
25262
+ });
25263
+ /**
25264
+ * Convert the MeshValue object into a JSON representation of Cardano data Value
25265
+ * Entries are sorted by byte ordering of policy ID, then token name
25266
+ * @returns Cardano data Value in JSON
25267
+ */
25268
+ __publicField(this, "toJSON", () => {
25269
+ const valueMapToParse = [];
25270
+ const valueMap = {};
25271
+ this.toAssets().forEach((asset) => {
25272
+ const sanitizedName = asset.unit.replace("lovelace", "");
25273
+ const policy = sanitizedName.slice(0, 56) || "";
25274
+ const token = sanitizedName.slice(56) || "";
25275
+ if (!valueMap[policy]) {
25276
+ valueMap[policy] = {};
25277
+ }
25278
+ if (!valueMap[policy][token]) {
25279
+ valueMap[policy][token] = Number(asset.quantity);
25280
+ } else {
25281
+ valueMap[policy][token] += Number(asset.quantity);
25282
+ }
25283
+ });
25284
+ const sortedPolicies = Object.keys(valueMap).sort(compareByteOrder);
25285
+ sortedPolicies.forEach((policy) => {
25286
+ const policyByte = currencySymbol(policy);
25287
+ const sortedTokenNames = Object.keys(valueMap[policy]).sort(
25288
+ compareByteOrder
25289
+ );
25290
+ const tokens = sortedTokenNames.map((name) => [
25291
+ tokenName(name),
25292
+ integer(valueMap[policy][name])
25293
+ ]);
25294
+ const policyMap = assocMap(tokens);
25295
+ valueMapToParse.push([policyByte, policyMap]);
25296
+ });
25297
+ return assocMap(valueMapToParse);
25298
+ });
25299
+ this.value = value2;
25300
+ }
25301
+ }, /**
25302
+ * Sort a Value (JSON representation) by policy ID then token name
25303
+ * @param plutusValue The Value to sort
25304
+ * @returns Sorted Value
25305
+ */
25306
+ __publicField(_a, "sortValue", (plutusValue) => {
25307
+ const sortedPolicies = [...plutusValue.map].sort(
25308
+ (a, b) => compareByteOrder(a.k.bytes, b.k.bytes)
25309
+ );
25310
+ const sortedMap = sortedPolicies.map((policyEntry) => {
25311
+ const sortedTokens = [...policyEntry.v.map].sort(
25312
+ (a, b) => compareByteOrder(a.k.bytes, b.k.bytes)
25313
+ );
25314
+ return {
25315
+ k: policyEntry.k,
25316
+ v: { map: sortedTokens }
25317
+ };
25318
+ });
25319
+ return { map: sortedMap };
25320
+ }), /**
25321
+ * Converting assets into MeshValue
25322
+ * @param assets The assets to convert
25323
+ * @returns MeshValue
25324
+ */
25325
+ __publicField(_a, "fromAssets", (assets) => {
25326
+ const value2 = new _a();
25327
+ value2.addAssets(assets);
25328
+ return value2;
25329
+ }), /**
25330
+ * Converting Value (the JSON representation of Cardano data Value) into MeshValue
25331
+ * @param plutusValue The Value to convert
25332
+ * @returns MeshValue
25333
+ */
25334
+ __publicField(_a, "fromValue", (plutusValue) => {
25335
+ const assets = [];
25336
+ plutusValue.map.forEach((policyMap) => {
25337
+ const policy = policyMap.k.bytes;
25338
+ policyMap.v.map.forEach((tokenMap) => {
25339
+ const token = tokenMap.k.bytes;
25340
+ const quantity = tokenMap.v.int.toString();
25341
+ const unsanitizedUnit = policy + token;
25342
+ const unit = unsanitizedUnit === "" ? "lovelace" : unsanitizedUnit;
25343
+ assets.push({ unit, quantity });
25344
+ });
25345
+ });
25346
+ return _a.fromAssets(assets);
25347
+ }), _a);
24963
25348
 
24964
25349
  // src/cardano/signer/cip-8.ts
24965
25350
  var Crypto = __toESM(require("@cardano-sdk/crypto"), 1);
@@ -25108,11 +25493,11 @@ var getCoseKeyFromPublicKey = (cbor) => {
25108
25493
  // src/cardano/signer/cardano-signer.ts
25109
25494
  var CardanoSigner = class {
25110
25495
  constructor() {
25111
- (0, import_core7.setInConwayEra)(true);
25496
+ (0, import_core6.setInConwayEra)(true);
25112
25497
  }
25113
25498
  static async signTx(tx, signers, returnFullTx = false) {
25114
- const cardanoTx = import_core7.Serialization.Transaction.fromCbor(
25115
- import_core7.Serialization.TxCBOR(tx)
25499
+ const cardanoTx = import_core6.Serialization.Transaction.fromCbor(
25500
+ import_core6.Serialization.TxCBOR(tx)
25116
25501
  );
25117
25502
  const txHash = cardanoTx.body().hash();
25118
25503
  const vkeyWitnesses = [];
@@ -25130,22 +25515,22 @@ var CardanoSigner = class {
25130
25515
  ...vkeyWitnesses
25131
25516
  ] : vkeyWitnesses;
25132
25517
  txWitnessSet2.setVkeys(
25133
- import_core7.Serialization.CborSet.fromCore(
25518
+ import_core6.Serialization.CborSet.fromCore(
25134
25519
  witnessSetVkeysValues,
25135
- import_core7.Serialization.VkeyWitness.fromCore
25520
+ import_core6.Serialization.VkeyWitness.fromCore
25136
25521
  )
25137
25522
  );
25138
- return new import_core7.Serialization.Transaction(
25523
+ return new import_core6.Serialization.Transaction(
25139
25524
  cardanoTx.body(),
25140
25525
  txWitnessSet2,
25141
25526
  cardanoTx.auxiliaryData()
25142
25527
  ).toCbor();
25143
25528
  }
25144
- const txWitnessSet = new import_core7.Serialization.TransactionWitnessSet();
25529
+ const txWitnessSet = new import_core6.Serialization.TransactionWitnessSet();
25145
25530
  txWitnessSet.setVkeys(
25146
- import_core7.Serialization.CborSet.fromCore(
25531
+ import_core6.Serialization.CborSet.fromCore(
25147
25532
  vkeyWitnesses,
25148
- import_core7.Serialization.VkeyWitness.fromCore
25533
+ import_core6.Serialization.VkeyWitness.fromCore
25149
25534
  )
25150
25535
  );
25151
25536
  return txWitnessSet.toCbor();
@@ -25179,7 +25564,7 @@ var CardanoSigner = class {
25179
25564
  };
25180
25565
 
25181
25566
  // src/cardano/utils/transaction-signers.ts
25182
- var import_core8 = require("@cardano-sdk/core");
25567
+ var import_core7 = require("@cardano-sdk/core");
25183
25568
  async function getRequiredSignersFromInputs(txBody, fetcher) {
25184
25569
  const requiredSigners = /* @__PURE__ */ new Set();
25185
25570
  let inputs = txBody.inputs().values();
@@ -25207,7 +25592,7 @@ async function getRequiredSignersFromInputs(txBody, fetcher) {
25207
25592
  });
25208
25593
  });
25209
25594
  for (const utxo of utxos) {
25210
- const address = import_core8.Cardano.Address.fromBech32(utxo.output.address);
25595
+ const address = import_core7.Cardano.Address.fromBech32(utxo.output.address);
25211
25596
  const addressProps = address.getProps();
25212
25597
  if (addressProps.paymentPart) {
25213
25598
  if (addressProps.paymentPart.type === 0 /* KeyHash */) {
@@ -25329,10 +25714,10 @@ function getRequiredSignersFromWithdrawals(txBody) {
25329
25714
  const withdrawals = txBody.withdrawals();
25330
25715
  if (withdrawals) {
25331
25716
  for (const rewardAccount of withdrawals.keys()) {
25332
- const address = import_core8.Cardano.Address.fromBech32(rewardAccount);
25717
+ const address = import_core7.Cardano.Address.fromBech32(rewardAccount);
25333
25718
  const addressType = address.getType();
25334
- if (addressType === import_core8.Cardano.AddressType.RewardKey) {
25335
- requiredSigners.add(import_core8.Cardano.RewardAccount.toHash(rewardAccount));
25719
+ if (addressType === import_core7.Cardano.AddressType.RewardKey) {
25720
+ requiredSigners.add(import_core7.Cardano.RewardAccount.toHash(rewardAccount));
25336
25721
  }
25337
25722
  }
25338
25723
  }
@@ -25389,6 +25774,24 @@ async function getTransactionRequiredSigners(transaction, fetcher) {
25389
25774
  return allRequiredSigners;
25390
25775
  }
25391
25776
 
25777
+ // src/cardano/utils/value.ts
25778
+ var import_core8 = require("@cardano-sdk/core");
25779
+ function mergeValue(a, b) {
25780
+ const ma = a.multiasset() ?? /* @__PURE__ */ new Map();
25781
+ b.multiasset()?.forEach((v, k) => {
25782
+ const newVal = (ma.get(k) ?? 0n) + v;
25783
+ if (newVal == 0n) {
25784
+ ma.delete(k);
25785
+ } else {
25786
+ ma.set(k, newVal);
25787
+ }
25788
+ });
25789
+ return new import_core8.Serialization.Value(
25790
+ BigInt(a.coin()) + BigInt(b.coin()),
25791
+ ma.size > 0 ? ma : void 0
25792
+ );
25793
+ }
25794
+
25392
25795
  // src/cardano/wallet/mesh/cardano-headless-wallet.ts
25393
25796
  var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
25394
25797
  constructor(networkId, addressManager, walletAddressType, fetcher, submitter) {
@@ -25649,9 +26052,7 @@ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
25649
26052
  transaction,
25650
26053
  this.fetcher
25651
26054
  );
25652
- const signersMap = await this.addressManager.getCredentialsSigners(
25653
- requiredSigners
25654
- );
26055
+ const signersMap = await this.addressManager.getCredentialsSigners(requiredSigners);
25655
26056
  if (!partialSign) {
25656
26057
  if (requiredSigners.size !== signersMap.size) {
25657
26058
  throw new Error("[CardanoWallet] Not all required signers found");
@@ -25801,26 +26202,12 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
25801
26202
  if (!this.fetcher) {
25802
26203
  throw new Error("[CardanoWallet] No fetcher provided");
25803
26204
  }
25804
- const utxos = await this.fetchAccountUtxos();
25805
- const getUtxoLovelaceValue = (utxo) => {
25806
- const value = utxo.output.amount;
25807
- let lovelace = 0;
25808
- for (const asset of value) {
25809
- if (asset.unit === "lovelace" || asset.unit === "") {
25810
- lovelace = parseInt(asset.quantity);
25811
- }
25812
- }
25813
- return lovelace;
25814
- };
25815
- const sortedUtxos = utxos.sort(
25816
- (a, b) => getUtxoLovelaceValue(a) - getUtxoLovelaceValue(b)
26205
+ const collaterals = await this.getCollateral();
26206
+ return collaterals.map(
26207
+ (coll) => fromTxUnspentOutput(
26208
+ import_core10.Serialization.TransactionUnspentOutput.fromCbor((0, import_util6.HexBlob)(coll))
26209
+ )
25817
26210
  );
25818
- for (const utxo of sortedUtxos) {
25819
- if (getUtxoLovelaceValue(utxo) >= 5e6) {
25820
- return [utxo];
25821
- }
25822
- }
25823
- return [];
25824
26211
  }
25825
26212
  /**
25826
26213
  * Get the balance of the wallet.
@@ -25835,7 +26222,9 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
25835
26222
  throw new Error("[CardanoWallet] No fetcher provided");
25836
26223
  }
25837
26224
  const utxos = await this.fetchAccountUtxos();
25838
- return utxos.map((utxo) => utxo.output.amount).flat();
26225
+ const values = utxos.map((utxo) => utxo.output.amount).flat();
26226
+ const meshValue = MeshValue.fromAssets(values);
26227
+ return meshValue.toAssets();
25839
26228
  }
25840
26229
  /**
25841
26230
  * Get the used addresses for the wallet.
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
8
  var __commonJS = (cb, mod) => function __require() {
8
9
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
10
  };
@@ -23,6 +24,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
25
  mod
25
26
  ));
27
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
26
28
 
27
29
  // node_modules/@noble/hashes/crypto.js
28
30
  var require_crypto = __commonJS({
@@ -25328,24 +25330,6 @@ var MeshCardanoBrowserWallet = class _MeshCardanoBrowserWallet extends CardanoBr
25328
25330
  // src/cardano/wallet/mesh/cardano-headless-wallet.ts
25329
25331
  import { Cardano as Cardano6, Serialization as Serialization6, setInConwayEra as setInConwayEra5 } from "@cardano-sdk/core";
25330
25332
 
25331
- // src/cardano/utils/value.ts
25332
- import { Serialization as Serialization3 } from "@cardano-sdk/core";
25333
- function mergeValue(a, b) {
25334
- const ma = a.multiasset() ?? /* @__PURE__ */ new Map();
25335
- b.multiasset()?.forEach((v, k) => {
25336
- const newVal = (ma.get(k) ?? 0n) + v;
25337
- if (newVal == 0n) {
25338
- ma.delete(k);
25339
- } else {
25340
- ma.set(k, newVal);
25341
- }
25342
- });
25343
- return new Serialization3.Value(
25344
- BigInt(a.coin()) + BigInt(b.coin()),
25345
- ma.size > 0 ? ma : void 0
25346
- );
25347
- }
25348
-
25349
25333
  // src/cardano/address/single-address-manager.ts
25350
25334
  import { setInConwayEra as setInConwayEra3 } from "@cardano-sdk/core";
25351
25335
  var AddressManager = class _AddressManager {
@@ -25494,7 +25478,7 @@ var AddressManager = class _AddressManager {
25494
25478
  };
25495
25479
 
25496
25480
  // src/cardano/signer/cardano-signer.ts
25497
- import { Serialization as Serialization4, setInConwayEra as setInConwayEra4 } from "@cardano-sdk/core";
25481
+ import { Serialization as Serialization3, setInConwayEra as setInConwayEra4 } from "@cardano-sdk/core";
25498
25482
  import { Ed25519PublicKeyHex, Ed25519SignatureHex as Ed25519SignatureHex2 } from "@cardano-sdk/crypto";
25499
25483
  import { HexBlob as HexBlob5 } from "@cardano-sdk/util";
25500
25484
  import {
@@ -25510,6 +25494,49 @@ var import_bech32 = __toESM(require_dist(), 1);
25510
25494
  var import_blake2b = __toESM(require_blake2b2(), 1);
25511
25495
  var import_blakejs = __toESM(require_blakejs(), 1);
25512
25496
  var import_bip393 = __toESM(require_src(), 1);
25497
+ var POLICY_ID_LENGTH = 56;
25498
+ var byteString = (bytes) => {
25499
+ if (bytes.length % 2 !== 0) {
25500
+ throw new Error("Invalid hex string - odd length: " + bytes);
25501
+ }
25502
+ if (!/^[0-9a-fA-F]*$/.test(bytes)) {
25503
+ throw new Error("Invalid hex string - non-hex string character: " + bytes);
25504
+ }
25505
+ return {
25506
+ bytes
25507
+ };
25508
+ };
25509
+ var integer = (int) => ({ int });
25510
+ var assocMap = (mapItems, validation = true) => ({
25511
+ map: mapItems.map(([k, v]) => {
25512
+ if (validation) {
25513
+ if (typeof k !== "object" || typeof v !== "object") {
25514
+ throw new Error(
25515
+ `Map item of JSON Cardano data type must be an object - ${k}, ${v}`
25516
+ );
25517
+ }
25518
+ }
25519
+ return { k, v };
25520
+ })
25521
+ });
25522
+ var policyId = (bytes) => {
25523
+ if (bytes.length !== POLICY_ID_LENGTH && bytes !== "") {
25524
+ throw new Error(
25525
+ `Invalid policy id for [${bytes}] - should be ${POLICY_ID_LENGTH / 2} bytes (${POLICY_ID_LENGTH} hex length) long or empty string for lovelace`
25526
+ );
25527
+ }
25528
+ return byteString(bytes);
25529
+ };
25530
+ var currencySymbol = (bytes) => policyId(bytes);
25531
+ var assetName = (bytes) => {
25532
+ if (bytes.length > 64) {
25533
+ throw new Error(
25534
+ `Invalid asset name for [${bytes}] - should be less than 32 bytes (64 hex length) long`
25535
+ );
25536
+ }
25537
+ return byteString(bytes);
25538
+ };
25539
+ var tokenName = (bytes) => assetName(bytes);
25513
25540
  var stringToHex = (str) => Buffer.from(str, "utf8").toString("hex");
25514
25541
  var isHexString = (hex) => /^[0-9A-F]*$/i.test(hex);
25515
25542
  var SLOT_CONFIG_NETWORK = {
@@ -25546,6 +25573,364 @@ var SLOT_CONFIG_NETWORK = {
25546
25573
  epochLength: 0
25547
25574
  }
25548
25575
  };
25576
+ var BigNum = class _BigNum {
25577
+ constructor(value2) {
25578
+ __publicField(this, "value");
25579
+ if (!value2) {
25580
+ this.value = BigInt(0);
25581
+ return;
25582
+ }
25583
+ this.value = BigInt(value2);
25584
+ }
25585
+ static new(value2) {
25586
+ if (!value2) {
25587
+ return new _BigNum(0);
25588
+ }
25589
+ return new _BigNum(value2);
25590
+ }
25591
+ // Operators
25592
+ divFloor(other) {
25593
+ this.value = this.value / other.value;
25594
+ return this;
25595
+ }
25596
+ checkedMul(other) {
25597
+ this.value *= other.value;
25598
+ return this;
25599
+ }
25600
+ checkedAdd(other) {
25601
+ this.value += other.value;
25602
+ return this;
25603
+ }
25604
+ checkedSub(other) {
25605
+ this.value -= other.value;
25606
+ return this;
25607
+ }
25608
+ clampedSub(other) {
25609
+ const result = this.value - other.value;
25610
+ this.value = result < 0n ? 0n : result;
25611
+ return this;
25612
+ }
25613
+ // Comparators
25614
+ lessThan(other) {
25615
+ return this.value < other.value;
25616
+ }
25617
+ compare(other) {
25618
+ if (this.value === other.value) {
25619
+ return 0;
25620
+ } else if (this.value < other.value) {
25621
+ return -1;
25622
+ } else {
25623
+ return 1;
25624
+ }
25625
+ }
25626
+ // Override
25627
+ toString() {
25628
+ return this.value.toString();
25629
+ }
25630
+ };
25631
+ var compareByteOrder = (a, b) => a < b ? -1 : a > b ? 1 : 0;
25632
+ var _a;
25633
+ var MeshValue = (_a = class {
25634
+ constructor(value2 = {}) {
25635
+ __publicField(this, "value");
25636
+ /**
25637
+ * Add an asset to the Value class's value record.
25638
+ * @param asset The asset to add
25639
+ * @returns The updated MeshValue object
25640
+ */
25641
+ __publicField(this, "addAsset", (asset) => {
25642
+ const quantity = BigInt(asset.quantity);
25643
+ const { unit } = asset;
25644
+ if (this.value[unit]) {
25645
+ this.value[unit] += quantity;
25646
+ } else {
25647
+ this.value[unit] = quantity;
25648
+ }
25649
+ return this;
25650
+ });
25651
+ /**
25652
+ * Add an array of assets to the Value class's value record.
25653
+ * @param assets The assets to add
25654
+ * @returns The updated MeshValue object
25655
+ */
25656
+ __publicField(this, "addAssets", (assets) => {
25657
+ assets.forEach((asset) => {
25658
+ this.addAsset(asset);
25659
+ });
25660
+ return this;
25661
+ });
25662
+ /**
25663
+ * Substract an asset from the Value class's value record.
25664
+ * @param asset The asset to subtract
25665
+ * @returns The updated MeshValue object
25666
+ */
25667
+ __publicField(this, "negateAsset", (asset) => {
25668
+ const { unit, quantity: assetQty } = asset;
25669
+ const quantity = BigNum.new(this.value[unit]);
25670
+ quantity.clampedSub(BigNum.new(assetQty));
25671
+ if (quantity.value === BigInt(0)) {
25672
+ delete this.value[unit];
25673
+ } else {
25674
+ this.value[unit] = quantity.value;
25675
+ }
25676
+ return this;
25677
+ });
25678
+ /**
25679
+ * Subtract an array of assets from the Value class's value record.
25680
+ * @param assets The assets to subtract
25681
+ * @returns The updated MeshValue object
25682
+ */
25683
+ __publicField(this, "negateAssets", (assets) => {
25684
+ assets.forEach((asset) => {
25685
+ this.negateAsset(asset);
25686
+ });
25687
+ return this;
25688
+ });
25689
+ /**
25690
+ * Get the quantity of asset object per unit
25691
+ * @param unit The unit to get the quantity of
25692
+ * @returns The quantity of the asset
25693
+ */
25694
+ __publicField(this, "get", (unit) => {
25695
+ return this.value[unit] ? BigInt(this.value[unit]) : BigInt(0);
25696
+ });
25697
+ /**
25698
+ * Get all assets that belong to a specific policy ID
25699
+ * @param policyId The policy ID to filter by
25700
+ * @returns Array of assets that match the policy ID
25701
+ */
25702
+ __publicField(this, "getPolicyAssets", (policyId2) => {
25703
+ const assets = [];
25704
+ Object.entries(this.value).forEach(([unit, quantity]) => {
25705
+ if (unit.startsWith(policyId2)) {
25706
+ assets.push({
25707
+ unit,
25708
+ quantity: quantity.toString()
25709
+ });
25710
+ }
25711
+ });
25712
+ return assets;
25713
+ });
25714
+ /**
25715
+ * Get all asset units
25716
+ * @returns The asset units
25717
+ */
25718
+ __publicField(this, "units", () => {
25719
+ return Object.keys(this.value);
25720
+ });
25721
+ /**
25722
+ * Check if the value is greater than or equal to another value
25723
+ * @param other - The value to compare against
25724
+ * @returns boolean
25725
+ */
25726
+ __publicField(this, "geq", (other) => {
25727
+ return Object.keys(other.value).every((key) => this.geqUnit(key, other));
25728
+ });
25729
+ /**
25730
+ * Check if the specific unit of value is greater than or equal to that unit of another value
25731
+ * @param unit - The unit to compare
25732
+ * @param other - The value to compare against
25733
+ * @returns boolean
25734
+ */
25735
+ __publicField(this, "geqUnit", (unit, other) => {
25736
+ if (this.value[unit] === void 0 || other.value[unit] === void 0) {
25737
+ return false;
25738
+ }
25739
+ return BigInt(this.value[unit]) >= BigInt(other.value[unit]);
25740
+ });
25741
+ /**
25742
+ * Check if the value is less than or equal to another value
25743
+ * @param other - The value to compare against
25744
+ * @returns boolean
25745
+ */
25746
+ __publicField(this, "leq", (other) => {
25747
+ return Object.keys(this.value).every((key) => this.leqUnit(key, other));
25748
+ });
25749
+ /**
25750
+ * Check if the specific unit of value is less than or equal to that unit of another value
25751
+ * @param unit - The unit to compare
25752
+ * @param other - The value to compare against
25753
+ * @returns boolean
25754
+ */
25755
+ __publicField(this, "leqUnit", (unit, other) => {
25756
+ if (this.value[unit] === void 0 || other.value[unit] === void 0) {
25757
+ return false;
25758
+ }
25759
+ return BigInt(this.value[unit]) <= BigInt(other.value[unit]);
25760
+ });
25761
+ /**
25762
+ * Check if the value is equal to another value
25763
+ * @param other - The value to compare against
25764
+ * @returns boolean
25765
+ */
25766
+ __publicField(this, "eq", (other) => {
25767
+ return Object.keys(this.value).every((key) => this.eqUnit(key, other));
25768
+ });
25769
+ /**
25770
+ * Check if the specific unit of value is equal to that unit of another value
25771
+ * @param unit - The unit to compare
25772
+ * @param other - The value to compare against
25773
+ * @returns boolean
25774
+ */
25775
+ __publicField(this, "eqUnit", (unit, other) => {
25776
+ if (this.value[unit] === void 0 || other.value[unit] === void 0) {
25777
+ return false;
25778
+ }
25779
+ return BigInt(this.value[unit]) === BigInt(other.value[unit]);
25780
+ });
25781
+ /**
25782
+ * Check if the value is empty
25783
+ * @returns boolean
25784
+ */
25785
+ __publicField(this, "isEmpty", () => {
25786
+ return Object.keys(this.value).length === 0;
25787
+ });
25788
+ /**
25789
+ * Merge the given values
25790
+ * @param values The other values to merge
25791
+ * @returns this
25792
+ */
25793
+ __publicField(this, "merge", (values) => {
25794
+ const valuesArray = Array.isArray(values) ? values : [values];
25795
+ valuesArray.forEach((other) => {
25796
+ Object.entries(other.value).forEach(([key, value2]) => {
25797
+ this.value[key] = (this.value[key] !== void 0 ? BigInt(this.value[key]) : BigInt(0)) + BigInt(value2);
25798
+ });
25799
+ });
25800
+ return this;
25801
+ });
25802
+ /**
25803
+ * Convert the MeshValue object into an array of Asset
25804
+ * @returns The array of Asset
25805
+ */
25806
+ __publicField(this, "toAssets", () => {
25807
+ const assets = [];
25808
+ Object.entries(this.value).forEach(([unit, quantity]) => {
25809
+ assets.push({ unit, quantity: quantity.toString() });
25810
+ });
25811
+ return assets;
25812
+ });
25813
+ /**
25814
+ * Convert the MeshValue object into Cardano data Value in Mesh Data type
25815
+ * Entries are sorted by byte ordering of policy ID, then token name
25816
+ */
25817
+ __publicField(this, "toData", () => {
25818
+ const unsortedMap = /* @__PURE__ */ new Map();
25819
+ this.toAssets().forEach((asset) => {
25820
+ const sanitizedName = asset.unit.replace("lovelace", "");
25821
+ const policy = sanitizedName.slice(0, 56) || "";
25822
+ const token = sanitizedName.slice(56) || "";
25823
+ if (!unsortedMap.has(policy)) {
25824
+ unsortedMap.set(policy, /* @__PURE__ */ new Map());
25825
+ }
25826
+ const tokenMap = unsortedMap.get(policy);
25827
+ const quantity = tokenMap?.get(token);
25828
+ if (!quantity) {
25829
+ tokenMap.set(token, BigInt(asset.quantity));
25830
+ } else {
25831
+ tokenMap.set(token, quantity + BigInt(asset.quantity));
25832
+ }
25833
+ });
25834
+ const sortedPolicies = Array.from(unsortedMap.keys()).sort(compareByteOrder);
25835
+ const valueMap = /* @__PURE__ */ new Map();
25836
+ sortedPolicies.forEach((policy) => {
25837
+ const unsortedTokenMap = unsortedMap.get(policy);
25838
+ const sortedTokens = Array.from(unsortedTokenMap.keys()).sort(
25839
+ compareByteOrder
25840
+ );
25841
+ const sortedTokenMap = /* @__PURE__ */ new Map();
25842
+ sortedTokens.forEach((token) => {
25843
+ sortedTokenMap.set(token, unsortedTokenMap.get(token));
25844
+ });
25845
+ valueMap.set(policy, sortedTokenMap);
25846
+ });
25847
+ return valueMap;
25848
+ });
25849
+ /**
25850
+ * Convert the MeshValue object into a JSON representation of Cardano data Value
25851
+ * Entries are sorted by byte ordering of policy ID, then token name
25852
+ * @returns Cardano data Value in JSON
25853
+ */
25854
+ __publicField(this, "toJSON", () => {
25855
+ const valueMapToParse = [];
25856
+ const valueMap = {};
25857
+ this.toAssets().forEach((asset) => {
25858
+ const sanitizedName = asset.unit.replace("lovelace", "");
25859
+ const policy = sanitizedName.slice(0, 56) || "";
25860
+ const token = sanitizedName.slice(56) || "";
25861
+ if (!valueMap[policy]) {
25862
+ valueMap[policy] = {};
25863
+ }
25864
+ if (!valueMap[policy][token]) {
25865
+ valueMap[policy][token] = Number(asset.quantity);
25866
+ } else {
25867
+ valueMap[policy][token] += Number(asset.quantity);
25868
+ }
25869
+ });
25870
+ const sortedPolicies = Object.keys(valueMap).sort(compareByteOrder);
25871
+ sortedPolicies.forEach((policy) => {
25872
+ const policyByte = currencySymbol(policy);
25873
+ const sortedTokenNames = Object.keys(valueMap[policy]).sort(
25874
+ compareByteOrder
25875
+ );
25876
+ const tokens = sortedTokenNames.map((name) => [
25877
+ tokenName(name),
25878
+ integer(valueMap[policy][name])
25879
+ ]);
25880
+ const policyMap = assocMap(tokens);
25881
+ valueMapToParse.push([policyByte, policyMap]);
25882
+ });
25883
+ return assocMap(valueMapToParse);
25884
+ });
25885
+ this.value = value2;
25886
+ }
25887
+ }, /**
25888
+ * Sort a Value (JSON representation) by policy ID then token name
25889
+ * @param plutusValue The Value to sort
25890
+ * @returns Sorted Value
25891
+ */
25892
+ __publicField(_a, "sortValue", (plutusValue) => {
25893
+ const sortedPolicies = [...plutusValue.map].sort(
25894
+ (a, b) => compareByteOrder(a.k.bytes, b.k.bytes)
25895
+ );
25896
+ const sortedMap = sortedPolicies.map((policyEntry) => {
25897
+ const sortedTokens = [...policyEntry.v.map].sort(
25898
+ (a, b) => compareByteOrder(a.k.bytes, b.k.bytes)
25899
+ );
25900
+ return {
25901
+ k: policyEntry.k,
25902
+ v: { map: sortedTokens }
25903
+ };
25904
+ });
25905
+ return { map: sortedMap };
25906
+ }), /**
25907
+ * Converting assets into MeshValue
25908
+ * @param assets The assets to convert
25909
+ * @returns MeshValue
25910
+ */
25911
+ __publicField(_a, "fromAssets", (assets) => {
25912
+ const value2 = new _a();
25913
+ value2.addAssets(assets);
25914
+ return value2;
25915
+ }), /**
25916
+ * Converting Value (the JSON representation of Cardano data Value) into MeshValue
25917
+ * @param plutusValue The Value to convert
25918
+ * @returns MeshValue
25919
+ */
25920
+ __publicField(_a, "fromValue", (plutusValue) => {
25921
+ const assets = [];
25922
+ plutusValue.map.forEach((policyMap) => {
25923
+ const policy = policyMap.k.bytes;
25924
+ policyMap.v.map.forEach((tokenMap) => {
25925
+ const token = tokenMap.k.bytes;
25926
+ const quantity = tokenMap.v.int.toString();
25927
+ const unsanitizedUnit = policy + token;
25928
+ const unit = unsanitizedUnit === "" ? "lovelace" : unsanitizedUnit;
25929
+ assets.push({ unit, quantity });
25930
+ });
25931
+ });
25932
+ return _a.fromAssets(assets);
25933
+ }), _a);
25549
25934
 
25550
25935
  // src/cardano/signer/cip-8.ts
25551
25936
  var import_blakejs2 = __toESM(require_blakejs(), 1);
@@ -25708,8 +26093,8 @@ var CardanoSigner = class {
25708
26093
  setInConwayEra4(true);
25709
26094
  }
25710
26095
  static async signTx(tx, signers, returnFullTx = false) {
25711
- const cardanoTx = Serialization4.Transaction.fromCbor(
25712
- Serialization4.TxCBOR(tx)
26096
+ const cardanoTx = Serialization3.Transaction.fromCbor(
26097
+ Serialization3.TxCBOR(tx)
25713
26098
  );
25714
26099
  const txHash = cardanoTx.body().hash();
25715
26100
  const vkeyWitnesses = [];
@@ -25727,22 +26112,22 @@ var CardanoSigner = class {
25727
26112
  ...vkeyWitnesses
25728
26113
  ] : vkeyWitnesses;
25729
26114
  txWitnessSet2.setVkeys(
25730
- Serialization4.CborSet.fromCore(
26115
+ Serialization3.CborSet.fromCore(
25731
26116
  witnessSetVkeysValues,
25732
- Serialization4.VkeyWitness.fromCore
26117
+ Serialization3.VkeyWitness.fromCore
25733
26118
  )
25734
26119
  );
25735
- return new Serialization4.Transaction(
26120
+ return new Serialization3.Transaction(
25736
26121
  cardanoTx.body(),
25737
26122
  txWitnessSet2,
25738
26123
  cardanoTx.auxiliaryData()
25739
26124
  ).toCbor();
25740
26125
  }
25741
- const txWitnessSet = new Serialization4.TransactionWitnessSet();
26126
+ const txWitnessSet = new Serialization3.TransactionWitnessSet();
25742
26127
  txWitnessSet.setVkeys(
25743
- Serialization4.CborSet.fromCore(
26128
+ Serialization3.CborSet.fromCore(
25744
26129
  vkeyWitnesses,
25745
- Serialization4.VkeyWitness.fromCore
26130
+ Serialization3.VkeyWitness.fromCore
25746
26131
  )
25747
26132
  );
25748
26133
  return txWitnessSet.toCbor();
@@ -25776,7 +26161,7 @@ var CardanoSigner = class {
25776
26161
  };
25777
26162
 
25778
26163
  // src/cardano/utils/transaction-signers.ts
25779
- import { Cardano as Cardano5 } from "@cardano-sdk/core";
26164
+ import { Cardano as Cardano4 } from "@cardano-sdk/core";
25780
26165
  async function getRequiredSignersFromInputs(txBody, fetcher) {
25781
26166
  const requiredSigners = /* @__PURE__ */ new Set();
25782
26167
  let inputs = txBody.inputs().values();
@@ -25804,7 +26189,7 @@ async function getRequiredSignersFromInputs(txBody, fetcher) {
25804
26189
  });
25805
26190
  });
25806
26191
  for (const utxo of utxos) {
25807
- const address = Cardano5.Address.fromBech32(utxo.output.address);
26192
+ const address = Cardano4.Address.fromBech32(utxo.output.address);
25808
26193
  const addressProps = address.getProps();
25809
26194
  if (addressProps.paymentPart) {
25810
26195
  if (addressProps.paymentPart.type === 0 /* KeyHash */) {
@@ -25926,10 +26311,10 @@ function getRequiredSignersFromWithdrawals(txBody) {
25926
26311
  const withdrawals = txBody.withdrawals();
25927
26312
  if (withdrawals) {
25928
26313
  for (const rewardAccount of withdrawals.keys()) {
25929
- const address = Cardano5.Address.fromBech32(rewardAccount);
26314
+ const address = Cardano4.Address.fromBech32(rewardAccount);
25930
26315
  const addressType = address.getType();
25931
- if (addressType === Cardano5.AddressType.RewardKey) {
25932
- requiredSigners.add(Cardano5.RewardAccount.toHash(rewardAccount));
26316
+ if (addressType === Cardano4.AddressType.RewardKey) {
26317
+ requiredSigners.add(Cardano4.RewardAccount.toHash(rewardAccount));
25933
26318
  }
25934
26319
  }
25935
26320
  }
@@ -25986,6 +26371,24 @@ async function getTransactionRequiredSigners(transaction, fetcher) {
25986
26371
  return allRequiredSigners;
25987
26372
  }
25988
26373
 
26374
+ // src/cardano/utils/value.ts
26375
+ import { Serialization as Serialization5 } from "@cardano-sdk/core";
26376
+ function mergeValue(a, b) {
26377
+ const ma = a.multiasset() ?? /* @__PURE__ */ new Map();
26378
+ b.multiasset()?.forEach((v, k) => {
26379
+ const newVal = (ma.get(k) ?? 0n) + v;
26380
+ if (newVal == 0n) {
26381
+ ma.delete(k);
26382
+ } else {
26383
+ ma.set(k, newVal);
26384
+ }
26385
+ });
26386
+ return new Serialization5.Value(
26387
+ BigInt(a.coin()) + BigInt(b.coin()),
26388
+ ma.size > 0 ? ma : void 0
26389
+ );
26390
+ }
26391
+
25989
26392
  // src/cardano/wallet/mesh/cardano-headless-wallet.ts
25990
26393
  var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
25991
26394
  constructor(networkId, addressManager, walletAddressType, fetcher, submitter) {
@@ -26246,9 +26649,7 @@ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
26246
26649
  transaction,
26247
26650
  this.fetcher
26248
26651
  );
26249
- const signersMap = await this.addressManager.getCredentialsSigners(
26250
- requiredSigners
26251
- );
26652
+ const signersMap = await this.addressManager.getCredentialsSigners(requiredSigners);
26252
26653
  if (!partialSign) {
26253
26654
  if (requiredSigners.size !== signersMap.size) {
26254
26655
  throw new Error("[CardanoWallet] Not all required signers found");
@@ -26398,26 +26799,12 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
26398
26799
  if (!this.fetcher) {
26399
26800
  throw new Error("[CardanoWallet] No fetcher provided");
26400
26801
  }
26401
- const utxos = await this.fetchAccountUtxos();
26402
- const getUtxoLovelaceValue = (utxo) => {
26403
- const value = utxo.output.amount;
26404
- let lovelace = 0;
26405
- for (const asset of value) {
26406
- if (asset.unit === "lovelace" || asset.unit === "") {
26407
- lovelace = parseInt(asset.quantity);
26408
- }
26409
- }
26410
- return lovelace;
26411
- };
26412
- const sortedUtxos = utxos.sort(
26413
- (a, b) => getUtxoLovelaceValue(a) - getUtxoLovelaceValue(b)
26802
+ const collaterals = await this.getCollateral();
26803
+ return collaterals.map(
26804
+ (coll) => fromTxUnspentOutput(
26805
+ Serialization7.TransactionUnspentOutput.fromCbor(HexBlob6(coll))
26806
+ )
26414
26807
  );
26415
- for (const utxo of sortedUtxos) {
26416
- if (getUtxoLovelaceValue(utxo) >= 5e6) {
26417
- return [utxo];
26418
- }
26419
- }
26420
- return [];
26421
26808
  }
26422
26809
  /**
26423
26810
  * Get the balance of the wallet.
@@ -26432,7 +26819,9 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
26432
26819
  throw new Error("[CardanoWallet] No fetcher provided");
26433
26820
  }
26434
26821
  const utxos = await this.fetchAccountUtxos();
26435
- return utxos.map((utxo) => utxo.output.amount).flat();
26822
+ const values = utxos.map((utxo) => utxo.output.amount).flat();
26823
+ const meshValue = MeshValue.fromAssets(values);
26824
+ return meshValue.toAssets();
26436
26825
  }
26437
26826
  /**
26438
26827
  * Get the used addresses for the wallet.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshsdk/wallet",
3
- "version": "2.0.0-beta.7",
3
+ "version": "2.0.0-beta.9",
4
4
  "description": "Wallets - https://meshjs.dev/apis/wallets",
5
5
  "main": "./dist/index.cjs",
6
6
  "browser": "./dist/index.js",
@@ -19,9 +19,9 @@
19
19
  ],
20
20
  "scripts": {
21
21
  "build": "tsup",
22
- "build:demo": "tsup demo/src/main.ts --format esm --outDir demo/dist --clean",
23
- "dev:demo": "tsup demo/src/main.ts --format esm --outDir demo/dist --watch",
24
- "preview:demo": "npx serve demo -p 5173",
22
+ "build:demo": "npm --prefix demo run build",
23
+ "dev:demo": "npm --prefix demo run dev",
24
+ "preview:demo": "npm --prefix demo run start",
25
25
  "build:docs": "typedoc src/index.ts --json ../../apps/docs/src/data/mesh-wallets.json",
26
26
  "clean": "rm -rf .turbo && rm -rf dist && rm -rf node_modules",
27
27
  "dev": "tsup src/index.ts --format esm,cjs --watch --dts",
@@ -31,25 +31,21 @@
31
31
  "test": "jest"
32
32
  },
33
33
  "devDependencies": {
34
+ "@ianvs/prettier-plugin-sort-imports": "^4.4.1",
34
35
  "@meshsdk/common": "1.9.0-beta.100",
35
36
  "@meshsdk/provider": "1.9.0-beta.99",
36
- "@types/jest": "^29.5.12",
37
+ "@types/jest": "^29.5.14",
38
+ "@types/mocha": "^10.0.10",
37
39
  "dotenv": "^16.4.5",
38
40
  "eslint": "^8.57.0",
39
41
  "jest": "^29.7.0",
40
42
  "patch-package": "^8.0.1",
43
+ "prettier": "^3.5.3",
41
44
  "ts-jest": "^29.1.4",
42
45
  "ts-node": "^10.9.2",
43
46
  "tsup": "^8.0.2",
44
47
  "typedoc": "^0.26.3",
45
- "typescript": "^5.3.3",
46
- "jest": "^29.7.0",
47
- "@types/jest": "^29.5.12",
48
- "ts-node": "^10.9.2",
49
- "ts-jest": "^29.1.4",
50
- "dotenv": "^16.4.5",
51
- "@meshsdk/provider": "1.9.0-beta.99",
52
- "@meshsdk/common": "1.9.0-beta.100"
48
+ "typescript": "^5.3.3"
53
49
  },
54
50
  "dependencies": {
55
51
  "@cardano-sdk/core": "0.46.11",