@odatano/core 2.0.0-rc.43 → 2.0.0-rc.45

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 (171) hide show
  1. package/@cds-models/CardanoAgentService/index.d.ts +0 -46
  2. package/@cds-models/CardanoBackendService/index.d.ts +0 -10
  3. package/@cds-models/CardanoIndexerService/index.d.ts +36 -20
  4. package/@cds-models/CardanoIndexerService/index.js +4 -0
  5. package/@cds-models/CardanoODataService/index.d.ts +19 -47
  6. package/@cds-models/CardanoSignService/index.d.ts +3 -18
  7. package/@cds-models/CardanoTransactionService/index.d.ts +9 -31
  8. package/@cds-models/CardanoWorkerService/index.d.ts +3 -19
  9. package/@cds-models/index.d.ts +17 -0
  10. package/@cds-models/index.js +2 -0
  11. package/@cds-models/odatano/cardano/index.d.ts +1 -34
  12. package/README.md +6 -6
  13. package/db/schema.cds +29 -44
  14. package/db/types.cds +22 -5
  15. package/package.json +3 -1
  16. package/scripts/migrate-slot-leader.mjs +3 -11
  17. package/scripts/migrate-txseq.mjs +3 -12
  18. package/src/index.d.ts +0 -4
  19. package/src/index.js +3 -5
  20. package/src/plugin.js +4 -8
  21. package/srv/blockchain/asset-decimals.d.ts +7 -0
  22. package/srv/blockchain/asset-decimals.js +91 -0
  23. package/srv/blockchain/backends/blockfrost-backend.d.ts +2 -10
  24. package/srv/blockchain/backends/blockfrost-backend.js +15 -21
  25. package/srv/blockchain/backends/cardano-backend.d.ts +12 -71
  26. package/srv/blockchain/backends/koios-backend.d.ts +14 -147
  27. package/srv/blockchain/backends/koios-backend.js +40 -164
  28. package/srv/blockchain/backends/odatano-backend.d.ts +1 -11
  29. package/srv/blockchain/backends/odatano-backend.js +11 -12
  30. package/srv/blockchain/backends/ogmios-backend.d.ts +13 -160
  31. package/srv/blockchain/backends/ogmios-backend.js +48 -175
  32. package/srv/blockchain/backends/ogmios-frame-guard.d.ts +2 -18
  33. package/srv/blockchain/backends/ogmios-frame-guard.js +8 -20
  34. package/srv/blockchain/cardano-client.d.ts +12 -80
  35. package/srv/blockchain/cardano-client.js +36 -88
  36. package/srv/blockchain/cardano-indexer.d.ts +12 -192
  37. package/srv/blockchain/cardano-indexer.js +132 -222
  38. package/srv/blockchain/cardano-tx-builder.d.ts +1 -28
  39. package/srv/blockchain/cardano-tx-builder.js +17 -34
  40. package/srv/blockchain/circuit-breaker.d.ts +1 -13
  41. package/srv/blockchain/circuit-breaker.js +5 -15
  42. package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +15 -0
  43. package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
  44. package/srv/blockchain/crawler/certificate-backfill.d.ts +0 -17
  45. package/srv/blockchain/crawler/certificate-backfill.js +8 -22
  46. package/srv/blockchain/crawler/crawler.d.ts +16 -93
  47. package/srv/blockchain/crawler/crawler.js +85 -160
  48. package/srv/blockchain/crawler/credential-backfill.d.ts +0 -9
  49. package/srv/blockchain/crawler/credential-backfill.js +6 -6
  50. package/srv/blockchain/crawler/hooks.d.ts +1 -5
  51. package/srv/blockchain/crawler/index.d.ts +0 -12
  52. package/srv/blockchain/crawler/index.js +6 -20
  53. package/srv/blockchain/crawler/sync-state.d.ts +6 -44
  54. package/srv/blockchain/crawler/sync-state.js +18 -53
  55. package/srv/blockchain/crawler/transaction-backfill.d.ts +0 -11
  56. package/srv/blockchain/crawler/transaction-backfill.js +11 -30
  57. package/srv/blockchain/crawler/utxo-set-import.d.ts +1 -30
  58. package/srv/blockchain/crawler/utxo-set-import.js +27 -53
  59. package/srv/blockchain/ledger-state.d.ts +10 -54
  60. package/srv/blockchain/ledger-state.js +11 -27
  61. package/srv/blockchain/pending-spends.d.ts +0 -12
  62. package/srv/blockchain/pending-spends.js +4 -12
  63. package/srv/blockchain/request-coalescer.d.ts +2 -16
  64. package/srv/blockchain/request-coalescer.js +2 -16
  65. package/srv/blockchain/signing/cose-verifier.d.ts +0 -9
  66. package/srv/blockchain/signing/cose-verifier.js +4 -10
  67. package/srv/blockchain/signing/external-signer.d.ts +1 -4
  68. package/srv/blockchain/signing/external-signer.js +2 -8
  69. package/srv/blockchain/signing/hsm-signer.d.ts +6 -18
  70. package/srv/blockchain/signing/hsm-signer.js +16 -28
  71. package/srv/blockchain/signing/signature-verifier.d.ts +1 -8
  72. package/srv/blockchain/signing/signature-verifier.js +9 -19
  73. package/srv/blockchain/signing/submission-finalizer.d.ts +10 -16
  74. package/srv/blockchain/signing/submission-finalizer.js +48 -19
  75. package/srv/blockchain/stored-chain.d.ts +1 -14
  76. package/srv/blockchain/stored-chain.js +3 -8
  77. package/srv/blockchain/transaction-building/buildooor-fee-patch.d.ts +0 -4
  78. package/srv/blockchain/transaction-building/buildooor-fee-patch.js +4 -9
  79. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +7 -150
  80. package/srv/blockchain/transaction-building/buildooor-tx.js +91 -196
  81. package/srv/blockchain/transaction-building/caller-datums.d.ts +0 -14
  82. package/srv/blockchain/transaction-building/caller-datums.js +3 -9
  83. package/srv/blockchain/transaction-building/cardano-tx.d.ts +1 -4
  84. package/srv/blockchain/wallet-worker/build-request.d.ts +0 -5
  85. package/srv/blockchain/wallet-worker/build-request.js +6 -9
  86. package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +5 -23
  87. package/srv/blockchain/wallet-worker/confirmation-tracker.js +16 -20
  88. package/srv/blockchain/wallet-worker/index.d.ts +1 -1
  89. package/srv/blockchain/wallet-worker/index.js +3 -5
  90. package/srv/blockchain/wallet-worker/job-store.d.ts +15 -65
  91. package/srv/blockchain/wallet-worker/job-store.js +0 -0
  92. package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -10
  93. package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -12
  94. package/srv/blockchain/wallet-worker/signers.d.ts +3 -11
  95. package/srv/blockchain/wallet-worker/signers.js +3 -6
  96. package/srv/blockchain/wallet-worker/wallet-worker.d.ts +3 -21
  97. package/srv/blockchain/wallet-worker/wallet-worker.js +47 -54
  98. package/srv/cardano-agent-service.cds +123 -146
  99. package/srv/cardano-agent-service.js +2 -5
  100. package/srv/cardano-backend-service.cds +10 -17
  101. package/srv/cardano-backend-service.js +7 -12
  102. package/srv/cardano-indexer-service.cds +35 -37
  103. package/srv/cardano-indexer-service.d.ts +5 -1
  104. package/srv/cardano-indexer-service.js +64 -33
  105. package/srv/cardano-service.cds +56 -40
  106. package/srv/cardano-service.js +42 -69
  107. package/srv/cardano-sign-service.cds +14 -23
  108. package/srv/cardano-sign-service.js +18 -24
  109. package/srv/cardano-tx-service.cds +27 -29
  110. package/srv/cardano-tx-service.js +60 -122
  111. package/srv/cardano-worker-service.cds +109 -125
  112. package/srv/cardano-worker-service.js +21 -31
  113. package/srv/cbor/cip68.d.ts +13 -0
  114. package/srv/cbor/cip68.js +56 -0
  115. package/srv/cbor/index.d.ts +1 -0
  116. package/srv/cbor/index.js +6 -1
  117. package/srv/cbor/parse.d.ts +3 -18
  118. package/srv/cbor/parse.js +2 -7
  119. package/srv/cbor/plutus-data-json.d.ts +0 -4
  120. package/srv/server.d.ts +5 -36
  121. package/srv/server.js +30 -51
  122. package/srv/utils/agent-grants-config.d.ts +0 -18
  123. package/srv/utils/agent-grants-config.js +6 -13
  124. package/srv/utils/agent-grants.d.ts +14 -68
  125. package/srv/utils/agent-grants.js +42 -60
  126. package/srv/utils/agent-token-auth.d.ts +0 -5
  127. package/srv/utils/agent-token-auth.js +2 -5
  128. package/srv/utils/backend-request-handler.d.ts +1 -1
  129. package/srv/utils/collections.d.ts +1 -4
  130. package/srv/utils/collections.js +1 -4
  131. package/srv/utils/const.d.ts +0 -18
  132. package/srv/utils/const.js +7 -18
  133. package/srv/utils/crypto.js +3 -5
  134. package/srv/utils/db-indexes.d.ts +2 -0
  135. package/srv/utils/db-indexes.js +22 -9
  136. package/srv/utils/db-sanitize.d.ts +1 -8
  137. package/srv/utils/db-sanitize.js +3 -8
  138. package/srv/utils/epoch-slots.d.ts +1 -8
  139. package/srv/utils/epoch-slots.js +3 -8
  140. package/srv/utils/error-codes.d.ts +0 -4
  141. package/srv/utils/error-codes.js +2 -4
  142. package/srv/utils/errors.d.ts +2 -22
  143. package/srv/utils/errors.js +13 -27
  144. package/srv/utils/liveness.d.ts +0 -4
  145. package/srv/utils/liveness.js +2 -4
  146. package/srv/utils/mappers.d.ts +0 -37
  147. package/srv/utils/mappers.js +22 -39
  148. package/srv/utils/network-context.js +2 -4
  149. package/srv/utils/paging.d.ts +31 -0
  150. package/srv/utils/paging.js +43 -0
  151. package/srv/utils/pg-inline-json.js +3 -7
  152. package/srv/utils/pg-order-nulls.js +2 -5
  153. package/srv/utils/plutus-placeholders.d.ts +0 -13
  154. package/srv/utils/plutus-placeholders.js +6 -13
  155. package/srv/utils/rate-limiter.d.ts +0 -8
  156. package/srv/utils/rate-limiter.js +2 -4
  157. package/srv/utils/reference-script.d.ts +0 -18
  158. package/srv/utils/reference-script.js +8 -19
  159. package/srv/utils/service-events.d.ts +0 -4
  160. package/srv/utils/service-events.js +2 -4
  161. package/srv/utils/signing-helper.d.ts +1 -8
  162. package/srv/utils/signing-helper.js +3 -8
  163. package/srv/utils/tx-build-helper.d.ts +2 -32
  164. package/srv/utils/tx-build-helper.js +26 -40
  165. package/srv/utils/tx-request-parsers.d.ts +1 -25
  166. package/srv/utils/tx-request-parsers.js +10 -25
  167. package/srv/utils/tx-utils.d.ts +0 -8
  168. package/srv/utils/tx-utils.js +10 -13
  169. package/srv/utils/types.d.ts +2 -37
  170. package/srv/utils/validators.d.ts +0 -4
  171. package/srv/utils/validators.js +2 -4
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LATEST_WINDOW = void 0;
4
+ exports.pageOf = pageOf;
5
+ exports.pageRows = pageRows;
6
+ exports.byKey = byKey;
7
+ exports.byOutRef = byOutRef;
8
+ exports.sortAssetHistory = sortAssetHistory;
9
+ exports.latestWindowPage = latestWindowPage;
10
+ const errors_1 = require("./errors");
11
+ /** The page a request asks for, with the operation's default limit when none is given. */
12
+ function pageOf(data, defaultLimit) {
13
+ return { limit: data.limit ?? defaultLimit, skip: data.skip ?? 0 };
14
+ }
15
+ /** The rows of one page out of a list that is already in its final order. */
16
+ function pageRows(rows, page) {
17
+ return rows.slice(page.skip, page.skip + page.limit);
18
+ }
19
+ /** Rows sorted by a string key; a fixed order keeps pages stable across calls. */
20
+ function byKey(rows, keyOf) {
21
+ return [...rows].sort((a, b) => keyOf(a).localeCompare(keyOf(b)));
22
+ }
23
+ /** UTxOs in output-reference order: tx hash, then output index. */
24
+ function byOutRef(rows) {
25
+ return [...rows].sort((a, b) => String(a.hash ?? '').localeCompare(String(b.hash ?? '')) || Number(a.index ?? 0) - Number(b.index ?? 0));
26
+ }
27
+ /** Newest first. Koios rows carry only a time, Blockfrost rows only a height; the tx hash breaks ties. */
28
+ function sortAssetHistory(rows) {
29
+ return [...rows].sort((a, b) => Number(b.blockHeight ?? -1) - Number(a.blockHeight ?? -1)
30
+ || Number(b.blockTime ?? -1) - Number(a.blockTime ?? -1)
31
+ || String(b.txHash ?? '').localeCompare(String(a.txHash ?? '')));
32
+ }
33
+ /** Operations over a provider's newest rows reach at most this far. */
34
+ exports.LATEST_WINDOW = 100;
35
+ /** Page over the newest LATEST_WINDOW rows; a page reaching past them is a 400. */
36
+ function latestWindowPage(req, ctx, defaultLimit) {
37
+ const page = pageOf(req.data, defaultLimit);
38
+ if (page.skip + page.limit > exports.LATEST_WINDOW) {
39
+ (0, errors_1.rejectInvalid)(req, ctx, `skip + limit must not exceed ${exports.LATEST_WINDOW}`, 'skip');
40
+ }
41
+ return page;
42
+ }
43
+ //# sourceMappingURL=paging.js.map
@@ -5,13 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.isInlineRowStream = isInlineRowStream;
7
7
  exports.installPostgresInlineJson = installPostgresInlineJson;
