@meshsdk/transaction 1.7.5 → 1.7.7

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
@@ -905,6 +905,22 @@ var MeshTxBuilderCore = class {
905
905
  });
906
906
  return this;
907
907
  };
908
+ /**
909
+ * Update DRep certificate, and adds it to the transaction
910
+ * @param drepId The bech32 drep id (i.e. starts with `drep1xxxxx`)
911
+ * @param anchor The DRep anchor, consists of a URL and a hash of the doc
912
+ */
913
+ drepUpdateCertificate = (drepId, anchor) => {
914
+ this.meshTxBuilderBody.certificates.push({
915
+ type: "BasicCertificate",
916
+ certType: {
917
+ type: "DRepUpdate",
918
+ drepId,
919
+ anchor
920
+ }
921
+ });
922
+ return this;
923
+ };
908
924
  /**
909
925
  * Dregister DRep certificate, and adds it to the transaction
910
926
  * @param drepId The bech32 drep id (i.e. starts with `drep1xxxxx`)
@@ -1710,6 +1726,48 @@ var Transaction = class {
1710
1726
  this.txBuilder = new MeshTxBuilder(options);
1711
1727
  this.initiator = options.initiator;
1712
1728
  }
1729
+ static attachMetadata(cborTx, cborTxMetadata) {
1730
+ const tx = (0, import_core_cst2.deserializeTx)(cborTx);
1731
+ const txAuxData = tx.auxiliaryData() ?? new import_core_cst2.Serialization.AuxiliaryData();
1732
+ txAuxData.setMetadata(
1733
+ import_core_cst2.Serialization.GeneralTransactionMetadata.fromCbor(import_core_cst2.CardanoSDKUtil.HexBlob(cborTxMetadata))
1734
+ );
1735
+ if (import_core_cst2.Cardano.computeAuxiliaryDataHash(txAuxData.toCore())?.toString() !== tx.body().auxiliaryDataHash()?.toString()) {
1736
+ throw new Error(
1737
+ "[Transaction] attachMetadata: The metadata hash does not match the auxiliary data hash."
1738
+ );
1739
+ }
1740
+ return new import_core_cst2.Transaction(tx.body(), tx.witnessSet(), txAuxData).toCbor().toString();
1741
+ }
1742
+ static deattachMetadata(cborTx) {
1743
+ const tx = (0, import_core_cst2.deserializeTx)(cborTx);
1744
+ return new import_core_cst2.Transaction(tx.body(), tx.witnessSet()).toCbor().toString();
1745
+ }
1746
+ static maskMetadata(cborTx) {
1747
+ const tx = (0, import_core_cst2.deserializeTx)(cborTx);
1748
+ const txMetadata = tx.auxiliaryData()?.metadata();
1749
+ if (txMetadata !== void 0) {
1750
+ const mockMetadata = /* @__PURE__ */ new Map();
1751
+ txMetadata.metadata()?.forEach((metadatum, label) => mockMetadata.set(label, mask(metadatum)));
1752
+ const txAuxData = tx.auxiliaryData();
1753
+ txMetadata.setMetadata(mockMetadata);
1754
+ txAuxData?.setMetadata(txMetadata);
1755
+ return new import_core_cst2.Transaction(tx.body(), tx.witnessSet(), txAuxData).toCbor().toString();
1756
+ }
1757
+ return cborTx;
1758
+ }
1759
+ static readMetadata(cborTx) {
1760
+ const tx = (0, import_core_cst2.deserializeTx)(cborTx);
1761
+ return tx.auxiliaryData()?.metadata()?.toCbor().toString() ?? "";
1762
+ }
1763
+ static writeMetadata(cborTx, cborTxMetadata) {
1764
+ const tx = (0, import_core_cst2.deserializeTx)(cborTx);
1765
+ const txAuxData = tx.auxiliaryData() ?? new import_core_cst2.Serialization.AuxiliaryData();
1766
+ txAuxData.setMetadata(
1767
+ import_core_cst2.Serialization.GeneralTransactionMetadata.fromCbor(import_core_cst2.CardanoSDKUtil.HexBlob(cborTxMetadata))
1768
+ );
1769
+ return new import_core_cst2.Transaction(tx.body(), tx.witnessSet(), txAuxData).toCbor().toString();
1770
+ }
1713
1771
  /**
1714
1772
  * Adds an output to the transaction.
1715
1773
  *
@@ -2195,6 +2253,31 @@ var Transaction = class {
2195
2253
  }
2196
2254
  }
2197
2255
  };
2256
+ function mask(metadatum) {
2257
+ switch (metadatum.getKind()) {
2258
+ case import_core_cst2.Serialization.TransactionMetadatumKind.Text:
2259
+ return import_core_cst2.Serialization.TransactionMetadatum.newText("0".repeat(metadatum.asText()?.length ?? 0));
2260
+ case import_core_cst2.Serialization.TransactionMetadatumKind.Bytes:
2261
+ case import_core_cst2.Serialization.TransactionMetadatumKind.Integer:
2262
+ return metadatum;
2263
+ case import_core_cst2.Serialization.TransactionMetadatumKind.List:
2264
+ const list = new import_core_cst2.Serialization.MetadatumList();
2265
+ for (let i = 0; i < (metadatum.asList()?.getLength() ?? 0); i++) {
2266
+ list.add(mask(metadatum.asList()?.get(i)));
2267
+ }
2268
+ return import_core_cst2.Serialization.TransactionMetadatum.newList(list);
2269
+ case import_core_cst2.Serialization.TransactionMetadatumKind.Map:
2270
+ const map = new import_core_cst2.Serialization.MetadatumMap();
2271
+ for (let i = 0; i < (metadatum.asMap()?.getLength() ?? 0); i++) {
2272
+ const key = metadatum.asMap()?.getKeys().get(i);
2273
+ const value = metadatum.asMap()?.get(key);
2274
+ map.insert(key, mask(value));
2275
+ }
2276
+ return import_core_cst2.Serialization.TransactionMetadatum.newMap(map);
2277
+ default:
2278
+ throw new Error(`Unsupported metadatum kind: ${metadatum.getKind()}`);
2279
+ }
2280
+ }
2198
2281
  // Annotate the CommonJS export names for ESM import in node:
2199
2282
  0 && (module.exports = {
2200
2283
  ForgeScript,
package/dist/index.d.cts CHANGED
@@ -336,6 +336,12 @@ declare class MeshTxBuilderCore {
336
336
  * @returns The MeshTxBuilder instance
337
337
  */
