@odatano/core 2.0.0-rc.3 → 2.0.0-rc.30

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 (162) 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/CardanoBackendService/index.d.ts +357 -0
  4. package/@cds-models/CardanoBackendService/index.js +40 -0
  5. package/@cds-models/CardanoIndexerService/index.d.ts +194 -2
  6. package/@cds-models/CardanoIndexerService/index.js +25 -0
  7. package/@cds-models/CardanoODataService/index.d.ts +294 -7
  8. package/@cds-models/CardanoODataService/index.js +33 -0
  9. package/@cds-models/CardanoSignService/index.d.ts +28 -3
  10. package/@cds-models/CardanoSignService/index.js +3 -0
  11. package/@cds-models/CardanoTransactionService/index.d.ts +52 -19
  12. package/@cds-models/CardanoTransactionService/index.js +4 -0
  13. package/@cds-models/index.d.ts +18 -0
  14. package/@cds-models/index.js +3 -0
  15. package/@cds-models/odatano/cardano/index.d.ts +408 -7
  16. package/@cds-models/odatano/cardano/index.js +42 -0
  17. package/README.md +64 -5
  18. package/db/schema.cds +677 -13
  19. package/db/types.cds +27 -0
  20. package/package.json +182 -173
  21. package/scripts/migrate-slot-leader.mjs +104 -0
  22. package/scripts/migrate-txseq.mjs +147 -0
  23. package/src/index.d.ts +11 -10
  24. package/src/index.js +28 -14
  25. package/src/plugin.js +39 -52
  26. package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
  27. package/srv/blockchain/backends/blockfrost-backend.js +49 -160
  28. package/srv/blockchain/backends/cardano-backend.d.ts +104 -158
  29. package/srv/blockchain/backends/cardano-backend.js +19 -5
  30. package/srv/blockchain/backends/koios-backend.d.ts +126 -60
  31. package/srv/blockchain/backends/koios-backend.js +356 -217
  32. package/srv/blockchain/backends/odatano-backend.d.ts +64 -0
  33. package/srv/blockchain/backends/odatano-backend.js +170 -0
  34. package/srv/blockchain/backends/ogmios-backend.d.ts +162 -94
  35. package/srv/blockchain/backends/ogmios-backend.js +548 -197
  36. package/srv/blockchain/backends/ogmios-frame-guard.d.ts +32 -0
  37. package/srv/blockchain/backends/ogmios-frame-guard.js +142 -0
  38. package/srv/blockchain/cardano-client.d.ts +78 -205
  39. package/srv/blockchain/cardano-client.js +186 -242
  40. package/srv/blockchain/cardano-indexer.d.ts +302 -242
  41. package/srv/blockchain/cardano-indexer.js +1191 -362
  42. package/srv/blockchain/cardano-tx-builder.d.ts +43 -81
  43. package/srv/blockchain/cardano-tx-builder.js +177 -132
  44. package/srv/blockchain/crawler/certificate-backfill.d.ts +67 -0
  45. package/srv/blockchain/crawler/certificate-backfill.js +169 -0
  46. package/srv/blockchain/crawler/crawler.d.ts +139 -54
  47. package/srv/blockchain/crawler/crawler.js +478 -96
  48. package/srv/blockchain/crawler/hooks.d.ts +3 -14
  49. package/srv/blockchain/crawler/index.d.ts +5 -0
  50. package/srv/blockchain/crawler/index.js +35 -7
  51. package/srv/blockchain/crawler/sync-state.d.ts +46 -28
  52. package/srv/blockchain/crawler/sync-state.js +128 -43
  53. package/srv/blockchain/crawler/transaction-backfill.d.ts +52 -0
  54. package/srv/blockchain/crawler/transaction-backfill.js +283 -0
  55. package/srv/blockchain/crawler/utxo-set-import.d.ts +78 -0
  56. package/srv/blockchain/crawler/utxo-set-import.js +363 -0
  57. package/srv/blockchain/ledger-state.d.ts +101 -0
  58. package/srv/blockchain/ledger-state.js +432 -0
  59. package/srv/blockchain/pending-spends.d.ts +28 -0
  60. package/srv/blockchain/pending-spends.js +89 -0
  61. package/srv/blockchain/signing/cose-verifier.d.ts +5 -12
  62. package/srv/blockchain/signing/cose-verifier.js +6 -12
  63. package/srv/blockchain/signing/external-signer.d.ts +16 -113
  64. package/srv/blockchain/signing/external-signer.js +19 -122
  65. package/srv/blockchain/signing/hsm-signer.d.ts +13 -45
  66. package/srv/blockchain/signing/hsm-signer.js +23 -63
  67. package/srv/blockchain/signing/signature-verifier.d.ts +8 -44
  68. package/srv/blockchain/signing/signature-verifier.js +13 -54
  69. package/srv/blockchain/signing/submission-finalizer.d.ts +9 -36
  70. package/srv/blockchain/signing/submission-finalizer.js +16 -49
  71. package/srv/blockchain/stored-chain.d.ts +33 -0
  72. package/srv/blockchain/stored-chain.js +234 -0
  73. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +108 -160
  74. package/srv/blockchain/transaction-building/buildooor-tx.js +620 -285
  75. package/srv/blockchain/transaction-building/caller-datums.d.ts +17 -0
  76. package/srv/blockchain/transaction-building/caller-datums.js +50 -0
  77. package/srv/blockchain/transaction-building/cardano-tx.d.ts +10 -35
  78. package/srv/blockchain/transaction-rows.d.ts +12 -0
  79. package/srv/blockchain/transaction-rows.js +43 -0
  80. package/srv/blockchain/wallet-worker/build-request.d.ts +4 -17
  81. package/srv/blockchain/wallet-worker/build-request.js +48 -24
  82. package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +25 -17
  83. package/srv/blockchain/wallet-worker/confirmation-tracker.js +87 -41
  84. package/srv/blockchain/wallet-worker/index.js +2 -8
  85. package/srv/blockchain/wallet-worker/job-store.d.ts +36 -103
  86. package/srv/blockchain/wallet-worker/job-store.js +0 -0
  87. package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +4 -20
  88. package/srv/blockchain/wallet-worker/lease-heartbeat.js +4 -20
  89. package/srv/blockchain/wallet-worker/signers.d.ts +6 -19
  90. package/srv/blockchain/wallet-worker/signers.js +3 -8
  91. package/srv/blockchain/wallet-worker/wallet-worker.d.ts +15 -71
  92. package/srv/blockchain/wallet-worker/wallet-worker.js +40 -91
  93. package/srv/cardano-agent-service.cds +146 -0
  94. package/srv/cardano-agent-service.d.ts +2 -0
  95. package/srv/cardano-agent-service.js +12 -0
  96. package/srv/cardano-backend-service.cds +52 -0
  97. package/srv/cardano-backend-service.d.ts +2 -0
  98. package/srv/cardano-backend-service.js +244 -0
  99. package/srv/cardano-indexer-service.cds +201 -73
  100. package/srv/cardano-indexer-service.js +280 -11
  101. package/srv/cardano-service.cds +56 -1
  102. package/srv/cardano-service.js +52 -113
  103. package/srv/cardano-sign-service.cds +200 -180
  104. package/srv/cardano-sign-service.js +55 -173
  105. package/srv/cardano-tx-service.cds +439 -364
  106. package/srv/cardano-tx-service.js +305 -209
  107. package/srv/cardano-ui.cds +16 -16
  108. package/srv/cardano-worker-service.js +7 -15
  109. package/srv/cbor/parse.js +13 -1
  110. package/srv/server.d.ts +28 -86
  111. package/srv/server.js +127 -135
  112. package/srv/utils/agent-grants-config.d.ts +37 -0
  113. package/srv/utils/agent-grants-config.js +138 -0
  114. package/srv/utils/agent-grants.d.ts +262 -0
  115. package/srv/utils/agent-grants.js +922 -0
  116. package/srv/utils/agent-token-auth.d.ts +16 -0
  117. package/srv/utils/agent-token-auth.js +78 -0
  118. package/srv/utils/backend-request-handler.d.ts +2 -16
  119. package/srv/utils/backend-request-handler.js +3 -18
  120. package/srv/utils/collections.d.ts +4 -8
  121. package/srv/utils/collections.js +4 -8
  122. package/srv/utils/const.d.ts +30 -67
  123. package/srv/utils/const.js +32 -72
  124. package/srv/utils/crypto.d.ts +3 -12
  125. package/srv/utils/crypto.js +5 -18
  126. package/srv/utils/db-indexes.d.ts +25 -0
  127. package/srv/utils/db-indexes.js +94 -0
  128. package/srv/utils/db-sanitize.d.ts +27 -0
  129. package/srv/utils/db-sanitize.js +85 -0
  130. package/srv/utils/epoch-slots.d.ts +13 -0
  131. package/srv/utils/epoch-slots.js +25 -0
  132. package/srv/utils/error-codes.d.ts +20 -73
  133. package/srv/utils/error-codes.js +19 -70
  134. package/srv/utils/errors.d.ts +50 -177
  135. package/srv/utils/errors.js +94 -218
  136. package/srv/utils/liveness.d.ts +16 -0
  137. package/srv/utils/liveness.js +40 -0
  138. package/srv/utils/mappers.d.ts +128 -214
  139. package/srv/utils/mappers.js +354 -299
  140. package/srv/utils/network-context.js +2 -11
  141. package/srv/utils/pg-inline-json.d.ts +8 -0
  142. package/srv/utils/pg-inline-json.js +62 -0
  143. package/srv/utils/pg-order-nulls.d.ts +14 -0
  144. package/srv/utils/pg-order-nulls.js +56 -0
  145. package/srv/utils/plutus-placeholders.d.ts +23 -16
  146. package/srv/utils/plutus-placeholders.js +63 -27
  147. package/srv/utils/rate-limiter.d.ts +46 -0
  148. package/srv/utils/rate-limiter.js +116 -0
  149. package/srv/utils/service-events.d.ts +2 -22
  150. package/srv/utils/service-events.js +3 -23
  151. package/srv/utils/signing-helper.d.ts +3 -18
  152. package/srv/utils/signing-helper.js +10 -32
  153. package/srv/utils/tx-build-helper.d.ts +26 -92
  154. package/srv/utils/tx-build-helper.js +68 -123
  155. package/srv/utils/tx-request-parsers.d.ts +107 -21
  156. package/srv/utils/tx-request-parsers.js +433 -34
  157. package/srv/utils/tx-utils.d.ts +4 -23
  158. package/srv/utils/tx-utils.js +12 -41
  159. package/srv/utils/types.d.ts +238 -169
  160. package/srv/utils/types.js +2 -6
  161. package/srv/utils/validators.d.ts +24 -90
  162. package/srv/utils/validators.js +50 -147
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DB_INDEXES = void 0;
7
+ exports.indexStatement = indexStatement;
8
+ exports.ensureDbIndexes = ensureDbIndexes;
9
+ /**
10
+ * Secondary indexes the CDS model cannot declare (temporal keys start with `validFrom`, so business-key
11
+ * lookups would scan). Created at start with CREATE INDEX IF NOT EXISTS, unquoted identifiers so Postgres
12
+ * folds them like @cap-js does; failures are logged, never fatal. HANA is skipped (column store, no IF NOT EXISTS).
13
+ */
14
+ const cds_1 = __importDefault(require("@sap/cds"));
15
+ const logger = cds_1.default.log('DbIndexes');
16
+ /** Every entry answers a query the service or the crawler actually runs. */
17
+ exports.DB_INDEXES = Object.freeze([
18
+ // Blocks: latest (ORDER BY height DESC), byHeight, crawler `height in`, rollback `slot >`, epoch filters
19
+ { name: 'odatano_cardano_blocks_height', table: 'odatano_cardano_Blocks', columns: 'height' },
20
+ // CAP renders `$orderby=height desc` as DESC NULLS LAST, which the plain ASC NULLS LAST
21
+ // index cannot serve backwards; the plain one stays for ASC and equality.
22
+ { name: 'odatano_cardano_blocks_height_desc', table: 'odatano_cardano_Blocks', columns: 'height DESC', postgres: 'height DESC NULLS LAST' },
23
+ { name: 'odatano_cardano_blocks_slot', table: 'odatano_cardano_Blocks', columns: 'slot' },
24
+ { name: 'odatano_cardano_blocks_epoch', table: 'odatano_cardano_Blocks', columns: 'epochNumber' },
25
+ // block counts per pool (Pools.blocksEpoch / blocksMinted from crawled blocks)
26
+ { name: 'odatano_cardano_blocks_slotleader', table: 'odatano_cardano_Blocks', columns: 'slotLeader, slot' },
27
+ // Transactions of a block (rollback `blockHash in`, OData filters by block / height)
28
+ { name: 'odatano_cardano_transactions_block', table: 'odatano_cardano_Transactions', columns: 'blockHash' },
29
+ { name: 'odatano_cardano_transactions_height', table: 'odatano_cardano_Transactions', columns: 'blockHeight' },
30
+ // Input/output rows back to their transaction (`tx` association, stale-seq check of the crawler)
31
+ { name: 'odatano_cardano_transactions_txseq', table: 'odatano_cardano_Transactions', columns: 'txSeq' },
32
+ // GetMetadataByTxHash, rollback
33
+ { name: 'odatano_cardano_transactionmetadata_tx', table: 'odatano_cardano_TransactionMetadata', columns: 'tx_hash' },
34
+ // rollback `txHash in` (key is unit, txHash)
35
+ { name: 'odatano_cardano_assethistory_tx', table: 'odatano_cardano_AssetHistory', columns: 'txHash' },
36
+ // temporal entities: the business key behind validFrom
37
+ { name: 'odatano_cardano_assets_unit', table: 'odatano_cardano_Assets', columns: 'unit' },
38
+ { name: 'odatano_cardano_addresses_address', table: 'odatano_cardano_Addresses', columns: 'address' },
39
+ { name: 'odatano_cardano_addressutxos_address', table: 'odatano_cardano_AddressUTxOs', columns: 'address_address' },
40
+ { name: 'odatano_cardano_addressassets_address', table: 'odatano_cardano_AddressAssets', columns: 'address_address' },
41
+ { name: 'odatano_cardano_utxoassets_address', table: 'odatano_cardano_UTxOAssets', columns: 'utxo_address_address' },
42
+ { name: 'odatano_cardano_addresstransactions_tx', table: 'odatano_cardano_AddressTransactions', columns: 'tx_hash' },
43
+ { name: 'odatano_cardano_accounts_stake', table: 'odatano_cardano_Accounts', columns: 'stakeAddress' },
44
+ { name: 'odatano_cardano_pools_poolid', table: 'odatano_cardano_Pools', columns: 'poolId' },
45
+ { name: 'odatano_cardano_dreps_drepid', table: 'odatano_cardano_Dreps', columns: 'drepId' },
46
+ // agent token lane: one lookup by token hash per request
47
+ { name: 'odatano_cardano_cardanoagentgrants_token', table: 'odatano_cardano_CardanoAgentGrants', columns: 'tokenHash' },
48
+ // crawler-fed ledger state: "who spent this output" and delegation per stake key / pool / DRep
49
+ { name: 'odatano_cardano_transactioninputs_spent', table: 'odatano_cardano_TransactionInputs', columns: 'spentTxHash, spentOutputIndex' },
50
+ { name: 'odatano_cardano_transactioncertificates_stake', table: 'odatano_cardano_TransactionCertificates', columns: 'stakeAddress' },
51
+ { name: 'odatano_cardano_transactioncertificates_pool', table: 'odatano_cardano_TransactionCertificates', columns: 'poolId' },
52
+ { name: 'odatano_cardano_transactioncertificates_drep', table: 'odatano_cardano_TransactionCertificates', columns: 'drepId' },
53
+ { name: 'odatano_cardano_transactionwithdrawals_stake', table: 'odatano_cardano_TransactionWithdrawals', columns: 'stakeAddress' },
54
+ // crawler-fed UTxO set: open rows per address, "who spent", stake-key rollups, asset holders
55
+ { name: 'odatano_cardano_ledgerutxos_address', table: 'odatano_cardano_LedgerUTxOs', columns: 'address, spentTxHash' },
56
+ { name: 'odatano_cardano_ledgerutxos_spent', table: 'odatano_cardano_LedgerUTxOs', columns: 'spentTxHash' },
57
+ { name: 'odatano_cardano_ledgeraddresses_stake', table: 'odatano_cardano_LedgerAddresses', columns: 'stakeAddress' },
58
+ { name: 'odatano_cardano_ledgeraddresses_paycred', table: 'odatano_cardano_LedgerAddresses', columns: 'paymentCredential' },
59
+ { name: 'odatano_cardano_ledgerutxoassets_unit', table: 'odatano_cardano_LedgerUTxOAssets', columns: 'unit' },
60
+ { name: 'odatano_cardano_ledgeraddressassets_unit', table: 'odatano_cardano_LedgerAddressAssets', columns: 'unit' },
61
+ ]);
62
+ /** The statement for one entry; exported so tests pin the shape. */
63
+ function indexStatement(spec, kind = 'sqlite') {
64
+ const columns = kind === 'postgres' && spec.postgres ? spec.postgres : spec.columns;
65
+ return `CREATE INDEX IF NOT EXISTS ${spec.name} ON ${spec.table} (${columns})`;
66
+ }
67
+ /** Creates every missing index; a failing statement is logged and skipped, the others still run. */
68
+ async function ensureDbIndexes(runner = cds_1.default.db) {
69
+ const ensured = [];
70
+ const failed = [];
71
+ if (!runner) {
72
+ logger.debug('no database service connected, indexes skipped');
73
+ return { ensured, failed };
74
+ }
75
+ const kind = String(runner.kind ?? 'sqlite');
76
+ if (kind === 'hana') {
77
+ logger.info('HANA: secondary indexes not created (column store, no IF NOT EXISTS)');
78
+ return { ensured, failed };
79
+ }
80
+ for (const spec of exports.DB_INDEXES) {
81
+ try {
82
+ await runner.run(indexStatement(spec, kind));
83
+ ensured.push(spec.name);
84
+ }
85
+ catch (err) {
86
+ failed.push(spec.name);
87
+ logger.warn(`index ${spec.name} on ${spec.table} not ensured: ${String(err?.message ?? err)}`);
88
+ }
89
+ }
90
+ if (failed.length === 0)
91
+ logger.info(`${ensured.length} indexes ensured`);
92
+ return { ensured, failed };
93
+ }
94
+ //# sourceMappingURL=db-indexes.js.map
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Strips U+0000 from every row this plugin writes: PostgreSQL cannot store NUL in `text`, and
3
+ * @cap-js/postgres bulk rows go through a JSON parser that rejects the NUL escape, failing the whole write.
4
+ */
5
+ /** Remove U+0000 from every string value of the row (nested objects included); same row when unchanged. */
6
+ export declare function stripNulStrings<T>(row: T): T;
7
+ /** Sanitise a row array for the database; cheap when nothing needs changing. */
8
+ export declare function sanitizeRows<T>(rows: T[]): T[];
9
+ /** The slice of a db-service request the sanitizer looks at (structural, so tests can fake it). */
10
+ export interface DbWriteRequest {
11
+ query?: unknown;
12
+ target?: {
13
+ name?: string;
14
+ } | null;
15
+ }
16
+ /** `before` handler for the db service: strips U+0000 from INSERT / UPSERT / UPDATE rows in place. */
17
+ export declare function sanitizeDbRequest(req: DbWriteRequest): void;
18
+ interface HookableService {
19
+ before(event: string | string[], handler: (req: DbWriteRequest) => void): unknown;
20
+ }
21
+ /**
22
+ * Hook the sanitizer into the database service (idempotent per instance; no-op without a db).
23
+ * @returns true when the hook was installed by this call
24
+ */
25
+ export declare function installDbSanitizer(db?: HookableService | undefined): boolean;
26
+ export {};
27
+ //# sourceMappingURL=db-sanitize.d.ts.map
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.stripNulStrings = stripNulStrings;
7
+ exports.sanitizeRows = sanitizeRows;
8
+ exports.sanitizeDbRequest = sanitizeDbRequest;
9
+ exports.installDbSanitizer = installDbSanitizer;
10
+ const cds_1 = __importDefault(require("@sap/cds"));
11
+ /**
12
+ * Strips U+0000 from every row this plugin writes: PostgreSQL cannot store NUL in `text`, and
13
+ * @cap-js/postgres bulk rows go through a JSON parser that rejects the NUL escape, failing the whole write.
14
+ */
15
+ /** Remove U+0000 from every string value of the row (nested objects included); same row when unchanged. */
16
+ function stripNulStrings(row) {
17
+ if (typeof row === 'string')
18
+ return (row.includes('\u0000') ? row.replaceAll('\u0000', '') : row);
19
+ if (row === null || typeof row !== 'object' || Buffer.isBuffer(row))
20
+ return row;
21
+ if (Array.isArray(row)) {
22
+ let out = null;
23
+ for (let i = 0; i < row.length; i++) {
24
+ const v = stripNulStrings(row[i]);
25
+ if (v !== row[i]) {
26
+ out ??= [...row];
27
+ out[i] = v;
28
+ }
29
+ }
30
+ return (out ?? row);
31
+ }
32
+ let out = null;
33
+ for (const [k, v] of Object.entries(row)) {
34
+ const nv = stripNulStrings(v);
35
+ if (nv !== v) {
36
+ out ??= { ...row };
37
+ out[k] = nv;
38
+ }
39
+ }
40
+ return (out ?? row);
41
+ }
42
+ /** Sanitise a row array for the database; cheap when nothing needs changing. */
43
+ function sanitizeRows(rows) {
44
+ let out = null;
45
+ for (let i = 0; i < rows.length; i++) {
46
+ const r = stripNulStrings(rows[i]);
47
+ if (r !== rows[i]) {
48
+ out ??= [...rows];
49
+ out[i] = r;
50
+ }
51
+ }
52
+ return out ?? rows;
53
+ }
54
+ /** Only this plugin's entities are rewritten; a consumer's own data is never touched. */
55
+ const OWN_NAMESPACE = 'odatano.cardano.';
56
+ /** `before` handler for the db service: strips U+0000 from INSERT / UPSERT / UPDATE rows in place. */
57
+ function sanitizeDbRequest(req) {
58
+ if (!req.target?.name?.startsWith(OWN_NAMESPACE))
59
+ return;
60
+ const q = req.query;
61
+ if (!q || typeof q !== 'object')
62
+ return;
63
+ const ins = q.INSERT;
64
+ if (ins && Array.isArray(ins.entries))
65
+ ins.entries = sanitizeRows(ins.entries);
66
+ const ups = q.UPSERT;
67
+ if (ups && Array.isArray(ups.entries))
68
+ ups.entries = sanitizeRows(ups.entries);
69
+ const upd = q.UPDATE;
70
+ if (upd?.data && typeof upd.data === 'object')
71
+ upd.data = stripNulStrings(upd.data);
72
+ }
73
+ const installed = new WeakSet();
74
+ /**
75
+ * Hook the sanitizer into the database service (idempotent per instance; no-op without a db).
76
+ * @returns true when the hook was installed by this call
77
+ */
78
+ function installDbSanitizer(db = cds_1.default.db) {
79
+ if (!db || typeof db.before !== 'function' || installed.has(db))
80
+ return false;
81
+ db.before(['CREATE', 'UPSERT', 'UPDATE'], sanitizeDbRequest);
82
+ installed.add(db);
83
+ return true;
84
+ }
85
+ //# sourceMappingURL=db-sanitize.js.map
@@ -0,0 +1,13 @@
1
+ import { EPOCH_CONFIG_BY_NETWORK } from './const';
2
+ type EpochNetwork = keyof typeof EPOCH_CONFIG_BY_NETWORK;
3
+ /** Epoch a slot belongs to, from the network's Shelley anchor. */
4
+ export declare function epochOfSlot(network: EpochNetwork, slot: number): number;
5
+ /** First absolute slot of an epoch, from the network's Shelley anchor. */
6
+ export declare function epochStartSlot(network: EpochNetwork, epoch: number): number;
7
+ /**
8
+ * Absolute POSIX seconds for a slot via the Shelley-anchored genesis infos (exact for Shelley-era
9
+ * slots). Ogmios' `eraStart.time` is RelativeTime since system start, not a Unix timestamp.
10
+ */
11
+ export declare function slotToPosixSeconds(network: EpochNetwork, slot: number): number;
12
+ export {};
13
+ //# sourceMappingURL=epoch-slots.d.ts.map
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.epochOfSlot = epochOfSlot;
4
+ exports.epochStartSlot = epochStartSlot;
5
+ exports.slotToPosixSeconds = slotToPosixSeconds;
6
+ const const_1 = require("./const");
7
+ /** Epoch a slot belongs to, from the network's Shelley anchor. */
8
+ function epochOfSlot(network, slot) {
9
+ const cfg = const_1.EPOCH_CONFIG_BY_NETWORK[network];
10
+ return cfg.shelleyStartEpoch + Math.floor((slot - cfg.shelleyStartSlot) / cfg.slotsPerEpoch);
11
+ }
12
+ /** First absolute slot of an epoch, from the network's Shelley anchor. */
13
+ function epochStartSlot(network, epoch) {
14
+ const cfg = const_1.EPOCH_CONFIG_BY_NETWORK[network];
15
+ return cfg.shelleyStartSlot + (epoch - cfg.shelleyStartEpoch) * cfg.slotsPerEpoch;
16
+ }
17
+ /**
18
+ * Absolute POSIX seconds for a slot via the Shelley-anchored genesis infos (exact for Shelley-era
19
+ * slots). Ogmios' `eraStart.time` is RelativeTime since system start, not a Unix timestamp.
20
+ */
21
+ function slotToPosixSeconds(network, slot) {
22
+ const genesis = const_1.GENESIS_INFOS_BY_NETWORK[network];
23
+ return Math.floor((genesis.systemStartPosixMs + (slot - genesis.startSlotNo) * genesis.slotLengthMs) / 1000);
24
+ }
25
+ //# sourceMappingURL=epoch-slots.js.map
@@ -1,94 +1,41 @@
1
- /**
2
- * Error codes used throughout the ODATANO backend
3
- */
1
+ /** Error codes used throughout the backend. */
4
2
  export declare const ERROR_CODES: {
5
- /**
6
- * 400 – Invalid input
7
- * Indicates that the input provided by the client is invalid (malformed address, invalid transaction hash, etc.)
8
- */
3
+ /** 400: malformed client input (address, tx hash, ...). */
9
4
  readonly INVALID_INPUT: "ODATANO_INVALID_INPUT";
10
- /**
11
- * 403 – Caller lacks the required role
12
- * Indicates the caller is authenticated but not authorized for the operation
13
- * (e.g. HSM-backed signing without the configured hsm.requiresRole)
14
- */
5
+ /** 403: authenticated but lacking the required role (e.g. hsm.requiresRole). */
15
6
  readonly FORBIDDEN: "ODATANO_FORBIDDEN";
16
- /**
17
- * 404 – Data not found
18
- * Indicates that the requested resource could not be found (Empty result set Address with no UTxOs, Transaction hash not found, etc.)
19
- */
7
+ /** 404: requested resource not found (unknown tx hash, address without UTxOs, ...). */
20
8
  readonly NOT_FOUND: "ODATANO_NOT_FOUND";
21
- /**
22
- * 400 – Insufficient funds/assets
23
- * Indicates that the address does not have enough funds or assets to complete the transaction
24
- */
9
+ /** 400: address lacks the funds or assets for the transaction. */
25
10
  readonly INSUFFICIENT_FUNDS: "ODATANO_INSUFFICIENT_FUNDS";
26
- /**
27
- * 400 – Transaction validation failed
28
- * Indicates that the transaction failed validation (wrong signature, tampered CBOR, etc.)
29
- */
11
+ /** 400: decoded transaction failed validation (wrong signature, tampered CBOR, ...). */
30
12
  readonly TX_VALIDATION_FAILED: "ODATANO_TX_VALIDATION_FAILED";
31
- /**
32
- * 400 – Transaction CBOR parse failed
33
- * Indicates that the provided transaction CBOR could not be decoded
34
- * (malformed bytes, truncated, not a Cardano Conway tx). Distinct from
35
- * TX_VALIDATION_FAILED which applies to decoded-but-invalid transactions.
36
- */
13
+ /** 400: transaction CBOR could not be decoded (malformed, truncated, not a Conway tx). */
37
14
  readonly TX_PARSE_FAILED: "ODATANO_TX_PARSE_FAILED";
38
- /**
39
- * 400 – Plutus script validation failed
40
- * Indicates that the ledger cleanly rejected the transaction due to script
41
- * evaluation — e.g. PlutusFailure, CekError, overspent budget, script hash
42
- * mismatch. Distinct from provider outages (503) and generic tx validation.
43
- */
15
+ /** 400: ledger rejected the tx on script evaluation (PlutusFailure, CekError, budget, hash mismatch). */
44
16
  readonly SCRIPT_VALIDATION_FAILURE: "ODATANO_SCRIPT_VALIDATION_FAILURE";
45
- /**
46
- * 409 – Transaction already submitted
47
- * Indicates that the transaction has already been submitted (duplicate/replay)
48
- */
17
+ /** 409: a crawler cursor block is not on this instance's chain (orphaned by a reorg). */
18
+ readonly CHAIN_POINT_MISMATCH: "ODATANO_CHAIN_POINT_MISMATCH";
19
+ /** 409: transaction already submitted (duplicate / replay). */
49
20
  readonly TX_ALREADY_SUBMITTED: "ODATANO_TX_ALREADY_SUBMITTED";
50
- /**
51
- * 429 – Rate limiting
52
- * indicates temporary unavailability
53
- */
21
+ /** 429: provider rate limit hit. */
54
22
  readonly PROVIDER_RATE_LIMITED: "ODATANO_PROVIDER_RATE_LIMITED";
55
- /**
56
- * 503 – Upstream / connectivity
57
- * Indicates that the Cardano data provider is currently unavailable
58
- */
23
+ /** 503: Cardano data provider unavailable. */
59
24
  readonly PROVIDER_UNAVAILABLE: "ODATANO_PROVIDER_UNAVAILABLE";
60
- /**
61
- * 500 – Internal fallback
62
- * Indicates an unexpected internal error
63
- */
25
+ /** 500: unexpected internal error. */
64
26
  readonly INTERNAL_ERROR: "ODATANO_INTERNAL_ERROR";
65
- /**
66
- * 503 – HSM unavailable
67
- * Indicates the HSM device or session is not available
68
- */
27
+ /** 503: HSM device or session not available. */
69
28
  readonly HSM_UNAVAILABLE: "ODATANO_HSM_UNAVAILABLE";
70
- /**
71
- * 500 – HSM signing failed
72
- * Indicates the HSM signing operation failed
73
- */
29
+ /** 500: HSM signing operation failed. */
74
30
  readonly HSM_SIGNING_FAILED: "ODATANO_HSM_SIGNING_FAILED";
75
- /**
76
- * 400 – HSM not configured
77
- * Indicates HSM signing was requested but HSM is not configured
78
- */
31
+ /** 400: HSM signing requested but HSM not configured. */
79
32
  readonly HSM_NOT_CONFIGURED: "ODATANO_HSM_NOT_CONFIGURED";
80
33
  /**
81
- * 503 – Detached transaction could not begin in time
82
- * The sign-service could not acquire a pooled DB connection for one of its
83
- * detached bookkeeping transactions. Most common cause: an in-process
84
- * consumer awaits SubmitVerifiedTransaction/SignAndSubmitWithHsm while its
85
- * own request transaction holds the (single) pooled sqlite connection —
86
- * see docs/KNOWN_ISSUES.md issue 11.
34
+ * 503: a detached bookkeeping transaction could not acquire a pooled DB connection in time,
35
+ * typically because an in-process caller awaits the action while its own request tx holds the single sqlite connection.
87
36
  */
88
37
  readonly NESTED_TX_TIMEOUT: "ODATANO_NESTED_TX_TIMEOUT";
89
38
  };
