@secondlayer/verify 0.5.2 → 0.5.4
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/index.d.ts +138 -53
- package/dist/index.js.map +14 -14
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
/** A byte string, held as a Uint8Array. */
|
|
1
2
|
type Bytes = Uint8Array;
|
|
3
|
+
/** Encodes bytes as a lowercase hex string. */
|
|
2
4
|
declare const hex: (b: Bytes) => string;
|
|
3
5
|
/** Hex to bytes; tolerates a 0x prefix. */
|
|
4
6
|
declare const unhex: (s: string) => Bytes;
|
|
7
|
+
/** A Nakamoto-era Stacks block header. */
|
|
5
8
|
interface NakamotoHeader {
|
|
6
9
|
/** Low 7 bits = header version; high bit = shadow block. */
|
|
7
10
|
version: number;
|
|
@@ -26,8 +29,10 @@ interface NakamotoHeader {
|
|
|
26
29
|
*/
|
|
27
30
|
declare function parseNakamotoHeader(raw: Bytes): NakamotoHeader;
|
|
28
31
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
32
|
+
* Hashes a Nakamoto header the way its signers sign it.
|
|
33
|
+
*
|
|
34
|
+
* It is sha512/256 over every header field except the signer signatures, which
|
|
35
|
+
* is also the header's `block_hash`.
|
|
31
36
|
*/
|
|
32
37
|
declare const signerSignatureHash: (h: NakamotoHeader) => Bytes;
|
|
33
38
|
/**
|
|
@@ -53,32 +58,38 @@ interface Epoch2Header {
|
|
|
53
58
|
blockHash: Bytes;
|
|
54
59
|
consensusHash: Bytes;
|
|
55
60
|
}
|
|
61
|
+
/** A Stacks block header from either era. */
|
|
56
62
|
type StacksHeader = NakamotoHeader | Epoch2Header;
|
|
57
63
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
64
|
+
* Parses the epoch 2.x block header at the start of `raw`.
|
|
65
|
+
*
|
|
66
|
+
* `raw` is a header from `/v2/headers`, or block bytes from `/v2/blocks/<id>`.
|
|
67
|
+
* `consensusHash` is the 20-byte hash of the sortition that elected the block.
|
|
61
68
|
*/
|
|
62
69
|
declare function parseEpoch2Header(raw: Bytes, consensusHash: Bytes): Epoch2Header;
|
|
70
|
+
/** Narrows a Stacks header to an epoch 2.x header. */
|
|
63
71
|
declare const isEpoch2Header: (h: StacksHeader) => h is Epoch2Header;
|
|
64
72
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
73
|
+
* Computes a header's block id, also called the index block hash.
|
|
74
|
+
*
|
|
75
|
+
* The id is sha512/256(block_hash || consensus_hash). A Nakamoto block hash is
|
|
76
|
+
* its signer signature hash; a 2.x one hashes the whole header.
|
|
68
77
|
*/
|
|
69
78
|
declare const blockId2: (h: StacksHeader) => Bytes;
|
|
70
|
-
/**
|
|
79
|
+
/** Hashes a key to its MARF path: sha512/256 of the UTF-8 key. */
|
|
71
80
|
declare const marfPath: (key: string) => Bytes;
|
|
72
|
-
/**
|
|
81
|
+
/** Hashes a value to its MARF value: sha512/256, padded to 40 bytes. */
|
|
73
82
|
declare function marfValue(value: string): Bytes;
|
|
74
83
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
84
|
+
* Lists the ancestor tries a MARF proof crosses.
|
|
85
|
+
*
|
|
86
|
+
* Each id is the backptr a descendant trie follows toward the leaf, and
|
|
87
|
+
* `verifyMarfProof` needs every one's header. They are read from untrusted
|
|
88
|
+
* proof bytes, so they are only fetch hints: the proof still fails unless each
|
|
89
|
+
* header hashes to the id the trie committed. Malformed proofs yield no ids.
|
|
80
90
|
*/
|
|
81
91
|
declare function marfProofAncestors(proof: Bytes): string[];
|
|
92
|
+
/** A MARF proof with the leaf path and value it covers. */
|
|
82
93
|
interface MarfProofInput {
|
|
83
94
|
/** Consensus-serialized TrieMerkleProof (`/v2/clarity/marf/<path>?proof=1`). */
|
|
84
95
|
proof: Bytes;
|
|
@@ -97,9 +108,11 @@ interface MarfProofInput {
|
|
|
97
108
|
headers: StacksHeader[];
|
|
98
109
|
}
|
|
99
110
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
111
|
+
* Verifies a MARF inclusion proof.
|
|
112
|
+
*
|
|
113
|
+
* It is true only when `value` is stored at `path` in the MARF whose tip root
|
|
114
|
+
* is `root`. Inclusion only: MARF proofs cannot prove absence. Malformed proof
|
|
115
|
+
* bytes verify false.
|
|
103
116
|
*/
|
|
104
117
|
declare function verifyMarfProof(input: MarfProofInput): boolean;
|
|
105
118
|
interface WitnessLeaf {
|
|
@@ -108,6 +121,7 @@ interface WitnessLeaf {
|
|
|
108
121
|
/** 32-byte value hash (first 32 bytes of the MARFValue; the tail is zero). */
|
|
109
122
|
valueHash: Bytes;
|
|
110
123
|
}
|
|
124
|
+
/** A recomputed trie root, its ancestor roots, and leaves. */
|
|
111
125
|
interface StateWitness {
|
|
112
126
|
/** Recomputed trie root; compare to the authenticated header's state_index_root. */
|
|
113
127
|
root: Bytes;
|
|
@@ -121,6 +135,7 @@ interface StateWitness {
|
|
|
121
135
|
* The result proves nothing until `root` equals a header's state_index_root.
|
|
122
136
|
*/
|
|
123
137
|
declare function parseWitness(bytes: Bytes): StateWitness;
|
|
138
|
+
/** The witness leaves, claimed writes, and bookkeeping keys to classify. */
|
|
124
139
|
interface BlockDiffInput {
|
|
125
140
|
/** `parseWitness(bytes).leaves`, from a witness whose root was checked. */
|
|
126
141
|
leaves: WitnessLeaf[];
|
|
@@ -134,6 +149,7 @@ interface BlockDiffInput {
|
|
|
134
149
|
interface ClassifiedLeaf extends WitnessLeaf {
|
|
135
150
|
key: string;
|
|
136
151
|
}
|
|
152
|
+
/** A block's witnessed leaves, split into writes, carried, and internal. */
|
|
137
153
|
interface BlockDiff {
|
|
138
154
|
/** Leaves matching a claimed write (path and value). */
|
|
139
155
|
writes: ClassifiedLeaf[];
|
|
@@ -159,10 +175,13 @@ declare const SIGNERS_CONTRACT = "SP000000000000000000002Q6VF78.signers";
|
|
|
159
175
|
/** Signer principal -> weight. */
|
|
160
176
|
type SignerSet = Map<string, bigint>;
|
|
161
177
|
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
178
|
+
* Decodes a `cycle-signer-set` value from the `.signers` contract.
|
|
179
|
+
*
|
|
180
|
+
* The value is hex or bytes, as stored in the MARF:
|
|
181
|
+
* `(some (list (tuple (signer principal) (weight uint) ...)))`.
|
|
164
182
|
*/
|
|
165
183
|
declare function decodeSignerSet(value: string | Bytes): SignerSet;
|
|
184
|
+
/** Whether the signed weight meets the threshold with known signers. */
|
|
166
185
|
interface SignerCheck {
|
|
167
186
|
/** Signed weight meets the threshold, and every signature is a distinct known signer. */
|
|
168
187
|
valid: boolean;
|
|
@@ -180,9 +199,11 @@ interface SignerCheck {
|
|
|
180
199
|
invalid: number;
|
|
181
200
|
}
|
|
182
201
|
/**
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
202
|
+
* Sums the weight of the signers who signed a block header.
|
|
203
|
+
*
|
|
204
|
+
* It recovers each header signature's key over `signer_signature_hash`, maps it
|
|
205
|
+
* to its mainnet p2pkh principal, and sums weights from `set`. The set must be
|
|
206
|
+
* the one for the reward cycle of the tenure-electing burn block.
|
|
186
207
|
*/
|
|
187
208
|
declare function verifySignerSignatures(header: NakamotoHeader, set: SignerSet): SignerCheck;
|
|
188
209
|
/**
|
|
@@ -193,6 +214,7 @@ declare function verifySignerSignatures(header: NakamotoHeader, set: SignerSet):
|
|
|
193
214
|
declare function verifyConsensusPreimage(consensusHash: Bytes, preimage: Bytes): string | null;
|
|
194
215
|
/** Mainnet PoX parameters (first_burnchain_block_height, reward_cycle_length). */
|
|
195
216
|
declare const MAINNET_FIRST_BURN_HEIGHT = 666050;
|
|
217
|
+
/** Burn blocks in a mainnet reward cycle. */
|
|
196
218
|
declare const MAINNET_REWARD_CYCLE_LENGTH = 2100;
|
|
197
219
|
/** Mainnet prepare phase: the last 100 burn blocks of a cycle pick the next cycle's signers. */
|
|
198
220
|
declare const MAINNET_PREPARE_LENGTH = 100;
|
|
@@ -201,13 +223,14 @@ declare const cycleStart: (cycle: number, firstBurnHeight?: number, cycleLength?
|
|
|
201
223
|
/** Reward cycle containing `burnHeight`. */
|
|
202
224
|
declare function rewardCycle(burnHeight: number, firstBurnHeight?: number, cycleLength?: number): number;
|
|
203
225
|
import { ClarityValue } from "@secondlayer/stacks/clarity";
|
|
204
|
-
/** `vm::<contract>::0::<map>::<serialized key hex
|
|
226
|
+
/** The MARF key of a map entry: `vm::<contract>::0::<map>::<serialized key hex>`. */
|
|
205
227
|
declare function mapEntryKey(contractId: string, mapName: string, key: ClarityValue): string;
|
|
206
|
-
/** `vm::<contract>::1::<var
|
|
228
|
+
/** The MARF key of a data variable: `vm::<contract>::1::<var>`. */
|
|
207
229
|
declare function dataVarKey(contractId: string, varName: string): string;
|
|
208
230
|
/**
|
|
209
|
-
* `vm::<contract>::2::<token>::<principal json
|
|
210
|
-
*
|
|
231
|
+
* The MARF key of a fungible token balance: `vm::<contract>::2::<token>::<principal json>`.
|
|
232
|
+
*
|
|
233
|
+
* The holder is serde-JSON PrincipalData, e.g. `{"Standard":[22,[...20 bytes]]}`.
|
|
211
234
|
*/
|
|
212
235
|
declare function ftBalanceKey(contractId: string, tokenName: string, holder: string): string;
|
|
213
236
|
interface BlockHeader {
|
|
@@ -223,13 +246,20 @@ interface BlockHeader {
|
|
|
223
246
|
bits: number;
|
|
224
247
|
nonce: number;
|
|
225
248
|
}
|
|
249
|
+
/** A Bitcoin header rule a chain check can fail on. */
|
|
226
250
|
type HeaderRule = "checkpoint" | "format" | "prev-link" | "bits" | "retarget" | "median-time-past" | "version" | "proof-of-work";
|
|
251
|
+
/**
|
|
252
|
+
* Thrown when a Bitcoin header fails a validation rule.
|
|
253
|
+
*
|
|
254
|
+
* `rule` names the rule and `height` the header that failed it.
|
|
255
|
+
*/
|
|
227
256
|
declare class HeaderValidationError extends Error {
|
|
228
257
|
readonly height: number;
|
|
229
258
|
readonly rule: HeaderRule;
|
|
230
259
|
readonly name = "HeaderValidationError";
|
|
231
260
|
constructor(height: number, rule: HeaderRule, detail: string);
|
|
232
261
|
}
|
|
262
|
+
/** A trusted Bitcoin header that anchors header validation. */
|
|
233
263
|
interface Checkpoint {
|
|
234
264
|
height: number;
|
|
235
265
|
/** Raw 80-byte header, bytes or hex. Trusted without validation. */
|
|
@@ -241,6 +271,7 @@ interface Checkpoint {
|
|
|
241
271
|
*/
|
|
242
272
|
periodStartTime?: number;
|
|
243
273
|
}
|
|
274
|
+
/** A Bitcoin header with its height, hash, and raw bytes. */
|
|
244
275
|
interface ChainEntry {
|
|
245
276
|
height: number;
|
|
246
277
|
/** Display-order hex. */
|
|
@@ -248,6 +279,7 @@ interface ChainEntry {
|
|
|
248
279
|
header: BlockHeader;
|
|
249
280
|
raw: Uint8Array;
|
|
250
281
|
}
|
|
282
|
+
/** A validated chain of Bitcoin headers, grown forward from a checkpoint. */
|
|
251
283
|
declare class HeaderChain {
|
|
252
284
|
private readonly base;
|
|
253
285
|
private readonly periodStartTime;
|
|
@@ -255,6 +287,7 @@ declare class HeaderChain {
|
|
|
255
287
|
private readonly heights;
|
|
256
288
|
private work;
|
|
257
289
|
private constructor();
|
|
290
|
+
/** Starts a header chain at a checkpoint. */
|
|
258
291
|
static fromCheckpoint(checkpoint: Checkpoint): HeaderChain;
|
|
259
292
|
get tip(): ChainEntry;
|
|
260
293
|
/** Work summed from the checkpoint (inclusive) to the tip; not chainwork since genesis. */
|
|
@@ -262,6 +295,7 @@ declare class HeaderChain {
|
|
|
262
295
|
get checkpointHeight(): number;
|
|
263
296
|
/** Height of a header in this chain by display-order hash, or undefined. */
|
|
264
297
|
heightOf(hashHex: string): number | undefined;
|
|
298
|
+
/** The header entry at a height, if the chain has one. */
|
|
265
299
|
headerAt(height: number): ChainEntry | undefined;
|
|
266
300
|
/**
|
|
267
301
|
* Validates and appends headers in order. All-or-nothing: if any header
|
|
@@ -284,6 +318,7 @@ declare class HeaderChain {
|
|
|
284
318
|
* (burn height 967,680 or later); earlier ones by hash chain from 9,055,251.
|
|
285
319
|
*/
|
|
286
320
|
declare const MAINNET_CHECKPOINT: VerifyCheckpoint;
|
|
321
|
+
/** A trusted Stacks header and signer set to start verification from. */
|
|
287
322
|
interface VerifyCheckpoint {
|
|
288
323
|
stacks: {
|
|
289
324
|
/** Raw Nakamoto header (hex) of a trusted block whose state holds `signerSet`. */
|
|
@@ -332,7 +367,7 @@ interface VmEventRow {
|
|
|
332
367
|
raw_key?: string | null;
|
|
333
368
|
raw_value?: string | null;
|
|
334
369
|
}
|
|
335
|
-
/** An epoch 2.x header and the consensus hash
|
|
370
|
+
/** An epoch 2.x header and the consensus hash it commits to. */
|
|
336
371
|
interface Epoch2HeaderResponse {
|
|
337
372
|
/** Consensus-serialized StacksBlockHeader. */
|
|
338
373
|
header: Bytes;
|
|
@@ -366,6 +401,12 @@ interface ProofSource {
|
|
|
366
401
|
/** Indexed vm_events write rows of the block, checked against its proven diff. */
|
|
367
402
|
getVmEvents?(height: number): Promise<VmEventRow[]>;
|
|
368
403
|
}
|
|
404
|
+
/**
|
|
405
|
+
* Thrown when a proof source request fails.
|
|
406
|
+
*
|
|
407
|
+
* It carries the request `url`, the HTTP `status` (null when there was none)
|
|
408
|
+
* and the detail.
|
|
409
|
+
*/
|
|
369
410
|
declare class SourceError extends Error {
|
|
370
411
|
readonly url: string;
|
|
371
412
|
readonly status: number | null;
|
|
@@ -375,6 +416,7 @@ declare class SourceError extends Error {
|
|
|
375
416
|
type Fetch = (url: string, init?: RequestInit) => Promise<Response>;
|
|
376
417
|
/** The hosted API. */
|
|
377
418
|
declare const DEFAULT_API_URL = "https://api.secondlayer.tools";
|
|
419
|
+
/** Options for reading proofs from the Secondlayer API. */
|
|
378
420
|
interface SecondlayerSourceOptions {
|
|
379
421
|
/** API origin. Defaults to {@link DEFAULT_API_URL}. */
|
|
380
422
|
baseUrl?: string;
|
|
@@ -386,37 +428,64 @@ interface SecondlayerSourceOptions {
|
|
|
386
428
|
fetch?: Fetch;
|
|
387
429
|
}
|
|
388
430
|
/**
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
431
|
+
* Reads every proof input from the Secondlayer API.
|
|
432
|
+
*
|
|
433
|
+
* Blocks, epoch 2.x headers, MARF proofs, witnesses, burn preimages, Bitcoin
|
|
434
|
+
* headers and each block's state writes come from `/v1/proofs/*`, which is free
|
|
435
|
+
* and rate limited. Indexed `vm_events` rows come from the Index API as metered
|
|
436
|
+
* rows, and are read only when `verifyBlock` gets `rows: true`. Methods are own
|
|
437
|
+
* properties, so a partial source spreads over it:
|
|
394
438
|
* `{ ...new SecondlayerProofSource(o), ...new NodeRpcProofSource(n) }`.
|
|
395
439
|
*/
|
|
396
440
|
declare class SecondlayerProofSource implements ProofSource {
|
|
441
|
+
/** Raw block bytes, header first, by block id or height. */
|
|
397
442
|
getBlock: (ref: string | number) => Promise<Bytes>;
|
|
443
|
+
/** An epoch 2.x header and its consensus hash, by index block hash. */
|
|
398
444
|
getEpoch2Header: (blockId: string) => Promise<Epoch2HeaderResponse>;
|
|
445
|
+
/**
|
|
446
|
+
* A MARF inclusion proof for a path at a tip.
|
|
447
|
+
*
|
|
448
|
+
* It is null when the key is absent.
|
|
449
|
+
*/
|
|
399
450
|
getMarfProof: (pathHex: string, tipId: string) => Promise<MarfProofResponse | null>;
|
|
451
|
+
/** The state witness for a block. */
|
|
400
452
|
getWitness: (blockId: string) => Promise<Bytes>;
|
|
453
|
+
/** The burn preimage behind a consensus hash. */
|
|
401
454
|
getBurnPreimage: (consensusHash: string) => Promise<BurnPreimage>;
|
|
455
|
+
/** Raw 80-byte Bitcoin headers, `count` of them from height `from`. */
|
|
402
456
|
getBitcoinHeaders: (from: number, count: number) => Promise<string[]>;
|
|
457
|
+
/**
|
|
458
|
+
* Every MARF write of a block, in ordinal order.
|
|
459
|
+
*
|
|
460
|
+
* It is null when there are none.
|
|
461
|
+
*/
|
|
403
462
|
getStateWrites: (height: number) => Promise<StateWrite[] | null>;
|
|
463
|
+
/** The indexed `vm_events` write rows of a block, from the Index API. */
|
|
404
464
|
getVmEvents: (height: number) => Promise<VmEventRow[]>;
|
|
405
465
|
constructor(opts?: SecondlayerSourceOptions);
|
|
406
466
|
}
|
|
467
|
+
/** Options for reading proofs from a Stacks node. */
|
|
407
468
|
interface NodeRpcSourceOptions {
|
|
408
469
|
/** Stacks node RPC origin, e.g. `http://localhost:20443`. */
|
|
409
470
|
nodeUrl: string;
|
|
410
471
|
fetch?: Fetch;
|
|
411
472
|
}
|
|
412
473
|
/**
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
474
|
+
* Reads blocks, epoch 2.x headers and MARF proofs from a Stacks node.
|
|
475
|
+
*
|
|
476
|
+
* It uses the node's RPC. Witnesses, burn preimages and Bitcoin headers need
|
|
477
|
+
* another source: spread this over one.
|
|
416
478
|
*/
|
|
417
479
|
declare class NodeRpcProofSource implements Pick<ProofSource, "getBlock" | "getEpoch2Header" | "getMarfProof"> {
|
|
480
|
+
/** Raw block bytes, header first, by block id or height. */
|
|
418
481
|
getBlock: (ref: string | number) => Promise<Bytes>;
|
|
482
|
+
/** An epoch 2.x header and its consensus hash, by index block hash. */
|
|
419
483
|
getEpoch2Header: (blockId: string) => Promise<Epoch2HeaderResponse>;
|
|
484
|
+
/**
|
|
485
|
+
* A MARF inclusion proof for a path at a tip.
|
|
486
|
+
*
|
|
487
|
+
* It is null when the key is absent.
|
|
488
|
+
*/
|
|
420
489
|
getMarfProof: (pathHex: string, tipId: string) => Promise<MarfProofResponse | null>;
|
|
421
490
|
constructor(opts: NodeRpcSourceOptions);
|
|
422
491
|
}
|
|
@@ -457,6 +526,7 @@ interface StateFailure {
|
|
|
457
526
|
path?: string;
|
|
458
527
|
ordinal?: number;
|
|
459
528
|
}
|
|
529
|
+
/** A block's height, parent, and state root to check rows against. */
|
|
460
530
|
interface BlockStateInput {
|
|
461
531
|
/** MARF height of the block (its Stacks chain length). */
|
|
462
532
|
height: number;
|
|
@@ -482,6 +552,7 @@ interface BlockStateInput {
|
|
|
482
552
|
*/
|
|
483
553
|
parentHolds?: (leaf: WitnessLeaf) => Promise<boolean>;
|
|
484
554
|
}
|
|
555
|
+
/** The proven diff, rows checked, notes, and failures. */
|
|
485
556
|
interface BlockStateResult {
|
|
486
557
|
diff?: ProvenDiff;
|
|
487
558
|
rowsChecked: number;
|
|
@@ -489,14 +560,16 @@ interface BlockStateResult {
|
|
|
489
560
|
failures: StateFailure[];
|
|
490
561
|
}
|
|
491
562
|
/**
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
*
|
|
495
|
-
*
|
|
496
|
-
*
|
|
563
|
+
* Verifies a block's state against an authenticated header.
|
|
564
|
+
*
|
|
565
|
+
* The witness must recompute `stateRoot`, then every leaf is classified. With
|
|
566
|
+
* state writes, any leaf that is not a named write, a carried parent value or
|
|
567
|
+
* MARF bookkeeping is a hidden write. Without them the diff is still proven,
|
|
568
|
+
* since every leaf is in the block: carried leaves are told apart only through
|
|
497
569
|
* `parentLeaves`, and the remaining writes come back unnamed.
|
|
498
570
|
*/
|
|
499
571
|
declare function verifyBlockState(input: BlockStateInput): Promise<BlockStateResult>;
|
|
572
|
+
/** A transaction's id and its consensus-serialized bytes. */
|
|
500
573
|
interface BlockTransaction {
|
|
501
574
|
/** sha512/256 of the transaction bytes, hex. */
|
|
502
575
|
txid: string;
|
|
@@ -504,20 +577,25 @@ interface BlockTransaction {
|
|
|
504
577
|
raw: Bytes;
|
|
505
578
|
}
|
|
506
579
|
/**
|
|
507
|
-
* tx_merkle_root over
|
|
508
|
-
*
|
|
509
|
-
*
|
|
580
|
+
* Computes the `tx_merkle_root` over transaction ids.
|
|
581
|
+
*
|
|
582
|
+
* A leaf is H(0x00 ‖ txid) and a node is H(0x01 ‖ l ‖ r). An odd level
|
|
583
|
+
* duplicates its last node, and a lone leaf is still paired with itself, so a
|
|
584
|
+
* one-transaction block hashes H(0x01 ‖ leaf ‖ leaf).
|
|
510
585
|
*/
|
|
511
586
|
declare function txMerkleRoot2(txids: Bytes[]): Bytes;
|
|
587
|
+
/** Thrown for a malformed block body or a transaction root mismatch. */
|
|
512
588
|
declare class TransactionsError extends Error {
|
|
513
589
|
readonly code: "malformed" | "tx-root-mismatch";
|
|
514
590
|
constructor(code: "malformed" | "tx-root-mismatch", message: string);
|
|
515
591
|
}
|
|
516
592
|
/**
|
|
517
|
-
*
|
|
518
|
-
*
|
|
519
|
-
*
|
|
520
|
-
*
|
|
593
|
+
* Hashes a block's transactions and checks them against the header.
|
|
594
|
+
*
|
|
595
|
+
* Each transaction is hashed to its txid and checked against the header's
|
|
596
|
+
* `tx_merkle_root`. The body after `header.byteLength` is a u32 count, then the
|
|
597
|
+
* transactions back to back. It returns null when the bytes are the header
|
|
598
|
+
* alone, as a source that serves headers only does. It throws
|
|
521
599
|
* {@link TransactionsError} on a malformed body, trailing bytes or a root
|
|
522
600
|
* mismatch.
|
|
523
601
|
*/
|
|
@@ -548,6 +626,7 @@ interface Ancestry {
|
|
|
548
626
|
*/
|
|
549
627
|
via: "parents" | "marf";
|
|
550
628
|
}
|
|
629
|
+
/** The result of verifying a block, step by step. */
|
|
551
630
|
interface BlockVerification {
|
|
552
631
|
/**
|
|
553
632
|
* Every step passed. At or above the checkpoint: header, burn binding,
|
|
@@ -588,6 +667,7 @@ interface BlockVerification {
|
|
|
588
667
|
/** Empty when ok. The first entry is the first broken link. */
|
|
589
668
|
failures: VerifyFailure[];
|
|
590
669
|
}
|
|
670
|
+
/** The proof source, checkpoint, and row checking for a block verify. */
|
|
591
671
|
interface VerifyOptions {
|
|
592
672
|
source: ProofSource;
|
|
593
673
|
/** Defaults to MAINNET_CHECKPOINT. */
|
|
@@ -606,8 +686,10 @@ interface VerifyOptions {
|
|
|
606
686
|
onStep?: (step: VerifyStep) => void;
|
|
607
687
|
}
|
|
608
688
|
/**
|
|
609
|
-
* Verifies blocks from one checkpoint against one source
|
|
610
|
-
*
|
|
689
|
+
* Verifies blocks from one checkpoint against one source.
|
|
690
|
+
*
|
|
691
|
+
* It caches the Bitcoin header chain, proven signer sets and fetched headers
|
|
692
|
+
* across calls.
|
|
611
693
|
*/
|
|
612
694
|
declare class BlockVerifier {
|
|
613
695
|
private readonly source;
|
|
@@ -736,6 +818,7 @@ declare class BlockVerifier {
|
|
|
736
818
|
/** One-shot: verify a block from a checkpoint (MAINNET_CHECKPOINT by default). */
|
|
737
819
|
declare const verifyBlock: (ref: string | number, opts: VerifyOptions) => Promise<BlockVerification>;
|
|
738
820
|
type LinkStatus = "ok" | "failed" | "skipped";
|
|
821
|
+
/** One verification step with its status and what it proved. */
|
|
739
822
|
interface LinkLine {
|
|
740
823
|
step: VerifyStep;
|
|
741
824
|
label: string;
|
|
@@ -749,9 +832,11 @@ declare const LINKS: readonly {
|
|
|
749
832
|
label: string
|
|
750
833
|
}[];
|
|
751
834
|
/**
|
|
752
|
-
*
|
|
753
|
-
*
|
|
754
|
-
*
|
|
835
|
+
* Describes a verification as one line per link and a verdict.
|
|
836
|
+
*
|
|
837
|
+
* It is the human view, shared by the CLI and the browser checker. Ancestry
|
|
838
|
+
* appears only below the checkpoint. `rows` says whether the caller asked for
|
|
839
|
+
* the rows link.
|
|
755
840
|
*/
|
|
756
841
|
declare function describeLinks(r: BlockVerification, cp: VerifyCheckpoint, opts?: {
|
|
757
842
|
rows?: boolean
|