Skip to content

Commit 518b5d9

Browse files
committed
Update validation.ts
1 parent a02f5d6 commit 518b5d9

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/utils/validation.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Bitcoin address validation
1+
// Bitcoin address validation (no changes)
22
export const isBitcoinAddress = (address: string): boolean => {
33
// Basic Bitcoin address format validation
44
const legacyFormat = /^[1][a-km-zA-HJ-NP-Z1-9]{25,34}$/; // Legacy address format (starts with 1)
@@ -12,21 +12,41 @@ export const isBitcoinAddress = (address: string): boolean => {
1212
);
1313
};
1414

15-
// Transaction ID validation
15+
// Transaction ID validation (modified with heuristic)
1616
export const isTransactionId = (txid: string): boolean => {
1717
// Transaction ID must be exactly 64 characters long and contain only hexadecimal characters
1818
const txidFormat = /^[a-fA-F0-9]{64}$/;
19-
return txidFormat.test(txid);
19+
if (!txidFormat.test(txid)) {
20+
return false; // Not a valid hex format or length
21+
}
22+
23+
// Heuristic: Transaction IDs are less likely to start with 6 consecutive zeros
24+
const leadingZeros = txid.substring(0, 6);
25+
if (leadingZeros === '000000') {
26+
return false; // If it starts with 6 zeros, likely a Block Hash (heuristic)
27+
}
28+
29+
return true; // Likely a Transaction ID based on heuristic
2030
};
2131

22-
// Block hash validation
32+
// Block hash validation (modified with heuristic)
2333
export const isBlockHash = (hash: string): boolean => {
2434
// Block hash must be exactly 64 characters long and contain only hexadecimal characters
2535
const blockHashFormat = /^[a-fA-F0-9]{64}$/;
26-
return blockHashFormat.test(hash);
36+
if (!blockHashFormat.test(hash)) {
37+
return false; // Not a valid hex format or length
38+
}
39+
40+
// Heuristic: Block Hashes are more likely to start with 6 consecutive zeros
41+
const leadingZeros = hash.substring(0, 6);
42+
if (leadingZeros === '000000') {
43+
return true; // Likely a Block Hash based on heuristic
44+
}
45+
46+
return false; // Not likely a Block Hash based on heuristic
2747
};
2848

29-
// Block height validation
49+
// Block height validation (no changes)
3050
export const isBlockHeight = (height: number): boolean => {
3151
// Current Bitcoin block height is around 800,000 as of 2025
3252
// This is a simple validation to ensure the height is reasonable

0 commit comments

Comments
 (0)