@odatano/core 2.0.0-rc.5 → 2.0.0-rc.50

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 (208) hide show
  1. package/@cds-models/CardanoAgentService/index.d.ts +99 -51
  2. package/@cds-models/CardanoAgentService/index.js +15 -0
  3. package/@cds-models/CardanoBackendService/index.d.ts +347 -0
  4. package/@cds-models/CardanoBackendService/index.js +40 -0
  5. package/@cds-models/CardanoIndexerService/index.d.ts +496 -11
  6. package/@cds-models/CardanoIndexerService/index.js +64 -0
  7. package/@cds-models/CardanoODataService/index.d.ts +414 -57
  8. package/@cds-models/CardanoODataService/index.js +42 -0
  9. package/@cds-models/CardanoSignService/index.d.ts +32 -19
  10. package/@cds-models/CardanoSignService/index.js +3 -0
  11. package/@cds-models/CardanoTransactionService/index.d.ts +58 -44
  12. package/@cds-models/CardanoTransactionService/index.js +4 -0
  13. package/@cds-models/CardanoWorkerService/index.d.ts +7 -22
  14. package/@cds-models/index.d.ts +101 -1
  15. package/@cds-models/index.js +16 -1
  16. package/@cds-models/odatano/cardano/index.d.ts +437 -32
  17. package/@cds-models/odatano/cardano/index.js +48 -0
  18. package/README.md +207 -167
  19. package/db/schema.cds +2402 -1705
  20. package/db/types.cds +446 -295
  21. package/package.json +41 -16
  22. package/scripts/migrate-schema.mjs +334 -0
  23. package/scripts/migrate-slot-leader.mjs +96 -0
  24. package/src/index.d.ts +20 -21
  25. package/src/index.js +45 -31
  26. package/src/plugin.js +17 -35
  27. package/srv/blockchain/asset-decimals.d.ts +7 -0
  28. package/srv/blockchain/asset-decimals.js +91 -0
  29. package/srv/blockchain/backends/blockfrost-backend.d.ts +25 -135
  30. package/srv/blockchain/backends/blockfrost-backend.js +66 -172
  31. package/srv/blockchain/backends/cardano-backend.d.ts +94 -186
  32. package/srv/blockchain/backends/cardano-backend.js +29 -5
  33. package/srv/blockchain/backends/koios-backend.d.ts +103 -168
  34. package/srv/blockchain/backends/koios-backend.js +428 -360
  35. package/srv/blockchain/backends/odatano-backend.d.ts +54 -0
  36. package/srv/blockchain/backends/odatano-backend.js +169 -0
  37. package/srv/blockchain/backends/ogmios-backend.d.ts +123 -190
  38. package/srv/blockchain/backends/ogmios-backend.js +637 -315
  39. package/srv/blockchain/backends/ogmios-frame-guard.d.ts +14 -0
  40. package/srv/blockchain/backends/ogmios-frame-guard.js +89 -0
  41. package/srv/blockchain/cardano-client.d.ts +61 -241
  42. package/srv/blockchain/cardano-client.js +253 -293
  43. package/srv/blockchain/cardano-indexer.d.ts +282 -281
  44. package/srv/blockchain/cardano-indexer.js +1551 -484
  45. package/srv/blockchain/cardano-tx-builder.d.ts +25 -89
  46. package/srv/blockchain/cardano-tx-builder.js +164 -140
  47. package/srv/blockchain/circuit-breaker.d.ts +1 -13
  48. package/srv/blockchain/circuit-breaker.js +5 -15
  49. package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
  50. package/srv/blockchain/crawler/account-snapshots.js +153 -0
  51. package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +15 -0
  52. package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
  53. package/srv/blockchain/crawler/asset-registry-backfill.d.ts +43 -0
  54. package/srv/blockchain/crawler/asset-registry-backfill.js +153 -0
  55. package/srv/blockchain/crawler/certificate-backfill.d.ts +52 -0
  56. package/srv/blockchain/crawler/certificate-backfill.js +162 -0
  57. package/srv/blockchain/crawler/crawler.d.ts +104 -81
  58. package/srv/blockchain/crawler/crawler.js +532 -160
  59. package/srv/blockchain/crawler/credential-backfill.d.ts +28 -0
  60. package/srv/blockchain/crawler/credential-backfill.js +124 -0
  61. package/srv/blockchain/crawler/hooks.d.ts +2 -17
  62. package/srv/blockchain/crawler/index.d.ts +1 -8
  63. package/srv/blockchain/crawler/index.js +31 -17
  64. package/srv/blockchain/crawler/input-asset-copies.d.ts +34 -0
  65. package/srv/blockchain/crawler/input-asset-copies.js +171 -0
  66. package/srv/blockchain/crawler/metadata-position-backfill.d.ts +16 -0
  67. package/srv/blockchain/crawler/metadata-position-backfill.js +55 -0
  68. package/srv/blockchain/crawler/output-datum-backfill.d.ts +39 -0
  69. package/srv/blockchain/crawler/output-datum-backfill.js +110 -0
  70. package/srv/blockchain/crawler/sync-state.d.ts +27 -47
  71. package/srv/blockchain/crawler/sync-state.js +113 -63
  72. package/srv/blockchain/crawler/transaction-backfill.d.ts +44 -0
  73. package/srv/blockchain/crawler/transaction-backfill.js +278 -0
  74. package/srv/blockchain/crawler/utxo-set-import.d.ts +66 -0
  75. package/srv/blockchain/crawler/utxo-set-import.js +399 -0
  76. package/srv/blockchain/ledger-state.d.ts +62 -0
  77. package/srv/blockchain/ledger-state.js +419 -0
  78. package/srv/blockchain/pending-spends.d.ts +16 -0
  79. package/srv/blockchain/pending-spends.js +81 -0
  80. package/srv/blockchain/pool-metadata.d.ts +15 -0
  81. package/srv/blockchain/pool-metadata.js +132 -0
  82. package/srv/blockchain/request-coalescer.d.ts +2 -16
  83. package/srv/blockchain/request-coalescer.js +2 -16
  84. package/srv/blockchain/signing/cose-verifier.d.ts +3 -17
  85. package/srv/blockchain/signing/cose-verifier.js +146 -70
  86. package/srv/blockchain/signing/external-signer.d.ts +15 -115
  87. package/srv/blockchain/signing/external-signer.js +17 -126
  88. package/srv/blockchain/signing/hsm-signer.d.ts +10 -54
  89. package/srv/blockchain/signing/hsm-signer.js +28 -79
  90. package/srv/blockchain/signing/signature-verifier.d.ts +9 -47
  91. package/srv/blockchain/signing/signature-verifier.js +70 -83
  92. package/srv/blockchain/signing/submission-finalizer.d.ts +23 -45
  93. package/srv/blockchain/signing/submission-finalizer.js +219 -86
  94. package/srv/blockchain/stored-chain.d.ts +20 -0
  95. package/srv/blockchain/stored-chain.js +237 -0
  96. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +31 -229
  97. package/srv/blockchain/transaction-building/buildooor-tx.js +652 -416
  98. package/srv/blockchain/transaction-building/cardano-tx.d.ts +9 -37
  99. package/srv/blockchain/transaction-presence.d.ts +5 -0
  100. package/srv/blockchain/transaction-presence.js +29 -0
  101. package/srv/blockchain/transaction-rows.d.ts +12 -0
  102. package/srv/blockchain/transaction-rows.js +44 -0
  103. package/srv/blockchain/wallet-worker/build-request.d.ts +5 -20
  104. package/srv/blockchain/wallet-worker/build-request.js +47 -30
  105. package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +5 -46
  106. package/srv/blockchain/wallet-worker/confirmation-tracker.js +25 -45
  107. package/srv/blockchain/wallet-worker/index.d.ts +1 -1
  108. package/srv/blockchain/wallet-worker/index.js +3 -11
  109. package/srv/blockchain/wallet-worker/job-store.d.ts +30 -148
  110. package/srv/blockchain/wallet-worker/job-store.js +101 -201
  111. package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -26
  112. package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -28
  113. package/srv/blockchain/wallet-worker/signers.d.ts +5 -24
  114. package/srv/blockchain/wallet-worker/signers.js +4 -12
  115. package/srv/blockchain/wallet-worker/wallet-worker.d.ts +8 -80
  116. package/srv/blockchain/wallet-worker/wallet-worker.js +107 -155
  117. package/srv/cardano-agent-service.cds +122 -84
  118. package/srv/cardano-agent-service.js +4 -9
  119. package/srv/cardano-backend-service.cds +78 -0
  120. package/srv/cardano-backend-service.d.ts +2 -0
  121. package/srv/cardano-backend-service.js +242 -0
  122. package/srv/cardano-indexer-service.cds +387 -73
  123. package/srv/cardano-indexer-service.d.ts +5 -1
  124. package/srv/cardano-indexer-service.js +532 -16
  125. package/srv/cardano-service.cds +424 -269
  126. package/srv/cardano-service.js +289 -201
  127. package/srv/cardano-sign-service.cds +201 -180
  128. package/srv/cardano-sign-service.js +71 -201
  129. package/srv/cardano-tx-service.cds +451 -370
  130. package/srv/cardano-tx-service.js +271 -289
  131. package/srv/cardano-ui.cds +16 -16
  132. package/srv/cardano-worker-service.cds +118 -125
  133. package/srv/cardano-worker-service.js +52 -61
  134. package/srv/cbor/cip68.d.ts +13 -0
  135. package/srv/cbor/cip68.js +56 -0
  136. package/srv/cbor/index.d.ts +3 -1
  137. package/srv/cbor/index.js +9 -1
  138. package/srv/cbor/parse.d.ts +30 -18
  139. package/srv/cbor/parse.js +44 -9
  140. package/srv/cbor/plutus-data-json.d.ts +20 -0
  141. package/srv/cbor/plutus-data-json.js +32 -0
  142. package/srv/config.d.ts +113 -0
  143. package/srv/config.js +409 -0
  144. package/srv/server.d.ts +15 -110
  145. package/srv/server.js +84 -404
  146. package/srv/utils/agent-access.d.ts +9 -0
  147. package/srv/utils/agent-access.js +67 -0
  148. package/srv/utils/agent-grants-config.d.ts +0 -46
  149. package/srv/utils/agent-grants-config.js +17 -85
  150. package/srv/utils/agent-grants.d.ts +106 -122
  151. package/srv/utils/agent-grants.js +538 -236
  152. package/srv/utils/agent-token-auth.d.ts +4 -99
  153. package/srv/utils/agent-token-auth.js +18 -182
  154. package/srv/utils/backend-request-handler.d.ts +3 -17
  155. package/srv/utils/backend-request-handler.js +3 -18
  156. package/srv/utils/collections.d.ts +3 -10
  157. package/srv/utils/collections.js +3 -10
  158. package/srv/utils/const.d.ts +23 -74
  159. package/srv/utils/const.js +32 -79
  160. package/srv/utils/crypto.d.ts +3 -12
  161. package/srv/utils/crypto.js +6 -21
  162. package/srv/utils/db-indexes.d.ts +27 -0
  163. package/srv/utils/db-indexes.js +120 -0
  164. package/srv/utils/db-sanitize.d.ts +20 -0
  165. package/srv/utils/db-sanitize.js +80 -0
  166. package/srv/utils/deep-json.d.ts +6 -0
  167. package/srv/utils/deep-json.js +240 -0
  168. package/srv/utils/epoch-slots.d.ts +13 -0
  169. package/srv/utils/epoch-slots.js +38 -0
  170. package/srv/utils/error-codes.d.ts +22 -75
  171. package/srv/utils/error-codes.js +23 -72
  172. package/srv/utils/errors.d.ts +46 -187
  173. package/srv/utils/errors.js +114 -230
  174. package/srv/utils/liveness.d.ts +12 -0
  175. package/srv/utils/liveness.js +35 -0
  176. package/srv/utils/mappers.d.ts +102 -223
  177. package/srv/utils/mappers.js +387 -316
  178. package/srv/utils/network-context.js +2 -13
  179. package/srv/utils/paging.d.ts +31 -0
  180. package/srv/utils/paging.js +43 -0
  181. package/srv/utils/pg-inline-json.d.ts +8 -0
  182. package/srv/utils/pg-inline-json.js +58 -0
  183. package/srv/utils/pg-order-nulls.d.ts +14 -0
  184. package/srv/utils/pg-order-nulls.js +54 -0
  185. package/srv/utils/plutus-placeholders.d.ts +16 -22
  186. package/srv/utils/plutus-placeholders.js +62 -33
  187. package/srv/utils/rate-limiter.d.ts +2 -21
  188. package/srv/utils/rate-limiter.js +5 -17
  189. package/srv/utils/readiness.d.ts +12 -0
  190. package/srv/utils/readiness.js +29 -0
  191. package/srv/utils/reference-script.d.ts +19 -0
  192. package/srv/utils/reference-script.js +84 -0
  193. package/srv/utils/result-numbers.d.ts +15 -0
  194. package/srv/utils/result-numbers.js +61 -0
  195. package/srv/utils/service-events.d.ts +0 -24
  196. package/srv/utils/service-events.js +3 -25
  197. package/srv/utils/signing-helper.d.ts +3 -20
  198. package/srv/utils/signing-helper.js +35 -64
  199. package/srv/utils/tx-build-helper.d.ts +10 -105
  200. package/srv/utils/tx-build-helper.js +81 -144
  201. package/srv/utils/tx-request-parsers.d.ts +82 -33
  202. package/srv/utils/tx-request-parsers.js +401 -49
  203. package/srv/utils/tx-utils.d.ts +3 -27
  204. package/srv/utils/tx-utils.js +32 -50
  205. package/srv/utils/types.d.ts +261 -191
  206. package/srv/utils/types.js +2 -6
  207. package/srv/utils/validators.d.ts +22 -92
  208. package/srv/utils/validators.js +50 -149
