@meshsdk/core 1.8.14 → 1.9.0-beta-38
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 +7 -1
- package/dist/index.cjs +162 -13
- package/dist/index.d.cts +140 -8
- package/dist/index.d.ts +140 -8
- package/dist/index.js +158 -13
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
|
|
22
22
|
<hr />
|
|
23
23
|
|
|
24
|
-
Mesh is an open-source library designed to make building
|
|
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,6 +31,12 @@ 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
|
package/dist/index.cjs
CHANGED
|
@@ -31,7 +31,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var index_exports = {};
|
|
33
33
|
__export(index_exports, {
|
|
34
|
-
|
|
34
|
+
MintingBlueprint: () => MintingBlueprint,
|
|
35
|
+
SpendingBlueprint: () => SpendingBlueprint,
|
|
36
|
+
WithdrawalBlueprint: () => WithdrawalBlueprint,
|
|
37
|
+
applyCborEncoding: () => applyCborEncoding,
|
|
35
38
|
applyParamsToScript: () => applyParamsToScript2,
|
|
36
39
|
checkSignature: () => import_core_cst.checkSignature,
|
|
37
40
|
core: () => core,
|
|
@@ -56,6 +59,7 @@ __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,
|
|
@@ -65,31 +69,35 @@ __export(index_exports, {
|
|
|
65
69
|
module.exports = __toCommonJS(index_exports);
|
|
66
70
|
|
|
67
71
|
// src/core.ts
|
|
68
|
-
var core = __toESM(require("@meshsdk/core-
|
|
69
|
-
var applyParamsToScript2 = core.applyParamsToScript;
|
|
70
|
-
var
|
|
72
|
+
var core = __toESM(require("@meshsdk/core-cst"), 1);
|
|
73
|
+
var applyParamsToScript2 = (rawScript, params, type) => core.applyParamsToScript(rawScript, params, type);
|
|
74
|
+
var applyCborEncoding = (rawScript) => {
|
|
75
|
+
return Buffer.from(
|
|
76
|
+
core.applyEncoding(Buffer.from(rawScript, "hex"), "SingleCBOR")
|
|
77
|
+
).toString("hex");
|
|
78
|
+
};
|
|
71
79
|
|
|
72
80
|
// src/utils/resolver.ts
|
|
73
81
|
var resolvePrivateKey = (words) => core.resolvePrivateKey(words);
|
|
74
|
-
var resolveTxHash = (txHex) => core.
|
|
75
|
-
var resolveDataHash = (
|
|
82
|
+
var resolveTxHash = (txHex) => core.resolveTxHash(txHex);
|
|
83
|
+
var resolveDataHash = (rawData, type = "Mesh") => core.resolveDataHash(rawData, type);
|
|
76
84
|
var resolveNativeScriptHash = (script) => core.resolveNativeScriptHash(script);
|
|
77
85
|
var resolveScriptHash = (scriptCode, version) => {
|
|
78
86
|
if (!version) {
|
|
79
|
-
return core.deserializeNativeScript(scriptCode).hash().
|
|
87
|
+
return core.deserializeNativeScript(scriptCode).hash().toString();
|
|
80
88
|
}
|
|
81
|
-
return core.deserializePlutusScript(scriptCode, version).hash().
|
|
89
|
+
return core.deserializePlutusScript(scriptCode, version).hash().toString();
|
|
82
90
|
};
|
|
83
91
|
var resolveRewardAddress = (bech32) => core.resolveRewardAddress(bech32);
|
|
84
92
|
var resolveStakeKeyHash = (bech32) => core.resolveStakeKeyHash(bech32);
|
|
85
93
|
var resolveScriptHashDRepId = (scriptHash) => core.resolveScriptHashDRepId(scriptHash);
|
|
86
94
|
var resolvePlutusScriptAddress = (script, networkId) => core.resolvePlutusScriptAddress(script, networkId);
|
|
87
95
|
var resolveNativeScriptAddress = (script, networkId) => core.resolveNativeScriptAddress(script, networkId);
|
|
88
|
-
var resolveNativeScriptHex = (script) => core.toNativeScript(script).
|
|
96
|
+
var resolveNativeScriptHex = (script) => core.toNativeScript(script).toCbor().toString();
|
|
89
97
|
var resolvePaymentKeyHash = (bech32) => core.deserializeBech32Address(bech32).pubKeyHash;
|
|
90
98
|
var resolvePlutusScriptHash = (bech32) => core.deserializeBech32Address(bech32).scriptHash;
|
|
91
99
|
var resolveScriptRef = (script) => core.resolveScriptRef(script);
|
|
92
|
-
var resolvePoolId = (hash) => core.
|
|
100
|
+
var resolvePoolId = (hash) => core.resolvePoolId(hash);
|
|
93
101
|
|
|
94
102
|
// src/utils/deserializer.ts
|
|
95
103
|
var deserializeAddress = (bech32) => core.deserializeBech32Address(bech32);
|
|
@@ -98,7 +106,10 @@ var deserializePoolId = (poolId) => core.resolveEd25519KeyHash(poolId);
|
|
|
98
106
|
|
|
99
107
|
// src/utils/serializer.ts
|
|
100
108
|
var serializeNativeScript = (script, stakeCredentialHash, networkId = 0, isScriptStakeCredential = false) => {
|
|
101
|
-
|
|
109
|
+
if (networkId !== 0 && networkId !== 1) {
|
|
110
|
+
throw new Error("Invalid network id");
|
|
111
|
+
}
|
|
112
|
+
const serializer = new core.CardanoSDKSerializer();
|
|
102
113
|
const { scriptCbor, scriptHash } = serializer.deserializer.script.deserializeNativeScript(script);
|
|
103
114
|
const deserializedAddress = {
|
|
104
115
|
scriptHash
|
|
@@ -112,7 +123,7 @@ var serializeNativeScript = (script, stakeCredentialHash, networkId = 0, isScrip
|
|
|
112
123
|
return { address, scriptCbor };
|
|
113
124
|
};
|
|
114
125
|
var serializePlutusScript = (script, stakeCredentialHash, networkId = 0, isScriptStakeCredential = false) => {
|
|
115
|
-
const scriptHash = core.deserializePlutusScript(script.code, script.version).hash().
|
|
126
|
+
const scriptHash = core.deserializePlutusScript(script.code, script.version).hash().toString();
|
|
116
127
|
const address = core.scriptHashToBech32(
|
|
117
128
|
scriptHash,
|
|
118
129
|
stakeCredentialHash,
|
|
@@ -124,10 +135,144 @@ var serializePlutusScript = (script, stakeCredentialHash, networkId = 0, isScrip
|
|
|
124
135
|
var serializeAddressObj = (address, networkId = 0) => {
|
|
125
136
|
return core.serializeAddressObj(address, networkId);
|
|
126
137
|
};
|
|
127
|
-
var serializePoolId = (hash) => core.
|
|
138
|
+
var serializePoolId = (hash) => core.resolvePoolId(hash);
|
|
128
139
|
var serializeRewardAddress = (hash, isScriptHash = false, networkId = 0) => {
|
|
129
140
|
return isScriptHash ? core.scriptHashToRewardAddress(hash, networkId) : core.keyHashToRewardAddress(hash, networkId);
|
|
130
141
|
};
|
|
142
|
+
var serializeData = (rawData, type = "Mesh") => {
|
|
143
|
+
const serializer = new core.CardanoSDKSerializer();
|
|
144
|
+
const builderData = {
|
|
145
|
+
type,
|
|
146
|
+
content: rawData
|
|
147
|
+
};
|
|
148
|
+
return serializer.serializeData(builderData);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// src/utils/blueprint/minting.ts
|
|
152
|
+
var MintingBlueprint = class {
|
|
153
|
+
version;
|
|
154
|
+
cbor;
|
|
155
|
+
hash;
|
|
156
|
+
constructor(version) {
|
|
157
|
+
this.version = version;
|
|
158
|
+
this.cbor = "";
|
|
159
|
+
this.hash = "";
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Initialize the minting blueprint, with the same parameters to `applyParamsToScript`
|
|
163
|
+
* @param compiledCode The raw script CborHex from blueprint.
|
|
164
|
+
* @param params The parameters to apply, in an array.
|
|
165
|
+
* @param paramsType The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
|
|
166
|
+
* @returns The minting blueprint object
|
|
167
|
+
*/
|
|
168
|
+
paramScript(compiledCode, params, paramsType = "Mesh") {
|
|
169
|
+
const cbor = applyParamsToScript2(compiledCode, params, paramsType);
|
|
170
|
+
const hash = resolveScriptHash(cbor, this.version);
|
|
171
|
+
this.hash = hash;
|
|
172
|
+
this.cbor = cbor;
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Initialize the minting blueprint, with no parameters
|
|
177
|
+
* @param compiledCode The raw script CborHex from blueprint.
|
|
178
|
+
* @returns The minting blueprint object
|
|
179
|
+
*/
|
|
180
|
+
noParamScript(compiledCode) {
|
|
181
|
+
return this.paramScript(compiledCode, []);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// src/utils/blueprint/spending.ts
|
|
186
|
+
var SpendingBlueprint = class {
|
|
187
|
+
version;
|
|
188
|
+
networkId;
|
|
189
|
+
cbor;
|
|
190
|
+
hash;
|
|
191
|
+
address;
|
|
192
|
+
stakeHash;
|
|
193
|
+
isStakeScriptCredential;
|
|
194
|
+
constructor(version, networkId, stakeHash, isStakeScriptCredential = false) {
|
|
195
|
+
this.version = version;
|
|
196
|
+
this.networkId = networkId;
|
|
197
|
+
this.stakeHash = stakeHash;
|
|
198
|
+
this.cbor = "";
|
|
199
|
+
this.hash = "";
|
|
200
|
+
this.address = "";
|
|
201
|
+
this.isStakeScriptCredential = isStakeScriptCredential;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Initialize the minting blueprint, with the same parameters to `applyParamsToScript`
|
|
205
|
+
* @param compiledCode The raw script CborHex from blueprint.
|
|
206
|
+
* @param params The parameters to apply, in an array.
|
|
207
|
+
* @param paramsType The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
|
|
208
|
+
* @returns
|
|
209
|
+
*/
|
|
210
|
+
paramScript(compiledCode, params, paramsType = "Mesh") {
|
|
211
|
+
const cbor = applyParamsToScript2(compiledCode, params, paramsType);
|
|
212
|
+
const hash = resolveScriptHash(cbor, this.version);
|
|
213
|
+
const plutusScript = {
|
|
214
|
+
code: cbor,
|
|
215
|
+
version: this.version
|
|
216
|
+
};
|
|
217
|
+
const address = serializePlutusScript(
|
|
218
|
+
plutusScript,
|
|
219
|
+
this.stakeHash,
|
|
220
|
+
this.networkId,
|
|
221
|
+
this.isStakeScriptCredential
|
|
222
|
+
).address;
|
|
223
|
+
this.hash = hash;
|
|
224
|
+
this.cbor = cbor;
|
|
225
|
+
this.address = address;
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Initialize the minting blueprint, with no parameters
|
|
230
|
+
* @param compiledCode The raw script CborHex from blueprint.
|
|
231
|
+
* @returns The minting blueprint object
|
|
232
|
+
*/
|
|
233
|
+
noParamScript(compiledCode) {
|
|
234
|
+
return this.paramScript(compiledCode, []);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
// src/utils/blueprint/withdrawal.ts
|
|
239
|
+
var WithdrawalBlueprint = class {
|
|
240
|
+
version;
|
|
241
|
+
networkId;
|
|
242
|
+
cbor;
|
|
243
|
+
hash;
|
|
244
|
+
address;
|
|
245
|
+
constructor(version, networkId) {
|
|
246
|
+
this.version = version;
|
|
247
|
+
this.networkId = networkId;
|
|
248
|
+
this.cbor = "";
|
|
249
|
+
this.hash = "";
|
|
250
|
+
this.address = "";
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Initialize the withdrawal blueprint, with the same parameters to `applyParamsToScript`
|
|
254
|
+
* @param compiledCode The raw script CborHex from blueprint.
|
|
255
|
+
* @param params The parameters to apply, in an array.
|
|
256
|
+
* @param paramsType The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
|
|
257
|
+
* @returns The withdrawal blueprint object
|
|
258
|
+
*/
|
|
259
|
+
paramScript(compiledCode, params, paramsType = "Mesh") {
|
|
260
|
+
const cbor = applyParamsToScript2(compiledCode, params, paramsType);
|
|
261
|
+
const hash = resolveScriptHash(cbor, this.version);
|
|
262
|
+
this.address = serializeRewardAddress(hash, true, this.networkId);
|
|
263
|
+
this.hash = hash;
|
|
264
|
+
this.cbor = cbor;
|
|
265
|
+
return this;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Initialize the withdrawal blueprint, with no parameters
|
|
269
|
+
* @param compiledCode The raw script CborHex from blueprint.
|
|
270
|
+
* @returns The withdrawal blueprint object
|
|
271
|
+
*/
|
|
272
|
+
noParamScript(compiledCode) {
|
|
273
|
+
return this.paramScript(compiledCode, []);
|
|
274
|
+
}
|
|
275
|
+
};
|
|
131
276
|
|
|
132
277
|
// src/index.ts
|
|
133
278
|
__reExport(index_exports, require("@meshsdk/common"), module.exports);
|
|
@@ -138,6 +283,9 @@ __reExport(index_exports, require("@meshsdk/wallet"), module.exports);
|
|
|
138
283
|
var import_core_cst = require("@meshsdk/core-cst");
|
|
139
284
|
// Annotate the CommonJS export names for ESM import in node:
|
|
140
285
|
0 && (module.exports = {
|
|
286
|
+
MintingBlueprint,
|
|
287
|
+
SpendingBlueprint,
|
|
288
|
+
WithdrawalBlueprint,
|
|
141
289
|
applyCborEncoding,
|
|
142
290
|
applyParamsToScript,
|
|
143
291
|
checkSignature,
|
|
@@ -163,6 +311,7 @@ var import_core_cst = require("@meshsdk/core-cst");
|
|
|
163
311
|
resolveStakeKeyHash,
|
|
164
312
|
resolveTxHash,
|
|
165
313
|
serializeAddressObj,
|
|
314
|
+
serializeData,
|
|
166
315
|
serializeNativeScript,
|
|
167
316
|
serializePlutusScript,
|
|
168
317
|
serializePoolId,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Data, NativeScript, LanguageVersion, PlutusScript, DeserializedAddress, PubKeyAddress, ScriptAddress } from '@meshsdk/common';
|
|
1
|
+
import { Data, PlutusDataType, BuilderData, NativeScript, LanguageVersion, PlutusScript, DeserializedAddress, PubKeyAddress, ScriptAddress, IMintingBlueprint, ISpendingBlueprint, IWithdrawalBlueprint } from '@meshsdk/common';
|
|
3
2
|
export * from '@meshsdk/common';
|
|
4
3
|
import * as coreCst from '@meshsdk/core-cst';
|
|
4
|
+
export { coreCst as core };
|
|
5
5
|
export { coreCst as cst };
|
|
6
6
|
export { checkSignature, generateNonce, signData } from '@meshsdk/core-cst';
|
|
7
7
|
export * from '@meshsdk/provider';
|
|
8
8
|
export * from '@meshsdk/transaction';
|
|
9
9
|
export * from '@meshsdk/wallet';
|
|
10
|
-
import * as coreCsl from '@meshsdk/core-csl';
|
|
11
|
-
export { coreCsl as core };
|
|
12
10
|
|
|
13
|
-
|
|
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
|
+
*/
|
|
14
28
|
declare const applyCborEncoding: (rawScript: string) => string;
|
|
15
29
|
|
|
16
30
|
/**
|
|
@@ -30,10 +44,11 @@ declare const resolvePrivateKey: (words: string[]) => string;
|
|
|
30
44
|
declare const resolveTxHash: (txHex: string) => string;
|
|
31
45
|
/**
|
|
32
46
|
* Hash Cardano data
|
|
33
|
-
* @param
|
|
47
|
+
* @param rawData Cardano data in Mesh, JSON or CBOR type
|
|
48
|
+
* @param type The data type, either Mesh, JSON or CBOR
|
|
34
49
|
* @returns Cardano data hash
|
|
35
50
|
*/
|
|
36
|
-
declare const resolveDataHash: (
|
|
51
|
+
declare const resolveDataHash: (rawData: BuilderData["content"], type?: PlutusDataType) => string;
|
|
37
52
|
/**
|
|
38
53
|
* Hash Cardano native script
|
|
39
54
|
* @param script Cardano native script in Mesh NativeScript type
|
|
@@ -163,5 +178,122 @@ declare const serializePoolId: (hash: string) => string;
|
|
|
163
178
|
* @returns Bech32 reward address
|
|
164
179
|
*/
|
|
165
180
|
declare const serializeRewardAddress: (hash: string, isScriptHash?: boolean, networkId?: 0 | 1) => string;
|
|
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
|
+
}
|
|
166
298
|
|
|
167
|
-
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,30 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Data, NativeScript, LanguageVersion, PlutusScript, DeserializedAddress, PubKeyAddress, ScriptAddress } from '@meshsdk/common';
|
|
1
|
+
import { Data, PlutusDataType, BuilderData, NativeScript, LanguageVersion, PlutusScript, DeserializedAddress, PubKeyAddress, ScriptAddress, IMintingBlueprint, ISpendingBlueprint, IWithdrawalBlueprint } from '@meshsdk/common';
|
|
3
2
|
export * from '@meshsdk/common';
|
|
4
3
|
import * as coreCst from '@meshsdk/core-cst';
|
|
4
|
+
export { coreCst as core };
|
|
5
5
|
export { coreCst as cst };
|
|
6
6
|
export { checkSignature, generateNonce, signData } from '@meshsdk/core-cst';
|
|
7
7
|
export * from '@meshsdk/provider';
|
|
8
8
|
export * from '@meshsdk/transaction';
|
|
9
9
|
export * from '@meshsdk/wallet';
|
|
10
|
-
import * as coreCsl from '@meshsdk/core-csl';
|
|
11
|
-
export { coreCsl as core };
|
|
12
10
|
|
|
13
|
-
|
|
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
|
+
*/
|
|
14
28
|
declare const applyCborEncoding: (rawScript: string) => string;
|
|
15
29
|
|
|
16
30
|
/**
|
|
@@ -30,10 +44,11 @@ declare const resolvePrivateKey: (words: string[]) => string;
|
|
|
30
44
|
declare const resolveTxHash: (txHex: string) => string;
|
|
31
45
|
/**
|
|
32
46
|
* Hash Cardano data
|
|
33
|
-
* @param
|
|
47
|
+
* @param rawData Cardano data in Mesh, JSON or CBOR type
|
|
48
|
+
* @param type The data type, either Mesh, JSON or CBOR
|
|
34
49
|
* @returns Cardano data hash
|
|
35
50
|
*/
|
|
36
|
-
declare const resolveDataHash: (
|
|
51
|
+
declare const resolveDataHash: (rawData: BuilderData["content"], type?: PlutusDataType) => string;
|
|
37
52
|
/**
|
|
38
53
|
* Hash Cardano native script
|
|
39
54
|
* @param script Cardano native script in Mesh NativeScript type
|
|
@@ -163,5 +178,122 @@ declare const serializePoolId: (hash: string) => string;
|
|
|
163
178
|
* @returns Bech32 reward address
|
|
164
179
|
*/
|
|
165
180
|
declare const serializeRewardAddress: (hash: string, isScriptHash?: boolean, networkId?: 0 | 1) => string;
|
|
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
|
+
}
|
|
166
298
|
|
|
167
|
-
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,29 +1,33 @@
|
|
|
1
1
|
// src/core.ts
|
|
2
|
-
import * as core from "@meshsdk/core-
|
|
3
|
-
var applyParamsToScript2 = core.applyParamsToScript;
|
|
4
|
-
var
|
|
2
|
+
import * as core from "@meshsdk/core-cst";
|
|
3
|
+
var applyParamsToScript2 = (rawScript, params, type) => core.applyParamsToScript(rawScript, params, type);
|
|
4
|
+
var applyCborEncoding = (rawScript) => {
|
|
5
|
+
return Buffer.from(
|
|
6
|
+
core.applyEncoding(Buffer.from(rawScript, "hex"), "SingleCBOR")
|
|
7
|
+
).toString("hex");
|
|
8
|
+
};
|
|
5
9
|
|
|
6
10
|
// src/utils/resolver.ts
|
|
7
11
|
var resolvePrivateKey = (words) => core.resolvePrivateKey(words);
|
|
8
|
-
var resolveTxHash = (txHex) => core.
|
|
9
|
-
var resolveDataHash = (
|
|
12
|
+
var resolveTxHash = (txHex) => core.resolveTxHash(txHex);
|
|
13
|
+
var resolveDataHash = (rawData, type = "Mesh") => core.resolveDataHash(rawData, type);
|
|
10
14
|
var resolveNativeScriptHash = (script) => core.resolveNativeScriptHash(script);
|
|
11
15
|
var resolveScriptHash = (scriptCode, version) => {
|
|
12
16
|
if (!version) {
|
|
13
|
-
return core.deserializeNativeScript(scriptCode).hash().
|
|
17
|
+
return core.deserializeNativeScript(scriptCode).hash().toString();
|
|
14
18
|
}
|
|
15
|
-
return core.deserializePlutusScript(scriptCode, version).hash().
|
|
19
|
+
return core.deserializePlutusScript(scriptCode, version).hash().toString();
|
|
16
20
|
};
|
|
17
21
|
var resolveRewardAddress = (bech32) => core.resolveRewardAddress(bech32);
|
|
18
22
|
var resolveStakeKeyHash = (bech32) => core.resolveStakeKeyHash(bech32);
|
|
19
23
|
var resolveScriptHashDRepId = (scriptHash) => core.resolveScriptHashDRepId(scriptHash);
|
|
20
24
|
var resolvePlutusScriptAddress = (script, networkId) => core.resolvePlutusScriptAddress(script, networkId);
|
|
21
25
|
var resolveNativeScriptAddress = (script, networkId) => core.resolveNativeScriptAddress(script, networkId);
|
|
22
|
-
var resolveNativeScriptHex = (script) => core.toNativeScript(script).
|
|
26
|
+
var resolveNativeScriptHex = (script) => core.toNativeScript(script).toCbor().toString();
|
|
23
27
|
var resolvePaymentKeyHash = (bech32) => core.deserializeBech32Address(bech32).pubKeyHash;
|
|
24
28
|
var resolvePlutusScriptHash = (bech32) => core.deserializeBech32Address(bech32).scriptHash;
|
|
25
29
|
var resolveScriptRef = (script) => core.resolveScriptRef(script);
|
|
26
|
-
var resolvePoolId = (hash) => core.
|
|
30
|
+
var resolvePoolId = (hash) => core.resolvePoolId(hash);
|
|
27
31
|
|
|
28
32
|
// src/utils/deserializer.ts
|
|
29
33
|
var deserializeAddress = (bech32) => core.deserializeBech32Address(bech32);
|
|
@@ -32,7 +36,10 @@ var deserializePoolId = (poolId) => core.resolveEd25519KeyHash(poolId);
|
|
|
32
36
|
|
|
33
37
|
// src/utils/serializer.ts
|
|
34
38
|
var serializeNativeScript = (script, stakeCredentialHash, networkId = 0, isScriptStakeCredential = false) => {
|
|
35
|
-
|
|
39
|
+
if (networkId !== 0 && networkId !== 1) {
|
|
40
|
+
throw new Error("Invalid network id");
|
|
41
|
+
}
|
|
42
|
+
const serializer = new core.CardanoSDKSerializer();
|
|
36
43
|
const { scriptCbor, scriptHash } = serializer.deserializer.script.deserializeNativeScript(script);
|
|
37
44
|
const deserializedAddress = {
|
|
38
45
|
scriptHash
|
|
@@ -46,7 +53,7 @@ var serializeNativeScript = (script, stakeCredentialHash, networkId = 0, isScrip
|
|
|
46
53
|
return { address, scriptCbor };
|
|
47
54
|
};
|
|
48
55
|
var serializePlutusScript = (script, stakeCredentialHash, networkId = 0, isScriptStakeCredential = false) => {
|
|
49
|
-
const scriptHash = core.deserializePlutusScript(script.code, script.version).hash().
|
|
56
|
+
const scriptHash = core.deserializePlutusScript(script.code, script.version).hash().toString();
|
|
50
57
|
const address = core.scriptHashToBech32(
|
|
51
58
|
scriptHash,
|
|
52
59
|
stakeCredentialHash,
|
|
@@ -58,10 +65,144 @@ var serializePlutusScript = (script, stakeCredentialHash, networkId = 0, isScrip
|
|
|
58
65
|
var serializeAddressObj = (address, networkId = 0) => {
|
|
59
66
|
return core.serializeAddressObj(address, networkId);
|
|
60
67
|
};
|
|
61
|
-
var serializePoolId = (hash) => core.
|
|
68
|
+
var serializePoolId = (hash) => core.resolvePoolId(hash);
|
|
62
69
|
var serializeRewardAddress = (hash, isScriptHash = false, networkId = 0) => {
|
|
63
70
|
return isScriptHash ? core.scriptHashToRewardAddress(hash, networkId) : core.keyHashToRewardAddress(hash, networkId);
|
|
64
71
|
};
|
|
72
|
+
var serializeData = (rawData, type = "Mesh") => {
|
|
73
|
+
const serializer = new core.CardanoSDKSerializer();
|
|
74
|
+
const builderData = {
|
|
75
|
+
type,
|
|
76
|
+
content: rawData
|
|
77
|
+
};
|
|
78
|
+
return serializer.serializeData(builderData);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/utils/blueprint/minting.ts
|
|
82
|
+
var MintingBlueprint = class {
|
|
83
|
+
version;
|
|
84
|
+
cbor;
|
|
85
|
+
hash;
|
|
86
|
+
constructor(version) {
|
|
87
|
+
this.version = version;
|
|
88
|
+
this.cbor = "";
|
|
89
|
+
this.hash = "";
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Initialize the minting blueprint, with the same parameters to `applyParamsToScript`
|
|
93
|
+
* @param compiledCode The raw script CborHex from blueprint.
|
|
94
|
+
* @param params The parameters to apply, in an array.
|
|
95
|
+
* @param paramsType The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
|
|
96
|
+
* @returns The minting blueprint object
|
|
97
|
+
*/
|
|
98
|
+
paramScript(compiledCode, params, paramsType = "Mesh") {
|
|
99
|
+
const cbor = applyParamsToScript2(compiledCode, params, paramsType);
|
|
100
|
+
const hash = resolveScriptHash(cbor, this.version);
|
|
101
|
+
this.hash = hash;
|
|
102
|
+
this.cbor = cbor;
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Initialize the minting blueprint, with no parameters
|
|
107
|
+
* @param compiledCode The raw script CborHex from blueprint.
|
|
108
|
+
* @returns The minting blueprint object
|
|
109
|
+
*/
|
|
110
|
+
noParamScript(compiledCode) {
|
|
111
|
+
return this.paramScript(compiledCode, []);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/utils/blueprint/spending.ts
|
|
116
|
+
var SpendingBlueprint = class {
|
|
117
|
+
version;
|
|
118
|
+
networkId;
|
|
119
|
+
cbor;
|
|
120
|
+
hash;
|
|
121
|
+
address;
|
|
122
|
+
stakeHash;
|
|
123
|
+
isStakeScriptCredential;
|
|
124
|
+
constructor(version, networkId, stakeHash, isStakeScriptCredential = false) {
|
|
125
|
+
this.version = version;
|
|
126
|
+
this.networkId = networkId;
|
|
127
|
+
this.stakeHash = stakeHash;
|
|
128
|
+
this.cbor = "";
|
|
129
|
+
this.hash = "";
|
|
130
|
+
this.address = "";
|
|
131
|
+
this.isStakeScriptCredential = isStakeScriptCredential;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Initialize the minting blueprint, with the same parameters to `applyParamsToScript`
|
|
135
|
+
* @param compiledCode The raw script CborHex from blueprint.
|
|
136
|
+
* @param params The parameters to apply, in an array.
|
|
137
|
+
* @param paramsType The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
|
|
138
|
+
* @returns
|
|
139
|
+
*/
|
|
140
|
+
paramScript(compiledCode, params, paramsType = "Mesh") {
|
|
141
|
+
const cbor = applyParamsToScript2(compiledCode, params, paramsType);
|
|
142
|
+
const hash = resolveScriptHash(cbor, this.version);
|
|
143
|
+
const plutusScript = {
|
|
144
|
+
code: cbor,
|
|
145
|
+
version: this.version
|
|
146
|
+
};
|
|
147
|
+
const address = serializePlutusScript(
|
|
148
|
+
plutusScript,
|
|
149
|
+
this.stakeHash,
|
|
150
|
+
this.networkId,
|
|
151
|
+
this.isStakeScriptCredential
|
|
152
|
+
).address;
|
|
153
|
+
this.hash = hash;
|
|
154
|
+
this.cbor = cbor;
|
|
155
|
+
this.address = address;
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Initialize the minting blueprint, with no parameters
|
|
160
|
+
* @param compiledCode The raw script CborHex from blueprint.
|
|
161
|
+
* @returns The minting blueprint object
|
|
162
|
+
*/
|
|
163
|
+
noParamScript(compiledCode) {
|
|
164
|
+
return this.paramScript(compiledCode, []);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// src/utils/blueprint/withdrawal.ts
|
|
169
|
+
var WithdrawalBlueprint = class {
|
|
170
|
+
version;
|
|
171
|
+
networkId;
|
|
172
|
+
cbor;
|
|
173
|
+
hash;
|
|
174
|
+
address;
|
|
175
|
+
constructor(version, networkId) {
|
|
176
|
+
this.version = version;
|
|
177
|
+
this.networkId = networkId;
|
|
178
|
+
this.cbor = "";
|
|
179
|
+
this.hash = "";
|
|
180
|
+
this.address = "";
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Initialize the withdrawal blueprint, with the same parameters to `applyParamsToScript`
|
|
184
|
+
* @param compiledCode The raw script CborHex from blueprint.
|
|
185
|
+
* @param params The parameters to apply, in an array.
|
|
186
|
+
* @param paramsType The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
|
|
187
|
+
* @returns The withdrawal blueprint object
|
|
188
|
+
*/
|
|
189
|
+
paramScript(compiledCode, params, paramsType = "Mesh") {
|
|
190
|
+
const cbor = applyParamsToScript2(compiledCode, params, paramsType);
|
|
191
|
+
const hash = resolveScriptHash(cbor, this.version);
|
|
192
|
+
this.address = serializeRewardAddress(hash, true, this.networkId);
|
|
193
|
+
this.hash = hash;
|
|
194
|
+
this.cbor = cbor;
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Initialize the withdrawal blueprint, with no parameters
|
|
199
|
+
* @param compiledCode The raw script CborHex from blueprint.
|
|
200
|
+
* @returns The withdrawal blueprint object
|
|
201
|
+
*/
|
|
202
|
+
noParamScript(compiledCode) {
|
|
203
|
+
return this.paramScript(compiledCode, []);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
65
206
|
|
|
66
207
|
// src/index.ts
|
|
67
208
|
export * from "@meshsdk/common";
|
|
@@ -71,7 +212,10 @@ export * from "@meshsdk/transaction";
|
|
|
71
212
|
export * from "@meshsdk/wallet";
|
|
72
213
|
import { checkSignature, signData, generateNonce } from "@meshsdk/core-cst";
|
|
73
214
|
export {
|
|
74
|
-
|
|
215
|
+
MintingBlueprint,
|
|
216
|
+
SpendingBlueprint,
|
|
217
|
+
WithdrawalBlueprint,
|
|
218
|
+
applyCborEncoding,
|
|
75
219
|
applyParamsToScript2 as applyParamsToScript,
|
|
76
220
|
checkSignature,
|
|
77
221
|
core,
|
|
@@ -96,6 +240,7 @@ export {
|
|
|
96
240
|
resolveStakeKeyHash,
|
|
97
241
|
resolveTxHash,
|
|
98
242
|
serializeAddressObj,
|
|
243
|
+
serializeData,
|
|
99
244
|
serializeNativeScript,
|
|
100
245
|
serializePlutusScript,
|
|
101
246
|
serializePoolId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshsdk/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0-beta-38",
|
|
4
4
|
"description": "Mesh SDK Core - https://meshjs.dev/",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"browser": "./dist/index.js",
|
|
@@ -33,13 +33,12 @@
|
|
|
33
33
|
"typescript": "^5.3.3"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@meshsdk/common": "1.
|
|
37
|
-
"@meshsdk/core-
|
|
38
|
-
"@meshsdk/
|
|
39
|
-
"@meshsdk/
|
|
40
|
-
"@meshsdk/
|
|
41
|
-
"@meshsdk/
|
|
42
|
-
"@meshsdk/wallet": "1.8.14"
|
|
36
|
+
"@meshsdk/common": "1.9.0-beta-38",
|
|
37
|
+
"@meshsdk/core-cst": "1.9.0-beta-38",
|
|
38
|
+
"@meshsdk/provider": "1.9.0-beta-38",
|
|
39
|
+
"@meshsdk/react": "1.9.0-beta-38",
|
|
40
|
+
"@meshsdk/transaction": "1.9.0-beta-38",
|
|
41
|
+
"@meshsdk/wallet": "1.9.0-beta-38"
|
|
43
42
|
},
|
|
44
43
|
"prettier": "@meshsdk/configs/prettier",
|
|
45
44
|
"publishConfig": {
|
|
@@ -48,9 +47,10 @@
|
|
|
48
47
|
"license": "Apache-2.0",
|
|
49
48
|
"keywords": [
|
|
50
49
|
"cardano",
|
|
51
|
-
"ada",
|
|
52
50
|
"web3",
|
|
53
51
|
"blockchain",
|
|
54
|
-
"sdk"
|
|
52
|
+
"sdk",
|
|
53
|
+
"typescript",
|
|
54
|
+
"javascript"
|
|
55
55
|
]
|
|
56
56
|
}
|