@odatano/core 2.0.0-rc.4 → 2.0.0-rc.5
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 +151 -0
- package/@cds-models/CardanoAgentService/index.js +21 -0
- package/@cds-models/odatano/cardano/index.d.ts +50 -0
- package/@cds-models/odatano/cardano/index.js +3 -0
- package/README.md +31 -0
- package/db/schema.cds +72 -0
- package/package.json +2 -2
- package/src/index.d.ts +6 -0
- package/src/index.js +17 -1
- package/src/plugin.js +33 -30
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +32 -1
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +91 -29
- package/srv/blockchain/wallet-worker/job-store.d.ts +11 -0
- package/srv/blockchain/wallet-worker/job-store.js +42 -9
- package/srv/cardano-agent-service.cds +84 -0
- package/srv/cardano-agent-service.d.ts +2 -0
- package/srv/cardano-agent-service.js +16 -0
- package/srv/server.d.ts +2 -1
- package/srv/server.js +12 -0
- package/srv/utils/agent-grants-config.d.ts +48 -0
- package/srv/utils/agent-grants-config.js +124 -0
- package/srv/utils/agent-grants.d.ts +211 -0
- package/srv/utils/agent-grants.js +541 -0
- package/srv/utils/agent-token-auth.d.ts +106 -0
- package/srv/utils/agent-token-auth.js +239 -0
- package/srv/utils/rate-limiter.d.ts +57 -0
- package/srv/utils/rate-limiter.js +126 -0
|
@@ -0,0 +1,151 @@
|
|
|
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 / RevokeAgentGrant: Admin-only administration. The token is
|
|
11
|
+
* returned ONCE from CreateAgentGrant and stored as SHA-256 only.
|
|
12
|
+
* - AgentGrants: Admin-only projection (no token hash). A request carrying a token
|
|
13
|
+
* runs as the principal `agent:<grantId>` with the role `agent-grant` and sees
|
|
14
|
+
* exactly its own row through the row-level restriction below.
|
|
15
|
+
* - GetGrantStatus: token self-service — what am I allowed to do, how much budget
|
|
16
|
+
* is left, when do I expire. What an MCP tool needs to describe itself honestly.
|
|
17
|
+
*
|
|
18
|
+
* A token request never inherits the operator's roles: `@requires: 'Admin'` on the
|
|
19
|
+
* two actions, on PauseWorker / ResumeWorker / pauseCrawler / resumeCrawler and on
|
|
20
|
+
* every other Admin surface therefore refuses it by construction. The allow list,
|
|
21
|
+
* wallet pinning and daily budget are enforced by a before('*') hook on all six
|
|
22
|
+
* ODATANO services (srv/utils/agent-grants.ts). The `x-agent-token` header only
|
|
23
|
+
* reaches the services when cds.requires.odatano-core.agentGrants.enabled is set
|
|
24
|
+
* (srv/utils/agent-token-auth.ts).
|
|
25
|
+
*/
|
|
26
|
+
export default class {
|
|
27
|
+
static readonly GetGrantStatus: typeof GetGrantStatus;
|
|
28
|
+
static readonly CreateAgentGrant: typeof CreateAgentGrant;
|
|
29
|
+
static readonly RevokeAgentGrant: typeof RevokeAgentGrant;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// entity 'AgentGrant'
|
|
33
|
+
export declare function _AgentGrantAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
|
|
34
|
+
new (...args: any[]): {
|
|
35
|
+
ID?: __.Key<string>
|
|
36
|
+
userId?: string
|
|
37
|
+
agentLabel?: string | null
|
|
38
|
+
allowedActions?: string
|
|
39
|
+
walletId?: string | null
|
|
40
|
+
allowedJobKinds?: string | null
|
|
41
|
+
maxJobsPerDay?: number | null
|
|
42
|
+
jobsUsedToday?: number | null
|
|
43
|
+
budgetWindow?: string | null
|
|
44
|
+
validUntil?: __.CdsTimestamp | null
|
|
45
|
+
isActive?: boolean | null
|
|
46
|
+
revokedAt?: __.CdsTimestamp | null
|
|
47
|
+
createdAt?: __.CdsTimestamp | null
|
|
48
|
+
lastUsedAt?: __.CdsTimestamp | null
|
|
49
|
+
} & InstanceType<TBase>
|
|
50
|
+
readonly kind: 'entity';
|
|
51
|
+
readonly keys: __.KeysOf<AgentGrant>;
|
|
52
|
+
readonly elements: __.ElementsOf<AgentGrant>;
|
|
53
|
+
readonly actions: globalThis.Record<never, never>;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Agent grants (v2.0): scoped bearer capabilities an Admin hands to an agent
|
|
57
|
+
* instead of a full user. The token is a capability, not an identity — it is
|
|
58
|
+
* stored as SHA-256 only, and a request carrying it runs as the principal
|
|
59
|
+
* `agent:<ID>` with the role `agent-grant`, never as the operator. Enforcement
|
|
60
|
+
* (allow list, wallet pinning, daily budget) lives in srv/utils/agent-grants.ts;
|
|
61
|
+
* the transport lane that admits `x-agent-token` in srv/utils/agent-token-auth.ts.
|
|
62
|
+
* Admin-only table: creation and revocation happen through CardanoAgentService
|
|
63
|
+
* actions, a token request may read its own row only.
|
|
64
|
+
*/
|
|
65
|
+
export class AgentGrant extends _AgentGrantAspect(__.Entity) {
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Agent grants (v2.0): scoped bearer capabilities an Admin hands to an agent
|
|
69
|
+
* instead of a full user. The token is a capability, not an identity — it is
|
|
70
|
+
* stored as SHA-256 only, and a request carrying it runs as the principal
|
|
71
|
+
* `agent:<ID>` with the role `agent-grant`, never as the operator. Enforcement
|
|
72
|
+
* (allow list, wallet pinning, daily budget) lives in srv/utils/agent-grants.ts;
|
|
73
|
+
* the transport lane that admits `x-agent-token` in srv/utils/agent-token-auth.ts.
|
|
74
|
+
* Admin-only table: creation and revocation happen through CardanoAgentService
|
|
75
|
+
* actions, a token request may read its own row only.
|
|
76
|
+
*/
|
|
77
|
+
export class AgentGrants extends Array<AgentGrant> {
|
|
78
|
+
$count?: number
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// entity 'GrantStatus'
|
|
82
|
+
export declare function _GrantStatusAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
|
|
83
|
+
new (...args: any[]): {
|
|
84
|
+
grantId?: string | null
|
|
85
|
+
agentLabel?: string | null
|
|
86
|
+
allowedActions?: Array<string>
|
|
87
|
+
walletId?: string | null
|
|
88
|
+
allowedJobKinds?: Array<string>
|
|
89
|
+
maxJobsPerDay?: number | null
|
|
90
|
+
jobsUsedToday?: number | null
|
|
91
|
+
budgetWindow?: string | null
|
|
92
|
+
validUntil?: __.CdsTimestamp | null
|
|
93
|
+
isActive?: boolean | null
|
|
94
|
+
} & InstanceType<TBase>
|
|
95
|
+
readonly kind: 'type';
|
|
96
|
+
readonly keys: __.KeysOf<GrantStatus>;
|
|
97
|
+
readonly elements: __.ElementsOf<GrantStatus>;
|
|
98
|
+
readonly actions: globalThis.Record<never, never>;
|
|
99
|
+
};
|
|
100
|
+
export class GrantStatus extends _GrantStatusAspect(__.Entity) {
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// entity 'IssuedGrant'
|
|
104
|
+
export declare function _IssuedGrantAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
|
|
105
|
+
new (...args: any[]): {
|
|
106
|
+
grantId?: string | null
|
|
107
|
+
token?: string | null
|
|
108
|
+
allowedActions?: Array<string>
|
|
109
|
+
walletId?: string | null
|
|
110
|
+
allowedJobKinds?: Array<string>
|
|
111
|
+
maxJobsPerDay?: number | null
|
|
112
|
+
validUntil?: __.CdsTimestamp | null
|
|
113
|
+
} & InstanceType<TBase>
|
|
114
|
+
readonly kind: 'type';
|
|
115
|
+
readonly keys: __.KeysOf<IssuedGrant>;
|
|
116
|
+
readonly elements: __.ElementsOf<IssuedGrant>;
|
|
117
|
+
readonly actions: globalThis.Record<never, never>;
|
|
118
|
+
};
|
|
119
|
+
export class IssuedGrant extends _IssuedGrantAspect(__.Entity) {
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
export declare const GetGrantStatus: {
|
|
124
|
+
// positional
|
|
125
|
+
(): globalThis.Promise<GrantStatus | null> | GrantStatus | null
|
|
126
|
+
// named
|
|
127
|
+
({}: globalThis.Record<never, never>): globalThis.Promise<GrantStatus | null> | GrantStatus | null
|
|
128
|
+
// metadata (do not use)
|
|
129
|
+
__parameters: globalThis.Record<never, never>, __returns: globalThis.Promise<GrantStatus | null> | GrantStatus | null, __self: never
|
|
130
|
+
kind: 'function'
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export declare const CreateAgentGrant: {
|
|
134
|
+
// positional
|
|
135
|
+
(allowedActions: Array<string>, walletId: string | null, allowedJobKinds: Array<string>, maxJobsPerDay: number | null, validUntil: __.CdsTimestamp | null, agentLabel: string | null): globalThis.Promise<IssuedGrant | null> | IssuedGrant | null
|
|
136
|
+
// named
|
|
137
|
+
({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
|
|
138
|
+
// metadata (do not use)
|
|
139
|
+
__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
|
|
140
|
+
kind: 'action'
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export declare const RevokeAgentGrant: {
|
|
144
|
+
// positional
|
|
145
|
+
(grantId: string | null): globalThis.Promise<boolean | null> | boolean | null
|
|
146
|
+
// named
|
|
147
|
+
({grantId}: {grantId?: string | null}): globalThis.Promise<boolean | null> | boolean | null
|
|
148
|
+
// metadata (do not use)
|
|
149
|
+
__parameters: {grantId?: string | null}, __returns: globalThis.Promise<boolean | null> | boolean | null, __self: never
|
|
150
|
+
kind: 'action'
|
|
151
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
// events
|
|
17
|
+
// actions
|
|
18
|
+
module.exports.GetGrantStatus = 'GetGrantStatus'
|
|
19
|
+
module.exports.CreateAgentGrant = 'CreateAgentGrant'
|
|
20
|
+
module.exports.RevokeAgentGrant = 'RevokeAgentGrant'
|
|
21
|
+
// enums
|
|
@@ -958,3 +958,53 @@ 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
|
+
}
|
|
@@ -105,6 +105,9 @@ 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 }})
|
|
108
111
|
// events
|
|
109
112
|
// actions
|
|
110
113
|
// 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,6 +108,36 @@ 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
|
+
```
|
|
120
|
+
|
|
121
|
+
1. An **Admin** issues a grant (`POST /odata/v4/cardano-agent/CreateAgentGrant`): an allow list of
|
|
122
|
+
actions, optionally a worker `walletId` (required for `SubmitWalletJob`/`CancelJob`), allowed job
|
|
123
|
+
kinds, a daily budget and an expiry. The response carries the token `odat_…` **once**; the
|
|
124
|
+
server stores only its SHA-256.
|
|
125
|
+
2. The agent sends `x-agent-token: odat_…` on any of the six service paths. It runs as the principal
|
|
126
|
+
`agent:<grantId>` with the single role `agent-grant`, never as the operator: every
|
|
127
|
+
`@requires: 'Admin'` surface (pause/resume, HSM signing, grant administration) refuses it by
|
|
128
|
+
construction. Reads and compute-only actions are always allowed; allow-listed actions each cost
|
|
129
|
+
one budget unit per UTC day (a build is the service an agent buys); everything else is 403.
|
|
130
|
+
Wallet jobs are pinned to the grant's wallet and visible only to the grant that queued them.
|
|
131
|
+
3. `GET /odata/v4/cardano-agent/GetGrantStatus()` tells the agent what it may do and how much budget
|
|
132
|
+
is left; `RevokeAgentGrant` turns the token into an unknown token immediately.
|
|
133
|
+
|
|
134
|
+
Grantable: `Build*`, `SetCollateral`, `CreateSigningRequest`, `VerifySignature`, `Submit*`,
|
|
135
|
+
`CheckSubmissionStatus`, `SubmitWalletJob`, `CancelJob`. Never: `SignWithHsm*`, `Pause*`/`Resume*`,
|
|
136
|
+
`pauseCrawler`/`resumeCrawler`, grant administration.
|
|
137
|
+
|
|
138
|
+
Programmatic seams for other packages (`@odatano/x402` sells grants against a 402 payment):
|
|
139
|
+
`issueAgentGrant()`, `revokeAgentGrantById()`, `registerTransportLane()` from `@odatano/core`.
|
|
140
|
+
|
|
110
141
|
## Requirements
|
|
111
142
|
|
|
112
143
|
- **Node.js >= 22.5** and **@sap/cds >= 10** (peer dependency). CAP 9 hosts cannot load `@odatano/core@2`.
|
package/db/schema.cds
CHANGED
|
@@ -1631,3 +1631,75 @@ 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
|
+
}
|
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.5",
|
|
4
4
|
"description": "SAP CAP plugin for Cardano blockchain OData V4 integration",
|
|
5
5
|
"imports": {
|
|
6
6
|
"#cds-models/*": "./@cds-models/*/index.js"
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"axios": "^1.18.0",
|
|
46
46
|
"esbuild": "0.28.1",
|
|
47
47
|
"form-data": "^4.0.6",
|
|
48
|
-
"fast-uri": "^3.1.
|
|
48
|
+
"fast-uri": "^3.1.7",
|
|
49
49
|
"ws": "7.5.11",
|
|
50
50
|
"@sap/approuter": {
|
|
51
51
|
"body-parser": "^2.2.3"
|
package/src/index.d.ts
CHANGED
|
@@ -4,6 +4,12 @@ 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';
|
|
9
|
+
export { registerTransportLane } from '../srv/utils/agent-token-auth';
|
|
10
|
+
export type { TransportLane, LaneOutcome } from '../srv/utils/agent-token-auth';
|
|
11
|
+
export { loadAgentGrantsConfig } from '../srv/utils/agent-grants-config';
|
|
12
|
+
export type { AgentGrantsConfig } from '../srv/utils/agent-grants-config';
|
|
7
13
|
export type { HsmConfig, HsmSignResult } from '../srv/utils/types';
|
|
8
14
|
export { parseTransaction } from '../srv/cbor';
|
|
9
15
|
export type { ParsedTransaction, ParsedInput, ParsedOutput, ParsedAsset, ParsedWitnesses, } from '../srv/cbor';
|
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.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.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;
|
|
40
40
|
exports.initialize = initialize;
|
|
41
41
|
exports.shutdown = shutdown;
|
|
42
42
|
exports.getStatus = getStatus;
|
|
@@ -65,6 +65,22 @@ Object.defineProperty(exports, "shutdownAppContext", { enumerable: true, get: fu
|
|
|
65
65
|
// Re-export HSM signer for programmatic access
|
|
66
66
|
var hsm_signer_1 = require("../srv/blockchain/signing/hsm-signer");
|
|
67
67
|
Object.defineProperty(exports, "getHsmSigner", { enumerable: true, get: function () { return hsm_signer_1.getHsmSigner; } });
|
|
68
|
+
// Agent grants (v2.0, AGENT_GRANTS_DESIGN.md): the programmatic seams other
|
|
69
|
+
// packages build on — @odatano/x402 sells grants through issueAgentGrant and
|
|
70
|
+
// adds its payment lane through registerTransportLane.
|
|
71
|
+
var agent_grants_1 = require("../srv/utils/agent-grants");
|
|
72
|
+
Object.defineProperty(exports, "issueAgentGrant", { enumerable: true, get: function () { return agent_grants_1.issueAgentGrant; } });
|
|
73
|
+
Object.defineProperty(exports, "revokeAgentGrantById", { enumerable: true, get: function () { return agent_grants_1.revokeAgentGrantById; } });
|
|
74
|
+
Object.defineProperty(exports, "hashAgentToken", { enumerable: true, get: function () { return agent_grants_1.hashAgentToken; } });
|
|
75
|
+
Object.defineProperty(exports, "AGENT_TOKEN_HEADER", { enumerable: true, get: function () { return agent_grants_1.AGENT_TOKEN_HEADER; } });
|
|
76
|
+
Object.defineProperty(exports, "AGENT_TOKEN_PREFIX", { enumerable: true, get: function () { return agent_grants_1.AGENT_TOKEN_PREFIX; } });
|
|
77
|
+
Object.defineProperty(exports, "AGENT_ROLE", { enumerable: true, get: function () { return agent_grants_1.AGENT_ROLE; } });
|
|
78
|
+
Object.defineProperty(exports, "AGENT_ALLOWLISTABLE_ACTIONS", { enumerable: true, get: function () { return agent_grants_1.AGENT_ALLOWLISTABLE_ACTIONS; } });
|
|
79
|
+
Object.defineProperty(exports, "AGENT_ALWAYS_ALLOWED_EVENTS", { enumerable: true, get: function () { return agent_grants_1.AGENT_ALWAYS_ALLOWED_EVENTS; } });
|
|
80
|
+
var agent_token_auth_1 = require("../srv/utils/agent-token-auth");
|
|
81
|
+
Object.defineProperty(exports, "registerTransportLane", { enumerable: true, get: function () { return agent_token_auth_1.registerTransportLane; } });
|
|
82
|
+
var agent_grants_config_1 = require("../srv/utils/agent-grants-config");
|
|
83
|
+
Object.defineProperty(exports, "loadAgentGrantsConfig", { enumerable: true, get: function () { return agent_grants_config_1.loadAgentGrantsConfig; } });
|
|
68
84
|
// Re-export pure CBOR utilities (no CAP round-trip needed)
|
|
69
85
|
var cbor_1 = require("../srv/cbor");
|
|
70
86
|
Object.defineProperty(exports, "parseTransaction", { enumerable: true, get: function () { return cbor_1.parseTransaction; } });
|
package/src/plugin.js
CHANGED
|
@@ -52,32 +52,46 @@ if (!cds_1.default.env.requires) {
|
|
|
52
52
|
if (!cds_1.default.env.requires.kinds) {
|
|
53
53
|
cds_1.default.env.requires.kinds = {};
|
|
54
54
|
}
|
|
55
|
+
/** The schema and the six CDS services this package ships, package-qualified. */
|
|
56
|
+
const PLUGIN_MODEL = [
|
|
57
|
+
'@odatano/core/db/schema',
|
|
58
|
+
'@odatano/core/srv/cardano-service',
|
|
59
|
+
'@odatano/core/srv/cardano-tx-service',
|
|
60
|
+
'@odatano/core/srv/cardano-sign-service',
|
|
61
|
+
'@odatano/core/srv/cardano-indexer-service',
|
|
62
|
+
'@odatano/core/srv/cardano-worker-service',
|
|
63
|
+
'@odatano/core/srv/cardano-agent-service'
|
|
64
|
+
];
|
|
65
|
+
/** Relative `@impl` values used in the CDS files (rewritten in plugin mode, see below). */
|
|
66
|
+
const IMPL_PATHS = [
|
|
67
|
+
'srv/cardano-service',
|
|
68
|
+
'srv/cardano-tx-service',
|
|
69
|
+
'srv/cardano-sign-service',
|
|
70
|
+
'srv/cardano-indexer-service',
|
|
71
|
+
'srv/cardano-worker-service',
|
|
72
|
+
'srv/cardano-agent-service'
|
|
73
|
+
];
|
|
55
74
|
cds_1.default.env.requires.kinds['odatano-core'] = {
|
|
56
75
|
impl: '@odatano/core',
|
|
57
|
-
model: [
|
|
58
|
-
'@odatano/core/db/schema',
|
|
59
|
-
'@odatano/core/srv/cardano-service',
|
|
60
|
-
'@odatano/core/srv/cardano-tx-service',
|
|
61
|
-
'@odatano/core/srv/cardano-sign-service',
|
|
62
|
-
'@odatano/core/srv/cardano-indexer-service',
|
|
63
|
-
'@odatano/core/srv/cardano-worker-service'
|
|
64
|
-
]
|
|
76
|
+
model: [...PLUGIN_MODEL]
|
|
65
77
|
};
|
|
66
78
|
// CRITICAL: Also set model directly on the requires entry.
|
|
67
79
|
// CAP's _link_required_services() merges kind→requires BEFORE cds-plugin.js runs,
|
|
68
80
|
// so the model array on the kind is never merged. Set it directly.
|
|
69
81
|
const req = cds_1.default.env.requires['odatano-core'];
|
|
70
82
|
if (req) {
|
|
71
|
-
req.model = [
|
|
72
|
-
'@odatano/core/db/schema',
|
|
73
|
-
'@odatano/core/srv/cardano-service',
|
|
74
|
-
'@odatano/core/srv/cardano-tx-service',
|
|
75
|
-
'@odatano/core/srv/cardano-sign-service',
|
|
76
|
-
'@odatano/core/srv/cardano-indexer-service',
|
|
77
|
-
'@odatano/core/srv/cardano-worker-service'
|
|
78
|
-
];
|
|
83
|
+
req.model = [...PLUGIN_MODEL];
|
|
79
84
|
}
|
|
80
85
|
logger.debug('Plugin registered');
|
|
86
|
+
/**
|
|
87
|
+
* Agent grants (AGENT_GRANTS_DESIGN.md). Off by default; switched on by
|
|
88
|
+
* cds.requires.odatano-core.agentGrants.enabled / AGENT_GRANTS_ENABLED=true.
|
|
89
|
+
* Has to run at plugin load, before CAP builds its middlewares (the auth impl
|
|
90
|
+
* is swapped here). srv/server.ts makes the same call for standalone mode, where
|
|
91
|
+
* this file is never loaded; the call is idempotent and never throws.
|
|
92
|
+
*/
|
|
93
|
+
require('../srv/utils/agent-grants-config')
|
|
94
|
+
.activateAgentGrants();
|
|
81
95
|
/**
|
|
82
96
|
* Rewrite @impl paths for plugin mode.
|
|
83
97
|
* CDS files use relative @impl (e.g. 'srv/cardano-service') which resolves from cds.root.
|
|
@@ -90,20 +104,9 @@ cds_1.default.on('loaded', (model) => {
|
|
|
90
104
|
return;
|
|
91
105
|
const defs = model.definitions ?? {};
|
|
92
106
|
for (const def of Object.values(defs)) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
else if (def['@impl'] === 'srv/cardano-tx-service') {
|
|
97
|
-
def['@impl'] = '@odatano/core/srv/cardano-tx-service';
|
|
98
|
-
}
|
|
99
|
-
else if (def['@impl'] === 'srv/cardano-sign-service') {
|
|
100
|
-
def['@impl'] = '@odatano/core/srv/cardano-sign-service';
|
|
101
|
-
}
|
|
102
|
-
else if (def['@impl'] === 'srv/cardano-indexer-service') {
|
|
103
|
-
def['@impl'] = '@odatano/core/srv/cardano-indexer-service';
|
|
104
|
-
}
|
|
105
|
-
else if (def['@impl'] === 'srv/cardano-worker-service') {
|
|
106
|
-
def['@impl'] = '@odatano/core/srv/cardano-worker-service';
|
|
107
|
+
const impl = def['@impl'];
|
|
108
|
+
if (impl && IMPL_PATHS.includes(impl)) {
|
|
109
|
+
def['@impl'] = `@odatano/core/${impl}`;
|
|
107
110
|
}
|
|
108
111
|
}
|
|
109
112
|
});
|
|
@@ -28,6 +28,13 @@ export interface TrackedJob {
|
|
|
28
28
|
submittedAt: string;
|
|
29
29
|
foundSlot: number | null;
|
|
30
30
|
foundHeight: number | null;
|
|
31
|
+
/**
|
|
32
|
+
* Polling round in which the tx was last SEEN on-chain (found or
|
|
33
|
+
* re-validated). A job found in the current round needs no second lookup
|
|
34
|
+
* before it is confirmed; one found in an earlier round is re-checked, so a
|
|
35
|
+
* rollback the crawler did not report (crawler off) cannot slip through.
|
|
36
|
+
*/
|
|
37
|
+
seenRound?: number;
|
|
31
38
|
}
|
|
32
39
|
export interface ConfirmationTrackerOptions {
|
|
33
40
|
confirmationDepth: number;
|
|
@@ -59,6 +66,8 @@ export declare class ConfirmationTracker {
|
|
|
59
66
|
private running;
|
|
60
67
|
private polling;
|
|
61
68
|
private lastKnownTipHeight;
|
|
69
|
+
/** Polling round counter; see TrackedJob.seenRound. */
|
|
70
|
+
private round;
|
|
62
71
|
constructor(deps: ConfirmationTrackerDeps);
|
|
63
72
|
start(): void;
|
|
64
73
|
stop(): void;
|
|
@@ -77,10 +86,32 @@ export declare class ConfirmationTracker {
|
|
|
77
86
|
}): void;
|
|
78
87
|
private onBlockIndexed;
|
|
79
88
|
private onReorg;
|
|
89
|
+
/**
|
|
90
|
+
* The recorded inclusion is gone (a reorg the crawler reported, or a polling
|
|
91
|
+
* re-check that no longer finds the tx): back to watching, and optionally
|
|
92
|
+
* re-submit the SAME signed CBOR — never a rebuild, that is the double-spend
|
|
93
|
+
* guard. "Already known" means the tx survived into the new chain's mempool;
|
|
94
|
+
* that is success, not an error.
|
|
95
|
+
*/
|
|
96
|
+
private forgetInclusion;
|
|
80
97
|
/** One polling round. Public for tests; guarded against overlapping rounds. */
|
|
81
98
|
pollOnce(): Promise<void>;
|
|
82
|
-
/**
|
|
99
|
+
/**
|
|
100
|
+
* Confirm every found job whose depth requirement is met by the known tip.
|
|
101
|
+
* `revalidate` (polling path): an inclusion not seen in THIS round is looked
|
|
102
|
+
* up again first — the crawler's reorg events are the only rollback signal,
|
|
103
|
+
* and with the crawler off there is none, so a tx that was found at height N
|
|
104
|
+
* and then rolled back would otherwise be confirmed on the tip alone.
|
|
105
|
+
*/
|
|
83
106
|
private confirmMature;
|
|
107
|
+
/**
|
|
108
|
+
* Is the tx still on-chain, and still deep enough? Re-reads it; a tx that
|
|
109
|
+
* moved to another block (re-included after a rollback) gets its new point
|
|
110
|
+
* and is judged at the new height; one that is gone is forgotten (back to
|
|
111
|
+
* watching, optional same-CBOR re-submit) and the tip is re-learned next
|
|
112
|
+
* round, because the pre-rollback tip may overstate the depth.
|
|
113
|
+
*/
|
|
114
|
+
private stillIncluded;
|
|
84
115
|
private finalize;
|
|
85
116
|
}
|
|
86
117
|
//# sourceMappingURL=confirmation-tracker.d.ts.map
|