Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk-core): add util to get public key from commonKeychain #3757

Merged
merged 2 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading