@odatano/core 2.0.0-rc.24 → 2.0.0-rc.26

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 (78) hide show
  1. package/@cds-models/CardanoIndexerService/index.d.ts +37 -0
  2. package/@cds-models/CardanoIndexerService/index.js +4 -0
  3. package/@cds-models/CardanoODataService/index.d.ts +27 -2
  4. package/@cds-models/CardanoODataService/index.js +3 -0
  5. package/@cds-models/CardanoSignService/index.d.ts +23 -1
  6. package/@cds-models/CardanoSignService/index.js +3 -0
  7. package/@cds-models/CardanoTransactionService/index.d.ts +34 -1
  8. package/@cds-models/CardanoTransactionService/index.js +4 -0
  9. package/@cds-models/index.d.ts +18 -0
  10. package/@cds-models/index.js +3 -0
  11. package/@cds-models/odatano/cardano/index.d.ts +49 -2
  12. package/@cds-models/odatano/cardano/index.js +6 -0
  13. package/README.md +195 -195
  14. package/db/schema.cds +74 -3
  15. package/db/types.cds +27 -0
  16. package/package.json +182 -182
  17. package/srv/blockchain/backends/blockfrost-backend.js +4 -2
  18. package/srv/blockchain/backends/cardano-backend.d.ts +0 -2
  19. package/srv/blockchain/backends/koios-backend.d.ts +1 -1
  20. package/srv/blockchain/backends/koios-backend.js +61 -14
  21. package/srv/blockchain/backends/odatano-backend.d.ts +5 -0
  22. package/srv/blockchain/backends/odatano-backend.js +12 -0
  23. package/srv/blockchain/backends/ogmios-backend.d.ts +12 -2
  24. package/srv/blockchain/backends/ogmios-backend.js +91 -21
  25. package/srv/blockchain/cardano-client.d.ts +11 -5
  26. package/srv/blockchain/cardano-client.js +51 -16
  27. package/srv/blockchain/cardano-indexer.d.ts +43 -15
  28. package/srv/blockchain/cardano-indexer.js +177 -68
  29. package/srv/blockchain/cardano-tx-builder.d.ts +11 -1
  30. package/srv/blockchain/cardano-tx-builder.js +57 -2
  31. package/srv/blockchain/crawler/certificate-backfill.d.ts +22 -0
  32. package/srv/blockchain/crawler/certificate-backfill.js +49 -30
  33. package/srv/blockchain/crawler/crawler.d.ts +3 -1
  34. package/srv/blockchain/crawler/crawler.js +12 -7
  35. package/srv/blockchain/crawler/sync-state.d.ts +3 -1
  36. package/srv/blockchain/crawler/sync-state.js +15 -2
  37. package/srv/blockchain/crawler/transaction-backfill.d.ts +52 -0
  38. package/srv/blockchain/crawler/transaction-backfill.js +283 -0
  39. package/srv/blockchain/crawler/utxo-set-import.d.ts +9 -0
  40. package/srv/blockchain/crawler/utxo-set-import.js +138 -47
  41. package/srv/blockchain/ledger-state.d.ts +16 -1
  42. package/srv/blockchain/ledger-state.js +38 -18
  43. package/srv/blockchain/pending-spends.d.ts +28 -0
  44. package/srv/blockchain/pending-spends.js +89 -0
  45. package/srv/blockchain/stored-chain.d.ts +5 -2
  46. package/srv/blockchain/stored-chain.js +31 -5
  47. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +12 -3
  48. package/srv/blockchain/transaction-building/buildooor-tx.js +203 -21
  49. package/srv/blockchain/transaction-building/cardano-tx.d.ts +2 -1
  50. package/srv/blockchain/transaction-rows.d.ts +1 -1
  51. package/srv/blockchain/transaction-rows.js +2 -1
  52. package/srv/blockchain/wallet-worker/build-request.js +1 -1
  53. package/srv/cardano-backend-service.js +35 -8
  54. package/srv/cardano-indexer-service.cds +201 -176
  55. package/srv/cardano-indexer-service.js +104 -10
  56. package/srv/cardano-service.cds +5 -0
  57. package/srv/cardano-service.js +3 -1
  58. package/srv/cardano-tx-service.cds +39 -0
  59. package/srv/cardano-tx-service.js +88 -14
  60. package/srv/server.js +4 -1
  61. package/srv/utils/agent-grants.js +1 -0
  62. package/srv/utils/const.d.ts +5 -0
  63. package/srv/utils/const.js +6 -1
  64. package/srv/utils/error-codes.d.ts +2 -0
  65. package/srv/utils/error-codes.js +2 -0
  66. package/srv/utils/errors.d.ts +7 -0
  67. package/srv/utils/errors.js +11 -1
  68. package/srv/utils/mappers.d.ts +24 -2
  69. package/srv/utils/mappers.js +49 -0
  70. package/srv/utils/pg-inline-json.d.ts +8 -0
  71. package/srv/utils/pg-inline-json.js +63 -0
  72. package/srv/utils/tx-build-helper.d.ts +2 -0
  73. package/srv/utils/tx-build-helper.js +12 -0
  74. package/srv/utils/tx-request-parsers.d.ts +46 -5
  75. package/srv/utils/tx-request-parsers.js +227 -16
  76. package/srv/utils/types.d.ts +59 -0
  77. package/srv/utils/validators.d.ts +5 -1
  78. package/srv/utils/validators.js +19 -9
