New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cardano-pab-client

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cardano-pab-client - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

dist/src/ContractEndpoints/index.d.ts

2

dist/src/Balancer/CoinSelection.d.ts

@@ -181,3 +181,3 @@ import type * as SL from "@emurgo/cardano-serialization-lib-browser";

*/
randomImprove: (inputs: any, mergedOutputsAmounts: any, limit: any) => Promise<SelectionResult>;
randomImprove: (inputs: any, mergedOutputsAmounts: any, limit: any, S: typeof SL) => Promise<SelectionResult>;
splitAmounts: typeof splitAmounts;

@@ -184,0 +184,0 @@ compare: typeof compare;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -69,9 +46,6 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

*/
randomImprove: (inputs, mergedOutputsAmounts, limit) => __awaiter(void 0, void 0, void 0, function* () {
randomImprove: (inputs, mergedOutputsAmounts, limit, S) => __awaiter(void 0, void 0, void 0, function* () {
if (!protocolParameters) {
throw new Error("Protocol parameters not set. Use setProtocolParameters().");
}
const SerLibLoader = (yield Promise.resolve().then(() => __importStar(require("../SerLibLoader")))).default;
SerLibLoader.load();
const S = SerLibLoader.lib;
/** @type {UTxOSelection} */

@@ -78,0 +52,0 @@ let utxoSelection = {

@@ -130,3 +130,3 @@ /**

* @param utxMint Minting information of the transaction.
* @param inputsInfo Complete information about the inputs.
* @param inputsUtxos The tx inputs UTxOs.
* @returns The sum of the inputs values minus the burning that happens in the transaction.

@@ -178,5 +178,5 @@ */

* Given an output list and an address, it merges the outputs belonging to that address into a
* single one.
* single one at the end of the outputs list.
* @param outputs The outputs to look up for the ones belonging to the specified address.
* @param addr The address.
* @param addr The address in hex format.
* @returns The new outputs.

@@ -254,2 +254,24 @@ */

}
/**
* The UTxOs that can be candidate must not already be in the inputs of the tx.
* @param inputsInfo Complete information about the inputs.
* @param walletUTxOs The wallet UTxOs.
* @returns The UTxOs that can be selected by the coin selection algorithm.
*/
export declare function getCandidateUTxOsForCoinSelection(walletUTxOs: S.TransactionUnspentOutput[], inputsUtxos: S.TransactionUnspentOutput[]): S.TransactionUnspentOutput[];
/**
* The index of a redeemer must be set according to the lexicographical order of the inputs,
* so here we precomute this ordering for correctly setting the redeemer's indexes.
* @param txInputs The transaction inputs in the correct order.
* @returns The array of indexes oif each input regarding the lexicographical order.
*/
export declare function calculateSortedInputIndexes(txInputs: S.TransactionInput[]): number[];
/**
* Calculates the exact network fee needed by the Cardano Node for the transaction to be successful.
* @param tx The transaction.
* @param amountOfVkeyWitnesses The amount of witnesses that the transaction needs to be valid.
* @param param2 Some protocol parameters needed by the calculation.
* @returns The needed fee of the given transaction.
*/
export declare function calculateFee(tx: S.Transaction, amountOfVkeyWitnesses: number, { linearFee, priceStep, priceMem }: Pick<ProtocolParameters, "linearFee" | "priceStep" | "priceMem">): number;
export {};

@@ -43,2 +43,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.calculateFee = exports.calculateSortedInputIndexes = exports.getCandidateUTxOsForCoinSelection = void 0;
const SerLibLoader_1 = __importDefault(require("../SerLibLoader"));
const CoinSelection_1 = __importStar(require("./CoinSelection"));

@@ -66,5 +68,4 @@ const serLibPrinter_1 = require("./serLibPrinter");

return __awaiter(this, void 0, void 0, function* () {
const SerLibLoader = (yield Promise.resolve().then(() => __importStar(require("../SerLibLoader")))).default;
yield SerLibLoader.load();
return new Balancer(protocolParameters, SerLibLoader.lib);
yield SerLibLoader_1.default.load();
return new Balancer(protocolParameters, SerLibLoader_1.default.lib);
});

@@ -114,5 +115,5 @@ }

const utxBody = utx.body();
const alreadyPaidValue = this.getAlreadyPaidValue(utxBody.mint(), inputsInfo);
const alreadyPaidValue = this.getAlreadyPaidValue(utxBody.mint(), inputsInfo.inputsUtxos);
const totalValueToPay = this.getTotalValueToPay(utxBody.outputs(), utxBody.mint(), feeUpperBound);
const candidateUTxOs = getCandidateUTxOsForCoinSelection(inputsInfo, walletUtxos);
const candidateUTxOs = getCandidateUTxOsForCoinSelection(walletUtxos, inputsInfo.inputsUtxos);
const { selectedUtxos, change } = yield this.runCoinSelection(totalValueToPay, alreadyPaidValue, candidateUTxOs, { linearFee, minUtxo, maxTxSize });

@@ -196,10 +197,10 @@ // update the txInfoInputs object adding the newly selected utxos.

* @param utxMint Minting information of the transaction.
* @param inputsInfo Complete information about the inputs.
* @param inputsUtxos The tx inputs UTxOs.
* @returns The sum of the inputs values minus the burning that happens in the transaction.
*/
getAlreadyPaidValue(utxMint, inputsInfo) {
getAlreadyPaidValue(utxMint, inputsUtxos) {
let alreadyPaidValue = this.S.Value.zero();
// sum values of wallet and script inputs
inputsInfo.inputsUtxos.forEach((inputUtxo) => {
alreadyPaidValue = alreadyPaidValue.checked_add(inputUtxo.output().amount());
inputsUtxos.forEach((utxo) => {
alreadyPaidValue = alreadyPaidValue.checked_add(utxo.output().amount());
});

@@ -253,3 +254,5 @@ // if there is burning of an asset present in the inputs of the transaction,

const redeemers = this.buildRedeemers(witnessSet.redeemers(), txInputs);
witnessSet.set_redeemers(redeemers);
if (redeemers) {
witnessSet.set_redeemers(redeemers);
}
return witnessSet;

@@ -265,6 +268,4 @@ }

var _a, _b;
// XXX: if there's no redeemers, the new redeemers will be an empty object.
// maybe we should return undefined and let undefined the redeemers field of the tx?
const newRedeemers = this.S.Redeemers.new();
if (redeemers) {
const newRedeemers = this.S.Redeemers.new();
const sortedInputIndexes = calculateSortedInputIndexes(txInputs);

@@ -279,4 +280,5 @@ for (let i = 0; i < redeemers.len(); i += 1) {

}
return newRedeemers;
}
return newRedeemers;
return redeemers;
}

@@ -366,5 +368,5 @@ /**

* Given an output list and an address, it merges the outputs belonging to that address into a
* single one.
* single one at the end of the outputs list.
* @param outputs The outputs to look up for the ones belonging to the specified address.
* @param addr The address.
* @param addr The address in hex format.
* @returns The new outputs.

@@ -384,11 +386,13 @@ */

}
if (toBeMerged.len() < 2) {
// no need to modify the outputs
return outputs;
}
let mergedValue = this.S.Value.zero();
if (toBeMerged.len() > 0) {
for (let i = 0; i < toBeMerged.len(); i += 1) {
const output = toBeMerged.get(i);
mergedValue = mergedValue.checked_add(output.amount());
}
const newOutput = this.S.TransactionOutput.new(this.S.Address.from_bech32(addr), mergedValue);
result.add(newOutput);
for (let i = 0; i < toBeMerged.len(); i += 1) {
const output = toBeMerged.get(i);
mergedValue = mergedValue.checked_add(output.amount());
}
const newOutput = this.S.TransactionOutput.new(this.S.Address.from_hex(addr), mergedValue);
result.add(newOutput);
return result;

@@ -445,3 +449,3 @@ }

CoinSelection_1.default.setProtocolParameters(minUtxo, linearFee.minFeeA.toString(), linearFee.minFeeB.toString(), maxTxSize.toString());
const selection = yield CoinSelection_1.default.randomImprove(candidateUtxosForCoinSelection, mustBePaid, 20);
const selection = yield CoinSelection_1.default.randomImprove(candidateUtxosForCoinSelection, mustBePaid, 20, this.S);
selectedUtxos = selection.input;

@@ -513,3 +517,3 @@ // here the change is the unused "sub-value" of the inputs present in the

// look for suitable output to add the change to
if (changeOutputIndex) {
if (changeOutputIndex !== undefined) {
// user specified the change output index

@@ -613,4 +617,4 @@ if (changeOutputIndex < 0 && outputs.len() - 1 < changeOutputIndex) {

*/
function getCandidateUTxOsForCoinSelection(inputsInfo, walletUTxOs) {
return walletUTxOs.filter((walletUTxO) => !inputsInfo.inputsUtxos.find((inputUTxO) =>
function getCandidateUTxOsForCoinSelection(walletUTxOs, inputsUtxos) {
return walletUTxOs.filter((walletUTxO) => !inputsUtxos.find((inputUTxO) =>
// eslint-disable-next-line implicit-arrow-linebreak

@@ -620,2 +624,3 @@ walletUTxO.input().transaction_id().to_hex() === inputUTxO.input().transaction_id().to_hex()

}
exports.getCandidateUTxOsForCoinSelection = getCandidateUTxOsForCoinSelection;
/**

@@ -658,2 +663,3 @@ * Function that given a redeemer, it gives the input index that references taking in account their

}
exports.calculateSortedInputIndexes = calculateSortedInputIndexes;
/**

@@ -669,13 +675,10 @@ * Calculates the exact network fee needed by the Cardano Node for the transaction to be successful.

const totalExUnits = (_a = tx.witness_set().redeemers()) === null || _a === void 0 ? void 0 : _a.total_ex_units();
let exUnitsMem;
let exUnitsSteps;
let exUnitsMem = 0;
let exUnitsSteps = 0;
if (totalExUnits) {
exUnitsMem = Number(totalExUnits.mem().to_str());
console.log("Total mem units:", exUnitsMem);
exUnitsSteps = Number(totalExUnits.steps().to_str());
console.log("Total steps units:", exUnitsSteps);
}
else {
throw new Error("Execution units not set.");
}
console.log("Total mem units:", exUnitsMem);
console.log("Total steps units:", exUnitsSteps);
// Regarding calculation of the size of the vkeyWitness:

@@ -692,2 +695,3 @@ // Each pair (vkey, signature) has 101 bytes in size, and

}
exports.calculateFee = calculateFee;
/**

@@ -694,0 +698,0 @@ * NOTE ON HOW TO USE IT: pass a deep copied `oldTxBody`!

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -34,3 +11,7 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const SerLibLoader_1 = __importDefault(require("../SerLibLoader"));
/**

@@ -112,5 +93,4 @@ * The purpose of this class is to build the complete information about each input

return __awaiter(this, void 0, void 0, function* () {
const SerLibLoader = (yield Promise.resolve().then(() => __importStar(require("../SerLibLoader")))).default;
yield SerLibLoader.load();
return new TxInputsInfo(transaction, scriptInputsInfo, walletUTxOs, SerLibLoader.lib);
yield SerLibLoader_1.default.load();
return new TxInputsInfo(transaction, scriptInputsInfo, walletUTxOs, SerLibLoader_1.default.lib);
});

@@ -161,3 +141,3 @@ }

assets.push({
asset_name: policyAsset.to_hex(),
asset_name: policyAsset.to_json().split("\"").join(""),
quantity: Number((_c = (_b = multiasset.get(policy)) === null || _b === void 0 ? void 0 : _b.get(policyAsset)) === null || _c === void 0 ? void 0 : _c.to_str()),

@@ -164,0 +144,0 @@ policy_id: policy.to_hex(),

@@ -7,25 +7,2 @@ "use strict";

*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -45,2 +22,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

const blake2b_1 = __importDefault(require("blake2b"));
const SerLibLoader_1 = __importDefault(require("../SerLibLoader"));
const common_1 = require("../common");

@@ -67,5 +45,4 @@ /**

return __awaiter(this, void 0, void 0, function* () {
const SerLibLoader = (yield Promise.resolve().then(() => __importStar(require("../SerLibLoader")))).default;
yield SerLibLoader.load();
return new CIP30WalletWrapper(walletObject, SerLibLoader.lib);
yield SerLibLoader_1.default.load();
return new CIP30WalletWrapper(walletObject, SerLibLoader_1.default.lib);
});

@@ -72,0 +49,0 @@ }

@@ -48,8 +48,3 @@ /**

};
export declare type ExportTxRedeemer = (SpendingRedeemer | MintingRedeemer) & {
units?: {
mem: string;
cpu: string;
};
};
export declare type ExportTxRedeemer = SpendingRedeemer | MintingRedeemer;
export declare type Amount = {

@@ -56,0 +51,0 @@ unit: string;

@@ -8,3 +8,8 @@ /**

import PABApi from "./PABApi";
import Value from "./PABApi/types/Value";
import AssetClass from "./PABApi/types/AssetClass";
import TxOutRef from "./PABApi/types/TxOutRef";
import { Plutus } from "./PABApi/types/Plutus";
import ContractEndpoints from "./ContractEndpoints";
import WalletAddress from "./ContractEndpoints/WalletAddress";
import TxBudgetAPI from "./TxBudgetApi";

@@ -15,2 +20,2 @@ import SerLibLoader from "./SerLibLoader";

import { failed, succeeded } from "./common";
export { CIP30WalletWrapper, Balancer, PABApi, ContractEndpoints, TxBudgetAPI, SerLibLoader, TxInputsInfo, getWalletInitialAPI, getProtocolParamsFromBlockfrost, succeeded, failed, };
export { CIP30WalletWrapper, PABApi, ContractEndpoints, TxBudgetAPI, Balancer, TxInputsInfo, SerLibLoader, Value, AssetClass, TxOutRef, WalletAddress, Plutus, getWalletInitialAPI, getProtocolParamsFromBlockfrost, succeeded, failed, };

@@ -10,3 +10,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.failed = exports.succeeded = exports.getProtocolParamsFromBlockfrost = exports.getWalletInitialAPI = exports.TxInputsInfo = exports.SerLibLoader = exports.TxBudgetAPI = exports.ContractEndpoints = exports.PABApi = exports.Balancer = exports.CIP30WalletWrapper = void 0;
exports.failed = exports.succeeded = exports.getProtocolParamsFromBlockfrost = exports.getWalletInitialAPI = exports.Plutus = exports.WalletAddress = exports.TxOutRef = exports.AssetClass = exports.Value = exports.SerLibLoader = exports.TxInputsInfo = exports.Balancer = exports.TxBudgetAPI = exports.ContractEndpoints = exports.PABApi = exports.CIP30WalletWrapper = void 0;
const CIP30WalletWrapper_1 = __importDefault(require("./CIP30WalletWrapper"));

@@ -18,4 +18,14 @@ exports.CIP30WalletWrapper = CIP30WalletWrapper_1.default;

exports.PABApi = PABApi_1.default;
const Value_1 = __importDefault(require("./PABApi/types/Value"));
exports.Value = Value_1.default;
const AssetClass_1 = __importDefault(require("./PABApi/types/AssetClass"));
exports.AssetClass = AssetClass_1.default;
const TxOutRef_1 = __importDefault(require("./PABApi/types/TxOutRef"));
exports.TxOutRef = TxOutRef_1.default;
const Plutus_1 = require("./PABApi/types/Plutus");
Object.defineProperty(exports, "Plutus", { enumerable: true, get: function () { return Plutus_1.Plutus; } });
const ContractEndpoints_1 = __importDefault(require("./ContractEndpoints"));
exports.ContractEndpoints = ContractEndpoints_1.default;
const WalletAddress_1 = __importDefault(require("./ContractEndpoints/WalletAddress"));
exports.WalletAddress = WalletAddress_1.default;
const TxBudgetApi_1 = __importDefault(require("./TxBudgetApi"));

@@ -22,0 +32,0 @@ exports.TxBudgetAPI = TxBudgetApi_1.default;

{
"name": "cardano-pab-client",
"version": "0.0.6",
"version": "0.0.7",
"description": "A set of tools to develop frontends that interact with the Plutus Application Backend.",

@@ -32,3 +32,3 @@ "author": "Plank",

"devDependencies": {
"@emurgo/cardano-serialization-lib-nodejs": "^11.2.1",
"@emurgo/cardano-serialization-lib-nodejs": "11.1.0",
"@jest/globals": "^29.3.1",

@@ -50,3 +50,3 @@ "@types/blake2b": "^2.1.0",

"dependencies": {
"@emurgo/cardano-serialization-lib-browser": "^11.1.0",
"@emurgo/cardano-serialization-lib-browser": "11.1.0",
"axios": "^1.1.3",

@@ -53,0 +53,0 @@ "blake2b": "^2.1.4"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc