@harmoniclabs/plu-ts-offchain
Advanced tools
Comparing version 0.1.12 to 0.1.13
@@ -8,2 +8,11 @@ "use strict"; | ||
var getSpendingPurposeData_1 = require("./getSpendingPurposeData.js"); | ||
var uint8array_utils_1 = require("@harmoniclabs/uint8array-utils"); | ||
function sortUTxO(a, b) { | ||
var ord = (0, uint8array_utils_1.lexCompare)(a.utxoRef.id.toBuffer(), b.utxoRef.id.toBuffer()); | ||
// if equal tx id order based on tx output index | ||
if (ord === 0) | ||
return a.utxoRef.index - b.utxoRef.index; | ||
// else order by tx id | ||
return ord; | ||
} | ||
function getTxInfos(transaction, genesisInfos) { | ||
@@ -15,11 +24,13 @@ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; | ||
} | ||
var sortedInputs = tx.inputs.slice().sort(sortUTxO); | ||
var sortedRefInputs = (_a = tx.refInputs) === null || _a === void 0 ? void 0 : _a.slice().sort(sortUTxO); | ||
var feeData = cardano_ledger_ts_1.Value.lovelaces(tx.fee).toData(); | ||
var mintData = ((_a = tx.mint) !== null && _a !== void 0 ? _a : cardano_ledger_ts_1.Value.lovelaces(0)).toData(); | ||
var certsData = new plutus_data_1.DataList((_c = (_b = tx.certs) === null || _b === void 0 ? void 0 : _b.map(function (cert) { return cert.toData(); })) !== null && _c !== void 0 ? _c : []); | ||
var withdrawsData = (_e = (_d = tx.withdrawals) === null || _d === void 0 ? void 0 : _d.toData()) !== null && _e !== void 0 ? _e : new plutus_data_1.DataMap([]); | ||
var mintData = ((_b = tx.mint) !== null && _b !== void 0 ? _b : cardano_ledger_ts_1.Value.lovelaces(0)).toData(); | ||
var certsData = new plutus_data_1.DataList((_d = (_c = tx.certs) === null || _c === void 0 ? void 0 : _c.map(function (cert) { return cert.toData(); })) !== null && _d !== void 0 ? _d : []); | ||
var withdrawsData = (_f = (_e = tx.withdrawals) === null || _e === void 0 ? void 0 : _e.toData()) !== null && _f !== void 0 ? _f : new plutus_data_1.DataMap([]); | ||
var intervalData = (0, getTxIntervalData_1.getTxIntervalData)(tx.validityIntervalStart, tx.ttl, genesisInfos); | ||
var sigsData = new plutus_data_1.DataList((_g = (_f = tx.requiredSigners) === null || _f === void 0 ? void 0 : _f.map(function (sig) { return sig.toData(); })) !== null && _g !== void 0 ? _g : []); | ||
var datumsData = new plutus_data_1.DataMap((_j = (_h = witnesses.datums) === null || _h === void 0 ? void 0 : _h.map(function (dat) { | ||
var sigsData = new plutus_data_1.DataList((_h = (_g = tx.requiredSigners) === null || _g === void 0 ? void 0 : _g.map(function (sig) { return sig.toData(); })) !== null && _h !== void 0 ? _h : []); | ||
var datumsData = new plutus_data_1.DataMap((_k = (_j = witnesses.datums) === null || _j === void 0 ? void 0 : _j.map(function (dat) { | ||
return new plutus_data_1.DataPair(new plutus_data_1.DataB((0, plutus_data_1.hashData)(dat)), dat); | ||
})) !== null && _j !== void 0 ? _j : []); | ||
})) !== null && _k !== void 0 ? _k : []); | ||
var txIdData = new plutus_data_1.DataB(tx.hash.toBuffer()); | ||
@@ -31,3 +42,3 @@ var v1 = undefined; | ||
// inputs | ||
new plutus_data_1.DataList(tx.inputs.map(function (input) { return input.toData("v1"); })), | ||
new plutus_data_1.DataList(sortedInputs.map(function (input) { return input.toData("v1"); })), | ||
// outputs | ||
@@ -60,5 +71,5 @@ new plutus_data_1.DataList(tx.outputs.map(function (out) { return out.toData("v1"); })), | ||
// inputs | ||
new plutus_data_1.DataList(tx.inputs.map(function (input) { return input.toData("v2"); })), | ||
new plutus_data_1.DataList(sortedInputs.map(function (input) { return input.toData("v2"); })), | ||
// refInputs | ||
new plutus_data_1.DataList((_l = (_k = tx.refInputs) === null || _k === void 0 ? void 0 : _k.map(function (refIn) { return refIn.toData("v2"); })) !== null && _l !== void 0 ? _l : []), | ||
new plutus_data_1.DataList((_l = sortedRefInputs === null || sortedRefInputs === void 0 ? void 0 : sortedRefInputs.map(function (refIn) { return refIn.toData("v2"); })) !== null && _l !== void 0 ? _l : []), | ||
// outputs | ||
@@ -65,0 +76,0 @@ new plutus_data_1.DataList(tx.outputs.map(function (out) { return out.toData("v2"); })), |
@@ -39,2 +39,17 @@ import { GenesisInfos } from "./GenesisInfos.js"; | ||
build: (args: ITxBuildArgs, opts?: ITxBuildOptions) => Promise<Tx>; | ||
/** | ||
* replaces the redeemers and clears vkeyWitnesses in the witness set | ||
* and re-computes the `scriptDataHash` in the body | ||
* | ||
* the input transaction is readonly and is not modified | ||
* | ||
* **A NEW TRANSACTION IS CREATED** with vkey witness set empty | ||
* (the new transaction is unsigned) | ||
* | ||
* to summarize, the new transaction differs in: | ||
* 1) `tx.body.scriptDataHash` | ||
* 2) `tx.witnesses.redeemers` | ||
* 3) `tx.witnesses.vkeyWitnesses` (empty) | ||
*/ | ||
overrideTxRedeemers(tx: Tx, newRedeemers: TxRedeemer[]): Tx; | ||
buildSync(buildArgs: ITxBuildArgs, { onScriptInvalid, onScriptResult }?: ITxBuildSyncOptions): Tx; | ||
@@ -41,0 +56,0 @@ assertMinOutLovelaces(txOuts: TxOut[]): void; |
@@ -222,2 +222,24 @@ "use strict"; | ||
}; | ||
/** | ||
* replaces the redeemers and clears vkeyWitnesses in the witness set | ||
* and re-computes the `scriptDataHash` in the body | ||
* | ||
* the input transaction is readonly and is not modified | ||
* | ||
* **A NEW TRANSACTION IS CREATED** with vkey witness set empty | ||
* (the new transaction is unsigned) | ||
* | ||
* to summarize, the new transaction differs in: | ||
* 1) `tx.body.scriptDataHash` | ||
* 2) `tx.witnesses.redeemers` | ||
* 3) `tx.witnesses.vkeyWitnesses` (empty) | ||
*/ | ||
TxBuilder.prototype.overrideTxRedeemers = function (tx, newRedeemers) { | ||
var _a; | ||
// datums passed by hash | ||
var datums = (_a = tx.witnesses.datums) !== null && _a !== void 0 ? _a : []; | ||
return new cardano_ledger_ts_1.Tx(__assign(__assign({}, tx), { body: new cardano_ledger_ts_1.TxBody(__assign(__assign({}, tx.body), { scriptDataHash: getScriptDataHash(newRedeemers, datums.length > 0 ? | ||
Array.from(cbor_1.Cbor.encode(new cbor_1.CborArray(datums.map(plutus_data_1.dataToCborObj))).toBuffer()) | ||
: [], (0, cardano_costmodels_ts_1.costModelsToLanguageViewCbor)(this.protocolParamters.costModels, { mustHaveV2: true, mustHaveV1: false }).toBuffer()) })), witnesses: new cardano_ledger_ts_1.TxWitnessSet(__assign(__assign({}, tx.witnesses), { vkeyWitnesses: [], redeemers: newRedeemers })) })); | ||
}; | ||
TxBuilder.prototype.buildSync = function (buildArgs, _a) { | ||
@@ -224,0 +246,0 @@ var _b; |
{ | ||
"name": "@harmoniclabs/plu-ts-offchain", | ||
"version": "0.1.12", | ||
"version": "0.1.13", | ||
"description": "An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript", | ||
@@ -80,8 +80,6 @@ "main": "./dist/index.js", | ||
"jest-environment-jsdom": "^29.4.3", | ||
"rollup": "^3.18.0", | ||
"tsc-alias": "^1.7.1", | ||
"typescript": "^4.6.3", | ||
"v8-profiler-next": "^1.9.0" | ||
"typescript": "^4.6.3" | ||
}, | ||
"funding": "https://github.com/sponsors/HarmonicLabs" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
180103
10
3339