@odatano/core 2.0.0-rc.26 → 2.0.0-rc.28
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/CardanoTransactionService/index.d.ts +12 -12
- package/package.json +1 -1
- package/srv/blockchain/backends/koios-backend.d.ts +1 -1
- package/srv/blockchain/backends/koios-backend.js +8 -6
- package/srv/blockchain/cardano-indexer.d.ts +1 -1
- package/srv/blockchain/cardano-tx-builder.d.ts +5 -0
- package/srv/blockchain/cardano-tx-builder.js +30 -1
- package/srv/blockchain/signing/submission-finalizer.js +0 -1
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +11 -0
- package/srv/blockchain/transaction-building/buildooor-tx.js +148 -14
- package/srv/blockchain/wallet-worker/build-request.js +8 -0
- package/srv/cardano-service.js +13 -17
- package/srv/cardano-tx-service.cds +19 -1
- package/srv/cardano-tx-service.js +65 -1
- package/srv/cardano-ui.cds +16 -16
- package/srv/server.js +11 -6
- package/srv/utils/const.d.ts +5 -2
- package/srv/utils/const.js +5 -2
- package/srv/utils/liveness.js +0 -1
- package/srv/utils/pg-inline-json.js +0 -1
- package/srv/utils/pg-order-nulls.js +0 -1
- package/srv/utils/tx-request-parsers.d.ts +43 -1
- package/srv/utils/tx-request-parsers.js +158 -1
- package/srv/utils/types.d.ts +50 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MAX_SCRIPT_INPUTS = exports.MAX_EXTRA_OUTPUTS = void 0;
|
|
3
|
+
exports.MAX_CERTIFICATES = exports.MAX_WITHDRAWALS = exports.MAX_SCRIPT_INPUTS = exports.MAX_EXTRA_OUTPUTS = void 0;
|
|
4
4
|
exports.parseUtxoRefArray = parseUtxoRefArray;
|
|
5
5
|
exports.parseRequiredSigners = parseRequiredSigners;
|
|
6
6
|
exports.parseAssetsArray = parseAssetsArray;
|
|
@@ -8,6 +8,8 @@ exports.parseExtraOutputs = parseExtraOutputs;
|
|
|
8
8
|
exports.parseOutputList = parseOutputList;
|
|
9
9
|
exports.parseMintActionPolicyFields = parseMintActionPolicyFields;
|
|
10
10
|
exports.parseScriptInputs = parseScriptInputs;
|
|
11
|
+
exports.parseWithdrawals = parseWithdrawals;
|
|
12
|
+
exports.parseCertificates = parseCertificates;
|
|
11
13
|
exports.parsePolicyMintActions = parsePolicyMintActions;
|
|
12
14
|
const validators_1 = require("./validators");
|
|
13
15
|
const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
@@ -334,6 +336,161 @@ function parseScriptInputs(json) {
|
|
|
334
336
|
}
|
|
335
337
|
return { parsed: out };
|
|
336
338
|
}
|
|
339
|
+
/** Upper bound on withdrawals per BuildPlutusTransaction. */
|
|
340
|
+
exports.MAX_WITHDRAWALS = 16;
|
|
341
|
+
/**
|
|
342
|
+
* Parse and validate withdrawalsJson: distinct reward accounts, lovelace >= 0, optionally a staking
|
|
343
|
+
* script (inline or by reference) with exactly one redeemer form; without a script no redeemer.
|
|
344
|
+
*/
|
|
345
|
+
function parseWithdrawals(json) {
|
|
346
|
+
if (!json)
|
|
347
|
+
return { parsed: undefined };
|
|
348
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(json, 'withdrawalsJson');
|
|
349
|
+
if (!jsonResult.valid)
|
|
350
|
+
return { error: jsonResult.error };
|
|
351
|
+
if (!Array.isArray(jsonResult.parsed))
|
|
352
|
+
return { error: 'withdrawalsJson must be a JSON array' };
|
|
353
|
+
if (jsonResult.parsed.length === 0)
|
|
354
|
+
return { parsed: undefined };
|
|
355
|
+
if (jsonResult.parsed.length > exports.MAX_WITHDRAWALS) {
|
|
356
|
+
return { error: `withdrawalsJson exceeds maximum of ${exports.MAX_WITHDRAWALS} entries` };
|
|
357
|
+
}
|
|
358
|
+
const out = [];
|
|
359
|
+
const seen = new Set();
|
|
360
|
+
for (let i = 0; i < jsonResult.parsed.length; i++) {
|
|
361
|
+
const entry = jsonResult.parsed[i];
|
|
362
|
+
const at = `withdrawals[${i}]`;
|
|
363
|
+
if (!entry || typeof entry !== 'object')
|
|
364
|
+
return { error: `${at} must be an object` };
|
|
365
|
+
if (typeof entry.rewardAddress !== 'string' || !(0, validators_1.isValidBech32StakeAddress)(entry.rewardAddress)) {
|
|
366
|
+
return { error: `${at}.rewardAddress must be a Bech32 stake address` };
|
|
367
|
+
}
|
|
368
|
+
const rewardAddress = entry.rewardAddress.toLowerCase();
|
|
369
|
+
if (seen.has(rewardAddress))
|
|
370
|
+
return { error: `${at} withdraws from ${rewardAddress} a second time` };
|
|
371
|
+
seen.add(rewardAddress);
|
|
372
|
+
const lovelace = typeof entry.lovelace === 'number' && Number.isInteger(entry.lovelace) && entry.lovelace >= 0
|
|
373
|
+
? String(entry.lovelace)
|
|
374
|
+
: typeof entry.lovelace === 'string' && /^\d+$/.test(entry.lovelace) ? entry.lovelace : undefined;
|
|
375
|
+
if (lovelace === undefined)
|
|
376
|
+
return { error: `${at}.lovelace must be a non-negative integer (0 for withdraw-zero)` };
|
|
377
|
+
const witness = parseStakingScriptWitness(entry, at, 'withdrawal');
|
|
378
|
+
if (witness.error)
|
|
379
|
+
return { error: witness.error };
|
|
380
|
+
out.push({ rewardAddress, lovelace, ...witness.parsed });
|
|
381
|
+
}
|
|
382
|
+
return { parsed: out };
|
|
383
|
+
}
|
|
384
|
+
function parseStakingScriptWitness(entry, at, kind) {
|
|
385
|
+
const present = (v) => v !== undefined && v !== null;
|
|
386
|
+
const parseJsonField = (value, field) => {
|
|
387
|
+
if (typeof value !== 'string')
|
|
388
|
+
return { error: `${field} must be a JSON string` };
|
|
389
|
+
const r = (0, validators_1.validatePlutusJson)(value, field);
|
|
390
|
+
return r.valid ? { parsed: r.parsed } : { error: r.error };
|
|
391
|
+
};
|
|
392
|
+
const w = {};
|
|
393
|
+
const hasInline = present(entry.stakingScript);
|
|
394
|
+
const hasRef = present(entry.referenceScript);
|
|
395
|
+
if (hasInline && hasRef)
|
|
396
|
+
return { error: `${at} takes stakingScript or referenceScript, not both` };
|
|
397
|
+
if (hasInline) {
|
|
398
|
+
if (typeof entry.stakingScript !== 'string' || !(0, validators_1.isValidCbor)(entry.stakingScript)) {
|
|
399
|
+
return { error: `${at}.stakingScript must be even-length CBOR hex` };
|
|
400
|
+
}
|
|
401
|
+
w.stakingScript = entry.stakingScript;
|
|
402
|
+
if (present(entry.scriptParamsJson)) {
|
|
403
|
+
const params = parseJsonField(entry.scriptParamsJson, `${at}.scriptParamsJson`);
|
|
404
|
+
if (params.error)
|
|
405
|
+
return { error: params.error };
|
|
406
|
+
if (!Array.isArray(params.parsed))
|
|
407
|
+
return { error: `${at}.scriptParamsJson must be a JSON array` };
|
|
408
|
+
if (params.parsed.length > 0)
|
|
409
|
+
w.scriptParams = params.parsed;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
else if (hasRef) {
|
|
413
|
+
const ref = entry.referenceScript;
|
|
414
|
+
if (!ref || typeof ref !== 'object' || typeof ref.txHash !== 'string' || !(0, validators_1.isTxHash)(ref.txHash)
|
|
415
|
+
|| typeof ref.outputIndex !== 'number' || !Number.isInteger(ref.outputIndex) || ref.outputIndex < 0) {
|
|
416
|
+
return { error: `${at}.referenceScript must be {txHash, outputIndex} of the UTxO carrying the script` };
|
|
417
|
+
}
|
|
418
|
+
if (present(entry.scriptParamsJson))
|
|
419
|
+
return { error: `${at}.scriptParamsJson applies to an inline stakingScript only` };
|
|
420
|
+
w.referenceScript = { txHash: ref.txHash.toLowerCase(), outputIndex: ref.outputIndex };
|
|
421
|
+
}
|
|
422
|
+
else if (present(entry.scriptParamsJson)) {
|
|
423
|
+
return { error: `${at}.scriptParamsJson applies to an inline stakingScript only` };
|
|
424
|
+
}
|
|
425
|
+
const hasRedeemerJson = present(entry.redeemerJson);
|
|
426
|
+
const hasRedeemerCbor = present(entry.redeemerCbor);
|
|
427
|
+
if (hasInline || hasRef) {
|
|
428
|
+
if (hasRedeemerJson === hasRedeemerCbor)
|
|
429
|
+
return { error: `${at} needs exactly one of redeemerJson or redeemerCbor` };
|
|
430
|
+
if (hasRedeemerCbor) {
|
|
431
|
+
const cbor = parsePlutusCbor(entry.redeemerCbor, `${at}.redeemerCbor`);
|
|
432
|
+
if (cbor.error)
|
|
433
|
+
return { error: cbor.error };
|
|
434
|
+
w.redeemerCbor = cbor.hex;
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
437
|
+
const redeemer = parseJsonField(entry.redeemerJson, `${at}.redeemerJson`);
|
|
438
|
+
if (redeemer.error)
|
|
439
|
+
return { error: redeemer.error };
|
|
440
|
+
w.redeemer = redeemer.parsed;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
else if (hasRedeemerJson || hasRedeemerCbor) {
|
|
444
|
+
return { error: `${at} has a redeemer but no staking script; a key-witnessed ${kind} takes none` };
|
|
445
|
+
}
|
|
446
|
+
return { parsed: w };
|
|
447
|
+
}
|
|
448
|
+
/** Upper bound on certificates per BuildPlutusTransaction. */
|
|
449
|
+
exports.MAX_CERTIFICATES = 16;
|
|
450
|
+
/**
|
|
451
|
+
* Parse and validate certificatesJson: stake registrations and deregistrations, each with an
|
|
452
|
+
* optional staking script (inline or by reference) and exactly one redeemer form when scripted.
|
|
453
|
+
*/
|
|
454
|
+
function parseCertificates(json) {
|
|
455
|
+
if (!json)
|
|
456
|
+
return { parsed: undefined };
|
|
457
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(json, 'certificatesJson');
|
|
458
|
+
if (!jsonResult.valid)
|
|
459
|
+
return { error: jsonResult.error };
|
|
460
|
+
if (!Array.isArray(jsonResult.parsed))
|
|
461
|
+
return { error: 'certificatesJson must be a JSON array' };
|
|
462
|
+
if (jsonResult.parsed.length === 0)
|
|
463
|
+
return { parsed: undefined };
|
|
464
|
+
if (jsonResult.parsed.length > exports.MAX_CERTIFICATES) {
|
|
465
|
+
return { error: `certificatesJson exceeds maximum of ${exports.MAX_CERTIFICATES} entries` };
|
|
466
|
+
}
|
|
467
|
+
const out = [];
|
|
468
|
+
for (let i = 0; i < jsonResult.parsed.length; i++) {
|
|
469
|
+
const entry = jsonResult.parsed[i];
|
|
470
|
+
const at = `certificates[${i}]`;
|
|
471
|
+
if (!entry || typeof entry !== 'object')
|
|
472
|
+
return { error: `${at} must be an object` };
|
|
473
|
+
if (entry.type !== 'registerStake' && entry.type !== 'deregisterStake') {
|
|
474
|
+
return { error: `${at}.type must be registerStake or deregisterStake` };
|
|
475
|
+
}
|
|
476
|
+
if (typeof entry.stakeAddress !== 'string' || !(0, validators_1.isValidBech32StakeAddress)(entry.stakeAddress)) {
|
|
477
|
+
return { error: `${at}.stakeAddress must be a Bech32 stake address` };
|
|
478
|
+
}
|
|
479
|
+
let deposit;
|
|
480
|
+
if (entry.deposit !== undefined && entry.deposit !== null) {
|
|
481
|
+
deposit = typeof entry.deposit === 'number' && Number.isInteger(entry.deposit) && entry.deposit > 0
|
|
482
|
+
? String(entry.deposit)
|
|
483
|
+
: typeof entry.deposit === 'string' && /^\d+$/.test(entry.deposit) && entry.deposit !== '0' ? entry.deposit : undefined;
|
|
484
|
+
if (deposit === undefined)
|
|
485
|
+
return { error: `${at}.deposit must be a positive integer (lovelace)` };
|
|
486
|
+
}
|
|
487
|
+
const witness = parseStakingScriptWitness(entry, at, 'certificate');
|
|
488
|
+
if (witness.error)
|
|
489
|
+
return { error: witness.error };
|
|
490
|
+
out.push({ type: entry.type, stakeAddress: entry.stakeAddress.toLowerCase(), ...(deposit ? { deposit } : {}), ...witness.parsed });
|
|
491
|
+
}
|
|
492
|
+
return { parsed: out };
|
|
493
|
+
}
|
|
337
494
|
/**
|
|
338
495
|
* Parse mintActionsJson for BuildPlutusTransaction: every action carries its own `mintingPolicyScript`
|
|
339
496
|
* (no request-level default) and optional `redeemerJson`; `assetUnit` is policyId+assetName, or a bare
|
package/srv/utils/types.d.ts
CHANGED
|
@@ -378,6 +378,11 @@ export type TxBuildRequest = {
|
|
|
378
378
|
txHash: string;
|
|
379
379
|
outputIndex: number;
|
|
380
380
|
}>;
|
|
381
|
+
/** UTxOs the build must never spend: left out of coin selection and collateral. */
|
|
382
|
+
protectInputs?: Array<{
|
|
383
|
+
txHash: string;
|
|
384
|
+
outputIndex: number;
|
|
385
|
+
}>;
|
|
381
386
|
/** CIP-31 reference inputs (read-only, not consumed), passed as readonlyRefInputs to Buildooor. */
|
|
382
387
|
referenceInputs?: Array<{
|
|
383
388
|
txHash: string;
|
|
@@ -437,10 +442,54 @@ export type PlutusTxOutput = NonNullable<TxBuildRequest['extraOutputs']>[number]
|
|
|
437
442
|
/** Inline datum as PlutusData CBOR hex, taken byte for byte; exclusive with inlineDatum. */
|
|
438
443
|
inlineDatumCbor?: string;
|
|
439
444
|
};
|
|
445
|
+
/**
|
|
446
|
+
* Reward-account withdrawal of a BuildPlutusTransaction. A staking script (inline or by reference)
|
|
447
|
+
* runs with the redeemer under the Reward purpose; without a script the stake key signs.
|
|
448
|
+
*/
|
|
449
|
+
export type WithdrawalInput = {
|
|
450
|
+
/** Bech32 reward account (stake address). */
|
|
451
|
+
rewardAddress: string;
|
|
452
|
+
/** Withdrawn lovelace; 0 for the withdraw-zero pattern. */
|
|
453
|
+
lovelace: string;
|
|
454
|
+
/** Staking script CBOR hex (script params already applied); exclusive with referenceScript. */
|
|
455
|
+
stakingScript?: string;
|
|
456
|
+
/** UTxO that carries the staking script as reference script; added as reference input. */
|
|
457
|
+
referenceScript?: {
|
|
458
|
+
txHash: string;
|
|
459
|
+
outputIndex: number;
|
|
460
|
+
};
|
|
461
|
+
/** Redeemer (PlutusData JSON); `__INPUT_IDX__` placeholders resolve against the final inputs. */
|
|
462
|
+
redeemer?: JSONValue;
|
|
463
|
+
/** Redeemer as PlutusData CBOR hex; wins over `redeemer`, no placeholders. */
|
|
464
|
+
redeemerCbor?: string;
|
|
465
|
+
};
|
|
466
|
+
/**
|
|
467
|
+
* Stake-credential certificate of a BuildPlutusTransaction. A registration without a script is the
|
|
468
|
+
* witness-free legacy form (key or script credential); with a script the Conway deposit form, run
|
|
469
|
+
* under the Certifying purpose. A deregistration needs the key's witness or the script.
|
|
470
|
+
*/
|
|
471
|
+
export type CertificateInput = {
|
|
472
|
+
type: 'registerStake' | 'deregisterStake';
|
|
473
|
+
/** Bech32 stake address of the credential. */
|
|
474
|
+
stakeAddress: string;
|
|
475
|
+
/** Explicit deposit (lovelace) for the Conway forms; defaults to the protocol's stake deposit. */
|
|
476
|
+
deposit?: string;
|
|
477
|
+
stakingScript?: string;
|
|
478
|
+
referenceScript?: {
|
|
479
|
+
txHash: string;
|
|
480
|
+
outputIndex: number;
|
|
481
|
+
};
|
|
482
|
+
redeemer?: JSONValue;
|
|
483
|
+
redeemerCbor?: string;
|
|
484
|
+
};
|
|
440
485
|
/** BuildPlutusTransaction: several script inputs, the outputs as given, change after them. */
|
|
441
|
-
export type TxBuildPlutusRequest = Pick<TxBuildRequest, 'network' | 'senderAddress' | 'changeAddress' | 'requiredSigners' | 'forceInputs' | 'referenceInputs' | 'mintActions' | 'validityStartMs' | 'validityEndMs'> & {
|
|
486
|
+
export type TxBuildPlutusRequest = Pick<TxBuildRequest, 'network' | 'senderAddress' | 'changeAddress' | 'requiredSigners' | 'forceInputs' | 'protectInputs' | 'referenceInputs' | 'mintActions' | 'validityStartMs' | 'validityEndMs'> & {
|
|
442
487
|
scriptInputs: ScriptInput[];
|
|
443
488
|
outputs: PlutusTxOutput[];
|
|
489
|
+
/** Reward-account withdrawals, with or without a staking script. */
|
|
490
|
+
withdrawals?: WithdrawalInput[];
|
|
491
|
+
/** Stake-credential registrations and deregistrations. */
|
|
492
|
+
certificates?: CertificateInput[];
|
|
444
493
|
};
|
|
445
494
|
/** Execution budget for Plutus scripts */
|
|
446
495
|
export type ExecutionBudget = {
|