@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
@@ -1,35 +1,8 @@
1
1
  using {odatano.cardano as db} from '../db/schema';
2
2
  using { Blake2b256, Bech32, AssetUnit, ParsedTransaction, TransactionConfirmations } from '../db/types';
3
3
 
4
- /**
5
- * Cardano OData Service
6
- *
7
- * Handles external read-only queries for Cardano blockchain data, including:
8
- * - Retrieving network information, blocks, epochs, pools, dreps, transactions, accounts, addresses, UTxOs, assets, and metadata
9
- * - Providing actions for fetching specific data by identifiers (hashes, addresses, etc.) and for retrieving the latest blockchain state (latest block, epoch, protocol parameters)
10
- *
11
- * ## Security: Authentication & Authorization
12
- *
13
- * All services use `@requires: 'authenticated-user'` (service-level gate).
14
- * The XSUAA scopes defined in xs-security.json (Read, Transact, Sign) are available
15
- * for consumer-level role assignment but are NOT enforced per-action in ODATANO itself.
16
- *
17
- * This is intentional — ODATANO is a blockchain bridge, not a multi-tenant application.
18
- * Per-resource ownership checks (IDOR prevention) are deliberately omitted because:
19
- *
20
- * 1. **Blockchain security model**: Unsigned transaction CBOR is not exploitable without
21
- * the corresponding private key. Viewing a build/signing request does not enable
22
- * fund theft — only the key holder can sign and submit.
23
- *
24
- * 2. **Cross-address operations are legitimate**: Smart contract interactions routinely
25
- * require building transactions for addresses the caller does not own — e.g. script
26
- * redemptions, multi-party Plutus workflows, or DApp backends building on behalf of users.
27
- * Enforcing sender == authenticated user would break these use cases.
28
- *
29
- * 3. **Consumer responsibility**: Consumers deploying ODATANO in multi-user environments
30
- * should add their own authorization layer (e.g. `@restrict` annotations, custom
31
- * middleware) that maps JWT claims to allowed wallet addresses if needed.
32
- */
4
+ // Read queries for Cardano chain data. Every operation needs an authenticated user;
5
+ // per-address ownership is not checked (docs/guides/SECURITY_GUIDE.md).
33
6
  @requires: 'authenticated-user'
34
7
  @path: '/odata/v4/cardano'
