@odatano/core 2.0.0-rc.4 → 2.0.0-rc.40

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 (166) 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 +305 -7
  8. package/@cds-models/CardanoODataService/index.js +34 -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 +46 -13
  12. package/@cds-models/CardanoTransactionService/index.js +4 -0
  13. package/@cds-models/index.d.ts +72 -0
  14. package/@cds-models/index.js +12 -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 +2297 -1633
  19. package/db/types.cds +114 -0
  20. package/package.json +27 -6
  21. package/scripts/migrate-slot-leader.mjs +104 -0
  22. package/scripts/migrate-txseq.mjs +147 -0
  23. package/src/index.d.ts +18 -11
  24. package/src/index.js +44 -14
  25. package/src/plugin.js +42 -52
  26. package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
  27. package/srv/blockchain/backends/blockfrost-backend.js +53 -162
  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 +376 -235
  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 +556 -201
  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 +87 -202
  39. package/srv/blockchain/cardano-client.js +210 -240
  40. package/srv/blockchain/cardano-indexer.d.ts +311 -242
  41. package/srv/blockchain/cardano-indexer.js +1238 -362
  42. package/srv/blockchain/cardano-tx-builder.d.ts +44 -81
  43. package/srv/blockchain/cardano-tx-builder.js +173 -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 +14 -45
  68. package/srv/blockchain/signing/signature-verifier.js +73 -76
  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 +111 -173
  74. package/srv/blockchain/transaction-building/buildooor-tx.js +649 -326
  75. package/srv/blockchain/transaction-building/caller-datums.d.ts +29 -0
  76. package/srv/blockchain/transaction-building/caller-datums.js +139 -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 +18 -23
  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 +65 -2
  102. package/srv/cardano-service.js +170 -129
  103. package/srv/cardano-sign-service.cds +200 -180
  104. package/srv/cardano-sign-service.js +57 -184
  105. package/srv/cardano-tx-service.cds +439 -370
  106. package/srv/cardano-tx-service.js +231 -190
  107. package/srv/cardano-ui.cds +16 -16
  108. package/srv/cardano-worker-service.js +7 -15
  109. package/srv/cbor/index.d.ts +1 -1
  110. package/srv/cbor/parse.d.ts +27 -0
  111. package/srv/cbor/parse.js +63 -2
  112. package/srv/server.d.ts +28 -86
  113. package/srv/server.js +132 -135
  114. package/srv/utils/agent-grants-config.d.ts +37 -0
  115. package/srv/utils/agent-grants-config.js +138 -0
  116. package/srv/utils/agent-grants.d.ts +262 -0
  117. package/srv/utils/agent-grants.js +922 -0
  118. package/srv/utils/agent-token-auth.d.ts +16 -0
  119. package/srv/utils/agent-token-auth.js +78 -0
  120. package/srv/utils/backend-request-handler.d.ts +2 -16
  121. package/srv/utils/backend-request-handler.js +3 -18
  122. package/srv/utils/collections.d.ts +4 -8
  123. package/srv/utils/collections.js +4 -8
  124. package/srv/utils/const.d.ts +30 -67
  125. package/srv/utils/const.js +32 -72
  126. package/srv/utils/crypto.d.ts +3 -12
  127. package/srv/utils/crypto.js +5 -18
  128. package/srv/utils/db-indexes.d.ts +25 -0
  129. package/srv/utils/db-indexes.js +94 -0
  130. package/srv/utils/db-sanitize.d.ts +27 -0
  131. package/srv/utils/db-sanitize.js +85 -0
  132. package/srv/utils/epoch-slots.d.ts +20 -0
  133. package/srv/utils/epoch-slots.js +43 -0
  134. package/srv/utils/error-codes.d.ts +20 -73
  135. package/srv/utils/error-codes.js +19 -70
  136. package/srv/utils/errors.d.ts +50 -177
  137. package/srv/utils/errors.js +94 -218
  138. package/srv/utils/legacy-service-paths.d.ts +11 -0
  139. package/srv/utils/legacy-service-paths.js +58 -0
  140. package/srv/utils/liveness.d.ts +16 -0
  141. package/srv/utils/liveness.js +40 -0
  142. package/srv/utils/mappers.d.ts +128 -214
  143. package/srv/utils/mappers.js +354 -299
  144. package/srv/utils/network-context.js +2 -11
  145. package/srv/utils/pg-inline-json.d.ts +8 -0
  146. package/srv/utils/pg-inline-json.js +62 -0
  147. package/srv/utils/pg-order-nulls.d.ts +14 -0
  148. package/srv/utils/pg-order-nulls.js +56 -0
  149. package/srv/utils/plutus-placeholders.d.ts +23 -16
  150. package/srv/utils/plutus-placeholders.js +63 -27
  151. package/srv/utils/rate-limiter.d.ts +46 -0
  152. package/srv/utils/rate-limiter.js +116 -0
  153. package/srv/utils/service-events.d.ts +2 -22
  154. package/srv/utils/service-events.js +3 -23
  155. package/srv/utils/signing-helper.d.ts +6 -16
  156. package/srv/utils/signing-helper.js +36 -60
  157. package/srv/utils/tx-build-helper.d.ts +28 -93
  158. package/srv/utils/tx-build-helper.js +75 -124
  159. package/srv/utils/tx-request-parsers.d.ts +101 -28
  160. package/srv/utils/tx-request-parsers.js +410 -43
  161. package/srv/utils/tx-utils.d.ts +4 -23
  162. package/srv/utils/tx-utils.js +12 -41
  163. package/srv/utils/types.d.ts +252 -179
  164. package/srv/utils/types.js +2 -6
  165. package/srv/utils/validators.d.ts +24 -90
  166. package/srv/utils/validators.js +50 -147
