@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
|
@@ -11,9 +11,7 @@ const signature_verifier_1 = require("./signature-verifier");
|
|
|
11
11
|
const errors_1 = require("../../utils/errors");
|
|
12
12
|
const types_1 = require("../../utils/types");
|
|
13
13
|
const logger = cds_1.default.log('ExternalSigner');
|
|
14
|
-
/**
|
|
15
|
-
* Default TTL for signing requests (30 minutes)
|
|
16
|
-
*/
|
|
14
|
+
/** Default TTL for signing requests (30 minutes). */
|
|
17
15
|
const DEFAULT_SIGNING_TTL_MS = 30 * 60 * 1000;
|
|
18
16
|
/** Network flag for cardano-cli (mainnet vs testnet-magic). */
|
|
19
17
|
const CLI_NETWORK_FLAG = {
|
|
@@ -21,12 +19,7 @@ const CLI_NETWORK_FLAG = {
|
|
|
21
19
|
preprod: '--testnet-magic 1',
|
|
22
20
|
preview: '--testnet-magic 2',
|
|
23
21
|
};
|
|
24
|
-
/**
|
|
25
|
-
* Build a copy-pasteable cardano-cli signing recipe for the unsigned tx.
|
|
26
|
-
* Templated (the caller supplies their own signing key file); the network flag
|
|
27
|
-
* and the unsigned CBOR are filled in. Previously this was always NULL despite
|
|
28
|
-
* the schema exposing a `cardanoCliCommand` field.
|
|
29
|
-
*/
|
|
22
|
+
/** cardano-cli signing recipe for the unsigned tx. The caller supplies the key file. */
|
|
30
23
|
function buildCardanoCliCommand(network, unsignedTxCbor) {
|
|
31
24
|
const netFlag = CLI_NETWORK_FLAG[network] ?? '--testnet-magic <MAGIC>';
|
|
32
25
|
return [
|
|
@@ -37,20 +30,7 @@ function buildCardanoCliCommand(network, unsignedTxCbor) {
|
|
|
37
30
|
'# 3) Submit the cborHex from tx.signed via SubmitSignedTransaction / SubmitVerifiedTransaction',
|
|
38
31
|
].join('\n');
|
|
39
32
|
}
|
|
40
|
-
/**
|
|
41
|
-
* ExternalSignerModule - Manages the external signing workflow
|
|
42
|
-
*
|
|
43
|
-
* This module orchestrates the complete flow:
|
|
44
|
-
* 1. Create signing request from build result
|
|
45
|
-
* 2. Export unsigned transaction for external signing
|
|
46
|
-
* 3. Receive and verify signed transaction
|
|
47
|
-
* 4. Prepare for submission
|
|
48
|
-
*
|
|
49
|
-
* Key security principles:
|
|
50
|
-
* - NO private keys are ever handled by this service
|
|
51
|
-
* - Signature verification ensures transaction integrity
|
|
52
|
-
* - Complete audit trail of the signing workflow
|
|
53
|
-
*/
|
|
33
|
+
/** External signing workflow. No private keys are ever handled here. */
|
|
54
34
|
class ExternalSignerModule {
|
|
55
35
|
verifier;
|
|
56
36
|
signingTtlMs;
|
|
@@ -58,20 +38,7 @@ class ExternalSignerModule {
|
|
|
58
38
|
this.verifier = (0, signature_verifier_1.getSignatureVerifier)();
|
|
59
39
|
this.signingTtlMs = options?.signingTtlMs ?? DEFAULT_SIGNING_TTL_MS;
|
|
60
40
|
}
|
|
61
|
-
/**
|
|
62
|
-
* Create an unsigned transaction export payload for external signing
|
|
63
|
-
*
|
|
64
|
-
* This is the entry point for the external signing workflow.
|
|
65
|
-
* Call this after building a transaction to get a standardized
|
|
66
|
-
* payload that external signers can use.
|
|
67
|
-
*
|
|
68
|
-
* @param buildId - The build ID from TransactionBuilds
|
|
69
|
-
* @param unsignedTxCbor - The unsigned transaction CBOR
|
|
70
|
-
* @param txBodyHash - The transaction body hash
|
|
71
|
-
* @param network - The Cardano network
|
|
72
|
-
* @param options - Additional options
|
|
73
|
-
* @returns Unsigned transaction export payload
|
|
74
|
-
*/
|
|
41
|
+
/** Create the unsigned-tx export payload that starts a signing request (workflow entry point). */
|
|
75
42
|
createSigningRequest(buildId, unsignedTxCbor, txBodyHash, network, message, options) {
|
|
76
43
|
const signingRequestId = cds_1.default.utils.uuid();
|
|
77
44
|
const now = new Date();
|
|
@@ -97,9 +64,7 @@ class ExternalSignerModule {
|
|
|
97
64
|
}, 'Created signing request');
|
|
98
65
|
return payload;
|
|
99
66
|
}
|
|
100
|
-
/**
|
|
101
|
-
* Generate signing instructions for different signer types
|
|
102
|
-
*/
|
|
67
|
+
/** Signing instructions for the different signer types (CIP-30 request + cardano-cli recipe). */
|
|
103
68
|
generateSigningInstructions(unsignedTxCbor, network, message, signerTypeHint) {
|
|
104
69
|
return {
|
|
105
70
|
signerTypeHint,
|
|
@@ -112,20 +77,9 @@ class ExternalSignerModule {
|
|
|
112
77
|
cardanoCliCommand: buildCardanoCliCommand(network, unsignedTxCbor),
|
|
113
78
|
};
|
|
114
79
|
}
|
|
115
|
-
/**
|
|
116
|
-
* Verify a signed transaction
|
|
117
|
-
*
|
|
118
|
-
* Call this after receiving a signed transaction from an external signer.
|
|
119
|
-
* This verifies the signature integrity before submission.
|
|
120
|
-
*
|
|
121
|
-
* @param signedTxCbor - The signed transaction CBOR
|
|
122
|
-
* @param expectedTxBodyHash - The expected transaction body hash (from the build)
|
|
123
|
-
* @param options - Additional verification options
|
|
124
|
-
* @returns Verification result
|
|
125
|
-
*/
|
|
80
|
+
/** Verify a signed tx against the build's body hash; enforces the signing TTL when `expiresAt` is given. */
|
|
126
81
|
verifySignedTransaction(signedTxCbor, expectedTxBodyHash, options) {
|
|
127
82
|
logger.debug({ expectedTxBodyHash }, 'Verifying signed transaction');
|
|
128
|
-
// Enforce signing TTL if expiresAt is provided
|
|
129
83
|
if (options?.expiresAt && this.isExpired(options.expiresAt)) {
|
|
130
84
|
return {
|
|
131
85
|
isValid: false,
|
|
@@ -156,14 +110,7 @@ class ExternalSignerModule {
|
|
|
156
110
|
}
|
|
157
111
|
return result;
|
|
158
112
|
}
|
|
159
|
-
/**
|
|
160
|
-
* Verify signed transaction and throw on failure
|
|
161
|
-
*
|
|
162
|
-
* @param signedTxCbor - The signed transaction CBOR
|
|
163
|
-
* @param expectedTxBodyHash - The expected transaction body hash
|
|
164
|
-
* @param options - Additional verification options
|
|
165
|
-
* @throws {TransactionValidationError} if verification fails
|
|
166
|
-
*/
|
|
113
|
+
/** Like verifySignedTransaction, but throws TransactionValidationError on failure. */
|
|
167
114
|
verifyOrThrow(signedTxCbor, expectedTxBodyHash, options) {
|
|
168
115
|
const result = this.verifySignedTransaction(signedTxCbor, expectedTxBodyHash, options);
|
|
169
116
|
if (!result.isValid) {
|
|
@@ -171,35 +118,21 @@ class ExternalSignerModule {
|
|
|
171
118
|
}
|
|
172
119
|
return result;
|
|
173
120
|
}
|
|
174
|
-
/**
|
|
175
|
-
* Create a complete signing workflow state
|
|
176
|
-
*
|
|
177
|
-
* This creates a trackable workflow state that can be stored
|
|
178
|
-
* and updated throughout the signing process.
|
|
179
|
-
*
|
|
180
|
-
* @param signingRequest - The unsigned transaction export payload
|
|
181
|
-
* @returns Initial workflow state
|
|
182
|
-
*/
|
|
121
|
+
/** Initial (pending) workflow state for a signing request. */
|
|
183
122
|
createWorkflowState(signingRequest) {
|
|
184
123
|
return {
|
|
185
|
-
status:
|
|
124
|
+
status: 'pending',
|
|
186
125
|
request: signingRequest,
|
|
187
126
|
timestamps: {
|
|
188
127
|
created: signingRequest.createdAt,
|
|
189
128
|
},
|
|
190
129
|
};
|
|
191
130
|
}
|
|
192
|
-
/**
|
|
193
|
-
* Update workflow state after signing
|
|
194
|
-
*
|
|
195
|
-
* @param state - Current workflow state
|
|
196
|
-
* @param signedTxCbor - The signed transaction CBOR
|
|
197
|
-
* @returns Updated workflow state
|
|
198
|
-
*/
|
|
131
|
+
/** Workflow state → signed. */
|
|
199
132
|
markAsSigned(state, signedTxCbor) {
|
|
200
133
|
return {
|
|
201
134
|
...state,
|
|
202
|
-
status:
|
|
135
|
+
status: 'signed',
|
|
203
136
|
signedTxCbor,
|
|
204
137
|
timestamps: {
|
|
205
138
|
...state.timestamps,
|
|
@@ -207,20 +140,14 @@ class ExternalSignerModule {
|
|
|
207
140
|
},
|
|
208
141
|
};
|
|
209
142
|
}
|
|
210
|
-
/**
|
|
211
|
-
* Update workflow state after verification
|
|
212
|
-
*
|
|
213
|
-
* @param state - Current workflow state
|
|
214
|
-
* @param verificationResult - The verification result
|
|
215
|
-
* @returns Updated workflow state
|
|
216
|
-
*/
|
|
143
|
+
/** Workflow state → verified, or → failed when the verification result is invalid. */
|
|
217
144
|
markAsVerified(state, verificationResult) {
|
|
218
145
|
if (!verificationResult.isValid) {
|
|
219
146
|
return this.markAsFailed(state, String(verificationResult.errorMessage));
|
|
220
147
|
}
|
|
221
148
|
return {
|
|
222
149
|
...state,
|
|
223
|
-
status:
|
|
150
|
+
status: 'verified',
|
|
224
151
|
verificationResult,
|
|
225
152
|
timestamps: {
|
|
226
153
|
...state.timestamps,
|
|
@@ -228,17 +155,11 @@ class ExternalSignerModule {
|
|
|
228
155
|
},
|
|
229
156
|
};
|
|
230
157
|
}
|
|
231
|
-
/**
|
|
232
|
-
* Update workflow state after submission
|
|
233
|
-
*
|
|
234
|
-
* @param state - Current workflow state
|
|
235
|
-
* @param txHash - The submitted transaction hash
|
|
236
|
-
* @returns Updated workflow state
|
|
237
|
-
*/
|
|
158
|
+
/** Workflow state → submitted. */
|
|
238
159
|
markAsSubmitted(state, txHash) {
|
|
239
160
|
return {
|
|
240
161
|
...state,
|
|
241
|
-
status:
|
|
162
|
+
status: 'submitted',
|
|
242
163
|
txHash,
|
|
243
164
|
timestamps: {
|
|
244
165
|
...state.timestamps,
|
|
@@ -246,17 +167,11 @@ class ExternalSignerModule {
|
|
|
246
167
|
},
|
|
247
168
|
};
|
|
248
169
|
}
|
|
249
|
-
/**
|
|
250
|
-
* Update workflow state on failure
|
|
251
|
-
*
|
|
252
|
-
* @param state - Current workflow state
|
|
253
|
-
* @param errorMessage - The error message
|
|
254
|
-
* @returns Updated workflow state
|
|
255
|
-
*/
|
|
170
|
+
/** Workflow state → failed. */
|
|
256
171
|
markAsFailed(state, errorMessage) {
|
|
257
172
|
return {
|
|
258
173
|
...state,
|
|
259
|
-
status:
|
|
174
|
+
status: 'failed',
|
|
260
175
|
errorMessage,
|
|
261
176
|
timestamps: {
|
|
262
177
|
...state.timestamps,
|
|
@@ -264,30 +179,12 @@ class ExternalSignerModule {
|
|
|
264
179
|
},
|
|
265
180
|
};
|
|
266
181
|
}
|
|
267
|
-
/**
|
|
268
|
-
* Check if a signing request has expired
|
|
269
|
-
*
|
|
270
|
-
* @param expiresAt - The expiration timestamp (ISO 8601)
|
|
271
|
-
* @returns true if expired
|
|
272
|
-
*/
|
|
182
|
+
/** True when the ISO-8601 `expiresAt` lies in the past. */
|
|
273
183
|
isExpired(expiresAt) {
|
|
274
184
|
return new Date(expiresAt) < new Date();
|
|
275
185
|
}
|
|
276
|
-
/**
|
|
277
|
-
* Validate a signed transaction payload before submission
|
|
278
|
-
*
|
|
279
|
-
* This performs all pre-submission checks:
|
|
280
|
-
* 1. Verify the signature
|
|
281
|
-
* 2. Check transaction hasn't been tampered with
|
|
282
|
-
* 3. Ensure the build ID matches
|
|
283
|
-
*
|
|
284
|
-
* @param payload - The signed transaction payload
|
|
285
|
-
* @param originalBuildTxBodyHash - The original transaction body hash from the build
|
|
286
|
-
* @returns Validation result with verification details
|
|
287
|
-
* @throws {TransactionValidationError} if validation fails
|
|
288
|
-
*/
|
|
186
|
+
/** Pre-submission check: signature + body-hash integrity against the build; throws TransactionValidationError. */
|
|
289
187
|
validateForSubmission(payload, originalBuildTxBodyHash) {
|
|
290
|
-
// Verify the signature and transaction integrity
|
|
291
188
|
const result = this.verifyOrThrow(payload.signedTxCbor, originalBuildTxBodyHash);
|
|
292
189
|
logger.info({
|
|
293
190
|
signingRequestId: payload.signingRequestId,
|
|
@@ -297,9 +194,7 @@ class ExternalSignerModule {
|
|
|
297
194
|
}, 'Transaction validated for submission');
|
|
298
195
|
return result;
|
|
299
196
|
}
|
|
300
|
-
/**
|
|
301
|
-
* Get the signature verifier instance
|
|
302
|
-
*/
|
|
197
|
+
/** The underlying signature verifier. */
|
|
303
198
|
getVerifier() {
|
|
304
199
|
return this.verifier;
|
|
305
200
|
}
|
|
@@ -307,18 +202,14 @@ class ExternalSignerModule {
|
|
|
307
202
|
exports.ExternalSignerModule = ExternalSignerModule;
|
|
308
203
|
// Singleton instance
|
|
309
204
|
let moduleInstance = null;
|
|
310
|
-
/**
|
|
311
|
-
* Get the singleton ExternalSignerModule instance
|
|
312
|
-
*/
|
|
205
|
+
/** Singleton ExternalSignerModule. */
|
|
313
206
|
function getExternalSignerModule() {
|
|
314
207
|
if (!moduleInstance) {
|
|
315
208
|
moduleInstance = new ExternalSignerModule();
|
|
316
209
|
}
|
|
317
210
|
return moduleInstance;
|
|
318
211
|
}
|
|
319
|
-
/**
|
|
320
|
-
* Create a new ExternalSignerModule instance with custom options
|
|
321
|
-
*/
|
|
212
|
+
/** New ExternalSignerModule with custom options (not the singleton). */
|
|
322
213
|
function createExternalSignerModule(options) {
|
|
323
214
|
return new ExternalSignerModule(options);
|
|
324
215
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type PresenceIndexer, type TransactionLookup } from '../transaction-presence';
|
|
2
|
+
import type { CardanoIndexer } from '../cardano-indexer';
|
|
3
|
+
export interface FailedRecheckProgress {
|
|
4
|
+
submissions: number;
|
|
5
|
+
requests: number;
|
|
6
|
+
jobs: number;
|
|
7
|
+
restored: number;
|
|
8
|
+
}
|
|
9
|
+
export interface FailedRecheckDeps {
|
|
10
|
+
indexer: PresenceIndexer & Pick<CardanoIndexer, 'indexVerifiedTransactionSubmission'>;
|
|
11
|
+
client: TransactionLookup;
|
|
12
|
+
}
|
|
13
|
+
export declare function recheckFailed(deps: FailedRecheckDeps, opts?: {
|
|
14
|
+
shouldStop?: () => boolean;
|
|
15
|
+
onProgress?: (p: FailedRecheckProgress) => void;
|
|
16
|
+
}): Promise<FailedRecheckProgress>;
|
|
17
|
+
//# sourceMappingURL=failed-recheck.d.ts.map
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.recheckFailed = recheckFailed;
|
|
7
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
8
|
+
const cardano_1 = require("#cds-models/odatano/cardano");
|
|
9
|
+
const tx_utils_1 = require("../../utils/tx-utils");
|
|
10
|
+
const transaction_presence_1 = require("../transaction-presence");
|
|
11
|
+
const external_signer_1 = require("./external-signer");
|
|
12
|
+
const job_store_1 = require("../wallet-worker/job-store");
|
|
13
|
+
const { SELECT, UPDATE } = cds_1.default.ql;
|
|
14
|
+
const logger = cds_1.default.log('FailedRecheck');
|
|
15
|
+
const SIGNING_REQUESTS = 'odatano.cardano.SigningRequests';
|
|
16
|
+
const PAGE = 200;
|
|
17
|
+
function note(slot) {
|
|
18
|
+
return `re-checked at ${new Date().toISOString()}: on chain${slot != null ? ` at slot ${slot}` : ''}`;
|
|
19
|
+
}
|
|
20
|
+
// Where the chain holds the transaction with passing scripts, or null. A crawled row that cannot tell
|
|
21
|
+
// whether its scripts passed asks a backend that can; without such an answer the row stays failed.
|
|
22
|
+
async function onChainWithPassingScripts(deps, txHash) {
|
|
23
|
+
try {
|
|
24
|
+
let presence = await (0, transaction_presence_1.findOnChain)(deps.indexer, deps.client, txHash);
|
|
25
|
+
if (presence && !presence.validityKnown && deps.client.supports('getTransaction')) {
|
|
26
|
+
const found = await deps.client.getTransaction(txHash);
|
|
27
|
+
presence = { slot: presence.slot, height: presence.height, scriptFailed: found.spendsCollaterals === true, validityKnown: typeof found.spendsCollaterals === 'boolean' };
|
|
28
|
+
}
|
|
29
|
+
return presence && presence.validityKnown && !presence.scriptFailed ? { slot: presence.slot } : null;
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
logger.debug({ txHash, error: err instanceof Error ? err.message : String(err) }, 'Lookup gave no answer; the row stays failed');
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Ids after `after`, in id order, from one page. */
|
|
37
|
+
async function page(read, after) {
|
|
38
|
+
return (0, tx_utils_1.runWithoutAmbientTx)(() => cds_1.default.tx((db) => read(db, after)));
|
|
39
|
+
}
|
|
40
|
+
async function recheckFailed(deps, opts = {}) {
|
|
41
|
+
const progress = { submissions: 0, requests: 0, jobs: 0, restored: 0 };
|
|
42
|
+
for (let after = '';;) {
|
|
43
|
+
if (opts.shouldStop?.())
|
|
44
|
+
return progress;
|
|
45
|
+
const rows = await page((db, a) => db.run(SELECT.from(cardano_1.TransactionSubmissions).columns('id', 'txHash')
|
|
46
|
+
.where({ status: 'failed', id: { '>': a } }).orderBy('id').limit(PAGE)), after);
|
|
47
|
+
if (!rows.length)
|
|
48
|
+
break;
|
|
49
|
+
after = rows[rows.length - 1].id;
|
|
50
|
+
for (const row of rows) {
|
|
51
|
+
progress.submissions++;
|
|
52
|
+
const found = await onChainWithPassingScripts(deps, row.txHash);
|
|
53
|
+
if (!found)
|
|
54
|
+
continue;
|
|
55
|
+
const moved = await (0, tx_utils_1.runWithoutAmbientTx)(() => cds_1.default.tx((db) => db.run(UPDATE.entity(cardano_1.TransactionSubmissions)
|
|
56
|
+
.set({ status: 'submitted', errorMessage: null, resolution: note(found.slot) }).where({ id: row.id, status: 'failed' }))));
|
|
57
|
+
if (Number(moved) > 0) {
|
|
58
|
+
progress.restored++;
|
|
59
|
+
logger.warn({ submissionId: row.id, txHash: row.txHash }, 'Failed submission is on chain; moved back to submitted');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
opts.onProgress?.({ ...progress });
|
|
63
|
+
}
|
|
64
|
+
for (let after = '';;) {
|
|
65
|
+
if (opts.shouldStop?.())
|
|
66
|
+
return progress;
|
|
67
|
+
const rows = await page((db, a) => db.run(SELECT.from(SIGNING_REQUESTS)
|
|
68
|
+
.columns('id', 'build_id', 'txBodyHash', 'signedTxCbor', 'signerType', 'signerInfo', 'submission_id')
|
|
69
|
+
.where({ status: 'failed', id: { '>': a } }).and('signedTxCbor is not null').orderBy('id').limit(PAGE)), after);
|
|
70
|
+
if (!rows.length)
|
|
71
|
+
break;
|
|
72
|
+
after = rows[rows.length - 1].id;
|
|
73
|
+
for (const row of rows) {
|
|
74
|
+
progress.requests++;
|
|
75
|
+
const found = await onChainWithPassingScripts(deps, row.txBodyHash);
|
|
76
|
+
if (!found)
|
|
77
|
+
continue;
|
|
78
|
+
try {
|
|
79
|
+
const moved = await (0, tx_utils_1.runWithoutAmbientTx)(() => cds_1.default.tx(async (db) => {
|
|
80
|
+
const won = await db.run(UPDATE.entity(SIGNING_REQUESTS)
|
|
81
|
+
.set({ status: 'submitted', errorMessage: null, resolution: note(found.slot) }).where({ id: row.id, status: 'failed' }));
|
|
82
|
+
if (Number(won) === 0 || row.submission_id || !row.build_id)
|
|
83
|
+
return Number(won) > 0;
|
|
84
|
+
// the submission record a submit writes, from the stored bytes
|
|
85
|
+
await deps.indexer.indexVerifiedTransactionSubmission(db, {
|
|
86
|
+
signingRequestId: row.id, buildId: row.build_id, fullSignedTxCbor: row.signedTxCbor, txHash: row.txBodyHash,
|
|
87
|
+
verificationResult: (0, external_signer_1.getExternalSignerModule)().verifyOrThrow(row.signedTxCbor, row.txBodyHash),
|
|
88
|
+
signerType: row.signerType ?? undefined, signerInfo: row.signerInfo ?? undefined,
|
|
89
|
+
});
|
|
90
|
+
return true;
|
|
91
|
+
}));
|
|
92
|
+
if (moved) {
|
|
93
|
+
progress.restored++;
|
|
94
|
+
logger.warn({ signingRequestId: row.id, txHash: row.txBodyHash }, 'Failed signing request is on chain; moved back to submitted');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
logger.error({ err, signingRequestId: row.id }, 'Failed signing request is on chain but could not be restored');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
opts.onProgress?.({ ...progress });
|
|
102
|
+
}
|
|
103
|
+
// Jobs failed on time or a refusal alone. Back to submitted, the tracker confirms them by depth,
|
|
104
|
+
// and their submission row follows.
|
|
105
|
+
for (let after = '';;) {
|
|
106
|
+
if (opts.shouldStop?.())
|
|
107
|
+
return progress;
|
|
108
|
+
const rows = await page((db, a) => db.run(SELECT.from(cardano_1.CardanoWalletJobs).columns('ID as id', 'txHash')
|
|
109
|
+
.where({ status: 'failed', errorCode: { in: [job_store_1.JOB_ERROR_CODES.TX_DROPPED, job_store_1.JOB_ERROR_CODES.SUBMIT_REJECTED] }, ID: { '>': a } })
|
|
110
|
+
.and('txHash is not null').orderBy('ID').limit(PAGE)), after);
|
|
111
|
+
if (!rows.length)
|
|
112
|
+
break;
|
|
113
|
+
after = rows[rows.length - 1].id;
|
|
114
|
+
for (const row of rows) {
|
|
115
|
+
progress.jobs++;
|
|
116
|
+
const found = await onChainWithPassingScripts(deps, row.txHash);
|
|
117
|
+
if (!found)
|
|
118
|
+
continue;
|
|
119
|
+
const moved = await (0, tx_utils_1.runWithoutAmbientTx)(() => cds_1.default.tx(async (db) => {
|
|
120
|
+
if (!(await (0, job_store_1.reopenFailedJob)(db, row.id, note(found.slot))))
|
|
121
|
+
return false;
|
|
122
|
+
await db.run(UPDATE.entity(cardano_1.TransactionSubmissions).set({ status: 'submitted', errorMessage: null, resolution: note(found.slot) })
|
|
123
|
+
.where({ txHash: row.txHash, status: 'failed' }));
|
|
124
|
+
return true;
|
|
125
|
+
}));
|
|
126
|
+
if (moved) {
|
|
127
|
+
progress.restored++;
|
|
128
|
+
logger.warn({ jobId: row.id, txHash: row.txHash }, 'Failed wallet job is on chain; moved back to submitted');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
opts.onProgress?.({ ...progress });
|
|
132
|
+
}
|
|
133
|
+
return progress;
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=failed-recheck.js.map
|
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
import { HsmConfig, HsmSignResult } from '../../utils/types';
|
|
2
|
-
/**
|
|
3
|
-
* HsmSigner - PKCS#11 Hardware Security Module integration for Cardano transaction signing
|
|
4
|
-
*
|
|
5
|
-
* Wraps a PKCS#11 compliant HSM (YubiHSM 2, AWS CloudHSM, Thales Luna, etc.)
|
|
6
|
-
* to provide Ed25519 signing for Cardano transactions. Private keys never leave
|
|
7
|
-
* the HSM chip — only signatures are returned.
|
|
8
|
-
*
|
|
9
|
-
* Lifecycle:
|
|
10
|
-
* 1. constructor(config) — stores config
|
|
11
|
-
* 2. init(network) — connects to HSM, locates key, exports public key, derives Cardano address
|
|
12
|
-
* 3. sign() / signTransaction() — signing operations
|
|
13
|
-
* 4. shutdown() — closes session
|
|
14
|
-
*/
|
|
15
|
-
/** Minimal PKCS#11 module surface used here. Loaded dynamically; no static type
|
|
16
|
-
* package is depended on. We narrow to the actual handful of methods invoked. */
|
|
2
|
+
/** Minimal PKCS#11 surface used here; pkcs11js is loaded dynamically, no static type package. */
|
|
17
3
|
interface PKCS11Instance {
|
|
18
4
|
load(path: string): void;
|
|
19
5
|
C_Initialize(): void;
|
|
@@ -43,6 +29,7 @@ type Pkcs11JsModule = {
|
|
|
43
29
|
type Pkcs11Loader = () => Pkcs11JsModule;
|
|
44
30
|
/** Test seam: inject a fake pkcs11js module loader (null restores the default). */
|
|
45
31
|
export declare function setPkcs11Loader(loader: Pkcs11Loader | null): void;
|
|
32
|
+
/** Ed25519 signing through a PKCS#11 HSM. Private keys never leave the device. */
|
|
46
33
|
export declare class HsmSigner {
|
|
47
34
|
private pkcs11;
|
|
48
35
|
private session;
|
|
@@ -53,32 +40,11 @@ export declare class HsmSigner {
|
|
|
53
40
|
private config;
|
|
54
41
|
private connected;
|
|
55
42
|
constructor(config: HsmConfig);
|
|
56
|
-
/**
|
|
57
|
-
* Initialize PKCS#11 session and locate the signing key.
|
|
58
|
-
* Called once during plugin startup.
|
|
59
|
-
*
|
|
60
|
-
* @param network - Cardano network (mainnet, preview, preprod) for address derivation
|
|
61
|
-
*/
|
|
43
|
+
/** Opens the session, exports the public key and derives the enterprise address. */
|
|
62
44
|
init(network: 'mainnet' | 'preview' | 'preprod' | string): Promise<void>;
|
|
63
|
-
/**
|
|
64
|
-
* Sign a 32-byte transaction body hash using the HSM.
|
|
65
|
-
* Returns the Ed25519 signature + public key for witness construction.
|
|
66
|
-
*
|
|
67
|
-
* @param txBodyHash - 32-byte hash of the transaction body
|
|
68
|
-
* @returns HsmSignResult with signature, public key, and key hash
|
|
69
|
-
*/
|
|
45
|
+
/** Sign a 32-byte tx body hash in the HSM; returns Ed25519 signature + public key for the witness. */
|
|
70
46
|
sign(txBodyHash: Buffer): HsmSignResult;
|
|
71
|
-
/**
|
|
72
|
-
* Sign a transaction and produce a complete signed transaction CBOR.
|
|
73
|
-
*
|
|
74
|
-
* Takes the unsigned transaction CBOR, signs the body hash via HSM,
|
|
75
|
-
* builds a VKey witness [publicKey, signature], and merges it into
|
|
76
|
-
* the transaction's witness set using raw CBOR manipulation.
|
|
77
|
-
*
|
|
78
|
-
* @param unsignedTxCbor - Unsigned transaction CBOR (hex)
|
|
79
|
-
* @param txBodyHash - Transaction body hash (hex, 64 chars)
|
|
80
|
-
* @returns Signed transaction CBOR (hex)
|
|
81
|
-
*/
|
|
47
|
+
/** Signs the body hash and splices the VKey witness in at the raw CBOR level. */
|
|
82
48
|
signTransaction(unsignedTxCbor: string, txBodyHash: string): string;
|
|
83
49
|
/** Get the HSM-derived Cardano enterprise address */
|
|
84
50
|
getAddress(): string;
|
|
@@ -94,26 +60,16 @@ export declare class HsmSigner {
|
|
|
94
60
|
publicKeyHash?: string;
|
|
95
61
|
address?: string;
|
|
96
62
|
};
|
|
97
|
-
/**
|
|
63
|
+
/** Closes the PKCS#11 session. */
|
|
98
64
|
shutdown(): void;
|
|
99
|
-
/**
|
|
100
|
-
* Find a key object (private or public) in the HSM by label and/or ID
|
|
101
|
-
*/
|
|
65
|
+
/** Finds an Ed25519 key object in the HSM by label or ID. */
|
|
102
66
|
private _findKey;
|
|
103
|
-
/**
|
|
104
|
-
* Export the Ed25519 public key from the HSM.
|
|
105
|
-
* Handles both DER-wrapped (04 20 <32 bytes>) and raw 32-byte formats.
|
|
106
|
-
*/
|
|
67
|
+
/** Accepts a DER-wrapped and a raw 32-byte Ed25519 public key. */
|
|
107
68
|
private _exportPublicKey;
|
|
108
69
|
}
|
|
109
|
-
/**
|
|
110
|
-
* Get the initialized HsmSigner instance.
|
|
111
|
-
* Returns null if HSM is not configured.
|
|
112
|
-
*/
|
|
70
|
+
/** The initialized HsmSigner, or null when HSM is not configured. */
|
|
113
71
|
export declare function getHsmSigner(): HsmSigner | null;
|
|
114
|
-
/**
|
|
115
|
-
* Set the HsmSigner instance (called during initialization and shutdown).
|
|
116
|
-
*/
|
|
72
|
+
/** Set the HsmSigner instance (initialization and shutdown). */
|
|
117
73
|
export declare function setHsmSigner(signer: HsmSigner | null): void;
|
|
118
74
|
export {};
|
|
119
75
|
//# sourceMappingURL=hsm-signer.d.ts.map
|