@secondlayer/stacks 4.2.0 → 4.3.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-03vfm21t.cjs +222 -0
- package/dist/shared/stacks-03vfm21t.cjs.map +12 -0
- package/dist/shared/stacks-0eatsx6d.cjs +25 -0
- package/dist/shared/stacks-0eatsx6d.cjs.map +10 -0
- package/dist/shared/stacks-1arrcd11.js.map +2 -2
- package/dist/shared/{stacks-mrk6tkkh.cjs → stacks-3mt2q2na.cjs} +26 -2
- package/dist/shared/{stacks-mrk6tkkh.cjs.map → stacks-3mt2q2na.cjs.map} +1 -1
- package/dist/shared/{stacks-rndfw2vh.js → stacks-7wkf2rph.js} +3 -26
- package/dist/shared/{stacks-rndfw2vh.js.map → stacks-7wkf2rph.js.map} +3 -5
- package/dist/shared/stacks-8pfdscq6.js +52 -0
- package/dist/shared/stacks-8pfdscq6.js.map +12 -0
- package/dist/shared/stacks-e4xn4m7j.js +27 -0
- package/dist/shared/stacks-e4xn4m7j.js.map +10 -0
- package/dist/shared/stacks-enpj9krt.cjs.map +2 -2
- package/dist/shared/{stacks-9qcr921s.cjs → stacks-kem68d80.cjs} +3 -3
- package/dist/shared/stacks-kem68d80.cjs.map +10 -0
- package/dist/shared/stacks-wdp5yr8n.cjs +39 -0
- package/dist/shared/stacks-wdp5yr8n.cjs.map +12 -0
- package/dist/shared/{stacks-0nedd34w.cjs → stacks-ycbq8pf7.cjs} +2 -25
- package/dist/shared/{stacks-0nedd34w.cjs.map → stacks-ycbq8pf7.cjs.map} +3 -5
- package/dist/shared/{stacks-rpqtgpyj.js → stacks-zcpvzbr0.js} +3 -3
- package/dist/shared/stacks-zcpvzbr0.js.map +10 -0
- package/dist/shared/stacks-ztzygy90.js +237 -0
- package/dist/shared/stacks-ztzygy90.js.map +12 -0
- package/dist/src/actions/index.js +5 -5
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/bitcoin/index.cjs +1 -217
- package/dist/src/bitcoin/index.cjs.map +3 -5
- package/dist/src/bitcoin/index.js +11 -223
- package/dist/src/bitcoin/index.js.map +3 -5
- package/dist/src/bns/index.js +1 -1
- package/dist/src/clarity/index.d.cts +1 -1
- package/dist/src/clarity/index.d.ts +1 -1
- package/dist/src/index.js +5 -5
- package/dist/src/index.js.map +1 -1
- package/dist/src/postconditions/index.d.cts +3 -2
- package/dist/src/postconditions/index.d.ts +3 -2
- package/dist/src/postconditions/index.js +1 -1
- package/dist/src/pox/index.cjs +1 -24
- package/dist/src/pox/index.cjs.map +3 -4
- package/dist/src/pox/index.js +8 -25
- package/dist/src/pox/index.js.map +3 -4
- package/dist/src/pox5/index.cjs +1118 -204
- package/dist/src/pox5/index.cjs.map +13 -8
- package/dist/src/pox5/index.d.cts +618 -162
- package/dist/src/pox5/index.d.ts +618 -162
- package/dist/src/pox5/index.js +1136 -208
- package/dist/src/pox5/index.js.map +13 -8
- package/dist/src/stackingdao/index.js +1 -1
- package/dist/src/tools/index.cjs.map +2 -2
- package/dist/src/tools/index.js.map +2 -2
- package/package.json +4 -3
- package/dist/shared/stacks-2evvn48s.js +0 -22
- package/dist/shared/stacks-2evvn48s.js.map +0 -10
- package/dist/shared/stacks-3kj51c6p.cjs +0 -16
- package/dist/shared/stacks-3kj51c6p.cjs.map +0 -10
- package/dist/shared/stacks-9qcr921s.cjs.map +0 -10
- package/dist/shared/stacks-rdgg7mj3.js +0 -7
- package/dist/shared/stacks-rdgg7mj3.js.map +0 -10
- package/dist/shared/stacks-rpqtgpyj.js.map +0 -10
- package/dist/shared/stacks-wscmfs7q.cjs +0 -5
- package/dist/shared/stacks-wscmfs7q.cjs.map +0 -10
|
@@ -8,11 +8,9 @@ import {
|
|
|
8
8
|
deployContract,
|
|
9
9
|
getAccountHistory,
|
|
10
10
|
getAccountInfo,
|
|
11
|
-
getBalance,
|
|
12
11
|
getBlock,
|
|
13
12
|
getContractAbi,
|
|
14
13
|
getContractSource,
|
|
15
|
-
getDataVar,
|
|
16
14
|
getMempoolStats,
|
|
17
15
|
getNftHoldings,
|
|
18
16
|
getRawBlock,
|
|
@@ -23,10 +21,12 @@ import {
|
|
|
23
21
|
simulateTransaction,
|
|
24
22
|
sponsorTransaction,
|
|
25
23
|
transferStx
|
|
26
|
-
} from "../../shared/stacks-
|
|
24
|
+
} from "../../shared/stacks-7wkf2rph.js";
|
|
27
25
|
import {
|
|
26
|
+
getBalance,
|
|
27
|
+
getDataVar,
|
|
28
28
|
multicall
|
|
29
|
-
} from "../../shared/stacks-
|
|
29
|
+
} from "../../shared/stacks-8pfdscq6.js";
|
|
30
30
|
import {
|
|
31
31
|
callContract,
|
|
32
32
|
estimateFee,
|
|
@@ -107,5 +107,5 @@ export {
|
|
|
107
107
|
ContractResponseError
|
|
108
108
|
};
|
|
109
109
|
|
|
110
|
-
//# debugId=
|
|
110
|
+
//# debugId=30258F7ACEFDEE5C64756E2164756E21
|
|
111
111
|
//# sourceMappingURL=index.js.map
|
|
@@ -35,222 +35,6 @@ __export(exports_bitcoin, {
|
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(exports_bitcoin);
|
|
37
37
|
|
|
38
|
-
// src/bitcoin/merkle.ts
|
|
39
|
-
function hashPair(left, right) {
|
|
40
|
-
return doubleSha256(concatBytes(left, right));
|
|
41
|
-
}
|
|
42
|
-
function nextLevel(level) {
|
|
43
|
-
const next = [];
|
|
44
|
-
for (let i = 0;i < level.length; i += 2) {
|
|
45
|
-
const left = level[i];
|
|
46
|
-
if (left === undefined)
|
|
47
|
-
throw new Error("merkle: missing left node");
|
|
48
|
-
const right = level[i + 1] ?? left;
|
|
49
|
-
next.push(hashPair(left, right));
|
|
50
|
-
}
|
|
51
|
-
return next;
|
|
52
|
-
}
|
|
53
|
-
function merkleRoot(txidsInternal) {
|
|
54
|
-
if (txidsInternal.length === 0) {
|
|
55
|
-
throw new Error("merkleRoot: empty tx list");
|
|
56
|
-
}
|
|
57
|
-
let level = txidsInternal.slice();
|
|
58
|
-
while (level.length > 1) {
|
|
59
|
-
level = nextLevel(level);
|
|
60
|
-
}
|
|
61
|
-
const root = level[0];
|
|
62
|
-
if (root === undefined)
|
|
63
|
-
throw new Error("merkleRoot: no root");
|
|
64
|
-
return root;
|
|
65
|
-
}
|
|
66
|
-
function buildMerkleProof(txidsInternal, txIndex) {
|
|
67
|
-
const txCount = txidsInternal.length;
|
|
68
|
-
if (txCount === 0) {
|
|
69
|
-
throw new Error("buildMerkleProof: empty tx list");
|
|
70
|
-
}
|
|
71
|
-
if (txIndex < 0 || txIndex >= txCount) {
|
|
72
|
-
throw new Error(`buildMerkleProof: txIndex ${txIndex} out of range for ${txCount} txs`);
|
|
73
|
-
}
|
|
74
|
-
const siblings = [];
|
|
75
|
-
let index = txIndex;
|
|
76
|
-
let level = txidsInternal.slice();
|
|
77
|
-
while (level.length > 1) {
|
|
78
|
-
const isRight = index % 2 === 1;
|
|
79
|
-
const siblingIndex = isRight ? index - 1 : index + 1;
|
|
80
|
-
const self = level[index];
|
|
81
|
-
if (self === undefined)
|
|
82
|
-
throw new Error("buildMerkleProof: missing node");
|
|
83
|
-
siblings.push(level[siblingIndex] ?? self);
|
|
84
|
-
level = nextLevel(level);
|
|
85
|
-
index = Math.floor(index / 2);
|
|
86
|
-
}
|
|
87
|
-
return { siblings, txIndex, txCount };
|
|
88
|
-
}
|
|
89
|
-
function rootFromProof(leafInternal, proof) {
|
|
90
|
-
let hash = leafInternal;
|
|
91
|
-
let index = proof.txIndex;
|
|
92
|
-
for (const sibling of proof.siblings) {
|
|
93
|
-
hash = index % 2 === 1 ? hashPair(sibling, hash) : hashPair(hash, sibling);
|
|
94
|
-
index = Math.floor(index / 2);
|
|
95
|
-
}
|
|
96
|
-
return hash;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// src/bitcoin/proof.ts
|
|
100
|
-
function normalizeTxid(txid) {
|
|
101
|
-
return without0x(txid).toLowerCase();
|
|
102
|
-
}
|
|
103
|
-
function assembleBlockForTx(args) {
|
|
104
|
-
const txIndex = args.txidsDisplay.indexOf(normalizeTxid(args.txid));
|
|
105
|
-
if (txIndex < 0) {
|
|
106
|
-
throw new Error(`tx ${args.txid} not found in block ${args.blockId}`);
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
header: hexToBytes(args.headerHex),
|
|
110
|
-
height: args.height,
|
|
111
|
-
txidsInternal: args.txidsDisplay.map((t) => reverseBytes(hexToBytes(t))),
|
|
112
|
-
txIndex
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
async function buildTxProof(source, params) {
|
|
116
|
-
const { txid, vout } = params;
|
|
117
|
-
const want = normalizeTxid(txid);
|
|
118
|
-
const [rawTx, block] = await Promise.all([
|
|
119
|
-
source.getRawTx(txid),
|
|
120
|
-
source.getBlockForTx(txid)
|
|
121
|
-
]);
|
|
122
|
-
const parsed = parseBitcoinTx(rawTx);
|
|
123
|
-
const gotDisplay = bytesToHex(reverseBytes(parsed.txidInternal));
|
|
124
|
-
if (gotDisplay !== want) {
|
|
125
|
-
throw new Error(`source returned a tx whose id ${gotDisplay} does not match requested ${want}`);
|
|
126
|
-
}
|
|
127
|
-
const atIndex = block.txidsInternal[block.txIndex];
|
|
128
|
-
if (!atIndex || bytesToHex(atIndex) !== bytesToHex(parsed.txidInternal)) {
|
|
129
|
-
throw new Error(`source txIndex ${block.txIndex} does not point at tx ${want}`);
|
|
130
|
-
}
|
|
131
|
-
const merkle = buildMerkleProof(block.txidsInternal, block.txIndex);
|
|
132
|
-
const headerRoot = parseBlockHeader(block.header).merkleRoot;
|
|
133
|
-
const computed = rootFromProof(parsed.txidInternal, merkle);
|
|
134
|
-
if (bytesToHex(computed) !== bytesToHex(headerRoot)) {
|
|
135
|
-
throw new Error("constructed merkle proof does not reconcile with the block header merkle root");
|
|
136
|
-
}
|
|
137
|
-
return {
|
|
138
|
-
rawTx,
|
|
139
|
-
txidInternal: parsed.txidInternal,
|
|
140
|
-
vout,
|
|
141
|
-
merkle,
|
|
142
|
-
header: block.header,
|
|
143
|
-
height: block.height
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
function fallbackProofSource(sources) {
|
|
147
|
-
if (sources.length === 0) {
|
|
148
|
-
throw new Error("fallbackProofSource: at least one source is required");
|
|
149
|
-
}
|
|
150
|
-
async function firstSuccess(fn) {
|
|
151
|
-
let lastError;
|
|
152
|
-
for (const source of sources) {
|
|
153
|
-
try {
|
|
154
|
-
return await fn(source);
|
|
155
|
-
} catch (error) {
|
|
156
|
-
lastError = error;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
throw lastError;
|
|
160
|
-
}
|
|
161
|
-
return {
|
|
162
|
-
getRawTx: (txid) => firstSuccess((s) => s.getRawTx(txid)),
|
|
163
|
-
getBlockForTx: (txid) => firstSuccess((s) => s.getBlockForTx(txid))
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
function bitcoinRpcSource(config) {
|
|
167
|
-
const doFetch = config.fetch ?? fetch;
|
|
168
|
-
async function rpc(method, rpcParams) {
|
|
169
|
-
const headers = {
|
|
170
|
-
"content-type": "application/json"
|
|
171
|
-
};
|
|
172
|
-
if (config.auth) {
|
|
173
|
-
const basic = typeof config.auth === "string" ? config.auth : btoa(`${config.auth.username}:${config.auth.password}`);
|
|
174
|
-
headers.authorization = `Basic ${basic}`;
|
|
175
|
-
}
|
|
176
|
-
const res = await doFetch(config.url, {
|
|
177
|
-
method: "POST",
|
|
178
|
-
headers,
|
|
179
|
-
body: JSON.stringify({
|
|
180
|
-
jsonrpc: "1.0",
|
|
181
|
-
id: "secondlayer",
|
|
182
|
-
method,
|
|
183
|
-
params: rpcParams
|
|
184
|
-
})
|
|
185
|
-
});
|
|
186
|
-
if (!res.ok) {
|
|
187
|
-
throw new Error(`bitcoin rpc ${method} failed: HTTP ${res.status}`);
|
|
188
|
-
}
|
|
189
|
-
const json = await res.json();
|
|
190
|
-
if (json.error) {
|
|
191
|
-
throw new Error(`bitcoin rpc ${method} error: ${json.error.message}`);
|
|
192
|
-
}
|
|
193
|
-
return json.result;
|
|
194
|
-
}
|
|
195
|
-
return {
|
|
196
|
-
async getRawTx(txid) {
|
|
197
|
-
return hexToBytes(await rpc("getrawtransaction", [txid, false]));
|
|
198
|
-
},
|
|
199
|
-
async getBlockForTx(txid) {
|
|
200
|
-
const tx = await rpc("getrawtransaction", [
|
|
201
|
-
txid,
|
|
202
|
-
true
|
|
203
|
-
]);
|
|
204
|
-
if (!tx.blockhash) {
|
|
205
|
-
throw new Error(`tx ${txid} is not in a block (node needs -txindex, or the tx is unconfirmed)`);
|
|
206
|
-
}
|
|
207
|
-
const block = await rpc("getblock", [
|
|
208
|
-
tx.blockhash,
|
|
209
|
-
1
|
|
210
|
-
]);
|
|
211
|
-
const header = await rpc("getblockheader", [tx.blockhash, false]);
|
|
212
|
-
return assembleBlockForTx({
|
|
213
|
-
txid,
|
|
214
|
-
blockId: tx.blockhash,
|
|
215
|
-
headerHex: header,
|
|
216
|
-
height: block.height,
|
|
217
|
-
txidsDisplay: block.tx
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
function esploraSource(config) {
|
|
223
|
-
const doFetch = config.fetch ?? fetch;
|
|
224
|
-
const base = config.url.replace(/\/+$/, "");
|
|
225
|
-
async function get(path) {
|
|
226
|
-
const res = await doFetch(`${base}${path}`);
|
|
227
|
-
if (!res.ok) {
|
|
228
|
-
throw new Error(`esplora GET ${path} failed: HTTP ${res.status}`);
|
|
229
|
-
}
|
|
230
|
-
return res;
|
|
231
|
-
}
|
|
232
|
-
return {
|
|
233
|
-
async getRawTx(txid) {
|
|
234
|
-
return hexToBytes((await (await get(`/tx/${txid}/hex`)).text()).trim());
|
|
235
|
-
},
|
|
236
|
-
async getBlockForTx(txid) {
|
|
237
|
-
const status = await (await get(`/tx/${txid}`)).json();
|
|
238
|
-
if (!status.status.confirmed) {
|
|
239
|
-
throw new Error(`tx ${txid} is unconfirmed`);
|
|
240
|
-
}
|
|
241
|
-
const blockHashHex = status.status.block_hash;
|
|
242
|
-
const header = (await (await get(`/block/${blockHashHex}/header`)).text()).trim();
|
|
243
|
-
const txids = await (await get(`/block/${blockHashHex}/txids`)).json();
|
|
244
|
-
return assembleBlockForTx({
|
|
245
|
-
txid,
|
|
246
|
-
blockId: blockHashHex,
|
|
247
|
-
headerHex: header,
|
|
248
|
-
height: status.status.block_height,
|
|
249
|
-
txidsDisplay: txids
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
38
|
// src/bitcoin/codec.ts
|
|
255
39
|
function merkleDepth(txCount) {
|
|
256
40
|
let depth = 0;
|
|
@@ -533,5 +317,5 @@ async function verifyBitcoinPayment(client, params) {
|
|
|
533
317
|
return { verified, mined, output, proof };
|
|
534
318
|
}
|
|
535
319
|
|
|
536
|
-
//# debugId=
|
|
320
|
+
//# debugId=375B1F06A4D78AE464756E2164756E21
|
|
537
321
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/bitcoin/
|
|
3
|
+
"sources": ["../src/bitcoin/codec.ts", "../src/bitcoin/constants.ts", "../src/bitcoin/abi/spvAdapter.ts", "../src/bitcoin/activation.ts", "../src/bitcoin/verifier.ts", "../src/bitcoin/actions.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
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
|
-
"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
5
|
"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
6
|
"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
7
|
"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",
|
|
@@ -11,7 +9,7 @@
|
|
|
11
9
|
"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
10
|
"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
11
|
],
|
|
14
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,SAAS,QAAQ,CAAC,MAAkB,OAA+B;AAAA,EAClE,OAAO,aAAa,YAAY,MAAM,KAAK,CAA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buildTxProof,
|
|
6
|
+
esploraSource,
|
|
7
|
+
fallbackProofSource,
|
|
8
|
+
merkleRoot,
|
|
9
|
+
rootFromProof
|
|
10
|
+
} from "../../shared/stacks-ztzygy90.js";
|
|
4
11
|
import {
|
|
5
12
|
BtcReader,
|
|
6
13
|
bitcoinTxid,
|
|
@@ -32,227 +39,8 @@ import {
|
|
|
32
39
|
} from "../../shared/stacks-ttdk2g2f.js";
|
|
33
40
|
import"../../shared/stacks-bfan7ex7.js";
|
|
34
41
|
import {
|
|
35
|
-
|
|
36
|
-
concatBytes,
|
|
37
|
-
hexToBytes,
|
|
38
|
-
without0x
|
|
42
|
+
hexToBytes
|
|
39
43
|
} from "../../shared/stacks-qs5fzts5.js";
|
|
40
|
-
// src/bitcoin/merkle.ts
|
|
41
|
-
function hashPair(left, right) {
|
|
42
|
-
return doubleSha256(concatBytes(left, right));
|
|
43
|
-
}
|
|
44
|
-
function nextLevel(level) {
|
|
45
|
-
const next = [];
|
|
46
|
-
for (let i = 0;i < level.length; i += 2) {
|
|
47
|
-
const left = level[i];
|
|
48
|
-
if (left === undefined)
|
|
49
|
-
throw new Error("merkle: missing left node");
|
|
50
|
-
const right = level[i + 1] ?? left;
|
|
51
|
-
next.push(hashPair(left, right));
|
|
52
|
-
}
|
|
53
|
-
return next;
|
|
54
|
-
}
|
|
55
|
-
function merkleRoot(txidsInternal) {
|
|
56
|
-
if (txidsInternal.length === 0) {
|
|
57
|
-
throw new Error("merkleRoot: empty tx list");
|
|
58
|
-
}
|
|
59
|
-
let level = txidsInternal.slice();
|
|
60
|
-
while (level.length > 1) {
|
|
61
|
-
level = nextLevel(level);
|
|
62
|
-
}
|
|
63
|
-
const root = level[0];
|
|
64
|
-
if (root === undefined)
|
|
65
|
-
throw new Error("merkleRoot: no root");
|
|
66
|
-
return root;
|
|
67
|
-
}
|
|
68
|
-
function buildMerkleProof(txidsInternal, txIndex) {
|
|
69
|
-
const txCount = txidsInternal.length;
|
|
70
|
-
if (txCount === 0) {
|
|
71
|
-
throw new Error("buildMerkleProof: empty tx list");
|
|
72
|
-
}
|
|
73
|
-
if (txIndex < 0 || txIndex >= txCount) {
|
|
74
|
-
throw new Error(`buildMerkleProof: txIndex ${txIndex} out of range for ${txCount} txs`);
|
|
75
|
-
}
|
|
76
|
-
const siblings = [];
|
|
77
|
-
let index = txIndex;
|
|
78
|
-
let level = txidsInternal.slice();
|
|
79
|
-
while (level.length > 1) {
|
|
80
|
-
const isRight = index % 2 === 1;
|
|
81
|
-
const siblingIndex = isRight ? index - 1 : index + 1;
|
|
82
|
-
const self = level[index];
|
|
83
|
-
if (self === undefined)
|
|
84
|
-
throw new Error("buildMerkleProof: missing node");
|
|
85
|
-
siblings.push(level[siblingIndex] ?? self);
|
|
86
|
-
level = nextLevel(level);
|
|
87
|
-
index = Math.floor(index / 2);
|
|
88
|
-
}
|
|
89
|
-
return { siblings, txIndex, txCount };
|
|
90
|
-
}
|
|
91
|
-
function rootFromProof(leafInternal, proof) {
|
|
92
|
-
let hash = leafInternal;
|
|
93
|
-
let index = proof.txIndex;
|
|
94
|
-
for (const sibling of proof.siblings) {
|
|
95
|
-
hash = index % 2 === 1 ? hashPair(sibling, hash) : hashPair(hash, sibling);
|
|
96
|
-
index = Math.floor(index / 2);
|
|
97
|
-
}
|
|
98
|
-
return hash;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// src/bitcoin/proof.ts
|
|
102
|
-
function normalizeTxid(txid) {
|
|
103
|
-
return without0x(txid).toLowerCase();
|
|
104
|
-
}
|
|
105
|
-
function assembleBlockForTx(args) {
|
|
106
|
-
const txIndex = args.txidsDisplay.indexOf(normalizeTxid(args.txid));
|
|
107
|
-
if (txIndex < 0) {
|
|
108
|
-
throw new Error(`tx ${args.txid} not found in block ${args.blockId}`);
|
|
109
|
-
}
|
|
110
|
-
return {
|
|
111
|
-
header: hexToBytes(args.headerHex),
|
|
112
|
-
height: args.height,
|
|
113
|
-
txidsInternal: args.txidsDisplay.map((t) => reverseBytes(hexToBytes(t))),
|
|
114
|
-
txIndex
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
async function buildTxProof(source, params) {
|
|
118
|
-
const { txid, vout } = params;
|
|
119
|
-
const want = normalizeTxid(txid);
|
|
120
|
-
const [rawTx, block] = await Promise.all([
|
|
121
|
-
source.getRawTx(txid),
|
|
122
|
-
source.getBlockForTx(txid)
|
|
123
|
-
]);
|
|
124
|
-
const parsed = parseBitcoinTx(rawTx);
|
|
125
|
-
const gotDisplay = bytesToHex(reverseBytes(parsed.txidInternal));
|
|
126
|
-
if (gotDisplay !== want) {
|
|
127
|
-
throw new Error(`source returned a tx whose id ${gotDisplay} does not match requested ${want}`);
|
|
128
|
-
}
|
|
129
|
-
const atIndex = block.txidsInternal[block.txIndex];
|
|
130
|
-
if (!atIndex || bytesToHex(atIndex) !== bytesToHex(parsed.txidInternal)) {
|
|
131
|
-
throw new Error(`source txIndex ${block.txIndex} does not point at tx ${want}`);
|
|
132
|
-
}
|
|
133
|
-
const merkle = buildMerkleProof(block.txidsInternal, block.txIndex);
|
|
134
|
-
const headerRoot = parseBlockHeader(block.header).merkleRoot;
|
|
135
|
-
const computed = rootFromProof(parsed.txidInternal, merkle);
|
|
136
|
-
if (bytesToHex(computed) !== bytesToHex(headerRoot)) {
|
|
137
|
-
throw new Error("constructed merkle proof does not reconcile with the block header merkle root");
|
|
138
|
-
}
|
|
139
|
-
return {
|
|
140
|
-
rawTx,
|
|
141
|
-
txidInternal: parsed.txidInternal,
|
|
142
|
-
vout,
|
|
143
|
-
merkle,
|
|
144
|
-
header: block.header,
|
|
145
|
-
height: block.height
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
function fallbackProofSource(sources) {
|
|
149
|
-
if (sources.length === 0) {
|
|
150
|
-
throw new Error("fallbackProofSource: at least one source is required");
|
|
151
|
-
}
|
|
152
|
-
async function firstSuccess(fn) {
|
|
153
|
-
let lastError;
|
|
154
|
-
for (const source of sources) {
|
|
155
|
-
try {
|
|
156
|
-
return await fn(source);
|
|
157
|
-
} catch (error) {
|
|
158
|
-
lastError = error;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
throw lastError;
|
|
162
|
-
}
|
|
163
|
-
return {
|
|
164
|
-
getRawTx: (txid) => firstSuccess((s) => s.getRawTx(txid)),
|
|
165
|
-
getBlockForTx: (txid) => firstSuccess((s) => s.getBlockForTx(txid))
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
function bitcoinRpcSource(config) {
|
|
169
|
-
const doFetch = config.fetch ?? fetch;
|
|
170
|
-
async function rpc(method, rpcParams) {
|
|
171
|
-
const headers = {
|
|
172
|
-
"content-type": "application/json"
|
|
173
|
-
};
|
|
174
|
-
if (config.auth) {
|
|
175
|
-
const basic = typeof config.auth === "string" ? config.auth : btoa(`${config.auth.username}:${config.auth.password}`);
|
|
176
|
-
headers.authorization = `Basic ${basic}`;
|
|
177
|
-
}
|
|
178
|
-
const res = await doFetch(config.url, {
|
|
179
|
-
method: "POST",
|
|
180
|
-
headers,
|
|
181
|
-
body: JSON.stringify({
|
|
182
|
-
jsonrpc: "1.0",
|
|
183
|
-
id: "secondlayer",
|
|
184
|
-
method,
|
|
185
|
-
params: rpcParams
|
|
186
|
-
})
|
|
187
|
-
});
|
|
188
|
-
if (!res.ok) {
|
|
189
|
-
throw new Error(`bitcoin rpc ${method} failed: HTTP ${res.status}`);
|
|
190
|
-
}
|
|
191
|
-
const json = await res.json();
|
|
192
|
-
if (json.error) {
|
|
193
|
-
throw new Error(`bitcoin rpc ${method} error: ${json.error.message}`);
|
|
194
|
-
}
|
|
195
|
-
return json.result;
|
|
196
|
-
}
|
|
197
|
-
return {
|
|
198
|
-
async getRawTx(txid) {
|
|
199
|
-
return hexToBytes(await rpc("getrawtransaction", [txid, false]));
|
|
200
|
-
},
|
|
201
|
-
async getBlockForTx(txid) {
|
|
202
|
-
const tx = await rpc("getrawtransaction", [
|
|
203
|
-
txid,
|
|
204
|
-
true
|
|
205
|
-
]);
|
|
206
|
-
if (!tx.blockhash) {
|
|
207
|
-
throw new Error(`tx ${txid} is not in a block (node needs -txindex, or the tx is unconfirmed)`);
|
|
208
|
-
}
|
|
209
|
-
const block = await rpc("getblock", [
|
|
210
|
-
tx.blockhash,
|
|
211
|
-
1
|
|
212
|
-
]);
|
|
213
|
-
const header = await rpc("getblockheader", [tx.blockhash, false]);
|
|
214
|
-
return assembleBlockForTx({
|
|
215
|
-
txid,
|
|
216
|
-
blockId: tx.blockhash,
|
|
217
|
-
headerHex: header,
|
|
218
|
-
height: block.height,
|
|
219
|
-
txidsDisplay: block.tx
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
function esploraSource(config) {
|
|
225
|
-
const doFetch = config.fetch ?? fetch;
|
|
226
|
-
const base = config.url.replace(/\/+$/, "");
|
|
227
|
-
async function get(path) {
|
|
228
|
-
const res = await doFetch(`${base}${path}`);
|
|
229
|
-
if (!res.ok) {
|
|
230
|
-
throw new Error(`esplora GET ${path} failed: HTTP ${res.status}`);
|
|
231
|
-
}
|
|
232
|
-
return res;
|
|
233
|
-
}
|
|
234
|
-
return {
|
|
235
|
-
async getRawTx(txid) {
|
|
236
|
-
return hexToBytes((await (await get(`/tx/${txid}/hex`)).text()).trim());
|
|
237
|
-
},
|
|
238
|
-
async getBlockForTx(txid) {
|
|
239
|
-
const status = await (await get(`/tx/${txid}`)).json();
|
|
240
|
-
if (!status.status.confirmed) {
|
|
241
|
-
throw new Error(`tx ${txid} is unconfirmed`);
|
|
242
|
-
}
|
|
243
|
-
const blockHashHex = status.status.block_hash;
|
|
244
|
-
const header = (await (await get(`/block/${blockHashHex}/header`)).text()).trim();
|
|
245
|
-
const txids = await (await get(`/block/${blockHashHex}/txids`)).json();
|
|
246
|
-
return assembleBlockForTx({
|
|
247
|
-
txid,
|
|
248
|
-
blockId: blockHashHex,
|
|
249
|
-
headerHex: header,
|
|
250
|
-
height: status.status.block_height,
|
|
251
|
-
txidsDisplay: txids
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
44
|
// src/bitcoin/codec.ts
|
|
257
45
|
function merkleDepth(txCount) {
|
|
258
46
|
let depth = 0;
|
|
@@ -568,5 +356,5 @@ export {
|
|
|
568
356
|
BtcReader
|
|
569
357
|
};
|
|
570
358
|
|
|
571
|
-
//# debugId=
|
|
359
|
+
//# debugId=66AE4A8CF0390B2764756E2164756E21
|
|
572
360
|
//# sourceMappingURL=index.js.map
|