@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
package/srv/utils/const.d.ts
CHANGED
|
@@ -1,77 +1,48 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cardano protocol constants
|
|
3
|
-
*/
|
|
1
|
+
/** Cardano protocol constants */
|
|
4
2
|
export declare const CARDANO_DEFAULTS: {
|
|
5
3
|
/** Maximum ADA supply in lovelace (45 billion ADA) */
|
|
6
4
|
MAX_LOVELACE_SUPPLY: string;
|
|
7
5
|
/** Milliseconds per slot */
|
|
8
6
|
MS_PER_SLOT: number;
|
|
9
7
|
};
|
|
10
|
-
/**
|
|
11
|
-
* Network-specific epoch geometry, anchored at the Shelley transition:
|
|
12
|
-
* `epochStartSlot(epoch) = shelleyStartSlot + (epoch - shelleyStartEpoch) * slotsPerEpoch`.
|
|
13
|
-
* A single global SLOTS_PER_EPOCH is wrong twice over — preview uses 86 400 (1 day),
|
|
14
|
-
* and mainnet/preprod epochs are offset by their Byron era.
|
|
15
|
-
*/
|
|
16
8
|
export declare const EPOCH_CONFIG_BY_NETWORK: {
|
|
17
9
|
readonly mainnet: {
|
|
18
10
|
readonly shelleyStartEpoch: 208;
|
|
19
11
|
readonly shelleyStartSlot: 4492800;
|
|
20
12
|
readonly slotsPerEpoch: 432000;
|
|
13
|
+
readonly securityParam: 2160;
|
|
14
|
+
readonly activeSlotsCoeff: 0.05;
|
|
21
15
|
};
|
|
22
16
|
readonly preprod: {
|
|
23
17
|
readonly shelleyStartEpoch: 4;
|
|
24
18
|
readonly shelleyStartSlot: 86400;
|
|
25
19
|
readonly slotsPerEpoch: 432000;
|
|
20
|
+
readonly securityParam: 2160;
|
|
21
|
+
readonly activeSlotsCoeff: 0.05;
|
|
26
22
|
};
|
|
27
23
|
readonly preview: {
|
|
28
24
|
readonly shelleyStartEpoch: 0;
|
|
29
25
|
readonly shelleyStartSlot: 0;
|
|
30
26
|
readonly slotsPerEpoch: 86400;
|
|
27
|
+
readonly securityParam: 432;
|
|
28
|
+
readonly activeSlotsCoeff: 0.05;
|
|
31
29
|
};
|
|
32
30
|
};
|
|
33
|
-
/**
|
|
34
|
-
* Default execution units for Plutus scripts
|
|
35
|
-
* Used when dynamic evaluation is not available
|
|
36
|
-
*/
|
|
31
|
+
/** Default Plutus execution units when dynamic evaluation is not available */
|
|
37
32
|
export declare const DEFAULT_EXECUTION_UNITS: {
|
|
38
|
-
/** Memory units for script execution */
|
|
39
33
|
mem: number;
|
|
40
|
-
/** CPU steps for script execution */
|
|
41
34
|
cpu: number;
|
|
42
35
|
};
|
|
43
|
-
/**
|
|
44
|
-
* High execution units for initial transaction build (before evaluation)
|
|
45
|
-
* Set higher than DEFAULT to ensure fee estimation is sufficient before actual evaluation
|
|
46
|
-
*/
|
|
36
|
+
/** High execution units for the initial build pass, so the fee estimate holds before evaluation */
|
|
47
37
|
export declare const HIGH_EXECUTION_UNITS: {
|
|
48
|
-
/** Memory units - high for evaluation pass */
|
|
49
38
|
mem: number;
|
|
50
|
-
/** CPU steps - high for evaluation pass */
|
|
51
39
|
cpu: number;
|
|
52
40
|
};
|
|
53
|
-
/**
|
|
54
|
-
* Execution unit buffer — relative multiplier applied to evaluator output.
|
|
55
|
-
* Combined with ABS_* floors below so small validators also get a meaningful cushion.
|
|
56
|
-
*/
|
|
41
|
+
/** Relative multiplier on evaluator ExUnits; combined with the ABS_* floors below. */
|
|
57
42
|
export declare const EXECUTION_UNIT_BUFFER = 1.1;
|
|
58
|
-
/**
|
|
59
|
-
* Absolute ExUnits floor added on top of the relative multiplier.
|
|
60
|
-
*
|
|
61
|
-
* Rationale: validators that iterate reference inputs and decode inline CBOR
|
|
62
|
-
* datums (e.g. oracle-consuming mint policies) show a larger ScriptContext →
|
|
63
|
-
* ledger drift than the documented ~10k–30k CPU / ~50–100 mem band — real-world
|
|
64
|
-
* cases overshot a 50k/1k floor by ~27k CPU / ~56 mem, burning the submit fee.
|
|
65
|
-
* The floor is sized to cover reference-input + CBOR-decoding drift on top of
|
|
66
|
-
* the 10% relative multiplier; `max_tx_ex_units` still caps build-time totals,
|
|
67
|
-
* so oversizing here cannot push a tx past network limits — it only trades a
|
|
68
|
-
* few extra lovelace of fee for avoiding an opaque PlutusFailure on submit.
|
|
69
|
-
*/
|
|
70
43
|
export declare const ABS_CPU_BUFFER = 200000;
|
|
71
44
|
export declare const ABS_MEM_BUFFER = 5000;
|
|
72
|
-
/**
|
|
73
|
-
* Transaction building constants
|
|
74
|
-
*/
|
|
45
|
+
/** Transaction building constants */
|
|
75
46
|
/** Collateral amount in lovelace (5 ADA) */
|
|
76
47
|
export declare const COLLATERAL_LOVELACE = 5000000n;
|
|
77
48
|
/** Fee buffer in lovelace (1 ADA) */
|
|
@@ -90,13 +61,12 @@ export declare const HRP: {
|
|
|
90
61
|
stake: RegExp;
|
|
91
62
|
};
|
|
92
63
|
};
|
|
93
|
-
/**
|
|
94
|
-
* Input validation limits to prevent DoS attacks
|
|
95
|
-
*/
|
|
64
|
+
/** Input validation limits to prevent DoS attacks */
|
|
96
65
|
/** Maximum JSON string length in bytes (1MB) */
|
|
97
66
|
export declare const MAX_JSON_SIZE = 1048576;
|
|
98
67
|
/** Maximum nesting depth for JSON objects/arrays */
|
|
99
68
|
export declare const MAX_DEPTH = 10;
|
|
69
|
+
export declare const PLUTUS_DATA_MAX_DEPTH = 64;
|
|
100
70
|
/** Maximum number of keys in a JSON object */
|
|
101
71
|
export declare const MAX_KEYS = 100;
|
|
102
72
|
/** Maximum number of elements in a JSON array */
|
|
@@ -105,13 +75,7 @@ export declare const MAX_ARRAY_LENGTH = 1000;
|
|
|
105
75
|
export declare const MAX_STRING_LENGTH = 65536;
|
|
106
76
|
/** Maximum ech32 string length to prevent DoS */
|
|
107
77
|
export declare const BECH32_MAX_LENGTH = 2000;
|
|
108
|
-
|
|
109
|
-
* Maximum hex length of transaction CBOR accepted by ParseTransactionCbor.
|
|
110
|
-
* Mainnet `maxTxSize` is currently 16 KiB; 64 KiB raw (= 128 KiB hex) leaves
|
|
111
|
-
* generous headroom for future protocol bumps and reference-script outputs
|
|
112
|
-
* while keeping the parser from being a memory-exhaustion vector.
|
|
113
|
-
*/
|
|
114
|
-
export declare const MAX_TX_CBOR_HEX_LENGTH: number;
|
|
78
|
+
export declare const MAX_TX_CBOR_HEX_LENGTH = 65536;
|
|
115
79
|
/** Maximum reasonable epoch number */
|
|
116
80
|
export declare const MAX_EPOCH = 100000;
|
|
117
81
|
/** Standard pool ID payload length */
|
|
@@ -128,14 +92,9 @@ export declare const ED25519_KEY_HASH_HEX_LENGTH = 56;
|
|
|
128
92
|
export declare const ED25519_KEY_HASH_REGEX: RegExp;
|
|
129
93
|
/** Minimum lovelace for a change output carrying native assets (2 ADA) */
|
|
130
94
|
export declare const MIN_CHANGE_LOVELACE = 2000000;
|
|
131
|
-
/**
|
|
132
|
-
* Shelley-era genesis parameters per network, used to construct Buildooor's
|
|
133
|
-
* GenesisInfos so `TxBuilder.posixToSlot()` can convert validity-window
|
|
134
|
-
* Posix ms into ledger slots. `slotLengthMs` is 1000 ms on all current networks.
|
|
135
|
-
*/
|
|
136
95
|
export declare const GENESIS_INFOS_BY_NETWORK: {
|
|
137
96
|
readonly mainnet: {
|
|
138
|
-
readonly systemStartPosixMs:
|
|
97
|
+
readonly systemStartPosixMs: 1596059091000;
|
|
139
98
|
readonly slotLengthMs: 1000;
|
|
140
99
|
readonly startSlotNo: 4492800;
|
|
141
100
|
};
|
|
@@ -152,32 +111,30 @@ export declare const GENESIS_INFOS_BY_NETWORK: {
|
|
|
152
111
|
};
|
|
153
112
|
/** Default validity-window start offset: `now - 2 min` to absorb clock skew. */
|
|
154
113
|
export declare const DEFAULT_VALIDITY_START_OFFSET_MS = 120000;
|
|
155
|
-
/** Default validity-window end offset: `now + 1 h
|
|
114
|
+
/** Default validity-window end offset: `now + 1 h`, enough for human-latency sign+submit flows. */
|
|
156
115
|
export declare const DEFAULT_VALIDITY_END_OFFSET_MS: number;
|
|
116
|
+
/** Latest expiry ODATANO builds or sends, from now. It bounds how long a sent transaction stays undecided. */
|
|
117
|
+
export declare const MAX_VALIDITY_MS: number;
|
|
157
118
|
/** Max accepted digits in a Posix-ms string (13 digits covers Unix ms timestamps through ~Nov 2286). */
|
|
158
119
|
export declare const MAX_POSIX_MS_DIGITS = 13;
|
|
159
|
-
/**
|
|
160
|
-
* Generic 64-character hex string (used for block hashes and other 32-byte hex identifiers)
|
|
161
|
-
*/
|
|
120
|
+
/** Generic 64-character hex string (block hashes and other 32-byte identifiers) */
|
|
162
121
|
export declare const HEX_64_REGEX: RegExp;
|
|
163
|
-
/**
|
|
164
|
-
* Generic 56-character hex string — 28-byte hashes (Blake2b-224 / payment credential / script hash / pool key hash).
|
|
165
|
-
*/
|
|
122
|
+
/** Generic 56-character hex string: 28-byte hashes (Blake2b-224, payment credential, script hash, pool key hash) */
|
|
166
123
|
export declare const HEX_56_REGEX: RegExp;
|
|
167
|
-
/**
|
|
168
|
-
|
|
169
|
-
*/
|
|
124
|
+
/** How long a stored address, account, pool, DRep or asset answers before it is read again. */
|
|
125
|
+
export declare const DEFAULT_INDEX_TTL_MS = 3600000;
|
|
126
|
+
/** How long protocol parameters answer before the backend is asked again. */
|
|
127
|
+
export declare const PROTOCOL_PARAMS_TTL_MS: number;
|
|
128
|
+
/** Transaction hash: 64-character hex string */
|
|
170
129
|
export declare const TX_HASH_REGEX: RegExp;
|
|
171
|
-
/**
|
|
172
|
-
* Asset unit Regex - policy ID (56 hex chars) + asset name (0-128 hex chars)
|
|
173
|
-
*/
|
|
130
|
+
/** Asset unit: policy ID (56 hex) + asset name (0-32 bytes = 0-64 hex, even length; total <= 120 = String(120) key column) */
|
|
174
131
|
export declare const ASSET_UNIT_REGEX: RegExp;
|
|
175
|
-
/**
|
|
176
|
-
* Pool ID Regex - bech32 with HRP "pool" and 28 bytes payload
|
|
177
|
-
*/
|
|
132
|
+
/** Pool ID: bech32 with HRP "pool" and 28-byte payload */
|
|
178
133
|
export declare const POOL_ID_REGEX: RegExp;
|
|
179
|
-
/**
|
|
180
|
-
* DRep ID Regex - bech32 with HRP "drep" and 50-60 chars payload
|
|
181
|
-
*/
|
|
134
|
+
/** DRep ID: bech32 with HRP "drep" and 50-60 chars payload */
|
|
182
135
|
export declare const DREP_ID_REGEX: RegExp;
|
|
136
|
+
/** Ogmios submit refusal for inputs the ledger does not hold as unspent (schema: UnknownOutputReferences). */
|
|
137
|
+
export declare const OGMIOS_UNKNOWN_OUTPUT_REFERENCES = 3117;
|
|
138
|
+
/** Ogmios submit refusal by the mempool; its data.error is the node's own text (schema: UnexpectedMempoolError). */
|
|
139
|
+
export declare const OGMIOS_UNEXPECTED_MEMPOOL_ERROR = 3997;
|
|
183
140
|
//# sourceMappingURL=const.d.ts.map
|
package/srv/utils/const.js
CHANGED
|
@@ -1,68 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DREP_ID_REGEX = exports.POOL_ID_REGEX = exports.ASSET_UNIT_REGEX = exports.TX_HASH_REGEX = exports.HEX_56_REGEX = exports.HEX_64_REGEX = exports.MAX_POSIX_MS_DIGITS = exports.DEFAULT_VALIDITY_END_OFFSET_MS = exports.DEFAULT_VALIDITY_START_OFFSET_MS = exports.GENESIS_INFOS_BY_NETWORK = exports.MIN_CHANGE_LOVELACE = exports.ED25519_KEY_HASH_REGEX = exports.ED25519_KEY_HASH_HEX_LENGTH = exports.MIN_FULL_ASSET_UNIT_LENGTH = exports.POLICY_ID_HEX_LENGTH = exports.DREP_ID_BYTES = exports.POOL_ID_BYTES = exports.MAX_EPOCH = exports.MAX_TX_CBOR_HEX_LENGTH = exports.BECH32_MAX_LENGTH = exports.MAX_STRING_LENGTH = exports.MAX_ARRAY_LENGTH = exports.MAX_KEYS = exports.MAX_DEPTH = exports.MAX_JSON_SIZE = exports.HRP = exports.FEE_BUFFER_LOVELACE = exports.COLLATERAL_LOVELACE = exports.ABS_MEM_BUFFER = exports.ABS_CPU_BUFFER = exports.EXECUTION_UNIT_BUFFER = exports.HIGH_EXECUTION_UNITS = exports.DEFAULT_EXECUTION_UNITS = exports.EPOCH_CONFIG_BY_NETWORK = exports.CARDANO_DEFAULTS = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Cardano protocol constants
|
|
6
|
-
*/
|
|
3
|
+
exports.OGMIOS_UNEXPECTED_MEMPOOL_ERROR = exports.OGMIOS_UNKNOWN_OUTPUT_REFERENCES = exports.DREP_ID_REGEX = exports.POOL_ID_REGEX = exports.ASSET_UNIT_REGEX = exports.TX_HASH_REGEX = exports.PROTOCOL_PARAMS_TTL_MS = exports.DEFAULT_INDEX_TTL_MS = exports.HEX_56_REGEX = exports.HEX_64_REGEX = exports.MAX_POSIX_MS_DIGITS = exports.MAX_VALIDITY_MS = exports.DEFAULT_VALIDITY_END_OFFSET_MS = exports.DEFAULT_VALIDITY_START_OFFSET_MS = exports.GENESIS_INFOS_BY_NETWORK = exports.MIN_CHANGE_LOVELACE = exports.ED25519_KEY_HASH_REGEX = exports.ED25519_KEY_HASH_HEX_LENGTH = exports.MIN_FULL_ASSET_UNIT_LENGTH = exports.POLICY_ID_HEX_LENGTH = exports.DREP_ID_BYTES = exports.POOL_ID_BYTES = exports.MAX_EPOCH = exports.MAX_TX_CBOR_HEX_LENGTH = exports.BECH32_MAX_LENGTH = exports.MAX_STRING_LENGTH = exports.MAX_ARRAY_LENGTH = exports.MAX_KEYS = exports.PLUTUS_DATA_MAX_DEPTH = exports.MAX_DEPTH = exports.MAX_JSON_SIZE = exports.HRP = exports.FEE_BUFFER_LOVELACE = exports.COLLATERAL_LOVELACE = exports.ABS_MEM_BUFFER = exports.ABS_CPU_BUFFER = exports.EXECUTION_UNIT_BUFFER = exports.HIGH_EXECUTION_UNITS = exports.DEFAULT_EXECUTION_UNITS = exports.EPOCH_CONFIG_BY_NETWORK = exports.CARDANO_DEFAULTS = void 0;
|
|
4
|
+
/** Cardano protocol constants */
|
|
7
5
|
exports.CARDANO_DEFAULTS = {
|
|
8
6
|
/** Maximum ADA supply in lovelace (45 billion ADA) */
|
|
9
7
|
MAX_LOVELACE_SUPPLY: '45000000000000000',
|
|
10
8
|
/** Milliseconds per slot */
|
|
11
9
|
MS_PER_SLOT: 1000,
|
|
12
10
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* `epochStartSlot(epoch) = shelleyStartSlot + (epoch - shelleyStartEpoch) * slotsPerEpoch`.
|
|
16
|
-
* A single global SLOTS_PER_EPOCH is wrong twice over — preview uses 86 400 (1 day),
|
|
17
|
-
* and mainnet/preprod epochs are offset by their Byron era.
|
|
18
|
-
*/
|
|
11
|
+
// Epoch layout per network, counted from the first Shelley epoch and slot.
|
|
12
|
+
// securityParam is k, the number of recent blocks whose ledger state the node can still acquire.
|
|
19
13
|
exports.EPOCH_CONFIG_BY_NETWORK = {
|
|
20
|
-
mainnet: { shelleyStartEpoch: 208, shelleyStartSlot: 4_492_800, slotsPerEpoch: 432_000 },
|
|
21
|
-
preprod: { shelleyStartEpoch: 4, shelleyStartSlot: 86_400, slotsPerEpoch: 432_000 },
|
|
22
|
-
preview: { shelleyStartEpoch: 0, shelleyStartSlot: 0, slotsPerEpoch: 86_400 },
|
|
14
|
+
mainnet: { shelleyStartEpoch: 208, shelleyStartSlot: 4_492_800, slotsPerEpoch: 432_000, securityParam: 2160, activeSlotsCoeff: 0.05 },
|
|
15
|
+
preprod: { shelleyStartEpoch: 4, shelleyStartSlot: 86_400, slotsPerEpoch: 432_000, securityParam: 2160, activeSlotsCoeff: 0.05 },
|
|
16
|
+
preview: { shelleyStartEpoch: 0, shelleyStartSlot: 0, slotsPerEpoch: 86_400, securityParam: 432, activeSlotsCoeff: 0.05 },
|
|
23
17
|
};
|
|
24
|
-
/**
|
|
25
|
-
* Default execution units for Plutus scripts
|
|
26
|
-
* Used when dynamic evaluation is not available
|
|
27
|
-
*/
|
|
18
|
+
/** Default Plutus execution units when dynamic evaluation is not available */
|
|
28
19
|
exports.DEFAULT_EXECUTION_UNITS = {
|
|
29
|
-
/** Memory units for script execution */
|
|
30
20
|
mem: 14_000_000,
|
|
31
|
-
/** CPU steps for script execution */
|
|
32
21
|
cpu: 10_000_000_000,
|
|
33
22
|
};
|
|
34
|
-
/**
|
|
35
|
-
* High execution units for initial transaction build (before evaluation)
|
|
36
|
-
* Set higher than DEFAULT to ensure fee estimation is sufficient before actual evaluation
|
|
37
|
-
*/
|
|
23
|
+
/** High execution units for the initial build pass, so the fee estimate holds before evaluation */
|
|
38
24
|
exports.HIGH_EXECUTION_UNITS = {
|
|
39
|
-
/** Memory units - high for evaluation pass */
|
|
40
25
|
mem: 28_000_000,
|
|
41
|
-
/** CPU steps - high for evaluation pass */
|
|
42
26
|
cpu: 20_000_000_000,
|
|
43
27
|
};
|
|
44
|
-
/**
|
|
45
|
-
* Execution unit buffer — relative multiplier applied to evaluator output.
|
|
46
|
-
* Combined with ABS_* floors below so small validators also get a meaningful cushion.
|
|
47
|
-
*/
|
|
28
|
+
/** Relative multiplier on evaluator ExUnits; combined with the ABS_* floors below. */
|
|
48
29
|
exports.EXECUTION_UNIT_BUFFER = 1.1;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
*
|
|
52
|
-
* Rationale: validators that iterate reference inputs and decode inline CBOR
|
|
53
|
-
* datums (e.g. oracle-consuming mint policies) show a larger ScriptContext →
|
|
54
|
-
* ledger drift than the documented ~10k–30k CPU / ~50–100 mem band — real-world
|
|
55
|
-
* cases overshot a 50k/1k floor by ~27k CPU / ~56 mem, burning the submit fee.
|
|
56
|
-
* The floor is sized to cover reference-input + CBOR-decoding drift on top of
|
|
57
|
-
* the 10% relative multiplier; `max_tx_ex_units` still caps build-time totals,
|
|
58
|
-
* so oversizing here cannot push a tx past network limits — it only trades a
|
|
59
|
-
* few extra lovelace of fee for avoiding an opaque PlutusFailure on submit.
|
|
60
|
-
*/
|
|
30
|
+
// Fixed ExUnits margin added on top of the multiplier, for validators whose cost drifts
|
|
31
|
+
// with the script context. The protocol's max_tx_ex_units still caps the total.
|
|
61
32
|
exports.ABS_CPU_BUFFER = 200_000;
|
|
62
33
|
exports.ABS_MEM_BUFFER = 5_000;
|
|
63
|
-
/**
|
|
64
|
-
* Transaction building constants
|
|
65
|
-
*/
|
|
34
|
+
/** Transaction building constants */
|
|
66
35
|
/** Collateral amount in lovelace (5 ADA) */
|
|
67
36
|
exports.COLLATERAL_LOVELACE = 5000000n;
|
|
68
37
|
/** Fee buffer in lovelace (1 ADA) */
|
|
@@ -72,13 +41,13 @@ exports.HRP = {
|
|
|
72
41
|
preview: { addr: /^addr_test1[0-9a-z]{50,100}$/, stake: /^stake_test1[0-9a-z]{53,}$/ },
|
|
73
42
|
preprod: { addr: /^addr_test1[0-9a-z]{50,100}$/, stake: /^stake_test1[0-9a-z]{53,}$/ },
|
|
74
43
|
};
|
|
75
|
-
/**
|
|
76
|
-
* Input validation limits to prevent DoS attacks
|
|
77
|
-
*/
|
|
44
|
+
/** Input validation limits to prevent DoS attacks */
|
|
78
45
|
/** Maximum JSON string length in bytes (1MB) */
|
|
79
46
|
exports.MAX_JSON_SIZE = 1_048_576;
|
|
80
47
|
/** Maximum nesting depth for JSON objects/arrays */
|
|
81
48
|
exports.MAX_DEPTH = 10;
|
|
49
|
+
// Higher depth limit for PlutusData JSON. Each constructor uses two JSON levels, so real redeemers exceed MAX_DEPTH.
|
|
50
|
+
exports.PLUTUS_DATA_MAX_DEPTH = 64;
|
|
82
51
|
/** Maximum number of keys in a JSON object */
|
|
83
52
|
exports.MAX_KEYS = 100;
|
|
84
53
|
/** Maximum number of elements in a JSON array */
|
|
@@ -87,13 +56,9 @@ exports.MAX_ARRAY_LENGTH = 1000;
|
|
|
87
56
|
exports.MAX_STRING_LENGTH = 65536;
|
|
88
57
|
/** Maximum ech32 string length to prevent DoS */
|
|
89
58
|
exports.BECH32_MAX_LENGTH = 2000;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
* generous headroom for future protocol bumps and reference-script outputs
|
|
94
|
-
* while keeping the parser from being a memory-exhaustion vector.
|
|
95
|
-
*/
|
|
96
|
-
exports.MAX_TX_CBOR_HEX_LENGTH = 65536 * 2;
|
|
59
|
+
// Max CBOR hex of ParseTransactionCbor and DecodePlutusData: 32 KiB raw, twice the protocol's
|
|
60
|
+
// maxTxSize of 16 KiB. With its JSON wrapper it fits the 100 kB request body CAP accepts.
|
|
61
|
+
exports.MAX_TX_CBOR_HEX_LENGTH = 65536;
|
|
97
62
|
/** Maximum reasonable epoch number */
|
|
98
63
|
exports.MAX_EPOCH = 100_000;
|
|
99
64
|
/** Standard pool ID payload length */
|
|
@@ -110,44 +75,39 @@ exports.ED25519_KEY_HASH_HEX_LENGTH = 56;
|
|
|
110
75
|
exports.ED25519_KEY_HASH_REGEX = /^[a-f0-9]{56}$/i;
|
|
111
76
|
/** Minimum lovelace for a change output carrying native assets (2 ADA) */
|
|
112
77
|
exports.MIN_CHANGE_LOVELACE = 2_000_000;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
* GenesisInfos so `TxBuilder.posixToSlot()` can convert validity-window
|
|
116
|
-
* Posix ms into ledger slots. `slotLengthMs` is 1000 ms on all current networks.
|
|
117
|
-
*/
|
|
78
|
+
// Shelley genesis values per network for slot and time conversion.
|
|
79
|
+
// systemStartPosixMs is the wall-clock time of the first Shelley slot.
|
|
118
80
|
exports.GENESIS_INFOS_BY_NETWORK = {
|
|
119
|
-
mainnet: { systemStartPosixMs:
|
|
81
|
+
mainnet: { systemStartPosixMs: 1596059091000, slotLengthMs: 1000, startSlotNo: 4492800 }, // 2020-07-29T21:44:51Z
|
|
120
82
|
preprod: { systemStartPosixMs: 1655683200000, slotLengthMs: 1000, startSlotNo: 0 },
|
|
121
83
|
preview: { systemStartPosixMs: 1666656000000, slotLengthMs: 1000, startSlotNo: 0 },
|
|
122
84
|
};
|
|
123
85
|
/** Default validity-window start offset: `now - 2 min` to absorb clock skew. */
|
|
124
86
|
exports.DEFAULT_VALIDITY_START_OFFSET_MS = 120_000;
|
|
125
|
-
/** Default validity-window end offset: `now + 1 h
|
|
87
|
+
/** Default validity-window end offset: `now + 1 h`, enough for human-latency sign+submit flows. */
|
|
126
88
|
exports.DEFAULT_VALIDITY_END_OFFSET_MS = 60 * 60 * 1000;
|
|
89
|
+
/** Latest expiry ODATANO builds or sends, from now. It bounds how long a sent transaction stays undecided. */
|
|
90
|
+
exports.MAX_VALIDITY_MS = 24 * 60 * 60 * 1000;
|
|
127
91
|
/** Max accepted digits in a Posix-ms string (13 digits covers Unix ms timestamps through ~Nov 2286). */
|
|
128
92
|
exports.MAX_POSIX_MS_DIGITS = 13;
|
|
129
|
-
/**
|
|
130
|
-
* Generic 64-character hex string (used for block hashes and other 32-byte hex identifiers)
|
|
131
|
-
*/
|
|
93
|
+
/** Generic 64-character hex string (block hashes and other 32-byte identifiers) */
|
|
132
94
|
exports.HEX_64_REGEX = /^[a-f0-9]{64}$/;
|
|
133
|
-
/**
|
|
134
|
-
* Generic 56-character hex string — 28-byte hashes (Blake2b-224 / payment credential / script hash / pool key hash).
|
|
135
|
-
*/
|
|
95
|
+
/** Generic 56-character hex string: 28-byte hashes (Blake2b-224, payment credential, script hash, pool key hash) */
|
|
136
96
|
exports.HEX_56_REGEX = /^[a-f0-9]{56}$/;
|
|
137
|
-
/**
|
|
138
|
-
|
|
139
|
-
*/
|
|
97
|
+
/** How long a stored address, account, pool, DRep or asset answers before it is read again. */
|
|
98
|
+
exports.DEFAULT_INDEX_TTL_MS = 3_600_000;
|
|
99
|
+
/** How long protocol parameters answer before the backend is asked again. */
|
|
100
|
+
exports.PROTOCOL_PARAMS_TTL_MS = 5 * 60 * 1000;
|
|
101
|
+
/** Transaction hash: 64-character hex string */
|
|
140
102
|
exports.TX_HASH_REGEX = /^[a-f0-9]{64}$/;
|
|
141
|
-
/**
|
|
142
|
-
|
|
143
|
-
*/
|
|
144
|
-
exports.ASSET_UNIT_REGEX = /^[a-f0-9]{56}([a-f0-9]{2}){0,32}$/; // policy ID (56) + asset name (0-32 bytes per ledger rules -> 0-64 hex chars, even length; total ≤ 120 = String(120) key column)
|
|
145
|
-
/**
|
|
146
|
-
* Pool ID Regex - bech32 with HRP "pool" and 28 bytes payload
|
|
147
|
-
*/
|
|
103
|
+
/** Asset unit: policy ID (56 hex) + asset name (0-32 bytes = 0-64 hex, even length; total <= 120 = String(120) key column) */
|
|
104
|
+
exports.ASSET_UNIT_REGEX = /^[a-f0-9]{56}([a-f0-9]{2}){0,32}$/;
|
|
105
|
+
/** Pool ID: bech32 with HRP "pool" and 28-byte payload */
|
|
148
106
|
exports.POOL_ID_REGEX = /^pool1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{51}$/;
|
|
149
|
-
/**
|
|
150
|
-
* DRep ID Regex - bech32 with HRP "drep" and 50-60 chars payload
|
|
151
|
-
*/
|
|
107
|
+
/** DRep ID: bech32 with HRP "drep" and 50-60 chars payload */
|
|
152
108
|
exports.DREP_ID_REGEX = /^drep1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{50,60}$/;
|
|
109
|
+
/** Ogmios submit refusal for inputs the ledger does not hold as unspent (schema: UnknownOutputReferences). */
|
|
110
|
+
exports.OGMIOS_UNKNOWN_OUTPUT_REFERENCES = 3117;
|
|
111
|
+
/** Ogmios submit refusal by the mempool; its data.error is the node's own text (schema: UnexpectedMempoolError). */
|
|
112
|
+
exports.OGMIOS_UNEXPECTED_MEMPOOL_ERROR = 3997;
|
|
153
113
|
//# sourceMappingURL=const.js.map
|
package/srv/utils/crypto.d.ts
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Derive the 32-byte encryption key from the environment.
|
|
3
|
-
* Production: ENCRYPTION_KEY is required. Development: process-scoped fallback.
|
|
4
|
-
*/
|
|
1
|
+
/** 32-byte key from ENCRYPTION_KEY; development falls back to a process-scoped key. */
|
|
5
2
|
export declare function getEncryptionKey(): Buffer;
|
|
6
|
-
/**
|
|
7
|
-
* Encrypt plaintext with AES-256-GCM.
|
|
8
|
-
* Returns the combined format `base64(iv):base64(authTag):base64(ciphertext)`.
|
|
9
|
-
*/
|
|
3
|
+
/** Encrypts to `base64(iv):base64(authTag):base64(ciphertext)`. */
|
|
10
4
|
export declare function encrypt(plaintext: string, key: Buffer): string;
|
|
11
|
-
/**
|
|
12
|
-
* Decrypt a combined `iv:authTag:ciphertext` string back to plaintext.
|
|
13
|
-
* Throws on authentication failure (tampered ciphertext or wrong key).
|
|
14
|
-
*/
|
|
5
|
+
/** Decrypts a combined `iv:authTag:ciphertext` string; throws on auth-tag mismatch. */
|
|
15
6
|
export declare function decrypt(combined: string, key: Buffer): string;
|
|
16
7
|
//# sourceMappingURL=crypto.d.ts.map
|
package/srv/utils/crypto.js
CHANGED
|
@@ -9,38 +9,27 @@ exports.decrypt = decrypt;
|
|
|
9
9
|
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
10
10
|
const node_os_1 = __importDefault(require("node:os"));
|
|
11
11
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
12
|
+
const config_1 = require("../config");
|
|
12
13
|
const logger = cds_1.default.log('CardanoWalletWorker');
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
* Ported from NIGHTGATE's srv/utils/crypto.ts. Used to decrypt operator-provided
|
|
17
|
-
* software signing keys (`iv:authTag:ciphertext`, all base64). Keys are derived
|
|
18
|
-
* from the ENCRYPTION_KEY environment variable; production refuses to start
|
|
19
|
-
* without it, development falls back to a process-scoped key.
|
|
20
|
-
*/
|
|
14
|
+
// AES-256-GCM for secrets at rest, stored as base64 `iv:authTag:ciphertext`.
|
|
15
|
+
// The key comes from ENCRYPTION_KEY. Production refuses to start without it.
|
|
21
16
|
const ALGORITHM = 'aes-256-gcm';
|
|
22
17
|
const IV_LENGTH = 12; // 96 bits, recommended for GCM
|
|
23
18
|
const AUTH_TAG_LENGTH = 16; // 128 bits
|
|
24
|
-
/**
|
|
25
|
-
* Derive the 32-byte encryption key from the environment.
|
|
26
|
-
* Production: ENCRYPTION_KEY is required. Development: process-scoped fallback.
|
|
27
|
-
*/
|
|
19
|
+
/** 32-byte key from ENCRYPTION_KEY; development falls back to a process-scoped key. */
|
|
28
20
|
function getEncryptionKey() {
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
31
|
-
return node_crypto_1.default.createHash('sha256').update(
|
|
21
|
+
const secret = (0, config_1.encryptionSecret)();
|
|
22
|
+
if (secret) {
|
|
23
|
+
return node_crypto_1.default.createHash('sha256').update(secret).digest();
|
|
32
24
|
}
|
|
33
|
-
if (
|
|
25
|
+
if ((0, config_1.isProduction)()) {
|
|
34
26
|
throw new Error('ENCRYPTION_KEY must be set in production. Refusing to start with a fallback key.');
|
|
35
27
|
}
|
|
36
|
-
logger.warn('ENCRYPTION_KEY not set
|
|
28
|
+
logger.warn('ENCRYPTION_KEY not set, using dev fallback key. Set ENCRYPTION_KEY for production.');
|
|
37
29
|
const fallback = `odatano-core-${process.pid}-${node_os_1.default.hostname()}`;
|
|
38
30
|
return node_crypto_1.default.createHash('sha256').update(fallback).digest();
|
|
39
31
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Encrypt plaintext with AES-256-GCM.
|
|
42
|
-
* Returns the combined format `base64(iv):base64(authTag):base64(ciphertext)`.
|
|
43
|
-
*/
|
|
32
|
+
/** Encrypts to `base64(iv):base64(authTag):base64(ciphertext)`. */
|
|
44
33
|
function encrypt(plaintext, key) {
|
|
45
34
|
const iv = node_crypto_1.default.randomBytes(IV_LENGTH);
|
|
46
35
|
const cipher = node_crypto_1.default.createCipheriv(ALGORITHM, key, iv, { authTagLength: AUTH_TAG_LENGTH });
|
|
@@ -48,10 +37,7 @@ function encrypt(plaintext, key) {
|
|
|
48
37
|
const authTag = cipher.getAuthTag();
|
|
49
38
|
return `${iv.toString('base64')}:${authTag.toString('base64')}:${encrypted.toString('base64')}`;
|
|
50
39
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Decrypt a combined `iv:authTag:ciphertext` string back to plaintext.
|
|
53
|
-
* Throws on authentication failure (tampered ciphertext or wrong key).
|
|
54
|
-
*/
|
|
40
|
+
/** Decrypts a combined `iv:authTag:ciphertext` string; throws on auth-tag mismatch. */
|
|
55
41
|
function decrypt(combined, key) {
|
|
56
42
|
const parts = combined.split(':');
|
|
57
43
|
if (parts.length !== 3) {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface IndexSpec {
|
|
2
|
+
/** Index name; lower case, table-prefixed, so it cannot collide across tables. */
|
|
3
|
+
name: string;
|
|
4
|
+
/** Table name as @cap-js creates it (namespace_Entity). */
|
|
5
|
+
table: string;
|
|
6
|
+
/** Column list, comma separated, in the order the lookups use. */
|
|
7
|
+
columns: string;
|
|
8
|
+
/** PostgreSQL spelling when it differs (SQLite knows no NULLS in an index definition). */
|
|
9
|
+
postgres?: string;
|
|
10
|
+
}
|
|
11
|
+
/** Every entry answers a query the service or the crawler actually runs. */
|
|
12
|
+
export declare const DB_INDEXES: readonly IndexSpec[];
|
|
13
|
+
/** Indexes a composite entry above replaces; dropped at start. */
|
|
14
|
+
export declare const DROPPED_DB_INDEXES: readonly string[];
|
|
15
|
+
/** The statement for one entry; exported so tests pin the shape. */
|
|
16
|
+
export declare function indexStatement(spec: IndexSpec, kind?: string): string;
|
|
17
|
+
/** Anything that runs a plain SQL string: the primary db service. */
|
|
18
|
+
export type SqlRunner = {
|
|
19
|
+
run: (sql: string, params?: unknown[]) => Promise<unknown>;
|
|
20
|
+
kind?: string;
|
|
21
|
+
};
|
|
22
|
+
/** Names of our indexes in this schema that are invalid; only a failed concurrent build leaves one. */
|
|
23
|
+
export declare const INVALID_INDEXES_STATEMENT: string;
|
|
24
|
+
export declare const INDEX_LOCK_STATEMENT = "SELECT pg_try_advisory_lock(hashtext('odatano_db_indexes.' || current_schema())) AS locked";
|
|
25
|
+
export declare const INDEX_UNLOCK_STATEMENT = "SELECT pg_advisory_unlock(hashtext('odatano_db_indexes.' || current_schema()))";
|
|
26
|
+
/** Creates every missing index; a failing statement is logged and skipped, the others still run. */
|
|
27
|
+
export declare function ensureDbIndexes(runner?: SqlRunner | undefined): Promise<{
|
|
28
|
+
ensured: string[];
|
|
29
|
+
failed: string[];
|
|
30
|
+
}>;
|
|
31
|
+
//# sourceMappingURL=db-indexes.d.ts.map
|