diff --git a/modules/bitgo/test/v2/unit/internal/tssUtils/ecdsa.ts b/modules/bitgo/test/v2/unit/internal/tssUtils/ecdsa.ts index c854606695..4fcd8ebe45 100644 --- a/modules/bitgo/test/v2/unit/internal/tssUtils/ecdsa.ts +++ b/modules/bitgo/test/v2/unit/internal/tssUtils/ecdsa.ts @@ -1468,6 +1468,14 @@ describe('TSS Ecdsa Utils:', async function () { message.should.equal(expectedMessageToSign); }); + it('publicKeyFromCommonKeychain returns correct public key', function () { + const commonKeychain = + '03f40c70545b519bb7bbc7195fd4b7d5bbfc873bfd38b18596e4b47a05b6a88d552e2e8319cb31e279b99dbe54115a983d35e86679af96d81b7478d1df368f76a8'; + const expectedPubKeyResult = `f40c70545b519bb7bbc7195fd4b7d5bbfc873bfd38b18596e4b47a05b6a88d556a10d6ab8055dc0b3a9af9dc4e42f4f9773c590afcc298d017c1b1ce29a88041`; + const actualPubKey = ECDSAUtils.EcdsaUtils.publicKeyFromCommonKeychain(commonKeychain); + actualPubKey.should.equal(expectedPubKeyResult); + }); + // #region Nock helpers async function createIncompleteBitgoHeldBackupKeyShare( userGpgKey: openpgp.SerializedKeyPair, diff --git a/modules/sdk-core/package.json b/modules/sdk-core/package.json index a0456c00db..923f704728 100644 --- a/modules/sdk-core/package.json +++ b/modules/sdk-core/package.json @@ -44,6 +44,8 @@ "@stablelib/hex": "^1.0.0", "@types/keccak": "^3.0.1", "@types/superagent": "4.1.15", + "elliptic": "^6.5.2", + "@types/elliptic": "^6.4.12", "bech32": "^2.0.0", "big.js": "^3.1.3", "bigint-crypto-utils": "3.1.4", 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 f446443b4b..35d5750c80 100644 --- a/modules/sdk-core/src/bitgo/utils/tss/ecdsa/ecdsa.ts +++ b/modules/sdk-core/src/bitgo/utils/tss/ecdsa/ecdsa.ts @@ -2,6 +2,7 @@ import assert from 'assert'; import { Buffer } from 'buffer'; import { Key, SerializedKeyPair } from 'openpgp'; import * as openpgp from 'openpgp'; +import { ec } from 'elliptic'; import { EcdsaPaillierProof, EcdsaRangeProof, EcdsaTypes, hexToBigInt, minModulusBitLength } from '@bitgo/sdk-lib-mpc'; import { bip32 } from '@bitgo/utxo-lib'; @@ -1181,4 +1182,11 @@ export class EcdsaUtils extends baseTSSUtils { .send(body) .result(); } + + static publicKeyFromCommonKeychain(commonKeychain: string) { + const pub = EcdsaUtils.getPublicKeyFromCommonKeychain(commonKeychain); + const secp256k1 = new ec('secp256k1'); + const key = secp256k1.keyFromPublic(pub, 'hex'); + return key.getPublic().encode('hex', false).slice(2); + } }