@odatano/core 2.0.0-rc.2 → 2.0.0-rc.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@cds-models/CardanoAgentService/index.d.ts +251 -0
- package/@cds-models/CardanoAgentService/index.js +36 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +139 -2
- package/@cds-models/CardanoIndexerService/index.js +18 -0
- package/@cds-models/CardanoODataService/index.d.ts +224 -0
- package/@cds-models/CardanoODataService/index.js +27 -0
- package/@cds-models/CardanoSignService/index.d.ts +5 -2
- package/@cds-models/CardanoTransactionService/index.d.ts +9 -9
- package/@cds-models/odatano/cardano/index.d.ts +316 -0
- package/@cds-models/odatano/cardano/index.js +33 -0
- package/README.md +195 -136
- package/db/schema.cds +2121 -1633
- package/package.json +179 -173
- package/src/index.d.ts +10 -10
- package/src/index.js +24 -14
- package/src/plugin.js +39 -52
- package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
- package/srv/blockchain/backends/blockfrost-backend.js +45 -158
- package/srv/blockchain/backends/cardano-backend.d.ts +78 -158
- package/srv/blockchain/backends/cardano-backend.js +14 -5
- package/srv/blockchain/backends/koios-backend.d.ts +126 -60
- package/srv/blockchain/backends/koios-backend.js +292 -202
- package/srv/blockchain/backends/ogmios-backend.d.ts +59 -96
- package/srv/blockchain/backends/ogmios-backend.js +241 -153
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +32 -0
- package/srv/blockchain/backends/ogmios-frame-guard.js +142 -0
- package/srv/blockchain/cardano-client.d.ts +50 -205
- package/srv/blockchain/cardano-client.js +80 -224
- package/srv/blockchain/cardano-indexer.d.ts +146 -244
- package/srv/blockchain/cardano-indexer.js +442 -285
- package/srv/blockchain/cardano-tx-builder.d.ts +19 -84
- package/srv/blockchain/cardano-tx-builder.js +21 -107
- package/srv/blockchain/crawler/certificate-backfill.d.ts +45 -0
- package/srv/blockchain/crawler/certificate-backfill.js +150 -0
- package/srv/blockchain/crawler/crawler.d.ts +121 -53
- package/srv/blockchain/crawler/crawler.js +402 -82
- package/srv/blockchain/crawler/hooks.d.ts +3 -14
- package/srv/blockchain/crawler/index.d.ts +5 -0
- package/srv/blockchain/crawler/index.js +35 -7
- package/srv/blockchain/crawler/sync-state.d.ts +44 -28
- package/srv/blockchain/crawler/sync-state.js +115 -43
- package/srv/blockchain/crawler/utxo-set-import.d.ts +69 -0
- package/srv/blockchain/crawler/utxo-set-import.js +269 -0
- package/srv/blockchain/ledger-state.d.ts +80 -0
- package/srv/blockchain/ledger-state.js +383 -0
- package/srv/blockchain/signing/cose-verifier.d.ts +5 -12
- package/srv/blockchain/signing/cose-verifier.js +6 -12
- package/srv/blockchain/signing/external-signer.d.ts +16 -113
- package/srv/blockchain/signing/external-signer.js +19 -122
- package/srv/blockchain/signing/hsm-signer.d.ts +13 -45
- package/srv/blockchain/signing/hsm-signer.js +23 -63
- package/srv/blockchain/signing/signature-verifier.d.ts +8 -44
- package/srv/blockchain/signing/signature-verifier.js +13 -54
- package/srv/blockchain/signing/submission-finalizer.d.ts +9 -36
- package/srv/blockchain/signing/submission-finalizer.js +16 -48
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +71 -160
- package/srv/blockchain/transaction-building/buildooor-tx.js +185 -260
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +8 -34
- package/srv/blockchain/wallet-worker/build-request.d.ts +4 -17
- package/srv/blockchain/wallet-worker/build-request.js +39 -23
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +25 -17
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +87 -41
- package/srv/blockchain/wallet-worker/index.js +2 -8
- package/srv/blockchain/wallet-worker/job-store.d.ts +36 -103
- package/srv/blockchain/wallet-worker/job-store.js +0 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +4 -20
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +4 -20
- package/srv/blockchain/wallet-worker/signers.d.ts +6 -19
- package/srv/blockchain/wallet-worker/signers.js +3 -8
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +15 -71
- package/srv/blockchain/wallet-worker/wallet-worker.js +34 -90
- package/srv/cardano-agent-service.cds +146 -0
- package/srv/cardano-agent-service.d.ts +2 -0
- package/srv/cardano-agent-service.js +12 -0
- package/srv/cardano-indexer-service.cds +164 -73
- package/srv/cardano-indexer-service.js +156 -11
- package/srv/cardano-service.cds +45 -0
- package/srv/cardano-service.js +38 -96
- package/srv/cardano-sign-service.cds +200 -180
- package/srv/cardano-sign-service.js +55 -173
- package/srv/cardano-tx-service.cds +32 -26
- package/srv/cardano-tx-service.js +133 -195
- package/srv/cardano-worker-service.js +7 -15
- package/srv/server.d.ts +28 -86
- package/srv/server.js +95 -128
- package/srv/utils/agent-grants-config.d.ts +37 -0
- package/srv/utils/agent-grants-config.js +138 -0
- package/srv/utils/agent-grants.d.ts +262 -0
- package/srv/utils/agent-grants.js +914 -0
- package/srv/utils/agent-token-auth.d.ts +16 -0
- package/srv/utils/agent-token-auth.js +78 -0
- package/srv/utils/backend-request-handler.d.ts +2 -16
- package/srv/utils/backend-request-handler.js +3 -18
- package/srv/utils/collections.d.ts +4 -8
- package/srv/utils/collections.js +4 -8
- package/srv/utils/const.d.ts +19 -68
- package/srv/utils/const.js +20 -69
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +5 -18
- package/srv/utils/db-indexes.d.ts +25 -0
- package/srv/utils/db-indexes.js +89 -0
- package/srv/utils/db-sanitize.d.ts +27 -0
- package/srv/utils/db-sanitize.js +85 -0
- package/srv/utils/error-codes.d.ts +18 -73
- package/srv/utils/error-codes.js +17 -70
- package/srv/utils/errors.d.ts +34 -178
- package/srv/utils/errors.js +55 -217
- package/srv/utils/liveness.d.ts +16 -0
- package/srv/utils/liveness.js +41 -0
- package/srv/utils/mappers.d.ts +82 -210
- package/srv/utils/mappers.js +272 -293
- package/srv/utils/network-context.js +2 -11
- package/srv/utils/pg-order-nulls.d.ts +14 -0
- package/srv/utils/pg-order-nulls.js +57 -0
- package/srv/utils/plutus-placeholders.d.ts +6 -18
- package/srv/utils/plutus-placeholders.js +6 -20
- package/srv/utils/rate-limiter.d.ts +46 -0
- package/srv/utils/rate-limiter.js +116 -0
- package/srv/utils/service-events.d.ts +2 -22
- package/srv/utils/service-events.js +3 -23
- package/srv/utils/signing-helper.d.ts +3 -18
- package/srv/utils/signing-helper.js +10 -32
- package/srv/utils/tx-build-helper.d.ts +18 -92
- package/srv/utils/tx-build-helper.js +32 -123
- package/srv/utils/tx-request-parsers.d.ts +14 -20
- package/srv/utils/tx-request-parsers.js +33 -20
- package/srv/utils/tx-utils.d.ts +4 -23
- package/srv/utils/tx-utils.js +12 -41
- package/srv/utils/types.d.ts +112 -169
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +19 -89
- package/srv/utils/validators.js +31 -138
|
@@ -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
|
-
*/
|
|
7
|
+
/** Parse a JSON string under size and complexity limits (DoS prevention); `fieldName` is for messages. */
|
|
15
8
|
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
|
-
*/
|
|
9
|
+
/** Transaction hash: 64-character hex string */
|
|
21
10
|
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
|
-
*/
|
|
11
|
+
/** Asset unit: policy ID (56 hex chars) + asset name (0-64 hex chars, even length) */
|
|
27
12
|
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
|
-
*/
|
|
13
|
+
/** Block hash: 64-character hex string */
|
|
33
14
|
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
|
-
*/
|
|
15
|
+
/** Payment credential: 28-byte key or script hash as 56-char lowercase hex (credential-keyed UTxO queries). */
|
|
40
16
|
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
|
-
*/
|
|
17
|
+
/** Pool ID: bech32 with HRP "pool" and a 28-byte payload. */
|
|
46
18
|
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
|
-
*/
|
|
19
|
+
/** DRep ID: bech32 with HRP "drep" and a 29-byte payload. */
|
|
52
20
|
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
|
-
*/
|
|
21
|
+
/** Bech32 address with the HRP of the active network; false before the app context is ready. */
|
|
58
22
|
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
|
-
*/
|
|
23
|
+
/** Bech32 stake address with the HRP of the active network; false before the app context is ready. */
|
|
64
24
|
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
|
-
*/
|
|
25
|
+
/** Epoch number: non-negative integer up to MAX_EPOCH */
|
|
70
26
|
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
|
-
*/
|
|
27
|
+
/** CBOR hex: non-empty, even-length hex string */
|
|
76
28
|
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
|
-
*/
|
|
29
|
+
/** `isValidCbor` plus the MAX_TX_CBOR_HEX_LENGTH cap (ParseTransactionCbor memory bound). */
|
|
84
30
|
export declare function isValidTxCborHex(cborRaw: unknown): cborRaw is string;
|
|
85
31
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
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).
|
|
32
|
+
* Payment credential of a Shelley bech32 address: 28-byte hash (hex) plus whether it is a script
|
|
33
|
+
* credential (bit 0 of the header's high nibble); null for undecodable or stake addresses.
|
|
90
34
|
*/
|
|
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
|
package/srv/utils/validators.js
CHANGED
|
@@ -17,27 +17,16 @@ exports.validateRequiredSigners = validateRequiredSigners;
|
|
|
17
17
|
exports.validateTransactionInputs = validateTransactionInputs;
|
|
18
18
|
const bech32_1 = require("bech32");
|
|
19
19
|
const const_1 = require("./const");
|
|
20
|
-
//
|
|
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.
|
|
20
|
+
// Leaf module, not `../server`: importing server would pull the whole server/indexer graph in here.
|
|
23
21
|
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
|
-
*/
|
|
22
|
+
/** Trimmed string, or null when not a string or empty after trim. */
|
|
29
23
|
function safeTrimString(s) {
|
|
30
24
|
if (typeof s !== "string")
|
|
31
25
|
return null;
|
|
32
26
|
const t = s.trim();
|
|
33
27
|
return t.length > 0 ? t : null;
|
|
34
28
|
}
|
|
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
|
-
*/
|
|
29
|
+
/** Strict bech32 decode with HRP allowlist; null when invalid. */
|
|
41
30
|
function tryDecodeBech32WithHrp(value, allowedHrp) {
|
|
42
31
|
try {
|
|
43
32
|
const decoded = bech32_1.bech32.decode(value, const_1.BECH32_MAX_LENGTH);
|
|
@@ -50,27 +39,16 @@ function tryDecodeBech32WithHrp(value, allowedHrp) {
|
|
|
50
39
|
return null;
|
|
51
40
|
}
|
|
52
41
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Convert bech32 words to byte length
|
|
55
|
-
* @param words - bech32 decoded words
|
|
56
|
-
* @returns { number } byte length of decoded words
|
|
57
|
-
*/
|
|
42
|
+
/** Byte length of decoded bech32 words (fromWords validates the word range). */
|
|
58
43
|
function wordsToBytesLen(words) {
|
|
59
|
-
// bech32.fromWords validates word range and converts 5-bit words -> bytes
|
|
60
44
|
return Buffer.from(bech32_1.bech32.fromWords(words)).length;
|
|
61
45
|
}
|
|
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
|
-
*/
|
|
46
|
+
/** Parse a JSON string under size and complexity limits (DoS prevention); `fieldName` is for messages. */
|
|
68
47
|
function validateJsonWithLimits(jsonString, fieldName) {
|
|
69
|
-
//
|
|
48
|
+
// Size limit before parsing
|
|
70
49
|
if (jsonString.length > const_1.MAX_JSON_SIZE) {
|
|
71
50
|
return { valid: false, error: `${fieldName} exceeds maximum size of ${const_1.MAX_JSON_SIZE} bytes` };
|
|
72
51
|
}
|
|
73
|
-
// Parse JSON
|
|
74
52
|
let parsed;
|
|
75
53
|
try {
|
|
76
54
|
parsed = JSON.parse(jsonString);
|
|
@@ -78,37 +56,27 @@ function validateJsonWithLimits(jsonString, fieldName) {
|
|
|
78
56
|
catch {
|
|
79
57
|
return { valid: false, error: `Invalid JSON in ${fieldName}` };
|
|
80
58
|
}
|
|
81
|
-
// Validate complexity recursively
|
|
82
59
|
const complexityError = checkJsonComplexity(parsed, 0);
|
|
83
60
|
if (complexityError) {
|
|
84
61
|
return { valid: false, error: `${fieldName}: ${complexityError}` };
|
|
85
62
|
}
|
|
86
63
|
return { valid: true, parsed };
|
|
87
64
|
}
|
|
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
|
-
*/
|
|
65
|
+
/** Recursive complexity check (depth, keys, array length, string length); error message or null. */
|
|
94
66
|
function checkJsonComplexity(value, depth) {
|
|
95
|
-
// Check depth limit
|
|
96
67
|
if (depth > const_1.MAX_DEPTH) {
|
|
97
68
|
return `Maximum nesting depth of ${const_1.MAX_DEPTH} exceeded`;
|
|
98
69
|
}
|
|
99
70
|
if (value === null || typeof value !== 'object') {
|
|
100
|
-
// Check string length for primitive strings
|
|
101
71
|
if (typeof value === 'string' && value.length > const_1.MAX_STRING_LENGTH) {
|
|
102
72
|
return `String value exceeds maximum length of ${const_1.MAX_STRING_LENGTH}`;
|
|
103
73
|
}
|
|
104
74
|
return null;
|
|
105
75
|
}
|
|
106
76
|
if (Array.isArray(value)) {
|
|
107
|
-
// Check array length
|
|
108
77
|
if (value.length > const_1.MAX_ARRAY_LENGTH) {
|
|
109
78
|
return `Array exceeds maximum length of ${const_1.MAX_ARRAY_LENGTH}`;
|
|
110
79
|
}
|
|
111
|
-
// Recursively check array elements
|
|
112
80
|
for (const item of value) {
|
|
113
81
|
const error = checkJsonComplexity(item, depth + 1);
|
|
114
82
|
if (error)
|
|
@@ -116,12 +84,10 @@ function checkJsonComplexity(value, depth) {
|
|
|
116
84
|
}
|
|
117
85
|
}
|
|
118
86
|
else {
|
|
119
|
-
// Check object key count
|
|
120
87
|
const keys = Object.keys(value);
|
|
121
88
|
if (keys.length > const_1.MAX_KEYS) {
|
|
122
89
|
return `Object exceeds maximum key count of ${const_1.MAX_KEYS}`;
|
|
123
90
|
}
|
|
124
|
-
// Recursively check object values
|
|
125
91
|
for (const key of keys) {
|
|
126
92
|
const error = checkJsonComplexity(value[key], depth + 1);
|
|
127
93
|
if (error)
|
|
@@ -130,53 +96,31 @@ function checkJsonComplexity(value, depth) {
|
|
|
130
96
|
}
|
|
131
97
|
return null;
|
|
132
98
|
}
|
|
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
|
-
*/
|
|
99
|
+
/** Transaction hash: 64-character hex string */
|
|
138
100
|
function isTxHash(s) {
|
|
139
101
|
return typeof s === "string" && const_1.TX_HASH_REGEX.test(s);
|
|
140
102
|
}
|
|
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
|
-
*/
|
|
103
|
+
/** Asset unit: policy ID (56 hex chars) + asset name (0-64 hex chars, even length) */
|
|
146
104
|
function isAssetUnit(s) {
|
|
147
105
|
if (typeof s !== "string")
|
|
148
106
|
return false;
|
|
149
107
|
const t = s.trim();
|
|
150
|
-
// Regex ensures: 56-192 hex chars, even length, valid hex
|
|
151
108
|
return const_1.ASSET_UNIT_REGEX.test(t);
|
|
152
109
|
}
|
|
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
|
-
*/
|
|
110
|
+
/** Block hash: 64-character hex string */
|
|
158
111
|
function isBlockHash(s) {
|
|
159
112
|
return typeof s === "string" && const_1.HEX_64_REGEX.test(s);
|
|
160
113
|
}
|
|
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
|
-
*/
|
|
114
|
+
/** Payment credential: 28-byte key or script hash as 56-char lowercase hex (credential-keyed UTxO queries). */
|
|
167
115
|
function isValidCredential(s) {
|
|
168
116
|
return typeof s === "string" && const_1.HEX_56_REGEX.test(s);
|
|
169
117
|
}
|
|
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
|
-
*/
|
|
118
|
+
/** Pool ID: bech32 with HRP "pool" and a 28-byte payload. */
|
|
175
119
|
function isValidPoolId(poolIdRaw) {
|
|
176
120
|
const poolId = safeTrimString(poolIdRaw);
|
|
177
121
|
if (!poolId)
|
|
178
122
|
return false;
|
|
179
|
-
//
|
|
123
|
+
// cheap prefilter
|
|
180
124
|
if (!const_1.POOL_ID_REGEX.test(poolId))
|
|
181
125
|
return false;
|
|
182
126
|
const decoded = tryDecodeBech32WithHrp(poolId, ["pool"]);
|
|
@@ -184,16 +128,12 @@ function isValidPoolId(poolIdRaw) {
|
|
|
184
128
|
return wordsToBytesLen(decoded.words) === const_1.POOL_ID_BYTES;
|
|
185
129
|
return false;
|
|
186
130
|
}
|
|
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
|
-
*/
|
|
131
|
+
/** DRep ID: bech32 with HRP "drep" and a 29-byte payload. */
|
|
192
132
|
function isValidDrepId(drepRaw) {
|
|
193
133
|
const drepId = safeTrimString(drepRaw);
|
|
194
134
|
if (!drepId)
|
|
195
135
|
return false;
|
|
196
|
-
//
|
|
136
|
+
// cheap prefilter
|
|
197
137
|
if (!const_1.DREP_ID_REGEX.test(drepId))
|
|
198
138
|
return false;
|
|
199
139
|
const decoded = tryDecodeBech32WithHrp(drepId, ["drep"]);
|
|
@@ -201,49 +141,36 @@ function isValidDrepId(drepRaw) {
|
|
|
201
141
|
return wordsToBytesLen(decoded.words) === const_1.DREP_ID_BYTES;
|
|
202
142
|
return false;
|
|
203
143
|
}
|
|
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
|
-
*/
|
|
144
|
+
/** Bech32 address with the HRP of the active network; false before the app context is ready. */
|
|
209
145
|
function isValidBech32Address(addrRaw) {
|
|
210
146
|
const addr = safeTrimString(addrRaw);
|
|
211
147
|
if (!addr)
|
|
212
148
|
return false;
|
|
213
|
-
//
|
|
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.
|
|
149
|
+
// No network yet (app context not initialized): a clean 400 instead of a leaked init error
|
|
218
150
|
const network = (0, network_context_1.getActiveNetwork)();
|
|
219
151
|
if (!network)
|
|
220
152
|
return false;
|
|
221
|
-
//
|
|
153
|
+
// network HRP prefilter
|
|
222
154
|
if (!const_1.HRP[network].addr.test(addr))
|
|
223
155
|
return false;
|
|
224
156
|
const allowed = ["addr", "addr_test"];
|
|
225
157
|
const decoded = tryDecodeBech32WithHrp(addr, allowed);
|
|
226
158
|
if (decoded) {
|
|
227
|
-
//
|
|
159
|
+
// 29 bytes (enterprise/reward) to 57 bytes (base address)
|
|
228
160
|
const len = wordsToBytesLen(decoded.words);
|
|
229
161
|
return len >= 29 && len <= 57;
|
|
230
162
|
}
|
|
231
163
|
return false;
|
|
232
164
|
}
|
|
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
|
-
*/
|
|
165
|
+
/** Bech32 stake address with the HRP of the active network; false before the app context is ready. */
|
|
238
166
|
function isValidBech32StakeAddress(stakeRaw) {
|
|
239
167
|
const stake = safeTrimString(stakeRaw);
|
|
240
168
|
if (!stake)
|
|
241
169
|
return false;
|
|
242
|
-
// Defensive against unset app context — same rationale as isValidBech32Address.
|
|
243
170
|
const network = (0, network_context_1.getActiveNetwork)();
|
|
244
171
|
if (!network)
|
|
245
172
|
return false;
|
|
246
|
-
//
|
|
173
|
+
// network HRP prefilter
|
|
247
174
|
if (!const_1.HRP[network].stake.test(stake))
|
|
248
175
|
return false;
|
|
249
176
|
const allowed = ["stake", "stake_test"];
|
|
@@ -253,43 +180,26 @@ function isValidBech32StakeAddress(stakeRaw) {
|
|
|
253
180
|
const len = wordsToBytesLen(decoded.words);
|
|
254
181
|
return len >= 1 && len <= 64;
|
|
255
182
|
}
|
|
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
|
-
*/
|
|
183
|
+
/** Epoch number: non-negative integer up to MAX_EPOCH */
|
|
261
184
|
function isEpochNumber(s) {
|
|
262
185
|
return typeof s === "number" && s >= 0 && s <= const_1.MAX_EPOCH && Number.isInteger(s);
|
|
263
186
|
}
|
|
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
|
-
*/
|
|
187
|
+
/** CBOR hex: non-empty, even-length hex string */
|
|
269
188
|
function isValidCbor(cborRaw) {
|
|
270
189
|
const cbor = safeTrimString(cborRaw);
|
|
271
190
|
if (!cbor)
|
|
272
191
|
return false;
|
|
273
|
-
// basic validation: must be even-length hex string
|
|
274
192
|
return /^[a-f0-9]+$/i.test(cbor) && cbor.length % 2 === 0;
|
|
275
193
|
}
|
|
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
|
-
*/
|
|
194
|
+
/** `isValidCbor` plus the MAX_TX_CBOR_HEX_LENGTH cap (ParseTransactionCbor memory bound). */
|
|
283
195
|
function isValidTxCborHex(cborRaw) {
|
|
284
196
|
if (!isValidCbor(cborRaw))
|
|
285
197
|
return false;
|
|
286
198
|
return cborRaw.trim().length <= const_1.MAX_TX_CBOR_HEX_LENGTH;
|
|
287
199
|
}
|
|
288
200
|
/**
|
|
289
|
-
*
|
|
290
|
-
*
|
|
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).
|
|
201
|
+
* Payment credential of a Shelley bech32 address: 28-byte hash (hex) plus whether it is a script
|
|
202
|
+
* credential (bit 0 of the header's high nibble); null for undecodable or stake addresses.
|
|
293
203
|
*/
|
|
294
204
|
function extractPaymentCredential(address) {
|
|
295
205
|
try {
|
|
@@ -311,12 +221,7 @@ function extractPaymentCredential(address) {
|
|
|
311
221
|
return null;
|
|
312
222
|
}
|
|
313
223
|
}
|
|
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
|
-
*/
|
|
224
|
+
/** Validate an array of Ed25519 key hashes (56 hex chars each); throws on any invalid entry. */
|
|
320
225
|
function validateRequiredSigners(signers) {
|
|
321
226
|
if (!Array.isArray(signers)) {
|
|
322
227
|
throw new Error('requiredSignersJson must be a JSON array');
|
|
@@ -328,15 +233,9 @@ function validateRequiredSigners(signers) {
|
|
|
328
233
|
}
|
|
329
234
|
return signers;
|
|
330
235
|
}
|
|
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
|
-
*/
|
|
236
|
+
/** Validate transaction build inputs; returns the validation errors (empty when all valid). */
|
|
337
237
|
function validateTransactionInputs(inputs, requiredFields) {
|
|
338
238
|
const errors = [];
|
|
339
|
-
// Check required fields
|
|
340
239
|
for (const field of requiredFields) {
|
|
341
240
|
if (inputs[field] === undefined || inputs[field] === null || inputs[field] === '') {
|
|
342
241
|
errors.push({
|
|
@@ -346,10 +245,8 @@ function validateTransactionInputs(inputs, requiredFields) {
|
|
|
346
245
|
});
|
|
347
246
|
}
|
|
348
247
|
}
|
|
349
|
-
// If required fields are missing, return early
|
|
350
248
|
if (errors.length > 0)
|
|
351
249
|
return errors;
|
|
352
|
-
// Validate address formats
|
|
353
250
|
if (inputs.senderAddress && !isValidBech32Address(inputs.senderAddress)) {
|
|
354
251
|
errors.push({
|
|
355
252
|
type: 'invalid',
|
|
@@ -371,7 +268,7 @@ function validateTransactionInputs(inputs, requiredFields) {
|
|
|
371
268
|
message: 'Invalid change address format'
|
|
372
269
|
});
|
|
373
270
|
}
|
|
374
|
-
//
|
|
271
|
+
// String-based positive-integer check avoids precision loss for large values
|
|
375
272
|
if (inputs.lovelaceAmount !== undefined && inputs.lovelaceAmount !== null) {
|
|
376
273
|
const s = String(inputs.lovelaceAmount);
|
|
377
274
|
if (!/^\d+$/.test(s) || s === '0') {
|
|
@@ -382,7 +279,7 @@ function validateTransactionInputs(inputs, requiredFields) {
|
|
|
382
279
|
});
|
|
383
280
|
}
|
|
384
281
|
}
|
|
385
|
-
//
|
|
282
|
+
// 65536 hex chars = 32 KB binary
|
|
386
283
|
const MAX_CBOR_HEX_LENGTH = 65536;
|
|
387
284
|
if (inputs.signedTxCbor && !isValidCbor(inputs.signedTxCbor)) {
|
|
388
285
|
errors.push({
|
|
@@ -435,7 +332,6 @@ function validateTransactionInputs(inputs, requiredFields) {
|
|
|
435
332
|
});
|
|
436
333
|
}
|
|
437
334
|
}
|
|
438
|
-
// Validate JSON fields with size and complexity limits
|
|
439
335
|
if (inputs.metadataJson) {
|
|
440
336
|
const result = validateJsonWithLimits(inputs.metadataJson, 'metadataJson');
|
|
441
337
|
if (!result.valid) {
|
|
@@ -503,10 +399,7 @@ function validateTransactionInputs(inputs, requiredFields) {
|
|
|
503
399
|
}
|
|
504
400
|
return errors;
|
|
505
401
|
}
|
|
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
|
-
*/
|
|
402
|
+
/** Posix-ms string field: non-negative integer with at most MAX_POSIX_MS_DIGITS digits; null when valid or absent. */
|
|
510
403
|
function validatePosixMsField(value, field) {
|
|
511
404
|
if (value === undefined || value === null || value === '')
|
|
512
405
|
return null;
|