@odatano/core 2.0.0-rc.4 → 2.0.0-rc.41

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.
Files changed (166) hide show
  1. package/@cds-models/CardanoAgentService/index.d.ts +251 -0
  2. package/@cds-models/CardanoAgentService/index.js +36 -0
  3. package/@cds-models/CardanoBackendService/index.d.ts +357 -0
  4. package/@cds-models/CardanoBackendService/index.js +40 -0
  5. package/@cds-models/CardanoIndexerService/index.d.ts +194 -2
  6. package/@cds-models/CardanoIndexerService/index.js +25 -0
  7. package/@cds-models/CardanoODataService/index.d.ts +305 -7
  8. package/@cds-models/CardanoODataService/index.js +34 -0
  9. package/@cds-models/CardanoSignService/index.d.ts +28 -3
  10. package/@cds-models/CardanoSignService/index.js +3 -0
  11. package/@cds-models/CardanoTransactionService/index.d.ts +46 -13
  12. package/@cds-models/CardanoTransactionService/index.js +4 -0
  13. package/@cds-models/index.d.ts +72 -0
  14. package/@cds-models/index.js +12 -0
  15. package/@cds-models/odatano/cardano/index.d.ts +408 -7
  16. package/@cds-models/odatano/cardano/index.js +42 -0
  17. package/README.md +64 -5
  18. package/db/schema.cds +2297 -1633
  19. package/db/types.cds +114 -0
  20. package/package.json +27 -6
  21. package/scripts/migrate-slot-leader.mjs +104 -0
  22. package/scripts/migrate-txseq.mjs +147 -0
  23. package/src/index.d.ts +18 -11
  24. package/src/index.js +44 -14
  25. package/src/plugin.js +42 -52
  26. package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
  27. package/srv/blockchain/backends/blockfrost-backend.js +53 -162
  28. package/srv/blockchain/backends/cardano-backend.d.ts +104 -158
  29. package/srv/blockchain/backends/cardano-backend.js +19 -5
  30. package/srv/blockchain/backends/koios-backend.d.ts +126 -60
  31. package/srv/blockchain/backends/koios-backend.js +376 -235
  32. package/srv/blockchain/backends/odatano-backend.d.ts +64 -0
  33. package/srv/blockchain/backends/odatano-backend.js +170 -0
  34. package/srv/blockchain/backends/ogmios-backend.d.ts +162 -94
  35. package/srv/blockchain/backends/ogmios-backend.js +556 -201
  36. package/srv/blockchain/backends/ogmios-frame-guard.d.ts +32 -0
  37. package/srv/blockchain/backends/ogmios-frame-guard.js +142 -0
  38. package/srv/blockchain/cardano-client.d.ts +87 -202
  39. package/srv/blockchain/cardano-client.js +210 -240
  40. package/srv/blockchain/cardano-indexer.d.ts +311 -242
  41. package/srv/blockchain/cardano-indexer.js +1238 -362
  42. package/srv/blockchain/cardano-tx-builder.d.ts +44 -81
  43. package/srv/blockchain/cardano-tx-builder.js +173 -132
  44. package/srv/blockchain/crawler/certificate-backfill.d.ts +67 -0
  45. package/srv/blockchain/crawler/certificate-backfill.js +169 -0
  46. package/srv/blockchain/crawler/crawler.d.ts +139 -54
  47. package/srv/blockchain/crawler/crawler.js +478 -96
  48. package/srv/blockchain/crawler/hooks.d.ts +3 -14
  49. package/srv/blockchain/crawler/index.d.ts +5 -0
  50. package/srv/blockchain/crawler/index.js +35 -7
  51. package/srv/blockchain/crawler/sync-state.d.ts +46 -28
  52. package/srv/blockchain/crawler/sync-state.js +128 -43
  53. package/srv/blockchain/crawler/transaction-backfill.d.ts +52 -0
  54. package/srv/blockchain/crawler/transaction-backfill.js +283 -0
  55. package/srv/blockchain/crawler/utxo-set-import.d.ts +78 -0
  56. package/srv/blockchain/crawler/utxo-set-import.js +363 -0
  57. package/srv/blockchain/ledger-state.d.ts +101 -0
  58. package/srv/blockchain/ledger-state.js +432 -0
  59. package/srv/blockchain/pending-spends.d.ts +28 -0
  60. package/srv/blockchain/pending-spends.js +89 -0
  61. package/srv/blockchain/signing/cose-verifier.d.ts +5 -12
  62. package/srv/blockchain/signing/cose-verifier.js +6 -12
  63. package/srv/blockchain/signing/external-signer.d.ts +16 -113
  64. package/srv/blockchain/signing/external-signer.js +19 -122
  65. package/srv/blockchain/signing/hsm-signer.d.ts +13 -45
  66. package/srv/blockchain/signing/hsm-signer.js +23 -63
  67. package/srv/blockchain/signing/signature-verifier.d.ts +14 -45
  68. package/srv/blockchain/signing/signature-verifier.js +73 -76
  69. package/srv/blockchain/signing/submission-finalizer.d.ts +9 -36
  70. package/srv/blockchain/signing/submission-finalizer.js +16 -49
  71. package/srv/blockchain/stored-chain.d.ts +33 -0
  72. package/srv/blockchain/stored-chain.js +234 -0
  73. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +111 -173
  74. package/srv/blockchain/transaction-building/buildooor-tx.js +649 -326
  75. package/srv/blockchain/transaction-building/caller-datums.d.ts +29 -0
  76. package/srv/blockchain/transaction-building/caller-datums.js +139 -0
  77. package/srv/blockchain/transaction-building/cardano-tx.d.ts +10 -35
  78. package/srv/blockchain/transaction-rows.d.ts +12 -0
  79. package/srv/blockchain/transaction-rows.js +43 -0
  80. package/srv/blockchain/wallet-worker/build-request.d.ts +4 -17
  81. package/srv/blockchain/wallet-worker/build-request.js +18 -23
  82. package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +25 -17
  83. package/srv/blockchain/wallet-worker/confirmation-tracker.js +87 -41
  84. package/srv/blockchain/wallet-worker/index.js +2 -8
  85. package/srv/blockchain/wallet-worker/job-store.d.ts +36 -103
  86. package/srv/blockchain/wallet-worker/job-store.js +0 -0
  87. package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +4 -20
  88. package/srv/blockchain/wallet-worker/lease-heartbeat.js +4 -20
  89. package/srv/blockchain/wallet-worker/signers.d.ts +6 -19
  90. package/srv/blockchain/wallet-worker/signers.js +3 -8
  91. package/srv/blockchain/wallet-worker/wallet-worker.d.ts +15 -71
  92. package/srv/blockchain/wallet-worker/wallet-worker.js +40 -91
  93. package/srv/cardano-agent-service.cds +146 -0
  94. package/srv/cardano-agent-service.d.ts +2 -0
  95. package/srv/cardano-agent-service.js +12 -0
  96. package/srv/cardano-backend-service.cds +52 -0
  97. package/srv/cardano-backend-service.d.ts +2 -0
  98. package/srv/cardano-backend-service.js +244 -0
  99. package/srv/cardano-indexer-service.cds +201 -73
  100. package/srv/cardano-indexer-service.js +280 -11
  101. package/srv/cardano-service.cds +65 -2
  102. package/srv/cardano-service.js +170 -129
  103. package/srv/cardano-sign-service.cds +200 -180
  104. package/srv/cardano-sign-service.js +57 -184
  105. package/srv/cardano-tx-service.cds +439 -370
  106. package/srv/cardano-tx-service.js +231 -190
  107. package/srv/cardano-ui.cds +16 -16
  108. package/srv/cardano-worker-service.js +7 -15
  109. package/srv/cbor/index.d.ts +1 -1
  110. package/srv/cbor/parse.d.ts +27 -0
  111. package/srv/cbor/parse.js +63 -2
  112. package/srv/server.d.ts +28 -86
  113. package/srv/server.js +132 -135
  114. package/srv/utils/agent-grants-config.d.ts +37 -0
  115. package/srv/utils/agent-grants-config.js +138 -0
  116. package/srv/utils/agent-grants.d.ts +262 -0
  117. package/srv/utils/agent-grants.js +922 -0
  118. package/srv/utils/agent-token-auth.d.ts +16 -0
  119. package/srv/utils/agent-token-auth.js +78 -0
  120. package/srv/utils/backend-request-handler.d.ts +2 -16
  121. package/srv/utils/backend-request-handler.js +3 -18
  122. package/srv/utils/collections.d.ts +4 -8
  123. package/srv/utils/collections.js +4 -8
  124. package/srv/utils/const.d.ts +30 -67
  125. package/srv/utils/const.js +32 -72
  126. package/srv/utils/crypto.d.ts +3 -12
  127. package/srv/utils/crypto.js +5 -18
  128. package/srv/utils/db-indexes.d.ts +25 -0
  129. package/srv/utils/db-indexes.js +94 -0
  130. package/srv/utils/db-sanitize.d.ts +27 -0
  131. package/srv/utils/db-sanitize.js +85 -0
  132. package/srv/utils/epoch-slots.d.ts +20 -0
  133. package/srv/utils/epoch-slots.js +43 -0
  134. package/srv/utils/error-codes.d.ts +20 -73
  135. package/srv/utils/error-codes.js +19 -70
  136. package/srv/utils/errors.d.ts +50 -177
  137. package/srv/utils/errors.js +94 -218
  138. package/srv/utils/legacy-service-paths.d.ts +11 -0
  139. package/srv/utils/legacy-service-paths.js +58 -0
  140. package/srv/utils/liveness.d.ts +16 -0
  141. package/srv/utils/liveness.js +40 -0
  142. package/srv/utils/mappers.d.ts +128 -214
  143. package/srv/utils/mappers.js +354 -299
  144. package/srv/utils/network-context.js +2 -11
  145. package/srv/utils/pg-inline-json.d.ts +8 -0
  146. package/srv/utils/pg-inline-json.js +62 -0
  147. package/srv/utils/pg-order-nulls.d.ts +14 -0
  148. package/srv/utils/pg-order-nulls.js +56 -0
  149. package/srv/utils/plutus-placeholders.d.ts +23 -16
  150. package/srv/utils/plutus-placeholders.js +63 -27
  151. package/srv/utils/rate-limiter.d.ts +46 -0
  152. package/srv/utils/rate-limiter.js +116 -0
  153. package/srv/utils/service-events.d.ts +2 -22
  154. package/srv/utils/service-events.js +3 -23
  155. package/srv/utils/signing-helper.d.ts +6 -16
  156. package/srv/utils/signing-helper.js +36 -60
  157. package/srv/utils/tx-build-helper.d.ts +28 -93
  158. package/srv/utils/tx-build-helper.js +75 -124
  159. package/srv/utils/tx-request-parsers.d.ts +101 -28
  160. package/srv/utils/tx-request-parsers.js +410 -43
  161. package/srv/utils/tx-utils.d.ts +4 -23
  162. package/srv/utils/tx-utils.js +12 -41
  163. package/srv/utils/types.d.ts +252 -179
  164. package/srv/utils/types.js +2 -6
  165. package/srv/utils/validators.d.ts +24 -90
  166. package/srv/utils/validators.js +50 -147
