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

coinselect

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

coinselect - npm Package Compare versions

Comparing version 3.1.11 to 3.1.12

1

break.js
var utils = require('./utils')
// break utxos into the maximum number of 'output' possible
module.exports = function broken (utxos, output, feeRate) {

@@ -4,0 +5,0 @@ if (!isFinite(utils.uintOrNaN(feeRate))) return {}

10

package.json
{
"name": "coinselect",
"version": "3.1.11",
"version": "3.1.12",
"description": "A transaction input selection module for bitcoin.",

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

],
"homepage": "https://github.com/dcousens/coinselect",
"homepage": "https://github.com/bitcoinjs/coinselect",
"bugs": {
"url": "https://github.com/dcousens/coinselect/issues"
"url": "https://github.com/bitcoinjs/coinselect/issues"
},

@@ -37,3 +37,3 @@ "license": "MIT",

"type": "git",
"url": "https://github.com/dcousens/coinselect.git"
"url": "https://github.com/bitcoinjs/coinselect.git"
},

@@ -47,3 +47,3 @@ "scripts": {

"devDependencies": {
"nyc": "^8.3.2",
"nyc": "^15.0.0",
"standard": "*",

@@ -50,0 +50,0 @@ "tape": "^4.5.1"

@@ -10,3 +10,20 @@ # coinselect

**WARNING:** Value units are in `satoshi`s, **not** Bitcoin.
## Algorithms
Module | Algorithm | Re-orders UTXOs?
-|-|-
`require('coinselect')` | Blackjack, with Accumulative fallback | By Descending Value
`require('coinselect/accumulative')` | Accumulative - accumulates inputs until the target value (+fees) is reached, skipping detrimental inputs | -
`require('coinselect/blackjack')` | Blackjack - accumulates inputs until the target value (+fees) is matched, does not accumulate inputs that go over the target value (within a threshold) | -
`require('coinselect/break')` | Break - breaks the input values into equal denominations of `output` (as provided) | -
`require('coinselect/split')` | Split - splits the input values evenly between all `outputs`, any provided `output` with `.value` remains unchanged | -
**Note:** Each algorithm will add a change output if the `input - output - fee` value difference is over a dust threshold.
This is calculated independently by `utils.finalize`, irrespective of the algorithm chosen, for the purposes of safety.
**Pro-tip:** if you want to send-all inputs to an output address, `coinselect/split` with a partial output (`.address` defined, no `.value`) can be used to send-all, while leaving an appropriate amount for the `fee`.
## Example

@@ -23,3 +40,12 @@

...,
value: 10000
value: 10000,
// For use with PSBT:
// not needed for coinSelect, but will be passed on to inputs later
nonWitnessUtxo: Buffer.from('...full raw hex of txId tx...', 'hex'),
// OR
// if your utxo is a segwit output, you can use witnessUtxo instead
witnessUtxo: {
script: Buffer.from('... scriptPubkey hex...', 'hex'),
value: 10000 // 0.0001 BTC and is the exact same as the value above
}
}

@@ -44,5 +70,13 @@ ]

let txb = new bitcoin.TransactionBuilder()
let psbt = new bitcoin.Psbt()
inputs.forEach(input => txb.addInput(input.txId, input.vout))
inputs.forEach(input =>
psbt.addInput({
hash: input.txId,
index: input.vout,
nonWitnessUtxo: input.nonWitnessUtxo,
// OR (not both)
witnessUtxo: input.witnessUtxo,
})
)
outputs.forEach(output => {

@@ -53,5 +87,9 @@ // watch out, outputs may have been added that you need to provide

output.address = wallet.getChangeAddress()
wallet.nextChangeAddress()
}
txb.addOutput(output.address, output.value)
psbt.addOutput({
address: output.address,
value: output.value,
})
})

@@ -58,0 +96,0 @@ ```

var utils = require('./utils')
// split utxos between each output, ignores outputs with .value defined
module.exports = function split (utxos, outputs, feeRate) {

@@ -24,3 +25,3 @@ if (!isFinite(utils.uintOrNaN(feeRate))) return {}

}, 0)
var splitValue = (remaining / splitOutputsCount) >>> 0
var splitValue = Math.floor(remaining / splitOutputsCount)

@@ -27,0 +28,0 @@ // ensure every output is either user defined, or over the threshold

// baseline estimates, used to improve performance
var TX_EMPTY_SIZE = 4 + 1 + 1 + 4
var TX_INPUT_BASE = 32 + 4 + 1 + 4
var TX_INPUT_PUBKEYHASH = 106
var TX_INPUT_PUBKEYHASH = 107
var TX_OUTPUT_BASE = 8 + 1

@@ -6,0 +6,0 @@ var TX_OUTPUT_PUBKEYHASH = 25

Sorry, the diff of this file is not supported yet

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