1- // Bitcoin address validation
1+ // Bitcoin address validation (no changes)
22export const isBitcoinAddress = ( address : string ) : boolean => {
33 // Basic Bitcoin address format validation
44 const legacyFormat = / ^ [ 1 ] [ a - k m - z A - H J - N P - Z 1 - 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)
1616export const isTransactionId = ( txid : string ) : boolean => {
1717 // Transaction ID must be exactly 64 characters long and contain only hexadecimal characters
1818 const txidFormat = / ^ [ a - f A - F 0 - 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)
2333export const isBlockHash = ( hash : string ) : boolean => {
2434 // Block hash must be exactly 64 characters long and contain only hexadecimal characters
2535 const blockHashFormat = / ^ [ a - f A - F 0 - 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)
3050export 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