Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion modules/abstract-eth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
},
"devDependencies": {
"@bitgo/sdk-api": "^1.56.1",
"@bitgo/sdk-test": "^8.0.48"
"@bitgo/sdk-test": "^8.0.48",
"@bitgo/sdk-lib-mpc": "^10.1.0"
}
}
16 changes: 15 additions & 1 deletion modules/abstract-eth/src/abstractEthLikeNewCoins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import {
TransactionBuilder,
TransferBuilder,
} from './lib';
import { getDerivationPath } from '@bitgo/sdk-lib-mpc';

/**
* The prebuilt hop transaction returned from the HSM
Expand Down Expand Up @@ -218,6 +219,8 @@ export type TSSRecoverOptions = RecoverOptionsWithBytes | NonTSSRecoverOptions;
export type RecoverOptions = {
userKey: string;
backupKey: string;
bitgoKey?: string;
seed?: string;
walletPassphrase?: string;
walletContractAddress: string; // use this as walletBaseAddress for TSS
recoveryDestination: string;
Expand Down Expand Up @@ -1812,6 +1815,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
// Clean up whitespace from entered values
const userPublicOrPrivateKeyShare = params.userKey.replace(/\s/g, '');
const backupPrivateOrPublicKeyShare = params.backupKey.replace(/\s/g, '');
const bitgoCommonKeychain = params.bitgoKey?.replace(/\s/g, '');

const gasLimit = new optionalDeps.ethUtil.BN(this.setGasLimit(params.gasLimit));
const gasPrice = params.eip1559
Expand All @@ -1822,10 +1826,20 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
getIsUnsignedSweep({
userKey: userPublicOrPrivateKeyShare,
backupKey: backupPrivateOrPublicKeyShare,
bitgoKey: bitgoCommonKeychain,
isTss: params.isTss,
})
) {
const backupKeyPair = new KeyPairLib({ pub: backupPrivateOrPublicKeyShare });
let backupKeyPair: KeyPairLib;
if (bitgoCommonKeychain) {
const MPC = new Ecdsa();
const path = params.seed ? getDerivationPath(params.seed) + '/0' : 'm/0';
const derivedCommonKeyChain = MPC.deriveUnhardened(bitgoCommonKeychain, path);
backupKeyPair = new KeyPairLib({ pub: derivedCommonKeyChain.slice(0, 66) });
} else {
backupKeyPair = new KeyPairLib({ pub: backupPrivateOrPublicKeyShare });
}

const baseAddress = backupKeyPair.getAddress();
const { txInfo, tx, nonce } = await this.buildTssRecoveryTxn(baseAddress, gasPrice, gasLimit, params);
return this.formatForOfflineVaultTSS(
Expand Down
13 changes: 7 additions & 6 deletions modules/bitgo/test/v2/unit/recovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ describe('Recovery:', function () {
params: {
module: 'account',
action: 'txlist',
address: '0xe7406dc43d13f698fb41a345c7783d39a4c2d191',
address: '0xd18ee37daeab8468020dd65fa7f6f6b9ac741584',
},
response: {
status: '0',
Expand All @@ -720,7 +720,7 @@ describe('Recovery:', function () {
params: {
module: 'account',
action: 'balance',
address: '0xe7406dc43d13f698fb41a345c7783d39a4c2d191',
address: '0xd18ee37daeab8468020dd65fa7f6f6b9ac741584',
},
response: {
status: '1',
Expand Down Expand Up @@ -1098,12 +1098,13 @@ describe('Recovery:', function () {

const basecoin = bitgo.coin('hteth');

const userKey = '03f8606a595917de4cf2244e27b7fba172505469392ad385d2dd2b3588a6bb878c';
const backupKey = '03f8606a595917de4cf2244e27b7fba172505469392ad385d2dd2b3588a6bb878c';
const bitgoKey =
'03ffd706c97ce5438ffa38016f3708a3e4ffa7126a2d03d3e02a087767950d72c9197ee747c5c146ae62f8d80fe313c943139190ce3e49727a9707e9626b15fc0d';

recoveryParams = {
userKey: userKey,
backupKey: backupKey,
userKey: '',
backupKey: '',
bitgoKey: bitgoKey,
walletContractAddress: '0xe7406dc43d13f698fb41a345c7783d39a4c2d191',
recoveryDestination: '0xac05da78464520aa7c9d4c19bd7a440b111b3054',
walletPassphrase: TestBitGo.V2.TEST_RECOVERY_PASSCODE,
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-core/src/bitgo/recovery/initiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,17 @@ export function getIsKrsRecovery({ backupKey, userKey }: { backupKey: string; us
export function getIsUnsignedSweep({
backupKey,
userKey,
bitgoKey,
isTss,
}: {
backupKey: string;
userKey: string;
bitgoKey?: string;
isTss?: boolean;
}): boolean {
if (isTss && bitgoKey) {
return true;
}
if (isTss) {
try {
return typeof JSON.parse(backupKey) === 'string' && typeof JSON.parse(userKey) === 'string';
Expand Down
Loading