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

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
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SigningStatus = exports.ExternalSignerType = void 0;
4
- /**
5
- * Supported external signer types
6
- */
4
+ /** Supported external signer types */
7
5
  var ExternalSignerType;
8
6
  (function (ExternalSignerType) {
9
7
  /** Cardano CLI - Reference implementation for signing */
@@ -17,9 +15,7 @@ var ExternalSignerType;
17
15
  /** Hardware Security Module (server-side PKCS#11) */
18
16
  ExternalSignerType["HSM"] = "hsm";
19
17
  })(ExternalSignerType || (exports.ExternalSignerType = ExternalSignerType = {}));
20
- /**
21
- * Signing request status
22
- */
18
+ /** Signing request status */
23
19
  var SigningStatus;
24
20
  (function (SigningStatus) {
25
21
  /** Request created, awaiting signing */
@@ -1,115 +1,54 @@
1
- /**
2
- * Result of JSON validation with limits
3
- */
1
+ /** Result of JSON validation with limits */
4
2
  interface JsonValidationResult {
5
3
  valid: boolean;
6
4
  error?: string;
7
5
  parsed?: unknown;
8
6
  }
9
- /**
10
- * Validate JSON string with size and complexity limits to prevent DoS
11
- * @param jsonString - The JSON string to validate
12
- * @param fieldName - Name of the field (for error messages)
13
- * @returns JsonValidationResult with parsed value or error message
14
- */
15
- export declare function validateJsonWithLimits(jsonString: string, fieldName: string): JsonValidationResult;
16
- /**
17
- * Transaction hash: 64-character hexadecimal string
18
- * @param s - The raw value to validate against transaction hash format
19
- * @returns { boolean } true if s is a valid transaction hash false otherwise
20
- */
7
+ /** Parse a JSON string under size and complexity limits (DoS prevention); `fieldName` is for messages. */
8
+ export declare function validateJsonWithLimits(jsonString: string, fieldName: string, maxDepth?: number): JsonValidationResult;
9
+ /** PlutusData JSON (redeemer, datum, script params): the same limits with PLUTUS_DATA_MAX_DEPTH. */
10
+ export declare function validatePlutusJson(jsonString: string, fieldName: string): JsonValidationResult;
11
+ /** Request fields that carry PlutusData JSON. */
12
+ export declare const PLUTUS_JSON_FIELDS: ReadonlySet<string>;
13
+ /** Transaction hash: 64-character hex string */
21
14
  export declare function isTxHash(s: unknown): s is string;
22
- /**
23
- * Asset unit: concatenation of policy ID (56 hex chars) + asset name (0-128 hex chars)
24
- * @param s - The raw value to validate against asset unit format
25
- * @returns { boolean } true if v is a valid asset unit false otherwise
26
- */
15
+ /** Asset unit: policy ID (56 hex chars) + asset name (0-64 hex chars, even length) */
27
16
  export declare function isAssetUnit(s: unknown): s is string;
28
- /**
29
- * Block hash: 64-character hexadecimal string
30
- * @param s - The raw value to validate against block hash format
31
- * @returns { boolean } true if s is a valid block hash false otherwise
32
- */
17
+ /** Block hash: 64-character hex string */
33
18
  export declare function isBlockHash(s: unknown): s is string;
34
- /**
35
- * Payment credential: 28-byte hash (key hash or script hash) as 56-char lowercase hex.
36
- * Used for credential-based UTxO queries (Indigo CDPs, Liqwid positions, etc.).
37
- * @param s - The raw value to validate against credential format
38
- * @returns { boolean } true if s is a valid 56-char lowercase hex string
39
- */
19
+ /** Payment credential: 28-byte key or script hash as 56-char lowercase hex (credential-keyed UTxO queries). */
40
20
  export declare function isValidCredential(s: unknown): s is string;
41
- /**
42
- * Pool ID: must be bech32-decodable, HRP=pool, payload length 28 bytes.
43
- * @param poolIdRaw - The raw value to validate against pool ID format
44
- * @returns { boolean } true if valid pool ID false otherwise
45
- */
21
+ /** Pool ID: bech32 with HRP "pool" and a 28-byte payload. */
46
22
  export declare function isValidPoolId(poolIdRaw: unknown): poolIdRaw is string;
47
- /**
48
- * DRep ID: must be bech32-decodable, HRP=drep.
49
- * @param drepRaw - The raw value to validate against drep ID format
50
- * @returns { boolean } true if valid drep ID false otherwise
51
- */
23
+ /** DRep ID: bech32 with HRP "drep" and a 29-byte payload. */
52
24
  export declare function isValidDrepId(drepRaw: unknown): drepRaw is string;
53
- /**
54
- * Validate Bech32 address: must be bech32-decodable, HRP based on network config.
55
- * @param addrRaw - The raw value to validate against bech32 address format
56
- * @returns { boolean } true if valid bech32 address false otherwise
57
- */
25
+ /** Bech32 address with the HRP of the active network; false before the app context is ready. */
58
26
  export declare function isValidBech32Address(addrRaw: unknown): addrRaw is string;
59
- /**
60
- * Validate Bech32 stake address: must be bech32-decodable, HRP based on network config.
61
- * @param stakeRaw - The raw value to validate against stake address format
62
- * @returns { boolean } true if valid bech32 stake address false otherwise
63
- */
27
+ /** Bech32 stake address with the HRP of the active network; false before the app context is ready. */
64
28
  export declare function isValidBech32StakeAddress(stakeRaw: unknown): stakeRaw is string;
65
- /**
66
- * Epoch number: non-negative integer within reasonable bounds
67
- * @param s - The parameter value to validate as epoch number
68
- * @returns { boolean } true if s is a valid epoch number false otherwise
69
- */
29
+ /** Epoch number: non-negative integer up to MAX_EPOCH */
70
30
  export declare function isEpochNumber(s: unknown): s is number;
71
- /**
72
- * Validate CBOR string: must be a non-empty even-length hexadecimal string
73
- * @param cborRaw - The raw value to validate against CBOR format
74
- * @returns { boolean } true if valid CBOR false otherwise
75
- */
31
+ /** CBOR hex: non-empty, even-length hex string */
76
32
  export declare function isValidCbor(cborRaw: unknown): cborRaw is string;
77
- /**
78
- * Validate a transaction CBOR hex string for the ParseTransactionCbor action.
79
- * Combines `isValidCbor` with a hard length limit to block memory-exhaustion
80
- * attacks on the server-side CBOR parser.
81
- * @param cborRaw - The raw value to validate
82
- * @returns { boolean } true if valid hex AND within MAX_TX_CBOR_HEX_LENGTH
83
- */
33
+ /** `isValidCbor` plus the MAX_TX_CBOR_HEX_LENGTH cap (ParseTransactionCbor memory bound). */
84
34
  export declare function isValidTxCborHex(cborRaw: unknown): cborRaw is string;
85
35
  /**
86
- * Extract the payment credential from a Shelley bech32 address.
87
- * Returns the 28-byte credential hash (hex) plus whether it is a SCRIPT
88
- * credential (address type bit 0 of the header high nibble), or null when the
89
- * address cannot be decoded / carries no payment part (stake addresses).
36
+ * Payment credential of a Shelley bech32 address: 28-byte hash (hex) plus whether it is a script
37
+ * credential (bit 0 of the header's high nibble); null for undecodable or stake addresses.
90
38
  */
91
39
  export declare function extractPaymentCredential(address: string): {
92
40
  hash: string;
93
41
  isScript: boolean;
94
42
  } | null;
95
- /**
96
- * Validate an array of Ed25519 key hashes (hex, 28 bytes / 56 hex chars each).
97
- * @param signers - The parsed JSON array to validate
98
- * @returns validated string array
99
- * @throws Error if any signer is invalid
100
- */
43
+ /** Validate an array of Ed25519 key hashes (56 hex chars each); throws on any invalid entry. */
101
44
  export declare function validateRequiredSigners(signers: unknown): string[];
102
- /**
103
- * Validation error details for transaction input validation
104
- */
45
+ /** Validation error details for transaction input validation */
105
46
  export interface ValidationError {
106
47
  type: 'missing' | 'invalid';
107
48
  field: string;
108
49
  message: string;
109
50
  }
110
- /**
111
- * Transaction input fields for validation
112
- */
51
+ /** Transaction input fields for validation */
113
52
  export interface TransactionInputs {
114
53
  senderAddress?: string;
115
54
  recipientAddress?: string;
@@ -134,12 +73,7 @@ export interface TransactionInputs {
134
73
  validityStartMs?: string;
135
74
  validityEndMs?: string;
136
75
  }
137
- /**
138
- * Validate transaction build inputs and return validation errors if any
139
- * @param inputs - Transaction input fields to validate
140
- * @param requiredFields - List of required field names
141
- * @returns Array of validation errors, empty if all valid
142
- */
76
+ /** Validate transaction build inputs; returns the validation errors (empty when all valid). */
143
77
  export declare function validateTransactionInputs(inputs: TransactionInputs, requiredFields: (keyof TransactionInputs)[]): ValidationError[];
144
78
  export {};
145
79
  //# sourceMappingURL=validators.d.ts.map
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PLUTUS_JSON_FIELDS = void 0;
3
4
  exports.validateJsonWithLimits = validateJsonWithLimits;
5
+ exports.validatePlutusJson = validatePlutusJson;
4
6
  exports.isTxHash = isTxHash;
5
7
  exports.isAssetUnit = isAssetUnit;
6
8
  exports.isBlockHash = isBlockHash;
@@ -17,27 +19,16 @@ exports.validateRequiredSigners = validateRequiredSigners;
17
19
  exports.validateTransactionInputs = validateTransactionInputs;
18
20
  const bech32_1 = require("bech32");
19
21
  const const_1 = require("./const");
20
- // Read the active network from a tiny leaf module rather than from `../server`:
21
- // importing server here would pull the whole server → indexer graph (which
22
- // accesses cds.ql at module load) into every consumer of a validator.
22
+ // Leaf module, not `../server`: importing server would pull the whole server/indexer graph in here.
23
23
  const network_context_1 = require("./network-context");
24
- /**
25
- * Safely trim a string value
26
- * @param s - The value to trim
27
- * @returns { string | null } trimmed string or null if input is not a string or empty after trim
28
- */
24
+ /** Trimmed string, or null when not a string or empty after trim. */
29
25
  function safeTrimString(s) {
30
26
  if (typeof s !== "string")
31
27
  return null;
32
28
  const t = s.trim();
33
29
  return t.length > 0 ? t : null;
34
30
  }
35
- /**
36
- * Strict bech32 decode with HRP allowlist.
37
- * @param value - bech32 encoded string
38
- * @param allowedHrp - list of allowed HRP prefixes
39
- * @returns { prefix: string; words: number[] } decoded bech32 parts or null if invalid
40
- */
31
+ /** Strict bech32 decode with HRP allowlist; null when invalid. */
41
32
  function tryDecodeBech32WithHrp(value, allowedHrp) {
42
33
  try {
43
34
  const decoded = bech32_1.bech32.decode(value, const_1.BECH32_MAX_LENGTH);
@@ -50,27 +41,16 @@ function tryDecodeBech32WithHrp(value, allowedHrp) {
50
41
  return null;
51
42
  }
52
43
  }
53
- /**
54
- * Convert bech32 words to byte length
55
- * @param words - bech32 decoded words
56
- * @returns { number } byte length of decoded words
57
- */
44
+ /** Byte length of decoded bech32 words (fromWords validates the word range). */
58
45
  function wordsToBytesLen(words) {
59
- // bech32.fromWords validates word range and converts 5-bit words -> bytes
60
46
  return Buffer.from(bech32_1.bech32.fromWords(words)).length;
61
47
  }
62
- /**
63
- * Validate JSON string with size and complexity limits to prevent DoS
64
- * @param jsonString - The JSON string to validate
65
- * @param fieldName - Name of the field (for error messages)
66
- * @returns JsonValidationResult with parsed value or error message
67
- */
68
- function validateJsonWithLimits(jsonString, fieldName) {
69
- // Check size limit first (before parsing)
48
+ /** Parse a JSON string under size and complexity limits (DoS prevention); `fieldName` is for messages. */
49
+ function validateJsonWithLimits(jsonString, fieldName, maxDepth = const_1.MAX_DEPTH) {
50
+ // Size limit before parsing
70
51
  if (jsonString.length > const_1.MAX_JSON_SIZE) {
71
52
  return { valid: false, error: `${fieldName} exceeds maximum size of ${const_1.MAX_JSON_SIZE} bytes` };
72
53
  }
73
- // Parse JSON
74
54
  let parsed;
75
55
  try {
76
56
  parsed = JSON.parse(jsonString);
@@ -78,105 +58,79 @@ function validateJsonWithLimits(jsonString, fieldName) {
78
58
  catch {
79
59
  return { valid: false, error: `Invalid JSON in ${fieldName}` };
80
60
  }
81
- // Validate complexity recursively
82
- const complexityError = checkJsonComplexity(parsed, 0);
61
+ const complexityError = checkJsonComplexity(parsed, 0, maxDepth);
83
62
  if (complexityError) {
84
63
  return { valid: false, error: `${fieldName}: ${complexityError}` };
85
64
  }
86
65
  return { valid: true, parsed };
87
66
  }
88
- /**
89
- * Recursively check JSON complexity (depth, keys, array length, string length)
90
- * @param value - The parsed JSON value
91
- * @param depth - Current nesting depth
92
- * @returns Error message if limits exceeded, null otherwise
93
- */
94
- function checkJsonComplexity(value, depth) {
95
- // Check depth limit
96
- if (depth > const_1.MAX_DEPTH) {
97
- return `Maximum nesting depth of ${const_1.MAX_DEPTH} exceeded`;
67
+ /** PlutusData JSON (redeemer, datum, script params): the same limits with PLUTUS_DATA_MAX_DEPTH. */
68
+ function validatePlutusJson(jsonString, fieldName) {
69
+ return validateJsonWithLimits(jsonString, fieldName, const_1.PLUTUS_DATA_MAX_DEPTH);
70
+ }
71
+ /** Request fields that carry PlutusData JSON. */
72
+ exports.PLUTUS_JSON_FIELDS = new Set([
73
+ 'redeemerJson', 'datumJson', 'inlineDatumJson', 'outputDatumJson', 'mintRedeemerJson', 'scriptParamsJson',
74
+ ]);
75
+ /** Recursive complexity check (depth, keys, array length, string length); error message or null. */
76
+ function checkJsonComplexity(value, depth, maxDepth) {
77
+ if (depth > maxDepth) {
78
+ return `Maximum nesting depth of ${maxDepth} exceeded`;
98
79
  }
99
80
  if (value === null || typeof value !== 'object') {
100
- // Check string length for primitive strings
101
81
  if (typeof value === 'string' && value.length > const_1.MAX_STRING_LENGTH) {
102
82
  return `String value exceeds maximum length of ${const_1.MAX_STRING_LENGTH}`;
103
83
  }
104
84
  return null;
105
85
  }
106
86
  if (Array.isArray(value)) {
107
- // Check array length
108
87
  if (value.length > const_1.MAX_ARRAY_LENGTH) {
109
88
  return `Array exceeds maximum length of ${const_1.MAX_ARRAY_LENGTH}`;
110
89
  }
111
- // Recursively check array elements
112
90
  for (const item of value) {
113
- const error = checkJsonComplexity(item, depth + 1);
91
+ const error = checkJsonComplexity(item, depth + 1, maxDepth);
114
92
  if (error)
115
93
  return error;
116
94
  }
117
95
  }
118
96
  else {
119
- // Check object key count
120
97
  const keys = Object.keys(value);
121
98
  if (keys.length > const_1.MAX_KEYS) {
122
99
  return `Object exceeds maximum key count of ${const_1.MAX_KEYS}`;
123
100
  }
124
- // Recursively check object values
125
101
  for (const key of keys) {
126
- const error = checkJsonComplexity(value[key], depth + 1);
102
+ const error = checkJsonComplexity(value[key], depth + 1, maxDepth);
127
103
  if (error)
128
104
  return error;
129
105
  }
130
106
  }
131
107
  return null;
132
108
  }
133
- /**
134
- * Transaction hash: 64-character hexadecimal string
135
- * @param s - The raw value to validate against transaction hash format
136
- * @returns { boolean } true if s is a valid transaction hash false otherwise
137
- */
109
+ /** Transaction hash: 64-character hex string */
138
110
  function isTxHash(s) {
139
111
  return typeof s === "string" && const_1.TX_HASH_REGEX.test(s);
140
112
  }
141
- /**
142
- * Asset unit: concatenation of policy ID (56 hex chars) + asset name (0-128 hex chars)
143
- * @param s - The raw value to validate against asset unit format
144
- * @returns { boolean } true if v is a valid asset unit false otherwise
145
- */
113
+ /** Asset unit: policy ID (56 hex chars) + asset name (0-64 hex chars, even length) */
146
114
  function isAssetUnit(s) {
147
115
  if (typeof s !== "string")
148
116
  return false;
149
117
  const t = s.trim();
150
- // Regex ensures: 56-192 hex chars, even length, valid hex
151
118
  return const_1.ASSET_UNIT_REGEX.test(t);
152
119
  }
153
- /**
154
- * Block hash: 64-character hexadecimal string
155
- * @param s - The raw value to validate against block hash format
156
- * @returns { boolean } true if s is a valid block hash false otherwise
157
- */
120
+ /** Block hash: 64-character hex string */
158
121
  function isBlockHash(s) {
159
122
  return typeof s === "string" && const_1.HEX_64_REGEX.test(s);
160
123
  }
161
- /**
162
- * Payment credential: 28-byte hash (key hash or script hash) as 56-char lowercase hex.
163
- * Used for credential-based UTxO queries (Indigo CDPs, Liqwid positions, etc.).
164
- * @param s - The raw value to validate against credential format
165
- * @returns { boolean } true if s is a valid 56-char lowercase hex string
166
- */
124
+ /** Payment credential: 28-byte key or script hash as 56-char lowercase hex (credential-keyed UTxO queries). */
167
125
  function isValidCredential(s) {
168
126
  return typeof s === "string" && const_1.HEX_56_REGEX.test(s);
169
127
  }
170
- /**
171
- * Pool ID: must be bech32-decodable, HRP=pool, payload length 28 bytes.
172
- * @param poolIdRaw - The raw value to validate against pool ID format
173
- * @returns { boolean } true if valid pool ID false otherwise
174
- */
128
+ /** Pool ID: bech32 with HRP "pool" and a 28-byte payload. */
175
129
  function isValidPoolId(poolIdRaw) {
176
130
  const poolId = safeTrimString(poolIdRaw);
177
131
  if (!poolId)
178
132
  return false;
179
- // optional: cheap prefilter (keeps performance high)
133
+ // cheap prefilter
180
134
  if (!const_1.POOL_ID_REGEX.test(poolId))
181
135
  return false;
182
136
  const decoded = tryDecodeBech32WithHrp(poolId, ["pool"]);
@@ -184,16 +138,12 @@ function isValidPoolId(poolIdRaw) {
184
138
  return wordsToBytesLen(decoded.words) === const_1.POOL_ID_BYTES;
185
139
  return false;
186
140
  }
187
- /**
188
- * DRep ID: must be bech32-decodable, HRP=drep.
189
- * @param drepRaw - The raw value to validate against drep ID format
190
- * @returns { boolean } true if valid drep ID false otherwise
191
- */
141
+ /** DRep ID: bech32 with HRP "drep" and a 29-byte payload. */
192
142
  function isValidDrepId(drepRaw) {
193
143
  const drepId = safeTrimString(drepRaw);
194
144
  if (!drepId)
195
145
  return false;
196
- // optional cheap prefilter
146
+ // cheap prefilter
197
147
  if (!const_1.DREP_ID_REGEX.test(drepId))
198
148
  return false;
199
149
  const decoded = tryDecodeBech32WithHrp(drepId, ["drep"]);
@@ -201,49 +151,36 @@ function isValidDrepId(drepRaw) {
201
151
  return wordsToBytesLen(decoded.words) === const_1.DREP_ID_BYTES;
202
152
  return false;
203
153
  }
204
- /**
205
- * Validate Bech32 address: must be bech32-decodable, HRP based on network config.
206
- * @param addrRaw - The raw value to validate against bech32 address format
207
- * @returns { boolean } true if valid bech32 address false otherwise
208
- */
154
+ /** Bech32 address with the HRP of the active network; false before the app context is ready. */
209
155
  function isValidBech32Address(addrRaw) {
210
156
  const addr = safeTrimString(addrRaw);
211
157
  if (!addr)
212
158
  return false;
213
- // get the active network to check the right HRP. If the app context isn't
214
- // ready yet (e.g., a backend init failure left it uninitialized) the network
215
- // is null — return false so the handler responds with a clean 400 "Invalid
216
- // bech32 address format" instead of leaking an init error to the client. The
217
- // actual init failure is surfaced via stderr in server.ts.
159
+ // No network yet (app context not initialized): a clean 400 instead of a leaked init error
218
160
  const network = (0, network_context_1.getActiveNetwork)();
219
161
  if (!network)
220
162
  return false;
221
- // prefilter from config to make sure it is the right network
163
+ // network HRP prefilter
222
164
  if (!const_1.HRP[network].addr.test(addr))
223
165
  return false;
224
166
  const allowed = ["addr", "addr_test"];
225
167
  const decoded = tryDecodeBech32WithHrp(addr, allowed);
226
168
  if (decoded) {
227
- // Cardano addresses: 29 bytes (enterprise/reward) to 57 bytes (base address)
169
+ // 29 bytes (enterprise/reward) to 57 bytes (base address)
228
170
  const len = wordsToBytesLen(decoded.words);
229
171
  return len >= 29 && len <= 57;
230
172
  }
231
173
  return false;
232
174
  }
233
- /**
234
- * Validate Bech32 stake address: must be bech32-decodable, HRP based on network config.
235
- * @param stakeRaw - The raw value to validate against stake address format
236
- * @returns { boolean } true if valid bech32 stake address false otherwise
237
- */
175
+ /** Bech32 stake address with the HRP of the active network; false before the app context is ready. */
238
176
  function isValidBech32StakeAddress(stakeRaw) {
239
177
  const stake = safeTrimString(stakeRaw);
240
178
  if (!stake)
241
179
  return false;
242
- // Defensive against unset app context — same rationale as isValidBech32Address.
243
180
  const network = (0, network_context_1.getActiveNetwork)();
244
181
  if (!network)
245
182
  return false;
246
- // prefilter from config to make sure it is the right network
183
+ // network HRP prefilter
247
184
  if (!const_1.HRP[network].stake.test(stake))
248
185
  return false;
249
186
  const allowed = ["stake", "stake_test"];
@@ -253,43 +190,26 @@ function isValidBech32StakeAddress(stakeRaw) {
253
190
  const len = wordsToBytesLen(decoded.words);
254
191
  return len >= 1 && len <= 64;
255
192
  }
256
- /**
257
- * Epoch number: non-negative integer within reasonable bounds
258
- * @param s - The parameter value to validate as epoch number
259
- * @returns { boolean } true if s is a valid epoch number false otherwise
260
- */
193
+ /** Epoch number: non-negative integer up to MAX_EPOCH */
261
194
  function isEpochNumber(s) {
262
195
  return typeof s === "number" && s >= 0 && s <= const_1.MAX_EPOCH && Number.isInteger(s);
263
196
  }
264
- /**
265
- * Validate CBOR string: must be a non-empty even-length hexadecimal string
266
- * @param cborRaw - The raw value to validate against CBOR format
267
- * @returns { boolean } true if valid CBOR false otherwise
268
- */
197
+ /** CBOR hex: non-empty, even-length hex string */
269
198
  function isValidCbor(cborRaw) {
270
199
  const cbor = safeTrimString(cborRaw);
271
200
  if (!cbor)
272
201
  return false;
273
- // basic validation: must be even-length hex string
274
202
  return /^[a-f0-9]+$/i.test(cbor) && cbor.length % 2 === 0;
275
203
  }
276
- /**
277
- * Validate a transaction CBOR hex string for the ParseTransactionCbor action.
278
- * Combines `isValidCbor` with a hard length limit to block memory-exhaustion
279
- * attacks on the server-side CBOR parser.
280
- * @param cborRaw - The raw value to validate
281
- * @returns { boolean } true if valid hex AND within MAX_TX_CBOR_HEX_LENGTH
282
- */
204
+ /** `isValidCbor` plus the MAX_TX_CBOR_HEX_LENGTH cap (ParseTransactionCbor memory bound). */
283
205
  function isValidTxCborHex(cborRaw) {
284
206
  if (!isValidCbor(cborRaw))
285
207
  return false;
286
208
  return cborRaw.trim().length <= const_1.MAX_TX_CBOR_HEX_LENGTH;
287
209
  }
288
210
  /**
289
- * Extract the payment credential from a Shelley bech32 address.
290
- * Returns the 28-byte credential hash (hex) plus whether it is a SCRIPT
291
- * credential (address type bit 0 of the header high nibble), or null when the
292
- * address cannot be decoded / carries no payment part (stake addresses).
211
+ * Payment credential of a Shelley bech32 address: 28-byte hash (hex) plus whether it is a script
212
+ * credential (bit 0 of the header's high nibble); null for undecodable or stake addresses.
293
213
  */
294
214
  function extractPaymentCredential(address) {
295
215
  try {
@@ -311,12 +231,7 @@ function extractPaymentCredential(address) {
311
231
  return null;
312
232
  }
313
233
  }
314
- /**
315
- * Validate an array of Ed25519 key hashes (hex, 28 bytes / 56 hex chars each).
316
- * @param signers - The parsed JSON array to validate
317
- * @returns validated string array
318
- * @throws Error if any signer is invalid
319
- */
234
+ /** Validate an array of Ed25519 key hashes (56 hex chars each); throws on any invalid entry. */
320
235
  function validateRequiredSigners(signers) {
321
236
  if (!Array.isArray(signers)) {
322
237
  throw new Error('requiredSignersJson must be a JSON array');
@@ -328,15 +243,9 @@ function validateRequiredSigners(signers) {
328
243
  }
329
244
  return signers;
330
245
  }
331
- /**
332
- * Validate transaction build inputs and return validation errors if any
333
- * @param inputs - Transaction input fields to validate
334
- * @param requiredFields - List of required field names
335
- * @returns Array of validation errors, empty if all valid
336
- */
246
+ /** Validate transaction build inputs; returns the validation errors (empty when all valid). */
337
247
  function validateTransactionInputs(inputs, requiredFields) {
338
248
  const errors = [];
339
- // Check required fields
340
249
  for (const field of requiredFields) {
341
250
  if (inputs[field] === undefined || inputs[field] === null || inputs[field] === '') {
342
251
  errors.push({
@@ -346,10 +255,8 @@ function validateTransactionInputs(inputs, requiredFields) {
346
255
  });
347
256
  }
348
257
  }
349
- // If required fields are missing, return early
350
258
  if (errors.length > 0)
351
259
  return errors;
352
- // Validate address formats
353
260
  if (inputs.senderAddress && !isValidBech32Address(inputs.senderAddress)) {
354
261
  errors.push({
355
262
  type: 'invalid',
@@ -371,7 +278,7 @@ function validateTransactionInputs(inputs, requiredFields) {
371
278
  message: 'Invalid change address format'
372
279
  });
373
280
  }
374
- // Validate lovelaceAmount is a positive integer (string-based to avoid precision loss for large values)
281
+ // String-based positive-integer check avoids precision loss for large values
375
282
  if (inputs.lovelaceAmount !== undefined && inputs.lovelaceAmount !== null) {
376
283
  const s = String(inputs.lovelaceAmount);
377
284
  if (!/^\d+$/.test(s) || s === '0') {
@@ -382,7 +289,7 @@ function validateTransactionInputs(inputs, requiredFields) {
382
289
  });
383
290
  }
384
291
  }
385
- // Validate CBOR format and size (max 65536 hex chars = 32 KB binary)
292
+ // 65536 hex chars = 32 KB binary
386
293
  const MAX_CBOR_HEX_LENGTH = 65536;
387
294
  if (inputs.signedTxCbor && !isValidCbor(inputs.signedTxCbor)) {
388
295
  errors.push({
@@ -435,7 +342,6 @@ function validateTransactionInputs(inputs, requiredFields) {
435
342
  });
436
343
  }
437
344
  }
438
- // Validate JSON fields with size and complexity limits
439
345
  if (inputs.metadataJson) {
440
346
  const result = validateJsonWithLimits(inputs.metadataJson, 'metadataJson');
441
347
  if (!result.valid) {
@@ -467,7 +373,7 @@ function validateTransactionInputs(inputs, requiredFields) {
467
373
  }
468
374
  }
469
375
  if (inputs.redeemerJson) {
470
- const result = validateJsonWithLimits(inputs.redeemerJson, 'redeemerJson');
376
+ const result = validatePlutusJson(inputs.redeemerJson, 'redeemerJson');
471
377
  if (!result.valid) {
472
378
  errors.push({
473
379
  type: 'invalid',
@@ -477,7 +383,7 @@ function validateTransactionInputs(inputs, requiredFields) {
477
383
  }
478
384
  }
479
385
  if (inputs.datumJson) {
480
- const result = validateJsonWithLimits(inputs.datumJson, 'datumJson');
386
+ const result = validatePlutusJson(inputs.datumJson, 'datumJson');
481
387
  if (!result.valid) {
482
388
  errors.push({
483
389
  type: 'invalid',
@@ -503,10 +409,7 @@ function validateTransactionInputs(inputs, requiredFields) {
503
409
  }
504
410
  return errors;
505
411
  }
506
- /**
507
- * Validate a Posix-ms string field: must be a non-negative integer with at most
508
- * MAX_POSIX_MS_DIGITS digits. Returns null if valid or absent.
509
- */
412
+ /** Posix-ms string field: non-negative integer with at most MAX_POSIX_MS_DIGITS digits; null when valid or absent. */
510
413
  function validatePosixMsField(value, field) {
511
414
  if (value === undefined || value === null || value === '')
512
415
  return null;