@meshsdk/core-csl 1.6.0-alpha.1
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 +9 -0
- package/dist/cjs/core/builder.d.ts +38 -0
- package/dist/cjs/core/builder.js +389 -0
- package/dist/cjs/core/index.d.ts +1 -0
- package/dist/cjs/core/index.js +17 -0
- package/dist/cjs/deser/builder.d.ts +18 -0
- package/dist/cjs/deser/builder.js +130 -0
- package/dist/cjs/deser/constants.d.ts +12 -0
- package/dist/cjs/deser/constants.js +15 -0
- package/dist/cjs/deser/converter.d.ts +27 -0
- package/dist/cjs/deser/converter.js +352 -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 +6 -0
- package/dist/cjs/deser/index.js +22 -0
- package/dist/cjs/deser/types.d.ts +146 -0
- package/dist/cjs/deser/types.js +2 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/utils/address.d.ts +12 -0
- package/dist/cjs/utils/address.js +60 -0
- package/dist/cjs/utils/aiken.d.ts +2 -0
- package/dist/cjs/utils/aiken.js +20 -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 +3 -0
- package/dist/cjs/utils/staking.js +25 -0
- package/dist/cjs/utils/transaction.d.ts +2 -0
- package/dist/cjs/utils/transaction.js +15 -0
- package/dist/mjs/core/builder.d.ts +38 -0
- package/dist/mjs/core/builder.js +380 -0
- package/dist/mjs/core/index.d.ts +1 -0
- package/dist/mjs/core/index.js +1 -0
- package/dist/mjs/deser/builder.d.ts +18 -0
- package/dist/mjs/deser/builder.js +118 -0
- package/dist/mjs/deser/constants.d.ts +12 -0
- package/dist/mjs/deser/constants.js +12 -0
- package/dist/mjs/deser/converter.d.ts +27 -0
- package/dist/mjs/deser/converter.js +321 -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 +6 -0
- package/dist/mjs/deser/index.js +6 -0
- package/dist/mjs/deser/types.d.ts +146 -0
- package/dist/mjs/deser/types.js +1 -0
- package/dist/mjs/index.d.ts +3 -0
- package/dist/mjs/index.js +3 -0
- package/dist/mjs/utils/address.d.ts +12 -0
- package/dist/mjs/utils/address.js +50 -0
- package/dist/mjs/utils/aiken.d.ts +2 -0
- package/dist/mjs/utils/aiken.js +15 -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 +3 -0
- package/dist/mjs/utils/staking.js +18 -0
- package/dist/mjs/utils/transaction.d.ts +2 -0
- package/dist/mjs/utils/transaction.js +10 -0
- package/package.json +53 -0
|
@@ -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("./deser"), exports);
|
|
18
|
+
__exportStar(require("./utils"), exports);
|
|
19
|
+
__exportStar(require("./core"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PubKeyAddress, ScriptAddress } from '@meshsdk/core';
|
|
2
|
+
export declare const addrBech32ToHex: (bech32: string) => string;
|
|
3
|
+
export declare const addrBech32ToObj: <T>(bech32: string) => T;
|
|
4
|
+
export declare const parsePlutusAddressObjToBech32: (plutusDataAddressObject: PubKeyAddress | ScriptAddress, networkId?: number) => string;
|
|
5
|
+
export declare const parsePlutusAddressToBech32: (plutusHex: string, networkId?: number) => string;
|
|
6
|
+
export declare const serializeBech32Address: (bech32Addr: string) => {
|
|
7
|
+
pubKeyHash: string;
|
|
8
|
+
scriptHash: string;
|
|
9
|
+
stakeCredential: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const scriptHashToBech32: (scriptHash: string, stakeCredential?: string, networkId?: number) => string;
|
|
12
|
+
export declare const v2ScriptToBech32: (scriptCbor: string, stakeCredential?: string, networkId?: number) => string;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.v2ScriptToBech32 = exports.scriptHashToBech32 = exports.serializeBech32Address = exports.parsePlutusAddressToBech32 = exports.parsePlutusAddressObjToBech32 = exports.addrBech32ToObj = exports.addrBech32ToHex = void 0;
|
|
4
|
+
const deser_1 = require("../deser");
|
|
5
|
+
const scripts_1 = require("./scripts");
|
|
6
|
+
const addrBech32ToHex = (bech32) => {
|
|
7
|
+
const hexAddress = deser_1.csl.Address.from_bech32(bech32).to_hex();
|
|
8
|
+
const cslAddress = deser_1.csl.Address.from_hex(hexAddress);
|
|
9
|
+
const hex = deser_1.csl.PlutusData.from_address(cslAddress).to_hex();
|
|
10
|
+
return hex;
|
|
11
|
+
};
|
|
12
|
+
exports.addrBech32ToHex = addrBech32ToHex;
|
|
13
|
+
const addrBech32ToObj = (bech32) => {
|
|
14
|
+
const hexAddress = deser_1.csl.Address.from_bech32(bech32).to_hex();
|
|
15
|
+
const cslAddress = deser_1.csl.Address.from_hex(hexAddress);
|
|
16
|
+
const json = JSON.parse(deser_1.csl.PlutusData.from_address(cslAddress).to_json(1));
|
|
17
|
+
return json;
|
|
18
|
+
};
|
|
19
|
+
exports.addrBech32ToObj = addrBech32ToObj;
|
|
20
|
+
const parsePlutusAddressObjToBech32 = (plutusDataAddressObject, networkId = 0) => {
|
|
21
|
+
const plutusDataPaymentKeyObject = plutusDataAddressObject.fields[0];
|
|
22
|
+
const plutusDataStakeKeyObject = plutusDataAddressObject.fields[1];
|
|
23
|
+
const cslPaymentKeyHash = plutusDataPaymentKeyObject.fields[0].bytes;
|
|
24
|
+
// Take into account whether the hash is a PubKeyHash or ScriptHash
|
|
25
|
+
const cslPaymentCredential = plutusDataPaymentKeyObject.constructor === 0
|
|
26
|
+
? deser_1.csl.StakeCredential.from_keyhash(deser_1.csl.Ed25519KeyHash.from_hex(cslPaymentKeyHash))
|
|
27
|
+
: deser_1.csl.StakeCredential.from_scripthash(deser_1.csl.ScriptHash.from_hex(cslPaymentKeyHash));
|
|
28
|
+
let bech32Addr = '';
|
|
29
|
+
// Parsing address according to whether it has a stake key
|
|
30
|
+
if (plutusDataStakeKeyObject.constructor === 0) {
|
|
31
|
+
const cslStakeKeyHash = deser_1.csl.Ed25519KeyHash.from_hex(plutusDataStakeKeyObject.fields[0].fields[0].fields[0].bytes);
|
|
32
|
+
const cslBaseAddress = deser_1.csl.BaseAddress.new(networkId, cslPaymentCredential, deser_1.csl.StakeCredential.from_keyhash(cslStakeKeyHash));
|
|
33
|
+
bech32Addr = cslBaseAddress.to_address().to_bech32();
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
const cslEnterpriseAddress = deser_1.csl.EnterpriseAddress.new(networkId, cslPaymentCredential);
|
|
37
|
+
bech32Addr = cslEnterpriseAddress.to_address().to_bech32();
|
|
38
|
+
}
|
|
39
|
+
return bech32Addr;
|
|
40
|
+
};
|
|
41
|
+
exports.parsePlutusAddressObjToBech32 = parsePlutusAddressObjToBech32;
|
|
42
|
+
const parsePlutusAddressToBech32 = (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.parsePlutusAddressObjToBech32)(plutusDataAddressObject, networkId);
|
|
46
|
+
};
|
|
47
|
+
exports.parsePlutusAddressToBech32 = parsePlutusAddressToBech32;
|
|
48
|
+
const serializeBech32Address = (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
|
+
stakeCredential: serializedAddress.get_stake_key_hash(),
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
exports.serializeBech32Address = serializeBech32Address;
|
|
57
|
+
const scriptHashToBech32 = (scriptHash, stakeCredential, networkId = 0) => deser_1.csl.script_to_address(networkId, scriptHash, stakeCredential);
|
|
58
|
+
exports.scriptHashToBech32 = scriptHashToBech32;
|
|
59
|
+
const v2ScriptToBech32 = (scriptCbor, stakeCredential, networkId = 0) => (0, exports.scriptHashToBech32)((0, scripts_1.getV2ScriptHash)(scriptCbor), stakeCredential, networkId);
|
|
60
|
+
exports.v2ScriptToBech32 = v2ScriptToBech32;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyObjParamsToScript = exports.applyParamsToScript = void 0;
|
|
4
|
+
const deser_1 = require("../deser");
|
|
5
|
+
const applyParamsToScript = (rawAikenScriptBlueprint, params) => {
|
|
6
|
+
const cslParams = deser_1.csl.JsVecString.new();
|
|
7
|
+
params.forEach((param) => {
|
|
8
|
+
cslParams.add(param);
|
|
9
|
+
});
|
|
10
|
+
return deser_1.csl.apply_params_to_script(cslParams, rawAikenScriptBlueprint);
|
|
11
|
+
};
|
|
12
|
+
exports.applyParamsToScript = applyParamsToScript;
|
|
13
|
+
const applyObjParamsToScript = (rawAikenScriptBlueprint, params) => {
|
|
14
|
+
const cslParams = deser_1.csl.JsVecString.new();
|
|
15
|
+
params.forEach((param) => {
|
|
16
|
+
cslParams.add(JSON.stringify(param));
|
|
17
|
+
});
|
|
18
|
+
return deser_1.csl.apply_params_to_script(cslParams, rawAikenScriptBlueprint);
|
|
19
|
+
};
|
|
20
|
+
exports.applyObjParamsToScript = applyObjParamsToScript;
|
|
@@ -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;
|
|
@@ -0,0 +1,23 @@
|
|
|
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("./address"), exports);
|
|
18
|
+
__exportStar(require("./datum"), exports);
|
|
19
|
+
__exportStar(require("./scripts"), exports);
|
|
20
|
+
__exportStar(require("./credentials"), exports);
|
|
21
|
+
__exportStar(require("./staking"), exports);
|
|
22
|
+
__exportStar(require("./transaction"), exports);
|
|
23
|
+
__exportStar(require("./aiken"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getV2ScriptHash: (script: string) => string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getV2ScriptHash = void 0;
|
|
4
|
+
const deser_1 = require("../deser");
|
|
5
|
+
const getV2ScriptHash = (script) => deser_1.csl.get_v2_script_hash(script);
|
|
6
|
+
exports.getV2ScriptHash = getV2ScriptHash;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.baseAddressToStakeAddress = exports.poolIdBech32ToHex = exports.poolIdHexToBech32 = void 0;
|
|
4
|
+
const deser_1 = require("../deser");
|
|
5
|
+
const poolIdHexToBech32 = (poolIdHash) => {
|
|
6
|
+
const cslPoolIdHash = deser_1.csl.Ed25519KeyHash.from_hex(poolIdHash);
|
|
7
|
+
return cslPoolIdHash.to_bech32('pool');
|
|
8
|
+
};
|
|
9
|
+
exports.poolIdHexToBech32 = poolIdHexToBech32;
|
|
10
|
+
const poolIdBech32ToHex = (poolIdBech32) => {
|
|
11
|
+
const cslPoolIdHash = deser_1.csl.Ed25519KeyHash.from_bech32(poolIdBech32);
|
|
12
|
+
return Buffer.from(cslPoolIdHash.to_bytes()).toString('hex');
|
|
13
|
+
};
|
|
14
|
+
exports.poolIdBech32ToHex = poolIdBech32ToHex;
|
|
15
|
+
const baseAddressToStakeAddress = (baseAddressBech32, network = 1) => {
|
|
16
|
+
var _a;
|
|
17
|
+
const networkId = network === 1 ? deser_1.csl.NetworkId.mainnet().kind() : deser_1.csl.NetworkId.testnet().kind();
|
|
18
|
+
const stakeCred = (_a = deser_1.csl.BaseAddress.from_address(deser_1.csl.Address.from_bech32(baseAddressBech32))) === null || _a === void 0 ? void 0 : _a.stake_cred();
|
|
19
|
+
if (stakeCred) {
|
|
20
|
+
const stakeAddress = deser_1.csl.RewardAddress.new(networkId, stakeCred).to_address().to_bech32();
|
|
21
|
+
return stakeAddress;
|
|
22
|
+
}
|
|
23
|
+
return '';
|
|
24
|
+
};
|
|
25
|
+
exports.baseAddressToStakeAddress = baseAddressToStakeAddress;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.signTransaction = exports.calculateTxHash = void 0;
|
|
4
|
+
const deser_1 = require("../deser");
|
|
5
|
+
const calculateTxHash = (txHex) => deser_1.csl.calculate_tx_hash(txHex);
|
|
6
|
+
exports.calculateTxHash = calculateTxHash;
|
|
7
|
+
const signTransaction = (txHex, signingKeys) => {
|
|
8
|
+
const cslSigningKeys = deser_1.csl.JsVecString.new();
|
|
9
|
+
signingKeys.forEach((key) => {
|
|
10
|
+
cslSigningKeys.add(key);
|
|
11
|
+
});
|
|
12
|
+
const signedTx = deser_1.csl.sign_transaction(txHex, cslSigningKeys);
|
|
13
|
+
return signedTx;
|
|
14
|
+
};
|
|
15
|
+
exports.signTransaction = signTransaction;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { BuilderData, Certificate, MeshTxBuilderBody, MintItem, Protocol, IMeshSerializer } from '@meshsdk/core';
|
|
2
|
+
import { TransactionBuilder, csl } from '../deser';
|
|
3
|
+
export declare const emptyTxBuilderBody: () => MeshTxBuilderBody;
|
|
4
|
+
export declare class CSLSerializer implements IMeshSerializer {
|
|
5
|
+
txBuilder: TransactionBuilder;
|
|
6
|
+
protocolParams: Protocol;
|
|
7
|
+
meshTxBuilderBody: MeshTxBuilderBody;
|
|
8
|
+
constructor(protocolParams?: Protocol);
|
|
9
|
+
serializeTxBody(txBody: MeshTxBuilderBody, protocolParams?: Protocol): string;
|
|
10
|
+
addSigningKeys(txHex: string, signingKeys: string[]): string;
|
|
11
|
+
private addUtxosFrom;
|
|
12
|
+
private makePlutusScriptSource;
|
|
13
|
+
protected removeDuplicateInputs: () => void;
|
|
14
|
+
private addAllInputs;
|
|
15
|
+
private addTxIn;
|
|
16
|
+
private addScriptTxIn;
|
|
17
|
+
private addAllOutputs;
|
|
18
|
+
private addOutput;
|
|
19
|
+
private addAllCollaterals;
|
|
20
|
+
private addCollateral;
|
|
21
|
+
private addCollateralReturn;
|
|
22
|
+
private addAllReferenceInputs;
|
|
23
|
+
private addReferenceInput;
|
|
24
|
+
protected addAllMints: (mints: MintItem[]) => void;
|
|
25
|
+
private addPlutusMint;
|
|
26
|
+
private addNativeMint;
|
|
27
|
+
private decimalToFraction;
|
|
28
|
+
private toPoolParams;
|
|
29
|
+
private addCertificate;
|
|
30
|
+
protected addAllCertificates: (allCertificates: Certificate[]) => void;
|
|
31
|
+
protected addCostModels: () => void;
|
|
32
|
+
private addChange;
|
|
33
|
+
private addValidityRange;
|
|
34
|
+
private addAllRequiredSignatures;
|
|
35
|
+
private addAllMetadata;
|
|
36
|
+
protected castRawDataToJsonString: (rawData: object | string) => string;
|
|
37
|
+
protected castDataToPlutusData: ({ type, content }: BuilderData) => csl.PlutusData;
|
|
38
|
+
}
|