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

@trezor/utxo-lib

Package Overview
Dependencies
Maintainers
4
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trezor/utxo-lib - npm Package Compare versions

Comparing version 2.0.2 to 2.0.3

5

CHANGELOG.md

@@ -0,1 +1,6 @@

# 2.0.3
- refactor(utxo-lib): use spread instead of Object.assign (55eecd28b)
- refactor(utxo-lib): coinselect VinVout values/amounts as BN (ab1dae3fd)
# 2.0.2

@@ -2,0 +7,0 @@

4

lib/coinselect/coinselectUtils.d.ts

@@ -32,6 +32,6 @@ import BN from 'bn.js';

export declare function sumOrNaN(range: {
value?: string;
value?: BN;
}[]): BN | undefined;
export declare function sumOrNaN<F extends boolean>(range: {
value?: string;
value?: BN;
}[], forgiving: F): F extends true ? BN : BN | undefined;

@@ -38,0 +38,0 @@ export declare function getFeePolicy(network?: Network): "bitcoin" | "doge" | "zcash";

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

const limit = new bn_js_1.default(dustThreshold);
const dustOutputsCount = outputs.filter(({ value }) => value && new bn_js_1.default(value).lt(limit)).length;
const dustOutputsCount = outputs.filter(({ value }) => value && value.lt(limit)).length;
return fee + dustOutputsCount * dustThreshold;

@@ -185,7 +185,5 @@ }

const dustAmount = getDustAmount(feeRate, options);
const finalOutputs = outputs.map(o => Object.assign({}, o, {
value: o.value,
}));
const finalOutputs = [...outputs];
if (remainderAfterExtraOutput.gte(new bn_js_1.default(dustAmount))) {
finalOutputs.push(Object.assign(Object.assign({}, changeOutput), { value: remainderAfterExtraOutput.toString() }));
finalOutputs.push(Object.assign(Object.assign({}, changeOutput), { value: remainderAfterExtraOutput }));
}

