@@ -1243,40 +1243,57 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
1243
1243
return calculateForwarderV1Address ( forwarderFactoryAddress , calculationSalt , initCode ) ;
1244
1244
}
1245
1245
1246
- deriveAddressFromPublicKey ( publicKey : string ) : string {
1246
+ deriveAddressFromPublicKey ( commonKeychain : string , index : number ) : string {
1247
+ const derivationPath = `m/${ index } ` ;
1248
+ const pubkeySize = 33 ;
1249
+
1250
+ const ecdsaMpc = new Ecdsa ( ) ;
1251
+ const derivedPublicKey = Buffer . from ( ecdsaMpc . deriveUnhardened ( commonKeychain , derivationPath ) , 'hex' )
1252
+ . subarray ( 0 , pubkeySize )
1253
+ . toString ( 'hex' ) ;
1254
+
1255
+ const publicKey = Buffer . from ( derivedPublicKey , 'hex' ) . slice ( 0 , 66 ) . toString ( 'hex' ) ;
1256
+
1247
1257
const keyPair = new KeyPairLib ( { pub : publicKey } ) ;
1248
1258
const address = keyPair . getAddress ( ) ;
1249
1259
return address ;
1250
1260
}
1251
1261
1252
- getConsolidationAddress ( params : EthConsolidationRecoveryOptions , index : number ) : string {
1262
+ getConsolidationAddress ( params : EthConsolidationRecoveryOptions , index : number ) : string [ ] {
1263
+ const possibleConsolidationAddresses : string [ ] = [ ] ;
1253
1264
if ( params . walletContractAddress && params . bitgoFeeAddress ) {
1254
1265
const ethNetwork = this . getNetwork ( ) ;
1255
1266
const forwarderFactoryAddress = ethNetwork ?. walletV4ForwarderFactoryAddress as string ;
1256
1267
const forwarderImplementationAddress = ethNetwork ?. walletV4ForwarderImplementationAddress as string ;
1257
1268
try {
1258
- return this . generateForwarderAddress (
1269
+ const forwarderAddress = this . generateForwarderAddress (
1259
1270
params . walletContractAddress ,
1260
1271
params . bitgoFeeAddress ,
1261
1272
forwarderFactoryAddress ,
1262
1273
forwarderImplementationAddress ,
1263
1274
index
1264
1275
) ;
1276
+ possibleConsolidationAddresses . push ( forwarderAddress ) ;
1265
1277
} catch ( e ) {
1266
1278
console . log ( `Failed to generate forwarder address: ${ e . message } ` ) ;
1267
1279
}
1268
1280
}
1269
1281
1270
1282
if ( params . userKey ) {
1271
1283
try {
1272
- return this . deriveAddressFromPublicKey ( params . userKey ) ;
1284
+ const derivedAddress = this . deriveAddressFromPublicKey ( params . userKey , index ) ;
1285
+ possibleConsolidationAddresses . push ( derivedAddress ) ;
1273
1286
} catch ( e ) {
1274
- console . log ( `Failed to generate derived address: ${ e . message } ` ) ;
1287
+ console . log ( `Failed to generate derived address: ${ e } ` ) ;
1275
1288
}
1276
1289
}
1277
- throw new Error (
1278
- 'Unable to generate consolidation address. Check that wallet contract address, fee address, or user key is valid.'
1279
- ) ;
1290
+
1291
+ if ( possibleConsolidationAddresses . length === 0 ) {
1292
+ throw new Error (
1293
+ 'Unable to generate consolidation address. Check that wallet contract address, fee address, or user key is valid.'
1294
+ ) ;
1295
+ }
1296
+ return possibleConsolidationAddresses ;
1280
1297
}
1281
1298
1282
1299
async recoverConsolidations ( params : EthConsolidationRecoveryOptions ) : Promise < Record < string , unknown > | undefined > {
@@ -1303,50 +1320,49 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
1303
1320
1304
1321
for ( let i = startIdx ; i < endIdx ; i ++ ) {
1305
1322
const consolidationAddress = this . getConsolidationAddress ( params , i ) ;
1306
-
1307
- const recoverParams = {
1308
- apiKey : params . apiKey ,
1309
- backupKey : params . backupKey ,
1310
- gasLimit : params . gasLimit ,
1311
- recoveryDestination : params . recoveryDestination ,
1312
- userKey : params . userKey ,
1313
- walletContractAddress : consolidationAddress ,
1314
- derivationSeed : '' ,
1315
- isTss : params . isTss ,
1316
- eip1559 : {
1317
- maxFeePerGas : params . eip1559 ?. maxFeePerGas || 20 ,
1318
- maxPriorityFeePerGas : params . eip1559 ?. maxPriorityFeePerGas || 200000 ,
1319
- } ,
1320
- replayProtectionOptions : {
1321
- chain : params . replayProtectionOptions ?. chain || 0 ,
1322
- hardfork : params . replayProtectionOptions ?. hardfork || 'london' ,
1323
- } ,
1324
- bitgoKey : '' ,
1325
- ignoreAddressTypes : [ ] ,
1326
- } ;
1327
-
1328
- let recoveryTransaction ;
1329
- try {
1330
- recoveryTransaction = await this . recover ( recoverParams ) ;
1331
- } catch ( e ) {
1332
- if (
1333
- e . message === 'Did not find address with funds to recover' ||
1334
- e . message === 'Did not find token account to recover tokens, please check token account' ||
1335
- e . message === 'Not enough token funds to recover'
1336
- ) {
1337
- lastScanIndex = i ;
1338
- continue ;
1323
+ for ( const address of consolidationAddress ) {
1324
+ const recoverParams = {
1325
+ apiKey : params . apiKey ,
1326
+ backupKey : params . backupKey ,
1327
+ gasLimit : params . gasLimit ,
1328
+ recoveryDestination : params . recoveryDestination ,
1329
+ userKey : params . userKey ,
1330
+ walletContractAddress : address ,
1331
+ derivationSeed : '' ,
1332
+ isTss : params . isTss ,
1333
+ eip1559 : {
1334
+ maxFeePerGas : params . eip1559 ?. maxFeePerGas || 20 ,
1335
+ maxPriorityFeePerGas : params . eip1559 ?. maxPriorityFeePerGas || 200000 ,
1336
+ } ,
1337
+ replayProtectionOptions : {
1338
+ chain : params . replayProtectionOptions ?. chain || 0 ,
1339
+ hardfork : params . replayProtectionOptions ?. hardfork || 'london' ,
1340
+ } ,
1341
+ bitgoKey : '' ,
1342
+ ignoreAddressTypes : [ ] ,
1343
+ } ;
1344
+ let recoveryTransaction ;
1345
+ try {
1346
+ recoveryTransaction = await this . recover ( recoverParams ) ;
1347
+ } catch ( e ) {
1348
+ if (
1349
+ e . message === 'Did not find address with funds to recover' ||
1350
+ e . message === 'Did not find token account to recover tokens, please check token account' ||
1351
+ e . message === 'Not enough token funds to recover'
1352
+ ) {
1353
+ lastScanIndex = i ;
1354
+ continue ;
1355
+ }
1356
+ throw e ;
1357
+ }
1358
+ if ( isUnsignedSweep ) {
1359
+ consolidationTransactions . push ( ( recoveryTransaction as MPCSweepTxs ) . txRequests [ 0 ] ) ;
1360
+ } else {
1361
+ consolidationTransactions . push ( recoveryTransaction ) ;
1339
1362
}
1340
- throw e ;
1341
- }
1342
-
1343
- if ( isUnsignedSweep ) {
1344
- consolidationTransactions . push ( ( recoveryTransaction as MPCSweepTxs ) . txRequests [ 0 ] ) ;
1345
- } else {
1346
- consolidationTransactions . push ( recoveryTransaction ) ;
1347
1363
}
1348
1364
1349
- lastScanIndex = i ;
1365
+ // lastScanIndex = i;
1350
1366
}
1351
1367
1352
1368
if ( consolidationTransactions . length === 0 ) {
0 commit comments