Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fivebinaries/coin-selection

Package Overview
Dependencies
Maintainers
3
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fivebinaries/coin-selection - npm Package Compare versions

Comparing version 2.0.0-beta.7 to 2.0.0-beta.8

4

lib/cjs/index.d.ts

@@ -1,5 +0,5 @@

import { Certificate, Options, PrecomposedTransaction, UserOutput, Utxo, Withdrawal } from './types/types';
export declare const coinSelection: (utxos: Utxo[], outputs: UserOutput[], changeAddress: string, certificates: Certificate[], withdrawals: Withdrawal[], accountPubKey: string, options?: Options | undefined) => PrecomposedTransaction;
import { CoinSelectionParams, Options, PrecomposedTransaction } from './types/types';
export declare const coinSelection: (params: CoinSelectionParams, options?: Options | undefined) => PrecomposedTransaction;
export * as trezorUtils from './utils/trezor';
export * as types from './types/types';
export { CoinSelectionError } from './utils/errors';

@@ -28,14 +28,9 @@ "use strict";

const logger_1 = require("./utils/logger");
const coinSelection = (utxos, outputs, changeAddress, certificates, withdrawals, accountPubKey, options) => {
const coinSelection = (params, options) => {
const logger = (0, logger_1.getLogger)(!!(options === null || options === void 0 ? void 0 : options.debug));
logger.debug('Args:', {
utxos,
outputs,
changeAddress,
certificates,
withdrawals,
accountPubKey,
params,
options,
});
if (utxos.length === 0) {
if (params.utxos.length === 0) {
logger.debug('Empty Utxo set');

@@ -46,8 +41,8 @@ throw new errors_1.CoinSelectionError(constants_1.ERROR.UTXO_BALANCE_INSUFFICIENT);

let res;
if (outputs.find(o => o.setMax) ||
certificates.length > 0 ||
withdrawals.length > 0 ||
if (params.outputs.find(o => o.setMax) ||
params.certificates.length > 0 ||
params.withdrawals.length > 0 ||
(options === null || options === void 0 ? void 0 : options.forceLargestFirstSelection)) {
logger.debug('Running largest-first alg');
res = (0, largestFirst_1.largestFirst)(utxos, outputs, changeAddress, certificates, withdrawals, accountPubKey, options);
res = (0, largestFirst_1.largestFirst)(params, options);
}

@@ -57,3 +52,3 @@ else {

try {
res = (0, randomImprove_1.randomImprove)(utxos, outputs, changeAddress, options);
res = (0, randomImprove_1.randomImprove)(params, options);
}

@@ -64,3 +59,3 @@ catch (error) {

logger.debug(`random-improve failed with ${error.code}. Retrying with largest-first alg.`);
res = (0, largestFirst_1.largestFirst)(utxos, outputs, changeAddress, certificates, withdrawals, accountPubKey, options);
res = (0, largestFirst_1.largestFirst)(params, options);
}

@@ -67,0 +62,0 @@ else {

@@ -1,2 +0,2 @@

import { Certificate, CoinSelectionResult, Options, UserOutput, Utxo, Withdrawal } from '../types/types';
export declare const largestFirst: (utxos: Utxo[], outputs: UserOutput[], changeAddress: string, certificates: Certificate[], withdrawals: Withdrawal[], accountPubKey: string, options?: Options | undefined) => CoinSelectionResult;
import { CoinSelectionParams, CoinSelectionResult, Options } from '../types/types';
export declare const largestFirst: (params: CoinSelectionParams, options?: Options | undefined) => CoinSelectionResult;

@@ -27,5 +27,9 @@ "use strict";

const errors_1 = require("../utils/errors");
const largestFirst = (utxos, outputs, changeAddress, certificates, withdrawals, accountPubKey, options) => {
const largestFirst = (params, options) => {
var _a;
const { utxos, outputs, changeAddress, certificates, withdrawals, accountPubKey, ttl, } = params;
const txBuilder = (0, common_1.getTxBuilder)((_a = options === null || options === void 0 ? void 0 : options.feeParams) === null || _a === void 0 ? void 0 : _a.a);
if (ttl) {
txBuilder.set_ttl(ttl);
}
const usedUtxos = [];

@@ -180,2 +184,3 @@ let sortedUtxos = (0, common_1.sortUtxos)(utxos);

return {
tx: { body: txBodyHex, hash: txHash, size: txBuilder.full_size() },
inputs: usedUtxos,

@@ -187,3 +192,3 @@ outputs: finalOutputs,

withdrawal: totalWithdrawal.to_str(),
tx: { body: txBodyHex, hash: txHash, size: txBuilder.full_size() },
ttl,
max,

@@ -190,0 +195,0 @@ };

@@ -1,2 +0,2 @@

import { CoinSelectionResult, Options, UserOutput, Utxo } from '../types/types';
export declare const randomImprove: (utxos: Utxo[], outputs: UserOutput[], changeAddress: string, options?: Options | undefined) => CoinSelectionResult;
import { CoinSelectionParams, CoinSelectionResult, Options } from '../types/types';
export declare const randomImprove: (params: Pick<CoinSelectionParams, 'utxos' | 'outputs' | 'changeAddress' | 'ttl'>, options?: Options | undefined) => CoinSelectionResult;

@@ -135,4 +135,5 @@ "use strict";

};
const randomImprove = (utxos, outputs, changeAddress, options) => {
const randomImprove = (params, options) => {
var _a;
const { utxos, outputs, changeAddress, ttl } = params;
const logger = (0, logger_1.getLogger)(!!(options === null || options === void 0 ? void 0 : options.debug));

@@ -144,2 +145,5 @@ if (outputs.length > utxos.length) {

const txBuilder = (0, common_1.getTxBuilder)((_a = options === null || options === void 0 ? void 0 : options.feeParams) === null || _a === void 0 ? void 0 : _a.a);
if (ttl) {
txBuilder.set_ttl(ttl);
}
const { utxoSelected, utxoRemaining, preparedOutputs } = selection(utxos, outputs, txBuilder, changeAddress);

@@ -169,2 +173,3 @@ // compute change and adjust for fee

return {
tx: { body: txBodyHex, hash: txHash, size: txBuilder.full_size() },
inputs: utxoSelected,

@@ -176,5 +181,5 @@ outputs: finalOutputs,

withdrawal: '0',
tx: { body: txBodyHex, hash: txHash, size: txBuilder.full_size() },
ttl,
};
};
exports.randomImprove = randomImprove;

@@ -72,2 +72,3 @@ import * as CardanoWasm from '@emurgo/cardano-serialization-lib-browser';

withdrawal: string;
ttl?: number;
max?: string;

@@ -108,1 +109,10 @@ }

}
export interface CoinSelectionParams {
utxos: Utxo[];
outputs: UserOutput[];
changeAddress: string;
certificates: Certificate[];
withdrawals: Withdrawal[];
accountPubKey: string;
ttl?: number;
}

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

let newMaxAmount = (0, exports.bigNumFromStr)('0');
let changeOutputAssets = (0, exports.multiAssetToArray)(changeOutput === null || changeOutput === void 0 ? void 0 : changeOutput.output.amount().multiasset());
const changeOutputAssets = (0, exports.multiAssetToArray)(changeOutput === null || changeOutput === void 0 ? void 0 : changeOutput.output.amount().multiasset());
if (maxOutputAsset === 'lovelace') {

@@ -427,0 +427,0 @@ // set maxOutput for ADA

@@ -1,5 +0,5 @@

import { Certificate, Options, PrecomposedTransaction, UserOutput, Utxo, Withdrawal } from './types/types';
export declare const coinSelection: (utxos: Utxo[], outputs: UserOutput[], changeAddress: string, certificates: Certificate[], withdrawals: Withdrawal[], accountPubKey: string, options?: Options | undefined) => PrecomposedTransaction;
import { CoinSelectionParams, Options, PrecomposedTransaction } from './types/types';
export declare const coinSelection: (params: CoinSelectionParams, options?: Options | undefined) => PrecomposedTransaction;
export * as trezorUtils from './utils/trezor';
export * as types from './types/types';
export { CoinSelectionError } from './utils/errors';

@@ -6,14 +6,9 @@ import { ERROR } from './constants';

import { getLogger } from './utils/logger';
export const coinSelection = (utxos, outputs, changeAddress, certificates, withdrawals, accountPubKey, options) => {
export const coinSelection = (params, options) => {
const logger = getLogger(!!(options === null || options === void 0 ? void 0 : options.debug));
logger.debug('Args:', {
utxos,
outputs,
changeAddress,
certificates,
withdrawals,
accountPubKey,
params,
options,
});
if (utxos.length === 0) {
if (params.utxos.length === 0) {
logger.debug('Empty Utxo set');

@@ -24,8 +19,8 @@ throw new CoinSelectionError(ERROR.UTXO_BALANCE_INSUFFICIENT);

let res;
if (outputs.find(o => o.setMax) ||
certificates.length > 0 ||
withdrawals.length > 0 ||
if (params.outputs.find(o => o.setMax) ||
params.certificates.length > 0 ||
params.withdrawals.length > 0 ||
(options === null || options === void 0 ? void 0 : options.forceLargestFirstSelection)) {
logger.debug('Running largest-first alg');
res = largestFirst(utxos, outputs, changeAddress, certificates, withdrawals, accountPubKey, options);
res = largestFirst(params, options);
}

@@ -35,3 +30,3 @@ else {

try {
res = randomImprove(utxos, outputs, changeAddress, options);
res = randomImprove(params, options);
}

@@ -42,3 +37,3 @@ catch (error) {

logger.debug(`random-improve failed with ${error.code}. Retrying with largest-first alg.`);
res = largestFirst(utxos, outputs, changeAddress, certificates, withdrawals, accountPubKey, options);
res = largestFirst(params, options);
}

@@ -45,0 +40,0 @@ else {

@@ -1,2 +0,2 @@

import { Certificate, CoinSelectionResult, Options, UserOutput, Utxo, Withdrawal } from '../types/types';
export declare const largestFirst: (utxos: Utxo[], outputs: UserOutput[], changeAddress: string, certificates: Certificate[], withdrawals: Withdrawal[], accountPubKey: string, options?: Options | undefined) => CoinSelectionResult;
import { CoinSelectionParams, CoinSelectionResult, Options } from '../types/types';
export declare const largestFirst: (params: CoinSelectionParams, options?: Options | undefined) => CoinSelectionResult;

@@ -5,5 +5,9 @@ import { ERROR } from '../constants';

import { CoinSelectionError } from '../utils/errors';
export const largestFirst = (utxos, outputs, changeAddress, certificates, withdrawals, accountPubKey, options) => {
export const largestFirst = (params, options) => {
var _a;
const { utxos, outputs, changeAddress, certificates, withdrawals, accountPubKey, ttl, } = params;
const txBuilder = getTxBuilder((_a = options === null || options === void 0 ? void 0 : options.feeParams) === null || _a === void 0 ? void 0 : _a.a);
if (ttl) {
txBuilder.set_ttl(ttl);
}
const usedUtxos = [];

@@ -158,2 +162,3 @@ let sortedUtxos = sortUtxos(utxos);

return {
tx: { body: txBodyHex, hash: txHash, size: txBuilder.full_size() },
inputs: usedUtxos,

@@ -165,5 +170,5 @@ outputs: finalOutputs,

withdrawal: totalWithdrawal.to_str(),
tx: { body: txBodyHex, hash: txHash, size: txBuilder.full_size() },
ttl,
max,
};
};

@@ -1,2 +0,2 @@

import { CoinSelectionResult, Options, UserOutput, Utxo } from '../types/types';
export declare const randomImprove: (utxos: Utxo[], outputs: UserOutput[], changeAddress: string, options?: Options | undefined) => CoinSelectionResult;
import { CoinSelectionParams, CoinSelectionResult, Options } from '../types/types';
export declare const randomImprove: (params: Pick<CoinSelectionParams, 'utxos' | 'outputs' | 'changeAddress' | 'ttl'>, options?: Options | undefined) => CoinSelectionResult;

@@ -113,4 +113,5 @@ import { ERROR } from '../constants';

};
export const randomImprove = (utxos, outputs, changeAddress, options) => {
export const randomImprove = (params, options) => {
var _a;
const { utxos, outputs, changeAddress, ttl } = params;
const logger = getLogger(!!(options === null || options === void 0 ? void 0 : options.debug));

@@ -122,2 +123,5 @@ if (outputs.length > utxos.length) {

const txBuilder = getTxBuilder((_a = options === null || options === void 0 ? void 0 : options.feeParams) === null || _a === void 0 ? void 0 : _a.a);
if (ttl) {
txBuilder.set_ttl(ttl);
}
const { utxoSelected, utxoRemaining, preparedOutputs } = selection(utxos, outputs, txBuilder, changeAddress);

@@ -147,2 +151,3 @@ // compute change and adjust for fee

return {
tx: { body: txBodyHex, hash: txHash, size: txBuilder.full_size() },
inputs: utxoSelected,

@@ -154,4 +159,4 @@ outputs: finalOutputs,

withdrawal: '0',
tx: { body: txBodyHex, hash: txHash, size: txBuilder.full_size() },
ttl,
};
};

@@ -72,2 +72,3 @@ import * as CardanoWasm from '@emurgo/cardano-serialization-lib-browser';

withdrawal: string;
ttl?: number;
max?: string;

@@ -108,1 +109,10 @@ }

}
export interface CoinSelectionParams {
utxos: Utxo[];
outputs: UserOutput[];
changeAddress: string;
certificates: Certificate[];
withdrawals: Withdrawal[];
accountPubKey: string;
ttl?: number;
}

@@ -379,3 +379,3 @@ import * as CardanoWasm from '@emurgo/cardano-serialization-lib-browser';

let newMaxAmount = bigNumFromStr('0');
let changeOutputAssets = multiAssetToArray(changeOutput === null || changeOutput === void 0 ? void 0 : changeOutput.output.amount().multiasset());
const changeOutputAssets = multiAssetToArray(changeOutput === null || changeOutput === void 0 ? void 0 : changeOutput.output.amount().multiasset());
if (maxOutputAsset === 'lovelace') {

@@ -382,0 +382,0 @@ // set maxOutput for ADA

{
"name": "@fivebinaries/coin-selection",
"version": "2.0.0-beta.7",
"version": "2.0.0-beta.8",
"description": "",

@@ -5,0 +5,0 @@ "keywords": [

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