@odatano/core 2.0.0-rc.2 → 2.0.0-rc.20

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 (132) hide show
  1. package/@cds-models/CardanoAgentService/index.d.ts +251 -0
  2. package/@cds-models/CardanoAgentService/index.js +36 -0
  3. package/@cds-models/CardanoIndexerService/index.d.ts +139 -2
  4. package/@cds-models/CardanoIndexerService/index.js +18 -0
  5. package/@cds-models/CardanoODataService/index.d.ts +224 -0
  6. package/@cds-models/CardanoODataService/index.js +27 -0
  7. package/@cds-models/CardanoSignService/index.d.ts +5 -2
  8. package/@cds-models/CardanoTransactionService/index.d.ts +9 -9
  9. package/@cds-models/odatano/cardano/index.d.ts +316 -0
  10. package/@cds-models/odatano/cardano/index.js +33 -0
  11. package/README.md +195 -136
  12. package/db/schema.cds +2121 -1633
  13. package/package.json +179 -173
  14. package/src/index.d.ts +10 -10
  15. package/src/index.js +24 -14
  16. package/src/plugin.js +39 -52
  17. package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
  18. package/srv/blockchain/backends/blockfrost-backend.js +45 -158
  19. package/srv/blockchain/backends/cardano-backend.d.ts +78 -158
  20. package/srv/blockchain/backends/cardano-backend.js +14 -5
  21. package/srv/blockchain/backends/koios-backend.d.ts +126 -60
  22. package/srv/blockchain/backends/koios-backend.js +292 -202
  23. package/srv/blockchain/backends/ogmios-backend.d.ts +59 -96
  24. package/srv/blockchain/backends/ogmios-backend.js +241 -153
  25. package/srv/blockchain/backends/ogmios-frame-guard.d.ts +32 -0
  26. package/srv/blockchain/backends/ogmios-frame-guard.js +142 -0
  27. package/srv/blockchain/cardano-client.d.ts +50 -205
  28. package/srv/blockchain/cardano-client.js +80 -224
  29. package/srv/blockchain/cardano-indexer.d.ts +146 -244
  30. package/srv/blockchain/cardano-indexer.js +442 -285
  31. package/srv/blockchain/cardano-tx-builder.d.ts +19 -84
  32. package/srv/blockchain/cardano-tx-builder.js +21 -107
  33. package/srv/blockchain/crawler/certificate-backfill.d.ts +45 -0
  34. package/srv/blockchain/crawler/certificate-backfill.js +150 -0
  35. package/srv/blockchain/crawler/crawler.d.ts +121 -53
  36. package/srv/blockchain/crawler/crawler.js +402 -82
  37. package/srv/blockchain/crawler/hooks.d.ts +3 -14
  38. package/srv/blockchain/crawler/index.d.ts +5 -0
  39. package/srv/blockchain/crawler/index.js +35 -7
  40. package/srv/blockchain/crawler/sync-state.d.ts +44 -28
  41. package/srv/blockchain/crawler/sync-state.js +115 -43
  42. package/srv/blockchain/crawler/utxo-set-import.d.ts +69 -0
  43. package/srv/blockchain/crawler/utxo-set-import.js +269 -0
  44. package/srv/blockchain/ledger-state.d.ts +80 -0
  45. package/srv/blockchain/ledger-state.js +383 -0
  46. package/srv/blockchain/signing/cose-verifier.d.ts +5 -12
  47. package/srv/blockchain/signing/cose-verifier.js +6 -12
  48. package/srv/blockchain/signing/external-signer.d.ts +16 -113
  49. package/srv/blockchain/signing/external-signer.js +19 -122
  50. package/srv/blockchain/signing/hsm-signer.d.ts +13 -45
  51. package/srv/blockchain/signing/hsm-signer.js +23 -63
  52. package/srv/blockchain/signing/signature-verifier.d.ts +8 -44
  53. package/srv/blockchain/signing/signature-verifier.js +13 -54
  54. package/srv/blockchain/signing/submission-finalizer.d.ts +9 -36
  55. package/srv/blockchain/signing/submission-finalizer.js +16 -48
  56. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +71 -160
  57. package/srv/blockchain/transaction-building/buildooor-tx.js +185 -260
  58. package/srv/blockchain/transaction-building/cardano-tx.d.ts +8 -34
  59. package/srv/blockchain/wallet-worker/build-request.d.ts +4 -17
  60. package/srv/blockchain/wallet-worker/build-request.js +39 -23
  61. package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +25 -17
  62. package/srv/blockchain/wallet-worker/confirmation-tracker.js +87 -41
  63. package/srv/blockchain/wallet-worker/index.js +2 -8
  64. package/srv/blockchain/wallet-worker/job-store.d.ts +36 -103
  65. package/srv/blockchain/wallet-worker/job-store.js +0 -0
  66. package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +4 -20
  67. package/srv/blockchain/wallet-worker/lease-heartbeat.js +4 -20
  68. package/srv/blockchain/wallet-worker/signers.d.ts +6 -19
  69. package/srv/blockchain/wallet-worker/signers.js +3 -8
  70. package/srv/blockchain/wallet-worker/wallet-worker.d.ts +15 -71
  71. package/srv/blockchain/wallet-worker/wallet-worker.js +34 -90
  72. package/srv/cardano-agent-service.cds +146 -0
  73. package/srv/cardano-agent-service.d.ts +2 -0
  74. package/srv/cardano-agent-service.js +12 -0
  75. package/srv/cardano-indexer-service.cds +164 -73
  76. package/srv/cardano-indexer-service.js +156 -11
  77. package/srv/cardano-service.cds +45 -0
  78. package/srv/cardano-service.js +38 -96
  79. package/srv/cardano-sign-service.cds +200 -180
  80. package/srv/cardano-sign-service.js +55 -173
  81. package/srv/cardano-tx-service.cds +32 -26
  82. package/srv/cardano-tx-service.js +133 -195
  83. package/srv/cardano-worker-service.js +7 -15
  84. package/srv/server.d.ts +28 -86
  85. package/srv/server.js +95 -128
  86. package/srv/utils/agent-grants-config.d.ts +37 -0
  87. package/srv/utils/agent-grants-config.js +138 -0
  88. package/srv/utils/agent-grants.d.ts +262 -0
  89. package/srv/utils/agent-grants.js +914 -0
  90. package/srv/utils/agent-token-auth.d.ts +16 -0
  91. package/srv/utils/agent-token-auth.js +78 -0
  92. package/srv/utils/backend-request-handler.d.ts +2 -16
  93. package/srv/utils/backend-request-handler.js +3 -18
  94. package/srv/utils/collections.d.ts +4 -8
  95. package/srv/utils/collections.js +4 -8
  96. package/srv/utils/const.d.ts +19 -68
  97. package/srv/utils/const.js +20 -69
  98. package/srv/utils/crypto.d.ts +3 -12
  99. package/srv/utils/crypto.js +5 -18
  100. package/srv/utils/db-indexes.d.ts +25 -0
  101. package/srv/utils/db-indexes.js +89 -0
  102. package/srv/utils/db-sanitize.d.ts +27 -0
  103. package/srv/utils/db-sanitize.js +85 -0
  104. package/srv/utils/error-codes.d.ts +18 -73
  105. package/srv/utils/error-codes.js +17 -70
  106. package/srv/utils/errors.d.ts +34 -178
  107. package/srv/utils/errors.js +55 -217
  108. package/srv/utils/liveness.d.ts +16 -0
  109. package/srv/utils/liveness.js +41 -0
  110. package/srv/utils/mappers.d.ts +82 -210
  111. package/srv/utils/mappers.js +272 -293
  112. package/srv/utils/network-context.js +2 -11
  113. package/srv/utils/pg-order-nulls.d.ts +14 -0
  114. package/srv/utils/pg-order-nulls.js +57 -0
  115. package/srv/utils/plutus-placeholders.d.ts +6 -18
  116. package/srv/utils/plutus-placeholders.js +6 -20
  117. package/srv/utils/rate-limiter.d.ts +46 -0
  118. package/srv/utils/rate-limiter.js +116 -0
  119. package/srv/utils/service-events.d.ts +2 -22
  120. package/srv/utils/service-events.js +3 -23
  121. package/srv/utils/signing-helper.d.ts +3 -18
  122. package/srv/utils/signing-helper.js +10 -32
  123. package/srv/utils/tx-build-helper.d.ts +18 -92
  124. package/srv/utils/tx-build-helper.js +32 -123
  125. package/srv/utils/tx-request-parsers.d.ts +14 -20
  126. package/srv/utils/tx-request-parsers.js +33 -20
  127. package/srv/utils/tx-utils.d.ts +4 -23
  128. package/srv/utils/tx-utils.js +12 -41
  129. package/srv/utils/types.d.ts +112 -169
  130. package/srv/utils/types.js +2 -6
  131. package/srv/utils/validators.d.ts +19 -89
  132. package/srv/utils/validators.js +31 -138
