Skip to content

Commit

Permalink
Merge pull request #3757 from BitGo/EA-37-commonKeychain-validation
Browse files Browse the repository at this point in the history
feat(sdk-core): add util to get public key from commonKeychain
  • Loading branch information
kxl4126 authored Jul 25, 2023
2 parents 6aa0962 + 89b7ede commit b70ad78
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions modules/bitgo/test/v2/unit/internal/tssUtils/ecdsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>,
Expand Down
2 changes: 2 additions & 0 deletions modules/sdk-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions modules/sdk-core/src/bitgo/utils/tss/ecdsa/ecdsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -1181,4 +1182,11 @@ export class EcdsaUtils extends baseTSSUtils<KeyShare> {
.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);
}
}

0 comments on commit b70ad78

Please sign in to comment.