@lucid-evolution/provider 0.2.3 → 0.2.4

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.4",
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",
@@ -1539,6 +1555,7 @@ function generateEmulatorAccount(assets) {
1539
1555
  privateKey: ""
1540
1556
  };
1541
1557
  }
1558
+ var DEFAULT_PROTOCOL_MAJOR_VERSION = 11;
1542
1559
  var Emulator = class {
1543
1560
  [EMULATOR_PROVIDER_BRAND] = true;
1544
1561
  ledger;
@@ -1853,29 +1870,34 @@ var Emulator = class {
1853
1870
  edKeyHashes.free();
1854
1871
  const nativeHashesOptional = {};
1855
1872
  const plutusHashesOptional = [];
1873
+ const plutusV3Hashes = /* @__PURE__ */ new Set();
1856
1874
  const plutusHashes = (0, import_core_utils2.withCMLScope)((own) => {
1857
1875
  const scriptHashes = [];
1858
- const collectHashes = (scripts) => {
1876
+ const collectHashes = (scripts, isPlutusV3 = false) => {
1859
1877
  own(scripts);
1860
1878
  for (let i = 0; i < (scripts?.len() || 0); i++) {
1861
1879
  (0, import_core_utils2.withCMLScope)((own2) => {
1862
1880
  const script = own2(scripts.get(i));
1863
- scriptHashes.push(own2(script.hash()).to_hex());
1881
+ const scriptHash = own2(script.hash()).to_hex();
1882
+ scriptHashes.push(scriptHash);
1883
+ if (isPlutusV3) plutusV3Hashes.add(scriptHash);
1864
1884
  });
1865
1885
  }
1866
1886
  };
1867
1887
  collectHashes(witnesses.plutus_v1_scripts());
1868
1888
  collectHashes(witnesses.plutus_v2_scripts());
1869
- collectHashes(witnesses.plutus_v3_scripts());
1889
+ collectHashes(witnesses.plutus_v3_scripts(), true);
1870
1890
  return scriptHashes;
1871
1891
  });
1872
1892
  const inputs = body.inputs();
1873
1893
  const resolvedInputs = [];
1894
+ const inputOutRefs = /* @__PURE__ */ new Set();
1874
1895
  for (let i = 0; i < inputs.len(); i++) {
1875
1896
  const outRef = (0, import_core_utils2.withCMLScope)((own) => {
1876
1897
  const input = own(inputs.get(i));
1877
1898
  return own(input.transaction_id()).to_hex() + input.index().toString();
1878
1899
  });
1900
+ inputOutRefs.add(outRef);
1879
1901
  const entryLedger = this.ledger[outRef];
1880
1902
  const { entry, type } = !entryLedger ? { entry: this.mempool[outRef], type: "Mempool" } : { entry: entryLedger, type: "Ledger" };
1881
1903
  if (!entry || entry.spent) {
@@ -1915,7 +1937,9 @@ It does not exist or was already spent.`
1915
1937
  const script = CML.PlutusScript.from_v3(
1916
1938
  CML.PlutusV3Script.from_cbor_bytes((0, import_core_utils2.fromHex)(scriptRef.script))
1917
1939
  );
1918
- plutusHashesOptional.push(script.hash().to_hex());
1940
+ const scriptHash = script.hash().to_hex();
1941
+ plutusHashesOptional.push(scriptHash);
1942
+ plutusV3Hashes.add(scriptHash);
1919
1943
  break;
1920
1944
  }
1921
1945
  }
@@ -1925,6 +1949,7 @@ It does not exist or was already spent.`
1925
1949
  }
1926
1950
  inputs.free();
1927
1951
  const referenceInputs = body.reference_inputs();
1952
+ const nonDisjointRefInputs = [];
1928
1953
  for (let i = 0; i < (referenceInputs?.len() || 0); i++) {
1929
1954
  const outRef = (0, import_core_utils2.withCMLScope)((own) => {
1930
1955
  const input = own(referenceInputs.get(i));
@@ -1940,6 +1965,11 @@ It does not exist or was already spent.`
1940
1965
  It does not exist or was already spent.`
1941
1966
  );
1942
1967
  }
1968
+ if (inputOutRefs.has(outRef)) {
1969
+ nonDisjointRefInputs.push(
1970
+ `${entry.utxo.txHash}#${entry.utxo.outputIndex}`
1971
+ );
1972
+ }
1943
1973
  const scriptRef = entry.utxo.scriptRef;
1944
1974
  if (scriptRef) {
1945
1975
  switch (scriptRef.type) {
@@ -1968,7 +1998,9 @@ It does not exist or was already spent.`
1968
1998
  const script = CML.PlutusScript.from_v3(
1969
1999
  CML.PlutusV3Script.from_cbor_bytes((0, import_core_utils2.fromHex)(scriptRef.script))
1970
2000
  );
1971
- plutusHashesOptional.push(script.hash().to_hex());
2001
+ const scriptHash = script.hash().to_hex();
2002
+ plutusHashesOptional.push(scriptHash);
2003
+ plutusV3Hashes.add(scriptHash);
1972
2004
  break;
1973
2005
  }
1974
2006
  }
@@ -2395,6 +2427,23 @@ It does not exist or was already spent.`
2395
2427
  if (extraDatumHash) {
2396
2428
  throw new Error(`Extraneous plutus data. Datum hash: ${extraDatumHash}`);
2397
2429
  }
2430
+ if (nonDisjointRefInputs.length > 0) {
2431
+ const protocolMajorVersion = this.protocolParameters.protocolMajorVersion ?? DEFAULT_PROTOCOL_MAJOR_VERSION;
2432
+ const overlap = nonDisjointRefInputs.join(", ");
2433
+ if (protocolMajorVersion === 9 || protocolMajorVersion === 10) {
2434
+ throw new Error(
2435
+ `BabbageNonDisjointRefInputs: reference inputs must be disjoint from inputs at protocol version ${protocolMajorVersion}. Overlapping: ${overlap}`
2436
+ );
2437
+ }
2438
+ const runsPlutusV3 = [...consumedHashes].some(
2439
+ (hash) => plutusV3Hashes.has(hash)
2440
+ );
2441
+ if (protocolMajorVersion >= 11 && runsPlutusV3) {
2442
+ throw new Error(
2443
+ `ReferenceInputsNotDisjointFromInputs: a PlutusV3 script context cannot be built while reference inputs overlap inputs. Overlapping: ${overlap}`
2444
+ );
2445
+ }
2446
+ }
2398
2447
  resolvedInputs.forEach(({ entry, type }) => {
2399
2448
  const outRef = entry.utxo.txHash + entry.utxo.outputIndex;
2400
2449
  entry.spent = true;
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.4",
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",
@@ -1505,6 +1521,7 @@ function generateEmulatorAccount(assets) {
1505
1521
  privateKey: ""
1506
1522
  };
1507
1523
  }
1524
+ var DEFAULT_PROTOCOL_MAJOR_VERSION = 11;
1508
1525
  var Emulator = class {
1509
1526
  [EMULATOR_PROVIDER_BRAND] = true;
1510
1527
  ledger;
@@ -1819,29 +1836,34 @@ var Emulator = class {
1819
1836
  edKeyHashes.free();
1820
1837
  const nativeHashesOptional = {};
1821
1838
  const plutusHashesOptional = [];
1839
+ const plutusV3Hashes = /* @__PURE__ */ new Set();
1822
1840
  const plutusHashes = withCMLScope((own) => {
1823
1841
  const scriptHashes = [];
1824
- const collectHashes = (scripts) => {
1842
+ const collectHashes = (scripts, isPlutusV3 = false) => {
1825
1843
  own(scripts);
1826
1844
  for (let i = 0; i < (scripts?.len() || 0); i++) {
1827
1845
  withCMLScope((own2) => {
1828
1846
  const script = own2(scripts.get(i));
1829
- scriptHashes.push(own2(script.hash()).to_hex());
1847
+ const scriptHash = own2(script.hash()).to_hex();
1848
+ scriptHashes.push(scriptHash);
1849
+ if (isPlutusV3) plutusV3Hashes.add(scriptHash);
1830
1850
  });
1831
1851
  }
1832
1852
  };
1833
1853
  collectHashes(witnesses.plutus_v1_scripts());
1834
1854
  collectHashes(witnesses.plutus_v2_scripts());
1835
- collectHashes(witnesses.plutus_v3_scripts());
1855
+ collectHashes(witnesses.plutus_v3_scripts(), true);
1836
1856
  return scriptHashes;
1837
1857
  });
1838
1858
  const inputs = body.inputs();
1839
1859
  const resolvedInputs = [];
1860
+ const inputOutRefs = /* @__PURE__ */ new Set();
1840
1861
  for (let i = 0; i < inputs.len(); i++) {
1841
1862
  const outRef = withCMLScope((own) => {
1842
1863
  const input = own(inputs.get(i));
1843
1864
  return own(input.transaction_id()).to_hex() + input.index().toString();
1844
1865
  });
1866
+ inputOutRefs.add(outRef);
1845
1867
  const entryLedger = this.ledger[outRef];
1846
1868
  const { entry, type } = !entryLedger ? { entry: this.mempool[outRef], type: "Mempool" } : { entry: entryLedger, type: "Ledger" };
1847
1869
  if (!entry || entry.spent) {
@@ -1881,7 +1903,9 @@ It does not exist or was already spent.`
1881
1903
  const script = CML.PlutusScript.from_v3(
1882
1904
  CML.PlutusV3Script.from_cbor_bytes(fromHex2(scriptRef.script))
1883
1905
  );
1884
- plutusHashesOptional.push(script.hash().to_hex());
1906
+ const scriptHash = script.hash().to_hex();
1907
+ plutusHashesOptional.push(scriptHash);
1908
+ plutusV3Hashes.add(scriptHash);
1885
1909
  break;
1886
1910
  }
1887
1911
  }
@@ -1891,6 +1915,7 @@ It does not exist or was already spent.`
1891
1915
  }
1892
1916
  inputs.free();
1893
1917
  const referenceInputs = body.reference_inputs();
1918
+ const nonDisjointRefInputs = [];
1894
1919
  for (let i = 0; i < (referenceInputs?.len() || 0); i++) {
1895
1920
  const outRef = withCMLScope((own) => {
1896
1921
  const input = own(referenceInputs.get(i));
@@ -1906,6 +1931,11 @@ It does not exist or was already spent.`
1906
1931
  It does not exist or was already spent.`
1907
1932
  );
1908
1933
  }
1934
+ if (inputOutRefs.has(outRef)) {
1935
+ nonDisjointRefInputs.push(
1936
+ `${entry.utxo.txHash}#${entry.utxo.outputIndex}`
1937
+ );
1938
+ }
1909
1939
  const scriptRef = entry.utxo.scriptRef;
1910
1940
  if (scriptRef) {
1911
1941
  switch (scriptRef.type) {
@@ -1934,7 +1964,9 @@ It does not exist or was already spent.`
1934
1964
  const script = CML.PlutusScript.from_v3(
1935
1965
  CML.PlutusV3Script.from_cbor_bytes(fromHex2(scriptRef.script))
1936
1966
  );
1937
- plutusHashesOptional.push(script.hash().to_hex());
1967
+ const scriptHash = script.hash().to_hex();
1968
+ plutusHashesOptional.push(scriptHash);
1969
+ plutusV3Hashes.add(scriptHash);
1938
1970
  break;
1939
1971
  }
1940
1972
  }
@@ -2361,6 +2393,23 @@ It does not exist or was already spent.`
2361
2393
  if (extraDatumHash) {
2362
2394
  throw new Error(`Extraneous plutus data. Datum hash: ${extraDatumHash}`);
2363
2395
  }
2396
+ if (nonDisjointRefInputs.length > 0) {
2397
+ const protocolMajorVersion = this.protocolParameters.protocolMajorVersion ?? DEFAULT_PROTOCOL_MAJOR_VERSION;
2398
+ const overlap = nonDisjointRefInputs.join(", ");
2399
+ if (protocolMajorVersion === 9 || protocolMajorVersion === 10) {
2400
+ throw new Error(
2401
+ `BabbageNonDisjointRefInputs: reference inputs must be disjoint from inputs at protocol version ${protocolMajorVersion}. Overlapping: ${overlap}`
2402
+ );
2403
+ }
2404
+ const runsPlutusV3 = [...consumedHashes].some(
2405
+ (hash) => plutusV3Hashes.has(hash)
2406
+ );
2407
+ if (protocolMajorVersion >= 11 && runsPlutusV3) {
2408
+ throw new Error(
2409
+ `ReferenceInputsNotDisjointFromInputs: a PlutusV3 script context cannot be built while reference inputs overlap inputs. Overlapping: ${overlap}`
2410
+ );
2411
+ }
2412
+ }
2364
2413
  resolvedInputs.forEach(({ entry, type }) => {
2365
2414
  const outRef = entry.utxo.txHash + entry.utxo.outputIndex;
2366
2415
  entry.spent = true;
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.4",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -31,8 +31,8 @@
31
31
  "@effect/schema": "^0.68.26",
32
32
  "effect": "^3.11.7",
33
33
  "@lucid-evolution/core-types": "0.3.0",
34
- "@lucid-evolution/core-utils": "0.1.17",
35
34
  "@lucid-evolution/utils": "0.1.74",
35
+ "@lucid-evolution/core-utils": "0.1.17",
36
36
  "@lucid-evolution/wallet": "0.2.2"
37
37
  },
38
38
  "devDependencies": {