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

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 (35) hide show
  1. package/@cds-models/CardanoAgentService/index.d.ts +255 -0
  2. package/@cds-models/CardanoAgentService/index.js +36 -0
  3. package/@cds-models/CardanoIndexerService/index.d.ts +28 -0
  4. package/@cds-models/CardanoIndexerService/index.js +4 -0
  5. package/@cds-models/odatano/cardano/index.d.ts +86 -0
  6. package/@cds-models/odatano/cardano/index.js +6 -0
  7. package/README.md +53 -3
  8. package/db/schema.cds +105 -0
  9. package/package.json +4 -3
  10. package/src/index.d.ts +6 -0
  11. package/src/index.js +21 -1
  12. package/src/plugin.js +33 -30
  13. package/srv/blockchain/backends/ogmios-backend.d.ts +23 -3
  14. package/srv/blockchain/backends/ogmios-backend.js +72 -5
  15. package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +32 -1
  16. package/srv/blockchain/wallet-worker/confirmation-tracker.js +91 -29
  17. package/srv/blockchain/wallet-worker/job-store.d.ts +11 -0
  18. package/srv/blockchain/wallet-worker/job-store.js +42 -9
  19. package/srv/cardano-agent-service.cds +150 -0
  20. package/srv/cardano-agent-service.d.ts +2 -0
  21. package/srv/cardano-agent-service.js +16 -0
  22. package/srv/cardano-indexer-service.cds +20 -0
  23. package/srv/cardano-indexer-service.js +3 -0
  24. package/srv/server.d.ts +2 -1
  25. package/srv/server.js +12 -0
  26. package/srv/utils/agent-grants-config.d.ts +64 -0
  27. package/srv/utils/agent-grants-config.js +144 -0
  28. package/srv/utils/agent-grants.d.ts +314 -0
  29. package/srv/utils/agent-grants.js +821 -0
  30. package/srv/utils/agent-token-auth.d.ts +106 -0
  31. package/srv/utils/agent-token-auth.js +239 -0
  32. package/srv/utils/liveness.d.ts +23 -0
  33. package/srv/utils/liveness.js +49 -0
  34. package/srv/utils/rate-limiter.d.ts +57 -0
  35. package/srv/utils/rate-limiter.js +126 -0
