@odatano/core 2.0.0-rc.5 → 2.0.0-rc.50
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 +347 -0
- package/@cds-models/CardanoBackendService/index.js +40 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +496 -11
- package/@cds-models/CardanoIndexerService/index.js +64 -0
- package/@cds-models/CardanoODataService/index.d.ts +414 -57
- package/@cds-models/CardanoODataService/index.js +42 -0
- package/@cds-models/CardanoSignService/index.d.ts +32 -19
- package/@cds-models/CardanoSignService/index.js +3 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +58 -44
- package/@cds-models/CardanoTransactionService/index.js +4 -0
- package/@cds-models/CardanoWorkerService/index.d.ts +7 -22
- package/@cds-models/index.d.ts +101 -1
- package/@cds-models/index.js +16 -1
- package/@cds-models/odatano/cardano/index.d.ts +437 -32
- package/@cds-models/odatano/cardano/index.js +48 -0
- package/README.md +207 -167
- package/db/schema.cds +2402 -1705
- package/db/types.cds +446 -295
- package/package.json +41 -16
- package/scripts/migrate-schema.mjs +334 -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 -135
- package/srv/blockchain/backends/blockfrost-backend.js +66 -172
- package/srv/blockchain/backends/cardano-backend.d.ts +94 -186
- package/srv/blockchain/backends/cardano-backend.js +29 -5
- package/srv/blockchain/backends/koios-backend.d.ts +103 -168
- package/srv/blockchain/backends/koios-backend.js +428 -360
- package/srv/blockchain/backends/odatano-backend.d.ts +54 -0
- package/srv/blockchain/backends/odatano-backend.js +169 -0
- package/srv/blockchain/backends/ogmios-backend.d.ts +123 -190
- package/srv/blockchain/backends/ogmios-backend.js +637 -315
- 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 +61 -241
- package/srv/blockchain/cardano-client.js +253 -293
- package/srv/blockchain/cardano-indexer.d.ts +282 -281
- package/srv/blockchain/cardano-indexer.js +1551 -484
- 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 +1 -13
- package/srv/blockchain/circuit-breaker.js +5 -15
- package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
- package/srv/blockchain/crawler/account-snapshots.js +153 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +15 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
- package/srv/blockchain/crawler/asset-registry-backfill.d.ts +43 -0
- package/srv/blockchain/crawler/asset-registry-backfill.js +153 -0
- package/srv/blockchain/crawler/certificate-backfill.d.ts +52 -0
- package/srv/blockchain/crawler/certificate-backfill.js +162 -0
- package/srv/blockchain/crawler/crawler.d.ts +104 -81
- package/srv/blockchain/crawler/crawler.js +532 -160
- package/srv/blockchain/crawler/credential-backfill.d.ts +28 -0
- package/srv/blockchain/crawler/credential-backfill.js +124 -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 +171 -0
- package/srv/blockchain/crawler/metadata-position-backfill.d.ts +16 -0
- package/srv/blockchain/crawler/metadata-position-backfill.js +55 -0
- package/srv/blockchain/crawler/output-datum-backfill.d.ts +39 -0
- package/srv/blockchain/crawler/output-datum-backfill.js +110 -0
- package/srv/blockchain/crawler/sync-state.d.ts +27 -47
- package/srv/blockchain/crawler/sync-state.js +113 -63
- package/srv/blockchain/crawler/transaction-backfill.d.ts +44 -0
- package/srv/blockchain/crawler/transaction-backfill.js +278 -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/ledger-state.d.ts +62 -0
- package/srv/blockchain/ledger-state.js +419 -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 +17 -126
- package/srv/blockchain/signing/hsm-signer.d.ts +10 -54
- package/srv/blockchain/signing/hsm-signer.js +28 -79
- package/srv/blockchain/signing/signature-verifier.d.ts +9 -47
- package/srv/blockchain/signing/signature-verifier.js +70 -83
- package/srv/blockchain/signing/submission-finalizer.d.ts +23 -45
- package/srv/blockchain/signing/submission-finalizer.js +219 -86
- package/srv/blockchain/stored-chain.d.ts +20 -0
- package/srv/blockchain/stored-chain.js +237 -0
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +31 -229
- package/srv/blockchain/transaction-building/buildooor-tx.js +652 -416
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +9 -37
- package/srv/blockchain/transaction-presence.d.ts +5 -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 +5 -20
- package/srv/blockchain/wallet-worker/build-request.js +47 -30
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +5 -46
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +25 -45
- package/srv/blockchain/wallet-worker/index.d.ts +1 -1
- package/srv/blockchain/wallet-worker/index.js +3 -11
- package/srv/blockchain/wallet-worker/job-store.d.ts +30 -148
- package/srv/blockchain/wallet-worker/job-store.js +101 -201
- 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 +8 -80
- package/srv/blockchain/wallet-worker/wallet-worker.js +107 -155
- package/srv/cardano-agent-service.cds +122 -84
- package/srv/cardano-agent-service.js +4 -9
- package/srv/cardano-backend-service.cds +78 -0
- package/srv/cardano-backend-service.d.ts +2 -0
- package/srv/cardano-backend-service.js +242 -0
- package/srv/cardano-indexer-service.cds +387 -73
- package/srv/cardano-indexer-service.d.ts +5 -1
- package/srv/cardano-indexer-service.js +532 -16
- package/srv/cardano-service.cds +424 -269
- package/srv/cardano-service.js +289 -201
- package/srv/cardano-sign-service.cds +201 -180
- package/srv/cardano-sign-service.js +71 -201
- package/srv/cardano-tx-service.cds +451 -370
- package/srv/cardano-tx-service.js +271 -289
- package/srv/cardano-ui.cds +16 -16
- package/srv/cardano-worker-service.cds +118 -125
- package/srv/cardano-worker-service.js +52 -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 +113 -0
- package/srv/config.js +409 -0
- package/srv/server.d.ts +15 -110
- package/srv/server.js +84 -404
- package/srv/utils/agent-access.d.ts +9 -0
- package/srv/utils/agent-access.js +67 -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 -236
- package/srv/utils/agent-token-auth.d.ts +4 -99
- package/srv/utils/agent-token-auth.js +18 -182
- package/srv/utils/backend-request-handler.d.ts +3 -17
- package/srv/utils/backend-request-handler.js +3 -18
- package/srv/utils/collections.d.ts +3 -10
- package/srv/utils/collections.js +3 -10
- package/srv/utils/const.d.ts +23 -74
- package/srv/utils/const.js +32 -79
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +6 -21
- package/srv/utils/db-indexes.d.ts +27 -0
- package/srv/utils/db-indexes.js +120 -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/epoch-slots.d.ts +13 -0
- package/srv/utils/epoch-slots.js +38 -0
- package/srv/utils/error-codes.d.ts +22 -75
- package/srv/utils/error-codes.js +23 -72
- package/srv/utils/errors.d.ts +46 -187
- package/srv/utils/errors.js +114 -230
- package/srv/utils/liveness.d.ts +12 -0
- package/srv/utils/liveness.js +35 -0
- package/srv/utils/mappers.d.ts +102 -223
- package/srv/utils/mappers.js +387 -316
- package/srv/utils/network-context.js +2 -13
- 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/result-numbers.d.ts +15 -0
- package/srv/utils/result-numbers.js +61 -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 +10 -105
- package/srv/utils/tx-build-helper.js +81 -144
- 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 +261 -191
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +22 -92
- package/srv/utils/validators.js +50 -149
package/srv/config.js
ADDED
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AGENT_AUTH_IMPL = exports.AGENT_GRANT_USAGE_RETENTION_DAYS_DEFAULT = exports.AGENT_TOKEN_CACHE_MS_DEFAULT = exports.AGENT_GRANT_ADMIN_RATE_LIMIT_DEFAULT = exports.AGENT_GRANTS_DELEGATES = void 0;
|
|
7
|
+
exports.coreCdsConfig = coreCdsConfig;
|
|
8
|
+
exports.configuredNetworkName = configuredNetworkName;
|
|
9
|
+
exports.autoInitSkipped = autoInitSkipped;
|
|
10
|
+
exports.detachedTxTimeoutMs = detachedTxTimeoutMs;
|
|
11
|
+
exports.loadConfigFromEnv = loadConfigFromEnv;
|
|
12
|
+
exports.loadPoolMetadataFetchFromEnv = loadPoolMetadataFetchFromEnv;
|
|
13
|
+
exports.loadHsmConfigFromEnv = loadHsmConfigFromEnv;
|
|
14
|
+
exports.loadCrawlerConfigFromEnv = loadCrawlerConfigFromEnv;
|
|
15
|
+
exports.loadWalletWorkerConfigFromEnv = loadWalletWorkerConfigFromEnv;
|
|
16
|
+
exports.loadGrantAdminRateLimit = loadGrantAdminRateLimit;
|
|
17
|
+
exports.loadTokenCacheMs = loadTokenCacheMs;
|
|
18
|
+
exports.loadGrantUsageRetentionDays = loadGrantUsageRetentionDays;
|
|
19
|
+
exports.configuredAuth = configuredAuth;
|
|
20
|
+
exports.customAuthImpl = customAuthImpl;
|
|
21
|
+
exports.loadAgentGrantsConfig = loadAgentGrantsConfig;
|
|
22
|
+
// Every setting is read here. cds.requires["odatano-core"] wins over process.env, which wins
|
|
23
|
+
// over the default. Only types are imported from the service code, so this module loads alone.
|
|
24
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
25
|
+
const process_1 = require("process");
|
|
26
|
+
const const_1 = require("./utils/const");
|
|
27
|
+
const errors_1 = require("./utils/errors");
|
|
28
|
+
const logger = cds_1.default.log('ODATANO');
|
|
29
|
+
const VALID_NETWORKS = ['mainnet', 'preview', 'preprod'];
|
|
30
|
+
/** The section as configured. Every read of it goes through here. */
|
|
31
|
+
function coreCdsConfig() {
|
|
32
|
+
const requires = cds_1.default.env?.requires;
|
|
33
|
+
return requires?.['odatano-core'] ?? {};
|
|
34
|
+
}
|
|
35
|
+
/** The network as written, unchecked: for probes that answer even when the configuration is invalid. */
|
|
36
|
+
function configuredNetworkName() {
|
|
37
|
+
return String(coreCdsConfig().network || process_1.env.NETWORK || 'preview');
|
|
38
|
+
}
|
|
39
|
+
/** SKIP_AUTO_INIT=true: tests mount the services without starting backends, crawler or worker. */
|
|
40
|
+
function autoInitSkipped() {
|
|
41
|
+
return process_1.env.SKIP_AUTO_INIT === 'true';
|
|
42
|
+
}
|
|
43
|
+
/** ODATANO_DETACHED_TX_TIMEOUT_MS when it is a positive number; read per call. */
|
|
44
|
+
function detachedTxTimeoutMs() {
|
|
45
|
+
const fromEnv = Number(process_1.env.ODATANO_DETACHED_TX_TIMEOUT_MS);
|
|
46
|
+
return Number.isFinite(fromEnv) && fromEnv > 0 ? fromEnv : undefined;
|
|
47
|
+
}
|
|
48
|
+
const VALID_BACKENDS = ['blockfrost', 'koios', 'ogmios', 'odatano'];
|
|
49
|
+
const CRAWLER_LIMITS = {
|
|
50
|
+
batchSize: { min: 1, max: 100 },
|
|
51
|
+
confirmationDepth: { min: 0, max: 2160 },
|
|
52
|
+
pollIntervalMs: { min: 1000, max: 3_600_000 },
|
|
53
|
+
assetEnrichRate: { min: 1, max: 20 },
|
|
54
|
+
};
|
|
55
|
+
const VALID_ASSET_CATALOGUE_MODES = ['off', 'bare', 'enrich'];
|
|
56
|
+
/** Parse a boolean crawler flag that defaults to `fallback` when unset. */
|
|
57
|
+
function crawlerBoolean(raw, name, fallback) {
|
|
58
|
+
if (raw === undefined || raw === null)
|
|
59
|
+
return fallback;
|
|
60
|
+
if (raw === true || raw === 'true')
|
|
61
|
+
return true;
|
|
62
|
+
if (raw === false || raw === 'false')
|
|
63
|
+
return false;
|
|
64
|
+
throw new errors_1.ConfigError(`Invalid ${name} "${String(raw)}". Must be true or false.`);
|
|
65
|
+
}
|
|
66
|
+
/** Parse an integer without allowing JavaScript's lossy/implicit coercions. */
|
|
67
|
+
function crawlerInteger(raw, name, min, max, defaultValue) {
|
|
68
|
+
if (raw == null)
|
|
69
|
+
return defaultValue;
|
|
70
|
+
if ((typeof raw !== 'number' && typeof raw !== 'string')
|
|
71
|
+
|| (typeof raw === 'string' && raw.trim() === '')) {
|
|
72
|
+
throw new errors_1.ConfigError(`Invalid ${name} "${String(raw)}". Must be an integer between ${min} and ${max}.`);
|
|
73
|
+
}
|
|
74
|
+
const parsed = typeof raw === 'number' ? raw : Number(raw);
|
|
75
|
+
if (!Number.isSafeInteger(parsed) || parsed < min || parsed > max) {
|
|
76
|
+
throw new errors_1.ConfigError(`Invalid ${name} "${String(raw)}". Must be an integer between ${min} and ${max}.`);
|
|
77
|
+
}
|
|
78
|
+
return parsed;
|
|
79
|
+
}
|
|
80
|
+
/** Blockchain components created once at bootstrap and shared across services. */
|
|
81
|
+
/** Backends and their credentials. Throws ConfigError for an invalid value. */
|
|
82
|
+
function loadConfigFromEnv() {
|
|
83
|
+
const cdsConfig = coreCdsConfig();
|
|
84
|
+
const network = configuredNetworkName();
|
|
85
|
+
if (!VALID_NETWORKS.includes(network)) {
|
|
86
|
+
throw new errors_1.ConfigError(`Invalid NETWORK "${cdsConfig.network || process_1.env.NETWORK}". Must be one of: ${VALID_NETWORKS.join(', ')}`);
|
|
87
|
+
}
|
|
88
|
+
const backendsRaw = cdsConfig.backends ?? process_1.env.BACKENDS;
|
|
89
|
+
const backendStrings = Array.isArray(backendsRaw) ? backendsRaw
|
|
90
|
+
: backendsRaw ? String(backendsRaw).split(',').map(b => b.trim()) : ['koios'];
|
|
91
|
+
const invalidBackends = backendStrings.filter(b => !VALID_BACKENDS.includes(b));
|
|
92
|
+
if (invalidBackends.length > 0) {
|
|
93
|
+
throw new errors_1.ConfigError(`Invalid BACKENDS: "${invalidBackends.join(', ')}". Must be one of: ${VALID_BACKENDS.join(', ')}`);
|
|
94
|
+
}
|
|
95
|
+
const backends = backendStrings;
|
|
96
|
+
const primaryTimeout = cdsConfig.primaryTimeoutMs ?? process_1.env.PRIMARY_TIMEOUT_MS;
|
|
97
|
+
const fallbackTimeout = cdsConfig.fallbackTimeoutMs ?? process_1.env.FALLBACK_TIMEOUT_MS;
|
|
98
|
+
// `!= null`, not truthiness: a CDS-config 0 must reach the <= 0 check.
|
|
99
|
+
if (primaryTimeout != null && isNaN(Number(primaryTimeout))) {
|
|
100
|
+
throw new errors_1.ConfigError(`Invalid PRIMARY_TIMEOUT_MS "${primaryTimeout}". Must be a number.`);
|
|
101
|
+
}
|
|
102
|
+
if (primaryTimeout != null && Number(primaryTimeout) <= 0) {
|
|
103
|
+
throw new errors_1.ConfigError(`Invalid PRIMARY_TIMEOUT_MS "${primaryTimeout}". Must be a positive number.`);
|
|
104
|
+
}
|
|
105
|
+
if (fallbackTimeout != null && isNaN(Number(fallbackTimeout))) {
|
|
106
|
+
throw new errors_1.ConfigError(`Invalid FALLBACK_TIMEOUT_MS "${fallbackTimeout}". Must be a number.`);
|
|
107
|
+
}
|
|
108
|
+
if (fallbackTimeout != null && Number(fallbackTimeout) <= 0) {
|
|
109
|
+
throw new errors_1.ConfigError(`Invalid FALLBACK_TIMEOUT_MS "${fallbackTimeout}". Must be a positive number.`);
|
|
110
|
+
}
|
|
111
|
+
const blockfrostApiKey = cdsConfig.blockfrostApiKey || process_1.env.BLOCKFROST_API_KEY || '';
|
|
112
|
+
const blockfrostCustomBackend = cdsConfig.blockfrostCustomBackend || process_1.env.BLOCKFROST_CUSTOM_BACKEND || '';
|
|
113
|
+
if (blockfrostCustomBackend && !/^https?:\/\//i.test(blockfrostCustomBackend)) {
|
|
114
|
+
throw new errors_1.ConfigError(`Invalid BLOCKFROST_CUSTOM_BACKEND "${blockfrostCustomBackend}". Must be an http(s) URL ` +
|
|
115
|
+
`(e.g. http://localhost:3010/api/v0).`);
|
|
116
|
+
}
|
|
117
|
+
const koiosApiKey = cdsConfig.koiosApiKey || process_1.env.KOIOS_API_KEY || '';
|
|
118
|
+
const ogmiosUrl = cdsConfig.ogmiosUrl || process_1.env.OGMIOS_URL || '';
|
|
119
|
+
const odatanoUrl = cdsConfig.odatanoUrl || process_1.env.ODATANO_URL || '';
|
|
120
|
+
const odatanoApiKey = cdsConfig.odatanoApiKey || process_1.env.ODATANO_API_KEY || '';
|
|
121
|
+
if (odatanoUrl && !/^https?:\/\//i.test(odatanoUrl)) {
|
|
122
|
+
throw new errors_1.ConfigError(`Invalid ODATANO_URL "${odatanoUrl}". Must be an http(s) URL (e.g. https://api.preprod.odatano.dev).`);
|
|
123
|
+
}
|
|
124
|
+
if (backends.includes('odatano') && !odatanoUrl && network === 'mainnet') {
|
|
125
|
+
throw new errors_1.ConfigError('ODATANO_URL is required for the odatano backend on mainnet.');
|
|
126
|
+
}
|
|
127
|
+
if (backends.includes('odatano') && !odatanoApiKey) {
|
|
128
|
+
logger.warn('ODATANO_API_KEY is not set but odatano is listed in BACKENDS; the public API refuses calls without a key');
|
|
129
|
+
}
|
|
130
|
+
if (backends.includes('blockfrost') && !blockfrostApiKey && !blockfrostCustomBackend) {
|
|
131
|
+
logger.warn('Neither BLOCKFROST_API_KEY nor BLOCKFROST_CUSTOM_BACKEND is set but blockfrost is listed in BACKENDS');
|
|
132
|
+
}
|
|
133
|
+
else if (backends.includes('blockfrost') && blockfrostCustomBackend) {
|
|
134
|
+
logger.info(`Blockfrost will use customBackend: ${blockfrostCustomBackend}`);
|
|
135
|
+
}
|
|
136
|
+
if (backends.includes('ogmios') && !ogmiosUrl) {
|
|
137
|
+
logger.warn('OGMIOS_URL is not set but ogmios is listed in BACKENDS');
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
network,
|
|
141
|
+
backends,
|
|
142
|
+
blockfrostApiKey,
|
|
143
|
+
blockfrostCustomBackend: blockfrostCustomBackend || undefined,
|
|
144
|
+
koiosApiKey,
|
|
145
|
+
ogmiosUrl,
|
|
146
|
+
odatanoUrl: odatanoUrl || undefined,
|
|
147
|
+
odatanoApiKey: odatanoApiKey || undefined,
|
|
148
|
+
primaryTimeoutMs: Number(primaryTimeout) || 30000, // || intentional: NaN (missing config) falls back to default
|
|
149
|
+
fallbackTimeoutMs: Number(fallbackTimeout) || 60000,
|
|
150
|
+
indexTtlMs: Number(cdsConfig.indexTtlMs ?? process_1.env.INDEX_TTL_MS) || const_1.DEFAULT_INDEX_TTL_MS,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/** `poolMetadataFetch` / POOL_METADATA_FETCH: load pool metadata files from their registered URL. Off by default. */
|
|
154
|
+
function loadPoolMetadataFetchFromEnv() {
|
|
155
|
+
return crawlerBoolean(coreCdsConfig().poolMetadataFetch ?? process_1.env.POOL_METADATA_FETCH, 'POOL_METADATA_FETCH', false);
|
|
156
|
+
}
|
|
157
|
+
/** From cds.requires.odatano-core.hsm or HSM_* env vars. Undefined when HSM is off. */
|
|
158
|
+
function loadHsmConfigFromEnv() {
|
|
159
|
+
const cdsConfig = coreCdsConfig();
|
|
160
|
+
const hsmCds = cdsConfig.hsm ?? {};
|
|
161
|
+
const hsmEnabled = hsmCds.enabled === true || process_1.env.HSM_ENABLED === 'true';
|
|
162
|
+
if (!hsmEnabled)
|
|
163
|
+
return undefined;
|
|
164
|
+
const pkcs11Module = hsmCds.pkcs11Module || process_1.env.HSM_PKCS11_MODULE || '';
|
|
165
|
+
if (!pkcs11Module) {
|
|
166
|
+
throw new errors_1.ConfigError('HSM_PKCS11_MODULE is required when HSM is enabled');
|
|
167
|
+
}
|
|
168
|
+
const pin = hsmCds.pin || process_1.env.HSM_PIN || '';
|
|
169
|
+
if (!pin) {
|
|
170
|
+
throw new errors_1.ConfigError('HSM_PIN is required when HSM is enabled');
|
|
171
|
+
}
|
|
172
|
+
const slot = Number(hsmCds.slot ?? process_1.env.HSM_SLOT ?? 0);
|
|
173
|
+
if (!Number.isInteger(slot) || slot < 0) {
|
|
174
|
+
throw new errors_1.ConfigError(`Invalid HSM slot: "${hsmCds.slot ?? process_1.env.HSM_SLOT}": must be a non-negative integer`);
|
|
175
|
+
}
|
|
176
|
+
// Fail closed: the HSM holds a real signing key, so an explicit role gate is mandatory.
|
|
177
|
+
const requiresRole = hsmCds.requiresRole || process_1.env.HSM_REQUIRES_ROLE || '';
|
|
178
|
+
if (!requiresRole) {
|
|
179
|
+
throw new errors_1.ConfigError('HSM_REQUIRES_ROLE (or cds.requires.odatano-core.hsm.requiresRole) is required when HSM is enabled. Set it to the XSUAA scope name allowed to invoke HSM signing actions');
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
enabled: true,
|
|
183
|
+
pkcs11Module,
|
|
184
|
+
slot,
|
|
185
|
+
pin,
|
|
186
|
+
keyId: hsmCds.keyId || process_1.env.HSM_KEY_ID,
|
|
187
|
+
keyLabel: hsmCds.keyLabel || process_1.env.HSM_KEY_LABEL,
|
|
188
|
+
requiresRole,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/** From cds.requires.odatano-core.crawler or CRAWLER_* env vars. Off by default. */
|
|
192
|
+
function loadCrawlerConfigFromEnv() {
|
|
193
|
+
const cdsConfig = coreCdsConfig();
|
|
194
|
+
const c = cdsConfig.crawler ?? {};
|
|
195
|
+
// A CDS value, including an explicit `false`, wins over the environment.
|
|
196
|
+
const enabledRaw = c.enabled !== undefined ? c.enabled : process_1.env.CRAWLER_ENABLED;
|
|
197
|
+
let enabled = false;
|
|
198
|
+
if (enabledRaw === true || enabledRaw === 'true') {
|
|
199
|
+
enabled = true;
|
|
200
|
+
}
|
|
201
|
+
else if (enabledRaw !== undefined && enabledRaw !== false && enabledRaw !== 'false') {
|
|
202
|
+
throw new errors_1.ConfigError(`Invalid CRAWLER_ENABLED "${String(enabledRaw)}". Must be true or false.`);
|
|
203
|
+
}
|
|
204
|
+
const startSlot = crawlerInteger(c.startSlot ?? process_1.env.CRAWLER_START_SLOT, 'CRAWLER_START_SLOT', 0, Number.MAX_SAFE_INTEGER);
|
|
205
|
+
const startHeight = crawlerInteger(c.startHeight ?? process_1.env.CRAWLER_START_HEIGHT, 'CRAWLER_START_HEIGHT', 0, Number.MAX_SAFE_INTEGER);
|
|
206
|
+
const startBlockHashRaw = c.startBlockHash ?? process_1.env.CRAWLER_START_HASH;
|
|
207
|
+
if (startBlockHashRaw != null && (typeof startBlockHashRaw !== 'string' || !/^[0-9a-f]{64}$/i.test(startBlockHashRaw.trim()))) {
|
|
208
|
+
throw new errors_1.ConfigError('Invalid CRAWLER_START_HASH. Must be exactly 64 hexadecimal characters.');
|
|
209
|
+
}
|
|
210
|
+
const startBlockHash = startBlockHashRaw?.trim() || undefined;
|
|
211
|
+
const source = (c.source ?? process_1.env.CRAWLER_SOURCE ?? 'auto');
|
|
212
|
+
const batchSize = crawlerInteger(c.batchSize ?? process_1.env.CRAWLER_BATCH_SIZE, 'CRAWLER_BATCH_SIZE', CRAWLER_LIMITS.batchSize.min, CRAWLER_LIMITS.batchSize.max, 20);
|
|
213
|
+
const confirmationDepth = crawlerInteger(c.confirmationDepth ?? process_1.env.CRAWLER_CONFIRMATION_DEPTH, 'CRAWLER_CONFIRMATION_DEPTH', CRAWLER_LIMITS.confirmationDepth.min, CRAWLER_LIMITS.confirmationDepth.max, 3);
|
|
214
|
+
const pollIntervalMs = crawlerInteger(c.pollIntervalMs ?? process_1.env.CRAWLER_POLL_INTERVAL_MS, 'CRAWLER_POLL_INTERVAL_MS', CRAWLER_LIMITS.pollIntervalMs.min, CRAWLER_LIMITS.pollIntervalMs.max, 20_000);
|
|
215
|
+
if (enabled && (startSlot == null || Number.isNaN(startSlot) || !startBlockHash)) {
|
|
216
|
+
throw new errors_1.ConfigError('Crawler is enabled but no start block is configured. Set crawler.startSlot + crawler.startBlockHash ' +
|
|
217
|
+
'(or CRAWLER_START_SLOT + CRAWLER_START_HASH).');
|
|
218
|
+
}
|
|
219
|
+
if (!['ogmios', 'pagination', 'auto'].includes(source)) {
|
|
220
|
+
throw new errors_1.ConfigError(`Invalid CRAWLER_SOURCE "${source}". Must be one of: ogmios, pagination, auto.`);
|
|
221
|
+
}
|
|
222
|
+
// Analytics coverage: mint/burn and the bare catalogue are free by-products of a crawled
|
|
223
|
+
// block and on by default; enrichment and epoch snapshots cost provider calls and are opt-in.
|
|
224
|
+
const assetHistory = crawlerBoolean(c.assetHistory ?? process_1.env.CRAWLER_ASSET_HISTORY, 'CRAWLER_ASSET_HISTORY', true);
|
|
225
|
+
const assetCatalogue = (c.assetCatalogue ?? process_1.env.CRAWLER_ASSET_CATALOGUE ?? 'bare');
|
|
226
|
+
if (!VALID_ASSET_CATALOGUE_MODES.includes(assetCatalogue)) {
|
|
227
|
+
throw new errors_1.ConfigError(`Invalid CRAWLER_ASSET_CATALOGUE "${assetCatalogue}". Must be one of: ${VALID_ASSET_CATALOGUE_MODES.join(', ')}.`);
|
|
228
|
+
}
|
|
229
|
+
const assetEnrichRate = crawlerInteger(c.assetEnrichRate ?? process_1.env.CRAWLER_ASSET_ENRICH_RATE, 'CRAWLER_ASSET_ENRICH_RATE', CRAWLER_LIMITS.assetEnrichRate.min, CRAWLER_LIMITS.assetEnrichRate.max, 2);
|
|
230
|
+
const epochSnapshots = crawlerBoolean(c.epochSnapshots ?? process_1.env.CRAWLER_EPOCH_SNAPSHOTS, 'CRAWLER_EPOCH_SNAPSHOTS', false);
|
|
231
|
+
// One row per pool-delegated account and epoch, read from the node with the epoch snapshot.
|
|
232
|
+
const accountSnapshots = crawlerBoolean(c.accountSnapshots ?? process_1.env.CRAWLER_ACCOUNT_SNAPSHOTS, 'CRAWLER_ACCOUNT_SNAPSHOTS', false);
|
|
233
|
+
if (accountSnapshots && !epochSnapshots) {
|
|
234
|
+
throw new errors_1.ConfigError('CRAWLER_ACCOUNT_SNAPSHOTS needs CRAWLER_EPOCH_SNAPSHOTS: the account snapshot is taken with the epoch snapshot.');
|
|
235
|
+
}
|
|
236
|
+
// Certificates + withdrawals are block content (no extra request) but opt-in to keep write volume stable.
|
|
237
|
+
const certificates = crawlerBoolean(c.certificates ?? process_1.env.CRAWLER_CERTIFICATES, 'CRAWLER_CERTIFICATES', false);
|
|
238
|
+
// UTxO set: opt-in, inert until a snapshot has been imported (importUtxoSet).
|
|
239
|
+
const utxoSet = crawlerBoolean(c.utxoSet ?? process_1.env.CRAWLER_UTXO_SET, 'CRAWLER_UTXO_SET', false);
|
|
240
|
+
// Crawled chain answers misses with 404 instead of a provider call.
|
|
241
|
+
const authoritative = crawlerBoolean(c.authoritative ?? process_1.env.CRAWLER_AUTHORITATIVE, 'CRAWLER_AUTHORITATIVE', false);
|
|
242
|
+
// A copy of every input's assets makes long ranges of inputs fast to read and stores the assets twice.
|
|
243
|
+
const inputAssetCopies = crawlerBoolean(c.inputAssetCopies ?? process_1.env.CRAWLER_INPUT_ASSET_COPIES, 'CRAWLER_INPUT_ASSET_COPIES', false);
|
|
244
|
+
return {
|
|
245
|
+
enabled, startSlot, startBlockHash, startHeight, source, batchSize, confirmationDepth, pollIntervalMs,
|
|
246
|
+
assetHistory, assetCatalogue, assetEnrichRate, epochSnapshots, accountSnapshots, certificates, utxoSet, authoritative, inputAssetCopies,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
const WALLET_WORKER_LIMITS = {
|
|
250
|
+
maxConcurrentWallets: { min: 1, max: 64 },
|
|
251
|
+
confirmationDepth: { min: 1, max: 2160 },
|
|
252
|
+
confirmationTimeoutMs: { min: 30_000, max: 86_400_000 },
|
|
253
|
+
pollIntervalMs: { min: 500, max: 3_600_000 },
|
|
254
|
+
maxAttempts: { min: 1, max: 10 },
|
|
255
|
+
};
|
|
256
|
+
/** From cds.requires.odatano-core.walletWorker or WALLET_WORKER_* env vars. Off by default. */
|
|
257
|
+
function loadWalletWorkerConfigFromEnv() {
|
|
258
|
+
const cdsConfig = coreCdsConfig();
|
|
259
|
+
const w = cdsConfig.walletWorker ?? {};
|
|
260
|
+
const enabledRaw = w.enabled !== undefined ? w.enabled : process_1.env.WALLET_WORKER_ENABLED;
|
|
261
|
+
let enabled = false;
|
|
262
|
+
if (enabledRaw === true || enabledRaw === 'true') {
|
|
263
|
+
enabled = true;
|
|
264
|
+
}
|
|
265
|
+
else if (enabledRaw !== undefined && enabledRaw !== false && enabledRaw !== 'false') {
|
|
266
|
+
throw new errors_1.ConfigError(`Invalid WALLET_WORKER_ENABLED "${String(enabledRaw)}". Must be true or false.`);
|
|
267
|
+
}
|
|
268
|
+
let walletsRaw = w.wallets ?? undefined;
|
|
269
|
+
if (walletsRaw === undefined && process_1.env.WALLET_WORKER_WALLETS) {
|
|
270
|
+
try {
|
|
271
|
+
walletsRaw = JSON.parse(process_1.env.WALLET_WORKER_WALLETS);
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
throw new errors_1.ConfigError('Invalid WALLET_WORKER_WALLETS: must be a JSON array of { walletId, signerType, keyEnv?, requiresRole? }.');
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const wallets = [];
|
|
278
|
+
if (walletsRaw !== undefined) {
|
|
279
|
+
if (!Array.isArray(walletsRaw)) {
|
|
280
|
+
throw new errors_1.ConfigError('Invalid walletWorker.wallets: must be an array of { walletId, signerType, keyEnv?, requiresRole? }.');
|
|
281
|
+
}
|
|
282
|
+
for (const entry of walletsRaw) {
|
|
283
|
+
const walletId = typeof entry?.walletId === 'string' ? entry.walletId.trim() : '';
|
|
284
|
+
const signerType = entry?.signerType;
|
|
285
|
+
if (!walletId || (signerType !== 'hsm' && signerType !== 'software')) {
|
|
286
|
+
throw new errors_1.ConfigError(`Invalid wallet entry ${JSON.stringify(entry)}: walletId and signerType (hsm|software) are required.`);
|
|
287
|
+
}
|
|
288
|
+
if (signerType === 'software' && (typeof entry.keyEnv !== 'string' || !entry.keyEnv.trim())) {
|
|
289
|
+
throw new errors_1.ConfigError(`Wallet "${walletId}" is signerType=software but has no keyEnv (name of the env var holding the signing key).`);
|
|
290
|
+
}
|
|
291
|
+
if (wallets.some((existing) => existing.walletId === walletId)) {
|
|
292
|
+
throw new errors_1.ConfigError(`Duplicate walletId "${walletId}" in walletWorker.wallets.`);
|
|
293
|
+
}
|
|
294
|
+
const requiresRole = entry.requiresRole ?? undefined;
|
|
295
|
+
if (requiresRole !== undefined && (typeof requiresRole !== 'string' || !requiresRole.trim() || requiresRole.trim().length > 100)) {
|
|
296
|
+
throw new errors_1.ConfigError(`Wallet "${walletId}": requiresRole must be a role name of 1 to 100 characters.`);
|
|
297
|
+
}
|
|
298
|
+
wallets.push({ walletId, signerType, keyEnv: entry.keyEnv, ...(requiresRole ? { requiresRole: requiresRole.trim() } : {}) });
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
const maxConcurrentWallets = crawlerInteger(w.maxConcurrentWallets ?? process_1.env.WALLET_WORKER_MAX_CONCURRENT, 'WALLET_WORKER_MAX_CONCURRENT', WALLET_WORKER_LIMITS.maxConcurrentWallets.min, WALLET_WORKER_LIMITS.maxConcurrentWallets.max, 4);
|
|
302
|
+
const confirmationDepth = crawlerInteger(w.confirmationDepth ?? process_1.env.WALLET_WORKER_CONFIRMATION_DEPTH, 'WALLET_WORKER_CONFIRMATION_DEPTH', WALLET_WORKER_LIMITS.confirmationDepth.min, WALLET_WORKER_LIMITS.confirmationDepth.max, 3);
|
|
303
|
+
const confirmationTimeoutMs = crawlerInteger(w.confirmationTimeoutMs ?? process_1.env.WALLET_WORKER_CONFIRMATION_TIMEOUT_MS, 'WALLET_WORKER_CONFIRMATION_TIMEOUT_MS', WALLET_WORKER_LIMITS.confirmationTimeoutMs.min, WALLET_WORKER_LIMITS.confirmationTimeoutMs.max, 600_000);
|
|
304
|
+
const pollIntervalMs = crawlerInteger(w.pollIntervalMs ?? process_1.env.WALLET_WORKER_POLL_INTERVAL_MS, 'WALLET_WORKER_POLL_INTERVAL_MS', WALLET_WORKER_LIMITS.pollIntervalMs.min, WALLET_WORKER_LIMITS.pollIntervalMs.max, 2_000);
|
|
305
|
+
const defaultMaxAttempts = crawlerInteger(w.defaultMaxAttempts ?? process_1.env.WALLET_WORKER_MAX_ATTEMPTS, 'WALLET_WORKER_MAX_ATTEMPTS', WALLET_WORKER_LIMITS.maxAttempts.min, WALLET_WORKER_LIMITS.maxAttempts.max, 3);
|
|
306
|
+
const resubmitRaw = w.resubmitOnRollback !== undefined ? w.resubmitOnRollback : process_1.env.WALLET_WORKER_RESUBMIT_ON_ROLLBACK;
|
|
307
|
+
let resubmitOnRollback = true;
|
|
308
|
+
if (resubmitRaw === false || resubmitRaw === 'false') {
|
|
309
|
+
resubmitOnRollback = false;
|
|
310
|
+
}
|
|
311
|
+
else if (resubmitRaw !== undefined && resubmitRaw !== true && resubmitRaw !== 'true') {
|
|
312
|
+
throw new errors_1.ConfigError(`Invalid WALLET_WORKER_RESUBMIT_ON_ROLLBACK "${String(resubmitRaw)}". Must be true or false.`);
|
|
313
|
+
}
|
|
314
|
+
if (enabled && wallets.length === 0) {
|
|
315
|
+
throw new errors_1.ConfigError('Wallet worker is enabled but no wallets are configured. Set walletWorker.wallets (or WALLET_WORKER_WALLETS).');
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
enabled,
|
|
319
|
+
wallets,
|
|
320
|
+
maxConcurrentWallets,
|
|
321
|
+
confirmationDepth,
|
|
322
|
+
confirmationTimeoutMs,
|
|
323
|
+
pollIntervalMs,
|
|
324
|
+
defaultMaxAttempts,
|
|
325
|
+
resubmitOnRollback,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
exports.AGENT_GRANTS_DELEGATES = ['mocked', 'basic', 'jwt', 'xsuaa', 'ias', 'dummy'];
|
|
329
|
+
exports.AGENT_GRANT_ADMIN_RATE_LIMIT_DEFAULT = 10;
|
|
330
|
+
// Grant administration calls per principal per hour. An invalid value logs a warning
|
|
331
|
+
// and falls back to the default. It never disables the feature.
|
|
332
|
+
function loadGrantAdminRateLimit(vars = process_1.env) {
|
|
333
|
+
const cfg = coreCdsConfig().agentGrants ?? {};
|
|
334
|
+
const raw = cfg.adminRateLimit !== undefined ? cfg.adminRateLimit : vars.AGENT_GRANT_ADMIN_RATE_LIMIT;
|
|
335
|
+
if (raw === undefined || raw === null || String(raw).trim() === '')
|
|
336
|
+
return exports.AGENT_GRANT_ADMIN_RATE_LIMIT_DEFAULT;
|
|
337
|
+
const n = Number(raw);
|
|
338
|
+
if (!Number.isInteger(n) || n < 1) {
|
|
339
|
+
logger.warn(`AGENT_GRANT_ADMIN_RATE_LIMIT "${String(raw)}" is not an integer >= 1; using ${exports.AGENT_GRANT_ADMIN_RATE_LIMIT_DEFAULT}`);
|
|
340
|
+
return exports.AGENT_GRANT_ADMIN_RATE_LIMIT_DEFAULT;
|
|
341
|
+
}
|
|
342
|
+
return n;
|
|
343
|
+
}
|
|
344
|
+
exports.AGENT_TOKEN_CACHE_MS_DEFAULT = 10_000;
|
|
345
|
+
// How long a resolved grant row is reused before the DB is read again. 0 disables the cache.
|
|
346
|
+
// This bounds how late a revoke on another replica takes effect.
|
|
347
|
+
function loadTokenCacheMs(vars = process_1.env) {
|
|
348
|
+
const cfg = coreCdsConfig().agentGrants ?? {};
|
|
349
|
+
const raw = cfg.tokenCacheMs !== undefined ? cfg.tokenCacheMs : vars.AGENT_TOKEN_CACHE_MS;
|
|
350
|
+
if (raw === undefined || raw === null || String(raw).trim() === '')
|
|
351
|
+
return exports.AGENT_TOKEN_CACHE_MS_DEFAULT;
|
|
352
|
+
const n = Number(raw);
|
|
353
|
+
if (!Number.isInteger(n) || n < 0) {
|
|
354
|
+
logger.warn(`AGENT_TOKEN_CACHE_MS "${String(raw)}" is not an integer >= 0; using ${exports.AGENT_TOKEN_CACHE_MS_DEFAULT}`);
|
|
355
|
+
return exports.AGENT_TOKEN_CACHE_MS_DEFAULT;
|
|
356
|
+
}
|
|
357
|
+
return n;
|
|
358
|
+
}
|
|
359
|
+
exports.AGENT_GRANT_USAGE_RETENTION_DAYS_DEFAULT = 400;
|
|
360
|
+
// Days a usage counter row is kept; 0 keeps every row. GetGrantUsage reads at most 366 days at once.
|
|
361
|
+
// An invalid value logs a warning and falls back to the default.
|
|
362
|
+
function loadGrantUsageRetentionDays(vars = process_1.env) {
|
|
363
|
+
const cfg = coreCdsConfig().agentGrants ?? {};
|
|
364
|
+
const raw = cfg.usageRetentionDays !== undefined ? cfg.usageRetentionDays : vars.AGENT_GRANT_USAGE_RETENTION_DAYS;
|
|
365
|
+
if (raw === undefined || raw === null || String(raw).trim() === '')
|
|
366
|
+
return exports.AGENT_GRANT_USAGE_RETENTION_DAYS_DEFAULT;
|
|
367
|
+
const n = Number(raw);
|
|
368
|
+
if (!Number.isInteger(n) || n < 0) {
|
|
369
|
+
logger.warn(`AGENT_GRANT_USAGE_RETENTION_DAYS "${String(raw)}" is not an integer >= 0; using ${exports.AGENT_GRANT_USAGE_RETENTION_DAYS_DEFAULT}`);
|
|
370
|
+
return exports.AGENT_GRANT_USAGE_RETENTION_DAYS_DEFAULT;
|
|
371
|
+
}
|
|
372
|
+
return n;
|
|
373
|
+
}
|
|
374
|
+
/** The configured `cds.requires.auth` as an object (the shorthand `"auth": "xsuaa"` is a string). */
|
|
375
|
+
function configuredAuth() {
|
|
376
|
+
const auth = cds_1.default.env?.requires?.auth;
|
|
377
|
+
if (typeof auth === 'string')
|
|
378
|
+
return { kind: auth };
|
|
379
|
+
return (auth ?? {});
|
|
380
|
+
}
|
|
381
|
+
/** The transport middleware, recognisable in `auth.impl` so activation stays idempotent. */
|
|
382
|
+
exports.AGENT_AUTH_IMPL = 'cap-auth';
|
|
383
|
+
/** A host-configured custom `cds.requires.auth.impl` (not this package's middleware); the lane wraps it. */
|
|
384
|
+
function customAuthImpl(auth = configuredAuth()) {
|
|
385
|
+
const impl = typeof auth.impl === 'string' ? auth.impl.trim() : '';
|
|
386
|
+
if (!impl || impl.includes(exports.AGENT_AUTH_IMPL))
|
|
387
|
+
return null;
|
|
388
|
+
return impl;
|
|
389
|
+
}
|
|
390
|
+
function loadAgentGrantsConfig(vars = process_1.env) {
|
|
391
|
+
const cfg = coreCdsConfig().agentGrants ?? {};
|
|
392
|
+
const enabledRaw = cfg.enabled !== undefined ? cfg.enabled : vars.AGENT_GRANTS_ENABLED;
|
|
393
|
+
const enabled = enabledRaw === true || String(enabledRaw ?? '').toLowerCase() === 'true';
|
|
394
|
+
const auth = configuredAuth();
|
|
395
|
+
const authKind = String(auth.kind ?? 'mocked');
|
|
396
|
+
// A host's own auth.impl becomes the delegate ("custom") unless configured otherwise.
|
|
397
|
+
const fallback = customAuthImpl(auth) ? 'custom' : authKind;
|
|
398
|
+
const delegateRaw = String(cfg.delegate ?? vars.AGENT_GRANTS_DELEGATE ?? fallback);
|
|
399
|
+
// `xsuaa-auth` / `basic-auth` spellings are what CAP itself accepts as kinds.
|
|
400
|
+
const delegate = delegateRaw.replace(/-auth$/, '');
|
|
401
|
+
if (enabled && delegate !== 'custom' && !exports.AGENT_GRANTS_DELEGATES.includes(delegate)) {
|
|
402
|
+
throw new Error(`Invalid agentGrants.delegate "${delegateRaw}". Must be one of: ${exports.AGENT_GRANTS_DELEGATES.join(', ')}, custom`);
|
|
403
|
+
}
|
|
404
|
+
if (enabled && delegate === 'custom' && !customAuthImpl(auth)) {
|
|
405
|
+
throw new Error('agentGrants.delegate "custom" needs a custom cds.requires.auth.impl to delegate to');
|
|
406
|
+
}
|
|
407
|
+
return { enabled, delegate, adminRateLimit: loadGrantAdminRateLimit(vars) };
|
|
408
|
+
}
|
|
409
|
+
//# sourceMappingURL=config.js.map
|
package/srv/server.d.ts
CHANGED
|
@@ -1,130 +1,35 @@
|
|
|
1
|
-
import { CardanoClient, CardanoClientConfig, BackendName
|
|
1
|
+
import { CardanoClient, CardanoClientConfig, BackendName } from './blockchain/cardano-client';
|
|
2
2
|
import { CardanoIndexer } from './blockchain/cardano-indexer';
|
|
3
3
|
import { CardanoTransactionBuilder } from './blockchain/cardano-tx-builder';
|
|
4
4
|
import type { LedgerProtocolParameters, HsmConfig } from './utils/types';
|
|
5
|
-
import type { CrawlerConfig } from './blockchain/crawler/crawler';
|
|
6
|
-
import type { WalletWorkerConfig } from './blockchain/wallet-worker';
|
|
7
|
-
/**
|
|
8
|
-
* Application context holding initialized blockchain components
|
|
9
|
-
* These are created once during CAP bootstrap and shared across services
|
|
10
|
-
*/
|
|
11
5
|
interface AppContext {
|
|
12
6
|
cardanoClient: CardanoClient;
|
|
13
7
|
cardanoIndexer: CardanoIndexer;
|
|
14
8
|
cardanoTxBuilder: CardanoTransactionBuilder;
|
|
15
9
|
}
|
|
16
|
-
/**
|
|
17
|
-
export { loadAgentGrantsConfig, activateAgentGrants } from './utils/agent-grants-config';
|
|
18
|
-
/**
|
|
19
|
-
* Get the application context (must be called after bootstrap)
|
|
20
|
-
* @throws {ProviderUnavailableError} 503 when uninitialized — request handlers using
|
|
21
|
-
* handleRequest/mapError translate this into a clean 503 response instead of a raw 500.
|
|
22
|
-
* If bootstrap actively failed, the cause is appended to the message.
|
|
23
|
-
*/
|
|
10
|
+
/** Throws 503 when uninitialized, with a bootstrap failure appended as cause. */
|
|
24
11
|
export declare function getAppContext(): AppContext;
|
|
25
|
-
/**
|
|
26
|
-
* Get the CardanoIndexer instance
|
|
27
|
-
* Convenience function for services
|
|
28
|
-
*/
|
|
29
12
|
export declare function getCardanoIndexer(): CardanoIndexer;
|
|
30
|
-
/**
|
|
31
|
-
* Get the CardanoClient instance
|
|
32
|
-
* Convenience function for services
|
|
33
|
-
*/
|
|
34
13
|
export declare function getCardanoClient(): CardanoClient;
|
|
35
|
-
/**
|
|
36
|
-
* Get the CardanoTransactionBuilder instance
|
|
37
|
-
* Convenience function for services and plugin consumers
|
|
38
|
-
*/
|
|
39
14
|
export declare function getCardanoTxBuilder(): CardanoTransactionBuilder;
|
|
40
|
-
/**
|
|
41
|
-
* Get the HSM configuration (if HSM is enabled).
|
|
42
|
-
* Used by sign service to check requiresRole.
|
|
43
|
-
*/
|
|
15
|
+
/** HSM configuration when enabled; the sign service reads requiresRole from it. */
|
|
44
16
|
export declare function getHsmConfig(): HsmConfig | undefined;
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
17
|
+
/** What getReadiness() reports about this process: the app context and, when configured, the HSM session. */
|
|
18
|
+
export declare function readinessParts(): {
|
|
19
|
+
context: boolean;
|
|
20
|
+
hsm: boolean | null;
|
|
21
|
+
};
|
|
50
22
|
export declare function initializeFromConfig(config: CardanoClientConfig, protocolParams?: LedgerProtocolParameters, hsmConfig?: HsmConfig): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* Reset the application context (for testing only)
|
|
53
|
-
* Allows tests to inject their own instances
|
|
54
|
-
*/
|
|
23
|
+
/** Reset the application context (tests only); lets tests inject their own instances. */
|
|
55
24
|
export declare function resetAppContext(context: AppContext | null): void;
|
|
56
|
-
/**
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* @param backends Array of backend names to use (e.g., ['koios'], ['blockfrost'])
|
|
60
|
-
* @param _txBuilderName Deprecated/ignored — Buildooor is the sole transaction builder (kept for signature compatibility)
|
|
61
|
-
* @param protocolParams Optional protocol parameters (to skip backend call during init)
|
|
62
|
-
* @returns Promise<AppContext> The created application context
|
|
63
|
-
*/
|
|
64
|
-
export declare function createTestContext(backends: BackendName[], _txBuilderName?: TransactionBuilderName, // kept for signature compat; Buildooor is the only builder
|
|
65
|
-
protocolParams?: LedgerProtocolParameters): Promise<AppContext>;
|
|
66
|
-
/**
|
|
67
|
-
* Shutdown the application context (for cleanup in tests)
|
|
68
|
-
* Closes all backend connections to allow process to exit cleanly
|
|
69
|
-
*/
|
|
25
|
+
/** Isolated test context: the configuration of the environment with the given backends. */
|
|
26
|
+
export declare function createTestContext(backends: BackendName[], protocolParams?: LedgerProtocolParameters): Promise<AppContext>;
|
|
27
|
+
/** Stop worker and crawler, then close all backend connections. Concurrent callers share one run. */
|
|
70
28
|
export declare function shutdownAppContext(): Promise<void>;
|
|
71
|
-
/**
|
|
72
|
-
* Load and validate CardanoClientConfig from CDS config or environment variables.
|
|
73
|
-
*
|
|
74
|
-
* When used as a plugin, consumers configure via package.json:
|
|
75
|
-
* { "cds": { "requires": { "odatano-core": { "network": "preview", "backends": ["blockfrost"], ... }}}}
|
|
76
|
-
*
|
|
77
|
-
* Priority: cds.env.requires["odatano-core"].X > process.env.X > default
|
|
78
|
-
*
|
|
79
|
-
* @returns validated CardanoClientConfig
|
|
80
|
-
* @throws {Error} if any config value is invalid
|
|
81
|
-
*/
|
|
82
|
-
export declare function loadConfigFromEnv(): CardanoClientConfig;
|
|
83
|
-
/**
|
|
84
|
-
* Load HSM configuration from CDS config or environment variables.
|
|
85
|
-
* Returns undefined if HSM is not enabled.
|
|
86
|
-
*
|
|
87
|
-
* Plugin mode: cds.requires.odatano-core.hsm.enabled = true
|
|
88
|
-
* Env mode: HSM_ENABLED=true
|
|
89
|
-
*
|
|
90
|
-
* @returns HsmConfig or undefined
|
|
91
|
-
*/
|
|
92
|
-
export declare function loadHsmConfigFromEnv(): HsmConfig | undefined;
|
|
93
|
-
/**
|
|
94
|
-
* Load the chain-crawler configuration from CDS config or environment variables.
|
|
95
|
-
* Returns { enabled:false } when the crawler is not switched on (the default), so
|
|
96
|
-
* existing deployments are unaffected.
|
|
97
|
-
*
|
|
98
|
-
* Plugin mode: cds.requires.odatano-core.crawler.{enabled,startSlot,startBlockHash,...}
|
|
99
|
-
* Env mode: CRAWLER_ENABLED / CRAWLER_START_SLOT / CRAWLER_START_HASH / ...
|
|
100
|
-
*/
|
|
101
|
-
export declare function loadCrawlerConfigFromEnv(): CrawlerConfig;
|
|
102
|
-
/**
|
|
103
|
-
* Start the chain crawler if it is enabled and the app context is ready. Never throws
|
|
104
|
-
* (crawler failure must not affect request serving) — errors are logged. Idempotent:
|
|
105
|
-
* startCrawler() is a no-op when one is already running.
|
|
106
|
-
*/
|
|
29
|
+
/** Start the crawler if enabled and the app context is ready. Never throws; idempotent. */
|
|
107
30
|
export declare function startCrawlerIfConfigured(): Promise<void>;
|
|
108
|
-
/**
|
|
109
|
-
* Load the wallet-worker configuration from CDS config or environment variables.
|
|
110
|
-
* Returns { enabled:false } when the worker is not switched on (the default).
|
|
111
|
-
*
|
|
112
|
-
* Plugin mode: cds.requires.odatano-core.walletWorker.{enabled,wallets,...}
|
|
113
|
-
* Env mode: WALLET_WORKER_ENABLED / WALLET_WORKER_WALLETS (JSON) / ...
|
|
114
|
-
*/
|
|
115
|
-
export declare function loadWalletWorkerConfigFromEnv(): WalletWorkerConfig;
|
|
116
|
-
/**
|
|
117
|
-
* Start the wallet worker if it is enabled and the app context is ready. Never
|
|
118
|
-
* throws (worker failure must not affect request serving) — errors are logged.
|
|
119
|
-
* Idempotent: startWalletWorker() is a no-op when one is already running.
|
|
120
|
-
*/
|
|
31
|
+
/** Start the wallet worker if enabled and the app context is ready. Never throws; idempotent. */
|
|
121
32
|
export declare function startWalletWorkerIfConfigured(): Promise<void>;
|
|
122
|
-
/**
|
|
123
|
-
* Re-drive deferred submissions that were claimed (status 'submitting' with
|
|
124
|
-
* persisted signedTxCbor) but whose detached submit never ran because the
|
|
125
|
-
* process died first (KNOWN_ISSUES #11, Layer 2). Idempotent — an already
|
|
126
|
-
* submitted tx finalizes via the TransactionAlreadySubmittedError path.
|
|
127
|
-
* Non-fatal, mirrors startCrawlerIfConfigured/startWalletWorkerIfConfigured.
|
|
128
|
-
*/
|
|
129
33
|
export declare function redriveInterruptedSubmissionsIfConfigured(): Promise<void>;
|
|
34
|
+
export {};
|
|
130
35
|
//# sourceMappingURL=server.d.ts.map
|