@mikeargento/bitgraph-audit 0.7.0 → 0.8.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.
@@ -0,0 +1,131 @@
1
+ import { type SettlementPointer } from "@mikeargento/bitgraph-verify";
2
+ /** Base mainnet: block number = (timestamp - l2GenesisTime) / blockTime. */
3
+ export declare const BASE_MAINNET_ROLLUP: Readonly<{
4
+ l2GenesisTime: 1686789347;
5
+ blockTime: 2;
6
+ }>;
7
+ export declare const BLOB_BYTES = 131072;
8
+ /** OP Stack blob encoding version 0: (4 * 31 + 3) * 1024 - 4 bytes of data per blob. */
9
+ export declare const MAX_BLOB_DATA_BYTES = 130044;
10
+ export interface SettlementBlobsCheck {
11
+ name: string;
12
+ ok: boolean;
13
+ detail?: string;
14
+ }
15
+ export interface SettlementLocated {
16
+ /** The Base block the batch places the transaction in, read from the batch's timestamp. */
17
+ baseBlockNumber: number;
18
+ baseBlockTimestamp: number;
19
+ /** The batch's parent_hash (the hash of the block before), when the batch form carries one. */
20
+ baseParentHash: string | null;
21
+ /** Index in the batch's transaction_list: the block's non-deposit transactions, in order. */
22
+ baseTxIndex: number;
23
+ txHash: string;
24
+ /** The transaction's exact bytes as the batch carries them, 0x hex. */
25
+ rawTx: string;
26
+ /** Whether the batch holding the block was complete in the decoded bytes (false past the end of a frame prefix). */
27
+ batchComplete: boolean;
28
+ }
29
+ export interface SettlementBlobsResult {
30
+ ok: boolean;
31
+ reason?: string;
32
+ checks: SettlementBlobsCheck[];
33
+ /** What was decoded: frames 0..framesDecoded-1 of the channel, whole or as a prefix. */
34
+ channel?: {
35
+ id: string;
36
+ framesDecoded: number;
37
+ /** The channel's frame count when known (complete, or stated by the pointer). */
38
+ framesTotal: number | null;
39
+ complete: boolean;
40
+ compression: "brotli" | "zlib";
41
+ decodedBytes: number;
42
+ /** Base blocks whose batches were complete in the decoded bytes. */
43
+ baseBlocks: number[];
44
+ };
45
+ located?: SettlementLocated;
46
+ }
47
+ export interface SettlementBlobsOptions {
48
+ /** How the rollup turns a batch timestamp into a block number. Base mainnet by default. */
49
+ rollup?: {
50
+ l2GenesisTime: number;
51
+ blockTime: number;
52
+ };
53
+ /** The L2 chain id, for rebuilding transactions out of span batches. Base mainnet by default. */
54
+ chainId?: bigint;
55
+ /** What the ceiling record says, each matched against what the batch says when given. */
56
+ expect?: {
57
+ /** The ceiling transaction to locate (else the pointer's `located.txHash`). */
58
+ txHash?: string;
59
+ /** Its exact bytes, 0x hex. */
60
+ rawTx?: string;
61
+ /** The Base block's parent hash, from the ceiling's carried header. */
62
+ baseParentHash?: string;
63
+ };
64
+ }
65
+ /**
66
+ * The data a blob carries: 4 field elements per round, each a 6-bit byte
67
+ * and 31 data bytes, the first round's first element holding the version
68
+ * and a 24-bit length. Padding past the length must be zero. A field
69
+ * element with its top two bits set is not a blob this encoding produced.
70
+ */
71
+ export declare function decodeOpBlob(blob: Uint8Array): Uint8Array;
72
+ export interface ChannelFrame {
73
+ channelId: string;
74
+ frameNumber: number;
75
+ frameData: Uint8Array;
76
+ isLast: boolean;
77
+ }
78
+ /** Frames out of a blob's data: derivation version 0, then channel_id(16) frame_number(2) length(4) data is_last(1), repeated. */
79
+ export declare function parseFrames(data: Uint8Array): ChannelFrame[];
80
+ export declare function decompressChannel(data: Uint8Array, complete: boolean): {
81
+ compression: "brotli" | "zlib";
82
+ bytes: Uint8Array;
83
+ };
84
+ export interface BatchTx {
85
+ raw: Uint8Array;
86
+ hash: string;
87
+ }
88
+ export interface DecodedBatch {
89
+ /** 0 singular, 1 span. */
90
+ type: number;
91
+ /** Offset of the batch's RLP item in the decompressed channel. */
92
+ offset: number;
93
+ /** Base blocks in this batch. A cut singular batch has one block with the transactions read so far. */
94
+ blocks: Array<{
95
+ number: number;
96
+ timestamp: number;
97
+ parentHash: string | null;
98
+ txs: BatchTx[];
99
+ complete: boolean;
100
+ }>;
101
+ }
102
+ /**
103
+ * Batches out of a decompressed channel. Each is an RLP byte string
104
+ * `batch_version ++ content`. When `complete` is false the stream may be cut:
105
+ * the last batch is then read as far as it goes and marked incomplete.
106
+ */
107
+ export declare function decodeBatches(channel: Uint8Array, complete: boolean, rollup: {
108
+ l2GenesisTime: number;
109
+ blockTime: number;
110
+ }, chainId: bigint): DecodedBatch[];
111
+ /**
112
+ * A span batch (OP Stack Delta): prefix (rel_timestamp, l1_origin_num,
113
+ * parent_check, l1_origin_check) then payload (block_count, origin_bits,
114
+ * block_tx_counts, txs). Transactions are stored by column (signatures,
115
+ * recipients, data, nonces, gas limits, protected bits) and are rebuilt
116
+ * here into their raw form so they can be hashed.
117
+ */
118
+ export declare function decodeSpanBatch(data: Uint8Array, rollup: {
119
+ l2GenesisTime: number;
120
+ blockTime: number;
121
+ }, chainId: bigint): DecodedBatch["blocks"];
122
+ /**
123
+ * Verify blob bytes against a settlement pointer and locate the ceiling
124
+ * transaction inside them. `blobBytesByVersionedHash` holds the bytes the
125
+ * caller has (keyed by 0x hex versioned hash, any case); blobs the pointer
126
+ * lists without bytes are skipped, and the channel is decoded from the
127
+ * frames that are present, as a whole when they are all there and as a
128
+ * prefix otherwise. Every check runs in order; the first failure is `reason`.
129
+ */
130
+ export declare function verifySettlementBlobs(pointer: SettlementPointer, blobBytesByVersionedHash: ReadonlyMap<string, Uint8Array>, options?: SettlementBlobsOptions): Promise<SettlementBlobsResult>;
131
+ //# sourceMappingURL=settlement-blobs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settlement-blobs.d.ts","sourceRoot":"","sources":["../src/settlement-blobs.ts"],"names":[],"mappings":"AAmCA,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,8BAA8B,CAAC;AAEtC,4EAA4E;AAC5E,eAAO,MAAM,mBAAmB;;;EAA6D,CAAC;AAE9F,eAAO,MAAM,UAAU,SAAS,CAAC;AACjC,wFAAwF;AACxF,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAI1C,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,M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