@@ -0,0 +1,255 @@
1
+ // This is an automatically generated file. Please do not change its contents manually!
2
+ import * as __ from './../_';
3
+
4
+ /**
5
+ * Cardano Agent Service (v2.0)
6
+ *
7
+ * Agent grants: scoped, budgeted bearer capabilities an Admin hands to an agent
8
+ * instead of a full user (see AGENT_GRANTS_DESIGN.md).
9
+ *
10
+ * - CreateAgentGrant / UpdateAgentGrant / RotateAgentGrantToken / RevokeAgentGrant:
11
+ * Admin-only administration, rate limited per principal per hour
12
+ * (AGENT_GRANT_ADMIN_RATE_LIMIT, default 10). The token is returned ONCE from
13
+ * CreateAgentGrant and RotateAgentGrantToken and stored as SHA-256 only.
14
+ * - AgentGrants: Admin-only projection (no token hash). A request carrying a token
15
+ * runs as the principal `agent:<grantId>` with the role `agent-grant` and sees
16
+ * exactly its own row through the row-level restriction below.
17
+ * - GetGrantStatus: token self-service — what am I allowed to do, how much budget
18
+ * is left, when do I expire. What an MCP tool needs to describe itself honestly.
19
+ * - GetGrantUsage: admitted calls per service and action over a window — an Admin
20
+ * for any grant, a token for its own (a partner usage view, ledger reconciliation).
21
+ *
22
+ * Names are this repo's PascalCase; semantics mirror NIGHTGATE's agent grants
23
+ * (createAgentGrant / updateAgentGrant / rotateAgentGrantToken / revokeAgentGrant /
24
+ * getGrantUsage), so a gateway drives both products with one code path.
25
+ *
26
+ * A token request never inherits the operator's roles: `@requires: 'Admin'` on the
27
+ * four actions, on PauseWorker / ResumeWorker / pauseCrawler / resumeCrawler and on
28
+ * every other Admin surface therefore refuses it by construction. The allow list,
29
+ * wallet pinning and daily budget are enforced by a before('*') hook on all six
30
+ * ODATANO services (srv/utils/agent-grants.ts). The `x-agent-token` header only
31
+ * reaches the services when cds.requires.odatano-core.agentGrants.enabled is set
32
+ * (srv/utils/agent-token-auth.ts).
33
+ */
34
+ export default class {
35
+ static readonly GetGrantStatus: typeof GetGrantStatus;
36
+ static readonly CreateAgentGrant: typeof CreateAgentGrant;
37
+ static readonly RevokeAgentGrant: typeof RevokeAgentGrant;
38
+ static readonly RotateAgentGrantToken: typeof RotateAgentGrantToken;
39
+ static readonly UpdateAgentGrant: typeof UpdateAgentGrant;
40
+ static readonly GetGrantUsage: typeof GetGrantUsage;
41
+ }
42
+
43
+ // entity 'AgentGrant'
44
+ export declare function _AgentGrantAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
45
+ new (...args: any[]): {
46
+ ID?: __.Key<string>
47
+ userId?: string
48
+ agentLabel?: string | null
49
+ allowedActions?: string
50
+ walletId?: string | null
51
+ allowedJobKinds?: string | null
52
+ maxJobsPerDay?: number | null
53
+ jobsUsedToday?: number | null
54
+ budgetWindow?: string | null
55
+ validUntil?: __.CdsTimestamp | null
56
+ isActive?: boolean | null
57
+ revokedAt?: __.CdsTimestamp | null
58
+ createdAt?: __.CdsTimestamp | null
59
+ lastUsedAt?: __.CdsTimestamp | null
60
+ } & InstanceType<TBase>
61
+ readonly kind: 'entity';
62
+ readonly keys: __.KeysOf<AgentGrant>;
63
+ readonly elements: __.ElementsOf<AgentGrant>;
64
+ readonly actions: globalThis.Record<never, never>;
65
+ };
66
+ /**
67
+ * Agent grants (v2.0): scoped bearer capabilities an Admin hands to an agent
68
+ * instead of a full user. The token is a capability, not an identity — it is
69
+ * stored as SHA-256 only, and a request carrying it runs as the principal
70
+ * `agent:<ID>` with the role `agent-grant`, never as the operator. Enforcement
71
+ * (allow list, wallet pinning, daily budget) lives in srv/utils/agent-grants.ts;
72
+ * the transport lane that admits `x-agent-token` in srv/utils/agent-token-auth.ts.
73
+ * Admin-only table: creation and revocation happen through CardanoAgentService
74
+ * actions, a token request may read its own row only.
75
+ */
76
+ export class AgentGrant extends _AgentGrantAspect(__.Entity) {
77
+ }
78
+ /**
79
+ * Agent grants (v2.0): scoped bearer capabilities an Admin hands to an agent
80
+ * instead of a full user. The token is a capability, not an identity — it is
81
+ * stored as SHA-256 only, and a request carrying it runs as the principal
82
+ * `agent:<ID>` with the role `agent-grant`, never as the operator. Enforcement
83
+ * (allow list, wallet pinning, daily budget) lives in srv/utils/agent-grants.ts;
84
+ * the transport lane that admits `x-agent-token` in srv/utils/agent-token-auth.ts.
85
+ * Admin-only table: creation and revocation happen through CardanoAgentService
86
+ * actions, a token request may read its own row only.
87
+ */
88
+ export class AgentGrants extends Array<AgentGrant> {
89
+ $count?: number
90
+ }
91
+
92
+ // entity 'GrantStatus'
93
+ export declare function _GrantStatusAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
94
+ new (...args: any[]): {
95
+ grantId?: string | null
96
+ agentLabel?: string | null
97
+ allowedActions?: Array<string>
98
+ walletId?: string | null
99
+ allowedJobKinds?: Array<string>
100
+ maxJobsPerDay?: number | null
101
+ jobsUsedToday?: number | null
102
+ budgetWindow?: string | null
103
+ validUntil?: __.CdsTimestamp | null
104
+ isActive?: boolean | null
105
+ } & InstanceType<TBase>
106
+ readonly kind: 'type';
107
+ readonly keys: __.KeysOf<GrantStatus>;
108
+ readonly elements: __.ElementsOf<GrantStatus>;
109
+ readonly actions: globalThis.Record<never, never>;
110
+ };
111
+ export class GrantStatus extends _GrantStatusAspect(__.Entity) {
112
+ }
113
+
114
+ // entity 'IssuedGrant'
115
+ export declare function _IssuedGrantAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
116
+ new (...args: any[]): {
117
+ grantId?: string | null
118
+ token?: string | null
119
+ allowedActions?: Array<string>
120
+ walletId?: string | null
121
+ allowedJobKinds?: Array<string>
122
+ maxJobsPerDay?: number | null
123
+ validUntil?: __.CdsTimestamp | null
124
+ } & InstanceType<TBase>
125
+ readonly kind: 'type';
126
+ readonly keys: __.KeysOf<IssuedGrant>;
127
+ readonly elements: __.ElementsOf<IssuedGrant>;
128
+ readonly actions: globalThis.Record<never, never>;
129
+ };
130
+ export class IssuedGrant extends _IssuedGrantAspect(__.Entity) {
131
+ }
132
+
133
+ // entity 'RotatedGrant'
134
+ export declare function _RotatedGrantAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
135
+ new (...args: any[]): {
136
+ grantId?: string | null
137
+ token?: string | null
138
+ } & InstanceType<TBase>
139
+ readonly kind: 'type';
140
+ readonly keys: __.KeysOf<RotatedGrant>;
141
+ readonly elements: __.ElementsOf<RotatedGrant>;
142
+ readonly actions: globalThis.Record<never, never>;
143
+ };
144
+ export class RotatedGrant extends _RotatedGrantAspect(__.Entity) {
145
+ }
146
+
147
+ // entity 'UpdatedGrant'
148
+ export declare function _UpdatedGrantAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
149
+ new (...args: any[]): {
150
+ grantId?: string | null
151
+ updated?: Array<string>
152
+ } & InstanceType<TBase>
153
+ readonly kind: 'type';
154
+ readonly keys: __.KeysOf<UpdatedGrant>;
155
+ readonly elements: __.ElementsOf<UpdatedGrant>;
156
+ readonly actions: globalThis.Record<never, never>;
157
+ };
158
+ export class UpdatedGrant extends _UpdatedGrantAspect(__.Entity) {
159
+ }
160
+
161
+ // entity 'GrantUsageCall'
162
+ export declare function _GrantUsageCallAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
163
+ new (...args: any[]): {
164
+ service?: string | null
165
+ action?: string | null
166
+ count?: number | null
167
+ refunded?: number | null
168
+ } & InstanceType<TBase>
169
+ readonly kind: 'type';
170
+ readonly keys: __.KeysOf<GrantUsageCall>;
171
+ readonly elements: __.ElementsOf<GrantUsageCall>;
172
+ readonly actions: globalThis.Record<never, never>;
173
+ };
174
+ export class GrantUsageCall extends _GrantUsageCallAspect(__.Entity) {
175
+ }
176
+
177
+ // entity 'GrantUsage'
178
+ export declare function _GrantUsageAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
179
+ new (...args: any[]): {
180
+ grantId?: string | null
181
+ since?: __.CdsTimestamp | null
182
+ until?: __.CdsTimestamp | null
183
+ calls?: Array<GrantUsageCall>
184
+ total?: number | null
185
+ jobsUsedToday?: number | null
186
+ maxJobsPerDay?: number | null
187
+ } & InstanceType<TBase>
188
+ readonly kind: 'type';
189
+ readonly keys: __.KeysOf<GrantUsage>;
190
+ readonly elements: __.ElementsOf<GrantUsage>;
191
+ readonly actions: globalThis.Record<never, never>;
192
+ };
193
+ export class GrantUsage extends _GrantUsageAspect(__.Entity) {
194
+ }
195
+
196
+
197
+ export declare const GetGrantStatus: {
198
+ // positional
199
+ (): globalThis.Promise<GrantStatus | null> | GrantStatus | null
200
+ // named
201
+ ({}: globalThis.Record<never, never>): globalThis.Promise<GrantStatus | null> | GrantStatus | null
202
+ // metadata (do not use)
203
+ __parameters: globalThis.Record<never, never>, __returns: globalThis.Promise<GrantStatus | null> | GrantStatus | null, __self: never
204
+ kind: 'function'
205
+ }
206
+
207
+ export declare const CreateAgentGrant: {
208
+ // positional
209
+ (allowedActions: Array<string>, walletId: string | null, allowedJobKinds: Array<string>, maxJobsPerDay: number | null, validUntil: __.CdsTimestamp | null, agentLabel: string | null): globalThis.Promise<IssuedGrant | null> | IssuedGrant | null
210
+ // named
211
+ ({allowedActions, walletId, allowedJobKinds, maxJobsPerDay, validUntil, agentLabel}: {allowedActions?: Array<string>, walletId?: string | null, allowedJobKinds?: Array<string>, maxJobsPerDay?: number | null, validUntil?: __.CdsTimestamp | null, agentLabel?: string | null}): globalThis.Promise<IssuedGrant | null> | IssuedGrant | null
212
+ // metadata (do not use)
213
+ __parameters: {allowedActions?: Array<string>, walletId?: string | null, allowedJobKinds?: Array<string>, maxJobsPerDay?: number | null, validUntil?: __.CdsTimestamp | null, agentLabel?: string | null}, __returns: globalThis.Promise<IssuedGrant | null> | IssuedGrant | null, __self: never
214
+ kind: 'action'
215
+ }
216
+
217
+ export declare const RevokeAgentGrant: {
218
+ // positional
219
+ (grantId: string | null): globalThis.Promise<boolean | null> | boolean | null
220
+ // named
221
+ ({grantId}: {grantId?: string | null}): globalThis.Promise<boolean | null> | boolean | null
222
+ // metadata (do not use)
223
+ __parameters: {grantId?: string | null}, __returns: globalThis.Promise<boolean | null> | boolean | null, __self: never
224
+ kind: 'action'
225
+ }
226
+
227
+ export declare const RotateAgentGrantToken: {
228
+ // positional
229
+ (grantId: string | null): globalThis.Promise<RotatedGrant | null> | RotatedGrant | null
230
+ // named
231
+ ({grantId}: {grantId?: string | null}): globalThis.Promise<RotatedGrant | null> | RotatedGrant | null
232
+ // metadata (do not use)
233
+ __parameters: {grantId?: string | null}, __returns: globalThis.Promise<RotatedGrant | null> | RotatedGrant | null, __self: never
234
+ kind: 'action'
235
+ }
236
+
237
+ export declare const UpdateAgentGrant: {
238
+ // positional
239
+ (grantId: string | null, agentLabel: string | null, allowedActions: Array<string>, allowedJobKinds: Array<string>, maxJobsPerDay: number | null, validUntil: __.CdsTimestamp | null): globalThis.Promise<UpdatedGrant | null> | UpdatedGrant | null
240
+ // named
241
+ ({grantId, agentLabel, allowedActions, allowedJobKinds, maxJobsPerDay, validUntil}: {grantId?: string | null, agentLabel?: string | null, allowedActions?: Array<string>, allowedJobKinds?: Array<string>, maxJobsPerDay?: number | null, validUntil?: __.CdsTimestamp | null}): globalThis.Promise<UpdatedGrant | null> | UpdatedGrant | null
242
+ // metadata (do not use)
243
+ __parameters: {grantId?: string | null, agentLabel?: string | null, allowedActions?: Array<string>, allowedJobKinds?: Array<string>, maxJobsPerDay?: number | null, validUntil?: __.CdsTimestamp | null}, __returns: globalThis.Promise<UpdatedGrant | null> | UpdatedGrant | null, __self: never
244
+ kind: 'action'
245
+ }
246
+
247
+ export declare const GetGrantUsage: {
248
+ // positional
249
+ (grantId: string | null, since: __.CdsTimestamp | null, until: __.CdsTimestamp | null): globalThis.Promise<GrantUsage | null> | GrantUsage | null
250
+ // named
251
+ ({grantId, since, until}: {grantId?: string | null, since?: __.CdsTimestamp | null, until?: __.CdsTimestamp | null}): globalThis.Promise<GrantUsage | null> | GrantUsage | null
252
+ // metadata (do not use)
253
+ __parameters: {grantId?: string | null, since?: __.CdsTimestamp | null, until?: __.CdsTimestamp | null}, __returns: globalThis.Promise<GrantUsage | null> | GrantUsage | null, __self: never
254
+ kind: 'function'
255
+ }
@@ -0,0 +1,36 @@
1
+ // This is an automatically generated file. Please do not change its contents manually!
2
+ const { createEntityProxy } = require('./../_')
3
+ // service
4
+ const CardanoAgentService = { name: 'CardanoAgentService' }
5
+ module.exports = CardanoAgentService
6
+ module.exports.CardanoAgentService = CardanoAgentService
7
+ // AgentGrants
8
+ module.exports.AgentGrant = createEntityProxy(['CardanoAgentService', 'AgentGrants'], { target: { is_singular: true } })
9
+ module.exports.AgentGrants = createEntityProxy(['CardanoAgentService', 'AgentGrants'], { target: { is_singular: false }})
10
+ // GrantStatus
11
+ module.exports.GrantStatus = createEntityProxy(['CardanoAgentService', 'GrantStatus'], { target: { is_singular: true } })
12
+ module.exports.__Array_GrantStatus_ = createEntityProxy(['CardanoAgentService', 'GrantStatus'], { target: { is_singular: false }})
13
+ // IssuedGrant
14
+ module.exports.IssuedGrant = createEntityProxy(['CardanoAgentService', 'IssuedGrant'], { target: { is_singular: true } })
15
+ module.exports.__Array_IssuedGrant_ = createEntityProxy(['CardanoAgentService', 'IssuedGrant'], { target: { is_singular: false }})
16
+ // RotatedGrant
17
+ module.exports.RotatedGrant = createEntityProxy(['CardanoAgentService', 'RotatedGrant'], { target: { is_singular: true } })
18
+ module.exports.__Array_RotatedGrant_ = createEntityProxy(['CardanoAgentService', 'RotatedGrant'], { target: { is_singular: false }})
19
+ // UpdatedGrant
20
+ module.exports.UpdatedGrant = createEntityProxy(['CardanoAgentService', 'UpdatedGrant'], { target: { is_singular: true } })
21
+ module.exports.__Array_UpdatedGrant_ = createEntityProxy(['CardanoAgentService', 'UpdatedGrant'], { target: { is_singular: false }})
22
+ // GrantUsageCall
23
+ module.exports.GrantUsageCall = createEntityProxy(['CardanoAgentService', 'GrantUsageCall'], { target: { is_singular: true } })
24
+ module.exports.__Array_GrantUsageCall_ = createEntityProxy(['CardanoAgentService', 'GrantUsageCall'], { target: { is_singular: false }})
25
+ // GrantUsage
26
+ module.exports.GrantUsage = createEntityProxy(['CardanoAgentService', 'GrantUsage'], { target: { is_singular: true } })
27
+ module.exports.__Array_GrantUsage_ = createEntityProxy(['CardanoAgentService', 'GrantUsage'], { target: { is_singular: false }})
28
+ // events
29
+ // actions
30
+ module.exports.GetGrantStatus = 'GetGrantStatus'
31
+ module.exports.CreateAgentGrant = 'CreateAgentGrant'
32
+ module.exports.RevokeAgentGrant = 'RevokeAgentGrant'
33
+ module.exports.RotateAgentGrantToken = 'RotateAgentGrantToken'
34
+ module.exports.UpdateAgentGrant = 'UpdateAgentGrant'
35
+ module.exports.GetGrantUsage = 'GetGrantUsage'
36
+ // enums
@@ -15,6 +15,7 @@ import * as __ from './../_';
15
15
  */