35
8
  service CardanoODataService @(impl: './cardano-service') {
@@ -217,6 +190,7 @@ service CardanoODataService @(impl: './cardano-service') {
217
190
  action GetEpochByNumber(
218
191
  @title: 'Epoch Number'
219
192
  @description: 'The sequential number of the epoch'
193
+ @assert.range: [0, _]
220
194
  epochNumber: Integer) returns Epochs;
221
195
 
222
196
  @title : 'Get Pools by Pool Id'
@@ -234,21 +208,26 @@ service CardanoODataService @(impl: './cardano-service') {
234
208
  drepId: String) returns Dreps;
235
209
 
236
210
  @title : 'Get Asset Info'
237
- @description: 'Retrieve native-asset information (supply, mint history, CIP-25 + CIP-26 metadata) by unit. Multi-backend (Blockfrost, Koios). Field availability differs slightly per backend — see entity description.'
211
+ @description: 'Retrieve native-asset information (supply, mint history, CIP-25 + CIP-26 metadata) by unit. Multi-backend (Blockfrost, Koios). Field availability differs slightly per backend; see entity description.'
238
212
  action GetAssetInfo(
239
213
  @title: 'Asset Unit'
240
214
  @description: 'Concatenation of policyId (56 hex) and assetNameHex (0-64 hex; ledger caps asset names at 32 bytes)'
241
215
  unit: AssetUnit) returns Assets;
242
216
 
243
217
  @title : 'Get Asset Mint/Burn History'
244
- @description: 'Retrieve recent mint/burn events for a native asset (most recent first). Koios is preferred (provides block timestamps); Blockfrost is the fallback (timestamps null). Always-fresh fetch — UPSERTs entries by (unit, txHash). For full pagination, query the AssetHistory entity directly with $top/$skip after seeding.'
218
+ @description: 'Retrieve recent mint/burn events for a native asset, newest first. Koios is preferred (provides block timestamps); Blockfrost is the fallback (timestamps null). Always-fresh fetch, UPSERTs entries by (unit, txHash). skip + limit covers at most the newest 100 events; older events are read from the AssetHistory entity with $top/$skip.'
245
219
  action GetAssetHistory(
246
220
  @title: 'Asset Unit'
247
221
  @description: 'Concatenation of policyId (56 hex) and assetNameHex (0-64 hex; ledger caps asset names at 32 bytes)'
248
222
  unit: AssetUnit,
249
223
  @title: 'Limit'
250
- @description: 'Maximum number of recent events to fetch (default 100, clamped to 1-100)'
251
- limit: Integer) returns many AssetHistory;
224
+ @description: 'Maximum number of rows (default 100, at most 100)'
225
+ @assert.range: [1, 100]
226
+ limit: Integer,
227
+ @title: 'Skip'
228
+ @description: 'Number of rows to skip (default 0)'
229
+ @assert.range: [0, 99]
230
+ skip: Integer) returns many AssetHistory;
252
231
 
253
232
  @title : 'Get Accounts by Stake Address'
254
233
  @description: 'Retrieve account information using the Bech32 Stake Address'
@@ -276,7 +255,15 @@ service CardanoODataService @(impl: './cardano-service') {
276
255
  action GetMetadataByTxHash(
277
256
  @title: 'Transaction Hash'
278
257
  @description: 'The unique identifier of the transaction'
279
- txHash: Blake2b256) returns many TransactionMetadata;
258
+ txHash: Blake2b256,
259
+ @title: 'Limit'
260
+ @description: 'Maximum number of rows (default 1000, at most 5000)'
261
+ @assert.range: [1, 5000]
262
+ limit: Integer,
263
+ @title: 'Skip'
264
+ @description: 'Number of rows to skip (default 0)'
265
+ @assert.range: [0, _]
266
+ skip: Integer) returns many TransactionMetadata;
280
267
 
281
268
  @title : 'Get Addresses by Bech32 Address'
282
269
  @description: 'Retrieve address information using the Bech32 Address'
@@ -290,31 +277,60 @@ service CardanoODataService @(impl: './cardano-service') {
290
277
  action GetUTxOsByAddress(
291
278
  @title: 'Bech32 Address'
292
279
  @description: 'The Bech32 encoded address'
293
- address: Bech32) returns many AddressUTxOs;
280
+ address: Bech32,
281
+ @title: 'Limit'
282
+ @description: 'Maximum number of rows (default 1000, at most 5000)'
283
+ @assert.range: [1, 5000]
284
+ limit: Integer,
285
+ @title: 'Skip'
286
+ @description: 'Number of rows to skip (default 0)'
287
+ @assert.range: [0, _]
288
+ skip: Integer) returns many AddressUTxOs;
294
289
 
295
290
  @title : 'Get UTxOs by Payment Credential'
296
291
  @description: 'Retrieve UTxOs across all bech32 addresses sharing the given 28-byte payment credential (key hash or script hash). Useful for protocols that write to multiple bech32 forms of the same script (e.g. Indigo CDPs, Liqwid positions). Served from the crawled UTxO set (crawler.utxoSet active and synced) with outputs read from the node at the tip, else from Koios; throws ProviderUnavailableError when neither is available. Always fresh, no cache check.'
297
292
  action GetUTxOsByCredential(
298
293
  @title: 'Payment Credential'
299
294
  @description: '28-byte payment credential hash as 56-char lowercase hex string'
300
- credential: String) returns many AddressUTxOs;
295
+ credential: String,
296
+ @title: 'Limit'
297
+ @description: 'Maximum number of rows (default 1000, at most 5000)'
298
+ @assert.range: [1, 5000]
299
+ limit: Integer,
300
+ @title: 'Skip'
301
+ @description: 'Number of rows to skip (default 0)'
302
+ @assert.range: [0, _]
303
+ skip: Integer) returns many AddressUTxOs;
301
304
 
302
305
  @title : 'Get Assets by Bech32 Address'
303
306
  @description: 'Retrieve asset information using the Bech32 Address'