package/README.md CHANGED
@@ -1,195 +1,195 @@
1
- <p align="center">
2
- <picture>
3
- <source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/npm/@odatano/brand@1/logos/odatano-core-logo-on-dark.svg">
4
- <img src="https://cdn.jsdelivr.net/npm/@odatano/brand@1/logos/odatano-core-logo.svg" alt="ODATANO CORE" height="84">
5
- </picture>
6
- </p>
7
-
8
- # Enterprise OData Services for the Cardano Blockchain
9
-
10
- Funded by [Cardano Catalyst Fund 14](https://projectcatalyst.io/funds/14/sponsored-by-leftovers/sap-cardano-odata-v4-api-with-cap-and-sap-cardano-sdk) all four milestones completed and approved (April 2026).
11
-
12
- **ODATANO** is an SAP CAP–based service that exposes the Cardano blockchain via a standardized **OData V4** interface, enabling enterprise-grade read and write access with native transaction building.
13
-
14
- [![Tests](https://github.com/ODATANO/ODATANO/actions/workflows/test.yaml/badge.svg)](https://github.com/ODATANO/ODATANO/actions/workflows/test.yaml)
15
- [![Coverage](https://codecov.io/gh/ODATANO/ODATANO/branch/main/graph/badge.svg)](https://codecov.io/gh/ODATANO/ODATANO)
16
- [![npm version](https://img.shields.io/npm/v/@odatano/core?logo=npm)](https://www.npmjs.com/package/@odatano/core)
17
- [![npm downloads](https://img.shields.io/npm/dt/@odatano/core?logo=npm&label=downloads&color=blue)](https://www.npmjs.com/package/@odatano/core)
18
- [![License](https://img.shields.io/badge/license-Apache%202.0-yellow)](LICENSE)
19
-
20
-
21
- ## Quick Start
22
-
23
- ### As CAP Plugin (recommended)
24
-
25
- Add ODATANO to any existing SAP CAP project:
26
-
27
- ```bash
28
- npm install @odatano/core @cap-js/sqlite
29
- ```
30
-
31
- ```json
32
- {
33
- "cds": {
34
- "requires": {
35
- "db": { "kind": "sqlite" },
36
- "odatano-core": {
37
- "network": "preview",
38
- "backends": ["blockfrost"]
39
- }
40
- }
41
- }
42
- }
43
- ```
44
-
45
- Put your API key in a `.env` file in the project root (loaded automatically by `cds serve` / `cds watch`) — don't commit it to `package.json`:
46
-
47
- ```bash
48
- # .env
49
- BLOCKFROST_API_KEY=preview_your_api_key_here
50
- ```
51
-
52
- ```bash
53
- cds deploy --to sqlite
54
- cds serve
55
- ```
56
-
57
- > Config in `cds.requires.odatano-core` takes precedence over environment
58
- > variables; a `blockfrostApiKey` set there would override the `.env` value.
59
-
60
- > **Self-hosted Blockfrost-compatible node?** (Dolos MiniBF, Demeter Self-Hosted)
61
- > Set `blockfrostCustomBackend` to the node's base URL (e.g. `http://localhost:3010/api/v0`).
62
- > When set, `blockfrostApiKey` becomes optional. See the [Backend Configuration Guide](docs/guides/BACKEND_CONFIGURATION.md#self-hosted-blockfrost-compatible-backends).
63
-
64
- ### Standalone
65
-
66
- Run ODATANO as a self-contained service (no host CAP project needed):
67
-
68
- ```bash
69
- git clone https://github.com/ODATANO/ODATANO && cd ODATANO
70
- npm ci
71
- cp .env.example .env # set BLOCKFROST_API_KEY, NETWORK, BACKENDS
72
- cds deploy --to sqlite
73
- cds serve
74
- ```
75
-
76
- Or with Docker — this brings up a local **cardano-node + Ogmios + ODATANO** stack
77
- (Preview), with the service pre-wired to the local Ogmios backend:
78
-
79
- ```bash
80
- docker compose up -d # full stack
81
- docker compose up -d cardano-node ogmios # just the chain backend (pre-sync)
82
- docker compose logs -f ogmios # watch sync (/health: 202 syncing, 200 near tip)
83
- ```
84
-
85
- > First sync from genesis takes hours; the node DB persists in a Docker volume so
86
- > restarts resume. Until Ogmios catches up, historical queries fall back to
87
- > Blockfrost (set `BLOCKFROST_API_KEY`).
88
-
89
- Service available at `http://localhost:4004`. See the [Quick Start Guide](docs/QUICK_START.md#local-ogmios--cardano-node-docker) for the local Ogmios stack and full details.
90
-
91
- ## Dev Mode: Mocked Authentication
92
-
93
- > **Heads-up.** `cds serve` uses CAP's mocked auth: `@requires: 'authenticated-user'` accepts any Basic-Auth header against a mock user (`alice`, `bob`, …) — passwords are not checked. Anonymous requests get 401, but anyone reaching the port can authenticate.
94
- >
95
- > Production needs the `[production]` profile (`NODE_ENV=production`), which switches to `auth: xsuaa`. Don't expose a dev-mode instance. See the [Security Guide](docs/guides/SECURITY_GUIDE.md#authentication-xsuaa).
96
- >
97
- > The Docker image runs `NODE_ENV=production` with HTTP basic auth via `@odatano/cap-auth` (`ODATANO_HTTP_PASSWORD` required, user `ODATANO_HTTP_USER` default `odatano`, roles `ODATANO_HTTP_ROLES` default `Admin`; 20 failed attempts per 15 min per client address and user, then 429). `ODATANO_AUTH=dummy` disables authentication for local testing only. `getLiveness()` and `VerifyDataSignature` stay anonymous.
98
- >
99
- > Database of the image: `ODATANO_DB_URL=postgres://user:pw@host:5432/db` selects PostgreSQL (schema deployed on every boot); otherwise SQLite at `ODATANO_DB_PATH` (default `/data/db.sqlite`). `docker compose run --rm --no-deps odatano migrate --from /data/db.sqlite` copies an existing SQLite file into a freshly deployed PostgreSQL.
100
-
101
- ## Services
102
-
103
- | Service | Path | Purpose |
104
- |---|---|---|
105
- | CardanoODataService | `/odata/v4/cardano-odata/` | Read blockchain data (29 entities, 19 actions) |
106
- | CardanoTransactionService | `/odata/v4/cardano-transaction/` | Build & submit transactions (13 actions) |
107
- | CardanoSignService | `/odata/v4/cardano-sign/` | External signing + HSM (9 actions) |
108
- | CardanoIndexerService | `/odata/v4/cardano-indexer/` | Chain crawler / pre-sync control (v2.0, off by default) |
109
- | CardanoWorkerService | `/odata/v4/cardano-worker/` | Asynchronous wallet jobs (v2.0, off by default) |
110
- | CardanoAgentService | `/odata/v4/cardano-agent/` | Agent grants: scoped bearer tokens for agents (v2.0, off by default) |
111
-
112
- Both v2.0 services also publish **CAP events**, so a consumer can subscribe instead of polling —
113
- in-process, no broker required:
114
-
115
- ```js
116
- (await cds.connect.to('CardanoWorkerService')).on('jobConfirmed', ({ data }) => …)
117
- (await cds.connect.to('CardanoIndexerService')).on('blockIndexed', ({ data }) => …)
118
- ```
119
-
120
- ## Agent grants (v2.0, off by default)
121
-
122
- Hand an agent a **scoped, budgeted token** instead of a user.
123
-
124
- ```bash
125
- AGENT_GRANTS_ENABLED=true # or cds.requires.odatano-core.agentGrants.enabled
126
- AGENT_GRANTS_DELEGATE=mocked # CAP auth kind that keeps authenticating non-token requests (default: configured kind)
127
- AGENT_GRANT_ADMIN_RATE_LIMIT=10 # grant administration calls per principal per hour (or agentGrants.adminRateLimit)
128
- AGENT_TOKEN_CACHE_MS=10000 # a resolved token is reused this long before the row is read again; 0 = off (or agentGrants.tokenCacheMs)
129
- ```
130
-
131
- 1. An **Admin** issues a grant (`POST /odata/v4/cardano-agent/CreateAgentGrant`): an allow list of
132
- actions, optionally a worker `walletId` (required for `SubmitWalletJob`/`CancelJob`), allowed job
133
- kinds, a daily budget and an expiry. The response carries the token `odat_…` **once**; the
134
- server stores only its SHA-256.
135
- 2. The agent sends `x-agent-token: odat_…` on any of the six service paths. It runs as the principal
136
- `agent:<grantId>` with the single role `agent-grant`, never as the operator: every
137
- `@requires: 'Admin'` surface (pause/resume, HSM signing, grant administration) refuses it by
138
- construction. Reads and compute-only actions are always allowed; allow-listed actions each cost
139
- one budget unit per UTC day (a build is the service an agent buys); everything else is 403.
140
- Wallet jobs are pinned to the grant's wallet and visible only to the grant that queued them.
141
- 3. `GET /odata/v4/cardano-agent/GetGrantStatus()` tells the agent what it may do and how much budget
142
- is left; `RevokeAgentGrant` turns the token into an unknown token immediately.
143
- 4. Lifecycle (Admin; the same semantics as the gateway's peer services, so one client drives
144
- them all): `UpdateAgentGrant` changes label, allow list, job kinds, daily budget or expiry
145
- (absent = untouched, explicit `null` = cleared; the wallet binding is immutable, 409
146
- `GRANT_REVOKED` on a revoked grant); `RotateAgentGrantToken` returns a fresh token once, the old
147
- one is unknown from the next request; `GetGrantUsage(grantId, since, until)` lists admitted calls
148
- per service and action over up to 366 days (an Admin for any grant, a token for its own). All
149
- administration calls share the per-principal hourly rate limit above.
150
-
151
- Grantable: `Build*`, `SetCollateral`, `CreateSigningRequest`, `VerifySignature`, `Submit*`,
152
- `CheckSubmissionStatus`, `SubmitWalletJob`, `CancelJob`. Never: `SignWithHsm*`, `Pause*`/`Resume*`,
153
- `pauseCrawler`/`resumeCrawler`, grant administration.
154
-
155
- Programmatic seams for other packages (`@odatano/x402` sells grants against a 402 payment):
156
- `issueAgentGrant()`, `updateAgentGrant()`, `rotateAgentGrantToken()`, `revokeAgentGrantById()`,
157
- `getGrantUsage()`, `registerTransportLane()` from `@odatano/core`.
158
-
159
- ## Liveness probe
160
-
161
- `GET /odata/v4/cardano-indexer/getLiveness()` answers `200 { status: "alive", timestamp, uptime,
162
- version, network }` **without credentials** (`@requires: 'any'`) as long as the process runs — no
163
- backend or DB probe, no secrets. The Docker `HEALTHCHECK`, compose and upstream probes use it
164
- instead of the service document, so a wrong operator password no longer reads as "ODATANO down".
165
- Readiness (crawler, worker, backends) stays authenticated: `getStatus()`, `GetWorkerStatus()`,
166
- `GetNetworkInformation`.
167
-
168
- ## Requirements
169
-
170
- - **Node.js >= 22.5** and **@sap/cds >= 10** (peer dependency). CAP 9 hosts cannot load `@odatano/core@2`.
171
- - Upgrading a consumer from 1.x: run **`cds deploy`**. 2.0 adds six tables (`CardanoSyncState`,
172
- `CardanoReorgLog`, `CardanoWorkerWallets`, `CardanoWalletJobs`, `CardanoAgentGrants`,
173
- `CardanoAgentGrantUsage`) plus a `dedupKey` column; without the redeploy the new services answer
174
- `no such table` while the old ones keep working.
175
-
176
- ## Documentation
177
-
178
- | Guide | Description |
179
- |-------|-------------|
180
- | [Quick Start](docs/QUICK_START.md) | Get running in 5 minutes |
181
- | [User Guide](docs/guides/USER_GUIDE.md) | API usage, entities, and examples |
182
- | [Developer Guide](docs/guides/DEVELOPER_GUIDE.md) | Architecture and development |
183
- | [Transaction Workflow](docs/guides/TRANSACTION_WORKFLOW.md) | Build → Sign → Submit flow |
184
- | [Security Guide](docs/guides/SECURITY_GUIDE.md) | Authentication, signing security, HSM |
185
- | [Docker Deployment](docs/guides/DOCKER_DEPLOYMENT.md) | Container deployment |
186
-
187
- ## License
188
-
189
- Apache License 2.0 - see [LICENSE](LICENSE)
190
-
191
- ## Support
192
-
193
- - **Issues**: [GitHub Issues](https://github.com/ODATANO/ODATANO/issues)
194
- - **Project Lead**: Max Weber
195
- - **Contact**: info@odatano.dev
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/npm/@odatano/brand@1/logos/odatano-core-logo-on-dark.svg">
4
+ <img src="https://cdn.jsdelivr.net/npm/@odatano/brand@1/logos/odatano-core-logo.svg" alt="ODATANO CORE" height="84">
5
+ </picture>
6
+ </p>
7
+
8
+ # Enterprise OData Services for the Cardano Blockchain
9
+
10
+ Funded by [Cardano Catalyst Fund 14](https://projectcatalyst.io/funds/14/sponsored-by-leftovers/sap-cardano-odata-v4-api-with-cap-and-sap-cardano-sdk) all four milestones completed and approved (April 2026).
11
+
12
+ **ODATANO** is an SAP CAP–based service that exposes the Cardano blockchain via a standardized **OData V4** interface, enabling enterprise-grade read and write access with native transaction building.
13
+
14
+ [![Tests](https://github.com/ODATANO/ODATANO/actions/workflows/test.yaml/badge.svg)](https://github.com/ODATANO/ODATANO/actions/workflows/test.yaml)
15
+ [![Coverage](https://codecov.io/gh/ODATANO/ODATANO/branch/main/graph/badge.svg)](https://codecov.io/gh/ODATANO/ODATANO)
16
+ [![npm version](https://img.shields.io/npm/v/@odatano/core?logo=npm)](https://www.npmjs.com/package/@odatano/core)
17
+ [![npm downloads](https://img.shields.io/npm/dt/@odatano/core?logo=npm&label=downloads&color=blue)](https://www.npmjs.com/package/@odatano/core)
18
+ [![License](https://img.shields.io/badge/license-Apache%202.0-yellow)](LICENSE)
19
+
20
+
21
+ ## Quick Start
22
+
23
+ ### As CAP Plugin (recommended)
24
+
25
+ Add ODATANO to any existing SAP CAP project:
26
+
27
+ ```bash
28
+ npm install @odatano/core @cap-js/sqlite
29
+ ```
30
+
31
+ ```json
32
+ {
33
+ "cds": {
34
+ "requires": {
35
+ "db": { "kind": "sqlite" },
36
+ "odatano-core": {
37
+ "network": "preview",
38
+ "backends": ["blockfrost"]
39
+ }
40
+ }
41
+ }
42
+ }
43
+ ```
44
+
45
+ Put your API key in a `.env` file in the project root (loaded automatically by `cds serve` / `cds watch`) — don't commit it to `package.json`:
46
+
47
+ ```bash
48
+ # .env
49
+ BLOCKFROST_API_KEY=preview_your_api_key_here
50
+ ```
51
+
52
+ ```bash
53
+ cds deploy --to sqlite
54
+ cds serve
55
+ ```
56
+
57
+ > Config in `cds.requires.odatano-core` takes precedence over environment
58
+ > variables; a `blockfrostApiKey` set there would override the `.env` value.
59
+
60
+ > **Self-hosted Blockfrost-compatible node?** (Dolos MiniBF, Demeter Self-Hosted)
61
+ > Set `blockfrostCustomBackend` to the node's base URL (e.g. `http://localhost:3010/api/v0`).
62
+ > When set, `blockfrostApiKey` becomes optional. See the [Backend Configuration Guide](docs/guides/BACKEND_CONFIGURATION.md#self-hosted-blockfrost-compatible-backends).
63
+
64
+ ### Standalone
65
+
66
+ Run ODATANO as a self-contained service (no host CAP project needed):
67
+
68
+ ```bash
69
+ git clone https://github.com/ODATANO/ODATANO && cd ODATANO
70
+ npm ci
71
+ cp .env.example .env # set BLOCKFROST_API_KEY, NETWORK, BACKENDS
72
+ cds deploy --to sqlite
73
+ cds serve
74
+ ```
75
+
76
+ Or with Docker — this brings up a local **cardano-node + Ogmios + ODATANO** stack
77
+ (Preview), with the service pre-wired to the local Ogmios backend:
78
+
79
+ ```bash
80
+ docker compose up -d # full stack
81
+ docker compose up -d cardano-node ogmios # just the chain backend (pre-sync)
82
+ docker compose logs -f ogmios # watch sync (/health: 202 syncing, 200 near tip)
83
+ ```
84
+
85
+ > First sync from genesis takes hours; the node DB persists in a Docker volume so
86
+ > restarts resume. Until Ogmios catches up, historical queries fall back to
87
+ > Blockfrost (set `BLOCKFROST_API_KEY`).
88
+
89
+ Service available at `http://localhost:4004`. See the [Quick Start Guide](docs/QUICK_START.md#local-ogmios--cardano-node-docker) for the local Ogmios stack and full details.
90
+
91
+ ## Dev Mode: Mocked Authentication
92
+
93
+ > **Heads-up.** `cds serve` uses CAP's mocked auth: `@requires: 'authenticated-user'` accepts any Basic-Auth header against a mock user (`alice`, `bob`, …) — passwords are not checked. Anonymous requests get 401, but anyone reaching the port can authenticate.
94
+ >
95
+ > Production needs the `[production]` profile (`NODE_ENV=production`), which switches to `auth: xsuaa`. Don't expose a dev-mode instance. See the [Security Guide](docs/guides/SECURITY_GUIDE.md#authentication-xsuaa).
96
+ >
97
+ > The Docker image runs `NODE_ENV=production` with HTTP basic auth via `@odatano/cap-auth` (`ODATANO_HTTP_PASSWORD` required, user `ODATANO_HTTP_USER` default `odatano`, roles `ODATANO_HTTP_ROLES` default `Admin`; 20 failed attempts per 15 min per client address and user, then 429). `ODATANO_AUTH=dummy` disables authentication for local testing only. `getLiveness()` and `VerifyDataSignature` stay anonymous.
98
+ >
99
+ > Database of the image: `ODATANO_DB_URL=postgres://user:pw@host:5432/db` selects PostgreSQL (schema deployed on every boot); otherwise SQLite at `ODATANO_DB_PATH` (default `/data/db.sqlite`). `docker compose run --rm --no-deps odatano migrate --from /data/db.sqlite` copies an existing SQLite file into a freshly deployed PostgreSQL.
100
+
101
+ ## Services
102
+
103
+ | Service | Path | Purpose |
104
+ |---|---|---|
105
+ | CardanoODataService | `/odata/v4/cardano-odata/` | Read blockchain data (29 entities, 19 actions) |
106
+ | CardanoTransactionService | `/odata/v4/cardano-transaction/` | Build & submit transactions (13 actions) |
107
+ | CardanoSignService | `/odata/v4/cardano-sign/` | External signing + HSM (9 actions) |
108
+ | CardanoIndexerService | `/odata/v4/cardano-indexer/` | Chain crawler / pre-sync control (v2.0, off by default) |
109
+ | CardanoWorkerService | `/odata/v4/cardano-worker/` | Asynchronous wallet jobs (v2.0, off by default) |
110
+ | CardanoAgentService | `/odata/v4/cardano-agent/` | Agent grants: scoped bearer tokens for agents (v2.0, off by default) |
111
+
112
+ Both v2.0 services also publish **CAP events**, so a consumer can subscribe instead of polling —
113
+ in-process, no broker required:
114
+
115
+ ```js
116
+ (await cds.connect.to('CardanoWorkerService')).on('jobConfirmed', ({ data }) => …)
117
+ (await cds.connect.to('CardanoIndexerService')).on('blockIndexed', ({ data }) => …)
118
+ ```
119
+
120
+ ## Agent grants (v2.0, off by default)
121
+
122
+ Hand an agent a **scoped, budgeted token** instead of a user.
123
+
124
+ ```bash
125
+ AGENT_GRANTS_ENABLED=true # or cds.requires.odatano-core.agentGrants.enabled
126
+ AGENT_GRANTS_DELEGATE=mocked # CAP auth kind that keeps authenticating non-token requests (default: configured kind)
127
+ AGENT_GRANT_ADMIN_RATE_LIMIT=10 # grant administration calls per principal per hour (or agentGrants.adminRateLimit)
128
+ AGENT_TOKEN_CACHE_MS=10000 # a resolved token is reused this long before the row is read again; 0 = off (or agentGrants.tokenCacheMs)
129
+ ```
130
+
131
+ 1. An **Admin** issues a grant (`POST /odata/v4/cardano-agent/CreateAgentGrant`): an allow list of
132
+ actions, optionally a worker `walletId` (required for `SubmitWalletJob`/`CancelJob`), allowed job
133
+ kinds, a daily budget and an expiry. The response carries the token `odat_…` **once**; the
134
+ server stores only its SHA-256.
135
+ 2. The agent sends `x-agent-token: odat_…` on any of the six service paths. It runs as the principal
136
+ `agent:<grantId>` with the single role `agent-grant`, never as the operator: every
137
+ `@requires: 'Admin'` surface (pause/resume, HSM signing, grant administration) refuses it by
138
+ construction. Reads and compute-only actions are always allowed; allow-listed actions each cost
139
+ one budget unit per UTC day (a build is the service an agent buys); everything else is 403.
140
+ Wallet jobs are pinned to the grant's wallet and visible only to the grant that queued them.
141
+ 3. `GET /odata/v4/cardano-agent/GetGrantStatus()` tells the agent what it may do and how much budget
142
+ is left; `RevokeAgentGrant` turns the token into an unknown token immediately.
143
+ 4. Lifecycle (Admin; the same semantics as the gateway's peer services, so one client drives
144
+ them all): `UpdateAgentGrant` changes label, allow list, job kinds, daily budget or expiry
145
+ (absent = untouched, explicit `null` = cleared; the wallet binding is immutable, 409
146
+ `GRANT_REVOKED` on a revoked grant); `RotateAgentGrantToken` returns a fresh token once, the old
147
+ one is unknown from the next request; `GetGrantUsage(grantId, since, until)` lists admitted calls
148
+ per service and action over up to 366 days (an Admin for any grant, a token for its own). All
149
+ administration calls share the per-principal hourly rate limit above.
150
+
151
+ Grantable: `Build*`, `SetCollateral`, `CreateSigningRequest`, `VerifySignature`, `Submit*`,
152
+ `CheckSubmissionStatus`, `SubmitWalletJob`, `CancelJob`. Never: `SignWithHsm*`, `Pause*`/`Resume*`,
153
+ `pauseCrawler`/`resumeCrawler`, grant administration.
154
+
155
+ Programmatic seams for other packages (`@odatano/x402` sells grants against a 402 payment):
156
+ `issueAgentGrant()`, `updateAgentGrant()`, `rotateAgentGrantToken()`, `revokeAgentGrantById()`,
157
+ `getGrantUsage()`, `registerTransportLane()` from `@odatano/core`.
158
+
159
+ ## Liveness probe
160
+
161
+ `GET /odata/v4/cardano-indexer/getLiveness()` answers `200 { status: "alive", timestamp, uptime,
162
+ version, network }` **without credentials** (`@requires: 'any'`) as long as the process runs — no
163
+ backend or DB probe, no secrets. The Docker `HEALTHCHECK`, compose and upstream probes use it
164
+ instead of the service document, so a wrong operator password no longer reads as "ODATANO down".
165
+ Readiness (crawler, worker, backends) stays authenticated: `getStatus()`, `GetWorkerStatus()`,
166
+ `GetNetworkInformation`.
167
+
168
+ ## Requirements
169
+
170
+ - **Node.js >= 22.5** and **@sap/cds >= 10** (peer dependency). CAP 9 hosts cannot load `@odatano/core@2`.
171
+ - Upgrading a consumer from 1.x: run **`cds deploy`**. 2.0 adds six tables (`CardanoSyncState`,
172
+ `CardanoReorgLog`, `CardanoWorkerWallets`, `CardanoWalletJobs`, `CardanoAgentGrants`,
173
+ `CardanoAgentGrantUsage`) plus a `dedupKey` column; without the redeploy the new services answer
174
+ `no such table` while the old ones keep working.
175
+
176
+ ## Documentation
177
+
178
+ | Guide | Description |
179
+ |-------|-------------|
180
+ | [Quick Start](docs/QUICK_START.md) | Get running in 5 minutes |
181
+ | [User Guide](docs/guides/USER_GUIDE.md) | API usage, entities, and examples |
182
+ | [Developer Guide](docs/guides/DEVELOPER_GUIDE.md) | Architecture and development |
183
+ | [Transaction Workflow](docs/guides/TRANSACTION_WORKFLOW.md) | Build → Sign → Submit flow |
184
+ | [Security Guide](docs/guides/SECURITY_GUIDE.md) | Authentication, signing security, HSM |
185
+ | [Docker Deployment](docs/guides/DOCKER_DEPLOYMENT.md) | Container deployment |
186
+
187
+ ## License
188
+
189
+ Apache License 2.0 - see [LICENSE](LICENSE)
190
+
191
+ ## Support
192
+
193
+ - **Issues**: [GitHub Issues](https://github.com/ODATANO/ODATANO/issues)
194
+ - **Project Lead**: Max Weber
195
+ - **Contact**: info@odatano.dev
package/db/schema.cds CHANGED
@@ -1,5 +1,5 @@
1
1
  using {temporal, } from '@sap/cds/common';
2
- using {Lovelace, Blake2b224, Blake2b256, HexBytes, Bech32, AssetUnit, AssetSlice, SigningStatus,SubmissionStatus, UTxODataSlice, MetadataLabel, CrawlSyncStatus, ReorgStatus, WalletJobStatus, WalletJobKind, WorkerSignerType} from '../db/types';
2
+ using {Lovelace, Blake2b224, Blake2b256, HexBytes, Bech32, AssetUnit, AssetSlice, AssetSumSlice, SigningStatus,SubmissionStatus, UTxODataSlice, MetadataLabel, CrawlSyncStatus, ReorgStatus, WalletJobStatus, WalletJobKind, WorkerSignerType} from '../db/types';
3
3
 
4
4
  namespace odatano.cardano;
5
5
 
@@ -601,7 +601,7 @@ entity AddressAssets : temporal {
601
601
 
602
602
  @title : 'Asset Details'
603
603
  @description: 'Structural slice for asset details'
604
- asset : AssetSlice;
604
+ asset : AssetSumSlice;
605
605
  }
606
606
 
607
607
  @title : 'Address UTxOs'
@@ -1021,7 +1021,7 @@ entity LedgerAddressAssets {
1021
1021
 
1022
1022
  @title : 'Asset'
1023
1023
  @description: 'Quantity and decomposed unit'
1024
- asset : AssetSlice;
1024
+ asset : AssetSumSlice;
1025
1025
  }
1026
1026
 
1027
1027
  @title : 'Ledger Accounts'
@@ -1111,6 +1111,48 @@ entity TransactionWithdrawals {
1111
1111
  lovelace : Lovelace;
1112
1112
  }
1113
1113
 
1114
+ @title : 'Transaction Redeemers'
1115
+ @description: 'Redeemers of a transaction as the chain crawler saw them (Ogmios chain-sync). A spend redeemer names the redeemed input, a mint redeemer the policy. Not written by the lazy path.'
1116
+ @readonly
1117
+ entity TransactionRedeemers {
1118
+
1119
+ @title : 'Transaction (key)'
1120
+ @description: 'The transaction carrying the redeemer'
1121
+ key tx : Association to Transactions;
1122
+
1123
+ @title : 'Purpose (key)'
1124
+ @description: 'spend | mint | publish | withdraw | vote | propose'
1125
+ key purpose : String(10);
1126
+
1127
+ @title : 'Redeemer Index (key)'
1128
+ @description: 'Index within its purpose (spend: position of the input in the sorted inputs; mint: of the policy in the sorted policies)'
1129
+ key redeemerIndex : Integer;
1130
+
1131
+ @title : 'Data'
1132
+ @description: 'Redeemer data as PlutusData CBOR hex'
1133
+ data : LargeString;
1134
+
1135
+ @title : 'Memory Units'
1136
+ @description: 'Execution memory units'
1137
+ mem : Integer64;
1138
+
1139
+ @title : 'CPU Steps'
1140
+ @description: 'Execution CPU steps'
1141
+ steps : Integer64;
1142
+
1143
+ @title : 'Redeemed Input Transaction'
1144
+ @description: 'spend: transaction that created the redeemed input'
1145
+ spentTxHash : Blake2b256;
1146
+
1147
+ @title : 'Redeemed Input Index'
1148
+ @description: 'spend: output index of the redeemed input'
1149
+ spentOutputIndex : Integer;
1150
+
1151
+ @title : 'Policy ID'
1152
+ @description: 'mint: the policy the redeemer runs'
1153
+ policyId : Blake2b224;
1154
+ }
1155
+
1114
1156
  @title : 'Transaction Outputs'
1115
1157
  @description: 'Projection for Transaction Outputs'
1116
1158
  @readonly
@@ -1391,6 +1433,10 @@ entity TransactionBuilds : temporal {
1391
1433
  @description: 'The outputs created in the transaction build'
1392
1434
  outputs : Composition of many TransactionBuildOutputs
1393
1435
  on outputs.build = $self;
1436
+ @title : 'Redeemers'
1437
+ @description: 'Redeemers of a script build with the execution units stamped on them'
1438
+ redeemers : Composition of many TransactionBuildRedeemers
1439
+ on redeemers.build = $self;
1394
1440
 
1395
1441
  @title : 'Associated Submission'
1396
1442
  @description: 'Association to the transaction submission if submitted'
@@ -1527,6 +1573,31 @@ entity TransactionBuildOutputs {
1527
1573
  hasAssets : Boolean;
1528
1574
  }
1529
1575
 
1576
+ @title : 'Transaction Build Redeemers'
1577
+ @description: 'Redeemers of a script build (spend, mint, …) with the execution units stamped on them; compare with maxTxExecutionUnits of the protocol parameters'
1578
+ entity TransactionBuildRedeemers {
1579
+
1580
+ @title : 'Build (key)'
1581
+ @description: 'Association to parent transaction build'
1582
+ key build : Association to TransactionBuilds;
1583
+
1584
+ @title : 'Tag (key)'
1585
+ @description: 'Redeemer purpose: Spend, Mint, Cert, Withdraw, Vote or Propose'
1586
+ key tag : String(10);
1587
+
1588
+ @title : 'Redeemer Index (key)'
1589
+ @description: 'Index within its purpose (spend: position of the input in the sorted inputs)'
1590
+ key redeemerIndex : Integer;
1591
+
1592
+ @title : 'Memory Units'
1593
+ @description: 'Execution memory units stamped on the redeemer'
1594
+ mem : Integer64;
1595
+
1596
+ @title : 'CPU Steps'
1597
+ @description: 'Execution CPU steps stamped on the redeemer'
1598
+ steps : Integer64;
1599
+ }
1600
+
1530
1601
  @title : 'Transaction Build Output Assets'
1531
1602
  @description: 'Entity for storing assets associated with transaction build outputs'
1532
1603
  entity TransactionBuildOutputAssets {
package/db/types.cds CHANGED
@@ -16,6 +16,8 @@ type HexBytes : String(5000);
16
16
  @title : 'Lovelace'
17
17
  @description: 'Amount of ADA in lovelace (1 ADA = 1_000_000 lovelace)'
18
18
  type Lovelace : Decimal(20, 0);
19
+ // Sum of asset quantities: one output holds at most 2^64-1, a sum over an address's outputs does not
20
+ type AssetAmount : Decimal(38, 0);
19
21
 
20
22
  @title : 'Asset Unit'
21
23
  @description: 'Concatenation of policyId and assetNameHex representing a unique asset'
@@ -57,6 +59,31 @@ type AssetSlice {
57
59
  fingerprint : String(44);
58
60
  }
59
61
 
62
+ @title : 'Asset Sum Slice'
63
+ @description: 'Asset details with the quantity summed over several outputs (per address)'
64
+ type AssetSumSlice {
65
+
66
+ @title : 'Asset Quantity'
67
+ @description: 'Quantity of the Asset summed over the outputs of the address'
68
+ quantity : AssetAmount;
69
+
70
+ @title : 'Asset Policy Id'
71
+ @description: 'Policy Id of the Asset'
72
+ policyId : Blake2b224;
73
+
74
+ @title : 'Asset Name Hex'
75
+ @description: 'Asset Name as Hex String'
76
+ assetNameHex : HexBytes;
77
+
78
+ @title : 'Asset Name'
79
+ @description: 'Asset Name as UTF-8 String'
80
+ assetName : String(128);
81
+
82
+ @title : 'Asset Fingerprint'
83
+ @description: 'CIP-14 Asset Fingerprint'
84
+ fingerprint : String(44);
85
+ }
86
+
60
87
  @title : 'Metadata Slice'
61
88
  @description: 'Structural slice for metadata details'
62
89
  type MetadataSlice {