@odatano/core 2.0.0-rc.5 → 2.0.0-rc.7
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.
- package/@cds-models/CardanoAgentService/index.d.ts +107 -3
- package/@cds-models/CardanoAgentService/index.js +15 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +37 -2
- package/@cds-models/CardanoIndexerService/index.js +4 -0
- package/@cds-models/CardanoSignService/index.d.ts +5 -2
- package/@cds-models/odatano/cardano/index.d.ts +36 -0
- package/@cds-models/odatano/cardano/index.js +3 -0
- package/README.md +185 -167
- package/db/schema.cds +33 -0
- package/package.json +6 -2
- package/src/index.d.ts +2 -2
- package/src/index.js +5 -1
- package/srv/blockchain/backends/ogmios-backend.d.ts +23 -3
- package/srv/blockchain/backends/ogmios-backend.js +72 -5
- package/srv/cardano-agent-service.cds +69 -3
- package/srv/cardano-indexer-service.cds +106 -73
- package/srv/cardano-indexer-service.js +3 -0
- package/srv/cardano-sign-service.cds +200 -180
- package/srv/utils/agent-grants-config.d.ts +17 -1
- package/srv/utils/agent-grants-config.js +22 -2
- package/srv/utils/agent-grants.d.ts +111 -8
- package/srv/utils/agent-grants.js +342 -62
- package/srv/utils/liveness.d.ts +23 -0
- package/srv/utils/liveness.js +49 -0
|
@@ -6,16 +6,24 @@ using {odatano.cardano as db} from '../db/schema';
|
|
|
6
6
|
* Agent grants: scoped, budgeted bearer capabilities an Admin hands to an agent
|
|
7
7
|
* instead of a full user (see AGENT_GRANTS_DESIGN.md).
|
|
8
8
|
*
|
|
9
|
-
* - CreateAgentGrant /
|
|
10
|
-
*
|
|
9
|
+
* - CreateAgentGrant / UpdateAgentGrant / RotateAgentGrantToken / RevokeAgentGrant:
|
|
10
|
+
* Admin-only administration, rate limited per principal per hour
|
|
11
|
+
* (AGENT_GRANT_ADMIN_RATE_LIMIT, default 10). The token is returned ONCE from
|
|
12
|
+
* CreateAgentGrant and RotateAgentGrantToken and stored as SHA-256 only.
|
|
11
13
|
* - AgentGrants: Admin-only projection (no token hash). A request carrying a token
|
|
12
14
|
* runs as the principal `agent:<grantId>` with the role `agent-grant` and sees
|
|
13
15
|
* exactly its own row through the row-level restriction below.
|
|
14
16
|
* - GetGrantStatus: token self-service — what am I allowed to do, how much budget
|
|
15
17
|
* is left, when do I expire. What an MCP tool needs to describe itself honestly.
|
|
18
|
+
* - GetGrantUsage: admitted calls per service and action over a window — an Admin
|
|
19
|
+
* for any grant, a token for its own (a partner usage view, ledger reconciliation).
|
|
20
|
+
*
|
|
21
|
+
* Names are this repo's PascalCase; semantics mirror NIGHTGATE's agent grants
|
|
22
|
+
* (createAgentGrant / updateAgentGrant / rotateAgentGrantToken / revokeAgentGrant /
|
|
23
|
+
* getGrantUsage), so a gateway drives both products with one code path.
|
|
16
24
|
*
|
|
17
25
|
* A token request never inherits the operator's roles: `@requires: 'Admin'` on the
|
|
18
|
-
*
|
|
26
|
+
* four actions, on PauseWorker / ResumeWorker / pauseCrawler / resumeCrawler and on
|
|
19
27
|
* every other Admin surface therefore refuses it by construction. The allow list,
|
|
20
28
|
* wallet pinning and daily budget are enforced by a before('*') hook on all six
|
|
21
29
|
* ODATANO services (srv/utils/agent-grants.ts). The `x-agent-token` header only
|
|
@@ -81,4 +89,62 @@ service CardanoAgentService @(impl: './cardano-agent-service') {
|
|
|
81
89
|
action RevokeAgentGrant(
|
|
82
90
|
@title: 'Grant Id' grantId : UUID
|
|
83
91
|
) returns Boolean;
|
|
92
|
+
|
|
93
|
+
@title : 'Rotated Grant'
|
|
94
|
+
type RotatedGrant {
|
|
95
|
+
grantId : UUID;
|
|
96
|
+
token : String; // shown once, never stored
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@title : 'Rotate Agent Grant Token'
|
|
100
|
+
@description: 'Replace the grant token; the old token is unknown from the next request. Budget, wallet, allow list and expiry survive. Admin only. 404 when the grant does not exist or is revoked.'
|
|
101
|
+
@requires : 'Admin'
|
|
102
|
+
action RotateAgentGrantToken(
|
|
103
|
+
@title: 'Grant Id' grantId : UUID
|
|
104
|
+
) returns RotatedGrant;
|
|
105
|
+
|
|
106
|
+
@title : 'Updated Grant'
|
|
107
|
+
type UpdatedGrant {
|
|
108
|
+
grantId : UUID;
|
|
109
|
+
updated : many String; // parameter names that were applied
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@title : 'Update Agent Grant'
|
|
113
|
+
@description: 'Change label, allow list, job kinds, daily budget or expiry of an active grant. An absent parameter stays as it is; an explicit null clears agentLabel, allowedJobKinds, maxJobsPerDay or validUntil. allowedActions cannot be emptied; the wallet binding is immutable (issue a new grant). Admin only. 404 unknown grant, 409 GRANT_REVOKED.'
|
|
114
|
+
@requires : 'Admin'
|
|
115
|
+
action UpdateAgentGrant(
|
|
116
|
+
@title: 'Grant Id' grantId : UUID,
|
|
117
|
+
@title: 'Agent Label' agentLabel : String(100),
|
|
118
|
+
@title: 'Allowed Actions' allowedActions : many String,
|
|
119
|
+
@title: 'Allowed Job Kinds' allowedJobKinds : many String,
|
|
120
|
+
@title: 'Max Jobs Per Day' maxJobsPerDay : Integer,
|
|
121
|
+
@title: 'Valid Until' validUntil : Timestamp
|
|
122
|
+
) returns UpdatedGrant;
|
|
123
|
+
|
|
124
|
+
@title : 'Grant Usage Call'
|
|
125
|
+
type GrantUsageCall {
|
|
126
|
+
service : String(60); // CardanoTransactionService, CardanoSignService, ...
|
|
127
|
+
action : String(100); // BuildSimpleAdaTransaction, SubmitTransaction, ...
|
|
128
|
+
count : Integer; // admitted and kept (budget charged and not refunded)
|
|
129
|
+
refunded : Integer; // admitted, then refunded because the handler refused the input
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@title : 'Grant Usage'
|
|
133
|
+
type GrantUsage {
|
|
134
|
+
grantId : UUID;
|
|
135
|
+
since : Timestamp;
|
|
136
|
+
until : Timestamp;
|
|
137
|
+
calls : many GrantUsageCall;
|
|
138
|
+
total : Integer;
|
|
139
|
+
jobsUsedToday : Integer;
|
|
140
|
+
maxJobsPerDay : Integer;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@title : 'Get Grant Usage'
|
|
144
|
+
@description: 'Admitted calls under a grant between since (default until - 30 days) and until (default now), at most 366 days, per UTC day, grouped by service and action. An Admin sees any grant (revoked ones keep their history); a token sees only its own.'
|
|
145
|
+
function GetGrantUsage(
|
|
146
|
+
@title: 'Grant Id' grantId : UUID,
|
|
147
|
+
@title: 'Since' since : Timestamp,
|
|
148
|
+
@title: 'Until' until : Timestamp
|
|
149
|
+
) returns GrantUsage;
|
|
84
150
|
}
|
|
@@ -1,73 +1,106 @@
|
|
|
1
|
-
using {odatano.cardano as db} from '../db/schema';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Cardano Indexer Service (v2.0)
|
|
5
|
-
*
|
|
6
|
-
* Control + observability surface for the chain crawler / pre-sync engine:
|
|
7
|
-
* - read-only projections of the sync cursor and reorg audit log
|
|
8
|
-
* - status function + pause/resume actions delegating to the crawler singleton
|
|
9
|
-
*
|
|
10
|
-
* Security note: see CardanoODataService (cardano-service.cds) for the rationale on
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
@requires:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
@
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
@
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
1
|
+
using {odatano.cardano as db} from '../db/schema';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cardano Indexer Service (v2.0)
|
|
5
|
+
*
|
|
6
|
+
* Control + observability surface for the chain crawler / pre-sync engine:
|
|
7
|
+
* - read-only projections of the sync cursor and reorg audit log
|
|
8
|
+
* - status function + pause/resume actions delegating to the crawler singleton
|
|
9
|
+
*
|
|
10
|
+
* Security note: see CardanoODataService (cardano-service.cds) for the rationale on
|
|
11
|
+
* auth. pause/resume are operational actions — gate behind a dedicated Admin scope.
|
|
12
|
+
* Read-only status and audit data remain available to authenticated users.
|
|
13
|
+
*
|
|
14
|
+
* Deliberately NO service-level @requires: CAP checks a service-level requirement
|
|
15
|
+
* on every request BEFORE the operation's own annotation, so an operation-level
|
|
16
|
+
* `@requires: 'any'` can never open a single function on an otherwise
|
|
17
|
+
* authenticated service (anonymous callers get the 401 challenge first). The
|
|
18
|
+
* requirement therefore sits on each element, and getLiveness() alone is 'any' —
|
|
19
|
+
* the same layout as NIGHTGATE's indexer service.
|
|
20
|
+
*/
|
|
21
|
+
// Service-level 'any' on purpose: CAP authorizes the service BEFORE the operation and
|
|
22
|
+
// treats a service without a service-level @requires as authenticated-user under
|
|
23
|
+
// NODE_ENV=production, which would 401 the anonymous operation below despite its own
|
|
24
|
+
// 'any'. Every element carries its requirement; the service itself refuses nothing.
|
|
25
|
+
@requires: 'any'
|
|
26
|
+
service CardanoIndexerService @(impl: './cardano-indexer-service') {
|
|
27
|
+
|
|
28
|
+
@readonly
|
|
29
|
+
@requires : 'authenticated-user'
|
|
30
|
+
@title : 'Sync State'
|
|
31
|
+
@description: 'Singleton crawl cursor — pre-sync progress, tip lag, status, errors'
|
|
32
|
+
entity SyncState as projection on db.CardanoSyncState;
|
|
33
|
+
|
|
34
|
+
@readonly
|
|
35
|
+
@requires : 'authenticated-user'
|
|
36
|
+
@title : 'Reorg Log'
|
|
37
|
+
@description: 'Audit trail of chain rollbacks handled by the crawler'
|
|
38
|
+
entity ReorgLog as projection on db.CardanoReorgLog;
|
|
39
|
+
|
|
40
|
+
@title : 'Crawler Status'
|
|
41
|
+
@description: 'Live crawler status summary (numeric fields as strings, CAP-10 aligned)'
|
|
42
|
+
type CrawlerStatus {
|
|
43
|
+
running : Boolean;
|
|
44
|
+
syncStatus : String;
|
|
45
|
+
lastSlot : String;
|
|
46
|
+
lastHeight : String;
|
|
47
|
+
tipHeight : String;
|
|
48
|
+
syncProgress : String;
|
|
49
|
+
consecutiveErrors : Integer;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@title : 'Get Crawler Status'
|
|
53
|
+
@description: 'Return the current crawler run state and sync progress'
|
|
54
|
+
/**
|
|
55
|
+
* Emitted AFTER each block is committed. Subscribe instead of polling:
|
|
56
|
+
* (await cds.connect.to('CardanoIndexerService')).on('blockIndexed', ({ data }) => …)
|
|
57
|
+
* In-process (plugin mode) this needs no messaging service.
|
|
58
|
+
*/
|
|
59
|
+
event blockIndexed {
|
|
60
|
+
hash : String(64);
|
|
61
|
+
slot : Integer64;
|
|
62
|
+
height : Integer64;
|
|
63
|
+
txHashes : many String(64);
|
|
64
|
+
tipSlot : Integer64;
|
|
65
|
+
tipHeight: Integer64;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Emitted AFTER a rollback is committed. Everything above `forkSlot` was removed. */
|
|
69
|
+
event reorg {
|
|
70
|
+
forkSlot : Integer64;
|
|
71
|
+
forkHeight : Integer64;
|
|
72
|
+
blocksRolledBack : Integer;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@requires : 'authenticated-user'
|
|
76
|
+
function getStatus() returns CrawlerStatus;
|
|
77
|
+
|
|
78
|
+
@title : 'Liveness'
|
|
79
|
+
type Liveness {
|
|
80
|
+
status : String; // 'alive'
|
|
81
|
+
timestamp : Timestamp;
|
|
82
|
+
uptime : Integer; // seconds since process start
|
|
83
|
+
version : String; // @odatano/core version
|
|
84
|
+
network : String; // configured network
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Anonymous on purpose: a liveness probe carries no credentials. 200 as long
|
|
88
|
+
// as the process answers — no backend or DB probe, no secrets, no backend
|
|
89
|
+
// names, no API key state. Readiness stays with getStatus and the worker
|
|
90
|
+
// status, which remain authenticated. Mirrors NIGHTGATE's
|
|
91
|
+
// `/api/v1/indexer/getLiveness()`, so a gateway probes both products the same way.
|
|
92
|
+
@title : 'Get Liveness'
|
|
93
|
+
@description: 'Unauthenticated liveness probe: 200 while the process answers. Docker HEALTHCHECK and upstream probes use this instead of the service document.'
|
|
94
|
+
@requires : 'any'
|
|
95
|
+
function getLiveness() returns Liveness;
|
|
96
|
+
|
|
97
|
+
@title : 'Pause Crawler'
|
|
98
|
+
@description: 'Stop the crawler (closes the chain-sync stream). Resume continues from the cursor.'
|
|
99
|
+
@requires : 'Admin'
|
|
100
|
+
action pauseCrawler() returns Boolean;
|
|
101
|
+
|
|
102
|
+
@title : 'Resume Crawler'
|
|
103
|
+
@description: 'Start/restart the crawler from the persisted cursor using the configured source.'
|
|
104
|
+
@requires : 'Admin'
|
|
105
|
+
action resumeCrawler() returns Boolean;
|
|
106
|
+
}
|
|
@@ -9,6 +9,7 @@ const errors_1 = require("./utils/errors");
|
|
|
9
9
|
const crawler_1 = require("./blockchain/crawler");
|
|
10
10
|
const sync_state_1 = require("./blockchain/crawler/sync-state");
|
|
11
11
|
const server_1 = require("./server");
|
|
12
|
+
const liveness_1 = require("./utils/liveness");
|
|
12
13
|
const logger = cds_1.default.log('CardanoIndexerService');
|
|
13
14
|
/**
|
|
14
15
|
* CardanoIndexerService handlers — thin control/observability surface over the crawler
|
|
@@ -16,6 +17,8 @@ const logger = cds_1.default.log('CardanoIndexerService');
|
|
|
16
17
|
* cursor and starts/stops the crawler.
|
|
17
18
|
*/
|
|
18
19
|
module.exports = (srv) => {
|
|
20
|
+
// getLiveness — unauthenticated probe (@requires: 'any'); no handleRequest, no app context.
|
|
21
|
+
srv.on('getLiveness', async () => (0, liveness_1.buildLiveness)());
|
|
19
22
|
// getStatus — live run state + sync progress (numeric fields as strings, CAP-10 aligned)
|
|
20
23
|
srv.on('getStatus', async (req) => {
|
|
21
24
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|