@@ -93,7 +93,23 @@ export const splitAddress = (address, format = "string") => {
9393export function validateCelestiaAddress ( address ) {
9494 if ( ! address ) return false
9595
96- const prefixes = [ "celestiavaloper" , "celestiavalcons" , "celestia" ] // order is important
96+ const prefix = "celestia1"
97+
98+ if ( ! address . startsWith ( prefix ) ) return false
99+
100+ const hashPart = address . slice ( prefix . length )
101+ if ( hashPart . length !== 38 ) return false
102+
103+ const validChars = / ^ [ q p z r y 9 x 8 g f 2 t v d w 0 s 3 j n 5 4 k h c e 6 m u a 7 l ] + $ /
104+ if ( ! validChars . test ( hashPart ) ) return false
105+
106+ return true
107+ }
108+
109+ export function validateCelestiaValidatorAddress ( address ) {
110+ if ( ! address ) return false
111+
112+ const prefixes = [ "celestiavaloper" , "celestiavalcons" ]
97113 const prefix = prefixes . find ( p => address . startsWith ( p ) )
98114 if ( ! prefix ) return false
99115
@@ -103,6 +119,7 @@ export function validateCelestiaAddress(address) {
103119 if ( hashPart . length !== 38 ) return false
104120
105121 const validChars = / ^ [ q p z r y 9 x 8 g f 2 t v d w 0 s 3 j n 5 4 k h c e 6 m u a 7 l ] + $ /
122+
106123 if ( ! validChars . test ( hashPart ) ) return false
107124
108125 return true
@@ -257,3 +274,24 @@ export function hexToRgba(hex, alpha = 255) {
257274
258275 return `rgba(${ r } , ${ g } , ${ b } , ${ a } )`
259276}
277+
278+ export function isValidId ( id , type ) {
279+ switch ( type ) {
280+ case "block" :
281+ case "proposal" :
282+ case "validator" :
283+ return / ^ [ 0 - 9 ] + $ / . test ( id ) ;
284+
285+ case "tx" :
286+ return / ^ [ A - F a - f 0 - 9 ] { 64 } $ / . test ( id ) ;
287+
288+ case "namespace" :
289+ return / ^ [ 0 - 9 a - f ] { 56 } $ / . test ( id ) ;
290+
291+ case "address" :
292+ return validateCelestiaAddress ( id ) ;
293+
294+ default :
295+ return false ;
296+ }
297+ }
0 commit comments