@odatano/core 2.0.0-rc.5 → 2.0.0-rc.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/@cds-models/CardanoAgentService/index.d.ts +99 -51
  2. package/@cds-models/CardanoAgentService/index.js +15 -0
  3. package/@cds-models/CardanoBackendService/index.d.ts +358 -0
  4. package/@cds-models/CardanoBackendService/index.js +41 -0
  5. package/@cds-models/CardanoIndexerService/index.d.ts +594 -11
  6. package/@cds-models/CardanoIndexerService/index.js +74 -0
  7. package/@cds-models/CardanoODataService/index.d.ts +417 -57
  8. package/@cds-models/CardanoODataService/index.js +42 -0
  9. package/@cds-models/CardanoSignService/index.d.ts +45 -19
  10. package/@cds-models/CardanoSignService/index.js +4 -0
  11. package/@cds-models/CardanoTransactionService/index.d.ts +70 -44
  12. package/@cds-models/CardanoTransactionService/index.js +5 -0
  13. package/@cds-models/CardanoWorkerService/index.d.ts +35 -22
  14. package/@cds-models/CardanoWorkerService/index.js +2 -0
  15. package/@cds-models/index.d.ts +114 -4
  16. package/@cds-models/index.js +20 -4
  17. package/@cds-models/odatano/cardano/index.d.ts +451 -32
  18. package/@cds-models/odatano/cardano/index.js +48 -0
  19. package/README.md +103 -167
  20. package/db/schema.cds +2455 -1705
  21. package/db/types.cds +456 -295
  22. package/package.json +41 -53
  23. package/scripts/deploy-schema.mjs +113 -0
  24. package/scripts/migrate-schema.mjs +528 -0
  25. package/scripts/migrate-slot-leader.mjs +96 -0
  26. package/src/index.d.ts +20 -21
  27. package/src/index.js +45 -31
  28. package/src/plugin.js +17 -35
  29. package/srv/blockchain/asset-decimals.d.ts +7 -0
  30. package/srv/blockchain/asset-decimals.js +91 -0
  31. package/srv/blockchain/backends/blockfrost-backend.d.ts +25 -137
  32. package/srv/blockchain/backends/blockfrost-backend.js +125 -215
  33. package/srv/blockchain/backends/call-signal.d.ts +7 -0
  34. package/srv/blockchain/backends/call-signal.js +22 -0
  35. package/srv/blockchain/backends/cardano-backend.d.ts +100 -189
  36. package/srv/blockchain/backends/cardano-backend.js +29 -5
  37. package/srv/blockchain/backends/koios-backend.d.ts +108 -170
  38. package/srv/blockchain/backends/koios-backend.js +488 -482
  39. package/srv/blockchain/backends/odatano-backend.d.ts +55 -0
  40. package/srv/blockchain/backends/odatano-backend.js +211 -0
  41. package/srv/blockchain/backends/ogmios-backend.d.ts +122 -190
  42. package/srv/blockchain/backends/ogmios-backend.js +683 -327
  43. package/srv/blockchain/backends/ogmios-frame-guard.d.ts +14 -0
  44. package/srv/blockchain/backends/ogmios-frame-guard.js +89 -0
  45. package/srv/blockchain/cardano-client.d.ts +71 -241
  46. package/srv/blockchain/cardano-client.js +354 -322
  47. package/srv/blockchain/cardano-indexer.d.ts +295 -283
  48. package/srv/blockchain/cardano-indexer.js +1690 -502
  49. package/srv/blockchain/cardano-tx-builder.d.ts +25 -89
  50. package/srv/blockchain/cardano-tx-builder.js +164 -140
  51. package/srv/blockchain/circuit-breaker.d.ts +2 -13
  52. package/srv/blockchain/circuit-breaker.js +11 -15
  53. package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
  54. package/srv/blockchain/crawler/account-snapshots.js +173 -0
  55. package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +17 -0
  56. package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
  57. package/srv/blockchain/crawler/asset-registry-backfill.d.ts +46 -0
  58. package/srv/blockchain/crawler/asset-registry-backfill.js +157 -0
  59. package/srv/blockchain/crawler/asset-slice-backfill.d.ts +35 -0
  60. package/srv/blockchain/crawler/asset-slice-backfill.js +149 -0
  61. package/srv/blockchain/crawler/certificate-backfill.d.ts +56 -0
  62. package/srv/blockchain/crawler/certificate-backfill.js +174 -0
  63. package/srv/blockchain/crawler/crawler.d.ts +125 -81
  64. package/srv/blockchain/crawler/crawler.js +738 -167
  65. package/srv/blockchain/crawler/credential-backfill.d.ts +30 -0
  66. package/srv/blockchain/crawler/credential-backfill.js +101 -0
  67. package/srv/blockchain/crawler/hooks.d.ts +2 -17
  68. package/srv/blockchain/crawler/index.d.ts +1 -8
  69. package/srv/blockchain/crawler/index.js +31 -17
  70. package/srv/blockchain/crawler/input-asset-copies.d.ts +34 -0
  71. package/srv/blockchain/crawler/input-asset-copies.js +161 -0
  72. package/srv/blockchain/crawler/key-pages.d.ts +12 -0
  73. package/srv/blockchain/crawler/key-pages.js +48 -0
  74. package/srv/blockchain/crawler/metadata-position-backfill.d.ts +22 -0
  75. package/srv/blockchain/crawler/metadata-position-backfill.js +59 -0
  76. package/srv/blockchain/crawler/output-datum-backfill.d.ts +41 -0
  77. package/srv/blockchain/crawler/output-datum-backfill.js +100 -0
  78. package/srv/blockchain/crawler/sync-state.d.ts +31 -47
  79. package/srv/blockchain/crawler/sync-state.js +135 -128
  80. package/srv/blockchain/crawler/transaction-backfill.d.ts +46 -0
  81. package/srv/blockchain/crawler/transaction-backfill.js +271 -0
  82. package/srv/blockchain/crawler/utxo-set-import.d.ts +66 -0
  83. package/srv/blockchain/crawler/utxo-set-import.js +399 -0
  84. package/srv/blockchain/crawler/window-plan.d.ts +31 -0
  85. package/srv/blockchain/crawler/window-plan.js +59 -0
  86. package/srv/blockchain/ledger-state.d.ts +62 -0
  87. package/srv/blockchain/ledger-state.js +521 -0
  88. package/srv/blockchain/pending-spends.d.ts +16 -0
  89. package/srv/blockchain/pending-spends.js +81 -0
  90. package/srv/blockchain/pool-metadata.d.ts +15 -0
  91. package/srv/blockchain/pool-metadata.js +132 -0
  92. package/srv/blockchain/request-coalescer.d.ts +2 -16
  93. package/srv/blockchain/request-coalescer.js +2 -16
  94. package/srv/blockchain/signing/cose-verifier.d.ts +3 -17
  95. package/srv/blockchain/signing/cose-verifier.js +146 -70
  96. package/srv/blockchain/signing/external-signer.d.ts +15 -115
  97. package/srv/blockchain/signing/external-signer.js +22 -131
  98. package/srv/blockchain/signing/failed-recheck.d.ts +17 -0
  99. package/srv/blockchain/signing/failed-recheck.js +135 -0
  100. package/srv/blockchain/signing/hsm-signer.d.ts +10 -54
  101. package/srv/blockchain/signing/hsm-signer.js +28 -79
  102. package/srv/blockchain/signing/landing-proof.d.ts +60 -0
  103. package/srv/blockchain/signing/landing-proof.js +224 -0
  104. package/srv/blockchain/signing/signature-verifier.d.ts +9 -47
  105. package/srv/blockchain/signing/signature-verifier.js +71 -87
  106. package/srv/blockchain/signing/submission-finalizer.d.ts +37 -45
  107. package/srv/blockchain/signing/submission-finalizer.js +280 -86
  108. package/srv/blockchain/stored-chain.d.ts +19 -0
  109. package/srv/blockchain/stored-chain.js +258 -0
  110. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +31 -229
  111. package/srv/blockchain/transaction-building/buildooor-tx.js +663 -421
  112. package/srv/blockchain/transaction-building/cardano-tx.d.ts +9 -37
  113. package/srv/blockchain/transaction-presence.d.ts +12 -0
  114. package/srv/blockchain/transaction-presence.js +29 -0
  115. package/srv/blockchain/transaction-rows.d.ts +12 -0
  116. package/srv/blockchain/transaction-rows.js +44 -0
  117. package/srv/blockchain/wallet-worker/build-request.d.ts +8 -23
  118. package/srv/blockchain/wallet-worker/build-request.js +40 -353
  119. package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +27 -47
  120. package/srv/blockchain/wallet-worker/confirmation-tracker.js +158 -61
  121. package/srv/blockchain/wallet-worker/index.d.ts +1 -1
  122. package/srv/blockchain/wallet-worker/index.js +3 -11
  123. package/srv/blockchain/wallet-worker/invalidation.d.ts +35 -0
  124. package/srv/blockchain/wallet-worker/invalidation.js +128 -0
  125. package/srv/blockchain/wallet-worker/job-store.d.ts +58 -150
  126. package/srv/blockchain/wallet-worker/job-store.js +200 -273
  127. package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -26
  128. package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -28
  129. package/srv/blockchain/wallet-worker/signers.d.ts +5 -24
  130. package/srv/blockchain/wallet-worker/signers.js +4 -12
  131. package/srv/blockchain/wallet-worker/wallet-worker.d.ts +29 -82
  132. package/srv/blockchain/wallet-worker/wallet-worker.js +334 -198
  133. package/srv/cardano-agent-service.cds +122 -84
  134. package/srv/cardano-agent-service.js +12 -9
  135. package/srv/cardano-backend-service.cds +81 -0
  136. package/srv/cardano-backend-service.d.ts +2 -0
  137. package/srv/cardano-backend-service.js +259 -0
  138. package/srv/cardano-indexer-service.cds +393 -18
  139. package/srv/cardano-indexer-service.d.ts +5 -1
  140. package/srv/cardano-indexer-service.js +477 -16
  141. package/srv/cardano-service.cds +426 -269
  142. package/srv/cardano-service.js +640 -217
  143. package/srv/cardano-sign-service.cds +211 -180
  144. package/srv/cardano-sign-service.js +210 -287
  145. package/srv/cardano-tx-service.cds +462 -370
  146. package/srv/cardano-tx-service.js +283 -800
  147. package/srv/cardano-ui.cds +16 -16
  148. package/srv/cardano-worker-service.cds +141 -125
  149. package/srv/cardano-worker-service.js +104 -61
  150. package/srv/cbor/cip68.d.ts +13 -0
  151. package/srv/cbor/cip68.js +56 -0
  152. package/srv/cbor/index.d.ts +3 -1
  153. package/srv/cbor/index.js +9 -1
  154. package/srv/cbor/parse.d.ts +30 -18
  155. package/srv/cbor/parse.js +44 -9
  156. package/srv/cbor/plutus-data-json.d.ts +20 -0
  157. package/srv/cbor/plutus-data-json.js +32 -0
  158. package/srv/config.d.ts +117 -0
  159. package/srv/config.js +419 -0
  160. package/srv/server.d.ts +15 -110
  161. package/srv/server.js +83 -405
  162. package/srv/utils/agent-access.d.ts +11 -0
  163. package/srv/utils/agent-access.js +86 -0
  164. package/srv/utils/agent-grants-config.d.ts +0 -46
  165. package/srv/utils/agent-grants-config.js +17 -85
  166. package/srv/utils/agent-grants.d.ts +106 -122
  167. package/srv/utils/agent-grants.js +538 -237
  168. package/srv/utils/agent-token-auth.d.ts +4 -99
  169. package/srv/utils/agent-token-auth.js +62 -186
  170. package/srv/utils/backend-request-handler.d.ts +3 -17
  171. package/srv/utils/backend-request-handler.js +3 -18
  172. package/srv/utils/build-request.d.ts +52 -0
  173. package/srv/utils/build-request.js +487 -0
  174. package/srv/utils/collections.d.ts +4 -10
  175. package/srv/utils/collections.js +14 -10
  176. package/srv/utils/const.d.ts +32 -75
  177. package/srv/utils/const.js +40 -80
  178. package/srv/utils/crypto.d.ts +3 -12
  179. package/srv/utils/crypto.js +11 -25
  180. package/srv/utils/db-indexes.d.ts +31 -0
  181. package/srv/utils/db-indexes.js +185 -0
  182. package/srv/utils/db-kind.d.ts +23 -0
  183. package/srv/utils/db-kind.js +42 -0
  184. package/srv/utils/db-sanitize.d.ts +20 -0
  185. package/srv/utils/db-sanitize.js +80 -0
  186. package/srv/utils/deep-json.d.ts +6 -0
  187. package/srv/utils/deep-json.js +240 -0
  188. package/srv/utils/detached-run.d.ts +41 -0
  189. package/srv/utils/detached-run.js +101 -0
  190. package/srv/utils/epoch-slots.d.ts +14 -0
  191. package/srv/utils/epoch-slots.js +45 -0
  192. package/srv/utils/error-codes.d.ts +26 -75
  193. package/srv/utils/error-codes.js +27 -72
  194. package/srv/utils/errors.d.ts +55 -187
  195. package/srv/utils/errors.js +161 -235
  196. package/srv/utils/lease.d.ts +20 -0
  197. package/srv/utils/lease.js +62 -0
  198. package/srv/utils/liveness.d.ts +12 -0
  199. package/srv/utils/liveness.js +35 -0
  200. package/srv/utils/mappers.d.ts +111 -223
  201. package/srv/utils/mappers.js +432 -371
  202. package/srv/utils/navigation.d.ts +17 -0
  203. package/srv/utils/navigation.js +52 -0
  204. package/srv/utils/network-context.d.ts +0 -1
  205. package/srv/utils/network-context.js +9 -15
  206. package/srv/utils/paging.d.ts +31 -0
  207. package/srv/utils/paging.js +43 -0
  208. package/srv/utils/pg-inline-json.d.ts +8 -0
  209. package/srv/utils/pg-inline-json.js +58 -0
  210. package/srv/utils/pg-order-nulls.d.ts +14 -0
  211. package/srv/utils/pg-order-nulls.js +54 -0
  212. package/srv/utils/plutus-placeholders.d.ts +16 -22
  213. package/srv/utils/plutus-placeholders.js +62 -33
  214. package/srv/utils/rate-limiter.d.ts +2 -21
  215. package/srv/utils/rate-limiter.js +5 -17
  216. package/srv/utils/readiness.d.ts +12 -0
  217. package/srv/utils/readiness.js +29 -0
  218. package/srv/utils/reference-script.d.ts +19 -0
  219. package/srv/utils/reference-script.js +84 -0
  220. package/srv/utils/resolution.d.ts +13 -0
  221. package/srv/utils/resolution.js +47 -0
  222. package/srv/utils/result-numbers.d.ts +15 -0
  223. package/srv/utils/result-numbers.js +61 -0
  224. package/srv/utils/row-values.d.ts +7 -0
  225. package/srv/utils/row-values.js +27 -0
  226. package/srv/utils/service-events.d.ts +0 -24
  227. package/srv/utils/service-events.js +3 -25
  228. package/srv/utils/signing-helper.d.ts +3 -20
  229. package/srv/utils/signing-helper.js +35 -64
  230. package/srv/utils/tx-build-helper.d.ts +25 -105
  231. package/srv/utils/tx-build-helper.js +108 -156
  232. package/srv/utils/tx-request-parsers.d.ts +82 -33
  233. package/srv/utils/tx-request-parsers.js +401 -49
  234. package/srv/utils/tx-utils.d.ts +3 -27
  235. package/srv/utils/tx-utils.js +32 -50
  236. package/srv/utils/types.d.ts +294 -232
  237. package/srv/utils/types.js +2 -22
  238. package/srv/utils/validators.d.ts +22 -92
  239. package/srv/utils/validators.js +60 -170
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SigningStatus = exports.ExternalSignerType = void 0;
4
- /**
5
- * Supported external signer types
6
- */
3
+ exports.ExternalSignerType = void 0;
4
+ /** Supported external signer types */
7
5
  var ExternalSignerType;
