@lucid-evolution/utils 0.1.75 → 0.2.0
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 +414 -107
- package/dist/index.d.cts +55 -2
- package/dist/index.d.ts +55 -2
- package/dist/index.js +412 -107
- package/package.json +6 -8
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _effect_schema_AST from '@effect/schema/AST';
|
|
2
2
|
import { Script, Native, Network, Credential, RewardAddress, AddressDetails, CertificateValidator, WithdrawalValidator, DatumJson, Datum, ProtocolParameters, CostModels, Address, KeyHash, ScriptHash, DatumHash, PrivateKey, PublicKey, Exact, MintingPolicy, PolicyId, SpendingValidator, Validator, Slot, UnixTime, UTxO, OutRef, TxOutput, Assets, Unit, RedeemerTag } from '@lucid-evolution/core-types';
|
|
3
|
-
import * as CML from '@
|
|
3
|
+
import * as CML from '@lucid-evolution/cml';
|
|
4
4
|
import { Data } from '@lucid-evolution/plutus';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -93,6 +93,12 @@ declare function networkToId(network: Network): number;
|
|
|
93
93
|
|
|
94
94
|
declare function validatorToAddress(network: Network, validator: SpendingValidator, stakeCredential?: Credential): Address;
|
|
95
95
|
declare function validatorToScriptHash(validator: Validator): ScriptHash;
|
|
96
|
+
/**
|
|
97
|
+
* The script's CBOR as CML reads it: the double CBOR encoded script
|
|
98
|
+
* (`applyDoubleCborEncoding`) for Plutus scripts, the script itself for native
|
|
99
|
+
* scripts. Returns a fresh copy.
|
|
100
|
+
*/
|
|
101
|
+
declare function scriptCborBytes(script: Script): Uint8Array;
|
|
96
102
|
declare function toScriptRef(script: Script): CML.Script;
|
|
97
103
|
declare function fromScriptRef(scriptRef: CML.Script): Script;
|
|
98
104
|
declare function mintingPolicyToId(mintingPolicy: MintingPolicy): PolicyId;
|
|
@@ -103,6 +109,49 @@ declare function mintingPolicyToId(mintingPolicy: MintingPolicy): PolicyId;
|
|
|
103
109
|
*/
|
|
104
110
|
declare function applyParamsToScript<T extends unknown[] = Data[]>(plutusScript: string, params: Exact<[...T]>, type?: T): string;
|
|
105
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Bounded memo tables keyed by script text.
|
|
114
|
+
*
|
|
115
|
+
* Script hex strings are long (a typical Plutus validator is 10-40k hex
|
|
116
|
+
* characters). V8 hashes a string longer than 16383 characters by its length
|
|
117
|
+
* alone, so a `Map` keyed by the script text puts every script of the same
|
|
118
|
+
* length in one hash bucket and a lookup can compare tens of kilobytes per
|
|
119
|
+
* entry. Parameterized validators make that common: every instance has the
|
|
120
|
+
* same length and differs only near the end. The tables here hash a short
|
|
121
|
+
* fingerprint of the script instead and confirm a hit by comparing the full
|
|
122
|
+
* text, keeping at most `MAX_CHAIN` scripts per fingerprint.
|
|
123
|
+
*
|
|
124
|
+
* Store only immutable values: strings, or byte arrays that are never handed
|
|
125
|
+
* to callers (return copies). Never store CML objects. Eviction is first-in
|
|
126
|
+
* first-out.
|
|
127
|
+
*/
|
|
128
|
+
/** A bounded memo table keyed by a namespace (such as the script type) and script text. */
|
|
129
|
+
declare class ScriptCache<V> {
|
|
130
|
+
private readonly capacity;
|
|
131
|
+
private readonly maxWeight;
|
|
132
|
+
private readonly weigh;
|
|
133
|
+
private readonly buckets;
|
|
134
|
+
/** Insertion order, for first-in first-out eviction. */
|
|
135
|
+
private readonly order;
|
|
136
|
+
private totalWeight;
|
|
137
|
+
/**
|
|
138
|
+
* @param capacity maximum number of entries
|
|
139
|
+
* @param maxWeight maximum total weight, see `weigh`
|
|
140
|
+
* @param weigh approximate retained bytes of an entry besides its key
|
|
141
|
+
*/
|
|
142
|
+
constructor(capacity: number, maxWeight: number, weigh?: (value: V) => number);
|
|
143
|
+
get size(): number;
|
|
144
|
+
get(namespace: string, script: string): V | undefined;
|
|
145
|
+
set(namespace: string, script: string, value: V): void;
|
|
146
|
+
clear(): void;
|
|
147
|
+
private remove;
|
|
148
|
+
/**
|
|
149
|
+
* Returns the cached value, or computes, stores and returns it. A `compute`
|
|
150
|
+
* that throws stores nothing.
|
|
151
|
+
*/
|
|
152
|
+
getOrCompute(namespace: string, script: string, compute: () => V): V;
|
|
153
|
+
}
|
|
154
|
+
|
|
106
155
|
/**
|
|
107
156
|
* Converts unix time to slot based on the network. For "Custom" network
|
|
108
157
|
* it is advisable use `unixTimeToSlot` method from `LucidEvolution`
|
|
@@ -115,6 +164,10 @@ declare function applyParamsToScript<T extends unknown[] = Data[]>(plutusScript:
|
|
|
115
164
|
declare function unixTimeToSlot(network: Network, unixTime: UnixTime): Slot;
|
|
116
165
|
declare function slotToUnixTime(network: Network, slot: Slot): UnixTime;
|
|
117
166
|
|
|
167
|
+
/**
|
|
168
|
+
* Builds the output directly rather than through `TransactionOutputBuilder`,
|
|
169
|
+
* whose every stage copies the datum and script; the result is the same.
|
|
170
|
+
*/
|
|
118
171
|
declare const utxoToTransactionOutput: (utxo: UTxO) => CML.TransactionOutput;
|
|
119
172
|
declare const utxoToTransactionInput: (utxo: UTxO) => CML.TransactionInput;
|
|
120
173
|
declare const utxoToCore: (utxo: UTxO) => CML.TransactionUnspentOutput;
|
|
@@ -205,4 +258,4 @@ declare const stringify: (data: any) => string;
|
|
|
205
258
|
declare const toCMLRedeemerTag: (tag: string) => CML.RedeemerTag;
|
|
206
259
|
declare const fromCMLRedeemerTag: (tag: CML.RedeemerTag) => RedeemerTag;
|
|
207
260
|
|
|
208
|
-
export { CBOREncodingLevel, type CMLNative, PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, applySingleCborEncoding, assetsToValue, calculateMinLovelaceFromUTxO, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumJsonToCbor, datumToHash, drepIDToCredential, fromCMLRedeemerTag, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, getInputIndices, getUniqueTokenName, isEqualUTxO, keyHashToCredential, mintingPolicyToId, networkToId, parseCMLNative, paymentCredentialOf, scriptFromCMLNative, scriptFromNative, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortCanonical, sortUTxOs, stakeCredentialOf, stringify, toCMLNativeScript, toCMLRedeemerTag, toLabel, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
|
|
261
|
+
export { CBOREncodingLevel, type CMLNative, PROTOCOL_PARAMETERS_DEFAULT, ScriptCache, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, applySingleCborEncoding, assetsToValue, calculateMinLovelaceFromUTxO, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumJsonToCbor, datumToHash, drepIDToCredential, fromCMLRedeemerTag, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, getInputIndices, getUniqueTokenName, isEqualUTxO, keyHashToCredential, mintingPolicyToId, networkToId, parseCMLNative, paymentCredentialOf, scriptCborBytes, scriptFromCMLNative, scriptFromNative, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortCanonical, sortUTxOs, stakeCredentialOf, stringify, toCMLNativeScript, toCMLRedeemerTag, toLabel, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _effect_schema_AST from '@effect/schema/AST';
|
|
2
2
|
import { Script, Native, Network, Credential, RewardAddress, AddressDetails, CertificateValidator, WithdrawalValidator, DatumJson, Datum, ProtocolParameters, CostModels, Address, KeyHash, ScriptHash, DatumHash, PrivateKey, PublicKey, Exact, MintingPolicy, PolicyId, SpendingValidator, Validator, Slot, UnixTime, UTxO, OutRef, TxOutput, Assets, Unit, RedeemerTag } from '@lucid-evolution/core-types';
|
|
3
|
-
import * as CML from '@
|
|
3
|
+
import * as CML from '@lucid-evolution/cml';
|
|
4
4
|
import { Data } from '@lucid-evolution/plutus';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -93,6 +93,12 @@ declare function networkToId(network: Network): number;
|
|
|
93
93
|
|
|
94
94
|
declare function validatorToAddress(network: Network, validator: SpendingValidator, stakeCredential?: Credential): Address;
|
|
95
95
|
declare function validatorToScriptHash(validator: Validator): ScriptHash;
|
|
96
|
+
/**
|
|
97
|
+
* The script's CBOR as CML reads it: the double CBOR encoded script
|
|
98
|
+
* (`applyDoubleCborEncoding`) for Plutus scripts, the script itself for native
|
|
99
|
+
* scripts. Returns a fresh copy.
|
|
100
|
+
*/
|
|
101
|
+
declare function scriptCborBytes(script: Script): Uint8Array;
|
|
96
102
|
declare function toScriptRef(script: Script): CML.Script;
|
|
97
103
|
declare function fromScriptRef(scriptRef: CML.Script): Script;
|
|
98
104
|
declare function mintingPolicyToId(mintingPolicy: MintingPolicy): PolicyId;
|
|
@@ -103,6 +109,49 @@ declare function mintingPolicyToId(mintingPolicy: MintingPolicy): PolicyId;
|
|
|
103
109
|
*/
|
|
104
110
|
declare function applyParamsToScript<T extends unknown[] = Data[]>(plutusScript: string, params: Exact<[...T]>, type?: T): string;
|
|
105
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Bounded memo tables keyed by script text.
|
|
114
|
+
*
|
|
115
|
+
* Script hex strings are long (a typical Plutus validator is 10-40k hex
|
|
116
|
+
* characters). V8 hashes a string longer than 16383 characters by its length
|
|
117
|
+
* alone, so a `Map` keyed by the script text puts every script of the same
|
|
118
|
+
* length in one hash bucket and a lookup can compare tens of kilobytes per
|
|
119
|
+
* entry. Parameterized validators make that common: every instance has the
|
|
120
|
+
* same length and differs only near the end. The tables here hash a short
|
|
121
|
+
* fingerprint of the script instead and confirm a hit by comparing the full
|
|
122
|
+
* text, keeping at most `MAX_CHAIN` scripts per fingerprint.
|
|
123
|
+
*
|
|
124
|
+
* Store only immutable values: strings, or byte arrays that are never handed
|
|
125
|
+
* to callers (return copies). Never store CML objects. Eviction is first-in
|
|
126
|
+
* first-out.
|
|
127
|
+
*/
|
|
128
|
+
/** A bounded memo table keyed by a namespace (such as the script type) and script text. */
|
|
129
|
+
declare class ScriptCache<V> {
|
|
130
|
+
private readonly capacity;
|
|
131
|
+
private readonly maxWeight;
|
|
132
|
+
private readonly weigh;
|
|
133
|
+
private readonly buckets;
|
|
134
|
+
/** Insertion order, for first-in first-out eviction. */
|
|
135
|
+
private readonly order;
|
|
136
|
+
private totalWeight;
|
|
137
|
+
/**
|
|
138
|
+
* @param capacity maximum number of entries
|
|
139
|
+
* @param maxWeight maximum total weight, see `weigh`
|
|
140
|
+
* @param weigh approximate retained bytes of an entry besides its key
|
|
141
|
+
*/
|
|
142
|
+
constructor(capacity: number, maxWeight: number, weigh?: (value: V) => number);
|
|
143
|
+
get size(): number;
|
|
144
|
+
get(namespace: string, script: string): V | undefined;
|
|
145
|
+
set(namespace: string, script: string, value: V): void;
|
|
146
|
+
clear(): void;
|
|
147
|
+
private remove;
|
|
148
|
+
/**
|
|
149
|
+
* Returns the cached value, or computes, stores and returns it. A `compute`
|
|
150
|
+
* that throws stores nothing.
|
|
151
|
+
*/
|
|
152
|
+
getOrCompute(namespace: string, script: string, compute: () => V): V;
|
|
153
|
+
}
|
|
154
|
+
|
|
106
155
|
/**
|
|
107
156
|
* Converts unix time to slot based on the network. For "Custom" network
|
|
108
157
|
* it is advisable use `unixTimeToSlot` method from `LucidEvolution`
|
|
@@ -115,6 +164,10 @@ declare function applyParamsToScript<T extends unknown[] = Data[]>(plutusScript:
|
|
|
115
164
|
declare function unixTimeToSlot(network: Network, unixTime: UnixTime): Slot;
|
|
116
165
|
declare function slotToUnixTime(network: Network, slot: Slot): UnixTime;
|
|
117
166
|
|
|
167
|
+
/**
|
|
168
|
+
* Builds the output directly rather than through `TransactionOutputBuilder`,
|
|
169
|
+
* whose every stage copies the datum and script; the result is the same.
|
|
170
|
+
*/
|
|
118
171
|
declare const utxoToTransactionOutput: (utxo: UTxO) => CML.TransactionOutput;
|
|
119
172
|
declare const utxoToTransactionInput: (utxo: UTxO) => CML.TransactionInput;
|
|
120
173
|
declare const utxoToCore: (utxo: UTxO) => CML.TransactionUnspentOutput;
|
|
@@ -205,4 +258,4 @@ declare const stringify: (data: any) => string;
|
|
|
205
258
|
declare const toCMLRedeemerTag: (tag: string) => CML.RedeemerTag;
|
|
206
259
|
declare const fromCMLRedeemerTag: (tag: CML.RedeemerTag) => RedeemerTag;
|
|
207
260
|
|
|
208
|
-
export { CBOREncodingLevel, type CMLNative, PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, applySingleCborEncoding, assetsToValue, calculateMinLovelaceFromUTxO, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumJsonToCbor, datumToHash, drepIDToCredential, fromCMLRedeemerTag, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, getInputIndices, getUniqueTokenName, isEqualUTxO, keyHashToCredential, mintingPolicyToId, networkToId, parseCMLNative, paymentCredentialOf, scriptFromCMLNative, scriptFromNative, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortCanonical, sortUTxOs, stakeCredentialOf, stringify, toCMLNativeScript, toCMLRedeemerTag, toLabel, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
|
|
261
|
+
export { CBOREncodingLevel, type CMLNative, PROTOCOL_PARAMETERS_DEFAULT, ScriptCache, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, applySingleCborEncoding, assetsToValue, calculateMinLovelaceFromUTxO, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumJsonToCbor, datumToHash, drepIDToCredential, fromCMLRedeemerTag, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, getInputIndices, getUniqueTokenName, isEqualUTxO, keyHashToCredential, mintingPolicyToId, networkToId, parseCMLNative, paymentCredentialOf, scriptCborBytes, scriptFromCMLNative, scriptFromNative, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortCanonical, sortUTxOs, stakeCredentialOf, stringify, toCMLNativeScript, toCMLRedeemerTag, toLabel, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
|