338
338
  drepDeregistrationCertificate: (drepId: string, coin?: string) => this;
339
+ /**
340
+ * Update DRep certificate, and adds it to the transaction
341
+ * @param drepId The bech32 drep id (i.e. starts with `drep1xxxxx`)
342
+ * @param anchor The DRep anchor, consists of a URL and a hash of the doc
343
+ */
344
+ drepUpdateCertificate: (drepId: string, anchor?: Anchor) => this;
339
345
  /**
340
346
  * Dregister DRep certificate, and adds it to the transaction
341
347
  * @param drepId The bech32 drep id (i.e. starts with `drep1xxxxx`)
@@ -507,6 +513,11 @@ declare class Transaction {
507
513
  initiator: IInitiator;
508
514
  isCollateralNeeded: boolean;
509
515
  constructor(options: TransactionOptions);
516
+ static attachMetadata(cborTx: string, cborTxMetadata: string): string;
517
+ static deattachMetadata(cborTx: string): string;
518
+ static maskMetadata(cborTx: string): string;
519
+ static readMetadata(cborTx: string): string;
520
+ static writeMetadata(cborTx: string, cborTxMetadata: string): string;
510
521
  /**
511
522
  * Adds an output to the transaction.
512
523
  *
package/dist/index.d.ts CHANGED
@@ -336,6 +336,12 @@ declare class MeshTxBuilderCore {
336
336
  * @returns The MeshTxBuilder instance
337
337
  */
338
338
  drepDeregistrationCertificate: (drepId: string, coin?: string) => this;
