@odatano/core 2.0.0-rc.4 → 2.0.0-rc.41

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.
Files changed (166) hide show
  1. package/@cds-models/CardanoAgentService/index.d.ts +251 -0
  2. package/@cds-models/CardanoAgentService/index.js +36 -0
  3. package/@cds-models/CardanoBackendService/index.d.ts +357 -0
  4. package/@cds-models/CardanoBackendService/index.js +40 -0
  5. package/@cds-models/CardanoIndexerService/index.d.ts +194 -2
  6. package/@cds-models/CardanoIndexerService/index.js +25 -0
  7. package/@cds-models/CardanoODataService/index.d.ts +305 -7
  8. package/@cds-models/CardanoODataService/index.js +34 -0
  9. package/@cds-models/CardanoSignService/index.d.ts +28 -3
  10. package/@cds-models/CardanoSignService/index.js +3 -0
  11. package/@cds-models/CardanoTransactionService/index.d.ts +46 -13
  12. package/@cds-models/CardanoTransactionService/index.js +4 -0
  13. package/@cds-models/index.d.ts +72 -0
  14. package/@cds-models/index.js +12 -0
  15. package/@cds-models/odatano/cardano/index.d.ts +408 -7
  16. package/@cds-models/odatano/cardano/index.js +42 -0
  17. package/README.md +64 -5
  18. package/db/schema.cds +2297 -1633
  19. package/db/types.cds +114 -0
  20. package/package.json +27 -6
  21. package/scripts/migrate-slot-leader.mjs +104 -0
  22. package/scripts/migrate-txseq.mjs +147 -0
  23. package/src/index.d.ts +18 -11
  24. package/src/index.js +44 -14
  25. package/src/plugin.js +42 -52
  26. package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
  27. package/srv/blockchain/backends/blockfrost-backend.js +53 -162
  28. package/srv/blockchain/backends/cardano-backend.d.ts +104 -158
  29. package/srv/blockchain/backends/cardano-backend.js +19 -5
  30. package/srv/blockchain/backends/koios-backend.d.ts +126 -60
  31. package/srv/blockchain/backends/koios-backend.js +376 -235
  32. package/srv/blockchain/backends/odatano-backend.d.ts +64 -0
  33. package/srv/blockchain/backends/odatano-backend.js +170 -0
  34. package/srv/blockchain/backends/ogmios-backend.d.ts +162 -94
  35. package/srv/blockchain/backends/ogmios-backend.js +556 -201
  36. package/srv/blockchain/backends/ogmios-frame-guard.d.ts +32 -0
  37. package/srv/blockchain/backends/ogmios-frame-guard.js +142 -0
  38. package/srv/blockchain/cardano-client.d.ts +87 -202
  39. package/srv/blockchain/cardano-client.js +210 -240
  40. package/srv/blockchain/cardano-indexer.d.ts +311 -242
  41. package/srv/blockchain/cardano-indexer.js +1238 -362
  42. package/srv/blockchain/cardano-tx-builder.d.ts +44 -81
  43. package/srv/blockchain/cardano-tx-builder.js +173 -132
  44. package/srv/blockchain/crawler/certificate-backfill.d.ts +67 -0
  45. package/srv/blockchain/crawler/certificate-backfill.js +169 -0
  46. package/srv/blockchain/crawler/crawler.d.ts +139 -54
  47. package/srv/blockchain/crawler/crawler.js +478 -96
  48. package/srv/blockchain/crawler/hooks.d.ts +3 -14
  49. package/srv/blockchain/crawler/index.d.ts +5 -0
  50. package/srv/blockchain/crawler/index.js +35 -7
  51. package/srv/blockchain/crawler/sync-state.d.ts +46 -28
  52. package/srv/blockchain/crawler/sync-state.js +128 -43
  53. package/srv/blockchain/crawler/transaction-backfill.d.ts +52 -0
  54. package/srv/blockchain/crawler/transaction-backfill.js +283 -0
  55. package/srv/blockchain/crawler/utxo-set-import.d.ts +78 -0
  56. package/srv/blockchain/crawler/utxo-set-import.js +363 -0
  57. package/srv/blockchain/ledger-state.d.ts +101 -0
  58. package/srv/blockchain/ledger-state.js +432 -0
  59. package/srv/blockchain/pending-spends.d.ts +28 -0
  60. package/srv/blockchain/pending-spends.js +89 -0
  61. package/srv/blockchain/signing/cose-verifier.d.ts +5 -12
  62. package/srv/blockchain/signing/cose-verifier.js +6 -12
  63. package/srv/blockchain/signing/external-signer.d.ts +16 -113
  64. package/srv/blockchain/signing/external-signer.js +19 -122
  65. package/srv/blockchain/signing/hsm-signer.d.ts +13 -45
  66. package/srv/blockchain/signing/hsm-signer.js +23 -63
  67. package/srv/blockchain/signing/signature-verifier.d.ts +14 -45
  68. package/srv/blockchain/signing/signature-verifier.js +73 -76
  69. package/srv/blockchain/signing/submission-finalizer.d.ts +9 -36
  70. package/srv/blockchain/signing/submission-finalizer.js +16 -49
  71. package/srv/blockchain/stored-chain.d.ts +33 -0
  72. package/srv/blockchain/stored-chain.js +234 -0
  73. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +111 -173
  74. package/srv/blockchain/transaction-building/buildooor-tx.js +649 -326
  75. package/srv/blockchain/transaction-building/caller-datums.d.ts +29 -0
  76. package/srv/blockchain/transaction-building/caller-datums.js +139 -0
  77. package/srv/blockchain/transaction-building/cardano-tx.d.ts +10 -35
  78. package/srv/blockchain/transaction-rows.d.ts +12 -0
  79. package/srv/blockchain/transaction-rows.js +43 -0
  80. package/srv/blockchain/wallet-worker/build-request.d.ts +4 -17
  81. package/srv/blockchain/wallet-worker/build-request.js +18 -23
  82. package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +25 -17
  83. package/srv/blockchain/wallet-worker/confirmation-tracker.js +87 -41
  84. package/srv/blockchain/wallet-worker/index.js +2 -8
  85. package/srv/blockchain/wallet-worker/job-store.d.ts +36 -103
  86. package/srv/blockchain/wallet-worker/job-store.js +0 -0
  87. package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +4 -20
  88. package/srv/blockchain/wallet-worker/lease-heartbeat.js +4 -20
  89. package/srv/blockchain/wallet-worker/signers.d.ts +6 -19
  90. package/srv/blockchain/wallet-worker/signers.js +3 -8
  91. package/srv/blockchain/wallet-worker/wallet-worker.d.ts +15 -71
  92. package/srv/blockchain/wallet-worker/wallet-worker.js +40 -91
  93. package/srv/cardano-agent-service.cds +146 -0
  94. package/srv/cardano-agent-service.d.ts +2 -0
  95. package/srv/cardano-agent-service.js +12 -0
  96. package/srv/cardano-backend-service.cds +52 -0
  97. package/srv/cardano-backend-service.d.ts +2 -0
  98. package/srv/cardano-backend-service.js +244 -0
  99. package/srv/cardano-indexer-service.cds +201 -73
  100. package/srv/cardano-indexer-service.js +280 -11
  101. package/srv/cardano-service.cds +65 -2
  102. package/srv/cardano-service.js +170 -129
  103. package/srv/cardano-sign-service.cds +200 -180
  104. package/srv/cardano-sign-service.js +57 -184
  105. package/srv/cardano-tx-service.cds +439 -370
  106. package/srv/cardano-tx-service.js +231 -190
  107. package/srv/cardano-ui.cds +16 -16
  108. package/srv/cardano-worker-service.js +7 -15
  109. package/srv/cbor/index.d.ts +1 -1
  110. package/srv/cbor/parse.d.ts +27 -0
  111. package/srv/cbor/parse.js +63 -2
  112. package/srv/server.d.ts +28 -86
  113. package/srv/server.js +132 -135
  114. package/srv/utils/agent-grants-config.d.ts +37 -0
  115. package/srv/utils/agent-grants-config.js +138 -0
  116. package/srv/utils/agent-grants.d.ts +262 -0
  117. package/srv/utils/agent-grants.js +922 -0
  118. package/srv/utils/agent-token-auth.d.ts +16 -0
  119. package/srv/utils/agent-token-auth.js +78 -0
  120. package/srv/utils/backend-request-handler.d.ts +2 -16
  121. package/srv/utils/backend-request-handler.js +3 -18
  122. package/srv/utils/collections.d.ts +4 -8
  123. package/srv/utils/collections.js +4 -8
  124. package/srv/utils/const.d.ts +30 -67
  125. package/srv/utils/const.js +32 -72
  126. package/srv/utils/crypto.d.ts +3 -12
  127. package/srv/utils/crypto.js +5 -18
  128. package/srv/utils/db-indexes.d.ts +25 -0
  129. package/srv/utils/db-indexes.js +94 -0
  130. package/srv/utils/db-sanitize.d.ts +27 -0
  131. package/srv/utils/db-sanitize.js +85 -0
  132. package/srv/utils/epoch-slots.d.ts +20 -0
  133. package/srv/utils/epoch-slots.js +43 -0
  134. package/srv/utils/error-codes.d.ts +20 -73
  135. package/srv/utils/error-codes.js +19 -70
  136. package/srv/utils/errors.d.ts +50 -177
  137. package/srv/utils/errors.js +94 -218
  138. package/srv/utils/legacy-service-paths.d.ts +11 -0
  139. package/srv/utils/legacy-service-paths.js +58 -0
  140. package/srv/utils/liveness.d.ts +16 -0
  141. package/srv/utils/liveness.js +40 -0
  142. package/srv/utils/mappers.d.ts +128 -214
  143. package/srv/utils/mappers.js +354 -299
  144. package/srv/utils/network-context.js +2 -11
  145. package/srv/utils/pg-inline-json.d.ts +8 -0
  146. package/srv/utils/pg-inline-json.js +62 -0
  147. package/srv/utils/pg-order-nulls.d.ts +14 -0
  148. package/srv/utils/pg-order-nulls.js +56 -0
  149. package/srv/utils/plutus-placeholders.d.ts +23 -16
  150. package/srv/utils/plutus-placeholders.js +63 -27
  151. package/srv/utils/rate-limiter.d.ts +46 -0
  152. package/srv/utils/rate-limiter.js +116 -0
  153. package/srv/utils/service-events.d.ts +2 -22
  154. package/srv/utils/service-events.js +3 -23
  155. package/srv/utils/signing-helper.d.ts +6 -16
  156. package/srv/utils/signing-helper.js +36 -60
  157. package/srv/utils/tx-build-helper.d.ts +28 -93
  158. package/srv/utils/tx-build-helper.js +75 -124
  159. package/srv/utils/tx-request-parsers.d.ts +101 -28
  160. package/srv/utils/tx-request-parsers.js +410 -43
  161. package/srv/utils/tx-utils.d.ts +4 -23
  162. package/srv/utils/tx-utils.js +12 -41
  163. package/srv/utils/types.d.ts +252 -179
  164. package/srv/utils/types.js +2 -6
  165. package/srv/utils/validators.d.ts +24 -90
  166. package/srv/utils/validators.js +50 -147
