@odatano/core 2.0.0-rc.31 → 2.0.0-rc.33
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/CardanoODataService/index.d.ts +11 -0
- package/@cds-models/CardanoODataService/index.js +1 -0
- package/@cds-models/index.d.ts +53 -0
- package/@cds-models/index.js +9 -0
- package/db/schema.cds +1 -1
- package/db/types.cds +83 -0
- package/package.json +1 -1
- package/src/index.d.ts +7 -1
- package/src/index.js +17 -1
- package/srv/blockchain/backends/blockfrost-backend.js +2 -1
- package/srv/blockchain/backends/koios-backend.js +22 -20
- package/srv/blockchain/backends/ogmios-backend.js +2 -1
- package/srv/blockchain/cardano-indexer.d.ts +10 -1
- package/srv/blockchain/cardano-indexer.js +47 -2
- package/srv/blockchain/signing/signature-verifier.d.ts +6 -1
- package/srv/blockchain/signing/signature-verifier.js +62 -24
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +2 -0
- package/srv/blockchain/transaction-building/buildooor-tx.js +57 -23
- package/srv/cardano-service.cds +8 -1
- package/srv/cardano-service.js +8 -0
- package/srv/cardano-sign-service.js +2 -11
- package/srv/cardano-tx-service.cds +3 -3
- package/srv/cardano-tx-service.js +5 -2
- package/srv/cbor/index.d.ts +1 -1
- package/srv/cbor/parse.d.ts +25 -0
- package/srv/cbor/parse.js +49 -1
- package/srv/utils/epoch-slots.d.ts +8 -1
- package/srv/utils/epoch-slots.js +20 -2
- package/srv/utils/mappers.js +1 -1
- package/srv/utils/signing-helper.d.ts +6 -1
- package/srv/utils/signing-helper.js +33 -35
- package/srv/utils/tx-build-helper.d.ts +2 -1
- package/srv/utils/tx-build-helper.js +7 -1
- package/srv/utils/tx-request-parsers.d.ts +1 -1
- package/srv/utils/tx-request-parsers.js +4 -4
- package/srv/utils/types.d.ts +20 -1
package/srv/utils/epoch-slots.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.epochOfSlot = epochOfSlot;
|
|
4
4
|
exports.epochStartSlot = epochStartSlot;
|
|
5
|
+
exports.slotToPosixMs = slotToPosixMs;
|
|
5
6
|
exports.slotToPosixSeconds = slotToPosixSeconds;
|
|
7
|
+
exports.posixToSlot = posixToSlot;
|
|
6
8
|
const const_1 = require("./const");
|
|
7
9
|
/** Epoch a slot belongs to, from the network's Shelley anchor. */
|
|
8
10
|
function epochOfSlot(network, slot) {
|
|
@@ -15,11 +17,27 @@ function epochStartSlot(network, epoch) {
|
|
|
15
17
|
return cfg.shelleyStartSlot + (epoch - cfg.shelleyStartEpoch) * cfg.slotsPerEpoch;
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
|
-
* Absolute POSIX
|
|
20
|
+
* Absolute POSIX milliseconds for a slot via the Shelley-anchored genesis infos (exact for Shelley-era
|
|
19
21
|
* slots). Ogmios' `eraStart.time` is RelativeTime since system start, not a Unix timestamp.
|
|
20
22
|
*/
|
|
23
|
+
function slotToPosixMs(network, slot) {
|
|
24
|
+
const genesis = const_1.GENESIS_INFOS_BY_NETWORK[network];
|
|
25
|
+
return genesis.systemStartPosixMs + (slot - genesis.startSlotNo) * genesis.slotLengthMs;
|
|
26
|
+
}
|
|
27
|
+
/** Absolute POSIX seconds for a slot, rounded down. */
|
|
21
28
|
function slotToPosixSeconds(network, slot) {
|
|
29
|
+
return Math.floor(slotToPosixMs(network, slot) / 1000);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Slot that contains a POSIX time in milliseconds.
|
|
33
|
+
* @throws RangeError for a time before the Shelley start, where slots were 20 s long.
|
|
34
|
+
*/
|
|
35
|
+
function posixToSlot(network, posixMs) {
|
|
22
36
|
const genesis = const_1.GENESIS_INFOS_BY_NETWORK[network];
|
|
23
|
-
|
|
37
|
+
const shelleyStartMs = slotToPosixMs(network, const_1.EPOCH_CONFIG_BY_NETWORK[network].shelleyStartSlot);
|
|
38
|
+
if (!Number.isFinite(posixMs) || posixMs < shelleyStartMs) {
|
|
39
|
+
throw new RangeError(`posixToSlot: ${posixMs} is not a time from the ${network} Shelley start on`);
|
|
40
|
+
}
|
|
41
|
+
return genesis.startSlotNo + Math.floor((posixMs - genesis.systemStartPosixMs) / genesis.slotLengthMs);
|
|
24
42
|
}
|
|
25
43
|
//# sourceMappingURL=epoch-slots.js.map
|
package/srv/utils/mappers.js
CHANGED
|
@@ -499,7 +499,7 @@ function mapPoolSnapshot(providerPoolData, epoch, at, origin = { source: 'koios'
|
|
|
499
499
|
blocksMinted: providerPoolData.blocksMinted,
|
|
500
500
|
blocksEpoch: providerPoolData.blocksEpoch,
|
|
501
501
|
liveStake: providerPoolData.liveStake,
|
|
502
|
-
liveSize: Number(providerPoolData.liveSize),
|
|
502
|
+
liveSize: providerPoolData.liveSize == null ? null : Number(providerPoolData.liveSize),
|
|
503
503
|
liveSaturation: Number(providerPoolData.liveSaturation),
|
|
504
504
|
liveDelegators: providerPoolData.liveDelegators,
|
|
505
505
|
activeStake: providerPoolData.activeStake,
|
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
* @returns complete signed transaction CBOR (hex)
|
|
4
4
|
*/
|
|
5
5
|
export declare function combineTransactionWithWitnesses(unsignedTxCbor: string, witnessSetCbor: string): string;
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* True when the CBOR is a CIP-30 witness set (map) rather than a full transaction (array).
|
|
8
|
+
* Reads the major type of the first byte only; a malformed map fails later in the combine step.
|
|
9
|
+
*/
|
|
7
10
|
export declare function isWitnessSetCbor(cborHex: string): boolean;
|
|
11
|
+
/** The signed transaction: as given, or the unsigned one plus a CIP-30 witness set. */
|
|
12
|
+
export declare function toSignedTransaction(unsignedTxCbor: string | null | undefined, signedTxOrWitnessSet: string): string;
|
|
8
13
|
//# sourceMappingURL=signing-helper.d.ts.map
|
|
@@ -5,6 +5,7 @@ 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");
|
|
@@ -24,35 +25,27 @@ function combineTransactionWithWitnesses(unsignedTxCbor, witnessSetCbor) {
|
|
|
24
25
|
const walletWsObj = cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(witnessSetCbor));
|
|
25
26
|
// txObj.array[0] = body, [1] = witness_set, [2] = is_valid, [3] = auxiliary_data
|
|
26
27
|
const origWs = txObj.array[1];
|
|
28
|
+
if (!(origWs instanceof cbor_1.CborMap) || !(walletWsObj instanceof cbor_1.CborMap)) {
|
|
29
|
+
throw new errors_1.TransactionValidationError('Witness set must be CBOR map per Cardano spec');
|
|
30
|
+
}
|
|
31
|
+
// The wallet signs with vkey witnesses (map key 0) or, for Byron addresses, bootstrap witnesses (key 2)
|
|
32
|
+
const isSignatureKey = (k) => k instanceof cbor_1.CborUInt && (Number(k.num) === 0 || Number(k.num) === 2);
|
|
33
|
+
const walletSignatures = walletWsObj.map.filter(e => isSignatureKey(e.k));
|
|
27
34
|
let witnessCount = 0;
|
|
28
|
-
|
|
29
|
-
//
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
.filter(e => !(e.k instanceof cbor_1.CborUInt && Number(e.k.num) === 0))
|
|
35
|
-
.concat([walletVkeyEntry]);
|
|
36
|
-
// New witness set map preserving the original's encoding style
|
|
37
|
-
txObj.array[1] = new cbor_1.CborMap(mergedEntries, {
|
|
38
|
-
indefinite: origWs.indefinite,
|
|
39
|
-
});
|
|
40
|
-
// VKey witnesses: CborArray, or CborTag(258, CborArray) in Conway
|
|
41
|
-
const vkeyValue = walletVkeyEntry.v;
|
|
42
|
-
if (vkeyValue instanceof cbor_1.CborArray) {
|
|
43
|
-
witnessCount = vkeyValue.array.length;
|
|
44
|
-
}
|
|
45
|
-
else if (vkeyValue instanceof cbor_1.CborTag && vkeyValue.data instanceof cbor_1.CborArray) {
|
|
46
|
-
witnessCount = vkeyValue.data.array.length;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
throw new errors_1.TransactionValidationError('Unexpected VKey witness format in witness set');
|
|
50
|
-
}
|
|
51
|
-
}
|
|
35
|
+
for (const { v } of walletSignatures) {
|
|
36
|
+
// CborArray, or CborTag(258, CborArray) in Conway
|
|
37
|
+
const items = v instanceof cbor_1.CborArray ? v.array : v instanceof cbor_1.CborTag && v.data instanceof cbor_1.CborArray ? v.data.array : undefined;
|
|
38
|
+
if (!items)
|
|
39
|
+
throw new errors_1.TransactionValidationError('Unexpected witness format in witness set');
|
|
40
|
+
witnessCount += items.length;
|
|
52
41
|
}
|
|
53
|
-
|
|
54
|
-
throw new errors_1.TransactionValidationError('Witness set
|
|
42
|
+
if (witnessCount === 0) {
|
|
43
|
+
throw new errors_1.TransactionValidationError('Witness set carries no vkey or bootstrap witness; the wallet did not sign');
|
|
55
44
|
}
|
|
45
|
+
// Keep original entries (redeemers, datums, scripts at keys 3-7), take the signatures from the wallet
|
|
46
|
+
const mergedEntries = origWs.map.filter(e => !isSignatureKey(e.k)).concat(walletSignatures);
|
|
47
|
+
// New witness set map preserving the original's encoding style
|
|
48
|
+
txObj.array[1] = new cbor_1.CborMap(mergedEntries, { indefinite: origWs.indefinite });
|
|
56
49
|
// New outer CborArray so the encoder cannot reuse the stale outer subCborRef; the inner
|
|
57
50
|
// subCborRefs are kept so the body bytes (and thus the signed body hash) stay identical.
|
|
58
51
|
const signedTxCbor = (0, uint8array_utils_1.toHex)(cbor_1.Cbor.encode(new cbor_1.CborArray(txObj.array, { indefinite: txObj.indefinite })));
|
|
@@ -70,16 +63,21 @@ function combineTransactionWithWitnesses(unsignedTxCbor, witnessSetCbor) {
|
|
|
70
63
|
throw new errors_1.TransactionValidationError(`Failed to combine transaction with witnesses: ${msg}`);
|
|
71
64
|
}
|
|
72
65
|
}
|
|
73
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* True when the CBOR is a CIP-30 witness set (map) rather than a full transaction (array).
|
|
68
|
+
* Reads the major type of the first byte only; a malformed map fails later in the combine step.
|
|
69
|
+
*/
|
|
74
70
|
function isWitnessSetCbor(cborHex) {
|
|
75
|
-
|
|
76
|
-
const obj = cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(cborHex));
|
|
77
|
-
if (obj instanceof cbor_1.CborArray)
|
|
78
|
-
return false;
|
|
79
|
-
return obj instanceof cbor_1.CborMap;
|
|
80
|
-
}
|
|
81
|
-
catch {
|
|
71
|
+
if (!/^[0-9a-f]{2}/i.test(cborHex))
|
|
82
72
|
return false;
|
|
83
|
-
|
|
73
|
+
return parseInt(cborHex.slice(0, 2), 16) >> 5 === 5;
|
|
74
|
+
}
|
|
75
|
+
/** The signed transaction: as given, or the unsigned one plus a CIP-30 witness set. */
|
|
76
|
+
function toSignedTransaction(unsignedTxCbor, signedTxOrWitnessSet) {
|
|
77
|
+
if (!isWitnessSetCbor(signedTxOrWitnessSet))
|
|
78
|
+
return signedTxOrWitnessSet;
|
|
79
|
+
if (!unsignedTxCbor)
|
|
80
|
+
throw new errors_1.TransactionValidationError('No unsigned transaction to add the witness set to');
|
|
81
|
+
return combineTransactionWithWitnesses(unsignedTxCbor, signedTxOrWitnessSet);
|
|
84
82
|
}
|
|
85
83
|
//# sourceMappingURL=signing-helper.js.map
|
|
@@ -30,8 +30,9 @@ export declare function extractTxCacheTargets(txCbor: string): TxCacheTargets;
|
|
|
30
30
|
/**
|
|
31
31
|
* Maps Buildooor errors to typed BackendErrors. Asset unit is parsed from "not enough <unit>" when not given;
|
|
32
32
|
* `context` (e.g. the collateral partition) is appended to the consumer-facing message.
|
|
33
|
+
* `requestedOutputs` is the number of outputs the caller asked for; Buildooor appends the change after them.
|
|
33
34
|
*/
|
|
34
|
-
export declare function mapBuilderError(err: unknown, assetUnit?: string, context?: string): never;
|
|
35
|
+
export declare function mapBuilderError(err: unknown, assetUnit?: string, context?: string, requestedOutputs?: number): never;
|
|
35
36
|
/** Split an asset unit into policyId (56 hex chars) and assetName (remaining hex). */
|
|
36
37
|
export declare function parseAssetUnit(assetUnit: string): {
|
|
37
38
|
policyId: string;
|
|
@@ -115,8 +115,9 @@ function extractTxCacheTargets(txCbor) {
|
|
|
115
115
|
/**
|
|
116
116
|
* Maps Buildooor errors to typed BackendErrors. Asset unit is parsed from "not enough <unit>" when not given;
|
|
117
117
|
* `context` (e.g. the collateral partition) is appended to the consumer-facing message.
|
|
118
|
+
* `requestedOutputs` is the number of outputs the caller asked for; Buildooor appends the change after them.
|
|
118
119
|
*/
|
|
119
|
-
function mapBuilderError(err, assetUnit, context) {
|
|
120
|
+
function mapBuilderError(err, assetUnit, context, requestedOutputs) {
|
|
120
121
|
// Typed errors keep their own status and payload
|
|
121
122
|
if (err instanceof errors_1.BackendError) {
|
|
122
123
|
throw err;
|
|
@@ -128,6 +129,11 @@ function mapBuilderError(err, assetUnit, context) {
|
|
|
128
129
|
const minAda = rawMsg.match(/tx output at index (\d+) did not have enough lovelaces[\s\S]*?minimum lovelaces required:\s*(\d+)[\s\S]*?output lovelaces\s*:\s*(\d+)/);
|
|
129
130
|
if (minAda) {
|
|
130
131
|
const [, index, minimum, actual] = minAda;
|
|
132
|
+
if (requestedOutputs !== undefined && Number(index) >= requestedOutputs) {
|
|
133
|
+
// the change output: the caller cannot raise it. The shortfall is unknown here, so no amounts
|
|
134
|
+
throw new errors_1.InsufficientFundsError('lovelace', 0n, 0n, err, `the change output needs at least ${minimum} lovelace (has ${actual}); the funding UTxOs cannot pay the fee and the change` +
|
|
135
|
+
(context ? ` (${context})` : ''));
|
|
136
|
+
}
|
|
131
137
|
const withAssets = /tx output:[\s\S]*"[0-9a-f]{56}"\s*:/i.test(rawMsg) ? ', it carries native assets' : '';
|
|
132
138
|
throw new errors_1.TransactionValidationError(`output ${index} needs at least ${minimum} lovelace (has ${actual}${withAssets}); raise its lovelace amount`, err);
|
|
133
139
|
}
|
|
@@ -85,7 +85,7 @@ export interface ParsedScriptInput {
|
|
|
85
85
|
/** Datum preimage as PlutusData CBOR hex (instead of datumJson). */
|
|
86
86
|
datumCbor?: string;
|
|
87
87
|
}
|
|
88
|
-
/** Parse and validate scriptInputsJson:
|
|
88
|
+
/** Parse and validate scriptInputsJson: 0..MAX_SCRIPT_INPUTS distinct script UTxOs, each with its own redeemer. */
|
|
89
89
|
export declare function parseScriptInputs(json: string | undefined): {
|
|
90
90
|
parsed?: ParsedScriptInput[];
|
|
91
91
|
error?: string;
|
|
@@ -235,15 +235,15 @@ function parseMintActionPolicyFields(entry, i, byReference = false) {
|
|
|
235
235
|
}
|
|
236
236
|
/** Upper bound on script inputs per BuildPlutusTransaction. */
|
|
237
237
|
exports.MAX_SCRIPT_INPUTS = 16;
|
|
238
|
-
/** Parse and validate scriptInputsJson:
|
|
238
|
+
/** Parse and validate scriptInputsJson: 0..MAX_SCRIPT_INPUTS distinct script UTxOs, each with its own redeemer. */
|
|
239
239
|
function parseScriptInputs(json) {
|
|
240
240
|
if (!json)
|
|
241
|
-
return {
|
|
241
|
+
return { parsed: [] };
|
|
242
242
|
const jsonResult = (0, validators_1.validateJsonWithLimits)(json, 'scriptInputsJson');
|
|
243
243
|
if (!jsonResult.valid)
|
|
244
244
|
return { error: jsonResult.error };
|
|
245
|
-
if (!Array.isArray(jsonResult.parsed)
|
|
246
|
-
return { error: 'scriptInputsJson must be a
|
|
245
|
+
if (!Array.isArray(jsonResult.parsed)) {
|
|
246
|
+
return { error: 'scriptInputsJson must be a JSON array' };
|
|
247
247
|
}
|
|
248
248
|
if (jsonResult.parsed.length > exports.MAX_SCRIPT_INPUTS) {
|
|
249
249
|
return { error: `scriptInputsJson exceeds maximum of ${exports.MAX_SCRIPT_INPUTS} entries` };
|
package/srv/utils/types.d.ts
CHANGED
|
@@ -216,7 +216,8 @@ export interface PoolData {
|
|
|
216
216
|
/** Blocks minted in the current epoch; null when the backend has no such figure (Koios). */
|
|
217
217
|
blocksEpoch: number | null;
|
|
218
218
|
liveStake: string;
|
|
219
|
-
|
|
219
|
+
/** Share of the total live stake; null when the backend has no such figure (Koios). */
|
|
220
|
+
liveSize: number | null;
|
|
220
221
|
/** Fraction of the ideal (saturated) pool size, NOT percent: 0.7542 = 75.42 %. */
|
|
221
222
|
liveSaturation: number;
|
|
222
223
|
/** Null when the source cannot count delegators (Ogmios ledger state). */
|
|
@@ -670,6 +671,24 @@ export interface SigningWorkflowState {
|
|
|
670
671
|
failed?: string;
|
|
671
672
|
};
|
|
672
673
|
}
|
|
674
|
+
/** Depth of a transaction in the chain. Depth 1 means it sits in the tip block. */
|
|
675
|
+
export interface TransactionConfirmations {
|
|
676
|
+
txHash: string;
|
|
677
|
+
/** null while the tx is not on chain. */
|
|
678
|
+
blockHeight: number | null;
|
|
679
|
+
tipHeight: number | null;
|
|
680
|
+
/** 0 while the tx is not on chain. */
|
|
681
|
+
confirmations: number;
|
|
682
|
+
}
|
|
683
|
+
/** Result of verifyTxWitnesses: every vkey signature checked against the body hash. */
|
|
684
|
+
export interface TxWitnessVerification {
|
|
685
|
+
valid: boolean;
|
|
686
|
+
/** null when the CBOR could not be read. */
|
|
687
|
+
txBodyHash: string | null;
|
|
688
|
+
/** blake2b-224 of each vkey whose signature verifies. */
|
|
689
|
+
signerKeyHashes: string[];
|
|
690
|
+
errors: string[];
|
|
691
|
+
}
|
|
673
692
|
/** Result of signature verification */
|
|
674
693
|
export interface SignatureVerificationResult {
|
|
675
694
|
/** Whether the signature is valid */
|