@meshsdk/common 1.9.0-beta.23 → 1.9.0-beta.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +52 -6
- package/dist/index.d.cts +51 -2
- package/dist/index.d.ts +51 -2
- package/dist/index.js +50 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -81,6 +81,7 @@ __export(index_exports, {
|
|
|
81
81
|
hexToString: () => hexToString,
|
|
82
82
|
integer: () => integer,
|
|
83
83
|
isNetwork: () => isNetwork,
|
|
84
|
+
jsonProofToPlutusData: () => jsonProofToPlutusData,
|
|
84
85
|
keepRelevant: () => keepRelevant,
|
|
85
86
|
largestFirst: () => largestFirst,
|
|
86
87
|
largestFirstMultiAsset: () => largestFirstMultiAsset,
|
|
@@ -113,6 +114,7 @@ __export(index_exports, {
|
|
|
113
114
|
none: () => none,
|
|
114
115
|
option: () => option,
|
|
115
116
|
outputReference: () => outputReference,
|
|
117
|
+
pairs: () => pairs,
|
|
116
118
|
parseAssetUnit: () => parseAssetUnit,
|
|
117
119
|
plutusBSArrayToString: () => plutusBSArrayToString,
|
|
118
120
|
policyId: () => policyId,
|
|
@@ -1197,6 +1199,18 @@ var assocMap = (mapItems, validation = true) => ({
|
|
|
1197
1199
|
return { k, v };
|
|
1198
1200
|
})
|
|
1199
1201
|
});
|
|
1202
|
+
var pairs = (mapItems, validation = true) => ({
|
|
1203
|
+
map: mapItems.map(([k, v]) => {
|
|
1204
|
+
if (validation) {
|
|
1205
|
+
if (typeof k !== "object" || typeof v !== "object") {
|
|
1206
|
+
throw new Error(
|
|
1207
|
+
`Map item of JSON Cardano data type must be an object - ${k}, ${v}`
|
|
1208
|
+
);
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
return { k, v };
|
|
1212
|
+
})
|
|
1213
|
+
});
|
|
1200
1214
|
|
|
1201
1215
|
// src/data/json/aliases.ts
|
|
1202
1216
|
var hashByteString = (bytes) => {
|
|
@@ -1276,6 +1290,36 @@ var scriptAddress = (bytes, stakeCredential, isStakeScriptCredential = false) =>
|
|
|
1276
1290
|
]);
|
|
1277
1291
|
var credential = (hash, isScriptCredential = false) => isScriptCredential ? conStr1([scriptHash(hash)]) : conStr0([pubKeyHash(hash)]);
|
|
1278
1292
|
|
|
1293
|
+
// src/data/json/mpf.ts
|
|
1294
|
+
var jsonProofToPlutusData = (proof) => {
|
|
1295
|
+
const proofSteps = [];
|
|
1296
|
+
const proofJson = proof;
|
|
1297
|
+
proofJson.forEach((proof2) => {
|
|
1298
|
+
const skip = integer(proof2.skip);
|
|
1299
|
+
switch (proof2.type) {
|
|
1300
|
+
case "branch":
|
|
1301
|
+
proofSteps.push(
|
|
1302
|
+
conStr0([skip, byteString(proof2.neighbors.toString("hex"))])
|
|
1303
|
+
);
|
|
1304
|
+
break;
|
|
1305
|
+
case "fork":
|
|
1306
|
+
const { prefix, nibble, root } = proof2.neighbor;
|
|
1307
|
+
const neighbor = conStr0([
|
|
1308
|
+
integer(nibble),
|
|
1309
|
+
byteString(prefix.toString("hex")),
|
|
1310
|
+
byteString(root.toString("hex"))
|
|
1311
|
+
]);
|
|
1312
|
+
proofSteps.push(conStr1([skip, neighbor]));
|
|
1313
|
+
break;
|
|
1314
|
+
case "leaf":
|
|
1315
|
+
const { key, value: value2 } = proof2.neighbor;
|
|
1316
|
+
proofSteps.push(conStr2([skip, byteString(key), byteString(value2)]));
|
|
1317
|
+
break;
|
|
1318
|
+
}
|
|
1319
|
+
});
|
|
1320
|
+
return proofSteps;
|
|
1321
|
+
};
|
|
1322
|
+
|
|
1279
1323
|
// src/data/parser.ts
|
|
1280
1324
|
var bytesToHex = (bytes) => Buffer.from(bytes).toString("hex");
|
|
1281
1325
|
var hexToBytes = (hex) => Buffer.from(hex, "hex");
|
|
@@ -1723,7 +1767,7 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
|
|
|
1723
1767
|
const selectedInputs = /* @__PURE__ */ new Set();
|
|
1724
1768
|
const onlyLovelace = /* @__PURE__ */ new Set();
|
|
1725
1769
|
const singletons = /* @__PURE__ */ new Set();
|
|
1726
|
-
const
|
|
1770
|
+
const pairs2 = /* @__PURE__ */ new Set();
|
|
1727
1771
|
const rest = /* @__PURE__ */ new Set();
|
|
1728
1772
|
const collaterals = /* @__PURE__ */ new Set();
|
|
1729
1773
|
for (let i = 0; i < inputs.length; i++) {
|
|
@@ -1742,7 +1786,7 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
|
|
|
1742
1786
|
break;
|
|
1743
1787
|
}
|
|
1744
1788
|
case 3: {
|
|
1745
|
-
|
|
1789
|
+
pairs2.add(i);
|
|
1746
1790
|
break;
|
|
1747
1791
|
}
|
|
1748
1792
|
default: {
|
|
@@ -1775,10 +1819,10 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
|
|
|
1775
1819
|
if (!assetRequired || Number(assetRequired) <= 0) break;
|
|
1776
1820
|
addUtxoWithAssetAmount(inputIndex, assetUnit, singletons);
|
|
1777
1821
|
}
|
|
1778
|
-
for (const inputIndex of
|
|
1822
|
+
for (const inputIndex of pairs2) {
|
|
1779
1823
|
const assetRequired = totalRequiredAssets.get(assetUnit);
|
|
1780
1824
|
if (!assetRequired || Number(assetRequired) <= 0) break;
|
|
1781
|
-
addUtxoWithAssetAmount(inputIndex, assetUnit,
|
|
1825
|
+
addUtxoWithAssetAmount(inputIndex, assetUnit, pairs2);
|
|
1782
1826
|
}
|
|
1783
1827
|
for (const inputIndex of rest) {
|
|
1784
1828
|
const assetRequired = totalRequiredAssets.get(assetUnit);
|
|
@@ -1796,10 +1840,10 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
|
|
|
1796
1840
|
if (!assetRequired || Number(assetRequired) <= 0) break;
|
|
1797
1841
|
addUtxoWithAssetAmount(inputIndex, "lovelace", singletons);
|
|
1798
1842
|
}
|
|
1799
|
-
for (const inputIndex of
|
|
1843
|
+
for (const inputIndex of pairs2) {
|
|
1800
1844
|
const assetRequired = totalRequiredAssets.get("lovelace");
|
|
1801
1845
|
if (!assetRequired || Number(assetRequired) <= 0) break;
|
|
1802
|
-
addUtxoWithAssetAmount(inputIndex, "lovelace",
|
|
1846
|
+
addUtxoWithAssetAmount(inputIndex, "lovelace", pairs2);
|
|
1803
1847
|
}
|
|
1804
1848
|
for (const inputIndex of rest) {
|
|
1805
1849
|
const assetRequired = totalRequiredAssets.get("lovelace");
|
|
@@ -2029,6 +2073,7 @@ var import_bip39 = require("bip39");
|
|
|
2029
2073
|
hexToString,
|
|
2030
2074
|
integer,
|
|
2031
2075
|
isNetwork,
|
|
2076
|
+
jsonProofToPlutusData,
|
|
2032
2077
|
keepRelevant,
|
|
2033
2078
|
largestFirst,
|
|
2034
2079
|
largestFirstMultiAsset,
|
|
@@ -2061,6 +2106,7 @@ var import_bip39 = require("bip39");
|
|
|
2061
2106
|
none,
|
|
2062
2107
|
option,
|
|
2063
2108
|
outputReference,
|
|
2109
|
+
pairs,
|
|
2064
2110
|
parseAssetUnit,
|
|
2065
2111
|
plutusBSArrayToString,
|
|
2066
2112
|
policyId,
|
package/dist/index.d.cts
CHANGED
|
@@ -893,11 +893,27 @@ type AssocMapItem<K, V> = {
|
|
|
893
893
|
v: V;
|
|
894
894
|
};
|
|
895
895
|
/**
|
|
896
|
+
* PlutusTx alias
|
|
896
897
|
* The Plutus Data association map in JSON
|
|
897
898
|
*/
|
|
898
899
|
type AssocMap<K = any, V = any> = {
|
|
899
900
|
map: AssocMapItem<K, V>[];
|
|
900
901
|
};
|
|
902
|
+
/**
|
|
903
|
+
* Aiken alias
|
|
904
|
+
* The Plutus Data association map item in JSON
|
|
905
|
+
*/
|
|
906
|
+
type Pair<K, V> = {
|
|
907
|
+
k: K;
|
|
908
|
+
v: V;
|
|
909
|
+
};
|
|
910
|
+
/**
|
|
911
|
+
* Aiken alias
|
|
912
|
+
* The Plutus Data association map in JSON
|
|
913
|
+
*/
|
|
914
|
+
type Pairs<K = any, V = any> = {
|
|
915
|
+
map: Pair<K, V>[];
|
|
916
|
+
};
|
|
901
917
|
/**
|
|
902
918
|
* The utility function to create a Plutus Data boolean in JSON
|
|
903
919
|
* @param b boolean value
|
|
@@ -948,6 +964,13 @@ declare const plutusBSArrayToString: (bsArray: List<ByteString>) => string;
|
|
|
948
964
|
* @returns The Plutus Data association map object
|
|
949
965
|
*/
|
|
950
966
|
declare const assocMap: <K, V>(mapItems: [K, V][], validation?: boolean) => AssocMap<K, V>;
|
|
967
|
+
/**
|
|
968
|
+
* The utility function to create a Plutus Data Pairs in JSON
|
|
969
|
+
* @param mapItems The items map in array
|
|
970
|
+
* @param validation Default true - If current data construction would perform validation (introducing this flag due to possible performance issue in loop validation)
|
|
971
|
+
* @returns The Plutus Data Pairs object
|
|
972
|
+
*/
|
|
973
|
+
declare const pairs: <K, V>(mapItems: [K, V][], validation?: boolean) => Pairs<K, V>;
|
|
951
974
|
|
|
952
975
|
/**
|
|
953
976
|
* All the type aliases here represent the type name used in smart contracts from PlutusTx or Aiken.
|
|
@@ -1188,7 +1211,33 @@ declare const scriptAddress: (bytes: string, stakeCredential?: string, isStakeSc
|
|
|
1188
1211
|
*/
|
|
1189
1212
|
declare const credential: (hash: string, isScriptCredential?: boolean) => Credential;
|
|
1190
1213
|
|
|
1191
|
-
type
|
|
1214
|
+
type ProofStep = ProofStepBranch | ProofStepFork | ProofStepLeaf;
|
|
1215
|
+
type ProofStepBranch = ConStr0<[
|
|
1216
|
+
Integer,
|
|
1217
|
+
ByteString
|
|
1218
|
+
]>;
|
|
1219
|
+
type ProofStepFork = ConStr1<[
|
|
1220
|
+
Integer,
|
|
1221
|
+
ForkNeighbor
|
|
1222
|
+
]>;
|
|
1223
|
+
type ProofStepLeaf = ConStr2<[
|
|
1224
|
+
Integer,
|
|
1225
|
+
ByteString,
|
|
1226
|
+
ByteString
|
|
1227
|
+
]>;
|
|
1228
|
+
type ForkNeighbor = ConStr0<[
|
|
1229
|
+
Integer,
|
|
1230
|
+
ByteString,
|
|
1231
|
+
ByteString
|
|
1232
|
+
]>;
|
|
1233
|
+
/**
|
|
1234
|
+
* The utility function to transform a JSON proof from Aiken TS offchain library to Mesh JSON Data type
|
|
1235
|
+
* @param proof The proof object from Aiken TS offchain library
|
|
1236
|
+
* @returns The proof object in Mesh JSON Data type
|
|
1237
|
+
*/
|
|
1238
|
+
declare const jsonProofToPlutusData: (proof: object) => ProofStep[];
|
|
1239
|
+
|
|
1240
|
+
type PlutusData = ConStr | Bool | ByteString | Integer | List | AssocMap | Pairs | MaybeStakingHash | PubKeyAddress | ScriptAddress | AssetClass | OutputReference | PubKeyHash | POSIXTime | Dict<any> | Tuple<any, any>;
|
|
1192
1241
|
|
|
1193
1242
|
/**
|
|
1194
1243
|
* Converting bytes to hex string
|
|
@@ -1681,4 +1730,4 @@ declare const hashDrepAnchor: (jsonLD: object) => string;
|
|
|
1681
1730
|
|
|
1682
1731
|
declare function getFile(url: string): string;
|
|
1683
1732
|
|
|
1684
|
-
export { type AccountInfo, type Action, type Anchor, type Asset, type AssetClass, type AssetExtended, AssetFingerprint, type AssetMetadata, type AssetName, type AssocMap, type AssocMapItem, type BasicVote, BigNum, type BlockInfo, type Bool, type Budget, type BuilderData, type BuiltinByteString, type ByteString, CIP68_100, CIP68_222, type Certificate, type CertificateType, type ConStr, type ConStr0, type ConStr1, type ConStr2, type ConStr3, type Credential, type CurrencySymbol, DEFAULT_FETCHER_OPTIONS, DEFAULT_PROTOCOL_PARAMETERS, DEFAULT_REDEEMER_BUDGET, DEFAULT_V1_COST_MODEL_LIST, DEFAULT_V2_COST_MODEL_LIST, DEFAULT_V3_COST_MODEL_LIST, DREP_DEPOSIT, type DRep, type Data, type DataSignature, type DatumSource, type DeserializedAddress, type DeserializedScript, type Dict, type DictItem, type Era, type Files, type FungibleAssetMetadata, type GovernanceProposalInfo, HARDENED_KEY_START, type IDeserializer, type IEvaluator, type IFetcher, type IFetcherOptions, type IInitiator, type IListener, type IMeshTxSerializer, type IMintingBlueprint, type IResolver, type ISigner, type ISpendingBlueprint, type ISubmitter, type IWallet, type IWithdrawalBlueprint, type ImageAssetMetadata, type Integer, LANGUAGE_VERSIONS, type LanguageVersion, type List, type MAssetClass, type MBool, type MConStr, type MConStr0, type MConStr1, type MConStr2, type MConStr3, type MCredential, type MMaybeStakingHash, type MNone, type MOption, type MOutputReference, type MPubKeyAddress, type MScriptAddress, type MSome, type MTuple, type MTxOutRef, type MValue, type MaybeStakingHash, type MeshTxBuilderBody, MeshValue, type Message, type Metadata, type Metadatum, type MetadatumMap, type Mint, type MintItem, type NativeScript, type Network, type NonFungibleAssetMetadata, type None, type Option, type Output, type OutputReference, POLICY_ID_LENGTH, type POSIXTime, type PlutusData, type PlutusDataType, type PlutusScript, type PolicyId, type PoolMetadata, type PoolParams, type Protocol, type PubKeyAddress, type PubKeyHash, type PubKeyTxIn, type PubKeyWithdrawal, type Quantity, type Recipient, type Redeemer, type RedeemerTagType, type RefTxIn, type Relay, type RequiredWith, type RoyaltiesStandard, SLOT_CONFIG_NETWORK, SUPPORTED_CLOCKS, SUPPORTED_HANDLES, SUPPORTED_LANGUAGE_VIEWS, SUPPORTED_OGMIOS_LINKS, SUPPORTED_TOKENS, SUPPORTED_WALLETS, type ScriptAddress, type ScriptHash, type ScriptSource, type ScriptTxIn, type ScriptTxInParameter, type ScriptVote, type ScriptWithdrawal, type SimpleScriptSourceInfo, type SimpleScriptTxIn, type SimpleScriptTxInParameter, type SimpleScriptVote, type SimpleScriptWithdrawal, type SlotConfig, type Some, type Token, type TokenName, type TransactionInfo, type Tuple, type TxIn, type TxInParameter, type TxMetadata, type TxOutRef, type UTxO, type Unit, UtxoSelection, type UtxoSelectionStrategy, type ValidityRange, type Value, type Vote, type VoteKind, type VoteType, type Voter, type VotingProcedure, type Wallet, type Withdrawal, assetClass, assetName, assocMap, bool, builtinByteString, byteString, bytesToHex, castProtocol, conStr, conStr0, conStr1, conStr2, conStr3, credential, currencySymbol, dict, emptyTxBuilderBody, experimentalSelectUtxos, fromUTF8, fungibleAssetKeys, getFile, hashByteString, hashDrepAnchor, hexToBytes, hexToString, integer, isNetwork, keepRelevant, largestFirst, largestFirstMultiAsset, list, mAssetClass, mBool, mConStr, mConStr0, mConStr1, mConStr2, mConStr3, mCredential, mMaybeStakingHash, mNone, mOption, mOutputReference, mPlutusBSArrayToString, mPubKeyAddress, mScriptAddress, mSome, mStringToPlutusBSArray, mTuple, mTxOutRef, mValue, maybeStakingHash, mergeAssets, metadataStandardKeys, metadataToCip68, none, option, outputReference, parseAssetUnit, plutusBSArrayToString, policyId, posixTime, pubKeyAddress, pubKeyHash, resolveEpochNo, resolveFingerprint, resolveLanguageView, resolveSlotNo, resolveTxFees, royaltiesStandardKeys, scriptAddress, scriptHash, slotToBeginUnixTime, some, stringToBSArray, stringToHex, toBytes, toUTF8, tokenName, tuple, txInToUtxo, txOutRef, unixTimeToEnclosingSlot, validityRangeToObj, value };
|
|
1733
|
+
export { type AccountInfo, type Action, type Anchor, type Asset, type AssetClass, type AssetExtended, AssetFingerprint, type AssetMetadata, type AssetName, type AssocMap, type AssocMapItem, type BasicVote, BigNum, type BlockInfo, type Bool, type Budget, type BuilderData, type BuiltinByteString, type ByteString, CIP68_100, CIP68_222, type Certificate, type CertificateType, type ConStr, type ConStr0, type ConStr1, type ConStr2, type ConStr3, type Credential, type CurrencySymbol, DEFAULT_FETCHER_OPTIONS, DEFAULT_PROTOCOL_PARAMETERS, DEFAULT_REDEEMER_BUDGET, DEFAULT_V1_COST_MODEL_LIST, DEFAULT_V2_COST_MODEL_LIST, DEFAULT_V3_COST_MODEL_LIST, DREP_DEPOSIT, type DRep, type Data, type DataSignature, type DatumSource, type DeserializedAddress, type DeserializedScript, type Dict, type DictItem, type Era, type Files, type ForkNeighbor, type FungibleAssetMetadata, type GovernanceProposalInfo, HARDENED_KEY_START, type IDeserializer, type IEvaluator, type IFetcher, type IFetcherOptions, type IInitiator, type IListener, type IMeshTxSerializer, type IMintingBlueprint, type IResolver, type ISigner, type ISpendingBlueprint, type ISubmitter, type IWallet, type IWithdrawalBlueprint, type ImageAssetMetadata, type Integer, LANGUAGE_VERSIONS, type LanguageVersion, type List, type MAssetClass, type MBool, type MConStr, type MConStr0, type MConStr1, type MConStr2, type MConStr3, type MCredential, type MMaybeStakingHash, type MNone, type MOption, type MOutputReference, type MPubKeyAddress, type MScriptAddress, type MSome, type MTuple, type MTxOutRef, type MValue, type MaybeStakingHash, type MeshTxBuilderBody, MeshValue, type Message, type Metadata, type Metadatum, type MetadatumMap, type Mint, type MintItem, type NativeScript, type Network, type NonFungibleAssetMetadata, type None, type Option, type Output, type OutputReference, POLICY_ID_LENGTH, type POSIXTime, type Pair, type Pairs, type PlutusData, type PlutusDataType, type PlutusScript, type PolicyId, type PoolMetadata, type PoolParams, type ProofStep, type ProofStepBranch, type ProofStepFork, type ProofStepLeaf, type Protocol, type PubKeyAddress, type PubKeyHash, type PubKeyTxIn, type PubKeyWithdrawal, type Quantity, type Recipient, type Redeemer, type RedeemerTagType, type RefTxIn, type Relay, type RequiredWith, type RoyaltiesStandard, SLOT_CONFIG_NETWORK, SUPPORTED_CLOCKS, SUPPORTED_HANDLES, SUPPORTED_LANGUAGE_VIEWS, SUPPORTED_OGMIOS_LINKS, SUPPORTED_TOKENS, SUPPORTED_WALLETS, type ScriptAddress, type ScriptHash, type ScriptSource, type ScriptTxIn, type ScriptTxInParameter, type ScriptVote, type ScriptWithdrawal, type SimpleScriptSourceInfo, type SimpleScriptTxIn, type SimpleScriptTxInParameter, type SimpleScriptVote, type SimpleScriptWithdrawal, type SlotConfig, type Some, type Token, type TokenName, type TransactionInfo, type Tuple, type TxIn, type TxInParameter, type TxMetadata, type TxOutRef, type UTxO, type Unit, UtxoSelection, type UtxoSelectionStrategy, type ValidityRange, type Value, type Vote, type VoteKind, type VoteType, type Voter, type VotingProcedure, type Wallet, type Withdrawal, assetClass, assetName, assocMap, bool, builtinByteString, byteString, bytesToHex, castProtocol, conStr, conStr0, conStr1, conStr2, conStr3, credential, currencySymbol, dict, emptyTxBuilderBody, experimentalSelectUtxos, fromUTF8, fungibleAssetKeys, getFile, hashByteString, hashDrepAnchor, hexToBytes, hexToString, integer, isNetwork, jsonProofToPlutusData, keepRelevant, largestFirst, largestFirstMultiAsset, list, mAssetClass, mBool, mConStr, mConStr0, mConStr1, mConStr2, mConStr3, mCredential, mMaybeStakingHash, mNone, mOption, mOutputReference, mPlutusBSArrayToString, mPubKeyAddress, mScriptAddress, mSome, mStringToPlutusBSArray, mTuple, mTxOutRef, mValue, maybeStakingHash, mergeAssets, metadataStandardKeys, metadataToCip68, none, option, outputReference, pairs, parseAssetUnit, plutusBSArrayToString, policyId, posixTime, pubKeyAddress, pubKeyHash, resolveEpochNo, resolveFingerprint, resolveLanguageView, resolveSlotNo, resolveTxFees, royaltiesStandardKeys, scriptAddress, scriptHash, slotToBeginUnixTime, some, stringToBSArray, stringToHex, toBytes, toUTF8, tokenName, tuple, txInToUtxo, txOutRef, unixTimeToEnclosingSlot, validityRangeToObj, value };
|
package/dist/index.d.ts
CHANGED
|
@@ -893,11 +893,27 @@ type AssocMapItem<K, V> = {
|
|
|
893
893
|
v: V;
|
|
894
894
|
};
|
|
895
895
|
/**
|
|
896
|
+
* PlutusTx alias
|
|
896
897
|
* The Plutus Data association map in JSON
|
|
897
898
|
*/
|
|
898
899
|
type AssocMap<K = any, V = any> = {
|
|
899
900
|
map: AssocMapItem<K, V>[];
|
|
900
901
|
};
|
|
902
|
+
/**
|
|
903
|
+
* Aiken alias
|
|
904
|
+
* The Plutus Data association map item in JSON
|
|
905
|
+
*/
|
|
906
|
+
type Pair<K, V> = {
|
|
907
|
+
k: K;
|
|
908
|
+
v: V;
|
|
909
|
+
};
|
|
910
|
+
/**
|
|
911
|
+
* Aiken alias
|
|
912
|
+
* The Plutus Data association map in JSON
|
|
913
|
+
*/
|
|
914
|
+
type Pairs<K = any, V = any> = {
|
|
915
|
+
map: Pair<K, V>[];
|
|
916
|
+
};
|
|
901
917
|
/**
|
|
902
918
|
* The utility function to create a Plutus Data boolean in JSON
|
|
903
919
|
* @param b boolean value
|
|
@@ -948,6 +964,13 @@ declare const plutusBSArrayToString: (bsArray: List<ByteString>) => string;
|
|
|
948
964
|
* @returns The Plutus Data association map object
|
|
949
965
|
*/
|
|
950
966
|
declare const assocMap: <K, V>(mapItems: [K, V][], validation?: boolean) => AssocMap<K, V>;
|
|
967
|
+
/**
|
|
968
|
+
* The utility function to create a Plutus Data Pairs in JSON
|
|
969
|
+
* @param mapItems The items map in array
|
|
970
|
+
* @param validation Default true - If current data construction would perform validation (introducing this flag due to possible performance issue in loop validation)
|
|
971
|
+
* @returns The Plutus Data Pairs object
|
|
972
|
+
*/
|
|
973
|
+
declare const pairs: <K, V>(mapItems: [K, V][], validation?: boolean) => Pairs<K, V>;
|
|
951
974
|
|
|
952
975
|
/**
|
|
953
976
|
* All the type aliases here represent the type name used in smart contracts from PlutusTx or Aiken.
|
|
@@ -1188,7 +1211,33 @@ declare const scriptAddress: (bytes: string, stakeCredential?: string, isStakeSc
|
|
|
1188
1211
|
*/
|
|
1189
1212
|
declare const credential: (hash: string, isScriptCredential?: boolean) => Credential;
|
|
1190
1213
|
|
|
1191
|
-
type
|
|
1214
|
+
type ProofStep = ProofStepBranch | ProofStepFork | ProofStepLeaf;
|
|
1215
|
+
type ProofStepBranch = ConStr0<[
|
|
1216
|
+
Integer,
|
|
1217
|
+
ByteString
|
|
1218
|
+
]>;
|
|
1219
|
+
type ProofStepFork = ConStr1<[
|
|
1220
|
+
Integer,
|
|
1221
|
+
ForkNeighbor
|
|
1222
|
+
]>;
|
|
1223
|
+
type ProofStepLeaf = ConStr2<[
|
|
1224
|
+
Integer,
|
|
1225
|
+
ByteString,
|
|
1226
|
+
ByteString
|
|
1227
|
+
]>;
|
|
1228
|
+
type ForkNeighbor = ConStr0<[
|
|
1229
|
+
Integer,
|
|
1230
|
+
ByteString,
|
|
1231
|
+
ByteString
|
|
1232
|
+
]>;
|
|
1233
|
+
/**
|
|
1234
|
+
* The utility function to transform a JSON proof from Aiken TS offchain library to Mesh JSON Data type
|
|
1235
|
+
* @param proof The proof object from Aiken TS offchain library
|
|
1236
|
+
* @returns The proof object in Mesh JSON Data type
|
|
1237
|
+
*/
|
|
1238
|
+
declare const jsonProofToPlutusData: (proof: object) => ProofStep[];
|
|
1239
|
+
|
|
1240
|
+
type PlutusData = ConStr | Bool | ByteString | Integer | List | AssocMap | Pairs | MaybeStakingHash | PubKeyAddress | ScriptAddress | AssetClass | OutputReference | PubKeyHash | POSIXTime | Dict<any> | Tuple<any, any>;
|
|
1192
1241
|
|
|
1193
1242
|
/**
|
|
1194
1243
|
* Converting bytes to hex string
|
|
@@ -1681,4 +1730,4 @@ declare const hashDrepAnchor: (jsonLD: object) => string;
|
|
|
1681
1730
|
|
|
1682
1731
|
declare function getFile(url: string): string;
|
|
1683
1732
|
|
|
1684
|
-
export { type AccountInfo, type Action, type Anchor, type Asset, type AssetClass, type AssetExtended, AssetFingerprint, type AssetMetadata, type AssetName, type AssocMap, type AssocMapItem, type BasicVote, BigNum, type BlockInfo, type Bool, type Budget, type BuilderData, type BuiltinByteString, type ByteString, CIP68_100, CIP68_222, type Certificate, type CertificateType, type ConStr, type ConStr0, type ConStr1, type ConStr2, type ConStr3, type Credential, type CurrencySymbol, DEFAULT_FETCHER_OPTIONS, DEFAULT_PROTOCOL_PARAMETERS, DEFAULT_REDEEMER_BUDGET, DEFAULT_V1_COST_MODEL_LIST, DEFAULT_V2_COST_MODEL_LIST, DEFAULT_V3_COST_MODEL_LIST, DREP_DEPOSIT, type DRep, type Data, type DataSignature, type DatumSource, type DeserializedAddress, type DeserializedScript, type Dict, type DictItem, type Era, type Files, type FungibleAssetMetadata, type GovernanceProposalInfo, HARDENED_KEY_START, type IDeserializer, type IEvaluator, type IFetcher, type IFetcherOptions, type IInitiator, type IListener, type IMeshTxSerializer, type IMintingBlueprint, type IResolver, type ISigner, type ISpendingBlueprint, type ISubmitter, type IWallet, type IWithdrawalBlueprint, type ImageAssetMetadata, type Integer, LANGUAGE_VERSIONS, type LanguageVersion, type List, type MAssetClass, type MBool, type MConStr, type MConStr0, type MConStr1, type MConStr2, type MConStr3, type MCredential, type MMaybeStakingHash, type MNone, type MOption, type MOutputReference, type MPubKeyAddress, type MScriptAddress, type MSome, type MTuple, type MTxOutRef, type MValue, type MaybeStakingHash, type MeshTxBuilderBody, MeshValue, type Message, type Metadata, type Metadatum, type MetadatumMap, type Mint, type MintItem, type NativeScript, type Network, type NonFungibleAssetMetadata, type None, type Option, type Output, type OutputReference, POLICY_ID_LENGTH, type POSIXTime, type PlutusData, type PlutusDataType, type PlutusScript, type PolicyId, type PoolMetadata, type PoolParams, type Protocol, type PubKeyAddress, type PubKeyHash, type PubKeyTxIn, type PubKeyWithdrawal, type Quantity, type Recipient, type Redeemer, type RedeemerTagType, type RefTxIn, type Relay, type RequiredWith, type RoyaltiesStandard, SLOT_CONFIG_NETWORK, SUPPORTED_CLOCKS, SUPPORTED_HANDLES, SUPPORTED_LANGUAGE_VIEWS, SUPPORTED_OGMIOS_LINKS, SUPPORTED_TOKENS, SUPPORTED_WALLETS, type ScriptAddress, type ScriptHash, type ScriptSource, type ScriptTxIn, type ScriptTxInParameter, type ScriptVote, type ScriptWithdrawal, type SimpleScriptSourceInfo, type SimpleScriptTxIn, type SimpleScriptTxInParameter, type SimpleScriptVote, type SimpleScriptWithdrawal, type SlotConfig, type Some, type Token, type TokenName, type TransactionInfo, type Tuple, type TxIn, type TxInParameter, type TxMetadata, type TxOutRef, type UTxO, type Unit, UtxoSelection, type UtxoSelectionStrategy, type ValidityRange, type Value, type Vote, type VoteKind, type VoteType, type Voter, type VotingProcedure, type Wallet, type Withdrawal, assetClass, assetName, assocMap, bool, builtinByteString, byteString, bytesToHex, castProtocol, conStr, conStr0, conStr1, conStr2, conStr3, credential, currencySymbol, dict, emptyTxBuilderBody, experimentalSelectUtxos, fromUTF8, fungibleAssetKeys, getFile, hashByteString, hashDrepAnchor, hexToBytes, hexToString, integer, isNetwork, keepRelevant, largestFirst, largestFirstMultiAsset, list, mAssetClass, mBool, mConStr, mConStr0, mConStr1, mConStr2, mConStr3, mCredential, mMaybeStakingHash, mNone, mOption, mOutputReference, mPlutusBSArrayToString, mPubKeyAddress, mScriptAddress, mSome, mStringToPlutusBSArray, mTuple, mTxOutRef, mValue, maybeStakingHash, mergeAssets, metadataStandardKeys, metadataToCip68, none, option, outputReference, parseAssetUnit, plutusBSArrayToString, policyId, posixTime, pubKeyAddress, pubKeyHash, resolveEpochNo, resolveFingerprint, resolveLanguageView, resolveSlotNo, resolveTxFees, royaltiesStandardKeys, scriptAddress, scriptHash, slotToBeginUnixTime, some, stringToBSArray, stringToHex, toBytes, toUTF8, tokenName, tuple, txInToUtxo, txOutRef, unixTimeToEnclosingSlot, validityRangeToObj, value };
|
|
1733
|
+
export { type AccountInfo, type Action, type Anchor, type Asset, type AssetClass, type AssetExtended, AssetFingerprint, type AssetMetadata, type AssetName, type AssocMap, type AssocMapItem, type BasicVote, BigNum, type BlockInfo, type Bool, type Budget, type BuilderData, type BuiltinByteString, type ByteString, CIP68_100, CIP68_222, type Certificate, type CertificateType, type ConStr, type ConStr0, type ConStr1, type ConStr2, type ConStr3, type Credential, type CurrencySymbol, DEFAULT_FETCHER_OPTIONS, DEFAULT_PROTOCOL_PARAMETERS, DEFAULT_REDEEMER_BUDGET, DEFAULT_V1_COST_MODEL_LIST, DEFAULT_V2_COST_MODEL_LIST, DEFAULT_V3_COST_MODEL_LIST, DREP_DEPOSIT, type DRep, type Data, type DataSignature, type DatumSource, type DeserializedAddress, type DeserializedScript, type Dict, type DictItem, type Era, type Files, type ForkNeighbor, type FungibleAssetMetadata, type GovernanceProposalInfo, HARDENED_KEY_START, type IDeserializer, type IEvaluator, type IFetcher, type IFetcherOptions, type IInitiator, type IListener, type IMeshTxSerializer, type IMintingBlueprint, type IResolver, type ISigner, type ISpendingBlueprint, type ISubmitter, type IWallet, type IWithdrawalBlueprint, type ImageAssetMetadata, type Integer, LANGUAGE_VERSIONS, type LanguageVersion, type List, type MAssetClass, type MBool, type MConStr, type MConStr0, type MConStr1, type MConStr2, type MConStr3, type MCredential, type MMaybeStakingHash, type MNone, type MOption, type MOutputReference, type MPubKeyAddress, type MScriptAddress, type MSome, type MTuple, type MTxOutRef, type MValue, type MaybeStakingHash, type MeshTxBuilderBody, MeshValue, type Message, type Metadata, type Metadatum, type MetadatumMap, type Mint, type MintItem, type NativeScript, type Network, type NonFungibleAssetMetadata, type None, type Option, type Output, type OutputReference, POLICY_ID_LENGTH, type POSIXTime, type Pair, type Pairs, type PlutusData, type PlutusDataType, type PlutusScript, type PolicyId, type PoolMetadata, type PoolParams, type ProofStep, type ProofStepBranch, type ProofStepFork, type ProofStepLeaf, type Protocol, type PubKeyAddress, type PubKeyHash, type PubKeyTxIn, type PubKeyWithdrawal, type Quantity, type Recipient, type Redeemer, type RedeemerTagType, type RefTxIn, type Relay, type RequiredWith, type RoyaltiesStandard, SLOT_CONFIG_NETWORK, SUPPORTED_CLOCKS, SUPPORTED_HANDLES, SUPPORTED_LANGUAGE_VIEWS, SUPPORTED_OGMIOS_LINKS, SUPPORTED_TOKENS, SUPPORTED_WALLETS, type ScriptAddress, type ScriptHash, type ScriptSource, type ScriptTxIn, type ScriptTxInParameter, type ScriptVote, type ScriptWithdrawal, type SimpleScriptSourceInfo, type SimpleScriptTxIn, type SimpleScriptTxInParameter, type SimpleScriptVote, type SimpleScriptWithdrawal, type SlotConfig, type Some, type Token, type TokenName, type TransactionInfo, type Tuple, type TxIn, type TxInParameter, type TxMetadata, type TxOutRef, type UTxO, type Unit, UtxoSelection, type UtxoSelectionStrategy, type ValidityRange, type Value, type Vote, type VoteKind, type VoteType, type Voter, type VotingProcedure, type Wallet, type Withdrawal, assetClass, assetName, assocMap, bool, builtinByteString, byteString, bytesToHex, castProtocol, conStr, conStr0, conStr1, conStr2, conStr3, credential, currencySymbol, dict, emptyTxBuilderBody, experimentalSelectUtxos, fromUTF8, fungibleAssetKeys, getFile, hashByteString, hashDrepAnchor, hexToBytes, hexToString, integer, isNetwork, jsonProofToPlutusData, keepRelevant, largestFirst, largestFirstMultiAsset, list, mAssetClass, mBool, mConStr, mConStr0, mConStr1, mConStr2, mConStr3, mCredential, mMaybeStakingHash, mNone, mOption, mOutputReference, mPlutusBSArrayToString, mPubKeyAddress, mScriptAddress, mSome, mStringToPlutusBSArray, mTuple, mTxOutRef, mValue, maybeStakingHash, mergeAssets, metadataStandardKeys, metadataToCip68, none, option, outputReference, pairs, parseAssetUnit, plutusBSArrayToString, policyId, posixTime, pubKeyAddress, pubKeyHash, resolveEpochNo, resolveFingerprint, resolveLanguageView, resolveSlotNo, resolveTxFees, royaltiesStandardKeys, scriptAddress, scriptHash, slotToBeginUnixTime, some, stringToBSArray, stringToHex, toBytes, toUTF8, tokenName, tuple, txInToUtxo, txOutRef, unixTimeToEnclosingSlot, validityRangeToObj, value };
|
package/dist/index.js
CHANGED
|
@@ -1052,6 +1052,18 @@ var assocMap = (mapItems, validation = true) => ({
|
|
|
1052
1052
|
return { k, v };
|
|
1053
1053
|
})
|
|
1054
1054
|
});
|
|
1055
|
+
var pairs = (mapItems, validation = true) => ({
|
|
1056
|
+
map: mapItems.map(([k, v]) => {
|
|
1057
|
+
if (validation) {
|
|
1058
|
+
if (typeof k !== "object" || typeof v !== "object") {
|
|
1059
|
+
throw new Error(
|
|
1060
|
+
`Map item of JSON Cardano data type must be an object - ${k}, ${v}`
|
|
1061
|
+
);
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
return { k, v };
|
|
1065
|
+
})
|
|
1066
|
+
});
|
|
1055
1067
|
|
|
1056
1068
|
// src/data/json/aliases.ts
|
|
1057
1069
|
var hashByteString = (bytes) => {
|
|
@@ -1131,6 +1143,36 @@ var scriptAddress = (bytes, stakeCredential, isStakeScriptCredential = false) =>
|
|
|
1131
1143
|
]);
|
|
1132
1144
|
var credential = (hash, isScriptCredential = false) => isScriptCredential ? conStr1([scriptHash(hash)]) : conStr0([pubKeyHash(hash)]);
|
|
1133
1145
|
|
|
1146
|
+
// src/data/json/mpf.ts
|
|
1147
|
+
var jsonProofToPlutusData = (proof) => {
|
|
1148
|
+
const proofSteps = [];
|
|
1149
|
+
const proofJson = proof;
|
|
1150
|
+
proofJson.forEach((proof2) => {
|
|
1151
|
+
const skip = integer(proof2.skip);
|
|
1152
|
+
switch (proof2.type) {
|
|
1153
|
+
case "branch":
|
|
1154
|
+
proofSteps.push(
|
|
1155
|
+
conStr0([skip, byteString(proof2.neighbors.toString("hex"))])
|
|
1156
|
+
);
|
|
1157
|
+
break;
|
|
1158
|
+
case "fork":
|
|
1159
|
+
const { prefix, nibble, root } = proof2.neighbor;
|
|
1160
|
+
const neighbor = conStr0([
|
|
1161
|
+
integer(nibble),
|
|
1162
|
+
byteString(prefix.toString("hex")),
|
|
1163
|
+
byteString(root.toString("hex"))
|
|
1164
|
+
]);
|
|
1165
|
+
proofSteps.push(conStr1([skip, neighbor]));
|
|
1166
|
+
break;
|
|
1167
|
+
case "leaf":
|
|
1168
|
+
const { key, value: value2 } = proof2.neighbor;
|
|
1169
|
+
proofSteps.push(conStr2([skip, byteString(key), byteString(value2)]));
|
|
1170
|
+
break;
|
|
1171
|
+
}
|
|
1172
|
+
});
|
|
1173
|
+
return proofSteps;
|
|
1174
|
+
};
|
|
1175
|
+
|
|
1134
1176
|
// src/data/parser.ts
|
|
1135
1177
|
var bytesToHex = (bytes) => Buffer.from(bytes).toString("hex");
|
|
1136
1178
|
var hexToBytes = (hex) => Buffer.from(hex, "hex");
|
|
@@ -1578,7 +1620,7 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
|
|
|
1578
1620
|
const selectedInputs = /* @__PURE__ */ new Set();
|
|
1579
1621
|
const onlyLovelace = /* @__PURE__ */ new Set();
|
|
1580
1622
|
const singletons = /* @__PURE__ */ new Set();
|
|
1581
|
-
const
|
|
1623
|
+
const pairs2 = /* @__PURE__ */ new Set();
|
|
1582
1624
|
const rest = /* @__PURE__ */ new Set();
|
|
1583
1625
|
const collaterals = /* @__PURE__ */ new Set();
|
|
1584
1626
|
for (let i = 0; i < inputs.length; i++) {
|
|
@@ -1597,7 +1639,7 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
|
|
|
1597
1639
|
break;
|
|
1598
1640
|
}
|
|
1599
1641
|
case 3: {
|
|
1600
|
-
|
|
1642
|
+
pairs2.add(i);
|
|
1601
1643
|
break;
|
|
1602
1644
|
}
|
|
1603
1645
|
default: {
|
|
@@ -1630,10 +1672,10 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
|
|
|
1630
1672
|
if (!assetRequired || Number(assetRequired) <= 0) break;
|
|
1631
1673
|
addUtxoWithAssetAmount(inputIndex, assetUnit, singletons);
|
|
1632
1674
|
}
|
|
1633
|
-
for (const inputIndex of
|
|
1675
|
+
for (const inputIndex of pairs2) {
|
|
1634
1676
|
const assetRequired = totalRequiredAssets.get(assetUnit);
|
|
1635
1677
|
if (!assetRequired || Number(assetRequired) <= 0) break;
|
|
1636
|
-
addUtxoWithAssetAmount(inputIndex, assetUnit,
|
|
1678
|
+
addUtxoWithAssetAmount(inputIndex, assetUnit, pairs2);
|
|
1637
1679
|
}
|
|
1638
1680
|
for (const inputIndex of rest) {
|
|
1639
1681
|
const assetRequired = totalRequiredAssets.get(assetUnit);
|
|
@@ -1651,10 +1693,10 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
|
|
|
1651
1693
|
if (!assetRequired || Number(assetRequired) <= 0) break;
|
|
1652
1694
|
addUtxoWithAssetAmount(inputIndex, "lovelace", singletons);
|
|
1653
1695
|
}
|
|
1654
|
-
for (const inputIndex of
|
|
1696
|
+
for (const inputIndex of pairs2) {
|
|
1655
1697
|
const assetRequired = totalRequiredAssets.get("lovelace");
|
|
1656
1698
|
if (!assetRequired || Number(assetRequired) <= 0) break;
|
|
1657
|
-
addUtxoWithAssetAmount(inputIndex, "lovelace",
|
|
1699
|
+
addUtxoWithAssetAmount(inputIndex, "lovelace", pairs2);
|
|
1658
1700
|
}
|
|
1659
1701
|
for (const inputIndex of rest) {
|
|
1660
1702
|
const assetRequired = totalRequiredAssets.get("lovelace");
|
|
@@ -1883,6 +1925,7 @@ export {
|
|
|
1883
1925
|
hexToString,
|
|
1884
1926
|
integer,
|
|
1885
1927
|
isNetwork,
|
|
1928
|
+
jsonProofToPlutusData,
|
|
1886
1929
|
keepRelevant,
|
|
1887
1930
|
largestFirst,
|
|
1888
1931
|
largestFirstMultiAsset,
|
|
@@ -1915,6 +1958,7 @@ export {
|
|
|
1915
1958
|
none,
|
|
1916
1959
|
option,
|
|
1917
1960
|
outputReference,
|
|
1961
|
+
pairs,
|
|
1918
1962
|
parseAssetUnit,
|
|
1919
1963
|
plutusBSArrayToString,
|
|
1920
1964
|
policyId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshsdk/common",
|
|
3
|
-
"version": "1.9.0-beta.
|
|
3
|
+
"version": "1.9.0-beta.24",
|
|
4
4
|
"description": "Contains constants, types and interfaces used across the SDK and different serialization libraries",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"browser": "./dist/index.js",
|