@@ -0,0 +1,16 @@
1
+ /**
2
+ * `x-agent-token` transport lane: a token on a service path runs as `agent:<grantId>` with
3
+ * role `agent-grant` (unknown 401, expired 410); other paths fall through to the delegate.
4
+ * Failed attempts are throttled per client address (20 per 15 minutes).
5
+ */
6
+ import { type TransportLane } from '@odatano/cap-auth';
7
+ /** Test seam: pin the service paths instead of reading `cds.services`. `null` resets. */
8
+ export declare function __setAgentServicePathsForTests(paths: string[] | null): void;
9
+ /** Forget throttle state and the path cache (tests). */
10
+ export declare function __resetAgentTokenLaneForTests(): void;
11
+ /** Mount paths of the six services, read from `cds.services` once they are served. */
12
+ export declare function agentServicePaths(): string[];
13
+ /** Exact segment boundary: `/odata/v4/cardano` and below, never `/odata/v4/cardano-evil`. */
14
+ export declare function inAgentLane(path: string, servicePaths?: string[]): boolean;
15
+ export declare const agentTokenLane: TransportLane;
16
+ //# sourceMappingURL=agent-token-auth.d.ts.map
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ /**
3
+ * `x-agent-token` transport lane: a token on a service path runs as `agent:<grantId>` with
4
+ * role `agent-grant` (unknown 401, expired 410); other paths fall through to the delegate.
5
+ * Failed attempts are throttled per client address (20 per 15 minutes).
6
+ */
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.agentTokenLane = void 0;
12
+ exports.__setAgentServicePathsForTests = __setAgentServicePathsForTests;
13
+ exports.__resetAgentTokenLaneForTests = __resetAgentTokenLaneForTests;
14
+ exports.agentServicePaths = agentServicePaths;
15
+ exports.inAgentLane = inAgentLane;
16
+ const cds_1 = __importDefault(require("@sap/cds"));
17
+ const cap_auth_1 = require("@odatano/cap-auth");
18
+ const agent_grants_1 = require("./agent-grants");
19
+ const rate_limiter_1 = require("./rate-limiter");
20
+ const tokenFailures = new rate_limiter_1.RateLimiter({ windowMs: 15 * 60 * 1000, maxRequests: 20, maxKeys: 10_000 });
21
+ let servicePathsCache = null;
22
+ let servicePathsPinned = false;
23
+ /** Test seam: pin the service paths instead of reading `cds.services`. `null` resets. */
24
+ function __setAgentServicePathsForTests(paths) {
25
+ servicePathsCache = paths;
26
+ servicePathsPinned = paths !== null;
27
+ }
28
+ /** Forget throttle state and the path cache (tests). */
29
+ function __resetAgentTokenLaneForTests() {
30
+ tokenFailures.reset();
31
+ servicePathsCache = null;
32
+ servicePathsPinned = false;
33
+ }
34
+ /** Mount paths of the six services, read from `cds.services` once they are served. */
35
+ function agentServicePaths() {
36
+ if (servicePathsPinned && servicePathsCache)
37
+ return servicePathsCache;
38
+ if (servicePathsCache && servicePathsCache.length === agent_grants_1.AGENT_SERVICE_NAMES.length)
39
+ return servicePathsCache;
40
+ const services = cds_1.default.services ?? {};
41
+ const paths = Object.values(services)
42
+ .filter((s) => s && agent_grants_1.AGENT_SERVICE_NAMES.includes(String(s.name)) && typeof s.path === 'string')
43
+ .map((s) => String(s.path).replace(/\/+$/, ''));
44
+ servicePathsCache = paths;
45
+ return paths;
46
+ }
47
+ /** Exact segment boundary: `/odata/v4/cardano` and below, never `/odata/v4/cardano-evil`. */
48
+ function inAgentLane(path, servicePaths = agentServicePaths()) {
49
+ const bare = path.split('?')[0];
50
+ return servicePaths.some((p) => (0, cap_auth_1.inLaneOf)(bare, p));
51
+ }
52
+ function clientKey(req) {
53
+ const ip = req.ip ?? req.socket?.remoteAddress ?? 'unknown';
54
+ return `ip=${String(ip).replace(/:/g, '.')}:agent-token`;
55
+ }
56
+ exports.agentTokenLane = {
57
+ name: 'agent-token',
58
+ match: (req) => typeof req.headers?.[agent_grants_1.AGENT_TOKEN_HEADER] === 'string' && req.headers[agent_grants_1.AGENT_TOKEN_HEADER].length > 0,
59
+ authenticate: async (req, res) => {
60
+ const token = req.headers[agent_grants_1.AGENT_TOKEN_HEADER];
61
+ if (!inAgentLane((0, cap_auth_1.requestPath)(req)))
62
+ return { next: true };
63
+ const key = clientKey(req);
64
+ const locked = tokenFailures.peek(key);
65
+ if (!locked.allowed)
66
+ return (0, cap_auth_1.respondError)(res, 429, 'Too many failed agent token attempts', locked.retryAfterMs);
67
+ const resolution = await (0, agent_grants_1.resolveAgentToken)(token);
68
+ if (!resolution.ok) {
69
+ const failed = tokenFailures.check(key);
70
+ if (!failed.allowed)
71
+ return (0, cap_auth_1.respondError)(res, 429, 'Too many failed agent token attempts', failed.retryAfterMs);
72
+ return (0, cap_auth_1.respondError)(res, resolution.status, resolution.message);
73
+ }
74
+ req.agentGrant = resolution.grant;
75
+ return { user: (0, agent_grants_1.makeAgentUser)(resolution.grant) };
76
+ },
77
+ };
78
+ //# sourceMappingURL=agent-token-auth.js.map
@@ -1,20 +1,6 @@
1
1
  import cds, { Request } from '@sap/cds';