@@ -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
 
@@ -1,125 +1,118 @@
1
- using {odatano.cardano as db} from '../db/schema';
2
-
3
- /**
4
- * Cardano Wallet Worker Service (v2.0)
5
- *
6
- * Control + observability surface for the wallet worker / job engine:
7
- * - job submission (async build → sign → submit → confirm from server-side wallets)
8
- * - job status polling + cancellation
9
- * - read-only projections of jobs and registered worker wallets
10
- * - pause/resume of the local worker instance (admin)
11
- *
12
- * Security note: SubmitWalletJob executes value transfers with server-held keys —
13
- * the service requires authentication throughout; control actions and foreign-job
14
- * visibility are gated behind the Admin role. Jobs on HSM-backed wallets addition-
15
- * ally require the configured hsm.requiresRole (HSM_REQUIRES_ROLE), the same gate
16
- * the synchronous SignWithHsm path enforces. Keys are NEVER accepted or exposed
17
- * through this surface.
18
- */
19
- @requires: 'authenticated-user'
20
- service CardanoWorkerService @(impl: './cardano-worker-service') {
21
-
22
- @readonly
23
- @title : 'Wallet Jobs'
24
- @description: 'Asynchronous wallet-worker jobs. Non-admin callers see their own jobs only.'
25
- @restrict : [
26
- { grant: 'READ', to: 'Admin' },
27
- { grant: 'READ', where: 'createdBy = $user' }
28
- ]
29
- // dedupKey is the internal backing column of the idempotency constraint.
30
- entity WalletJobs as projection on db.CardanoWalletJobs excluding { dedupKey };
31
-
32
- @readonly
33
- @title : 'Worker Wallets'
34
- @description: 'Registered server-side worker wallets (addresses and stats only — no key material, no lease internals)'
35
- entity WorkerWallets as projection on db.CardanoWorkerWallets excluding { leaseOwner, leaseUntil };
36
-
37
- @title : 'Wallet Job Submission Result'
38
- type JobSubmissionResult {
39
- jobId : UUID;
40
- status : String(12);
41
- deduplicated : Boolean;
42
- }
43
-
44
- @title : 'Wallet Job Status'
45
- type JobStatus {
46
- jobId : UUID;
47
- walletId : String(50);
48
- kind : String(12);
49
- status : String(12);
50
- attempt : Integer;
51
- txHash : String(64);
52
- fee : String;
53
- errorCode : String(50);
54
- errorMessage : String(500);
55
- submittedAt : Timestamp;
56
- confirmedAt : Timestamp;
57
- finishedAt : Timestamp;
58
- }
59
-
60
- @title : 'Worker Status'
61
- type WorkerStatus {
62
- running : Boolean;
63
- wallets : many String;
64
- executing : many String;
65
- awaitingConfirmation : Integer;
66
- pendingJobs : Integer;
67
- }
68
-
69
- /**
70
- * Terminal job outcomes. Subscribing removes the need for a GetJobStatus poll loop:
71
- * (await cds.connect.to('CardanoWorkerService')).on('jobConfirmed', ({ data }) => …)
72
- */
73
- event jobConfirmed {
74
- jobId : UUID;
75
- walletId : String(50);
76
- kind : String(12);
77
- txHash : String(64);
78
- }
79
-
80
- event jobFailed {
81
- jobId : UUID;
82
- walletId : String(50);
83
- kind : String(12);
84
- txHash : String(64); // null when the job never reached the chain
85
- errorCode : String(50);
86
- errorMessage : String(500);
87
- }
88
-
89
- @title : 'Submit Wallet Job'
90
- @description: 'Queue an asynchronous transaction job for a worker wallet. Returns immediately with a jobId; poll GetJobStatus for the outcome. The request JSON is the same payload shape as the corresponding Build* action; senderAddress is always overridden with the wallet address.'
91
- action SubmitWalletJob(
92
- @title: 'Wallet Id' walletId : String(50),
93
- @title: 'Job Kind' kind : String(12),
94
- @title: 'Request JSON' requestJson : LargeString,
95
- @title: 'Idempotency Key' idempotencyKey : String(100),
96
- @title: 'Priority' priority : Integer,
97
- @title: 'Not Before' notBefore : Timestamp
98
- ) returns JobSubmissionResult;
99
-
100
- @title : 'Cancel Job'
101
- @description: 'Cancel a still-pending job. Jobs that started building may already reach the chain and cannot be cancelled.'
102
- action CancelJob(
103
- @title: 'Job Id' jobId : UUID
104
- ) returns Boolean;
105
-
106
- @title : 'Get Job Status'
107
- @description: 'Current lifecycle state of a wallet job (non-admins: own jobs only)'
108
- function GetJobStatus(
109
- @title: 'Job Id' jobId : UUID
110
- ) returns JobStatus;
111
-
112
- @title : 'Get Worker Status'
113
- @description: 'Live worker summary: running state, wallets, in-flight executions, confirmation backlog, queue depth'
114
- function GetWorkerStatus() returns WorkerStatus;
115
-
116
- @title : 'Pause Worker'
117
- @description: 'Stop the local worker instance (finishes in-flight steps; queued jobs stay pending).'
118
- @requires : 'Admin'
119
- action PauseWorker() returns Boolean;
120
-
121
- @title : 'Resume Worker'
122
- @description: 'Start/restart the local worker instance using the configured wallets.'
123
- @requires : 'Admin'
124
- action ResumeWorker() returns Boolean;
125
- }
1
+ using { WalletJobKind } from '../db/types';
2
+ using {odatano.cardano as db} from '../db/schema';
3
+
4
+ // Async wallet jobs signed with server-held keys, which are never accepted or returned here.
5
+ // Control actions and foreign jobs need Admin. A job needs the wallet's requiresRole and, on an
6
+ // HSM wallet, hsm.requiresRole. An agent token gets a 403 on every event of this service.
7
+ @requires: 'Transact'
8
+ @odatano.agent: 'closed'
9
+ service CardanoWorkerService @(impl: './cardano-worker-service') {
10
+
11
+ @readonly
12
+ @title : 'Wallet Jobs'
13
+ @description: 'Asynchronous wallet-worker jobs. Non-admin callers see their own jobs only.'
14
+ @restrict : [
15
+ { grant: 'READ', to: 'Admin' },
16
+ { grant: 'READ', where: 'createdBy = $user' }
17
+ ]
18
+ // dedupKey is the internal backing column of the idempotency constraint.
19
+ entity WalletJobs as projection on db.CardanoWalletJobs excluding { dedupKey };
20
+
21
+ @readonly
22
+ @title : 'Worker Wallets'
23
+ @description: 'Registered server-side worker wallets (addresses and stats only; no key material, no lease internals)'
24
+ entity WorkerWallets as projection on db.CardanoWorkerWallets excluding { leaseOwner, leaseUntil };
25
+
26
+ @title : 'Wallet Job Submission Result'
27
+ type JobSubmissionResult {
28
+ jobId : UUID;
29
+ status : String(12);
30
+ deduplicated : Boolean;
31
+ }
32
+
33
+ @title : 'Wallet Job Status'
34
+ type JobStatus {
35
+ jobId : UUID;
36
+ walletId : String(50);
37
+ kind : String(12);
38
+ status : String(12);
39
+ attempt : Integer;
40
+ txHash : String(64);
41
+ fee : String;
42
+ errorCode : String(50);
43
+ errorMessage : String(500);
44
+ submittedAt : Timestamp;
45
+ confirmedAt : Timestamp;
46
+ finishedAt : Timestamp;
47
+ }
48
+
49
+ @title : 'Worker Status'
50
+ type WorkerStatus {
51
+ running : Boolean;
52
+ wallets : many String;
53
+ executing : many String;
54
+ awaitingConfirmation : Integer;
55
+ pendingJobs : Integer;
56
+ }
57
+
58
+ /** Terminal job outcome. Subscribe in process, or wait over HTTP with GetJobStatus(waitMs). */
59
+ event jobConfirmed {
60
+ jobId : UUID;
61
+ walletId : String(50);
62
+ kind : String(12);
63
+ txHash : String(64);
64
+ }
65
+
66
+ event jobFailed {
67
+ jobId : UUID;
68
+ walletId : String(50);
69
+ kind : String(12);
70
+ txHash : String(64); // null when the job never reached the chain
71
+ errorCode : String(50);
72
+ errorMessage : String(500);
73
+ }
74
+
75
+ @title : 'Submit Wallet Job'
76
+ @description: 'Queue an asynchronous transaction job for a worker wallet. Returns immediately with a jobId; poll GetJobStatus for the outcome. The request JSON is the same payload shape as the corresponding Build* action; senderAddress is always overridden with the wallet address. A retry with the same idempotencyKey and request returns the job that holds the key; another request under that key is a 409.'
77
+ @odatano.agent: 'operator'
78
+ action SubmitWalletJob(
79
+ @title: 'Wallet Id' walletId : String(50),
80
+ @title: 'Job Kind' @assert.range kind : WalletJobKind,
81
+ @title: 'Request JSON' requestJson : LargeString,
82
+ @title: 'Idempotency Key' idempotencyKey : String(100),
83
+ @title: 'Priority' @assert.range: [0, 10000] priority : Integer,
84
+ @title: 'Not Before' notBefore : Timestamp
85
+ ) returns JobSubmissionResult;
86
+
87
+ @title : 'Cancel Job'
88
+ @description: 'Cancel a still-pending job. Jobs that started building may already reach the chain and cannot be cancelled.'
89
+ @odatano.agent: 'operator'
90
+ action CancelJob(
91
+ @title: 'Job Id' jobId : UUID
92
+ ) returns Boolean;
93
+
94
+ @title : 'Get Job Status'
95
+ @description: 'Current lifecycle state of a wallet job (non-admins: own jobs only). With waitMs the call answers as soon as the job is confirmed, failed or cancelled, or after that time with the state it has then. Keep waitMs below the timeout of the proxies in front of the service.'
96
+ @odatano.agent: 'operator'
97
+ function GetJobStatus(
98
+ @title: 'Job Id' jobId : UUID,
99
+ @title: 'Wait (ms)' @assert.range: [0, 30000] waitMs : Integer
100
+ ) returns JobStatus;
101
+
102
+ @title : 'Get Worker Status'
103
+ @description: 'Live worker summary: running state, wallets, in-flight executions, confirmation backlog, queue depth'
104
+ @odatano.agent: 'operator'
105
+ function GetWorkerStatus() returns WorkerStatus;
106
+
107
+ @title : 'Pause Worker'
108
+ @description: 'Stop the local worker instance (finishes in-flight steps; queued jobs stay pending).'
109
+ @requires : 'Admin'
110
+ @odatano.agent: 'operator'
111
+ action PauseWorker() returns Boolean;
112
+
113
+ @title : 'Resume Worker'
114
+ @description: 'Start/restart the local worker instance using the configured wallets.'
115
+ @requires : 'Admin'
116
+ @odatano.agent: 'operator'
117
+ action ResumeWorker() returns Boolean;
118
+ }
@@ -8,35 +8,22 @@ const backend_request_handler_1 = require("./utils/backend-request-handler");
8
8
  const errors_1 = require("./utils/errors");
