@odatano/core 1.9.5 → 1.11.0

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 CHANGED
@@ -1,164 +1,164 @@
1
- {
2
- "name": "@odatano/core",
3
- "version": "1.9.5",
4
- "description": "SAP CAP plugin for Cardano blockchain OData V4 integration",
5
- "imports": {
6
- "#cds-models/*": "./@cds-models/*/index.js"
7
- },
8
- "main": "src/index.js",
9
- "types": "src/index.d.ts",
10
- "files": [
11
- "cds-plugin.js",
12
- "src/**/*.js",
13
- "src/**/*.d.ts",
14
- "srv/**/*.js",
15
- "srv/**/*.d.ts",
16
- "srv/**/*.cds",
17
- "db/**/*.cds",
18
- "@cds-models/"
19
- ],
20
- "engines": {
21
- "node": ">=20"
22
- },
23
- "peerDependencies": {
24
- "@sap/cds": ">=9"
25
- },
26
- "dependencies": {
27
- "@blockfrost/blockfrost-js": "~6.0.0",
28
- "@cap-js/hana": "^2",
29
- "@cardano-ogmios/client": "^6.14.0",
30
- "@harmoniclabs/buildooor": "0.2.6",
31
- "@harmoniclabs/cardano-costmodels-ts": "~1.4.0",
32
- "@harmoniclabs/cardano-ledger-ts": "^0.5.1",
33
- "@harmoniclabs/cbor": "^2.0.1",
34
- "@harmoniclabs/crypto": "^0.3.0",
35
- "@harmoniclabs/uint8array-utils": "^1.0.4",
36
- "@sap/xssec": "^4",
37
- "axios": "^1.16.1",
38
- "bech32": "^2.0.0",
39
- "blake2b": "^2.1.4"
40
- },
41
- "optionalDependencies": {
42
- "pkcs11js": "^2.1.6"
43
- },
44
- "overrides": {
45
- "axios": "^1.16.1"
46
- },
47
- "devDependencies": {
48
- "@cap-js/cds-test": "^0.4.1",
49
- "@cap-js/cds-typer": "^0.38.0",
50
- "@cap-js/cds-types": "^0.15.0",
51
- "@cap-js/sqlite": "^2",
52
- "@sap/cds": "^9",
53
- "@sap/cds-dk": "^9.4.3",
54
- "@sap/eslint-plugin-cds": "^4",
55
- "@types/blake2b": "^2.1.3",
56
- "@types/jest": "^29.5.14",
57
- "@types/node": "^22.19.7",
58
- "@typescript-eslint/eslint-plugin": "^8.50.1",
59
- "@typescript-eslint/parser": "^8.50.1",
60
- "dotenv": "^16.3.1",
61
- "eslint": "^9.39.2",
62
- "jest": "^29.6.1",
63
- "nock": "^13.5.6",
64
- "ts-jest": "^29.4.5",
65
- "ts-node": "^10.9.2",
66
- "tsx": "^4.21.0",
67
- "typescript": "^5.9.3"
68
- },
69
- "cds": {
70
- "typer": {
71
- "ieee754compatible": true
72
- },
73
- "build": {
74
- "tasks": [
75
- {
76
- "for": "node-cf",
77
- "src": "srv",
78
- "dest": "../gen/srv"
79
- },
80
- {
81
- "for": "hana",
82
- "src": "db",
83
- "dest": "../gen/db"
84
- }
85
- ]
86
- },
87
- "requires": {
88
- "db": {
89
- "kind": "sqlite",
90
- "credentials": {
91
- "url": "db.sqlite"
92
- }
93
- },
94
- "[production]": {
95
- "db": {
96
- "kind": "hana",
97
- "pool": {
98
- "acquireTimeoutMillis": 30000,
99
- "min": 0,
100
- "max": 10
101
- }
102
- },
103
- "auth": "xsuaa"
104
- }
105
- }
106
- },
107
- "scripts": {
108
- "clean": "node -e \"require('glob').sync('{srv,db,src}/**/*.{js,js.map,d.ts,d.ts.map}',{ignore:'**/node_modules/**'}).forEach(f=>require('fs').unlinkSync(f));console.log('Clean complete')\"",
109
- "clean:models": "node -e \"require('fs').rmSync('@cds-models',{recursive:true,force:true});console.log('Removed @cds-models')\"",
110
- "build": "npm run cds:types && tsc",
111
- "build:plugin": "npm run cds:types && tsc -p tsconfig.build.json",
112
- "prepublishOnly": "npm run clean && npm run clean:models && npm run build:plugin",
113
- "start": "cds-serve",
114
- "cds:watch": "cds watch",
115
- "cds:serve": "cds serve --with-mocks",
116
- "cds:types": "cds-typer \"*\" --outputDirectory @cds-models",
117
- "lint": "eslint .",
118
- "typecheck": "tsc --noEmit",
119
- "db:deploy": "cds deploy",
120
- "pretest": "npm run cds:types && npm run db:deploy",
121
- "test": "jest --runInBand --forceExit",
122
- "test:coverage": "jest --runInBand --coverage --forceExit",
123
- "test:ci": "jest --runInBand --testPathIgnorePatterns=core-ogmios.test.ts --forceExit",
124
- "test:ci:coverage": "jest --runInBand --coverage --testPathIgnorePatterns=core-ogmios.test.ts --forceExit",
125
- "test:integration": "npm test -- --testPathPattern=integration",
126
- "test:integration:blockfrost": "npm test -- --testPathPattern=core.blockfrost.test.ts",
127
- "test:integration:koios": "npm test -- --testPathPattern=core.koios.test.ts",
128
- "test:integration:ogmios": "npm test -- --testPathPattern=core-ogmios.test.ts",
129
- "test:integration:both": "npm run test:integration:blockfrost && npm run test:integration:koios",
130
- "test:unit": "npm test -- --testPathPattern=unit",
131
- "watch-odatano": "cds watch --open odatano/index.html?sap-ui-xx-viewCache=false --livereload false",
132
- "watch-wallet": "cds watch --open wallet/webapp/index.html"
133
- },
134
- "workspaces": [
135
- "app/router"
136
- ],
137
- "sapux": [
138
- "app/odatano"
139
- ],
140
- "directories": {
141
- "doc": "docs",
142
- "test": "test"
143
- },
144
- "repository": {
145
- "type": "git",
146
- "url": "git+https://github.com/ODATANO/ODATANO.git"
147
- },
148
- "keywords": [
149
- "CAP",
150
- "CDS",
151
- "plugin",
152
- "Cardano",
153
- "blockchain",
154
- "OData",
155
- "SAP"
156
- ],
157
- "author": "Maximilian Weber",
158
- "license": "Apache-2.0",
159
- "type": "commonjs",
160
- "bugs": {
161
- "url": "https://github.com/ODATANO/ODATANO/issues"
162
- },
163
- "homepage": "https://github.com/ODATANO/ODATANO#readme"
1
+ {
2
+ "name": "@odatano/core",
3
+ "version": "1.11.0",
4
+ "description": "SAP CAP plugin for Cardano blockchain OData V4 integration",
5
+ "imports": {
6
+ "#cds-models/*": "./@cds-models/*/index.js"
7
+ },
8
+ "main": "src/index.js",
9
+ "types": "src/index.d.ts",
10
+ "files": [
11
+ "cds-plugin.js",
12
+ "src/**/*.js",
13
+ "src/**/*.d.ts",
14
+ "srv/**/*.js",
15
+ "srv/**/*.d.ts",
16
+ "srv/**/*.cds",
17
+ "db/**/*.cds",
18
+ "@cds-models/"
19
+ ],
20
+ "engines": {
21
+ "node": ">=20"
22
+ },
23
+ "peerDependencies": {
24
+ "@sap/cds": ">=9"
25
+ },
26
+ "dependencies": {
27
+ "@blockfrost/blockfrost-js": "~6.0.0",
28
+ "@cap-js/hana": "^2",
29
+ "@cardano-ogmios/client": "^6.14.0",
30
+ "@harmoniclabs/buildooor": "0.2.9",
31
+ "@harmoniclabs/cardano-costmodels-ts": "~1.6.1",
32
+ "@harmoniclabs/cardano-ledger-ts": "^0.5.6",
33
+ "@harmoniclabs/cbor": "^2.0.1",
34
+ "@harmoniclabs/crypto": "^0.3.0",
35
+ "@harmoniclabs/uint8array-utils": "^1.0.4",
36
+ "@sap/xssec": "^4",
37
+ "axios": "^1.16.1",
38
+ "bech32": "^2.0.0",
39
+ "blake2b": "^2.1.4"
40
+ },
41
+ "optionalDependencies": {
42
+ "pkcs11js": "^2.1.6"
43
+ },
44
+ "overrides": {
45
+ "axios": "^1.16.1"
46
+ },
47
+ "devDependencies": {
48
+ "@cap-js/cds-test": "^0.4.1",
49
+ "@cap-js/cds-typer": "^0.38.0",
50
+ "@cap-js/cds-types": "^0.15.0",
51
+ "@cap-js/sqlite": "^2",
52
+ "@sap/cds": "^9",
53
+ "@sap/cds-dk": "^9.4.3",
54
+ "@sap/eslint-plugin-cds": "^4",
55
+ "@types/blake2b": "^2.1.3",
56
+ "@types/jest": "^29.5.14",
57
+ "@types/node": "^22.19.7",
58
+ "@typescript-eslint/eslint-plugin": "^8.50.1",
59
+ "@typescript-eslint/parser": "^8.50.1",
60
+ "dotenv": "^16.3.1",
61
+ "eslint": "^9.39.2",
62
+ "jest": "^29.6.1",
63
+ "nock": "^13.5.6",
64
+ "ts-jest": "^29.4.5",
65
+ "ts-node": "^10.9.2",
66
+ "tsx": "^4.21.0",
67
+ "typescript": "^5.9.3"
68
+ },
69
+ "cds": {
70
+ "typer": {
71
+ "ieee754compatible": true
72
+ },
73
+ "build": {
74
+ "tasks": [
75
+ {
76
+ "for": "node-cf",
77
+ "src": "srv",
78
+ "dest": "../gen/srv"
79
+ },
80
+ {
81
+ "for": "hana",
82
+ "src": "db",
83
+ "dest": "../gen/db"
84
+ }
85
+ ]
86
+ },
87
+ "requires": {
88
+ "db": {
89
+ "kind": "sqlite",
90
+ "credentials": {
91
+ "url": "db.sqlite"
92
+ }
93
+ },
94
+ "[production]": {
95
+ "db": {
96
+ "kind": "hana",
97
+ "pool": {
98
+ "acquireTimeoutMillis": 30000,
99
+ "min": 0,
100
+ "max": 10
101
+ }
102
+ },
103
+ "auth": "xsuaa"
104
+ }
105
+ }
106
+ },
107
+ "scripts": {
108
+ "clean": "node -e \"require('glob').sync('{srv,db,src}/**/*.{js,js.map,d.ts,d.ts.map}',{ignore:'**/node_modules/**'}).forEach(f=>require('fs').unlinkSync(f));console.log('Clean complete')\"",
109
+ "clean:models": "node -e \"require('fs').rmSync('@cds-models',{recursive:true,force:true});console.log('Removed @cds-models')\"",
110
+ "build": "npm run cds:types && tsc",
111
+ "build:plugin": "npm run cds:types && tsc -p tsconfig.build.json",
112
+ "prepublishOnly": "npm run clean && npm run clean:models && npm run build:plugin",
113
+ "start": "cds-serve",
114
+ "cds:watch": "cds watch",
115
+ "cds:serve": "cds serve --with-mocks",
116
+ "cds:types": "cds-typer \"*\" --outputDirectory @cds-models",
117
+ "lint": "eslint .",
118
+ "typecheck": "tsc --noEmit",
119
+ "db:deploy": "cds deploy",
120
+ "pretest": "npm run cds:types && npm run db:deploy",
121
+ "test": "jest --runInBand --forceExit",
122
+ "test:coverage": "jest --runInBand --coverage --forceExit",
123
+ "test:ci": "jest --runInBand --testPathIgnorePatterns=core-ogmios.test.ts --forceExit",
124
+ "test:ci:coverage": "jest --runInBand --coverage --testPathIgnorePatterns=core-ogmios.test.ts --forceExit",
125
+ "test:integration": "npm test -- --testPathPattern=integration",
126
+ "test:integration:blockfrost": "npm test -- --testPathPattern=core.blockfrost.test.ts",
127
+ "test:integration:koios": "npm test -- --testPathPattern=core.koios.test.ts",
128
+ "test:integration:ogmios": "npm test -- --testPathPattern=core-ogmios.test.ts",
129
+ "test:integration:both": "npm run test:integration:blockfrost && npm run test:integration:koios",
130
+ "test:unit": "npm test -- --testPathPattern=unit",
131
+ "watch-odatano": "cds watch --open odatano/index.html?sap-ui-xx-viewCache=false --livereload false",
132
+ "watch-wallet": "cds watch --open wallet/webapp/index.html"
133
+ },
134
+ "workspaces": [
135
+ "app/router"
136
+ ],
137
+ "sapux": [
138
+ "app/odatano"
139
+ ],
140
+ "directories": {
141
+ "doc": "docs",
142
+ "test": "test"
143
+ },
144
+ "repository": {
145
+ "type": "git",
146
+ "url": "git+https://github.com/ODATANO/ODATANO.git"
147
+ },
148
+ "keywords": [
149
+ "CAP",
150
+ "CDS",
151
+ "plugin",
152
+ "Cardano",
153
+ "blockchain",
154
+ "OData",
155
+ "SAP"
156
+ ],
157
+ "author": "Maximilian Weber",
158
+ "license": "Apache-2.0",
159
+ "type": "commonjs",
160
+ "bugs": {
161
+ "url": "https://github.com/ODATANO/ODATANO/issues"
162
+ },
163
+ "homepage": "https://github.com/ODATANO/ODATANO#readme"
164
164
  }
package/src/index.js CHANGED
@@ -85,6 +85,9 @@ async function initialize() {
85
85
  if (!alreadyInitialized) {
86
86
  logger.info('ODATANO core initialized');
87
87
  }
88
+ // Re-drive deferred submissions interrupted by a restart (plugin mode). Non-fatal.
89
+ const { redriveInterruptedSubmissionsIfConfigured } = await Promise.resolve().then(() => __importStar(require('../srv/server')));
90
+ await redriveInterruptedSubmissionsIfConfigured();
88
91
  }
89
92
  /**
90
93
  * Shutdown the ODATANO plugin.
@@ -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. Operating at the raw-CBOR level also avoids
19
- * the @harmoniclabs/cardano-ledger-ts AuxiliaryData.fromCbor bug on metadata-only aux_data.
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. Raw-CBOR parsing is immune to the
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;
@@ -0,0 +1,63 @@
1
+ import cds, { Request } from '@sap/cds';
2
+ /** Shape persisted by indexVerifiedTransactionSubmission. */
3
+ export interface FinalizeParams {
4
+ signingRequestId: string;
5
+ buildId: string;
6
+ fullSignedTxCbor: string;
7
+ txHash: string;
8
+ verificationResult: {
9
+ txBodyHash: string;
10
+ witnessCount: number;
11
+ signerKeyHashes: string[];
12
+ warnings: string[];
13
+ };
14
+ signerType?: string;
15
+ signerInfo?: string;
16
+ }
17
+ /**
18
+ * Submit a verified+claimed signing request to the blockchain and persist the
19
+ * outcome — DELIBERATELY outside the caller's request transaction.
20
+ *
21
+ * The caller must already have durably committed `status:'submitting'` (the
22
+ * claim). This function then:
23
+ * 1. submits with NO DB write-lock held (the lock was the reason concurrent
24
+ * submits serialized and the SQLite busy-timeout could fire mid-network),
25
+ * 2. on submit failure: marks the request 'failed' in its own committed tx
26
+ * and rethrows (NOT rolled back to a pre-submit status — losing the
27
+ * attempt would hide a tx the node may have accepted),
28
+ * 3. on success: persists the submission + 'submitted' status in a committed
29
+ * transaction.
30
+ *
31
+ * Crash window: a process death between (1) and (3) leaves the request durably
32
+ * at 'submitting'. Deferred-path requests carry their signed CBOR on the row
33
+ * and are re-driven at the next boot (redriveInterruptedSubmissions); sync-path
34
+ * requests are left for the operator/poller exactly as before.
35
+ */
36
+ export declare function submitAndFinalize(SigningRequests: unknown, params: FinalizeParams, afterFinalize?: (db: cds.Transaction) => Promise<void>): Promise<unknown>;
37
+ /**
38
+ * Deferred-submit scheduler (KNOWN_ISSUES #11, Layer 2).
39
+ *
40
+ * Called by an action handler AFTER verify + claim ran on the CALLER's
41
+ * transaction. Hooks the request's post-commit event: only once the caller's
42
+ * root transaction has committed (claim durable, pooled connection released)
43
+ * does the network submit + finalize run — detached via setImmediate +
44
+ * runWithoutAmbientTx, so no ambient transaction is held across it.
45
+ *
46
+ * If the caller's transaction rolls back instead, 'succeeded' never fires and
47
+ * nothing was claimed — strictly consistent.
48
+ */
49
+ export declare function scheduleDeferredSubmit(req: Request, SigningRequests: unknown, params: FinalizeParams): void;
50
+ /**
51
+ * Boot-time recovery: re-drive submissions that were claimed on the deferred
52
+ * path (status 'submitting' WITH persisted signedTxCbor) but never finalized —
53
+ * i.e. the process died between the caller's commit and the detached submit.
54
+ *
55
+ * Safe to repeat: a tx the node already holds finalizes as 'submitted' via the
56
+ * TransactionAlreadySubmittedError path in submitAndFinalize. Rows at
57
+ * 'submitting' WITHOUT signed CBOR (sync-path crash window) are deliberately
58
+ * left untouched for the operator/poller, exactly as before Layer 2.
59
+ *
60
+ * @returns number of rows re-driven (attempted, not necessarily succeeded)
61
+ */
62
+ export declare function redriveInterruptedSubmissions(): Promise<number>;
63
+ //# sourceMappingURL=submission-finalizer.d.ts.map
@@ -0,0 +1,153 @@
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.submitAndFinalize = submitAndFinalize;
7
+ exports.scheduleDeferredSubmit = scheduleDeferredSubmit;
8
+ exports.redriveInterruptedSubmissions = redriveInterruptedSubmissions;
9
+ const cds_1 = __importDefault(require("@sap/cds"));
10
+ const errors_1 = require("../../utils/errors");
11
+ const tx_utils_1 = require("../../utils/tx-utils");
12
+ const tx_build_helper_1 = require("../../utils/tx-build-helper");
13
+ const external_signer_1 = require("./external-signer");
14
+ const { SELECT, UPDATE } = cds_1.default.ql;
15
+ const logger = cds_1.default.log('SubmissionFinalizer');
16
+ // Lazy require breaks the srv/server.ts <-> this-module import cycle (the
17
+ // server calls redriveInterruptedSubmissions at boot; we need its app-context
18
+ // getters at runtime only). Same pattern as src/plugin.ts.
19
+ function server() {
20
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
21
+ return require('../../server');
22
+ }
23
+ /**
24
+ * Submit a verified+claimed signing request to the blockchain and persist the
25
+ * outcome — DELIBERATELY outside the caller's request transaction.
26
+ *
27
+ * The caller must already have durably committed `status:'submitting'` (the
28
+ * claim). This function then:
29
+ * 1. submits with NO DB write-lock held (the lock was the reason concurrent
30
+ * submits serialized and the SQLite busy-timeout could fire mid-network),
31
+ * 2. on submit failure: marks the request 'failed' in its own committed tx
32
+ * and rethrows (NOT rolled back to a pre-submit status — losing the
33
+ * attempt would hide a tx the node may have accepted),
34
+ * 3. on success: persists the submission + 'submitted' status in a committed
35
+ * transaction.
36
+ *
37
+ * Crash window: a process death between (1) and (3) leaves the request durably
38
+ * at 'submitting'. Deferred-path requests carry their signed CBOR on the row
39
+ * and are re-driven at the next boot (redriveInterruptedSubmissions); sync-path
40
+ * requests are left for the operator/poller exactly as before.
41
+ */
42
+ async function submitAndFinalize(SigningRequests, params, afterFinalize) {
43
+ // Persist the submission + 'submitted' status in its own committed transaction.
44
+ const finalizeSubmitted = () => (0, tx_utils_1.detachedTx)('finalize transaction submission', async (db) => {
45
+ const submission = await server().getCardanoIndexer().indexVerifiedTransactionSubmission(db, params);
46
+ if (afterFinalize)
47
+ await afterFinalize(db);
48
+ // Invalidate stale UTxO cache (spent inputs + output addresses) — best-effort,
49
+ // must never roll back the durable submission record.
50
+ try {
51
+ await server().getCardanoIndexer().invalidateUtxoCacheForTx(db, (0, tx_build_helper_1.extractTxCacheTargets)(params.fullSignedTxCbor));
52
+ }
53
+ catch (invalidateErr) {
54
+ logger.warn(`UTxO cache invalidation failed (submit unaffected): ${invalidateErr instanceof Error ? invalidateErr.message : String(invalidateErr)}`);
55
+ }
56
+ return submission;
57
+ });
58
+ try {
59
+ await server().getCardanoClient().submitTransaction(params.fullSignedTxCbor);
60
+ }
61
+ catch (submitErr) {
62
+ // Already-submitted means the tx reached the mempool — e.g. the first backend accepted
63
+ // it but its response was lost and a fallback observed the duplicate. That is SUCCESS,
64
+ // not failure: finalize it as 'submitted' (same as the happy path) instead of durably
65
+ // recording a spurious 'failed' for a tx the node already holds.
66
+ if (submitErr instanceof errors_1.TransactionAlreadySubmittedError) {
67
+ logger.info({ signingRequestId: params.signingRequestId, txHash: params.txHash }, 'Submit reported already-submitted — finalizing as submitted (tx already in mempool)');
68
+ return finalizeSubmitted();
69
+ }
70
+ try {
71
+ await (0, tx_utils_1.detachedTx)('mark signing request failed', (db) => db.run(UPDATE.entity(SigningRequests).set({ status: 'failed' }).where({ id: params.signingRequestId })));
72
+ }
73
+ catch (markErr) {
74
+ logger.error({ err: markErr, signingRequestId: params.signingRequestId }, 'Could not durably mark signing request failed after submit error');
75
+ }
76
+ throw submitErr;
77
+ }
78
+ return finalizeSubmitted();
79
+ }
80
+ /**
81
+ * Deferred-submit scheduler (KNOWN_ISSUES #11, Layer 2).
82
+ *
83
+ * Called by an action handler AFTER verify + claim ran on the CALLER's
84
+ * transaction. Hooks the request's post-commit event: only once the caller's
85
+ * root transaction has committed (claim durable, pooled connection released)
86
+ * does the network submit + finalize run — detached via setImmediate +
87
+ * runWithoutAmbientTx, so no ambient transaction is held across it.
88
+ *
89
+ * If the caller's transaction rolls back instead, 'succeeded' never fires and
90
+ * nothing was claimed — strictly consistent.
91
+ */
92
+ function scheduleDeferredSubmit(req, SigningRequests, params) {
93
+ req.on('succeeded', () => {
94
+ setImmediate(() => {
95
+ (0, tx_utils_1.runWithoutAmbientTx)(() => submitAndFinalize(SigningRequests, params))
96
+ .then(() => {
97
+ logger.info({ signingRequestId: params.signingRequestId, txHash: params.txHash }, 'Deferred submit finalized');
98
+ })
99
+ .catch((err) => {
100
+ // submitAndFinalize already durably marked the request 'failed'.
101
+ logger.error({ err, signingRequestId: params.signingRequestId }, 'Deferred submit failed (signing request marked failed)');
102
+ });
103
+ });
104
+ });
105
+ }
106
+ /**
107
+ * Boot-time recovery: re-drive submissions that were claimed on the deferred
108
+ * path (status 'submitting' WITH persisted signedTxCbor) but never finalized —
109
+ * i.e. the process died between the caller's commit and the detached submit.
110
+ *
111
+ * Safe to repeat: a tx the node already holds finalizes as 'submitted' via the
112
+ * TransactionAlreadySubmittedError path in submitAndFinalize. Rows at
113
+ * 'submitting' WITHOUT signed CBOR (sync-path crash window) are deliberately
114
+ * left untouched for the operator/poller, exactly as before Layer 2.
115
+ *
116
+ * @returns number of rows re-driven (attempted, not necessarily succeeded)
117
+ */
118
+ async function redriveInterruptedSubmissions() {
119
+ const SigningRequests = 'odatano.cardano.SigningRequests';
120
+ const rows = await (0, tx_utils_1.detachedTx)('load interrupted deferred submissions', (db) => db.run(SELECT.from(SigningRequests)
121
+ .where({ status: 'submitting' })
122
+ .and('signedTxCbor is not null')));
123
+ if (!rows.length)
124
+ return 0;
125
+ logger.info(`Re-driving ${rows.length} interrupted deferred submission(s)`);
126
+ let attempted = 0;
127
+ for (const row of rows) {
128
+ try {
129
+ // Re-verify from the persisted CBOR (deterministic — it passed at claim
130
+ // time; this recomputes the witness metadata the finalize step persists).
131
+ const verificationResult = (0, external_signer_1.getExternalSignerModule)().verifyOrThrow(row.signedTxCbor, row.txBodyHash);
132
+ attempted++;
133
+ await submitAndFinalize(SigningRequests, {
134
+ signingRequestId: row.id,
135
+ buildId: row.build_id ?? '',
136
+ fullSignedTxCbor: row.signedTxCbor,
137
+ txHash: row.txBodyHash,
138
+ verificationResult,
139
+ signerType: row.signerType ?? undefined,
140
+ signerInfo: row.signerInfo ?? undefined,
141
+ });
142
+ logger.info({ signingRequestId: row.id, txHash: row.txBodyHash }, 'Interrupted submission re-driven');
143
+ }
144
+ catch (err) {
145
+ // submitAndFinalize marked the row 'failed' on submit errors; verification
146
+ // errors leave it at 'submitting' for manual inspection (should not happen
147
+ // for CBOR that verified once).
148
+ logger.error({ err, signingRequestId: row.id }, 'Re-drive of interrupted submission failed');
149
+ }
150
+ }
151
+ return attempted;
152
+ }
153
+ //# sourceMappingURL=submission-finalizer.js.map
@@ -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
- * Not implemented via TxBuilder.overrideTxRedeemers: that method computes the script
109
- * data hash from the OLD witness set (library bug), which would yield a phase-1
110
- * rejection (PPViewHashesDontMatch). We rebuild the witness set first and hash it with
111
- * the same exported getScriptDataHash the build itself uses.
112
- *
113
- * The hash is recomputed even when the target units already match: Buildooor's
114
- * internal hash comes from the named-key cost models, which clamp the chain array
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
  /**