@anywalletkit/wallet-btc 0.0.0-stage → 0.2.1
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/LICENSE +202 -0
- package/README.md +100 -2
- package/dist/chunk-KAAQYL5X.js +318 -0
- package/dist/chunk-KAAQYL5X.js.map +1 -0
- package/dist/history-B5fmsCjZ.d.cts +338 -0
- package/dist/history-B5fmsCjZ.d.ts +338 -0
- package/dist/history.cjs +332 -0
- package/dist/history.cjs.map +1 -0
- package/dist/history.d.cts +2 -0
- package/dist/history.d.ts +2 -0
- package/dist/history.js +17 -0
- package/dist/history.js.map +1 -0
- package/dist/index.cjs +1275 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +405 -0
- package/dist/index.d.ts +405 -0
- package/dist/index.js +966 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
import { B as BtcClient, U as Utxo, a as BlockbookTx, b as BtcConfig, c as BtcTxDescription, d as BtcAddressType, e as BtcNetwork, f as BtcSpend, g as BtcTransferOptions, h as BtcMaxSpendableResult, i as BtcReceipt, j as BtcTransaction } from './history-B5fmsCjZ.js';
|
|
2
|
+
export { k as BlockbookAddressPage, l as BlockbookClient, m as BlockbookTxDetails, n as BlockbookVin, o as BlockbookVout, p as BtcChainTx, q as BtcClientConfig, r as BtcHistoryCursor, s as BtcHistoryOptions, t as BtcHistoryPage, u as BtcHistoryRaw, v as BtcHistorySource, w as BtcTxInputDescription, x as BtcTxOutputDescription, y as BtcWarning, C as CAIP2_GENESIS, H as HistoryUnavailableError, z as btcExplorerTxUrl, A as createBtcHistory, D as decodeHistoryCursor, E as encodeHistoryCursor, F as mapBlockbookTx, G as unconfirmedOutgoing } from './history-B5fmsCjZ.js';
|
|
3
|
+
import { Signer, IWalletAccountReadOnly, IWalletAccount, TransferResult, WalletManager, FeeRates } from '@anywalletkit/core';
|
|
4
|
+
import { Transaction } from '@scure/btc-signer';
|
|
5
|
+
import { BTC_NETWORK } from '@scure/btc-signer/utils.js';
|
|
6
|
+
|
|
7
|
+
/** Why a spend was refused before signing. */
|
|
8
|
+
type UnsafeTransactionCode =
|
|
9
|
+
/** Fee rate above `maxFeeRate`. */
|
|
10
|
+
'fee-rate-too-high'
|
|
11
|
+
/** An output that is neither the requested recipient/amount nor our change. */
|
|
12
|
+
| 'unexpected-output'
|
|
13
|
+
/** The recipient output is missing or carries a different amount. */
|
|
14
|
+
| 'recipient-mismatch'
|
|
15
|
+
/** A change output pays an address that is not ours. */
|
|
16
|
+
| 'change-not-ours'
|
|
17
|
+
/** A coin the indexer reported does not match its previous transaction (txid, amount or script). */
|
|
18
|
+
| 'prevout-mismatch';
|
|
19
|
+
/** A transaction failed a hard safety check and was not signed / broadcast. */
|
|
20
|
+
declare class UnsafeTransactionError extends Error {
|
|
21
|
+
readonly code: UnsafeTransactionCode;
|
|
22
|
+
constructor(code: UnsafeTransactionCode, message: string);
|
|
23
|
+
}
|
|
24
|
+
/** Coin selection would need more inputs than `maxInputs` allows. */
|
|
25
|
+
declare class TooManyInputsError extends Error {
|
|
26
|
+
readonly maxInputs: number;
|
|
27
|
+
constructor(maxInputs: number);
|
|
28
|
+
}
|
|
29
|
+
/** BIP-137 message signatures only exist for p2pkh/p2wpkh keys; taproot accounts have none (BIP-322 is not implemented). */
|
|
30
|
+
declare class UnsupportedAddressTypeError extends Error {
|
|
31
|
+
constructor(message: string);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Esplora REST transport — the API served by mempool.space (`https://mempool.space/api`)
|
|
36
|
+
* and Blockstream (`https://blockstream.info/api`). Public instances exist, so it is
|
|
37
|
+
* the natural fallback behind a self-hosted Blockbook.
|
|
38
|
+
*
|
|
39
|
+
* Balance semantics: `unconfirmedOutgoing` is the mempool net outflow
|
|
40
|
+
* (spent − funded, clamped at 0), a conservative stand-in for Bitcoin Core's
|
|
41
|
+
* trusted-change rule that Blockbook's richer address record allows.
|
|
42
|
+
*/
|
|
43
|
+
declare class EsploraClient implements BtcClient {
|
|
44
|
+
private readonly base;
|
|
45
|
+
private readonly fetchFn;
|
|
46
|
+
private readonly timeoutMs;
|
|
47
|
+
constructor(config: {
|
|
48
|
+
url: string;
|
|
49
|
+
}, fetchFn?: typeof fetch, timeoutMs?: number);
|
|
50
|
+
connect(): Promise<void>;
|
|
51
|
+
close(): Promise<void>;
|
|
52
|
+
private request;
|
|
53
|
+
private json;
|
|
54
|
+
private text;
|
|
55
|
+
getBalance(address: string): Promise<{
|
|
56
|
+
confirmed: bigint;
|
|
57
|
+
unconfirmed: bigint;
|
|
58
|
+
unconfirmedOutgoing: bigint;
|
|
59
|
+
}>;
|
|
60
|
+
listUnspent(address: string): Promise<Utxo[]>;
|
|
61
|
+
/** Esplora pages 25 (mempool.space: up to 50) txs per call; walk `/txs/chain/<last>` until a short page. */
|
|
62
|
+
getHistory(address: string): Promise<{
|
|
63
|
+
txid: string;
|
|
64
|
+
height: number;
|
|
65
|
+
}[]>;
|
|
66
|
+
getTransactionInfo(txid: string): Promise<BlockbookTx | undefined>;
|
|
67
|
+
getTransaction(txid: string): Promise<string>;
|
|
68
|
+
broadcast(rawTx: string): Promise<string>;
|
|
69
|
+
/** `/fee-estimates` → { "1": sat/vB, "2": …, "25": …, "144": … }; picks the nearest target ≥ `blocks`. */
|
|
70
|
+
estimateFee(blocks: number): Promise<number>;
|
|
71
|
+
getBlockHeight(): Promise<number>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** One client, or a failover client over the list: each call walks the list in order, `retries` extra rounds. */
|
|
75
|
+
declare function createClient(config: BtcConfig): BtcClient | undefined;
|
|
76
|
+
|
|
77
|
+
/** BIP-137 hash of a message (`Bitcoin Signed Message:` prefix, double SHA-256). */
|
|
78
|
+
declare function magicHash(message: string | Uint8Array): Uint8Array;
|
|
79
|
+
/** Address flavour a BIP-137 signature header is written for. */
|
|
80
|
+
type SegwitType = 'p2wpkh' | 'p2sh(p2wpkh)';
|
|
81
|
+
/** Encode `r‖s` + recovery id as a base64 BIP-137 signature. */
|
|
82
|
+
declare function encodeMessageSignature(rs: Uint8Array, recovery: number, segwitType?: SegwitType | undefined): string;
|
|
83
|
+
/** Sign with a raw private key (RFC-6979 deterministic, low-S). Kept for callers that hold a key outside a Signer. */
|
|
84
|
+
declare function signMessage(message: string | Uint8Array, privateKey: Uint8Array, segwitType?: SegwitType | undefined): string;
|
|
85
|
+
/** Sign through a {@link Signer} (`ecdsa-recoverable`, context `btc-message`). */
|
|
86
|
+
declare function signMessageWith(message: string | Uint8Array, signer: Signer, segwitType?: SegwitType | undefined): Promise<string>;
|
|
87
|
+
/** Recover the public key (compressed unless the header says otherwise) from a BIP-137 signature, or undefined when malformed. */
|
|
88
|
+
declare function recoverMessagePublicKey(message: string | Uint8Array, signature: string): {
|
|
89
|
+
publicKey: Uint8Array;
|
|
90
|
+
segwitType: SegwitType | undefined;
|
|
91
|
+
} | undefined;
|
|
92
|
+
|
|
93
|
+
/** Most inputs one spend may use; above it the account asks to consolidate first. */
|
|
94
|
+
declare const MAX_UTXO_INPUTS = 200;
|
|
95
|
+
/** An output the selection must fund. */
|
|
96
|
+
interface SelectionTarget {
|
|
97
|
+
value: bigint;
|
|
98
|
+
/** vbytes the output occupies (see `outputVBytes`). */
|
|
99
|
+
vbytes: number;
|
|
100
|
+
}
|
|
101
|
+
/** Input to {@link selectCoins}. */
|
|
102
|
+
interface CoinSelectOptions {
|
|
103
|
+
utxos: Utxo[];
|
|
104
|
+
targets: SelectionTarget[];
|
|
105
|
+
/** sat/vB, ≥ 1. */
|
|
106
|
+
feeRate: bigint;
|
|
107
|
+
/** Weight units one of our inputs adds (`INPUT_WEIGHT[addressType]`). */
|
|
108
|
+
inputWeight: number;
|
|
109
|
+
/** vbytes a change output to our own address occupies. */
|
|
110
|
+
changeVBytes: number;
|
|
111
|
+
/** Dust threshold for our change output type. */
|
|
112
|
+
changeDust: bigint;
|
|
113
|
+
maxInputs?: number;
|
|
114
|
+
}
|
|
115
|
+
/** UTXOs chosen for a spend, the fee and the change. */
|
|
116
|
+
interface CoinSelection {
|
|
117
|
+
utxos: Utxo[];
|
|
118
|
+
fee: bigint;
|
|
119
|
+
/** Change back to us; 0n when folded into the fee. */
|
|
120
|
+
change: bigint;
|
|
121
|
+
/** True when change existed but fell below dust and became fee. */
|
|
122
|
+
changeFolded: boolean;
|
|
123
|
+
/** Estimated vsize of the final transaction. */
|
|
124
|
+
vsize: number;
|
|
125
|
+
feeRate: bigint;
|
|
126
|
+
}
|
|
127
|
+
/** Virtual size (vB) of a segwit transaction with the given inputs and outputs. */
|
|
128
|
+
declare function estimateVsize(inputs: number, inputWeight: number, outputVBytes: number[]): number;
|
|
129
|
+
/** UTXOs worth spending at this fee rate, largest first. */
|
|
130
|
+
declare function spendableUtxos(utxos: Utxo[], feeRate: bigint, inputWeight: number): Utxo[];
|
|
131
|
+
/**
|
|
132
|
+
* Pick UTXOs to fund the targets at `feeRate` (sat/vB): change goes back when it is above dust,
|
|
133
|
+
* otherwise it joins the fee.
|
|
134
|
+
*
|
|
135
|
+
* @throws `InsufficientFundsError` (core) when the UTXOs cannot cover targets plus fee,
|
|
136
|
+
* `TooManyInputsError` above `maxInputs`, Error for a fee rate below 1 sat/vB.
|
|
137
|
+
*/
|
|
138
|
+
declare function selectCoins(o: CoinSelectOptions): CoinSelection;
|
|
139
|
+
/** Sweep: every spendable input (largest first, capped), one output, no change. */
|
|
140
|
+
declare function selectAll(o: Omit<CoinSelectOptions, 'targets' | 'changeVBytes' | 'changeDust'> & {
|
|
141
|
+
outputVBytes: number;
|
|
142
|
+
}): {
|
|
143
|
+
utxos: Utxo[];
|
|
144
|
+
fee: bigint;
|
|
145
|
+
amount: bigint;
|
|
146
|
+
vsize: number;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/** Default fee-rate ceiling, sat/vB; a spend above it is refused. */
|
|
150
|
+
declare const DEFAULT_MAX_FEE_RATE = 500;
|
|
151
|
+
/** Replace-by-fee signalling: any sequence below 0xfffffffe (BIP-125). */
|
|
152
|
+
declare const RBF_SEQUENCE = 4294967293;
|
|
153
|
+
/** Opts out of RBF while still letting nLockTime apply. */
|
|
154
|
+
declare const FINAL_SEQUENCE = 4294967294;
|
|
155
|
+
/** What a description needs to tell recipient, change and unknown outputs apart. */
|
|
156
|
+
interface DescribeContext {
|
|
157
|
+
network: BTC_NETWORK;
|
|
158
|
+
/** Our own address: outputs paying it are tagged `change`. */
|
|
159
|
+
ownAddress: string;
|
|
160
|
+
/** The spend the caller asked for. Outputs matching it are `recipient`; anything else is `unknown`. */
|
|
161
|
+
intended?: {
|
|
162
|
+
to: string;
|
|
163
|
+
value: bigint;
|
|
164
|
+
} | undefined;
|
|
165
|
+
maxFeeRate?: number | undefined;
|
|
166
|
+
}
|
|
167
|
+
/** Parse raw tx hex. Prevout amounts are not in the wire format — callers pass them in `inputValues`. */
|
|
168
|
+
declare function parseRawTransaction(rawHex: string): Transaction;
|
|
169
|
+
/**
|
|
170
|
+
* Describe a (signed or unsigned) btc-signer Transaction given the sat value of
|
|
171
|
+
* every input, in input order. Pure: no network, no signing.
|
|
172
|
+
*/
|
|
173
|
+
declare function describeTransaction(tx: Transaction, inputValues: bigint[], ctx: DescribeContext): BtcTxDescription;
|
|
174
|
+
/**
|
|
175
|
+
* Hard checks run before signing and before broadcasting. Throws UnsafeTransactionError;
|
|
176
|
+
* never mutates. With `intended`, exactly one output must be the requested
|
|
177
|
+
* recipient/amount and every other output must be our change.
|
|
178
|
+
*/
|
|
179
|
+
declare function assertSafe(desc: BtcTxDescription, ctx: DescribeContext): void;
|
|
180
|
+
|
|
181
|
+
/** Output-script families btc-signer recognises (`OutScript.decode(...).type`). */
|
|
182
|
+
type ScriptKind = 'pk' | 'pkh' | 'sh' | 'wsh' | 'wpkh' | 'ms' | 'tr' | 'tr_ns' | 'tr_ms' | 'p2a' | 'unknown';
|
|
183
|
+
/** An address decoded to its output script. */
|
|
184
|
+
interface DecodedAddress {
|
|
185
|
+
script: Uint8Array;
|
|
186
|
+
kind: ScriptKind;
|
|
187
|
+
}
|
|
188
|
+
/** Decode and validate an address for `network`; throws on a malformed address or a foreign network. */
|
|
189
|
+
declare function decodeAddress(address: string, network: BTC_NETWORK): DecodedAddress;
|
|
190
|
+
/** Address for an output script, or undefined when the script has no address form. */
|
|
191
|
+
declare function addressFromScript(script: Uint8Array, network: BTC_NETWORK): string | undefined;
|
|
192
|
+
/** Type of an output script; `unknown` when it cannot be decoded. */
|
|
193
|
+
declare function scriptKind(script: Uint8Array): ScriptKind;
|
|
194
|
+
/** Address of a compressed public key: p2wpkh (`bc1q…`) or p2tr key-path (`bc1p…`). */
|
|
195
|
+
declare function addressFromPublicKey(publicKey: Uint8Array, network: BTC_NETWORK, type?: BtcAddressType): string;
|
|
196
|
+
/** Weight units one of OUR inputs adds once signed (prevout 41 B × 4 + witness). p2wpkh assumes a 72-byte DER sig. */
|
|
197
|
+
declare const INPUT_WEIGHT: Record<BtcAddressType, number>;
|
|
198
|
+
/** Virtual bytes an output of this script kind occupies (8 B value + 1 B len + script). */
|
|
199
|
+
declare function outputVBytes(kind: ScriptKind, script?: Uint8Array): number;
|
|
200
|
+
/** Bitcoin Core dust threshold (3 sat/vB discard rate) per output type, in sats. */
|
|
201
|
+
declare function dustLimit(kind: ScriptKind): bigint;
|
|
202
|
+
/** Smallest p2wpkh output relay policy accepts, in satoshis. */
|
|
203
|
+
declare const DUST_LIMIT_P2WPKH: bigint;
|
|
204
|
+
/** Smallest p2tr output relay policy accepts, in satoshis. */
|
|
205
|
+
declare const DUST_LIMIT_P2TR: bigint;
|
|
206
|
+
|
|
207
|
+
/** btc-signer ships mainnet + testnet; regtest only differs in the bech32 HRP. */
|
|
208
|
+
declare const REGTEST_NETWORK: BTC_NETWORK;
|
|
209
|
+
/** `@scure/btc-signer` parameters of a network. */
|
|
210
|
+
declare function networkParams(network: BtcNetwork): BTC_NETWORK;
|
|
211
|
+
/** SLIP-44 coin type: 0 for mainnet, 1 for every test network. */
|
|
212
|
+
declare const coinType: (network: BtcNetwork) => 0 | 1;
|
|
213
|
+
/** BIP purpose for the address type: 84 (p2wpkh) or 86 (p2tr). */
|
|
214
|
+
declare const purposeFor: (type: BtcAddressType) => 84 | 86;
|
|
215
|
+
|
|
216
|
+
/** A coin selection for one spend, with the recipient's script. */
|
|
217
|
+
interface SpendPlan extends CoinSelection {
|
|
218
|
+
/** Sats the recipient gets (the requested value — never reduced). */
|
|
219
|
+
amount: bigint;
|
|
220
|
+
recipientScript: Uint8Array;
|
|
221
|
+
recipientKind: ScriptKind;
|
|
222
|
+
}
|
|
223
|
+
/** Watch-only Bitcoin account: balances, quotes, receipts, BIP-137 verification. No key. */
|
|
224
|
+
declare class WalletAccountReadOnlyBtc implements IWalletAccountReadOnly {
|
|
225
|
+
/** The address. */
|
|
226
|
+
readonly address: string;
|
|
227
|
+
readonly chain: string;
|
|
228
|
+
/** Output script of `address`. */
|
|
229
|
+
readonly scriptPubKey: Uint8Array;
|
|
230
|
+
/** Script type of the address. */
|
|
231
|
+
readonly scriptKind: ScriptKind;
|
|
232
|
+
/** p2wpkh / p2tr when the address is one we know how to spend from; undefined for other script types. */
|
|
233
|
+
readonly addressType: BtcAddressType | undefined;
|
|
234
|
+
/** Smallest output this address type may create, in satoshis. */
|
|
235
|
+
readonly dustLimit: bigint;
|
|
236
|
+
protected readonly _config: BtcConfig;
|
|
237
|
+
protected readonly _client: BtcClient | undefined;
|
|
238
|
+
protected readonly _network: BTC_NETWORK;
|
|
239
|
+
protected readonly _networkName: BtcNetwork;
|
|
240
|
+
constructor(address: string, config?: BtcConfig);
|
|
241
|
+
protected requireClient(what: string): BtcClient;
|
|
242
|
+
/** Fee-rate ceiling in sat/vB: `BtcConfig.maxFeeRate` or {@link DEFAULT_MAX_FEE_RATE}. */
|
|
243
|
+
get maxFeeRate(): number;
|
|
244
|
+
/** The address. */
|
|
245
|
+
getAddress(): Promise<string>;
|
|
246
|
+
/** Confirmed minus pending outgoing (Bitcoin Core wallet semantics). */
|
|
247
|
+
getBalance(): Promise<bigint>;
|
|
248
|
+
/** Always throws: Bitcoin has no tokens. */
|
|
249
|
+
getTokenBalance(_token: string): Promise<bigint>;
|
|
250
|
+
/** Weight one of OUR inputs adds; throws for address types we cannot spend from. */
|
|
251
|
+
protected inputWeight(): number;
|
|
252
|
+
protected resolveFeeRate(spend: {
|
|
253
|
+
feeRate?: bigint | number;
|
|
254
|
+
confirmationTarget?: number;
|
|
255
|
+
}): Promise<bigint>;
|
|
256
|
+
/** Coin selection for a spend (see coinselect.ts). Validates the recipient and the dust floor first. */
|
|
257
|
+
protected planSpend(spend: BtcSpend): Promise<SpendPlan>;
|
|
258
|
+
/** Fee of a spend in satoshis, from a coin selection at the current fee rate. */
|
|
259
|
+
quoteSendTransaction(tx: BtcSpend): Promise<{
|
|
260
|
+
fee: bigint;
|
|
261
|
+
}>;
|
|
262
|
+
/**
|
|
263
|
+
* Fee of a transfer in satoshis.
|
|
264
|
+
*
|
|
265
|
+
* @throws Error when `token` is set.
|
|
266
|
+
*/
|
|
267
|
+
quoteTransfer(o: BtcTransferOptions): Promise<{
|
|
268
|
+
fee: bigint;
|
|
269
|
+
}>;
|
|
270
|
+
/** Everything spendable in ONE transaction to a single output of our own address type, no change. */
|
|
271
|
+
getMaxSpendable(opts?: {
|
|
272
|
+
feeRate?: bigint | number;
|
|
273
|
+
confirmationTarget?: number;
|
|
274
|
+
to?: string;
|
|
275
|
+
}): Promise<BtcMaxSpendableResult>;
|
|
276
|
+
/** Undefined until the transaction is mined. */
|
|
277
|
+
getTransactionReceipt(hash: string): Promise<BtcReceipt | undefined>;
|
|
278
|
+
/** BIP-137: recover the key and compare its p2wpkh address with ours. Taproot addresses have no BIP-137 form. */
|
|
279
|
+
verify(message: string | Uint8Array, signature: string): Promise<boolean>;
|
|
280
|
+
/** Chain tip for anti-fee-sniping; undefined when disabled or the transport cannot tell. */
|
|
281
|
+
protected lockTimeHeight(): Promise<number>;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** Address for a compressed public key; `network` may be a name or btc-signer params. */
|
|
285
|
+
declare function addressFor(publicKey: Uint8Array, network?: BtcNetwork | BTC_NETWORK, type?: BtcAddressType): string;
|
|
286
|
+
interface Built {
|
|
287
|
+
tx: Transaction;
|
|
288
|
+
fee: bigint;
|
|
289
|
+
plan: SpendPlan;
|
|
290
|
+
desc: BtcTxDescription;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Signing Bitcoin account — BIP-84 p2wpkh or BIP-86 p2tr (key-path). The key never
|
|
294
|
+
* enters this package: every signature is one `signer.sign(...)` call over a
|
|
295
|
+
* btc-signer-computed sighash — a {@link LocalSigner} for seed wallets, anything
|
|
296
|
+
* else (hardware, MPC, backend) through `externalSigner()`:
|
|
297
|
+
*
|
|
298
|
+
* ```text
|
|
299
|
+
* p2wpkh input → `ecdsa` over the BIP-143 sighash (SIGHASH_ALL), DER-encoded here
|
|
300
|
+
* p2tr input → `schnorr` + `tweak` over the BIP-341 sighash (DEFAULT), tweak = TapTweak(xonly)
|
|
301
|
+
* BIP-137 msg → `ecdsa-recoverable` over the magic hash
|
|
302
|
+
* ```
|
|
303
|
+
*
|
|
304
|
+
* Every spend is resolved to a full description ("what you sign") and run through
|
|
305
|
+
* the hard safety checks (fee-rate ceiling, recipient/amount exactness, change
|
|
306
|
+
* ownership) before signing AND before broadcast — also for caller-supplied raw hex.
|
|
307
|
+
*/
|
|
308
|
+
declare class WalletAccountBtc extends WalletAccountReadOnlyBtc implements IWalletAccount {
|
|
309
|
+
/** UTXOs, fee rate and tip height come from the network before signing. */
|
|
310
|
+
readonly needsNetwork = true;
|
|
311
|
+
/** Derivation path, or `external` for an external signer. */
|
|
312
|
+
readonly path: string;
|
|
313
|
+
/** Compressed secp256k1 public key. */
|
|
314
|
+
readonly publicKey: Uint8Array;
|
|
315
|
+
readonly addressType: BtcAddressType;
|
|
316
|
+
/** The signer that holds the key. */
|
|
317
|
+
readonly signer: Signer;
|
|
318
|
+
private _disposed;
|
|
319
|
+
private _readOnly;
|
|
320
|
+
/** `publicKey` is the signer's compressed secp256k1 key (33 bytes); it is needed synchronously for the address. */
|
|
321
|
+
constructor(signer: Signer, publicKey: Uint8Array, path: string, config?: BtcConfig);
|
|
322
|
+
/** Back-compat: wrap a raw derived key in a {@link LocalSigner} (the account takes ownership; it cannot derive). */
|
|
323
|
+
static fromPrivateKey(privateKey: Uint8Array, publicKey: Uint8Array, path: string, config?: BtcConfig): WalletAccountBtc;
|
|
324
|
+
/** Account index for the standard m/{84|86}'/{0|1}'/0'/0/i path. */
|
|
325
|
+
get index(): number | undefined;
|
|
326
|
+
private live;
|
|
327
|
+
/** BIP-137 p2wpkh signature, base64 (Electrum / Bitcoin Core encoding). Not available for taproot accounts. */
|
|
328
|
+
sign(message: string | Uint8Array): Promise<string>;
|
|
329
|
+
/** The x-only internal key and its BIP-86 tweak (no script tree) for taproot key-path spends. */
|
|
330
|
+
private taprootKeys;
|
|
331
|
+
/**
|
|
332
|
+
* Sign every input through the signer and attach the witness-ready signature:
|
|
333
|
+
* p2wpkh → `partialSig` (DER + SIGHASH_ALL), p2tr → `tapKeySig` (64 bytes, DEFAULT).
|
|
334
|
+
* btc-signer only computes the sighash and assembles the witness; it never sees a key.
|
|
335
|
+
*/
|
|
336
|
+
private signInputs;
|
|
337
|
+
private ctx;
|
|
338
|
+
private buildAndSign;
|
|
339
|
+
/**
|
|
340
|
+
* Plan → sign → measure. The plan's fee assumes 72-byte DER signatures; if the
|
|
341
|
+
* signed vsize somehow needs more, the difference comes out of change (never the
|
|
342
|
+
* recipient) and the tx is re-signed once.
|
|
343
|
+
*/
|
|
344
|
+
protected buildSignedTransaction(spend: BtcSpend): Promise<Built>;
|
|
345
|
+
private checkMax;
|
|
346
|
+
/**
|
|
347
|
+
* BIP-143 (p2wpkh) commits each input's signature to that input's CLAIMED amount
|
|
348
|
+
* only: an indexer that understates a different coin in each of two signing
|
|
349
|
+
* sessions can combine their signatures into one valid tx whose real fee the
|
|
350
|
+
* wallet never showed (scan 2026-10-23 F2). So every p2wpkh coin is read from
|
|
351
|
+
* its full previous transaction, which must hash to the claimed txid, and its
|
|
352
|
+
* amount and script must match before anything is signed. Taproot (BIP-341)
|
|
353
|
+
* commits to every input amount and skips the extra requests.
|
|
354
|
+
*/
|
|
355
|
+
private verifyPrevouts;
|
|
356
|
+
/** Prevout values of a raw tx, fetched through the client (the wire format carries none). */
|
|
357
|
+
private inputValues;
|
|
358
|
+
/** Describe a raw signed tx (needs the network for prevout values) and run the safety checks. */
|
|
359
|
+
private describeRaw;
|
|
360
|
+
/** "What you sign": the fully resolved spend (signed, NOT broadcast) or a caller's raw hex. */
|
|
361
|
+
describeTransaction(tx: BtcTransaction): Promise<BtcTxDescription>;
|
|
362
|
+
/** Sign without broadcasting. Returns the raw transaction hex. Raw hex input is returned unchanged. */
|
|
363
|
+
signTransaction(tx: BtcTransaction): Promise<string>;
|
|
364
|
+
quoteSendTransaction(tx: BtcTransaction): Promise<{
|
|
365
|
+
fee: bigint;
|
|
366
|
+
}>;
|
|
367
|
+
sendTransaction(tx: BtcTransaction): Promise<TransferResult>;
|
|
368
|
+
/** Native BTC only (`token` is rejected). Subject to `transferMaxFee`. */
|
|
369
|
+
transfer(o: BtcTransferOptions): Promise<TransferResult>;
|
|
370
|
+
/** The same address as a {@link WalletAccountReadOnlyBtc}. */
|
|
371
|
+
toReadOnlyAccount(): IWalletAccountReadOnly;
|
|
372
|
+
dispose(): void;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* One seed → Bitcoin accounts.
|
|
377
|
+
* p2wpkh (default): BIP-84, m/84'/0'/0'/0/i on mainnet, m/84'/1'/0'/0/i on test networks — bc1q… / tb1q…
|
|
378
|
+
* p2tr: BIP-86, m/86'/0'/0'/0/i (key-path taproot) — bc1p… / tb1p…
|
|
379
|
+
* Paths may be relative to the purpose/coin prefix ("0'/0/i") or given in full.
|
|
380
|
+
*
|
|
381
|
+
* Built with a secp256k1 `Signer` instead of a seed, the manager wraps it:
|
|
382
|
+
* - a derivable `SeedSigner` sitting at the account branch (`m/84'/0'/0'/0` or
|
|
383
|
+
* `m/86'/0'/0'/0`, per `addressType`/`network`) yields `getAccount(i)` children;
|
|
384
|
+
* - a `SeedSigner` at a leaf, or any external signer, is `getAccount(0)` (path = the
|
|
385
|
+
* signer's path, or 'external') with the configured address type; other
|
|
386
|
+
* indexes/paths throw.
|
|
387
|
+
*/
|
|
388
|
+
declare class WalletManagerBtc extends WalletManager<WalletAccountBtc, BtcConfig> {
|
|
389
|
+
constructor(seedOrSigner: string | Uint8Array | Signer, config?: BtcConfig);
|
|
390
|
+
/**
|
|
391
|
+
* `m/84'/0'` for p2wpkh or `m/86'/0'` for p2tr on mainnet (coin type 1 on test networks); account
|
|
392
|
+
* `i` is at `basePath/0'/0/i`.
|
|
393
|
+
*/
|
|
394
|
+
get basePath(): string;
|
|
395
|
+
getAccount(index?: number): Promise<WalletAccountBtc>;
|
|
396
|
+
getAccountByPath(path: string): Promise<WalletAccountBtc>;
|
|
397
|
+
/** Resolve `path` against an injected signer: the signer itself, or a child when it can derive there. */
|
|
398
|
+
private fromSigner;
|
|
399
|
+
/** A read-only account for any address, with this manager's config. */
|
|
400
|
+
getReadOnlyAccount(address: string): WalletAccountReadOnlyBtc;
|
|
401
|
+
/** sat/vB from the client's estimator: fast = 1 block, normal = 3, slow = 6. */
|
|
402
|
+
getFeeRates(): Promise<FeeRates>;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export { BlockbookTx, BtcAddressType, BtcClient, BtcConfig, BtcMaxSpendableResult, BtcNetwork, BtcReceipt, BtcSpend, BtcTransaction, BtcTransferOptions, BtcTxDescription, type CoinSelectOptions, type CoinSelection, DEFAULT_MAX_FEE_RATE, DUST_LIMIT_P2TR, DUST_LIMIT_P2WPKH, type DecodedAddress, type DescribeContext, EsploraClient, FINAL_SEQUENCE, INPUT_WEIGHT, MAX_UTXO_INPUTS, RBF_SEQUENCE, REGTEST_NETWORK, type ScriptKind, type SegwitType, type SelectionTarget, type SpendPlan, TooManyInputsError, type UnsafeTransactionCode, UnsafeTransactionError, UnsupportedAddressTypeError, Utxo, WalletAccountBtc, WalletAccountReadOnlyBtc, WalletManagerBtc, addressFor, addressFromPublicKey, addressFromScript, assertSafe, coinType, createClient, decodeAddress, WalletManagerBtc as default, describeTransaction, dustLimit, encodeMessageSignature, estimateVsize, magicHash, networkParams, outputVBytes, parseRawTransaction, purposeFor, recoverMessagePublicKey, scriptKind, selectAll, selectCoins, signMessage, signMessageWith, spendableUtxos };
|