@secondlayer/stacks 2.8.1 → 2.9.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.
Files changed (34) hide show
  1. package/README.md +88 -0
  2. package/dist/shared/{stacks-sfpr4b0y.js → stacks-53bjdb6p.js} +2 -2
  3. package/dist/shared/{stacks-9z833ww5.js → stacks-5nmz5ad9.js} +3 -3
  4. package/dist/shared/{stacks-9z833ww5.js.map → stacks-5nmz5ad9.js.map} +1 -1
  5. package/dist/shared/{stacks-s9148m6h.js → stacks-8mj5jw77.js} +6 -4
  6. package/dist/shared/{stacks-s9148m6h.js.map → stacks-8mj5jw77.js.map} +2 -2
  7. package/dist/shared/stacks-cdvn8qbh.cjs +20 -0
  8. package/dist/shared/stacks-cdvn8qbh.cjs.map +10 -0
  9. package/dist/shared/{stacks-y9txtw3p.cjs → stacks-maamjqma.cjs} +2 -20
  10. package/dist/shared/{stacks-y9txtw3p.cjs.map → stacks-maamjqma.cjs.map} +3 -4
  11. package/dist/shared/stacks-q1mjkt15.js +34 -0
  12. package/dist/shared/stacks-q1mjkt15.js.map +10 -0
  13. package/dist/shared/{stacks-a63xq06y.js → stacks-z1j5d6fd.js} +3 -21
  14. package/dist/shared/{stacks-a63xq06y.js.map → stacks-z1j5d6fd.js.map} +3 -4
  15. package/dist/src/actions/index.js +7 -5
  16. package/dist/src/actions/index.js.map +1 -1
  17. package/dist/src/bitcoin/index.cjs +679 -0
  18. package/dist/src/bitcoin/index.cjs.map +19 -0
  19. package/dist/src/bitcoin/index.d.cts +743 -0
  20. package/dist/src/bitcoin/index.d.ts +743 -0
  21. package/dist/src/bitcoin/index.js +704 -0
  22. package/dist/src/bitcoin/index.js.map +19 -0
  23. package/dist/src/bns/index.js +4 -3
  24. package/dist/src/bns/index.js.map +2 -2
  25. package/dist/src/index.js +6 -4
  26. package/dist/src/index.js.map +2 -2
  27. package/dist/src/pox/index.js +5 -4
  28. package/dist/src/pox/index.js.map +2 -2
  29. package/dist/src/sbtc/index.js +5 -4
  30. package/dist/src/sbtc/index.js.map +2 -2
  31. package/dist/src/stackingdao/index.js +4 -3
  32. package/dist/src/stackingdao/index.js.map +2 -2
  33. package/package.json +8 -4
  34. /package/dist/shared/{stacks-sfpr4b0y.js.map → stacks-53bjdb6p.js.map} +0 -0