@@ -891,13 +891,13 @@ annotate srv.Addresses with @(
891
891
  $Type : 'UI.ReferenceFacet',
892
892
  Label : 'Assets',
893
893
  Target : 'assets/@UI.LineItem',
894
- ![@UI.Hidden]: (not hasAssets)
894
+ @UI.Hidden: (not hasAssets)
895
895
  },
896
896
  {
897
897
  $Type : 'UI.ReferenceFacet',
898
898
  Label : 'UTxOs',
899
899
  Target : 'utxos/@UI.LineItem',
900
- ![@UI.Hidden]: (not hasUTxOs)
900
+ @UI.Hidden: (not hasUTxOs)
901
901
  }
902
902
  ],
903
903
 
@@ -1075,7 +1075,7 @@ annotate srv.AddressUTxOs with @(
1075
1075
  $Type : 'UI.ReferenceFacet',
1076
1076
  Label : 'Assets',
1077
1077
  Target : 'assets/@UI.LineItem',
1078
- ![@UI.Hidden]: (not hasAssets)
1078
+ @UI.Hidden: (not hasAssets)
1079
1079
  },
1080
1080
  {
1081
1081
  $Type : 'UI.ReferenceFacet',
@@ -1305,19 +1305,19 @@ annotate srv.Transactions with @(
1305
1305
  $Type : 'UI.ReferenceFacet',
1306
1306
  Label : 'Metadata',
1307
1307
  Target : 'metadata/@UI.LineItem',
1308
- ![@UI.Hidden]: (not hasMetadata)
1308
+ @UI.Hidden: (not hasMetadata)
1309
1309
  },
1310
1310
  {
1311
1311
  $Type : 'UI.ReferenceFacet',
1312
1312
  Label : 'Inputs',
1313
1313
  Target : 'inputs/@UI.LineItem',
1314
- ![@UI.Hidden]: (not hasInputs)
1314
+ @UI.Hidden: (not hasInputs)
1315
1315
  },
1316
1316
  {
1317
1317
  $Type : 'UI.ReferenceFacet',
1318
1318
  Label : 'Outputs',
1319
1319
  Target : 'outputs/@UI.LineItem',
1320
- ![@UI.Hidden]: (not hasOutputs)
1320
+ @UI.Hidden: (not hasOutputs)
1321
1321
  }
1322
1322
  ],
1323
1323
 
@@ -1451,7 +1451,7 @@ annotate srv.TransactionInputs with @(
1451
1451
  $Type : 'UI.ReferenceFacet',
1452
1452
  Label : 'Assets',
1453
1453
  Target : 'assets/@UI.LineItem',
1454
- ![@UI.Hidden]: (not hasAssets)
1454
+ @UI.Hidden: (not hasAssets)
1455
1455
  },