8
- /**
9
- * Bulk INSERT/UPSERT on PostgreSQL: send the rows as one text parameter.
10
- * @cap-js/postgres turns every `.entries()` row list into a stream and ships it through a
11
- * per-transaction temp table (`CREATE TEMP TABLE` + `COPY`), three round trips per write plus a
12
- * table created and dropped per transaction. Row lists built from in-memory arrays are drained
13
- * into a string instead; streams a caller passes in (media) keep the driver's path.
14
- */
8
+ // Sends bulk INSERT and UPSERT rows on PostgreSQL as one text parameter. The driver default
9
+ // streams them through a temp table, which costs three round trips per write.
10
+ // Streams a caller passes in keep the driver's path.
15
11
  const cds_1 = __importDefault(require("@sap/cds"));
16
12
  const stream_1 = require("stream");
17
13
  const logger = cds_1.default.log('PgInlineJson');
@@ -5,11 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.stripNullsForNotNull = stripNullsForNotNull;
7
7
  exports.installPostgresOrderNulls = installPostgresOrderNulls;
8
- /**
9
- * ORDER BY on PostgreSQL: drop the NULLS clause for columns that cannot be NULL.
10
- * @cap-js/postgres renders `ASC NULLS FIRST` / `DESC NULLS LAST`, the opposite of a btree index's
11
- * placement, so `$top` reads sorted the whole table; key, `not null` and `@cds.valid.from` columns are exempt.
12
- */
8
+ // Drops the NULLS clause from ORDER BY on PostgreSQL for columns that cannot be NULL.
9
+ // The driver's NULLS placement is the opposite of the btree index, so `$top` would sort the whole table.
13
10
  const cds_1 = __importDefault(require("@sap/cds"));