@@ -1,6 +1,14 @@
1
1
  import { Transaction, BlockData, Address, UTxO, NetworkInformation, EpochData, MetadataLabelTx, PoolData, AccountData, DrepData, AssetInfo, LedgerProtocolParameters, ScriptEvaluationResult } from '../../utils/types';
2
- import { EvaluatingBackend, ChainSyncBackend, ChainSyncCallbacks, ChainSyncHandle, ChainPoint } from './cardano-backend';
2
+ import { EvaluatingBackend, ChainSyncBackend, ChainSyncCallbacks, ChainSyncHandle, ChainPoint, LedgerStateBackend } from './cardano-backend';
3
3
  import { Network } from '../cardano-client';
4
+ /**
5
+ * Decode a CIP-129 DRep ID (`drep1…`, 29 bytes) into credential hash and type. Header byte:
6
+ * high nibble 0x2 = DRep, low nibble 0x2 = key hash / 0x3 = script hash.
7
+ */
8
+ export declare function decodeDrepId(drepId: string): {
9
+ hashHex: string;
10
+ isScript: boolean;
11
+ };
4
12
  /** Resolve Ogmios ledger tip which may be 'origin' (genesis block) or a point */
5
13
  export declare function resolveOgmiosTip(tip: 'origin' | {
6
14
  slot: number;
@@ -11,15 +19,13 @@ export declare function resolveOgmiosTip(tip: 'origin' | {
11
19
  };
12
20
  /** Resolve Ogmios block height which may be 'origin' (genesis block) or a number */
13
21
  export declare function resolveOgmiosHeight(height: 'origin' | number): number;
14
- export declare class OgmiosBackend implements EvaluatingBackend, ChainSyncBackend {
22
+ /** CardanoBackend implementation over an Ogmios WebSocket (local node). */
23
+ export declare class OgmiosBackend implements EvaluatingBackend, ChainSyncBackend, LedgerStateBackend {
15
24
  readonly name = "ogmios";
16
25
  /**
17
- * Capability declaration — the orchestrator skips Ogmios for these without
18
- * counting circuit failures. Historic queries are out of protocol scope;
19
- * getAddress/getNetworkInformation previously FABRICATED placeholder data
20
- * (type:'base'/isScript:false/stakeAddress:null resp. maxSupply as
21
- * total/circulating) which preferLive routing then preferred over correct
22
- * Blockfrost/Koios data.
26
+ * Capability declaration — the orchestrator skips Ogmios for these without counting
27
+ * circuit failures. Historic queries are out of protocol scope, and address/network
28
+ * aggregates cannot be derived from state queries.
23
29
  */
24
30
  readonly unsupportedMethods: ReadonlySet<string>;
25
31
  private stateQueryClient;
@@ -30,56 +36,32 @@ export declare class OgmiosBackend implements EvaluatingBackend, ChainSyncBacken
30
36
  private network;
31
37
  private timeoutMs;
32
38
  private ogmiosUrl;
33
- /**
34
- * Constructor
35
- */
36
39
  constructor(network: Network, timeoutMs: number, ogmiosUrl: string);
37
40
  /**
38
- * Force fresh (non-keep-alive) HTTP connections for the Ogmios `/health` probe.
39
- *
40
- * createInteractionContext() opens the WebSocket, but FIRST probes
41
- * `GET http://<ogmios>/health` via the library's `cross-fetch` → node-fetch v2
42
- * → Node-core `http`. Since Node 19, `http.globalAgent` defaults to
43
- * keepAlive:true, so node-fetch reuses pooled sockets. Against Ogmios' Warp
44
- * server on Node 22/24 a reused socket the server has already half-closed
45
- * yields "Invalid response body … Premature close" the instant the body is
46
- * read — deterministically (Node 20's older http client tolerated it; `curl`
47
- * does too, so the /health response itself is well-formed and the node is
48
- * healthy). The lib pins cross-fetch even in 7.0 and exposes no way to inject
49
- * an agent into that internal fetch, so we neutralise keep-alive process-wide
50
- * for `http://`. Blast radius is tiny: the only `http://` consumer is the local
51
- * Ogmios probe — Blockfrost/Koios run over `https` with their own axios agents
52
- * and are unaffected. Runs once, lazily, only when Ogmios is actually used.
41
+ * Force non-keep-alive HTTP for the Ogmios `/health` probe: node-fetch v2 uses `http.globalAgent`,
42
+ * whose pooled sockets (kept alive since Node 19) fail with "Premature close" once Ogmios' Warp server
43
+ * half-closes them. No agent hook exists, so keep-alive is disabled process-wide for `http://` only.
53
44
  */
54
45
  private static keepAliveDisabled;
55
46
  private static disableHttpKeepAlive;
56
47
  /** Validate Ogmios URL scheme and reject dangerous protocols */
57
48
  private static validateOgmiosUrl;
58
49
  /**
59
- * Bound an init step in time. A hung WebSocket connect/handshake (e.g. the
60
- * node is alive but too busy catching up to answer) would otherwise block
61
- * forever — there is no built-in connect timeout — hanging the whole
62
- * app-context bootstrap (seen as a 6h CI job timeout). On timeout we reject
63
- * with a message containing "timeout" so the orchestrator's transient-error
64
- * retry picks it up instead of dying.
50
+ * Bound an init step in time: the WebSocket connect/handshake has no built-in timeout and
51
+ * can hang when the node is busy. The rejection message contains "timeout" so the
52
+ * orchestrator's transient-error retry picks it up.
65
53
  */
66
54
  private withInitTimeout;
67
55
  /**
68
- * Force-release an Ogmios interaction socket after a failed/expired open or
69
- * close step. The runtime uses `ws` (and therefore supports `terminate`), but
70
- * the close fallback keeps the helper compatible with the public structural
71
- * InteractionContext type and lightweight test doubles.
56
+ * Force-release an interaction socket after a failed/expired open or close. The runtime
57
+ * socket is `ws` (has `terminate`); the `close` fallback keeps test doubles working.
72
58
  */
73
59
  private forceCloseContext;
74
- /**
75
- * Initialize the Ogmios backend connection
76
- */
60
+ /** Open the interaction context and the query/submission clients. */
77
61
  init(): Promise<boolean>;
78
62
  /**
79
- * Reconnect when the WebSocket has died since the last successful init.
80
- * No-op when never initialized (test-injected clients) — startup-init
81
- * recovery is the orchestrator's job (lazy init retry in CardanoClient).
82
- * Concurrent callers share one reconnect attempt.
63
+ * Reconnect when the WebSocket died since the last init. No-op when never initialized
64
+ * (test-injected clients); concurrent callers share one reconnect attempt.
83
65
  */
84
66
  private ensureConnected;
85
67
  /**
@@ -107,29 +89,23 @@ export declare class OgmiosBackend implements EvaluatingBackend, ChainSyncBacken
107
89
  */
108
90
  getTransactionMetadata(_tx_hash: string): Promise<MetadataLabelTx[]>;
109
91
  /**
110
- * Get specific Drep Data (not supported for Ogmios)
111
- * @param _drepId drep id
112
- * @returns {Promise<DrepData>} drep data
92
+ * DRep data from the live ledger state (`queryLedgerState/delegateRepresentatives`) via the
93
+ * raw `Method()` primitive, since the client ships no wrapper. Ogmios lists only REGISTERED
94
+ * DReps: retired/unknown → NotFoundError; `expired` is derived from the mandate epoch.
95
+ * @param drepId CIP-129 bech32 DRep ID (`drep1…`)
113
96
  */
114
- getDrep(_drepId: string): Promise<DrepData>;
97
+ getDrep(drepId: string): Promise<DrepData>;
115
98
  /**
116
99
  * Get Asset Info (not supported for Ogmios — no aggregate-supply query in the protocol)
117
100
  * @param _unit asset unit (policyId + assetNameHex)
118
101
  * @returns {Promise<AssetInfo>} asset info
119
102
  */
120
103
  getAssetInfo(_unit: string): Promise<AssetInfo>;
121
- /**
122
- * Get specific Network Information (not supported — Ogmios state queries
123
- * expose no supply/stake aggregates; the previous implementation fabricated
124
- * maxSupply as total/circulating, which preferLive routing then preferred
125
- * over correct Blockfrost/Koios data)
126
- */
104
+ /** Not supported — Ogmios state queries expose no supply/stake aggregates. */
127
105
  getNetworkInformation(): Promise<NetworkInformation>;
128
106
  /**
129
- * Get current specific Address Data (not supported — address type, script
130
- * flag and stake address are not derivable from Ogmios state queries; the
131
- * previous implementation fabricated type:'base'/isScript:false/
132
- * stakeAddress:null. UTxOs remain available via getAddressUtxos.)
107
+ * Not supported — address type, script flag and stake address are not derivable from
108
+ * state queries. UTxOs remain available via getAddressUtxos.
133
109
  */
134
110
  getAddress(_address: string): Promise<Address>;
135
111
  /** get current specific Address UTxOs
@@ -137,12 +113,15 @@ export declare class OgmiosBackend implements EvaluatingBackend, ChainSyncBacken
137
113
  * @returns {Promise<UTxO[]>} address UTxOs
138
114
  */
139
115
  getAddressUtxos(address: string): Promise<UTxO[]>;
116
+ /** Ogmios `Utxo` entry → normalized UTxO line (shared by the address query and the set import). */
117
+ private mapOgmiosUtxo;
140
118
  /**
141
- * Get Address Transactions (not supported by Ogmios - use historical backend)
142
- * Ogmios is a live state query backend and does not provide historical transaction data
143
- * @param _address bech32 address
144
- * @returns {Promise<Transaction[]>} always throws - use historical backend instead
119
+ * Whole UTxO set as of `point` (crawler snapshot import) on a SEPARATE WebSocket: local-state-query
120
+ * holds one acquired point per connection, so the shared socket would pin live queries to the past.
121
+ * The point must be inside the node's volatile window (last 2160 blocks) or acquisition is refused.
145
122
  */
123
+ queryUtxoSetAt(point: ChainPoint): Promise<UTxO[]>;
124
+ /** Not supported — Ogmios is a live state-query backend; use Blockfrost/Koios. */
146
125
  getAddressTransactions(_address: string): Promise<Transaction[]>;
147
126
  /**
148
127
  * Get current specific Pool Data
@@ -189,59 +168,43 @@ export declare class OgmiosBackend implements EvaluatingBackend, ChainSyncBacken
189
168
  */
190
169
  getCurrentSlot(): Promise<number>;
191
170
  /**
192
- * Check whether a UTxO is still unspent via Ogmios `queryLedgerState/utxo`
193
- * with an outputReferences filter. Empty result means spent or nonexistent.
171
+ * Unspent check via `queryLedgerState/utxo` with an outputReferences filter; empty = spent or nonexistent.
194
172
  * @param txHash 64-char lowercase hex
195
173
  * @param outputIndex non-negative integer
196
- * @returns {Promise<boolean>} true iff the UTxO exists and is unspent
197
174
  */
198
175
  isUtxoUnspent(txHash: string, outputIndex: number): Promise<boolean>;
199
- /**
200
- * Shutdown the Ogmios Backend
201
- * Closes all connections and marks as shutdown
202
- */
176
+ /** Close the WebSocket and mark the backend as shut down. */
203
177
  shutdown(): Promise<void>;
204
- /**
205
- * Check if backend is connected
206
- */
207
178
  isConnected(): boolean;
208
- /**
209
- * Ensure the client is not shutdown before operations
210
- */
211
179
  private ensureNotShutdown;
212
180
  /**
213
- * Convert Ogmios value format to odatano amount array
214
- * Ogmios: { ada: { lovelace: 1000000 }, policyId: { assetName: quantity } }
215
- * Standard: [{ unit: 'lovelace', quantity: '1000000' }, { unit: 'policyId.assetName', quantity: 'N' }]
181
+ * Ogmios value `{ ada: { lovelace }, policyId: { assetName: qty } }` →
182
+ * `[{ unit: 'lovelace', quantity }, { unit: policyId+assetName, quantity }]`.
216
183
  */
217
184
  private convertOgmiosValue;
218
185
  /**
219
- * Open a dedicated chain-synchronization stream. Uses its own InteractionContext
220
- * (a separate WebSocket) from the query/submission clients, because it is a
221
- * long-lived stream. `sequential: true` + `inFlight: 1` deliver blocks one at a
222
- * time in order, which the crawler needs for reorg detection and serial persist.
223
- *
224
- * KNOWN LIMITATIONS (documented, to harden against a live node — see CRAWLER_DESIGN.md):
225
- * - Input address/amount are left empty: Ogmios chain-sync inputs are bare
226
- * references ({txId,index}); the indexer resolves them from already-indexed
227
- * outputs (indexBlockFull, C3).
228
- * - Per-tx `size` and `deposit` are not surfaced by chain-sync (set 0).
229
- * - Output `referenceScriptHash` is not derived from the inline script yet.
186
+ * Open a long-lived chain-sync stream on its own WebSocket. `sequential: true` + `inFlight: 1`
187
+ * deliver blocks strictly in order (required by reorg detection and serial persist). Inputs arrive
188
+ * as bare references (resolved by the indexer from indexed outputs); per-tx size/deposit are not surfaced.
230
189
  */
231
190
  openChainSync(from: ChainPoint[] | 'origin', callbacks: ChainSyncCallbacks): Promise<ChainSyncHandle>;
232
191
  /**
233
- * Map an Ogmios Praos block into our BlockData + its transactions. Block-level
234
- * fees are the sum of per-tx fees; epoch/epochSlot are derived from the slot via
235
- * the network's Shelley anchor (same config the tx-builder uses).
192
+ * Map an Ogmios Praos block to BlockData + transactions. Block fees are the sum of per-tx
193
+ * fees; epoch/epochSlot derive from the slot via the Shelley anchor. A phase-2 failure without
194
+ * `total_collateral` still carries its declared fee here; applyCollateralFees() corrects it.
236
195
  */
237
196
  private mapOgmiosBlock;
238
197
  /**
239
- * Map a single Ogmios chain-sync transaction into our Transaction. Outputs, fee
240
- * and metadata are mapped fully; inputs are kept as bare references (address/amount
241
- * resolved downstream by the indexer). `spends` selects the ledger-applied
242
- * partition: a phase-2-invalid transaction consumes collaterals and creates only
243
- * its collateral-return output, never its declared regular inputs/outputs.
198
+ * Map one chain-sync transaction. Inputs stay bare references (resolved by the indexer).
199
+ * `spends` selects the ledger-applied partition: a phase-2-invalid tx consumes collaterals
200
+ * and creates only its collateral-return output; the fee follows that partition too.
244
201
  */
245
202
  private mapOgmiosTx;
203
+ /**
204
+ * Normalize Ogmios certificates onto the shared `CertificateKind` vocabulary. A `stakeDelegation`
205
+ * with both pool and DRep target is split into two entries with the same index (as db-sync
206
+ * reports it); bare credential hashes are re-encoded as bech32 to match the other tables.
207
+ */
208
+ private mapOgmiosCertificates;
246
209
  }
247
210
  //# sourceMappingURL=ogmios-backend.d.ts.map