@exodus/bitcoin-api 5.0.1 → 5.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,27 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [5.0.3](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@5.0.0...@exodus/bitcoin-api@5.0.3) (2026-08-10)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * extract broadcast rejection reason from error body message field ([#8396](https://github.com/ExodusMovement/assets/issues/8396)) ([a916a55](https://github.com/ExodusMovement/assets/commit/a916a55af921da5125405a0be8ca43321a3654fd))
12
+ * refuse SIGHASH_SINGLE signatures that commit to no output (3927405) ([#8479](https://github.com/ExodusMovement/assets/issues/8479)) ([cde191b](https://github.com/ExodusMovement/assets/commit/cde191b91a32be1bc5de4bb838b97d0e6a843527))
13
+ * **send-validation:** improve displayed amount format in validation messages ([#8366](https://github.com/ExodusMovement/assets/issues/8366)) ([940dcd4](https://github.com/ExodusMovement/assets/commit/940dcd4cbe75f4ab48e067bd033afd249caae9a4))
14
+
15
+
16
+
17
+ ## [5.0.2](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@5.0.0...@exodus/bitcoin-api@5.0.2) (2026-07-16)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * extract broadcast rejection reason from error body message field ([#8396](https://github.com/ExodusMovement/assets/issues/8396)) ([a916a55](https://github.com/ExodusMovement/assets/commit/a916a55af921da5125405a0be8ca43321a3654fd))
23
+ * **send-validation:** improve displayed amount format in validation messages ([#8366](https://github.com/ExodusMovement/assets/issues/8366)) ([940dcd4](https://github.com/ExodusMovement/assets/commit/940dcd4cbe75f4ab48e067bd033afd249caae9a4))
24
+
25
+
26
+
6
27
  ## [5.0.1](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@5.0.0...@exodus/bitcoin-api@5.0.1) (2026-07-11)
7
28
 
8
29
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/bitcoin-api",
3
- "version": "5.0.1",
3
+ "version": "5.0.3",
4
4
  "description": "Bitcoin transaction and fee monitors, RPC with the blockchain node, other networking code.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -63,5 +63,5 @@
63
63
  "type": "git",
64
64
  "url": "git+https://github.com/ExodusMovement/assets.git"
65
65
  },
66
- "gitHead": "07af9a0d2bda8262afce9aaabafabe0fa68286ba"
66
+ "gitHead": "e76fe6900a823d6abd2cbf7efa273132c5dab1ae"
67
67
  }
@@ -30,7 +30,12 @@ const parseBroadcastErrorReason = (data) => {
30
30
 
31
31
  try {
32
32
  const parsed = JSON.parse(data)
33
- return parsed?.error || data
33
+ // Magnifier surfaces bitcoind's rejection reason (e.g.
34
+ // bad-txns-inputs-missingorspent) in fastify's `message` field, while
35
+ // `error` only carries the generic "Internal Server Error". tx-send
36
+ // pattern-matches the reason to classify failures as final and to trigger
37
+ // stale-UTXO repair, so `message` must win.
38
+ return parsed?.message || parsed?.error || data
34
39
  } catch {
35
40
  return data
36
41
  }
@@ -43,7 +43,11 @@ const parseBroadcastErrorReason = (data) => {
43
43
 
44
44
  try {
45
45
  const parsed = JSON.parse(data)
46
- return parsed?.error || data
46
+ // Esplora rejections are usually plain text (handled by the catch), but
47
+ // structured variants put bitcoind's reason in `message`
48
+ // (e.g. {"code":-25,"message":"bad-txns-inputs-missingorspent"}), which
49
+ // tx-send pattern-matches for retry classification and stale-UTXO repair.
50
+ return parsed?.message || parsed?.error || data
47
51
  } catch {
48
52
  return data
49
53
  }
package/src/psbt-utils.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import BIP32 from '@exodus/bip32'
2
+ import { Transaction } from '@exodus/bitcoinjs'
2
3
  import BipPath from 'bip32-path'
3
4
  import lodash from 'lodash'
4
5
  import assert from 'minimalistic-assert'
@@ -167,3 +168,31 @@ export function normalizeWitnessUtxoValue(value) {
167
168
  export function setPsbtVersionIfNotBitcoin(psbt, assetName) {
168
169
  if (!['bitcoin', 'bitcoinregtest', 'bitcointestnet'].includes(assetName)) psbt.setVersion(1)
169
170
  }
171
+
172
+ // A SIGHASH_SINGLE signature commits only to the output at the same index as the input it
173
+ // signs. When that index is at or past the last output there is no such output, and under
174
+ // both the legacy and the BIP143 digest the outputs commitment becomes a constant. The
175
+ // signature then authorises the inputs while binding none of the recipients, so whoever
176
+ // holds the signed PSBT can replace every output and still broadcast a valid transaction.
177
+ //
178
+ // Bitcoin Core rejects that case when verifying legacy inputs, but a wallet that produces
179
+ // the signature has already lost: the caller keeps it. So refuse before signing.
180
+ //
181
+ // The mask is used rather than a value list because the ANYONECANPAY variant, 0x83, has to
182
+ // be caught as well, and Transaction.SIGHASH_OUTPUT_MASK is the base type mask.
183
+ export const assertOutputCommitment = ({ psbt, index }) => {
184
+ const { sighashType } = psbt.data.inputs[index] ?? {}
185
+
186
+ if (sighashType === undefined) return // SIGHASH_DEFAULT, taproot's implicit sign-all.
187
+
188
+ const isSighashSingle =
189
+ (sighashType & Transaction.SIGHASH_OUTPUT_MASK) === Transaction.SIGHASH_SINGLE
190
+
191
+ if (isSighashSingle && index >= psbt.txOutputs.length) {
192
+ throw new Error(
193
+ `Refusing to sign input ${index} with SIGHASH_SINGLE: the transaction has ` +
194
+ `${psbt.txOutputs.length} output(s), so there is no output at index ${index} for the ` +
195
+ `signature to commit to. Every recipient could be replaced after signing.`
196
+ )
197
+ }
198
+ }
@@ -1,7 +1,7 @@
1
1
  import { bip371, payments, Transaction } from '@exodus/bitcoinjs'
2
2
  import { publicKeyToX } from '@exodus/crypto/secp256k1'
3
3
 
4
- import { withUnsafeNonSegwit } from '../psbt-utils.js'
4
+ import { assertOutputCommitment, withUnsafeNonSegwit } from '../psbt-utils.js'
5
5
  import { createGetKeyWithMetadata } from './create-get-key-and-purpose.js'
6
6
  import { toAsyncBufferSigner, toAsyncSigner } from './taproot.js'
7
7
 
@@ -38,6 +38,12 @@ export function createSignWithWallet({
38
38
  if (!inputInfo) continue
39
39
 
40
40
  const input = psbt.data.inputs[index]
41
+
42
+ // Refuse a sighash whose signature would commit to no outputs at all. Checked on
43
+ // the PSBT input rather than on inputsToSign, because the value in the PSBT is the
44
+ // one the digest is built from.
45
+ assertOutputCommitment({ psbt, index })
46
+
41
47
  const { address, sigHash, derivationPath } = inputInfo
42
48
  // The sighash value from the PSBT input itself will be used.
43
49
  // This list just represents possible sighash values the inputs can have.
@@ -1,5 +1,6 @@
1
1
  import assert from 'minimalistic-assert'
2
2
 
3
+ import { assertOutputCommitment } from '../psbt-utils.js'
3
4
  import { extractTransaction, shouldSkipFinalize } from './common.js'
4
5
  import { createPrepareForSigning } from './default-prepare-for-signing.js'
5
6
 
@@ -59,6 +60,14 @@ function createSignWithHardwareWallet({ assetName, resolvePurpose }) {
59
60
  addressPathsMap,
60
61
  accountIndex,
61
62
  })
63
+ // Same refusal as the software path in create-sign-with-wallet.js. A hardware device is
64
+ // handed the serialised PSBT and signs what it is given, so the check has to happen here
65
+ // too or the guard only covers software wallets.
66
+ for (let index = 0; index < psbt.inputCount; index++) {
67
+ if (!inputsToSign[index]) continue
68
+ assertOutputCommitment({ psbt, index })
69
+ }
70
+
62
71
  const signatures = await hardwareDevice.signTransaction({
63
72
  assetName,
64
73
  signableTransaction: psbt.toBuffer(),