14
11
  const logger = cds_1.default.log('PgOrderNulls');
15
12
  const INSTALLED = Symbol.for('odatano.pgOrderNulls');
@@ -1,8 +1,4 @@
1
1
  import type { JSONValue } from './types';
2
- /**
3
- * PlutusData-JSON input-index placeholder `__INPUT_IDX:<64-hex txHash>#<outputIndex>__`; must be the
4
- * entire `int` field value. Hash case-insensitive, normalized to lowercase at the use site.
5
- */
6
2
  export declare const INPUT_IDX_REGEX: RegExp;
7
3
  /** Reference-input index placeholder `__REF_IDX:<64-hex txHash>#<outputIndex>__`, same rules as INPUT_IDX_REGEX. */
8
4
  export declare const REF_IDX_REGEX: RegExp;
@@ -26,17 +22,8 @@ export interface ResolveContext {
26
22
  /** Withdrawal credential hashes in ledger order; absent where the build does not support `__WDRL_IDX__`. */
27
23
  sortedWithdrawals?: string[];
28
24
  }
29
- /**
30
- * Replicates Buildooor's input sort (ledger CBOR-set order): txHash bytes, then outputIndex asc.
31
- * The ledger orders reference inputs the same way.
32
- */
33
25
  export declare function sortInputsLikeBuildooor<T extends InputRef>(refs: T[]): T[];
34
26
  /** Ledger order of withdrawals: script credentials before key credentials, then hash bytes. */
35
27
  export declare function sortWithdrawalsLikeLedger<T extends WithdrawalCredential>(entries: T[]): T[];
36
- /**
37
- * Replaces `{int: "__INPUT_IDX:…__"}`, `{int: "__REF_IDX:…__"}` and `{int: "__WDRL_IDX:…__"}` leaves with
38
- * the position in the matching list. Only `int` fields are inspected (`bytes` may legitimately contain
39
- * `__`); an unknown ref throws TransactionValidationError.
40
- */
41
28
  export declare function resolveIndexPlaceholders(node: JSONValue, ctx: ResolveContext): JSONValue;
42
29
  //# sourceMappingURL=plutus-placeholders.d.ts.map
@@ -5,20 +5,16 @@ exports.sortInputsLikeBuildooor = sortInputsLikeBuildooor;
5
5
  exports.sortWithdrawalsLikeLedger = sortWithdrawalsLikeLedger;
6
6
  exports.resolveIndexPlaceholders = resolveIndexPlaceholders;
