Draft Inverse Bloom Filter

This commit is contained in:
Jim Hamill
2025-01-20 07:47:07 +00:00
parent d6a04f4350
commit 1aebc6da42
21 changed files with 1285 additions and 381 deletions
+23 -11
View File
@@ -1,4 +1,6 @@
import { binToHex, hexToBin, isHex, hash256 } from '@bitauth/libauth';
import { Bytes } from './bytes.js';
import { hash256 } from '@bitauth/libauth';
export interface BlockHeaderRaw {
version: number;
@@ -13,6 +15,21 @@ export interface BlockHeaderRaw {
* Represents a Bitcoin Cash block header.
* This class handles parsing and serialization of BCH block headers between different formats
* (raw object, bytes, hex) and provides access to individual header fields.
*
* @example
*
* ```ts
* // Import our primitives.
* import { BlockHeader } from '@xocash/primitives';
*
* // Instantiate BlockHeader Primitive from Hex.
* const blockHeader = BlockHeader.from('blockHeaderHex');
*
* // Output Block Header information.
* console.log(blockHeader.getVersion());
* console.log(blockHeader.getTimestamp());
* console.log(blockHeader.getNonce());
* ```
*/
export class BlockHeader {
/**
@@ -80,12 +97,7 @@ export class BlockHeader {
* @throws Error if the hex string length is not 160
*/
static fromHex(hex: string): BlockHeader {
// Ensure that the given string is hex.
if (!isHex(hex)) {
throw new Error('The given string is not valid hexadecimal.');
}
return this.fromBytes(hexToBin(hex));
return this.fromBytes(Bytes.fromHex(hex).toBytes());
}
/**
@@ -149,7 +161,7 @@ export class BlockHeader {
* @returns 160-character hex string representing the block header
*/
toHex(): string {
return binToHex(this.toBytes());
return Bytes.fromBytes(this.toBytes()).toHex();
}
/**
@@ -193,7 +205,7 @@ export class BlockHeader {
* @returns 64-character hex string
*/
getPreviousBlockHashHex(): string {
return binToHex(this.previousBlockHash);
return Bytes.fromBytes(this.previousBlockHash).toHex();
}
/**
@@ -201,7 +213,7 @@ export class BlockHeader {
* @returns 64-character hex string
*/
getMerkleRootHex(): string {
return binToHex(this.merkleRoot);
return Bytes.fromBytes(this.merkleRoot).toHex();
}
/**
@@ -217,6 +229,6 @@ export class BlockHeader {
* @returns 64-character hex string
*/
getHashHex(): string {
return binToHex(this.getHash());
return Bytes.fromBytes(this.getHash()).toHex();
}
}