@odatano/core 2.0.0-rc.24 → 2.0.0-rc.26
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/CardanoIndexerService/index.d.ts +37 -0
- package/@cds-models/CardanoIndexerService/index.js +4 -0
- package/@cds-models/CardanoODataService/index.d.ts +27 -2
- package/@cds-models/CardanoODataService/index.js +3 -0
- package/@cds-models/CardanoSignService/index.d.ts +23 -1
- package/@cds-models/CardanoSignService/index.js +3 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +34 -1
- package/@cds-models/CardanoTransactionService/index.js +4 -0
- package/@cds-models/index.d.ts +18 -0
- package/@cds-models/index.js +3 -0
- package/@cds-models/odatano/cardano/index.d.ts +49 -2
- package/@cds-models/odatano/cardano/index.js +6 -0
- package/README.md +195 -195
- package/db/schema.cds +74 -3
- package/db/types.cds +27 -0
- package/package.json +182 -182
- package/srv/blockchain/backends/blockfrost-backend.js +4 -2
- package/srv/blockchain/backends/cardano-backend.d.ts +0 -2
- package/srv/blockchain/backends/koios-backend.d.ts +1 -1
- package/srv/blockchain/backends/koios-backend.js +61 -14
- package/srv/blockchain/backends/odatano-backend.d.ts +5 -0
- package/srv/blockchain/backends/odatano-backend.js +12 -0
- package/srv/blockchain/backends/ogmios-backend.d.ts +12 -2
- package/srv/blockchain/backends/ogmios-backend.js +91 -21
- package/srv/blockchain/cardano-client.d.ts +11 -5
- package/srv/blockchain/cardano-client.js +51 -16
- package/srv/blockchain/cardano-indexer.d.ts +43 -15
- package/srv/blockchain/cardano-indexer.js +177 -68
- package/srv/blockchain/cardano-tx-builder.d.ts +11 -1
- package/srv/blockchain/cardano-tx-builder.js +57 -2
- package/srv/blockchain/crawler/certificate-backfill.d.ts +22 -0
- package/srv/blockchain/crawler/certificate-backfill.js +49 -30
- package/srv/blockchain/crawler/crawler.d.ts +3 -1
- package/srv/blockchain/crawler/crawler.js +12 -7
- package/srv/blockchain/crawler/sync-state.d.ts +3 -1
- package/srv/blockchain/crawler/sync-state.js +15 -2
- package/srv/blockchain/crawler/transaction-backfill.d.ts +52 -0
- package/srv/blockchain/crawler/transaction-backfill.js +283 -0
- package/srv/blockchain/crawler/utxo-set-import.d.ts +9 -0
- package/srv/blockchain/crawler/utxo-set-import.js +138 -47
- package/srv/blockchain/ledger-state.d.ts +16 -1
- package/srv/blockchain/ledger-state.js +38 -18
- package/srv/blockchain/pending-spends.d.ts +28 -0
- package/srv/blockchain/pending-spends.js +89 -0
- package/srv/blockchain/stored-chain.d.ts +5 -2
- package/srv/blockchain/stored-chain.js +31 -5
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +12 -3
- package/srv/blockchain/transaction-building/buildooor-tx.js +203 -21
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +2 -1
- package/srv/blockchain/transaction-rows.d.ts +1 -1
- package/srv/blockchain/transaction-rows.js +2 -1
- package/srv/blockchain/wallet-worker/build-request.js +1 -1
- package/srv/cardano-backend-service.js +35 -8
- package/srv/cardano-indexer-service.cds +201 -176
- package/srv/cardano-indexer-service.js +104 -10
- package/srv/cardano-service.cds +5 -0
- package/srv/cardano-service.js +3 -1
- package/srv/cardano-tx-service.cds +39 -0
- package/srv/cardano-tx-service.js +88 -14
- package/srv/server.js +4 -1
- package/srv/utils/agent-grants.js +1 -0
- package/srv/utils/const.d.ts +5 -0
- package/srv/utils/const.js +6 -1
- package/srv/utils/error-codes.d.ts +2 -0
- package/srv/utils/error-codes.js +2 -0
- package/srv/utils/errors.d.ts +7 -0
- package/srv/utils/errors.js +11 -1
- package/srv/utils/mappers.d.ts +24 -2
- package/srv/utils/mappers.js +49 -0
- package/srv/utils/pg-inline-json.d.ts +8 -0
- package/srv/utils/pg-inline-json.js +63 -0
- package/srv/utils/tx-build-helper.d.ts +2 -0
- package/srv/utils/tx-build-helper.js +12 -0
- package/srv/utils/tx-request-parsers.d.ts +46 -5
- package/srv/utils/tx-request-parsers.js +227 -16
- package/srv/utils/types.d.ts +59 -0
- package/srv/utils/validators.d.ts +5 -1
- package/srv/utils/validators.js +19 -9
|
@@ -1,16 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MAX_EXTRA_OUTPUTS = void 0;
|
|
3
|
+
exports.MAX_SCRIPT_INPUTS = exports.MAX_EXTRA_OUTPUTS = void 0;
|
|
4
4
|
exports.parseUtxoRefArray = parseUtxoRefArray;
|
|
5
5
|
exports.parseRequiredSigners = parseRequiredSigners;
|
|
6
6
|
exports.parseAssetsArray = parseAssetsArray;
|
|
7
7
|
exports.parseExtraOutputs = parseExtraOutputs;
|
|
8
|
+
exports.parseOutputList = parseOutputList;
|
|
8
9
|
exports.parseMintActionPolicyFields = parseMintActionPolicyFields;
|
|
10
|
+
exports.parseScriptInputs = parseScriptInputs;
|
|
11
|
+
exports.parsePolicyMintActions = parsePolicyMintActions;
|
|
9
12
|
const validators_1 = require("./validators");
|
|
13
|
+
const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
14
|
+
const plutus_data_1 = require("@harmoniclabs/plutus-data");
|
|
15
|
+
const const_1 = require("./const");
|
|
10
16
|
/**
|
|
11
17
|
* Shared parsers for the Build*-action JSON payload fields (transaction service and wallet worker).
|
|
12
18
|
* Result contract: `{ parsed }` on success (undefined for absent/empty input) or `{ error }` with a client message.
|
|
13
19
|
*/
|
|
20
|
+
/** PlutusData as CBOR hex, checked to decode; `field` names it in the error. */
|
|
21
|
+
function parsePlutusCbor(value, field) {
|
|
22
|
+
if (typeof value !== 'string' || !(0, validators_1.isValidCbor)(value))
|
|
23
|
+
return { error: `${field} must be even-length CBOR hex` };
|
|
24
|
+
try {
|
|
25
|
+
(0, plutus_data_1.dataFromCbor)(value);
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
return { error: `${field} is not PlutusData CBOR: ${err instanceof Error ? err.message : String(err)}` };
|
|
29
|
+
}
|
|
30
|
+
return { hex: value.toLowerCase() };
|
|
31
|
+
}
|
|
14
32
|
function parseUtxoRefArray(json, fieldName) {
|
|
15
33
|
if (!json)
|
|
16
34
|
return { parsed: undefined };
|
|
@@ -82,46 +100,54 @@ function parseAssetsArray(assetsJson, fieldName) {
|
|
|
82
100
|
exports.MAX_EXTRA_OUTPUTS = 32;
|
|
83
101
|
/** Parse and validate extraOutputsJson (undefined for an empty array). */
|
|
84
102
|
function parseExtraOutputs(extraOutputsJson) {
|
|
85
|
-
|
|
103
|
+
return parseOutputList(extraOutputsJson, 'extraOutputsJson');
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Parse an output list. `outputsJson` (BuildPlutusTransaction) additionally accepts `datumHash`;
|
|
107
|
+
* the entries keep their order, each is min-ADA checked by the builder.
|
|
108
|
+
*/
|
|
109
|
+
function parseOutputList(json, fieldName) {
|
|
110
|
+
if (!json)
|
|
86
111
|
return { parsed: undefined };
|
|
87
|
-
const
|
|
112
|
+
const name = fieldName.replace(/Json$/, '');
|
|
113
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(json, fieldName);
|
|
88
114
|
if (!jsonResult.valid)
|
|
89
115
|
return { error: jsonResult.error };
|
|
90
116
|
if (!Array.isArray(jsonResult.parsed))
|
|
91
|
-
return { error:
|
|
117
|
+
return { error: `${fieldName} must be a JSON array` };
|
|
92
118
|
if (jsonResult.parsed.length === 0)
|
|
93
119
|
return { parsed: undefined };
|
|
94
120
|
if (jsonResult.parsed.length > exports.MAX_EXTRA_OUTPUTS) {
|
|
95
|
-
return { error:
|
|
121
|
+
return { error: `${fieldName} exceeds maximum of ${exports.MAX_EXTRA_OUTPUTS} entries` };
|
|
96
122
|
}
|
|
97
123
|
const out = [];
|
|
98
124
|
for (let i = 0; i < jsonResult.parsed.length; i++) {
|
|
99
125
|
const entry = jsonResult.parsed[i];
|
|
100
126
|
if (!entry || typeof entry !== 'object') {
|
|
101
|
-
return { error:
|
|
127
|
+
return { error: `${name}[${i}] must be an object` };
|
|
102
128
|
}
|
|
103
129
|
if (typeof entry.address !== 'string' || !(0, validators_1.isValidBech32Address)(entry.address)) {
|
|
104
|
-
return { error:
|
|
130
|
+
return { error: `${name}[${i}].address is not a valid Bech32 address` };
|
|
105
131
|
}
|
|
106
132
|
if (typeof entry.lovelaceAmount !== 'string' || !/^\d+$/.test(entry.lovelaceAmount) || entry.lovelaceAmount === '0') {
|
|
107
|
-
return { error:
|
|
133
|
+
return { error: `${name}[${i}].lovelaceAmount must be a positive integer string` };
|
|
108
134
|
}
|
|
109
135
|
let assets;
|
|
110
136
|
if (entry.assets !== undefined && entry.assets !== null) {
|
|
111
137
|
if (!Array.isArray(entry.assets)) {
|
|
112
|
-
return { error:
|
|
138
|
+
return { error: `${name}[${i}].assets must be an array` };
|
|
113
139
|
}
|
|
114
140
|
assets = [];
|
|
115
141
|
for (let j = 0; j < entry.assets.length; j++) {
|
|
116
142
|
const a = entry.assets[j];
|
|
117
143
|
if (!a || typeof a !== 'object') {
|
|
118
|
-
return { error:
|
|
144
|
+
return { error: `${name}[${i}].assets[${j}] must be an object` };
|
|
119
145
|
}
|
|
120
146
|
if (typeof a.unit !== 'string' || a.unit.toLowerCase() === 'lovelace' || !(0, validators_1.isAssetUnit)(a.unit)) {
|
|
121
|
-
return { error:
|
|
147
|
+
return { error: `${name}[${i}].assets[${j}].unit must be a valid asset unit (policyId + assetName hex)` };
|
|
122
148
|
}
|
|
123
149
|
if (typeof a.quantity !== 'string' || !/^\d+$/.test(a.quantity) || a.quantity === '0') {
|
|
124
|
-
return { error:
|
|
150
|
+
return { error: `${name}[${i}].assets[${j}].quantity must be a positive integer string` };
|
|
125
151
|
}
|
|
126
152
|
assets.push({ unit: a.unit, quantity: a.quantity });
|
|
127
153
|
}
|
|
@@ -129,17 +155,39 @@ function parseExtraOutputs(extraOutputsJson) {
|
|
|
129
155
|
let inlineDatum;
|
|
130
156
|
if (entry.inlineDatumJson !== undefined && entry.inlineDatumJson !== null) {
|
|
131
157
|
if (typeof entry.inlineDatumJson !== 'string') {
|
|
132
|
-
return { error:
|
|
158
|
+
return { error: `${name}[${i}].inlineDatumJson must be a JSON string` };
|
|
133
159
|
}
|
|
134
|
-
const datumResult = (0, validators_1.
|
|
160
|
+
const datumResult = (0, validators_1.validatePlutusJson)(entry.inlineDatumJson, `${name}[${i}].inlineDatumJson`);
|
|
135
161
|
if (!datumResult.valid)
|
|
136
162
|
return { error: datumResult.error };
|
|
137
163
|
inlineDatum = datumResult.parsed;
|
|
138
164
|
}
|
|
165
|
+
let inlineDatumCbor;
|
|
166
|
+
if (entry.inlineDatumCbor !== undefined && entry.inlineDatumCbor !== null) {
|
|
167
|
+
if (fieldName !== 'outputsJson')
|
|
168
|
+
return { error: `${name}[${i}].inlineDatumCbor is only supported in outputsJson` };
|
|
169
|
+
if (inlineDatum !== undefined)
|
|
170
|
+
return { error: `${name}[${i}] takes inlineDatumJson or inlineDatumCbor, not both` };
|
|
171
|
+
const cbor = parsePlutusCbor(entry.inlineDatumCbor, `${name}[${i}].inlineDatumCbor`);
|
|
172
|
+
if (cbor.error)
|
|
173
|
+
return { error: cbor.error };
|
|
174
|
+
inlineDatumCbor = cbor.hex;
|
|
175
|
+
}
|
|
176
|
+
let datumHash;
|
|
177
|
+
if (entry.datumHash !== undefined && entry.datumHash !== null) {
|
|
178
|
+
if (fieldName !== 'outputsJson')
|
|
179
|
+
return { error: `${name}[${i}].datumHash is only supported in outputsJson` };
|
|
180
|
+
if (typeof entry.datumHash !== 'string' || !/^[0-9a-fA-F]{64}$/.test(entry.datumHash)) {
|
|
181
|
+
return { error: `${name}[${i}].datumHash must be 64 hex chars` };
|
|
182
|
+
}
|
|
183
|
+
if (inlineDatum !== undefined || inlineDatumCbor !== undefined)
|
|
184
|
+
return { error: `${name}[${i}] takes an inline datum or datumHash, not both` };
|
|
185
|
+
datumHash = entry.datumHash.toLowerCase();
|
|
186
|
+
}
|
|
139
187
|
let referenceScript;
|
|
140
188
|
if (entry.referenceScriptHex !== undefined && entry.referenceScriptHex !== null) {
|
|
141
189
|
if (typeof entry.referenceScriptHex !== 'string' || !(0, validators_1.isValidCbor)(entry.referenceScriptHex)) {
|
|
142
|
-
return { error:
|
|
190
|
+
return { error: `${name}[${i}].referenceScriptHex must be even-length hex` };
|
|
143
191
|
}
|
|
144
192
|
referenceScript = entry.referenceScriptHex;
|
|
145
193
|
}
|
|
@@ -148,6 +196,8 @@ function parseExtraOutputs(extraOutputsJson) {
|
|
|
148
196
|
lovelaceAmount: entry.lovelaceAmount,
|
|
149
197
|
assets,
|
|
150
198
|
inlineDatum,
|
|
199
|
+
...(datumHash ? { datumHash } : {}),
|
|
200
|
+
...(inlineDatumCbor ? { inlineDatumCbor } : {}),
|
|
151
201
|
referenceScript,
|
|
152
202
|
});
|
|
153
203
|
}
|
|
@@ -170,7 +220,7 @@ function parseMintActionPolicyFields(entry, i) {
|
|
|
170
220
|
if (typeof entry.redeemerJson !== 'string') {
|
|
171
221
|
return { error: `mintActions[${i}].redeemerJson must be a JSON string` };
|
|
172
222
|
}
|
|
173
|
-
const jsonResult = (0, validators_1.
|
|
223
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(entry.redeemerJson, `mintActions[${i}].redeemerJson`);
|
|
174
224
|
if (!jsonResult.valid)
|
|
175
225
|
return { error: jsonResult.error };
|
|
176
226
|
redeemer = jsonResult.parsed;
|
|
@@ -180,4 +230,165 @@ function parseMintActionPolicyFields(entry, i) {
|
|
|
180
230
|
}
|
|
181
231
|
return { script, redeemer };
|
|
182
232
|
}
|
|
233
|
+
/** Upper bound on script inputs per BuildPlutusTransaction. */
|
|
234
|
+
exports.MAX_SCRIPT_INPUTS = 16;
|
|
235
|
+
/** Parse and validate scriptInputsJson: 1..MAX_SCRIPT_INPUTS distinct script UTxOs, each with its own redeemer. */
|
|
236
|
+
function parseScriptInputs(json) {
|
|
237
|
+
if (!json)
|
|
238
|
+
return { error: 'scriptInputsJson is required' };
|
|
239
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(json, 'scriptInputsJson');
|
|
240
|
+
if (!jsonResult.valid)
|
|
241
|
+
return { error: jsonResult.error };
|
|
242
|
+
if (!Array.isArray(jsonResult.parsed) || jsonResult.parsed.length === 0) {
|
|
243
|
+
return { error: 'scriptInputsJson must be a non-empty JSON array' };
|
|
244
|
+
}
|
|
245
|
+
if (jsonResult.parsed.length > exports.MAX_SCRIPT_INPUTS) {
|
|
246
|
+
return { error: `scriptInputsJson exceeds maximum of ${exports.MAX_SCRIPT_INPUTS} entries` };
|
|
247
|
+
}
|
|
248
|
+
const parseJsonField = (value, field) => {
|
|
249
|
+
if (typeof value !== 'string')
|
|
250
|
+
return { error: `${field} must be a JSON string` };
|
|
251
|
+
const r = (0, validators_1.validatePlutusJson)(value, field);
|
|
252
|
+
return r.valid ? { parsed: r.parsed } : { error: r.error };
|
|
253
|
+
};
|
|
254
|
+
const out = [];
|
|
255
|
+
const seen = new Set();
|
|
256
|
+
for (let i = 0; i < jsonResult.parsed.length; i++) {
|
|
257
|
+
const entry = jsonResult.parsed[i];
|
|
258
|
+
const at = `scriptInputs[${i}]`;
|
|
259
|
+
if (!entry || typeof entry !== 'object')
|
|
260
|
+
return { error: `${at} must be an object` };
|
|
261
|
+
if (typeof entry.txHash !== 'string' || !(0, validators_1.isTxHash)(entry.txHash))
|
|
262
|
+
return { error: `${at}.txHash must be 64 hex chars` };
|
|
263
|
+
const idx = entry.outputIndex;
|
|
264
|
+
if (typeof idx !== 'number' || !Number.isInteger(idx) || idx < 0)
|
|
265
|
+
return { error: `${at}.outputIndex must be a non-negative integer` };
|
|
266
|
+
const key = `${entry.txHash.toLowerCase()}#${idx}`;
|
|
267
|
+
if (seen.has(key))
|
|
268
|
+
return { error: `${at} spends ${key} a second time` };
|
|
269
|
+
seen.add(key);
|
|
270
|
+
const hasInline = entry.validatorScript !== undefined && entry.validatorScript !== null;
|
|
271
|
+
const hasRef = entry.referenceScript !== undefined && entry.referenceScript !== null;
|
|
272
|
+
if (hasInline === hasRef)
|
|
273
|
+
return { error: `${at} needs exactly one of validatorScript or referenceScript` };
|
|
274
|
+
const input = { txHash: entry.txHash.toLowerCase(), outputIndex: idx, redeemer: null };
|
|
275
|
+
if (hasInline) {
|
|
276
|
+
if (typeof entry.validatorScript !== 'string' || !(0, validators_1.isValidCbor)(entry.validatorScript)) {
|
|
277
|
+
return { error: `${at}.validatorScript must be even-length CBOR hex` };
|
|
278
|
+
}
|
|
279
|
+
input.validatorScript = entry.validatorScript;
|
|
280
|
+
if (entry.scriptParamsJson !== undefined && entry.scriptParamsJson !== null) {
|
|
281
|
+
const params = parseJsonField(entry.scriptParamsJson, `${at}.scriptParamsJson`);
|
|
282
|
+
if (params.error)
|
|
283
|
+
return { error: params.error };
|
|
284
|
+
if (!Array.isArray(params.parsed))
|
|
285
|
+
return { error: `${at}.scriptParamsJson must be a JSON array` };
|
|
286
|
+
if (params.parsed.length > 0)
|
|
287
|
+
input.scriptParams = params.parsed;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
const ref = entry.referenceScript;
|
|
292
|
+
if (!ref || typeof ref !== 'object' || typeof ref.txHash !== 'string' || !(0, validators_1.isTxHash)(ref.txHash)
|
|
293
|
+
|| typeof ref.outputIndex !== 'number' || !Number.isInteger(ref.outputIndex) || ref.outputIndex < 0) {
|
|
294
|
+
return { error: `${at}.referenceScript must be {txHash, outputIndex} of the UTxO carrying the script` };
|
|
295
|
+
}
|
|
296
|
+
if (entry.scriptParamsJson !== undefined && entry.scriptParamsJson !== null) {
|
|
297
|
+
return { error: `${at}.scriptParamsJson applies to an inline validatorScript only` };
|
|
298
|
+
}
|
|
299
|
+
input.referenceScript = { txHash: ref.txHash.toLowerCase(), outputIndex: ref.outputIndex };
|
|
300
|
+
}
|
|
301
|
+
const hasRedeemerJson = entry.redeemerJson !== undefined && entry.redeemerJson !== null;
|
|
302
|
+
const hasRedeemerCbor = entry.redeemerCbor !== undefined && entry.redeemerCbor !== null;
|
|
303
|
+
if (hasRedeemerJson === hasRedeemerCbor)
|
|
304
|
+
return { error: `${at} needs exactly one of redeemerJson or redeemerCbor` };
|
|
305
|
+
if (hasRedeemerCbor) {
|
|
306
|
+
const cbor = parsePlutusCbor(entry.redeemerCbor, `${at}.redeemerCbor`);
|
|
307
|
+
if (cbor.error)
|
|
308
|
+
return { error: cbor.error };
|
|
309
|
+
input.redeemerCbor = cbor.hex;
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
const redeemer = parseJsonField(entry.redeemerJson, `${at}.redeemerJson`);
|
|
313
|
+
if (redeemer.error)
|
|
314
|
+
return { error: redeemer.error };
|
|
315
|
+
input.redeemer = redeemer.parsed;
|
|
316
|
+
}
|
|
317
|
+
const hasDatumJson = entry.datumJson !== undefined && entry.datumJson !== null;
|
|
318
|
+
const hasDatumCbor = entry.datumCbor !== undefined && entry.datumCbor !== null;
|
|
319
|
+
if (hasDatumJson && hasDatumCbor)
|
|
320
|
+
return { error: `${at} takes datumJson or datumCbor, not both` };
|
|
321
|
+
if (hasDatumCbor) {
|
|
322
|
+
const cbor = parsePlutusCbor(entry.datumCbor, `${at}.datumCbor`);
|
|
323
|
+
if (cbor.error)
|
|
324
|
+
return { error: cbor.error };
|
|
325
|
+
input.datumCbor = cbor.hex;
|
|
326
|
+
}
|
|
327
|
+
else if (hasDatumJson) {
|
|
328
|
+
const datum = parseJsonField(entry.datumJson, `${at}.datumJson`);
|
|
329
|
+
if (datum.error)
|
|
330
|
+
return { error: datum.error };
|
|
331
|
+
input.datum = datum.parsed;
|
|
332
|
+
}
|
|
333
|
+
out.push(input);
|
|
334
|
+
}
|
|
335
|
+
return { parsed: out };
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Parse mintActionsJson for BuildPlutusTransaction: every action carries its own `mintingPolicyScript`
|
|
339
|
+
* (no request-level default) and optional `redeemerJson`; `assetUnit` is policyId+assetName, or a bare
|
|
340
|
+
* assetName that is prefixed with the policy id of the action's script.
|
|
341
|
+
*/
|
|
342
|
+
function parsePolicyMintActions(json) {
|
|
343
|
+
if (!json)
|
|
344
|
+
return { parsed: undefined };
|
|
345
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(json, 'mintActionsJson');
|
|
346
|
+
if (!jsonResult.valid)
|
|
347
|
+
return { error: jsonResult.error };
|
|
348
|
+
if (!Array.isArray(jsonResult.parsed))
|
|
349
|
+
return { error: 'mintActionsJson must be a JSON array' };
|
|
350
|
+
if (jsonResult.parsed.length === 0)
|
|
351
|
+
return { parsed: undefined };
|
|
352
|
+
const out = [];
|
|
353
|
+
for (let i = 0; i < jsonResult.parsed.length; i++) {
|
|
354
|
+
const entry = jsonResult.parsed[i];
|
|
355
|
+
if (!entry || typeof entry !== 'object')
|
|
356
|
+
return { error: `mintActions[${i}] must be an object` };
|
|
357
|
+
if (typeof entry.quantity !== 'string' || !/^-?\d+$/.test(entry.quantity) || BigInt(entry.quantity) === 0n) {
|
|
358
|
+
return { error: `mintActions[${i}].quantity must be a non-zero integer string` };
|
|
359
|
+
}
|
|
360
|
+
if (entry.mintingPolicyScript === undefined || entry.mintingPolicyScript === null) {
|
|
361
|
+
return { error: `mintActions[${i}].mintingPolicyScript is required` };
|
|
362
|
+
}
|
|
363
|
+
const policy = parseMintActionPolicyFields(entry, i);
|
|
364
|
+
if (policy.error)
|
|
365
|
+
return { error: policy.error };
|
|
366
|
+
let policyId;
|
|
367
|
+
try {
|
|
368
|
+
policyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(policy.script, 'hex')).hash.toString();
|
|
369
|
+
}
|
|
370
|
+
catch (err) {
|
|
371
|
+
return { error: `mintActions[${i}].mintingPolicyScript is not a valid Plutus script: ${err instanceof Error ? err.message : String(err)}` };
|
|
372
|
+
}
|
|
373
|
+
if (typeof entry.assetUnit !== 'string' || !/^[0-9a-fA-F]*$/.test(entry.assetUnit) || entry.assetUnit.length % 2 !== 0) {
|
|
374
|
+
return { error: `mintActions[${i}].assetUnit must be hex (policyId+assetName, or a bare assetName)` };
|
|
375
|
+
}
|
|
376
|
+
let assetUnit = entry.assetUnit.toLowerCase();
|
|
377
|
+
if (assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
378
|
+
assetUnit = policyId + assetUnit;
|
|
379
|
+
}
|
|
380
|
+
else if (!assetUnit.startsWith(policyId)) {
|
|
381
|
+
return { error: `mintActions[${i}].assetUnit does not start with its policy id ${policyId}` };
|
|
382
|
+
}
|
|
383
|
+
if (!(0, validators_1.isAssetUnit)(assetUnit))
|
|
384
|
+
return { error: `mintActions[${i}].assetUnit is not a valid asset unit` };
|
|
385
|
+
out.push({
|
|
386
|
+
assetUnit,
|
|
387
|
+
quantity: BigInt(entry.quantity),
|
|
388
|
+
mintingPolicyScript: policy.script,
|
|
389
|
+
...(policy.redeemer !== undefined ? { redeemerJson: policy.redeemer } : {}),
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
return { parsed: out };
|
|
393
|
+
}
|
|
183
394
|
//# sourceMappingURL=tx-request-parsers.js.map
|
package/srv/utils/types.d.ts
CHANGED
|
@@ -62,6 +62,22 @@ export interface TxWithdrawal {
|
|
|
62
62
|
/** Lovelace as string. */
|
|
63
63
|
amount: Lovelace | string;
|
|
64
64
|
}
|
|
65
|
+
/** One redeemer of a transaction. */
|
|
66
|
+
export interface TxRedeemer {
|
|
67
|
+
/** spend | mint | publish | withdraw | vote | propose */
|
|
68
|
+
purpose: string;
|
|
69
|
+
/** Index within its purpose, as the ledger counts it. */
|
|
70
|
+
index: number;
|
|
71
|
+
/** PlutusData CBOR hex. */
|
|
72
|
+
data: string;
|
|
73
|
+
mem: string;
|
|
74
|
+
steps: string;
|
|
75
|
+
/** spend: the redeemed input. */
|
|
76
|
+
txHash?: Hex | null;
|
|
77
|
+
outputIndex?: number | null;
|
|
78
|
+
/** mint: the policy. */
|
|
79
|
+
policyId?: Hex | null;
|
|
80
|
+
}
|
|
65
81
|
/** Normalized transaction */
|
|
66
82
|
export interface Transaction {
|
|
67
83
|
hash: Hex;
|
|
@@ -98,6 +114,8 @@ export interface Transaction {
|
|
|
98
114
|
certificates?: TxCertificate[];
|
|
99
115
|
/** Reward-account withdrawals; same `[]` vs undefined convention as `certificates`. */
|
|
100
116
|
withdrawals?: TxWithdrawal[];
|
|
117
|
+
/** Redeemers; `[]` when the tx has none, undefined when the source does not report them (Blockfrost, Koios). */
|
|
118
|
+
redeemers?: TxRedeemer[];
|
|
101
119
|
}
|
|
102
120
|
/** Address view with current value and known UTxOs */
|
|
103
121
|
export interface Address {
|
|
@@ -118,6 +136,8 @@ export interface UTxO {
|
|
|
118
136
|
blockHash?: Hex;
|
|
119
137
|
datumHash?: Hex | null;
|
|
120
138
|
scriptRef?: Hex | null;
|
|
139
|
+
/** Full CBOR of the reference script (Plutus) when the source delivers it; builder use only. */
|
|
140
|
+
scriptRefCbor?: Hex | null;
|
|
121
141
|
inlineDatum?: string | null;
|
|
122
142
|
}
|
|
123
143
|
/** Basic block information */
|
|
@@ -390,6 +410,38 @@ export type TxBuildMintRequest = TxBuildRequest & {
|
|
|
390
410
|
export type TxBuildPlutusSpendRequest = TxBuildRequest & {
|
|
391
411
|
plutusScriptExecution: PlutusScriptExecution;
|
|
392
412
|
};
|
|
413
|
+
/** One script UTxO spent by a BuildPlutusTransaction: an inline validator or a UTxO carrying the script. */
|
|
414
|
+
export type ScriptInput = {
|
|
415
|
+
txHash: string;
|
|
416
|
+
outputIndex: number;
|
|
417
|
+
/** Validator CBOR hex (script params already applied); exclusive with referenceScript. */
|
|
418
|
+
validatorScript?: string;
|
|
419
|
+
/** UTxO that carries the validator as reference script; added as reference input. */
|
|
420
|
+
referenceScript?: {
|
|
421
|
+
txHash: string;
|
|
422
|
+
outputIndex: number;
|
|
423
|
+
};
|
|
424
|
+
/** Redeemer (PlutusData JSON); `__INPUT_IDX__` placeholders resolve against the final inputs. */
|
|
425
|
+
redeemer: JSONValue;
|
|
426
|
+
/** Redeemer as PlutusData CBOR hex; wins over `redeemer`, no placeholders. */
|
|
427
|
+
redeemerCbor?: string;
|
|
428
|
+
/** Datum preimage (PlutusData JSON) for a hash-datum UTxO; inline datums are read from the UTxO. */
|
|
429
|
+
datum?: JSONValue;
|
|
430
|
+
/** Datum preimage as PlutusData CBOR hex; wins over `datum`. */
|
|
431
|
+
datumCbor?: string;
|
|
432
|
+
};
|
|
433
|
+
/** Output of a BuildPlutusTransaction, kept in the given order. */
|
|
434
|
+
export type PlutusTxOutput = NonNullable<TxBuildRequest['extraOutputs']>[number] & {
|
|
435
|
+
/** Datum hash to lock the output with (hex); exclusive with inlineDatum. */
|
|
436
|
+
datumHash?: string;
|
|
437
|
+
/** Inline datum as PlutusData CBOR hex, taken byte for byte; exclusive with inlineDatum. */
|
|
438
|
+
inlineDatumCbor?: string;
|
|
439
|
+
};
|
|
440
|
+
/** BuildPlutusTransaction: several script inputs, the outputs as given, change after them. */
|
|
441
|
+
export type TxBuildPlutusRequest = Pick<TxBuildRequest, 'network' | 'senderAddress' | 'changeAddress' | 'requiredSigners' | 'forceInputs' | 'referenceInputs' | 'mintActions' | 'validityStartMs' | 'validityEndMs'> & {
|
|
442
|
+
scriptInputs: ScriptInput[];
|
|
443
|
+
outputs: PlutusTxOutput[];
|
|
444
|
+
};
|
|
393
445
|
/** Execution budget for Plutus scripts */
|
|
394
446
|
export type ExecutionBudget = {
|
|
395
447
|
memory: number;
|
|
@@ -449,6 +501,13 @@ export type TxBuildResult = {
|
|
|
449
501
|
forcedInputsUsed?: number;
|
|
450
502
|
/** Number of CIP-31 reference inputs included in the built transaction (0 if referenceInputs was not used). */
|
|
451
503
|
referenceInputsUsed?: number;
|
|
504
|
+
/** Execution units stamped on each redeemer (script builds). */
|
|
505
|
+
redeemers?: Array<{
|
|
506
|
+
tag: string;
|
|
507
|
+
index: number;
|
|
508
|
+
mem: string;
|
|
509
|
+
steps: string;
|
|
510
|
+
}>;
|
|
452
511
|
};
|
|
453
512
|
/** Supported external signer types */
|
|
454
513
|
export declare enum ExternalSignerType {
|
|
@@ -5,7 +5,11 @@ interface JsonValidationResult {
|
|
|
5
5
|
parsed?: unknown;
|
|
6
6
|
}
|
|
7
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): JsonValidationResult;
|
|
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>;
|
|
9
13
|
/** Transaction hash: 64-character hex string */
|
|
10
14
|
export declare function isTxHash(s: unknown): s is string;
|
|
11
15
|
/** Asset unit: policy ID (56 hex chars) + asset name (0-64 hex chars, even length) */
|
package/srv/utils/validators.js
CHANGED
|
@@ -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;
|
|
@@ -44,7 +46,7 @@ function wordsToBytesLen(words) {
|
|
|
44
46
|
return Buffer.from(bech32_1.bech32.fromWords(words)).length;
|
|
45
47
|
}
|
|
46
48
|
/** Parse a JSON string under size and complexity limits (DoS prevention); `fieldName` is for messages. */
|
|
47
|
-
function validateJsonWithLimits(jsonString, fieldName) {
|
|
49
|
+
function validateJsonWithLimits(jsonString, fieldName, maxDepth = const_1.MAX_DEPTH) {
|
|
48
50
|
// Size limit before parsing
|
|
49
51
|
if (jsonString.length > const_1.MAX_JSON_SIZE) {
|
|
50
52
|
return { valid: false, error: `${fieldName} exceeds maximum size of ${const_1.MAX_JSON_SIZE} bytes` };
|
|
@@ -56,16 +58,24 @@ function validateJsonWithLimits(jsonString, fieldName) {
|
|
|
56
58
|
catch {
|
|
57
59
|
return { valid: false, error: `Invalid JSON in ${fieldName}` };
|
|
58
60
|
}
|
|
59
|
-
const complexityError = checkJsonComplexity(parsed, 0);
|
|
61
|
+
const complexityError = checkJsonComplexity(parsed, 0, maxDepth);
|
|
60
62
|
if (complexityError) {
|
|
61
63
|
return { valid: false, error: `${fieldName}: ${complexityError}` };
|
|
62
64
|
}
|
|
63
65
|
return { valid: true, parsed };
|
|
64
66
|
}
|
|
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
|
+
]);
|
|
65
75
|
/** Recursive complexity check (depth, keys, array length, string length); error message or null. */
|
|
66
|
-
function checkJsonComplexity(value, depth) {
|
|
67
|
-
if (depth >
|
|
68
|
-
return `Maximum nesting depth of ${
|
|
76
|
+
function checkJsonComplexity(value, depth, maxDepth) {
|
|
77
|
+
if (depth > maxDepth) {
|
|
78
|
+
return `Maximum nesting depth of ${maxDepth} exceeded`;
|
|
69
79
|
}
|
|
70
80
|
if (value === null || typeof value !== 'object') {
|
|
71
81
|
if (typeof value === 'string' && value.length > const_1.MAX_STRING_LENGTH) {
|
|
@@ -78,7 +88,7 @@ function checkJsonComplexity(value, depth) {
|
|
|
78
88
|
return `Array exceeds maximum length of ${const_1.MAX_ARRAY_LENGTH}`;
|
|
79
89
|
}
|
|
80
90
|
for (const item of value) {
|
|
81
|
-
const error = checkJsonComplexity(item, depth + 1);
|
|
91
|
+
const error = checkJsonComplexity(item, depth + 1, maxDepth);
|
|
82
92
|
if (error)
|
|
83
93
|
return error;
|
|
84
94
|
}
|
|
@@ -89,7 +99,7 @@ function checkJsonComplexity(value, depth) {
|
|
|
89
99
|
return `Object exceeds maximum key count of ${const_1.MAX_KEYS}`;
|
|
90
100
|
}
|
|
91
101
|
for (const key of keys) {
|
|
92
|
-
const error = checkJsonComplexity(value[key], depth + 1);
|
|
102
|
+
const error = checkJsonComplexity(value[key], depth + 1, maxDepth);
|
|
93
103
|
if (error)
|
|
94
104
|
return error;
|
|
95
105
|
}
|
|
@@ -363,7 +373,7 @@ function validateTransactionInputs(inputs, requiredFields) {
|
|
|
363
373
|
}
|
|
364
374
|
}
|
|
365
375
|
if (inputs.redeemerJson) {
|
|
366
|
-
const result =
|
|
376
|
+
const result = validatePlutusJson(inputs.redeemerJson, 'redeemerJson');
|
|
367
377
|
if (!result.valid) {
|
|
368
378
|
errors.push({
|
|
369
379
|
type: 'invalid',
|
|
@@ -373,7 +383,7 @@ function validateTransactionInputs(inputs, requiredFields) {
|
|
|
373
383
|
}
|
|
374
384
|
}
|
|
375
385
|
if (inputs.datumJson) {
|
|
376
|
-
const result =
|
|
386
|
+
const result = validatePlutusJson(inputs.datumJson, 'datumJson');
|
|
377
387
|
if (!result.valid) {
|
|
378
388
|
errors.push({
|
|
379
389
|
type: 'invalid',
|