File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,15 @@ describe("isValidAddress", () => {
1111 ) ;
1212 } ) ;
1313
14+ it ( "accepts a Penumbra compat address" , ( ) => {
15+ expect (
16+ isValidAddress (
17+ "penumbracompat11ld2kghffzgwq4597ejpgmnwxa7ju0cndytuxtsjh8qhjyfuwq0rwd5flnw4a3fgclw7m5puh50nskn2c88flhne2hzchnpxru609d5wgmqqvhdf0sy2tktqfcm2p2tmxeuc86n" ,
18+ "penumbracompat1" ,
19+ ) ,
20+ ) . toBe ( true ) ;
21+ } ) ;
22+
1423 it ( "rejects an invalid address" , ( ) => {
1524 expect ( isValidAddress ( "cosmos1fail" , "cosmos" ) ) . toBe ( false ) ;
1625 } ) ;
Original file line number Diff line number Diff line change 11import { fromBech32 } from "@cosmjs/encoding" ;
22
3+ // Penumbra are up to 150 chars. ibc-go has a limit of 2048.
4+ // See https://github.com/cosmos/cosmjs/pull/1674
5+ const lengthLimit = 512 ;
6+
37export function isValidAddress ( input : string , requiredPrefix : string ) : boolean {
4- if ( input . length > 2048 ) {
5- return false ;
6- }
78 try {
8- const { prefix, data } = fromBech32 ( input ) ;
9+ const { prefix, data } = fromBech32 ( input , lengthLimit ) ;
910 if ( prefix !== requiredPrefix ) {
1011 return false ;
1112 }
12- return data . length >= 20 ;
13+ return data . length >= 20 && data . length <= 128 ;
1314 } catch {
1415 return false ;
1516 }
You can’t perform that action at this time.
0 commit comments