@@ -0,0 +1,743 @@
1
+ type IntCV = {
2
+ readonly type: "int"
3
+ readonly value: bigint
4
+ };
5
+ type UIntCV = {
6
+ readonly type: "uint"
7
+ readonly value: bigint
8
+ };
9
+ type BooleanCV = TrueCV | FalseCV;
10
+ type TrueCV = {
11
+ readonly type: "true"
12
+ };
13
+ type FalseCV = {
14
+ readonly type: "false"
15
+ };
16
+ type BufferCV = {
17
+ readonly type: "buffer"
18
+ readonly value: string
19
+ };
20
+ type NoneCV = {
21
+ readonly type: "none"
22
+ };
23
+ type SomeCV = {
24
+ readonly type: "some"
25
+ readonly value: ClarityValue
26
+ };
27
+ type ResponseOkCV = {
28
+ readonly type: "ok"
29
+ readonly value: ClarityValue
30
+ };
31
+ type ResponseErrorCV = {
32
+ readonly type: "err"
33
+ readonly value: ClarityValue
34
+ };
35
+ type StandardPrincipalCV = {
36
+ readonly type: "address"
37
+ readonly value: string
38
+ };
39
+ type ContractPrincipalCV = {
40
+ readonly type: "contract"
41
+ readonly value: string
42
+ };
43
+ type ListCV = {
44
+ type: "list"
45
+ value: ClarityValue[]
46
+ };
47
+ type TupleData = {
48
+ [key: string]: ClarityValue
49
+ };
50
+ type TupleCV = {
51
+ type: "tuple"
52
+ value: TupleData
53
+ };
54
+ type StringAsciiCV = {
55
+ readonly type: "ascii"
56
+ readonly value: string
57
+ };
58
+ type StringUtf8CV = {
59
+ readonly type: "utf8"
60
+ readonly value: string
61
+ };
62
+ type ClarityValue = IntCV | UIntCV | BooleanCV | BufferCV | NoneCV | SomeCV | ResponseOkCV | ResponseErrorCV | StandardPrincipalCV | ContractPrincipalCV | ListCV | TupleCV | StringAsciiCV | StringUtf8CV;
63
+ /**
64
+ * Bitcoin double-SHA256: `sha256(sha256(bytes))`. This is the hash Bitcoin uses
65
+ * for txids, block headers, and merkle nodes — NOT the same as the Stacks
66
+ * `txidFromBytes` (which uses sha512_256), so it lives here, not in `utils/hash`.
67
+ */
68
+ declare function doubleSha256(bytes: Uint8Array): Uint8Array;
69
+ /**
70
+ * Reverse a byte array. Bitcoin hashes are computed and stored in *internal*
71
+ * (little-endian) order but *displayed* big-endian, so the two differ by a
72
+ * reversal. The SIP-044 built-ins consume internal order; only reverse for
73
+ * display / when matching an explorer value.
74
+ */
75
+ declare function reverseBytes(bytes: Uint8Array): Uint8Array;
76
+ /**
77
+ * A little-endian, varint-aware byte reader for Bitcoin serialization. The
78
+ * shared `utils/BytesReader` is big-endian only; Bitcoin tx fields are
79
+ * little-endian with compact-size (varint) length prefixes.
80
+ */
81
+ declare class BtcReader {
82
+ private readonly data;
83
+ private readonly view;
84
+ offset: number;
85
+ constructor(data: Uint8Array);
86
+ get length(): number;
87
+ readUInt8(): number;
88
+ /** Read the next byte without advancing. */
89
+ peekUInt8(): number;
90
+ readUInt32LE(): number;
91
+ readUInt64LE(): bigint;
92
+ readBytes(n: number): Uint8Array;
93
+ /** Read a Bitcoin compact-size unsigned integer (varint). */
94
+ readVarInt(): number;
95
+ }
96
+ interface BitcoinTxInput {
97
+ /** Previous output txid, in serialized (internal) byte order. */
98
+ prevTxid: Uint8Array;
99
+ vout: number;
100
+ scriptSig: Uint8Array;
101
+ sequence: number;
102
+ }
103
+ interface BitcoinTxOutput {
104
+ /** Output value in satoshis. */
105
+ value: bigint;
106
+ scriptPubKey: Uint8Array;
107
+ }
108
+ interface ParsedBitcoinTx {
109
+ version: number;
110
+ hasWitness: boolean;
111
+ inputs: BitcoinTxInput[];
112
+ outputs: BitcoinTxOutput[];
113
+ locktime: number;
114
+ /**
115
+ * The legacy txid as the raw double-SHA256 in *internal* byte order — ready
116
+ * to pass as the leaf to `verify-merkle-proof`. Witness data is excluded
117
+ * (the txid is computed over the legacy serialization), so this is stable for
118
+ * both legacy and SegWit txs. Use `reverseBytes` for the displayed form.
119
+ */
120
+ txidInternal: Uint8Array;
121
+ }
122
+ /** Parse a serialized Bitcoin tx (legacy or SegWit) into its fields + txid. */
123
+ declare function parseBitcoinTx(rawTx: Uint8Array): ParsedBitcoinTx;
124
+ /**
125
+ * Return the legacy (witness-stripped) serialization of a tx. For a legacy tx
126
+ * this is the input unchanged; for a SegWit tx the marker, flag, and witness
127
+ * stack are removed. This is the byte string the txid is hashed over.
128
+ */
129
+ declare function stripWitness(rawTx: Uint8Array): Uint8Array;
130
+ /**
131
+ * Compute a tx's id from its raw serialization. Internal byte order by default
132
+ * (the merkle leaf / built-in input); pass `{ display: true }` for the
133
+ * explorer-style big-endian form.
134
+ */
135
+ declare function bitcoinTxid(rawTx: Uint8Array, { display }?: {
136
+ display?: boolean
137
+ }): Uint8Array;
138
+ interface BlockHeader {
139
+ version: number;
140
+ /** Previous block hash, internal byte order. */
141
+ prevBlock: Uint8Array;
142
+ /** Merkle root, internal byte order — pairs with `verify-merkle-proof`. */
143
+ merkleRoot: Uint8Array;
144
+ timestamp: number;
145
+ bits: number;
146
+ nonce: number;
147
+ }
148
+ /** Parse an 80-byte Bitcoin block header into its fields (hashes internal order). */
149
+ declare function parseBlockHeader(header: Uint8Array): BlockHeader;
150
+ /**
151
+ * Hash an 80-byte block header (double-SHA256). Internal byte order by default;
152
+ * `{ display: true }` for the explorer-style block hash.
153
+ */
154
+ declare function blockHash(header: Uint8Array, { display }?: {
155
+ display?: boolean
156
+ }): Uint8Array;
157
+ /**
158
+ * A Bitcoin merkle inclusion proof, shaped for the SIP-044 `verify-merkle-proof`
159
+ * built-in: `(leaf-hash, root-hash, tx-index, tx-count, sibling-hashes)`.
160
+ *
161
+ * - `siblings` are the sibling node hashes from the leaf up to (excluding) the
162
+ * root, in *internal* byte order — never reversed.
163
+ * - `txCount` (not tree-depth) pins the canonical tree shape; the built-in
164
+ * rejects any proof whose length differs from `ceil(log2(tx-count))`.
165
+ */
166
+ interface MerkleProof {
167
+ siblings: Uint8Array[];
168
+ txIndex: number;
169
+ txCount: number;
170
+ }
171
+ /**
172
+ * Compute the merkle root over txids in *internal* byte order. The result is
173
+ * also internal order — it matches the `merkle-root` field read straight out of
174
+ * an 80-byte block header, so it can be cross-checked against the header before
175
+ * a proof is trusted.
176
+ */
177
+ declare function merkleRoot2(txidsInternal: Uint8Array[]): Uint8Array;
178
+ /**
179
+ * Build the merkle inclusion proof for the tx at `txIndex`. Sibling count is
180
+ * exactly `ceil(log2(txCount))`, as the SIP-044 built-in requires.
181
+ */
182
+ declare function buildMerkleProof(txidsInternal: Uint8Array[], txIndex: number): MerkleProof;
183
+ /**
184
+ * Recompute the merkle root from a leaf + its proof — the same fold the on-chain
185
+ * `verify-merkle-proof` performs. Use it off-chain to self-check a constructed
186
+ * proof against the header's merkle root before submitting a contract call.
187
+ */
188
+ declare function rootFromProof(leafInternal: Uint8Array, proof: MerkleProof): Uint8Array;
189
+ /**
190
+ * A self-contained Bitcoin SPV proof: everything the SIP-044 built-ins need to
191
+ * prove a tx (and one of its outputs) is committed in a confirmed block. Hashes
192
+ * are internal byte order throughout.
193
+ */
194
+ interface SpvProof {
195
+ rawTx: Uint8Array;
196
+ /** The tx's txid, internal order — the merkle leaf. */
197
+ txidInternal: Uint8Array;
198
+ /** Output index of interest, if the proof targets a specific output. */
199
+ vout?: number;
200
+ merkle: MerkleProof;
201
+ /** The 80-byte block header that commits the tx. */
202
+ header: Uint8Array;
203
+ /** Bitcoin block height. */
204
+ height: number;
205
+ }
206
+ /** The block context a `ProofSource` resolves for a confirmed tx. */
207
+ interface BlockForTx {
208
+ /** 80-byte block header. */
209
+ header: Uint8Array;
210
+ height: number;
211
+ /** All of the block's txids, internal order, in block order. */
212
+ txidsInternal: Uint8Array[];
213
+ /** Index of the target tx within the block. */
214
+ txIndex: number;
215
+ }
216
+ /**
217
+ * Where proof inputs come from. The default is the integrator's own Bitcoin node
218
+ * (`bitcoinRpcSource`) — trustless; a hosted Esplora-compatible endpoint
219
+ * (`esploraSource`) is the fallback. `buildTxProof` independently re-checks
220
+ * whatever a source returns, so a wrong or hostile source fails loudly rather
221
+ * than producing a bad proof.
222
+ */
223
+ interface ProofSource {
224
+ /** Raw (serialized) tx bytes for a txid (display-order hex). */
225
+ getRawTx(txid: string): Promise<Uint8Array>;
226
+ /** The confirming block's header, height, and txid set for a txid. */
227
+ getBlockForTx(txid: string): Promise<BlockForTx>;
228
+ }
229
+ /**
230
+ * Assemble an `SpvProof` for a txid from a `ProofSource`, validating every claim
231
+ * the source makes:
232
+ * - the returned raw tx actually hashes to the requested txid,
233
+ * - the claimed `txIndex` points at that txid in the block, and
234
+ * - the resulting merkle proof folds back to the block header's merkle root.
235
+ * Any mismatch throws — the proof is never returned half-trusted.
236
+ */
237
+ declare function buildTxProof(source: ProofSource, params: {
238
+ txid: string
239
+ vout?: number
240
+ }): Promise<SpvProof>;
241
+ /**
242
+ * Compose sources into an ordered fallback chain: each call tries them in turn
243
+ * and returns the first success, throwing the last error if all fail. Put the
244
+ * trustless integrator node first and a hosted endpoint last.
245
+ */
246
+ declare function fallbackProofSource(sources: ProofSource[]): ProofSource;
247
+ interface BitcoinRpcConfig {
248
+ /** Bitcoin Core JSON-RPC endpoint URL. */
249
+ url: string;
250
+ /** Basic auth — `{ username, password }` or a pre-encoded base64 string. */
251
+ auth?: {
252
+ username: string
253
+ password: string
254
+ } | string;
255
+ /** Override the fetch implementation (testing / custom agents). */
256
+ fetch?: typeof fetch;
257
+ }
258
+ /**
259
+ * A `ProofSource` backed by the integrator's own Bitcoin Core node over
260
+ * JSON-RPC. This is the trustless default. The node must run with `-txindex`
261
+ * (or the tx must be in the mempool's block view) so `getrawtransaction` can
262
+ * resolve the confirming block.
263
+ */
264
+ declare function bitcoinRpcSource(config: BitcoinRpcConfig): ProofSource;
265
+ interface EsploraConfig {
266
+ /** Esplora REST base URL, e.g. `https://blockstream.info/api` or a self-hosted instance. */
267
+ url: string;
268
+ /** Override the fetch implementation. */
269
+ fetch?: typeof fetch;
270
+ }
271
+ /**
272
+ * A `ProofSource` backed by an Esplora REST API (self-hosted, or a hosted
273
+ * provider as a fallback). Provider-agnostic: any Esplora-compatible endpoint
274
+ * works. Use as the hosted fallback behind `bitcoinRpcSource`.
275
+ */
276
+ declare function esploraSource(config: EsploraConfig): ProofSource;
277
+ /**
278
+ * Encode the argument vector for the SIP-044 native built-in
279
+ * `(verify-merkle-proof leaf-hash root-hash tx-index tx-count sibling-hashes)`.
280
+ *
281
+ * Returns the five args in order: `[leaf, root, tx-index, tx-count, siblings]`.
282
+ * All hashes are passed in *internal* (raw) byte order — the built-in does NOT
283
+ * reverse, and neither does this. The leaf is the tx's `txidInternal`; the root
284
+ * is the block header's merkle root in internal order.
285
+ *
286
+ * Throws on shapes the built-in would reject, so a caller fails locally with a
287
+ * clear message instead of an opaque on-chain `false`.
288
+ */
289
+ declare function encodeMerkleProofArgs(params: {
290
+ leaf: Uint8Array
291
+ root: Uint8Array
292
+ proof: MerkleProof
293
+ }): [BufferCV, BufferCV, UIntCV, UIntCV, ListCV];
294
+ interface DecodedTxOutput {
295
+ /** scriptPubKey bytes. */
296
+ script: Uint8Array;
297
+ /** Output value in satoshis. */
298
+ amount: bigint;
299
+ /** The tx's txid in internal byte order — ready as a merkle leaf. */
300
+ txid: Uint8Array;
301
+ }
302
+ /**
303
+ * Decode the tuple returned by `get-bitcoin-tx-output?`:
304
+ * `(tuple (script (buff 1024)) (amount uint) (txid (buff 32)))`.
305
+ *
306
+ * Accepts either the bare tuple or a `(response ok ...)` wrapping it, so it
307
+ * works whether or not the caller has already unwrapped the response.
308
+ */
309
+ declare function decodeTxOutput(cv: ClarityValue): DecodedTxOutput;
310
+ type OutputScriptType = "p2pkh" | "p2sh" | "p2wpkh" | "p2wsh" | "p2tr" | "op_return" | "unknown";
311
+ interface ParsedOutputScript {
312
+ type: OutputScriptType;
313
+ /**
314
+ * The hash / witness program for the recognized output types: the 20-byte
315
+ * pubkey-hash (p2pkh), 20-byte script-hash (p2sh), or the 20/32-byte witness
316
+ * program (p2wpkh/p2wsh/p2tr). Undefined for op_return / unknown.
317
+ *
318
+ * Address formatting is intentionally left to the caller — base58/bech32 HRPs
319
+ * and version bytes are network-dependent, so it belongs where the network is
320
+ * known (see `verifyBitcoinPayment`), not in this pure decoder.
321
+ */
322
+ hash?: Uint8Array;
323
+ /** OP_RETURN payload (the pushed data after the OP_RETURN opcode). */
324
+ data?: Uint8Array;
325
+ }
326
+ /**
327
+ * Classify a Bitcoin output scriptPubKey by its standard template and surface
328
+ * the embedded hash / witness program. Recognizes P2PKH, P2SH, P2WPKH, P2WSH,
329
+ * P2TR, and OP_RETURN; anything else is `unknown`.
330
+ */
331
+ declare function parseOutputScript(script: Uint8Array): ParsedOutputScript;
332
+ type BitcoinNetwork = "mainnet" | "testnet";
333
+ interface SpvAdapterRef {
334
+ /** Deployer principal. */
335
+ address: string;
336
+ /** Contract name. */
337
+ name: string;
338
+ }
339
+ /**
340
+ * Reference `spv-adapter` deployments (the read-only wrapper around the SIP-044
341
+ * built-ins). Populated by plan 013 once Clarity 6 / Epoch 4.0 activates and the
342
+ * contract is deployed. Until then this is empty and callers must pass an
343
+ * explicit `contract` to `bitcoinVerifier`.
344
+ */
345
+ declare const SPV_ADAPTER_CONTRACTS: Partial<Record<BitcoinNetwork, SpvAdapterRef>>;
346
+ /**
347
+ * ABI for the reference `spv-adapter` contract — a thin, read-only wrapper that
348
+ * exposes the SIP-044 Bitcoin built-ins (callable only from within a Clarity
349
+ * contract) over read-only RPC. Plan 013 deploys a contract matching this shape;
350
+ * `bitcoinVerifier` binds to it (or to an integrator's own contract with the
351
+ * same surface).
352
+ *
353
+ * Hashes are internal (raw) byte order — the same as the built-ins. Do NOT
354
+ * reverse before calling.
355
+ */
356
+ declare const SPV_ADAPTER_ABI: {
357
+ readonly functions: readonly [{
358
+ readonly name: "get-tx-output"
359
+ readonly access: "read-only"
360
+ readonly args: readonly [{
361
+ readonly name: "tx"
362
+ readonly type: {
363
+ readonly buff: {
364
+ readonly length: 4096
365
+ }
366
+ }
367
+ }, {
368
+ readonly name: "vout"
369
+ readonly type: "uint128"
370
+ }]
371
+ readonly outputs: {
372
+ readonly response: {
373
+ readonly ok: {
374
+ readonly tuple: readonly [{
375
+ readonly name: "script"
376
+ readonly type: {
377
+ readonly buff: {
378
+ readonly length: 1024
379
+ }
380
+ }
381
+ }, {
382
+ readonly name: "amount"
383
+ readonly type: "uint128"
384
+ }, {
385
+ readonly name: "txid"
386
+ readonly type: {
387
+ readonly buff: {
388
+ readonly length: 32
389
+ }
390
+ }
391
+ }]
392
+ }
393
+ readonly error: "uint128"
394
+ }
395
+ }
396
+ }, {
397
+ readonly name: "verify-merkle"
398
+ readonly access: "read-only"
399
+ readonly args: readonly [{
400
+ readonly name: "leaf"
401
+ readonly type: {
402
+ readonly buff: {
403
+ readonly length: 32
404
+ }
405
+ }
406
+ }, {
407
+ readonly name: "root"
408
+ readonly type: {
409
+ readonly buff: {
410
+ readonly length: 32
411
+ }
412
+ }
413
+ }, {
414
+ readonly name: "tx-index"
415
+ readonly type: "uint128"
416
+ }, {
417
+ readonly name: "tx-count"
418
+ readonly type: "uint128"
419
+ }, {
420
+ readonly name: "siblings"
421
+ readonly type: {
422
+ readonly list: {
423
+ readonly type: {
424
+ readonly buff: {
425
+ readonly length: 32
426
+ }
427
+ }
428
+ readonly length: 24
429
+ }
430
+ }
431
+ }]
432
+ readonly outputs: "bool"
433
+ }, {
434
+ readonly name: "was-tx-mined"
435
+ readonly access: "read-only"
436
+ readonly args: readonly [{
437
+ readonly name: "header"
438
+ readonly type: {
439
+ readonly buff: {
440
+ readonly length: 80
441
+ }
442
+ }
443
+ }, {
444
+ readonly name: "height"
445
+ readonly type: "uint128"
446
+ }, {
447
+ readonly name: "leaf"
448
+ readonly type: {
449
+ readonly buff: {
450
+ readonly length: 32
451
+ }
452
+ }
453
+ }, {
454
+ readonly name: "tx-index"
455
+ readonly type: "uint128"
456
+ }, {
457
+ readonly name: "tx-count"
458
+ readonly type: "uint128"
459
+ }, {
460
+ readonly name: "siblings"
461
+ readonly type: {
462
+ readonly list: {
463
+ readonly type: {
464
+ readonly buff: {
465
+ readonly length: 32
466
+ }
467
+ }
468
+ readonly length: 24
469
+ }
470
+ }
471
+ }]
472
+ readonly outputs: {
473
+ readonly response: {
474
+ readonly ok: "bool"
475
+ readonly error: "uint128"
476
+ }
477
+ }
478
+ }]
479
+ };
480
+ /** Account derived from a local private key (mnemonic or raw key). */
481
+ type LocalAccount = {
482
+ type: "local"
483
+ address: string
484
+ /** Compressed public key (hex) */
485
+ publicKey: string
486
+ /** Raw ECDSA sign over a hash */
487
+ sign(hash: Uint8Array): Uint8Array
488
+ /** Sign a structured message (SIP-018) */
489
+ signMessage(message: string | Uint8Array): string
490
+ };
491
+ /** Account with a user-provided signing function (sync or async). */
492
+ type CustomAccount = {
493
+ type: "custom"
494
+ address: string
495
+ publicKey: string
496
+ sign(hash: Uint8Array): Promise<Uint8Array> | Uint8Array
497
+ };
498
+ /** Browser wallet provider interface (e.g. Leather, Xverse). */
499
+ type StacksProvider = {
500
+ request(method: string, params?: any): Promise<any>
501
+ };
502
+ /** Account backed by a browser wallet {@link StacksProvider}. */
503
+ type ProviderAccount = {
504
+ type: "provider"
505
+ address: string
506
+ publicKey: string
507
+ provider: StacksProvider
508
+ };
509
+ /** Allocates mempool-safe sequential nonces across rapid broadcasts from one account. */
510
+ type NonceManager = {
511
+ consume(params: {
512
+ client: Client
513
+ address: string
514
+ }): Promise<bigint>
515
+ reset(params: {
516
+ client: Client
517
+ address: string
518
+ }): void | Promise<void>
519
+ /** Next nonce that {@link NonceManager.consume} would return without consuming it, or `undefined` if untracked. */
520
+ peek(params: {
521
+ client: Client
522
+ address: string
523
+ }): Promise<bigint | undefined>
524
+ };
525
+ /** Full chain descriptor used by clients and transports for network-aware operations. */
526
+ type StacksChain = {
527
+ /** Chain ID (e.g. 0x00000001 for mainnet) */
528
+ id: number
529
+ /** Human-readable name */
530
+ name: string
531
+ /** Network type */
532
+ network: "mainnet" | "testnet"
533
+ /** Transaction version byte for serialization */
534
+ transactionVersion: number
535
+ /** Peer network ID for P2P broadcasting */
536
+ peerNetworkId: number
537
+ /** Address version bytes */
538
+ addressVersion: {
539
+ singleSig: number
540
+ multiSig: number
541
+ }
542
+ /** Magic bytes for network identification */
543
+ magicBytes: string
544
+ /** Boot address (system contracts deployer) */
545
+ bootAddress: string
546
+ /** Native currency info */
547
+ nativeCurrency: {
548
+ name: string
549
+ symbol: string
550
+ decimals: number
551
+ }
552
+ /** Default RPC URLs */
553
+ rpcUrls: {
554
+ default: {
555
+ http: string[]
556
+ ws?: string[]
557
+ }
558
+ }
559
+ /** Block explorer URLs */
560
+ blockExplorers?: {
561
+ default: {
562
+ name: string
563
+ url: string
564
+ }
565
+ }
566
+ };
567
+ /** Function that sends an HTTP request to a Stacks node API path. */
568
+ type RequestFn = (path: string, options?: RequestOptions) => Promise<any>;
569
+ /** Options for a transport-level HTTP request. */
570
+ type RequestOptions = {
571
+ method?: "GET" | "POST" | "PUT" | "DELETE"
572
+ body?: unknown
573
+ headers?: Record<string, string>
574
+ };
575
+ /** Shared configuration for all transport types. */
576
+ type TransportConfig = {
577
+ url?: string
578
+ timeout?: number
579
+ retryCount?: number
580
+ retryDelay?: number
581
+ fetchOptions?: RequestInit
582
+ apiKey?: string
583
+ };
584
+ /** A resolved transport instance with a bound request function. */
585
+ type Transport = {
586
+ type: string
587
+ request: RequestFn
588
+ config: TransportConfig
589
+ destroy?: () => void
590
+ };
591
+ /** Union of all supported account types (local key, custom signer, or browser provider). */
592
+ type Account = LocalAccount | CustomAccount | ProviderAccount;
593
+ /**
594
+ * Core client instance that holds chain context, transport, and extensible actions.
595
+ * Created via {@link createClient}, {@link createPublicClient}, or {@link createWalletClient}.
596
+ */
597
+ type Client<TExtended extends Record<string, unknown> = Record<string, unknown>> = {
598
+ chain?: StacksChain
599
+ account?: Account
600
+ transport: Transport
601
+ request: RequestFn
602
+ /** Optional nonce manager for mempool-safe sequential nonces across rapid broadcasts. */
603
+ nonceManager?: NonceManager
604
+ extend: <const TNew extends Record<string, unknown>>(fn: (client: Client<TExtended>) => TNew) => Client<TExtended & TNew> & TNew
605
+ } & TExtended;
606
+ /**
607
+ * SIP-044 (the native Bitcoin SPV built-ins) activates as part of the **Stacks
608
+ * Epoch 4.0 hard fork**. The exact activation Bitcoin block height is only
609
+ * selected after the SIP vote passes, so there is no constant to hardcode — a
610
+ * caller passes it once it is known.
611
+ */
612
+ interface Clarity6Gate {
613
+ /**
614
+ * Bitcoin burn block height at which Clarity 6 / Epoch 4.0 activates. Pass it
615
+ * once the vote selects it; until then `isClarity6Active` cannot answer and
616
+ * throws.
617
+ */
618
+ activationBurnHeight?: number;
619
+ }
620
+ /** Read the node's current Bitcoin burn block height from `/v2/info`. */
621
+ declare function getBurnBlockHeight(client: Client): Promise<number>;
622
+ /**
623
+ * Whether Clarity 6 (the native SPV built-ins) is active on the node behind
624
+ * `client`. Compares the node's current burn height to the SIP-044 / Epoch 4.0
625
+ * activation height, which must be supplied (it is unknown until the vote — see
626
+ * `Clarity6Gate`). `bitcoinVerifier` uses this to refuse calls before activation
627
+ * rather than failing with an opaque contract error.
628
+ */
629
+ declare function isClarity6Active(client: Client, gate?: Clarity6Gate): Promise<boolean>;
630
+ interface BitcoinVerifierConfig {
631
+ /** Adapter contract principal, `"address.name"` (the reference `spv-adapter` or an integrator's own). */
632
+ contract: string;
633
+ /** Optional read-only call sender; defaults to the contract address. */
634
+ sender?: string;
635
+ }
636
+ interface BitcoinVerifier {
637
+ /**
638
+ * Verify a merkle inclusion proof against a supplied root via the adapter's
639
+ * `verify-merkle` (the native `verify-merkle-proof`). This proves membership
640
+ * under `root`; authenticating that `root` belongs to a canonical Bitcoin
641
+ * block is a separate step (header → height), composed in `verifyBitcoinPayment`.
642
+ */
643
+ verifyMerkleProof(input: {
644
+ leaf: Uint8Array
645
+ root: Uint8Array
646
+ proof: MerkleProof
647
+ }): Promise<boolean>;
648
+ /** Verify an `SpvProof`'s merkle inclusion against its own header root (membership only — not chain-authenticated). */
649
+ verifySpvProof(proof: SpvProof): Promise<boolean>;
650
+ /**
651
+ * Full header-authenticated SPV check via the adapter's `was-tx-mined`: the
652
+ * contract authenticates the proof's header against the chain
653
+ * (`get-burn-block-info? header-hash`), extracts its root, and proves
654
+ * inclusion — atomically. Returns `false` if the header isn't canonical at
655
+ * its height or the tx isn't included. This is the real "is it on Bitcoin" check.
656
+ */
657
+ wasTxMined(proof: SpvProof): Promise<boolean>;
658
+ /**
659
+ * Decode one output of a serialized Bitcoin tx via the adapter's
660
+ * `get-tx-output` (the native `get-bitcoin-tx-output?`).
661
+ */
662
+ getTxOutput(rawTx: Uint8Array, vout: number): Promise<DecodedTxOutput>;
663
+ }
664
+ /**
665
+ * Bind a `BitcoinVerifier` to a deployed adapter contract. There is a single,
666
+ * native target — no caps and no legacy `clarity-bitcoin` path. The built-ins do
667
+ * not exist until Clarity 6 / Epoch 4.0 activates, so read-only calls only
668
+ * succeed on a node at that epoch (a local Clarity-6 devnet, or mainnet after
669
+ * activation); guard with `isClarity6Active` when in doubt.
670
+ */
671
+ declare function bitcoinVerifier(client: Client, config: BitcoinVerifierConfig): BitcoinVerifier;
672
+ /**
673
+ * Render a parsed output script as a Bitcoin address for the given network.
674
+ * Returns `undefined` for scripts without a standard address (OP_RETURN, P2PK,
675
+ * unknown). Address encoding is network-dependent, which is why this is separate
676
+ * from the pure `parseOutputScript` decoder.
677
+ */
678
+ declare function formatBitcoinAddress(parsed: ParsedOutputScript, network?: BitcoinNetwork): string | undefined;
679
+ interface BitcoinPaymentOutput {
680
+ vout: number;
681
+ /** scriptPubKey bytes. */
682
+ script: Uint8Array;
683
+ /** Value in satoshis. */
684
+ amount: bigint;
685
+ type: OutputScriptType;
686
+ /** Address for the configured network, if the script has a standard one. */
687
+ address?: string;
688
+ }
689
+ interface VerifyBitcoinPaymentResult {
690
+ /** `mined` AND every supplied `expect` constraint holds. */
691
+ verified: boolean;
692
+ /**
693
+ * On-chain proof that the tx is committed in a Bitcoin block. With
694
+ * `authenticateHeader` (default), this is the adapter's `was-tx-mined` —
695
+ * header authenticated against the chain AND merkle inclusion. With it off,
696
+ * it is merkle inclusion against the proof's own (unauthenticated) header.
697
+ */
698
+ mined: boolean;
699
+ /** The decoded output at `vout`. */
700
+ output: BitcoinPaymentOutput;
701
+ /** The proof used (built or supplied). */
702
+ proof: SpvProof;
703
+ }
704
+ type VerifyBitcoinPaymentParams = ({
705
+ proof: SpvProof
706
+ } | {
707
+ txid: string
708
+ source: ProofSource
709
+ }) & {
710
+ /** Adapter contract principal, `"address.name"`. */
711
+ contract: string
712
+ /** Output index to decode and assert against. */
713
+ vout: number
714
+ /** Network for address formatting. Defaults to mainnet. */
715
+ network?: BitcoinNetwork
716
+ /** Optional expectations; each supplied field must match for `verified`. */
717
+ expect?: {
718
+ address?: string
719
+ amount?: bigint
720
+ }
721
+ /**
722
+ * Confirm the proof's header is the canonical block at its height via
723
+ * `get-header-merkle-root` (default true). Turn off only when the caller has
724
+ * already authenticated the header.
725
+ */
726
+ authenticateHeader?: boolean
727
+ sender?: string
728
+ };
729
+ /**
730
+ * Verify that a Bitcoin payment is committed on-chain and (optionally) matches
731
+ * an expected recipient/amount. Composes the whole SPV flow:
732
+ * 1. build the proof from a `ProofSource` (or accept a prepared `SpvProof`),
733
+ * 2. prove the tx is mined — `was-tx-mined` (header authenticated against the
734
+ * chain + merkle inclusion) by default, or membership-only when
735
+ * `authenticateHeader` is off,
736
+ * 3. decode the target output and assert any `expect` constraints.
737
+ *
738
+ * The output is decoded off-chain from the proof's raw tx, which is sound: the
739
+ * raw tx is pinned to the proven txid (`buildTxProof` checks it hashes to the
740
+ * leaf), so its bytes are committed.
741
+ */
742
+ declare function verifyBitcoinPayment(client: Client, params: VerifyBitcoinPaymentParams): Promise<VerifyBitcoinPaymentResult>;
743
+ export { verifyBitcoinPayment, stripWitness, rootFromProof, reverseBytes, parseOutputScript, parseBlockHeader, parseBitcoinTx, merkleRoot2 as merkleRoot, isClarity6Active, getBurnBlockHeight, formatBitcoinAddress, fallbackProofSource, esploraSource, encodeMerkleProofArgs, doubleSha256, decodeTxOutput, buildTxProof, buildMerkleProof, blockHash, bitcoinVerifier, bitcoinTxid, bitcoinRpcSource, VerifyBitcoinPaymentResult, VerifyBitcoinPaymentParams, SpvProof, SpvAdapterRef, SPV_ADAPTER_CONTRACTS, SPV_ADAPTER_ABI, ProofSource, ParsedOutputScript, ParsedBitcoinTx, OutputScriptType, MerkleProof, EsploraConfig, DecodedTxOutput, Clarity6Gate, BtcReader, BlockHeader, BlockForTx, BitcoinVerifierConfig, BitcoinVerifier, BitcoinTxOutput, BitcoinTxInput, BitcoinRpcConfig, BitcoinPaymentOutput, BitcoinNetwork };