@exodus/bitcoin-api 4.9.5 → 4.9.6

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,16 @@
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
+ ## [4.9.6](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@4.9.5...@exodus/bitcoin-api@4.9.6) (2026-03-02)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+
12
+ * fix(bitcoin-api): normalize witnessUtxo values for PSBT input (#7497)
13
+
14
+
15
+
6
16
  ## [4.9.5](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@4.9.4...@exodus/bitcoin-api@4.9.5) (2026-02-14)
7
17
 
8
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/bitcoin-api",
3
- "version": "4.9.5",
3
+ "version": "4.9.6",
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",
@@ -61,5 +61,5 @@
61
61
  "type": "git",
62
62
  "url": "git+https://github.com/ExodusMovement/assets.git"
63
63
  },
64
- "gitHead": "8c4fcde522beb978df6a5099e0fa9e34bb4a7e04"
64
+ "gitHead": "04dc4d08ec82b0405ec1ec3a52d682ef11451914"
65
65
  }
@@ -6,6 +6,7 @@ import { SubType, writePsbtGlobalField, writePsbtOutputField } from './psbt-prop
6
6
  import {
7
7
  getAddressType,
8
8
  getPurposeXPubs,
9
+ normalizeWitnessUtxoValue,
9
10
  setPsbtVersionIfNotBitcoin,
10
11
  validatePurpose,
11
12
  } from './psbt-utils.js'
@@ -112,7 +113,7 @@ function createPsbtInput({
112
113
 
113
114
  if (isWrappedSegwitAddress || isSegwitAddress || isTaprootAddress) {
114
115
  psbtInput.witnessUtxo = {
115
- value: input.value,
116
+ value: normalizeWitnessUtxoValue(input.value),
116
117
  script: Buffer.from(input.script, 'hex'),
117
118
  }
118
119
  }
@@ -132,7 +133,7 @@ function createPsbtInput({
132
133
  // vendor forks, malformed historical data). When that happens we fall back to a
133
134
  // witness-only record and rely on the signer to opt-in to __UNSAFE_SIGN_NONSEGWIT.
134
135
  psbtInput.witnessUtxo = {
135
- value: input.value,
136
+ value: normalizeWitnessUtxoValue(input.value),
136
137
  script: Buffer.from(input.script, 'hex'),
137
138
  }
138
139
  }
package/src/psbt-utils.js CHANGED
@@ -132,6 +132,39 @@ export async function withUnsafeNonSegwit({ psbt, fn, unsafe = true }) {
132
132
  }
133
133
  }
134
134
 
135
+ export function normalizeWitnessUtxoValue(value) {
136
+ if (typeof value === 'number') {
137
+ if (!Number.isSafeInteger(value)) {
138
+ throw new TypeError('witnessUtxo value does not fit in a safe integer')
139
+ }
140
+
141
+ return value
142
+ }
143
+
144
+ if (typeof value === 'bigint') {
145
+ if (!Number.isSafeInteger(Number(value))) {
146
+ throw new TypeError('witnessUtxo value does not fit in a safe integer')
147
+ }
148
+
149
+ return Number(value)
150
+ }
151
+
152
+ if (Buffer.isBuffer(value)) {
153
+ if (value.length !== 8) {
154
+ throw new Error(`Unexpected witnessUtxo value buffer size: ${value.length}`)
155
+ }
156
+
157
+ const parsed = value.readBigUInt64LE(0)
158
+ if (parsed > BigInt(Number.MAX_SAFE_INTEGER)) {
159
+ throw new Error('witnessUtxo value does not fit in a safe integer')
160
+ }
161
+
162
+ return Number(parsed)
163
+ }
164
+
165
+ throw new TypeError(`Unsupported witnessUtxo value type: ${typeof value}`)
166
+ }
167
+
135
168
  export function setPsbtVersionIfNotBitcoin(psbt, assetName) {
136
169
  if (!['bitcoin', 'bitcoinregtest', 'bitcointestnet'].includes(assetName)) psbt.setVersion(1)
137
170
  }
@@ -2,7 +2,7 @@ import { Psbt as DefaultPsbt, Transaction as DefaultTransaction } from '@exodus/
2
2
  import assert from 'minimalistic-assert'
3
3
 
4
4
  import { writePsbtBlockHeight } from '../psbt-proprietary-types.js'
5
- import { setPsbtVersionIfNotBitcoin } from '../psbt-utils.js'
5
+ import { normalizeWitnessUtxoValue, setPsbtVersionIfNotBitcoin } from '../psbt-utils.js'
6
6
  import { getMaximumFeeRate } from './maximum-fee-rates.js'
7
7
 
8
8
  /**
@@ -115,7 +115,10 @@ function createPsbtFromTxData({
115
115
 
116
116
  if (isSegwitAddress || isTaprootAddress) {
117
117
  // taproot outputs only require the value and the script, not the full transaction
118
- txIn.witnessUtxo = { value, script: Buffer.from(script, 'hex') }
118
+ txIn.witnessUtxo = {
119
+ value: normalizeWitnessUtxoValue(value),
120
+ script: Buffer.from(script, 'hex'),
121
+ }
119
122
  }
120
123
 
121
124
  const rawTx = (rawTxs || []).find((t) => t.txId === txId)
@@ -130,7 +133,10 @@ function createPsbtFromTxData({
130
133
  // temp fix for https://exodusio.slack.com/archives/CP202D90Q/p1671014704829939 until bitcoinjs could parse a mweb tx without failing
131
134
  console.warn(`Setting psbt.__CACHE.__UNSAFE_SIGN_NONSEGWIT = true for asset ${assetName}`)
132
135
  psbt.__CACHE.__UNSAFE_SIGN_NONSEGWIT = true
133
- txIn.witnessUtxo = { value, script: Buffer.from(script, 'hex') }
136
+ txIn.witnessUtxo = {
137
+ value: normalizeWitnessUtxoValue(value),
138
+ script: Buffer.from(script, 'hex'),
139
+ }
134
140
  }
135
141
  }
136
142