@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/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.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.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 },
|
|
15
|
+
preprod: { shelleyStartEpoch: 4, shelleyStartSlot: 86_400, slotsPerEpoch: 432_000, securityParam: 2160 },
|
|
16
|
+
preview: { shelleyStartEpoch: 0, shelleyStartSlot: 0, slotsPerEpoch: 86_400, securityParam: 432 },
|
|
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,12 +56,7 @@ 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
|
-
* Maximum hex length of transaction CBOR accepted by ParseTransactionCbor.
|
|
92
|
-
* Mainnet `maxTxSize` is currently 16 KiB; 64 KiB raw (= 128 KiB hex) leaves
|
|
93
|
-
* generous headroom for future protocol bumps and reference-script outputs
|
|
94
|
-
* while keeping the parser from being a memory-exhaustion vector.
|
|
95
|
-
*/
|
|
59
|
+
/** Max tx CBOR hex accepted by ParseTransactionCbor: 64 KiB raw, well above mainnet maxTxSize (16 KiB). */
|
|
96
60
|
exports.MAX_TX_CBOR_HEX_LENGTH = 65536 * 2;
|
|
97
61
|
/** Maximum reasonable epoch number */
|
|
98
62
|
exports.MAX_EPOCH = 100_000;
|
|
@@ -110,44 +74,33 @@ exports.ED25519_KEY_HASH_HEX_LENGTH = 56;
|
|
|
110
74
|
exports.ED25519_KEY_HASH_REGEX = /^[a-f0-9]{56}$/i;
|
|
111
75
|
/** Minimum lovelace for a change output carrying native assets (2 ADA) */
|
|
112
76
|
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
|
-
*/
|
|
77
|
+
// Shelley genesis values per network for slot and time conversion.
|
|
78
|
+
// systemStartPosixMs is the wall-clock time of the first Shelley slot.
|
|
118
79
|
exports.GENESIS_INFOS_BY_NETWORK = {
|
|
119
|
-
mainnet: { systemStartPosixMs:
|
|
80
|
+
mainnet: { systemStartPosixMs: 1596059091000, slotLengthMs: 1000, startSlotNo: 4492800 }, // 2020-07-29T21:44:51Z
|
|
120
81
|
preprod: { systemStartPosixMs: 1655683200000, slotLengthMs: 1000, startSlotNo: 0 },
|
|
121
82
|
preview: { systemStartPosixMs: 1666656000000, slotLengthMs: 1000, startSlotNo: 0 },
|
|
122
83
|
};
|
|
123
84
|
/** Default validity-window start offset: `now - 2 min` to absorb clock skew. */
|
|
124
85
|
exports.DEFAULT_VALIDITY_START_OFFSET_MS = 120_000;
|
|
125
|
-
/** Default validity-window end offset: `now + 1 h
|
|
86
|
+
/** Default validity-window end offset: `now + 1 h`, enough for human-latency sign+submit flows. */
|
|
126
87
|
exports.DEFAULT_VALIDITY_END_OFFSET_MS = 60 * 60 * 1000;
|
|
127
88
|
/** Max accepted digits in a Posix-ms string (13 digits covers Unix ms timestamps through ~Nov 2286). */
|
|
128
89
|
exports.MAX_POSIX_MS_DIGITS = 13;
|
|
129
|
-
/**
|
|
130
|
-
* Generic 64-character hex string (used for block hashes and other 32-byte hex identifiers)
|
|
131
|
-
*/
|
|
90
|
+
/** Generic 64-character hex string (block hashes and other 32-byte identifiers) */
|
|
132
91
|
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
|
-
*/
|
|
92
|
+
/** Generic 56-character hex string: 28-byte hashes (Blake2b-224, payment credential, script hash, pool key hash) */
|
|
136
93
|
exports.HEX_56_REGEX = /^[a-f0-9]{56}$/;
|
|
137
|
-
/**
|
|
138
|
-
|
|
139
|
-
*/
|
|
94
|
+
/** How long a stored address, account, pool, DRep or asset answers before it is read again. */
|
|
95
|
+
exports.DEFAULT_INDEX_TTL_MS = 3_600_000;
|
|
96
|
+
/** How long protocol parameters answer before the backend is asked again. */
|
|
97
|
+
exports.PROTOCOL_PARAMS_TTL_MS = 5 * 60 * 1000;
|
|
98
|
+
/** Transaction hash: 64-character hex string */
|
|
140
99
|
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
|
-
*/
|
|
100
|
+
/** Asset unit: policy ID (56 hex) + asset name (0-32 bytes = 0-64 hex, even length; total <= 120 = String(120) key column) */
|
|
101
|
+
exports.ASSET_UNIT_REGEX = /^[a-f0-9]{56}([a-f0-9]{2}){0,32}$/;
|
|
102
|
+
/** Pool ID: bech32 with HRP "pool" and 28-byte payload */
|
|
148
103
|
exports.POOL_ID_REGEX = /^pool1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{51}$/;
|
|
149
|
-
/**
|
|
150
|
-
* DRep ID Regex - bech32 with HRP "drep" and 50-60 chars payload
|
|
151
|
-
*/
|
|
104
|
+
/** DRep ID: bech32 with HRP "drep" and 50-60 chars payload */
|
|
152
105
|
exports.DREP_ID_REGEX = /^drep1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{50,60}$/;
|
|
153
106
|
//# 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
|
@@ -10,21 +10,12 @@ 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
12
|
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
|
-
*/
|
|
13
|
+
// AES-256-GCM for secrets at rest, stored as base64 `iv:authTag:ciphertext`.
|
|
14
|
+
// The key comes from ENCRYPTION_KEY. Production refuses to start without it.
|
|
21
15
|
const ALGORITHM = 'aes-256-gcm';
|
|
22
16
|
const IV_LENGTH = 12; // 96 bits, recommended for GCM
|
|
23
17
|
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
|
-
*/
|
|
18
|
+
/** 32-byte key from ENCRYPTION_KEY; development falls back to a process-scoped key. */
|
|
28
19
|
function getEncryptionKey() {
|
|
29
20
|
const envKey = process.env.ENCRYPTION_KEY;
|
|
30
21
|
if (envKey) {
|
|
@@ -33,14 +24,11 @@ function getEncryptionKey() {
|
|
|
33
24
|
if (process.env.NODE_ENV === 'production') {
|
|
34
25
|
throw new Error('ENCRYPTION_KEY must be set in production. Refusing to start with a fallback key.');
|
|
35
26
|
}
|
|
36
|
-
logger.warn('ENCRYPTION_KEY not set
|
|
27
|
+
logger.warn('ENCRYPTION_KEY not set, using dev fallback key. Set ENCRYPTION_KEY for production.');
|
|
37
28
|
const fallback = `odatano-core-${process.pid}-${node_os_1.default.hostname()}`;
|
|
38
29
|
return node_crypto_1.default.createHash('sha256').update(fallback).digest();
|
|
39
30
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Encrypt plaintext with AES-256-GCM.
|
|
42
|
-
* Returns the combined format `base64(iv):base64(authTag):base64(ciphertext)`.
|
|
43
|
-
*/
|
|
31
|
+
/** Encrypts to `base64(iv):base64(authTag):base64(ciphertext)`. */
|
|
44
32
|
function encrypt(plaintext, key) {
|
|
45
33
|
const iv = node_crypto_1.default.randomBytes(IV_LENGTH);
|
|
46
34
|
const cipher = node_crypto_1.default.createCipheriv(ALGORITHM, key, iv, { authTagLength: AUTH_TAG_LENGTH });
|
|
@@ -48,10 +36,7 @@ function encrypt(plaintext, key) {
|
|
|
48
36
|
const authTag = cipher.getAuthTag();
|
|
49
37
|
return `${iv.toString('base64')}:${authTag.toString('base64')}:${encrypted.toString('base64')}`;
|
|
50
38
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Decrypt a combined `iv:authTag:ciphertext` string back to plaintext.
|
|
53
|
-
* Throws on authentication failure (tampered ciphertext or wrong key).
|
|
54
|
-
*/
|
|
39
|
+
/** Decrypts a combined `iv:authTag:ciphertext` string; throws on auth-tag mismatch. */
|
|
55
40
|
function decrypt(combined, key) {
|
|
56
41
|
const parts = combined.split(':');
|
|
57
42
|
if (parts.length !== 3) {
|
|
@@ -0,0 +1,27 @@
|
|
|
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) => Promise<unknown>;
|
|
20
|
+
kind?: string;
|
|
21
|
+
};
|
|
22
|
+
/** Creates every missing index; a failing statement is logged and skipped, the others still run. */
|
|
23
|
+
export declare function ensureDbIndexes(runner?: SqlRunner | undefined): Promise<{
|
|
24
|
+
ensured: string[];
|
|
25
|
+
failed: string[];
|
|
26
|
+
}>;
|
|
27
|
+
//# sourceMappingURL=db-indexes.d.ts.map
|
|
@@ -0,0 +1,120 @@
|
|
|
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.DROPPED_DB_INDEXES = exports.DB_INDEXES = void 0;
|
|
7
|
+
exports.indexStatement = indexStatement;
|
|
8
|
+
exports.ensureDbIndexes = ensureDbIndexes;
|
|
9
|
+
// Secondary indexes the CDS model cannot declare, created at start. Temporal keys start with validFrom,
|
|
10
|
+
// so lookups by business key would scan without them. Failures are logged, never fatal.
|
|
11
|
+
// HANA is skipped because it has no CREATE INDEX IF NOT EXISTS.
|
|
12
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
13
|
+
const logger = cds_1.default.log('DbIndexes');
|
|
14
|
+
/** Every entry answers a query the service or the crawler actually runs. */
|
|
15
|
+
exports.DB_INDEXES = Object.freeze([
|
|
16
|
+
// Blocks: latest (ORDER BY height DESC), byHeight, crawler `height in`, rollback `slot >`, epoch filters
|
|
17
|
+
{ name: 'odatano_cardano_blocks_height', table: 'odatano_cardano_Blocks', columns: 'height' },
|
|
18
|
+
// CAP renders `$orderby=height desc` as DESC NULLS LAST, which the plain ASC NULLS LAST
|
|
19
|
+
// index cannot serve backwards; the plain one stays for ASC and equality.
|
|
20
|
+
{ name: 'odatano_cardano_blocks_height_desc', table: 'odatano_cardano_Blocks', columns: 'height DESC', postgres: 'height DESC NULLS LAST' },
|
|
21
|
+
{ name: 'odatano_cardano_blocks_slot', table: 'odatano_cardano_Blocks', columns: 'slot' },
|
|
22
|
+
{ name: 'odatano_cardano_blocks_epoch', table: 'odatano_cardano_Blocks', columns: 'epochNumber' },
|
|
23
|
+
// the first block at or after a point in time (`$filter=time ge …&$orderby=time`)
|
|
24
|
+
// CAP sorts a nullable column as ASC NULLS FIRST or DESC NULLS LAST on PostgreSQL; this serves both
|
|
25
|
+
{ name: 'odatano_cardano_blocks_time', table: 'odatano_cardano_Blocks', columns: 'time', postgres: 'time NULLS FIRST' },
|
|
26
|
+
// block counts per pool (Pools.blocksEpoch / blocksMinted from crawled blocks)
|
|
27
|
+
{ name: 'odatano_cardano_blocks_slotleader', table: 'odatano_cardano_Blocks', columns: 'slotLeader, slot' },
|
|
28
|
+
// Transactions of a block in block order (rollback `blockHash in`, GetBlockTransactions)
|
|
29
|
+
{ name: 'odatano_cardano_transactions_block_idx', table: 'odatano_cardano_Transactions', columns: 'blockHash, txIndex' },
|
|
30
|
+
{ name: 'odatano_cardano_transactions_height', table: 'odatano_cardano_Transactions', columns: 'blockHeight' },
|
|
31
|
+
// Input/output rows back to their transaction (`tx` association, stale-seq check of the crawler)
|
|
32
|
+
{ name: 'odatano_cardano_transactions_txseq', table: 'odatano_cardano_Transactions', columns: 'txSeq' },
|
|
33
|
+
// GetMetadataByTxHash, rollback
|
|
34
|
+
{ name: 'odatano_cardano_transactionmetadata_tx', table: 'odatano_cardano_TransactionMetadata', columns: 'tx_hash' },
|
|
35
|
+
{ name: 'odatano_cardano_transactionmetadata_label_seq', table: 'odatano_cardano_TransactionMetadata', columns: 'id, txSeq' },
|
|
36
|
+
// rollback `txHash in` (key is unit, txHash); newest events of a unit
|
|
37
|
+
{ name: 'odatano_cardano_assethistory_tx', table: 'odatano_cardano_AssetHistory', columns: 'txHash' },
|
|
38
|
+
{ name: 'odatano_cardano_assethistory_unit_height', table: 'odatano_cardano_AssetHistory', columns: 'unit, blockHeight DESC', postgres: 'unit, blockHeight DESC NULLS LAST' },
|
|
39
|
+
// temporal entities: the business key behind validFrom
|
|
40
|
+
{ name: 'odatano_cardano_assets_unit', table: 'odatano_cardano_Assets', columns: 'unit' },
|
|
41
|
+
{ name: 'odatano_cardano_addresses_address', table: 'odatano_cardano_Addresses', columns: 'address' },
|
|
42
|
+
{ name: 'odatano_cardano_addressutxos_address', table: 'odatano_cardano_AddressUTxOs', columns: 'address_address' },
|
|
43
|
+
{ name: 'odatano_cardano_addressassets_address', table: 'odatano_cardano_AddressAssets', columns: 'address_address' },
|
|
44
|
+
{ name: 'odatano_cardano_utxoassets_address', table: 'odatano_cardano_UTxOAssets', columns: 'utxo_address_address' },
|
|
45
|
+
{ name: 'odatano_cardano_addresstransactions_tx', table: 'odatano_cardano_AddressTransactions', columns: 'tx_hash' },
|
|
46
|
+
{ name: 'odatano_cardano_accounts_stake', table: 'odatano_cardano_Accounts', columns: 'stakeAddress' },
|
|
47
|
+
{ name: 'odatano_cardano_pools_poolid', table: 'odatano_cardano_Pools', columns: 'poolId' },
|
|
48
|
+
{ name: 'odatano_cardano_dreps_drepid', table: 'odatano_cardano_Dreps', columns: 'drepId' },
|
|
49
|
+
// agent token lane: one lookup by token hash per request
|
|
50
|
+
{ name: 'odatano_cardano_cardanoagentgrants_token', table: 'odatano_cardano_CardanoAgentGrants', columns: 'tokenHash' },
|
|
51
|
+
// crawler-fed ledger state: "who spent this output" and delegation per stake key / pool / DRep
|
|
52
|
+
{ name: 'odatano_cardano_transactioninputs_spent', table: 'odatano_cardano_TransactionInputs', columns: 'spentTxHash, spentOutputIndex' },
|
|
53
|
+
// outputs to / inputs from a payment credential in slot order (txSeq); datum lookup by hash across txs
|
|
54
|
+
{ name: 'odatano_cardano_transactionoutputs_paycred', table: 'odatano_cardano_TransactionOutputs', columns: 'utxo_paymentCredential, txSeq' },
|
|
55
|
+
{ name: 'odatano_cardano_transactioninputs_paycred', table: 'odatano_cardano_TransactionInputs', columns: 'utxoData_paymentCredential, txSeq' },
|
|
56
|
+
{ name: 'odatano_cardano_transactiondatums_hash', table: 'odatano_cardano_TransactionDatums', columns: 'dataHash' },
|
|
57
|
+
{ name: 'odatano_cardano_transactioncertificates_stake', table: 'odatano_cardano_TransactionCertificates', columns: 'stakeAddress' },
|
|
58
|
+
{ name: 'odatano_cardano_transactioncertificates_pool', table: 'odatano_cardano_TransactionCertificates', columns: 'poolId' },
|
|
59
|
+
{ name: 'odatano_cardano_transactioncertificates_drep', table: 'odatano_cardano_TransactionCertificates', columns: 'drepId' },
|
|
60
|
+
{ name: 'odatano_cardano_transactionwithdrawals_stake', table: 'odatano_cardano_TransactionWithdrawals', columns: 'stakeAddress' },
|
|
61
|
+
// all accounts of one epoch; the key starts with the stake address
|
|
62
|
+
{ name: 'odatano_cardano_accountepochsnapshots_epoch', table: 'odatano_cardano_AccountEpochSnapshots', columns: 'epoch' },
|
|
63
|
+
// crawler-fed UTxO set: open rows per address, "who spent", stake-key rollups, asset holders
|
|
64
|
+
{ name: 'odatano_cardano_ledgerutxos_address', table: 'odatano_cardano_LedgerUTxOs', columns: 'address, spentTxHash' },
|
|
65
|
+
// newest created and spent rows of an address (latest transactions from the UTxO set)
|
|
66
|
+
{ name: 'odatano_cardano_ledgerutxos_address_created', table: 'odatano_cardano_LedgerUTxOs', columns: 'address, createdSlot' },
|
|
67
|
+
{ name: 'odatano_cardano_ledgerutxos_address_spent', table: 'odatano_cardano_LedgerUTxOs', columns: 'address, spentSlot' },
|
|
68
|
+
{ name: 'odatano_cardano_ledgerutxos_spent', table: 'odatano_cardano_LedgerUTxOs', columns: 'spentTxHash' },
|
|
69
|
+
{ name: 'odatano_cardano_ledgerutxos_paycred', table: 'odatano_cardano_LedgerUTxOs', columns: 'utxo_paymentCredential, spentTxHash' },
|
|
70
|
+
{ name: 'odatano_cardano_ledgeraddresses_stake', table: 'odatano_cardano_LedgerAddresses', columns: 'stakeAddress' },
|
|
71
|
+
{ name: 'odatano_cardano_ledgeraddresses_paycred', table: 'odatano_cardano_LedgerAddresses', columns: 'paymentCredential' },
|
|
72
|
+
{ name: 'odatano_cardano_ledgerutxoassets_unit', table: 'odatano_cardano_LedgerUTxOAssets', columns: 'unit' },
|
|
73
|
+
{ name: 'odatano_cardano_ledgeraddressassets_unit', table: 'odatano_cardano_LedgerAddressAssets', columns: 'unit' },
|
|
74
|
+
// wallet worker: jobs by status, and the jobs of one wallet with its next due job in dispatch order
|
|
75
|
+
{ name: 'odatano_cardano_cardanowalletjobs_status', table: 'odatano_cardano_CardanoWalletJobs', columns: 'status' },
|
|
76
|
+
{ name: 'odatano_cardano_cardanowalletjobs_next', table: 'odatano_cardano_CardanoWalletJobs', columns: 'walletId, status, priority, createdAt' },
|
|
77
|
+
]);
|
|
78
|
+
/** Indexes a composite entry above replaces; dropped at start. */
|
|
79
|
+
exports.DROPPED_DB_INDEXES = Object.freeze([
|
|
80
|
+
'odatano_cardano_transactions_block',
|
|
81
|
+
'odatano_cardano_cardanowalletjobs_due',
|
|
82
|
+
'odatano_cardano_cardanowalletjobs_wallet',
|
|
83
|
+
]);
|
|
84
|
+
/** The statement for one entry; exported so tests pin the shape. */
|
|
85
|
+
function indexStatement(spec, kind = 'sqlite') {
|
|
86
|
+
const columns = kind === 'postgres' && spec.postgres ? spec.postgres : spec.columns;
|
|
87
|
+
return `CREATE INDEX IF NOT EXISTS ${spec.name} ON ${spec.table} (${columns})`;
|
|
88
|
+
}
|
|
89
|
+
/** Creates every missing index; a failing statement is logged and skipped, the others still run. */
|
|
90
|
+
async function ensureDbIndexes(runner = cds_1.default.db) {
|
|
91
|
+
const ensured = [];
|
|
92
|
+
const failed = [];
|
|
93
|
+
if (!runner) {
|
|
94
|
+
logger.debug('no database service connected, indexes skipped');
|
|
95
|
+
return { ensured, failed };
|
|
96
|
+
}
|
|
97
|
+
const kind = String(runner.kind ?? 'sqlite');
|
|
98
|
+
if (kind === 'hana') {
|
|
99
|
+
logger.info('HANA: secondary indexes not created (column store, no IF NOT EXISTS)');
|
|
100
|
+
return { ensured, failed };
|
|
101
|
+
}
|
|
102
|
+
for (const name of exports.DROPPED_DB_INDEXES) {
|
|
103
|
+
await runner.run(`DROP INDEX IF EXISTS ${name}`)
|
|
104
|
+
.catch((err) => logger.warn(`index ${name} not dropped: ${String(err?.message ?? err)}`));
|
|
105
|
+
}
|
|
106
|
+
for (const spec of exports.DB_INDEXES) {
|
|
107
|
+
try {
|
|
108
|
+
await runner.run(indexStatement(spec, kind));
|
|
109
|
+
ensured.push(spec.name);
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
failed.push(spec.name);
|
|
113
|
+
logger.warn(`index ${spec.name} on ${spec.table} not ensured: ${String(err?.message ?? err)}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (failed.length === 0)
|
|
117
|
+
logger.info(`${ensured.length} indexes ensured`);
|
|
118
|
+
return { ensured, failed };
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=db-indexes.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Remove U+0000 from every string value of the row (nested objects included); same row when unchanged. */
|
|
2
|
+
export declare function stripNulStrings<T>(row: T): T;
|
|
3
|
+
/** Sanitise a row array for the database; cheap when nothing needs changing. */
|
|
4
|
+
export declare function sanitizeRows<T>(rows: T[]): T[];
|
|
5
|
+
/** The slice of a db-service request the sanitizer looks at (structural, so tests can fake it). */
|
|
6
|
+
export interface DbWriteRequest {
|
|
7
|
+
query?: unknown;
|
|
8
|
+
target?: {
|
|
9
|
+
name?: string;
|
|
10
|
+
} | null;
|
|
11
|
+
}
|
|
12
|
+
/** `before` handler for the db service: strips U+0000 from INSERT / UPSERT / UPDATE rows in place. */
|
|
13
|
+
export declare function sanitizeDbRequest(req: DbWriteRequest): void;
|
|
14
|
+
interface HookableService {
|
|
15
|
+
before(event: string | string[], handler: (req: DbWriteRequest) => void): unknown;
|
|
16
|
+
}
|
|
17
|
+
/** Hooks the sanitizer into the database service once. Returns true when this call installed it. */
|
|
18
|
+
export declare function installDbSanitizer(db?: HookableService | undefined): boolean;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=db-sanitize.d.ts.map
|
|
@@ -0,0 +1,80 @@
|
|
|
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.stripNulStrings = stripNulStrings;
|
|
7
|
+
exports.sanitizeRows = sanitizeRows;
|
|
8
|
+
exports.sanitizeDbRequest = sanitizeDbRequest;
|
|
9
|
+
exports.installDbSanitizer = installDbSanitizer;
|
|
10
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
11
|
+
// Strips U+0000 from every row this plugin writes. PostgreSQL cannot store NUL in text,
|
|
12
|
+
// and one NUL fails a whole bulk write.
|
|
13
|
+
/** Remove U+0000 from every string value of the row (nested objects included); same row when unchanged. */
|
|
14
|
+
function stripNulStrings(row) {
|
|
15
|
+
if (typeof row === 'string')
|
|
16
|
+
return (row.includes('\u0000') ? row.replaceAll('\u0000', '') : row);
|
|
17
|
+
if (row === null || typeof row !== 'object' || Buffer.isBuffer(row))
|
|
18
|
+
return row;
|
|
19
|
+
if (Array.isArray(row)) {
|
|
20
|
+
let out = null;
|
|
21
|
+
for (let i = 0; i < row.length; i++) {
|
|
22
|
+
const v = stripNulStrings(row[i]);
|
|
23
|
+
if (v !== row[i]) {
|
|
24
|
+
out ??= [...row];
|
|
25
|
+
out[i] = v;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return (out ?? row);
|
|
29
|
+
}
|
|
30
|
+
let out = null;
|
|
31
|
+
for (const [k, v] of Object.entries(row)) {
|
|
32
|
+
const nv = stripNulStrings(v);
|
|
33
|
+
if (nv !== v) {
|
|
34
|
+
out ??= { ...row };
|
|
35
|
+
out[k] = nv;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return (out ?? row);
|
|
39
|
+
}
|
|
40
|
+
/** Sanitise a row array for the database; cheap when nothing needs changing. */
|
|
41
|
+
function sanitizeRows(rows) {
|
|
42
|
+
let out = null;
|
|
43
|
+
for (let i = 0; i < rows.length; i++) {
|
|
44
|
+
const r = stripNulStrings(rows[i]);
|
|
45
|
+
if (r !== rows[i]) {
|
|
46
|
+
out ??= [...rows];
|
|
47
|
+
out[i] = r;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return out ?? rows;
|
|
51
|
+
}
|
|
52
|
+
/** Only this plugin's entities are rewritten; a consumer's own data is never touched. */
|
|
53
|
+
const OWN_NAMESPACE = 'odatano.cardano.';
|
|
54
|
+
/** `before` handler for the db service: strips U+0000 from INSERT / UPSERT / UPDATE rows in place. */
|
|
55
|
+
function sanitizeDbRequest(req) {
|
|
56
|
+
if (!req.target?.name?.startsWith(OWN_NAMESPACE))
|
|
57
|
+
return;
|
|
58
|
+
const q = req.query;
|
|
59
|
+
if (!q || typeof q !== 'object')
|
|
60
|
+
return;
|
|
61
|
+
const ins = q.INSERT;
|
|
62
|
+
if (ins && Array.isArray(ins.entries))
|
|
63
|
+
ins.entries = sanitizeRows(ins.entries);
|
|
64
|
+
const ups = q.UPSERT;
|
|
65
|
+
if (ups && Array.isArray(ups.entries))
|
|
66
|
+
ups.entries = sanitizeRows(ups.entries);
|
|
67
|
+
const upd = q.UPDATE;
|
|
68
|
+
if (upd?.data && typeof upd.data === 'object')
|
|
69
|
+
upd.data = stripNulStrings(upd.data);
|
|
70
|
+
}
|
|
71
|
+
const installed = new WeakSet();
|
|
72
|
+
/** Hooks the sanitizer into the database service once. Returns true when this call installed it. */
|
|
73
|
+
function installDbSanitizer(db = cds_1.default.db) {
|
|
74
|
+
if (!db || typeof db.before !== 'function' || installed.has(db))
|
|
75
|
+
return false;
|
|
76
|
+
db.before(['CREATE', 'UPSERT', 'UPDATE'], sanitizeDbRequest);
|
|
77
|
+
installed.add(db);
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=db-sanitize.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { JSONValue } from './types';
|
|
2
|
+
/** JSON.stringify without a replacer. Big integers are written as plain digits. */
|
|
3
|
+
export declare function stringifyJson(root: unknown): string;
|
|
4
|
+
/** JSON.parse with long integer literals as bigint. No key rewrite and no field-specific rule. */
|
|
5
|
+
export declare function parseJson(text: string): JSONValue;
|
|
6
|
+
//# sourceMappingURL=deep-json.d.ts.map
|