Skip to content

Commit

Permalink
Merge pull request #3711 from BitGo/WP-208-fix-eddsa-external-signer-…
Browse files Browse the repository at this point in the history
…commitment-exchange

fix(sdk-core): fix prebuildTransactionTss method
  • Loading branch information
alebusse authored Jul 11, 2023
2 parents a7df0fc + d65487a commit e884193
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
15 changes: 12 additions & 3 deletions modules/sdk-core/src/bitgo/utils/tss/eddsa/eddsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ export class EddsaUtils extends baseTSSUtils<KeyShare> {
txRequestId = txRequest.txRequestId;
}

const { apiVersion } = txRequestResolved;

const { userToBitgoCommitment, encryptedSignerShare, encryptedUserToBitgoRShare } =
await externalSignerCommitmentGenerator({ txRequest: txRequestResolved });

Expand All @@ -502,15 +504,22 @@ export class EddsaUtils extends baseTSSUtils<KeyShare> {
txRequestId,
userToBitgoCommitment,
encryptedSignerShare,
'full'
apiVersion
);

const { rShare } = await externalSignerRShareGenerator({
txRequest: txRequestResolved,
encryptedUserToBitgoRShare,
});

await offerUserToBitgoRShare(this.bitgo, this.wallet.id(), txRequestId, rShare, encryptedSignerShare.share, 'full');
await offerUserToBitgoRShare(
this.bitgo,
this.wallet.id(),
txRequestId,
rShare,
encryptedSignerShare.share,
apiVersion
);
const bitgoToUserRShare = await getBitgoToUserRShare(this.bitgo, this.wallet.id(), txRequestId);
const gSignShareTransactionParams = {
txRequest: txRequestResolved,
Expand All @@ -519,7 +528,7 @@ export class EddsaUtils extends baseTSSUtils<KeyShare> {
bitgoToUserCommitment,
};
const gShare = await externalSignerGShareGenerator(gSignShareTransactionParams);
await sendUserToBitgoGShare(this.bitgo, this.wallet.id(), txRequestId, gShare, 'full');
await sendUserToBitgoGShare(this.bitgo, this.wallet.id(), txRequestId, gShare, apiVersion);
return await getTxRequest(this.bitgo, this.wallet.id(), txRequestId);
}

Expand Down
10 changes: 6 additions & 4 deletions modules/sdk-core/src/bitgo/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2631,17 +2631,19 @@ export class Wallet implements IWallet {
private async prebuildTransactionTss(params: PrebuildTransactionOptions = {}): Promise<PrebuildTransactionResult> {
const reqId = params.reqId || new RequestTracer();
this.bitgo.setRequestTracer(reqId);

if (
params.apiVersion === 'lite' &&
(this._wallet.type === 'custodial' || this.baseCoin.getMPCAlgorithm() === 'ecdsa')
(this._wallet.type === 'custodial' || this._wallet.type === 'cold' || this.baseCoin.getMPCAlgorithm() === 'ecdsa')
) {
throw new Error(`Custodial and ECDSA MPC algorithm must always use 'full' api version`);
}

const apiVersion =
params.apiVersion ||
(this._wallet.type === 'custodial' || this.baseCoin.getMPCAlgorithm() === 'ecdsa' ? 'full' : 'lite');

(this._wallet.type === 'custodial' || this._wallet.type === 'cold' || this.baseCoin.getMPCAlgorithm() === 'ecdsa'
? 'full'
: 'lite');
// Two options different implementations of fees seems to now be supported, for now we will support both to be backwards compatible
// TODO(BG-59685): deprecate one of these so that we have a single way to pass fees
let feeOptions;
Expand Down Expand Up @@ -2988,7 +2990,7 @@ export class Wallet implements IWallet {
}

// ECDSA TSS uses TxRequestFull
if (this.baseCoin.getMPCAlgorithm() === 'ecdsa' || params.apiVersion === 'full') {
if (this.baseCoin.getMPCAlgorithm() === 'ecdsa' || params.apiVersion === 'full' || this._wallet.type === 'cold') {
return getTxRequest(this.bitgo, this.id(), signedTransaction.txRequestId);
}

Expand Down

0 comments on commit e884193

Please sign in to comment.