@meshsdk/wallet 2.0.0-beta.7 → 2.0.0-beta.8

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
@@ -24748,26 +24748,8 @@ var MeshCardanoBrowserWallet = class _MeshCardanoBrowserWallet extends CardanoBr
24748
24748
  // src/cardano/wallet/mesh/cardano-headless-wallet.ts
24749
24749
  var import_core9 = require("@cardano-sdk/core");
24750
24750
 
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
24751
  // src/cardano/address/single-address-manager.ts
24770
- var import_core6 = require("@cardano-sdk/core");
24752
+ var import_core5 = require("@cardano-sdk/core");
24771
24753
  var AddressManager = class _AddressManager {
24772
24754
  static async create(config) {
24773
24755
  let paymentSigner;
@@ -24856,7 +24838,7 @@ var AddressManager = class _AddressManager {
24856
24838
  );
24857
24839
  }
24858
24840
  constructor(paymentCredential, stakeCredential, drepCredential, paymentSigner, networkId, stakeSigner, drepSigner) {
24859
- (0, import_core6.setInConwayEra)(true);
24841
+ (0, import_core5.setInConwayEra)(true);
24860
24842
  this.paymentCredential = paymentCredential;
24861
24843
  this.stakeCredential = stakeCredential;
24862
24844
  this.drepCredential = drepCredential;
@@ -24914,7 +24896,7 @@ var AddressManager = class _AddressManager {
24914
24896
  };
24915
24897
 
24916
24898
  // src/cardano/signer/cardano-signer.ts
24917
- var import_core7 = require("@cardano-sdk/core");
24899
+ var import_core6 = require("@cardano-sdk/core");
24918
24900
  var import_crypto5 = require("@cardano-sdk/crypto");
24919
24901
  var import_util5 = require("@cardano-sdk/util");
24920
24902
  var import_cbor2 = require("@harmoniclabs/cbor");
@@ -25108,11 +25090,11 @@ var getCoseKeyFromPublicKey = (cbor) => {
25108
25090
  // src/cardano/signer/cardano-signer.ts
25109
25091
  var CardanoSigner = class {
25110
25092
  constructor() {
25111
- (0, import_core7.setInConwayEra)(true);
25093
+ (0, import_core6.setInConwayEra)(true);
25112
25094
  }
25113
25095
  static async signTx(tx, signers, returnFullTx = false) {
25114
- const cardanoTx = import_core7.Serialization.Transaction.fromCbor(
25115
- import_core7.Serialization.TxCBOR(tx)
25096
+ const cardanoTx = import_core6.Serialization.Transaction.fromCbor(
25097
+ import_core6.Serialization.TxCBOR(tx)
25116
25098
  );
25117
25099
  const txHash = cardanoTx.body().hash();
25118
25100
  const vkeyWitnesses = [];
@@ -25130,22 +25112,22 @@ var CardanoSigner = class {
25130
25112
  ...vkeyWitnesses
25131
25113
  ] : vkeyWitnesses;
25132
25114
  txWitnessSet2.setVkeys(
25133
- import_core7.Serialization.CborSet.fromCore(
25115
+ import_core6.Serialization.CborSet.fromCore(
25134
25116
  witnessSetVkeysValues,
25135
- import_core7.Serialization.VkeyWitness.fromCore
25117
+ import_core6.Serialization.VkeyWitness.fromCore
25136
25118
  )
25137
25119
  );
25138
- return new import_core7.Serialization.Transaction(
25120
+ return new import_core6.Serialization.Transaction(
25139
25121
  cardanoTx.body(),
25140
25122
  txWitnessSet2,
25141
25123
  cardanoTx.auxiliaryData()
25142
25124
  ).toCbor();
25143
25125
  }
25144
- const txWitnessSet = new import_core7.Serialization.TransactionWitnessSet();
25126
+ const txWitnessSet = new import_core6.Serialization.TransactionWitnessSet();
25145
25127
  txWitnessSet.setVkeys(
25146
- import_core7.Serialization.CborSet.fromCore(
25128
+ import_core6.Serialization.CborSet.fromCore(
25147
25129
  vkeyWitnesses,
25148
- import_core7.Serialization.VkeyWitness.fromCore
25130
+ import_core6.Serialization.VkeyWitness.fromCore
25149
25131
  )
25150
25132
  );
25151
25133
  return txWitnessSet.toCbor();
@@ -25179,7 +25161,7 @@ var CardanoSigner = class {
25179
25161
  };
25180
25162
 
25181
25163
  // src/cardano/utils/transaction-signers.ts
25182
- var import_core8 = require("@cardano-sdk/core");
25164
+ var import_core7 = require("@cardano-sdk/core");
25183
25165
  async function getRequiredSignersFromInputs(txBody, fetcher) {
25184
25166
  const requiredSigners = /* @__PURE__ */ new Set();
25185
25167
  let inputs = txBody.inputs().values();
@@ -25207,7 +25189,7 @@ async function getRequiredSignersFromInputs(txBody, fetcher) {
25207
25189
  });
25208
25190
  });
25209
25191
  for (const utxo of utxos) {
25210
- const address = import_core8.Cardano.Address.fromBech32(utxo.output.address);
25192
+ const address = import_core7.Cardano.Address.fromBech32(utxo.output.address);
25211
25193
  const addressProps = address.getProps();
25212
25194
  if (addressProps.paymentPart) {
25213
25195
  if (addressProps.paymentPart.type === 0 /* KeyHash */) {
@@ -25329,10 +25311,10 @@ function getRequiredSignersFromWithdrawals(txBody) {
25329
25311
  const withdrawals = txBody.withdrawals();
25330
25312
  if (withdrawals) {
25331
25313
  for (const rewardAccount of withdrawals.keys()) {
25332
- const address = import_core8.Cardano.Address.fromBech32(rewardAccount);
25314
+ const address = import_core7.Cardano.Address.fromBech32(rewardAccount);
25333
25315
  const addressType = address.getType();
25334
- if (addressType === import_core8.Cardano.AddressType.RewardKey) {
25335
- requiredSigners.add(import_core8.Cardano.RewardAccount.toHash(rewardAccount));
25316
+ if (addressType === import_core7.Cardano.AddressType.RewardKey) {
25317
+ requiredSigners.add(import_core7.Cardano.RewardAccount.toHash(rewardAccount));
25336
25318
  }
25337
25319
  }
25338
25320
  }
@@ -25389,6 +25371,24 @@ async function getTransactionRequiredSigners(transaction, fetcher) {
25389
25371
  return allRequiredSigners;
25390
25372
  }
25391
25373
 
25374
+ // src/cardano/utils/value.ts
25375
+ var import_core8 = require("@cardano-sdk/core");
25376
+ function mergeValue(a, b) {
25377
+ const ma = a.multiasset() ?? /* @__PURE__ */ new Map();
25378
+ b.multiasset()?.forEach((v, k) => {
25379
+ const newVal = (ma.get(k) ?? 0n) + v;
25380
+ if (newVal == 0n) {
25381
+ ma.delete(k);
25382
+ } else {
25383
+ ma.set(k, newVal);
25384
+ }
25385
+ });
25386
+ return new import_core8.Serialization.Value(
25387
+ BigInt(a.coin()) + BigInt(b.coin()),
25388
+ ma.size > 0 ? ma : void 0
25389
+ );
25390
+ }
25391
+
25392
25392
  // src/cardano/wallet/mesh/cardano-headless-wallet.ts
25393
25393
  var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
25394
25394
  constructor(networkId, addressManager, walletAddressType, fetcher, submitter) {
@@ -25649,9 +25649,7 @@ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
25649
25649
  transaction,
25650
25650
  this.fetcher
25651
25651
  );
25652
- const signersMap = await this.addressManager.getCredentialsSigners(
25653
- requiredSigners
25654
- );
25652
+ const signersMap = await this.addressManager.getCredentialsSigners(requiredSigners);
25655
25653
  if (!partialSign) {
25656
25654
  if (requiredSigners.size !== signersMap.size) {
25657
25655
  throw new Error("[CardanoWallet] Not all required signers found");
@@ -25801,26 +25799,12 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
25801
25799
  if (!this.fetcher) {
25802
25800
  throw new Error("[CardanoWallet] No fetcher provided");
25803
25801
  }
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)
25802
+ const collaterals = await this.getCollateral();
25803
+ return collaterals.map(
25804
+ (coll) => fromTxUnspentOutput(
25805
+ import_core10.Serialization.TransactionUnspentOutput.fromCbor((0, import_util6.HexBlob)(coll))
25806
+ )
25817
25807
  );
25818
- for (const utxo of sortedUtxos) {
25819
- if (getUtxoLovelaceValue(utxo) >= 5e6) {
25820
- return [utxo];
25821
- }
25822
- }
25823
- return [];
25824
25808
  }
25825
25809
  /**
25826
25810
  * Get the balance of the wallet.
package/dist/index.js CHANGED
@@ -25328,24 +25328,6 @@ var MeshCardanoBrowserWallet = class _MeshCardanoBrowserWallet extends CardanoBr
25328
25328
  // src/cardano/wallet/mesh/cardano-headless-wallet.ts
25329
25329
  import { Cardano as Cardano6, Serialization as Serialization6, setInConwayEra as setInConwayEra5 } from "@cardano-sdk/core";
25330
25330
 
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
25331
  // src/cardano/address/single-address-manager.ts
25350
25332
  import { setInConwayEra as setInConwayEra3 } from "@cardano-sdk/core";
25351
25333
  var AddressManager = class _AddressManager {
@@ -25494,7 +25476,7 @@ var AddressManager = class _AddressManager {
25494
25476
  };
25495
25477
 
25496
25478
  // src/cardano/signer/cardano-signer.ts
25497
- import { Serialization as Serialization4, setInConwayEra as setInConwayEra4 } from "@cardano-sdk/core";
25479
+ import { Serialization as Serialization3, setInConwayEra as setInConwayEra4 } from "@cardano-sdk/core";
25498
25480
  import { Ed25519PublicKeyHex, Ed25519SignatureHex as Ed25519SignatureHex2 } from "@cardano-sdk/crypto";
25499
25481
  import { HexBlob as HexBlob5 } from "@cardano-sdk/util";
25500
25482
  import {
@@ -25708,8 +25690,8 @@ var CardanoSigner = class {
25708
25690
  setInConwayEra4(true);
25709
25691
  }
25710
25692
  static async signTx(tx, signers, returnFullTx = false) {
25711
- const cardanoTx = Serialization4.Transaction.fromCbor(
25712
- Serialization4.TxCBOR(tx)
25693
+ const cardanoTx = Serialization3.Transaction.fromCbor(
25694
+ Serialization3.TxCBOR(tx)
25713
25695
  );
25714
25696
  const txHash = cardanoTx.body().hash();
25715
25697
  const vkeyWitnesses = [];
@@ -25727,22 +25709,22 @@ var CardanoSigner = class {
25727
25709
  ...vkeyWitnesses
25728
25710
  ] : vkeyWitnesses;
25729
25711
  txWitnessSet2.setVkeys(
25730
- Serialization4.CborSet.fromCore(
25712
+ Serialization3.CborSet.fromCore(
25731
25713
  witnessSetVkeysValues,
25732
- Serialization4.VkeyWitness.fromCore
25714
+ Serialization3.VkeyWitness.fromCore
25733
25715
  )
25734
25716
  );
25735
- return new Serialization4.Transaction(
25717
+ return new Serialization3.Transaction(
25736
25718
  cardanoTx.body(),
25737
25719
  txWitnessSet2,
25738
25720
  cardanoTx.auxiliaryData()
25739
25721
  ).toCbor();
25740
25722
  }
25741
- const txWitnessSet = new Serialization4.TransactionWitnessSet();
25723
+ const txWitnessSet = new Serialization3.TransactionWitnessSet();
25742
25724
  txWitnessSet.setVkeys(
25743
- Serialization4.CborSet.fromCore(
25725
+ Serialization3.CborSet.fromCore(
25744
25726
  vkeyWitnesses,
25745
- Serialization4.VkeyWitness.fromCore
25727
+ Serialization3.VkeyWitness.fromCore
25746
25728
  )
25747
25729
  );
25748
25730
  return txWitnessSet.toCbor();
@@ -25776,7 +25758,7 @@ var CardanoSigner = class {
25776
25758
  };
25777
25759
 
25778
25760
  // src/cardano/utils/transaction-signers.ts
25779
- import { Cardano as Cardano5 } from "@cardano-sdk/core";
25761
+ import { Cardano as Cardano4 } from "@cardano-sdk/core";
25780
25762
  async function getRequiredSignersFromInputs(txBody, fetcher) {
25781
25763
  const requiredSigners = /* @__PURE__ */ new Set();
25782
25764
  let inputs = txBody.inputs().values();
@@ -25804,7 +25786,7 @@ async function getRequiredSignersFromInputs(txBody, fetcher) {
25804
25786
  });
25805
25787
  });
25806
25788
  for (const utxo of utxos) {
25807
- const address = Cardano5.Address.fromBech32(utxo.output.address);
25789
+ const address = Cardano4.Address.fromBech32(utxo.output.address);
25808
25790
  const addressProps = address.getProps();
25809
25791
  if (addressProps.paymentPart) {
25810
25792
  if (addressProps.paymentPart.type === 0 /* KeyHash */) {
@@ -25926,10 +25908,10 @@ function getRequiredSignersFromWithdrawals(txBody) {
25926
25908
  const withdrawals = txBody.withdrawals();
25927
25909
  if (withdrawals) {
25928
25910
  for (const rewardAccount of withdrawals.keys()) {
25929
- const address = Cardano5.Address.fromBech32(rewardAccount);
25911
+ const address = Cardano4.Address.fromBech32(rewardAccount);
25930
25912
  const addressType = address.getType();
25931
- if (addressType === Cardano5.AddressType.RewardKey) {
25932
- requiredSigners.add(Cardano5.RewardAccount.toHash(rewardAccount));
25913
+ if (addressType === Cardano4.AddressType.RewardKey) {
25914
+ requiredSigners.add(Cardano4.RewardAccount.toHash(rewardAccount));
25933
25915
  }
25934
25916
  }
25935
25917
  }
@@ -25986,6 +25968,24 @@ async function getTransactionRequiredSigners(transaction, fetcher) {
25986
25968
  return allRequiredSigners;
25987
25969
  }
25988
25970
 
25971
+ // src/cardano/utils/value.ts
25972
+ import { Serialization as Serialization5 } from "@cardano-sdk/core";
25973
+ function mergeValue(a, b) {
25974
+ const ma = a.multiasset() ?? /* @__PURE__ */ new Map();
25975
+ b.multiasset()?.forEach((v, k) => {
25976
+ const newVal = (ma.get(k) ?? 0n) + v;
25977
+ if (newVal == 0n) {
25978
+ ma.delete(k);
25979
+ } else {
25980
+ ma.set(k, newVal);
25981
+ }
25982
+ });
25983
+ return new Serialization5.Value(
25984
+ BigInt(a.coin()) + BigInt(b.coin()),
25985
+ ma.size > 0 ? ma : void 0
25986
+ );
25987
+ }
25988
+
25989
25989
  // src/cardano/wallet/mesh/cardano-headless-wallet.ts
25990
25990
  var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
25991
25991
  constructor(networkId, addressManager, walletAddressType, fetcher, submitter) {
@@ -26246,9 +26246,7 @@ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
26246
26246
  transaction,
26247
26247
  this.fetcher
26248
26248
  );
26249
- const signersMap = await this.addressManager.getCredentialsSigners(
26250
- requiredSigners
26251
- );
26249
+ const signersMap = await this.addressManager.getCredentialsSigners(requiredSigners);
26252
26250
  if (!partialSign) {
26253
26251
  if (requiredSigners.size !== signersMap.size) {
26254
26252
  throw new Error("[CardanoWallet] Not all required signers found");
@@ -26398,26 +26396,12 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
26398
26396
  if (!this.fetcher) {
26399
26397
  throw new Error("[CardanoWallet] No fetcher provided");
26400
26398
  }
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)
26399
+ const collaterals = await this.getCollateral();
26400
+ return collaterals.map(
26401
+ (coll) => fromTxUnspentOutput(
26402
+ Serialization7.TransactionUnspentOutput.fromCbor(HexBlob6(coll))
26403
+ )
26414
26404
  );
26415
- for (const utxo of sortedUtxos) {
26416
- if (getUtxoLovelaceValue(utxo) >= 5e6) {
26417
- return [utxo];
26418
- }
26419
- }
26420
- return [];
26421
26405
  }
26422
26406
  /**
26423
26407
  * Get the balance of 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.8",
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,6 +31,7 @@
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
37
  "@types/jest": "^29.5.12",
@@ -38,18 +39,12 @@
38
39
  "eslint": "^8.57.0",
39
40
  "jest": "^29.7.0",
40
41
  "patch-package": "^8.0.1",
42
+ "prettier": "^3.5.3",
41
43
  "ts-jest": "^29.1.4",
42
44
  "ts-node": "^10.9.2",
43
45
  "tsup": "^8.0.2",
44
46
  "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"
47
+ "typescript": "^5.3.3"
53
48
  },
54
49
  "dependencies": {
55
50
  "@cardano-sdk/core": "0.46.11",