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

rn-bitcoinjs-lib

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

rn-bitcoinjs-lib - npm Package Compare versions

Comparing version 4.0.2-3 to 4.0.3-1

12

CHANGELOG.md

@@ -0,1 +1,11 @@

# 4.0.3
__fixed__
- Fixed `TransactionBuilder` to require that the Transaction has outputs before signing (#1151)
- Fixed `payments.p2sh`, which now takes the network from the redeem attribute if one is not given in the object argument (#1232)
- Fixed `Block.calculateTarget` to allow for exponents up to 29 (#1285)
- Fixed some low priority rarely occurring bugs with multisig payments and `TransactionBuilder` multisig processing (#1307)
__added__
- Regtest network object to `networks` (#1261)
# 4.0.2

@@ -22,3 +32,3 @@ __fixed__

- `ECPair.prototype.sign` now returns a 64-byte signature `Buffer`, not an `ECSignature` object (#1084)
- `ECPair` (and all ECDSA code) now uses [`tiny-secp256k1`](http://github.com/bitcoinjs/tiny-secp256k1), which uses the [`libsecp256k1` library](https://github.com/bitcoin-core/secp256k1) (#1070)
- `ECPair` (and all ECDSA code) now uses [`tiny-secp256k1`](https://github.com/bitcoinjs/tiny-secp256k1), which uses the [`libsecp256k1` library](https://github.com/bitcoin-core/secp256k1) (#1070)
- `TransactionBuilder` internal variables are now `__` prefixed to discourage public usage (#1038)

@@ -25,0 +35,0 @@ - `TransactionBuilder` now defaults to version 2 transaction versions (#1036)

12

package.json
{
"name": "rn-bitcoinjs-lib",
"version": "4.0.2-3",
"version": "4.0.3-1",
"description": "Client-side Bitcoin JavaScript library",

@@ -55,3 +55,3 @@ "main": "./src/index.js",

"bs58": "^4.0.0",
"dhttp": "^2.5.0",
"dhttp": "^3.0.0",
"hoodwink": "^2.0.0",

@@ -66,2 +66,3 @@ "minimaldata": "^1.0.2",

"react-native": {
"crypto": "react-native-crypto",
"_stream_transform": "readable-stream/transform",

@@ -72,5 +73,7 @@ "_stream_readable": "readable-stream/readable",

"_stream_passthrough": "readable-stream/passthrough",
"stream": "stream-browserify"
"stream": "stream-browserify",
"vm": "vm-browserify"
},
"browser": {
"crypto": "react-native-crypto",
"_stream_transform": "readable-stream/transform",

@@ -81,4 +84,5 @@ "_stream_readable": "readable-stream/readable",

"_stream_passthrough": "readable-stream/passthrough",
"stream": "stream-browserify"
"stream": "stream-browserify",
"vm": "vm-browserify"
}
}

@@ -14,5 +14,6 @@ # BitcoinJS (bitcoinjs-lib)

You shouldn't trust or rely on this repo for anything other than testing. To setup bitcoinjs-lib (4.0.2) in your RN project, please follow the how-to below:
[RN BitcoinJS-Lib (4.0.2) Setup](https://gist.github.com/coreyphillips/928ae27ccea69cd0b494d13ad2b3f27d)
You shouldn't trust or rely on this repo for anything other than testing. To setup bitcoinjs-lib (4.0.3) in your RN project, please follow the how-to below:
[RN BitcoinJS-Lib (4.0.3) Setup](https://gist.github.com/coreyphillips/723a718f3630f965a83007a81afe5926)
If you have any difficulty with the setup instructions below and need a repo for reference, feel free to clone, review and experiment with the pre-built RN repo here: [RNBitcoinJS](https://github.com/coreyphillips/RNBitcoinJS)

@@ -26,7 +27,7 @@ We recommend every user of this library and the [bitcoinjs](https://github.com/bitcoinjs) ecosystem audit and verify any underlying code for its validity and suitability.

- Advanced and feature rich,
- Standardized, using [standard](http://github.com/standard/standard) and Node `Buffer`'s throughout, and
- Standardized, using [standard](https://github.com/standard/standard) and Node `Buffer`'s throughout, and
- Friendly, with a strong and helpful community, ready to answer questions.
## Documentation
Presently, we do not have any formal documentation other than our [examples](#examples), please [ask for help](https://github.com/bitcoinjs/bitcoinjs-lib/issues/new) if our examples aren't enough to guide you.
Presently, we do not have any formal documentation other than our [examples](https://github.com/bitcoinjs/bitcoinjs-lib#examples), please [ask for help](https://github.com/bitcoinjs/bitcoinjs-lib/issues/new) if our examples aren't enough to guide you.

@@ -93,2 +94,29 @@

Crypto is hard.
When working with private keys, the random number generator is fundamentally one of the most important parts of any software you write.
For random number generation, we *default* to the [`randombytes`](https://github.com/crypto-browserify/randombytes) module, which uses [`window.crypto.getRandomValues`](https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues) in the browser, or Node js' [`crypto.randomBytes`](https://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback), depending on your build system.
Although this default is ~OK, there is no simple way to detect if the underlying RNG provided is good enough, or if it is **catastrophically bad**.
You should always verify this yourself to your own standards.
This library uses [tiny-secp256k1](https://github.com/bitcoinjs/tiny-secp256k1), which uses [RFC6979](https://tools.ietf.org/html/rfc6979) to help prevent `k` re-use and exploitation.
Unfortunately, this isn't a silver bullet.
Often, Javascript itself is working against us by bypassing these counter-measures.
Problems in [`Buffer (UInt8Array)`](https://github.com/feross/buffer), for example, can trivially result in **catastrophic fund loss** without any warning.
It can do this through undermining your random number generation, accidentally producing a [duplicate `k` value](https://www.nilsschneider.net/2013/01/28/recovering-bitcoin-private-keys.html), sending Bitcoin to a malformed output script, or any of a million different ways.
Running tests in your target environment is important and a recommended step to verify continuously.
Finally, **adhere to best practice**.
We are not an authorative source of best practice, but, at the very least:
* [Don't re-use addresses](https://en.bitcoin.it/wiki/Address_reuse).
* Don't share BIP32 extended public keys ('xpubs'). [They are a liability](https://bitcoin.stackexchange.com/questions/56916/derivation-of-parent-private-key-from-non-hardened-child), and it only takes 1 misplaced private key (or a buggy implementation!) and you are vulnerable to **catastrophic fund loss**.
* [Don't use `Math.random`](https://security.stackexchange.com/questions/181580/why-is-math-random-not-designed-to-be-cryptographically-secure) - in any way - don't.
* Enforce that users always verify (manually) a freshly-decoded human-readable version of their intended transaction before broadcast.
* Don't *ask* users to generate mnemonics, or 'brain wallets', humans are terrible random number generators.
* Lastly, if you can, use [Typescript](https://www.typescriptlang.org/) or similar.
### Node.js

@@ -100,2 +128,28 @@ Use [bitcoinjs-lib](https://github.com/bitcoinjs/bitcoinjs-lib)

### Typescript or VSCode users
Type declarations for Typescript [are available](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/0897921174860ec3d5318992d2323b3ae8100a68/types/bitcoinjs-lib) for version `^3.0.0` of the library.
``` bash
npm install @types/bitcoinjs-lib
```
For VSCode (and other editors), it is advised to install the type declarations, as Intellisense uses that information to help you code (autocompletion, static analysis).
**WARNING**: These Typescript definitions are not maintained by the maintainers of this repository, and are instead maintained at [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped).
Please report any issues or problems there.
### Flow
[Flow-type](https://flowtype.org/) definitions for are available in the [flow-*typed* repository](https://github.com/flowtype/flow-typed/tree/master/definitions/npm/bitcoinjs-lib_v2.x.x) for version `^2.0.0` of the library.
You can [download them directly](https://github.com/flowtype/flow-typed/blob/master/definitions/npm/bitcoinjs-lib_v2.x.x/flow_v0.17.x-/bitcoinjs-lib_v2.x.x.js), or using the flow-typed CLI:
``` bash
npm install -g flow-typed
flow-typed install -f 0.27 bitcoinjs-lib@2.2.0
```
**WARNING**: These flow-typed definitions are not maintained by the maintainers of this repository.
## Examples

@@ -106,41 +160,33 @@ The below examples are implemented as integration tests, they should be very easy to understand.

- [Generate a random address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js#L22)
- [Generate an address from a SHA256 hash](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js#L29)
- [Import an address via WIF](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js#L40)
- [Generate a 2-of-3 P2SH multisig address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js#L47)
- [Generate a SegWit address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js#L60)
- [Generate a SegWit P2SH address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js#L67)
- [Generate a SegWit 3-of-4 multisig address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js#L76)
- [Generate a SegWit 2-of-2 P2SH multisig address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js#L90)
- [Support the retrieval of transactions for an address (3rd party blockchain)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js#L104)
- [Generate a Testnet address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js#L123)
- [Generate a Litecoin address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js#L133)
- [Create a 1-to-1 Transaction](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.js#L13)
- [Create a 2-to-2 Transaction](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.js#L28)
- [Create (and broadcast via 3PBP) a typical Transaction](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.js#L47)
- [Create (and broadcast via 3PBP) a Transaction with an OP\_RETURN output](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.js#L83)
- [Create (and broadcast via 3PBP) a Transaction with a 2-of-4 P2SH(multisig) input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.js#L105)
- [Create (and broadcast via 3PBP) a Transaction with a SegWit P2SH(P2WPKH) input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.js#L143)
- [Create (and broadcast via 3PBP) a Transaction with a SegWit P2WPKH input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.js#L174)
- [Create (and broadcast via 3PBP) a Transaction with a SegWit P2PK input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.js#L218)
- [Create (and broadcast via 3PBP) a Transaction with a SegWit 3-of-4 P2SH(P2WSH(multisig)) input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.js#L263)
- [Verify a Transaction signature](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.js#L304)
- [Import a BIP32 testnet xpriv and export to WIF](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.js#L12)
- [Export a BIP32 xpriv, then import it](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.js#L20)
- [Export a BIP32 xpub](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.js#L31)
- [Create a BIP32, bitcoin, account 0, external address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.js#L40)
- [Create a BIP44, bitcoin, account 0, external address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.js#L55)
- [Create a BIP49, bitcoin testnet, account 0, external address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.js#L71)
- [Use BIP39 to generate BIP32 addresses](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.js#L86)
- [Create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the past)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/cltv.js#L43)
- [Create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the future)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/cltv.js#L88)
- [Create (and broadcast via 3PBP) a Transaction where Alice and Bob can redeem the output at any time](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/cltv.js#L144)
- [Create (but fail to broadcast via 3PBP) a Transaction where Alice attempts to redeem before the expiry](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/cltv.js#L190)
- [Recover a private key from duplicate R values](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/crypto.js#L14)
- [Recover a BIP32 parent private key from the parent public key, and a derived, non-hardened child private key](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/crypto.js#L68)
- [Generate a single-key stealth address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/stealth.js#L72)
- [Generate a single-key stealth address (randomly)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/stealth.js#L91)
- [Recover parent recipient.d, if a derived private key is leaked (and nonce was revealed)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/stealth.js#L107)
- [Generate a dual-key stealth address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/stealth.js#L124)
- [Generate a dual-key stealth address (randomly)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/stealth.js#L147)
- [Generate a random address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js)
- [Import an address via WIF](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js)
- [Generate a 2-of-3 P2SH multisig address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js)
- [Generate a SegWit address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js)
- [Generate a SegWit P2SH address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js)
- [Generate a SegWit 3-of-4 multisig address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js)
- [Generate a SegWit 2-of-2 P2SH multisig address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js)
- [Support the retrieval of transactions for an address (3rd party blockchain)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js)
- [Generate a Testnet address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js)
- [Generate a Litecoin address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js)
- [Create a 1-to-1 Transaction](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.js)
- [Create a 2-to-2 Transaction](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.js)
- [Create (and broadcast via 3PBP) a typical Transaction](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.js)
- [Create (and broadcast via 3PBP) a Transaction with an OP\_RETURN output](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.js)
- [Create (and broadcast via 3PBP) a Transaction with a 2-of-4 P2SH(multisig) input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.js)
- [Create (and broadcast via 3PBP) a Transaction with a SegWit P2SH(P2WPKH) input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.js)
- [Create (and broadcast via 3PBP) a Transaction with a SegWit P2WPKH input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.js)
- [Create (and broadcast via 3PBP) a Transaction with a SegWit P2PK input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.js)
- [Create (and broadcast via 3PBP) a Transaction with a SegWit 3-of-4 P2SH(P2WSH(multisig)) input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.js)
- [Verify a Transaction signature](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.js)
- [Import a BIP32 testnet xpriv and export to WIF](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.js)
- [Export a BIP32 xpriv, then import it](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.js)
- [Export a BIP32 xpub](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.js)
- [Create a BIP32, bitcoin, account 0, external address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.js)
- [Create a BIP44, bitcoin, account 0, external address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.js)
- [Create a BIP49, bitcoin testnet, account 0, external address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.js)
- [Use BIP39 to generate BIP32 addresses](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.js)
- [Create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the past)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/cltv.js)
- [Create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the future)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/cltv.js)
- [Create (and broadcast via 3PBP) a Transaction where Alice and Bob can redeem the output at any time](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/cltv.js)
- [Create (but fail to broadcast via 3PBP) a Transaction where Alice attempts to redeem before the expiry](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/cltv.js)

@@ -147,0 +193,0 @@ If you have a use case that you feel could be listed here, please [ask for it](https://github.com/bitcoinjs/bitcoinjs-lib/issues/new)!

@@ -148,3 +148,3 @@ const Buffer = require('safe-buffer').Buffer

const target = Buffer.alloc(32, 0)
target.writeUInt32BE(mantissa, 28 - exponent)
target.writeUIntBE(mantissa, 29 - exponent, 3)
return target

@@ -151,0 +151,0 @@ }

@@ -12,3 +12,3 @@ const decompile = require('./script').decompile

const types = {
MULTISIG: 'multisig',
P2MS: 'multisig',
NONSTANDARD: 'nonstandard',

@@ -34,3 +34,3 @@ NULLDATA: 'nulldata',

if (multisig.output.check(chunks)) return types.MULTISIG
if (multisig.output.check(chunks)) return types.P2MS
if (pubKey.output.check(chunks)) return types.P2PK

@@ -50,3 +50,3 @@ if (witnessCommitment.output.check(chunks)) return types.WITNESS_COMMITMENT

if (scriptHash.input.check(chunks, allowIncomplete)) return types.P2SH
if (multisig.input.check(chunks, allowIncomplete)) return types.MULTISIG
if (multisig.input.check(chunks, allowIncomplete)) return types.P2MS
if (pubKey.input.check(chunks)) return types.P2PK

@@ -53,0 +53,0 @@

@@ -0,4 +1,3 @@

const ecc = require('tiny-secp256k1')
import { randomBytes } from 'react-native-randombytes'
const ecc = require('tiny-secp256k1')
const typeforce = require('typeforce')

@@ -5,0 +4,0 @@ const types = require('./types')

@@ -16,2 +16,13 @@ // https://en.bitcoin.it/wiki/List_of_address_prefixes

},
regtest: {
messagePrefix: '\x18Bitcoin Signed Message:\n',
bech32: 'bcrt',
bip32: {
public: 0x043587cf,
private: 0x04358394
},
pubKeyHash: 0x6f,
scriptHash: 0xc4,
wif: 0xef
},
testnet: {

@@ -18,0 +29,0 @@ messagePrefix: '\x18Bitcoin Signed Message:\n',

@@ -132,3 +132,3 @@ const lazy = require('./lazy')

if (a.signatures && !stacksEqual(a.signatures.equals(o.signatures))) throw new TypeError('Signature mismatch')
if (a.signatures && !stacksEqual(a.signatures, o.signatures)) throw new TypeError('Signature mismatch')
if (a.m !== undefined && a.m !== a.signatures.length) throw new TypeError('Signature count mismatch')

@@ -135,0 +135,0 @@ }

@@ -48,3 +48,7 @@ const lazy = require('./lazy')

const network = a.network || BITCOIN_NETWORK
let network = a.network
if (!network) {
network = (a.redeem && a.redeem.network) || BITCOIN_NETWORK
}
const o = { network }

@@ -51,0 +55,0 @@

@@ -62,3 +62,7 @@ const lazy = require('./lazy')

const network = a.network || BITCOIN_NETWORK
let network = a.network
if (!network) {
network = (a.redeem && a.redeem.network) || BITCOIN_NETWORK
}
const o = { network }

@@ -65,0 +69,0 @@

@@ -59,4 +59,4 @@ const Buffer = require('safe-buffer').Buffer

case SCRIPT_TYPES.MULTISIG: {
const { pubkeys, signatures } = payments.p2ms({
case SCRIPT_TYPES.P2MS: {
const { m, pubkeys, signatures } = payments.p2ms({
input: scriptSig,

@@ -67,5 +67,6 @@ output: scriptPubKey

return {
prevOutType: SCRIPT_TYPES.MULTISIG,
prevOutType: SCRIPT_TYPES.P2MS,
pubkeys: pubkeys,
signatures: signatures
signatures: signatures,
maxSignatures: m
}

@@ -131,3 +132,3 @@ }

function fixMultisigOrder (input, transaction, vin) {
if (input.redeemScriptType !== SCRIPT_TYPES.MULTISIG || !input.redeemScript) return
if (input.redeemScriptType !== SCRIPT_TYPES.P2MS || !input.redeemScript) return
if (input.pubkeys.length === input.signatures.length) return

@@ -208,3 +209,3 @@

case SCRIPT_TYPES.MULTISIG: {
case SCRIPT_TYPES.P2MS: {
const p2ms = payments.p2ms({ output: script })

@@ -214,3 +215,4 @@ return {

pubkeys: p2ms.pubkeys,
signatures: p2ms.pubkeys.map(() => undefined)
signatures: p2ms.pubkeys.map(() => undefined),
maxSignatures: p2ms.m
}

@@ -223,3 +225,3 @@ }

function prepareInput (input, ourPubKey, redeemScript, witnessValue, witnessScript) {
function prepareInput (input, ourPubKey, redeemScript, witnessScript) {
if (redeemScript && witnessScript) {

@@ -259,3 +261,4 @@ const p2wsh = payments.p2wsh({ redeem: { output: witnessScript } })

pubkeys: expanded.pubkeys,
signatures: expanded.signatures
signatures: expanded.signatures,
maxSignatures: expanded.maxSignatures
}

@@ -298,3 +301,4 @@ }

pubkeys: expanded.pubkeys,
signatures: expanded.signatures
signatures: expanded.signatures,
maxSignatures: expanded.maxSignatures
}

@@ -332,3 +336,4 @@ }

pubkeys: expanded.pubkeys,
signatures: expanded.signatures
signatures: expanded.signatures,
maxSignatures: expanded.maxSignatures
}

@@ -363,3 +368,4 @@ }

pubkeys: expanded.pubkeys,
signatures: expanded.signatures
signatures: expanded.signatures,
maxSignatures: expanded.maxSignatures
}

@@ -405,3 +411,4 @@ }

}
case SCRIPT_TYPES.MULTISIG: {
case SCRIPT_TYPES.P2MS: {
const m = input.maxSignatures
if (allowIncomplete) {

@@ -413,3 +420,6 @@ signatures = signatures.map(x => x || ops.OP_0)

return payments.p2ms({ signatures }, { allowIncomplete })
// if the transaction is not not complete (complete), or if signatures.length === m, validate
// otherwise, the number of OP_0's may be >= m, so don't validate (boo)
const validate = !allowIncomplete || (m === signatures.length)
return payments.p2ms({ m, pubkeys, signatures }, { allowIncomplete, validate })
}

@@ -648,3 +658,5 @@ case SCRIPT_TYPES.P2SH: {

if (!this.__inputs[vin]) throw new Error('No input at index: ' + vin)
hashType = hashType || Transaction.SIGHASH_ALL
if (this.__needsOutputs(hashType)) throw new Error('Transaction needs outputs')

@@ -669,3 +681,3 @@ const input = this.__inputs[vin]

if (!canSign(input)) {
const prepared = prepareInput(input, ourPubKey, redeemScript, witnessValue, witnessScript)
const prepared = prepareInput(input, ourPubKey, redeemScript, witnessScript)

@@ -711,4 +723,3 @@ // updates inline

return this.__inputs.every(function (input) {
// any signatures?
if (input.signatures === undefined) return true
if (!input.signatures) return true

@@ -726,2 +737,21 @@ return input.signatures.every(function (signature) {

TransactionBuilder.prototype.__needsOutputs = function (signingHashType) {
if (signingHashType === Transaction.SIGHASH_ALL) {
return this.__tx.outs.length === 0
}
// if inputs are being signed with SIGHASH_NONE, we don't strictly need outputs
// .build() will fail, but .buildIncomplete() is OK
return (this.__tx.outs.length === 0) && this.__inputs.some((input) => {
if (!input.signatures) return false
return input.signatures.some((signature) => {
if (!signature) return false // no signature, no issue
const hashType = signatureHashType(signature)
if (hashType & Transaction.SIGHASH_NONE) return false // SIGHASH_NONE doesn't care about outputs
return true // SIGHASH_* does care
})
})
}
TransactionBuilder.prototype.__canModifyOutputs = function () {

@@ -728,0 +758,0 @@ const nInputs = this.__tx.ins.length

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