From e57f6f926d1b99fb3cad3953f05550163474bcfb Mon Sep 17 00:00:00 2001 From: Alejandro Busse Date: Mon, 29 Jan 2024 17:40:34 -0300 Subject: [PATCH] fix(sdk-core): fix hash for tss ecdsa PA signing Moved hash selection to EcDSA utils to fix PA signing and avoid the need to pass the hash to the signer WP-1186 TICKET: WP-1186 --- modules/sdk-core/src/bitgo/utils/tss/baseTypes.ts | 2 -- modules/sdk-core/src/bitgo/utils/tss/ecdsa/ecdsa.ts | 12 +++++++++++- modules/sdk-core/src/bitgo/wallet/wallet.ts | 10 ---------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/modules/sdk-core/src/bitgo/utils/tss/baseTypes.ts b/modules/sdk-core/src/bitgo/utils/tss/baseTypes.ts index 54a6e107af..4c06df9b84 100644 --- a/modules/sdk-core/src/bitgo/utils/tss/baseTypes.ts +++ b/modules/sdk-core/src/bitgo/utils/tss/baseTypes.ts @@ -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'; @@ -346,7 +345,6 @@ export type TSSParams = { prv: string; reqId: IRequestTracer; apiVersion?: ApiVersion; - hash?: Hash; }; export type TSSParamsForMessage = TSSParams & { diff --git a/modules/sdk-core/src/bitgo/utils/tss/ecdsa/ecdsa.ts b/modules/sdk-core/src/bitgo/utils/tss/ecdsa/ecdsa.ts index 7f403127d1..53616db303 100644 --- a/modules/sdk-core/src/bitgo/utils/tss/ecdsa/ecdsa.ts +++ b/modules/sdk-core/src/bitgo/utils/tss/ecdsa/ecdsa.ts @@ -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'; @@ -973,11 +974,20 @@ export class EcdsaUtils extends baseTSSUtils { 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 diff --git a/modules/sdk-core/src/bitgo/wallet/wallet.ts b/modules/sdk-core/src/bitgo/wallet/wallet.ts index 811d506f0d..bc06d19439 100644 --- a/modules/sdk-core/src/bitgo/wallet/wallet.ts +++ b/modules/sdk-core/src/bitgo/wallet/wallet.ts @@ -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'; @@ -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,