@odatano/core 2.0.0-rc.4 → 2.0.0-rc.40
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 +251 -0
- package/@cds-models/CardanoAgentService/index.js +36 -0
- package/@cds-models/CardanoBackendService/index.d.ts +357 -0
- package/@cds-models/CardanoBackendService/index.js +40 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +194 -2
- package/@cds-models/CardanoIndexerService/index.js +25 -0
- package/@cds-models/CardanoODataService/index.d.ts +305 -7
- package/@cds-models/CardanoODataService/index.js +34 -0
- package/@cds-models/CardanoSignService/index.d.ts +28 -3
- package/@cds-models/CardanoSignService/index.js +3 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +46 -13
- package/@cds-models/CardanoTransactionService/index.js +4 -0
- package/@cds-models/index.d.ts +72 -0
- package/@cds-models/index.js +12 -0
- package/@cds-models/odatano/cardano/index.d.ts +408 -7
- package/@cds-models/odatano/cardano/index.js +42 -0
- package/README.md +64 -5
- package/db/schema.cds +2297 -1633
- package/db/types.cds +114 -0
- package/package.json +27 -6
- package/scripts/migrate-slot-leader.mjs +104 -0
- package/scripts/migrate-txseq.mjs +147 -0
- package/src/index.d.ts +18 -11
- package/src/index.js +44 -14
- package/src/plugin.js +42 -52
- package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
- package/srv/blockchain/backends/blockfrost-backend.js +53 -162
- package/srv/blockchain/backends/cardano-backend.d.ts +104 -158
- package/srv/blockchain/backends/cardano-backend.js +19 -5
- package/srv/blockchain/backends/koios-backend.d.ts +126 -60
- package/srv/blockchain/backends/koios-backend.js +376 -235
- package/srv/blockchain/backends/odatano-backend.d.ts +64 -0
- package/srv/blockchain/backends/odatano-backend.js +170 -0
- package/srv/blockchain/backends/ogmios-backend.d.ts +162 -94
- package/srv/blockchain/backends/ogmios-backend.js +556 -201
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +32 -0
- package/srv/blockchain/backends/ogmios-frame-guard.js +142 -0
- package/srv/blockchain/cardano-client.d.ts +87 -202
- package/srv/blockchain/cardano-client.js +210 -240
- package/srv/blockchain/cardano-indexer.d.ts +311 -242
- package/srv/blockchain/cardano-indexer.js +1238 -362
- package/srv/blockchain/cardano-tx-builder.d.ts +44 -81
- package/srv/blockchain/cardano-tx-builder.js +173 -132
- package/srv/blockchain/crawler/certificate-backfill.d.ts +67 -0
- package/srv/blockchain/crawler/certificate-backfill.js +169 -0
- package/srv/blockchain/crawler/crawler.d.ts +139 -54
- package/srv/blockchain/crawler/crawler.js +478 -96
- package/srv/blockchain/crawler/hooks.d.ts +3 -14
- package/srv/blockchain/crawler/index.d.ts +5 -0
- package/srv/blockchain/crawler/index.js +35 -7
- package/srv/blockchain/crawler/sync-state.d.ts +46 -28
- package/srv/blockchain/crawler/sync-state.js +128 -43
- package/srv/blockchain/crawler/transaction-backfill.d.ts +52 -0
- package/srv/blockchain/crawler/transaction-backfill.js +283 -0
- package/srv/blockchain/crawler/utxo-set-import.d.ts +78 -0
- package/srv/blockchain/crawler/utxo-set-import.js +363 -0
- package/srv/blockchain/ledger-state.d.ts +101 -0
- package/srv/blockchain/ledger-state.js +432 -0
- package/srv/blockchain/pending-spends.d.ts +28 -0
- package/srv/blockchain/pending-spends.js +89 -0
- package/srv/blockchain/signing/cose-verifier.d.ts +5 -12
- package/srv/blockchain/signing/cose-verifier.js +6 -12
- package/srv/blockchain/signing/external-signer.d.ts +16 -113
- package/srv/blockchain/signing/external-signer.js +19 -122
- package/srv/blockchain/signing/hsm-signer.d.ts +13 -45
- package/srv/blockchain/signing/hsm-signer.js +23 -63
- package/srv/blockchain/signing/signature-verifier.d.ts +14 -45
- package/srv/blockchain/signing/signature-verifier.js +73 -76
- package/srv/blockchain/signing/submission-finalizer.d.ts +9 -36
- package/srv/blockchain/signing/submission-finalizer.js +16 -49
- package/srv/blockchain/stored-chain.d.ts +33 -0
- package/srv/blockchain/stored-chain.js +234 -0
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +111 -173
- package/srv/blockchain/transaction-building/buildooor-tx.js +649 -326
- package/srv/blockchain/transaction-building/caller-datums.d.ts +29 -0
- package/srv/blockchain/transaction-building/caller-datums.js +139 -0
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +10 -35
- package/srv/blockchain/transaction-rows.d.ts +12 -0
- package/srv/blockchain/transaction-rows.js +43 -0
- package/srv/blockchain/wallet-worker/build-request.d.ts +4 -17
- package/srv/blockchain/wallet-worker/build-request.js +18 -23
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +25 -17
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +87 -41
- package/srv/blockchain/wallet-worker/index.js +2 -8
- package/srv/blockchain/wallet-worker/job-store.d.ts +36 -103
- package/srv/blockchain/wallet-worker/job-store.js +0 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +4 -20
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +4 -20
- package/srv/blockchain/wallet-worker/signers.d.ts +6 -19
- package/srv/blockchain/wallet-worker/signers.js +3 -8
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +15 -71
- package/srv/blockchain/wallet-worker/wallet-worker.js +40 -91
- package/srv/cardano-agent-service.cds +146 -0
- package/srv/cardano-agent-service.d.ts +2 -0
- package/srv/cardano-agent-service.js +12 -0
- package/srv/cardano-backend-service.cds +52 -0
- package/srv/cardano-backend-service.d.ts +2 -0
- package/srv/cardano-backend-service.js +244 -0
- package/srv/cardano-indexer-service.cds +201 -73
- package/srv/cardano-indexer-service.js +280 -11
- package/srv/cardano-service.cds +65 -2
- package/srv/cardano-service.js +170 -129
- package/srv/cardano-sign-service.cds +200 -180
- package/srv/cardano-sign-service.js +57 -184
- package/srv/cardano-tx-service.cds +439 -370
- package/srv/cardano-tx-service.js +231 -190
- package/srv/cardano-ui.cds +16 -16
- package/srv/cardano-worker-service.js +7 -15
- package/srv/cbor/index.d.ts +1 -1
- package/srv/cbor/parse.d.ts +27 -0
- package/srv/cbor/parse.js +63 -2
- package/srv/server.d.ts +28 -86
- package/srv/server.js +132 -135
- package/srv/utils/agent-grants-config.d.ts +37 -0
- package/srv/utils/agent-grants-config.js +138 -0
- package/srv/utils/agent-grants.d.ts +262 -0
- package/srv/utils/agent-grants.js +922 -0
- package/srv/utils/agent-token-auth.d.ts +16 -0
- package/srv/utils/agent-token-auth.js +78 -0
- package/srv/utils/backend-request-handler.d.ts +2 -16
- package/srv/utils/backend-request-handler.js +3 -18
- package/srv/utils/collections.d.ts +4 -8
- package/srv/utils/collections.js +4 -8
- package/srv/utils/const.d.ts +30 -67
- package/srv/utils/const.js +32 -72
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +5 -18
- package/srv/utils/db-indexes.d.ts +25 -0
- package/srv/utils/db-indexes.js +94 -0
- package/srv/utils/db-sanitize.d.ts +27 -0
- package/srv/utils/db-sanitize.js +85 -0
- package/srv/utils/epoch-slots.d.ts +20 -0
- package/srv/utils/epoch-slots.js +43 -0
- package/srv/utils/error-codes.d.ts +20 -73
- package/srv/utils/error-codes.js +19 -70
- package/srv/utils/errors.d.ts +50 -177
- package/srv/utils/errors.js +94 -218
- package/srv/utils/legacy-service-paths.d.ts +11 -0
- package/srv/utils/legacy-service-paths.js +58 -0
- package/srv/utils/liveness.d.ts +16 -0
- package/srv/utils/liveness.js +40 -0
- package/srv/utils/mappers.d.ts +128 -214
- package/srv/utils/mappers.js +354 -299
- package/srv/utils/network-context.js +2 -11
- package/srv/utils/pg-inline-json.d.ts +8 -0
- package/srv/utils/pg-inline-json.js +62 -0
- package/srv/utils/pg-order-nulls.d.ts +14 -0
- package/srv/utils/pg-order-nulls.js +56 -0
- package/srv/utils/plutus-placeholders.d.ts +23 -16
- package/srv/utils/plutus-placeholders.js +63 -27
- package/srv/utils/rate-limiter.d.ts +46 -0
- package/srv/utils/rate-limiter.js +116 -0
- package/srv/utils/service-events.d.ts +2 -22
- package/srv/utils/service-events.js +3 -23
- package/srv/utils/signing-helper.d.ts +6 -16
- package/srv/utils/signing-helper.js +36 -60
- package/srv/utils/tx-build-helper.d.ts +28 -93
- package/srv/utils/tx-build-helper.js +75 -124
- package/srv/utils/tx-request-parsers.d.ts +101 -28
- package/srv/utils/tx-request-parsers.js +410 -43
- package/srv/utils/tx-utils.d.ts +4 -23
- package/srv/utils/tx-utils.js +12 -41
- package/srv/utils/types.d.ts +252 -179
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +24 -90
- package/srv/utils/validators.js +50 -147
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
import { SignatureVerifier } from './signature-verifier';
|
|
2
2
|
import { ExternalSignerType, UnsignedTxExportPayload, SignedTxPayload, SigningWorkflowState, SignatureVerificationResult, VerificationOptions } from '../../utils/types';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* This module orchestrates the complete flow:
|
|
7
|
-
* 1. Create signing request from build result
|
|
8
|
-
* 2. Export unsigned transaction for external signing
|
|
9
|
-
* 3. Receive and verify signed transaction
|
|
10
|
-
* 4. Prepare for submission
|
|
11
|
-
*
|
|
12
|
-
* Key security principles:
|
|
13
|
-
* - NO private keys are ever handled by this service
|
|
14
|
-
* - Signature verification ensures transaction integrity
|
|
15
|
-
* - Complete audit trail of the signing workflow
|
|
4
|
+
* External signing workflow: create signing request → export unsigned tx → verify the
|
|
5
|
+
* signed tx → prepare submission. No private keys are ever handled here.
|
|
16
6
|
*/
|
|
17
7
|
export declare class ExternalSignerModule {
|
|
18
8
|
private verifier;
|
|
@@ -20,126 +10,39 @@ export declare class ExternalSignerModule {
|
|
|
20
10
|
constructor(options?: {
|
|
21
11
|
signingTtlMs?: number;
|
|
22
12
|
});
|
|
23
|
-
/**
|
|
24
|
-
* Create an unsigned transaction export payload for external signing
|
|
25
|
-
*
|
|
26
|
-
* This is the entry point for the external signing workflow.
|
|
27
|
-
* Call this after building a transaction to get a standardized
|
|
28
|
-
* payload that external signers can use.
|
|
29
|
-
*
|
|
30
|
-
* @param buildId - The build ID from TransactionBuilds
|
|
31
|
-
* @param unsignedTxCbor - The unsigned transaction CBOR
|
|
32
|
-
* @param txBodyHash - The transaction body hash
|
|
33
|
-
* @param network - The Cardano network
|
|
34
|
-
* @param options - Additional options
|
|
35
|
-
* @returns Unsigned transaction export payload
|
|
36
|
-
*/
|
|
13
|
+
/** Create the unsigned-tx export payload that starts a signing request (workflow entry point). */
|
|
37
14
|
createSigningRequest(buildId: string, unsignedTxCbor: string, txBodyHash: string, network: string, message: string, options?: {
|
|
38
15
|
requiredSigners?: string[];
|
|
39
16
|
signerTypeHint?: ExternalSignerType;
|
|
40
17
|
}): UnsignedTxExportPayload;
|
|
41
|
-
/**
|
|
42
|
-
* Generate signing instructions for different signer types
|
|
43
|
-
*/
|
|
18
|
+
/** Signing instructions for the different signer types (CIP-30 request + cardano-cli recipe). */
|
|
44
19
|
private generateSigningInstructions;
|
|
45
|
-
/**
|
|
46
|
-
* Verify a signed transaction
|
|
47
|
-
*
|
|
48
|
-
* Call this after receiving a signed transaction from an external signer.
|
|
49
|
-
* This verifies the signature integrity before submission.
|
|
50
|
-
*
|
|
51
|
-
* @param signedTxCbor - The signed transaction CBOR
|
|
52
|
-
* @param expectedTxBodyHash - The expected transaction body hash (from the build)
|
|
53
|
-
* @param options - Additional verification options
|
|
54
|
-
* @returns Verification result
|
|
55
|
-
*/
|
|
20
|
+
/** Verify a signed tx against the build's body hash; enforces the signing TTL when `expiresAt` is given. */
|
|
56
21
|
verifySignedTransaction(signedTxCbor: string, expectedTxBodyHash: string, options?: Omit<VerificationOptions, 'expectedTxBodyHash'> & {
|
|
57
22
|
expiresAt?: string;
|
|
58
23
|
}): SignatureVerificationResult;
|
|
59
|
-
/**
|
|
60
|
-
* Verify signed transaction and throw on failure
|
|
61
|
-
*
|
|
62
|
-
* @param signedTxCbor - The signed transaction CBOR
|
|
63
|
-
* @param expectedTxBodyHash - The expected transaction body hash
|
|
64
|
-
* @param options - Additional verification options
|
|
65
|
-
* @throws {TransactionValidationError} if verification fails
|
|
66
|
-
*/
|
|
24
|
+
/** Like verifySignedTransaction, but throws TransactionValidationError on failure. */
|
|
67
25
|
verifyOrThrow(signedTxCbor: string, expectedTxBodyHash: string, options?: Omit<VerificationOptions, 'expectedTxBodyHash'>): SignatureVerificationResult;
|
|
68
|
-
/**
|
|
69
|
-
* Create a complete signing workflow state
|
|
70
|
-
*
|
|
71
|
-
* This creates a trackable workflow state that can be stored
|
|
72
|
-
* and updated throughout the signing process.
|
|
73
|
-
*
|
|
74
|
-
* @param signingRequest - The unsigned transaction export payload
|
|
75
|
-
* @returns Initial workflow state
|
|
76
|
-
*/
|
|
26
|
+
/** Initial (pending) workflow state for a signing request. */
|
|
77
27
|
createWorkflowState(signingRequest: UnsignedTxExportPayload): SigningWorkflowState;
|
|
78
|
-
/**
|
|
79
|
-
* Update workflow state after signing
|
|
80
|
-
*
|
|
81
|
-
* @param state - Current workflow state
|
|
82
|
-
* @param signedTxCbor - The signed transaction CBOR
|
|
83
|
-
* @returns Updated workflow state
|
|
84
|
-
*/
|
|
28
|
+
/** Workflow state → signed. */
|
|
85
29
|
markAsSigned(state: SigningWorkflowState, signedTxCbor: string): SigningWorkflowState;
|
|
86
|
-
/**
|
|
87
|
-
* Update workflow state after verification
|
|
88
|
-
*
|
|
89
|
-
* @param state - Current workflow state
|
|
90
|
-
* @param verificationResult - The verification result
|
|
91
|
-
* @returns Updated workflow state
|
|
92
|
-
*/
|
|
30
|
+
/** Workflow state → verified, or → failed when the verification result is invalid. */
|
|
93
31
|
markAsVerified(state: SigningWorkflowState, verificationResult: SignatureVerificationResult): SigningWorkflowState;
|
|
94
|
-
/**
|
|
95
|
-
* Update workflow state after submission
|
|
96
|
-
*
|
|
97
|
-
* @param state - Current workflow state
|
|
98
|
-
* @param txHash - The submitted transaction hash
|
|
99
|
-
* @returns Updated workflow state
|
|
100
|
-
*/
|
|
32
|
+
/** Workflow state → submitted. */
|
|
101
33
|
markAsSubmitted(state: SigningWorkflowState, txHash: string): SigningWorkflowState;
|
|
102
|
-
/**
|
|
103
|
-
* Update workflow state on failure
|
|
104
|
-
*
|
|
105
|
-
* @param state - Current workflow state
|
|
106
|
-
* @param errorMessage - The error message
|
|
107
|
-
* @returns Updated workflow state
|
|
108
|
-
*/
|
|
34
|
+
/** Workflow state → failed. */
|
|
109
35
|
markAsFailed(state: SigningWorkflowState, errorMessage: string): SigningWorkflowState;
|
|
110
|
-
/**
|
|
111
|
-
* Check if a signing request has expired
|
|
112
|
-
*
|
|
113
|
-
* @param expiresAt - The expiration timestamp (ISO 8601)
|
|
114
|
-
* @returns true if expired
|
|
115
|
-
*/
|
|
36
|
+
/** True when the ISO-8601 `expiresAt` lies in the past. */
|
|
116
37
|
isExpired(expiresAt: string): boolean;
|
|
117
|
-
/**
|
|
118
|
-
* Validate a signed transaction payload before submission
|
|
119
|
-
*
|
|
120
|
-
* This performs all pre-submission checks:
|
|
121
|
-
* 1. Verify the signature
|
|
122
|
-
* 2. Check transaction hasn't been tampered with
|
|
123
|
-
* 3. Ensure the build ID matches
|
|
124
|
-
*
|
|
125
|
-
* @param payload - The signed transaction payload
|
|
126
|
-
* @param originalBuildTxBodyHash - The original transaction body hash from the build
|
|
127
|
-
* @returns Validation result with verification details
|
|
128
|
-
* @throws {TransactionValidationError} if validation fails
|
|
129
|
-
*/
|
|
38
|
+
/** Pre-submission check: signature + body-hash integrity against the build; throws TransactionValidationError. */
|
|
130
39
|
validateForSubmission(payload: SignedTxPayload, originalBuildTxBodyHash: string): SignatureVerificationResult;
|
|
131
|
-
/**
|
|
132
|
-
* Get the signature verifier instance
|
|
133
|
-
*/
|
|
40
|
+
/** The underlying signature verifier. */
|
|
134
41
|
getVerifier(): SignatureVerifier;
|
|
135
42
|
}
|
|
136
|
-
/**
|
|
137
|
-
* Get the singleton ExternalSignerModule instance
|
|
138
|
-
*/
|
|
43
|
+
/** Singleton ExternalSignerModule. */
|
|
139
44
|
export declare function getExternalSignerModule(): ExternalSignerModule;
|
|
140
|
-
/**
|
|
141
|
-
* Create a new ExternalSignerModule instance with custom options
|
|
142
|
-
*/
|
|
45
|
+
/** New ExternalSignerModule with custom options (not the singleton). */
|
|
143
46
|
export declare function createExternalSignerModule(options?: {
|
|
144
47
|
signingTtlMs?: number;
|
|
145
48
|
}): ExternalSignerModule;
|
|
@@ -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 = {
|
|
@@ -22,10 +20,8 @@ const CLI_NETWORK_FLAG = {
|
|
|
22
20
|
preview: '--testnet-magic 2',
|
|
23
21
|
};
|
|
24
22
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* and the unsigned CBOR are filled in. Previously this was always NULL despite
|
|
28
|
-
* the schema exposing a `cardanoCliCommand` field.
|
|
23
|
+
* Copy-pasteable cardano-cli signing recipe for the unsigned tx (network flag and CBOR
|
|
24
|
+
* filled in; the caller supplies the signing key file).
|
|
29
25
|
*/
|
|
30
26
|
function buildCardanoCliCommand(network, unsignedTxCbor) {
|
|
31
27
|
const netFlag = CLI_NETWORK_FLAG[network] ?? '--testnet-magic <MAGIC>';
|
|
@@ -38,18 +34,8 @@ function buildCardanoCliCommand(network, unsignedTxCbor) {
|
|
|
38
34
|
].join('\n');
|
|
39
35
|
}
|
|
40
36
|
/**
|
|
41
|
-
*
|
|
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
|
|
37
|
+
* External signing workflow: create signing request → export unsigned tx → verify the
|
|
38
|
+
* signed tx → prepare submission. No private keys are ever handled here.
|
|
53
39
|
*/
|
|
54
40
|
class ExternalSignerModule {
|
|
55
41
|
verifier;
|
|
@@ -58,20 +44,7 @@ class ExternalSignerModule {
|
|
|
58
44
|
this.verifier = (0, signature_verifier_1.getSignatureVerifier)();
|
|
59
45
|
this.signingTtlMs = options?.signingTtlMs ?? DEFAULT_SIGNING_TTL_MS;
|
|
60
46
|
}
|
|
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
|
-
*/
|
|
47
|
+
/** Create the unsigned-tx export payload that starts a signing request (workflow entry point). */
|
|
75
48
|
createSigningRequest(buildId, unsignedTxCbor, txBodyHash, network, message, options) {
|
|
76
49
|
const signingRequestId = cds_1.default.utils.uuid();
|
|
77
50
|
const now = new Date();
|
|
@@ -97,9 +70,7 @@ class ExternalSignerModule {
|
|
|
97
70
|
}, 'Created signing request');
|
|
98
71
|
return payload;
|
|
99
72
|
}
|
|
100
|
-
/**
|
|
101
|
-
* Generate signing instructions for different signer types
|
|
102
|
-
*/
|
|
73
|
+
/** Signing instructions for the different signer types (CIP-30 request + cardano-cli recipe). */
|
|
103
74
|
generateSigningInstructions(unsignedTxCbor, network, message, signerTypeHint) {
|
|
104
75
|
return {
|
|
105
76
|
signerTypeHint,
|
|
@@ -112,20 +83,9 @@ class ExternalSignerModule {
|
|
|
112
83
|
cardanoCliCommand: buildCardanoCliCommand(network, unsignedTxCbor),
|
|
113
84
|
};
|
|
114
85
|
}
|
|
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
|
-
*/
|
|
86
|
+
/** Verify a signed tx against the build's body hash; enforces the signing TTL when `expiresAt` is given. */
|
|
126
87
|
verifySignedTransaction(signedTxCbor, expectedTxBodyHash, options) {
|
|
127
88
|
logger.debug({ expectedTxBodyHash }, 'Verifying signed transaction');
|
|
128
|
-
// Enforce signing TTL if expiresAt is provided
|
|
129
89
|
if (options?.expiresAt && this.isExpired(options.expiresAt)) {
|
|
130
90
|
return {
|
|
131
91
|
isValid: false,
|
|
@@ -156,14 +116,7 @@ class ExternalSignerModule {
|
|
|
156
116
|
}
|
|
157
117
|
return result;
|
|
158
118
|
}
|
|
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
|
-
*/
|
|
119
|
+
/** Like verifySignedTransaction, but throws TransactionValidationError on failure. */
|
|
167
120
|
verifyOrThrow(signedTxCbor, expectedTxBodyHash, options) {
|
|
168
121
|
const result = this.verifySignedTransaction(signedTxCbor, expectedTxBodyHash, options);
|
|
169
122
|
if (!result.isValid) {
|
|
@@ -171,15 +124,7 @@ class ExternalSignerModule {
|
|
|
171
124
|
}
|
|
172
125
|
return result;
|
|
173
126
|
}
|
|
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
|
-
*/
|
|
127
|
+
/** Initial (pending) workflow state for a signing request. */
|
|
183
128
|
createWorkflowState(signingRequest) {
|
|
184
129
|
return {
|
|
185
130
|
status: types_1.SigningStatus.PENDING,
|
|
@@ -189,13 +134,7 @@ class ExternalSignerModule {
|
|
|
189
134
|
},
|
|
190
135
|
};
|
|
191
136
|
}
|
|
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
|
-
*/
|
|
137
|
+
/** Workflow state → signed. */
|
|
199
138
|
markAsSigned(state, signedTxCbor) {
|
|
200
139
|
return {
|
|
201
140
|
...state,
|
|
@@ -207,13 +146,7 @@ class ExternalSignerModule {
|
|
|
207
146
|
},
|
|
208
147
|
};
|
|
209
148
|
}
|
|
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
|
-
*/
|
|
149
|
+
/** Workflow state → verified, or → failed when the verification result is invalid. */
|
|
217
150
|
markAsVerified(state, verificationResult) {
|
|
218
151
|
if (!verificationResult.isValid) {
|
|
219
152
|
return this.markAsFailed(state, String(verificationResult.errorMessage));
|
|
@@ -228,13 +161,7 @@ class ExternalSignerModule {
|
|
|
228
161
|
},
|
|
229
162
|
};
|
|
230
163
|
}
|
|
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
|
-
*/
|
|
164
|
+
/** Workflow state → submitted. */
|
|
238
165
|
markAsSubmitted(state, txHash) {
|
|
239
166
|
return {
|
|
240
167
|
...state,
|
|
@@ -246,13 +173,7 @@ class ExternalSignerModule {
|
|
|
246
173
|
},
|
|
247
174
|
};
|
|
248
175
|
}
|
|
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
|
-
*/
|
|
176
|
+
/** Workflow state → failed. */
|
|
256
177
|
markAsFailed(state, errorMessage) {
|
|
257
178
|
return {
|
|
258
179
|
...state,
|
|
@@ -264,30 +185,12 @@ class ExternalSignerModule {
|
|
|
264
185
|
},
|
|
265
186
|
};
|
|
266
187
|
}
|
|
267
|
-
/**
|
|
268
|
-
* Check if a signing request has expired
|
|
269
|
-
*
|
|
270
|
-
* @param expiresAt - The expiration timestamp (ISO 8601)
|
|
271
|
-
* @returns true if expired
|
|
272
|
-
*/
|
|
188
|
+
/** True when the ISO-8601 `expiresAt` lies in the past. */
|
|
273
189
|
isExpired(expiresAt) {
|
|
274
190
|
return new Date(expiresAt) < new Date();
|
|
275
191
|
}
|
|
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
|
-
*/
|
|
192
|
+
/** Pre-submission check: signature + body-hash integrity against the build; throws TransactionValidationError. */
|
|
289
193
|
validateForSubmission(payload, originalBuildTxBodyHash) {
|
|
290
|
-
// Verify the signature and transaction integrity
|
|
291
194
|
const result = this.verifyOrThrow(payload.signedTxCbor, originalBuildTxBodyHash);
|
|
292
195
|
logger.info({
|
|
293
196
|
signingRequestId: payload.signingRequestId,
|
|
@@ -297,9 +200,7 @@ class ExternalSignerModule {
|
|
|
297
200
|
}, 'Transaction validated for submission');
|
|
298
201
|
return result;
|
|
299
202
|
}
|
|
300
|
-
/**
|
|
301
|
-
* Get the signature verifier instance
|
|
302
|
-
*/
|
|
203
|
+
/** The underlying signature verifier. */
|
|
303
204
|
getVerifier() {
|
|
304
205
|
return this.verifier;
|
|
305
206
|
}
|
|
@@ -307,18 +208,14 @@ class ExternalSignerModule {
|
|
|
307
208
|
exports.ExternalSignerModule = ExternalSignerModule;
|
|
308
209
|
// Singleton instance
|
|
309
210
|
let moduleInstance = null;
|
|
310
|
-
/**
|
|
311
|
-
* Get the singleton ExternalSignerModule instance
|
|
312
|
-
*/
|
|
211
|
+
/** Singleton ExternalSignerModule. */
|
|
313
212
|
function getExternalSignerModule() {
|
|
314
213
|
if (!moduleInstance) {
|
|
315
214
|
moduleInstance = new ExternalSignerModule();
|
|
316
215
|
}
|
|
317
216
|
return moduleInstance;
|
|
318
217
|
}
|
|
319
|
-
/**
|
|
320
|
-
* Create a new ExternalSignerModule instance with custom options
|
|
321
|
-
*/
|
|
218
|
+
/** New ExternalSignerModule with custom options (not the singleton). */
|
|
322
219
|
function createExternalSignerModule(options) {
|
|
323
220
|
return new ExternalSignerModule(options);
|
|
324
221
|
}
|
|
@@ -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,10 @@ 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
|
+
/**
|
|
33
|
+
* Ed25519 transaction signing through a PKCS#11 HSM (YubiHSM 2, CloudHSM, Luna, …); private
|
|
34
|
+
* keys never leave the device. Lifecycle: init(network) → sign()/signTransaction() → shutdown().
|
|
35
|
+
*/
|
|
46
36
|
export declare class HsmSigner {
|
|
47
37
|
private pkcs11;
|
|
48
38
|
private session;
|
|
@@ -54,30 +44,15 @@ export declare class HsmSigner {
|
|
|
54
44
|
private connected;
|
|
55
45
|
constructor(config: HsmConfig);
|
|
56
46
|
/**
|
|
57
|
-
*
|
|
58
|
-
* Called once
|
|
59
|
-
*
|
|
60
|
-
* @param network - Cardano network (mainnet, preview, preprod) for address derivation
|
|
47
|
+
* Open the PKCS#11 session, locate the key, export the public key and derive the
|
|
48
|
+
* enterprise address for `network`. Called once at startup.
|
|
61
49
|
*/
|
|
62
50
|
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
|
-
*/
|
|
51
|
+
/** Sign a 32-byte tx body hash in the HSM; returns Ed25519 signature + public key for the witness. */
|
|
70
52
|
sign(txBodyHash: Buffer): HsmSignResult;
|
|
71
53
|
/**
|
|
72
|
-
* Sign
|
|
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)
|
|
54
|
+
* Sign the body hash (hex) in the HSM, build the VKey witness [publicKey, signature] and
|
|
55
|
+
* splice it into the witness set at the raw CBOR level. Returns the signed tx CBOR (hex).
|
|
81
56
|
*/
|
|
82
57
|
signTransaction(unsignedTxCbor: string, txBodyHash: string): string;
|
|
83
58
|
/** Get the HSM-derived Cardano enterprise address */
|
|
@@ -96,9 +71,7 @@ export declare class HsmSigner {
|
|
|
96
71
|
};
|
|
97
72
|
/** Graceful shutdown — close PKCS#11 session */
|
|
98
73
|
shutdown(): void;
|
|
99
|
-
/**
|
|
100
|
-
* Find a key object (private or public) in the HSM by label and/or ID
|
|
101
|
-
*/
|
|
74
|
+
/** Find an Ed25519 key object (private or public) in the HSM by label and/or ID. */
|
|
102
75
|
private _findKey;
|
|
103
76
|
/**
|
|
104
77
|
* Export the Ed25519 public key from the HSM.
|
|
@@ -106,14 +79,9 @@ export declare class HsmSigner {
|
|
|
106
79
|
*/
|
|
107
80
|
private _exportPublicKey;
|
|
108
81
|
}
|
|
109
|
-
/**
|
|
110
|
-
* Get the initialized HsmSigner instance.
|
|
111
|
-
* Returns null if HSM is not configured.
|
|
112
|
-
*/
|
|
82
|
+
/** The initialized HsmSigner, or null when HSM is not configured. */
|
|
113
83
|
export declare function getHsmSigner(): HsmSigner | null;
|
|
114
|
-
/**
|
|
115
|
-
* Set the HsmSigner instance (called during initialization and shutdown).
|
|
116
|
-
*/
|
|
84
|
+
/** Set the HsmSigner instance (initialization and shutdown). */
|
|
117
85
|
export declare function setHsmSigner(signer: HsmSigner | null): void;
|
|
118
86
|
export {};
|
|
119
87
|
//# sourceMappingURL=hsm-signer.d.ts.map
|