@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
|
@@ -9,14 +9,14 @@ exports.getHsmSigner = getHsmSigner;
|
|
|
9
9
|
exports.setHsmSigner = setHsmSigner;
|
|
10
10
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
11
11
|
const errors_1 = require("../../utils/errors");
|
|
12
|
+
const config_1 = require("../../config");
|
|
12
13
|
const error_codes_1 = require("../../utils/error-codes");
|
|
13
14
|
const cbor_1 = require("@harmoniclabs/cbor");
|
|
14
15
|
const uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
|
|
16
|
+
const blake2b_1 = __importDefault(require("blake2b"));
|
|
17
|
+
const bech32_1 = require("bech32");
|
|
15
18
|
const logger = cds_1.default.log('HsmSigner');
|
|
16
|
-
/**
|
|
17
|
-
* CKM_EDDSA mechanism ID (PKCS#11 v3.0)
|
|
18
|
-
* Used for Ed25519 signing operations
|
|
19
|
-
*/
|
|
19
|
+
/** CKM_EDDSA mechanism ID (PKCS#11 v3.0) for Ed25519 signing. */
|
|
20
20
|
const CKM_EDDSA = 0x00001057;
|
|
21
21
|
const defaultPkcs11Loader = () => require('pkcs11js');
|
|
22
22
|
let pkcs11Loader = defaultPkcs11Loader;
|
|
@@ -24,6 +24,7 @@ let pkcs11Loader = defaultPkcs11Loader;
|
|
|
24
24
|
function setPkcs11Loader(loader) {
|
|
25
25
|
pkcs11Loader = loader ?? defaultPkcs11Loader;
|
|
26
26
|
}
|
|
27
|
+
/** Ed25519 signing through a PKCS#11 HSM. Private keys never leave the device. */
|
|
27
28
|
class HsmSigner {
|
|
28
29
|
pkcs11;
|
|
29
30
|
session;
|
|
@@ -36,14 +37,9 @@ class HsmSigner {
|
|
|
36
37
|
constructor(config) {
|
|
37
38
|
this.config = config;
|
|
38
39
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Initialize PKCS#11 session and locate the signing key.
|
|
41
|
-
* Called once during plugin startup.
|
|
42
|
-
*
|
|
43
|
-
* @param network - Cardano network (mainnet, preview, preprod) for address derivation
|
|
44
|
-
*/
|
|
40
|
+
/** Opens the session, exports the public key and derives the enterprise address. */
|
|
45
41
|
async init(network) {
|
|
46
|
-
//
|
|
42
|
+
// pkcs11js is only loaded when HSM is configured
|
|
47
43
|
let pkcs11js;
|
|
48
44
|
try {
|
|
49
45
|
pkcs11js = pkcs11Loader();
|
|
@@ -53,61 +49,49 @@ class HsmSigner {
|
|
|
53
49
|
}
|
|
54
50
|
this.pkcs11 = new pkcs11js.PKCS11();
|
|
55
51
|
try {
|
|
56
|
-
// 1. Load PKCS#11 module
|
|
57
52
|
this.pkcs11.load(this.config.pkcs11Module);
|
|
58
53
|
this.pkcs11.C_Initialize();
|
|
59
54
|
logger.info({ module: this.config.pkcs11Module }, 'PKCS#11 module loaded');
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
// returned by C_GetSlotList(true), NOT the PKCS#11 slot ID (which need not be
|
|
63
|
-
// contiguous or zero-based). Configure it as a position, not a hardware slot id.
|
|
55
|
+
// `config.slot` is the 0-based index into C_GetSlotList(true) (slots with a token),
|
|
56
|
+
// not the PKCS#11 slot ID, which need not be contiguous or zero-based.
|
|
64
57
|
const slots = this.pkcs11.C_GetSlotList(true);
|
|
65
58
|
if (this.config.slot >= slots.length) {
|
|
66
59
|
throw new errors_1.HsmError(`HSM slot index ${this.config.slot} not found. ${slots.length} slot(s) with a token present (valid indices 0..${slots.length - 1}).`, 503, error_codes_1.ERROR_CODES.HSM_UNAVAILABLE);
|
|
67
60
|
}
|
|
68
61
|
this.session = this.pkcs11.C_OpenSession(slots[this.config.slot], pkcs11js.CKF_SERIAL_SESSION | pkcs11js.CKF_RW_SESSION);
|
|
69
62
|
logger.debug({ slot: this.config.slot }, 'PKCS#11 session opened');
|
|
70
|
-
// 3. Login with PIN
|
|
71
63
|
try {
|
|
72
64
|
this.pkcs11.C_Login(this.session, pkcs11js.CKU_USER, this.config.pin);
|
|
73
65
|
}
|
|
74
66
|
finally {
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
// - this.config (shared reference with the server-side hsmConfigInstance
|
|
78
|
-
// singleton) — mutate IN PLACE, not reassign, so the singleton clears too
|
|
79
|
-
// - the HSM_PIN environment variable
|
|
80
|
-
// - the CAP config (cds.env.requires['odatano-core'].hsm.pin)
|
|
67
|
+
// Clear the PIN everywhere it could linger, whatever the login outcome.
|
|
68
|
+
// The config object is shared with the server singleton, so it is changed in place.
|
|
81
69
|
this.config.pin = '';
|
|
82
70
|
if (process.env.HSM_PIN)
|
|
83
71
|
delete process.env.HSM_PIN;
|
|
84
72
|
try {
|
|
85
|
-
const hsmCds =
|
|
73
|
+
const hsmCds = (0, config_1.coreCdsConfig)().hsm;
|
|
86
74
|
if (hsmCds && 'pin' in hsmCds)
|
|
87
75
|
hsmCds.pin = '';
|
|
88
76
|
}
|
|
89
77
|
catch { /* best effort */ }
|
|
90
78
|
}
|
|
91
79
|
logger.debug('PKCS#11 login successful');
|
|
92
|
-
// 4. Find private key by label or ID
|
|
93
80
|
this.privateKeyHandle = this._findKey(pkcs11js, pkcs11js.CKO_PRIVATE_KEY);
|
|
94
|
-
// 5. Export public key
|
|
95
81
|
this.publicKeyBytes = this._exportPublicKey(pkcs11js);
|
|
96
82
|
logger.debug({ publicKeyLength: this.publicKeyBytes.length }, 'Ed25519 public key exported');
|
|
97
|
-
//
|
|
98
|
-
const blake2b = require('blake2b');
|
|
83
|
+
// Key hash = blake2b-224 of the public key
|
|
99
84
|
const hashOut = Buffer.alloc(28);
|
|
100
|
-
|
|
85
|
+
(0, blake2b_1.default)(28).update(this.publicKeyBytes).digest(hashOut);
|
|
101
86
|
this.publicKeyHashHex = hashOut.toString('hex');
|
|
102
87
|
// Enterprise key-hash address: header 0x61 (mainnet) or 0x60 (testnet)
|
|
103
|
-
const { bech32 } = require('bech32');
|
|
104
88
|
const headerByte = network === 'mainnet' ? 0x61 : 0x60;
|
|
105
89
|
const payload = Buffer.alloc(29);
|
|
106
90
|
payload[0] = headerByte;
|
|
107
91
|
hashOut.copy(payload, 1);
|
|
108
|
-
const words = bech32.toWords(payload);
|
|
92
|
+
const words = bech32_1.bech32.toWords(payload);
|
|
109
93
|
const hrp = network === 'mainnet' ? 'addr' : 'addr_test';
|
|
110
|
-
this.cardanoAddress = bech32.encode(hrp, words, 120);
|
|
94
|
+
this.cardanoAddress = bech32_1.bech32.encode(hrp, words, 120);
|
|
111
95
|
this.connected = true;
|
|
112
96
|
logger.info({
|
|
113
97
|
keyLabel: this.config.keyLabel,
|
|
@@ -124,19 +108,12 @@ class HsmSigner {
|
|
|
124
108
|
throw new errors_1.HsmError(`Failed to initialize HSM: ${msg}`, 503, error_codes_1.ERROR_CODES.HSM_UNAVAILABLE, err);
|
|
125
109
|
}
|
|
126
110
|
}
|
|
127
|
-
/**
|
|
128
|
-
* Sign a 32-byte transaction body hash using the HSM.
|
|
129
|
-
* Returns the Ed25519 signature + public key for witness construction.
|
|
130
|
-
*
|
|
131
|
-
* @param txBodyHash - 32-byte hash of the transaction body
|
|
132
|
-
* @returns HsmSignResult with signature, public key, and key hash
|
|
133
|
-
*/
|
|
111
|
+
/** Sign a 32-byte tx body hash in the HSM; returns Ed25519 signature + public key for the witness. */
|
|
134
112
|
sign(txBodyHash) {
|
|
135
113
|
if (!this.connected) {
|
|
136
114
|
throw new errors_1.HsmError('HSM not connected', 503, error_codes_1.ERROR_CODES.HSM_UNAVAILABLE);
|
|
137
115
|
}
|
|
138
116
|
try {
|
|
139
|
-
// CKM_EDDSA = Ed25519 signing mechanism
|
|
140
117
|
this.pkcs11.C_SignInit(this.session, { mechanism: CKM_EDDSA }, this.privateKeyHandle);
|
|
141
118
|
const signature = this.pkcs11.C_Sign(this.session, txBodyHash, Buffer.alloc(64));
|
|
142
119
|
return {
|
|
@@ -150,22 +127,11 @@ class HsmSigner {
|
|
|
150
127
|
throw new errors_1.HsmError(`HSM signing failed: ${msg}`, 500, error_codes_1.ERROR_CODES.HSM_SIGNING_FAILED, err);
|
|
151
128
|
}
|
|
152
129
|
}
|
|
153
|
-
/**
|
|
154
|
-
* Sign a transaction and produce a complete signed transaction CBOR.
|
|
155
|
-
*
|
|
156
|
-
* Takes the unsigned transaction CBOR, signs the body hash via HSM,
|
|
157
|
-
* builds a VKey witness [publicKey, signature], and merges it into
|
|
158
|
-
* the transaction's witness set using raw CBOR manipulation.
|
|
159
|
-
*
|
|
160
|
-
* @param unsignedTxCbor - Unsigned transaction CBOR (hex)
|
|
161
|
-
* @param txBodyHash - Transaction body hash (hex, 64 chars)
|
|
162
|
-
* @returns Signed transaction CBOR (hex)
|
|
163
|
-
*/
|
|
130
|
+
/** Signs the body hash and splices the VKey witness in at the raw CBOR level. */
|
|
164
131
|
signTransaction(unsignedTxCbor, txBodyHash) {
|
|
165
132
|
const hashBytes = Buffer.from(txBodyHash, 'hex');
|
|
166
133
|
const result = this.sign(hashBytes);
|
|
167
134
|
try {
|
|
168
|
-
// Parse unsigned transaction at raw CBOR level
|
|
169
135
|
const txObj = cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(unsignedTxCbor));
|
|
170
136
|
if (!(txObj instanceof cbor_1.CborArray) || txObj.array.length < 2) {
|
|
171
137
|
throw new errors_1.HsmError('Invalid transaction CBOR structure', 400, error_codes_1.ERROR_CODES.HSM_SIGNING_FAILED);
|
|
@@ -175,13 +141,10 @@ class HsmSigner {
|
|
|
175
141
|
new cbor_1.CborBytes(Buffer.from(result.publicKeyHex, 'hex')),
|
|
176
142
|
new cbor_1.CborBytes(Buffer.from(result.signatureHex, 'hex')),
|
|
177
143
|
]);
|
|
178
|
-
//
|
|
179
|
-
//
|
|
180
|
-
// Multi-sig (e.g. wallet + HSM) uses combineTransactionWithWitnesses() instead.
|
|
144
|
+
// The HSM witness replaces all vkey witnesses, since it signs alone. Other keys are kept.
|
|
145
|
+
// Multi-sig goes through combineTransactionWithWitnesses().
|
|
181
146
|
const origWs = txObj.array[1];
|
|
182
147
|
if (origWs instanceof cbor_1.CborMap) {
|
|
183
|
-
// Replace VKey witnesses (key 0) with HSM witness only
|
|
184
|
-
// Preserves all other entries (redeemers key 5, datums key 4, scripts keys 1-3, 6-7)
|
|
185
148
|
const entries = origWs.map.filter((e) => !(e.k instanceof cbor_1.CborUInt && Number(e.k.num) === 0));
|
|
186
149
|
entries.push({
|
|
187
150
|
k: new cbor_1.CborUInt(0),
|
|
@@ -230,7 +193,7 @@ class HsmSigner {
|
|
|
230
193
|
address: this.connected ? this.cardanoAddress : undefined,
|
|
231
194
|
};
|
|
232
195
|
}
|
|
233
|
-
/**
|
|
196
|
+
/** Closes the PKCS#11 session. */
|
|
234
197
|
shutdown() {
|
|
235
198
|
if (this.session) {
|
|
236
199
|
try {
|
|
@@ -249,14 +212,12 @@ class HsmSigner {
|
|
|
249
212
|
// ---------------------------------------------------------------------------
|
|
250
213
|
// Private helpers
|
|
251
214
|
// ---------------------------------------------------------------------------
|
|
252
|
-
/**
|
|
253
|
-
* Find a key object (private or public) in the HSM by label and/or ID
|
|
254
|
-
*/
|
|
215
|
+
/** Finds an Ed25519 key object in the HSM by label or ID. */
|
|
255
216
|
_findKey(pkcs11js, objectClass) {
|
|
256
217
|
const template = [
|
|
257
218
|
{ type: pkcs11js.CKA_CLASS, value: objectClass },
|
|
258
219
|
];
|
|
259
|
-
// CKK_EC_EDWARDS
|
|
220
|
+
// CKK_EC_EDWARDS is PKCS#11 v3.0 and may be missing in older pkcs11js versions.
|
|
260
221
|
const CKK_EC_EDWARDS = pkcs11js.CKK_EC_EDWARDS ?? 0x00000040;
|
|
261
222
|
template.push({ type: pkcs11js.CKA_KEY_TYPE, value: CKK_EC_EDWARDS });
|
|
262
223
|
if (this.config.keyLabel) {
|
|
@@ -274,18 +235,13 @@ class HsmSigner {
|
|
|
274
235
|
}
|
|
275
236
|
return handles[0];
|
|
276
237
|
}
|
|
277
|
-
/**
|
|
278
|
-
* Export the Ed25519 public key from the HSM.
|
|
279
|
-
* Handles both DER-wrapped (04 20 <32 bytes>) and raw 32-byte formats.
|
|
280
|
-
*/
|
|
238
|
+
/** Accepts a DER-wrapped and a raw 32-byte Ed25519 public key. */
|
|
281
239
|
_exportPublicKey(pkcs11js) {
|
|
282
240
|
const pubKeyHandle = this._findKey(pkcs11js, pkcs11js.CKO_PUBLIC_KEY);
|
|
283
|
-
// Extract CKA_EC_POINT (DER-encoded public key)
|
|
284
241
|
const attrs = this.pkcs11.C_GetAttributeValue(this.session, pubKeyHandle, [
|
|
285
242
|
{ type: pkcs11js.CKA_EC_POINT },
|
|
286
243
|
]);
|
|
287
|
-
// CKA_EC_POINT for Ed25519 is DER OCTET STRING
|
|
288
|
-
// Format: 04 20 <32 bytes>
|
|
244
|
+
// CKA_EC_POINT for Ed25519 is a DER OCTET STRING around the 32-byte key: 04 20 <32 bytes>
|
|
289
245
|
const ecPoint = Buffer.from(attrs[0].value);
|
|
290
246
|
if (ecPoint.length === 34 && ecPoint[0] === 0x04 && ecPoint[1] === 0x20) {
|
|
291
247
|
return ecPoint.slice(2);
|
|
@@ -298,20 +254,13 @@ class HsmSigner {
|
|
|
298
254
|
}
|
|
299
255
|
}
|
|
300
256
|
exports.HsmSigner = HsmSigner;
|
|
301
|
-
//
|
|
302
|
-
// Singleton pattern (same as getExternalSignerModule())
|
|
303
|
-
// ---------------------------------------------------------------------------
|
|
257
|
+
// Singleton instance
|
|
304
258
|
let hsmSignerInstance = null;
|
|
305
|
-
/**
|
|
306
|
-
* Get the initialized HsmSigner instance.
|
|
307
|
-
* Returns null if HSM is not configured.
|
|
308
|
-
*/
|
|
259
|
+
/** The initialized HsmSigner, or null when HSM is not configured. */
|
|
309
260
|
function getHsmSigner() {
|
|
310
261
|
return hsmSignerInstance;
|
|
311
262
|
}
|
|
312
|
-
/**
|
|
313
|
-
* Set the HsmSigner instance (called during initialization and shutdown).
|
|
314
|
-
*/
|
|
263
|
+
/** Set the HsmSigner instance (initialization and shutdown). */
|
|
315
264
|
function setHsmSigner(signer) {
|
|
316
265
|
hsmSignerInstance = signer;
|
|
317
266
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type PresenceIndexer, type TransactionLookup } from '../transaction-presence';
|
|
2
|
+
import type { CardanoClient, Network } from '../cardano-client';
|
|
3
|
+
/** Slots an indexer may lag the node; added to the horizon when the ledger read came from one. */
|
|
4
|
+
export declare const PROVIDER_LAG_SLOTS = 3600;
|
|
5
|
+
/** Slots past its expiry after which a transaction can no longer land on the chain the node follows. */
|
|
6
|
+
export declare function settleSlots(network: Network): number;
|
|
7
|
+
export type LandingClient = TransactionLookup & Pick<CardanoClient, 'network' | 'isUtxoUnspent' | 'readLedger'>;
|
|
8
|
+
export type LandingIndexer = PresenceIndexer;
|
|
9
|
+
export type LandingVerdict = {
|
|
10
|
+
verdict: 'onChain';
|
|
11
|
+
} | {
|
|
12
|
+
verdict: 'scriptFailed';
|
|
13
|
+
reason: string;
|
|
14
|
+
} | {
|
|
15
|
+
verdict: 'neverLands';
|
|
16
|
+
reason: string;
|
|
17
|
+
} | {
|
|
18
|
+
verdict: 'unresolved';
|
|
19
|
+
reason: string;
|
|
20
|
+
} | {
|
|
21
|
+
verdict: 'stale';
|
|
22
|
+
reason: string;
|
|
23
|
+
unspentInputs: Array<{
|
|
24
|
+
txHash: string;
|
|
25
|
+
outputIndex: number;
|
|
26
|
+
}>;
|
|
27
|
+
} | {
|
|
28
|
+
verdict: 'open';
|
|
29
|
+
};
|
|
30
|
+
export declare function isFinalRefusal(err: unknown): boolean;
|
|
31
|
+
export interface LandingFacts {
|
|
32
|
+
ttlSlot: number | null;
|
|
33
|
+
inputs: Array<{
|
|
34
|
+
txHash: string;
|
|
35
|
+
outputIndex: number;
|
|
36
|
+
}>;
|
|
37
|
+
outputCount: number;
|
|
38
|
+
isValid: boolean;
|
|
39
|
+
collateralInputs: Array<{
|
|
40
|
+
txHash: string;
|
|
41
|
+
outputIndex: number;
|
|
42
|
+
}>;
|
|
43
|
+
hasCollateralReturn: boolean;
|
|
44
|
+
}
|
|
45
|
+
/** Expiry, inputs, outputs and collateral of a signed transaction. */
|
|
46
|
+
export declare function landingFacts(signedTxCbor: string): LandingFacts;
|
|
47
|
+
export declare function sendProblem(signedTxCbor: string, network: Network, nowMs?: number): string | null;
|
|
48
|
+
/** True once the expiry has passed by the wall clock: then no node accepts the bytes any more. */
|
|
49
|
+
export declare function isExpired(signedTxCbor: string, network: Network, nowMs?: number): boolean;
|
|
50
|
+
/** Own output indexes read for landing evidence: the last (the builder puts the change there), then the first. */
|
|
51
|
+
export declare function outputsToCheck(outputCount: number): number[];
|
|
52
|
+
/** True when one of the transaction's own outputs is unspent: then it landed with passing scripts. */
|
|
53
|
+
export declare function hasUnspentOutput(signedTxCbor: string, txHash: string, client: Pick<CardanoClient, 'isUtxoUnspent'>): Promise<boolean>;
|
|
54
|
+
/** Forgets what this process remembers about spent inputs; for tests. */
|
|
55
|
+
export declare function resetLandingMemory(): void;
|
|
56
|
+
export declare function judgeLanding(signedTxCbor: string, txHash: string, { indexer, client }: {
|
|
57
|
+
indexer: LandingIndexer;
|
|
58
|
+
client: LandingClient;
|
|
59
|
+
}, sentAtMs?: number | null, nowMs?: number): Promise<LandingVerdict>;
|
|
60
|
+
//# sourceMappingURL=landing-proof.d.ts.map
|
|
@@ -0,0 +1,224 @@
|
|
|
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.PROVIDER_LAG_SLOTS = void 0;
|
|
7
|
+
exports.settleSlots = settleSlots;
|
|
8
|
+
exports.isFinalRefusal = isFinalRefusal;
|
|
9
|
+
exports.landingFacts = landingFacts;
|
|
10
|
+
exports.sendProblem = sendProblem;
|
|
11
|
+
exports.isExpired = isExpired;
|
|
12
|
+
exports.outputsToCheck = outputsToCheck;
|
|
13
|
+
exports.hasUnspentOutput = hasUnspentOutput;
|
|
14
|
+
exports.resetLandingMemory = resetLandingMemory;
|
|
15
|
+
exports.judgeLanding = judgeLanding;
|
|
16
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
17
|
+
const errors_1 = require("../../utils/errors");
|
|
18
|
+
const tx_build_helper_1 = require("../../utils/tx-build-helper");
|
|
19
|
+
const const_1 = require("../../utils/const");
|
|
20
|
+
const epoch_slots_1 = require("../../utils/epoch-slots");
|
|
21
|
+
const transaction_presence_1 = require("../transaction-presence");
|
|
22
|
+
const logger = cds_1.default.log('LandingProof');
|
|
23
|
+
// On chain needs positive evidence: the crawled chain, a backend that returns it, an own output unspent.
|
|
24
|
+
// Never lands needs the tip past the expiry by the rollback horizon and an input still unspent. Past
|
|
25
|
+
// that point without either proof the outcome is unresolved, and an operator decides it.
|
|
26
|
+
/** Slots an indexer may lag the node; added to the horizon when the ledger read came from one. */
|
|
27
|
+
exports.PROVIDER_LAG_SLOTS = 3600;
|
|
28
|
+
/** Outputs of the transaction looked up to see whether it landed, besides the last one (the change). */
|
|
29
|
+
const OUTPUTS_CHECKED = 10;
|
|
30
|
+
/** Slots past its expiry after which a transaction can no longer land on the chain the node follows. */
|
|
31
|
+
function settleSlots(network) {
|
|
32
|
+
return (0, epoch_slots_1.rollbackHorizonSlots)(network);
|
|
33
|
+
}
|
|
34
|
+
// Ogmios refusals that hold for the bytes at any time and in any ledger state: bad or missing
|
|
35
|
+
// signatures, metadata, no inputs, wrong network, minted ada, boot address attributes, an input also
|
|
36
|
+
// a reference, a pointer address in the collateral return.
|
|
37
|
+
const FINAL_CODES = new Set([3100, 3101, 3105, 3106, 3107, 3108, 3121, 3124, 3126, 3127, 3164, 3169]);
|
|
38
|
+
// The same failures as the ledger names them in the refusal text of Blockfrost and Koios.
|
|
39
|
+
const FINAL_TEXT = /InvalidWitnessesUTXOW|MissingVKeyWitnessesUTXOW|MissingTxBodyMetadataHash|MissingTxMetadata|ConflictingMetadataHash|InvalidMetadata|InputSetEmptyUTxO|WrongNetwork|TriesToForgeADA|OutputBootAddrAttrsTooBig|NonDisjointRefInputs/;
|
|
40
|
+
/** The errors an error carries: itself, its originalError and the errors it collects. */
|
|
41
|
+
function errorTree(err, depth = 0) {
|
|
42
|
+
if (depth > 4 || err == null || typeof err !== 'object')
|
|
43
|
+
return err == null ? [] : [err];
|
|
44
|
+
const nested = [err.originalError, ...(err.errors ?? [])];
|
|
45
|
+
return [err, ...nested.flatMap((e) => (e == null ? [] : errorTree(e, depth + 1)))];
|
|
46
|
+
}
|
|
47
|
+
/** JSON-RPC codes of node refusals (3000-3999) anywhere in the error. */
|
|
48
|
+
function nodeRefusalCodes(err) {
|
|
49
|
+
return errorTree(err)
|
|
50
|
+
.map((e) => e.code)
|
|
51
|
+
.filter((c) => typeof c === 'number' && c >= 3000 && c < 4000);
|
|
52
|
+
}
|
|
53
|
+
function errorText(err) {
|
|
54
|
+
return errorTree(err).map((e) => (e instanceof Error ? e.message : typeof e === 'string' ? e : '')).join(' ');
|
|
55
|
+
}
|
|
56
|
+
// True when the refusal holds for these bytes whatever the ledger holds, so the transaction can never
|
|
57
|
+
// land. A refusal over inputs, the validity interval, fees, scripts or protocol parameters is no
|
|
58
|
+
// verdict: a resend of a transaction that already landed gets those too. An unknown refusal is none.
|
|
59
|
+
function isFinalRefusal(err) {
|
|
60
|
+
if (!(0, errors_1.isSubmitRejection)(err))
|
|
61
|
+
return false;
|
|
62
|
+
const codes = nodeRefusalCodes(err);
|
|
63
|
+
if (codes.length)
|
|
64
|
+
return codes.some((c) => FINAL_CODES.has(c));
|
|
65
|
+
return FINAL_TEXT.test(errorText(err));
|
|
66
|
+
}
|
|
67
|
+
/** Expiry, inputs, outputs and collateral of a signed transaction. */
|
|
68
|
+
function landingFacts(signedTxCbor) {
|
|
69
|
+
const t = (0, tx_build_helper_1.extractTxCacheTargets)(signedTxCbor);
|
|
70
|
+
return {
|
|
71
|
+
ttlSlot: t.ttlSlot ?? null,
|
|
72
|
+
inputs: t.inputs ?? [],
|
|
73
|
+
outputCount: t.outputCount ?? 0,
|
|
74
|
+
isValid: t.isValid !== false,
|
|
75
|
+
collateralInputs: t.collateralInputs ?? [],
|
|
76
|
+
hasCollateralReturn: t.hasCollateralReturn === true,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
// Why ODATANO will not send these bytes, or null. The expiry is what lets a send without an answer
|
|
80
|
+
// be decided, and the cap bounds how long a record or a wallet queue can stay open. Bytes marked to
|
|
81
|
+
// fail their scripts would only spend the collateral.
|
|
82
|
+
function sendProblem(signedTxCbor, network, nowMs = Date.now()) {
|
|
83
|
+
const { ttlSlot, isValid } = landingFacts(signedTxCbor);
|
|
84
|
+
if (!isValid)
|
|
85
|
+
return 'The transaction is marked to fail its scripts (isValid false); sending it would only spend its collateral';
|
|
86
|
+
if (ttlSlot === null)
|
|
87
|
+
return 'The transaction has no expiry (body key 3, TTL); set one, so its outcome can be decided';
|
|
88
|
+
// valid only while the slot is below the TTL
|
|
89
|
+
if (ttlSlot <= (0, epoch_slots_1.posixToSlot)(network, nowMs))
|
|
90
|
+
return `The transaction expired at slot ${ttlSlot}; no node accepts it any more`;
|
|
91
|
+
const latest = (0, epoch_slots_1.posixToSlot)(network, nowMs + const_1.MAX_VALIDITY_MS);
|
|
92
|
+
if (ttlSlot > latest)
|
|
93
|
+
return `The transaction expires at slot ${ttlSlot}, more than ${const_1.MAX_VALIDITY_MS / 3_600_000} hours ahead (latest slot ${latest})`;
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
/** True once the expiry has passed by the wall clock: then no node accepts the bytes any more. */
|
|
97
|
+
function isExpired(signedTxCbor, network, nowMs = Date.now()) {
|
|
98
|
+
let ttlSlot;
|
|
99
|
+
try {
|
|
100
|
+
ttlSlot = landingFacts(signedTxCbor).ttlSlot;
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return false; // unreadable bytes: the node answers for them
|
|
104
|
+
}
|
|
105
|
+
return ttlSlot !== null && (0, epoch_slots_1.posixToSlot)(network, nowMs) >= ttlSlot;
|
|
106
|
+
}
|
|
107
|
+
/** Own output indexes read for landing evidence: the last (the builder puts the change there), then the first. */
|
|
108
|
+
function outputsToCheck(outputCount) {
|
|
109
|
+
if (outputCount <= 0)
|
|
110
|
+
return [];
|
|
111
|
+
const first = Array.from({ length: Math.min(outputCount, OUTPUTS_CHECKED) }, (_, i) => i);
|
|
112
|
+
return [...new Set([outputCount - 1, ...first])];
|
|
113
|
+
}
|
|
114
|
+
/** True when one of the transaction's own outputs is unspent: then it landed with passing scripts. */
|
|
115
|
+
async function hasUnspentOutput(signedTxCbor, txHash, client) {
|
|
116
|
+
for (const i of outputsToCheck(landingFacts(signedTxCbor).outputCount)) {
|
|
117
|
+
if (await client.isUtxoUnspent(txHash, i))
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
// Tip slot at which inputs of a transaction without an expiry were first seen spent: some of them, or
|
|
123
|
+
// all. A spend counts once it is older than the rollback horizon, since a rollback could undo a younger one.
|
|
124
|
+
const someSpentSince = new Map();
|
|
125
|
+
const allSpentSince = new Map();
|
|
126
|
+
/** Forgets what this process remembers about spent inputs; for tests. */
|
|
127
|
+
function resetLandingMemory() {
|
|
128
|
+
someSpentSince.clear();
|
|
129
|
+
allSpentSince.clear();
|
|
130
|
+
}
|
|
131
|
+
/** The tip slot `seen` holds for a transaction, set to `tip` on the first look. */
|
|
132
|
+
function firstSeen(seen, txHash, tip) {
|
|
133
|
+
const since = seen.get(txHash);
|
|
134
|
+
if (since !== undefined)
|
|
135
|
+
return since;
|
|
136
|
+
seen.set(txHash, tip);
|
|
137
|
+
return tip;
|
|
138
|
+
}
|
|
139
|
+
// What an own output shows: on chain, landed with failing scripts (its collateral return, which the
|
|
140
|
+
// ledger puts after the outputs, is unspent), or nothing.
|
|
141
|
+
async function ownOutputEvidence(facts, signedTxCbor, txHash, client) {
|
|
142
|
+
if (await hasUnspentOutput(signedTxCbor, txHash, client))
|
|
143
|
+
return { verdict: 'onChain' };
|
|
144
|
+
if (facts.hasCollateralReturn && await client.isUtxoUnspent(txHash, facts.outputCount)) {
|
|
145
|
+
return { verdict: 'scriptFailed', reason: scriptFailedReason(txHash) };
|
|
146
|
+
}
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
function scriptFailedReason(txHash) {
|
|
150
|
+
return `Transaction ${txHash} is on chain with failing scripts: only its collateral was spent, the payment did not happen`;
|
|
151
|
+
}
|
|
152
|
+
// Reads the chain for a sent transaction. sentAtMs bounds a transaction without an expiry. A lookup
|
|
153
|
+
// that cannot answer proves nothing, and then nothing else decides either.
|
|
154
|
+
async function judgeLanding(signedTxCbor, txHash, { indexer, client }, sentAtMs = null, nowMs = Date.now()) {
|
|
155
|
+
try {
|
|
156
|
+
let presence;
|
|
157
|
+
try {
|
|
158
|
+
presence = await (0, transaction_presence_1.findOnChain)(indexer, client, txHash);
|
|
159
|
+
}
|
|
160
|
+
catch (lookupErr) {
|
|
161
|
+
logger.debug({ txHash, error: lookupErr instanceof Error ? lookupErr.message : String(lookupErr) }, 'Transaction lookup gave no answer');
|
|
162
|
+
return { verdict: 'open' };
|
|
163
|
+
}
|
|
164
|
+
if (presence)
|
|
165
|
+
return presence.scriptFailed ? { verdict: 'scriptFailed', reason: scriptFailedReason(txHash) } : { verdict: 'onChain' };
|
|
166
|
+
const facts = landingFacts(signedTxCbor);
|
|
167
|
+
const settle = settleSlots(client.network);
|
|
168
|
+
if (facts.ttlSlot === null)
|
|
169
|
+
return await judgeWithoutExpiry(facts, signedTxCbor, txHash, client, settle, sentAtMs, nowMs);
|
|
170
|
+
// the wall clock first, so no ledger read runs while the transaction may still land
|
|
171
|
+
if ((0, epoch_slots_1.posixToSlot)(client.network, nowMs) <= facts.ttlSlot + settle)
|
|
172
|
+
return { verdict: 'open' };
|
|
173
|
+
// tip, inputs and collateral from one source; an unknown outpoint is not unspent
|
|
174
|
+
const refs = [...facts.inputs, ...facts.collateralInputs];
|
|
175
|
+
const ledger = await client.readLedger(refs);
|
|
176
|
+
if (ledger.tip <= facts.ttlSlot + settle + (ledger.live ? 0 : exports.PROVIDER_LAG_SLOTS))
|
|
177
|
+
return { verdict: 'open' };
|
|
178
|
+
const own = await ownOutputEvidence(facts, signedTxCbor, txHash, client);
|
|
179
|
+
if (own)
|
|
180
|
+
return own;
|
|
181
|
+
// a landing spends every input, or with failing scripts every collateral input
|
|
182
|
+
const inputUnspent = ledger.unspent.slice(0, facts.inputs.length).includes(true);
|
|
183
|
+
const collateralUnspent = facts.collateralInputs.length === 0 || ledger.unspent.slice(facts.inputs.length).includes(true);
|
|
184
|
+
if (inputUnspent && collateralUnspent) {
|
|
185
|
+
return { verdict: 'neverLands', reason: `Transaction ${txHash} expired at slot ${facts.ttlSlot} and an input it spends is still unspent (tip ${ledger.tip})` };
|
|
186
|
+
}
|
|
187
|
+
return { verdict: 'unresolved', reason: `Transaction ${txHash} expired at slot ${facts.ttlSlot}; its inputs are spent and nothing shows whether by this transaction` };
|
|
188
|
+
}
|
|
189
|
+
catch (err) {
|
|
190
|
+
logger.warn({ txHash, error: err instanceof Error ? err.message : String(err) }, 'Chain read for a sent transaction was inconclusive');
|
|
191
|
+
return { verdict: 'open' };
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// Without an expiry the bytes can land while every input is unspent: past the longest expiry plus the
|
|
195
|
+
// horizon that makes them stale. A landing spends every input, so some but not all spent past the horizon
|
|
196
|
+
// means it never lands, all spent means unresolved. Before that bound only own outputs decide.
|
|
197
|
+
async function judgeWithoutExpiry(facts, signedTxCbor, txHash, client, settle, sentAtMs, nowMs) {
|
|
198
|
+
if (sentAtMs == null || nowMs <= sentAtMs + const_1.MAX_VALIDITY_MS + settle * 1000)
|
|
199
|
+
return { verdict: 'open' };
|
|
200
|
+
const own = await ownOutputEvidence(facts, signedTxCbor, txHash, client);
|
|
201
|
+
if (own)
|
|
202
|
+
return own;
|
|
203
|
+
const ledger = await client.readLedger(facts.inputs);
|
|
204
|
+
const unspentInputs = facts.inputs.filter((_, i) => ledger.unspent[i]);
|
|
205
|
+
const margin = settle + (ledger.live ? 0 : exports.PROVIDER_LAG_SLOTS);
|
|
206
|
+
if (unspentInputs.length === facts.inputs.length) {
|
|
207
|
+
someSpentSince.delete(txHash);
|
|
208
|
+
allSpentSince.delete(txHash);
|
|
209
|
+
return { verdict: 'stale', reason: `Transaction ${txHash} has no expiry and has not landed; every input it spends is unspent, so it can still land`, unspentInputs };
|
|
210
|
+
}
|
|
211
|
+
if (unspentInputs.length) {
|
|
212
|
+
allSpentSince.delete(txHash);
|
|
213
|
+
if (ledger.tip < firstSeen(someSpentSince, txHash, ledger.tip) + margin)
|
|
214
|
+
return { verdict: 'open' };
|
|
215
|
+
someSpentSince.delete(txHash);
|
|
216
|
+
return { verdict: 'neverLands', reason: `Transaction ${txHash} has no expiry; one of its inputs is spent by another transaction and another is unspent, so it never landed and never can` };
|
|
217
|
+
}
|
|
218
|
+
someSpentSince.delete(txHash);
|
|
219
|
+
if (ledger.tip < firstSeen(allSpentSince, txHash, ledger.tip) + margin)
|
|
220
|
+
return { verdict: 'open' };
|
|
221
|
+
allSpentSince.delete(txHash);
|
|
222
|
+
return { verdict: 'unresolved', reason: `Transaction ${txHash} has no expiry; its inputs are spent and nothing shows whether by this transaction` };
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=landing-proof.js.map
|
|
@@ -1,56 +1,18 @@
|
|
|
1
|
-
import { SignatureVerificationResult, VerificationOptions } from '../../utils/types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* This module provides signature verification for externally signed transactions.
|
|
6
|
-
* It ensures:
|
|
7
|
-
* 1. The signed CBOR is valid and parseable
|
|
8
|
-
* 2. The transaction body hash matches the expected hash (integrity check)
|
|
9
|
-
* 3. Required signatures are present (when specified)
|
|
10
|
-
* 4. No tampering occurred between build and sign steps
|
|
11
|
-
*/
|
|
1
|
+
import { SignatureVerificationResult, TxWitnessVerification, VerificationOptions } from '../../utils/types';
|
|
2
|
+
export declare function verifyTxWitnesses(signedTxCbor: string): TxWitnessVerification;
|
|
3
|
+
/** Verifies externally signed transactions without private keys. */
|
|
12
4
|
export declare class SignatureVerifier {
|
|
13
|
-
/**
|
|
14
|
-
* Verify a signed transaction
|
|
15
|
-
*
|
|
16
|
-
* @param signedTxCbor - The signed transaction in CBOR hex format
|
|
17
|
-
* @param options - Verification options
|
|
18
|
-
* @returns Verification result with details
|
|
19
|
-
*/
|
|
5
|
+
/** Verify a signed tx (hex CBOR); all failures are reported in the result, never thrown. */
|
|
20
6
|
verify(signedTxCbor: string, options?: VerificationOptions): SignatureVerificationResult;
|
|
21
|
-
/**
|
|
22
|
-
* Verify signature and throw on failure
|
|
23
|
-
*
|
|
24
|
-
* @param signedTxCbor - The signed transaction in CBOR hex format
|
|
25
|
-
* @param options - Verification options
|
|
26
|
-
* @throws {TransactionValidationError} if verification fails
|
|
27
|
-
*/
|
|
7
|
+
/** Like verify(), but throws TransactionValidationError on failure. */
|
|
28
8
|
verifyOrThrow(signedTxCbor: string, options?: VerificationOptions): SignatureVerificationResult;
|
|
29
|
-
/**
|
|
30
|
-
* Extract transaction body hash from unsigned or signed CBOR
|
|
31
|
-
*
|
|
32
|
-
* @param txCbor - Transaction CBOR (signed or unsigned)
|
|
33
|
-
* @returns Transaction body hash as hex string
|
|
34
|
-
* @throws {Error} if CBOR is invalid
|
|
35
|
-
*/
|
|
9
|
+
/** Body hash (hex) of an unsigned or signed tx CBOR; throws BackendError 400 on invalid CBOR. */
|
|
36
10
|
extractTxBodyHash(txCbor: string): string;
|
|
37
|
-
/**
|
|
38
|
-
* Check if a transaction is signed (has witnesses)
|
|
39
|
-
*
|
|
40
|
-
* @param txCbor - Transaction CBOR
|
|
41
|
-
* @returns true if transaction has at least one witness
|
|
42
|
-
*/
|
|
11
|
+
/** True when the tx carries at least one vkey witness. */
|
|
43
12
|
isSigned(txCbor: string): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Get witness count from transaction
|
|
46
|
-
*
|
|
47
|
-
* @param txCbor - Transaction CBOR
|
|
48
|
-
* @returns Number of witnesses
|
|
49
|
-
*/
|
|
13
|
+
/** Number of vkey witnesses in the tx (0 on invalid CBOR). */
|
|
50
14
|
getWitnessCount(txCbor: string): number;
|
|
51
15
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Get the singleton SignatureVerifier instance
|
|
54
|
-
*/
|
|
16
|
+
/** Singleton SignatureVerifier. */
|
|
55
17
|
export declare function getSignatureVerifier(): SignatureVerifier;
|
|
56
18
|
//# sourceMappingURL=signature-verifier.d.ts.map
|