Socket
Book a DemoInstallSign in
Socket

@trezor/utxo-lib

Package Overview
Dependencies
Maintainers
5
Versions
70
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

to
1.0.0-beta.2

19

lib/bs58check.js

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

const payload = buffer.slice(0, -4);
const got = crypto_1.blake256(crypto_1.blake256(payload)).slice(0, 4);
const got = (0, crypto_1.blake256)((0, crypto_1.blake256)(payload)).slice(0, 4);
if ((want[0] ^ got[0]) | (want[1] ^ got[1]) | (want[2] ^ got[2]) | (want[3] ^ got[3]))

@@ -33,3 +33,6 @@ throw new Error('invalid checksum');

catch (e) {
throw new Error(`${address} ${e.message}`);
if (e instanceof Error) {
throw new Error(`${address} ${e.message}`);
}
throw new Error(`${address} ${e}`);
}

@@ -40,3 +43,3 @@ return payload;

function encodeBlake256(payload) {
const checksum = crypto_1.blake256(crypto_1.blake256(payload)).slice(0, 4);
const checksum = (0, crypto_1.blake256)((0, crypto_1.blake256)(payload)).slice(0, 4);
return bs58.encode(Buffer.concat([payload, checksum]));

@@ -46,15 +49,15 @@ }

function encode(payload, network = networks_1.bitcoin) {
if (networks_1.isNetworkType('decred', network))
if ((0, networks_1.isNetworkType)('decred', network))
return encodeBlake256(payload);
const encoded = bs58check.encode(payload);
return networks_1.isNetworkType('bitcoinCash', network) ? bchaddrjs.toCashAddress(encoded) : encoded;
return (0, networks_1.isNetworkType)('bitcoinCash', network) ? bchaddrjs.toCashAddress(encoded) : encoded;
}
exports.encode = encode;
function decode(payload, network = networks_1.bitcoin) {
if (networks_1.isNetworkType('decred', network))
if ((0, networks_1.isNetworkType)('decred', network))
return decodeBlake256(payload);
if (networks_1.isNetworkType('bitcoinCash', network) && !bchaddrjs.isCashAddress(payload)) {
if ((0, networks_1.isNetworkType)('bitcoinCash', network) && !bchaddrjs.isCashAddress(payload)) {
throw Error(`${payload} is not a cash address`);
}
const address = networks_1.isNetworkType('bitcoinCash', network)
const address = (0, networks_1.isNetworkType)('bitcoinCash', network)
? bchaddrjs.toLegacyAddress(payload)

@@ -61,0 +64,0 @@ : payload;

@@ -9,6 +9,6 @@ "use strict";

function coinselect(inputs, outputs, feeRate, options) {
const sortedInputs = options.skipPermutation ? inputs : inputs.sort(utils_1.sortByScore(feeRate));
const algorithm = tryconfirmed_1.tryConfirmed(utils_1.anyOf([bnb_1.bnb(0.5), accumulative_1.accumulative]), options);
const sortedInputs = options.skipPermutation ? inputs : inputs.sort((0, utils_1.sortByScore)(feeRate));
const algorithm = (0, tryconfirmed_1.tryConfirmed)((0, utils_1.anyOf)([(0, bnb_1.bnb)(0.5), accumulative_1.accumulative]), options);
return algorithm(sortedInputs, outputs, feeRate, options);
}
exports.coinselect = coinselect;

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

});
const utxos = utils_1.filterCoinbase(utxosO, coinbase);
const utxos = (0, utils_1.filterCoinbase)(utxosO, coinbase);
if (utxos.length === 0) {

@@ -38,0 +38,0 @@ return { fee: 0 };

@@ -14,4 +14,4 @@ "use strict";

function coinselect(utxos, rOutputs, height, feeRate, segwit, countMax, countMaxId, dustThreshold, network, baseFee, floorBaseFee, dustOutputFee, skipUtxoSelection, skipPermutation) {
const inputs0 = utils_2.convertInputs(utxos, height, segwit);
const outputs0 = utils_2.convertOutputs(rOutputs, network);
const inputs0 = (0, utils_2.convertInputs)(utxos, height, segwit);
const outputs0 = (0, utils_2.convertOutputs)(rOutputs, network);
const options = {

@@ -28,3 +28,3 @@ inputLength: segwit ? SEGWIT_INPUT_SCRIPT_LENGTH : INPUT_SCRIPT_LENGTH,

const result = skipUtxoSelection != null && !countMax
? utils_1.finalize(inputs0, outputs0, feeRate, options)
? (0, utils_1.finalize)(inputs0, outputs0, feeRate, options)
: algorithm(inputs0, outputs0, feeRate, options);

@@ -44,3 +44,3 @@ if (!result.inputs || !result.outputs) {

.toString();
const bytes = utils_1.transactionBytes(inputs, outputs);
const bytes = (0, utils_1.transactionBytes)(inputs, outputs);
const feePerByte = fee / bytes;

@@ -47,0 +47,0 @@ return {

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

catch (e) {
return { type: 'error', error: e.message };
if (e instanceof Error) {
return { type: 'error', error: e.message };
}
return { type: 'error', error: `${e}` };
}

@@ -26,6 +29,9 @@ const splitOutputs = request.splitByCompleteness(outputs);

try {
csResult = coinselect_1.coinselect(utxos, outputs, height, parseInt(feeRate, 10), segwit, countMax.exists, countMax.id, dustThreshold, network, baseFee, floorBaseFee, dustOutputFee, skipUtxoSelection, skipPermutation);
csResult = (0, coinselect_1.coinselect)(utxos, outputs, height, parseInt(feeRate, 10), segwit, countMax.exists, countMax.id, dustThreshold, network, baseFee, floorBaseFee, dustOutputFee, skipUtxoSelection, skipPermutation);
}
catch (e) {
return { type: 'error', error: e.message };
if (e instanceof Error) {
return { type: 'error', error: e.message };
}
return { type: 'error', error: `${e}` };
}

@@ -32,0 +38,0 @@ if (csResult.type === 'false') {

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

const res = {
hash: bufferutils_1.reverseBuffer(Buffer.from(utxo.transactionHash, 'hex')),
hash: (0, bufferutils_1.reverseBuffer)(Buffer.from(utxo.transactionHash, 'hex')),
index: utxo.index,

@@ -28,3 +28,3 @@ path: basePath.concat([...utxo.addressPath]),

};
const script = embed_1.p2data({ data: [opReturnDataBuffer] }).output;
const script = (0, embed_1.p2data)({ data: [opReturnDataBuffer] }).output;
return {

@@ -52,3 +52,3 @@ output,

function inputComparator(aHash, aVout, bHash, bVout) {
return bufferutils_1.reverseBuffer(aHash).compare(bufferutils_1.reverseBuffer(bHash)) || aVout - bVout;
return (0, bufferutils_1.reverseBuffer)(aHash).compare((0, bufferutils_1.reverseBuffer)(bHash)) || aVout - bVout;
}

@@ -55,0 +55,0 @@ function outputComparator(aScript, aValue, bScript, bValue) {

@@ -89,4 +89,4 @@ "use strict";

bip32: {
public: 0x0488b21e,
private: 0x0488ade4,
public: 0x043587cf,
private: 0x04358394,
},

@@ -101,4 +101,4 @@ pubKeyHash: 0x6f,

bip32: {
public: 0x0488b21e,
private: 0x0488ade4,
public: 0x02fe52cc,
private: 0x2fe52f8,
},

@@ -134,3 +134,3 @@ pubKeyHash: 0x4c,

3: 0x5ba81b19,
4: 0x2bb40e60,
4: 0xf5b9230b,
},

@@ -152,3 +152,3 @@ };

3: 0x5ba81b19,
4: 0x2bb40e60,
4: 0xf5b9230b,
},

@@ -155,0 +155,0 @@ };

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

getId() {
return bufferutils_1.reverseBuffer(this.getHash(false)).toString('hex');
return (0, bufferutils_1.reverseBuffer)(this.getHash(false)).toString('hex');
}

@@ -72,0 +72,0 @@ getExtraData() {

@@ -16,6 +16,6 @@ "use strict";

varuint.encodingLength(tx.outs.length) +
tx.ins.reduce((sum, input) => sum + 40 + base_1.varSliceSize(input.script), 0) +
tx.outs.reduce((sum, output) => sum + 8 + base_1.varSliceSize(output.script), 0) +
(((_a = tx.specific) === null || _a === void 0 ? void 0 : _a.extraPayload) ? base_1.varSliceSize(tx.specific.extraPayload) : 0) +
(hasWitnesses ? tx.ins.reduce((sum, input) => sum + base_1.vectorSize(input.witness), 0) : 0));
tx.ins.reduce((sum, input) => sum + 40 + (0, base_1.varSliceSize)(input.script), 0) +
tx.outs.reduce((sum, output) => sum + 8 + (0, base_1.varSliceSize)(output.script), 0) +
(((_a = tx.specific) === null || _a === void 0 ? void 0 : _a.extraPayload) ? (0, base_1.varSliceSize)(tx.specific.extraPayload) : 0) +
(hasWitnesses ? tx.ins.reduce((sum, input) => sum + (0, base_1.vectorSize)(input.witness), 0) : 0));
}

@@ -22,0 +22,0 @@ function toBuffer(tx, buffer, initialOffset, _ALLOW_WITNESS = true) {

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

const bufferutils_1 = require("../bufferutils");
const bcrypto = require("../crypto");
const base_1 = require("./base");

@@ -15,6 +16,6 @@ const DECRED_TX_VERSION = 1;

}
function byteLength(tx) {
function byteLength(tx, _ALLOW_WITNESS = true) {
let byteLength = 4 + varuint.encodingLength(tx.ins.length);
let nWitness = 0;
const hasWitnesses = tx.hasWitnesses();
const hasWitnesses = _ALLOW_WITNESS && tx.hasWitnesses();
byteLength += tx.ins.reduce((sum, input) => {

@@ -25,3 +26,3 @@ sum += 32 + 4 + 1 + 4;

sum += 8 + 4 + 4;
sum += base_1.varSliceSize(input.decredWitness.script);
sum += (0, base_1.varSliceSize)(input.decredWitness.script);
}

@@ -36,3 +37,3 @@ return sum;

sum += 8 + 2;
sum += base_1.varSliceSize(output.script);
sum += (0, base_1.varSliceSize)(output.script);
return sum;

@@ -45,6 +46,6 @@ }, 0);

if (!buffer)
buffer = Buffer.allocUnsafe(byteLength(tx));
buffer = Buffer.allocUnsafe(byteLength(tx, _ALLOW_WITNESS));
const bufferWriter = new bufferutils_1.BufferWriter(buffer, initialOffset || 0);
bufferWriter.writeUInt16(tx.version);
bufferWriter.writeUInt16(tx.type);
bufferWriter.writeUInt16(_ALLOW_WITNESS ? tx.type : DECRED_TX_SERIALIZE_NO_WITNESS);
bufferWriter.writeVarInt(tx.ins.length);

@@ -78,2 +79,10 @@ tx.ins.forEach(txIn => {

}
function getHash(tx, forWitness = false) {
if (forWitness && tx.isCoinbase())
return Buffer.alloc(32, 0);
return bcrypto.blake256(toBuffer(tx, undefined, undefined, forWitness));
}
function weight(tx) {
return tx.byteLength(true);
}
function fromConstructor(options) {

@@ -84,2 +93,4 @@ const tx = new base_1.TransactionBase(options);

tx.hasWitnesses = hasWitnesses.bind(null, tx);
tx.getHash = getHash.bind(null, tx);
tx.weight = weight.bind(null, tx);
return tx;

@@ -86,0 +97,0 @@ }

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

super(options);
if (networks_1.isNetworkType('dash', this.network))
if ((0, networks_1.isNetworkType)('dash', this.network))
return dash.fromConstructor(options);
if (networks_1.isNetworkType('decred', this.network))
if ((0, networks_1.isNetworkType)('decred', this.network))
return decred.fromConstructor(options);
if (networks_1.isNetworkType('peercoin', this.network))
if ((0, networks_1.isNetworkType)('peercoin', this.network))
return peercoin.fromConstructor(options);
if (networks_1.isNetworkType('zcash', this.network))
if ((0, networks_1.isNetworkType)('zcash', this.network))
return zcash.fromConstructor(options);

@@ -26,12 +26,12 @@ return bitcoin.fromConstructor(options);

static isCoinbaseHash(buffer) {
return base_1.isCoinbaseHash(buffer);
return (0, base_1.isCoinbaseHash)(buffer);
}
static fromBuffer(buffer, options = {}) {
if (networks_1.isNetworkType('dash', options.network))
if ((0, networks_1.isNetworkType)('dash', options.network))
return dash.fromBuffer(buffer, options);
if (networks_1.isNetworkType('decred', options.network))
if ((0, networks_1.isNetworkType)('decred', options.network))
return decred.fromBuffer(buffer, options);
if (networks_1.isNetworkType('peercoin', options.network))
if ((0, networks_1.isNetworkType)('peercoin', options.network))
return peercoin.fromBuffer(buffer, options);
if (networks_1.isNetworkType('zcash', options.network))
if ((0, networks_1.isNetworkType)('zcash', options.network))
return zcash.fromBuffer(buffer, options);

@@ -38,0 +38,0 @@ return bitcoin.fromBuffer(buffer, options);

@@ -26,4 +26,4 @@ "use strict";

if (joinSplitsLen < 1)
return bufferutils_1.varIntSize(joinSplitsLen);
return (bufferutils_1.varIntSize(joinSplitsLen) +
return (0, bufferutils_1.varIntSize)(joinSplitsLen);
return ((0, bufferutils_1.varIntSize)(joinSplitsLen) +
(tx.version >= ZCASH_SAPLING_VERSION ? 1698 * joinSplitsLen : 1802 * joinSplitsLen) +

@@ -44,4 +44,4 @@ 32 +

varuint.encodingLength(tx.outs.length) +
tx.ins.reduce((sum, input) => sum + 40 + base_1.varSliceSize(input.script), 0) +
tx.outs.reduce((sum, output) => sum + 8 + base_1.varSliceSize(output.script), 0) +
tx.ins.reduce((sum, input) => sum + 40 + (0, base_1.varSliceSize)(input.script), 0) +
tx.outs.reduce((sum, output) => sum + 8 + (0, base_1.varSliceSize)(output.script), 0) +
4 +

@@ -170,4 +170,4 @@ overwinterSize +

varuint.encodingLength(tx.outs.length) +
tx.ins.reduce((sum, input) => sum + 40 + base_1.varSliceSize(input.script), 0) +
tx.outs.reduce((sum, output) => sum + 8 + base_1.varSliceSize(output.script), 0) +
tx.ins.reduce((sum, input) => sum + 40 + (0, base_1.varSliceSize)(input.script), 0) +
tx.outs.reduce((sum, output) => sum + 8 + (0, base_1.varSliceSize)(output.script), 0) +
4;

@@ -174,0 +174,0 @@ return tx.toBuffer().slice(offset);

{
"name": "@trezor/utxo-lib",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"author": "Trezor <info@trezor.io>",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/trezor/trezor-suite/packages/utxo-lib",

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.