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