304
307
  action GetAssetsByAddress(
305
308
  @title: 'Bech32 Address'
306
309
  @description: 'The Bech32 encoded address'
307
- address: Bech32) returns many AddressAssets;
310
+ address: Bech32,
311
+ @title: 'Limit'
312
+ @description: 'Maximum number of rows (default 1000, at most 5000)'
313
+ @assert.range: [1, 5000]
314
+ limit: Integer,
315
+ @title: 'Skip'
316
+ @description: 'Number of rows to skip (default 0)'
317
+ @assert.range: [0, _]
318
+ skip: Integer) returns many AddressAssets;
308
319
 
309
320
  @title : 'Get latest Transactions by Bech32 Address'
310
- @description: 'Retrieve the latest transactions from the Bech32 Address'
321
+ @description: 'Retrieve the latest transactions of the Bech32 Address, newest first. skip + limit covers at most the newest 100 transactions.'
311
322
  action GetLatestTransactionsByAddress(
312
323
  @title: 'Bech32 Address'
313
324
  @description: 'The Bech32 encoded address'
314
325
  address: Bech32,
315
326
  @title: 'Limit'
316
- @description: 'The maximum number of transactions to retrieve'
317
- limit: Integer) returns many AddressTransactions;
327
+ @description: 'Maximum number of rows (default 10, at most 100)'
328
+ @assert.range: [1, 100]
329
+ limit: Integer,
330
+ @title: 'Skip'
331
+ @description: 'Number of rows to skip (default 0)'
332
+ @assert.range: [0, 99]
333
+ skip: Integer) returns many AddressTransactions;
318
334
 
319
335
  @title : 'Get Latest Block'
320
336
  @description: 'Retrieve the latest block information'
@@ -9,6 +9,8 @@ const validators_1 = require("./utils/validators");
9
9
  const errors_1 = require("./utils/errors");
10
10
  const backend_request_handler_1 = require("./utils/backend-request-handler");
11
11
  const cbor_1 = require("./cbor");
12
+ const paging_1 = require("./utils/paging");
13
+ const CardanoODataService_1 = require("#cds-models/CardanoODataService");
12
14
  /** Newest temporal slice per key; child tables keep one row per validFrom. */
