@odatano/core 1.11.0 → 2.0.0-rc.10
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 +255 -0
- package/@cds-models/CardanoAgentService/index.js +36 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +177 -0
- package/@cds-models/CardanoIndexerService/index.js +27 -0
- package/@cds-models/CardanoODataService/index.d.ts +693 -2172
- package/@cds-models/CardanoODataService/index.js +88 -390
- package/@cds-models/CardanoSignService/index.d.ts +448 -1576
- package/@cds-models/CardanoSignService/index.js +62 -293
- package/@cds-models/CardanoTransactionService/index.d.ts +437 -1494
- package/@cds-models/CardanoTransactionService/index.js +60 -271
- package/@cds-models/CardanoWorkerService/index.d.ts +224 -0
- package/@cds-models/CardanoWorkerService/index.js +32 -0
- package/@cds-models/_/index.d.ts +70 -40
- package/@cds-models/_/index.js +17 -32
- package/@cds-models/cds/outbox/index.d.ts +28 -0
- package/@cds-models/index.d.ts +225 -522
- package/@cds-models/index.js +35 -218
- package/@cds-models/odatano/cardano/index.d.ts +919 -2884
- package/@cds-models/odatano/cardano/index.js +115 -536
- package/@cds-models/sap/common/index.d.ts +196 -600
- package/@cds-models/sap/common/index.js +28 -269
- package/README.md +194 -102
- package/db/schema.cds +388 -1
- package/db/types.cds +48 -0
- package/package.json +48 -33
- package/src/index.d.ts +7 -1
- package/src/index.js +30 -2
- package/src/plugin.js +33 -20
- package/srv/blockchain/backends/blockfrost-backend.d.ts +21 -2
- package/srv/blockchain/backends/blockfrost-backend.js +69 -25
- package/srv/blockchain/backends/cardano-backend.d.ts +69 -0
- package/srv/blockchain/backends/cardano-backend.js +13 -0
- package/srv/blockchain/backends/koios-backend.d.ts +26 -2
- package/srv/blockchain/backends/koios-backend.js +148 -25
- package/srv/blockchain/backends/ogmios-backend.d.ts +60 -9
- package/srv/blockchain/backends/ogmios-backend.js +326 -10
- package/srv/blockchain/cardano-client.d.ts +19 -0
- package/srv/blockchain/cardano-client.js +36 -0
- package/srv/blockchain/cardano-indexer.d.ts +50 -1
- package/srv/blockchain/cardano-indexer.js +193 -0
- package/srv/blockchain/crawler/crawler.d.ts +176 -0
- package/srv/blockchain/crawler/crawler.js +744 -0
- package/srv/blockchain/crawler/hooks.d.ts +43 -0
- package/srv/blockchain/crawler/hooks.js +62 -0
- package/srv/blockchain/crawler/index.d.ts +35 -0
- package/srv/blockchain/crawler/index.js +168 -0
- package/srv/blockchain/crawler/sync-state.d.ts +106 -0
- package/srv/blockchain/crawler/sync-state.js +287 -0
- package/srv/blockchain/signing/hsm-signer.d.ts +45 -0
- package/srv/blockchain/signing/hsm-signer.js +8 -1
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +20 -0
- package/srv/blockchain/transaction-building/buildooor-tx.js +104 -20
- package/srv/blockchain/wallet-worker/build-request.d.ts +26 -0
- package/srv/blockchain/wallet-worker/build-request.js +370 -0
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +117 -0
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +290 -0
- package/srv/blockchain/wallet-worker/index.d.ts +14 -0
- package/srv/blockchain/wallet-worker/index.js +80 -0
- package/srv/blockchain/wallet-worker/job-store.d.ts +272 -0
- package/srv/blockchain/wallet-worker/job-store.js +597 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +43 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +99 -0
- package/srv/blockchain/wallet-worker/signers.d.ts +57 -0
- package/srv/blockchain/wallet-worker/signers.js +131 -0
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +145 -0
- package/srv/blockchain/wallet-worker/wallet-worker.js +542 -0
- package/srv/cardano-agent-service.cds +150 -0
- package/srv/cardano-agent-service.d.ts +2 -0
- package/srv/cardano-agent-service.js +16 -0
- package/srv/cardano-indexer-service.cds +106 -0
- package/srv/cardano-indexer-service.d.ts +2 -0
- package/srv/cardano-indexer-service.js +79 -0
- package/srv/cardano-service.js +79 -4
- package/srv/cardano-sign-service.cds +200 -180
- package/srv/cardano-tx-service.cds +32 -26
- package/srv/cardano-tx-service.d.ts +1 -11
- package/srv/cardano-tx-service.js +107 -200
- package/srv/cardano-worker-service.cds +125 -0
- package/srv/cardano-worker-service.d.ts +2 -0
- package/srv/cardano-worker-service.js +199 -0
- package/srv/server.d.ts +34 -2
- package/srv/server.js +246 -36
- package/srv/utils/agent-grants-config.d.ts +65 -0
- package/srv/utils/agent-grants-config.js +148 -0
- package/srv/utils/agent-grants.d.ts +314 -0
- package/srv/utils/agent-grants.js +821 -0
- package/srv/utils/agent-token-auth.d.ts +19 -0
- package/srv/utils/agent-token-auth.js +81 -0
- package/srv/utils/collections.d.ts +13 -0
- package/srv/utils/collections.js +24 -0
- package/srv/utils/crypto.d.ts +16 -0
- package/srv/utils/crypto.js +75 -0
- package/srv/utils/db-sanitize.d.ts +40 -0
- package/srv/utils/db-sanitize.js +98 -0
- package/srv/utils/error-codes.d.ts +6 -0
- package/srv/utils/error-codes.js +6 -0
- package/srv/utils/errors.d.ts +12 -0
- package/srv/utils/errors.js +45 -0
- package/srv/utils/liveness.d.ts +23 -0
- package/srv/utils/liveness.js +49 -0
- package/srv/utils/mappers.d.ts +27 -0
- package/srv/utils/mappers.js +80 -10
- package/srv/utils/rate-limiter.d.ts +57 -0
- package/srv/utils/rate-limiter.js +126 -0
- package/srv/utils/service-events.d.ts +26 -0
- package/srv/utils/service-events.js +46 -0
- package/srv/utils/tx-request-parsers.d.ts +71 -0
- package/srv/utils/tx-request-parsers.js +202 -0
- package/srv/utils/tx-utils.d.ts +2 -1
- package/srv/utils/tx-utils.js +3 -2
- package/srv/utils/types.d.ts +17 -1
- package/@cds-models/CardanoODataService/index.d.ts.map +0 -1
- package/@cds-models/CardanoODataService/index.js.map +0 -1
- package/@cds-models/CardanoODataService/index.ts +0 -776
- package/@cds-models/CardanoSignService/index.d.ts.map +0 -1
- package/@cds-models/CardanoSignService/index.js.map +0 -1
- package/@cds-models/CardanoSignService/index.ts +0 -569
- package/@cds-models/CardanoTransactionService/index.d.ts.map +0 -1
- package/@cds-models/CardanoTransactionService/index.js.map +0 -1
- package/@cds-models/CardanoTransactionService/index.ts +0 -526
- package/@cds-models/_/index.d.ts.map +0 -1
- package/@cds-models/_/index.js.map +0 -1
- package/@cds-models/_/index.ts +0 -96
- package/@cds-models/cds/outbox/index.ts +0 -27
- package/@cds-models/index.d.ts.map +0 -1
- package/@cds-models/index.js.map +0 -1
- package/@cds-models/index.ts +0 -245
- package/@cds-models/odatano/cardano/index.d.ts.map +0 -1
- package/@cds-models/odatano/cardano/index.js.map +0 -1
- package/@cds-models/odatano/cardano/index.ts +0 -789
- package/@cds-models/sap/common/index.d.ts.map +0 -1
- package/@cds-models/sap/common/index.js.map +0 -1
- package/@cds-models/sap/common/index.ts +0 -249
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `x-agent-token` transport lane for `@odatano/cap-auth`: a token on one
|
|
3
|
+
* of the ODATANO service paths is authenticated here (unknown 401, expired
|
|
4
|
+
* 410, non-leaking) and the request continues as `agent:<grantId>` with the
|
|
5
|
+
* role `agent-grant`; the grant rides on the express request for the
|
|
6
|
+
* enforcement hook. A token on any other path is left to the delegate.
|
|
7
|
+
* Failed attempts are throttled per client address (20 per 15 minutes).
|
|
8
|
+
*/
|
|
9
|
+
import { type TransportLane } from '@odatano/cap-auth';
|
|
10
|
+
/** Test seam: pin the service paths instead of reading `cds.services`. `null` resets. */
|
|
11
|
+
export declare function __setAgentServicePathsForTests(paths: string[] | null): void;
|
|
12
|
+
/** Forget throttle state and the path cache (tests). */
|
|
13
|
+
export declare function __resetAgentTokenLaneForTests(): void;
|
|
14
|
+
/** Mount paths of the six services, read from `cds.services` once they are served. */
|
|
15
|
+
export declare function agentServicePaths(): string[];
|
|
16
|
+
/** Exact segment boundary: `/odata/v4/cardano-odata` and below, never `/odata/v4/cardano-odata-evil`. */
|
|
17
|
+
export declare function inAgentLane(path: string, servicePaths?: string[]): boolean;
|
|
18
|
+
export declare const agentTokenLane: TransportLane;
|
|
19
|
+
//# sourceMappingURL=agent-token-auth.d.ts.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The `x-agent-token` transport lane for `@odatano/cap-auth`: a token on one
|
|
4
|
+
* of the ODATANO service paths is authenticated here (unknown 401, expired
|
|
5
|
+
* 410, non-leaking) and the request continues as `agent:<grantId>` with the
|
|
6
|
+
* role `agent-grant`; the grant rides on the express request for the
|
|
7
|
+
* enforcement hook. A token on any other path is left to the delegate.
|
|
8
|
+
* Failed attempts are throttled per client address (20 per 15 minutes).
|
|
9
|
+
*/
|
|
10
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.agentTokenLane = void 0;
|
|
15
|
+
exports.__setAgentServicePathsForTests = __setAgentServicePathsForTests;
|
|
16
|
+
exports.__resetAgentTokenLaneForTests = __resetAgentTokenLaneForTests;
|
|
17
|
+
exports.agentServicePaths = agentServicePaths;
|
|
18
|
+
exports.inAgentLane = inAgentLane;
|
|
19
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
20
|
+
const cap_auth_1 = require("@odatano/cap-auth");
|
|
21
|
+
const agent_grants_1 = require("./agent-grants");
|
|
22
|
+
const rate_limiter_1 = require("./rate-limiter");
|
|
23
|
+
const tokenFailures = new rate_limiter_1.RateLimiter({ windowMs: 15 * 60 * 1000, maxRequests: 20, maxKeys: 10_000 });
|
|
24
|
+
let servicePathsCache = null;
|
|
25
|
+
let servicePathsPinned = false;
|
|
26
|
+
/** Test seam: pin the service paths instead of reading `cds.services`. `null` resets. */
|
|
27
|
+
function __setAgentServicePathsForTests(paths) {
|
|
28
|
+
servicePathsCache = paths;
|
|
29
|
+
servicePathsPinned = paths !== null;
|
|
30
|
+
}
|
|
31
|
+
/** Forget throttle state and the path cache (tests). */
|
|
32
|
+
function __resetAgentTokenLaneForTests() {
|
|
33
|
+
tokenFailures.reset();
|
|
34
|
+
servicePathsCache = null;
|
|
35
|
+
servicePathsPinned = false;
|
|
36
|
+
}
|
|
37
|
+
/** Mount paths of the six services, read from `cds.services` once they are served. */
|
|
38
|
+
function agentServicePaths() {
|
|
39
|
+
if (servicePathsPinned && servicePathsCache)
|
|
40
|
+
return servicePathsCache;
|
|
41
|
+
if (servicePathsCache && servicePathsCache.length === agent_grants_1.AGENT_SERVICE_NAMES.length)
|
|
42
|
+
return servicePathsCache;
|
|
43
|
+
const services = cds_1.default.services ?? {};
|
|
44
|
+
const paths = Object.values(services)
|
|
45
|
+
.filter((s) => s && agent_grants_1.AGENT_SERVICE_NAMES.includes(String(s.name)) && typeof s.path === 'string')
|
|
46
|
+
.map((s) => String(s.path).replace(/\/+$/, ''));
|
|
47
|
+
servicePathsCache = paths;
|
|
48
|
+
return paths;
|
|
49
|
+
}
|
|
50
|
+
/** Exact segment boundary: `/odata/v4/cardano-odata` and below, never `/odata/v4/cardano-odata-evil`. */
|
|
51
|
+
function inAgentLane(path, servicePaths = agentServicePaths()) {
|
|
52
|
+
const bare = path.split('?')[0];
|
|
53
|
+
return servicePaths.some((p) => (0, cap_auth_1.inLaneOf)(bare, p));
|
|
54
|
+
}
|
|
55
|
+
function clientKey(req) {
|
|
56
|
+
const ip = req.ip ?? req.socket?.remoteAddress ?? 'unknown';
|
|
57
|
+
return `ip=${String(ip).replace(/:/g, '.')}:agent-token`;
|
|
58
|
+
}
|
|
59
|
+
exports.agentTokenLane = {
|
|
60
|
+
name: 'agent-token',
|
|
61
|
+
match: (req) => typeof req.headers?.[agent_grants_1.AGENT_TOKEN_HEADER] === 'string' && req.headers[agent_grants_1.AGENT_TOKEN_HEADER].length > 0,
|
|
62
|
+
authenticate: async (req, res) => {
|
|
63
|
+
const token = req.headers[agent_grants_1.AGENT_TOKEN_HEADER];
|
|
64
|
+
if (!inAgentLane((0, cap_auth_1.requestPath)(req)))
|
|
65
|
+
return { next: true };
|
|
66
|
+
const key = clientKey(req);
|
|
67
|
+
const locked = tokenFailures.peek(key);
|
|
68
|
+
if (!locked.allowed)
|
|
69
|
+
return (0, cap_auth_1.respondError)(res, 429, 'Too many failed agent token attempts', locked.retryAfterMs);
|
|
70
|
+
const resolution = await (0, agent_grants_1.resolveAgentToken)(token);
|
|
71
|
+
if (!resolution.ok) {
|
|
72
|
+
const failed = tokenFailures.check(key);
|
|
73
|
+
if (!failed.allowed)
|
|
74
|
+
return (0, cap_auth_1.respondError)(res, 429, 'Too many failed agent token attempts', failed.retryAfterMs);
|
|
75
|
+
return (0, cap_auth_1.respondError)(res, resolution.status, resolution.message);
|
|
76
|
+
}
|
|
77
|
+
req.agentGrant = resolution.grant;
|
|
78
|
+
return { user: (0, agent_grants_1.makeAgentUser)(resolution.grant) };
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=agent-token-auth.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small collection helpers shared across the blockchain layer.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Split an array into fixed-size chunks. Used to keep CQL IN-lists below DB driver
|
|
6
|
+
* bind-variable limits (SQLite caps at 999 on older builds / 32766 on node:sqlite).
|
|
7
|
+
* @param arr source array (not mutated)
|
|
8
|
+
* @param size chunk size (must be > 0; guarded to avoid an infinite loop)
|
|
9
|
+
*/
|
|
10
|
+
export declare function chunk<T>(arr: T[], size: number): T[][];
|
|
11
|
+
/** Max bind variables per IN-list — well below every supported driver's cap. */
|
|
12
|
+
export declare const IN_CHUNK = 500;
|
|
13
|
+
//# sourceMappingURL=collections.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Small collection helpers shared across the blockchain layer.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.IN_CHUNK = void 0;
|
|
7
|
+
exports.chunk = chunk;
|
|
8
|
+
/**
|
|
9
|
+
* Split an array into fixed-size chunks. Used to keep CQL IN-lists below DB driver
|
|
10
|
+
* bind-variable limits (SQLite caps at 999 on older builds / 32766 on node:sqlite).
|
|
11
|
+
* @param arr source array (not mutated)
|
|
12
|
+
* @param size chunk size (must be > 0; guarded to avoid an infinite loop)
|
|
13
|
+
*/
|
|
14
|
+
function chunk(arr, size) {
|
|
15
|
+
if (size <= 0)
|
|
16
|
+
throw new RangeError(`chunk size must be > 0, got ${size}`);
|
|
17
|
+
const out = [];
|
|
18
|
+
for (let i = 0; i < arr.length; i += size)
|
|
19
|
+
out.push(arr.slice(i, i + size));
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
/** Max bind variables per IN-list — well below every supported driver's cap. */
|
|
23
|
+
exports.IN_CHUNK = 500;
|
|
24
|
+
//# sourceMappingURL=collections.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive the 32-byte encryption key from the environment.
|
|
3
|
+
* Production: ENCRYPTION_KEY is required. Development: process-scoped fallback.
|
|
4
|
+
*/
|
|
5
|
+
export declare function getEncryptionKey(): Buffer;
|
|
6
|
+
/**
|
|
7
|
+
* Encrypt plaintext with AES-256-GCM.
|
|
8
|
+
* Returns the combined format `base64(iv):base64(authTag):base64(ciphertext)`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function encrypt(plaintext: string, key: Buffer): string;
|
|
11
|
+
/**
|
|
12
|
+
* Decrypt a combined `iv:authTag:ciphertext` string back to plaintext.
|
|
13
|
+
* Throws on authentication failure (tampered ciphertext or wrong key).
|
|
14
|
+
*/
|
|
15
|
+
export declare function decrypt(combined: string, key: Buffer): string;
|
|
16
|
+
//# sourceMappingURL=crypto.d.ts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
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.getEncryptionKey = getEncryptionKey;
|
|
7
|
+
exports.encrypt = encrypt;
|
|
8
|
+
exports.decrypt = decrypt;
|
|
9
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
10
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
11
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
12
|
+
const logger = cds_1.default.log('CardanoWalletWorker');
|
|
13
|
+
/**
|
|
14
|
+
* AES-256-GCM utilities for secrets at rest (v2.0 wallet worker).
|
|
15
|
+
*
|
|
16
|
+
* Ported from NIGHTGATE's srv/utils/crypto.ts. Used to decrypt operator-provided
|
|
17
|
+
* software signing keys (`iv:authTag:ciphertext`, all base64). Keys are derived
|
|
18
|
+
* from the ENCRYPTION_KEY environment variable; production refuses to start
|
|
19
|
+
* without it, development falls back to a process-scoped key.
|
|
20
|
+
*/
|
|
21
|
+
const ALGORITHM = 'aes-256-gcm';
|
|
22
|
+
const IV_LENGTH = 12; // 96 bits, recommended for GCM
|
|
23
|
+
const AUTH_TAG_LENGTH = 16; // 128 bits
|
|
24
|
+
/**
|
|
25
|
+
* Derive the 32-byte encryption key from the environment.
|
|
26
|
+
* Production: ENCRYPTION_KEY is required. Development: process-scoped fallback.
|
|
27
|
+
*/
|
|
28
|
+
function getEncryptionKey() {
|
|
29
|
+
const envKey = process.env.ENCRYPTION_KEY;
|
|
30
|
+
if (envKey) {
|
|
31
|
+
return node_crypto_1.default.createHash('sha256').update(envKey).digest();
|
|
32
|
+
}
|
|
33
|
+
if (process.env.NODE_ENV === 'production') {
|
|
34
|
+
throw new Error('ENCRYPTION_KEY must be set in production. Refusing to start with a fallback key.');
|
|
35
|
+
}
|
|
36
|
+
logger.warn('ENCRYPTION_KEY not set — using dev fallback key. Set ENCRYPTION_KEY for production.');
|
|
37
|
+
const fallback = `odatano-core-${process.pid}-${node_os_1.default.hostname()}`;
|
|
38
|
+
return node_crypto_1.default.createHash('sha256').update(fallback).digest();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Encrypt plaintext with AES-256-GCM.
|
|
42
|
+
* Returns the combined format `base64(iv):base64(authTag):base64(ciphertext)`.
|
|
43
|
+
*/
|
|
44
|
+
function encrypt(plaintext, key) {
|
|
45
|
+
const iv = node_crypto_1.default.randomBytes(IV_LENGTH);
|
|
46
|
+
const cipher = node_crypto_1.default.createCipheriv(ALGORITHM, key, iv, { authTagLength: AUTH_TAG_LENGTH });
|
|
47
|
+
const encrypted = Buffer.concat([cipher.update(plaintext, 'utf8'), cipher.final()]);
|
|
48
|
+
const authTag = cipher.getAuthTag();
|
|
49
|
+
return `${iv.toString('base64')}:${authTag.toString('base64')}:${encrypted.toString('base64')}`;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Decrypt a combined `iv:authTag:ciphertext` string back to plaintext.
|
|
53
|
+
* Throws on authentication failure (tampered ciphertext or wrong key).
|
|
54
|
+
*/
|
|
55
|
+
function decrypt(combined, key) {
|
|
56
|
+
const parts = combined.split(':');
|
|
57
|
+
if (parts.length !== 3) {
|
|
58
|
+
throw new Error('Invalid encrypted format: expected iv:authTag:ciphertext');
|
|
59
|
+
}
|
|
60
|
+
const [ivB64, tagB64, dataB64] = parts;
|
|
61
|
+
const iv = Buffer.from(ivB64, 'base64');
|
|
62
|
+
const authTag = Buffer.from(tagB64, 'base64');
|
|
63
|
+
const encrypted = Buffer.from(dataB64, 'base64');
|
|
64
|
+
if (iv.length !== IV_LENGTH) {
|
|
65
|
+
throw new Error(`Invalid IV length: expected ${IV_LENGTH} bytes, got ${iv.length}`);
|
|
66
|
+
}
|
|
67
|
+
if (authTag.length !== AUTH_TAG_LENGTH) {
|
|
68
|
+
throw new Error(`Invalid auth tag length: expected ${AUTH_TAG_LENGTH} bytes, got ${authTag.length}`);
|
|
69
|
+
}
|
|
70
|
+
const decipher = node_crypto_1.default.createDecipheriv(ALGORITHM, key, iv, { authTagLength: AUTH_TAG_LENGTH });
|
|
71
|
+
decipher.setAuthTag(authTag);
|
|
72
|
+
const decrypted = Buffer.concat([decipher.update(encrypted), decipher.final()]);
|
|
73
|
+
return decrypted.toString('utf8');
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Last line of defence before writes to PostgreSQL.
|
|
3
|
+
*
|
|
4
|
+
* PostgreSQL cannot store U+0000 in `text`, and @cap-js/postgres passes bulk
|
|
5
|
+
* INSERT/UPSERT rows as one JSON document whose parser rejects the escape
|
|
6
|
+
* sequence for NUL ("unsupported Unicode escape sequence"). A single decoded
|
|
7
|
+
* string with a NUL character therefore fails the whole write — a crawled block
|
|
8
|
+
* or a lazily indexed request alike. Mappers avoid producing such strings (see
|
|
9
|
+
* decodeAssetName); installDbSanitizer() guarantees it for every row this plugin
|
|
10
|
+
* writes, whatever the source (provider JSON such as Koios' asset_name_ascii or
|
|
11
|
+
* pool metadata included), by hooking the database service once per process.
|
|
12
|
+
*/
|
|
13
|
+
/** Remove U+0000 from every string value of the row (nested plain objects included). Returns the same row when nothing changed. */
|
|
14
|
+
export declare function stripNulStrings<T>(row: T): T;
|
|
15
|
+
/** Sanitise a row array for the database; cheap when nothing needs changing. */
|
|
16
|
+
export declare function sanitizeRows<T>(rows: T[]): T[];
|
|
17
|
+
/** The slice of a db-service request the sanitizer looks at (structural, so tests can fake it). */
|
|
18
|
+
export interface DbWriteRequest {
|
|
19
|
+
query?: unknown;
|
|
20
|
+
target?: {
|
|
21
|
+
name?: string;
|
|
22
|
+
} | null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* `before` handler for the database service: strips U+0000 from the rows of an
|
|
26
|
+
* INSERT / UPSERT / UPDATE against one of this plugin's entities, in place.
|
|
27
|
+
*/
|
|
28
|
+
export declare function sanitizeDbRequest(req: DbWriteRequest): void;
|
|
29
|
+
interface HookableService {
|
|
30
|
+
before(event: string | string[], handler: (req: DbWriteRequest) => void): unknown;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Hook the sanitizer into the database service (idempotent per service instance).
|
|
34
|
+
* Called from the app-context bootstrap; a missing/unconnected db is a no-op so
|
|
35
|
+
* unit tests and early programmatic initialize() calls never fail here.
|
|
36
|
+
* @returns true when the hook was installed by this call
|
|
37
|
+
*/
|
|
38
|
+
export declare function installDbSanitizer(db?: HookableService | undefined): boolean;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=db-sanitize.d.ts.map
|
|
@@ -0,0 +1,98 @@
|
|
|
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.stripNulStrings = stripNulStrings;
|
|
7
|
+
exports.sanitizeRows = sanitizeRows;
|
|
8
|
+
exports.sanitizeDbRequest = sanitizeDbRequest;
|
|
9
|
+
exports.installDbSanitizer = installDbSanitizer;
|
|
10
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
11
|
+
/**
|
|
12
|
+
* Last line of defence before writes to PostgreSQL.
|
|
13
|
+
*
|
|
14
|
+
* PostgreSQL cannot store U+0000 in `text`, and @cap-js/postgres passes bulk
|
|
15
|
+
* INSERT/UPSERT rows as one JSON document whose parser rejects the escape
|
|
16
|
+
* sequence for NUL ("unsupported Unicode escape sequence"). A single decoded
|
|
17
|
+
* string with a NUL character therefore fails the whole write — a crawled block
|
|
18
|
+
* or a lazily indexed request alike. Mappers avoid producing such strings (see
|
|
19
|
+
* decodeAssetName); installDbSanitizer() guarantees it for every row this plugin
|
|
20
|
+
* writes, whatever the source (provider JSON such as Koios' asset_name_ascii or
|
|
21
|
+
* pool metadata included), by hooking the database service once per process.
|
|
22
|
+
*/
|
|
23
|
+
/** Remove U+0000 from every string value of the row (nested plain objects included). Returns the same row when nothing changed. */
|
|
24
|
+
function stripNulStrings(row) {
|
|
25
|
+
if (typeof row === 'string')
|
|
26
|
+
return (row.includes('\u0000') ? row.replaceAll('\u0000', '') : row);
|
|
27
|
+
if (row === null || typeof row !== 'object' || Buffer.isBuffer(row))
|
|
28
|
+
return row;
|
|
29
|
+
if (Array.isArray(row)) {
|
|
30
|
+
let out = null;
|
|
31
|
+
for (let i = 0; i < row.length; i++) {
|
|
32
|
+
const v = stripNulStrings(row[i]);
|
|
33
|
+
if (v !== row[i]) {
|
|
34
|
+
out ??= [...row];
|
|
35
|
+
out[i] = v;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return (out ?? row);
|
|
39
|
+
}
|
|
40
|
+
let out = null;
|
|
41
|
+
for (const [k, v] of Object.entries(row)) {
|
|
42
|
+
const nv = stripNulStrings(v);
|
|
43
|
+
if (nv !== v) {
|
|
44
|
+
out ??= { ...row };
|
|
45
|
+
out[k] = nv;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return (out ?? row);
|
|
49
|
+
}
|
|
50
|
+
/** Sanitise a row array for the database; cheap when nothing needs changing. */
|
|
51
|
+
function sanitizeRows(rows) {
|
|
52
|
+
let out = null;
|
|
53
|
+
for (let i = 0; i < rows.length; i++) {
|
|
54
|
+
const r = stripNulStrings(rows[i]);
|
|
55
|
+
if (r !== rows[i]) {
|
|
56
|
+
out ??= [...rows];
|
|
57
|
+
out[i] = r;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return out ?? rows;
|
|
61
|
+
}
|
|
62
|
+
/** Only this plugin's entities are rewritten — a consumer's own data is never touched. */
|
|
63
|
+
const OWN_NAMESPACE = 'odatano.cardano.';
|
|
64
|
+
/**
|
|
65
|
+
* `before` handler for the database service: strips U+0000 from the rows of an
|
|
66
|
+
* INSERT / UPSERT / UPDATE against one of this plugin's entities, in place.
|
|
67
|
+
*/
|
|
68
|
+
function sanitizeDbRequest(req) {
|
|
69
|
+
if (!req.target?.name?.startsWith(OWN_NAMESPACE))
|
|
70
|
+
return;
|
|
71
|
+
const q = req.query;
|
|
72
|
+
if (!q || typeof q !== 'object')
|
|
73
|
+
return;
|
|
74
|
+
const ins = q.INSERT;
|
|
75
|
+
if (ins && Array.isArray(ins.entries))
|
|
76
|
+
ins.entries = sanitizeRows(ins.entries);
|
|
77
|
+
const ups = q.UPSERT;
|
|
78
|
+
if (ups && Array.isArray(ups.entries))
|
|
79
|
+
ups.entries = sanitizeRows(ups.entries);
|
|
80
|
+
const upd = q.UPDATE;
|
|
81
|
+
if (upd?.data && typeof upd.data === 'object')
|
|
82
|
+
upd.data = stripNulStrings(upd.data);
|
|
83
|
+
}
|
|
84
|
+
const installed = new WeakSet();
|
|
85
|
+
/**
|
|
86
|
+
* Hook the sanitizer into the database service (idempotent per service instance).
|
|
87
|
+
* Called from the app-context bootstrap; a missing/unconnected db is a no-op so
|
|
88
|
+
* unit tests and early programmatic initialize() calls never fail here.
|
|
89
|
+
* @returns true when the hook was installed by this call
|
|
90
|
+
*/
|
|
91
|
+
function installDbSanitizer(db = cds_1.default.db) {
|
|
92
|
+
if (!db || typeof db.before !== 'function' || installed.has(db))
|
|
93
|
+
return false;
|
|
94
|
+
db.before(['CREATE', 'UPSERT', 'UPDATE'], sanitizeDbRequest);
|
|
95
|
+
installed.add(db);
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=db-sanitize.js.map
|
|
@@ -7,6 +7,12 @@ export declare const ERROR_CODES: {
|
|
|
7
7
|
* Indicates that the input provided by the client is invalid (malformed address, invalid transaction hash, etc.)
|
|
8
8
|
*/
|
|
9
9
|
readonly INVALID_INPUT: "ODATANO_INVALID_INPUT";
|
|
10
|
+
/**
|
|
11
|
+
* 403 – Caller lacks the required role
|
|
12
|
+
* Indicates the caller is authenticated but not authorized for the operation
|
|
13
|
+
* (e.g. HSM-backed signing without the configured hsm.requiresRole)
|
|
14
|
+
*/
|
|
15
|
+
readonly FORBIDDEN: "ODATANO_FORBIDDEN";
|
|
10
16
|
/**
|
|
11
17
|
* 404 – Data not found
|
|
12
18
|
* Indicates that the requested resource could not be found (Empty result set Address with no UTxOs, Transaction hash not found, etc.)
|
package/srv/utils/error-codes.js
CHANGED
|
@@ -10,6 +10,12 @@ exports.ERROR_CODES = {
|
|
|
10
10
|
* Indicates that the input provided by the client is invalid (malformed address, invalid transaction hash, etc.)
|
|
11
11
|
*/
|
|
12
12
|
INVALID_INPUT: 'ODATANO_INVALID_INPUT',
|
|
13
|
+
/**
|
|
14
|
+
* 403 – Caller lacks the required role
|
|
15
|
+
* Indicates the caller is authenticated but not authorized for the operation
|
|
16
|
+
* (e.g. HSM-backed signing without the configured hsm.requiresRole)
|
|
17
|
+
*/
|
|
18
|
+
FORBIDDEN: 'ODATANO_FORBIDDEN',
|
|
13
19
|
/**
|
|
14
20
|
* 404 – Data not found
|
|
15
21
|
* Indicates that the requested resource could not be found (Empty result set Address with no UTxOs, Transaction hash not found, etc.)
|
package/srv/utils/errors.d.ts
CHANGED
|
@@ -151,6 +151,16 @@ export declare class AllBackendsFailedError extends BackendError {
|
|
|
151
151
|
*/
|
|
152
152
|
constructor(errors: BackendError[], originalError?: unknown);
|
|
153
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* True when the error proves the resource is absent on EVERY backend that was
|
|
156
|
+
* consulted: either a direct NotFoundError, or an AllBackendsFailedError whose
|
|
157
|
+
* collected per-backend errors are all 404s. CardanoClient's failover wraps
|
|
158
|
+
* per-backend errors (including 404s) into AllBackendsFailedError, so callers
|
|
159
|
+
* that need "definitively not found" (e.g. the wallet-worker's dropped-tx
|
|
160
|
+
* detection) must use this instead of `instanceof NotFoundError`. A mixed
|
|
161
|
+
* result (one backend 404, another 500) is NOT proof of absence.
|
|
162
|
+
*/
|
|
163
|
+
export declare function isNotFoundOnAllBackends(err: unknown): boolean;
|
|
154
164
|
/**
|
|
155
165
|
* HttpErrorLike - Simplified interface for HTTP errors from various libraries
|
|
156
166
|
*/
|
|
@@ -169,6 +179,8 @@ export interface HttpErrorLike {
|
|
|
169
179
|
};
|
|
170
180
|
[k: string]: unknown;
|
|
171
181
|
}
|
|
182
|
+
/** True when a PostgREST error body's `code` denotes a provider-side SQL fault. */
|
|
183
|
+
export declare function isPostgrestServerErrorCode(code: unknown): boolean;
|
|
172
184
|
/**
|
|
173
185
|
* Utility functions to extract status and message from HttpErrorLike
|
|
174
186
|
* @param err error object
|
package/srv/utils/errors.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AllBackendsInitFailedError = exports.BackendInitError = exports.ConfigError = exports.HsmError = exports.AllBackendsFailedError = exports.RateLimitError = exports.ProviderUnavailableError = exports.MixedAssetsError = exports.InsufficientFundsError = exports.TransactionAlreadySubmittedError = exports.ScriptValidationError = exports.TransactionValidationError = exports.NotFoundError = exports.BackendError = void 0;
|
|
4
|
+
exports.isNotFoundOnAllBackends = isNotFoundOnAllBackends;
|
|
5
|
+
exports.isPostgrestServerErrorCode = isPostgrestServerErrorCode;
|
|
4
6
|
exports.getErrorStatus = getErrorStatus;
|
|
5
7
|
exports.getErrorMessage = getErrorMessage;
|
|
6
8
|
exports.normalizeBackendError = normalizeBackendError;
|
|
@@ -217,6 +219,38 @@ class AllBackendsFailedError extends BackendError {
|
|
|
217
219
|
}
|
|
218
220
|
}
|
|
219
221
|
exports.AllBackendsFailedError = AllBackendsFailedError;
|
|
222
|
+
/**
|
|
223
|
+
* True when the error proves the resource is absent on EVERY backend that was
|
|
224
|
+
* consulted: either a direct NotFoundError, or an AllBackendsFailedError whose
|
|
225
|
+
* collected per-backend errors are all 404s. CardanoClient's failover wraps
|
|
226
|
+
* per-backend errors (including 404s) into AllBackendsFailedError, so callers
|
|
227
|
+
* that need "definitively not found" (e.g. the wallet-worker's dropped-tx
|
|
228
|
+
* detection) must use this instead of `instanceof NotFoundError`. A mixed
|
|
229
|
+
* result (one backend 404, another 500) is NOT proof of absence.
|
|
230
|
+
*/
|
|
231
|
+
function isNotFoundOnAllBackends(err) {
|
|
232
|
+
if (err instanceof NotFoundError)
|
|
233
|
+
return true;
|
|
234
|
+
return err instanceof AllBackendsFailedError
|
|
235
|
+
&& err.errors.length > 0
|
|
236
|
+
&& err.errors.every((e) => e instanceof NotFoundError || e.statusCode === 404);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* PostgreSQL error-code classes that indicate a fault in the provider's own
|
|
240
|
+
* database/deployment rather than in our request. Koios (PostgREST) surfaces
|
|
241
|
+
* these as HTTP 400 — e.g. code '42703' ("column … does not exist") from a
|
|
242
|
+
* half-migrated SQL function on one load-balanced instance, or '57014'
|
|
243
|
+
* (statement timeout) under load. Client-input errors (class 22, invalid text
|
|
244
|
+
* representation etc.) are deliberately NOT listed — those remain 4xx.
|
|
245
|
+
* Classes: 08 connection, 42 syntax/undefined object, 53 insufficient
|
|
246
|
+
* resources, 57 operator intervention (incl. query_canceled), 58 system
|
|
247
|
+
* error, XX internal error.
|
|
248
|
+
*/
|
|
249
|
+
const PG_SERVER_ERROR_CODE_CLASSES = ['08', '42', '53', '57', '58', 'XX'];
|
|
250
|
+
/** True when a PostgREST error body's `code` denotes a provider-side SQL fault. */
|
|
251
|
+
function isPostgrestServerErrorCode(code) {
|
|
252
|
+
return typeof code === 'string' && PG_SERVER_ERROR_CODE_CLASSES.some(c => code.startsWith(c));
|
|
253
|
+
}
|
|
220
254
|
/**
|
|
221
255
|
* Utility functions to extract status and message from HttpErrorLike
|
|
222
256
|
* @param err error object
|
|
@@ -326,6 +360,17 @@ function normalizeBackendError(err, backendName) {
|
|
|
326
360
|
if (validationErrorHints.some(h => messageLower.includes(h))) {
|
|
327
361
|
return new TransactionValidationError(`Transaction validation failed: ${message}`, err);
|
|
328
362
|
}
|
|
363
|
+
// Priority 3b: PostgREST server-side SQL faults surfaced as HTTP 400 (Koios).
|
|
364
|
+
// Body shape: { code: '42703', message: 'column … does not exist' } (broken
|
|
365
|
+
// SQL function on one LB instance) or { code: '57014' } (statement timeout).
|
|
366
|
+
// These are provider faults, not request validation — classify as retry-able
|
|
367
|
+
// 503 so multi-backend failover and the circuit breaker treat them like any
|
|
368
|
+
// other provider outage. Checked before Priority 4: the PostgREST message
|
|
369
|
+
// ("column … does not exist") would otherwise be misread as a resource 404.
|
|
370
|
+
const pgErrorBody = err?.response?.data;
|
|
371
|
+
if ((status === 400 || status === 422) && isPostgrestServerErrorCode(pgErrorBody?.code)) {
|
|
372
|
+
return new ProviderUnavailableError(`Provider database error (${pgErrorBody?.code}): ${pgErrorBody?.message ?? message}`, backendName, undefined, err);
|
|
373
|
+
}
|
|
329
374
|
// Priority 4: Message indicates "not found" or equivalent → always 404.
|
|
330
375
|
// This also handles providers returning wrong status codes for missing
|
|
331
376
|
// resources. Deliberately NOT here: 'not available' / bare 'no data' — those
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Liveness body for CardanoIndexerService.getLiveness() (unauthenticated,
|
|
3
|
+
* `@requires: 'any'`): process facts only. Never touches the app context, the
|
|
4
|
+
* backends or the DB, so it answers while those are still initializing or have
|
|
5
|
+
* failed — that is what a liveness probe is for; readiness stays with
|
|
6
|
+
* getStatus and the backend health entities, which remain authenticated.
|
|
7
|
+
*
|
|
8
|
+
* No secrets, no backend names, no API key state. Mirrors NIGHTGATE's
|
|
9
|
+
* `/api/v1/indexer/getLiveness()` (status 'alive', timestamp, uptime), plus the
|
|
10
|
+
* package version and the configured network.
|
|
11
|
+
*/
|
|
12
|
+
export interface Liveness {
|
|
13
|
+
status: 'alive';
|
|
14
|
+
timestamp: string;
|
|
15
|
+
/** Seconds since the process started. */
|
|
16
|
+
uptime: number;
|
|
17
|
+
/** @odatano/core version; '' when package.json is not where the in-place build puts it. */
|
|
18
|
+
version: string;
|
|
19
|
+
/** Configured network (cds.requires.odatano-core.network, NETWORK, default preview). */
|
|
20
|
+
network: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function buildLiveness(now?: Date): Liveness;
|
|
23
|
+
//# sourceMappingURL=liveness.d.ts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Liveness body for CardanoIndexerService.getLiveness() (unauthenticated,
|
|
4
|
+
* `@requires: 'any'`): process facts only. Never touches the app context, the
|
|
5
|
+
* backends or the DB, so it answers while those are still initializing or have
|
|
6
|
+
* failed — that is what a liveness probe is for; readiness stays with
|
|
7
|
+
* getStatus and the backend health entities, which remain authenticated.
|
|
8
|
+
*
|
|
9
|
+
* No secrets, no backend names, no API key state. Mirrors NIGHTGATE's
|
|
10
|
+
* `/api/v1/indexer/getLiveness()` (status 'alive', timestamp, uptime), plus the
|
|
11
|
+
* package version and the configured network.
|
|
12
|
+
*/
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.buildLiveness = buildLiveness;
|
|
18
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
19
|
+
const path_1 = __importDefault(require("path"));
|
|
20
|
+
const processStartedAt = Date.now();
|
|
21
|
+
let cachedVersion = null;
|
|
22
|
+
function packageVersion() {
|
|
23
|
+
if (cachedVersion !== null)
|
|
24
|
+
return cachedVersion;
|
|
25
|
+
try {
|
|
26
|
+
// srv/utils → package root; the build compiles in place, so this holds in
|
|
27
|
+
// standalone and plugin mode alike.
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
29
|
+
const pkg = require(path_1.default.resolve(__dirname, '..', '..', 'package.json'));
|
|
30
|
+
cachedVersion = String(pkg.version ?? '');
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
cachedVersion = '';
|
|
34
|
+
}
|
|
35
|
+
return cachedVersion;
|
|
36
|
+
}
|
|
37
|
+
function buildLiveness(now = new Date()) {
|
|
38
|
+
const requires = (cds_1.default.env?.requires ?? {});
|
|
39
|
+
const core = (requires['odatano-core'] ?? {});
|
|
40
|
+
const network = String(core.network || process.env.NETWORK || 'preview');
|
|
41
|
+
return {
|
|
42
|
+
status: 'alive',
|
|
43
|
+
timestamp: now.toISOString(),
|
|
44
|
+
uptime: Math.max(0, Math.floor((now.getTime() - processStartedAt) / 1000)),
|
|
45
|
+
version: packageVersion(),
|
|
46
|
+
network,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=liveness.js.map
|
package/srv/utils/mappers.d.ts
CHANGED
|
@@ -118,6 +118,19 @@ export declare function mapEpoch(providerEpochData: EpochProviderData): EpochRow
|
|
|
118
118
|
* @returns {TransactionMetadataRow[]} mapped transaction metadata rows
|
|
119
119
|
*/
|
|
120
120
|
export declare function mapTransactionMetadata(providerLabels: MetadataLabelTxProviderData[]): TransactionMetadataRow[];
|
|
121
|
+
/**
|
|
122
|
+
* Metadata labels are uint64, the `TransactionMetadata.id` key is Integer64 (int64).
|
|
123
|
+
* Labels >= 2^63 are mapped through two's complement (BigInt.asIntN) so they stay
|
|
124
|
+
* unique and in range – preprod tx ee4f7c88… carries label 17802948329108123211,
|
|
125
|
+
* which PostgreSQL rejected as "out of range for type bigint" and halted the
|
|
126
|
+
* crawler. Beyond 2^53 the value is passed as a decimal string so that no
|
|
127
|
+
* precision is lost on the way to the database (CAP accepts strings for
|
|
128
|
+
* Integer64); `label` always keeps the original text.
|
|
129
|
+
*
|
|
130
|
+
* @returns the int64 key, or null when the label is not a non-negative integer
|
|
131
|
+
* (the caller skips the row — a NaN key would fail the whole bulk write)
|
|
132
|
+
*/
|
|
133
|
+
export declare function metadataIdFor(label: string | number): number | string | null;
|
|
121
134
|
/**
|
|
122
135
|
* Map Pool Data
|
|
123
136
|
* Converts provider pool data into PoolRow format
|
|
@@ -243,6 +256,20 @@ export declare function mapAddressTransactionBuild(addr: string, buildId: string
|
|
|
243
256
|
* @returns Object with all cost model values as number arrays in canonical order
|
|
244
257
|
*/
|
|
245
258
|
export declare function normalizeCostModels(raw: Record<string, unknown>): Record<string, number[]>;
|
|
259
|
+
/**
|
|
260
|
+
* Decode an asset name (hex bytes) into its display string.
|
|
261
|
+
*
|
|
262
|
+
* Asset names are arbitrary bytes. When they are not valid UTF-8, or when they
|
|
263
|
+
* contain U+0000, the hex form is returned unchanged: PostgreSQL rejects NUL in
|
|
264
|
+
* `text` and in the JSON documents @cap-js/postgres uses for bulk INSERT/UPSERT
|
|
265
|
+
* ("unsupported Unicode escape sequence"), which halted the crawler on preprod
|
|
266
|
+
* block 4281919 (asset name ending in 0x00). SQLite accepted the same bytes
|
|
267
|
+
* silently. `assetNameHex` always keeps the exact bytes, so nothing is lost.
|
|
268
|
+
*
|
|
269
|
+
* @param hex - asset name as hex string
|
|
270
|
+
* @returns UTF-8 text, or the hex string when the bytes are not clean text
|
|
271
|
+
*/
|
|
272
|
+
export declare function decodeAssetName(hex: string): string;
|
|
246
273
|
/**
|
|
247
274
|
* Compute CIP-14 asset fingerprint from policyId and assetName.
|
|
248
275
|
* Algorithm: bech32_encode("asset", blake2b_160(policyId_bytes + assetName_bytes))
|