@babylonlabs-io/ts-sdk 0.41.1 → 0.44.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/dist/ApplicationRegistry.abi-BAPhJch3.cjs +2 -0
- package/dist/ApplicationRegistry.abi-BAPhJch3.cjs.map +1 -0
- package/dist/{ProtocolParams.abi-C2brDWTI.js → ApplicationRegistry.abi-Dn2qk6JG.js} +90 -90
- package/dist/ApplicationRegistry.abi-Dn2qk6JG.js.map +1 -0
- package/dist/{PeginManager-Bsou6AQV.js → PeginManager-BezsAEDe.js} +125 -127
- package/dist/PeginManager-BezsAEDe.js.map +1 -0
- package/dist/{PeginManager-BOuzU8Zo.cjs → PeginManager-D-8vmqzq.cjs} +2 -2
- package/dist/PeginManager-D-8vmqzq.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +180 -179
- package/dist/mempoolApi-CknccHKg.cjs +2 -0
- package/dist/mempoolApi-CknccHKg.cjs.map +1 -0
- package/dist/mempoolApi-DI9HISqi.js +451 -0
- package/dist/mempoolApi-DI9HISqi.js.map +1 -0
- package/dist/primeVpAuth-Duds3vAO.cjs +2 -0
- package/dist/primeVpAuth-Duds3vAO.cjs.map +1 -0
- package/dist/primeVpAuth-qEC9TTO_.js +1136 -0
- package/dist/primeVpAuth-qEC9TTO_.js.map +1 -0
- package/dist/tbv/core/clients/eth/types.d.ts +7 -0
- package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts +8 -0
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +31 -31
- package/dist/tbv/core/contracts/index.cjs +1 -1
- package/dist/tbv/core/contracts/index.js +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +182 -181
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- package/dist/tbv/core/managers/index.cjs +1 -1
- package/dist/tbv/core/managers/index.js +1 -1
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.d.ts +2 -1
- package/dist/tbv/core/primitives/index.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.js +23 -22
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +182 -181
- package/dist/tbv/integrations/aave/clients/__tests__/oracle.test.d.ts +2 -0
- package/dist/tbv/integrations/aave/clients/__tests__/oracle.test.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/clients/abis/AaveOracle.abi.json.d.ts +36 -0
- package/dist/tbv/integrations/aave/clients/index.d.ts +1 -0
- package/dist/tbv/integrations/aave/clients/index.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/clients/oracle.d.ts +14 -0
- package/dist/tbv/integrations/aave/clients/oracle.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/index.cjs +1 -1
- package/dist/tbv/integrations/aave/index.cjs.map +1 -1
- package/dist/tbv/integrations/aave/index.d.ts +1 -1
- package/dist/tbv/integrations/aave/index.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/index.js +249 -141
- package/dist/tbv/integrations/aave/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/PeginManager-BOuzU8Zo.cjs.map +0 -1
- package/dist/PeginManager-Bsou6AQV.js.map +0 -1
- package/dist/ProtocolParams.abi-C2brDWTI.js.map +0 -1
- package/dist/ProtocolParams.abi-DQhcqsNr.cjs +0 -2
- package/dist/ProtocolParams.abi-DQhcqsNr.cjs.map +0 -1
- package/dist/mempoolApi-C7hkVkym.js +0 -214
- package/dist/mempoolApi-C7hkVkym.js.map +0 -1
- package/dist/mempoolApi-DEAS9wVa.cjs +0 -2
- package/dist/mempoolApi-DEAS9wVa.cjs.map +0 -1
- package/dist/types-0bvDGR4x.js +0 -1347
- package/dist/types-0bvDGR4x.js.map +0 -1
- package/dist/types-Be3sAYzr.cjs +0 -2
- package/dist/types-Be3sAYzr.cjs.map +0 -1
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import { B as $, H as p, K as E, T as F } from "./validation-CxqROCno.js";
|
|
2
|
-
const I = 21e6 * 1e8, u = 3e4;
|
|
3
|
-
async function i(e, r) {
|
|
4
|
-
const t = new AbortController(), n = setTimeout(
|
|
5
|
-
() => t.abort(),
|
|
6
|
-
u
|
|
7
|
-
), a = [t.signal, r == null ? void 0 : r.signal].filter(
|
|
8
|
-
Boolean
|
|
9
|
-
);
|
|
10
|
-
try {
|
|
11
|
-
return await fetch(e, {
|
|
12
|
-
...r,
|
|
13
|
-
signal: AbortSignal.any(a)
|
|
14
|
-
});
|
|
15
|
-
} catch (o) {
|
|
16
|
-
throw clearTimeout(n), o != null && typeof o == "object" && "name" in o && o.name === "AbortError" ? new Error(
|
|
17
|
-
`Mempool API request timed out after ${u}ms: ${e}`
|
|
18
|
-
) : o;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
const l = 1e4;
|
|
22
|
-
function w(e) {
|
|
23
|
-
return Number.isInteger(e) && e > 0 && e <= I;
|
|
24
|
-
}
|
|
25
|
-
function g(e) {
|
|
26
|
-
return Number.isInteger(e) && e > 0 && e <= l;
|
|
27
|
-
}
|
|
28
|
-
function m(e, r) {
|
|
29
|
-
return !Number.isInteger(e) || e < 0 ? !1 : r === void 0 || e < r;
|
|
30
|
-
}
|
|
31
|
-
function c(e) {
|
|
32
|
-
if (!F.test(e))
|
|
33
|
-
throw new Error(`Invalid transaction ID format: ${e}`);
|
|
34
|
-
}
|
|
35
|
-
function h(e) {
|
|
36
|
-
if (!$.test(e))
|
|
37
|
-
throw new Error(`Invalid Bitcoin address format: ${e}`);
|
|
38
|
-
}
|
|
39
|
-
function d(e, r) {
|
|
40
|
-
if (!p.test(e))
|
|
41
|
-
throw new Error(
|
|
42
|
-
`Invalid scriptPubKey: not valid hex for ${r}`
|
|
43
|
-
);
|
|
44
|
-
if (!E.some(
|
|
45
|
-
(n) => e.toLowerCase().startsWith(n)
|
|
46
|
-
))
|
|
47
|
-
throw new Error(
|
|
48
|
-
`Unrecognized scriptPubKey type for ${r}: prefix ${e.slice(0, 6)} does not match any known Bitcoin script type`
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
const y = {
|
|
52
|
-
mainnet: "https://mempool.space/api",
|
|
53
|
-
testnet: "https://mempool.space/testnet/api",
|
|
54
|
-
signet: "https://mempool.space/signet/api"
|
|
55
|
-
};
|
|
56
|
-
async function s(e, r) {
|
|
57
|
-
try {
|
|
58
|
-
const t = await i(e, r);
|
|
59
|
-
if (!t.ok) {
|
|
60
|
-
const a = await t.text();
|
|
61
|
-
throw new Error(
|
|
62
|
-
`Mempool API error (${t.status}): ${a || t.statusText}`
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
const n = t.headers.get("content-type");
|
|
66
|
-
return n != null && n.includes("application/json") ? await t.json() : await t.text();
|
|
67
|
-
} catch (t) {
|
|
68
|
-
throw t instanceof Error ? new Error(`Failed to fetch from mempool API: ${t.message}`) : new Error("Failed to fetch from mempool API: Unknown error");
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
async function v(e, r) {
|
|
72
|
-
try {
|
|
73
|
-
const t = await i(`${r}/tx`, {
|
|
74
|
-
method: "POST",
|
|
75
|
-
body: e,
|
|
76
|
-
headers: {
|
|
77
|
-
"Content-Type": "text/plain"
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
if (!t.ok) {
|
|
81
|
-
const a = await t.text();
|
|
82
|
-
let o;
|
|
83
|
-
try {
|
|
84
|
-
o = JSON.parse(a).message;
|
|
85
|
-
} catch {
|
|
86
|
-
o = a;
|
|
87
|
-
}
|
|
88
|
-
throw new Error(
|
|
89
|
-
o || `Failed to broadcast transaction: ${t.statusText}`
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
return await t.text();
|
|
93
|
-
} catch (t) {
|
|
94
|
-
throw t instanceof Error ? new Error(`Failed to broadcast BTC transaction: ${t.message}`) : new Error("Failed to broadcast BTC transaction: Unknown error");
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
async function T(e, r) {
|
|
98
|
-
return c(e), s(`${r}/tx/${e}`);
|
|
99
|
-
}
|
|
100
|
-
async function b(e) {
|
|
101
|
-
const r = await s(`${e}/blocks/tip/height`), t = r.trim();
|
|
102
|
-
if (!/^\d+$/.test(t))
|
|
103
|
-
throw new Error(
|
|
104
|
-
`Mempool API returned an invalid block tip height: "${r}"`
|
|
105
|
-
);
|
|
106
|
-
return Number.parseInt(t, 10);
|
|
107
|
-
}
|
|
108
|
-
async function A(e, r) {
|
|
109
|
-
c(e);
|
|
110
|
-
try {
|
|
111
|
-
const t = await i(`${r}/tx/${e}/hex`);
|
|
112
|
-
if (!t.ok) {
|
|
113
|
-
const n = await t.text();
|
|
114
|
-
throw new Error(
|
|
115
|
-
`Mempool API error (${t.status}): ${n || t.statusText}`
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
return await t.text();
|
|
119
|
-
} catch (t) {
|
|
120
|
-
throw t instanceof Error ? new Error(`Failed to get transaction hex for ${e}: ${t.message}`) : new Error(`Failed to get transaction hex for ${e}: Unknown error`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
async function P(e, r, t) {
|
|
124
|
-
c(e);
|
|
125
|
-
const n = await T(e, t);
|
|
126
|
-
if (!m(r, n.vout.length))
|
|
127
|
-
throw new Error(
|
|
128
|
-
`Invalid vout ${r} for transaction ${e} (has ${n.vout.length} outputs)`
|
|
129
|
-
);
|
|
130
|
-
const a = n.vout[r];
|
|
131
|
-
if (!w(a.value))
|
|
132
|
-
throw new Error(`Invalid UTXO value ${a.value} for ${e}:${r}`);
|
|
133
|
-
return d(a.scriptpubkey, `${e}:${r}`), {
|
|
134
|
-
txid: e,
|
|
135
|
-
vout: r,
|
|
136
|
-
value: a.value,
|
|
137
|
-
scriptPubKey: a.scriptpubkey
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
async function O(e, r) {
|
|
141
|
-
h(e);
|
|
142
|
-
try {
|
|
143
|
-
const t = await s(`${r}/address/${e}/utxo`), n = await s(`${r}/v1/validate-address/${e}`);
|
|
144
|
-
if (!n.isvalid)
|
|
145
|
-
throw new Error(
|
|
146
|
-
`Invalid Bitcoin address: ${e}. Mempool API validation failed.`
|
|
147
|
-
);
|
|
148
|
-
d(n.scriptPubKey, e);
|
|
149
|
-
for (const o of t) {
|
|
150
|
-
if (c(o.txid), !m(o.vout))
|
|
151
|
-
throw new Error(`Invalid vout ${o.vout} for ${o.txid}`);
|
|
152
|
-
if (!w(o.value))
|
|
153
|
-
throw new Error(
|
|
154
|
-
`Invalid UTXO value ${o.value} for ${o.txid}:${o.vout}`
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
return t.sort((o, f) => f.value - o.value).map((o) => ({
|
|
158
|
-
txid: o.txid,
|
|
159
|
-
vout: o.vout,
|
|
160
|
-
value: o.value,
|
|
161
|
-
scriptPubKey: n.scriptPubKey,
|
|
162
|
-
confirmed: o.status.confirmed
|
|
163
|
-
}));
|
|
164
|
-
} catch (t) {
|
|
165
|
-
throw t instanceof Error ? new Error(
|
|
166
|
-
`Failed to get UTXOs for address ${e}: ${t.message}`
|
|
167
|
-
) : new Error(
|
|
168
|
-
`Failed to get UTXOs for address ${e}: Unknown error`
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
function U(e) {
|
|
173
|
-
return y[e];
|
|
174
|
-
}
|
|
175
|
-
async function k(e, r) {
|
|
176
|
-
return h(e), s(`${r}/address/${e}/txs`);
|
|
177
|
-
}
|
|
178
|
-
async function M(e) {
|
|
179
|
-
const r = await i(`${e}/v1/fees/recommended`);
|
|
180
|
-
if (!r.ok)
|
|
181
|
-
throw new Error(
|
|
182
|
-
`Failed to fetch network fees: ${r.status} ${r.statusText}`
|
|
183
|
-
);
|
|
184
|
-
const t = await r.json(), n = [
|
|
185
|
-
"fastestFee",
|
|
186
|
-
"halfHourFee",
|
|
187
|
-
"hourFee",
|
|
188
|
-
"economyFee",
|
|
189
|
-
"minimumFee"
|
|
190
|
-
];
|
|
191
|
-
for (const a of n)
|
|
192
|
-
if (!g(t[a]))
|
|
193
|
-
throw new Error(
|
|
194
|
-
`Invalid fee rate ${a}=${t[a]} from mempool API: expected a positive number ≤ ${l}`
|
|
195
|
-
);
|
|
196
|
-
if (t.minimumFee > t.economyFee || t.economyFee > t.hourFee || t.hourFee > t.halfHourFee || t.halfHourFee > t.fastestFee)
|
|
197
|
-
throw new Error(
|
|
198
|
-
`Fee rate ordering violation from mempool API: expected minimumFee (${t.minimumFee}) <= economyFee (${t.economyFee}) <= hourFee (${t.hourFee}) <= halfHourFee (${t.halfHourFee}) <= fastestFee (${t.fastestFee}).`
|
|
199
|
-
);
|
|
200
|
-
return t;
|
|
201
|
-
}
|
|
202
|
-
export {
|
|
203
|
-
y as M,
|
|
204
|
-
O as a,
|
|
205
|
-
U as b,
|
|
206
|
-
M as c,
|
|
207
|
-
b as d,
|
|
208
|
-
A as e,
|
|
209
|
-
T as f,
|
|
210
|
-
k as g,
|
|
211
|
-
P as h,
|
|
212
|
-
v as p
|
|
213
|
-
};
|
|
214
|
-
//# sourceMappingURL=mempoolApi-C7hkVkym.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mempoolApi-C7hkVkym.js","sources":["../src/tbv/core/clients/mempool/mempoolApi.ts"],"sourcesContent":["/**\n * Mempool API Client\n *\n * Client for interacting with mempool.space API for Bitcoin network operations.\n * Used for broadcasting transactions and fetching UTXO data.\n *\n * @module clients/mempool/mempoolApi\n */\n\nimport {\n BITCOIN_ADDRESS_RE,\n HEX_RE,\n KNOWN_SCRIPT_PREFIXES,\n TXID_RE,\n} from \"../../utils/validation\";\n\nimport type { MempoolUTXO, NetworkFees, TxInfo, UtxoInfo } from \"./types\";\n\n/** Maximum valid satoshi value: 21 million BTC × 10^8 sats/BTC */\nconst MAX_SATOSHIS = 21_000_000 * 1e8;\n\n/** Timeout for mempool API requests — prevents indefinite hangs from stalled endpoints */\nconst MEMPOOL_REQUEST_TIMEOUT_MS = 30_000;\n\n/**\n * Fetch wrapper with AbortController-based timeout.\n * Ensures all mempool API requests fail bounded rather than hanging indefinitely.\n */\nasync function fetchWithTimeout(\n url: string,\n options?: RequestInit,\n): Promise<Response> {\n const controller = new AbortController();\n const timeoutId = setTimeout(\n () => controller.abort(),\n MEMPOOL_REQUEST_TIMEOUT_MS,\n );\n\n // Compose timeout signal with any caller-supplied signal so both can cancel\n const signals = [controller.signal, options?.signal].filter(\n Boolean,\n ) as AbortSignal[];\n\n try {\n // Don't clear timeout here — let it cover body consumption by callers\n return await fetch(url, {\n ...options,\n signal: AbortSignal.any(signals),\n });\n } catch (error) {\n clearTimeout(timeoutId);\n if (\n error != null &&\n typeof error === \"object\" &&\n \"name\" in error &&\n error.name === \"AbortError\"\n ) {\n throw new Error(\n `Mempool API request timed out after ${MEMPOOL_REQUEST_TIMEOUT_MS}ms: ${url}`,\n );\n }\n throw error;\n }\n}\n\n/**\n * Maximum sane fee rate in sat/vByte.\n * The April 2024 Runes spike peaked around 1,805 sat/vB — 10,000 provides ample headroom.\n */\nconst MAX_FEE_RATE = 10_000;\n\nfunction isValidSatoshiValue(value: number): boolean {\n return Number.isInteger(value) && value > 0 && value <= MAX_SATOSHIS;\n}\n\nfunction isValidFeeRate(value: number): boolean {\n return Number.isInteger(value) && value > 0 && value <= MAX_FEE_RATE;\n}\n\nfunction isValidVout(vout: number, outputCount?: number): boolean {\n if (!Number.isInteger(vout) || vout < 0) return false;\n return outputCount === undefined || vout < outputCount;\n}\n\n\nfunction assertValidTxid(txid: string): void {\n if (!TXID_RE.test(txid)) {\n throw new Error(`Invalid transaction ID format: ${txid}`);\n }\n}\n\nfunction assertValidAddress(address: string): void {\n if (!BITCOIN_ADDRESS_RE.test(address)) {\n throw new Error(`Invalid Bitcoin address format: ${address}`);\n }\n}\n\nfunction assertValidScriptPubKey(scriptPubKey: string, context: string): void {\n if (!HEX_RE.test(scriptPubKey)) {\n throw new Error(\n `Invalid scriptPubKey: not valid hex for ${context}`,\n );\n }\n const matchesKnownType = KNOWN_SCRIPT_PREFIXES.some((prefix) =>\n scriptPubKey.toLowerCase().startsWith(prefix),\n );\n if (!matchesKnownType) {\n throw new Error(\n `Unrecognized scriptPubKey type for ${context}: ` +\n `prefix ${scriptPubKey.slice(0, 6)} does not match any known Bitcoin script type`,\n );\n }\n}\n\n/**\n * Default mempool API URLs by network.\n */\nexport const MEMPOOL_API_URLS = {\n mainnet: \"https://mempool.space/api\",\n testnet: \"https://mempool.space/testnet/api\",\n signet: \"https://mempool.space/signet/api\",\n} as const;\n\n/**\n * Fetch wrapper with error handling.\n */\nasync function fetchApi<T>(\n url: string,\n options?: RequestInit,\n): Promise<T> {\n try {\n const response = await fetchWithTimeout(url, options);\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(\n `Mempool API error (${response.status}): ${errorText || response.statusText}`,\n );\n }\n\n const contentType = response.headers.get(\"content-type\");\n if (contentType?.includes(\"application/json\")) {\n return (await response.json()) as T;\n } else {\n return (await response.text()) as T;\n }\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(`Failed to fetch from mempool API: ${error.message}`);\n }\n throw new Error(\"Failed to fetch from mempool API: Unknown error\");\n }\n}\n\n/**\n * Push a signed transaction to the Bitcoin network.\n *\n * @param txHex - The signed transaction hex string\n * @param apiUrl - Mempool API base URL\n * @returns The transaction ID\n * @throws Error if broadcasting fails\n */\nexport async function pushTx(txHex: string, apiUrl: string): Promise<string> {\n try {\n const response = await fetchWithTimeout(`${apiUrl}/tx`, {\n method: \"POST\",\n body: txHex,\n headers: {\n \"Content-Type\": \"text/plain\",\n },\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n // Try to extract error message from response using robust JSON parsing\n let message: string | undefined;\n try {\n const errorJson = JSON.parse(errorText);\n message = errorJson.message;\n } catch {\n // Not JSON, use raw text\n message = errorText;\n }\n throw new Error(\n message || `Failed to broadcast transaction: ${response.statusText}`,\n );\n }\n\n // Response is the transaction ID (plain text)\n const txId = await response.text();\n return txId;\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(`Failed to broadcast BTC transaction: ${error.message}`);\n }\n throw new Error(\"Failed to broadcast BTC transaction: Unknown error\");\n }\n}\n\n/**\n * Get transaction information from mempool.\n *\n * @param txid - The transaction ID\n * @param apiUrl - Mempool API base URL\n * @returns Transaction information\n */\nexport async function getTxInfo(txid: string, apiUrl: string): Promise<TxInfo> {\n assertValidTxid(txid);\n return fetchApi<TxInfo>(`${apiUrl}/tx/${txid}`);\n}\n\n/**\n * Get the current block tip height.\n *\n * Source: mempool.space API — `GET /api/blocks/tip/height` returns the height\n * of the most recent block as a plain-text integer.\n *\n * @param apiUrl - Mempool API base URL\n * @returns The height of the most recent block\n * @throws Error if the response is not a whole number\n */\nexport async function getTipHeight(apiUrl: string): Promise<number> {\n const raw = await fetchApi<string>(`${apiUrl}/blocks/tip/height`);\n const trimmed = raw.trim();\n if (!/^\\d+$/.test(trimmed)) {\n throw new Error(\n `Mempool API returned an invalid block tip height: \"${raw}\"`,\n );\n }\n return Number.parseInt(trimmed, 10);\n}\n\n/**\n * Get the hex representation of a transaction.\n *\n * @param txid - The transaction ID\n * @param apiUrl - Mempool API base URL\n * @returns The transaction hex string\n * @throws Error if the request fails or transaction is not found\n */\nexport async function getTxHex(txid: string, apiUrl: string): Promise<string> {\n assertValidTxid(txid);\n try {\n const response = await fetchWithTimeout(`${apiUrl}/tx/${txid}/hex`);\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(\n `Mempool API error (${response.status}): ${errorText || response.statusText}`,\n );\n }\n\n return await response.text();\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(`Failed to get transaction hex for ${txid}: ${error.message}`);\n }\n throw new Error(`Failed to get transaction hex for ${txid}: Unknown error`);\n }\n}\n\n/**\n * Get UTXO information for a specific transaction output.\n *\n * This is used for constructing PSBTs where we need the witnessUtxo data.\n * Only supports Taproot (P2TR) and native SegWit (P2WPKH, P2WSH) script types.\n *\n * @param txid - The transaction ID containing the UTXO\n * @param vout - The output index\n * @param apiUrl - Mempool API base URL\n * @returns UTXO information with value and scriptPubKey\n */\nexport async function getUtxoInfo(\n txid: string,\n vout: number,\n apiUrl: string,\n): Promise<UtxoInfo> {\n assertValidTxid(txid);\n const txInfo = await getTxInfo(txid, apiUrl);\n\n if (!isValidVout(vout, txInfo.vout.length)) {\n throw new Error(\n `Invalid vout ${vout} for transaction ${txid} (has ${txInfo.vout.length} outputs)`,\n );\n }\n\n const output = txInfo.vout[vout];\n if (!isValidSatoshiValue(output.value)) {\n throw new Error(`Invalid UTXO value ${output.value} for ${txid}:${vout}`);\n }\n assertValidScriptPubKey(output.scriptpubkey, `${txid}:${vout}`);\n\n return {\n txid,\n vout,\n value: output.value,\n scriptPubKey: output.scriptpubkey,\n };\n}\n\n/**\n * Get all UTXOs for a Bitcoin address.\n *\n * @param address - The Bitcoin address\n * @param apiUrl - Mempool API base URL\n * @returns Array of UTXOs sorted by value (largest first)\n */\nexport async function getAddressUtxos(\n address: string,\n apiUrl: string,\n): Promise<MempoolUTXO[]> {\n assertValidAddress(address);\n try {\n // Fetch UTXOs for the address\n const utxos = await fetchApi<\n {\n txid: string;\n vout: number;\n value: number;\n status: {\n confirmed: boolean;\n };\n }[]\n >(`${apiUrl}/address/${address}/utxo`);\n\n // Fetch scriptPubKey for the address\n const addressInfo = await fetchApi<{\n isvalid: boolean;\n scriptPubKey: string;\n }>(`${apiUrl}/v1/validate-address/${address}`);\n\n if (!addressInfo.isvalid) {\n throw new Error(\n `Invalid Bitcoin address: ${address}. Mempool API validation failed.`,\n );\n }\n assertValidScriptPubKey(addressInfo.scriptPubKey, address);\n\n // Validate UTXO fields from the listing endpoint.\n // Per-UTXO cross-verification against /tx/{txid} is intentionally NOT done\n // here — it would be expensive (N API calls) and redundant: the broadcast\n // path already verifies each selected input via getUtxoInfo before signing.\n // Both endpoints come from the same mempool API, so cross-checking one\n // against the other on the same server does not add real security.\n for (const utxo of utxos) {\n assertValidTxid(utxo.txid);\n if (!isValidVout(utxo.vout)) {\n throw new Error(`Invalid vout ${utxo.vout} for ${utxo.txid}`);\n }\n if (!isValidSatoshiValue(utxo.value)) {\n throw new Error(\n `Invalid UTXO value ${utxo.value} for ${utxo.txid}:${utxo.vout}`,\n );\n }\n }\n\n // Sort by value (largest first) and map to our UTXO format\n const sortedUTXOs = utxos.sort((a, b) => b.value - a.value);\n\n return sortedUTXOs.map((utxo) => ({\n txid: utxo.txid,\n vout: utxo.vout,\n value: utxo.value,\n scriptPubKey: addressInfo.scriptPubKey,\n confirmed: utxo.status.confirmed,\n }));\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(\n `Failed to get UTXOs for address ${address}: ${error.message}`,\n );\n }\n throw new Error(\n `Failed to get UTXOs for address ${address}: Unknown error`,\n );\n }\n}\n\n/**\n * Get the mempool API URL for a given network.\n *\n * @param network - Bitcoin network (mainnet, testnet, signet)\n * @returns The mempool API URL\n */\nexport function getMempoolApiUrl(\n network: \"mainnet\" | \"testnet\" | \"signet\",\n): string {\n return MEMPOOL_API_URLS[network];\n}\n\n/**\n * Transaction summary from address transactions endpoint.\n */\nexport interface AddressTx {\n txid: string;\n status: {\n confirmed: boolean;\n block_height?: number;\n };\n}\n\n/**\n * Get recent transactions for a Bitcoin address.\n *\n * Returns the last 25 confirmed transactions plus any unconfirmed (mempool) transactions.\n * This is useful for checking if a specific transaction has been broadcast.\n *\n * @param address - The Bitcoin address\n * @param apiUrl - Mempool API base URL\n * @returns Array of recent transactions\n */\nexport async function getAddressTxs(\n address: string,\n apiUrl: string,\n): Promise<AddressTx[]> {\n assertValidAddress(address);\n return fetchApi<AddressTx[]>(`${apiUrl}/address/${address}/txs`);\n}\n\n/**\n * Fetches Bitcoin network fee recommendations from mempool.space API.\n *\n * @param apiUrl - Mempool API base URL\n * @returns Fee rates in sat/vbyte for different confirmation times\n * @throws Error if request fails or returns invalid data\n *\n * @see https://mempool.space/docs/api/rest#get-recommended-fees\n */\nexport async function getNetworkFees(apiUrl: string): Promise<NetworkFees> {\n const response = await fetchWithTimeout(`${apiUrl}/v1/fees/recommended`);\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch network fees: ${response.status} ${response.statusText}`,\n );\n }\n\n const data = await response.json();\n\n const feeFields = [\n \"fastestFee\",\n \"halfHourFee\",\n \"hourFee\",\n \"economyFee\",\n \"minimumFee\",\n ] as const;\n\n for (const field of feeFields) {\n if (!isValidFeeRate(data[field])) {\n throw new Error(\n `Invalid fee rate ${field}=${data[field]} from mempool API: expected a positive number ≤ ${MAX_FEE_RATE}`,\n );\n }\n }\n\n if (\n data.minimumFee > data.economyFee ||\n data.economyFee > data.hourFee ||\n data.hourFee > data.halfHourFee ||\n data.halfHourFee > data.fastestFee\n ) {\n throw new Error(\n `Fee rate ordering violation from mempool API: expected ` +\n `minimumFee (${data.minimumFee}) <= economyFee (${data.economyFee}) <= ` +\n `hourFee (${data.hourFee}) <= halfHourFee (${data.halfHourFee}) <= ` +\n `fastestFee (${data.fastestFee}).`,\n );\n }\n\n return data as NetworkFees;\n}\n\n"],"names":["MAX_SATOSHIS","MEMPOOL_REQUEST_TIMEOUT_MS","fetchWithTimeout","url","options","controller","timeoutId","signals","error","MAX_FEE_RATE","isValidSatoshiValue","value","isValidFeeRate","isValidVout","vout","outputCount","assertValidTxid","txid","TXID_RE","assertValidAddress","address","BITCOIN_ADDRESS_RE","assertValidScriptPubKey","scriptPubKey","context","HEX_RE","KNOWN_SCRIPT_PREFIXES","prefix","MEMPOOL_API_URLS","fetchApi","response","errorText","contentType","pushTx","txHex","apiUrl","message","getTxInfo","getTipHeight","raw","trimmed","getTxHex","getUtxoInfo","txInfo","output","getAddressUtxos","utxos","addressInfo","utxo","a","b","getMempoolApiUrl","network","getAddressTxs","getNetworkFees","data","feeFields","field"],"mappings":";AAmBA,MAAMA,IAAe,OAAa,KAG5BC,IAA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BACrDA,EAAK,OAAO,qBAAqBA,EAAK,WAAW,oBAC9CA,EAAK,UAAU;AAAA,IAAA;AAIpC,SAAOA;AACT;"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const i=require("./validation-u8W7Lp2x.cjs"),g=21e6*1e8,l=3e4;async function c(e,r){const t=new AbortController,n=setTimeout(()=>t.abort(),l),s=[t.signal,r==null?void 0:r.signal].filter(Boolean);try{return await fetch(e,{...r,signal:AbortSignal.any(s)})}catch(o){throw clearTimeout(n),o!=null&&typeof o=="object"&&"name"in o&&o.name==="AbortError"?new Error(`Mempool API request timed out after ${l}ms: ${e}`):o}}const w=1e4;function m(e){return Number.isInteger(e)&&e>0&&e<=g}function I(e){return Number.isInteger(e)&&e>0&&e<=w}function h(e,r){return!Number.isInteger(e)||e<0?!1:r===void 0||e<r}function f(e){if(!i.TXID_RE.test(e))throw new Error(`Invalid transaction ID format: ${e}`)}function d(e){if(!i.BITCOIN_ADDRESS_RE.test(e))throw new Error(`Invalid Bitcoin address format: ${e}`)}function $(e,r){if(!i.HEX_RE.test(e))throw new Error(`Invalid scriptPubKey: not valid hex for ${r}`);if(!i.KNOWN_SCRIPT_PREFIXES.some(n=>e.toLowerCase().startsWith(n)))throw new Error(`Unrecognized scriptPubKey type for ${r}: prefix ${e.slice(0,6)} does not match any known Bitcoin script type`)}const p={mainnet:"https://mempool.space/api",testnet:"https://mempool.space/testnet/api",signet:"https://mempool.space/signet/api"};async function a(e,r){try{const t=await c(e,r);if(!t.ok){const s=await t.text();throw new Error(`Mempool API error (${t.status}): ${s||t.statusText}`)}const n=t.headers.get("content-type");return n!=null&&n.includes("application/json")?await t.json():await t.text()}catch(t){throw t instanceof Error?new Error(`Failed to fetch from mempool API: ${t.message}`):new Error("Failed to fetch from mempool API: Unknown error")}}async function F(e,r){try{const t=await c(`${r}/tx`,{method:"POST",body:e,headers:{"Content-Type":"text/plain"}});if(!t.ok){const s=await t.text();let o;try{o=JSON.parse(s).message}catch{o=s}throw new Error(o||`Failed to broadcast transaction: ${t.statusText}`)}return await t.text()}catch(t){throw t instanceof Error?new Error(`Failed to broadcast BTC transaction: ${t.message}`):new Error("Failed to broadcast BTC transaction: Unknown error")}}async function E(e,r){return f(e),a(`${r}/tx/${e}`)}async function T(e){const r=await a(`${e}/blocks/tip/height`),t=r.trim();if(!/^\d+$/.test(t))throw new Error(`Mempool API returned an invalid block tip height: "${r}"`);return Number.parseInt(t,10)}async function x(e,r){f(e);try{const t=await c(`${r}/tx/${e}/hex`);if(!t.ok){const n=await t.text();throw new Error(`Mempool API error (${t.status}): ${n||t.statusText}`)}return await t.text()}catch(t){throw t instanceof Error?new Error(`Failed to get transaction hex for ${e}: ${t.message}`):new Error(`Failed to get transaction hex for ${e}: Unknown error`)}}async function y(e,r,t){f(e);const n=await E(e,t);if(!h(r,n.vout.length))throw new Error(`Invalid vout ${r} for transaction ${e} (has ${n.vout.length} outputs)`);const s=n.vout[r];if(!m(s.value))throw new Error(`Invalid UTXO value ${s.value} for ${e}:${r}`);return $(s.scriptpubkey,`${e}:${r}`),{txid:e,vout:r,value:s.value,scriptPubKey:s.scriptpubkey}}async function v(e,r){d(e);try{const t=await a(`${r}/address/${e}/utxo`),n=await a(`${r}/v1/validate-address/${e}`);if(!n.isvalid)throw new Error(`Invalid Bitcoin address: ${e}. Mempool API validation failed.`);$(n.scriptPubKey,e);for(const o of t){if(f(o.txid),!h(o.vout))throw new Error(`Invalid vout ${o.vout} for ${o.txid}`);if(!m(o.value))throw new Error(`Invalid UTXO value ${o.value} for ${o.txid}:${o.vout}`)}return t.sort((o,u)=>u.value-o.value).map(o=>({txid:o.txid,vout:o.vout,value:o.value,scriptPubKey:n.scriptPubKey,confirmed:o.status.confirmed}))}catch(t){throw t instanceof Error?new Error(`Failed to get UTXOs for address ${e}: ${t.message}`):new Error(`Failed to get UTXOs for address ${e}: Unknown error`)}}function A(e){return p[e]}async function b(e,r){return d(e),a(`${r}/address/${e}/txs`)}async function P(e){const r=await c(`${e}/v1/fees/recommended`);if(!r.ok)throw new Error(`Failed to fetch network fees: ${r.status} ${r.statusText}`);const t=await r.json(),n=["fastestFee","halfHourFee","hourFee","economyFee","minimumFee"];for(const s of n)if(!I(t[s]))throw new Error(`Invalid fee rate ${s}=${t[s]} from mempool API: expected a positive number ≤ ${w}`);if(t.minimumFee>t.economyFee||t.economyFee>t.hourFee||t.hourFee>t.halfHourFee||t.halfHourFee>t.fastestFee)throw new Error(`Fee rate ordering violation from mempool API: expected minimumFee (${t.minimumFee}) <= economyFee (${t.economyFee}) <= hourFee (${t.hourFee}) <= halfHourFee (${t.halfHourFee}) <= fastestFee (${t.fastestFee}).`);return t}exports.MEMPOOL_API_URLS=p;exports.getAddressTxs=b;exports.getAddressUtxos=v;exports.getMempoolApiUrl=A;exports.getNetworkFees=P;exports.getTipHeight=T;exports.getTxHex=x;exports.getTxInfo=E;exports.getUtxoInfo=y;exports.pushTx=F;
|
|
2
|
-
//# sourceMappingURL=mempoolApi-DEAS9wVa.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mempoolApi-DEAS9wVa.cjs","sources":["../src/tbv/core/clients/mempool/mempoolApi.ts"],"sourcesContent":["/**\n * Mempool API Client\n *\n * Client for interacting with mempool.space API for Bitcoin network operations.\n * Used for broadcasting transactions and fetching UTXO data.\n *\n * @module clients/mempool/mempoolApi\n */\n\nimport {\n BITCOIN_ADDRESS_RE,\n HEX_RE,\n KNOWN_SCRIPT_PREFIXES,\n TXID_RE,\n} from \"../../utils/validation\";\n\nimport type { MempoolUTXO, NetworkFees, TxInfo, UtxoInfo } from \"./types\";\n\n/** Maximum valid satoshi value: 21 million BTC × 10^8 sats/BTC */\nconst MAX_SATOSHIS = 21_000_000 * 1e8;\n\n/** Timeout for mempool API requests — prevents indefinite hangs from stalled endpoints */\nconst MEMPOOL_REQUEST_TIMEOUT_MS = 30_000;\n\n/**\n * Fetch wrapper with AbortController-based timeout.\n * Ensures all mempool API requests fail bounded rather than hanging indefinitely.\n */\nasync function fetchWithTimeout(\n url: string,\n options?: RequestInit,\n): Promise<Response> {\n const controller = new AbortController();\n const timeoutId = setTimeout(\n () => controller.abort(),\n MEMPOOL_REQUEST_TIMEOUT_MS,\n );\n\n // Compose timeout signal with any caller-supplied signal so both can cancel\n const signals = [controller.signal, options?.signal].filter(\n Boolean,\n ) as AbortSignal[];\n\n try {\n // Don't clear timeout here — let it cover body consumption by callers\n return await fetch(url, {\n ...options,\n signal: AbortSignal.any(signals),\n });\n } catch (error) {\n clearTimeout(timeoutId);\n if (\n error != null &&\n typeof error === \"object\" &&\n \"name\" in error &&\n error.name === \"AbortError\"\n ) {\n throw new Error(\n `Mempool API request timed out after ${MEMPOOL_REQUEST_TIMEOUT_MS}ms: ${url}`,\n );\n }\n throw error;\n }\n}\n\n/**\n * Maximum sane fee rate in sat/vByte.\n * The April 2024 Runes spike peaked around 1,805 sat/vB — 10,000 provides ample headroom.\n */\nconst MAX_FEE_RATE = 10_000;\n\nfunction isValidSatoshiValue(value: number): boolean {\n return Number.isInteger(value) && value > 0 && value <= MAX_SATOSHIS;\n}\n\nfunction isValidFeeRate(value: number): boolean {\n return Number.isInteger(value) && value > 0 && value <= MAX_FEE_RATE;\n}\n\nfunction isValidVout(vout: number, outputCount?: number): boolean {\n if (!Number.isInteger(vout) || vout < 0) return false;\n return outputCount === undefined || vout < outputCount;\n}\n\n\nfunction assertValidTxid(txid: string): void {\n if (!TXID_RE.test(txid)) {\n throw new Error(`Invalid transaction ID format: ${txid}`);\n }\n}\n\nfunction assertValidAddress(address: string): void {\n if (!BITCOIN_ADDRESS_RE.test(address)) {\n throw new Error(`Invalid Bitcoin address format: ${address}`);\n }\n}\n\nfunction assertValidScriptPubKey(scriptPubKey: string, context: string): void {\n if (!HEX_RE.test(scriptPubKey)) {\n throw new Error(\n `Invalid scriptPubKey: not valid hex for ${context}`,\n );\n }\n const matchesKnownType = KNOWN_SCRIPT_PREFIXES.some((prefix) =>\n scriptPubKey.toLowerCase().startsWith(prefix),\n );\n if (!matchesKnownType) {\n throw new Error(\n `Unrecognized scriptPubKey type for ${context}: ` +\n `prefix ${scriptPubKey.slice(0, 6)} does not match any known Bitcoin script type`,\n );\n }\n}\n\n/**\n * Default mempool API URLs by network.\n */\nexport const MEMPOOL_API_URLS = {\n mainnet: \"https://mempool.space/api\",\n testnet: \"https://mempool.space/testnet/api\",\n signet: \"https://mempool.space/signet/api\",\n} as const;\n\n/**\n * Fetch wrapper with error handling.\n */\nasync function fetchApi<T>(\n url: string,\n options?: RequestInit,\n): Promise<T> {\n try {\n const response = await fetchWithTimeout(url, options);\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(\n `Mempool API error (${response.status}): ${errorText || response.statusText}`,\n );\n }\n\n const contentType = response.headers.get(\"content-type\");\n if (contentType?.includes(\"application/json\")) {\n return (await response.json()) as T;\n } else {\n return (await response.text()) as T;\n }\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(`Failed to fetch from mempool API: ${error.message}`);\n }\n throw new Error(\"Failed to fetch from mempool API: Unknown error\");\n }\n}\n\n/**\n * Push a signed transaction to the Bitcoin network.\n *\n * @param txHex - The signed transaction hex string\n * @param apiUrl - Mempool API base URL\n * @returns The transaction ID\n * @throws Error if broadcasting fails\n */\nexport async function pushTx(txHex: string, apiUrl: string): Promise<string> {\n try {\n const response = await fetchWithTimeout(`${apiUrl}/tx`, {\n method: \"POST\",\n body: txHex,\n headers: {\n \"Content-Type\": \"text/plain\",\n },\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n // Try to extract error message from response using robust JSON parsing\n let message: string | undefined;\n try {\n const errorJson = JSON.parse(errorText);\n message = errorJson.message;\n } catch {\n // Not JSON, use raw text\n message = errorText;\n }\n throw new Error(\n message || `Failed to broadcast transaction: ${response.statusText}`,\n );\n }\n\n // Response is the transaction ID (plain text)\n const txId = await response.text();\n return txId;\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(`Failed to broadcast BTC transaction: ${error.message}`);\n }\n throw new Error(\"Failed to broadcast BTC transaction: Unknown error\");\n }\n}\n\n/**\n * Get transaction information from mempool.\n *\n * @param txid - The transaction ID\n * @param apiUrl - Mempool API base URL\n * @returns Transaction information\n */\nexport async function getTxInfo(txid: string, apiUrl: string): Promise<TxInfo> {\n assertValidTxid(txid);\n return fetchApi<TxInfo>(`${apiUrl}/tx/${txid}`);\n}\n\n/**\n * Get the current block tip height.\n *\n * Source: mempool.space API — `GET /api/blocks/tip/height` returns the height\n * of the most recent block as a plain-text integer.\n *\n * @param apiUrl - Mempool API base URL\n * @returns The height of the most recent block\n * @throws Error if the response is not a whole number\n */\nexport async function getTipHeight(apiUrl: string): Promise<number> {\n const raw = await fetchApi<string>(`${apiUrl}/blocks/tip/height`);\n const trimmed = raw.trim();\n if (!/^\\d+$/.test(trimmed)) {\n throw new Error(\n `Mempool API returned an invalid block tip height: \"${raw}\"`,\n );\n }\n return Number.parseInt(trimmed, 10);\n}\n\n/**\n * Get the hex representation of a transaction.\n *\n * @param txid - The transaction ID\n * @param apiUrl - Mempool API base URL\n * @returns The transaction hex string\n * @throws Error if the request fails or transaction is not found\n */\nexport async function getTxHex(txid: string, apiUrl: string): Promise<string> {\n assertValidTxid(txid);\n try {\n const response = await fetchWithTimeout(`${apiUrl}/tx/${txid}/hex`);\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(\n `Mempool API error (${response.status}): ${errorText || response.statusText}`,\n );\n }\n\n return await response.text();\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(`Failed to get transaction hex for ${txid}: ${error.message}`);\n }\n throw new Error(`Failed to get transaction hex for ${txid}: Unknown error`);\n }\n}\n\n/**\n * Get UTXO information for a specific transaction output.\n *\n * This is used for constructing PSBTs where we need the witnessUtxo data.\n * Only supports Taproot (P2TR) and native SegWit (P2WPKH, P2WSH) script types.\n *\n * @param txid - The transaction ID containing the UTXO\n * @param vout - The output index\n * @param apiUrl - Mempool API base URL\n * @returns UTXO information with value and scriptPubKey\n */\nexport async function getUtxoInfo(\n txid: string,\n vout: number,\n apiUrl: string,\n): Promise<UtxoInfo> {\n assertValidTxid(txid);\n const txInfo = await getTxInfo(txid, apiUrl);\n\n if (!isValidVout(vout, txInfo.vout.length)) {\n throw new Error(\n `Invalid vout ${vout} for transaction ${txid} (has ${txInfo.vout.length} outputs)`,\n );\n }\n\n const output = txInfo.vout[vout];\n if (!isValidSatoshiValue(output.value)) {\n throw new Error(`Invalid UTXO value ${output.value} for ${txid}:${vout}`);\n }\n assertValidScriptPubKey(output.scriptpubkey, `${txid}:${vout}`);\n\n return {\n txid,\n vout,\n value: output.value,\n scriptPubKey: output.scriptpubkey,\n };\n}\n\n/**\n * Get all UTXOs for a Bitcoin address.\n *\n * @param address - The Bitcoin address\n * @param apiUrl - Mempool API base URL\n * @returns Array of UTXOs sorted by value (largest first)\n */\nexport async function getAddressUtxos(\n address: string,\n apiUrl: string,\n): Promise<MempoolUTXO[]> {\n assertValidAddress(address);\n try {\n // Fetch UTXOs for the address\n const utxos = await fetchApi<\n {\n txid: string;\n vout: number;\n value: number;\n status: {\n confirmed: boolean;\n };\n }[]\n >(`${apiUrl}/address/${address}/utxo`);\n\n // Fetch scriptPubKey for the address\n const addressInfo = await fetchApi<{\n isvalid: boolean;\n scriptPubKey: string;\n }>(`${apiUrl}/v1/validate-address/${address}`);\n\n if (!addressInfo.isvalid) {\n throw new Error(\n `Invalid Bitcoin address: ${address}. Mempool API validation failed.`,\n );\n }\n assertValidScriptPubKey(addressInfo.scriptPubKey, address);\n\n // Validate UTXO fields from the listing endpoint.\n // Per-UTXO cross-verification against /tx/{txid} is intentionally NOT done\n // here — it would be expensive (N API calls) and redundant: the broadcast\n // path already verifies each selected input via getUtxoInfo before signing.\n // Both endpoints come from the same mempool API, so cross-checking one\n // against the other on the same server does not add real security.\n for (const utxo of utxos) {\n assertValidTxid(utxo.txid);\n if (!isValidVout(utxo.vout)) {\n throw new Error(`Invalid vout ${utxo.vout} for ${utxo.txid}`);\n }\n if (!isValidSatoshiValue(utxo.value)) {\n throw new Error(\n `Invalid UTXO value ${utxo.value} for ${utxo.txid}:${utxo.vout}`,\n );\n }\n }\n\n // Sort by value (largest first) and map to our UTXO format\n const sortedUTXOs = utxos.sort((a, b) => b.value - a.value);\n\n return sortedUTXOs.map((utxo) => ({\n txid: utxo.txid,\n vout: utxo.vout,\n value: utxo.value,\n scriptPubKey: addressInfo.scriptPubKey,\n confirmed: utxo.status.confirmed,\n }));\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(\n `Failed to get UTXOs for address ${address}: ${error.message}`,\n );\n }\n throw new Error(\n `Failed to get UTXOs for address ${address}: Unknown error`,\n );\n }\n}\n\n/**\n * Get the mempool API URL for a given network.\n *\n * @param network - Bitcoin network (mainnet, testnet, signet)\n * @returns The mempool API URL\n */\nexport function getMempoolApiUrl(\n network: \"mainnet\" | \"testnet\" | \"signet\",\n): string {\n return MEMPOOL_API_URLS[network];\n}\n\n/**\n * Transaction summary from address transactions endpoint.\n */\nexport interface AddressTx {\n txid: string;\n status: {\n confirmed: boolean;\n block_height?: number;\n };\n}\n\n/**\n * Get recent transactions for a Bitcoin address.\n *\n * Returns the last 25 confirmed transactions plus any unconfirmed (mempool) transactions.\n * This is useful for checking if a specific transaction has been broadcast.\n *\n * @param address - The Bitcoin address\n * @param apiUrl - Mempool API base URL\n * @returns Array of recent transactions\n */\nexport async function getAddressTxs(\n address: string,\n apiUrl: string,\n): Promise<AddressTx[]> {\n assertValidAddress(address);\n return fetchApi<AddressTx[]>(`${apiUrl}/address/${address}/txs`);\n}\n\n/**\n * Fetches Bitcoin network fee recommendations from mempool.space API.\n *\n * @param apiUrl - Mempool API base URL\n * @returns Fee rates in sat/vbyte for different confirmation times\n * @throws Error if request fails or returns invalid data\n *\n * @see https://mempool.space/docs/api/rest#get-recommended-fees\n */\nexport async function getNetworkFees(apiUrl: string): Promise<NetworkFees> {\n const response = await fetchWithTimeout(`${apiUrl}/v1/fees/recommended`);\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch network fees: ${response.status} ${response.statusText}`,\n );\n }\n\n const data = await response.json();\n\n const feeFields = [\n \"fastestFee\",\n \"halfHourFee\",\n \"hourFee\",\n \"economyFee\",\n \"minimumFee\",\n ] as const;\n\n for (const field of feeFields) {\n if (!isValidFeeRate(data[field])) {\n throw new Error(\n `Invalid fee rate ${field}=${data[field]} from mempool API: expected a positive number ≤ ${MAX_FEE_RATE}`,\n );\n }\n }\n\n if (\n data.minimumFee > data.economyFee ||\n data.economyFee > data.hourFee ||\n data.hourFee > data.halfHourFee ||\n data.halfHourFee > data.fastestFee\n ) {\n throw new Error(\n `Fee rate ordering violation from mempool API: expected ` +\n `minimumFee (${data.minimumFee}) <= economyFee (${data.economyFee}) <= ` +\n `hourFee (${data.hourFee}) <= halfHourFee (${data.halfHourFee}) <= ` +\n `fastestFee (${data.fastestFee}).`,\n );\n }\n\n return data as NetworkFees;\n}\n\n"],"names":["MAX_SATOSHIS","MEMPOOL_REQUEST_TIMEOUT_MS","fetchWithTimeout","url","options","controller","timeoutId","signals","error","MAX_FEE_RATE","isValidSatoshiValue","value","isValidFeeRate","isValidVout","vout","outputCount","assertValidTxid","txid","TXID_RE","assertValidAddress","address","BITCOIN_ADDRESS_RE","assertValidScriptPubKey","scriptPubKey","context","HEX_RE","KNOWN_SCRIPT_PREFIXES","prefix","MEMPOOL_API_URLS","fetchApi","response","errorText","contentType","pushTx","txHex","apiUrl","message","getTxInfo","getTipHeight","raw","trimmed","getTxHex","getUtxoInfo","txInfo","output","getAddressUtxos","utxos","addressInfo","utxo","a","b","getMempoolApiUrl","network","getAddressTxs","getNetworkFees","data","feeFields","field"],"mappings":"0DAmBMA,EAAe,KAAa,IAG5BC,EAA6B,IAMnC,eAAeC,EACbC,EACAC,EACmB,CACnB,MAAMC,EAAa,IAAI,gBACjBC,EAAY,WAChB,IAAMD,EAAW,MAAA,EACjBJ,CAAA,EAIIM,EAAU,CAACF,EAAW,OAAQD,GAAA,YAAAA,EAAS,MAA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