8
6
  (function (ExternalSignerType) {
9
7
  /** Cardano CLI - Reference implementation for signing */
@@ -17,22 +15,4 @@ 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
- */
23
- var SigningStatus;
24
- (function (SigningStatus) {
25
- /** Request created, awaiting signing */
26
- SigningStatus["PENDING"] = "pending";
27
- /** Transaction has been signed */
28
- SigningStatus["SIGNED"] = "signed";
29
- /** Signature verified, ready for submission */
30
- SigningStatus["VERIFIED"] = "verified";
31
- /** Transaction submitted to network */
32
- SigningStatus["SUBMITTED"] = "submitted";
33
- /** Signing or verification failed */
34
- SigningStatus["FAILED"] = "failed";
35
- /** Request expired (not signed within TTL) */
36
- SigningStatus["EXPIRED"] = "expired";
37
- })(SigningStatus || (exports.SigningStatus = SigningStatus = {}));
38
18
  //# sourceMappingURL=types.js.map
@@ -1,115 +1,50 @@
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. */
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. */
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
- /**
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).
90
- */
91
35
  export declare function extractPaymentCredential(address: string): {
92
36
  hash: string;
93
37
  isScript: boolean;
94
38
  } | 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
- */
39
+ /** Validate an array of Ed25519 key hashes (56 hex chars each); throws on any invalid entry. */
101
40
  export declare function validateRequiredSigners(signers: unknown): string[];
102
- /**
103
- * Validation error details for transaction input validation
104
- */
41
+ /** Validation error details for transaction input validation */
105
42
  export interface ValidationError {
106
43
  type: 'missing' | 'invalid';
107
44
  field: string;
108
45
  message: string;
109
46
  }
110
- /**
111
- * Transaction input fields for validation
112
- */
47
+ /** Transaction input fields for validation */
113
48
  export interface TransactionInputs {
114
49
  senderAddress?: string;
115
50
  recipientAddress?: string;
@@ -134,12 +69,7 @@ export interface TransactionInputs {
134
69
  validityStartMs?: string;
135
70
  validityEndMs?: string;
136
71
  }
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
- */
72
+ /** Validate transaction build inputs; returns the validation errors (empty when all valid). */
143
73
  export declare function validateTransactionInputs(inputs: TransactionInputs, requiredFields: (keyof TransactionInputs)[]): ValidationError[];
144
74
  export {};
145
75
  //# 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,17 @@ 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
+ const mappers_1 = require("./mappers");
25
+ /** Trimmed string, or null when not a string or empty after trim. */
29
26
  function safeTrimString(s) {
30
27
  if (typeof s !== "string")
31
28
  return null;
32
29
  const t = s.trim();
33
30
  return t.length > 0 ? t : null;
34
31
  }
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
- */
32
+ /** Strict bech32 decode with HRP allowlist; null when invalid. */
41
33
  function tryDecodeBech32WithHrp(value, allowedHrp) {
42
34
  try {
43
35
  const decoded = bech32_1.bech32.decode(value, const_1.BECH32_MAX_LENGTH);
@@ -50,27 +42,16 @@ function tryDecodeBech32WithHrp(value, allowedHrp) {
50
42
  return null;
51
43
  }
52
44
  }
53
- /**
54
- * Convert bech32 words to byte length
55
- * @param words - bech32 decoded words
56
- * @returns { number } byte length of decoded words
57
- */
45
+ /** Byte length of decoded bech32 words (fromWords validates the word range). */
58
46
  function wordsToBytesLen(words) {
59
- // bech32.fromWords validates word range and converts 5-bit words -> bytes
60
47
  return Buffer.from(bech32_1.bech32.fromWords(words)).length;
61
48
  }
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)
49
+ /** Parse a JSON string under size and complexity limits (DoS prevention); `fieldName` is for messages. */
50
+ function validateJsonWithLimits(jsonString, fieldName, maxDepth = const_1.MAX_DEPTH) {
51
+ // Size limit before parsing
70
52
  if (jsonString.length > const_1.MAX_JSON_SIZE) {
71
53
  return { valid: false, error: `${fieldName} exceeds maximum size of ${const_1.MAX_JSON_SIZE} bytes` };
72
54
  }
73
- // Parse JSON
74
55
  let parsed;
75
56
  try {
76
57
  parsed = JSON.parse(jsonString);
@@ -78,105 +59,79 @@ function validateJsonWithLimits(jsonString, fieldName) {
78
59
  catch {
79
60
  return { valid: false, error: `Invalid JSON in ${fieldName}` };
80
61
  }
81
- // Validate complexity recursively
82
- const complexityError = checkJsonComplexity(parsed, 0);
62
+ const complexityError = checkJsonComplexity(parsed, 0, maxDepth);
83
63
  if (complexityError) {
84
64
  return { valid: false, error: `${fieldName}: ${complexityError}` };
85
65
  }
86
66
  return { valid: true, parsed };
87
67
  }
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`;
68
+ /** PlutusData JSON (redeemer, datum, script params): the same limits with PLUTUS_DATA_MAX_DEPTH. */
69
+ function validatePlutusJson(jsonString, fieldName) {
70
+ return validateJsonWithLimits(jsonString, fieldName, const_1.PLUTUS_DATA_MAX_DEPTH);
71
+ }
72
+ /** Request fields that carry PlutusData JSON. */
73
+ exports.PLUTUS_JSON_FIELDS = new Set([
74
+ 'redeemerJson', 'datumJson', 'inlineDatumJson', 'outputDatumJson', 'mintRedeemerJson', 'scriptParamsJson',
75
+ ]);
76
+ /** Recursive complexity check (depth, keys, array length, string length); error message or null. */
77
+ function checkJsonComplexity(value, depth, maxDepth) {
78
+ if (depth > maxDepth) {
79
+ return `Maximum nesting depth of ${maxDepth} exceeded`;
98
80
  }
99
81
  if (value === null || typeof value !== 'object') {
100
- // Check string length for primitive strings
101
82
  if (typeof value === 'string' && value.length > const_1.MAX_STRING_LENGTH) {
102
83
  return `String value exceeds maximum length of ${const_1.MAX_STRING_LENGTH}`;
103
84
  }
104
85
  return null;
105
86
  }
106
87
  if (Array.isArray(value)) {
107
- // Check array length
108
88
  if (value.length > const_1.MAX_ARRAY_LENGTH) {
109
89
  return `Array exceeds maximum length of ${const_1.MAX_ARRAY_LENGTH}`;
110
90
  }
111
- // Recursively check array elements
112
91
  for (const item of value) {
113
- const error = checkJsonComplexity(item, depth + 1);
92
+ const error = checkJsonComplexity(item, depth + 1, maxDepth);
114
93
  if (error)
115
94
  return error;
116
95
  }
117
96
  }
118
97
  else {
119
- // Check object key count
120
98
  const keys = Object.keys(value);
121
99
  if (keys.length > const_1.MAX_KEYS) {
122
100
  return `Object exceeds maximum key count of ${const_1.MAX_KEYS}`;
123
101
  }
124
- // Recursively check object values
125
102
  for (const key of keys) {
126
- const error = checkJsonComplexity(value[key], depth + 1);
103
+ const error = checkJsonComplexity(value[key], depth + 1, maxDepth);
127
104
  if (error)
128
105
  return error;
129
106
  }
130
107
  }
131
108
  return null;
132
109
  }
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
- */
110
+ /** Transaction hash: 64-character hex string */
138
111
  function isTxHash(s) {
139
112
  return typeof s === "string" && const_1.TX_HASH_REGEX.test(s);
140
113
  }
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
- */
114
+ /** Asset unit: policy ID (56 hex chars) + asset name (0-64 hex chars, even length) */
146
115
  function isAssetUnit(s) {
147
116
  if (typeof s !== "string")
148
117
  return false;
149
118
  const t = s.trim();
150
- // Regex ensures: 56-192 hex chars, even length, valid hex
151
119
  return const_1.ASSET_UNIT_REGEX.test(t);
152
120
  }
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
- */
121
+ /** Block hash: 64-character hex string */
158
122
  function isBlockHash(s) {
159
123
  return typeof s === "string" && const_1.HEX_64_REGEX.test(s);
160
124
  }
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
- */
125
+ /** Payment credential: 28-byte key or script hash as 56-char lowercase hex (credential-keyed UTxO queries). */
167
126
  function isValidCredential(s) {
168
127
  return typeof s === "string" && const_1.HEX_56_REGEX.test(s);
169
128
  }
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
- */
129
+ /** Pool ID: bech32 with HRP "pool" and a 28-byte payload. */
175
130
  function isValidPoolId(poolIdRaw) {
176
131
  const poolId = safeTrimString(poolIdRaw);
177
132
  if (!poolId)
178
133
  return false;
179
- // optional: cheap prefilter (keeps performance high)
134
+ // cheap prefilter
180
135
  if (!const_1.POOL_ID_REGEX.test(poolId))
181
136
  return false;
182
137
  const decoded = tryDecodeBech32WithHrp(poolId, ["pool"]);
@@ -184,16 +139,12 @@ function isValidPoolId(poolIdRaw) {
184
139
  return wordsToBytesLen(decoded.words) === const_1.POOL_ID_BYTES;
185
140
  return false;
186
141
  }
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
- */
142
+ /** DRep ID: bech32 with HRP "drep" and a 29-byte payload. */
192
143
  function isValidDrepId(drepRaw) {
193
144
  const drepId = safeTrimString(drepRaw);
194
145
  if (!drepId)
195
146
  return false;
196
- // optional cheap prefilter
147
+ // cheap prefilter
197
148
  if (!const_1.DREP_ID_REGEX.test(drepId))
198
149
  return false;
199
150
  const decoded = tryDecodeBech32WithHrp(drepId, ["drep"]);
@@ -201,49 +152,35 @@ function isValidDrepId(drepRaw) {
201
152
  return wordsToBytesLen(decoded.words) === const_1.DREP_ID_BYTES;
202
153
  return false;
203
154
  }
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
- */
155
+ /** Bech32 address with the HRP of the active network. */
209
156
  function isValidBech32Address(addrRaw) {
210
157
  const addr = safeTrimString(addrRaw);
211
158
  if (!addr)
212
159
  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.
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. */
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,70 +190,30 @@ 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
- /**
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).
293
- */
210
+ // Payment credential hash of a Shelley address and whether it is a script credential.
211
+ // Null for undecodable or stake addresses.
294
212
  function extractPaymentCredential(address) {
295
- try {
296
- const decoded = bech32_1.bech32.decode(address, const_1.BECH32_MAX_LENGTH);
297
- const bytes = Buffer.from(bech32_1.bech32.fromWords(decoded.words));
298
- // 1 header byte + 28-byte payment credential (+ optional 28-byte stake part)
299
- if (bytes.length < 29)
300
- return null;
301
- const addrType = bytes[0] >> 4;
302
- // types 0-7 are payment addresses; 14/15 are stake addresses (no payment part)
303
- if (addrType > 7)
304
- return null;
305
- return {
306
- hash: bytes.subarray(1, 29).toString('hex'),
307
- isScript: (addrType & 0x1) === 1,
308
- };
309
- }
310
- catch {
311
- return null;
312
- }
213
+ const decoded = (0, mappers_1.decodeShelleyAddress)(address);
214
+ return decoded.paymentCredential ? { hash: decoded.paymentCredential, isScript: decoded.isScript } : null;
313
215
  }
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
- */
216
+ /** Validate an array of Ed25519 key hashes (56 hex chars each); throws on any invalid entry. */
320
217
  function validateRequiredSigners(signers) {
321
218
  if (!Array.isArray(signers)) {
322
219
  throw new Error('requiredSignersJson must be a JSON array');
@@ -328,15 +225,9 @@ function validateRequiredSigners(signers) {
328
225
  }
329
226
  return signers;
330
227
  }
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
- */
228
+ /** Validate transaction build inputs; returns the validation errors (empty when all valid). */
337
229
  function validateTransactionInputs(inputs, requiredFields) {
338
230
  const errors = [];
339
- // Check required fields
340
231
  for (const field of requiredFields) {
341
232
  if (inputs[field] === undefined || inputs[field] === null || inputs[field] === '') {
342
233
  errors.push({
@@ -346,10 +237,8 @@ function validateTransactionInputs(inputs, requiredFields) {
346
237
  });
347
238
  }
348
239
  }
349
- // If required fields are missing, return early
350
240
  if (errors.length > 0)
351
241
  return errors;
352
- // Validate address formats
353
242
  if (inputs.senderAddress && !isValidBech32Address(inputs.senderAddress)) {
354
243
  errors.push({
355
244
  type: 'invalid',
@@ -371,7 +260,7 @@ function validateTransactionInputs(inputs, requiredFields) {
371
260
  message: 'Invalid change address format'
372
261
  });
373
262
  }
374
- // Validate lovelaceAmount is a positive integer (string-based to avoid precision loss for large values)
263
+ // String-based positive-integer check avoids precision loss for large values
375
264
  if (inputs.lovelaceAmount !== undefined && inputs.lovelaceAmount !== null) {
376
265
  const s = String(inputs.lovelaceAmount);
377
266
  if (!/^\d+$/.test(s) || s === '0') {
@@ -382,8 +271,6 @@ function validateTransactionInputs(inputs, requiredFields) {
382
271
  });
383
272
  }
384
273
  }
385
- // Validate CBOR format and size (max 65536 hex chars = 32 KB binary)
386
- const MAX_CBOR_HEX_LENGTH = 65536;
387
274
  if (inputs.signedTxCbor && !isValidCbor(inputs.signedTxCbor)) {
388
275
  errors.push({
389
276
  type: 'invalid',
@@ -391,11 +278,11 @@ function validateTransactionInputs(inputs, requiredFields) {
391
278
  message: 'Invalid signedTxCbor format'
392
279
  });
393
280
  }
394
- else if (inputs.signedTxCbor && typeof inputs.signedTxCbor === 'string' && inputs.signedTxCbor.length > MAX_CBOR_HEX_LENGTH) {
281
+ else if (inputs.signedTxCbor && typeof inputs.signedTxCbor === 'string' && inputs.signedTxCbor.length > const_1.MAX_TX_CBOR_HEX_LENGTH) {
395
282
  errors.push({
396
283
  type: 'invalid',
397
284
  field: 'signedTxCbor',
398
- message: `signedTxCbor exceeds maximum size of ${MAX_CBOR_HEX_LENGTH} hex characters`
285
+ message: `signedTxCbor exceeds maximum size of ${const_1.MAX_TX_CBOR_HEX_LENGTH} hex characters`
399
286
  });
400
287
  }
401
288
  if (inputs.mintingPolicyScript && !isValidCbor(inputs.mintingPolicyScript)) {
@@ -435,7 +322,6 @@ function validateTransactionInputs(inputs, requiredFields) {
435
322
  });
436
323
  }
437
324
  }
438
- // Validate JSON fields with size and complexity limits
439
325
  if (inputs.metadataJson) {
440
326
  const result = validateJsonWithLimits(inputs.metadataJson, 'metadataJson');
441
327
  if (!result.valid) {
@@ -467,7 +353,7 @@ function validateTransactionInputs(inputs, requiredFields) {
467
353
  }
468
354
  }
469
355
  if (inputs.redeemerJson) {
470
- const result = validateJsonWithLimits(inputs.redeemerJson, 'redeemerJson');
356
+ const result = validatePlutusJson(inputs.redeemerJson, 'redeemerJson');
471
357
  if (!result.valid) {
472
358
  errors.push({
473
359
  type: 'invalid',
@@ -477,7 +363,7 @@ function validateTransactionInputs(inputs, requiredFields) {
477
363
  }
478
364
  }
479
365
  if (inputs.datumJson) {
480
- const result = validateJsonWithLimits(inputs.datumJson, 'datumJson');
366
+ const result = validatePlutusJson(inputs.datumJson, 'datumJson');
481
367
  if (!result.valid) {
482
368
  errors.push({
483
369
  type: 'invalid',
@@ -501,12 +387,16 @@ function validateTransactionInputs(inputs, requiredFields) {
501
387
  });
502
388
  }
503
389
  }
390
+ if (!validityEndErr && inputs.validityEndMs && Number(inputs.validityEndMs) > Date.now() + const_1.MAX_VALIDITY_MS) {
391
+ errors.push({
392
+ type: 'invalid',
393
+ field: 'validityEndMs',
394
+ message: `validityEndMs may be at most ${const_1.MAX_VALIDITY_MS / 3_600_000} hours from now`
395
+ });
396
+ }
504
397
  return errors;
505
398
  }
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
- */
399
+ /** Posix-ms string field: non-negative integer with at most MAX_POSIX_MS_DIGITS digits; null when valid or absent. */
510
400
  function validatePosixMsField(value, field) {
511
401
  if (value === undefined || value === null || value === '')
512
402
  return null;