16
16
  export default class {
17
17
  static readonly getStatus: typeof getStatus;
18
+ static readonly getLiveness: typeof getLiveness;
18
19
  static readonly pauseCrawler: typeof pauseCrawler;
19
20
  static readonly resumeCrawler: typeof resumeCrawler;
20
21
  }
@@ -93,6 +94,23 @@ export declare function _CrawlerStatusAspect<TBase extends new (...args: any[])
93
94
  export class CrawlerStatus extends _CrawlerStatusAspect(__.Entity) {
94
95
  }
95
96
 
97
+ // entity 'Liveness'
98
+ export declare function _LivenessAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
99
+ new (...args: any[]): {
100
+ status?: string | null
101
+ timestamp?: __.CdsTimestamp | null
102
+ uptime?: number | null
103
+ version?: string | null
104
+ network?: string | null
105
+ } & InstanceType<TBase>
106
+ readonly kind: 'type';
107
+ readonly keys: __.KeysOf<Liveness>;
108
+ readonly elements: __.ElementsOf<Liveness>;
109
+ readonly actions: globalThis.Record<never, never>;
110
+ };
111
+ export class Liveness extends _LivenessAspect(__.Entity) {
112
+ }
113
+
96
114
  // event
97
115
  export declare class blockIndexed {
98
116
  readonly kind: 'event';
@@ -121,6 +139,16 @@ export declare const getStatus: {
121
139
  kind: 'function'
122
140
  }
123
141
 
142
+ export declare const getLiveness: {
143
+ // positional
144
+ (): globalThis.Promise<Liveness | null> | Liveness | null
145
+ // named
146
+ ({}: globalThis.Record<never, never>): globalThis.Promise<Liveness | null> | Liveness | null
147
+ // metadata (do not use)
148
+ __parameters: globalThis.Record<never, never>, __returns: globalThis.Promise<Liveness | null> | Liveness | null, __self: never
149
+ kind: 'function'
150
+ }
151
+
124
152
  export declare const pauseCrawler: {
125
153
  // positional
126
154
  (): globalThis.Promise<boolean | null> | boolean | null
@@ -13,11 +13,15 @@ module.exports.ReorgLog_ = createEntityProxy(['CardanoIndexerService', 'ReorgLog
13
13
  // CrawlerStatus
14
14
  module.exports.CrawlerStatus = createEntityProxy(['CardanoIndexerService', 'CrawlerStatus'], { target: { is_singular: true } })
15
15
  module.exports.__Array_CrawlerStatus_ = createEntityProxy(['CardanoIndexerService', 'CrawlerStatus'], { target: { is_singular: false }})
16
+ // Liveness
17
+ module.exports.Liveness = createEntityProxy(['CardanoIndexerService', 'Liveness'], { target: { is_singular: true } })
18
+ module.exports.__Array_Liveness_ = createEntityProxy(['CardanoIndexerService', 'Liveness'], { target: { is_singular: false }})
16
19
  // events
17
20
  module.exports.blockIndexed = 'CardanoIndexerService.blockIndexed'
18
21
  module.exports.reorg = 'CardanoIndexerService.reorg'
19
22
  // actions
20
23
  module.exports.getStatus = 'getStatus'
24
+ module.exports.getLiveness = 'getLiveness'
21
25
  module.exports.pauseCrawler = 'pauseCrawler'
22
26
  module.exports.resumeCrawler = 'resumeCrawler'
23
27
  // enums
@@ -958,3 +958,89 @@ export class CardanoWalletJob extends _CardanoWalletJobAspect(__.Entity) {
958
958
  export class CardanoWalletJobs extends Array<CardanoWalletJob> {
959
959
  $count?: number
960
960
  }
961
+
962
+ // entity 'CardanoAgentGrant'
963
+ export declare function _CardanoAgentGrantAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
964
+ new (...args: any[]): {
965
+ ID?: __.Key<string>
966
+ userId?: string
967
+ agentLabel?: string | null
968
+ tokenHash?: string
969
+ allowedActions?: string
970
+ walletId?: string | null
971
+ allowedJobKinds?: string | null
972
+ maxJobsPerDay?: number | null
973
+ jobsUsedToday?: number | null
974
+ budgetWindow?: string | null
975
+ validUntil?: __.CdsTimestamp | null
976
+ isActive?: boolean | null
977
+ revokedAt?: __.CdsTimestamp | null
978
+ createdAt?: __.CdsTimestamp | null
979
+ lastUsedAt?: __.CdsTimestamp | null
980
+ } & InstanceType<TBase>
981
+ readonly kind: 'entity';
982
+ readonly keys: __.KeysOf<CardanoAgentGrant>;
983
+ readonly elements: __.ElementsOf<CardanoAgentGrant>;
984
+ readonly actions: globalThis.Record<never, never>;
985
+ };
986
+ /**
987
+ * Agent grants (v2.0): scoped bearer capabilities an Admin hands to an agent
988
+ * instead of a full user. The token is a capability, not an identity — it is
989
+ * stored as SHA-256 only, and a request carrying it runs as the principal
990
+ * `agent:<ID>` with the role `agent-grant`, never as the operator. Enforcement
991
+ * (allow list, wallet pinning, daily budget) lives in srv/utils/agent-grants.ts;
992
+ * the transport lane that admits `x-agent-token` in srv/utils/agent-token-auth.ts.
993
+ * Admin-only table: creation and revocation happen through CardanoAgentService
994
+ * actions, a token request may read its own row only.
995
+ */
996
+ export class CardanoAgentGrant extends _CardanoAgentGrantAspect(__.Entity) {
997
+ }
998
+ /**
999
+ * Agent grants (v2.0): scoped bearer capabilities an Admin hands to an agent
1000
+ * instead of a full user. The token is a capability, not an identity — it is
1001
+ * stored as SHA-256 only, and a request carrying it runs as the principal
1002
+ * `agent:<ID>` with the role `agent-grant`, never as the operator. Enforcement
1003
+ * (allow list, wallet pinning, daily budget) lives in srv/utils/agent-grants.ts;
1004
+ * the transport lane that admits `x-agent-token` in srv/utils/agent-token-auth.ts.
1005
+ * Admin-only table: creation and revocation happen through CardanoAgentService
1006
+ * actions, a token request may read its own row only.
1007
+ */
1008
+ export class CardanoAgentGrants extends Array<CardanoAgentGrant> {
1009
+ $count?: number
1010
+ }
1011
+
1012
+ // entity 'CardanoAgentGrantUsage'
1013
+ export declare function _CardanoAgentGrantUsageAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
1014
+ new (...args: any[]): {
1015
+ grant?: __.Key<__.Association.to<CardanoAgentGrant>>
1016
+ grant_ID?: __.Key<string>
1017
+ day?: __.Key<string>
1018
+ service?: __.Key<string>
1019
+ action?: __.Key<string>
1020
+ calls?: number | null
1021
+ refunded?: number | null
1022
+ } & InstanceType<TBase>
1023
+ readonly kind: 'entity';
1024
+ readonly keys: __.KeysOf<CardanoAgentGrantUsage>;
1025
+ readonly elements: __.ElementsOf<CardanoAgentGrantUsage>;
1026
+ readonly actions: globalThis.Record<never, never>;
1027
+ };
1028
+ /**
1029
+ * Daily per-action counters of admitted calls under a grant (feeds
1030
+ * CardanoAgentService.GetGrantUsage). Written by the enforcement hook next to
1031
+ * the daily budget: `calls + 1` when a call is admitted, `refunded + 1` when the
1032
+ * handler then refuses its input. Not exposed as an entity — the function is
1033
+ * the contract. A few dozen rows per grant and day at most; no retention job yet.
1034
+ */
1035
+ export class CardanoAgentGrantUsage extends _CardanoAgentGrantUsageAspect(__.Entity) {
1036
+ }
1037
+ /**
1038
+ * Daily per-action counters of admitted calls under a grant (feeds
1039
+ * CardanoAgentService.GetGrantUsage). Written by the enforcement hook next to
1040
+ * the daily budget: `calls + 1` when a call is admitted, `refunded + 1` when the
1041
+ * handler then refuses its input. Not exposed as an entity — the function is
1042
+ * the contract. A few dozen rows per grant and day at most; no retention job yet.
1043
+ */
1044
+ export class CardanoAgentGrantUsage_ extends Array<CardanoAgentGrantUsage> {
1045
+ $count?: number
1046
+ }
@@ -105,6 +105,12 @@ module.exports.CardanoWorkerWallets = createEntityProxy(['odatano.cardano', 'Car
105
105
  // CardanoWalletJobs
106
106
  module.exports.CardanoWalletJob = createEntityProxy(['odatano.cardano', 'CardanoWalletJobs'], { target: { is_singular: true } })
107
107
  module.exports.CardanoWalletJobs = createEntityProxy(['odatano.cardano', 'CardanoWalletJobs'], { target: { is_singular: false }})
108
+ // CardanoAgentGrants
109
+ module.exports.CardanoAgentGrant = createEntityProxy(['odatano.cardano', 'CardanoAgentGrants'], { target: { is_singular: true } })
110
+ module.exports.CardanoAgentGrants = createEntityProxy(['odatano.cardano', 'CardanoAgentGrants'], { target: { is_singular: false }})
111
+ // CardanoAgentGrantUsage
112
+ module.exports.CardanoAgentGrantUsage = createEntityProxy(['odatano.cardano', 'CardanoAgentGrantUsage'], { target: { is_singular: true } })
113
+ module.exports.CardanoAgentGrantUsage_ = createEntityProxy(['odatano.cardano', 'CardanoAgentGrantUsage'], { target: { is_singular: false }})
108
114
  // events
109
115
  // actions
110
116
  // enums
package/README.md CHANGED
@@ -98,6 +98,7 @@ Service available at `http://localhost:4004`. See the [Quick Start Guide](docs/Q
98
98
  | CardanoSignService | `/odata/v4/cardano-sign/` | External signing + HSM (9 actions) |
99
99
  | CardanoIndexerService | `/odata/v4/cardano-indexer/` | Chain crawler / pre-sync control (v2.0, off by default) |
100
100
  | CardanoWorkerService | `/odata/v4/cardano-worker/` | Asynchronous wallet jobs (v2.0, off by default) |
101
+ | CardanoAgentService | `/odata/v4/cardano-agent/` | Agent grants: scoped bearer tokens for agents (v2.0, off by default) |
101
102
 
102
103
  Both v2.0 services also publish **CAP events**, so a consumer can subscribe instead of polling —
103
104
  in-process, no broker required:
@@ -107,12 +108,61 @@ in-process, no broker required:
107
108
  (await cds.connect.to('CardanoIndexerService')).on('blockIndexed', ({ data }) => …)
108
109
  ```
109
110
 
111
+ ## Agent grants (v2.0, off by default)
112
+
113
+ Hand an agent a **scoped, budgeted token** instead of a user. Design and rationale:
114
+ [AGENT_GRANTS_DESIGN.md](AGENT_GRANTS_DESIGN.md).
115
+
116
+ ```bash
117
+ AGENT_GRANTS_ENABLED=true # or cds.requires.odatano-core.agentGrants.enabled
118
+ AGENT_GRANTS_DELEGATE=mocked # CAP auth kind that keeps authenticating non-token requests (default: configured kind)
119
+ AGENT_GRANT_ADMIN_RATE_LIMIT=10 # grant administration calls per principal per hour (or agentGrants.adminRateLimit)
120
+ ```
121
+
122
+ 1. An **Admin** issues a grant (`POST /odata/v4/cardano-agent/CreateAgentGrant`): an allow list of
123
+ actions, optionally a worker `walletId` (required for `SubmitWalletJob`/`CancelJob`), allowed job
124
+ kinds, a daily budget and an expiry. The response carries the token `odat_…` **once**; the
125
+ server stores only its SHA-256.
126
+ 2. The agent sends `x-agent-token: odat_…` on any of the six service paths. It runs as the principal
127
+ `agent:<grantId>` with the single role `agent-grant`, never as the operator: every
128
+ `@requires: 'Admin'` surface (pause/resume, HSM signing, grant administration) refuses it by
129
+ construction. Reads and compute-only actions are always allowed; allow-listed actions each cost
130
+ one budget unit per UTC day (a build is the service an agent buys); everything else is 403.
131
+ Wallet jobs are pinned to the grant's wallet and visible only to the grant that queued them.
132
+ 3. `GET /odata/v4/cardano-agent/GetGrantStatus()` tells the agent what it may do and how much budget
133
+ is left; `RevokeAgentGrant` turns the token into an unknown token immediately.
134
+ 4. Lifecycle (Admin, same semantics as NIGHTGATE's agent grants so a gateway drives both with one
135
+ code path): `UpdateAgentGrant` changes label, allow list, job kinds, daily budget or expiry
136
+ (absent = untouched, explicit `null` = cleared; the wallet binding is immutable, 409
137
+ `GRANT_REVOKED` on a revoked grant); `RotateAgentGrantToken` returns a fresh token once, the old
138
+ one is unknown from the next request; `GetGrantUsage(grantId, since, until)` lists admitted calls
139
+ per service and action over up to 366 days (an Admin for any grant, a token for its own). All
140
+ administration calls share the per-principal hourly rate limit above.
141
+
142
+ Grantable: `Build*`, `SetCollateral`, `CreateSigningRequest`, `VerifySignature`, `Submit*`,
143
+ `CheckSubmissionStatus`, `SubmitWalletJob`, `CancelJob`. Never: `SignWithHsm*`, `Pause*`/`Resume*`,
144
+ `pauseCrawler`/`resumeCrawler`, grant administration.
145
+
146
+ Programmatic seams for other packages (`@odatano/x402` sells grants against a 402 payment):
147
+ `issueAgentGrant()`, `updateAgentGrant()`, `rotateAgentGrantToken()`, `revokeAgentGrantById()`,
148
+ `getGrantUsage()`, `registerTransportLane()` from `@odatano/core`.
149
+
150
+ ## Liveness probe
151
+
152
+ `GET /odata/v4/cardano-indexer/getLiveness()` answers `200 { status: "alive", timestamp, uptime,
153
+ version, network }` **without credentials** (`@requires: 'any'`) as long as the process runs — no
154
+ backend or DB probe, no secrets. The Docker `HEALTHCHECK`, compose and upstream probes use it
155
+ instead of the service document, so a wrong operator password no longer reads as "ODATANO down".
156
+ Readiness (crawler, worker, backends) stays authenticated: `getStatus()`, `GetWorkerStatus()`,
157
+ `GetNetworkInformation`.
158
+
110
159
  ## Requirements
111
160
 
112
161
  - **Node.js >= 22.5** and **@sap/cds >= 10** (peer dependency). CAP 9 hosts cannot load `@odatano/core@2`.
113
- - Upgrading a consumer from 1.x: run **`cds deploy`**. 2.0 adds four tables (`CardanoSyncState`,
114
- `CardanoReorgLog`, `CardanoWorkerWallets`, `CardanoWalletJobs`) plus a `dedupKey` column; without
115
- the redeploy the new services answer `no such table` while the old ones keep working.
162
+ - Upgrading a consumer from 1.x: run **`cds deploy`**. 2.0 adds six tables (`CardanoSyncState`,
163
+ `CardanoReorgLog`, `CardanoWorkerWallets`, `CardanoWalletJobs`, `CardanoAgentGrants`,
164
+ `CardanoAgentGrantUsage`) plus a `dedupKey` column; without the redeploy the new services answer
165
+ `no such table` while the old ones keep working.
116
166
 
117
167
  ## Documentation
118
168
 
package/db/schema.cds CHANGED
@@ -1631,3 +1631,108 @@ entity CardanoWalletJobs {
1631
1631
  @description: 'Timestamp the job reached a terminal state (confirmed | failed | cancelled)'
1632
1632
  finishedAt : Timestamp;
1633
1633
  }
1634
+
1635
+ /**
1636
+ * Agent grants (v2.0): scoped bearer capabilities an Admin hands to an agent
1637
+ * instead of a full user. The token is a capability, not an identity — it is
1638
+ * stored as SHA-256 only, and a request carrying it runs as the principal
1639
+ * `agent:<ID>` with the role `agent-grant`, never as the operator. Enforcement
1640
+ * (allow list, wallet pinning, daily budget) lives in srv/utils/agent-grants.ts;
1641
+ * the transport lane that admits `x-agent-token` in srv/utils/agent-token-auth.ts.
1642
+ * Admin-only table: creation and revocation happen through CardanoAgentService
1643
+ * actions, a token request may read its own row only.
1644
+ */
1645
+ @title : 'Agent Grants'
1646
+ @description: 'Scoped, budgeted bearer capabilities for agents (token stored as SHA-256 only)'
1647
+ entity CardanoAgentGrants {
1648
+
1649
+ @title : 'Grant Id (Key)'
1650
+ key ID : UUID;
1651
+
1652
+ @title : 'Operator'
1653
+ @description: 'User id of the Admin that issued the grant (audit; the token never runs as this user)'
1654
+ userId : String(200) not null;
1655
+
1656
+ @title : 'Agent Label'
1657
+ @description: 'Human-readable agent name, informational'
1658
+ agentLabel : String(100);
1659
+
1660
+ @title : 'Token Hash'
1661
+ @description: 'SHA-256 of the bearer token; the token itself is shown once and never stored'
1662
+ tokenHash : String(64) not null;
1663
+
1664
+ @title : 'Allowed Actions'
1665
+ @description: 'JSON array of allow-listed action names (builds, signing-request lifecycle, submits, wallet jobs)'
1666
+ allowedActions : LargeString not null;
1667
+
1668
+ @title : 'Wallet Id'
1669
+ @description: 'Worker wallet this grant is pinned to; required for SubmitWalletJob / CancelJob, injected into those requests'
1670
+ walletId : String(50);
1671
+
1672
+ @title : 'Allowed Job Kinds'
1673
+ @description: 'JSON array of WalletJobKind values the grant may queue; null = every kind'
1674
+ allowedJobKinds : LargeString;
1675
+
1676
+ @title : 'Max Jobs Per Day'
1677
+ @description: 'Daily budget of allow-listed action calls (UTC day); null = unlimited'
1678
+ maxJobsPerDay : Integer;
1679
+
1680
+ @title : 'Jobs Used Today'
1681
+ @description: 'Budget consumed inside budgetWindow'
1682
+ jobsUsedToday : Integer default 0;
1683
+
1684
+ @title : 'Budget Window'
1685
+ @description: 'UTC day YYYY-MM-DD the counter belongs to'
1686
+ budgetWindow : String(10);
1687
+
1688
+ @title : 'Valid Until'
1689
+ @description: 'Expiry; null = no expiry'
1690
+ validUntil : Timestamp;
1691
+
1692
+ @title : 'Is Active'
1693
+ @description: 'False once revoked; a revoked token is an unknown token'
1694
+ isActive : Boolean default true;
1695
+
1696
+ @title : 'Revoked At'
1697
+ revokedAt : Timestamp;
1698
+
1699
+ @title : 'Created At'
1700
+ createdAt : Timestamp;
1701
+
1702
+ @title : 'Last Used At'
1703
+ @description: 'Last request admitted under this token (updated at most once a minute)'
1704
+ lastUsedAt : Timestamp;
1705
+ }
1706
+
1707
+ /**
1708
+ * Daily per-action counters of admitted calls under a grant (feeds
1709
+ * CardanoAgentService.GetGrantUsage). Written by the enforcement hook next to
1710
+ * the daily budget: `calls + 1` when a call is admitted, `refunded + 1` when the
1711
+ * handler then refuses its input. Not exposed as an entity — the function is
1712
+ * the contract. A few dozen rows per grant and day at most; no retention job yet.
1713
+ */
1714
+ entity CardanoAgentGrantUsage {
1715
+
1716
+ @title : 'Grant'
1717
+ key grant : Association to CardanoAgentGrants;
1718
+
1719
+ @title : 'Day'
1720
+ @description: 'UTC day YYYY-MM-DD the call was admitted on'
1721
+ key day : String(10);
1722
+
1723
+ @title : 'Service'
1724
+ @description: 'CAP service name (CardanoTransactionService, CardanoSignService, ...)'
1725
+ key service : String(60);
1726
+
1727
+ @title : 'Action'
1728
+ @description: 'Action name (BuildSimpleAdaTransaction, SubmitTransaction, ...)'
1729
+ key action : String(100);
1730
+
1731
+ @title : 'Calls'
1732
+ @description: 'Admitted calls (budget charged where the grant has one)'
1733
+ calls : Integer default 0;
1734
+
1735
+ @title : 'Refunded'
1736
+ @description: 'Admitted calls whose handler refused the input (400..428); their unit was given back'
1737
+ refunded : Integer default 0;
1738
+ }