XO Integration Part II
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user