90
- /**
91
- * EnumType representing all possible error codes
92
- */
39
+ /** Union of all error code values. */
93
40
  export type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
94
41
  //# sourceMappingURL=error-codes.d.ts.map
@@ -1,92 +1,41 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ERROR_CODES = void 0;
4
- /**
5
- * Error codes used throughout the ODATANO backend
6
- */
4
+ /** Error codes used throughout the backend. */
7
5
  exports.ERROR_CODES = {
8
- /**
9
- * 400 – Invalid input
10
- * Indicates that the input provided by the client is invalid (malformed address, invalid transaction hash, etc.)
11
- */
6
+ /** 400: malformed client input (address, tx hash, ...). */
12
7
  INVALID_INPUT: 'ODATANO_INVALID_INPUT',
13
- /**
14
- * 403 – Caller lacks the required role
15
- * Indicates the caller is authenticated but not authorized for the operation
16
- * (e.g. HSM-backed signing without the configured hsm.requiresRole)
17
- */
8
+ /** 403: authenticated but lacking the required role (e.g. hsm.requiresRole). */
18
9
  FORBIDDEN: 'ODATANO_FORBIDDEN',
19
- /**
20
- * 404 – Data not found
21
- * Indicates that the requested resource could not be found (Empty result set Address with no UTxOs, Transaction hash not found, etc.)
22
- */
10
+ /** 404: requested resource not found (unknown tx hash, address without UTxOs, ...). */
23
11
  NOT_FOUND: 'ODATANO_NOT_FOUND',
24
- /**
25
- * 400 – Insufficient funds/assets
26
- * Indicates that the address does not have enough funds or assets to complete the transaction
27
- */
12
+ /** 400: address lacks the funds or assets for the transaction. */
28
13
  INSUFFICIENT_FUNDS: 'ODATANO_INSUFFICIENT_FUNDS',
29
- /**
30
- * 400 – Transaction validation failed
31
- * Indicates that the transaction failed validation (wrong signature, tampered CBOR, etc.)
32
- */
14
+ /** 400: decoded transaction failed validation (wrong signature, tampered CBOR, ...). */
33
15
  TX_VALIDATION_FAILED: 'ODATANO_TX_VALIDATION_FAILED',
34
- /**
35
- * 400 – Transaction CBOR parse failed
36
- * Indicates that the provided transaction CBOR could not be decoded
37
- * (malformed bytes, truncated, not a Cardano Conway tx). Distinct from
38
- * TX_VALIDATION_FAILED which applies to decoded-but-invalid transactions.
39
- */
16
+ /** 400: transaction CBOR could not be decoded (malformed, truncated, not a Conway tx). */
40
17
  TX_PARSE_FAILED: 'ODATANO_TX_PARSE_FAILED',
41
- /**
42
- * 400 – Plutus script validation failed
43
- * Indicates that the ledger cleanly rejected the transaction due to script
44
- * evaluation — e.g. PlutusFailure, CekError, overspent budget, script hash
45
- * mismatch. Distinct from provider outages (503) and generic tx validation.
46
- */
18
+ /** 400: ledger rejected the tx on script evaluation (PlutusFailure, CekError, budget, hash mismatch). */
47
19
  SCRIPT_VALIDATION_FAILURE: 'ODATANO_SCRIPT_VALIDATION_FAILURE',
48
- /**
49
- * 409 – Transaction already submitted
50
- * Indicates that the transaction has already been submitted (duplicate/replay)
51
- */
20
+ /** 409: a crawler cursor block is not on this instance's chain (orphaned by a reorg). */
21
+ CHAIN_POINT_MISMATCH: 'ODATANO_CHAIN_POINT_MISMATCH',
22
+ /** 409: transaction already submitted (duplicate / replay). */
52
23
  TX_ALREADY_SUBMITTED: 'ODATANO_TX_ALREADY_SUBMITTED',
53
- /**
54
- * 429 – Rate limiting
55
- * indicates temporary unavailability
56
- */
24
+ /** 429: provider rate limit hit. */
57
25
  PROVIDER_RATE_LIMITED: 'ODATANO_PROVIDER_RATE_LIMITED',
58
- /**
59
- * 503 – Upstream / connectivity
60
- * Indicates that the Cardano data provider is currently unavailable
61
- */
26
+ /** 503: Cardano data provider unavailable. */
62
27
  PROVIDER_UNAVAILABLE: 'ODATANO_PROVIDER_UNAVAILABLE',
63
- /**
64
- * 500 – Internal fallback
65
- * Indicates an unexpected internal error
66
- */
28
+ /** 500: unexpected internal error. */
67
29
  INTERNAL_ERROR: 'ODATANO_INTERNAL_ERROR',
68
- /**
69
- * 503 – HSM unavailable
70
- * Indicates the HSM device or session is not available
71
- */
30
+ /** 503: HSM device or session not available. */
72
31
  HSM_UNAVAILABLE: 'ODATANO_HSM_UNAVAILABLE',
73
- /**
74
- * 500 – HSM signing failed
75
- * Indicates the HSM signing operation failed
76
- */
32
+ /** 500: HSM signing operation failed. */
77
33
  HSM_SIGNING_FAILED: 'ODATANO_HSM_SIGNING_FAILED',
78
- /**
79
- * 400 – HSM not configured
80
- * Indicates HSM signing was requested but HSM is not configured
81
- */
34
+ /** 400: HSM signing requested but HSM not configured. */
82
35
  HSM_NOT_CONFIGURED: 'ODATANO_HSM_NOT_CONFIGURED',
83
36
  /**
84
- * 503 – Detached transaction could not begin in time
85
- * The sign-service could not acquire a pooled DB connection for one of its
86
- * detached bookkeeping transactions. Most common cause: an in-process
87
- * consumer awaits SubmitVerifiedTransaction/SignAndSubmitWithHsm while its
88
- * own request transaction holds the (single) pooled sqlite connection —
89
- * see docs/KNOWN_ISSUES.md issue 11.
37
+ * 503: a detached bookkeeping transaction could not acquire a pooled DB connection in time,
38
+ * typically because an in-process caller awaits the action while its own request tx holds the single sqlite connection.
90
39
  */
91
40
  NESTED_TX_TIMEOUT: 'ODATANO_NESTED_TX_TIMEOUT',
92
41
  };