File tree 2 files changed +9
-0
lines changed
2 files changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,9 @@ export class Keypair {
38
38
39
39
static fromAddress ( address ) {
40
40
let publicKey = strkey . decodeCheck ( "accountId" , address ) ;
41
+ if ( publicKey . length !== 32 ) {
42
+ throw new Error ( 'Invalid Stellar address' ) ;
43
+ }
41
44
return new this ( { publicKey} ) ;
42
45
}
43
46
Original file line number Diff line number Diff line change @@ -106,7 +106,13 @@ describe('Keypair.fromAddress', function() {
106
106
expect ( ( ) => StellarBase . Keypair . fromAddress ( "hel0" ) ) . to . throw ( )
107
107
expect ( ( ) => StellarBase . Keypair . fromAddress ( "masterpassphrasemasterpassphrase" ) ) . to . throw ( )
108
108
expect ( ( ) => StellarBase . Keypair . fromAddress ( "sfyjodTxbwLtRToZvi6yQ1KnpZriwTJ7n6nrASFR6goRviCU3Ff" ) ) . to . throw ( )
109
+ } ) ;
109
110
111
+ it ( "throws an error if the address isn't 32 bytes" , function ( ) {
112
+ expect ( ( ) => StellarBase . Keypair . fromAddress ( "masterpassphrasemasterpassphrase" ) ) . to . throw ( )
113
+ expect ( ( ) => StellarBase . Keypair . fromAddress ( "masterpassphrasemasterpassphrase" ) ) . to . throw ( )
114
+ expect ( ( ) => StellarBase . Keypair . fromAddress ( null ) ) . to . throw ( )
115
+ expect ( ( ) => StellarBase . Keypair . fromAddress ( ) ) . to . throw ( )
110
116
} ) ;
111
117
112
118
} ) ;
You can’t perform that action at this time.
0 commit comments