1456
1456
  {
1457
1457
  $Type : 'UI.ReferenceFacet',
@@ -1625,7 +1625,7 @@ annotate srv.TransactionOutputs with @(
1625
1625
  $Type : 'UI.ReferenceFacet',
1626
1626
  Label : 'Assets',
1627
1627
  Target : 'assets/@UI.LineItem',
1628
- ![@UI.Hidden]: (not hasAssets)
1628
+ @UI.Hidden: (not hasAssets)
1629
1629
  },
1630
1630
  {
1631
1631
  $Type : 'UI.ReferenceFacet',
@@ -1860,7 +1860,7 @@ annotate srv.Accounts with @(
1860
1860
  $Type : 'UI.ReferenceFacet',
1861
1861
  Label : 'Addresses',
1862
1862
  Target : 'Address/@UI.LineItem',
1863
- ![@UI.Hidden]: (not hasAddresses)
1863
+ @UI.Hidden: (not hasAddresses)
1864
1864
  }
1865
1865
  ],
1866
1866
 
@@ -2301,19 +2301,19 @@ annotate txsrv.TransactionBuilds with @(
2301
2301
  $Type : 'UI.ReferenceFacet',
2302
2302
  Label : 'Inputs',
2303
2303
  Target : 'inputs/@UI.LineItem',
2304
- ![@UI.Hidden]: (not hasInputs)
2304
+ @UI.Hidden: (not hasInputs)
2305
2305
  },
2306
2306
  {
2307
2307
  $Type : 'UI.ReferenceFacet',
2308
2308
  Label : 'Outputs',
2309
2309
  Target : 'outputs/@UI.LineItem',
2310
- ![@UI.Hidden]: (not hasOutputs)
2310
+ @UI.Hidden: (not hasOutputs)
2311
2311
  },
2312
2312
  {
2313
2313
  $Type : 'UI.ReferenceFacet',
2314
2314
  Label : 'Submission',
2315
2315
  Target : 'submission/@UI.FieldGroup#SubmissionDetails',
2316
- ![@UI.Hidden]: (not wasSubmitted)
2316
+ @UI.Hidden: (not wasSubmitted)
2317
2317
  }
2318
2318
  ],
2319
2319
 
@@ -2439,7 +2439,7 @@ annotate txsrv.TransactionBuildInputs with @(
2439
2439
  $Type : 'UI.ReferenceFacet',
2440
2440
  Label : 'Assets',
2441
2441
  Target : 'assets/@UI.LineItem',
2442
- ![@UI.Hidden]: (not hasAssets)
2442
+ @UI.Hidden: (not hasAssets)
2443
2443
  },
