@odatano/core 2.0.0-rc.3 → 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/CardanoTransactionService/index.d.ts +9 -9
- 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 +173 -173
- package/src/index.d.ts +6 -0
- package/src/index.js +17 -1
- package/src/plugin.js +33 -30
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +20 -0
- package/srv/blockchain/transaction-building/buildooor-tx.js +104 -20
- package/srv/blockchain/wallet-worker/build-request.js +35 -6
- 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/cardano-tx-service.cds +32 -26
- package/srv/cardano-tx-service.js +96 -38
- 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
- package/srv/utils/tx-request-parsers.d.ts +13 -0
- package/srv/utils/tx-request-parsers.js +32 -0
- package/srv/utils/types.d.ts +15 -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
|
|
@@ -196,17 +196,17 @@ export declare function _TransactionSubmissionAspect<TBase extends new (...args:
|
|
|
196
196
|
};
|
|
197
197
|
/**
|
|
198
198
|
* TransactionSubmissions status flow:
|
|
199
|
-
* pending
|
|
200
|
-
* submitted
|
|
201
|
-
* pending | submitted
|
|
199
|
+
* pending -> [submit to chain] -> submitted (internal, in SubmitTransaction handler)
|
|
200
|
+
* submitted -> [CheckSubmissionStatus] confirmed | stays submitted (conditional)
|
|
201
|
+
* pending | submitted -> failed (blockchain error)
|
|
202
202
|
*/
|
|
203
203
|
export class TransactionSubmission extends _TransactionSubmissionAspect(__.Entity) {
|
|
204
204
|
}
|
|
205
205
|
/**
|
|
206
206
|
* TransactionSubmissions status flow:
|
|
207
|
-
* pending
|
|
208
|
-
* submitted
|
|
209
|
-
* pending | submitted
|
|
207
|
+
* pending -> [submit to chain] -> submitted (internal, in SubmitTransaction handler)
|
|
208
|
+
* submitted -> [CheckSubmissionStatus] confirmed | stays submitted (conditional)
|
|
209
|
+
* pending | submitted -> failed (blockchain error)
|
|
210
210
|
*/
|
|
211
211
|
export class TransactionSubmissions extends Array<TransactionSubmission> {
|
|
212
212
|
$count?: number
|
|
@@ -420,11 +420,11 @@ export declare const BuildMultiAssetTransaction: {
|
|
|
420
420
|
|
|
421
421
|
export declare const BuildMintTransaction: {
|
|
422
422
|
// positional
|
|
423
|
-
(senderAddress: _.Bech32 | null, recipientAddress: _.Bech32 | null, lovelaceAmount: _.Lovelace | null, mintActionsJson: string | null, mintingPolicyScript: string | null, changeAddress: _.Bech32 | null, requiredSignersJson: string | null, scriptParamsJson: string | null, inlineDatumJson: string | null, mintRedeemerJson: string | null, lockOnScript: boolean | null, forceInputsJson: string | null, referenceInputsJson: string | null, metadataJson: string | null, referenceScriptHex: string | null, validityStartMs: string | null, validityEndMs: string | null): globalThis.Promise<TransactionBuild | null> | TransactionBuild | null
|
|
423
|
+
(senderAddress: _.Bech32 | null, recipientAddress: _.Bech32 | null, lovelaceAmount: _.Lovelace | null, mintActionsJson: string | null, mintingPolicyScript: string | null, changeAddress: _.Bech32 | null, requiredSignersJson: string | null, scriptParamsJson: string | null, inlineDatumJson: string | null, mintRedeemerJson: string | null, lockOnScript: boolean | null, forceInputsJson: string | null, referenceInputsJson: string | null, extraOutputsJson: string | null, metadataJson: string | null, referenceScriptHex: string | null, validityStartMs: string | null, validityEndMs: string | null): globalThis.Promise<TransactionBuild | null> | TransactionBuild | null
|
|
424
424
|
// named
|
|
425
|
-
({senderAddress, recipientAddress, lovelaceAmount, mintActionsJson, mintingPolicyScript, changeAddress, requiredSignersJson, scriptParamsJson, inlineDatumJson, mintRedeemerJson, lockOnScript, forceInputsJson, referenceInputsJson, metadataJson, referenceScriptHex, validityStartMs, validityEndMs}: {senderAddress?: _.Bech32 | null, recipientAddress?: _.Bech32 | null, lovelaceAmount?: _.Lovelace | null, mintActionsJson?: string | null, mintingPolicyScript?: string | null, changeAddress?: _.Bech32 | null, requiredSignersJson?: string | null, scriptParamsJson?: string | null, inlineDatumJson?: string | null, mintRedeemerJson?: string | null, lockOnScript?: boolean | null, forceInputsJson?: string | null, referenceInputsJson?: string | null, metadataJson?: string | null, referenceScriptHex?: string | null, validityStartMs?: string | null, validityEndMs?: string | null}): globalThis.Promise<TransactionBuild | null> | TransactionBuild | null
|
|
425
|
+
({senderAddress, recipientAddress, lovelaceAmount, mintActionsJson, mintingPolicyScript, changeAddress, requiredSignersJson, scriptParamsJson, inlineDatumJson, mintRedeemerJson, lockOnScript, forceInputsJson, referenceInputsJson, extraOutputsJson, metadataJson, referenceScriptHex, validityStartMs, validityEndMs}: {senderAddress?: _.Bech32 | null, recipientAddress?: _.Bech32 | null, lovelaceAmount?: _.Lovelace | null, mintActionsJson?: string | null, mintingPolicyScript?: string | null, changeAddress?: _.Bech32 | null, requiredSignersJson?: string | null, scriptParamsJson?: string | null, inlineDatumJson?: string | null, mintRedeemerJson?: string | null, lockOnScript?: boolean | null, forceInputsJson?: string | null, referenceInputsJson?: string | null, extraOutputsJson?: string | null, metadataJson?: string | null, referenceScriptHex?: string | null, validityStartMs?: string | null, validityEndMs?: string | null}): globalThis.Promise<TransactionBuild | null> | TransactionBuild | null
|
|
426
426
|
// metadata (do not use)
|
|
427
|
-
__parameters: {senderAddress?: _.Bech32 | null, recipientAddress?: _.Bech32 | null, lovelaceAmount?: _.Lovelace | null, mintActionsJson?: string | null, mintingPolicyScript?: string | null, changeAddress?: _.Bech32 | null, requiredSignersJson?: string | null, scriptParamsJson?: string | null, inlineDatumJson?: string | null, mintRedeemerJson?: string | null, lockOnScript?: boolean | null, forceInputsJson?: string | null, referenceInputsJson?: string | null, metadataJson?: string | null, referenceScriptHex?: string | null, validityStartMs?: string | null, validityEndMs?: string | null}, __returns: globalThis.Promise<TransactionBuild | null> | TransactionBuild | null, __self: never
|
|
427
|
+
__parameters: {senderAddress?: _.Bech32 | null, recipientAddress?: _.Bech32 | null, lovelaceAmount?: _.Lovelace | null, mintActionsJson?: string | null, mintingPolicyScript?: string | null, changeAddress?: _.Bech32 | null, requiredSignersJson?: string | null, scriptParamsJson?: string | null, inlineDatumJson?: string | null, mintRedeemerJson?: string | null, lockOnScript?: boolean | null, forceInputsJson?: string | null, referenceInputsJson?: string | null, extraOutputsJson?: string | null, metadataJson?: string | null, referenceScriptHex?: string | null, validityStartMs?: string | null, validityEndMs?: string | null}, __returns: globalThis.Promise<TransactionBuild | null> | TransactionBuild | null, __self: never
|
|
428
428
|
kind: 'action'
|
|
429
429
|
}
|
|
430
430
|
|
|
@@ -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
|
+
}
|