2
- /**
3
- * BackendRequestHandler - Provides standardized handling for backend requests
4
- */
5
- /**
6
- * BackendRequestHandler - Wraps a backend method call with standardized error handling
7
- * @param fn - The async function to execute
8
- * @param backendName - Name of the backend (for error context)
9
- * @param resourceName - Name of the resource being accessed (e.g., "Transaction", "Address")
10
- * @returns {Promise<T>} The result of the backend call or a normalized error
11
- */
2
+ /** Wraps a backend call and normalizes any thrown error to a BackendError subclass. */
12
3
  export declare function handleBackendRequest<T>(fn: () => Promise<T>, backendName: string): Promise<T>;
13
- /**
14
- * General request handler for CardanoService
15
- * @param req - The incoming request
16
- * @param handler - The async function containing business logic
17
- * @returns {Promise<unknown>} The result of the handler or a mapped error response
18
- */
4
+ /** Runs a service handler inside the request transaction and maps errors to OData responses. */
19
5
  export declare function handleRequest(req: Request, handler: (db: cds.Transaction) => Promise<unknown>): Promise<unknown>;
20
6
  //# sourceMappingURL=backend-request-handler.d.ts.map
@@ -9,16 +9,7 @@ const errors_1 = require("./errors");
9
9
  const cds_1 = __importDefault(require("@sap/cds"));
