Use Bytes Primitive

This commit is contained in:
Jim Hamill
2025-07-23 00:27:41 +00:00
parent 9af5dc0087
commit e72c678785
10 changed files with 62 additions and 72 deletions
+8 -5
View File
@@ -23,15 +23,18 @@ import { hash256 } from '@bitauth/libauth';
* ```
*/
export class BlockHeader {
protected readonly bytes: Bytes;
// View of our data so that we can extract as numbers.
private view: DataView;
protected readonly view: DataView;
/**
* Creates a new BlockHeader instance.
* @param bytes The bytes representing our Block Header (Big Endian)
*/
protected constructor(private readonly bytes: Uint8Array) {
this.view = new DataView(bytes.buffer);
protected constructor(bytes: Bytes | Uint8Array) {
this.bytes = Bytes.from(bytes);
this.view = new DataView(this.bytes.buffer);
}
/**
@@ -58,7 +61,7 @@ export class BlockHeader {
* @returns A new BlockHeader instance
* @throws Error if the byte array length is not 80
*/
static fromBytes(bytes: Uint8Array): BlockHeader {
static fromBytes(bytes: Bytes | Uint8Array): BlockHeader {
if (bytes.length !== 80) {
throw new Error('Invalid block header length');
}
@@ -134,7 +137,7 @@ export class BlockHeader {
* Serializes the block header to a byte array.
* @returns 80-byte array containing the serialized block header
*/
toBytes(): Uint8Array {
toBytes(): Bytes {
return this.bytes;
}