@odatano/core 1.10.0 → 2.0.0-rc.1
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 +142 -0
- package/@cds-models/CardanoIndexerService/index.js +23 -0
- package/@cds-models/CardanoODataService/index.d.ts +693 -2172
- package/@cds-models/CardanoODataService/index.js +88 -390
- package/@cds-models/CardanoSignService/index.d.ts +443 -1574
- package/@cds-models/CardanoSignService/index.js +62 -293
- package/@cds-models/CardanoTransactionService/index.d.ts +431 -1488
- package/@cds-models/CardanoTransactionService/index.js +60 -271
- package/@cds-models/CardanoWorkerService/index.d.ts +224 -0
- package/@cds-models/CardanoWorkerService/index.js +32 -0
- package/@cds-models/_/index.d.ts +70 -40
- package/@cds-models/_/index.js +17 -32
- package/@cds-models/cds/outbox/index.d.ts +28 -0
- package/@cds-models/index.d.ts +225 -522
- package/@cds-models/index.js +35 -218
- package/@cds-models/odatano/cardano/index.d.ts +896 -2947
- package/@cds-models/odatano/cardano/index.js +109 -536
- package/@cds-models/sap/common/index.d.ts +196 -600
- package/@cds-models/sap/common/index.js +28 -269
- package/README.md +136 -102
- package/db/schema.cds +283 -1
- package/db/types.cds +48 -0
- package/package.json +43 -34
- package/src/index.d.ts +1 -1
- package/src/index.js +10 -2
- package/src/plugin.js +12 -2
- package/srv/blockchain/backends/blockfrost-backend.d.ts +21 -2
- package/srv/blockchain/backends/blockfrost-backend.js +68 -15
- package/srv/blockchain/backends/cardano-backend.d.ts +69 -0
- package/srv/blockchain/backends/cardano-backend.js +13 -0
- package/srv/blockchain/backends/koios-backend.d.ts +26 -2
- package/srv/blockchain/backends/koios-backend.js +147 -15
- package/srv/blockchain/backends/ogmios-backend.d.ts +37 -6
- package/srv/blockchain/backends/ogmios-backend.js +254 -5
- package/srv/blockchain/cardano-client.d.ts +19 -0
- package/srv/blockchain/cardano-client.js +36 -0
- package/srv/blockchain/cardano-indexer.d.ts +50 -1
- package/srv/blockchain/cardano-indexer.js +191 -0
- package/srv/blockchain/crawler/crawler.d.ts +151 -0
- package/srv/blockchain/crawler/crawler.js +677 -0
- package/srv/blockchain/crawler/hooks.d.ts +43 -0
- package/srv/blockchain/crawler/hooks.js +62 -0
- package/srv/blockchain/crawler/index.d.ts +26 -0
- package/srv/blockchain/crawler/index.js +135 -0
- package/srv/blockchain/crawler/sync-state.d.ts +94 -0
- package/srv/blockchain/crawler/sync-state.js +265 -0
- package/srv/blockchain/signing/hsm-signer.d.ts +45 -0
- package/srv/blockchain/signing/hsm-signer.js +8 -1
- package/srv/blockchain/signing/signature-verifier.js +4 -5
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +7 -10
- package/srv/blockchain/transaction-building/buildooor-tx.js +12 -15
- package/srv/blockchain/wallet-worker/build-request.d.ts +26 -0
- package/srv/blockchain/wallet-worker/build-request.js +341 -0
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +86 -0
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +228 -0
- package/srv/blockchain/wallet-worker/index.d.ts +14 -0
- package/srv/blockchain/wallet-worker/index.js +80 -0
- package/srv/blockchain/wallet-worker/job-store.d.ts +261 -0
- package/srv/blockchain/wallet-worker/job-store.js +564 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +43 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +99 -0
- package/srv/blockchain/wallet-worker/signers.d.ts +57 -0
- package/srv/blockchain/wallet-worker/signers.js +131 -0
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +145 -0
- package/srv/blockchain/wallet-worker/wallet-worker.js +542 -0
- package/srv/cardano-indexer-service.cds +73 -0
- package/srv/cardano-indexer-service.d.ts +2 -0
- package/srv/cardano-indexer-service.js +76 -0
- package/srv/cardano-service.js +22 -1
- package/srv/cardano-tx-service.d.ts +1 -11
- package/srv/cardano-tx-service.js +11 -162
- package/srv/cardano-worker-service.cds +125 -0
- package/srv/cardano-worker-service.d.ts +2 -0
- package/srv/cardano-worker-service.js +199 -0
- package/srv/server.d.ts +32 -1
- package/srv/server.js +228 -2
- package/srv/utils/collections.d.ts +13 -0
- package/srv/utils/collections.js +24 -0
- package/srv/utils/crypto.d.ts +16 -0
- package/srv/utils/crypto.js +75 -0
- package/srv/utils/error-codes.d.ts +6 -0
- package/srv/utils/error-codes.js +6 -0
- package/srv/utils/errors.d.ts +12 -0
- package/srv/utils/errors.js +45 -0
- package/srv/utils/mappers.js +13 -3
- package/srv/utils/service-events.d.ts +26 -0
- package/srv/utils/service-events.js +46 -0
- package/srv/utils/tx-build-helper.d.ts +1 -2
- package/srv/utils/tx-build-helper.js +3 -5
- package/srv/utils/tx-request-parsers.d.ts +58 -0
- package/srv/utils/tx-request-parsers.js +170 -0
- package/srv/utils/tx-utils.d.ts +2 -1
- package/srv/utils/tx-utils.js +3 -2
- package/srv/utils/types.d.ts +2 -1
- package/@cds-models/CardanoODataService/index.d.ts.map +0 -1
- package/@cds-models/CardanoODataService/index.js.map +0 -1
- package/@cds-models/CardanoODataService/index.ts +0 -776
- package/@cds-models/CardanoSignService/index.d.ts.map +0 -1
- package/@cds-models/CardanoSignService/index.js.map +0 -1
- package/@cds-models/CardanoSignService/index.ts +0 -569
- package/@cds-models/CardanoTransactionService/index.d.ts.map +0 -1
- package/@cds-models/CardanoTransactionService/index.js.map +0 -1
- package/@cds-models/CardanoTransactionService/index.ts +0 -526
- package/@cds-models/_/index.d.ts.map +0 -1
- package/@cds-models/_/index.js.map +0 -1
- package/@cds-models/_/index.ts +0 -96
- package/@cds-models/cds/outbox/index.ts +0 -27
- package/@cds-models/index.d.ts.map +0 -1
- package/@cds-models/index.js.map +0 -1
- package/@cds-models/index.ts +0 -245
- package/@cds-models/odatano/cardano/index.d.ts.map +0 -1
- package/@cds-models/odatano/cardano/index.js.map +0 -1
- package/@cds-models/odatano/cardano/index.ts +0 -789
- package/@cds-models/sap/common/index.d.ts.map +0 -1
- package/@cds-models/sap/common/index.js.map +0 -1
- package/@cds-models/sap/common/index.ts +0 -249
- package/srv/blockchain/transaction-building/keep-relevant.d.ts +0 -29
- package/srv/blockchain/transaction-building/keep-relevant.js +0 -116
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.HsmSigner = void 0;
|
|
7
|
+
exports.setPkcs11Loader = setPkcs11Loader;
|
|
7
8
|
exports.getHsmSigner = getHsmSigner;
|
|
8
9
|
exports.setHsmSigner = setHsmSigner;
|
|
9
10
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
@@ -17,6 +18,12 @@ const logger = cds_1.default.log('HsmSigner');
|
|
|
17
18
|
* Used for Ed25519 signing operations
|
|
18
19
|
*/
|
|
19
20
|
const CKM_EDDSA = 0x00001057;
|
|
21
|
+
const defaultPkcs11Loader = () => require('pkcs11js');
|
|
22
|
+
let pkcs11Loader = defaultPkcs11Loader;
|
|
23
|
+
/** Test seam: inject a fake pkcs11js module loader (null restores the default). */
|
|
24
|
+
function setPkcs11Loader(loader) {
|
|
25
|
+
pkcs11Loader = loader ?? defaultPkcs11Loader;
|
|
26
|
+
}
|
|
20
27
|
class HsmSigner {
|
|
21
28
|
pkcs11;
|
|
22
29
|
session;
|
|
@@ -39,7 +46,7 @@ class HsmSigner {
|
|
|
39
46
|
// Dynamic import — pkcs11js is only loaded when HSM is configured
|
|
40
47
|
let pkcs11js;
|
|
41
48
|
try {
|
|
42
|
-
pkcs11js =
|
|
49
|
+
pkcs11js = pkcs11Loader();
|
|
43
50
|
}
|
|
44
51
|
catch {
|
|
45
52
|
throw new errors_1.HsmError('pkcs11js is not installed. Install it with: npm install pkcs11js', 500, error_codes_1.ERROR_CODES.HSM_UNAVAILABLE);
|
|
@@ -15,8 +15,9 @@ const logger = cds_1.default.log('SignatureVerifier');
|
|
|
15
15
|
/**
|
|
16
16
|
* blake2b-256 over the ORIGINAL transaction-body bytes (CBOR array index 0).
|
|
17
17
|
* subCborRef preserves the exact received bytes, so the hash matches what was signed
|
|
18
|
-
* and re-serialization can never drift it.
|
|
19
|
-
*
|
|
18
|
+
* and re-serialization can never drift it. (Historically this also sidestepped the
|
|
19
|
+
* ledger-ts AuxiliaryData.fromCbor bug on metadata-only aux_data — fixed in 0.5.6 —
|
|
20
|
+
* but byte-exactness remains the reason to stay at the raw-CBOR level.)
|
|
20
21
|
*/
|
|
21
22
|
function computeBodyHash(txBytes) {
|
|
22
23
|
const tx = cbor_1.Cbor.parse(txBytes);
|
|
@@ -93,9 +94,7 @@ class SignatureVerifier {
|
|
|
93
94
|
};
|
|
94
95
|
try {
|
|
95
96
|
// Compute the body hash over the original CBOR body bytes (no re-serialization),
|
|
96
|
-
// matching exactly what was signed.
|
|
97
|
-
// @harmoniclabs/cardano-ledger-ts AuxiliaryData.fromCbor bug that rejects
|
|
98
|
-
// metadata-only Conway aux_data.
|
|
97
|
+
// matching exactly what was signed.
|
|
99
98
|
const txBytes = (0, uint8array_utils_1.fromHex)(signedTxCbor);
|
|
100
99
|
const computedHash = computeBodyHash(txBytes);
|
|
101
100
|
result.txBodyHash = computedHash;
|
|
@@ -105,16 +105,13 @@ export declare class BuildooorTxBuilder implements CardanoTxBuilder {
|
|
|
105
105
|
/**
|
|
106
106
|
* Replace the redeemers' execution units and recompute scriptDataHash.
|
|
107
107
|
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
* the
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* to the parameter count the library release knows — wrong on networks whose cost
|
|
116
|
-
* model has grown past that (ScriptIntegrityHashMismatch at submit). This recompute
|
|
117
|
-
* with _languageViewCostModels (raw chain arrays) is where the hash becomes correct.
|
|
108
|
+
* Still not implemented via TxBuilder.overrideTxRedeemers, although buildooor
|
|
109
|
+
* 0.2.9 fixed its old-witness-set hashing (our PR): that method hashes with the
|
|
110
|
+
* builder's named-key cost models, which clamp the chain array to the parameter
|
|
111
|
+
* count the library release knows — wrong whenever the on-chain cost model has
|
|
112
|
+
* grown past that (ScriptIntegrityHashMismatch at submit). This recompute with
|
|
113
|
+
* _languageViewCostModels (raw chain arrays) stays governance-proof, so the hash
|
|
114
|
+
* is recomputed here even when the target units already match.
|
|
118
115
|
*/
|
|
119
116
|
private _stampExecUnits;
|
|
120
117
|
/**
|
|
@@ -4,13 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.BuildooorTxBuilder = void 0;
|
|
7
|
+
// Coin selection uses this.txBuilder.keepRelevant again since buildooor 0.2.9
|
|
8
|
+
// ships the fixed implementation (our PR); the vendored keep-relevant.ts is gone.
|
|
7
9
|
const buildooor_1 = require("@harmoniclabs/buildooor");
|
|
8
10
|
const uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
|
|
9
11
|
const tx_build_helper_1 = require("../../utils/tx-build-helper");
|
|
10
12
|
const errors_1 = require("../../utils/errors");
|
|
11
13
|
const plutus_placeholders_1 = require("../../utils/plutus-placeholders");
|
|
12
|
-
// Vendored coin selection (buildooor PR #12 fix) — NOT this.txBuilder.keepRelevant; see keep-relevant.ts
|
|
13
|
-
const keep_relevant_1 = require("./keep-relevant");
|
|
14
14
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
15
15
|
const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
16
16
|
// Metadata classes are imported from the DIST paths ON PURPOSE: buildooor's
|
|
@@ -221,7 +221,7 @@ class BuildooorTxBuilder {
|
|
|
221
221
|
const forcedInputs = forced.map(u => ({ utxo: this._mapMultiAssetUtxoToLedgerUtxo(u) }));
|
|
222
222
|
const candidateInputs = rest.map(u => ({ utxo: this._mapMultiAssetUtxoToLedgerUtxo(u) }));
|
|
223
223
|
// Coin selection on candidates only; forced inputs are prepended unconditionally
|
|
224
|
-
const selected =
|
|
224
|
+
const selected = this.txBuilder.keepRelevant(outputValue, candidateInputs);
|
|
225
225
|
const inputs = [...forcedInputs, ...selected];
|
|
226
226
|
logger.debug(`Coin selection: ${selected.length}/${candidateInputs.length} UTxOs selected (${forcedInputs.length} forced) for ${label}`);
|
|
227
227
|
const metadata = req.metadataJson !== undefined && req.metadataJson !== null
|
|
@@ -266,7 +266,7 @@ class BuildooorTxBuilder {
|
|
|
266
266
|
const allFundingInputs = fundingLedgerUtxos.map(utxo => ({ utxo }));
|
|
267
267
|
// Coin selection: only need enough ADA from funding UTxOs (minted tokens come from thin air)
|
|
268
268
|
const requiredFundingValue = cardano_ledger_ts_1.Value.lovelaces(BigInt(req.lovelaceAmount));
|
|
269
|
-
const selectedFunding =
|
|
269
|
+
const selectedFunding = this.txBuilder.keepRelevant(requiredFundingValue, allFundingInputs);
|
|
270
270
|
const inputs = [...forcedInputs, ...selectedFunding];
|
|
271
271
|
logger.debug(`Coin selection: ${selectedFunding.length}/${allFundingInputs.length} UTxOs selected (${forcedInputs.length} forced) for mint`);
|
|
272
272
|
// FR-3: resolve __INPUT_IDX__ placeholders in mintRedeemer + inlineDatum after final input order is known.
|
|
@@ -360,7 +360,7 @@ class BuildooorTxBuilder {
|
|
|
360
360
|
requiredFundingValue = cardano_ledger_ts_1.Value.add(requiredFundingValue, this._buildLedgerValue(BigInt(extra.lovelaceAmount), extra.assets));
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
|
-
const selectedFundingInputs =
|
|
363
|
+
const selectedFundingInputs = this.txBuilder.keepRelevant(requiredFundingValue, allFundingInputs);
|
|
364
364
|
logger.debug(`Coin selection: ${selectedFundingInputs.length}/${allFundingInputs.length} UTxOs selected (${forcedInputs.length} forced) for Plutus spend`);
|
|
365
365
|
// FR-3: compute the final input order (replicates Buildooor's lex sort) and resolve any
|
|
366
366
|
// __INPUT_IDX__ placeholders in redeemer / datum / output datums BEFORE PlutusData encoding.
|
|
@@ -675,16 +675,13 @@ class BuildooorTxBuilder {
|
|
|
675
675
|
/**
|
|
676
676
|
* Replace the redeemers' execution units and recompute scriptDataHash.
|
|
677
677
|
*
|
|
678
|
-
*
|
|
679
|
-
*
|
|
680
|
-
*
|
|
681
|
-
* the
|
|
682
|
-
*
|
|
683
|
-
*
|
|
684
|
-
*
|
|
685
|
-
* to the parameter count the library release knows — wrong on networks whose cost
|
|
686
|
-
* model has grown past that (ScriptIntegrityHashMismatch at submit). This recompute
|
|
687
|
-
* with _languageViewCostModels (raw chain arrays) is where the hash becomes correct.
|
|
678
|
+
* Still not implemented via TxBuilder.overrideTxRedeemers, although buildooor
|
|
679
|
+
* 0.2.9 fixed its old-witness-set hashing (our PR): that method hashes with the
|
|
680
|
+
* builder's named-key cost models, which clamp the chain array to the parameter
|
|
681
|
+
* count the library release knows — wrong whenever the on-chain cost model has
|
|
682
|
+
* grown past that (ScriptIntegrityHashMismatch at submit). This recompute with
|
|
683
|
+
* _languageViewCostModels (raw chain arrays) stays governance-proof, so the hash
|
|
684
|
+
* is recomputed here even when the target units already match.
|
|
688
685
|
*/
|
|
689
686
|
_stampExecUnits(tx, targets) {
|
|
690
687
|
const rdmrs = tx.witnesses.redeemers ?? [];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TxBuildRequest } from '../../utils/types';
|
|
2
|
+
import type { Network } from '../cardano-client';
|
|
3
|
+
import type { WalletJobKindValue } from './job-store';
|
|
4
|
+
/**
|
|
5
|
+
* Transform a stored wallet-job `requestJson` (the documented Build*-action
|
|
6
|
+
* payload shape — assetsJson, mintActionsJson, metadataJson strings, …) into
|
|
7
|
+
* the TxBuildRequest shape the CardanoIndexer build methods expect (assets,
|
|
8
|
+
* mintActions with bigint quantities, parsed metadata, assembled
|
|
9
|
+
* plutusScriptExecution, …).
|
|
10
|
+
*
|
|
11
|
+
* The synchronous CardanoTransactionService handlers do this transformation
|
|
12
|
+
* inline per action; the worker executes the SAME payload asynchronously, so
|
|
13
|
+
* this module mirrors that logic using the shared parsers
|
|
14
|
+
* (srv/utils/tx-request-parsers.ts). Validation failures throw
|
|
15
|
+
* BackendError 400 INVALID_INPUT — deterministic, so the job fails terminally
|
|
16
|
+
* instead of burning retries.
|
|
17
|
+
*/
|
|
18
|
+
type RawRequest = Record<string, unknown>;
|
|
19
|
+
/**
|
|
20
|
+
* Transform the raw job request (documented Build*-action payload) into the
|
|
21
|
+
* TxBuildRequest the matching CardanoIndexer build method expects. Throws
|
|
22
|
+
* BackendError 400 INVALID_INPUT for malformed payloads (terminal job failure).
|
|
23
|
+
*/
|
|
24
|
+
export declare function prepareWorkerBuildRequest(kind: WalletJobKindValue, raw: RawRequest, network: Network): TxBuildRequest;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=build-request.d.ts.map
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareWorkerBuildRequest = prepareWorkerBuildRequest;
|
|
4
|
+
const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
5
|
+
const errors_1 = require("../../utils/errors");
|
|
6
|
+
const error_codes_1 = require("../../utils/error-codes");
|
|
7
|
+
const validators_1 = require("../../utils/validators");
|
|
8
|
+
const tx_request_parsers_1 = require("../../utils/tx-request-parsers");
|
|
9
|
+
const tx_build_helper_1 = require("../../utils/tx-build-helper");
|
|
10
|
+
const mappers_1 = require("../../utils/mappers");
|
|
11
|
+
const const_1 = require("../../utils/const");
|
|
12
|
+
function fail(message) {
|
|
13
|
+
throw new errors_1.BackendError(message, 400, error_codes_1.ERROR_CODES.INVALID_INPUT);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Presence-only check for required payload fields. Format validation (bech32,
|
|
17
|
+
* hex, amounts) deliberately stays with the builder/indexer, mirroring what a
|
|
18
|
+
* missing field would produce on the synchronous path — the transform's job is
|
|
19
|
+
* the SHAPE, not re-validating content.
|
|
20
|
+
*/
|
|
21
|
+
function requirePresent(raw, required) {
|
|
22
|
+
const missing = required.filter((f) => raw[f] === undefined || raw[f] === null || raw[f] === '');
|
|
23
|
+
if (missing.length > 0)
|
|
24
|
+
fail(`${missing.join(', ')} ${missing.length === 1 ? 'is' : 'are'} required`);
|
|
25
|
+
}
|
|
26
|
+
function parseJsonField(raw, field) {
|
|
27
|
+
const value = raw[field];
|
|
28
|
+
if (value == null)
|
|
29
|
+
return undefined;
|
|
30
|
+
if (typeof value !== 'string')
|
|
31
|
+
fail(`${field} must be a JSON string`);
|
|
32
|
+
const result = (0, validators_1.validateJsonWithLimits)(value, field);
|
|
33
|
+
if (!result.valid)
|
|
34
|
+
fail(result.error);
|
|
35
|
+
return result.parsed;
|
|
36
|
+
}
|
|
37
|
+
function parseScriptParams(raw) {
|
|
38
|
+
const parsed = parseJsonField(raw, 'scriptParamsJson');
|
|
39
|
+
if (parsed === undefined)
|
|
40
|
+
return undefined;
|
|
41
|
+
if (!Array.isArray(parsed))
|
|
42
|
+
fail('scriptParamsJson must be a JSON array');
|
|
43
|
+
return parsed;
|
|
44
|
+
}
|
|
45
|
+
/** Mirrors the BuildMint/BuildPlutusSpend mint-action parsing (bigint quantities). */
|
|
46
|
+
function parseMintActions(raw, allowBareNames) {
|
|
47
|
+
const parsed = parseJsonField(raw, 'mintActionsJson');
|
|
48
|
+
if (!Array.isArray(parsed))
|
|
49
|
+
fail('mintActionsJson must be a JSON array');
|
|
50
|
+
return parsed.map((rawAction) => {
|
|
51
|
+
if (!rawAction || typeof rawAction !== 'object') {
|
|
52
|
+
fail('Each mint action must be an object with assetUnit and quantity');
|
|
53
|
+
}
|
|
54
|
+
const action = rawAction;
|
|
55
|
+
if (typeof action.quantity !== 'string' || !/^-?\d+$/.test(action.quantity)) {
|
|
56
|
+
fail(`Invalid quantity: "${String(action.quantity)}" — must be an integer string`);
|
|
57
|
+
}
|
|
58
|
+
if (typeof action.assetUnit !== 'string')
|
|
59
|
+
fail('Each mint action must have an assetUnit string');
|
|
60
|
+
const bareAssetNameForExpansion = allowBareNames &&
|
|
61
|
+
action.assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH &&
|
|
62
|
+
action.assetUnit.length % 2 === 0 &&
|
|
63
|
+
/^[0-9a-fA-F]*$/.test(action.assetUnit);
|
|
64
|
+
if (!(0, validators_1.isAssetUnit)(action.assetUnit) && !bareAssetNameForExpansion) {
|
|
65
|
+
fail(`Invalid assetUnit: "${action.assetUnit}" — must be policyId+assetName hex (or a bare assetName hex when scriptParamsJson is set)`);
|
|
66
|
+
}
|
|
67
|
+
return { assetUnit: action.assetUnit, quantity: BigInt(action.quantity) };
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function scriptHashOf(scriptHex, context) {
|
|
71
|
+
try {
|
|
72
|
+
return cardano_ledger_ts_1.Script.fromCbor(Buffer.from(scriptHex, 'hex')).hash.toString();
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
return fail(`${context}: ${err instanceof Error ? err.message : String(err)}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* BUG 9 mirror: every (expanded) mint action must carry the effective policy id —
|
|
80
|
+
* parseAssetUnit silently discards the first 56 hex chars, so a mismatched prefix
|
|
81
|
+
* would mint a truncated asset name.
|
|
82
|
+
*/
|
|
83
|
+
function assertPolicyPrefix(actions, policyId) {
|
|
84
|
+
const mismatch = actions.find((a) => !a.assetUnit.toLowerCase().startsWith(policyId));
|
|
85
|
+
if (mismatch) {
|
|
86
|
+
fail(`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)`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function takeParsed(result) {
|
|
90
|
+
if (result.error)
|
|
91
|
+
fail(result.error);
|
|
92
|
+
return result.parsed;
|
|
93
|
+
}
|
|
94
|
+
function prepareSimpleAda(raw, network) {
|
|
95
|
+
requirePresent(raw, ['senderAddress', 'recipientAddress', 'lovelaceAmount']);
|
|
96
|
+
const clean = { ...raw };
|
|
97
|
+
clean.forceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.forceInputsJson, 'forceInputsJson'));
|
|
98
|
+
delete clean.forceInputsJson;
|
|
99
|
+
const outputDatum = parseJsonField(raw, 'outputDatumJson');
|
|
100
|
+
if (outputDatum !== undefined)
|
|
101
|
+
clean.outputDatum = outputDatum;
|
|
102
|
+
delete clean.outputDatumJson;
|
|
103
|
+
const assets = takeParsed((0, tx_request_parsers_1.parseAssetsArray)(raw.assetsJson, 'assetsJson'));
|
|
104
|
+
if (assets)
|
|
105
|
+
clean.assets = assets;
|
|
106
|
+
delete clean.assetsJson;
|
|
107
|
+
const scriptParams = parseScriptParams(raw);
|
|
108
|
+
if (raw.lockOnScript) {
|
|
109
|
+
const validatorScript = raw.validatorScript;
|
|
110
|
+
if (typeof validatorScript !== 'string' || !validatorScript) {
|
|
111
|
+
fail('lockOnScript requires validatorScript to derive the script address');
|
|
112
|
+
}
|
|
113
|
+
const finalScript = scriptParams && scriptParams.length > 0
|
|
114
|
+
? (0, tx_build_helper_1.applyScriptParameters)(validatorScript, scriptParams)
|
|
115
|
+
: validatorScript;
|
|
116
|
+
clean.recipientAddress = (0, mappers_1.scriptHashToEnterpriseAddress)(scriptHashOf(finalScript, 'Failed to derive script address'), network);
|
|
117
|
+
}
|
|
118
|
+
delete clean.validatorScript;
|
|
119
|
+
delete clean.scriptParamsJson;
|
|
120
|
+
delete clean.lockOnScript;
|
|
121
|
+
if (raw.referenceScriptHex)
|
|
122
|
+
clean.referenceScript = raw.referenceScriptHex;
|
|
123
|
+
delete clean.referenceScriptHex;
|
|
124
|
+
return clean;
|
|
125
|
+
}
|
|
126
|
+
function prepareMetadata(raw) {
|
|
127
|
+
requirePresent(raw, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'metadataJson']);
|
|
128
|
+
const parsedMetadata = parseJsonField(raw, 'metadataJson');
|
|
129
|
+
return { ...raw, metadataJson: parsedMetadata };
|
|
130
|
+
}
|
|
131
|
+
function prepareMultiAsset(raw) {
|
|
132
|
+
requirePresent(raw, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'assetsJson']);
|
|
133
|
+
const assets = takeParsed((0, tx_request_parsers_1.parseAssetsArray)(raw.assetsJson, 'assetsJson'));
|
|
134
|
+
if (!assets || assets.length === 0)
|
|
135
|
+
fail('assetsJson must contain at least one asset');
|
|
136
|
+
const clean = { ...raw, assets };
|
|
137
|
+
delete clean.assetsJson;
|
|
138
|
+
const outputDatum = parseJsonField(raw, 'outputDatumJson');
|
|
139
|
+
if (outputDatum !== undefined)
|
|
140
|
+
clean.outputDatum = outputDatum;
|
|
141
|
+
delete clean.outputDatumJson;
|
|
142
|
+
if (raw.referenceScriptHex)
|
|
143
|
+
clean.referenceScript = raw.referenceScriptHex;
|
|
144
|
+
delete clean.referenceScriptHex;
|
|
145
|
+
return clean;
|
|
146
|
+
}
|
|
147
|
+
function prepareMint(raw, network) {
|
|
148
|
+
requirePresent(raw, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'mintActionsJson', 'mintingPolicyScript']);
|
|
149
|
+
const scriptParams = parseScriptParams(raw);
|
|
150
|
+
const mintActions = parseMintActions(raw, !!scriptParams);
|
|
151
|
+
const requiredSigners = takeParsed((0, tx_request_parsers_1.parseRequiredSigners)(raw.requiredSignersJson));
|
|
152
|
+
const inlineDatum = parseJsonField(raw, 'inlineDatumJson');
|
|
153
|
+
const mintRedeemer = parseJsonField(raw, 'mintRedeemerJson');
|
|
154
|
+
const forceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.forceInputsJson, 'forceInputsJson'));
|
|
155
|
+
const referenceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.referenceInputsJson, 'referenceInputsJson'));
|
|
156
|
+
if (raw.lockOnScript && (!scriptParams || scriptParams.length === 0)) {
|
|
157
|
+
fail('lockOnScript requires scriptParamsJson to derive script address');
|
|
158
|
+
}
|
|
159
|
+
let parsedMetadata;
|
|
160
|
+
if (raw.metadataJson) {
|
|
161
|
+
parsedMetadata = parseJsonField(raw, 'metadataJson');
|
|
162
|
+
if (typeof parsedMetadata !== 'object' || parsedMetadata === null || Array.isArray(parsedMetadata)) {
|
|
163
|
+
fail('metadataJson must be an object with numeric label keys');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const clean = { ...raw };
|
|
167
|
+
delete clean.mintActionsJson;
|
|
168
|
+
delete clean.requiredSignersJson;
|
|
169
|
+
delete clean.scriptParamsJson;
|
|
170
|
+
delete clean.inlineDatumJson;
|
|
171
|
+
delete clean.mintRedeemerJson;
|
|
172
|
+
delete clean.lockOnScript;
|
|
173
|
+
delete clean.forceInputsJson;
|
|
174
|
+
delete clean.referenceInputsJson;
|
|
175
|
+
if (parsedMetadata)
|
|
176
|
+
clean.metadataJson = parsedMetadata;
|
|
177
|
+
else
|
|
178
|
+
delete clean.metadataJson;
|
|
179
|
+
if (raw.referenceScriptHex)
|
|
180
|
+
clean.referenceScript = raw.referenceScriptHex;
|
|
181
|
+
delete clean.referenceScriptHex;
|
|
182
|
+
// Apply script parameters (parameterized policies), expand bare asset names,
|
|
183
|
+
// route lockOnScript output — mirrors BuildMintTransaction.
|
|
184
|
+
let finalMintingPolicyScript = raw.mintingPolicyScript;
|
|
185
|
+
let effectivePolicyId;
|
|
186
|
+
if (scriptParams && scriptParams.length > 0) {
|
|
187
|
+
try {
|
|
188
|
+
finalMintingPolicyScript = (0, tx_build_helper_1.applyScriptParameters)(raw.mintingPolicyScript, scriptParams);
|
|
189
|
+
}
|
|
190
|
+
catch (err) {
|
|
191
|
+
fail(`Failed to apply script parameters: ${err instanceof Error ? err.message : String(err)}`);
|
|
192
|
+
}
|
|
193
|
+
effectivePolicyId = scriptHashOf(finalMintingPolicyScript, 'Failed to hash applied script');
|
|
194
|
+
for (const action of mintActions) {
|
|
195
|
+
if (action.assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
196
|
+
action.assetUnit = effectivePolicyId + action.assetUnit;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (raw.lockOnScript) {
|
|
200
|
+
clean.recipientAddress = (0, mappers_1.scriptHashToEnterpriseAddress)(effectivePolicyId, network);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
try {
|
|
205
|
+
effectivePolicyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(raw.mintingPolicyScript, 'hex')).hash.toString();
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
// invalid script CBOR — skip the prefix check; the builder rejects it with its own message
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (effectivePolicyId)
|
|
212
|
+
assertPolicyPrefix(mintActions, effectivePolicyId);
|
|
213
|
+
return {
|
|
214
|
+
...clean,
|
|
215
|
+
mintActions,
|
|
216
|
+
mintingPolicyScript: finalMintingPolicyScript,
|
|
217
|
+
requiredSigners,
|
|
218
|
+
inlineDatum,
|
|
219
|
+
mintRedeemer,
|
|
220
|
+
forceInputs,
|
|
221
|
+
referenceInputs,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
function preparePlutusSpend(raw, network) {
|
|
225
|
+
requirePresent(raw, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'validatorScript', 'scriptTxHash', 'redeemerJson']);
|
|
226
|
+
if (raw.scriptOutputIndex === undefined || raw.scriptOutputIndex === null) {
|
|
227
|
+
fail('scriptOutputIndex is required');
|
|
228
|
+
}
|
|
229
|
+
const parsedRedeemer = parseJsonField(raw, 'redeemerJson');
|
|
230
|
+
const parsedDatum = parseJsonField(raw, 'datumJson');
|
|
231
|
+
const requiredSigners = takeParsed((0, tx_request_parsers_1.parseRequiredSigners)(raw.requiredSignersJson));
|
|
232
|
+
const scriptParams = parseScriptParams(raw);
|
|
233
|
+
const inlineDatum = parseJsonField(raw, 'inlineDatumJson');
|
|
234
|
+
if (raw.lockOnScript && (!scriptParams || scriptParams.length === 0)) {
|
|
235
|
+
fail('lockOnScript requires scriptParamsJson to derive script address');
|
|
236
|
+
}
|
|
237
|
+
const forceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.forceInputsJson, 'forceInputsJson'));
|
|
238
|
+
const referenceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.referenceInputsJson, 'referenceInputsJson'));
|
|
239
|
+
const extraOutputs = takeParsed((0, tx_request_parsers_1.parseExtraOutputs)(raw.extraOutputsJson));
|
|
240
|
+
// Optional combined spend+mint (FR-1) — mirrors BuildPlutusSpendTransaction.
|
|
241
|
+
const validatorScript = raw.validatorScript;
|
|
242
|
+
const mintingPolicyScript = raw.mintingPolicyScript;
|
|
243
|
+
let mintActions;
|
|
244
|
+
let mintRedeemer;
|
|
245
|
+
if (raw.mintActionsJson) {
|
|
246
|
+
if (!mintingPolicyScript)
|
|
247
|
+
fail('mintActionsJson requires mintingPolicyScript');
|
|
248
|
+
mintActions = parseMintActions(raw, !!scriptParams && mintingPolicyScript === validatorScript);
|
|
249
|
+
mintRedeemer = parseJsonField(raw, 'mintRedeemerJson');
|
|
250
|
+
}
|
|
251
|
+
else if (mintingPolicyScript || raw.mintRedeemerJson) {
|
|
252
|
+
fail('mintingPolicyScript / mintRedeemerJson require mintActionsJson');
|
|
253
|
+
}
|
|
254
|
+
let finalValidatorScript = validatorScript;
|
|
255
|
+
if (scriptParams && scriptParams.length > 0) {
|
|
256
|
+
try {
|
|
257
|
+
finalValidatorScript = (0, tx_build_helper_1.applyScriptParameters)(validatorScript, scriptParams);
|
|
258
|
+
}
|
|
259
|
+
catch (err) {
|
|
260
|
+
fail(`Failed to apply script parameters: ${err instanceof Error ? err.message : String(err)}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
let finalMintingPolicyScript;
|
|
264
|
+
if (mintActions) {
|
|
265
|
+
finalMintingPolicyScript = (mintingPolicyScript === validatorScript) ? finalValidatorScript : mintingPolicyScript;
|
|
266
|
+
if (finalMintingPolicyScript && scriptParams && scriptParams.length > 0 && mintingPolicyScript === validatorScript) {
|
|
267
|
+
const appliedPolicyId = scriptHashOf(finalMintingPolicyScript, 'Failed to hash applied script');
|
|
268
|
+
for (const action of mintActions) {
|
|
269
|
+
if (action.assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
270
|
+
action.assetUnit = appliedPolicyId + action.assetUnit;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (finalMintingPolicyScript) {
|
|
275
|
+
let mintPolicyId;
|
|
276
|
+
try {
|
|
277
|
+
mintPolicyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(finalMintingPolicyScript, 'hex')).hash.toString();
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
// invalid script CBOR — skip the prefix check; the builder rejects it with its own message
|
|
281
|
+
}
|
|
282
|
+
if (mintPolicyId)
|
|
283
|
+
assertPolicyPrefix(mintActions, mintPolicyId);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
const clean = {
|
|
287
|
+
...raw,
|
|
288
|
+
plutusScriptExecution: {
|
|
289
|
+
validatorScript: finalValidatorScript,
|
|
290
|
+
scriptUtxo: {
|
|
291
|
+
txHash: raw.scriptTxHash,
|
|
292
|
+
outputIndex: raw.scriptOutputIndex,
|
|
293
|
+
},
|
|
294
|
+
redeemer: parsedRedeemer,
|
|
295
|
+
datum: parsedDatum,
|
|
296
|
+
},
|
|
297
|
+
requiredSigners,
|
|
298
|
+
inlineDatum,
|
|
299
|
+
forceInputs,
|
|
300
|
+
referenceInputs,
|
|
301
|
+
extraOutputs,
|
|
302
|
+
mintActions,
|
|
303
|
+
mintingPolicyScript: finalMintingPolicyScript,
|
|
304
|
+
mintRedeemer,
|
|
305
|
+
};
|
|
306
|
+
if (raw.referenceScriptHex)
|
|
307
|
+
clean.referenceScript = raw.referenceScriptHex;
|
|
308
|
+
delete clean.requiredSignersJson;
|
|
309
|
+
delete clean.scriptParamsJson;
|
|
310
|
+
delete clean.inlineDatumJson;
|
|
311
|
+
delete clean.forceInputsJson;
|
|
312
|
+
delete clean.referenceInputsJson;
|
|
313
|
+
delete clean.extraOutputsJson;
|
|
314
|
+
delete clean.mintActionsJson;
|
|
315
|
+
delete clean.mintRedeemerJson;
|
|
316
|
+
delete clean.referenceScriptHex;
|
|
317
|
+
delete clean.redeemerJson;
|
|
318
|
+
delete clean.datumJson;
|
|
319
|
+
if (raw.lockOnScript && scriptParams && scriptParams.length > 0) {
|
|
320
|
+
clean.recipientAddress = (0, mappers_1.scriptHashToEnterpriseAddress)(scriptHashOf(finalValidatorScript, 'Failed to derive script address'), network);
|
|
321
|
+
}
|
|
322
|
+
delete clean.lockOnScript;
|
|
323
|
+
return clean;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Transform the raw job request (documented Build*-action payload) into the
|
|
327
|
+
* TxBuildRequest the matching CardanoIndexer build method expects. Throws
|
|
328
|
+
* BackendError 400 INVALID_INPUT for malformed payloads (terminal job failure).
|
|
329
|
+
*/
|
|
330
|
+
function prepareWorkerBuildRequest(kind, raw, network) {
|
|
331
|
+
switch (kind) {
|
|
332
|
+
case 'simpleAda': return prepareSimpleAda(raw, network);
|
|
333
|
+
case 'metadata': return prepareMetadata(raw);
|
|
334
|
+
case 'multiAsset': return prepareMultiAsset(raw);
|
|
335
|
+
case 'mint': return prepareMint(raw, network);
|
|
336
|
+
case 'plutusSpend': return preparePlutusSpend(raw, network);
|
|
337
|
+
default:
|
|
338
|
+
return fail(`Unsupported job kind "${String(kind)}"`);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
//# sourceMappingURL=build-request.js.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { CardanoClient } from '../cardano-client';
|
|
2
|
+
/**
|
|
3
|
+
* Confirmation tracker (v2.0, design §7).
|
|
4
|
+
*
|
|
5
|
+
* Watches `submitted` jobs until their tx sits at depth ≥ `confirmationDepth`:
|
|
6
|
+
* - Crawler hook (preferred, zero extra load): `blockIndexed` events match
|
|
7
|
+
* submitted tx hashes and carry the advancing tip; `reorg` events invalidate
|
|
8
|
+
* confirmation points behind the fork and optionally re-submit the SAME
|
|
9
|
+
* signed CBOR (never a rebuild — the double-spend guard).
|
|
10
|
+
* - Polling fallback (always on, hook path just accelerates): every
|
|
11
|
+
* `pollIntervalMs` unfound txs are looked up via `client.getTransaction`
|
|
12
|
+
* and the tip via `client.getLatestBlock`.
|
|
13
|
+
*
|
|
14
|
+
* A tx that stays unseen past `confirmationTimeoutMs` fails as TX_DROPPED —
|
|
15
|
+
* safe to retry from the caller, because the guard is the on-chain lookup itself.
|
|
16
|
+
*
|
|
17
|
+
* Confirmations are counted as `tipHeight - foundHeight + 1`, so depth 1 means
|
|
18
|
+
* "confirmed as soon as included in a block".
|
|
19
|
+
*/
|
|
20
|
+
export interface TrackedJob {
|
|
21
|
+
jobId: string;
|
|
22
|
+
walletId: string;
|
|
23
|
+
/** Job kind, carried so terminal events can name it without a DB read. */
|
|
24
|
+
kind: string | null;
|
|
25
|
+
txHash: string;
|
|
26
|
+
signedTxCbor: string | null;
|
|
27
|
+
/** ISO timestamp of mempool acceptance (timeout base). */
|
|
28
|
+
submittedAt: string;
|
|
29
|
+
foundSlot: number | null;
|
|
30
|
+
foundHeight: number | null;
|
|
31
|
+
}
|
|
32
|
+
export interface ConfirmationTrackerOptions {
|
|
33
|
+
confirmationDepth: number;
|
|
34
|
+
confirmationTimeoutMs: number;
|
|
35
|
+
pollIntervalMs: number;
|
|
36
|
+
resubmitOnRollback: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface ConfirmationTrackerDeps {
|
|
39
|
+
client: CardanoClient;
|
|
40
|
+
options: ConfirmationTrackerOptions;
|
|
41
|
+
/** Called exactly once per job when it reaches a terminal state. */
|
|
42
|
+
onFinal?: (job: {
|
|
43
|
+
jobId: string;
|
|
44
|
+
walletId: string;
|
|
45
|
+
outcome: 'confirmed' | 'failed';
|
|
46
|
+
kind: string | null;
|
|
47
|
+
/** The tracked transaction — present even on failure (it was submitted). */
|
|
48
|
+
txHash: string;
|
|
49
|
+
errorCode?: string;
|
|
50
|
+
errorMessage?: string;
|
|
51
|
+
}) => void;
|
|
52
|
+
}
|
|
53
|
+
export declare class ConfirmationTracker {
|
|
54
|
+
private readonly deps;
|
|
55
|
+
private readonly pending;
|
|
56
|
+
private readonly blockListener;
|
|
57
|
+
private readonly reorgListener;
|
|
58
|
+
private pollTimer;
|
|
59
|
+
private running;
|
|
60
|
+
private polling;
|
|
61
|
+
private lastKnownTipHeight;
|
|
62
|
+
constructor(deps: ConfirmationTrackerDeps);
|
|
63
|
+
start(): void;
|
|
64
|
+
stop(): void;
|
|
65
|
+
/** Number of jobs currently awaiting confirmation. */
|
|
66
|
+
size(): number;
|
|
67
|
+
/** Register a submitted job for confirmation watching. Idempotent per jobId. */
|
|
68
|
+
track(job: {
|
|
69
|
+
jobId: string;
|
|
70
|
+
walletId: string;
|
|
71
|
+
kind?: string | null;
|
|
72
|
+
txHash: string;
|
|
73
|
+
signedTxCbor: string | null;
|
|
74
|
+
submittedAt?: string | null;
|
|
75
|
+
confirmedSlot?: number | null;
|
|
76
|
+
confirmedHeight?: number | null;
|
|
77
|
+
}): void;
|
|
78
|
+
private onBlockIndexed;
|
|
79
|
+
private onReorg;
|
|
80
|
+
/** One polling round. Public for tests; guarded against overlapping rounds. */
|
|
81
|
+
pollOnce(): Promise<void>;
|
|
82
|
+
/** Confirm every found job whose depth requirement is met by the known tip. */
|
|
83
|
+
private confirmMature;
|
|
84
|
+
private finalize;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=confirmation-tracker.d.ts.map
|