@odatano/core 1.8.0 → 1.9.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/@cds-models/CardanoODataService/index.d.ts +66 -42
- package/@cds-models/CardanoODataService/index.d.ts.map +1 -1
- package/@cds-models/CardanoODataService/index.js.map +1 -1
- package/@cds-models/CardanoODataService/index.ts +11 -7
- package/@cds-models/odatano/cardano/index.d.ts +70 -46
- package/@cds-models/odatano/cardano/index.d.ts.map +1 -1
- package/@cds-models/odatano/cardano/index.js +2 -2
- package/@cds-models/odatano/cardano/index.js.map +1 -1
- package/@cds-models/odatano/cardano/index.ts +13 -13
- package/db/schema.cds +18 -18
- package/db/types.cds +3 -3
- package/package.json +17 -2
- package/src/index.d.ts +29 -0
- package/src/index.js +1 -0
- package/src/plugin.d.ts +2 -0
- package/src/plugin.js +6 -0
- package/srv/blockchain/backends/blockfrost-backend.d.ts +155 -0
- package/srv/blockchain/backends/blockfrost-backend.js +19 -8
- package/srv/blockchain/backends/cardano-backend.d.ts +182 -0
- package/srv/blockchain/backends/koios-backend.d.ts +171 -0
- package/srv/blockchain/backends/koios-backend.js +69 -27
- package/srv/blockchain/backends/ogmios-backend.d.ts +188 -0
- package/srv/blockchain/backends/ogmios-backend.js +175 -108
- package/srv/blockchain/cardano-client.d.ts +279 -0
- package/srv/blockchain/cardano-client.js +134 -33
- package/srv/blockchain/cardano-indexer.d.ts +330 -0
- package/srv/blockchain/cardano-indexer.js +51 -8
- package/srv/blockchain/cardano-tx-builder.d.ts +113 -0
- package/srv/blockchain/cardano-tx-builder.js +61 -54
- package/srv/blockchain/circuit-breaker.d.ts +37 -0
- package/srv/blockchain/circuit-breaker.js +11 -2
- package/srv/blockchain/request-coalescer.d.ts +23 -0
- package/srv/blockchain/signing/external-signer.d.ts +146 -0
- package/srv/blockchain/signing/external-signer.js +23 -0
- package/srv/blockchain/signing/hsm-signer.d.ts +74 -0
- package/srv/blockchain/signing/hsm-signer.js +20 -5
- package/srv/blockchain/signing/signature-verifier.d.ts +56 -0
- package/srv/blockchain/signing/signature-verifier.js +11 -2
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +236 -0
- package/srv/blockchain/transaction-building/buildooor-tx.js +626 -187
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +47 -0
- package/srv/cardano-service.cds +23 -3
- package/srv/cardano-service.d.ts +2 -0
- package/srv/cardano-service.js +25 -5
- package/srv/cardano-sign-service.d.ts +2 -0
- package/srv/cardano-sign-service.js +219 -131
- package/srv/cardano-tx-service.d.ts +12 -0
- package/srv/cardano-tx-service.js +152 -110
- package/srv/cbor/index.d.ts +2 -0
- package/srv/cbor/parse.d.ts +64 -0
- package/srv/server.d.ts +90 -0
- package/srv/server.js +27 -9
- package/srv/utils/backend-request-handler.d.ts +20 -0
- package/srv/utils/const.d.ts +183 -0
- package/srv/utils/const.js +13 -6
- package/srv/utils/error-codes.d.ts +79 -0
- package/srv/utils/errors.d.ts +259 -0
- package/srv/utils/errors.js +22 -7
- package/srv/utils/mappers.d.ts +260 -0
- package/srv/utils/mappers.js +34 -10
- package/srv/utils/plutus-placeholders.d.ts +35 -0
- package/srv/utils/plutus-placeholders.js +5 -15
- package/srv/utils/signing-helper.d.ts +23 -0
- package/srv/utils/signing-helper.js +5 -2
- package/srv/utils/tx-build-helper.d.ts +76 -0
- package/srv/utils/tx-build-helper.js +10 -37
- package/srv/utils/types.d.ts +653 -0
- package/srv/utils/validators.d.ts +145 -0
- package/srv/utils/validators.js +28 -1
- package/@cds-models/CardanoWatcherAdminService/index.js +0 -109
- package/@cds-models/CardanoWatcherAdminService/index.js.map +0 -1
- package/@cds-models/CardanoWatcherAdminService/index.ts +0 -263
- package/@cds-models/cds/outbox/index.js.map +0 -1
- package/@cds-models/cds/xt/MTXServices/index.js +0 -8
- package/@cds-models/cds/xt/MTXServices/index.js.map +0 -1
- package/@cds-models/cds/xt/MTXServices/index.ts +0 -4
- package/@cds-models/odatano/reeve/index.js +0 -77
- package/@cds-models/odatano/reeve/index.js.map +0 -1
- package/@cds-models/odatano/reeve/index.ts +0 -57
- package/@cds-models/odatano/transactions/index.js +0 -55
- package/@cds-models/odatano/transactions/index.js.map +0 -1
- package/@cds-models/odatano/transactions/index.ts +0 -18
- package/@cds-models/odatano/watch/index.js +0 -114
- package/@cds-models/odatano/watch/index.js.map +0 -1
- package/@cds-models/odatano/watch/index.ts +0 -110
- package/config/preview/cardano-node/alonzo-genesis.json +0 -196
- package/config/preview/cardano-node/byron-genesis.json +0 -117
- package/config/preview/cardano-node/config.json +0 -117
- package/config/preview/cardano-node/conway-genesis.json +0 -297
- package/config/preview/cardano-node/peer-snapshot.json +0 -890
- package/config/preview/cardano-node/shelley-genesis.json +0 -68
- package/config/preview/cardano-node/topology.json +0 -24
- package/output/sora/iter0_base.json +0 -32
- package/output/sora/iter0_base.mp4 +0 -0
- package/output/sora/logo_ref_1280x720.png +0 -0
- package/output/sora/odatano_full_logo_sky_ref_1280x720.png +0 -0
- package/output/sora/odatano_full_logo_transparent.png +0 -0
- package/output/sora/odatano_full_logo_transparent_dark.png +0 -0
- package/output/sora/odatano_full_logo_v4_8s.json +0 -32
- package/output/sora/odatano_full_logo_v4_8s.mp4 +0 -0
- package/output/sora/odatano_full_logo_v5_create.json +0 -15
- package/output/sora/odatano_full_logo_v5_fixes.json +0 -15
- package/output/sora/odatano_full_logo_v5_fixes.mp4 +0 -0
- package/output/sora/odatano_logo_v1.json +0 -32
- package/output/sora/odatano_logo_v1.mp4 +0 -0
- package/output/sora/odatano_o_only_clean.png +0 -0
- package/output/sora/odatano_o_sky_ref_1280x720.png +0 -0
- package/output/sora/odatano_o_sky_v2_8s.json +0 -32
- package/output/sora/odatano_o_sky_v2_8s.mp4 +0 -0
- package/output/sora/odatano_o_sky_v3_create.json +0 -15
- package/output/sora/odatano_o_sky_v3_splash_text.json +0 -15
- package/output/sora/odatano_o_sky_v3_splash_text.mp4 +0 -0
- package/output/sora/odatano_v6_composite_exact_logo.mp4 +0 -0
- package/output/sora/odatano_v6_composite_exact_logo_clean.mp4 +0 -0
- package/output/sora/odatano_v6_composite_exact_logo_final.mp4 +0 -0
- package/output/sora/odatano_v6_endframe.jpg +0 -0
- package/output/sora/odatano_v6_endframe_clean.jpg +0 -0
- package/output/sora/odatano_v6_endframe_final.jpg +0 -0
- package/output/sora/odatano_v7_1_earlylogo_fadeoldtext.mp4 +0 -0
- package/output/sora/odatano_v7_1_end.jpg +0 -0
- package/output/sora/odatano_v7_1_transition.jpg +0 -0
- package/output/sora/odatano_v7_2_original2d_keep_sky.mp4 +0 -0
- package/output/sora/odatano_v7_endframe_nobg.jpg +0 -0
- package/output/sora/odatano_v7_endframe_nobg_cleanend.jpg +0 -0
- package/output/sora/odatano_v7_spin_splash_logo_nobg.mp4 +0 -0
- package/output/sora/odatano_v7_spin_splash_logo_nobg_cleanend.mp4 +0 -0
- package/prod.mtaext +0 -17
- package/prod.mtaext.example +0 -27
- package/review.md +0 -42
- package/src/index.d.ts.map +0 -1
- package/src/index.js.map +0 -1
- package/src/plugin.d.ts.map +0 -1
- package/src/plugin.js.map +0 -1
- package/srv/blockchain/backends/blockfrost-backend.d.ts.map +0 -1
- package/srv/blockchain/backends/blockfrost-backend.js.map +0 -1
- package/srv/blockchain/backends/cardano-backend.d.ts.map +0 -1
- package/srv/blockchain/backends/cardano-backend.js.map +0 -1
- package/srv/blockchain/backends/koios-backend.d.ts.map +0 -1
- package/srv/blockchain/backends/koios-backend.js.map +0 -1
- package/srv/blockchain/backends/ogmios-backend.d.ts.map +0 -1
- package/srv/blockchain/backends/ogmios-backend.js.map +0 -1
- package/srv/blockchain/cardano-client.d.ts.map +0 -1
- package/srv/blockchain/cardano-client.js.map +0 -1
- package/srv/blockchain/cardano-indexer.d.ts.map +0 -1
- package/srv/blockchain/cardano-indexer.js.map +0 -1
- package/srv/blockchain/cardano-tx-builder.d.ts.map +0 -1
- package/srv/blockchain/cardano-tx-builder.js.map +0 -1
- package/srv/blockchain/circuit-breaker.d.ts.map +0 -1
- package/srv/blockchain/circuit-breaker.js.map +0 -1
- package/srv/blockchain/request-coalescer.d.ts.map +0 -1
- package/srv/blockchain/request-coalescer.js.map +0 -1
- package/srv/blockchain/signing/external-signer.d.ts.map +0 -1
- package/srv/blockchain/signing/external-signer.js.map +0 -1
- package/srv/blockchain/signing/hsm-signer.d.ts.map +0 -1
- package/srv/blockchain/signing/hsm-signer.js.map +0 -1
- package/srv/blockchain/signing/signature-verifier.d.ts.map +0 -1
- package/srv/blockchain/signing/signature-verifier.js.map +0 -1
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts.map +0 -1
- package/srv/blockchain/transaction-building/buildooor-tx.js.map +0 -1
- package/srv/blockchain/transaction-building/cardano-tx.d.ts.map +0 -1
- package/srv/blockchain/transaction-building/cardano-tx.js.map +0 -1
- package/srv/cardano-service.d.ts.map +0 -1
- package/srv/cardano-service.js.map +0 -1
- package/srv/cardano-sign-service.d.ts.map +0 -1
- package/srv/cardano-sign-service.js.map +0 -1
- package/srv/cardano-tx-service.d.ts.map +0 -1
- package/srv/cardano-tx-service.js.map +0 -1
- package/srv/cbor/index.d.ts.map +0 -1
- package/srv/cbor/index.js.map +0 -1
- package/srv/cbor/parse.d.ts.map +0 -1
- package/srv/cbor/parse.js.map +0 -1
- package/srv/server.d.ts.map +0 -1
- package/srv/server.js.map +0 -1
- package/srv/utils/backend-request-handler.d.ts.map +0 -1
- package/srv/utils/backend-request-handler.js.map +0 -1
- package/srv/utils/const.d.ts.map +0 -1
- package/srv/utils/const.js.map +0 -1
- package/srv/utils/error-codes.d.ts.map +0 -1
- package/srv/utils/error-codes.js.map +0 -1
- package/srv/utils/errors.d.ts.map +0 -1
- package/srv/utils/errors.js.map +0 -1
- package/srv/utils/mappers.d.ts.map +0 -1
- package/srv/utils/mappers.js.map +0 -1
- package/srv/utils/plutus-placeholders.d.ts.map +0 -1
- package/srv/utils/plutus-placeholders.js.map +0 -1
- package/srv/utils/signing-helper.d.ts.map +0 -1
- package/srv/utils/signing-helper.js.map +0 -1
- package/srv/utils/tx-build-helper.d.ts.map +0 -1
- package/srv/utils/tx-build-helper.js.map +0 -1
- package/srv/utils/types.d.ts.map +0 -1
- package/srv/utils/types.js.map +0 -1
- package/srv/utils/validators.d.ts.map +0 -1
- package/srv/utils/validators.js.map +0 -1
|
@@ -6,7 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
7
7
|
const backend_request_handler_1 = require("./utils/backend-request-handler");
|
|
8
8
|
const errors_1 = require("./utils/errors");
|
|
9
|
+
const mappers_1 = require("./utils/mappers");
|
|
9
10
|
const validators_1 = require("./utils/validators");
|
|
11
|
+
const cbor_1 = require("./cbor");
|
|
10
12
|
const server_1 = require("./server");
|
|
11
13
|
const external_signer_1 = require("./blockchain/signing/external-signer");
|
|
12
14
|
const hsm_signer_1 = require("./blockchain/signing/hsm-signer");
|
|
@@ -21,6 +23,7 @@ async function verifyBuildOwnership(req, db, buildId, address, TransactionBuilds
|
|
|
21
23
|
const build = await db.run(SELECT.one.from(TransactionBuilds).where({ id: buildId }));
|
|
22
24
|
if (!build)
|
|
23
25
|
(0, errors_1.rejectInvalid)(req, actionName, 'Build not found', 'buildId');
|
|
26
|
+
// rejectInvalid returns `never` → build is narrowed to non-null here
|
|
24
27
|
if (address && build.senderAddress !== address) {
|
|
25
28
|
(0, errors_1.rejectInvalid)(req, actionName, 'Address does not match build owner', 'address');
|
|
26
29
|
}
|
|
@@ -34,13 +37,98 @@ async function checkAndExpireSigningRequest(db, signingRequest, SigningRequests)
|
|
|
34
37
|
const now = new Date().toISOString();
|
|
35
38
|
const result = await db.run(UPDATE.entity(SigningRequests)
|
|
36
39
|
.set({ status: 'expired' })
|
|
37
|
-
|
|
40
|
+
// status filter: only PENDING requests may expire — without it an old
|
|
41
|
+
// 'submitted'/'verified' record would be flipped to 'expired' here
|
|
42
|
+
.where({ id: signingRequest.id, status: 'pending', expiresAt: { '<=': now } }));
|
|
38
43
|
if (result > 0) {
|
|
39
44
|
signingRequest.status = 'expired';
|
|
40
45
|
return true;
|
|
41
46
|
}
|
|
47
|
+
// NOTE: when the surrounding request is subsequently rejected, CAP rolls the
|
|
48
|
+
// managed transaction back — including this update. The expiry status is
|
|
49
|
+
// then re-applied on the next touch; reads always re-check expiresAt.
|
|
42
50
|
return false;
|
|
43
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Resolve the key hashes that MUST witness a signing request:
|
|
54
|
+
* - the `required_signers` declared in the unsigned tx body (extra_signatories)
|
|
55
|
+
* - the payment KEY hash of the associated build's senderAddress (the fee
|
|
56
|
+
* payer's inputs require its witness on-chain anyway; script credentials
|
|
57
|
+
* are skipped — scripts witness via redeemers, not vkeys)
|
|
58
|
+
*
|
|
59
|
+
* Previously NONE of this was checked: any valid signature from ANY key
|
|
60
|
+
* flipped the request to 'verified' / let SubmitVerifiedTransaction proceed.
|
|
61
|
+
* Returns undefined when nothing is derivable (no over-restriction).
|
|
62
|
+
*/
|
|
63
|
+
async function resolveRequiredSigners(db, signingRequest, TransactionBuilds) {
|
|
64
|
+
const signers = new Set();
|
|
65
|
+
try {
|
|
66
|
+
const parsed = (0, cbor_1.parseTransaction)(signingRequest.unsignedTxCbor);
|
|
67
|
+
for (const s of parsed.requiredSigners ?? [])
|
|
68
|
+
signers.add(s.toLowerCase());
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
// body-hash verification still protects integrity; just log
|
|
72
|
+
logger.warn(`Could not parse unsigned tx for required_signers: ${err instanceof Error ? err.message : String(err)}`);
|
|
73
|
+
}
|
|
74
|
+
if (signingRequest.build_id) {
|
|
75
|
+
const build = await db.run(SELECT.one.from(TransactionBuilds).where({ id: signingRequest.build_id }));
|
|
76
|
+
if (build?.senderAddress) {
|
|
77
|
+
const cred = (0, validators_1.extractPaymentCredential)(build.senderAddress);
|
|
78
|
+
if (cred && !cred.isScript)
|
|
79
|
+
signers.add(cred.hash.toLowerCase());
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return signers.size > 0 ? [...signers] : undefined;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Submit a verified+claimed signing request to the blockchain and persist the
|
|
86
|
+
* outcome — DELIBERATELY outside the caller's request transaction.
|
|
87
|
+
*
|
|
88
|
+
* The caller must already have durably committed `status:'submitting'` (the
|
|
89
|
+
* claim). This function then:
|
|
90
|
+
* 1. submits with NO DB write-lock held (the lock was the reason concurrent
|
|
91
|
+
* submits serialized and the SQLite busy-timeout could fire mid-network),
|
|
92
|
+
* 2. on submit failure: marks the request 'failed' in its own committed tx
|
|
93
|
+
* and rethrows (NOT rolled back to a pre-submit status — losing the
|
|
94
|
+
* attempt would hide a tx the node may have accepted),
|
|
95
|
+
* 3. on success: persists the submission + 'submitted' status in a committed
|
|
96
|
+
* transaction.
|
|
97
|
+
*
|
|
98
|
+
* Crash window: a process death between (1) and (3) leaves the request durably
|
|
99
|
+
* at 'submitting' — the operator/poller checks the chain — instead of silently
|
|
100
|
+
* reverting to 'pending'/'verified' with no on-chain trace.
|
|
101
|
+
*/
|
|
102
|
+
async function submitAndFinalize(SigningRequests, params, afterFinalize) {
|
|
103
|
+
// Persist the submission + 'submitted' status in its own committed transaction.
|
|
104
|
+
const finalizeSubmitted = () => cds_1.default.tx(async (db) => {
|
|
105
|
+
const submission = await (0, server_1.getCardanoIndexer)().indexVerifiedTransactionSubmission(db, params);
|
|
106
|
+
if (afterFinalize)
|
|
107
|
+
await afterFinalize(db);
|
|
108
|
+
return submission;
|
|
109
|
+
});
|
|
110
|
+
try {
|
|
111
|
+
await (0, server_1.getCardanoClient)().submitTransaction(params.fullSignedTxCbor);
|
|
112
|
+
}
|
|
113
|
+
catch (submitErr) {
|
|
114
|
+
// Already-submitted means the tx reached the mempool — e.g. the first backend accepted
|
|
115
|
+
// it but its response was lost and a fallback observed the duplicate. That is SUCCESS,
|
|
116
|
+
// not failure: finalize it as 'submitted' (same as the happy path) instead of durably
|
|
117
|
+
// recording a spurious 'failed' for a tx the node already holds.
|
|
118
|
+
if (submitErr instanceof errors_1.TransactionAlreadySubmittedError) {
|
|
119
|
+
logger.info({ signingRequestId: params.signingRequestId, txHash: params.txHash }, 'Submit reported already-submitted — finalizing as submitted (tx already in mempool)');
|
|
120
|
+
return finalizeSubmitted();
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
await cds_1.default.tx((db) => db.run(UPDATE.entity(SigningRequests).set({ status: 'failed' }).where({ id: params.signingRequestId })));
|
|
124
|
+
}
|
|
125
|
+
catch (markErr) {
|
|
126
|
+
logger.error({ err: markErr, signingRequestId: params.signingRequestId }, 'Could not durably mark signing request failed after submit error');
|
|
127
|
+
}
|
|
128
|
+
throw submitErr;
|
|
129
|
+
}
|
|
130
|
+
return finalizeSubmitted();
|
|
131
|
+
}
|
|
44
132
|
/**
|
|
45
133
|
* Enforce HSM role check if hsm.requiresRole is configured.
|
|
46
134
|
* Rejects with 403 if the user lacks the required role.
|
|
@@ -153,13 +241,24 @@ module.exports = (srv) => {
|
|
|
153
241
|
if (address && signingRequest.build_id) {
|
|
154
242
|
await verifyBuildOwnership(req, db, signingRequest.build_id, address, TransactionBuilds, 'VerifySignature');
|
|
155
243
|
}
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
|
|
244
|
+
// Atomically CLAIM the pending request (pending → 'signed' = verification
|
|
245
|
+
// in progress). Replaces the read-then-check pattern that let two
|
|
246
|
+
// concurrent verifies both pass `status === 'pending'` and double-insert
|
|
247
|
+
// verification records (last-writer-wins on status). The final status is
|
|
248
|
+
// overwritten to 'verified'/'failed' by persistSignatureVerification.
|
|
249
|
+
const now = new Date().toISOString();
|
|
250
|
+
const claimed = await db.run(UPDATE.entity(SigningRequests)
|
|
251
|
+
.set({ status: 'signed' })
|
|
252
|
+
.where({ id: signingRequestId, status: 'pending', expiresAt: { '>': now } }));
|
|
253
|
+
if (claimed === 0) {
|
|
254
|
+
// re-read the committed state for an accurate message (a concurrent
|
|
255
|
+
// verify may have moved it since our SELECT above)
|
|
256
|
+
const current = await db.run(SELECT.one.from(SigningRequests).where({ id: signingRequestId }));
|
|
257
|
+
if (current && current.status === 'pending' && current.expiresAt <= now) {
|
|
258
|
+
await db.run(UPDATE.entity(SigningRequests).set({ status: 'expired' }).where({ id: signingRequestId, status: 'pending' }));
|
|
259
|
+
(0, errors_1.rejectInvalid)(req, 'VerifySignature', 'Signing request has expired', 'signingRequestId');
|
|
260
|
+
}
|
|
261
|
+
(0, errors_1.rejectInvalid)(req, 'VerifySignature', `Signing request status is '${current?.status ?? 'unknown'}', expected 'pending'`, 'signingRequestId');
|
|
163
262
|
}
|
|
164
263
|
// Detect if signedTxCbor is a witness set (CIP-30) or a full signed transaction (cardano-cli)
|
|
165
264
|
let fullSignedTxCbor;
|
|
@@ -172,9 +271,11 @@ module.exports = (srv) => {
|
|
|
172
271
|
// Full signed transaction provided (e.g., from cardano-cli)
|
|
173
272
|
fullSignedTxCbor = signedTxCbor;
|
|
174
273
|
}
|
|
175
|
-
// Verify the signature
|
|
274
|
+
// Verify the signature — bound to the keys that must actually witness
|
|
275
|
+
// this transaction (declared required_signers + the build's fee payer)
|
|
276
|
+
const requiredSigners = await resolveRequiredSigners(db, signingRequest, TransactionBuilds);
|
|
176
277
|
const signerModule = (0, external_signer_1.getExternalSignerModule)();
|
|
177
|
-
const result = signerModule.verifySignedTransaction(fullSignedTxCbor, signingRequest.txBodyHash);
|
|
278
|
+
const result = signerModule.verifySignedTransaction(fullSignedTxCbor, signingRequest.txBodyHash, { requiredSigners });
|
|
178
279
|
// Delegate persistence to indexer (store full signed tx for later submission)
|
|
179
280
|
const verificationRecord = await (0, server_1.getCardanoIndexer)().persistSignatureVerification(db, {
|
|
180
281
|
signingRequestId,
|
|
@@ -204,79 +305,69 @@ module.exports = (srv) => {
|
|
|
204
305
|
(0, errors_1.throwIfValidationErrors)(req, 'SubmitVerifiedTransaction', errors);
|
|
205
306
|
if (address && !(0, validators_1.isValidBech32Address)(address))
|
|
206
307
|
(0, errors_1.rejectInvalid)(req, 'SubmitVerifiedTransaction', 'Invalid bech32 address format', 'address');
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if (
|
|
224
|
-
|
|
225
|
-
|
|
308
|
+
// Three committed phases instead of one request-long transaction (see
|
|
309
|
+
// submitAndFinalize): the network submit must NOT run inside an open DB
|
|
310
|
+
// transaction. Errors are mapped the same way handleRequest would.
|
|
311
|
+
try {
|
|
312
|
+
// PHASE 1 (committed): atomically claim → 'submitting' and fully verify.
|
|
313
|
+
// A reject/verification failure here rolls the claim back, so a bad
|
|
314
|
+
// signature never strands the request in 'submitting'.
|
|
315
|
+
const prep = await cds_1.default.tx(async (db) => {
|
|
316
|
+
const now = new Date().toISOString();
|
|
317
|
+
const claimed = await db.run(UPDATE.entity(SigningRequests)
|
|
318
|
+
.set({ status: 'submitting' })
|
|
319
|
+
.where({
|
|
320
|
+
id: signingRequestId,
|
|
321
|
+
status: { in: ['pending', 'verified'] },
|
|
322
|
+
expiresAt: { '>': now },
|
|
323
|
+
}));
|
|
324
|
+
if (claimed === 0) {
|
|
325
|
+
// Claim failed — fetch to provide a specific error message
|
|
326
|
+
const existing = await db.run(SELECT.one.from(SigningRequests).where({ id: signingRequestId }));
|
|
327
|
+
if (!existing)
|
|
328
|
+
(0, errors_1.rejectInvalid)(req, 'SubmitVerifiedTransaction', 'Signing request not found', 'signingRequestId');
|
|
329
|
+
if (existing.expiresAt <= now)
|
|
330
|
+
(0, errors_1.rejectInvalid)(req, 'SubmitVerifiedTransaction', 'Signing request has expired', 'signingRequestId');
|
|
331
|
+
(0, errors_1.rejectInvalid)(req, 'SubmitVerifiedTransaction', `Signing request status is '${existing.status}', expected 'pending' or 'verified'`, 'signingRequestId');
|
|
226
332
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
//
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
// Verify signature (throws on failure)
|
|
252
|
-
const signerModule = (0, external_signer_1.getExternalSignerModule)();
|
|
253
|
-
const verificationResult = signerModule.verifyOrThrow(fullSignedTxCbor, signingRequest.txBodyHash);
|
|
254
|
-
logger.info({
|
|
255
|
-
signingRequestId,
|
|
256
|
-
witnessCount: verificationResult.witnessCount,
|
|
257
|
-
signers: verificationResult.signerKeyHashes,
|
|
258
|
-
}, 'Signature verified, proceeding with submission');
|
|
259
|
-
// Submit to blockchain
|
|
260
|
-
const txHash = signingRequest.txBodyHash;
|
|
261
|
-
await (0, server_1.getCardanoClient)().submitTransaction(fullSignedTxCbor);
|
|
262
|
-
logger.info({ txHash }, 'Verified transaction submitted to blockchain');
|
|
263
|
-
// Delegate all persistence to indexer
|
|
264
|
-
const submissionRecord = await (0, server_1.getCardanoIndexer)().indexVerifiedTransactionSubmission(db, {
|
|
333
|
+
// Re-fetch the full record (now with status='submitting')
|
|
334
|
+
const signingRequest = await db.run(SELECT.one.from(SigningRequests).where({ id: signingRequestId }));
|
|
335
|
+
// Ownership check: verify address matches build owner (defense-in-depth)
|
|
336
|
+
if (address && signingRequest.build_id) {
|
|
337
|
+
await verifyBuildOwnership(req, db, signingRequest.build_id, address, TransactionBuilds, 'SubmitVerifiedTransaction');
|
|
338
|
+
}
|
|
339
|
+
// Check if build association exists
|
|
340
|
+
if (!signingRequest.build_id) {
|
|
341
|
+
(0, errors_1.rejectInvalid)(req, 'SubmitVerifiedTransaction', 'Signing request has no associated build', 'signingRequestId');
|
|
342
|
+
}
|
|
343
|
+
// Detect if signedTxCbor is a witness set (CIP-30) or a full signed transaction (cardano-cli)
|
|
344
|
+
const fullSignedTxCbor = (0, signing_helper_1.isWitnessSetCbor)(signedTxCbor)
|
|
345
|
+
? (0, signing_helper_1.combineTransactionWithWitnesses)(signingRequest.unsignedTxCbor, signedTxCbor)
|
|
346
|
+
: signedTxCbor;
|
|
347
|
+
// Verify signature (throws on failure) — bound to the keys that must
|
|
348
|
+
// actually witness this transaction (required_signers + fee payer)
|
|
349
|
+
const requiredSigners = await resolveRequiredSigners(db, signingRequest, TransactionBuilds);
|
|
350
|
+
const verificationResult = (0, external_signer_1.getExternalSignerModule)().verifyOrThrow(fullSignedTxCbor, signingRequest.txBodyHash, { requiredSigners });
|
|
351
|
+
return { buildId: signingRequest.build_id, txHash: signingRequest.txBodyHash, fullSignedTxCbor, verificationResult };
|
|
352
|
+
});
|
|
353
|
+
logger.info({ signingRequestId, witnessCount: prep.verificationResult.witnessCount }, 'Signature verified, proceeding with submission');
|
|
354
|
+
// PHASES 2+3: submit outside any DB tx, then finalize in its own tx
|
|
355
|
+
const submissionRecord = await submitAndFinalize(SigningRequests, {
|
|
265
356
|
signingRequestId,
|
|
266
|
-
buildId:
|
|
267
|
-
fullSignedTxCbor,
|
|
268
|
-
txHash,
|
|
269
|
-
verificationResult,
|
|
357
|
+
buildId: prep.buildId,
|
|
358
|
+
fullSignedTxCbor: prep.fullSignedTxCbor,
|
|
359
|
+
txHash: prep.txHash,
|
|
360
|
+
verificationResult: prep.verificationResult,
|
|
270
361
|
signerType,
|
|
271
362
|
signerInfo,
|
|
272
363
|
});
|
|
273
|
-
logger.info({
|
|
274
|
-
signingRequestId,
|
|
275
|
-
submissionId: submissionRecord.id,
|
|
276
|
-
txHash,
|
|
277
|
-
}, 'Transaction submitted and all records updated');
|
|
364
|
+
logger.info({ signingRequestId, txHash: prep.txHash }, 'Transaction submitted and all records updated');
|
|
278
365
|
return submissionRecord;
|
|
279
|
-
}
|
|
366
|
+
}
|
|
367
|
+
catch (e) {
|
|
368
|
+
logger.error({ err: e }, 'SubmitVerifiedTransaction error');
|
|
369
|
+
return (0, mappers_1.mapError)(req, e, 'SubmitVerifiedTransaction');
|
|
370
|
+
}
|
|
280
371
|
});
|
|
281
372
|
/**
|
|
282
373
|
* Get all existing signing requests by address
|
|
@@ -340,6 +431,13 @@ module.exports = (srv) => {
|
|
|
340
431
|
const verificationResult = signerModule.verifySignedTransaction(signedTxCbor, build.txBodyHash);
|
|
341
432
|
const hsmStatus = hsmSigner.getStatus();
|
|
342
433
|
const hsmKeyIdentifier = hsmStatus.keyLabel || hsmStatus.keyId || 'unknown';
|
|
434
|
+
// A failed HSM verification is an HSM/server fault, not a successful sign —
|
|
435
|
+
// reject (rolls back) instead of returning 200 with status 'failed', matching
|
|
436
|
+
// SignAndSubmitWithHsm.
|
|
437
|
+
if (!verificationResult.isValid) {
|
|
438
|
+
logger.error({ signingRequestId: signingRequestRecord.id, hsmKey: hsmKeyIdentifier }, 'HSM signature verification failed');
|
|
439
|
+
(0, errors_1.rejectInvalid)(req, 'SignWithHsm', 'HSM signature verification failed', 'signedTxCbor');
|
|
440
|
+
}
|
|
343
441
|
// 5. Persist verification
|
|
344
442
|
await (0, server_1.getCardanoIndexer)().persistSignatureVerification(db, {
|
|
345
443
|
signingRequestId: signingRequestRecord.id,
|
|
@@ -382,64 +480,54 @@ module.exports = (srv) => {
|
|
|
382
480
|
if (!hsmSigner || !hsmSigner.isConnected()) {
|
|
383
481
|
(0, errors_1.rejectInvalid)(req, 'SignAndSubmitWithHsm', 'HSM is not configured or not connected', 'hsm');
|
|
384
482
|
}
|
|
385
|
-
|
|
386
|
-
// 1
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
signingPayload,
|
|
483
|
+
try {
|
|
484
|
+
// PHASE 1 (committed): fetch build, sign with HSM, verify. A failure
|
|
485
|
+
// here rolls back the freshly-created signing request.
|
|
486
|
+
const prep = await cds_1.default.tx(async (db) => {
|
|
487
|
+
// 1. Fetch the build (with ownership check)
|
|
488
|
+
const build = await verifyBuildOwnership(req, db, buildId, address, TransactionBuilds, 'SignAndSubmitWithHsm');
|
|
489
|
+
// HSM can only sign builds for its own address
|
|
490
|
+
const hsmAddress = hsmSigner.getAddress();
|
|
491
|
+
if (build.senderAddress !== hsmAddress) {
|
|
492
|
+
(0, errors_1.rejectInvalid)(req, 'SignAndSubmitWithHsm', `Build sender '${build.senderAddress}' does not match HSM address '${hsmAddress}'`, 'buildId');
|
|
493
|
+
}
|
|
494
|
+
// 2. Create signing request
|
|
495
|
+
const signerModule = (0, external_signer_1.getExternalSignerModule)();
|
|
496
|
+
const signingPayload = signerModule.createSigningRequest(build.id, build.unsignedTxCbor, build.txBodyHash, build.network, 'HSM signing + submit');
|
|
497
|
+
const signingRequestRecord = await (0, server_1.getCardanoIndexer)().persistSigningRequest(db, { buildId, signingPayload });
|
|
498
|
+
// 3. Sign with HSM
|
|
499
|
+
const signedTxCbor = hsmSigner.signTransaction(build.unsignedTxCbor, build.txBodyHash);
|
|
500
|
+
// 4. Verify HSM signature — reject (rolls back) if invalid before submitting
|
|
501
|
+
const verificationResult = signerModule.verifySignedTransaction(signedTxCbor, build.txBodyHash);
|
|
502
|
+
const hsmStatus = hsmSigner.getStatus();
|
|
503
|
+
const hsmKeyIdentifier = hsmStatus.keyLabel || hsmStatus.keyId || 'unknown';
|
|
504
|
+
if (!verificationResult.isValid) {
|
|
505
|
+
logger.error({ signingRequestId: signingRequestRecord.id, hsmKey: hsmKeyIdentifier }, 'HSM signature verification failed — aborting submission');
|
|
506
|
+
(0, errors_1.rejectInvalid)(req, 'SignAndSubmitWithHsm', 'HSM signature verification failed', 'signedTxCbor');
|
|
507
|
+
}
|
|
508
|
+
// Claim the request as 'submitting' in this same committed phase
|
|
509
|
+
await db.run(UPDATE.entity(SigningRequests).set({ status: 'submitting', hsmKeyId: hsmKeyIdentifier }).where({ id: signingRequestRecord.id }));
|
|
510
|
+
return { signingRequestId: signingRequestRecord.id, signedTxCbor, txHash: build.txBodyHash, verificationResult, hsmKeyIdentifier };
|
|
399
511
|
});
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
//
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
const hsmKeyIdentifier = hsmStatus.keyLabel || hsmStatus.keyId || 'unknown';
|
|
406
|
-
if (!verificationResult.isValid) {
|
|
407
|
-
logger.error({
|
|
408
|
-
signingRequestId: signingRequestRecord.id,
|
|
409
|
-
hsmKey: hsmKeyIdentifier,
|
|
410
|
-
}, 'HSM signature verification failed — aborting submission');
|
|
411
|
-
(0, errors_1.rejectInvalid)(req, 'SignAndSubmitWithHsm', 'HSM signature verification failed', 'signedTxCbor');
|
|
412
|
-
}
|
|
413
|
-
logger.info({
|
|
414
|
-
signingRequestId: signingRequestRecord.id,
|
|
415
|
-
witnessCount: verificationResult.witnessCount,
|
|
416
|
-
hsmKey: hsmKeyIdentifier,
|
|
417
|
-
}, 'HSM signature verified, proceeding with submission');
|
|
418
|
-
// 5. Submit to blockchain
|
|
419
|
-
const txHash = build.txBodyHash;
|
|
420
|
-
await (0, server_1.getCardanoClient)().submitTransaction(signedTxCbor);
|
|
421
|
-
logger.info({ txHash }, 'HSM-signed transaction submitted to blockchain');
|
|
422
|
-
// 6. Persist everything atomically via indexer
|
|
423
|
-
const submissionRecord = await (0, server_1.getCardanoIndexer)().indexVerifiedTransactionSubmission(db, {
|
|
424
|
-
signingRequestId: signingRequestRecord.id,
|
|
512
|
+
logger.info({ signingRequestId: prep.signingRequestId, witnessCount: prep.verificationResult.witnessCount, hsmKey: prep.hsmKeyIdentifier }, 'HSM signature verified, proceeding with submission');
|
|
513
|
+
// PHASES 2+3: submit outside any DB tx, then finalize (re-set hsmKeyId,
|
|
514
|
+
// which indexVerifiedTransactionSubmission does not touch)
|
|
515
|
+
const submissionRecord = await submitAndFinalize(SigningRequests, {
|
|
516
|
+
signingRequestId: prep.signingRequestId,
|
|
425
517
|
buildId,
|
|
426
|
-
fullSignedTxCbor: signedTxCbor,
|
|
427
|
-
txHash,
|
|
428
|
-
verificationResult,
|
|
518
|
+
fullSignedTxCbor: prep.signedTxCbor,
|
|
519
|
+
txHash: prep.txHash,
|
|
520
|
+
verificationResult: prep.verificationResult,
|
|
429
521
|
signerType: 'hsm',
|
|
430
|
-
signerInfo: `HSM key: ${hsmKeyIdentifier}`,
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
await db.run(UPDATE.entity(SigningRequests)
|
|
434
|
-
.set({ hsmKeyId: hsmKeyIdentifier })
|
|
435
|
-
.where({ id: signingRequestRecord.id }));
|
|
436
|
-
logger.info({
|
|
437
|
-
signingRequestId: signingRequestRecord.id,
|
|
438
|
-
submissionId: submissionRecord.id,
|
|
439
|
-
txHash,
|
|
440
|
-
}, 'HSM-signed transaction submitted and all records updated');
|
|
522
|
+
signerInfo: `HSM key: ${prep.hsmKeyIdentifier}`,
|
|
523
|
+
}, (db) => db.run(UPDATE.entity(SigningRequests).set({ hsmKeyId: prep.hsmKeyIdentifier }).where({ id: prep.signingRequestId })).then(() => undefined));
|
|
524
|
+
logger.info({ signingRequestId: prep.signingRequestId, txHash: prep.txHash }, 'HSM-signed transaction submitted and all records updated');
|
|
441
525
|
return submissionRecord;
|
|
442
|
-
}
|
|
526
|
+
}
|
|
527
|
+
catch (e) {
|
|
528
|
+
logger.error({ err: e }, 'SignAndSubmitWithHsm error');
|
|
529
|
+
return (0, mappers_1.mapError)(req, e, 'SignAndSubmitWithHsm');
|
|
530
|
+
}
|
|
443
531
|
});
|
|
444
532
|
/**
|
|
445
533
|
* Get HSM connection status and key information.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { JSONValue } from './utils/types';
|
|
2
|
+
export interface ParsedExtraOutput {
|
|
3
|
+
address: string;
|
|
4
|
+
lovelaceAmount: string;
|
|
5
|
+
assets?: Array<{
|
|
6
|
+
unit: string;
|
|
7
|
+
quantity: string;
|
|
8
|
+
}>;
|
|
9
|
+
inlineDatum?: JSONValue;
|
|
10
|
+
referenceScript?: string;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=cardano-tx-service.d.ts.map
|