@@ -238,76 +238,88 @@ describe('Internet computer', function () {
238238 } ;
239239
240240 describe ( 'Wallet VersionKey 1' , ( ) => {
241+ let keychains ;
242+
243+ before ( function ( ) {
244+ keychains = [
245+ { commonKeychain : addressVerificationData . commonKeychain } ,
246+ { commonKeychain : addressVerificationData . commonKeychain } ,
247+ { commonKeychain : addressVerificationData . commonKeychain } ,
248+ ] ;
249+ } ) ;
250+
241251 it ( 'should verify a valid memo-based address' , async function ( ) {
242- const rootAddress = testData . Accounts . account1 . address ;
252+ const rootAddress = addressVerificationData . rootAddress ;
243253 const addressWithMemo = `${ rootAddress } ?memoId=123` ;
244254
245255 const params = {
246256 address : addressWithMemo ,
247257 rootAddress : rootAddress ,
248258 walletVersion : 1 ,
249- keychains : [ ] ,
250- index : 123 ,
259+ keychains : keychains ,
260+ index : 0 ,
251261 } ;
252262
253263 const result = await basecoin . isWalletAddress ( params ) ;
254264 result . should . equal ( true ) ;
255265 } ) ;
256266
257267 it ( 'should verify address with memoId=0' , async function ( ) {
258- const rootAddress = testData . Accounts . account1 . address ;
268+ const rootAddress = addressVerificationData . rootAddress ;
259269 const addressWithMemo = `${ rootAddress } ?memoId=0` ;
260270
261271 const params = {
262272 address : addressWithMemo ,
263273 rootAddress : rootAddress ,
264274 walletVersion : 1 ,
265- keychains : [ ] ,
275+ keychains : keychains ,
266276 index : 0 ,
267277 } ;
268278
269279 const result = await basecoin . isWalletAddress ( params ) ;
270280 result . should . equal ( true ) ;
271281 } ) ;
272282
273- it ( 'should fail when base address does not match root address ' , async function ( ) {
274- const rootAddress = testData . Accounts . account1 . address ;
283+ it ( 'should fail when extracted root does not match provided rootAddress param ' , async function ( ) {
284+ const rootAddress = addressVerificationData . rootAddress ;
275285 const differentAddress = testData . Accounts . account2 . address ;
276286 const addressWithMemo = `${ differentAddress } ?memoId=123` ;
277287
278288 const params = {
279289 address : addressWithMemo ,
280290 rootAddress : rootAddress ,
281291 walletVersion : 1 ,
282- keychains : [ ] ,
283- index : 123 ,
292+ keychains : keychains ,
293+ index : 0 ,
284294 } ;
285295
286- const result = await basecoin . isWalletAddress ( params ) ;
287- result . should . equal ( false ) ;
296+ // The extracted root (differentAddress) doesn't match provided rootAddress
297+ await basecoin
298+ . isWalletAddress ( params )
299+ . should . be . rejectedWith ( `address validation failure: expected ${ rootAddress } but got ${ differentAddress } ` ) ;
288300 } ) ;
289301
290302 it ( 'should throw error when rootAddress is missing for wallet version 1' , async function ( ) {
291- const address = `${ testData . Accounts . account1 . address } ?memoId=123` ;
303+ const address = `${ addressVerificationData . rootAddress } ?memoId=123` ;
292304
293305 const params = {
294306 address : address ,
295307 walletVersion : 1 ,
296- keychains : [ ] ,
297- index : 123 ,
308+ keychains : keychains ,
309+ index : 0 ,
298310 } ;
299311
300312 await basecoin . isWalletAddress ( params ) . should . be . rejectedWith ( 'rootAddress is required for wallet version 1' ) ;
301313 } ) ;
302314
303315 it ( 'should throw error when memoId is missing for wallet version 1' , async function ( ) {
304- const rootAddress = testData . Accounts . account1 . address ;
316+ const rootAddress = addressVerificationData . rootAddress ;
305317
306318 const params = {
307319 address : rootAddress ,
308320 rootAddress : rootAddress ,
309321 walletVersion : 1 ,
310- keychains : [ ] ,
322+ keychains : keychains ,
311323 index : 0 ,
312324 } ;
313325
@@ -317,21 +329,40 @@ describe('Internet computer', function () {
317329 } ) ;
318330
319331 it ( 'should handle large memoId values' , async function ( ) {
320- const rootAddress = testData . Accounts . account1 . address ;
332+ const rootAddress = addressVerificationData . rootAddress ;
321333 const largeMemoId = '9007199254740991' ;
322334 const addressWithMemo = `${ rootAddress } ?memoId=${ largeMemoId } ` ;
323335
324336 const params = {
325337 address : addressWithMemo ,
326338 rootAddress : rootAddress ,
327339 walletVersion : 1 ,
328- keychains : [ ] ,
329- index : Number ( largeMemoId ) ,
340+ keychains : keychains ,
341+ index : 0 ,
330342 } ;
331343
332344 const result = await basecoin . isWalletAddress ( params ) ;
333345 result . should . equal ( true ) ;
334346 } ) ;
347+
348+ it ( 'should fail when rootAddress does not match commonKeychain derivation' , async function ( ) {
349+ // Use a rootAddress that doesn't match what's derived from commonKeychain
350+ const invalidRootAddress = testData . Accounts . account1 . address ;
351+ const addressWithMemo = `${ invalidRootAddress } ?memoId=123` ;
352+
353+ const params = {
354+ address : addressWithMemo ,
355+ rootAddress : invalidRootAddress ,
356+ walletVersion : 1 ,
357+ keychains : keychains ,
358+ index : 0 ,
359+ } ;
360+
361+ // rootAddress is cryptographically verified against commonKeychain
362+ await basecoin
363+ . isWalletAddress ( params )
364+ . should . be . rejectedWith ( `address validation failure: address ${ invalidRootAddress } is not a wallet address` ) ;
365+ } ) ;
335366 } ) ;
336367
337368 describe ( 'Wallet VersionKey 2+' , ( ) => {
@@ -368,7 +399,9 @@ describe('Internet computer', function () {
368399 walletVersion : 2 ,
369400 } ;
370401
371- await basecoin . isWalletAddress ( params ) . should . be . rejectedWith ( `invalid address: ${ invalidAddress } ` ) ;
402+ await basecoin
403+ . isWalletAddress ( params )
404+ . should . be . rejectedWith ( `address validation failure: address ${ invalidAddress } is not a wallet address` ) ;
372405 } ) ;
373406
374407 it ( 'should throw error when keychains is missing' , async function ( ) {
0 commit comments