@odatano/core 2.0.0-rc.5 → 2.0.0-rc.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@cds-models/CardanoAgentService/index.d.ts +99 -51
- package/@cds-models/CardanoAgentService/index.js +15 -0
- package/@cds-models/CardanoBackendService/index.d.ts +358 -0
- package/@cds-models/CardanoBackendService/index.js +41 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +594 -11
- package/@cds-models/CardanoIndexerService/index.js +74 -0
- package/@cds-models/CardanoODataService/index.d.ts +417 -57
- package/@cds-models/CardanoODataService/index.js +42 -0
- package/@cds-models/CardanoSignService/index.d.ts +45 -19
- package/@cds-models/CardanoSignService/index.js +4 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +70 -44
- package/@cds-models/CardanoTransactionService/index.js +5 -0
- package/@cds-models/CardanoWorkerService/index.d.ts +35 -22
- package/@cds-models/CardanoWorkerService/index.js +2 -0
- package/@cds-models/index.d.ts +114 -4
- package/@cds-models/index.js +20 -4
- package/@cds-models/odatano/cardano/index.d.ts +451 -32
- package/@cds-models/odatano/cardano/index.js +48 -0
- package/README.md +103 -167
- package/db/schema.cds +2455 -1705
- package/db/types.cds +456 -295
- package/package.json +41 -53
- package/scripts/deploy-schema.mjs +113 -0
- package/scripts/migrate-schema.mjs +528 -0
- package/scripts/migrate-slot-leader.mjs +96 -0
- package/src/index.d.ts +20 -21
- package/src/index.js +45 -31
- package/src/plugin.js +17 -35
- package/srv/blockchain/asset-decimals.d.ts +7 -0
- package/srv/blockchain/asset-decimals.js +91 -0
- package/srv/blockchain/backends/blockfrost-backend.d.ts +25 -137
- package/srv/blockchain/backends/blockfrost-backend.js +125 -215
- package/srv/blockchain/backends/call-signal.d.ts +7 -0
- package/srv/blockchain/backends/call-signal.js +22 -0
- package/srv/blockchain/backends/cardano-backend.d.ts +100 -189
- package/srv/blockchain/backends/cardano-backend.js +29 -5
- package/srv/blockchain/backends/koios-backend.d.ts +108 -170
- package/srv/blockchain/backends/koios-backend.js +488 -482
- package/srv/blockchain/backends/odatano-backend.d.ts +55 -0
- package/srv/blockchain/backends/odatano-backend.js +211 -0
- package/srv/blockchain/backends/ogmios-backend.d.ts +122 -190
- package/srv/blockchain/backends/ogmios-backend.js +683 -327
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +14 -0
- package/srv/blockchain/backends/ogmios-frame-guard.js +89 -0
- package/srv/blockchain/cardano-client.d.ts +71 -241
- package/srv/blockchain/cardano-client.js +354 -322
- package/srv/blockchain/cardano-indexer.d.ts +295 -283
- package/srv/blockchain/cardano-indexer.js +1690 -502
- package/srv/blockchain/cardano-tx-builder.d.ts +25 -89
- package/srv/blockchain/cardano-tx-builder.js +164 -140
- package/srv/blockchain/circuit-breaker.d.ts +2 -13
- package/srv/blockchain/circuit-breaker.js +11 -15
- package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
- package/srv/blockchain/crawler/account-snapshots.js +173 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +17 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
- package/srv/blockchain/crawler/asset-registry-backfill.d.ts +46 -0
- package/srv/blockchain/crawler/asset-registry-backfill.js +157 -0
- package/srv/blockchain/crawler/asset-slice-backfill.d.ts +35 -0
- package/srv/blockchain/crawler/asset-slice-backfill.js +149 -0
- package/srv/blockchain/crawler/certificate-backfill.d.ts +56 -0
- package/srv/blockchain/crawler/certificate-backfill.js +174 -0
- package/srv/blockchain/crawler/crawler.d.ts +125 -81
- package/srv/blockchain/crawler/crawler.js +738 -167
- package/srv/blockchain/crawler/credential-backfill.d.ts +30 -0
- package/srv/blockchain/crawler/credential-backfill.js +101 -0
- package/srv/blockchain/crawler/hooks.d.ts +2 -17
- package/srv/blockchain/crawler/index.d.ts +1 -8
- package/srv/blockchain/crawler/index.js +31 -17
- package/srv/blockchain/crawler/input-asset-copies.d.ts +34 -0
- package/srv/blockchain/crawler/input-asset-copies.js +161 -0
- package/srv/blockchain/crawler/key-pages.d.ts +12 -0
- package/srv/blockchain/crawler/key-pages.js +48 -0
- package/srv/blockchain/crawler/metadata-position-backfill.d.ts +22 -0
- package/srv/blockchain/crawler/metadata-position-backfill.js +59 -0
- package/srv/blockchain/crawler/output-datum-backfill.d.ts +41 -0
- package/srv/blockchain/crawler/output-datum-backfill.js +100 -0
- package/srv/blockchain/crawler/sync-state.d.ts +31 -47
- package/srv/blockchain/crawler/sync-state.js +135 -128
- package/srv/blockchain/crawler/transaction-backfill.d.ts +46 -0
- package/srv/blockchain/crawler/transaction-backfill.js +271 -0
- package/srv/blockchain/crawler/utxo-set-import.d.ts +66 -0
- package/srv/blockchain/crawler/utxo-set-import.js +399 -0
- package/srv/blockchain/crawler/window-plan.d.ts +31 -0
- package/srv/blockchain/crawler/window-plan.js +59 -0
- package/srv/blockchain/ledger-state.d.ts +62 -0
- package/srv/blockchain/ledger-state.js +521 -0
- package/srv/blockchain/pending-spends.d.ts +16 -0
- package/srv/blockchain/pending-spends.js +81 -0
- package/srv/blockchain/pool-metadata.d.ts +15 -0
- package/srv/blockchain/pool-metadata.js +132 -0
- package/srv/blockchain/request-coalescer.d.ts +2 -16
- package/srv/blockchain/request-coalescer.js +2 -16
- package/srv/blockchain/signing/cose-verifier.d.ts +3 -17
- package/srv/blockchain/signing/cose-verifier.js +146 -70
- package/srv/blockchain/signing/external-signer.d.ts +15 -115
- package/srv/blockchain/signing/external-signer.js +22 -131
- package/srv/blockchain/signing/failed-recheck.d.ts +17 -0
- package/srv/blockchain/signing/failed-recheck.js +135 -0
- package/srv/blockchain/signing/hsm-signer.d.ts +10 -54
- package/srv/blockchain/signing/hsm-signer.js +28 -79
- package/srv/blockchain/signing/landing-proof.d.ts +60 -0
- package/srv/blockchain/signing/landing-proof.js +224 -0
- package/srv/blockchain/signing/signature-verifier.d.ts +9 -47
- package/srv/blockchain/signing/signature-verifier.js +71 -87
- package/srv/blockchain/signing/submission-finalizer.d.ts +37 -45
- package/srv/blockchain/signing/submission-finalizer.js +280 -86
- package/srv/blockchain/stored-chain.d.ts +19 -0
- package/srv/blockchain/stored-chain.js +258 -0
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +31 -229
- package/srv/blockchain/transaction-building/buildooor-tx.js +663 -421
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +9 -37
- package/srv/blockchain/transaction-presence.d.ts +12 -0
- package/srv/blockchain/transaction-presence.js +29 -0
- package/srv/blockchain/transaction-rows.d.ts +12 -0
- package/srv/blockchain/transaction-rows.js +44 -0
- package/srv/blockchain/wallet-worker/build-request.d.ts +8 -23
- package/srv/blockchain/wallet-worker/build-request.js +40 -353
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +27 -47
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +158 -61
- package/srv/blockchain/wallet-worker/index.d.ts +1 -1
- package/srv/blockchain/wallet-worker/index.js +3 -11
- package/srv/blockchain/wallet-worker/invalidation.d.ts +35 -0
- package/srv/blockchain/wallet-worker/invalidation.js +128 -0
- package/srv/blockchain/wallet-worker/job-store.d.ts +58 -150
- package/srv/blockchain/wallet-worker/job-store.js +200 -273
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -26
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -28
- package/srv/blockchain/wallet-worker/signers.d.ts +5 -24
- package/srv/blockchain/wallet-worker/signers.js +4 -12
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +29 -82
- package/srv/blockchain/wallet-worker/wallet-worker.js +334 -198
- package/srv/cardano-agent-service.cds +122 -84
- package/srv/cardano-agent-service.js +12 -9
- package/srv/cardano-backend-service.cds +81 -0
- package/srv/cardano-backend-service.d.ts +2 -0
- package/srv/cardano-backend-service.js +259 -0
- package/srv/cardano-indexer-service.cds +393 -18
- package/srv/cardano-indexer-service.d.ts +5 -1
- package/srv/cardano-indexer-service.js +477 -16
- package/srv/cardano-service.cds +426 -269
- package/srv/cardano-service.js +640 -217
- package/srv/cardano-sign-service.cds +211 -180
- package/srv/cardano-sign-service.js +210 -287
- package/srv/cardano-tx-service.cds +462 -370
- package/srv/cardano-tx-service.js +283 -800
- package/srv/cardano-ui.cds +16 -16
- package/srv/cardano-worker-service.cds +141 -125
- package/srv/cardano-worker-service.js +104 -61
- package/srv/cbor/cip68.d.ts +13 -0
- package/srv/cbor/cip68.js +56 -0
- package/srv/cbor/index.d.ts +3 -1
- package/srv/cbor/index.js +9 -1
- package/srv/cbor/parse.d.ts +30 -18
- package/srv/cbor/parse.js +44 -9
- package/srv/cbor/plutus-data-json.d.ts +20 -0
- package/srv/cbor/plutus-data-json.js +32 -0
- package/srv/config.d.ts +117 -0
- package/srv/config.js +419 -0
- package/srv/server.d.ts +15 -110
- package/srv/server.js +83 -405
- package/srv/utils/agent-access.d.ts +11 -0
- package/srv/utils/agent-access.js +86 -0
- package/srv/utils/agent-grants-config.d.ts +0 -46
- package/srv/utils/agent-grants-config.js +17 -85
- package/srv/utils/agent-grants.d.ts +106 -122
- package/srv/utils/agent-grants.js +538 -237
- package/srv/utils/agent-token-auth.d.ts +4 -99
- package/srv/utils/agent-token-auth.js +62 -186
- package/srv/utils/backend-request-handler.d.ts +3 -17
- package/srv/utils/backend-request-handler.js +3 -18
- package/srv/utils/build-request.d.ts +52 -0
- package/srv/utils/build-request.js +487 -0
- package/srv/utils/collections.d.ts +4 -10
- package/srv/utils/collections.js +14 -10
- package/srv/utils/const.d.ts +32 -75
- package/srv/utils/const.js +40 -80
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +11 -25
- package/srv/utils/db-indexes.d.ts +31 -0
- package/srv/utils/db-indexes.js +185 -0
- package/srv/utils/db-kind.d.ts +23 -0
- package/srv/utils/db-kind.js +42 -0
- package/srv/utils/db-sanitize.d.ts +20 -0
- package/srv/utils/db-sanitize.js +80 -0
- package/srv/utils/deep-json.d.ts +6 -0
- package/srv/utils/deep-json.js +240 -0
- package/srv/utils/detached-run.d.ts +41 -0
- package/srv/utils/detached-run.js +101 -0
- package/srv/utils/epoch-slots.d.ts +14 -0
- package/srv/utils/epoch-slots.js +45 -0
- package/srv/utils/error-codes.d.ts +26 -75
- package/srv/utils/error-codes.js +27 -72
- package/srv/utils/errors.d.ts +55 -187
- package/srv/utils/errors.js +161 -235
- package/srv/utils/lease.d.ts +20 -0
- package/srv/utils/lease.js +62 -0
- package/srv/utils/liveness.d.ts +12 -0
- package/srv/utils/liveness.js +35 -0
- package/srv/utils/mappers.d.ts +111 -223
- package/srv/utils/mappers.js +432 -371
- package/srv/utils/navigation.d.ts +17 -0
- package/srv/utils/navigation.js +52 -0
- package/srv/utils/network-context.d.ts +0 -1
- package/srv/utils/network-context.js +9 -15
- package/srv/utils/paging.d.ts +31 -0
- package/srv/utils/paging.js +43 -0
- package/srv/utils/pg-inline-json.d.ts +8 -0
- package/srv/utils/pg-inline-json.js +58 -0
- package/srv/utils/pg-order-nulls.d.ts +14 -0
- package/srv/utils/pg-order-nulls.js +54 -0
- package/srv/utils/plutus-placeholders.d.ts +16 -22
- package/srv/utils/plutus-placeholders.js +62 -33
- package/srv/utils/rate-limiter.d.ts +2 -21
- package/srv/utils/rate-limiter.js +5 -17
- package/srv/utils/readiness.d.ts +12 -0
- package/srv/utils/readiness.js +29 -0
- package/srv/utils/reference-script.d.ts +19 -0
- package/srv/utils/reference-script.js +84 -0
- package/srv/utils/resolution.d.ts +13 -0
- package/srv/utils/resolution.js +47 -0
- package/srv/utils/result-numbers.d.ts +15 -0
- package/srv/utils/result-numbers.js +61 -0
- package/srv/utils/row-values.d.ts +7 -0
- package/srv/utils/row-values.js +27 -0
- package/srv/utils/service-events.d.ts +0 -24
- package/srv/utils/service-events.js +3 -25
- package/srv/utils/signing-helper.d.ts +3 -20
- package/srv/utils/signing-helper.js +35 -64
- package/srv/utils/tx-build-helper.d.ts +25 -105
- package/srv/utils/tx-build-helper.js +108 -156
- package/srv/utils/tx-request-parsers.d.ts +82 -33
- package/srv/utils/tx-request-parsers.js +401 -49
- package/srv/utils/tx-utils.d.ts +3 -27
- package/srv/utils/tx-utils.js +32 -50
- package/srv/utils/types.d.ts +294 -232
- package/srv/utils/types.js +2 -22
- package/srv/utils/validators.d.ts +22 -92
- package/srv/utils/validators.js +60 -170
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.SignatureVerifier = void 0;
|
|
7
|
+
exports.verifyTxWitnesses = verifyTxWitnesses;
|
|
7
8
|
exports.getSignatureVerifier = getSignatureVerifier;
|
|
8
9
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
9
10
|
const cbor_1 = require("@harmoniclabs/cbor");
|
|
@@ -12,13 +13,8 @@ const crypto_1 = require("@harmoniclabs/crypto");
|
|
|
12
13
|
const errors_1 = require("../../utils/errors");
|
|
13
14
|
const error_codes_1 = require("../../utils/error-codes");
|
|
14
15
|
const logger = cds_1.default.log('SignatureVerifier');
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* subCborRef preserves the exact received bytes, so the hash matches what was signed
|
|
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.)
|
|
21
|
-
*/
|
|
16
|
+
// blake2b-256 over the original body bytes. subCborRef keeps the received bytes,
|
|
17
|
+
// so the hash matches what was signed.
|
|
22
18
|
function computeBodyHash(txBytes) {
|
|
23
19
|
const tx = cbor_1.Cbor.parse(txBytes);
|
|
24
20
|
if (!(tx instanceof cbor_1.CborArray) || tx.array.length < 1 || !tx.array[0].subCborRef) {
|
|
@@ -26,64 +22,73 @@ function computeBodyHash(txBytes) {
|
|
|
26
22
|
}
|
|
27
23
|
return (0, uint8array_utils_1.toHex)((0, crypto_1.blake2b_256)(tx.array[0].subCborRef.toBuffer()));
|
|
28
24
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
* tag 258 (set) — unwrapped here. Returns [] when the tx has no vkey witnesses.
|
|
33
|
-
*/
|
|
34
|
-
function extractVkeyWitnesses(txBytes) {
|
|
25
|
+
// Conway wraps the vkey witness array in CBOR tag 258, which is unwrapped here.
|
|
26
|
+
// `malformed` counts entries that are not a [vkey, signature] byte pair.
|
|
27
|
+
function readVkeyWitnesses(txBytes) {
|
|
35
28
|
const tx = cbor_1.Cbor.parse(txBytes);
|
|
36
29
|
if (!(tx instanceof cbor_1.CborArray) || !(tx.array[1] instanceof cbor_1.CborMap))
|
|
37
|
-
return [];
|
|
30
|
+
return { witnesses: [], malformed: 0 };
|
|
38
31
|
const entry = tx.array[1].map.find(e => e.k instanceof cbor_1.CborUInt && Number(e.k.num) === 0);
|
|
39
32
|
if (!entry)
|
|
40
|
-
return [];
|
|
33
|
+
return { witnesses: [], malformed: 0 };
|
|
41
34
|
let arr = entry.v;
|
|
42
35
|
if (arr instanceof cbor_1.CborTag)
|
|
43
36
|
arr = arr.data;
|
|
44
37
|
if (!(arr instanceof cbor_1.CborArray))
|
|
45
|
-
return [];
|
|
46
|
-
// Parse defensively: a malformed witness entry (wrong shape or non-bytes members)
|
|
47
|
-
// would otherwise throw a TypeError and surface as an opaque internal error. Skip
|
|
48
|
-
// any entry that isn't a [vkey, signature] pair of byte strings.
|
|
38
|
+
return { witnesses: [], malformed: 0 };
|
|
49
39
|
const witnesses = [];
|
|
50
|
-
let
|
|
51
|
-
|
|
40
|
+
let malformed = 0;
|
|
41
|
+
arr.array.forEach((pair, index) => {
|
|
52
42
|
if (!(pair instanceof cbor_1.CborArray) || pair.array.length !== 2) {
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
malformed++;
|
|
44
|
+
return;
|
|
55
45
|
}
|
|
56
46
|
const [vk, sg] = pair.array;
|
|
57
47
|
if (!(vk instanceof cbor_1.CborBytes) || !(sg instanceof cbor_1.CborBytes)) {
|
|
58
|
-
|
|
59
|
-
|
|
48
|
+
malformed++;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
witnesses.push({ index, pubKey: vk.bytes, signature: sg.bytes });
|
|
52
|
+
});
|
|
53
|
+
return { witnesses, malformed };
|
|
54
|
+
}
|
|
55
|
+
/** Ed25519 check of one witness over the body hash; false for a key or signature of the wrong length. */
|
|
56
|
+
function signatureValid(w, bodyHashBytes) {
|
|
57
|
+
try {
|
|
58
|
+
return (0, crypto_1.verifyEd25519Signature_sync)(w.signature, bodyHashBytes, w.pubKey);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Checks every vkey witness against the body hash. Needs no initialize().
|
|
65
|
+
// A tx without vkey witnesses is valid here; required signers are the caller's check.
|
|
66
|
+
function verifyTxWitnesses(signedTxCbor) {
|
|
67
|
+
const errors = [];
|
|
68
|
+
const signerKeyHashes = [];
|
|
69
|
+
let txBodyHash = null;
|
|
70
|
+
try {
|
|
71
|
+
const txBytes = (0, uint8array_utils_1.fromHex)(signedTxCbor);
|
|
72
|
+
txBodyHash = computeBodyHash(txBytes);
|
|
73
|
+
const bodyHashBytes = (0, uint8array_utils_1.fromHex)(txBodyHash);
|
|
74
|
+
const { witnesses, malformed } = readVkeyWitnesses(txBytes);
|
|
75
|
+
if (malformed > 0)
|
|
76
|
+
errors.push(`${malformed} vkey witness entr${malformed === 1 ? 'y is' : 'ies are'} not a [vkey, signature] byte pair`);
|
|
77
|
+
for (const w of witnesses) {
|
|
78
|
+
if (signatureValid(w, bodyHashBytes))
|
|
79
|
+
signerKeyHashes.push((0, uint8array_utils_1.toHex)((0, crypto_1.blake2b_224)(w.pubKey)));
|
|
80
|
+
else
|
|
81
|
+
errors.push(`Invalid signature at witness index ${w.index}`);
|
|
60
82
|
}
|
|
61
|
-
witnesses.push({ pubKey: vk.bytes, signature: sg.bytes });
|
|
62
83
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
logger.warn(`Skipped ${skipped} malformed vkey witness entr${skipped === 1 ? 'y' : 'ies'} while verifying (expected [vkey, signature] byte pairs)`);
|
|
84
|
+
catch (error) {
|
|
85
|
+
errors.push(`Failed to read transaction: ${error instanceof Error ? error.message : String(error)}`);
|
|
66
86
|
}
|
|
67
|
-
return
|
|
87
|
+
return { valid: errors.length === 0, txBodyHash, signerKeyHashes, errors };
|
|
68
88
|
}
|
|
69
|
-
/**
|
|
70
|
-
* SignatureVerifier - Verifies transaction signatures without accessing private keys
|
|
71
|
-
*
|
|
72
|
-
* This module provides signature verification for externally signed transactions.
|
|
73
|
-
* It ensures:
|
|
74
|
-
* 1. The signed CBOR is valid and parseable
|
|
75
|
-
* 2. The transaction body hash matches the expected hash (integrity check)
|
|
76
|
-
* 3. Required signatures are present (when specified)
|
|
77
|
-
* 4. No tampering occurred between build and sign steps
|
|
78
|
-
*/
|
|
89
|
+
/** Verifies externally signed transactions without private keys. */
|
|
79
90
|
class SignatureVerifier {
|
|
80
|
-
/**
|
|
81
|
-
* Verify a signed transaction
|
|
82
|
-
*
|
|
83
|
-
* @param signedTxCbor - The signed transaction in CBOR hex format
|
|
84
|
-
* @param options - Verification options
|
|
85
|
-
* @returns Verification result with details
|
|
86
|
-
*/
|
|
91
|
+
/** Verify a signed tx (hex CBOR); all failures are reported in the result, never thrown. */
|
|
87
92
|
verify(signedTxCbor, options = {}) {
|
|
88
93
|
const result = {
|
|
89
94
|
isValid: false,
|
|
@@ -93,8 +98,7 @@ class SignatureVerifier {
|
|
|
93
98
|
warnings: [],
|
|
94
99
|
};
|
|
95
100
|
try {
|
|
96
|
-
//
|
|
97
|
-
// matching exactly what was signed.
|
|
101
|
+
// Body hash over the original body bytes, exactly what was signed.
|
|
98
102
|
const txBytes = (0, uint8array_utils_1.fromHex)(signedTxCbor);
|
|
99
103
|
const computedHash = computeBodyHash(txBytes);
|
|
100
104
|
result.txBodyHash = computedHash;
|
|
@@ -108,9 +112,15 @@ class SignatureVerifier {
|
|
|
108
112
|
}
|
|
109
113
|
logger.debug('Transaction body hash verified successfully');
|
|
110
114
|
}
|
|
111
|
-
// Extract vkey witnesses (raw pubkey + signature bytes)
|
|
112
|
-
|
|
115
|
+
// Extract vkey witnesses (raw pubkey + signature bytes). The node refuses a transaction with a
|
|
116
|
+
// malformed entry, so it never verifies here either.
|
|
117
|
+
const { witnesses: vkeyWitnesses, malformed } = readVkeyWitnesses(txBytes);
|
|
113
118
|
result.witnessCount = vkeyWitnesses.length;
|
|
119
|
+
if (malformed > 0) {
|
|
120
|
+
result.errorMessage = `${malformed} vkey witness entr${malformed === 1 ? 'y is' : 'ies are'} not a [vkey, signature] byte pair`;
|
|
121
|
+
logger.warn(result.errorMessage);
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
114
124
|
if (vkeyWitnesses.length > 0) {
|
|
115
125
|
// signer key hash = blake2b-224 of the Ed25519 public key
|
|
116
126
|
for (const w of vkeyWitnesses) {
|
|
@@ -137,11 +147,9 @@ class SignatureVerifier {
|
|
|
137
147
|
// verify each signature cryptographically against the transaction body hash
|
|
138
148
|
if (vkeyWitnesses.length > 0) {
|
|
139
149
|
const bodyHashBytes = (0, uint8array_utils_1.fromHex)(computedHash);
|
|
140
|
-
for (
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (!isValidSig) {
|
|
144
|
-
result.errorMessage = `Invalid signature at witness index ${i}. The signature does not match the transaction body.`;
|
|
150
|
+
for (const w of vkeyWitnesses) {
|
|
151
|
+
if (!signatureValid(w, bodyHashBytes)) {
|
|
152
|
+
result.errorMessage = `Invalid signature at witness index ${w.index}. The signature does not match the transaction body.`;
|
|
145
153
|
logger.warn(result.errorMessage);
|
|
146
154
|
return result;
|
|
147
155
|
}
|
|
@@ -159,13 +167,7 @@ class SignatureVerifier {
|
|
|
159
167
|
}
|
|
160
168
|
return result;
|
|
161
169
|
}
|
|
162
|
-
/**
|
|
163
|
-
* Verify signature and throw on failure
|
|
164
|
-
*
|
|
165
|
-
* @param signedTxCbor - The signed transaction in CBOR hex format
|
|
166
|
-
* @param options - Verification options
|
|
167
|
-
* @throws {TransactionValidationError} if verification fails
|
|
168
|
-
*/
|
|
170
|
+
/** Like verify(), but throws TransactionValidationError on failure. */
|
|
169
171
|
verifyOrThrow(signedTxCbor, options = {}) {
|
|
170
172
|
const result = this.verify(signedTxCbor, options);
|
|
171
173
|
if (!result.isValid) {
|
|
@@ -173,13 +175,7 @@ class SignatureVerifier {
|
|
|
173
175
|
}
|
|
174
176
|
return result;
|
|
175
177
|
}
|
|
176
|
-
/**
|
|
177
|
-
* Extract transaction body hash from unsigned or signed CBOR
|
|
178
|
-
*
|
|
179
|
-
* @param txCbor - Transaction CBOR (signed or unsigned)
|
|
180
|
-
* @returns Transaction body hash as hex string
|
|
181
|
-
* @throws {Error} if CBOR is invalid
|
|
182
|
-
*/
|
|
178
|
+
/** Body hash (hex) of an unsigned or signed tx CBOR; throws BackendError 400 on invalid CBOR. */
|
|
183
179
|
extractTxBodyHash(txCbor) {
|
|
184
180
|
try {
|
|
185
181
|
return computeBodyHash((0, uint8array_utils_1.fromHex)(txCbor));
|
|
@@ -189,29 +185,19 @@ class SignatureVerifier {
|
|
|
189
185
|
throw new errors_1.BackendError(`Failed to extract transaction body hash: ${msg}`, 400, error_codes_1.ERROR_CODES.INVALID_INPUT);
|
|
190
186
|
}
|
|
191
187
|
}
|
|
192
|
-
/**
|
|
193
|
-
* Check if a transaction is signed (has witnesses)
|
|
194
|
-
*
|
|
195
|
-
* @param txCbor - Transaction CBOR
|
|
196
|
-
* @returns true if transaction has at least one witness
|
|
197
|
-
*/
|
|
188
|
+
/** True when the tx carries at least one vkey witness. */
|
|
198
189
|
isSigned(txCbor) {
|
|
199
190
|
try {
|
|
200
|
-
return
|
|
191
|
+
return readVkeyWitnesses((0, uint8array_utils_1.fromHex)(txCbor)).witnesses.length > 0;
|
|
201
192
|
}
|
|
202
193
|
catch {
|
|
203
194
|
return false;
|
|
204
195
|
}
|
|
205
196
|
}
|
|
206
|
-
/**
|
|
207
|
-
* Get witness count from transaction
|
|
208
|
-
*
|
|
209
|
-
* @param txCbor - Transaction CBOR
|
|
210
|
-
* @returns Number of witnesses
|
|
211
|
-
*/
|
|
197
|
+
/** Number of vkey witnesses in the tx (0 on invalid CBOR). */
|
|
212
198
|
getWitnessCount(txCbor) {
|
|
213
199
|
try {
|
|
214
|
-
return
|
|
200
|
+
return readVkeyWitnesses((0, uint8array_utils_1.fromHex)(txCbor)).witnesses.length;
|
|
215
201
|
}
|
|
216
202
|
catch {
|
|
217
203
|
return 0;
|
|
@@ -221,9 +207,7 @@ class SignatureVerifier {
|
|
|
221
207
|
exports.SignatureVerifier = SignatureVerifier;
|
|
222
208
|
// Singleton instance
|
|
223
209
|
let verifierInstance = null;
|
|
224
|
-
/**
|
|
225
|
-
* Get the singleton SignatureVerifier instance
|
|
226
|
-
*/
|
|
210
|
+
/** Singleton SignatureVerifier. */
|
|
227
211
|
function getSignatureVerifier() {
|
|
228
212
|
if (!verifierInstance) {
|
|
229
213
|
verifierInstance = new SignatureVerifier();
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import cds, { Request } from '@sap/cds';
|
|
2
|
+
import { type LandingClient } from './landing-proof';
|
|
3
|
+
import type { CardanoIndexer } from '../cardano-indexer';
|
|
4
|
+
import type { CardanoClient } from '../cardano-client';
|
|
5
|
+
import { type TransactionSubmission } from '#cds-models/CardanoTransactionService';
|
|
6
|
+
/** An open submit is sent again for this long. After it only the chain is read. */
|
|
7
|
+
export declare const RESUBMIT_WINDOW_MS: number;
|
|
2
8
|
/** Shape persisted by indexVerifiedTransactionSubmission. */
|
|
3
9
|
export interface FinalizeParams {
|
|
4
10
|
signingRequestId: string;
|
|
@@ -13,51 +19,37 @@ export interface FinalizeParams {
|
|
|
13
19
|
};
|
|
14
20
|
signerType?: string;
|
|
15
21
|
signerInfo?: string;
|
|
22
|
+
/** When the transaction was first sent; bounds a transaction without an expiry. */
|
|
23
|
+
sentAtMs?: number | null;
|
|
16
24
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export declare function
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
*/
|
|
25
|
+
type SubmissionIndexer = Pick<CardanoIndexer, 'persistTransactionSubmission' | 'updateSubmissionStatus' | 'dropDuplicateSubmission' | 'invalidateUtxoCacheForTx' | 'findCrawledTransaction'>;
|
|
26
|
+
type SubmissionClient = Pick<CardanoClient, 'submitTransaction'> & LandingClient;
|
|
27
|
+
interface SubmissionDeps {
|
|
28
|
+
indexer: SubmissionIndexer & Pick<CardanoIndexer, 'indexVerifiedTransactionSubmission'>;
|
|
29
|
+
client: SubmissionClient;
|
|
30
|
+
}
|
|
31
|
+
type SubmitOutcome = 'accepted' | 'rejected' | 'scriptFailed' | 'unresolved' | 'unknown';
|
|
32
|
+
/** Records the reconciler reads only once an hour: no expiry, not landed, an input still unspent. */
|
|
33
|
+
export declare function staleRecordIds(): string[];
|
|
34
|
+
export declare function attemptSubmit(signedTxCbor: string, txHash: string, send: boolean, indexer: Pick<CardanoIndexer, 'findCrawledTransaction'>, client: SubmissionClient, sentAtMs?: number | null): Promise<{
|
|
35
|
+
outcome: SubmitOutcome;
|
|
36
|
+
error?: unknown;
|
|
37
|
+
finalRefusal?: boolean;
|
|
38
|
+
unspentInputs?: Array<{
|
|
39
|
+
txHash: string;
|
|
40
|
+
outputIndex: number;
|
|
41
|
+
}>;
|
|
42
|
+
}>;
|
|
43
|
+
export declare function submitAndFinalize(SigningRequests: unknown, params: FinalizeParams, afterFinalize?: (db: cds.Transaction) => Promise<void>, send?: boolean, { indexer, client }?: SubmissionDeps): Promise<unknown>;
|
|
44
|
+
export declare function submitRecorded(params: {
|
|
45
|
+
signedTxCbor: string;
|
|
46
|
+
txHash: string;
|
|
47
|
+
buildId: string | null;
|
|
48
|
+
}, indexer?: SubmissionIndexer, client?: SubmissionClient): Promise<TransactionSubmission>;
|
|
49
49
|
export declare function scheduleDeferredSubmit(req: Request, SigningRequests: unknown, params: FinalizeParams): void;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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>;
|
|
50
|
+
export declare function redriveInterruptedSubmissions(deps?: SubmissionDeps): Promise<number>;
|
|
51
|
+
/** Starts the periodic pass over open signing requests and submissions. Idempotent. */
|
|
52
|
+
export declare function startSubmissionReconciler(): void;
|
|
53
|
+
export declare function stopSubmissionReconciler(): void;
|
|
54
|
+
export {};
|
|
63
55
|
//# sourceMappingURL=submission-finalizer.d.ts.map
|