@meshsdk/core 1.5.8 → 1.5.10

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.
@@ -5,6 +5,8 @@ export declare class BlockfrostProvider implements IFetcher, IListener, ISubmitt
5
5
  constructor(baseUrl: string);
6
6
  constructor(projectId: string, version?: number);
7
7
  fetchAccountInfo(address: string): Promise<AccountInfo>;
8
+ private resolveScriptRef;
9
+ private toUTxO;
8
10
  fetchAddressUTxOs(address: string, asset?: string): Promise<UTxO[]>;
9
11
  fetchAssetAddresses(asset: string): Promise<{
10
12
  address: string;
@@ -19,6 +21,7 @@ export declare class BlockfrostProvider implements IFetcher, IListener, ISubmitt
19
21
  fetchHandleAddress(handle: string): Promise<string>;
20
22
  fetchProtocolParameters(epoch?: number): Promise<Protocol>;
21
23
  fetchTxInfo(hash: string): Promise<TransactionInfo>;
24
+ fetchUTxOs(hash: string): Promise<UTxO[]>;
22
25
  onTxConfirmed(txHash: string, callback: () => void, limit?: number): void;
23
26
  submitTx(tx: string): Promise<string>;
24
27
  private fetchPlutusScriptCBOR;
@@ -3,7 +3,7 @@ import type { AccountInfo, Asset, AssetMetadata, BlockInfo, Protocol, Transactio
3
3
  export declare class KoiosProvider implements IFetcher, IListener, ISubmitter {
4
4
  private readonly _axiosInstance;
5
5
  constructor(baseUrl: string);
6
- constructor(network: 'api' | 'preview' | 'preprod' | 'guild', version?: number);
6
+ constructor(network: 'api' | 'preview' | 'preprod' | 'guild', token: string, version?: number);
7
7
  fetchAccountInfo(address: string): Promise<AccountInfo>;
8
8
  fetchAddressUTxOs(address: string, asset?: string): Promise<UTxO[]>;
9
9
  fetchAssetAddresses(asset: string): Promise<{
@@ -19,6 +19,9 @@ export declare class KoiosProvider implements IFetcher, IListener, ISubmitter {
19
19
  fetchHandleAddress(handle: string): Promise<string>;
20
20
  fetchProtocolParameters(epoch: number): Promise<Protocol>;
21
21
  fetchTxInfo(hash: string): Promise<TransactionInfo>;
22
+ fetchUTxOs(hash: string): Promise<UTxO[]>;
22
23
  onTxConfirmed(txHash: string, callback: () => void, limit?: number): void;
23
24
  submitTx(tx: string): Promise<string>;
25
+ private toUTxO;
26
+ private resolveScriptRef;
24
27
  }
@@ -1,15 +1,17 @@
1
- import { IFetcher, ISubmitter } from '@mesh/common/contracts';
2
- import type { AccountInfo, Asset, AssetMetadata, BlockInfo, Protocol, TransactionInfo, UTxO } from '@mesh/common/types';
1
+ import { IEvaluator, IFetcher, ISubmitter } from '@mesh/common/contracts';
2
+ import type { AccountInfo, Action, Asset, AssetMetadata, BlockInfo, Protocol, TransactionInfo, UTxO } from '@mesh/common/types';
3
3
  export declare type MaestroSupportedNetworks = 'Mainnet' | 'Preprod' | 'Preview';
4
4
  export interface MaestroConfig {
5
5
  network: MaestroSupportedNetworks;
6
6
  apiKey: string;
7
7
  turboSubmit?: boolean;
8
8
  }
9
- export declare class MaestroProvider implements IFetcher, ISubmitter {
9
+ export declare class MaestroProvider implements IFetcher, ISubmitter, IEvaluator {
10
10
  private readonly _axiosInstance;
11
+ private readonly _amountsAsStrings;
11
12
  submitUrl: string;
12
13
  constructor({ network, apiKey, turboSubmit }: MaestroConfig);
14
+ evaluateTx(cbor: string): Promise<Omit<Action, 'data'>[]>;
13
15
  fetchAccountInfo(address: string): Promise<AccountInfo>;
14
16
  fetchAddressUTxOs(address: string, asset?: string): Promise<UTxO[]>;
15
17
  fetchAssetAddresses(asset: string): Promise<{
@@ -25,6 +27,9 @@ export declare class MaestroProvider implements IFetcher, ISubmitter {
25
27
  fetchHandleAddress(handle: string): Promise<string>;
26
28
  fetchProtocolParameters(epoch?: number): Promise<Protocol>;
27
29
  fetchTxInfo(hash: string): Promise<TransactionInfo>;
30
+ fetchUTxOs(hash: string): Promise<UTxO[]>;
28
31
  onTxConfirmed(txHash: string, callback: () => void, limit?: number): void;
29
32
  submitTx(tx: string): Promise<string>;
33
+ private toUTxO;
34
+ private resolveScript;
30
35
  }
@@ -19,6 +19,7 @@ export declare class TangoProvider implements IEvaluator, IFetcher, IListener, I
19
19
  fetchHandleAddress(handle: string): Promise<string>;
20
20
  fetchProtocolParameters(epoch: number): Promise<Protocol>;
21
21
  fetchTxInfo(hash: string): Promise<TransactionInfo>;
22
+ fetchUTxOs(hash: string): Promise<UTxO[]>;
22
23
  onTxConfirmed(txHash: string, callback: () => void, limit?: number): void;
23
24
  submitTx(tx: string): Promise<string>;
24
25
  }
@@ -1 +1,2 @@
1
1
  export * from './transaction.service';
2
+ export * from './meshTxBuilder';
@@ -0,0 +1 @@
1
+ export * from './meshTxBuilder.service';
@@ -0,0 +1,44 @@
1
+ import { IEvaluator, IFetcher, ISubmitter } from '@mesh/common/contracts';
2
+ import { MeshTxBuilderCore } from './meshTxBuilderCore';
3
+ import { MeshTxBuilderBody } from './type';
4
+ declare type MeshTxBuilderOptions = {
5
+ fetcher?: IFetcher;
6
+ submitter?: ISubmitter;
7
+ evaluator?: IEvaluator;
8
+ isHydra?: boolean;
9
+ };
10
+ /**
11
+ * MeshTxBuilder is a lower level api for building transaction
12
+ * @param {IFetcher} [fetcher] an optional parameter for fetching utxo
13
+ * @param {ISubmitter} [submitter] an optional parameter for submitting transaction
14
+ * @param {IEvaluator} [evaluator] an optional parameter for evaluating transaction
15
+ * @param {boolean} [isHydra] an optional parameter for using hydra transaction building for configuring 0 fee in protocol parameters
16
+ */
17
+ export declare class MeshTxBuilder extends MeshTxBuilderCore {
18
+ private _fetcher?;
19
+ private _submitter?;
20
+ private _evaluator?;
21
+ private queriedTxHashes;
22
+ private queriedUTxOs;
23
+ constructor({ fetcher, submitter, evaluator, isHydra, }: MeshTxBuilderOptions);
24
+ /**
25
+ * It builds the transaction and query the blockchain for missing information
26
+ * @param customizedTx The optional customized transaction body
27
+ * @returns The signed transaction in hex ready to submit / signed by client
28
+ */
29
+ complete: (customizedTx?: MeshTxBuilderBody) => Promise<this>;
30
+ /**
31
+ * Submit transactions to the blockchain using the fetcher instance
32
+ * @param txHex The signed transaction in hex
33
+ * @returns
34
+ */
35
+ submitTx: (txHex: string) => Promise<string | undefined>;
36
+ /**
37
+ * Get the UTxO information from the blockchain
38
+ * @param TxHash The TxIn object that contains the txHash and txIndex, while missing amount and address information
39
+ */
40
+ private getUTxOInfo;
41
+ private queryAllTxInfo;
42
+ private completeTxInformation;
43
+ }
44
+ export {};
@@ -0,0 +1,239 @@
1
+ import { Action, Asset, Budget, Data, Protocol } from '@mesh/common/types';
2
+ import { csl } from '@mesh/core';
3
+ import { MintItem, TxIn, PubKeyTxIn, MeshTxBuilderBody, RefTxIn } from './type';
4
+ export declare class MeshTxBuilderCore {
5
+ txHex: string;
6
+ txBuilder: csl.TransactionBuilder;
7
+ private _protocolParams;
8
+ private txOutput?;
9
+ private addingScriptInput;
10
+ private addingPlutusMint;
11
+ protected isHydra: boolean;
12
+ meshTxBuilderBody: MeshTxBuilderBody;
13
+ protected mintItem?: MintItem;
14
+ protected txInQueueItem?: TxIn;
15
+ protected collateralQueueItem?: PubKeyTxIn;
16
+ protected refScriptTxInQueueItem?: RefTxIn;
17
+ /**
18
+ * Synchronous functions here
19
+ */
20
+ /**
21
+ * It builds the transaction without dependencies
22
+ * @param customizedTx The optional customized transaction body
23
+ * @returns The signed transaction in hex ready to submit / signed by client
24
+ */
25
+ completeSync: (customizedTx?: MeshTxBuilderBody) => this;
26
+ /**
27
+ * Complete the signing process
28
+ * @returns The signed transaction in hex
29
+ */
30
+ completeSigning: () => string;
31
+ serializeTxBody: (txBody: MeshTxBuilderBody) => this;
32
+ /**
33
+ * Set the input for transaction
34
+ * @param txHash The transaction hash of the input UTxO
35
+ * @param txIndex The transaction index of the input UTxO
36
+ * @param amount The asset amount of index of the input UTxO
37
+ * @param address The address of the input UTxO
38
+ * @returns The MeshTxBuilder instance
39
+ */
40
+ txIn: (txHash: string, txIndex: number, amount?: Asset[], address?: string) => this;
41
+ /**
42
+ * Set the script for transaction input
43
+ * @param {string} scriptCbor The CborHex of the script
44
+ * @returns The MeshTxBuilder instance
45
+ */
46
+ txInScript: (scriptCbor: string) => void;
47
+ /**
48
+ * Set the input datum for transaction input
49
+ * @param {Data} datum The datum in object format
50
+ * @returns The MeshTxBuilder instance
51
+ */
52
+ txInDatumValue: (datum: Data) => this;
53
+ /**
54
+ * Tell the transaction builder that the input UTxO has inlined datum
55
+ * @returns The MeshTxBuilder instance
56
+ */
57
+ txInInlineDatumPresent: () => this;
58
+ /**
59
+ * Set the redeemer for the reference input to be spent in same transaction
60
+ * @param redeemer The redeemer in object format
61
+ * @param exUnits The execution units budget for the redeemer
62
+ * @returns The MeshTxBuilder instance
63
+ */
64
+ txInRedeemerValue: (redeemer: Data, exUnits?: Budget) => this;
65
+ /**
66
+ * Set the output for transaction
67
+ * @param {string} address The recipient of the output
68
+ * @param {Asset[]} amount The amount of other native assets attached with UTxO
69
+ * @returns The MeshTxBuilder instance
70
+ */
71
+ txOut: (address: string, amount: Asset[]) => this;
72
+ /**
73
+ * Set the output datum hash for transaction
74
+ * @param {Data} datum The datum in object format
75
+ * @returns The MeshTxBuilder instance
76
+ */
77
+ txOutDatumHashValue: (datum: Data) => this;
78
+ /**
79
+ * Set the output inline datum for transaction
80
+ * @param {Data} datum The datum in object format
81
+ * @returns The MeshTxBuilder instance
82
+ */
83
+ txOutInlineDatumValue: (datum: Data) => this;
84
+ /**
85
+ * Set the reference script to be attached with the output
86
+ * @param scriptCbor The CBOR hex of the script to be attached to UTxO as reference script
87
+ * @returns The MeshTxBuilder instance
88
+ */
89
+ txOutReferenceScript: (scriptCbor: string) => this;
90
+ /**
91
+ * Set the instruction that it is currently using V2 Plutus spending scripts
92
+ * @returns The MeshTxBuilder instance
93
+ */
94
+ spendingPlutusScriptV2: () => this;
95
+ /**
96
+ * Set the reference input where it would also be spent in the transaction
97
+ * @param txHash The transaction hash of the reference UTxO
98
+ * @param txIndex The transaction index of the reference UTxO
99
+ * @param spendingScriptHash The script hash of the spending script
100
+ * @returns The MeshTxBuilder instance
101
+ */
102
+ spendingTxInReference: (txHash: string, txIndex: number, spendingScriptHash?: string) => this;
103
+ /**
104
+ * [Alias of txInInlineDatumPresent] Set the instruction that the reference input has inline datum
105
+ * @returns The MeshTxBuilder instance
106
+ */
107
+ spendingReferenceTxInInlineDatumPresent: () => this;
108
+ /**
109
+ * [Alias of txInRedeemerValue] Set the redeemer for the reference input to be spent in same transaction
110
+ * @param redeemer The redeemer in object format
111
+ * @param exUnits The execution units budget for the redeemer
112
+ * @returns The MeshTxBuilder instance
113
+ */
114
+ spendingReferenceTxInRedeemerValue: (redeemer: Data, exUnits?: Budget) => this;
115
+ /**
116
+ * Specify a read only reference input. This reference input is not witnessing anything it is simply provided in the plutus script context.
117
+ * @param txHash The transaction hash of the reference UTxO
118
+ * @param txIndex The transaction index of the reference UTxO
119
+ * @returns The MeshTxBuilder instance
120
+ */
121
+ readOnlyTxInReference: (txHash: string, txIndex: number) => this;
122
+ /**
123
+ * Set the instruction that it is currently using V2 Plutus minting scripts
124
+ * @returns The MeshTxBuilder instance
125
+ */
126
+ mintPlutusScriptV2: () => this;
127
+ /**
128
+ * Set the minting value of transaction
129
+ * @param quantity The quantity of asset to be minted
130
+ * @param policy The policy id of the asset to be minted
131
+ * @param name The hex of token name of the asset to be minted
132
+ * @returns The MeshTxBuilder instance
133
+ */
134
+ mint: (quantity: number, policy: string, name: string) => this;
135
+ /**
136
+ * Set the minting script of current mint
137
+ * @param scriptCBOR The CBOR hex of the minting policy script
138
+ * @returns The MeshTxBuilder instance
139
+ */
140
+ mintingScript: (scriptCBOR: string) => this;
141
+ /**
142
+ * Use reference script for minting
143
+ * @param txHash The transaction hash of the UTxO
144
+ * @param txIndex The transaction index of the UTxO
145
+ * @returns The MeshTxBuilder instance
146
+ */
147
+ mintTxInReference: (txHash: string, txIndex: number) => this;
148
+ /**
149
+ * Set the redeemer for minting
150
+ * @param redeemer The redeemer in object format
151
+ * @param exUnits The execution units budget for the redeemer
152
+ * @returns The MeshTxBuilder instance
153
+ */
154
+ mintReferenceTxInRedeemerValue: (redeemer: Data, exUnits?: Budget) => this;
155
+ /**
156
+ * Set the redeemer for the reference input to be spent in same transaction
157
+ * @param redeemer The redeemer in object format
158
+ * @param exUnits The execution units budget for the redeemer
159
+ * @returns The MeshTxBuilder instance
160
+ */
161
+ mintRedeemerValue: (redeemer: Data, exUnits?: Budget) => this;
162
+ /**
163
+ * Set the required signer of the transaction
164
+ * @param pubKeyHash The PubKeyHash of the required signer
165
+ * @returns The MeshTxBuilder instance
166
+ */
167
+ requiredSignerHash: (pubKeyHash: string) => this;
168
+ /**
169
+ * Set the collateral UTxO for the transaction
170
+ * @param txHash The transaction hash of the collateral UTxO
171
+ * @param txIndex The transaction index of the collateral UTxO
172
+ * @param amount The asset amount of index of the collateral UTxO
173
+ * @param address The address of the collateral UTxO
174
+ * @returns The MeshTxBuilder instance
175
+ */
176
+ txInCollateral: (txHash: string, txIndex: number, amount?: Asset[], address?: string) => this;
177
+ /**
178
+ * Configure the address to accept change UTxO
179
+ * @param addr The address to accept change UTxO
180
+ * @returns The MeshTxBuilder instance
181
+ */
182
+ changeAddress: (addr: string) => this;
183
+ /**
184
+ * Set the transaction valid interval to be valid only after the slot
185
+ * @param slot The transaction is valid only after this slot
186
+ * @returns The MeshTxBuilder instance
187
+ */
188
+ invalidBefore: (slot: number) => this;
189
+ /**
190
+ * Set the transaction valid interval to be valid only before the slot
191
+ * @param slot The transaction is valid only before this slot
192
+ * @returns The MeshTxBuilder instance
193
+ */
194
+ invalidHereafter: (slot: number) => this;
195
+ /**
196
+ * Add metadata to the transaction
197
+ * @param tag The tag of the metadata
198
+ * @param metadata The metadata in object format
199
+ * @returns The MeshTxBuilder instance
200
+ */
201
+ metadataValue: <T extends object>(tag: string, metadata: T) => this;
202
+ /**
203
+ * Set the protocol parameters to be used for the transaction other than the default one
204
+ * @param params (Part of) the protocol parameters to be used for the transaction
205
+ * @returns The MeshTxBuilder instance
206
+ */
207
+ protocolParams: (params: Partial<Protocol>) => this;
208
+ /**
209
+ * Sign the transaction with the private key
210
+ * @param skeyHex The private key in cborHex (with or without 5820 prefix, i.e. the format when generated from cardano-cli)
211
+ * @returns
212
+ */
213
+ signingKey: (skeyHex: string) => this;
214
+ private addAllSigningKeys;
215
+ private buildTx;
216
+ private queueInput;
217
+ private queueMint;
218
+ private makePlutusScriptSource;
219
+ private addAllInputs;
220
+ private addTxIn;
221
+ private addScriptTxIn;
222
+ private addAllOutputs;
223
+ private addOutput;
224
+ private addAllCollaterals;
225
+ private addCollateral;
226
+ private addCollateralReturn;
227
+ private addAllReferenceInputs;
228
+ private addReferenceInput;
229
+ protected addAllMints: (mints: MintItem[]) => void;
230
+ private addPlutusMint;
231
+ private addNativeMint;
232
+ protected queueAllLastItem: () => void;
233
+ protected addCostModels: () => void;
234
+ private addChange;
235
+ private addValidityRange;
236
+ private addAllRequiredSignatures;
237
+ private addAllMetadata;
238
+ protected updateRedeemer: (meshTxBuilderBody: MeshTxBuilderBody, txEvaluation: Omit<Action, 'data'>[]) => void;
239
+ }
@@ -0,0 +1,95 @@
1
+ import { Asset, Budget, Data } from '@mesh/common/types';
2
+ export declare type MeshTxBuilderBody = {
3
+ inputs: TxIn[];
4
+ outputs: Output[];
5
+ collaterals: PubKeyTxIn[];
6
+ requiredSignatures: string[];
7
+ referenceInputs: RefTxIn[];
8
+ mints: MintItem[];
9
+ changeAddress: string;
10
+ metadata: Metadata[];
11
+ validityRange: ValidityRange;
12
+ signingKey: string[];
13
+ };
14
+ export declare type Output = {
15
+ address: string;
16
+ amount: Asset[];
17
+ datum?: {
18
+ type: 'Hash' | 'Inline';
19
+ data: Data;
20
+ };
21
+ referenceScript?: string;
22
+ };
23
+ export declare type ValidityRange = {
24
+ invalidBefore?: number;
25
+ invalidHereafter?: number;
26
+ };
27
+ export declare type RequiredWith<T, K extends keyof T> = Required<T> & {
28
+ [P in K]: Required<T[P]>;
29
+ };
30
+ export declare type RefTxIn = {
31
+ txHash: string;
32
+ txIndex: number;
33
+ };
34
+ export declare type TxIn = PubKeyTxIn | ScriptTxIn;
35
+ export declare type PubKeyTxIn = {
36
+ type: 'PubKey';
37
+ txIn: TxInParameter;
38
+ };
39
+ export declare type ScriptTxIn = {
40
+ type: 'Script';
41
+ txIn: TxInParameter;
42
+ scriptTxIn: ScriptTxInParameter;
43
+ };
44
+ export declare type TxInParameter = {
45
+ txHash: string;
46
+ txIndex: number;
47
+ amount?: Asset[];
48
+ address?: string;
49
+ };
50
+ export declare type ScriptTxInParameter = {
51
+ scriptSource?: {
52
+ type: 'Provided';
53
+ scriptCbor: string;
54
+ } | {
55
+ type: 'Inline';
56
+ txInInfo: ScriptSourceInfo;
57
+ };
58
+ datumSource?: {
59
+ type: 'Provided';
60
+ data: Data;
61
+ } | {
62
+ type: 'Inline';
63
+ txHash: string;
64
+ txIndex: number;
65
+ };
66
+ redeemer?: Redeemer;
67
+ };
68
+ export declare type ScriptSourceInfo = {
69
+ txHash: string;
70
+ txIndex: number;
71
+ spendingScriptHash?: string;
72
+ };
73
+ export declare type MintItem = {
74
+ type: 'Plutus' | 'Native';
75
+ policyId: string;
76
+ assetName: string;
77
+ amount: number;
78
+ redeemer?: Redeemer;
79
+ scriptSource?: {
80
+ type: 'Provided';
81
+ cbor: string;
82
+ } | {
83
+ type: 'Reference Script';
84
+ txHash: string;
85
+ txIndex: number;
86
+ };
87
+ };
88
+ export declare type Redeemer = {
89
+ data: Data;
90
+ exUnits: Budget;
91
+ };
92
+ export declare type Metadata = {
93
+ tag: string;
94
+ metadata: object;
95
+ };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Rapidly build Web3 apps on the Cardano Blockchain.",
4
4
  "homepage": "https://meshjs.dev",
5
5
  "author": "MeshJS",
6
- "version": "1.5.8",
6
+ "version": "1.5.10",
7
7
  "license": "Apache-2.0",
8
8
  "type": "module",
9
9
  "repository": {
@@ -67,8 +67,8 @@
67
67
  "dependencies": {
68
68
  "@emurgo/cardano-message-signing-browser": "1.0.1",
69
69
  "@emurgo/cardano-message-signing-nodejs": "1.0.1",
70
- "@emurgo/cardano-serialization-lib-browser": "11.3.0",
71
- "@emurgo/cardano-serialization-lib-nodejs": "11.3.0",
70
+ "@emurgo/cardano-serialization-lib-browser": "11.5.0",
71
+ "@emurgo/cardano-serialization-lib-nodejs": "11.5.0",
72
72
  "@emurgo/cip14-js": "3.0.1",
73
73
  "axios": "0.27.2",
74
74
  "bip39": "3.0.4",