@@ -214,3 +212,3 @@ return {

function utxoScore(x, feeRate) {
return new bn_js_1.default(x.value).sub(new bn_js_1.default(getFeeForBytes(feeRate, inputBytes(x))));
return x.value.sub(new bn_js_1.default(getFeeForBytes(feeRate, inputBytes(x))));
}

@@ -217,0 +215,0 @@ exports.utxoScore = utxoScore;

@@ -28,8 +28,6 @@ "use strict";

return { fee };
const outputsSplit = outputs.map(x => {
if (x.value)
return x;
const y = Object.assign({}, x);
y.value = splitValue.toString();
return y;
const outputsSplit = outputs.map(output => {
if (output.value)
return output;
return Object.assign(Object.assign({}, output), { value: splitValue });
});

@@ -36,0 +34,0 @@ return (0, coinselectUtils_1.finalize)(utxos, outputsSplit, feeRate, options);

@@ -28,6 +28,7 @@ "use strict";

}
if (typeof utxo.amount !== 'string') {
throw new Error('Missing amount');
const value = (0, coinselectUtils_1.bignumberOrNaN)(utxo.amount);
if (!value) {
throw new Error('Invalid amount');
}
return Object.assign(Object.assign({}, utxo), { type: txType, i, script: { length: coinselectUtils_1.INPUT_SCRIPT_LENGTH[txType] }, value: utxo.amount });
return Object.assign(Object.assign({}, utxo), { type: txType, i, script: { length: coinselectUtils_1.INPUT_SCRIPT_LENGTH[txType] }, value });
}

@@ -59,4 +60,7 @@ function validateAndParseUtxos(txType, { utxos }) {

if (output.type === 'payment') {
const value = (0, coinselectUtils_1.bignumberOrNaN)(output.amount);
if (!value)
throw new Error('Invalid amount');
return {
value: output.amount,
value,
script: (0, address_1.toOutputScript)(output.address, network),

@@ -66,4 +70,7 @@ };

if (output.type === 'payment-noaddress') {
const value = (0, coinselectUtils_1.bignumberOrNaN)(output.amount);
if (!value)
throw new Error('Invalid amount');
return {
value: output.amount,
value,
script,

@@ -74,3 +81,3 @@ };

return {
value: '0',
value: (0, coinselectUtils_1.bignumberOrNaN)('0', true),
script: (0, embed_1.p2data)({ data: [Buffer.from(output.dataHex, 'hex')] }).output,

@@ -110,6 +117,2 @@ };

}
if ((output.type === 'payment' || output.type === 'payment-noaddress') &&
typeof output.amount !== 'string') {
return incorrectOutputError(i, 'Missing output amount');
}
try {

@@ -116,0 +119,0 @@ const csOutput = transformOutput(output, txType, network);

@@ -40,7 +40,7 @@ "use strict";

if (request.outputs[index]) {
return total.add(new bn_js_1.default(output.value));
return total.add(output.value);
}
return total;
}, new bn_js_1.default(result.fee));
const max = sendMaxOutputIndex >= 0 ? result.outputs[sendMaxOutputIndex].value : undefined;
const max = sendMaxOutputIndex >= 0 ? result.outputs[sendMaxOutputIndex].value.toString() : undefined;
const bytes = (0, coinselectUtils_1.transactionBytes)(result.inputs, result.outputs);

@@ -47,0 +47,0 @@ const feePerByte = result.fee / bytes;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTransaction = void 0;
const tslib_1 = require("tslib");
const bn_js_1 = tslib_1.__importDefault(require("bn.js"));
function convertOutput(selectedOutput, composeOutput) {
if (composeOutput.type === 'change') {
return Object.assign(Object.assign({}, composeOutput), { amount: selectedOutput.value });
return Object.assign(Object.assign({}, composeOutput), { amount: selectedOutput.value.toString() });
}

@@ -13,3 +11,3 @@ if (composeOutput.type === 'opreturn') {

}
return Object.assign(Object.assign({}, composeOutput), { type: 'payment', amount: selectedOutput.value });
return Object.assign(Object.assign({}, composeOutput), { type: 'payment', amount: selectedOutput.value.toString() });
}

@@ -20,3 +18,3 @@ function inputComparator(a, b) {

function outputComparator(a, b) {
return (new bn_js_1.default(a.value).cmp(new bn_js_1.default(b.value)) ||
return (a.value.cmp(b.value) ||
(Buffer.isBuffer(a.script) && Buffer.isBuffer(b.script)

@@ -23,0 +21,0 @@ ? a.script.compare(b.script)

@@ -1,6 +0,4 @@

declare const OPS: {
[key: string]: number;
};
declare const OPS: Record<string, number>;
declare const REVERSE_OPS: string[];
export { OPS, REVERSE_OPS };
//# sourceMappingURL=ops.d.ts.map

@@ -6,8 +6,3 @@ "use strict";

const ops = tslib_1.__importStar(require("bitcoin-ops"));
const OPS = Object.assign({
OP_SSTX: 0xba,
OP_SSTXCHANGE: 0xbd,
OP_SSGEN: 0xbb,
OP_SSRTX: 0xbc,
}, ops || {});
const OPS = Object.assign(Object.assign({}, ops), { OP_SSTX: 0xba, OP_SSTXCHANGE: 0xbd, OP_SSGEN: 0xbb, OP_SSRTX: 0xbc });
exports.OPS = OPS;

@@ -14,0 +9,0 @@ const REVERSE_OPS = [];

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

static fromHex(hex, options = {}) {
return this.fromBuffer(Buffer.from(hex, 'hex'), Object.assign(options, { nostrict: false }));
return this.fromBuffer(Buffer.from(hex, 'hex'), Object.assign(Object.assign({}, options), { nostrict: false }));
}

@@ -43,0 +43,0 @@ }

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

import BN from 'bn.js';
export type CoinSelectPaymentType = 'p2pkh' | 'p2sh' | 'p2tr' | 'p2wpkh' | 'p2wsh';

@@ -21,3 +22,3 @@ export interface CoinSelectOptions {

};
value: string;
value: BN;
confirmations: number;

@@ -33,3 +34,3 @@ coinbase?: boolean;

};
value?: string;
value?: BN;
weight?: number;

@@ -41,3 +42,3 @@ }

};
value: string;
value: BN;
}

@@ -44,0 +45,0 @@ export interface CoinSelectRequest extends CoinSelectOptions {

{
"name": "@trezor/utxo-lib",
"version": "2.0.2",
"version": "2.0.3",
"author": "Trezor <info@trezor.io>",

@@ -39,3 +39,3 @@ "homepage": "https://github.com/trezor/trezor-suite/tree/develop/packages/utxo-lib",

"dependencies": {
"@trezor/utils": "9.0.16",
"@trezor/utils": "9.0.17",
"bchaddrjs": "^0.5.2",

@@ -42,0 +42,0 @@ "bech32": "^2.0.0",

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