@lucid-evolution/provider 0.3.0 → 0.4.1

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.
Files changed (3) hide show
  1. package/dist/index.cjs +610 -554
  2. package/dist/index.js +106 -63
  3. package/package.json +6 -10
package/dist/index.js CHANGED
@@ -89,7 +89,7 @@ var OgmiosJsonRpcError = class extends KupmiosError {
89
89
  var toKupmiosError = (cause, protocol, operation) => cause instanceof KupmiosError ? cause : new KupmiosError({ cause, protocol, operation });
90
90
 
91
91
  // src/core.ts
92
- import * as CML from "@anastasia-labs/cardano-multiplatform-lib-nodejs";
92
+ import * as CML from "@lucid-evolution/cml";
93
93
 
94
94
  // src/blockfrost.ts
95
95
  import { fromHex, sleep } from "@lucid-evolution/core-utils";
@@ -101,7 +101,7 @@ import {
101
101
  // package.json
102
102
  var package_default = {
103
103
  name: "@lucid-evolution/provider",
104
- version: "0.3.0",
104
+ version: "0.4.1",
105
105
  description: "",
106
106
  main: "./dist/index.js",
107
107
  types: "./dist/index.d.ts",
@@ -127,14 +127,10 @@ var package_default = {
127
127
  keywords: [],
128
128
  author: "",
129
129
  license: "MIT",
130
- browser: {
131
- "@anastasia-labs/cardano-multiplatform-lib-nodejs": "@anastasia-labs/cardano-multiplatform-lib-browser"
132
- },
133
130
  dependencies: {
134
- "@anastasia-labs/cardano-multiplatform-lib-browser": "6.2.0-1",
135
- "@anastasia-labs/cardano-multiplatform-lib-nodejs": "6.2.0-1",
136
131
  "@effect/platform": "^0.71.3",
137
132
  "@effect/schema": "^0.68.26",
133
+ "@lucid-evolution/cml": "workspace:*",
138
134
  "@lucid-evolution/core-types": "workspace:*",
139
135
  "@lucid-evolution/core-utils": "workspace:*",
140
136
  "@lucid-evolution/utils": "workspace:*",
@@ -150,7 +146,8 @@ var package_default = {
150
146
  };
151
147
 
152
148
  // src/internal/blockfrost.ts
153
- import { pipe, Record } from "effect";
149
+ import * as Record from "effect/Record";
150
+ import { pipe } from "effect/Function";
154
151
  import { applySingleCborEncoding } from "@lucid-evolution/utils";
155
152
  var toAditionalUTXOs = (utxos) => (utxos || []).map((utxo) => [
156
153
  {
@@ -221,16 +218,16 @@ var Blockfrost = class {
221
218
  constructor(url, projectId, options = {}) {
222
219
  this.url = url;
223
220
  this.projectId = projectId || "";
224
- const timeout = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
225
- if (!Number.isFinite(timeout) || timeout <= 0) {
221
+ const timeout3 = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
222
+ if (!Number.isFinite(timeout3) || timeout3 <= 0) {
226
223
  throw new TypeError("requestTimeoutMs must be a positive finite number.");
227
224
  }
228
- this.requestTimeoutMs = timeout;
225
+ this.requestTimeoutMs = timeout3;
229
226
  }
230
227
  /** `fetch` bounded by the provider's request timeout, combined with any caller-supplied signal. */
231
228
  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;
229
+ const timeout3 = AbortSignal.timeout(this.requestTimeoutMs);
230
+ const signal = init.signal == null ? timeout3 : typeof AbortSignal.any === "function" ? AbortSignal.any([init.signal, timeout3]) : init.signal;
234
231
  return fetch(input, { ...init, signal });
235
232
  }
236
233
  async getProtocolParameters() {
@@ -561,19 +558,17 @@ var lucid = package_default.version;
561
558
 
562
559
  // src/kupmios.ts
563
560
  import { applyDoubleCborEncoding as applyDoubleCborEncoding2, fromUnit as fromUnit2 } from "@lucid-evolution/utils";
564
- import { Schema as S3 } from "effect";
565
- import {
566
- Cause,
567
- Effect as Effect2,
568
- Exit,
569
- Layer,
570
- pipe as pipe3,
571
- Array as _Array,
572
- Schedule
573
- } from "effect";
561
+ import * as S3 from "effect/Schema";
562
+ import * as Cause from "effect/Cause";
563
+ import * as Effect2 from "effect/Effect";
564
+ import * as Exit from "effect/Exit";
565
+ import * as Layer from "effect/Layer";
566
+ import * as _Array from "effect/Array";
567
+ import * as Schedule from "effect/Schedule";
568
+ import { pipe as pipe3 } from "effect/Function";
574
569
 
575
570
  // src/internal/ogmios.ts
576
- import { Schema as S } from "effect";
571
+ import * as S from "effect/Schema";
577
572
  import { applySingleCborEncoding as applySingleCborEncoding2, fromUnit } from "@lucid-evolution/utils";
578
573
  var JSONRPCSchema = (schema) => S.Struct({
579
574
  jsonrpc: S.String,
@@ -854,7 +849,7 @@ var toOgmiosUTxOs = (utxos) => {
854
849
  };
855
850
 
856
851
  // src/internal/kupo.ts
857
- import { Schema as S2 } from "effect";
852
+ import * as S2 from "effect/Schema";
858
853
  var QuantitySchema = S2.Union(
859
854
  S2.Number.pipe(S2.filter(Number.isSafeInteger)),
860
855
  S2.String.pipe(S2.pattern(/^\d+$/))
@@ -904,13 +899,12 @@ var DelegationSchema = S2.NullOr(
904
899
  );
905
900
 
906
901
  // src/internal/HttpUtils.ts
907
- import {
908
- HttpClient,
909
- HttpClientError,
910
- HttpClientRequest,
911
- HttpClientResponse
912
- } from "@effect/platform";
913
- import { Effect, identity, pipe as pipe2 } from "effect";
902
+ import * as HttpClient from "@effect/platform/HttpClient";
903
+ import * as HttpClientError from "@effect/platform/HttpClientError";
904
+ import * as HttpClientRequest from "@effect/platform/HttpClientRequest";
905
+ import * as HttpClientResponse from "@effect/platform/HttpClientResponse";
906
+ import * as Effect from "effect/Effect";
907
+ import { identity, pipe as pipe2 } from "effect/Function";
914
908
  var filterStatusOk = (self) => self.status >= 200 && self.status < 300 ? Effect.succeed(self) : self.text.pipe(
915
909
  Effect.flatMap(
916
910
  (text) => Effect.fail(
@@ -928,15 +922,12 @@ var makeGet = (url, schema, headers) => pipe2(
928
922
  HttpClientRequest.get(url),
929
923
  // Conditional bearer token authentication
930
924
  headers ? HttpClientRequest.setHeaders(headers) : identity,
931
- // Execute the HTTP request and retrieve the response
932
925
  HttpClient.execute,
933
926
  // Ensure only 2xx responses are treated as successes.
934
927
  Effect.flatMap(filterStatusOk),
935
928
  // Parse the response body using the provided JSON schema
936
929
  // This validates and transforms the response to the expected type
937
930
  Effect.flatMap(HttpClientResponse.schemaBodyJson(schema)),
938
- // Ensure request is aborted if the program is interrupted
939
- // Prevents resource leaks and ensures clean request termination
940
931
  Effect.scoped
941
932
  );
942
933
  var makePostAsJson = (url, data, schema, headers) => pipe2(
@@ -953,8 +944,6 @@ var makePostAsJson = (url, data, schema, headers) => pipe2(
953
944
  // Parse the response body using the provided JSON schema
954
945
  // This validates and transforms the response to the expected type
955
946
  Effect.flatMap(HttpClientResponse.schemaBodyJson(schema)),
956
- // Ensure request is aborted if the program is interrupted
957
- // Prevents resource leaks and ensures clean request termination
958
947
  Effect.scoped
959
948
  );
960
949
  var makePostAsJsonResponse = (url, data, schema, headers) => pipe2(
@@ -991,27 +980,24 @@ var makePostAsUint8Array = (url, data, schema, headers) => pipe2(
991
980
  headers ? HttpClientRequest.setHeaders(headers) : identity,
992
981
  // Set the request body as a Uint8Array with CBOR content type
993
982
  HttpClientRequest.bodyUint8Array(data, "application/cbor"),
994
- // Execute the HTTP request and retrieve the response
995
983
  HttpClient.execute,
996
984
  // Ensure only 2xx responses are treated as successes.
997
985
  Effect.flatMap(filterStatusOk),
998
986
  // Parse the response body using the provided JSON schema
999
987
  // This validates and transforms the response to the expected type
1000
988
  Effect.flatMap(HttpClientResponse.schemaBodyJson(schema)),
1001
- // Ensure request is aborted if the program is interrupted
1002
- // Prevents resource leaks and ensures clean request termination
1003
989
  Effect.scoped
1004
990
  );
1005
991
 
1006
992
  // src/kupmios.ts
1007
- import { FetchHttpClient } from "@effect/platform";
993
+ import * as FetchHttpClient from "@effect/platform/FetchHttpClient";
1008
994
  var DEFAULT_REQUEST_TIMEOUT_MS2 = 3e4;
1009
995
  var DEFAULT_AWAIT_TX_TIMEOUT_MS = 16e4;
1010
- var validateTimeout = (name, timeout) => {
1011
- if (!Number.isFinite(timeout) || timeout <= 0) {
996
+ var validateTimeout = (name, timeout3) => {
997
+ if (!Number.isFinite(timeout3) || timeout3 <= 0) {
1012
998
  throw new TypeError(`${name} must be a positive finite number.`);
1013
999
  }
1014
- return timeout;
1000
+ return timeout3;
1015
1001
  };
1016
1002
  var catchProviderError = (protocol, operation) => (effect) => Effect2.catchAll(
1017
1003
  effect,
@@ -1125,11 +1111,11 @@ var Kupmios = class {
1125
1111
  async getUtxos(addressOrCredential) {
1126
1112
  const isAddress = typeof addressOrCredential === "string";
1127
1113
  const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
1128
- const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&resolve_hashes`;
1114
+ const pattern2 = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&resolve_hashes`;
1129
1115
  const schema = S3.Array(ResolvedUTxOSchema);
1130
1116
  const utxos = await runProviderEffect(
1131
1117
  pipe3(
1132
- makeGet(pattern, schema, this.options.kupoHeader),
1118
+ makeGet(pattern2, schema, this.options.kupoHeader),
1133
1119
  Effect2.map(kupmiosUtxosToUtxos),
1134
1120
  Effect2.timeout(this.requestTimeoutMs),
1135
1121
  catchProviderError("kupo", "getUtxos"),
@@ -1144,11 +1130,11 @@ var Kupmios = class {
1144
1130
  const isAddress = typeof addressOrCredential === "string";
1145
1131
  const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
1146
1132
  const { policyId, assetName } = fromUnit2(unit);
1147
- const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&resolve_hashes&policy_id=${policyId}${assetName ? `&asset_name=${assetName}` : ""}`;
1133
+ const pattern2 = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&resolve_hashes&policy_id=${policyId}${assetName ? `&asset_name=${assetName}` : ""}`;
1148
1134
  const schema = S3.Array(ResolvedUTxOSchema);
1149
1135
  const utxos = await runProviderEffect(
1150
1136
  pipe3(
1151
- makeGet(pattern, schema, this.options.kupoHeader),
1137
+ makeGet(pattern2, schema, this.options.kupoHeader),
1152
1138
  Effect2.map(kupmiosUtxosToUtxos),
1153
1139
  Effect2.timeout(this.requestTimeoutMs),
1154
1140
  catchProviderError("kupo", "getUtxosWithUnit"),
@@ -1168,11 +1154,11 @@ var Kupmios = class {
1168
1154
  const normalizedPolicyId = policyId.toLowerCase();
1169
1155
  const isAddress = typeof addressOrCredential === "string";
1170
1156
  const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
1171
- const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&resolve_hashes&policy_id=${normalizedPolicyId}`;
1157
+ const pattern2 = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&resolve_hashes&policy_id=${normalizedPolicyId}`;
1172
1158
  const schema = S3.Array(ResolvedUTxOSchema);
1173
1159
  return runProviderEffect(
1174
1160
  pipe3(
1175
- makeGet(pattern, schema, this.options.kupoHeader),
1161
+ makeGet(pattern2, schema, this.options.kupoHeader),
1176
1162
  Effect2.map(kupmiosUtxosToUtxos),
1177
1163
  Effect2.timeout(this.requestTimeoutMs),
1178
1164
  catchProviderError("kupo", "getUtxosWithPolicy"),
@@ -1184,11 +1170,11 @@ var Kupmios = class {
1184
1170
  }
1185
1171
  async getUtxoByUnit(unit) {
1186
1172
  const { policyId, assetName } = fromUnit2(unit);
1187
- const pattern = `${this.kupoUrl}/matches/${policyId}.${assetName ?? ""}?unspent&resolve_hashes`;
1173
+ const pattern2 = `${this.kupoUrl}/matches/${policyId}.${assetName ?? ""}?unspent&resolve_hashes`;
1188
1174
  const schema = S3.Array(ResolvedUTxOSchema);
1189
1175
  const utxos = await runProviderEffect(
1190
1176
  pipe3(
1191
- makeGet(pattern, schema, this.options.kupoHeader),
1177
+ makeGet(pattern2, schema, this.options.kupoHeader),
1192
1178
  Effect2.map(kupmiosUtxosToUtxos),
1193
1179
  Effect2.timeout(this.requestTimeoutMs),
1194
1180
  catchProviderError("kupo", "getUtxoByUnit"),
@@ -1266,11 +1252,11 @@ var Kupmios = class {
1266
1252
  return { poolId, rewards };
1267
1253
  }
1268
1254
  async getDatum(datumHash) {
1269
- const pattern = `${this.kupoUrl}/datums/${datumHash}`;
1255
+ const pattern2 = `${this.kupoUrl}/datums/${datumHash}`;
1270
1256
  const schema = DatumSchema;
1271
1257
  const result = await runProviderEffect(
1272
1258
  pipe3(
1273
- makeGet(pattern, schema, this.options.kupoHeader),
1259
+ makeGet(pattern2, schema, this.options.kupoHeader),
1274
1260
  Effect2.provide(this.httpLayer),
1275
1261
  Effect2.timeout(this.requestTimeoutMs),
1276
1262
  Effect2.flatMap(Effect2.fromNullable),
@@ -1282,13 +1268,13 @@ var Kupmios = class {
1282
1268
  return result.datum;
1283
1269
  }
1284
1270
  async getTransactionStatus(txHash, options = {}) {
1285
- const pattern = `${this.kupoUrl}/matches/*@${txHash}`;
1271
+ const pattern2 = `${this.kupoUrl}/matches/*@${txHash}`;
1286
1272
  const schema = S3.Array(UTxOSchema).annotations({
1287
1273
  identifier: "Array<KupmiosSchema.KupoUTxO>"
1288
1274
  });
1289
1275
  const matches = await runProviderEffect(
1290
1276
  pipe3(
1291
- makeGet(pattern, schema, this.options.kupoHeader),
1277
+ makeGet(pattern2, schema, this.options.kupoHeader),
1292
1278
  Effect2.timeout(this.requestTimeoutMs),
1293
1279
  catchProviderError("kupo", "getTransactionStatus"),
1294
1280
  Effect2.provide(this.httpLayer)
@@ -1310,13 +1296,13 @@ var Kupmios = class {
1310
1296
  };
1311
1297
  }
1312
1298
  async awaitTx(txHash, checkInterval = 2e4) {
1313
- const pattern = `${this.kupoUrl}/matches/*@${txHash}`;
1299
+ const pattern2 = `${this.kupoUrl}/matches/*@${txHash}`;
1314
1300
  const schema = S3.Array(UTxOSchema).annotations({
1315
1301
  identifier: "Array<KupmiosSchema.KupoUTxO>"
1316
1302
  });
1317
1303
  const result = await runProviderEffect(
1318
1304
  pipe3(
1319
- makeGet(pattern, schema, this.options.kupoHeader),
1305
+ makeGet(pattern2, schema, this.options.kupoHeader),
1320
1306
  Effect2.provide(this.httpLayer),
1321
1307
  Effect2.repeat({
1322
1308
  schedule: Schedule.exponential(checkInterval),
@@ -1508,6 +1494,53 @@ import {
1508
1494
  import { fromHex as fromHex2, withCMLScope } from "@lucid-evolution/core-utils";
1509
1495
  import { walletFromSeed } from "@lucid-evolution/wallet";
1510
1496
 
1497
+ // src/internal/ed25519.ts
1498
+ var nodeCrypto = (() => {
1499
+ try {
1500
+ return globalThis.process?.getBuiltinModule?.("node:crypto");
1501
+ } catch {
1502
+ return void 0;
1503
+ }
1504
+ })();
1505
+ var SPKI_PREFIX = [
1506
+ 48,
1507
+ 42,
1508
+ 48,
1509
+ 5,
1510
+ 6,
1511
+ 3,
1512
+ 43,
1513
+ 101,
1514
+ 112,
1515
+ 3,
1516
+ 33,
1517
+ 0
1518
+ ];
1519
+ var nativeVerifyEd25519 = (publicKey, message, signature) => {
1520
+ if (!nodeCrypto || publicKey.length !== 32 || signature.length !== 64) {
1521
+ return false;
1522
+ }
1523
+ if (publicKey.every((byte) => byte === 0)) return false;
1524
+ try {
1525
+ const spki = Buffer.alloc(SPKI_PREFIX.length + 32);
1526
+ spki.set(SPKI_PREFIX);
1527
+ spki.set(publicKey, SPKI_PREFIX.length);
1528
+ const key = nodeCrypto.createPublicKey({
1529
+ key: spki,
1530
+ format: "der",
1531
+ type: "spki"
1532
+ });
1533
+ return nodeCrypto.verify(null, message, key, signature);
1534
+ } catch {
1535
+ return false;
1536
+ }
1537
+ };
1538
+ var verifyEd25519 = (publicKey, message, signature) => nativeVerifyEd25519(
1539
+ publicKey.to_raw_bytes(),
1540
+ message,
1541
+ signature.to_raw_bytes()
1542
+ ) || publicKey.verify(message, signature);
1543
+
1511
1544
  // src/internal/emulator-ledger.ts
1512
1545
  import { getAddressDetails } from "@lucid-evolution/utils";
1513
1546
  var isUnorderedKey = (key) => {
@@ -2019,7 +2052,11 @@ var Emulator = class {
2019
2052
  const witness = own3(vkeyWitnesses.get(i));
2020
2053
  const publicKey = own3(witness.vkey());
2021
2054
  const keyHash = own3(publicKey.hash()).to_hex();
2022
- if (!publicKey.verify(fromHex2(txHash), own3(witness.ed25519_signature()))) {
2055
+ if (!verifyEd25519(
2056
+ publicKey,
2057
+ fromHex2(txHash),
2058
+ own3(witness.ed25519_signature())
2059
+ )) {
2023
2060
  throw new Error(`Invalid vkey witness. Key hash: ${keyHash}`);
2024
2061
  }
2025
2062
  keyHashes2.push(keyHash);
@@ -2860,8 +2897,10 @@ import { fromHex as fromHex3 } from "@lucid-evolution/core-utils";
2860
2897
  import { fromUnit as fromUnit3 } from "@lucid-evolution/utils";
2861
2898
 
2862
2899
  // src/internal/koios.ts
2863
- import { FetchHttpClient as FetchHttpClient2 } from "@effect/platform";
2864
- import { Effect as Effect3, pipe as pipe4, Schema as S4 } from "effect";
2900
+ import * as FetchHttpClient2 from "@effect/platform/FetchHttpClient";
2901
+ import * as Effect3 from "effect/Effect";
2902
+ import * as S4 from "effect/Schema";
2903
+ import { pipe as pipe4 } from "effect/Function";
2865
2904
  import { applyDoubleCborEncoding as applyDoubleCborEncoding3 } from "@lucid-evolution/utils";
2866
2905
  var ProtocolParametersSchema2 = S4.Struct({
2867
2906
  pvt_motion_no_confidence: S4.Number,
@@ -3155,8 +3194,12 @@ var getUtxosEffect = (baseUrl, addressOrCredential, headers) => {
3155
3194
  };
3156
3195
 
3157
3196
  // src/koios.ts
3158
- import { Data, Effect as Effect4, pipe as pipe5, Schedule as Schedule2, Schema as S5 } from "effect";
3159
- import { FetchHttpClient as FetchHttpClient3 } from "@effect/platform";
3197
+ import * as Data from "effect/Data";
3198
+ import * as Effect4 from "effect/Effect";
3199
+ import * as Schedule2 from "effect/Schedule";
3200
+ import * as S5 from "effect/Schema";
3201
+ import { pipe as pipe5 } from "effect/Function";
3202
+ import * as FetchHttpClient3 from "@effect/platform/FetchHttpClient";
3160
3203
  var KoiosError = class extends Data.TaggedError("KoiosError") {
3161
3204
  get message() {
3162
3205
  return `${this.cause}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucid-evolution/provider",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -21,19 +21,15 @@
21
21
  "keywords": [],
22
22
  "author": "",
23
23
  "license": "MIT",
24
- "browser": {
25
- "@anastasia-labs/cardano-multiplatform-lib-nodejs": "@anastasia-labs/cardano-multiplatform-lib-browser"
26
- },
27
24
  "dependencies": {
28
- "@anastasia-labs/cardano-multiplatform-lib-browser": "6.2.0-1",
29
- "@anastasia-labs/cardano-multiplatform-lib-nodejs": "6.2.0-1",
30
25
  "@effect/platform": "^0.71.3",
31
26
  "@effect/schema": "^0.68.26",
32
27
  "effect": "^3.11.7",
33
- "@lucid-evolution/core-types": "0.4.0",
34
- "@lucid-evolution/utils": "0.1.76",
35
- "@lucid-evolution/core-utils": "0.1.17",
36
- "@lucid-evolution/wallet": "0.3.0"
28
+ "@lucid-evolution/cml": "0.1.1",
29
+ "@lucid-evolution/core-types": "0.5.1",
30
+ "@lucid-evolution/core-utils": "0.2.1",
31
+ "@lucid-evolution/utils": "0.2.1",
32
+ "@lucid-evolution/wallet": "0.4.1"
37
33
  },
38
34
  "devDependencies": {
39
35
  "@types/node": "^20.12.8",