7
7
  const errors_1 = require("./errors");
8
- /**
9
- * PlutusData-JSON input-index placeholder `__INPUT_IDX:<64-hex txHash>#<outputIndex>__`; must be the
10
- * entire `int` field value. Hash case-insensitive, normalized to lowercase at the use site.
11
- */
8
+ // Input-index placeholder; must be the entire `int` field value.
9
+ // The hash is case-insensitive and lowercased at the use site.
12
10
  exports.INPUT_IDX_REGEX = /^__INPUT_IDX:([0-9a-fA-F]{64})#(\d+)__$/;
13
11
  /** Reference-input index placeholder `__REF_IDX:<64-hex txHash>#<outputIndex>__`, same rules as INPUT_IDX_REGEX. */
14
12
  exports.REF_IDX_REGEX = /^__REF_IDX:([0-9a-fA-F]{64})#(\d+)__$/;
15
13
  /** Withdrawal index placeholder `__WDRL_IDX:<56-hex credential hash>__`, same rules as INPUT_IDX_REGEX. */
16
14
  exports.WDRL_IDX_REGEX = /^__WDRL_IDX:([0-9a-fA-F]{56})__$/;
17
15
  const MAX_WALK_DEPTH = 64;
18
- /**
19
- * Replicates Buildooor's input sort (ledger CBOR-set order): txHash bytes, then outputIndex asc.
20
- * The ledger orders reference inputs the same way.
21
- */
16
+ // Ledger set order as Buildooor sorts it: txHash bytes, then outputIndex.
17
+ // The ledger orders reference inputs the same way.
22
18
  function sortInputsLikeBuildooor(refs) {
23
19
  const copy = refs.slice();
24
20
  copy.sort((a, b) => {
@@ -41,11 +37,8 @@ function sortWithdrawalsLikeLedger(entries) {
41
37
  });
42
38
  return copy;
43
39
  }
44
- /**
45
- * Replaces `{int: "__INPUT_IDX:…__"}`, `{int: "__REF_IDX:…__"}` and `{int: "__WDRL_IDX:…__"}` leaves with
46
- * the position in the matching list. Only `int` fields are inspected (`bytes` may legitimately contain
47
- * `__`); an unknown ref throws TransactionValidationError.
48
- */
40
+ // Replaces INPUT_IDX, REF_IDX and WDRL_IDX placeholders with the position in the matching list.
41
+ // Only `int` fields are inspected, since `bytes` may contain `__`. An unknown ref throws.
49
42
  function resolveIndexPlaceholders(node, ctx) {
50
43
  return walk(node, ctx, 0);
51
44
  }
@@ -6,20 +6,12 @@ export interface RateLimiterOptions {
6
6
  maxKeys?: number;
7
7
  /** Stale-key sweep interval (default 60 000 ms). */
8
8
  sweepIntervalMs?: number;
9
- /**
10
- * Max distinct keys one group (key up to its first ':', the principal) may hold (default 64),
11
- * so one caller's made-up scopes cannot evict other callers' windows.
12
- */
13
9
  maxKeysPerGroup?: number;
14
10
  }
15
11
  export interface RateCheckResult {
16
12
  allowed: boolean;
17
13
  retryAfterMs: number;
18
14
  }
19
- /**
20
- * Rate-limit key `principal:scope` for a CAP request; the principal is the user, else the client
21
- * address (last resort: batch parts and proxies hide it). No ':' in the principal, it is the group.
22
- */
23
15
  export declare function principalRateKey(req: unknown, scope: string): string;
24
16
  export declare class RateLimiter {
25
17
  private readonly windowMs;
@@ -8,10 +8,8 @@ function groupOf(key) {
8
8
  const i = key.indexOf(':');
9
9
  return i < 0 ? key : key.slice(0, i);
10
10
  }
11
- /**
12
- * Rate-limit key `principal:scope` for a CAP request; the principal is the user, else the client
13
- * address (last resort: batch parts and proxies hide it). No ':' in the principal, it is the group.
14
- */
11
+ // Key `principal:scope` for a CAP request. The principal is the user, else the client address.
12
+ // Colons in an IPv6 address are replaced, because the text before the first ':' is the group.
15
13
  function principalRateKey(req, scope) {
16
14
  const r = req;
17
15
  const user = r?.user?.id;
@@ -8,30 +8,12 @@ export interface ReferenceScriptInfo {
8
8
  type: ReferenceScriptType;
9
9
  cbor: string | null;
10
10
  }
11
- /**
12
- * Provider spelling of a script type to ours: Ogmios `plutus:v3` / `native`, Koios and cardano-cli
13
- * `plutusV3` / `PlutusScriptV3` / `timelock` / `multisig` / `SimpleScript`. Null when unknown.
14
- */
15
11
  export declare function normalizeScriptType(raw: unknown): ReferenceScriptType | null;
16
12
  /** Ledger script hash: blake2b-224 over the language tag byte followed by the script bytes. */
17
13
  export declare function referenceScriptHash(type: ReferenceScriptType, bytes: Uint8Array): string;
18
- /**
19
- * Bytes the ledger charges for a reference script: for Plutus the script bytestring as the
20
- * compiler emits it, for a native script its CBOR.
21
- */
22
14
  export declare function referenceScriptSize(script: Script): number;
23
- /**
24
- * A Plutus script object of the given ledger size and no content: lets the fee count the bytes of
25
- * a reference script whose bytes are not at hand (hash and size only). Never a witness, never
26
- * serialized; its hash matches no real script.
27
- */
28
15
  export declare function sizePlaceholderScript(size: number): Script;
29
16
  /** Hash, size and type of an Ogmios `script` object (`{ language, cbor }`); null without one. */
30
17
  export declare function ogmiosReferenceScript(script: unknown): ReferenceScriptInfo | null;
31
- /**
32
- * Hash, size and type of a cardano-cli dump's `referenceScript`. The Plutus TextEnvelope
33
- * `cborHex` wraps the script bytestring once more than the ledger does; the inner bytes are
34
- * what the ledger hashes and charges for. A native script is given as its JSON.
35
- */
36
18
  export declare function cliReferenceScript(ref: unknown): ReferenceScriptInfo | null;
37
19
  //# sourceMappingURL=reference-script.d.ts.map
@@ -10,10 +10,8 @@ const crypto_1 = require("@harmoniclabs/crypto");
10
10
  const cbor_1 = require("@harmoniclabs/cbor");
11
11
  const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
12
12
  const LANGUAGE_TAG = { native: 0, plutusV1: 1, plutusV2: 2, plutusV3: 3 };
13
- /**
14
- * Provider spelling of a script type to ours: Ogmios `plutus:v3` / `native`, Koios and cardano-cli
15
- * `plutusV3` / `PlutusScriptV3` / `timelock` / `multisig` / `SimpleScript`. Null when unknown.
16
- */
13
+ // Maps provider spellings such as `plutus:v3`, `PlutusScriptV3`, `timelock` or `SimpleScript`.
14
+ // Null when unknown.
17
15
  function normalizeScriptType(raw) {
18
16
  if (typeof raw !== 'string')
19
17
  return null;
@@ -27,10 +25,7 @@ function referenceScriptHash(type, bytes) {
27
25
  const tagged = Uint8Array.from(Buffer.concat([Buffer.from([LANGUAGE_TAG[type]]), Buffer.from(bytes)]));
28
26
  return Buffer.from((0, crypto_1.blake2b_224)(tagged)).toString('hex');
29
27
  }
30
- /**
31
- * Bytes the ledger charges for a reference script: for Plutus the script bytestring as the
32
- * compiler emits it, for a native script its CBOR.
33
- */
28
+ // Ledger-charged size: the compiler's script bytestring for Plutus, the CBOR for native scripts.
34
29
  function referenceScriptSize(script) {
35
30
  if (script.type === 'NativeScript')
36
31
  return script.bytes.length;
@@ -39,11 +34,8 @@ function referenceScriptSize(script) {
39
34
  const header = n < 24 ? 1 : n < 0x100 ? 2 : n < 0x10000 ? 3 : 5;
40
35
  return n + header;
41
36
  }
42
- /**
43
- * A Plutus script object of the given ledger size and no content: lets the fee count the bytes of
44
- * a reference script whose bytes are not at hand (hash and size only). Never a witness, never
45
- * serialized; its hash matches no real script.
46
- */
37
+ // Empty script of the given ledger size, so the fee counts a reference script known by size only.
38
+ // Never a witness, never serialized. Its hash matches no real script.
47
39
  function sizePlaceholderScript(size) {
48
40
  for (let n = Math.max(0, size - 5); n <= size; n++) {
49
41
  const header = n < 24 ? 1 : n < 0x100 ? 2 : n < 0x10000 ? 3 : 5;
@@ -61,11 +53,8 @@ function ogmiosReferenceScript(script) {
61
53
  const bytes = Buffer.from(s.cbor, 'hex');
62
54
  return { hash: referenceScriptHash(type, bytes), size: bytes.length, type, cbor: type === 'native' ? null : s.cbor };
63
55
  }
64
- /**
65
- * Hash, size and type of a cardano-cli dump's `referenceScript`. The Plutus TextEnvelope
66
- * `cborHex` wraps the script bytestring once more than the ledger does; the inner bytes are
67
- * what the ledger hashes and charges for. A native script is given as its JSON.
68
- */
56
+ // cardano-cli's Plutus `cborHex` wraps the script once more than the ledger does.
57
+ // The ledger hashes and charges the inner bytes. A native script is given as JSON.
69
58
  function cliReferenceScript(ref) {
70
59
  const r = ref;
71
60
  const script = r?.script;
@@ -82,7 +71,7 @@ function cliReferenceScript(ref) {
82
71
  return { hash: referenceScriptHash(type, inner), size: inner.length, type, cbor: inner.toString('hex') };
83
72
  }
84
73
  if (type === 'native' || r?.scriptLanguage?.startsWith('SimpleScript')) {
85
- // the cli prints a native script as its JSON (sig / all / any / atLeast / after / before)
74
+ // cardano-cli prints a native script as JSON.
86
75
  const native = cardano_ledger_ts_1.Script.native(script);
87
76
  return { hash: native.hash.toString(), size: native.bytes.length, type: 'native', cbor: null };
88
77
  }
@@ -1,6 +1,2 @@
1
- /**
2
- * Emits a declared CAP service event in-process (no broker needed). Never throws, never blocks,
3
- * silent when the service is not served yet. Callers must emit AFTER their transaction commits.
4
- */
5
1
  export declare function emitServiceEvent(serviceName: string, event: string, data: Record<string, unknown>): void;
6
2
  //# sourceMappingURL=service-events.d.ts.map
@@ -6,10 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.emitServiceEvent = emitServiceEvent;
7
7
  const cds_1 = __importDefault(require("@sap/cds"));
8
8
  const logger = cds_1.default.log('ServiceEvents');
9
- /**
10
- * Emits a declared CAP service event in-process (no broker needed). Never throws, never blocks,
11
- * silent when the service is not served yet. Callers must emit AFTER their transaction commits.
12
- */
9
+ // Emits a CAP service event in-process. Never throws and is silent before the service is served.
10
+ // Callers must emit after their transaction commits.
13
11
  function emitServiceEvent(serviceName, event, data) {
14
12
  const srv = cds_1.default.services?.[serviceName];
15
13
  if (!srv?.emit)
@@ -1,12 +1,5 @@
1
- /**
2
- * Combine an unsigned tx with the witness set a CIP-30 `signTx()` returns into a submittable signed tx.
3
- * @returns complete signed transaction CBOR (hex)
4
- */
1
+ /** Merges the witness set from CIP-30 `signTx()` into the unsigned tx. Returns signed CBOR hex. */
5
2
  export declare function combineTransactionWithWitnesses(unsignedTxCbor: string, witnessSetCbor: string): string;
6
- /**
7
- * True when the CBOR is a CIP-30 witness set (map) rather than a full transaction (array).
8
- * Reads the major type of the first byte only; a malformed map fails later in the combine step.
9
- */
10
3
  export declare function isWitnessSetCbor(cborHex: string): boolean;
11
4
  /** The signed transaction: as given, or the unsigned one plus a CIP-30 witness set. */
12
5
  export declare function toSignedTransaction(unsignedTxCbor: string | null | undefined, signedTxOrWitnessSet: string): string;
@@ -11,10 +11,7 @@ const cbor_1 = require("@harmoniclabs/cbor");
11
11
  const uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
12
12
  const errors_1 = require("./errors");
13
13
  const logger = cds_1.default.log('SigningHelper');
14
- /**
15
- * Combine an unsigned tx with the witness set a CIP-30 `signTx()` returns into a submittable signed tx.
16
- * @returns complete signed transaction CBOR (hex)
17
- */
14
+ /** Merges the witness set from CIP-30 `signTx()` into the unsigned tx. Returns signed CBOR hex. */
18
15
  function combineTransactionWithWitnesses(unsignedTxCbor, witnessSetCbor) {
19
16
  try {
20
17
  // Raw CBOR level: no Cardano type validation, preserves all encoding metadata
@@ -63,10 +60,8 @@ function combineTransactionWithWitnesses(unsignedTxCbor, witnessSetCbor) {
63
60
  throw new errors_1.TransactionValidationError(`Failed to combine transaction with witnesses: ${msg}`);
64
61
  }
65
62
  }
66
- /**
67
- * True when the CBOR is a CIP-30 witness set (map) rather than a full transaction (array).
68
- * Reads the major type of the first byte only; a malformed map fails later in the combine step.
69
- */
63
+ // A witness set is a CBOR map, a full transaction an array. Only the first byte is read.
64
+ // A malformed map fails later in the combine step.
70
65
  function isWitnessSetCbor(cborHex) {
71
66
  if (!/^[0-9a-f]{2}/i.test(cborHex))
72
67
  return false;
@@ -7,10 +7,7 @@ export declare function getLovelace(u: OdatanoUtxo): bigint;
7
7
  export declare function isCollateralCandidate(u: OdatanoUtxo): boolean;
8
8
  /** Throws MixedAssetsError when the UTxO carries non-ADA assets. */
9
9
  export declare function assertAdaOnly(u: OdatanoUtxo): void;
10
- /**
11
- * Transaction hash of a signed or unsigned tx CBOR: blake2b-256 over the body bytes, so witnesses do not affect it.
12
- * @returns 64-char hex string
13
- */
10
+ /** Transaction hash: blake2b-256 over the body bytes, so witnesses do not affect it. */
14
11
  export declare function getTxHashFromCbor(txCbor: string): string;
15
12
  /** Cache-invalidation targets of a submitted transaction (see extractTxCacheTargets). */
16
13
  export interface TxCacheTargets {
@@ -22,16 +19,7 @@ export interface TxCacheTargets {
22
19
  /** Distinct bech32 addresses receiving outputs (sender change + recipients). */
23
20
  outputAddresses: string[];
24
21
  }
25
- /**
26
- * Consumed input refs and output addresses of a tx CBOR: the UTxO-cache rows a submit makes stale.
27
- * Outputs whose address bytes cannot be decoded (Byron) are skipped.
28
- */
29
22
  export declare function extractTxCacheTargets(txCbor: string): TxCacheTargets;
30
- /**
31
- * Maps Buildooor errors to typed BackendErrors. Asset unit is parsed from "not enough <unit>" when not given;
32
- * `context` (e.g. the collateral partition) is appended to the consumer-facing message.
33
- * `requestedOutputs` is the number of outputs the caller asked for; Buildooor appends the change after them.
34
- */
35
23
  export declare function mapBuilderError(err: unknown, assetUnit?: string, context?: string, requestedOutputs?: number): never;
36
24
  /** Split an asset unit into policyId (56 hex chars) and assetName (remaining hex). */
37
25
  export declare function parseAssetUnit(assetUnit: string): {
@@ -40,29 +28,11 @@ export declare function parseAssetUnit(assetUnit: string): {
40
28
  };
41
29
  /** JSON (`int` / `bytes` / `list` / `map` / `constructor`|`constr`) to Buildooor PlutusData. */
42
30
  export declare function jsonToPlutusData(json: JSONValue): Data;
43
- /**
44
- * Backend inline datum to lowercase CBOR hex: hex string (Blockfrost), `{ bytes, value }` wrapper (Koios)
45
- * or raw PlutusData JSON. Returns null on unknown shapes instead of throwing.
46
- */
47
31
  export declare function inlineDatumToHex(datum: unknown): string | null;
48
32
  /** UPLC type tag for a typed script parameter (see {@link encodeScriptParam}). */
49
33
  export type ScriptParamUplcType = 'data' | 'bytes' | 'int' | 'bool' | 'unit';
50
- /**
51
- * Encode a script parameter as the UPLC constant of the type the validator expects: typed
52
- * `{ uplc: data|bytes|int|bool|unit, value }` for native-typed params, or a bare PlutusData object
53
- * (Aiken / CIP-57 convention) as shorthand for `uplc: "data"`.
54
- */
55
34
  export declare function encodeScriptParam(param: JSONValue): UPLCConst;
56
- /**
57
- * Apply parameters to a parameterized PlutusV3 script (CBOR-wrapped flat UPLC): each parameter becomes a
58
- * UPLC Application around the program body, encoded via {@link encodeScriptParam}.
59
- * @returns CBOR hex of the applied script
60
- */
35
+ /** Wraps the program body in one UPLC application per parameter. Returns the script CBOR hex. */
61
36
  export declare function applyScriptParameters(scriptHex: string, params: JSONValue[]): string;
62
- /**
63
- * Script hash of a Plutus script, CBOR-wrapped once or twice as cardano-cli writes it:
64
- * blake2b-224 over the language byte and the once-wrapped CBOR. The version cannot be read
65
- * from the script, so the caller names it.
66
- */
67
37
  export declare function plutusScriptHash(scriptHex: string, version: 'plutusV2' | 'plutusV3'): string;
68
38
  //# sourceMappingURL=tx-build-helper.d.ts.map
@@ -36,10 +36,7 @@ function assertAdaOnly(u) {
36
36
  throw new errors_1.MixedAssetsError(`${u.txHash}#${u.outputIndex}`, nonAda.map(a => a.unit));
37
37
  }
38
38
  }
39
- /**
40
- * Transaction hash of a signed or unsigned tx CBOR: blake2b-256 over the body bytes, so witnesses do not affect it.
41
- * @returns 64-char hex string
42
- */
39
+ /** Transaction hash: blake2b-256 over the body bytes, so witnesses do not affect it. */
43
40
  function getTxHashFromCbor(txCbor) {
44
41
  if (!txCbor || typeof txCbor !== 'string') {
45
42
  throw new Error('Invalid input: txCbor must be a non-empty string');
@@ -61,10 +58,8 @@ function getTxHashFromCbor(txCbor) {
61
58
  throw new errors_1.TransactionValidationError('Failed to parse transaction CBOR', err, error_codes_1.ERROR_CODES.TX_PARSE_FAILED);
62
59
  }
63
60
  }
64
- /**
65
- * Consumed input refs and output addresses of a tx CBOR: the UTxO-cache rows a submit makes stale.
66
- * Outputs whose address bytes cannot be decoded (Byron) are skipped.
67
- */
61
+ // Consumed inputs and output addresses, i.e. the UTxO-cache rows a submit makes stale.
62
+ // Outputs with undecodable Byron addresses are skipped.
68
63
  function extractTxCacheTargets(txCbor) {
69
64
  let body;
70
65
  try {
@@ -112,11 +107,8 @@ function extractTxCacheTargets(txCbor) {
112
107
  }
113
108
  return { inputs, outputAddresses: [...outputAddresses] };
114
109
  }
115
- /**
116
- * Maps Buildooor errors to typed BackendErrors. Asset unit is parsed from "not enough <unit>" when not given;
117
- * `context` (e.g. the collateral partition) is appended to the consumer-facing message.
118
- * `requestedOutputs` is the number of outputs the caller asked for; Buildooor appends the change after them.
119
- */
110
+ // Maps Buildooor errors to typed BackendErrors. `context` is appended to the message.
111
+ // `requestedOutputs` counts the caller's outputs. Buildooor appends the change after them.
120
112
  function mapBuilderError(err, assetUnit, context, requestedOutputs) {
121
113
  // Typed errors keep their own status and payload
122
114
  if (err instanceof errors_1.BackendError) {
@@ -198,18 +190,22 @@ function normalizeConstructorKey(obj) {
198
190
  /** JSON (`int` / `bytes` / `list` / `map` / `constructor`|`constr`) to Buildooor PlutusData. */
199
191
  function jsonToPlutusData(json) {
200
192
  if (json === null || json === undefined) {
201
- throw new Error('PlutusData JSON cannot be null or undefined');
193
+ throw new errors_1.TransactionValidationError('PlutusData JSON cannot be null or undefined');
202
194
  }
203
195
  if (typeof json === 'object' && !Array.isArray(json)) {
204
196
  const normalized = normalizeConstructorKey(json);
205
- return (0, plutus_data_1.dataFromJson)(normalized);
197
+ try {
198
+ return (0, plutus_data_1.dataFromJson)(normalized);
199
+ }
200
+ catch (err) {
201
+ // request data: a shape Buildooor cannot read is the caller's mistake, not a server fault
202
+ throw new errors_1.TransactionValidationError(`Invalid PlutusData JSON: ${err instanceof Error ? err.message : String(err)}`, err);
203
+ }
206
204
  }
207
- throw new Error(`Unsupported PlutusData JSON format: expected an object with "int", "bytes", "list", "map", or "constructor" key`);
205
+ throw new errors_1.TransactionValidationError(`Unsupported PlutusData JSON format: expected an object with "int", "bytes", "list", "map", or "constructor" key`);
208
206
  }
209
- /**
210
- * Backend inline datum to lowercase CBOR hex: hex string (Blockfrost), `{ bytes, value }` wrapper (Koios)
211
- * or raw PlutusData JSON. Returns null on unknown shapes instead of throwing.
212
- */
207
+ // Accepts a hex string, the `{ bytes, value }` wrapper of Koios, or PlutusData JSON.
208
+ // Returns null on unknown shapes instead of throwing.
213
209
  function inlineDatumToHex(datum) {
214
210
  if (datum === null || datum === undefined)
215
211
  return null;
@@ -243,11 +239,8 @@ function inlineDatumToHex(datum) {
243
239
  return null;
244
240
  }
245
241
  }
246
- /**
247
- * Encode a script parameter as the UPLC constant of the type the validator expects: typed
248
- * `{ uplc: data|bytes|int|bool|unit, value }` for native-typed params, or a bare PlutusData object
249
- * (Aiken / CIP-57 convention) as shorthand for `uplc: "data"`.
250
- */
242
+ // Typed form is `{ uplc, value }` with uplc one of data, bytes, int, bool or unit.
243
+ // A bare PlutusData object, the CIP-57 convention, is shorthand for `uplc: "data"`.
251
244
  function encodeScriptParam(param) {
252
245
  if (param !== null &&
253
246
  typeof param === 'object' &&
@@ -259,43 +252,39 @@ function encodeScriptParam(param) {
259
252
  return uplc_1.UPLCConst.data(jsonToPlutusData(value));
260
253
  case 'bytes': {
261
254
  if (typeof value !== 'string' || !/^([0-9a-fA-F]{2})*$/.test(value)) {
262
- throw new Error('Script param of uplc type "bytes" requires an even-length hex string "value"');
255
+ throw new errors_1.TransactionValidationError('Script param of uplc type "bytes" requires an even-length hex string "value"');
263
256
  }
264
257
  return uplc_1.UPLCConst.byteString((0, uint8array_utils_1.fromHex)(value));
265
258
  }
266
259
  case 'int': {
267
260
  if (typeof value !== 'number' && typeof value !== 'string') {
268
- throw new Error('Script param of uplc type "int" requires a number or numeric-string "value"');
261
+ throw new errors_1.TransactionValidationError('Script param of uplc type "int" requires a number or numeric-string "value"');
269
262
  }
270
263
  let n;
271
264
  try {
272
265
  n = BigInt(value);
273
266
  }
274
267
  catch {
275
- throw new Error(`Script param of uplc type "int" has a non-integer "value": ${String(value)}`);
268
+ throw new errors_1.TransactionValidationError(`Script param of uplc type "int" has a non-integer "value": ${String(value)}`);
276
269
  }
277
270
  return uplc_1.UPLCConst.int(n);
278
271
  }
279
272
  case 'bool': {
280
273
  if (typeof value !== 'boolean') {
281
- throw new Error('Script param of uplc type "bool" requires a boolean "value"');
274
+ throw new errors_1.TransactionValidationError('Script param of uplc type "bool" requires a boolean "value"');
282
275
  }
283
276
  return uplc_1.UPLCConst.bool(value);
284
277
  }
285
278
  case 'unit':
286
279
  return uplc_1.UPLCConst.unit;
287
280
  default:
288
- throw new Error(`Unknown script param uplc type "${String(uplc)}"; expected one of: data, bytes, int, bool, unit`);
281
+ throw new errors_1.TransactionValidationError(`Unknown script param uplc type "${String(uplc)}"; expected one of: data, bytes, int, bool, unit`);
289
282
  }
290
283
  }
291
284
  // Bare PlutusData: apply as Data
292
285
  return uplc_1.UPLCConst.data(jsonToPlutusData(param));
293
286
  }
294
- /**
295
- * Apply parameters to a parameterized PlutusV3 script (CBOR-wrapped flat UPLC): each parameter becomes a
296
- * UPLC Application around the program body, encoded via {@link encodeScriptParam}.
297
- * @returns CBOR hex of the applied script
298
- */
287
+ /** Wraps the program body in one UPLC application per parameter. Returns the script CBOR hex. */
299
288
  function applyScriptParameters(scriptHex, params) {
300
289
  if (!Array.isArray(params) || params.length === 0) {
301
290
  throw new Error('Script parameters must be a non-empty array');
@@ -314,11 +303,8 @@ function applyScriptParameters(scriptHex, params) {
314
303
  const cborEncoded = cbor_1.Cbor.encode(new cbor_1.CborBytes(appliedFlatBytes));
315
304
  return (0, uint8array_utils_1.toHex)(cborEncoded);
316
305
  }
317
- /**
318
- * Script hash of a Plutus script, CBOR-wrapped once or twice as cardano-cli writes it:
319
- * blake2b-224 over the language byte and the once-wrapped CBOR. The version cannot be read
320
- * from the script, so the caller names it.
321
- */
306
+ // blake2b-224 over the language byte and the once-wrapped CBOR. Accepts cardano-cli's double wrap.
307
+ // The version cannot be read from the script, so the caller names it.
322
308
  function plutusScriptHash(scriptHex, version) {
323
309
  if (version !== 'plutusV2' && version !== 'plutusV3') {
324
310
  throw new errors_1.TransactionValidationError(`version must be plutusV2 or plutusV3, got ${String(version)}`);
@@ -1,8 +1,4 @@
1
1
  import type { JSONValue, MintAction } from './types';
2
- /**
3
- * Shared parsers for the Build*-action JSON payload fields (transaction service and wallet worker).
4
- * Result contract: `{ parsed }` on success (undefined for absent/empty input) or `{ error }` with a client message.
5
- */
6
2
  /** PlutusData as CBOR hex, checked to decode; `field` names it in the error. */
7
3
  export declare function parsePlutusCbor(value: unknown, field: string): {
8
4
  hex?: string;
@@ -49,18 +45,11 @@ export declare function parseExtraOutputs(extraOutputsJson: string | undefined):
49
45
  parsed?: ParsedExtraOutput[];
50
46
  error?: string;
51
47
  };
52
- /**
53
- * Parse an output list. `outputsJson` (BuildPlutusTransaction) additionally accepts `datumHash`;
54
- * the entries keep their order, each is min-ADA checked by the builder.
55
- */
48
+ /** Entries keep their order. `outputsJson` also accepts `datumHash`. */
56
49
  export declare function parseOutputList(json: string | undefined, fieldName: 'extraOutputsJson' | 'outputsJson'): {
57
50
  parsed?: ParsedExtraOutput[];
58
51
  error?: string;
59
52
  };
60
- /**
61
- * Parse the optional per-action policy fields of a mintActionsJson entry: `mintingPolicyScript` (CBOR hex,
62
- * applied as-is) and `redeemerJson` (JSON string). Absent fields fall back to the top-level script/redeemer.
63
- */
64
53
  export declare function parseMintActionPolicyFields(entry: Record<string, unknown>, i: number, byReference?: boolean): {
65
54
  script?: string;
66
55
  redeemer?: JSONValue;
@@ -105,10 +94,6 @@ export interface ParsedWithdrawal {
105
94
  redeemer?: JSONValue;
106
95
  redeemerCbor?: string;
107
96
  }
108
- /**
109
- * Parse and validate withdrawalsJson: distinct reward accounts, lovelace >= 0, optionally a staking
110
- * script (inline or by reference) with exactly one redeemer form; without a script no redeemer.
111
- */
112
97
  export declare function parseWithdrawals(json: string | undefined): {
113
98
  parsed?: ParsedWithdrawal[];
114
99
  error?: string;
@@ -123,19 +108,10 @@ export interface ParsedCertificate extends ParsedStakingScriptWitness {
123
108
  stakeAddress: string;
124
109
  deposit?: string;
125
110
  }
126
- /**
127
- * Parse and validate certificatesJson: stake registrations and deregistrations, each with an
128
- * optional staking script (inline or by reference) and exactly one redeemer form when scripted.
129
- */
130
111
  export declare function parseCertificates(json: string | undefined): {
131
112
  parsed?: ParsedCertificate[];
132
113
  error?: string;
133
114
  };
134
- /**
135
- * Parse mintActionsJson for BuildPlutusTransaction: every action carries its own `mintingPolicyScript`
136
- * or `referenceScript` (no request-level default) and optional `redeemerJson`; `assetUnit` is
137
- * policyId+assetName, or with an inline script a bare assetName prefixed with the script's policy id.
138
- */
139
115
  export declare function parsePolicyMintActions(json: string | undefined): {
140
116
  parsed?: MintAction[];
141
117
  error?: string;