13
15
  function latestSlices(rows, keyOf) {
14
16
  const seen = new Map();
@@ -24,13 +26,9 @@ const { SELECT } = cds_1.default.ql;
24
26
  const logger = cds_1.default.log(`CardanoService`);
25
27
  /** Upper bound of the temporal window; must outlast the slowest index-on-miss of one request. */
26
28
  const TEMPORAL_WINDOW_SLACK_MS = 60 * 60 * 1000;
27
- /**
28
- * Let this request see the temporal slices it writes during index-on-miss: CAP's temporal
29
- * filter (`validFrom < $valid.to`) defaults to a `now`..`now+1ms` window fixed at transaction
30
- * start, so a slice stamped after the backend fetch would be invisible to the handler's
31
- * re-read. Only the upper bound moves; explicit `sap-valid-*` options are left alone.
32
- * Must run before the handler's first DB statement.
33
- */
29
+ // CAP's temporal window is fixed at transaction start, so a slice written by index-on-miss would be
30
+ // invisible to the re-read. This widens the upper bound unless the client set `sap-valid-*`.
31
+ // Must run before the handler's first DB statement.
34
32
  function widenTemporalWindow(req) {
35
33
  const q = req.http?.req?.query;
36
34
  if (q && (q['sap-valid-at'] || q['sap-valid-from'] || q['sap-valid-to']))
@@ -47,10 +45,7 @@ function widenTemporalWindow(req) {
47
45
  bag['VALID-TO'] = to;
48
46
  }
49
47
  }
50
- /**
51
- * Factory: READ handler with index-on-miss. With a key, indexes on a cache miss and then
52
- * runs the client's own query so `$expand` / `$select` apply; without a key, passes through.
53
- */
48
+ /** READ handler that indexes a missing key first, then runs the client's own query (keeps `$expand`, `$select`). */
54
49
  function indexOnMissRead(entity, reqKeyField, validate, indexFn, options) {
55
50
  const dbKey = options?.entityKeyField || reqKeyField;
56
51
  const errMsg = options?.errorMessage || `Invalid ${reqKeyField} format`;
@@ -106,11 +101,7 @@ function isAddressRef(t) {
106
101
  return (path.length === 1 && path[0] === 'address_address') || (path.length === 2 && path[0] === 'address' && path[1] === 'address');
107
102
  }
108
103
  const stringVal = (t) => t !== undefined && isVal(t) && typeof t.val === 'string' ? t.val : undefined;
109
- /**
110
- * Addresses a read of an address child set names: the parent of a navigation
111
- * (`Addresses('…')/utxos`) or the `$filter` terms `address_address eq '…'` (either operand
112
- * order) and `address_address in ('…', …)`.
113
- */
104
+ /** Addresses a child-set read names: the navigation parent, or `address_address` in an `eq` or `in` filter. */
114
105
  function addressesInReadQuery(req) {
115
106
  const found = new Set();
116
107
  const parent = req.data?.address_address;
@@ -150,11 +141,7 @@ function addressesInReadQuery(req) {
150
141
  walk(('SELECT' in query && query.SELECT?.where) || []);
151
142
  return Array.from(found);
152
143
  }
153
- /**
154
- * Factory: READ handler for a child set of Addresses with index-on-miss. The address is taken
155
- * from the navigation parent or the `$filter`; without one the read passes through.
156
- * `isIndexed` says whether the address needs no fetch, `indexFn` fetches it.
157
- */
144
+ /** READ handler for a child set of Addresses: indexes the named address on a miss, then runs the query. */
158
145
  function addressChildRead(isIndexed, indexFn) {
159
146
  return async (req) => {
160
147
  const addresses = addressesInReadQuery(req);
@@ -194,7 +181,7 @@ module.exports = (srv) => {
194
181
  LedgerProtocolParameters, AddressTransactions,
195
182
  })) {
196
183
  if (entity?.is_singular) {
197
- throw new Error(`CardanoODataService: '${name}' resolves to the SINGULAR cds-typer class — ` +
184
+ throw new Error(`CardanoODataService: '${name}' resolves to the SINGULAR cds-typer class: ` +
198
185
  `READ handlers registered with it never match under cds 10. Destructure the ` +
199
186
  `plural entity-set class instead (e.g. '${name}_ as ${name}').`);
200
187
  }
@@ -251,25 +238,22 @@ module.exports = (srv) => {
251
238
  // ---------------------------------------------------------------------------
252
239
  srv.on('READ', Assets, indexOnMissRead(Assets, 'unit', validators_1.isAssetUnit, (db, u) => indexer().indexAsset(db, u), { errorMessage: 'Invalid asset unit format' }));
253
240
  srv.on('GetAssetInfo', indexOnMissAction('GetAssetInfo', Assets, 'unit', validators_1.isAssetUnit, (db, u) => indexer().indexAsset(db, u), { errorMessage: 'Invalid asset unit format' }));
254
- // ---------------------------------------------------------------------------
255
- // Asset History
256
- // ---------------------------------------------------------------------------
257
- // Generic READ is served from the DB only; GetAssetHistory(unit) seeds the rows.
241
+ // Asset history: READ serves stored rows only; GetAssetHistory fetches and stores them.
258
242
  srv.on('READ', AssetHistory, async (req) => {
259
243
  return (0, backend_request_handler_1.handleRequest)(req, async (db) => db.run(req.query));
260
244
  });
261
- // GetAssetHistory — always-fresh fetch of recent mint/burn events.
262
- srv.on('GetAssetHistory', async (req) => {
263
- const { unit, limit } = req.data;
245
+ // GetAssetHistory: always-fresh fetch of recent mint/burn events.
246
+ srv.on(CardanoODataService_1.GetAssetHistory, async (req) => {
247
+ const { unit } = req.data;
264
248
  if (!unit)
265
249
  return (0, errors_1.rejectMissing)(req, 'GetAssetHistory', 'unit');
266
250
  if (!(0, validators_1.isAssetUnit)(unit)) {
267
251
  return (0, errors_1.rejectInvalid)(req, 'GetAssetHistory', 'Invalid asset unit format', 'unit');
268
252
  }
269
- // Clamp: an unbounded limit would page the upstream backend indefinitely.
270
- const effectiveLimit = Math.min(Math.max(typeof limit === 'number' ? limit : 100, 1), 100);
253
+ const page = (0, paging_1.latestWindowPage)(req, 'GetAssetHistory', 100);
271
254
  return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
272
- return await indexer().indexAssetHistory(db, unit, effectiveLimit);
255
+ const events = await indexer().indexAssetHistory(db, unit, page.skip + page.limit);
256
+ return (0, paging_1.pageRows)((0, paging_1.sortAssetHistory)(events), page);
273
257
  });
274
258
  });
275
259
  // ---------------------------------------------------------------------------
@@ -277,20 +261,21 @@ module.exports = (srv) => {
277
261
  // ---------------------------------------------------------------------------
278
262
  srv.on('READ', Addresses, indexOnMissRead(Addresses, 'address', validators_1.isValidBech32Address, (db, a) => indexer().indexAddress(db, a), { errorMessage: 'Invalid bech32 address format' }));
279
263
  srv.on('GetAddressByBech32', indexOnMissAction('GetAddressByBech32', Addresses, 'address', validators_1.isValidBech32Address, (db, a) => indexer().indexAddress(db, a), { errorMessage: 'Invalid bech32 address format' }));
280
- // GetAssetsByAddress — indexes the parent address if needed, then queries child assets.
281
- srv.on('GetAssetsByAddress', async (req) => {
264
+ // GetAssetsByAddress: indexes the parent address if needed, then queries child assets.
265
+ srv.on(CardanoODataService_1.GetAssetsByAddress, async (req) => {
282
266
  const { address } = req.data;
283
267
  if (!address)
284
268
  (0, errors_1.rejectMissing)(req, 'GetAssetsByAddress', 'address');
285
269
  if (!(0, validators_1.isValidBech32Address)(address))
286
270
  (0, errors_1.rejectInvalid)(req, 'GetAssetsByAddress', 'Invalid bech32 address format', 'address');
271
+ const page = (0, paging_1.pageOf)(req.data, 1000);
287
272
  return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
288
273
  widenTemporalWindow(req); // before the first DB statement
289
274
  const existing = await db.run(SELECT.one.from(Addresses).where({ address }));
290
275
  if (!existing)
291
276
  await indexer().indexAddress(db, address);
292
277
  const assets = await db.run(SELECT.from(AddressAssets).where({ address_address: address }));
293
- return latestSlices(assets, (asset) => asset.unit ?? '');
278
+ return (0, paging_1.pageRows)((0, paging_1.byKey)(latestSlices(assets, (asset) => asset.unit ?? ''), (a) => a.unit ?? ''), page);
294
279
  });
295
280
  });
296
281
  // Prefer the full address index; when no configured backend supports getAddress
@@ -314,44 +299,44 @@ module.exports = (srv) => {
314
299
  const addressIndexed = async (db, address) => !!(await db.run(SELECT.one.from(Addresses).where({ address })));
315
300
  const addressUtxosIndexed = async (db, address) => (await addressIndexed(db, address))
316
301
  || !!(await db.run(SELECT.one.from(AddressUTxOs).where({ address_address: address })));
317
- // GetUTxOsByAddress — indexes the address if needed, then queries child UTxOs.
318
- srv.on('GetUTxOsByAddress', async (req) => {
302
+ // GetUTxOsByAddress: indexes the address if needed, then queries child UTxOs.
303
+ srv.on(CardanoODataService_1.GetUTxOsByAddress, async (req) => {
319
304
  const { address } = req.data;
320
305
  if (!address)
321
306
  (0, errors_1.rejectMissing)(req, 'GetUTxOsByAddress', 'address');
322
307
  if (!(0, validators_1.isValidBech32Address)(address))
323
308
  (0, errors_1.rejectInvalid)(req, 'GetUTxOsByAddress', 'Invalid bech32 address format', 'address');
309
+ const page = (0, paging_1.pageOf)(req.data, 1000);
324
310
  return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
325
311
  widenTemporalWindow(req); // before the first DB statement
326
312
  if (!(await addressUtxosIndexed(db, address)))
327
313
  await indexAddressOrUtxos(db, address);
328
314
  const utxos = await db.run(SELECT.from(AddressUTxOs).where({ address_address: address }));
329
- return latestSlices(utxos, (utxo) => `${utxo.hash}#${utxo.index}`);
315
+ return (0, paging_1.pageRows)((0, paging_1.byOutRef)(latestSlices(utxos, (utxo) => `${utxo.hash}#${utxo.index}`)), page);
330
316
  });
331
317
  });
332
318
  // Collection reads of the address child sets fill like the parent: an address named in the
333
319
  // navigation or the $filter is indexed on a miss, then the client's own query runs.
334
320
  srv.on('READ', AddressUTxOs, addressChildRead(addressUtxosIndexed, indexAddressOrUtxos));
335
321
  srv.on('READ', AddressAssets, addressChildRead(addressIndexed, (db, address) => indexer().indexAddress(db, address)));
336
- // GetUTxOsByCredential — always-fresh credential-keyed UTxO query (dApp state reads need current
322
+ // GetUTxOsByCredential: always-fresh credential-keyed UTxO query (dApp state reads need current
337
323
  // data). Crawled UTxO set + node first, else Koios; ProviderUnavailableError without either.
338
- srv.on('GetUTxOsByCredential', async (req) => {
324
+ srv.on(CardanoODataService_1.GetUTxOsByCredential, async (req) => {
339
325
  const { credential } = req.data;
340
326
  if (!credential)
341
327
  return (0, errors_1.rejectMissing)(req, 'GetUTxOsByCredential', 'credential');
342
328
  if (!(0, validators_1.isValidCredential)(credential)) {
343
- return (0, errors_1.rejectInvalid)(req, 'GetUTxOsByCredential', 'Invalid payment credential — expected 56-char lowercase hex (28 bytes)', 'credential');
329
+ return (0, errors_1.rejectInvalid)(req, 'GetUTxOsByCredential', 'Invalid payment credential: expected 56-char lowercase hex (28 bytes)', 'credential');
344
330
  }
345
- return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
346
- return await indexer().indexCredentialUtxos(db, credential);
347
- });
331
+ const page = (0, paging_1.pageOf)(req.data, 1000);
332
+ return (0, backend_request_handler_1.handleRequest)(req, async (db) => (0, paging_1.pageRows)((0, paging_1.byOutRef)(await indexer().indexCredentialUtxos(db, credential)), page));
348
333
  });
349
334
  // ---------------------------------------------------------------------------
350
335
  // Transactions
351
336
  // ---------------------------------------------------------------------------
352
337
  srv.on('READ', Transactions, indexOnMissRead(Transactions, 'hash', validators_1.isTxHash, (db, h) => indexer().indexTransaction(db, h), { errorMessage: 'Invalid transaction hash format' }));
353
338
  srv.on('GetTransactionByHash', indexOnMissAction('GetTransactionByHash', Transactions, 'hash', validators_1.isTxHash, (db, h) => indexer().indexTransaction(db, h), { errorMessage: 'Invalid transaction hash format' }));
354
- srv.on('GetTransactionConfirmations', async (req) => {
339
+ srv.on(CardanoODataService_1.GetTransactionConfirmations, async (req) => {
355
340
  const { txHash } = req.data;
356
341
  if (!txHash)
357
342
  (0, errors_1.rejectMissing)(req, 'GetTransactionConfirmations', 'txHash');
@@ -363,19 +348,18 @@ module.exports = (srv) => {
363
348
  // Transaction Metadata
364
349
  // ---------------------------------------------------------------------------
365
350
  srv.on('READ', TransactionMetadata, indexOnMissRead(TransactionMetadata, 'tx_hash', validators_1.isTxHash, (db, h) => indexer().indexTransactionMetadata(db, h), { errorMessage: 'Invalid transaction hash format' }));
366
- // GetMetadataByTxHash — returns all metadata rows of a transaction.
367
- srv.on('GetMetadataByTxHash', async (req) => {
351
+ // GetMetadataByTxHash: returns all metadata rows of a transaction.
352
+ srv.on(CardanoODataService_1.GetMetadataByTxHash, async (req) => {
368
353
  const { txHash } = req.data;
369
354
  if (!txHash)
370
355
  (0, errors_1.rejectMissing)(req, 'GetMetadataByTxHash', 'txHash');
371
356
  if (!(0, validators_1.isTxHash)(txHash))
372
357
  (0, errors_1.rejectInvalid)(req, 'GetMetadataByTxHash', 'Invalid transaction hash format', 'txHash');
358
+ const page = (0, paging_1.pageOf)(req.data, 1000);
373
359
  return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
374
360
  const existing = await db.run(SELECT.from(TransactionMetadata).where({ tx_hash: txHash }));
375
- if (!existing || existing.length === 0) {
376
- return await indexer().indexTransactionMetadata(db, txHash);
377
- }
378
- return existing;
361
+ const rows = existing?.length ? existing : await indexer().indexTransactionMetadata(db, txHash);
362
+ return (0, paging_1.pageRows)((0, paging_1.byKey)(rows, (m) => String(m.label ?? '').padStart(20, '0')), page);
379
363
  });
380
364
  });
381
365
  // ---------------------------------------------------------------------------
@@ -395,7 +379,7 @@ module.exports = (srv) => {
395
379
  // ---------------------------------------------------------------------------
396
380
  // Transaction CBOR parsing (pure; no backend or DB access)
397
381
  // ---------------------------------------------------------------------------
398
- srv.on('ParseTransactionCbor', async (req) => {
382
+ srv.on(CardanoODataService_1.ParseTransactionCbor, async (req) => {
399
383
  const { cbor } = req.data;
400
384
  if (cbor == null || cbor === '')
401
385
  (0, errors_1.rejectMissing)(req, 'ParseTransactionCbor', 'cbor');
@@ -404,7 +388,7 @@ module.exports = (srv) => {
404
388
  }
405
389
  return (0, backend_request_handler_1.handleRequest)(req, async () => (0, cbor_1.parseTransaction)(cbor));
406
390
  });
407
- srv.on('DecodePlutusData', async (req) => {
391
+ srv.on(CardanoODataService_1.DecodePlutusData, async (req) => {
408
392
  const { cbor } = req.data;
409
393
  if (cbor == null || cbor === '')
410
394
  (0, errors_1.rejectMissing)(req, 'DecodePlutusData', 'cbor');
@@ -416,26 +400,15 @@ module.exports = (srv) => {
416
400
  // ---------------------------------------------------------------------------
417
401
  // Address Transactions
418
402
  // ---------------------------------------------------------------------------
419
- srv.on('GetLatestTransactionsByAddress', async (req) => {
420
- const { address, limit } = req.data;
403
+ srv.on(CardanoODataService_1.GetLatestTransactionsByAddress, async (req) => {
404
+ const { address } = req.data;
421
405
  if (!address)
422
406
  (0, errors_1.rejectMissing)(req, 'GetLatestTransactionsByAddress', 'address');
423
407
  if (!(0, validators_1.isValidBech32Address)(address))
424
408
  (0, errors_1.rejectInvalid)(req, 'GetLatestTransactionsByAddress', 'Invalid bech32 address format', 'address');
425
- const txLimit = Math.min(Math.max(limit || 10, 1), 100);
426
- return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
427
- // The crawled UTxO set is current; the cached rows may miss the newest transactions.
428
- if (await indexer().ledgerCoverageActive(db))
429
- return indexer().indexAddressTransactions(db, address, txLimit);
430
- const existing = await db.run(SELECT.from(AddressTransactions)
431
- .where({ address_address: address })
432
- .orderBy('blockTime desc')
433
- .limit(txLimit));
434
- if (!existing || existing.length < txLimit) {
435
- return indexer().indexAddressTransactions(db, address, txLimit);
436
- }
437
- return existing;
438
- });
409
+ const page = (0, paging_1.latestWindowPage)(req, 'GetLatestTransactionsByAddress', 10);
410
+ // Every call lists the newest hashes; stored rows are reused, only new ones are fetched.
411
+ return (0, backend_request_handler_1.handleRequest)(req, async (db) => (0, paging_1.pageRows)(await indexer().indexAddressTransactions(db, address, page.skip + page.limit), page));
439
412
  });
440
413
  logger.debug('All handlers registered');
441
414
  };
@@ -1,25 +1,9 @@
1
1
  using {odatano.cardano as db} from '../db/schema';
2
2
  using {Bech32} from '../db/types';
3
3
 
4
- /**
5
- * Cardano Sign Service
6
- *
7
- * Handles the external signing workflow for Cardano transactions, including:
8
- * - Creating signing requests with transaction details and signing instructions
9
- * - Verifying signatures of signed transactions and storing verification results
10
- * - Submitting verified transactions to the blockchain and tracking submission status
11
- * - Providing actions for signing with a Hardware Security Module (HSM) and retrieving HSM status
12
- *
13
- * Security note: see CardanoODataService (cardano-service.cds) for the rationale on auth
14
- * without per-resource ownership enforcement. Deliberately NO service-level @requires:
15
- * CAP checks it on every request BEFORE the operation annotation, which silenced the
16
- * `any` on VerifyDataSignature (anonymous callers got the 401 challenge first). The
17
- * requirement therefore sits on each element; VerifyDataSignature alone is public.
18
- */
19
- // Service-level 'any' on purpose: CAP authorizes the service BEFORE the operation and
20
- // treats a service without a service-level @requires as authenticated-user under
21
- // NODE_ENV=production, which would 401 the anonymous operation below despite its own
22
- // 'any'. Every element carries its requirement; the service itself refuses nothing.
4
+ // External signing: signing requests, signature checks, submission and HSM signing.
5
+ // The service itself is 'any': CAP checks the service before the operation, so anything stricter
6
+ // would 401 the anonymous VerifyDataSignature. Each element carries its own requirement.
23
7
  @requires: 'any'
24
8
  service CardanoSignService @(impl: './cardano-sign-service') {
25
9
 
@@ -34,7 +18,7 @@ service CardanoSignService @(impl: './cardano-sign-service') {
34
18
 
35
19
  @readonly
36
20
  @title : 'Address Signing Requests'
37
- @description: 'Projection for retrieving signing requests by address'
21
+ @description: 'Signing requests of an address, ordered by request id'
38
22
  @requires : 'authenticated-user'
39
23
  entity AddressSigningRequests as projection on db.AddressSigningRequests;
40
24
 
@@ -106,8 +90,7 @@ service CardanoSignService @(impl: './cardano-sign-service') {
106
90
  // ---------------------------------------------------------------------------
107
91
 
108
92
  // Public override: this action is the crypto check behind wallet-based LOGIN,
109
- // so the caller is not yet authenticated. It is a stateless verification —
110
- // no DB write, no key access, no state — so exposing it leaks nothing.
93
+ // so the caller is not yet authenticated. It writes nothing and touches no key, so it leaks nothing.
111
94
  @requires : 'any'
112
95
  @title : 'Verify Data Signature (CIP-30 signData)'
113
96
  @description: 'Verify a COSE_Sign1 message signature against a bech32 address. Confirms the Ed25519 signature, that the signer key hashes to the address payment credential, and (optionally) that the signed payload matches an expected value.'
@@ -155,7 +138,15 @@ service CardanoSignService @(impl: './cardano-sign-service') {
155
138
  action GetSigningRequestsByAddress(
156
139
  @title: 'Bech32 Address'
157
140
  @description: 'The Bech32 encoded address to retrieve signing requests for'
158
- address: Bech32) returns array of AddressSigningRequests;
141
+ address: Bech32,
142
+ @title: 'Limit'
143
+ @description: 'Maximum number of rows (default 1000, at most 5000)'
144
+ @assert.range: [1, 5000]
145
+ limit: Integer,
146
+ @title: 'Skip'
147
+ @description: 'Number of rows to skip (default 0)'
148
+ @assert.range: [0, _]
149
+ skip: Integer) returns array of AddressSigningRequests;
159
150
 
160
151
  // ---------------------------------------------------------------------------
161
152
  // HSM (Hardware Security Module) Signing Actions