@meshsdk/core 1.9.0-beta.1 → 1.9.0-beta.100

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/README.md CHANGED
@@ -8,20 +8,20 @@
8
8
 
9
9
  <h1 style="border-bottom: none"><a href='https://meshjs.dev/'>Mesh</a> TypeScript SDK</h1>
10
10
 
11
- [![Licence](https://img.shields.io/github/license/meshjs/mesh)](https://github.com/meshjs/mesh/blob/master/LICENSE)
12
- [![Build](https://github.com/meshjs/mesh/actions/workflows/build.yml/badge.svg)](https://github.com/meshjs/mesh/actions/workflows/build.yml)
13
- [![Package](https://github.com/meshjs/mesh/actions/workflows/publish.yml/badge.svg)](https://github.com/meshjs/mesh/actions/workflows/publish.yml)
11
+ [![Licence](https://img.shields.io/github/license/meshjs/mesh)](https://github.com/meshjs/mesh/blob/master/LICENSE)
12
+ [![Build](https://github.com/meshjs/mesh/actions/workflows/build.yml/badge.svg)](https://github.com/meshjs/mesh/actions/workflows/build.yml)
13
+ [![Package](https://github.com/meshjs/mesh/actions/workflows/publish.yml/badge.svg)](https://github.com/meshjs/mesh/actions/workflows/publish.yml)
14
14
 
15
- [![Twitter/X](https://img.shields.io/badge/Follow%20us-@MeshJS-blue?logo=x&style=for-the-badge)](https://x.com/meshsdk)
16
- [![NPM](https://img.shields.io/npm/v/%40meshsdk%2Fcore?style=for-the-badge)](https://www.npmjs.com/package/@meshsdk/core)
15
+ [![Twitter/X](https://img.shields.io/badge/Follow%20us-@MeshJS-blue?logo=x&style=for-the-badge)](https://x.com/meshsdk)
16
+ [![NPM](https://img.shields.io/npm/v/%40meshsdk%2Fcore?style=for-the-badge)](https://www.npmjs.com/package/@meshsdk/core)
17
17
 
18
- <strong>All-in-one TypeScript SDK for Cardano apps</strong>
18
+ <strong>All-in-one TypeScript SDK for Cardano apps</strong>
19
19
 
20
20
  </div>
21
21
 
22
22
  <hr />
23
23
 
24
- Mesh is an open-source library designed to make building dApps accessible. Whether you're a beginner developer, startup, web3 market leader, or a large enterprise, Mesh makes web3 development easy with reliable, scalable, and well-engineered APIs & developer tools.
24
+ Mesh is an open-source library designed to make building applications accessible. Whether you're a beginner developer, startup, web3 market leader, or a large enterprise, Mesh makes web3 development easy with reliable, scalable, and well-engineered APIs & developer tools.
25
25
 
26
26
  Explore the features on [Mesh Playground](https://meshjs.dev/).
27
27
 
@@ -31,48 +31,54 @@ Instant setup a new project with a single command using Mesh CLI and start build
31
31
  npx meshjs your-app-name
32
32
  ```
33
33
 
34
+ Or install the core package:
35
+
36
+ ```bash
37
+ npm install @meshsdk/core
38
+ ```
39
+
34
40
  ## What's inside?
35
41
 
36
42
  ### Packages
37
43
 
38
44
  A collection of packages that provide different functionalities to interact with the Cardano blockchain.
39
45
 
40
- | | Description | Docs | Playground |
41
- | --- | --- | --- | --- |
42
- | [@meshsdk/common](https://github.com/MeshJS/mesh/tree/main/packages/mesh-common) | Contains constants, types and interfaces used across the SDK and different serialization libraries | [:page_facing_up:](https://docs.meshjs.dev/common) | |
43
- | [@meshsdk/contract](https://github.com/MeshJS/mesh/tree/main/packages/mesh-contract) | A collection of smart contracts and its transactions | [:page_facing_up:](https://docs.meshjs.dev/contracts) | [:shipit:](https://meshjs.dev/smart-contracts) |
44
- | [@meshsdk/core](https://github.com/MeshJS/mesh/tree/main/packages/mesh-core) | Exports all the functionalities including wallets, transactions, and providers | | [:shipit:](https://meshjs.dev/) |
45
- | [@meshsdk/core-csl](https://github.com/MeshJS/mesh/tree/main/packages/mesh-core-csl) | Types and utilities functions between Mesh and cardano-serialization-lib | [:page_facing_up:](https://docs.meshjs.dev/core-csl) | |
46
- | [@meshsdk/core-cst](https://github.com/MeshJS/mesh/tree/main/packages/mesh-core-cst) | Types and utilities functions between Mesh and cardano-js-sdk | [:page_facing_up:](https://docs.meshjs.dev/core-cst) | |
47
- | [@meshsdk/provider](https://github.com/MeshJS/mesh/tree/main/packages/mesh-provider) | Blockchain data providers | [:page_facing_up:](https://docs.meshjs.dev/providers) | [:shipit:](https://meshjs.dev/providers) |
48
- | [@meshsdk/react](https://github.com/MeshJS/mesh/tree/main/packages/mesh-react) | React component library | | [:shipit:](https://meshjs.dev/react) |
49
- | [@meshsdk/transaction](https://github.com/MeshJS/mesh/tree/main/packages/mesh-transaction) | Transactions to send assets, mint tokens, and interact with smart contracts | [:page_facing_up:](https://docs.meshjs.dev/transactions) | [:shipit:](https://meshjs.dev/apis/transaction) |
50
- | [@meshsdk/wallet](https://github.com/MeshJS/mesh/tree/main/packages/mesh-wallet) | Wallets to manage assets and interact with the blockchain | [:page_facing_up:](https://docs.meshjs.dev/wallets) | [:shipit:](https://meshjs.dev/apis/wallets) |
46
+ | | Description | Docs | Playground |
47
+ | ------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------- | ----------------------------------------------- |
48
+ | [@meshsdk/common](https://github.com/MeshJS/mesh/tree/main/packages/mesh-common) | Contains constants, types and interfaces used across the SDK and different serialization libraries | [:page_facing_up:](https://docs.meshjs.dev/common) | |
49
+ | [@meshsdk/contract](https://github.com/MeshJS/mesh/tree/main/packages/mesh-contract) | A collection of smart contracts and its transactions | [:page_facing_up:](https://docs.meshjs.dev/contracts) | [:shipit:](https://meshjs.dev/smart-contracts) |
50
+ | [@meshsdk/core](https://github.com/MeshJS/mesh/tree/main/packages/mesh-core) | Exports all the functionalities including wallets, transactions, and providers | | [:shipit:](https://meshjs.dev/) |
51
+ | [@meshsdk/core-csl](https://github.com/MeshJS/mesh/tree/main/packages/mesh-core-csl) | Types and utilities functions between Mesh and cardano-serialization-lib | [:page_facing_up:](https://docs.meshjs.dev/core-csl) | |
52
+ | [@meshsdk/core-cst](https://github.com/MeshJS/mesh/tree/main/packages/mesh-core-cst) | Types and utilities functions between Mesh and cardano-js-sdk | [:page_facing_up:](https://docs.meshjs.dev/core-cst) | |
53
+ | [@meshsdk/provider](https://github.com/MeshJS/mesh/tree/main/packages/mesh-provider) | Blockchain data providers | [:page_facing_up:](https://docs.meshjs.dev/providers) | [:shipit:](https://meshjs.dev/providers) |
54
+ | [@meshsdk/react](https://github.com/MeshJS/mesh/tree/main/packages/mesh-react) | React component library | | [:shipit:](https://meshjs.dev/react) |
55
+ | [@meshsdk/transaction](https://github.com/MeshJS/mesh/tree/main/packages/mesh-transaction) | Transactions to send assets, mint tokens, and interact with smart contracts | [:page_facing_up:](https://docs.meshjs.dev/transactions) | [:shipit:](https://meshjs.dev/apis/transaction) |
56
+ | [@meshsdk/wallet](https://github.com/MeshJS/mesh/tree/main/packages/mesh-wallet) | Wallets to manage assets and interact with the blockchain | [:page_facing_up:](https://docs.meshjs.dev/wallets) | [:shipit:](https://meshjs.dev/apis/wallets) |
51
57
 
52
58
  ### Apps
53
59
 
54
60
  Frontend documentation and live demos for Mesh SDK.
55
61
 
56
- | | Description | Website |
57
- | --- | --- | --- |
58
- | [apps/docs](https://github.com/MeshJS/mesh/tree/main/apps/docs) | Mesh technical docs | [:shipit:](https://docs.meshjs.dev/) |
59
- | [apps/playground](https://github.com/MeshJS/mesh/tree/main/apps/playground) | Mesh homepage and live demos | [:shipit:](https://meshjs.dev/) |
62
+ | | Description | Website |
63
+ | --------------------------------------------------------------------------- | ---------------------------- | ------------------------------------ |
64
+ | [apps/docs](https://github.com/MeshJS/mesh/tree/main/apps/docs) | Mesh technical docs | [:shipit:](https://docs.meshjs.dev/) |
65
+ | [apps/playground](https://github.com/MeshJS/mesh/tree/main/apps/playground) | Mesh homepage and live demos | [:shipit:](https://meshjs.dev/) |
60
66
 
61
67
  ### Mesh Smart Contracts Library
62
68
 
63
69
  Here's a list of open-source smart contracts, complete with documentation, live demos, and end-to-end source code.
64
70
 
65
- | Contract | Description | Links |
66
- | --- | --- | --- |
67
- | Content Ownership | Create a content registry and users can create content that is stored in the registry | [[demo](https://meshjs.dev/smart-contracts/content-ownership)] [[source](https://github.com/MeshJS/mesh/tree/main/packages/mesh-contract/src/content-ownership)] [[docs](https://docs.meshjs.dev/contracts/classes/MeshContentOwnershipContract)] |
68
- | Escrow | Facilitates the secure exchange of assets between two parties by acting as a trusted intermediary that holds the assets until the conditions of the agreement are met | [[demo](https://meshjs.dev/smart-contracts/escrow)] [[source](https://github.com/MeshJS/mesh/tree/main/packages/mesh-contract/src/escrow)] [[docs](https://docs.meshjs.dev/contracts/classes/MeshEscrowContract)] |
69
- | Giftcard | Allows users to create a transactions to lock assets into the smart contract, which can be redeemed by any user | [[demo](https://meshjs.dev/smart-contracts/giftcard)] [[source](https://github.com/MeshJS/mesh/tree/main/packages/mesh-contract/src/giftcard)] [[docs](https://docs.meshjs.dev/contracts/classes/MeshGiftcardContract)] |
70
- | Hello World | A simple lock-and-unlock assets contract, providing a hands-on introduction to end-to-end smart contract validation and transaction building | [[demo](https://meshjs.dev/smart-contracts/hello-world)] [[source](https://github.com/MeshJS/mesh/tree/main/packages/mesh-contract/src/hello-world)] [[docs](https://docs.meshjs.dev/contracts/classes/MeshHelloWorldContract)] |
71
- | Marketplace | Allows anyone to buy and sell native assets such as NFTs | [[demo](https://meshjs.dev/smart-contracts/marketplace)] [[source](https://github.com/MeshJS/mesh/tree/main/packages/mesh-contract/src/marketplace)] [[docs](https://docs.meshjs.dev/contracts/classes/MeshMarketplaceContract)] |
72
- | NFT Minting Machine | Mint NFTs with an automatically incremented index, which increases by one for each newly minted NFT | [[demo](https://meshjs.dev/smart-contracts/plutus-nft)] [[source](https://github.com/MeshJS/mesh/tree/main/packages/mesh-contract/src/plutus-nft)] [[docs](https://docs.meshjs.dev/contracts/classes/MeshPlutusNFTContract)] |
73
- | Payment Splitter | Allows users to split incoming payments among a group of accounts | [[demo](https://meshjs.dev/smart-contracts/payment-splitter)] [[source](https://github.com/MeshJS/mesh/tree/main/packages/mesh-contract/src/payment-splitter)] [[docs](https://docs.meshjs.dev/contracts/classes/MeshPaymentSplitterContract)] |
74
- | Swap | Facilitates the exchange of assets between two parties | [[demo](https://meshjs.dev/smart-contracts/swap)] [[source](https://github.com/MeshJS/mesh/tree/main/packages/mesh-contract/src/swap)] [[docs](https://docs.meshjs.dev/contracts/classes/MeshSwapContract)] |
75
- | Vesting | Allows users to lock tokens for a period of time and withdraw the funds after the lockup period | [[demo](https://meshjs.dev/smart-contracts/vesting)] [[source](https://github.com/MeshJS/mesh/tree/main/packages/mesh-contract/src/vesting)] [[docs](https://docs.meshjs.dev/contracts/classes/MeshVestingContract)] |
71
+ | Contract | Description | Links |
72
+ | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
73
+ | Content Ownership | Create a content registry and users can create content that is stored in the registry | [[demo](https://meshjs.dev/smart-contracts/content-ownership)] [[source](https://github.com/MeshJS/mesh/tree/main/packages/mesh-contract/src/content-ownership)] [[docs](https://docs.meshjs.dev/contracts/classes/MeshContentOwnershipContract)] |
74
+ | Escrow | Facilitates the secure exchange of assets between two parties by acting as a trusted intermediary that holds the assets until the conditions of the agreement are met | [[demo](https://meshjs.dev/smart-contracts/escrow)] [[source](https://github.com/MeshJS/mesh/tree/main/packages/mesh-contract/src/escrow)] [[docs](https://docs.meshjs.dev/contracts/classes/MeshEscrowContract)] |
75
+ | Giftcard | Allows users to create a transactions to lock assets into the smart contract, which can be redeemed by any user | [[demo](https://meshjs.dev/smart-contracts/giftcard)] [[source](https://github.com/MeshJS/mesh/tree/main/packages/mesh-contract/src/giftcard)] [[docs](https://docs.meshjs.dev/contracts/classes/MeshGiftcardContract)] |
76
+ | Hello World | A simple lock-and-unlock assets contract, providing a hands-on introduction to end-to-end smart contract validation and transaction building | [[demo](https://meshjs.dev/smart-contracts/hello-world)] [[source](https://github.com/MeshJS/mesh/tree/main/packages/mesh-contract/src/hello-world)] [[docs](https://docs.meshjs.dev/contracts/classes/MeshHelloWorldContract)] |
77
+ | Marketplace | Allows anyone to buy and sell native assets such as NFTs | [[demo](https://meshjs.dev/smart-contracts/marketplace)] [[source](https://github.com/MeshJS/mesh/tree/main/packages/mesh-contract/src/marketplace)] [[docs](https://docs.meshjs.dev/contracts/classes/MeshMarketplaceContract)] |
78
+ | NFT Minting Machine | Mint NFTs with an automatically incremented index, which increases by one for each newly minted NFT | [[demo](https://meshjs.dev/smart-contracts/plutus-nft)] [[source](https://github.com/MeshJS/mesh/tree/main/packages/mesh-contract/src/plutus-nft)] [[docs](https://docs.meshjs.dev/contracts/classes/MeshPlutusNFTContract)] |
79
+ | Payment Splitter | Allows users to split incoming payments among a group of accounts | [[demo](https://meshjs.dev/smart-contracts/payment-splitter)] [[source](https://github.com/MeshJS/mesh/tree/main/packages/mesh-contract/src/payment-splitter)] [[docs](https://docs.meshjs.dev/contracts/classes/MeshPaymentSplitterContract)] |
80
+ | Swap | Facilitates the exchange of assets between two parties | [[demo](https://meshjs.dev/smart-contracts/swap)] [[source](https://github.com/MeshJS/mesh/tree/main/packages/mesh-contract/src/swap)] [[docs](https://docs.meshjs.dev/contracts/classes/MeshSwapContract)] |
81
+ | Vesting | Allows users to lock tokens for a period of time and withdraw the funds after the lockup period | [[demo](https://meshjs.dev/smart-contracts/vesting)] [[source](https://github.com/MeshJS/mesh/tree/main/packages/mesh-contract/src/vesting)] [[docs](https://docs.meshjs.dev/contracts/classes/MeshVestingContract)] |
76
82
 
77
83
  ## Usage
78
84
 
package/dist/index.cjs CHANGED
@@ -31,15 +31,18 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  // src/index.ts
32
32
  var index_exports = {};
33
33
  __export(index_exports, {
34
+ MintingBlueprint: () => MintingBlueprint,
35
+ SpendingBlueprint: () => SpendingBlueprint,
36
+ WithdrawalBlueprint: () => WithdrawalBlueprint,
34
37
  applyCborEncoding: () => applyCborEncoding,
35
38
  applyParamsToScript: () => applyParamsToScript2,
36
- checkSignature: () => import_core_cst.checkSignature,
39
+ checkSignature: () => import_core_cst2.checkSignature,
37
40
  core: () => core,
38
41
  cst: () => cst,
39
42
  deserializeAddress: () => deserializeAddress,
40
43
  deserializeDatum: () => deserializeDatum,
41
44
  deserializePoolId: () => deserializePoolId,
42
- generateNonce: () => import_core_cst.generateNonce,
45
+ generateNonce: () => import_core_cst2.generateNonce,
43
46
  resolveDataHash: () => resolveDataHash,
44
47
  resolveNativeScriptAddress: () => resolveNativeScriptAddress,
45
48
  resolveNativeScriptHash: () => resolveNativeScriptHash,
@@ -56,27 +59,28 @@ __export(index_exports, {
56
59
  resolveStakeKeyHash: () => resolveStakeKeyHash,
57
60
  resolveTxHash: () => resolveTxHash,
58
61
  serializeAddressObj: () => serializeAddressObj,
62
+ serializeData: () => serializeData,
59
63
  serializeNativeScript: () => serializeNativeScript,
60
64
  serializePlutusScript: () => serializePlutusScript,
61
65
  serializePoolId: () => serializePoolId,
62
66
  serializeRewardAddress: () => serializeRewardAddress,
63
- signData: () => import_core_cst.signData
67
+ signData: () => import_core_cst2.signData
64
68
  });
65
69
  module.exports = __toCommonJS(index_exports);
66
70
 
67
71
  // src/core.ts
68
72
  var core = __toESM(require("@meshsdk/core-cst"), 1);
69
- var applyParamsToScript2 = core.applyParamsToScript;
70
- var applyCborEncoding = (script) => {
73
+ var applyParamsToScript2 = (rawScript, params, type) => core.applyParamsToScript(rawScript, params, type);
74
+ var applyCborEncoding = (rawScript) => {
71
75
  return Buffer.from(
72
- core.applyEncoding(Buffer.from(script, "hex"), "SingleCBOR")
76
+ core.applyEncoding(Buffer.from(rawScript, "hex"), "SingleCBOR")
73
77
  ).toString("hex");
74
78
  };
75
79
 
76
80
  // src/utils/resolver.ts
77
81
  var resolvePrivateKey = (words) => core.resolvePrivateKey(words);
78
82
  var resolveTxHash = (txHex) => core.resolveTxHash(txHex);
79
- var resolveDataHash = (data) => core.resolveDataHash(data);
83
+ var resolveDataHash = (rawData, type = "Mesh") => core.resolveDataHash(rawData, type);
80
84
  var resolveNativeScriptHash = (script) => core.resolveNativeScriptHash(script);
81
85
  var resolveScriptHash = (scriptCode, version) => {
82
86
  if (!version) {
@@ -89,16 +93,20 @@ var resolveStakeKeyHash = (bech32) => core.resolveStakeKeyHash(bech32);
89
93
  var resolveScriptHashDRepId = (scriptHash) => core.resolveScriptHashDRepId(scriptHash);
90
94
  var resolvePlutusScriptAddress = (script, networkId) => core.resolvePlutusScriptAddress(script, networkId);
91
95
  var resolveNativeScriptAddress = (script, networkId) => core.resolveNativeScriptAddress(script, networkId);
92
- var resolveNativeScriptHex = (script) => core.toNativeScript(script).toCbor();
96
+ var resolveNativeScriptHex = (script) => core.toNativeScript(script).toCbor().toString();
93
97
  var resolvePaymentKeyHash = (bech32) => core.deserializeBech32Address(bech32).pubKeyHash;
94
98
  var resolvePlutusScriptHash = (bech32) => core.deserializeBech32Address(bech32).scriptHash;
95
99
  var resolveScriptRef = (script) => core.resolveScriptRef(script);
96
100
  var resolvePoolId = (hash) => core.resolvePoolId(hash);
97
101
 
98
102
  // src/utils/deserializer.ts
103
+ var import_core_cst = require("@meshsdk/core-cst");
99
104
  var deserializeAddress = (bech32) => core.deserializeBech32Address(bech32);
100
105
  var deserializeDatum = (datumCbor) => core.parseDatumCbor(datumCbor);
101
- var deserializePoolId = (poolId) => core.resolveEd25519KeyHash(poolId);
106
+ var deserializePoolId = (poolId) => {
107
+ const cardanoPoolId = (0, import_core_cst.PoolId)(poolId);
108
+ return import_core_cst.PoolId.toKeyHash(cardanoPoolId).toString();
109
+ };
102
110
 
103
111
  // src/utils/serializer.ts
104
112
  var serializeNativeScript = (script, stakeCredentialHash, networkId = 0, isScriptStakeCredential = false) => {
@@ -135,6 +143,140 @@ var serializePoolId = (hash) => core.resolvePoolId(hash);
135
143
  var serializeRewardAddress = (hash, isScriptHash = false, networkId = 0) => {
136
144
  return isScriptHash ? core.scriptHashToRewardAddress(hash, networkId) : core.keyHashToRewardAddress(hash, networkId);
137
145
  };
146
+ var serializeData = (rawData, type = "Mesh") => {
147
+ const serializer = new core.CardanoSDKSerializer();
148
+ const builderData = {
149
+ type,
150
+ content: rawData
151
+ };
152
+ return serializer.serializeData(builderData);
153
+ };
154
+
155
+ // src/utils/blueprint/minting.ts
156
+ var MintingBlueprint = class {
157
+ version;
158
+ cbor;
159
+ hash;
160
+ constructor(version) {
161
+ this.version = version;
162
+ this.cbor = "";
163
+ this.hash = "";
164
+ }
165
+ /**
166
+ * Initialize the minting blueprint, with the same parameters to `applyParamsToScript`
167
+ * @param compiledCode The raw script CborHex from blueprint.
168
+ * @param params The parameters to apply, in an array.
169
+ * @param paramsType The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
170
+ * @returns The minting blueprint object
171
+ */
172
+ paramScript(compiledCode, params, paramsType = "Mesh") {
173
+ const cbor = applyParamsToScript2(compiledCode, params, paramsType);
174
+ const hash = resolveScriptHash(cbor, this.version);
175
+ this.hash = hash;
176
+ this.cbor = cbor;
177
+ return this;
178
+ }
179
+ /**
180
+ * Initialize the minting blueprint, with no parameters
181
+ * @param compiledCode The raw script CborHex from blueprint.
182
+ * @returns The minting blueprint object
183
+ */
184
+ noParamScript(compiledCode) {
185
+ return this.paramScript(compiledCode, []);
186
+ }
187
+ };
188
+
189
+ // src/utils/blueprint/spending.ts
190
+ var SpendingBlueprint = class {
191
+ version;
192
+ networkId;
193
+ cbor;
194
+ hash;
195
+ address;
196
+ stakeHash;
197
+ isStakeScriptCredential;
198
+ constructor(version, networkId, stakeHash, isStakeScriptCredential = false) {
199
+ this.version = version;
200
+ this.networkId = networkId;
201
+ this.stakeHash = stakeHash;
202
+ this.cbor = "";
203
+ this.hash = "";
204
+ this.address = "";
205
+ this.isStakeScriptCredential = isStakeScriptCredential;
206
+ }
207
+ /**
208
+ * Initialize the minting blueprint, with the same parameters to `applyParamsToScript`
209
+ * @param compiledCode The raw script CborHex from blueprint.
210
+ * @param params The parameters to apply, in an array.
211
+ * @param paramsType The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
212
+ * @returns
213
+ */
214
+ paramScript(compiledCode, params, paramsType = "Mesh") {
215
+ const cbor = applyParamsToScript2(compiledCode, params, paramsType);
216
+ const hash = resolveScriptHash(cbor, this.version);
217
+ const plutusScript = {
218
+ code: cbor,
219
+ version: this.version
220
+ };
221
+ const address = serializePlutusScript(
222
+ plutusScript,
223
+ this.stakeHash,
224
+ this.networkId,
225
+ this.isStakeScriptCredential
226
+ ).address;
227
+ this.hash = hash;
228
+ this.cbor = cbor;
229
+ this.address = address;
230
+ return this;
231
+ }
232
+ /**
233
+ * Initialize the minting blueprint, with no parameters
234
+ * @param compiledCode The raw script CborHex from blueprint.
235
+ * @returns The minting blueprint object
236
+ */
237
+ noParamScript(compiledCode) {
238
+ return this.paramScript(compiledCode, []);
239
+ }
240
+ };
241
+
242
+ // src/utils/blueprint/withdrawal.ts
243
+ var WithdrawalBlueprint = class {
244
+ version;
245
+ networkId;
246
+ cbor;
247
+ hash;
248
+ address;
249
+ constructor(version, networkId) {
250
+ this.version = version;
251
+ this.networkId = networkId;
252
+ this.cbor = "";
253
+ this.hash = "";
254
+ this.address = "";
255
+ }
256
+ /**
257
+ * Initialize the withdrawal blueprint, with the same parameters to `applyParamsToScript`
258
+ * @param compiledCode The raw script CborHex from blueprint.
259
+ * @param params The parameters to apply, in an array.
260
+ * @param paramsType The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
261
+ * @returns The withdrawal blueprint object
262
+ */
263
+ paramScript(compiledCode, params, paramsType = "Mesh") {
264
+ const cbor = applyParamsToScript2(compiledCode, params, paramsType);
265
+ const hash = resolveScriptHash(cbor, this.version);
266
+ this.address = serializeRewardAddress(hash, true, this.networkId);
267
+ this.hash = hash;
268
+ this.cbor = cbor;
269
+ return this;
270
+ }
271
+ /**
272
+ * Initialize the withdrawal blueprint, with no parameters
273
+ * @param compiledCode The raw script CborHex from blueprint.
274
+ * @returns The withdrawal blueprint object
275
+ */
276
+ noParamScript(compiledCode) {
277
+ return this.paramScript(compiledCode, []);
278
+ }
279
+ };
138
280
 
139
281
  // src/index.ts
140
282
  __reExport(index_exports, require("@meshsdk/common"), module.exports);
@@ -142,9 +284,12 @@ var cst = __toESM(require("@meshsdk/core-cst"), 1);
142
284
  __reExport(index_exports, require("@meshsdk/provider"), module.exports);
143
285
  __reExport(index_exports, require("@meshsdk/transaction"), module.exports);
144
286
  __reExport(index_exports, require("@meshsdk/wallet"), module.exports);
145
- var import_core_cst = require("@meshsdk/core-cst");
287
+ var import_core_cst2 = require("@meshsdk/core-cst");
146
288
  // Annotate the CommonJS export names for ESM import in node:
147
289
  0 && (module.exports = {
290
+ MintingBlueprint,
291
+ SpendingBlueprint,
292
+ WithdrawalBlueprint,
148
293
  applyCborEncoding,
149
294
  applyParamsToScript,
150
295
  checkSignature,
@@ -170,6 +315,7 @@ var import_core_cst = require("@meshsdk/core-cst");
170
315
  resolveStakeKeyHash,
171
316
  resolveTxHash,
172
317
  serializeAddressObj,
318
+ serializeData,
173
319
  serializeNativeScript,
174
320
  serializePlutusScript,
175
321
  serializePoolId,
package/dist/index.d.cts CHANGED
@@ -1,16 +1,31 @@
1
- import * as _meshsdk_common from '@meshsdk/common';
2
- import { Data, NativeScript, LanguageVersion, PlutusScript, DeserializedAddress, PubKeyAddress, ScriptAddress } from '@meshsdk/common';
1
+ import { Data, PlutusDataType, BuilderData, NativeScript, PlutusScript, LanguageVersion, DeserializedAddress, PubKeyAddress, ScriptAddress, IMintingBlueprint, ISpendingBlueprint, IWithdrawalBlueprint } from '@meshsdk/common';
3
2
  export * from '@meshsdk/common';
4
- import * as core from '@meshsdk/core-cst';
5
- export { core };
6
- export { core as cst };
3
+ import * as coreCst from '@meshsdk/core-cst';
4
+ export { coreCst as core };
5
+ export { coreCst as cst };
7
6
  export { checkSignature, generateNonce, signData } from '@meshsdk/core-cst';
8
7
  export * from '@meshsdk/provider';
9
8
  export * from '@meshsdk/transaction';
10
9
  export * from '@meshsdk/wallet';
11
10
 
12
- declare const applyParamsToScript: (rawScript: string, params: object[] | _meshsdk_common.Data[], type?: _meshsdk_common.PlutusDataType) => string;
13
- declare const applyCborEncoding: (script: string) => string;
11
+ /**
12
+ * Apply parameters to a given CIP57 blueprint compiledCode,
13
+ * making it ready for use in transactions
14
+ *
15
+ * @param rawScript - The raw script CborHex from blueprint.
16
+ * @param params - The parameters to apply, in an array.
17
+ * @param type - The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
18
+ * @returns The double-cbor encoded script CborHex with the parameters applied.
19
+ */
20
+ declare const applyParamsToScript: (rawScript: string, params: object[] | Data[], type?: PlutusDataType) => string;
21
+ /**
22
+ * Apply Cbor encoding to rawScript from CIP57 blueprint compiledCode,
23
+ * making it ready for use in transactions
24
+ *
25
+ * @param rawScript - The raw script CborHex from blueprint.
26
+ * @returns The double-cbor encoded script CborHex.
27
+ */
28
+ declare const applyCborEncoding: (rawScript: string) => string;
14
29
 
15
30
  /**
16
31
  * Resolve the private key from mnemonic words
@@ -29,10 +44,11 @@ declare const resolvePrivateKey: (words: string[]) => string;
29
44
  declare const resolveTxHash: (txHex: string) => string;
30
45
  /**
31
46
  * Hash Cardano data
32
- * @param data Cardano data in Mesh Data type
47
+ * @param rawData Cardano data in Mesh, JSON or CBOR type
48
+ * @param type The data type, either Mesh, JSON or CBOR
33
49
  * @returns Cardano data hash
34
50
  */
35
- declare const resolveDataHash: (data: Data) => string;
51
+ declare const resolveDataHash: (rawData: BuilderData["content"], type?: PlutusDataType) => string;
36
52
  /**
37
53
  * Hash Cardano native script
38
54
  * @param script Cardano native script in Mesh NativeScript type
@@ -75,7 +91,7 @@ declare const resolveNativeScriptAddress: (script: NativeScript, networkId?: num
75
91
  /**
76
92
  * Deprecated - use `serializeNativeScript` instead
77
93
  */
78
- declare const resolveNativeScriptHex: (script: NativeScript) => core.CardanoSDKUtil.HexBlob;
94
+ declare const resolveNativeScriptHex: (script: NativeScript) => any;
79
95
  /**
80
96
  * Deprecated - use `deserializeAddress` instead
81
97
  */
@@ -139,7 +155,7 @@ declare const serializeNativeScript: (script: NativeScript, stakeCredentialHash?
139
155
  * @returns Bech32 address
140
156
  */
141
157
  declare const serializePlutusScript: (script: PlutusScript, stakeCredentialHash?: string, networkId?: number, isScriptStakeCredential?: boolean) => {
142
- address: string;
158
+ address: any;
143
159
  };
144
160
  /**
145
161
  * Serialize address in Cardano data JSON format into bech32 address
@@ -161,6 +177,123 @@ declare const serializePoolId: (hash: string) => string;
161
177
  * @param networkId 0 (testnet) or 1 (mainnet). Default to be 0 (testnet).
162
178
  * @returns Bech32 reward address
163
179
  */
164
- declare const serializeRewardAddress: (hash: string, isScriptHash?: boolean, networkId?: 0 | 1) => string;
180
+ declare const serializeRewardAddress: (hash: string, isScriptHash?: boolean, networkId?: 0 | 1) => any;
181
+ /**
182
+ * Serialize the data from Mesh or JSON format into CBOR hex
183
+ * @param data The data in Mesh or JSON format
184
+ * @param type The data type. Default to be Mesh data type
185
+ * @returns The CBOR hex string
186
+ */
187
+ declare const serializeData: (rawData: BuilderData["content"], type?: Omit<PlutusDataType, "CBOR">) => string;
188
+
189
+ /**
190
+ * Minting blueprint
191
+ * @category Blueprint
192
+ * @implements IMintingBlueprint
193
+ * @class
194
+ * @example
195
+ *
196
+ * const blueprint = new MintingBlueprint("V3");
197
+ * blueprint.paramScript("84xxxxxx", ["params"], "Mesh");
198
+ *
199
+ * const policyId = blueprint.hash;
200
+ * const scriptCbor = blueprint.cbor;
201
+ */
202
+ declare class MintingBlueprint implements IMintingBlueprint {
203
+ version: LanguageVersion;
204
+ cbor: string;
205
+ hash: string;
206
+ constructor(version: LanguageVersion);
207
+ /**
208
+ * Initialize the minting blueprint, with the same parameters to `applyParamsToScript`
209
+ * @param compiledCode The raw script CborHex from blueprint.
210
+ * @param params The parameters to apply, in an array.
211
+ * @param paramsType The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
212
+ * @returns The minting blueprint object
213
+ */
214
+ paramScript(compiledCode: string, params: object[] | Data[], paramsType?: PlutusDataType): this;
215
+ /**
216
+ * Initialize the minting blueprint, with no parameters
217
+ * @param compiledCode The raw script CborHex from blueprint.
218
+ * @returns The minting blueprint object
219
+ */
220
+ noParamScript(compiledCode: string): this;
221
+ }
222
+
223
+ /**
224
+ * Spending blueprint
225
+ * @category Blueprint
226
+ * @implements ISpendingBlueprint
227
+ * @class
228
+ * @example
229
+ *
230
+ * const blueprint = new SpendingBlueprint("V3", 0, stakeHash);
231
+ * blueprint.paramScript("84xxxxxx", ["params"], "Mesh");
232
+ *
233
+ * const scriptHash = blueprint.hash;
234
+ * const scriptCbor = blueprint.cbor;
235
+ * const scriptAddress = blueprint.address;
236
+ */
237
+ declare class SpendingBlueprint implements ISpendingBlueprint {
238
+ version: LanguageVersion;
239
+ networkId: number;
240
+ cbor: string;
241
+ hash: string;
242
+ address: string;
243
+ stakeHash?: string;
244
+ isStakeScriptCredential: boolean;
245
+ constructor(version: LanguageVersion, networkId: number, stakeHash: string, isStakeScriptCredential?: boolean);
246
+ /**
247
+ * Initialize the minting blueprint, with the same parameters to `applyParamsToScript`
248
+ * @param compiledCode The raw script CborHex from blueprint.
249
+ * @param params The parameters to apply, in an array.
250
+ * @param paramsType The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
251
+ * @returns
252
+ */
253
+ paramScript(compiledCode: string, params: object[] | Data[], paramsType?: PlutusDataType): this;
254
+ /**
255
+ * Initialize the minting blueprint, with no parameters
256
+ * @param compiledCode The raw script CborHex from blueprint.
257
+ * @returns The minting blueprint object
258
+ */
259
+ noParamScript(compiledCode: string): this;
260
+ }
261
+
262
+ /**
263
+ * Withdrawal blueprint
264
+ * @category Blueprint
265
+ * @implements IWithdrawalBlueprint
266
+ * @class
267
+ * @example
268
+ *
269
+ * const blueprint = new WithdrawalBlueprint("V3", 0);
270
+ * blueprint.paramScript("84xxxxxx", ["params"], "Mesh");
271
+ *
272
+ * const scriptHash = blueprint.hash;
273
+ * const scriptCbor = blueprint.cbor;
274
+ * const rewardAddress = blueprint.address;
275
+ */
276
+ declare class WithdrawalBlueprint implements IWithdrawalBlueprint {
277
+ version: LanguageVersion;
278
+ networkId: number;
279
+ cbor: string;
280
+ hash: string;
281
+ address: string;
282
+ constructor(version: LanguageVersion, networkId: number);
283
+ /**
284
+ * Initialize the withdrawal blueprint, with the same parameters to `applyParamsToScript`
285
+ * @param compiledCode The raw script CborHex from blueprint.
286
+ * @param params The parameters to apply, in an array.
287
+ * @param paramsType The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
288
+ * @returns The withdrawal blueprint object
289
+ */
290
+ paramScript(compiledCode: string, params: object[] | Data[], paramsType?: PlutusDataType): this;
291
+ /**
292
+ * Initialize the withdrawal blueprint, with no parameters
293
+ * @param compiledCode The raw script CborHex from blueprint.
294
+ * @returns The withdrawal blueprint object
295
+ */
296
+ noParamScript(compiledCode: string): this;
297
+ }
165
298
 
166
- export { applyCborEncoding, applyParamsToScript, deserializeAddress, deserializeDatum, deserializePoolId, resolveDataHash, resolveNativeScriptAddress, resolveNativeScriptHash, resolveNativeScriptHex, resolvePaymentKeyHash, resolvePlutusScriptAddress, resolvePlutusScriptHash, resolvePoolId, resolvePrivateKey, resolveRewardAddress, resolveScriptHash, resolveScriptHashDRepId, resolveScriptRef, resolveStakeKeyHash, resolveTxHash, serializeAddressObj, serializeNativeScript, serializePlutusScript, serializePoolId, serializeRewardAddress };
299
+ export { MintingBlueprint, SpendingBlueprint, WithdrawalBlueprint, applyCborEncoding, applyParamsToScript, deserializeAddress, deserializeDatum, deserializePoolId, resolveDataHash, resolveNativeScriptAddress, resolveNativeScriptHash, resolveNativeScriptHex, resolvePaymentKeyHash, resolvePlutusScriptAddress, resolvePlutusScriptHash, resolvePoolId, resolvePrivateKey, resolveRewardAddress, resolveScriptHash, resolveScriptHashDRepId, resolveScriptRef, resolveStakeKeyHash, resolveTxHash, serializeAddressObj, serializeData, serializeNativeScript, serializePlutusScript, serializePoolId, serializeRewardAddress };
package/dist/index.d.ts CHANGED
@@ -1,16 +1,31 @@
1
- import * as _meshsdk_common from '@meshsdk/common';
2
- import { Data, NativeScript, LanguageVersion, PlutusScript, DeserializedAddress, PubKeyAddress, ScriptAddress } from '@meshsdk/common';
1
+ import { Data, PlutusDataType, BuilderData, NativeScript, PlutusScript, LanguageVersion, DeserializedAddress, PubKeyAddress, ScriptAddress, IMintingBlueprint, ISpendingBlueprint, IWithdrawalBlueprint } from '@meshsdk/common';
3
2
  export * from '@meshsdk/common';
4
- import * as core from '@meshsdk/core-cst';
5
- export { core };
6
- export { core as cst };
3
+ import * as coreCst from '@meshsdk/core-cst';
4
+ export { coreCst as core };
5
+ export { coreCst as cst };
7
6
  export { checkSignature, generateNonce, signData } from '@meshsdk/core-cst';
8
7
  export * from '@meshsdk/provider';
9
8
  export * from '@meshsdk/transaction';
10
9
  export * from '@meshsdk/wallet';
11
10
 
12
- declare const applyParamsToScript: (rawScript: string, params: object[] | _meshsdk_common.Data[], type?: _meshsdk_common.PlutusDataType) => string;
13
- declare const applyCborEncoding: (script: string) => string;
11
+ /**
12
+ * Apply parameters to a given CIP57 blueprint compiledCode,
13
+ * making it ready for use in transactions
14
+ *
15
+ * @param rawScript - The raw script CborHex from blueprint.
16
+ * @param params - The parameters to apply, in an array.
17
+ * @param type - The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
18
+ * @returns The double-cbor encoded script CborHex with the parameters applied.
19
+ */
20
+ declare const applyParamsToScript: (rawScript: string, params: object[] | Data[], type?: PlutusDataType) => string;
21
+ /**
22
+ * Apply Cbor encoding to rawScript from CIP57 blueprint compiledCode,
23
+ * making it ready for use in transactions
24
+ *
25
+ * @param rawScript - The raw script CborHex from blueprint.
26
+ * @returns The double-cbor encoded script CborHex.
27
+ */
28
+ declare const applyCborEncoding: (rawScript: string) => string;
14
29
 
15
30
  /**
16
31
  * Resolve the private key from mnemonic words
@@ -29,10 +44,11 @@ declare const resolvePrivateKey: (words: string[]) => string;
29
44
  declare const resolveTxHash: (txHex: string) => string;
30
45
  /**
31
46
  * Hash Cardano data
32
- * @param data Cardano data in Mesh Data type
47
+ * @param rawData Cardano data in Mesh, JSON or CBOR type
48
+ * @param type The data type, either Mesh, JSON or CBOR
33
49
  * @returns Cardano data hash
34
50
  */
35
- declare const resolveDataHash: (data: Data) => string;
51
+ declare const resolveDataHash: (rawData: BuilderData["content"], type?: PlutusDataType) => string;
36
52
  /**
37
53
  * Hash Cardano native script
38
54
  * @param script Cardano native script in Mesh NativeScript type
@@ -75,7 +91,7 @@ declare const resolveNativeScriptAddress: (script: NativeScript, networkId?: num
75
91
  /**
76
92
  * Deprecated - use `serializeNativeScript` instead
77
93
  */
78
- declare const resolveNativeScriptHex: (script: NativeScript) => core.CardanoSDKUtil.HexBlob;
94
+ declare const resolveNativeScriptHex: (script: NativeScript) => any;
79
95
  /**
80
96
  * Deprecated - use `deserializeAddress` instead
81
97
  */
@@ -139,7 +155,7 @@ declare const serializeNativeScript: (script: NativeScript, stakeCredentialHash?
139
155
  * @returns Bech32 address
140
156
  */
141
157
  declare const serializePlutusScript: (script: PlutusScript, stakeCredentialHash?: string, networkId?: number, isScriptStakeCredential?: boolean) => {
142
- address: string;
158
+ address: any;
143
159
  };
144
160
  /**
145
161
  * Serialize address in Cardano data JSON format into bech32 address
@@ -161,6 +177,123 @@ declare const serializePoolId: (hash: string) => string;
161
177
  * @param networkId 0 (testnet) or 1 (mainnet). Default to be 0 (testnet).
162
178
  * @returns Bech32 reward address
163
179
  */
164
- declare const serializeRewardAddress: (hash: string, isScriptHash?: boolean, networkId?: 0 | 1) => string;
180
+ declare const serializeRewardAddress: (hash: string, isScriptHash?: boolean, networkId?: 0 | 1) => any;
181
+ /**
182
+ * Serialize the data from Mesh or JSON format into CBOR hex
183
+ * @param data The data in Mesh or JSON format
184
+ * @param type The data type. Default to be Mesh data type
185
+ * @returns The CBOR hex string
186
+ */
187
+ declare const serializeData: (rawData: BuilderData["content"], type?: Omit<PlutusDataType, "CBOR">) => string;
188
+
189
+ /**
190
+ * Minting blueprint
191
+ * @category Blueprint
192
+ * @implements IMintingBlueprint
193
+ * @class
194
+ * @example
195
+ *
196
+ * const blueprint = new MintingBlueprint("V3");
197
+ * blueprint.paramScript("84xxxxxx", ["params"], "Mesh");
198
+ *
199
+ * const policyId = blueprint.hash;
200
+ * const scriptCbor = blueprint.cbor;
201
+ */
202
+ declare class MintingBlueprint implements IMintingBlueprint {
203
+ version: LanguageVersion;
204
+ cbor: string;
205
+ hash: string;
206
+ constructor(version: LanguageVersion);
207
+ /**
208
+ * Initialize the minting blueprint, with the same parameters to `applyParamsToScript`
209
+ * @param compiledCode The raw script CborHex from blueprint.
210
+ * @param params The parameters to apply, in an array.
211
+ * @param paramsType The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
212
+ * @returns The minting blueprint object
213
+ */
214
+ paramScript(compiledCode: string, params: object[] | Data[], paramsType?: PlutusDataType): this;
215
+ /**
216
+ * Initialize the minting blueprint, with no parameters
217
+ * @param compiledCode The raw script CborHex from blueprint.
218
+ * @returns The minting blueprint object
219
+ */
220
+ noParamScript(compiledCode: string): this;
221
+ }
222
+
223
+ /**
224
+ * Spending blueprint
225
+ * @category Blueprint
226
+ * @implements ISpendingBlueprint
227
+ * @class
228
+ * @example
229
+ *
230
+ * const blueprint = new SpendingBlueprint("V3", 0, stakeHash);
231
+ * blueprint.paramScript("84xxxxxx", ["params"], "Mesh");
232
+ *
233
+ * const scriptHash = blueprint.hash;
234
+ * const scriptCbor = blueprint.cbor;
235
+ * const scriptAddress = blueprint.address;
236
+ */
237
+ declare class SpendingBlueprint implements ISpendingBlueprint {
238
+ version: LanguageVersion;
239
+ networkId: number;
240
+ cbor: string;
241
+ hash: string;
242
+ address: string;
243
+ stakeHash?: string;
244
+ isStakeScriptCredential: boolean;
245
+ constructor(version: LanguageVersion, networkId: number, stakeHash: string, isStakeScriptCredential?: boolean);
246
+ /**
247
+ * Initialize the minting blueprint, with the same parameters to `applyParamsToScript`
248
+ * @param compiledCode The raw script CborHex from blueprint.
249
+ * @param params The parameters to apply, in an array.
250
+ * @param paramsType The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
251
+ * @returns
252
+ */
253
+ paramScript(compiledCode: string, params: object[] | Data[], paramsType?: PlutusDataType): this;
254
+ /**
255
+ * Initialize the minting blueprint, with no parameters
256
+ * @param compiledCode The raw script CborHex from blueprint.
257
+ * @returns The minting blueprint object
258
+ */
259
+ noParamScript(compiledCode: string): this;
260
+ }
261
+
262
+ /**
263
+ * Withdrawal blueprint
264
+ * @category Blueprint
265
+ * @implements IWithdrawalBlueprint
266
+ * @class
267
+ * @example
268
+ *
269
+ * const blueprint = new WithdrawalBlueprint("V3", 0);
270
+ * blueprint.paramScript("84xxxxxx", ["params"], "Mesh");
271
+ *
272
+ * const scriptHash = blueprint.hash;
273
+ * const scriptCbor = blueprint.cbor;
274
+ * const rewardAddress = blueprint.address;
275
+ */
276
+ declare class WithdrawalBlueprint implements IWithdrawalBlueprint {
277
+ version: LanguageVersion;
278
+ networkId: number;
279
+ cbor: string;
280
+ hash: string;
281
+ address: string;
282
+ constructor(version: LanguageVersion, networkId: number);
283
+ /**
284
+ * Initialize the withdrawal blueprint, with the same parameters to `applyParamsToScript`
285
+ * @param compiledCode The raw script CborHex from blueprint.
286
+ * @param params The parameters to apply, in an array.
287
+ * @param paramsType The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
288
+ * @returns The withdrawal blueprint object
289
+ */
290
+ paramScript(compiledCode: string, params: object[] | Data[], paramsType?: PlutusDataType): this;
291
+ /**
292
+ * Initialize the withdrawal blueprint, with no parameters
293
+ * @param compiledCode The raw script CborHex from blueprint.
294
+ * @returns The withdrawal blueprint object
295
+ */
296
+ noParamScript(compiledCode: string): this;
297
+ }
165
298
 
166
- export { applyCborEncoding, applyParamsToScript, deserializeAddress, deserializeDatum, deserializePoolId, resolveDataHash, resolveNativeScriptAddress, resolveNativeScriptHash, resolveNativeScriptHex, resolvePaymentKeyHash, resolvePlutusScriptAddress, resolvePlutusScriptHash, resolvePoolId, resolvePrivateKey, resolveRewardAddress, resolveScriptHash, resolveScriptHashDRepId, resolveScriptRef, resolveStakeKeyHash, resolveTxHash, serializeAddressObj, serializeNativeScript, serializePlutusScript, serializePoolId, serializeRewardAddress };
299
+ export { MintingBlueprint, SpendingBlueprint, WithdrawalBlueprint, applyCborEncoding, applyParamsToScript, deserializeAddress, deserializeDatum, deserializePoolId, resolveDataHash, resolveNativeScriptAddress, resolveNativeScriptHash, resolveNativeScriptHex, resolvePaymentKeyHash, resolvePlutusScriptAddress, resolvePlutusScriptHash, resolvePoolId, resolvePrivateKey, resolveRewardAddress, resolveScriptHash, resolveScriptHashDRepId, resolveScriptRef, resolveStakeKeyHash, resolveTxHash, serializeAddressObj, serializeData, serializeNativeScript, serializePlutusScript, serializePoolId, serializeRewardAddress };
package/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
1
  // src/core.ts
2
2
  import * as core from "@meshsdk/core-cst";
3
- var applyParamsToScript2 = core.applyParamsToScript;
4
- var applyCborEncoding = (script) => {
3
+ var applyParamsToScript2 = (rawScript, params, type) => core.applyParamsToScript(rawScript, params, type);
4
+ var applyCborEncoding = (rawScript) => {
5
5
  return Buffer.from(
6
- core.applyEncoding(Buffer.from(script, "hex"), "SingleCBOR")
6
+ core.applyEncoding(Buffer.from(rawScript, "hex"), "SingleCBOR")
7
7
  ).toString("hex");
8
8
  };
9
9
 
10
10
  // src/utils/resolver.ts
11
11
  var resolvePrivateKey = (words) => core.resolvePrivateKey(words);
12
12
  var resolveTxHash = (txHex) => core.resolveTxHash(txHex);
13
- var resolveDataHash = (data) => core.resolveDataHash(data);
13
+ var resolveDataHash = (rawData, type = "Mesh") => core.resolveDataHash(rawData, type);
14
14
  var resolveNativeScriptHash = (script) => core.resolveNativeScriptHash(script);
15
15
  var resolveScriptHash = (scriptCode, version) => {
16
16
  if (!version) {
@@ -23,16 +23,20 @@ var resolveStakeKeyHash = (bech32) => core.resolveStakeKeyHash(bech32);
23
23
  var resolveScriptHashDRepId = (scriptHash) => core.resolveScriptHashDRepId(scriptHash);
24
24
  var resolvePlutusScriptAddress = (script, networkId) => core.resolvePlutusScriptAddress(script, networkId);
25
25
  var resolveNativeScriptAddress = (script, networkId) => core.resolveNativeScriptAddress(script, networkId);
26
- var resolveNativeScriptHex = (script) => core.toNativeScript(script).toCbor();
26
+ var resolveNativeScriptHex = (script) => core.toNativeScript(script).toCbor().toString();
27
27
  var resolvePaymentKeyHash = (bech32) => core.deserializeBech32Address(bech32).pubKeyHash;
28
28
  var resolvePlutusScriptHash = (bech32) => core.deserializeBech32Address(bech32).scriptHash;
29
29
  var resolveScriptRef = (script) => core.resolveScriptRef(script);
30
30
  var resolvePoolId = (hash) => core.resolvePoolId(hash);
31
31
 
32
32
  // src/utils/deserializer.ts
33
+ import { PoolId } from "@meshsdk/core-cst";
33
34
  var deserializeAddress = (bech32) => core.deserializeBech32Address(bech32);
34
35
  var deserializeDatum = (datumCbor) => core.parseDatumCbor(datumCbor);
35
- var deserializePoolId = (poolId) => core.resolveEd25519KeyHash(poolId);
36
+ var deserializePoolId = (poolId) => {
37
+ const cardanoPoolId = PoolId(poolId);
38
+ return PoolId.toKeyHash(cardanoPoolId).toString();
39
+ };
36
40
 
37
41
  // src/utils/serializer.ts
38
42
  var serializeNativeScript = (script, stakeCredentialHash, networkId = 0, isScriptStakeCredential = false) => {
@@ -69,6 +73,140 @@ var serializePoolId = (hash) => core.resolvePoolId(hash);
69
73
  var serializeRewardAddress = (hash, isScriptHash = false, networkId = 0) => {
70
74
  return isScriptHash ? core.scriptHashToRewardAddress(hash, networkId) : core.keyHashToRewardAddress(hash, networkId);
71
75
  };
76
+ var serializeData = (rawData, type = "Mesh") => {
77
+ const serializer = new core.CardanoSDKSerializer();
78
+ const builderData = {
79
+ type,
80
+ content: rawData
81
+ };
82
+ return serializer.serializeData(builderData);
83
+ };
84
+
85
+ // src/utils/blueprint/minting.ts
86
+ var MintingBlueprint = class {
87
+ version;
88
+ cbor;
89
+ hash;
90
+ constructor(version) {
91
+ this.version = version;
92
+ this.cbor = "";
93
+ this.hash = "";
94
+ }
95
+ /**
96
+ * Initialize the minting blueprint, with the same parameters to `applyParamsToScript`
97
+ * @param compiledCode The raw script CborHex from blueprint.
98
+ * @param params The parameters to apply, in an array.
99
+ * @param paramsType The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
100
+ * @returns The minting blueprint object
101
+ */
102
+ paramScript(compiledCode, params, paramsType = "Mesh") {
103
+ const cbor = applyParamsToScript2(compiledCode, params, paramsType);
104
+ const hash = resolveScriptHash(cbor, this.version);
105
+ this.hash = hash;
106
+ this.cbor = cbor;
107
+ return this;
108
+ }
109
+ /**
110
+ * Initialize the minting blueprint, with no parameters
111
+ * @param compiledCode The raw script CborHex from blueprint.
112
+ * @returns The minting blueprint object
113
+ */
114
+ noParamScript(compiledCode) {
115
+ return this.paramScript(compiledCode, []);
116
+ }
117
+ };
118
+
119
+ // src/utils/blueprint/spending.ts
120
+ var SpendingBlueprint = class {
121
+ version;
122
+ networkId;
123
+ cbor;
124
+ hash;
125
+ address;
126
+ stakeHash;
127
+ isStakeScriptCredential;
128
+ constructor(version, networkId, stakeHash, isStakeScriptCredential = false) {
129
+ this.version = version;
130
+ this.networkId = networkId;
131
+ this.stakeHash = stakeHash;
132
+ this.cbor = "";
133
+ this.hash = "";
134
+ this.address = "";
135
+ this.isStakeScriptCredential = isStakeScriptCredential;
136
+ }
137
+ /**
138
+ * Initialize the minting blueprint, with the same parameters to `applyParamsToScript`
139
+ * @param compiledCode The raw script CborHex from blueprint.
140
+ * @param params The parameters to apply, in an array.
141
+ * @param paramsType The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
142
+ * @returns
143
+ */
144
+ paramScript(compiledCode, params, paramsType = "Mesh") {
145
+ const cbor = applyParamsToScript2(compiledCode, params, paramsType);
146
+ const hash = resolveScriptHash(cbor, this.version);
147
+ const plutusScript = {
148
+ code: cbor,
149
+ version: this.version
150
+ };
151
+ const address = serializePlutusScript(
152
+ plutusScript,
153
+ this.stakeHash,
154
+ this.networkId,
155
+ this.isStakeScriptCredential
156
+ ).address;
157
+ this.hash = hash;
158
+ this.cbor = cbor;
159
+ this.address = address;
160
+ return this;
161
+ }
162
+ /**
163
+ * Initialize the minting blueprint, with no parameters
164
+ * @param compiledCode The raw script CborHex from blueprint.
165
+ * @returns The minting blueprint object
166
+ */
167
+ noParamScript(compiledCode) {
168
+ return this.paramScript(compiledCode, []);
169
+ }
170
+ };
171
+
172
+ // src/utils/blueprint/withdrawal.ts
173
+ var WithdrawalBlueprint = class {
174
+ version;
175
+ networkId;
176
+ cbor;
177
+ hash;
178
+ address;
179
+ constructor(version, networkId) {
180
+ this.version = version;
181
+ this.networkId = networkId;
182
+ this.cbor = "";
183
+ this.hash = "";
184
+ this.address = "";
185
+ }
186
+ /**
187
+ * Initialize the withdrawal blueprint, with the same parameters to `applyParamsToScript`
188
+ * @param compiledCode The raw script CborHex from blueprint.
189
+ * @param params The parameters to apply, in an array.
190
+ * @param paramsType The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
191
+ * @returns The withdrawal blueprint object
192
+ */
193
+ paramScript(compiledCode, params, paramsType = "Mesh") {
194
+ const cbor = applyParamsToScript2(compiledCode, params, paramsType);
195
+ const hash = resolveScriptHash(cbor, this.version);
196
+ this.address = serializeRewardAddress(hash, true, this.networkId);
197
+ this.hash = hash;
198
+ this.cbor = cbor;
199
+ return this;
200
+ }
201
+ /**
202
+ * Initialize the withdrawal blueprint, with no parameters
203
+ * @param compiledCode The raw script CborHex from blueprint.
204
+ * @returns The withdrawal blueprint object
205
+ */
206
+ noParamScript(compiledCode) {
207
+ return this.paramScript(compiledCode, []);
208
+ }
209
+ };
72
210
 
73
211
  // src/index.ts
74
212
  export * from "@meshsdk/common";
@@ -78,6 +216,9 @@ export * from "@meshsdk/transaction";
78
216
  export * from "@meshsdk/wallet";
79
217
  import { checkSignature, signData, generateNonce } from "@meshsdk/core-cst";
80
218
  export {
219
+ MintingBlueprint,
220
+ SpendingBlueprint,
221
+ WithdrawalBlueprint,
81
222
  applyCborEncoding,
82
223
  applyParamsToScript2 as applyParamsToScript,
83
224
  checkSignature,
@@ -103,6 +244,7 @@ export {
103
244
  resolveStakeKeyHash,
104
245
  resolveTxHash,
105
246
  serializeAddressObj,
247
+ serializeData,
106
248
  serializeNativeScript,
107
249
  serializePlutusScript,
108
250
  serializePoolId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshsdk/core",
3
- "version": "1.9.0-beta.1",
3
+ "version": "1.9.0-beta.100",
4
4
  "description": "Mesh SDK Core - https://meshjs.dev/",
5
5
  "main": "./dist/index.cjs",
6
6
  "browser": "./dist/index.js",
@@ -33,12 +33,11 @@
33
33
  "typescript": "^5.3.3"
34
34
  },
35
35
  "dependencies": {
36
- "@meshsdk/common": "1.9.0-beta.1",
37
- "@meshsdk/core-cst": "1.9.0-beta.1",
38
- "@meshsdk/provider": "1.9.0-beta.1",
39
- "@meshsdk/react": "1.9.0-beta.1",
40
- "@meshsdk/transaction": "1.9.0-beta.1",
41
- "@meshsdk/wallet": "1.9.0-beta.1"
36
+ "@meshsdk/common": "1.9.0-beta.100",
37
+ "@meshsdk/core-cst": "1.9.0-beta.100",
38
+ "@meshsdk/provider": "1.9.0-beta.99",
39
+ "@meshsdk/transaction": "1.9.0-beta.100",
40
+ "@meshsdk/wallet": "1.9.0-beta.100"
42
41
  },
43
42
  "prettier": "@meshsdk/configs/prettier",
44
43
  "publishConfig": {
@@ -47,9 +46,10 @@
47
46
  "license": "Apache-2.0",
48
47
  "keywords": [
49
48
  "cardano",
50
- "ada",
51
49
  "web3",
52
50
  "blockchain",
53
- "sdk"
51
+ "sdk",
52
+ "typescript",
53
+ "javascript"
54
54
  ]
55
- }
55
+ }