@@ -3353,4 +3353,84 @@ describe('SOL:', function () {
33533353 ) ;
33543354 } ) ;
33553355 } ) ;
3356+
3357+ describe ( 'isWalletAddress' , ( ) => {
3358+ it ( 'should verify valid wallet address with correct keychain and index' , async function ( ) {
3359+ const address = '7YAesfwPk41VChUgr65bm8FEep7ymWqLSW5rpYB5zZPY' ;
3360+ const commonKeychain =
3361+ '8ea32ecacfc83effbd2e2790ee44fa7c59b4d86c29a12f09fb613d8195f93f4e21875cad3b98adada40c040c54c3569467df41a020881a6184096378701862bd' ;
3362+ const index = '1' ;
3363+ const keychains = [ { commonKeychain } ] ;
3364+
3365+ const result = await basecoin . isWalletAddress ( { keychains, address, index } ) ;
3366+ result . should . equal ( true ) ;
3367+ } ) ;
3368+
3369+ it ( 'should return false for address with incorrect keychain' , async function ( ) {
3370+ const address = '7YAesfwPk41VChUgr65bm8FEep7ymWqLSW5rpYB5zZPY' ;
3371+ const wrongKeychain =
3372+ '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' ;
3373+ const index = '1' ;
3374+ const keychains = [ { commonKeychain : wrongKeychain } ] ;
3375+
3376+ const result = await basecoin . isWalletAddress ( { keychains, address, index } ) ;
3377+ result . should . equal ( false ) ;
3378+ } ) ;
3379+
3380+ it ( 'should return false for address with incorrect index' , async function ( ) {
3381+ const address = '7YAesfwPk41VChUgr65bm8FEep7ymWqLSW5rpYB5zZPY' ;
3382+ const commonKeychain =
3383+ '8ea32ecacfc83effbd2e2790ee44fa7c59b4d86c29a12f09fb613d8195f93f4e21875cad3b98adada40c040c54c3569467df41a020881a6184096378701862bd' ;
3384+ const wrongIndex = '999' ;
3385+ const keychains = [ { commonKeychain } ] ;
3386+
3387+ const result = await basecoin . isWalletAddress ( { keychains, address, index : wrongIndex } ) ;
3388+ result . should . equal ( false ) ;
3389+ } ) ;
3390+
3391+ it ( 'should throw error for invalid address' , async function ( ) {
3392+ const invalidAddress = 'invalidaddress' ;
3393+ const commonKeychain =
3394+ '8ea32ecacfc83effbd2e2790ee44fa7c59b4d86c29a12f09fb613d8195f93f4e21875cad3b98adada40c040c54c3569467df41a020881a6184096378701862bd' ;
3395+ const index = '1' ;
3396+ const keychains = [ { commonKeychain } ] ;
3397+
3398+ await assert . rejects ( async ( ) => await basecoin . isWalletAddress ( { keychains, address : invalidAddress , index } ) , {
3399+ message : `invalid address: ${ invalidAddress } ` ,
3400+ } ) ;
3401+ } ) ;
3402+
3403+ it ( 'should throw error when keychains are missing' , async function ( ) {
3404+ const address = '7YAesfwPk41VChUgr65bm8FEep7ymWqLSW5rpYB5zZPY' ;
3405+ const index = '1' ;
3406+
3407+ await assert . rejects ( async ( ) => await basecoin . isWalletAddress ( { address, index } as any ) , {
3408+ message : 'missing required param keychains' ,
3409+ } ) ;
3410+ } ) ;
3411+
3412+ it ( 'should throw error when keychains have different commonKeychains' , async function ( ) {
3413+ const address = '7YAesfwPk41VChUgr65bm8FEep7ymWqLSW5rpYB5zZPY' ;
3414+ const commonKeychain1 =
3415+ '8ea32ecacfc83effbd2e2790ee44fa7c59b4d86c29a12f09fb613d8195f93f4e21875cad3b98adada40c040c54c3569467df41a020881a6184096378701862bd' ;
3416+ const commonKeychain2 =
3417+ '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' ;
3418+ const index = '1' ;
3419+ const keychains = [ { commonKeychain : commonKeychain1 } , { commonKeychain : commonKeychain2 } ] ;
3420+
3421+ await assert . rejects ( async ( ) => await basecoin . isWalletAddress ( { keychains, address, index } ) , {
3422+ message : 'all keychains must have the same commonKeychain for MPC coins' ,
3423+ } ) ;
3424+ } ) ;
3425+ } ) ;
3426+
3427+ describe ( 'getAddressFromPublicKey' , ( ) => {
3428+ it ( 'should convert public key to base58 address' , function ( ) {
3429+ const publicKey = '61220a9394802b1d1df37b35f7a3197970f48081092cee011fc98f7b71b2bd43' ;
3430+ const expectedAddress = '7YAesfwPk41VChUgr65bm8FEep7ymWqLSW5rpYB5zZPY' ;
3431+
3432+ const address = basecoin . getAddressFromPublicKey ( publicKey ) ;
3433+ address . should . equal ( expectedAddress ) ;
3434+ } ) ;
3435+ } ) ;
33563436} ) ;
0 commit comments