Skip to content

Commit fd705e9

Browse files
committed
feat!: make encrypt/decrypt async
BREAKING CHANGE: synchronous encrypt/decrypt callsites have been removed TICKET: WCN-174
1 parent 222d539 commit fd705e9

122 files changed

Lines changed: 1169 additions & 2213 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/ts/tss-recovery/mpcv2-recovery.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ECDSAUtils } from '@bitgo/sdk-core';
2+
import { BitGo } from 'bitgo';
23
import * as crypto from 'crypto';
34
import * as fs from 'fs';
45
import * as secp256k1 from 'secp256k1';
@@ -12,10 +13,11 @@ const walletPassphrase = "<Wallet passphrase>";
1213

1314

1415
async function testRecoveryMpcV2() {
16+
const bitgo = new BitGo({ env: 'test' });
1517
const userKey = fs.readFileSync('userKey.txt', 'utf8').replace(/(\r\n|\n|\r)/gm, "");
1618
const backupKey = fs.readFileSync('backupKey.txt', 'utf8').replace(/(\r\n|\n|\r)/gm, "");
1719
// Converting the user and backup keys on the keycard to key buffers that can be used in signing.
18-
const mpcv2KeyChain = await ECDSAUtils.getMpcV2RecoveryKeyShares(userKey, backupKey, walletPassphrase);
20+
const mpcv2KeyChain = await ECDSAUtils.getMpcV2RecoveryKeyShares(userKey, backupKey, walletPassphrase, bitgo);
1921
assert(mpcv2KeyChain.commonKeyChain === commonKeyChain, "Common key chain on keys do not match the common key chain from keycard.");
2022
// Computing SHA256 hash of the message.
2123
const messageHash = crypto.createHash('sha256').update(Buffer.from(sampleMessage, 'utf8')).digest();

modules/abstract-eth/src/abstractEthLikeNewCoins.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
14821482

14831483
if (!userKey.startsWith('xpub') && !userKey.startsWith('xprv')) {
14841484
try {
1485-
userKey = await this.bitgo.decryptAsync({
1485+
userKey = await this.bitgo.decrypt({
14861486
input: userKey,
14871487
password: params.walletPassphrase,
14881488
});
@@ -1501,7 +1501,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
15011501
let backupPrv;
15021502

15031503
try {
1504-
backupPrv = await this.bitgo.decryptAsync({
1504+
backupPrv = await this.bitgo.decrypt({
15051505
input: backupKey,
15061506
password: params.walletPassphrase,
15071507
});
@@ -1674,7 +1674,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
16741674

16751675
let userKeyPrv;
16761676
try {
1677-
userKeyPrv = await this.bitgo.decryptAsync({
1677+
userKeyPrv = await this.bitgo.decrypt({
16781678
input: params.encryptedPrv,
16791679
password: params.walletPassphrase,
16801680
});
@@ -1753,7 +1753,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
17531753
if (params.walletPassphrase) {
17541754
if (!userKey.startsWith('xpub') && !userKey.startsWith('xprv')) {
17551755
try {
1756-
userKeyPrv = await this.bitgo.decryptAsync({
1756+
userKeyPrv = await this.bitgo.decrypt({
17571757
input: userKey,
17581758
password: params.walletPassphrase,
17591759
});
@@ -2559,7 +2559,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
25592559
const walletPassphrase = buildParams.walletPassphrase;
25602560

25612561
const userKeychain = await this.keychains().get({ id: wallet.keyIds()[0] });
2562-
const userPrv = await wallet.getUserPrvAsync({ keychain: userKeychain, walletPassphrase });
2562+
const userPrv = await wallet.getUserPrv({ keychain: userKeychain, walletPassphrase });
25632563
const userPrvBuffer = bip32.fromBase58(userPrv).privateKey;
25642564
if (!userPrvBuffer) {
25652565
throw new Error('invalid userPrv');

modules/abstract-eth/src/ethLikeToken.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export class EthLikeToken extends AbstractEthLikeNewCoins {
219219
// Decrypt private keys from KeyCard values
220220
if (!userKey.startsWith('xpub') && !userKey.startsWith('xprv')) {
221221
try {
222-
userKey = await this.bitgo.decryptAsync({
222+
userKey = await this.bitgo.decrypt({
223223
input: userKey,
224224
password: params.walletPassphrase,
225225
});
@@ -239,7 +239,7 @@ export class EthLikeToken extends AbstractEthLikeNewCoins {
239239
let backupPrv;
240240

241241
try {
242-
backupPrv = await this.bitgo.decryptAsync({
242+
backupPrv = await this.bitgo.decrypt({
243243
input: backupKey,
244244
password: params.walletPassphrase,
245245
});

modules/abstract-lightning/src/wallet/lightning.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export class LightningWallet implements ILightningWallet {
265265
}
266266
const signature = createMessageSignature(
267267
t.exact(LightningPaymentRequest).encode(params),
268-
await this.wallet.bitgo.decryptAsync({ password: params.passphrase, input: userAuthKeyEncryptedPrv })
268+
await this.wallet.bitgo.decrypt({ password: params.passphrase, input: userAuthKeyEncryptedPrv })
269269
);
270270

271271
const paymentIntent: { intent: LightningPaymentIntent } = {
@@ -390,7 +390,7 @@ export class LightningWallet implements ILightningWallet {
390390
}
391391
const signature = createMessageSignature(
392392
transactionRequestCreate.transactions[0].unsignedTx.serializedTxHex,
393-
await this.wallet.bitgo.decryptAsync({ password: params.passphrase, input: userAuthKeyEncryptedPrv })
393+
await this.wallet.bitgo.decrypt({ password: params.passphrase, input: userAuthKeyEncryptedPrv })
394394
);
395395

396396
const transactionRequestWithSignature = (await this.wallet.bitgo

modules/abstract-lightning/src/wallet/selfCustodialLightning.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,29 @@ async function encryptWalletUpdateRequest(
1515
...params,
1616
};
1717

18-
const userAuthXprv = await wallet.bitgo.decryptAsync({
18+
const userAuthXprv = await wallet.bitgo.decrypt({
1919
password: params.passphrase,
2020
input: userAuthKeyEncryptedPrv,
2121
});
2222

2323
if (params.signerTlsKey) {
24-
requestWithEncryption.encryptedSignerTlsKey = await wallet.bitgo.encryptAsync({
24+
requestWithEncryption.encryptedSignerTlsKey = await wallet.bitgo.encrypt({
2525
password: params.passphrase,
2626
input: params.signerTlsKey,
2727
encryptionVersion: params.encryptionVersion,
2828
});
2929
}
3030

3131
if (params.signerAdminMacaroon) {
32-
requestWithEncryption.encryptedSignerAdminMacaroon = await wallet.bitgo.encryptAsync({
32+
requestWithEncryption.encryptedSignerAdminMacaroon = await wallet.bitgo.encrypt({
3333
password: params.passphrase,
3434
input: params.signerAdminMacaroon,
3535
encryptionVersion: params.encryptionVersion,
3636
});
3737
}
3838

3939
if (params.signerMacaroon) {
40-
requestWithEncryption.encryptedSignerMacaroon = await wallet.bitgo.encryptAsync({
40+
requestWithEncryption.encryptedSignerMacaroon = await wallet.bitgo.encrypt({
4141
password: deriveLightningServiceSharedSecret(coinName, userAuthXprv).toString('hex'),
4242
input: params.signerMacaroon,
4343
encryptionVersion: params.encryptionVersion,
@@ -92,7 +92,7 @@ export async function updateWalletCoinSpecific(
9292
const updateRequestWithEncryption = await encryptWalletUpdateRequest(wallet, params, userAuthKeyEncryptedPrv);
9393
const signature = createMessageSignature(
9494
updateRequestWithEncryption,
95-
await wallet.bitgo.decryptAsync({ password: params.passphrase, input: userAuthKeyEncryptedPrv })
95+
await wallet.bitgo.decrypt({ password: params.passphrase, input: userAuthKeyEncryptedPrv })
9696
);
9797
const coinSpecific = {
9898
[wallet.coin()]: {

modules/abstract-substrate/src/abstractSubstrateCoin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ export class SubstrateCoin extends BaseCoin {
345345
// Decrypt private keys from KeyCard values
346346
let userPrv;
347347
try {
348-
userPrv = await this.bitgo.decryptAsync({
348+
userPrv = await this.bitgo.decrypt({
349349
input: userKey,
350350
password: params.walletPassphrase,
351351
});
@@ -356,7 +356,7 @@ export class SubstrateCoin extends BaseCoin {
356356

357357
let backupPrv;
358358
try {
359-
backupPrv = await this.bitgo.decryptAsync({
359+
backupPrv = await this.bitgo.decrypt({
360360
input: backupKey,
361361
password: params.walletPassphrase,
362362
});

modules/abstract-utxo/src/abstractUtxoCoin.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ import { assertFixedScriptWalletAddress, generateAddress } from './address/fixed
8181
import { ParsedTransaction } from './transaction/types';
8282
import { decodeDescriptorPsbt, decodePsbt, encodeTransaction, stringToBufferTryFormats } from './transaction/decode';
8383
import { fetchKeychains, toBip32Triple, UtxoKeychain } from './keychains';
84-
import { verifyKeySignature, verifyUserPublicKey, verifyUserPublicKeyAsync } from './verifyKey';
84+
import { verifyKeySignature, verifyUserPublicKey } from './verifyKey';
8585
import { getPolicyForEnv } from './descriptor/validatePolicy';
8686
import { signTransaction } from './transaction/signTransaction';
8787
import { isUtxoWalletData, UtxoWallet } from './wallet';
@@ -604,17 +604,10 @@ export abstract class AbstractUtxoCoin extends BaseCoin implements Musig2Partici
604604
}
605605

606606
/**
607-
* @deprecated - use function verifyUserPublicKey instead
607+
* @deprecated - use the exported `verifyUserPublicKey` function instead
608608
*/
609-
protected verifyUserPublicKey(params: VerifyUserPublicKeyOptions): boolean {
610-
return verifyUserPublicKey(this.bitgo, params);
611-
}
612-
613-
/**
614-
* @deprecated - use function verifyUserPublicKeyAsync instead
615-
*/
616-
protected async verifyUserPublicKeyAsync(params: VerifyUserPublicKeyOptions): Promise<boolean> {
617-
return await verifyUserPublicKeyAsync(this.bitgo, params);
609+
protected async verifyUserPublicKey(params: VerifyUserPublicKeyOptions): Promise<boolean> {
610+
return await verifyUserPublicKey(this.bitgo, params);
618611
}
619612

620613
/**

modules/abstract-utxo/src/impl/btc/inscriptionBuilder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export class InscriptionBuilder implements IInscriptionBuilder {
260260
inscriptionData: Buffer
261261
): Promise<SubmitTransactionResponse> {
262262
const userKeychain = await this.wallet.baseCoin.keychains().get({ id: this.wallet.keyIds()[KeyIndices.USER] });
263-
const xprv = await this.wallet.getUserPrvAsync({ keychain: userKeychain, walletPassphrase });
263+
const xprv = await this.wallet.getUserPrv({ keychain: userKeychain, walletPassphrase });
264264

265265
const halfSignedCommitTransaction = (await this.wallet.signTransaction({
266266
prv: xprv,
@@ -300,7 +300,7 @@ export class InscriptionBuilder implements IInscriptionBuilder {
300300
txPrebuild: PrebuildTransactionResult
301301
): Promise<SubmitTransactionResponse> {
302302
const userKeychain = await this.wallet.baseCoin.keychains().get({ id: this.wallet.keyIds()[KeyIndices.USER] });
303-
const prv = await this.wallet.getUserPrvAsync({ keychain: userKeychain, walletPassphrase });
303+
const prv = await this.wallet.getUserPrv({ keychain: userKeychain, walletPassphrase });
304304

305305
const halfSigned = (await this.wallet.signTransaction({ prv, txPrebuild })) as HalfSignedUtxoTransaction;
306306
return this.wallet.submitTransaction({ halfSigned });

modules/abstract-utxo/src/recovery/backupKeyRecovery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
BitGoBase,
44
ErrorNoInputToRecover,
55
getKrsProvider,
6-
getBip32KeysAsync as getBip32KeysFromSdkCore,
6+
getBip32Keys as getBip32KeysFromSdkCore,
77
isTriple,
88
krsProviders,
99
Triple,

modules/abstract-utxo/src/recovery/crossChainRecovery.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BIP32, CoinName, fixedScriptWallet, address as wasmAddress } from '@bitgo/wasm-utxo';
2-
import { decryptAsync } from '@bitgo/sdk-api';
2+
import { decrypt } from '@bitgo/sdk-api';
33
import { BitGoBase, IWallet, Keychain, Triple, Wallet } from '@bitgo/sdk-core';
44

55
import { AbstractUtxoCoin, TransactionInfo } from '../abstractUtxoCoin';
@@ -313,7 +313,7 @@ async function getPrv(xprv?: string, passphrase?: string, wallet?: IWallet | Wal
313313
encryptedPrv = (await (wallet as WalletV1).getEncryptedUserKeychain()).encryptedXprv;
314314
}
315315

316-
return getPrv(await decryptAsync(passphrase, encryptedPrv));
316+
return getPrv(await decrypt(passphrase, encryptedPrv));
317317
}
318318

319319
/**

0 commit comments

Comments
 (0)