@meshsdk/core-csl 1.5.28
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 +5 -0
- package/dist/cjs/core/adaptor/data.d.ts +3 -0
- package/dist/cjs/core/adaptor/data.js +21 -0
- package/dist/cjs/core/adaptor/index.d.ts +15 -0
- package/dist/cjs/core/adaptor/index.js +25 -0
- package/dist/cjs/core/adaptor/mint.d.ts +5 -0
- package/dist/cjs/core/adaptor/mint.js +42 -0
- package/dist/cjs/core/adaptor/output.d.ts +2 -0
- package/dist/cjs/core/adaptor/output.js +33 -0
- package/dist/cjs/core/adaptor/script.d.ts +3 -0
- package/dist/cjs/core/adaptor/script.js +46 -0
- package/dist/cjs/core/adaptor/txIn.d.ts +5 -0
- package/dist/cjs/core/adaptor/txIn.js +76 -0
- package/dist/cjs/core/adaptor/utxo.d.ts +2 -0
- package/dist/cjs/core/adaptor/utxo.js +20 -0
- package/dist/cjs/core/adaptor/withdrawal.d.ts +2 -0
- package/dist/cjs/core/adaptor/withdrawal.js +30 -0
- package/dist/cjs/core/index.d.ts +1 -0
- package/dist/cjs/core/index.js +17 -0
- package/dist/cjs/core/serializer.d.ts +12 -0
- package/dist/cjs/core/serializer.js +111 -0
- package/dist/cjs/deser/constants.d.ts +13 -0
- package/dist/cjs/deser/constants.js +16 -0
- package/dist/cjs/deser/converter.d.ts +17 -0
- package/dist/cjs/deser/converter.js +203 -0
- package/dist/cjs/deser/csl.d.ts +1 -0
- package/dist/cjs/deser/csl.js +27 -0
- package/dist/cjs/deser/deserializer.d.ts +19 -0
- package/dist/cjs/deser/deserializer.js +40 -0
- package/dist/cjs/deser/index.d.ts +5 -0
- package/dist/cjs/deser/index.js +21 -0
- package/dist/cjs/deser/resolver.d.ts +12 -0
- package/dist/cjs/deser/resolver.js +90 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/utils/address.d.ts +9 -0
- package/dist/cjs/utils/address.js +61 -0
- package/dist/cjs/utils/aiken.d.ts +17 -0
- package/dist/cjs/utils/aiken.js +52 -0
- package/dist/cjs/utils/credentials.d.ts +1 -0
- package/dist/cjs/utils/credentials.js +10 -0
- package/dist/cjs/utils/datum.d.ts +4 -0
- package/dist/cjs/utils/datum.js +18 -0
- package/dist/cjs/utils/index.d.ts +7 -0
- package/dist/cjs/utils/index.js +23 -0
- package/dist/cjs/utils/scripts.d.ts +1 -0
- package/dist/cjs/utils/scripts.js +6 -0
- package/dist/cjs/utils/staking.d.ts +4 -0
- package/dist/cjs/utils/staking.js +34 -0
- package/dist/cjs/utils/transaction.d.ts +2 -0
- package/dist/cjs/utils/transaction.js +15 -0
- package/dist/mjs/core/adaptor/data.d.ts +3 -0
- package/dist/mjs/core/adaptor/data.js +16 -0
- package/dist/mjs/core/adaptor/index.d.ts +15 -0
- package/dist/mjs/core/adaptor/index.js +21 -0
- package/dist/mjs/core/adaptor/mint.d.ts +5 -0
- package/dist/mjs/core/adaptor/mint.js +35 -0
- package/dist/mjs/core/adaptor/output.d.ts +2 -0
- package/dist/mjs/core/adaptor/output.js +29 -0
- package/dist/mjs/core/adaptor/script.d.ts +3 -0
- package/dist/mjs/core/adaptor/script.js +39 -0
- package/dist/mjs/core/adaptor/txIn.d.ts +5 -0
- package/dist/mjs/core/adaptor/txIn.js +68 -0
- package/dist/mjs/core/adaptor/utxo.d.ts +2 -0
- package/dist/mjs/core/adaptor/utxo.js +16 -0
- package/dist/mjs/core/adaptor/withdrawal.d.ts +2 -0
- package/dist/mjs/core/adaptor/withdrawal.js +26 -0
- package/dist/mjs/core/index.d.ts +1 -0
- package/dist/mjs/core/index.js +1 -0
- package/dist/mjs/core/serializer.d.ts +12 -0
- package/dist/mjs/core/serializer.js +105 -0
- package/dist/mjs/deser/constants.d.ts +13 -0
- package/dist/mjs/deser/constants.js +13 -0
- package/dist/mjs/deser/converter.d.ts +17 -0
- package/dist/mjs/deser/converter.js +184 -0
- package/dist/mjs/deser/csl.d.ts +1 -0
- package/dist/mjs/deser/csl.js +1 -0
- package/dist/mjs/deser/deserializer.d.ts +19 -0
- package/dist/mjs/deser/deserializer.js +20 -0
- package/dist/mjs/deser/index.d.ts +5 -0
- package/dist/mjs/deser/index.js +5 -0
- package/dist/mjs/deser/resolver.d.ts +12 -0
- package/dist/mjs/deser/resolver.js +75 -0
- package/dist/mjs/index.d.ts +3 -0
- package/dist/mjs/index.js +3 -0
- package/dist/mjs/utils/address.d.ts +9 -0
- package/dist/mjs/utils/address.js +50 -0
- package/dist/mjs/utils/aiken.d.ts +17 -0
- package/dist/mjs/utils/aiken.js +47 -0
- package/dist/mjs/utils/credentials.d.ts +1 -0
- package/dist/mjs/utils/credentials.js +6 -0
- package/dist/mjs/utils/datum.d.ts +4 -0
- package/dist/mjs/utils/datum.js +13 -0
- package/dist/mjs/utils/index.d.ts +7 -0
- package/dist/mjs/utils/index.js +7 -0
- package/dist/mjs/utils/scripts.d.ts +1 -0
- package/dist/mjs/utils/scripts.js +2 -0
- package/dist/mjs/utils/staking.d.ts +4 -0
- package/dist/mjs/utils/staking.js +25 -0
- package/dist/mjs/utils/transaction.d.ts +2 -0
- package/dist/mjs/utils/transaction.js +10 -0
- package/package.json +45 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.toNativeScript = exports.castDataToPlutusData = exports.castRawDataToJsonString = exports.toPlutusData = exports.toScriptRef = exports.toLovelace = exports.fromLovelace = exports.toUTF8 = exports.fromUTF8 = exports.toBytes = exports.fromBytes = exports.toRewardAddress = exports.toEnterpriseAddress = exports.toBaseAddress = exports.toAddress = void 0;
|
|
7
|
+
/* eslint-disable consistent-return */
|
|
8
|
+
/* eslint-disable default-case */
|
|
9
|
+
const json_bigint_1 = __importDefault(require("json-bigint"));
|
|
10
|
+
// import { LANGUAGE_VERSIONS } from ".";
|
|
11
|
+
const csl_1 = require("./csl");
|
|
12
|
+
const deserializer_1 = require("./deserializer");
|
|
13
|
+
/* -----------------[ Address ]----------------- */
|
|
14
|
+
const toAddress = (bech32) => csl_1.csl.Address.from_bech32(bech32);
|
|
15
|
+
exports.toAddress = toAddress;
|
|
16
|
+
const toBaseAddress = (bech32) => csl_1.csl.BaseAddress.from_address((0, exports.toAddress)(bech32));
|
|
17
|
+
exports.toBaseAddress = toBaseAddress;
|
|
18
|
+
const toEnterpriseAddress = (bech32) => csl_1.csl.EnterpriseAddress.from_address((0, exports.toAddress)(bech32));
|
|
19
|
+
exports.toEnterpriseAddress = toEnterpriseAddress;
|
|
20
|
+
const toRewardAddress = (bech32) => csl_1.csl.RewardAddress.from_address((0, exports.toAddress)(bech32));
|
|
21
|
+
exports.toRewardAddress = toRewardAddress;
|
|
22
|
+
/* -----------------[ Bytes ]----------------- */
|
|
23
|
+
const fromBytes = (bytes) => Buffer.from(bytes).toString("hex");
|
|
24
|
+
exports.fromBytes = fromBytes;
|
|
25
|
+
const toBytes = (hex) => {
|
|
26
|
+
if (hex.length % 2 === 0 && /^[0-9A-F]*$/i.test(hex))
|
|
27
|
+
return Buffer.from(hex, "hex");
|
|
28
|
+
return Buffer.from(hex, "utf-8");
|
|
29
|
+
};
|
|
30
|
+
exports.toBytes = toBytes;
|
|
31
|
+
/* -----------------[ UTF-8 ]----------------- */
|
|
32
|
+
const fromUTF8 = (utf8) => {
|
|
33
|
+
if (utf8.length % 2 === 0 && /^[0-9A-F]*$/i.test(utf8))
|
|
34
|
+
return utf8;
|
|
35
|
+
return (0, exports.fromBytes)(Buffer.from(utf8, "utf-8"));
|
|
36
|
+
};
|
|
37
|
+
exports.fromUTF8 = fromUTF8;
|
|
38
|
+
const toUTF8 = (hex) => Buffer.from(hex, "hex").toString("utf-8");
|
|
39
|
+
exports.toUTF8 = toUTF8;
|
|
40
|
+
/* -----------------[ Lovelace ]----------------- */
|
|
41
|
+
const fromLovelace = (lovelace) => lovelace / 1000000;
|
|
42
|
+
exports.fromLovelace = fromLovelace;
|
|
43
|
+
const toLovelace = (ada) => ada * 1000000;
|
|
44
|
+
exports.toLovelace = toLovelace;
|
|
45
|
+
// /* -----------------[ NativeScript ]----------------- */
|
|
46
|
+
// export const fromNativeScript = (script: csl.NativeScript) => {
|
|
47
|
+
// const fromNativeScripts = (scripts: csl.NativeScripts) => {
|
|
48
|
+
// const nativeScripts = new Array<NativeScript>();
|
|
49
|
+
// for (let index = 0; index < scripts.len(); index += 1) {
|
|
50
|
+
// nativeScripts.push(fromNativeScript(scripts.get(index)));
|
|
51
|
+
// }
|
|
52
|
+
// return nativeScripts;
|
|
53
|
+
// };
|
|
54
|
+
// switch (script.kind()) {
|
|
55
|
+
// case csl.NativeScriptKind.ScriptAll: {
|
|
56
|
+
// const scriptAll = script.as_script_all()!;
|
|
57
|
+
// return <NativeScript>{
|
|
58
|
+
// type: "all",
|
|
59
|
+
// scripts: fromNativeScripts(scriptAll.native_scripts()),
|
|
60
|
+
// };
|
|
61
|
+
// }
|
|
62
|
+
// case csl.NativeScriptKind.ScriptAny: {
|
|
63
|
+
// const scriptAny = script.as_script_any()!;
|
|
64
|
+
// return <NativeScript>{
|
|
65
|
+
// type: "any",
|
|
66
|
+
// scripts: fromNativeScripts(scriptAny.native_scripts()),
|
|
67
|
+
// };
|
|
68
|
+
// }
|
|
69
|
+
// case csl.NativeScriptKind.ScriptNOfK: {
|
|
70
|
+
// const scriptNOfK = script.as_script_n_of_k()!;
|
|
71
|
+
// return <NativeScript>{
|
|
72
|
+
// type: "atLeast",
|
|
73
|
+
// required: scriptNOfK.n(),
|
|
74
|
+
// scripts: fromNativeScripts(scriptNOfK.native_scripts()),
|
|
75
|
+
// };
|
|
76
|
+
// }
|
|
77
|
+
// case csl.NativeScriptKind.TimelockStart: {
|
|
78
|
+
// const timelockStart = script.as_timelock_start()!;
|
|
79
|
+
// return <NativeScript>{
|
|
80
|
+
// type: "after",
|
|
81
|
+
// slot: timelockStart.slot_bignum().to_str(),
|
|
82
|
+
// };
|
|
83
|
+
// }
|
|
84
|
+
// case csl.NativeScriptKind.TimelockExpiry: {
|
|
85
|
+
// const timelockExpiry = script.as_timelock_expiry()!;
|
|
86
|
+
// return <NativeScript>{
|
|
87
|
+
// type: "before",
|
|
88
|
+
// slot: timelockExpiry.slot_bignum().to_str(),
|
|
89
|
+
// };
|
|
90
|
+
// }
|
|
91
|
+
// case csl.NativeScriptKind.ScriptPubkey: {
|
|
92
|
+
// const scriptPubkey = script.as_script_pubkey()!;
|
|
93
|
+
// return <NativeScript>{
|
|
94
|
+
// type: "sig",
|
|
95
|
+
// keyHash: scriptPubkey.addr_keyhash().to_hex(),
|
|
96
|
+
// };
|
|
97
|
+
// }
|
|
98
|
+
// default:
|
|
99
|
+
// throw new Error(`Script Kind: ${script.kind()}, is not supported`);
|
|
100
|
+
// }
|
|
101
|
+
// };
|
|
102
|
+
// /* -----------------[ Scripts ]----------------- */
|
|
103
|
+
// export const fromScriptRef = (
|
|
104
|
+
// scriptRef: string,
|
|
105
|
+
// ): PlutusScript | NativeScript | undefined => {
|
|
106
|
+
// const script = csl.ScriptRef.from_hex(scriptRef);
|
|
107
|
+
// if (script.is_plutus_script()) {
|
|
108
|
+
// const plutusScript = script.plutus_script()!;
|
|
109
|
+
// return <PlutusScript>{
|
|
110
|
+
// code: plutusScript.to_hex(),
|
|
111
|
+
// version: Object.keys(LANGUAGE_VERSIONS).find(
|
|
112
|
+
// (key) =>
|
|
113
|
+
// LANGUAGE_VERSIONS[key as LanguageVersion].to_hex() ===
|
|
114
|
+
// plutusScript.language_version().to_hex(),
|
|
115
|
+
// ),
|
|
116
|
+
// };
|
|
117
|
+
// }
|
|
118
|
+
// const nativeScript = script.native_script()!;
|
|
119
|
+
// return fromNativeScript(nativeScript);
|
|
120
|
+
// };
|
|
121
|
+
const toScriptRef = (script) => {
|
|
122
|
+
if ("code" in script) {
|
|
123
|
+
const plutusScript = (0, deserializer_1.deserializePlutusScript)(script.code, script.version);
|
|
124
|
+
return csl_1.csl.ScriptRef.new_plutus_script(plutusScript);
|
|
125
|
+
}
|
|
126
|
+
return csl_1.csl.ScriptRef.new_native_script((0, exports.toNativeScript)(script));
|
|
127
|
+
};
|
|
128
|
+
exports.toScriptRef = toScriptRef;
|
|
129
|
+
/* -----------------[ PlutusData ]----------------- */
|
|
130
|
+
const toPlutusData = (data) => {
|
|
131
|
+
const toPlutusList = (dataArray) => {
|
|
132
|
+
const plutusList = csl_1.csl.PlutusList.new();
|
|
133
|
+
dataArray.forEach((element) => {
|
|
134
|
+
plutusList.add((0, exports.toPlutusData)(element));
|
|
135
|
+
});
|
|
136
|
+
return plutusList;
|
|
137
|
+
};
|
|
138
|
+
switch (typeof data) {
|
|
139
|
+
case "string":
|
|
140
|
+
return csl_1.csl.PlutusData.new_bytes((0, exports.toBytes)(data));
|
|
141
|
+
case "number":
|
|
142
|
+
return csl_1.csl.PlutusData.new_integer(csl_1.csl.BigInt.from_str(data.toString()));
|
|
143
|
+
case "bigint":
|
|
144
|
+
return csl_1.csl.PlutusData.new_integer(csl_1.csl.BigInt.from_str(data.toString()));
|
|
145
|
+
case "object":
|
|
146
|
+
if (data instanceof Array) {
|
|
147
|
+
const plutusList = toPlutusList(data);
|
|
148
|
+
return csl_1.csl.PlutusData.new_list(plutusList);
|
|
149
|
+
}
|
|
150
|
+
if (data instanceof Map) {
|
|
151
|
+
const plutusMap = csl_1.csl.PlutusMap.new();
|
|
152
|
+
data.forEach((value, key) => {
|
|
153
|
+
const plutusMapValue = csl_1.csl.PlutusMapValues.new();
|
|
154
|
+
plutusMapValue.add((0, exports.toPlutusData)(value));
|
|
155
|
+
plutusMap.insert((0, exports.toPlutusData)(key), plutusMapValue);
|
|
156
|
+
});
|
|
157
|
+
return csl_1.csl.PlutusData.new_map(plutusMap);
|
|
158
|
+
}
|
|
159
|
+
return csl_1.csl.PlutusData.new_constr_plutus_data(csl_1.csl.ConstrPlutusData.new(csl_1.csl.BigNum.from_str(data.alternative.toString()), toPlutusList(data.fields)));
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
exports.toPlutusData = toPlutusData;
|
|
163
|
+
const castRawDataToJsonString = (rawData) => {
|
|
164
|
+
if (typeof rawData === "object") {
|
|
165
|
+
return json_bigint_1.default.stringify(rawData);
|
|
166
|
+
}
|
|
167
|
+
return rawData;
|
|
168
|
+
};
|
|
169
|
+
exports.castRawDataToJsonString = castRawDataToJsonString;
|
|
170
|
+
const castDataToPlutusData = ({ type, content, }) => {
|
|
171
|
+
if (type === "Mesh") {
|
|
172
|
+
return (0, exports.toPlutusData)(content);
|
|
173
|
+
}
|
|
174
|
+
if (type === "CBOR") {
|
|
175
|
+
return csl_1.csl.PlutusData.from_hex(content);
|
|
176
|
+
}
|
|
177
|
+
return csl_1.csl.PlutusData.from_json(content, csl_1.csl.PlutusDatumSchema.DetailedSchema);
|
|
178
|
+
};
|
|
179
|
+
exports.castDataToPlutusData = castDataToPlutusData;
|
|
180
|
+
const toNativeScript = (script) => {
|
|
181
|
+
const toNativeScripts = (scripts) => {
|
|
182
|
+
const nativeScripts = csl_1.csl.NativeScripts.new();
|
|
183
|
+
scripts.forEach((script) => {
|
|
184
|
+
nativeScripts.add((0, exports.toNativeScript)(script));
|
|
185
|
+
});
|
|
186
|
+
return nativeScripts;
|
|
187
|
+
};
|
|
188
|
+
switch (script.type) {
|
|
189
|
+
case "all":
|
|
190
|
+
return csl_1.csl.NativeScript.new_script_all(csl_1.csl.ScriptAll.new(toNativeScripts(script.scripts)));
|
|
191
|
+
case "any":
|
|
192
|
+
return csl_1.csl.NativeScript.new_script_any(csl_1.csl.ScriptAny.new(toNativeScripts(script.scripts)));
|
|
193
|
+
case "atLeast":
|
|
194
|
+
return csl_1.csl.NativeScript.new_script_n_of_k(csl_1.csl.ScriptNOfK.new(script.required, toNativeScripts(script.scripts)));
|
|
195
|
+
case "after":
|
|
196
|
+
return csl_1.csl.NativeScript.new_timelock_start(csl_1.csl.TimelockStart.new_timelockstart(csl_1.csl.BigNum.from_str(script.slot)));
|
|
197
|
+
case "before":
|
|
198
|
+
return csl_1.csl.NativeScript.new_timelock_expiry(csl_1.csl.TimelockExpiry.new_timelockexpiry(csl_1.csl.BigNum.from_str(script.slot)));
|
|
199
|
+
case "sig":
|
|
200
|
+
return csl_1.csl.NativeScript.new_script_pubkey(csl_1.csl.ScriptPubkey.new((0, deserializer_1.deserializeEd25519KeyHash)(script.keyHash)));
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
exports.toNativeScript = toNativeScript;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as csl from "@sidan-lab/sidan-csl-rs-nodejs";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.csl = void 0;
|
|
27
|
+
exports.csl = __importStar(require("@sidan-lab/sidan-csl-rs-nodejs"));
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { LanguageVersion } from "@meshsdk/common";
|
|
2
|
+
import { csl } from "./csl";
|
|
3
|
+
export declare const deserializeAddress: (address: string) => csl.Address;
|
|
4
|
+
export declare const deserializeBip32PrivateKey: (bip32PrivateKey: string) => csl.Bip32PrivateKey;
|
|
5
|
+
export declare const deserializeDataHash: (dataHash: string) => csl.DataHash;
|
|
6
|
+
export declare const deserializeEd25519KeyHash: (ed25519KeyHash: string) => csl.Ed25519KeyHash;
|
|
7
|
+
export declare const deserializeEd25519Signature: (ed25519Signature: string) => csl.Ed25519Signature;
|
|
8
|
+
export declare const deserializeNativeScript: (nativeScript: string) => csl.NativeScript;
|
|
9
|
+
export declare const deserializePublicKey: (publicKey: string) => csl.PublicKey;
|
|
10
|
+
export declare const deserializePlutusData: (plutusData: string) => csl.PlutusData;
|
|
11
|
+
export declare const deserializePlutusScript: (plutusScript: string, version: LanguageVersion) => csl.PlutusScript;
|
|
12
|
+
export declare const deserializeScriptRef: (scriptRef: string) => csl.ScriptRef;
|
|
13
|
+
export declare const deserializeScriptHash: (scriptHash: string) => csl.ScriptHash;
|
|
14
|
+
export declare const deserializeTx: (tx: string) => csl.Transaction;
|
|
15
|
+
export declare const deserializeTxBody: (txBody: string) => csl.TransactionBody;
|
|
16
|
+
export declare const deserializeTxHash: (txHash: string) => csl.TransactionHash;
|
|
17
|
+
export declare const deserializeTxUnspentOutput: (txUnspentOutput: string) => csl.TransactionUnspentOutput;
|
|
18
|
+
export declare const deserializeTxWitnessSet: (txWitnessSet: string) => csl.TransactionWitnessSet;
|
|
19
|
+
export declare const deserializeValue: (value: string) => csl.Value;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeValue = exports.deserializeTxWitnessSet = exports.deserializeTxUnspentOutput = exports.deserializeTxHash = exports.deserializeTxBody = exports.deserializeTx = exports.deserializeScriptHash = exports.deserializeScriptRef = exports.deserializePlutusScript = exports.deserializePlutusData = exports.deserializePublicKey = exports.deserializeNativeScript = exports.deserializeEd25519Signature = exports.deserializeEd25519KeyHash = exports.deserializeDataHash = exports.deserializeBip32PrivateKey = exports.deserializeAddress = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const converter_1 = require("./converter");
|
|
6
|
+
const csl_1 = require("./csl");
|
|
7
|
+
const deserializeAddress = (address) => csl_1.csl.Address.from_bytes((0, converter_1.toBytes)(address));
|
|
8
|
+
exports.deserializeAddress = deserializeAddress;
|
|
9
|
+
const deserializeBip32PrivateKey = (bip32PrivateKey) => csl_1.csl.Bip32PrivateKey.from_bytes((0, converter_1.toBytes)(bip32PrivateKey));
|
|
10
|
+
exports.deserializeBip32PrivateKey = deserializeBip32PrivateKey;
|
|
11
|
+
const deserializeDataHash = (dataHash) => csl_1.csl.DataHash.from_bytes((0, converter_1.toBytes)(dataHash));
|
|
12
|
+
exports.deserializeDataHash = deserializeDataHash;
|
|
13
|
+
const deserializeEd25519KeyHash = (ed25519KeyHash) => csl_1.csl.Ed25519KeyHash.from_bytes((0, converter_1.toBytes)(ed25519KeyHash));
|
|
14
|
+
exports.deserializeEd25519KeyHash = deserializeEd25519KeyHash;
|
|
15
|
+
const deserializeEd25519Signature = (ed25519Signature) => csl_1.csl.Ed25519Signature.from_bytes((0, converter_1.toBytes)(ed25519Signature));
|
|
16
|
+
exports.deserializeEd25519Signature = deserializeEd25519Signature;
|
|
17
|
+
const deserializeNativeScript = (nativeScript) => csl_1.csl.NativeScript.from_bytes((0, converter_1.toBytes)(nativeScript));
|
|
18
|
+
exports.deserializeNativeScript = deserializeNativeScript;
|
|
19
|
+
const deserializePublicKey = (publicKey) => csl_1.csl.PublicKey.from_bytes((0, converter_1.toBytes)(publicKey));
|
|
20
|
+
exports.deserializePublicKey = deserializePublicKey;
|
|
21
|
+
const deserializePlutusData = (plutusData) => csl_1.csl.PlutusData.from_bytes((0, converter_1.toBytes)(plutusData));
|
|
22
|
+
exports.deserializePlutusData = deserializePlutusData;
|
|
23
|
+
const deserializePlutusScript = (plutusScript, version) => csl_1.csl.PlutusScript.from_bytes_with_version((0, converter_1.toBytes)(plutusScript), constants_1.LANGUAGE_VERSIONS[version]);
|
|
24
|
+
exports.deserializePlutusScript = deserializePlutusScript;
|
|
25
|
+
const deserializeScriptRef = (scriptRef) => csl_1.csl.ScriptRef.from_bytes((0, converter_1.toBytes)(scriptRef));
|
|
26
|
+
exports.deserializeScriptRef = deserializeScriptRef;
|
|
27
|
+
const deserializeScriptHash = (scriptHash) => csl_1.csl.ScriptHash.from_bytes((0, converter_1.toBytes)(scriptHash));
|
|
28
|
+
exports.deserializeScriptHash = deserializeScriptHash;
|
|
29
|
+
const deserializeTx = (tx) => csl_1.csl.Transaction.from_bytes((0, converter_1.toBytes)(tx));
|
|
30
|
+
exports.deserializeTx = deserializeTx;
|
|
31
|
+
const deserializeTxBody = (txBody) => csl_1.csl.TransactionBody.from_bytes((0, converter_1.toBytes)(txBody));
|
|
32
|
+
exports.deserializeTxBody = deserializeTxBody;
|
|
33
|
+
const deserializeTxHash = (txHash) => csl_1.csl.TransactionHash.from_bytes((0, converter_1.toBytes)(txHash));
|
|
34
|
+
exports.deserializeTxHash = deserializeTxHash;
|
|
35
|
+
const deserializeTxUnspentOutput = (txUnspentOutput) => csl_1.csl.TransactionUnspentOutput.from_bytes((0, converter_1.toBytes)(txUnspentOutput));
|
|
36
|
+
exports.deserializeTxUnspentOutput = deserializeTxUnspentOutput;
|
|
37
|
+
const deserializeTxWitnessSet = (txWitnessSet) => csl_1.csl.TransactionWitnessSet.from_bytes((0, converter_1.toBytes)(txWitnessSet));
|
|
38
|
+
exports.deserializeTxWitnessSet = deserializeTxWitnessSet;
|
|
39
|
+
const deserializeValue = (value) => csl_1.csl.Value.from_bytes((0, converter_1.toBytes)(value));
|
|
40
|
+
exports.deserializeValue = deserializeValue;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./deserializer"), exports);
|
|
18
|
+
__exportStar(require("./converter"), exports);
|
|
19
|
+
__exportStar(require("./csl"), exports);
|
|
20
|
+
__exportStar(require("./constants"), exports);
|
|
21
|
+
__exportStar(require("./resolver"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Data, NativeScript, PlutusScript } from "@meshsdk/common";
|
|
2
|
+
export declare const resolveStakeKeyHash: (bech32: string) => string;
|
|
3
|
+
export declare const resolvePrivateKey: (words: string[]) => string;
|
|
4
|
+
export declare const resolveNativeScriptAddress: (script: NativeScript, networkId?: number) => string;
|
|
5
|
+
export declare const resolvePlutusScriptAddress: (script: PlutusScript, networkId?: number) => string;
|
|
6
|
+
export declare const resolveNativeScriptHash: (script: NativeScript) => string;
|
|
7
|
+
export declare const resolveRewardAddress: (bech32: string) => string;
|
|
8
|
+
export declare const resolveDataHash: (data: Data) => string;
|
|
9
|
+
export declare const resolveNativeScriptHex: (script: NativeScript) => string;
|
|
10
|
+
export declare const resolvePoolId: (hash: string) => string;
|
|
11
|
+
export declare const resolveScriptRef: (script: PlutusScript | NativeScript) => string;
|
|
12
|
+
export declare const resolveEd25519KeyHash: (bech32: string) => string;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveEd25519KeyHash = exports.resolveScriptRef = exports.resolvePoolId = exports.resolveNativeScriptHex = exports.resolveDataHash = exports.resolveRewardAddress = exports.resolveNativeScriptHash = exports.resolvePlutusScriptAddress = exports.resolveNativeScriptAddress = exports.resolvePrivateKey = exports.resolveStakeKeyHash = void 0;
|
|
4
|
+
const common_1 = require("@meshsdk/common");
|
|
5
|
+
const _1 = require(".");
|
|
6
|
+
const csl_1 = require("./csl");
|
|
7
|
+
const resolveStakeKeyHash = (bech32) => {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
try {
|
|
10
|
+
const stakeKeyHash = [
|
|
11
|
+
(_a = (0, _1.toBaseAddress)(bech32)) === null || _a === void 0 ? void 0 : _a.stake_cred().to_keyhash(),
|
|
12
|
+
(_b = (0, _1.toRewardAddress)(bech32)) === null || _b === void 0 ? void 0 : _b.payment_cred().to_keyhash(),
|
|
13
|
+
].find((kh) => kh !== undefined);
|
|
14
|
+
if (stakeKeyHash !== undefined)
|
|
15
|
+
return stakeKeyHash.to_hex();
|
|
16
|
+
throw new Error(`Couldn't resolve stake key hash from address: ${bech32}`);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
throw new Error(`An error occurred during resolveStakeKeyHash: ${error}.`);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
exports.resolveStakeKeyHash = resolveStakeKeyHash;
|
|
23
|
+
const resolvePrivateKey = (words) => {
|
|
24
|
+
const buildBip32PrivateKey = (entropy, password = "") => {
|
|
25
|
+
return csl_1.csl.Bip32PrivateKey.from_bip39_entropy((0, _1.toBytes)(entropy), (0, _1.toBytes)((0, _1.fromUTF8)(password)));
|
|
26
|
+
};
|
|
27
|
+
const entropy = (0, common_1.mnemonicToEntropy)(words.join(" "));
|
|
28
|
+
const bip32PrivateKey = buildBip32PrivateKey(entropy);
|
|
29
|
+
const bech32PrivateKey = bip32PrivateKey.to_bech32();
|
|
30
|
+
bip32PrivateKey.free();
|
|
31
|
+
return bech32PrivateKey;
|
|
32
|
+
};
|
|
33
|
+
exports.resolvePrivateKey = resolvePrivateKey;
|
|
34
|
+
const resolveNativeScriptAddress = (script, networkId = 0) => {
|
|
35
|
+
const nativeScript = (0, _1.toNativeScript)(script);
|
|
36
|
+
const enterpriseAddress = csl_1.csl.EnterpriseAddress.new(networkId, csl_1.csl.Credential.from_scripthash(nativeScript.hash()));
|
|
37
|
+
return enterpriseAddress.to_address().to_bech32();
|
|
38
|
+
};
|
|
39
|
+
exports.resolveNativeScriptAddress = resolveNativeScriptAddress;
|
|
40
|
+
const resolvePlutusScriptAddress = (script, networkId = 0) => {
|
|
41
|
+
const plutusScript = (0, _1.deserializePlutusScript)(script.code, script.version);
|
|
42
|
+
const enterpriseAddress = csl_1.csl.EnterpriseAddress.new(networkId, csl_1.csl.Credential.from_scripthash(plutusScript.hash()));
|
|
43
|
+
return enterpriseAddress.to_address().to_bech32();
|
|
44
|
+
};
|
|
45
|
+
exports.resolvePlutusScriptAddress = resolvePlutusScriptAddress;
|
|
46
|
+
const resolveNativeScriptHash = (script) => {
|
|
47
|
+
return (0, _1.toNativeScript)(script).hash().to_hex();
|
|
48
|
+
};
|
|
49
|
+
exports.resolveNativeScriptHash = resolveNativeScriptHash;
|
|
50
|
+
const resolveRewardAddress = (bech32) => {
|
|
51
|
+
const buildRewardAddress = (networkId, stakeKeyHash) => {
|
|
52
|
+
return csl_1.csl.RewardAddress.new(networkId, csl_1.csl.Credential.from_keyhash(stakeKeyHash));
|
|
53
|
+
};
|
|
54
|
+
try {
|
|
55
|
+
const address = (0, _1.toAddress)(bech32);
|
|
56
|
+
const baseAddress = (0, _1.toBaseAddress)(bech32);
|
|
57
|
+
const stakeKeyHash = baseAddress === null || baseAddress === void 0 ? void 0 : baseAddress.stake_cred().to_keyhash();
|
|
58
|
+
if (stakeKeyHash !== undefined)
|
|
59
|
+
return buildRewardAddress(address.network_id(), stakeKeyHash)
|
|
60
|
+
.to_address()
|
|
61
|
+
.to_bech32();
|
|
62
|
+
throw new Error(`Couldn't resolve reward address from address: ${bech32}`);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
throw new Error(`An error occurred during resolveRewardAddress: ${error}.`);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
exports.resolveRewardAddress = resolveRewardAddress;
|
|
69
|
+
const resolveDataHash = (data) => {
|
|
70
|
+
const plutusData = (0, _1.toPlutusData)(data);
|
|
71
|
+
const dataHash = csl_1.csl.hash_plutus_data(plutusData);
|
|
72
|
+
return dataHash.to_hex();
|
|
73
|
+
};
|
|
74
|
+
exports.resolveDataHash = resolveDataHash;
|
|
75
|
+
const resolveNativeScriptHex = (script) => {
|
|
76
|
+
return (0, _1.toNativeScript)(script).to_hex();
|
|
77
|
+
};
|
|
78
|
+
exports.resolveNativeScriptHex = resolveNativeScriptHex;
|
|
79
|
+
const resolvePoolId = (hash) => {
|
|
80
|
+
return csl_1.csl.Ed25519KeyHash.from_hex(hash).to_bech32("pool1");
|
|
81
|
+
};
|
|
82
|
+
exports.resolvePoolId = resolvePoolId;
|
|
83
|
+
const resolveScriptRef = (script) => {
|
|
84
|
+
return (0, _1.toScriptRef)(script).to_hex();
|
|
85
|
+
};
|
|
86
|
+
exports.resolveScriptRef = resolveScriptRef;
|
|
87
|
+
const resolveEd25519KeyHash = (bech32) => {
|
|
88
|
+
return csl_1.csl.Ed25519KeyHash.from_bech32(bech32).to_hex();
|
|
89
|
+
};
|
|
90
|
+
exports.resolveEd25519KeyHash = resolveEd25519KeyHash;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./utils"), exports);
|
|
18
|
+
__exportStar(require("./core"), exports);
|
|
19
|
+
__exportStar(require("./deser"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DeserializedAddress, PubKeyAddress, ScriptAddress } from "@meshsdk/common";
|
|
2
|
+
export declare const serialzeAddress: (deserializedAddress: Partial<DeserializedAddress>, networkId?: number) => string;
|
|
3
|
+
export declare const addrBech32ToHex: (bech32: string) => string;
|
|
4
|
+
export declare const addrBech32ToObj: <T>(bech32: string) => T;
|
|
5
|
+
export declare const serializeAddressObj: (plutusDataAddressObject: PubKeyAddress | ScriptAddress, networkId?: number) => string;
|
|
6
|
+
export declare const serializePlutusAddressToBech32: (plutusHex: string, networkId?: number) => string;
|
|
7
|
+
export declare const deserializeBech32Address: (bech32Addr: string) => DeserializedAddress;
|
|
8
|
+
export declare const scriptHashToBech32: (scriptHash: string, stakeCredentialHash?: string, networkId?: number, isScriptStakeCredentialHash?: boolean) => string;
|
|
9
|
+
export declare const v2ScriptToBech32: (scriptCbor: string, stakeCredential?: string, networkId?: number, isScriptStakeCredential?: boolean) => string;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.v2ScriptToBech32 = exports.scriptHashToBech32 = exports.deserializeBech32Address = exports.serializePlutusAddressToBech32 = exports.serializeAddressObj = exports.addrBech32ToObj = exports.addrBech32ToHex = exports.serialzeAddress = void 0;
|
|
4
|
+
const common_1 = require("@meshsdk/common");
|
|
5
|
+
const deser_1 = require("../deser");
|
|
6
|
+
const scripts_1 = require("./scripts");
|
|
7
|
+
const serialzeAddress = (deserializedAddress, networkId = 0) => {
|
|
8
|
+
const { pubKeyHash, scriptHash, stakeCredentialHash, stakeScriptCredentialHash, } = deserializedAddress;
|
|
9
|
+
const isPaymentScript = !pubKeyHash;
|
|
10
|
+
const isStakeScript = !stakeCredentialHash;
|
|
11
|
+
const paymentHash = isPaymentScript ? scriptHash : pubKeyHash;
|
|
12
|
+
const stakeHash = isStakeScript
|
|
13
|
+
? stakeScriptCredentialHash
|
|
14
|
+
: stakeCredentialHash;
|
|
15
|
+
if (!paymentHash)
|
|
16
|
+
throw new Error("Error: serializeAddress: Address must contain a payment part");
|
|
17
|
+
const addressObj = isPaymentScript
|
|
18
|
+
? (0, common_1.pubKeyAddress)(paymentHash, stakeHash, isStakeScript)
|
|
19
|
+
: (0, common_1.scriptAddress)(paymentHash, stakeHash, isStakeScript);
|
|
20
|
+
return (0, exports.serializeAddressObj)(addressObj, networkId);
|
|
21
|
+
};
|
|
22
|
+
exports.serialzeAddress = serialzeAddress;
|
|
23
|
+
const addrBech32ToHex = (bech32) => {
|
|
24
|
+
const hexAddress = deser_1.csl.Address.from_bech32(bech32).to_hex();
|
|
25
|
+
const cslAddress = deser_1.csl.Address.from_hex(hexAddress);
|
|
26
|
+
const hex = deser_1.csl.PlutusData.from_address(cslAddress).to_hex();
|
|
27
|
+
return hex;
|
|
28
|
+
};
|
|
29
|
+
exports.addrBech32ToHex = addrBech32ToHex;
|
|
30
|
+
const addrBech32ToObj = (bech32) => {
|
|
31
|
+
const hexAddress = deser_1.csl.Address.from_bech32(bech32).to_hex();
|
|
32
|
+
const cslAddress = deser_1.csl.Address.from_hex(hexAddress);
|
|
33
|
+
const json = JSON.parse(deser_1.csl.PlutusData.from_address(cslAddress).to_json(1));
|
|
34
|
+
return json;
|
|
35
|
+
};
|
|
36
|
+
exports.addrBech32ToObj = addrBech32ToObj;
|
|
37
|
+
const serializeAddressObj = (plutusDataAddressObject, networkId = 0) => {
|
|
38
|
+
const bech32Addr = deser_1.csl.parse_plutus_address_obj_to_bech32(JSON.stringify(plutusDataAddressObject), networkId);
|
|
39
|
+
return bech32Addr;
|
|
40
|
+
};
|
|
41
|
+
exports.serializeAddressObj = serializeAddressObj;
|
|
42
|
+
const serializePlutusAddressToBech32 = (plutusHex, networkId = 0) => {
|
|
43
|
+
const cslPlutusDataAddress = deser_1.csl.PlutusData.from_hex(plutusHex);
|
|
44
|
+
const plutusDataAddressObject = JSON.parse(cslPlutusDataAddress.to_json(deser_1.csl.PlutusDatumSchema.DetailedSchema));
|
|
45
|
+
return (0, exports.serializeAddressObj)(plutusDataAddressObject, networkId);
|
|
46
|
+
};
|
|
47
|
+
exports.serializePlutusAddressToBech32 = serializePlutusAddressToBech32;
|
|
48
|
+
const deserializeBech32Address = (bech32Addr) => {
|
|
49
|
+
const serializedAddress = deser_1.csl.serialize_bech32_address(bech32Addr);
|
|
50
|
+
return {
|
|
51
|
+
pubKeyHash: serializedAddress.get_pub_key_hash(),
|
|
52
|
+
scriptHash: serializedAddress.get_script_hash(),
|
|
53
|
+
stakeCredentialHash: serializedAddress.get_stake_key_hash(),
|
|
54
|
+
stakeScriptCredentialHash: serializedAddress.get_stake_key_script_hash(),
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
exports.deserializeBech32Address = deserializeBech32Address;
|
|
58
|
+
const scriptHashToBech32 = (scriptHash, stakeCredentialHash, networkId = 0, isScriptStakeCredentialHash = false) => deser_1.csl.wasm_script_to_address(networkId, scriptHash, stakeCredentialHash, isScriptStakeCredentialHash);
|
|
59
|
+
exports.scriptHashToBech32 = scriptHashToBech32;
|
|
60
|
+
const v2ScriptToBech32 = (scriptCbor, stakeCredential, networkId = 0, isScriptStakeCredential = false) => (0, exports.scriptHashToBech32)((0, scripts_1.getV2ScriptHash)(scriptCbor), stakeCredential, networkId, isScriptStakeCredential);
|
|
61
|
+
exports.v2ScriptToBech32 = v2ScriptToBech32;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Data } from "@meshsdk/common";
|
|
2
|
+
/**
|
|
3
|
+
* Apply parameters to a given script blueprint.
|
|
4
|
+
*
|
|
5
|
+
* @param rawScript - The raw script CborHex from blueprint.
|
|
6
|
+
* @param params - The parameters to apply, in an array.
|
|
7
|
+
* @param type - The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
|
|
8
|
+
* @returns The double-cbor encoded script CborHex with the parameters applied.
|
|
9
|
+
*/
|
|
10
|
+
export declare const applyParamsToScript: (rawScript: string, params: object[] | Data[], type?: "Mesh" | "JSON" | "CBOR") => string;
|
|
11
|
+
/**
|
|
12
|
+
* Apply Cbor encoding.
|
|
13
|
+
*
|
|
14
|
+
* @param rawScript - The raw script CborHex from blueprint.
|
|
15
|
+
* @returns The double-cbor encoded script CborHex.
|
|
16
|
+
*/
|
|
17
|
+
export declare const applyCborEncoding: (rawScript: string) => string;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyCborEncoding = exports.applyParamsToScript = void 0;
|
|
4
|
+
const deser_1 = require("../deser");
|
|
5
|
+
/**
|
|
6
|
+
* Apply parameters to a given script blueprint.
|
|
7
|
+
*
|
|
8
|
+
* @param rawScript - The raw script CborHex from blueprint.
|
|
9
|
+
* @param params - The parameters to apply, in an array.
|
|
10
|
+
* @param type - The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR.
|
|
11
|
+
* @returns The double-cbor encoded script CborHex with the parameters applied.
|
|
12
|
+
*/
|
|
13
|
+
const applyParamsToScript = (rawScript, params, type = "Mesh") => {
|
|
14
|
+
const cslParams = deser_1.csl.JsVecString.new();
|
|
15
|
+
let paramType = deser_1.csl.BuilderDataType.CBOR;
|
|
16
|
+
switch (type) {
|
|
17
|
+
case "JSON":
|
|
18
|
+
paramType = deser_1.csl.BuilderDataType.JSON;
|
|
19
|
+
params.forEach((param) => {
|
|
20
|
+
if (typeof param === "object") {
|
|
21
|
+
cslParams.add(JSON.stringify(param));
|
|
22
|
+
}
|
|
23
|
+
else if (typeof param === "string") {
|
|
24
|
+
cslParams.add(param);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
break;
|
|
28
|
+
case "Mesh":
|
|
29
|
+
params.forEach((param) => {
|
|
30
|
+
const paramCbor = (0, deser_1.toPlutusData)(param);
|
|
31
|
+
cslParams.add(paramCbor.to_hex());
|
|
32
|
+
});
|
|
33
|
+
break;
|
|
34
|
+
default:
|
|
35
|
+
params.forEach((param) => {
|
|
36
|
+
cslParams.add(param);
|
|
37
|
+
});
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
return deser_1.csl.apply_params_to_script(rawScript, cslParams, paramType);
|
|
41
|
+
};
|
|
42
|
+
exports.applyParamsToScript = applyParamsToScript;
|
|
43
|
+
/**
|
|
44
|
+
* Apply Cbor encoding.
|
|
45
|
+
*
|
|
46
|
+
* @param rawScript - The raw script CborHex from blueprint.
|
|
47
|
+
* @returns The double-cbor encoded script CborHex.
|
|
48
|
+
*/
|
|
49
|
+
const applyCborEncoding = (rawScript) => {
|
|
50
|
+
return deser_1.csl.apply_params_to_script(rawScript, deser_1.csl.JsVecString.new(), deser_1.csl.BuilderDataType.CBOR);
|
|
51
|
+
};
|
|
52
|
+
exports.applyCborEncoding = applyCborEncoding;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const skeyToPubKeyHash: (skeyHex: string) => string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.skeyToPubKeyHash = void 0;
|
|
4
|
+
const deser_1 = require("../deser");
|
|
5
|
+
const skeyToPubKeyHash = (skeyHex) => {
|
|
6
|
+
const isHexUnclean = skeyHex.slice(0, 4) === "5820" && skeyHex.length === 68;
|
|
7
|
+
const cleanHex = isHexUnclean ? skeyHex.slice(4) : skeyHex;
|
|
8
|
+
return deser_1.csl.PrivateKey.from_hex(cleanHex).to_public().hash().to_hex();
|
|
9
|
+
};
|
|
10
|
+
exports.skeyToPubKeyHash = skeyToPubKeyHash;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseDatumCbor = exports.parseInlineDatum = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
|
+
const deser_1 = require("../deser");
|
|
6
|
+
const parseInlineDatum = (utxo) => {
|
|
7
|
+
const datumCbor = utxo.inline_datum || "";
|
|
8
|
+
const parsedDatum = deser_1.csl.PlutusData.from_hex(datumCbor);
|
|
9
|
+
const datum = JSON.parse(parsedDatum.to_json(1));
|
|
10
|
+
return datum;
|
|
11
|
+
};
|
|
12
|
+
exports.parseInlineDatum = parseInlineDatum;
|
|
13
|
+
const parseDatumCbor = (datumCbor) => {
|
|
14
|
+
const parsedDatum = deser_1.csl.PlutusData.from_hex(datumCbor);
|
|
15
|
+
const datum = JSON.parse(parsedDatum.to_json(1));
|
|
16
|
+
return datum;
|
|
17
|
+
};
|
|
18
|
+
exports.parseDatumCbor = parseDatumCbor;
|