@odatano/core 1.9.4 → 1.9.5
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/package.json +1 -1
- package/srv/cardano-tx-service.js +50 -7
package/package.json
CHANGED
|
@@ -465,13 +465,13 @@ module.exports = (srv) => {
|
|
|
465
465
|
delete cleanData.referenceScriptHex;
|
|
466
466
|
// Apply script parameters if provided (for parameterized validators)
|
|
467
467
|
let finalMintingPolicyScript = mintingPolicyScript;
|
|
468
|
+
let effectivePolicyId;
|
|
468
469
|
if (scriptParams && scriptParams.length > 0) {
|
|
469
|
-
let appliedPolicyId;
|
|
470
470
|
try {
|
|
471
471
|
finalMintingPolicyScript = (0, tx_build_helper_1.applyScriptParameters)(mintingPolicyScript, scriptParams);
|
|
472
472
|
// BUG 7 fix: expand assetName-only entries to full assetUnit using the applied script's policyId.
|
|
473
473
|
const appliedScript = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(finalMintingPolicyScript, 'hex'));
|
|
474
|
-
|
|
474
|
+
effectivePolicyId = appliedScript.hash.toString();
|
|
475
475
|
}
|
|
476
476
|
catch (err) {
|
|
477
477
|
const errMsg = err instanceof Error ? err.message : String(err);
|
|
@@ -479,14 +479,34 @@ module.exports = (srv) => {
|
|
|
479
479
|
}
|
|
480
480
|
for (const action of parsedMintActions) {
|
|
481
481
|
if (action.assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
482
|
-
action.assetUnit =
|
|
482
|
+
action.assetUnit = effectivePolicyId + action.assetUnit;
|
|
483
483
|
}
|
|
484
484
|
}
|
|
485
485
|
// lockOnScript: route output to the enterprise script address derived from applied script hash
|
|
486
486
|
if (lockOnScript) {
|
|
487
|
-
const scriptAddr = (0, mappers_1.scriptHashToEnterpriseAddress)(
|
|
487
|
+
const scriptAddr = (0, mappers_1.scriptHashToEnterpriseAddress)(effectivePolicyId, (0, server_1.getCardanoClient)().network);
|
|
488
488
|
cleanData.recipientAddress = scriptAddr;
|
|
489
|
-
logger.debug({ scriptAddress: scriptAddr, scriptHash:
|
|
489
|
+
logger.debug({ scriptAddress: scriptAddr, scriptHash: effectivePolicyId }, 'lockOnScript: routing output to script address');
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
493
|
+
try {
|
|
494
|
+
effectivePolicyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(mintingPolicyScript, 'hex')).hash.toString();
|
|
495
|
+
}
|
|
496
|
+
catch {
|
|
497
|
+
// invalid script CBOR — skip the prefix check; the builder rejects it with its own message
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
// BUG 9 fix: the builder mints every action under the policy script's hash and
|
|
501
|
+
// parseAssetUnit silently discards the unit's first 56 hex chars. A bare asset name
|
|
502
|
+
// of 29-32 bytes is length-indistinguishable from a full unit, so a mismatched
|
|
503
|
+
// prefix would mint a truncated name. At this point every action holds a full
|
|
504
|
+
// unit (bare names were expanded above), so all of them must carry the policyId.
|
|
505
|
+
if (effectivePolicyId) {
|
|
506
|
+
const policyId = effectivePolicyId;
|
|
507
|
+
const mismatch = parsedMintActions.find((action) => !action.assetUnit.toLowerCase().startsWith(policyId));
|
|
508
|
+
if (mismatch) {
|
|
509
|
+
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');
|
|
490
510
|
}
|
|
491
511
|
}
|
|
492
512
|
const buildResult = await (0, server_1.getCardanoIndexer)().indexMintBuildResult(db, {
|
|
@@ -503,10 +523,13 @@ module.exports = (srv) => {
|
|
|
503
523
|
if (buildResult.scriptHash) {
|
|
504
524
|
const policyId = buildResult.scriptHash;
|
|
505
525
|
const updates = {};
|
|
506
|
-
// CIP-14 asset fingerprint for the first minted asset
|
|
526
|
+
// CIP-14 asset fingerprint for the first minted asset. The unit is always a
|
|
527
|
+
// full policyId+assetName here: bare names were expanded before the build and
|
|
528
|
+
// the BUG 9 prefix check rejected everything else (a 56-hex unit is an empty
|
|
529
|
+
// asset name, not a bare 28-byte name).
|
|
507
530
|
if (parsedMintActions.length > 0) {
|
|
508
531
|
const firstAssetUnit = parsedMintActions[0].assetUnit;
|
|
509
|
-
const assetNameHex = firstAssetUnit.
|
|
532
|
+
const assetNameHex = firstAssetUnit.slice(const_1.POLICY_ID_HEX_LENGTH);
|
|
510
533
|
buildResult.fingerprint = (0, mappers_1.computeCip14Fingerprint)(policyId, assetNameHex);
|
|
511
534
|
updates.fingerprint = buildResult.fingerprint;
|
|
512
535
|
}
|
|
@@ -670,6 +693,26 @@ module.exports = (srv) => {
|
|
|
670
693
|
}
|
|
671
694
|
}
|
|
672
695
|
}
|
|
696
|
+
// BUG 9 fix: same policyId-prefix check as BuildMintTransaction — the builder
|
|
697
|
+
// mints every action under the mint script's hash and parseAssetUnit silently
|
|
698
|
+
// discards the unit's first 56 hex chars, so a mismatched prefix would mint a
|
|
699
|
+
// truncated asset name.
|
|
700
|
+
if (finalMintingPolicyScript) {
|
|
701
|
+
let mintPolicyId;
|
|
702
|
+
try {
|
|
703
|
+
mintPolicyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(finalMintingPolicyScript, 'hex')).hash.toString();
|
|
704
|
+
}
|
|
705
|
+
catch {
|
|
706
|
+
// invalid script CBOR — skip the prefix check; the builder rejects it with its own message
|
|
707
|
+
}
|
|
708
|
+
if (mintPolicyId) {
|
|
709
|
+
const policyId = mintPolicyId;
|
|
710
|
+
const mismatch = parsedMintActions.find((action) => !action.assetUnit.toLowerCase().startsWith(policyId));
|
|
711
|
+
if (mismatch) {
|
|
712
|
+
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');
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
673
716
|
}
|
|
674
717
|
const cleanData = {
|
|
675
718
|
...req.data,
|