@meshsdk/transaction 1.7.6 → 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 +67 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +73 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1726,6 +1726,48 @@ var Transaction = class {
|
|
|
1726
1726
|
this.txBuilder = new MeshTxBuilder(options);
|
|
1727
1727
|
this.initiator = options.initiator;
|
|
1728
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
|
+
}
|
|
1729
1771
|
/**
|
|
1730
1772
|
* Adds an output to the transaction.
|
|
1731
1773
|
*
|
|
@@ -2211,6 +2253,31 @@ var Transaction = class {
|
|
|
2211
2253
|
}
|
|
2212
2254
|
}
|
|
2213
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
|
+
}
|
|
2214
2281
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2215
2282
|
0 && (module.exports = {
|
|
2216
2283
|
ForgeScript,
|
package/dist/index.d.cts
CHANGED
|
@@ -513,6 +513,11 @@ declare class Transaction {
|
|
|
513
513
|
initiator: IInitiator;
|
|
514
514
|
isCollateralNeeded: boolean;
|
|
515
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;
|
|
516
521
|
/**
|
|
517
522
|
* Adds an output to the transaction.
|
|
518
523
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -513,6 +513,11 @@ declare class Transaction {
|
|
|
513
513
|
initiator: IInitiator;
|
|
514
514
|
isCollateralNeeded: boolean;
|
|
515
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;
|
|
516
521
|
/**
|
|
517
522
|
* Adds an output to the transaction.
|
|
518
523
|
*
|
package/dist/index.js
CHANGED
|
@@ -1699,9 +1699,14 @@ import {
|
|
|
1699
1699
|
SUPPORTED_TOKENS
|
|
1700
1700
|
} from "@meshsdk/common";
|
|
1701
1701
|
import {
|
|
1702
|
+
Cardano,
|
|
1703
|
+
CardanoSDKUtil,
|
|
1704
|
+
deserializeTx,
|
|
1702
1705
|
deserializeNativeScript,
|
|
1703
1706
|
deserializePlutusScript,
|
|
1704
|
-
fromScriptRef
|
|
1707
|
+
fromScriptRef,
|
|
1708
|
+
Serialization,
|
|
1709
|
+
Transaction as Tx
|
|
1705
1710
|
} from "@meshsdk/core-cst";
|
|
1706
1711
|
var Transaction = class {
|
|
1707
1712
|
txBuilder;
|
|
@@ -1711,6 +1716,48 @@ var Transaction = class {
|
|
|
1711
1716
|
this.txBuilder = new MeshTxBuilder(options);
|
|
1712
1717
|
this.initiator = options.initiator;
|
|
1713
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
|
+
}
|
|
1714
1761
|
/**
|
|
1715
1762
|
* Adds an output to the transaction.
|
|
1716
1763
|
*
|
|
@@ -2196,6 +2243,31 @@ var Transaction = class {
|
|
|
2196
2243
|
}
|
|
2197
2244
|
}
|
|
2198
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
|
+
}
|
|
2199
2271
|
export {
|
|
2200
2272
|
ForgeScript,
|
|
2201
2273
|
MeshTxBuilder,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshsdk/transaction",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"browser": "./dist/index.js",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"typescript": "^5.3.3"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@meshsdk/common": "1.7.
|
|
39
|
-
"@meshsdk/core-csl": "1.7.
|
|
40
|
-
"@meshsdk/core-cst": "1.7.
|
|
38
|
+
"@meshsdk/common": "1.7.7",
|
|
39
|
+
"@meshsdk/core-csl": "1.7.7",
|
|
40
|
+
"@meshsdk/core-cst": "1.7.7",
|
|
41
41
|
"json-bigint": "^1.0.0"
|
|
42
42
|
},
|
|
43
43
|
"prettier": "@meshsdk/configs/prettier",
|