@lucid-evolution/provider 0.2.3 → 0.2.5

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 CHANGED
@@ -144,7 +144,7 @@ var import_utils2 = require("@lucid-evolution/utils");
144
144
  // package.json
145
145
  var package_default = {
146
146
  name: "@lucid-evolution/provider",
147
- version: "0.2.3",
147
+ version: "0.2.5",
148
148
  description: "",
149
149
  main: "./dist/index.js",
150
150
  types: "./dist/index.d.ts",
@@ -247,6 +247,7 @@ var fromLegacyRedeemerTag = (redeemerTag) => {
247
247
  };
248
248
 
249
249
  // src/blockfrost.ts
250
+ var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
250
251
  var toBlockfrostQueryPredicate = (addressOrCredential) => {
251
252
  if (typeof addressOrCredential === "string") return addressOrCredential;
252
253
  if (addressOrCredential.type === "Key") {
@@ -259,12 +260,24 @@ var toBlockfrostQueryPredicate = (addressOrCredential) => {
259
260
  var Blockfrost = class {
260
261
  url;
261
262
  projectId;
262
- constructor(url, projectId) {
263
+ requestTimeoutMs;
264
+ constructor(url, projectId, options = {}) {
263
265
  this.url = url;
264
266
  this.projectId = projectId || "";
267
+ const timeout = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
268
+ if (!Number.isFinite(timeout) || timeout <= 0) {
269
+ throw new TypeError("requestTimeoutMs must be a positive finite number.");
270
+ }
271
+ this.requestTimeoutMs = timeout;
272
+ }
273
+ /** `fetch` bounded by the provider's request timeout, combined with any caller-supplied signal. */
274
+ fetch(input, init = {}) {
275
+ const timeout = AbortSignal.timeout(this.requestTimeoutMs);
276
+ const signal = init.signal == null ? timeout : typeof AbortSignal.any === "function" ? AbortSignal.any([init.signal, timeout]) : init.signal;
277
+ return fetch(input, { ...init, signal });
265
278
  }
266
279
  async getProtocolParameters() {
267
- const result = await fetch(`${this.url}/epochs/latest/parameters`, {
280
+ const result = await this.fetch(`${this.url}/epochs/latest/parameters`, {
268
281
  headers: { project_id: this.projectId, lucid }
269
282
  }).then((res) => res.json());
270
283
  return {
@@ -292,7 +305,7 @@ var Blockfrost = class {
292
305
  };
293
306
  }
294
307
  async getTreasury() {
295
- const result = await fetch(`${this.url}/network`, {
308
+ const result = await this.fetch(`${this.url}/network`, {
296
309
  headers: { project_id: this.projectId, lucid }
297
310
  }).then((res) => res.json());
298
311
  if (!result || result.error || result.supply?.treasury === void 0) {
@@ -305,7 +318,7 @@ var Blockfrost = class {
305
318
  let result = [];
306
319
  let page = 1;
307
320
  while (true) {
308
- const pageResult = await fetch(
321
+ const pageResult = await this.fetch(
309
322
  `${this.url}/addresses/${queryPredicate}/utxos?page=${page}`,
310
323
  { headers: { project_id: this.projectId, lucid } }
311
324
  ).then((res) => res.json());
@@ -327,7 +340,7 @@ var Blockfrost = class {
327
340
  let result = [];
328
341
  let page = 1;
329
342
  while (true) {
330
- const pageResult = await fetch(
343
+ const pageResult = await this.fetch(
331
344
  `${this.url}/addresses/${queryPredicate}/utxos/${unit}?page=${page}`,
332
345
  { headers: { project_id: this.projectId, lucid } }
333
346
  ).then((res) => res.json());
@@ -345,7 +358,7 @@ var Blockfrost = class {
345
358
  return this.blockfrostUtxosToUtxos(result);
346
359
  }
347
360
  async getUtxoByUnit(unit) {
348
- const addresses = await fetch(
361
+ const addresses = await this.fetch(
349
362
  `${this.url}/assets/${unit}/addresses?count=2`,
350
363
  { headers: { project_id: this.projectId, lucid } }
351
364
  ).then((res) => res.json());
@@ -366,7 +379,7 @@ var Blockfrost = class {
366
379
  const queryHashes = [...new Set(outRefs.map((outRef) => outRef.txHash))];
367
380
  const utxos = await Promise.all(
368
381
  queryHashes.map(async (txHash) => {
369
- const result = await fetch(`${this.url}/txs/${txHash}/utxos`, {
382
+ const result = await this.fetch(`${this.url}/txs/${txHash}/utxos`, {
370
383
  headers: { project_id: this.projectId, lucid }
371
384
  }).then((res) => res.json());
372
385
  if (!result || result.error) {
@@ -388,7 +401,7 @@ var Blockfrost = class {
388
401
  );
389
402
  }
390
403
  async getRewardAccount(rewardAddress) {
391
- const response = await fetch(`${this.url}/accounts/${rewardAddress}`, {
404
+ const response = await this.fetch(`${this.url}/accounts/${rewardAddress}`, {
392
405
  headers: { project_id: this.projectId, lucid }
393
406
  });
394
407
  if (response.status === 404) {
@@ -411,9 +424,12 @@ var Blockfrost = class {
411
424
  return { poolId, rewards };
412
425
  }
413
426
  async getDatum(datumHash) {
414
- const datum = await fetch(`${this.url}/scripts/datum/${datumHash}/cbor`, {
415
- headers: { project_id: this.projectId, lucid }
416
- }).then((res) => res.json()).then((res) => res.cbor);
427
+ const datum = await this.fetch(
428
+ `${this.url}/scripts/datum/${datumHash}/cbor`,
429
+ {
430
+ headers: { project_id: this.projectId, lucid }
431
+ }
432
+ ).then((res) => res.json()).then((res) => res.cbor);
417
433
  if (!datum || datum.error) {
418
434
  throw new Error(`No datum found for datum hash: ${datumHash}`);
419
435
  }
@@ -422,7 +438,7 @@ var Blockfrost = class {
422
438
  awaitTx(txHash, checkInterval = 3e3) {
423
439
  return new Promise((res) => {
424
440
  const confirmation = setInterval(async () => {
425
- const isConfirmed = await fetch(`${this.url}/txs/${txHash}/cbor`, {
441
+ const isConfirmed = await this.fetch(`${this.url}/txs/${txHash}/cbor`, {
426
442
  headers: { project_id: this.projectId, lucid }
427
443
  }).then((res2) => res2.json());
428
444
  if (isConfirmed && !isConfirmed.error) {
@@ -434,7 +450,7 @@ var Blockfrost = class {
434
450
  });
435
451
  }
436
452
  async getTransactionStatus(txHash, options = {}) {
437
- const response = await fetch(`${this.url}/txs/${txHash}`, {
453
+ const response = await this.fetch(`${this.url}/txs/${txHash}`, {
438
454
  headers: { project_id: this.projectId, lucid },
439
455
  signal: options.signal
440
456
  });
@@ -457,7 +473,7 @@ var Blockfrost = class {
457
473
  };
458
474
  }
459
475
  async submitTx(tx) {
460
- const result = await fetch(`${this.url}/tx/submit`, {
476
+ const result = await this.fetch(`${this.url}/tx/submit`, {
461
477
  method: "POST",
462
478
  headers: {
463
479
  "Content-Type": "application/cbor",
@@ -492,19 +508,19 @@ var Blockfrost = class {
492
508
  datumHash: !r.inline_datum && r.data_hash || void 0,
493
509
  datum: r.inline_datum || void 0,
494
510
  scriptRef: r.reference_script_hash ? await (async () => {
495
- const { type } = await fetch(
511
+ const { type } = await this.fetch(
496
512
  `${this.url}/scripts/${r.reference_script_hash}`,
497
513
  {
498
514
  headers: { project_id: this.projectId, lucid }
499
515
  }
500
516
  ).then((res) => res.json());
501
- const { cbor: script } = await fetch(
517
+ const { cbor: script } = await this.fetch(
502
518
  `${this.url}/scripts/${r.reference_script_hash}/cbor`,
503
519
  { headers: { project_id: this.projectId, lucid } }
504
520
  ).then((res) => res.json());
505
521
  switch (type) {
506
522
  case "timelock":
507
- const { json: native } = await fetch(
523
+ const { json: native } = await this.fetch(
508
524
  `${this.url}/scripts/${r.reference_script_hash}/json`,
509
525
  { headers: { project_id: this.projectId, lucid } }
510
526
  ).then((res) => res.json());
@@ -539,7 +555,7 @@ var Blockfrost = class {
539
555
  cbor: tx,
540
556
  ...utxos?.length ? { additionalUtxoSet: toAditionalUTXOs(utxos) } : {}
541
557
  };
542
- const res = await fetch(`${this.url}/utils/txs/evaluate/utxos`, {
558
+ const res = await this.fetch(`${this.url}/utils/txs/evaluate/utxos`, {
543
559
  method: "POST",
544
560
  headers: {
545
561
  "Content-Type": "application/json",
@@ -1019,7 +1035,7 @@ var makePostAsUint8Array = (url, data, schema, headers) => (0, import_effect4.pi
1019
1035
 
1020
1036
  // src/kupmios.ts
1021
1037
  var import_platform2 = require("@effect/platform");
1022
- var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
1038
+ var DEFAULT_REQUEST_TIMEOUT_MS2 = 3e4;
1023
1039
  var DEFAULT_AWAIT_TX_TIMEOUT_MS = 16e4;
1024
1040
  var validateTimeout = (name, timeout) => {
1025
1041
  if (!Number.isFinite(timeout) || timeout <= 0) {
@@ -1057,7 +1073,7 @@ var Kupmios = class {
1057
1073
  this.options = options;
1058
1074
  this.requestTimeoutMs = validateTimeout(
1059
1075
  "requestTimeoutMs",
1060
- options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS
1076
+ options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS2
1061
1077
  );
1062
1078
  this.awaitTxTimeoutMs = validateTimeout(
1063
1079
  "awaitTxTimeoutMs",
@@ -1429,6 +1445,8 @@ var toAssets = (value) => {
1429
1445
  };
1430
1446
  var toProtocolParameters = (result) => {
1431
1447
  return {
1448
+ protocolMajorVersion: result.version.major,
1449
+ protocolMinorVersion: result.version.minor,
1432
1450
  minFeeA: result.minFeeCoefficient,
1433
1451
  minFeeB: result.minFeeConstant.ada.lovelace,
1434
1452
  maxTxSize: result.maxTransactionSize.bytes,
@@ -1539,6 +1557,7 @@ function generateEmulatorAccount(assets) {
1539
1557
  privateKey: ""
1540
1558
  };
1541
1559
  }
1560
+ var DEFAULT_PROTOCOL_MAJOR_VERSION = 11;
1542
1561
  var Emulator = class {
1543
1562
  [EMULATOR_PROVIDER_BRAND] = true;
1544
1563
  ledger;
@@ -1853,29 +1872,34 @@ var Emulator = class {
1853
1872
  edKeyHashes.free();
1854
1873
  const nativeHashesOptional = {};
1855
1874
  const plutusHashesOptional = [];
1875
+ const plutusV3Hashes = /* @__PURE__ */ new Set();
1856
1876
  const plutusHashes = (0, import_core_utils2.withCMLScope)((own) => {
1857
1877
  const scriptHashes = [];
1858
- const collectHashes = (scripts) => {
1878
+ const collectHashes = (scripts, isPlutusV3 = false) => {
1859
1879
  own(scripts);
1860
1880
  for (let i = 0; i < (scripts?.len() || 0); i++) {
1861
1881
  (0, import_core_utils2.withCMLScope)((own2) => {
1862
1882
  const script = own2(scripts.get(i));
1863
- scriptHashes.push(own2(script.hash()).to_hex());
1883
+ const scriptHash = own2(script.hash()).to_hex();
1884
+ scriptHashes.push(scriptHash);
1885
+ if (isPlutusV3) plutusV3Hashes.add(scriptHash);
1864
1886
  });
1865
1887
  }
1866
1888
  };
1867
1889
  collectHashes(witnesses.plutus_v1_scripts());
1868
1890
  collectHashes(witnesses.plutus_v2_scripts());
1869
- collectHashes(witnesses.plutus_v3_scripts());
1891
+ collectHashes(witnesses.plutus_v3_scripts(), true);
1870
1892
  return scriptHashes;
1871
1893
  });
1872
1894
  const inputs = body.inputs();
1873
1895
  const resolvedInputs = [];
1896
+ const inputOutRefs = /* @__PURE__ */ new Set();
1874
1897
  for (let i = 0; i < inputs.len(); i++) {
1875
1898
  const outRef = (0, import_core_utils2.withCMLScope)((own) => {
1876
1899
  const input = own(inputs.get(i));
1877
1900
  return own(input.transaction_id()).to_hex() + input.index().toString();
1878
1901
  });
1902
+ inputOutRefs.add(outRef);
1879
1903
  const entryLedger = this.ledger[outRef];
1880
1904
  const { entry, type } = !entryLedger ? { entry: this.mempool[outRef], type: "Mempool" } : { entry: entryLedger, type: "Ledger" };
1881
1905
  if (!entry || entry.spent) {
@@ -1915,7 +1939,9 @@ It does not exist or was already spent.`
1915
1939
  const script = CML.PlutusScript.from_v3(
1916
1940
  CML.PlutusV3Script.from_cbor_bytes((0, import_core_utils2.fromHex)(scriptRef.script))
1917
1941
  );
1918
- plutusHashesOptional.push(script.hash().to_hex());
1942
+ const scriptHash = script.hash().to_hex();
1943
+ plutusHashesOptional.push(scriptHash);
1944
+ plutusV3Hashes.add(scriptHash);
1919
1945
  break;
1920
1946
  }
1921
1947
  }
@@ -1925,6 +1951,7 @@ It does not exist or was already spent.`
1925
1951
  }
1926
1952
  inputs.free();
1927
1953
  const referenceInputs = body.reference_inputs();
1954
+ const nonDisjointRefInputs = [];
1928
1955
  for (let i = 0; i < (referenceInputs?.len() || 0); i++) {
1929
1956
  const outRef = (0, import_core_utils2.withCMLScope)((own) => {
1930
1957
  const input = own(referenceInputs.get(i));
@@ -1940,6 +1967,11 @@ It does not exist or was already spent.`
1940
1967
  It does not exist or was already spent.`
1941
1968
  );
1942
1969
  }
1970
+ if (inputOutRefs.has(outRef)) {
1971
+ nonDisjointRefInputs.push(
1972
+ `${entry.utxo.txHash}#${entry.utxo.outputIndex}`
1973
+ );
1974
+ }
1943
1975
  const scriptRef = entry.utxo.scriptRef;
1944
1976
  if (scriptRef) {
1945
1977
  switch (scriptRef.type) {
@@ -1968,7 +2000,9 @@ It does not exist or was already spent.`
1968
2000
  const script = CML.PlutusScript.from_v3(
1969
2001
  CML.PlutusV3Script.from_cbor_bytes((0, import_core_utils2.fromHex)(scriptRef.script))
1970
2002
  );
1971
- plutusHashesOptional.push(script.hash().to_hex());
2003
+ const scriptHash = script.hash().to_hex();
2004
+ plutusHashesOptional.push(scriptHash);
2005
+ plutusV3Hashes.add(scriptHash);
1972
2006
  break;
1973
2007
  }
1974
2008
  }
@@ -2395,6 +2429,23 @@ It does not exist or was already spent.`
2395
2429
  if (extraDatumHash) {
2396
2430
  throw new Error(`Extraneous plutus data. Datum hash: ${extraDatumHash}`);
2397
2431
  }
2432
+ if (nonDisjointRefInputs.length > 0) {
2433
+ const protocolMajorVersion = this.protocolParameters.protocolMajorVersion ?? DEFAULT_PROTOCOL_MAJOR_VERSION;
2434
+ const overlap = nonDisjointRefInputs.join(", ");
2435
+ if (protocolMajorVersion === 9 || protocolMajorVersion === 10) {
2436
+ throw new Error(
2437
+ `BabbageNonDisjointRefInputs: reference inputs must be disjoint from inputs at protocol version ${protocolMajorVersion}. Overlapping: ${overlap}`
2438
+ );
2439
+ }
2440
+ const runsPlutusV3 = [...consumedHashes].some(
2441
+ (hash) => plutusV3Hashes.has(hash)
2442
+ );
2443
+ if (protocolMajorVersion >= 11 && runsPlutusV3) {
2444
+ throw new Error(
2445
+ `ReferenceInputsNotDisjointFromInputs: a PlutusV3 script context cannot be built while reference inputs overlap inputs. Overlapping: ${overlap}`
2446
+ );
2447
+ }
2448
+ }
2398
2449
  resolvedInputs.forEach(({ entry, type }) => {
2399
2450
  const outRef = entry.utxo.txHash + entry.utxo.outputIndex;
2400
2451
  entry.spent = true;
@@ -2581,6 +2632,8 @@ var Maestro = class {
2581
2632
  return parseInt(str.slice(0, forwardSlashIndex)) / parseInt(str.slice(forwardSlashIndex + 1));
2582
2633
  };
2583
2634
  return {
2635
+ protocolMajorVersion: result.version?.major,
2636
+ protocolMinorVersion: result.version?.minor,
2584
2637
  minFeeA: parseInt(result.min_fee_coefficient),
2585
2638
  minFeeB: parseInt(result.min_fee_constant.ada.lovelace),
2586
2639
  maxTxSize: parseInt(result.max_transaction_size.bytes),
@@ -3243,6 +3296,8 @@ var Koios = class {
3243
3296
  import_effect8.Effect.runPromise
3244
3297
  );
3245
3298
  return {
3299
+ protocolMajorVersion: result.protocol_major,
3300
+ protocolMinorVersion: result.protocol_minor,
3246
3301
  minFeeA: result.min_fee_a,
3247
3302
  minFeeB: result.min_fee_b,
3248
3303
  maxTxSize: result.max_tx_size,
package/dist/index.d.cts CHANGED
@@ -48,10 +48,17 @@ declare class OgmiosJsonRpcError extends KupmiosError {
48
48
  constructor(options: OgmiosJsonRpcErrorOptions);
49
49
  }
50
50
 
51
+ interface BlockfrostOptions {
52
+ /** Abort any single request after this many milliseconds. Defaults to 30 000. */
53
+ readonly requestTimeoutMs?: number;
54
+ }
51
55
  declare class Blockfrost implements Provider {
52
56
  url: string;
53
57
  projectId: string;
54
- constructor(url: string, projectId?: string);
58
+ private readonly requestTimeoutMs;
59
+ constructor(url: string, projectId?: string, options?: BlockfrostOptions);
60
+ /** `fetch` bounded by the provider's request timeout, combined with any caller-supplied signal. */
61
+ private fetch;
55
62
  getProtocolParameters(): Promise<ProtocolParameters>;
56
63
  getTreasury(): Promise<bigint>;
57
64
  getUtxos(addressOrCredential: Address | Credential): Promise<UTxO[]>;
@@ -287,4 +294,4 @@ declare class Koios implements Provider {
287
294
  evaluateTx(tx: Transaction, additionalUTxOs?: UTxO[]): Promise<EvalRedeemer[]>;
288
295
  }
289
296
 
290
- export { Blockfrost, Emulator, type EmulatorAccount, Koios, KoiosError, Kupmios, KupmiosError, type KupmiosErrorOptions, type KupmiosOptions, Maestro, type MaestroConfig, type MaestroSupportedNetworks, OgmiosJsonRpcError, type OgmiosJsonRpcErrorOptions, type ProviderErrorKind, type ProviderTransportProtocol, generateEmulatorAccount, generateEmulatorAccountFromPrivateKey, isEmulatorProvider };
297
+ export { Blockfrost, type BlockfrostOptions, Emulator, type EmulatorAccount, Koios, KoiosError, Kupmios, KupmiosError, type KupmiosErrorOptions, type KupmiosOptions, Maestro, type MaestroConfig, type MaestroSupportedNetworks, OgmiosJsonRpcError, type OgmiosJsonRpcErrorOptions, type ProviderErrorKind, type ProviderTransportProtocol, generateEmulatorAccount, generateEmulatorAccountFromPrivateKey, isEmulatorProvider };
package/dist/index.d.ts CHANGED
@@ -48,10 +48,17 @@ declare class OgmiosJsonRpcError extends KupmiosError {
48
48
  constructor(options: OgmiosJsonRpcErrorOptions);
49
49
  }
50
50
 
51
+ interface BlockfrostOptions {
52
+ /** Abort any single request after this many milliseconds. Defaults to 30 000. */
53
+ readonly requestTimeoutMs?: number;
54
+ }
51
55
  declare class Blockfrost implements Provider {
52
56
  url: string;
53
57
  projectId: string;
54
- constructor(url: string, projectId?: string);
58
+ private readonly requestTimeoutMs;
59
+ constructor(url: string, projectId?: string, options?: BlockfrostOptions);
60
+ /** `fetch` bounded by the provider's request timeout, combined with any caller-supplied signal. */
61
+ private fetch;
55
62
  getProtocolParameters(): Promise<ProtocolParameters>;
56
63
  getTreasury(): Promise<bigint>;
57
64
  getUtxos(addressOrCredential: Address | Credential): Promise<UTxO[]>;
@@ -287,4 +294,4 @@ declare class Koios implements Provider {
287
294
  evaluateTx(tx: Transaction, additionalUTxOs?: UTxO[]): Promise<EvalRedeemer[]>;
288
295
  }
289
296
 
290
- export { Blockfrost, Emulator, type EmulatorAccount, Koios, KoiosError, Kupmios, KupmiosError, type KupmiosErrorOptions, type KupmiosOptions, Maestro, type MaestroConfig, type MaestroSupportedNetworks, OgmiosJsonRpcError, type OgmiosJsonRpcErrorOptions, type ProviderErrorKind, type ProviderTransportProtocol, generateEmulatorAccount, generateEmulatorAccountFromPrivateKey, isEmulatorProvider };
297
+ export { Blockfrost, type BlockfrostOptions, Emulator, type EmulatorAccount, Koios, KoiosError, Kupmios, KupmiosError, type KupmiosErrorOptions, type KupmiosOptions, Maestro, type MaestroConfig, type MaestroSupportedNetworks, OgmiosJsonRpcError, type OgmiosJsonRpcErrorOptions, type ProviderErrorKind, type ProviderTransportProtocol, generateEmulatorAccount, generateEmulatorAccountFromPrivateKey, isEmulatorProvider };
package/dist/index.js CHANGED
@@ -101,7 +101,7 @@ import {
101
101
  // package.json
102
102
  var package_default = {
103
103
  name: "@lucid-evolution/provider",
104
- version: "0.2.3",
104
+ version: "0.2.5",
105
105
  description: "",
106
106
  main: "./dist/index.js",
107
107
  types: "./dist/index.d.ts",
@@ -204,6 +204,7 @@ var fromLegacyRedeemerTag = (redeemerTag) => {
204
204
  };
205
205
 
206
206
  // src/blockfrost.ts
207
+ var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
207
208
  var toBlockfrostQueryPredicate = (addressOrCredential) => {
208
209
  if (typeof addressOrCredential === "string") return addressOrCredential;
209
210
  if (addressOrCredential.type === "Key") {
@@ -216,12 +217,24 @@ var toBlockfrostQueryPredicate = (addressOrCredential) => {
216
217
  var Blockfrost = class {
217
218
  url;
218
219
  projectId;
219
- constructor(url, projectId) {
220
+ requestTimeoutMs;
221
+ constructor(url, projectId, options = {}) {
220
222
  this.url = url;
221
223
  this.projectId = projectId || "";
224
+ const timeout = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
225
+ if (!Number.isFinite(timeout) || timeout <= 0) {
226
+ throw new TypeError("requestTimeoutMs must be a positive finite number.");
227
+ }
228
+ this.requestTimeoutMs = timeout;
229
+ }
230
+ /** `fetch` bounded by the provider's request timeout, combined with any caller-supplied signal. */
231
+ fetch(input, init = {}) {
232
+ const timeout = AbortSignal.timeout(this.requestTimeoutMs);
233
+ const signal = init.signal == null ? timeout : typeof AbortSignal.any === "function" ? AbortSignal.any([init.signal, timeout]) : init.signal;
234
+ return fetch(input, { ...init, signal });
222
235
  }
223
236
  async getProtocolParameters() {
224
- const result = await fetch(`${this.url}/epochs/latest/parameters`, {
237
+ const result = await this.fetch(`${this.url}/epochs/latest/parameters`, {
225
238
  headers: { project_id: this.projectId, lucid }
226
239
  }).then((res) => res.json());
227
240
  return {
@@ -249,7 +262,7 @@ var Blockfrost = class {
249
262
  };
250
263
  }
251
264
  async getTreasury() {
252
- const result = await fetch(`${this.url}/network`, {
265
+ const result = await this.fetch(`${this.url}/network`, {
253
266
  headers: { project_id: this.projectId, lucid }
254
267
  }).then((res) => res.json());
255
268
  if (!result || result.error || result.supply?.treasury === void 0) {
@@ -262,7 +275,7 @@ var Blockfrost = class {
262
275
  let result = [];
263
276
  let page = 1;
264
277
  while (true) {
265
- const pageResult = await fetch(
278
+ const pageResult = await this.fetch(
266
279
  `${this.url}/addresses/${queryPredicate}/utxos?page=${page}`,
267
280
  { headers: { project_id: this.projectId, lucid } }
268
281
  ).then((res) => res.json());
@@ -284,7 +297,7 @@ var Blockfrost = class {
284
297
  let result = [];
285
298
  let page = 1;
286
299
  while (true) {
287
- const pageResult = await fetch(
300
+ const pageResult = await this.fetch(
288
301
  `${this.url}/addresses/${queryPredicate}/utxos/${unit}?page=${page}`,
289
302
  { headers: { project_id: this.projectId, lucid } }
290
303
  ).then((res) => res.json());
@@ -302,7 +315,7 @@ var Blockfrost = class {
302
315
  return this.blockfrostUtxosToUtxos(result);
303
316
  }
304
317
  async getUtxoByUnit(unit) {
305
- const addresses = await fetch(
318
+ const addresses = await this.fetch(
306
319
  `${this.url}/assets/${unit}/addresses?count=2`,
307
320
  { headers: { project_id: this.projectId, lucid } }
308
321
  ).then((res) => res.json());
@@ -323,7 +336,7 @@ var Blockfrost = class {
323
336
  const queryHashes = [...new Set(outRefs.map((outRef) => outRef.txHash))];
324
337
  const utxos = await Promise.all(
325
338
  queryHashes.map(async (txHash) => {
326
- const result = await fetch(`${this.url}/txs/${txHash}/utxos`, {
339
+ const result = await this.fetch(`${this.url}/txs/${txHash}/utxos`, {
327
340
  headers: { project_id: this.projectId, lucid }
328
341
  }).then((res) => res.json());
329
342
  if (!result || result.error) {
@@ -345,7 +358,7 @@ var Blockfrost = class {
345
358
  );
346
359
  }
347
360
  async getRewardAccount(rewardAddress) {
348
- const response = await fetch(`${this.url}/accounts/${rewardAddress}`, {
361
+ const response = await this.fetch(`${this.url}/accounts/${rewardAddress}`, {
349
362
  headers: { project_id: this.projectId, lucid }
350
363
  });
351
364
  if (response.status === 404) {
@@ -368,9 +381,12 @@ var Blockfrost = class {
368
381
  return { poolId, rewards };
369
382
  }
370
383
  async getDatum(datumHash) {
371
- const datum = await fetch(`${this.url}/scripts/datum/${datumHash}/cbor`, {
372
- headers: { project_id: this.projectId, lucid }
373
- }).then((res) => res.json()).then((res) => res.cbor);
384
+ const datum = await this.fetch(
385
+ `${this.url}/scripts/datum/${datumHash}/cbor`,
386
+ {
387
+ headers: { project_id: this.projectId, lucid }
388
+ }
389
+ ).then((res) => res.json()).then((res) => res.cbor);
374
390
  if (!datum || datum.error) {
375
391
  throw new Error(`No datum found for datum hash: ${datumHash}`);
376
392
  }
@@ -379,7 +395,7 @@ var Blockfrost = class {
379
395
  awaitTx(txHash, checkInterval = 3e3) {
380
396
  return new Promise((res) => {
381
397
  const confirmation = setInterval(async () => {
382
- const isConfirmed = await fetch(`${this.url}/txs/${txHash}/cbor`, {
398
+ const isConfirmed = await this.fetch(`${this.url}/txs/${txHash}/cbor`, {
383
399
  headers: { project_id: this.projectId, lucid }
384
400
  }).then((res2) => res2.json());
385
401
  if (isConfirmed && !isConfirmed.error) {
@@ -391,7 +407,7 @@ var Blockfrost = class {
391
407
  });
392
408
  }
393
409
  async getTransactionStatus(txHash, options = {}) {
394
- const response = await fetch(`${this.url}/txs/${txHash}`, {
410
+ const response = await this.fetch(`${this.url}/txs/${txHash}`, {
395
411
  headers: { project_id: this.projectId, lucid },
396
412
  signal: options.signal
397
413
  });
@@ -414,7 +430,7 @@ var Blockfrost = class {
414
430
  };
415
431
  }
416
432
  async submitTx(tx) {
417
- const result = await fetch(`${this.url}/tx/submit`, {
433
+ const result = await this.fetch(`${this.url}/tx/submit`, {
418
434
  method: "POST",
419
435
  headers: {
420
436
  "Content-Type": "application/cbor",
@@ -449,19 +465,19 @@ var Blockfrost = class {
449
465
  datumHash: !r.inline_datum && r.data_hash || void 0,
450
466
  datum: r.inline_datum || void 0,
451
467
  scriptRef: r.reference_script_hash ? await (async () => {
452
- const { type } = await fetch(
468
+ const { type } = await this.fetch(
453
469
  `${this.url}/scripts/${r.reference_script_hash}`,
454
470
  {
455
471
  headers: { project_id: this.projectId, lucid }
456
472
  }
457
473
  ).then((res) => res.json());
458
- const { cbor: script } = await fetch(
474
+ const { cbor: script } = await this.fetch(
459
475
  `${this.url}/scripts/${r.reference_script_hash}/cbor`,
460
476
  { headers: { project_id: this.projectId, lucid } }
461
477
  ).then((res) => res.json());
462
478
  switch (type) {
463
479
  case "timelock":
464
- const { json: native } = await fetch(
480
+ const { json: native } = await this.fetch(
465
481
  `${this.url}/scripts/${r.reference_script_hash}/json`,
466
482
  { headers: { project_id: this.projectId, lucid } }
467
483
  ).then((res) => res.json());
@@ -496,7 +512,7 @@ var Blockfrost = class {
496
512
  cbor: tx,
497
513
  ...utxos?.length ? { additionalUtxoSet: toAditionalUTXOs(utxos) } : {}
498
514
  };
499
- const res = await fetch(`${this.url}/utils/txs/evaluate/utxos`, {
515
+ const res = await this.fetch(`${this.url}/utils/txs/evaluate/utxos`, {
500
516
  method: "POST",
501
517
  headers: {
502
518
  "Content-Type": "application/json",
@@ -981,7 +997,7 @@ var makePostAsUint8Array = (url, data, schema, headers) => pipe2(
981
997
 
982
998
  // src/kupmios.ts
983
999
  import { FetchHttpClient } from "@effect/platform";
984
- var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
1000
+ var DEFAULT_REQUEST_TIMEOUT_MS2 = 3e4;
985
1001
  var DEFAULT_AWAIT_TX_TIMEOUT_MS = 16e4;
986
1002
  var validateTimeout = (name, timeout) => {
987
1003
  if (!Number.isFinite(timeout) || timeout <= 0) {
@@ -1019,7 +1035,7 @@ var Kupmios = class {
1019
1035
  this.options = options;
1020
1036
  this.requestTimeoutMs = validateTimeout(
1021
1037
  "requestTimeoutMs",
1022
- options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS
1038
+ options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS2
1023
1039
  );
1024
1040
  this.awaitTxTimeoutMs = validateTimeout(
1025
1041
  "awaitTxTimeoutMs",
@@ -1391,6 +1407,8 @@ var toAssets = (value) => {
1391
1407
  };
1392
1408
  var toProtocolParameters = (result) => {
1393
1409
  return {
1410
+ protocolMajorVersion: result.version.major,
1411
+ protocolMinorVersion: result.version.minor,
1394
1412
  minFeeA: result.minFeeCoefficient,
1395
1413
  minFeeB: result.minFeeConstant.ada.lovelace,
1396
1414
  maxTxSize: result.maxTransactionSize.bytes,
@@ -1505,6 +1523,7 @@ function generateEmulatorAccount(assets) {
1505
1523
  privateKey: ""
1506
1524
  };
1507
1525
  }
1526
+ var DEFAULT_PROTOCOL_MAJOR_VERSION = 11;
1508
1527
  var Emulator = class {
1509
1528
  [EMULATOR_PROVIDER_BRAND] = true;
1510
1529
  ledger;
@@ -1819,29 +1838,34 @@ var Emulator = class {
1819
1838
  edKeyHashes.free();
1820
1839
  const nativeHashesOptional = {};
1821
1840
  const plutusHashesOptional = [];
1841
+ const plutusV3Hashes = /* @__PURE__ */ new Set();
1822
1842
  const plutusHashes = withCMLScope((own) => {
1823
1843
  const scriptHashes = [];
1824
- const collectHashes = (scripts) => {
1844
+ const collectHashes = (scripts, isPlutusV3 = false) => {
1825
1845
  own(scripts);
1826
1846
  for (let i = 0; i < (scripts?.len() || 0); i++) {
1827
1847
  withCMLScope((own2) => {
1828
1848
  const script = own2(scripts.get(i));
1829
- scriptHashes.push(own2(script.hash()).to_hex());
1849
+ const scriptHash = own2(script.hash()).to_hex();
1850
+ scriptHashes.push(scriptHash);
1851
+ if (isPlutusV3) plutusV3Hashes.add(scriptHash);
1830
1852
  });
1831
1853
  }
1832
1854
  };
1833
1855
  collectHashes(witnesses.plutus_v1_scripts());
1834
1856
  collectHashes(witnesses.plutus_v2_scripts());
1835
- collectHashes(witnesses.plutus_v3_scripts());
1857
+ collectHashes(witnesses.plutus_v3_scripts(), true);
1836
1858
  return scriptHashes;
1837
1859
  });
1838
1860
  const inputs = body.inputs();
1839
1861
  const resolvedInputs = [];
1862
+ const inputOutRefs = /* @__PURE__ */ new Set();
1840
1863
  for (let i = 0; i < inputs.len(); i++) {
1841
1864
  const outRef = withCMLScope((own) => {
1842
1865
  const input = own(inputs.get(i));
1843
1866
  return own(input.transaction_id()).to_hex() + input.index().toString();
1844
1867
  });
1868
+ inputOutRefs.add(outRef);
1845
1869
  const entryLedger = this.ledger[outRef];
1846
1870
  const { entry, type } = !entryLedger ? { entry: this.mempool[outRef], type: "Mempool" } : { entry: entryLedger, type: "Ledger" };
1847
1871
  if (!entry || entry.spent) {
@@ -1881,7 +1905,9 @@ It does not exist or was already spent.`
1881
1905
  const script = CML.PlutusScript.from_v3(
1882
1906
  CML.PlutusV3Script.from_cbor_bytes(fromHex2(scriptRef.script))
1883
1907
  );
1884
- plutusHashesOptional.push(script.hash().to_hex());
1908
+ const scriptHash = script.hash().to_hex();
1909
+ plutusHashesOptional.push(scriptHash);
1910
+ plutusV3Hashes.add(scriptHash);
1885
1911
  break;
1886
1912
  }
1887
1913
  }
@@ -1891,6 +1917,7 @@ It does not exist or was already spent.`
1891
1917
  }
1892
1918
  inputs.free();
1893
1919
  const referenceInputs = body.reference_inputs();
1920
+ const nonDisjointRefInputs = [];
1894
1921
  for (let i = 0; i < (referenceInputs?.len() || 0); i++) {
1895
1922
  const outRef = withCMLScope((own) => {
1896
1923
  const input = own(referenceInputs.get(i));
@@ -1906,6 +1933,11 @@ It does not exist or was already spent.`
1906
1933
  It does not exist or was already spent.`
1907
1934
  );
1908
1935
  }
1936
+ if (inputOutRefs.has(outRef)) {
1937
+ nonDisjointRefInputs.push(
1938
+ `${entry.utxo.txHash}#${entry.utxo.outputIndex}`
1939
+ );
1940
+ }
1909
1941
  const scriptRef = entry.utxo.scriptRef;
1910
1942
  if (scriptRef) {
1911
1943
  switch (scriptRef.type) {
@@ -1934,7 +1966,9 @@ It does not exist or was already spent.`
1934
1966
  const script = CML.PlutusScript.from_v3(
1935
1967
  CML.PlutusV3Script.from_cbor_bytes(fromHex2(scriptRef.script))
1936
1968
  );
1937
- plutusHashesOptional.push(script.hash().to_hex());
1969
+ const scriptHash = script.hash().to_hex();
1970
+ plutusHashesOptional.push(scriptHash);
1971
+ plutusV3Hashes.add(scriptHash);
1938
1972
  break;
1939
1973
  }
1940
1974
  }
@@ -2361,6 +2395,23 @@ It does not exist or was already spent.`
2361
2395
  if (extraDatumHash) {
2362
2396
  throw new Error(`Extraneous plutus data. Datum hash: ${extraDatumHash}`);
2363
2397
  }
2398
+ if (nonDisjointRefInputs.length > 0) {
2399
+ const protocolMajorVersion = this.protocolParameters.protocolMajorVersion ?? DEFAULT_PROTOCOL_MAJOR_VERSION;
2400
+ const overlap = nonDisjointRefInputs.join(", ");
2401
+ if (protocolMajorVersion === 9 || protocolMajorVersion === 10) {
2402
+ throw new Error(
2403
+ `BabbageNonDisjointRefInputs: reference inputs must be disjoint from inputs at protocol version ${protocolMajorVersion}. Overlapping: ${overlap}`
2404
+ );
2405
+ }
2406
+ const runsPlutusV3 = [...consumedHashes].some(
2407
+ (hash) => plutusV3Hashes.has(hash)
2408
+ );
2409
+ if (protocolMajorVersion >= 11 && runsPlutusV3) {
2410
+ throw new Error(
2411
+ `ReferenceInputsNotDisjointFromInputs: a PlutusV3 script context cannot be built while reference inputs overlap inputs. Overlapping: ${overlap}`
2412
+ );
2413
+ }
2414
+ }
2364
2415
  resolvedInputs.forEach(({ entry, type }) => {
2365
2416
  const outRef = entry.utxo.txHash + entry.utxo.outputIndex;
2366
2417
  entry.spent = true;
@@ -2551,6 +2602,8 @@ var Maestro = class {
2551
2602
  return parseInt(str.slice(0, forwardSlashIndex)) / parseInt(str.slice(forwardSlashIndex + 1));
2552
2603
  };
2553
2604
  return {
2605
+ protocolMajorVersion: result.version?.major,
2606
+ protocolMinorVersion: result.version?.minor,
2554
2607
  minFeeA: parseInt(result.min_fee_coefficient),
2555
2608
  minFeeB: parseInt(result.min_fee_constant.ada.lovelace),
2556
2609
  maxTxSize: parseInt(result.max_transaction_size.bytes),
@@ -3213,6 +3266,8 @@ var Koios = class {
3213
3266
  Effect4.runPromise
3214
3267
  );
3215
3268
  return {
3269
+ protocolMajorVersion: result.protocol_major,
3270
+ protocolMinorVersion: result.protocol_minor,
3216
3271
  minFeeA: result.min_fee_a,
3217
3272
  minFeeB: result.min_fee_b,
3218
3273
  maxTxSize: result.max_tx_size,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucid-evolution/provider",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -30,8 +30,8 @@
30
30
  "@effect/platform": "^0.71.3",
31
31
  "@effect/schema": "^0.68.26",
32
32
  "effect": "^3.11.7",
33
- "@lucid-evolution/core-types": "0.3.0",
34
33
  "@lucid-evolution/core-utils": "0.1.17",
34
+ "@lucid-evolution/core-types": "0.3.0",
35
35
  "@lucid-evolution/utils": "0.1.74",
36
36
  "@lucid-evolution/wallet": "0.2.2"
37
37
  },