@odatano/core 2.0.0-rc.5 → 2.0.0-rc.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@cds-models/CardanoAgentService/index.d.ts +99 -51
- package/@cds-models/CardanoAgentService/index.js +15 -0
- package/@cds-models/CardanoBackendService/index.d.ts +347 -0
- package/@cds-models/CardanoBackendService/index.js +40 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +496 -11
- package/@cds-models/CardanoIndexerService/index.js +64 -0
- package/@cds-models/CardanoODataService/index.d.ts +414 -57
- package/@cds-models/CardanoODataService/index.js +42 -0
- package/@cds-models/CardanoSignService/index.d.ts +32 -19
- package/@cds-models/CardanoSignService/index.js +3 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +58 -44
- package/@cds-models/CardanoTransactionService/index.js +4 -0
- package/@cds-models/CardanoWorkerService/index.d.ts +7 -22
- package/@cds-models/index.d.ts +101 -1
- package/@cds-models/index.js +16 -1
- package/@cds-models/odatano/cardano/index.d.ts +437 -32
- package/@cds-models/odatano/cardano/index.js +48 -0
- package/README.md +207 -167
- package/db/schema.cds +2402 -1705
- package/db/types.cds +446 -295
- package/package.json +41 -16
- package/scripts/migrate-schema.mjs +334 -0
- package/scripts/migrate-slot-leader.mjs +96 -0
- package/src/index.d.ts +20 -21
- package/src/index.js +45 -31
- package/src/plugin.js +17 -35
- package/srv/blockchain/asset-decimals.d.ts +7 -0
- package/srv/blockchain/asset-decimals.js +91 -0
- package/srv/blockchain/backends/blockfrost-backend.d.ts +25 -135
- package/srv/blockchain/backends/blockfrost-backend.js +66 -172
- package/srv/blockchain/backends/cardano-backend.d.ts +94 -186
- package/srv/blockchain/backends/cardano-backend.js +29 -5
- package/srv/blockchain/backends/koios-backend.d.ts +103 -168
- package/srv/blockchain/backends/koios-backend.js +428 -360
- package/srv/blockchain/backends/odatano-backend.d.ts +54 -0
- package/srv/blockchain/backends/odatano-backend.js +169 -0
- package/srv/blockchain/backends/ogmios-backend.d.ts +123 -190
- package/srv/blockchain/backends/ogmios-backend.js +637 -315
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +14 -0
- package/srv/blockchain/backends/ogmios-frame-guard.js +89 -0
- package/srv/blockchain/cardano-client.d.ts +61 -241
- package/srv/blockchain/cardano-client.js +253 -293
- package/srv/blockchain/cardano-indexer.d.ts +282 -281
- package/srv/blockchain/cardano-indexer.js +1551 -484
- package/srv/blockchain/cardano-tx-builder.d.ts +25 -89
- package/srv/blockchain/cardano-tx-builder.js +164 -140
- package/srv/blockchain/circuit-breaker.d.ts +1 -13
- package/srv/blockchain/circuit-breaker.js +5 -15
- package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
- package/srv/blockchain/crawler/account-snapshots.js +153 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +15 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
- package/srv/blockchain/crawler/asset-registry-backfill.d.ts +43 -0
- package/srv/blockchain/crawler/asset-registry-backfill.js +153 -0
- package/srv/blockchain/crawler/certificate-backfill.d.ts +52 -0
- package/srv/blockchain/crawler/certificate-backfill.js +162 -0
- package/srv/blockchain/crawler/crawler.d.ts +104 -81
- package/srv/blockchain/crawler/crawler.js +532 -160
- package/srv/blockchain/crawler/credential-backfill.d.ts +28 -0
- package/srv/blockchain/crawler/credential-backfill.js +124 -0
- package/srv/blockchain/crawler/hooks.d.ts +2 -17
- package/srv/blockchain/crawler/index.d.ts +1 -8
- package/srv/blockchain/crawler/index.js +31 -17
- package/srv/blockchain/crawler/input-asset-copies.d.ts +34 -0
- package/srv/blockchain/crawler/input-asset-copies.js +171 -0
- package/srv/blockchain/crawler/metadata-position-backfill.d.ts +16 -0
- package/srv/blockchain/crawler/metadata-position-backfill.js +55 -0
- package/srv/blockchain/crawler/output-datum-backfill.d.ts +39 -0
- package/srv/blockchain/crawler/output-datum-backfill.js +110 -0
- package/srv/blockchain/crawler/sync-state.d.ts +27 -47
- package/srv/blockchain/crawler/sync-state.js +113 -63
- package/srv/blockchain/crawler/transaction-backfill.d.ts +44 -0
- package/srv/blockchain/crawler/transaction-backfill.js +278 -0
- package/srv/blockchain/crawler/utxo-set-import.d.ts +66 -0
- package/srv/blockchain/crawler/utxo-set-import.js +399 -0
- package/srv/blockchain/ledger-state.d.ts +62 -0
- package/srv/blockchain/ledger-state.js +419 -0
- package/srv/blockchain/pending-spends.d.ts +16 -0
- package/srv/blockchain/pending-spends.js +81 -0
- package/srv/blockchain/pool-metadata.d.ts +15 -0
- package/srv/blockchain/pool-metadata.js +132 -0
- package/srv/blockchain/request-coalescer.d.ts +2 -16
- package/srv/blockchain/request-coalescer.js +2 -16
- package/srv/blockchain/signing/cose-verifier.d.ts +3 -17
- package/srv/blockchain/signing/cose-verifier.js +146 -70
- package/srv/blockchain/signing/external-signer.d.ts +15 -115
- package/srv/blockchain/signing/external-signer.js +17 -126
- package/srv/blockchain/signing/hsm-signer.d.ts +10 -54
- package/srv/blockchain/signing/hsm-signer.js +28 -79
- package/srv/blockchain/signing/signature-verifier.d.ts +9 -47
- package/srv/blockchain/signing/signature-verifier.js +70 -83
- package/srv/blockchain/signing/submission-finalizer.d.ts +23 -45
- package/srv/blockchain/signing/submission-finalizer.js +219 -86
- package/srv/blockchain/stored-chain.d.ts +20 -0
- package/srv/blockchain/stored-chain.js +237 -0
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +31 -229
- package/srv/blockchain/transaction-building/buildooor-tx.js +652 -416
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +9 -37
- package/srv/blockchain/transaction-presence.d.ts +5 -0
- package/srv/blockchain/transaction-presence.js +29 -0
- package/srv/blockchain/transaction-rows.d.ts +12 -0
- package/srv/blockchain/transaction-rows.js +44 -0
- package/srv/blockchain/wallet-worker/build-request.d.ts +5 -20
- package/srv/blockchain/wallet-worker/build-request.js +47 -30
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +5 -46
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +25 -45
- package/srv/blockchain/wallet-worker/index.d.ts +1 -1
- package/srv/blockchain/wallet-worker/index.js +3 -11
- package/srv/blockchain/wallet-worker/job-store.d.ts +30 -148
- package/srv/blockchain/wallet-worker/job-store.js +101 -201
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -26
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -28
- package/srv/blockchain/wallet-worker/signers.d.ts +5 -24
- package/srv/blockchain/wallet-worker/signers.js +4 -12
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +8 -80
- package/srv/blockchain/wallet-worker/wallet-worker.js +107 -155
- package/srv/cardano-agent-service.cds +122 -84
- package/srv/cardano-agent-service.js +4 -9
- package/srv/cardano-backend-service.cds +78 -0
- package/srv/cardano-backend-service.d.ts +2 -0
- package/srv/cardano-backend-service.js +242 -0
- package/srv/cardano-indexer-service.cds +387 -73
- package/srv/cardano-indexer-service.d.ts +5 -1
- package/srv/cardano-indexer-service.js +532 -16
- package/srv/cardano-service.cds +424 -269
- package/srv/cardano-service.js +289 -201
- package/srv/cardano-sign-service.cds +201 -180
- package/srv/cardano-sign-service.js +71 -201
- package/srv/cardano-tx-service.cds +451 -370
- package/srv/cardano-tx-service.js +271 -289
- package/srv/cardano-ui.cds +16 -16
- package/srv/cardano-worker-service.cds +118 -125
- package/srv/cardano-worker-service.js +52 -61
- package/srv/cbor/cip68.d.ts +13 -0
- package/srv/cbor/cip68.js +56 -0
- package/srv/cbor/index.d.ts +3 -1
- package/srv/cbor/index.js +9 -1
- package/srv/cbor/parse.d.ts +30 -18
- package/srv/cbor/parse.js +44 -9
- package/srv/cbor/plutus-data-json.d.ts +20 -0
- package/srv/cbor/plutus-data-json.js +32 -0
- package/srv/config.d.ts +113 -0
- package/srv/config.js +409 -0
- package/srv/server.d.ts +15 -110
- package/srv/server.js +84 -404
- package/srv/utils/agent-access.d.ts +9 -0
- package/srv/utils/agent-access.js +67 -0
- package/srv/utils/agent-grants-config.d.ts +0 -46
- package/srv/utils/agent-grants-config.js +17 -85
- package/srv/utils/agent-grants.d.ts +106 -122
- package/srv/utils/agent-grants.js +538 -236
- package/srv/utils/agent-token-auth.d.ts +4 -99
- package/srv/utils/agent-token-auth.js +18 -182
- package/srv/utils/backend-request-handler.d.ts +3 -17
- package/srv/utils/backend-request-handler.js +3 -18
- package/srv/utils/collections.d.ts +3 -10
- package/srv/utils/collections.js +3 -10
- package/srv/utils/const.d.ts +23 -74
- package/srv/utils/const.js +32 -79
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +6 -21
- package/srv/utils/db-indexes.d.ts +27 -0
- package/srv/utils/db-indexes.js +120 -0
- package/srv/utils/db-sanitize.d.ts +20 -0
- package/srv/utils/db-sanitize.js +80 -0
- package/srv/utils/deep-json.d.ts +6 -0
- package/srv/utils/deep-json.js +240 -0
- package/srv/utils/epoch-slots.d.ts +13 -0
- package/srv/utils/epoch-slots.js +38 -0
- package/srv/utils/error-codes.d.ts +22 -75
- package/srv/utils/error-codes.js +23 -72
- package/srv/utils/errors.d.ts +46 -187
- package/srv/utils/errors.js +114 -230
- package/srv/utils/liveness.d.ts +12 -0
- package/srv/utils/liveness.js +35 -0
- package/srv/utils/mappers.d.ts +102 -223
- package/srv/utils/mappers.js +387 -316
- package/srv/utils/network-context.js +2 -13
- package/srv/utils/paging.d.ts +31 -0
- package/srv/utils/paging.js +43 -0
- package/srv/utils/pg-inline-json.d.ts +8 -0
- package/srv/utils/pg-inline-json.js +58 -0
- package/srv/utils/pg-order-nulls.d.ts +14 -0
- package/srv/utils/pg-order-nulls.js +54 -0
- package/srv/utils/plutus-placeholders.d.ts +16 -22
- package/srv/utils/plutus-placeholders.js +62 -33
- package/srv/utils/rate-limiter.d.ts +2 -21
- package/srv/utils/rate-limiter.js +5 -17
- package/srv/utils/readiness.d.ts +12 -0
- package/srv/utils/readiness.js +29 -0
- package/srv/utils/reference-script.d.ts +19 -0
- package/srv/utils/reference-script.js +84 -0
- package/srv/utils/result-numbers.d.ts +15 -0
- package/srv/utils/result-numbers.js +61 -0
- package/srv/utils/service-events.d.ts +0 -24
- package/srv/utils/service-events.js +3 -25
- package/srv/utils/signing-helper.d.ts +3 -20
- package/srv/utils/signing-helper.js +35 -64
- package/srv/utils/tx-build-helper.d.ts +10 -105
- package/srv/utils/tx-build-helper.js +81 -144
- package/srv/utils/tx-request-parsers.d.ts +82 -33
- package/srv/utils/tx-request-parsers.js +401 -49
- package/srv/utils/tx-utils.d.ts +3 -27
- package/srv/utils/tx-utils.js +32 -50
- package/srv/utils/types.d.ts +261 -191
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +22 -92
- package/srv/utils/validators.js +50 -149
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import cds from '@sap/cds';
|
|
2
|
+
/** The parts of a linked model definition this module reads. */
|
|
3
|
+
interface Typed {
|
|
4
|
+
items?: Typed;
|
|
5
|
+
elements?: Record<string, Typed | undefined>;
|
|
6
|
+
_target?: Typed;
|
|
7
|
+
scale?: number;
|
|
8
|
+
returns?: Typed;
|
|
9
|
+
actions?: Record<string, Typed | undefined>;
|
|
10
|
+
}
|
|
11
|
+
/** `value` with every Int64 and Decimal number as text; `value` itself when it holds none. */
|
|
12
|
+
export declare function numbersAsText(def: Typed | undefined, value: unknown): unknown;
|
|
13
|
+
export declare function answerNumbersAsText(srv: cds.Service): void;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=result-numbers.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
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.numbersAsText = numbersAsText;
|
|
7
|
+
exports.answerNumbersAsText = answerNumbersAsText;
|
|
8
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
9
|
+
/** Text of an Int64 or Decimal value, in the form the database returns it. */
|
|
10
|
+
function numberText(def, value) {
|
|
11
|
+
const scale = def instanceof cds_1.default.builtin.classes.Decimal ? def.scale : undefined;
|
|
12
|
+
if (scale === undefined)
|
|
13
|
+
return String(value);
|
|
14
|
+
return typeof value === 'bigint' ? (scale ? `${value}.${'0'.repeat(scale)}` : String(value)) : value.toFixed(scale);
|
|
15
|
+
}
|
|
16
|
+
/** `value` with every Int64 and Decimal number as text; `value` itself when it holds none. */
|
|
17
|
+
function numbersAsText(def, value) {
|
|
18
|
+
if (!def || value === null || value === undefined)
|
|
19
|
+
return value;
|
|
20
|
+
if (Array.isArray(value)) {
|
|
21
|
+
// a to-many association has no `items`: its rows are rows of the target
|
|
22
|
+
const of = def.items ?? def;
|
|
23
|
+
let copy;
|
|
24
|
+
value.forEach((item, i) => {
|
|
25
|
+
const text = numbersAsText(of, item);
|
|
26
|
+
// Object.assign keeps what CAP adds to a result array, such as $count
|
|
27
|
+
if (text !== item)
|
|
28
|
+
(copy ??= Object.assign([], value))[i] = text;
|
|
29
|
+
});
|
|
30
|
+
return copy ?? value;
|
|
31
|
+
}
|
|
32
|
+
if (typeof value === 'number' || typeof value === 'bigint') {
|
|
33
|
+
const { Int64, Decimal } = cds_1.default.builtin.classes;
|
|
34
|
+
return def instanceof Int64 || def instanceof Decimal ? numberText(def, value) : value;
|
|
35
|
+
}
|
|
36
|
+
if (typeof value !== 'object')
|
|
37
|
+
return value;
|
|
38
|
+
const elements = (def._target ?? def).elements;
|
|
39
|
+
if (!elements)
|
|
40
|
+
return value;
|
|
41
|
+
let copy;
|
|
42
|
+
for (const [name, item] of Object.entries(value)) {
|
|
43
|
+
const text = numbersAsText(elements[name], item);
|
|
44
|
+
if (text !== item)
|
|
45
|
+
(copy ??= { ...value })[name] = text;
|
|
46
|
+
}
|
|
47
|
+
return copy ?? value;
|
|
48
|
+
}
|
|
49
|
+
// Answers reads and operations of `srv` with Int64 and Decimal as text. The result is replaced,
|
|
50
|
+
// never changed in place: a handler may answer with an object that other code keeps counting in.
|
|
51
|
+
function answerNumbersAsText(srv) {
|
|
52
|
+
srv.after('*', (_results, req) => {
|
|
53
|
+
const target = req.target;
|
|
54
|
+
const operations = (target?.actions ?? srv.actions);
|
|
55
|
+
const def = req.event === 'READ' ? target : operations?.[req.event]?.returns;
|
|
56
|
+
const text = numbersAsText(def, req.results);
|
|
57
|
+
if (text !== req.results)
|
|
58
|
+
req.reply(text);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=result-numbers.js.map
|
|
@@ -1,26 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Mirror an internal notification onto a CAP service as a declared event, so
|
|
3
|
-
* consumers can subscribe instead of polling:
|
|
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.
|
|
24
|
-
*/
|
|
25
1
|
export declare function emitServiceEvent(serviceName: string, event: string, data: Record<string, unknown>): void;
|
|
26
2
|
//# sourceMappingURL=service-events.d.ts.map
|
|
@@ -6,34 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.emitServiceEvent = emitServiceEvent;
|
|
7
7
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
8
8
|
const logger = cds_1.default.log('ServiceEvents');
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* consumers can subscribe instead of polling:
|
|
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.
|
|
32
|
-
*/
|
|
9
|
+
// Emits a CAP service event in-process. Never throws and is silent before the service is served.
|
|
10
|
+
// Callers must emit after their transaction commits.
|
|
33
11
|
function emitServiceEvent(serviceName, event, data) {
|
|
34
12
|
const srv = cds_1.default.services?.[serviceName];
|
|
35
13
|
if (!srv?.emit)
|
|
36
|
-
return; // not served
|
|
14
|
+
return; // not served yet
|
|
37
15
|
try {
|
|
38
16
|
void Promise.resolve(srv.emit(event, data)).catch((err) => {
|
|
39
17
|
logger.warn(`${serviceName}.${event} subscriber failed (ignored):`, err);
|
|
@@ -1,23 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Combine an unsigned transaction with a witness set from CIP-30 wallet signing
|
|
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)
|
|
11
|
-
*/
|
|
1
|
+
/** Merges the witness set from CIP-30 `signTx()` into the unsigned tx. Returns signed CBOR hex. */
|
|
12
2
|
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
|
-
*/
|
|
22
3
|
export declare function isWitnessSetCbor(cborHex: string): boolean;
|
|
4
|
+
/** The signed transaction: as given, or the unsigned one plus a CIP-30 witness set. */
|
|
5
|
+
export declare function toSignedTransaction(unsignedTxCbor: string | null | undefined, signedTxOrWitnessSet: string): string;
|
|
23
6
|
//# sourceMappingURL=signing-helper.d.ts.map
|
|
@@ -5,25 +5,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.combineTransactionWithWitnesses = combineTransactionWithWitnesses;
|
|
7
7
|
exports.isWitnessSetCbor = isWitnessSetCbor;
|
|
8
|
+
exports.toSignedTransaction = toSignedTransaction;
|
|
8
9
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
9
10
|
const cbor_1 = require("@harmoniclabs/cbor");
|
|
10
11
|
const uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
|
|
11
12
|
const errors_1 = require("./errors");
|
|
12
13
|
const logger = cds_1.default.log('SigningHelper');
|
|
13
|
-
/**
|
|
14
|
-
* Combine an unsigned transaction with a witness set from CIP-30 wallet signing
|
|
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)
|
|
23
|
-
*/
|
|
14
|
+
/** Merges the witness set from CIP-30 `signTx()` into the unsigned tx. Returns signed CBOR hex. */
|
|
24
15
|
function combineTransactionWithWitnesses(unsignedTxCbor, witnessSetCbor) {
|
|
25
16
|
try {
|
|
26
|
-
//
|
|
17
|
+
// Raw CBOR level: no Cardano type validation, preserves all encoding metadata
|
|
27
18
|
const txObj = cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(unsignedTxCbor));
|
|
28
19
|
if (!(txObj instanceof cbor_1.CborArray) || txObj.array.length < 2) {
|
|
29
20
|
throw new errors_1.TransactionValidationError('Invalid transaction CBOR structure');
|
|
@@ -31,41 +22,29 @@ function combineTransactionWithWitnesses(unsignedTxCbor, witnessSetCbor) {
|
|
|
31
22
|
const walletWsObj = cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(witnessSetCbor));
|
|
32
23
|
// txObj.array[0] = body, [1] = witness_set, [2] = is_valid, [3] = auxiliary_data
|
|
33
24
|
const origWs = txObj.array[1];
|
|
25
|
+
if (!(origWs instanceof cbor_1.CborMap) || !(walletWsObj instanceof cbor_1.CborMap)) {
|
|
26
|
+
throw new errors_1.TransactionValidationError('Witness set must be CBOR map per Cardano spec');
|
|
27
|
+
}
|
|
28
|
+
// The wallet signs with vkey witnesses (map key 0) or, for Byron addresses, bootstrap witnesses (key 2)
|
|
29
|
+
const isSignatureKey = (k) => k instanceof cbor_1.CborUInt && (Number(k.num) === 0 || Number(k.num) === 2);
|
|
30
|
+
const walletSignatures = walletWsObj.map.filter(e => isSignatureKey(e.k));
|
|
34
31
|
let witnessCount = 0;
|
|
35
|
-
|
|
36
|
-
//
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const mergedEntries = origWs.map
|
|
42
|
-
.filter(e => !(e.k instanceof cbor_1.CborUInt && Number(e.k.num) === 0))
|
|
43
|
-
.concat([walletVkeyEntry]);
|
|
44
|
-
// Construct new witness set CborMap preserving the original's encoding style
|
|
45
|
-
txObj.array[1] = new cbor_1.CborMap(mergedEntries, {
|
|
46
|
-
indefinite: origWs.indefinite,
|
|
47
|
-
});
|
|
48
|
-
// Count VKey witnesses — value may be CborArray or CborTag(258, CborArray) in Conway era
|
|
49
|
-
const vkeyValue = walletVkeyEntry.v;
|
|
50
|
-
if (vkeyValue instanceof cbor_1.CborArray) {
|
|
51
|
-
witnessCount = vkeyValue.array.length;
|
|
52
|
-
}
|
|
53
|
-
else if (vkeyValue instanceof cbor_1.CborTag && vkeyValue.data instanceof cbor_1.CborArray) {
|
|
54
|
-
witnessCount = vkeyValue.data.array.length;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
throw new errors_1.TransactionValidationError('Unexpected VKey witness format in witness set');
|
|
58
|
-
}
|
|
59
|
-
}
|
|
32
|
+
for (const { v } of walletSignatures) {
|
|
33
|
+
// CborArray, or CborTag(258, CborArray) in Conway
|
|
34
|
+
const items = v instanceof cbor_1.CborArray ? v.array : v instanceof cbor_1.CborTag && v.data instanceof cbor_1.CborArray ? v.data.array : undefined;
|
|
35
|
+
if (!items)
|
|
36
|
+
throw new errors_1.TransactionValidationError('Unexpected witness format in witness set');
|
|
37
|
+
witnessCount += items.length;
|
|
60
38
|
}
|
|
61
|
-
|
|
62
|
-
throw new errors_1.TransactionValidationError('Witness set
|
|
39
|
+
if (witnessCount === 0) {
|
|
40
|
+
throw new errors_1.TransactionValidationError('Witness set carries no vkey or bootstrap witness; the wallet did not sign');
|
|
63
41
|
}
|
|
64
|
-
//
|
|
65
|
-
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
// the
|
|
42
|
+
// Keep original entries (redeemers, datums, scripts at keys 3-7), take the signatures from the wallet
|
|
43
|
+
const mergedEntries = origWs.map.filter(e => !isSignatureKey(e.k)).concat(walletSignatures);
|
|
44
|
+
// New witness set map preserving the original's encoding style
|
|
45
|
+
txObj.array[1] = new cbor_1.CborMap(mergedEntries, { indefinite: origWs.indefinite });
|
|
46
|
+
// New outer CborArray so the encoder cannot reuse the stale outer subCborRef; the inner
|
|
47
|
+
// subCborRefs are kept so the body bytes (and thus the signed body hash) stay identical.
|
|
69
48
|
const signedTxCbor = (0, uint8array_utils_1.toHex)(cbor_1.Cbor.encode(new cbor_1.CborArray(txObj.array, { indefinite: txObj.indefinite })));
|
|
70
49
|
logger.info({
|
|
71
50
|
unsignedTxLength: unsignedTxCbor.length,
|
|
@@ -81,27 +60,19 @@ function combineTransactionWithWitnesses(unsignedTxCbor, witnessSetCbor) {
|
|
|
81
60
|
throw new errors_1.TransactionValidationError(`Failed to combine transaction with witnesses: ${msg}`);
|
|
82
61
|
}
|
|
83
62
|
}
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
*/
|
|
63
|
+
// A witness set is a CBOR map, a full transaction an array. Only the first byte is read.
|
|
64
|
+
// A malformed map fails later in the combine step.
|
|
93
65
|
function isWitnessSetCbor(cborHex) {
|
|
94
|
-
|
|
95
|
-
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
|
-
if (obj instanceof cbor_1.CborArray)
|
|
99
|
-
return false;
|
|
100
|
-
return obj instanceof cbor_1.CborMap;
|
|
101
|
-
}
|
|
102
|
-
catch {
|
|
103
|
-
// Invalid / unparseable CBOR
|
|
66
|
+
if (!/^[0-9a-f]{2}/i.test(cborHex))
|
|
104
67
|
return false;
|
|
105
|
-
|
|
68
|
+
return parseInt(cborHex.slice(0, 2), 16) >> 5 === 5;
|
|
69
|
+
}
|
|
70
|
+
/** The signed transaction: as given, or the unsigned one plus a CIP-30 witness set. */
|
|
71
|
+
function toSignedTransaction(unsignedTxCbor, signedTxOrWitnessSet) {
|
|
72
|
+
if (!isWitnessSetCbor(signedTxOrWitnessSet))
|
|
73
|
+
return signedTxOrWitnessSet;
|
|
74
|
+
if (!unsignedTxCbor)
|
|
75
|
+
throw new errors_1.TransactionValidationError('No unsigned transaction to add the witness set to');
|
|
76
|
+
return combineTransactionWithWitnesses(unsignedTxCbor, signedTxOrWitnessSet);
|
|
106
77
|
}
|
|
107
78
|
//# sourceMappingURL=signing-helper.js.map
|
|
@@ -1,25 +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
|
-
|
|
12
|
-
|
|
13
|
-
* @throws {MixedAssetsError} if UTxO contains non-ADA assets
|
|
14
|
-
*/
|
|
6
|
+
/** A UTxO the builders may take as collateral: lovelace only and no reference script. */
|
|
7
|
+
export declare function isCollateralCandidate(u: OdatanoUtxo): boolean;
|
|
8
|
+
/** Throws MixedAssetsError when the UTxO carries non-ADA assets. */
|
|
15
9
|
export declare function assertAdaOnly(u: OdatanoUtxo): void;
|
|
16
|
-
/**
|
|
17
|
-
* Extract transaction hash from a transaction CBOR (signed or unsigned).
|
|
18
|
-
* Hash is computed over the body, so witness presence does not affect it.
|
|
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
|
|
22
|
-
*/
|
|
10
|
+
/** Transaction hash: blake2b-256 over the body bytes, so witnesses do not affect it. */
|
|
23
11
|
export declare function getTxHashFromCbor(txCbor: string): string;
|
|
24
12
|
/** Cache-invalidation targets of a submitted transaction (see extractTxCacheTargets). */
|
|
25
13
|
export interface TxCacheTargets {
|
|
@@ -31,103 +19,20 @@ export interface TxCacheTargets {
|
|
|
31
19
|
/** Distinct bech32 addresses receiving outputs (sender change + recipients). */
|
|
32
20
|
outputAddresses: string[];
|
|
33
21
|
}
|
|
34
|
-
/**
|
|
35
|
-
* Extract the consumed input refs and the output addresses from a transaction
|
|
36
|
-
* CBOR (signed or unsigned) — the rows a successful submit makes stale in the
|
|
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
|
|
45
|
-
*/
|
|
46
22
|
export declare function extractTxCacheTargets(txCbor: string): TxCacheTargets;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
* Used by the Buildooor transaction builder.
|
|
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
|
|
59
|
-
*/
|
|
60
|
-
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
|
-
*/
|
|
23
|
+
export declare function mapBuilderError(err: unknown, assetUnit?: string, context?: string, requestedOutputs?: number): never;
|
|
24
|
+
/** Split an asset unit into policyId (56 hex chars) and assetName (remaining hex). */
|
|
66
25
|
export declare function parseAssetUnit(assetUnit: string): {
|
|
67
26
|
policyId: string;
|
|
68
27
|
assetName: string;
|
|
69
28
|
};
|
|
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
|
-
*/
|
|
29
|
+
/** JSON (`int` / `bytes` / `list` / `map` / `constructor`|`constr`) to Buildooor PlutusData. */
|
|
81
30
|
export declare function jsonToPlutusData(json: JSONValue): Data;
|
|
82
|
-
/**
|
|
83
|
-
* Normalize a backend-provided inline datum to canonical CBOR hex.
|
|
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.
|
|
93
|
-
*/
|
|
94
31
|
export declare function inlineDatumToHex(datum: unknown): string | null;
|
|
95
32
|
/** UPLC type tag for a typed script parameter (see {@link encodeScriptParam}). */
|
|
96
33
|
export type ScriptParamUplcType = 'data' | 'bytes' | 'int' | 'bool' | 'unit';
|
|
97
|
-
/**
|
|
98
|
-
* Encode a single script parameter into the UPLC constant the parameterized
|
|
99
|
-
* script expects.
|
|
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.
|
|
118
|
-
*/
|
|
119
34
|
export declare function encodeScriptParam(param: JSONValue): UPLCConst;
|
|
120
|
-
/**
|
|
121
|
-
* Apply parameters to a parameterized PlutusV3 script (CBOR-wrapped flat UPLC).
|
|
122
|
-
* Each parameter becomes a successive UPLC Application wrapping the program body.
|
|
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)
|
|
131
|
-
*/
|
|
35
|
+
/** Wraps the program body in one UPLC application per parameter. Returns the script CBOR hex. */
|
|
132
36
|
export declare function applyScriptParameters(scriptHex: string, params: JSONValue[]): string;
|
|
37
|
+
export declare function plutusScriptHash(scriptHex: string, version: 'plutusV2' | 'plutusV3'): string;
|
|
133
38
|
//# sourceMappingURL=tx-build-helper.d.ts.map
|