@@ -0,0 +1,29 @@
1
+ import { Tx } from "@harmoniclabs/cardano-ledger-ts";
2
+ /**
3
+ * Inline datums given as CBOR, keyed by output index. Buildooor writes every datum in its
4
+ * own encoding, so definite lists and maps change bytes and hash. These helpers put the
5
+ * caller's bytes back into the built transaction.
6
+ */
7
+ export type CallerDatums = Map<number, Uint8Array>;
8
+ /** Bytes one output gains when its datum is written as given; negative when it shrinks. */
9
+ export declare function callerDatumGrowth(datum: Uint8Array): number;
10
+ /** Bytes the whole transaction gains from the caller's datums, never below zero. */
11
+ export declare function callerDatumsGrowth(datums: CallerDatums): number;
12
+ /**
13
+ * Replace Buildooor's datum encoding in the listed outputs with the caller's bytes.
14
+ * Only the datum bytes change. Containers in CBOR count items, not bytes, so the rest stays valid.
15
+ */
16
+ export declare function writeCallerDatums(tx: Tx, datums: CallerDatums): Tx;
17
+ /** Datum hash as the ledger computes it: blake2b-256 of the datum bytes. */
18
+ export declare function datumHashOf(datum: Uint8Array): string;
19
+ /** Bytes the witness set gains from the caller's datums, never below zero. */
20
+ export declare function witnessDatumsGrowth(datums: Uint8Array[]): number;
21
+ /**
22
+ * Replace Buildooor's encoding of the witness datums with the caller's bytes, then recompute
23
+ * scriptDataHash over redeemers, datums and language views as they now stand in the transaction.
24
+ * The ledger finds a witness datum by the hash of its bytes, so a re-encoded datum is missing to it.
25
+ */
26
+ export declare function writeWitnessDatums(tx: Tx, datums: Uint8Array[], languageViews: Uint8Array): Tx;
27
+ /** scriptDataHash of a transaction over its redeemer and datum bytes as they stand, laid out like Buildooor's getScriptDataHash. */
28
+ export declare function scriptDataHashOf(txBytes: Uint8Array, languageViews: Uint8Array): Uint8Array;
29
+ //# sourceMappingURL=caller-datums.d.ts.map
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.callerDatumGrowth = callerDatumGrowth;
4
+ exports.callerDatumsGrowth = callerDatumsGrowth;
5
+ exports.writeCallerDatums = writeCallerDatums;
6
+ exports.datumHashOf = datumHashOf;
7
+ exports.witnessDatumsGrowth = witnessDatumsGrowth;
8
+ exports.writeWitnessDatums = writeWitnessDatums;
9
+ exports.scriptDataHashOf = scriptDataHashOf;
10
+ const cbor_1 = require("@harmoniclabs/cbor");
11
+ const plutus_data_1 = require("@harmoniclabs/plutus-data");
12
+ const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
13
+ const crypto_1 = require("@harmoniclabs/crypto");
14
+ const uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
15
+ /** Output map entry `2 => [1, #6.24(datum)]` that holds an inline datum. */
16
+ function inlineDatumEntry(datum) {
17
+ return Buffer.concat([Buffer.from([0x02, 0x82, 0x01]), Buffer.from(cbor_1.Cbor.encode(new cbor_1.CborTag(24, new cbor_1.CborBytes(datum))))]);
18
+ }
19
+ /** Bytes one output gains when its datum is written as given; negative when it shrinks. */
20
+ function callerDatumGrowth(datum) {
21
+ return inlineDatumEntry(datum).length - inlineDatumEntry((0, plutus_data_1.dataToCbor)((0, plutus_data_1.dataFromCbor)(datum))).length;
22
+ }
23
+ /** Bytes the whole transaction gains from the caller's datums, never below zero. */
24
+ function callerDatumsGrowth(datums) {
25
+ let growth = 0;
26
+ for (const datum of datums.values())
27
+ growth += callerDatumGrowth(datum);
28
+ return Math.max(0, growth);
29
+ }
30
+ /**
31
+ * Replace Buildooor's datum encoding in the listed outputs with the caller's bytes.
32
+ * Only the datum bytes change. Containers in CBOR count items, not bytes, so the rest stays valid.
33
+ */
34
+ function writeCallerDatums(tx, datums) {
35
+ if (datums.size === 0)
36
+ return tx;
37
+ let bytes = Buffer.from(tx.toCbor());
38
+ const outputs = cardano_ledger_ts_1.Tx.fromCbor((0, uint8array_utils_1.toHex)(bytes)).body.outputs;
39
+ // Last output first, so the offsets of earlier outputs stay valid
40
+ for (const index of [...datums.keys()].sort((a, b) => b - a)) {
41
+ const out = outputs[index];
42
+ const ref = out?.cborRef;
43
+ if (!out || !ref || out.datum === undefined || out.datum instanceof cardano_ledger_ts_1.Hash32) {
44
+ throw new Error(`output ${index} of the built transaction carries no inline datum`);
45
+ }
46
+ const built = inlineDatumEntry((0, plutus_data_1.dataToCbor)(out.datum));
47
+ const at = bytes.subarray(ref.start, ref.end).indexOf(built);
48
+ if (at < 0)
49
+ throw new Error(`inline datum of output ${index} not found in the built transaction`);
50
+ const start = ref.start + at;
51
+ bytes = Buffer.concat([bytes.subarray(0, start), inlineDatumEntry(datums.get(index)), bytes.subarray(start + built.length)]);
52
+ }
53
+ return cardano_ledger_ts_1.Tx.fromCbor((0, uint8array_utils_1.toHex)(bytes));
54
+ }
55
+ /** Datum hash as the ledger computes it: blake2b-256 of the datum bytes. */
56
+ function datumHashOf(datum) {
57
+ return (0, uint8array_utils_1.toHex)((0, crypto_1.blake2b_256)(datum));
58
+ }
59
+ /** Bytes the witness set gains from the caller's datums, never below zero. */
60
+ function witnessDatumsGrowth(datums) {
61
+ let growth = 0;
62
+ for (const datum of datums)
63
+ growth += datum.length - (0, plutus_data_1.dataToCbor)((0, plutus_data_1.dataFromCbor)(datum)).length;
64
+ return Math.max(0, growth);
65
+ }
66
+ /** End offset of a parsed item; a tag carries no offset of its own, its content does. */
67
+ function endOf(item) {
68
+ let inner = item;
69
+ while (inner instanceof cbor_1.CborTag)
70
+ inner = inner.data;
71
+ return inner.subCborRef.end;
72
+ }
73
+ /** Length of a CBOR item head, from its first byte. */
74
+ function headLength(first) {
75
+ const info = first & 0x1f;
76
+ return info < 24 || info === 31 ? 1 : info === 24 ? 2 : info === 25 ? 3 : info === 26 ? 5 : 9;
77
+ }
78
+ function entryOf(map, key) {
79
+ return map.map.find(e => e.k instanceof cbor_1.CborUInt && Number(e.k.num) === key);
80
+ }
81
+ /** Bytes of a map entry's value as they stand in `bytes`. */
82
+ function valueBytes(bytes, entry) {
83
+ return bytes.subarray(entry.k.subCborRef.end, endOf(entry.v));
84
+ }
85
+ /**
86
+ * Replace Buildooor's encoding of the witness datums with the caller's bytes, then recompute
87
+ * scriptDataHash over redeemers, datums and language views as they now stand in the transaction.
88
+ * The ledger finds a witness datum by the hash of its bytes, so a re-encoded datum is missing to it.
89
+ */
90
+ function writeWitnessDatums(tx, datums, languageViews) {
91
+ const wanted = new Map();
92
+ for (const datum of datums) {
93
+ const built = (0, uint8array_utils_1.toHex)((0, plutus_data_1.dataToCbor)((0, plutus_data_1.dataFromCbor)(datum)));
94
+ if (built !== (0, uint8array_utils_1.toHex)(datum))
95
+ wanted.set(built, datum);
96
+ }
97
+ if (wanted.size === 0)
98
+ return tx;
99
+ let bytes = Buffer.from(tx.toCbor());
100
+ let root = cbor_1.Cbor.parse(bytes, { keepRef: true });
101
+ const datumsEntry = entryOf(root.array[1], 4);
102
+ let list = datumsEntry?.v;
103
+ while (list instanceof cbor_1.CborTag)
104
+ list = list.data;
105
+ if (!(list instanceof cbor_1.CborArray))
106
+ throw new Error('the built transaction carries no witness datums');
107
+ // Rebuild the datum list item by item: head, items, and the break byte of an indefinite list
108
+ const listStart = list.subCborRef.start;
109
+ const listEnd = list.subCborRef.end;
110
+ let at = listStart + headLength(bytes[listStart]);
111
+ const parts = [bytes.subarray(listStart, at)];
112
+ for (const item of list.array) {
113
+ const end = endOf(item);
114
+ parts.push(wanted.get((0, uint8array_utils_1.toHex)(bytes.subarray(at, end))) ?? bytes.subarray(at, end));
115
+ at = end;
116
+ }
117
+ parts.push(bytes.subarray(at, listEnd));
118
+ bytes = Buffer.concat([bytes.subarray(0, listStart), ...parts, bytes.subarray(listEnd)]);
119
+ root = cbor_1.Cbor.parse(bytes, { keepRef: true });
120
+ const hashEntry = entryOf(root.array[0], 11);
121
+ if (!hashEntry)
122
+ throw new Error('the built transaction carries no scriptDataHash');
123
+ bytes.set(scriptDataHashOf(bytes, languageViews), endOf(hashEntry.v) - 32);
124
+ return cardano_ledger_ts_1.Tx.fromCbor((0, uint8array_utils_1.toHex)(bytes));
125
+ }
126
+ /** scriptDataHash of a transaction over its redeemer and datum bytes as they stand, laid out like Buildooor's getScriptDataHash. */
127
+ function scriptDataHashOf(txBytes, languageViews) {
128
+ const bytes = Buffer.from(txBytes);
129
+ const witnesses = cbor_1.Cbor.parse(bytes, { keepRef: true }).array[1];
130
+ const redeemers = entryOf(witnesses, 5);
131
+ const datums = entryOf(witnesses, 4);
132
+ if (!redeemers && !datums)
133
+ throw new Error('the transaction carries no redeemers and no datums');
134
+ const datumBytes = datums ? valueBytes(bytes, datums) : Buffer.alloc(0);
135
+ return (0, crypto_1.blake2b_256)(redeemers
136
+ ? Buffer.concat([valueBytes(bytes, redeemers), datumBytes, languageViews])
137
+ : Buffer.concat([Buffer.from([0xa0]), datumBytes, Buffer.from([0xa0])]));
138
+ }
139
+ //# sourceMappingURL=caller-datums.js.map
@@ -1,47 +1,22 @@
1
- import { TxBuildRequest, TxBuildMintRequest, TxBuildPlutusSpendRequest, TxBuildContext, TxBuildResult, LedgerProtocolParameters } from "../../utils/types";
1
+ import { TxBuildRequest, TxBuildMintRequest, TxBuildPlutusSpendRequest, TxBuildPlutusRequest, TxBuildContext, TxBuildResult, LedgerProtocolParameters } from "../../utils/types";
2
2
  import { CardanoClient } from "../cardano-client";
