@@ -2,6 +2,7 @@ import { BitGoAPI } from '@bitgo/sdk-api';
22import { TestBitGo , TestBitGoAPI } from '@bitgo/sdk-test' ;
33import { randomBytes } from 'crypto' ;
44import should = require( 'should' ) ;
5+ import assert = require( 'assert' ) ;
56import { Dot , Tdot , KeyPair } from '../../src' ;
67import * as testData from '../fixtures' ;
78import { chainName , txVersion , genesisHash , specVersion } from '../resources' ;
@@ -670,4 +671,71 @@ describe('DOT:', function () {
670671 ) ;
671672 } ) ;
672673 } ) ;
674+
675+ describe ( 'isWalletAddress' , ( ) => {
676+ it ( 'should verify valid wallet address with correct keychain and index' , async function ( ) {
677+ const address = '5DxD9nT16GQLrU6aB5pSS5VtxoZbVju3NHUCcawxZyZCTf74' ;
678+ const commonKeychain =
679+ '6d2d5150f6e435dfd9b4f225f2cc29d95ec3b61b34e8bec98693b1a7ffe44cd764f99ee5058838d785c73360ad4f24d78e0255ab2c368c09060b29a9b27f040e' ;
680+ const index = '3' ;
681+ const keychains = [ { id : '1' , type : 'tss' as const , commonKeychain } ] ;
682+
683+ const result = await basecoin . isWalletAddress ( { keychains, address, index } ) ;
684+ result . should . equal ( true ) ;
685+ } ) ;
686+
687+ it ( 'should return false for address with incorrect keychain' , async function ( ) {
688+ const address = '5DxD9nT16GQLrU6aB5pSS5VtxoZbVju3NHUCcawxZyZCTf74' ;
689+ const wrongKeychain =
690+ '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' ;
691+ const index = '3' ;
692+ const keychains = [ { id : '1' , type : 'tss' as const , commonKeychain : wrongKeychain } ] ;
693+
694+ const result = await basecoin . isWalletAddress ( { keychains, address, index } ) ;
695+ result . should . equal ( false ) ;
696+ } ) ;
697+
698+ it ( 'should return false for address with incorrect index' , async function ( ) {
699+ const address = '5DxD9nT16GQLrU6aB5pSS5VtxoZbVju3NHUCcawxZyZCTf74' ;
700+ const commonKeychain =
701+ '6d2d5150f6e435dfd9b4f225f2cc29d95ec3b61b34e8bec98693b1a7ffe44cd764f99ee5058838d785c73360ad4f24d78e0255ab2c368c09060b29a9b27f040e' ;
702+ const wrongIndex = '999' ;
703+ const keychains = [ { id : '1' , type : 'tss' as const , commonKeychain } ] ;
704+
705+ const result = await basecoin . isWalletAddress ( { keychains, address, index : wrongIndex } ) ;
706+ result . should . equal ( false ) ;
707+ } ) ;
708+
709+ it ( 'should throw error for invalid address' , async function ( ) {
710+ const invalidAddress = 'invalidaddress' ;
711+ const commonKeychain =
712+ '6d2d5150f6e435dfd9b4f225f2cc29d95ec3b61b34e8bec98693b1a7ffe44cd764f99ee5058838d785c73360ad4f24d78e0255ab2c368c09060b29a9b27f040e' ;
713+ const index = '3' ;
714+ const keychains = [ { id : '1' , type : 'tss' as const , commonKeychain } ] ;
715+
716+ await assert . rejects ( async ( ) => await basecoin . isWalletAddress ( { keychains, address : invalidAddress , index } ) , {
717+ message : `invalid address: ${ invalidAddress } ` ,
718+ } ) ;
719+ } ) ;
720+ } ) ;
721+
722+ describe ( 'getAddressFromPublicKey' , ( ) => {
723+ it ( 'should convert public key to SS58 address for testnet' , function ( ) {
724+ const publicKey = '53845d7b6a6e4a666fa2a0f500b88849b02926da5590993731d2b428b7643690' ;
725+ const expectedAddress = '5DxD9nT16GQLrU6aB5pSS5VtxoZbVju3NHUCcawxZyZCTf74' ;
726+
727+ const address = basecoin . getAddressFromPublicKey ( publicKey ) ;
728+ address . should . equal ( expectedAddress ) ;
729+ } ) ;
730+
731+ it ( 'should convert public key to SS58 address for mainnet' , function ( ) {
732+ const publicKey = '53845d7b6a6e4a666fa2a0f500b88849b02926da5590993731d2b428b7643690' ;
733+ // Mainnet uses different SS58 prefix (0) vs testnet (42)
734+ const address = prodCoin . getAddressFromPublicKey ( publicKey ) ;
735+ address . should . be . type ( 'string' ) ;
736+ address . length . should . be . greaterThan ( 0 ) ;
737+ // Should be different from testnet address
738+ address . should . not . equal ( '5DxD9nT16GQLrU6aB5pSS5VtxoZbVju3NHUCcawxZyZCTf74' ) ;
739+ } ) ;
740+ } ) ;
673741} ) ;
0 commit comments