9
9
  const error_codes_1 = require("./utils/error-codes");
10
10
  const validators_1 = require("./utils/validators");
11
+ const result_numbers_1 = require("./utils/result-numbers");
11
12
  const wallet_worker_1 = require("./blockchain/wallet-worker");
12
13
  const job_store_1 = require("./blockchain/wallet-worker/job-store");
13
14
  const server_1 = require("./server");
15
+ const config_1 = require("./config");
16
+ const CardanoWorkerService_1 = require("#cds-models/CardanoWorkerService");
14
17
  const logger = cds_1.default.log('CardanoWorkerService');
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).
22
- */
18
+ const TERMINAL_JOB_STATUS = new Set(['confirmed', 'failed', 'cancelled']);
19
+ const JOB_WAIT_POLL_MS = 1000;
23
20
  function isAdmin(req) {
24
21
  return req.user?.is?.('Admin') ?? false;
25
22
  }
26
- /**
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.
32
- */
33
- function missingHsmRole(req, signerType) {
34
- if (signerType !== 'hsm')
35
- return null;
36
- const requiresRole = (0, server_1.getHsmConfig)()?.requiresRole;
37
- if (!requiresRole || req.user?.is(requiresRole))
38
- return null;
39
- return requiresRole;
23
+ /** The first role the caller lacks for this wallet: its own requiresRole, then hsm.requiresRole on an HSM wallet. */
24
+ function missingWalletRole(req, wallet) {
25
+ const roles = [wallet?.requiresRole, wallet?.signerType === 'hsm' ? (0, server_1.getHsmConfig)()?.requiresRole : null];
26
+ return roles.find((role) => role && !req.user?.is(role)) ?? null;
40
27
  }
41
28
  function toJobStatus(job) {
42
29
  return {
@@ -54,23 +41,22 @@ function toJobStatus(job) {
54
41
  finishedAt: job.finishedAt,
55
42
  };
56
43
  }
44
+ /** CardanoWorkerService handlers: job submission and status, worker control. */
57
45
  module.exports = (srv) => {
58
- // SubmitWalletJob — queue an async transaction job; returns the jobId immediately.
59
- srv.on('SubmitWalletJob', async (req) => {
46
+ (0, result_numbers_1.answerNumbersAsText)(srv);
47
+ // SubmitWalletJob: queue an async transaction job; returns the jobId immediately.
48
+ srv.on(CardanoWorkerService_1.SubmitWalletJob, async (req) => {
60
49
  const { walletId, kind, requestJson, idempotencyKey, priority, notBefore } = req.data;
61
50
  if (!walletId?.trim())
62
51
  return (0, errors_1.rejectInvalid)(req, 'SubmitWalletJob', 'walletId is required', 'walletId');
63
- if (!kind || !job_store_1.WALLET_JOB_KINDS.includes(kind)) {
64
- return (0, errors_1.rejectInvalid)(req, 'SubmitWalletJob', `Invalid kind "${String(kind)}" — must be one of: ${job_store_1.WALLET_JOB_KINDS.join(', ')}`, 'kind');
65
- }
52
+ // the model rejects an unknown kind and a priority outside 0..10000
53
+ if (!kind)
54
+ return (0, errors_1.rejectMissing)(req, 'SubmitWalletJob', 'kind');
66
55
  if (!requestJson?.trim())
67
56
  return (0, errors_1.rejectInvalid)(req, 'SubmitWalletJob', 'requestJson is required', 'requestJson');
68
57
  const jsonResult = (0, validators_1.validateJsonWithLimits)(requestJson, 'requestJson');
69
58
  if (!jsonResult.valid)
70
59
  return (0, errors_1.rejectInvalid)(req, 'SubmitWalletJob', jsonResult.error, 'requestJson');
71
- if (priority != null && (!Number.isInteger(priority) || priority < 0 || priority > 10_000)) {
72
- return (0, errors_1.rejectInvalid)(req, 'SubmitWalletJob', 'priority must be an integer between 0 and 10000', 'priority');
73
- }
74
60
  if (notBefore != null && Number.isNaN(Date.parse(String(notBefore)))) {
75
61
  return (0, errors_1.rejectInvalid)(req, 'SubmitWalletJob', 'notBefore must be a valid timestamp', 'notBefore');
76
62
  }
@@ -79,36 +65,36 @@ module.exports = (srv) => {
79
65
  }
80
66
  let config;
81
67
  try {
82
- config = (0, server_1.loadWalletWorkerConfigFromEnv)();
68
+ config = (0, config_1.loadWalletWorkerConfigFromEnv)();
83
69
  }
84
70
  catch (err) {
85
71
  return (0, errors_1.rejectInvalid)(req, 'SubmitWalletJob', err instanceof Error ? err.message : String(err));
86
72
  }
87
73
  if (!config.enabled) {
88
- return (0, errors_1.rejectInvalid)(req, 'SubmitWalletJob', 'Wallet worker is not enabled — set cds.requires.odatano-core.walletWorker.enabled (or WALLET_WORKER_ENABLED=true) with configured wallets.');
74
+ return (0, errors_1.rejectInvalid)(req, 'SubmitWalletJob', 'Wallet worker is not enabled: set cds.requires.odatano-core.walletWorker.enabled (or WALLET_WORKER_ENABLED=true) with configured wallets.');
89
75
  }
90
76
  // Role gate on this instance's config, mirroring the sign service's 403.
91
- const configuredRole = missingHsmRole(req, config.wallets.find((w) => w.walletId === walletId)?.signerType);
77
+ const configuredRole = missingWalletRole(req, config.wallets.find((w) => w.walletId === walletId));
92
78
  if (configuredRole) {
93
- return req.reject(403, `SubmitWalletJob on HSM-backed wallet "${walletId}" requires role '${configuredRole}'`);
79
+ return req.reject(403, `SubmitWalletJob on wallet "${walletId}" requires role '${configuredRole}'`);
94
80
  }
95
81
  return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
96
82
  const wallet = await (0, job_store_1.readWallet)(db, walletId);
97
83
  if (!wallet)
98
- return (0, errors_1.rejectInvalid)(req, 'SubmitWalletJob', `Unknown wallet "${walletId}" — configured wallets are registered at worker start`, 'walletId');
84
+ return (0, errors_1.rejectInvalid)(req, 'SubmitWalletJob', `Unknown wallet "${walletId}": configured wallets are registered at worker start`, 'walletId');
99
85
  if (!wallet.enabled)
100
86
  return (0, errors_1.rejectInvalid)(req, 'SubmitWalletJob', `Wallet "${walletId}" is disabled`, 'walletId');
101
- // Registered row too: another instance may run the HSM wallet this one has no config for.
102
- const registeredRole = missingHsmRole(req, wallet.signerType);
87
+ // Registered row too: another instance may run the wallet this one has no config for.
88
+ const registeredRole = missingWalletRole(req, wallet);
103
89
  if (registeredRole) {
104
- throw new errors_1.BackendError(`Wallet "${walletId}" is HSM-backed and requires role '${registeredRole}'`, 403, error_codes_1.ERROR_CODES.FORBIDDEN, undefined, undefined, 'walletId');
90
+ throw new errors_1.BackendError(`SubmitWalletJob on wallet "${walletId}" requires role '${registeredRole}'`, 403, error_codes_1.ERROR_CODES.FORBIDDEN, undefined, undefined, 'walletId');
105
91
  }
106
92
  const result = await (0, job_store_1.insertJob)(db, {
107
93
  walletId,
108
94
  kind: kind,
109
95
  request: requestJson,
110
96
  idempotencyKey: idempotencyKey ?? null,
111
- priority,
97
+ priority: priority ?? undefined,
112
98
  notBefore: notBefore ? new Date(notBefore).toISOString() : null,
113
99
  maxAttempts: config.defaultMaxAttempts,
114
100
  createdBy: req.user?.id ?? null,
@@ -117,52 +103,57 @@ module.exports = (srv) => {
117
103
  return result;
118
104
  });
119
105
  });
120
- // CancelJob — pending jobs only; scoped to the creator unless Admin.
121
- srv.on('CancelJob', async (req) => {
106
+ // CancelJob: pending jobs only; scoped to the creator unless Admin.
107
+ srv.on(CardanoWorkerService_1.CancelJob, async (req) => {
122
108
  const { jobId } = req.data;
123
109
  if (!jobId)
124
110
  return (0, errors_1.rejectInvalid)(req, 'CancelJob', 'jobId is required', 'jobId');
125
111
  return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
126
112
  const job = await (0, job_store_1.getJobById)(db, jobId);
127
113
  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.
114
+ // Same 404 for "not found" and "not yours" (no existence oracle). Throw, don't
115
+ // req.reject: inside handleRequest a plain CAP error is remapped to 500.
132
116
  throw new errors_1.NotFoundError(`Job ${jobId}`);
133
117
  }
134
118
  const cancelled = await (0, job_store_1.markCancelled)(db, jobId);
135
119
  if (!cancelled) {
136
- return (0, errors_1.rejectInvalid)(req, 'CancelJob', `Job ${jobId} is ${job.status} — only pending jobs can be cancelled`, 'jobId');
120
+ return (0, errors_1.rejectInvalid)(req, 'CancelJob', `Job ${jobId} is ${job.status}: only pending jobs can be cancelled`, 'jobId');
137
121
  }
138
122
  return true;
139
123
  });
140
124
  });
141
- // GetJobStatus — scoped to the creator unless Admin.
142
- srv.on('GetJobStatus', async (req) => {
143
- const { jobId } = req.data;
125
+ // GetJobStatus: scoped to the creator unless Admin. With waitMs it answers once the job is
126
+ // confirmed, failed or cancelled, or when the time is up. Each read has its own transaction,
127
+ // so a waiting request holds no database connection.
128
+ srv.on(CardanoWorkerService_1.GetJobStatus, async (req) => {
129
+ const { jobId, waitMs } = req.data;
144
130
  if (!jobId)
145
131
  return (0, errors_1.rejectInvalid)(req, 'GetJobStatus', 'jobId is required', 'jobId');
146
- return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
147
- const job = await (0, job_store_1.getJobById)(db, jobId);
148
- if (!job || (!isAdmin(req) && job.createdBy !== req.user?.id)) {
149
- throw new errors_1.NotFoundError(`Job ${jobId}`); // see CancelJob: reject() here becomes a 500
132
+ const deadline = Date.now() + Number(waitMs ?? 0);
133
+ return (0, backend_request_handler_1.handleRequest)(req, async () => {
134
+ for (;;) {
135
+ const job = await (0, job_store_1.runWithoutAmbientTx)(() => cds_1.default.tx((tx) => (0, job_store_1.getJobById)(tx, jobId)));
136
+ if (!job || (!isAdmin(req) && job.createdBy !== req.user?.id)) {
137
+ throw new errors_1.NotFoundError(`Job ${jobId}`); // see CancelJob: reject() here becomes a 500
138
+ }
139
+ const timeUp = Date.now() + JOB_WAIT_POLL_MS > deadline || req.http?.res.destroyed === true;
140
+ if (TERMINAL_JOB_STATUS.has(job.status) || timeUp)
141
+ return toJobStatus(job);
142
+ await new Promise((resolve) => setTimeout(resolve, JOB_WAIT_POLL_MS));
150
143
  }
151
- return toJobStatus(job);
152
144
  });
153
145
  });
154
- // GetWorkerStatus — live summary of the local worker instance.
146
+ // GetWorkerStatus: live summary of the local worker instance.
155
147
  srv.on('GetWorkerStatus', async (req) => {
156
148
  return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
157
149
  const worker = (0, wallet_worker_1.getWalletWorker)();
158
150
  const summary = worker?.getStatusSummary() ?? {
159
151
  running: false, wallets: [], executing: [], awaitingConfirmation: 0,
160
152
  };
161
- const pending = await (0, job_store_1.findDueJobs)(db, new Date(8640000000000000)); // all pending, ignore notBefore
162
- return { ...summary, pendingJobs: pending.length };
153
+ return { ...summary, pendingJobs: await (0, job_store_1.countPendingJobs)(db) };
163
154
  });
164
155
  });
165
- // PauseWorker — stop the local instance; queued jobs stay pending.
156
+ // PauseWorker: stop the local instance; queued jobs stay pending.
166
157
  srv.on('PauseWorker', async (req) => {
167
158
  return (0, backend_request_handler_1.handleRequest)(req, async () => {
168
159
  await (0, wallet_worker_1.stopWalletWorker)();
@@ -170,18 +161,18 @@ module.exports = (srv) => {
170
161
  return true;
171
162
  });
172
163
  });
173
- // ResumeWorker — (re)start the local instance from config. Gated on enabled,
164
+ // ResumeWorker: (re)start the local instance from config. Gated on enabled,
174
165
  // mirroring resumeCrawler.
175
166
  srv.on('ResumeWorker', async (req) => {
176
167
  let config;
177
168
  try {
178
- config = (0, server_1.loadWalletWorkerConfigFromEnv)();
169
+ config = (0, config_1.loadWalletWorkerConfigFromEnv)();
179
170
  }
180
171
  catch (err) {
181
172
  return (0, errors_1.rejectInvalid)(req, 'ResumeWorker', err instanceof Error ? err.message : String(err));
182
173
  }
183
174
  if (!config.enabled) {
184
- return (0, errors_1.rejectInvalid)(req, 'ResumeWorker', 'Wallet worker is not enabled — set cds.requires.odatano-core.walletWorker.enabled (or WALLET_WORKER_ENABLED=true) before resuming.');
175
+ return (0, errors_1.rejectInvalid)(req, 'ResumeWorker', 'Wallet worker is not enabled: set cds.requires.odatano-core.walletWorker.enabled (or WALLET_WORKER_ENABLED=true) before resuming.');
185
176
  }
186
177
  return (0, backend_request_handler_1.handleRequest)(req, async () => {
187
178
  const client = (0, server_1.getCardanoClient)();
@@ -0,0 +1,13 @@
1
+ /** CIP-67 asset-name labels of the CIP-68 token classes, as the first 4 bytes of the asset name. */
2
+ export declare const CIP68_LABEL: {
3
+ readonly reference: "000643b0";
4
+ readonly nft: "000de140";
5
+ readonly ft: "0014df10";
6
+ readonly rft: "001bc280";
7
+ };
8
+ /** Reference-NFT unit of a CIP-68 user token with label 333 or 444; null for any other unit. */
9
+ export declare function cip68ReferenceUnit(unit: string): string | null;
10
+ /** The label-333 and label-444 units a CIP-68 reference NFT describes; null for any other unit. */
11
+ export declare function cip68UserUnits(referenceUnit: string): string[] | null;
12
+ export declare function cip68DecimalsFromDatum(cborHex: string): number | null;
13
+ //# sourceMappingURL=cip68.d.ts.map