|
2 | 2 | * @prettier |
3 | 3 | */ |
4 | 4 | import { |
| 5 | + classifyRecoveryKeys, |
5 | 6 | AddressCoinSpecific, |
6 | 7 | BitGoBase, |
7 | 8 | BuildNftTransferDataOptions, |
@@ -1515,6 +1516,9 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin implem |
1515 | 1516 | } |
1516 | 1517 | } |
1517 | 1518 |
|
| 1519 | + // NOTE: deliberately keyed on params.userKey only, not getTssCommonKeychain. Resolving the |
| 1520 | + // TSS fallback chain here would scan an extra derived address whenever a caller supplies |
| 1521 | + // backupKey without userKey, changing which addresses a consolidation sweeps. |
1518 | 1522 | if (params.userKey) { |
1519 | 1523 | try { |
1520 | 1524 | const derivedAddress = this.deriveAddressFromPublicKey(params.userKey, index); |
@@ -1554,22 +1558,23 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin implem |
1554 | 1558 | const consolidatedTransactions: any[] = []; |
1555 | 1559 | let lastScanIndex = startIdx; |
1556 | 1560 |
|
| 1561 | + // A TSS recovery sweeps the m/0 address derived from the common keychain and never reads |
| 1562 | + // walletContractAddress, so the forwarder address was never the address being swept here. |
| 1563 | + // Pass the address actually swept, which is also what the key mismatch check compares. |
| 1564 | + // Loop-invariant, and left undefined when no keychain was supplied so recover() reports that. |
| 1565 | + const tssCommonKeychain = params.isTss ? this.getTssCommonKeychain(params) : ''; |
| 1566 | + const tssBaseAddress = tssCommonKeychain ? this.deriveAddressFromPublicKey(tssCommonKeychain, 0) : undefined; |
| 1567 | + |
1557 | 1568 | for (let i = startIdx; i < endIdx; i++) { |
1558 | 1569 | const consolidationAddress = this.getConsolidationAddress(params, i); |
1559 | 1570 | for (const address of consolidationAddress) { |
1560 | | - // A TSS recovery sweeps the m/0 address derived from the common keychain and never reads |
1561 | | - // walletContractAddress, so the forwarder address was never the address being swept here. |
1562 | | - // Pass the address actually swept, which is also what the key mismatch check compares. |
1563 | | - const recoverWalletContractAddress = params.isTss |
1564 | | - ? this.deriveAddressFromPublicKey(this.getTssCommonKeychain(params), 0) |
1565 | | - : address; |
1566 | 1571 | const recoverParams = { |
1567 | 1572 | apiKey: params.apiKey, |
1568 | 1573 | backupKey: params.backupKey || '', |
1569 | 1574 | gasLimit: params.gasLimit, |
1570 | 1575 | recoveryDestination: params.recoveryDestination || '', |
1571 | 1576 | userKey: params.userKey || '', |
1572 | | - walletContractAddress: recoverWalletContractAddress, |
| 1577 | + walletContractAddress: tssBaseAddress ?? address, |
1573 | 1578 | derivationSeed: '', |
1574 | 1579 | isTss: params.isTss, |
1575 | 1580 | eip1559: { |
@@ -1635,18 +1640,9 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin implem |
1635 | 1640 | } |
1636 | 1641 |
|
1637 | 1642 | this.validateRecoveryParams(params); |
1638 | | - // validateRecoveryParams guarantees both keys are present outside of unsigned TSS sweeps, |
1639 | | - // which never reach this non-TSS path. Classify from the RAW keys, as before the type change: |
1640 | | - // stripping whitespace first would flip the result for a key pasted with a leading newline. |
1641 | | - const rawUserKey = params.userKey ?? ''; |
1642 | | - const rawBackupKey = params.backupKey ?? ''; |
1643 | | - const isUnsignedSweep = |
1644 | | - params.isUnsignedSweep ?? |
1645 | | - getIsUnsignedSweep({ userKey: rawUserKey, backupKey: rawBackupKey, isTss: params.isTss }); |
1646 | | - |
1647 | | - // Clean up whitespace from entered values |
1648 | | - let userKey = rawUserKey.replace(/\s/g, ''); |
1649 | | - const backupKey = rawBackupKey.replace(/\s/g, ''); |
| 1643 | + const recoveryKeys = classifyRecoveryKeys(params); |
| 1644 | + const { backupKey, isUnsignedSweep } = recoveryKeys; |
| 1645 | + let userKey = recoveryKeys.userKey; |
1650 | 1646 | const gasLimit = new optionalDeps.ethUtil.BN(this.setGasLimit(params.gasLimit)); |
1651 | 1647 | const gasPrice = params.eip1559 |
1652 | 1648 | ? new optionalDeps.ethUtil.BN(params.eip1559.maxFeePerGas) |
|
0 commit comments