@odatano/core 2.0.0-rc.19 → 2.0.0-rc.20
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 +1 -5
- package/@cds-models/CardanoIndexerService/index.d.ts +51 -2
- package/@cds-models/CardanoIndexerService/index.js +7 -0
- package/package.json +1 -1
- package/src/index.d.ts +4 -10
- package/src/index.js +6 -16
- package/src/plugin.js +11 -27
- package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
- package/srv/blockchain/backends/blockfrost-backend.js +39 -150
- package/srv/blockchain/backends/cardano-backend.d.ts +53 -171
- package/srv/blockchain/backends/cardano-backend.js +1 -5
- package/srv/blockchain/backends/koios-backend.d.ts +26 -71
- package/srv/blockchain/backends/koios-backend.js +50 -132
- package/srv/blockchain/backends/ogmios-backend.d.ts +43 -124
- package/srv/blockchain/backends/ogmios-backend.js +71 -179
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +12 -57
- package/srv/blockchain/backends/ogmios-frame-guard.js +27 -66
- package/srv/blockchain/cardano-client.d.ts +43 -216
- package/srv/blockchain/cardano-client.js +49 -234
- package/srv/blockchain/cardano-indexer.d.ts +79 -357
- package/srv/blockchain/cardano-indexer.js +98 -406
- package/srv/blockchain/cardano-tx-builder.d.ts +19 -84
- package/srv/blockchain/cardano-tx-builder.js +21 -107
- package/srv/blockchain/crawler/certificate-backfill.d.ts +45 -0
- package/srv/blockchain/crawler/certificate-backfill.js +150 -0
- package/srv/blockchain/crawler/crawler.d.ts +41 -145
- package/srv/blockchain/crawler/crawler.js +57 -172
- package/srv/blockchain/crawler/hooks.d.ts +3 -14
- package/srv/blockchain/crawler/index.d.ts +2 -6
- package/srv/blockchain/crawler/index.js +4 -9
- package/srv/blockchain/crawler/sync-state.d.ts +17 -39
- package/srv/blockchain/crawler/sync-state.js +23 -55
- package/srv/blockchain/crawler/utxo-set-import.d.ts +5 -22
- package/srv/blockchain/crawler/utxo-set-import.js +8 -28
- package/srv/blockchain/ledger-state.d.ts +3 -12
- 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 +8 -44
- package/srv/blockchain/signing/signature-verifier.js +13 -54
- package/srv/blockchain/signing/submission-finalizer.d.ts +9 -36
- package/srv/blockchain/signing/submission-finalizer.js +16 -48
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +65 -174
- package/srv/blockchain/transaction-building/buildooor-tx.js +107 -266
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +8 -34
- package/srv/blockchain/wallet-worker/build-request.d.ts +4 -17
- package/srv/blockchain/wallet-worker/build-request.js +9 -22
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +12 -35
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +16 -32
- package/srv/blockchain/wallet-worker/index.js +2 -8
- package/srv/blockchain/wallet-worker/job-store.d.ts +33 -111
- 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 +34 -90
- package/srv/cardano-agent-service.cds +1 -5
- package/srv/cardano-agent-service.js +3 -7
- package/srv/cardano-indexer-service.cds +32 -4
- package/srv/cardano-indexer-service.js +83 -15
- package/srv/cardano-service.js +36 -98
- package/srv/cardano-sign-service.cds +1 -1
- package/srv/cardano-sign-service.js +55 -173
- package/srv/cardano-tx-service.cds +1 -1
- package/srv/cardano-tx-service.js +54 -174
- package/srv/cardano-worker-service.js +7 -15
- package/srv/server.d.ts +27 -86
- package/srv/server.js +52 -148
- package/srv/utils/agent-grants-config.d.ts +11 -50
- package/srv/utils/agent-grants-config.js +12 -45
- package/srv/utils/agent-grants.d.ts +34 -123
- package/srv/utils/agent-grants.js +57 -156
- package/srv/utils/agent-token-auth.d.ts +2 -5
- package/srv/utils/agent-token-auth.js +2 -5
- 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 +19 -68
- package/srv/utils/const.js +20 -69
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +5 -18
- package/srv/utils/db-indexes.d.ts +2 -7
- package/srv/utils/db-indexes.js +7 -34
- package/srv/utils/db-sanitize.d.ts +5 -18
- package/srv/utils/db-sanitize.js +6 -19
- package/srv/utils/error-codes.d.ts +18 -73
- package/srv/utils/error-codes.js +17 -70
- package/srv/utils/errors.d.ts +29 -191
- package/srv/utils/errors.js +44 -229
- package/srv/utils/liveness.d.ts +2 -9
- package/srv/utils/liveness.js +3 -11
- package/srv/utils/mappers.d.ts +50 -298
- package/srv/utils/mappers.js +80 -386
- package/srv/utils/network-context.js +2 -11
- package/srv/utils/pg-order-nulls.js +4 -23
- package/srv/utils/plutus-placeholders.d.ts +6 -18
- package/srv/utils/plutus-placeholders.js +6 -20
- package/srv/utils/rate-limiter.d.ts +6 -17
- package/srv/utils/rate-limiter.js +5 -15
- package/srv/utils/service-events.d.ts +2 -22
- package/srv/utils/service-events.js +3 -23
- package/srv/utils/signing-helper.d.ts +3 -18
- package/srv/utils/signing-helper.js +10 -32
- package/srv/utils/tx-build-helper.d.ts +18 -92
- package/srv/utils/tx-build-helper.js +32 -123
- package/srv/utils/tx-request-parsers.d.ts +7 -26
- package/srv/utils/tx-request-parsers.js +7 -26
- package/srv/utils/tx-utils.d.ts +4 -23
- package/srv/utils/tx-utils.js +12 -41
- package/srv/utils/types.d.ts +67 -206
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +19 -89
- package/srv/utils/validators.js +31 -138
|
@@ -26,26 +26,16 @@ const errors_1 = require("../../utils/errors");
|
|
|
26
26
|
const { SELECT, INSERT, UPDATE } = cds_1.default.ql;
|
|
27
27
|
const logger = cds_1.default.log('CardanoCrawler');
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* the crawler has indexed the chain, so a restart resumes instead of re-crawling.
|
|
33
|
-
*
|
|
34
|
-
* NOTE (CAP 10): Integer64 / Decimal columns are read back from SQLite/HANA as
|
|
35
|
-
* STRINGS, not JS numbers — the same change that makes them strings over OData.
|
|
36
|
-
* Every read here therefore coerces numeric fields with `num()`; callers get a
|
|
37
|
-
* clean numeric `SyncCursor` and never have to think about it.
|
|
29
|
+
* Cursor helpers for `CardanoSyncState`, the singleton row recording how far the crawler
|
|
30
|
+
* has indexed. Integer64/Decimal columns come back from the DB as strings, so every read
|
|
31
|
+
* coerces numeric fields; callers get a numeric `SyncCursor`.
|
|
38
32
|
*/
|
|
39
33
|
exports.SINGLETON_ID = 'SINGLETON';
|
|
40
34
|
/** Circuit-breaker threshold: pause crawling after this many back-to-back failures. */
|
|
41
35
|
exports.MAX_CONSECUTIVE_ERRORS = 10;
|
|
42
36
|
/** A short, renewable DB lease prevents two app instances from advancing one cursor. */
|
|
43
37
|
exports.CRAWLER_LEASE_TTL_MS = 15_000;
|
|
44
|
-
/**
|
|
45
|
-
* Coerce a CAP-10 numeric-as-string (or number/bigint/null) into a JS number.
|
|
46
|
-
* Separate optional/required helpers avoid overload declarations (and the
|
|
47
|
-
* no-redeclare lint false-positive they caused).
|
|
48
|
-
*/
|
|
38
|
+
/** Coerce a numeric-as-string (or number/bigint/null) into a JS number. */
|
|
49
39
|
function optionalNum(v) {
|
|
50
40
|
if (v === null || v === undefined || v === '')
|
|
51
41
|
return null;
|
|
@@ -63,8 +53,8 @@ function timestamp(v) {
|
|
|
63
53
|
return String(v);
|
|
64
54
|
}
|
|
65
55
|
/**
|
|
66
|
-
* Import-lease read-back: ownership and deadline only.
|
|
67
|
-
*
|
|
56
|
+
* Import-lease read-back: ownership and deadline only. Unlike the crawler lease it does not
|
|
57
|
+
* require `desiredRunning`, which is cleared while an import runs.
|
|
68
58
|
*/
|
|
69
59
|
function importLeaseHeld(cursor, owner, expectedMs) {
|
|
70
60
|
if (!cursor || cursor.leaseOwner !== owner || !cursor.leaseUntil)
|
|
@@ -107,10 +97,8 @@ function toCursor(row) {
|
|
|
107
97
|
};
|
|
108
98
|
}
|
|
109
99
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* (if given) and status 'stopped'. Subsequent calls just return the current row.
|
|
113
|
-
* Safe to call from both the crawler and the control service.
|
|
100
|
+
* Ensure the singleton cursor row exists and return it; a fresh DB gets the configured
|
|
101
|
+
* start point and status 'stopped'.
|
|
114
102
|
*/
|
|
115
103
|
async function ensureSyncStateSingleton(db, network, start) {
|
|
116
104
|
const existing = await db.run(SELECT.one.from(cardano_1.CardanoSyncState).where({ ID: exports.SINGLETON_ID }));
|
|
@@ -160,9 +148,8 @@ function isCrawlerLeaseActive(cursor, now = new Date()) {
|
|
|
160
148
|
return Number.isFinite(deadline) && deadline > now.getTime();
|
|
161
149
|
}
|
|
162
150
|
/**
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
* for SELECT, whereas affected-row return shapes differ between SQLite and HANA.
|
|
151
|
+
* Acquire an expired/unowned lease with compare-and-swap semantics. Verified by a read-back
|
|
152
|
+
* SELECT: affected-row return shapes differ between SQLite and HANA.
|
|
166
153
|
*/
|
|
167
154
|
async function tryAcquireCrawlerLease(db, owner, now = new Date(), ttlMs = exports.CRAWLER_LEASE_TTL_MS) {
|
|
168
155
|
const raw = await db.run(SELECT.one.from(cardano_1.CardanoSyncState).where({ ID: exports.SINGLETON_ID }));
|
|
@@ -174,15 +161,9 @@ async function tryAcquireCrawlerLease(db, owner, now = new Date(), ttlMs = expor
|
|
|
174
161
|
const deadline = current.leaseUntil ? Date.parse(current.leaseUntil) : Number.NEGATIVE_INFINITY;
|
|
175
162
|
if (current.leaseOwner && current.leaseOwner !== owner && deadline > now.getTime())
|
|
176
163
|
return false;
|
|
177
|
-
// CAS on the observed OWNER only
|
|
178
|
-
//
|
|
179
|
-
//
|
|
180
|
-
// Deliberately NOT comparing leaseUntil: HANA/driver timestamp normalization can
|
|
181
|
-
// make the read-back representation differ from what the WHERE serializes, so a
|
|
182
|
-
// timestamp-equality CAS may NEVER match again after a leader crash — the lease
|
|
183
|
-
// would be stuck until the row is cleared by hand. The residual race (the old
|
|
184
|
-
// owner renewing concurrently) resolves via fencing: its next renew no longer
|
|
185
|
-
// matches leaseOwner and it halts.
|
|
164
|
+
// CAS on the observed OWNER only, verified by read-back. leaseUntil is deliberately not
|
|
165
|
+
// compared: timestamp normalization on some adapters would make that CAS never match again
|
|
166
|
+
// after a leader crash. A concurrently renewing old owner is fenced by its next renew.
|
|
186
167
|
const where = {
|
|
187
168
|
ID: exports.SINGLETON_ID,
|
|
188
169
|
leaseOwner: raw.leaseOwner ?? null,
|
|
@@ -210,13 +191,8 @@ async function renewCrawlerLease(db, owner, now = new Date(), ttlMs = exports.CR
|
|
|
210
191
|
return leaseDeadlineReached(verified, owner, now.getTime() + ttlMs);
|
|
211
192
|
}
|
|
212
193
|
/**
|
|
213
|
-
* Release only the caller's lease
|
|
214
|
-
*
|
|
215
|
-
* `pauseCluster` clears `desiredRunning`, which no restart undoes — every instance
|
|
216
|
-
* then refuses to start until an operator calls resumeCrawler. Reserve it for
|
|
217
|
-
* failures a restart genuinely cannot fix (misconfiguration, no resume point). A
|
|
218
|
-
* crashed stream, a provider outage or a node restart must NOT latch: those are
|
|
219
|
-
* exactly the cases where coming back up should resume the pre-sync by itself.
|
|
194
|
+
* Release only the caller's lease. `pauseCluster` clears `desiredRunning`, which no restart
|
|
195
|
+
* undoes — reserve it for failures a restart cannot fix (misconfiguration, no resume point).
|
|
220
196
|
*/
|
|
221
197
|
async function releaseCrawlerLease(db, owner, status, pauseCluster = false) {
|
|
222
198
|
await db.run(UPDATE.entity(cardano_1.CardanoSyncState).set({
|
|
@@ -227,9 +203,8 @@ async function releaseCrawlerLease(db, owner, status, pauseCluster = false) {
|
|
|
227
203
|
}).where({ ID: exports.SINGLETON_ID, leaseOwner: owner }));
|
|
228
204
|
}
|
|
229
205
|
/**
|
|
230
|
-
* Persist the pause/resume intent shared by every
|
|
231
|
-
*
|
|
232
|
-
* otherwise keep the standby backoff at its cap for the first retry.
|
|
206
|
+
* Persist the pause/resume intent shared by every instance. Resuming clears the error
|
|
207
|
+
* streak so the standby backoff restarts at its base.
|
|
233
208
|
*/
|
|
234
209
|
async function setCrawlerDesiredRunning(db, desiredRunning) {
|
|
235
210
|
const set = { desiredRunning };
|
|
@@ -240,11 +215,8 @@ async function setCrawlerDesiredRunning(db, desiredRunning) {
|
|
|
240
215
|
await db.run(UPDATE.entity(cardano_1.CardanoSyncState).set(set).where({ ID: exports.SINGLETON_ID }));
|
|
241
216
|
}
|
|
242
217
|
/**
|
|
243
|
-
* Latch the cluster off because of a poison block
|
|
244
|
-
*
|
|
245
|
-
* the poison is a property of the block, not of the instance that observed it, and
|
|
246
|
-
* that instance may have lost its lease while the failure was being recorded. Only
|
|
247
|
-
* an operator's resumeCrawler brings the crawler back.
|
|
218
|
+
* Latch the cluster off because of a poison block. Deliberately not lease-scoped: the poison
|
|
219
|
+
* is a property of the block, not of the instance. Only resumeCrawler brings the crawler back.
|
|
248
220
|
*/
|
|
249
221
|
async function latchPoisonBlock(db, message) {
|
|
250
222
|
await db.run(UPDATE.entity(cardano_1.CardanoSyncState).set({
|
|
@@ -255,9 +227,8 @@ async function latchPoisonBlock(db, message) {
|
|
|
255
227
|
}).where({ ID: exports.SINGLETON_ID }));
|
|
256
228
|
}
|
|
257
229
|
/**
|
|
258
|
-
* Advance the cursor to a freshly
|
|
259
|
-
*
|
|
260
|
-
* lastIndexedAt. Optionally records the latest known tip (for progress).
|
|
230
|
+
* Advance the cursor to a freshly indexed block, clear the error streak and optionally
|
|
231
|
+
* record the latest known tip. Pass status 'synced' when the block is at the tip.
|
|
261
232
|
*/
|
|
262
233
|
async function advanceCursor(db, block, tip, status = 'syncing',
|
|
263
234
|
/** Extra cursor columns written in the same statement (e.g. the ledger's `utxoAppliedSlot`). */
|
|
@@ -280,11 +251,8 @@ extra) {
|
|
|
280
251
|
await db.run(UPDATE.entity(cardano_1.CardanoSyncState).set(set).where({ ID: exports.SINGLETON_ID }));
|
|
281
252
|
}
|
|
282
253
|
/**
|
|
283
|
-
* Lease for the UTxO set import
|
|
284
|
-
*
|
|
285
|
-
* sees a foreign owner with a live deadline) and a second import is refused the same way.
|
|
286
|
-
* Unlike the crawler lease it does not require `desiredRunning` — the cluster is paused
|
|
287
|
-
* during an import by design.
|
|
254
|
+
* Lease for the UTxO set import, on the crawler's lease columns: a crawler start on any
|
|
255
|
+
* instance and a second import are refused while it is held. Does not require `desiredRunning`.
|
|
288
256
|
*/
|
|
289
257
|
async function tryAcquireImportLease(db, owner, now = new Date(), ttlMs = exports.CRAWLER_LEASE_TTL_MS) {
|
|
290
258
|
const raw = await db.run(SELECT.one.from(cardano_1.CardanoSyncState).where({ ID: exports.SINGLETON_ID }));
|
|
@@ -3,22 +3,9 @@ import type { CardanoIndexer } from '../cardano-indexer';
|
|
|
3
3
|
import type { Amount } from '../../utils/types';
|
|
4
4
|
import { type LedgerAnchor } from '../ledger-state';
|
|
5
5
|
/**
|
|
6
|
-
* One-off import of the UTxO set at the anchor
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* - `ogmios`: `queryLedgerState/utxo` for the whole set, acquired at the crawler's
|
|
10
|
-
* cursor point (which must lie inside the node's volatile window, i.e. the crawl is at
|
|
11
|
-
* the tip). Fine on preview/preprod; on mainnet the whole-set query is memory-heavy on
|
|
12
|
-
* the node, use a file.
|
|
13
|
-
* - `file`: a `cardano-cli query utxo --whole-utxo --out-file` dump. `.json` is parsed
|
|
14
|
-
* whole (small networks); `.ndjson` / `.jsonl` is streamed line by line, one entry per
|
|
15
|
-
* line as `jq -c 'to_entries[]'` emits it (`{"key":"tx#ix","value":{…}}`) or as a
|
|
16
|
-
* one-key object. The anchor is the tip at dump time (`cardano-cli query tip` before
|
|
17
|
-
* and after; same hash = valid anchor).
|
|
18
|
-
*
|
|
19
|
-
* Preconditions: the crawler is paused (no active lease) and its cursor is not past the
|
|
20
|
-
* anchor — blocks between cursor and anchor are crawled but not applied, blocks after it
|
|
21
|
-
* are. The tables are truncated first, so a re-import is always a full one.
|
|
6
|
+
* One-off import of the UTxO set at the anchor `crawler.utxoSet` builds on: from Ogmios
|
|
7
|
+
* (`queryLedgerState/utxo` at the cursor point) or a `cardano-cli query utxo --whole-utxo`
|
|
8
|
+
* dump (`.json` parsed whole; `.ndjson`/`.jsonl` streamed, one entry or `{key,value}` per line).
|
|
22
9
|
*/
|
|
23
10
|
export declare class UtxoSetImportError extends Error {
|
|
24
11
|
constructor(message: string);
|
|
@@ -60,12 +47,8 @@ export interface CliUtxoValue {
|
|
|
60
47
|
referenceScript?: unknown;
|
|
61
48
|
}
|
|
62
49
|
/**
|
|
63
|
-
* `JSON.parse` for a cardano-cli dump that keeps every integer exact
|
|
64
|
-
*
|
|
65
|
-
* it ever reaches `String()`. A small scanner quotes every integer literal that sits
|
|
66
|
-
* OUTSIDE a string (string contents, escapes included, pass through untouched), so the
|
|
67
|
-
* value arrives as a string — the entry parser stringifies anyway. Floats keep their JSON
|
|
68
|
-
* meaning; a cli dump has none in value position.
|
|
50
|
+
* `JSON.parse` for a cardano-cli dump that keeps every integer exact: integer literals outside
|
|
51
|
+
* strings are quoted before parsing, so a quantity above 2^53 is never rounded.
|
|
69
52
|
*/
|
|
70
53
|
export declare function parseJsonLossless<T = unknown>(text: string): T;
|
|
71
54
|
/** Parse one `"txHash#index": {…}` entry of a cardano-cli dump; null when malformed. */
|
|
@@ -20,22 +20,9 @@ const collections_1 = require("../../utils/collections");
|
|
|
20
20
|
const { UPSERT, DELETE } = cds_1.default.ql;
|
|
21
21
|
const logger = cds_1.default.log('LedgerState');
|
|
22
22
|
/**
|
|
23
|
-
* One-off import of the UTxO set at the anchor
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* - `ogmios`: `queryLedgerState/utxo` for the whole set, acquired at the crawler's
|
|
27
|
-
* cursor point (which must lie inside the node's volatile window, i.e. the crawl is at
|
|
28
|
-
* the tip). Fine on preview/preprod; on mainnet the whole-set query is memory-heavy on
|
|
29
|
-
* the node, use a file.
|
|
30
|
-
* - `file`: a `cardano-cli query utxo --whole-utxo --out-file` dump. `.json` is parsed
|
|
31
|
-
* whole (small networks); `.ndjson` / `.jsonl` is streamed line by line, one entry per
|
|
32
|
-
* line as `jq -c 'to_entries[]'` emits it (`{"key":"tx#ix","value":{…}}`) or as a
|
|
33
|
-
* one-key object. The anchor is the tip at dump time (`cardano-cli query tip` before
|
|
34
|
-
* and after; same hash = valid anchor).
|
|
35
|
-
*
|
|
36
|
-
* Preconditions: the crawler is paused (no active lease) and its cursor is not past the
|
|
37
|
-
* anchor — blocks between cursor and anchor are crawled but not applied, blocks after it
|
|
38
|
-
* are. The tables are truncated first, so a re-import is always a full one.
|
|
23
|
+
* One-off import of the UTxO set at the anchor `crawler.utxoSet` builds on: from Ogmios
|
|
24
|
+
* (`queryLedgerState/utxo` at the cursor point) or a `cardano-cli query utxo --whole-utxo`
|
|
25
|
+
* dump (`.json` parsed whole; `.ndjson`/`.jsonl` streamed, one entry or `{key,value}` per line).
|
|
39
26
|
*/
|
|
40
27
|
class UtxoSetImportError extends Error {
|
|
41
28
|
constructor(message) {
|
|
@@ -53,16 +40,11 @@ class UtxoSetLeaseLostError extends UtxoSetImportError {
|
|
|
53
40
|
}
|
|
54
41
|
exports.UtxoSetLeaseLostError = UtxoSetLeaseLostError;
|
|
55
42
|
/**
|
|
56
|
-
* `JSON.parse` for a cardano-cli dump that keeps every integer exact
|
|
57
|
-
*
|
|
58
|
-
* it ever reaches `String()`. A small scanner quotes every integer literal that sits
|
|
59
|
-
* OUTSIDE a string (string contents, escapes included, pass through untouched), so the
|
|
60
|
-
* value arrives as a string — the entry parser stringifies anyway. Floats keep their JSON
|
|
61
|
-
* meaning; a cli dump has none in value position.
|
|
43
|
+
* `JSON.parse` for a cardano-cli dump that keeps every integer exact: integer literals outside
|
|
44
|
+
* strings are quoted before parsing, so a quantity above 2^53 is never rounded.
|
|
62
45
|
*/
|
|
63
46
|
function parseJsonLossless(text) {
|
|
64
|
-
//
|
|
65
|
-
// quoted, floats keep their JSON meaning (a cli dump has none in value position).
|
|
47
|
+
// string literals pass through untouched; floats keep their JSON meaning
|
|
66
48
|
const rewritten = text.replace(/"(?:[^"\\]|\\.)*"|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/g, (m) => (m[0] === '"' || !/^-?\d+$/.test(m) ? m : `"${m}"`));
|
|
67
49
|
return JSON.parse(rewritten);
|
|
68
50
|
}
|
|
@@ -206,10 +188,8 @@ async function importUtxoSet(opts) {
|
|
|
206
188
|
}, Math.max(1000, Math.floor(sync_state_1.CRAWLER_LEASE_TTL_MS / 3)));
|
|
207
189
|
heartbeat.unref();
|
|
208
190
|
/**
|
|
209
|
-
* Every write
|
|
210
|
-
*
|
|
211
|
-
* lease between two batches makes this transaction fail before its writes commit. The
|
|
212
|
-
* heartbeat flag alone only knows what was true at the last tick.
|
|
191
|
+
* Every write re-takes the lease INSIDE its transaction (conditional UPDATE + read-back), so
|
|
192
|
+
* a successor that took the lease between two batches fails this transaction before commit.
|
|
213
193
|
*/
|
|
214
194
|
const writeTx = (fn) => cds_1.default.tx(async (tx) => {
|
|
215
195
|
if (leaseLost || !(await (0, sync_state_1.renewImportLease)(tx, leaseOwner)))
|
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
import type { Transaction as CapTransaction } from '@sap/cds';
|
|
2
2
|
import type { Amount, BlockData, Transaction as ProviderTransaction } from '../utils/types';
|
|
3
3
|
/**
|
|
4
|
-
* Crawler-fed ledger state (`crawler.utxoSet`):
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* `LedgerAccounts`) so the lazy, provider-fed `Addresses` / `AddressUTxOs` path and its
|
|
8
|
-
* TTL semantics stay untouched.
|
|
9
|
-
*
|
|
10
|
-
* Correctness rests on an anchor: the set is imported once at a recent point
|
|
11
|
-
* (`utxo-set-import.ts`) and only blocks AFTER that point are applied here. A reorg past
|
|
12
|
-
* the anchor invalidates the set; a reorg after it is undone by `undoLedgerForTransactions`
|
|
13
|
-
* (reopen what the rolled-back blocks spent, drop what they created, recount the touched
|
|
14
|
-
* addresses from the open rows — the recount, not a mirror of the forward logic, is the
|
|
15
|
-
* undo). Everything runs inside the caller's block transaction.
|
|
4
|
+
* Crawler-fed ledger state (`crawler.utxoSet`): UTxO set + per-address/per-stake-key running
|
|
5
|
+
* sums in non-temporal tables. Only blocks AFTER the imported anchor are applied; a reorg past
|
|
6
|
+
* the anchor invalidates the set, one after it is undone by a recount of the open rows.
|
|
16
7
|
*/
|
|
17
8
|
/** The point the imported UTxO set describes; blocks with slot > anchor.slot are applied. */
|
|
18
9
|
export interface LedgerAnchor {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Input to {@link verifyDataSignature}
|
|
3
|
-
* `coseSignature`
|
|
4
|
-
* hex `key` field (COSE_Key).
|
|
2
|
+
* Input to {@link verifyDataSignature}, mirroring the CIP-30 `signData` result:
|
|
3
|
+
* `coseSignature` = hex `signature` field (COSE_Sign1), `coseKey` = hex `key` field (COSE_Key).
|
|
5
4
|
*/
|
|
6
5
|
export interface CoseVerifyInput {
|
|
7
6
|
address: string;
|
|
@@ -20,15 +19,9 @@ export interface CoseVerifyResult {
|
|
|
20
19
|
signerVkh: string;
|
|
21
20
|
}
|
|
22
21
|
/**
|
|
23
|
-
* Verify a CIP-30 `signData` (COSE_Sign1)
|
|
24
|
-
* address
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* Checks, in order:
|
|
28
|
-
* 1. COSE_Sign1 + COSE_Key parse
|
|
29
|
-
* 2. signer key hash (blake2b-224) == the address payment credential (key, not script)
|
|
30
|
-
* 3. (optional) signed payload == expectedPayload
|
|
31
|
-
* 4. Ed25519 signature over the COSE Sig_structure
|
|
22
|
+
* Verify a CIP-30 `signData` (COSE_Sign1) signature against a bech32 address: signer key hash
|
|
23
|
+
* (blake2b-224) must equal the address payment key credential, optional payload check, then
|
|
24
|
+
* Ed25519 over the Sig_structure. Stateless, no nonce/replay handling; never throws (`{ valid: false, reason }`).
|
|
32
25
|
*/
|
|
33
26
|
export declare function verifyDataSignature(input: CoseVerifyInput): CoseVerifyResult;
|
|
34
27
|
//# sourceMappingURL=cose-verifier.d.ts.map
|
|
@@ -71,15 +71,9 @@ function buildSigStructure(protectedBytes, payload) {
|
|
|
71
71
|
return cbor_1.Cbor.encode(sigStruct);
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
|
-
* Verify a CIP-30 `signData` (COSE_Sign1)
|
|
75
|
-
* address
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* Checks, in order:
|
|
79
|
-
* 1. COSE_Sign1 + COSE_Key parse
|
|
80
|
-
* 2. signer key hash (blake2b-224) == the address payment credential (key, not script)
|
|
81
|
-
* 3. (optional) signed payload == expectedPayload
|
|
82
|
-
* 4. Ed25519 signature over the COSE Sig_structure
|
|
74
|
+
* Verify a CIP-30 `signData` (COSE_Sign1) signature against a bech32 address: signer key hash
|
|
75
|
+
* (blake2b-224) must equal the address payment key credential, optional payload check, then
|
|
76
|
+
* Ed25519 over the Sig_structure. Stateless, no nonce/replay handling; never throws (`{ valid: false, reason }`).
|
|
83
77
|
*/
|
|
84
78
|
function verifyDataSignature(input) {
|
|
85
79
|
const result = { valid: false, reason: '', signedPayload: '', signerVkh: '' };
|
|
@@ -88,7 +82,7 @@ function verifyDataSignature(input) {
|
|
|
88
82
|
const pubKey = parseCoseKey(input.coseKey);
|
|
89
83
|
result.signedPayload = Buffer.from(payload).toString('utf8');
|
|
90
84
|
result.signerVkh = (0, uint8array_utils_1.toHex)((0, crypto_1.blake2b_224)(pubKey));
|
|
91
|
-
//
|
|
85
|
+
// signer key hash must equal the address payment credential (key hash, not script)
|
|
92
86
|
const cred = (0, validators_1.extractPaymentCredential)(input.address);
|
|
93
87
|
if (!cred) {
|
|
94
88
|
result.reason = 'Address could not be decoded or has no payment credential (base/enterprise key-hash address required)';
|
|
@@ -102,14 +96,14 @@ function verifyDataSignature(input) {
|
|
|
102
96
|
result.reason = `Signer key hash ${result.signerVkh} does not match address payment credential ${cred.hash}`;
|
|
103
97
|
return result;
|
|
104
98
|
}
|
|
105
|
-
//
|
|
99
|
+
// optional anti-replay payload check
|
|
106
100
|
if (input.expectedPayload !== undefined && input.expectedPayload !== null) {
|
|
107
101
|
if (result.signedPayload !== input.expectedPayload) {
|
|
108
102
|
result.reason = 'Signed payload does not match the expected payload';
|
|
109
103
|
return result;
|
|
110
104
|
}
|
|
111
105
|
}
|
|
112
|
-
//
|
|
106
|
+
// Ed25519 signature over the rebuilt Sig_structure
|
|
113
107
|
const sigStructure = buildSigStructure(protectedBytes, payload);
|
|
114
108
|
if (!(0, crypto_1.verifyEd25519Signature_sync)(signature, sigStructure, pubKey)) {
|
|
115
109
|
result.reason = 'Ed25519 signature does not verify against the signed message';
|
|
@@ -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;
|