@lucid-evolution/utils 0.1.25 → 0.1.27
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 +25 -0
- package/dist/index.d.cts +18 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.js +24 -0
- package/package.json +8 -7
package/dist/index.cjs
CHANGED
|
@@ -53,6 +53,7 @@ __export(src_exports, {
|
|
|
53
53
|
generatePrivateKey: () => generatePrivateKey,
|
|
54
54
|
generateSeedPhrase: () => generateSeedPhrase,
|
|
55
55
|
getAddressDetails: () => getAddressDetails,
|
|
56
|
+
getInputIndices: () => getInputIndices,
|
|
56
57
|
getUniqueTokenName: () => getUniqueTokenName,
|
|
57
58
|
isEqualUTxO: () => isEqualUTxO,
|
|
58
59
|
keyHashToCredential: () => keyHashToCredential,
|
|
@@ -1152,6 +1153,8 @@ var sortUTxOs = (utxos, order = "LargestFirst") => {
|
|
|
1152
1153
|
return [...utxos].sort(largestFirst);
|
|
1153
1154
|
case "SmallestFirst":
|
|
1154
1155
|
return [...utxos].sort(smallestFirst);
|
|
1156
|
+
case "Canonical":
|
|
1157
|
+
return [...utxos].sort(canonical);
|
|
1155
1158
|
}
|
|
1156
1159
|
};
|
|
1157
1160
|
var largestFirst = (a, b) => {
|
|
@@ -1170,7 +1173,28 @@ var smallestFirst = (a, b) => {
|
|
|
1170
1173
|
}
|
|
1171
1174
|
return lovelaceA - lovelaceB;
|
|
1172
1175
|
};
|
|
1176
|
+
var canonical = (a, b) => {
|
|
1177
|
+
if (a.txHash < b.txHash) {
|
|
1178
|
+
return -1;
|
|
1179
|
+
} else if (a.txHash > b.txHash) {
|
|
1180
|
+
return 1;
|
|
1181
|
+
} else {
|
|
1182
|
+
return a.outputIndex - b.outputIndex;
|
|
1183
|
+
}
|
|
1184
|
+
};
|
|
1173
1185
|
var isEqualUTxO = (self, that) => self.txHash === that.txHash && self.outputIndex === that.outputIndex;
|
|
1186
|
+
function getInputIndices(indexInputs, allInputs, sorted = false) {
|
|
1187
|
+
const sortedInputs = sorted ? allInputs : sortUTxOs(allInputs, "Canonical");
|
|
1188
|
+
const indicesMap = /* @__PURE__ */ new Map();
|
|
1189
|
+
sortedInputs.forEach((value, index) => {
|
|
1190
|
+
indicesMap.set(value.txHash + value.outputIndex, BigInt(index));
|
|
1191
|
+
});
|
|
1192
|
+
return indexInputs.flatMap((value) => {
|
|
1193
|
+
const index = indicesMap.get(value.txHash + value.outputIndex);
|
|
1194
|
+
if (index !== void 0) return index;
|
|
1195
|
+
else return [];
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1174
1198
|
var calculateMinLovelaceFromUTxO = (coinsPerUtxoByte, utxo) => buildOutput(utxo).with_asset_and_min_required_coin(
|
|
1175
1199
|
assetsToValue(utxo.assets).multi_asset(),
|
|
1176
1200
|
coinsPerUtxoByte
|
|
@@ -1224,6 +1248,7 @@ var stringify = (data) => JSON.stringify(
|
|
|
1224
1248
|
generatePrivateKey,
|
|
1225
1249
|
generateSeedPhrase,
|
|
1226
1250
|
getAddressDetails,
|
|
1251
|
+
getInputIndices,
|
|
1227
1252
|
getUniqueTokenName,
|
|
1228
1253
|
isEqualUTxO,
|
|
1229
1254
|
keyHashToCredential,
|
package/dist/index.d.cts
CHANGED
|
@@ -119,9 +119,14 @@ type SortOrder =
|
|
|
119
119
|
/**
|
|
120
120
|
* Smallest amount of "lovelace" with least number of unique assets first
|
|
121
121
|
*/
|
|
122
|
-
| "SmallestFirst"
|
|
122
|
+
| "SmallestFirst"
|
|
123
|
+
/**
|
|
124
|
+
* Lexicographically sorted as per ledger rules
|
|
125
|
+
*/
|
|
126
|
+
| "Canonical";
|
|
123
127
|
/**
|
|
124
128
|
* Sorts an array of UTXOs according to specified sort order ("LargestFirst" by default).
|
|
129
|
+
* The provided array is cloned and reference to the new sorted array is returned.
|
|
125
130
|
*
|
|
126
131
|
* @param {UTxO[]} utxos - The array of UTXO objects to be sorted.
|
|
127
132
|
* @param {SortOrder} [order="LargestFirst"] - The order in which to sort the UTXOs.
|
|
@@ -130,6 +135,17 @@ type SortOrder =
|
|
|
130
135
|
*/
|
|
131
136
|
declare const sortUTxOs: (utxos: UTxO[], order?: SortOrder) => UTxO[];
|
|
132
137
|
declare const isEqualUTxO: (self: UTxO, that: UTxO) => boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Provides an array of input indices for given "indexInputs" UTxOs.
|
|
140
|
+
* Indices obtained from the list of transaction inputs which are
|
|
141
|
+
* ordered as per ledger rules.
|
|
142
|
+
*
|
|
143
|
+
* @param indexInputs Input utxos whose indices need to be returned
|
|
144
|
+
* @param allInputs All the inputs utxos being spent by the transaction
|
|
145
|
+
* @param sorted Whether the provided "allInputs" are sorted canonically or not
|
|
146
|
+
* @returns Input indices of utxos as they appear in "indexInputs"
|
|
147
|
+
*/
|
|
148
|
+
declare function getInputIndices(indexInputs: UTxO[], allInputs: UTxO[], sorted?: Boolean): bigint[];
|
|
133
149
|
declare const calculateMinLovelaceFromUTxO: (coinsPerUtxoByte: bigint, utxo: UTxO) => bigint;
|
|
134
150
|
|
|
135
151
|
declare function valueToAssets(value: CML.Value): Assets;
|
|
@@ -157,4 +173,4 @@ declare function getUniqueTokenName(utxo: UTxO): Promise<string>;
|
|
|
157
173
|
|
|
158
174
|
declare const stringify: (data: any) => string;
|
|
159
175
|
|
|
160
|
-
export { type CMLNative, PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, calculateMinLovelaceFromUTxO, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumToHash, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, getUniqueTokenName, isEqualUTxO, keyHashToCredential, mintingPolicyToId, networkToId, parseCMLNative, paymentCredentialOf, scriptFromCMLNative, scriptFromNative, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortUTxOs, stakeCredentialOf, stringify, toCMLNativeScript, toLabel, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
|
|
176
|
+
export { type CMLNative, PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, calculateMinLovelaceFromUTxO, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumToHash, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, getInputIndices, getUniqueTokenName, isEqualUTxO, keyHashToCredential, mintingPolicyToId, networkToId, parseCMLNative, paymentCredentialOf, scriptFromCMLNative, scriptFromNative, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortUTxOs, stakeCredentialOf, stringify, toCMLNativeScript, toLabel, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
|
package/dist/index.d.ts
CHANGED
|
@@ -119,9 +119,14 @@ type SortOrder =
|
|
|
119
119
|
/**
|
|
120
120
|
* Smallest amount of "lovelace" with least number of unique assets first
|
|
121
121
|
*/
|
|
122
|
-
| "SmallestFirst"
|
|
122
|
+
| "SmallestFirst"
|
|
123
|
+
/**
|
|
124
|
+
* Lexicographically sorted as per ledger rules
|
|
125
|
+
*/
|
|
126
|
+
| "Canonical";
|
|
123
127
|
/**
|
|
124
128
|
* Sorts an array of UTXOs according to specified sort order ("LargestFirst" by default).
|
|
129
|
+
* The provided array is cloned and reference to the new sorted array is returned.
|
|
125
130
|
*
|
|
126
131
|
* @param {UTxO[]} utxos - The array of UTXO objects to be sorted.
|
|
127
132
|
* @param {SortOrder} [order="LargestFirst"] - The order in which to sort the UTXOs.
|
|
@@ -130,6 +135,17 @@ type SortOrder =
|
|
|
130
135
|
*/
|
|
131
136
|
declare const sortUTxOs: (utxos: UTxO[], order?: SortOrder) => UTxO[];
|
|
132
137
|
declare const isEqualUTxO: (self: UTxO, that: UTxO) => boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Provides an array of input indices for given "indexInputs" UTxOs.
|
|
140
|
+
* Indices obtained from the list of transaction inputs which are
|
|
141
|
+
* ordered as per ledger rules.
|
|
142
|
+
*
|
|
143
|
+
* @param indexInputs Input utxos whose indices need to be returned
|
|
144
|
+
* @param allInputs All the inputs utxos being spent by the transaction
|
|
145
|
+
* @param sorted Whether the provided "allInputs" are sorted canonically or not
|
|
146
|
+
* @returns Input indices of utxos as they appear in "indexInputs"
|
|
147
|
+
*/
|
|
148
|
+
declare function getInputIndices(indexInputs: UTxO[], allInputs: UTxO[], sorted?: Boolean): bigint[];
|
|
133
149
|
declare const calculateMinLovelaceFromUTxO: (coinsPerUtxoByte: bigint, utxo: UTxO) => bigint;
|
|
134
150
|
|
|
135
151
|
declare function valueToAssets(value: CML.Value): Assets;
|
|
@@ -157,4 +173,4 @@ declare function getUniqueTokenName(utxo: UTxO): Promise<string>;
|
|
|
157
173
|
|
|
158
174
|
declare const stringify: (data: any) => string;
|
|
159
175
|
|
|
160
|
-
export { type CMLNative, PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, calculateMinLovelaceFromUTxO, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumToHash, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, getUniqueTokenName, isEqualUTxO, keyHashToCredential, mintingPolicyToId, networkToId, parseCMLNative, paymentCredentialOf, scriptFromCMLNative, scriptFromNative, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortUTxOs, stakeCredentialOf, stringify, toCMLNativeScript, toLabel, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
|
|
176
|
+
export { type CMLNative, PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, calculateMinLovelaceFromUTxO, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumToHash, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, getInputIndices, getUniqueTokenName, isEqualUTxO, keyHashToCredential, mintingPolicyToId, networkToId, parseCMLNative, paymentCredentialOf, scriptFromCMLNative, scriptFromNative, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortUTxOs, stakeCredentialOf, stringify, toCMLNativeScript, toLabel, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
|
package/dist/index.js
CHANGED
|
@@ -1069,6 +1069,8 @@ var sortUTxOs = (utxos, order = "LargestFirst") => {
|
|
|
1069
1069
|
return [...utxos].sort(largestFirst);
|
|
1070
1070
|
case "SmallestFirst":
|
|
1071
1071
|
return [...utxos].sort(smallestFirst);
|
|
1072
|
+
case "Canonical":
|
|
1073
|
+
return [...utxos].sort(canonical);
|
|
1072
1074
|
}
|
|
1073
1075
|
};
|
|
1074
1076
|
var largestFirst = (a, b) => {
|
|
@@ -1087,7 +1089,28 @@ var smallestFirst = (a, b) => {
|
|
|
1087
1089
|
}
|
|
1088
1090
|
return lovelaceA - lovelaceB;
|
|
1089
1091
|
};
|
|
1092
|
+
var canonical = (a, b) => {
|
|
1093
|
+
if (a.txHash < b.txHash) {
|
|
1094
|
+
return -1;
|
|
1095
|
+
} else if (a.txHash > b.txHash) {
|
|
1096
|
+
return 1;
|
|
1097
|
+
} else {
|
|
1098
|
+
return a.outputIndex - b.outputIndex;
|
|
1099
|
+
}
|
|
1100
|
+
};
|
|
1090
1101
|
var isEqualUTxO = (self, that) => self.txHash === that.txHash && self.outputIndex === that.outputIndex;
|
|
1102
|
+
function getInputIndices(indexInputs, allInputs, sorted = false) {
|
|
1103
|
+
const sortedInputs = sorted ? allInputs : sortUTxOs(allInputs, "Canonical");
|
|
1104
|
+
const indicesMap = /* @__PURE__ */ new Map();
|
|
1105
|
+
sortedInputs.forEach((value, index) => {
|
|
1106
|
+
indicesMap.set(value.txHash + value.outputIndex, BigInt(index));
|
|
1107
|
+
});
|
|
1108
|
+
return indexInputs.flatMap((value) => {
|
|
1109
|
+
const index = indicesMap.get(value.txHash + value.outputIndex);
|
|
1110
|
+
if (index !== void 0) return index;
|
|
1111
|
+
else return [];
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1091
1114
|
var calculateMinLovelaceFromUTxO = (coinsPerUtxoByte, utxo) => buildOutput(utxo).with_asset_and_min_required_coin(
|
|
1092
1115
|
assetsToValue(utxo.assets).multi_asset(),
|
|
1093
1116
|
coinsPerUtxoByte
|
|
@@ -1140,6 +1163,7 @@ export {
|
|
|
1140
1163
|
generatePrivateKey,
|
|
1141
1164
|
generateSeedPhrase,
|
|
1142
1165
|
getAddressDetails,
|
|
1166
|
+
getInputIndices,
|
|
1143
1167
|
getUniqueTokenName,
|
|
1144
1168
|
isEqualUTxO,
|
|
1145
1169
|
keyHashToCredential,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucid-evolution/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.27",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"@emurgo/cardano-serialization-lib-nodejs": "^11.5.0",
|
|
34
34
|
"cborg": "^4.2.0",
|
|
35
35
|
"effect": "^3.1.2",
|
|
36
|
-
"@lucid-evolution/bip39": "0.2.
|
|
37
|
-
"@lucid-evolution/core-types": "0.1.
|
|
38
|
-
"@lucid-evolution/core-utils": "0.1.
|
|
39
|
-
"@lucid-evolution/crc8": "0.1.
|
|
40
|
-
"@lucid-evolution/plutus": "0.1.
|
|
41
|
-
"@lucid-evolution/uplc": "0.2.
|
|
36
|
+
"@lucid-evolution/bip39": "0.2.10",
|
|
37
|
+
"@lucid-evolution/core-types": "0.1.11",
|
|
38
|
+
"@lucid-evolution/core-utils": "0.1.8",
|
|
39
|
+
"@lucid-evolution/crc8": "0.1.8",
|
|
40
|
+
"@lucid-evolution/plutus": "0.1.14",
|
|
41
|
+
"@lucid-evolution/uplc": "0.2.9"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/node": "^20.12.8",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
51
|
+
"lint": "tsc --noEmit",
|
|
51
52
|
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
52
53
|
"test": "vitest run"
|
|
53
54
|
}
|