2444
2444
  {
2445
2445
  $Type : 'UI.ReferenceFacet',
@@ -2611,7 +2611,7 @@ annotate txsrv.TransactionBuildOutputs with @(
2611
2611
  $Type : 'UI.ReferenceFacet',
2612
2612
  Label : 'Assets',
2613
2613
  Target : 'assets/@UI.LineItem',
2614
- ![@UI.Hidden]: (not hasAssets)
2614
+ @UI.Hidden: (not hasAssets)
2615
2615
  },
2616
2616
  {
2617
2617
  $Type : 'UI.ReferenceFacet',
@@ -2796,13 +2796,13 @@ annotate txsrv.TransactionSubmissions with @(
2796
2796
  $Type : 'UI.ReferenceFacet',
2797
2797
  Label : 'Error Details',
2798
2798
  Target : '@UI.FieldGroup#ErrorDetails',
2799
- ![@UI.Hidden]: (not hasErrors)
2799
+ @UI.Hidden: (not hasErrors)
2800
2800
  },
2801
2801
  {
2802
2802
  $Type : 'UI.ReferenceFacet',
2803
2803
  Label : 'Errors',
2804
2804
  Target : 'errors/@UI.LineItem',
2805
- ![@UI.Hidden]: (not hasErrors)
2805
+ @UI.Hidden: (not hasErrors)
2806
2806
  }
2807
2807
  ],
2808
2808
 
@@ -13,22 +13,16 @@ const job_store_1 = require("./blockchain/wallet-worker/job-store");
13
13
  const server_1 = require("./server");
14
14
  const logger = cds_1.default.log('CardanoWorkerService');
15
15
  /**
16
- * CardanoWorkerService handlers — thin control surface over the wallet-worker
17
- * singleton (srv/blockchain/wallet-worker). Engine logic lives there; this only
18
- * validates inputs, inserts/reads job rows and starts/stops the worker.
19
- *
20
- * Validation rejections happen BEFORE handleRequest (project convention); the
21
- * job INSERT runs on the request's ambient transaction (NIGHTGATE lesson 1).
16
+ * CardanoWorkerService handlers: control surface over the wallet-worker singleton
17
+ * (srv/blockchain/wallet-worker). Validates inputs, inserts/reads job rows, starts/stops
18
+ * the worker. The job INSERT runs on the request's ambient transaction.
22
19
  */
23
20
  function isAdmin(req) {
24
21
  return req.user?.is?.('Admin') ?? false;
25
22
  }
26
23
  /**
27
- * A job on an HSM-backed wallet spends the same server-held key as the synchronous
28
- * SignWithHsm path, so it inherits that path's role gate (enforceHsmRole in
29
- * cardano-sign-service.ts) — 'authenticated-user' alone must not reach the HSM.
30
- * Returns the role the caller is missing, or null when the wallet is not HSM-backed,
31
- * no role is configured, or the caller holds it.
24
+ * HSM-backed wallets inherit the SignWithHsm role gate (enforceHsmRole in the sign service).
25
+ * Returns the role the caller is missing, or null when not HSM-backed, no role configured, or held.
32
26
  */
33
27
  function missingHsmRole(req, signerType) {
34
28
  if (signerType !== 'hsm')
@@ -125,10 +119,8 @@ module.exports = (srv) => {
125
119
  return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
126
120
  const job = await (0, job_store_1.getJobById)(db, jobId);
127
121
  if (!job || (!isAdmin(req) && job.createdBy !== req.user?.id)) {
128
- // Same 404 for "not found" and "not yours" — no existence oracle.
129
- // THROW, don't req.reject: we are inside handleRequest, whose catch would
130
- // see a plain CAP error and remap it to 500 (mapError). A BackendError
131
- // carries its status through.
122
+ // Same 404 for "not found" and "not yours" (no existence oracle). Throw, don't
123
+ // req.reject: inside handleRequest a plain CAP error is remapped to 500.
132
124
  throw new errors_1.NotFoundError(`Job ${jobId}`);
133
125
  }
134
126
  const cancelled = await (0, job_store_1.markCancelled)(db, jobId);
@@ -1,2 +1,2 @@
1
- export { parseTransaction, type ParsedTransaction, type ParsedInput, type ParsedOutput, type ParsedAsset, type ParsedWitnesses, } from './parse';
1
+ export { parseTransaction, type ParsedTransaction, type ParsedInput, type ParsedOutput, type ParsedAsset, type ParsedWitnesses, type ParsedWithdrawal, type ParsedCertificate, } from './parse';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -15,6 +15,19 @@ export interface ParsedOutput {
15
15
  datumHash: string | null;
16
16
  inlineDatumHex: string | null;
17
17
  referenceScriptHex: string | null;
18
+ /** Byte length of the output as it stands in the transaction. */
19
+ cborSize: number;
20
+ }
21
+ export interface ParsedWithdrawal {
22
+ /** Bech32 reward address. */
23
+ rewardAddress: string;
24
+ lovelace: string;
25
+ }
26
+ export interface ParsedCertificate {
27
+ /** Position in the body's certificate list. */
28
+ index: number;
29
+ /** Ledger certificate name, e.g. `StakeDelegation` or `RegistrationDrep`. */
30
+ type: string;
18
31
  }
19
32
  export interface ParsedWitnesses {
20
33
  vkeyCount: number;
@@ -35,6 +48,8 @@ export interface ParsedTransaction {
35
48
  * consumer needing that split must compare against the service network.
36
49
  */
37
50
  network: 'mainnet' | 'testnet' | null;
51
+ /** Body field 15: 1 = mainnet, 0 = testnet, null if absent. */
52
+ networkId: number | null;
38
53
  inputs: ParsedInput[];
39
54
  outputs: ParsedOutput[];
40
55
  /** Validity-interval start slot (decimal string) or `null` if absent. */
@@ -48,9 +63,21 @@ export interface ParsedTransaction {
48
63
  /** Metadata labels present (uint64 → decimal string); full payload via GetMetadataByTxHash for submitted txs. */
49
64
  metadataLabels: string[];
50
65
  collateral: ParsedInput[];
66
+ referenceInputs: ParsedInput[];
67
+ withdrawals: ParsedWithdrawal[];
68
+ certificates: ParsedCertificate[];
69
+ /** Number of votes over all voters; 0 if the body has no voting procedures. */
70
+ votingProcedures: number;
71
+ proposalProcedures: number;
72
+ /** Lovelace (decimal string) or `null` if absent. */
73
+ treasuryDonation: string | null;
74
+ /** Lovelace (decimal string) or `null` if absent. */
75
+ currentTreasuryValue: string | null;
51
76
  /** 28-byte Ed25519 key hashes listed in the tx body's required_signers field. */
52
77
  requiredSigners: string[];
53
78
  scriptDataHash: string | null;
79
+ /** `false` when the transaction is flagged as failing its scripts. On chain it then spends only the collateral and creates no outputs. */
80
+ isValid: boolean;
54
81
  witnesses: ParsedWitnesses;
55
82
  }
56
83
  /**
package/srv/cbor/parse.js CHANGED
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseTransaction = parseTransaction;
4
4
  const buildooor_1 = require("@harmoniclabs/buildooor");
5
+ const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
6
+ const cbor_1 = require("@harmoniclabs/cbor");
5
7
  const errors_1 = require("../utils/errors");
6
8
  const error_codes_1 = require("../utils/error-codes");
7
9
  /**
@@ -13,8 +15,12 @@ const error_codes_1 = require("../utils/error-codes");
13
15
  */
14
16
  function parseTransaction(cborHex) {
15
17
  let tx;
18
+ let raw;
16
19
  try {
17
- tx = buildooor_1.Tx.fromCbor(Buffer.from(cborHex, 'hex'));
20
+ // one decode for both readers; keepRef keeps the original bytes for the body hash and datums
21
+ const parsed = cbor_1.Cbor.parse(Buffer.from(cborHex, 'hex'), { keepRef: true });
22
+ tx = buildooor_1.Tx.fromCborObj(parsed);
23
+ raw = readBodyFields(parsed);
18
24
  }
19
25
  catch (e) {
20
26
  const msg = e instanceof Error ? e.message : String(e);
@@ -24,6 +30,7 @@ function parseTransaction(cborHex) {
24
30
  return {
25
31
  txHash: body.hash.toString(),
26
32
  network: normalizeNetwork(body.network),
33
+ networkId: raw.networkId,
27
34
  inputs: body.inputs.map(mapInput),
28
35
  outputs: body.outputs.map(mapOutput),
29
36
  validityStart: body.validityIntervalStart != null ? body.validityIntervalStart.toString() : null,
@@ -32,8 +39,19 @@ function parseTransaction(cborHex) {
32
39
  mint: mapMint(body.mint),
33
40
  metadataLabels: extractMetadataLabels(tx.auxiliaryData),
34
41
  collateral: (body.collateralInputs ?? []).map(mapInput),
42
+ referenceInputs: (body.refInputs ?? []).map(mapInput),
43
+ withdrawals: (body.withdrawals?.map ?? []).map((w) => ({
44
+ rewardAddress: w.rewardAccount.toString(),
45
+ lovelace: w.amount.toString(),
46
+ })),
47
+ certificates: (body.certs ?? []).map(mapCertificate),
48
+ votingProcedures: raw.votingProcedures,
49
+ proposalProcedures: raw.proposalProcedures,
50
+ treasuryDonation: raw.treasuryDonation,
51
+ currentTreasuryValue: raw.currentTreasuryValue,
35
52
  requiredSigners: (body.requiredSigners ?? []).map((s) => s.toString()),
36
53
  scriptDataHash: body.scriptDataHash ? body.scriptDataHash.toString() : null,
54
+ isValid: tx.isScriptValid,
37
55
  witnesses: countWitnesses(tx.witnesses),
38
56
  };
39
57
  }
@@ -66,7 +84,7 @@ function mapOutput(out) {
66
84
  }
67
85
  else {
68
86
  // anything not a Hash32 is an inline `Data` (PlutusData) payload
69
- inlineDatumHex = Buffer.from((0, buildooor_1.dataToCbor)(out.datum)).toString('hex');
87
+ inlineDatumHex = Buffer.from(inlineDatumBytes(out) ?? (0, buildooor_1.dataToCbor)(out.datum)).toString('hex');
70
88
  }
71
89
  }
72
90
  const referenceScriptHex = out.refScript
@@ -79,8 +97,51 @@ function mapOutput(out) {
79
97
  datumHash,
80
98
  inlineDatumHex,
81
99
  referenceScriptHex,
100
+ // the bytes as received; a re-encoding can be shorter
101
+ cborSize: out.cborRef ? out.cborRef.toBuffer().length : out.toCborBytes().length,
82
102
  };
83
103
  }
104
+ function mapCertificate(cert, index) {
105
+ return { index, type: (0, cardano_ledger_ts_1.certTypeToString)(cert.certType) };
106
+ }
107
+ /** Body fields 15 and 19 to 22 as they stand in the bytes. `Tx.fromCbor` drops 19 to 22 and maps any network byte other than 0 to mainnet. */
108
+ function readBodyFields(parsed) {
109
+ const body = parsed instanceof cbor_1.CborArray ? parsed.array[0] : undefined;
110
+ const field = (key) => body instanceof cbor_1.CborMap ? body.map.find(e => e.k instanceof cbor_1.CborUInt && e.k.num === BigInt(key))?.v : undefined;
111
+ const uint = (key) => {
112
+ const v = field(key);
113
+ return v instanceof cbor_1.CborUInt ? v.num : null;
114
+ };
115
+ // voting_procedures = { voter => { gov_action_id => voting_procedure } }
116
+ const voting = field(19);
117
+ const votes = voting instanceof cbor_1.CborMap
118
+ ? voting.map.reduce((n, e) => n + (e.v instanceof cbor_1.CborMap ? e.v.map.length : 0), 0)
119
+ : 0;
120
+ const networkId = uint(15);
121
+ return {
122
+ networkId: networkId == null ? null : Number(networkId),
123
+ votingProcedures: votes,
124
+ proposalProcedures: setItems(field(20)).length,
125
+ treasuryDonation: uint(22)?.toString() ?? null,
126
+ currentTreasuryValue: uint(21)?.toString() ?? null,
127
+ };
128
+ }
129
+ /** Items of a CBOR set, with or without the Conway set tag 258. */
130
+ function setItems(obj) {
131
+ const inner = obj instanceof cbor_1.CborTag ? obj.data : obj;
132
+ return inner instanceof cbor_1.CborArray ? inner.array : [];
133
+ }
134
+ /** Inline datum bytes as they stand in the transaction; decoding and re-encoding may change them. */
135
+ function inlineDatumBytes(out) {
136
+ if (!out.cborRef)
137
+ return undefined;
138
+ const parsed = cbor_1.Cbor.parse(out.toCborBytes());
139
+ if (!(parsed instanceof cbor_1.CborMap))
140
+ return undefined;
141
+ const option = parsed.map.find(e => e.k instanceof cbor_1.CborUInt && e.k.num === 2n)?.v;
142
+ const tagged = option instanceof cbor_1.CborArray ? option.array[1] : undefined;
143
+ return tagged instanceof cbor_1.CborTag && tagged.data instanceof cbor_1.CborBytes ? tagged.data.bytes : undefined;
144
+ }
84
145
  function mapMint(mint) {
85
146
  if (!mint)
86
147
  return [];
package/srv/server.d.ts CHANGED
@@ -4,126 +4,68 @@ import { CardanoTransactionBuilder } from './blockchain/cardano-tx-builder';
4
4
  import type { LedgerProtocolParameters, HsmConfig } from './utils/types';
5
5
  import type { CrawlerConfig } from './blockchain/crawler/crawler';
6
6
  import type { WalletWorkerConfig } from './blockchain/wallet-worker';
7
- /**
8
- * Application context holding initialized blockchain components
9
- * These are created once during CAP bootstrap and shared across services
10
- */
7
+ /** Blockchain components created once at bootstrap and shared across services. */
11
8
  interface AppContext {
12
9
  cardanoClient: CardanoClient;
13
10
  cardanoIndexer: CardanoIndexer;
14
11
  cardanoTxBuilder: CardanoTransactionBuilder;
15
12
  }
13
+ /** Agent-grant feature switch; its own module so src/plugin.ts can read it at load. */
14
+ export { loadAgentGrantsConfig, activateAgentGrants } from './utils/agent-grants-config';
16
15
  /**
17
- * Get the application context (must be called after bootstrap)
18
- * @throws {ProviderUnavailableError} 503 when uninitialized — request handlers using
19
- * handleRequest/mapError translate this into a clean 503 response instead of a raw 500.
20
- * If bootstrap actively failed, the cause is appended to the message.
16
+ * The application context.
17
+ * @throws {ProviderUnavailableError} 503 when uninitialized; a bootstrap failure is appended as cause.
21
18
  */
22
19
  export declare function getAppContext(): AppContext;
23
- /**
24
- * Get the CardanoIndexer instance
25
- * Convenience function for services
26
- */
27
20
  export declare function getCardanoIndexer(): CardanoIndexer;
28
- /**
29
- * Get the CardanoClient instance
30
- * Convenience function for services
31
- */
32
21
  export declare function getCardanoClient(): CardanoClient;
33
- /**
34
- * Get the CardanoTransactionBuilder instance
35
- * Convenience function for services and plugin consumers
36
- */
37
22
  export declare function getCardanoTxBuilder(): CardanoTransactionBuilder;
38
- /**
39
- * Get the HSM configuration (if HSM is enabled).
40
- * Used by sign service to check requiresRole.
41
- */
23
+ /** HSM configuration when enabled; the sign service reads requiresRole from it. */
42
24
  export declare function getHsmConfig(): HsmConfig | undefined;
43
25
  /**
44
- * Initialize from a pre-built config (used by plugin's src/index.ts)
45
- * @param config - validated CardanoClientConfig
46
- * @param protocolParams - Optional protocol parameters (for tests)
26
+ * Initialize from a pre-built config (plugin path). Idempotent: a second call must not
27
+ * create a duplicate CardanoClient; tests reinitialize via resetAppContext() / createTestContext().
47
28
  */
48
29
  export declare function initializeFromConfig(config: CardanoClientConfig, protocolParams?: LedgerProtocolParameters, hsmConfig?: HsmConfig): Promise<void>;
49
- /**
50
- * Reset the application context (for testing only)
51
- * Allows tests to inject their own instances
52
- */
30
+ /** Reset the application context (tests only); lets tests inject their own instances. */
53
31
  export declare function resetAppContext(context: AppContext | null): void;
54
32
  /**
55
- * Create a test context with specific backends and transaction builder
56
- * Used by integration tests to create isolated test instances
57
- * @param backends Array of backend names to use (e.g., ['koios'], ['blockfrost'])
58
- * @param _txBuilderName Deprecated/ignored — Buildooor is the sole transaction builder (kept for signature compatibility)
59
- * @param protocolParams Optional protocol parameters (to skip backend call during init)
60
- * @returns Promise<AppContext> The created application context
61
- */
62
- export declare function createTestContext(backends: BackendName[], _txBuilderName?: TransactionBuilderName, // kept for signature compat; Buildooor is the only builder
63
- protocolParams?: LedgerProtocolParameters): Promise<AppContext>;
64
- /**
65
- * Shutdown the application context (for cleanup in tests)
66
- * Closes all backend connections to allow process to exit cleanly
33
+ * Create an isolated test context with the given backends.
34
+ * @param _txBuilderName ignored; Buildooor is the sole builder (kept for signature compatibility)
35
+ * @param protocolParams optional, skips the backend call during init
67
36
  */
37
+ export declare function createTestContext(backends: BackendName[], _txBuilderName?: TransactionBuilderName, protocolParams?: LedgerProtocolParameters): Promise<AppContext>;
38
+ /** Stop worker and crawler, then close all backend connections. */
68
39
  export declare function shutdownAppContext(): Promise<void>;
69
40
  /**
70
- * Load and validate CardanoClientConfig from CDS config or environment variables.
71
- *
72
- * When used as a plugin, consumers configure via package.json:
73
- * { "cds": { "requires": { "odatano-core": { "network": "preview", "backends": ["blockfrost"], ... }}}}
74
- *
75
- * Priority: cds.env.requires["odatano-core"].X > process.env.X > default
76
- *
77
- * @returns validated CardanoClientConfig
78
- * @throws {Error} if any config value is invalid
41
+ * Load and validate CardanoClientConfig.
42
+ * Priority: cds.env.requires["odatano-core"].X > process.env.X > default.
43
+ * @throws {ConfigError} if any value is invalid
79
44
  */
80
45
  export declare function loadConfigFromEnv(): CardanoClientConfig;
81
46
  /**
82
- * Load HSM configuration from CDS config or environment variables.
83
- * Returns undefined if HSM is not enabled.
84
- *
85
- * Plugin mode: cds.requires.odatano-core.hsm.enabled = true
86
- * Env mode: HSM_ENABLED=true
87
- *
88
- * @returns HsmConfig or undefined
47
+ * Load the HSM configuration (cds.requires.odatano-core.hsm.* or HSM_* env vars).
48
+ * Returns undefined when HSM is not enabled.
89
49
  */
90
50
  export declare function loadHsmConfigFromEnv(): HsmConfig | undefined;
91
51
  /**
92
- * Load the chain-crawler configuration from CDS config or environment variables.
93
- * Returns { enabled:false } when the crawler is not switched on (the default), so
94
- * existing deployments are unaffected.
95
- *
96
- * Plugin mode: cds.requires.odatano-core.crawler.{enabled,startSlot,startBlockHash,...}
97
- * Env mode: CRAWLER_ENABLED / CRAWLER_START_SLOT / CRAWLER_START_HASH / ...
52
+ * Load the chain-crawler configuration (cds.requires.odatano-core.crawler.* or CRAWLER_* env vars).
53
+ * Returns { enabled: false } when the crawler is off (the default).
98
54
  */
99
55
  export declare function loadCrawlerConfigFromEnv(): CrawlerConfig;
100
- /**
101
- * Start the chain crawler if it is enabled and the app context is ready. Never throws
102
- * (crawler failure must not affect request serving) — errors are logged. Idempotent:
103
- * startCrawler() is a no-op when one is already running.
104
- */
56
+ /** Start the crawler if enabled and the app context is ready. Never throws; idempotent. */
105
57
  export declare function startCrawlerIfConfigured(): Promise<void>;
106
58
  /**
107
- * Load the wallet-worker configuration from CDS config or environment variables.
108
- * Returns { enabled:false } when the worker is not switched on (the default).
109
- *
110
- * Plugin mode: cds.requires.odatano-core.walletWorker.{enabled,wallets,...}
111
- * Env mode: WALLET_WORKER_ENABLED / WALLET_WORKER_WALLETS (JSON) / ...
59
+ * Load the wallet-worker configuration (cds.requires.odatano-core.walletWorker.* or WALLET_WORKER_* env vars).
60
+ * Returns { enabled: false } when the worker is off (the default).
112
61
  */
113
62
  export declare function loadWalletWorkerConfigFromEnv(): WalletWorkerConfig;
114
- /**
115
- * Start the wallet worker if it is enabled and the app context is ready. Never
116
- * throws (worker failure must not affect request serving) — errors are logged.
117
- * Idempotent: startWalletWorker() is a no-op when one is already running.
118
- */
63
+ /** Start the wallet worker if enabled and the app context is ready. Never throws; idempotent. */
119
64
  export declare function startWalletWorkerIfConfigured(): Promise<void>;
120
65
  /**
121
- * Re-drive deferred submissions that were claimed (status 'submitting' with
122
- * persisted signedTxCbor) but whose detached submit never ran because the
123
- * process died first (KNOWN_ISSUES #11, Layer 2). Idempotent — an already
124
- * submitted tx finalizes via the TransactionAlreadySubmittedError path.
125
- * Non-fatal, mirrors startCrawlerIfConfigured/startWalletWorkerIfConfigured.
66
+ * Re-drive deferred submissions claimed as 'submitting' whose detached submit never ran
67
+ * (process died first). Idempotent: an already submitted tx finalizes via
68
+ * TransactionAlreadySubmittedError. Never throws.
126
69
  */
127
70
  export declare function redriveInterruptedSubmissionsIfConfigured(): Promise<void>;
128
- export {};
129
71
  //# sourceMappingURL=server.d.ts.map