@lucid-evolution/utils 0.1.36 → 0.1.37
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 +43 -0
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +42 -0
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -46,6 +46,7 @@ __export(src_exports, {
|
|
|
46
46
|
createCostModels: () => createCostModels,
|
|
47
47
|
credentialToAddress: () => credentialToAddress,
|
|
48
48
|
credentialToRewardAddress: () => credentialToRewardAddress,
|
|
49
|
+
datumJsonToCbor: () => datumJsonToCbor,
|
|
49
50
|
datumToHash: () => datumToHash,
|
|
50
51
|
fromLabel: () => fromLabel,
|
|
51
52
|
fromScriptRef: () => fromScriptRef,
|
|
@@ -197,6 +198,47 @@ var applyDoubleCborEncoding = (script) => {
|
|
|
197
198
|
return (0, import_core_utils.toHex)((0, import_cborg.encode)((0, import_core_utils.fromHex)(script)));
|
|
198
199
|
}
|
|
199
200
|
};
|
|
201
|
+
function datumJsonToCbor(json) {
|
|
202
|
+
const convert = (json2) => {
|
|
203
|
+
if (!isNaN(json2.int)) {
|
|
204
|
+
const plutusBigInt = CML.BigInteger.from_str(json2.int.toString());
|
|
205
|
+
return CML.PlutusData.new_integer(plutusBigInt);
|
|
206
|
+
} else if (json2.bytes || !isNaN(Number(json2.bytes))) {
|
|
207
|
+
return CML.PlutusData.new_bytes((0, import_core_utils.fromHex)(json2.bytes));
|
|
208
|
+
} else if (json2.list) {
|
|
209
|
+
const l = CML.PlutusDataList.new();
|
|
210
|
+
json2.list.forEach((v) => {
|
|
211
|
+
l.add(convert(v));
|
|
212
|
+
});
|
|
213
|
+
return CML.PlutusData.new_list(l);
|
|
214
|
+
} else if (json2.map && json2.map.length > 0 && typeof json2.map[0] === "object") {
|
|
215
|
+
const m = CML.PlutusMap.new();
|
|
216
|
+
json2.map.forEach(({ k, v }) => {
|
|
217
|
+
m.set(convert(k), convert(v));
|
|
218
|
+
});
|
|
219
|
+
return CML.PlutusData.new_map(m);
|
|
220
|
+
} else if (json2.map && typeof json2.map === "function") {
|
|
221
|
+
const l = CML.PlutusDataList.new();
|
|
222
|
+
Object.values(json2).forEach((value) => {
|
|
223
|
+
l.add(convert(value));
|
|
224
|
+
});
|
|
225
|
+
return CML.PlutusData.new_list(l);
|
|
226
|
+
} else if (!isNaN(json2.constructor)) {
|
|
227
|
+
const l = CML.PlutusDataList.new();
|
|
228
|
+
json2.fields.forEach((v) => {
|
|
229
|
+
l.add(convert(v));
|
|
230
|
+
});
|
|
231
|
+
const bigInt = CML.BigInteger.from_str(
|
|
232
|
+
json2.constructor.toString()
|
|
233
|
+
).as_u64();
|
|
234
|
+
return CML.PlutusData.new_constr_plutus_data(
|
|
235
|
+
CML.ConstrPlutusData.new(bigInt, l)
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
throw new Error("Unsupported type");
|
|
239
|
+
};
|
|
240
|
+
return convert(json).to_cbor_hex();
|
|
241
|
+
}
|
|
200
242
|
|
|
201
243
|
// src/scripts.ts
|
|
202
244
|
var import_plutus = require("@lucid-evolution/plutus");
|
|
@@ -1506,6 +1548,7 @@ var stringify = (data) => JSON.stringify(
|
|
|
1506
1548
|
createCostModels,
|
|
1507
1549
|
credentialToAddress,
|
|
1508
1550
|
credentialToRewardAddress,
|
|
1551
|
+
datumJsonToCbor,
|
|
1509
1552
|
datumToHash,
|
|
1510
1553
|
fromLabel,
|
|
1511
1554
|
fromScriptRef,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _effect_schema_AST from '@effect/schema/AST';
|
|
2
|
-
import { Native, Script, Network, Credential, RewardAddress, CertificateValidator, WithdrawalValidator, AddressDetails, CostModels, ProtocolParameters, Address, ScriptHash, KeyHash,
|
|
2
|
+
import { Native, Script, Network, Credential, RewardAddress, CertificateValidator, WithdrawalValidator, AddressDetails, DatumJson, Datum, CostModels, ProtocolParameters, Address, ScriptHash, KeyHash, DatumHash, PrivateKey, PublicKey, SpendingValidator, Validator, MintingPolicy, PolicyId, Exact, UnixTime, Slot, UTxO, OutRef, TxOutput, Assets, Unit } from '@lucid-evolution/core-types';
|
|
3
3
|
import * as CML from '@anastasia-labs/cardano-multiplatform-lib-nodejs';
|
|
4
4
|
import { Data } from '@lucid-evolution/plutus';
|
|
5
5
|
|
|
@@ -66,6 +66,7 @@ declare function validatorToRewardAddress(network: Network, validator: Certifica
|
|
|
66
66
|
declare function getAddressDetails(address: string): AddressDetails;
|
|
67
67
|
|
|
68
68
|
declare const applyDoubleCborEncoding: (script: string) => string;
|
|
69
|
+
declare function datumJsonToCbor(json: DatumJson): Datum;
|
|
69
70
|
|
|
70
71
|
declare function createCostModels(costModels: CostModels): CML.CostModels;
|
|
71
72
|
declare const PROTOCOL_PARAMETERS_DEFAULT: ProtocolParameters;
|
|
@@ -184,4 +185,4 @@ declare function getUniqueTokenName(utxo: UTxO): Promise<string>;
|
|
|
184
185
|
|
|
185
186
|
declare const stringify: (data: any) => string;
|
|
186
187
|
|
|
187
|
-
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 };
|
|
188
|
+
export { type CMLNative, PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, calculateMinLovelaceFromUTxO, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumJsonToCbor, 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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _effect_schema_AST from '@effect/schema/AST';
|
|
2
|
-
import { Native, Script, Network, Credential, RewardAddress, CertificateValidator, WithdrawalValidator, AddressDetails, CostModels, ProtocolParameters, Address, ScriptHash, KeyHash,
|
|
2
|
+
import { Native, Script, Network, Credential, RewardAddress, CertificateValidator, WithdrawalValidator, AddressDetails, DatumJson, Datum, CostModels, ProtocolParameters, Address, ScriptHash, KeyHash, DatumHash, PrivateKey, PublicKey, SpendingValidator, Validator, MintingPolicy, PolicyId, Exact, UnixTime, Slot, UTxO, OutRef, TxOutput, Assets, Unit } from '@lucid-evolution/core-types';
|
|
3
3
|
import * as CML from '@anastasia-labs/cardano-multiplatform-lib-nodejs';
|
|
4
4
|
import { Data } from '@lucid-evolution/plutus';
|
|
5
5
|
|
|
@@ -66,6 +66,7 @@ declare function validatorToRewardAddress(network: Network, validator: Certifica
|
|
|
66
66
|
declare function getAddressDetails(address: string): AddressDetails;
|
|
67
67
|
|
|
68
68
|
declare const applyDoubleCborEncoding: (script: string) => string;
|
|
69
|
+
declare function datumJsonToCbor(json: DatumJson): Datum;
|
|
69
70
|
|
|
70
71
|
declare function createCostModels(costModels: CostModels): CML.CostModels;
|
|
71
72
|
declare const PROTOCOL_PARAMETERS_DEFAULT: ProtocolParameters;
|
|
@@ -184,4 +185,4 @@ declare function getUniqueTokenName(utxo: UTxO): Promise<string>;
|
|
|
184
185
|
|
|
185
186
|
declare const stringify: (data: any) => string;
|
|
186
187
|
|
|
187
|
-
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 };
|
|
188
|
+
export { type CMLNative, PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, calculateMinLovelaceFromUTxO, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumJsonToCbor, 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
|
@@ -109,6 +109,47 @@ var applyDoubleCborEncoding = (script) => {
|
|
|
109
109
|
return toHex(encode(fromHex(script)));
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
|
+
function datumJsonToCbor(json) {
|
|
113
|
+
const convert = (json2) => {
|
|
114
|
+
if (!isNaN(json2.int)) {
|
|
115
|
+
const plutusBigInt = CML.BigInteger.from_str(json2.int.toString());
|
|
116
|
+
return CML.PlutusData.new_integer(plutusBigInt);
|
|
117
|
+
} else if (json2.bytes || !isNaN(Number(json2.bytes))) {
|
|
118
|
+
return CML.PlutusData.new_bytes(fromHex(json2.bytes));
|
|
119
|
+
} else if (json2.list) {
|
|
120
|
+
const l = CML.PlutusDataList.new();
|
|
121
|
+
json2.list.forEach((v) => {
|
|
122
|
+
l.add(convert(v));
|
|
123
|
+
});
|
|
124
|
+
return CML.PlutusData.new_list(l);
|
|
125
|
+
} else if (json2.map && json2.map.length > 0 && typeof json2.map[0] === "object") {
|
|
126
|
+
const m = CML.PlutusMap.new();
|
|
127
|
+
json2.map.forEach(({ k, v }) => {
|
|
128
|
+
m.set(convert(k), convert(v));
|
|
129
|
+
});
|
|
130
|
+
return CML.PlutusData.new_map(m);
|
|
131
|
+
} else if (json2.map && typeof json2.map === "function") {
|
|
132
|
+
const l = CML.PlutusDataList.new();
|
|
133
|
+
Object.values(json2).forEach((value) => {
|
|
134
|
+
l.add(convert(value));
|
|
135
|
+
});
|
|
136
|
+
return CML.PlutusData.new_list(l);
|
|
137
|
+
} else if (!isNaN(json2.constructor)) {
|
|
138
|
+
const l = CML.PlutusDataList.new();
|
|
139
|
+
json2.fields.forEach((v) => {
|
|
140
|
+
l.add(convert(v));
|
|
141
|
+
});
|
|
142
|
+
const bigInt = CML.BigInteger.from_str(
|
|
143
|
+
json2.constructor.toString()
|
|
144
|
+
).as_u64();
|
|
145
|
+
return CML.PlutusData.new_constr_plutus_data(
|
|
146
|
+
CML.ConstrPlutusData.new(bigInt, l)
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
throw new Error("Unsupported type");
|
|
150
|
+
};
|
|
151
|
+
return convert(json).to_cbor_hex();
|
|
152
|
+
}
|
|
112
153
|
|
|
113
154
|
// src/scripts.ts
|
|
114
155
|
import { Data } from "@lucid-evolution/plutus";
|
|
@@ -1427,6 +1468,7 @@ export {
|
|
|
1427
1468
|
createCostModels,
|
|
1428
1469
|
credentialToAddress,
|
|
1429
1470
|
credentialToRewardAddress,
|
|
1471
|
+
datumJsonToCbor,
|
|
1430
1472
|
datumToHash,
|
|
1431
1473
|
fromLabel,
|
|
1432
1474
|
fromScriptRef,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucid-evolution/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.37",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"bip39": "^3.1.0",
|
|
37
37
|
"cborg": "^4.2.0",
|
|
38
38
|
"effect": "^3.1.2",
|
|
39
|
-
"@lucid-evolution/core-types": "0.1.
|
|
39
|
+
"@lucid-evolution/core-types": "0.1.15",
|
|
40
40
|
"@lucid-evolution/core-utils": "0.1.13",
|
|
41
41
|
"@lucid-evolution/crc8": "0.1.8",
|
|
42
|
-
"@lucid-evolution/plutus": "0.1.
|
|
42
|
+
"@lucid-evolution/plutus": "0.1.21",
|
|
43
43
|
"@lucid-evolution/uplc": "0.2.11"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|