XO Integration Part II

This commit is contained in:
Jim Hamill
2025-05-08 08:05:46 +00:00
parent 476a535768
commit 1870877df5
13 changed files with 164 additions and 21 deletions
+25
View File
@@ -88,6 +88,31 @@ export class BlockHeader {
return new this(bytes);
}
static generateRandom(timestampUnix?: number): BlockHeader {
// Create buffer for the 80-byte header
const header = new Uint8Array(80);
// Fill with random bytes
crypto.getRandomValues(header);
// Optional: Set specific version if needed
// First 4 bytes is version (little-endian)
const version = 1;
header[0] = version & 0xff;
header[1] = (version >> 8) & 0xff;
header[2] = (version >> 16) & 0xff;
header[3] = (version >> 24) & 0xff;
// Optional: Set realistic timestamp (current time)
const timestamp = timestampUnix || Math.floor(Date.now() / 1000);
header[68] = timestamp & 0xff;
header[69] = (timestamp >> 8) & 0xff;
header[70] = (timestamp >> 16) & 0xff;
header[71] = (timestamp >> 24) & 0xff;
return this.fromBytes(header);
}
/**
* Checks whether the given BlochHeader is of a valid structure.
*