@odatano/core 2.0.0-rc.5 → 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.
- package/@cds-models/CardanoAgentService/index.d.ts +107 -3
- package/@cds-models/CardanoAgentService/index.js +15 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +28 -0
- package/@cds-models/CardanoIndexerService/index.js +4 -0
- package/@cds-models/odatano/cardano/index.d.ts +36 -0
- package/@cds-models/odatano/cardano/index.js +3 -0
- package/README.md +23 -4
- package/db/schema.cds +33 -0
- package/package.json +3 -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 +20 -0
- package/srv/cardano-indexer-service.js +3 -0
- 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
|
@@ -7,16 +7,24 @@ import * as __ from './../_';
|
|
|
7
7
|
* Agent grants: scoped, budgeted bearer capabilities an Admin hands to an agent
|
|
8
8
|
* instead of a full user (see AGENT_GRANTS_DESIGN.md).
|
|
9
9
|
*
|
|
10
|
-
* - CreateAgentGrant /
|
|
11
|
-
*
|
|
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.
|
|
12
14
|
* - AgentGrants: Admin-only projection (no token hash). A request carrying a token
|
|
13
15
|
* runs as the principal `agent:<grantId>` with the role `agent-grant` and sees
|
|
14
16
|
* exactly its own row through the row-level restriction below.
|
|
15
17
|
* - GetGrantStatus: token self-service — what am I allowed to do, how much budget
|
|
16
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.
|
|
17
25
|
*
|
|
18
26
|
* A token request never inherits the operator's roles: `@requires: 'Admin'` on the
|
|
19
|
-
*
|
|
27
|
+
* four actions, on PauseWorker / ResumeWorker / pauseCrawler / resumeCrawler and on
|
|
20
28
|
* every other Admin surface therefore refuses it by construction. The allow list,
|
|
21
29
|
* wallet pinning and daily budget are enforced by a before('*') hook on all six
|
|
22
30
|
* ODATANO services (srv/utils/agent-grants.ts). The `x-agent-token` header only
|
|
@@ -27,6 +35,9 @@ export default class {
|
|
|
27
35
|
static readonly GetGrantStatus: typeof GetGrantStatus;
|
|
28
36
|
static readonly CreateAgentGrant: typeof CreateAgentGrant;
|
|
29
37
|
static readonly RevokeAgentGrant: typeof RevokeAgentGrant;
|
|
38
|
+
static readonly RotateAgentGrantToken: typeof RotateAgentGrantToken;
|
|
39
|
+
static readonly UpdateAgentGrant: typeof UpdateAgentGrant;
|
|
40
|
+
static readonly GetGrantUsage: typeof GetGrantUsage;
|
|
30
41
|
}
|
|
31
42
|
|
|
32
43
|
// entity 'AgentGrant'
|
|
@@ -119,6 +130,69 @@ export declare function _IssuedGrantAspect<TBase extends new (...args: any[]) =>
|
|
|
119
130
|
export class IssuedGrant extends _IssuedGrantAspect(__.Entity) {
|
|
120
131
|
}
|
|
121
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
|
+
|
|
122
196
|
|
|
123
197
|
export declare const GetGrantStatus: {
|
|
124
198
|
// positional
|
|
@@ -148,4 +222,34 @@ export declare const RevokeAgentGrant: {
|
|
|
148
222
|
// metadata (do not use)
|
|
149
223
|
__parameters: {grantId?: string | null}, __returns: globalThis.Promise<boolean | null> | boolean | null, __self: never
|
|
150
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'
|
|
151
255
|
}
|
|
@@ -13,9 +13,24 @@ module.exports.__Array_GrantStatus_ = createEntityProxy(['CardanoAgentService',
|
|
|
13
13
|
// IssuedGrant
|
|
14
14
|
module.exports.IssuedGrant = createEntityProxy(['CardanoAgentService', 'IssuedGrant'], { target: { is_singular: true } })
|
|
15
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 }})
|
|
16
28
|
// events
|
|
17
29
|
// actions
|
|
18
30
|
module.exports.GetGrantStatus = 'GetGrantStatus'
|
|
19
31
|
module.exports.CreateAgentGrant = 'CreateAgentGrant'
|
|
20
32
|
module.exports.RevokeAgentGrant = 'RevokeAgentGrant'
|
|
33
|
+
module.exports.RotateAgentGrantToken = 'RotateAgentGrantToken'
|
|
34
|
+
module.exports.UpdateAgentGrant = 'UpdateAgentGrant'
|
|
35
|
+
module.exports.GetGrantUsage = 'GetGrantUsage'
|
|
21
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
|
|
@@ -1008,3 +1008,39 @@ export class CardanoAgentGrant extends _CardanoAgentGrantAspect(__.Entity) {
|
|
|
1008
1008
|
export class CardanoAgentGrants extends Array<CardanoAgentGrant> {
|
|
1009
1009
|
$count?: number
|
|
1010
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
|
+
}
|
|
@@ -108,6 +108,9 @@ module.exports.CardanoWalletJobs = createEntityProxy(['odatano.cardano', 'Cardan
|
|
|
108
108
|
// CardanoAgentGrants
|
|
109
109
|
module.exports.CardanoAgentGrant = createEntityProxy(['odatano.cardano', 'CardanoAgentGrants'], { target: { is_singular: true } })
|
|
110
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 }})
|
|
111
114
|
// events
|
|
112
115
|
// actions
|
|
113
116
|
// enums
|
package/README.md
CHANGED
|
@@ -116,6 +116,7 @@ Hand an agent a **scoped, budgeted token** instead of a user. Design and rationa
|
|
|
116
116
|
```bash
|
|
117
117
|
AGENT_GRANTS_ENABLED=true # or cds.requires.odatano-core.agentGrants.enabled
|
|
118
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)
|
|
119
120
|
```
|
|
120
121
|
|
|
121
122
|
1. An **Admin** issues a grant (`POST /odata/v4/cardano-agent/CreateAgentGrant`): an allow list of
|
|
@@ -130,20 +131,38 @@ AGENT_GRANTS_DELEGATE=mocked # CAP auth kind that keeps authenticating n
|
|
|
130
131
|
Wallet jobs are pinned to the grant's wallet and visible only to the grant that queued them.
|
|
131
132
|
3. `GET /odata/v4/cardano-agent/GetGrantStatus()` tells the agent what it may do and how much budget
|
|
132
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.
|
|
133
141
|
|
|
134
142
|
Grantable: `Build*`, `SetCollateral`, `CreateSigningRequest`, `VerifySignature`, `Submit*`,
|
|
135
143
|
`CheckSubmissionStatus`, `SubmitWalletJob`, `CancelJob`. Never: `SignWithHsm*`, `Pause*`/`Resume*`,
|
|
136
144
|
`pauseCrawler`/`resumeCrawler`, grant administration.
|
|
137
145
|
|
|
138
146
|
Programmatic seams for other packages (`@odatano/x402` sells grants against a 402 payment):
|
|
139
|
-
`issueAgentGrant()`, `
|
|
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`.
|
|
140
158
|
|
|
141
159
|
## Requirements
|
|
142
160
|
|
|
143
161
|
- **Node.js >= 22.5** and **@sap/cds >= 10** (peer dependency). CAP 9 hosts cannot load `@odatano/core@2`.
|
|
144
|
-
- Upgrading a consumer from 1.x: run **`cds deploy`**. 2.0 adds
|
|
145
|
-
`CardanoReorgLog`, `CardanoWorkerWallets`, `CardanoWalletJobs
|
|
146
|
-
|
|
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.
|
|
147
166
|
|
|
148
167
|
## Documentation
|
|
149
168
|
|
package/db/schema.cds
CHANGED
|
@@ -1703,3 +1703,36 @@ entity CardanoAgentGrants {
|
|
|
1703
1703
|
@description: 'Last request admitted under this token (updated at most once a minute)'
|
|
1704
1704
|
lastUsedAt : Timestamp;
|
|
1705
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@odatano/core",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.6",
|
|
4
4
|
"description": "SAP CAP plugin for Cardano blockchain OData V4 integration",
|
|
5
5
|
"imports": {
|
|
6
6
|
"#cds-models/*": "./@cds-models/*/index.js"
|
|
@@ -141,7 +141,8 @@
|
|
|
141
141
|
"pretest:unit": "npm run cds:types",
|
|
142
142
|
"test:unit": "vitest run --project unit",
|
|
143
143
|
"watch-odatano": "cds watch --open odatano/index.html?sap-ui-xx-viewCache=false --livereload false",
|
|
144
|
-
"watch-wallet": "cds watch --open wallet/webapp/index.html"
|
|
144
|
+
"watch-wallet": "cds watch --open wallet/webapp/index.html",
|
|
145
|
+
"release:check": "node scripts/release-check.mjs"
|
|
145
146
|
},
|
|
146
147
|
"sapux": [
|
|
147
148
|
"app/odatano"
|
package/src/index.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ export { CardanoIndexer } from '../srv/blockchain/cardano-indexer';
|
|
|
4
4
|
export { CardanoTransactionBuilder } from '../srv/blockchain/cardano-tx-builder';
|
|
5
5
|
export { getAppContext, getCardanoIndexer, getCardanoClient, getCardanoTxBuilder, loadConfigFromEnv, loadHsmConfigFromEnv, loadCrawlerConfigFromEnv, startCrawlerIfConfigured, loadWalletWorkerConfigFromEnv, startWalletWorkerIfConfigured, shutdownAppContext, } from '../srv/server';
|
|
6
6
|
export { getHsmSigner } from '../srv/blockchain/signing/hsm-signer';
|
|
7
|
-
export { issueAgentGrant, revokeAgentGrantById, hashAgentToken, AGENT_TOKEN_HEADER, AGENT_TOKEN_PREFIX, AGENT_ROLE, AGENT_ALLOWLISTABLE_ACTIONS, AGENT_ALWAYS_ALLOWED_EVENTS, } from '../srv/utils/agent-grants';
|
|
8
|
-
export type { IssueAgentGrantInput, IssuedAgentGrant, AgentGrantStatus } from '../srv/utils/agent-grants';
|
|
7
|
+
export { issueAgentGrant, updateAgentGrant, rotateAgentGrantToken, revokeAgentGrantById, getGrantUsage, resolveUsageWindow, hashAgentToken, AGENT_TOKEN_HEADER, AGENT_TOKEN_PREFIX, AGENT_ROLE, AGENT_ALLOWLISTABLE_ACTIONS, AGENT_ALWAYS_ALLOWED_EVENTS, } from '../srv/utils/agent-grants';
|
|
8
|
+
export type { IssueAgentGrantInput, IssuedAgentGrant, AgentGrantStatus, UpdateAgentGrantInput, UpdateAgentGrantResult, RotatedAgentGrant, AgentGrantUsage, GrantUsageCall, UsageWindow, } from '../srv/utils/agent-grants';
|
|
9
9
|
export { registerTransportLane } from '../srv/utils/agent-token-auth';
|
|
10
10
|
export type { TransportLane, LaneOutcome } from '../srv/utils/agent-token-auth';
|
|
11
11
|
export { loadAgentGrantsConfig } from '../srv/utils/agent-grants-config';
|
package/src/index.js
CHANGED
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.parseTransaction = exports.loadAgentGrantsConfig = exports.registerTransportLane = exports.AGENT_ALWAYS_ALLOWED_EVENTS = exports.AGENT_ALLOWLISTABLE_ACTIONS = exports.AGENT_ROLE = exports.AGENT_TOKEN_PREFIX = exports.AGENT_TOKEN_HEADER = exports.hashAgentToken = exports.revokeAgentGrantById = exports.issueAgentGrant = exports.getHsmSigner = exports.shutdownAppContext = exports.startWalletWorkerIfConfigured = exports.loadWalletWorkerConfigFromEnv = exports.startCrawlerIfConfigured = exports.loadCrawlerConfigFromEnv = exports.loadHsmConfigFromEnv = exports.loadConfigFromEnv = exports.getCardanoTxBuilder = exports.getCardanoClient = exports.getCardanoIndexer = exports.getAppContext = exports.CardanoTransactionBuilder = exports.CardanoIndexer = exports.CardanoClient = void 0;
|
|
39
|
+
exports.parseTransaction = exports.loadAgentGrantsConfig = exports.registerTransportLane = exports.AGENT_ALWAYS_ALLOWED_EVENTS = exports.AGENT_ALLOWLISTABLE_ACTIONS = exports.AGENT_ROLE = exports.AGENT_TOKEN_PREFIX = exports.AGENT_TOKEN_HEADER = exports.hashAgentToken = exports.resolveUsageWindow = exports.getGrantUsage = exports.revokeAgentGrantById = exports.rotateAgentGrantToken = exports.updateAgentGrant = exports.issueAgentGrant = exports.getHsmSigner = exports.shutdownAppContext = exports.startWalletWorkerIfConfigured = exports.loadWalletWorkerConfigFromEnv = exports.startCrawlerIfConfigured = exports.loadCrawlerConfigFromEnv = exports.loadHsmConfigFromEnv = exports.loadConfigFromEnv = exports.getCardanoTxBuilder = exports.getCardanoClient = exports.getCardanoIndexer = exports.getAppContext = exports.CardanoTransactionBuilder = exports.CardanoIndexer = exports.CardanoClient = void 0;
|
|
40
40
|
exports.initialize = initialize;
|
|
41
41
|
exports.shutdown = shutdown;
|
|
42
42
|
exports.getStatus = getStatus;
|
|
@@ -70,7 +70,11 @@ Object.defineProperty(exports, "getHsmSigner", { enumerable: true, get: function
|
|
|
70
70
|
// adds its payment lane through registerTransportLane.
|
|
71
71
|
var agent_grants_1 = require("../srv/utils/agent-grants");
|
|
72
72
|
Object.defineProperty(exports, "issueAgentGrant", { enumerable: true, get: function () { return agent_grants_1.issueAgentGrant; } });
|
|
73
|
+
Object.defineProperty(exports, "updateAgentGrant", { enumerable: true, get: function () { return agent_grants_1.updateAgentGrant; } });
|
|
74
|
+
Object.defineProperty(exports, "rotateAgentGrantToken", { enumerable: true, get: function () { return agent_grants_1.rotateAgentGrantToken; } });
|
|
73
75
|
Object.defineProperty(exports, "revokeAgentGrantById", { enumerable: true, get: function () { return agent_grants_1.revokeAgentGrantById; } });
|
|
76
|
+
Object.defineProperty(exports, "getGrantUsage", { enumerable: true, get: function () { return agent_grants_1.getGrantUsage; } });
|
|
77
|
+
Object.defineProperty(exports, "resolveUsageWindow", { enumerable: true, get: function () { return agent_grants_1.resolveUsageWindow; } });
|
|
74
78
|
Object.defineProperty(exports, "hashAgentToken", { enumerable: true, get: function () { return agent_grants_1.hashAgentToken; } });
|
|
75
79
|
Object.defineProperty(exports, "AGENT_TOKEN_HEADER", { enumerable: true, get: function () { return agent_grants_1.AGENT_TOKEN_HEADER; } });
|
|
76
80
|
Object.defineProperty(exports, "AGENT_TOKEN_PREFIX", { enumerable: true, get: function () { return agent_grants_1.AGENT_TOKEN_PREFIX; } });
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { Transaction, BlockData, Address, UTxO, NetworkInformation, EpochData, MetadataLabelTx, PoolData, AccountData, DrepData, AssetInfo, LedgerProtocolParameters, ScriptEvaluationResult } from '../../utils/types';
|
|
2
2
|
import { EvaluatingBackend, ChainSyncBackend, ChainSyncCallbacks, ChainSyncHandle, ChainPoint } from './cardano-backend';
|
|
3
3
|
import { Network } from '../cardano-client';
|
|
4
|
+
/**
|
|
5
|
+
* Decode a CIP-129 DRep ID (`drep1…`, 29 bytes) into its credential hash and
|
|
6
|
+
* type. Header byte: high nibble 0x2 = DRep, low nibble 0x2 = key hash /
|
|
7
|
+
* 0x3 = script hash. The validators already enforce HRP + length before the
|
|
8
|
+
* request reaches a backend, so this only has to split the payload.
|
|
9
|
+
*/
|
|
10
|
+
export declare function decodeDrepId(drepId: string): {
|
|
11
|
+
hashHex: string;
|
|
12
|
+
isScript: boolean;
|
|
13
|
+
};
|
|
4
14
|
/** Resolve Ogmios ledger tip which may be 'origin' (genesis block) or a point */
|
|
5
15
|
export declare function resolveOgmiosTip(tip: 'origin' | {
|
|
6
16
|
slot: number;
|
|
@@ -107,11 +117,21 @@ export declare class OgmiosBackend implements EvaluatingBackend, ChainSyncBacken
|
|
|
107
117
|
*/
|
|
108
118
|
getTransactionMetadata(_tx_hash: string): Promise<MetadataLabelTx[]>;
|
|
109
119
|
/**
|
|
110
|
-
* Get
|
|
111
|
-
*
|
|
120
|
+
* Get DRep data from the live ledger state (`queryLedgerState/delegateRepresentatives`).
|
|
121
|
+
*
|
|
122
|
+
* The client package (6.14) ships the schema types but no wrapper for this query,
|
|
123
|
+
* so it goes through the exported `Method()` primitive on our interaction context —
|
|
124
|
+
* the same building block the client uses for `stakePools` & co.
|
|
125
|
+
*
|
|
126
|
+
* Semantics vs. Blockfrost/Koios: Ogmios only lists REGISTERED DReps, so a retired
|
|
127
|
+
* or unknown DRep is a NotFoundError here (never `retired: true`), and there is no
|
|
128
|
+
* last-activity epoch — `expired` is derived from the mandate epoch instead.
|
|
129
|
+
* Routing keeps `getDrep` historical-preferred; this is the Ogmios-only fallback.
|
|
130
|
+
*
|
|
131
|
+
* @param drepId CIP-129 bech32 DRep ID (`drep1…`)
|
|
112
132
|
* @returns {Promise<DrepData>} drep data
|
|
113
133
|
*/
|
|
114
|
-
getDrep(
|
|
134
|
+
getDrep(drepId: string): Promise<DrepData>;
|
|
115
135
|
/**
|
|
116
136
|
* Get Asset Info (not supported for Ogmios — no aggregate-supply query in the protocol)
|
|
117
137
|
* @param _unit asset unit (policyId + assetNameHex)
|
|
@@ -4,11 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.OgmiosBackend = void 0;
|
|
7
|
+
exports.decodeDrepId = decodeDrepId;
|
|
7
8
|
exports.resolveOgmiosTip = resolveOgmiosTip;
|
|
8
9
|
exports.resolveOgmiosHeight = resolveOgmiosHeight;
|
|
9
10
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
10
11
|
const node_http_1 = __importDefault(require("node:http"));
|
|
11
12
|
const client_1 = require("@cardano-ogmios/client");
|
|
13
|
+
const bech32_1 = require("bech32");
|
|
12
14
|
const backend_request_handler_1 = require("../../utils/backend-request-handler");
|
|
13
15
|
const errors_1 = require("../../utils/errors");
|
|
14
16
|
const mappers_1 = require("../../utils/mappers");
|
|
@@ -63,6 +65,23 @@ function ogmiosValueToLovelaceString(value) {
|
|
|
63
65
|
const lovelace = value.ada?.lovelace;
|
|
64
66
|
return lovelace === undefined ? '0' : String(lovelace);
|
|
65
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Decode a CIP-129 DRep ID (`drep1…`, 29 bytes) into its credential hash and
|
|
70
|
+
* type. Header byte: high nibble 0x2 = DRep, low nibble 0x2 = key hash /
|
|
71
|
+
* 0x3 = script hash. The validators already enforce HRP + length before the
|
|
72
|
+
* request reaches a backend, so this only has to split the payload.
|
|
73
|
+
*/
|
|
74
|
+
function decodeDrepId(drepId) {
|
|
75
|
+
const decoded = bech32_1.bech32.decode(drepId, const_1.BECH32_MAX_LENGTH);
|
|
76
|
+
const bytes = Buffer.from(bech32_1.bech32.fromWords(decoded.words));
|
|
77
|
+
if (decoded.prefix !== 'drep' || bytes.length !== 29) {
|
|
78
|
+
throw new errors_1.NotFoundError('Drep', 'ogmios');
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
hashHex: bytes.subarray(1).toString('hex'),
|
|
82
|
+
isScript: (bytes[0] & 0x0f) === 0x03,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
66
85
|
/** Resolve Ogmios ledger tip which may be 'origin' (genesis block) or a point */
|
|
67
86
|
function resolveOgmiosTip(tip) {
|
|
68
87
|
return tip === 'origin' ? { slot: 0, hash: '' } : { slot: tip.slot, hash: tip.id };
|
|
@@ -88,7 +107,8 @@ class OgmiosBackend {
|
|
|
88
107
|
'getTransaction',
|
|
89
108
|
'getTransactionMetadata',
|
|
90
109
|
'getAddressTransactions',
|
|
91
|
-
|
|
110
|
+
// getDrep is NOT listed: served from the live ledger state via
|
|
111
|
+
// queryLedgerState/delegateRepresentatives (Ogmios ≥ 6.4).
|
|
92
112
|
'getAssetInfo',
|
|
93
113
|
'getAddress',
|
|
94
114
|
'getNetworkInformation',
|
|
@@ -305,13 +325,60 @@ class OgmiosBackend {
|
|
|
305
325
|
}, this.name);
|
|
306
326
|
}
|
|
307
327
|
/**
|
|
308
|
-
* Get
|
|
309
|
-
*
|
|
328
|
+
* Get DRep data from the live ledger state (`queryLedgerState/delegateRepresentatives`).
|
|
329
|
+
*
|
|
330
|
+
* The client package (6.14) ships the schema types but no wrapper for this query,
|
|
331
|
+
* so it goes through the exported `Method()` primitive on our interaction context —
|
|
332
|
+
* the same building block the client uses for `stakePools` & co.
|
|
333
|
+
*
|
|
334
|
+
* Semantics vs. Blockfrost/Koios: Ogmios only lists REGISTERED DReps, so a retired
|
|
335
|
+
* or unknown DRep is a NotFoundError here (never `retired: true`), and there is no
|
|
336
|
+
* last-activity epoch — `expired` is derived from the mandate epoch instead.
|
|
337
|
+
* Routing keeps `getDrep` historical-preferred; this is the Ogmios-only fallback.
|
|
338
|
+
*
|
|
339
|
+
* @param drepId CIP-129 bech32 DRep ID (`drep1…`)
|
|
310
340
|
* @returns {Promise<DrepData>} drep data
|
|
311
341
|
*/
|
|
312
|
-
async getDrep(
|
|
342
|
+
async getDrep(drepId) {
|
|
313
343
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
314
|
-
|
|
344
|
+
await this.ensureConnected();
|
|
345
|
+
if (!this.context) {
|
|
346
|
+
throw new errors_1.ProviderUnavailableError('Ogmios interaction context not available', this.name);
|
|
347
|
+
}
|
|
348
|
+
const { hashHex, isScript } = decodeDrepId(drepId);
|
|
349
|
+
const [summaries, currentEpoch] = await Promise.all([
|
|
350
|
+
(0, client_1.Method)({
|
|
351
|
+
method: 'queryLedgerState/delegateRepresentatives',
|
|
352
|
+
params: isScript ? { scripts: [hashHex] } : { keys: [hashHex] },
|
|
353
|
+
}, {
|
|
354
|
+
handler: (response, resolve, reject) => {
|
|
355
|
+
if (response.error) {
|
|
356
|
+
reject(new Error(response.error.message ?? `Ogmios error ${response.error.code ?? ''}`.trim()));
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
resolve(Array.isArray(response.result) ? response.result : []);
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
}, this.context),
|
|
363
|
+
this.stateQueryClient.epoch(),
|
|
364
|
+
]);
|
|
365
|
+
// Filter by id: the query is already credential-scoped, but never trust a
|
|
366
|
+
// broader answer (abstain/noConfidence rows carry no id and are dropped here).
|
|
367
|
+
const drep = summaries.find((s) => s.type === 'registered' && s.id?.toLowerCase() === hashHex);
|
|
368
|
+
if (!drep)
|
|
369
|
+
throw new errors_1.NotFoundError('Drep', this.name);
|
|
370
|
+
const mandateEpoch = drep.mandate?.epoch;
|
|
371
|
+
return {
|
|
372
|
+
drepId,
|
|
373
|
+
hex: hashHex,
|
|
374
|
+
amount: ogmiosValueToLovelaceString(drep.stake),
|
|
375
|
+
hasScript: isScript || drep.from === 'script',
|
|
376
|
+
// Ogmios reports the mandate (expiry) epoch, not the last activity — keep 0,
|
|
377
|
+
// matching what the Koios mapper does since its schema change.
|
|
378
|
+
lastActiveEpoch: 0,
|
|
379
|
+
expired: typeof mandateEpoch === 'number' && mandateEpoch < Number(currentEpoch),
|
|
380
|
+
retired: false,
|
|
381
|
+
};
|
|
315
382
|
}, this.name);
|
|
316
383
|
}
|
|
317
384
|
/**
|