@odatano/core 1.7.10 → 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/LICENSE +1 -24
- package/README.md +102 -96
- package/db/schema.cds +18 -18
- package/db/types.cds +3 -3
- package/package.json +25 -11
- 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 +64 -57
- 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 +79 -79
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +236 -0
- package/srv/blockchain/transaction-building/buildooor-tx.js +632 -173
- 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 +26 -6
- package/srv/cardano-sign-service.cds +5 -0
- package/srv/cardano-sign-service.d.ts +2 -0
- package/srv/cardano-sign-service.js +221 -134
- package/srv/cardano-tx-service.cds +8 -0
- package/srv/cardano-tx-service.d.ts +12 -0
- package/srv/cardano-tx-service.js +170 -111
- 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 +52 -41
- 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 +6 -17
- package/srv/utils/signing-helper.d.ts +23 -0
- package/srv/utils/signing-helper.js +11 -49
- package/srv/utils/tx-build-helper.d.ts +76 -0
- package/srv/utils/tx-build-helper.js +29 -80
- 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 -118
- package/config/preview/cardano-node/conway-genesis.json +0 -297
- package/config/preview/cardano-node/shelley-genesis.json +0 -68
- package/config/preview/cardano-node/topology.json +0 -19
- 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/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/gerolamo-backend.d.ts.map +0 -1
- package/srv/blockchain/backends/gerolamo-backend.js +0 -321
- package/srv/blockchain/backends/gerolamo-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/blockchain/transaction-building/csl-tx.d.ts.map +0 -1
- package/srv/blockchain/transaction-building/csl-tx.js +0 -922
- package/srv/blockchain/transaction-building/csl-tx.js.map +0 -1
- package/srv/blockchain/transaction-building/tx-builder-registry.d.ts.map +0 -1
- package/srv/blockchain/transaction-building/tx-builder-registry.js +0 -69
- package/srv/blockchain/transaction-building/tx-builder-registry.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.
|
|
@@ -65,13 +153,12 @@ module.exports = (srv) => {
|
|
|
65
153
|
*/
|
|
66
154
|
let lastExpiryCheck = 0;
|
|
67
155
|
const EXPIRY_CHECK_INTERVAL_MS = 60_000;
|
|
68
|
-
srv.before('READ', SigningRequests, async () => {
|
|
156
|
+
srv.before('READ', SigningRequests, async (req) => {
|
|
69
157
|
const now = Date.now();
|
|
70
158
|
if (now - lastExpiryCheck < EXPIRY_CHECK_INTERVAL_MS)
|
|
71
159
|
return;
|
|
72
160
|
lastExpiryCheck = now;
|
|
73
|
-
|
|
74
|
-
await db.run(UPDATE.entity(SigningRequests)
|
|
161
|
+
await cds_1.default.tx(req).run(UPDATE.entity(SigningRequests)
|
|
75
162
|
.set({ status: 'expired' })
|
|
76
163
|
.where({ status: 'pending', expiresAt: { '<=': new Date().toISOString() } }));
|
|
77
164
|
});
|
|
@@ -154,13 +241,24 @@ module.exports = (srv) => {
|
|
|
154
241
|
if (address && signingRequest.build_id) {
|
|
155
242
|
await verifyBuildOwnership(req, db, signingRequest.build_id, address, TransactionBuilds, 'VerifySignature');
|
|
156
243
|
}
|
|
157
|
-
//
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
//
|
|
162
|
-
|
|
163
|
-
|
|
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');
|
|
164
262
|
}
|
|
165
263
|
// Detect if signedTxCbor is a witness set (CIP-30) or a full signed transaction (cardano-cli)
|
|
166
264
|
let fullSignedTxCbor;
|
|
@@ -173,9 +271,11 @@ module.exports = (srv) => {
|
|
|
173
271
|
// Full signed transaction provided (e.g., from cardano-cli)
|
|
174
272
|
fullSignedTxCbor = signedTxCbor;
|
|
175
273
|
}
|
|
176
|
-
// 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);
|
|
177
277
|
const signerModule = (0, external_signer_1.getExternalSignerModule)();
|
|
178
|
-
const result = signerModule.verifySignedTransaction(fullSignedTxCbor, signingRequest.txBodyHash);
|
|
278
|
+
const result = signerModule.verifySignedTransaction(fullSignedTxCbor, signingRequest.txBodyHash, { requiredSigners });
|
|
179
279
|
// Delegate persistence to indexer (store full signed tx for later submission)
|
|
180
280
|
const verificationRecord = await (0, server_1.getCardanoIndexer)().persistSignatureVerification(db, {
|
|
181
281
|
signingRequestId,
|
|
@@ -205,79 +305,69 @@ module.exports = (srv) => {
|
|
|
205
305
|
(0, errors_1.throwIfValidationErrors)(req, 'SubmitVerifiedTransaction', errors);
|
|
206
306
|
if (address && !(0, validators_1.isValidBech32Address)(address))
|
|
207
307
|
(0, errors_1.rejectInvalid)(req, 'SubmitVerifiedTransaction', 'Invalid bech32 address format', 'address');
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
if (
|
|
225
|
-
|
|
226
|
-
|
|
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');
|
|
227
332
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
//
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
// Verify signature (throws on failure)
|
|
253
|
-
const signerModule = (0, external_signer_1.getExternalSignerModule)();
|
|
254
|
-
const verificationResult = signerModule.verifyOrThrow(fullSignedTxCbor, signingRequest.txBodyHash);
|
|
255
|
-
logger.info({
|
|
256
|
-
signingRequestId,
|
|
257
|
-
witnessCount: verificationResult.witnessCount,
|
|
258
|
-
signers: verificationResult.signerKeyHashes,
|
|
259
|
-
}, 'Signature verified, proceeding with submission');
|
|
260
|
-
// Submit to blockchain
|
|
261
|
-
const txHash = signingRequest.txBodyHash;
|
|
262
|
-
await (0, server_1.getCardanoClient)().submitTransaction(fullSignedTxCbor);
|
|
263
|
-
logger.info({ txHash }, 'Verified transaction submitted to blockchain');
|
|
264
|
-
// Delegate all persistence to indexer
|
|
265
|
-
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, {
|
|
266
356
|
signingRequestId,
|
|
267
|
-
buildId:
|
|
268
|
-
fullSignedTxCbor,
|
|
269
|
-
txHash,
|
|
270
|
-
verificationResult,
|
|
357
|
+
buildId: prep.buildId,
|
|
358
|
+
fullSignedTxCbor: prep.fullSignedTxCbor,
|
|
359
|
+
txHash: prep.txHash,
|
|
360
|
+
verificationResult: prep.verificationResult,
|
|
271
361
|
signerType,
|
|
272
362
|
signerInfo,
|
|
273
363
|
});
|
|
274
|
-
logger.info({
|
|
275
|
-
signingRequestId,
|
|
276
|
-
submissionId: submissionRecord.id,
|
|
277
|
-
txHash,
|
|
278
|
-
}, 'Transaction submitted and all records updated');
|
|
364
|
+
logger.info({ signingRequestId, txHash: prep.txHash }, 'Transaction submitted and all records updated');
|
|
279
365
|
return submissionRecord;
|
|
280
|
-
}
|
|
366
|
+
}
|
|
367
|
+
catch (e) {
|
|
368
|
+
logger.error({ err: e }, 'SubmitVerifiedTransaction error');
|
|
369
|
+
return (0, mappers_1.mapError)(req, e, 'SubmitVerifiedTransaction');
|
|
370
|
+
}
|
|
281
371
|
});
|
|
282
372
|
/**
|
|
283
373
|
* Get all existing signing requests by address
|
|
@@ -341,6 +431,13 @@ module.exports = (srv) => {
|
|
|
341
431
|
const verificationResult = signerModule.verifySignedTransaction(signedTxCbor, build.txBodyHash);
|
|
342
432
|
const hsmStatus = hsmSigner.getStatus();
|
|
343
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
|
+
}
|
|
344
441
|
// 5. Persist verification
|
|
345
442
|
await (0, server_1.getCardanoIndexer)().persistSignatureVerification(db, {
|
|
346
443
|
signingRequestId: signingRequestRecord.id,
|
|
@@ -383,64 +480,54 @@ module.exports = (srv) => {
|
|
|
383
480
|
if (!hsmSigner || !hsmSigner.isConnected()) {
|
|
384
481
|
(0, errors_1.rejectInvalid)(req, 'SignAndSubmitWithHsm', 'HSM is not configured or not connected', 'hsm');
|
|
385
482
|
}
|
|
386
|
-
|
|
387
|
-
// 1
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
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 };
|
|
400
511
|
});
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
//
|
|
404
|
-
const
|
|
405
|
-
|
|
406
|
-
const hsmKeyIdentifier = hsmStatus.keyLabel || hsmStatus.keyId || 'unknown';
|
|
407
|
-
if (!verificationResult.isValid) {
|
|
408
|
-
logger.error({
|
|
409
|
-
signingRequestId: signingRequestRecord.id,
|
|
410
|
-
hsmKey: hsmKeyIdentifier,
|
|
411
|
-
}, 'HSM signature verification failed — aborting submission');
|
|
412
|
-
(0, errors_1.rejectInvalid)(req, 'SignAndSubmitWithHsm', 'HSM signature verification failed', 'signedTxCbor');
|
|
413
|
-
}
|
|
414
|
-
logger.info({
|
|
415
|
-
signingRequestId: signingRequestRecord.id,
|
|
416
|
-
witnessCount: verificationResult.witnessCount,
|
|
417
|
-
hsmKey: hsmKeyIdentifier,
|
|
418
|
-
}, 'HSM signature verified, proceeding with submission');
|
|
419
|
-
// 5. Submit to blockchain
|
|
420
|
-
const txHash = build.txBodyHash;
|
|
421
|
-
await (0, server_1.getCardanoClient)().submitTransaction(signedTxCbor);
|
|
422
|
-
logger.info({ txHash }, 'HSM-signed transaction submitted to blockchain');
|
|
423
|
-
// 6. Persist everything atomically via indexer
|
|
424
|
-
const submissionRecord = await (0, server_1.getCardanoIndexer)().indexVerifiedTransactionSubmission(db, {
|
|
425
|
-
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,
|
|
426
517
|
buildId,
|
|
427
|
-
fullSignedTxCbor: signedTxCbor,
|
|
428
|
-
txHash,
|
|
429
|
-
verificationResult,
|
|
518
|
+
fullSignedTxCbor: prep.signedTxCbor,
|
|
519
|
+
txHash: prep.txHash,
|
|
520
|
+
verificationResult: prep.verificationResult,
|
|
430
521
|
signerType: 'hsm',
|
|
431
|
-
signerInfo: `HSM key: ${hsmKeyIdentifier}`,
|
|
432
|
-
});
|
|
433
|
-
|
|
434
|
-
await db.run(UPDATE.entity(SigningRequests)
|
|
435
|
-
.set({ hsmKeyId: hsmKeyIdentifier })
|
|
436
|
-
.where({ id: signingRequestRecord.id }));
|
|
437
|
-
logger.info({
|
|
438
|
-
signingRequestId: signingRequestRecord.id,
|
|
439
|
-
submissionId: submissionRecord.id,
|
|
440
|
-
txHash,
|
|
441
|
-
}, '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');
|
|
442
525
|
return submissionRecord;
|
|
443
|
-
}
|
|
526
|
+
}
|
|
527
|
+
catch (e) {
|
|
528
|
+
logger.error({ err: e }, 'SignAndSubmitWithHsm error');
|
|
529
|
+
return (0, mappers_1.mapError)(req, e, 'SignAndSubmitWithHsm');
|
|
530
|
+
}
|
|
444
531
|
});
|
|
445
532
|
/**
|
|
446
533
|
* Get HSM connection status and key information.
|
|
@@ -18,26 +18,32 @@ service CardanoTransactionService @(impl: './cardano-tx-service') {
|
|
|
18
18
|
// Entity Projections - Transaction Building & Submission
|
|
19
19
|
// ---------------------------------------------------------------------------
|
|
20
20
|
|
|
21
|
+
@readonly
|
|
21
22
|
@title : 'Transaction Builds'
|
|
22
23
|
@description: 'Projection for Transaction Builds'
|
|
23
24
|
entity TransactionBuilds as projection on db.TransactionBuilds;
|
|
24
25
|
|
|
26
|
+
@readonly
|
|
25
27
|
@title : 'Transaction Build Inputs'
|
|
26
28
|
@description: 'Projection for Transaction Build Inputs'
|
|
27
29
|
entity TransactionBuildInputs as projection on db.TransactionBuildInputs;
|
|
28
30
|
|
|
31
|
+
@readonly
|
|
29
32
|
@title : 'Transaction Build Outputs'
|
|
30
33
|
@description: 'Projection for Transaction Build Outputs'
|
|
31
34
|
entity TransactionBuildOutputs as projection on db.TransactionBuildOutputs;
|
|
32
35
|
|
|
36
|
+
@readonly
|
|
33
37
|
@title : 'Transaction Build Input Assets'
|
|
34
38
|
@description: 'Projection for Transaction Build Input Assets'
|
|
35
39
|
entity TransactionBuildInputAssets as projection on db.TransactionBuildInputAssets;
|
|
36
40
|
|
|
41
|
+
@readonly
|
|
37
42
|
@title : 'Transaction Build Output Assets'
|
|
38
43
|
@description: 'Projection for Transaction Build Output Assets'
|
|
39
44
|
entity TransactionBuildOutputAssets as projection on db.TransactionBuildOutputAssets;
|
|
40
45
|
|
|
46
|
+
@readonly
|
|
41
47
|
@title : 'Transaction Submissions'
|
|
42
48
|
@description: 'Projection for Transaction Submissions'
|
|
43
49
|
entity TransactionSubmissions as projection on db.TransactionSubmissions
|
|
@@ -56,10 +62,12 @@ service CardanoTransactionService @(impl: './cardano-tx-service') {
|
|
|
56
62
|
CheckSubmissionStatus @from : [ #submitted];
|
|
57
63
|
};
|
|
58
64
|
|
|
65
|
+
@readonly
|
|
59
66
|
@title : 'Transaction Submission Errors'
|
|
60
67
|
@description: 'Projection for Transaction Submission Errors'
|
|
61
68
|
entity TransactionSubmissionErrors as projection on db.TransactionSubmissionErrors;
|
|
62
69
|
|
|
70
|
+
@readonly
|
|
63
71
|
@title : 'Address Transaction Builds'
|
|
64
72
|
@description: 'Projection for retrieving transaction builds by address'
|
|
65
73
|
entity AddressTransactionBuilds as projection on db.AddressTransactionBuilds;
|
|
@@ -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
|