3
- /**
4
- * CardanoTxBuilder - Interface Definition for the Cardano transaction builder (Buildooor)
5
- * Defines the standard methods that any Cardano transaction builder must implement to be used interchangeably.
6
- */
3
+ /** Interface for the Cardano transaction builder (Buildooor). */
7
4
  export interface CardanoTxBuilder {
8
- /**
9
- * Builder name
10
- */
5
+ /** Builder name */
11
6
  name: string;
12
7
  /**
13
- * Initialize the builder
14
- * @param client - The CardanoClient instance
15
- * @param protocolParams - Optional protocol parameters (if not provided, fetched from backend)
8
+ * Initialize the builder.
9
+ * @param protocolParams - optional; fetched from the backend when omitted
16
10
  */
17
11
  init(client: CardanoClient, protocolParams?: LedgerProtocolParameters): Promise<void>;
18
- /**
19
- * Build unsigned transfer transaction (ADA-only or with native assets)
20
- * @param req transaction build request
21
- * @param ctx transaction build context
22
- * @returns {Promise<TxBuildResult>} transaction build result
23
- */
12
+ /** Build an unsigned transfer transaction (ADA-only or with native assets). */
24
13
  buildUnsignedTransfer(req: TxBuildRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
25
- /**
26
- * Build unsigned transaction with metadata
27
- * @param req transaction build request
28
- * @param ctx transaction build context
29
- * @returns {Promise<TxBuildResult>} transaction build result
30
- */
14
+ /** Build an unsigned transaction with attached metadata. */
31
15
  buildUnsignedTransactionWithMetadata(req: TxBuildRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
32
- /**
33
- * Build unsigned Plutus SC transaction
34
- * @param req transaction build request
35
- * @param ctx transaction build context
36
- * @returns {Promise<TxBuildResult>} transaction build result
37
- */
16
+ /** Build an unsigned Plutus mint transaction. */
38
17
  buildUnsignedMintTransaction(req: TxBuildMintRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
39
- /**
40
- * Build unsigned Plutus spending transaction (consume UTxO at script address)
41
- * @param req transaction build request with plutusScriptExecution
42
- * @param ctx transaction build context
43
- * @returns {Promise<TxBuildResult>} transaction build result
44
- */
18
+ /** Build an unsigned Plutus spending transaction (consume a UTxO at a script address). */
45
19
  buildUnsignedPlutusSpendTransaction(req: TxBuildPlutusSpendRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
20
+ buildUnsignedPlutusTransaction(req: TxBuildPlutusRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
46
21
  }
47
22
  //# sourceMappingURL=cardano-tx.d.ts.map
@@ -0,0 +1,12 @@
1
+ import type { Transaction as CapTransaction } from '@sap/cds';
2
+ export interface TxKey {
3
+ hash: string;
4
+ txSeq: number | string | null;
5
+ }
6
+ /** `txSeq` as a stable map key: Int64 columns come back as number or string depending on the driver. */
7
+ export declare const seqKey: (txSeq: number | string) => string;
8
+ /** Hash and txSeq of the given transactions that are indexed. */
9
+ export declare function readTxKeys(tx: CapTransaction, hashes: string[]): Promise<TxKey[]>;
10
+ /** Delete transactions with their input/output, asset, metadata, certificate, withdrawal and redeemer rows. */
11
+ export declare function deleteTransactionRows(tx: CapTransaction, keys: TxKey[]): Promise<void>;
12
+ //# sourceMappingURL=transaction-rows.d.ts.map
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.seqKey = void 0;
7
+ exports.readTxKeys = readTxKeys;
8
+ exports.deleteTransactionRows = deleteTransactionRows;
9
+ const cds_1 = __importDefault(require("@sap/cds"));
10
+ const cardano_1 = require("#cds-models/odatano/cardano");
11
+ const collections_1 = require("../utils/collections");
12
+ const { SELECT, DELETE } = cds_1.default.ql;
13
+ /** `txSeq` as a stable map key: Int64 columns come back as number or string depending on the driver. */
14
+ const seqKey = (txSeq) => String(Number(txSeq));
15
+ exports.seqKey = seqKey;
16
+ /** Hash and txSeq of the given transactions that are indexed. */
17
+ async function readTxKeys(tx, hashes) {
18
+ const keys = [];
19
+ for (const hashChunk of (0, collections_1.chunk)(hashes, collections_1.IN_CHUNK)) {
20
+ const rows = await tx.run(SELECT.from(cardano_1.Transactions).columns('hash', 'txSeq').where({ hash: { in: hashChunk } }));
21
+ keys.push(...(rows ?? []));
22
+ }
23
+ return keys;
24
+ }
25
+ /** Delete transactions with their input/output, asset, metadata, certificate, withdrawal and redeemer rows. */
26
+ async function deleteTransactionRows(tx, keys) {
27
+ for (const keyChunk of (0, collections_1.chunk)(keys, collections_1.IN_CHUNK)) {
28
+ const hashes = keyChunk.map(k => k.hash);
29
+ const seqs = keyChunk.filter(k => k.txSeq != null).map(k => k.txSeq);
30
+ if (seqs.length) {
31
+ await tx.run(DELETE.from(cardano_1.TransactionInputAssets).where({ input_txSeq: { in: seqs } }));
32
+ await tx.run(DELETE.from(cardano_1.TransactionOutputAssets).where({ output_txSeq: { in: seqs } }));
33
+ await tx.run(DELETE.from(cardano_1.TransactionInputs).where({ txSeq: { in: seqs } }));
34
+ await tx.run(DELETE.from(cardano_1.TransactionOutputs).where({ txSeq: { in: seqs } }));
35
+ }
36
+ await tx.run(DELETE.from(cardano_1.TransactionMetadata_).where({ tx_hash: { in: hashes } }));
37
+ await tx.run(DELETE.from(cardano_1.TransactionCertificates).where({ tx_hash: { in: hashes } }));
38
+ await tx.run(DELETE.from(cardano_1.TransactionWithdrawals).where({ tx_hash: { in: hashes } }));
39
+ await tx.run(DELETE.from(cardano_1.TransactionRedeemers).where({ tx_hash: { in: hashes } }));
40
+ await tx.run(DELETE.from(cardano_1.Transactions).where({ hash: { in: hashes } }));
41
+ }
42
+ }
43
+ //# sourceMappingURL=transaction-rows.js.map
@@ -2,25 +2,12 @@ import type { TxBuildRequest } from '../../utils/types';
2
2
  import type { Network } from '../cardano-client';
3
3
  import type { WalletJobKindValue } from './job-store';
4
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.
5
+ * Transforms a stored wallet-job request (Build*-action payload shape) into the
6
+ * TxBuildRequest the CardanoIndexer build methods expect, mirroring the synchronous handlers.
7
+ * Validation failures throw BackendError 400 INVALID_INPUT so the job fails terminally, not via retries.
17
8
  */
18
9
  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
- */
10
+ /** Raw job request → TxBuildRequest for the matching build method; malformed payloads throw 400 INVALID_INPUT. */
24
11
  export declare function prepareWorkerBuildRequest(kind: WalletJobKindValue, raw: RawRequest, network: Network): TxBuildRequest;
25
12
  export {};
26
13
  //# sourceMappingURL=build-request.d.ts.map
@@ -12,12 +12,7 @@ const const_1 = require("../../utils/const");
12
12
  function fail(message) {
13
13
  throw new errors_1.BackendError(message, 400, error_codes_1.ERROR_CODES.INVALID_INPUT);
14
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
- */
15
+ /** Presence-only check; format validation (bech32, hex, amounts) stays with the builder/indexer. */
21
16
  function requirePresent(raw, required) {
22
17
  const missing = required.filter((f) => raw[f] === undefined || raw[f] === null || raw[f] === '');
23
18
  if (missing.length > 0)
@@ -29,7 +24,7 @@ function parseJsonField(raw, field) {
29
24
  return undefined;
30
25
  if (typeof value !== 'string')
31
26
  fail(`${field} must be a JSON string`);
32
- const result = (0, validators_1.validateJsonWithLimits)(value, field);
27
+ const result = validators_1.PLUTUS_JSON_FIELDS.has(field) ? (0, validators_1.validatePlutusJson)(value, field) : (0, validators_1.validateJsonWithLimits)(value, field);
33
28
  if (!result.valid)
34
29
  fail(result.error);
35
30
  return result.parsed;
@@ -42,8 +37,7 @@ function parseScriptParams(raw) {
42
37
  fail('scriptParamsJson must be a JSON array');
43
38
  return parsed;
44
39
  }
45
- /** Mirrors the BuildMint/BuildPlutusSpend mint-action parsing (bigint quantities,
46
- * multi-policy per-action fields). */
40
+ /** Mint-action parsing as in BuildMint/BuildPlutusSpend (bigint quantities, per-action policy fields). */
47
41
  function parseMintActions(raw, allowBareNames) {
48
42
  const parsed = parseJsonField(raw, 'mintActionsJson');
49
43
  if (!Array.isArray(parsed))
@@ -58,7 +52,7 @@ function parseMintActions(raw, allowBareNames) {
58
52
  }
59
53
  if (typeof action.assetUnit !== 'string')
60
54
  fail('Each mint action must have an assetUnit string');
61
- // Multi-policy mint FR: optional per-action mintingPolicyScript + redeemerJson.
55
+ // Optional per-action mintingPolicyScript + redeemerJson (multi-policy mint).
62
56
  const policyFields = (0, tx_request_parsers_1.parseMintActionPolicyFields)(action, i);
63
57
  if (policyFields.error)
64
58
  fail(policyFields.error);
@@ -100,13 +94,11 @@ function scriptHashOf(scriptHex, context) {
100
94
  }
101
95
  }
102
96
  /**
103
- * BUG 9 mirror: every (expanded) mint action must carry the effective policy id —
104
- * parseAssetUnit silently discards the first 56 hex chars, so a mismatched prefix
105
- * would mint a truncated asset name.
97
+ * Every mint action must carry the effective policy id: parseAssetUnit drops the first
98
+ * 56 hex chars, so a mismatched prefix would mint a truncated asset name.
106
99
  */
107
100
  function assertPolicyPrefix(actions, policyId) {
108
- // Actions with their own per-action script were already checked against THAT
109
- // script's policy id during parsing.
101
+ // Actions with their own script were already checked against that script's policy id.
110
102
  const mismatch = actions.find((a) => !a.mintingPolicyScript && !a.assetUnit.toLowerCase().startsWith(policyId));
111
103
  if (mismatch) {
112
104
  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)`);
@@ -122,6 +114,8 @@ function prepareSimpleAda(raw, network) {
122
114
  const clean = { ...raw };
123
115
  clean.forceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.forceInputsJson, 'forceInputsJson'));
124
116
  delete clean.forceInputsJson;
117
+ clean.protectInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.protectInputsJson, 'protectInputsJson'));
118
+ delete clean.protectInputsJson;
125
119
  const outputDatum = parseJsonField(raw, 'outputDatumJson');
126
120
  if (outputDatum !== undefined)
127
121
  clean.outputDatum = outputDatum;
@@ -178,6 +172,7 @@ function prepareMint(raw, network) {
178
172
  const inlineDatum = parseJsonField(raw, 'inlineDatumJson');
179
173
  const mintRedeemer = parseJsonField(raw, 'mintRedeemerJson');
180
174
  const forceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.forceInputsJson, 'forceInputsJson'));
175
+ const protectInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.protectInputsJson, 'protectInputsJson'));
181
176
  const referenceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.referenceInputsJson, 'referenceInputsJson'));
182
177
  const extraOutputs = takeParsed((0, tx_request_parsers_1.parseExtraOutputs)(raw.extraOutputsJson));
183
178
  if (raw.lockOnScript && (!scriptParams || scriptParams.length === 0)) {
@@ -198,6 +193,7 @@ function prepareMint(raw, network) {
198
193
  delete clean.mintRedeemerJson;
199
194
  delete clean.lockOnScript;
200
195
  delete clean.forceInputsJson;
196
+ delete clean.protectInputsJson;
201
197
  delete clean.referenceInputsJson;
202
198
  delete clean.extraOutputsJson;
203
199
  if (parsedMetadata)
@@ -207,8 +203,7 @@ function prepareMint(raw, network) {
207
203
  if (raw.referenceScriptHex)
208
204
  clean.referenceScript = raw.referenceScriptHex;
209
205
  delete clean.referenceScriptHex;
210
- // Apply script parameters (parameterized policies), expand bare asset names,
211
- // route lockOnScript output — mirrors BuildMintTransaction.
206
+ // Apply script parameters, expand bare asset names, route lockOnScript output.
212
207
  let finalMintingPolicyScript = raw.mintingPolicyScript;
213
208
  let effectivePolicyId;
214
209
  if (scriptParams && scriptParams.length > 0) {
@@ -246,6 +241,7 @@ function prepareMint(raw, network) {
246
241
  inlineDatum,
247
242
  mintRedeemer,
248
243
  forceInputs,
244
+ protectInputs,
249
245
  referenceInputs,
250
246
  extraOutputs,
251
247
  };
@@ -264,9 +260,10 @@ function preparePlutusSpend(raw, network) {
264
260
  fail('lockOnScript requires scriptParamsJson to derive script address');
265
261
  }
266
262
  const forceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.forceInputsJson, 'forceInputsJson'));
263
+ const protectInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.protectInputsJson, 'protectInputsJson'));
267
264
  const referenceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.referenceInputsJson, 'referenceInputsJson'));
268
265
  const extraOutputs = takeParsed((0, tx_request_parsers_1.parseExtraOutputs)(raw.extraOutputsJson));
269
- // Optional combined spend+mint (FR-1) — mirrors BuildPlutusSpendTransaction.
266
+ // Optional combined spend+mint.
270
267
  const validatorScript = raw.validatorScript;
271
268
  const mintingPolicyScript = raw.mintingPolicyScript;
272
269
  let mintActions;
@@ -326,6 +323,7 @@ function preparePlutusSpend(raw, network) {
326
323
  requiredSigners,
327
324
  inlineDatum,
328
325
  forceInputs,
326
+ protectInputs,
329
327
  referenceInputs,
330
328
  extraOutputs,
331
329
  mintActions,
@@ -338,6 +336,7 @@ function preparePlutusSpend(raw, network) {
338
336
  delete clean.scriptParamsJson;
339
337
  delete clean.inlineDatumJson;
340
338
  delete clean.forceInputsJson;
339
+ delete clean.protectInputsJson;
341
340
  delete clean.referenceInputsJson;
342
341
  delete clean.extraOutputsJson;
343
342
  delete clean.mintActionsJson;
@@ -351,11 +350,7 @@ function preparePlutusSpend(raw, network) {
351
350
  delete clean.lockOnScript;
352
351
  return clean;
353
352
  }
354
- /**
355
- * Transform the raw job request (documented Build*-action payload) into the
356
- * TxBuildRequest the matching CardanoIndexer build method expects. Throws
357
- * BackendError 400 INVALID_INPUT for malformed payloads (terminal job failure).
358
- */
353
+ /** Raw job request → TxBuildRequest for the matching build method; malformed payloads throw 400 INVALID_INPUT. */
359
354
  function prepareWorkerBuildRequest(kind, raw, network) {
360
355
  switch (kind) {
361
356
  case 'simpleAda': return prepareSimpleAda(raw, network);
@@ -1,21 +1,9 @@
1
1
  import type { CardanoClient } from '../cardano-client';
2
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".
3
+ * Watches `submitted` jobs until their tx sits at depth >= `confirmationDepth`, via crawler
4
+ * `blockIndexed`/`reorg` hooks plus an always-on polling fallback. A reorg re-submits the SAME
5
+ * signed CBOR (never a rebuild); a tx unseen past `confirmationTimeoutMs` fails as TX_DROPPED.
6
+ * Depth = `tipHeight - foundHeight + 1`, so depth 1 means "included in a block".
19
7
  */
20
8
  export interface TrackedJob {
21
9
  jobId: string;
@@ -28,6 +16,11 @@ export interface TrackedJob {
28
16
  submittedAt: string;
29
17
  foundSlot: number | null;
30
18
  foundHeight: number | null;
19
+ /**
20
+ * Polling round in which the tx was last seen on-chain. An inclusion from an earlier
21
+ * round is re-checked before confirming, so a rollback the crawler did not report cannot slip through.
22
+ */
23
+ seenRound?: number;
31
24
  }
32
25
  export interface ConfirmationTrackerOptions {
33
26
  confirmationDepth: number;
@@ -59,6 +52,8 @@ export declare class ConfirmationTracker {
59
52
  private running;
60
53
  private polling;
61
54
  private lastKnownTipHeight;
55
+ /** Polling round counter; see TrackedJob.seenRound. */
56
+ private round;
62
57
  constructor(deps: ConfirmationTrackerDeps);
63
58
  start(): void;
64
59
  stop(): void;
@@ -77,10 +72,23 @@ export declare class ConfirmationTracker {
77
72
  }): void;
78
73
  private onBlockIndexed;
79
74
  private onReorg;
75
+ /**
76
+ * Inclusion rolled back: back to watching, optionally re-submitting the SAME signed CBOR
77
+ * (never a rebuild — the double-spend guard). "Already known" means the tx survived; success.
78
+ */
79
+ private forgetInclusion;
80
80
  /** One polling round. Public for tests; guarded against overlapping rounds. */
81
81
  pollOnce(): Promise<void>;
82
- /** Confirm every found job whose depth requirement is met by the known tip. */
82
+ /**
83
+ * Confirm every found job whose depth is met by the known tip. With `revalidate`
84
+ * (polling path) an inclusion not seen in this round is looked up again first.
85
+ */
83
86
  private confirmMature;
87
+ /**
88
+ * Is the tx still on-chain and deep enough? A tx that moved blocks is re-anchored at its
89
+ * new height; one that is gone goes back to watching and the tip is re-learned next round.
90
+ */
91
+ private stillIncluded;
84
92
  private finalize;
85
93
  }
86
94
  //# sourceMappingURL=confirmation-tracker.d.ts.map