Skip to content
Merged
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
5 changes: 3 additions & 2 deletions modules/abstract-cosmos/src/cosmosCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export class CosmosCoin<CustomMessage = never> extends BaseCoin {
throw new Error('Invalid key format');
}

return await ECDSAUtils.getMpcV2RecoveryKeyShares(userKey, backupKey, walletPassphrase);
return await ECDSAUtils.getMpcV2RecoveryKeyShares(userKey, backupKey, walletPassphrase, this.bitgo);
}

/**
Expand Down Expand Up @@ -491,7 +491,8 @@ export class CosmosCoin<CustomMessage = never> extends BaseCoin {
const { userKeyShare, backupKeyShare, commonKeyChain } = await ECDSAUtils.getMpcV2RecoveryKeyShares(
userKey,
backupKey,
params.walletPassphrase
params.walletPassphrase,
this.bitgo
); // baseAddress is not extracted

const MPC = new Ecdsa();
Expand Down
3 changes: 2 additions & 1 deletion modules/abstract-eth/src/abstractEthLikeNewCoins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2250,7 +2250,8 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
const { userKeyShare, backupKeyShare, commonKeyChain } = await ECDSAUtils.getMpcV2RecoveryKeyShares(
userPublicOrPrivateKeyShare,
backupPrivateOrPublicKeyShare,
params.walletPassphrase
params.walletPassphrase,
this.bitgo
);

const { gasLimit, gasPrice } = await this.getGasValues(params);
Expand Down
8 changes: 4 additions & 4 deletions modules/abstract-utxo/src/recovery/backupKeyRecovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
BitGoBase,
ErrorNoInputToRecover,
getKrsProvider,
getBip32Keys as getBip32KeysFromSdkCore,
getBip32KeysAsync as getBip32KeysFromSdkCore,
isTriple,
krsProviders,
Triple,
Expand Down Expand Up @@ -410,8 +410,8 @@ export function formatBackupKeyRecoveryResult(
return txInfo;
}

function getBip32Keys(bitgo: BitGoBase, params: RecoverParams): Triple<BIP32> {
const keys = getBip32KeysFromSdkCore(bitgo, params, { requireBitGoXpub: true });
async function getBip32Keys(bitgo: BitGoBase, params: RecoverParams): Promise<Triple<BIP32>> {
const keys = await getBip32KeysFromSdkCore(bitgo, params, { requireBitGoXpub: true });
Comment thread
bdesoky marked this conversation as resolved.
if (!isTriple(keys)) {
throw new Error(`expected key triple`);
}
Expand Down Expand Up @@ -469,7 +469,7 @@ export async function backupKeyRecovery(
}

// check whether key material and password authenticate the users and return parent keys of all three keys of the wallet
const keys = getBip32Keys(bitgo, params);
const keys = await getBip32Keys(bitgo, params);
const walletKeys = fixedScriptWallet.RootWalletKeys.from({
triple: keys,
derivationPrefixes: [params.userKeyPath || 'm/0/0', 'm/0/0', 'm/0/0'],
Expand Down
4 changes: 2 additions & 2 deletions modules/abstract-utxo/src/recovery/crossChainRecovery.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BIP32, CoinName, fixedScriptWallet, address as wasmAddress } from '@bitgo/wasm-utxo';
import { decryptAsync } from '@bitgo/sdk-api';
import { BitGoBase, IWallet, Keychain, Triple, Wallet } from '@bitgo/sdk-core';
import { decrypt } from '@bitgo/sdk-api';

import { AbstractUtxoCoin, TransactionInfo } from '../abstractUtxoCoin';
import { signAndVerifyPsbt } from '../transaction/fixedScript/signTransaction';
Expand Down Expand Up @@ -313,7 +313,7 @@ async function getPrv(xprv?: string, passphrase?: string, wallet?: IWallet | Wal
encryptedPrv = (await (wallet as WalletV1).getEncryptedUserKeychain()).encryptedXprv;
}

return getPrv(decrypt(passphrase, encryptedPrv));
return getPrv(await decryptAsync(passphrase, encryptedPrv));
}

/**
Expand Down
27 changes: 18 additions & 9 deletions modules/sdk-api/src/v1/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,10 @@ Wallet.prototype.createAndSignTransaction = function (params, callback) {
const safeUserKey = _.get(this.wallet, 'private.userPrivKey');
if (_.isString(safeUserKey) && _.isString(params.walletPassphrase)) {
// @ts-expect-error - no implicit this
transaction.signingKey = this.bitgo.decrypt({ password: params.walletPassphrase, input: safeUserKey });
transaction.signingKey = await this.bitgo.decryptAsync({
password: params.walletPassphrase,
input: safeUserKey,
});
} else {
throw e;
}
Expand Down Expand Up @@ -1809,10 +1812,13 @@ Wallet.prototype.getAndPrepareSigningKeychain = function (params, callback) {

// Caller provided a wallet passphrase
if (params.walletPassphrase) {
return self.getEncryptedUserKeychain().then(function (keychain) {
return self.getEncryptedUserKeychain().then(async function (keychain) {
// Decrypt the user key with a passphrase
try {
keychain.xprv = self.bitgo.decrypt({ password: params.walletPassphrase, input: keychain.encryptedXprv });
keychain.xprv = await self.bitgo.decryptAsync({
password: params.walletPassphrase,
input: keychain.encryptedXprv,
});
} catch (e) {
throw new Error('Unable to decrypt user keychain');
}
Expand Down Expand Up @@ -2295,21 +2301,24 @@ Wallet.prototype.shareWallet = function (params, callback) {
sharing = result;

if (needsKeychain) {
return self.getEncryptedUserKeychain({}).then(function (keychain) {
return self.getEncryptedUserKeychain({}).then(async function (keychain) {
// Decrypt the user key with a passphrase
if (keychain.encryptedXprv) {
if (!params.walletPassphrase) {
throw new Error('Missing walletPassphrase argument');
}
try {
keychain.xprv = self.bitgo.decrypt({ password: params.walletPassphrase, input: keychain.encryptedXprv });
keychain.xprv = await self.bitgo.decryptAsync({
password: params.walletPassphrase,
input: keychain.encryptedXprv,
});
} catch (e) {
throw new Error('Unable to decrypt user keychain');
}

const eckey = makeRandomKey();
const secret = getSharedSecret(eckey, Buffer.from(sharing.pubkey, 'hex')).toString('hex');
const newEncryptedXprv = self.bitgo.encrypt({ password: secret, input: keychain.xprv });
const newEncryptedXprv = await self.bitgo.encryptAsync({ password: secret, input: keychain.xprv });

sharedKeychain = {
xpub: keychain.xpub,
Expand Down Expand Up @@ -2599,10 +2608,10 @@ Wallet.prototype.recover = async function (params) {
assert(parsedUnsignedTx.outs.length === 1);
assert(_.sumBy(params.unspents, 'value') - _.sumBy(parsedUnsignedTx.outs, 'value') === Number(approximateTxFee));

const plainUserKey = this.bitgo.decrypt({ password: params.walletPassphrase, input: params.userKey });
const plainUserKey = await this.bitgo.decryptAsync({ password: params.walletPassphrase, input: params.userKey });
const halfSignedTx = await this.signTransaction({ ...unsignedTx, signingKey: plainUserKey });

const plainBackupKey = this.bitgo.decrypt({ password: params.walletPassphrase, input: params.backupKey });
const plainBackupKey = await this.bitgo.decryptAsync({ password: params.walletPassphrase, input: params.backupKey });
const fullSignedTx = await this.signTransaction({
...unsignedTx,
transactionHex: halfSignedTx.tx,
Expand Down Expand Up @@ -2659,7 +2668,7 @@ Wallet.prototype.sweep = async function (params) {
assert(parsedUnsignedTx.outs.length === 1);
assert(_.sumBy(params.unspents, 'value') - _.sumBy(parsedUnsignedTx.outs, 'value') === Number(approximateTxFee));

const plainUserKey = this.bitgo.decrypt({ password: params.walletPassphrase, input: params.userKey });
const plainUserKey = await this.bitgo.decryptAsync({ password: params.walletPassphrase, input: params.userKey });
const halfSignedTx = await this.signTransaction({ ...unsignedTx, signingKey: plainUserKey });

return await this.sendTransaction({
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-eos/src/eos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
BitGoBase,
checkKrsProvider,
Environments,
getBip32Keys,
getBip32KeysAsync,
getIsKrsRecovery,
getIsUnsignedSweep,
HalfSignedAccountTransaction as BaseHalfSignedTransaction,
Expand Down Expand Up @@ -905,7 +905,7 @@ export class Eos extends BaseCoin {
throw new Error('Invalid destination address!');
}

const keys = getBip32Keys(this.bitgo, params, { requireBitGoXpub: false });
const keys = await getBip32KeysAsync(this.bitgo, params, { requireBitGoXpub: false });

const rootAddressDetails = this.getAddressDetails(params.rootAddress);
const account = await this.getAccountFromNode({ address: rootAddressDetails.address });
Expand Down
3 changes: 2 additions & 1 deletion modules/sdk-coin-icp/src/icp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ export class Icp extends BaseCoin {
({ userKeyShare, backupKeyShare, commonKeyChain } = await ECDSAUtils.getMpcV2RecoveryKeyShares(
userKey,
backupKey,
params.walletPassphrase
params.walletPassphrase,
this.bitgo
));
publicKey = MPC.deriveUnhardened(commonKeyChain, ROOT_PATH).slice(0, 66);
} else {
Expand Down
3 changes: 2 additions & 1 deletion modules/sdk-coin-rune/src/rune.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ export class Rune extends CosmosCoin {
const { userKeyShare, backupKeyShare, commonKeyChain } = await ECDSAUtils.getMpcV2RecoveryKeyShares(
userKey,
backupKey,
params.walletPassphrase
params.walletPassphrase,
this.bitgo
); // baseAddress is not extracted
// Step 3: Instantiate the ECDSA signer and fetch the address details
const MPC = new Ecdsa();
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-stx/src/stx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
BaseTransaction,
BitGoBase,
Environments,
getBip32Keys,
getBip32KeysAsync,
getIsUnsignedSweep,
KeyPair,
MethodNotImplementedError,
Expand Down Expand Up @@ -701,7 +701,7 @@ export class Stx extends BaseCoin {
}
}
const isUnsignedSweep = getIsUnsignedSweep(params);
const keys = getBip32Keys(this.bitgo, params, { requireBitGoXpub: true });
const keys = await getBip32KeysAsync(this.bitgo, params, { requireBitGoXpub: true });
const rootAddressDetails = getAddressDetails(params.rootAddress);
const [accountBalanceData, accountNonceData] = await Promise.all([
this.getNativeStxBalanceFromNode({ address: rootAddressDetails.address }),
Expand Down
3 changes: 2 additions & 1 deletion modules/sdk-coin-tempo/src/tempo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,8 @@ export class Tempo extends AbstractEthLikeNewCoins {
const { userKeyShare, backupKeyShare, commonKeyChain } = await ECDSAUtils.getMpcV2RecoveryKeyShares(
userKey,
backupKey,
params.walletPassphrase
params.walletPassphrase,
this.bitgo
);

const MPC = new Ecdsa();
Expand Down
6 changes: 3 additions & 3 deletions modules/sdk-coin-trx/src/trx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
BaseCoin,
BitGoBase,
common,
getBip32Keys,
getBip32KeysAsync,
getIsKrsRecovery,
getIsUnsignedSweep,
KeyPair,
Expand Down Expand Up @@ -848,7 +848,7 @@ export class Trx extends BaseCoin {
}

// get our user, backup keys
const keys = getBip32Keys(this.bitgo, params, { requireBitGoXpub: false });
const keys = await getBip32KeysAsync(this.bitgo, params, { requireBitGoXpub: false });

// we need to decode our bitgoKey to a base58 address
const bitgoHexAddr = this.pubToHexAddress(this.xpubToUncompressedPub(params.bitgoKey));
Expand Down Expand Up @@ -1032,7 +1032,7 @@ export class Trx extends BaseCoin {
);
}

const keys = getBip32Keys(this.bitgo, params, { requireBitGoXpub: false });
const keys = await getBip32KeysAsync(this.bitgo, params, { requireBitGoXpub: false });
const baseAddrHex = this.pubToHexAddress(this.xpubToUncompressedPub(params.bitgoKey));

const txnsBatch: RecoveryTransaction[] = [];
Expand Down
6 changes: 4 additions & 2 deletions modules/sdk-coin-vet/src/vet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ export class Vet extends BaseCoin {
({ userKeyShare, backupKeyShare, commonKeyChain } = await ECDSAUtils.getMpcV2RecoveryKeyShares(
userKey,
backupKey,
params.walletPassphrase
params.walletPassphrase,
this.bitgo
));
publicKey = MPC.deriveUnhardened(commonKeyChain, 'm/0').slice(0, 66);
}
Expand Down Expand Up @@ -763,7 +764,8 @@ export class Vet extends BaseCoin {
({ userKeyShare, backupKeyShare, commonKeyChain } = await ECDSAUtils.getMpcV2RecoveryKeyShares(
userKey,
backupKey,
params.walletPassphrase
params.walletPassphrase,
this.bitgo
));
publicKey = MPC.deriveUnhardened(commonKeyChain, 'm/0').slice(0, 66);
}
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-xrp/src/xrp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
BaseCoin,
BitGoBase,
checkKrsProvider,
getBip32Keys,
getBip32KeysAsync,
InvalidAddressError,
KeyPair,
MethodNotImplementedError,
Expand Down Expand Up @@ -552,7 +552,7 @@ export class Xrp extends BaseCoin {
throw new Error('Invalid destination address!');
}

const keys = getBip32Keys(this.bitgo, params, { requireBitGoXpub: false });
const keys = await getBip32KeysAsync(this.bitgo, params, { requireBitGoXpub: false });

const { addressDetails, feeDetails, serverDetails, accountLines } = await promiseProps({
addressDetails: this.bitgo.post(rippledUrl).send(accountInfoParams),
Expand Down
14 changes: 7 additions & 7 deletions modules/sdk-coin-xrp/test/resources/xrp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ export const TEST_TOKEN_TRANSFER_TX = {

export const keys = {
userKey:
'{"iv":"ZN/gBap8QYIpjbbkZCDY8g==","v":1,"iter":10000,"ks":256,"ts":64,"mode"\n' +
':"ccm","adata":"","cipher":"aes","salt":"Egt/IC14ugw=","ct":"eRiONKtGrlEX8e\n' +
'5s5EAon7MadWZxyQWJMFJp16rimEd/2LWyGObo/d6hdJWUSZE1lDzpYV9x/Qg3vKz8Wy4ee8R0h\n' +
'{"iv":"ZN/gBap8QYIpjbbkZCDY8g==","v":1,"iter":10000,"ks":256,"ts":64,"mode"' +
':"ccm","adata":"","cipher":"aes","salt":"Egt/IC14ugw=","ct":"eRiONKtGrlEX8e' +
'5s5EAon7MadWZxyQWJMFJp16rimEd/2LWyGObo/d6hdJWUSZE1lDzpYV9x/Qg3vKz8Wy4ee8R0h' +
'8J+Ddo/Q8dR/yDNImcNGBclBMrh9c8cowuzRMnbMlbrLc949tN3d3A1jXOu3Rr5Wt4h1ag="}',
backupKey:
'{"iv":"D5SCw343R+l9qbP3TrXzlg==","v":1,"iter":10000,"ks":256,"ts":64,"mode"\n' +
':"ccm","adata":"","cipher":"aes","salt":"yug6WjWDjCA=","ct":"++m1LyBWw9emM2\n' +
'J1P85+T2VJEFPXFjshWssVBaHuccsiD0MsYsFX5d+hVfDrWV2aDOJAuOdtoCo+R3LrG2JST80ru\n' +
'{"iv":"D5SCw343R+l9qbP3TrXzlg==","v":1,"iter":10000,"ks":256,"ts":64,"mode"' +
':"ccm","adata":"","cipher":"aes","salt":"yug6WjWDjCA=","ct":"++m1LyBWw9emM2' +
'J1P85+T2VJEFPXFjshWssVBaHuccsiD0MsYsFX5d+hVfDrWV2aDOJAuOdtoCo+R3LrG2JST80ru' +
'37Y383IvRlB3A85MSo/poMtN1JyzorwF6Cfiz26bY3OKxywaeWJvr9SEDJxTDTx8HH9GsE="}',
bitgoKey:
'xpub661MyMwAqRbcGBXTTnaLrqur67ZHc9BA9X3GdAx6Kj8HVyg32TvktXv8DPN13QvnWSnrfC8\n' +
'xpub661MyMwAqRbcGBXTTnaLrqur67ZHc9BA9X3GdAx6Kj8HVyg32TvktXv8DPN13QvnWSnrfC8' +
'KFWvaUfR4kfwyikf6TuyJ3Ei8HGs7vxfdyia',
rootAddress: 'rNTfZB1h4TDdF9QXw37nbWk9euZmRby4qn',
};
Expand Down
Loading
Loading