@exodus/bitcoin-api 4.16.1 → 5.0.0

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,19 @@
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.0](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@4.16.1...@exodus/bitcoin-api@5.0.0) (2026-07-10)
7
+
8
+
9
+ ### ⚠ BREAKING CHANGES
10
+
11
+ * **bitcoin:** broadcast btc via mempool space send path (#8349)
12
+
13
+ ### Features
14
+
15
+ * **bitcoin:** broadcast btc via mempool space send path ([#8349](https://github.com/ExodusMovement/assets/issues/8349)) ([ff44736](https://github.com/ExodusMovement/assets/commit/ff44736b7aae845e5261bd60c8583d5871adb8f2))
16
+
17
+
18
+
6
19
  ## [4.16.1](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@4.16.0...@exodus/bitcoin-api@4.16.1) (2026-07-09)
7
20
 
8
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/bitcoin-api",
3
- "version": "4.16.1",
3
+ "version": "5.0.0",
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": "dd519241ca0e24a4bbb93aeec3c9ff540c7e71f7"
66
+ "gitHead": "1d7fd9da145bcfeb290441b3b8c72f9f5310eaca"
67
67
  }
@@ -16,9 +16,8 @@ const RETRY_WAIT_TIMES = ['5s', '10s', '20s', '30s']
16
16
  const TIP_HEIGHT_CACHE_TTL_MS = 10_000
17
17
 
18
18
  const MEMPOOL_HTTP_ERROR_MESSAGE = safeString`mempool-api-http-error`
19
- const MEMPOOL_INSIGHT_JSON_ERROR_MESSAGE = safeString`mempool-insight-api-invalid-json`
20
- const MEMPOOL_INSIGHT_MISSING_TXID_MESSAGE = safeString`mempool-insight-api-missing-txid`
21
- const MEMPOOL_INSIGHT_HTTP_ERROR_BROADCAST_MESSAGE = safeString`mempool-insight-api-http-error:broadcast`
19
+ const MEMPOOL_MISSING_TXID_MESSAGE = safeString`mempool-api-missing-txid`
20
+ const MEMPOOL_HTTP_ERROR_BROADCAST_MESSAGE = safeString`mempool-api-http-error:broadcast`
22
21
  const MEMPOOL_JSON_ERROR_MESSAGE = safeString`mempool-api-invalid-json`
23
22
  const MEMPOOL_TEXT_ERROR_MESSAGE = safeString`mempool-api-invalid-text`
24
23
  const MEMPOOL_HTTP_ERROR_TX_MESSAGE = safeString`mempool-api-http-error:tx`
@@ -34,6 +33,9 @@ const MEMPOOL_HTTP_ERROR_CPFP_MESSAGE = safeString`mempool-api-http-error:cpfp`
34
33
  const MEMPOOL_FEES_PAYLOAD_ERROR_MESSAGE = safeString`mempool-api-invalid-fees-payload`
35
34
  const MEMPOOL_INVALID_VALUE_ERROR_MESSAGE = safeString`mempool-api-invalid-value`
36
35
 
36
+ // A txid is a double-SHA256 hash: always exactly 32 bytes / 64 hex chars.
37
+ const TXID_HEX_PATTERN = /^[\da-f]{64}$/i
38
+
37
39
  const parseBroadcastErrorReason = (data) => {
38
40
  if (!data) {
39
41
  return null
@@ -213,14 +215,8 @@ const normalizeTx = (tx, tipHeight, outspends) => {
213
215
  }
214
216
 
215
217
  export default class MempoolRestClient {
216
- constructor({
217
- mempoolBaseURL,
218
- clarityBaseURL,
219
- retryWaitTimes = RETRY_WAIT_TIMES,
220
- configMinFeeRate = 10,
221
- } = {}) {
218
+ constructor({ mempoolBaseURL, retryWaitTimes = RETRY_WAIT_TIMES, configMinFeeRate = 10 } = {}) {
222
219
  this._mempoolBaseURL = mempoolBaseURL
223
- this._clarityBaseURL = clarityBaseURL
224
220
  this._retryWaitTimes = retryWaitTimes
225
221
  this._configMinFeeRate = configMinFeeRate
226
222
  this._tipHeightCache = null
@@ -234,10 +230,6 @@ export default class MempoolRestClient {
234
230
  this._mempoolBaseURL = mempoolBaseURL
235
231
  }
236
232
 
237
- setClarityBaseUrl(clarityBaseURL) {
238
- this._clarityBaseURL = clarityBaseURL
239
- }
240
-
241
233
  _mempoolApiUrl(path, { version } = {}) {
242
234
  return urlJoin(this._mempoolBaseURL, version === 'v1' ? '/api/v1' : '/api', path)
243
235
  }
@@ -655,47 +647,37 @@ export default class MempoolRestClient {
655
647
  return { size, fees: Math.round(fees) }
656
648
  }
657
649
 
658
- // Keep broadcast behavior aligned with the existing insight client.
659
- // Our Insight/Magnifier path fans out to Exodus-managed bitcoin nodes and has the
660
- // operational behavior we already depend on when propagation is slow or a rejection
661
- // is temporary. The mempool REST API alone is not a drop-in replacement for that.
650
+ // mempool.space/esplora broadcast: POST the raw hex as text, success is the
651
+ // txid as plain text, rejections are 400s whose text body carries bitcoind's
652
+ // sendrawtransaction reason (e.g. `txn-already-in-mempool`, `missing inputs`).
653
+ // That reason is preserved on `error.reason` because tx-send retry
654
+ // classification (broadcast-tx.js) pattern-matches it.
662
655
  async broadcastTx(rawTx) {
663
656
  const payload = rawTx instanceof Uint8Array ? Buffer.from(rawTx).toString('hex') : rawTx
664
- const response = await fetch(urlJoin(this._clarityBaseURL, '/tx/send'), {
657
+ const response = await fetch(this._mempoolApiUrl('/tx'), {
665
658
  method: 'post',
666
659
  headers: {
667
- Accept: 'application/json',
668
- 'Content-Type': 'application/json',
660
+ Accept: 'text/plain',
661
+ 'Content-Type': 'text/plain',
669
662
  },
670
- body: JSON.stringify({ rawtx: payload }),
663
+ body: payload,
671
664
  })
672
665
 
673
- let data = await response.text()
666
+ const data = await response.text()
674
667
 
675
668
  if (!response.ok) {
676
- console.warn(`Mempool Client's Insight Broadcast HTTP Error:`)
669
+ console.warn(`Mempool Client's Broadcast HTTP Error:`)
677
670
  console.warn(response.statusText)
678
671
  console.warn(data)
679
- const error = createHttpError(response, MEMPOOL_INSIGHT_HTTP_ERROR_BROADCAST_MESSAGE)
672
+ const error = createHttpError(response, MEMPOOL_HTTP_ERROR_BROADCAST_MESSAGE)
680
673
  error.reason = parseBroadcastErrorReason(data)
681
674
  throw error
682
675
  }
683
676
 
684
- try {
685
- data = JSON.parse(data)
686
- } catch (err) {
687
- console.warn(`Mempool Client's Insight Broadcast JSON Parse Error:`, err.message, data)
688
- const error = new Error(MEMPOOL_INSIGHT_JSON_ERROR_MESSAGE, { cause: err })
689
- const traceId = TraceId.fromResponse && TraceId.fromResponse(response)
690
- if (traceId) {
691
- error.traceId = traceId
692
- }
693
-
694
- throw error
695
- }
696
-
697
- if (!data.txid) {
698
- const error = new Error(MEMPOOL_INSIGHT_MISSING_TXID_MESSAGE)
677
+ const txid = String(data).trim()
678
+ if (!TXID_HEX_PATTERN.test(txid)) {
679
+ console.warn(`Mempool Client's Broadcast Unexpected Payload:`, data)
680
+ const error = new Error(MEMPOOL_MISSING_TXID_MESSAGE)
699
681
  const traceId = TraceId.fromResponse && TraceId.fromResponse(response)
700
682
  if (traceId) {
701
683
  error.traceId = traceId
@@ -704,7 +686,6 @@ export default class MempoolRestClient {
704
686
  throw error
705
687
  }
706
688
 
707
- const { txid } = data
708
689
  return { txid }
709
690
  }
710
691
  }
@@ -118,10 +118,9 @@ export function toMempoolWebSocketUrl(apiUrl) {
118
118
  export function normalizeInsightConfig(config, monitorType) {
119
119
  const apiUrl = config?.insightServers?.[0]
120
120
  const mempoolApiUrl = config?.mempoolServer
121
- const clarityApiUrl = config?.clarityServer
122
121
  const wsUrl =
123
122
  monitorType === 'mempool'
124
123
  ? config?.mempoolServerWS || toMempoolWebSocketUrl(mempoolApiUrl)
125
124
  : config?.insightServersWS?.[0] || toWSUrl(apiUrl)
126
- return { apiUrl, mempoolApiUrl, clarityApiUrl, wsUrl }
125
+ return { apiUrl, mempoolApiUrl, wsUrl }
127
126
  }
@@ -91,21 +91,12 @@ export class Monitor extends BaseMonitor {
91
91
  }
92
92
 
93
93
  setServer(assetConfig = {}) {
94
- const { apiUrl, mempoolApiUrl, clarityApiUrl, wsUrl } = normalizeInsightConfig(
95
- assetConfig,
96
- this.#monitorType
97
- )
94
+ const { apiUrl, mempoolApiUrl, wsUrl } = normalizeInsightConfig(assetConfig, this.#monitorType)
98
95
 
99
96
  if (this.#monitorType === 'mempool') {
100
- const clarityBaseUrl = clarityApiUrl || apiUrl
101
-
102
97
  if (mempoolApiUrl) {
103
98
  this.#insightClient.setMempoolBaseUrl(mempoolApiUrl)
104
99
  }
105
-
106
- if (clarityBaseUrl) {
107
- this.#insightClient.setClarityBaseUrl(clarityBaseUrl)
108
- }
109
100
  } else if (apiUrl) {
110
101
  this.#insightClient.setBaseUrl(apiUrl)
111
102
  }