@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
|
@@ -17,29 +17,19 @@ const tx_request_parsers_1 = require("./utils/tx-request-parsers");
|
|
|
17
17
|
const VALID_DERIVE_NETWORKS = ['mainnet', 'preview', 'preprod'];
|
|
18
18
|
const { SELECT, UPDATE } = cds_1.default.ql;
|
|
19
19
|
const logger = cds_1.default.log('CardanoTxService');
|
|
20
|
-
/**
|
|
21
|
-
* Cardano Transaction Service Implementation
|
|
22
|
-
* Handles transaction building and submission operations & some additional data queries.
|
|
23
|
-
*/
|
|
20
|
+
/** CardanoTransactionService handlers: transaction building, submission and script helpers. */
|
|
24
21
|
module.exports = (srv) => {
|
|
25
22
|
logger.debug('Module loaded - registering handlers');
|
|
26
23
|
const { TransactionBuilds, TransactionSubmissions, AddressTransactionBuilds } = require('#cds-models/CardanoTransactionService');
|
|
27
|
-
|
|
28
|
-
* Build a simple ADA-only transaction
|
|
29
|
-
* @param req - CDS request object (with senderAddress, recipientAddress, lovelaceAmount, changeAddress)
|
|
30
|
-
* @returns {TransactionBuild} Transaction build details
|
|
31
|
-
*/
|
|
24
|
+
// BuildSimpleAdaTransaction — ADA (optionally with assets / datum) to one recipient or a script.
|
|
32
25
|
srv.on('BuildSimpleAdaTransaction', async (req) => {
|
|
33
26
|
const { senderAddress, recipientAddress, lovelaceAmount, outputDatumJson, assetsJson, forceInputsJson, validatorScript, scriptParamsJson, lockOnScript, referenceScriptHex, validityStartMs, validityEndMs } = req.data;
|
|
34
|
-
// validate inputs
|
|
35
27
|
const errors = (0, validators_1.validateTransactionInputs)({ senderAddress, recipientAddress, lovelaceAmount, referenceScriptHex, validityStartMs, validityEndMs }, ['senderAddress', 'recipientAddress', 'lovelaceAmount']);
|
|
36
28
|
(0, errors_1.throwIfValidationErrors)(req, 'BuildSimpleAdaTransaction', errors);
|
|
37
29
|
if (req.data.changeAddress && !(0, validators_1.isValidBech32Address)(req.data.changeAddress)) {
|
|
38
30
|
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', 'Invalid changeAddress format', 'changeAddress');
|
|
39
31
|
}
|
|
40
|
-
// parse optional output datum
|
|
41
32
|
const cleanData = { ...req.data };
|
|
42
|
-
// parse optional forceInputsJson
|
|
43
33
|
const forceInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(forceInputsJson, 'forceInputsJson');
|
|
44
34
|
if (forceInputsResult.error)
|
|
45
35
|
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', forceInputsResult.error, 'forceInputsJson');
|
|
@@ -52,7 +42,7 @@ module.exports = (srv) => {
|
|
|
52
42
|
cleanData.outputDatum = jsonResult.parsed;
|
|
53
43
|
delete cleanData.outputDatumJson;
|
|
54
44
|
}
|
|
55
|
-
//
|
|
45
|
+
// Native assets to lock at a script address
|
|
56
46
|
const assetsResult = (0, tx_request_parsers_1.parseAssetsArray)(assetsJson, 'assetsJson');
|
|
57
47
|
if (assetsResult.error)
|
|
58
48
|
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', assetsResult.error, 'assetsJson');
|
|
@@ -60,7 +50,7 @@ module.exports = (srv) => {
|
|
|
60
50
|
cleanData.assets = assetsResult.parsed;
|
|
61
51
|
delete cleanData.assetsJson;
|
|
62
52
|
}
|
|
63
|
-
//
|
|
53
|
+
// Parameters for a parameterized validator
|
|
64
54
|
let scriptParams;
|
|
65
55
|
if (scriptParamsJson) {
|
|
66
56
|
const jsonResult = (0, validators_1.validateJsonWithLimits)(scriptParamsJson, 'scriptParamsJson');
|
|
@@ -71,11 +61,10 @@ module.exports = (srv) => {
|
|
|
71
61
|
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', 'scriptParamsJson must be a JSON array', 'scriptParamsJson');
|
|
72
62
|
}
|
|
73
63
|
}
|
|
74
|
-
// lockOnScript requires a validatorScript to derive the target address from
|
|
75
64
|
if (lockOnScript && !validatorScript) {
|
|
76
65
|
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', 'lockOnScript requires validatorScript to derive the script address', 'validatorScript');
|
|
77
66
|
}
|
|
78
|
-
//
|
|
67
|
+
// lockOnScript: derive script hash + address and override the recipient before the build.
|
|
79
68
|
let derivedScriptHash;
|
|
80
69
|
let derivedScriptAddress;
|
|
81
70
|
if (lockOnScript && validatorScript) {
|
|
@@ -99,11 +88,10 @@ module.exports = (srv) => {
|
|
|
99
88
|
cleanData.referenceScript = referenceScriptHex;
|
|
100
89
|
}
|
|
101
90
|
delete cleanData.referenceScriptHex;
|
|
102
|
-
// handle the request / building the transaction / indexing the build result / returning build details
|
|
103
91
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
104
92
|
logger.debug({ senderAddress, recipientAddress: cleanData.recipientAddress, lovelaceAmount, hasDatum: !!outputDatumJson, hasAssets: !!assetsJson, lockOnScript: !!lockOnScript }, 'Building simple ADA transaction');
|
|
105
93
|
const buildResult = await (0, server_1.getCardanoIndexer)().indexSimpleBuildResult(db, cleanData);
|
|
106
|
-
// Persist derived script address + hash on the build record
|
|
94
|
+
// Persist the derived script address + hash on the build record
|
|
107
95
|
if (lockOnScript && derivedScriptHash && derivedScriptAddress && buildResult.id) {
|
|
108
96
|
buildResult.scriptHash = derivedScriptHash;
|
|
109
97
|
buildResult.scriptAddress = derivedScriptAddress;
|
|
@@ -115,41 +103,29 @@ module.exports = (srv) => {
|
|
|
115
103
|
return buildResult;
|
|
116
104
|
});
|
|
117
105
|
});
|
|
118
|
-
|
|
119
|
-
* Build a transaction with metadata
|
|
120
|
-
* @param req - CDS request object (with senderAddress, recipientAddress, lovelaceAmount, metadataJson, changeAddress)
|
|
121
|
-
* @returns {TransactionBuild} Transaction build details
|
|
122
|
-
*/
|
|
106
|
+
// BuildTransactionWithMetadata — ADA transfer with auxiliary metadata.
|
|
123
107
|
srv.on('BuildTransactionWithMetadata', async (req) => {
|
|
124
108
|
const { senderAddress, recipientAddress, lovelaceAmount, metadataJson } = req.data;
|
|
125
|
-
// validate inputs (includes JSON parsing validation)
|
|
126
109
|
const errors = (0, validators_1.validateTransactionInputs)({ senderAddress, recipientAddress, lovelaceAmount, metadataJson }, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'metadataJson']);
|
|
127
110
|
(0, errors_1.throwIfValidationErrors)(req, 'BuildTransactionWithMetadata', errors);
|
|
128
111
|
if (req.data.changeAddress && !(0, validators_1.isValidBech32Address)(req.data.changeAddress)) {
|
|
129
112
|
return (0, errors_1.rejectInvalid)(req, 'BuildTransactionWithMetadata', 'Invalid changeAddress format', 'changeAddress');
|
|
130
113
|
}
|
|
131
|
-
//
|
|
114
|
+
// Already validated as JSON above
|
|
132
115
|
const parsedMetadata = JSON.parse(metadataJson);
|
|
133
|
-
// handle the request / building the transaction / indexing the build result / returning build details
|
|
134
116
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
135
117
|
logger.debug({ senderAddress, recipientAddress, lovelaceAmount, metadataKeyCount: Object.keys(parsedMetadata).length }, 'Building transaction with metadata');
|
|
136
118
|
return await (0, server_1.getCardanoIndexer)().indexMetadataBuildResult(db, { ...req.data, metadataJson: parsedMetadata });
|
|
137
119
|
});
|
|
138
120
|
});
|
|
139
|
-
|
|
140
|
-
* Build a multi-asset transaction
|
|
141
|
-
* @param req - CDS request object (with senderAddress, recipientAddress, lovelaceAmount, assetsJson, changeAddress)
|
|
142
|
-
* @returns {TransactionBuild} Transaction build details
|
|
143
|
-
*/
|
|
121
|
+
// BuildMultiAssetTransaction — ADA plus native assets to one recipient.
|
|
144
122
|
srv.on('BuildMultiAssetTransaction', async (req) => {
|
|
145
123
|
const { senderAddress, recipientAddress, lovelaceAmount, assetsJson, outputDatumJson, referenceScriptHex, validityStartMs, validityEndMs } = req.data;
|
|
146
|
-
// validate inputs (includes JSON parsing validation)
|
|
147
124
|
const errors = (0, validators_1.validateTransactionInputs)({ senderAddress, recipientAddress, lovelaceAmount, assetsJson, referenceScriptHex, validityStartMs, validityEndMs }, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'assetsJson']);
|
|
148
125
|
(0, errors_1.throwIfValidationErrors)(req, 'BuildMultiAssetTransaction', errors);
|
|
149
126
|
if (req.data.changeAddress && !(0, validators_1.isValidBech32Address)(req.data.changeAddress)) {
|
|
150
127
|
return (0, errors_1.rejectInvalid)(req, 'BuildMultiAssetTransaction', 'Invalid changeAddress format', 'changeAddress');
|
|
151
128
|
}
|
|
152
|
-
// Parse and validate assetsJson entries (unit + quantity, like parseExtraOutputs)
|
|
153
129
|
const assetsResult = (0, tx_request_parsers_1.parseAssetsArray)(assetsJson, 'assetsJson');
|
|
154
130
|
if (assetsResult.error)
|
|
155
131
|
return (0, errors_1.rejectInvalid)(req, 'BuildMultiAssetTransaction', assetsResult.error, 'assetsJson');
|
|
@@ -157,10 +133,8 @@ module.exports = (srv) => {
|
|
|
157
133
|
if (!parsedAssets || parsedAssets.length === 0) {
|
|
158
134
|
return (0, errors_1.rejectInvalid)(req, 'BuildMultiAssetTransaction', 'assetsJson must contain at least one asset', 'assetsJson');
|
|
159
135
|
}
|
|
160
|
-
// Validation BEFORE handleRequest (convention) — build the clean request object up front
|
|
161
136
|
const cleanData = { ...req.data };
|
|
162
137
|
delete cleanData.assetsJson;
|
|
163
|
-
// parse optional output datum (for locking assets at script addresses)
|
|
164
138
|
if (outputDatumJson) {
|
|
165
139
|
const jsonResult = (0, validators_1.validateJsonWithLimits)(outputDatumJson, 'outputDatumJson');
|
|
166
140
|
if (!jsonResult.valid)
|
|
@@ -172,7 +146,6 @@ module.exports = (srv) => {
|
|
|
172
146
|
cleanData.referenceScript = referenceScriptHex;
|
|
173
147
|
}
|
|
174
148
|
delete cleanData.referenceScriptHex;
|
|
175
|
-
// handle the request / building the transaction / indexing the build result / returning build details
|
|
176
149
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
177
150
|
logger.debug({ senderAddress, recipientAddress, lovelaceAmount, assets: parsedAssets, hasDatum: !!outputDatumJson }, 'Building multi-asset transaction');
|
|
178
151
|
const result = await (0, server_1.getCardanoIndexer)().indexMultiAssetBuildResult(db, { ...cleanData, assets: parsedAssets });
|
|
@@ -180,39 +153,54 @@ module.exports = (srv) => {
|
|
|
180
153
|
return result;
|
|
181
154
|
});
|
|
182
155
|
});
|
|
183
|
-
|
|
184
|
-
* Build a minting transaction
|
|
185
|
-
* @param req - CDS request object (with senderAddress, recipientAddress, lovelaceAmount, mintActionsJson, mintingPolicyScript, changeAddress)
|
|
186
|
-
* @returns {TransactionBuild} Transaction build details
|
|
187
|
-
*/
|
|
156
|
+
// BuildMintTransaction — mint/burn under one or more Plutus policies.
|
|
188
157
|
srv.on('BuildMintTransaction', async (req) => {
|
|
189
|
-
const { senderAddress, recipientAddress, lovelaceAmount, mintActionsJson, mintingPolicyScript, requiredSignersJson, scriptParamsJson, inlineDatumJson, mintRedeemerJson, lockOnScript, forceInputsJson, referenceInputsJson, referenceScriptHex, metadataJson, validityStartMs, validityEndMs } = req.data;
|
|
190
|
-
// validate inputs (includes JSON and CBOR validation)
|
|
158
|
+
const { senderAddress, recipientAddress, lovelaceAmount, mintActionsJson, mintingPolicyScript, requiredSignersJson, scriptParamsJson, inlineDatumJson, mintRedeemerJson, lockOnScript, forceInputsJson, referenceInputsJson, referenceScriptHex, extraOutputsJson, metadataJson, validityStartMs, validityEndMs } = req.data;
|
|
191
159
|
const errors = (0, validators_1.validateTransactionInputs)({ senderAddress, recipientAddress, lovelaceAmount, mintActionsJson, mintingPolicyScript, referenceScriptHex, metadataJson, validityStartMs, validityEndMs }, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'mintActionsJson', 'mintingPolicyScript']);
|
|
192
160
|
(0, errors_1.throwIfValidationErrors)(req, 'BuildMintTransaction', errors);
|
|
193
161
|
if (req.data.changeAddress && !(0, validators_1.isValidBech32Address)(req.data.changeAddress)) {
|
|
194
162
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'Invalid changeAddress format', 'changeAddress');
|
|
195
163
|
}
|
|
196
|
-
//
|
|
164
|
+
// Mint actions: quantities become bigint; bare asset names are expanded with the policy id.
|
|
197
165
|
const parsedMintActionsRaw = JSON.parse(mintActionsJson);
|
|
198
166
|
if (!Array.isArray(parsedMintActionsRaw)) {
|
|
199
167
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'mintActionsJson must be a JSON array', 'mintActionsJson');
|
|
200
168
|
}
|
|
201
|
-
const parsedMintActions = parsedMintActionsRaw.map((action) => {
|
|
169
|
+
const parsedMintActions = parsedMintActionsRaw.map((action, actionIndex) => {
|
|
202
170
|
if (!action || typeof action !== 'object') {
|
|
203
171
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'Each mint action must be an object with assetUnit and quantity', 'mintActionsJson');
|
|
204
172
|
}
|
|
205
|
-
//
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
173
|
+
// Optional per-action mintingPolicyScript + redeemerJson
|
|
174
|
+
const policyFields = (0, tx_request_parsers_1.parseMintActionPolicyFields)(action, actionIndex);
|
|
175
|
+
if (policyFields.error) {
|
|
176
|
+
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', policyFields.error, 'mintActionsJson');
|
|
177
|
+
}
|
|
178
|
+
let actionPolicyId;
|
|
179
|
+
if (policyFields.script) {
|
|
180
|
+
try {
|
|
181
|
+
actionPolicyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(policyFields.script, 'hex')).hash.toString();
|
|
182
|
+
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
185
|
+
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', `mintActions[${actionIndex}].mintingPolicyScript is not a valid Plutus script: ${errMsg}`, 'mintActionsJson');
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const bareAssetNameForExpansion = (!!scriptParamsJson || !!actionPolicyId) &&
|
|
210
189
|
typeof action.assetUnit === 'string' &&
|
|
211
190
|
action.assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH &&
|
|
212
191
|
action.assetUnit.length % 2 === 0 &&
|
|
213
192
|
/^[0-9a-fA-F]*$/.test(action.assetUnit);
|
|
214
193
|
if (typeof action.assetUnit !== 'string' || (!(0, validators_1.isAssetUnit)(action.assetUnit) && !bareAssetNameForExpansion)) {
|
|
215
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', `Invalid assetUnit: "${action.assetUnit}" — must be policyId+assetName hex (or a bare assetName hex when scriptParamsJson is set)`, 'mintActionsJson');
|
|
194
|
+
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', `Invalid assetUnit: "${action.assetUnit}" — must be policyId+assetName hex (or a bare assetName hex when scriptParamsJson or a per-action mintingPolicyScript is set)`, 'mintActionsJson');
|
|
195
|
+
}
|
|
196
|
+
let assetUnit = action.assetUnit;
|
|
197
|
+
if (actionPolicyId) {
|
|
198
|
+
if (assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
199
|
+
assetUnit = actionPolicyId + assetUnit;
|
|
200
|
+
}
|
|
201
|
+
else if (!assetUnit.toLowerCase().startsWith(actionPolicyId)) {
|
|
202
|
+
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', `mintActions[${actionIndex}].assetUnit "${assetUnit}" does not start with its own policy id ${actionPolicyId}`, 'mintActionsJson');
|
|
203
|
+
}
|
|
216
204
|
}
|
|
217
205
|
if (typeof action.quantity !== 'string') {
|
|
218
206
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'Each mint action must have a string quantity', 'mintActionsJson');
|
|
@@ -221,18 +209,22 @@ module.exports = (srv) => {
|
|
|
221
209
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', `Invalid quantity format: "${action.quantity}" — must be an integer string`, 'mintActionsJson');
|
|
222
210
|
}
|
|
223
211
|
try {
|
|
224
|
-
return {
|
|
212
|
+
return {
|
|
213
|
+
assetUnit,
|
|
214
|
+
quantity: BigInt(action.quantity),
|
|
215
|
+
...(action.redeemer !== undefined ? { redeemer: action.redeemer } : {}),
|
|
216
|
+
...(policyFields.script ? { mintingPolicyScript: policyFields.script } : {}),
|
|
217
|
+
...(policyFields.redeemer !== undefined ? { redeemerJson: policyFields.redeemer } : {})
|
|
218
|
+
};
|
|
225
219
|
}
|
|
226
220
|
catch {
|
|
227
221
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', `Invalid quantity: "${action.quantity}" — cannot parse as integer`, 'mintActionsJson');
|
|
228
222
|
}
|
|
229
223
|
});
|
|
230
|
-
// Parse and validate optional requiredSignersJson
|
|
231
224
|
const requiredSignersResult = (0, tx_request_parsers_1.parseRequiredSigners)(requiredSignersJson);
|
|
232
225
|
if (requiredSignersResult.error)
|
|
233
226
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', requiredSignersResult.error, 'requiredSignersJson');
|
|
234
227
|
const requiredSigners = requiredSignersResult.parsed;
|
|
235
|
-
// Parse and validate optional scriptParamsJson
|
|
236
228
|
let scriptParams;
|
|
237
229
|
if (scriptParamsJson) {
|
|
238
230
|
const jsonResult = (0, validators_1.validateJsonWithLimits)(scriptParamsJson, 'scriptParamsJson');
|
|
@@ -243,7 +235,6 @@ module.exports = (srv) => {
|
|
|
243
235
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'scriptParamsJson must be a JSON array', 'scriptParamsJson');
|
|
244
236
|
}
|
|
245
237
|
}
|
|
246
|
-
// Parse and validate optional inlineDatumJson
|
|
247
238
|
let inlineDatum;
|
|
248
239
|
if (inlineDatumJson) {
|
|
249
240
|
const jsonResult = (0, validators_1.validateJsonWithLimits)(inlineDatumJson, 'inlineDatumJson');
|
|
@@ -251,7 +242,6 @@ module.exports = (srv) => {
|
|
|
251
242
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', jsonResult.error, 'inlineDatumJson');
|
|
252
243
|
inlineDatum = jsonResult.parsed;
|
|
253
244
|
}
|
|
254
|
-
// Parse and validate optional mintRedeemerJson
|
|
255
245
|
let mintRedeemer;
|
|
256
246
|
if (mintRedeemerJson) {
|
|
257
247
|
const jsonResult = (0, validators_1.validateJsonWithLimits)(mintRedeemerJson, 'mintRedeemerJson');
|
|
@@ -259,23 +249,23 @@ module.exports = (srv) => {
|
|
|
259
249
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', jsonResult.error, 'mintRedeemerJson');
|
|
260
250
|
mintRedeemer = jsonResult.parsed;
|
|
261
251
|
}
|
|
262
|
-
// Validate lockOnScript requires scriptParamsJson
|
|
263
252
|
if (lockOnScript && (!scriptParams || scriptParams.length === 0)) {
|
|
264
253
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'lockOnScript requires scriptParamsJson to derive script address', 'lockOnScript');
|
|
265
254
|
}
|
|
266
|
-
//
|
|
255
|
+
// extraOutputsJson: each minted token can sit on its own output with its own inline datum
|
|
256
|
+
const extraOutputsResult = (0, tx_request_parsers_1.parseExtraOutputs)(extraOutputsJson);
|
|
257
|
+
if (extraOutputsResult.error)
|
|
258
|
+
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', extraOutputsResult.error, 'extraOutputsJson');
|
|
259
|
+
const extraOutputs = extraOutputsResult.parsed;
|
|
267
260
|
const forceInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(forceInputsJson, 'forceInputsJson');
|
|
268
261
|
if (forceInputsResult.error)
|
|
269
262
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', forceInputsResult.error, 'forceInputsJson');
|
|
270
263
|
const forceInputs = forceInputsResult.parsed;
|
|
271
|
-
//
|
|
264
|
+
// CIP-31 reference inputs
|
|
272
265
|
const refInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(referenceInputsJson, 'referenceInputsJson');
|
|
273
266
|
if (refInputsResult.error)
|
|
274
267
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', refInputsResult.error, 'referenceInputsJson');
|
|
275
268
|
const referenceInputs = refInputsResult.parsed;
|
|
276
|
-
// Parse and validate optional metadataJson (auxiliary_data on the mint tx).
|
|
277
|
-
// validateTransactionInputs has already JSON-validated the string; re-parse here
|
|
278
|
-
// and enforce the label-object shape that the builder's metadata mapper expects.
|
|
279
269
|
let parsedMetadata;
|
|
280
270
|
if (metadataJson) {
|
|
281
271
|
try {
|
|
@@ -289,10 +279,8 @@ module.exports = (srv) => {
|
|
|
289
279
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'metadataJson must be an object with numeric label keys', 'metadataJson');
|
|
290
280
|
}
|
|
291
281
|
}
|
|
292
|
-
// handle the request / building the transaction / indexing the build result / returning build details
|
|
293
282
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
294
283
|
logger.debug({ senderAddress, recipientAddress, lovelaceAmount, mintActions: parsedMintActions, forceInputs: forceInputs?.length ?? 0, referenceInputs: referenceInputs?.length ?? 0, hasMetadata: !!parsedMetadata }, 'Building minting transaction');
|
|
295
|
-
// Create clean request object with parsed mintActions (remove mintActionsJson, add mintActions)
|
|
296
284
|
const cleanData = { ...req.data };
|
|
297
285
|
delete cleanData.mintActionsJson;
|
|
298
286
|
delete cleanData.requiredSignersJson;
|
|
@@ -302,6 +290,7 @@ module.exports = (srv) => {
|
|
|
302
290
|
delete cleanData.lockOnScript;
|
|
303
291
|
delete cleanData.forceInputsJson;
|
|
304
292
|
delete cleanData.referenceInputsJson;
|
|
293
|
+
delete cleanData.extraOutputsJson;
|
|
305
294
|
if (parsedMetadata) {
|
|
306
295
|
cleanData.metadataJson = parsedMetadata;
|
|
307
296
|
}
|
|
@@ -312,13 +301,12 @@ module.exports = (srv) => {
|
|
|
312
301
|
cleanData.referenceScript = referenceScriptHex;
|
|
313
302
|
}
|
|
314
303
|
delete cleanData.referenceScriptHex;
|
|
315
|
-
//
|
|
304
|
+
// Parameterized policy: apply params, then expand bare asset names with the applied hash.
|
|
316
305
|
let finalMintingPolicyScript = mintingPolicyScript;
|
|
317
306
|
let effectivePolicyId;
|
|
318
307
|
if (scriptParams && scriptParams.length > 0) {
|
|
319
308
|
try {
|
|
320
309
|
finalMintingPolicyScript = (0, tx_build_helper_1.applyScriptParameters)(mintingPolicyScript, scriptParams);
|
|
321
|
-
// BUG 7 fix: expand assetName-only entries to full assetUnit using the applied script's policyId.
|
|
322
310
|
const appliedScript = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(finalMintingPolicyScript, 'hex'));
|
|
323
311
|
effectivePolicyId = appliedScript.hash.toString();
|
|
324
312
|
}
|
|
@@ -331,7 +319,7 @@ module.exports = (srv) => {
|
|
|
331
319
|
action.assetUnit = effectivePolicyId + action.assetUnit;
|
|
332
320
|
}
|
|
333
321
|
}
|
|
334
|
-
// lockOnScript: route output to the enterprise
|
|
322
|
+
// lockOnScript: route the output to the enterprise address of the applied script
|
|
335
323
|
if (lockOnScript) {
|
|
336
324
|
const scriptAddr = (0, mappers_1.scriptHashToEnterpriseAddress)(effectivePolicyId, (0, server_1.getCardanoClient)().network);
|
|
337
325
|
cleanData.recipientAddress = scriptAddr;
|
|
@@ -343,17 +331,13 @@ module.exports = (srv) => {
|
|
|
343
331
|
effectivePolicyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(mintingPolicyScript, 'hex')).hash.toString();
|
|
344
332
|
}
|
|
345
333
|
catch {
|
|
346
|
-
//
|
|
334
|
+
// Invalid script CBOR: skip the prefix check, the builder rejects it with its own message.
|
|
347
335
|
}
|
|
348
336
|
}
|
|
349
|
-
//
|
|
350
|
-
// parseAssetUnit silently discards the unit's first 56 hex chars. A bare asset name
|
|
351
|
-
// of 29-32 bytes is length-indistinguishable from a full unit, so a mismatched
|
|
352
|
-
// prefix would mint a truncated name. At this point every action holds a full
|
|
353
|
-
// unit (bare names were expanded above), so all of them must carry the policyId.
|
|
337
|
+
// Every action without its own policy must carry the top-level policy id prefix.
|
|
354
338
|
if (effectivePolicyId) {
|
|
355
339
|
const policyId = effectivePolicyId;
|
|
356
|
-
const mismatch = parsedMintActions.find((action) => !action.assetUnit.toLowerCase().startsWith(policyId));
|
|
340
|
+
const mismatch = parsedMintActions.find((action) => !action.mintingPolicyScript && !action.assetUnit.toLowerCase().startsWith(policyId));
|
|
357
341
|
if (mismatch) {
|
|
358
342
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', `assetUnit "${mismatch.assetUnit}" does not start with the minting policy id ${policyId} — pass the full unit as policyId+assetName (asset names longer than 28 bytes cannot be passed bare)`, 'mintActionsJson');
|
|
359
343
|
}
|
|
@@ -366,23 +350,23 @@ module.exports = (srv) => {
|
|
|
366
350
|
inlineDatum,
|
|
367
351
|
mintRedeemer,
|
|
368
352
|
forceInputs,
|
|
369
|
-
referenceInputs
|
|
353
|
+
referenceInputs,
|
|
354
|
+
extraOutputs
|
|
370
355
|
});
|
|
371
|
-
// Post-build:
|
|
356
|
+
// Post-build: CIP-14 fingerprint and scriptAddress
|
|
372
357
|
if (buildResult.scriptHash) {
|
|
373
358
|
const policyId = buildResult.scriptHash;
|
|
374
359
|
const updates = {};
|
|
375
|
-
//
|
|
376
|
-
//
|
|
377
|
-
// the BUG 9 prefix check rejected everything else (a 56-hex unit is an empty
|
|
378
|
-
// asset name, not a bare 28-byte name).
|
|
360
|
+
// Fingerprint of the first minted asset. The policy id is taken from the unit, not from
|
|
361
|
+
// buildResult.scriptHash: a per-action policy may differ from the top-level script.
|
|
379
362
|
if (parsedMintActions.length > 0) {
|
|
380
363
|
const firstAssetUnit = parsedMintActions[0].assetUnit;
|
|
364
|
+
const firstPolicyId = firstAssetUnit.slice(0, const_1.POLICY_ID_HEX_LENGTH);
|
|
381
365
|
const assetNameHex = firstAssetUnit.slice(const_1.POLICY_ID_HEX_LENGTH);
|
|
382
|
-
buildResult.fingerprint = (0, mappers_1.computeCip14Fingerprint)(
|
|
366
|
+
buildResult.fingerprint = (0, mappers_1.computeCip14Fingerprint)(firstPolicyId, assetNameHex);
|
|
383
367
|
updates.fingerprint = buildResult.fingerprint;
|
|
384
368
|
}
|
|
385
|
-
// lockOnScript: persist the derived script address on the build record
|
|
369
|
+
// lockOnScript: persist the derived script address on the build record
|
|
386
370
|
if (lockOnScript && scriptParams && scriptParams.length > 0) {
|
|
387
371
|
buildResult.scriptAddress = (0, mappers_1.scriptHashToEnterpriseAddress)(policyId, (0, server_1.getCardanoClient)().network);
|
|
388
372
|
updates.scriptAddress = buildResult.scriptAddress;
|
|
@@ -395,33 +379,24 @@ module.exports = (srv) => {
|
|
|
395
379
|
return buildResult;
|
|
396
380
|
});
|
|
397
381
|
});
|
|
398
|
-
|
|
399
|
-
* Build a Plutus spending transaction (consume UTxO at script address)
|
|
400
|
-
* @param req - CDS request object (with senderAddress, recipientAddress, lovelaceAmount, validatorScript, scriptTxHash, scriptOutputIndex, redeemerJson, datumJson, changeAddress)
|
|
401
|
-
* @returns {TransactionBuild} Transaction build details
|
|
402
|
-
*/
|
|
382
|
+
// BuildPlutusSpendTransaction — consume a UTxO at a script address, optionally minting too.
|
|
403
383
|
srv.on('BuildPlutusSpendTransaction', async (req) => {
|
|
404
384
|
const { senderAddress, recipientAddress, lovelaceAmount, validatorScript, scriptTxHash, scriptOutputIndex, redeemerJson, datumJson, requiredSignersJson, scriptParamsJson, inlineDatumJson, lockOnScript, forceInputsJson, extraOutputsJson, mintActionsJson, mintingPolicyScript, mintRedeemerJson, referenceInputsJson, referenceScriptHex, validityStartMs, validityEndMs } = req.data;
|
|
405
|
-
// Validate inputs
|
|
406
385
|
const errors = (0, validators_1.validateTransactionInputs)({ senderAddress, recipientAddress, lovelaceAmount, validatorScript, scriptTxHash, scriptOutputIndex, redeemerJson, datumJson, referenceScriptHex, validityStartMs, validityEndMs }, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'validatorScript', 'scriptTxHash', 'redeemerJson']);
|
|
407
386
|
(0, errors_1.throwIfValidationErrors)(req, 'BuildPlutusSpendTransaction', errors);
|
|
408
387
|
if (req.data.changeAddress && !(0, validators_1.isValidBech32Address)(req.data.changeAddress)) {
|
|
409
388
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', 'Invalid changeAddress format', 'changeAddress');
|
|
410
389
|
}
|
|
411
|
-
//
|
|
390
|
+
// A number: not covered by the required-fields check
|
|
412
391
|
if (scriptOutputIndex === undefined || scriptOutputIndex === null) {
|
|
413
392
|
return (0, errors_1.rejectMissing)(req, 'BuildPlutusSpendTransaction', 'scriptOutputIndex');
|
|
414
393
|
}
|
|
415
|
-
// Parse redeemer JSON
|
|
416
394
|
const parsedRedeemer = JSON.parse(redeemerJson);
|
|
417
|
-
// Parse optional datum JSON
|
|
418
395
|
const parsedDatum = datumJson ? JSON.parse(datumJson) : undefined;
|
|
419
|
-
// Parse and validate optional requiredSignersJson
|
|
420
396
|
const requiredSignersResult = (0, tx_request_parsers_1.parseRequiredSigners)(requiredSignersJson);
|
|
421
397
|
if (requiredSignersResult.error)
|
|
422
398
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', requiredSignersResult.error, 'requiredSignersJson');
|
|
423
399
|
const requiredSigners = requiredSignersResult.parsed;
|
|
424
|
-
// Parse and validate optional scriptParamsJson
|
|
425
400
|
let scriptParams;
|
|
426
401
|
if (scriptParamsJson) {
|
|
427
402
|
const jsonResult = (0, validators_1.validateJsonWithLimits)(scriptParamsJson, 'scriptParamsJson');
|
|
@@ -432,7 +407,6 @@ module.exports = (srv) => {
|
|
|
432
407
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', 'scriptParamsJson must be a JSON array', 'scriptParamsJson');
|
|
433
408
|
}
|
|
434
409
|
}
|
|
435
|
-
// Parse and validate optional inlineDatumJson
|
|
436
410
|
let inlineDatum;
|
|
437
411
|
if (inlineDatumJson) {
|
|
438
412
|
const jsonResult = (0, validators_1.validateJsonWithLimits)(inlineDatumJson, 'inlineDatumJson');
|
|
@@ -440,27 +414,23 @@ module.exports = (srv) => {
|
|
|
440
414
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', jsonResult.error, 'inlineDatumJson');
|
|
441
415
|
inlineDatum = jsonResult.parsed;
|
|
442
416
|
}
|
|
443
|
-
// Validate lockOnScript requires scriptParamsJson
|
|
444
417
|
if (lockOnScript && (!scriptParams || scriptParams.length === 0)) {
|
|
445
418
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', 'lockOnScript requires scriptParamsJson to derive script address', 'lockOnScript');
|
|
446
419
|
}
|
|
447
|
-
// Parse and validate optional forceInputsJson
|
|
448
420
|
const forceInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(forceInputsJson, 'forceInputsJson');
|
|
449
421
|
if (forceInputsResult.error)
|
|
450
422
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', forceInputsResult.error, 'forceInputsJson');
|
|
451
423
|
const forceInputs = forceInputsResult.parsed;
|
|
452
|
-
//
|
|
424
|
+
// CIP-31 reference inputs
|
|
453
425
|
const refInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(referenceInputsJson, 'referenceInputsJson');
|
|
454
426
|
if (refInputsResult.error)
|
|
455
427
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', refInputsResult.error, 'referenceInputsJson');
|
|
456
428
|
const referenceInputs = refInputsResult.parsed;
|
|
457
|
-
// Parse and validate optional extraOutputsJson
|
|
458
429
|
const extraOutputsResult = (0, tx_request_parsers_1.parseExtraOutputs)(extraOutputsJson);
|
|
459
430
|
if (extraOutputsResult.error)
|
|
460
431
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', extraOutputsResult.error, 'extraOutputsJson');
|
|
461
432
|
const extraOutputs = extraOutputsResult.parsed;
|
|
462
|
-
//
|
|
463
|
-
// mintingPolicyScript is required alongside it. mintRedeemerJson is optional.
|
|
433
|
+
// Optional combined spend+mint parameters
|
|
464
434
|
let parsedMintActions;
|
|
465
435
|
let parsedMintRedeemer;
|
|
466
436
|
if (mintActionsJson) {
|
|
@@ -473,7 +443,7 @@ module.exports = (srv) => {
|
|
|
473
443
|
if (!Array.isArray(mintJson.parsed)) {
|
|
474
444
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', 'mintActionsJson must be a JSON array', 'mintActionsJson');
|
|
475
445
|
}
|
|
476
|
-
parsedMintActions = mintJson.parsed.map((rawAction) => {
|
|
446
|
+
parsedMintActions = mintJson.parsed.map((rawAction, actionIndex) => {
|
|
477
447
|
if (!rawAction || typeof rawAction !== 'object') {
|
|
478
448
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', 'Each mint action must be an object with assetUnit and quantity', 'mintActionsJson');
|
|
479
449
|
}
|
|
@@ -484,18 +454,44 @@ module.exports = (srv) => {
|
|
|
484
454
|
if (typeof action.assetUnit !== 'string') {
|
|
485
455
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', 'Each mint action must have assetUnit string', 'mintActionsJson');
|
|
486
456
|
}
|
|
487
|
-
//
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
457
|
+
// Optional per-action mintingPolicyScript + redeemerJson (same rules as BuildMintTransaction)
|
|
458
|
+
const policyFields = (0, tx_request_parsers_1.parseMintActionPolicyFields)(action, actionIndex);
|
|
459
|
+
if (policyFields.error) {
|
|
460
|
+
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', policyFields.error, 'mintActionsJson');
|
|
461
|
+
}
|
|
462
|
+
let actionPolicyId;
|
|
463
|
+
if (policyFields.script) {
|
|
464
|
+
try {
|
|
465
|
+
actionPolicyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(policyFields.script, 'hex')).hash.toString();
|
|
466
|
+
}
|
|
467
|
+
catch (err) {
|
|
468
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
469
|
+
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', `mintActions[${actionIndex}].mintingPolicyScript is not a valid Plutus script: ${errMsg}`, 'mintActionsJson');
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
const bareAssetNameForExpansion = ((!!scriptParamsJson && mintingPolicyScript === validatorScript) || !!actionPolicyId) &&
|
|
492
473
|
action.assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH &&
|
|
493
474
|
action.assetUnit.length % 2 === 0 &&
|
|
494
475
|
/^[0-9a-fA-F]*$/.test(action.assetUnit);
|
|
495
476
|
if (!(0, validators_1.isAssetUnit)(action.assetUnit) && !bareAssetNameForExpansion) {
|
|
496
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', `Invalid assetUnit: "${action.assetUnit}" — must be policyId+assetName hex (or a bare assetName hex when scriptParamsJson is set and the policy equals the validator)`, 'mintActionsJson');
|
|
477
|
+
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', `Invalid assetUnit: "${action.assetUnit}" — must be policyId+assetName hex (or a bare assetName hex when a per-action mintingPolicyScript is set, or scriptParamsJson is set and the policy equals the validator)`, 'mintActionsJson');
|
|
497
478
|
}
|
|
498
|
-
|
|
479
|
+
let assetUnit = action.assetUnit;
|
|
480
|
+
if (actionPolicyId) {
|
|
481
|
+
if (assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
482
|
+
assetUnit = actionPolicyId + assetUnit;
|
|
483
|
+
}
|
|
484
|
+
else if (!assetUnit.toLowerCase().startsWith(actionPolicyId)) {
|
|
485
|
+
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', `mintActions[${actionIndex}].assetUnit "${assetUnit}" does not start with its own policy id ${actionPolicyId}`, 'mintActionsJson');
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
return {
|
|
489
|
+
assetUnit,
|
|
490
|
+
quantity: BigInt(action.quantity),
|
|
491
|
+
...(typeof action.redeemer === 'number' ? { redeemer: action.redeemer } : {}),
|
|
492
|
+
...(policyFields.script ? { mintingPolicyScript: policyFields.script } : {}),
|
|
493
|
+
...(policyFields.redeemer !== undefined ? { redeemerJson: policyFields.redeemer } : {})
|
|
494
|
+
};
|
|
499
495
|
});
|
|
500
496
|
if (mintRedeemerJson) {
|
|
501
497
|
const mrJson = (0, validators_1.validateJsonWithLimits)(mintRedeemerJson, 'mintRedeemerJson');
|
|
@@ -509,7 +505,6 @@ module.exports = (srv) => {
|
|
|
509
505
|
}
|
|
510
506
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
511
507
|
logger.debug({ senderAddress, recipientAddress, lovelaceAmount, scriptTxHash, scriptOutputIndex }, 'Building Plutus spending transaction');
|
|
512
|
-
// Apply script parameters if provided (for parameterized validators)
|
|
513
508
|
let finalValidatorScript = validatorScript;
|
|
514
509
|
if (scriptParams && scriptParams.length > 0) {
|
|
515
510
|
try {
|
|
@@ -520,8 +515,8 @@ module.exports = (srv) => {
|
|
|
520
515
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', `Failed to apply script parameters: ${errMsg}`, 'scriptParamsJson');
|
|
521
516
|
}
|
|
522
517
|
}
|
|
523
|
-
//
|
|
524
|
-
//
|
|
518
|
+
// A mint policy byte-equal to the validator (multi-purpose script) reuses the
|
|
519
|
+
// params-applied validator hex; any other policy passes through unchanged.
|
|
525
520
|
let finalMintingPolicyScript;
|
|
526
521
|
if (parsedMintActions) {
|
|
527
522
|
finalMintingPolicyScript = (mintingPolicyScript === validatorScript)
|
|
@@ -542,21 +537,20 @@ module.exports = (srv) => {
|
|
|
542
537
|
}
|
|
543
538
|
}
|
|
544
539
|
}
|
|
545
|
-
//
|
|
546
|
-
//
|
|
547
|
-
// discards the unit's first 56 hex chars, so a mismatched prefix would mint a
|
|
548
|
-
// truncated asset name.
|
|
540
|
+
// Policy-id prefix check as in BuildMintTransaction: the builder discards the unit's
|
|
541
|
+
// first 56 hex chars, so a mismatched prefix would mint a truncated asset name.
|
|
549
542
|
if (finalMintingPolicyScript) {
|
|
550
543
|
let mintPolicyId;
|
|
551
544
|
try {
|
|
552
545
|
mintPolicyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(finalMintingPolicyScript, 'hex')).hash.toString();
|
|
553
546
|
}
|
|
554
547
|
catch {
|
|
555
|
-
//
|
|
548
|
+
// Invalid script CBOR: skip the prefix check, the builder rejects it with its own message.
|
|
556
549
|
}
|
|
557
550
|
if (mintPolicyId) {
|
|
558
551
|
const policyId = mintPolicyId;
|
|
559
|
-
|
|
552
|
+
// Actions with a per-action script were already checked against that policy id.
|
|
553
|
+
const mismatch = parsedMintActions.find((action) => !action.mintingPolicyScript && !action.assetUnit.toLowerCase().startsWith(policyId));
|
|
560
554
|
if (mismatch) {
|
|
561
555
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', `assetUnit "${mismatch.assetUnit}" does not start with the minting policy id ${policyId} — pass the full unit as policyId+assetName (asset names longer than 28 bytes cannot be passed bare)`, 'mintActionsJson');
|
|
562
556
|
}
|
|
@@ -596,7 +590,7 @@ module.exports = (srv) => {
|
|
|
596
590
|
delete cleanData.mintActionsJson;
|
|
597
591
|
delete cleanData.mintRedeemerJson;
|
|
598
592
|
delete cleanData.referenceScriptHex;
|
|
599
|
-
// lockOnScript: route continuing output to enterprise script address
|
|
593
|
+
// lockOnScript: route the continuing output to the enterprise script address
|
|
600
594
|
if (lockOnScript && scriptParams && scriptParams.length > 0) {
|
|
601
595
|
try {
|
|
602
596
|
const appliedScript = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(finalValidatorScript, 'hex'));
|
|
@@ -611,7 +605,7 @@ module.exports = (srv) => {
|
|
|
611
605
|
}
|
|
612
606
|
}
|
|
613
607
|
const buildResult = await (0, server_1.getCardanoIndexer)().indexPlutusSpendBuildResult(db, cleanData);
|
|
614
|
-
// lockOnScript: persist the derived script address on the build record
|
|
608
|
+
// lockOnScript: persist the derived script address on the build record
|
|
615
609
|
if (lockOnScript && scriptParams && scriptParams.length > 0 && buildResult.scriptHash && buildResult.id) {
|
|
616
610
|
const scriptAddr = (0, mappers_1.scriptHashToEnterpriseAddress)(buildResult.scriptHash, (0, server_1.getCardanoClient)().network);
|
|
617
611
|
buildResult.scriptAddress = scriptAddr;
|
|
@@ -621,17 +615,11 @@ module.exports = (srv) => {
|
|
|
621
615
|
return buildResult;
|
|
622
616
|
});
|
|
623
617
|
});
|
|
624
|
-
|
|
625
|
-
* Get build details for previously built transaction
|
|
626
|
-
* @param req - CDS request object (with buildId)
|
|
627
|
-
* @returns {TransactionBuild} Transaction build details
|
|
628
|
-
*/
|
|
618
|
+
// GetBuildDetails — an existing transaction build by id.
|
|
629
619
|
srv.on('GetBuildDetails', async (req) => {
|
|
630
620
|
const { buildId } = req.data;
|
|
631
|
-
// Validate inputs
|
|
632
621
|
const errors = (0, validators_1.validateTransactionInputs)({ buildId }, ['buildId']);
|
|
633
622
|
(0, errors_1.throwIfValidationErrors)(req, 'GetBuildDetails', errors);
|
|
634
|
-
// handle the request / fetching the build details
|
|
635
623
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
636
624
|
const existing = await db.run(SELECT.one.from(TransactionBuilds).where({ id: buildId }));
|
|
637
625
|
if (!existing)
|
|
@@ -639,13 +627,7 @@ module.exports = (srv) => {
|
|
|
639
627
|
return existing;
|
|
640
628
|
});
|
|
641
629
|
});
|
|
642
|
-
|
|
643
|
-
* Set up a collateral UTxO for Plutus transactions.
|
|
644
|
-
* Checks if the address already has >= 2 UTxOs with >= 5 ADA each.
|
|
645
|
-
* If not, builds a self-send transaction to create a 5 ADA collateral UTxO.
|
|
646
|
-
* @param req - CDS request object (with address)
|
|
647
|
-
* @returns {TransactionBuild} Transaction build details for the collateral setup
|
|
648
|
-
*/
|
|
630
|
+
// SetCollateral — ensures >= 2 UTxOs of >= 5 ADA; otherwise builds a self-send that creates one.
|
|
649
631
|
srv.on('SetCollateral', async (req) => {
|
|
650
632
|
const { address } = req.data;
|
|
651
633
|
if (!address)
|
|
@@ -654,11 +636,8 @@ module.exports = (srv) => {
|
|
|
654
636
|
return (0, errors_1.rejectInvalid)(req, 'SetCollateral', 'Invalid Bech32 address format', 'address');
|
|
655
637
|
}
|
|
656
638
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
657
|
-
// Inside handleRequest
|
|
658
|
-
//
|
|
659
|
-
// getAddressUtxos both get caught and properly mapped via mapError.
|
|
660
|
-
// Use rejectInvalid (throws BackendError 400) instead of req.reject so
|
|
661
|
-
// mapError sees a typed BackendError and preserves the 400 status.
|
|
639
|
+
// Inside handleRequest use rejectInvalid (typed BackendError 400), not req.reject,
|
|
640
|
+
// so mapError preserves the status.
|
|
662
641
|
const utxos = await (0, server_1.getCardanoClient)().getAddressUtxos(address);
|
|
663
642
|
if (utxos.length === 0) {
|
|
664
643
|
return (0, errors_1.rejectInvalid)(req, 'SetCollateral', 'No UTxOs found at address', 'address');
|
|
@@ -687,32 +666,24 @@ module.exports = (srv) => {
|
|
|
687
666
|
return { ...result, collateralAvailable: false };
|
|
688
667
|
});
|
|
689
668
|
});
|
|
690
|
-
|
|
691
|
-
* Submit signed transaction built previously
|
|
692
|
-
* Handler validates, checks build exists, submits to blockchain, delegates persistence to indexer
|
|
693
|
-
* @param req - CDS request object (with buildId, signedTxCbor)
|
|
694
|
-
* @returns {TransactionSubmission} Transaction submission details
|
|
695
|
-
*/
|
|
669
|
+
// SubmitTransaction — submit the signed CBOR of a previous build.
|
|
696
670
|
srv.on('SubmitTransaction', async (req) => {
|
|
697
671
|
logger.debug('SubmitTransaction Action handler called');
|
|
698
672
|
const { buildId, signedTxCbor } = req.data;
|
|
699
|
-
// Validate inputs (includes CBOR format validation)
|
|
700
673
|
const errors = (0, validators_1.validateTransactionInputs)({ buildId, signedTxCbor }, ['buildId', 'signedTxCbor']);
|
|
701
674
|
(0, errors_1.throwIfValidationErrors)(req, 'SubmitTransaction', errors);
|
|
702
675
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
703
676
|
logger.debug({ buildId }, 'Submitting signed transaction');
|
|
704
|
-
// Validate build exists
|
|
705
677
|
const existing = await db.run(SELECT.one.from(TransactionBuilds).where({ id: buildId }));
|
|
706
678
|
if (!existing)
|
|
707
679
|
throw new errors_1.NotFoundError(`Build '${buildId}'`);
|
|
708
|
-
//
|
|
680
|
+
// The signed CBOR must belong to this build (audit-trail integrity)
|
|
709
681
|
const signedTxHash = (0, tx_build_helper_1.getTxHashFromCbor)(signedTxCbor);
|
|
710
682
|
if (signedTxHash !== existing.txBodyHash) {
|
|
711
683
|
return (0, errors_1.rejectInvalid)(req, 'SubmitTransaction', `signedTxCbor hash '${signedTxHash}' does not match build txBodyHash '${existing.txBodyHash}'`, 'signedTxCbor');
|
|
712
684
|
}
|
|
713
|
-
// Use txBodyHash from build
|
|
714
685
|
const txHash = existing.txBodyHash;
|
|
715
|
-
// Two-phase submit: persist
|
|
686
|
+
// Two-phase submit: persist as 'pending', then submit
|
|
716
687
|
const submissionRecord = await (0, server_1.getCardanoIndexer)().persistTransactionSubmission(db, {
|
|
717
688
|
signedTxCbor,
|
|
718
689
|
txHash,
|
|
@@ -723,9 +694,8 @@ module.exports = (srv) => {
|
|
|
723
694
|
logger.info({ txHash }, 'Transaction submitted to blockchain');
|
|
724
695
|
await (0, server_1.getCardanoIndexer)().updateSubmissionStatus(db, submissionRecord.id, 'submitted');
|
|
725
696
|
submissionRecord.status = 'submitted';
|
|
726
|
-
//
|
|
727
|
-
//
|
|
728
|
-
// failure here must not fail the already-successful submit.
|
|
697
|
+
// Best-effort UTxO cache invalidation (spent inputs, output addresses, sender);
|
|
698
|
+
// a failure must not fail the successful submit.
|
|
729
699
|
try {
|
|
730
700
|
const addrBuild = await db.run(SELECT.one.from(AddressTransactionBuilds).where({ txBuild_id: buildId }));
|
|
731
701
|
await (0, server_1.getCardanoIndexer)().invalidateUtxoCacheForTx(db, (0, tx_build_helper_1.extractTxCacheTargets)(signedTxCbor), addrBuild?.address_address ? [addrBuild.address_address] : []);
|
|
@@ -743,29 +713,20 @@ module.exports = (srv) => {
|
|
|
743
713
|
return submissionRecord;
|
|
744
714
|
});
|
|
745
715
|
});
|
|
746
|
-
|
|
747
|
-
* Submit signed transaction without prior build
|
|
748
|
-
* Handler validates, submits to blockchain, delegates persistence to indexer
|
|
749
|
-
* Two-phase: persist with 'pending' first, then update to 'submitted' or 'failed'
|
|
750
|
-
* @param req - CDS request object (with signedTxCbor, network)
|
|
751
|
-
* @returns {TransactionSubmission} Transaction submission details
|
|
752
|
-
*/
|
|
716
|
+
// SubmitSignedTransaction — submit externally built signed CBOR (no prior build).
|
|
753
717
|
srv.on('SubmitSignedTransaction', async (req) => {
|
|
754
718
|
logger.debug('SubmitSignedTransaction Action handler called');
|
|
755
719
|
const { signedTxCbor, network } = req.data;
|
|
756
|
-
// Validate inputs (includes CBOR format validation)
|
|
757
720
|
const errors = (0, validators_1.validateTransactionInputs)({ signedTxCbor }, ['signedTxCbor']);
|
|
758
721
|
(0, errors_1.throwIfValidationErrors)(req, 'SubmitSignedTransaction', errors);
|
|
759
722
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
760
|
-
//
|
|
761
|
-
// configured network so a caller targeting the wrong deployment gets a clear 400.
|
|
723
|
+
// A caller targeting the wrong deployment gets a clear 400
|
|
762
724
|
const configuredNetwork = (0, server_1.getCardanoClient)().network;
|
|
763
725
|
if (network && network !== configuredNetwork) {
|
|
764
726
|
return (0, errors_1.rejectInvalid)(req, 'SubmitSignedTransaction', `network '${network}' does not match this deployment's network '${configuredNetwork}'`, 'network');
|
|
765
727
|
}
|
|
766
|
-
// Extract txHash from signed CBOR
|
|
767
728
|
const txHash = (0, tx_build_helper_1.getTxHashFromCbor)(signedTxCbor);
|
|
768
|
-
// Two-phase submit: persist
|
|
729
|
+
// Two-phase submit: persist as 'pending', then submit
|
|
769
730
|
const submissionRecord = await (0, server_1.getCardanoIndexer)().persistTransactionSubmission(db, {
|
|
770
731
|
signedTxCbor,
|
|
771
732
|
txHash,
|
|
@@ -776,7 +737,7 @@ module.exports = (srv) => {
|
|
|
776
737
|
logger.info({ txHash }, 'External transaction submitted');
|
|
777
738
|
await (0, server_1.getCardanoIndexer)().updateSubmissionStatus(db, submissionRecord.id, 'submitted');
|
|
778
739
|
submissionRecord.status = 'submitted';
|
|
779
|
-
//
|
|
740
|
+
// Best-effort UTxO cache invalidation
|
|
780
741
|
try {
|
|
781
742
|
await (0, server_1.getCardanoIndexer)().invalidateUtxoCacheForTx(db, (0, tx_build_helper_1.extractTxCacheTargets)(signedTxCbor));
|
|
782
743
|
}
|
|
@@ -793,22 +754,14 @@ module.exports = (srv) => {
|
|
|
793
754
|
return submissionRecord;
|
|
794
755
|
});
|
|
795
756
|
});
|
|
796
|
-
|
|
797
|
-
* Check submission status (bound action on TransactionSubmissions)
|
|
798
|
-
* @flow.status validates @from: [#submitted] automatically (409 if wrong state)
|
|
799
|
-
* Queries blockchain for transaction confirmation and updates status accordingly
|
|
800
|
-
* @param req - CDS request with entity key in params
|
|
801
|
-
* @returns {TransactionSubmission} The updated transaction submission status
|
|
802
|
-
*/
|
|
757
|
+
// CheckSubmissionStatus — bound action; the @from: [#submitted] state gate is enforced by CAP.
|
|
803
758
|
srv.on('CheckSubmissionStatus', async (req) => {
|
|
804
759
|
logger.debug('CheckSubmissionStatus Action handler called');
|
|
805
760
|
const { id: submissionId } = req.params[0];
|
|
806
|
-
// @from: [#submitted] validated by framework — no manual status check needed
|
|
807
761
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
808
762
|
const submission = await db.run(SELECT.one.from(TransactionSubmissions).where({ id: submissionId }));
|
|
809
763
|
if (!submission)
|
|
810
764
|
throw new errors_1.NotFoundError(`Submission '${submissionId}'`);
|
|
811
|
-
// Query blockchain for confirmation
|
|
812
765
|
try {
|
|
813
766
|
const txDetails = await (0, server_1.getCardanoClient)().getTransaction(submission.txHash);
|
|
814
767
|
if (txDetails) {
|
|
@@ -822,11 +775,10 @@ module.exports = (srv) => {
|
|
|
822
775
|
catch (err) {
|
|
823
776
|
const errMsg = err instanceof Error ? err.message : String(err);
|
|
824
777
|
if (err instanceof errors_1.NotFoundError || err?.statusCode === 404) {
|
|
825
|
-
// Transaction genuinely not yet confirmed on chain
|
|
826
778
|
logger.debug({ submissionId, txHash: submission.txHash }, 'Transaction not yet confirmed on chain');
|
|
827
779
|
}
|
|
828
780
|
else {
|
|
829
|
-
//
|
|
781
|
+
// A provider error must not be masked as "pending"
|
|
830
782
|
logger.warn({ submissionId, txHash: submission.txHash, error: errMsg }, 'Failed to check transaction confirmation status');
|
|
831
783
|
throw err;
|
|
832
784
|
}
|
|
@@ -834,28 +786,19 @@ module.exports = (srv) => {
|
|
|
834
786
|
return submission;
|
|
835
787
|
});
|
|
836
788
|
});
|
|
837
|
-
|
|
838
|
-
* Get all existing transaction builds by address
|
|
839
|
-
* @param req - CDS request object (with address)
|
|
840
|
-
* @returns {AddressTransactionBuilds} Address transaction build associations
|
|
841
|
-
*/
|
|
789
|
+
// GetTransactionBuildsByAddress — address ↔ build associations.
|
|
842
790
|
srv.on('GetTransactionBuildsByAddress', async (req) => {
|
|
843
791
|
logger.debug('GetTransactionBuildsByAddress Action handler called');
|
|
844
792
|
const { address } = req.data;
|
|
845
|
-
// Validate inputs
|
|
846
793
|
if (!address)
|
|
847
794
|
return (0, errors_1.rejectMissing)(req, 'GetTransactionBuildsByAddress', 'address');
|
|
848
795
|
if (!(0, validators_1.isValidBech32Address)(address))
|
|
849
796
|
return (0, errors_1.rejectInvalid)(req, 'GetTransactionBuildsByAddress', 'Invalid bech32 address format', 'address');
|
|
850
|
-
// Fetch the address-build associations
|
|
851
797
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
852
798
|
return db.run(SELECT.from(AddressTransactionBuilds).where({ address_address: address }));
|
|
853
799
|
});
|
|
854
800
|
});
|
|
855
|
-
|
|
856
|
-
* Derive the enterprise script address + script hash for a validator script,
|
|
857
|
-
* optionally after applying PlutusData parameters. No transaction is built.
|
|
858
|
-
*/
|
|
801
|
+
// DeriveScriptAddress — enterprise address + hash of a validator, optionally parameterized.
|
|
859
802
|
srv.on('DeriveScriptAddress', async (req) => {
|
|
860
803
|
const { validatorScript, scriptParamsJson, network } = req.data;
|
|
861
804
|
if (!validatorScript)
|
|
@@ -877,9 +820,7 @@ module.exports = (srv) => {
|
|
|
877
820
|
return (0, errors_1.rejectInvalid)(req, 'DeriveScriptAddress', `Invalid network "${network}". Must be one of: ${VALID_DERIVE_NETWORKS.join(', ')}`, 'network');
|
|
878
821
|
}
|
|
879
822
|
return (0, backend_request_handler_1.handleRequest)(req, async () => {
|
|
880
|
-
//
|
|
881
|
-
// is uninitialized. Resolving the network outside the inner CBOR try/catch
|
|
882
|
-
// keeps that 503 distinct from the 400 used for malformed validatorScript bytes.
|
|
823
|
+
// Resolved outside the CBOR try/catch so an uninitialized client stays a 503, not a 400.
|
|
883
824
|
const targetNetwork = network
|
|
884
825
|
? network
|
|
885
826
|
: (0, server_1.getCardanoClient)().network;
|
|
@@ -897,10 +838,7 @@ module.exports = (srv) => {
|
|
|
897
838
|
}
|
|
898
839
|
});
|
|
899
840
|
});
|
|
900
|
-
|
|
901
|
-
* Extract the 28-byte payment credential (key hash or script hash) from a Bech32
|
|
902
|
-
* Cardano address. Pure local decoding — no blockchain call.
|
|
903
|
-
*/
|
|
841
|
+
// ExtractPaymentKeyHash — 28-byte payment credential of a bech32 address; pure local decoding.
|
|
904
842
|
srv.on('ExtractPaymentKeyHash', async (req) => {
|
|
905
843
|
const { address } = req.data;
|
|
906
844
|
if (!address)
|
|
@@ -911,7 +849,7 @@ module.exports = (srv) => {
|
|
|
911
849
|
try {
|
|
912
850
|
const decoded = bech32_1.bech32.decode(address, const_1.BECH32_MAX_LENGTH);
|
|
913
851
|
const bytes = Buffer.from(bech32_1.bech32.fromWords(decoded.words));
|
|
914
|
-
//
|
|
852
|
+
// 1 header byte + 28-byte payment credential (+ optional 28-byte stake credential)
|
|
915
853
|
if (bytes.length < 29) {
|
|
916
854
|
return (0, errors_1.rejectInvalid)(req, 'ExtractPaymentKeyHash', 'Address is too short to contain a payment credential', 'address');
|
|
917
855
|
}
|