@odatano/core 2.0.0-rc.5 → 2.0.0-rc.51
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 +99 -51
- package/@cds-models/CardanoAgentService/index.js +15 -0
- package/@cds-models/CardanoBackendService/index.d.ts +358 -0
- package/@cds-models/CardanoBackendService/index.js +41 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +594 -11
- package/@cds-models/CardanoIndexerService/index.js +74 -0
- package/@cds-models/CardanoODataService/index.d.ts +417 -57
- package/@cds-models/CardanoODataService/index.js +42 -0
- package/@cds-models/CardanoSignService/index.d.ts +45 -19
- package/@cds-models/CardanoSignService/index.js +4 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +70 -44
- package/@cds-models/CardanoTransactionService/index.js +5 -0
- package/@cds-models/CardanoWorkerService/index.d.ts +35 -22
- package/@cds-models/CardanoWorkerService/index.js +2 -0
- package/@cds-models/index.d.ts +114 -4
- package/@cds-models/index.js +20 -4
- package/@cds-models/odatano/cardano/index.d.ts +451 -32
- package/@cds-models/odatano/cardano/index.js +48 -0
- package/README.md +103 -167
- package/db/schema.cds +2455 -1705
- package/db/types.cds +456 -295
- package/package.json +41 -53
- package/scripts/deploy-schema.mjs +113 -0
- package/scripts/migrate-schema.mjs +528 -0
- package/scripts/migrate-slot-leader.mjs +96 -0
- package/src/index.d.ts +20 -21
- package/src/index.js +45 -31
- package/src/plugin.js +17 -35
- package/srv/blockchain/asset-decimals.d.ts +7 -0
- package/srv/blockchain/asset-decimals.js +91 -0
- package/srv/blockchain/backends/blockfrost-backend.d.ts +25 -137
- package/srv/blockchain/backends/blockfrost-backend.js +125 -215
- package/srv/blockchain/backends/call-signal.d.ts +7 -0
- package/srv/blockchain/backends/call-signal.js +22 -0
- package/srv/blockchain/backends/cardano-backend.d.ts +100 -189
- package/srv/blockchain/backends/cardano-backend.js +29 -5
- package/srv/blockchain/backends/koios-backend.d.ts +108 -170
- package/srv/blockchain/backends/koios-backend.js +488 -482
- package/srv/blockchain/backends/odatano-backend.d.ts +55 -0
- package/srv/blockchain/backends/odatano-backend.js +211 -0
- package/srv/blockchain/backends/ogmios-backend.d.ts +122 -190
- package/srv/blockchain/backends/ogmios-backend.js +683 -327
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +14 -0
- package/srv/blockchain/backends/ogmios-frame-guard.js +89 -0
- package/srv/blockchain/cardano-client.d.ts +71 -241
- package/srv/blockchain/cardano-client.js +354 -322
- package/srv/blockchain/cardano-indexer.d.ts +295 -283
- package/srv/blockchain/cardano-indexer.js +1690 -502
- package/srv/blockchain/cardano-tx-builder.d.ts +25 -89
- package/srv/blockchain/cardano-tx-builder.js +164 -140
- package/srv/blockchain/circuit-breaker.d.ts +2 -13
- package/srv/blockchain/circuit-breaker.js +11 -15
- package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
- package/srv/blockchain/crawler/account-snapshots.js +173 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +17 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
- package/srv/blockchain/crawler/asset-registry-backfill.d.ts +46 -0
- package/srv/blockchain/crawler/asset-registry-backfill.js +157 -0
- package/srv/blockchain/crawler/asset-slice-backfill.d.ts +35 -0
- package/srv/blockchain/crawler/asset-slice-backfill.js +149 -0
- package/srv/blockchain/crawler/certificate-backfill.d.ts +56 -0
- package/srv/blockchain/crawler/certificate-backfill.js +174 -0
- package/srv/blockchain/crawler/crawler.d.ts +125 -81
- package/srv/blockchain/crawler/crawler.js +738 -167
- package/srv/blockchain/crawler/credential-backfill.d.ts +30 -0
- package/srv/blockchain/crawler/credential-backfill.js +101 -0
- package/srv/blockchain/crawler/hooks.d.ts +2 -17
- package/srv/blockchain/crawler/index.d.ts +1 -8
- package/srv/blockchain/crawler/index.js +31 -17
- package/srv/blockchain/crawler/input-asset-copies.d.ts +34 -0
- package/srv/blockchain/crawler/input-asset-copies.js +161 -0
- package/srv/blockchain/crawler/key-pages.d.ts +12 -0
- package/srv/blockchain/crawler/key-pages.js +48 -0
- package/srv/blockchain/crawler/metadata-position-backfill.d.ts +22 -0
- package/srv/blockchain/crawler/metadata-position-backfill.js +59 -0
- package/srv/blockchain/crawler/output-datum-backfill.d.ts +41 -0
- package/srv/blockchain/crawler/output-datum-backfill.js +100 -0
- package/srv/blockchain/crawler/sync-state.d.ts +31 -47
- package/srv/blockchain/crawler/sync-state.js +135 -128
- package/srv/blockchain/crawler/transaction-backfill.d.ts +46 -0
- package/srv/blockchain/crawler/transaction-backfill.js +271 -0
- package/srv/blockchain/crawler/utxo-set-import.d.ts +66 -0
- package/srv/blockchain/crawler/utxo-set-import.js +399 -0
- package/srv/blockchain/crawler/window-plan.d.ts +31 -0
- package/srv/blockchain/crawler/window-plan.js +59 -0
- package/srv/blockchain/ledger-state.d.ts +62 -0
- package/srv/blockchain/ledger-state.js +521 -0
- package/srv/blockchain/pending-spends.d.ts +16 -0
- package/srv/blockchain/pending-spends.js +81 -0
- package/srv/blockchain/pool-metadata.d.ts +15 -0
- package/srv/blockchain/pool-metadata.js +132 -0
- package/srv/blockchain/request-coalescer.d.ts +2 -16
- package/srv/blockchain/request-coalescer.js +2 -16
- package/srv/blockchain/signing/cose-verifier.d.ts +3 -17
- package/srv/blockchain/signing/cose-verifier.js +146 -70
- package/srv/blockchain/signing/external-signer.d.ts +15 -115
- package/srv/blockchain/signing/external-signer.js +22 -131
- package/srv/blockchain/signing/failed-recheck.d.ts +17 -0
- package/srv/blockchain/signing/failed-recheck.js +135 -0
- package/srv/blockchain/signing/hsm-signer.d.ts +10 -54
- package/srv/blockchain/signing/hsm-signer.js +28 -79
- package/srv/blockchain/signing/landing-proof.d.ts +60 -0
- package/srv/blockchain/signing/landing-proof.js +224 -0
- package/srv/blockchain/signing/signature-verifier.d.ts +9 -47
- package/srv/blockchain/signing/signature-verifier.js +71 -87
- package/srv/blockchain/signing/submission-finalizer.d.ts +37 -45
- package/srv/blockchain/signing/submission-finalizer.js +280 -86
- package/srv/blockchain/stored-chain.d.ts +19 -0
- package/srv/blockchain/stored-chain.js +258 -0
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +31 -229
- package/srv/blockchain/transaction-building/buildooor-tx.js +663 -421
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +9 -37
- package/srv/blockchain/transaction-presence.d.ts +12 -0
- package/srv/blockchain/transaction-presence.js +29 -0
- package/srv/blockchain/transaction-rows.d.ts +12 -0
- package/srv/blockchain/transaction-rows.js +44 -0
- package/srv/blockchain/wallet-worker/build-request.d.ts +8 -23
- package/srv/blockchain/wallet-worker/build-request.js +40 -353
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +27 -47
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +158 -61
- package/srv/blockchain/wallet-worker/index.d.ts +1 -1
- package/srv/blockchain/wallet-worker/index.js +3 -11
- package/srv/blockchain/wallet-worker/invalidation.d.ts +35 -0
- package/srv/blockchain/wallet-worker/invalidation.js +128 -0
- package/srv/blockchain/wallet-worker/job-store.d.ts +58 -150
- package/srv/blockchain/wallet-worker/job-store.js +200 -273
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -26
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -28
- package/srv/blockchain/wallet-worker/signers.d.ts +5 -24
- package/srv/blockchain/wallet-worker/signers.js +4 -12
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +29 -82
- package/srv/blockchain/wallet-worker/wallet-worker.js +334 -198
- package/srv/cardano-agent-service.cds +122 -84
- package/srv/cardano-agent-service.js +12 -9
- package/srv/cardano-backend-service.cds +81 -0
- package/srv/cardano-backend-service.d.ts +2 -0
- package/srv/cardano-backend-service.js +259 -0
- package/srv/cardano-indexer-service.cds +393 -18
- package/srv/cardano-indexer-service.d.ts +5 -1
- package/srv/cardano-indexer-service.js +477 -16
- package/srv/cardano-service.cds +426 -269
- package/srv/cardano-service.js +640 -217
- package/srv/cardano-sign-service.cds +211 -180
- package/srv/cardano-sign-service.js +210 -287
- package/srv/cardano-tx-service.cds +462 -370
- package/srv/cardano-tx-service.js +283 -800
- package/srv/cardano-ui.cds +16 -16
- package/srv/cardano-worker-service.cds +141 -125
- package/srv/cardano-worker-service.js +104 -61
- package/srv/cbor/cip68.d.ts +13 -0
- package/srv/cbor/cip68.js +56 -0
- package/srv/cbor/index.d.ts +3 -1
- package/srv/cbor/index.js +9 -1
- package/srv/cbor/parse.d.ts +30 -18
- package/srv/cbor/parse.js +44 -9
- package/srv/cbor/plutus-data-json.d.ts +20 -0
- package/srv/cbor/plutus-data-json.js +32 -0
- package/srv/config.d.ts +117 -0
- package/srv/config.js +419 -0
- package/srv/server.d.ts +15 -110
- package/srv/server.js +83 -405
- package/srv/utils/agent-access.d.ts +11 -0
- package/srv/utils/agent-access.js +86 -0
- package/srv/utils/agent-grants-config.d.ts +0 -46
- package/srv/utils/agent-grants-config.js +17 -85
- package/srv/utils/agent-grants.d.ts +106 -122
- package/srv/utils/agent-grants.js +538 -237
- package/srv/utils/agent-token-auth.d.ts +4 -99
- package/srv/utils/agent-token-auth.js +62 -186
- package/srv/utils/backend-request-handler.d.ts +3 -17
- package/srv/utils/backend-request-handler.js +3 -18
- package/srv/utils/build-request.d.ts +52 -0
- package/srv/utils/build-request.js +487 -0
- package/srv/utils/collections.d.ts +4 -10
- package/srv/utils/collections.js +14 -10
- package/srv/utils/const.d.ts +32 -75
- package/srv/utils/const.js +40 -80
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +11 -25
- package/srv/utils/db-indexes.d.ts +31 -0
- package/srv/utils/db-indexes.js +185 -0
- package/srv/utils/db-kind.d.ts +23 -0
- package/srv/utils/db-kind.js +42 -0
- package/srv/utils/db-sanitize.d.ts +20 -0
- package/srv/utils/db-sanitize.js +80 -0
- package/srv/utils/deep-json.d.ts +6 -0
- package/srv/utils/deep-json.js +240 -0
- package/srv/utils/detached-run.d.ts +41 -0
- package/srv/utils/detached-run.js +101 -0
- package/srv/utils/epoch-slots.d.ts +14 -0
- package/srv/utils/epoch-slots.js +45 -0
- package/srv/utils/error-codes.d.ts +26 -75
- package/srv/utils/error-codes.js +27 -72
- package/srv/utils/errors.d.ts +55 -187
- package/srv/utils/errors.js +161 -235
- package/srv/utils/lease.d.ts +20 -0
- package/srv/utils/lease.js +62 -0
- package/srv/utils/liveness.d.ts +12 -0
- package/srv/utils/liveness.js +35 -0
- package/srv/utils/mappers.d.ts +111 -223
- package/srv/utils/mappers.js +432 -371
- package/srv/utils/navigation.d.ts +17 -0
- package/srv/utils/navigation.js +52 -0
- package/srv/utils/network-context.d.ts +0 -1
- package/srv/utils/network-context.js +9 -15
- package/srv/utils/paging.d.ts +31 -0
- package/srv/utils/paging.js +43 -0
- package/srv/utils/pg-inline-json.d.ts +8 -0
- package/srv/utils/pg-inline-json.js +58 -0
- package/srv/utils/pg-order-nulls.d.ts +14 -0
- package/srv/utils/pg-order-nulls.js +54 -0
- package/srv/utils/plutus-placeholders.d.ts +16 -22
- package/srv/utils/plutus-placeholders.js +62 -33
- package/srv/utils/rate-limiter.d.ts +2 -21
- package/srv/utils/rate-limiter.js +5 -17
- package/srv/utils/readiness.d.ts +12 -0
- package/srv/utils/readiness.js +29 -0
- package/srv/utils/reference-script.d.ts +19 -0
- package/srv/utils/reference-script.js +84 -0
- package/srv/utils/resolution.d.ts +13 -0
- package/srv/utils/resolution.js +47 -0
- package/srv/utils/result-numbers.d.ts +15 -0
- package/srv/utils/result-numbers.js +61 -0
- package/srv/utils/row-values.d.ts +7 -0
- package/srv/utils/row-values.js +27 -0
- package/srv/utils/service-events.d.ts +0 -24
- package/srv/utils/service-events.js +3 -25
- package/srv/utils/signing-helper.d.ts +3 -20
- package/srv/utils/signing-helper.js +35 -64
- package/srv/utils/tx-build-helper.d.ts +25 -105
- package/srv/utils/tx-build-helper.js +108 -156
- package/srv/utils/tx-request-parsers.d.ts +82 -33
- package/srv/utils/tx-request-parsers.js +401 -49
- package/srv/utils/tx-utils.d.ts +3 -27
- package/srv/utils/tx-utils.js +32 -50
- package/srv/utils/types.d.ts +294 -232
- package/srv/utils/types.js +2 -22
- package/srv/utils/validators.d.ts +22 -92
- package/srv/utils/validators.js +60 -170
|
@@ -1,25 +1,13 @@
|
|
|
1
1
|
import type { UTxO as OdatanoUtxo, JSONValue } from '../utils/types';
|
|
2
2
|
import { type Data } from '@harmoniclabs/plutus-data';
|
|
3
3
|
import { UPLCConst } from '@harmoniclabs/uplc';
|
|
4
|
-
/**
|
|
5
|
-
* Extract lovelace amount from UTxO
|
|
6
|
-
* @param u UTxO to extract from
|
|
7
|
-
* @returns {bigint} lovelace amount
|
|
8
|
-
*/
|
|
4
|
+
/** Lovelace amount of a UTxO. */
|
|
9
5
|
export declare function getLovelace(u: OdatanoUtxo): bigint;
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* @throws {MixedAssetsError} if UTxO contains non-ADA assets
|
|
14
|
-
*/
|
|
6
|
+
/** A UTxO the builders may take as collateral: lovelace only and no reference script. */
|
|
7
|
+
export declare function isCollateralCandidate(u: OdatanoUtxo): boolean;
|
|
8
|
+
/** Throws MixedAssetsError when the UTxO carries non-ADA assets. */
|
|
15
9
|
export declare function assertAdaOnly(u: OdatanoUtxo): void;
|
|
16
|
-
/**
|
|
17
|
-
* Extract transaction hash from a transaction CBOR (signed or unsigned).
|
|
18
|
-
* Hash is computed over the body, so witness presence does not affect it.
|
|
19
|
-
* @param txCbor transaction in CBOR hex format
|
|
20
|
-
* @returns {string} transaction hash (64 character hex string)
|
|
21
|
-
* @throws {Error} if CBOR is invalid or transaction hash cannot be extracted
|
|
22
|
-
*/
|
|
10
|
+
/** Transaction hash: blake2b-256 over the body bytes, so witnesses do not affect it. */
|
|
23
11
|
export declare function getTxHashFromCbor(txCbor: string): string;
|
|
24
12
|
/** Cache-invalidation targets of a submitted transaction (see extractTxCacheTargets). */
|
|
25
13
|
export interface TxCacheTargets {
|
|
@@ -30,104 +18,36 @@ export interface TxCacheTargets {
|
|
|
30
18
|
}>;
|
|
31
19
|
/** Distinct bech32 addresses receiving outputs (sender change + recipients). */
|
|
32
20
|
outputAddresses: string[];
|
|
21
|
+
/** Outputs of the transaction, every address kind included. */
|
|
22
|
+
outputCount: number;
|
|
23
|
+
/** Last slot in which the transaction is valid (body key 3); null without an expiry. */
|
|
24
|
+
ttlSlot: number | null;
|
|
25
|
+
/** First slot in which the transaction is valid (body key 8); null without a start. */
|
|
26
|
+
validityStartSlot: number | null;
|
|
27
|
+
/** False when the transaction is marked to fail its scripts: then only its collateral is spent. */
|
|
28
|
+
isValid: boolean;
|
|
29
|
+
/** Collateral inputs (body key 13), spent instead of the inputs when the scripts fail. */
|
|
30
|
+
collateralInputs: Array<{
|
|
31
|
+
txHash: string;
|
|
32
|
+
outputIndex: number;
|
|
33
|
+
}>;
|
|
34
|
+
/** Whether the body names a collateral return (key 16). It is output `outputCount` when the scripts fail. */
|
|
35
|
+
hasCollateralReturn: boolean;
|
|
33
36
|
}
|
|
34
|
-
/**
|
|
35
|
-
* Extract the consumed input refs and the output addresses from a transaction
|
|
36
|
-
* CBOR (signed or unsigned) — the rows a successful submit makes stale in the
|
|
37
|
-
* UTxO cache. Works at the raw-CBOR level for the same reason as
|
|
38
|
-
* getTxHashFromCbor (byte-exact, no high-level Tx round-trip).
|
|
39
|
-
*
|
|
40
|
-
* Outputs whose address bytes cannot be decoded (e.g. Byron bootstrap
|
|
41
|
-
* addresses) are skipped — invalidation is best-effort per address.
|
|
42
|
-
*
|
|
43
|
-
* @param txCbor transaction in CBOR hex format
|
|
44
|
-
* @throws {TransactionValidationError} if the CBOR is not a transaction
|
|
45
|
-
*/
|
|
46
37
|
export declare function extractTxCacheTargets(txCbor: string): TxCacheTargets;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
* Used by the Buildooor transaction builder.
|
|
50
|
-
* When no assetUnit is provided, extracts it from the error message if possible
|
|
51
|
-
* (e.g. "not enough <policyId.assetName>"), falling back to 'lovelace'.
|
|
52
|
-
* @param err Error from builder
|
|
53
|
-
* @param assetUnit Optional asset unit override (auto-extracted from error message if omitted)
|
|
54
|
-
* @param context Optional build-flow context (e.g. the collateral/funding partition)
|
|
55
|
-
* appended to the consumer-facing message — the builder's own message
|
|
56
|
-
* has no way of knowing it
|
|
57
|
-
* @throws {InsufficientFundsError} if error is related to insufficient funds
|
|
58
|
-
* @throws {Error} original error if not mappable
|
|
59
|
-
*/
|
|
60
|
-
export declare function mapBuilderError(err: unknown, assetUnit?: string, context?: string): never;
|
|
61
|
-
/**
|
|
62
|
-
* Parse asset unit string into policyId and assetName
|
|
63
|
-
* Format: policyId (56 hex chars) + assetName (remaining hex)
|
|
64
|
-
* Used by the Buildooor transaction builder
|
|
65
|
-
*/
|
|
38
|
+
export declare function mapBuilderError(err: unknown, assetUnit?: string, context?: string, requestedOutputs?: number): never;
|
|
39
|
+
/** Split an asset unit into policyId (56 hex chars) and assetName (remaining hex). */
|
|
66
40
|
export declare function parseAssetUnit(assetUnit: string): {
|
|
67
41
|
policyId: string;
|
|
68
42
|
assetName: string;
|
|
69
43
|
};
|
|
70
|
-
/**
|
|
71
|
-
* Convert JSON value to Buildooor PlutusData (Data type).
|
|
72
|
-
* Accepts both cardano-cli format ("constructor") and Buildooor format ("constr").
|
|
73
|
-
* - { "int": 42 } → DataI(42)
|
|
74
|
-
* - { "bytes": "deadbeef" } → DataB("deadbeef")
|
|
75
|
-
* - { "list": [...] } → DataList([...])
|
|
76
|
-
* - { "map": [{ "k": ..., "v": ... }] } → DataMap([...])
|
|
77
|
-
* - { "constructor": 0, "fields": [...] } or { "constr": 0, "fields": [...] } → DataConstr(0, [...])
|
|
78
|
-
* @param json JSON value representing PlutusData
|
|
79
|
-
* @returns Buildooor Data object
|
|
80
|
-
*/
|
|
44
|
+
/** JSON (`int` / `bytes` / `list` / `map` / `constructor`|`constr`) to Buildooor PlutusData. */
|
|
81
45
|
export declare function jsonToPlutusData(json: JSONValue): Data;
|
|
82
|
-
/**
|
|
83
|
-
* Normalize a backend-provided inline datum to canonical CBOR hex.
|
|
84
|
-
*
|
|
85
|
-
* Backends report inline datums in different shapes:
|
|
86
|
-
* - Blockfrost: hex CBOR string (e.g. "19a6aa")
|
|
87
|
-
* - Koios (_extended): wrapper { bytes: "<hex>", value: { ...PlutusData JSON... } }
|
|
88
|
-
* - Koios (sometimes empty): { bytes: null, value: null }
|
|
89
|
-
* - Some endpoints: raw PlutusData JSON ({ "int": 42 } / { "constructor": 0, "fields": [] })
|
|
90
|
-
*
|
|
91
|
-
* Returns hex CBOR (lowercase) or null. Defensive: returns null on unknown
|
|
92
|
-
* shapes rather than throwing — backend mappers must not crash on malformed data.
|
|
93
|
-
*/
|
|
94
46
|
export declare function inlineDatumToHex(datum: unknown): string | null;
|
|
95
47
|
/** UPLC type tag for a typed script parameter (see {@link encodeScriptParam}). */
|
|
96
48
|
export type ScriptParamUplcType = 'data' | 'bytes' | 'int' | 'bool' | 'unit';
|
|
97
|
-
/**
|
|
98
|
-
* Encode a single script parameter into the UPLC constant the parameterized
|
|
99
|
-
* script expects.
|
|
100
|
-
*
|
|
101
|
-
* A script parameter is applied as a UPLC constant whose TYPE must match what
|
|
102
|
-
* the compiled validator expects for that parameter. Two input shapes are
|
|
103
|
-
* accepted:
|
|
104
|
-
*
|
|
105
|
-
* 1. Typed — `{ "uplc": "<type>", "value": <...> }`:
|
|
106
|
-
* - `"data"` → `UPLCConst.data(...)` value: PlutusData JSON ("constr"/cardano-cli form)
|
|
107
|
-
* - `"bytes"` → `UPLCConst.byteString(...)` value: even-length hex string
|
|
108
|
-
* - `"int"` → `UPLCConst.int(...)` value: number | numeric string
|
|
109
|
-
* - `"bool"` → `UPLCConst.bool(...)` value: boolean
|
|
110
|
-
* - `"unit"` → `UPLCConst.unit` value: omitted
|
|
111
|
-
* Required for compilers whose scalar params are NATIVE-typed rather than
|
|
112
|
-
* Data-wrapped (e.g. Pebble: `param x: PubKeyHash` expects a native
|
|
113
|
-
* `bytestring`, not a `Data` bytestring).
|
|
114
|
-
*
|
|
115
|
-
* 2. Bare PlutusData object (e.g. `{ "bytes": "ab.." }`, `{ "constructor": 0, ... }`)
|
|
116
|
-
* — shorthand for `{ "uplc": "data", "value": <object> }`. This is the
|
|
117
|
-
* Aiken / CIP-57 blueprint convention, where every parameter is Data.
|
|
118
|
-
*/
|
|
119
49
|
export declare function encodeScriptParam(param: JSONValue): UPLCConst;
|
|
120
|
-
/**
|
|
121
|
-
* Apply parameters to a parameterized PlutusV3 script (CBOR-wrapped flat UPLC).
|
|
122
|
-
* Each parameter becomes a successive UPLC Application wrapping the program body.
|
|
123
|
-
*
|
|
124
|
-
* Parameters are applied in their declared UPLC type via {@link encodeScriptParam}:
|
|
125
|
-
* pass `{ uplc, value }` entries for native-typed params (e.g. Pebble scalars),
|
|
126
|
-
* or bare PlutusData objects for the Data convention (Aiken / CIP-57 blueprints).
|
|
127
|
-
*
|
|
128
|
-
* @param scriptHex CBOR hex of the unapplied Plutus script (as output by Aiken/Pebble/Plutus compilers)
|
|
129
|
-
* @param params Array of script parameters (typed `{uplc,value}` and/or bare PlutusData JSON) to apply in order
|
|
130
|
-
* @returns CBOR hex of the applied script (ready for transaction building)
|
|
131
|
-
*/
|
|
50
|
+
/** Wraps the program body in one UPLC application per parameter. Returns the script CBOR hex. */
|
|
132
51
|
export declare function applyScriptParameters(scriptHex: string, params: JSONValue[]): string;
|
|
52
|
+
export declare function plutusScriptHash(scriptHex: string, version: 'plutusV2' | 'plutusV3'): string;
|
|
133
53
|
//# sourceMappingURL=tx-build-helper.d.ts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getLovelace = getLovelace;
|
|
4
|
+
exports.isCollateralCandidate = isCollateralCandidate;
|
|
4
5
|
exports.assertAdaOnly = assertAdaOnly;
|
|
5
6
|
exports.getTxHashFromCbor = getTxHashFromCbor;
|
|
6
7
|
exports.extractTxCacheTargets = extractTxCacheTargets;
|
|
@@ -10,6 +11,7 @@ exports.jsonToPlutusData = jsonToPlutusData;
|
|
|
10
11
|
exports.inlineDatumToHex = inlineDatumToHex;
|
|
11
12
|
exports.encodeScriptParam = encodeScriptParam;
|
|
12
13
|
exports.applyScriptParameters = applyScriptParameters;
|
|
14
|
+
exports.plutusScriptHash = plutusScriptHash;
|
|
13
15
|
const uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
|
|
14
16
|
const crypto_1 = require("@harmoniclabs/crypto");
|
|
15
17
|
const errors_1 = require("./errors");
|
|
@@ -18,48 +20,32 @@ const plutus_data_1 = require("@harmoniclabs/plutus-data");
|
|
|
18
20
|
const uplc_1 = require("@harmoniclabs/uplc");
|
|
19
21
|
const cbor_1 = require("@harmoniclabs/cbor");
|
|
20
22
|
const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
21
|
-
/**
|
|
22
|
-
* Extract lovelace amount from UTxO
|
|
23
|
-
* @param u UTxO to extract from
|
|
24
|
-
* @returns {bigint} lovelace amount
|
|
25
|
-
*/
|
|
23
|
+
/** Lovelace amount of a UTxO. */
|
|
26
24
|
function getLovelace(u) {
|
|
27
25
|
const entry = u.amount.find(a => (a.unit).toLowerCase() === "lovelace");
|
|
28
26
|
return BigInt(entry?.quantity ?? "0");
|
|
29
27
|
}
|
|
30
|
-
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*/
|
|
28
|
+
/** A UTxO the builders may take as collateral: lovelace only and no reference script. */
|
|
29
|
+
function isCollateralCandidate(u) {
|
|
30
|
+
return u.amount.every(a => a.unit.toLowerCase() === 'lovelace' || BigInt(a.quantity) === 0n) && !u.scriptRef && !u.scriptRefCbor;
|
|
31
|
+
}
|
|
32
|
+
/** Throws MixedAssetsError when the UTxO carries non-ADA assets. */
|
|
35
33
|
function assertAdaOnly(u) {
|
|
36
34
|
const nonAda = u.amount.filter(a => (a.unit).toLowerCase() !== "lovelace" && BigInt(a.quantity) !== 0n);
|
|
37
35
|
if (nonAda.length > 0) {
|
|
38
36
|
throw new errors_1.MixedAssetsError(`${u.txHash}#${u.outputIndex}`, nonAda.map(a => a.unit));
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
|
-
/**
|
|
42
|
-
* Extract transaction hash from a transaction CBOR (signed or unsigned).
|
|
43
|
-
* Hash is computed over the body, so witness presence does not affect it.
|
|
44
|
-
* @param txCbor transaction in CBOR hex format
|
|
45
|
-
* @returns {string} transaction hash (64 character hex string)
|
|
46
|
-
* @throws {Error} if CBOR is invalid or transaction hash cannot be extracted
|
|
47
|
-
*/
|
|
39
|
+
/** Transaction hash: blake2b-256 over the body bytes, so witnesses do not affect it. */
|
|
48
40
|
function getTxHashFromCbor(txCbor) {
|
|
49
41
|
if (!txCbor || typeof txCbor !== 'string') {
|
|
50
42
|
throw new Error('Invalid input: txCbor must be a non-empty string');
|
|
51
43
|
}
|
|
52
|
-
//
|
|
53
|
-
// so an odd-length string is malformed and would otherwise surface as a confusing
|
|
54
|
-
// "Failed to parse transaction CBOR" from fromHex/Cbor.parse rather than a clear
|
|
55
|
-
// input-validation error.
|
|
44
|
+
// Even length: an odd hex string would otherwise fail later as a confusing parse error
|
|
56
45
|
if (!/^[a-fA-F0-9]+$/.test(txCbor) || txCbor.length % 2 !== 0) {
|
|
57
46
|
throw new Error('Invalid input: txCbor must be a valid hex string');
|
|
58
47
|
}
|
|
59
|
-
//
|
|
60
|
-
// subCborRef.toBuffer() returns the exact bytes as received — no re-serialization, so
|
|
61
|
-
// the hash matches what was signed. We stay at the raw-CBOR level (never instantiate
|
|
62
|
-
// the high-level Tx type) for that byte-exactness.
|
|
48
|
+
// Hash the ORIGINAL body bytes via subCborRef (no re-serialization), so it matches what was signed
|
|
63
49
|
try {
|
|
64
50
|
const tx = cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(txCbor));
|
|
65
51
|
if (!(tx instanceof cbor_1.CborArray) || tx.array.length < 1 || !tx.array[0].subCborRef) {
|
|
@@ -69,52 +55,49 @@ function getTxHashFromCbor(txCbor) {
|
|
|
69
55
|
return (0, uint8array_utils_1.toHex)((0, crypto_1.blake2b_256)(bodyBytes));
|
|
70
56
|
}
|
|
71
57
|
catch (err) {
|
|
72
|
-
// typed 400 — a plain Error here surfaced as a 500 to the consumer
|
|
73
58
|
throw new errors_1.TransactionValidationError('Failed to parse transaction CBOR', err, error_codes_1.ERROR_CODES.TX_PARSE_FAILED);
|
|
74
59
|
}
|
|
75
60
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
* CBOR (signed or unsigned) — the rows a successful submit makes stale in the
|
|
79
|
-
* UTxO cache. Works at the raw-CBOR level for the same reason as
|
|
80
|
-
* getTxHashFromCbor (byte-exact, no high-level Tx round-trip).
|
|
81
|
-
*
|
|
82
|
-
* Outputs whose address bytes cannot be decoded (e.g. Byron bootstrap
|
|
83
|
-
* addresses) are skipped — invalidation is best-effort per address.
|
|
84
|
-
*
|
|
85
|
-
* @param txCbor transaction in CBOR hex format
|
|
86
|
-
* @throws {TransactionValidationError} if the CBOR is not a transaction
|
|
87
|
-
*/
|
|
61
|
+
// Consumed inputs and output addresses, i.e. the UTxO-cache rows a submit makes stale.
|
|
62
|
+
// Outputs with undecodable Byron addresses are skipped.
|
|
88
63
|
function extractTxCacheTargets(txCbor) {
|
|
89
64
|
let body;
|
|
65
|
+
let isValid = true;
|
|
90
66
|
try {
|
|
91
67
|
const tx = cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(txCbor));
|
|
92
68
|
if (!(tx instanceof cbor_1.CborArray) || !(tx.array[0] instanceof cbor_1.CborMap)) {
|
|
93
69
|
throw new Error('not a transaction');
|
|
94
70
|
}
|
|
95
71
|
body = tx.array[0];
|
|
72
|
+
// [body, witnesses, isValid, auxiliary data] since Alonzo; a body alone has no flag
|
|
73
|
+
const flag = tx.array.length === 4 ? tx.array[2] : undefined;
|
|
74
|
+
if (flag instanceof cbor_1.CborSimple && flag.simple === false)
|
|
75
|
+
isValid = false;
|
|
96
76
|
}
|
|
97
77
|
catch (err) {
|
|
98
78
|
throw new errors_1.TransactionValidationError('Failed to parse transaction CBOR', err, error_codes_1.ERROR_CODES.TX_PARSE_FAILED);
|
|
99
79
|
}
|
|
100
80
|
const bodyValue = (key) => body.map.find(e => e.k instanceof cbor_1.CborUInt && e.k.num === BigInt(key))?.v;
|
|
101
|
-
//
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
81
|
+
// keys 0 and 13: inputs and collateral inputs, plain array or CBOR tag-258 set (Conway)
|
|
82
|
+
const outRefs = (key) => {
|
|
83
|
+
const refs = [];
|
|
84
|
+
let set = bodyValue(key);
|
|
85
|
+
if (set instanceof cbor_1.CborTag)
|
|
86
|
+
set = set.data;
|
|
87
|
+
if (!(set instanceof cbor_1.CborArray))
|
|
88
|
+
return refs;
|
|
89
|
+
for (const entry of set.array) {
|
|
90
|
+
if (entry instanceof cbor_1.CborArray && entry.array[0] instanceof cbor_1.CborBytes && entry.array[1] instanceof cbor_1.CborUInt) {
|
|
91
|
+
refs.push({ txHash: (0, uint8array_utils_1.toHex)(entry.array[0].bytes), outputIndex: Number(entry.array[1].num) });
|
|
112
92
|
}
|
|
113
93
|
}
|
|
114
|
-
|
|
115
|
-
|
|
94
|
+
return refs;
|
|
95
|
+
};
|
|
96
|
+
const inputs = outRefs(0);
|
|
97
|
+
// key 1: outputs, post-Alonzo map form ({0: address, ...}) or legacy array form ([address, amount, ...])
|
|
116
98
|
const outputAddresses = new Set();
|
|
117
99
|
const outputsObj = bodyValue(1);
|
|
100
|
+
const outputCount = outputsObj instanceof cbor_1.CborArray ? outputsObj.array.length : 0;
|
|
118
101
|
if (outputsObj instanceof cbor_1.CborArray) {
|
|
119
102
|
for (const output of outputsObj.array) {
|
|
120
103
|
const addrObj = output instanceof cbor_1.CborMap
|
|
@@ -126,35 +109,41 @@ function extractTxCacheTargets(txCbor) {
|
|
|
126
109
|
outputAddresses.add(cardano_ledger_ts_1.Address.fromBuffer(addrObj.bytes).toString());
|
|
127
110
|
}
|
|
128
111
|
catch {
|
|
129
|
-
// non-Shelley address bytes
|
|
112
|
+
// non-Shelley address bytes: nothing cached under a bech32 key
|
|
130
113
|
}
|
|
131
114
|
}
|
|
132
115
|
}
|
|
133
|
-
|
|
116
|
+
const ttl = bodyValue(3);
|
|
117
|
+
const ttlSlot = ttl instanceof cbor_1.CborUInt ? Number(ttl.num) : null;
|
|
118
|
+
const start = bodyValue(8);
|
|
119
|
+
const validityStartSlot = start instanceof cbor_1.CborUInt ? Number(start.num) : null;
|
|
120
|
+
return {
|
|
121
|
+
inputs, outputAddresses: [...outputAddresses], outputCount, ttlSlot, validityStartSlot,
|
|
122
|
+
isValid, collateralInputs: outRefs(13), hasCollateralReturn: bodyValue(16) !== undefined,
|
|
123
|
+
};
|
|
134
124
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
* (e.g. "not enough <policyId.assetName>"), falling back to 'lovelace'.
|
|
140
|
-
* @param err Error from builder
|
|
141
|
-
* @param assetUnit Optional asset unit override (auto-extracted from error message if omitted)
|
|
142
|
-
* @param context Optional build-flow context (e.g. the collateral/funding partition)
|
|
143
|
-
* appended to the consumer-facing message — the builder's own message
|
|
144
|
-
* has no way of knowing it
|
|
145
|
-
* @throws {InsufficientFundsError} if error is related to insufficient funds
|
|
146
|
-
* @throws {Error} original error if not mappable
|
|
147
|
-
*/
|
|
148
|
-
function mapBuilderError(err, assetUnit, context) {
|
|
149
|
-
// Already-typed errors carry their own status + payload (amounts, asset units,
|
|
150
|
-
// validation details) — re-wrapping them into a generic InsufficientFundsError
|
|
151
|
-
// because their MESSAGE happens to contain "balance"/"insufficient" destroys that.
|
|
125
|
+
// Maps Buildooor errors to typed BackendErrors. `context` is appended to the message.
|
|
126
|
+
// `requestedOutputs` counts the caller's outputs. Buildooor appends the change after them.
|
|
127
|
+
function mapBuilderError(err, assetUnit, context, requestedOutputs) {
|
|
128
|
+
// Typed errors keep their own status and payload
|
|
152
129
|
if (err instanceof errors_1.BackendError) {
|
|
153
130
|
throw err;
|
|
154
131
|
}
|
|
155
132
|
const errObj = err;
|
|
156
133
|
const rawMsg = errObj?.message || errObj?.toString?.() || String(err);
|
|
157
134
|
const msg = rawMsg.toLowerCase();
|
|
135
|
+
// An output below the protocol's min-ADA: a request error, not missing funds
|
|
136
|
+
const minAda = rawMsg.match(/tx output at index (\d+) did not have enough lovelaces[\s\S]*?minimum lovelaces required:\s*(\d+)[\s\S]*?output lovelaces\s*:\s*(\d+)/);
|
|
137
|
+
if (minAda) {
|
|
138
|
+
const [, index, minimum, actual] = minAda;
|
|
139
|
+
if (requestedOutputs !== undefined && Number(index) >= requestedOutputs) {
|
|
140
|
+
// the change output: the caller cannot raise it. The shortfall is unknown here, so no amounts
|
|
141
|
+
throw new errors_1.InsufficientFundsError('lovelace', 0n, 0n, err, `the change output needs at least ${minimum} lovelace (has ${actual}); the funding UTxOs cannot pay the fee and the change` +
|
|
142
|
+
(context ? ` (${context})` : ''));
|
|
143
|
+
}
|
|
144
|
+
const withAssets = /tx output:[\s\S]*"[0-9a-f]{56}"\s*:/i.test(rawMsg) ? ', it carries native assets' : '';
|
|
145
|
+
throw new errors_1.TransactionValidationError(`output ${index} needs at least ${minimum} lovelace (has ${actual}${withAssets}); raise its lovelace amount`, err);
|
|
146
|
+
}
|
|
158
147
|
if (msg.includes('not enough') ||
|
|
159
148
|
msg.includes('insufficient') ||
|
|
160
149
|
msg.includes('balance')) {
|
|
@@ -162,24 +151,19 @@ function mapBuilderError(err, assetUnit, context) {
|
|
|
162
151
|
const match = msg.match(/not enough\s+([a-f0-9.]+)/i);
|
|
163
152
|
return match?.[1] || 'lovelace';
|
|
164
153
|
})();
|
|
165
|
-
//
|
|
166
|
-
// context) instead of a meaningless "required 0, available 0".
|
|
154
|
+
// No amounts known here: surface the builder's own message instead of "required 0, available 0"
|
|
167
155
|
throw new errors_1.InsufficientFundsError(effectiveUnit, 0n, 0n, err, context ? `${rawMsg} (${context})` : rawMsg);
|
|
168
156
|
}
|
|
169
157
|
throw err;
|
|
170
158
|
}
|
|
171
|
-
/**
|
|
172
|
-
* Parse asset unit string into policyId and assetName
|
|
173
|
-
* Format: policyId (56 hex chars) + assetName (remaining hex)
|
|
174
|
-
* Used by the Buildooor transaction builder
|
|
175
|
-
*/
|
|
159
|
+
/** Split an asset unit into policyId (56 hex chars) and assetName (remaining hex). */
|
|
176
160
|
function parseAssetUnit(assetUnit) {
|
|
177
161
|
return {
|
|
178
162
|
policyId: assetUnit.substring(0, 56),
|
|
179
163
|
assetName: assetUnit.substring(56)
|
|
180
164
|
};
|
|
181
165
|
}
|
|
182
|
-
/** Allowed keys in PlutusData JSON
|
|
166
|
+
/** Allowed keys in PlutusData JSON; anything else is stripped */
|
|
183
167
|
const PLUTUS_DATA_ALLOWED_KEYS = new Set([
|
|
184
168
|
'constructor', 'constr', 'fields', 'int', 'bytes', 'list', 'map', 'k', 'v'
|
|
185
169
|
]);
|
|
@@ -193,11 +177,7 @@ function sanitizePlutusKeys(obj) {
|
|
|
193
177
|
}
|
|
194
178
|
return clean;
|
|
195
179
|
}
|
|
196
|
-
/**
|
|
197
|
-
* Normalize PlutusData JSON from cardano-cli format ("constructor") to
|
|
198
|
-
* Buildooor format ("constr"), recursively through fields/list/map.
|
|
199
|
-
* Also strips unrecognized keys for safety.
|
|
200
|
-
*/
|
|
180
|
+
/** Normalize cardano-cli "constructor" to Buildooor "constr" recursively; strips unknown keys. */
|
|
201
181
|
function normalizeConstructorKey(obj) {
|
|
202
182
|
const safe = sanitizePlutusKeys(obj);
|
|
203
183
|
const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
@@ -222,43 +202,29 @@ function normalizeConstructorKey(obj) {
|
|
|
222
202
|
}
|
|
223
203
|
return safe;
|
|
224
204
|
}
|
|
225
|
-
/**
|
|
226
|
-
* Convert JSON value to Buildooor PlutusData (Data type).
|
|
227
|
-
* Accepts both cardano-cli format ("constructor") and Buildooor format ("constr").
|
|
228
|
-
* - { "int": 42 } → DataI(42)
|
|
229
|
-
* - { "bytes": "deadbeef" } → DataB("deadbeef")
|
|
230
|
-
* - { "list": [...] } → DataList([...])
|
|
231
|
-
* - { "map": [{ "k": ..., "v": ... }] } → DataMap([...])
|
|
232
|
-
* - { "constructor": 0, "fields": [...] } or { "constr": 0, "fields": [...] } → DataConstr(0, [...])
|
|
233
|
-
* @param json JSON value representing PlutusData
|
|
234
|
-
* @returns Buildooor Data object
|
|
235
|
-
*/
|
|
205
|
+
/** JSON (`int` / `bytes` / `list` / `map` / `constructor`|`constr`) to Buildooor PlutusData. */
|
|
236
206
|
function jsonToPlutusData(json) {
|
|
237
207
|
if (json === null || json === undefined) {
|
|
238
|
-
throw new
|
|
208
|
+
throw new errors_1.TransactionValidationError('PlutusData JSON cannot be null or undefined');
|
|
239
209
|
}
|
|
240
210
|
if (typeof json === 'object' && !Array.isArray(json)) {
|
|
241
211
|
const normalized = normalizeConstructorKey(json);
|
|
242
|
-
|
|
212
|
+
try {
|
|
213
|
+
return (0, plutus_data_1.dataFromJson)(normalized);
|
|
214
|
+
}
|
|
215
|
+
catch (err) {
|
|
216
|
+
// request data: a shape Buildooor cannot read is the caller's mistake, not a server fault
|
|
217
|
+
throw new errors_1.TransactionValidationError(`Invalid PlutusData JSON: ${err instanceof Error ? err.message : String(err)}`, err);
|
|
218
|
+
}
|
|
243
219
|
}
|
|
244
|
-
throw new
|
|
220
|
+
throw new errors_1.TransactionValidationError(`Unsupported PlutusData JSON format: expected an object with "int", "bytes", "list", "map", or "constructor" key`);
|
|
245
221
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
*
|
|
249
|
-
* Backends report inline datums in different shapes:
|
|
250
|
-
* - Blockfrost: hex CBOR string (e.g. "19a6aa")
|
|
251
|
-
* - Koios (_extended): wrapper { bytes: "<hex>", value: { ...PlutusData JSON... } }
|
|
252
|
-
* - Koios (sometimes empty): { bytes: null, value: null }
|
|
253
|
-
* - Some endpoints: raw PlutusData JSON ({ "int": 42 } / { "constructor": 0, "fields": [] })
|
|
254
|
-
*
|
|
255
|
-
* Returns hex CBOR (lowercase) or null. Defensive: returns null on unknown
|
|
256
|
-
* shapes rather than throwing — backend mappers must not crash on malformed data.
|
|
257
|
-
*/
|
|
222
|
+
// Accepts a hex string, the `{ bytes, value }` wrapper of Koios, or PlutusData JSON.
|
|
223
|
+
// Returns null on unknown shapes instead of throwing.
|
|
258
224
|
function inlineDatumToHex(datum) {
|
|
259
225
|
if (datum === null || datum === undefined)
|
|
260
226
|
return null;
|
|
261
|
-
// Already hex CBOR
|
|
227
|
+
// Already hex CBOR
|
|
262
228
|
if (typeof datum === 'string') {
|
|
263
229
|
const s = datum.trim();
|
|
264
230
|
if (!s)
|
|
@@ -268,8 +234,7 @@ function inlineDatumToHex(datum) {
|
|
|
268
234
|
if (typeof datum !== 'object' || Array.isArray(datum))
|
|
269
235
|
return null;
|
|
270
236
|
const obj = datum;
|
|
271
|
-
// Koios wrapper
|
|
272
|
-
// Distinguished from raw PlutusData {bytes:"deadbeef"} by the presence of `value`.
|
|
237
|
+
// Koios wrapper { bytes, value }; `value` distinguishes it from raw PlutusData { bytes }
|
|
273
238
|
if ('value' in obj && typeof obj.bytes === 'string' && obj.bytes.length > 0) {
|
|
274
239
|
const hex = obj.bytes.trim();
|
|
275
240
|
return /^[0-9a-fA-F]+$/.test(hex) && hex.length % 2 === 0 ? hex.toLowerCase() : null;
|
|
@@ -289,28 +254,8 @@ function inlineDatumToHex(datum) {
|
|
|
289
254
|
return null;
|
|
290
255
|
}
|
|
291
256
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
* script expects.
|
|
295
|
-
*
|
|
296
|
-
* A script parameter is applied as a UPLC constant whose TYPE must match what
|
|
297
|
-
* the compiled validator expects for that parameter. Two input shapes are
|
|
298
|
-
* accepted:
|
|
299
|
-
*
|
|
300
|
-
* 1. Typed — `{ "uplc": "<type>", "value": <...> }`:
|
|
301
|
-
* - `"data"` → `UPLCConst.data(...)` value: PlutusData JSON ("constr"/cardano-cli form)
|
|
302
|
-
* - `"bytes"` → `UPLCConst.byteString(...)` value: even-length hex string
|
|
303
|
-
* - `"int"` → `UPLCConst.int(...)` value: number | numeric string
|
|
304
|
-
* - `"bool"` → `UPLCConst.bool(...)` value: boolean
|
|
305
|
-
* - `"unit"` → `UPLCConst.unit` value: omitted
|
|
306
|
-
* Required for compilers whose scalar params are NATIVE-typed rather than
|
|
307
|
-
* Data-wrapped (e.g. Pebble: `param x: PubKeyHash` expects a native
|
|
308
|
-
* `bytestring`, not a `Data` bytestring).
|
|
309
|
-
*
|
|
310
|
-
* 2. Bare PlutusData object (e.g. `{ "bytes": "ab.." }`, `{ "constructor": 0, ... }`)
|
|
311
|
-
* — shorthand for `{ "uplc": "data", "value": <object> }`. This is the
|
|
312
|
-
* Aiken / CIP-57 blueprint convention, where every parameter is Data.
|
|
313
|
-
*/
|
|
257
|
+
// Typed form is `{ uplc, value }` with uplc one of data, bytes, int, bool or unit.
|
|
258
|
+
// A bare PlutusData object, the CIP-57 convention, is shorthand for `uplc: "data"`.
|
|
314
259
|
function encodeScriptParam(param) {
|
|
315
260
|
if (param !== null &&
|
|
316
261
|
typeof param === 'object' &&
|
|
@@ -322,68 +267,75 @@ function encodeScriptParam(param) {
|
|
|
322
267
|
return uplc_1.UPLCConst.data(jsonToPlutusData(value));
|
|
323
268
|
case 'bytes': {
|
|
324
269
|
if (typeof value !== 'string' || !/^([0-9a-fA-F]{2})*$/.test(value)) {
|
|
325
|
-
throw new
|
|
270
|
+
throw new errors_1.TransactionValidationError('Script param of uplc type "bytes" requires an even-length hex string "value"');
|
|
326
271
|
}
|
|
327
272
|
return uplc_1.UPLCConst.byteString((0, uint8array_utils_1.fromHex)(value));
|
|
328
273
|
}
|
|
329
274
|
case 'int': {
|
|
330
275
|
if (typeof value !== 'number' && typeof value !== 'string') {
|
|
331
|
-
throw new
|
|
276
|
+
throw new errors_1.TransactionValidationError('Script param of uplc type "int" requires a number or numeric-string "value"');
|
|
332
277
|
}
|
|
333
278
|
let n;
|
|
334
279
|
try {
|
|
335
280
|
n = BigInt(value);
|
|
336
281
|
}
|
|
337
282
|
catch {
|
|
338
|
-
throw new
|
|
283
|
+
throw new errors_1.TransactionValidationError(`Script param of uplc type "int" has a non-integer "value": ${String(value)}`);
|
|
339
284
|
}
|
|
340
285
|
return uplc_1.UPLCConst.int(n);
|
|
341
286
|
}
|
|
342
287
|
case 'bool': {
|
|
343
288
|
if (typeof value !== 'boolean') {
|
|
344
|
-
throw new
|
|
289
|
+
throw new errors_1.TransactionValidationError('Script param of uplc type "bool" requires a boolean "value"');
|
|
345
290
|
}
|
|
346
291
|
return uplc_1.UPLCConst.bool(value);
|
|
347
292
|
}
|
|
348
293
|
case 'unit':
|
|
349
294
|
return uplc_1.UPLCConst.unit;
|
|
350
295
|
default:
|
|
351
|
-
throw new
|
|
296
|
+
throw new errors_1.TransactionValidationError(`Unknown script param uplc type "${String(uplc)}"; expected one of: data, bytes, int, bool, unit`);
|
|
352
297
|
}
|
|
353
298
|
}
|
|
354
|
-
// Bare PlutusData
|
|
299
|
+
// Bare PlutusData: apply as Data
|
|
355
300
|
return uplc_1.UPLCConst.data(jsonToPlutusData(param));
|
|
356
301
|
}
|
|
357
|
-
/**
|
|
358
|
-
* Apply parameters to a parameterized PlutusV3 script (CBOR-wrapped flat UPLC).
|
|
359
|
-
* Each parameter becomes a successive UPLC Application wrapping the program body.
|
|
360
|
-
*
|
|
361
|
-
* Parameters are applied in their declared UPLC type via {@link encodeScriptParam}:
|
|
362
|
-
* pass `{ uplc, value }` entries for native-typed params (e.g. Pebble scalars),
|
|
363
|
-
* or bare PlutusData objects for the Data convention (Aiken / CIP-57 blueprints).
|
|
364
|
-
*
|
|
365
|
-
* @param scriptHex CBOR hex of the unapplied Plutus script (as output by Aiken/Pebble/Plutus compilers)
|
|
366
|
-
* @param params Array of script parameters (typed `{uplc,value}` and/or bare PlutusData JSON) to apply in order
|
|
367
|
-
* @returns CBOR hex of the applied script (ready for transaction building)
|
|
368
|
-
*/
|
|
302
|
+
/** Wraps the program body in one UPLC application per parameter. Returns the script CBOR hex. */
|
|
369
303
|
function applyScriptParameters(scriptHex, params) {
|
|
370
304
|
if (!Array.isArray(params) || params.length === 0) {
|
|
371
305
|
throw new Error('Script parameters must be a non-empty array');
|
|
372
306
|
}
|
|
373
|
-
//
|
|
307
|
+
// CBOR-unwrap to the flat UPLC bytes
|
|
374
308
|
const cborObj = cbor_1.Cbor.parse(scriptHex);
|
|
375
309
|
const flatBytes = cborObj.bytes;
|
|
376
|
-
// 2. Flat-decode → UPLCProgram
|
|
377
310
|
const program = uplc_1.UPLCDecoder.parse(flatBytes, 'flat');
|
|
378
|
-
// 3. Apply each parameter as Application(body, <typed UPLC constant>)
|
|
379
311
|
let body = program.body;
|
|
380
312
|
for (const param of params) {
|
|
381
313
|
body = new uplc_1.Application(body, encodeScriptParam(param));
|
|
382
314
|
}
|
|
383
|
-
//
|
|
315
|
+
// Flat-encode the applied program and CBOR-wrap it again
|
|
384
316
|
const applied = new uplc_1.UPLCProgram(program.version, body);
|
|
385
317
|
const appliedFlatBytes = (0, uplc_1.compileUPLC)(applied);
|
|
386
318
|
const cborEncoded = cbor_1.Cbor.encode(new cbor_1.CborBytes(appliedFlatBytes));
|
|
387
319
|
return (0, uint8array_utils_1.toHex)(cborEncoded);
|
|
388
320
|
}
|
|
321
|
+
// blake2b-224 over the language byte and the once-wrapped CBOR. Accepts cardano-cli's double wrap.
|
|
322
|
+
// The version cannot be read from the script, so the caller names it.
|
|
323
|
+
function plutusScriptHash(scriptHex, version) {
|
|
324
|
+
if (version !== 'plutusV2' && version !== 'plutusV3') {
|
|
325
|
+
throw new errors_1.TransactionValidationError(`version must be plutusV2 or plutusV3, got ${String(version)}`);
|
|
326
|
+
}
|
|
327
|
+
let script;
|
|
328
|
+
try {
|
|
329
|
+
script = new cardano_ledger_ts_1.Script(version === 'plutusV2' ? cardano_ledger_ts_1.ScriptType.PlutusV2 : cardano_ledger_ts_1.ScriptType.PlutusV3, (0, uint8array_utils_1.fromHex)(scriptHex));
|
|
330
|
+
}
|
|
331
|
+
catch (err) {
|
|
332
|
+
throw new errors_1.TransactionValidationError(`scriptHex is not a CBOR-wrapped Plutus script: ${err instanceof Error ? err.message : String(err)}`);
|
|
333
|
+
}
|
|
334
|
+
// Plutus V2 runs UPLC 1.0.0 only; the first three flat bytes hold the UPLC version
|
|
335
|
+
const b = script.bytes;
|
|
336
|
+
if (version === 'plutusV2' && !(b.length >= 3 && b[0] === 1 && b[1] === 0 && b[2] === 0)) {
|
|
337
|
+
throw new errors_1.TransactionValidationError('scriptHex is not UPLC 1.0.0 code, so it cannot be a Plutus V2 script');
|
|
338
|
+
}
|
|
339
|
+
return script.hash.toString();
|
|
340
|
+
}
|
|
389
341
|
//# sourceMappingURL=tx-build-helper.js.map
|