@odatano/core 2.0.0-rc.5 → 2.0.0-rc.51
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 +99 -51
- package/@cds-models/CardanoAgentService/index.js +15 -0
- package/@cds-models/CardanoBackendService/index.d.ts +358 -0
- package/@cds-models/CardanoBackendService/index.js +41 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +594 -11
- package/@cds-models/CardanoIndexerService/index.js +74 -0
- package/@cds-models/CardanoODataService/index.d.ts +417 -57
- package/@cds-models/CardanoODataService/index.js +42 -0
- package/@cds-models/CardanoSignService/index.d.ts +45 -19
- package/@cds-models/CardanoSignService/index.js +4 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +70 -44
- package/@cds-models/CardanoTransactionService/index.js +5 -0
- package/@cds-models/CardanoWorkerService/index.d.ts +35 -22
- package/@cds-models/CardanoWorkerService/index.js +2 -0
- package/@cds-models/index.d.ts +114 -4
- package/@cds-models/index.js +20 -4
- package/@cds-models/odatano/cardano/index.d.ts +451 -32
- package/@cds-models/odatano/cardano/index.js +48 -0
- package/README.md +103 -167
- package/db/schema.cds +2455 -1705
- package/db/types.cds +456 -295
- package/package.json +41 -53
- package/scripts/deploy-schema.mjs +113 -0
- package/scripts/migrate-schema.mjs +528 -0
- package/scripts/migrate-slot-leader.mjs +96 -0
- package/src/index.d.ts +20 -21
- package/src/index.js +45 -31
- package/src/plugin.js +17 -35
- package/srv/blockchain/asset-decimals.d.ts +7 -0
- package/srv/blockchain/asset-decimals.js +91 -0
- package/srv/blockchain/backends/blockfrost-backend.d.ts +25 -137
- package/srv/blockchain/backends/blockfrost-backend.js +125 -215
- package/srv/blockchain/backends/call-signal.d.ts +7 -0
- package/srv/blockchain/backends/call-signal.js +22 -0
- package/srv/blockchain/backends/cardano-backend.d.ts +100 -189
- package/srv/blockchain/backends/cardano-backend.js +29 -5
- package/srv/blockchain/backends/koios-backend.d.ts +108 -170
- package/srv/blockchain/backends/koios-backend.js +488 -482
- package/srv/blockchain/backends/odatano-backend.d.ts +55 -0
- package/srv/blockchain/backends/odatano-backend.js +211 -0
- package/srv/blockchain/backends/ogmios-backend.d.ts +122 -190
- package/srv/blockchain/backends/ogmios-backend.js +683 -327
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +14 -0
- package/srv/blockchain/backends/ogmios-frame-guard.js +89 -0
- package/srv/blockchain/cardano-client.d.ts +71 -241
- package/srv/blockchain/cardano-client.js +354 -322
- package/srv/blockchain/cardano-indexer.d.ts +295 -283
- package/srv/blockchain/cardano-indexer.js +1690 -502
- package/srv/blockchain/cardano-tx-builder.d.ts +25 -89
- package/srv/blockchain/cardano-tx-builder.js +164 -140
- package/srv/blockchain/circuit-breaker.d.ts +2 -13
- package/srv/blockchain/circuit-breaker.js +11 -15
- package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
- package/srv/blockchain/crawler/account-snapshots.js +173 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +17 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
- package/srv/blockchain/crawler/asset-registry-backfill.d.ts +46 -0
- package/srv/blockchain/crawler/asset-registry-backfill.js +157 -0
- package/srv/blockchain/crawler/asset-slice-backfill.d.ts +35 -0
- package/srv/blockchain/crawler/asset-slice-backfill.js +149 -0
- package/srv/blockchain/crawler/certificate-backfill.d.ts +56 -0
- package/srv/blockchain/crawler/certificate-backfill.js +174 -0
- package/srv/blockchain/crawler/crawler.d.ts +125 -81
- package/srv/blockchain/crawler/crawler.js +738 -167
- package/srv/blockchain/crawler/credential-backfill.d.ts +30 -0
- package/srv/blockchain/crawler/credential-backfill.js +101 -0
- package/srv/blockchain/crawler/hooks.d.ts +2 -17
- package/srv/blockchain/crawler/index.d.ts +1 -8
- package/srv/blockchain/crawler/index.js +31 -17
- package/srv/blockchain/crawler/input-asset-copies.d.ts +34 -0
- package/srv/blockchain/crawler/input-asset-copies.js +161 -0
- package/srv/blockchain/crawler/key-pages.d.ts +12 -0
- package/srv/blockchain/crawler/key-pages.js +48 -0
- package/srv/blockchain/crawler/metadata-position-backfill.d.ts +22 -0
- package/srv/blockchain/crawler/metadata-position-backfill.js +59 -0
- package/srv/blockchain/crawler/output-datum-backfill.d.ts +41 -0
- package/srv/blockchain/crawler/output-datum-backfill.js +100 -0
- package/srv/blockchain/crawler/sync-state.d.ts +31 -47
- package/srv/blockchain/crawler/sync-state.js +135 -128
- package/srv/blockchain/crawler/transaction-backfill.d.ts +46 -0
- package/srv/blockchain/crawler/transaction-backfill.js +271 -0
- package/srv/blockchain/crawler/utxo-set-import.d.ts +66 -0
- package/srv/blockchain/crawler/utxo-set-import.js +399 -0
- package/srv/blockchain/crawler/window-plan.d.ts +31 -0
- package/srv/blockchain/crawler/window-plan.js +59 -0
- package/srv/blockchain/ledger-state.d.ts +62 -0
- package/srv/blockchain/ledger-state.js +521 -0
- package/srv/blockchain/pending-spends.d.ts +16 -0
- package/srv/blockchain/pending-spends.js +81 -0
- package/srv/blockchain/pool-metadata.d.ts +15 -0
- package/srv/blockchain/pool-metadata.js +132 -0
- package/srv/blockchain/request-coalescer.d.ts +2 -16
- package/srv/blockchain/request-coalescer.js +2 -16
- package/srv/blockchain/signing/cose-verifier.d.ts +3 -17
- package/srv/blockchain/signing/cose-verifier.js +146 -70
- package/srv/blockchain/signing/external-signer.d.ts +15 -115
- package/srv/blockchain/signing/external-signer.js +22 -131
- package/srv/blockchain/signing/failed-recheck.d.ts +17 -0
- package/srv/blockchain/signing/failed-recheck.js +135 -0
- package/srv/blockchain/signing/hsm-signer.d.ts +10 -54
- package/srv/blockchain/signing/hsm-signer.js +28 -79
- package/srv/blockchain/signing/landing-proof.d.ts +60 -0
- package/srv/blockchain/signing/landing-proof.js +224 -0
- package/srv/blockchain/signing/signature-verifier.d.ts +9 -47
- package/srv/blockchain/signing/signature-verifier.js +71 -87
- package/srv/blockchain/signing/submission-finalizer.d.ts +37 -45
- package/srv/blockchain/signing/submission-finalizer.js +280 -86
- package/srv/blockchain/stored-chain.d.ts +19 -0
- package/srv/blockchain/stored-chain.js +258 -0
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +31 -229
- package/srv/blockchain/transaction-building/buildooor-tx.js +663 -421
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +9 -37
- package/srv/blockchain/transaction-presence.d.ts +12 -0
- package/srv/blockchain/transaction-presence.js +29 -0
- package/srv/blockchain/transaction-rows.d.ts +12 -0
- package/srv/blockchain/transaction-rows.js +44 -0
- package/srv/blockchain/wallet-worker/build-request.d.ts +8 -23
- package/srv/blockchain/wallet-worker/build-request.js +40 -353
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +27 -47
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +158 -61
- package/srv/blockchain/wallet-worker/index.d.ts +1 -1
- package/srv/blockchain/wallet-worker/index.js +3 -11
- package/srv/blockchain/wallet-worker/invalidation.d.ts +35 -0
- package/srv/blockchain/wallet-worker/invalidation.js +128 -0
- package/srv/blockchain/wallet-worker/job-store.d.ts +58 -150
- package/srv/blockchain/wallet-worker/job-store.js +200 -273
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -26
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -28
- package/srv/blockchain/wallet-worker/signers.d.ts +5 -24
- package/srv/blockchain/wallet-worker/signers.js +4 -12
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +29 -82
- package/srv/blockchain/wallet-worker/wallet-worker.js +334 -198
- package/srv/cardano-agent-service.cds +122 -84
- package/srv/cardano-agent-service.js +12 -9
- package/srv/cardano-backend-service.cds +81 -0
- package/srv/cardano-backend-service.d.ts +2 -0
- package/srv/cardano-backend-service.js +259 -0
- package/srv/cardano-indexer-service.cds +393 -18
- package/srv/cardano-indexer-service.d.ts +5 -1
- package/srv/cardano-indexer-service.js +477 -16
- package/srv/cardano-service.cds +426 -269
- package/srv/cardano-service.js +640 -217
- package/srv/cardano-sign-service.cds +211 -180
- package/srv/cardano-sign-service.js +210 -287
- package/srv/cardano-tx-service.cds +462 -370
- package/srv/cardano-tx-service.js +283 -800
- package/srv/cardano-ui.cds +16 -16
- package/srv/cardano-worker-service.cds +141 -125
- package/srv/cardano-worker-service.js +104 -61
- package/srv/cbor/cip68.d.ts +13 -0
- package/srv/cbor/cip68.js +56 -0
- package/srv/cbor/index.d.ts +3 -1
- package/srv/cbor/index.js +9 -1
- package/srv/cbor/parse.d.ts +30 -18
- package/srv/cbor/parse.js +44 -9
- package/srv/cbor/plutus-data-json.d.ts +20 -0
- package/srv/cbor/plutus-data-json.js +32 -0
- package/srv/config.d.ts +117 -0
- package/srv/config.js +419 -0
- package/srv/server.d.ts +15 -110
- package/srv/server.js +83 -405
- package/srv/utils/agent-access.d.ts +11 -0
- package/srv/utils/agent-access.js +86 -0
- package/srv/utils/agent-grants-config.d.ts +0 -46
- package/srv/utils/agent-grants-config.js +17 -85
- package/srv/utils/agent-grants.d.ts +106 -122
- package/srv/utils/agent-grants.js +538 -237
- package/srv/utils/agent-token-auth.d.ts +4 -99
- package/srv/utils/agent-token-auth.js +62 -186
- package/srv/utils/backend-request-handler.d.ts +3 -17
- package/srv/utils/backend-request-handler.js +3 -18
- package/srv/utils/build-request.d.ts +52 -0
- package/srv/utils/build-request.js +487 -0
- package/srv/utils/collections.d.ts +4 -10
- package/srv/utils/collections.js +14 -10
- package/srv/utils/const.d.ts +32 -75
- package/srv/utils/const.js +40 -80
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +11 -25
- package/srv/utils/db-indexes.d.ts +31 -0
- package/srv/utils/db-indexes.js +185 -0
- package/srv/utils/db-kind.d.ts +23 -0
- package/srv/utils/db-kind.js +42 -0
- package/srv/utils/db-sanitize.d.ts +20 -0
- package/srv/utils/db-sanitize.js +80 -0
- package/srv/utils/deep-json.d.ts +6 -0
- package/srv/utils/deep-json.js +240 -0
- package/srv/utils/detached-run.d.ts +41 -0
- package/srv/utils/detached-run.js +101 -0
- package/srv/utils/epoch-slots.d.ts +14 -0
- package/srv/utils/epoch-slots.js +45 -0
- package/srv/utils/error-codes.d.ts +26 -75
- package/srv/utils/error-codes.js +27 -72
- package/srv/utils/errors.d.ts +55 -187
- package/srv/utils/errors.js +161 -235
- package/srv/utils/lease.d.ts +20 -0
- package/srv/utils/lease.js +62 -0
- package/srv/utils/liveness.d.ts +12 -0
- package/srv/utils/liveness.js +35 -0
- package/srv/utils/mappers.d.ts +111 -223
- package/srv/utils/mappers.js +432 -371
- package/srv/utils/navigation.d.ts +17 -0
- package/srv/utils/navigation.js +52 -0
- package/srv/utils/network-context.d.ts +0 -1
- package/srv/utils/network-context.js +9 -15
- package/srv/utils/paging.d.ts +31 -0
- package/srv/utils/paging.js +43 -0
- package/srv/utils/pg-inline-json.d.ts +8 -0
- package/srv/utils/pg-inline-json.js +58 -0
- package/srv/utils/pg-order-nulls.d.ts +14 -0
- package/srv/utils/pg-order-nulls.js +54 -0
- package/srv/utils/plutus-placeholders.d.ts +16 -22
- package/srv/utils/plutus-placeholders.js +62 -33
- package/srv/utils/rate-limiter.d.ts +2 -21
- package/srv/utils/rate-limiter.js +5 -17
- package/srv/utils/readiness.d.ts +12 -0
- package/srv/utils/readiness.js +29 -0
- package/srv/utils/reference-script.d.ts +19 -0
- package/srv/utils/reference-script.js +84 -0
- package/srv/utils/resolution.d.ts +13 -0
- package/srv/utils/resolution.js +47 -0
- package/srv/utils/result-numbers.d.ts +15 -0
- package/srv/utils/result-numbers.js +61 -0
- package/srv/utils/row-values.d.ts +7 -0
- package/srv/utils/row-values.js +27 -0
- package/srv/utils/service-events.d.ts +0 -24
- package/srv/utils/service-events.js +3 -25
- package/srv/utils/signing-helper.d.ts +3 -20
- package/srv/utils/signing-helper.js +35 -64
- package/srv/utils/tx-build-helper.d.ts +25 -105
- package/srv/utils/tx-build-helper.js +108 -156
- package/srv/utils/tx-request-parsers.d.ts +82 -33
- package/srv/utils/tx-request-parsers.js +401 -49
- package/srv/utils/tx-utils.d.ts +3 -27
- package/srv/utils/tx-utils.js +32 -50
- package/srv/utils/types.d.ts +294 -232
- package/srv/utils/types.js +2 -22
- package/srv/utils/validators.d.ts +22 -92
- package/srv/utils/validators.js +60 -170
|
@@ -1,106 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
* Transport authentication with lanes: CAP's configured strategy PLUS an
|
|
3
|
-
* `x-agent-token` lane (AGENT_GRANTS_DESIGN.md §3).
|
|
4
|
-
*
|
|
5
|
-
* CAP's auth middleware 401s a request without transport credentials before any
|
|
6
|
-
* service hook runs, so an agent holding only an `odat_` token could never
|
|
7
|
-
* reach a service. This middleware is installed as `cds.requires.auth.impl` by
|
|
8
|
-
* src/plugin.ts when `odatano-core.agentGrants.enabled` is set, and:
|
|
9
|
-
*
|
|
10
|
-
* - runs every registered LANE first. The built-in lane admits a request that
|
|
11
|
-
* carries `x-agent-token` on one of the six ODATANO service paths (exact
|
|
12
|
-
* segment match, no lookalike prefixes): the token is authenticated HERE
|
|
13
|
-
* (unknown 401, expired 410, non-leaking) and the request continues as the
|
|
14
|
-
* principal `agent:<grantId>` with the role `agent-grant`. The resolved grant
|
|
15
|
-
* rides on the express request (`req.agentGrant`) for the enforcement hook.
|
|
16
|
-
* Other packages (@odatano/x402) add lanes with `registerTransportLane`
|
|
17
|
-
* instead of fighting for the single `auth.impl` slot.
|
|
18
|
-
* - otherwise DELEGATES to CAP's own strategy for the configured kind
|
|
19
|
-
* (mocked/basic → basic-auth, jwt/xsuaa → jwt-auth, ias, dummy): behaviour
|
|
20
|
-
* for every request without a token is exactly what it was before.
|
|
21
|
-
*
|
|
22
|
-
* Failed token attempts are throttled per client address (20 per 15 minutes):
|
|
23
|
-
* one static hash lookup must not become an offline-speed guessing oracle.
|
|
24
|
-
*/
|
|
25
|
-
import cds from '@sap/cds';
|
|
26
|
-
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
27
|
-
import { type AgentGrantRow } from './agent-grants';
|
|
28
|
-
type ExpressReq = IncomingMessage & {
|
|
29
|
-
headers: Record<string, string | string[] | undefined>;
|
|
30
|
-
originalUrl?: string;
|
|
31
|
-
baseUrl?: string;
|
|
32
|
-
path?: string;
|
|
33
|
-
ip?: string;
|
|
34
|
-
user?: unknown;
|
|
35
|
-
agentGrant?: AgentGrantRow;
|
|
36
|
-
};
|
|
37
|
-
type ExpressRes = ServerResponse & {
|
|
38
|
-
status?: (code: number) => ExpressRes;
|
|
39
|
-
set?: (name: string, value: string) => ExpressRes;
|
|
40
|
-
json?: (body: unknown) => void;
|
|
41
|
-
};
|
|
42
|
-
type Next = (err?: unknown) => void;
|
|
43
|
-
export type AuthMiddleware = (req: ExpressReq, res: ExpressRes, next: Next) => unknown;
|
|
44
|
-
/** What a lane's `authenticate` may answer. */
|
|
45
|
-
export type LaneOutcome =
|
|
46
|
-
/** The lane authenticated the request; continue as this principal. */
|
|
47
|
-
{
|
|
48
|
-
user: cds.User;
|
|
49
|
-
}
|
|
50
|
-
/** The lane already sent a response (401/410/429); stop here. */
|
|
51
|
-
| {
|
|
52
|
-
handled: true;
|
|
53
|
-
}
|
|
54
|
-
/** Not this lane's request after all; try the next lane, then the delegate. */
|
|
55
|
-
| null;
|
|
56
|
-
export interface TransportLane {
|
|
57
|
-
/** Unique name; registering the same name twice replaces the lane. */
|
|
58
|
-
name: string;
|
|
59
|
-
/** Cheap check on headers/path; no I/O. */
|
|
60
|
-
match: (req: ExpressReq) => boolean;
|
|
61
|
-
/** Authenticate; may respond itself. */
|
|
62
|
-
authenticate: (req: ExpressReq, res: ExpressRes) => Promise<LaneOutcome>;
|
|
63
|
-
}
|
|
64
|
-
/** Add (or replace) a lane. Lanes run in registration order, the built-in agent-token lane first. */
|
|
65
|
-
export declare function registerTransportLane(lane: TransportLane): void;
|
|
66
|
-
/** Registered lane names, in order (tests, diagnostics). */
|
|
67
|
-
export declare function transportLanes(): string[];
|
|
68
|
-
/** Remove every lane except the built-in one (tests). */
|
|
69
|
-
export declare function __resetTransportLanesForTests(): void;
|
|
1
|
+
import { type TransportLane } from '@odatano/cap-auth';
|
|
70
2
|
/** Test seam: pin the service paths instead of reading `cds.services`. `null` resets. */
|
|
71
3
|
export declare function __setAgentServicePathsForTests(paths: string[] | null): void;
|
|
4
|
+
/** Forget throttle state and the path cache (tests). */
|
|
5
|
+
export declare function __resetAgentTokenLaneForTests(): void;
|
|
72
6
|
/** Mount paths of the six services, read from `cds.services` once they are served. */
|
|
73
7
|
export declare function agentServicePaths(): string[];
|
|
74
|
-
/** Exact segment boundary: `/odata/v4/cardano
|
|
8
|
+
/** Exact segment boundary: `/odata/v4/cardano` and below, never `/odata/v4/cardano-evil`. */
|
|
75
9
|
export declare function inAgentLane(path: string, servicePaths?: string[]): boolean;
|
|
76
10
|
export declare const agentTokenLane: TransportLane;
|
|
77
|
-
interface AuthOptions {
|
|
78
|
-
kind?: string;
|
|
79
|
-
impl?: string;
|
|
80
|
-
/** Set by activateAgentGrants: the strategy that keeps authenticating non-token requests. */
|
|
81
|
-
agentGrantsDelegate?: string;
|
|
82
|
-
/**
|
|
83
|
-
* Set by activateAgentGrants when the host had its own `auth.impl` before us:
|
|
84
|
-
* that module (path as configured, resolved like CAP does it) is the delegate,
|
|
85
|
-
* whatever `kind` says. The host's gate keeps running for every non-token
|
|
86
|
-
* request, on every path.
|
|
87
|
-
*/
|
|
88
|
-
agentGrantsDelegateImpl?: string;
|
|
89
|
-
[key: string]: unknown;
|
|
90
|
-
}
|
|
91
|
-
/** Load CAP's own middleware for `kind`; exported so the wrapper can be unit-tested with a stub. */
|
|
92
|
-
/**
|
|
93
|
-
* Resolve a host-configured `auth.impl` the way CAP's auth factory does
|
|
94
|
-
* (@sap/cds/lib/srv/middlewares/auth/index.js): as a module relative to
|
|
95
|
-
* cds.root, else with a `./` prefix. Exported for the unit tests.
|
|
96
|
-
*/
|
|
97
|
-
export declare function resolveCustomImpl(impl: string, root?: string): string;
|
|
98
|
-
export declare function loadDelegate(options: AuthOptions, kind: string): AuthMiddleware;
|
|
99
|
-
export declare function createAgentTokenAuth(options: AuthOptions, delegate?: AuthMiddleware): AuthMiddleware;
|
|
100
|
-
/**
|
|
101
|
-
* CAP requires this module and, seeing a function with fewer than three
|
|
102
|
-
* parameters, calls it with the merged auth options to obtain the middleware.
|
|
103
|
-
*/
|
|
104
|
-
export default function agentTokenAuthFactory(options: AuthOptions): AuthMiddleware;
|
|
105
|
-
export {};
|
|
106
11
|
//# sourceMappingURL=agent-token-auth.d.ts.map
|
|
@@ -1,78 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
2
|
+
// A token on a service path runs as `agent:<grantId>` with role `agent-grant`. Other paths go to the delegate.
|
|
3
|
+
// Unknown tokens get 401, expired ones 410. Failed attempts are throttled per client address.
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
+
var ownKeys = function(o) {
|
|
22
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
+
var ar = [];
|
|
24
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
+
return ar;
|
|
26
|
+
};
|
|
27
|
+
return ownKeys(o);
|
|
28
|
+
};
|
|
29
|
+
return function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
26
37
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
38
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
39
|
};
|
|
29
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
41
|
exports.agentTokenLane = void 0;
|
|
31
|
-
exports.registerTransportLane = registerTransportLane;
|
|
32
|
-
exports.transportLanes = transportLanes;
|
|
33
|
-
exports.__resetTransportLanesForTests = __resetTransportLanesForTests;
|
|
34
42
|
exports.__setAgentServicePathsForTests = __setAgentServicePathsForTests;
|
|
43
|
+
exports.__resetAgentTokenLaneForTests = __resetAgentTokenLaneForTests;
|
|
35
44
|
exports.agentServicePaths = agentServicePaths;
|
|
36
45
|
exports.inAgentLane = inAgentLane;
|
|
37
|
-
exports.resolveCustomImpl = resolveCustomImpl;
|
|
38
|
-
exports.loadDelegate = loadDelegate;
|
|
39
|
-
exports.createAgentTokenAuth = createAgentTokenAuth;
|
|
40
|
-
exports.default = agentTokenAuthFactory;
|
|
41
46
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
47
|
+
const capAuth = __importStar(require("@odatano/cap-auth"));
|
|
48
|
+
const cap_auth_1 = require("@odatano/cap-auth");
|
|
42
49
|
const agent_grants_1 = require("./agent-grants");
|
|
43
50
|
const rate_limiter_1 = require("./rate-limiter");
|
|
44
|
-
const lanes = [];
|
|
45
|
-
/** Add (or replace) a lane. Lanes run in registration order, the built-in agent-token lane first. */
|
|
46
|
-
function registerTransportLane(lane) {
|
|
47
|
-
const i = lanes.findIndex((l) => l.name === lane.name);
|
|
48
|
-
if (i >= 0)
|
|
49
|
-
lanes[i] = lane;
|
|
50
|
-
else
|
|
51
|
-
lanes.push(lane);
|
|
52
|
-
}
|
|
53
|
-
/** Registered lane names, in order (tests, diagnostics). */
|
|
54
|
-
function transportLanes() {
|
|
55
|
-
return lanes.map((l) => l.name);
|
|
56
|
-
}
|
|
57
|
-
/** Remove every lane except the built-in one (tests). */
|
|
58
|
-
function __resetTransportLanesForTests() {
|
|
59
|
-
lanes.length = 0;
|
|
60
|
-
tokenFailures.reset();
|
|
61
|
-
servicePathsCache = null;
|
|
62
|
-
servicePathsPinned = false;
|
|
63
|
-
}
|
|
64
|
-
/** Built-in CAP strategies by kind, same table as @sap/cds/lib/srv/middlewares/auth/index.js. */
|
|
65
|
-
const BUILTIN = {
|
|
66
|
-
mocked: 'basic-auth',
|
|
67
|
-
basic: 'basic-auth',
|
|
68
|
-
ias: 'ias-auth',
|
|
69
|
-
jwt: 'jwt-auth',
|
|
70
|
-
xsuaa: 'jwt-auth',
|
|
71
|
-
dummy: 'dummy-auth',
|
|
72
|
-
};
|
|
73
|
-
// ---------------------------------------------------------------------------
|
|
74
|
-
// Built-in lane: x-agent-token on the ODATANO service paths
|
|
75
|
-
// ---------------------------------------------------------------------------
|
|
76
51
|
const tokenFailures = new rate_limiter_1.RateLimiter({ windowMs: 15 * 60 * 1000, maxRequests: 20, maxKeys: 10_000 });
|
|
77
52
|
let servicePathsCache = null;
|
|
78
53
|
let servicePathsPinned = false;
|
|
@@ -81,6 +56,12 @@ function __setAgentServicePathsForTests(paths) {
|
|
|
81
56
|
servicePathsCache = paths;
|
|
82
57
|
servicePathsPinned = paths !== null;
|
|
83
58
|
}
|
|
59
|
+
/** Forget throttle state and the path cache (tests). */
|
|
60
|
+
function __resetAgentTokenLaneForTests() {
|
|
61
|
+
tokenFailures.reset();
|
|
62
|
+
servicePathsCache = null;
|
|
63
|
+
servicePathsPinned = false;
|
|
64
|
+
}
|
|
84
65
|
/** Mount paths of the six services, read from `cds.services` once they are served. */
|
|
85
66
|
function agentServicePaths() {
|
|
86
67
|
if (servicePathsPinned && servicePathsCache)
|
|
@@ -94,146 +75,41 @@ function agentServicePaths() {
|
|
|
94
75
|
servicePathsCache = paths;
|
|
95
76
|
return paths;
|
|
96
77
|
}
|
|
97
|
-
|
|
98
|
-
const raw = String(req.originalUrl || req.url || req.path || '');
|
|
99
|
-
return raw.split('?')[0];
|
|
100
|
-
}
|
|
101
|
-
/** Exact segment boundary: `/odata/v4/cardano-odata` and below, never `/odata/v4/cardano-odata-evil`. */
|
|
78
|
+
/** Exact segment boundary: `/odata/v4/cardano` and below, never `/odata/v4/cardano-evil`. */
|
|
102
79
|
function inAgentLane(path, servicePaths = agentServicePaths()) {
|
|
103
|
-
|
|
80
|
+
const bare = path.split('?')[0];
|
|
81
|
+
return servicePaths.some((p) => (0, cap_auth_1.inLaneOf)(bare, p));
|
|
104
82
|
}
|
|
83
|
+
// The login package's own reading of the client address and of `trustProxy`, so a token and a
|
|
84
|
+
// password are throttled per the same client. A release without `trustedProxyCount` has no proxy setting.
|
|
85
|
+
const clientAddressOf = capAuth.clientAddress;
|
|
86
|
+
const proxyCountOf = capAuth.trustedProxyCount;
|
|
105
87
|
function clientKey(req) {
|
|
106
|
-
const
|
|
107
|
-
return `ip=${
|
|
108
|
-
}
|
|
109
|
-
function respond(res, status, message, retryAfterMs) {
|
|
110
|
-
if (retryAfterMs !== undefined)
|
|
111
|
-
res.set?.('Retry-After', String(Math.max(1, Math.ceil(retryAfterMs / 1000))));
|
|
112
|
-
const body = { error: { code: String(status), message } };
|
|
113
|
-
if (typeof res.status === 'function' && typeof res.json === 'function') {
|
|
114
|
-
res.status(status);
|
|
115
|
-
res.json(body);
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
res.statusCode = status;
|
|
119
|
-
res.setHeader('content-type', 'application/json');
|
|
120
|
-
res.end(JSON.stringify(body));
|
|
121
|
-
}
|
|
122
|
-
return { handled: true };
|
|
88
|
+
const trustProxy = cds_1.default.env.requires.auth?.trustProxy;
|
|
89
|
+
return `ip=${clientAddressOf(req, proxyCountOf ? proxyCountOf(trustProxy) : 0)}:agent-token`;
|
|
123
90
|
}
|
|
124
91
|
exports.agentTokenLane = {
|
|
125
92
|
name: 'agent-token',
|
|
126
93
|
match: (req) => typeof req.headers?.[agent_grants_1.AGENT_TOKEN_HEADER] === 'string' && req.headers[agent_grants_1.AGENT_TOKEN_HEADER].length > 0,
|
|
127
94
|
authenticate: async (req, res) => {
|
|
128
95
|
const token = req.headers[agent_grants_1.AGENT_TOKEN_HEADER];
|
|
129
|
-
if (!inAgentLane(requestPath(req)))
|
|
130
|
-
|
|
131
|
-
// (and will 401 a request that carries nothing else).
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
96
|
+
if (!inAgentLane((0, cap_auth_1.requestPath)(req)))
|
|
97
|
+
return { next: true };
|
|
134
98
|
const key = clientKey(req);
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return respond(res, 429, 'Too many failed agent token attempts', locked.retryAfterMs);
|
|
99
|
+
// A token is 32 random bytes, so a valid one cannot be guessed: it passes even while its client
|
|
100
|
+
// is locked, and other clients' failures never shut it out. A locked client gets 429 for any other.
|
|
138
101
|
const resolution = await (0, agent_grants_1.resolveAgentToken)(token);
|
|
139
102
|
if (!resolution.ok) {
|
|
103
|
+
const locked = tokenFailures.peek(key);
|
|
104
|
+
if (!locked.allowed)
|
|
105
|
+
return (0, cap_auth_1.respondError)(res, 429, 'Too many failed agent token attempts', locked.retryAfterMs);
|
|
140
106
|
const failed = tokenFailures.check(key);
|
|
141
107
|
if (!failed.allowed)
|
|
142
|
-
return
|
|
143
|
-
return
|
|
108
|
+
return (0, cap_auth_1.respondError)(res, 429, 'Too many failed agent token attempts', failed.retryAfterMs);
|
|
109
|
+
return (0, cap_auth_1.respondError)(res, resolution.status, resolution.message);
|
|
144
110
|
}
|
|
145
111
|
req.agentGrant = resolution.grant;
|
|
146
112
|
return { user: (0, agent_grants_1.makeAgentUser)(resolution.grant) };
|
|
147
113
|
},
|
|
148
114
|
};
|
|
149
|
-
function ensureBuiltinLane() {
|
|
150
|
-
if (!lanes.some((l) => l.name === exports.agentTokenLane.name))
|
|
151
|
-
lanes.unshift(exports.agentTokenLane);
|
|
152
|
-
}
|
|
153
|
-
/** Load CAP's own middleware for `kind`; exported so the wrapper can be unit-tested with a stub. */
|
|
154
|
-
/**
|
|
155
|
-
* Resolve a host-configured `auth.impl` the way CAP's auth factory does
|
|
156
|
-
* (@sap/cds/lib/srv/middlewares/auth/index.js): as a module relative to
|
|
157
|
-
* cds.root, else with a `./` prefix. Exported for the unit tests.
|
|
158
|
-
*/
|
|
159
|
-
function resolveCustomImpl(impl, root = String(cds_1.default.root ?? process.cwd())) {
|
|
160
|
-
try {
|
|
161
|
-
return require.resolve(impl, { paths: [root] });
|
|
162
|
-
}
|
|
163
|
-
catch {
|
|
164
|
-
return require.resolve(`./${impl}`, { paths: [root] });
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
function asMiddleware(loaded, delegateOptions, what) {
|
|
168
|
-
// default export of an ESM / .ts module
|
|
169
|
-
const candidate = loaded?.default ?? loaded;
|
|
170
|
-
const mw = typeof candidate === 'function' && candidate.length < 3
|
|
171
|
-
? candidate(delegateOptions)
|
|
172
|
-
: candidate;
|
|
173
|
-
if (typeof mw !== 'function') {
|
|
174
|
-
throw new Error(`agent-token-auth: ${what} did not yield a middleware function`);
|
|
175
|
-
}
|
|
176
|
-
return mw;
|
|
177
|
-
}
|
|
178
|
-
function loadDelegate(options, kind) {
|
|
179
|
-
// The delegate must not see our impl (it would recurse) nor our private keys.
|
|
180
|
-
const delegateOptions = { ...options };
|
|
181
|
-
delete delegateOptions.impl;
|
|
182
|
-
delete delegateOptions.agentGrantsDelegate;
|
|
183
|
-
delete delegateOptions.agentGrantsDelegateImpl;
|
|
184
|
-
// A host that brought its own auth.impl keeps it: whatever it enforced
|
|
185
|
-
// before agent grants were switched on, it still enforces for every request
|
|
186
|
-
// that does not carry a token, on every path.
|
|
187
|
-
const custom = options.agentGrantsDelegateImpl;
|
|
188
|
-
if (custom) {
|
|
189
|
-
const resolved = resolveCustomImpl(custom);
|
|
190
|
-
return asMiddleware(require(resolved), { ...delegateOptions, impl: custom }, `custom auth impl '${custom}'`);
|
|
191
|
-
}
|
|
192
|
-
const builtin = BUILTIN[kind.replace(/-auth$/, '')];
|
|
193
|
-
if (!builtin)
|
|
194
|
-
throw new Error(`agent-token-auth: no built-in CAP auth strategy for kind '${kind}'`);
|
|
195
|
-
// Same module CAP itself would have loaded for this kind. Pinned by the
|
|
196
|
-
// @sap/cds peer dependency; the self-test in asMiddleware fails fast if the shape moves.
|
|
197
|
-
const factory = require(`@sap/cds/lib/srv/middlewares/auth/${builtin}`);
|
|
198
|
-
return asMiddleware(factory, { ...delegateOptions, kind }, `CAP auth strategy '${builtin}'`);
|
|
199
|
-
}
|
|
200
|
-
function createAgentTokenAuth(options, delegate) {
|
|
201
|
-
const delegateKind = String(options.agentGrantsDelegate ?? options.kind ?? 'mocked');
|
|
202
|
-
const inner = delegate ?? loadDelegate(options, delegateKind);
|
|
203
|
-
ensureBuiltinLane();
|
|
204
|
-
const delegateLabel = options.agentGrantsDelegateImpl ? `custom impl ${options.agentGrantsDelegateImpl}` : `'${delegateKind}'`;
|
|
205
|
-
cds_1.default.log('AgentGrants').info(`agent-token transport lane active, delegating other requests to ${delegateLabel}`);
|
|
206
|
-
return async function agentTokenAuth(req, res, next) {
|
|
207
|
-
for (const lane of lanes) {
|
|
208
|
-
if (!lane.match(req))
|
|
209
|
-
continue;
|
|
210
|
-
let outcome;
|
|
211
|
-
try {
|
|
212
|
-
outcome = await lane.authenticate(req, res);
|
|
213
|
-
}
|
|
214
|
-
catch (err) {
|
|
215
|
-
cds_1.default.log('AgentGrants').error(`transport lane '${lane.name}' failed: ${String(err?.message ?? err)}`);
|
|
216
|
-
respond(res, 500, 'authentication lane failed');
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
if (outcome === null)
|
|
220
|
-
continue;
|
|
221
|
-
if ('handled' in outcome)
|
|
222
|
-
return;
|
|
223
|
-
req.user = outcome.user;
|
|
224
|
-
const ctx = cds_1.default.context;
|
|
225
|
-
if (ctx)
|
|
226
|
-
ctx.user = outcome.user;
|
|
227
|
-
return next();
|
|
228
|
-
}
|
|
229
|
-
return inner(req, res, next);
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* CAP requires this module and, seeing a function with fewer than three
|
|
234
|
-
* parameters, calls it with the merged auth options to obtain the middleware.
|
|
235
|
-
*/
|
|
236
|
-
function agentTokenAuthFactory(options) {
|
|
237
|
-
return createAgentTokenAuth(options);
|
|
238
|
-
}
|
|
239
115
|
//# sourceMappingURL=agent-token-auth.js.map
|
|
@@ -1,20 +1,6 @@
|
|
|
1
1
|
import cds, { Request } from '@sap/cds';
|
|
2
|
-
/**
|
|
3
|
-
* BackendRequestHandler - Provides standardized handling for backend requests
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* BackendRequestHandler - Wraps a backend method call with standardized error handling
|
|
7
|
-
* @param fn - The async function to execute
|
|
8
|
-
* @param backendName - Name of the backend (for error context)
|
|
9
|
-
* @param resourceName - Name of the resource being accessed (e.g., "Transaction", "Address")
|
|
10
|
-
* @returns {Promise<T>} The result of the backend call or a normalized error
|
|
11
|
-
*/
|
|
2
|
+
/** Wraps a backend call and normalizes any thrown error to a BackendError subclass. */
|
|
12
3
|
export declare function handleBackendRequest<T>(fn: () => Promise<T>, backendName: string): Promise<T>;
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
* @param req - The incoming request
|
|
16
|
-
* @param handler - The async function containing business logic
|
|
17
|
-
* @returns {Promise<unknown>} The result of the handler or a mapped error response
|
|
18
|
-
*/
|
|
19
|
-
export declare function handleRequest(req: Request, handler: (db: cds.Transaction) => Promise<unknown>): Promise<unknown>;
|
|
4
|
+
/** Runs a service handler inside the request transaction and maps errors to OData responses. */
|
|
5
|
+
export declare function handleRequest<T>(req: Request, handler: (db: cds.Transaction) => Promise<T>): Promise<T>;
|
|
20
6
|
//# sourceMappingURL=backend-request-handler.d.ts.map
|
|
@@ -9,16 +9,7 @@ const errors_1 = require("./errors");
|
|
|
9
9
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
10
10
|
const mappers_1 = require("./mappers");
|
|
11
11
|
const logger = cds_1.default.log('BackendRequestHandler');
|
|
12
|
-
/**
|
|
13
|
-
* BackendRequestHandler - Provides standardized handling for backend requests
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* BackendRequestHandler - Wraps a backend method call with standardized error handling
|
|
17
|
-
* @param fn - The async function to execute
|
|
18
|
-
* @param backendName - Name of the backend (for error context)
|
|
19
|
-
* @param resourceName - Name of the resource being accessed (e.g., "Transaction", "Address")
|
|
20
|
-
* @returns {Promise<T>} The result of the backend call or a normalized error
|
|
21
|
-
*/
|
|
12
|
+
/** Wraps a backend call and normalizes any thrown error to a BackendError subclass. */
|
|
22
13
|
async function handleBackendRequest(fn, backendName) {
|
|
23
14
|
try {
|
|
24
15
|
return await fn();
|
|
@@ -27,16 +18,10 @@ async function handleBackendRequest(fn, backendName) {
|
|
|
27
18
|
throw (0, errors_1.normalizeBackendError)(err, backendName);
|
|
28
19
|
}
|
|
29
20
|
}
|
|
30
|
-
/**
|
|
31
|
-
* General request handler for CardanoService
|
|
32
|
-
* @param req - The incoming request
|
|
33
|
-
* @param handler - The async function containing business logic
|
|
34
|
-
* @returns {Promise<unknown>} The result of the handler or a mapped error response
|
|
35
|
-
*/
|
|
21
|
+
/** Runs a service handler inside the request transaction and maps errors to OData responses. */
|
|
36
22
|
async function handleRequest(req, handler) {
|
|
37
23
|
const context = req.target?.name || req.event;
|
|
38
|
-
//
|
|
39
|
-
// on req.reject()/req.error() (called by mapError). No explicit rollback needed.
|
|
24
|
+
// Managed transaction: CAP rolls back on req.reject()/req.error(), no explicit rollback.
|
|
40
25
|
const db = cds_1.default.tx(req);
|
|
41
26
|
try {
|
|
42
27
|
return await handler(db);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { MintAction, TxBuildPlutusRequest, TxBuildPlutusSpendRequest, TxBuildRequest } from './types';
|
|
2
|
+
import type { Network } from '../blockchain/cardano-client';
|
|
3
|
+
type RawRequest = Record<string, unknown>;
|
|
4
|
+
/** A prepared request; for lockOnScript also the script hash and address the output goes to. */
|
|
5
|
+
export interface PreparedBuild<T> {
|
|
6
|
+
request: T;
|
|
7
|
+
scriptHash?: string;
|
|
8
|
+
scriptAddress?: string;
|
|
9
|
+
}
|
|
10
|
+
/** What a request that does not pass says: a missing field, or why a field is invalid. */
|
|
11
|
+
export interface BuildRequestError {
|
|
12
|
+
error: string;
|
|
13
|
+
field?: string;
|
|
14
|
+
missing?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export type Prepared<T> = PreparedBuild<T> | BuildRequestError;
|
|
17
|
+
/** The network, read only where a script address is derived. */
|
|
18
|
+
export type NetworkOf = () => Network;
|
|
19
|
+
/** The kinds of build a stored request can be for. */
|
|
20
|
+
export type BuildKind = 'simpleAda' | 'metadata' | 'multiAsset' | 'mint' | 'plutusSpend';
|
|
21
|
+
/** Policy id of a Plutus script given as CBOR hex. Throws the library's error for bytes that are no script. */
|
|
22
|
+
export declare function scriptHashOf(scriptHex: string): string;
|
|
23
|
+
/** The texts each action answers with; they are API. */
|
|
24
|
+
declare const MINT_TEXTS: {
|
|
25
|
+
readonly mint: {
|
|
26
|
+
readonly quantityFirst: false;
|
|
27
|
+
readonly noQuantity: () => string;
|
|
28
|
+
readonly badQuantity: (q: unknown) => string;
|
|
29
|
+
readonly noUnit: (u: unknown) => string;
|
|
30
|
+
readonly badUnit: (u: unknown) => string;
|
|
31
|
+
};
|
|
32
|
+
readonly spend: {
|
|
33
|
+
readonly quantityFirst: true;
|
|
34
|
+
readonly noQuantity: (q: unknown) => string;
|
|
35
|
+
readonly badQuantity: (q: unknown) => string;
|
|
36
|
+
readonly noUnit: (_unit: unknown) => string;
|
|
37
|
+
readonly badUnit: (u: unknown) => string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export declare function parseMintActions(raw: RawRequest, allowBareNames: boolean, texts?: keyof typeof MINT_TEXTS): MintAction[];
|
|
41
|
+
export declare function prepareSimpleAdaRequest(raw: RawRequest, network: NetworkOf): Prepared<TxBuildRequest>;
|
|
42
|
+
export declare function prepareMetadataRequest(raw: RawRequest): Prepared<TxBuildRequest>;
|
|
43
|
+
export declare function prepareMultiAssetRequest(raw: RawRequest): Prepared<TxBuildRequest>;
|
|
44
|
+
export declare function prepareMintRequest(raw: RawRequest, network: NetworkOf): Prepared<TxBuildRequest>;
|
|
45
|
+
export declare function preparePlutusSpendRequest(raw: RawRequest, network: NetworkOf): Prepared<TxBuildPlutusSpendRequest>;
|
|
46
|
+
/** Most recipients one payout takes; the transaction size limit may be reached earlier. */
|
|
47
|
+
export declare const MAX_PAYOUT_OUTPUTS = 150;
|
|
48
|
+
export declare function preparePayoutRequest(raw: RawRequest): Prepared<TxBuildPlutusRequest>;
|
|
49
|
+
/** The prepared request for a build kind. */
|
|
50
|
+
export declare function prepareBuildRequest(kind: BuildKind, raw: RawRequest, network: NetworkOf): Prepared<TxBuildRequest>;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=build-request.d.ts.map
|