10
10
  const mappers_1 = require("./mappers");
11
11
  const logger = cds_1.default.log('BackendRequestHandler');
12
- /**
13
- * BackendRequestHandler - Provides standardized handling for backend requests
14
- */
15
- /**
16
- * BackendRequestHandler - Wraps a backend method call with standardized error handling
17
- * @param fn - The async function to execute
18
- * @param backendName - Name of the backend (for error context)
19
- * @param resourceName - Name of the resource being accessed (e.g., "Transaction", "Address")
20
- * @returns {Promise<T>} The result of the backend call or a normalized error
21
- */
12
+ /** Wraps a backend call and normalizes any thrown error to a BackendError subclass. */
22
13
  async function handleBackendRequest(fn, backendName) {
23
14
  try {
24
15
  return await fn();
@@ -27,16 +18,10 @@ async function handleBackendRequest(fn, backendName) {
27
18
  throw (0, errors_1.normalizeBackendError)(err, backendName);
28
19
  }
29
20
  }
30
- /**
31
- * General request handler for CardanoService
32
- * @param req - The incoming request
33
- * @param handler - The async function containing business logic
34
- * @returns {Promise<unknown>} The result of the handler or a mapped error response
35
- */
21
+ /** Runs a service handler inside the request transaction and maps errors to OData responses. */
36
22
  async function handleRequest(req, handler) {
37
23
  const context = req.target?.name || req.event;
38
- // cds.tx(req) returns the request's managed transaction — CAP auto-rolls back
39
- // on req.reject()/req.error() (called by mapError). No explicit rollback needed.
24
+ // Managed transaction: CAP rolls back on req.reject()/req.error(), no explicit rollback.
40
25
  const db = cds_1.default.tx(req);
41
26
  try {
42
27
  return await handler(db);
@@ -1,13 +1,9 @@
1
+ /** Small collection helpers shared across the blockchain layer. */
1
2
  /**
2
- * Small collection helpers shared across the blockchain layer.
3
- */
4
- /**
5
- * Split an array into fixed-size chunks. Used to keep CQL IN-lists below DB driver
6
- * bind-variable limits (SQLite caps at 999 on older builds / 32766 on node:sqlite).
7
- * @param arr source array (not mutated)
8
- * @param size chunk size (must be > 0; guarded to avoid an infinite loop)
3
+ * Split an array into fixed-size chunks; keeps CQL IN-lists below driver bind-variable limits
4
+ * (SQLite: 999 on older builds, 32766 on node:sqlite).
9
5
  */
10
6
  export declare function chunk<T>(arr: T[], size: number): T[][];
11
- /** Max bind variables per IN-list — well below every supported driver's cap. */
7
+ /** Max bind variables per IN-list, below every supported driver's cap. */
12
8
  export declare const IN_CHUNK = 500;
13
9
  //# sourceMappingURL=collections.d.ts.map
@@ -1,15 +1,11 @@
1
1
  "use strict";
2
- /**
3
- * Small collection helpers shared across the blockchain layer.
4
- */
2
+ /** Small collection helpers shared across the blockchain layer. */
5
3
  Object.defineProperty(exports, "__esModule", { value: true });
6
4
  exports.IN_CHUNK = void 0;
7
5
  exports.chunk = chunk;
8
6
  /**
9
- * Split an array into fixed-size chunks. Used to keep CQL IN-lists below DB driver
10
- * bind-variable limits (SQLite caps at 999 on older builds / 32766 on node:sqlite).
11
- * @param arr source array (not mutated)
12
- * @param size chunk size (must be > 0; guarded to avoid an infinite loop)
7
+ * Split an array into fixed-size chunks; keeps CQL IN-lists below driver bind-variable limits
8
+ * (SQLite: 999 on older builds, 32766 on node:sqlite).
13
9
  */
14
10
  function chunk(arr, size) {
15
11
  if (size <= 0)
@@ -19,6 +15,6 @@ function chunk(arr, size) {
19
15
  out.push(arr.slice(i, i + size));
20
16
  return out;
21
17
  }
22
- /** Max bind variables per IN-list — well below every supported driver's cap. */
18
+ /** Max bind variables per IN-list, below every supported driver's cap. */
23
19
  exports.IN_CHUNK = 500;
24
20
  //# sourceMappingURL=collections.js.map
@@ -1,6 +1,4 @@
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;
@@ -8,70 +6,50 @@ export declare const CARDANO_DEFAULTS: {
8
6
  MS_PER_SLOT: number;
9
7
  };
10
8
  /**
11
- * Network-specific epoch geometry, anchored at the Shelley transition:
9
+ * Per-network epoch geometry anchored at the Shelley transition:
12
10
  * `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.
11
+ * Preview epochs are 1 day; mainnet/preprod are offset by their Byron era.
12
+ * `securityParam` (k): blocks the node keeps volatile, i.e. how far back ledger state can be acquired.
15
13
  */
16
14
  export declare const EPOCH_CONFIG_BY_NETWORK: {
17
15
  readonly mainnet: {
18
16
  readonly shelleyStartEpoch: 208;
19
17
  readonly shelleyStartSlot: 4492800;
20
18
  readonly slotsPerEpoch: 432000;
19
+ readonly securityParam: 2160;
21
20
  };
22
21
  readonly preprod: {
23
22
  readonly shelleyStartEpoch: 4;
24
23
  readonly shelleyStartSlot: 86400;
25
24
  readonly slotsPerEpoch: 432000;
25
+ readonly securityParam: 2160;
26
26
  };
27
27
  readonly preview: {
28
28
  readonly shelleyStartEpoch: 0;
29
29
  readonly shelleyStartSlot: 0;
30
30
  readonly slotsPerEpoch: 86400;
31
+ readonly securityParam: 432;
31
32
  };
32
33
  };
33
- /**
34
- * Default execution units for Plutus scripts
35
- * Used when dynamic evaluation is not available
36
- */
34
+ /** Default Plutus execution units when dynamic evaluation is not available */
37
35
  export declare const DEFAULT_EXECUTION_UNITS: {
38
- /** Memory units for script execution */
39
36
  mem: number;
40
- /** CPU steps for script execution */
41
37
  cpu: number;
42
38
  };
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
- */
39
+ /** High execution units for the initial build pass, so the fee estimate holds before evaluation */
47
40
  export declare const HIGH_EXECUTION_UNITS: {
48
- /** Memory units - high for evaluation pass */
49
41
  mem: number;
50
- /** CPU steps - high for evaluation pass */
51
42
  cpu: number;
52
43
  };
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
- */
44
+ /** Relative multiplier on evaluator ExUnits; combined with the ABS_* floors below. */
57
45
  export declare const EXECUTION_UNIT_BUFFER = 1.1;
58
46
  /**
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.
47
+ * Absolute ExUnits floor on top of the relative multiplier: covers ScriptContext drift of validators
48
+ * that iterate reference inputs and decode CBOR datums. `max_tx_ex_units` still caps the total.
69
49
  */
70
50
  export declare const ABS_CPU_BUFFER = 200000;
71
51
  export declare const ABS_MEM_BUFFER = 5000;
72
- /**
73
- * Transaction building constants
74
- */
52
+ /** Transaction building constants */
75
53
  /** Collateral amount in lovelace (5 ADA) */
76
54
  export declare const COLLATERAL_LOVELACE = 5000000n;
77
55
  /** Fee buffer in lovelace (1 ADA) */
@@ -90,13 +68,16 @@ export declare const HRP: {
90
68
  stake: RegExp;
91
69
  };
92
70
  };
93
- /**
94
- * Input validation limits to prevent DoS attacks
95
- */
71
+ /** Input validation limits to prevent DoS attacks */
96
72
  /** Maximum JSON string length in bytes (1MB) */
97
73
  export declare const MAX_JSON_SIZE = 1048576;
98
74
  /** Maximum nesting depth for JSON objects/arrays */
99
75
  export declare const MAX_DEPTH = 10;
76
+ /**
77
+ * Nesting depth for PlutusData JSON (redeemers, datums, script params): every constructor takes two
78
+ * levels ({constructor, fields: [...]}), so protocol redeemers go past MAX_DEPTH; size stays capped.
79
+ */
80
+ export declare const PLUTUS_DATA_MAX_DEPTH = 64;
100
81
  /** Maximum number of keys in a JSON object */
101
82
  export declare const MAX_KEYS = 100;
102
83
  /** Maximum number of elements in a JSON array */
@@ -105,12 +86,7 @@ export declare const MAX_ARRAY_LENGTH = 1000;
105
86
  export declare const MAX_STRING_LENGTH = 65536;
106
87
  /** Maximum ech32 string length to prevent DoS */
107
88
  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
- */
89
+ /** Max tx CBOR hex accepted by ParseTransactionCbor: 64 KiB raw, well above mainnet maxTxSize (16 KiB). */
114
90
  export declare const MAX_TX_CBOR_HEX_LENGTH: number;
115
91
  /** Maximum reasonable epoch number */
116
92
  export declare const MAX_EPOCH = 100000;
@@ -129,13 +105,12 @@ export declare const ED25519_KEY_HASH_REGEX: RegExp;
129
105
  /** Minimum lovelace for a change output carrying native assets (2 ADA) */
130
106
  export declare const MIN_CHANGE_LOVELACE = 2000000;
131
107
  /**
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.
108
+ * Shelley genesis parameters per network for Buildooor's GenesisInfos (`TxBuilder.posixToSlot()`)
109
+ * and `slotToPosixSeconds()`. `systemStartPosixMs` is the first Shelley slot's wall-clock time.
135
110
  */
136
111
  export declare const GENESIS_INFOS_BY_NETWORK: {
137
112
  readonly mainnet: {
138
- readonly systemStartPosixMs: 1596491091000;
113
+ readonly systemStartPosixMs: 1596059091000;
139
114
  readonly slotLengthMs: 1000;
140
115
  readonly startSlotNo: 4492800;
141
116
  };
@@ -152,32 +127,20 @@ export declare const GENESIS_INFOS_BY_NETWORK: {
152
127
  };
153
128
  /** Default validity-window start offset: `now - 2 min` to absorb clock skew. */
154
129
  export declare const DEFAULT_VALIDITY_START_OFFSET_MS = 120000;
155
- /** Default validity-window end offset: `now + 1 h` — generous enough for human-latency sign+submit flows. */
130
+ /** Default validity-window end offset: `now + 1 h`, enough for human-latency sign+submit flows. */
156
131
  export declare const DEFAULT_VALIDITY_END_OFFSET_MS: number;
157
132
  /** Max accepted digits in a Posix-ms string (13 digits covers Unix ms timestamps through ~Nov 2286). */
158
133
  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
- */
134
+ /** Generic 64-character hex string (block hashes and other 32-byte identifiers) */
162
135
  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
- */
136
+ /** Generic 56-character hex string: 28-byte hashes (Blake2b-224, payment credential, script hash, pool key hash) */
166
137
  export declare const HEX_56_REGEX: RegExp;
167
- /**
168
- * Transaction hash Regex - 64-character hexadecimal string
169
- */
138
+ /** Transaction hash: 64-character hex string */
170
139
  export declare const TX_HASH_REGEX: RegExp;
171
- /**
172
- * Asset unit Regex - policy ID (56 hex chars) + asset name (0-128 hex chars)
173
- */
140
+ /** Asset unit: policy ID (56 hex) + asset name (0-32 bytes = 0-64 hex, even length; total <= 120 = String(120) key column) */
174
141
  export declare const ASSET_UNIT_REGEX: RegExp;
175
- /**
176
- * Pool ID Regex - bech32 with HRP "pool" and 28 bytes payload
177
- */
142
+ /** Pool ID: bech32 with HRP "pool" and 28-byte payload */
178
143
  export declare const POOL_ID_REGEX: RegExp;
179
- /**
180
- * DRep ID Regex - bech32 with HRP "drep" and 50-60 chars payload
181
- */
144
+ /** DRep ID: bech32 with HRP "drep" and 50-60 chars payload */
182
145
  export declare const DREP_ID_REGEX: RegExp;
183
146
  //# sourceMappingURL=const.d.ts.map
@@ -1,9 +1,7 @@
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.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',
@@ -11,58 +9,35 @@ exports.CARDANO_DEFAULTS = {
11
9
  MS_PER_SLOT: 1000,
12
10
  };
13
11
  /**
14
- * Network-specific epoch geometry, anchored at the Shelley transition:
12
+ * Per-network epoch geometry anchored at the Shelley transition:
15
13
  * `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.
14
+ * Preview epochs are 1 day; mainnet/preprod are offset by their Byron era.
15
+ * `securityParam` (k): blocks the node keeps volatile, i.e. how far back ledger state can be acquired.
18
16
  */
19
17
  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 },
18
+ mainnet: { shelleyStartEpoch: 208, shelleyStartSlot: 4_492_800, slotsPerEpoch: 432_000, securityParam: 2160 },
19
+ preprod: { shelleyStartEpoch: 4, shelleyStartSlot: 86_400, slotsPerEpoch: 432_000, securityParam: 2160 },
20
+ preview: { shelleyStartEpoch: 0, shelleyStartSlot: 0, slotsPerEpoch: 86_400, securityParam: 432 },
23
21
  };
24
- /**
25
- * Default execution units for Plutus scripts
26
- * Used when dynamic evaluation is not available
27
- */
22
+ /** Default Plutus execution units when dynamic evaluation is not available */
28
23
  exports.DEFAULT_EXECUTION_UNITS = {
29
- /** Memory units for script execution */
30
24
  mem: 14_000_000,
31
- /** CPU steps for script execution */
32
25
  cpu: 10_000_000_000,
33
26
  };
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
- */
27
+ /** High execution units for the initial build pass, so the fee estimate holds before evaluation */
38
28
  exports.HIGH_EXECUTION_UNITS = {
39
- /** Memory units - high for evaluation pass */
40
29
  mem: 28_000_000,
41
- /** CPU steps - high for evaluation pass */
42
30
  cpu: 20_000_000_000,
43
31
  };
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
- */
32
+ /** Relative multiplier on evaluator ExUnits; combined with the ABS_* floors below. */
48
33
  exports.EXECUTION_UNIT_BUFFER = 1.1;
49
34
  /**
50
- * Absolute ExUnits floor added on top of the relative multiplier.
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.
35
+ * Absolute ExUnits floor on top of the relative multiplier: covers ScriptContext drift of validators
36
+ * that iterate reference inputs and decode CBOR datums. `max_tx_ex_units` still caps the total.
60
37
  */
61
38
  exports.ABS_CPU_BUFFER = 200_000;
62
39
  exports.ABS_MEM_BUFFER = 5_000;
63
- /**
64
- * Transaction building constants
65
- */
40
+ /** Transaction building constants */
66
41
  /** Collateral amount in lovelace (5 ADA) */
67
42
  exports.COLLATERAL_LOVELACE = 5000000n;
68
43
  /** Fee buffer in lovelace (1 ADA) */
@@ -72,13 +47,16 @@ exports.HRP = {
72
47
  preview: { addr: /^addr_test1[0-9a-z]{50,100}$/, stake: /^stake_test1[0-9a-z]{53,}$/ },
73
48
  preprod: { addr: /^addr_test1[0-9a-z]{50,100}$/, stake: /^stake_test1[0-9a-z]{53,}$/ },
74
49
  };
75
- /**
76
- * Input validation limits to prevent DoS attacks
77
- */
50
+ /** Input validation limits to prevent DoS attacks */
78
51
  /** Maximum JSON string length in bytes (1MB) */
79
52
  exports.MAX_JSON_SIZE = 1_048_576;
80
53
  /** Maximum nesting depth for JSON objects/arrays */
81
54
  exports.MAX_DEPTH = 10;
55
+ /**
56
+ * Nesting depth for PlutusData JSON (redeemers, datums, script params): every constructor takes two
57
+ * levels ({constructor, fields: [...]}), so protocol redeemers go past MAX_DEPTH; size stays capped.
58
+ */
59
+ exports.PLUTUS_DATA_MAX_DEPTH = 64;
82
60
  /** Maximum number of keys in a JSON object */
83
61
  exports.MAX_KEYS = 100;
84
62
  /** Maximum number of elements in a JSON array */
@@ -87,12 +65,7 @@ exports.MAX_ARRAY_LENGTH = 1000;
87
65
  exports.MAX_STRING_LENGTH = 65536;
88
66
  /** Maximum ech32 string length to prevent DoS */
89
67
  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
- */
68
+ /** Max tx CBOR hex accepted by ParseTransactionCbor: 64 KiB raw, well above mainnet maxTxSize (16 KiB). */
96
69
  exports.MAX_TX_CBOR_HEX_LENGTH = 65536 * 2;
97
70
  /** Maximum reasonable epoch number */
98
71
  exports.MAX_EPOCH = 100_000;
@@ -111,43 +84,30 @@ exports.ED25519_KEY_HASH_REGEX = /^[a-f0-9]{56}$/i;
111
84
  /** Minimum lovelace for a change output carrying native assets (2 ADA) */
112
85
  exports.MIN_CHANGE_LOVELACE = 2_000_000;
113
86
  /**
114
- * Shelley-era genesis parameters per network, used to construct Buildooor's
115
- * GenesisInfos so `TxBuilder.posixToSlot()` can convert validity-window
116
- * Posix ms into ledger slots. `slotLengthMs` is 1000 ms on all current networks.
87
+ * Shelley genesis parameters per network for Buildooor's GenesisInfos (`TxBuilder.posixToSlot()`)
88
+ * and `slotToPosixSeconds()`. `systemStartPosixMs` is the first Shelley slot's wall-clock time.
117
89
  */
118
90
  exports.GENESIS_INFOS_BY_NETWORK = {
119
- mainnet: { systemStartPosixMs: 1596491091000, slotLengthMs: 1000, startSlotNo: 4492800 },
91
+ mainnet: { systemStartPosixMs: 1596059091000, slotLengthMs: 1000, startSlotNo: 4492800 }, // 2020-07-29T21:44:51Z
120
92
  preprod: { systemStartPosixMs: 1655683200000, slotLengthMs: 1000, startSlotNo: 0 },
121
93
  preview: { systemStartPosixMs: 1666656000000, slotLengthMs: 1000, startSlotNo: 0 },
122
94
  };
123
95
  /** Default validity-window start offset: `now - 2 min` to absorb clock skew. */
124
96
  exports.DEFAULT_VALIDITY_START_OFFSET_MS = 120_000;
125
- /** Default validity-window end offset: `now + 1 h` — generous enough for human-latency sign+submit flows. */
97
+ /** Default validity-window end offset: `now + 1 h`, enough for human-latency sign+submit flows. */
126
98
  exports.DEFAULT_VALIDITY_END_OFFSET_MS = 60 * 60 * 1000;
127
99
  /** Max accepted digits in a Posix-ms string (13 digits covers Unix ms timestamps through ~Nov 2286). */
128
100
  exports.MAX_POSIX_MS_DIGITS = 13;
129
- /**
130
- * Generic 64-character hex string (used for block hashes and other 32-byte hex identifiers)
131
- */
101
+ /** Generic 64-character hex string (block hashes and other 32-byte identifiers) */
132
102
  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
- */
103
+ /** Generic 56-character hex string: 28-byte hashes (Blake2b-224, payment credential, script hash, pool key hash) */
136
104
  exports.HEX_56_REGEX = /^[a-f0-9]{56}$/;
137
- /**
138
- * Transaction hash Regex - 64-character hexadecimal string
139
- */
105
+ /** Transaction hash: 64-character hex string */
140
106
  exports.TX_HASH_REGEX = /^[a-f0-9]{64}$/;
141
- /**
142
- * Asset unit Regex - policy ID (56 hex chars) + asset name (0-128 hex chars)
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
- */
107
+ /** Asset unit: policy ID (56 hex) + asset name (0-32 bytes = 0-64 hex, even length; total <= 120 = String(120) key column) */
108
+ exports.ASSET_UNIT_REGEX = /^[a-f0-9]{56}([a-f0-9]{2}){0,32}$/;
109
+ /** Pool ID: bech32 with HRP "pool" and 28-byte payload */
148
110
  exports.POOL_ID_REGEX = /^pool1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{51}$/;
149
- /**
150
- * DRep ID Regex - bech32 with HRP "drep" and 50-60 chars payload
151
- */
111
+ /** DRep ID: bech32 with HRP "drep" and 50-60 chars payload */
152
112
  exports.DREP_ID_REGEX = /^drep1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{50,60}$/;
153
113
  //# sourceMappingURL=const.js.map
@@ -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
@@ -11,20 +11,13 @@ 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
13
  /**
14
- * AES-256-GCM utilities for secrets at rest (v2.0 wallet worker).
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.
14
+ * AES-256-GCM for secrets at rest (wallet worker signing keys), format `iv:authTag:ciphertext` in base64.
15
+ * Key derived from ENCRYPTION_KEY; production refuses to start without it.
20
16
  */
21
17
  const ALGORITHM = 'aes-256-gcm';
22
18
  const IV_LENGTH = 12; // 96 bits, recommended for GCM
23
19
  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
- */
20
+ /** 32-byte key from ENCRYPTION_KEY; development falls back to a process-scoped key. */
28
21
  function getEncryptionKey() {
29
22
  const envKey = process.env.ENCRYPTION_KEY;
30
23
  if (envKey) {
@@ -37,10 +30,7 @@ function getEncryptionKey() {
37
30
  const fallback = `odatano-core-${process.pid}-${node_os_1.default.hostname()}`;
38
31
  return node_crypto_1.default.createHash('sha256').update(fallback).digest();
39
32
  }
40
- /**
41
- * Encrypt plaintext with AES-256-GCM.
42
- * Returns the combined format `base64(iv):base64(authTag):base64(ciphertext)`.
43
- */
33
+ /** Encrypts to `base64(iv):base64(authTag):base64(ciphertext)`. */
44
34
  function encrypt(plaintext, key) {
45
35
  const iv = node_crypto_1.default.randomBytes(IV_LENGTH);
46
36
  const cipher = node_crypto_1.default.createCipheriv(ALGORITHM, key, iv, { authTagLength: AUTH_TAG_LENGTH });
@@ -48,10 +38,7 @@ function encrypt(plaintext, key) {
48
38
  const authTag = cipher.getAuthTag();
49
39
  return `${iv.toString('base64')}:${authTag.toString('base64')}:${encrypted.toString('base64')}`;
50
40
  }
51
- /**
52
- * Decrypt a combined `iv:authTag:ciphertext` string back to plaintext.
53
- * Throws on authentication failure (tampered ciphertext or wrong key).
54
- */
41
+ /** Decrypts a combined `iv:authTag:ciphertext` string; throws on auth-tag mismatch. */
55
42
  function decrypt(combined, key) {
56
43
  const parts = combined.split(':');
57
44
  if (parts.length !== 3) {
@@ -0,0 +1,25 @@
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
+ /** The statement for one entry; exported so tests pin the shape. */
14
+ export declare function indexStatement(spec: IndexSpec, kind?: string): string;
15
+ /** Anything that runs a plain SQL string: the primary db service. */
16
+ export type SqlRunner = {
17
+ run: (sql: string) => Promise<unknown>;
18
+ kind?: string;
19
+ };
20
+ /** Creates every missing index; a failing statement is logged and skipped, the others still run. */
21
+ export declare function ensureDbIndexes(runner?: SqlRunner | undefined): Promise<{
22
+ ensured: string[];
23
+ failed: string[];
24
+ }>;
25
+ //# sourceMappingURL=db-indexes.d.ts.map