@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
|
@@ -3,17 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.setActiveNetwork = setActiveNetwork;
|
|
4
4
|
exports.getActiveNetwork = getActiveNetwork;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* This is a deliberately tiny *leaf* module: it has no runtime dependencies (the
|
|
9
|
-
* `Network` import is type-only and erased at compile), so leaf utilities such as
|
|
10
|
-
* `validators.ts` can read the configured network WITHOUT importing `server.ts`
|
|
11
|
-
* — which would otherwise drag the whole server → indexer graph (and its
|
|
12
|
-
* module-load `cds.ql` access) into every consumer.
|
|
13
|
-
*
|
|
14
|
-
* Set during bootstrap by `initializeAppContext` and cleared on shutdown. Reads
|
|
15
|
-
* before bootstrap return `null`; callers treat that as "not ready" rather than
|
|
16
|
-
* throwing (e.g. network-aware validators return `false`).
|
|
6
|
+
* Dependency-free holder for the active network, so leaf utilities (validators) can read it
|
|
7
|
+
* without importing `server.ts`. Set by `initializeAppContext`, `null` before bootstrap.
|
|
17
8
|
*/
|
|
18
9
|
let active = null;
|
|
19
10
|
/** Record the active network. Pass `null` to clear (shutdown/reset). */
|
|
@@ -6,27 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.stripNullsForNotNull = stripNullsForNotNull;
|
|
7
7
|
exports.installPostgresOrderNulls = installPostgresOrderNulls;
|
|
8
8
|
/**
|
|
9
|
-
* ORDER BY on PostgreSQL:
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* `ASC NULLS FIRST` and `DESC NULLS LAST`, to give SQLite's and HANA's null
|
|
13
|
-
* order on Postgres too. A Postgres btree index is `ASC NULLS LAST` (read
|
|
14
|
-
* backwards `DESC NULLS FIRST`), the opposite placement, so the planner
|
|
15
|
-
* cannot use an index for such an ORDER BY and sorts the whole table before
|
|
16
|
-
* the LIMIT. CAP orders every `$top` read by the entity key, so on the hosted
|
|
17
|
-
* box `Blocks?$top=1` took 0.8 to 7.6 s over 2M rows in NIGHTGATE and every
|
|
18
|
-
* `$top` on a large ODATANO table sorted the same way (measured 2026-09-23,
|
|
19
|
-
* `ORDER BY "$b".ID ASC NULLS FIRST LIMIT 1`, parallel seq scan + top-N sort).
|
|
20
|
-
*
|
|
21
|
-
* A key column, a `not null` column and a temporal `@cds.valid.from` column
|
|
22
|
-
* (part of the persisted primary key, NOT NULL, but neither `key` nor
|
|
23
|
-
* `notNull` in the linked model) hold no NULL, so the placement is
|
|
24
|
-
* meaningless there and is dropped; the plain `ASC` / `DESC` then matches the
|
|
25
|
-
* primary key and the secondary indexes. Nullable columns keep the clause (the
|
|
26
|
-
* semantics stay SQLite's); an explicit `nulls` on the term is always kept.
|
|
27
|
-
* Installed once at start on the Postgres renderer class; a driver without the
|
|
28
|
-
* hook (or no Postgres driver at all) leaves everything as it is, with a
|
|
29
|
-
* warning when the deployment runs on Postgres.
|
|
9
|
+
* ORDER BY on PostgreSQL: drop the NULLS clause for columns that cannot be NULL.
|
|
10
|
+
* @cap-js/postgres renders `ASC NULLS FIRST` / `DESC NULLS LAST`, the opposite of a btree index's
|
|
11
|
+
* placement, so `$top` reads sorted the whole table; key, `not null` and `@cds.valid.from` columns are exempt.
|
|
30
12
|
*/
|
|
31
13
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
32
14
|
const logger = cds_1.default.log('PgOrderNulls');
|
|
@@ -51,8 +33,7 @@ function installPostgresOrderNulls() {
|
|
|
51
33
|
PostgresService = require('@cap-js/postgres/lib/PostgresService');
|
|
52
34
|
}
|
|
53
35
|
catch (err) {
|
|
54
|
-
// No Postgres driver
|
|
55
|
-
// the module: silent unless the database IS Postgres.
|
|
36
|
+
// No loadable Postgres driver: silent unless the database is Postgres.
|
|
56
37
|
const dbKind = String((cds_1.default.env?.requires?.db)?.kind ?? '');
|
|
57
38
|
if (dbKind === 'postgres')
|
|
58
39
|
logger.warn(`@cap-js/postgres/lib/PostgresService not loadable, ORDER BY keeps the NULLS clause: ${String(err?.message ?? err)}`);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { JSONValue } from './types';
|
|
2
2
|
/**
|
|
3
|
-
* PlutusData-JSON input-index placeholder
|
|
4
|
-
*
|
|
5
|
-
* The placeholder must be the entire `int` field value — partial matches are ignored.
|
|
3
|
+
* PlutusData-JSON input-index placeholder `__INPUT_IDX:<64-hex txHash>#<outputIndex>__`; must be the
|
|
4
|
+
* entire `int` field value. Hash case-insensitive, normalized to lowercase at the use site.
|
|
6
5
|
*/
|
|
7
6
|
export declare const INPUT_IDX_REGEX: RegExp;
|
|
8
7
|
/** Minimal UTxO reference shape used by the placeholder resolver. */
|
|
@@ -11,25 +10,14 @@ export interface InputRef {
|
|
|
11
10
|
outputIndex: number;
|
|
12
11
|
}
|
|
13
12
|
export interface ResolveContext {
|
|
14
|
-
/** Inputs in their final, post-sort order
|
|
13
|
+
/** Inputs in their final, post-sort order; the array index is the resolved placeholder value. */
|
|
15
14
|
sortedInputs: InputRef[];
|
|
16
15
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Replicates Buildooor's input sort: lexicographic on the txHash bytes, tie-break by outputIndex asc.
|
|
19
|
-
* This mirrors the Cardano ledger CBOR-set ordering used by Buildooor.
|
|
20
|
-
* Verified against node_modules/@harmoniclabs/buildooor/dist/TxBuilder/TxBuilder.js:772.
|
|
21
|
-
*/
|
|
16
|
+
/** Replicates Buildooor's input sort (ledger CBOR-set order): txHash bytes, then outputIndex asc. */
|
|
22
17
|
export declare function sortInputsLikeBuildooor<T extends InputRef>(refs: T[]): T[];
|
|
23
18
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* Placeholders are only recognised inside an `int` field. Strings elsewhere (e.g. `bytes`)
|
|
28
|
-
* are left untouched — hex payloads may legitimately contain `__` sequences.
|
|
29
|
-
*
|
|
30
|
-
* Throws TransactionValidationError if a placeholder references a UTxO ref that is not present
|
|
31
|
-
* in `ctx.sortedInputs`. The exact placeholder string is included in the message so consumers
|
|
32
|
-
* can diagnose missing forceInputs / script UTxOs.
|
|
19
|
+
* Replaces `{int: "__INPUT_IDX:<hash>#<idx>__"}` leaves with the input's sorted position. Only `int`
|
|
20
|
+
* fields are inspected (`bytes` may legitimately contain `__`); an unknown ref throws TransactionValidationError.
|
|
33
21
|
*/
|
|
34
22
|
export declare function resolveIndexPlaceholders(node: JSONValue, ctx: ResolveContext): JSONValue;
|
|
35
23
|
//# sourceMappingURL=plutus-placeholders.d.ts.map
|
|
@@ -5,19 +5,12 @@ exports.sortInputsLikeBuildooor = sortInputsLikeBuildooor;
|
|
|
5
5
|
exports.resolveIndexPlaceholders = resolveIndexPlaceholders;
|
|
6
6
|
const errors_1 = require("./errors");
|
|
7
7
|
/**
|
|
8
|
-
* PlutusData-JSON input-index placeholder
|
|
9
|
-
*
|
|
10
|
-
* The placeholder must be the entire `int` field value — partial matches are ignored.
|
|
8
|
+
* PlutusData-JSON input-index placeholder `__INPUT_IDX:<64-hex txHash>#<outputIndex>__`; must be the
|
|
9
|
+
* entire `int` field value. Hash case-insensitive, normalized to lowercase at the use site.
|
|
11
10
|
*/
|
|
12
|
-
// case-insensitive: tx hashes are conventionally lowercase, but accept either
|
|
13
|
-
// case and normalize the captured hash to lowercase at the use site
|
|
14
11
|
exports.INPUT_IDX_REGEX = /^__INPUT_IDX:([0-9a-fA-F]{64})#(\d+)__$/;
|
|
15
12
|
const MAX_WALK_DEPTH = 64;
|
|
16
|
-
/**
|
|
17
|
-
* Replicates Buildooor's input sort: lexicographic on the txHash bytes, tie-break by outputIndex asc.
|
|
18
|
-
* This mirrors the Cardano ledger CBOR-set ordering used by Buildooor.
|
|
19
|
-
* Verified against node_modules/@harmoniclabs/buildooor/dist/TxBuilder/TxBuilder.js:772.
|
|
20
|
-
*/
|
|
13
|
+
/** Replicates Buildooor's input sort (ledger CBOR-set order): txHash bytes, then outputIndex asc. */
|
|
21
14
|
function sortInputsLikeBuildooor(refs) {
|
|
22
15
|
const copy = refs.slice();
|
|
23
16
|
copy.sort((a, b) => {
|
|
@@ -31,15 +24,8 @@ function sortInputsLikeBuildooor(refs) {
|
|
|
31
24
|
return copy;
|
|
32
25
|
}
|
|
33
26
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* Placeholders are only recognised inside an `int` field. Strings elsewhere (e.g. `bytes`)
|
|
38
|
-
* are left untouched — hex payloads may legitimately contain `__` sequences.
|
|
39
|
-
*
|
|
40
|
-
* Throws TransactionValidationError if a placeholder references a UTxO ref that is not present
|
|
41
|
-
* in `ctx.sortedInputs`. The exact placeholder string is included in the message so consumers
|
|
42
|
-
* can diagnose missing forceInputs / script UTxOs.
|
|
27
|
+
* Replaces `{int: "__INPUT_IDX:<hash>#<idx>__"}` leaves with the input's sorted position. Only `int`
|
|
28
|
+
* fields are inspected (`bytes` may legitimately contain `__`); an unknown ref throws TransactionValidationError.
|
|
43
29
|
*/
|
|
44
30
|
function resolveIndexPlaceholders(node, ctx) {
|
|
45
31
|
return walk(node, ctx, 0);
|
|
@@ -59,7 +45,7 @@ function walk(node, ctx, depth) {
|
|
|
59
45
|
const match = exports.INPUT_IDX_REGEX.exec(value);
|
|
60
46
|
if (match) {
|
|
61
47
|
const [, rawTxHash, idxStr] = match;
|
|
62
|
-
const txHash = rawTxHash.toLowerCase(); //
|
|
48
|
+
const txHash = rawTxHash.toLowerCase(); // input refs are validated lowercase
|
|
63
49
|
const outputIndex = Number(idxStr);
|
|
64
50
|
const pos = ctx.sortedInputs.findIndex(ref => ref.txHash === txHash && ref.outputIndex === outputIndex);
|
|
65
51
|
if (pos === -1) {
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* In-memory sliding-window rate limiter, ported from NIGHTGATE
|
|
3
|
-
* (srv/utils/rate-limiter.ts). Used for grant administration and for failed
|
|
4
|
-
* agent-token attempts; nothing here touches the database.
|
|
5
|
-
*/
|
|
1
|
+
/** In-memory sliding-window rate limiter (grant administration, failed agent-token attempts). No DB. */
|
|
6
2
|
export interface RateLimiterOptions {
|
|
7
3
|
windowMs: number;
|
|
8
4
|
maxRequests: number;
|
|
@@ -11,10 +7,8 @@ export interface RateLimiterOptions {
|
|
|
11
7
|
/** Stale-key sweep interval (default 60 000 ms). */
|
|
12
8
|
sweepIntervalMs?: number;
|
|
13
9
|
/**
|
|
14
|
-
* Max distinct keys
|
|
15
|
-
*
|
|
16
|
-
* single caller can do to the shared table: without it, made-up scopes under
|
|
17
|
-
* one principal evicted every other caller's window.
|
|
10
|
+
* Max distinct keys one group (key up to its first ':', the principal) may hold (default 64),
|
|
11
|
+
* so one caller's made-up scopes cannot evict other callers' windows.
|
|
18
12
|
*/
|
|
19
13
|
maxKeysPerGroup?: number;
|
|
20
14
|
}
|
|
@@ -23,10 +17,8 @@ export interface RateCheckResult {
|
|
|
23
17
|
retryAfterMs: number;
|
|
24
18
|
}
|
|
25
19
|
/**
|
|
26
|
-
* Rate-limit key for a CAP request
|
|
27
|
-
*
|
|
28
|
-
* so the address is the last resort only. The principal is the limiter's GROUP
|
|
29
|
-
* (see maxKeysPerGroup), hence no ':' in it.
|
|
20
|
+
* Rate-limit key `principal:scope` for a CAP request; the principal is the user, else the client
|
|
21
|
+
* address (last resort: batch parts and proxies hide it). No ':' in the principal, it is the group.
|
|
30
22
|
*/
|
|
31
23
|
export declare function principalRateKey(req: unknown, scope: string): string;
|
|
32
24
|
export declare class RateLimiter {
|
|
@@ -43,10 +35,7 @@ export declare class RateLimiter {
|
|
|
43
35
|
peek(key: string): RateCheckResult;
|
|
44
36
|
/** Forget every key (tests). */
|
|
45
37
|
reset(): void;
|
|
46
|
-
/**
|
|
47
|
-
* Consume `count` slots atomically: either ALL fit into the window and are
|
|
48
|
-
* recorded, or NONE are (a rejected caller has consumed nothing).
|
|
49
|
-
*/
|
|
38
|
+
/** Consume `count` slots atomically: all fit and are recorded, or none are. */
|
|
50
39
|
checkMany(key: string, count: number): RateCheckResult;
|
|
51
40
|
private dropKey;
|
|
52
41
|
/** Remove keys with no hits within the current window. */
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* In-memory sliding-window rate limiter, ported from NIGHTGATE
|
|
4
|
-
* (srv/utils/rate-limiter.ts). Used for grant administration and for failed
|
|
5
|
-
* agent-token attempts; nothing here touches the database.
|
|
6
|
-
*/
|
|
2
|
+
/** In-memory sliding-window rate limiter (grant administration, failed agent-token attempts). No DB. */
|
|
7
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
4
|
exports.RateLimiter = void 0;
|
|
9
5
|
exports.principalRateKey = principalRateKey;
|
|
@@ -13,10 +9,8 @@ function groupOf(key) {
|
|
|
13
9
|
return i < 0 ? key : key.slice(0, i);
|
|
14
10
|
}
|
|
15
11
|
/**
|
|
16
|
-
* Rate-limit key for a CAP request
|
|
17
|
-
*
|
|
18
|
-
* so the address is the last resort only. The principal is the limiter's GROUP
|
|
19
|
-
* (see maxKeysPerGroup), hence no ':' in it.
|
|
12
|
+
* Rate-limit key `principal:scope` for a CAP request; the principal is the user, else the client
|
|
13
|
+
* address (last resort: batch parts and proxies hide it). No ':' in the principal, it is the group.
|
|
20
14
|
*/
|
|
21
15
|
function principalRateKey(req, scope) {
|
|
22
16
|
const r = req;
|
|
@@ -61,10 +55,7 @@ class RateLimiter {
|
|
|
61
55
|
this.hits.clear();
|
|
62
56
|
this.groupCounts.clear();
|
|
63
57
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Consume `count` slots atomically: either ALL fit into the window and are
|
|
66
|
-
* recorded, or NONE are (a rejected caller has consumed nothing).
|
|
67
|
-
*/
|
|
58
|
+
/** Consume `count` slots atomically: all fit and are recorded, or none are. */
|
|
68
59
|
checkMany(key, count) {
|
|
69
60
|
if (count <= 0)
|
|
70
61
|
return { allowed: true, retryAfterMs: 0 };
|
|
@@ -75,8 +66,7 @@ class RateLimiter {
|
|
|
75
66
|
if ((this.groupCounts.get(group) ?? 0) >= this.maxKeysPerGroup) {
|
|
76
67
|
return { allowed: false, retryAfterMs: this.windowMs };
|
|
77
68
|
}
|
|
78
|
-
// At capacity a
|
|
79
|
-
// insertion ordered and `set` below re-inserts on every hit).
|
|
69
|
+
// At capacity a new key evicts the least recently used one (insertion-ordered map, re-inserted per hit).
|
|
80
70
|
if (this.hits.size >= this.maxKeys) {
|
|
81
71
|
const oldest = this.hits.keys().next().value;
|
|
82
72
|
if (oldest !== undefined)
|
|
@@ -1,26 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* const worker = await cds.connect.to('CardanoWorkerService');
|
|
6
|
-
* worker.on('jobConfirmed', ({ data }) => …);
|
|
7
|
-
*
|
|
8
|
-
* ODATANO ships as a CAP plugin, so a consumer runs in the SAME process — these
|
|
9
|
-
* events therefore need no broker and no `cds.requires.messaging`. Configuring a
|
|
10
|
-
* messaging service later routes the very same emits through it (with the CAP
|
|
11
|
-
* outbox) without a change here.
|
|
12
|
-
*
|
|
13
|
-
* Three properties this helper guarantees, because every caller is a background
|
|
14
|
-
* loop that must not be disturbed by an observer:
|
|
15
|
-
* - **Never throws.** A missing service, a rejected emit or a broken subscriber
|
|
16
|
-
* is logged and swallowed; the crawler/worker carries on.
|
|
17
|
-
* - **Never blocks.** Emission is fire-and-forget; a slow subscriber cannot stall
|
|
18
|
-
* block ingestion.
|
|
19
|
-
* - **Silent when unserved.** In unit tests and before CAP's `served` phase the
|
|
20
|
-
* service simply does not exist yet — that is normal, not an error.
|
|
21
|
-
*
|
|
22
|
-
* Call sites must emit AFTER their transaction commits: an event that names data
|
|
23
|
-
* a subscriber cannot read yet is worse than no event.
|
|
2
|
+
* Emits a declared CAP service event in-process (no broker needed). Never throws, never blocks,
|
|
3
|
+
* silent when the service is not served yet. Callers must emit AFTER their transaction commits.
|
|
24
4
|
*/
|
|
25
5
|
export declare function emitServiceEvent(serviceName: string, event: string, data: Record<string, unknown>): void;
|
|
26
6
|
//# sourceMappingURL=service-events.d.ts.map
|
|
@@ -7,33 +7,13 @@ exports.emitServiceEvent = emitServiceEvent;
|
|
|
7
7
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
8
8
|
const logger = cds_1.default.log('ServiceEvents');
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* const worker = await cds.connect.to('CardanoWorkerService');
|
|
14
|
-
* worker.on('jobConfirmed', ({ data }) => …);
|
|
15
|
-
*
|
|
16
|
-
* ODATANO ships as a CAP plugin, so a consumer runs in the SAME process — these
|
|
17
|
-
* events therefore need no broker and no `cds.requires.messaging`. Configuring a
|
|
18
|
-
* messaging service later routes the very same emits through it (with the CAP
|
|
19
|
-
* outbox) without a change here.
|
|
20
|
-
*
|
|
21
|
-
* Three properties this helper guarantees, because every caller is a background
|
|
22
|
-
* loop that must not be disturbed by an observer:
|
|
23
|
-
* - **Never throws.** A missing service, a rejected emit or a broken subscriber
|
|
24
|
-
* is logged and swallowed; the crawler/worker carries on.
|
|
25
|
-
* - **Never blocks.** Emission is fire-and-forget; a slow subscriber cannot stall
|
|
26
|
-
* block ingestion.
|
|
27
|
-
* - **Silent when unserved.** In unit tests and before CAP's `served` phase the
|
|
28
|
-
* service simply does not exist yet — that is normal, not an error.
|
|
29
|
-
*
|
|
30
|
-
* Call sites must emit AFTER their transaction commits: an event that names data
|
|
31
|
-
* a subscriber cannot read yet is worse than no event.
|
|
10
|
+
* Emits a declared CAP service event in-process (no broker needed). Never throws, never blocks,
|
|
11
|
+
* silent when the service is not served yet. Callers must emit AFTER their transaction commits.
|
|
32
12
|
*/
|
|
33
13
|
function emitServiceEvent(serviceName, event, data) {
|
|
34
14
|
const srv = cds_1.default.services?.[serviceName];
|
|
35
15
|
if (!srv?.emit)
|
|
36
|
-
return; // not served
|
|
16
|
+
return; // not served yet
|
|
37
17
|
try {
|
|
38
18
|
void Promise.resolve(srv.emit(event, data)).catch((err) => {
|
|
39
19
|
logger.warn(`${serviceName}.${event} subscriber failed (ignored):`, err);
|
|
@@ -1,23 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Combine an unsigned
|
|
3
|
-
*
|
|
4
|
-
* CIP-30 signTx() returns only the witness set, not a complete signed transaction.
|
|
5
|
-
* This function combines the original unsigned transaction with the witness set
|
|
6
|
-
* to create a complete signed transaction that can be submitted to the network.
|
|
7
|
-
*
|
|
8
|
-
* @param unsignedTxCbor - The unsigned transaction CBOR (hex)
|
|
9
|
-
* @param witnessSetCbor - The witness set CBOR from CIP-30 signTx() (hex)
|
|
10
|
-
* @returns Complete signed transaction CBOR (hex)
|
|
2
|
+
* Combine an unsigned tx with the witness set a CIP-30 `signTx()` returns into a submittable signed tx.
|
|
3
|
+
* @returns complete signed transaction CBOR (hex)
|
|
11
4
|
*/
|
|
12
5
|
export declare function combineTransactionWithWitnesses(unsignedTxCbor: string, witnessSetCbor: string): string;
|
|
13
|
-
/**
|
|
14
|
-
* Check if a CBOR string is a witness set (vs a full transaction)
|
|
15
|
-
*
|
|
16
|
-
* CIP-30 returns witness sets, not full transactions.
|
|
17
|
-
* This helps detect when we need to call combineTransactionWithWitnesses.
|
|
18
|
-
*
|
|
19
|
-
* @param cborHex - CBOR hex string
|
|
20
|
-
* @returns true if it's a witness set, false if it's a full transaction
|
|
21
|
-
*/
|
|
6
|
+
/** True when the CBOR is a CIP-30 witness set (map) rather than a full transaction (array). */
|
|
22
7
|
export declare function isWitnessSetCbor(cborHex: string): boolean;
|
|
23
8
|
//# sourceMappingURL=signing-helper.d.ts.map
|
|
@@ -11,19 +11,12 @@ const uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
|
|
|
11
11
|
const errors_1 = require("./errors");
|
|
12
12
|
const logger = cds_1.default.log('SigningHelper');
|
|
13
13
|
/**
|
|
14
|
-
* Combine an unsigned
|
|
15
|
-
*
|
|
16
|
-
* CIP-30 signTx() returns only the witness set, not a complete signed transaction.
|
|
17
|
-
* This function combines the original unsigned transaction with the witness set
|
|
18
|
-
* to create a complete signed transaction that can be submitted to the network.
|
|
19
|
-
*
|
|
20
|
-
* @param unsignedTxCbor - The unsigned transaction CBOR (hex)
|
|
21
|
-
* @param witnessSetCbor - The witness set CBOR from CIP-30 signTx() (hex)
|
|
22
|
-
* @returns Complete signed transaction CBOR (hex)
|
|
14
|
+
* Combine an unsigned tx with the witness set a CIP-30 `signTx()` returns into a submittable signed tx.
|
|
15
|
+
* @returns complete signed transaction CBOR (hex)
|
|
23
16
|
*/
|
|
24
17
|
function combineTransactionWithWitnesses(unsignedTxCbor, witnessSetCbor) {
|
|
25
18
|
try {
|
|
26
|
-
//
|
|
19
|
+
// Raw CBOR level: no Cardano type validation, preserves all encoding metadata
|
|
27
20
|
const txObj = cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(unsignedTxCbor));
|
|
28
21
|
if (!(txObj instanceof cbor_1.CborArray) || txObj.array.length < 2) {
|
|
29
22
|
throw new errors_1.TransactionValidationError('Invalid transaction CBOR structure');
|
|
@@ -33,19 +26,18 @@ function combineTransactionWithWitnesses(unsignedTxCbor, witnessSetCbor) {
|
|
|
33
26
|
const origWs = txObj.array[1];
|
|
34
27
|
let witnessCount = 0;
|
|
35
28
|
if (origWs instanceof cbor_1.CborMap && walletWsObj instanceof cbor_1.CborMap) {
|
|
36
|
-
//
|
|
29
|
+
// Wallet's VKey witnesses (map key 0)
|
|
37
30
|
const walletVkeyEntry = walletWsObj.map.find(e => e.k instanceof cbor_1.CborUInt && Number(e.k.num) === 0);
|
|
38
31
|
if (walletVkeyEntry) {
|
|
39
|
-
//
|
|
40
|
-
// remove any existing key 0, then add wallet's key 0 (VKey witnesses)
|
|
32
|
+
// Keep original entries (redeemers, datums, scripts at keys 3-7), replace key 0 with the wallet's
|
|
41
33
|
const mergedEntries = origWs.map
|
|
42
34
|
.filter(e => !(e.k instanceof cbor_1.CborUInt && Number(e.k.num) === 0))
|
|
43
35
|
.concat([walletVkeyEntry]);
|
|
44
|
-
//
|
|
36
|
+
// New witness set map preserving the original's encoding style
|
|
45
37
|
txObj.array[1] = new cbor_1.CborMap(mergedEntries, {
|
|
46
38
|
indefinite: origWs.indefinite,
|
|
47
39
|
});
|
|
48
|
-
//
|
|
40
|
+
// VKey witnesses: CborArray, or CborTag(258, CborArray) in Conway
|
|
49
41
|
const vkeyValue = walletVkeyEntry.v;
|
|
50
42
|
if (vkeyValue instanceof cbor_1.CborArray) {
|
|
51
43
|
witnessCount = vkeyValue.array.length;
|
|
@@ -61,11 +53,8 @@ function combineTransactionWithWitnesses(unsignedTxCbor, witnessSetCbor) {
|
|
|
61
53
|
else {
|
|
62
54
|
throw new errors_1.TransactionValidationError('Witness set must be CBOR map per Cardano spec');
|
|
63
55
|
}
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
// matches now that the witness set changed). The INNER element subCborRefs are
|
|
67
|
-
// deliberately kept: that byte-preserves the body (array[0]), so the tx body hash
|
|
68
|
-
// the witnesses signed stays identical.
|
|
56
|
+
// New outer CborArray so the encoder cannot reuse the stale outer subCborRef; the inner
|
|
57
|
+
// subCborRefs are kept so the body bytes (and thus the signed body hash) stay identical.
|
|
69
58
|
const signedTxCbor = (0, uint8array_utils_1.toHex)(cbor_1.Cbor.encode(new cbor_1.CborArray(txObj.array, { indefinite: txObj.indefinite })));
|
|
70
59
|
logger.info({
|
|
71
60
|
unsignedTxLength: unsignedTxCbor.length,
|
|
@@ -81,26 +70,15 @@ function combineTransactionWithWitnesses(unsignedTxCbor, witnessSetCbor) {
|
|
|
81
70
|
throw new errors_1.TransactionValidationError(`Failed to combine transaction with witnesses: ${msg}`);
|
|
82
71
|
}
|
|
83
72
|
}
|
|
84
|
-
/**
|
|
85
|
-
* Check if a CBOR string is a witness set (vs a full transaction)
|
|
86
|
-
*
|
|
87
|
-
* CIP-30 returns witness sets, not full transactions.
|
|
88
|
-
* This helps detect when we need to call combineTransactionWithWitnesses.
|
|
89
|
-
*
|
|
90
|
-
* @param cborHex - CBOR hex string
|
|
91
|
-
* @returns true if it's a witness set, false if it's a full transaction
|
|
92
|
-
*/
|
|
73
|
+
/** True when the CBOR is a CIP-30 witness set (map) rather than a full transaction (array). */
|
|
93
74
|
function isWitnessSetCbor(cborHex) {
|
|
94
75
|
try {
|
|
95
76
|
const obj = cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(cborHex));
|
|
96
|
-
// A full transaction is a CBOR array ([body, witness_set, is_valid, aux_data]);
|
|
97
|
-
// a CIP-30 witness set is a CBOR map. The two shapes are unambiguous.
|
|
98
77
|
if (obj instanceof cbor_1.CborArray)
|
|
99
78
|
return false;
|
|
100
79
|
return obj instanceof cbor_1.CborMap;
|
|
101
80
|
}
|
|
102
81
|
catch {
|
|
103
|
-
// Invalid / unparseable CBOR
|
|
104
82
|
return false;
|
|
105
83
|
}
|
|
106
84
|
}
|
|
@@ -1,24 +1,13 @@
|
|
|
1
1
|
import type { UTxO as OdatanoUtxo, JSONValue } from '../utils/types';
|
|
2
2
|
import { type Data } from '@harmoniclabs/plutus-data';
|
|
3
3
|
import { UPLCConst } from '@harmoniclabs/uplc';
|
|
4
|
-
/**
|
|
5
|
-
* Extract lovelace amount from UTxO
|
|
6
|
-
* @param u UTxO to extract from
|
|
7
|
-
* @returns {bigint} lovelace amount
|
|
8
|
-
*/
|
|
4
|
+
/** Lovelace amount of a UTxO. */
|
|
9
5
|
export declare function getLovelace(u: OdatanoUtxo): bigint;
|
|
10
|
-
/**
|
|
11
|
-
* Assert that UTxO contains only ADA (lovelace)
|
|
12
|
-
* @param u UTxO to check
|
|
13
|
-
* @throws {MixedAssetsError} if UTxO contains non-ADA assets
|
|
14
|
-
*/
|
|
6
|
+
/** Throws MixedAssetsError when the UTxO carries non-ADA assets. */
|
|
15
7
|
export declare function assertAdaOnly(u: OdatanoUtxo): void;
|
|
16
8
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @param txCbor transaction in CBOR hex format
|
|
20
|
-
* @returns {string} transaction hash (64 character hex string)
|
|
21
|
-
* @throws {Error} if CBOR is invalid or transaction hash cannot be extracted
|
|
9
|
+
* Transaction hash of a signed or unsigned tx CBOR: blake2b-256 over the body bytes, so witnesses do not affect it.
|
|
10
|
+
* @returns 64-char hex string
|
|
22
11
|
*/
|
|
23
12
|
export declare function getTxHashFromCbor(txCbor: string): string;
|
|
24
13
|
/** Cache-invalidation targets of a submitted transaction (see extractTxCacheTargets). */
|
|
@@ -32,102 +21,39 @@ export interface TxCacheTargets {
|
|
|
32
21
|
outputAddresses: string[];
|
|
33
22
|
}
|
|
34
23
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* UTxO cache. Works at the raw-CBOR level for the same reason as
|
|
38
|
-
* getTxHashFromCbor (byte-exact, no high-level Tx round-trip).
|
|
39
|
-
*
|
|
40
|
-
* Outputs whose address bytes cannot be decoded (e.g. Byron bootstrap
|
|
41
|
-
* addresses) are skipped — invalidation is best-effort per address.
|
|
42
|
-
*
|
|
43
|
-
* @param txCbor transaction in CBOR hex format
|
|
44
|
-
* @throws {TransactionValidationError} if the CBOR is not a transaction
|
|
24
|
+
* Consumed input refs and output addresses of a tx CBOR: the UTxO-cache rows a submit makes stale.
|
|
25
|
+
* Outputs whose address bytes cannot be decoded (Byron) are skipped.
|
|
45
26
|
*/
|
|
46
27
|
export declare function extractTxCacheTargets(txCbor: string): TxCacheTargets;
|
|
47
28
|
/**
|
|
48
|
-
* Maps
|
|
49
|
-
*
|
|
50
|
-
* When no assetUnit is provided, extracts it from the error message if possible
|
|
51
|
-
* (e.g. "not enough <policyId.assetName>"), falling back to 'lovelace'.
|
|
52
|
-
* @param err Error from builder
|
|
53
|
-
* @param assetUnit Optional asset unit override (auto-extracted from error message if omitted)
|
|
54
|
-
* @param context Optional build-flow context (e.g. the collateral/funding partition)
|
|
55
|
-
* appended to the consumer-facing message — the builder's own message
|
|
56
|
-
* has no way of knowing it
|
|
57
|
-
* @throws {InsufficientFundsError} if error is related to insufficient funds
|
|
58
|
-
* @throws {Error} original error if not mappable
|
|
29
|
+
* Maps Buildooor errors to typed BackendErrors. Asset unit is parsed from "not enough <unit>" when not given;
|
|
30
|
+
* `context` (e.g. the collateral partition) is appended to the consumer-facing message.
|
|
59
31
|
*/
|
|
60
32
|
export declare function mapBuilderError(err: unknown, assetUnit?: string, context?: string): never;
|
|
61
|
-
/**
|
|
62
|
-
* Parse asset unit string into policyId and assetName
|
|
63
|
-
* Format: policyId (56 hex chars) + assetName (remaining hex)
|
|
64
|
-
* Used by the Buildooor transaction builder
|
|
65
|
-
*/
|
|
33
|
+
/** Split an asset unit into policyId (56 hex chars) and assetName (remaining hex). */
|
|
66
34
|
export declare function parseAssetUnit(assetUnit: string): {
|
|
67
35
|
policyId: string;
|
|
68
36
|
assetName: string;
|
|
69
37
|
};
|
|
70
|
-
/**
|
|
71
|
-
* Convert JSON value to Buildooor PlutusData (Data type).
|
|
72
|
-
* Accepts both cardano-cli format ("constructor") and Buildooor format ("constr").
|
|
73
|
-
* - { "int": 42 } → DataI(42)
|
|
74
|
-
* - { "bytes": "deadbeef" } → DataB("deadbeef")
|
|
75
|
-
* - { "list": [...] } → DataList([...])
|
|
76
|
-
* - { "map": [{ "k": ..., "v": ... }] } → DataMap([...])
|
|
77
|
-
* - { "constructor": 0, "fields": [...] } or { "constr": 0, "fields": [...] } → DataConstr(0, [...])
|
|
78
|
-
* @param json JSON value representing PlutusData
|
|
79
|
-
* @returns Buildooor Data object
|
|
80
|
-
*/
|
|
38
|
+
/** JSON (`int` / `bytes` / `list` / `map` / `constructor`|`constr`) to Buildooor PlutusData. */
|
|
81
39
|
export declare function jsonToPlutusData(json: JSONValue): Data;
|
|
82
40
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* Backends report inline datums in different shapes:
|
|
86
|
-
* - Blockfrost: hex CBOR string (e.g. "19a6aa")
|
|
87
|
-
* - Koios (_extended): wrapper { bytes: "<hex>", value: { ...PlutusData JSON... } }
|
|
88
|
-
* - Koios (sometimes empty): { bytes: null, value: null }
|
|
89
|
-
* - Some endpoints: raw PlutusData JSON ({ "int": 42 } / { "constructor": 0, "fields": [] })
|
|
90
|
-
*
|
|
91
|
-
* Returns hex CBOR (lowercase) or null. Defensive: returns null on unknown
|
|
92
|
-
* shapes rather than throwing — backend mappers must not crash on malformed data.
|
|
41
|
+
* Backend inline datum to lowercase CBOR hex: hex string (Blockfrost), `{ bytes, value }` wrapper (Koios)
|
|
42
|
+
* or raw PlutusData JSON. Returns null on unknown shapes instead of throwing.
|
|
93
43
|
*/
|
|
94
44
|
export declare function inlineDatumToHex(datum: unknown): string | null;
|
|
95
45
|
/** UPLC type tag for a typed script parameter (see {@link encodeScriptParam}). */
|
|
96
46
|
export type ScriptParamUplcType = 'data' | 'bytes' | 'int' | 'bool' | 'unit';
|
|
97
47
|
/**
|
|
98
|
-
* Encode a
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* A script parameter is applied as a UPLC constant whose TYPE must match what
|
|
102
|
-
* the compiled validator expects for that parameter. Two input shapes are
|
|
103
|
-
* accepted:
|
|
104
|
-
*
|
|
105
|
-
* 1. Typed — `{ "uplc": "<type>", "value": <...> }`:
|
|
106
|
-
* - `"data"` → `UPLCConst.data(...)` value: PlutusData JSON ("constr"/cardano-cli form)
|
|
107
|
-
* - `"bytes"` → `UPLCConst.byteString(...)` value: even-length hex string
|
|
108
|
-
* - `"int"` → `UPLCConst.int(...)` value: number | numeric string
|
|
109
|
-
* - `"bool"` → `UPLCConst.bool(...)` value: boolean
|
|
110
|
-
* - `"unit"` → `UPLCConst.unit` value: omitted
|
|
111
|
-
* Required for compilers whose scalar params are NATIVE-typed rather than
|
|
112
|
-
* Data-wrapped (e.g. Pebble: `param x: PubKeyHash` expects a native
|
|
113
|
-
* `bytestring`, not a `Data` bytestring).
|
|
114
|
-
*
|
|
115
|
-
* 2. Bare PlutusData object (e.g. `{ "bytes": "ab.." }`, `{ "constructor": 0, ... }`)
|
|
116
|
-
* — shorthand for `{ "uplc": "data", "value": <object> }`. This is the
|
|
117
|
-
* Aiken / CIP-57 blueprint convention, where every parameter is Data.
|
|
48
|
+
* Encode a script parameter as the UPLC constant of the type the validator expects: typed
|
|
49
|
+
* `{ uplc: data|bytes|int|bool|unit, value }` for native-typed params, or a bare PlutusData object
|
|
50
|
+
* (Aiken / CIP-57 convention) as shorthand for `uplc: "data"`.
|
|
118
51
|
*/
|
|
119
52
|
export declare function encodeScriptParam(param: JSONValue): UPLCConst;
|
|
120
53
|
/**
|
|
121
|
-
* Apply parameters to a parameterized PlutusV3 script (CBOR-wrapped flat UPLC)
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* Parameters are applied in their declared UPLC type via {@link encodeScriptParam}:
|
|
125
|
-
* pass `{ uplc, value }` entries for native-typed params (e.g. Pebble scalars),
|
|
126
|
-
* or bare PlutusData objects for the Data convention (Aiken / CIP-57 blueprints).
|
|
127
|
-
*
|
|
128
|
-
* @param scriptHex CBOR hex of the unapplied Plutus script (as output by Aiken/Pebble/Plutus compilers)
|
|
129
|
-
* @param params Array of script parameters (typed `{uplc,value}` and/or bare PlutusData JSON) to apply in order
|
|
130
|
-
* @returns CBOR hex of the applied script (ready for transaction building)
|
|
54
|
+
* Apply parameters to a parameterized PlutusV3 script (CBOR-wrapped flat UPLC): each parameter becomes a
|
|
55
|
+
* UPLC Application around the program body, encoded via {@link encodeScriptParam}.
|
|
56
|
+
* @returns CBOR hex of the applied script
|
|
131
57
|
*/
|
|
132
58
|
export declare function applyScriptParameters(scriptHex: string, params: JSONValue[]): string;
|
|
133
59
|
//# sourceMappingURL=tx-build-helper.d.ts.map
|