339
+ /**
340
+ * Update DRep certificate, and adds it to the transaction
341
+ * @param drepId The bech32 drep id (i.e. starts with `drep1xxxxx`)
342
+ * @param anchor The DRep anchor, consists of a URL and a hash of the doc
343
+ */
344
+ drepUpdateCertificate: (drepId: string, anchor?: Anchor) => this;
339
345
  /**
340
346
  * Dregister DRep certificate, and adds it to the transaction
341
347
  * @param drepId The bech32 drep id (i.e. starts with `drep1xxxxx`)
@@ -507,6 +513,11 @@ declare class Transaction {
507
513
  initiator: IInitiator;
508
514
  isCollateralNeeded: boolean;
509
515
  constructor(options: TransactionOptions);
516
+ static attachMetadata(cborTx: string, cborTxMetadata: string): string;
517
+ static deattachMetadata(cborTx: string): string;
518
+ static maskMetadata(cborTx: string): string;
519
+ static readMetadata(cborTx: string): string;
520
+ static writeMetadata(cborTx: string, cborTxMetadata: string): string;
510
521
  /**
511
522
  * Adds an output to the transaction.
512
523
  *
package/dist/index.js CHANGED
@@ -872,6 +872,22 @@ var MeshTxBuilderCore = class {
872
872
  });
873
873
  return this;
874
874
  };
875
+ /**
876
+ * Update DRep certificate, and adds it to the transaction
877
+ * @param drepId The bech32 drep id (i.e. starts with `drep1xxxxx`)
878
+ * @param anchor The DRep anchor, consists of a URL and a hash of the doc
879
+ */
880
+ drepUpdateCertificate = (drepId, anchor) => {
881
+ this.meshTxBuilderBody.certificates.push({
882
+ type: "BasicCertificate",
883
+ certType: {
884
+ type: "DRepUpdate",
885
+ drepId,
886
+ anchor
887
+ }
888
+ });
889
+ return this;
890
+ };
875
891
  /**
876
892
  * Dregister DRep certificate, and adds it to the transaction
877
893
  * @param drepId The bech32 drep id (i.e. starts with `drep1xxxxx`)
@@ -1683,9 +1699,14 @@ import {
1683
1699
  SUPPORTED_TOKENS
1684
1700
  } from "@meshsdk/common";
1685
1701
  import {
1702
+ Cardano,
1703
+ CardanoSDKUtil,
1704
+ deserializeTx,
1686
1705
  deserializeNativeScript,
1687
1706
  deserializePlutusScript,
1688
- fromScriptRef
1707
+ fromScriptRef,
1708
+ Serialization,
1709
+ Transaction as Tx
1689
1710
  } from "@meshsdk/core-cst";
1690
1711
  var Transaction = class {
1691
1712
  txBuilder;
@@ -1695,6 +1716,48 @@ var Transaction = class {
1695
1716
  this.txBuilder = new MeshTxBuilder(options);
1696
1717
  this.initiator = options.initiator;
1697
1718
  }
1719
+ static attachMetadata(cborTx, cborTxMetadata) {
1720
+ const tx = deserializeTx(cborTx);
1721
+ const txAuxData = tx.auxiliaryData() ?? new Serialization.AuxiliaryData();
1722
+ txAuxData.setMetadata(
1723
+ Serialization.GeneralTransactionMetadata.fromCbor(CardanoSDKUtil.HexBlob(cborTxMetadata))
1724
+ );
1725
+ if (Cardano.computeAuxiliaryDataHash(txAuxData.toCore())?.toString() !== tx.body().auxiliaryDataHash()?.toString()) {
1726
+ throw new Error(
1727
+ "[Transaction] attachMetadata: The metadata hash does not match the auxiliary data hash."
1728
+ );
1729
+ }
1730
+ return new Tx(tx.body(), tx.witnessSet(), txAuxData).toCbor().toString();
1731
+ }
1732
+ static deattachMetadata(cborTx) {
1733
+ const tx = deserializeTx(cborTx);
1734
+ return new Tx(tx.body(), tx.witnessSet()).toCbor().toString();
1735
+ }
1736
+ static maskMetadata(cborTx) {
1737
+ const tx = deserializeTx(cborTx);
1738
+ const txMetadata = tx.auxiliaryData()?.metadata();
1739
+ if (txMetadata !== void 0) {
1740
+ const mockMetadata = /* @__PURE__ */ new Map();
1741
+ txMetadata.metadata()?.forEach((metadatum, label) => mockMetadata.set(label, mask(metadatum)));
1742
+ const txAuxData = tx.auxiliaryData();
1743
+ txMetadata.setMetadata(mockMetadata);
1744
+ txAuxData?.setMetadata(txMetadata);
1745
+ return new Tx(tx.body(), tx.witnessSet(), txAuxData).toCbor().toString();
1746
+ }
1747
+ return cborTx;
1748
+ }
1749
+ static readMetadata(cborTx) {
1750
+ const tx = deserializeTx(cborTx);
1751
+ return tx.auxiliaryData()?.metadata()?.toCbor().toString() ?? "";
1752
+ }
1753
+ static writeMetadata(cborTx, cborTxMetadata) {
1754
+ const tx = deserializeTx(cborTx);
1755
+ const txAuxData = tx.auxiliaryData() ?? new Serialization.AuxiliaryData();
1756
+ txAuxData.setMetadata(
1757
+ Serialization.GeneralTransactionMetadata.fromCbor(CardanoSDKUtil.HexBlob(cborTxMetadata))
1758
+ );
1759
+ return new Tx(tx.body(), tx.witnessSet(), txAuxData).toCbor().toString();
1760
+ }
1698
1761
  /**
1699
1762
  * Adds an output to the transaction.
1700
1763
  *
@@ -2180,6 +2243,31 @@ var Transaction = class {
2180
2243
  }
2181
2244
  }
2182
2245
  };
2246
+ function mask(metadatum) {
2247
+ switch (metadatum.getKind()) {
2248
+ case Serialization.TransactionMetadatumKind.Text:
2249
+ return Serialization.TransactionMetadatum.newText("0".repeat(metadatum.asText()?.length ?? 0));
2250
+ case Serialization.TransactionMetadatumKind.Bytes:
2251
+ case Serialization.TransactionMetadatumKind.Integer:
2252
+ return metadatum;
2253
+ case Serialization.TransactionMetadatumKind.List:
2254
+ const list = new Serialization.MetadatumList();
2255
+ for (let i = 0; i < (metadatum.asList()?.getLength() ?? 0); i++) {
2256
+ list.add(mask(metadatum.asList()?.get(i)));
2257
+ }
2258
+ return Serialization.TransactionMetadatum.newList(list);
2259
+ case Serialization.TransactionMetadatumKind.Map:
2260
+ const map = new Serialization.MetadatumMap();
2261
+ for (let i = 0; i < (metadatum.asMap()?.getLength() ?? 0); i++) {
2262
+ const key = metadatum.asMap()?.getKeys().get(i);
2263
+ const value = metadatum.asMap()?.get(key);
2264
+ map.insert(key, mask(value));
2265
+ }
2266
+ return Serialization.TransactionMetadatum.newMap(map);
2267
+ default:
2268
+ throw new Error(`Unsupported metadatum kind: ${metadatum.getKind()}`);
2269
+ }
2270
+ }
2183
2271
  export {
2184
2272
  ForgeScript,
2185
2273
  MeshTxBuilder,
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@meshsdk/transaction",
3
- "version": "1.7.5",
3
+ "version": "1.7.7",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
+ "browser": "./dist/index.js",
6
7
  "module": "./dist/index.js",
7
8
  "types": "./dist/index.d.ts",
8
9
  "type": "module",
@@ -34,9 +35,9 @@
34
35
  "typescript": "^5.3.3"
35
36
  },
36
37
  "dependencies": {
37
- "@meshsdk/common": "1.7.5",
38
- "@meshsdk/core-csl": "1.7.5",
39
- "@meshsdk/core-cst": "1.7.5",
38
+ "@meshsdk/common": "1.7.7",
39
+ "@meshsdk/core-csl": "1.7.7",
40
+ "@meshsdk/core-cst": "1.7.7",
40
41
  "json-bigint": "^1.0.0"
41
42
  },
42
43
  "prettier": "@meshsdk/configs/prettier",