Skip to content

Commit

Permalink
Merge pull request #4238 from BitGo/WP-1186-fix-hash-for-tss-ecdsa-pa
Browse files Browse the repository at this point in the history
fix(sdk-core): fix hash for tss ecdsa PA signing
  • Loading branch information
alebusse authored Jan 29, 2024
2 parents a18daab + e57f6f9 commit 5686110
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
2 changes: 0 additions & 2 deletions modules/sdk-core/src/bitgo/utils/tss/baseTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ApiKeyShare, Keychain } from '../../keychain';
import { ApiVersion, Memo, WalletType } from '../../wallet';
import { EDDSA, GShare, SignShare, Signature } from '../../../account-lib/mpc/tss';
import { KeyShare } from './ecdsa';
import { Hash } from 'crypto';
import { EcdsaTypes } from '@bitgo/sdk-lib-mpc';
import { TssEcdsaStep1ReturnMessage, TssEcdsaStep2ReturnMessage, TxRequestChallengeResponse } from '../../tss/types';
import { AShare, DShare, SShare } from '../../tss/ecdsa/types';
Expand Down Expand Up @@ -346,7 +345,6 @@ export type TSSParams = {
prv: string;
reqId: IRequestTracer;
apiVersion?: ApiVersion;
hash?: Hash;
};

export type TSSParamsForMessage = TSSParams & {
Expand Down
12 changes: 11 additions & 1 deletion modules/sdk-core/src/bitgo/utils/tss/ecdsa/ecdsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Buffer } from 'buffer';
import { Key, SerializedKeyPair } from 'openpgp';
import * as openpgp from 'openpgp';
import { ec } from 'elliptic';
import { Hash } from 'crypto';

import { EcdsaPaillierProof, EcdsaRangeProof, EcdsaTypes, hexToBigInt, minModulusBitLength } from '@bitgo/sdk-lib-mpc';
import { bip32 } from '@bitgo/utxo-lib';
Expand Down Expand Up @@ -973,11 +974,20 @@ export class EcdsaUtils extends baseTSSUtils<KeyShare> {
step2Return.muDShare
)) as DShare;

// If only the getHashFunction() is defined for the coin use it otherwise
// pass undefined hash, default hash will be used in that case.
let hash: Hash | undefined;
try {
hash = this.baseCoin.getHashFunction();
} catch (err) {
hash = undefined;
}

const userSShare = await ECDSAMethods.createUserSignatureShare(
step2Return.oShare as OShare,
bitgoToUserDShare,
signablePayload,
params.hash
hash
);

// signing stage three with SShare send to bitgo and receives SShare
Expand Down
10 changes: 0 additions & 10 deletions modules/sdk-core/src/bitgo/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ import { Lightning } from '../lightning';
import EddsaUtils from '../utils/tss/eddsa';
import { EcdsaUtils } from '../utils/tss/ecdsa';
import { getTxRequest } from '../tss';
import { Hash } from 'crypto';
import { ofcTokens } from '@bitgo/statics';
import { buildParamKeys, BuildParams } from './BuildParams';
import { postWithCodec } from '../utils/postWithCodec';
Expand Down Expand Up @@ -3138,21 +3137,12 @@ export class Wallet implements IWallet {
throw new Error('prv required to sign transactions with TSS');
}

// If only the getHashFunction() is defined for the coin use it otherwise
// pass undefined hash, default hash will be used in that case.
let hash: Hash | undefined;
try {
hash = this.baseCoin.getHashFunction();
} catch (err) {
hash = undefined;
}
try {
const signedTxRequest = await this.tssUtils!.signTxRequest({
txRequest: params.txPrebuild.txRequestId,
prv: params.prv,
reqId: params.reqId || new RequestTracer(),
apiVersion: params.apiVersion,
hash,
});
return {
txRequestId: signedTxRequest.txRequestId,
Expand Down

0 comments on commit 5686110

Please sign in to comment.