@secondlayer/stacks 2.17.0 → 2.19.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/shared/stacks-rdgg7mj3.js +7 -0
- package/dist/shared/stacks-rdgg7mj3.js.map +10 -0
- package/dist/shared/stacks-wscmfs7q.cjs +5 -0
- package/dist/shared/stacks-wscmfs7q.cjs.map +10 -0
- package/dist/src/bitcoin/index.cjs +13 -6
- package/dist/src/bitcoin/index.cjs.map +5 -5
- package/dist/src/bitcoin/index.d.cts +33 -16
- package/dist/src/bitcoin/index.d.ts +33 -16
- package/dist/src/bitcoin/index.js +16 -6
- package/dist/src/bitcoin/index.js.map +5 -5
- package/dist/src/pox5/index.cjs +26 -2
- package/dist/src/pox5/index.cjs.map +4 -4
- package/dist/src/pox5/index.d.cts +21 -11
- package/dist/src/pox5/index.d.ts +21 -11
- package/dist/src/pox5/index.js +29 -2
- package/dist/src/pox5/index.js.map +4 -4
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/epochs.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * Stacks hard-fork epoch activation heights, as Bitcoin burn block heights.\n *\n * Epoch 4.0 carries both SIP-044 (the native Bitcoin SPV built-ins / Clarity 6)\n * and SIP-045 (`pox-5` Bitcoin Staking) — one fork, one height. Keep it here so\n * the two modules can never disagree.\n */\n\n/**\n * Epoch 4.0 activation height on mainnet — Bitcoin block 960,230 (~2026-07-30\n * AM UTC, per the stacks-core 4.0.1 release notes).\n *\n * Only mainnet has a fixed height. On other networks, read it from the node\n * (`getPox5Activation` for pox-5) or pass it explicitly.\n */\nexport const EPOCH_4_ACTIVATION_BURN_HEIGHT_MAINNET = 960_230;\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAeO,IAAM,yCAAyC;",
|
|
8
|
+
"debugId": "8EEE65BECBBFB88C64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/epochs.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * Stacks hard-fork epoch activation heights, as Bitcoin burn block heights.\n *\n * Epoch 4.0 carries both SIP-044 (the native Bitcoin SPV built-ins / Clarity 6)\n * and SIP-045 (`pox-5` Bitcoin Staking) — one fork, one height. Keep it here so\n * the two modules can never disagree.\n */\n\n/**\n * Epoch 4.0 activation height on mainnet — Bitcoin block 960,230 (~2026-07-30\n * AM UTC, per the stacks-core 4.0.1 release notes).\n *\n * Only mainnet has a fixed height. On other networks, read it from the node\n * (`getPox5Activation` for pox-5) or pass it explicitly.\n */\nexport const EPOCH_4_ACTIVATION_BURN_HEIGHT_MAINNET = 960_230;\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAeO,IAAM,yCAAyC;",
|
|
8
|
+
"debugId": "F5668139F3FAEE4164756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -30,6 +30,7 @@ __export(exports_bitcoin, {
|
|
|
30
30
|
bitcoinRpcSource: () => bitcoinRpcSource,
|
|
31
31
|
SPV_ADAPTER_CONTRACTS: () => SPV_ADAPTER_CONTRACTS,
|
|
32
32
|
SPV_ADAPTER_ABI: () => SPV_ADAPTER_ABI,
|
|
33
|
+
EPOCH_4_ACTIVATION_BURN_HEIGHT_MAINNET: () => EPOCH_4_ACTIVATION_BURN_HEIGHT_MAINNET,
|
|
33
34
|
BtcReader: () => BtcReader
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(exports_bitcoin);
|
|
@@ -344,7 +345,12 @@ function parseOutputScript(script) {
|
|
|
344
345
|
return { type: "unknown" };
|
|
345
346
|
}
|
|
346
347
|
// src/bitcoin/constants.ts
|
|
347
|
-
var SPV_ADAPTER_CONTRACTS = {
|
|
348
|
+
var SPV_ADAPTER_CONTRACTS = {
|
|
349
|
+
mainnet: {
|
|
350
|
+
address: "SP2M1DE95TS0QBM4K893X6ST49FFJ53CCX9CYWNVY",
|
|
351
|
+
name: "spv-adapter"
|
|
352
|
+
}
|
|
353
|
+
};
|
|
348
354
|
function getSpvAdapter(network) {
|
|
349
355
|
return SPV_ADAPTER_CONTRACTS[network];
|
|
350
356
|
}
|
|
@@ -416,11 +422,12 @@ async function getBurnBlockHeight(client) {
|
|
|
416
422
|
return info.burn_block_height;
|
|
417
423
|
}
|
|
418
424
|
async function isClarity6Active(client, gate = {}) {
|
|
419
|
-
|
|
420
|
-
|
|
425
|
+
const activation = gate.activationBurnHeight ?? (client.chain?.network === "mainnet" ? EPOCH_4_ACTIVATION_BURN_HEIGHT_MAINNET : undefined);
|
|
426
|
+
if (activation == null) {
|
|
427
|
+
throw new Error(`Clarity 6 (SIP-044 / Epoch 4.0) has no fixed activation height on ${client.chain?.network ?? "this network"} — pass { activationBurnHeight }`);
|
|
421
428
|
}
|
|
422
429
|
const current = await getBurnBlockHeight(client);
|
|
423
|
-
return current >=
|
|
430
|
+
return current >= activation;
|
|
424
431
|
}
|
|
425
432
|
// src/bitcoin/verifier.ts
|
|
426
433
|
function clarityToBool(cv) {
|
|
@@ -498,7 +505,7 @@ async function verifyBitcoinPayment(client, params) {
|
|
|
498
505
|
const adapter = getSpvAdapter(network);
|
|
499
506
|
const resolvedContract = contract ?? (adapter ? spvAdapterPrincipal(adapter) : undefined);
|
|
500
507
|
if (!resolvedContract) {
|
|
501
|
-
throw new Error(`No spv-adapter deployed for ${network} — pass an explicit \`contract
|
|
508
|
+
throw new Error(`No spv-adapter deployed for ${network} — pass an explicit \`contract\`. Only mainnet has a published reference adapter; the SIP-044 built-ins require Clarity 6 / Epoch 4.0 (deploy recipe: contracts/README.md).`);
|
|
502
509
|
}
|
|
503
510
|
const proof = "proof" in params ? params.proof : await buildTxProof(params.source, { txid: params.txid, vout });
|
|
504
511
|
const verifier = bitcoinVerifier(client, {
|
|
@@ -526,5 +533,5 @@ async function verifyBitcoinPayment(client, params) {
|
|
|
526
533
|
return { verified, mined, output, proof };
|
|
527
534
|
}
|
|
528
535
|
|
|
529
|
-
//# debugId=
|
|
536
|
+
//# debugId=AD5CA540E5C47D0F64756E2164756E21
|
|
530
537
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
"import { concatBytes } from \"../utils/encoding.ts\";\nimport { doubleSha256 } from \"./serialize.ts\";\n\n/**\n * A Bitcoin merkle inclusion proof, shaped for the SIP-044 `verify-merkle-proof`\n * built-in: `(leaf-hash, root-hash, tx-index, tx-count, sibling-hashes)`.\n *\n * - `siblings` are the sibling node hashes from the leaf up to (excluding) the\n * root, in *internal* byte order — never reversed.\n * - `txCount` (not tree-depth) pins the canonical tree shape; the built-in\n * rejects any proof whose length differs from `ceil(log2(tx-count))`.\n */\nexport interface MerkleProof {\n\tsiblings: Uint8Array[];\n\ttxIndex: number;\n\ttxCount: number;\n}\n\n/** Combine an ordered pair of nodes into their parent hash. */\nfunction hashPair(left: Uint8Array, right: Uint8Array): Uint8Array {\n\treturn doubleSha256(concatBytes(left, right));\n}\n\n/** Collapse one merkle level into the next, duplicating the last node if odd. */\nfunction nextLevel(level: Uint8Array[]): Uint8Array[] {\n\tconst next: Uint8Array[] = [];\n\tfor (let i = 0; i < level.length; i += 2) {\n\t\tconst left = level[i];\n\t\tif (left === undefined) throw new Error(\"merkle: missing left node\");\n\t\t// Bitcoin duplicates the final node when a level has an odd count.\n\t\tconst right = level[i + 1] ?? left;\n\t\tnext.push(hashPair(left, right));\n\t}\n\treturn next;\n}\n\n/**\n * Compute the merkle root over txids in *internal* byte order. The result is\n * also internal order — it matches the `merkle-root` field read straight out of\n * an 80-byte block header, so it can be cross-checked against the header before\n * a proof is trusted.\n */\nexport function merkleRoot(txidsInternal: Uint8Array[]): Uint8Array {\n\tif (txidsInternal.length === 0) {\n\t\tthrow new Error(\"merkleRoot: empty tx list\");\n\t}\n\tlet level = txidsInternal.slice();\n\twhile (level.length > 1) {\n\t\tlevel = nextLevel(level);\n\t}\n\tconst root = level[0];\n\tif (root === undefined) throw new Error(\"merkleRoot: no root\");\n\treturn root;\n}\n\n/**\n * Build the merkle inclusion proof for the tx at `txIndex`. Sibling count is\n * exactly `ceil(log2(txCount))`, as the SIP-044 built-in requires.\n */\nexport function buildMerkleProof(\n\ttxidsInternal: Uint8Array[],\n\ttxIndex: number,\n): MerkleProof {\n\tconst txCount = txidsInternal.length;\n\tif (txCount === 0) {\n\t\tthrow new Error(\"buildMerkleProof: empty tx list\");\n\t}\n\tif (txIndex < 0 || txIndex >= txCount) {\n\t\tthrow new Error(\n\t\t\t`buildMerkleProof: txIndex ${txIndex} out of range for ${txCount} txs`,\n\t\t);\n\t}\n\n\tconst siblings: Uint8Array[] = [];\n\tlet index = txIndex;\n\tlet level = txidsInternal.slice();\n\twhile (level.length > 1) {\n\t\tconst isRight = index % 2 === 1;\n\t\tconst siblingIndex = isRight ? index - 1 : index + 1;\n\t\tconst self = level[index];\n\t\tif (self === undefined) throw new Error(\"buildMerkleProof: missing node\");\n\t\t// When the node is the last of an odd level, it is paired with itself.\n\t\tsiblings.push(level[siblingIndex] ?? self);\n\t\tlevel = nextLevel(level);\n\t\tindex = Math.floor(index / 2);\n\t}\n\n\treturn { siblings, txIndex, txCount };\n}\n\n/**\n * Recompute the merkle root from a leaf + its proof — the same fold the on-chain\n * `verify-merkle-proof` performs. Use it off-chain to self-check a constructed\n * proof against the header's merkle root before submitting a contract call.\n */\nexport function rootFromProof(\n\tleafInternal: Uint8Array,\n\tproof: MerkleProof,\n): Uint8Array {\n\tlet hash = leafInternal;\n\tlet index = proof.txIndex;\n\tfor (const sibling of proof.siblings) {\n\t\thash = index % 2 === 1 ? hashPair(sibling, hash) : hashPair(hash, sibling);\n\t\tindex = Math.floor(index / 2);\n\t}\n\treturn hash;\n}\n",
|
|
6
6
|
"import { bytesToHex, hexToBytes, without0x } from \"../utils/encoding.ts\";\nimport { type MerkleProof, buildMerkleProof, rootFromProof } from \"./merkle.ts\";\nimport { parseBitcoinTx, parseBlockHeader, reverseBytes } from \"./serialize.ts\";\n\n/**\n * A self-contained Bitcoin SPV proof: everything the SIP-044 built-ins need to\n * prove a tx (and one of its outputs) is committed in a confirmed block. Hashes\n * are internal byte order throughout.\n */\nexport interface SpvProof {\n\trawTx: Uint8Array;\n\t/** The tx's txid, internal order — the merkle leaf. */\n\ttxidInternal: Uint8Array;\n\t/** Output index of interest, if the proof targets a specific output. */\n\tvout?: number;\n\tmerkle: MerkleProof;\n\t/** The 80-byte block header that commits the tx. */\n\theader: Uint8Array;\n\t/** Bitcoin block height. */\n\theight: number;\n}\n\n/** The block context a `ProofSource` resolves for a confirmed tx. */\nexport interface BlockForTx {\n\t/** 80-byte block header. */\n\theader: Uint8Array;\n\theight: number;\n\t/** All of the block's txids, internal order, in block order. */\n\ttxidsInternal: Uint8Array[];\n\t/** Index of the target tx within the block. */\n\ttxIndex: number;\n}\n\n/**\n * Where proof inputs come from. The default is the integrator's own Bitcoin node\n * (`bitcoinRpcSource`) — trustless; a hosted Esplora-compatible endpoint\n * (`esploraSource`) is the fallback. `buildTxProof` independently re-checks\n * whatever a source returns, so a wrong or hostile source fails loudly rather\n * than producing a bad proof.\n */\nexport interface ProofSource {\n\t/** Raw (serialized) tx bytes for a txid (display-order hex). */\n\tgetRawTx(txid: string): Promise<Uint8Array>;\n\t/** The confirming block's header, height, and txid set for a txid. */\n\tgetBlockForTx(txid: string): Promise<BlockForTx>;\n}\n\nfunction normalizeTxid(txid: string): string {\n\treturn without0x(txid).toLowerCase();\n}\n\n/**\n * Locate `txid` in a block's txid set and assemble its `BlockForTx`. Owns the\n * display→internal byte-order reversal (`reverseBytes`) so the ProofSources\n * can't drift on the one operation a silent merkle-root mismatch would hide.\n * `txidsDisplay` are display-order hex txids as returned by Core / Esplora.\n */\nfunction assembleBlockForTx(args: {\n\ttxid: string;\n\tblockId: string;\n\theaderHex: string;\n\theight: number;\n\ttxidsDisplay: string[];\n}): BlockForTx {\n\tconst txIndex = args.txidsDisplay.indexOf(normalizeTxid(args.txid));\n\tif (txIndex < 0) {\n\t\tthrow new Error(`tx ${args.txid} not found in block ${args.blockId}`);\n\t}\n\treturn {\n\t\theader: hexToBytes(args.headerHex),\n\t\theight: args.height,\n\t\ttxidsInternal: args.txidsDisplay.map((t) => reverseBytes(hexToBytes(t))),\n\t\ttxIndex,\n\t};\n}\n\n/**\n * Assemble an `SpvProof` for a txid from a `ProofSource`, validating every claim\n * the source makes:\n * - the returned raw tx actually hashes to the requested txid,\n * - the claimed `txIndex` points at that txid in the block, and\n * - the resulting merkle proof folds back to the block header's merkle root.\n * Any mismatch throws — the proof is never returned half-trusted.\n */\nexport async function buildTxProof(\n\tsource: ProofSource,\n\tparams: { txid: string; vout?: number },\n): Promise<SpvProof> {\n\tconst { txid, vout } = params;\n\tconst want = normalizeTxid(txid);\n\n\tconst [rawTx, block] = await Promise.all([\n\t\tsource.getRawTx(txid),\n\t\tsource.getBlockForTx(txid),\n\t]);\n\n\tconst parsed = parseBitcoinTx(rawTx);\n\tconst gotDisplay = bytesToHex(reverseBytes(parsed.txidInternal));\n\tif (gotDisplay !== want) {\n\t\tthrow new Error(\n\t\t\t`source returned a tx whose id ${gotDisplay} does not match requested ${want}`,\n\t\t);\n\t}\n\n\tconst atIndex = block.txidsInternal[block.txIndex];\n\tif (!atIndex || bytesToHex(atIndex) !== bytesToHex(parsed.txidInternal)) {\n\t\tthrow new Error(\n\t\t\t`source txIndex ${block.txIndex} does not point at tx ${want}`,\n\t\t);\n\t}\n\n\tconst merkle = buildMerkleProof(block.txidsInternal, block.txIndex);\n\n\tconst headerRoot = parseBlockHeader(block.header).merkleRoot;\n\tconst computed = rootFromProof(parsed.txidInternal, merkle);\n\tif (bytesToHex(computed) !== bytesToHex(headerRoot)) {\n\t\tthrow new Error(\n\t\t\t\"constructed merkle proof does not reconcile with the block header merkle root\",\n\t\t);\n\t}\n\n\treturn {\n\t\trawTx,\n\t\ttxidInternal: parsed.txidInternal,\n\t\tvout,\n\t\tmerkle,\n\t\theader: block.header,\n\t\theight: block.height,\n\t};\n}\n\n/**\n * Compose sources into an ordered fallback chain: each call tries them in turn\n * and returns the first success, throwing the last error if all fail. Put the\n * trustless integrator node first and a hosted endpoint last.\n */\nexport function fallbackProofSource(sources: ProofSource[]): ProofSource {\n\tif (sources.length === 0) {\n\t\tthrow new Error(\"fallbackProofSource: at least one source is required\");\n\t}\n\tasync function firstSuccess<T>(\n\t\tfn: (s: ProofSource) => Promise<T>,\n\t): Promise<T> {\n\t\tlet lastError: unknown;\n\t\tfor (const source of sources) {\n\t\t\ttry {\n\t\t\t\treturn await fn(source);\n\t\t\t} catch (error) {\n\t\t\t\tlastError = error;\n\t\t\t}\n\t\t}\n\t\tthrow lastError;\n\t}\n\treturn {\n\t\tgetRawTx: (txid) => firstSuccess((s) => s.getRawTx(txid)),\n\t\tgetBlockForTx: (txid) => firstSuccess((s) => s.getBlockForTx(txid)),\n\t};\n}\n\nexport interface BitcoinRpcConfig {\n\t/** Bitcoin Core JSON-RPC endpoint URL. */\n\turl: string;\n\t/** Basic auth — `{ username, password }` or a pre-encoded base64 string. */\n\tauth?: { username: string; password: string } | string;\n\t/** Override the fetch implementation (testing / custom agents). */\n\tfetch?: typeof fetch;\n}\n\n/**\n * A `ProofSource` backed by the integrator's own Bitcoin Core node over\n * JSON-RPC. This is the trustless default. The node must run with `-txindex`\n * (or the tx must be in the mempool's block view) so `getrawtransaction` can\n * resolve the confirming block.\n */\nexport function bitcoinRpcSource(config: BitcoinRpcConfig): ProofSource {\n\tconst doFetch = config.fetch ?? fetch;\n\n\tasync function rpc<T>(method: string, rpcParams: unknown[]): Promise<T> {\n\t\tconst headers: Record<string, string> = {\n\t\t\t\"content-type\": \"application/json\",\n\t\t};\n\t\tif (config.auth) {\n\t\t\tconst basic =\n\t\t\t\ttypeof config.auth === \"string\"\n\t\t\t\t\t? config.auth\n\t\t\t\t\t: btoa(`${config.auth.username}:${config.auth.password}`);\n\t\t\theaders.authorization = `Basic ${basic}`;\n\t\t}\n\t\tconst res = await doFetch(config.url, {\n\t\t\tmethod: \"POST\",\n\t\t\theaders,\n\t\t\tbody: JSON.stringify({\n\t\t\t\tjsonrpc: \"1.0\",\n\t\t\t\tid: \"secondlayer\",\n\t\t\t\tmethod,\n\t\t\t\tparams: rpcParams,\n\t\t\t}),\n\t\t});\n\t\tif (!res.ok) {\n\t\t\tthrow new Error(`bitcoin rpc ${method} failed: HTTP ${res.status}`);\n\t\t}\n\t\tconst json = (await res.json()) as {\n\t\t\tresult: T;\n\t\t\terror: { message: string } | null;\n\t\t};\n\t\tif (json.error) {\n\t\t\tthrow new Error(`bitcoin rpc ${method} error: ${json.error.message}`);\n\t\t}\n\t\treturn json.result;\n\t}\n\n\treturn {\n\t\tasync getRawTx(txid) {\n\t\t\treturn hexToBytes(await rpc<string>(\"getrawtransaction\", [txid, false]));\n\t\t},\n\t\tasync getBlockForTx(txid) {\n\t\t\tconst tx = await rpc<{ blockhash?: string }>(\"getrawtransaction\", [\n\t\t\t\ttxid,\n\t\t\t\ttrue,\n\t\t\t]);\n\t\t\tif (!tx.blockhash) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`tx ${txid} is not in a block (node needs -txindex, or the tx is unconfirmed)`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst block = await rpc<{ tx: string[]; height: number }>(\"getblock\", [\n\t\t\t\ttx.blockhash,\n\t\t\t\t1,\n\t\t\t]);\n\t\t\tconst header = await rpc<string>(\"getblockheader\", [tx.blockhash, false]);\n\t\t\treturn assembleBlockForTx({\n\t\t\t\ttxid,\n\t\t\t\tblockId: tx.blockhash,\n\t\t\t\theaderHex: header,\n\t\t\t\theight: block.height,\n\t\t\t\ttxidsDisplay: block.tx,\n\t\t\t});\n\t\t},\n\t};\n}\n\nexport interface EsploraConfig {\n\t/** Esplora REST base URL, e.g. `https://blockstream.info/api` or a self-hosted instance. */\n\turl: string;\n\t/** Override the fetch implementation. */\n\tfetch?: typeof fetch;\n}\n\n/**\n * A `ProofSource` backed by an Esplora REST API (self-hosted, or a hosted\n * provider as a fallback). Provider-agnostic: any Esplora-compatible endpoint\n * works. Use as the hosted fallback behind `bitcoinRpcSource`.\n */\nexport function esploraSource(config: EsploraConfig): ProofSource {\n\tconst doFetch = config.fetch ?? fetch;\n\tconst base = config.url.replace(/\\/+$/, \"\");\n\n\tasync function get(path: string): Promise<Response> {\n\t\tconst res = await doFetch(`${base}${path}`);\n\t\tif (!res.ok) {\n\t\t\tthrow new Error(`esplora GET ${path} failed: HTTP ${res.status}`);\n\t\t}\n\t\treturn res;\n\t}\n\n\treturn {\n\t\tasync getRawTx(txid) {\n\t\t\treturn hexToBytes((await (await get(`/tx/${txid}/hex`)).text()).trim());\n\t\t},\n\t\tasync getBlockForTx(txid) {\n\t\t\tconst status = (await (await get(`/tx/${txid}`)).json()) as {\n\t\t\t\tstatus: {\n\t\t\t\t\tconfirmed: boolean;\n\t\t\t\t\tblock_height: number;\n\t\t\t\t\tblock_hash: string;\n\t\t\t\t};\n\t\t\t};\n\t\t\tif (!status.status.confirmed) {\n\t\t\t\tthrow new Error(`tx ${txid} is unconfirmed`);\n\t\t\t}\n\t\t\tconst blockHashHex = status.status.block_hash;\n\t\t\tconst header = (\n\t\t\t\tawait (await get(`/block/${blockHashHex}/header`)).text()\n\t\t\t).trim();\n\t\t\tconst txids = (await (\n\t\t\t\tawait get(`/block/${blockHashHex}/txids`)\n\t\t\t).json()) as string[];\n\t\t\treturn assembleBlockForTx({\n\t\t\t\ttxid,\n\t\t\t\tblockId: blockHashHex,\n\t\t\t\theaderHex: header,\n\t\t\t\theight: status.status.block_height,\n\t\t\t\ttxidsDisplay: txids,\n\t\t\t});\n\t\t},\n\t};\n}\n",
|
|
7
7
|
"import {\n\ttype BufferCV,\n\ttype ClarityValue,\n\ttype ListCV,\n\ttype TupleCV,\n\ttype UIntCV,\n\tbufferCV,\n\tlistCV,\n\tuintCV,\n} from \"../clarity/index.ts\";\nimport { hexToBytes } from \"../utils/encoding.ts\";\nimport type { MerkleProof } from \"./merkle.ts\";\n\n/**\n * Number of merkle levels for a tree of `txCount` leaves — i.e. the exact\n * sibling count the SIP-044 `verify-merkle-proof` built-in expects\n * (`ceil(log2(tx-count))`). Computed by repeated halving to avoid float error\n * at exact powers of two.\n */\nfunction merkleDepth(txCount: number): number {\n\tlet depth = 0;\n\tlet n = txCount;\n\twhile (n > 1) {\n\t\tn = Math.ceil(n / 2);\n\t\tdepth++;\n\t}\n\treturn depth;\n}\n\n/** Max siblings the native `verify-merkle-proof` accepts: `(list 24 (buff 32))`. */\nconst MAX_SIBLINGS = 24;\n\nfunction assertHash32(bytes: Uint8Array, label: string): void {\n\tif (bytes.length !== 32) {\n\t\tthrow new Error(`${label} must be 32 bytes, got ${bytes.length}`);\n\t}\n}\n\n/**\n * Encode the argument vector for the SIP-044 native built-in\n * `(verify-merkle-proof leaf-hash root-hash tx-index tx-count sibling-hashes)`.\n *\n * Returns the five args in order: `[leaf, root, tx-index, tx-count, siblings]`.\n * All hashes are passed in *internal* (raw) byte order — the built-in does NOT\n * reverse, and neither does this. The leaf is the tx's `txidInternal`; the root\n * is the block header's merkle root in internal order.\n *\n * Throws on shapes the built-in would reject, so a caller fails locally with a\n * clear message instead of an opaque on-chain `false`.\n */\nexport function encodeMerkleProofArgs(params: {\n\tleaf: Uint8Array;\n\troot: Uint8Array;\n\tproof: MerkleProof;\n}): [BufferCV, BufferCV, UIntCV, UIntCV, ListCV] {\n\tconst { leaf, root, proof } = params;\n\tassertHash32(leaf, \"merkle leaf\");\n\tassertHash32(root, \"merkle root\");\n\n\tif (proof.txIndex < 0 || proof.txIndex >= proof.txCount) {\n\t\tthrow new Error(\n\t\t\t`tx-index ${proof.txIndex} out of range for tx-count ${proof.txCount}`,\n\t\t);\n\t}\n\tif (proof.siblings.length > MAX_SIBLINGS) {\n\t\tthrow new Error(\n\t\t\t`proof has ${proof.siblings.length} siblings, native verify-merkle-proof caps at ${MAX_SIBLINGS}`,\n\t\t);\n\t}\n\tconst expectedDepth = merkleDepth(proof.txCount);\n\tif (proof.siblings.length !== expectedDepth) {\n\t\tthrow new Error(\n\t\t\t`proof has ${proof.siblings.length} siblings but tx-count ${proof.txCount} requires exactly ${expectedDepth}`,\n\t\t);\n\t}\n\tfor (const [i, sibling] of proof.siblings.entries()) {\n\t\tassertHash32(sibling, `sibling ${i}`);\n\t}\n\n\treturn [\n\t\tbufferCV(leaf),\n\t\tbufferCV(root),\n\t\tuintCV(proof.txIndex),\n\t\tuintCV(proof.txCount),\n\t\tlistCV(proof.siblings.map((s) => bufferCV(s))),\n\t];\n}\n\nexport interface DecodedTxOutput {\n\t/** scriptPubKey bytes. */\n\tscript: Uint8Array;\n\t/** Output value in satoshis. */\n\tamount: bigint;\n\t/** The tx's txid in internal byte order — ready as a merkle leaf. */\n\ttxid: Uint8Array;\n}\n\nfunction expectBuffer(cv: ClarityValue | undefined, label: string): Uint8Array {\n\tif (cv?.type !== \"buffer\") {\n\t\tthrow new Error(`expected ${label} to be a buffer, got ${cv?.type}`);\n\t}\n\treturn hexToBytes(cv.value);\n}\n\n/**\n * Decode the tuple returned by `get-bitcoin-tx-output?`:\n * `(tuple (script (buff 1024)) (amount uint) (txid (buff 32)))`.\n *\n * Accepts either the bare tuple or a `(response ok ...)` wrapping it, so it\n * works whether or not the caller has already unwrapped the response.\n */\nexport function decodeTxOutput(cv: ClarityValue): DecodedTxOutput {\n\tconst tuple: ClarityValue = cv.type === \"ok\" ? cv.value : cv;\n\tif (tuple.type !== \"tuple\") {\n\t\tthrow new Error(`expected a tuple, got ${tuple.type}`);\n\t}\n\tconst fields = (tuple as TupleCV).value;\n\tconst amount = fields.amount;\n\tif (amount?.type !== \"uint\") {\n\t\tthrow new Error(\n\t\t\t`expected tuple field \"amount\" to be uint, got ${amount?.type}`,\n\t\t);\n\t}\n\treturn {\n\t\tscript: expectBuffer(fields.script, 'tuple field \"script\"'),\n\t\tamount: amount.value,\n\t\ttxid: expectBuffer(fields.txid, 'tuple field \"txid\"'),\n\t};\n}\n\nexport type OutputScriptType =\n\t| \"p2pkh\"\n\t| \"p2sh\"\n\t| \"p2wpkh\"\n\t| \"p2wsh\"\n\t| \"p2tr\"\n\t| \"op_return\"\n\t| \"unknown\";\n\nexport interface ParsedOutputScript {\n\ttype: OutputScriptType;\n\t/**\n\t * The hash / witness program for the recognized output types: the 20-byte\n\t * pubkey-hash (p2pkh), 20-byte script-hash (p2sh), or the 20/32-byte witness\n\t * program (p2wpkh/p2wsh/p2tr). Undefined for op_return / unknown.\n\t *\n\t * Address formatting is intentionally left to the caller — base58/bech32 HRPs\n\t * and version bytes are network-dependent, so it belongs where the network is\n\t * known (see `verifyBitcoinPayment`), not in this pure decoder.\n\t */\n\thash?: Uint8Array;\n\t/** OP_RETURN payload (the pushed data after the OP_RETURN opcode). */\n\tdata?: Uint8Array;\n}\n\nconst OP_DUP = 0x76;\nconst OP_HASH160 = 0xa9;\nconst OP_EQUALVERIFY = 0x88;\nconst OP_CHECKSIG = 0xac;\nconst OP_EQUAL = 0x87;\nconst OP_RETURN = 0x6a;\nconst OP_0 = 0x00;\nconst OP_1 = 0x51;\n\n/**\n * Classify a Bitcoin output scriptPubKey by its standard template and surface\n * the embedded hash / witness program. Recognizes P2PKH, P2SH, P2WPKH, P2WSH,\n * P2TR, and OP_RETURN; anything else is `unknown`.\n */\nexport function parseOutputScript(script: Uint8Array): ParsedOutputScript {\n\tconst n = script.length;\n\n\t// P2PKH: OP_DUP OP_HASH160 <20> ... OP_EQUALVERIFY OP_CHECKSIG\n\tif (\n\t\tn === 25 &&\n\t\tscript[0] === OP_DUP &&\n\t\tscript[1] === OP_HASH160 &&\n\t\tscript[2] === 0x14 &&\n\t\tscript[23] === OP_EQUALVERIFY &&\n\t\tscript[24] === OP_CHECKSIG\n\t) {\n\t\treturn { type: \"p2pkh\", hash: script.slice(3, 23) };\n\t}\n\n\t// P2SH: OP_HASH160 <20> ... OP_EQUAL\n\tif (\n\t\tn === 23 &&\n\t\tscript[0] === OP_HASH160 &&\n\t\tscript[1] === 0x14 &&\n\t\tscript[22] === OP_EQUAL\n\t) {\n\t\treturn { type: \"p2sh\", hash: script.slice(2, 22) };\n\t}\n\n\t// P2WPKH: OP_0 <20>\n\tif (n === 22 && script[0] === OP_0 && script[1] === 0x14) {\n\t\treturn { type: \"p2wpkh\", hash: script.slice(2, 22) };\n\t}\n\n\t// P2WSH: OP_0 <32>\n\tif (n === 34 && script[0] === OP_0 && script[1] === 0x20) {\n\t\treturn { type: \"p2wsh\", hash: script.slice(2, 34) };\n\t}\n\n\t// P2TR: OP_1 <32>\n\tif (n === 34 && script[0] === OP_1 && script[1] === 0x20) {\n\t\treturn { type: \"p2tr\", hash: script.slice(2, 34) };\n\t}\n\n\t// OP_RETURN: data carrier\n\tif (n >= 1 && script[0] === OP_RETURN) {\n\t\treturn { type: \"op_return\", data: script.slice(1) };\n\t}\n\n\treturn { type: \"unknown\" };\n}\n",
|
|
8
|
-
"export type BitcoinNetwork = \"mainnet\" | \"testnet\" | \"regtest\";\n\nexport interface SpvAdapterRef {\n\t/** Deployer principal. */\n\taddress: string;\n\t/** Contract name. */\n\tname: string;\n}\n\n/**\n * Reference `spv-adapter` deployments (the read-only wrapper around the SIP-044\n * built-ins) — the single source of truth for the published adapter principal.\n *
|
|
8
|
+
"export type BitcoinNetwork = \"mainnet\" | \"testnet\" | \"regtest\";\n\nexport interface SpvAdapterRef {\n\t/** Deployer principal. */\n\taddress: string;\n\t/** Contract name. */\n\tname: string;\n}\n\n/**\n * Reference `spv-adapter` deployments (the read-only wrapper around the SIP-044\n * built-ins) — the single source of truth for the published adapter principal.\n * A network is listed only once its adapter is deployed AND verified against a\n * real Bitcoin header; `verifyBitcoinPayment` requires an explicit `contract`\n * for any network absent here (deploy recipe: `contracts/README.md`).\n *\n * `testnet` is absent because Stacks testnet has no Epoch 4.0 — the SIP-044\n * built-ins do not exist there, so the contract cannot be deployed.\n */\nexport const SPV_ADAPTER_CONTRACTS: Partial<\n\tRecord<BitcoinNetwork, SpvAdapterRef>\n> = {\n\tmainnet: {\n\t\taddress: \"SP2M1DE95TS0QBM4K893X6ST49FFJ53CCX9CYWNVY\",\n\t\tname: \"spv-adapter\",\n\t},\n};\n\n/** Resolve the reference adapter for a network, or `undefined` if none is deployed yet. */\nexport function getSpvAdapter(\n\tnetwork: BitcoinNetwork,\n): SpvAdapterRef | undefined {\n\treturn SPV_ADAPTER_CONTRACTS[network];\n}\n\n/** A `\"address.name\"` contract principal from an adapter ref. */\nexport function spvAdapterPrincipal(ref: SpvAdapterRef): string {\n\treturn `${ref.address}.${ref.name}`;\n}\n",
|
|
9
9
|
"import type { AbiContract } from \"../../clarity/abi/index.ts\";\n\n/**\n * ABI for the reference `spv-adapter` contract — a thin, read-only wrapper that\n * exposes the SIP-044 Bitcoin built-ins (callable only from within a Clarity\n * contract) over read-only RPC. Plan 013 deploys a contract matching this shape;\n * `bitcoinVerifier` binds to it (or to an integrator's own contract with the\n * same surface).\n *\n * Hashes are internal (raw) byte order — the same as the built-ins. Do NOT\n * reverse before calling.\n */\nexport const SPV_ADAPTER_ABI = {\n\tfunctions: [\n\t\t{\n\t\t\t// (get-bitcoin-tx-output? tx vout)\n\t\t\tname: \"get-tx-output\",\n\t\t\taccess: \"read-only\",\n\t\t\targs: [\n\t\t\t\t{ name: \"tx\", type: { buff: { length: 4096 } } },\n\t\t\t\t{ name: \"vout\", type: \"uint128\" },\n\t\t\t],\n\t\t\toutputs: {\n\t\t\t\tresponse: {\n\t\t\t\t\tok: {\n\t\t\t\t\t\ttuple: [\n\t\t\t\t\t\t\t{ name: \"script\", type: { buff: { length: 1024 } } },\n\t\t\t\t\t\t\t{ name: \"amount\", type: \"uint128\" },\n\t\t\t\t\t\t\t{ name: \"txid\", type: { buff: { length: 32 } } },\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t\terror: \"uint128\",\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\t// (verify-merkle-proof leaf-hash root-hash tx-index tx-count sibling-hashes)\n\t\t\tname: \"verify-merkle\",\n\t\t\taccess: \"read-only\",\n\t\t\targs: [\n\t\t\t\t{ name: \"leaf\", type: { buff: { length: 32 } } },\n\t\t\t\t{ name: \"root\", type: { buff: { length: 32 } } },\n\t\t\t\t{ name: \"tx-index\", type: \"uint128\" },\n\t\t\t\t{ name: \"tx-count\", type: \"uint128\" },\n\t\t\t\t{\n\t\t\t\t\tname: \"siblings\",\n\t\t\t\t\ttype: { list: { type: { buff: { length: 32 } }, length: 24 } },\n\t\t\t\t},\n\t\t\t],\n\t\t\toutputs: \"bool\",\n\t\t},\n\t\t{\n\t\t\t// Composed SPV check: authenticate the caller-supplied header against\n\t\t\t// `(get-burn-block-info? header-hash height)`, extract its merkle root,\n\t\t\t// and `verify-merkle-proof` tx inclusion under it — atomically on-chain.\n\t\t\t// (ok true) = mined, (ok false) = header valid but tx not included,\n\t\t\t// (err ...) = header not authentic at that height.\n\t\t\tname: \"was-tx-mined\",\n\t\t\taccess: \"read-only\",\n\t\t\targs: [\n\t\t\t\t{ name: \"header\", type: { buff: { length: 80 } } },\n\t\t\t\t{ name: \"height\", type: \"uint128\" },\n\t\t\t\t{ name: \"leaf\", type: { buff: { length: 32 } } },\n\t\t\t\t{ name: \"tx-index\", type: \"uint128\" },\n\t\t\t\t{ name: \"tx-count\", type: \"uint128\" },\n\t\t\t\t{\n\t\t\t\t\tname: \"siblings\",\n\t\t\t\t\ttype: { list: { type: { buff: { length: 32 } }, length: 24 } },\n\t\t\t\t},\n\t\t\t],\n\t\t\toutputs: { response: { ok: \"bool\", error: \"uint128\" } },\n\t\t},\n\t],\n} as const satisfies AbiContract;\n",
|
|
10
|
-
"import type { Client } from \"../clients/types.ts\";\nimport { MalformedResponseError } from \"../errors/response.ts\";\n\n/**\n * SIP-044 (the native Bitcoin SPV built-ins) activates as part of the **Stacks\n * Epoch 4.0 hard fork
|
|
10
|
+
"import type { Client } from \"../clients/types.ts\";\nimport { EPOCH_4_ACTIVATION_BURN_HEIGHT_MAINNET } from \"../epochs.ts\";\nimport { MalformedResponseError } from \"../errors/response.ts\";\n\n/**\n * SIP-044 (the native Bitcoin SPV built-ins) activates as part of the **Stacks\n * Epoch 4.0 hard fork** — the same fork that ships `pox-5` (SIP-045), so both\n * share one height: {@link EPOCH_4_ACTIVATION_BURN_HEIGHT_MAINNET}.\n */\nexport interface Clarity6Gate {\n\t/**\n\t * Bitcoin burn block height at which Clarity 6 / Epoch 4.0 activates.\n\t * Optional on a mainnet client, which falls back to the known mainnet\n\t * height; required on every other network, where no fixed height exists.\n\t */\n\tactivationBurnHeight?: number;\n}\n\n/** Read the node's current Bitcoin burn block height from `/v2/info`. */\nexport async function getBurnBlockHeight(client: Client): Promise<number> {\n\tconst info = (await client.request(\"/v2/info\")) as {\n\t\tburn_block_height?: number;\n\t};\n\tif (typeof info?.burn_block_height !== \"number\") {\n\t\tthrow new MalformedResponseError(\n\t\t\t'getBurnBlockHeight: /v2/info response is missing \"burn_block_height\"',\n\t\t);\n\t}\n\treturn info.burn_block_height;\n}\n\n/**\n * Whether Clarity 6 (the native SPV built-ins) is active on the node behind\n * `client`. Compares the node's current burn height to the SIP-044 / Epoch 4.0\n * activation height: the known mainnet height when `client.chain` is mainnet,\n * otherwise the one you supply. `bitcoinVerifier` uses this to refuse calls\n * before activation rather than failing with an opaque contract error.\n */\nexport async function isClarity6Active(\n\tclient: Client,\n\tgate: Clarity6Gate = {},\n): Promise<boolean> {\n\tconst activation =\n\t\tgate.activationBurnHeight ??\n\t\t(client.chain?.network === \"mainnet\"\n\t\t\t? EPOCH_4_ACTIVATION_BURN_HEIGHT_MAINNET\n\t\t\t: undefined);\n\tif (activation == null) {\n\t\tthrow new Error(\n\t\t\t`Clarity 6 (SIP-044 / Epoch 4.0) has no fixed activation height on ${client.chain?.network ?? \"this network\"} — pass { activationBurnHeight }`,\n\t\t);\n\t}\n\tconst current = await getBurnBlockHeight(client);\n\treturn current >= activation;\n}\n",
|
|
11
11
|
"import { readContract } from \"../actions/public/readContract.ts\";\nimport {\n\ttype ClarityValue,\n\tbufferCV,\n\tlistCV,\n\tuintCV,\n} from \"../clarity/index.ts\";\nimport type { Client } from \"../clients/types.ts\";\nimport {\n\ttype DecodedTxOutput,\n\tdecodeTxOutput,\n\tencodeMerkleProofArgs,\n} from \"./codec.ts\";\nimport type { MerkleProof } from \"./merkle.ts\";\nimport type { SpvProof } from \"./proof.ts\";\nimport { parseBlockHeader } from \"./serialize.ts\";\n\nexport interface BitcoinVerifierConfig {\n\t/** Adapter contract principal, `\"address.name\"` (the reference `spv-adapter` or an integrator's own). */\n\tcontract: string;\n\t/** Optional read-only call sender; defaults to the contract address. */\n\tsender?: string;\n}\n\nexport interface BitcoinVerifier {\n\t/**\n\t * Verify a merkle inclusion proof against a supplied root via the adapter's\n\t * `verify-merkle` (the native `verify-merkle-proof`). This proves membership\n\t * under `root`; authenticating that `root` belongs to a canonical Bitcoin\n\t * block is a separate step (header → height), composed in `verifyBitcoinPayment`.\n\t */\n\tverifyMerkleProof(input: {\n\t\tleaf: Uint8Array;\n\t\troot: Uint8Array;\n\t\tproof: MerkleProof;\n\t}): Promise<boolean>;\n\t/** Verify an `SpvProof`'s merkle inclusion against its own header root (membership only — not chain-authenticated). */\n\tverifySpvProof(proof: SpvProof): Promise<boolean>;\n\t/**\n\t * Full header-authenticated SPV check via the adapter's `was-tx-mined`: the\n\t * contract authenticates the proof's header against the chain\n\t * (`get-burn-block-info? header-hash`), extracts its root, and proves\n\t * inclusion — atomically. Returns `false` if the header isn't canonical at\n\t * its height or the tx isn't included. This is the real \"is it on Bitcoin\" check.\n\t */\n\twasTxMined(proof: SpvProof): Promise<boolean>;\n\t/**\n\t * Decode one output of a serialized Bitcoin tx via the adapter's\n\t * `get-tx-output` (the native `get-bitcoin-tx-output?`).\n\t */\n\tgetTxOutput(rawTx: Uint8Array, vout: number): Promise<DecodedTxOutput>;\n}\n\nfunction clarityToBool(cv: ClarityValue): boolean {\n\tconst value = cv.type === \"ok\" ? cv.value : cv;\n\tif (value.type === \"true\") return true;\n\tif (value.type === \"false\") return false;\n\tthrow new Error(`expected a boolean result, got ${value.type}`);\n}\n\n/**\n * Bind a `BitcoinVerifier` to a deployed adapter contract. There is a single,\n * native target — no caps and no legacy `clarity-bitcoin` path. The built-ins do\n * not exist until Clarity 6 / Epoch 4.0 activates, so read-only calls only\n * succeed on a node at that epoch (a local Clarity-6 devnet, or mainnet after\n * activation); guard with `isClarity6Active` when in doubt.\n */\nexport function bitcoinVerifier(\n\tclient: Client,\n\tconfig: BitcoinVerifierConfig,\n): BitcoinVerifier {\n\tconst { contract, sender } = config;\n\n\tasync function verifyMerkleProof(input: {\n\t\tleaf: Uint8Array;\n\t\troot: Uint8Array;\n\t\tproof: MerkleProof;\n\t}): Promise<boolean> {\n\t\tconst args = encodeMerkleProofArgs(input);\n\t\tconst result = await readContract(client, {\n\t\t\tcontract,\n\t\t\tfunctionName: \"verify-merkle\",\n\t\t\targs,\n\t\t\tsender,\n\t\t});\n\t\treturn clarityToBool(result);\n\t}\n\n\treturn {\n\t\tverifyMerkleProof,\n\t\tverifySpvProof(proof) {\n\t\t\tconst root = parseBlockHeader(proof.header).merkleRoot;\n\t\t\treturn verifyMerkleProof({\n\t\t\t\tleaf: proof.txidInternal,\n\t\t\t\troot,\n\t\t\t\tproof: proof.merkle,\n\t\t\t});\n\t\t},\n\t\tasync wasTxMined(proof) {\n\t\t\tconst result = await readContract(client, {\n\t\t\t\tcontract,\n\t\t\t\tfunctionName: \"was-tx-mined\",\n\t\t\t\targs: [\n\t\t\t\t\tbufferCV(proof.header),\n\t\t\t\t\tuintCV(proof.height),\n\t\t\t\t\tbufferCV(proof.txidInternal),\n\t\t\t\t\tuintCV(proof.merkle.txIndex),\n\t\t\t\t\tuintCV(proof.merkle.txCount),\n\t\t\t\t\tlistCV(proof.merkle.siblings.map((s) => bufferCV(s))),\n\t\t\t\t],\n\t\t\t\tsender,\n\t\t\t});\n\t\t\t// (response bool uint): (ok true) mined, (ok false) not, (err) bad header → fail closed.\n\t\t\tif (result.type === \"err\") return false;\n\t\t\treturn clarityToBool(result);\n\t\t},\n\t\tasync getTxOutput(rawTx, vout) {\n\t\t\tconst result = await readContract(client, {\n\t\t\t\tcontract,\n\t\t\t\tfunctionName: \"get-tx-output\",\n\t\t\t\targs: [bufferCV(rawTx), uintCV(vout)],\n\t\t\t\tsender,\n\t\t\t});\n\t\t\tif (result.type === \"err\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`get-tx-output failed on-chain: ${JSON.stringify(result.value)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn decodeTxOutput(result);\n\t\t},\n\t};\n}\n",
|
|
12
|
-
"import type { Client } from \"../clients/types.ts\";\nimport { formatBitcoinAddress } from \"./address.ts\";\nimport { type OutputScriptType, parseOutputScript } from \"./codec.ts\";\nimport {\n\ttype BitcoinNetwork,\n\tgetSpvAdapter,\n\tspvAdapterPrincipal,\n} from \"./constants.ts\";\nimport { type ProofSource, type SpvProof, buildTxProof } from \"./proof.ts\";\nimport { parseBitcoinTx } from \"./serialize.ts\";\nimport { bitcoinVerifier } from \"./verifier.ts\";\n\nexport interface BitcoinPaymentOutput {\n\tvout: number;\n\t/** scriptPubKey bytes. */\n\tscript: Uint8Array;\n\t/** Value in satoshis. */\n\tamount: bigint;\n\ttype: OutputScriptType;\n\t/** Address for the configured network, if the script has a standard one. */\n\taddress?: string;\n}\n\nexport interface VerifyBitcoinPaymentResult {\n\t/** `mined` AND every supplied `expect` constraint holds. */\n\tverified: boolean;\n\t/**\n\t * On-chain proof that the tx is committed in a Bitcoin block. With\n\t * `authenticateHeader` (default), this is the adapter's `was-tx-mined` —\n\t * header authenticated against the chain AND merkle inclusion. With it off,\n\t * it is merkle inclusion against the proof's own (unauthenticated) header.\n\t */\n\tmined: boolean;\n\t/** The decoded output at `vout`. */\n\toutput: BitcoinPaymentOutput;\n\t/** The proof used (built or supplied). */\n\tproof: SpvProof;\n}\n\nexport type VerifyBitcoinPaymentParams = (\n\t| { proof: SpvProof }\n\t| { txid: string; source: ProofSource }\n) & {\n\t/**\n\t * Adapter contract principal, `\"address.name\"`. Optional
|
|
12
|
+
"import type { Client } from \"../clients/types.ts\";\nimport { formatBitcoinAddress } from \"./address.ts\";\nimport { type OutputScriptType, parseOutputScript } from \"./codec.ts\";\nimport {\n\ttype BitcoinNetwork,\n\tgetSpvAdapter,\n\tspvAdapterPrincipal,\n} from \"./constants.ts\";\nimport { type ProofSource, type SpvProof, buildTxProof } from \"./proof.ts\";\nimport { parseBitcoinTx } from \"./serialize.ts\";\nimport { bitcoinVerifier } from \"./verifier.ts\";\n\nexport interface BitcoinPaymentOutput {\n\tvout: number;\n\t/** scriptPubKey bytes. */\n\tscript: Uint8Array;\n\t/** Value in satoshis. */\n\tamount: bigint;\n\ttype: OutputScriptType;\n\t/** Address for the configured network, if the script has a standard one. */\n\taddress?: string;\n}\n\nexport interface VerifyBitcoinPaymentResult {\n\t/** `mined` AND every supplied `expect` constraint holds. */\n\tverified: boolean;\n\t/**\n\t * On-chain proof that the tx is committed in a Bitcoin block. With\n\t * `authenticateHeader` (default), this is the adapter's `was-tx-mined` —\n\t * header authenticated against the chain AND merkle inclusion. With it off,\n\t * it is merkle inclusion against the proof's own (unauthenticated) header.\n\t */\n\tmined: boolean;\n\t/** The decoded output at `vout`. */\n\toutput: BitcoinPaymentOutput;\n\t/** The proof used (built or supplied). */\n\tproof: SpvProof;\n}\n\nexport type VerifyBitcoinPaymentParams = (\n\t| { proof: SpvProof }\n\t| { txid: string; source: ProofSource }\n) & {\n\t/**\n\t * Adapter contract principal, `\"address.name\"`. Optional on networks with a\n\t * published reference adapter (see `SPV_ADAPTER_CONTRACTS` — mainnet only);\n\t * required everywhere else.\n\t */\n\tcontract?: string;\n\t/** Output index to decode and assert against. */\n\tvout: number;\n\t/** Network for address formatting. Defaults to mainnet. */\n\tnetwork?: BitcoinNetwork;\n\t/** Optional expectations; each supplied field must match for `verified`. */\n\texpect?: { address?: string; amount?: bigint };\n\t/**\n\t * Confirm the proof's header is the canonical block at its height via\n\t * `get-header-merkle-root` (default true). Turn off only when the caller has\n\t * already authenticated the header.\n\t */\n\tauthenticateHeader?: boolean;\n\tsender?: string;\n};\n\n/**\n * Verify that a Bitcoin payment is committed on-chain and (optionally) matches\n * an expected recipient/amount. Composes the whole SPV flow:\n * 1. build the proof from a `ProofSource` (or accept a prepared `SpvProof`),\n * 2. prove the tx is mined — `was-tx-mined` (header authenticated against the\n * chain + merkle inclusion) by default, or membership-only when\n * `authenticateHeader` is off,\n * 3. decode the target output and assert any `expect` constraints.\n *\n * The output is decoded off-chain from the proof's raw tx, which is sound: the\n * raw tx is pinned to the proven txid (`buildTxProof` checks it hashes to the\n * leaf), so its bytes are committed.\n */\nexport async function verifyBitcoinPayment(\n\tclient: Client,\n\tparams: VerifyBitcoinPaymentParams,\n): Promise<VerifyBitcoinPaymentResult> {\n\tconst {\n\t\tcontract,\n\t\tvout,\n\t\tnetwork = \"mainnet\",\n\t\texpect,\n\t\tauthenticateHeader = true,\n\t\tsender,\n\t} = params;\n\n\tconst adapter = getSpvAdapter(network);\n\tconst resolvedContract =\n\t\tcontract ?? (adapter ? spvAdapterPrincipal(adapter) : undefined);\n\tif (!resolvedContract) {\n\t\tthrow new Error(\n\t\t\t`No spv-adapter deployed for ${network} — pass an explicit \\`contract\\`. Only mainnet has a published reference adapter; the SIP-044 built-ins require Clarity 6 / Epoch 4.0 (deploy recipe: contracts/README.md).`,\n\t\t);\n\t}\n\n\tconst proof =\n\t\t\"proof\" in params\n\t\t\t? params.proof\n\t\t\t: await buildTxProof(params.source, { txid: params.txid, vout });\n\n\tconst verifier = bitcoinVerifier(client, {\n\t\tcontract: resolvedContract,\n\t\tsender,\n\t});\n\tconst mined = authenticateHeader\n\t\t? await verifier.wasTxMined(proof)\n\t\t: await verifier.verifySpvProof(proof);\n\n\tconst parsedTx = parseBitcoinTx(proof.rawTx);\n\tconst out = parsedTx.outputs[vout];\n\tif (!out) {\n\t\tthrow new Error(\n\t\t\t`vout ${vout} out of range (tx has ${parsedTx.outputs.length} outputs)`,\n\t\t);\n\t}\n\tconst parsedScript = parseOutputScript(out.scriptPubKey);\n\tconst address = formatBitcoinAddress(parsedScript, network);\n\tconst output: BitcoinPaymentOutput = {\n\t\tvout,\n\t\tscript: out.scriptPubKey,\n\t\tamount: out.value,\n\t\ttype: parsedScript.type,\n\t\taddress,\n\t};\n\n\tconst amountOk = expect?.amount === undefined || out.value === expect.amount;\n\tconst addressOk = expect?.address === undefined || address === expect.address;\n\tconst verified = mined && amountOk && addressOk;\n\n\treturn { verified, mined, output, proof };\n}\n"
|
|
13
13
|
],
|
|
14
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,SAAS,QAAQ,CAAC,MAAkB,OAA+B;AAAA,EAClE,OAAO,aAAa,YAAY,MAAM,KAAK,CAAC;AAAA;AAI7C,SAAS,SAAS,CAAC,OAAmC;AAAA,EACrD,MAAM,OAAqB,CAAC;AAAA,EAC5B,SAAS,IAAI,EAAG,IAAI,MAAM,QAAQ,KAAK,GAAG;AAAA,IACzC,MAAM,OAAO,MAAM;AAAA,IACnB,IAAI,SAAS;AAAA,MAAW,MAAM,IAAI,MAAM,2BAA2B;AAAA,IAEnE,MAAM,QAAQ,MAAM,IAAI,MAAM;AAAA,IAC9B,KAAK,KAAK,SAAS,MAAM,KAAK,CAAC;AAAA,EAChC;AAAA,EACA,OAAO;AAAA;AASD,SAAS,UAAU,CAAC,eAAyC;AAAA,EACnE,IAAI,cAAc,WAAW,GAAG;AAAA,IAC/B,MAAM,IAAI,MAAM,2BAA2B;AAAA,EAC5C;AAAA,EACA,IAAI,QAAQ,cAAc,MAAM;AAAA,EAChC,OAAO,MAAM,SAAS,GAAG;AAAA,IACxB,QAAQ,UAAU,KAAK;AAAA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YAAY;AAAA,EACvD,MAAM,UAAU,qBAAqB,cAAc,OAAO;AAAA,EAC1D,MAAM,SAA+B;AAAA,IACpC;AAAA,IACA,QAAQ,IAAI;AAAA,IACZ,QAAQ,IAAI;AAAA,IACZ,MAAM,aAAa;AAAA,IACnB;AAAA,EACD;AAAA,EAEA,MAAM,WAAW,QAAQ,WAAW,aAAa,IAAI,UAAU,OAAO;AAAA,EACtE,MAAM,YAAY,QAAQ,YAAY,aAAa,YAAY,OAAO;AAAA,EACtE,MAAM,WAAW,SAAS,YAAY;AAAA,EAEtC,OAAO,EAAE,UAAU,OAAO,QAAQ,MAAM;AAAA;",
|
|
15
|
+
"debugId": "AD5CA540E5C47D0F64756E2164756E21",
|
|
16
16
|
"names": []
|
|
17
17
|
}
|
|
@@ -339,9 +339,12 @@ interface SpvAdapterRef {
|
|
|
339
339
|
/**
|
|
340
340
|
* Reference `spv-adapter` deployments (the read-only wrapper around the SIP-044
|
|
341
341
|
* built-ins) — the single source of truth for the published adapter principal.
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
342
|
+
* A network is listed only once its adapter is deployed AND verified against a
|
|
343
|
+
* real Bitcoin header; `verifyBitcoinPayment` requires an explicit `contract`
|
|
344
|
+
* for any network absent here (deploy recipe: `contracts/README.md`).
|
|
345
|
+
*
|
|
346
|
+
* `testnet` is absent because Stacks testnet has no Epoch 4.0 — the SIP-044
|
|
347
|
+
* built-ins do not exist there, so the contract cannot be deployed.
|
|
345
348
|
*/
|
|
346
349
|
declare const SPV_ADAPTER_CONTRACTS: Partial<Record<BitcoinNetwork, SpvAdapterRef>>;
|
|
347
350
|
/** Resolve the reference adapter for a network, or `undefined` if none is deployed yet. */
|
|
@@ -610,15 +613,14 @@ type Client<TExtended extends Record<string, unknown> = Record<string, unknown>>
|
|
|
610
613
|
} & TExtended;
|
|
611
614
|
/**
|
|
612
615
|
* SIP-044 (the native Bitcoin SPV built-ins) activates as part of the **Stacks
|
|
613
|
-
* Epoch 4.0 hard fork
|
|
614
|
-
*
|
|
615
|
-
* caller passes it once it is known.
|
|
616
|
+
* Epoch 4.0 hard fork** — the same fork that ships `pox-5` (SIP-045), so both
|
|
617
|
+
* share one height: {@link EPOCH_4_ACTIVATION_BURN_HEIGHT_MAINNET}.
|
|
616
618
|
*/
|
|
617
619
|
interface Clarity6Gate {
|
|
618
620
|
/**
|
|
619
|
-
* Bitcoin burn block height at which Clarity 6 / Epoch 4.0 activates.
|
|
620
|
-
*
|
|
621
|
-
*
|
|
621
|
+
* Bitcoin burn block height at which Clarity 6 / Epoch 4.0 activates.
|
|
622
|
+
* Optional on a mainnet client, which falls back to the known mainnet
|
|
623
|
+
* height; required on every other network, where no fixed height exists.
|
|
622
624
|
*/
|
|
623
625
|
activationBurnHeight?: number;
|
|
624
626
|
}
|
|
@@ -627,11 +629,26 @@ declare function getBurnBlockHeight(client: Client): Promise<number>;
|
|
|
627
629
|
/**
|
|
628
630
|
* Whether Clarity 6 (the native SPV built-ins) is active on the node behind
|
|
629
631
|
* `client`. Compares the node's current burn height to the SIP-044 / Epoch 4.0
|
|
630
|
-
* activation height
|
|
631
|
-
*
|
|
632
|
-
* rather than failing with an opaque contract error.
|
|
632
|
+
* activation height: the known mainnet height when `client.chain` is mainnet,
|
|
633
|
+
* otherwise the one you supply. `bitcoinVerifier` uses this to refuse calls
|
|
634
|
+
* before activation rather than failing with an opaque contract error.
|
|
633
635
|
*/
|
|
634
636
|
declare function isClarity6Active(client: Client, gate?: Clarity6Gate): Promise<boolean>;
|
|
637
|
+
/**
|
|
638
|
+
* Stacks hard-fork epoch activation heights, as Bitcoin burn block heights.
|
|
639
|
+
*
|
|
640
|
+
* Epoch 4.0 carries both SIP-044 (the native Bitcoin SPV built-ins / Clarity 6)
|
|
641
|
+
* and SIP-045 (`pox-5` Bitcoin Staking) — one fork, one height. Keep it here so
|
|
642
|
+
* the two modules can never disagree.
|
|
643
|
+
*/
|
|
644
|
+
/**
|
|
645
|
+
* Epoch 4.0 activation height on mainnet — Bitcoin block 960,230 (~2026-07-30
|
|
646
|
+
* AM UTC, per the stacks-core 4.0.1 release notes).
|
|
647
|
+
*
|
|
648
|
+
* Only mainnet has a fixed height. On other networks, read it from the node
|
|
649
|
+
* (`getPox5Activation` for pox-5) or pass it explicitly.
|
|
650
|
+
*/
|
|
651
|
+
declare const EPOCH_4_ACTIVATION_BURN_HEIGHT_MAINNET = 960230;
|
|
635
652
|
interface BitcoinVerifierConfig {
|
|
636
653
|
/** Adapter contract principal, `"address.name"` (the reference `spv-adapter` or an integrator's own). */
|
|
637
654
|
contract: string;
|
|
@@ -729,9 +746,9 @@ type VerifyBitcoinPaymentParams = ({
|
|
|
729
746
|
source: ProofSource
|
|
730
747
|
}) & {
|
|
731
748
|
/**
|
|
732
|
-
* Adapter contract principal, `"address.name"`. Optional
|
|
733
|
-
*
|
|
734
|
-
*
|
|
749
|
+
* Adapter contract principal, `"address.name"`. Optional on networks with a
|
|
750
|
+
* published reference adapter (see `SPV_ADAPTER_CONTRACTS` — mainnet only);
|
|
751
|
+
* required everywhere else.
|
|
735
752
|
*/
|
|
736
753
|
contract?: string
|
|
737
754
|
/** Output index to decode and assert against. */
|
|
@@ -765,4 +782,4 @@ type VerifyBitcoinPaymentParams = ({
|
|
|
765
782
|
* leaf), so its bytes are committed.
|
|
766
783
|
*/
|
|
767
784
|
declare function verifyBitcoinPayment(client: Client, params: VerifyBitcoinPaymentParams): Promise<VerifyBitcoinPaymentResult>;
|
|
768
|
-
export { verifyBitcoinPayment, taprootTweakPubkey, stripWitness, spvAdapterPrincipal, rootFromProof, reverseBytes, publicKeyToP2wpkhAddress, publicKeyToP2trAddress, parseOutputScript, parseBlockHeader, parseBitcoinTx, merkleRoot2 as merkleRoot, isClarity6Active, getSpvAdapter, 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 };
|
|
785
|
+
export { verifyBitcoinPayment, taprootTweakPubkey, stripWitness, spvAdapterPrincipal, rootFromProof, reverseBytes, publicKeyToP2wpkhAddress, publicKeyToP2trAddress, parseOutputScript, parseBlockHeader, parseBitcoinTx, merkleRoot2 as merkleRoot, isClarity6Active, getSpvAdapter, 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, EPOCH_4_ACTIVATION_BURN_HEIGHT_MAINNET, DecodedTxOutput, Clarity6Gate, BtcReader, BlockHeader, BlockForTx, BitcoinVerifierConfig, BitcoinVerifier, BitcoinTxOutput, BitcoinTxInput, BitcoinRpcConfig, BitcoinPaymentOutput, BitcoinNetwork };
|
|
@@ -339,9 +339,12 @@ interface SpvAdapterRef {
|
|
|
339
339
|
/**
|
|
340
340
|
* Reference `spv-adapter` deployments (the read-only wrapper around the SIP-044
|
|
341
341
|
* built-ins) — the single source of truth for the published adapter principal.
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
342
|
+
* A network is listed only once its adapter is deployed AND verified against a
|
|
343
|
+
* real Bitcoin header; `verifyBitcoinPayment` requires an explicit `contract`
|
|
344
|
+
* for any network absent here (deploy recipe: `contracts/README.md`).
|
|
345
|
+
*
|
|
346
|
+
* `testnet` is absent because Stacks testnet has no Epoch 4.0 — the SIP-044
|
|
347
|
+
* built-ins do not exist there, so the contract cannot be deployed.
|
|
345
348
|
*/
|
|
346
349
|
declare const SPV_ADAPTER_CONTRACTS: Partial<Record<BitcoinNetwork, SpvAdapterRef>>;
|
|
347
350
|
/** Resolve the reference adapter for a network, or `undefined` if none is deployed yet. */
|
|
@@ -610,15 +613,14 @@ type Client<TExtended extends Record<string, unknown> = Record<string, unknown>>
|
|
|
610
613
|
} & TExtended;
|
|
611
614
|
/**
|
|
612
615
|
* SIP-044 (the native Bitcoin SPV built-ins) activates as part of the **Stacks
|
|
613
|
-
* Epoch 4.0 hard fork
|
|
614
|
-
*
|
|
615
|
-
* caller passes it once it is known.
|
|
616
|
+
* Epoch 4.0 hard fork** — the same fork that ships `pox-5` (SIP-045), so both
|
|
617
|
+
* share one height: {@link EPOCH_4_ACTIVATION_BURN_HEIGHT_MAINNET}.
|
|
616
618
|
*/
|
|
617
619
|
interface Clarity6Gate {
|
|
618
620
|
/**
|
|
619
|
-
* Bitcoin burn block height at which Clarity 6 / Epoch 4.0 activates.
|
|
620
|
-
*
|
|
621
|
-
*
|
|
621
|
+
* Bitcoin burn block height at which Clarity 6 / Epoch 4.0 activates.
|
|
622
|
+
* Optional on a mainnet client, which falls back to the known mainnet
|
|
623
|
+
* height; required on every other network, where no fixed height exists.
|
|
622
624
|
*/
|
|
623
625
|
activationBurnHeight?: number;
|
|
624
626
|
}
|
|
@@ -627,11 +629,26 @@ declare function getBurnBlockHeight(client: Client): Promise<number>;
|
|
|
627
629
|
/**
|
|
628
630
|
* Whether Clarity 6 (the native SPV built-ins) is active on the node behind
|
|
629
631
|
* `client`. Compares the node's current burn height to the SIP-044 / Epoch 4.0
|
|
630
|
-
* activation height
|
|
631
|
-
*
|
|
632
|
-
* rather than failing with an opaque contract error.
|
|
632
|
+
* activation height: the known mainnet height when `client.chain` is mainnet,
|
|
633
|
+
* otherwise the one you supply. `bitcoinVerifier` uses this to refuse calls
|
|
634
|
+
* before activation rather than failing with an opaque contract error.
|
|
633
635
|
*/
|
|
634
636
|
declare function isClarity6Active(client: Client, gate?: Clarity6Gate): Promise<boolean>;
|
|
637
|
+
/**
|
|
638
|
+
* Stacks hard-fork epoch activation heights, as Bitcoin burn block heights.
|
|
639
|
+
*
|
|
640
|
+
* Epoch 4.0 carries both SIP-044 (the native Bitcoin SPV built-ins / Clarity 6)
|
|
641
|
+
* and SIP-045 (`pox-5` Bitcoin Staking) — one fork, one height. Keep it here so
|
|
642
|
+
* the two modules can never disagree.
|
|
643
|
+
*/
|
|
644
|
+
/**
|
|
645
|
+
* Epoch 4.0 activation height on mainnet — Bitcoin block 960,230 (~2026-07-30
|
|
646
|
+
* AM UTC, per the stacks-core 4.0.1 release notes).
|
|
647
|
+
*
|
|
648
|
+
* Only mainnet has a fixed height. On other networks, read it from the node
|
|
649
|
+
* (`getPox5Activation` for pox-5) or pass it explicitly.
|
|
650
|
+
*/
|
|
651
|
+
declare const EPOCH_4_ACTIVATION_BURN_HEIGHT_MAINNET = 960230;
|
|
635
652
|
interface BitcoinVerifierConfig {
|
|
636
653
|
/** Adapter contract principal, `"address.name"` (the reference `spv-adapter` or an integrator's own). */
|
|
637
654
|
contract: string;
|
|
@@ -729,9 +746,9 @@ type VerifyBitcoinPaymentParams = ({
|
|
|
729
746
|
source: ProofSource
|
|
730
747
|
}) & {
|
|
731
748
|
/**
|
|
732
|
-
* Adapter contract principal, `"address.name"`. Optional
|
|
733
|
-
*
|
|
734
|
-
*
|
|
749
|
+
* Adapter contract principal, `"address.name"`. Optional on networks with a
|
|
750
|
+
* published reference adapter (see `SPV_ADAPTER_CONTRACTS` — mainnet only);
|
|
751
|
+
* required everywhere else.
|
|
735
752
|
*/
|
|
736
753
|
contract?: string
|
|
737
754
|
/** Output index to decode and assert against. */
|
|
@@ -765,4 +782,4 @@ type VerifyBitcoinPaymentParams = ({
|
|
|
765
782
|
* leaf), so its bytes are committed.
|
|
766
783
|
*/
|
|
767
784
|
declare function verifyBitcoinPayment(client: Client, params: VerifyBitcoinPaymentParams): Promise<VerifyBitcoinPaymentResult>;
|
|
768
|
-
export { verifyBitcoinPayment, taprootTweakPubkey, stripWitness, spvAdapterPrincipal, rootFromProof, reverseBytes, publicKeyToP2wpkhAddress, publicKeyToP2trAddress, parseOutputScript, parseBlockHeader, parseBitcoinTx, merkleRoot2 as merkleRoot, isClarity6Active, getSpvAdapter, 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 };
|
|
785
|
+
export { verifyBitcoinPayment, taprootTweakPubkey, stripWitness, spvAdapterPrincipal, rootFromProof, reverseBytes, publicKeyToP2wpkhAddress, publicKeyToP2trAddress, parseOutputScript, parseBlockHeader, parseBitcoinTx, merkleRoot2 as merkleRoot, isClarity6Active, getSpvAdapter, 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, EPOCH_4_ACTIVATION_BURN_HEIGHT_MAINNET, DecodedTxOutput, Clarity6Gate, BtcReader, BlockHeader, BlockForTx, BitcoinVerifierConfig, BitcoinVerifier, BitcoinTxOutput, BitcoinTxInput, BitcoinRpcConfig, BitcoinPaymentOutput, BitcoinNetwork };
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EPOCH_4_ACTIVATION_BURN_HEIGHT_MAINNET
|
|
3
|
+
} from "../../shared/stacks-rdgg7mj3.js";
|
|
1
4
|
import {
|
|
2
5
|
BtcReader,
|
|
3
6
|
bitcoinTxid,
|
|
@@ -346,7 +349,12 @@ function parseOutputScript(script) {
|
|
|
346
349
|
return { type: "unknown" };
|
|
347
350
|
}
|
|
348
351
|
// src/bitcoin/constants.ts
|
|
349
|
-
var SPV_ADAPTER_CONTRACTS = {
|
|
352
|
+
var SPV_ADAPTER_CONTRACTS = {
|
|
353
|
+
mainnet: {
|
|
354
|
+
address: "SP2M1DE95TS0QBM4K893X6ST49FFJ53CCX9CYWNVY",
|
|
355
|
+
name: "spv-adapter"
|
|
356
|
+
}
|
|
357
|
+
};
|
|
350
358
|
function getSpvAdapter(network) {
|
|
351
359
|
return SPV_ADAPTER_CONTRACTS[network];
|
|
352
360
|
}
|
|
@@ -418,11 +426,12 @@ async function getBurnBlockHeight(client) {
|
|
|
418
426
|
return info.burn_block_height;
|
|
419
427
|
}
|
|
420
428
|
async function isClarity6Active(client, gate = {}) {
|
|
421
|
-
|
|
422
|
-
|
|
429
|
+
const activation = gate.activationBurnHeight ?? (client.chain?.network === "mainnet" ? EPOCH_4_ACTIVATION_BURN_HEIGHT_MAINNET : undefined);
|
|
430
|
+
if (activation == null) {
|
|
431
|
+
throw new Error(`Clarity 6 (SIP-044 / Epoch 4.0) has no fixed activation height on ${client.chain?.network ?? "this network"} — pass { activationBurnHeight }`);
|
|
423
432
|
}
|
|
424
433
|
const current = await getBurnBlockHeight(client);
|
|
425
|
-
return current >=
|
|
434
|
+
return current >= activation;
|
|
426
435
|
}
|
|
427
436
|
// src/bitcoin/verifier.ts
|
|
428
437
|
function clarityToBool(cv) {
|
|
@@ -500,7 +509,7 @@ async function verifyBitcoinPayment(client, params) {
|
|
|
500
509
|
const adapter = getSpvAdapter(network);
|
|
501
510
|
const resolvedContract = contract ?? (adapter ? spvAdapterPrincipal(adapter) : undefined);
|
|
502
511
|
if (!resolvedContract) {
|
|
503
|
-
throw new Error(`No spv-adapter deployed for ${network} — pass an explicit \`contract
|
|
512
|
+
throw new Error(`No spv-adapter deployed for ${network} — pass an explicit \`contract\`. Only mainnet has a published reference adapter; the SIP-044 built-ins require Clarity 6 / Epoch 4.0 (deploy recipe: contracts/README.md).`);
|
|
504
513
|
}
|
|
505
514
|
const proof = "proof" in params ? params.proof : await buildTxProof(params.source, { txid: params.txid, vout });
|
|
506
515
|
const verifier = bitcoinVerifier(client, {
|
|
@@ -557,8 +566,9 @@ export {
|
|
|
557
566
|
bitcoinRpcSource,
|
|
558
567
|
SPV_ADAPTER_CONTRACTS,
|
|
559
568
|
SPV_ADAPTER_ABI,
|
|
569
|
+
EPOCH_4_ACTIVATION_BURN_HEIGHT_MAINNET,
|
|
560
570
|
BtcReader
|
|
561
571
|
};
|
|
562
572
|
|
|
563
|
-
//# debugId=
|
|
573
|
+
//# debugId=55A60A5D16744F0264756E2164756E21
|
|
564
574
|
//# sourceMappingURL=index.js.map
|